airflow.contrib.hooks.imap_hook
¶
Module Contents¶
-
class
airflow.contrib.hooks.imap_hook.
ImapHook
(imap_conn_id='imap_default')[source]¶ Bases:
airflow.hooks.base_hook.BaseHook
This hook connects to a mail server by using the imap protocol.
- Parameters
imap_conn_id (str) – The connection id that contains the information used to authenticate the client.
-
has_mail_attachment
(self, name, mail_folder='INBOX', check_regex=False)[source]¶ Checks the mail folder for mails containing attachments with the given name.
-
retrieve_mail_attachments
(self, name, mail_folder='INBOX', check_regex=False, latest_only=False, not_found_mode='raise')[source]¶ Retrieves mail’s attachments in the mail folder by its name.
- Parameters
name (str) – The name of the attachment that will be downloaded.
mail_folder (str) – The mail folder where to look at.
check_regex (bool) – Checks the name for a regular expression.
latest_only (bool) – If set to True it will only retrieve the first matched attachment.
not_found_mode (str) – Specify what should happen if no attachment has been found. Supported values are ‘raise’, ‘warn’ and ‘ignore’. If it is set to ‘raise’ it will raise an exception, if set to ‘warn’ it will only print a warning and if set to ‘ignore’ it won’t notify you at all.
- Returns
a list of tuple each containing the attachment filename and its payload.
- Return type
a list of tuple
-
download_mail_attachments
(self, name, local_output_directory, mail_folder='INBOX', check_regex=False, latest_only=False, not_found_mode='raise')[source]¶ Downloads mail’s attachments in the mail folder by its name to the local directory.
- Parameters
name (str) – The name of the attachment that will be downloaded.
local_output_directory (str) – The output directory on the local machine where the files will be downloaded to.
mail_folder (str) – The mail folder where to look at.
check_regex (bool) – Checks the name for a regular expression.
latest_only (bool) – If set to True it will only download the first matched attachment.
not_found_mode (str) – Specify what should happen if no attachment has been found. Supported values are ‘raise’, ‘warn’ and ‘ignore’. If it is set to ‘raise’ it will raise an exception, if set to ‘warn’ it will only print a warning and if set to ‘ignore’ it won’t notify you at all.
-
class
airflow.contrib.hooks.imap_hook.
Mail
(mail_body)[source]¶ Bases:
airflow.LoggingMixin
This class simplifies working with mails returned by the imaplib client.
- Parameters
mail_body (str) – The mail body of a mail received from imaplib client.
-
has_attachments
(self)[source]¶ Checks the mail for a attachments.
- Returns
True if it has attachments and False if not.
- Return type
-
class
airflow.contrib.hooks.imap_hook.
MailPart
(part)[source]¶ This class is a wrapper for a Mail object’s part and gives it more features.
- Parameters
part (any) – The mail part in a Mail object.
-
is_attachment
(self)[source]¶ Checks if the part is a valid mail attachment.
- Returns
True if it is an attachment and False if not.
- Return type