U
    42iÊ                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  G dd de!Z"dS )z2Twilio SendGrid v3/mail/send response body builder   )Bcc)Cc)Content)	CustomArg)DynamicTemplateData)Email)From)Header)MimeType)Personalization)ReplyTo)SendAt)Subject)Substitution)
TemplateId)Toc                   @   sZ  e Zd ZdZd}ddZdd Zd~d	d
Zdd Zdd Zdd Z	dddZ
edd ZdddZedd ZejdddZdddZedd ZejdddZddd Zed!d" Zejdd#d"Zdd$d%Zed&d' Zejd(d' Zed)d* Zed+d, Zejd-d, Zd.d/ Zed0d1 Zejd2d1 Zd3d4 Zed5d6 Zed7d8 Zejd9d8 Zd:d; Zed<d= Zejd>d= Zed?d@ ZejdAd@ ZedBdC Z e jdDdC Z edEdF Z!e!jdGdF Z!edHdI Z"e"jdJdI Z"edKdL Z#edMdN Z$e$jdOdN Z$ddPdQZ%edRdS Z&edTdU Z'e'jdVdU Z'dWdX Z(edYdZ Z)e)jd[dZ Z)ed\d] Z*ed^d_ Z+e+jd`d_ Z+dadb Z,edcdd Z-ededf Z.e.jdgdf Z.dhdi Z/edjdk Z0e0jdldk Z0edmdn Z1e1jdodn Z1edpdq Z2e2jdrdq Z2edsdt Z3e3jdudt Z3edvdw Z4e4jdxdw Z4dydz Z5e6d{d| Z7dS )Mailz*Creates the response body for v3/mail/sendNFc	           	      C   s   d| _ d| _d| _d| _d| _g | _d| _d| _d| _d| _	d| _
d| _d| _d| _d| _d| _d| _d| _|dk	rz|| _|dk	r| ||| |dk	r|| _|dk	r| |tj |dk	r| |tj |dk	r| |tj dS )a  
        Creates the response body for a v3/mail/send API call

        :param from_email: The email address of the sender
        :type from_email: From, tuple, optional
        :param subject: The subject of the email
        :type subject: Subject, optional
        :param to_emails: The email address of the recipient
        :type to_emails: To, str, tuple, list(str), list(tuple),
                         list(To), optional
        :param plain_text_content: The plain text body of the email
        :type plain_text_content: string, optional
        :param html_content: The html body of the email
        :type html_content: string, optional
        :param amp_html_content: The amp-html body of the email
        :type amp_html_content: string, optional
        N)_attachments_categories	_contents_custom_args_headers_personalizations	_sections_asm	_batch_id_from_email_ip_pool_name_mail_settings	_reply_to_reply_to_list_send_at_subject_template_id_tracking_settings
from_emailadd_tosubjectadd_contentr
   textamphtml)	selfr%   	to_emailsr'   Zplain_text_contentZhtml_contentZamp_html_contentglobal_substitutionsis_multiple r0   >/tmp/pip-unpacked-wheel-clku7wca/sendgrid/helpers/mail/mail.py__init__   s<    zMail.__init__c                 C   s   t |  S )zA JSON-ready string representation of this Mail object.

        :returns: A JSON-ready string representation of this Mail object.
        :rtype: string
        )strgetr,   r0   r0   r1   __str__S   s    zMail.__str__    c                 C   s   |pg }| || |S )aZ  Ensure an item is appended to a list or create a new empty list

        :param new_items: the item(s) to append
        :type new_items: list(obj)
        :param append_to: the list on which to append the items
        :type append_to: list()
        :param index: index of the list on which to append the items
        :type index: int
        insert)r,   	new_itemsZ	append_toindexr0   r0   r1   _ensure_append[   s    
zMail._ensure_appendc                 C   s   |pg }| d| |S )a  Ensure an item is inserted to a list or create a new empty list

        :param new_items: the item(s) to insert
        :type new_items: list(obj)
        :param insert_to: the list on which to insert the items at index 0
        :type insert_to: list()
        r7   r8   )r,   r:   Z	insert_tor0   r0   r1   _ensure_inserti   s    zMail._ensure_insertc                 C   s&   t  }dd |pg D }dd |D S )z]Flatten a dict

        :param dicts: Flatten a dict
        :type dicts: list(dict)
        c                 S   s   g | ]}|  qS r0   r4   ).0dr0   r0   r1   
