
    ;en4                     ~   	 g d Z ddlZddlZddlZddlZddlZddlZddl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Zd	Zd	Zd
ZdZ ej        d          Z ej        d          Zd Z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 Z&d'dZ' ej        dej(                  Z)d Z*	 	 d(d!Z+d)d#Z,dS )*)collapse_rfc2231_valuedecode_paramsdecode_rfc2231encode_rfc2231
formataddr
formatdateformat_datetimegetaddresses
make_msgid	mktime_tz	parseaddr	parsedateparsedate_tzparsedate_to_datetimeunquote    N)quote)AddressList)r   )r   r   _parsedate_tz)Charsetz,  z
'z[][\\()<>@,:;".]z[\\"]c                 T    	 	 |                                   dS # t          $ r Y dS w xY w)NFT)encodeUnicodeEncodeError)ss    "/usr/lib/python3.11/email/utils.py_has_surrogatesr   3   s>    B	


u   tts    
''c                 Z    |                      dd          }|                    dd          S )Nutf-8surrogateescapereplace)r   decode)stringoriginal_bytess     r   	_sanitizer%   @   s.    
 ]]7,=>>N  )444    r   c                    	 | \  }}|                     d           |r	 |                     d           d}t                              |          rd}t                              d|          }|||d|dS # t
          $ rD t          |t                    rt          |          }|	                    |          }|d|dcY S w xY w|S )Nasciir   "z\\\g<0>z <>)
r   
specialsresearch	escapesresubr   
isinstancestrr   header_encode)paircharsetnameaddressquotesencoded_names         r   r   r   L   s    MD'NN7 C	CKK    F  && ==T22D$*FDD&&&'''BB " 	7 	7 	7'3'' +!'**"0066L ,ggg6666		7 Ns   A9 9ACCc                 x    	 t                               d | D                       }t          |          }|j        S )Nc              3   4   K   | ]}t          |          V  d S )Nr0   ).0vs     r   	<genexpr>zgetaddresses.<locals>.<genexpr>p   s(      66Q#a&&666666r&   )
COMMASPACEjoin_AddressListaddresslist)fieldvaluesallas      r   r	   r	   n   s:    A
//66+666
6
6CSA=r&   c           	          dg d| d                  | d         g d| d         dz
           | d         | d         | d	         | d
         |fz  S )Nz"%s, %02d %s %04d %02d:%02d:%02d %s)MonTueWedThuFriSatSun      )JanFebMarAprMayJunJulAugSepOctNovDec   r             )	timetuplezones     r   _format_timetuple_and_zonerb   u   sj    /999)A,G!	3 	3 	33<Q<!3C	E!ilIaL)A,3  r&   Fc                 $   	 | t          j                     } |s|r0t          j                            | t          j        j                  }nt          j                            |           }|r|                                }d}t          ||          S )NF)timedatetimefromtimestamptimezoneutcutcfromtimestamp
astimezoner   )timeval	localtimeusegmtdts       r   r   r   ~   s    " )++ 9F 9,,Wh6G6KLL//88 ]]__2v&&&r&   c                     	 |                                  }|r3| j        | j        t          j        j        k    rt          d          d}n| j        d}n|                     d          }t          ||          S )Nz%usegmt option requires a UTC datetimeGMTz-0000z%z)r`   tzinfore   rg   rh   
ValueErrorstrftimerb   )rn   rm   nowra   s       r   r   r      s~     ,,..C !9	X->-B B BDEEE		{{4  %c4000r&   c                     	 t          t          j                    dz            }t          j                    }t	          j        d          }| d} nd| z   } |t          j                    }d|||| |fz  }|S )Nd   @   r   .z<%d.%d.%d%s@%s>)intrd   osgetpidrandomgetrandbitssocketgetfqdn)idstringdomainrk   pidrandintmsgids         r   r
   r
      s}     $)++c/""G
)++C $$G>~!!#w& IIELr&   c           	         t          |           }|t          dt          |           z            |^ }}|t          j        |d d          S t          j        |d d         dt          j        t          j        |                    iS )Nz!Invalid date value or format "%s"rM   rq   seconds)r   rr   r0   re   rg   	timedelta)dataparsed_date_tzdtupletzs       r   r   r      s    "4((N<s4yyHIII KVR	z &!*--fRaRj F$X%7%C%C%CDDF F Fr&   c                 D    	 t          |           j        }|sdS |d         S )N)r   r   r   )r@   rA   )addraddrss     r   r   r      s/     *E v8Or&   c                 N   	 t          |           dk    r|                     d          rG|                     d          r2| dd                             dd                              dd          S |                     d          r|                     d          r
| dd         S | S )	Nr[   r)   z\\\z\"<r*   )len
startswithendswithr!   r:   s    r   r   r      s    &
3xx!||>># 	G3<<#4#4 	Gqt9$$VT22::5#FFF>># 	3<<#4#4 	qt9Jr&   c                 n    	 |                      t          d          }t          |          dk    rd d | fS |S )NrN   )splitTICKr   )r   partss     r   r   r      s8    -GGD!E
5zzQT1}Lr&   c                 t    	 t           j                            | d|pd          } ||| S |d}|d|d| S )Nr   r(   )safeencodingr   )urllibparser   )r   r3   languages      r   r   r      s[     	120B7CCA8+ (((AA..r&   z&^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$c                    	 | d         g}i }| dd          D ]\  }}|                     d          }t          |          }t                              |          }|rW|                    dd          \  }}|t          |          }|                    |g                               |||f           |                    |dt          |          z  f           |r|	                                D ]\  }}g }d}	|
                                 |D ]@\  }}
}|r#t          j                            |
d	          }
d
}	|                    |
           At          t                              |                    }|	r1t          |          \  }}}|                    |||d|z  ff           |                    |d|z  f           |S )Nr   r[   *r4   numz"%s"Fzlatin-1)r   T)r   r   rfc2231_continuationmatchgroupry   
