
    gE                     $   d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ d dl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mZmZmZ d dlmZm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z(m)Z)  ej                  d      Z*de*_+         ej                  d      Z,ejZ                  e,_+        dZ.dZ/ G d de0      Z1h dZ2d Z3d Z4 G d d      Z5 G d de5e      Z6 G d d e5e      Z7 G d! d"e5e      Z8 G d# d$      Z9 G d% d&e9      Z:y)'    Ncharset)encoders)	generatormessage_from_string)HeaderParseError)Header)Addressparser)Message)MIMEBase)MIMEMessage)MIMEMultipart)MIMEText)
formataddr
formatdategetaddresses
make_msgid)BytesIOStringIO)Path)settings)DNS_NAME)	force_strpunycodeutf-8zapplication/octet-streami  c                       e Zd Zy)BadHeaderErrorN)__name__
__module____qualname__     p/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/core/mail/message.pyr   r   #   s    r#   r   >   reply-to	resent-cc	resent-to
resent-bccresent-fromresent-sendercctobccfromsenderc                    xs t         j                  t        |      }d|v sd|v rt        d|d| d      	 |j	                  d       | j                         dk(  rt        |      j	                         }| |fS # t        $ r[ | j                         t        v r%dj                  fd	t        |f      D              }nt        |      j	                         }Y | |fS w xY w)
z6Forbid multi-line headers to prevent header injection.
z*Header values can't contain newlines (got z for header )asciisubject, c              3   6   K   | ]  }t        |        y wN)sanitize_address).0addrencodings     r$   	<genexpr>z,forbid_multi_line_headers.<locals>.<genexpr>C   s      =QT x0=Qs   )r   DEFAULT_CHARSETstrr   encodelowerr	   UnicodeEncodeErrorADDRESS_HEADERSjoinr   )namevalr<   s     `r$   forbid_multi_line_headersrG   7   s    3833H
c(Cs{dckMPRVW
 	
'

7 ::<9$+$$&C9  1::<?*)) =I3&=Q C h'..0C 91s   A= =AC! C!c                 H   d}t        | t              set        |       } 	 t        j                  |       \  }}|rt        d|d| d      |j                  xs d}|j                  }|j                  xs d}n-| \  }}d|vrt        d| d      |j                  dd	      \  }}||z   |z   }d
|v sd|v rt        d      	 |j                  d       t        |      j                         }	 |j                  d       t        |      }t!        ||      }	t#        ||	j$                  f      S # t        t
        t        f$ r t        d| z        w xY w# t        $ r t        ||      j                         }Y w xY w# t        $ r t        ||      j                         }Y w xY w)zF
    Format a pair of (name, address) or an email address string.
    NzInvalid address; only z could be parsed from "" zInvalid address "%s"@zInvalid address "   r1   r2   z7Invalid address; address parts cannot contain newlines.r4   )usernamedomain)
isinstancetupler   r   get_mailbox
ValueErrordisplay_name
local_partrN   r   
IndexErrorrsplitr@   r	   rB   r   r
   r   	addr_spec)
