| :mod:`airflow.contrib.hooks.imap_hook` |
| ====================================== |
| |
| .. py:module:: airflow.contrib.hooks.imap_hook |
| |
| |
| Module Contents |
| --------------- |
| |
| .. py:class:: ImapHook(imap_conn_id='imap_default') |
| |
| Bases: :class:`airflow.hooks.base_hook.BaseHook` |
| |
| This hook connects to a mail server by using the imap protocol. |
| |
| :param imap_conn_id: The connection id that contains the information used to authenticate the client. |
| :type imap_conn_id: str |
| |
| |
| .. method:: __enter__(self) |
| |
| |
| |
| |
| .. method:: __exit__(self, exc_type, exc_val, exc_tb) |
| |
| |
| |
| |
| .. method:: has_mail_attachment(self, name, mail_folder='INBOX', check_regex=False) |
| |
| Checks the mail folder for mails containing attachments with the given name. |
| |
| :param name: The name of the attachment that will be searched for. |
| :type name: str |
| :param mail_folder: The mail folder where to look at. |
| :type mail_folder: str |
| :param check_regex: Checks the name for a regular expression. |
| :type check_regex: bool |
| :returns: True if there is an attachment with the given name and False if not. |
| :rtype: bool |
| |
| |
| |
| |
| .. method:: retrieve_mail_attachments(self, name, mail_folder='INBOX', check_regex=False, latest_only=False, not_found_mode='raise') |
| |
| Retrieves mail's attachments in the mail folder by its name. |
| |
| :param name: The name of the attachment that will be downloaded. |
| :type name: str |
| :param mail_folder: The mail folder where to look at. |
| :type mail_folder: str |
| :param check_regex: Checks the name for a regular expression. |
| :type check_regex: bool |
| :param latest_only: If set to True it will only retrieve |
| the first matched attachment. |
| :type latest_only: bool |
| :param not_found_mode: 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. |
| :type not_found_mode: str |
| :returns: a list of tuple each containing the attachment filename and its payload. |
| :rtype: a list of tuple |
| |
| |
| |
| |
| .. method:: download_mail_attachments(self, name, local_output_directory, mail_folder='INBOX', check_regex=False, latest_only=False, not_found_mode='raise') |
| |
| Downloads mail's attachments in the mail folder by its name to the local directory. |
| |
| :param name: The name of the attachment that will be downloaded. |
| :type name: str |
| :param local_output_directory: The output directory on the local machine |
| where the files will be downloaded to. |
| :type local_output_directory: str |
| :param mail_folder: The mail folder where to look at. |
| :type mail_folder: str |
| :param check_regex: Checks the name for a regular expression. |
| :type check_regex: bool |
| :param latest_only: If set to True it will only download |
| the first matched attachment. |
| :type latest_only: bool |
| :param not_found_mode: 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. |
| :type not_found_mode: str |
| |
| |
| |
| |
| .. method:: _handle_not_found_mode(self, not_found_mode) |
| |
| |
| |
| |
| .. method:: _retrieve_mails_attachments_by_name(self, name, mail_folder, check_regex, latest_only) |
| |
| |
| |
| |
| .. method:: _list_mail_ids_desc(self) |
| |
| |
| |
| |
| .. method:: _fetch_mail_body(self, mail_id) |
| |
| |
| |
| |
| .. method:: _check_mail_body(self, response_mail_body, name, check_regex, latest_only) |
| |
| |
| |
| |
| .. method:: _create_files(self, mail_attachments, local_output_directory) |
| |
| |
| |
| |
| .. method:: _is_symlink(self, name) |
| |
| |
| |
| |
| .. method:: _is_escaping_current_directory(self, name) |
| |
| |
| |
| |
| .. method:: _correct_path(self, name, local_output_directory) |
| |
| |
| |
| |
| .. method:: _create_file(self, name, payload, local_output_directory) |
| |
| |
| |
| |
| .. py:class:: Mail(mail_body) |
| |
| Bases: :class:`airflow.LoggingMixin` |
| |
| This class simplifies working with mails returned by the imaplib client. |
| |
| :param mail_body: The mail body of a mail received from imaplib client. |
| :type mail_body: str |
| |
| |
| .. method:: has_attachments(self) |
| |
| Checks the mail for a attachments. |
| |
| :returns: True if it has attachments and False if not. |
| :rtype: bool |
| |
| |
| |
| |
| .. method:: get_attachments_by_name(self, name, check_regex, find_first=False) |
| |
| Gets all attachments by name for the mail. |
| |
| :param name: The name of the attachment to look for. |
| :type name: str |
| :param check_regex: Checks the name for a regular expression. |
| :type check_regex: bool |
| :param find_first: If set to True it will only find the first match and then quit. |
| :type find_first: bool |
| :returns: a list of tuples each containing name and payload |
| where the attachments name matches the given name. |
| :rtype: list of tuple |
| |
| |
| |
| |
| .. py:class:: MailPart(part) |
| |
| This class is a wrapper for a Mail object's part and gives it more features. |
| |
| :param part: The mail part in a Mail object. |
| :type part: any |
| |
| |
| .. method:: is_attachment(self) |
| |
| Checks if the part is a valid mail attachment. |
| |
| :returns: True if it is an attachment and False if not. |
| :rtype: bool |
| |
| |
| |
| |
| .. method:: has_matching_name(self, name) |
| |
| Checks if the given name matches the part's name. |
| |
| :param name: The name to look for. |
| :type name: str |
| :returns: True if it matches the name (including regular expression). |
| :rtype: tuple |
| |
| |
| |
| |
| .. method:: has_equal_name(self, name) |
| |
| Checks if the given name is equal to the part's name. |
| |
| :param name: The name to look for. |
| :type name: str |
| :returns: True if it is equal to the given name. |
| :rtype: bool |
| |
| |
| |
| |
| .. method:: get_file(self) |
| |
| Gets the file including name and payload. |
| |
| :returns: the part's name and payload. |
| :rtype: tuple |
| |
| |
| |
| |