Your IP : 3.149.29.209


Current Path : /opt/alt/python310/lib64/python3.10/email/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/email/__pycache__/message.cpython-310.opt-2.pyc

o

6��fԷ�@s�	ddgZddlZddlZddlZddlmZmZddlmZddlm	Z	ddl
mZmZddlm
Zdd	lmZejZd
Ze�d�Zdd
�Zddd�Zdd�Zdd�ZGdd�d�ZGdd�de�ZGdd�de�ZdS)�Message�EmailMessage�N)�BytesIO�StringIO)�utils)�errors)�Policy�compat32��charset)�decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]cCs4t|��d�\}}}|s|��dfS|��|��fS)N�;)�str�	partition�strip)�param�a�sep�b�r�4/opt/alt/python310/lib64/python3.10/email/message.py�_splitparamsrTcCs�	|dur_t|�dkr_t|t�r'|d7}t�|d|d|d�}d||fSz|�d�WntyH|d7}t�|dd�}d||fYSw|sPt�|�rYd	|t�	|�fSd||fS|S)
Nr�*���%s=%s�asciizutf-8�z%s="%s")
�len�
isinstance�tuplerZencode_rfc2231�encode�UnicodeEncodeError�	tspecials�search�quote)r�valuer%rrr�_formatparam's"
�r'cCsdt|�}g}|dd�dkr�|dd�}|�d�}|dkrK|�dd|�|�dd|�drK|�d|d�}|dkrK|�dd|�|�dd|�ds/|dkrSt|�}|d|�}d|vrx|�d�}|d|�����d||dd���}|�|���||d�}|dd�dks|S)Nr
rr�"z\"r�=)r�find�countr�indexr�lower�append)�sZplist�end�f�irrr�_parseparamIs$
((�
,�
r3cCs0t|t�r|d|dt�|d�fSt�|�S)Nrrr)rr r�unquote)r&rrr�
_unquotevalue]s

r5c@s�eZdZ	efdd�Zdd�Zdcdd	�Zd
d�Zdddd
�Zdd�Z	dd�Z
dd�Zdd�Zdedd�Z
dfdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zdfd0d1�Zd2d3�Zd4d5�Zdfd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dgdJdK�Z&	H	IdgdLdM�Z'	I	dhdPdQ�Z(didRdS�Z)djdTdU�Z*dfdVdW�Z+dfdXdY�Z,dZd[�Z-dfd\d]�Z.dfd^d_�Z/d`da�Z0ddbl1m2Z2dS)krcCs:||_g|_d|_d|_d|_d|_|_g|_d|_dS)N�
text/plain)	�policy�_headers�	_unixfrom�_payload�_charsetZpreambleZepilogue�defects�
_default_type)�selfr7rrr�__init__xs
zMessage.__init__cC�
	|��S�N)�	as_string�r>rrr�__str__��zMessage.__str__FrNcCsL	ddlm}|dur|jn|}t�}||d||d�}|j||d�|��S)Nr)�	GeneratorF)�mangle_from_�maxheaderlenr7��unixfrom)�email.generatorrFr7r�flatten�getvalue)r>rJrHr7rF�fp�grrrrB�s
