core.utils.mail_parsing module¶
Provides functions for parsing features from the maildata.
- Global variables:
logger (
logging.Logger): The logger for this module.
- core.utils.mail_parsing.get_header(email_message, header_name, joining_string=',')[source]¶
Shorthand to safely get a header from a
email.message.EmailMessage.Strips trailing whitespace from the header.
- Parameters:
email_message (
EmailMessage) – The message to get the header from.header_name (
str) – The name of the header field.joining_string (
str) – The string to join multiple headers with. Default to ‘,’ which is safe for CharFields.
- Return type:
- Returns:
The decoded header field as a string if found else “”.
- core.utils.mail_parsing.parse_datetime_header(date_header)[source]¶
Parses the date header into a datetime object.
If an error occurs uses the current time as fallback.
Note
Uses
email.utils.parsedate_to_datetime()anddjango.utils.timezone.now().
- core.utils.mail_parsing.get_bodytexts(email_message)[source]¶
Parses the various bodytexts from a
email.message.EmailMessage.- Parameters:
email_message (
EmailMessage) – The message to parse the bodytexts from.- Return type:
- Returns:
A dict containing the bodytexts with their contenttypes as keys.
- core.utils.mail_parsing.parse_IMAP_mailbox_data(mailbox_data)[source]¶
Parses the mailbox name as received in
core.utils.fetchers.IMAP4Fetcher.Note
Uses
imap_tools.imap_utf7.utf7_decode()to decode IMAPs modified utf7 encoding. The result must not be changed afterwards, otherwise opening the mailbox via this name is not possible!
- core.utils.mail_parsing.parse_mailbox_type(mailbox_type_name)[source]¶
Maps the mailbox type names from the various protocols to the choice enum.
- core.utils.mail_parsing.find_best_href_in_header(header)[source]¶
Finds the best href in a header of hrefs.
The href is selected via the logic: https > http > …
- core.utils.mail_parsing.make_icalendar_readout(icalendar_file)[source]¶
Parses the main features of a icalendar file into a list.
References