
    j9d                        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+J,r,  S SK-J.r.J/r/J0r0  S SK1J2r2  SSK3J4r4J5r5J6r6  \
R                  " S5      r7S\7l8        \
R                  " S5      r9\
Rt                  \9l8        Sr;Sr<\=r>1 Skr?S r@S rA " S S5      rB " S S \B\5      rC " S! S"\B\5      rD " S# S$\B\5      rE\" S%S&S'/5      rF\" S(/ S)Q5      rG " S* S+5      rH " S, S-\H5      rIg).    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warn_about_external_use)force_bytes	force_strpunycode)get_current_timezone   )CONNECTION_ARG_WARNINGFAIL_SILENTLY_ARG_WARNINGreport_using_incompatibility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     P/var/www/html/KUNJ/venv/lib/python3.13/site-packages/django/core/mail/message.py	<genexpr>,forbid_multi_line_headers.<locals>.<genexpr>_   s       =QT x00=Qs   )warningswarnr   r   DEFAULT_CHARSETstrBadHeaderErrorencodelowerr
   UnicodeEncodeErrorADDRESS_HEADERSjoinr   )namevalr=   s     `r>   forbid_multi_line_headersrM   L   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!   r2   r3   z7Invalid address; address parts cannot contain newlines.r5   )usernamedomain)rA   rB   r   
isinstancetupler   r   get_mailbox
ValueErrordisplay_name
local_partrS   r	   
IndexErrorrsplitrF   r
   rH   r   r   r   	addr_spec)
r<   r=   addresstokenrestnm	localpartrS   address_partsparsed_addresss
             r>   r:   r:   k   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selfrk   rl   fpgs        r>   	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.
Frh   rj   )r   r   BytesGeneratorrn   ro   rp   s        r>   as_bytesMIMEMixin.as_bytes   s9     Y$$Re<			$7	;{{}rv    N)Fr2   )__name__
__module____qualname____firstlineno__rt   ry   __static_attributes__r{   rv   r>   re   re      s    rv   re   c                       \ rS rSrS rSrg)SafeMIMEMessage   c                 N    [        XS5      u  p[        R                  " XU5        g )Nr5   )rM   r   __setitem__rq   rK   rL   s      r>   r   SafeMIMEMessage.__setitem__   s"     .dA	C0rv   r{   N)r|   r}   r~   r   r   r   r{   rv   r>   r   r      s    1rv   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)r=   r   __init__)rq   _textr   r   s       r>   r   SafeMIMEText.__init__   s     $Lrv   c                 b    [        XU R                  5      u  p[        R                  " XU5        g r9   )rM   r=   r   r   r   s      r>   r   SafeMIMEText.__setitem__   s$    -dG	T-rv   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)lenrF   RFC5322_EMAIL_LINE_LENGTH_LIMIT)r;   lines     r>   r?   +SafeMIMEText.set_payload.<locals>.<genexpr>   s2      ! 1D DKK'8K9:120s   ,.r   )rT   Charsetany
splitlinesutf8_charset_qputf8_charsetr   set_payload)rq   payloadr   has_long_liness       r>   r   SafeMIMEText.set_payload   sW    gj'//&J&J  ! $..0! N *8o\GTG<rv   r=   )plainNr9   )r|   r}   r~   r   r   r   r   r   r{   rv   r>   r   r      s    M.
=rv   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 r9   )r=   r   r   )rq   r   boundary	_subpartsr=   _paramss         r>   r   SafeMIMEMultipart.__init__   s     !txNgNrv   c                 b    [        XU R                  5      u  p[        R                  " XU5        g r9   )rM   r=   r   r   r   s      r>   r   SafeMIMEMultipart.__setitem__   s$    -dG	!!$c2rv   r   )mixedNNN)r|   r}   r~   r   r   r   r   r{   rv   r>   r   r      s    HLO3rv   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 5       r\R                  S 5       r\R                  R                  S	.S
 jrS rSSS.S j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        Ub  [)        [*        [,        SS9  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 tuplerP   Nr!   )skip_frames)rT   rD   	TypeErrorlistr'   r&   r(   r   r   DEFAULT_FROM_EMAIL
from_emailr6   bodyr   emailmessageMIMEPartattachr   extra_headersr   r"   r   _connection)rq   r6   r   r   r'   r(   r   r   r   r&   r   
attachments               r>   r   EmailMessage.__init__   sg   : "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, * %]!#&(@a &rv   c                 >    Sn[        U[        5        U R                  $ )Nz4The EmailMessage.connection attribute is deprecated.r   r   r   )rq   msgs     r>   r   EmailMessage.connectionD  s    D%=>rv   c                 4    Sn[        U[        5        Xl        g )NzqThe EmailMessage.connection attribute is deprecated. Switch to EmailMessage.send(using=...) with a MAILERS alias.r   )rq   valuer   s      r>   r   r   J  s     A 	 	 %=> rv   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       nUS:X  a  [3        S5      eUS;  d  M.  [5        USS9X&'   M<     U R7                  U5        U$ s  snf )Nr   SubjectFromToCczReply-TodateDatez
message-id)rS   z
Message-IDr(   z`Bcc is not a valid email header. Use the "bcc" argument to specify blind carbon copy recipients.>   r&   r'   r)   r+   T)strings_only)r   r   r   _add_bodies_add_attachmentsrD   r6   r   getr   _set_list_header_if_not_emptyr'   r&   r   rG   r   EMAIL_USE_LOCALTIMEr    r   utcr   nowr   r   itemsrW   r   #_idna_encode_address_header_domains)	rq   r   r   keyheader_namestzrK   r   headers	            r>   r   EmailMessage.messageS  s   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\F H 
 ==%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(   )rq   r   s     r>   
