
    LȂi\                     v   S SK rS SKrS SKrS SKrS SKJr  S SKJrJr  S SKJ	r
  S SKJr  S SKJr  S SKJr  S SKJrJrJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJrJrJr  S SK J!r!J"r"  S SK#J$r$  S SK%J&r&  S SK'J(r(  S SK)J*r*J+r+  S SK,J-r-J.r.J/r/  S SK0J1r1  \
R                  " S5      r2S\2l3        \
R                  " S5      r4\
Rj                  \4l3        Sr6Sr7\8r91 Skr:S r;S r< " S S5      r= " S S\=\5      r> " S S \=\5      r? " S! S"\=\5      r@\" S#S$S%/5      rA\" S&/ S'Q5      rB " S( S)5      rC " S* S+\C5      rDg),    N)
namedtuple)datetimetimezonecharset)	generator)HeaderParseError)Header)AddressAddressHeaderparser)MIMEBase)MIMEMessage)MIMEMultipart)MIMEText)
formataddrgetaddresses
make_msgid)BytesIOStringIO)Path)settings)DNS_NAME)RemovedInDjango70Warningdeprecate_posargs)force_bytes	force_strpunycode)get_current_timezoneutf-8zapplication/octet-streami  >   cctobccfromsenderreply-to	resent-cc	resent-to
resent-bccresent-fromresent-senderc                    ^ [         R                  " S[        5        T=(       d    [        R                  m[        U5      nSU;   d  SU;   a  [        SU< SU < S35      e UR                  S5        U R                  5       S:X  a  [        U5      R                  5       nX4$ ! [         a`    U R                  5       [        ;   a)  S	R                  U4S
 j[        U45       5       5      n X4$ [        UT5      R                  5       n X4$ f = f)z6Forbid multi-line headers to prevent header injection.zThe internal API forbid_multi_line_headers() is deprecated. Python's modern email API (with email.message.EmailMessage or email.policy.default) will reject multi-line headers.
z*Header values can't contain newlines (got z for header )asciisubject, c              3   :   >#    U H  n[        UT5      v   M     g 7fN)sanitize_address).0addrencodings     ID:\sksbv-state-backend\venv\Lib\site-packages\django/core/mail/message.py	<genexpr>,forbid_multi_line_headers.<locals>.<genexpr>U   s       =QT x00=Qs   )warningswarnr   r   DEFAULT_CHARSETstrBadHeaderErrorencodelowerr
   UnicodeEncodeErrorADDRESS_HEADERSjoinr   )namevalr8   s     `r9   forbid_multi_line_headersrH   B   s    MM	A 	!	 3833H
c(Cs{dckMPRVW
 	
'

7 ::<9$+$$&C9  1::<?*)) =I3&=Q C 9	 h'..0C 91s   "B# #AD.DDc                    [         R                  " S[        5        Sn[        U [        5      (       dv  [        U 5      n  [        R                  " U 5      u  p4U(       a  [        SU< SU < S35      eUR                  =(       d    SnUR                  nUR                  =(       d    SnO-U u  pRSU;  a  [        S	U S35      eUR                  SS
5      u  pgXV-   U-   nSU;   d  SU;   a  [        S5      e UR                  S5        [!        U5      R                  5       n UR                  S5        [%        U5      n['        XgS9n	[)        XYR*                  45      $ ! [        [        [        4 a    [        SU -  5      ef = f! ["         a    [!        XQ5      R                  5       n Nf = f! ["         a    [!        Xa5      R                  5       n Nf = f)z>
Format a pair of (name, address) or an email address string.
a  The internal API sanitize_address() is deprecated. Python's modern email API (with email.message.EmailMessage or email.policy.default) will handle most required validation and encoding. Use Python's email.headerregistry.Address to construct formatted addresses from component parts.NzInvalid address; only z could be parsed from "" zInvalid address "%s"@zInvalid address "   r-   r.   z7Invalid address; address parts cannot contain newlines.r0   )usernamedomain)r<   r=   r   
isinstancetupler   r   get_mailbox
ValueErrordisplay_name
local_partrO   r	   
IndexErrorrsplitrA   r
   rC   r   r   r   	addr_spec)
r7   r8   addresstokenrestnm	localpartrO   address_partsparsed_addresss
             r9   r5   r5   a   s    MM	5
 	! GdE""	( ,,T2KE  LQSWX  ##)rB((I\\'RFg0	;<<#NN32	NV+M} 5RSS+
		'BZ 9! fFi?Nr33455E !*j9 	<3d:;;	<2  +B!((*+  99/668	9s/   E 5*F  F+ $E?#F('F(+#GGc                   (    \ rS rSrSS jrSS jrSrg)	MIMEMixin   c                     [        5       n[        R                  " USS9nUR                  XUS9  UR	                  5       $ )zReturn 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selfrg   rh   fpgs        r9   	as_stringMIMEMixin.as_string   s9     Z7			$7	;{{}    c                     [        5       n[        R                  " USS9nUR                  XUS9  UR	                  5       $ )zReturn 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.
Frd   rf   )r   r   BytesGeneratorrj   rk   rl   s        r9   as_bytesMIMEMixin.as_bytes   s9     Y$$Re<			$7	;{{}rr    N)Fr-   )__name__
__module____qualname____firstlineno__rp   ru   __static_attributes__rw   rr   r9   ra   ra      s    rr   ra   c                       \ rS rSrS rSrg)SafeMIMEMessage   c                 N    [        XS5      u  p[        R                  " XU5        g )Nr0   )rH   r   __setitem__rm   rF   rG   s      r9   r   SafeMIMEMessage.__setitem__   s"     .dA	C0rr   rw   N)rx   ry   rz   r{   r   r|   rw   rr   r9   r~   r~      s    1rr   r~   c                   .    \ rS rSrSS jrS rSS jrSrg)	SafeMIMEText   Nc                 :    X0l         [        R                  " XX#S9  g )N)_subtype_charset)r8   r   __init__)rm   _textr   r   s       r9   r   SafeMIMEText.__init__   s     $Lrr   c                 b    [        XU R                  5      u  p[        R                  " XU5        g r4   )rH   r8   r   r   r   s      r9   r   SafeMIMEText.__setitem__   s$    -dG	T-rr   c                     US:X  aR  [        U[        R                  5      (       d3  [        S UR                  5        5       5      nU(       a  [        O[
        n[        R                  " XUS9  g )Nr    c              3   ^   #    U H$  n[        UR                  S S95      [        :  v   M&     g7f)surrogateescape)errorsN)lenrA   RFC5322_EMAIL_LINE_LENGTH_LIMIT)r6   lines     r9   r:   +SafeMIMEText.set_payload.<locals>.<genexpr>   s2      ! 1D DKK'8K9:120s   +-r   )rP   Charsetany
splitlinesutf8_charset_qputf8_charsetr   set_payload)rm   payloadr   has_long_liness       r9   r   SafeMIMEText.set_payload   sW    gj'//&J&J  ! $..0! N *8o\GTG<rr   r8   )plainNr4   )rx   ry   rz   r{   r   r   r   r|   rw   rr   r9   r   r      s    M.
=rr   r   c                   &    \ rS rSr SS jrS rSrg)SafeMIMEMultipart   Nc                 @    X@l         [        R                  " XX#40 UD6  g r4   )r8   r   r   )rm   r   boundary	_subpartsr8   _paramss         r9   r   SafeMIMEMultipart.__init__   s     !txNgNrr   c                 b    [        XU R                  5      u  p[        R                  " XU5        g r4   )rH   r8   r   r   r   s      r9   r   SafeMIMEMultipart.__setitem__   s$    -dG	!!$c2rr   r   )mixedNNN)rx   ry   rz   r{   r   r   r|   rw   rr   r9   r   r      s    HLO3rr   r   EmailAlternativecontentmimetypeEmailAttachment)filenamer   r   c            	           \ rS rSrSrSrSr\" \/ SQ5          SSSSSSSS.S jj5       r	SS jr
\R                  R                  S.S	 jrS
 rSS jrSS jrSS jrS rS rS rS rS rSrg)EmailMessage   z"A container for email information.r   Nr#   
connectionattachmentsheadersr!   reply_toc                   U(       a1  [        U[        5      (       a  [        S5      e[        U5      U l        O/ U l        U	(       a1  [        U	[        5      (       a  [        S5      e[        U	5      U l        O/ U l        U(       a1  [        U[        5      (       a  [        S5      e[        U5      U l        O/ U l        U
(       a1  [        U
[        5      (       a  [        S5      e[        U
5      U l        O/ U l        U=(       d    [        R                  U l
        Xl        U=(       d    SU l        / U l        U(       a|  U Hv  n[        U[        R                  R                   5      (       a  U R#                  U5        M?  [        U[$        5      (       a  U R#                  U5        Mg  U R"                  " U6   Mx     U=(       d    0 U l        X`l        g)O
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 tuplerK   N)rP   r?   	TypeErrorlistr"   r!   r#   r   r   DEFAULT_FROM_EMAIL
from_emailr1   bodyr   emailmessageMIMEPartattachr   extra_headersr   )rm   r1   r   r   r"   r#   r   r   r   r!   r   
attachments               r9   r   EmailMessage.__init__   sN   : "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%--*@*@AAKK
+
H55KK
+KK, * %]$rr   c                 ^    SSK Jn  U R                  (       d  U" US9U l        U R                  $ )Nr   )get_connection)fail_silently)django.core.mailr   r   )rm   r   r   s      r9   r   EmailMessage.get_connection4  s"    3,=IDOrr   policyc                   [         R                  R                  US9nU R                  U5        U R	                  U5        [        U R                  5      US'   [        U R                  R                  SU R                  5      5      US'   U R                  USU R                  5        U R                  USU R                  5        U R                  USU R                  5        U R                   Vs/ sH  o3R                  5       PM     nnSU;  aI  [        R                   (       a  [#        5       nO[$        R&                  n[(        R*                  " U5      US'   S	U;  a  [-        [.        S
9US'   U R                  R1                  5        H'  u  pgUR                  5       S;  d  M  [3        USS9X&'   M)     U R5                  U5        U$ s  snf )Nr   SubjectFromToCczReply-TodateDatez
message-id)rO   z
Message-ID>   r!   r"   r$   r&   T)strings_only)r   r   r   _add_bodies_add_attachmentsr?   r1   r   getr   _set_list_header_if_not_emptyr"   r!   r   rB   r   EMAIL_USE_LOCALTIMEr   r   utcr   nowr   r   itemsr   #_idna_encode_address_header_domains)rm   r   msgkeyheader_namestzrF   values           r9   r   EmailMessage.message;  sn   mm(((7c"T\\*I$,,00IJF**3dgg>**3dgg>**3
DMMJ 04/A/AB/A		/AB%++)+\\",,r*CK|+ *( ;C--335KDzz|#CC%e$?	 6 	005
 Cs   /Gc                     U R                   U R                  -   U R                  -    Vs/ sH  o(       d  M  UPM     sn$ s  snf )zj
Return a list of all recipients of the email (includes direct
addressees as well as Cc and Bcc entries).
)r"   r!   r#   )rm   r   s     r9   
recipientsEmailMessage.recipientsY  s6    
 %)GGdgg$5$@K$@%U$@KKKs   	??c                 p    U R                  5       (       d  gU R                  U5      R                  U /5      $ )zSend the email message.r   )r   r   send_messages)rm   r   s     r9   sendEmailMessage.send`  s2       ""=1??GGrr   c                    [        U[        R                  R                  5      (       a-  Uc  Ub  [	        S5      eU R
                  R                  U5        g[        U[        5      (       aH  [        R                  " S[        5        Uc  Ub  [	        S5      eU R
                  R                  U5        gUc  [	        S5      eU=(       d&    [        R                  " U5      S   =(       d    [        nUR                  SS5      u  pEUS	:X  a&  [        U[        5      (       a   UR!                  5       nU R
                  R                  [%        XU5      5        g! ["         a	    [        n N8f = f)
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 MIMEPart instance is provided.zKMIMEBase attachments are deprecated. Use an email.message.MIMEPart instead.zLcontent and mimetype must not be given when a MIMEBase instance is provided.zcontent must be provided.r   /rM   text)rP   r   r   r   rS   r   appendr   r<   r=   r   	mimetypes
guess_typeDEFAULT_ATTACHMENT_MIME_TYPEsplitbytesdecodeUnicodeDecodeErrorr   )rm   r   r   r   basetypesubtypes         r9   r   EmailMessage.attachh  sS    h 6 677"h&: ,  ##H-(++MM:(
 "h&: ,  ##H-_899  0''1!40/ 
 !)sA 6H6!gu--@").."2 ##OHx$PQ . @ $@@s   !E E*)E*c                     [        U5      nUR                  S5       nUR                  5       nU R                  UR                  XB5        SSS5        g! , (       d  f       g= f)a4  
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   rF   )rm   pathr   filer   s        r9   attach_fileEmailMessage.attach_file  sA     DzYYt_iikGKK		75 __s   -A
A!c                     U R                   (       d  U R                  (       d\  U R                  =(       d    [        R                  n[        U R                   =(       d    SUSS9nUR                  X0R                  US9  g g )NrK   r   )r8   r   r   r   )r   r   r8   r   r>   r   set_contentcontent_subtype)rm   r   r8   r   s       r9   r   EmailMessage._add_bodies  s\    99D,,}}@(@(@H		R(;LD OOD*>*>OQ -rr   c                    U R                   (       a  [        U S5      (       a  [        S5      eUR                  5         U R                    Hz  n[	        U[
        R                  R                  5      (       a  UR                  U5        M?  [	        U[        5      (       a  UR                  U5        Mg  U R                  " U/UQ76   M|     g g )Nmixed_subtypezJEmailMessage no longer supports the undocumented `mixed_subtype` attribute)r   hasattrAttributeError
make_mixedrP   r   r   r   r   r   _add_attachment)rm   r   r   s      r9   r   EmailMessage._add_attachments  s    t_--$>  NN"..
j%--*@*@AAJJz*
H55JJz*((:z: / rr   c                 *   U R                   =(       d    [        R                  nUR                  SS5      u  pgUS:X  a&  [	        U[
        5      (       a   UR                  5       nUS:X  a  UR                  X7X%S9  g US:X  a  [	        U[        5      (       a  UR                  UR                  S9nOk[	        U[        R                  R                  [        R                  R                  45      (       d(  [        R                  " [!        U5      UR                  S9nUR                  X7US9  g [	        U[
        ["        [$        45      (       d  [!        U5      nUR                  UUUUS9  g ! [         a    [        nUR                  SS5      u  pg GN-f = f)	Nr   rM   r   )r   r   r   r   r   )r   r   )maintyper   r   )r8   r   r>   r   rP   r   r   r   r   add_attachmentr   r   r   r   Messagemessage_from_bytesr   	bytearray
memoryview)rm   r   r   r   r   r8   r  r   s           r9   r  EmailMessage._add_attachment  sg   ==<H$<$<$NN32v*We"<"<;!..* v8   " '<00!///<%--44emm6K6KL   22( w(K gy*'EFF%g.!!	  9 & ;7$,NN3$:!';s   E* *$FFc                      U R                   U   X'   g! [         a&    U(       a  SR                  S U 5       5      X'    g gf = f)zi
Set msg's header, either from self.extra_headers, if present, or from
the values argument if not empty.
r2   c              3   6   #    U H  n[        U5      v   M     g 7fr4   )r?   )r6   vs     r9   r:   =EmailMessage._set_list_header_if_not_empty.<locals>.<genexpr>  s     '?1As   N)r   KeyErrorrE   )rm   r   headervaluess       r9   r   *EmailMessage._set_list_header_if_not_empty  sI    
	@,,V4CK 	@"ii'?'?? 	@s    +AAc                    [        UR                  SS5      (       d  UR                  5        H  u  p#[        U[        5      (       d  M  [        S UR                   5       5      (       d  M?  UR                  UUR                   Vs/ sH5  n[        UR                  UR                  [        UR                  5      S9PM7     sn5        M     ggs  snf )zj
If msg.policy does not permit utf8 in headers, IDNA encode all
non-ASCII domains in its address headers.
utf8Fc              3   \   #    U H#  oR                   R                  5       (       + v   M%     g 7fr4   )rO   isascii)r6   r7   s     r9   r:   CEmailMessage._idna_encode_address_header_domains.<locals>.<genexpr>  s$      <:I$++---/s   *,)rT   rN   rO   N)getattrr   r   rP   r   r   	addressesreplace_headerr   rT   rN   r   rO   )rm   r   fieldr   r7   s        r9   r   0EmailMessage._idna_encode_address_header_domains  s     szz6511 !$		e]33 <:?//< 9 9 && ). )8 $-1->->)-'/'<
 )8
	 !,	 2s   ;C)
r   r#   r   r!   r   r   r   r   r1   r"   rK   rK   NN)F)NNNr4   )rx   ry   rz   r{   __doc__r  r8   r   r   r   r   r   r   defaultr   r   r   r   r  r   r   r  r   r   r|   rw   rr   r9   r   r      s    ,O H 	

 8% 8%
8%t !& 4 4 <LH2Rh6 R;$*X	@rr   r   c            
          ^  \ rS rSrSr\" \/ SQ5          S
SSSSSSSS.U 4S jjj5       rS rU 4S jr	S r
S	rU =r$ )EmailMultiAlternativesi  z
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.
)r#   r   r   r   alternativesr!   r   Nc                   > [         TU ]  UUUUUUUUU
US9
  U	=(       d    /  Vs/ sH  n[        U6 PM     snU l        gs  snf )r   r   N)superr   r   r.  )rm   r1   r   r   r"   r#   r   r   r   r.  r!   r   alternative	__class__s                r9   r   EmailMultiAlternatives.__init__$  si    > 	!# 	 	
 @L?Qr?Q
?Q{k*?Q
 
s   ?c                 n    Ub  Uc  [        S5      eU R                  R                  [        X5      5        g)z-Attach an alternative content representation.Nz+Both content and mimetype must be provided.)rS   r.  r   r   )rm   r   r   s      r9   attach_alternative)EmailMultiAlternatives.attach_alternativeS  s2    ?h.JKK  !1'!DErr   c                 R  > U R                   (       d  U R                  (       d  [        TU ]  U5        U R                  (       a  [	        U S5      (       a  [        S5      eUR                  5         U R                  =(       d    [        R                  nU R                   H  nUR                  R                  SS5      u  pEUR                  nUS:X  a7  [        U[        5      (       a  UR                  5       nUR!                  XeUS9  Mj  [#        XbSS9nUR!                  XdUS	9  M     U$ )
Nalternative_subtypezZEmailMultiAlternatives no longer supports the undocumented `alternative_subtype` attributer   rM   r   r  T)r8   r   )r  r   )r   r.  r0  r   r
  r  make_alternativer8   r   r>   r   r   r   rP   r   r   add_alternativer   )rm   r   r8   r1  r  r   r   r2  s          r9   r   "EmailMultiAlternatives._add_bodiesY  s    99D--G$t233$D    "}}@(@(@H#00$/$8$8$>$>sA$F!%--v%!'511").."2''('S)'SWXG''G'T  1 
rr   c                     XR                   ;  a  gU R                   H$  u  p#UR                  S5      (       d  M  X;  d  M$    g   g)zb
Checks that ``text`` occurs in the email body and in all attached MIME
type text/* alternatives.
Fztext/T)r   r.  
startswith)rm   r   r   r   s       r9   body_contains$EmailMultiAlternatives.body_containsq  sB    
 yy !%!2!2G""7++0C "3 rr   )r.  r)  )rx   ry   rz   r{   r*  r   r   r   r5  r   r>  r|   __classcell__)r2  s   @r9   r-  r-    sn      	
 !
 !
 !
!
FF0 rr   r-  )Eemail.messager   email.policyr   r<   collectionsr   r   r   r   r   r   email.errorsr	   email.headerr
   email.headerregistryr   r   r   email.mime.baser   email.mime.messager   email.mime.multipartr   email.mime.textr   email.utilsr   r   r   ior   r   pathlibr   django.confr   django.core.mail.utilsr   django.utils.deprecationr   r   django.utils.encodingr   r   r   django.utils.timezoner   r   body_encodingr   QPr   r   rS   r@   rD   rH   r5   ra   r~   r   r   r   r   r   r-  rw   rr   r9   <module>rU     s        " ' $  )  ? ? $ * . $ < <      + P B B 6
 w'! //'* '

   :  #&   >46p :1i 1=9h =.	3	= 	3 09j2IJ .0STt tn	_\ _rr   