ó
®â0_c           @  sb  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m	 Z
 m Z 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 m Z 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& e j d ƒ Z' d e' _) e j d ƒ Z* e j+ e* _) d Z, d Z- d e. f d „  ƒ  YZ/ d d d „ Z0 d d d d d d d d d d d  h Z1 d! „  Z2 d" „  Z3 d# „  Z4 d$ d0 d% „  ƒ  YZ5 d& e5 e f d' „  ƒ  YZ6 d( e5 e f d) „  ƒ  YZ7 d* e5 e f d+ „  ƒ  YZ8 d, e9 f d- „  ƒ  YZ: d. e: f d/ „  ƒ  YZ; d S(1   iÿÿÿÿ(   t   unicode_literalsN(   t   charsett   encoderst	   generatort   message_from_string(   t   Header(   t   Message(   t   MIMEBase(   t   MIMEMessage(   t   MIMEMultipart(   t   MIMEText(   t
   formatdatet   getaddressest	   parseaddr(   t   BytesIO(   t   settings(   t   DNS_NAME(   t   six(   t
   force_textu   utf-8u   application/octet-streamiæ  t   BadHeaderErrorc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyR   &   s   c         C  s“   t  j  ƒ  } t  j d t  j | ƒ ƒ } t j ƒ  } t j d ƒ } |  d k rW d }  n
 d |  }  | d k rv t } n  d | | | |  | f } | S(   un  Returns a string suitable for RFC 5322 compliant Message-ID, e.g:

    <20020201195627.33539.96671@nightshade.la.mastaler.com>

    Optional idstring if given is a string used to strengthen the
    uniqueness of the message id.  Optional domain if given provides the
    portion of the message id after the '@'.  It defaults to the locally
    defined hostname.
    u   %Y%m%d%H%M%Si † u    u   .u   <%s.%s.%s%s@%s>N(	   t   timet   strftimet   gmtimet   ost   getpidt   randomt	   randranget   NoneR   (   t   idstringt   domaint   timevalt   utcdatet   pidt   randintt   msgid(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt
   make_msgid.   s    
	
	u   fromu   senderu   reply-tou   tou   ccu   bccu   resent-fromu   resent-senderu	   resent-tou	   resent-ccu
   resent-bccc           sú   ˆ  p t  j ‰  t | ƒ } d | k s3 d | k rL t d | |  f ƒ ‚ n  y | j d ƒ Wnc t k
 rÂ |  j ƒ  t k rª d j ‡  f d †  t	 | f ƒ Dƒ ƒ } qê t
 | ˆ  ƒ j ƒ  } n( X|  j ƒ  d k rê t
 | ƒ j ƒ  } n  t |  ƒ | f S(   u8   Forbids multi-line headers, to prevent header injection.u   
u   u;   Header values can't contain newlines (got %r for header %r)u   asciiu   , c         3  s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   t   sanitize_address(   t   .0t   addr(   t   encoding(    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pys	   <genexpr>a   s    u   subject(   R   t   DEFAULT_CHARSETR   R   t   encodet   UnicodeEncodeErrort   lowert   ADDRESS_HEADERSt   joinR   R   t   str(   t   namet   valR)   (    (   R)   s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt   forbid_multi_line_headersW   s    +c         C  sž   d |  k ry |  j  d d ƒ \ } } y | j d ƒ Wn& t k
 r] t | | ƒ j ƒ  } n X| j d ƒ j d ƒ } n t |  | ƒ j ƒ  } d } | | f S(   u÷   
    Split the address into local part and domain, properly encoded.

    When non-ascii characters are present in the local part, it must be
    MIME-word encoded. The domain name must be idna-encoded if it contains
    non-ascii characters.
    u   @i   u   asciiu   idnau    (   t   splitR+   R,   R   t   decode(   R(   R)   t	   localpartR   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt
   split_addrj   s    c   
      C  s“  t  |  t ƒ s$ t t |  ƒ ƒ }  n  |  \ } }  d \ } } t | | ƒ j ƒ  } y |  j d ƒ Wn& t k
 rŠ t |  | ƒ \ } } n Xt	 j
 rØ d d l m } | rÈ | rÈ d j | | g ƒ }  n  | | |  f ƒ Sd d l m } d d l m } m } | r,| r,| | d | d | ƒ}	 t |	 ƒ Sy | | d	 |  ƒ}	 WnD | | f k
 rˆt |  | ƒ \ } } | | d | d | ƒ}	 n Xt |	 ƒ S(   uF   
    Format a pair of (name, address) or an email address string.
    u   asciiiÿÿÿÿ(   t
   formataddru   @(   t   Address(   t   InvalidHeaderDefectt   NonASCIILocalPartDefectt   usernameR   t	   addr_specN(   NN(   t
   isinstancet   tupleR   R   R   R   R+   R,   R7   R   t   PY2t   email.utilsR8   R/   t   email.headerregistryR9   t   email.errorsR:   R;   R0   (
   R(   R)   t   nmR6   R   R8   R9   R:   R;   t   address(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyR&   ‚   s2    	
t	   MIMEMixinc           B  s8   e  Z e d  d „ Z e j r' e Z n e d  d „ Z RS(   u   
c         C  sc   t  j ƒ  } t j | d t ƒ} t  j r@ | j |  d | ƒn | j |  d | d | ƒ| j ƒ  S(   u&  Return the entire formatted message as a string.
        Optional `unixfrom' when True, means include the Unix From_ envelope
        header.

        This overrides the default as_string() implementation to not mangle
        lines that begin with 'From '. See bug #13433 for details.
        t   mangle_from_t   unixfromt   linesep(   R   t   StringIOR   t	   Generatort   FalseR@   t   flattent   getvalue(   t   selfRH   RI   t   fpt   g(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt	   as_string©   s    	c         C  sA   t  ƒ  } t j | d t ƒ} | j |  d | d | ƒ| j ƒ  S(   u6  Return the entire formatted message as bytes.
            Optional `unixfrom' when True, means include the Unix From_ envelope
            header.

            This overrides the default as_bytes() implementation to not mangle
            lines that begin with 'From '. See bug #13433 for details.
            RG   RH   RI   (   R   R   t   BytesGeneratorRL   RM   RN   (   RO   RH   RI   RP   RQ   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt   as_bytes¼   s    	(   R   R   RL   RR   R   R@   RT   (    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRF   ¨   s   		t   SafeMIMEMessagec           B  s   e  Z d  „  Z RS(   c         C  s/   t  | | d ƒ \ } } t j |  | | ƒ d  S(   Nu   ascii(   R3   R   t   __setitem__(   RO   R1   R2   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRV   Ì   s    (   R   R   RV   (    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRU   Ê   s   t   SafeMIMETextc           B  s,   e  Z d  d d „ Z d „  Z d d „ Z RS(   u   plainc         C  s)   | |  _  t j |  | d | d | ƒd  S(   Nt   _subtypet   _charset(   R)   R
   t   __init__(   RO   t   _textRX   RY   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRZ   Ô   s    	c         C  s2   t  | | |  j ƒ \ } } t j |  | | ƒ d  S(   N(   R3   R)   R
   RV   (   RO   R1   R2   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRV   Ø   s    c         C  sW   | d k r= t  d „  | j ƒ  Dƒ ƒ } | r4 t n t } n  t j |  | d | ƒd  S(   Nu   utf-8c         s  s*   |  ]  } t  | j d  ƒ ƒ t k Vq d S(   u   utf-8N(   t   lenR+   t   RFC5322_EMAIL_LINE_LENGTH_LIMIT(   R'   t   l(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pys	   <genexpr>ß   s   R   (   t   anyt
   splitlinest   utf8_charset_qpt   utf8_charsetR
   t   set_payload(   RO   t   payloadR   t   has_long_lines(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRc   Ü   s    N(   R   R   R   RZ   RV   Rc   (    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRW   Ò   s   	t   SafeMIMEMultipartc           B  s&   e  Z d  d d d d „ Z d „  Z RS(   u   mixedc         K  s&   | |  _  t j |  | | | |  d  S(   N(   R)   R	   RZ   (   RO   RX   t   boundaryt	   _subpartsR)   t   _params(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRZ   ê   s    	c         C  s2   t  | | |  j ƒ \ } } t j |  | | ƒ d  S(   N(   R3   R)   R	   RV   (   RO   R1   R2   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRV   î   s    N(   R   R   R   RZ   RV   (    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRf   è   s   t   EmailMessagec           B  s¶   e  Z d  Z d Z d Z d Z d d d d d d d d d d d „
 Z e d „ Z	 d „  Z
 d „  Z e d „ Z d d d d	 „ Z d d
 „ Z d „  Z d „  Z d „  Z d d „ Z RS(   u,   
    A container for email information.
    u   plainu   mixedu    c         C  s—  | r9 t  | t j ƒ r' t d ƒ ‚ n  t | ƒ |  _ n	 g  |  _ |	 r{ t  |	 t j ƒ ri t d ƒ ‚ n  t |	 ƒ |  _ n	 g  |  _ | r½ t  | t j ƒ r« t d ƒ ‚ n  t | ƒ |  _ n	 g  |  _ |
 rÿ t  |
 t j ƒ rí t d ƒ ‚ n  t |
 ƒ |  _ n	 g  |  _ | pt	 j
 |  _ | |  _ | |  _ g  |  _ | r{x= | D]2 } t  | t ƒ rg|  j | ƒ qB|  j | Œ  qBWn  | p„i  |  _ | |  _ d S(   u  
        Initialize a single email message (which can be sent to multiple
        recipients).

        All strings used to create the message can be unicode strings
        (or UTF-8 bytestrings). The SafeMIMEText class will handle any
        necessary encoding conversions.
        u%   "to" argument must be a list or tupleu%   "cc" argument must be a list or tupleu&   "bcc" argument must be a list or tupleu+   "reply_to" argument must be a list or tupleN(   R>   R   t   string_typest	   TypeErrort   listt   tot   cct   bcct   reply_toR   t   DEFAULT_FROM_EMAILt
   from_emailt   subjectt   bodyt   attachmentsR   t   attacht   extra_headerst
   connection(   RO   Rt   Ru   Rs   Rn   Rp   Ry   Rv   t   headersRo   Rq   t
   attachment(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRZ   û   s>    							c         C  s5   d d l  m } |  j s. | d | ƒ |  _ n  |  j S(   Niÿÿÿÿ(   t   get_connectiont   fail_silently(   t   django.core.mailR|   Ry   (   RO   R}   R|   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyR|   +  s    	c         C  s¤  |  j  p t j } t |  j |  j | ƒ } |  j | ƒ } |  j | d <|  j j	 d |  j
 ƒ | d <|  j j	 d d j t t |  j ƒ ƒ ƒ | d <|  j r» d j t t |  j ƒ ƒ | d <n  |  j rõ |  j j	 d d j t t |  j ƒ ƒ ƒ | d <n  g  |  j D] } | j ƒ  ^ qÿ } d | k r<t d t j ƒ | d	 <n  d
 | k r^t d t ƒ | d <n  x? |  j j ƒ  D]. \ } } | j ƒ  d k r’qnn  | | | <qnW| S(   Nu   Subjectu   Fromu   Tou   , u   Ccu   Reply-Tou   datet	   localtimeu   Dateu
   message-idR   u
   Message-IDu   fromu   to(   u   fromu   to(   R)   R   R*   RW   Ru   t   content_subtypet   _create_messageRt   Rx   t   getRs   R/   t   mapR   Rn   Ro   Rq   R-   R   t   EMAIL_USE_LOCALTIMER%   R   t   items(   RO   R)   t   msgt   keyt   header_namesR1   t   value(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt   message1  s(    .	"	1"c         C  s.   g  |  j  |  j |  j D] } | r | ^ q S(   uƒ   
        Returns a list of all recipients of the email (includes direct
        addressees as well as Cc and Bcc entries).
        (   Rn   Ro   Rp   (   RO   t   email(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt
   recipientsO  s    c         C  s)   |  j  ƒ  s d S|  j | ƒ j |  g ƒ S(   u   Sends the email message.i    (   RŒ   R|   t   send_messages(   RO   R}   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt   sendV  s    c         C  s  t  | t ƒ rF | d k s! t ‚ | d k s3 t ‚ |  j j | ƒ nÁ | d k	 sX t ‚ | s… t j | ƒ \ } } | s… t } q… n  | j	 d d ƒ \ } } | d k rî t  | t
 j ƒ rî y | j d ƒ } Wqë t k
 rç t } që Xqî n  |  j j | | | f ƒ d S(   u  
        Attaches a file with the given filename and content. The filename can
        be omitted and the mimetype is guessed, if not provided.

        If the first parameter is a MIMEBase subclass it is inserted directly
        into the resulting message attachments.

        For a text/* mimetype (guessed or specified), when a bytes object is
        specified as content, it will be decoded as UTF-8. If that fails,
        the mimetype will be set to DEFAULT_ATTACHMENT_MIME_TYPE and the
        content is not decoded.
        u   /i   u   textu   utf-8N(   R>   R   R   t   AssertionErrorRv   t   appendt	   mimetypest
   guess_typet   DEFAULT_ATTACHMENT_MIME_TYPER4   R   t   binary_typeR5   t   UnicodeDecodeError(   RO   t   filenamet   contentt   mimetypet   _t   basetypet   subtype(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRw   ^  s"    c         C  sM   t  j j | ƒ } t | d ƒ & } | j ƒ  } |  j | | | ƒ Wd QXd S(   uŽ  
        Attaches a file from the filesystem.

        The mimetype will be set to the DEFAULT_ATTACHMENT_MIME_TYPE if it is
        not specified and cannot be guessed.

        For a text/* mimetype (guessed or specified), the file's content
        will be decoded as UTF-8. If that fails, the mimetype will be set to
        DEFAULT_ATTACHMENT_MIME_TYPE and the content is not decoded.
        u   rbN(   R   t   patht   basenamet   opent   readRw   (   RO   Rœ   R˜   R–   t   fileR—   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt   attach_fileƒ  s    c         C  s   |  j  | ƒ S(   N(   t   _create_attachments(   RO   R†   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyR   ”  s    c         C  s¢   |  j  rž |  j p t j } | } t d |  j d | ƒ } |  j rR | j | ƒ n  xI |  j  D]; } t | t	 ƒ r | j | ƒ q\ | j |  j
 | Œ  ƒ q\ Wn  | S(   NRX   R)   (   Rv   R)   R   R*   Rf   t   mixed_subtypeRu   Rw   R>   R   t   _create_attachment(   RO   R†   R)   t   body_msgR{   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyR¢   —  s    		c         C  sÞ   | j  d d ƒ \ } } | d k rK |  j p3 t j } t | | | ƒ } n | d k r± | d k r± t | t ƒ r | j ƒ  } n t | t ƒ sŸ t	 | ƒ } n  t
 | | ƒ } n) t | | ƒ } | j | ƒ t j | ƒ | S(   uÒ   
        Converts the content, mimetype pair into a MIME attachment object.

        If the mimetype is message/rfc822, content may be an
        email.Message or EmailMessage object, as well as a str.
        u   /i   u   textu   messageu   rfc822(   R4   R)   R   R*   RW   R>   Rj   RŠ   R   R   RU   R   Rc   t   Encoderst   encode_base64(   RO   R—   R˜   Rš   R›   R)   R{   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt   _create_mime_attachment¥  s    c         C  s„   |  j  | | ƒ } | r€ y | j d ƒ Wn; t k
 rf t j rT | j d ƒ } n  d d | f } n X| j d d d | ƒn  | S(   uh   
        Converts the filename, content, mimetype triple into a MIME attachment
        object.
        u   asciiu   utf-8u    u   Content-Dispositionu
   attachmentR–   (   R¨   R+   R,   R   R@   t
   add_header(   RO   R–   R—   R˜   R{   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyR¤   Ã  s    	
N(   R   R   t   __doc__R€   R£   R   R)   RZ   RL   R|   RŠ   RŒ   RŽ   Rw   R¡   R   R¢   R¨   R¤   (    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRj   ó   s"   .		%			t   EmailMultiAlternativesc           B  sY   e  Z d  Z d Z d d d d d d d d d d d d „ Z d „  Z d „  Z d „  Z RS(   u°   
    A version of EmailMessage that makes it easy to send multipart/alternative
    messages. For example, including text and HTML versions of the text is
    made easier.
    u   alternativeu    c         C  sD   t  t |  ƒ j | | | | | | | | |
 | ƒ
 |	 p: g  |  _ d S(   u  
        Initialize a single email message (which can be sent to multiple
        recipients).

        All strings used to create the message can be unicode strings (or UTF-8
        bytestrings). The SafeMIMEText class will handle any necessary encoding
        conversions.
        N(   t   superR«   RZ   t   alternatives(   RO   Rt   Ru   Rs   Rn   Rp   Ry   Rv   Rz   R­   Ro   Rq   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyRZ   Ý  s    c         C  s>   | d k	 s t ‚ | d k	 s$ t ‚ |  j j | | f ƒ d S(   u-   Attach an alternative content representation.N(   R   R   R­   R   (   RO   R—   R˜   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt   attach_alternativeî  s    c         C  s   |  j  |  j | ƒ ƒ S(   N(   R¢   t   _create_alternatives(   RO   R†   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyR   ô  s    c         C  sƒ   |  j  p t j } |  j r | } t d |  j d | ƒ } |  j rR | j | ƒ n  x* |  j D] } | j |  j | Œ  ƒ q\ Wn  | S(   NRX   R)   (	   R)   R   R*   R­   Rf   t   alternative_subtypeRu   Rw   R¨   (   RO   R†   R)   R¥   t   alternative(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyR¯   ÷  s    		N(	   R   R   Rª   R°   R   RZ   R®   R   R¯   (    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyR«   Õ  s   		(    (<   t
   __future__R    R‘   R   R   R   R‹   R   t   CharsetR   R¦   R   R   t   email.headerR   t   email.messageR   t   email.mime.baseR   t   email.mime.messageR   t   email.mime.multipartR	   t   email.mime.textR
   RA   R   R   R   t   ioR   t   django.confR   t   django.core.mail.utilsR   t   django.utilsR   t   django.utils.encodingR   Rb   R   t   body_encodingRa   t   QPR“   R]   t
   ValueErrorR   R%   R.   R3   R7   R&   RF   RU   RW   Rf   t   objectRj   R«   (    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/mail/message.pyt   <module>   sZ   "					&"â