<listcomp>|   s     z'Mail._flatten_dicts.<locals>.<listcomp>c                 S   s$   i | ]}|  D ]\}}||qqS r0   )items)r?   r@   kvr0   r0   r1   
<dictcomp>}   s
     
   z'Mail._flatten_dicts.<locals>.<dictcomp>)dict)r,   Zdictsr@   Zlist_of_dictsr0   r0   r1   _flatten_dictsu   s    zMail._flatten_dictsc                 C   s   |dk	r|  S dS )zGet the JSON representation of the object, else return None

        :param from_obj: Get the JSON representation of the object,
        else return None
        :type from_obj: obj
        Nr>   )r,   Zfrom_objr0   r0   r1   _get_or_none   s    zMail._get_or_nonec           	      C   sJ  |dkrt |tr8|D ]}t }|| | | qnt }|| | | |dk	rt |tr|D ]}| jD ]}|| qrqhn| jD ]}|| qnz| j| }d}W n tk
r   t }d}Y nX t |tr|D ]}|| qn
|| |dk	r2t |tr(|D ]}|| qn
|| |sF| j||d dS )a  Adds emails to the Personalization object

        :param emails: An Email or list of Email objects
        :type emails: Email, list(Email)
        :param global_substitutions: A dict of substitutions for all recipients
        :type global_substitutions: dict
        :param is_multiple: Create a new personalization for each recipient
        :type is_multiple: bool
        :param p: p is the Personalization object or Personalization object
                  index
        :type p: Personalization, integer, optional
        TNFr;   )	
isinstancelistr   Z	add_emailadd_personalizationpersonalizationsadd_substitutionr   
IndexError)	r,   Zemailsr.   r/   pemailpersonalizationsubstitutionhas_internal_personalizationr0   r0   r1   _set_emails   sB    












zMail._set_emailsc                 C   s   | j S )z]A list of one or more Personalization objects

        :rtype: list(Personalization)
        )r   r5   r0   r0   r1   rM      s    zMail.personalizationsc                 C   s   |  || j|| _dS )zAdd a Personalization object

        :param personalization: Add a Personalization object
        :type personalization: Personalization
        :param index: The index where to add the Personalization
        :type index: int
        N)r<   r   )r,   rR   r;   r0   r0   r1   rL      s
      zMail.add_personalizationc                 C   s   d S Nr0   r5   r0   r0   r1   to   s    zMail.toc                 C   s   t |trV|D ]D}t |tr&t|d}t |trBt|d |d }| |||| qn@t |trjt|d}t |trt|d |d }| |||| dS )a>  Adds To objects to the Personalization object

        :param to_emails: The email addresses of all recipients
        :type to_emails: To, str, tuple, list(str), list(tuple), list(To)
        :param global_substitutions: A dict of substitutions for all recipients
        :type global_substitutions: dict
        :param is_multiple: Create a new personalization for each recipient
        :type is_multiple: bool
        :param p: p is the Personalization object or Personalization object
                  index
        :type p: Personalization, integer, optional
        Nr7   r   )rJ   rK   r3   r   tupler&   )r,   r-   r.   r/   rP   rQ   r0   r0   r1   rW      s    






c                 C   s   t |trl|D ]Z}t |tr(t|d}n0t |trFt|d |d }nt |tsXtd| |||| qnPt |trt|d}t |trt|d |d }t |tr|j}| |||| dS )a#  Adds a To object to the Personalization object

        :param to_email: A To object
        :type to_email: To, str, tuple, list(str), list(tuple), list(To)
        :param global_substitutions: A dict of substitutions for all recipients
        :type global_substitutions: dict
        :param is_multiple: Create a new personalization for each recipient
        :type is_multiple: bool
        :param p: p is the Personalization object or Personalization object
                  index
        :type p: Personalization, integer, optional
        Nr7   r   z<Please use a To/Cc/Bcc, tuple, or a str for a to_email list.)	rJ   rK   r3   r   rX   r   
ValueErrorrU   rR   )r,   to_emailr.   r/   rP   rQ   r0   r0   r1   r&      s$    