�zMessage.as_stringcCr@rA)�as_bytesrCrrr�	__bytes__�rEzMessage.__bytes__cCsJ	ddlm}|dur|jn|}t�}||d|d�}|j||d�|��S)Nr)�BytesGeneratorF)rGr7rI)rKrRr7rrLrM)r>rJr7rRrNrOrrrrP�szMessage.as_bytescCs	t|jt�SrA)rr:�listrCrrr�is_multipart�szMessage.is_multipartcCs
||_dSrA�r9)r>rJrrr�set_unixfrom�s
zMessage.set_unixfromcCs|jSrArUrCrrr�get_unixfrom�szMessage.get_unixfromcCsB	|jdur|g|_dSz	|j�|�WdSty td��w)Nz=Attach is not valid on a message with a non-multipart payload)r:r.�AttributeError�	TypeError)r>�payloadrrr�attach�s
�zMessage.attachcCs�	|��r|r	dS|dur|jS|j|S|dur(t|jt�s(tdt|j���|j}t|�dd����}t|t�r|t	�
|�rd|�dd�}|scz|�|�
dd�d�}Wn(tyb|�dd�}Ynwn|r|z|�d�}Wnty{|�d�}Ynw|s�|S|d	kr�t�|�S|d
kr�td�|����\}}|D]	}|j�||�q�|S|dvr�t|�}	t�}
z
tj|	|
d
d�|
��WStjy�|YSwt|t�r�|S|S)NzExpected list, got %szcontent-transfer-encodingrr�surrogateescaper�replace�raw-unicode-escapezquoted-printable�base64�)z
x-uuencodeZuuencodeZuuezx-uueT)�quiet)rTr:rrSrY�typer�getr-rZ_has_surrogatesr!�decode�	get_param�LookupError�UnicodeError�quopriZdecodestringr�join�
splitlinesr7Z
handle_defectr�uurM�Error)r>r2rdrZ�cteZbpayloadr&r<ZdefectZin_fileZout_filerrr�get_payload�s`!


���

�
zMessage.get_payloadcCsv	t|d�r|dur||_dSt|t�st|�}|�|j�}t|d�r+|�dd�|_n||_|dur9|�|�dSdS)Nr!rdrr\)�hasattrr:r�Charsetr!�output_charsetrd�set_charset)r>rZrrrr�set_payload/s


�zMessage.set_payloadcCs	|dur|�d�d|_dSt|t�st|�}||_d|vr%|�dd�d|vr4|jdd|��d�n|�d|���||��krI|�|j�|_d|vr�|�	�}z||�WdSt
y�|j}|r|z|�dd	�}Wnty{|�|j
�}Ynw|�|�|_|�d|�YdSwdS)
Nr�MIME-Version�1.0�Content-Typer6r
zContent-Transfer-Encodingrr\)�	del_paramr;rrp�
add_headerZget_output_charset�	set_paramZbody_encoder:Zget_body_encodingrYr!rgrq)r>rrmrZrrrrrCsB

����zMessage.set_charsetcC�	|jSrA)r;rCrrr�get_charsetrszMessage.get_charsetcCs	t|j�SrA)rr8rCrrr�__len__zs
zMessage.__len__cCs	|�|�SrA)rc�r>�namerrr�__getitem__~s
zMessage.__getitem__cCst	|j�|�}|r-|��}d}|jD]\}}|��|kr,|d7}||kr,td�||���q|j�|j�||��dS)Nrrz/There may be at most {} {} headers in a message)r7Zheader_max_countr-r8�
ValueError�formatr.�header_store_parse)r>r~�valZ	max_countZlname�found�k�vrrr�__setitem__�s��zMessage.__setitem__cCsB	|��}g}|jD]\}}|��|kr|�||f�q
||_dSrA)r-r8r.)r>r~�
newheadersr�r�rrr�__delitem__�s�
zMessage.__delitem__cCs|��dd�|jD�vS)NcSsg|]\}}|���qSr)r-��.0r�r�rrr�
<listcomp>�sz(Message.__contains__.<locals>.<listcomp>)r-r8r}rrr�__contains__�szMessage.__contains__ccs�|jD]\}}|VqdSrA�r8)r>Zfieldr&rrr�__iter__�s��zMessage.__iter__cCs	dd�|jD�S)NcSsg|]\}}|�qSrrr�rrrr��sz Message.keys.<locals>.<listcomp>r�rCrrr�keys�szMessage.keysc�	�fdd��jD�S)Ncsg|]\}}�j�||��qSr�r7�header_fetch_parser�rCrrr��s�z"Message.values.<locals>.<listcomp>r�rCrrCr�values��
�zMessage.valuescr�)Ncs"g|]
\}}|�j�||�f�qSrr�r�rCrrr��s�z!Message.items.<locals>.<listcomp>r�rCrrCr�items�r�z
Message.itemscCs<	|��}|jD]\}}|��|kr|j�||�Sq|SrA)r-r8r7r�)r>r~�failobjr�r�rrrrc�s�zMessage.getcCs	|j�||f�dSrA)r8r.)r>r~r&rrr�set_raw�szMessage.set_rawcCs	t|j���SrA)�iterr8�copyrCrrr�	raw_items�szMessage.raw_itemscCsJ	g}|��}|jD]\}}|��|kr|�|j�||��q
|s#|S|SrA)r-r8r.r7r�)r>r~r�r�r�r�rrr�get_all�s�zMessage.get_allcKsr	g}|��D]\}}|dur|�|�dd��q|�t|�dd�|��q|dur0|�d|�t�|�||<dS)N�_�-r)r�r.r]r'�insert�	SEMISPACEri)r>�_name�_valueZ_params�partsr�r�rrrrxszMessage.add_headercCs\	|��}ttt|j��|j�D]\}\}}|��|kr)|j�||�|j|<dSqt|��rA)r-�zip�rangerr8r7r��KeyError)r>r�r�r2r�r�rrr�replace_header!s"�zMessage.replace_headercCsJ	t�}|�d|�}||ur|��St|�d��}|�d�dkr#dS|S)N�content-typer�/rr6)�objectrc�get_default_typerr-r+)r>�missingr&�ctyperrr�get_content_type4szMessage.get_content_typecC�	|��}|�d�dS)Nr�r�r��split�r>r�rrr�get_content_maintypeL�zMessage.get_content_maintypecCr�)Nr�rr�r�rrr�get_content_subtypeUr�zMessage.get_content_subtypecCrzrA�r=rCrrrr�^szMessage.get_default_typecCs	||_dSrAr�r�rrr�set_default_typegs
zMessage.set_default_typec		Cs�t�}|�||�}||ur|Sg}t|�D]+}z|�dd�\}}|��}|��}Wnty8|��}d}Ynw|�||f�qt�|�}|S)Nr)rr)	r�rcr3r�rr�r.rZ
decode_params)	r>r��headerr�r&�params�pr~r�rrr�_get_params_preserveps"�
zMessage._get_params_preserver�TcCs6	t�}|�||�}||ur|S|rdd�|D�S|S)NcSsg|]
\}}|t|�f�qSr)r5r�rrrr��sz&Message.get_params.<locals>.<listcomp>)r�r�)r>r�r�r4r�r�rrr�
get_params�szMessage.get_paramscCsP	||vr|S|�||�D]\}}|��|��kr%|r!t|�S|Sq
|SrA)r�r-r5)r>rr�r�r4r�r�rrrre�s�zMessage.get_paramrvrcCs	t|t�s
|r
|||f}||vr|��dkrd}n|�|�}|j||d�s;|s/t|||�}n=t�|t|||�g�}n1d}|j||d�D]'\}	}
d}|	��|��krYt|||�}nt|	|
|�}|sd|}qDt�||g�}qD||�|�kr�|r}|�	||�dS||=|||<dSdS)Nr�r6)r�r�r�r4)
rr r-rcrer'r�rir�r�)r>rr&r��requoterZlanguager]r�Z	old_param�	old_valueZappend_paramrrrry�s:

���zMessage.set_paramcCs�	||vrdSd}|j||d�D] \}}|��|��kr0|s%t|||�}qt�|t|||�g�}q||�|�krA||=|||<dSdS)Nrr�)r�r-r'r�rirc)r>rr�r�Z	new_ctyper�r�rrrrw�s 
���zMessage.del_paramcCs�	|�d�dks
t�|��dkr|d=d|d<||vr!|||<dS|j||d�}||=|||<|dd�D]\}}|�||||�q5dS)Nr�rr�zmime-versionrurtr�)r+r�r-r�ry)r>rbr�r�r�r�r�rrr�set_types�zMessage.set_typecCsF	t�}|�d|d�}||ur|�d|d�}||ur|St�|���S)N�filename�content-dispositionr~r�)r�rer�collapse_rfc2231_valuer)r>r�r�r�rrr�get_filename&szMessage.get_filenamecCs.	t�}|�d|�}||ur|St�|���S)N�boundary)r�rerr��rstrip)r>r�r�r�rrr�get_boundary6szMessage.get_boundarycCs	t�}|�|d�}||urt�d��g}d}|D]\}}|��dkr/|�dd|f�d}q|�||f�q|sB|�dd|f�g}|jD]=\}	}
|	��dkr}g}|D]\}}
|
dkrc|�|�qU|�d||
f�qUt�|�}
|�|j	�
|	|
��qG|�|	|
f�qG||_dS)	Nr�zNo Content-Type header foundFr�z"%s"Trr)r�r�rZHeaderParseErrorr-r.r8r�rir7r�)r>r�r�r�Z	newparamsZfoundpZpkZpvr��hr�r�r�r�rrr�set_boundaryCs4	


zMessage.set_boundaryc	Cs�	t�}|�d|�}||ur|St|t�r9|dpd}z|d�d�}t||�}Wnttfy8|d}Ynwz
|�d�W|��StyN|YSw)Nrrzus-asciirr^)	r�rerr r!rrfrgr-)r>r�r�rZpcharsetrPrrr�get_content_charsetqs&
���zMessage.get_content_charsetcs	�fdd�|��D�S)Ncsg|]}|����qSr)r�)r��part�r�rrr��sz(Message.get_charsets.<locals>.<listcomp>��walk)r>r�rr�r�get_charsets�szMessage.get_charsetscCs,	|�d�}|durdSt|�d��}|S)Nr�r)rcrr-)r>r&�c_drrr�get_content_disposition�s
zMessage.get_content_dispositionr�)FrN)FN)NFrA)Nr�T)rvTNrF)r�T)rvT)3�__name__�
__module__�__qualname__r	r?rDrBrQrPrTrVrWr[rnrsrrr{r|rr�r�r�r�r�r�r�rcr�r�r�rxr�r�r�r�r�r�r�r�reryrwr�r�r�r�r�r�r�Zemail.iteratorsr�rrrrrish



Z/


				

�"
�
3

 

.

cs�eZdZd/�fdd�	Zd0�fdd�	Zdd�Zd	d
�Zdd�Zd1dd�Zhd�Z	dd�Z
dd�Zdd�dd�Zdd�dd�Z
dd�Zd/dd�Zd/dd�Zd/d d!�Zdd"�d#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Z�ZS)2�MIMEPartNcs(|durddlm}|}t��|�dS)Nr)�default)Zemail.policyr��superr?)r>r7r���	__class__rrr?�szMIMEPart.__init__Fcs2	|dur|jn|}|dur|j}t��|||�SrA)r7Zmax_line_lengthr�rB)r>rJrHr7r�rrrB�s

zMIMEPart.as_stringcCs|j|jjdd�d�S)NT)�utf8�r7)rBr7ZclonerCrrrrD�szMIMEPart.__str__cCs |�d�}|durdS|jdkS)Nr�F�
attachment)rcZcontent_disposition)r>r�rrr�
is_attachment�s
zMIMEPart.is_attachmentc	cs�|��rdS|���d�\}}|dkr"||vr |�|�|fVdS|dks*|��s,dS|dkrB|��D]}|�||�EdHq4dSd|vrN|�d�|fVd}|�d�}|rh|��D]}|d|krg|}nq[|durx|��}|rv|dnd}|dur�|�||�EdHdSdS)Nr��text�	multipart�related�start�
content-idr)	r�r�r�r,rT�
iter_parts�
_find_bodyrern)	r>r��preferencelist�maintype�subtypeZsubpart�	candidater�Zsubpartsrrrr��s<�
��zMIMEPart._find_body�r��html�plaincCsF	t|�}d}|�||�D]\}}||kr |}|}|dkr |Sq
|S)Nr)rr�)r>r�Z	best_prio�bodyZprior�rrr�get_body�s	�zMIMEPart.get_body>)r�r�)r�r�)r�r�)r��alternativec
cs �	|���d�\}}|dks|dkrdS|��}z|��}Wn
ty)YdSw|dkrf|dkrf|�d�}|rZd}g}|D]}|�d�|krKd}q?|�|�q?|rZ|EdHdS|�d	�|EdHdSg}	|D]#}|���d�\}}||f|j	vr�|�
�s�||	vr�|	�|�qj|VqjdS)
Nr�r�r�r�r�Fr�Tr)r�r�rnr�rXrercr.�pop�_body_typesr�)
r>r�r�rZr�r�r�Zattachmentsr��seenrrr�iter_attachmentssJ�
�



�
�zMIMEPart.iter_attachmentsccs"�	|��r|��EdHdSdSrA)rTrnrCrrrr�=s
��zMIMEPart.iter_parts)�content_managercOs(|dur|jj}|j|g|�Ri|��SrA)r7r��get_content�r>r��args�kwrrrr�EszMIMEPart.get_contentcOs,|dur|jj}|j|g|�Ri|��dSrA)r7r��set_contentr�rrrr�JszMIMEPart.set_contentc
Cs�|��dkr|��}||f}||vrtd�||���g}g}|jD]\}}|���d�r5|�||f�q"|�||f�q"|rSt|�|j	d�}	||	_|j
|	_
|	g|_
ng|_
||_d||d<|durk|�d|�dSdS)Nr�zCannot convert {} to {}�content-r�z
multipart/rvr�)r�r�r�r�r8r-�
startswithr.rbr7r:ry)
r>r�Zdisallowed_subtypesr�Zexisting_subtypeZkeep_headersZpart_headersr~r&r�rrr�_make_multipartOs0
�
�zMIMEPart._make_multipartcC�|�dd|�dS)Nr�)r��mixed�r��r>r�rrr�make_relatedj�zMIMEPart.make_relatedcCr�)Nr�)r�r�r�rrr�make_alternativemrzMIMEPart.make_alternativecCr�)Nr�rr�r�rrr�
make_mixedprzMIMEPart.make_mixed)�_dispcOsj|��dks|��|krt|d|��t|�|jd�}|j|i|��|r.d|vr.||d<|�|�dS)Nr�Zmake_r�r�zContent-Disposition)r�r��getattrrbr7r�r[)r>Z_subtyperr�r�r�rrr�_add_multipartsszMIMEPart._add_multipartcO� |jdg|�Rddi|��dS)Nr�rZinline�r�r>r�r�rrr�add_related}� zMIMEPart.add_relatedcOs|jdg|�Ri|��dS)Nr�rr	rrr�add_alternative�szMIMEPart.add_alternativecOr)Nr�rr�rr	rrr�add_attachment�rzMIMEPart.add_attachmentcCsg|_d|_dSrA�r8r:rCrrr�clear�s
zMIMEPart.clearcCsdd�|jD�|_d|_dS)NcSs&g|]\}}|���d�s||f�qS)r�)r-r�)r��nr�rrrr��s�z*MIMEPart.clear_content.<locals>.<listcomp>rrCrrr�
clear_content�s
zMIMEPart.clear_contentrA)FNN)r�)r�r�r�r?rBrDr�r�r�r�r�r�r�r�r�rrrrr
rr
rr�
__classcell__rrr�rr��s,
7



r�cseZdZ�fdd�Z�ZS)rcs*t�j|i|��d|vrd|d<dSdS)Nrtru)r�r�r	r�rrr��s�zEmailMessage.set_content)r�r�r�r�rrrr�rr�s)NT)�__all__�rerkrh�iorrZemailrrZemail._policybaserr	rr;Zemail._encoded_wordsrrpr��compiler#rr'r3r5rr�rrrrr�<module>s8


"N`

?>