r;   r<   addresstokenrestnm	localpartrN   address_partsparsed_addresss
             r$   r9   r9   N   s    GdE"	( ,,T2KE4  LQSWX  ##)rB((I\\'RFGg0	;<<#NN32	6NV+M} 5RSS+
		'BZ 9! fFi?Nr>33455E !*j9 	<3d:;;	<2  +B!((*+  99h/668	9s/   D, *E ,E; ,#E#E87E8;#F! F!c                       e Zd ZddZddZy)	MIMEMixinc                     t               }t        j                  |d      }|j                  | ||       |j	                         S )a&  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.
        Fmangle_from_unixfromlinesep)r   r   	Generatorflattengetvalueselfre   rf   fpgs        r$   	as_stringzMIMEMixin.as_string}   s;     Z7			$7	;{{}r#   c                     t               }t        j                  |d      }|j                  | ||       |j	                         S )a"  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.
        Frb   rd   )r   r   BytesGeneratorrh   ri   rj   s        r$   as_byteszMIMEMixin.as_bytes   s;     Y$$Re<			$7	;{{}r#   N)Fr1   )r   r    r!   rn   rq   r"   r#   r$   r`   r`   |   s    r#   r`   c                       e Zd Zd Zy)SafeMIMEMessagec                 R    t        ||d      \  }}t        j                  | ||       y )Nr4   )rG   r   __setitem__rk   rE   rF   s      r$   ru   zSafeMIMEMessage.__setitem__   s&    -dCA	cdC0r#   N)r   r    r!   ru   r"   r#   r$   rs   rs      s    1r#   rs   c                   "    e Zd ZddZd ZddZy)SafeMIMETextNc                 D    || _         t        j                  | |||       y )N)_subtype_charset)r<   r   __init__)rk   _textrz   r{   s       r$   r|   zSafeMIMEText.__init__   s     $8Lr#   c                 f    t        ||| j                        \  }}t        j                  | ||       y r8   )rG   r<   r   ru   rv   s      r$   ru   zSafeMIMEText.__setitem__   s*    -dCG	cT4-r#   c                     |dk(  rHt        |t        j                        s.t        d |j                         D              }|rt        nt
        }t        j                  | ||       y )Nr   c              3   `   K   | ]&  }t        |j                  d             t        kD   ( yw)surrogateescape)errorsN)lenr@   RFC5322_EMAIL_LINE_LENGTH_LIMIT)r:   lines     r$   r=   z+SafeMIMEText.set_payload.<locals>.<genexpr>   s3      ! 1D DKK'8K9:120s   ,.r   )rO   Charsetany
splitlinesutf8_charset_qputf8_charsetr   set_payload)rk   payloadr   has_long_liness       r$   r   zSafeMIMEText.set_payload   sV    gj'//&J  ! $..0! N *8o\GT7G<r#   )plainNr8   )r   r    r!   r|   ru   r   r"   r#   r$   rx   rx      s    M.
=r#   rx   c                       e Zd Z	 ddZd Zy)SafeMIMEMultipartNc                 D    || _         t        j                  | |||fi | y r8   )r<   r   r|   )rk   rz   boundary	_subpartsr<   _paramss         r$   r|   zSafeMIMEMultipart.__init__   s$     !tXxNgNr#   c                 f    t        ||| j                        \  }}t        j                  | ||       y r8   )rG   r<   r   ru   rv   s      r$   ru   zSafeMIMEMultipart.__setitem__   s*    -dCG	c!!$c2r#   )mixedNNN)r   r    r!   r|   ru   r"   r#   r$   r   r      s    HLO3r#   r   c                       e Zd ZdZdZdZdZ	 	 	 	 	 	 	 	 	 	 ddZddZd Z	d Z
dd	Zdd
ZddZd Zd Zd ZddZd Zy)EmailMessagez"A container for email information.r   r   Nc                    |r,t        |t              rt        d      t        |      | _        ng | _        |	r,t        |	t              rt        d      t        |	      | _        ng | _        |r,t        |t              rt        d      t        |      | _        ng | _        |
r,t        |
t              rt        d      t        |
      | _        ng | _        |xs t        j                  | _
        || _        |xs d| _        g | _        |r8|D ]3  }t        |t              r| j                  |       % | j                  |  5 |xs i | _        || _        y)g
        Initialize a single email message (which can be sent to multiple
        recipients).
        z%"to" argument must be a list or tuplez%"cc" argument must be a list or tuplez&"bcc" argument must be a list or tuplez+"reply_to" argument must be a list or tuplerJ   N)rO   r?   	TypeErrorlistr,   r+   r-   reply_tor   DEFAULT_FROM_EMAIL
from_emailr5   bodyattachmentsr   attachextra_headers
connection)rk   r5   r   r   r,   r-   r   r   headersr+   r   
attachments               r$   r|   zEmailMessage.__init__   s"   " "c" GHH2hDGDG"c" GHH2hDGDG#s# HIICyDHDH(C( MNN NDMDM$C(C(CJB	)
j(3KK
+DKK,	 *
 %]$r#   c                 Z    ddl m} | j                  s ||      | _        | j                  S )Nr   )get_connection)fail_silently)django.core.mailr   r   )rk   r   r   s      r$   r   zEmailMessage.get_connection   s"    3,=IDOr#   c                    | j                   xs t        j                  }t        | j                  | j
                  |      }| j                  |      }| j                  |d<   | j                  j                  d| j                        |d<   | j                  |d| j                         | j                  |d| j                         | j                  |d| j                         | j                  D cg c]  }|j                          }}d|vrt!        t        j"                        |d<   d	|vrt%        t&        
      |d<   | j                  j)                         D ]  \  }}|j                         dk7  s|||<     |S c c}w )NSubjectFromToCczReply-Todate)	localtimeDatez
message-id)rN   z
Message-IDr.   )r<   r   r>   rx   r   content_subtype_create_messager5   r   getr   _set_list_header_if_not_emptyr,   r+   r   rA   r   EMAIL_USE_LOCALTIMEr   r   items)rk   r<   msgkeyheader_namesrE   values          r$   messagezEmailMessage.message  sG   ==<H$<$<499d&:&:HE""3'I((,,VT__EF**3dgg>**3dgg>**3
DMMJ 04/A/AB/A		/AB%
 %x/K/KLCK|+ *( ;C--335KD%zz|v%!D	 6 
 Cs   .E<c                 z    | j                   | j                  z   | j                  z   D cg c]  }|s|	 c}S c c}w )z
        Return a list of all recipients of the email (includes direct
        addressees as well as Cc and Bcc entries).
        )r,   r+   r-   )rk   emails     r$   
recipientszEmailMessage.recipients   s6    
 %)GGdgg$5$@K$@%U$@KKKs   88c                 f    | j                         sy| j                  |      j                  | g      S )zSend the email message.r   )r   r   send_messages)rk   r   s     r$   sendzEmailMessage.send'  s/      ""=1??GGr#   c                    t        |t              r+||t        d      | j                  j	                  |       y|t        d      |xs  t        j                  |      d   xs t        }|j                  dd      \  }}|dk(  r!t        |t              r	 |j                         }| j                  j	                  |||f       y# t        $ r	 t        }Y 0w xY w)a  
        Attach 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, insert it directly
        into the resulting message attachments.

        For a text/* mimetype (guessed or specified), when a bytes object is
        specified as content, decode it as UTF-8. If that fails, set the
        mimetype to DEFAULT_ATTACHMENT_MIME_TYPE and don't decode the content.
        NzLcontent and mimetype must not be given when a MIMEBase instance is provided.zcontent must be provided.r   /rL   text)rO   r   rR   r   append	mimetypes
guess_typeDEFAULT_ATTACHMENT_MIME_TYPEsplitbytesdecodeUnicodeDecodeError)rk   filenamecontentmimetypebasetypesubtypes         r$   r   zEmailMessage.attach/  s     h)"h&: ,  ##H-_899  0''1!40/ 
 !)sA 6Hg6!gu-@").."2 ##Xw$AB . @ $@@s   C CCc                     t        |      }|j                  d      5 }|j                         }| j                  |j                  ||       ddd       y# 1 sw Y   yxY w)al  
        Attach a file from the filesystem.

        Set the mimetype to DEFAULT_ATTACHMENT_MIME_TYPE if it isn't specified
        and cannot be guessed.

        For a text/* mimetype (guessed or specified), decode the file's content
        as UTF-8. If that fails, set the mimetype to
        DEFAULT_ATTACHMENT_MIME_TYPE and don't decode the content.
        rbN)r   openreadr   rE   )rk   pathr   filer   s        r$   attach_filezEmailMessage.attach_fileW  sC     DzYYt_iikGKK		7H5 __s   .AAc                 $    | j                  |      S r8   )_create_attachmentsrk   r   s     r$   r   zEmailMessage._create_messageg  s    '',,r#   c                    | j                   r| j                  xs t        j                  }|}t	        | j
                  |      }| j                  s|j                         r|j                  |       | j                   D ]B  }t        |t              r|j                  |       %|j                   | j                  |        D |S N)rz   r<   )r   r<   r   r>   r   mixed_subtyper   is_multipartr   rO   r   _create_attachment)rk   r   r<   body_msgr   s        r$   r   z EmailMessage._create_attachmentsj  s    }}@(@(@HH#T-?-?(SCyyH113

8$"..
j(3JJz*JJ6t66
CD	 /
 
r#   c                    |j                  dd      \  }}|dk(  r-| j                  xs t        j                  }t	        |||      }|S |dk(  rX|dk(  rSt        |t              r|j                         }n$t        |t              st        t        |            }t        ||      }|S t        ||      }|j                  |       t        j                  |       |S )z
        Convert 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.
        r   rL   r   r   rfc822)r   r<   r   r>   rx   rO   r   r   r   r   r   rs   r   r   Encodersencode_base64)rk   r   r   r   r   r<   r   s          r$   _create_mime_attachmentz$EmailMessage._create_mime_attachmentx  s     %NN32'v}}@(@(@H%gwAJ$ # "w(': '<0!//+1 .i.@A(':J  "(G4J""7+"":.r#   c                     | j                  ||      }|r&	 |j                  d       |j                  dd|       |S # t        $ r dd|f}Y &w xY w)zg
        Convert the filename, content, mimetype triple into a MIME attachment
        object.
        r4   r   rJ   zContent-Dispositionr   )r   )r   r@   rB   
add_header)rk   r   r   r   r   s        r$   r   zEmailMessage._create_attachment  sk    
 11'8D
3( !!%|h "   & 3#R23s   = AAc                     |r	 | j                   |   }|||<   yy# t        $ r dj                  d |D              }Y *w xY w)zt
        Set msg's header, either from self.extra_headers, if present, or from
        the values argument.
        r6   c              3   2   K   | ]  }t        |        y wr8   )r?   )r:   vs     r$   r=   z=EmailMessage._set_list_header_if_not_empty.<locals>.<genexpr>  s     !9&Q#a&&s   N)r   KeyErrorrD   )rk   r   headervaluesr   s        r$   r   z*EmailMessage._set_list_header_if_not_empty  sQ    
 :**62  CK   :		!9&!99:s    !>>)
rJ   rJ   NNNNNNNN)F)NNNr8   )r   r    r!   __doc__r   r   r<   r|   r   r   r   r   r   r   r   r   r   r   r   r"   r#   r$   r   r      su    ,OMH 4%l6LH&CP6 -< 
 r#   r   c                   P     e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 d fd	Zd Zd Zd Z xZ	S )EmailMultiAlternativesz
    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.
    alternativec                 L    t         |   |||||||||
|
       |	xs g | _        y)r   N)superr|   alternatives)rk   r5   r   r   r,   r-   r   r   r   r   r+   r   	__class__s               r$   r|   zEmailMultiAlternatives.__init__  s?    $ 		
 ).Br#   c                 \    ||t        d      | j                  j                  ||f       y)z-Attach an alternative content representation.Nz+Both content and mimetype must be provided.)rR   r   r   )rk   r   r   s      r$   attach_alternativez)EmailMultiAlternatives.attach_alternative  s1    ?h.JKK  '8!45r#   c                 B    | j                  | j                  |            S r8   )r   _create_alternativesr   s     r$   r   z&EmailMultiAlternatives._create_message  s    ''(A(A#(FGGr#   c                 $   | j                   xs t        j                  }| j                  re|}t	        | j
                  |      }| j                  r|j                  |       | j                  D ]   }|j                   | j                  |        " |S r   )	r<   r   r>   r   r   alternative_subtyper   r   r   )rk   r   r<   r   r   s        r$   r   z+EmailMultiAlternatives._create_alternatives  s}    ==<H$<$<H#11HC yy

8$#00

7477EF  1
r#   )rJ   rJ   NNNNNNNNN)
r   r    r!   r   r   r|   r   r   r   __classcell__)r   s   @r$   r   r     sI     ( /@6Hr#   r   );r   r   r   r   r   r   r   r   email.errorsr   email.headerr	   email.headerregistryr
   r   email.messager   email.mime.baser   email.mime.messager   email.mime.multipartr   email.mime.textr   email.utilsr   r   r   r   ior   r   pathlibr   django.confr   django.core.mail.utilsr   django.utils.encodingr   r   r   body_encodingr   QPr   r   rR   r   rC   rG   r9   r`   rs   rx   r   r   r   r"   r#   r$   <module>r     s     $ & 0 )  0 ! $ * . $ H H      + 5 ww'! !'//'* '

   : "% 	Z 	
.+6\ 81i 1=9h =,	3	= 	3o  o d=\ =r#   