zMail.add_toc                 C   s   d S rV   r0   r5   r0   r0   r1   cc  s    zMail.ccc                 C   s   t |trV|D ]D}t |tr&t|d}t |trBt|d |d }| |||| qn@t |trjt|d}t |trt|d |d }| |||| dS )a  Adds Cc objects to the Personalization object

        :param cc_emails: An Cc or list of Cc objects
        :type cc_emails: Cc, list(Cc), tuple
        :param global_substitutions: A dict of substitutions for all recipients
        :type global_substitutions: dict
        :param is_multiple: Create a new personalization for each recipient
        :type is_multiple: bool
        :param p: p is the Personalization object or Personalization object
                  index
        :type p: Personalization, integer, optional
        Nr7   r   )rJ   rK   r3   r   rX   add_ccr   )r,   Z	cc_emailsr.   r/   rP   rQ   r0   r0   r1   r[     s    






c                 C   sV   t |trt|d}t |tr0t|d |d }t |tr@|j}| j||||d dS )a  Adds a Cc object to the Personalization object

        :param to_emails: An Cc object
        :type to_emails: Cc
        :param global_substitutions: A dict of substitutions for all recipients
        :type global_substitutions: dict
        :param is_multiple: Create a new personalization for each recipient
        :type is_multiple: bool
        :param p: p is the Personalization object or Personalization object
                  index
        :type p: Personalization, integer, optional
        Nr7   r   r/   rP   )rJ   r3   r   rX   r   rR   rU   )r,   cc_emailr.   r/   rP   r0   r0   r1   r\   7  s    



   zMail.add_ccc                 C   s   d S rV   r0   r5   r0   r0   r1   bccN  s    zMail.bccc                 C   s   t |trV|D ]D}t |tr&t|d}t |trBt|d |d }| |||| qn@t |trjt|d}t |trt|d |d }| |||| dS )a  Adds Bcc objects to the Personalization object

        :param bcc_emails: An Bcc or list of Bcc objects
        :type bcc_emails: Bcc, list(Bcc), tuple
        :param global_substitutions: A dict of substitutions for all recipients
        :type global_substitutions: dict
        :param is_multiple: Create a new personalization for each recipient
        :type is_multiple: bool
        :param p: p is the Personalization object or Personalization object
                  index
        :type p: Personalization, integer, optional
        Nr7   r   )rJ   rK   r3   r   rX   add_bcc)r,   Z
bcc_emailsr.   r/   rP   rQ   r0   r0   r1   r_   R  s    






