module grabber.email_message

Inheritance diagram of pymmails.grabber.email_message

Short summary

module pymmails.grabber.email_message

define an Email grabbed from a server.

source on GitHub

Classes

class

truncated documentation

EmailMessage

overloads the message to class to add some functionalities such as a display using HTML

Properties

property

truncated documentation

body

return the body of the message

body_html

return the body of the messag

Fields

UniqueID

builds a unique ID

Static Methods

staticmethod

truncated documentation

call_decode_header

call email.header.decode_header

create_from_bytes

Creates an instance of EmailMessage from a binary string (bytes) (see as_bytes()).

interpret_default_filename

reverse engineer method default_filename()

read_metadata

read metadata assuming metafile contaings a json string

Methods

method

truncated documentation

__lt__

usual

__sortkey__

usual

as_bytes

converts the mail into a binary string

as_string

Converts the mail into a string.

decode_header

decode a string encoded in the header

default_filename

define a default filename (no extension)

dump

Dumps a message using a call such as EmailMessageRenderer.

dump_attachments

Dumps the mail into a folder using HTML format. If the destination files already exists, it skips it. If …

enumerate_attachments

enumerate the attachments as 4-uple (filename, content, message_id, content_id)

get_all_charsets

returns all the charsets

get_date

return a datetime object for the field Date

get_date_str

return the date into a string

get_field

get a field and cleans it

get_from

returns a tuple (label, email address) or a list of groups from the regular expression

get_from_str

return a string for the receivers

get_name

return the sender name of an email (if available)

get_nb_attachements

return the number of attachments

get_to

return the receivers

get_to_str

return a string for the receivers

to_dict

Returns all fields for an emails as a dictionary

Documentation

define an Email grabbed from a server.

source on GitHub

class pymmails.grabber.email_message.EmailMessage(policy=Compat32())

Bases: Message

overloads the message to class to add some functionalities such as a display using HTML

source on GitHub

property Fields
Returns:

list of available fields

source on GitHub

property UniqueID

builds a unique ID

source on GitHub

__lt__(at)

usual

source on GitHub

__sortkey__()

usual

source on GitHub

_date_format = '%Y-%m-%dT%H:%M:%S.%fZ'
_search_encodings = ['iso-8859-1', 'windows-1252', 'UTF-8', 'utf-8']

use for method @see me call_decode_header

as_bytes()

converts the mail into a binary string

Returns:

bytes

See Message.as_bytes

source on GitHub

as_string(unixfrom=False, maxheaderlen=None, policy=None)

Converts the mail into a string.

Returns:

string

See Message.as_string

source on GitHub

property body

return the body of the message

source on GitHub

property body_html

return the body of the messag

source on GitHub

static call_decode_header(st, is_email=False)

call email.header.decode_header

Parameters:
Returns:

text, encoding

source on GitHub

static create_from_bytes(b)

Creates an instance of EmailMessage from a binary string (bytes) (see as_bytes).

Parameters:

b – binary string

Returns:

instance of EmailMessage

source on GitHub

decode_header(field, st)

decode a string encoded in the header

Parameters:
  • field – field

  • st – string

Returns:

string (it never return None)

source on GitHub

default_filename()

define a default filename (no extension)

Returns:

str

source on GitHub

dump(render, location, attach_folder='attachments', fLOG=<function noLOG>, **params)

Dumps a message using a call such as EmailMessageRenderer.

Parameters:
  • render – instance of class EmailMessageRenderer

  • location – location of the file to store

  • attach_folder – folder for the attachments, it will be created if it does not exist

  • buffer_write – None or instance of BufferFilesWriting

  • fLOG – logging function

  • params – others parameters, see EmailMessageRenderer.write

Returns:

list of stored files

source on GitHub

dump_attachments(attach_folder='.', buffer_write=None, metadata=True, fLOG=<function noLOG>)

Dumps the mail into a folder using HTML format. If the destination files already exists, it skips it. If an attachments already has the same name, it chooses another one if the attachment is different (otherwise it keeps it as it is).

Parameters:
  • attach_folder – destination folder

  • buffer_write – None or instance of BufferFilesWriting

  • metadata – if True, also dump metadata about attachments

  • fLOG – logging function

Returns:

list of attachments

The results is a list of 3-uple:

  • full name of the attachments

  • message id

  • content id

The metadata contains information about the mail it comes from. The data is stored in a json format (except for date). It is stored in a file with extension .metadata.

source on GitHub

enumerate_attachments()

enumerate the attachments as 4-uple (filename, content, message_id, content_id)

Returns:

iterator on tuple (filename, content, message_id, content_id)

source on GitHub

get_all_charsets(part=None)

returns all the charsets

source on GitHub

get_date()

return a datetime object for the field Date

source on GitHub

get_date_str()

return the date into a string

Returns:

date as a string (iso format)

source on GitHub

get_field(field)

get a field and cleans it

Parameters:

field – subject or …

Returns:

text

source on GitHub

get_from()

returns a tuple (label, email address) or a list of groups from the regular expression

Returns:

tuple ( label, email address)

source on GitHub

get_from_str()

return a string for the receivers

Returns:

string

source on GitHub

get_name(_fallback_get_from=True)

return the sender name of an email (if available)

Parameters:

_fallback_get_from – internal parameter, avoir recursion

Returns:

name (or None if not found)

source on GitHub

get_nb_attachements()

return the number of attachments

Returns:

int

source on GitHub

get_to(cc=False, field='to')

return the receivers

Parameters:
  • cc – get receivers or second receivers

  • field – field to use, to or Delivered-To (the second one is used as a backup anyway)

Returns:

list of tuple [ ( label, email address) ]

source on GitHub

get_to_str(cc=False, field='to')

return a string for the receivers

Parameters:
  • cc – get receivers or second receivers

  • field – field to use, to or Delivered-To (the second one is used as a backup anyway)

Returns:

string

source on GitHub

static interpret_default_filename(name)

reverse engineer method default_filename

Parameters:

name – filename

Returns:

dictionary

The function creates a dictionary with keys date, from, uid, name.

source on GitHub

static read_metadata(metafile)

read metadata assuming metafile contaings a json string

Parameters:

metafile – json string

Returns:

dictionary

source on GitHub

to_dict()

Returns all fields for an emails as a dictionary

Returns:

dictionary { key : value }

source on GitHub