module grabber.email_message
¶
Short summary¶
module pymmails.grabber.email_message
define an Email grabbed from a server.
Classes¶
class |
truncated documentation |
---|---|
overloads the message to class to add some functionalities such as a display using HTML |
Properties¶
property |
truncated documentation |
---|---|
return the body of the message |
|
return the body of the messag |
|
builds a unique ID |
Static Methods¶
staticmethod |
truncated documentation |
---|---|
Creates an instance of |
|
reverse engineer method |
|
read metadata assuming metafile contaings a json string |
Methods¶
method |
truncated documentation |
---|---|
usual |
|
usual |
|
converts the mail into a binary string |
|
Converts the mail into a string. |
|
decode a string encoded in the header |
|
define a default filename (no extension) |
|
Dumps a message using a call such as |
|
Dumps the mail into a folder using HTML format. If the destination files already exists, it skips it. If … |
|
enumerate the attachments as 4-uple (filename, content, message_id, content_id) |
|
returns all the charsets |
|
return a datetime object for the field Date |
|
return the date into a string |
|
get a field and cleans it |
|
returns a tuple (label, email address) or a list of groups from the regular expression |
|
return a string for the receivers |
|
return the sender name of an email (if available) |
|
return the number of attachments |
|
return the receivers |
|
return a string for the receivers |
|
Returns all fields for an emails as a dictionary |
Documentation¶
define an Email grabbed from a server.
- 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
- property Fields¶
- Returns:
list of available fields
- property UniqueID¶
builds a unique ID
- __lt__(at)¶
usual
- __sortkey__()¶
usual
- _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
- as_string(unixfrom=False, maxheaderlen=None, policy=None)¶
Converts the mail into a string.
- Returns:
string
- property body¶
return the body of the message
- property body_html¶
return the body of the messag
- static call_decode_header(st, is_email=False)¶
call email.header.decode_header
- Parameters:
st – string or email.header.Header
is_email – does something specific for emails
- Returns:
text, encoding
- static create_from_bytes(b)¶
Creates an instance of
EmailMessage
from a binary string (bytes) (seeas_bytes
).- Parameters:
b – binary string
- Returns:
instance of
EmailMessage
- decode_header(field, st)¶
decode a string encoded in the header
- Parameters:
field – field
st – string
- Returns:
string (it never return None)
- default_filename()¶
define a default filename (no extension)
- Returns:
str
- 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
- 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
.
- enumerate_attachments()¶
enumerate the attachments as 4-uple (filename, content, message_id, content_id)
- Returns:
iterator on tuple (filename, content, message_id, content_id)
- get_all_charsets(part=None)¶
returns all the charsets
- get_date()¶
return a datetime object for the field Date
- get_date_str()¶
return the date into a string
- Returns:
date as a string (iso format)
- get_field(field)¶
get a field and cleans it
- Parameters:
field – subject or …
- Returns:
text
- get_from()¶
returns a tuple (label, email address) or a list of groups from the regular expression
- Returns:
tuple ( label, email address)
- get_from_str()¶
return a string for the receivers
- Returns:
string
- 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)
- get_nb_attachements()¶
return the number of attachments
- Returns:
int
- get_to(cc=False, field='to')¶
return the receivers
- Parameters:
cc – get receivers or second receivers
field – field to use,
to
orDelivered-To
(the second one is used as a backup anyway)
- Returns:
list of tuple [ ( label, email address) ]
- 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
orDelivered-To
(the second one is used as a backup anyway)
- Returns:
string
- 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.
- static read_metadata(metafile)¶
read metadata assuming metafile contaings a json string
- Parameters:
metafile – json string
- Returns:
dictionary
- to_dict()¶
Returns all fields for an emails as a dictionary
- Returns:
dictionary { key : value }