c                 C   sV   t |trt|d}t |tr0t|d |d }t |tr@|j}| j||||d dS )a  Adds a Bcc object to the Personalization object

        :param to_emails: An Bcc object
        :type to_emails: Bcc
        :param global_substitutions: A dict of substitutions for all recipients
        :type global_substitutions: dict
        :param is_multiple: Create a new personalization for each recipient
        :type is_multiple: bool
        :param p: p is the Personalization object or Personalization object
                  index
        :type p: Personalization, integer, optional
        Nr7   r   r]   )rJ   r3   r   rX   r   rR   rU   )r,   	bcc_emailr.   r/   rP   r0   r0   r1   r`   s  s    



zMail.add_bccc                 C   s   | j S )z;The global Subject object

        :rtype: Subject
        )r"   r5   r0   r0   r1   r'     s    zMail.subjectc                 C   s|   t |trn|jdk	rfz| j|j }d}W n tk
rF   t }d}Y nX |j|_|sl| j||jd qx|| _n
t|| _dS )z|The subject of the email(s)

        :param value: The subject of the email(s)
        :type value: Subject, string
        NTFrI   )	rJ   r   rR   r   rO   r   r'   rL   r"   r,   valuerR   rT   r0   r0   r1   r'     s"    



c                 C   s   | j S )zFA list of global Header objects

        :rtype: list(Header)
        )r   r5   r0   r0   r1   headers  s    zMail.headersc                 C   s   d S rV   r0   r5   r0   r0   r1   header  s    zMail.headerc                 C   s.   t |tr |D ]}| | qn
| | dS )zAdd headers to the email

        :param value: A list of Header objects or a dict of header key/values
        :type value: Header, list(Header), dict
        N)rJ   rK   
add_header)r,   rd   hr0   r0   r1   re     s    
c                 C   s   |j dk	rz| j|j  }d}W n tk
r<   t }d}Y nX t|trnt| d \}}|t	|| n
|| |s| j
||j d nFt|trt| d \}}| t	||| j| _n| || j| _dS )zAdd headers to the email globaly or to a specific Personalization

        :param value: A Header object or a dict of header key/values
        :type value: Header, dict
        NTFr7   rI   )rR   r   rO   r   rJ   rF   rK   rB   rf   r	   rL   r<   r   )r,   re   rR   rT   rC   rD   r0   r0   r1   rf     s0    





 zMail.add_headerc                 C   s   d S rV   r0   r5   r0   r0   r1   rS     s    zMail.substitutionc                 C   s.   t |tr |D ]}| | qn
| | dS )zAdd substitutions to the email

        :param value: Add substitutions to the email
        :type value: Substitution, list(Substitution)
        N)rJ   rK   rN   )r,   rS   sr0   r0   r1   rS     s    
c                 C   s   |j rZz| j|j  }d}W n tk
r8   t }d}Y nX || |s| j||j d nBt|tr|D ]}| jD ]}|| qrqhn| jD ]}|| qdS )zAdd a substitution to the email

        :param value: Add a substitution to the email
        :type value: Substitution
        TFrI   N)	rR   r   rO   r   rN   rL   rJ   rK   rM   )r,   rS   rR   rT   rh   rP   r0   r0   r1   rN     s(    


 


zMail.add_substitutionc                 C   s   | j S )zLA list of global CustomArg objects

        :rtype: list(CustomArg)
        r   r5   r0   r0   r1   custom_args  s    zMail.custom_argsc                 C   s   | j S rV   ri   r5   r0   r0   r1   
custom_arg"  s    zMail.custom_argc                 C   s.   t |tr |D ]}| | qn
| | dS )zAdd custom args to the email

        :param value: A list of CustomArg objects or a dict of custom arg
                      key/values
        :type value: CustomArg, list(CustomArg), dict
        N)rJ   rK   add_custom_arg)r,   rk   cr0   r0   r1   rk   &  s    
c                 C   s   t |ts|jdk	rz| j|j }d}W n tk
rF   t }d}Y nX t |trxt| d \}}|t	|| n
|| |s| j
||jd nFt |trt| d \}}| t	||| j| _n| || j| _dS )zAdd custom args to the email globaly or to a specific Personalization

        :param value: A CustomArg object or a dict of custom arg key/values
        :type value: CustomArg, dict
        NTFr7   rI   )rJ   rF   rR   r   rO   r   rK   rB   rl   r   rL   r<   r   )r,   rk   rR   rT   rC   rD   r0   r0   r1   rl   4  s6    



 
  zMail.add_custom_argc                 C   s   | j S )z9The global SendAt object

        :rtype: SendAt
        )r!   r5   r0   r0   r1   send_atT  s    zMail.send_atc                 C   s|   t |trn|jdk	rfz| j|j }d}W n tk
rF   t }d}Y nX |j|_|sl| j||jd qx|| _n
t|| _dS )zA unix timestamp specifying when your email should
        be delivered.

        :param value: A unix timestamp specifying when your email should
        be delivered.
        :type value: SendAt, int
        NTFrI   )	rJ   r   rR   r   rO   r   rn   rL   r!   rb   r0   r0   r1   rn   \  s"    	



 c                 C   s   d S rV   r0   r5   r0   r0   r1   dynamic_template_datax  s    zMail.dynamic_template_datac                 C   sf   t |tst|}z| j|j }d}W n tk
rD   t }d}Y nX |j|_|sb| j||jd dS )zData for a transactional template

        :param value: Data for a transactional template
        :type value: DynamicTemplateData, a JSON-serializable structure
        TFrI   N)rJ   r   r   rR   rO   r   ro   rL   rb   r0   r0   r1   ro   |  s    

 c                 C   s   | j S )z>The email address of the sender

        :rtype: From
        )r   r5   r0   r0   r1   r%     s    zMail.from_emailc                 C   s:   t |trt|d}t |tr0t|d |d }|| _dS )zThe email address of the sender

        :param value: The email address of the sender
        :type value: From, str, tuple
        Nr7   r   )rJ   r3   r   rX   r   r,   rc   r0   r0   r1   r%     s
    


c                 C   s   | j S )z<The reply to email address

        :rtype: ReplyTo
        )r   r5   r0   r0   r1   reply_to  s    zMail.reply_toc                 C   s:   t |trt|d}t |tr0t|d |d }|| _dS )z~The reply to email address

        :param value: The reply to email address
        :type value: ReplyTo, str, tuple
        Nr7   r   )rJ   r3   r   rX   r   rp   r0   r0   r1   rq     s
    


c                 C   s   | j S )zPA list of ReplyTo email addresses

        :rtype: list(ReplyTo), tuple
        )r    r5   r0   r0   r1   reply_to_list  s    zMail.reply_to_listc                 C   sF   t |trB|D ],}t |tr2t |jts:tdqtdq|| _dS )zA list of ReplyTo email addresses

        :param value: A list of ReplyTo email addresses
        :type value: list(ReplyTo), tuple
        z;You must provide an email for each entry in a reply_to_listz2Please use a list of ReplyTos for a reply_to_list.N)rJ   rK   r   rQ   r3   rY   r    )r,   rc   Zreplyr0   r0   r1   rr     s    


c                 C   s   | j S )zAThe contents of the email

        :rtype: list(Content)
        )r   r5   r0   r0   r1   contents  s    zMail.contentsc                 C   s   d S rV   r0   r5   r0   r0   r1   content  s    zMail.contentc                 C   s.   t |tr |D ]}| | qn
| | dS )zThe content(s) of the email

        :param contents: The content(s) of the email
        :type contents: Content, list(Content)
        N)rJ   rK   r(   )r,   rs   rm   r0   r0   r1   rt     s    
c                 C   s   t |trt||}|jtjkr2| || j| _n|jtjkr| jr|| jD ].}|jtjkrdd} qqJ|jtj	krJd} qqJnd}| j
|| j|d| _n*| jrt| j}nd}| j
|| j|d| _dS )zAdd content to the email

        :param contents: Content to be added to the email
        :type contents: Content
        :param mime_type: Override the mime type
        :type mime_type: MimeType, str
        r   r7   rI   N)rJ   r3   r   	mime_typer
   r)   r=   r   r*   r+   r<   len)r,   rt   ru   _contentr;   r0   r0   r1   r(     s6    


  
  zMail.add_contentc                 C   s   | j S )zHThe attachments to this email

        :rtype: list(Attachment)
        )r   r5   r0   r0   r1   attachments  s    zMail.attachmentsc                 C   s   d S rV   r0   r5   r0   r0   r1   
attachment  s    zMail.attachmentc                 C   s.   t |tr |D ]}| | qn
| | dS )zAdd attachment(s) to this email

        :param attachment: Add attachment(s) to this email
        :type attachment: Attachment, list(Attachment)
        N)rJ   rK   add_attachment)r,   ry   ar0   r0   r1   ry     s    
c                 C   s   |  || j| _dS )zAdd an attachment to this email

        :param attachment: Add an attachment to this email
        :type attachment: Attachment
        N)r<   r   )r,   ry   r0   r0   r1   rz   *  s    zMail.add_attachmentc                 C   s   | j S )zQThe transactional template id for this email

        :rtype: TemplateId
        )r#   r5   r0   r0   r1   template_id2  s    zMail.template_idc                 C   s    t |tr|| _n
t|| _dS )zThe transactional template id for this email

        :param value: The transactional template id for this email
        :type value: TemplateId
        N)rJ   r   r#   rp   r0   r0   r1   r|   :  s    
c                 C   s   | j S )zXThe block sections of code to be used as substitutions

        :rtype: Section
        )r   r5   r0   r0   r1   sectionsF  s    zMail.sectionsc                 C   s   d S rV   r0   r5   r0   r0   r1   sectionN  s    zMail.sectionc                 C   s.   t |tr |D ]}| | qn
| | dS )zgThe block sections of code to be used as substitutions

        :rtype: Section, list(Section)
        N)rJ   rK   add_section)r,   r~   rg   r0   r0   r1   r~   R  s    
c                 C   s   |  || j| _dS )zA block section of code to be used as substitutions

        :param section: A block section of code to be used as substitutions
        :type section: Section
        N)r<   r   )r,   r~   r0   r0   r1   r   ^  s    zMail.add_sectionc                 C   s   | j S )zPThe categories assigned to this message

        :rtype: list(Category)
        )r   r5   r0   r0   r1   
categoriesf  s    zMail.categoriesc                 C   s   d S rV   r0   r5   r0   r0   r1   categoryn  s    zMail.categoryc                 C   s.   t |tr |D ]}| | qn
| | dS )zPAdd categories assigned to this message

        :rtype: list(Category)
        N)rJ   rK   add_category)r,   r   rm   r0   r0   r1   r   r  s    
c                 C   s   |  || j| _dS )zJAdd a category assigned to this message

        :rtype: Category
        N)r<   r   )r,   r   r0   r0   r1   r   ~  s    zMail.add_categoryc                 C   s   | j S )z=The batch id for this email

        :rtype: BatchId
        r   r5   r0   r0   r1   batch_id  s    zMail.batch_idc                 C   s
   || _ dS )ztThe batch id for this email

        :param value: The batch id for this email
        :type value: BatchId
        Nr   rp   r0   r0   r1   r     s    c                 C   s   | j S )zHAn object specifying unsubscribe behavior.

        :rtype: Asm
        r   r5   r0   r0   r1   asm  s    zMail.asmc                 C   s
   || _ dS )zAn object specifying unsubscribe behavior.

        :param value: An object specifying unsubscribe behavior.
        :type value: Asm
        Nr   rp   r0   r0   r1   r     s    c                 C   s   | j S )z\The IP Pool that you would like to send this email from

        :rtype: IpPoolName
        r   r5   r0   r0   r1   ip_pool_name  s    zMail.ip_pool_namec                 C   s
   || _ dS )zThe IP Pool that you would like to send this email from

        :paran value: The IP Pool that you would like to send this email from
        :type value: IpPoolName
        Nr   rp   r0   r0   r1   r     s    c                 C   s   | j S )zGThe mail settings for this email

        :rtype: MailSettings
        r   r5   r0   r0   r1   mail_settings  s    zMail.mail_settingsc                 C   s
   || _ dS )zThe mail settings for this email

        :param value: The mail settings for this email
        :type value: MailSettings
        Nr   rp   r0   r0   r1   r     s    c                 C   s   | j S )zOThe tracking settings for this email

        :rtype: TrackingSettings
        r$   r5   r0   r0   r1   tracking_settings  s    zMail.tracking_settingsc                 C   s
   || _ dS )zThe tracking settings for this email

        :param value: The tracking settings for this email
        :type value: TrackingSettings
        Nr   rp   r0   r0   r1   r     s    c                 C   s   |  | j|  | jdd | jp"g D dd | jp4g D dd | jpFg D |  | j| | j| | j	dd | j
pvg D | | j|  | j|  | j|  | j|  | j|  | j|  | j|  | jdd | jpg D d}dd	 | D S )
z
        Get a JSON-ready representation of this Mail object.

        :returns: This Mail object, ready for use in a request body.
        :rtype: dict
        c                 S   s   g | ]}|  qS r0   r>   )r?   rP   r0   r0   r1   rA     s     zMail.get.<locals>.<listcomp>c                 S   s   g | ]}|  qS r0   r>   r?   rm   r0   r0   r1   rA     s     c                 S   s   g | ]}|  qS r0   r>   )r?   r{   r0   r0   r1   rA     s     c                 S   s   g | ]}|  qS r0   r>   r   r0   r0   r1   rA     s     c                 S   s   g | ]}|  qS r0   r>   )r?   rr0   r0   r1   rA     s     )fromr'   rM   rt   rx   r|   r}   rd   r   rj   rn   r   r   r   r   r   rq   rr   c                 S   s.   i | ]&\}}|d k	r|g kr|i kr||qS rV   r0   )r?   keyrc   r0   r0   r1   rE     s       zMail.get.<locals>.<dictcomp>)rH   r%   r'   rM   rs   rx   r|   rG   r}   rd   r   rj   rn   r   r   r   r   r   rq   rr   rB   )r,   mailr0   r0   r1   r4     s(    












zMail.getc                 C   s   | t |d|dt |dd}z| }W n tk
rP   | }Y nX |t| |  |	 D ]\}}|
t|| qr|S )zCreate a Mail object from an instance of
        email.message.EmailMessage.

        :type message: email.message.EmailMessage
        :rtype: Mail
        r   r   r   )r%   r'   r-   )r   r4   get_contentAttributeErrorget_payloadr(   r   get_content_typestriprB   rf   r	   )clsmessager   bodyrC   rD   r0   r0   r1   from_EmailMessage  s     zMail.from_EmailMessage)NNNNNNNF)r7   )NFr7   )r7   )NFr7   )NFr7   )NFr7   )NFr7   )NFr7   )NFr7   )N)8__name__
__module____qualname____doc__r2   r6   r<   r=   rG   rH   rU   propertyrM   rL   rW   setterr&   r[   r\   r_   r`   r'   rd   re   rf   rS   rN   rj   rk   rl   rn   ro   r%   rq   rr   rs   rt   r(   rx   ry   rz   r|   r}   r~   r   r   r   r   r   r   r   r   r   r4   classmethodr   r0   r0   r0   r1   r      s&          
<


     
9


     
#
     

   #   





 




 













#




















r   N)#r   ra   r   r^   r   rt   r   rk   r   ro   r   rQ   r   r%   r   re   r	   ru   r
   rR   r   rq   r   rn   r   r'   r   rS   r   r|   r   rZ   r   objectr   r0   r0   r0   r1   <module>   s"   