recipientsEmailMessage.recipientsw  s6    
 %)GGdgg$5$@K$@%U$@KKKs
   
A A )usingc                   U R                  5       (       d  gSSKJn  U(       a  [        [        [
        5        [        U S5      (       a  [        S5      eUb&  [        U R                  U5        UR                  U   nO?U R                  (       a  U R                  nU(       a  [        S5      eOUR                  US9nUR                  U /5      $ )zSend the email message.r   )mailget_connectionzIEmailMessage no longer supports the undocumented get_connection() method.z_fail_silently cannot be used with a connection. Pass fail_silently to get_connection() instead.)fail_silently)r   django.corer   r   r#   r   hasattrAttributeErrorr$   r   mailersr   r   send_messages)rq   r   r   r   r   s        r>   sendEmailMessage.send~  s        	%#$=?WX4)** + 
 ()9)9=Ie,J))JF   ,,=,IJ''//rv   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   /r!   text)rT   r   r   r   rW   r   appendr   rA   rB   r   	mimetypes
guess_typeDEFAULT_ATTACHMENT_MIME_TYPEsplitbytesdecodeUnicodeDecodeErrorr   )rq   r   r   r   basetypesubtypes         r>   r   EmailMessage.attach  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   rK   )rq   pathr   filer   s        r>   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 )NrP   r   )r=   r   r  r   )r   r   r=   r   rC   r   set_contentcontent_subtype)rq   r   r=   r   s       r>   r   EmailMessage._add_bodies  s\    99D,,}}@(@(@H		R(;LD OOD*>*>OQ -rv   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   r   r   
make_mixedrT   r   r   r   r   r   _add_attachment)rq   r   r   s      r>   r   EmailMessage._add_attachments  s    t_--$>  NN"..
j%--*@*@AAJJz*
H55JJz*((:z: / rv   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   r!   r   )r  r   r   r   r   )r  r   )maintyper  r   )r=   r   rC   r  rT   r  r  r  r  add_attachmentr   r   r   r   Messagemessage_from_bytesr   	bytearray
memoryview)rq   r   r   r   r   r=   r  r  s           r>   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.
r7   c              3   8   #    U  H  n[        U5      v   M     g 7fr9   )rD   )r;   vs     r>   r?   =EmailMessage._set_list_header_if_not_empty.<locals>.<genexpr>6  s     '?1As   N)r   KeyErrorrJ   )rq   r   r   valuess       r>   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r9   )rS   isascii)r;   r<   s     r>   r?   CEmailMessage._idna_encode_address_header_domains.<locals>.<genexpr>H  s$      <:I$++---/s   +-)rX   rR   rS   N)getattrr   r   rT   r   r   	addressesreplace_headerr   rX   rR   r   rS   )rq   r   fieldr   r<   s        r>   r   0EmailMessage._idna_encode_address_header_domains8  s     szz6511 !$		e]33 <:?//< 9 9 && ). )8 $-1->->)-'/'<
 )8
	 !,	 2s   <C)
r   r   r(   r   r&   r   r   r   r6   r'   rP   rP   NN)F)NNNr9   )r|   r}   r~   r   __doc__r  r=   r   r   r   propertyr   setterr   r   defaultr   r   r   r   r  r   r   r  r   r   r   r{   rv   r>   r   r      s    ,O H 	

 =& =&
=&@    
 ! ! !& 4 4 "HL#0 #0J2Rh6 R;$*X	@rv   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$ )EmailMultiAlternativesiX  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;  )rq   r6   r   r   r'   r(   r   r   r   r;  r&   r   alternative	__class__s                r>   r   EmailMultiAlternatives.__init___  si    > 	!# 	 	
 @L?Qr?Q
?Q{k*?Q
 
s   A 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.)rW   r;  r   r   )rq   r   r   s      r>   attach_alternative)EmailMultiAlternatives.attach_alternative  s2    ?h.JKK  !1'!DErv   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   r!   r   r  T)r=   r   )r  r  )r   r;  r=  r   r   r   make_alternativer=   r   rC   r   r  r   rT   r  r  add_alternativer   )rq   r   r=   r>  r  r  r   r?  s          r>   r   "EmailMultiAlternatives._add_bodies  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 
rv   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)rq   r   r   r   s       r>   body_contains$EmailMultiAlternatives.body_contains  sB    
 yy !%!2!2G""7++0C "3 rv   )r;  r4  )r|   r}   r~   r   r5  r   r   r   rB  r   rK  r   __classcell__)r?  s   @r>   r:  r:  X  sn      	
 !
 !
 !
!
FF0 rv   r:  )Jemail.messager   email.policyr   rA   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   r   django.utils.encodingr   r   r   django.utils.timezoner    deprecationr"   r#   r$   r   body_encodingr   QPr  r   rW   rE   rI   rM   r:   re   r   r   r   r   r   r   r:  r{   rv   r>   <module>rc     s4       " ' $  )  ? ? $ * . $ < <      + 
 C B 6  w'! //'* '

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