setdefaultappendr   itemssortr   r   EMPTYSTRINGr?   r   )params
new_paramsrfc2231_paramsr4   valueencodedmor   continuationsextendedr   r3   r   s                r   r   r     s    )J Nabbz 
= 
=e--$$!''-- 	=//ID##hh%%dB//66UG7LMMMMtVeEll%:;<<<< :#1#7#7#9#9 	: 	:D-EH    $1    Q $ ,,Q,CCA#HQ+**51122E :+9%+@+@(5!!4'8Ve^)L"MNNNN!!4%"89999r&   r!   us-asciic                    t          | t                    rt          |           dk    rt          |           S | \  }}}||}t	          |d          }	 t          |||          S # t          $ r t          |          cY S w xY w)Nr\   zraw-unicode-escape)r/   tupler   r   bytesr0   LookupError)r   errorsfallback_charsetr3   r   textrawbytess          r   r   r   4  s    eU## s5zzQu~~ $GXt #T/00H8Wf---   t}}s   A$ $B ?B r   c                 f   	 | @t           j                             t           j        j                                                  S | j        |                                 S |                                 d d         |fz   }t          j        |          }t          j	        |          }	 t          j
        |j                  }t          j        ||j                  }n# t          $ r | t          j         t          j        |          d d          z
  }t          j        o
|j        dk    }|rt          j        nt          j         }|t          j
        |          k    r&t          j        |t          j        |                   }nt          j        |          }Y nw xY w|                     |          S )Nr   r   rM   r   )rq   )re   rt   rg   rh   rj   rq   r`   rd   mktimerl   r   	tm_gmtofftm_zoneAttributeErrorgmtimedaylighttm_isdstaltzonetznamer!   )	rn   isdsttmr   localtmdeltar   dstgmtoffs	            r   rl   rl   N  s    
z $$X%6%:;;FFHHH	y}} 
	x	'Bk"ooGnW%%G*"7+<===ugo66 	* 	* 	* X&G(<(<RaR(@AAm4 01 4#&94<<DM:H&v66666"5$+c*:;;BB"5))B	* ::R:   s   (4C B:FF)r   )NFF)F)NN)r!   r   )Nr   )-__all__rz   rerd   r|   r~   re   urllib.parser   email._parseaddrr   r   r@   r   r   r   r   email.charsetr   r>   r   UEMPTYSTRINGCRLFr   compiler+   r-   r   r%   r   r	   rb   r   r   r
   r   r   r   r   r   ASCIIr   r   r   rl   r_   r&   r   <module>r      sK  
   $ 
			 				         " " " " " " 8 8 8 8 8 8 & & & & & & C C C C C C C C C C " ! ! ! ! !

RZ+,,
BJx  		 	 	5 5 5   D    ' ' ' ':1 1 1 1&   .F F F
 
 
    / / / / "rz"KH  . . .` *3,6   4%! %! %! %! %! %!r&   