Your IP : 216.73.216.86


Current Path : /home/emeraadmin/public_html/4d695/
Upload File :
Current File : /home/emeraadmin/public_html/4d695/email.tar

__pycache__/_encoded_words.cpython-312.pyc000064400000020164151706203560014445 0ustar00�

T��h]!��2�dZddlZddlZddlZddlZddlmZmZddlm	Z	gd�Z
ejejd�jd��Zd�ZGd	�d
e�Ze�Zdeed�<d
�Zd�Zd�Zd�Zd�Zeed�Zd�Zeed�Zeed�Zdd�Zy)z� Routines for manipulating RFC2047 encoded words.

This is currently a package-private API, but will be considered for promotion
to a public API if there is demand.

�N)�
ascii_letters�digits)�errors)�decode_q�encode_q�decode_b�encode_b�len_q�len_b�decode�encodes=([a-fA-F0-9]{2})c�f�tj|jd�j��S)N�)�bytes�fromhex�groupr)�ms �-/usr/lib64/python3.12/email/_encoded_words.py�<lambda>rAs��%�-�-�����
� 1� 1� 3�4�c�@�|jdd�}t|�gfS)N�_� )�replace�_q_byte_subber)�encodeds rrrCs"���o�o�d�D�)�G��'�"�B�&�&rc�b�eZdZdejd�zejd�zZd�Zy)�	_QByteMaps-!*+/�asciic�v�||jvrt|�||<||Sdj|�||<||S)Nz={:02X})�safe�chr�format)�self�keys  r�__missing__z_QByteMap.__missing__MsG���$�)�)���C��D��I��C�y��"�(�(��-�D��I��C�y�rN)�__name__�
__module__�__qualname__rr
rr!r&�rrrrIs/���*�m�*�*�7�3�3�m�f�m�m�G�6L�L�D�rr�_� c�2�djd�|D��S)N�c3�.K�|]
}t|���y�w�N)�_q_byte_map��.0�xs  r�	<genexpr>zencode_q.<locals>.<genexpr>Zs����3�7�a�;�q�>�7�s�)�join��bstrings rrrYs��
�7�7�3�7�3�3�3rc�&�td�|D��S)Nc3�@K�|]}tt|����y�wr0)�lenr1r2s  rr5zlen_q.<locals>.<genexpr>]s����4�G�q�s�;�q�>�"�G�s�)�sumr7s rr
r
\s���4�G�4�4�4rc�P�t|�dz}|rddd|z
nd}	tj||zd��|rtj�gfSgfS#t
j$r�	tj|d��tj�gfcYS#t
j$r|	tj|dzd��tj�tj�gfcYcYS#t
j$r|tj�gfcYcYcYSwxYwwxYwwxYw)N�s===rT)�validateFs==)	r;�base64�	b64decoder�InvalidBase64PaddingDefect�binascii�Error�InvalidBase64CharactersDefect�InvalidBase64LengthDefect)r�pad_err�missing_paddings   rrrds7���'�l�Q��G�,3�f�Z�a��i�(��O�E����W��6��F�5<�V�
.�
.�
0�1�
�	
�BD�
�	
���>�>�E�	E�� � ��5�9��5�5�7�8��
���~�~�	E�
E��$�$�W�u�_�u�E��9�9�;��6�6�8�:����
�>�>�
E���!A�!A�!C� D�D�D�

E��	E��E�sZ�0A�
A�D%�$+B�D%�D!�&AC,�'D!�(D%�,*D�D!�D%�D�D!�!D%c�J�tj|�jd�S)Nr)r@�	b64encoderr7s rr	r	�s�����G�$�+�+�G�4�4rc�N�tt|�d�\}}|dz|rdzSdzS)N�r>r)�divmodr;)r8�groups_of_3�leftovers   rrr�s0��"�3�w�<��3��K����?�8�a�3�3��3�3r)�q�bc�<�|jd�\}}}}}|jd�\}}}|j�}|jdd�}t	||�\}}	|j|�}||||fS#t$r=|jtjd|�d���|j|d�}Y�Kttf$rP|jdd�}|j�dk7r(|jtjd|�d	���Y��wxYw)
a�Decode encoded word and return (string, charset, lang, defects) tuple.

    An RFC 2047/2243 encoded word has the form:

        =?charset*lang?cte?encoded_string?=

    where '*lang' may be omitted but the other parts may not be.

    This function expects exactly such a string (that is, it does not check the
    syntax and may raise errors if the string is not well formed), and returns
    the encoded_string decoded first from its Content Transfer Encoding and
    then from the resulting bytes into unicode using the specified charset.  If
    the cte-decoded string does not successfully decode using the specified
    character set, a defect is added to the defects list and the unknown octets
    are replaced by the unicode 'unknown' character \uFDFF.

    The specified charset and language are returned.  The default for language,
    which is rarely if ever encountered, is the empty string.

    �?�*r�surrogateescapez0Encoded word contains bytes not decodable using z charset�unknown-8bitzUnknown charset z* in encoded word; decoded as unknown bytes)
�split�	partition�lowerr
�
_cte_decodersr�UnicodeDecodeError�appendr�UndecodableBytesDefect�LookupError�UnicodeEncodeError�CharsetError)	�ewr+�charset�cte�
cte_string�langr8�defects�strings	         rrr�s1��*&(�X�X�c�]�"�A�w��Z���(�(��-��G�Q��

�)�)�+�C�����):�;�G�$�S�)�'�2��G�W�
?�����(���7�D�'�)�)���<����v�4�4�62�29��H�6F�G�	H�����):�;���+�,�?�����):�;���=�=�?�n�,��N�N�6�.�.�1A�'��M<�0=�>�
?��?�s�!A8�8AD�=AD�Dc��|dk(r|jdd�}n|j|�}|�(td|�}td|�}||z
dkrdnd}t||�}|rd|z}dj||||�S)	aEncode string using the CTE encoding that produces the shorter result.

    Produces an RFC 2047/2243 encoded word of the form:

        =?charset*lang?cte?encoded_string?=

    where '*lang' is omitted unless the 'lang' parameter is given a value.
    Optional argument charset (defaults to utf-8) specifies the charset to use
    to encode the string to binary before CTE encoding it.  Optional argument
    'encoding' is the cte specifier for the encoding that should be used ('q'
    or 'b'); if it is None (the default) the encoding which produces the
    shortest encoded sequence is used, except that 'q' is preferred if it is up
    to five characters longer.  Optional argument 'lang' (default '') gives the
    RFC 2243 language string to specify in the encoded word.

    rVrrUrPrQ�rTz=?{}{}?{}?{}?=)r
�_cte_encode_length�
_cte_encodersr#)rgrb�encodingrer8�qlen�blenrs        rr
r
�s���"�.� ��-�-��):�;���-�-��(����!�#�&�w�/��!�#�&�w�/����+��/�3�s���H�%�g�.�G���T�z���"�"�7�D�(�G�D�Dr)zutf-8Nr.)�__doc__�rer@rC�	functoolsrgrr�emailr�__all__�partial�compile�subrr�dictrr1�ordrr
rr	rrZrrkrjr
r*rr�<module>rys����R
�
���(��
��#��"�"�:�2�:�:�.C�#D�#H�#H�4�6��'�	��	��k����C��H��4�5�$E�L5�4�
�	��
�
'*�V
�	��
�
�	���
Er__pycache__/_header_value_parser.cpython-312.opt-2.pyc000064400000343531151706203560016574 0ustar00�

T��h��	��
�	ddlZddlZddlZddlmZddlmZddlmZ	ddlm
Z
ddlmZed�Z
e
ed�zZed	�Zee
zZeed
�z
Zeed�z
Zeed�zed
�z
Zee
zZeed
�zZee
zZeed�z
ZddhZeezZd�Zd�Zej8dej:ej<z�ZGd�de �Z!Gd�de!�Z"Gd�de!�Z#Gd�de!�Z$Gd�de!�Z%Gd�de"�Z&Gd �d!e!�Z'Gd"�d#e!�Z(Gd$�d%e!�Z)Gd&�d'e!�Z*Gd(�d)e*�Z+Gd*�d+e"�Z,Gd,�d-e!�Z-Gd.�d/e!�Z.Gd0�d1e!�Z/Gd2�d3e!�Z0Gd4�d5e!�Z1Gd6�d7e!�Z2Gd8�d9e!�Z3Gd:�d;e!�Z4Gd<�d=e!�Z5Gd>�d?e!�Z6Gd@�dAe!�Z7GdB�dCe!�Z8GdD�dEe!�Z9GdF�dGe!�Z:GdH�dIe!�Z;GdJ�dKe!�Z<GdL�dMe$�Z=GdN�dOe!�Z>GdP�dQe!�Z?GdR�dSe!�Z@GdT�dUe!�ZAGdV�dWeA�ZBGdX�dYe!�ZCGdZ�d[e!�ZDGd\�d]e!�ZEGd^�d_e!�ZFGd`�dae!�ZGGdb�dceG�ZHGdd�deeG�ZIGdf�dge!�ZJGdh�die!�ZKGdj�dke!�ZLGdl�dmeL�ZMGdn�doeM�ZNGdp�dqe!�ZOGdr�dseP�ZQGdt�dueQ�ZRGdv�dweQ�ZSGdx�dyeR�ZTGdz�d{e
j��ZVeSd
d|�ZWeSd}d~�ZXdeX_YdeX_ZeSd�d��Z[ej8d�j�d�j�e
���j�Z_ej8d�j�ej�d�j�e����j�Zbej8d��j�Zdej8d�j�ej�d�j�e����j�Zeej8d�j�ej�d�j�e����j�Zfej8d�j�ej�d�j�e����j�Zgd��Zhd��Zid��Zjd�d��Zkd��Zld��Zmd��Znd��Zod��Zpd��Zqd��Zrd��Zsd��Ztd��Zud��Zvd��Zwd��Zxd��Zyd��Zzd��Z{d��Z|d��Z}d��Z~d��Zd��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�y)��N)�	hexdigits)�
itemgetter)�_encoded_words)�errors)�utilsz 	�(z
()<>@,:;.\"[]�.z."(z/?=z*'%�%�
�
c�Z�	t|�jdd�jdd�S)N�\�\\�"z\")�str�replace��values �3/usr/lib64/python3.12/email/_header_value_parser.py�make_quoted_pairsrcs)��E��u�:���d�F�+�3�3�C��?�?�c�$�t|�}d|�d�S)Nr)r)r�escapeds  r�quote_stringrhs����&�G�
�w�i�q�>�rz�
   =\?            # literal =?
   [^?]*          # charset
   \?             # literal ?
   [qQbB]         # literal 'q' or 'b', case insensitive
   \?             # literal ?
  .*?             # encoded word
  \?=             # literal ?=
c���eZdZdZdZdZ�fd�Zd�Z�fd�Ze	d��Z
e	d��Zd�Ze	d	��Z
e	d
��Zd�Zdd�Zdd
�Zdd�Z�xZS)�	TokenListNTc�2��t�|�|i|��g|_y�N)�super�__init__�defects)�self�args�kw�	__class__s   �rr zTokenList.__init__�s���
���$�%�"�%���rc�2�djd�|D��S)N�c3�2K�|]}t|����y�wr�r��.0�xs  r�	<genexpr>z$TokenList.__str__.<locals>.<genexpr>������,�t�!�s�1�v�t�����join�r"s r�__str__zTokenList.__str__�s���w�w�,�t�,�,�,rc�h��dj|jjt�|���S�Nz{}({})��formatr%�__name__r�__repr__�r"r%s �rr9zTokenList.__repr__�s+������t�~�~�6�6�"�W�-�/�1�	1rc�2�djd�|D��S)Nr'c3�NK�|]}|js�|j���y�wrrr*s  rr-z"TokenList.value.<locals>.<genexpr>�s����8��1����q�w�w��s�%�%r0r2s rrzTokenList.value�s���w�w�8��8�8�8rc�<�td�|D�|j�S)Nc3�4K�|]}|j���y�wr)�all_defectsr*s  rr-z(TokenList.all_defects.<locals>.<genexpr>�s����0�4�a�A�M�M�4���)�sumr!r2s rr?zTokenList.all_defects�s���0�4�0�$�,�,�?�?rc�(�|dj�S�Nr)�startswith_fwsr2s rrDzTokenList.startswith_fws�s���A�w�%�%�'�'rc�(�	td�|D��S)Nc3�4K�|]}|j���y�wr)�
as_ew_allowed)r+�parts  rr-z*TokenList.as_ew_allowed.<locals>.<genexpr>�s����7�$�$�4�%�%�$�r@)�allr2s rrGzTokenList.as_ew_allowed�s��O��7�$�7�7�7rc�N�g}|D]}|j|j��|Sr)�extend�comments)r"rL�tokens   rrLzTokenList.comments�s&�����E��O�O�E�N�N�+���rc��t||��S)N��policy)�_refold_parse_tree�r"rPs  r�foldzTokenList.fold�s��!�$�v�6�6rc�:�t|j|���y)N��indent)�print�ppstr�r"rVs  r�pprintzTokenList.pprint�s��
�d�j�j��j�'�(rc�D�dj|j|���S)NrrU)r1�_pprYs  rrXzTokenList.ppstr�s���y�y������0�1�1rc#�~K�dj||jj|j���|D]A}t	|d�s|dj|�z���&|j|dz�Ed{����C|jrdj|j�}nd}dj||���y7�E�w)Nz{}{}/{}(r\z*    !! invalid element in token list: {!r}z    z Defects: {}r'z{}){})r7r%r8�
token_type�hasattrr\r!)r"rVrM�extras    rr\z
TokenList._pp�s����������N�N�#�#��O�O��	��E��5�%�(��!5�5;�V�E�]�C�D�!�9�9�V�F�]�3�3�3���<�<�"�)�)�$�,�,�7�E��E��n�n�V�U�+�+�4�s�A3B=�5B;�6AB=�r')r8�
__module__�__qualname__r^�syntactic_break�ew_combine_allowedr r3r9�propertyrr?rDrGrLrSrZrXr\�
__classcell__�r%s@rrr}s�����J��O����-�1��9��9��@��@�(��8��8�����7�)�2�,rrc�,�eZdZed��Zed��Zy)�WhiteSpaceTokenListc��y�N� �r2s rrzWhiteSpaceTokenList.value����rc�`�|D�cgc]}|jdk(s�|j�� c}Scc}w)N�comment)r^�content�r"r,s  rrLzWhiteSpaceTokenList.comments�s)��#'�C�4�a�1�<�<��+B��	�	�4�C�C��C��+�+N)r8rbrcrfrrLrnrrrjrj�s*��
�����D��Drrjc��eZdZdZy)�UnstructuredTokenList�unstructuredN�r8rbrcr^rnrrrvrv�s���Jrrvc��eZdZdZy)�Phrase�phraseNrxrnrrrzrz�����Jrrzc��eZdZdZy)�Word�wordNrxrnrrr~r~�����Jrr~c��eZdZdZy)�CFWSList�cfwsNrxrnrrr�r��r�rr�c��eZdZdZy)�Atom�atomNrxrnrrr�r��r�rr�c��eZdZdZdZy)�TokenrMFN)r8rbrcr^�encode_as_ewrnrrr�r��s���J��Lrr�c��eZdZdZdZdZdZy)�EncodedWord�encoded-wordN)r8rbrcr^�cte�charset�langrnrrr�r��s���J�
�C��G��Drr�c�@�eZdZdZed��Zed��Zed��Zy)�QuotedString�
quoted-stringc�L�|D]}|jdk(s�|jcSy�N�bare-quoted-string�r^rrss  rrrzQuotedString.content�s"���A��|�|�3�3��w�w��rc��g}|D]G}|jdk(r|jt|���-|j|j��Idj	|�S)Nr�r')r^�appendrrr1)r"�resr,s   r�quoted_valuezQuotedString.quoted_value�sN�����A��|�|�3�3��
�
�3�q�6�"��
�
�1�7�7�#�	�
�w�w�s�|�rc�L�|D]}|jdk(s�|jcSyr�r��r"rMs  r�stripped_valuezQuotedString.stripped_value�s%���E����#7�7��{�{�"�rN)r8rbrcr^rfrrr�r�rnrrr�r��sA�� �J�
����
�����#��#rr�c�&�eZdZdZd�Zed��Zy)�BareQuotedStringr�c�D�tdjd�|D���S)Nr'c3�2K�|]}t|����y�wrr)r*s  rr-z+BareQuotedString.__str__.<locals>.<genexpr>
s����#9�D�q�C��F�D�r/)rr1r2s rr3zBareQuotedString.__str__	s���B�G�G�#9�D�#9�9�:�:rc�2�djd�|D��S)Nr'c3�2K�|]}t|����y�wrr)r*s  rr-z)BareQuotedString.value.<locals>.<genexpr>r.r/r0r2s rrzBareQuotedString.value����w�w�,�t�,�,�,rN)r8rbrcr^r3rfrrnrrr�r�s ��%�J�;��-��-rr�c�<�eZdZdZd�Zd�Zed��Zed��Zy)�Commentrqc��djtdg|D�cgc]}|j|���c}dggg��Scc}w)Nr'r�))r1rA�quoterss  rr3zComment.__str__sK���w�w�s� �E�48�9�D�q�T�Z�Z��]�D�9� �E�� "�	#�$�	$��9s�>c��|jdk(rt|�St|�jdd�jdd�jdd�S)Nrqrrrz\(r�z\))r^rr)r"rs  rr�z
Comment.quotesR�����y�(��u�:���5�z�!�!�$��/�7�7�"%�u�.�.5�g�"%�u�/.�	.rc�2�djd�|D��S)Nr'c3�2K�|]}t|����y�wrr)r*s  rr-z"Comment.content.<locals>.<genexpr>%r.r/r0r2s rrrzComment.content#r�rc��|jgSr)rrr2s rrLzComment.comments's�����~�rN)	r8rbrcr^r3r�rfrrrLrnrrr�r�s9���J�$�.��-��-����rr�c�@�eZdZdZed��Zed��Zed��Zy)�AddressListzaddress-listc�L�|D�cgc]}|jdk(s�|��c}Scc}w)N�address�r^rss  r�	addresseszAddressList.addresses/�%���;�4�a�1�<�<��#:��4�;�;��;��!�!c�(�td�|D�g�S)Nc3�RK�|]}|jdk(r|j���!y�w�r�N�r^�	mailboxesr*s  rr-z(AddressList.mailboxes.<locals>.<genexpr>5s'����>�!��Q�\�\�9�%<��K�K�!���%'�rAr2s rr�zAddressList.mailboxes3�!���>�!�>�?A�C�	Crc�(�td�|D�g�S)Nc3�RK�|]}|jdk(r|j���!y�wr��r^�
all_mailboxesr*s  rr-z,AddressList.all_mailboxes.<locals>.<genexpr>:s'����>�!��Q�\�\�9�%<��O�O�!�r�r�r2s rr�zAddressList.all_mailboxes8r�rN)r8rbrcr^rfr�r�r�rnrrr�r�+sE���J�
�<��<��C��C��C��Crr�c�@�eZdZdZed��Zed��Zed��Zy)�Addressr�c�F�|djdk(r|djSy)Nr�group�r^�display_namer2s rr�zAddress.display_nameBs)����7����(���7�'�'�'�)rc�x�|djdk(r|dgS|djdk(rgS|djS�Nr�mailbox�invalid-mailboxr�r2s rr�zAddress.mailboxesGsH����7����*���G�9��
�!�W�
�
�#4�
4��I��A�w� � � rc��|djdk(r|dgS|djdk(r|dgS|djSr�r�r2s rr�zAddress.all_mailboxesOsO����7����*���G�9��
�!�W�
�
�#4�
4���G�9���A�w�$�$�$rN)r8rbrcr^rfr�r�r�rnrrr�r�>sA���J�
�(��(��!��!��%��%rr�c�0�eZdZdZed��Zed��Zy)�MailboxList�mailbox-listc�L�|D�cgc]}|jdk(s�|��c}Scc}w)Nr�r�rss  rr�zMailboxList.mailboxes[r�r�c�H�|D�cgc]}|jdvr|��c}Scc}w)N)r�r�r�rss  rr�zMailboxList.all_mailboxes_s2���?�4�a��|�|�=�=��4�?�	?��?s�N�r8rbrcr^rfr�r�rnrrr�r�Ws-���J�
�<��<��?��?rr�c�0�eZdZdZed��Zed��Zy)�	GroupList�
group-listc�L�|r|djdk7rgS|djS�Nrr�r�r2s rr�zGroupList.mailboxesis+���t�A�w�)�)�^�;��I��A�w� � � rc�L�|r|djdk7rgS|djSr�r�r2s rr�zGroupList.all_mailboxesos+���t�A�w�)�)�^�;��I��A�w�$�$�$rNr�rnrrr�r�es-���J�
�!��!�
�%��%rr�c�@�eZdZdZed��Zed��Zed��Zy)�Groupr�c�H�|djdk7rgS|djS�N�r�r�r2s rr�zGroup.mailboxeszs)����7����-��I��A�w� � � rc�H�|djdk7rgS|djSr�r�r2s rr�zGroup.all_mailboxes�s)����7����-��I��A�w�$�$�$rc� �|djSrC)r�r2s rr�zGroup.display_name�s���A�w�#�#�#rN)r8rbrcr^rfr�r�r�rnrrr�r�vsA���J�
�!��!�
�%��%�
�$��$rr�c�`�eZdZdZed��Zed��Zed��Zed��Zed��Z	y)�NameAddr�	name-addrc�>�t|�dk(ry|djS�N�r)�lenr�r2s rr�zNameAddr.display_name�s ���t�9��>���A�w�#�#�#rc� �|djS�N�����
local_partr2s rr�zNameAddr.local_part�s���B�x�"�"�"rc� �|djSr���domainr2s rr�zNameAddr.domain�s���B�x���rc� �|djSr�)�router2s rr�zNameAddr.route�s���B�x�~�~�rc� �|djSr���	addr_specr2s rr�zNameAddr.addr_spec�s���B�x�!�!�!rN�
r8rbrcr^rfr�r�r�r�r�rnrrr�r��si���J�
�$��$�
�#��#����������"��"rr�c�P�eZdZdZed��Zed��Zed��Zed��Zy)�	AngleAddrz
angle-addrc�L�|D]}|jdk(s�|jcSy�N�	addr-spec)r^r�rss  rr�zAngleAddr.local_part�s"���A��|�|�{�*��|�|�#�rc�L�|D]}|jdk(s�|jcSyr��r^r�rss  rr�zAngleAddr.domain�s!���A��|�|�{�*��x�x��rc�L�|D]}|jdk(s�|jcSy)N�	obs-route)r^�domainsrss  rr�zAngleAddr.route�s"���A��|�|�{�*��y�y� �rc��|D]O}|jdk(s�|jr|jcSt|j�|jzcSy)Nr�z<>)r^r�r�rrss  rr�zAngleAddr.addr_spec�sF���A��|�|�{�*��<�<��;�;�&�'����5����C�C��rN)	r8rbrcr^rfr�r�r�r�rnrrr�r��sU���J�
�$��$�
� �� �
�!��!�
���rr�c� �eZdZdZed��Zy)�ObsRouter�c�`�|D�cgc]}|jdk(s�|j�� c}Scc}w)Nr�r�rss  rr�zObsRoute.domains�s)��"&�C�$�Q�!�,�,�(�*B����$�C�C��CrtN)r8rbrcr^rfr�rnrrrr�s���J�
�D��Drrc�`�eZdZdZed��Zed��Zed��Zed��Zed��Z	y)�Mailboxr�c�F�|djdk(r|djSy�Nrr�r�r2s rr�zMailbox.display_name�s)����7����,���7�'�'�'�-rc� �|djSrCr�r2s rr�zMailbox.local_part�����A�w�!�!�!rc� �|djSrCr�r2s rr�zMailbox.domain�s���A�w�~�~�rc�F�|djdk(r|djSyr)r^r�r2s rr�z
Mailbox.route�s'����7����,���7�=�=� �-rc� �|djSrCr�r2s rr�zMailbox.addr_spec�s���A�w� � � rNr�rnrrrr�si���J�
�(��(��"��"������!��!��!��!rrc�0�eZdZdZed��ZexZxZxZZ	y)�InvalidMailboxr�c��yrrnr2s rr�zInvalidMailbox.display_name����rNr�rnrrr
r
�s/��"�J�
����/;�:�J�:��:�%�)rr
c�0��eZdZdZdZe�fd��Z�xZS)�Domainr�Fc�R��djt�|�j��S�Nr'�r1rr�splitr:s �rr�z
Domain.domain������w�w�u�w�}�*�*�,�-�-r)r8rbrcr^rGrfr�rgrhs@rrr�s����J��M�
�.��.rrc��eZdZdZy)�DotAtom�dot-atomNrxrnrrrrs���Jrrc��eZdZdZdZy)�DotAtomTextz
dot-atom-textTN�r8rbrcr^rGrnrrrrs�� �J��Mrrc��eZdZdZdZy)�
NoFoldLiteralzno-fold-literalFNrrnrrrr
s��"�J��Mrrc�T�eZdZdZdZed��Zed��Zed��Zed��Z	y)�AddrSpecr�Fc� �|djSrCr�r2s rr�zAddrSpec.local_partrrc�>�t|�dkry|djS)N�r�)r�r�r2s rr�zAddrSpec.domains���t�9�q�=���B�x���rc���t|�dkr|djS|djj�|djz|djj�zS)Nr#rr�r�)r�r�rstrip�lstripr2s rrzAddrSpec.valuesU���t�9�q�=���7�=�=� ��A�w�}�}�#�#�%�d�1�g�m�m�3�D��G�M�M�4H�4H�4J�J�Jrc���t|j�}t|�t|tz
�kDrt	|j�}n|j}|j
�|dz|j
zS|S)N�@)�setr�r��
DOT_ATOM_ENDSrr�)r"�nameset�lps   rr�zAddrSpec.addr_spec$s_���d�o�o�&���w�<�#�g�m�3�4�4��d�o�o�.�B����B��;�;�"���8�d�k�k�)�)��	rN)
r8rbrcr^rGrfr�r�rr�rnrrr r s\���J��M�
�"��"�����
�K��K�
���rr c��eZdZdZdZy)�ObsLocalPartzobs-local-partFNrrnrrr.r.0s��!�J��Mrr.c�@��eZdZdZdZed��Ze�fd��Z�xZS)�DisplayNamezdisplay-nameFc��t|�}t|�dk(r|jS|djdk(r|j	d�n<t|dt�r)|ddjdk(rt|ddd�|d<|djdk(r|j	�|jSt|dt�r)|ddjdk(rt|ddd�|d<|jS)Nrr�r�r�)rr�rr^�pop�
isinstance)r"r�s  rr�zDisplayName.display_name;s�����o���s�8�q�=��9�9���q�6����&��G�G�A�J��3�q�6�9�-���F�1�I�(�(�F�2�"�3�q�6�!�"�:�.��A���r�7����'��G�G�I�
�y�y���3�r�7�I�.���G�B�K�*�*�f�4�#�C��G�C�R�L�1��B���y�y�rc���d}|jrd}n|D]}|jdk(s�d}�t|�dk7r�|r�dx}}|djdk(s(t|dt�r|ddjdk(rd}|djdk(s(t|dt�r|ddjdk(rd}|t|j�z|zSt�|� S)	NFTr�rr'r�rmr�)	r!r^r�r3rrr�rr)r"r�r,�pre�postr%s     �rrzDisplayName.valueNs�������<�<��E����<�<�?�2� �E���t�9��>�e��O�C�$��Q��"�"�f�,��4��7�I�.��Q���
�%�%��/����R��#�#�v�-��4��8�Y�/��R����'�'�6�1����|�D�$5�$5�6�6�t�;�;��7�=� r)	r8rbrcr^rerfr�rrgrhs@rr0r06s4����J���
����$�!��!rr0c�4�eZdZdZdZed��Zed��Zy)�	LocalPartz
local-partFc�b�|djdk(r|djS|djS)Nrr�)r^r�rr2s rrzLocalPart.valueks2����7����0���7�'�'�'���7�=�=� rc���tg}t}d}|dtgzD]�}|jdk(r�|r2|jdk(r#|djdk(rt|dd�|d<t|t�}|r?|jdk(r0|djdk(r|j	t|dd��n|j	|�|d}|}��t|dd�}|j
S)NFrr��dotr�r�)�DOTr^rr3r�r)r"r��last�
last_is_tl�tok�is_tls      rr�zLocalPart.local_partrs����e�����
���7�c�U�?�C��~�~��'���s�~�~��6���H�'�'�6�1�#�D��"�I�.��B���s�I�.�E��$�/�/�U�2���F�%�%��/��
�
�9�S���W�-�.��
�
�3���r�7�D��J�#���A�b�	�"���y�y�rN)r8rbrcr^rGrfrr�rnrrr8r8fs2���J��M�
�!��!����rr8c�@��eZdZdZdZe�fd��Zed��Z�xZS)�
DomainLiteralzdomain-literalFc�R��djt�|�j��Srrr:s �rr�zDomainLiteral.domain�rrc�L�|D]}|jdk(s�|jcSy)N�ptextr�rss  r�ipzDomainLiteral.ip�s!���A��|�|�w�&��w�w��r)	r8rbrcr^rGrfr�rFrgrhs@rrBrB�s3���!�J��M�
�.��.����rrBc��eZdZdZdZdZy)�MIMEVersionzmime-versionN)r8rbrcr^�major�minorrnrrrHrH�s���J��E��ErrHc�<�eZdZdZdZdZdZed��Zed��Z	y)�	Parameter�	parameterF�us-asciic�<�|jr|djSdSr�)�	sectioned�numberr2s r�section_numberzParameter.section_number�s��"&���t�A�w�~�~�6�Q�6rc���|D]n}|jdk(r|jcS|jdk(s�0|D]:}|jdk(s�|D]#}|jdk(s�|jcccS�<�py)Nrr�r�r')r^r�r�s  r�param_valuezParameter.param_value�sx���E����7�*��+�+�+����?�2�"�E��'�'�+?�?�%*�E�$�/�/�7�:�',�';�';� ;�&+�#�	�rN)
r8rbrcr^rP�extendedr�rfrRrTrnrrrLrL�s<���J��I��H��G�
�7��7�
���rrLc��eZdZdZy)�InvalidParameter�invalid-parameterNrxrnrrrWrW�s��$�JrrWc� �eZdZdZed��Zy)�	Attribute�	attributec�d�|D]+}|jjd�s�|jcSy)N�attrtext)r^�endswithrr�s  rr�zAttribute.stripped_value�s*���E����(�(��4��{�{�"�rN�r8rbrcr^rfr�rnrrrZrZ�s���J�
�#��#rrZc��eZdZdZdZy)�Section�sectionN)r8rbrcr^rQrnrrrara�s���J�
�Frrac� �eZdZdZed��Zy)�Valuerc��|d}|jdk(r|d}|jjd�r|jS|jS)Nrr�r�)r�r[zextended-attribute)r^r^r�rr�s  rr�zValue.stripped_value�sP���Q������v�%���G�E����$�$�D�F��'�'�'��z�z�rNr_rnrrrdrd�s���J�
���rrdc�*�eZdZdZdZed��Zd�Zy)�MimeParameters�mime-parametersFc#�lK�i}|D]w}|jjd�s�|djdk7r�2|djj�}||vrg||<||j	|j
|f��y|j
�D�]�\}}t|td���}|dd}|j}|jsRt|�dkDrD|dddk(r9|ddjj	tjd��|dd}g}d}|D�]\}	}
|	|k7ri|
js/|
jj	tjd���G|
jj	tjd��|dz
}|
j}|
jrv	t j"j%|�}	|j'|d	�}t-j.|�r.|
jj	tj0��	|j	|���d
j5|�}||f�����y#t(t*f$r|j'd
d	�}Y��wxYw#t*$r$t j"j3|d��}Y��wxYw�w)NrMrr[)�keyr�z.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numbering�surrogateescaperNzlatin-1)�encodingr')r^r^r�stripr�rR�items�sortedrr�rUr�r!r�InvalidHeaderDefectrT�urllib�parse�unquote_to_bytes�decode�LookupError�UnicodeEncodeErrorr�_has_surrogates�UndecodableBytesDefect�unquoter1)r"�paramsrM�name�parts�first_paramr��value_parts�irR�paramrs            rrzzMimeParameters.params�s��������E��#�#�,�,�[�9���Q�x�"�"�k�1����8�>�>�'�'�)�D��6�!�!��t���4�L����!5�!5�u� =�>��"�<�<�>�K�D�%��5�j��m�4�E���(�1�+�K�!�)�)�G��'�'�C��J��N���8�A�;�!�#��!�H�Q�K�'�'�.�.�v�/I�/I�H�0J�K�!�"�1�I�E��K��A�).�%���!�Q�&�!�>�>��
�
�,�,�V�-G�-G�I�.K�L� ��
�
�,�,�V�-G�-G�F�.H�I��Q����)�)���>�>�R� &��� =� =�e� D��P�$)�L�L��:K�$L�E�!�0�0��7�!�M�M�0�0��1N�1N�1P�Q��"�"�5�)�C*/�D�G�G�K�(�E���+��g*��R!,�-?�@�P�
%*�L�L��=N�$O�E�P��.�P�!'��� 4� 4�U�Y� 4� O��	P�sI�F6J4�9J�I�+A2J4�!J�>J4�J�J4�*J1�.J4�0J1�1J4c	���g}|jD]C\}}|r+|jdj|t|����3|j|��Edj	|�}|rd|zSdS)N�{}={}z; rmr')rzr�r7rr1)r"rzr{rs    rr3zMimeParameters.__str__,se�����;�;�K�D�%���
�
�g�n�n�T�<��3F�G�H��
�
�d�#�	'�
���6�"��%�s�V�|�-�2�-rN)r8rbrcr^rdrfrzr3rnrrrgrg�s&��"�J��O�
�C��C�J.rrgc� �eZdZdZed��Zy)�ParameterizedHeaderValueFc�`�t|�D]}|jdk(s�|jcSiS)Nrh)�reversedr^rzr�s  rrzzParameterizedHeaderValue.params=s0���d�^�E����#4�4��|�|�#�$��	rN)r8rbrcrdrfrzrnrrr�r�7s���O�
���rr�c��eZdZdZdZdZdZy)�ContentTypezcontent-typeF�text�plainN)r8rbrcr^rG�maintype�subtypernrrr�r�Es���J��M��H��Grr�c��eZdZdZdZdZy)�ContentDispositionzcontent-dispositionFN)r8rbrcr^rG�content_dispositionrnrrr�r�Ls��&�J��M��rr�c��eZdZdZdZdZy)�ContentTransferEncodingzcontent-transfer-encodingF�7bitN)r8rbrcr^rGr�rnrrr�r�Rs��,�J��M�
�Crr�c��eZdZdZdZy)�HeaderLabelzheader-labelFNrrnrrr�r�Xs���J��Mrr�c��eZdZdZdZd�Zy)�MsgIDzmsg-idFc�2�t|�|jzSr)r�lineseprRs  rrSz
MsgID.foldas���4�y�6�>�>�)�)rN)r8rbrcr^rGrSrnrrr�r�]s���J��M�*rr�c��eZdZdZy)�	MessageIDz
message-idNrxrnrrr�r�fs���Jrr�c��eZdZdZy)�InvalidMessageIDzinvalid-message-idNrxrnrrr�r�js��%�Jrr�c��eZdZdZy)�Header�headerNrxrnrrr�r�nr|rr�c�r��eZdZdZdZdZ�fd�Z�fd�Zd�Ze	d��Z
d
�fd�	Zd�Ze	d��Z
d	�Z�xZS)�TerminalTc�D��t�|�||�}||_g|_|Sr)r�__new__r^r!)�clsrr^r"r%s    �rr�zTerminal.__new__|s&����w��s�E�*��$�������rc�h��dj|jjt�|���Sr5r6r:s �rr9zTerminal.__repr__�s&������t�~�~�6�6���8H�8J�K�Krc�b�t|jjdz|jz�y)N�/)rWr%r8r^r2s rrZzTerminal.pprint�s"��
�d�n�n�%�%��+�d�o�o�=�>rc�,�t|j�Sr)�listr!r2s rr?zTerminal.all_defects�s���D�L�L�!�!rc	����dj||jj|jt�|��|jsd�gSdj|j��gS)Nz
{}{}/{}({}){}r'z {})r7r%r8r^rr9r!)r"rVr%s  �rr\zTerminal._pp�sg����&�&���N�N�#�#��O�O��G����l�l�B���	�
).���T�\�\�(B���	rc��yrrnr2s r�pop_trailing_wszTerminal.pop_trailing_ws�rrc��gSrrnr2s rrLzTerminal.comments�s���	rc�0�t|�|jfSr)rr^r2s r�__getnewargs__zTerminal.__getnewargs__�s���4�y�$�/�/�*�*rra)r8rbrcrGrerdr�r9rZrfr?r\r�rLr�rgrhs@rr�r�vsZ����M����O��L�?��"��"�������+rr�c�"�eZdZed��Zd�Zy)�WhiteSpaceTerminalc��yrlrnr2s rrzWhiteSpaceTerminal.value�rorc��y)NTrnr2s rrDz!WhiteSpaceTerminal.startswith_fws�s��rN�r8rbrcrfrrDrnrrr�r��s��
����rr�c�"�eZdZed��Zd�Zy)�
ValueTerminalc��|Srrnr2s rrzValueTerminal.value�s���rc��y)NFrnr2s rrDzValueTerminal.startswith_fws�s��rNr�rnrrr�r��s��
����rr�c�"�eZdZed��Zd�Zy)�EWWhiteSpaceTerminalc��yrrnr2s rrzEWWhiteSpaceTerminal.value�s��rc��yrrnr2s rr3zEWWhiteSpaceTerminal.__str__�s��rN)r8rbrcrfrr3rnrrr�r��s��
����rr�c��eZdZy)�_InvalidEwErrorN)r8rbrcrnrrr�r��s��;rr�r;�,zlist-separatorFr(zroute-component-markerz([{}]+)r'z[^{}]+z[\x00-\x20\x7F]c��	t|�}|r.|jjtj|��tj|�r/|jjtjd��yy)Nz*Non-ASCII characters found in header token)�_non_printable_finderr!r�r�NonPrintableDefectrrwrx)�xtext�non_printabless  r�_validate_xtextr��sd��J�*�5�1�N��
�
�
���V�6�6�~�F�G����U�#�
�
�
���V�:�:�8�:�	;�$rc�$�	t|d�^}}g}d}d}tt|��D]6}||dk(r
|rd}d}nd}�|rd}n	|||vrn|j||��8dz}dj	|�dj	||dg|z�|fS)Nr�FrTr')�
_wsp_splitter�ranger�r�r1)r�endchars�fragment�	remainder�vchars�escape�had_qp�poss        r�_get_ptext_to_endcharsr��s����)���2��H�y�
�F�
�F�
�F��S��]�#���C�=�D� �����������F�
�c�]�h�
&���
�
�h�s�m�$�$��A�g��
�7�7�6�?�B�G�G�X�c�d�^�$4�y�$@�A�6�I�Irc�t�	|j�}t|dt|�t|�z
d�}||fS)N�fws)r&r�r�)r�newvaluer�s   r�get_fwsr�s?����|�|�~�H�
�U�#<�C��J�s�8�}�$<�=�u�
E�C���=�rc��	t�}|jd�s$tjdj	|���|ddjdd�^}}||ddk(r$tjdj	|���dj
|�}t|�dkDrF|dtvr;|dtvr0|jd�dkr|jdd�^}}|dz|z}t|j��dkDr.|jjtjd	��||_
dj
|�}	tjd|zdz�\}}}	}
||_|	|_|jj+|
�|ru|dt,vr t/|�\}}|j|��-t1|d�^}}t3||�}
t5|
�|j|
�dj
|�}|r�u|r9|dt,vr.|jjtjd��||fS#t t"f$r%t%d
j	|j���wxYw)N�=?z"expected encoded word but found {}r�z?=r�r'r�?zwhitespace inside encoded wordz!encoded word format invalid: '{}'z.missing trailing whitespace after encoded-word)r��
startswithr�HeaderParseErrorr7rr1r�r�countr!r�rpr��_ewrt�
ValueError�KeyErrorr�r�r�rK�WSPr�r�r�r�)r�
terminal_type�ewr?r��remstr�restr�r�r�r!rM�chars�vtexts              r�get_encoded_wordr� se���
��B����D�!��%�%�0�7�7��>�@�	@��A�B�i�o�o�d�A�.�O�C�)�
�e�A�B�i���%�%�0�7�7��>�@�	@�
�W�W�Y�
�F��F��a���q�	�Y���q�	�Y���	�	�#����!�<�<��a�0���y��D�j�4���
�3�9�9�;��!��
�
�
���&�4�4�,�.�	/�
�B�F��G�G�I��E�@�'*�z�z�$��*�t�2C�'D�$��g�t�W��B�J��B�G��J�J���g��
���7�c�>�!�$�-�K�E�4��I�I�e���)�$��2���	��e�]�3�����
�	�	�%���w�w�y�!���
��q���$�
�
�
���&�4�4�<�>�	?�
�u�9���)
��!�@��/�6�6�r�v�v�>�@�	@�@�s� I�4I?c�"�	t�}|�r[|dtvr t|�\}}|j|��.d}|j	d�r�	t|d�\}}d}t
|�dkDrB|djdk7r0|jjtjd��d}|r2t
|�d	kDr$|d
jdk(rt|dd�|d<|j|���t|d	�^}}|r(tj!|�r|j#d�^}}t%|d�}t'|�|j|�dj)|�}|r��[|S#t$rd}Y��tj$rY��wxYw)
NrTr��utextr�r�z&missing whitespace before encoded wordFr����r�r')rvr�r�r�r�r�r�r^r!rrpr�r�r�r��rfc2047_matcher�search�	partitionr�r�r1)rrwrM�valid_ew�have_wsr?r�r�s        r�get_unstructuredr�Qs����,)�*�L�
���8�s�?�"�5�>�L�E�5�����&�������D�!�
�/��w�?���u����|�$�q�(�#�B�'�2�2�e�;�$�,�,�3�3�F�4N�4N�D�5F�G�"'���s�<�0�1�4�#�B�'�2�2�n�D�+?�(��,�e�,5��R�(��#�#�E�*��'��q�1���i���.�.�s�3�#�o�o�d�3�O�C�)��c�7�+��������E�"����	�"��Q�R���A#�
!� ���*�*�
��
�s�E,�,F�9F�
Fc�Z�	t|d�\}}}t|d�}t|�||fS)Nz()rE)r�r�r��rrE�_s   r�get_qp_ctextr��s9��
�-�U�D�9�O�E�5�!��u�g�.�E��E���%�<�rc�Z�	t|d�\}}}t|d�}t|�||fS)NrrE)r�r�r�r�s   r�get_qcontentr��s9���-�U�C�8�O�E�5�!��%��)�E��E���%�<�rc���	t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)Nzexpected atext but found '{}'�atext)�_non_atom_end_matcherrr�r7r�r�r�r�)r�mr�s   r�	get_atextr��sp���
	�e�$�A���%�%�+�2�2�5�9�;�	;�
�G�G�I�E��#�e�*�+��E��%��)�E��E���%�<�rc�P�	|r|ddk7r$tjdj|���t�}|dd}|r'|ddk(rt	|�\}}|j|�|r�|ddk7r�|dtvrt|�\}}n�|dddk(r�d}	t|�\}}|jjtjd��d	}|rSt|�dkDrE|d
jdk(r3|djd
k(r!t|d
d�|d
<nt	|�\}}|j|�|r	|ddk7r��|s2|jjtjd��||fS||ddfS#tj$rt	|�\}}Y��wxYw)Nrrzexpected '"' but found '{}'r�r�r�Fz!encoded word inside quoted stringTr�r�r�r�z"end of header inside quoted string)rr�r7r�r�r�r�r�r�r!rpr�r^r�)r�bare_quoted_stringrMr�s    r�get_bare_quoted_stringr��s�����E�!�H��O��%�%�*�1�1�%�8�:�	:�)�+���!�"�I�E���q��S��#�E�*���u��!�!�%�(�
�E�!�H��O���8�s�?�"�5�>�L�E�5�
�2�A�Y�$�
��H�
3�/��6���u�"�*�*�1�1�&�2L�2L�7�39�:���
�C� 2�3�a�7�&�r�*�5�5��>�*�2�.�9�9�^�K�-A�*�2�.��.7�&�r�*�(��.�L�E�5��!�!�%�(�+�E�!�H��O�,��"�"�)�)�&�*D�*D�0�+2�	3�!�5�(�(��u�Q�R�y�(�(��!�*�*�
3�+�E�2���u�
3�s�>F�!F%�$F%c��	|r,|ddk7r$tjdj|���t�}|dd}|rc|ddk7r[|dtvrt|�\}}n%|ddk(rt
|�\}}nt|�\}}|j|�|r	|ddk7r�[|s2|jjtjd��||fS||ddfS)Nrrzexpected '(' but found '{}'r�r�zend of header inside comment)rr�r7r�r�r��get_commentr�r�r!rp)rrqrMs   rr�r��s����

��q��S���%�%�)�0�0��7�9�	9��i�G��!�"�I�E�
�E�!�H��O���8�s�?�"�5�>�L�E�5�
�1�X��_�&�u�-�L�E�5�'��.�L�E�5����u���E�!�H��O�������v�9�9�*� ,�	-���~���E�!�"�I��rc���	t�}|rR|dtvrG|dtvrt|�\}}nt	|�\}}|j|�|r|dtvr�G||fSrC)r��CFWS_LEADERr�r�r�r�)rr�rMs   r�get_cfwsrsl����:�D�
�E�!�H��+���8�s�?�"�5�>�L�E�5�&�u�-�L�E�5����E���E�!�H��+���;�rc��	t�}|r*|dtvrt|�\}}|j|�t	|�\}}|j|�|r*|dtvrt|�\}}|j|�||fSrC)r�rrr�r�)r�
quoted_stringrMs   r�get_quoted_stringrs����!�N�M���q��[�(������u����U�#�)�%�0�L�E�5��������q��[�(������u����U�#��%��rc��	t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���|jd�r	t|�\}}nt|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS#t
j$rt|�\}}Y�dwxYw)Nrzexpected atom but found '{}'r�)r�rrr��	ATOM_ENDSrr�r7r�r�r�)rr�rMs   r�get_atomr's�����6�D���q��[�(������u����E����q��Y�&��%�%�*�1�1�%�8�:�	:������	,�+�E�2�L�E�5�!��'���u��K�K�����q��[�(������u����E����;����&�&�	,�%�U�+�L�E�5�	,�s�;C�!C=�<C=c��	t�}|r|dtvr$tjdj	|���|r\|dtvrQt|�\}}|j
|�|r"|ddk(r|j
t�|dd}|r|dtvr�Q|dtur'tjdj	d|z���||fS)Nrz8expected atom at a start of dot-atom-text but found '{}'r	r�r�z4expected atom at end of dot-atom-text but found '{}')rrrr�r7r�r�r<)r�
dot_atom_textrMs   r�get_dot_atom_textr
Bs���� �M�M��E�!�H�	�)��%�%�'+�+1�6�%�=�:�	:�
�E�!�H�I�-� ��'���u����U�#��U�1�X��_�� � ��%��!�"�I�E��E�!�H�I�-��R��C���%�%�'�#�V�C��I�.�0�	0��%��rc��	t�}|dtvrt|�\}}|j|�|j	d�r	t|�\}}nt|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS#tj$rt|�\}}Y�dwxYw)Nrr�)	rrrr�r�r�rr�r
)r�dot_atomrMs   r�get_dot_atomr
Us����
�y�H��Q�x�;�������u�����������	4�+�E�2�L�E�5�)��/���u��O�O�E����q��[�(������u�������U�?����&�&�	4�-�U�3�L�E�5�	4�s�B&�&!C
�	C
c�*�	|dtvrt|�\}}nd}|stjd��|ddk(rt	|�\}}n=|dt
vr$tjdj
|���t|�\}}|�|g|dd||fS)Nrz5Expected 'atom' or 'quoted-string' but found nothing.rz1Expected 'atom' or 'quoted-string' but found '{}')rrrr�r�SPECIALSr7r)r�leaderrMs   r�get_wordrns����
�Q�x�;�� ���
�������%�%�C�E�	E��Q�x��}�(��/���u�	�q��X�	��%�%�'7�7=�v�e�}�F�	F� �����u�
���H��b�q�	��%�<�rc���	t�}	t|�\}}|j|�|r�|dtvr|ddk(rI|jt�|j
jtjd��|dd}n 	t|�\}}|j|�|r|dtvr�||fS#tj$r1|j
jtjd��Y��wxYw#tj$rL|dtvr=t|�\}}|j
jtjd��n�Y��wxYw)Nzphrase does not start with wordrr	zperiod in 'phrase'r�zcomment found without atom)rzrr�rr�r!rp�PHRASE_ENDSr<�ObsoleteHeaderDefectrr)rr{rMs   r�
get_phraser�sR��
��X�F�0������u��
�
�e���E�!�H�K�/���8�S�=��M�M�#���N�N�!�!�&�"=�"=�$�#&�
'��!�"�I�E�
�'�����u�
�M�M�%� �!�E�!�H�K�/�"�5�=���)�"�"�0������f�8�8�-�/�	0�0���*�*�
���8�{�*�#+�E�?�L�E�5��N�N�)�)�&�*E�*E�4�+6�7��7�
�s%�B<�D�<AD�?D�AE"�!E"c��	t�}d}|r|dtvrt|�\}}|s$tjdj|���	t
|�\}}|�|g|dd|j|�|r�|ddk(s|dtvr�tt|�|z�\}}|jdk(r/|jjtjd��n.|jjtj d��||d<	|j"j%d�||fS#tj$rK	t|�\}}n7#tj$r!|ddk7r|dtvr�t�}YnwxYwY��6wxYw#t&$r4|jjtj(d��Y||fSwxYw)	Nrz"expected local-part but found '{}'r�invalid-obs-local-partz<local-part is not dot-atom, quoted-string, or obs-local-partz,local-part is not a dot-atom (contains CFWS)�asciiz)local-part contains non-ASCII characters))r8rrrr�r7r
rrrr��get_obs_local_partrr^r!rprr�encoderv�NonASCIILocalPartDefect)rr�rrM�obs_local_parts     r�get_local_partr�s������J�
�F���q��[�(� ���
�����%�%�0�7�7��>�@�	@� �#�E�*���u����H��b�q�	����e���%��(�D�.�E�!�H�K�$?� 2�3�z�?�U�3J� K�����$�$�(@�@����%�%�f�&@�&@�N�'P�
Q�
���%�%�f�&A�&A�>�'@�
A�&�
�1�
�>�������(��u����1�"�"� �	 �#�E�?�L�E�5���&�&�	 ��Q�x�4��E�!�H��$;���K�E�	 �� ��*�>����!�!�&�"@�"@�;�#=�	>��u���>�sH�D7�F�7F�E�F�1F�F�
F�F�F�7G�Gc�P�	t�}d}|�rB|ddk(s|dtv�r.|ddk(rM|r.|jjt	j
d��|jt�d}|dd}�l|ddk(rT|jt|dd��|dd}|jjt	j
d	��d}��|r@|d
jdk7r.|jjt	j
d��	t|�\}}d}|j|�|r|ddk(r��!|dtvr��.|s$t	jd
j|���|djdk(s2|djdk(rNt|�dkDr@|djdk(r.|jjt	j
d��|d
jdk(s2|d
jdk(rNt|�dkDr@|djdk(r.|jjt	j
d��|jrd|_||fS#tj$r|dtvr�t|�\}}Y��{wxYw)NFrrr	zinvalid repeated '.'Tr��misplaced-specialz/'\' character outside of quoted-string/ccontentr�r;zmissing '.' between wordsz&expected obs-local-part but found '{}'r�z!Invalid leading '.' in local partr�z"Invalid trailing '.' in local partr)r.rr!r�rrpr<r�r^rr�rrr7r�)rr�last_non_ws_was_dotrMs    rrr�s����!�^�N���
�U�1�X�t�^�u�Q�x�{�'B���8�s�?�"��&�&�-�-�f�.H�.H�*�/,�-��!�!�#�&�"&���!�"�I�E��
�1�X�t�^��!�!�-��a��0C�#E�
F��!�"�I�E��"�"�)�)�&�*D�*D�B�+D�
E�"'����n�R�0�;�;�u�D��"�"�)�)�&�*D�*D�+�+-�
.�	+�#�E�?�L�E�5�"'��
	���e�$�7�U�1�X�t�^�u�Q�x�{�'B�8��%�%�4�;�;�E�B�D�	D��q��$�$��-��1��(�(�&�0����!�#��1��(�(�%�/����%�%�f�&@�&@�/�'1�	2��r��%�%��.��2��)�)�6�1����!�#��2��)�)�5�0����%�%�f�&@�&@�0�'2�	3����$<��!��5� � ��-�&�&�	+��Q�x�{�*��#�E�?�L�E�5�	+�s�I4�4-J%�$J%c��	t|d�\}}}t|d�}|r.|jjt	j
d��t
|�||fS)Nz[]rEz(quoted printable found in domain-literal)r�r�r!r�rrr�)rrEr�s   r�	get_dtextr"s_��
�2�%��>��E�5�&��%��)�E�
�
�
�
���V�8�8�6�8�	9��E���%�<�rc��|ry|jtjd��|jtdd��y)NFz"end of input inside domain-literal�]�domain-literal-endT)r�rrpr�)r�domain_literals  r�_check_for_early_dl_endr'%s?�������&�4�4�,�.�/����-��-A�B�C�rc�p�	t�}|dtvrt|�\}}|j|�|st	j
d��|ddk7r$t	j
dj
|���|dd}t||�r||fS|jtdd��|dtvrt|�\}}|j|�t|�\}}|j|�t||�r||fS|dtvrt|�\}}|j|�t||�r||fS|ddk7r$t	j
dj
|���|jtdd	��|dd}|r*|dtvrt|�\}}|j|�||fS)
Nrzexpected domain-literal�[z6expected '[' at start of domain-literal but found '{}'r�zdomain-literal-startr$z4expected ']' at end of domain-literal but found '{}'r%)rBrrr�rr�r7r'r�r�r�r")rr&rMs   r�get_domain_literalr*-s����#�_�N��Q�x�;�������u����e�$���%�%�&?�@�@��Q�x�3���%�%�'!�!'����0�	0��!�"�I�E��u�n�5��u�$�$����-��-C�D�E��Q�x�3���u�~���u����e�$��U�#�L�E�5����%� ��u�n�5��u�$�$��Q�x�3���u�~���u����e�$��u�n�5��u�$�$��Q�x�3���%�%�'!�!'����0�	0����-��-A�B�C��!�"�I�E���q��[�(������u����e�$��5� � rc�$�	t�}d}|r|dtvrt|�\}}|s$tjdj|���|ddk(r+t
|�\}}|�|g|dd|j|�||fS	t|�\}}|r|ddk(rtjd��|�|g|dd|j|�|r�|ddk(r�|jjtjd��|djdk(r|d|dd|rJ|ddk(rB|jt�t|d	d�\}}|j|�|r	|ddk(r�B||fS#tj$rt|�\}}Y��wxYw)
Nrzexpected domain but found '{}'r)r(zInvalid Domainr	z(domain is not a dot-atom (contains CFWS)rr�)rrrrr�r7r*r�r
rr!rr^r<)rr�rrMs    r�
get_domainr,Ts�����X�F�
�F���q��[�(� ���
�����%�%�,�3�3�E�:�<�	<��Q�x�3��)�%�0���u�����E�"�1�I��
�
�e���u�}��'�#�E�*���u�
��q��S���%�%�&6�7�7�
���H��b�q�	�
�M�M�%����q��S�������f�9�9�6�8�	9��!�9���:�-��q�	�F�1�I���a��C���M�M�#��#�E�!�"�I�.�L�E�5��M�M�%� ���a��C���5�=���!�"�"�'������u�'�s�E+�+!F�Fc�P�	t�}t|�\}}|j|�|r|ddk7r2|jjt	j
d��||fS|jt
dd��t|dd�\}}|j|�||fS)Nrr(z#addr-spec local part with no domain�address-at-symbolr�)r rr�r!rrpr�r,)rr�rMs   r�
get_addr_specr/zs�����
�I�!�%�(�L�E�5�
���U���E�!�H��O���� � ��!;�!;�1�"3�	4��%���
���]�3�(;�<�=��e�A�B�i�(�L�E�5�
���U���e��rc���	t�}|rw|ddk(s|dtvrd|dtvr t|�\}}|j|�n"|ddk(r|jt�|dd}|r|ddk(r�X|dtvr�d|r|ddk7r$tjdj|���|jt�t|dd�\}}|j|�|r�|ddk(r�|jt�|dd}|snw|dtvrt|�\}}|j|�|snJ|ddk(r7|jt�t|dd�\}}|j|�|r	|ddk(r��|stjd��|ddk7r$tjdj|���|jtdd	��||ddfS)
Nrr�r�r(z(expected obs-route domain but found '{}'z%end of header while parsing obs-route�:z4expected ':' marking end of obs-route but found '{}'zend-of-obs-route-marker)rrrr��
ListSeparatorrr�r7�RouteComponentMarkerr,r�)r�	obs_routerMs   r�
get_obs_router5�s�����
�I�
�U�1�X�s�]�e�A�h�+�&=���8�{�"�#�E�?�L�E�5����U�#�
�1�X��_����]�+��!�"�I�E�
�U�1�X�s�]�e�A�h�+�&=��E�!�H��O��%�%�6�=�=�e�D�F�	F�
���)�*��e�A�B�i�(�L�E�5�
���U��
�E�!�H�c�M�����'��a�b�	������8�{�"�#�E�?�L�E�5����U�#�����8�s�?����1�2�%�e�A�B�i�0�L�E�5����U�#��E�!�H�c�M���%�%�&M�N�N��Q�x�3���%�%�('�'-�v�e�}�6�	6�
���]�3�(A�B�C��e�A�B�i��rc�z�	t�}|r*|dtvrt|�\}}|j|�|r|ddk7r$t	j
dj
|���|jtdd��|dd}|rZ|ddk(rR|jtdd��|jjt	jd��|dd}||fS	t|�\}}|j|�|r|ddk(r|dd}n.|jjt	jd��|jtdd��|r*|dtvrt|�\}}|j|�||fS#tj
$r�	t|�\}}|jjt	jd	��n;#tj
$r%t	j
d
j
|���wxYw|j|�t|�\}}Y��HwxYw)Nr�<z"expected angle-addr but found '{}'zangle-addr-startr��>zangle-addr-endznull addr-spec in angle-addrz*obsolete route specification in angle-addrz.expected addr-spec or obs-route but found '{}'z"missing trailing '>' on angle-addr)
r�rrr�rr�r7r�r!rpr/r5r)r�
angle_addrrMs   r�get_angle_addrr:�s9�����J���q��[�(������u����%� ��E�!�H��O��%�%�0�7�7��>�@�	@����m�C�);�<�=��!�"�I�E�
��q��S�����-��-=�>�?����!�!�&�"<�"<�*�#,�	-��a�b�	���5� � �,�$�U�+���u����e����q��S���a�b�	�����!�!�&�"<�"<�0�#2�	3����m�C�)9�:�;���q��[�(������u����%� ��u����)�"�"�	,�	P�(��/�L�E�5����%�%�f�&A�&A�<�'>�
?���&�&�	P��)�)�@�G�G��N�P�
P�	P��	���%� �$�U�+���u�	,�s*�#F�H:�<G�H:�8H�"H:�9H:c��	t�}t|�\}}|j|dd�|jdd|_||fSr)r0rrKr!)rr�rMs   r�get_display_namer<�sL����=�L��e�$�L�E�5�����a��!� �=�=��+�L�����rc��	t�}d}|s$tjdj|���|dtvr4t|�\}}|s$tjdj|���|ddk7r�|dtvr$tjdj|���t|�\}}|s$tjdj|���|�%t|dt�r
|g|dddn|g|ddd}|j|�t|�\}}|�|g|dd|j|�||fS)Nz!expected name-addr but found '{}'rr7)r�rr�r7rrrr<r3rr�r:)r�	name_addrrrMs    r�
get_name_addrr?�se����
�I�
�F���%�%�/�6�6�u�=�?�	?��Q�x�;�� ���
�����)�)�3�:�:�6�B�D�
D��Q�x�3����8�{�"��)�)�3�:�:�5�A�C�
C�'��.���u���)�)�3�:�:�5�A�C�
C����%��(�I�.� &�x��a���!��#�H��b�q�	��F������!�%�(�L�E�5�
���H��b�q�	�
���U���e��rc�n�	t�}	t|�\}}t
d�|jD��rd|_|j|�||fS#tj$rN	t	|�\}}n;#tj$r%tjdj|���wxYwY��wxYw)Nzexpected mailbox but found '{}'c3�PK�|]}t|tj���� y�wr)r3rrpr*s  rr-zget_mailbox.<locals>.<genexpr>%s%����3� 1�1��a��3�3�4� 1���$&r�)
rr?rr�r/r7�anyr?r^r�)rr�rMs   r�get_mailboxrDs����
�i�G�A�$�U�+���u��3� %� 1� 1�3�3�.����N�N�5���E�>����"�"�A�	A�(��/�L�E�5���&�&�	A��)�)�1�8�8��?�A�
A�	A���A�s)�A�B4�'A6�5B4�68B.�.B4�3B4c���	t�}|r_|d|vrX|dtvr$|jt|dd��|dd}nt	|�\}}|j|�|r|d|vr�X||fS)Nrrr�)r
rr�r�r)rr��invalid_mailboxrMs    r�get_invalid_mailboxrG+s����%�&�O�
�E�!�H�H�,���8�{�"��"�"�=��q��1D�$F�
G��!�"�I�E�%�e�,�L�E�5��"�"�5�)��E�!�H�H�,��E�!�!rc�^�	t�}|r�|ddk7r�	t|�\}}|j|�|ra|ddvrZ|d}d|_t|d�\}}|j|�|jjtjd��|r"|ddk(r|jt�|d	d}|r	|ddk7r��||fS#tj$�rLd}|dt
vr�t
|�\}}|r|ddvr@|j|�|jjtjd��n�t|d�\}}|�|g|dd|j|�|jjtjd��n�|ddk(r/|jjtjd��nVt|d�\}}|�|g|dd|j|�|jjtjd��Y���wxYw)
Nr�;z,;zempty element in mailbox-listzinvalid mailbox in mailbox-listr�r�r�r�)r�rDr�rr�rrr!rrGrpr^rKr2)r�mailbox_listrMrr�s     r�get_mailbox_listrK=s:��
��=�L�
�E�!�H��O�	8�&�u�-�L�E�5�����&�4�U�1�X�T�)�#�2�&�G�!2�G��.�u�d�;�L�E�5��N�N�5�!�� � �'�'��(B�(B�1�)3�
4��U�1�X��_����
�.��!�"�I�E�Q�E�!�H��O�R�����K�&�&�	8��F��Q�x�;�&� (���
�����a��D� 0� �'�'��/� �(�(�/�/��0K�0K�7�19�:�$7�u�d�#C�L�E�5��)�%+�H��b�q�	� �'�'��.� �(�(�/�/��0J�0J�9�1;�<��q��S���$�$�+�+�F�,G�,G�3�-5�6� 3�5�$�?���u��%�!'��E�"�1�I��#�#�E�*��$�$�+�+�F�,F�,F�5�-7�8��/	8�s�C�EH,�+H,c��	t�}|s2|jjtjd��||fSd}|r{|dt
vrpt
|�\}}|sC|jjtjd��|j|�||fS|ddk(r|j|�||fSt|�\}}t|j�dk(rV|�|j|�|j|�|jjtjd��||fS|�|g|dd|j|�||fS)Nzend of header before group-listrzend of header in group-listrIzgroup-list with empty entries)r�r!r�rrprrrKr�r�rKr)r�
group_listrrMs    r�get_group_listrNvsf�����J�����!�!�&�"<�"<�-�#/�	0��5� � �
�F���q��[�(� ���
����
���%�%�f�&@�&@�-�'/�
0����f�%��u�$�$���8�s�?����f�%��u�$�$�#�E�*�L�E�5�
�5�����"������f�%����%� ����!�!�&�"=�"=�+�#-�	.��5� � �
���H��b�q�	����e���u��rc���	t�}t|�\}}|r|ddk7r$tjdj	|���|j|�|jt
dd��|dd}|r*|ddk(r"|jt
dd��||ddfSt|�\}}|j|�|s/|jjtjd��n,|ddk7r$tjd	j	|���|jt
dd��|dd}|r*|dtvrt|�\}}|j|�||fS)
Nrr1z8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorr�rIzgroup-terminatorzend of header in groupz)expected ';' at end of group but found {})r�r<rr�r7r�r�rNr!rprr)rr�rMs   r�	get_grouprP�sf���
�G�E�#�E�*�L�E�5��E�!�H��O��%�%�'*�*0�&��-�9�	9�	�L�L���	�L�L��s�$C�D�E��!�"�I�E���q��S��
���]�3�(:�;�<��e�A�B�i���!�%�(�L�E�5�	�L�L����
�
�
���V�7�7�$�&�	'�	�q��S���%�%�7�>�>�u�E�G�	G�	�L�L��s�$6�7�8��!�"�I�E���q��[�(������u�
���U���%�<�rc�(�	t�}	t|�\}}|j
|�||fS#tj$rN	t	|�\}}n;#tj$r%tjdj|���wxYwY�uwxYw)Nzexpected address but found '{}')r�rPrr�rDr7r�)rr�rMs   r�get_addressrR�s���� �i�G�A� ��'���u��N�N�5���E�>����"�"�A�	A�&�u�-�L�E�5���&�&�	A��)�)�1�8�8��?�A�
A�	A���A�s'�0�B�A�B�8B�B�Bc�`�	t�}|r�	t|�\}}|j|�|re|ddk7r]|dd}d|_t|d�\}}|j|�|jjtjd��|r|jt�|dd}|r��||fS#tj$�rad}|dt
vr�t
|�\}}|r|ddk(r@|j|�|jjtjd��n�t|d�\}}|�|g|dd|jt|g��|jjtjd��n�|ddk(r/|jjtjd��n`t|d�\}}|�|g|dd|jt|g��|jjtjd��Y���wxYw)	Nrr�z"address-list entry with no contentzinvalid address in address-listzempty element in address-listr�r�r�)r�rRr�rr�rrr!rrGr�rpr^rKr2)r�address_listrMrr�s     r�get_address_listrU�s-����=�L�
�	8�&�u�-�L�E�5�����&�4�U�1�X��_�#�2�&�q�)�G�!2�G��.�u�c�:�L�E�5��N�N�5�!�� � �'�'��(B�(B�1�)3�
4�����
�.��!�"�I�E�Q�R�����K�&�&�	8��F��Q�x�;�&� (���
�����a��C�� �'�'��/� �(�(�/�/��0K�0K�<�1>�?�$7�u�c�#B�L�E�5��)�%+�H��b�q�	� �'�'����(8�9� �(�(�/�/��0J�0J�9�1;�<��q��S���$�$�+�+�F�,G�,G�3�-5�6� 3�5�#�>���u��%�!'��E�"�1�I��#�#�G�U�G�$4�5��$�$�+�+�F�,F�,F�5�-7�8��/	8�s�B8�8E1H-�,H-c���	t�}|s$tjdj|���|ddk7r$tjdj|���|j	tdd��|dd}t
|�\}}|j	|�|r|ddk7r$tjdj|���|j	tdd	��||ddfS)
Nz'expected no-fold-literal but found '{}'rr)z;expected '[' at the start of no-fold-literal but found '{}'zno-fold-literal-startr�r$z9expected ']' at the end of no-fold-literal but found '{}'zno-fold-literal-end)rrr�r7r�r�r")r�no_fold_literalrMs   r�get_no_fold_literalrX
s����#�o�O���%�%�5�<�<�U�C�E�	E��Q�x�3���%�%�
�#�V�E�]�,�	,����=��.E�F�G��!�"�I�E��U�#�L�E�5����5�!��E�!�H��O��%�%�
�#�V�E�]�,�	,����=��.C�D�E��E�!�"�I�%�%rc�H�	t�}|r*|dtvrt|�\}}|j|�|r|ddk7r$t	j
dj
|���|jtdd��|dd}	t|�\}}|j|�|r|ddk7r\|jjt	jd	��|r(|dd
k(r |jtd
d��|dd}||fS|jtdd��|dd}	t|�\}}|j|�|r|dd
k(r|dd}n.|jjt	jd��|jtd
d��|r*|dtvrt|�\}}|j|�||fS#tj
$r}	t|�\}}|jjt	jd��n;#tj
$r%t	j
dj
|���wxYwY���wxYw#tj
$r�	t|�\}}n�#tj
$r|	t|�\}}|jjt	jd
��n;#tj
$r%t	j
dj
|���wxYwYnwxYwY���wxYw)Nrr7zexpected msg-id but found '{}'zmsg-id-startr�zobsolete id-left in msg-idz4expected dot-atom-text or obs-id-left but found '{}'r(zmsg-id with no id-rightr8z
msg-id-endr.zobsolete id-right in msg-idzFexpected dot-atom-text, no-fold-literal or obs-id-right but found '{}'zmissing trailing '>' on msg-id)r�rrr�rr�r7r�r
rr!rrprXr,)r�msg_idrMs   r�
get_msg_idr[#s����
�W�F���q��[�(������u��
�
�e���E�!�H��O��%�%�,�3�3�E�:�<�	<�
�M�M�-��^�4�5��!�"�I�E�1�(��/���u��M�M�%���E�!�H��O������f�8�8�%�'�	(�
�U�1�X��_��M�M�-��\�:�;��!�"�I�E��u�}��
�M�M�-��%8�9�:��!�"�I�E�
5�(��/���u��M�M�%����q��S���a�b�	�������f�8�8�,�.�	/�
�M�M�-��\�2�3���q��[�(������u��
�
�e���5�=���a�"�"�	1�	1�-�e�4�L�E�5��N�N�!�!�&�"=�"=�,�#.�
/���&�&�	1��)�)�"�"(�&��-�1�
1�	1��
/�		1��4�"�"�5�
	5�.�u�5�L�E�5���&�&�	5�
5�)�%�0���u����%�%�f�&A�&A�1�'3�4���*�*�
5��-�-�&�&,�f�U�m�5�5�
5��4�	5��5�sx�G�-I(�I%�)<H&�%I%�&8I�I%�$I%�(L!�<J�
L!�L�<K�L�8L�L�L!�L�L!� L!c���	t�}	t|�\}}|j|�|r=|jjt	j
dj
|���|S#tj$r^}t|�}t|�}|jjt	j
dj
|���Yd}~|Sd}~wwxYw)NzUnexpected {!r}zInvalid msg-id: {!r})
r�r[r�r!rrpr7r�r�r�)r�
message_idrM�exs    r�parse_message_idr_hs������J�2�!�%�(���u����%� �����%�%�f�&@�&@�!�(�(��/�'1�
2�����"�"�K� ��'��%�e�,�
����!�!��&�&�'=�'D�'D�R�'H�I�	K�	K����K�s�A-�-C�AC�Cc�l�	t�}|s0|jjtjd��|S|dt
vrOt
|�\}}|j|�|s.|jjtjd��d}|r6|ddk7r.|dt
vr#||dz
}|dd}|r|ddk7r|dt
vr�#|j�sY|jjtjdj|���|jt|d��n+t|�|_|jt|d	��|r*|dt
vrt
|�\}}|j|�|r|ddk7rY|j�.|jjtjd
��|r|jt|d��|S|jtdd��|dd}|r*|dt
vrt
|�\}}|j|�|s<|j�.|jjtjd
��|Sd}|r&|dt
vr||dz
}|dd}|r|dt
vr�|j�sY|jjtjdj|���|jt|d��n+t|�|_
|jt|d	��|r*|dt
vrt
|�\}}|j|�|rI|jjtjd
��|jt|d��|S)Nz%Missing MIME version number (eg: 1.0)rz0Expected MIME version number but found only CFWSr'r	r�z1Expected MIME major version number but found {!r}r��digitsz0Incomplete MIME version; found only major numberzversion-separatorz1Expected MIME minor version number but found {!r}z'Excess non-CFWS text after MIME version)rHr!r�r�HeaderMissingRequiredValuerr�isdigitrpr7r��intrIrJ)r�mime_versionrMras    r�parse_mime_versionrf�su���
�=�L�����#�#�F�$E�$E�3�%5�	6����Q�x�;�������u����E�"��� � �'�'��(I�(I�B�)D�
E�
�F�
�E�!�H��O��a���(C��%��(����a�b�	���E�!�H��O��a���(C��>�>�����#�#�F�$>�$>�?�F�F�v�N�%P�	Q����M�&�'�:�;� ��[������M�&�(�;�<���q��[�(������u����E�"��E�!�H��O����)�� � �'�'��(B�(B�B�)D�
E�����
�e�W� =�>������
�c�+>�?�@��!�"�I�E���q��[�(������u����E�"�����)�� � �'�'��(B�(B�B�)D�
E���
�F�
�E�!�H�K�/��%��(����a�b�	���E�!�H�K�/��>�>�����#�#�F�$>�$>�?�F�F�v�N�%P�	Q����M�&�'�:�;� ��[������M�&�(�;�<���q��[�(������u����E�"�����#�#�F�$>�$>�5�%7�	8����M�%��9�:��rc���	t�}|ra|ddk7rY|dtvr$|jt|dd��|dd}nt	|�\}}|j|�|r	|ddk7r�Y||fS)NrrIrr�)rWrr�r�r)r�invalid_parameterrMs   r�get_invalid_parameterri�s����)�*��
�E�!�H��O���8�{�"��$�$�]�5��8�3F�&H�
I��!�"�I�E�%�e�,�L�E�5��$�$�U�+��E�!�H��O��e�#�#rc���	t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)Nzexpected ttext but found '{}'�ttext)�_non_token_end_matcherrr�r7r�r�r�r�)rr�rks   r�	get_ttextrm�sp���	�u�%�A���%�%�+�2�2�5�9�;�	;�
�G�G�I�E��#�e�*�+��E��%��)�E��E���%�<�rc�p�	t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���t|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS�Nrzexpected token but found '{}')	r�rrr��
TOKEN_ENDSrr�r7rm)r�mtokenrMs   r�	get_tokenrr�s�����W�F���q��[�(������u��
�
�e����q��Z�'��%�%�+�2�2�5�9�;�	;��U�#�L�E�5�
�M�M�%����q��[�(������u��
�
�e���5�=�rc���	t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)Nz expected attrtext but found {!r}r])�_non_attribute_end_matcherrr�r7r�r�r�r��rr�r]s   r�get_attrtextrv	sp���	#�5�)�A���%�%�.�5�5�e�<�>�	>��w�w�y�H��#�h�-�.�!�E��X�z�2�H��H���U�?�rc�p�	t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���t|�\}}|j|�|r*|dtvrt|�\}}|j|�||fSro)	rZrrr��ATTRIBUTE_ENDSrr�r7rv�rr[rMs   r�
get_attributerz	s������I���q��[�(������u��������q��^�+��%�%�+�2�2�5�9�;�	;���&�L�E�5�
���U����q��[�(������u�������e��rc���	t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)Nz)expected extended attrtext but found {!r}�extended-attrtext)�#_non_extended_attribute_end_matcherrr�r7r�r�r�r�rus   r�get_extended_attrtextr~.	ss���	,�E�2�A���%�%�7�>�>�u�E�G�	G��w�w�y�H��#�h�-�.�!�E��X�':�;�H��H���U�?�rc�p�	t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���t|�\}}|j|�|r*|dtvrt|�\}}|j|�||fSro)	rZrrr��EXTENDED_ATTRIBUTE_ENDSrr�r7r~rys   r�get_extended_attributer�@	s������I���q��[�(������u��������q��4�4��%�%�+�2�2�5�9�;�	;�(��/�L�E�5�
���U����q��[�(������u�������e��rc�n�	t�}|r|ddk7r$tjdj|���|j	tdd��|dd}|r|dj
�s$tjdj|���d}|r6|dj
�r#||dz
}|dd}|r|dj
�r�#|ddk(r3|dk7r.|jj	tjd	��t|�|_
|j	t|d
��||fS)Nr�*zExpected section but found {}zsection-markerr�z$Expected section number but found {}r'�0z'section number has an invalid leading 0ra)rarr�r7r�r�rcr!rprdrQ)rrbras   r�get_sectionr�V	s7����i�G��E�!�H��O��%�%�&E�&L�&L�(-�'/�0�	0��N�N�=��&6�7�8��!�"�I�E���a��(�(�*��%�%�'1�17����@�	@�
�F�
�E�!�H�$�$�&��%��(����a�b�	���E�!�H�$�$�&��a�y�C��F�c�M������v�9�9�9� ;�	<���[�G�N��N�N�=���2�3��E�>�rc�L�	t�}|stjd��d}|dtvrt	|�\}}|s$tjdj|���|ddk(rt
|�\}}nt|�\}}|�|g|dd|j|�||fS)Nz&Expected value but found end of stringrz Expected value but found only {}r)	rdrr�rrr7rr�r�)r�vrrMs    r�	get_valuer�t	s����	��A���%�%�&N�O�O�
�F��Q�x�;�� ���
�����%�%�'0�06��v��@�	@��Q�x�3��(��/���u�-�e�4���u�
���H��b�q�	��H�H�U�O��e�8�Orc�
�	t�}t|�\}}|j|�|r|ddk(rA|jjt	j
dj
|���||fS|ddk(rm	t|�\}}d|_|j|�|st	jd��|ddk(r'|jtdd��|dd}d|_|dd	k7rt	jd
��|jtd	d��|dd}|r*|dtvrt|�\}}|j|�d}|}|j�r|�r|ddk(r�t|�\}}|j}d
}|j dk(r(|r|ddk(rd}n/t#|�\}}|r|ddk(rd}n	t%|�\}}|sd}	|ra|jjt	j
d��|j|�|D]}	|	j&dk(s�g|	dd|	}n|}n0d}|jjt	j
d��|r|ddk(rd}nt)|�\}}|jr|j dkDrQ|r|ddk7r|j|�|�|}||fS|jjt	j
d��|sF|jjt	j
d��|j|�|��#||fS|�I|D]}	|	j&dk(s�n	j&dk(|j|	�|	j*|_|ddk7r$t	jdj
|���|jtdd��|dd}|rf|ddk7r^t#|�\}}|j|�|j*|_|r|ddk7r$t	jdj
|���|jtdd��|dd}|�et1�}
|rV|dt2vrt5|�\}}n(|ddk(rtdd�}|dd}nt7|�\}}|
j|�|r�V|
}nt)|�\}}|j|�|�|}||fS#tj$rY��WwxYw#Y��.xYw)NrrIz)Parameter contains name ({}) but no valuer�TzIncomplete parameterzextended-parameter-markerr��=zParameter not followed by '='�parameter-separatorrF�'z5Quoted string value for extended parameter is invalidr�zZParameter marked as extended but appears to have a quoted string value that is non-encodedzcApparent initial-extended-value but attribute was not marked as extended or was not initial sectionz(Missing required charset/lang delimitersr|r]z=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {}�DQUOTE)rLrzr�r!rrpr7r�rPr�r�rUrrrr�rRrvr~r^r�rr�r�rdr�r�r�)rr�rMr��appendto�qstring�inner_value�
semi_validr��tr�s           r�
get_parameterr��	s���
�K�E� ��'�L�E�5�	�L�L����E�!�H��O�
�
�
���V�7�7�9%�%+�V�E�]�4�	5��e�|���Q�x�3��	�&�u�-�L�E�5�"�E�O��L�L�����)�)�*@�A�A���8�s�?��L�L��s�,G�H�I��!�"�I�E�!�E�N��Q�x�3���%�%�&E�F�F�	�L�L��s�$9�:�;��!�"�I�E���q��[�(������u�
���U���I��H��~�~�%�E�!�H��O�/�u�5�����,�,���
����1�$��{�1�~��4�!�
�*�;�7���t��D��G�s�N�!%�J�
&�3�K�@���t��!%�J���M�M� � ��!;�!;�G�"I�
J��L�L��!����<�<�#7�7��A�a�D� �H��	�
 �E��I��M�M� � ��!;�!;�:�";�
<�
��q��S���� ��'���u��>�>�U�1�1�A�5���a��C���O�O�E�"��$�!���%�<��
�
�
���V�7�7�
D�E�	F��
�
�
���V�7�7�6�8�	9���������%�<�������<�<�#6�6���
�L�L�J�&��O�O�A���G�G�E�M���8�s�?��)�)�+F�FL�f�U�m�U�
U����
�c�+>�?�@��a�b�	���U�1�X��_�'��.�L�E�5��O�O�E�"����E�J��E�!�H��O��-�-�/<�<B�F�5�M�K�K����
�c�+>�?�@��a�b�	�����G����Q�x�3��&�u�~���u��q��S��%�c�8�4���a�b�	��+�E�2���u�
�H�H�U�O���� ��'���u��O�O�E�������%�<���i�&�&�	��	��D
��s�?&S&�T�&S=�<S=�Tc��	t�}|r�	t|�\}}|j|�|rp|ddk7rh|d}d|_t|�\}}|j|�|jjtjdj|���|r |jtdd��|d	d}|r��|S#tj$r�d}|dt
vrt
|�\}}|s|j|�|cYS|ddk(rB|�|j|�|jjtjd��ndt|�\}}|r|g|dd|j|�|jjtjdj|���Y���wxYw)
NrrIzparameter entry with no contentzinvalid parameter {!r}r�rXz)parameter with invalid trailing text {!r}r�r�)rgr�r�rr�rrr!rprir7r^rKr�)r�mime_parametersrMrr�s     r�parse_mime_parametersr�
s����%�&�O�
�	=�(��/�L�E�5��"�"�5�)�(�U�1�X��_�$�B�'�E�2�E��0��7�L�E�5��L�L����#�#�*�*�6�+E�+E�;�B�B�5�I�,K�
L���"�"�=��6K�#L�M��!�"�I�E�G�H���A�&�&�	=��F��Q�x�;�&� (���
�����&�&�v�.�&�&��Q�x�3���%�#�*�*�6�2��'�'�.�.�v�/I�/I�5�07�8� 5�U�;���u��!'��E�"�1�I��&�&�u�-��'�'�.�.�v�/I�/I�,�3�3�E�:�0<�=��#	=�s�C�AF>�B.F>�=F>c�B�	|ra|ddk7rY|dtvr$|jt|dd��|dd}nt|�\}}|j|�|r	|ddk7r�Y|sy|jtdd��|jt	|dd��y)NrrIrr�r�)rr�r�rr�)�	tokenlistrrMs   r�_find_mime_parametersr�K
s�����E�!�H��O���8�{�"����]�5��8�5H�I�J��!�"�I�E�%�e�,�L�E�5����U�#�
�E�!�H��O���
���]�3�(=�>�?�
���*�5���9�5�6rc�:�	t�}|s0|jjtjd��|S	t|�\}}|j|�|r|ddk7r>|jjtjd��|rt||�|S|jj�j�|_
|jtdd��|dd}	t|�\}}|j|�|jj�j�|_|s|S|dd	k7rO|jjtjd
j|���|`
|`t||�|S|jtd	d��|jt!|dd��|S#tj$rN|jjtjdj|���t||�|cYSwxYw#tj$rN|jjtjdj|���t||�|cYSwxYw)Nz"Missing content type specificationz(Expected content maintype but found {!r}rr�zInvalid content typezcontent-type-separatorr�z'Expected content subtype but found {!r}rIz<Only parameters are valid after content type, but found {!r}r�)r�r!r�rrbrrr�rpr7r�rrm�lowerr�r�r�r�)r�ctyperMs   r�parse_content_type_headerr�[
sM���
�M�E��
�
�
���V�>�>�0�2�	3���� ��'���u�
�L�L����E�!�H��O�
�
�
���V�7�7�"�$�	%��!�%��/����[�[�&�&�(�.�.�0�E�N�	�L�L��s�$<�=�>��!�"�I�E�� ��'���u�
�L�L����K�K�%�%�'�-�-�/�E�M�����Q�x�3��
�
�
���V�7�7�
�����(�	)�
�N�E�M��e�U�+���	�L�L��s�$9�:�;�	�L�L�&�u�Q�R�y�1�2��L��Q�"�"��
�
�
���V�7�7�6�=�=�e�D�F�	G��e�U�+���	��&�"�"��
�
�
���V�7�7�5�<�<�U�C�E�	F��e�U�+���	�s%�G�4H9�AH6�5H6�9AJ�Jc��	t�}|s0|jjtjd��|S	t|�\}}|j|�|jj�j�|_
|s|S|ddk7rK|jjtjdj|���t||�|S|jtdd��|jt|dd��|S#tj$rN|jjtjdj|���t||�|cYSwxYw)NzMissing content dispositionz+Expected content disposition but found {!r}rrIzCOnly parameters are valid after content disposition, but found {!r}r�r�)r�r!r�rrbrrr�rpr7r�rrmr�r�r�r�)r�disp_headerrMs   r� parse_content_disposition_headerr��
sb���%�&�K�����"�"�6�#D�#D�)�$+�	,���� ��'���u����u��&+�k�k�&7�&7�&9�&?�&?�&A�K�#�����Q�x�3�����"�"�6�#=�#=�
�����$(�	)�	�k�5�1������}�S�*?�@�A����,�U�1�2�Y�7�8����#�"�"�����"�"�6�#=�#=�9�@�@��G�$I�	J��k�5�1���	�s�D�AE=�<E=c���	t�}|s0|jjtjd��|S	t|�\}}|j|�|jj�j�|_	|s|S|r|jjtjd��|dtvr$|jt|dd��|dd}nt|�\}}|j|�|r�|S#tj$r@|jjtjdj|���Y��wxYw)Nz!Missing content transfer encodingz1Expected content transfer encoding but found {!r}z*Extra text after content transfer encodingrrr�)r�r!r�rrbrrrrmr�r�r�rpr7rr�r)r�
cte_headerrMs   r�&parse_content_transfer_encoding_headerr��
sR���)�*�J�����!�!�&�"C�"C�/�#1�	2���5� ��'���u�
	���%� ����*�*�,�2�2�4�
�����
����!�!�&�"<�"<�8�#:�	;���8�{�"����m�E�!�H�6I�J�K��!�"�I�E�%�e�,�L�E�5����e�$�����#�"�"�P����!�!�&�"<�"<�?�F�F�u�M�#O�	P�P�s�D�AE%�$E%c�Z�d}|r&|dr!|ddtvr|dd}|ddd|d<|S)Nr'r�)r�)�lines�wsps  r�_steal_trailing_WSP_if_existsr��
sD��
�C���r��u�R�y��}��3��B�i��m���"�I�c�r�N��b�	��Jrc	��	|jxstj}|jrdnd}dg}d}d}d}d}d}	t	dd�}
t|�}|�rL|j
d�}||
ur|dz}�t|�}
|	s;|jdvrtj|
�}	ntj|
�}		|
j|�|}|jdk(rt!||||���|	�r|�s|j"s�d}	d}|j$r|j'|�
�dt)|j*�}|j*|vrHt)|�|t)|d�z
kDrt-|�}|j/|�|dxx|z
cc<��9t1|d�st|�|z}d}	��W|j"r;|�||k7r|d
k(s
|dk(r|dk7rd}t3|
||||j4||�}d}|}d}	���d}d}	t)|
�|t)|d�z
kr|dxx|
z
cc<���d}|j$r~t)|
�dz|krmt-|�}|s|j7�rP|j/||
z�g}|dD]}|t8vrn|j/|��dj;|�}d}��Zt1|d�s�t|�}|jdk(r?t=dd�g|D�cgc]}t=t?|�d���c}zt=dd�gz}|j"s|dz
}|j/|
�||z}���|j"r|s|jAd|�d}	��t-|�}|s|j7�r|j/||
z�n
|dxx|
z
cc<|r��L|j*j;|�|j*zS#t$r'td	�|jD��rd
}nd}d}	Y��,wxYwcc}w)N�utf-8rNr'rF�wrap_as_ew_blockedr�)rEr�c3�PK�|]}t|tj���� y�wr)r3rrxr*s  rr-z%_refold_parse_tree.<locals>.<genexpr>
s%����.�,�q��a��!>�!>�?�,�rB�unknown-8bitTrhrOr�rr�rrE)!�max_line_length�sys�maxsize�utf8r�r�r2rr^�
SPECIALSNL�
isdisjoint�NLSETrrvrCr?�_fold_mime_parametersrGrdrSr�r�r�r�r_�_fold_as_ewrerDr�r1r�r�insert)�
parse_treerP�maxlenrlr��leading_whitespace�last_ew�last_charsetr��
want_encoding�end_ew_not_allowedr|rH�tstrr��encoded_part�newline�whitespace_accumulator�char�newparts�ps                     rrQrQ�
sX����
#�
#�
2�s�{�{�F� �+�+�w�:�H�
�D�E����G��L����M�!�"�&:�;�����E�
��y�y��|���%�%��!�#����4�y������"4�4�$.�$9�$9�$�$?� ?�
�%*�$4�$4�T�$:� :�
�	!��K�K��!��G��?�?�/�/�!�$��v�x�@���!3��%�%� %�
����'�'�#'�9�9�F�9�#;�<Q�c�&�.�.�>Q�=Q�#R�L��~�~�\�9��|�,�v��E�"�I��/F�F�&C�E�&J�G�!�L�L��1��b�	�\�1�	� �
�4��*��T�
�U�*�� %�
���#�#��'��|�+�!�^�3�!�W�,��J�1F�"�G�%�d�E�6�7�&*�&=�&=�w�HZ�\��&(�"�&�� %�
���� %�
��t�9���U�2�Y��/�/��"�I���I��
 ��� � ��D�	�A�
��'�3�E�:�G��$�-�-�/�
���W�t�^�,�)+�&�!�"�I�D��3���*�1�1�$�7�&�&(�W�W�-C�%D�"�����t�X�&��D�z�H����"6�6�
#�3��0�1�&�(�&��#�#4�Q�#7��A�&�(�(�#�3��0�1�2��
�%�%�"�a�'�"���� 2�3��u�$�E�����&8�
�L�L��D�!� �M��/��6���d�)�)�+��L�L��4��(�
�"�I���I�K�N�>�>���u�%����6�6��o"�	!��.� �,�,�.�.�(��"�� �M�	!��B(s�;O�$O>�,O;�:O;c� �	|�+|r)tt|d|d|z��}|dd||d<nM|dtvrB|d}|dd}t|d�|k(r|j	t|��|dxx|z
cc<d}|dtvr
|d}|dd}|�t|d�n|}	|dk(rdn|}
t|
�dz}|dz|k\rt
jd��|�r!|t|d�z
}||z
t|�z
}
|
dkr|j	d	��<t|�dkDr9t|d�dk(r(|r&tj||
�
�}|dxx|z
cc<d}|d|
}tj||
�
�}t|�|z
}|dkDr0|dd}tj||
�
�}t|�|z
}|dkDr�0|dxx|z
cc<|t|�d}d}|r|j	d	�t|d�}	|r��!|dxx|z
cc<|r|	SdS)Nr�rr�r'rNr��z3max_line_length is too small to fit an encoded wordrm)r�)
rr�r�r�r�r�rr�r�r)�	to_encoder�r�r�rer�r��leading_wsp�trailing_wsp�new_last_ew�	encode_as�
chrome_len�remaining_space�
text_space�encoded_word�to_encode_word�excesss                 rr�r��si��	���1���U�2�Y�w�x�0�9�<�=�?�	��"�I�h�w�'��b�	�	�1���	� ��l���a�b�M�	���b�	�N�f�$��L�L�6�u�=�>�
�b�	�[� �	��L���}��� ��}���c�r�N�	�$+�O�#�e�B�i�.��K�"�j�0��g�I��Y��!�#�J��Q��6�!��%�%�A�C�	C�� �3�u�R�y�>�1��$�z�1�C�8J�4K�K�
���?��L�L�����u�:��>�c�%��)�n��1�6H��:�:�&8�)�L�L��"�I��%�I�!#��"�;�J�/���z�z�.�)�D���\�"�_�4���q�j�,�C�R�0�N��:�:�n�i�H�L���&��8�F��q�j�	�b�	�\�!�	��c�.�1�2�3�	�����L�L����e�B�i�.�K�?�@
�"�I���I�,�;�6�$�6rc	��	|jD�]�\}}|dj�jd�s
|dxxdz
cc<|}d}	|j|�d}|r6tjj|d	|�
�}	dj|||	�}
ndj|t|��}
t|d�t|
�zd
z|kr|ddz|
z|d<��t|
�dz|kr|jd|
z���d}|dz}|s��t|�tt|��zdzt|�z}
||
dzkrd}||
z
dz
x}}	|d|}tjj|d	|�
�}	t|	�|krn|d
z}�<|jdj||||	��d	}|d
z
}||d}|r
|dxxdz
cc<|r�����y#t$r"d}tj|�rd}d}nd}Y���wxYw)Nr�rI�strictFTr�rkr�r')�saferz
{}*={}''{}r�r�rmr�rz''r#�Nz {}*{}*={}{})rzr%r^rrvrrwrqrrr�r7rr�r�r)rHr�r�rlr{rr��
error_handler�encoding_required�
encoded_valuer�rb�extra_chromer��
splitpoint�maxchars�partials                 rr�r��sF����{�{���e��R�y���!�*�*�3�/��"�I���I��� �
�		"��L�L��"� %���"�L�L�.�.��B�}�/�6�M��&�&�t�W�m�D�D��>�>�$��U�(;�<�D��u�R�y�>�C��I�%��)�F�2��b�	�C��$�.�E�"�I��
��Y��]�f�
$��L�L��t��$������~����T��S��W��%6�6��:�S��=N�N�J���a��'�
��$*�Z�$7�!�$;�;�J������,�� &��� 2� 2��"�]�!3�!<�
��}�%��1���a��
�
�
�L�L��.�.��g�|�]�<�
=��L��q�L�G��*�+�&�E���b�	�S� �	�-�I#��"�	"� $���$�$�U�+�(�� 1�
�!���
	"�s�	G�'G?�>G?)r�)��rer�rq�stringr�operatorr�emailrr�rrr)r�rrrr*r�	TSPECIALSrp�	ASPECIALSrxr�r�r�rr�compile�VERBOSE�	MULTILINEr�r�rrjrvrzr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr
rrrrr r.r0r8rBrHrLrWrZrardrgr�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r<r2rGrdr3r7r1rr�r��matchr��findallr�rlrtr}r�r�r�r�r�r�r�r�r�r�rrrr
r
rrrrr"r'r*r,r/r5r:r<r?rDrGrKrNrPrRrUrXr[r_rfrirmrrrvrzr~r�r�r�r�r�r�r�r�r�r�rQr�r�rnrr�<module>r�s5��C�J
�
�
���'���
�%�j���C��H�n���� ���s�N�	��C��H�$�
���U��#��
��E�
�
"�c�#�h�.�	�
��_�
���E�
�"�	��S���(�3�s�8�3��	
�t���
��
�
�@�
��"�*�*���Z�Z�"�,�,�� ��@,��@,�FD�)�D� �I� ��Y���9���"���9���I��
�)��#�9�#�6	-�|�	-��!��4C�)�C�&%�i�%�2?�)�?�%�	�%�"$�I�$�*"�y�"�6�	��DD�y�D�!�i�!�6;�Y�;�.�Y�.��i���)��
�I��
�y��B�9��-!�&�-!�`!�	�!�H
�I�
� �)���	��8%�y�%�
#�	�#��i���I��S.�Y�S.�l�y���*���1���i���)��
*�I�*����&�y�&��Y��(+�s�(+�V����H���-��<�f�-�-�<��C�����c�#3�4�
�#�
�� %�
��$�S�*B�C��.��
�
�:�,�,�R�W�W�S�\�:�;�A�A�
�"��
�
�9�#3�#3�
�B�I�I�b�g�g�i� �!�$#�$�$)�E��"��
�
�#5�6�>�>��#����I�$4�$4�
�B�I�I�b�g�g�j�!�"�%$�%�%*�U��'�R�Z�Z�	�(8�(8�
�B�I�I�b�g�g�n�%�&�)(�)�).���&0�b�j�j��1A�1A�
�B�I�I�b�g�g�-�.�/�21�'2�27�%�$�;�J�<
�/�bA�F�"
�� ))�V�2� �$�6 �&�2 �D$�L%�N2!�h�(�%!�N$�L� ) �V,�\�"�H�*"�$6�r#�J�<�:4�n&�,B�J�8B�H$�$�&�.�&�.�$�,�<�,K�Z2�h7� 6�p�<�^�Y7�vJ7�XI!r__pycache__/_header_value_parser.cpython-312.pyc000064400000404061151706203560015630 0ustar00�

T��h��	��
�dZddlZddlZddlZddlmZddlmZddlm	Z
ddlmZddlmZe
d�Zee
d	�zZe
d
�ZeezZee
d�z
Zee
d�z
Zee
d
�ze
d�z
ZeezZee
d�zZeezZee
d�z
ZddhZeezZd�Zd�Zej:dej<ej>z�Z Gd�de!�Z"Gd�de"�Z#Gd�de"�Z$Gd�de"�Z%Gd�de"�Z&Gd�d e#�Z'Gd!�d"e"�Z(Gd#�d$e"�Z)Gd%�d&e"�Z*Gd'�d(e"�Z+Gd)�d*e+�Z,Gd+�d,e#�Z-Gd-�d.e"�Z.Gd/�d0e"�Z/Gd1�d2e"�Z0Gd3�d4e"�Z1Gd5�d6e"�Z2Gd7�d8e"�Z3Gd9�d:e"�Z4Gd;�d<e"�Z5Gd=�d>e"�Z6Gd?�d@e"�Z7GdA�dBe"�Z8GdC�dDe"�Z9GdE�dFe"�Z:GdG�dHe"�Z;GdI�dJe"�Z<GdK�dLe"�Z=GdM�dNe%�Z>GdO�dPe"�Z?GdQ�dRe"�Z@GdS�dTe"�ZAGdU�dVe"�ZBGdW�dXeB�ZCGdY�dZe"�ZDGd[�d\e"�ZEGd]�d^e"�ZFGd_�d`e"�ZGGda�dbe"�ZHGdc�ddeH�ZIGde�dfeH�ZJGdg�dhe"�ZKGdi�dje"�ZLGdk�dle"�ZMGdm�dneM�ZNGdo�dpeN�ZOGdq�dre"�ZPGds�dteQ�ZRGdu�dveR�ZSGdw�dxeR�ZTGdy�dzeS�ZUGd{�d|ej��ZWeTdd}�ZXeTd~d�ZYd�eY_Zd�eY_[eTd�d��Z\ej:d�j�d�j�e���j�Z`ej:d�j�ej�d�j�e����j�Zcej:d��j�Zeej:d�j�ej�d�j�e����j�Zfej:d�j�ej�d�j�e����j�Zgej:d�j�ej�d�j�e����j�Zhd��Zid��Zjd��Zkd�d��Zld��Zmd��Znd��Zod��Zpd��Zqd��Zrd��Zsd��Ztd��Zud��Zvd��Zwd��Zxd��Zyd��Zzd��Z{d��Z|d��Z}d��Z~d��Zd��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�y)�alHeader value parser implementing various email-related RFC parsing rules.

The parsing methods defined in this module implement various email related
parsing rules.  Principal among them is RFC 5322, which is the followon
to RFC 2822 and primarily a clarification of the former.  It also implements
RFC 2047 encoded word decoding.

RFC 5322 goes to considerable trouble to maintain backward compatibility with
RFC 822 in the parse phase, while cleaning up the structure on the generation
phase.  This parser supports correct RFC 5322 generation by tagging white space
as folding white space only when folding is allowed in the non-obsolete rule
sets.  Actually, the parser is even more generous when accepting input than RFC
5322 mandates, following the spirit of Postel's Law, which RFC 5322 encourages.
Where possible deviations from the standard are annotated on the 'defects'
attribute of tokens that deviate.

The general structure of the parser follows RFC 5322, and uses its terminology
where there is a direct correspondence.  Where the implementation requires a
somewhat different structure than that used by the formal grammar, new terms
that mimic the closest existing terms are used.  Thus, it really helps to have
a copy of RFC 5322 handy when studying this code.

Input to the parser is a string that has already been unfolded according to
RFC 5322 rules.  According to the RFC this unfolding is the very first step, and
this parser leaves the unfolding step to a higher level message parser, which
will have already detected the line breaks that need unfolding while
determining the beginning and end of each header.

The output of the parser is a TokenList object, which is a list subclass.  A
TokenList is a recursive data structure.  The terminal nodes of the structure
are Terminal objects, which are subclasses of str.  These do not correspond
directly to terminal objects in the formal grammar, but are instead more
practical higher level combinations of true terminals.

All TokenList and Terminal objects have a 'value' attribute, which produces the
semantically meaningful value of that part of the parse subtree.  The value of
all whitespace tokens (no matter how many sub-tokens they may contain) is a
single space, as per the RFC rules.  This includes 'CFWS', which is herein
included in the general class of whitespace tokens.  There is one exception to
the rule that whitespace tokens are collapsed into single spaces in values: in
the value of a 'bare-quoted-string' (a quoted-string with no leading or
trailing whitespace), any whitespace that appeared between the quotation marks
is preserved in the returned value.  Note that in all Terminal strings quoted
pairs are turned into their unquoted values.

All TokenList and Terminal objects also have a string value, which attempts to
be a "canonical" representation of the RFC-compliant form of the substring that
produced the parsed subtree, including minimal use of quoted pair quoting.
Whitespace runs are not collapsed.

Comment tokens also have a 'content' attribute providing the string found
between the parens (including any nested comments) with whitespace preserved.

All TokenList and Terminal objects have a 'defects' attribute which is a
possibly empty list all of the defects found while creating the token.  Defects
may appear on any token in the tree, and a composite list of all defects in the
subtree is available through the 'all_defects' attribute of any node.  (For
Terminal notes x.defects == x.all_defects.)

Each object in a parse tree is called a 'token', and each has a 'token_type'
attribute that gives the name from the RFC 5322 grammar that it represents.
Not all RFC 5322 nodes are produced, and there is one non-RFC 5322 node that
may be produced: 'ptext'.  A 'ptext' is a string of printable ascii characters.
It is returned in place of lists of (ctext/quoted-pair) and
(qtext/quoted-pair).

XXX: provide complete list of token types.
�N)�	hexdigits)�
itemgetter)�_encoded_words)�errors)�utilsz 	�(z
()<>@,:;.\"[]�.z."(z/?=z*'%�%�
�
c�X�t|�jdd�jdd�S)z;Escape dquote and backslash for use within a quoted-string.�\�\\�"z\")�str�replace��values �3/usr/lib64/python3.12/email/_header_value_parser.py�make_quoted_pairsrcs&���u�:���d�F�+�3�3�C��?�?�c�$�t|�}d|�d�S)Nr)r)r�escapeds  r�quote_stringrhs����&�G�
�w�i�q�>�rz�
   =\?            # literal =?
   [^?]*          # charset
   \?             # literal ?
   [qQbB]         # literal 'q' or 'b', case insensitive
   \?             # literal ?
  .*?             # encoded word
  \?=             # literal ?=
c���eZdZdZdZdZ�fd�Zd�Z�fd�Ze	d��Z
e	d��Zd�Ze	d	��Z
e	d
��Zd�Zdd�Zdd
�Zdd�Z�xZS)�	TokenListNTc�2��t�|�|i|��g|_y�N)�super�__init__�defects)�self�args�kw�	__class__s   �rr zTokenList.__init__�s���
���$�%�"�%���rc�2�djd�|D��S)N�c3�2K�|]}t|����y�wr�r��.0�xs  r�	<genexpr>z$TokenList.__str__.<locals>.<genexpr>������,�t�!�s�1�v�t�����join�r"s r�__str__zTokenList.__str__�s���w�w�,�t�,�,�,rc�h��dj|jjt�|���S�Nz{}({})��formatr%�__name__r�__repr__�r"r%s �rr9zTokenList.__repr__�s+������t�~�~�6�6�"�W�-�/�1�	1rc�2�djd�|D��S)Nr'c3�NK�|]}|js�|j���y�wrrr*s  rr-z"TokenList.value.<locals>.<genexpr>�s����8��1����q�w�w��s�%�%r0r2s rrzTokenList.value�s���w�w�8��8�8�8rc�<�td�|D�|j�S)Nc3�4K�|]}|j���y�wr)�all_defectsr*s  rr-z(TokenList.all_defects.<locals>.<genexpr>�s����0�4�a�A�M�M�4���)�sumr!r2s rr?zTokenList.all_defects�s���0�4�0�$�,�,�?�?rc�(�|dj�S�Nr)�startswith_fwsr2s rrDzTokenList.startswith_fws�s���A�w�%�%�'�'rc�&�td�|D��S)zATrue if all top level tokens of this part may be RFC2047 encoded.c3�4K�|]}|j���y�wr)�
as_ew_allowed)r+�parts  rr-z*TokenList.as_ew_allowed.<locals>.<genexpr>�s����7�$�$�4�%�%�$�r@)�allr2s rrGzTokenList.as_ew_allowed�s���7�$�7�7�7rc�N�g}|D]}|j|j��|Sr)�extend�comments)r"rL�tokens   rrLzTokenList.comments�s&�����E��O�O�E�N�N�+���rc��t||��S)N��policy)�_refold_parse_tree�r"rPs  r�foldzTokenList.fold�s��!�$�v�6�6rc�:�t|j|���y)N��indent)�print�ppstr�r"rVs  r�pprintzTokenList.pprint�s��
�d�j�j��j�'�(rc�D�dj|j|���S)NrrU)r1�_pprYs  rrXzTokenList.ppstr�s���y�y������0�1�1rc#�~K�dj||jj|j���|D]A}t	|d�s|dj|�z���&|j|dz�Ed{����C|jrdj|j�}nd}dj||���y7�E�w)Nz{}{}/{}(r\z*    !! invalid element in token list: {!r}z    z Defects: {}r'z{}){})r7r%r8�
token_type�hasattrr\r!)r"rVrM�extras    rr\z
TokenList._pp�s����������N�N�#�#��O�O��	��E��5�%�(��!5�5;�V�E�]�C�D�!�9�9�V�F�]�3�3�3���<�<�"�)�)�$�,�,�7�E��E��n�n�V�U�+�+�4�s�A3B=�5B;�6AB=�r')r8�
__module__�__qualname__r^�syntactic_break�ew_combine_allowedr r3r9�propertyrr?rDrGrLrSrZrXr\�
__classcell__�r%s@rrr}s�����J��O����-�1��9��9��@��@�(��8��8�����7�)�2�,rrc�,�eZdZed��Zed��Zy)�WhiteSpaceTokenListc��y�N� �r2s rrzWhiteSpaceTokenList.value����rc�`�|D�cgc]}|jdk(s�|j�� c}Scc}w)N�comment)r^�content�r"r,s  rrLzWhiteSpaceTokenList.comments�s)��#'�C�4�a�1�<�<��+B��	�	�4�C�C��C��+�+N)r8rbrcrfrrLrnrrrjrj�s*��
�����D��Drrjc��eZdZdZy)�UnstructuredTokenList�unstructuredN�r8rbrcr^rnrrrvrv�s���Jrrvc��eZdZdZy)�Phrase�phraseNrxrnrrrzrz�����Jrrzc��eZdZdZy)�Word�wordNrxrnrrr~r~�����Jrr~c��eZdZdZy)�CFWSList�cfwsNrxrnrrr�r��r�rr�c��eZdZdZy)�Atom�atomNrxrnrrr�r��r�rr�c��eZdZdZdZy)�TokenrMFN)r8rbrcr^�encode_as_ewrnrrr�r��s���J��Lrr�c��eZdZdZdZdZdZy)�EncodedWord�encoded-wordN)r8rbrcr^�cte�charset�langrnrrr�r��s���J�
�C��G��Drr�c�@�eZdZdZed��Zed��Zed��Zy)�QuotedString�
quoted-stringc�L�|D]}|jdk(s�|jcSy�N�bare-quoted-string�r^rrss  rrrzQuotedString.content�s"���A��|�|�3�3��w�w��rc��g}|D]G}|jdk(r|jt|���-|j|j��Idj	|�S)Nr�r')r^�appendrrr1)r"�resr,s   r�quoted_valuezQuotedString.quoted_value�sN�����A��|�|�3�3��
�
�3�q�6�"��
�
�1�7�7�#�	�
�w�w�s�|�rc�L�|D]}|jdk(s�|jcSyr�r��r"rMs  r�stripped_valuezQuotedString.stripped_value�s%���E����#7�7��{�{�"�rN)r8rbrcr^rfrrr�r�rnrrr�r��sA�� �J�
����
�����#��#rr�c�&�eZdZdZd�Zed��Zy)�BareQuotedStringr�c�D�tdjd�|D���S)Nr'c3�2K�|]}t|����y�wrr)r*s  rr-z+BareQuotedString.__str__.<locals>.<genexpr>
s����#9�D�q�C��F�D�r/)rr1r2s rr3zBareQuotedString.__str__	s���B�G�G�#9�D�#9�9�:�:rc�2�djd�|D��S)Nr'c3�2K�|]}t|����y�wrr)r*s  rr-z)BareQuotedString.value.<locals>.<genexpr>r.r/r0r2s rrzBareQuotedString.value����w�w�,�t�,�,�,rN)r8rbrcr^r3rfrrnrrr�r�s ��%�J�;��-��-rr�c�<�eZdZdZd�Zd�Zed��Zed��Zy)�Commentrqc��djtdg|D�cgc]}|j|���c}dggg��Scc}w)Nr'r�))r1rA�quoterss  rr3zComment.__str__sK���w�w�s� �E�48�9�D�q�T�Z�Z��]�D�9� �E�� "�	#�$�	$��9s�>c��|jdk(rt|�St|�jdd�jdd�jdd�S)Nrqrrrz\(r�z\))r^rr)r"rs  rr�z
Comment.quotesR�����y�(��u�:���5�z�!�!�$��/�7�7�"%�u�.�.5�g�"%�u�/.�	.rc�2�djd�|D��S)Nr'c3�2K�|]}t|����y�wrr)r*s  rr-z"Comment.content.<locals>.<genexpr>%r.r/r0r2s rrrzComment.content#r�rc��|jgSr)rrr2s rrLzComment.comments's�����~�rN)	r8rbrcr^r3r�rfrrrLrnrrr�r�s9���J�$�.��-��-����rr�c�@�eZdZdZed��Zed��Zed��Zy)�AddressListzaddress-listc�L�|D�cgc]}|jdk(s�|��c}Scc}w)N�address�r^rss  r�	addresseszAddressList.addresses/�%���;�4�a�1�<�<��#:��4�;�;��;��!�!c�(�td�|D�g�S)Nc3�RK�|]}|jdk(r|j���!y�w�r�N�r^�	mailboxesr*s  rr-z(AddressList.mailboxes.<locals>.<genexpr>5s'����>�!��Q�\�\�9�%<��K�K�!���%'�rAr2s rr�zAddressList.mailboxes3�!���>�!�>�?A�C�	Crc�(�td�|D�g�S)Nc3�RK�|]}|jdk(r|j���!y�wr��r^�
all_mailboxesr*s  rr-z,AddressList.all_mailboxes.<locals>.<genexpr>:s'����>�!��Q�\�\�9�%<��O�O�!�r�r�r2s rr�zAddressList.all_mailboxes8r�rN)r8rbrcr^rfr�r�r�rnrrr�r�+sE���J�
�<��<��C��C��C��Crr�c�@�eZdZdZed��Zed��Zed��Zy)�Addressr�c�F�|djdk(r|djSy)Nr�group�r^�display_namer2s rr�zAddress.display_nameBs)����7����(���7�'�'�'�)rc�x�|djdk(r|dgS|djdk(rgS|djS�Nr�mailbox�invalid-mailboxr�r2s rr�zAddress.mailboxesGsH����7����*���G�9��
�!�W�
�
�#4�
4��I��A�w� � � rc��|djdk(r|dgS|djdk(r|dgS|djSr�r�r2s rr�zAddress.all_mailboxesOsO����7����*���G�9��
�!�W�
�
�#4�
4���G�9���A�w�$�$�$rN)r8rbrcr^rfr�r�r�rnrrr�r�>sA���J�
�(��(��!��!��%��%rr�c�0�eZdZdZed��Zed��Zy)�MailboxList�mailbox-listc�L�|D�cgc]}|jdk(s�|��c}Scc}w)Nr�r�rss  rr�zMailboxList.mailboxes[r�r�c�H�|D�cgc]}|jdvr|��c}Scc}w)N)r�r�r�rss  rr�zMailboxList.all_mailboxes_s2���?�4�a��|�|�=�=��4�?�	?��?s�N�r8rbrcr^rfr�r�rnrrr�r�Ws-���J�
�<��<��?��?rr�c�0�eZdZdZed��Zed��Zy)�	GroupList�
group-listc�L�|r|djdk7rgS|djS�Nrr�r�r2s rr�zGroupList.mailboxesis+���t�A�w�)�)�^�;��I��A�w� � � rc�L�|r|djdk7rgS|djSr�r�r2s rr�zGroupList.all_mailboxesos+���t�A�w�)�)�^�;��I��A�w�$�$�$rNr�rnrrr�r�es-���J�
�!��!�
�%��%rr�c�@�eZdZdZed��Zed��Zed��Zy)�Groupr�c�H�|djdk7rgS|djS�N�r�r�r2s rr�zGroup.mailboxeszs)����7����-��I��A�w� � � rc�H�|djdk7rgS|djSr�r�r2s rr�zGroup.all_mailboxes�s)����7����-��I��A�w�$�$�$rc� �|djSrC)r�r2s rr�zGroup.display_name�s���A�w�#�#�#rN)r8rbrcr^rfr�r�r�rnrrr�r�vsA���J�
�!��!�
�%��%�
�$��$rr�c�`�eZdZdZed��Zed��Zed��Zed��Zed��Z	y)�NameAddr�	name-addrc�>�t|�dk(ry|djS�N�r)�lenr�r2s rr�zNameAddr.display_name�s ���t�9��>���A�w�#�#�#rc� �|djS�N�����
local_partr2s rr�zNameAddr.local_part�s���B�x�"�"�"rc� �|djSr���domainr2s rr�zNameAddr.domain�s���B�x���rc� �|djSr�)�router2s rr�zNameAddr.route�s���B�x�~�~�rc� �|djSr���	addr_specr2s rr�zNameAddr.addr_spec�s���B�x�!�!�!rN�
r8rbrcr^rfr�r�r�r�r�rnrrr�r��si���J�
�$��$�
�#��#����������"��"rr�c�P�eZdZdZed��Zed��Zed��Zed��Zy)�	AngleAddrz
angle-addrc�L�|D]}|jdk(s�|jcSy�N�	addr-spec)r^r�rss  rr�zAngleAddr.local_part�s"���A��|�|�{�*��|�|�#�rc�L�|D]}|jdk(s�|jcSyr��r^r�rss  rr�zAngleAddr.domain�s!���A��|�|�{�*��x�x��rc�L�|D]}|jdk(s�|jcSy)N�	obs-route)r^�domainsrss  rr�zAngleAddr.route�s"���A��|�|�{�*��y�y� �rc��|D]O}|jdk(s�|jr|jcSt|j�|jzcSy)Nr�z<>)r^r�r�rrss  rr�zAngleAddr.addr_spec�sF���A��|�|�{�*��<�<��;�;�&�'����5����C�C��rN)	r8rbrcr^rfr�r�r�r�rnrrr�r��sU���J�
�$��$�
� �� �
�!��!�
���rr�c� �eZdZdZed��Zy)�ObsRouter�c�`�|D�cgc]}|jdk(s�|j�� c}Scc}w)Nr�r�rss  rr�zObsRoute.domains�s)��"&�C�$�Q�!�,�,�(�*B����$�C�C��CrtN)r8rbrcr^rfr�rnrrrr�s���J�
�D��Drrc�`�eZdZdZed��Zed��Zed��Zed��Zed��Z	y)�Mailboxr�c�F�|djdk(r|djSy�Nrr�r�r2s rr�zMailbox.display_name�s)����7����,���7�'�'�'�-rc� �|djSrCr�r2s rr�zMailbox.local_part�����A�w�!�!�!rc� �|djSrCr�r2s rr�zMailbox.domain�s���A�w�~�~�rc�F�|djdk(r|djSyr)r^r�r2s rr�z
Mailbox.route�s'����7����,���7�=�=� �-rc� �|djSrCr�r2s rr�zMailbox.addr_spec�s���A�w� � � rNr�rnrrrr�si���J�
�(��(��"��"������!��!��!��!rrc�0�eZdZdZed��ZexZxZxZZ	y)�InvalidMailboxr�c��yrrnr2s rr�zInvalidMailbox.display_name����rNr�rnrrr
r
�s/��"�J�
����/;�:�J�:��:�%�)rr
c�0��eZdZdZdZe�fd��Z�xZS)�Domainr�Fc�R��djt�|�j��S�Nr'�r1rr�splitr:s �rr�z
Domain.domain������w�w�u�w�}�*�*�,�-�-r)r8rbrcr^rGrfr�rgrhs@rrr�s����J��M�
�.��.rrc��eZdZdZy)�DotAtom�dot-atomNrxrnrrrrs���Jrrc��eZdZdZdZy)�DotAtomTextz
dot-atom-textTN�r8rbrcr^rGrnrrrrs�� �J��Mrrc��eZdZdZdZy)�
NoFoldLiteralzno-fold-literalFNrrnrrrr
s��"�J��Mrrc�T�eZdZdZdZed��Zed��Zed��Zed��Z	y)�AddrSpecr�Fc� �|djSrCr�r2s rr�zAddrSpec.local_partrrc�>�t|�dkry|djS)N�r�)r�r�r2s rr�zAddrSpec.domains���t�9�q�=���B�x���rc���t|�dkr|djS|djj�|djz|djj�zS)Nr#rr�r�)r�r�rstrip�lstripr2s rrzAddrSpec.valuesU���t�9�q�=���7�=�=� ��A�w�}�}�#�#�%�d�1�g�m�m�3�D��G�M�M�4H�4H�4J�J�Jrc���t|j�}t|�t|tz
�kDrt	|j�}n|j}|j
�|dz|j
zS|S)N�@)�setr�r��
DOT_ATOM_ENDSrr�)r"�nameset�lps   rr�zAddrSpec.addr_spec$s_���d�o�o�&���w�<�#�g�m�3�4�4��d�o�o�.�B����B��;�;�"���8�d�k�k�)�)��	rN)
r8rbrcr^rGrfr�r�rr�rnrrr r s\���J��M�
�"��"�����
�K��K�
���rr c��eZdZdZdZy)�ObsLocalPartzobs-local-partFNrrnrrr.r.0s��!�J��Mrr.c�@��eZdZdZdZed��Ze�fd��Z�xZS)�DisplayNamezdisplay-nameFc��t|�}t|�dk(r|jS|djdk(r|j	d�n<t|dt�r)|ddjdk(rt|ddd�|d<|djdk(r|j	�|jSt|dt�r)|ddjdk(rt|ddd�|d<|jS)Nrr�r�r�)rr�rr^�pop�
isinstance)r"r�s  rr�zDisplayName.display_name;s�����o���s�8�q�=��9�9���q�6����&��G�G�A�J��3�q�6�9�-���F�1�I�(�(�F�2�"�3�q�6�!�"�:�.��A���r�7����'��G�G�I�
�y�y���3�r�7�I�.���G�B�K�*�*�f�4�#�C��G�C�R�L�1��B���y�y�rc���d}|jrd}n|D]}|jdk(s�d}�t|�dk7r�|r�dx}}|djdk(s(t|dt�r|ddjdk(rd}|djdk(s(t|dt�r|ddjdk(rd}|t|j�z|zSt�|� S)	NFTr�rr'r�rmr�)	r!r^r�r3rrr�rr)r"r�r,�pre�postr%s     �rrzDisplayName.valueNs�������<�<��E����<�<�?�2� �E���t�9��>�e��O�C�$��Q��"�"�f�,��4��7�I�.��Q���
�%�%��/����R��#�#�v�-��4��8�Y�/��R����'�'�6�1����|�D�$5�$5�6�6�t�;�;��7�=� r)	r8rbrcr^rerfr�rrgrhs@rr0r06s4����J���
����$�!��!rr0c�4�eZdZdZdZed��Zed��Zy)�	LocalPartz
local-partFc�b�|djdk(r|djS|djS)Nrr�)r^r�rr2s rrzLocalPart.valueks2����7����0���7�'�'�'���7�=�=� rc���tg}t}d}|dtgzD]�}|jdk(r�|r2|jdk(r#|djdk(rt|dd�|d<t|t�}|r?|jdk(r0|djdk(r|j	t|dd��n|j	|�|d}|}��t|dd�}|j
S)NFrr��dotr�r�)�DOTr^rr3r�r)r"r��last�
last_is_tl�tok�is_tls      rr�zLocalPart.local_partrs����e�����
���7�c�U�?�C��~�~��'���s�~�~��6���H�'�'�6�1�#�D��"�I�.��B���s�I�.�E��$�/�/�U�2���F�%�%��/��
�
�9�S���W�-�.��
�
�3���r�7�D��J�#���A�b�	�"���y�y�rN)r8rbrcr^rGrfrr�rnrrr8r8fs2���J��M�
�!��!����rr8c�@��eZdZdZdZe�fd��Zed��Z�xZS)�
DomainLiteralzdomain-literalFc�R��djt�|�j��Srrr:s �rr�zDomainLiteral.domain�rrc�L�|D]}|jdk(s�|jcSy)N�ptextr�rss  r�ipzDomainLiteral.ip�s!���A��|�|�w�&��w�w��r)	r8rbrcr^rGrfr�rFrgrhs@rrBrB�s3���!�J��M�
�.��.����rrBc��eZdZdZdZdZy)�MIMEVersionzmime-versionN)r8rbrcr^�major�minorrnrrrHrH�s���J��E��ErrHc�<�eZdZdZdZdZdZed��Zed��Z	y)�	Parameter�	parameterF�us-asciic�<�|jr|djSdSr�)�	sectioned�numberr2s r�section_numberzParameter.section_number�s��"&���t�A�w�~�~�6�Q�6rc���|D]n}|jdk(r|jcS|jdk(s�0|D]:}|jdk(s�|D]#}|jdk(s�|jcccS�<�py)Nrr�r�r')r^r�r�s  r�param_valuezParameter.param_value�sx���E����7�*��+�+�+����?�2�"�E��'�'�+?�?�%*�E�$�/�/�7�:�',�';�';� ;�&+�#�	�rN)
r8rbrcr^rP�extendedr�rfrRrTrnrrrLrL�s<���J��I��H��G�
�7��7�
���rrLc��eZdZdZy)�InvalidParameter�invalid-parameterNrxrnrrrWrW�s��$�JrrWc� �eZdZdZed��Zy)�	Attribute�	attributec�d�|D]+}|jjd�s�|jcSy)N�attrtext)r^�endswithrr�s  rr�zAttribute.stripped_value�s*���E����(�(��4��{�{�"�rN�r8rbrcr^rfr�rnrrrZrZ�s���J�
�#��#rrZc��eZdZdZdZy)�Section�sectionN)r8rbrcr^rQrnrrrara�s���J�
�Frrac� �eZdZdZed��Zy)�Valuerc��|d}|jdk(r|d}|jjd�r|jS|jS)Nrr�r�)r�r[zextended-attribute)r^r^r�rr�s  rr�zValue.stripped_value�sP���Q������v�%���G�E����$�$�D�F��'�'�'��z�z�rNr_rnrrrdrd�s���J�
���rrdc�*�eZdZdZdZed��Zd�Zy)�MimeParameters�mime-parametersFc#�lK�i}|D]w}|jjd�s�|djdk7r�2|djj�}||vrg||<||j	|j
|f��y|j
�D�]�\}}t|td���}|dd}|j}|jsRt|�dkDrD|dddk(r9|ddjj	tjd��|dd}g}d}|D�]\}	}
|	|k7ri|
js/|
jj	tjd���G|
jj	tjd��|dz
}|
j}|
jrv	t j"j%|�}	|j'|d	�}t-j.|�r.|
jj	tj0��	|j	|���d
j5|�}||f�����y#t(t*f$r|j'd
d	�}Y��wxYw#t*$r$t j"j3|d��}Y��wxYw�w)NrMrr[)�keyr�z.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numbering�surrogateescaperNzlatin-1)�encodingr')r^r^r�stripr�rR�items�sortedrr�rUr�r!r�InvalidHeaderDefectrT�urllib�parse�unquote_to_bytes�decode�LookupError�UnicodeEncodeErrorr�_has_surrogates�UndecodableBytesDefect�unquoter1)r"�paramsrM�name�parts�first_paramr��value_parts�irR�paramrs            rrzzMimeParameters.params�s��������E��#�#�,�,�[�9���Q�x�"�"�k�1����8�>�>�'�'�)�D��6�!�!��t���4�L����!5�!5�u� =�>��"�<�<�>�K�D�%��5�j��m�4�E���(�1�+�K�!�)�)�G��'�'�C��J��N���8�A�;�!�#��!�H�Q�K�'�'�.�.�v�/I�/I�H�0J�K�!�"�1�I�E��K��A�).�%���!�Q�&�!�>�>��
�
�,�,�V�-G�-G�I�.K�L� ��
�
�,�,�V�-G�-G�F�.H�I��Q����)�)���>�>�R� &��� =� =�e� D��P�$)�L�L��:K�$L�E�!�0�0��7�!�M�M�0�0��1N�1N�1P�Q��"�"�5�)�C*/�D�G�G�K�(�E���+��g*��R!,�-?�@�P�
%*�L�L��=N�$O�E�P��.�P�!'��� 4� 4�U�Y� 4� O��	P�sI�F6J4�9J�I�+A2J4�!J�>J4�J�J4�*J1�.J4�0J1�1J4c	���g}|jD]C\}}|r+|jdj|t|����3|j|��Edj	|�}|rd|zSdS)N�{}={}z; rmr')rzr�r7rr1)r"rzr{rs    rr3zMimeParameters.__str__,se�����;�;�K�D�%���
�
�g�n�n�T�<��3F�G�H��
�
�d�#�	'�
���6�"��%�s�V�|�-�2�-rN)r8rbrcr^rdrfrzr3rnrrrgrg�s&��"�J��O�
�C��C�J.rrgc� �eZdZdZed��Zy)�ParameterizedHeaderValueFc�`�t|�D]}|jdk(s�|jcSiS)Nrh)�reversedr^rzr�s  rrzzParameterizedHeaderValue.params=s0���d�^�E����#4�4��|�|�#�$��	rN)r8rbrcrdrfrzrnrrr�r�7s���O�
���rr�c��eZdZdZdZdZdZy)�ContentTypezcontent-typeF�text�plainN)r8rbrcr^rG�maintype�subtypernrrr�r�Es���J��M��H��Grr�c��eZdZdZdZdZy)�ContentDispositionzcontent-dispositionFN)r8rbrcr^rG�content_dispositionrnrrr�r�Ls��&�J��M��rr�c��eZdZdZdZdZy)�ContentTransferEncodingzcontent-transfer-encodingF�7bitN)r8rbrcr^rGr�rnrrr�r�Rs��,�J��M�
�Crr�c��eZdZdZdZy)�HeaderLabelzheader-labelFNrrnrrr�r�Xs���J��Mrr�c��eZdZdZdZd�Zy)�MsgIDzmsg-idFc�2�t|�|jzSr)r�lineseprRs  rrSz
MsgID.foldas���4�y�6�>�>�)�)rN)r8rbrcr^rGrSrnrrr�r�]s���J��M�*rr�c��eZdZdZy)�	MessageIDz
message-idNrxrnrrr�r�fs���Jrr�c��eZdZdZy)�InvalidMessageIDzinvalid-message-idNrxrnrrr�r�js��%�Jrr�c��eZdZdZy)�Header�headerNrxrnrrr�r�nr|rr�c�r��eZdZdZdZdZ�fd�Z�fd�Zd�Ze	d��Z
d
�fd�	Zd�Ze	d��Z
d	�Z�xZS)�TerminalTc�D��t�|�||�}||_g|_|Sr)r�__new__r^r!)�clsrr^r"r%s    �rr�zTerminal.__new__|s&����w��s�E�*��$�������rc�h��dj|jjt�|���Sr5r6r:s �rr9zTerminal.__repr__�s&������t�~�~�6�6���8H�8J�K�Krc�b�t|jjdz|jz�y)N�/)rWr%r8r^r2s rrZzTerminal.pprint�s"��
�d�n�n�%�%��+�d�o�o�=�>rc�,�t|j�Sr)�listr!r2s rr?zTerminal.all_defects�s���D�L�L�!�!rc	����dj||jj|jt�|��|jsd�gSdj|j��gS)Nz
{}{}/{}({}){}r'z {})r7r%r8r^rr9r!)r"rVr%s  �rr\zTerminal._pp�sg����&�&���N�N�#�#��O�O��G����l�l�B���	�
).���T�\�\�(B���	rc��yrrnr2s r�pop_trailing_wszTerminal.pop_trailing_ws�rrc��gSrrnr2s rrLzTerminal.comments�s���	rc�0�t|�|jfSr)rr^r2s r�__getnewargs__zTerminal.__getnewargs__�s���4�y�$�/�/�*�*rra)r8rbrcrGrerdr�r9rZrfr?r\r�rLr�rgrhs@rr�r�vsZ����M����O��L�?��"��"�������+rr�c�"�eZdZed��Zd�Zy)�WhiteSpaceTerminalc��yrlrnr2s rrzWhiteSpaceTerminal.value�rorc��y)NTrnr2s rrDz!WhiteSpaceTerminal.startswith_fws�s��rN�r8rbrcrfrrDrnrrr�r��s��
����rr�c�"�eZdZed��Zd�Zy)�
ValueTerminalc��|Srrnr2s rrzValueTerminal.value�s���rc��y)NFrnr2s rrDzValueTerminal.startswith_fws�s��rNr�rnrrr�r��s��
����rr�c�"�eZdZed��Zd�Zy)�EWWhiteSpaceTerminalc��yrrnr2s rrzEWWhiteSpaceTerminal.value�s��rc��yrrnr2s rr3zEWWhiteSpaceTerminal.__str__�s��rN)r8rbrcrfrr3rnrrr�r��s��
����rr�c��eZdZdZy)�_InvalidEwErrorz1Invalid encoded word found while parsing headers.N)r8rbrc�__doc__rnrrr�r��s��;rr�r;�,zlist-separatorFr(zroute-component-markerz([{}]+)r'z[^{}]+z[\x00-\x20\x7F]c��t|�}|r.|jjtj|��tj|�r/|jjtjd��yy)z@If input token contains ASCII non-printables, register a defect.z*Non-ASCII characters found in header tokenN)�_non_printable_finderr!r�r�NonPrintableDefectrrwrx)�xtext�non_printabless  r�_validate_xtextr��sc��+�5�1�N��
�
�
���V�6�6�~�F�G����U�#�
�
�
���V�:�:�8�:�	;�$rc�"�t|d�^}}g}d}d}tt|��D]6}||dk(r
|rd}d}nd}�|rd}n	|||vrn|j||��8dz}dj	|�dj	||dg|z�|fS)akScan printables/quoted-pairs until endchars and return unquoted ptext.

    This function turns a run of qcontent, ccontent-without-comments, or
    dtext-with-quoted-printables into a single string by unquoting any
    quoted printables.  It returns the string, the remaining value, and
    a flag that is True iff there were any quoted printables decoded.

    r�FrTr'N)�
_wsp_splitter�ranger�r�r1)r�endchars�fragment�	remainder�vchars�escape�had_qp�poss        r�_get_ptext_to_endcharsr��s���)���2��H�y�
�F�
�F�
�F��S��]�#���C�=�D� �����������F�
�c�]�h�
&���
�
�h�s�m�$�$��A�g��
�7�7�6�?�B�G�G�X�c�d�^�$4�y�$@�A�6�I�Irc�r�|j�}t|dt|�t|�z
d�}||fS)z�FWS = 1*WSP

    This isn't the RFC definition.  We're using fws to represent tokens where
    folding can be done, but when we are parsing the *un*folding has already
    been done so we don't need to watch out for CRLF.

    N�fws)r&r�r�)r�newvaluer�s   r�get_fwsr�s:���|�|�~�H�
�U�#<�C��J�s�8�}�$<�=�u�
E�C���=�rc��t�}|jd�s$tjdj	|���|ddjdd�^}}||ddk(r$tjdj	|���dj
|�}t|�dkDrF|dtvr;|dtvr0|jd	�dkr|jdd�^}}|dz|z}t|j��dkDr.|jjtjd
��||_
dj
|�}	tjd|zdz�\}}}	}
||_|	|_|jj+|
�|ru|dt,vr t/|�\}}|j|��-t1|d�^}}t3||�}
t5|
�|j|
�dj
|�}|r�u|r9|dt,vr.|jjtjd��||fS#t t"f$r%t%dj	|j���wxYw)
zE encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

    �=?z"expected encoded word but found {}r�Nz?=r�r'r�?zwhitespace inside encoded wordz!encoded word format invalid: '{}'z.missing trailing whitespace after encoded-word)r��
startswithr�HeaderParseErrorr7rr1r�r�countr!r�rpr��_ewrt�
ValueError�KeyErrorr�r�r�rK�WSPr�r�r�r�)r�
terminal_type�ewr?r��remstr�restr�r�r�r!rM�chars�vtexts              r�get_encoded_wordr� s`��
��B����D�!��%�%�0�7�7��>�@�	@��A�B�i�o�o�d�A�.�O�C�)�
�e�A�B�i���%�%�0�7�7��>�@�	@�
�W�W�Y�
�F��F��a���q�	�Y���q�	�Y���	�	�#����!�<�<��a�0���y��D�j�4���
�3�9�9�;��!��
�
�
���&�4�4�,�.�	/�
�B�F��G�G�I��E�@�'*�z�z�$��*�t�2C�'D�$��g�t�W��B�J��B�G��J�J���g��
���7�c�>�!�$�-�K�E�4��I�I�e���)�$��2���	��e�]�3�����
�	�	�%���w�w�y�!���
��q���$�
�
�
���&�4�4�<�>�	?�
�u�9���)
��!�@��/�6�6�r�v�v�>�@�	@�@�s� I
�
4I>c� �t�}|�r[|dtvr t|�\}}|j|��.d}|j	d�r�	t|d�\}}d}t
|�dkDrB|djdk7r0|jjtjd��d}|r2t
|�d	kDr$|d
jdk(rt|dd�|d<|j|���t|d	�^}}|r(tj!|�r|j#d�^}}t%|d�}t'|�|j|�dj)|�}|r��[|S#t$rd}Y��tj$rY��wxYw)
aOunstructured = (*([FWS] vchar) *WSP) / obs-unstruct
       obs-unstruct = *((*LF *CR *(obs-utext) *LF *CR)) / FWS)
       obs-utext = %d0 / obs-NO-WS-CTL / LF / CR

       obs-NO-WS-CTL is control characters except WSP/CR/LF.

    So, basically, we have printable runs, plus control characters or nulls in
    the obsolete syntax, separated by whitespace.  Since RFC 2047 uses the
    obsolete syntax in its specification, but requires whitespace on either
    side of the encoded words, I can see no reason to need to separate the
    non-printable-non-whitespace from the printable runs if they occur, so we
    parse this into xtext tokens separated by WSP tokens.

    Because an 'unstructured' value must by definition constitute the entire
    value, this 'get' routine does not return a remaining value, only the
    parsed TokenList.

    rTr��utextr�r�z&missing whitespace before encoded wordFr����r�r')rvr�r�r�r�r�r�r^r!rrpr�r�r�r��rfc2047_matcher�search�	partitionr�r�r1)rrwrM�valid_ew�have_wsr?r�r�s        r�get_unstructuredr�Qs���.)�*�L�
���8�s�?�"�5�>�L�E�5�����&�������D�!�
�/��w�?���u����|�$�q�(�#�B�'�2�2�e�;�$�,�,�3�3�F�4N�4N�D�5F�G�"'���s�<�0�1�4�#�B�'�2�2�n�D�+?�(��,�e�,5��R�(��#�#�E�*��'��q�1���i���.�.�s�3�#�o�o�d�3�O�C�)��c�7�+��������E�"����	�"��Q�R���A#�
!� ���*�*�
��
�s�
E+�+F
�8F
�F
c�X�t|d�\}}}t|d�}t|�||fS)actext = <printable ascii except \ ( )>

    This is not the RFC ctext, since we are handling nested comments in comment
    and unquoting quoted-pairs here.  We allow anything except the '()'
    characters, but if we find any ASCII other than the RFC defined printable
    ASCII, a NonPrintableDefect is added to the token's defects list.  Since
    quoted pairs are converted to their unquoted values, what is returned is
    a 'ptext' token.  In this case it is a WhiteSpaceTerminal, so it's value
    is ' '.

    z()rE)r�r�r��rrE�_s   r�get_qp_ctextr��s4��-�U�D�9�O�E�5�!��u�g�.�E��E���%�<�rc�X�t|d�\}}}t|d�}t|�||fS)aoqcontent = qtext / quoted-pair

    We allow anything except the DQUOTE character, but if we find any ASCII
    other than the RFC defined printable ASCII, a NonPrintableDefect is
    added to the token's defects list.  Any quoted pairs are converted to their
    unquoted values, so what is returned is a 'ptext' token.  In this case it
    is a ValueTerminal.

    rrE)r�r�r�r�s   r�get_qcontentr��s4��-�U�C�8�O�E�5�!��%��)�E��E���%�<�rc���t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)z�atext = <matches _atext_matcher>

    We allow any non-ATOM_ENDS in atext, but add an InvalidATextDefect to
    the token's defects list if we find non-atext characters.
    zexpected atext but found '{}'N�atext)�_non_atom_end_matcherrr�r7r�r�r�r�)r�mr�s   r�	get_atextr��sk��	�e�$�A���%�%�+�2�2�5�9�;�	;�
�G�G�I�E��#�e�*�+��E��%��)�E��E���%�<�rc�N�|r|ddk7r$tjdj|���t�}|dd}|r'|ddk(rt	|�\}}|j|�|r�|ddk7r�|dtvrt|�\}}n�|dddk(r�d}	t|�\}}|jjtjd	��d
}|rSt|�dkDrE|djdk(r3|d
jdk(r!t|dd�|d<nt	|�\}}|j|�|r	|ddk7r��|s2|jjtjd��||fS||ddfS#tj$rt	|�\}}Y��wxYw)z�bare-quoted-string = DQUOTE *([FWS] qcontent) [FWS] DQUOTE

    A quoted-string without the leading or trailing white space.  Its
    value is the text between the quote marks, with whitespace
    preserved and quoted pairs decoded.
    rrzexpected '"' but found '{}'r�Nr�r�Fz!encoded word inside quoted stringTr�r�r�r�z"end of header inside quoted string)rr�r7r�r�r�r�r�r�r!rpr�r^r�)r�bare_quoted_stringrMr�s    r�get_bare_quoted_stringr��s����E�!�H��O��%�%�*�1�1�%�8�:�	:�)�+���!�"�I�E���q��S��#�E�*���u��!�!�%�(�
�E�!�H��O���8�s�?�"�5�>�L�E�5�
�2�A�Y�$�
��H�
3�/��6���u�"�*�*�1�1�&�2L�2L�7�39�:���
�C� 2�3�a�7�&�r�*�5�5��>�*�2�.�9�9�^�K�-A�*�2�.��.7�&�r�*�(��.�L�E�5��!�!�%�(�+�E�!�H��O�,��"�"�)�)�&�*D�*D�0�+2�	3�!�5�(�(��u�Q�R�y�(�(��!�*�*�
3�+�E�2���u�
3�s�>F�!F$�#F$c��|r,|ddk7r$tjdj|���t�}|dd}|rc|ddk7r[|dtvrt|�\}}n%|ddk(rt
|�\}}nt|�\}}|j|�|r	|ddk7r�[|s2|jjtjd��||fS||ddfS)z�comment = "(" *([FWS] ccontent) [FWS] ")"
       ccontent = ctext / quoted-pair / comment

    We handle nested comments here, and quoted-pair in our qp-ctext routine.
    rrzexpected '(' but found '{}'r�Nr�zend of header inside comment)rr�r7r�r�r��get_commentr�r�r!rp)rrqrMs   rr�r��s���
��q��S���%�%�)�0�0��7�9�	9��i�G��!�"�I�E�
�E�!�H��O���8�s�?�"�5�>�L�E�5�
�1�X��_�&�u�-�L�E�5�'��.�L�E�5����u���E�!�H��O�������v�9�9�*� ,�	-���~���E�!�"�I��rc���t�}|rR|dtvrG|dtvrt|�\}}nt	|�\}}|j|�|r|dtvr�G||fS)z,CFWS = (1*([FWS] comment) [FWS]) / FWS

    r)r��CFWS_LEADERr�r�r�r�)rr�rMs   r�get_cfwsrsg���:�D�
�E�!�H��+���8�s�?�"�5�>�L�E�5�&�u�-�L�E�5����E���E�!�H��+���;�rc��t�}|r*|dtvrt|�\}}|j|�t	|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS)z�quoted-string = [CFWS] <bare-quoted-string> [CFWS]

    'bare-quoted-string' is an intermediate class defined by this
    parser and not by the RFC grammar.  It is the quoted string
    without any attached CFWS.
    r)r�rrr�r�)r�
quoted_stringrMs   r�get_quoted_stringrs���!�N�M���q��[�(������u����U�#�)�%�0�L�E�5��������q��[�(������u����U�#��%��rc��t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���|jd�r	t|�\}}nt|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS#t
j$rt|�\}}Y�dwxYw)zPatom = [CFWS] 1*atext [CFWS]

    An atom could be an rfc2047 encoded word.
    rzexpected atom but found '{}'r�)r�rrr��	ATOM_ENDSrr�r7r�r�r�)rr�rMs   r�get_atomr's���
�6�D���q��[�(������u����E����q��Y�&��%�%�*�1�1�%�8�:�	:������	,�+�E�2�L�E�5�!��'���u��K�K�����q��[�(������u����E����;����&�&�	,�%�U�+�L�E�5�	,�s�:C�!C<�;C<c��t�}|r|dtvr$tjdj	|���|r\|dtvrQt|�\}}|j
|�|r"|ddk(r|j
t�|dd}|r|dtvr�Q|dtur'tjdj	d|z���||fS)z( dot-text = 1*atext *("." 1*atext)

    rz8expected atom at a start of dot-atom-text but found '{}'r	r�Nr�z4expected atom at end of dot-atom-text but found '{}')rrrr�r7r�r�r<)r�
dot_atom_textrMs   r�get_dot_atom_textrBs��� �M�M��E�!�H�	�)��%�%�'+�+1�6�%�=�:�	:�
�E�!�H�I�-� ��'���u����U�#��U�1�X��_�� � ��%��!�"�I�E��E�!�H�I�-��R��C���%�%�'�#�V�C��I�.�0�	0��%��rc��t�}|dtvrt|�\}}|j|�|j	d�r	t|�\}}nt|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS#tj$rt|�\}}Y�dwxYw)z� dot-atom = [CFWS] dot-atom-text [CFWS]

    Any place we can have a dot atom, we could instead have an rfc2047 encoded
    word.
    rr�)	rrrr�r�r�rr�r)r�dot_atomrMs   r�get_dot_atomrUs����y�H��Q�x�;�������u�����������	4�+�E�2�L�E�5�)��/���u��O�O�E����q��[�(������u�������U�?����&�&�	4�-�U�3�L�E�5�	4�s�B%�%!C	�C	c�(�|dtvrt|�\}}nd}|stjd��|ddk(rt	|�\}}n=|dt
vr$tjdj
|���t|�\}}|�|g|dd||fS)a�word = atom / quoted-string

    Either atom or quoted-string may start with CFWS.  We have to peel off this
    CFWS first to determine which type of word to parse.  Afterward we splice
    the leading CFWS, if any, into the parsed sub-token.

    If neither an atom or a quoted-string is found before the next special, a
    HeaderParseError is raised.

    The token returned is either an Atom or a QuotedString, as appropriate.
    This means the 'word' level of the formal grammar is not represented in the
    parse tree; this is because having that extra layer when manipulating the
    parse tree is more confusing than it is helpful.

    rNz5Expected 'atom' or 'quoted-string' but found nothing.rz1Expected 'atom' or 'quoted-string' but found '{}')rrrr�r�SPECIALSr7r)r�leaderrMs   r�get_wordrns��� 
�Q�x�;�� ���
�������%�%�C�E�	E��Q�x��}�(��/���u�	�q��X�	��%�%�'7�7=�v�e�}�F�	F� �����u�
���H��b�q�	��%�<�rc���t�}	t|�\}}|j|�|r�|dtvr|ddk(rI|jt�|j
jtjd��|dd}n 	t|�\}}|j|�|r|dtvr�||fS#tj$r1|j
jtjd��Y��wxYw#tj$rL|dtvr=t|�\}}|j
jtjd��n�Y��wxYw)a� phrase = 1*word / obs-phrase
        obs-phrase = word *(word / "." / CFWS)

    This means a phrase can be a sequence of words, periods, and CFWS in any
    order as long as it starts with at least one word.  If anything other than
    words is detected, an ObsoleteHeaderDefect is added to the token's defect
    list.  We also accept a phrase that starts with CFWS followed by a dot;
    this is registered as an InvalidHeaderDefect, since it is not supported by
    even the obsolete grammar.

    zphrase does not start with wordrr	zperiod in 'phrase'r�Nzcomment found without atom)rzrr�rr�r!rp�PHRASE_ENDSr<�ObsoleteHeaderDefectrr)rr{rMs   r�
get_phraser�sM���X�F�0������u��
�
�e���E�!�H�K�/���8�S�=��M�M�#���N�N�!�!�&�"=�"=�$�#&�
'��!�"�I�E�
�'�����u�
�M�M�%� �!�E�!�H�K�/�"�5�=���)�"�"�0������f�8�8�-�/�	0�0���*�*�
���8�{�*�#+�E�?�L�E�5��N�N�)�)�&�*E�*E�4�+6�7��7�
�s%�B;�
D�;AC?�>C?�AE!� E!c��t�}d}|r|dtvrt|�\}}|s$tjdj|���	t
|�\}}|�|g|dd|j|�|r�|ddk(s|dtvr�tt|�|z�\}}|jdk(r/|jjtjd��n.|jjtj d��||d<	|j"j%d�||fS#tj$rK	t|�\}}n7#tj$r!|ddk7r|dtvr�t�}YnwxYwY��6wxYw#t&$r4|jjtj(d	��Y||fSwxYw)
z= local-part = dot-atom / quoted-string / obs-local-part

    Nrz"expected local-part but found '{}'r�invalid-obs-local-partz<local-part is not dot-atom, quoted-string, or obs-local-partz,local-part is not a dot-atom (contains CFWS)�asciiz)local-part contains non-ASCII characters))r8rrrr�r7rrrrr��get_obs_local_partrr^r!rprr�encoderv�NonASCIILocalPartDefect)rr�rrM�obs_local_parts     r�get_local_partr�s�����J�
�F���q��[�(� ���
�����%�%�0�7�7��>�@�	@� �#�E�*���u����H��b�q�	����e���%��(�D�.�E�!�H�K�$?� 2�3�z�?�U�3J� K�����$�$�(@�@����%�%�f�&@�&@�N�'P�
Q�
���%�%�f�&A�&A�>�'@�
A�&�
�1�
�>�������(��u����1�"�"� �	 �#�E�?�L�E�5���&�&�	 ��Q�x�4��E�!�H��$;���K�E�	 �� ��*�>����!�!�&�"@�"@�;�#=�	>��u���>�sH�D6�F�6F�
E�F�1F
�
F�F
�
F�F�7G�Gc�N�t�}d}|�rB|ddk(s|dtv�r.|ddk(rM|r.|jjt	j
d��|jt�d}|dd}�l|ddk(rT|jt|dd	��|dd}|jjt	j
d
��d}��|r@|djdk7r.|jjt	j
d
��	t|�\}}d}|j|�|r|ddk(r��!|dtvr��.|s$t	jdj|���|djdk(s2|djdk(rNt|�dkDr@|djdk(r.|jjt	j
d��|djdk(s2|djdk(rNt|�dkDr@|djdk(r.|jjt	j
d��|jrd|_||fS#tj$r|dtvr�t|�\}}Y��{wxYw)z' obs-local-part = word *("." word)
    Frrr	zinvalid repeated '.'Tr�N�misplaced-specialz/'\' character outside of quoted-string/ccontentr�r;zmissing '.' between wordsz&expected obs-local-part but found '{}'r�z!Invalid leading '.' in local partr�z"Invalid trailing '.' in local partr)r.rr!r�rrpr<r�r^rr�rrr7r�)rr�last_non_ws_was_dotrMs    rrr�s���"�^�N���
�U�1�X�t�^�u�Q�x�{�'B���8�s�?�"��&�&�-�-�f�.H�.H�*�/,�-��!�!�#�&�"&���!�"�I�E��
�1�X�t�^��!�!�-��a��0C�#E�
F��!�"�I�E��"�"�)�)�&�*D�*D�B�+D�
E�"'����n�R�0�;�;�u�D��"�"�)�)�&�*D�*D�+�+-�
.�	+�#�E�?�L�E�5�"'��
	���e�$�7�U�1�X�t�^�u�Q�x�{�'B�8��%�%�4�;�;�E�B�D�	D��q��$�$��-��1��(�(�&�0����!�#��1��(�(�%�/����%�%�f�&@�&@�/�'1�	2��r��%�%��.��2��)�)�6�1����!�#��2��)�)�5�0����%�%�f�&@�&@�0�'2�	3����$<��!��5� � ��-�&�&�	+��Q�x�{�*��#�E�?�L�E�5�	+�s�I3�3-J$�#J$c��t|d�\}}}t|d�}|r.|jjt	j
d��t
|�||fS)a dtext = <printable ascii except \ [ ]> / obs-dtext
        obs-dtext = obs-NO-WS-CTL / quoted-pair

    We allow anything except the excluded characters, but if we find any
    ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is
    added to the token's defects list.  Quoted pairs are converted to their
    unquoted values, so what is returned is a ptext token, in this case a
    ValueTerminal.  If there were quoted-printables, an ObsoleteHeaderDefect is
    added to the returned token's defect list.

    z[]rEz(quoted printable found in domain-literal)r�r�r!r�rrr�)rrEr�s   r�	get_dtextr#sZ��2�%��>��E�5�&��%��)�E�
�
�
�
���V�8�8�6�8�	9��E���%�<�rc��|ry|jtjd��|jtdd��y)NFz"end of input inside domain-literal�]�domain-literal-endT)r�rrpr�)r�domain_literals  r�_check_for_early_dl_endr(%s?�������&�4�4�,�.�/����-��-A�B�C�rc�n�t�}|dtvrt|�\}}|j|�|st	j
d��|ddk7r$t	j
dj
|���|dd}t||�r||fS|jtdd��|dtvrt|�\}}|j|�t|�\}}|j|�t||�r||fS|dtvrt|�\}}|j|�t||�r||fS|ddk7r$t	j
d	j
|���|jtdd
��|dd}|r*|dtvrt|�\}}|j|�||fS)zB domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]

    rzexpected domain-literal�[z6expected '[' at start of domain-literal but found '{}'r�Nzdomain-literal-startr%z4expected ']' at end of domain-literal but found '{}'r&)rBrrr�rr�r7r(r�r�r�r#)rr'rMs   r�get_domain_literalr+-s���#�_�N��Q�x�;�������u����e�$���%�%�&?�@�@��Q�x�3���%�%�'!�!'����0�	0��!�"�I�E��u�n�5��u�$�$����-��-C�D�E��Q�x�3���u�~���u����e�$��U�#�L�E�5����%� ��u�n�5��u�$�$��Q�x�3���u�~���u����e�$��u�n�5��u�$�$��Q�x�3���%�%�'!�!'����0�	0����-��-A�B�C��!�"�I�E���q��[�(������u����e�$��5� � rc�"�t�}d}|r|dtvrt|�\}}|s$tjdj|���|ddk(r+t
|�\}}|�|g|dd|j|�||fS	t|�\}}|r|ddk(rtjd��|�|g|dd|j|�|r�|ddk(r�|jjtjd��|djd	k(r|d|dd|rJ|ddk(rB|jt�t|d
d�\}}|j|�|r	|ddk(r�B||fS#tj$rt|�\}}Y��wxYw)z] domain = dot-atom / domain-literal / obs-domain
        obs-domain = atom *("." atom))

    Nrzexpected domain but found '{}'r*r(zInvalid Domainr	z(domain is not a dot-atom (contains CFWS)rr�)rrrrr�r7r+r�rrr!rr^r<)rr�rrMs    r�
get_domainr-Ts���
�X�F�
�F���q��[�(� ���
�����%�%�,�3�3�E�:�<�	<��Q�x�3��)�%�0���u�����E�"�1�I��
�
�e���u�}��'�#�E�*���u�
��q��S���%�%�&6�7�7�
���H��b�q�	�
�M�M�%����q��S�������f�9�9�6�8�	9��!�9���:�-��q�	�F�1�I���a��C���M�M�#��#�E�!�"�I�.�L�E�5��M�M�%� ���a��C���5�=���!�"�"�'������u�'�s�E*�*!F�
Fc�N�t�}t|�\}}|j|�|r|ddk7r2|jjt	j
d��||fS|jt
dd��t|dd�\}}|j|�||fS)z( addr-spec = local-part "@" domain

    rr(z#addr-spec local part with no domain�address-at-symbolr�N)r rr�r!rrpr�r-)rr�rMs   r�
get_addr_specr0zs����
�I�!�%�(�L�E�5�
���U���E�!�H��O���� � ��!;�!;�1�"3�	4��%���
���]�3�(;�<�=��e�A�B�i�(�L�E�5�
���U���e��rc���t�}|rw|ddk(s|dtvrd|dtvr t|�\}}|j|�n"|ddk(r|jt�|dd}|r|ddk(r�X|dtvr�d|r|ddk7r$tjdj|���|jt�t|dd�\}}|j|�|r�|ddk(r�|jt�|dd}|snw|dtvrt|�\}}|j|�|snJ|ddk(r7|jt�t|dd�\}}|j|�|r	|ddk(r��|stjd��|ddk7r$tjd	j|���|jtdd
��||ddfS)z� obs-route = obs-domain-list ":"
        obs-domain-list = *(CFWS / ",") "@" domain *("," [CFWS] ["@" domain])

        Returns an obs-route token with the appropriate sub-tokens (that is,
        there is no obs-domain-list in the parse tree).
    rr�r�Nr(z(expected obs-route domain but found '{}'z%end of header while parsing obs-route�:z4expected ':' marking end of obs-route but found '{}'zend-of-obs-route-marker)rrrr��
ListSeparatorrr�r7�RouteComponentMarkerr-r�)r�	obs_routerMs   r�
get_obs_router6�s����
�I�
�U�1�X�s�]�e�A�h�+�&=���8�{�"�#�E�?�L�E�5����U�#�
�1�X��_����]�+��!�"�I�E�
�U�1�X�s�]�e�A�h�+�&=��E�!�H��O��%�%�6�=�=�e�D�F�	F�
���)�*��e�A�B�i�(�L�E�5�
���U��
�E�!�H�c�M�����'��a�b�	������8�{�"�#�E�?�L�E�5����U�#�����8�s�?����1�2�%�e�A�B�i�0�L�E�5����U�#��E�!�H�c�M���%�%�&M�N�N��Q�x�3���%�%�('�'-�v�e�}�6�	6�
���]�3�(A�B�C��e�A�B�i��rc�x�t�}|r*|dtvrt|�\}}|j|�|r|ddk7r$t	j
dj
|���|jtdd��|dd}|rZ|ddk(rR|jtdd��|jjt	jd	��|dd}||fS	t|�\}}|j|�|r|ddk(r|dd}n.|jjt	jd��|jtdd��|r*|dtvrt|�\}}|j|�||fS#tj
$r�	t|�\}}|jjt	jd
��n;#tj
$r%t	j
dj
|���wxYw|j|�t|�\}}Y��HwxYw)
z� angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
        obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS]

    r�<z"expected angle-addr but found '{}'zangle-addr-startr�N�>zangle-addr-endznull addr-spec in angle-addrz*obsolete route specification in angle-addrz.expected addr-spec or obs-route but found '{}'z"missing trailing '>' on angle-addr)
r�rrr�rr�r7r�r!rpr0r6r)r�
angle_addrrMs   r�get_angle_addrr;�s4��
��J���q��[�(������u����%� ��E�!�H��O��%�%�0�7�7��>�@�	@����m�C�);�<�=��!�"�I�E�
��q��S�����-��-=�>�?����!�!�&�"<�"<�*�#,�	-��a�b�	���5� � �,�$�U�+���u����e����q��S���a�b�	�����!�!�&�"<�"<�0�#2�	3����m�C�)9�:�;���q��[�(������u����%� ��u����)�"�"�	,�	P�(��/�L�E�5����%�%�f�&A�&A�<�'>�
?���&�&�	P��)�)�@�G�G��N�P�
P�	P��	���%� �$�U�+���u�	,�s*�"F
�
H9�<G�H9�8H�"H9�8H9c��t�}t|�\}}|j|dd�|jdd|_||fS)z� display-name = phrase

    Because this is simply a name-rule, we don't return a display-name
    token containing a phrase, but rather a display-name token with
    the content of the phrase.

    N)r0rrKr!)rr�rMs   r�get_display_namer=�sG���=�L��e�$�L�E�5�����a��!� �=�=��+�L�����rc��t�}d}|s$tjdj|���|dtvr4t|�\}}|s$tjdj|���|ddk7r�|dtvr$tjdj|���t|�\}}|s$tjdj|���|�%t|dt�r
|g|dddn|g|ddd}|j|�t|�\}}|�|g|dd|j|�||fS)z, name-addr = [display-name] angle-addr

    Nz!expected name-addr but found '{}'rr8)r�rr�r7rrrr=r3rr�r;)r�	name_addrrrMs    r�
get_name_addrr@�s`���
�I�
�F���%�%�/�6�6�u�=�?�	?��Q�x�;�� ���
�����)�)�3�:�:�6�B�D�
D��Q�x�3����8�{�"��)�)�3�:�:�5�A�C�
C�'��.���u���)�)�3�:�:�5�A�C�
C����%��(�I�.� &�x��a���!��#�H��b�q�	��F������!�%�(�L�E�5�
���H��b�q�	�
���U���e��rc�l�t�}	t|�\}}t
d�|jD��rd|_|j|�||fS#tj$rN	t	|�\}}n;#tj$r%tjdj|���wxYwY��wxYw)z& mailbox = name-addr / addr-spec

    zexpected mailbox but found '{}'c3�PK�|]}t|tj���� y�wr)r3rrpr*s  rr-zget_mailbox.<locals>.<genexpr>%s%����3� 1�1��a��3�3�4� 1���$&r�)
rr@rr�r0r7�anyr?r^r�)rr�rMs   r�get_mailboxrEs����i�G�A�$�U�+���u��3� %� 1� 1�3�3�.����N�N�5���E�>����"�"�A�	A�(��/�L�E�5���&�&�	A��)�)�1�8�8��?�A�
A�	A���A�s)�A�B3�&A5�4B3�58B-�-B3�2B3c���t�}|r_|d|vrX|dtvr$|jt|dd��|dd}nt	|�\}}|j|�|r|d|vr�X||fS)z� Read everything up to one of the chars in endchars.

    This is outside the formal grammar.  The InvalidMailbox TokenList that is
    returned acts like a Mailbox, but the data attributes are None.

    rr r�N)r
rr�r�r)rr��invalid_mailboxrMs    r�get_invalid_mailboxrH+s���%�&�O�
�E�!�H�H�,���8�{�"��"�"�=��q��1D�$F�
G��!�"�I�E�%�e�,�L�E�5��"�"�5�)��E�!�H�H�,��E�!�!rc�\�t�}|r�|ddk7r�	t|�\}}|j|�|ra|ddvrZ|d}d	|_t|d�\}}|j|�|jjtjd��|r"|ddk(r|jt�|d
d}|r	|ddk7r��||fS#tj$�rLd}|dt
vr�t
|�\}}|r|ddvr@|j|�|jjtjd��n�t|d�\}}|�|g|dd|j|�|jjtjd��n�|ddk(r/|jjtjd��nVt|d�\}}|�|g|dd|j|�|jjtjd��Y���wxYw)aJ mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list
        obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS])

    For this routine we go outside the formal grammar in order to improve error
    handling.  We recognize the end of the mailbox list only at the end of the
    value or at a ';' (the group terminator).  This is so that we can turn
    invalid mailboxes into InvalidMailbox tokens and continue parsing any
    remaining valid mailboxes.  We also allow all mailbox entries to be null,
    and this condition is handled appropriately at a higher level.

    r�;Nz,;zempty element in mailbox-listzinvalid mailbox in mailbox-listr�r�r�r�)r�rEr�rr�rrr!rrHrpr^rKr3)r�mailbox_listrMrr�s     r�get_mailbox_listrL=s5���=�L�
�E�!�H��O�	8�&�u�-�L�E�5�����&�4�U�1�X�T�)�#�2�&�G�!2�G��.�u�d�;�L�E�5��N�N�5�!�� � �'�'��(B�(B�1�)3�
4��U�1�X��_����
�.��!�"�I�E�Q�E�!�H��O�R�����K�&�&�	8��F��Q�x�;�&� (���
�����a��D� 0� �'�'��/� �(�(�/�/��0K�0K�7�19�:�$7�u�d�#C�L�E�5��)�%+�H��b�q�	� �'�'��.� �(�(�/�/��0J�0J�9�1;�<��q��S���$�$�+�+�F�,G�,G�3�-5�6� 3�5�$�?���u��%�!'��E�"�1�I��#�#�E�*��$�$�+�+�F�,F�,F�5�-7�8��/	8�s�C�EH+�*H+c��t�}|s2|jjtjd��||fSd}|r{|dt
vrpt
|�\}}|sC|jjtjd��|j|�||fS|ddk(r|j|�||fSt|�\}}t|j�dk(rV|�|j|�|j|�|jjtjd��||fS|�|g|dd|j|�||fS)zg group-list = mailbox-list / CFWS / obs-group-list
        obs-group-list = 1*([CFWS] ",") [CFWS]

    zend of header before group-listNrzend of header in group-listrJzgroup-list with empty entries)r�r!r�rrprrrLr�r�rKr)r�
group_listrrMs    r�get_group_listrOvsa��
��J�����!�!�&�"<�"<�-�#/�	0��5� � �
�F���q��[�(� ���
����
���%�%�f�&@�&@�-�'/�
0����f�%��u�$�$���8�s�?����f�%��u�$�$�#�E�*�L�E�5�
�5�����"������f�%����%� ����!�!�&�"=�"=�+�#-�	.��5� � �
���H��b�q�	����e���u��rc���t�}t|�\}}|r|ddk7r$tjdj	|���|j|�|jt
dd��|dd}|r*|ddk(r"|jt
dd��||ddfSt|�\}}|j|�|s/|jjtjd	��n,|ddk7r$tjd
j	|���|jt
dd��|dd}|r*|dtvrt|�\}}|j|�||fS)z7 group = display-name ":" [group-list] ";" [CFWS]

    rr2z8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorr�NrJzgroup-terminatorzend of header in groupz)expected ';' at end of group but found {})r�r=rr�r7r�r�rOr!rprr)rr�rMs   r�	get_grouprQ�sa��
�G�E�#�E�*�L�E�5��E�!�H��O��%�%�'*�*0�&��-�9�	9�	�L�L���	�L�L��s�$C�D�E��!�"�I�E���q��S��
���]�3�(:�;�<��e�A�B�i���!�%�(�L�E�5�	�L�L����
�
�
���V�7�7�$�&�	'�	�q��S���%�%�7�>�>�u�E�G�	G�	�L�L��s�$6�7�8��!�"�I�E���q��[�(������u�
���U���%�<�rc�&�t�}	t|�\}}|j
|�||fS#tj$rN	t	|�\}}n;#tj$r%tjdj|���wxYwY�uwxYw)a� address = mailbox / group

    Note that counter-intuitively, an address can be either a single address or
    a list of addresses (a group).  This is why the returned Address object has
    a 'mailboxes' attribute which treats a single address as a list of length
    one.  When you need to differentiate between to two cases, extract the single
    element, which is either a mailbox or a group token.

    zexpected address but found '{}')r�rQrr�rEr7r�)rr�rMs   r�get_addressrS�s���"�i�G�A� ��'���u��N�N�5���E�>����"�"�A�	A�&�u�-�L�E�5���&�&�	A��)�)�1�8�8��?�A�
A�	A���A�s'�/�B�A�B�8B
�
B�Bc�^�t�}|r�	t|�\}}|j|�|re|ddk7r]|dd}d|_t|d�\}}|j|�|jjtjd��|r|jt�|d	d}|r��||fS#tj$�rad}|dt
vr�t
|�\}}|r|ddk(r@|j|�|jjtjd��n�t|d�\}}|�|g|dd|jt|g��|jjtjd��n�|ddk(r/|jjtjd��n`t|d�\}}|�|g|dd|jt|g��|jjtjd��Y���wxYw)
a� address_list = (address *("," address)) / obs-addr-list
        obs-addr-list = *([CFWS] ",") address *("," [address / CFWS])

    We depart from the formal grammar here by continuing to parse until the end
    of the input, assuming the input to be entirely composed of an
    address-list.  This is always true in email parsing, and allows us
    to skip invalid addresses to parse additional valid ones.

    Nrr�z"address-list entry with no contentzinvalid address in address-listzempty element in address-listr�r�r�)r�rSr�rr�rrr!rrHr�rpr^rKr3)r�address_listrMrr�s     r�get_address_listrV�s(���=�L�
�	8�&�u�-�L�E�5�����&�4�U�1�X��_�#�2�&�q�)�G�!2�G��.�u�c�:�L�E�5��N�N�5�!�� � �'�'��(B�(B�1�)3�
4�����
�.��!�"�I�E�Q�R�����K�&�&�	8��F��Q�x�;�&� (���
�����a��C�� �'�'��/� �(�(�/�/��0K�0K�<�1>�?�$7�u�c�#B�L�E�5��)�%+�H��b�q�	� �'�'����(8�9� �(�(�/�/��0J�0J�9�1;�<��q��S���$�$�+�+�F�,G�,G�3�-5�6� 3�5�#�>���u��%�!'��E�"�1�I��#�#�G�U�G�$4�5��$�$�+�+�F�,F�,F�5�-7�8��/	8�s�B7�7E1H,�+H,c���t�}|s$tjdj|���|ddk7r$tjdj|���|j	tdd��|dd}t
|�\}}|j	|�|r|ddk7r$tjd	j|���|j	tdd
��||ddfS)z& no-fold-literal = "[" *dtext "]"
    z'expected no-fold-literal but found '{}'rr*z;expected '[' at the start of no-fold-literal but found '{}'zno-fold-literal-startr�Nr%z9expected ']' at the end of no-fold-literal but found '{}'zno-fold-literal-end)rrr�r7r�r�r#)r�no_fold_literalrMs   r�get_no_fold_literalrY
s���$�o�O���%�%�5�<�<�U�C�E�	E��Q�x�3���%�%�
�#�V�E�]�,�	,����=��.E�F�G��!�"�I�E��U�#�L�E�5����5�!��E�!�H��O��%�%�
�#�V�E�]�,�	,����=��.C�D�E��E�!�"�I�%�%rc�F�t�}|r*|dtvrt|�\}}|j|�|r|ddk7r$t	j
dj
|���|jtdd��|dd}	t|�\}}|j|�|r|dd	k7r\|jjt	jd
��|r(|ddk(r |jtdd��|dd}||fS|jtd	d
��|dd}	t|�\}}|j|�|r|ddk(r|dd}n.|jjt	jd��|jtdd��|r*|dtvrt|�\}}|j|�||fS#tj
$r}	t|�\}}|jjt	jd��n;#tj
$r%t	j
dj
|���wxYwY���wxYw#tj
$r�	t|�\}}n�#tj
$r|	t|�\}}|jjt	jd��n;#tj
$r%t	j
dj
|���wxYwYnwxYwY���wxYw)z�msg-id = [CFWS] "<" id-left '@' id-right  ">" [CFWS]
       id-left = dot-atom-text / obs-id-left
       id-right = dot-atom-text / no-fold-literal / obs-id-right
       no-fold-literal = "[" *dtext "]"
    rr8zexpected msg-id but found '{}'zmsg-id-startr�Nzobsolete id-left in msg-idz4expected dot-atom-text or obs-id-left but found '{}'r(zmsg-id with no id-rightr9z
msg-id-endr/zobsolete id-right in msg-idzFexpected dot-atom-text, no-fold-literal or obs-id-right but found '{}'zmissing trailing '>' on msg-id)r�rrr�rr�r7r�rrr!rrprYr-)r�msg_idrMs   r�
get_msg_idr\#s����W�F���q��[�(������u��
�
�e���E�!�H��O��%�%�,�3�3�E�:�<�	<�
�M�M�-��^�4�5��!�"�I�E�1�(��/���u��M�M�%���E�!�H��O������f�8�8�%�'�	(�
�U�1�X��_��M�M�-��\�:�;��!�"�I�E��u�}��
�M�M�-��%8�9�:��!�"�I�E�
5�(��/���u��M�M�%����q��S���a�b�	�������f�8�8�,�.�	/�
�M�M�-��\�2�3���q��[�(������u��
�
�e���5�=���a�"�"�	1�	1�-�e�4�L�E�5��N�N�!�!�&�"=�"=�,�#.�
/���&�&�	1��)�)�"�"(�&��-�1�
1�	1��
/�		1��4�"�"�5�
	5�.�u�5�L�E�5���&�&�	5�
5�)�%�0���u����%�%�f�&A�&A�1�'3�4���*�*�
5��-�-�&�&,�f�U�m�5�5�
5��4�	5��5�sx�G�,I'�I$�(<H%�$I$�%8I�I$�#I$�'L �;J
�	L �
L�<K�L�8L�L�L �L�L �L c��t�}	t|�\}}|j|�|r=|jjt	j
dj
|���|S#tj$r^}t|�}t|�}|jjt	j
dj
|���Yd}~|Sd}~wwxYw)z2message-id      =   "Message-ID:" msg-id CRLF
    zUnexpected {!r}zInvalid msg-id: {!r}N)
r�r\r�r!rrpr7r�r�r�)r�
message_idrM�exs    r�parse_message_idr`hs�����J�2�!�%�(���u����%� �����%�%�f�&@�&@�!�(�(��/�'1�
2�����"�"�K� ��'��%�e�,�
����!�!��&�&�'=�'D�'D�R�'H�I�	K�	K����K�s�A,�,C�?AC�Cc�j�t�}|s0|jjtjd��|S|dt
vrOt
|�\}}|j|�|s.|jjtjd��d}|r6|ddk7r.|dt
vr#||dz
}|dd}|r|ddk7r|dt
vr�#|j�sY|jjtjdj|���|jt|d	��n+t|�|_|jt|d
��|r*|dt
vrt
|�\}}|j|�|r|ddk7rY|j�.|jjtjd��|r|jt|d	��|S|jtdd��|dd}|r*|dt
vrt
|�\}}|j|�|s<|j�.|jjtjd��|Sd}|r&|dt
vr||dz
}|dd}|r|dt
vr�|j�sY|jjtjd
j|���|jt|d	��n+t|�|_
|jt|d
��|r*|dt
vrt
|�\}}|j|�|rI|jjtjd��|jt|d	��|S)zE mime-version = [CFWS] 1*digit [CFWS] "." [CFWS] 1*digit [CFWS]

    z%Missing MIME version number (eg: 1.0)rz0Expected MIME version number but found only CFWSr'r	r�Nz1Expected MIME major version number but found {!r}r��digitsz0Incomplete MIME version; found only major numberzversion-separatorz1Expected MIME minor version number but found {!r}z'Excess non-CFWS text after MIME version)rHr!r�r�HeaderMissingRequiredValuerr�isdigitrpr7r��intrIrJ)r�mime_versionrMrbs    r�parse_mime_versionrg�sp���=�L�����#�#�F�$E�$E�3�%5�	6����Q�x�;�������u����E�"��� � �'�'��(I�(I�B�)D�
E�
�F�
�E�!�H��O��a���(C��%��(����a�b�	���E�!�H��O��a���(C��>�>�����#�#�F�$>�$>�?�F�F�v�N�%P�	Q����M�&�'�:�;� ��[������M�&�(�;�<���q��[�(������u����E�"��E�!�H��O����)�� � �'�'��(B�(B�B�)D�
E�����
�e�W� =�>������
�c�+>�?�@��!�"�I�E���q��[�(������u����E�"�����)�� � �'�'��(B�(B�B�)D�
E���
�F�
�E�!�H�K�/��%��(����a�b�	���E�!�H�K�/��>�>�����#�#�F�$>�$>�?�F�F�v�N�%P�	Q����M�&�'�:�;� ��[������M�&�(�;�<���q��[�(������u����E�"�����#�#�F�$>�$>�5�%7�	8����M�%��9�:��rc���t�}|ra|ddk7rY|dtvr$|jt|dd��|dd}nt	|�\}}|j|�|r	|ddk7r�Y||fS)z� Read everything up to the next ';'.

    This is outside the formal grammar.  The InvalidParameter TokenList that is
    returned acts like a Parameter, but the data attributes are None.

    rrJr r�N)rWrr�r�r)r�invalid_parameterrMs   r�get_invalid_parameterrj�s���)�*��
�E�!�H��O���8�{�"��$�$�]�5��8�3F�&H�
I��!�"�I�E�%�e�,�L�E�5��$�$�U�+��E�!�H��O��e�#�#rc���t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)a8ttext = <matches _ttext_matcher>

    We allow any non-TOKEN_ENDS in ttext, but add defects to the token's
    defects list if we find non-ttext characters.  We also register defects for
    *any* non-printables even though the RFC doesn't exclude all of them,
    because we follow the spirit of RFC 5322.

    zexpected ttext but found '{}'N�ttext)�_non_token_end_matcherrr�r7r�r�r�r�)rr�rls   r�	get_ttextrn�sk��	�u�%�A���%�%�+�2�2�5�9�;�	;�
�G�G�I�E��#�e�*�+��E��%��)�E��E���%�<�rc�n�t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���t|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS)z�token = [CFWS] 1*ttext [CFWS]

    The RFC equivalent of ttext is any US-ASCII chars except space, ctls, or
    tspecials.  We also exclude tabs even though the RFC doesn't.

    The RFC implies the CFWS but is not explicit about it in the BNF.

    r�expected token but found '{}')	r�rrr��
TOKEN_ENDSrr�r7rn)r�mtokenrMs   r�	get_tokenrs�s����W�F���q��[�(������u��
�
�e����q��Z�'��%�%�+�2�2�5�9�;�	;��U�#�L�E�5�
�M�M�%����q��[�(������u��
�
�e���5�=�rc���t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)aQattrtext = 1*(any non-ATTRIBUTE_ENDS character)

    We allow any non-ATTRIBUTE_ENDS in attrtext, but add defects to the
    token's defects list if we find non-attrtext characters.  We also register
    defects for *any* non-printables even though the RFC doesn't exclude all of
    them, because we follow the spirit of RFC 5322.

    z expected attrtext but found {!r}Nr])�_non_attribute_end_matcherrr�r7r�r�r�r��rr�r]s   r�get_attrtextrw	sk��	#�5�)�A���%�%�.�5�5�e�<�>�	>��w�w�y�H��#�h�-�.�!�E��X�z�2�H��H���U�?�rc�n�t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���t|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS)aH [CFWS] 1*attrtext [CFWS]

    This version of the BNF makes the CFWS explicit, and as usual we use a
    value terminal for the actual run of characters.  The RFC equivalent of
    attrtext is the token characters, with the subtraction of '*', "'", and '%'.
    We include tab in the excluded set just as we do for token.

    rrp)	rZrrr��ATTRIBUTE_ENDSrr�r7rw�rr[rMs   r�
get_attributer{	s�����I���q��[�(������u��������q��^�+��%�%�+�2�2�5�9�;�	;���&�L�E�5�
���U����q��[�(������u�������e��rc���t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)z�attrtext = 1*(any non-ATTRIBUTE_ENDS character plus '%')

    This is a special parsing routine so that we get a value that
    includes % escapes as a single string (which we decode as a single
    string later).

    z)expected extended attrtext but found {!r}N�extended-attrtext)�#_non_extended_attribute_end_matcherrr�r7r�r�r�r�rvs   r�get_extended_attrtextr.	sn��	,�E�2�A���%�%�7�>�>�u�E�G�	G��w�w�y�H��#�h�-�.�!�E��X�':�;�H��H���U�?�rc�n�t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���t|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS)z� [CFWS] 1*extended_attrtext [CFWS]

    This is like the non-extended version except we allow % characters, so that
    we can pick up an encoded value as a single string.

    rrp)	rZrrr��EXTENDED_ATTRIBUTE_ENDSrr�r7rrzs   r�get_extended_attributer�@	s�����I���q��[�(������u��������q��4�4��%�%�+�2�2�5�9�;�	;�(��/�L�E�5�
���U����q��[�(������u�������e��rc�l�t�}|r|ddk7r$tjdj|���|j	tdd��|dd}|r|dj
�s$tjdj|���d}|r6|dj
�r#||dz
}|dd}|r|dj
�r�#|dd	k(r3|d	k7r.|jj	tjd
��t|�|_
|j	t|d��||fS)a6 '*' digits

    The formal BNF is more complicated because leading 0s are not allowed.  We
    check for that and add a defect.  We also assume no CFWS is allowed between
    the '*' and the digits, though the RFC is not crystal clear on that.
    The caller should already have dealt with leading CFWS.

    r�*zExpected section but found {}zsection-markerr�Nz$Expected section number but found {}r'�0z'section number has an invalid leading 0rb)rarr�r7r�r�rdr!rprerQ)rrbrbs   r�get_sectionr�V	s2���i�G��E�!�H��O��%�%�&E�&L�&L�(-�'/�0�	0��N�N�=��&6�7�8��!�"�I�E���a��(�(�*��%�%�'1�17����@�	@�
�F�
�E�!�H�$�$�&��%��(����a�b�	���E�!�H�$�$�&��a�y�C��F�c�M������v�9�9�9� ;�	<���[�G�N��N�N�=���2�3��E�>�rc�J�t�}|stjd��d}|dtvrt	|�\}}|s$tjdj|���|ddk(rt
|�\}}nt|�\}}|�|g|dd|j|�||fS)z  quoted-string / attribute

    z&Expected value but found end of stringNrz Expected value but found only {}r)	rdrr�rrr7rr�r�)r�vrrMs    r�	get_valuer�t	s���	��A���%�%�&N�O�O�
�F��Q�x�;�� ���
�����%�%�'0�06��v��@�	@��Q�x�3��(��/���u�-�e�4���u�
���H��b�q�	��H�H�U�O��e�8�Orc�2
�t�}t|�\}}|j|�|r|ddk(rA|jjt	j
dj
|���||fS|ddk(rm	t|�\}}d|_|j|�|st	jd��|ddk(r'|jtdd��|dd	}d|_|dd
k7rt	jd��|jtd
d��|dd	}|r*|dtvrt|�\}}|j|�d	}|}|j�r|�r|dd
k(r�t|�\}}|j}d}|j dk(r(|r|ddk(rd}n/t#|�\}}|r|ddk(rd}n	t%|�\}}|sd}	|ra|jjt	j
d��|j|�|D]}	|	j&dk(s�g|	d	d	|	}n|}n0d	}|jjt	j
d��|r|ddk(rd	}nt)|�\}}|jr|j dkDrZ|r|ddk7r"|j|�|�|rJ|��|}||fS|jjt	j
d��|sF|jjt	j
d��|j|�|��#||fS|�I|D]}	|	j&dk(s�n	j&dk(|j|	�|	j*|_|ddk7r$t	jdj
|���|jtdd��|dd	}|rf|ddk7r^t#|�\}}|j|�|j*|_|r|ddk7r$t	jdj
|���|jtdd��|dd	}|�et1�}
|rV|dt2vrt5|�\}}n(|dd
k(rtd
d�}|dd	}nt7|�\}}|
j|�|r�V|
}nt)|�\}}|j|�|�|rJ|��|}||fS#tj$rY��iwxYw#Y��@xYw)aY attribute [section] ["*"] [CFWS] "=" value

    The CFWS is implied by the RFC but not made explicit in the BNF.  This
    simplified form of the BNF from the RFC is made to conform with the RFC BNF
    through some extra checks.  We do it this way because it makes both error
    recovery and working with the resulting parse tree easier.
    rrJz)Parameter contains name ({}) but no valuer�TzIncomplete parameterzextended-parameter-markerr�N�=zParameter not followed by '='�parameter-separatorrF�'z5Quoted string value for extended parameter is invalidr�zZParameter marked as extended but appears to have a quoted string value that is non-encodedzcApparent initial-extended-value but attribute was not marked as extended or was not initial sectionz(Missing required charset/lang delimitersr}r]z=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {}�DQUOTE)rLr{r�r!rrpr7r�rPr�r�rUrrrr�rRrwrr^r�rr�r�rdr�r�r�)rr�rMr��appendto�qstring�inner_value�
semi_validr��tr�s           r�
get_parameterr��	s+��
�K�E� ��'�L�E�5�	�L�L����E�!�H��O�
�
�
���V�7�7�9%�%+�V�E�]�4�	5��e�|���Q�x�3��	�&�u�-�L�E�5�"�E�O��L�L�����)�)�*@�A�A���8�s�?��L�L��s�,G�H�I��!�"�I�E�!�E�N��Q�x�3���%�%�&E�F�F�	�L�L��s�$9�:�;��!�"�I�E���q��[�(������u�
���U���I��H��~�~�%�E�!�H��O�/�u�5�����,�,���
����1�$��{�1�~��4�!�
�*�;�7���t��D��G�s�N�!%�J�
&�3�K�@���t��!%�J���M�M� � ��!;�!;�G�"I�
J��L�L��!����<�<�#7�7��A�a�D� �H��	�
 �E��I��M�M� � ��!;�!;�:�";�
<�
��q��S���� ��'���u��>�>�U�1�1�A�5���a��C���O�O�E�"��$� �'�%�'�y�!���%�<��
�
�
���V�7�7�
D�E�	F��
�
�
���V�7�7�6�8�	9���������%�<�������<�<�#6�6���
�L�L�J�&��O�O�A���G�G�E�M���8�s�?��)�)�+F�FL�f�U�m�U�
U����
�c�+>�?�@��a�b�	���U�1�X��_�'��.�L�E�5��O�O�E�"����E�J��E�!�H��O��-�-�/<�<B�F�5�M�K�K����
�c�+>�?�@��a�b�	�����G����Q�x�3��&�u�~���u��q��S��%�c�8�4���a�b�	��+�E�2���u�
�H�H�U�O���� ��'���u��O�O�E������%��y����%�<���i�&�&�	��	��D
��s�>&S7�T�7T�
T�Tc��t�}|r�	t|�\}}|j|�|rp|ddk7rh|d}d|_t|�\}}|j|�|jjtjdj|���|r |jtdd	��|d
d}|r��|S#tj$r�d}|dt
vrt
|�\}}|s|j|�|cYS|ddk(rB|�|j|�|jjtjd��ndt|�\}}|r|g|dd|j|�|jjtjdj|���Y���wxYw)a! parameter *( ";" parameter )

    That BNF is meant to indicate this routine should only be called after
    finding and handling the leading ';'.  There is no corresponding rule in
    the formal RFC grammar, but it is more convenient for us for the set of
    parameters to be treated as its own TokenList.

    This is 'parse' routine because it consumes the remaining value, but it
    would never be called to parse a full header.  Instead it is called to
    parse everything after the non-parameter value of a specific MIME header.

    NrrJzparameter entry with no contentzinvalid parameter {!r}r�rXz)parameter with invalid trailing text {!r}r�r�)rgr�r�rr�rrr!rprjr7r^rKr�)r�mime_parametersrMrr�s     r�parse_mime_parametersr�
s���%�&�O�
�	=�(��/�L�E�5��"�"�5�)�(�U�1�X��_�$�B�'�E�2�E��0��7�L�E�5��L�L����#�#�*�*�6�+E�+E�;�B�B�5�I�,K�
L���"�"�=��6K�#L�M��!�"�I�E�G�H���A�&�&�	=��F��Q�x�;�&� (���
�����&�&�v�.�&�&��Q�x�3���%�#�*�*�6�2��'�'�.�.�v�/I�/I�5�07�8� 5�U�;���u��!'��E�"�1�I��&�&�u�-��'�'�.�.�v�/I�/I�,�3�3�E�:�0<�=��#	=�s�C�AF=�B.F=�<F=c�@�|ra|ddk7rY|dtvr$|jt|dd��|dd}nt|�\}}|j|�|r	|ddk7r�Y|sy|jtdd��|jt	|dd��y)zBDo our best to find the parameters in an invalid MIME header

    rrJr r�Nr�)rr�r�rr�)�	tokenlistrrMs   r�_find_mime_parametersr�K
s����E�!�H��O���8�{�"����]�5��8�5H�I�J��!�"�I�E�%�e�,�L�E�5����U�#�
�E�!�H��O���
���]�3�(=�>�?�
���*�5���9�5�6rc�8�t�}|s0|jjtjd��|S	t|�\}}|j|�|r|ddk7r>|jjtjd��|rt||�|S|jj�j�|_
|jtdd��|dd}	t|�\}}|j|�|jj�j�|_|s|S|dd
k7rO|jjtjdj|���|`
|`t||�|S|jtd
d��|jt!|dd��|S#tj$rN|jjtjdj|���t||�|cYSwxYw#tj$rN|jjtjd	j|���t||�|cYSwxYw)
z� maintype "/" subtype *( ";" parameter )

    The maintype and substype are tokens.  Theoretically they could
    be checked against the official IANA list + x-token, but we
    don't do that.
    z"Missing content type specificationz(Expected content maintype but found {!r}rr�zInvalid content typezcontent-type-separatorr�Nz'Expected content subtype but found {!r}rJz<Only parameters are valid after content type, but found {!r}r�)r�r!r�rrcrsr�rpr7r�rrm�lowerr�r�r�r�)r�ctyperMs   r�parse_content_type_headerr�[
sH��
�M�E��
�
�
���V�>�>�0�2�	3���� ��'���u�
�L�L����E�!�H��O�
�
�
���V�7�7�"�$�	%��!�%��/����[�[�&�&�(�.�.�0�E�N�	�L�L��s�$<�=�>��!�"�I�E�� ��'���u�
�L�L����K�K�%�%�'�-�-�/�E�M�����Q�x�3��
�
�
���V�7�7�
�����(�	)�
�N�E�M��e�U�+���	�L�L��s�$9�:�;�	�L�L�&�u�Q�R�y�1�2��L��Q�"�"��
�
�
���V�7�7�6�=�=�e�D�F�	G��e�U�+���	��&�"�"��
�
�
���V�7�7�5�<�<�U�C�E�	F��e�U�+���	�s%�G�3H8�AH5�4H5�8AJ�Jc��t�}|s0|jjtjd��|S	t|�\}}|j|�|jj�j�|_
|s|S|ddk7rK|jjtjdj|���t||�|S|jtdd��|jt|dd��|S#tj$rN|jjtjdj|���t||�|cYSwxYw)	z* disposition-type *( ";" parameter )

    zMissing content dispositionz+Expected content disposition but found {!r}rrJzCOnly parameters are valid after content disposition, but found {!r}r�r�N)r�r!r�rrcrsr�rpr7r�rrmr�r�r�r�)r�disp_headerrMs   r� parse_content_disposition_headerr��
s]��%�&�K�����"�"�6�#D�#D�)�$+�	,���� ��'���u����u��&+�k�k�&7�&7�&9�&?�&?�&A�K�#�����Q�x�3�����"�"�6�#=�#=�
�����$(�	)�	�k�5�1������}�S�*?�@�A����,�U�1�2�Y�7�8����#�"�"�����"�"�6�#=�#=�9�@�@��G�$I�	J��k�5�1���	�s�D�AE<�;E<c���t�}|s0|jjtjd��|S	t|�\}}|j|�|jj�j�|_	|s|S|r|jjtjd��|dtvr$|jt|dd��|dd}nt|�\}}|j|�|r�|S#tj$r@|jjtjdj|���Y��wxYw)z mechanism

    z!Missing content transfer encodingz1Expected content transfer encoding but found {!r}z*Extra text after content transfer encodingrr r�N)r�r!r�rrcrsrrmr�r�r�rpr7rr�r)r�
cte_headerrMs   r�&parse_content_transfer_encoding_headerr��
sM��
)�*�J�����!�!�&�"C�"C�/�#1�	2���5� ��'���u�
	���%� ����*�*�,�2�2�4�
�����
����!�!�&�"<�"<�8�#:�	;���8�{�"����m�E�!�H�6I�J�K��!�"�I�E�%�e�,�L�E�5����e�$�����#�"�"�P����!�!�&�"<�"<�?�F�F�u�M�#O�	P�P�s�D�AE$�#E$c�Z�d}|r&|dr!|ddtvr|dd}|ddd|d<|S)Nr'r�)r�)�lines�wsps  r�_steal_trailing_WSP_if_existsr��
sD��
�C���r��u�R�y��}��3��B�i��m���"�I�c�r�N��b�	��Jrc	��|jxstj}|jrdnd}dg}d}d}d}d}d}	t	dd�}
t|�}|�rL|j
d�}||
ur|dz}�t|�}
|	s;|jd	vrtj|
�}	ntj|
�}		|
j|�|}|jd
k(rt!||||���|	�r|�s|j"s�d}	d}|j$r|j'|��dt)|j*�}|j*|vrHt)|�|t)|d�z
kDrt-|�}|j/|�|dxx|z
cc<��9t1|d�st|�|z}d}	��W|j"r;|�||k7r|dk(s
|dk(r|dk7rd}t3|
||||j4||�}d}|}d}	���d}d}	t)|
�|t)|d�z
kr|dxx|
z
cc<���d}|j$r~t)|
�dz|krmt-|�}|s|j7�rP|j/||
z�g}|dD]}|t8vrn|j/|��dj;|�}d}��Zt1|d�s�t|�}|jdk(r?t=dd�g|D�cgc]}t=t?|�d���c}zt=dd�gz}|j"s|dz
}|j/|
�||z}���|j"r|s|jAd|�d}	��t-|�}|s|j7�r|j/||
z�n
|dxx|
z
cc<|r��L|j*j;|�|j*zS#t$r'td
�|jD��rd}nd}d}	Y��,wxYwcc}w)zLReturn string of contents of parse_tree folded according to RFC rules.

    �utf-8rNr'NrF�wrap_as_ew_blockedr�)rEr�c3�PK�|]}t|tj���� y�wr)r3rrxr*s  rr-z%_refold_parse_tree.<locals>.<genexpr>
s%����.�,�q��a��!>�!>�?�,�rC�unknown-8bitTrhrOr�rr�rrE)!�max_line_length�sys�maxsize�utf8r�r�r2rr^�
SPECIALSNL�
isdisjoint�NLSETrrvrDr?�_fold_mime_parametersrGrdrSr�r�r�r�r_�_fold_as_ewrerDr�r1r�r�insert)�
parse_treerP�maxlenrlr��leading_whitespace�last_ew�last_charsetr��
want_encoding�end_ew_not_allowedr|rH�tstrr��encoded_part�newline�whitespace_accumulator�char�newparts�ps                     rrQrQ�
sS��
�
#�
#�
2�s�{�{�F� �+�+�w�:�H�
�D�E����G��L����M�!�"�&:�;�����E�
��y�y��|���%�%��!�#����4�y������"4�4�$.�$9�$9�$�$?� ?�
�%*�$4�$4�T�$:� :�
�	!��K�K��!��G��?�?�/�/�!�$��v�x�@���!3��%�%� %�
����'�'�#'�9�9�F�9�#;�<Q�c�&�.�.�>Q�=Q�#R�L��~�~�\�9��|�,�v��E�"�I��/F�F�&C�E�&J�G�!�L�L��1��b�	�\�1�	� �
�4��*��T�
�U�*�� %�
���#�#��'��|�+�!�^�3�!�W�,��J�1F�"�G�%�d�E�6�7�&*�&=�&=�w�HZ�\��&(�"�&�� %�
���� %�
��t�9���U�2�Y��/�/��"�I���I��
 ��� � ��D�	�A�
��'�3�E�:�G��$�-�-�/�
���W�t�^�,�)+�&�!�"�I�D��3���*�1�1�$�7�&�&(�W�W�-C�%D�"�����t�X�&��D�z�H����"6�6�
#�3��0�1�&�(�&��#�#4�Q�#7��A�&�(�(�#�3��0�1�2��
�%�%�"�a�'�"���� 2�3��u�$�E�����&8�
�L�L��D�!� �M��/��6���d�)�)�+��L�L��4��(�
�"�I���I�K�N�>�>���u�%����6�6��o"�	!��.� �,�,�.�.�(��"�� �M�	!��B(s�:O
�#O=�
,O:�9O:c��|�+|r)tt|d|d|z��}|dd||d<nM|dtvrB|d}|dd}t|d�|k(r|j	t|��|dxx|z
cc<d}|dtvr
|d}|dd}|�t|d�n|}	|dk(rdn|}
t|
�dz}|dz|k\rt
jd	��|�r!|t|d�z
}||z
t|�z
}
|
dkr|j	d
��<t|�dkDr9t|d�dk(r(|r&tj||
��}|dxx|z
cc<d}|d|
}tj||
��}t|�|z
}|dkDr0|dd}tj||
��}t|�|z
}|dkDr�0|dxx|z
cc<|t|�d}d}|r|j	d
�t|d�}	|r��!|dxx|z
cc<|r|	SdS)a�Fold string to_encode into lines as encoded word, combining if allowed.
    Return the new value for last_ew, or None if ew_combine_allowed is False.

    If there is already an encoded word in the last line of lines (indicated by
    a non-None value for last_ew) and ew_combine_allowed is true, decode the
    existing ew, combine it with to_encode, and re-encode.  Otherwise, encode
    to_encode.  In either case, split to_encode as necessary so that the
    encoded segments fit within maxlen.

    Nr�rr�r'rNr��z3max_line_length is too small to fit an encoded wordrm)r�)
rr�r�r�r�r�rr�r�r)�	to_encoder�r�r�rer�r��leading_wsp�trailing_wsp�new_last_ew�	encode_as�
chrome_len�remaining_space�
text_space�encoded_word�to_encode_word�excesss                 rr�r��sd����1���U�2�Y�w�x�0�9�<�=�?�	��"�I�h�w�'��b�	�	�1���	� ��l���a�b�M�	���b�	�N�f�$��L�L�6�u�=�>�
�b�	�[� �	��L���}��� ��}���c�r�N�	�$+�O�#�e�B�i�.��K�"�j�0��g�I��Y��!�#�J��Q��6�!��%�%�A�C�	C�� �3�u�R�y�>�1��$�z�1�C�8J�4K�K�
���?��L�L�����u�:��>�c�%��)�n��1�6H��:�:�&8�)�L�L��"�I��%�I�!#��"�;�J�/���z�z�.�)�D���\�"�_�4���q�j�,�C�R�0�N��:�:�n�i�H�L���&��8�F��q�j�	�b�	�\�!�	��c�.�1�2�3�	�����L�L����e�B�i�.�K�?�@
�"�I���I�,�;�6�$�6rc	��|jD�]�\}}|dj�jd�s
|dxxdz
cc<|}d}	|j|�d}|r6tjj|d	|�
�}	dj|||	�}
ndj|t|��}
t|d�t|
�zd
z|kr|ddz|
z|d<��t|
�dz|kr|jd|
z���d}|dz}|s��t|�tt|��zdzt|�z}
||
dzkrd}||
z
dz
x}}	|d|}tjj|d	|�
�}	t|	�|krn|d
z}�<|jdj||||	��d	}|d
z
}||d}|r
|dxxdz
cc<|r�����y#t$r"d}tj|�rd}d}nd}Y���wxYw)a>Fold TokenList 'part' into the 'lines' list as mime parameters.

    Using the decoded list of parameters and values, format them according to
    the RFC rules, including using RFC2231 encoding if the value cannot be
    expressed in 'encoding' and/or the parameter+value is too long to fit
    within 'maxlen'.

    r�rJ�strictFTr�rkr�r')�saferz
{}*={}''{}r�r�rmr�rz''r#�NNz {}*{}*={}{})rzr%r^rrvrrwrqrrr�r7rr�r�r)rHr�r�rlr{rr��
error_handler�encoding_required�
encoded_valuer�rb�extra_chromer��
splitpoint�maxchars�partials                 rr�r��sA���{�{���e��R�y���!�*�*�3�/��"�I���I��� �
�		"��L�L��"� %���"�L�L�.�.��B�}�/�6�M��&�&�t�W�m�D�D��>�>�$��U�(;�<�D��u�R�y�>�C��I�%��)�F�2��b�	�C��$�.�E�"�I��
��Y��]�f�
$��L�L��t��$������~����T��S��W��%6�6��:�S��=N�N�J���a��'�
��$*�Z�$7�!�$;�;�J������,�� &��� 2� 2��"�]�!3�!<�
��}�%��1���a��
�
�
�L�L��.�.��g�|�]�<�
=��L��q�L�G��*�+�&�E���b�	�S� �	�-�I#��"�	"� $���$�$�U�+�(�� 1�
�!���
	"�s�G�'G>�=G>)r�)�r��rer�rq�stringr�operatorr�emailrr�rrr)r�rrrr*r�	TSPECIALSrq�	ASPECIALSryr�r�r�rr�compile�VERBOSE�	MULTILINEr�r�rrjrvrzr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr
rrrrr r.r0r8rBrHrLrWrZrardrgr�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r<r3rGrdr4r7r1rr�r��matchr��findallr�rmrur~r�r�r�r�r�r�r�r�r�r�rrrrrrrrrr#r(r+r-r0r6r;r=r@rErHrLrOrQrSrVrYr\r`rgrjrnrsrwr{rr�r�r�r�r�r�r�r�r�r�rQr�r�rnrr�<module>r�s5��C�J
�
�
���'���
�%�j���C��H�n���� ���s�N�	��C��H�$�
���U��#��
��E�
�
"�c�#�h�.�	�
��_�
���E�
�"�	��S���(�3�s�8�3��	
�t���
��
�
�@�
��"�*�*���Z�Z�"�,�,�� ��@,��@,�FD�)�D� �I� ��Y���9���"���9���I��
�)��#�9�#�6	-�|�	-��!��4C�)�C�&%�i�%�2?�)�?�%�	�%�"$�I�$�*"�y�"�6�	��DD�y�D�!�i�!�6;�Y�;�.�Y�.��i���)��
�I��
�y��B�9��-!�&�-!�`!�	�!�H
�I�
� �)���	��8%�y�%�
#�	�#��i���I��S.�Y�S.�l�y���*���1���i���)��
*�I�*����&�y�&��Y��(+�s�(+�V����H���-��<�f�-�-�<��C�����c�#3�4�
�#�
�� %�
��$�S�*B�C��.��
�
�:�,�,�R�W�W�S�\�:�;�A�A�
�"��
�
�9�#3�#3�
�B�I�I�b�g�g�i� �!�$#�$�$)�E��"��
�
�#5�6�>�>��#����I�$4�$4�
�B�I�I�b�g�g�j�!�"�%$�%�%*�U��'�R�Z�Z�	�(8�(8�
�B�I�I�b�g�g�n�%�&�)(�)�).���&0�b�j�j��1A�1A�
�B�I�I�b�g�g�-�.�/�21�'2�27�%�$�;�J�<
�/�bA�F�"
�� ))�V�2� �$�6 �&�2 �D$�L%�N2!�h�(�%!�N$�L� ) �V,�\�"�H�*"�$6�r#�J�<�:4�n&�,B�J�8B�H$�$�&�.�&�.�$�,�<�,K�Z2�h7� 6�p�<�^�Y7�vJ7�XI!r__pycache__/_parseaddr.cpython-312.opt-1.pyc000064400000055317151706203560014542 0ustar00�

T��h�E���dZgd�ZddlZddlZdZdZdZgd�Zgd�Zddddd	d
dd	ddd
ddd
d�Z	d�Z
d�Zd�Zd�Z
d�ZGd�d�ZGd�de�Zy)zcEmail address parsing code.

Lifted directly from rfc822.py.  This should eventually be rewritten.
)�	mktime_tz�	parsedate�parsedate_tz�quote�N� �z, )�jan�feb�mar�apr�may�jun�jul�aug�sep�oct�nov�dec�january�february�march�aprilr
�june�july�august�	september�october�november�december)�mon�tue�wed�thu�fri�sat�sunip���i���i���i����iD���i��)�UT�UTC�GMT�Z�AST�ADT�EST�EDT�CST�CDT�MST�MDT�PST�PDTc�H�t|�}|sy|d�d|d<t|�S)zQConvert a date string to a time tuple.

    Accounts for military timezones.
    N�	r)�
_parsedate_tz�tuple)�data�ress  �)/usr/lib64/python3.12/email/_parseaddr.pyrr-s0��
��
�C���
�1�v�~���A����:��c
��|sy|j�}|sy|djd�s|dj�tvr|d=n'|dj	d�}|dk\r|d|dzd|d<t|�dk(r*|djd�}t|�dk(r||ddz}t|�dk(rP|d}|j
d�}|d	k(r|j
d�}|dkDr|d|||dg|ddn|jd
�t|�dkry|dd}|\}}}}}|r|r|sy|j�}|tvr||j�}}|tvrytj|�dz}|dkDr|dz}|d	dk(r|dd	}|j
d
�}|dkDr||}}|d	dk(r|dd	}|sy|dj�s||}}|d	dk(r|dd	}|jd
�}t|�dk(r|\}	}
d}nkt|�dk(r|\}	}
}nVt|�dk(rGd|dvr@|djd�}t|�dk(r|\}	}
d}nt|�dk(r|\}	}
}nyy	t|�}t|�}t|	�}	t|
�}
t|�}|dkr|dkDr|dz
}n|dz
}d}|j�}|tvr
t|}n$	t|�}|dk(r|jd�rd}|r!|dkrd	}
|}nd}
|
|dzdz|dzdzzz}||||	|
|ddd	|g
S#t$rYywxYw#t$rY�awxYw)a�Convert date to extended time tuple.

    The last (additional) element is the time zone offset in seconds, except if
    the timezone was specified as -0000.  In that case the last element is
    None.  This indicates a UTC timestamp that explicitly declaims knowledge of
    the source timezone, as opposed to a +0000 timestamp that indicates the
    source timezone really was UTC.

    Nr�,���-��+���r���:��0�.�d�Dili�i�<)�split�endswith�lower�	_daynames�rfind�len�find�append�_monthnames�index�isdigit�int�
ValueError�upper�
_timezones�
startswith)r9�i�stuff�s�dd�mm�yy�tm�tz�thh�tmm�tss�tzoffset�tzsigns              r;r7r79s������:�:�<�D����A�w������Q��
�
��9� <���G���G�M�M�#�����6��1�g�a��c�d�m�D��G�
�4�y�A�~��Q��
�
�c�"���u�:��?��4���8�#�D�
�4�y�A�~���G��
�F�F�3�K����7����s��A��q�5��"�1��q���u�~�D���H��K�K��O�
�4�y�1�}�����8�D���R��R��R��2�"��	����B�	����R�X�X�Z�B��
�[� ��	�	�	�2�	��	"�B�	�B�w�
�b���	�"�v��}�
���W��
�����A��1�u��R�B��	�"�v��}�
���W����
�a�5�=�=�?��R�B��	�"�v��}�
���W��	���#��B�
�2�w�!�|��
��c���	�R��A�����c�3�	�R��A��#��A��,�
��U�[�[��
���r�7�a�<��J�S�#��C�
��W��\� �O�S�#�s����
��W��
��W���#�h���#�h���#�h��
�C�x�
��7��$�J�B�
�$�J�B��H�	����B�	�Z���b�>��	��2�w�H��Q�;�2�=�=��-��H���a�<��F� �y�H��F��x��}�d�2�h��n�b�5H�H�I����B��S�#�q�!�R��:�:��E�����*�	��	�s$�+7L.�L=�.	L:�9L:�=	M	�M	c�F�t|�}t|t�r|ddS|S)z&Convert a time string to a time tuple.Nr6)r�
isinstancer8�r9�ts  r;rr�s&���T��A��!�U����!�u���r<c�|�|d�tj|dddz�Stj|�}||dz
S)zETurn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp.r6N�)rD)�time�mktime�calendar�timegmrms  r;rr�sA���A�w���{�{�4���8�e�+�,�,��O�O�D�!���4��7�{�r<c�F�|jdd�jdd�S)z�Prepare string to be used in a quoted string.

    Turns backslash and double quote characters into quoted pairs.  These
    are the only characters that need to be quoted inside a quoted string.
    Does not add the surrounding double quotes.
    �\z\\�"z\")�replace)�strs r;rr�s"���;�;�t�V�$�,�,�S�%�8�8r<c�b�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
dd	�Zd
�Zd�Z
d�Zdd�Zd�Zy
)�
AddrlistClassaAddress parser class by Ben Escoto.

    To understand what this class does, it helps to have a copy of RFC 2822 in
    front of you.

    Note: this class interface is deprecated and may be removed in the future.
    Use email.utils.AddressList instead.
    c�,�d|_d|_d|_d|_|j|jz|_|j|jz|jz|_|j
j
dd�|_||_g|_	y)z�Initialize a new instance.

        `field' is an unparsed address header field, containing
        one or more addresses.
        z()<>@,:;."[]rz 	z
rJrN)
�specials�pos�LWS�CR�FWS�atomendsrx�
phraseends�field�commentlist��selfr�s  r;�__init__zAddrlistClass.__init__�sz��(��
�����������8�8�d�g�g�%����
�
����0�4�7�7�:��
��-�-�/�/��R�8�����
���r<c�J�g}|jt|j�kr�|j|j|jdzvrY|j|jdvr(|j	|j|j�|xjdz
c_nG|j|jdk(r*|j
j	|j
��nn#|jt|j�kr��tj|�S)z&Skip white space and extract comments.z

r?�()	r~rSr�rrUr��
getcomment�EMPTYSTRING�join)r��wslists  r;�gotonextzAddrlistClass.gotonext�s������h�h��T�Z�Z��(��z�z�$�(�(�#�t�x�x�&�'8�8��:�:�d�h�h�'�v�5��M�M�$�*�*�T�X�X�"6�7����A�
�����D�H�H�%��,�� � �'�'����(9�:���h�h��T�Z�Z��(�����'�'r<c���g}|jt|j�krL|j�}|r||z
}n|j	d�|jt|j�kr�L|S)zVParse all addresses.

        Returns a list containing all of the addresses.
        )rr)r~rSr��
getaddressrU)r��result�ads   r;�getaddrlistzAddrlistClass.getaddrlist�s^��
���h�h��T�Z�Z��(����"�B���"����
�
�h�'��h�h��T�Z�Z��(��
r<c��g|_|j�|j}|j}|j�}|j�g}|jt	|j
�k\r*|�rftj|j�|dfg}�n?|j
|jdvrB||_||_|j�}tj|j�|fg}�n�|j
|jdk(r�g}t	|j
�}|xjdz
c_|jt	|j
�k�rw|j�|j|kr3|j
|jdk(r|xjdz
c_�n%||j�z}|jt	|j
�kr��n�|j
|jdk(rp|j�}|jr;tj|�dzdj|j�zd	z|fg}n{tj|�|fg}nb|r&tj|j�|dfg}n:|j
|j|jvr|xjdz
c_|j�|jt	|j
�kr1|j
|jd
k(r|xjdz
c_|S)zParse the next address.rz.@rGr?�;�<z (r�)r>)r�r�r~�
getphraselistrSr��SPACEr��getaddrspecr��getrouteaddrr})r��oldpos�oldcl�plist�
returnlist�addrspec�fieldlen�	routeaddrs        r;r�zAddrlistClass.getaddresss�������
�
������� � ���"�"�$���
�
���
��8�8�s�4�:�:��&��$�z�z�$�*:�*:�;�U�1�X�F�G�
�
�Z�Z����
!�T�
)��D�H�$�D���'�'�)�H� �:�:�d�&6�&6�7��B�C�J�
�Z�Z����
!�S�
(��J��4�:�:��H��H�H��M�H��(�(�S����_�,��
�
���8�8�h�&�4�:�:�d�h�h�+?�3�+F��H�H��M�H��'�$�/�/�*;�;�
��(�(�S����_�,��Z�Z����
!�S�
(��)�)�+�I����$�z�z�%�0�4�7�"�x�x��(8�(8�9� :�<?� @�AJ�L�M�
� %�z�z�%�0�)�<�=�
��$�z�z�$�*:�*:�;�U�1�X�F�G�
����D�H�H�%����6����A�
���
�
���8�8�c�$�*�*�o�%�$�*�*�T�X�X�*>�#�*E��H�H��M�H��r<c���|j|jdk7ryd}|xjdz
c_|j�d}|jt|j�k�r|r|j	�d}n�|j|jdk(r|xjdz
c_	|S|j|jdk(r|xjdz
c_d}nZ|j|jd	k(r|xjdz
c_n(|j�}|xjdz
c_	|S|j�|jt|j�kr��|S)
z�Parse a route address (Return-path value).

        This method just skips all the route stuff and returns the addrspec.
        r�NFr?r�>�@TrG)r�r~r�rS�	getdomainr�)r��expectroute�adlists   r;r�zAddrlistClass.getrouteaddrGs&��
�:�:�d�h�h��3�&�������A�
���
�
�����h�h��T�Z�Z��(����� �#�����D�H�H�%��,����A�
����
����D�H�H�%��,����A�
��"�����D�H�H�%��,����A�
���)�)�+�����A�
����
�
�M�M�O�!�h�h��T�Z�Z��(�$�
r<c��g}|j�|jt|j�k�rgd}|j|jdk(rN|r#|dj	�s|j�|j
d�|xjdz
c_d}n�|j|jdk(r,|j
dt|j��z�nj|j|j|jvr&|r#|dj	�s|j�nh|j
|j��|j�}|r|r|j
|�|jt|j�kr��g|jt|j�k\s|j|jdk7rtj|�S|j
d�|xjdz
c_|j�|j�}|stStj|�|zS)	zParse an RFC 2822 addr-spec.TrJrDr?Frwz"%s"r�)r�r~rSr��strip�poprUr�getquoter��getatomr�r�r�)r��aslist�preserve_ws�ws�domains     r;r�zAddrlistClass.getaddrspecgs������
�
���h�h��T�Z�Z��(��K��z�z�$�(�(�#�s�*��&��*�"2�"2�"4��J�J�L��
�
�c�"����A�
��#�����D�H�H�%��,��
�
�f�u�T�]�]�_�'=�=�>����D�H�H�%����6��&��*�"2�"2�"4��J�J�L���
�
�d�l�l�n�-�����B��r��
�
�b�!�%�h�h��T�Z�Z��(�(�8�8�s�4�:�:��&�$�*�*�T�X�X�*>�#�*E��#�#�F�+�+��
�
�c�����A�
���
�
�����!���������'�&�0�0r<c��g}|jt|j�k�r�|j|j|jvr|xjdz
c_�n,|j|jdk(r*|jj|j
��n�|j|jdk(r |j|j��n�|j|jdk(r'|xjdz
c_|jd�ng|j|jdk(rtS|j|j|jvrnC|j|j��|jt|j�kr���tj|�S)z-Get the complete domain name from an address.r?r��[rJr�)r~rSr�rr�rUr��getdomainliteralr�r�r�r�)r��sdlists  r;r�zAddrlistClass.getdomain�s=�����h�h��T�Z�Z��(��z�z�$�(�(�#�t�x�x�/����A�
�����D�H�H�%��,�� � �'�'����(9�:����D�H�H�%��,��
�
�d�3�3�5�6����D�H�H�%��,����A�
���
�
�c�"����D�H�H�%��,�#�"����D�H�H�%����6���
�
�d�l�l�n�-�#�h�h��T�Z�Z��(�$����'�'r<c��|j|j|k7rydg}d}|xjdz
c_|jt|j�k�r|r+|j|j|j�d}n�|j|j|vr|xjdz
c_n�|r<|j|jdk(r |j|j	����|j|jdk(rd}n(|j|j|j�|xjdz
c_|jt|j�kr��t
j
|�S)a�Parse a header fragment delimited by special characters.

        `beginchar' is the start character for the fragment.
        If self is not looking at an instance of `beginchar' then
        getdelimited returns the empty string.

        `endchars' is a sequence of allowable end-delimiting characters.
        Parsing stops when one of these is encountered.

        If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed
        within the parsed fragment.
        rFr?r�rvT)r�r~rSrUr�r�r�)r��	beginchar�endchars�
allowcomments�slistrs      r;�getdelimitedzAddrlistClass.getdelimited�s%���:�:�d�h�h��9�,����������A�
���h�h��T�Z�Z��(�����T�Z�Z����1�2������D�H�H�%��1����A�
����4�:�:�d�h�h�#7�3�#>����T�_�_�.�/�����D�H�H�%��-������T�Z�Z����1�2��H�H��M�H��h�h��T�Z�Z��(� ����&�&r<c�(�|jddd�S)z1Get a quote-delimited fragment from self's field.rwz"
F�r��r�s r;r�zAddrlistClass.getquote�s��� � ��e�U�3�3r<c�(�|jddd�S)z7Get a parenthesis-delimited fragment from self's field.r�z)
Tr�r�s r;r�zAddrlistClass.getcomment�s��� � ��e�T�2�2r<c�.�d|jddd�zS)z!Parse an RFC 2822 domain-literal.z[%s]r�z]
Fr�r�s r;r�zAddrlistClass.getdomainliteral�s����)�)�#�u�e�<�<�<r<Nc��dg}|�|j}|jt|j�kr||j|j|vrn`|j	|j|j�|xjdz
c_|jt|j�kr�|t
j
|�S)aParse an RFC 2822 atom.

        Optional atomends specifies a different set of end token delimiters
        (the default is to use self.atomends).  This is used e.g. in
        getphraselist() since phrase endings must not include the `.' (which
        is legal in phrases).rr?)r�r~rSr�rUr�r�)r�r��atomlists   r;r�zAddrlistClass.getatom�s����4�����}�}�H��h�h��T�Z�Z��(��z�z�$�(�(�#�x�/������
�
�4�8�8� 4�5��H�H��M�H��h�h��T�Z�Z��(�����)�)r<c��g}|jt|j�k�r3|j|j|jvr|xjdz
c_n�|j|jdk(r |j	|j��n�|j|jdk(r*|jj	|j��nR|j|j|jvr	|S|j	|j|j��|jt|j�kr��3|S)z�Parse a sequence of RFC 2822 phrases.

        A phrase is a sequence of words, which are in turn either RFC 2822
        atoms or quoted-strings.  Phrases are canonicalized by squeezing all
        runs of continuous whitespace into one space.
        r?rwr�)
r~rSr�r�rUr�r�r�r�r�)r�r�s  r;r�zAddrlistClass.getphraselist�s������h�h��T�Z�Z��(��z�z�$�(�(�#�t�x�x�/����A�
�����D�H�H�%��,����T�]�]�_�-����D�H�H�%��,�� � �'�'����(9�:����D�H�H�%����8�������T�\�\�$�/�/�:�;��h�h��T�Z�Z��(��r<)T�N)�__name__�
__module__�__qualname__�__doc__r�r�r�r�r�r�r�r�r�r�r�r�r��r<r;r{r{�sL����&(��9�v�@$1�L(�.#'�J4�3�=�*�(r<r{c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�AddressListz@An AddressList encapsulates a list of parsed RFC 2822 addresses.c�n�tj||�|r|j�|_yg|_yr�)r{r�r��addresslistr�s  r;r�zAddressList.__init__s.�����t�U�+��#�/�/�1�D��!�D�r<c�,�t|j�Sr�)rSr�r�s r;�__len__zAddressList.__len__	s���4�#�#�$�$r<c��td�}|jdd|_|jD],}||jvs�|jj|��.|Sr��r�r�rU�r��other�newaddr�xs    r;�__add__zAddressList.__add__sX���d�#��"�.�.�q�1����"�"�A���(�(�(��#�#�*�*�1�-�#��r<c�|�|jD],}||jvs�|jj|��.|Sr�)r�rU�r�r�r�s   r;�__iadd__zAddressList.__iadd__s;���"�"�A���(�(�(�� � �'�'��*�#��r<c��td�}|jD],}||jvs�|jj|��.|Sr�r�r�s    r;�__sub__zAddressList.__sub__sE���d�#���!�!�A���)�)�)��#�#�*�*�1�-�"��r<c�|�|jD],}||jvs�|jj|��.|Sr�)r��remover�s   r;�__isub__zAddressList.__isub__$s;���"�"�A��D�$�$�$�� � �'�'��*�#��r<c� �|j|Sr�)r�)r�rWs  r;�__getitem__zAddressList.__getitem__+s������&�&r<N)r�r�r�r�r�r�r�r�r�r�r�r�r<r;r�r�s(��J�"�%�����'r<r�)r��__all__rqrsr�r��
COMMASPACErVrQr\rr7rrrr{r�r�r<r;�<module>r�s����
�������
�
�I��

>�	��A�Q�A��$��$��$��$��$��
�
�z;�z��9�k�k�Z	-'�-�-'r<__pycache__/_parseaddr.cpython-312.pyc000064400000055317151706203560013603 0ustar00�

T��h�E���dZgd�ZddlZddlZdZdZdZgd�Zgd�Zddddd	d
dd	ddd
ddd
d�Z	d�Z
d�Zd�Zd�Z
d�ZGd�d�ZGd�de�Zy)zcEmail address parsing code.

Lifted directly from rfc822.py.  This should eventually be rewritten.
)�	mktime_tz�	parsedate�parsedate_tz�quote�N� �z, )�jan�feb�mar�apr�may�jun�jul�aug�sep�oct�nov�dec�january�february�march�aprilr
�june�july�august�	september�october�november�december)�mon�tue�wed�thu�fri�sat�sunip���i���i���i����iD���i��)�UT�UTC�GMT�Z�AST�ADT�EST�EDT�CST�CDT�MST�MDT�PST�PDTc�H�t|�}|sy|d�d|d<t|�S)zQConvert a date string to a time tuple.

    Accounts for military timezones.
    N�	r)�
_parsedate_tz�tuple)�data�ress  �)/usr/lib64/python3.12/email/_parseaddr.pyrr-s0��
��
�C���
�1�v�~���A����:��c
��|sy|j�}|sy|djd�s|dj�tvr|d=n'|dj	d�}|dk\r|d|dzd|d<t|�dk(r*|djd�}t|�dk(r||ddz}t|�dk(rP|d}|j
d�}|d	k(r|j
d�}|dkDr|d|||dg|ddn|jd
�t|�dkry|dd}|\}}}}}|r|r|sy|j�}|tvr||j�}}|tvrytj|�dz}|dkDr|dz}|d	dk(r|dd	}|j
d
�}|dkDr||}}|d	dk(r|dd	}|sy|dj�s||}}|d	dk(r|dd	}|jd
�}t|�dk(r|\}	}
d}nkt|�dk(r|\}	}
}nVt|�dk(rGd|dvr@|djd�}t|�dk(r|\}	}
d}nt|�dk(r|\}	}
}nyy	t|�}t|�}t|	�}	t|
�}
t|�}|dkr|dkDr|dz
}n|dz
}d}|j�}|tvr
t|}n$	t|�}|dk(r|jd�rd}|r!|dkrd	}
|}nd}
|
|dzdz|dzdzzz}||||	|
|ddd	|g
S#t$rYywxYw#t$rY�awxYw)a�Convert date to extended time tuple.

    The last (additional) element is the time zone offset in seconds, except if
    the timezone was specified as -0000.  In that case the last element is
    None.  This indicates a UTC timestamp that explicitly declaims knowledge of
    the source timezone, as opposed to a +0000 timestamp that indicates the
    source timezone really was UTC.

    Nr�,���-��+���r���:��0�.�d�Dili�i�<)�split�endswith�lower�	_daynames�rfind�len�find�append�_monthnames�index�isdigit�int�
ValueError�upper�
_timezones�
startswith)r9�i�stuff�s�dd�mm�yy�tm�tz�thh�tmm�tss�tzoffset�tzsigns              r;r7r79s������:�:�<�D����A�w������Q��
�
��9� <���G���G�M�M�#�����6��1�g�a��c�d�m�D��G�
�4�y�A�~��Q��
�
�c�"���u�:��?��4���8�#�D�
�4�y�A�~���G��
�F�F�3�K����7����s��A��q�5��"�1��q���u�~�D���H��K�K��O�
�4�y�1�}�����8�D���R��R��R��2�"��	����B�	����R�X�X�Z�B��
�[� ��	�	�	�2�	��	"�B�	�B�w�
�b���	�"�v��}�
���W��
�����A��1�u��R�B��	�"�v��}�
���W����
�a�5�=�=�?��R�B��	�"�v��}�
���W��	���#��B�
�2�w�!�|��
��c���	�R��A�����c�3�	�R��A��#��A��,�
��U�[�[��
���r�7�a�<��J�S�#��C�
��W��\� �O�S�#�s����
��W��
��W���#�h���#�h���#�h��
�C�x�
��7��$�J�B�
�$�J�B��H�	����B�	�Z���b�>��	��2�w�H��Q�;�2�=�=��-��H���a�<��F� �y�H��F��x��}�d�2�h��n�b�5H�H�I����B��S�#�q�!�R��:�:��E�����*�	��	�s$�+7L.�L=�.	L:�9L:�=	M	�M	c�F�t|�}t|t�r|ddS|S)z&Convert a time string to a time tuple.Nr6)r�
isinstancer8�r9�ts  r;rr�s&���T��A��!�U����!�u���r<c�|�|d�tj|dddz�Stj|�}||dz
S)zETurn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp.r6N�)rD)�time�mktime�calendar�timegmrms  r;rr�sA���A�w���{�{�4���8�e�+�,�,��O�O�D�!���4��7�{�r<c�F�|jdd�jdd�S)z�Prepare string to be used in a quoted string.

    Turns backslash and double quote characters into quoted pairs.  These
    are the only characters that need to be quoted inside a quoted string.
    Does not add the surrounding double quotes.
    �\z\\�"z\")�replace)�strs r;rr�s"���;�;�t�V�$�,�,�S�%�8�8r<c�b�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
dd	�Zd
�Zd�Z
d�Zdd�Zd�Zy
)�
AddrlistClassaAddress parser class by Ben Escoto.

    To understand what this class does, it helps to have a copy of RFC 2822 in
    front of you.

    Note: this class interface is deprecated and may be removed in the future.
    Use email.utils.AddressList instead.
    c�,�d|_d|_d|_d|_|j|jz|_|j|jz|jz|_|j
j
dd�|_||_g|_	y)z�Initialize a new instance.

        `field' is an unparsed address header field, containing
        one or more addresses.
        z()<>@,:;."[]rz 	z
rJrN)
�specials�pos�LWS�CR�FWS�atomendsrx�
phraseends�field�commentlist��selfr�s  r;�__init__zAddrlistClass.__init__�sz��(��
�����������8�8�d�g�g�%����
�
����0�4�7�7�:��
��-�-�/�/��R�8�����
���r<c�J�g}|jt|j�kr�|j|j|jdzvrY|j|jdvr(|j	|j|j�|xjdz
c_nG|j|jdk(r*|j
j	|j
��nn#|jt|j�kr��tj|�S)z&Skip white space and extract comments.z

r?�()	r~rSr�rrUr��
getcomment�EMPTYSTRING�join)r��wslists  r;�gotonextzAddrlistClass.gotonext�s������h�h��T�Z�Z��(��z�z�$�(�(�#�t�x�x�&�'8�8��:�:�d�h�h�'�v�5��M�M�$�*�*�T�X�X�"6�7����A�
�����D�H�H�%��,�� � �'�'����(9�:���h�h��T�Z�Z��(�����'�'r<c���g}|jt|j�krL|j�}|r||z
}n|j	d�|jt|j�kr�L|S)zVParse all addresses.

        Returns a list containing all of the addresses.
        )rr)r~rSr��
getaddressrU)r��result�ads   r;�getaddrlistzAddrlistClass.getaddrlist�s^��
���h�h��T�Z�Z��(����"�B���"����
�
�h�'��h�h��T�Z�Z��(��
r<c��g|_|j�|j}|j}|j�}|j�g}|jt	|j
�k\r*|�rftj|j�|dfg}�n?|j
|jdvrB||_||_|j�}tj|j�|fg}�n�|j
|jdk(r�g}t	|j
�}|xjdz
c_|jt	|j
�k�rw|j�|j|kr3|j
|jdk(r|xjdz
c_�n%||j�z}|jt	|j
�kr��n�|j
|jdk(rp|j�}|jr;tj|�dzdj|j�zd	z|fg}n{tj|�|fg}nb|r&tj|j�|dfg}n:|j
|j|jvr|xjdz
c_|j�|jt	|j
�kr1|j
|jd
k(r|xjdz
c_|S)zParse the next address.rz.@rGr?�;�<z (r�)r>)r�r�r~�
getphraselistrSr��SPACEr��getaddrspecr��getrouteaddrr})r��oldpos�oldcl�plist�
returnlist�addrspec�fieldlen�	routeaddrs        r;r�zAddrlistClass.getaddresss�������
�
������� � ���"�"�$���
�
���
��8�8�s�4�:�:��&��$�z�z�$�*:�*:�;�U�1�X�F�G�
�
�Z�Z����
!�T�
)��D�H�$�D���'�'�)�H� �:�:�d�&6�&6�7��B�C�J�
�Z�Z����
!�S�
(��J��4�:�:��H��H�H��M�H��(�(�S����_�,��
�
���8�8�h�&�4�:�:�d�h�h�+?�3�+F��H�H��M�H��'�$�/�/�*;�;�
��(�(�S����_�,��Z�Z����
!�S�
(��)�)�+�I����$�z�z�%�0�4�7�"�x�x��(8�(8�9� :�<?� @�AJ�L�M�
� %�z�z�%�0�)�<�=�
��$�z�z�$�*:�*:�;�U�1�X�F�G�
����D�H�H�%����6����A�
���
�
���8�8�c�$�*�*�o�%�$�*�*�T�X�X�*>�#�*E��H�H��M�H��r<c���|j|jdk7ryd}|xjdz
c_|j�d}|jt|j�k�r|r|j	�d}n�|j|jdk(r|xjdz
c_	|S|j|jdk(r|xjdz
c_d}nZ|j|jd	k(r|xjdz
c_n(|j�}|xjdz
c_	|S|j�|jt|j�kr��|S)
z�Parse a route address (Return-path value).

        This method just skips all the route stuff and returns the addrspec.
        r�NFr?r�>�@TrG)r�r~r�rS�	getdomainr�)r��expectroute�adlists   r;r�zAddrlistClass.getrouteaddrGs&��
�:�:�d�h�h��3�&�������A�
���
�
�����h�h��T�Z�Z��(����� �#�����D�H�H�%��,����A�
����
����D�H�H�%��,����A�
��"�����D�H�H�%��,����A�
���)�)�+�����A�
����
�
�M�M�O�!�h�h��T�Z�Z��(�$�
r<c��g}|j�|jt|j�k�rgd}|j|jdk(rN|r#|dj	�s|j�|j
d�|xjdz
c_d}n�|j|jdk(r,|j
dt|j��z�nj|j|j|jvr&|r#|dj	�s|j�nh|j
|j��|j�}|r|r|j
|�|jt|j�kr��g|jt|j�k\s|j|jdk7rtj|�S|j
d�|xjdz
c_|j�|j�}|stStj|�|zS)	zParse an RFC 2822 addr-spec.TrJrDr?Frwz"%s"r�)r�r~rSr��strip�poprUr�getquoter��getatomr�r�r�)r��aslist�preserve_ws�ws�domains     r;r�zAddrlistClass.getaddrspecgs������
�
���h�h��T�Z�Z��(��K��z�z�$�(�(�#�s�*��&��*�"2�"2�"4��J�J�L��
�
�c�"����A�
��#�����D�H�H�%��,��
�
�f�u�T�]�]�_�'=�=�>����D�H�H�%����6��&��*�"2�"2�"4��J�J�L���
�
�d�l�l�n�-�����B��r��
�
�b�!�%�h�h��T�Z�Z��(�(�8�8�s�4�:�:��&�$�*�*�T�X�X�*>�#�*E��#�#�F�+�+��
�
�c�����A�
���
�
�����!���������'�&�0�0r<c��g}|jt|j�k�r�|j|j|jvr|xjdz
c_�n,|j|jdk(r*|jj|j
��n�|j|jdk(r |j|j��n�|j|jdk(r'|xjdz
c_|jd�ng|j|jdk(rtS|j|j|jvrnC|j|j��|jt|j�kr���tj|�S)z-Get the complete domain name from an address.r?r��[rJr�)r~rSr�rr�rUr��getdomainliteralr�r�r�r�)r��sdlists  r;r�zAddrlistClass.getdomain�s=�����h�h��T�Z�Z��(��z�z�$�(�(�#�t�x�x�/����A�
�����D�H�H�%��,�� � �'�'����(9�:����D�H�H�%��,��
�
�d�3�3�5�6����D�H�H�%��,����A�
���
�
�c�"����D�H�H�%��,�#�"����D�H�H�%����6���
�
�d�l�l�n�-�#�h�h��T�Z�Z��(�$����'�'r<c��|j|j|k7rydg}d}|xjdz
c_|jt|j�k�r|r+|j|j|j�d}n�|j|j|vr|xjdz
c_n�|r<|j|jdk(r |j|j	����|j|jdk(rd}n(|j|j|j�|xjdz
c_|jt|j�kr��t
j
|�S)a�Parse a header fragment delimited by special characters.

        `beginchar' is the start character for the fragment.
        If self is not looking at an instance of `beginchar' then
        getdelimited returns the empty string.

        `endchars' is a sequence of allowable end-delimiting characters.
        Parsing stops when one of these is encountered.

        If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed
        within the parsed fragment.
        rFr?r�rvT)r�r~rSrUr�r�r�)r��	beginchar�endchars�
allowcomments�slistrs      r;�getdelimitedzAddrlistClass.getdelimited�s%���:�:�d�h�h��9�,����������A�
���h�h��T�Z�Z��(�����T�Z�Z����1�2������D�H�H�%��1����A�
����4�:�:�d�h�h�#7�3�#>����T�_�_�.�/�����D�H�H�%��-������T�Z�Z����1�2��H�H��M�H��h�h��T�Z�Z��(� ����&�&r<c�(�|jddd�S)z1Get a quote-delimited fragment from self's field.rwz"
F�r��r�s r;r�zAddrlistClass.getquote�s��� � ��e�U�3�3r<c�(�|jddd�S)z7Get a parenthesis-delimited fragment from self's field.r�z)
Tr�r�s r;r�zAddrlistClass.getcomment�s��� � ��e�T�2�2r<c�.�d|jddd�zS)z!Parse an RFC 2822 domain-literal.z[%s]r�z]
Fr�r�s r;r�zAddrlistClass.getdomainliteral�s����)�)�#�u�e�<�<�<r<Nc��dg}|�|j}|jt|j�kr||j|j|vrn`|j	|j|j�|xjdz
c_|jt|j�kr�|t
j
|�S)aParse an RFC 2822 atom.

        Optional atomends specifies a different set of end token delimiters
        (the default is to use self.atomends).  This is used e.g. in
        getphraselist() since phrase endings must not include the `.' (which
        is legal in phrases).rr?)r�r~rSr�rUr�r�)r�r��atomlists   r;r�zAddrlistClass.getatom�s����4�����}�}�H��h�h��T�Z�Z��(��z�z�$�(�(�#�x�/������
�
�4�8�8� 4�5��H�H��M�H��h�h��T�Z�Z��(�����)�)r<c��g}|jt|j�k�r3|j|j|jvr|xjdz
c_n�|j|jdk(r |j	|j��n�|j|jdk(r*|jj	|j��nR|j|j|jvr	|S|j	|j|j��|jt|j�kr��3|S)z�Parse a sequence of RFC 2822 phrases.

        A phrase is a sequence of words, which are in turn either RFC 2822
        atoms or quoted-strings.  Phrases are canonicalized by squeezing all
        runs of continuous whitespace into one space.
        r?rwr�)
r~rSr�r�rUr�r�r�r�r�)r�r�s  r;r�zAddrlistClass.getphraselist�s������h�h��T�Z�Z��(��z�z�$�(�(�#�t�x�x�/����A�
�����D�H�H�%��,����T�]�]�_�-����D�H�H�%��,�� � �'�'����(9�:����D�H�H�%����8�������T�\�\�$�/�/�:�;��h�h��T�Z�Z��(��r<)T�N)�__name__�
__module__�__qualname__�__doc__r�r�r�r�r�r�r�r�r�r�r�r�r��r<r;r{r{�sL����&(��9�v�@$1�L(�.#'�J4�3�=�*�(r<r{c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�AddressListz@An AddressList encapsulates a list of parsed RFC 2822 addresses.c�n�tj||�|r|j�|_yg|_yr�)r{r�r��addresslistr�s  r;r�zAddressList.__init__s.�����t�U�+��#�/�/�1�D��!�D�r<c�,�t|j�Sr�)rSr�r�s r;�__len__zAddressList.__len__	s���4�#�#�$�$r<c��td�}|jdd|_|jD],}||jvs�|jj|��.|Sr��r�r�rU�r��other�newaddr�xs    r;�__add__zAddressList.__add__sX���d�#��"�.�.�q�1����"�"�A���(�(�(��#�#�*�*�1�-�#��r<c�|�|jD],}||jvs�|jj|��.|Sr�)r�rU�r�r�r�s   r;�__iadd__zAddressList.__iadd__s;���"�"�A���(�(�(�� � �'�'��*�#��r<c��td�}|jD],}||jvs�|jj|��.|Sr�r�r�s    r;�__sub__zAddressList.__sub__sE���d�#���!�!�A���)�)�)��#�#�*�*�1�-�"��r<c�|�|jD],}||jvs�|jj|��.|Sr�)r��remover�s   r;�__isub__zAddressList.__isub__$s;���"�"�A��D�$�$�$�� � �'�'��*�#��r<c� �|j|Sr�)r�)r�rWs  r;�__getitem__zAddressList.__getitem__+s������&�&r<N)r�r�r�r�r�r�r�r�r�r�r�r�r<r;r�r�s(��J�"�%�����'r<r�)r��__all__rqrsr�r��
COMMASPACErVrQr\rr7rrrr{r�r�r<r;�<module>r�s����
�������
�
�I��

>�	��A�Q�A��$��$��$��$��$��
�
�z;�z��9�k�k�Z	-'�-�-'r<__pycache__/_policybase.cpython-312.opt-1.pyc000064400000044314151706203560014722 0ustar00�

T��h�<���dZddlZddlmZddlmZddlmZgd�ZGd�d�Z	d	�Z
d
�ZGd�de	ej�
�Z
eGd�de
��Ze�Zy)zwPolicy framework for the email package.

Allows fine grained feature control of how the package parses and emits data.
�N)�header)�charset)�_has_surrogates)�Policy�Compat32�compat32c�:��eZdZdZ�fd�Zd�Zd�Zd�Zd�Z�xZ	S)�_PolicyBasea�Policy Object basic framework.

    This class is useless unless subclassed.  A subclass should define
    class attributes with defaults for any values that are to be
    managed by the Policy object.  The constructor will then allow
    non-default values to be set for these attributes at instance
    creation time.  The instance will be callable, taking these same
    attributes keyword arguments, and returning a new instance
    identical to the called instance except for those values changed
    by the keyword arguments.  Instances may be added, yielding new
    instances with any non-default values from the right hand
    operand overriding those in the left hand operand.  That is,

        A + B == A(<non-default values of B>)

    The repr of an instance can be used to reconstruct the object
    if and only if the repr of the values can be used to reconstruct
    those values.

    c����|j�D]T\}}t||�rtt|�||��'tdj
||jj���y)z�Create new Policy, possibly overriding some defaults.

        See class docstring for a list of overridable attributes.

        �*{!r} is an invalid keyword argument for {}N)	�items�hasattr�superr
�__setattr__�	TypeError�format�	__class__�__name__)�self�kw�name�valuers    ��*/usr/lib64/python3.12/email/_policybase.py�__init__z_PolicyBase.__init__)s^����8�8�:�K�D�%��t�T�"��k�$�3�D�%�@��@�G�G��d�n�n�5�5�7�8�8�	&�c���|jj�D��cgc]\}}dj||���}}}dj|jjdj|��Scc}}w)Nz{}={!r}z{}({})z, )�__dict__r
rrr�join)rrr�argss    r�__repr__z_PolicyBase.__repr__7sh��$(�M�M�$7�$7�$9�<�$9�[�T�5��!�!�$��.�$9�	
�<����t�~�~�6�6��	�	�$��H�H��<s�A2c��|jj|j�}|jj�D]\}}tj|||��|j�D]W\}}t
||�s/tdj||jj���tj|||��Y|S)z�Return a new instance with specified attributes changed.

        The new instance has the same attribute values as the current object,
        except for the changes passed in as keyword arguments.

        r)
r�__new__rr
�objectrrrrr)rr�	newpolicy�attrrs     r�clonez_PolicyBase.clone<s����N�N�*�*�4�>�>�:�	��=�=�.�.�0�K�D�%����y�$��6�1��8�8�:�K�D�%��4��&��@�G�G��d�n�n�5�5�7�8�8�
���y�$��6�&��rc��t||�rd}nd}t|j|jj|���)Nz'{!r} object attribute {!r} is read-onlyz!{!r} object has no attribute {!r})r�AttributeErrorrrr)rrr�msgs    rrz_PolicyBase.__setattr__Ns6���4���;�C�5�C��S�Z�Z����(?�(?��F�G�Grc�:�|jdi|j��S)z�Non-default values from right operand override those from left.

        The object returned is a new instance of the subclass.

        �)r&r)r�others  r�__add__z_PolicyBase.__add__Us���t�z�z�+�E�N�N�+�+r)
r�
__module__�__qualname__�__doc__rr r&rr-�
__classcell__)rs@rr
r
s#����*8�I�
�$H�,rr
c�f�|jdd�d}|jdd�d}|dz|zS)N�
�r)�rsplit�split)�doc�	added_docs  r�_append_docr9^s;��

�*�*�T�1�
�a�
 �C�����a�(��+�I���:�	�!�!rc���|jrM|jjd�r2t|jdj|j�|_|jj�D]{\}}|js�|jjd�s�/d�|jD�D]7}t
t
||�d�}|s�t||j�|_�{�}|S)N�+rc3�JK�|]}|j�D]}|����y�w)N)�mro)�.0�base�cs   r�	<genexpr>z%_extend_docstrings.<locals>.<genexpr>hs����F�M�D�4�8�8�:�a�a�:�a�M�s�!#r0)r0�
startswithr9�	__bases__rr
�getattr)�clsrr%r@r7s     r�_extend_docstringsrFcs���
�{�{�s�{�{�-�-�c�2�!�#�-�-��"2�":�":�C�K�K�H����l�l�(�(�*�
��d��<�<�D�L�L�3�3�C�8�F�C�M�M�F���g�a��.�	�:���#.�s�D�L�L�#A�D�L��	G�+��Jrc���eZdZdZdZdZdZdZdZdZ	dZ
d�Zd	�Zd
�Z
ejd��Zejd��Zejd
��Zejd��Zejd��Zy)ra�
Controls for how messages are interpreted and formatted.

    Most of the classes and many of the methods in the email package accept
    Policy objects as parameters.  A Policy object contains a set of values and
    functions that control how input is interpreted and how output is rendered.
    For example, the parameter 'raise_on_defect' controls whether or not an RFC
    violation results in an error being raised or not, while 'max_line_length'
    controls the maximum length of output lines when a Message is serialized.

    Any valid attribute may be overridden when a Policy is created by passing
    it as a keyword argument to the constructor.  Policy objects are immutable,
    but a new Policy object can be created with only certain values changed by
    calling the Policy instance with keyword arguments.  Policy objects can
    also be added, producing a new Policy object in which the non-default
    attributes set in the right hand operand overwrite those specified in the
    left operand.

    Settable attributes:

    raise_on_defect     -- If true, then defects should be raised as errors.
                           Default: False.

    linesep             -- string containing the value to use as separation
                           between output lines.  Default '\n'.

    cte_type            -- Type of allowed content transfer encodings

                           7bit  -- ASCII only
                           8bit  -- Content-Transfer-Encoding: 8bit is allowed

                           Default: 8bit.  Also controls the disposition of
                           (RFC invalid) binary data in headers; see the
                           documentation of the binary_fold method.

    max_line_length     -- maximum length of lines, excluding 'linesep',
                           during serialization.  None or 0 means no line
                           wrapping is done.  Default is 78.

    mangle_from_        -- a flag that, when True escapes From_ lines in the
                           body of the message by putting a `>' in front of
                           them. This is used when the message is being
                           serialized by a generator. Default: False.

    message_factory     -- the class to use to create new message objects.
                           If the value is None, the default is Message.

    verify_generated_headers
                        -- if true, the generator verifies that each header
                           they are properly folded, so that a parser won't
                           treat it as multiple headers, start-of-body, or
                           part of another header.
                           This is a check against custom Header & fold()
                           implementations.
    Fr3�8bit�NNTc�D�|jr|�|j||�y)aZBased on policy, either raise defect or call register_defect.

            handle_defect(obj, defect)

        defect should be a Defect subclass, but in any case must be an
        Exception subclass.  obj is the object on which the defect should be
        registered if it is not raised.  If the raise_on_defect is True, the
        defect is raised as an error, otherwise the object and the defect are
        passed to register_defect.

        This method is intended to be called by parsers that discover defects.
        The email package parsers always call it with Defect instances.

        N)�raise_on_defect�register_defect�r�obj�defects   r�
handle_defectzPolicy.handle_defect�s"������L����S�&�)rc�:�|jj|�y)a�Record 'defect' on 'obj'.

        Called by handle_defect if raise_on_defect is False.  This method is
        part of the Policy API so that Policy subclasses can implement custom
        defect handling.  The default implementation calls the append method of
        the defects attribute of obj.  The objects used by the email package by
        default that get passed to this method will always have a defects
        attribute with an append method.

        N)�defects�appendrMs   rrLzPolicy.register_defect�s��	�����6�"rc��y)a[Return the maximum allowed number of headers named 'name'.

        Called when a header is added to a Message object.  If the returned
        value is not 0 or None, and there are already a number of headers with
        the name 'name' equal to the value returned, a ValueError is raised.

        Because the default behavior of Message's __setitem__ is to append the
        value to the list of headers, it is easy to create duplicate headers
        without realizing it.  This method allows certain headers to be limited
        in the number of instances of that header that may be added to a
        Message programmatically.  (The limit is not observed by the parser,
        which will faithfully produce as many headers as exist in the message
        being parsed.)

        The default implementation returns None for all header names.
        Nr+)rrs  r�header_max_countzPolicy.header_max_count�s��"rc��t�)aZGiven a list of linesep terminated strings constituting the lines of
        a single header, return the (name, value) tuple that should be stored
        in the model.  The input lines should retain their terminating linesep
        characters.  The lines passed in by the email package may contain
        surrogateescaped binary data.
        ��NotImplementedError)r�sourceliness  r�header_source_parsezPolicy.header_source_parse��
��"�!rc��t�)z�Given the header name and the value provided by the application
        program, return the (name, value) that should be stored in the model.
        rW�rrrs   r�header_store_parsezPolicy.header_store_parse�s
��
"�!rc��t�)awGiven the header name and the value from the model, return the value
        to be returned to the application program that is requesting that
        header.  The value passed in by the email package may contain
        surrogateescaped binary data if the lines were parsed by a BytesParser.
        The returned value should not contain any surrogateescaped data.

        rWr]s   r�header_fetch_parsezPolicy.header_fetch_parse�s
��"�!rc��t�)a�Given the header name and the value from the model, return a string
        containing linesep characters that implement the folding of the header
        according to the policy controls.  The value passed in by the email
        package may contain surrogateescaped binary data if the lines were
        parsed by a BytesParser.  The returned value should not contain any
        surrogateescaped data.

        rWr]s   r�foldzPolicy.folds
��"�!rc��t�)a%Given the header name and the value from the model, return binary
        data containing linesep characters that implement the folding of the
        header according to the policy controls.  The value passed in by the
        email package may contain surrogateescaped binary data.

        rWr]s   r�fold_binaryzPolicy.fold_binaryr[r)rr.r/r0rK�linesep�cte_type�max_line_length�mangle_from_�message_factory�verify_generated_headersrPrLrU�abc�abstractmethodrZr^r`rbrdr+rrrrps���5�n�O��G��H��O��L��O�#��*�&#��&	���"��"�	���"��"�	���"��"�	���	"��	"�	���"��"rr)�	metaclassc�>�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)rz�+
    This particular policy is the backward compatibility Policy.  It
    replicates the behavior of the email package version 5.1.
    Tc��t|t�s|St|�r&tj|t
j|��S|S)N�r�header_name)�
isinstance�strrr�Header�_charset�UNKNOWN8BITr]s   r�_sanitize_headerzCompat32._sanitize_header!s@���%��%��L��5�!��=�=���0D�0D�-1�3�
3��Lrc��|djdd�\}}dj|g|dd���jd�}||jd�fS)a4+
        The name is parsed as everything up to the ':' and returned unmodified.
        The value is determined by stripping leading whitespace off the
        remainder of the first line joined with all subsequent lines, and
        stripping any trailing carriage return or linefeed characters.

        r�:r4�Nz 	
z
)r6r�lstrip�rstrip)rrYrrs    rrZzCompat32.header_source_parse-sY��"�!�n�*�*�3��2���e�����1��Q�R��1�2�9�9�)�D���e�l�l�6�*�+�+rc�
�||fS)z>+
        The name and value are returned unmodified.
        r+r]s   rr^zCompat32.header_store_parse9s���e�}�rc�&�|j||�S)z�+
        If the value contains binary data, it is converted into a Header object
        using the unknown-8bit charset.  Otherwise it is returned unmodified.
        )rwr]s   rr`zCompat32.header_fetch_parse?s��
�$�$�T�5�1�1rc�*�|j||d��S)a+
        Headers are folded using the Header folding algorithm, which preserves
        existing line breaks in the value, and wraps each resulting line to the
        max_line_length.  Non-ASCII binary data are CTE encoded using the
        unknown-8bit charset.

        T��sanitize)�_foldr]s   rrbz
Compat32.foldFs���z�z�$���z�5�5rc�h�|j|||jdk(��}|jdd�S)a�+
        Headers are folded using the Header folding algorithm, which preserves
        existing line breaks in the value, and wraps each resulting line to the
        max_line_length.  If cte_type is 7bit, non-ascii binary data is CTE
        encoded using the unknown-8bit charset.  Otherwise the original source
        header is used, with its existing line breaks and/or binary data.

        �7bitr��ascii�surrogateescape)r�rf�encode)rrr�foldeds    rrdzCompat32.fold_binaryPs3�����D�%�$�-�-��2G��H���}�}�W�&7�8�8rc��g}|jd|z�t|t�r`t|�r=|r't	j
|tj|��}n.|j|�d}nt	j
||��}n|}|�Fd}|j�|j}|j|j|j|���|j|j�dj|�S)Nz%s: rp)rqr)re�
maxlinelenrz)rSrrrsrrrtrurvrgr�rer)rrrr��parts�hr�s       rr�zCompat32._fold\s�����
���V�d�]�#��e�S�!��u�%���
�
�e�.6�.B�.B�26�8�A��L�L��'��A��M�M�%�T�:���A��=��J��#�#�/�!�1�1�
��L�L����$�,�,�:��N�O�
���T�\�\�"��w�w�u�~�rN)rr.r/r0rhrwrZr^r`rbrdr�r+rrrrs1���
�L�
�
,��2�6�
9�rr)r0rk�emailrrru�email.utilsr�__all__r
r9rF�ABCMetarrrr+rr�<module>r�ss���
��%�'���I,�I,�X"�

�d"�[�C�K�K�d"�N�c�v�c��c�L�:�r__pycache__/base64mime.cpython-312.pyc000064400000007553151706203560013432 0ustar00�

T��h�
��d�dZgd�ZddlmZddlmZmZdZdZdZ	dZ
d	�Zdd
�Zdefd�Z
d
�ZeZeZy)a�Base64 content transfer encoding per RFCs 2045-2047.

This module handles the content transfer encoding method defined in RFC 2045
to encode arbitrary 8-bit data using the three 8-bit bytes in four 7-bit
characters encoding known as Base64.

It is used in the MIME standards for email to attach images, audio, and text
using some 8-bit character sets to messages.

This module provides an interface to encode and decode both headers and bodies
with Base64 encoding.

RFC 2045 defines a method for including character set information in an
`encoded-word' in a header.  This method is commonly used for 8-bit real names
in To:, From:, Cc:, etc. fields, as well as Subject: lines.

This module does not do the line wrapping or end-of-line character conversion
necessary for proper internationalized headers; it only does dumb encoding and
decoding.  To deal with the various line wrapping issues, use the email.header
module.
)�body_decode�body_encode�decode�decodestring�
header_encode�
header_length�)�	b64encode)�
b2a_base64�
a2b_base64z
�
��c�N�tt|�d�\}}|dz}|r|dz
}|S)z6Return the length of s when it is encoded with base64.��)�divmod�len)�	bytearray�groups_of_3�leftover�ns    �)/usr/lib64/python3.12/email/base64mime.pyrr1s1��"�3�y�>�1�5��K���a��A��	�Q����H�c��|syt|t�r|j|�}t|�j	d�}d|�d|�d�S)z�Encode a single header line with Base64 encoding in a given charset.

    charset names the character set to use to encode the header.  It defaults
    to iso-8859-1.  Base64 encoding is defined in RFC 2045.
    r
�asciiz=?z?b?z?=)�
isinstance�str�encoder	r)�header_bytes�charset�encodeds   rrr;sD�����,��$�#�*�*�7�3����%�,�,�W�5�G�#�W�-�-r�Lc�*�|syg}|dzdz}tdt|�|�D]Y}t||||z�jd�}|j	t
�r|t
k7r|dd|z}|j
|��[tj|�S)a1Encode a string with base64.

    Each line will be wrapped at, at most, maxlinelen characters (defaults to
    76 characters).

    Each line of encoded text will end with eol, which defaults to "\n".  Set
    this to "\r\n" if you will be using the result of this function directly
    in an email.
    r
rrrrN���)	�rangerr
r�endswith�NL�append�EMPTYSTRING�join)�s�
maxlinelen�eol�encvec�
max_unencoded�i�encs       rrrIs���
��
�F���N�a�'�M�
�1�c�!�f�m�
,����1�Q��.�/�0�7�7��@���<�<����r�	��c�r�(�S�.�C��
�
�c��
-����F�#�#rc��|s
t�St|t�rt|j	d��St|�S)z�Decode a raw base64 string, returning a bytes object.

    This function does not parse a full MIME header value encoded with
    base64 (like =?iso-8859-1?b?bmloISBuaWgh?=) -- please use the high
    level email.header class for that functionality.
    zraw-unicode-escape)�bytesrrrr)�strings rrrbs8����w��	�F�C�	 ��&�-�-�(<�=�>�>��&�!�!rN)z
iso-8859-1)�__doc__�__all__�base64r	�binasciir
r�CRLFr'r)�MISC_LENrrrrrr�rr�<module>r<sV��
�,���+�
��	����
��
�.�!�b�$�2"� ���r__pycache__/charset.cpython-312.opt-1.pyc000064400000035512151706203560014062 0ustar00�

T��h�B�	��gd�ZddlmZddlZddlZddlmZddlmZdZ	dZ
dZd	Zd
Z
dZdZid
e	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�d
d�de
e
df�de
e
df�de
ddf�de
ddf�e
ddfe
e
dfee
dfd ��Zid!d
�d"d
�d#d�d$d�d%d�d&d�d'd�d(d�d)d�d*d�d+d�d,d�d-d�d.d�d/d�d0d�d1d�dddd2dd3d
d4��Zd5d6dd7�Zdd8�Zd9�Zd:�Zd;�ZGd<�d=�Zy)>)�Charset�	add_alias�add_charset�	add_codec�)�partialN)�errors)�encode_7or8bit�����us-asciizunknown-8bit�z
iso-8859-1z
iso-8859-2z
iso-8859-3z
iso-8859-4z
iso-8859-9ziso-8859-10ziso-8859-13ziso-8859-14ziso-8859-15ziso-8859-16zwindows-1252�viscii)NNN�big5�gb2312zeuc-jp�iso-2022-jp�	shift_jis�utf-8)rzkoi8-rr�latin_1zlatin-1�latin_2zlatin-2�latin_3zlatin-3�latin_4zlatin-4�latin_5zlatin-5�latin_6zlatin-6�latin_7zlatin-7�latin_8zlatin-8�latin_9zks_c_5601-1987zeuc-kr)zlatin-9�latin_10zlatin-10�cp949�euc_jp�euc_kr�ascii�eucgb2312_cn�big5_tw)rrrc�D�|tk(rtd��|||ft|<y)a>Add character set properties to the global registry.

    charset is the input character set, and must be the canonical name of a
    character set.

    Optional header_enc and body_enc is either charset.QP for
    quoted-printable, charset.BASE64 for base64 encoding, charset.SHORTEST for
    the shortest of qp or base64 encoding, or None for no encoding.  SHORTEST
    is only valid for header_enc.  It describes how message headers and
    message bodies in the input charset are to be encoded.  Default is no
    encoding.

    Optional output_charset is the character set that the output should be
    in.  Conversions will proceed from input charset, to Unicode, to the
    output charset when the method Charset.convert() is called.  The default
    is to output in the same character set as the input.

    Both input_charset and output_charset must have Unicode codec entries in
    the module's charset-to-codec mapping; use add_codec(charset, codecname)
    to add codecs the module does not know about.  See the codecs module's
    documentation for more information.
    z!SHORTEST not allowed for body_encN)�SHORTEST�
ValueError�CHARSETS)�charset�
header_enc�body_enc�output_charsets    �&/usr/lib64/python3.12/email/charset.pyrrjs)��.�8���<�=�=�#�X�~�>�H�W��c��|t|<y)z�Add a character set alias.

    alias is the alias name, e.g. latin-1
    canonical is the character set's canonical name, e.g. iso-8859-1
    N)�ALIASES)�alias�	canonicals  r.rr�s
���G�E�Nr/c��|t|<y)a$Add a codec that map characters in the given charset to/from Unicode.

    charset is the canonical name of a character set.  codecname is the name
    of a Python codec, as appropriate for the second argument to the unicode()
    built-in, or to the encode() method of a Unicode string.
    N)�	CODEC_MAP)r*�	codecnames  r.rr�s��#�I�g�r/c�Z�|tk(r|jdd�S|j|�S)Nr#�surrogateescape)�UNKNOWN8BIT�encode)�string�codecs  r.�_encoder=�s+������}�}�W�&7�8�8��}�}�U�#�#r/c�J�eZdZdZefd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
y)ra@	Map character sets to their email properties.

    This class provides information about the requirements imposed on email
    for a specific character set.  It also provides convenience routines for
    converting between character sets, given the availability of the
    applicable codecs.  Given a character set, it will do its best to provide
    information on how to use that character set in an email in an
    RFC-compliant way.

    Certain character sets must be encoded with quoted-printable or base64
    when used in email headers or bodies.  Certain character sets must be
    converted outright, and are not allowed in email.  Instances of this
    module expose the following information about a character set:

    input_charset: The initial character set specified.  Common aliases
                   are converted to their `official' email names (e.g. latin_1
                   is converted to iso-8859-1).  Defaults to 7-bit us-ascii.

    header_encoding: If the character set must be encoded before it can be
                     used in an email header, this attribute will be set to
                     charset.QP (for quoted-printable), charset.BASE64 (for
                     base64 encoding), or charset.SHORTEST for the shortest of
                     QP or BASE64 encoding.  Otherwise, it will be None.

    body_encoding: Same as header_encoding, but describes the encoding for the
                   mail message's body, which indeed may be different than the
                   header encoding.  charset.SHORTEST is not allowed for
                   body_encoding.

    output_charset: Some character sets must be converted before they can be
                    used in email headers or bodies.  If the input_charset is
                    one of them, this attribute will contain the name of the
                    charset output will be converted to.  Otherwise, it will
                    be None.

    input_codec: The name of the Python codec used to convert the
                 input_charset to Unicode.  If no conversion codec is
                 necessary, this attribute will be None.

    output_codec: The name of the Python codec used to convert Unicode
                  to the output_charset.  If no conversion codec is necessary,
                  this attribute will have the same value as the input_codec.
    c��	t|t�r|jd�nt|d�}|j
�}tj||�|_	tj|jttdf�\}}}|s|j}||_
||_tj||�|_t j|j|j�|_t j|j|j�|_y#t$rt	j
|��wxYw)Nr#)�
isinstance�strr:�UnicodeErrorr�CharsetError�lowerr1�get�
input_charsetr)r'�BASE64�header_encoding�
body_encodingr-r5�input_codec�output_codec)�selfrF�henc�benc�convs     r.�__init__zCharset.__init__�s��
	5��-��-��$�$�W�-� #�M�7� ;�
�&�+�+�-�
�$�[�[��
�F���$�<�<��(:�(:�)1�6�4�(@�B���d�D���%�%�D�#���!���%�k�k�$��5���%�=�=��);�);�)-�);�);�=���%�M�M�$�*=�*=�*.�*=�*=�?����)�	5��%�%�m�4�4�	5�s�.D � D?c�6�|jj�S�N)rFrD�rLs r.�__repr__zCharset.__repr__�s���!�!�'�'�)�)r/c�L�t|�t|�j�k(SrR)rArD)rL�others  r.�__eq__zCharset.__eq__�s���4�y�C��J�,�,�.�.�.r/c�^�|jtk(ry|jtk(rytS)aPReturn the content-transfer-encoding used for body encoding.

        This is either the string `quoted-printable' or `base64' depending on
        the encoding used, or it is a function in which case you should call
        the function with a single argument, the Message object being
        encoded.  The function should then set the Content-Transfer-Encoding
        header itself to whatever is appropriate.

        Returns "quoted-printable" if self.body_encoding is QP.
        Returns "base64" if self.body_encoding is BASE64.
        Returns conversion function otherwise.
        zquoted-printable�base64)rI�QPrGr	rSs r.�get_body_encodingzCharset.get_body_encoding�s,������#�%�
�
�
�6�
)��!�!r/c�6�|jxs|jS)z�Return the output character set.

        This is self.output_charset if that is not None, otherwise it is
        self.input_charset.
        )r-rFrSs r.�get_output_charsetzCharset.get_output_charset
s���"�"�8�d�&8�&8�8r/c��|jxsd}t||�}|j|�}|�|S|j||�S)a�Header-encode a string by converting it first to bytes.

        The type of encoding (base64 or quoted-printable) will be based on
        this charset's `header_encoding`.

        :param string: A unicode string for the header.  It must be possible
            to encode this string to bytes using the character set's
            output codec.
        :return: The encoded string, with RFC 2047 chrome.
        r)rKr=�_get_encoder�
header_encode)rLr;r<�header_bytes�encoder_modules     r.r`zCharset.header_encodesN���!�!�/�Z���v�u�-���*�*�<�8���!��M��+�+�L�%�@�@r/c���|jxsd}t||�}|j|�}t|j|��}|j�}t
|�tz}g}	g}
t|�|z
}|D]�}|
j|�tj|
�}
|jt|
|��}||kDs�J|
j�|	s|
s|	jd�n8tj|
�}t||�}|	j||��|g}
t|�|z
}��tj|
�}t||�}|	j||��|	S)afHeader-encode a string by converting it first to bytes.

        This is similar to `header_encode()` except that the string is fit
        into maximum line lengths as given by the argument.

        :param string: A unicode string for the header.  It must be possible
            to encode this string to bytes using the character set's
            output codec.
        :param maxlengths: Maximum line length iterator.  Each element
            returned from this iterator will provide the next maximum line
            length.  This parameter is used as an argument to built-in next()
            and should never be exhausted.  The maximum line lengths should
            not count the RFC 2047 chrome.  These line lengths are only a
            hint; the splitter does the best it can.
        :return: Lines of encoded strings, each with RFC 2047 chrome.
        r)r*N)rKr=r_rr`r]�len�RFC2047_CHROME_LEN�next�append�EMPTYSTRING�join�
header_length�pop)rLr;�
maxlengthsr<rarb�encoderr*�extra�lines�current_line�maxlen�	character�	this_line�length�joined_lines                r.�header_encode_lineszCharset.header_encode_lines%sV��$�!�!�/�Z���v�u�-���*�*�<�8���.�6�6��F���)�)�+���G��1�1�������j�!�E�)���I����	�*�#�(�(��6�I�#�1�1�'�)�W�2M�N�F����� � �"��\��L�L��&�"-�"2�"2�<�"@�K�#*�;��#>�L��L�L���!6�7� )�{���j�)�E�1�� � "�&�&�|�4���{�E�2��
���W�\�*�+��r/c�|�|jtk(rtjS|jtk(rtj
S|jtk(rctjj|�}tj
j|�}||krtjStj
SyrR)rHrG�email�
base64mimerZ�
quoprimimer'rj)rLra�len64�lenqps    r.r_zCharset._get_encoderbs������6�)��#�#�#�
�
!�
!�R�
'��#�#�#�
�
!�
!�X�
-��$�$�2�2�<�@�E��$�$�2�2�<�@�E��u�}��'�'�'��'�'�'�r/c��|s|S|jturJt|t�r|j	|j
�}tjj|�S|jtur[t|t�r|j	|j
�}|jd�}tjj|�St|t�r*|j	|j
�jd�}|S)avBody-encode a string by converting it first to bytes.

        The type of encoding (base64 or quoted-printable) will be based on
        self.body_encoding.  If body_encoding is None, we assume the
        output charset is a 7bit encoding, so re-encoding the decoded
        string using the ascii codec produces the correct string version
        of the content.
        �latin1r#)rIrGr@rAr:r-rxry�body_encoderZ�decoderz)rLr;s  r.rzCharset.body_encodeqs�����M�����'��&�#�&����t�':�':�;���#�#�/�/��7�7�
�
�
�2�
%��&�#�&����t�':�':�;���]�]�8�,�F��#�#�/�/��7�7��&�#�&����t�':�':�;�B�B�7�K���Mr/N)�__name__�
__module__�__qualname__�__doc__�DEFAULT_CHARSETrPrTrWr[r]r`rvr_r�r/r.rr�s=��*�V&5�?�B*�/�"�*9�A�&;�z
�r/r)�__all__�	functoolsr�email.base64mimerx�email.quoprimimer�email.encodersr	rZrGr'rer�r9rhr)r1r5rrrr=rr�r/r.�<module>r�s���
������)�����������������B�r��-���B�r��-���B�r��-�	�
�B�r��-���B�r��-���B�r��-���B�r��-���B�r��-���B�r��-�� �B�r��-�!�"�B�r��-�#�$
�B�r��-�%�&�-�'�(�F�v��-�)�*
�F�v��-�+�,
�F�t�
�6�-�.�F�t�
�6�/�0�t��-��v��-��v�w�/�5��>�
�|��
�|���|���|�	�
�|���|�
��|���|���|���|���}���}���}���}���}�� �}�!�"�}�#�$�������1��<"���

�	�?�8�#�$�l�lr/__pycache__/charset.cpython-312.opt-2.pyc000064400000021320151706203560014053 0ustar00�

T��h�B�	��gd�ZddlmZddlZddlZddlmZddlmZdZ	dZ
dZd	Zd
Z
dZdZid
e	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�d
d�de
e
df�de
e
df�de
ddf�de
ddf�e
ddfe
e
dfee
dfd ��Zid!d
�d"d
�d#d�d$d�d%d�d&d�d'd�d(d�d)d�d*d�d+d�d,d�d-d�d.d�d/d�d0d�d1d�dddd2dd3d
d4��Zd5d6dd7�Zdd8�Zd9�Zd:�Zd;�ZGd<�d=�Zy)>)�Charset�	add_alias�add_charset�	add_codec�)�partialN)�errors)�encode_7or8bit�����us-asciizunknown-8bit�z
iso-8859-1z
iso-8859-2z
iso-8859-3z
iso-8859-4z
iso-8859-9ziso-8859-10ziso-8859-13ziso-8859-14ziso-8859-15ziso-8859-16zwindows-1252�viscii)NNN�big5�gb2312zeuc-jp�iso-2022-jp�	shift_jis�utf-8)rzkoi8-rr�latin_1zlatin-1�latin_2zlatin-2�latin_3zlatin-3�latin_4zlatin-4�latin_5zlatin-5�latin_6zlatin-6�latin_7zlatin-7�latin_8zlatin-8�latin_9zks_c_5601-1987zeuc-kr)zlatin-9�latin_10zlatin-10�cp949�euc_jp�euc_kr�ascii�eucgb2312_cn�big5_tw)rrrc�F�	|tk(rtd��|||ft|<y)Nz!SHORTEST not allowed for body_enc)�SHORTEST�
ValueError�CHARSETS)�charset�
header_enc�body_enc�output_charsets    �&/usr/lib64/python3.12/email/charset.pyrrjs.���,�8���<�=�=�#�X�~�>�H�W��c��	|t|<y�N)�ALIASES)�alias�	canonicals  r.rr�s���
�G�E�Nr/c��	|t|<yr1)�	CODEC_MAP)r*�	codecnames  r.rr�s���#�I�g�r/c�Z�|tk(r|jdd�S|j|�S)Nr#�surrogateescape)�UNKNOWN8BIT�encode)�string�codecs  r.�_encoder>�s+������}�}�W�&7�8�8��}�}�U�#�#r/c�H�eZdZ	efd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zy
)rc��	t|t�r|jd�nt|d�}|j
�}tj||�|_	tj|jttdf�\}}}|s|j}||_
||_tj||�|_t j|j|j�|_t j|j|j�|_y#t$rt	j
|��wxYw)Nr#)�
isinstance�strr;�UnicodeErrorr�CharsetError�lowerr2�get�
input_charsetr)r'�BASE64�header_encoding�
body_encodingr-r6�input_codec�output_codec)�selfrG�henc�benc�convs     r.�__init__zCharset.__init__�s��
	5��-��-��$�$�W�-� #�M�7� ;�
�&�+�+�-�
�$�[�[��
�F���$�<�<��(:�(:�)1�6�4�(@�B���d�D���%�%�D�#���!���%�k�k�$��5���%�=�=��);�);�)-�);�);�=���%�M�M�$�*=�*=�*.�*=�*=�?����)�	5��%�%�m�4�4�	5�s�.D � D?c�6�|jj�Sr1)rGrE�rMs r.�__repr__zCharset.__repr__�s���!�!�'�'�)�)r/c�L�t|�t|�j�k(Sr1)rBrE)rM�others  r.�__eq__zCharset.__eq__�s���4�y�C��J�,�,�.�.�.r/c�`�	|jtk(ry|jtk(rytS)Nzquoted-printable�base64)rJ�QPrHr	rSs r.�get_body_encodingzCharset.get_body_encoding�s1��	�����#�%�
�
�
�6�
)��!�!r/c�8�	|jxs|jSr1)r-rGrSs r.�get_output_charsetzCharset.get_output_charset
s ��	�
�"�"�8�d�&8�&8�8r/c��	|jxsd}t||�}|j|�}|�|S|j||�S)Nr)rLr>�_get_encoder�
header_encode)rMr<r=�header_bytes�encoder_modules     r.r`zCharset.header_encodesS��		��!�!�/�Z���v�u�-���*�*�<�8���!��M��+�+�L�%�@�@r/c���	|jxsd}t||�}|j|�}t|j|��}|j�}t
|�tz}g}	g}
t|�|z
}|D]�}|
j|�tj|
�}
|jt|
|��}||kDs�J|
j�|	s|
s|	jd�n8tj|
�}t||�}|	j||��|g}
t|�|z
}��tj|
�}t||�}|	j||��|	S)Nr)r*)rLr>r_rr`r]�len�RFC2047_CHROME_LEN�next�append�EMPTYSTRING�join�
header_length�pop)rMr<�
maxlengthsr=rarb�encoderr*�extra�lines�current_line�maxlen�	character�	this_line�length�joined_lines                r.�header_encode_lineszCharset.header_encode_lines%s[��	�"�!�!�/�Z���v�u�-���*�*�<�8���.�6�6��F���)�)�+���G��1�1�������j�!�E�)���I����	�*�#�(�(��6�I�#�1�1�'�)�W�2M�N�F����� � �"��\��L�L��&�"-�"2�"2�<�"@�K�#*�;��#>�L��L�L���!6�7� )�{���j�)�E�1�� � "�&�&�|�4���{�E�2��
���W�\�*�+��r/c�|�|jtk(rtjS|jtk(rtj
S|jtk(rctjj|�}tj
j|�}||krtjStj
Syr1)rIrH�email�
base64mimerZ�
quoprimimer'rj)rMra�len64�lenqps    r.r_zCharset._get_encoderbs������6�)��#�#�#�
�
!�
!�R�
'��#�#�#�
�
!�
!�X�
-��$�$�2�2�<�@�E��$�$�2�2�<�@�E��u�}��'�'�'��'�'�'�r/c��	|s|S|jturJt|t�r|j	|j
�}tjj|�S|jtur[t|t�r|j	|j
�}|jd�}tjj|�St|t�r*|j	|j
�jd�}|S)N�latin1r#)rJrHrArBr;r-rxry�body_encoderZ�decoderz)rMr<s  r.rzCharset.body_encodeqs���	���M�����'��&�#�&����t�':�':�;���#�#�/�/��7�7�
�
�
�2�
%��&�#�&����t�':�':�;���]�]�8�,�F��#�#�/�/��7�7��&�#�&����t�':�':�;�B�B�7�K���Mr/N)
�__name__�
__module__�__qualname__�DEFAULT_CHARSETrQrTrWr[r]r`rvr_r�r/r.rr�s=��*�V&5�?�B*�/�"�*9�A�&;�z
�r/r)�__all__�	functoolsr�email.base64mimerx�email.quoprimimer�email.encodersr	rZrHr'rer�r:rhr)r2r6rrrr>rr�r/r.�<module>r�s���
������)�����������������B�r��-���B�r��-���B�r��-�	�
�B�r��-���B�r��-���B�r��-���B�r��-���B�r��-���B�r��-�� �B�r��-�!�"�B�r��-�#�$
�B�r��-�%�&�-�'�(�F�v��-�)�*
�F�v��-�+�,
�F�t�
�6�-�.�F�t�
�6�/�0�t��-��v��-��v�w�/�5��>�
�|��
�|���|���|�	�
�|���|�
��|���|���|���|���}���}���}���}���}�� �}�!�"�}�#�$�������1��<"���

�	�?�8�#�$�l�lr/__pycache__/charset.cpython-312.pyc000064400000035615151706203560013127 0ustar00�

T��h�B�	��gd�ZddlmZddlZddlZddlmZddlmZdZ	dZ
dZd	Zd
Z
dZdZid
e	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�de	e	df�d
d�de
e
df�de
e
df�de
ddf�de
ddf�e
ddfe
e
dfee
dfd ��Zid!d
�d"d
�d#d�d$d�d%d�d&d�d'd�d(d�d)d�d*d�d+d�d,d�d-d�d.d�d/d�d0d�d1d�dddd2dd3d
d4��Zd5d6dd7�Zdd8�Zd9�Zd:�Zd;�ZGd<�d=�Zy)>)�Charset�	add_alias�add_charset�	add_codec�)�partialN)�errors)�encode_7or8bit�����us-asciizunknown-8bit�z
iso-8859-1z
iso-8859-2z
iso-8859-3z
iso-8859-4z
iso-8859-9ziso-8859-10ziso-8859-13ziso-8859-14ziso-8859-15ziso-8859-16zwindows-1252�viscii)NNN�big5�gb2312zeuc-jp�iso-2022-jp�	shift_jis�utf-8)rzkoi8-rr�latin_1zlatin-1�latin_2zlatin-2�latin_3zlatin-3�latin_4zlatin-4�latin_5zlatin-5�latin_6zlatin-6�latin_7zlatin-7�latin_8zlatin-8�latin_9zks_c_5601-1987zeuc-kr)zlatin-9�latin_10zlatin-10�cp949�euc_jp�euc_kr�ascii�eucgb2312_cn�big5_tw)rrrc�D�|tk(rtd��|||ft|<y)a>Add character set properties to the global registry.

    charset is the input character set, and must be the canonical name of a
    character set.

    Optional header_enc and body_enc is either charset.QP for
    quoted-printable, charset.BASE64 for base64 encoding, charset.SHORTEST for
    the shortest of qp or base64 encoding, or None for no encoding.  SHORTEST
    is only valid for header_enc.  It describes how message headers and
    message bodies in the input charset are to be encoded.  Default is no
    encoding.

    Optional output_charset is the character set that the output should be
    in.  Conversions will proceed from input charset, to Unicode, to the
    output charset when the method Charset.convert() is called.  The default
    is to output in the same character set as the input.

    Both input_charset and output_charset must have Unicode codec entries in
    the module's charset-to-codec mapping; use add_codec(charset, codecname)
    to add codecs the module does not know about.  See the codecs module's
    documentation for more information.
    z!SHORTEST not allowed for body_encN)�SHORTEST�
ValueError�CHARSETS)�charset�
header_enc�body_enc�output_charsets    �&/usr/lib64/python3.12/email/charset.pyrrjs)��.�8���<�=�=�#�X�~�>�H�W��c��|t|<y)z�Add a character set alias.

    alias is the alias name, e.g. latin-1
    canonical is the character set's canonical name, e.g. iso-8859-1
    N)�ALIASES)�alias�	canonicals  r.rr�s
���G�E�Nr/c��|t|<y)a$Add a codec that map characters in the given charset to/from Unicode.

    charset is the canonical name of a character set.  codecname is the name
    of a Python codec, as appropriate for the second argument to the unicode()
    built-in, or to the encode() method of a Unicode string.
    N)�	CODEC_MAP)r*�	codecnames  r.rr�s��#�I�g�r/c�Z�|tk(r|jdd�S|j|�S)Nr#�surrogateescape)�UNKNOWN8BIT�encode)�string�codecs  r.�_encoder=�s+������}�}�W�&7�8�8��}�}�U�#�#r/c�J�eZdZdZefd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
y)ra@	Map character sets to their email properties.

    This class provides information about the requirements imposed on email
    for a specific character set.  It also provides convenience routines for
    converting between character sets, given the availability of the
    applicable codecs.  Given a character set, it will do its best to provide
    information on how to use that character set in an email in an
    RFC-compliant way.

    Certain character sets must be encoded with quoted-printable or base64
    when used in email headers or bodies.  Certain character sets must be
    converted outright, and are not allowed in email.  Instances of this
    module expose the following information about a character set:

    input_charset: The initial character set specified.  Common aliases
                   are converted to their `official' email names (e.g. latin_1
                   is converted to iso-8859-1).  Defaults to 7-bit us-ascii.

    header_encoding: If the character set must be encoded before it can be
                     used in an email header, this attribute will be set to
                     charset.QP (for quoted-printable), charset.BASE64 (for
                     base64 encoding), or charset.SHORTEST for the shortest of
                     QP or BASE64 encoding.  Otherwise, it will be None.

    body_encoding: Same as header_encoding, but describes the encoding for the
                   mail message's body, which indeed may be different than the
                   header encoding.  charset.SHORTEST is not allowed for
                   body_encoding.

    output_charset: Some character sets must be converted before they can be
                    used in email headers or bodies.  If the input_charset is
                    one of them, this attribute will contain the name of the
                    charset output will be converted to.  Otherwise, it will
                    be None.

    input_codec: The name of the Python codec used to convert the
                 input_charset to Unicode.  If no conversion codec is
                 necessary, this attribute will be None.

    output_codec: The name of the Python codec used to convert Unicode
                  to the output_charset.  If no conversion codec is necessary,
                  this attribute will have the same value as the input_codec.
    c��	t|t�r|jd�nt|d�}|j
�}tj||�|_	tj|jttdf�\}}}|s|j}||_
||_tj||�|_t j|j|j�|_t j|j|j�|_y#t$rt	j
|��wxYw)Nr#)�
isinstance�strr:�UnicodeErrorr�CharsetError�lowerr1�get�
input_charsetr)r'�BASE64�header_encoding�
body_encodingr-r5�input_codec�output_codec)�selfrF�henc�benc�convs     r.�__init__zCharset.__init__�s��
	5��-��-��$�$�W�-� #�M�7� ;�
�&�+�+�-�
�$�[�[��
�F���$�<�<��(:�(:�)1�6�4�(@�B���d�D���%�%�D�#���!���%�k�k�$��5���%�=�=��);�);�)-�);�);�=���%�M�M�$�*=�*=�*.�*=�*=�?����)�	5��%�%�m�4�4�	5�s�.D � D?c�6�|jj�S�N)rFrD�rLs r.�__repr__zCharset.__repr__�s���!�!�'�'�)�)r/c�L�t|�t|�j�k(SrR)rArD)rL�others  r.�__eq__zCharset.__eq__�s���4�y�C��J�,�,�.�.�.r/c��|jtk7sJ�|jtk(ry|jtk(rytS)aPReturn the content-transfer-encoding used for body encoding.

        This is either the string `quoted-printable' or `base64' depending on
        the encoding used, or it is a function in which case you should call
        the function with a single argument, the Message object being
        encoded.  The function should then set the Content-Transfer-Encoding
        header itself to whatever is appropriate.

        Returns "quoted-printable" if self.body_encoding is QP.
        Returns "base64" if self.body_encoding is BASE64.
        Returns conversion function otherwise.
        zquoted-printable�base64)rIr'�QPrGr	rSs r.�get_body_encodingzCharset.get_body_encoding�s@���!�!�X�-�-�-�����#�%�
�
�
�6�
)��!�!r/c�6�|jxs|jS)z�Return the output character set.

        This is self.output_charset if that is not None, otherwise it is
        self.input_charset.
        )r-rFrSs r.�get_output_charsetzCharset.get_output_charset
s���"�"�8�d�&8�&8�8r/c��|jxsd}t||�}|j|�}|�|S|j||�S)a�Header-encode a string by converting it first to bytes.

        The type of encoding (base64 or quoted-printable) will be based on
        this charset's `header_encoding`.

        :param string: A unicode string for the header.  It must be possible
            to encode this string to bytes using the character set's
            output codec.
        :return: The encoded string, with RFC 2047 chrome.
        r)rKr=�_get_encoder�
header_encode)rLr;r<�header_bytes�encoder_modules     r.r`zCharset.header_encodesN���!�!�/�Z���v�u�-���*�*�<�8���!��M��+�+�L�%�@�@r/c���|jxsd}t||�}|j|�}t|j|��}|j�}t
|�tz}g}	g}
t|�|z
}|D]�}|
j|�tj|
�}
|jt|
|��}||kDs�J|
j�|	s|
s|	jd�n8tj|
�}t||�}|	j||��|g}
t|�|z
}��tj|
�}t||�}|	j||��|	S)afHeader-encode a string by converting it first to bytes.

        This is similar to `header_encode()` except that the string is fit
        into maximum line lengths as given by the argument.

        :param string: A unicode string for the header.  It must be possible
            to encode this string to bytes using the character set's
            output codec.
        :param maxlengths: Maximum line length iterator.  Each element
            returned from this iterator will provide the next maximum line
            length.  This parameter is used as an argument to built-in next()
            and should never be exhausted.  The maximum line lengths should
            not count the RFC 2047 chrome.  These line lengths are only a
            hint; the splitter does the best it can.
        :return: Lines of encoded strings, each with RFC 2047 chrome.
        r)r*N)rKr=r_rr`r]�len�RFC2047_CHROME_LEN�next�append�EMPTYSTRING�join�
header_length�pop)rLr;�
maxlengthsr<rarb�encoderr*�extra�lines�current_line�maxlen�	character�	this_line�length�joined_lines                r.�header_encode_lineszCharset.header_encode_lines%sV��$�!�!�/�Z���v�u�-���*�*�<�8���.�6�6��F���)�)�+���G��1�1�������j�!�E�)���I����	�*�#�(�(��6�I�#�1�1�'�)�W�2M�N�F����� � �"��\��L�L��&�"-�"2�"2�<�"@�K�#*�;��#>�L��L�L���!6�7� )�{���j�)�E�1�� � "�&�&�|�4���{�E�2��
���W�\�*�+��r/c�|�|jtk(rtjS|jtk(rtj
S|jtk(rctjj|�}tj
j|�}||krtjStj
SyrR)rHrG�email�
base64mimerZ�
quoprimimer'rj)rLra�len64�lenqps    r.r_zCharset._get_encoderbs������6�)��#�#�#�
�
!�
!�R�
'��#�#�#�
�
!�
!�X�
-��$�$�2�2�<�@�E��$�$�2�2�<�@�E��u�}��'�'�'��'�'�'�r/c��|s|S|jturJt|t�r|j	|j
�}tjj|�S|jtur[t|t�r|j	|j
�}|jd�}tjj|�St|t�r*|j	|j
�jd�}|S)avBody-encode a string by converting it first to bytes.

        The type of encoding (base64 or quoted-printable) will be based on
        self.body_encoding.  If body_encoding is None, we assume the
        output charset is a 7bit encoding, so re-encoding the decoded
        string using the ascii codec produces the correct string version
        of the content.
        �latin1r#)rIrGr@rAr:r-rxry�body_encoderZ�decoderz)rLr;s  r.rzCharset.body_encodeqs�����M�����'��&�#�&����t�':�':�;���#�#�/�/��7�7�
�
�
�2�
%��&�#�&����t�':�':�;���]�]�8�,�F��#�#�/�/��7�7��&�#�&����t�':�':�;�B�B�7�K���Mr/N)�__name__�
__module__�__qualname__�__doc__�DEFAULT_CHARSETrPrTrWr[r]r`rvr_r�r/r.rr�s=��*�V&5�?�B*�/�"�*9�A�&;�z
�r/r)�__all__�	functoolsr�email.base64mimerx�email.quoprimimer�email.encodersr	rZrGr'rer�r9rhr)r1r5rrrr=rr�r/r.�<module>r�s���
������)�����������������B�r��-���B�r��-���B�r��-�	�
�B�r��-���B�r��-���B�r��-���B�r��-���B�r��-���B�r��-�� �B�r��-�!�"�B�r��-�#�$
�B�r��-�%�&�-�'�(�F�v��-�)�*
�F�v��-�+�,
�F�t�
�6�-�.�F�t�
�6�/�0�t��-��v��-��v�w�/�5��>�
�|��
�|���|���|�	�
�|���|�
��|���|���|���|���}���}���}���}���}�� �}�!�"�}�#�$�������1��<"���

�	�?�8�#�$�l�lr/__pycache__/contentmanager.cpython-312.opt-1.pyc000064400000030114151706203560015427 0ustar00�

T��h\)��F�ddlZddlZddlZddlZddlmZGd�d�Ze�Zdd�Zejde�d�Z
dj�D]Zejee
��[d	�Z
d
j�D]Zejdeze
��[d�Zejd
e�d�Zd�Zd�Zd�Z			dd�Zej+ee�			dd�Zej+ej0j2e�			dd�ZeeefD]Zej+ee��[y)�N)�
quoprimimec�0�eZdZd�Zd�Zd�Zd�Zd�Zd�Zy)�ContentManagerc� �i|_i|_y�N)�get_handlers�set_handlers)�selfs �-/usr/lib64/python3.12/email/contentmanager.py�__init__zContentManager.__init__	s��������c�"�||j|<yr)r)r
�key�handlers   r�add_get_handlerzContentManager.add_get_handler
s��!(����#�r
c�B�|j�}||jvr|j||g|��i|��S|j�}||jvr|j||g|��i|��Sd|jvr|jd|g|��i|��St|��)N�)�get_content_typer�get_content_maintype�KeyError)r
�msg�args�kw�content_type�maintypes      r�get_contentzContentManager.get_contents����+�+�-���4�,�,�,�2�4�$�$�\�2�3�D��D��D�D��+�+�-���t�(�(�(�.�4�$�$�X�.�s�@�T�@�R�@�@�
��"�"�"�(�4�$�$�R�(��:�t�:�r�:�:��|�$�$r
c�"�||j|<yr)r	)r
�typekeyrs   r�add_set_handlerzContentManager.add_set_handlers��%,����'�"r
c��|j�dk(rtd��|j||�}|j�|||g|��i|��y)N�	multipartz"set_content not valid on multipart)r�	TypeError�_find_set_handler�
clear_content)r
r�objrrrs      r�set_contentzContentManager.set_contentsS���#�#�%��4��@�A�A��(�(��c�2��������S�&�4�&�2�&r
c��d}t|�jD]�}||jvr|j|cS|j}t	|dd�}|rdj||f�n|}|�|}||jvr|j|cS||jvr|j|cS|j}||jvs��|j|cSd|jvr|jdSt|��)N�
__module__r�.)�type�__mro__r	�__qualname__�getattr�join�__name__r)	r
rr%�full_path_for_error�typ�qname�modname�	full_path�names	         rr#z ContentManager._find_set_handler's
��"����9�$�$�C��d�'�'�'��(�(��-�-��$�$�E��c�<��4�G�6=����'�5�!1�2�5�I�"�*�&/�#��D�-�-�-��(�(��3�3���)�)�)��(�(��/�/��<�<�D��t�(�(�(��(�(��.�.�%��4�$�$�$��$�$�T�*�*��*�+�+r
N)	r/r(r,rrrrr&r#�r
rrrs ���)�	%�-�'�,r
rc�p�|jd��}|jdd�}|j||��S)NT��decode�charset�ASCII)�errors)�get_payload�	get_paramr9)rr<�contentr:s    r�get_text_contentr@@s5���o�o�T�o�*�G��m�m�I�w�/�G��>�>�'�&�>�1�1r
�textc�&�|jd��S)NTr8�r=�rs r�get_non_text_contentrEGs���?�?�$�?�'�'r
zaudio image video applicationc�$�|jd�S�NrrCrDs r�get_message_contentrHNs���?�?�1��r
zrfc822 external-bodyzmessage/c�6�t|jd��SrG)�bytesr=rDs r�%get_and_fixup_unknown_message_contentrKUs�������#�$�$r
�messagec���dj||f�|d<|rzt|dd�s8|j}|D�cgc]!}|j|j	|g����#}}	|D],}|j
r|j
d�|||j<�.yycc}w#tjj$r:}tdjj|j����|�d}~wwxYw)N�/zContent-Typerr5zInvalid header: {})�policy)
r.�hasattrrO�header_factory�header_source_parse�defectsr5�emailr<�HeaderDefect�
ValueError�format�fold)rr�subtype�headers�mp�header�excs       r�_prepare_setr^as����(�(�H�g�#6�7�C�����w�q�z�6�*����B�%,�.�%,�6�)�r�(�(�"�*@�*@�&��*J�K�%,�
�.�	J�!���>�>� �.�.��+�+�#)��F�K�K� �"�
��.���|�|�(�(�	J��1�8�8� &���3�:�:�� >�@�A�FI�
J��	J�s�&B�!1B�C0�65C+�+C0c��|�|�d}|�||d<|�|jd|dd��|�||d<|�+|j�D]\}}|j||��yy)N�
attachmentzContent-Disposition�filenameT)r\�replacez
Content-ID)�	set_param�items)r�dispositionra�cid�paramsr�values       r�
_finalize_setrirs�����x�3�"����%0��!�"����
�
�j��2�"�	�	$�����L��
�� �,�,�.�J�C���M�M�#�u�%�)�r
c���g}|dzdz}tdt|�|�D]=}||||z}|jtj|�jd���?dj
|�S)N��r�asciir)�range�len�append�binascii�
b2a_base64r9r.)�data�max_line_length�
encoded_lines�unencoded_bytes_per_line�i�thislines      r�_encode_base64ry�sv���M�.�!�3�a�7��
�1�c�$�i�!9�
:����!�4�4�5�����X�0�0��:�A�A�'�J�K�;��7�7�=�!�!r
c����|j|�j�}|jjd���fd�}d�}|��td�|D�d��|jkr	d||�jd�fS||dd
�}tj|jd�|j�}tj|�}	t|�t|	�kDrd}nd
}t|�d
kr||fS|dk(r||�jd�}
||
fS|dk(r||�jdd	�}
||
fS|d
k(r9tj||�jd�|j�}
||
fS|dk(r t||�|j�}
||
fStdj|���#t$rYnwxYw|jdk(s��[d||�jdd	�fS)Nrmc�,���j|��zSr�r.)�lines�lineseps �r�
embedded_bodyz#_encode_text.<locals>.embedded_body�s���W�\�\�%�%8�7�%B�Br
c�*�dj|�dzS)N�
r|)r}s r�normal_bodyz!_encode_text.<locals>.normal_body�s��5�:�:�e�#4�u�#<�<r
c3�2K�|]}t|����y�wr)ro)�.0�xs  r�	<genexpr>z_encode_text.<locals>.<genexpr>�s����&��1��A���s�r)�default�7bit�8bit�surrogateescape�
zlatin-1�base64�quoted-printablez$Unknown content transfer encoding {})�encode�
splitlinesr~�maxrtr9�UnicodeDecodeError�cte_typer�body_encoderqrrroryrVrW)�stringr:�cterOr}rr��sniff�sniff_qp�sniff_base64rsr~s           @r�_encode_textr��s����M�M�'�"�-�-�/�E��n�n�#�#�G�,�G�B�<�
�{��&��&��2�f�6L�6L�L�
��{�5�1�8�8��A�A�A�
�e�C�R�j�)���)�)�%�,�,�y�*A�*0�*@�*@�B���*�*�5�1���x�=�3�|�,�,��C�$�C��5�z�R���H�}�$�
�f�}��5�!�(�(��1����9��

����5�!�(�(��2C�D����9��

�"�	"��%�%�k�%�&8�&?�&?�	�&J�&,�&<�&<�>����9��	

����m�E�2�F�4J�4J�K����9���?�F�F�s�K�L�L��3&�
��
�����&�(��{�5�1�8�8��BS�T�T�Ts�(F<�<	G�Gc
��t|d||	�t||||j�\}}
|j|
�|j	dt
jjj||�d��||d<t|||||�y)NrAr:T�rb�Content-Transfer-Encoding)
r^r�rO�set_payloadrcrTr:�ALIASES�getri)rr�rYr:r�rerarfrgrZ�payloads           r�set_text_contentr��s�����f�g�w�/�����c�j�j�A�L�C���O�O�G���M�M�)��-�-�'�'�+�+�G�W�=��� �(+�C�#�$��#�{�H�c�6�:r
c	�4�|dk(rtd��|dk(r%|dvrtdj|���|�dn|}n*|dk(r!|dvrtd	j|���d
}n|�d
}t|d||�|j|g�||d<t	|||||�y)
N�partialz4message/partial is not supported for Message objects�rfc822)Nr�r��binaryz*message/rfc822 parts do not support cte={}r�z
external-body)Nr�z1message/external-body parts do not support cte={}r�rLr�)rVrWr^r�ri)	rrLrYr�rerarfrgrZs	         r�set_message_contentr��s����)���O�P�P��(���6�6��<�C�C�C�H�J�
J���f���	�O�	#��n�$��C�J�J�3�O�Q�
Q���	������i��'�2��O�O�W�I��'*�C�#�$��#�{�H�c�6�:r
c
�r�t||||	�|dk(r"t||jj��}n]|dk(r+t	j
|ddd��}|j
d�}n-|dk(r|j
d�}n|d	vr|j
dd
�}|j|�||d<t|||||�y)Nr�)rtr�FT)�istextr\�	quotetabsrmr�)r�r�r�r�)	r^ryrOrtrq�b2a_qpr9r�ri)
rrsrrYr�rerarfrgrZs
          r�set_bytes_contentr��s�����h���1�
�h���d�C�J�J�4N�4N�O��	�"�	"����t�E�%�4�P���{�{�7�#��	����{�{�7�#��	�"�	"��{�{�7�$5�6���O�O�D��'*�C�#�$��#�{�H�c�6�:r
r�)�plainzutf-8NNNNNN)r�NNNNNN)r�NNNNN)rq�
email.charsetrT�
email.message�email.errorsrr�raw_data_managerr@rrE�splitrrHrYrKr^riryr�r�r�strr�rL�Messager�rJ�	bytearray�
memoryviewr1r6r
r�<module>r�s[�������3,�3,�l"�#��2�� � ��)9�:�(�/�5�5�7�H��$�$�X�/C�D�8���%�+�+�-�G��$�$�Z��%7�9L�M�.��%�� � ��!F�H�J�"&�*"�$�NIM�:>�*.�
;�� � ��&6�7�=A�<@�,0�;�<� � ����!6�!6�8K�L�9A�:>�*.�;�&
�9�j�)�C��$�$�S�*;�<�*�r
__pycache__/errors.cpython-312.pyc000064400000015557151706203560013015 0ustar00�

T��h���`�dZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd	�d
ee�ZGd�de�ZGd
�de�Z	Gd�de
�ZGd�de�ZGd�de�Z
Gd�de�ZGd�de�ZGd�de�ZGd�de�ZeZGd�de�ZGd�d e�ZGd!�d"e�ZGd#�d$e�ZGd%�d&e�ZGd'�d(e�ZGd)�d*e�ZGd+�d,e�ZGd-�d.e�ZGd/�d0e�ZGd1�d2e�ZGd3�d4e�ZGd5�d6e�Zy7)8z email package exception classes.c��eZdZdZy)�MessageErrorz+Base class for errors in the email package.N��__name__�
__module__�__qualname__�__doc__���%/usr/lib64/python3.12/email/errors.pyrr���5r
rc��eZdZdZy)�MessageParseErrorz&Base class for message parsing errors.Nrr	r
rrrs��0r
rc��eZdZdZy)�HeaderParseErrorzError while parsing headers.Nrr	r
rrr���&r
rc��eZdZdZy)�
BoundaryErrorz#Couldn't find terminating boundary.Nrr	r
rrrs��-r
rc��eZdZdZy)�MultipartConversionErrorz(Conversion to a multipart is prohibited.Nrr	r
rrr���2r
rc��eZdZdZy)�CharsetErrorzAn illegal charset was given.Nrr	r
rrrs��'r
rc��eZdZdZy)�HeaderWriteErrorzError while writing headers.Nrr	r
rrr rr
rc�$��eZdZdZd�fd�	Z�xZS)�
MessageDefectz Base class for a message defect.c�6��|�t�|�|�||_y�N)�super�__init__�line)�selfr!�	__class__s  �rr zMessageDefect.__init__(s������G��T�"���	r
r�rrrrr �
__classcell__�r#s@rrr%s���*��r
rc��eZdZdZy)�NoBoundaryInMultipartDefectzBA message claimed to be a multipart but had no boundary parameter.Nrr	r
rr(r(-s��Lr
r(c��eZdZdZy)�StartBoundaryNotFoundDefectz+The claimed start boundary was never found.Nrr	r
rr*r*0rr
r*c��eZdZdZy)�CloseBoundaryNotFoundDefectzEA start boundary was found, but not the corresponding close boundary.Nrr	r
rr,r,3���Or
r,c��eZdZdZy)�#FirstHeaderLineIsContinuationDefectz;A message had a continuation line as its first header line.Nrr	r
rr/r/6s��Er
r/c��eZdZdZy)�MisplacedEnvelopeHeaderDefectz?A 'Unix-from' header was found in the middle of a header block.Nrr	r
rr1r19���Ir
r1c��eZdZdZy)� MissingHeaderBodySeparatorDefectzEFound line with no leading whitespace and no colon before blank line.Nrr	r
rr4r4<r-r
r4c��eZdZdZy)�!MultipartInvariantViolationDefectz?A message claimed to be a multipart but no subparts were found.Nrr	r
rr6r6Ar2r
r6c��eZdZdZy)�-InvalidMultipartContentTransferEncodingDefectzEAn invalid content transfer encoding was set on the multipart itself.Nrr	r
rr8r8Dr-r
r8c��eZdZdZy)�UndecodableBytesDefectz0Header contained bytes that could not be decodedNrr	r
rr:r:G���:r
r:c��eZdZdZy)�InvalidBase64PaddingDefectz/base64 encoded sequence had an incorrect lengthNrr	r
rr=r=Js��9r
r=c��eZdZdZy)�InvalidBase64CharactersDefectz=base64 encoded sequence had characters not in base64 alphabetNrr	r
rr?r?Ms��Gr
r?c��eZdZdZy)�InvalidBase64LengthDefectz4base64 encoded sequence had invalid length (1 mod 4)Nrr	r
rrArAPs��>r
rAc�"��eZdZdZ�fd�Z�xZS)�HeaderDefectzBase class for a header defect.c�$��t�|�|i|��yr)rr )r"�args�kwr#s   �rr zHeaderDefect.__init__Xs���
���$�%�"�%r
r$r&s@rrCrCUs���)�&�&r
rCc��eZdZdZy)�InvalidHeaderDefectz+Header is not valid, message gives details.Nrr	r
rrHrH[rr
rHc��eZdZdZy)�HeaderMissingRequiredValuez(A header that must have a value had noneNrr	r
rrJrJ^rr
rJc�(��eZdZdZ�fd�Zd�Z�xZS)�NonPrintableDefectz8ASCII characters outside the ascii-printable range foundc�2��t�|�|�||_yr)rr �non_printables)r"rNr#s  �rr zNonPrintableDefect.__init__ds���
����(�,��r
c�8�dj|j�S)Nz6the following ASCII non-printables found in header: {})�formatrN)r"s r�__str__zNonPrintableDefect.__str__hs������+�+�,�	.r
)rrrrr rQr%r&s@rrLrLas���B�-�.r
rLc��eZdZdZy)�ObsoleteHeaderDefectz0Header uses syntax declared obsolete by RFC 5322Nrr	r
rrSrSlr;r
rSc��eZdZdZy)�NonASCIILocalPartDefectz(local_part contains non-ASCII charactersNrr	r
rrUrUorr
rUc��eZdZdZy)�InvalidDateDefectz%Header has unparsable or invalid dateNrr	r
rrWrWts��/r
rWN) r�	Exceptionrrrr�	TypeErrorrrr�
ValueErrorrr(r*r,r/r1r4�MalformedHeaderDefectr6r8r:r=r?rArCrHrJrLrSrUrWr	r
r�<module>r\sj��
'�6�9�6�1��1�'�(�'�.�%�.�3�|�Y�3�(�<�(�'�|�'�
�J��M�-�M�6�-�6�P�-�P�F�-�F�J�M�J�P�}�P�9��J�
�J�P�M�P�;�]�;�:��:�H�M�H�?�
�?�
&�=�&�6�,�6�3��3�	.��	.�;�<�;�3�l�3�
0��0r
__pycache__/feedparser.cpython-312.opt-2.pyc000064400000043100151706203560014542 0ustar00�

T��hY��P�	ddgZddlZddlmZddlmZddlmZddlm	Z	ejd�Zejd	�Zejd
�Z
ejd	�Zejd�ZdZd
Ze�ZGd�de�ZGd�d�ZGd�de�Zy)�
FeedParser�BytesFeedParser�N)�errors)�compat32)�deque)�StringIOz
\r\n|\r|\nz(\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ])��
c�J�eZdZ	d�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�BufferedSubFilec�`�td��|_t�|_g|_d|_y)Nr	)�newlineF)r�_partialr�_lines�	_eofstack�_closed��selfs �)/usr/lib64/python3.12/email/feedparser.py�__init__zBufferedSubFile.__init__4s'��!��,��
��g���������c�:�|jj|�y�N)r�append)r�preds  r�push_eof_matcherz BufferedSubFile.push_eof_matcher?s�������d�#rc�6�|jj�Sr)r�poprs r�pop_eof_matcherzBufferedSubFile.pop_eof_matcherBs���~�~�!�!�#�#rc��|jjd�|j|jj��|jjd�|jj	�d|_y)NrT)r�seek�	pushlines�	readlines�truncaterrs r�closezBufferedSubFile.closeEsV���
�
���1�����t�}�}�.�.�0�1��
�
���1���
�
��� ���rc��|js|jrytS|jj�}t	|j
�D]'}||�s�|jj
|�y|S�Nr	)rr�NeedMoreData�popleft�reversedr�
appendleft)r�line�ateofs   r�readlinezBufferedSubFile.readlineMse���{�{��|�|�����{�{�"�"�$���d�n�n�-�E��T�{����&�&�t�,��	.�
�rc�:�|jj|�yr)rr+�rr,s  r�
unreadlinezBufferedSubFile.unreadline_s��	
�����t�$rc��	|jj|�d|vrd|vry|jjd�|jj�}|jjd�|jj	�|djd�s)|jj|j
��|j|�y)Nr
�
r���)r�writer!r#r$�endswithrr")r�data�partss   r�pushzBufferedSubFile.pushds���2��
�
���D�!��t���D� 0��	
�
�
���1���
�
�'�'�)���
�
���1���
�
��� ��R�y�!�!�$�'��M�M����	�	��,����u�rc�:�|jj|�yr)r�extend)r�liness  rr"zBufferedSubFile.pushlinesys�������5�!rc��|Sr�rs r�__iter__zBufferedSubFile.__iter__|s���rc�<�|j�}|dk(rt�|Sr')r.�
StopIterationr0s  r�__next__zBufferedSubFile.__next__s���}�}����2�:����rN)
�__name__�
__module__�__qualname__rrrr%r.r1r9r"r?rBr>rrrr,s9���	�$�$���$%�
�*"��rrc�L�eZdZ	ded�d�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zy)
rN��policyc�t�	||_d|_|�,|j�ddlm}||_n-|j|_n||_	||j��t�|_g|_	|j�j|_d|_
d|_d|_y#t$r
d|_Y�]wxYw)NFr)�MessagerGT)rH�_old_style_factory�message_factory�
email.messagerJ�_factory�	TypeErrorr�_input�	_msgstack�	_parsegenrB�_parse�_cur�_last�_headersonly)rrNrHrJs    rrzFeedParser.__init__�s���	����"'������%�%�-�1� '��
� &� 6� 6��
�$�D�M�
/�����,�&�'�������n�n�&�/�/�����	���
�!�����
/�*.��'�
/�s�B$�$B7�6B7c��d|_y)NT)rVrs r�_set_headersonlyzFeedParser._set_headersonly�s
�� ��rc�\�	|jj|�|j�yr)rPr9�_call_parse)rr7s  r�feedzFeedParser.feed�s#��-�����������rc�D�	|j�y#t$rYywxYwr)rSrArs rrZzFeedParser._call_parse�s"��	��K�K�M���	��	�s��	�c�:�	|jj�|j�|j�}|j	�dk(rL|j�s<|js0tj�}|jj||�|S)N�	multipart)rPr%rZ�_pop_message�get_content_maintype�is_multipartrVr�!MultipartInvariantViolationDefectrH�
handle_defect)r�root�defects   rr%zFeedParser.close�s}��J������������ � �"���$�$�&�+�5��(�(�*�4�3D�3D��=�=�?�F��K�K�%�%�d�F�3��rc��|jr|j�}n|j|j��}|jr.|jj	�dk(r|jd�|jr|jdj|�|jj|�||_||_	y)NrGzmultipart/digestzmessage/rfc822r4)
rKrNrHrT�get_content_type�set_default_typerQ�attachrrU)r�msgs  r�_new_messagezFeedParser._new_message�s����"�"��-�-�/�C��-�-�t�{�{�-�3�C��9�9����3�3�5�9K�K�� � �!1�2��>�>��N�N�2��%�%�c�*������c�"���	���
rc��|jj�}|jr|jd|_|Sd|_|S)Nr4)rQrrT)r�retvals  rr_zFeedParser._pop_message�s@�����#�#�%���>�>����r�*�D�I��
��D�I��
rc#�BK�|j�g}|jD]�}|tur	t���tj	|�slt
j	|�sUt
j�}|jj|j|�|jj|�n|j|���|j|�|jrug}	|jj�}|tur	t���,|dk(rn|j|��C|jj!t"j%|��y|jj'�dk(r�	|jj)t
j�|j+�D]}|tur	t���n|j-�|jj/�	|jj�}|tur	t���,		|jj�}|tur	t���,	|dk(r	y|jj|���|jj1�dk(r8|j+�D]}|tur	t���n|j-�y|jj1�dk(�r�|jj3�}|��t
j4�}|jj|j|�g}|jD]$}|tur	t���|j|��&|jj!t"j%|��yt7|jj9dd��j;�dvr:t
j<�}|jj|j|�d	|z}t?j@d
t?jB|�zdz�}d}	g}
d}d}	|jj�}|tur	t���,|dk(r�n�|j	|�}
|
�r�|
jEd
�rd}|
jEd�}�ny|	r�|
ra|
d}tFjI|�}|r!|dtK|jEd��|
d<t"j%|
�|j_&d}	|jj|���	|jj�}|tur	t���,|j	|�}
|
s|jj|�n�[|jj)|j�|j+�D]}|tur	t���n|jNj1�dk(rv|jNjP}|dk(rd|jN_(n�|��tFjI|�}
|
r�tK|
jEd��}|d||jN_(nl|jNjR}tU|t6�rFtFjI|�}
|
r/|dtK|
jEd��}||jN_)|jj/�|j-�|j|_'n|
j|����|	r�t
jV�}|jj|j|�|jj!t"j%|
��g}|jD]}|tus�t���t"j%|�|j_(y|s;t
jX�}|jj|j|�y|rdg}ng}|jD]$}|tur	t���|j|��&|r<|d}tZj	|�}|r |tK|jEd��d|d<t"j%|�|j_(yg}|jD]$}|tur	t���|j|��&|jj!t"j%|��y�w)NTr	zmessage/delivery-status�messager^zcontent-transfer-encoding�8bit)�7bitrp�binaryz--z(?P<sep>z4)(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$F�end�linesepr4r).rkrPr(�headerRE�match�NLCREr� MissingHeaderBodySeparatorDefectrHrcrTr1r�_parse_headersrVr.�set_payload�EMPTYSTRING�joinrgrrRr_rr`�get_boundary�NoBoundaryInMultipartDefect�str�get�lower�-InvalidMultipartContentTransferEncodingDefect�re�compile�escape�group�	NLCRE_eol�search�len�preamblerU�epilogue�_payload�
isinstance�StartBoundaryNotFoundDefect�CloseBoundaryNotFoundDefect�	NLCRE_bol)r�headersr,rer<rm�boundary�	separator�
boundaryre�capturing_preambler�rt�close_boundary_seen�mo�lastline�eolmor�rs�payload�	firstline�bolmos                     rrRzFeedParser._parsegen�s������������K�K�D��|�#�"�"���>�>�$�'��{�{�4�(�#�D�D�F�F��K�K�-�-�d�i�i��@��K�K�*�*�4�0���N�N�4� � � 	
���G�$�����E���{�{�+�+�-���<�'�&�&���2�:�����T�"��
�I�I�!�!�+�"2�"2�5�"9�:���9�9�%�%�'�+D�D�����,�,�U�[�[�9�"�n�n�.�F���-�*�*� ��	/�
�!�!�#����+�+�-�
��;�;�/�/�1�D��|�+�*�*� ����;�;�/�/�1�D��|�+�*�*� ���2�:��
����&�&�t�,�?�B�9�9�)�)�+�y�8��.�.�*���\�)�&�&���	+�

������9�9�)�)�+�{�:��y�y�-�-�/�H���
 �;�;�=�����)�)�$�)�)�V�<��� �K�K�D��|�+�*�*� ��L�L��&�	(�
�	�	�%�%�k�&6�&6�u�&=�>���D�I�I�M�M�"=�v�F�G�M�M�O�5�6��M�M�O�����)�)�$�)�)�V�<�
�x��I�����R�Y�Y�y�1�1�G�H�I�J�"&���H��G�"'����{�{�+�+�-���<�'�&�&���2�:���%�%�d�+���
�x�x���.2�+�"$�(�(�9�"5���)�#�(0��|�H�$-�$4�$4�X�$>�E�$�/7�8M�#�e�k�k�!�n�:M�9M�/N����1<�1A�1A�(�1K�D�I�I�.�-2�*����.�.�t�4� �
�#�{�{�3�3�5���<�/�".�.�$�'�-�-�d�3��!� �K�K�2�2�4�8�!���K�K�0�0��1A�1A�B�"&�.�.�"2��!�\�1�".�.�$��	#3��z�z�6�6�8�K�G�#'�:�:�#6�#6��#�r�>�26�D�J�J�/�%�1�!*�!1�!1�(�!;�B�!�&)�"�(�(�1�+�&6��6>�u���o��
�
� 3�"&�*�*�"5�"5��%�g�s�3�!*�!1�!1�'�!:�B�!�*1�2D�C������4D�3D�*E��6=��
�
� 3��K�K�/�/�1��%�%�'�"&���D�J��O�O�D�)�_�f"��;�;�=�����)�)�$�)�)�V�<��	�	�%�%�k�&6�&6�x�&@�A��� �K�K�D��|�+�*�*� �(�&1�%5�%5�h�%?��	�	�"��'��;�;�=�����)�)�$�)�)�V�<����4���������<�'�&�&������%�	$��$�Q�K�	�!���	�2���"+�C����A��,?�,@�"A�H�Q�K�!,�!1�!1�(�!;�D�I�I������K�K�D��|�#�"�"���L�L���	 �
	
�	�	���k�.�.�u�5�6�s
�^.d�1E.dc��d}g}t|�D�]�\}}|ddvrP|s<tj|�}|jj	|j
|��L|j
|��^|r6|j
j|jj|��dg}}|jd�r�|dk(rQtj|�}|r|dt|jd��}|j
j|���|t|�dz
k(r|jj!|�ytj"|�}|j
j$j
|���g|j'd�}|dk(r<tj(d�}|j
j$j
|����|d|}|g}���|r3|j
j|jj|��yy)Nr	rz 	zFrom ��:zMissing header name.)�	enumerater�#FirstHeaderLineIsContinuationDefectrHrcrTr�set_raw�header_source_parse�
startswithr�r�r�r��set_unixfromrPr1�MisplacedEnvelopeHeaderDefect�defects�find�InvalidHeaderDefect)	rr<�
lastheader�	lastvalue�linenor,rer��is	         rryzFeedParser._parse_headers�s����
��	�%�e�,�L�F�D��A�w�%��!�$�G�G��M�F��K�K�-�-�d�i�i��@��� � ��&���!��	�	�!�!�4�;�;�#B�#B�9�#M�N�(*�B�I�
����w�'��Q�;�"�)�)�$�/�B��#�$6�c�"�(�(�1�+�&6�%6�7���I�I�*�*�4�0���s�5�z�A�~�-��K�K�*�*�4�0��$�A�A�$�G�F��I�I�%�%�,�,�V�4���	�	�#��A�
�A�v��3�3�4J�K���	�	�!�!�(�(��0���b�q��J���I�g-�j��D�I�I���t�{�{�>�>�y�I�J�rr)
rCrDrErrrXr[rZr%rkr_rRryr>rrrr�s<��'�"��"�>!��
����{7�z:Krc� ��eZdZ	�fd�Z�xZS)rc�D��t�|�|jdd��y)N�ascii�surrogateescape)�superr[�decode)rr7�	__class__s  �rr[zBytesFeedParser.feeds���
���T�[�[��*;�<�=r)rCrDrEr[�
__classcell__)r�s@rrrs���2�>�>r)�__all__r��emailr�email._policybaser�collectionsr�iorr�rwr�r��NLCRE_crackrur{�NL�objectr(rrrr>rr�<module>r�s���
�"�*�
+��	��&�����
�
�=�!���B�J�J��'�	��B�J�J�(�)�	��b�j�j��)���2�:�:�>�?����	���x��W�f�W�tIK�IK�X>�j�>r__pycache__/feedparser.cpython-312.pyc000064400000046530151706203560013614 0ustar00�

T��hY��R�dZddgZddlZddlmZddlmZddlmZddl	m
Z
ejd	�Zejd
�Z
ejd�Zejd
�Zejd�Zd
ZdZe�ZGd�de�ZGd�d�ZGd�de�Zy)aFeedParser - An email feed parser.

The feed parser implements an interface for incrementally parsing an email
message, line by line.  This has advantages for certain applications, such as
those reading email messages off a socket.

FeedParser.feed() is the primary interface for pushing new data into the
parser.  It returns when there's nothing more it can do with the available
data.  When you have no more data to push into the parser, call .close().
This completes the parsing and returns the root message object.

The other advantage of this parser is that it will never raise a parsing
exception.  Instead, when it finds something unexpected, it adds a 'defect' to
the current message.  Defects are just instances that live on the message
object's .defects attribute.
�
FeedParser�BytesFeedParser�N)�errors)�compat32)�deque)�StringIOz
\r\n|\r|\nz(\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ])��
c�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�BufferedSubFileakA file-ish object that can have new data loaded into it.

    You can also push and pop line-matching predicates onto a stack.  When the
    current predicate matches the current line, a false EOF response
    (i.e. empty string) is returned instead.  This lets the parser adhere to a
    simple abstraction -- it parses until EOF closes the current message.
    c�`�td��|_t�|_g|_d|_y)Nr	)�newlineF)r�_partialr�_lines�	_eofstack�_closed��selfs �)/usr/lib64/python3.12/email/feedparser.py�__init__zBufferedSubFile.__init__4s'��!��,��
��g���������c�:�|jj|�y�N)r�append)r�preds  r�push_eof_matcherz BufferedSubFile.push_eof_matcher?s�������d�#rc�6�|jj�Sr)r�poprs r�pop_eof_matcherzBufferedSubFile.pop_eof_matcherBs���~�~�!�!�#�#rc��|jjd�|j|jj��|jjd�|jj	�d|_y)NrT)r�seek�	pushlines�	readlines�truncaterrs r�closezBufferedSubFile.closeEsV���
�
���1�����t�}�}�.�.�0�1��
�
���1���
�
��� ���rc��|js|jrytS|jj�}t	|j
�D]'}||�s�|jj
|�y|S�Nr	)rr�NeedMoreData�popleft�reversedr�
appendleft)r�line�ateofs   r�readlinezBufferedSubFile.readlineMse���{�{��|�|�����{�{�"�"�$���d�n�n�-�E��T�{����&�&�t�,��	.�
�rc�N�|tusJ�|jj|�yr)r(rr+�rr,s  r�
unreadlinezBufferedSubFile.unreadline_s"���<�'�'�'������t�$rc��|jj|�d|vrd|vry|jjd�|jj�}|jjd�|jj	�|djd�s)|jj|j
��|j|�y)z$Push some new data into this object.r
�
Nr���)r�writer!r#r$�endswithrr")r�data�partss   r�pushzBufferedSubFile.pushds����
�
���D�!��t���D� 0��	
�
�
���1���
�
�'�'�)���
�
���1���
�
��� ��R�y�!�!�$�'��M�M����	�	��,����u�rc�:�|jj|�yr)r�extend)r�liness  rr"zBufferedSubFile.pushlinesys�������5�!rc��|Sr�rs r�__iter__zBufferedSubFile.__iter__|s���rc�<�|j�}|dk(rt�|Sr')r.�
StopIterationr0s  r�__next__zBufferedSubFile.__next__s���}�}����2�:����rN)�__name__�
__module__�__qualname__�__doc__rrrr%r.r1r9r"r?rBr>rrrr,s9���	�$�$���$%�
�*"��rrc�N�eZdZdZd
ed�d�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
y)rzA feed-style parser of email.N��policyc�r�||_d|_|�,|j�ddlm}||_n-|j|_n||_	||j��t�|_g|_	|j�j|_d|_
d|_d|_y#t$r
d|_Y�]wxYw)a_factory is called with no arguments to create a new message obj

        The policy keyword specifies a policy object that controls a number of
        aspects of the parser's operation.  The default policy maintains
        backward compatibility.

        FNr)�MessagerHT)rI�_old_style_factory�message_factory�
email.messagerK�_factory�	TypeErrorr�_input�	_msgstack�	_parsegenrB�_parse�_cur�_last�_headersonly)rrOrIrKs    rrzFeedParser.__init__�s������"'������%�%�-�1� '��
� &� 6� 6��
�$�D�M�
/�����,�&�'�������n�n�&�/�/�����	���
�!�����
/�*.��'�
/�s�B#�#B6�5B6c��d|_y)NT)rWrs r�_set_headersonlyzFeedParser._set_headersonly�s
�� ��rc�Z�|jj|�|j�y)zPush more data into the parser.N)rQr9�_call_parse)rr7s  r�feedzFeedParser.feed�s ������������rc�D�	|j�y#t$rYywxYwr)rTrArs rr[zFeedParser._call_parse�s"��	��K�K�M���	��	�s��	�c�T�|jj�|j�|j�}|jrJ�|j�dk(rL|j
�s<|js0tj�}|jj||�|S)z<Parse all remaining data and return the root message object.�	multipart)rQr%r[�_pop_messagerR�get_content_maintype�is_multipartrWr�!MultipartInvariantViolationDefectrI�
handle_defect)r�root�defects   rr%zFeedParser.close�s�������������� � �"���>�>�!�!��$�$�&�+�5��(�(�*�4�3D�3D��=�=�?�F��K�K�%�%�d�F�3��rc��|jr|j�}n|j|j��}|jr.|jj	�dk(r|jd�|jr|jdj|�|jj|�||_||_	y)NrHzmultipart/digestzmessage/rfc822r4)
rLrOrIrU�get_content_type�set_default_typerR�attachrrV)r�msgs  r�_new_messagezFeedParser._new_message�s����"�"��-�-�/�C��-�-�t�{�{�-�3�C��9�9����3�3�5�9K�K�� � �!1�2��>�>��N�N�2��%�%�c�*������c�"���	���
rc��|jj�}|jr|jd|_|Sd|_|S)Nr4)rRrrU)r�retvals  rr`zFeedParser._pop_message�s@�����#�#�%���>�>����r�*�D�I��
��D�I��
rc#�JK�|j�g}|jD]�}|tur	t���tj	|�slt
j	|�sUt
j�}|jj|j|�|jj|�n|j|���|j|�|jrug}	|jj�}|tur	t���,|dk(rn|j|��C|jj!t"j%|��y|jj'�dk(r�	|jj)t
j�|j+�D]}|tur	t���n|j-�|jj/�	|jj�}|tur	t���,		|jj�}|tur	t���,	|dk(r	y|jj|���|jj1�dk(r8|j+�D]}|tur	t���n|j-�y|jj1�dk(�r�|jj3�}|��t
j4�}|jj|j|�g}|jD]$}|tur	t���|j|��&|jj!t"j%|��yt7|jj9dd��j;�dvr:t
j<�}|jj|j|�d	|z}t?j@d
t?jB|�zdz�}d}	g}
d}d}	|jj�}|tur	t���,|dk(r�n�|j	|�}
|
�r�|
jEd
�rd}|
jEd�}�n}|	r�|
ra|
d}tFjI|�}|r!|dtK|jEd��|
d<t"j%|
�|j_&d}	|jj|���	|jj�}|tur	t���,|j	|�}
|
s|jj|�n�[|jj)|j�|j+�D]}|tur	t���n|jNj1�dk(rv|jNjP}|dk(rd|jN_(n�|��tFjI|�}
|
r�tK|
jEd��}|d||jN_(nl|jNjR}tU|t6�rFtFjI|�}
|
r/|dtK|
jEd��}||jN_)|jj/�|j-�|j|_'n|	sJ�|
j|����|	r�t
jV�}|jj|j|�|jj!t"j%|
��g}|jD]}|tus�t���t"j%|�|j_(y|s;t
jX�}|jj|j|�y|rdg}ng}|jD]$}|tur	t���|j|��&|r<|d}tZj	|�}|r |tK|jEd��d|d<t"j%|�|j_(yg}|jD]$}|tur	t���|j|��&|jj!t"j%|��y�w)NTr	zmessage/delivery-status�messager_zcontent-transfer-encoding�8bit)�7bitrq�binaryz--z(?P<sep>z4)(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$F�end�linesepr4r).rlrQr(�headerRE�match�NLCREr� MissingHeaderBodySeparatorDefectrIrdrUr1r�_parse_headersrWr.�set_payload�EMPTYSTRING�joinrhrrSr`rra�get_boundary�NoBoundaryInMultipartDefect�str�get�lower�-InvalidMultipartContentTransferEncodingDefect�re�compile�escape�group�	NLCRE_eol�search�len�preamblerV�epilogue�_payload�
isinstance�StartBoundaryNotFoundDefect�CloseBoundaryNotFoundDefect�	NLCRE_bol)r�headersr,rfr<rn�boundary�	separator�
boundaryre�capturing_preambler�ru�close_boundary_seen�mo�lastline�eolmor�rt�payload�	firstline�bolmos                     rrSzFeedParser._parsegen�s������������K�K�D��|�#�"�"���>�>�$�'��{�{�4�(�#�D�D�F�F��K�K�-�-�d�i�i��@��K�K�*�*�4�0���N�N�4� � � 	
���G�$�����E���{�{�+�+�-���<�'�&�&���2�:�����T�"��
�I�I�!�!�+�"2�"2�5�"9�:���9�9�%�%�'�+D�D�����,�,�U�[�[�9�"�n�n�.�F���-�*�*� ��	/�
�!�!�#����+�+�-�
��;�;�/�/�1�D��|�+�*�*� ����;�;�/�/�1�D��|�+�*�*� ���2�:��
����&�&�t�,�?�B�9�9�)�)�+�y�8��.�.�*���\�)�&�&���	+�

������9�9�)�)�+�{�:��y�y�-�-�/�H���
 �;�;�=�����)�)�$�)�)�V�<��� �K�K�D��|�+�*�*� ��L�L��&�	(�
�	�	�%�%�k�&6�&6�u�&=�>���D�I�I�M�M�"=�v�F�G�M�M�O�5�6��M�M�O�����)�)�$�)�)�V�<�
�x��I�����R�Y�Y�y�1�1�G�H�I�J�"&���H��G�"'����{�{�+�+�-���<�'�&�&���2�:���%�%�d�+���
�x�x���.2�+�"$�(�(�9�"5���)�#�(0��|�H�$-�$4�$4�X�$>�E�$�/7�8M�#�e�k�k�!�n�:M�9M�/N����1<�1A�1A�(�1K�D�I�I�.�-2�*����.�.�t�4� �
�#�{�{�3�3�5���<�/�".�.�$�'�-�-�d�3��!� �K�K�2�2�4�8�!���K�K�0�0��1A�1A�B�"&�.�.�"2��!�\�1�".�.�$��	#3��z�z�6�6�8�K�G�#'�:�:�#6�#6��#�r�>�26�D�J�J�/�%�1�!*�!1�!1�(�!;�B�!�&)�"�(�(�1�+�&6��6>�u���o��
�
� 3�"&�*�*�"5�"5��%�g�s�3�!*�!1�!1�'�!:�B�!�*1�2D�C������4D�3D�*E��6=��
�
� 3��K�K�/�/�1��%�%�'�"&���D�J�.�-�-��O�O�D�)�_�f"��;�;�=�����)�)�$�)�)�V�<��	�	�%�%�k�&6�&6�x�&@�A��� �K�K�D��|�+�*�*� �(�&1�%5�%5�h�%?��	�	�"��'��;�;�=�����)�)�$�)�)�V�<����4���������<�'�&�&������%�	$��$�Q�K�	�!���	�2���"+�C����A��,?�,@�"A�H�Q�K�!,�!1�!1�(�!;�D�I�I������K�K�D��|�#�"�"���L�L���	 �
	
�	�	���k�.�.�u�5�6�s
�^2d#�5E.d#c�,�d}g}t|�D�]�\}}|ddvrP|s<tj|�}|jj	|j
|��L|j
|��^|r6|j
j|jj|��dg}}|jd�r�|dk(rQtj|�}|r|dt|jd��}|j
j|���|t|�dz
k(r|jj!|�ytj"|�}|j
j$j
|���g|j'd�}|dk(r<tj(d�}|j
j$j
|����|dkDsJd��|d|}|g}���|r3|j
j|jj|��yy)	Nr	rz 	zFrom ��:zMissing header name.z3_parse_headers fed line with no : and no leading WS)�	enumerater�#FirstHeaderLineIsContinuationDefectrIrdrUr�set_raw�header_source_parse�
startswithr�r�r�r��set_unixfromrQr1�MisplacedEnvelopeHeaderDefect�defects�find�InvalidHeaderDefect)	rr<�
lastheader�	lastvalue�linenor,rfr��is	         rrzzFeedParser._parse_headers�s����
��	�%�e�,�L�F�D��A�w�%��!�$�G�G��M�F��K�K�-�-�d�i�i��@��� � ��&���!��	�	�!�!�4�;�;�#B�#B�9�#M�N�(*�B�I�
����w�'��Q�;�"�)�)�$�/�B��#�$6�c�"�(�(�1�+�&6�%6�7���I�I�*�*�4�0���s�5�z�A�~�-��K�K�*�*�4�0��$�A�A�$�G�F��I�I�%�%�,�,�V�4���	�	�#��A�
�A�v��3�3�4J�K���	�	�!�!�(�(��0���Q�3�M�M�M�3��b�q��J���I�g-�j��D�I�I���t�{�{�>�>�y�I�J�rr)rCrDrErFrrrYr\r[r%rlr`rSrzr>rrrr�s<��'�"��"�>!��
����{7�z:Krc�"��eZdZdZ�fd�Z�xZS)rz(Like FeedParser, but feed accepts bytes.c�D��t�|�|jdd��y)N�ascii�surrogateescape)�superr\�decode)rr7�	__class__s  �rr\zBytesFeedParser.feeds���
���T�[�[��*;�<�=r)rCrDrErFr\�
__classcell__)r�s@rrrs���2�>�>r)rF�__all__r��emailr�email._policybaser�collectionsr�iorr�rxr�r��NLCRE_crackrvr|�NL�objectr(rrrr>rr�<module>r�s���
�"�*�
+��	��&�����
�
�=�!���B�J�J��'�	��B�J�J�(�)�	��b�j�j��)���2�:�:�>�?����	���x��W�f�W�tIK�IK�X>�j�>r__pycache__/generator.cpython-312.opt-1.pyc000064400000051362151706203560014420 0ustar00�

��i�S���dZgd�ZddlZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZddl
mZdZd	Zej"d
�Zej"dej&�Zej"d�Zej"d
�ZGd�d�ZGd�de�ZdZGd�de�Zeeej:dz
��ZdezZej@Z y)z:Classes to generate plain text from a message object tree.)�	Generator�DecodedGenerator�BytesGenerator�N)�deepcopy)�StringIO�BytesIO)�_has_surrogates)�HeaderWriteError�_�
z
\r\n|\r|\nz^From z\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]s\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]c��eZdZdZddd�d�Zd�Zdd�Zd�Zd�Zd	�Z	d
�Z
d�Zd�Zd
�Z
d�ZeZd�Zd�Zd�Zd�Zedd��Zed��Zy)rz�Generates output from a Message object tree.

    This basic generator writes the message to the given file object as plain
    text.
    N��policyc�`�|�|�dn|j}||_||_||_||_y)a�Create the generator for message flattening.

        outfp is the output file-like object for writing the message to.  It
        must have a write() method.

        Optional mangle_from_ is a flag that, when True (the default if policy
        is not set), escapes From_ lines in the body of the message by putting
        a `>' in front of them.

        Optional maxheaderlen specifies the longest length for a non-continued
        header.  When a header line is longer (in characters, with tabs
        expanded to 8 spaces) than maxheaderlen, the header will split as
        defined in the Header class.  Set maxheaderlen to zero to disable
        header wrapping.  The default is 78, as recommended (but not required)
        by RFC 2822.

        The policy keyword specifies a policy object that controls a number of
        aspects of the generator's operation.  If no policy is specified,
        the policy associated with the Message object passed to the
        flatten method is used.

        NT)�mangle_from_�_fp�
_mangle_from_�maxheaderlenr)�self�outfprrrs     �(/usr/lib64/python3.12/email/generator.py�__init__zGenerator.__init__&s9��2��#)�>�4�v�7J�7J�L����)���(������c�:�|jj|�y�N)r�write�r�ss  rrzGenerator.writeFs�������q�rc���|j�|jn|j}|�|j|��}|j�|j|j��}|j|_|j|j�|_d|_|j|j�|_|j}|j}	||_||_|rZ|j�}|s*dtjtj��z}|j||jz�|j|�||_||_y#||_||_wxYw)a�Print the message object tree rooted at msg to the output file
        specified when the Generator instance was created.

        unixfrom is a flag that forces the printing of a Unix From_ delimiter
        before the first object in the message tree.  If the original message
        has no From_ delimiter, a `standard' one is crafted.  By default, this
        is False to inhibit the printing of any From_ delimiter.

        Note that for subobjects, no From_ line is printed.

        linesep specifies the characters used to indicate a new line in
        the output.  The default value is determined by the policy specified
        when the Generator instance was created or, if none was specified,
        from the policy associated with the msg.

        N)�linesep��max_line_length�zFrom nobody )r�clonerr �_NL�_encode�_encoded_NL�_EMPTY�_encoded_EMPTY�get_unixfrom�time�ctimer�_write)r�msg�unixfromr r�old_gen_policy�old_msg_policy�ufroms        r�flattenzGenerator.flattenJs%��* $�{�{�2�����������\�\�'�\�2�F����(��\�\�$�2C�2C�\�D�F��>�>����<�<����1������"�l�l�4�;�;�7���
��������	(� �D�K��C�J���(�(�*���*�T�Z�Z��	�	��-D�D�E��
�
�5�4�8�8�+�,��K�K���(�D�K�'�C�J��)�D�K�'�C�J�s
�A;E�E,c�T�|j||jd|j��S)z1Clone this generator with the exact same options.Nr)�	__class__rr)r�fps  rr$zGenerator.clone{s-���~�~�b�"�0�0�"�%)�[�[��2�	2rc��t�Sr)r�rs r�_new_bufferzGenerator._new_buffer�s
���z�rc��|Sr�rs  rr&zGenerator._encode�s���rc���|sytj|�}|ddD].}|j|�|j|j��0|dr|j|d�yy)N���)�NLCRE�splitrr%)r�lines�lines   r�_write_lineszGenerator._write_lines�s`�������E�"���#�2�J�D��J�J�t���J�J�t�x�x� ����9��J�J�u�R�y�!�rc� �|j}	d|_|j�x|_}|j|�||_|j}|`|rOt	|�}|jd��	|d|d<n|j
d|d�|j
d|d�t|dd�}|�|j|�n||�|jj|j��y#||_|j}|`wxYw)N�content-transfer-encodingr�Content-Transfer-Encoding�content-type��_write_headers)r�
_munge_cter9�	_dispatchr�get�replace_header�getattrrHr�getvalue)rr.�oldfp�sfp�	munge_cte�meths      rr-zGenerator._write�s�������	 �"�D�O�!�-�-�/�/�D�H�s��N�N�3���D�H����I�����3�-�C��w�w�2�3�;�3<�Q�<��/�0��"�"�#>�	�!��M����~�y��|�<��s�,�d�3���<�����$���J������s�|�|�~�&��'�D�H����I���s�/C6�6D
c�&�|j�}|j�}tj||f�j	dd�}t|d|zd�}|�0|j	dd�}t|d|zd�}|�|j}||�y)N�-r�_handle_)�get_content_maintype�get_content_subtype�
UNDERSCORE�join�replacerM�
_writeBody)rr.�main�sub�specificrR�generics       rrJzGenerator._dispatch�s���
�'�'�)���%�%�'���?�?�D�#�;�/�7�7��S�A���t�Z�(�2�D�9���<��l�l�3��,�G��4��g�!5�t�<�D��|������S�	rc���|j�D]�\}}|jj||�}|jjr~|jj}|j|jj�st
d|�d|����tj|j|��rt
d|����|j|���|j|j�y�Nz folded header does not end with z: z folded header contains newline: )�	raw_itemsr�fold�verify_generated_headersr �endswithr
�NEWLINE_WITHOUT_FWSP�search�removesuffixrr%�rr.�h�v�foldedr s      rrHzGenerator._write_headers�s����M�M�O�D�A�q��[�[�%�%�a��+�F��{�{�3�3��+�+�-�-�����t�{�{�':�':�;�*�:�7�+�R��z�R�T�T�'�.�.�v�/B�/B�7�/K�L�*�:�6�*�E�G�G��J�J�v��$�	
�
�
�4�8�8�rc��|j�}|�yt|t�stdt	|�z��t|j�r\|jd�}|�It|�}|d=|j|j|�|j�}|d|df|_
|jrtjd|�}|j|�y)Nzstring payload expected: %s�charsetrDrF�>From )�get_payload�
isinstance�str�	TypeError�typer	�_payload�	get_paramr�set_payloadrIr�fcrer]rB)rr.�payloadrns    r�_handle_textzGenerator._handle_text�s����/�/�#���?���'�3�'��9�D��M�I�J�J��3�<�<�(��m�m�I�.�G��"��s�m���3�4�������g�6��/�/�+��#&�'B�#C�#&�~�#6�#8�������h�h�x��1�G����'�"rc�0�g}|j�}|�g}n5t|t�r|j|�yt|t�s|g}|D]`}|j�}|j
|�}|j|d|j��|j|j���b|j�}|s=|jj|�}|j|�}|j|�|j �e|j"r!t$j'd|j �}	n|j }	|j)|	�|j|j�|jd|z|jz�|r*|j*j|j-d��|D]K}
|j|jdz|z|jz�|j*j|
��M|j|jdz|zdz|jz�|j.�K|j"r!t$j'd|j.�}n|j.}|j)|�yy)NF�r/r roz--r)rprqrrr�listr9r$r3r%�appendrN�get_boundaryr'rY�_make_boundary�set_boundary�preamblerrxr]rBr�pop�epilogue)rr.�msgtexts�subparts�partr�g�boundary�alltextr��	body_partr�s            r�_handle_multipartzGenerator._handle_multipart
s�����?�?�$�����H�
��#�
&��J�J�x� ���H�d�+� �z�H��D�� � �"�A��
�
�1�
�A�
�I�I�d�U�D�H�H�I�=��O�O�A�J�J�L�)�	��#�#�%����&�&�+�+�H�5�G��*�*�7�3�H����X�&��<�<�#��!�!��8�8�H�c�l�l�;���<�<�����h�'��J�J�t�x�x� ��
�
�4�(�?�T�X�X�-�.���H�H�N�N�8�<�<��?�+�"�I��J�J�t�x�x�$���1�D�H�H�<�=��H�H�N�N�9�%�	"�	
�
�
�4�8�8�d�?�X�-��4�t�x�x�?�@��<�<�#��!�!��8�8�H�c�l�l�;���<�<�����h�'�$rc��|j}|jd��|_	|j|�||_y#||_wxYw)Nrr!)rr$r�)rr.�ps   r�_handle_multipart_signedz"Generator._handle_multipart_signedGsA��
�K�K���g�g�a�g�0���	��"�"�3�'��D�K��!�D�K�s	�>�	Ac��g}|j�D]�}|j�}|j|�}|j|d|j��|j�}|j
|j�}|r@|d|jk(r.|j|jj|dd����|j|���|jj|jj|��y)NFr|r=)
rpr9r$r3r%rNr?r'r)r~rYrr)rr.�blocksr�rr��textr@s        r�_handle_message_delivery_statusz)Generator._handle_message_delivery_statusRs������O�O�%�D�� � �"�A��
�
�1�
�A�
�I�I�d�U�D�H�H�I�=��:�:�<�D��J�J�t�/�/�0�E���r��d�&9�&9�9��
�
�d�.�.�3�3�E�#�2�J�?�@��
�
�d�#�&�	
�����t�'�'�,�,�V�4�5rc�R�|j�}|j|�}|j}t|t�r>|j|j
d�d|j��|j�}n|j|�}|jj|�y)NrFr|)r9r$rurqr}r3rpr%rNr&rr)rr.rr�rys     r�_handle_messagezGenerator._handle_messagegsz��������J�J�q�M���,�,���g�t�$�
�I�I�c�o�o�a�(�5�$�(�(�I�K��j�j�l�G��l�l�7�+�G������w�rc�@�tjtj�}dt|zzdz}|�|S|}d}	|jdt
j|�zdztj�}|j|�s	|S|dzt|�z}|dz
}�d)Nz===============z==rz^--z(--)?$�.rG)�random�	randrange�sys�maxsize�_fmt�_compile_re�re�escape�	MULTILINErgrr)�clsr��tokenr��b�counter�cres       rr�zGenerator._make_boundary�s���� � ����-������.��5���<��O�������/�/�%�"�)�)�A�,�"6��"A�2�<�<�P�C��:�:�d�#�����3���W��-�A��q�L�G�rc�.�tj||�Sr)r��compile�r�r�flagss   rr�zGenerator._compile_re�s���z�z�!�U�#�#r)NN)FNr)�__name__�
__module__�__qualname__�__doc__rrr3r$r9r&rBr-rJrHrzr[r�r�r�r��classmethodr�r�r;rrrrs�������@�/(�b2�(��	"� %'�N�(
�&#�,�J�8(�t	�6�* �2����"�$��$rrc�N��eZdZdZd�Zd�Zd�Zd�Z�fd�ZeZ	e
d��Z�xZS)ra�Generates a bytes version of a Message object tree.

    Functionally identical to the base Generator except that the output is
    bytes and not string.  When surrogates were used in the input to encode
    bytes, these are decoded back to bytes for output.  If the policy has
    cte_type set to 7bit, then the message is transformed such that the
    non-ASCII bytes are properly content transfer encoded, using the charset
    unknown-8bit.

    The outfp object must accept bytes in its write method.
    c�Z�|jj|jdd��y)N�ascii�surrogateescape)rr�encoders  rrzBytesGenerator.write�s�������q�x�x��):�;�<rc��t�Sr)rr8s rr9zBytesGenerator._new_buffer�s
���y�rc�$�|jd�S�Nr�)r�rs  rr&zBytesGenerator._encode�s���x�x�� � rc���|j�D]�\}}|jj||�}|jjrx|jjj�}|j
|�std|�d|����tj|j|��rtd|����|jj|���|j|j�yra)rbr�fold_binaryrdr r�rer
�NEWLINE_WITHOUT_FWSP_BYTESrgrhrrr%ris      rrHzBytesGenerator._write_headers�s����M�M�O�D�A�q��[�[�,�,�Q��2�F��{�{�3�3��+�+�-�-�4�4�6�����w�/�*�:�7�+�R��z�R�T�T�-�4�4�V�5H�5H��5Q�R�*�:�6�*�E�G�G��H�H�N�N�6�"�$�	
�
�
�4�8�8�rc�<��|j�yt|j�rf|jjdk(sM|jr%t
j
d|j�|_|j|j�ytt|�+|�y)N�7bitro)rur	r�cte_typerrxr]rB�superrrz)rr.r5s  �rrzzBytesGenerator._handle_text�so����<�<����3�<�<�(����1E�1E�v�1M��!�!�#�x�x��#�,�,�?������c�l�l�+��.��3�C�8rc�L�tj|jd�|�Sr�)r�r�r�r�s   rr�zBytesGenerator._compile_re�s���z�z�!�(�(�7�+�U�3�3r)
r�r�r�r�rr9r&rHrzr[r�r��
__classcell__)r5s@rrr�s:���
�=��!��"
9��J��4��4rrzD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c�$�eZdZdZddd�d�Zd�Zy)rz�Generates a text representation of a message.

    Like the Generator base class, except that non-text parts are substituted
    with a format string representing the part.
    Nrc�b�tj|||||��|�t|_y||_y)a�Like Generator.__init__() except that an additional optional
        argument is allowed.

        Walks through all subparts of a message.  If the subpart is of main
        type `text', then it prints the decoded payload of the subpart.

        Otherwise, fmt is a format string that is used instead of the message
        payload.  fmt is expanded with the following keywords (in
        %(keyword)s format):

        type       : Full MIME type of the non-text part
        maintype   : Main MIME type of the non-text part
        subtype    : Sub-MIME type of the non-text part
        filename   : Filename of the non-text part
        description: Description associated with the non-text part
        encoding   : Content transfer encoding of the non-text part

        The default value for fmt is None, meaning

        [Non-text (%(type)s) part of message omitted, filename %(filename)s]
        rN)rr�_FMTr�)rrrr�fmtrs      rrzDecodedGenerator.__init__�s5��.	���4���l�"(�	�	*��;��D�I��D�Irc
��|j�D]�}|j�}|dk(rt|jd��|���6|dk(r�<t|j|j�|j�|j
�|jd�|jdd�|jd	d
�d�z|����y)Nr�F)�decode)�file�	multipartz
[no filename]zContent-Descriptionz[no description]rEz
[no encoding])rt�maintype�subtype�filename�description�encoding)	�walkrV�printrpr��get_content_typerW�get_filenamerK)rr.r�r�s    rrJzDecodedGenerator._dispatch�s����H�H�J�D��0�0�2�H��6�!��d�&�&�e�&�4�4�@��[�(���d�i�i�#'�#8�#8�#:�#'�#<�#<�#>�#'�#;�#;�#=�#'�#4�#4�_�#E�#'�8�8�,A�,>�$@�#'�8�8�,G�,;�$=�	#�	�!�	"�r)NNN)r�r�r�r�rrJr;rrrr�s���
���<"rrrGz%%0%dd)!r��__all__r�r�r+r��copyr�iorr�email.utilsr	�email.errorsr
rX�NLr�r>r�rxrfr�rrr�r�len�reprr��_widthr�r�r;rr�<module>r�s���
A�
=��	�
��
�� �'�)�
�
�	����
�
�=�!���r�z�z�)�R�\�\�*��!�r�z�z�"C�D��'�R�Z�Z�(J�K��x$�x$�v84�Y�84�vN��6"�y�6"�t

�T�#�+�+�a�-�
 �	!���&����)�)�r__pycache__/generator.cpython-312.pyc000064400000051362151706203560013461 0ustar00�

��i�S���dZgd�ZddlZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZddl
mZdZd	Zej"d
�Zej"dej&�Zej"d�Zej"d
�ZGd�d�ZGd�de�ZdZGd�de�Zeeej:dz
��ZdezZej@Z y)z:Classes to generate plain text from a message object tree.)�	Generator�DecodedGenerator�BytesGenerator�N)�deepcopy)�StringIO�BytesIO)�_has_surrogates)�HeaderWriteError�_�
z
\r\n|\r|\nz^From z\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]s\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]c��eZdZdZddd�d�Zd�Zdd�Zd�Zd�Zd	�Z	d
�Z
d�Zd�Zd
�Z
d�ZeZd�Zd�Zd�Zd�Zedd��Zed��Zy)rz�Generates output from a Message object tree.

    This basic generator writes the message to the given file object as plain
    text.
    N��policyc�`�|�|�dn|j}||_||_||_||_y)a�Create the generator for message flattening.

        outfp is the output file-like object for writing the message to.  It
        must have a write() method.

        Optional mangle_from_ is a flag that, when True (the default if policy
        is not set), escapes From_ lines in the body of the message by putting
        a `>' in front of them.

        Optional maxheaderlen specifies the longest length for a non-continued
        header.  When a header line is longer (in characters, with tabs
        expanded to 8 spaces) than maxheaderlen, the header will split as
        defined in the Header class.  Set maxheaderlen to zero to disable
        header wrapping.  The default is 78, as recommended (but not required)
        by RFC 2822.

        The policy keyword specifies a policy object that controls a number of
        aspects of the generator's operation.  If no policy is specified,
        the policy associated with the Message object passed to the
        flatten method is used.

        NT)�mangle_from_�_fp�
_mangle_from_�maxheaderlenr)�self�outfprrrs     �(/usr/lib64/python3.12/email/generator.py�__init__zGenerator.__init__&s9��2��#)�>�4�v�7J�7J�L����)���(������c�:�|jj|�y�N)r�write�r�ss  rrzGenerator.writeFs�������q�rc���|j�|jn|j}|�|j|��}|j�|j|j��}|j|_|j|j�|_d|_|j|j�|_|j}|j}	||_||_|rZ|j�}|s*dtjtj��z}|j||jz�|j|�||_||_y#||_||_wxYw)a�Print the message object tree rooted at msg to the output file
        specified when the Generator instance was created.

        unixfrom is a flag that forces the printing of a Unix From_ delimiter
        before the first object in the message tree.  If the original message
        has no From_ delimiter, a `standard' one is crafted.  By default, this
        is False to inhibit the printing of any From_ delimiter.

        Note that for subobjects, no From_ line is printed.

        linesep specifies the characters used to indicate a new line in
        the output.  The default value is determined by the policy specified
        when the Generator instance was created or, if none was specified,
        from the policy associated with the msg.

        N)�linesep��max_line_length�zFrom nobody )r�clonerr �_NL�_encode�_encoded_NL�_EMPTY�_encoded_EMPTY�get_unixfrom�time�ctimer�_write)r�msg�unixfromr r�old_gen_policy�old_msg_policy�ufroms        r�flattenzGenerator.flattenJs%��* $�{�{�2�����������\�\�'�\�2�F����(��\�\�$�2C�2C�\�D�F��>�>����<�<����1������"�l�l�4�;�;�7���
��������	(� �D�K��C�J���(�(�*���*�T�Z�Z��	�	��-D�D�E��
�
�5�4�8�8�+�,��K�K���(�D�K�'�C�J��)�D�K�'�C�J�s
�A;E�E,c�T�|j||jd|j��S)z1Clone this generator with the exact same options.Nr)�	__class__rr)r�fps  rr$zGenerator.clone{s-���~�~�b�"�0�0�"�%)�[�[��2�	2rc��t�Sr)r�rs r�_new_bufferzGenerator._new_buffer�s
���z�rc��|Sr�rs  rr&zGenerator._encode�s���rc���|sytj|�}|ddD].}|j|�|j|j��0|dr|j|d�yy)N���)�NLCRE�splitrr%)r�lines�lines   r�_write_lineszGenerator._write_lines�s`�������E�"���#�2�J�D��J�J�t���J�J�t�x�x� ����9��J�J�u�R�y�!�rc� �|j}	d|_|j�x|_}|j|�||_|j}|`|rOt	|�}|jd��	|d|d<n|j
d|d�|j
d|d�t|dd�}|�|j|�n||�|jj|j��y#||_|j}|`wxYw)N�content-transfer-encodingr�Content-Transfer-Encoding�content-type��_write_headers)r�
_munge_cter9�	_dispatchr�get�replace_header�getattrrHr�getvalue)rr.�oldfp�sfp�	munge_cte�meths      rr-zGenerator._write�s�������	 �"�D�O�!�-�-�/�/�D�H�s��N�N�3���D�H����I�����3�-�C��w�w�2�3�;�3<�Q�<��/�0��"�"�#>�	�!��M����~�y��|�<��s�,�d�3���<�����$���J������s�|�|�~�&��'�D�H����I���s�/C6�6D
c�&�|j�}|j�}tj||f�j	dd�}t|d|zd�}|�0|j	dd�}t|d|zd�}|�|j}||�y)N�-r�_handle_)�get_content_maintype�get_content_subtype�
UNDERSCORE�join�replacerM�
_writeBody)rr.�main�sub�specificrR�generics       rrJzGenerator._dispatch�s���
�'�'�)���%�%�'���?�?�D�#�;�/�7�7��S�A���t�Z�(�2�D�9���<��l�l�3��,�G��4��g�!5�t�<�D��|������S�	rc���|j�D]�\}}|jj||�}|jjr~|jj}|j|jj�st
d|�d|����tj|j|��rt
d|����|j|���|j|j�y�Nz folded header does not end with z: z folded header contains newline: )�	raw_itemsr�fold�verify_generated_headersr �endswithr
�NEWLINE_WITHOUT_FWSP�search�removesuffixrr%�rr.�h�v�foldedr s      rrHzGenerator._write_headers�s����M�M�O�D�A�q��[�[�%�%�a��+�F��{�{�3�3��+�+�-�-�����t�{�{�':�':�;�*�:�7�+�R��z�R�T�T�'�.�.�v�/B�/B�7�/K�L�*�:�6�*�E�G�G��J�J�v��$�	
�
�
�4�8�8�rc��|j�}|�yt|t�stdt	|�z��t|j�r\|jd�}|�It|�}|d=|j|j|�|j�}|d|df|_
|jrtjd|�}|j|�y)Nzstring payload expected: %s�charsetrDrF�>From )�get_payload�
isinstance�str�	TypeError�typer	�_payload�	get_paramr�set_payloadrIr�fcrer]rB)rr.�payloadrns    r�_handle_textzGenerator._handle_text�s����/�/�#���?���'�3�'��9�D��M�I�J�J��3�<�<�(��m�m�I�.�G��"��s�m���3�4�������g�6��/�/�+��#&�'B�#C�#&�~�#6�#8�������h�h�x��1�G����'�"rc�0�g}|j�}|�g}n5t|t�r|j|�yt|t�s|g}|D]`}|j�}|j
|�}|j|d|j��|j|j���b|j�}|s=|jj|�}|j|�}|j|�|j �e|j"r!t$j'd|j �}	n|j }	|j)|	�|j|j�|jd|z|jz�|r*|j*j|j-d��|D]K}
|j|jdz|z|jz�|j*j|
��M|j|jdz|zdz|jz�|j.�K|j"r!t$j'd|j.�}n|j.}|j)|�yy)NF�r/r roz--r)rprqrrr�listr9r$r3r%�appendrN�get_boundaryr'rY�_make_boundary�set_boundary�preamblerrxr]rBr�pop�epilogue)rr.�msgtexts�subparts�partr�g�boundary�alltextr��	body_partr�s            r�_handle_multipartzGenerator._handle_multipart
s�����?�?�$�����H�
��#�
&��J�J�x� ���H�d�+� �z�H��D�� � �"�A��
�
�1�
�A�
�I�I�d�U�D�H�H�I�=��O�O�A�J�J�L�)�	��#�#�%����&�&�+�+�H�5�G��*�*�7�3�H����X�&��<�<�#��!�!��8�8�H�c�l�l�;���<�<�����h�'��J�J�t�x�x� ��
�
�4�(�?�T�X�X�-�.���H�H�N�N�8�<�<��?�+�"�I��J�J�t�x�x�$���1�D�H�H�<�=��H�H�N�N�9�%�	"�	
�
�
�4�8�8�d�?�X�-��4�t�x�x�?�@��<�<�#��!�!��8�8�H�c�l�l�;���<�<�����h�'�$rc��|j}|jd��|_	|j|�||_y#||_wxYw)Nrr!)rr$r�)rr.�ps   r�_handle_multipart_signedz"Generator._handle_multipart_signedGsA��
�K�K���g�g�a�g�0���	��"�"�3�'��D�K��!�D�K�s	�>�	Ac��g}|j�D]�}|j�}|j|�}|j|d|j��|j�}|j
|j�}|r@|d|jk(r.|j|jj|dd����|j|���|jj|jj|��y)NFr|r=)
rpr9r$r3r%rNr?r'r)r~rYrr)rr.�blocksr�rr��textr@s        r�_handle_message_delivery_statusz)Generator._handle_message_delivery_statusRs������O�O�%�D�� � �"�A��
�
�1�
�A�
�I�I�d�U�D�H�H�I�=��:�:�<�D��J�J�t�/�/�0�E���r��d�&9�&9�9��
�
�d�.�.�3�3�E�#�2�J�?�@��
�
�d�#�&�	
�����t�'�'�,�,�V�4�5rc�R�|j�}|j|�}|j}t|t�r>|j|j
d�d|j��|j�}n|j|�}|jj|�y)NrFr|)r9r$rurqr}r3rpr%rNr&rr)rr.rr�rys     r�_handle_messagezGenerator._handle_messagegsz��������J�J�q�M���,�,���g�t�$�
�I�I�c�o�o�a�(�5�$�(�(�I�K��j�j�l�G��l�l�7�+�G������w�rc�@�tjtj�}dt|zzdz}|�|S|}d}	|jdt
j|�zdztj�}|j|�s	|S|dzt|�z}|dz
}�d)Nz===============z==rz^--z(--)?$�.rG)�random�	randrange�sys�maxsize�_fmt�_compile_re�re�escape�	MULTILINErgrr)�clsr��tokenr��b�counter�cres       rr�zGenerator._make_boundary�s���� � ����-������.��5���<��O�������/�/�%�"�)�)�A�,�"6��"A�2�<�<�P�C��:�:�d�#�����3���W��-�A��q�L�G�rc�.�tj||�Sr)r��compile�r�r�flagss   rr�zGenerator._compile_re�s���z�z�!�U�#�#r)NN)FNr)�__name__�
__module__�__qualname__�__doc__rrr3r$r9r&rBr-rJrHrzr[r�r�r�r��classmethodr�r�r;rrrrs�������@�/(�b2�(��	"� %'�N�(
�&#�,�J�8(�t	�6�* �2����"�$��$rrc�N��eZdZdZd�Zd�Zd�Zd�Z�fd�ZeZ	e
d��Z�xZS)ra�Generates a bytes version of a Message object tree.

    Functionally identical to the base Generator except that the output is
    bytes and not string.  When surrogates were used in the input to encode
    bytes, these are decoded back to bytes for output.  If the policy has
    cte_type set to 7bit, then the message is transformed such that the
    non-ASCII bytes are properly content transfer encoded, using the charset
    unknown-8bit.

    The outfp object must accept bytes in its write method.
    c�Z�|jj|jdd��y)N�ascii�surrogateescape)rr�encoders  rrzBytesGenerator.write�s�������q�x�x��):�;�<rc��t�Sr)rr8s rr9zBytesGenerator._new_buffer�s
���y�rc�$�|jd�S�Nr�)r�rs  rr&zBytesGenerator._encode�s���x�x�� � rc���|j�D]�\}}|jj||�}|jjrx|jjj�}|j
|�std|�d|����tj|j|��rtd|����|jj|���|j|j�yra)rbr�fold_binaryrdr r�rer
�NEWLINE_WITHOUT_FWSP_BYTESrgrhrrr%ris      rrHzBytesGenerator._write_headers�s����M�M�O�D�A�q��[�[�,�,�Q��2�F��{�{�3�3��+�+�-�-�4�4�6�����w�/�*�:�7�+�R��z�R�T�T�-�4�4�V�5H�5H��5Q�R�*�:�6�*�E�G�G��H�H�N�N�6�"�$�	
�
�
�4�8�8�rc�<��|j�yt|j�rf|jjdk(sM|jr%t
j
d|j�|_|j|j�ytt|�+|�y)N�7bitro)rur	r�cte_typerrxr]rB�superrrz)rr.r5s  �rrzzBytesGenerator._handle_text�so����<�<����3�<�<�(����1E�1E�v�1M��!�!�#�x�x��#�,�,�?������c�l�l�+��.��3�C�8rc�L�tj|jd�|�Sr�)r�r�r�r�s   rr�zBytesGenerator._compile_re�s���z�z�!�(�(�7�+�U�3�3r)
r�r�r�r�rr9r&rHrzr[r�r��
__classcell__)r5s@rrr�s:���
�=��!��"
9��J��4��4rrzD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c�$�eZdZdZddd�d�Zd�Zy)rz�Generates a text representation of a message.

    Like the Generator base class, except that non-text parts are substituted
    with a format string representing the part.
    Nrc�b�tj|||||��|�t|_y||_y)a�Like Generator.__init__() except that an additional optional
        argument is allowed.

        Walks through all subparts of a message.  If the subpart is of main
        type `text', then it prints the decoded payload of the subpart.

        Otherwise, fmt is a format string that is used instead of the message
        payload.  fmt is expanded with the following keywords (in
        %(keyword)s format):

        type       : Full MIME type of the non-text part
        maintype   : Main MIME type of the non-text part
        subtype    : Sub-MIME type of the non-text part
        filename   : Filename of the non-text part
        description: Description associated with the non-text part
        encoding   : Content transfer encoding of the non-text part

        The default value for fmt is None, meaning

        [Non-text (%(type)s) part of message omitted, filename %(filename)s]
        rN)rr�_FMTr�)rrrr�fmtrs      rrzDecodedGenerator.__init__�s5��.	���4���l�"(�	�	*��;��D�I��D�Irc
��|j�D]�}|j�}|dk(rt|jd��|���6|dk(r�<t|j|j�|j�|j
�|jd�|jdd�|jd	d
�d�z|����y)Nr�F)�decode)�file�	multipartz
[no filename]zContent-Descriptionz[no description]rEz
[no encoding])rt�maintype�subtype�filename�description�encoding)	�walkrV�printrpr��get_content_typerW�get_filenamerK)rr.r�r�s    rrJzDecodedGenerator._dispatch�s����H�H�J�D��0�0�2�H��6�!��d�&�&�e�&�4�4�@��[�(���d�i�i�#'�#8�#8�#:�#'�#<�#<�#>�#'�#;�#;�#=�#'�#4�#4�_�#E�#'�8�8�,A�,>�$@�#'�8�8�,G�,;�$=�	#�	�!�	"�r)NNN)r�r�r�r�rrJr;rrrr�s���
���<"rrrGz%%0%dd)!r��__all__r�r�r+r��copyr�iorr�email.utilsr	�email.errorsr
rX�NLr�r>r�rxrfr�rrr�r�len�reprr��_widthr�r�r;rr�<module>r�s���
A�
=��	�
��
�� �'�)�
�
�	����
�
�=�!���r�z�z�)�R�\�\�*��!�r�z�z�"C�D��'�R�Z�Z�(J�K��x$�x$�v84�Y�84�vN��6"�y�6"�t

�T�#�+�+�a�-�
 �	!���&����)�)�r__pycache__/header.cpython-312.opt-1.pyc000064400000057677151706203560013701 0ustar00�

T��h^���dZgd�ZddlZddlZddlZddlZddlmZddlm	Z
e
jZdZdZ
dZd	Zd
ZdZdZed
�Zed�Zej*dej,ej.z�Zej*d�Zej*d�Zej6j8Zd�Z		dd�ZGd�d�ZGd�d�Z Gd�de!�Z"y)z+Header encoding and decoding functionality.)�Header�
decode_header�make_header�N)�HeaderParseError)�charset�
� � z        ��Nz 	�us-asciizutf-8ai
  =\?                   # literal =?
  (?P<charset>[^?]*?)   # non-greedy up to the next ? is the charset
  \?                    # literal ?
  (?P<encoding>[qQbB])  # either a "q" or a "b", case insensitive
  \?                    # literal ?
  (?P<encoded>.*?)      # non-greedy up to the next ?= is the encoded string
  \?=                   # literal ?=
  z[\041-\176]+:$z
\n[^ \t]+:c
��t|d�rG|jD��cgc]/\}}tj|t	|��t	|�f��1c}}St
j
|�s|dfgSg}|j�D]�}t
j|�}d}|s�|jd�}|r|j�}d}|r|j|ddf�|rc|jd�j�}|jd�j�}|jd�}	|j|	||f�|r����g}
t|�D]K\}}|dkDs�|ds�||dz
ds�||dz
dj�s�8|
j|dz
��Mt|
�D]}
||
=�g}|D]�\}}}|�|j||f��|dk(r3t j"j%|�}|j||f��U|d	k(rOt'|�d
z}|r|ddd
|z
z
}	t j(j+|�}|j||f���t3d
|z��g}dx}}|D]Y\}}t5|t�rt7|d�}|�|}|}�)||k7r|j||f�|}|}�F|�
|t8|zz
}�U||z
}�[|j||f�|Scc}}w#t,j.$rt1d��wxYw)a;Decode a message header value without converting charset.

    Returns a list of (string, charset) pairs containing each of the decoded
    parts of the header.  Charset is None for non-encoded parts of the header,
    otherwise a lower-case string containing the name of the character set
    specified in the encoded string.

    header may be a string that may or may not contain RFC2047 encoded words,
    or it may be a Header object.

    An email.errors.HeaderParseError may be raised when certain decoding error
    occurs (e.g. a base64 decoding exception).
    �_chunksNTrF���q�b�z===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)�hasattrr�_charset�_encode�str�ecre�search�
splitlines�split�pop�lstrip�append�lower�	enumerate�isspace�reversed�email�
quoprimime�
header_decode�len�
base64mime�decode�binascii�Errorr�AssertionError�
isinstance�bytes�BSPACE)�header�stringr�words�line�parts�first�	unencoded�encoding�encoded�droplist�n�w�d�
decoded_words�encoded_string�word�paderr�	collapsed�	last_word�last_charsets                     �%/usr/lib64/python3.12/email/header.pyrr;s8���v�y�!�+1�>�>�;�+9�����!�!�&�#�g�,�7��W��F�+9�;�	;��;�;�v�������
�E��!�!�#���
�
�4� ������	�	�!��I��%�,�,�.�	�������i��t�4�5���)�)�A�,�,�,�.�� �9�9�Q�<�-�-�/���)�)�A�,�����g�x��9�:��$�"�H��%� ���1��Q�3�1�Q�4�E�!�A�#�J�q�M�e�A�a�C�j��m�.C�.C�.E��O�O�A�a�C� �!��h�
���!�H� ��M�-2�)���'���� � �.�'�!:�;�
��_��#�#�1�1�.�A�D�� � �$���1�
��_���(�1�,�F���%���V��"4�4��
6��'�'�.�.�~�>���$�$�d�G�_�5� �!8�8�!C�D�D�%.3�*�I�#�#�I��&�
��g��d�C� ���3�4�D����I�"�L�
��
$����i��6�7��I�"�L�
�
!���$��&�I����I�'����i��.�/����W;��d�>�>�
@�&�'>�?�?�
@�s�4K%�*K+�+L
c��t|||��}|D]4\}}|�t|t�st|�}|j||��6|S)a�Create a Header from a sequence of pairs as returned by decode_header()

    decode_header() takes a header value string and returns a sequence of
    pairs of the format (decoded_string, charset) where charset is the string
    name of the character set.

    This function takes one of those sequence of pairs and returns a Header
    instance.  Optional maxlinelen, header_name, and continuation_ws are as in
    the Header constructor.
    )�
maxlinelen�header_name�continuation_ws)rr-�Charsetr)�decoded_seqrFrGrH�h�srs       rDrr�sQ��	�*�+�.�	0�A�!�
��7���z�'�7�'C��g�&�G�	����G��	"�

�H�c�B�eZdZ			d	d�Zd�Zd�Zd
d�Zd�Zdd�Zd�Z	y)rNc��|�t}nt|t�st|�}||_||_g|_|�|j
|||�|�t}||_|�d|_	yt|�dz|_	y)aDCreate a MIME-compliant header that can contain many character sets.

        Optional s is the initial header value.  If None, the initial header
        value is not set.  You can later append to the header with .append()
        method calls.  s may be a byte string or a Unicode string, but see the
        .append() documentation for semantics.

        Optional charset serves two purposes: it has the same meaning as the
        charset argument to the .append() method.  It also sets the default
        character set for all subsequent .append() calls that omit the charset
        argument.  If charset is not provided in the constructor, the us-ascii
        charset is used both as s's initial charset and as the default for
        subsequent .append() calls.

        The maximum line length can be specified explicitly via maxlinelen. For
        splitting the first line to a shorter value (to account for the field
        header which isn't included in s, e.g. `Subject') pass in the name of
        the field in header_name.  The default maxlinelen is 78 as recommended
        by RFC 2822.

        continuation_ws must be RFC 2822 compliant folding whitespace (usually
        either a space or a hard tab) which will be prepended to continuation
        lines.

        errors is passed through to the .append() call.
        Nrr)�USASCIIr-rIr�_continuation_wsrr�
MAXLINELEN�_maxlinelen�
_headerlenr')�selfrLrrFrGrH�errorss       rD�__init__zHeader.__init__�s���:�?��G��G�W�-��g�&�G���
� /�������=��K�K��7�F�+���#�J�%������D�O�"�+�.��2�D�OrMc��|j�g}d}d}|jD]�\}}|}|tjk(r$|j	dd�}|jdd�}|rU|xr|j
|d�}|dvr|dvr5|s3|jt�d}n|dvr|s|jt�|xr|j
|d�}|}|j|���tj|�S)z&Return the string value of the header.N�ascii�surrogateescape�replacer�Nr
���)�
_normalizerr�UNKNOWN8BIT�encoder)�	_nonctextr�SPACE�EMPTYSTRING�join)	rU�uchunks�lastcs�	lastspacer1r�nextcs�original_bytes�hasspaces	         rD�__str__zHeader.__str__�s������������	�#�|�|�O�F�G��F���-�-�-�!'���w�8I�!J��'�.�.�w�	�B���!�?�d�n�n�V�A�Y�&?���!3�3��!3�3�H����u�-�!%���#5�5�i��N�N�5�)��=�4�>�>�&��*�#=�I��F��N�N�6�"�+ ,�,����(�(rMc��|t|�k(S�N)r)rU�others  rD�__eq__z
Header.__eq__�s����D�	�!�!rMc���|�
|j}nt|t�st|�}t|t�sH|jxsd}|tj
k(r|j
dd�}n|j
||�}|jxsd}|tj
k7r	|j||�|jj||f�y#t$r|dk7r�t}Y�5wxYw)a.Append a string to the MIME header.

        Optional charset, if given, should be a Charset instance or the name
        of a character set (which will be converted to a Charset instance).  A
        value of None (the default) means that the charset given in the
        constructor is used.

        s may be a byte string or a Unicode string.  If it is a byte string
        (i.e. isinstance(s, str) is false), then charset is the encoding of
        that byte string, and a UnicodeError will be raised if the string
        cannot be decoded with that charset.  If s is a Unicode string, then
        charset is a hint specifying the character set of the characters in
        the string.  In either case, when producing an RFC 2822 compliant
        header using RFC 2047 rules, the string will be encoded using the
        output codec of the charset.  If the string cannot be encoded to the
        output codec, a UnicodeError will be raised.

        Optional `errors' is passed as the errors argument to the decode
        call if s is a byte string.
        Nr
rZ)
rr-rIr�input_codecr_r)�output_codecr`�UnicodeEncodeError�UTF8rr)rUrLrrV�
input_charset�output_charsets      rDrz
Header.appends���*�?��m�m�G��G�W�-��g�&�G��!�S�!�#�/�/�=�:�M��� 4� 4�4��H�H�Z�):�;���H�H�]�F�3��!�-�-�;����X�1�1�1�
������0�
	
�����Q��L�)��	&�
�!�:�-����
�s�'C�C/�.C/c�.�|j�xs|dvS)z=True if string s is not a ctext character of RFC822.
        )�(�)�\)r")rUrLs  rDrazHeader._nonctext0s���y�y�{�3�a�#3�3�3rMc�.�|j�|�|j}|dk(rd}t|j||j|�}d}dx}}|j
D�][\}}	|�I|xr|j
|d�}|dvr|r|	dvr'|j�n|	dvr|s|j�|xr|j
|d�}|	}d}|j�}
|
r|jd|
d|	�n|jdd|	�|
ddD]�}|j�|	j�/|j|jd	|j�z|	��N|j�}|dt|�t|�z
}
|j|
||	���t|
�dkDs��L|j���^|j
r|j�|j|�}tj!|�rt#d
j%|���|S)a�Encode a message header into an RFC-compliant format.

        There are many issues involved in converting a given string for use in
        an email header.  Only certain character sets are readable in most
        email clients, and as header strings can only contain a subset of
        7-bit ASCII, care must be taken to properly convert and encode (with
        Base64 or quoted-printable) header strings.  In addition, there is a
        75-character length limit on any given encoded header field, so
        line-wrapping must be performed, even with double-byte character sets.

        Optional maxlinelen specifies the maximum length of each generated
        line, exclusive of the linesep string.  Individual lines may be longer
        than maxlinelen if a folding point cannot be found.  The first line
        will be shorter by the length of the header name plus ": " if a header
        name was specified at Header construction time.  The default value for
        maxlinelen is determined at header construction time.

        Optional splitchars is a string containing characters which should be
        given extra weight by the splitting algorithm during normal header
        wrapping.  This is in very rough support of RFC 2822's `higher level
        syntactic breaks':  split points preceded by a splitchar are preferred
        during line splitting, with the characters preferred in the order in
        which they appear in the string.  Space and tab may be included in the
        string to indicate whether preference should be given to one over the
        other as a split point when other split chars do not appear in the line
        being split.  Splitchars does not affect RFC 2047 encoded lines.

        Optional linesep is a string to be used to separate the lines of
        the value.  The default value is the most useful for typical
        Python applications, but it can be set to \r\n to produce RFC-compliant
        line separators when needed.
        Nri@Br\r]Frrr	z8header value appears to contain an embedded header: {!r})r^rS�_ValueFormatterrTrQrra�add_transitionr�feed�newline�header_encodingrr'�_str�_embedded_headerrr�format)rU�
splitcharsrF�linesep�	formatterrfrjrgr1r�linesr3�sline�fws�values               rDr`z
Header.encode5s��B	
�������)�)�J���?� �J�#�D�O�O�Z�$(�$9�$9�:�G�	���#�#��9�#�|�|�O�F�G��#�!�?�d�n�n�V�A�Y�&?���!3�3�#�w�6H�'H�!�0�0�2��$6�6�y��,�,�.��=�4�>�>�&��*�#=�I��F��H��%�%�'�E�����r�5��8�W�5����r�2�w�/��a�b�	���!�!�#��*�*�6��N�N�4�#8�#8�#����
�:M�#*�,�!�K�K�M�E��4��D�	�#�e�*� 4�5�C��N�N�3��w�7�"��5�z�A�~��!�!�#�5 ,�6�<�<��$�$�&����w�'���"�"�5�)�"�$+�+1�6�%�=�:�
:��rMc��g}d}g}|jD]I\}}||k(r|j|��|�&|jtj|�|f�|g}|}�K|r&|jtj|�|f�||_yrm)rrrbrd)rU�chunksrC�
last_chunkr1rs      rDr^zHeader._normalize�s��������
�#�|�|�O�F�G��,�&��!�!�&�)��+��M�M�5�:�:�j�#9�<�"H�I�$�X�
�&�� ,���M�M�5�:�:�j�1�<�@�A���rM)NNNNr	�strict)Nr�)z;, 	Nr)
�__name__�
__module__�__qualname__rWrkrorrar`r^�rMrDrr�s3��'+�.2�-5�-3�^)�@"�)*�V4�
N�`rMrc�B�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)r|c�|�||_||_t|�|_||_g|_t
|�|_yrm)�_maxlenrQr'�_continuation_ws_len�_splitchars�_lines�_Accumulator�
_current_line)rU�	headerlen�maxlenrHr�s     rDrWz_ValueFormatter.__init__�s:����� /���$'��$8��!�%������)�)�4��rMc�X�|j�|j|j�Srm)rrdr�)rUr�s  rDr�z_ValueFormatter._str�s�������|�|�D�K�K�(�(rMc�,�|jt�Srm)r��NL�rUs rDrkz_ValueFormatter.__str__�s���y�y��}�rMc���|jj�}|dk7r|jj|�t|j�dkDr|jj	�r7|j
r+|j
dxxt
|j�z
cc<n.|j
jt
|j��|jj�y)N)r	rrr])	r�r�pushr'�	is_onlywsr�rr�reset)rU�end_of_lines  rDrz_ValueFormatter.newline�s����(�(�,�,�.���)�#�#�D���#�#�[�1��t�!�!�"�Q�&��!�!�+�+�-�$�+�+����B��3�t�'9�'9�#:�:�����"�"�3�t�'9�'9�#:�;���� � �"rMc�<�|jjdd�y)Nr	r)r�r�r�s rDr}z_ValueFormatter.add_transition�s��������R�(rMc��|j�|j|||j�y|j||j	��}	|jd�}|�|j||�	|j�}|j�|jj|j|�|D]*}|jj|j|z��,y#t$rYywxYw#t$rYywxYw�Nr)r��_ascii_splitr��header_encode_lines�_maxlengthsr�
IndexError�
_append_chunkrr�r�rQr�r)rUr�r1r�
encoded_lines�
first_line�	last_liner3s        rDr~z_ValueFormatter.feed�s����"�"�*����c�6�4�+;�+;�<�� �3�3�F�D�<L�<L�<N�O�
�	�&�*�*�1�-�J��!����s�J�/�	�%�)�)�+�I�	
���������� 5� 5�y�A�!�D��K�K���t�4�4�t�;�<�"���	��	���	��	�s$�C(�2C7�(	C4�3C4�7	D�Dc#�K�|jt|j�z
��	|j|jz
����wrm)r�r'r�r�r�s rDr�z_ValueFormatter._maxlengths�s=�����l�l�S��!3�!3�4�4�4���,�,��!:�!:�:�:��s�AAc���tjdtzdz||z�}|drdg|ddn|jd�t	t|�gdz�D]\}}|j
||��y)Nz([z]+)rrr)�rer�FWSr�zip�iterr�)rUr�r1r�r4�parts      rDr�z_ValueFormatter._ascii_split�sl������c��%���V��4����8���E�"�1�I��I�I�a�L��t�E�{�m�A�o�.�I�C�����s�D�)�/rMc�:�|jj||�t|j�|jkD�r\|jD]�}t|jj
�dz
dd�D]R}|j�r|j|d}|r
|d|k(rn%|j|dz
d}|s�I|d|k(s�Rn��nh|jj�\}}|jjdkDr|j�|sd}|jj||�y|jj|�}|jjt|j��|jj|�yy)Nrrr]r	)r�r�r'r�r��range�
part_countr"r�
_initial_sizer�pop_fromr�rrr�)rUr�r1�ch�i�prevpartr��	remainders        rDr�z_ValueFormatter._append_chunk�so��������V�,��t�!�!�"�T�\�\�1��&�&���t�1�1�<�<�>�q�@�!�R�H�A��z�z�|�"�0�0��3�A�6���3�q�6�2�:�!�#�1�1�!�A�#�6�q�9�H��H�R�L�"�$4��I���'�!�.�.�2�2�4�	��T��%�%�3�3�a�7��L�L�N��"���"�"�'�'��T�2���*�*�3�3�A�6�I��K�K���s�4�#5�#5�6�7����$�$�Y�/�92rMN)r�r�r�rWr�rkrr}r~r�r�r�r�rMrDr|r|�s0��5�)��	#�)�#=�J;�*�,0rMr|c�\��eZdZd
�fd�	Zd�Zd
d�Z�fd�Zd�Zd�Zdd�Z	d�Z
�fd	�Z�xZS)r�c�0��||_t�|�	�yrm)r��superrW)rU�initial_size�	__class__s  �rDrWz_Accumulator.__init__s���)���
���rMc�*�|j||f�yrm)r)rUr�r1s   rDr�z_Accumulator.pushs�����S�&�M�"rMc��||d}g||d|Srmr�)rUr��poppeds   rDr�z_Accumulator.pop_from!s���a�b�����Q�R���
rMc�H��|j�dk(ryt�|�	�S)Nr)rr)r�r�r�rUr�s �rDrz_Accumulator.pop&s!����?�?��a����w�{�}�rMc�<�td�|D�|j�S)Nc3�PK�|]\}}t|�t|�z��� y�wrm)r'��.0r�r�s   rD�	<genexpr>z'_Accumulator.__len__.<locals>.<genexpr>,s"����=��9�3��C��H�S��Y�&����$&)�sumr�r�s rD�__len__z_Accumulator.__len__+s ���=��=��%�%�'�	'rMc�:�tjd�|D��S)Nc3�PK�|]\}}tj||f���� y�wrm�rcrdr�s   rDr�z'_Accumulator.__str__.<locals>.<genexpr>0s+����!7�15�I�C��"-�!1�!1�3��+�!>�15�r�r�r�s rDrkz_Accumulator.__str__/s"�����!7�15�!7�8�	8rMc�$�|�g}||ddd|_yr�)r�)rU�startvals  rDr�z_Accumulator.reset3s�����H���Q����rMc�`�|jdk(xr|xst|�j�Sr�)r�rr"r�s rDr�z_Accumulator.is_onlyws9s,���!�!�1�$�J�d�(�*I�c�$�i�6G�6G�6I�JrMc� ��t�|��Srm)r�r�r�s �rDr�z_Accumulator.part_count<s����w�� � rM)rrm)
r�r�r�rWr�r�rr�rkr�r�r��
__classcell__)r�s@rDr�r�s6����#��
�
'�8��K�!�!rMr�)NNr	)#�__doc__�__all__r�r*�email.quoprimimer$�email.base64mime�email.errorsrrrrIr�rbr/�SPACE8rcrRr�rPrt�compile�VERBOSE�	MULTILINEr�fcrer�r%�_max_appendrrrr|�listr�r�rMrD�<module>r�s��
2���
����)�%�
�
�
��	����	
��	����
�
���
�*�
���w����r�z�z��
�z�z�B�L�L� �"���r�z�z�#�$���2�:�:�m�,�����*�*��[�|;?� #�
�,f�f�R}0�}0�@%!�4�%!rM__pycache__/headerregistry.cpython-312.opt-2.pyc000064400000061371151706203560015455 0ustar00�

T��hSQ��*�	ddlmZddlmZddlmZddlmZGd�d�ZGd�d�ZGd	�d
e	�Z
d�ZGd�d
�ZGd�de�Z
Gd�d�ZGd�de�ZGd�d�ZGd�de�ZGd�de�ZGd�de�ZGd�d�ZGd�d�ZGd �d!e�ZGd"�d#e�ZGd$�d%�ZGd&�d'�Zid(e
�d)e�d*e�d+e�d,e�d-e�d.e�d/e�d0e�d1e�d2e�d3e�d4e�d5e�d6e�d7e�d8e�eeed9��ZGd:�d;�Zy<)=�)�MappingProxyType)�utils)�errors)�_header_value_parserc�f�eZdZd
d�Zed��Zed��Zed��Zed��Zd�Z	d�Z
d	�Zy)�AddressNc	��	djtd||||f��}d|vsd|vrtd��|�w|s|rtd��t	j
|�\}}|rtdj
||���|jr|jd�|j}|j}||_
||_||_y)N��
�
z8invalid arguments; address parts cannot contain CR or LFz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r)
�join�filter�
ValueError�	TypeError�parser�
get_addr_spec�format�all_defects�
local_part�domain�
_display_name�	_username�_domain)�self�display_name�usernamer�	addr_spec�inputs�a_s�rests        �-/usr/lib64/python3.12/email/headerregistry.py�__init__zAddress.__init__s���	� �����|�X�v�y�&Q�R�S���6�>�T�V�^��W�X�X�� ��6��!8�9�9��,�,�Y�7�I�C��� �"=�=C�V�$'��>4�5�5�����o�o�a�(�(��~�~�H��Z�Z�F�)���!������c��|jS�N�r�rs r!rzAddress.display_name8����!�!�!r#c��|jSr%)rr's r!rzAddress.username<����~�~�r#c��|jSr%)rr's r!rzAddress.domain@����|�|�r#c���	|j}tjj|�stj|�}|j
r|dz|j
zS|sy|S)N�@�<>)rr�
DOT_ATOM_ENDS�
isdisjoint�quote_stringr)r�lps  r!rzAddress.addr_specDs[��	��]�]���#�#�.�.�r�2��$�$�R�(�B��;�;���8�d�k�k�)�)����	r#c��dj|jj|j|j|j
�S)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r�	__class__�__name__rrrr's r!�__repr__zAddress.__repr__Rs9��B�I�I����/�/��)�)�4�=�=�$�+�+�G�	Gr#c��|j}tjj|�stj|�}|r/|j
dk(rdn|j
}dj
||�S|j
S)Nr/r
z{} <{}>)rr�SPECIALSr1r2rr)r�disprs   r!�__str__zAddress.__str__Wse��� � �����)�)�$�/��&�&�t�,�D��"�n�n�d�2�����I��#�#�D�)�4�4��~�~�r#c���t|t�stS|j|jk(xr4|j|jk(xr|j
|j
k(Sr%)�
isinstancer�NotImplementedrrr�r�others  r!�__eq__zAddress.__eq__`sU���%��)�!�!��!�!�U�%7�%7�7�,��
�
����/�,����u�|�|�+�	-r#)r
r
r
N)r6�
__module__�__qualname__r"�propertyrrrrr7r;rA�r#r!rrsh��(�T�"��"�������������G�
�-r#rc�F�eZdZdd�Zed��Zed��Zd�Zd�Zd�Z	y)	�GroupNc�X�	||_|rt|�|_yt�|_yr%)r�tuple�
_addresses)rr�	addressess   r!r"zGroup.__init__js'��
	�*���.7�%�	�*���U�W��r#c��|jSr%r&r's r!rzGroup.display_name|r(r#c��|jSr%)rJr's r!rKzGroup.addresses�s�����r#c�x�dj|jj|j|j�S)Nz${}(display_name={!r}, addresses={!r})rr5r6rrKr's r!r7zGroup.__repr__�s1��5�<�<����(�(��"�"�D�N�N�4�	4r#c�x�|j�0t|j�dk(rt|jd�S|j}|�4tj
j
|�st	j|�}djd�|jD��}|rd|zn|}dj||�S)N�r�, c3�2K�|]}t|����y�wr%)�str)�.0�xs  r!�	<genexpr>z Group.__str__.<locals>.<genexpr>�s����:�>�a�3�q�6�>�s�� z{}:{};)
r�lenrKrSrr9r1r2r
r)rr:�adrstrs   r!r;z
Group.__str__�s������$��T�^�^�)<�a�)?��t�~�~�a�(�)�)�� � ����F�O�O�$>�$>�t�$D��&�&�t�,�D����:�4�>�>�:�:��!'��v��V�����t�V�,�,r#c��t|t�stS|j|jk(xr|j|jk(Sr%)r=rGr>rrKr?s  r!rAzGroup.__eq__�s@���%��'�!�!��!�!�U�%7�%7�7�2����%�/�/�1�	3r#)NN)
r6rBrCr"rDrrKr7r;rArEr#r!rGrGhs?��E�$�"��"�����4�
-�3r#rGc�V�eZdZ	d�Zd�Zed��Zed��Zd�Ze	d��Z
d�Zy)	�
BaseHeaderc��dgi}|j||�tj|d�rtj|d�|d<tj||d�}|d=|j|fi|��|S)N�defects�decoded)�parser�_has_surrogates�	_sanitizerS�__new__�init)�cls�name�value�kwdsrs     r!rczBaseHeader.__new__�st���2����	�	�%���� � ��i��1�#�o�o�d�9�o�>�D��O��{�{�3��Y��0����O���	�	�$��$���r#c�.�||_||_||_yr%)�_name�_parse_tree�_defects)rrf�
parse_treer^s    r!rdzBaseHeader.init�s����
�%�����
r#c��|jSr%)rjr's r!rfzBaseHeader.name�s���z�z�r#c�,�t|j�Sr%)rIrlr's r!r^zBaseHeader.defects�s���T�]�]�#�#r#c��t|jj|jjt	|�f|j�fSr%)�_reconstruct_headerr5r6�	__bases__rS�__getstate__r's r!�
__reduce__zBaseHeader.__reduce__�sC������'�'����(�(��D�	�
�

����!�	!r#c�.�tj||�Sr%)rSrc)rergs  r!�_reconstructzBaseHeader._reconstruct�s���{�{�3��&�&r#c	��	tjtjtj|jd�tjdd�g�g�}|j
r9|j
tjtjdd�g��|j
|j
�|j|��S)Nzheader-name�:z
header-seprW�fws)�policy)
r�Header�HeaderLabel�
ValueTerminalrfrk�append�CFWSList�WhiteSpaceTerminal�fold)rrz�headers   r!r�zBaseHeader.fold�s���	� �������$�$�T�Y�Y�
�>��$�$�S�,�7� 9�
:� ���
����M�M�����!:�!:�3��!F� G�H�
J��
�
�d�&�&�'��{�{�&�{�)�)r#N)r6rBrCrcrdrDrfr^rt�classmethodrvr�rEr#r!r\r\�sX���@� �
�����$��$�!��'��'�*r#r\c�:�t||i�j|�Sr%)�typerv)�cls_name�basesrgs   r!rqrqs����%��$�1�1�%�8�8r#c�D�eZdZdZeej�Zed��Z	y)�UnstructuredHeaderNc�N�|j|�|d<t|d�|d<y)Nrmr_)�value_parserrS�rergrhs   r!r`zUnstructuredHeader.parse	s*�� �-�-�e�4��\���d�<�0�1��Y�r#)
r6rBrC�	max_count�staticmethodr�get_unstructuredr�r�r`rEr#r!r�r�s)���I��� 7� 7�8�L��2��2r#r�c��eZdZdZy)�UniqueUnstructuredHeaderrPN�r6rBrCr�rEr#r!r�r�����Ir#r�c�h��eZdZ	dZeej�Zed��Z	�fd�Z
ed��Z�xZ
S)�
DateHeaderNc��|sH|djtj��d|d<d|d<tj�|d<yt|t�r||d<	tj|�}||d<tj|d�|d<|j|d�|d<y#t$rF|djtjd��d|d<tj�|d<YywxYw)Nr^�datetimer
r_rmzInvalid date value or format)
r~r�HeaderMissingRequiredValuer�	TokenListr=rSr�parsedate_to_datetimer�InvalidDateDefect�format_datetimer�r�s   r!r`zDateHeader.parse$s������O�"�"�6�#D�#D�#F�G�#�D��� �D��O�!'�!1�!1�!3�D�����e�S�!�#�D��O�
��3�3�E�:��!��Z���/�/��Z�0@�A��Y�� �-�-�d�9�o�>��\����
��Y��&�&�v�'?�'?�@^�'_�`�#'��Z� �%+�%5�%5�%7��\�"��	
�s�!B.�.AC=�<C=c�P��|jd�|_t�|�|i|��y)Nr�)�pop�	_datetime�superrd�r�args�kwr5s   �r!rdzDateHeader.init9s$������
�+���
���d�!�b�!r#c��|jSr%)r�r's r!r�zDateHeader.datetime=r*r#)r6rBrCr�r�rr�r�r�r`rdrDr��
__classcell__�r5s@r!r�r�sL�����I� �� 7� 7�8�L��?��?�("����r#r�c��eZdZdZy)�UniqueDateHeaderrPNr�rEr#r!r�r�Br�r#r�c�b��eZdZdZed��Zed��Z�fd�Ze	d��Z
e	d��Z�xZS)�
AddressHeaderNc�6�tj|�\}}|Sr%)r�get_address_list)rg�address_lists  r!r�zAddressHeader.value_parserKs��$�5�5�e�<���e��r#c��t|t�r�|j|�x|d<}g}|jD]t}|j	t|j|jD�cgc]9}t|jxsd|jxsd|jxsd���;c}���vt|j�}n9t|d�s|g}|D�cgc]}t|d�s
td|g�n|��}}g}||d<||d<dj|D�cgc]
}t|���c}�|d<d|vr|j|d�|d<yycc}wcc}wcc}w)	Nrmr
�__iter__rK�groupsr^rQr_)r=rSr�rKr~rGr�
all_mailboxesrrr�listr�hasattrr
)	rergrhr�r��addr�mbr^�items	         r!r`zAddressHeader.parseQs����e�S�!�14�0@�0@��0G�G�D�����F�$�.�.���
�
�e�D�$5�$5�04�/A�/A�%C�0B��&-�R�_�_�-B��-/�]�]�-@�b�-/�Y�Y�_�"�&>�0B�%C�D�E�/��<�3�3�4�G��5�*�-����16�7�05��29��{�1K�e�D�4�&�)�/3�4�05�
�7��G���X��!��Y���)�)�6�$B�6�4�S��Y�6�$B�C��Y���t�#�!$�!1�!1�$�y�/�!B�D���$��!%C��7��%Cs�!>E
�"E�Ec�p��t|jd��|_d|_t	�|�|i|��y)Nr�)rIr��_groupsrJr�rdr�s   �r!rdzAddressHeader.initms0����R�V�V�H�-�.������
���d�!�b�!r#c��|jSr%)r�r's r!r�zAddressHeader.groupsrr,r#c�t�|j�!td�|jD��|_|jS)Nc3�BK�|]}|jD]}|����y�wr%)rK)rT�group�addresss   r!rVz*AddressHeader.addresses.<locals>.<genexpr>ys(����$L���;@�?�?��%,�;J�%,��s�)rJrIr�r's r!rKzAddressHeader.addressesvs5���?�?�"�#�$L����$L�L�D�O����r#)
r6rBrCr�r�r�r�r`rdrDr�rKr�r�s@r!r�r�Gs]����I�����
�C��C�6"�
�������r#r�c��eZdZdZy)�UniqueAddressHeaderrPNr�rEr#r!r�r�~r�r#r�c��eZdZed��Zy)�SingleAddressHeaderc��t|j�dk7r$tdj|j���|jdS)NrPz9value of single address header {} is not a single addressr)rXrKrrrfr's r!r�zSingleAddressHeader.address�sB���t�~�~���!��#�$*�F�4�9�9�$5�7�
7��~�~�a� � r#N)r6rBrCrDr�rEr#r!r�r��s��
�!��!r#r�c��eZdZdZy)�UniqueSingleAddressHeaderrPNr�rEr#r!r�r��r�r#r�c���eZdZdZeej�Zed��Z	�fd�Z
ed��Zed��Z
ed��Z�xZS)�MIMEVersionHeaderrPc�:�|j|�x|d<}t|�|d<|dj|j�|j�dn|j
|d<|j|d<|j�dj
|d|d�|d<yd|d<y)Nrmr_r^�major�minorz{}.{}�version)r�rS�extendrr�r�r�rergrhrms    r!r`zMIMEVersionHeader.parse�s���*-�*:�*:�5�*A�A��\��Z��j�/��Y���Y����z�5�5�6� *� 0� 0� 8��j�>N�>N��W�
�"�(�(��W�
����'�%�n�n�T�'�]�D��M�J�D��O�"�D��Or#c���|jd�|_|jd�|_|jd�|_t	�|�|i|��y)Nr�r�r�)r��_version�_major�_minorr�rdr�s   �r!rdzMIMEVersionHeader.init�sB������y�)��
��f�f�W�o����f�f�W�o���
���d�!�b�!r#c��|jSr%)r�r's r!r�zMIMEVersionHeader.major�����{�{�r#c��|jSr%)r�r's r!r�zMIMEVersionHeader.minor�r�r#c��|jSr%)r�r's r!r�zMIMEVersionHeader.version�����}�}�r#)r6rBrCr�r�r�parse_mime_versionr�r�r`rdrDr�r�r�r�r�s@r!r�r��sk����I��� 9� 9�:�L��	#��	#�"������������r#r�c�B��eZdZdZed��Z�fd�Zed��Z�xZ	S)�ParameterizedMIMEHeaderrPc�f�|j|�x|d<}t|�|d<|dj|j�|j�i|d<y|jD��cic]<\}}tj|�j�tj|���>c}}|d<ycc}}w)Nrmr_r^�params)r�rSr�rr�rrb�lower)rergrhrmrfs     r!r`zParameterizedMIMEHeader.parse�s���*-�*:�*:�5�*A�A��\��Z��j�/��Y���Y����z�5�5�6����$��D��N�
3=�2C�2C�E�2C�;�4��$�o�o�d�3�9�9�;�$)�O�O�E�$:�;�2C�E�D��N��Es�$AB-c�P��|jd�|_t�|�|i|��y)Nr�)r��_paramsr�rdr�s   �r!rdzParameterizedMIMEHeader.init�s$����v�v�h�'���
���d�!�b�!r#c�,�t|j�Sr%)rr�r's r!r�zParameterizedMIMEHeader.params�s������-�-r#)
r6rBrCr�r�r`rdrDr�r�r�s@r!r�r��s7���
�I��
E��
E�"��.��.r#r�c�r��eZdZeej
�Z�fd�Zed��Z	ed��Z
ed��Z�xZS)�ContentTypeHeaderc����t�|�|i|��tj|jj
�|_tj|jj�|_yr%)	r�rdrrbrk�maintype�	_maintype�subtype�_subtyper�s   �r!rdzContentTypeHeader.init�sL���
���d�!�b�!�����)9�)9�)B�)B�C�������(8�(8�(@�(@�A��
r#c��|jSr%)r�r's r!r�zContentTypeHeader.maintype�r*r#c��|jSr%)r�r's r!r�zContentTypeHeader.subtype�r�r#c�:�|jdz|jzS)N�/)r�r�r's r!�content_typezContentTypeHeader.content_type�s���}�}�s�"�T�\�\�1�1r#)
r6rBrCr�r�parse_content_type_headerr�rdrDr�r�r�r�r�s@r!r�r��sU����� @� @�A�L�B�
���������2��2r#r�c�R��eZdZeej
�Z�fd�Zed��Z	�xZ
S)�ContentDispositionHeaderc���t�|�|i|��|jj}|�||_yt	j
|�|_yr%)r�rdrk�content_dispositionrrb�_content_disposition)rr�r��cdr5s    �r!rdzContentDispositionHeader.init�sA���
���d�!�b�!�
�
�
�
1�
1��*,�*�B��!�%�/�/�"�:M��!r#c��|jSr%)r�r's r!r�z,ContentDispositionHeader.content_disposition�s���(�(�(r#)r6rBrCr�r� parse_content_disposition_headerr�rdrDr�r�r�s@r!r�r��s-����� G� G�H�L�N�
�)��)r#r�c�f��eZdZdZeej�Zed��Z	�fd�Z
ed��Z�xZ
S)�ContentTransferEncodingHeaderrPc��|j|�x|d<}t|�|d<|dj|j�y�Nrmr_r^�r�rSr�rr�s    r!r`z#ContentTransferEncodingHeader.parse��A��*-�*:�*:�5�*A�A��\��Z��j�/��Y���Y����z�5�5�6r#c���t�|�|i|��tj|jj
�|_yr%)r�rdrrbrk�cte�_cter�s   �r!rdz"ContentTransferEncodingHeader.inits0���
���d�!�b�!��O�O�D�$4�$4�$8�$8�9��	r#c��|jSr%)r�r's r!r�z!ContentTransferEncodingHeader.ctes���y�y�r#)r6rBrCr�r�r�&parse_content_transfer_encoding_headerr�r�r`rdrDr�r�r�s@r!r�r��sC����I��� M� M�N�L��7��7�
:����r#r�c�D�eZdZdZeej�Zed��Z	y)�MessageIDHeaderrPc��|j|�x|d<}t|�|d<|dj|j�yr�r�r�s    r!r`zMessageIDHeader.parser�r#N)
r6rBrCr�r�r�parse_message_idr�r�r`rEr#r!rr
s)���I��� 7� 7�8�L��7��7r#r�subject�datezresent-datez	orig-date�senderz
resent-sender�toz	resent-to�ccz	resent-cc�bccz
resent-bcc�fromzresent-fromzreply-tozmime-versionzcontent-type)zcontent-dispositionzcontent-transfer-encodingz
message-idc�.�eZdZ	eedfd�Zd�Zd�Zd�Zy)�HeaderRegistryTc�t�	i|_||_||_|r |jjt�yyr%)�registry�
base_class�
default_class�update�_default_header_map)rrr�use_default_maps    r!r"zHeaderRegistry.__init__6s:��		���
�$���*�����M�M� � �!4�5�r#c�@�	||j|j�<yr%)r
r��rrfres   r!�map_to_typezHeaderRegistry.map_to_typeHs��	�'*��
�
�d�j�j�l�#r#c��|jj|j�|j�}t	d|j
z||jfi�S)N�_)r
�getr�rr�r6rrs   r!�__getitem__zHeaderRegistry.__getitem__NsE���m�m����
�
��d�.@�.@�A���C����$�s�D�O�O�&<�b�A�Ar#c��	||||�Sr%rE)rrfrgs   r!�__call__zHeaderRegistry.__call__Rs��	��t�D�z�$��&�&r#N)	r6rBrCr\r�r"rrrrEr#r!rr2s#��/�",�<N�'+�6�$*�B�
'r#rN)�typesr�emailrrrrrrGrSr\rqr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrEr#r!�<module>rs����
#���0�Y-�Y-�x/3�/3�ha*��a*�H9�2�2��1��
+�+�\�z��
4�4�n�-��
!�-�!�� 3��
"�"�J.�.�:2�/�2�,)�6�)���*	7�	7��
�$<��
�$4���J���$4�	�

�$=���$7�
�	�$7���M��	�$7���M��
�$7���M���$7���M���$7�� �$5�!�"�$5�#�$%=�$A�$3�)��.*'�*'r#__pycache__/headerregistry.cpython-312.pyc000064400000074367151706203560014526 0ustar00�

T��hSQ��,�dZddlmZddlmZddlmZddlmZGd�d�ZGd�d	�Z	Gd
�de
�Zd�ZGd
�d�Z
Gd�de
�ZGd�d�ZGd�de�ZGd�d�ZGd�de�ZGd�de�ZGd�de�ZGd�d�ZGd�d �ZGd!�d"e�ZGd#�d$e�ZGd%�d&�ZGd'�d(�Zid)e�d*e�d+e�d,e�d-e�d.e�d/e�d0e�d1e�d2e�d3e�d4e�d5e�d6e�d7e�d8e�d9e�eeed:��ZGd;�d<�Zy=)>z�Representing and manipulating email headers via custom objects.

This module provides an implementation of the HeaderRegistry API.
The implementation is designed to flexibly follow RFC5322 rules.
�)�MappingProxyType)�utils)�errors)�_header_value_parserc�f�eZdZd
d�Zed��Zed��Zed��Zed��Zd�Z	d�Z
d	�Zy)�AddressNc	��djtd||||f��}d|vsd|vrtd��|�w|s|rtd��t	j
|�\}}|rtdj
||���|jr|jd�|j}|j}||_
||_||_y)	a�Create an object representing a full email address.

        An address can have a 'display_name', a 'username', and a 'domain'.  In
        addition to specifying the username and domain separately, they may be
        specified together by using the addr_spec keyword *instead of* the
        username and domain keywords.  If an addr_spec string is specified it
        must be properly quoted according to RFC 5322 rules; an error will be
        raised if it is not.

        An Address object has display_name, username, domain, and addr_spec
        attributes, all of which are read-only.  The addr_spec and the string
        value of the object are both quoted according to RFC5322 rules, but
        without any Content Transfer Encoding.

        �N�
�
z8invalid arguments; address parts cannot contain CR or LFz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r)
�join�filter�
ValueError�	TypeError�parser�
get_addr_spec�format�all_defects�
local_part�domain�
_display_name�	_username�_domain)�self�display_name�usernamer�	addr_spec�inputs�a_s�rests        �-/usr/lib64/python3.12/email/headerregistry.py�__init__zAddress.__init__s���"�����|�X�v�y�&Q�R�S���6�>�T�V�^��W�X�X�� ��6��!8�9�9��,�,�Y�7�I�C��� �"=�=C�V�$'��>4�5�5�����o�o�a�(�(��~�~�H��Z�Z�F�)���!������c��|jS�N�r�rs r!rzAddress.display_name8����!�!�!r#c��|jSr%)rr's r!rzAddress.username<����~�~�r#c��|jSr%)rr's r!rzAddress.domain@����|�|�r#c���|j}tjj|�stj|�}|j
r|dz|j
zS|sy|S)z�The addr_spec (username@domain) portion of the address, quoted
        according to RFC 5322 rules, but with no Content Transfer Encoding.
        �@�<>)rr�
DOT_ATOM_ENDS�
isdisjoint�quote_stringr)r�lps  r!rzAddress.addr_specDsV��
�]�]���#�#�.�.�r�2��$�$�R�(�B��;�;���8�d�k�k�)�)����	r#c��dj|jj|j|j|j
�S)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r�	__class__�__name__rrrr's r!�__repr__zAddress.__repr__Rs9��B�I�I����/�/��)�)�4�=�=�$�+�+�G�	Gr#c��|j}tjj|�stj|�}|r/|j
dk(rdn|j
}dj
||�S|j
S)Nr/r
z{} <{}>)rr�SPECIALSr1r2rr)r�disprs   r!�__str__zAddress.__str__Wse��� � �����)�)�$�/��&�&�t�,�D��"�n�n�d�2�����I��#�#�D�)�4�4��~�~�r#c���t|t�stS|j|jk(xr4|j|jk(xr|j
|j
k(Sr%)�
isinstancer�NotImplementedrrr�r�others  r!�__eq__zAddress.__eq__`sU���%��)�!�!��!�!�U�%7�%7�7�,��
�
����/�,����u�|�|�+�	-r#)r
r
r
N)r6�
__module__�__qualname__r"�propertyrrrrr7r;rA�r#r!rrsh��(�T�"��"�������������G�
�-r#rc�F�eZdZdd�Zed��Zed��Zd�Zd�Zd�Z	y)	�GroupNc�V�||_|rt|�|_yt�|_y)aCreate an object representing an address group.

        An address group consists of a display_name followed by colon and a
        list of addresses (see Address) terminated by a semi-colon.  The Group
        is created by specifying a display_name and a possibly empty list of
        Address objects.  A Group can also be used to represent a single
        address that is not in a group, which is convenient when manipulating
        lists that are a combination of Groups and individual Addresses.  In
        this case the display_name should be set to None.  In particular, the
        string representation of a Group whose display_name is None is the same
        as the Address object, if there is one and only one Address object in
        the addresses list.

        N)r�tuple�
_addresses)rr�	addressess   r!r"zGroup.__init__js"��*���.7�%�	�*���U�W��r#c��|jSr%r&r's r!rzGroup.display_name|r(r#c��|jSr%)rJr's r!rKzGroup.addresses�s�����r#c�x�dj|jj|j|j�S)Nz${}(display_name={!r}, addresses={!r})rr5r6rrKr's r!r7zGroup.__repr__�s1��5�<�<����(�(��"�"�D�N�N�4�	4r#c�x�|j�0t|j�dk(rt|jd�S|j}|�4tj
j
|�st	j|�}djd�|jD��}|rd|zn|}dj||�S)N�r�, c3�2K�|]}t|����y�wr%)�str)�.0�xs  r!�	<genexpr>z Group.__str__.<locals>.<genexpr>�s����:�>�a�3�q�6�>�s�� z{}:{};)
r�lenrKrSrr9r1r2r
r)rr:�adrstrs   r!r;z
Group.__str__�s������$��T�^�^�)<�a�)?��t�~�~�a�(�)�)�� � ����F�O�O�$>�$>�t�$D��&�&�t�,�D����:�4�>�>�:�:��!'��v��V�����t�V�,�,r#c��t|t�stS|j|jk(xr|j|jk(Sr%)r=rGr>rrKr?s  r!rAzGroup.__eq__�s@���%��'�!�!��!�!�U�%7�%7�7�2����%�/�/�1�	3r#)NN)
r6rBrCr"rDrrKr7r;rArEr#r!rGrGhs?��E�$�"��"�����4�
-�3r#rGc�X�eZdZdZd�Zd�Zed��Zed��Zd�Z	e
d��Zd�Zy	)
�
BaseHeadera|Base class for message headers.

    Implements generic behavior and provides tools for subclasses.

    A subclass must define a classmethod named 'parse' that takes an unfolded
    value string and a dictionary as its arguments.  The dictionary will
    contain one key, 'defects', initialized to an empty list.  After the call
    the dictionary must contain two additional keys: parse_tree, set to the
    parse tree obtained from parsing the header, and 'decoded', set to the
    string value of the idealized representation of the data from the value.
    (That is, encoded words are decoded, and values that have canonical
    representations are so represented.)

    The defects key is intended to collect parsing defects, which the message
    parser will subsequently dispose of as appropriate.  The parser should not,
    insofar as practical, raise any errors.  Defects should be added to the
    list instead.  The standard header parsers register defects for RFC
    compliance issues, for obsolete RFC syntax, and for unrecoverable parsing
    errors.

    The parse method may add additional keys to the dictionary.  In this case
    the subclass must define an 'init' method, which will be passed the
    dictionary as its keyword arguments.  The method should use (usually by
    setting them as the value of similarly named attributes) and remove all the
    extra keys added by its parse method, and then use super to call its parent
    class with the remaining arguments and keywords.

    The subclass should also make sure that a 'max_count' attribute is defined
    that is either None or 1. XXX: need to better define this API.

    c��dgi}|j||�tj|d�rtj|d�|d<tj||d�}|d=|j|fi|��|S)N�defects�decoded)�parser�_has_surrogates�	_sanitizerS�__new__�init)�cls�name�value�kwdsrs     r!rczBaseHeader.__new__�st���2����	�	�%���� � ��i��1�#�o�o�d�9�o�>�D��O��{�{�3��Y��0����O���	�	�$��$���r#c�.�||_||_||_yr%)�_name�_parse_tree�_defects)rrf�
parse_treer^s    r!rdzBaseHeader.init�s����
�%�����
r#c��|jSr%)rjr's r!rfzBaseHeader.name�s���z�z�r#c�,�t|j�Sr%)rIrlr's r!r^zBaseHeader.defects�s���T�]�]�#�#r#c��t|jj|jjt	|�f|j�fSr%)�_reconstruct_headerr5r6�	__bases__rS�__getstate__r's r!�
__reduce__zBaseHeader.__reduce__�sC������'�'����(�(��D�	�
�

����!�	!r#c�.�tj||�Sr%)rSrc)rergs  r!�_reconstructzBaseHeader._reconstruct�s���{�{�3��&�&r#c	��tjtjtj|jd�tjdd�g�g�}|j
r9|j
tjtjdd�g��|j
|j
�|j|��S)atFold header according to policy.

        The parsed representation of the header is folded according to
        RFC5322 rules, as modified by the policy.  If the parse tree
        contains surrogateescaped bytes, the bytes are CTE encoded using
        the charset 'unknown-8bit".

        Any non-ASCII characters in the parse tree are CTE encoded using
        charset utf-8. XXX: make this a policy setting.

        The returned value is an ASCII-only string possibly containing linesep
        characters, and ending with a linesep character.  The string includes
        the header name and the ': ' separator.

        zheader-name�:z
header-seprW�fws)�policy)
r�Header�HeaderLabel�
ValueTerminalrfrk�append�CFWSList�WhiteSpaceTerminal�fold)rrz�headers   r!r�zBaseHeader.fold�s���"�������$�$�T�Y�Y�
�>��$�$�S�,�7� 9�
:� ���
����M�M�����!:�!:�3��!F� G�H�
J��
�
�d�&�&�'��{�{�&�{�)�)r#N)
r6rBrC�__doc__rcrdrDrfr^rt�classmethodrvr�rEr#r!r\r\�sX���@� �
�����$��$�!��'��'�*r#r\c�:�t||i�j|�Sr%)�typerv)�cls_name�basesrgs   r!rqrqs����%��$�1�1�%�8�8r#c�D�eZdZdZeej�Zed��Z	y)�UnstructuredHeaderNc�N�|j|�|d<t|d�|d<y)Nrmr_)�value_parserrS�rergrhs   r!r`zUnstructuredHeader.parse	s*�� �-�-�e�4��\���d�<�0�1��Y�r#)
r6rBrC�	max_count�staticmethodr�get_unstructuredr�r�r`rEr#r!r�r�s)���I��� 7� 7�8�L��2��2r#r�c��eZdZdZy)�UniqueUnstructuredHeaderrPN�r6rBrCr�rEr#r!r�r�����Ir#r�c�j��eZdZdZdZeej�Ze	d��Z
�fd�Zed��Z
�xZS)�
DateHeadera�Header whose value consists of a single timestamp.

    Provides an additional attribute, datetime, which is either an aware
    datetime using a timezone, or a naive datetime if the timezone
    in the input string is -0000.  Also accepts a datetime as input.
    The 'value' attribute is the normalized form of the timestamp,
    which means it is the output of format_datetime on the datetime.
    Nc��|sH|djtj��d|d<d|d<tj�|d<yt|t�r||d<	tj|�}||d<tj|d�|d<|j|d�|d<y#t$rF|djtjd��d|d<tj�|d<YywxYw)Nr^�datetimer
r_rmzInvalid date value or format)
r~r�HeaderMissingRequiredValuer�	TokenListr=rSr�parsedate_to_datetimer�InvalidDateDefect�format_datetimer�r�s   r!r`zDateHeader.parse$s������O�"�"�6�#D�#D�#F�G�#�D��� �D��O�!'�!1�!1�!3�D�����e�S�!�#�D��O�
��3�3�E�:��!��Z���/�/��Z�0@�A��Y�� �-�-�d�9�o�>��\����
��Y��&�&�v�'?�'?�@^�'_�`�#'��Z� �%+�%5�%5�%7��\�"��	
�s�!B.�.AC=�<C=c�P��|jd�|_t�|�|i|��y)Nr�)�pop�	_datetime�superrd�r�args�kwr5s   �r!rdzDateHeader.init9s$������
�+���
���d�!�b�!r#c��|jSr%)r�r's r!r�zDateHeader.datetime=r*r#)r6rBrCr�r�r�rr�r�r�r`rdrDr��
__classcell__�r5s@r!r�r�sL�����I� �� 7� 7�8�L��?��?�("����r#r�c��eZdZdZy)�UniqueDateHeaderrPNr�rEr#r!r�r�Br�r#r�c�b��eZdZdZed��Zed��Z�fd�Ze	d��Z
e	d��Z�xZS)�
AddressHeaderNc�H�tj|�\}}|rJd��|S)Nzthis should not happen)r�get_address_list)rg�address_lists  r!r�zAddressHeader.value_parserKs+��$�5�5�e�<���e��2�2�2�y��r#c��t|t�r�|j|�x|d<}g}|jD]t}|j	t|j|jD�cgc]9}t|jxsd|jxsd|jxsd���;c}���vt|j�}n9t|d�s|g}|D�cgc]}t|d�s
td|g�n|��}}g}||d<||d<dj|D�cgc]
}t|���c}�|d<d|vr|j|d�|d<yycc}wcc}wcc}w)	Nrmr
�__iter__rK�groupsr^rQr_)r=rSr�rKr~rGr�
all_mailboxesrrr�listr�hasattrr
)	rergrhr�r��addr�mbr^�items	         r!r`zAddressHeader.parseQs����e�S�!�14�0@�0@��0G�G�D�����F�$�.�.���
�
�e�D�$5�$5�04�/A�/A�%C�0B��&-�R�_�_�-B��-/�]�]�-@�b�-/�Y�Y�_�"�&>�0B�%C�D�E�/��<�3�3�4�G��5�*�-����16�7�05��29��{�1K�e�D�4�&�)�/3�4�05�
�7��G���X��!��Y���)�)�6�$B�6�4�S��Y�6�$B�C��Y���t�#�!$�!1�!1�$�y�/�!B�D���$��!%C��7��%Cs�!>E
�"E�Ec�p��t|jd��|_d|_t	�|�|i|��y)Nr�)rIr��_groupsrJr�rdr�s   �r!rdzAddressHeader.initms0����R�V�V�H�-�.������
���d�!�b�!r#c��|jSr%)r�r's r!r�zAddressHeader.groupsrr,r#c�t�|j�!td�|jD��|_|jS)Nc3�BK�|]}|jD]}|����y�wr%)rK)rT�group�addresss   r!rVz*AddressHeader.addresses.<locals>.<genexpr>ys(����$L���;@�?�?��%,�;J�%,��s�)rJrIr�r's r!rKzAddressHeader.addressesvs5���?�?�"�#�$L����$L�L�D�O����r#)
r6rBrCr�r�r�r�r`rdrDr�rKr�r�s@r!r�r�Gs]����I�����
�C��C�6"�
�������r#r�c��eZdZdZy)�UniqueAddressHeaderrPNr�rEr#r!r�r�~r�r#r�c��eZdZed��Zy)�SingleAddressHeaderc��t|j�dk7r$tdj|j���|jdS)NrPz9value of single address header {} is not a single addressr)rXrKrrrfr's r!r�zSingleAddressHeader.address�sB���t�~�~���!��#�$*�F�4�9�9�$5�7�
7��~�~�a� � r#N)r6rBrCrDr�rEr#r!r�r��s��
�!��!r#r�c��eZdZdZy)�UniqueSingleAddressHeaderrPNr�rEr#r!r�r��r�r#r�c���eZdZdZeej�Zed��Z	�fd�Z
ed��Zed��Z
ed��Z�xZS)�MIMEVersionHeaderrPc�:�|j|�x|d<}t|�|d<|dj|j�|j�dn|j
|d<|j|d<|j�dj
|d|d�|d<yd|d<y)Nrmr_r^�major�minorz{}.{}�version)r�rS�extendrr�r�r�rergrhrms    r!r`zMIMEVersionHeader.parse�s���*-�*:�*:�5�*A�A��\��Z��j�/��Y���Y����z�5�5�6� *� 0� 0� 8��j�>N�>N��W�
�"�(�(��W�
����'�%�n�n�T�'�]�D��M�J�D��O�"�D��Or#c���|jd�|_|jd�|_|jd�|_t	�|�|i|��y)Nr�r�r�)r��_version�_major�_minorr�rdr�s   �r!rdzMIMEVersionHeader.init�sB������y�)��
��f�f�W�o����f�f�W�o���
���d�!�b�!r#c��|jSr%)r�r's r!r�zMIMEVersionHeader.major�����{�{�r#c��|jSr%)r�r's r!r�zMIMEVersionHeader.minor�r�r#c��|jSr%)r�r's r!r�zMIMEVersionHeader.version�����}�}�r#)r6rBrCr�r�r�parse_mime_versionr�r�r`rdrDr�r�r�r�r�s@r!r�r��sk����I��� 9� 9�:�L��	#��	#�"������������r#r�c�B��eZdZdZed��Z�fd�Zed��Z�xZ	S)�ParameterizedMIMEHeaderrPc�f�|j|�x|d<}t|�|d<|dj|j�|j�i|d<y|jD��cic]<\}}tj|�j�tj|���>c}}|d<ycc}}w)Nrmr_r^�params)r�rSr�rr�rrb�lower)rergrhrmrfs     r!r`zParameterizedMIMEHeader.parse�s���*-�*:�*:�5�*A�A��\��Z��j�/��Y���Y����z�5�5�6����$��D��N�
3=�2C�2C�E�2C�;�4��$�o�o�d�3�9�9�;�$)�O�O�E�$:�;�2C�E�D��N��Es�$AB-c�P��|jd�|_t�|�|i|��y)Nr�)r��_paramsr�rdr�s   �r!rdzParameterizedMIMEHeader.init�s$����v�v�h�'���
���d�!�b�!r#c�,�t|j�Sr%)rr�r's r!r�zParameterizedMIMEHeader.params�s������-�-r#)
r6rBrCr�r�r`rdrDr�r�r�s@r!r�r��s7���
�I��
E��
E�"��.��.r#r�c�r��eZdZeej
�Z�fd�Zed��Z	ed��Z
ed��Z�xZS)�ContentTypeHeaderc����t�|�|i|��tj|jj
�|_tj|jj�|_yr%)	r�rdrrbrk�maintype�	_maintype�subtype�_subtyper�s   �r!rdzContentTypeHeader.init�sL���
���d�!�b�!�����)9�)9�)B�)B�C�������(8�(8�(@�(@�A��
r#c��|jSr%)r�r's r!r�zContentTypeHeader.maintype�r*r#c��|jSr%)r�r's r!r�zContentTypeHeader.subtype�r�r#c�:�|jdz|jzS)N�/)r�r�r's r!�content_typezContentTypeHeader.content_type�s���}�}�s�"�T�\�\�1�1r#)
r6rBrCr�r�parse_content_type_headerr�rdrDr�r�r�r�r�s@r!r�r��sU����� @� @�A�L�B�
���������2��2r#r�c�R��eZdZeej
�Z�fd�Zed��Z	�xZ
S)�ContentDispositionHeaderc���t�|�|i|��|jj}|�||_yt	j
|�|_yr%)r�rdrk�content_dispositionrrb�_content_disposition)rr�r��cdr5s    �r!rdzContentDispositionHeader.init�sA���
���d�!�b�!�
�
�
�
1�
1��*,�*�B��!�%�/�/�"�:M��!r#c��|jSr%)r�r's r!r�z,ContentDispositionHeader.content_disposition�s���(�(�(r#)r6rBrCr�r� parse_content_disposition_headerr�rdrDr�r�r�s@r!r�r��s-����� G� G�H�L�N�
�)��)r#r�c�f��eZdZdZeej�Zed��Z	�fd�Z
ed��Z�xZ
S)�ContentTransferEncodingHeaderrPc��|j|�x|d<}t|�|d<|dj|j�y�Nrmr_r^�r�rSr�rr�s    r!r`z#ContentTransferEncodingHeader.parse��A��*-�*:�*:�5�*A�A��\��Z��j�/��Y���Y����z�5�5�6r#c���t�|�|i|��tj|jj
�|_yr%)r�rdrrbrk�cte�_cter�s   �r!rdz"ContentTransferEncodingHeader.inits0���
���d�!�b�!��O�O�D�$4�$4�$8�$8�9��	r#c��|jSr%)r�r's r!r�z!ContentTransferEncodingHeader.ctes���y�y�r#)r6rBrCr�r�r�&parse_content_transfer_encoding_headerr�r�r`rdrDr�r�r�s@r!r�r��sC����I��� M� M�N�L��7��7�
:����r#r�c�D�eZdZdZeej�Zed��Z	y)�MessageIDHeaderrPc��|j|�x|d<}t|�|d<|dj|j�yr�r�r�s    r!r`zMessageIDHeader.parser�r#N)
r6rBrCr�r�r�parse_message_idr�r�r`rEr#r!rr
s)���I��� 7� 7�8�L��7��7r#r�subject�datezresent-datez	orig-date�senderz
resent-sender�toz	resent-to�ccz	resent-cc�bccz
resent-bcc�fromzresent-fromzreply-tozmime-versionzcontent-type)zcontent-dispositionzcontent-transfer-encodingz
message-idc�0�eZdZdZeedfd�Zd�Zd�Zd�Z	y)�HeaderRegistryz%A header_factory and header registry.Tc�r�i|_||_||_|r |jjt�yy)a�Create a header_factory that works with the Policy API.

        base_class is the class that will be the last class in the created
        header class's __bases__ list.  default_class is the class that will be
        used if "name" (see __call__) does not appear in the registry.
        use_default_map controls whether or not the default mapping of names to
        specialized classes is copied in to the registry when the factory is
        created.  The default is True.

        N)�registry�
base_class�
default_class�update�_default_header_map)rrr�use_default_maps    r!r"zHeaderRegistry.__init__6s5����
�$���*�����M�M� � �!4�5�r#c�>�||j|j�<y)zLRegister cls as the specialized class for handling "name" headers.

        N)rr��rrfres   r!�map_to_typezHeaderRegistry.map_to_typeHs��'*��
�
�d�j�j�l�#r#c��|jj|j�|j�}t	d|j
z||jfi�S)N�_)r�getr�rr�r6rrs   r!�__getitem__zHeaderRegistry.__getitem__NsE���m�m����
�
��d�.@�.@�A���C����$�s�D�O�O�&<�b�A�Ar#c��||||�S)a�Create a header instance for header 'name' from 'value'.

        Creates a header instance by creating a specialized class for parsing
        and representing the specified header by combining the factory
        base_class with a specialized class from the registry or the
        default_class, and passing the name and value to the constructed
        class's constructor.

        rE)rrfrgs   r!�__call__zHeaderRegistry.__call__Rs���t�D�z�$��&�&r#N)
r6rBrCr�r\r�r"rrrrEr#r!rr2s#��/�",�<N�'+�6�$*�B�
'r#rN)r��typesr�emailrrrrrrGrSr\rqr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrEr#r!�<module>rs����
#���0�Y-�Y-�x/3�/3�ha*��a*�H9�2�2��1��
+�+�\�z��
4�4�n�-��
!�-�!�� 3��
"�"�J.�.�:2�/�2�,)�6�)���*	7�	7��
�$<��
�$4���J���$4�	�

�$=���$7�
�	�$7���M��	�$7���M��
�$7���M���$7���M���$7�� �$5�!�"�$5�#�$%=�$A�$3�)��.*'�*'r#__pycache__/iterators.cpython-312.opt-1.pyc000064400000005361151706203560014444 0ustar00�

T��hQ��B�dZgd�ZddlZddlmZd�Zd	d�Zd
d�Zdd�Zy)z1Various types of useful iterators and generators.)�body_line_iterator�typed_subpart_iterator�walk�N)�StringIOc#�K�|��|j�r.|j�D]}|j�Ed{����yy7��w)z�Walk over the message tree, yielding each subpart.

    The walk is performed in depth-first order.  This method is a
    generator.
    N)�is_multipart�get_payloadr)�self�subparts  �(/usr/lib64/python3.12/email/iterators.pyrrsC�����J������'�'�)�G��|�|�~�%�%�*��%�s�;A�A�	Ac#�K�|j�D]8}|j|��}t|t�s�&t	|�Ed{����:y7��w)z�Iterate over the parts, returning string payloads line-by-line.

    Optional decode (default False) is passed through to .get_payload().
    )�decodeN)rr	�
isinstance�strr)�msgrr�payloads    rrr sH����
�8�8�:���%�%�V�%�4���g�s�#���(�(�(��
)�s�6A�A�A�Ac#�K�|j�D]0}|j�|k(s�|�|j�|k(s�-|���2y�w)z�Iterate over the subparts with a given MIME type.

    Use `maintype' as the main MIME type to match against; this defaults to
    "text".  Optional `subtype' is the MIME subtype to match against; if
    omitted, only the main type is matched.
    N)r�get_content_maintype�get_content_subtype)r�maintype�subtypers    rrr+sC�����8�8�:���'�'�)�X�5���'�"=�"=�"?�7�"J��
��s�'A�A�Ac�>�|�tj}d|dzz}t||j�zd|��|rtd|j	�z|��nt|��|j�r'|j
�D]}t|||dz|��yy)	zA handy debugging aidN� ��)�end�filez [%s])r�)�sys�stdout�print�get_content_type�get_default_typerr	�
_structure)r�fp�level�include_default�tabrs      rr$r$8s���	�z�
�Z�Z��

����
�C�	�#��$�$�&�
&�B�R�8��
�g��,�,�.�.�R�8�
�2��
�������(�G��w��E�!�G�_�=�)��)F)�textN)NrF)	�__doc__�__all__r�iorrrrr$�r)r�<module>r/s-��
8�����	&�)�
�>r)__pycache__/iterators.cpython-312.opt-2.pyc000064400000004243151706203560014443 0ustar00�

T��hQ��@�	gd�ZddlZddlmZd�Zdd�Zd	d�Zd
d�Zy))�body_line_iterator�typed_subpart_iterator�walk�N)�StringIOc#�K�	|��|j�r.|j�D]}|j�Ed{����yy7��w�N)�is_multipart�get_payloadr)�self�subparts  �(/usr/lib64/python3.12/email/iterators.pyrrsH�����
�J������'�'�)�G��|�|�~�%�%�*��%�s�<A	�A�	A	c#�K�	|j�D]8}|j|��}t|t�s�&t	|�Ed{����:y7��w)N)�decode)rr
�
isinstance�strr)�msgrr�payloads    r
rr sM������8�8�:���%�%�V�%�4���g�s�#���(�(�(��
)�s�7A�A�A�	Ac#�K�	|j�D]0}|j�|k(s�|�|j�|k(s�-|���2y�wr)r�get_content_maintype�get_content_subtype)r�maintype�subtypers    r
rr+sH������8�8�:���'�'�)�X�5���'�"=�"=�"?�7�"J��
��s�(A�A�Ac�@�	|�tj}d|dzz}t||j�zd|��|rtd|j	�z|��nt|��|j�r'|j
�D]}t|||dz|��yy)N� ��)�end�filez [%s])r�)�sys�stdout�print�get_content_type�get_default_typer	r
�
_structure)r�fp�level�include_default�tabrs      r
r%r%8s����	�z�
�Z�Z��

����
�C�	�#��$�$�&�
&�B�R�8��
�g��,�,�.�.�R�8�
�2��
�������(�G��w��E�!�G�_�=�)��)F)�textN)NrF)�__all__r �iorrrrr%�r*r
�<module>r/s-��
8�����	&�)�
�>r*__pycache__/iterators.cpython-312.pyc000064400000005361151706203560013505 0ustar00�

T��hQ��B�dZgd�ZddlZddlmZd�Zd	d�Zd
d�Zdd�Zy)z1Various types of useful iterators and generators.)�body_line_iterator�typed_subpart_iterator�walk�N)�StringIOc#�K�|��|j�r.|j�D]}|j�Ed{����yy7��w)z�Walk over the message tree, yielding each subpart.

    The walk is performed in depth-first order.  This method is a
    generator.
    N)�is_multipart�get_payloadr)�self�subparts  �(/usr/lib64/python3.12/email/iterators.pyrrsC�����J������'�'�)�G��|�|�~�%�%�*��%�s�;A�A�	Ac#�K�|j�D]8}|j|��}t|t�s�&t	|�Ed{����:y7��w)z�Iterate over the parts, returning string payloads line-by-line.

    Optional decode (default False) is passed through to .get_payload().
    )�decodeN)rr	�
isinstance�strr)�msgrr�payloads    rrr sH����
�8�8�:���%�%�V�%�4���g�s�#���(�(�(��
)�s�6A�A�A�Ac#�K�|j�D]0}|j�|k(s�|�|j�|k(s�-|���2y�w)z�Iterate over the subparts with a given MIME type.

    Use `maintype' as the main MIME type to match against; this defaults to
    "text".  Optional `subtype' is the MIME subtype to match against; if
    omitted, only the main type is matched.
    N)r�get_content_maintype�get_content_subtype)r�maintype�subtypers    rrr+sC�����8�8�:���'�'�)�X�5���'�"=�"=�"?�7�"J��
��s�'A�A�Ac�>�|�tj}d|dzz}t||j�zd|��|rtd|j	�z|��nt|��|j�r'|j
�D]}t|||dz|��yy)	zA handy debugging aidN� ��)�end�filez [%s])r�)�sys�stdout�print�get_content_type�get_default_typerr	�
_structure)r�fp�level�include_default�tabrs      rr$r$8s���	�z�
�Z�Z��

����
�C�	�#��$�$�&�
&�B�R�8��
�g��,�,�.�.�R�8�
�2��
�������(�G��w��E�!�G�_�=�)��)F)�textN)NrF)	�__doc__�__all__r�iorrrrr$�r)r�<module>r/s-��
8�����	&�)�
�>r)__pycache__/message.cpython-312.pyc000064400000147500151706203560013117 0ustar00�

T��hW����dZddgZddlZddlZddlZddlmZmZddlm	Z	ddlm
Z
ddlmZdd	lm
Zdd
lmZej"ZdZej&d�Zd
�Zdd�Zd�Zd�Zd�ZGd�d�ZGd�de�ZGd�de�Zy)z8Basic message object for the email package object model.�Message�EmailMessage�N)�BytesIO�StringIO)�utils)�errors)�compat32��charset)�decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]c��t|�jd�\}}}|s|j�dfS|j�|j�fS)N�;)�str�	partition�strip)�param�a�sep�bs    �&/usr/lib64/python3.12/email/message.py�_splitparamrsH��
�E�
�$�$�S�)�I�A�s�A���w�w�y�$����7�7�9�a�g�g�i���c��|��t|�dkDr�t|t�r,|dz
}tj|d|d|d�}|�d|��S	|jd�|stj|�r|�d	tj|��d
�S|�d|��S|S#t$r&|dz
}tj|dd�}|�d|��cYSwxYw)a~Convenience function to format and return a key=value pair.

    This will quote the value if needed or if quote is true.  If value is a
    three tuple (charset, language, value), it will be encoded according
    to RFC2231 rules.  If it contains non-ascii characters it will likewise
    be encoded according to RFC2231 rules, using the utf-8 charset and
    a null language.
    r�*���=�asciizutf-8�z="�")
�len�
isinstance�tupler�encode_rfc2231�encode�UnicodeEncodeError�	tspecials�search�quote)r�valuer)s   r�_formatparamr+'s���
��S��Z�!�^��e�U�#��S�L�E��(�(��q��5��8�U�1�X�F�E�#�U�+�+�
0����W�%��I�$�$�U�+� %�u�{�{�5�'9�:�:�#�U�+�+����&�
0������,�,�U�G�R�@��"'��/�/�
0�s�B�,C	�C	c�r�dt|�z}g}|dddk(�r|dd}|jd�}|dkDro|jdd|�|jdd|�z
dzrE|jd|dz�}|dkDr+|jdd|�|jdd|�z
dzr�E|dkrt|�}|d|}d|vrL|j	d�}|d|j�j
�dz||dzdj�z}|j|j��||d}|dddk(r��|S)Nrrrr z\"rr)r�find�countr!�indexr�lower�append)�s�plist�end�f�is     r�_parseparamr7Is?���c�!�f��A��E�
�B�Q�%�3�,�
�a�b�E���f�f�S�k���A�g�1�7�7�3��3�/�!�'�'�%��C�2H�H�A�M��&�&��c�A�g�&�C��A�g�1�7�7�3��3�/�!�'�'�%��C�2H�H�A�M���7��a�&�C�
�d�s�G���!�8������A��"�1����
�#�#�%��+�a��!���g�m�m�o�=�A�
���Q�W�W�Y��
�c�d�G���B�Q�%�3�,��Lrc��t|t�r!|d|dtj|d�fStj|�S)Nrrr)r"r#r�unquote)r*s r�
_unquotevaluer:]s?��
�%����Q�x��q��5�=�=��q��#:�:�:��}�}�U�#�#rc�R�g}t|j��}|D]G}|jd�s�|jd�j	d�\}}}	t|d��nt
d��|D]L}|st
d��|jd�dk(rn)	tj|�}|j|��Ndj|�S#t$rY��wxYw#tj$r/|d	d
z
dzdzd
zdz}tj|d|�}Y�twxYw)zDecode uuencoded data.sbegin � �)�basez`begin` line not foundzTruncated inputs 	
sendr� �?���Nr)
�iter�
splitlines�
startswith�removeprefixr�int�
ValueErrorr�binascii�a2b_uu�Errorr1�join)	�encoded�
decoded_lines�encoded_lines_iter�line�mode�_�path�decoded_line�nbytess	         r�
_decode_uurWhs2���M��g�0�0�2�3��"���?�?�9�%� �-�-�i�8�B�B�4�H�M�D�!�T�
��D�q�!��#��1�2�2�"����.�/�/�
�Z�Z��
%��
/��	:�#�?�?�4�0�L�
	���\�*�#��8�8�M�"�"��'�
��
���~�~�	:��Q���
�b�(�A�-��1�a�7�F�#�?�?�4���=�9�L�	:�s$�
C�C$�	C!� C!�$?D&�%D&c�T�eZdZdZefd�Zd�Zd2d�Zd�Zd3d�Z	d	�Z
d
�Zd�Zd�Z
d4d
�Zd5d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd5d�Zd�Zd�Zd5d�Zd�Zd�Z d �Z!d!�Z"d"�Z#d#�Z$d$�Z%d%�Z&d6d&�Z'		d6d'�Z(		d7d(�Z)d8d)�Z*d9d*�Z+d5d+�Z,d5d,�Z-d-�Z.d5d.�Z/d5d/�Z0d0�Z1dd1l2m3Z3y):ra�Basic message object.

    A message object is defined as something that has a bunch of RFC 2822
    headers and a payload.  It may optionally have an envelope header
    (a.k.a. Unix-From or From_ header).  If the message is a container (i.e. a
    multipart or a message/rfc822), then the payload is a list of Message
    objects, otherwise it is a string.

    Message objects implement part of the `mapping' interface, which assumes
    there is exactly one occurrence of the header per message.  Some headers
    do in fact appear multiple times (e.g. Received) and for those headers,
    you must use the explicit API to set or get all the headers.  Not all of
    the mapping methods are implemented.
    c��||_g|_d|_d|_d|_dx|_|_g|_d|_y)N�
text/plain)	�policy�_headers�	_unixfrom�_payload�_charset�preamble�epilogue�defects�
_default_type)�selfr[s  r�__init__zMessage.__init__�sB�������
������
���
�(,�,��
��
����)��rc�"�|j�S)z9Return the entire formatted message as a string.
        )�	as_string�rds r�__str__zMessage.__str__�s���~�~��rrNc��ddlm}|�|jn|}t�}||d||��}|j	||��|j�S)a�Return the entire formatted message as a string.

        Optional 'unixfrom', when true, means include the Unix From_ envelope
        header.  For backward compatibility reasons, if maxheaderlen is
        not specified it defaults to 0, so you must override it explicitly
        if you want a different maxheaderlen.  'policy' is passed to the
        Generator instance used to serialize the message; if it is not
        specified the policy associated with the message instance is used.

        If the message object contains binary data that is not encoded
        according to RFC standards, the non-compliant data will be replaced by
        unicode "unknown character" code points.
        r)�	GeneratorF)�mangle_from_�maxheaderlenr[��unixfrom)�email.generatorrkr[r�flatten�getvalue)rdrormr[rk�fp�gs       rrgzMessage.as_string�sP��	.� &�����F��
�Z���b�#(�#/�#�
%��	
�	�	�$��	�*��{�{�}�rc�"�|j�S)z?Return the entire formatted message as a bytes object.
        )�as_bytesrhs r�	__bytes__zMessage.__bytes__�s���}�}��rc��ddlm}|�|jn|}t�}||d|��}|j	||��|j�S)aJReturn the entire formatted message as a bytes object.

        Optional 'unixfrom', when true, means include the Unix From_ envelope
        header.  'policy' is passed to the BytesGenerator instance used to
        serialize the message; if not specified the policy associated with
        the message instance is used.
        r)�BytesGeneratorF)rlr[rn)rpryr[rrqrr)rdror[ryrsrts      rrvzMessage.as_bytes�sG��	3� &�����F��
�Y���2�E�&�A��	�	�	�$��	�*��{�{�}�rc�6�t|jt�S)z6Return True if the message consists of multiple parts.)r"r^�listrhs r�is_multipartzMessage.is_multipart�s���$�-�-��.�.rc��||_y�N�r])rdros  r�set_unixfromzMessage.set_unixfrom�s	��!��rc��|jSr~rrhs r�get_unixfromzMessage.get_unixfrom�s���~�~�rc��|j�	|g|_y	|jj|�y#t$rtd��wxYw)z�Add the given payload to the current payload.

        The current payload will always be a list of objects after this method
        is called.  If you want to set the payload to a scalar object, use
        set_payload() instead.
        Nz=Attach is not valid on a message with a non-multipart payload)r^r1�AttributeError�	TypeError)rd�payloads  r�attachzMessage.attach�sO���=�=� �$�I�D�M�
:��
�
�$�$�W�-��!�
:��!9�:�:�
:�s	�3�Ac��|j�r |ry|�|jS|j|S|�;t|jt�s!t	dt|j�z��|j}|j
dd�}t|d�r
|j}n't|�j�j�}|s^t|t�rLtj|�r7	|jdd�}	|j|j!d�d�}|S|St|t�r	|jdd�}|d
k(rt'j(�S|dk(rPt+dj-j/���\}}|D]}|j0j3||�� |S|d
vr	t5�St|t�rS|S#t"$r|jdd�}Y|SwxYw#t$$rY|SwxYw#t$$r|jd	�}Y��wxYw#t6$rcYSwxYw)aZReturn a reference to the payload.

        The payload will either be a list object or a string.  If you mutate
        the list object, you modify the message's payload in place.  Optional
        i returns that index into the payload.

        Optional decode is a flag indicating whether the payload should be
        decoded or not, according to the Content-Transfer-Encoding header
        (default is False).

        When True and the message is not a multipart, the payload will be
        decoded if this header's value is `quoted-printable' or `base64'.  If
        some other encoding is used, or the header is missing, or if the
        payload has bogus data (i.e. bogus base64 or uuencoded data), the
        payload is returned as-is.

        If the message is a multipart and the decode flag is True, then None
        is returned.
        NzExpected list, got %szcontent-transfer-encodingr�cter�surrogateescape�replace�raw-unicode-escapezquoted-printable�base64r)z
x-uuencode�uuencode�uuezx-uue)r|r^r"r{r��type�get�hasattrr�rrr0r�_has_surrogatesr%�decode�get_content_charset�LookupErrorr&�quopri�decodestringrrMrEr[�
handle_defectrWrI)	rdr6r�r�r��bpayloadr*rb�defects	         r�get_payloadzMessage.get_payload�s8��D�������y��}�}�$��}�}�Q�'�'�
�=��D�M�M�4�!@��3�d�4�=�=�6I�I�J�J��-�-���h�h�2�B�7���3����'�'�C��c�(�.�.�"�(�(�*�C���'�3�'�E�,A�,A�'�,J��&�~�~�g�7H�I�H�F�"*�/�/�$�2J�2J�7�2S�U^�"_��
�N�7�N��g�s�#�
@�"�>�>�'�3D�E���$�$��&�&�x�0�0�
�H�_�&�c�h�h�x�/B�/B�/D�&E�F�N�E�7�!�����)�)�$��7�"��L�
�>�
>�
 �!�(�+�+��g�s�#��O����?'�F�"*�/�/�'�9�"E���N�	F��)����N���&�
@�
#�>�>�*>�?��
@��$�
 ���
 �sT�4H�!G"�=H�
H4�"H�=H�H�H�	H�H�H1�0H1�4I�Ic��t|d�rA|�||_yt|t�st|�}|j	|j
d�}t|d�r|j
dd�|_n||_|�|j|�yy)z�Set the payload to the given value.

        Optional charset sets the message's default character set.  See
        set_charset() for details.
        r%Nr�r�r)r�r^r"�Charsetr%�output_charsetr��set_charset)rdr�rs   r�set_payloadzMessage.set_payloadOs����7�H�%��� '��
���g�w�/�!�'�*���n�n�W�%;�%;�=N�O�G��7�H�%�#�N�N�7�4E�F�D�M�#�D�M������W�%�rc���|�|jd�d|_yt|t�st|�}||_d|vr|j	dd�d|vr#|j	dd|j���n |j
d|j��||j�k7r |j|j�|_d|vr|j�}	||�yy#t$rw|j}|r>	|jd	d
�}n*#t$r|j|j�}YnwxYw|j|�|_|j	d|�YywxYw)a�Set the charset of the payload to a given character set.

        charset can be a Charset instance, a string naming a character set, or
        None.  If it is a string it will be converted to a Charset instance.
        If charset is None, the charset parameter will be removed from the
        Content-Type field.  Anything else will generate a TypeError.

        The message will be assumed to be of type text/* encoded with
        charset.input_charset.  It will be converted to charset.output_charset
        and encoded properly, if needed, when generating the plain text
        representation of the message.  MIME headers (MIME-Version,
        Content-Type, Content-Transfer-Encoding) will be added as needed.
        Nr�MIME-Version�1.0�Content-TyperZr
zContent-Transfer-Encodingrr�)�	del_paramr_r"r��
add_header�get_output_charset�	set_param�body_encoder^�get_body_encodingr�r%�UnicodeErrorr�)rdrr�r�s    rr�zMessage.set_charsetcs`���?��N�N�9�%� �D�M���'�7�+��g�&�G���
���%��O�O�N�E�2���%��O�O�N�L�$+�$>�$>�$@�
�
B�
�N�N�9�g�&@�&@�&B�C��g�0�0�2�2�#�/�/��
�
�>�D�M�&�d�2��+�+�-�C�

B��D�	�3���
B��-�-���I�")�.�.��:K�"L���'�I�")�.�.��1G�1G�"H��I�� '� 3� 3�G� <��
���� ;�S�A�
B�s6�#C-�-E-�D�E-�$D?�<E-�>D?�?+E-�,E-c��|jS)zKReturn the Charset instance associated with the message's payload.
        )r_rhs r�get_charsetzMessage.get_charset�s���}�}�rc�,�t|j�S)z9Return the total number of headers, including duplicates.)r!r\rhs r�__len__zMessage.__len__�s���4�=�=�!�!rc�$�|j|�S)a-Get a header value.

        Return None if the header is missing instead of raising an exception.

        Note that if the header appeared multiple times, exactly which
        occurrence gets returned is undefined.  Use get_all() to get all
        the values matching a header field name.
        )r�)rd�names  r�__getitem__zMessage.__getitem__�s���x�x��~�rc�f�|jj|�}|r_|j�}d}|jD]>\}}|j�|k(s�|dz
}||k\s�%t	dj||���|jj
|jj||��y)z�Set the value of a header.

        Note: this does not overwrite an existing header with the same field
        name.  Use __delitem__() first to delete any existing headers.
        rrz/There may be at most {} {} headers in a messageN)r[�header_max_countr0r\rI�formatr1�header_store_parse)rdr��val�	max_count�lname�found�k�vs        r�__setitem__zMessage.__setitem__�s����K�K�0�0��6�	���J�J�L�E��E��
�
���1��7�7�9��%��Q�J�E��	�)�(�*8�8>��y�$�8O�Q�Q�	&�	
�
�
���T�[�[�;�;�D�#�F�Grc��|j�}g}|jD],\}}|j�|k7s�|j||f��.||_y)zwDelete all occurrences of a header, if present.

        Does not raise an exception if the header is missing.
        N)r0r\r1)rdr��
newheadersr�r�s     r�__delitem__zMessage.__delitem__�sO��
�z�z�|���
��M�M�D�A�q��w�w�y�D� ��!�!�1�a�&�)�"�#��
rc�v�|j�}|jD]\}}||j�k(s�yy)NTF)r0r\)rdr��
name_lowerr�r�s     r�__contains__zMessage.__contains__�s5���Z�Z�\�
��M�M�D�A�q��Q�W�W�Y�&��"�rc#�<K�|jD]	\}}|���y�wr~�r\)rd�fieldr*s   r�__iter__zMessage.__iter__�s���� �M�M�L�E�5��K�*�s�c�L�|jD��cgc]\}}|��	c}}Scc}}w)a.Return a list of all the message's header field names.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        r��rdr�r�s   r�keyszMessage.keys�s$��#�m�m�,�m�d�a���m�,�,��,s� c��|jD��cgc]!\}}|jj||���#c}}Scc}}w)a)Return a list of all the message's header values.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        �r\r[�header_fetch_parser�s   r�valueszMessage.values�sB��!�M�M�+�)�D�A�q����.�.�q�!�4�)�+�	+��+s�&:c	��|jD��cgc]#\}}||jj||�f��%c}}Scc}}w)a'Get all the message's header fields and values.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        r�r�s   r�itemsz
Message.items�sG��!�M�M�+�)�D�A�q��D�K�K�2�2�1�a�8�9�)�+�	+��+s�(<c��|j�}|jD]6\}}|j�|k(s�|jj||�cS|S)z~Get a header value.

        Like __getitem__() but return failobj instead of None when the field
        is missing.
        )r0r\r[r�)rdr��failobjr�r�s     rr�zMessage.get�sM���z�z�|���M�M�D�A�q��w�w�y�D� ��{�{�5�5�a��;�;�"��rc�>�|jj||f�y)z�Store name and value in the model without modification.

        This is an "internal" API, intended only for use by a parser.
        N)r\r1)rdr�r*s   r�set_rawzMessage.set_raws��
	
�
�
���d�E�]�+rc�H�t|jj��S)z�Return the (name, value) header pairs without modification.

        This is an "internal" API, intended only for use by a generator.
        )rDr\�copyrhs r�	raw_itemszMessage.raw_items
s��
�D�M�M�&�&�(�)�)rc���g}|j�}|jD]D\}}|j�|k(s�|j|jj	||���F|s|S|S)aQReturn a list of all the values for the named field.

        These will be sorted in the order they appeared in the original
        message, and may contain duplicates.  Any fields deleted and
        re-inserted are always appended to the header list.

        If no such fields exist, failobj is returned (defaults to None).
        )r0r\r1r[r�)rdr�r�r�r�r�s      r�get_allzMessage.get_alls`�����z�z�|���M�M�D�A�q��w�w�y�D� ��
�
�d�k�k�<�<�Q��B�C�"���N��
rc	�.�g}|j�D]T\}}|�"|j|jdd���*|jt|jdd�|���V|�|j	d|�t
j
|�||<y)u�Extended header setting.

        name is the header field to add.  keyword arguments can be used to set
        additional parameters for the header field, with underscores converted
        to dashes.  Normally the parameter will be added as key="value" unless
        value is None, in which case only the key will be added.  If a
        parameter value contains non-ASCII characters it can be specified as a
        three-tuple of (charset, language, value), in which case it will be
        encoded according to RFC2231 rules.  Otherwise it will be encoded using
        the utf-8 charset and a language of ''.

        Examples:

        msg.add_header('content-disposition', 'attachment', filename='bud.gif')
        msg.add_header('content-disposition', 'attachment',
                       filename=('utf-8', '', Fußballer.ppt'))
        msg.add_header('content-disposition', 'attachment',
                       filename='Fußballer.ppt'))
        NrS�-r)r�r1r�r+�insert�	SEMISPACErM)rd�_name�_value�_params�partsr�r�s       rr�zMessage.add_header's��(���M�M�O�D�A�q��y����Q�Y�Y�s�C�0�1����\�!�)�)�C��*=�q�A�B�	$�
���L�L��F�#��n�n�U�+��U�rc�.�|j�}ttt|j��|j�D]F\}\}}|j�|k(s�|j
j
||�|j|<yt|��)z�Replace a header.

        Replace the first matching header found in the message, retaining
        header order and case.  If no matching header was found, a KeyError is
        raised.
        N)r0�zip�ranger!r\r[r��KeyError)rdr�r�r6r�r�s      r�replace_headerzMessage.replace_headerEsw�����
���U�3�t�}�}�#5�6��
�
�F�I�A�v��1��w�w�y�E�!�#'�;�;�#A�#A�!�V�#L��
�
�a� ��G�
�5�/�!rc���t�}|jd|�}||ur|j�St|�dj	�}|jd�dk7ry|S)a0Return the message's content type.

        The returned string is coerced to lower case of the form
        `maintype/subtype'.  If there was no Content-Type header in the
        message, the default type as given by get_default_type() will be
        returned.  Since according to RFC 2045, messages always have a default
        type this will always return a value.

        RFC 2045 defines a message's default type to be text/plain unless it
        appears inside a multipart/digest container, in which case it would be
        message/rfc822.
        �content-typer�/rrZ)�objectr��get_default_typerr0r.)rd�missingr*�ctypes    r�get_content_typezMessage.get_content_typeXsc���(�������1���G���(�(�*�*��E�"�1�%�+�+�-���;�;�s��q� ���rc�J�|j�}|jd�dS)z�Return the message's main content type.

        This is the `maintype' part of the string returned by
        get_content_type().
        r�r�r��split�rdr�s  r�get_content_maintypezMessage.get_content_maintypep�&���%�%�'���{�{�3���"�"rc�J�|j�}|jd�dS)z�Returns the message's sub-content type.

        This is the `subtype' part of the string returned by
        get_content_type().
        r�rr�r�s  r�get_content_subtypezMessage.get_content_subtypeyr�rc��|jS)aReturn the `default' content type.

        Most messages have a default content type of text/plain, except for
        messages that are subparts of multipart/digest containers.  Such
        subparts have a default content type of message/rfc822.
        �rcrhs rr�zMessage.get_default_type�s���!�!�!rc��||_y)z�Set the `default' content type.

        ctype should be either "text/plain" or "message/rfc822", although this
        is not enforced.  The default content type is not stored in the
        Content-Type header.
        Nr�r�s  r�set_default_typezMessage.set_default_type�s��#��rc�l�t�}|j||�}||ur|Sg}t|�D]K}	|jdd�\}}|j	�}|j	�}|j
||f��Mtj|�}|S#t
$r|j	�}d}Y�IwxYw)Nrrr)	r�r�r7r�rrIr1r�
decode_params)	rdr��headerr�r*�params�pr�r�s	         r�_get_params_preservezMessage._get_params_preserve�s����(�������)���G���N����U�#�A�
��G�G�C��O�	��c��z�z�|���i�i�k��

�M�M�4��+�&�$��$�$�V�,���
��
�
��w�w�y����
�s�5B�B3�2B3c��t�}|j||�}||ur|S|r |D��cgc]\}}|t|�f��c}}S|Scc}}w)amReturn the message's Content-Type parameters, as a list.

        The elements of the returned list are 2-tuples of key/value pairs, as
        split on the `=' sign.  The left hand side of the `=' is the key,
        while the right hand side is the value.  If there is no `=' sign in
        the parameter the value is the empty string.  The value is as
        described in the get_param() method.

        Optional failobj is the object to return if there is no Content-Type
        header.  Optional header is the header to search instead of
        Content-Type.  If unquote is True, the value is unquoted.
        )r�rr:)rdr�r�r9r�r�r�r�s        r�
get_paramszMessage.get_params�sZ���(���*�*�7�F�;���W���N��6<�=�f�d�a��Q�
�a�(�)�f�=�=��M��>s�Ac��||vr|S|j||�D]9\}}|j�|j�k(s�(|r
t|�cS|cS|S)a�Return the parameter value if found in the Content-Type header.

        Optional failobj is the object to return if there is no Content-Type
        header, or the Content-Type header has no such parameter.  Optional
        header is the header to search instead of Content-Type.

        Parameter keys are always compared case insensitively.  The return
        value can either be a string, or a 3-tuple if the parameter was RFC
        2231 encoded.  When it's a 3-tuple, the elements of the value are of
        the form (CHARSET, LANGUAGE, VALUE).  Note that both CHARSET and
        LANGUAGE can be None, in which case you should consider VALUE to be
        encoded in the us-ascii charset.  You can usually ignore LANGUAGE.
        The parameter value (either the returned string, or the VALUE item in
        the 3-tuple) is always unquoted, unless unquote is set to False.

        If your application doesn't care whether the parameter was RFC 2231
        encoded, it can turn the return value into a string as follows:

            rawparam = msg.get_param('foo')
            param = email.utils.collapse_rfc2231_value(rawparam)

        )rr0r:)rdrr�r�r9r�r�s       r�	get_paramzMessage.get_param�sZ��0����N��-�-�g�v�>�D�A�q��w�w�y�E�K�K�M�)��(��+�+��H�?��rc�f�t|t�s|r|||f}||vr|j�dk(rd}n|j|�}|j	||��s3|st|||�}n�tj|t|||�g�}nwd}|j||��D]_\}	}
d}|	j�|j�k(rt|||�}n
t|	|
|�}|s|}�Itj||g�}�a||j|�k7r|r|j||�y||=|||<yy)a�Set a parameter in the Content-Type header.

        If the parameter already exists in the header, its value will be
        replaced with the new value.

        If header is Content-Type and has not yet been defined for this
        message, it will be set to "text/plain" and the new parameter and
        value will be appended as per RFC 2045.

        An alternate header can be specified in the header argument, and all
        parameters will be quoted as necessary unless requote is False.

        If charset is specified, the parameter will be encoded according to RFC
        2231.  Optional language specifies the RFC 2231 language, defaulting
        to the empty string.  Both charset and language should be strings.
        r�rZ)r�r�r�r9N)
r"r#r0r�rr+r�rMrr�)rdrr*r��requoter�languager�r��	old_param�	old_value�append_params            rr�zMessage.set_param�s<��$�%��'�G��h��.�E����&�,�,�.�N�"B� �E��H�H�V�$�E��~�~�e�F�~�3��$�U�E�7�;��!����L���w�?�@�B���E�(,���v�@G�)8�)I�$�	�9�!���?�?�$����
�5�#/��u�g�#F�L�#/�	�9�g�#N�L��(�E�%�N�N�E�<�+@�A�E�)I��D�H�H�V�$�$���#�#�F�E�2���L�$��V��%rc	�*�||vryd}|j||��D]Y\}}|j�|j�k7s�(|st|||�}�8tj	|t|||�g�}�[||j|�k7r	||=|||<yy)a>Remove the given parameter completely from the Content-Type header.

        The header will be re-written in place without the parameter or its
        value. All values will be quoted as necessary unless requote is
        False.  Optional header specifies an alternative to the Content-Type
        header.
        Nrr)rr0r+r�rMr�)rdrr�r�	new_ctyperr�s       rr�zMessage.del_params��������	��O�O�6�7�O�C�D�A�q��w�w�y�E�K�K�M�)� � ,�Q��7� ;�I� )���	�0<�Q��7�0K�0M�!N�I�D������(�(��V��$�D��L�)rc��|jd�dk(st�|j�dk(r|d=d|d<||vr|||<y|j||��}||=|||<|ddD]\}}|j	||||��y)	aKSet the main type and subtype for the Content-Type header.

        type must be a string in the form "maintype/subtype", otherwise a
        ValueError is raised.

        This method replaces the Content-Type header, keeping all the
        parameters in place.  If requote is False, this leaves the existing
        header's quoting as is.  Otherwise, the parameters will be quoted (the
        default).

        An alternative header can be specified in the header argument.  When
        the Content-Type header is set, we'll always also add a MIME-Version
        header.
        r�rr�zmime-versionr�r�Nr)r.rIr0rr�)rdr�r�rr�rr�s       r�set_typezMessage.set_type*s��� �z�z�#��!�#����<�<�>�^�+��^�$�#(�D�� �����D��L��������@����L���V���1�2�J�D�A�q��N�N�1�a���1�rc��t�}|jd|d�}||ur|jd|d�}||ur|Stj|�j	�S)a@Return the filename associated with the payload if present.

        The filename is extracted from the Content-Disposition header's
        `filename' parameter, and it is unquoted.  If that header is missing
        the `filename' parameter, this method falls back to looking for the
        `name' parameter.
        �filename�content-dispositionr�r�)r�rr�collapse_rfc2231_valuer)rdr�r�rs    r�get_filenamezMessage.get_filenameJs_���(���>�>�*�g�7L�M���w���~�~�f�g�~�F�H��w���N��+�+�H�5�;�;�=�=rc��t�}|jd|�}||ur|Stj|�j	�S)z�Return the boundary associated with the payload if present.

        The boundary is extracted from the Content-Type header's `boundary'
        parameter, and it is unquoted.
        �boundary)r�rrr�rstrip)rdr�r�rs    r�get_boundaryzMessage.get_boundaryZsB���(���>�>�*�g�6���w���N��+�+�H�5�<�<�>�>rc��t�}|j|d�}||urtjd��g}d}|D]D\}}|j	�dk(r|jdd|zf�d}�2|j||f��F|s|jdd|zf�g}|jD]�\}	}
|	j	�dk(rzg}|D]2\}}
|
dk(r|j|��|j|�d|
����4tj|�}
|j|jj|	|
����|j|	|
f���||_y	)
a�Set the boundary parameter in Content-Type to 'boundary'.

        This is subtly different than deleting the Content-Type header and
        adding a new one with a new boundary parameter via add_header().  The
        main difference is that using the set_boundary() method preserves the
        order of the Content-Type header in the original message.

        HeaderParseError is raised if the message has no Content-Type header.
        r�zNo Content-Type header foundFrz"%s"TrrN)r�rr�HeaderParseErrorr0r1r\r�rMr[r�)rdrr�r��	newparams�foundp�pk�pvr��hr�r�r�r�s              r�set_boundaryzMessage.set_boundarygsT���(���*�*�7�N�C���W���)�)�*H�I�I��	����F�B���x�x�z�Z�'�� � �*�f�x�.?�!@�A���� � �"�b��*���
���j�&�8�*;�<�=��
��M�M�D�A�q��w�w�y�N�*���%�D�A�q��B�w����Q������1�%5�6�	&�
 �n�n�U�+���!�!�$�+�+�"@�"@��C�"H�I��!�!�1�a�&�)�"�#��
rc�T�t�}|jd|�}||ur|St|t�r*|dxsd}	|dj	d�}t||�}	|j	d�|j�S#ttf$r|d}Y�8wxYw#t$r|cYSwxYw)z�Return the charset parameter of the Content-Type header.

        The returned string is always coerced to lower case.  If there is no
        Content-Type header, or if that header has no charset parameter,
        failobj is returned.
        rrzus-asciirr�)	r�rr"r#r%rr�r�r0)rdr�r�r�pcharsetrvs      rr�zMessage.get_content_charset�s����(���.�.��G�4���g���N��g�u�%��q�z�/�Z�H�
%�#�1�:�,�,�-A�B���h��1��	��N�N�:�&��}�}���� ��.�
%�!�!�*��
%��
�	��N�	�s#� A?�B�?B�B�B'�&B'c�f�|j�D�cgc]}|j|���c}Scc}w)a�Return a list containing the charset(s) used in this message.

        The returned list of items describes the Content-Type headers'
        charset parameter for this message and all the subparts in its
        payload.

        Each item will either be a string (the value of the charset parameter
        in the Content-Type header of that part) or the value of the
        'failobj' parameter (defaults to None), if the part does not have a
        main MIME type of "text", or the charset is not defined.

        The list will contain one string for each part of the message, plus
        one for the container message (i.e. self), so that a non-multipart
        message will still return a list of length 1.
        )�walkr�)rdr��parts   r�get_charsetszMessage.get_charsets�s.�� ?C�i�i�k�J�k�d��(�(��1�k�J�J��Js�.c�f�|jd�}|�yt|�dj�}|S)z�Return the message's content-disposition if it exists, or None.

        The return values can be either 'inline', 'attachment' or None
        according to the rfc2183.
        rNr)r�rr0)rdr*�c_ds   r�get_content_dispositionzMessage.get_content_disposition�s8�����.�/���=���%� ��#�)�)�+���
r)r%)FrN)FN)NFr~)Nr�T)r�TNrF)r�T)r�T)4�__name__�
__module__�__qualname__�__doc__r	rerirgrwrvr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�r�rrrr!r�r'r*�email.iteratorsr%�rrrr�s��
�'�
*� �
�0�

�/�"��:� Z�x&�(-B�^�"�	�H�$
#���-�	+�	+�
�",�*��$,�<
"�&�0#�#�"�#��*�,5C�� �DFJ�5:�1%�f%�,2�@>� ?�,#�\�<K�$
�%rc���eZdZd�fd�	Zd�fd�	Zd�Zd�Zd�Zdd�Zhd�Z	d	�Z
d
�Zdd�d�Zdd�d
�Z
d�Zdd�Zdd�Zdd�Zdd�d�Zd�Zd�Zd�Zd�Zd�Z�xZS)�MIMEPartNc�8��|�ddlm}|}t�|�
|�y)Nr)�default)�email.policyr4�superre)rdr[r4�	__class__s   �rrezMIMEPart.__init__�s����>�,��F�
���� rc�b��|�|jn|}|�|j}t�|�
|||�S)aReturn the entire formatted message as a string.

        Optional 'unixfrom', when true, means include the Unix From_ envelope
        header.  maxheaderlen is retained for backward compatibility with the
        base Message class, but defaults to None, meaning that the policy value
        for max_line_length controls the header maximum length.  'policy' is
        passed to the Generator instance used to serialize the message; if it
        is not specified the policy associated with the message instance is
        used.
        )r[�max_line_lengthr6rg)rdrormr[r7s    �rrgzMIMEPart.as_string�s9���!'�����F����!�1�1�L��w� ��<��@�@rc�Z�|j|jjd����S)NT)�utf8�r[)rgr[�clonerhs rrizMIMEPart.__str__�s%���~�~�T�[�[�%6�%6�D�%6�%A�~�B�Brc�J�|jd�}|�dS|jdk(S)NrF�
attachment)r��content_disposition)rdr)s  r�
is_attachmentzMIMEPart.is_attachment�s+���h�h�,�-����u�P��)@�)@�L�)P�Prc#�\K�|j�ry|j�jd�\}}|dk(r||vr|j|�|f��y|dk7s|j	�sy|dk7r0|j�D]}|j
||�Ed{����yd|vr|jd�|f��d}|jd�}|r!|j�D]}|d|k(s�|}n|�|j�}|r|dnd}|�|j
||�Ed{���yy7��7��w)Nr��text�	multipart�related�start�
content-idr)	rAr�r�r/r|�
iter_parts�
_find_bodyrr�)	rdr&�preferencelist�maintype�subtype�subpart�	candidaterF�subpartss	         rrIzMIMEPart._find_body�sK��������� �1�1�3�9�9�#�>���'��v���.�(�%�+�+�G�4�d�;�;���{�"�$�*;�*;�*=���i���?�?�,���?�?�7�N�C�C�C�-����&�!�'�'�	�2�D�9�9��	����w�'����?�?�,���<�(�E�1� '�I��-����'�'�)�H�'/����T�I�� ����y�.�A�A�A�!�D��
B�s+�BD,�D(�AD,�*7D,�!D*�"D,�*D,c�x�t|�}d}|j||�D]\}}||ks�|}|}|dk(s�|S|S)aReturn best candidate mime part for display as 'body' of message.

        Do a depth first search, starting with self, looking for the first part
        matching each of the items in preferencelist, and return the part
        corresponding to the first item that has a match, or None if no items
        have a match.  If 'related' is not included in preferencelist, consider
        the root part of any multipart/related encountered as a candidate
        match.  Ignore parts with 'Content-Disposition: attachment'.
        Nr)r!rI)rdrJ�	best_prio�body�prior&s      r�get_bodyzMIMEPart.get_bodysU����'�	����/�/�$��?�J�D�$��i�� �	����1�9����
@��r>�rC�html�rC�plain�rDrE�rD�alternativec#�K�|j�jd�\}}|dk7s|dk(ry|j�}	|j�}|dk(rt|dk(ro|jd�}|r@d}g}|D]*}|j
d�|k(rd	}�|j|��,|r|Ed{���y|jd
�|Ed{���yg}	|D]^}|j�jd�\}}||f|jvr&|j�s||	vr|	j|��[|���`y#t$rYywxYw7��7�|�w)aReturn an iterator over the non-main parts of a multipart.

        Skip the first of each occurrence of text/plain, text/html,
        multipart/related, or multipart/alternative in the multipart (unless
        they have a 'Content-Disposition: attachment' header) and include all
        remaining subparts in the returned iterator.  When applied to a
        multipart/related, return all parts except the root part.  Return an
        empty iterator when applied to a multipart/alternative or a
        non-multipart.
        r�rDr[NrErFFrGTr)r�r�r�r�r�rr�r1�pop�_body_typesrA)
rdrKrLr�r�rFr��attachmentsr&�seens
          r�iter_attachmentszMIMEPart.iter_attachments*sb����!�1�1�3�9�9�#�>���'��{�"�g��&>���"�"�$��	��L�L�N�E�
�{�"�w�)�';��N�N�7�+�E���� ��!�D��x�x��-��6� $��#�*�*�4�0�	"�
�*�*�*���I�I�a�L��������D� $� 5� 5� 7� =� =�c� B��H�g��7�#�t�'7�'7�7��*�*�,���1D����G�$���J�
��7�	��	��$+��
�sI�>E�D0�AE�(D?�)E�E�A+E�0	D<�9E�;D<�<E�Ec#�bK�|j�r|j�Ed{���yy7��w)z~Return an iterator over all immediate subparts of a multipart.

        Return an empty iterator for a non-multipart.
        N)r|r�rhs rrHzMIMEPart.iter_partsas.����
�����'�'�)�)�)��)�s�$/�-�/)�content_managerc�^�|�|jj}|j|g|��i|��Sr~)r[rc�get_content�rdrc�args�kws    rrezMIMEPart.get_contentis4���"�"�k�k�9�9�O�*��*�*�4�=�$�=�"�=�=rc�`�|�|jj}|j|g|��i|��yr~)r[rc�set_contentrfs    rrjzMIMEPart.set_contentns1���"�"�k�k�9�9�O�#��#�#�D�6�4�6�2�6rc�$�|j�dk(r5|j�}||fz}||vrtdj||���g}g}|jD]K\}}|j�j
d�r|j||f��9|j||f��M|r=t|�|j��}	||	_|j|	_
|	g|_
ng|_
||_d|z|d<|�|jd|�yy)NrDzCannot convert {} to {}�content-r<z
multipart/r�r)r�r�rIr�r\r0rFr1r�r[r^r�)
rdrL�disallowed_subtypesr�existing_subtype�keep_headers�part_headersr�r*r&s
          r�_make_multipartzMIMEPart._make_multipartss���$�$�&�+�5�#�7�7�9��"5��
�"B���#6�6� �!:�!A�!A�$�g�"/�0�0������=�=�K�D�%��z�z�|�&�&�z�2��#�#�T�5�M�2��#�#�T�5�M�2�	)�
��4��:�T�[�[�1�D�(�D�M� �M�M�D�M�!�F�D�M��D�M�$��
�+�g�5��^�����N�N�:�x�0� rc�*�|jdd|�y)NrE)r[�mixed�rq�rdrs  r�make_relatedzMIMEPart.make_related�s�����Y�(@�(�Krc�*�|jdd|�y)Nr[)rsrtrus  r�make_alternativezMIMEPart.make_alternative�s�����]�J��Arc�*�|jdd|�y)Nrsr0rtrus  r�
make_mixedzMIMEPart.make_mixed�s�����W�b�(�3r)�_dispc��|j�dk7s|j�|k7rt|d|z��t|�|j��}|j
|i|��|r	d|vr||d<|j
|�y)NrD�make_r<rzContent-Disposition)r�r��getattrr�r[rjr�)rd�_subtyper{rgrhr&s      r�_add_multipartzMIMEPart._add_multipart�s����%�%�'�;�6��(�(�*�h�6�-�G�D�'�H�,�-�/��t�D�z����-������$�%�"�%��*�$�6�*/�D�&�'����D�rc�4�|jdg|��ddi|��y)NrEr{�inline�r��rdrgrhs   r�add_relatedzMIMEPart.add_related�s!������I�C��C�H�C��Crc�0�|jdg|��i|��y)Nr[r�r�s   r�add_alternativezMIMEPart.add_alternative�s������M�7�D�7�B�7rc�4�|jdg|��ddi|��y)Nrsr{r?r�r�s   r�add_attachmentzMIMEPart.add_attachment�s!������G�E�d�E�,�E�"�Erc� �g|_d|_yr~)r\r^rhs r�clearzMIMEPart.clear�s����
���
rc��|jD��cgc](\}}|j�jd�s||f��*c}}|_d|_ycc}}w)Nrl)r\r0rFr^)rd�nr�s   r�
clear_contentzMIMEPart.clear_content�sN��,0�M�M�B�M�D�A�q� !���	� 4� 4�Z� @��Q��M�B��
���
��Bs�-Ar~)FNN))rErVrX)r+r,r-rergrirArIrTr^rarHrerjrqrvrxrzr�r�r�r�r�r��
__classcell__�r7s@rr2r2�s����!�A� C�Q�B�:�(1�K�5�n*�26�>�
26�7�
1�6L�B�4�59��D�8�F��rr2c���eZdZ�fd�Z�xZS)rc�8��t�|�|i|��d|vrd|d<yy)Nr�r�)r6rj)rdrgrhr7s   �rrjzEmailMessage.set_content�s,���
���T�(�R�(���%�#(�D�� �&r)r+r,r-rjr�r�s@rrr�s
���)�)r)NT)r.�__all__rJ�rer��iorr�emailrr�email._policybaser	rr_�email._encoded_wordsrr�r��compiler'rr+r7r:rWrr2rr0rr�<module>r�s���
?��n�
%���	�
� ���&�%�)�
�
�
���	�
�B�J�J�2�3�	� � �D�($�#�>K
%�K
%�\\�w�\�~)�8�)r__pycache__/parser.cpython-312.pyc000064400000015134151706203560012764 0ustar00�

T��ho���dZgd�ZddlmZmZddlmZmZddlm	Z	Gd�d�Z
Gd�d	e
�ZGd
�d�ZGd�d
e�Z
y)z-A parser of RFC 2822 and MIME email messages.)�Parser�HeaderParser�BytesParser�BytesHeaderParser�
FeedParser�BytesFeedParser�)�StringIO�
TextIOWrapper)rr)�compat32c�*�eZdZded�d�Zdd�Zdd�Zy)rN��policyc� �||_||_y)a�Parser of RFC 2822 and MIME email messages.

        Creates an in-memory object tree representing the email message, which
        can then be manipulated and turned over to a Generator to return the
        textual representation of the message.

        The string must be formatted as a block of RFC 2822 headers and header
        continuation lines, optionally preceded by a `Unix-from' header.  The
        header block is terminated either by the end of the string or by a
        blank line.

        _class is the class to instantiate for new message objects when they
        must be created.  This class must have a constructor that can take
        zero arguments.  Default is Message.Message.

        The policy keyword specifies a policy object that controls a number of
        aspects of the parser's operation.  The default policy maintains
        backward compatibility.

        N)�_classr)�selfrrs   �%/usr/lib64/python3.12/email/parser.py�__init__zParser.__init__s��*������c��t|j|j��}|r|j�|j	d�x}r%|j|�|j	d�x}r�%|j
�S)a\Create a message structure from the data in a file.

        Reads all the data from the file and returns the root of the message
        structure.  Optional headersonly is a flag specifying whether to stop
        parsing after reading the headers or not.  The default is False,
        meaning it parses the entire contents of the file.
        r
i )rrr�_set_headersonly�read�feed�close)r�fp�headersonly�
feedparser�datas     r�parsezParser.parse)sj�� ����D�K�K�@�
���'�'�)��g�g�d�m�#�d�#��O�O�D�!��g�g�d�m�#�d�#����!�!rc�:�|jt|�|��S)a-Create a message structure from a string.

        Returns the root of the message structure.  Optional headersonly is a
        flag specifying whether to stop parsing after reading the headers or
        not.  The default is False, meaning it parses the entire contents of
        the file.
        �r)rr	�r�textrs   r�parsestrzParser.parsestr8s���z�z�(�4�.�k�z�B�Br)N�F)�__name__�
__module__�__qualname__rrrr#�rrrrs���h��0
"�Crrc��eZdZdd�Zdd�Zy)rc�0�tj||d�S�NT)rr�rrrs   rrzHeaderParser.parseDs���|�|�D�"�d�+�+rc�0�tj||d�Sr+)rr#r!s   rr#zHeaderParser.parsestrGs�����t�T�4�0�0rN�T)r%r&r'rr#r(rrrrCs��,�1rrc�"�eZdZd�Zdd�Zdd�Zy)rc�$�t|i|��|_y)a�Parser of binary RFC 2822 and MIME email messages.

        Creates an in-memory object tree representing the email message, which
        can then be manipulated and turned over to a Generator to return the
        textual representation of the message.

        The input must be formatted as a block of RFC 2822 headers and header
        continuation lines, optionally preceded by a `Unix-from' header.  The
        header block is terminated either by the end of the input or by a
        blank line.

        _class is the class to instantiate for new message objects when they
        must be created.  This class must have a constructor that can take
        zero arguments.  Default is Message.Message.
        N)r�parser)r�args�kws   rrzBytesParser.__init__Ms�� �d�)�b�)��rc��t|dd��}	|jj||�|j�S#|j�wxYw)acCreate a message structure from the data in a binary file.

        Reads all the data from the file and returns the root of the message
        structure.  Optional headersonly is a flag specifying whether to stop
        parsing after reading the headers or not.  The default is False,
        meaning it parses the entire contents of the file.
        �ascii�surrogateescape)�encoding�errors)r
r1r�detachr,s   rrzBytesParser.parse_s?���2��8I�
J��	��;�;�$�$�R��5��I�I�K��B�I�I�K�s	�<�Ac�`�|jdd��}|jj||�S)a2Create a message structure from a byte string.

        Returns the root of the message structure.  Optional headersonly is a
        flag specifying whether to stop parsing after reading the headers or
        not.  The default is False, meaning it parses the entire contents of
        the file.
        �ASCIIr6)r8)�decoder1r#r!s   r�
parsebyteszBytesParser.parsebytesns.���{�{�7�+<�{�=���{�{�#�#�D�+�6�6rNr$)r%r&r'rrr=r(rrrrKs��*�$�	7rrc��eZdZdd�Zdd�Zy)rc�2�tj||d��S�NTr )rrr,s   rrzBytesHeaderParser.parse{s��� � ��r�t� �<�<rc�2�tj||d��Sr@)rr=r!s   rr=zBytesHeaderParser.parsebytes~s���%�%�d�D�d�%�C�CrNr.)r%r&r'rr=r(rrrrzs
��=�DrrN)�__doc__�__all__�ior	r
�email.feedparserrr�email._policybaserrrrrr(rr�<module>rGsN��
4�,��'�8�&�0C�0C�f1�6�1�,7�,7�^D��Dr__pycache__/policy.cpython-312.pyc000064400000027034151706203560012771 0ustar00�

T��hv)��P�dZddlZddlZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZgd�Zej"d	�ZeGd
�de��Ze�Ze`ej-d�
�Zej-d��Zej-dd��Zej-d��Zy)zcThis will be the home for the policy that hooks in the new
code that adds all the email6 features.
�N)�Policy�Compat32�compat32�_extend_docstrings)�_has_surrogates)�HeaderRegistry)�raw_data_manager)�EmailMessage)rrr�EmailPolicy�default�strict�SMTP�HTTPz\n|\r\n?c�l��eZdZdZeZdZdZe�Z	e
Z�fd�Zd�Z
d�Zd�Zd�Zd	�Zd
�Zdd�Z�xZS)
raQ+
    PROVISIONAL

    The API extensions enabled by this policy are currently provisional.
    Refer to the documentation for details.

    This policy adds new header parsing and folding algorithms.  Instead of
    simple strings, headers are custom objects with custom attributes
    depending on the type of the field.  The folding algorithm fully
    implements RFCs 2047 and 5322.

    In addition to the settable attributes listed above that apply to
    all Policies, this policy adds the following additional attributes:

    utf8                -- if False (the default) message headers will be
                           serialized as ASCII, using encoded words to encode
                           any non-ASCII characters in the source strings.  If
                           True, the message headers will be serialized using
                           utf8 and will not contain encoded words (see RFC
                           6532 for more on this serialization format).

    refold_source       -- if the value for a header in the Message object
                           came from the parsing of some source, this attribute
                           indicates whether or not a generator should refold
                           that value when transforming the message back into
                           stream form.  The possible values are:

                           none  -- all source values use original folding
                           long  -- source values that have any line that is
                                    longer than max_line_length will be
                                    refolded
                           all  -- all values are refolded.

                           The default is 'long'.

    header_factory      -- a callable that takes two arguments, 'name' and
                           'value', where 'name' is a header field name and
                           'value' is an unfolded header field value, and
                           returns a string-like object that represents that
                           header.  A default header_factory is provided that
                           understands some of the RFC5322 header field types.
                           (Currently address fields and date fields have
                           special treatment, while all other fields are
                           treated as unstructured.  This list will be
                           completed before the extension is marked stable.)

    content_manager     -- an object with at least two methods: get_content
                           and set_content.  When the get_content or
                           set_content method of a Message object is called,
                           it calls the corresponding method of this object,
                           passing it the message object as its first argument,
                           and any arguments or keywords that were passed to
                           it as additional arguments.  The default
                           content_manager is
                           :data:`~email.contentmanager.raw_data_manager`.

    F�longc�j��d|vrtj|dt��t�|�di|��y)N�header_factory�)�object�__setattr__r�super�__init__)�self�kw�	__class__s  ��%/usr/lib64/python3.12/email/policy.pyrzEmailPolicy.__init__]s3����2�%����t�%5�~�7G�H�
����2��c�4�|j|jS)z�+
        The implementation for this class returns the max_count attribute from
        the specialized header class that would be used to construct a header
        of type 'name'.
        )r�	max_count)r�names  r�header_max_countzEmailPolicy.header_max_countds���"�"�4�(�2�2�2rc��|djdd�\}}dj|g|dd���jd�}||jd�fS)a]+
        The name is parsed as everything up to the ':' and returned unmodified.
        The value is determined by stripping leading whitespace off the
        remainder of the first line joined with all subsequent lines, and
        stripping any trailing carriage return or linefeed characters.  (This
        is the same as Compat32).

        r�:��Nz 	
�
)�split�join�lstrip�rstrip)r�sourcelinesr �values    r�header_source_parsezEmailPolicy.header_source_parsevsY��"�!�n�*�*�3��2���e�����1��Q�R��1�2�9�9�)�D���e�l�l�6�*�+�+rc��t|d�r/|jj�|j�k(r||fSt|t�r't|j
��dkDrtd��||j||�fS)a�+
        The name is returned unchanged.  If the input value has a 'name'
        attribute and it matches the name ignoring case, the value is returned
        unchanged.  Otherwise the name and value are passed to header_factory
        method, and the resulting custom header object is returned as the
        value.  In this case a ValueError is raised if the input value contains
        CR or LF characters.

        r r$zDHeader values may not contain linefeed or carriage return characters)	�hasattrr �lower�
isinstance�str�len�
splitlines�
ValueErrorr�rr r,s   r�header_store_parsezEmailPolicy.header_store_parse�s}���5�&�!�e�j�j�&6�&6�&8�D�J�J�L�&H��%�=� ��e�S�!�c�%�*:�*:�*<�&=�a�&?��=�>�
>��d�)�)�$��6�7�7rc��t|d�r|Sdjtj|��}|j	||�S)ai+
        If the value has a 'name' attribute, it is returned to unmodified.
        Otherwise the name and the value with any linesep characters removed
        are passed to the header_factory method, and the resulting custom
        header object is returned.  Any surrogateescaped bytes get turned
        into the unicode unknown-character glyph.

        r r%)r/r(�linesep_splitterr'rr6s   r�header_fetch_parsezEmailPolicy.header_fetch_parse�s@���5�&�!��L����(�.�.�u�5�6���"�"�4��/�/rc�*�|j||d��S)a+
        Header folding is controlled by the refold_source policy setting.  A
        value is considered to be a 'source value' if and only if it does not
        have a 'name' attribute (having a 'name' attribute means it is a header
        object of some sort).  If a source value needs to be refolded according
        to the policy, it is converted into a custom header object by passing
        the name and the value with any linesep characters removed to the
        header_factory method.  Folding of a custom header object is done by
        calling its fold method with the current policy.

        Source values are split into lines using splitlines.  If the value is
        not to be refolded, the lines are rejoined using the linesep from the
        policy and returned.  The exception is lines containing non-ascii
        binary data.  In that case the value is refolded regardless of the
        refold_source setting, which causes the binary data to be CTE encoded
        using the unknown-8bit charset.

        T��
refold_binary)�_foldr6s   r�foldzEmailPolicy.fold�s��&�z�z�$��T�z�:�:rc��|j|||jdk(��}|jrdnd}|j|d�S)a+
        The same as fold if cte_type is 7bit, except that the returned value is
        bytes.

        If cte_type is 8bit, non-ASCII binary data is converted back into
        bytes.  Headers with binary data are not refolded, regardless of the
        refold_header setting, since there is no way to know whether the binary
        data consists of single byte characters or multibyte characters.

        If utf8 is true, headers are encoded to utf8, otherwise to ascii with
        non-ASCII unicode rendered as encoded words.

        �7bitr<�utf8�ascii�surrogateescape)r>�cte_typerB�encode)rr r,�folded�charsets     r�fold_binaryzEmailPolicy.fold_binary�s@�����D�%�t�}�}�f�7L��M�� �I�I�&�7���}�}�W�&7�8�8rc���t|d�r|j|��S|jr|jntj�t
j
|�}|jdk(xsN|jdk(xr=|xr t|d�t|�zdz�kDxst�fd�|ddD��}|s+|js|j�}n
|rt|�}|r1|j|d	j|��j|��S|d
z|jj|�z|jzS)Nr )�policy�allrr�c3�:�K�|]}t|��kD���y�w)N)r3)�.0�x�maxlens  �r�	<genexpr>z$EmailPolicy._fold.<locals>.<genexpr>�s�����<�)�Q��Q��&��)�s�r$r%z: )r/r?�max_line_length�sys�maxsizer9r'�
refold_sourcer3�anyrB�isasciirrr(�linesep)rr r,r=�lines�refoldrQs      @rr>zEmailPolicy._fold�s(����5�&�!��:�:�T�:�*�*�)-�)=�)=��%�%�3�;�;�� �&�&�u�-���$�$��-�>��$�$��.�>��A�s�5��8�}�S��Y�6�q�8�6�A�=��<�%���)�<�<�	�
��9�9�"�]�]�_�,���(��/����&�&�t�R�W�W�U�^�<�A�A��A�N�N��d�{�T�\�\�.�.�u�5�5����D�Dr)F)�__name__�
__module__�__qualname__�__doc__r
�message_factoryrBrVrrr	�content_managerrr!r-r7r:r?rIr>�
__classcell__)rs@rrrsP���8�t#�O��D��M�#�%�N�&�O��3�$,�8�&
0�;�*9�$ErrT)�raise_on_defectr&)rY)rYrS)rB)r_�rerT�email._policybaserrrr�email.utilsr�email.headerregistryr�email.contentmanagerr	�
email.messager
�__all__�compiler9rrr�cloner
rr�SMTPUTF8rrr�<module>rns����
�
�L�L�'�A�1�&�	���2�:�:�k�*���DE�&�DE��DE�N�-����	���t��	,���}�}�V�}�$���}�}�V�T�}�:���:�:�4�:� �r__pycache__/quoprimime.cpython-312.pyc000064400000023340151706203560013655 0ustar00�

T��h�&���dZgd�ZddlZddlmZmZmZdZdZdZ	e
d�D�cgc]}d	|z��	c}ZeddZeddZ
d
ejd�zejd�zD]
Zee�ee<�deed
�<dD]
Zee�e
e<�d�Zd�Zd�Zd�Zdd�Zd�Zd�Zdd�Ze
ddZdD]
Zee�ee<�[defd�Zefd�ZeZeZd�Zd�Z ycc}w)aFQuoted-printable content transfer encoding per RFCs 2045-2047.

This module handles the content transfer encoding method defined in RFC 2045
to encode US ASCII-like 8-bit data called `quoted-printable'.  It is used to
safely encode text that is in a character set similar to the 7-bit US ASCII
character set, but that includes some 8-bit characters that are normally not
allowed in email bodies or headers.

Quoted-printable is very space-inefficient for encoding binary files; use the
email.base64mime module for that instead.

This module provides an interface to encode and decode both headers and bodies
with quoted-printable encoding.

RFC 2045 defines a method for including character set information in an
`encoded-word' in a header.  This method is commonly used for 8-bit real names
in To:/From:/Cc: etc. fields, as well as Subject: lines.

This module does not do the line wrapping or end-of-line character
conversion necessary for proper internationalized headers; it only
does dumb encoding and decoding.  To deal with the various line
wrapping issues, use the email.header module.
)
�body_decode�body_encode�body_length�decode�decodestring�
header_decode�
header_encode�
header_length�quote�unquote�N)�
ascii_letters�digits�	hexdigits�
�
��z=%02Xs-!*+/�ascii�_� s_ !"#$%&'()*+,-./0123456789:;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~	c�,�t|�t|k7S)z>Return True if the octet should be escaped with header quopri.)�chr�_QUOPRI_HEADER_MAP��octets �)/usr/lib64/python3.12/email/quoprimime.py�header_checkrJs���u�:�+�E�2�2�2�c�,�t|�t|k7S)z<Return True if the octet should be escaped with body quopri.)r�_QUOPRI_BODY_MAPrs r�
body_checkr!Os���u�:�)�%�0�0�0rc�&�td�|D��S)a:Return a header quoted-printable encoding length.

    Note that this does not include any RFC 2047 chrome added by
    `header_encode()`.

    :param bytearray: An array of bytes (a.k.a. octets).
    :return: The length in bytes of the byte array when it is encoded with
        quoted-printable for headers.
    c3�@K�|]}tt|����y�w�N)�lenr��.0rs  r�	<genexpr>z header_length.<locals>.<genexpr>^s����E�9�%�s�%�e�,�-�9�����sum��	bytearrays rr	r	Ts���E�9�E�E�Erc�&�td�|D��S)z�Return a body quoted-printable encoding length.

    :param bytearray: An array of bytes (a.k.a. octets).
    :return: The length in bytes of the byte array when it is encoded with
        quoted-printable for bodies.
    c3�@K�|]}tt|����y�wr$)r%r r&s  rr(zbody_length.<locals>.<genexpr>hs����C���s�#�E�*�+��r)r*r,s rrras���C��C�C�Crc��t|t�st|�}|s |j|j	��yt|d�t|�z|kr|dxx||zz
cc<y|j|j	��y)N���)�
isinstance�strr�append�lstripr%)�L�s�maxlen�extras    r�_max_appendr:ksg���a�����F���	��������	�Q�r�U��c�!�f�	��	&�	�"�������	�������rc�2�tt|ddd��S)zDTurn a string in the form =AB to the ASCII character with value 0xab���)r�int�r7s rrrvs���s�1�Q�q�6�2���rc�&�tt|�Sr$)�_QUOPRI_MAP�ord��cs rr
r
{s���s�1�v��rc�b�|sy|jd�jt�}d|�d|�d�S)a�Encode a single header line with quoted-printable (like) encoding.

    Defined in RFC 2045, this `Q' encoding is similar to quoted-printable, but
    used specifically for email header fields to allow charsets with mostly 7
    bit characters (and some 8 bit) to remain more or less readable in non-RFC
    2045 aware mail clients.

    charset names the character set to use in the RFC 2046 header.  It
    defaults to iso-8859-1.
    r�latin1z=?z?q?z?=)r�	translater)�header_bytes�charset�encodeds   rrrs3�����!�!�(�+�5�5�6H�I�G�$�W�-�-rs
�Lc��|dkrtd��|s|S|jt�}d|z}|dz
}g}|j}|j	�D]�}d}t|�dz
|z
}	||	krV||z}
||
dz
dk(r||||
dz
�|
dz
}n,||
dz
dk(r||||
�|
dz
}n||||
dz�|
}||	kr�V|rN|ddvrG||	z
}|d	k\rt
|d�}n|dk(r	|d|z}n|t
|d�z}|||d|z���|||d
���|dtvr|d�|j|�S)a�Encode with quoted-printable, wrapping at maxlinelen characters.

    Each line of encoded text will end with eol, which defaults to "\n".  Set
    this to "\r\n" if you will be using the result of this function directly
    in an email.

    Each line will be wrapped at, at most, maxlinelen characters before the
    eol string (maxlinelen defaults to 76 characters, the maximum value
    permitted by RFC 2045).  Long lines will have the 'soft line break'
    quoted-printable character "=" appended to them, so the decoded text will
    be identical to the original text.

    The minimum maxlinelen is 4 to have room for a quoted character ("=XX")
    followed by a soft line break.  Smaller values will generate a
    ValueError.

    �zmaxlinelen must be at least 4�=r<r�r1z 	r=Nr)	�
ValueErrorrH�_QUOPRI_BODY_ENCODE_MAPr4�
splitlinesr%r
�CRLF�join)
�body�
maxlinelen�eol�
soft_break�maxlinelen1�encoded_bodyr4�line�start�	laststart�stop�room�qs
             rrr�s���&�A�~��8�9�9�����>�>�1�2�D��s��J��q�.�K��L�
�
 �
 �F����!������I��M�J�.�	��y� ��;�&�D��D�1�H�~��$��t�E�$��(�+�,��q����d�Q�h��3�&��t�E�$�'�(��q����t�E�$�'�#�-�.����y� ��D��H��%��9�$�D��q�y��$�r�(�O�������H�z�)����t�B�x��0���4��b�>�A�%�&��4���<� �C"�H�B�x�4���r�
��8�8�L�!�!rc���|s|Sd}|j�D]�}|j�}|s||z
}�d}t|�}||ks�.||}|dk7r||z
}|dz
}nV|dz|k(r|dz
}�)|dz|kr6||dztvr(||dztvr|t	|||dz�z
}|dz
}n
||z
}|dz
}||k(r||z
}||kr�{��|ddvr|j|�r|d	d}|S)
z_Decode a quoted-printable string.

    Lines are separated with eol, which defaults to \n.
    rrrOr<rPr=r1rN)rS�rstripr%rr�endswith)rKrX�decodedr\�i�nrEs       rrr�s3��
����G��"�"�$���{�{�}����s�N�G��
����I���!�e��Q��A��C�x��1����Q����1�����Q�����1��q��T�!�A�#�Y�)�3��Q�q�S�	�Y�8N��7�4��!�A�#�;�/�/���Q����1����Q����A�v��3���)�!�e�%�<�r�{�&� �W�%5�%5�c�%:��#�2�,���Nrc�:�|jd�}t|�S)zCTurn a match in the form =AB to the ASCII character with value 0xabr)�groupr)�matchr7s  r�_unquote_matchrks��
���A��A��1�:�rc�|�|jdd�}tjdt|tj��S)aDecode a string encoded with RFC 2045 MIME header `Q' encoding.

    This function does not parse a full MIME header value encoded with
    quoted-printable (like =?iso-8859-1?q?Hello_World?=) -- please use
    the high level email.header class for that functionality.
    rrz=[a-fA-F0-9]{2})�flags)�replace�re�subrk�ASCIIr@s rrr$s.��	
�	�	�#�s��A�
�6�6�$�n�a�r�x�x�H�Hr)r)z
iso-8859-1)!�__doc__�__all__ro�stringr
rrrT�NL�EMPTYSTRING�rangerBrr �encoderErrCrr!r	rr:rr
rrRrrrrrkrrDs0r�<module>rysQ��
�0��
�3�3�
��	����%*�#�J�/�J�q�w��{�J�/�� ��^���q�>��
�(�M�(�(��1�	1�M�F�M�M�'�4J�	J�A���F��q��
K� #��3�s�8��.�A��a�&��Q��.�3�
1�

F�D�� �
�.�*+�1�-��	�A�!$�Q���A��
��!#��I"�^�,�`�����I��[0s�C__pycache__/utils.cpython-312.pyc000064400000037144151706203560012635 0ustar00�

T��h�>����dZgd�ZddlZddlZddlZddlZddlZddlZddlZ	ddl
mZddl
mZ
ddl
mZddl
mZmZmZddlmZd	Zd
Zd
ZdZdZej2d
�Zej2d�Zd�Zd�Zd'd�Zd�Zd�Z dZ!dd�d�Z"d�Z#d�Z$d�Z%d�Z&d(d�Z'd)d�Z(d*d�Z)d�Z*dd�d�Z+d �Z,d!�Z-d*d"�Z.ej2d#ej^�Z0d$�Z1		d+d%�Z2d*d&�Z3y),zMiscellaneous utilities.)�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�D�	|j�y#t$rYywxYw)z;Return True if s may contain surrogate-escaped binary data.FT)�encode�UnicodeEncodeError)�ss �$/usr/lib64/python3.12/email/utils.py�_has_surrogatesr4s%��
�	���
�������s��	�c�J�|jdd�}|jdd�S)N�utf-8�surrogateescape�replace)r�decode)�string�original_bytess  r�	_sanitizer%As(��
�]�]�7�,=�>�N�� � ��)�4�4�c�V�|\}}|jd�|rM	|jd�d}tj|�rd}tj	d|�}|�|�|�d|�d�S|S#t
$r7t
|t�rt|�}|j|�}|�d|�d�cYSwxYw)a�The inverse of parseaddr(), this takes a 2-tuple of the form
    (realname, email_address) and returns the string value suitable
    for an RFC 2822 From, To or Cc header.

    If the first element of pair is false, then the second element is
    returned unmodified.

    The optional charset is the character set that is used to encode
    realname in case realname is not ASCII safe.  Can be an instance of str or
    a Charset-like object which has a header_encode method.  Default is
    'utf-8'.
    �asciir�"z\\\g<0>z <�>)
r�
specialsre�search�	escapesre�subr�
isinstance�strr�
header_encode)�pair�charset�name�address�quotes�encoded_names      rrrMs����M�D�'��N�N�7���	C��K�K�� ��F�� � ��&����=�=��T�2�D�$*�D�&�'�B�B��N��"�	7��'�3�'�!�'�*��"�0�0��6�L� ,�g�6�6�		7�s�A(�(=B(�'B(c#�K�d}d}t|�D]!\}}|r|d|zf��d}�|dk(rd}�||f���#|r|df��yy�w)NrF�\T)�	enumerate)�addr�pos�escape�chs    r�_iter_escaped_charsr?nsb����
�C�
�F��T�?���R����r�	�"�"��F�
�4�Z��F���)�O�#���D�k���s�>Ac��d|vr|Sd}d}g}t|�D]0\}}|dk(s�|�|}�||k7r|j|||�|dz}d}�2|t|�kr|j||d�dj|�S)z Strip real names between quotes.r)rN�r)r?�append�len�join)r;�start�open_pos�resultr<r>s      r�_strip_quoted_realnamesrH}s���
�$����
�E��H�
�F�&�t�,���R�
��9������H�$��M�M�$�u�X�"6�7��a�����-�
�s�4�y���
�
�d�5�6�l�#�
�7�7�6�?�r&T)�strictc��|s3tjd�|D��}t|�}|jS|D�cgc]
}t	|���}}t|�}tj|�}t|�}t
|j�}d}|D]$}t|�}|d|jd�zz
}�&t|�|k7rdgS|Scc}w)z�Return a list of (REALNAME, EMAIL) or ('','') for each fieldvalue.

    When parsing fails for a fieldvalue, a 2-tuple of ('', '') is returned in
    its place.

    If strict is true, use a strict parser which rejects malformed inputs.
    c3�2K�|]}t|����y�w)N�r0)�.0�vs  r�	<genexpr>zgetaddresses.<locals>.<genexpr>�s����:�k��c�!�f�k�s�rrA�,�rr)
�
COMMASPACErD�_AddressList�addresslistr0�_pre_parse_validation�_post_parse_validationrH�countrC)�fieldvaluesrI�all�arNr;rG�ns        rr	r	�s���$��o�o�:�k�:�:�������}�}��#.�/�;�a�3�q�6�;�K�/�'��4�K��?�?�;�'�D��T��A�
#�A�M�M�
2�F�	
�A�
��
$�A�&��	�Q������
�����6�{�a���z���M��%0s�Cc��t|�}d}t|�D]"\}}|dk(r|dz
}�|dk(s�|dz}|dks�"y|dk(S)Nr�(rA�)F)rHr?)r;�opensr<r>s    r�_check_parenthesisr`�sZ��"�4�(�D�
�E�&�t�,���R�
��9��Q�J�E�
�3�Y��Q�J�E��q�y��
-�
�Q�J�r&c�T�g}|D] }t|�sd}|j|��"|S)Nz('', ''))r`rB)�email_header_fields�accepted_valuesrNs   rrUrU�s4���O�
 ��!�!�$��A����q�!�!�
�r&c�L�g}|D]}d|dvrd}|j|��|S)N�[rArQ)rB)�parsed_email_header_tuplesrcrNs   rrVrV�s9���O�(���!�A�$�;��A����q�!�(�
�r&c	�`�dgd�|d|dgd�|ddz
|d|d|d	|d
|fzS)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�DecrAr����)�	timetuple�zones  r�_format_timetuple_and_zoner��sZ��/�9�)�A�,�G��!��	3�3<�Q�<�!�3C�	E��!��i��l�I�a�L�)�A�,��
3��r&c��|�tj�}tjj|tjj�}|r|j�}d}n|s|j
d��}t||�S)a�Returns a date string as specified by RFC 2822, e.g.:

    Fri, 09 Nov 2001 01:08:47 -0000

    Optional timeval if given is a floating-point time value as accepted by
    gmtime() and localtime(), otherwise the current time is used.

    Optional localtime is a flag that when True, interprets timeval, and
    returns a date relative to the local timezone instead of UTC, properly
    taking daylight savings time into account.

    Optional argument usegmt means that the timezone is written out as
    an ascii string, not numeric one (so "GMT" instead of "+0000"). This
    is needed for HTTP, and is only used when localtime==False.
    NF)�tzinfo)�time�datetime�
fromtimestamp�timezone�utc�
astimezoner!r)�timeval�	localtime�usegmt�dts    rrr�sk��$���)�)�+��	�	�	�	(�	(��(�2C�2C�2G�2G�	H�B��
�]�]�_����
�
�Z�Z�t�Z�
$���2�v�&�&r&c��|j�}|rA|j�'|jtjjk7rtd��d}n |j�d}n|j
d�}t||�S)a$Turn a datetime into a date string as specified in RFC 2822.

    If usegmt is True, dt must be an aware datetime with an offset of zero.  In
    this case 'GMT' will be rendered instead of the normal +0000 required by
    RFC2822.  This is to support HTTP headers involving date stamps.
    z%usegmt option requires a UTC datetime�GMTz-0000z%z)r�r�r�r�r��
ValueError�strftimer�)r�r��nowr�s    rrrsn��
�,�,�.�C�
�
�9�9���	�	�X�->�->�-B�-B� B��D�E�E���	���	����{�{�4� ��%�c�4�0�0r&c���ttj�dz�}tj�}t	j
d�}|�d}nd|z}|�t
j�}d|||||fz}|S)a{Returns a string suitable for RFC 2822 compliant Message-ID, e.g:

    <142480216486.20800.16526388040877946887@nightshade.la.mastaler.com>

    Optional idstring if given is a string used to strengthen the
    uniqueness of the message id.  Optional domain if given provides the
    portion of the message id after the '@'.  It defaults to the locally
    defined hostname.
    �d�@r�.z<%d.%d.%d%s@%s>)�intr��os�getpid�random�getrandbits�socket�getfqdn)�idstring�domainr��pid�randint�msgids      rr
r
"sr���$�)�)�+�c�/�"�G�
�)�)�+�C�� � ��$�G�������>��
�~����!����#�w��&� I�I�E��Lr&c	��t|�}|�tdt|�z��|�^}}|�tj|dd�Stj|dddtjtj
|���i�S)Nz!Invalid date value or format "%s"ror�)�seconds)rr�r0r�r��	timedelta)�data�parsed_date_tz�dtuple�tzs    rrr9s���"�4�(�N����<�s�4�y�H�I�I� �K�V�R�	�z�� � �&��!�*�-�-����f�R�a�j�F��$�$�X�%7�%7��%C�D�F�Fr&c��|st|�j}|sy|dSt|t�r|d}t|t�syt|g�d}t
t|�j�}|rt|�dkDry|dS)a
    Parse addr into its constituent realname and email address parts.

    Return a tuple of realname and email address, unless the parse fails, in
    which case return a 2-tuple of ('', '').

    If strict is True, use a strict parser which rejects malformed inputs.
    rQrrA)rSrTr/�listr0rUrVrC)r;rI�addrss   rrrDs�����T�"�.�.�����Q�x���$����A�w���d�C� �� �$��(��+�D�"�<��#5�#A�#A�B�E��C��J��N����8�Or&c��t|�dkDrn|jd�r6|jd�r%|ddjdd�jdd�S|jd�r|jd�r|ddS|S)	zRemove quotes from a string.rAr)���z\\r9z\"�<r*)rC�
startswith�endswithr!rLs rrrcsr��
�3�x�!�|��>�>�#��3�<�<��#4��q��9�$�$�V�T�2�:�:�5�#�F�F��>�>�#��3�<�<��#4��q��9���Jr&c�X�|jtd�}t|�dkrdd|fS|S)z#Decode string according to RFC 2231rpN)�split�TICKrC)r�partss  rrros.��
�G�G�D�!��E�
�5�z�Q���T�1�}���Lr&c�v�tjj|d|xsd��}|�|�|S|�d}|�d|�d|��S)z�Encode string according to RFC 2231.

    If neither charset nor language is given, then s is returned as-is.  If
    charset is given but not language, the string is encoded using the empty
    string for language.
    rr()�safe�encodingr)�urllib�parser)rr3�languages   rrrwsK��	�����1�2��0B�7��C�A���8�+������� �(�A�.�.r&z&^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$c��|dg}i}|ddD]�\}}|jd�}t|�}tj|�}|rG|j	dd�\}}|�t|�}|j
|g�j|||f���|j|dt|�zf���|r�|j�D]�\}}g}d}	|j�|D]<\}}
}|r#tjj|
d	�
�}
d}	|j|
��>ttj|��}|	r)t|�\}}}|j|||d|zff���|j|d|zf���|S)zDecode parameters list according to RFC 2231.

    params is a sequence of 2-tuples containing (param name, string value).
    rrAN�*r4�numz"%s"Fzlatin-1)r�T)r�r�rfc2231_continuation�match�groupr��
setdefaultrBr�items�sortr�r��EMPTYSTRINGrDr)
�params�
new_params�rfc2231_paramsr4�value�encoded�mor��
continuations�extendedrr3r�s
             rrr�s���
��)��J��N��a�b�z���e��-�-��$������
!�
'�
'��
-��
������/�I�D�#����#�h���%�%�d�B�/�6�6��U�G�7L�M����t�V�e�E�l�%:�;�<�"��#1�#7�#7�#9��D�-��E��H���� �$1���Q������,�,�Q��,�C�A�#�H����Q��$1��+�*�*�5�1�2�E��+9�%�+@�(���5��!�!�4�'�8�V�e�^�)L�"M�N��!�!�4��%��"8�9�/$:�0�r&c���t|t�rt|�dk7rt|�S|\}}}|�|}t	|d�}	t|||�S#t$rt|�cYSwxYw)Nr}zraw-unicode-escape)r/�tuplerCr�bytesr0�LookupError)r��errors�fallback_charsetr3r��text�rawbytess       rrr�st���e�U�#�s�5�z�Q���u�~��$��G�X�t���#���T�/�0�H���8�W�f�-�-�����t�}���s�A�A%�$A%c��|�ddl}|jddd��|�tjj�}|j	�S)a}Return local time as an aware datetime object.

    If called without arguments, return current time.  Otherwise *dt*
    argument should be a datetime instance, and it is converted to the
    local time zone according to the system time zone database.  If *dt* is
    naive (that is, dt.tzinfo is None), it is assumed to be in local time.
    The isdst parameter is ignored.

    Nrz$The 'isdst' parameter to 'localtime'z>{name} is deprecated and slated for removal in Python {remove})r}�)�message�remove)�warnings�_deprecatedr�r�r�)r��isdstr�s   rr�r��sP��
������2�T��	�	�

�z�
�
�
�
"�
"�
$��
�=�=�?�r&)r)NFF)F)NN)r!zus-ascii)4�__doc__�__all__r��rer�r�r�r��urllib.parser��email._parseaddrrrrSrr
rr�
email.charsetrrRr��UEMPTYSTRING�CRLFr��compiler+r-rr%rr?rH�supports_strict_parsingr	r`rUrVr�rrr
rrrrr�ASCIIr�rrr�r�r&r�<module>r�s��
���$
�	��
�
���"�8�&�C�C�"�
�
�����
��
��
�R�Z�Z�+�
,�
��B�J�J�x� �	�	�5��B��2��(,�)�X��	��'�:1�&�.F�#��>��/�"�r�z�z�"K��H�H���.�`*3�,6��4r&__pycache__/_encoded_words.cpython-312.opt-1.pyc000064400000020164151706203560015404 0ustar00�

T��h]!��2�dZddlZddlZddlZddlZddlmZmZddlm	Z	gd�Z
ejejd�jd��Zd�ZGd	�d
e�Ze�Zdeed�<d
�Zd�Zd�Zd�Zd�Zeed�Zd�Zeed�Zeed�Zdd�Zy)z� Routines for manipulating RFC2047 encoded words.

This is currently a package-private API, but will be considered for promotion
to a public API if there is demand.

�N)�
ascii_letters�digits)�errors)�decode_q�encode_q�decode_b�encode_b�len_q�len_b�decode�encodes=([a-fA-F0-9]{2})c�f�tj|jd�j��S)N�)�bytes�fromhex�groupr)�ms �-/usr/lib64/python3.12/email/_encoded_words.py�<lambda>rAs��%�-�-�����
� 1� 1� 3�4�c�@�|jdd�}t|�gfS)N�_� )�replace�_q_byte_subber)�encodeds rrrCs"���o�o�d�D�)�G��'�"�B�&�&rc�b�eZdZdejd�zejd�zZd�Zy)�	_QByteMaps-!*+/�asciic�v�||jvrt|�||<||Sdj|�||<||S)Nz={:02X})�safe�chr�format)�self�keys  r�__missing__z_QByteMap.__missing__MsG���$�)�)���C��D��I��C�y��"�(�(��-�D��I��C�y�rN)�__name__�
__module__�__qualname__rr
rr!r&�rrrrIs/���*�m�*�*�7�3�3�m�f�m�m�G�6L�L�D�rr�_� c�2�djd�|D��S)N�c3�.K�|]
}t|���y�w�N)�_q_byte_map��.0�xs  r�	<genexpr>zencode_q.<locals>.<genexpr>Zs����3�7�a�;�q�>�7�s�)�join��bstrings rrrYs��
�7�7�3�7�3�3�3rc�&�td�|D��S)Nc3�@K�|]}tt|����y�wr0)�lenr1r2s  rr5zlen_q.<locals>.<genexpr>]s����4�G�q�s�;�q�>�"�G�s�)�sumr7s rr
r
\s���4�G�4�4�4rc�P�t|�dz}|rddd|z
nd}	tj||zd��|rtj�gfSgfS#t
j$r�	tj|d��tj�gfcYS#t
j$r|	tj|dzd��tj�tj�gfcYcYS#t
j$r|tj�gfcYcYcYSwxYwwxYwwxYw)N�s===rT)�validateFs==)	r;�base64�	b64decoder�InvalidBase64PaddingDefect�binascii�Error�InvalidBase64CharactersDefect�InvalidBase64LengthDefect)r�pad_err�missing_paddings   rrrds7���'�l�Q��G�,3�f�Z�a��i�(��O�E����W��6��F�5<�V�
.�
.�
0�1�
�	
�BD�
�	
���>�>�E�	E�� � ��5�9��5�5�7�8��
���~�~�	E�
E��$�$�W�u�_�u�E��9�9�;��6�6�8�:����
�>�>�
E���!A�!A�!C� D�D�D�

E��	E��E�sZ�0A�
A�D%�$+B�D%�D!�&AC,�'D!�(D%�,*D�D!�D%�D�D!�!D%c�J�tj|�jd�S)Nr)r@�	b64encoderr7s rr	r	�s�����G�$�+�+�G�4�4rc�N�tt|�d�\}}|dz|rdzSdzS)N�r>r)�divmodr;)r8�groups_of_3�leftovers   rrr�s0��"�3�w�<��3��K����?�8�a�3�3��3�3r)�q�bc�<�|jd�\}}}}}|jd�\}}}|j�}|jdd�}t	||�\}}	|j|�}||||fS#t$r=|jtjd|�d���|j|d�}Y�Kttf$rP|jdd�}|j�dk7r(|jtjd|�d	���Y��wxYw)
a�Decode encoded word and return (string, charset, lang, defects) tuple.

    An RFC 2047/2243 encoded word has the form:

        =?charset*lang?cte?encoded_string?=

    where '*lang' may be omitted but the other parts may not be.

    This function expects exactly such a string (that is, it does not check the
    syntax and may raise errors if the string is not well formed), and returns
    the encoded_string decoded first from its Content Transfer Encoding and
    then from the resulting bytes into unicode using the specified charset.  If
    the cte-decoded string does not successfully decode using the specified
    character set, a defect is added to the defects list and the unknown octets
    are replaced by the unicode 'unknown' character \uFDFF.

    The specified charset and language are returned.  The default for language,
    which is rarely if ever encountered, is the empty string.

    �?�*r�surrogateescapez0Encoded word contains bytes not decodable using z charset�unknown-8bitzUnknown charset z* in encoded word; decoded as unknown bytes)
�split�	partition�lowerr
�
_cte_decodersr�UnicodeDecodeError�appendr�UndecodableBytesDefect�LookupError�UnicodeEncodeError�CharsetError)	�ewr+�charset�cte�
cte_string�langr8�defects�strings	         rrr�s1��*&(�X�X�c�]�"�A�w��Z���(�(��-��G�Q��

�)�)�+�C�����):�;�G�$�S�)�'�2��G�W�
?�����(���7�D�'�)�)���<����v�4�4�62�29��H�6F�G�	H�����):�;���+�,�?�����):�;���=�=�?�n�,��N�N�6�.�.�1A�'��M<�0=�>�
?��?�s�!A8�8AD�=AD�Dc��|dk(r|jdd�}n|j|�}|�(td|�}td|�}||z
dkrdnd}t||�}|rd|z}dj||||�S)	aEncode string using the CTE encoding that produces the shorter result.

    Produces an RFC 2047/2243 encoded word of the form:

        =?charset*lang?cte?encoded_string?=

    where '*lang' is omitted unless the 'lang' parameter is given a value.
    Optional argument charset (defaults to utf-8) specifies the charset to use
    to encode the string to binary before CTE encoding it.  Optional argument
    'encoding' is the cte specifier for the encoding that should be used ('q'
    or 'b'); if it is None (the default) the encoding which produces the
    shortest encoded sequence is used, except that 'q' is preferred if it is up
    to five characters longer.  Optional argument 'lang' (default '') gives the
    RFC 2243 language string to specify in the encoded word.

    rVrrUrPrQ�rTz=?{}{}?{}?{}?=)r
�_cte_encode_length�
_cte_encodersr#)rgrb�encodingrer8�qlen�blenrs        rr
r
�s���"�.� ��-�-��):�;���-�-��(����!�#�&�w�/��!�#�&�w�/����+��/�3�s���H�%�g�.�G���T�z���"�"�7�D�(�G�D�Dr)zutf-8Nr.)�__doc__�rer@rC�	functoolsrgrr�emailr�__all__�partial�compile�subrr�dictrr1�ordrr
rr	rrZrrkrjr
r*rr�<module>rys����R
�
���(��
��#��"�"�:�2�:�:�.C�#D�#H�#H�4�6��'�	��	��k����C��H��4�5�$E�L5�4�
�	��
�
'*�V
�	��
�
�	���
Er__pycache__/_encoded_words.cpython-312.opt-2.pyc000064400000014451151706203560015407 0ustar00�

T��h]!��0�	ddlZddlZddlZddlZddlmZmZddlmZgd�Z	ejejd�jd��Z
d�ZGd�d	e�Ze�Zd
eed�<d�Zd
�Zd�Zd�Zd�Zeed�Zd�Zeed�Zeed�Zdd�Zy)�N)�
ascii_letters�digits)�errors)�decode_q�encode_q�decode_b�encode_b�len_q�len_b�decode�encodes=([a-fA-F0-9]{2})c�f�tj|jd�j��S)N�)�bytes�fromhex�groupr)�ms �-/usr/lib64/python3.12/email/_encoded_words.py�<lambda>rAs��%�-�-�����
� 1� 1� 3�4�c�@�|jdd�}t|�gfS)N�_� )�replace�_q_byte_subber)�encodeds rrrCs"���o�o�d�D�)�G��'�"�B�&�&rc�b�eZdZdejd�zejd�zZd�Zy)�	_QByteMaps-!*+/�asciic�v�||jvrt|�||<||Sdj|�||<||S)Nz={:02X})�safe�chr�format)�self�keys  r�__missing__z_QByteMap.__missing__MsG���$�)�)���C��D��I��C�y��"�(�(��-�D��I��C�y�rN)�__name__�
__module__�__qualname__rr
rr!r&�rrrrIs/���*�m�*�*�7�3�3�m�f�m�m�G�6L�L�D�rr�_� c�2�djd�|D��S)N�c3�.K�|]
}t|���y�w�N)�_q_byte_map��.0�xs  r�	<genexpr>zencode_q.<locals>.<genexpr>Zs����3�7�a�;�q�>�7�s�)�join��bstrings rrrYs��
�7�7�3�7�3�3�3rc�&�td�|D��S)Nc3�@K�|]}tt|����y�wr0)�lenr1r2s  rr5zlen_q.<locals>.<genexpr>]s����4�G�q�s�;�q�>�"�G�s�)�sumr7s rr
r
\s���4�G�4�4�4rc�P�t|�dz}|rddd|z
nd}	tj||zd��|rtj�gfSgfS#t
j$r�	tj|d��tj�gfcYS#t
j$r|	tj|dzd��tj�tj�gfcYcYS#t
j$r|tj�gfcYcYcYSwxYwwxYwwxYw)N�s===rT)�validateFs==)	r;�base64�	b64decoder�InvalidBase64PaddingDefect�binascii�Error�InvalidBase64CharactersDefect�InvalidBase64LengthDefect)r�pad_err�missing_paddings   rrrds7���'�l�Q��G�,3�f�Z�a��i�(��O�E����W��6��F�5<�V�
.�
.�
0�1�
�	
�BD�
�	
���>�>�E�	E�� � ��5�9��5�5�7�8��
���~�~�	E�
E��$�$�W�u�_�u�E��9�9�;��6�6�8�:����
�>�>�
E���!A�!A�!C� D�D�D�

E��	E��E�sZ�0A�
A�D%�$+B�D%�D!�&AC,�'D!�(D%�,*D�D!�D%�D�D!�!D%c�J�tj|�jd�S)Nr)r@�	b64encoderr7s rr	r	�s�����G�$�+�+�G�4�4rc�N�tt|�d�\}}|dz|rdzSdzS)N�r>r)�divmodr;)r8�groups_of_3�leftovers   rrr�s0��"�3�w�<��3��K����?�8�a�3�3��3�3r)�q�bc�>�	|jd�\}}}}}|jd�\}}}|j�}|jdd�}t	||�\}}	|j|�}||||fS#t$r=|jtjd|�d���|j|d�}Y�Kttf$rP|jdd�}|j�dk7r(|jtjd|�d	���Y��wxYw)
N�?�*r�surrogateescapez0Encoded word contains bytes not decodable using z charset�unknown-8bitzUnknown charset z* in encoded word; decoded as unknown bytes)
�split�	partition�lowerr
�
_cte_decodersr�UnicodeDecodeError�appendr�UndecodableBytesDefect�LookupError�UnicodeEncodeError�CharsetError)	�ewr+�charset�cte�
cte_string�langr8�defects�strings	         rrr�s6���(&(�X�X�c�]�"�A�w��Z���(�(��-��G�Q��

�)�)�+�C�����):�;�G�$�S�)�'�2��G�W�
?�����(���7�D�'�)�)���<����v�4�4�62�29��H�6F�G�	H�����):�;���+�,�?�����):�;���=�=�?�n�,��N�N�6�.�.�1A�'��M<�0=�>�
?��?�s�"A9�9AD�>AD�Dc��	|dk(r|jdd�}n|j|�}|�(td|�}td|�}||z
dkrdnd}t||�}|rd|z}dj||||�S)	NrVrrUrPrQ�rTz=?{}{}?{}?{}?=)r
�_cte_encode_length�
_cte_encodersr#)rgrb�encodingrer8�qlen�blenrs        rr
r
�s���� �.� ��-�-��):�;���-�-��(����!�#�&�w�/��!�#�&�w�/����+��/�3�s���H�%�g�.�G���T�z���"�"�7�D�(�G�D�Dr)zutf-8Nr.)�rer@rC�	functoolsrgrr�emailr�__all__�partial�compile�subrr�dictrr1�ordrr
rr	rrZrrkrjr
r*rr�<module>rxs����R
�
���(��
��#��"�"�:�2�:�:�.C�#D�#H�#H�4�6��'�	��	��k����C��H��4�5�$E�L5�4�
�	��
�
'*�V
�	��
�
�	���
Er__pycache__/_header_value_parser.cpython-312.opt-1.pyc000064400000403763151706203560016577 0ustar00�

T��h��	��
�dZddlZddlZddlZddlmZddlmZddlm	Z
ddlmZddlmZe
d�Zee
d	�zZe
d
�ZeezZee
d�z
Zee
d�z
Zee
d
�ze
d�z
ZeezZee
d�zZeezZee
d�z
ZddhZeezZd�Zd�Zej:dej<ej>z�Z Gd�de!�Z"Gd�de"�Z#Gd�de"�Z$Gd�de"�Z%Gd�de"�Z&Gd�d e#�Z'Gd!�d"e"�Z(Gd#�d$e"�Z)Gd%�d&e"�Z*Gd'�d(e"�Z+Gd)�d*e+�Z,Gd+�d,e#�Z-Gd-�d.e"�Z.Gd/�d0e"�Z/Gd1�d2e"�Z0Gd3�d4e"�Z1Gd5�d6e"�Z2Gd7�d8e"�Z3Gd9�d:e"�Z4Gd;�d<e"�Z5Gd=�d>e"�Z6Gd?�d@e"�Z7GdA�dBe"�Z8GdC�dDe"�Z9GdE�dFe"�Z:GdG�dHe"�Z;GdI�dJe"�Z<GdK�dLe"�Z=GdM�dNe%�Z>GdO�dPe"�Z?GdQ�dRe"�Z@GdS�dTe"�ZAGdU�dVe"�ZBGdW�dXeB�ZCGdY�dZe"�ZDGd[�d\e"�ZEGd]�d^e"�ZFGd_�d`e"�ZGGda�dbe"�ZHGdc�ddeH�ZIGde�dfeH�ZJGdg�dhe"�ZKGdi�dje"�ZLGdk�dle"�ZMGdm�dneM�ZNGdo�dpeN�ZOGdq�dre"�ZPGds�dteQ�ZRGdu�dveR�ZSGdw�dxeR�ZTGdy�dzeS�ZUGd{�d|ej��ZWeTdd}�ZXeTd~d�ZYd�eY_Zd�eY_[eTd�d��Z\ej:d�j�d�j�e���j�Z`ej:d�j�ej�d�j�e����j�Zcej:d��j�Zeej:d�j�ej�d�j�e����j�Zfej:d�j�ej�d�j�e����j�Zgej:d�j�ej�d�j�e����j�Zhd��Zid��Zjd��Zkd�d��Zld��Zmd��Znd��Zod��Zpd��Zqd��Zrd��Zsd��Ztd��Zud��Zvd��Zwd��Zxd��Zyd��Zzd��Z{d��Z|d��Z}d��Z~d��Zd��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�y)�alHeader value parser implementing various email-related RFC parsing rules.

The parsing methods defined in this module implement various email related
parsing rules.  Principal among them is RFC 5322, which is the followon
to RFC 2822 and primarily a clarification of the former.  It also implements
RFC 2047 encoded word decoding.

RFC 5322 goes to considerable trouble to maintain backward compatibility with
RFC 822 in the parse phase, while cleaning up the structure on the generation
phase.  This parser supports correct RFC 5322 generation by tagging white space
as folding white space only when folding is allowed in the non-obsolete rule
sets.  Actually, the parser is even more generous when accepting input than RFC
5322 mandates, following the spirit of Postel's Law, which RFC 5322 encourages.
Where possible deviations from the standard are annotated on the 'defects'
attribute of tokens that deviate.

The general structure of the parser follows RFC 5322, and uses its terminology
where there is a direct correspondence.  Where the implementation requires a
somewhat different structure than that used by the formal grammar, new terms
that mimic the closest existing terms are used.  Thus, it really helps to have
a copy of RFC 5322 handy when studying this code.

Input to the parser is a string that has already been unfolded according to
RFC 5322 rules.  According to the RFC this unfolding is the very first step, and
this parser leaves the unfolding step to a higher level message parser, which
will have already detected the line breaks that need unfolding while
determining the beginning and end of each header.

The output of the parser is a TokenList object, which is a list subclass.  A
TokenList is a recursive data structure.  The terminal nodes of the structure
are Terminal objects, which are subclasses of str.  These do not correspond
directly to terminal objects in the formal grammar, but are instead more
practical higher level combinations of true terminals.

All TokenList and Terminal objects have a 'value' attribute, which produces the
semantically meaningful value of that part of the parse subtree.  The value of
all whitespace tokens (no matter how many sub-tokens they may contain) is a
single space, as per the RFC rules.  This includes 'CFWS', which is herein
included in the general class of whitespace tokens.  There is one exception to
the rule that whitespace tokens are collapsed into single spaces in values: in
the value of a 'bare-quoted-string' (a quoted-string with no leading or
trailing whitespace), any whitespace that appeared between the quotation marks
is preserved in the returned value.  Note that in all Terminal strings quoted
pairs are turned into their unquoted values.

All TokenList and Terminal objects also have a string value, which attempts to
be a "canonical" representation of the RFC-compliant form of the substring that
produced the parsed subtree, including minimal use of quoted pair quoting.
Whitespace runs are not collapsed.

Comment tokens also have a 'content' attribute providing the string found
between the parens (including any nested comments) with whitespace preserved.

All TokenList and Terminal objects have a 'defects' attribute which is a
possibly empty list all of the defects found while creating the token.  Defects
may appear on any token in the tree, and a composite list of all defects in the
subtree is available through the 'all_defects' attribute of any node.  (For
Terminal notes x.defects == x.all_defects.)

Each object in a parse tree is called a 'token', and each has a 'token_type'
attribute that gives the name from the RFC 5322 grammar that it represents.
Not all RFC 5322 nodes are produced, and there is one non-RFC 5322 node that
may be produced: 'ptext'.  A 'ptext' is a string of printable ascii characters.
It is returned in place of lists of (ctext/quoted-pair) and
(qtext/quoted-pair).

XXX: provide complete list of token types.
�N)�	hexdigits)�
itemgetter)�_encoded_words)�errors)�utilsz 	�(z
()<>@,:;.\"[]�.z."(z/?=z*'%�%�
�
c�X�t|�jdd�jdd�S)z;Escape dquote and backslash for use within a quoted-string.�\�\\�"z\")�str�replace��values �3/usr/lib64/python3.12/email/_header_value_parser.py�make_quoted_pairsrcs&���u�:���d�F�+�3�3�C��?�?�c�$�t|�}d|�d�S)Nr)r)r�escapeds  r�quote_stringrhs����&�G�
�w�i�q�>�rz�
   =\?            # literal =?
   [^?]*          # charset
   \?             # literal ?
   [qQbB]         # literal 'q' or 'b', case insensitive
   \?             # literal ?
  .*?             # encoded word
  \?=             # literal ?=
c���eZdZdZdZdZ�fd�Zd�Z�fd�Ze	d��Z
e	d��Zd�Ze	d	��Z
e	d
��Zd�Zdd�Zdd
�Zdd�Z�xZS)�	TokenListNTc�2��t�|�|i|��g|_y�N)�super�__init__�defects)�self�args�kw�	__class__s   �rr zTokenList.__init__�s���
���$�%�"�%���rc�2�djd�|D��S)N�c3�2K�|]}t|����y�wr�r��.0�xs  r�	<genexpr>z$TokenList.__str__.<locals>.<genexpr>������,�t�!�s�1�v�t�����join�r"s r�__str__zTokenList.__str__�s���w�w�,�t�,�,�,rc�h��dj|jjt�|���S�Nz{}({})��formatr%�__name__r�__repr__�r"r%s �rr9zTokenList.__repr__�s+������t�~�~�6�6�"�W�-�/�1�	1rc�2�djd�|D��S)Nr'c3�NK�|]}|js�|j���y�wrrr*s  rr-z"TokenList.value.<locals>.<genexpr>�s����8��1����q�w�w��s�%�%r0r2s rrzTokenList.value�s���w�w�8��8�8�8rc�<�td�|D�|j�S)Nc3�4K�|]}|j���y�wr)�all_defectsr*s  rr-z(TokenList.all_defects.<locals>.<genexpr>�s����0�4�a�A�M�M�4���)�sumr!r2s rr?zTokenList.all_defects�s���0�4�0�$�,�,�?�?rc�(�|dj�S�Nr)�startswith_fwsr2s rrDzTokenList.startswith_fws�s���A�w�%�%�'�'rc�&�td�|D��S)zATrue if all top level tokens of this part may be RFC2047 encoded.c3�4K�|]}|j���y�wr)�
as_ew_allowed)r+�parts  rr-z*TokenList.as_ew_allowed.<locals>.<genexpr>�s����7�$�$�4�%�%�$�r@)�allr2s rrGzTokenList.as_ew_allowed�s���7�$�7�7�7rc�N�g}|D]}|j|j��|Sr)�extend�comments)r"rL�tokens   rrLzTokenList.comments�s&�����E��O�O�E�N�N�+���rc��t||��S)N��policy)�_refold_parse_tree�r"rPs  r�foldzTokenList.fold�s��!�$�v�6�6rc�:�t|j|���y)N��indent)�print�ppstr�r"rVs  r�pprintzTokenList.pprint�s��
�d�j�j��j�'�(rc�D�dj|j|���S)NrrU)r1�_pprYs  rrXzTokenList.ppstr�s���y�y������0�1�1rc#�~K�dj||jj|j���|D]A}t	|d�s|dj|�z���&|j|dz�Ed{����C|jrdj|j�}nd}dj||���y7�E�w)Nz{}{}/{}(r\z*    !! invalid element in token list: {!r}z    z Defects: {}r'z{}){})r7r%r8�
token_type�hasattrr\r!)r"rVrM�extras    rr\z
TokenList._pp�s����������N�N�#�#��O�O��	��E��5�%�(��!5�5;�V�E�]�C�D�!�9�9�V�F�]�3�3�3���<�<�"�)�)�$�,�,�7�E��E��n�n�V�U�+�+�4�s�A3B=�5B;�6AB=�r')r8�
__module__�__qualname__r^�syntactic_break�ew_combine_allowedr r3r9�propertyrr?rDrGrLrSrZrXr\�
__classcell__�r%s@rrr}s�����J��O����-�1��9��9��@��@�(��8��8�����7�)�2�,rrc�,�eZdZed��Zed��Zy)�WhiteSpaceTokenListc��y�N� �r2s rrzWhiteSpaceTokenList.value����rc�`�|D�cgc]}|jdk(s�|j�� c}Scc}w)N�comment)r^�content�r"r,s  rrLzWhiteSpaceTokenList.comments�s)��#'�C�4�a�1�<�<��+B��	�	�4�C�C��C��+�+N)r8rbrcrfrrLrnrrrjrj�s*��
�����D��Drrjc��eZdZdZy)�UnstructuredTokenList�unstructuredN�r8rbrcr^rnrrrvrv�s���Jrrvc��eZdZdZy)�Phrase�phraseNrxrnrrrzrz�����Jrrzc��eZdZdZy)�Word�wordNrxrnrrr~r~�����Jrr~c��eZdZdZy)�CFWSList�cfwsNrxrnrrr�r��r�rr�c��eZdZdZy)�Atom�atomNrxrnrrr�r��r�rr�c��eZdZdZdZy)�TokenrMFN)r8rbrcr^�encode_as_ewrnrrr�r��s���J��Lrr�c��eZdZdZdZdZdZy)�EncodedWord�encoded-wordN)r8rbrcr^�cte�charset�langrnrrr�r��s���J�
�C��G��Drr�c�@�eZdZdZed��Zed��Zed��Zy)�QuotedString�
quoted-stringc�L�|D]}|jdk(s�|jcSy�N�bare-quoted-string�r^rrss  rrrzQuotedString.content�s"���A��|�|�3�3��w�w��rc��g}|D]G}|jdk(r|jt|���-|j|j��Idj	|�S)Nr�r')r^�appendrrr1)r"�resr,s   r�quoted_valuezQuotedString.quoted_value�sN�����A��|�|�3�3��
�
�3�q�6�"��
�
�1�7�7�#�	�
�w�w�s�|�rc�L�|D]}|jdk(s�|jcSyr�r��r"rMs  r�stripped_valuezQuotedString.stripped_value�s%���E����#7�7��{�{�"�rN)r8rbrcr^rfrrr�r�rnrrr�r��sA�� �J�
����
�����#��#rr�c�&�eZdZdZd�Zed��Zy)�BareQuotedStringr�c�D�tdjd�|D���S)Nr'c3�2K�|]}t|����y�wrr)r*s  rr-z+BareQuotedString.__str__.<locals>.<genexpr>
s����#9�D�q�C��F�D�r/)rr1r2s rr3zBareQuotedString.__str__	s���B�G�G�#9�D�#9�9�:�:rc�2�djd�|D��S)Nr'c3�2K�|]}t|����y�wrr)r*s  rr-z)BareQuotedString.value.<locals>.<genexpr>r.r/r0r2s rrzBareQuotedString.value����w�w�,�t�,�,�,rN)r8rbrcr^r3rfrrnrrr�r�s ��%�J�;��-��-rr�c�<�eZdZdZd�Zd�Zed��Zed��Zy)�Commentrqc��djtdg|D�cgc]}|j|���c}dggg��Scc}w)Nr'r�))r1rA�quoterss  rr3zComment.__str__sK���w�w�s� �E�48�9�D�q�T�Z�Z��]�D�9� �E�� "�	#�$�	$��9s�>c��|jdk(rt|�St|�jdd�jdd�jdd�S)Nrqrrrz\(r�z\))r^rr)r"rs  rr�z
Comment.quotesR�����y�(��u�:���5�z�!�!�$��/�7�7�"%�u�.�.5�g�"%�u�/.�	.rc�2�djd�|D��S)Nr'c3�2K�|]}t|����y�wrr)r*s  rr-z"Comment.content.<locals>.<genexpr>%r.r/r0r2s rrrzComment.content#r�rc��|jgSr)rrr2s rrLzComment.comments's�����~�rN)	r8rbrcr^r3r�rfrrrLrnrrr�r�s9���J�$�.��-��-����rr�c�@�eZdZdZed��Zed��Zed��Zy)�AddressListzaddress-listc�L�|D�cgc]}|jdk(s�|��c}Scc}w)N�address�r^rss  r�	addresseszAddressList.addresses/�%���;�4�a�1�<�<��#:��4�;�;��;��!�!c�(�td�|D�g�S)Nc3�RK�|]}|jdk(r|j���!y�w�r�N�r^�	mailboxesr*s  rr-z(AddressList.mailboxes.<locals>.<genexpr>5s'����>�!��Q�\�\�9�%<��K�K�!���%'�rAr2s rr�zAddressList.mailboxes3�!���>�!�>�?A�C�	Crc�(�td�|D�g�S)Nc3�RK�|]}|jdk(r|j���!y�wr��r^�
all_mailboxesr*s  rr-z,AddressList.all_mailboxes.<locals>.<genexpr>:s'����>�!��Q�\�\�9�%<��O�O�!�r�r�r2s rr�zAddressList.all_mailboxes8r�rN)r8rbrcr^rfr�r�r�rnrrr�r�+sE���J�
�<��<��C��C��C��Crr�c�@�eZdZdZed��Zed��Zed��Zy)�Addressr�c�F�|djdk(r|djSy)Nr�group�r^�display_namer2s rr�zAddress.display_nameBs)����7����(���7�'�'�'�)rc�x�|djdk(r|dgS|djdk(rgS|djS�Nr�mailbox�invalid-mailboxr�r2s rr�zAddress.mailboxesGsH����7����*���G�9��
�!�W�
�
�#4�
4��I��A�w� � � rc��|djdk(r|dgS|djdk(r|dgS|djSr�r�r2s rr�zAddress.all_mailboxesOsO����7����*���G�9��
�!�W�
�
�#4�
4���G�9���A�w�$�$�$rN)r8rbrcr^rfr�r�r�rnrrr�r�>sA���J�
�(��(��!��!��%��%rr�c�0�eZdZdZed��Zed��Zy)�MailboxList�mailbox-listc�L�|D�cgc]}|jdk(s�|��c}Scc}w)Nr�r�rss  rr�zMailboxList.mailboxes[r�r�c�H�|D�cgc]}|jdvr|��c}Scc}w)N)r�r�r�rss  rr�zMailboxList.all_mailboxes_s2���?�4�a��|�|�=�=��4�?�	?��?s�N�r8rbrcr^rfr�r�rnrrr�r�Ws-���J�
�<��<��?��?rr�c�0�eZdZdZed��Zed��Zy)�	GroupList�
group-listc�L�|r|djdk7rgS|djS�Nrr�r�r2s rr�zGroupList.mailboxesis+���t�A�w�)�)�^�;��I��A�w� � � rc�L�|r|djdk7rgS|djSr�r�r2s rr�zGroupList.all_mailboxesos+���t�A�w�)�)�^�;��I��A�w�$�$�$rNr�rnrrr�r�es-���J�
�!��!�
�%��%rr�c�@�eZdZdZed��Zed��Zed��Zy)�Groupr�c�H�|djdk7rgS|djS�N�r�r�r2s rr�zGroup.mailboxeszs)����7����-��I��A�w� � � rc�H�|djdk7rgS|djSr�r�r2s rr�zGroup.all_mailboxes�s)����7����-��I��A�w�$�$�$rc� �|djSrC)r�r2s rr�zGroup.display_name�s���A�w�#�#�#rN)r8rbrcr^rfr�r�r�rnrrr�r�vsA���J�
�!��!�
�%��%�
�$��$rr�c�`�eZdZdZed��Zed��Zed��Zed��Zed��Z	y)�NameAddr�	name-addrc�>�t|�dk(ry|djS�N�r)�lenr�r2s rr�zNameAddr.display_name�s ���t�9��>���A�w�#�#�#rc� �|djS�N�����
local_partr2s rr�zNameAddr.local_part�s���B�x�"�"�"rc� �|djSr���domainr2s rr�zNameAddr.domain�s���B�x���rc� �|djSr�)�router2s rr�zNameAddr.route�s���B�x�~�~�rc� �|djSr���	addr_specr2s rr�zNameAddr.addr_spec�s���B�x�!�!�!rN�
r8rbrcr^rfr�r�r�r�r�rnrrr�r��si���J�
�$��$�
�#��#����������"��"rr�c�P�eZdZdZed��Zed��Zed��Zed��Zy)�	AngleAddrz
angle-addrc�L�|D]}|jdk(s�|jcSy�N�	addr-spec)r^r�rss  rr�zAngleAddr.local_part�s"���A��|�|�{�*��|�|�#�rc�L�|D]}|jdk(s�|jcSyr��r^r�rss  rr�zAngleAddr.domain�s!���A��|�|�{�*��x�x��rc�L�|D]}|jdk(s�|jcSy)N�	obs-route)r^�domainsrss  rr�zAngleAddr.route�s"���A��|�|�{�*��y�y� �rc��|D]O}|jdk(s�|jr|jcSt|j�|jzcSy)Nr�z<>)r^r�r�rrss  rr�zAngleAddr.addr_spec�sF���A��|�|�{�*��<�<��;�;�&�'����5����C�C��rN)	r8rbrcr^rfr�r�r�r�rnrrr�r��sU���J�
�$��$�
� �� �
�!��!�
���rr�c� �eZdZdZed��Zy)�ObsRouter�c�`�|D�cgc]}|jdk(s�|j�� c}Scc}w)Nr�r�rss  rr�zObsRoute.domains�s)��"&�C�$�Q�!�,�,�(�*B����$�C�C��CrtN)r8rbrcr^rfr�rnrrrr�s���J�
�D��Drrc�`�eZdZdZed��Zed��Zed��Zed��Zed��Z	y)�Mailboxr�c�F�|djdk(r|djSy�Nrr�r�r2s rr�zMailbox.display_name�s)����7����,���7�'�'�'�-rc� �|djSrCr�r2s rr�zMailbox.local_part�����A�w�!�!�!rc� �|djSrCr�r2s rr�zMailbox.domain�s���A�w�~�~�rc�F�|djdk(r|djSyr)r^r�r2s rr�z
Mailbox.route�s'����7����,���7�=�=� �-rc� �|djSrCr�r2s rr�zMailbox.addr_spec�s���A�w� � � rNr�rnrrrr�si���J�
�(��(��"��"������!��!��!��!rrc�0�eZdZdZed��ZexZxZxZZ	y)�InvalidMailboxr�c��yrrnr2s rr�zInvalidMailbox.display_name����rNr�rnrrr
r
�s/��"�J�
����/;�:�J�:��:�%�)rr
c�0��eZdZdZdZe�fd��Z�xZS)�Domainr�Fc�R��djt�|�j��S�Nr'�r1rr�splitr:s �rr�z
Domain.domain������w�w�u�w�}�*�*�,�-�-r)r8rbrcr^rGrfr�rgrhs@rrr�s����J��M�
�.��.rrc��eZdZdZy)�DotAtom�dot-atomNrxrnrrrrs���Jrrc��eZdZdZdZy)�DotAtomTextz
dot-atom-textTN�r8rbrcr^rGrnrrrrs�� �J��Mrrc��eZdZdZdZy)�
NoFoldLiteralzno-fold-literalFNrrnrrrr
s��"�J��Mrrc�T�eZdZdZdZed��Zed��Zed��Zed��Z	y)�AddrSpecr�Fc� �|djSrCr�r2s rr�zAddrSpec.local_partrrc�>�t|�dkry|djS)N�r�)r�r�r2s rr�zAddrSpec.domains���t�9�q�=���B�x���rc���t|�dkr|djS|djj�|djz|djj�zS)Nr#rr�r�)r�r�rstrip�lstripr2s rrzAddrSpec.valuesU���t�9�q�=���7�=�=� ��A�w�}�}�#�#�%�d�1�g�m�m�3�D��G�M�M�4H�4H�4J�J�Jrc���t|j�}t|�t|tz
�kDrt	|j�}n|j}|j
�|dz|j
zS|S)N�@)�setr�r��
DOT_ATOM_ENDSrr�)r"�nameset�lps   rr�zAddrSpec.addr_spec$s_���d�o�o�&���w�<�#�g�m�3�4�4��d�o�o�.�B����B��;�;�"���8�d�k�k�)�)��	rN)
r8rbrcr^rGrfr�r�rr�rnrrr r s\���J��M�
�"��"�����
�K��K�
���rr c��eZdZdZdZy)�ObsLocalPartzobs-local-partFNrrnrrr.r.0s��!�J��Mrr.c�@��eZdZdZdZed��Ze�fd��Z�xZS)�DisplayNamezdisplay-nameFc��t|�}t|�dk(r|jS|djdk(r|j	d�n<t|dt�r)|ddjdk(rt|ddd�|d<|djdk(r|j	�|jSt|dt�r)|ddjdk(rt|ddd�|d<|jS)Nrr�r�r�)rr�rr^�pop�
isinstance)r"r�s  rr�zDisplayName.display_name;s�����o���s�8�q�=��9�9���q�6����&��G�G�A�J��3�q�6�9�-���F�1�I�(�(�F�2�"�3�q�6�!�"�:�.��A���r�7����'��G�G�I�
�y�y���3�r�7�I�.���G�B�K�*�*�f�4�#�C��G�C�R�L�1��B���y�y�rc���d}|jrd}n|D]}|jdk(s�d}�t|�dk7r�|r�dx}}|djdk(s(t|dt�r|ddjdk(rd}|djdk(s(t|dt�r|ddjdk(rd}|t|j�z|zSt�|� S)	NFTr�rr'r�rmr�)	r!r^r�r3rrr�rr)r"r�r,�pre�postr%s     �rrzDisplayName.valueNs�������<�<��E����<�<�?�2� �E���t�9��>�e��O�C�$��Q��"�"�f�,��4��7�I�.��Q���
�%�%��/����R��#�#�v�-��4��8�Y�/��R����'�'�6�1����|�D�$5�$5�6�6�t�;�;��7�=� r)	r8rbrcr^rerfr�rrgrhs@rr0r06s4����J���
����$�!��!rr0c�4�eZdZdZdZed��Zed��Zy)�	LocalPartz
local-partFc�b�|djdk(r|djS|djS)Nrr�)r^r�rr2s rrzLocalPart.valueks2����7����0���7�'�'�'���7�=�=� rc���tg}t}d}|dtgzD]�}|jdk(r�|r2|jdk(r#|djdk(rt|dd�|d<t|t�}|r?|jdk(r0|djdk(r|j	t|dd��n|j	|�|d}|}��t|dd�}|j
S)NFrr��dotr�r�)�DOTr^rr3r�r)r"r��last�
last_is_tl�tok�is_tls      rr�zLocalPart.local_partrs����e�����
���7�c�U�?�C��~�~��'���s�~�~��6���H�'�'�6�1�#�D��"�I�.��B���s�I�.�E��$�/�/�U�2���F�%�%��/��
�
�9�S���W�-�.��
�
�3���r�7�D��J�#���A�b�	�"���y�y�rN)r8rbrcr^rGrfrr�rnrrr8r8fs2���J��M�
�!��!����rr8c�@��eZdZdZdZe�fd��Zed��Z�xZS)�
DomainLiteralzdomain-literalFc�R��djt�|�j��Srrr:s �rr�zDomainLiteral.domain�rrc�L�|D]}|jdk(s�|jcSy)N�ptextr�rss  r�ipzDomainLiteral.ip�s!���A��|�|�w�&��w�w��r)	r8rbrcr^rGrfr�rFrgrhs@rrBrB�s3���!�J��M�
�.��.����rrBc��eZdZdZdZdZy)�MIMEVersionzmime-versionN)r8rbrcr^�major�minorrnrrrHrH�s���J��E��ErrHc�<�eZdZdZdZdZdZed��Zed��Z	y)�	Parameter�	parameterF�us-asciic�<�|jr|djSdSr�)�	sectioned�numberr2s r�section_numberzParameter.section_number�s��"&���t�A�w�~�~�6�Q�6rc���|D]n}|jdk(r|jcS|jdk(s�0|D]:}|jdk(s�|D]#}|jdk(s�|jcccS�<�py)Nrr�r�r')r^r�r�s  r�param_valuezParameter.param_value�sx���E����7�*��+�+�+����?�2�"�E��'�'�+?�?�%*�E�$�/�/�7�:�',�';�';� ;�&+�#�	�rN)
r8rbrcr^rP�extendedr�rfrRrTrnrrrLrL�s<���J��I��H��G�
�7��7�
���rrLc��eZdZdZy)�InvalidParameter�invalid-parameterNrxrnrrrWrW�s��$�JrrWc� �eZdZdZed��Zy)�	Attribute�	attributec�d�|D]+}|jjd�s�|jcSy)N�attrtext)r^�endswithrr�s  rr�zAttribute.stripped_value�s*���E����(�(��4��{�{�"�rN�r8rbrcr^rfr�rnrrrZrZ�s���J�
�#��#rrZc��eZdZdZdZy)�Section�sectionN)r8rbrcr^rQrnrrrara�s���J�
�Frrac� �eZdZdZed��Zy)�Valuerc��|d}|jdk(r|d}|jjd�r|jS|jS)Nrr�r�)r�r[zextended-attribute)r^r^r�rr�s  rr�zValue.stripped_value�sP���Q������v�%���G�E����$�$�D�F��'�'�'��z�z�rNr_rnrrrdrd�s���J�
���rrdc�*�eZdZdZdZed��Zd�Zy)�MimeParameters�mime-parametersFc#�lK�i}|D]w}|jjd�s�|djdk7r�2|djj�}||vrg||<||j	|j
|f��y|j
�D�]�\}}t|td���}|dd}|j}|jsRt|�dkDrD|dddk(r9|ddjj	tjd��|dd}g}d}|D�]\}	}
|	|k7ri|
js/|
jj	tjd���G|
jj	tjd��|dz
}|
j}|
jrv	t j"j%|�}	|j'|d	�}t-j.|�r.|
jj	tj0��	|j	|���d
j5|�}||f�����y#t(t*f$r|j'd
d	�}Y��wxYw#t*$r$t j"j3|d��}Y��wxYw�w)NrMrr[)�keyr�z.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numbering�surrogateescaperNzlatin-1)�encodingr')r^r^r�stripr�rR�items�sortedrr�rUr�r!r�InvalidHeaderDefectrT�urllib�parse�unquote_to_bytes�decode�LookupError�UnicodeEncodeErrorr�_has_surrogates�UndecodableBytesDefect�unquoter1)r"�paramsrM�name�parts�first_paramr��value_parts�irR�paramrs            rrzzMimeParameters.params�s��������E��#�#�,�,�[�9���Q�x�"�"�k�1����8�>�>�'�'�)�D��6�!�!��t���4�L����!5�!5�u� =�>��"�<�<�>�K�D�%��5�j��m�4�E���(�1�+�K�!�)�)�G��'�'�C��J��N���8�A�;�!�#��!�H�Q�K�'�'�.�.�v�/I�/I�H�0J�K�!�"�1�I�E��K��A�).�%���!�Q�&�!�>�>��
�
�,�,�V�-G�-G�I�.K�L� ��
�
�,�,�V�-G�-G�F�.H�I��Q����)�)���>�>�R� &��� =� =�e� D��P�$)�L�L��:K�$L�E�!�0�0��7�!�M�M�0�0��1N�1N�1P�Q��"�"�5�)�C*/�D�G�G�K�(�E���+��g*��R!,�-?�@�P�
%*�L�L��=N�$O�E�P��.�P�!'��� 4� 4�U�Y� 4� O��	P�sI�F6J4�9J�I�+A2J4�!J�>J4�J�J4�*J1�.J4�0J1�1J4c	���g}|jD]C\}}|r+|jdj|t|����3|j|��Edj	|�}|rd|zSdS)N�{}={}z; rmr')rzr�r7rr1)r"rzr{rs    rr3zMimeParameters.__str__,se�����;�;�K�D�%���
�
�g�n�n�T�<��3F�G�H��
�
�d�#�	'�
���6�"��%�s�V�|�-�2�-rN)r8rbrcr^rdrfrzr3rnrrrgrg�s&��"�J��O�
�C��C�J.rrgc� �eZdZdZed��Zy)�ParameterizedHeaderValueFc�`�t|�D]}|jdk(s�|jcSiS)Nrh)�reversedr^rzr�s  rrzzParameterizedHeaderValue.params=s0���d�^�E����#4�4��|�|�#�$��	rN)r8rbrcrdrfrzrnrrr�r�7s���O�
���rr�c��eZdZdZdZdZdZy)�ContentTypezcontent-typeF�text�plainN)r8rbrcr^rG�maintype�subtypernrrr�r�Es���J��M��H��Grr�c��eZdZdZdZdZy)�ContentDispositionzcontent-dispositionFN)r8rbrcr^rG�content_dispositionrnrrr�r�Ls��&�J��M��rr�c��eZdZdZdZdZy)�ContentTransferEncodingzcontent-transfer-encodingF�7bitN)r8rbrcr^rGr�rnrrr�r�Rs��,�J��M�
�Crr�c��eZdZdZdZy)�HeaderLabelzheader-labelFNrrnrrr�r�Xs���J��Mrr�c��eZdZdZdZd�Zy)�MsgIDzmsg-idFc�2�t|�|jzSr)r�lineseprRs  rrSz
MsgID.foldas���4�y�6�>�>�)�)rN)r8rbrcr^rGrSrnrrr�r�]s���J��M�*rr�c��eZdZdZy)�	MessageIDz
message-idNrxrnrrr�r�fs���Jrr�c��eZdZdZy)�InvalidMessageIDzinvalid-message-idNrxrnrrr�r�js��%�Jrr�c��eZdZdZy)�Header�headerNrxrnrrr�r�nr|rr�c�r��eZdZdZdZdZ�fd�Z�fd�Zd�Ze	d��Z
d
�fd�	Zd�Ze	d��Z
d	�Z�xZS)�TerminalTc�D��t�|�||�}||_g|_|Sr)r�__new__r^r!)�clsrr^r"r%s    �rr�zTerminal.__new__|s&����w��s�E�*��$�������rc�h��dj|jjt�|���Sr5r6r:s �rr9zTerminal.__repr__�s&������t�~�~�6�6���8H�8J�K�Krc�b�t|jjdz|jz�y)N�/)rWr%r8r^r2s rrZzTerminal.pprint�s"��
�d�n�n�%�%��+�d�o�o�=�>rc�,�t|j�Sr)�listr!r2s rr?zTerminal.all_defects�s���D�L�L�!�!rc	����dj||jj|jt�|��|jsd�gSdj|j��gS)Nz
{}{}/{}({}){}r'z {})r7r%r8r^rr9r!)r"rVr%s  �rr\zTerminal._pp�sg����&�&���N�N�#�#��O�O��G����l�l�B���	�
).���T�\�\�(B���	rc��yrrnr2s r�pop_trailing_wszTerminal.pop_trailing_ws�rrc��gSrrnr2s rrLzTerminal.comments�s���	rc�0�t|�|jfSr)rr^r2s r�__getnewargs__zTerminal.__getnewargs__�s���4�y�$�/�/�*�*rra)r8rbrcrGrerdr�r9rZrfr?r\r�rLr�rgrhs@rr�r�vsZ����M����O��L�?��"��"�������+rr�c�"�eZdZed��Zd�Zy)�WhiteSpaceTerminalc��yrlrnr2s rrzWhiteSpaceTerminal.value�rorc��y)NTrnr2s rrDz!WhiteSpaceTerminal.startswith_fws�s��rN�r8rbrcrfrrDrnrrr�r��s��
����rr�c�"�eZdZed��Zd�Zy)�
ValueTerminalc��|Srrnr2s rrzValueTerminal.value�s���rc��y)NFrnr2s rrDzValueTerminal.startswith_fws�s��rNr�rnrrr�r��s��
����rr�c�"�eZdZed��Zd�Zy)�EWWhiteSpaceTerminalc��yrrnr2s rrzEWWhiteSpaceTerminal.value�s��rc��yrrnr2s rr3zEWWhiteSpaceTerminal.__str__�s��rN)r8rbrcrfrr3rnrrr�r��s��
����rr�c��eZdZdZy)�_InvalidEwErrorz1Invalid encoded word found while parsing headers.N)r8rbrc�__doc__rnrrr�r��s��;rr�r;�,zlist-separatorFr(zroute-component-markerz([{}]+)r'z[^{}]+z[\x00-\x20\x7F]c��t|�}|r.|jjtj|��tj|�r/|jjtjd��yy)z@If input token contains ASCII non-printables, register a defect.z*Non-ASCII characters found in header tokenN)�_non_printable_finderr!r�r�NonPrintableDefectrrwrx)�xtext�non_printabless  r�_validate_xtextr��sc��+�5�1�N��
�
�
���V�6�6�~�F�G����U�#�
�
�
���V�:�:�8�:�	;�$rc�"�t|d�^}}g}d}d}tt|��D]6}||dk(r
|rd}d}nd}�|rd}n	|||vrn|j||��8dz}dj	|�dj	||dg|z�|fS)akScan printables/quoted-pairs until endchars and return unquoted ptext.

    This function turns a run of qcontent, ccontent-without-comments, or
    dtext-with-quoted-printables into a single string by unquoting any
    quoted printables.  It returns the string, the remaining value, and
    a flag that is True iff there were any quoted printables decoded.

    r�FrTr'N)�
_wsp_splitter�ranger�r�r1)r�endchars�fragment�	remainder�vchars�escape�had_qp�poss        r�_get_ptext_to_endcharsr��s���)���2��H�y�
�F�
�F�
�F��S��]�#���C�=�D� �����������F�
�c�]�h�
&���
�
�h�s�m�$�$��A�g��
�7�7�6�?�B�G�G�X�c�d�^�$4�y�$@�A�6�I�Irc�r�|j�}t|dt|�t|�z
d�}||fS)z�FWS = 1*WSP

    This isn't the RFC definition.  We're using fws to represent tokens where
    folding can be done, but when we are parsing the *un*folding has already
    been done so we don't need to watch out for CRLF.

    N�fws)r&r�r�)r�newvaluer�s   r�get_fwsr�s:���|�|�~�H�
�U�#<�C��J�s�8�}�$<�=�u�
E�C���=�rc��t�}|jd�s$tjdj	|���|ddjdd�^}}||ddk(r$tjdj	|���dj
|�}t|�dkDrF|dtvr;|dtvr0|jd	�dkr|jdd�^}}|dz|z}t|j��dkDr.|jjtjd
��||_
dj
|�}	tjd|zdz�\}}}	}
||_|	|_|jj+|
�|ru|dt,vr t/|�\}}|j|��-t1|d�^}}t3||�}
t5|
�|j|
�dj
|�}|r�u|r9|dt,vr.|jjtjd��||fS#t t"f$r%t%dj	|j���wxYw)
zE encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

    �=?z"expected encoded word but found {}r�Nz?=r�r'r�?zwhitespace inside encoded wordz!encoded word format invalid: '{}'z.missing trailing whitespace after encoded-word)r��
startswithr�HeaderParseErrorr7rr1r�r�countr!r�rpr��_ewrt�
ValueError�KeyErrorr�r�r�rK�WSPr�r�r�r�)r�
terminal_type�ewr?r��remstr�restr�r�r�r!rM�chars�vtexts              r�get_encoded_wordr� s`��
��B����D�!��%�%�0�7�7��>�@�	@��A�B�i�o�o�d�A�.�O�C�)�
�e�A�B�i���%�%�0�7�7��>�@�	@�
�W�W�Y�
�F��F��a���q�	�Y���q�	�Y���	�	�#����!�<�<��a�0���y��D�j�4���
�3�9�9�;��!��
�
�
���&�4�4�,�.�	/�
�B�F��G�G�I��E�@�'*�z�z�$��*�t�2C�'D�$��g�t�W��B�J��B�G��J�J���g��
���7�c�>�!�$�-�K�E�4��I�I�e���)�$��2���	��e�]�3�����
�	�	�%���w�w�y�!���
��q���$�
�
�
���&�4�4�<�>�	?�
�u�9���)
��!�@��/�6�6�r�v�v�>�@�	@�@�s� I
�
4I>c� �t�}|�r[|dtvr t|�\}}|j|��.d}|j	d�r�	t|d�\}}d}t
|�dkDrB|djdk7r0|jjtjd��d}|r2t
|�d	kDr$|d
jdk(rt|dd�|d<|j|���t|d	�^}}|r(tj!|�r|j#d�^}}t%|d�}t'|�|j|�dj)|�}|r��[|S#t$rd}Y��tj$rY��wxYw)
aOunstructured = (*([FWS] vchar) *WSP) / obs-unstruct
       obs-unstruct = *((*LF *CR *(obs-utext) *LF *CR)) / FWS)
       obs-utext = %d0 / obs-NO-WS-CTL / LF / CR

       obs-NO-WS-CTL is control characters except WSP/CR/LF.

    So, basically, we have printable runs, plus control characters or nulls in
    the obsolete syntax, separated by whitespace.  Since RFC 2047 uses the
    obsolete syntax in its specification, but requires whitespace on either
    side of the encoded words, I can see no reason to need to separate the
    non-printable-non-whitespace from the printable runs if they occur, so we
    parse this into xtext tokens separated by WSP tokens.

    Because an 'unstructured' value must by definition constitute the entire
    value, this 'get' routine does not return a remaining value, only the
    parsed TokenList.

    rTr��utextr�r�z&missing whitespace before encoded wordFr����r�r')rvr�r�r�r�r�r�r^r!rrpr�r�r�r��rfc2047_matcher�search�	partitionr�r�r1)rrwrM�valid_ew�have_wsr?r�r�s        r�get_unstructuredr�Qs���.)�*�L�
���8�s�?�"�5�>�L�E�5�����&�������D�!�
�/��w�?���u����|�$�q�(�#�B�'�2�2�e�;�$�,�,�3�3�F�4N�4N�D�5F�G�"'���s�<�0�1�4�#�B�'�2�2�n�D�+?�(��,�e�,5��R�(��#�#�E�*��'��q�1���i���.�.�s�3�#�o�o�d�3�O�C�)��c�7�+��������E�"����	�"��Q�R���A#�
!� ���*�*�
��
�s�
E+�+F
�8F
�F
c�X�t|d�\}}}t|d�}t|�||fS)actext = <printable ascii except \ ( )>

    This is not the RFC ctext, since we are handling nested comments in comment
    and unquoting quoted-pairs here.  We allow anything except the '()'
    characters, but if we find any ASCII other than the RFC defined printable
    ASCII, a NonPrintableDefect is added to the token's defects list.  Since
    quoted pairs are converted to their unquoted values, what is returned is
    a 'ptext' token.  In this case it is a WhiteSpaceTerminal, so it's value
    is ' '.

    z()rE)r�r�r��rrE�_s   r�get_qp_ctextr��s4��-�U�D�9�O�E�5�!��u�g�.�E��E���%�<�rc�X�t|d�\}}}t|d�}t|�||fS)aoqcontent = qtext / quoted-pair

    We allow anything except the DQUOTE character, but if we find any ASCII
    other than the RFC defined printable ASCII, a NonPrintableDefect is
    added to the token's defects list.  Any quoted pairs are converted to their
    unquoted values, so what is returned is a 'ptext' token.  In this case it
    is a ValueTerminal.

    rrE)r�r�r�r�s   r�get_qcontentr��s4��-�U�C�8�O�E�5�!��%��)�E��E���%�<�rc���t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)z�atext = <matches _atext_matcher>

    We allow any non-ATOM_ENDS in atext, but add an InvalidATextDefect to
    the token's defects list if we find non-atext characters.
    zexpected atext but found '{}'N�atext)�_non_atom_end_matcherrr�r7r�r�r�r�)r�mr�s   r�	get_atextr��sk��	�e�$�A���%�%�+�2�2�5�9�;�	;�
�G�G�I�E��#�e�*�+��E��%��)�E��E���%�<�rc�N�|r|ddk7r$tjdj|���t�}|dd}|r'|ddk(rt	|�\}}|j|�|r�|ddk7r�|dtvrt|�\}}n�|dddk(r�d}	t|�\}}|jjtjd	��d
}|rSt|�dkDrE|djdk(r3|d
jdk(r!t|dd�|d<nt	|�\}}|j|�|r	|ddk7r��|s2|jjtjd��||fS||ddfS#tj$rt	|�\}}Y��wxYw)z�bare-quoted-string = DQUOTE *([FWS] qcontent) [FWS] DQUOTE

    A quoted-string without the leading or trailing white space.  Its
    value is the text between the quote marks, with whitespace
    preserved and quoted pairs decoded.
    rrzexpected '"' but found '{}'r�Nr�r�Fz!encoded word inside quoted stringTr�r�r�r�z"end of header inside quoted string)rr�r7r�r�r�r�r�r�r!rpr�r^r�)r�bare_quoted_stringrMr�s    r�get_bare_quoted_stringr��s����E�!�H��O��%�%�*�1�1�%�8�:�	:�)�+���!�"�I�E���q��S��#�E�*���u��!�!�%�(�
�E�!�H��O���8�s�?�"�5�>�L�E�5�
�2�A�Y�$�
��H�
3�/��6���u�"�*�*�1�1�&�2L�2L�7�39�:���
�C� 2�3�a�7�&�r�*�5�5��>�*�2�.�9�9�^�K�-A�*�2�.��.7�&�r�*�(��.�L�E�5��!�!�%�(�+�E�!�H��O�,��"�"�)�)�&�*D�*D�0�+2�	3�!�5�(�(��u�Q�R�y�(�(��!�*�*�
3�+�E�2���u�
3�s�>F�!F$�#F$c��|r,|ddk7r$tjdj|���t�}|dd}|rc|ddk7r[|dtvrt|�\}}n%|ddk(rt
|�\}}nt|�\}}|j|�|r	|ddk7r�[|s2|jjtjd��||fS||ddfS)z�comment = "(" *([FWS] ccontent) [FWS] ")"
       ccontent = ctext / quoted-pair / comment

    We handle nested comments here, and quoted-pair in our qp-ctext routine.
    rrzexpected '(' but found '{}'r�Nr�zend of header inside comment)rr�r7r�r�r��get_commentr�r�r!rp)rrqrMs   rr�r��s���
��q��S���%�%�)�0�0��7�9�	9��i�G��!�"�I�E�
�E�!�H��O���8�s�?�"�5�>�L�E�5�
�1�X��_�&�u�-�L�E�5�'��.�L�E�5����u���E�!�H��O�������v�9�9�*� ,�	-���~���E�!�"�I��rc���t�}|rR|dtvrG|dtvrt|�\}}nt	|�\}}|j|�|r|dtvr�G||fS)z,CFWS = (1*([FWS] comment) [FWS]) / FWS

    r)r��CFWS_LEADERr�r�r�r�)rr�rMs   r�get_cfwsrsg���:�D�
�E�!�H��+���8�s�?�"�5�>�L�E�5�&�u�-�L�E�5����E���E�!�H��+���;�rc��t�}|r*|dtvrt|�\}}|j|�t	|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS)z�quoted-string = [CFWS] <bare-quoted-string> [CFWS]

    'bare-quoted-string' is an intermediate class defined by this
    parser and not by the RFC grammar.  It is the quoted string
    without any attached CFWS.
    r)r�rrr�r�)r�
quoted_stringrMs   r�get_quoted_stringrs���!�N�M���q��[�(������u����U�#�)�%�0�L�E�5��������q��[�(������u����U�#��%��rc��t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���|jd�r	t|�\}}nt|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS#t
j$rt|�\}}Y�dwxYw)zPatom = [CFWS] 1*atext [CFWS]

    An atom could be an rfc2047 encoded word.
    rzexpected atom but found '{}'r�)r�rrr��	ATOM_ENDSrr�r7r�r�r�)rr�rMs   r�get_atomr's���
�6�D���q��[�(������u����E����q��Y�&��%�%�*�1�1�%�8�:�	:������	,�+�E�2�L�E�5�!��'���u��K�K�����q��[�(������u����E����;����&�&�	,�%�U�+�L�E�5�	,�s�:C�!C<�;C<c��t�}|r|dtvr$tjdj	|���|r\|dtvrQt|�\}}|j
|�|r"|ddk(r|j
t�|dd}|r|dtvr�Q|dtur'tjdj	d|z���||fS)z( dot-text = 1*atext *("." 1*atext)

    rz8expected atom at a start of dot-atom-text but found '{}'r	r�Nr�z4expected atom at end of dot-atom-text but found '{}')rrrr�r7r�r�r<)r�
dot_atom_textrMs   r�get_dot_atom_textrBs��� �M�M��E�!�H�	�)��%�%�'+�+1�6�%�=�:�	:�
�E�!�H�I�-� ��'���u����U�#��U�1�X��_�� � ��%��!�"�I�E��E�!�H�I�-��R��C���%�%�'�#�V�C��I�.�0�	0��%��rc��t�}|dtvrt|�\}}|j|�|j	d�r	t|�\}}nt|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS#tj$rt|�\}}Y�dwxYw)z� dot-atom = [CFWS] dot-atom-text [CFWS]

    Any place we can have a dot atom, we could instead have an rfc2047 encoded
    word.
    rr�)	rrrr�r�r�rr�r)r�dot_atomrMs   r�get_dot_atomrUs����y�H��Q�x�;�������u�����������	4�+�E�2�L�E�5�)��/���u��O�O�E����q��[�(������u�������U�?����&�&�	4�-�U�3�L�E�5�	4�s�B%�%!C	�C	c�(�|dtvrt|�\}}nd}|stjd��|ddk(rt	|�\}}n=|dt
vr$tjdj
|���t|�\}}|�|g|dd||fS)a�word = atom / quoted-string

    Either atom or quoted-string may start with CFWS.  We have to peel off this
    CFWS first to determine which type of word to parse.  Afterward we splice
    the leading CFWS, if any, into the parsed sub-token.

    If neither an atom or a quoted-string is found before the next special, a
    HeaderParseError is raised.

    The token returned is either an Atom or a QuotedString, as appropriate.
    This means the 'word' level of the formal grammar is not represented in the
    parse tree; this is because having that extra layer when manipulating the
    parse tree is more confusing than it is helpful.

    rNz5Expected 'atom' or 'quoted-string' but found nothing.rz1Expected 'atom' or 'quoted-string' but found '{}')rrrr�r�SPECIALSr7r)r�leaderrMs   r�get_wordrns��� 
�Q�x�;�� ���
�������%�%�C�E�	E��Q�x��}�(��/���u�	�q��X�	��%�%�'7�7=�v�e�}�F�	F� �����u�
���H��b�q�	��%�<�rc���t�}	t|�\}}|j|�|r�|dtvr|ddk(rI|jt�|j
jtjd��|dd}n 	t|�\}}|j|�|r|dtvr�||fS#tj$r1|j
jtjd��Y��wxYw#tj$rL|dtvr=t|�\}}|j
jtjd��n�Y��wxYw)a� phrase = 1*word / obs-phrase
        obs-phrase = word *(word / "." / CFWS)

    This means a phrase can be a sequence of words, periods, and CFWS in any
    order as long as it starts with at least one word.  If anything other than
    words is detected, an ObsoleteHeaderDefect is added to the token's defect
    list.  We also accept a phrase that starts with CFWS followed by a dot;
    this is registered as an InvalidHeaderDefect, since it is not supported by
    even the obsolete grammar.

    zphrase does not start with wordrr	zperiod in 'phrase'r�Nzcomment found without atom)rzrr�rr�r!rp�PHRASE_ENDSr<�ObsoleteHeaderDefectrr)rr{rMs   r�
get_phraser�sM���X�F�0������u��
�
�e���E�!�H�K�/���8�S�=��M�M�#���N�N�!�!�&�"=�"=�$�#&�
'��!�"�I�E�
�'�����u�
�M�M�%� �!�E�!�H�K�/�"�5�=���)�"�"�0������f�8�8�-�/�	0�0���*�*�
���8�{�*�#+�E�?�L�E�5��N�N�)�)�&�*E�*E�4�+6�7��7�
�s%�B;�
D�;AC?�>C?�AE!� E!c��t�}d}|r|dtvrt|�\}}|s$tjdj|���	t
|�\}}|�|g|dd|j|�|r�|ddk(s|dtvr�tt|�|z�\}}|jdk(r/|jjtjd��n.|jjtj d��||d<	|j"j%d�||fS#tj$rK	t|�\}}n7#tj$r!|ddk7r|dtvr�t�}YnwxYwY��6wxYw#t&$r4|jjtj(d	��Y||fSwxYw)
z= local-part = dot-atom / quoted-string / obs-local-part

    Nrz"expected local-part but found '{}'r�invalid-obs-local-partz<local-part is not dot-atom, quoted-string, or obs-local-partz,local-part is not a dot-atom (contains CFWS)�asciiz)local-part contains non-ASCII characters))r8rrrr�r7rrrrr��get_obs_local_partrr^r!rprr�encoderv�NonASCIILocalPartDefect)rr�rrM�obs_local_parts     r�get_local_partr�s�����J�
�F���q��[�(� ���
�����%�%�0�7�7��>�@�	@� �#�E�*���u����H��b�q�	����e���%��(�D�.�E�!�H�K�$?� 2�3�z�?�U�3J� K�����$�$�(@�@����%�%�f�&@�&@�N�'P�
Q�
���%�%�f�&A�&A�>�'@�
A�&�
�1�
�>�������(��u����1�"�"� �	 �#�E�?�L�E�5���&�&�	 ��Q�x�4��E�!�H��$;���K�E�	 �� ��*�>����!�!�&�"@�"@�;�#=�	>��u���>�sH�D6�F�6F�
E�F�1F
�
F�F
�
F�F�7G�Gc�N�t�}d}|�rB|ddk(s|dtv�r.|ddk(rM|r.|jjt	j
d��|jt�d}|dd}�l|ddk(rT|jt|dd	��|dd}|jjt	j
d
��d}��|r@|djdk7r.|jjt	j
d
��	t|�\}}d}|j|�|r|ddk(r��!|dtvr��.|s$t	jdj|���|djdk(s2|djdk(rNt|�dkDr@|djdk(r.|jjt	j
d��|djdk(s2|djdk(rNt|�dkDr@|djdk(r.|jjt	j
d��|jrd|_||fS#tj$r|dtvr�t|�\}}Y��{wxYw)z' obs-local-part = word *("." word)
    Frrr	zinvalid repeated '.'Tr�N�misplaced-specialz/'\' character outside of quoted-string/ccontentr�r;zmissing '.' between wordsz&expected obs-local-part but found '{}'r�z!Invalid leading '.' in local partr�z"Invalid trailing '.' in local partr)r.rr!r�rrpr<r�r^rr�rrr7r�)rr�last_non_ws_was_dotrMs    rrr�s���"�^�N���
�U�1�X�t�^�u�Q�x�{�'B���8�s�?�"��&�&�-�-�f�.H�.H�*�/,�-��!�!�#�&�"&���!�"�I�E��
�1�X�t�^��!�!�-��a��0C�#E�
F��!�"�I�E��"�"�)�)�&�*D�*D�B�+D�
E�"'����n�R�0�;�;�u�D��"�"�)�)�&�*D�*D�+�+-�
.�	+�#�E�?�L�E�5�"'��
	���e�$�7�U�1�X�t�^�u�Q�x�{�'B�8��%�%�4�;�;�E�B�D�	D��q��$�$��-��1��(�(�&�0����!�#��1��(�(�%�/����%�%�f�&@�&@�/�'1�	2��r��%�%��.��2��)�)�6�1����!�#��2��)�)�5�0����%�%�f�&@�&@�0�'2�	3����$<��!��5� � ��-�&�&�	+��Q�x�{�*��#�E�?�L�E�5�	+�s�I3�3-J$�#J$c��t|d�\}}}t|d�}|r.|jjt	j
d��t
|�||fS)a dtext = <printable ascii except \ [ ]> / obs-dtext
        obs-dtext = obs-NO-WS-CTL / quoted-pair

    We allow anything except the excluded characters, but if we find any
    ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is
    added to the token's defects list.  Quoted pairs are converted to their
    unquoted values, so what is returned is a ptext token, in this case a
    ValueTerminal.  If there were quoted-printables, an ObsoleteHeaderDefect is
    added to the returned token's defect list.

    z[]rEz(quoted printable found in domain-literal)r�r�r!r�rrr�)rrEr�s   r�	get_dtextr#sZ��2�%��>��E�5�&��%��)�E�
�
�
�
���V�8�8�6�8�	9��E���%�<�rc��|ry|jtjd��|jtdd��y)NFz"end of input inside domain-literal�]�domain-literal-endT)r�rrpr�)r�domain_literals  r�_check_for_early_dl_endr(%s?�������&�4�4�,�.�/����-��-A�B�C�rc�n�t�}|dtvrt|�\}}|j|�|st	j
d��|ddk7r$t	j
dj
|���|dd}t||�r||fS|jtdd��|dtvrt|�\}}|j|�t|�\}}|j|�t||�r||fS|dtvrt|�\}}|j|�t||�r||fS|ddk7r$t	j
d	j
|���|jtdd
��|dd}|r*|dtvrt|�\}}|j|�||fS)zB domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]

    rzexpected domain-literal�[z6expected '[' at start of domain-literal but found '{}'r�Nzdomain-literal-startr%z4expected ']' at end of domain-literal but found '{}'r&)rBrrr�rr�r7r(r�r�r�r#)rr'rMs   r�get_domain_literalr+-s���#�_�N��Q�x�;�������u����e�$���%�%�&?�@�@��Q�x�3���%�%�'!�!'����0�	0��!�"�I�E��u�n�5��u�$�$����-��-C�D�E��Q�x�3���u�~���u����e�$��U�#�L�E�5����%� ��u�n�5��u�$�$��Q�x�3���u�~���u����e�$��u�n�5��u�$�$��Q�x�3���%�%�'!�!'����0�	0����-��-A�B�C��!�"�I�E���q��[�(������u����e�$��5� � rc�"�t�}d}|r|dtvrt|�\}}|s$tjdj|���|ddk(r+t
|�\}}|�|g|dd|j|�||fS	t|�\}}|r|ddk(rtjd��|�|g|dd|j|�|r�|ddk(r�|jjtjd��|djd	k(r|d|dd|rJ|ddk(rB|jt�t|d
d�\}}|j|�|r	|ddk(r�B||fS#tj$rt|�\}}Y��wxYw)z] domain = dot-atom / domain-literal / obs-domain
        obs-domain = atom *("." atom))

    Nrzexpected domain but found '{}'r*r(zInvalid Domainr	z(domain is not a dot-atom (contains CFWS)rr�)rrrrr�r7r+r�rrr!rr^r<)rr�rrMs    r�
get_domainr-Ts���
�X�F�
�F���q��[�(� ���
�����%�%�,�3�3�E�:�<�	<��Q�x�3��)�%�0���u�����E�"�1�I��
�
�e���u�}��'�#�E�*���u�
��q��S���%�%�&6�7�7�
���H��b�q�	�
�M�M�%����q��S�������f�9�9�6�8�	9��!�9���:�-��q�	�F�1�I���a��C���M�M�#��#�E�!�"�I�.�L�E�5��M�M�%� ���a��C���5�=���!�"�"�'������u�'�s�E*�*!F�
Fc�N�t�}t|�\}}|j|�|r|ddk7r2|jjt	j
d��||fS|jt
dd��t|dd�\}}|j|�||fS)z( addr-spec = local-part "@" domain

    rr(z#addr-spec local part with no domain�address-at-symbolr�N)r rr�r!rrpr�r-)rr�rMs   r�
get_addr_specr0zs����
�I�!�%�(�L�E�5�
���U���E�!�H��O���� � ��!;�!;�1�"3�	4��%���
���]�3�(;�<�=��e�A�B�i�(�L�E�5�
���U���e��rc���t�}|rw|ddk(s|dtvrd|dtvr t|�\}}|j|�n"|ddk(r|jt�|dd}|r|ddk(r�X|dtvr�d|r|ddk7r$tjdj|���|jt�t|dd�\}}|j|�|r�|ddk(r�|jt�|dd}|snw|dtvrt|�\}}|j|�|snJ|ddk(r7|jt�t|dd�\}}|j|�|r	|ddk(r��|stjd��|ddk7r$tjd	j|���|jtdd
��||ddfS)z� obs-route = obs-domain-list ":"
        obs-domain-list = *(CFWS / ",") "@" domain *("," [CFWS] ["@" domain])

        Returns an obs-route token with the appropriate sub-tokens (that is,
        there is no obs-domain-list in the parse tree).
    rr�r�Nr(z(expected obs-route domain but found '{}'z%end of header while parsing obs-route�:z4expected ':' marking end of obs-route but found '{}'zend-of-obs-route-marker)rrrr��
ListSeparatorrr�r7�RouteComponentMarkerr-r�)r�	obs_routerMs   r�
get_obs_router6�s����
�I�
�U�1�X�s�]�e�A�h�+�&=���8�{�"�#�E�?�L�E�5����U�#�
�1�X��_����]�+��!�"�I�E�
�U�1�X�s�]�e�A�h�+�&=��E�!�H��O��%�%�6�=�=�e�D�F�	F�
���)�*��e�A�B�i�(�L�E�5�
���U��
�E�!�H�c�M�����'��a�b�	������8�{�"�#�E�?�L�E�5����U�#�����8�s�?����1�2�%�e�A�B�i�0�L�E�5����U�#��E�!�H�c�M���%�%�&M�N�N��Q�x�3���%�%�('�'-�v�e�}�6�	6�
���]�3�(A�B�C��e�A�B�i��rc�x�t�}|r*|dtvrt|�\}}|j|�|r|ddk7r$t	j
dj
|���|jtdd��|dd}|rZ|ddk(rR|jtdd��|jjt	jd	��|dd}||fS	t|�\}}|j|�|r|ddk(r|dd}n.|jjt	jd��|jtdd��|r*|dtvrt|�\}}|j|�||fS#tj
$r�	t|�\}}|jjt	jd
��n;#tj
$r%t	j
dj
|���wxYw|j|�t|�\}}Y��HwxYw)
z� angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
        obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS]

    r�<z"expected angle-addr but found '{}'zangle-addr-startr�N�>zangle-addr-endznull addr-spec in angle-addrz*obsolete route specification in angle-addrz.expected addr-spec or obs-route but found '{}'z"missing trailing '>' on angle-addr)
r�rrr�rr�r7r�r!rpr0r6r)r�
angle_addrrMs   r�get_angle_addrr;�s4��
��J���q��[�(������u����%� ��E�!�H��O��%�%�0�7�7��>�@�	@����m�C�);�<�=��!�"�I�E�
��q��S�����-��-=�>�?����!�!�&�"<�"<�*�#,�	-��a�b�	���5� � �,�$�U�+���u����e����q��S���a�b�	�����!�!�&�"<�"<�0�#2�	3����m�C�)9�:�;���q��[�(������u����%� ��u����)�"�"�	,�	P�(��/�L�E�5����%�%�f�&A�&A�<�'>�
?���&�&�	P��)�)�@�G�G��N�P�
P�	P��	���%� �$�U�+���u�	,�s*�"F
�
H9�<G�H9�8H�"H9�8H9c��t�}t|�\}}|j|dd�|jdd|_||fS)z� display-name = phrase

    Because this is simply a name-rule, we don't return a display-name
    token containing a phrase, but rather a display-name token with
    the content of the phrase.

    N)r0rrKr!)rr�rMs   r�get_display_namer=�sG���=�L��e�$�L�E�5�����a��!� �=�=��+�L�����rc��t�}d}|s$tjdj|���|dtvr4t|�\}}|s$tjdj|���|ddk7r�|dtvr$tjdj|���t|�\}}|s$tjdj|���|�%t|dt�r
|g|dddn|g|ddd}|j|�t|�\}}|�|g|dd|j|�||fS)z, name-addr = [display-name] angle-addr

    Nz!expected name-addr but found '{}'rr8)r�rr�r7rrrr=r3rr�r;)r�	name_addrrrMs    r�
get_name_addrr@�s`���
�I�
�F���%�%�/�6�6�u�=�?�	?��Q�x�;�� ���
�����)�)�3�:�:�6�B�D�
D��Q�x�3����8�{�"��)�)�3�:�:�5�A�C�
C�'��.���u���)�)�3�:�:�5�A�C�
C����%��(�I�.� &�x��a���!��#�H��b�q�	��F������!�%�(�L�E�5�
���H��b�q�	�
���U���e��rc�l�t�}	t|�\}}t
d�|jD��rd|_|j|�||fS#tj$rN	t	|�\}}n;#tj$r%tjdj|���wxYwY��wxYw)z& mailbox = name-addr / addr-spec

    zexpected mailbox but found '{}'c3�PK�|]}t|tj���� y�wr)r3rrpr*s  rr-zget_mailbox.<locals>.<genexpr>%s%����3� 1�1��a��3�3�4� 1���$&r�)
rr@rr�r0r7�anyr?r^r�)rr�rMs   r�get_mailboxrEs����i�G�A�$�U�+���u��3� %� 1� 1�3�3�.����N�N�5���E�>����"�"�A�	A�(��/�L�E�5���&�&�	A��)�)�1�8�8��?�A�
A�	A���A�s)�A�B3�&A5�4B3�58B-�-B3�2B3c���t�}|r_|d|vrX|dtvr$|jt|dd��|dd}nt	|�\}}|j|�|r|d|vr�X||fS)z� Read everything up to one of the chars in endchars.

    This is outside the formal grammar.  The InvalidMailbox TokenList that is
    returned acts like a Mailbox, but the data attributes are None.

    rr r�N)r
rr�r�r)rr��invalid_mailboxrMs    r�get_invalid_mailboxrH+s���%�&�O�
�E�!�H�H�,���8�{�"��"�"�=��q��1D�$F�
G��!�"�I�E�%�e�,�L�E�5��"�"�5�)��E�!�H�H�,��E�!�!rc�\�t�}|r�|ddk7r�	t|�\}}|j|�|ra|ddvrZ|d}d	|_t|d�\}}|j|�|jjtjd��|r"|ddk(r|jt�|d
d}|r	|ddk7r��||fS#tj$�rLd}|dt
vr�t
|�\}}|r|ddvr@|j|�|jjtjd��n�t|d�\}}|�|g|dd|j|�|jjtjd��n�|ddk(r/|jjtjd��nVt|d�\}}|�|g|dd|j|�|jjtjd��Y���wxYw)aJ mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list
        obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS])

    For this routine we go outside the formal grammar in order to improve error
    handling.  We recognize the end of the mailbox list only at the end of the
    value or at a ';' (the group terminator).  This is so that we can turn
    invalid mailboxes into InvalidMailbox tokens and continue parsing any
    remaining valid mailboxes.  We also allow all mailbox entries to be null,
    and this condition is handled appropriately at a higher level.

    r�;Nz,;zempty element in mailbox-listzinvalid mailbox in mailbox-listr�r�r�r�)r�rEr�rr�rrr!rrHrpr^rKr3)r�mailbox_listrMrr�s     r�get_mailbox_listrL=s5���=�L�
�E�!�H��O�	8�&�u�-�L�E�5�����&�4�U�1�X�T�)�#�2�&�G�!2�G��.�u�d�;�L�E�5��N�N�5�!�� � �'�'��(B�(B�1�)3�
4��U�1�X��_����
�.��!�"�I�E�Q�E�!�H��O�R�����K�&�&�	8��F��Q�x�;�&� (���
�����a��D� 0� �'�'��/� �(�(�/�/��0K�0K�7�19�:�$7�u�d�#C�L�E�5��)�%+�H��b�q�	� �'�'��.� �(�(�/�/��0J�0J�9�1;�<��q��S���$�$�+�+�F�,G�,G�3�-5�6� 3�5�$�?���u��%�!'��E�"�1�I��#�#�E�*��$�$�+�+�F�,F�,F�5�-7�8��/	8�s�C�EH+�*H+c��t�}|s2|jjtjd��||fSd}|r{|dt
vrpt
|�\}}|sC|jjtjd��|j|�||fS|ddk(r|j|�||fSt|�\}}t|j�dk(rV|�|j|�|j|�|jjtjd��||fS|�|g|dd|j|�||fS)zg group-list = mailbox-list / CFWS / obs-group-list
        obs-group-list = 1*([CFWS] ",") [CFWS]

    zend of header before group-listNrzend of header in group-listrJzgroup-list with empty entries)r�r!r�rrprrrLr�r�rKr)r�
group_listrrMs    r�get_group_listrOvsa��
��J�����!�!�&�"<�"<�-�#/�	0��5� � �
�F���q��[�(� ���
����
���%�%�f�&@�&@�-�'/�
0����f�%��u�$�$���8�s�?����f�%��u�$�$�#�E�*�L�E�5�
�5�����"������f�%����%� ����!�!�&�"=�"=�+�#-�	.��5� � �
���H��b�q�	����e���u��rc���t�}t|�\}}|r|ddk7r$tjdj	|���|j|�|jt
dd��|dd}|r*|ddk(r"|jt
dd��||ddfSt|�\}}|j|�|s/|jjtjd	��n,|ddk7r$tjd
j	|���|jt
dd��|dd}|r*|dtvrt|�\}}|j|�||fS)z7 group = display-name ":" [group-list] ";" [CFWS]

    rr2z8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorr�NrJzgroup-terminatorzend of header in groupz)expected ';' at end of group but found {})r�r=rr�r7r�r�rOr!rprr)rr�rMs   r�	get_grouprQ�sa��
�G�E�#�E�*�L�E�5��E�!�H��O��%�%�'*�*0�&��-�9�	9�	�L�L���	�L�L��s�$C�D�E��!�"�I�E���q��S��
���]�3�(:�;�<��e�A�B�i���!�%�(�L�E�5�	�L�L����
�
�
���V�7�7�$�&�	'�	�q��S���%�%�7�>�>�u�E�G�	G�	�L�L��s�$6�7�8��!�"�I�E���q��[�(������u�
���U���%�<�rc�&�t�}	t|�\}}|j
|�||fS#tj$rN	t	|�\}}n;#tj$r%tjdj|���wxYwY�uwxYw)a� address = mailbox / group

    Note that counter-intuitively, an address can be either a single address or
    a list of addresses (a group).  This is why the returned Address object has
    a 'mailboxes' attribute which treats a single address as a list of length
    one.  When you need to differentiate between to two cases, extract the single
    element, which is either a mailbox or a group token.

    zexpected address but found '{}')r�rQrr�rEr7r�)rr�rMs   r�get_addressrS�s���"�i�G�A� ��'���u��N�N�5���E�>����"�"�A�	A�&�u�-�L�E�5���&�&�	A��)�)�1�8�8��?�A�
A�	A���A�s'�/�B�A�B�8B
�
B�Bc�^�t�}|r�	t|�\}}|j|�|re|ddk7r]|dd}d|_t|d�\}}|j|�|jjtjd��|r|jt�|d	d}|r��||fS#tj$�rad}|dt
vr�t
|�\}}|r|ddk(r@|j|�|jjtjd��n�t|d�\}}|�|g|dd|jt|g��|jjtjd��n�|ddk(r/|jjtjd��n`t|d�\}}|�|g|dd|jt|g��|jjtjd��Y���wxYw)
a� address_list = (address *("," address)) / obs-addr-list
        obs-addr-list = *([CFWS] ",") address *("," [address / CFWS])

    We depart from the formal grammar here by continuing to parse until the end
    of the input, assuming the input to be entirely composed of an
    address-list.  This is always true in email parsing, and allows us
    to skip invalid addresses to parse additional valid ones.

    Nrr�z"address-list entry with no contentzinvalid address in address-listzempty element in address-listr�r�r�)r�rSr�rr�rrr!rrHr�rpr^rKr3)r�address_listrMrr�s     r�get_address_listrV�s(���=�L�
�	8�&�u�-�L�E�5�����&�4�U�1�X��_�#�2�&�q�)�G�!2�G��.�u�c�:�L�E�5��N�N�5�!�� � �'�'��(B�(B�1�)3�
4�����
�.��!�"�I�E�Q�R�����K�&�&�	8��F��Q�x�;�&� (���
�����a��C�� �'�'��/� �(�(�/�/��0K�0K�<�1>�?�$7�u�c�#B�L�E�5��)�%+�H��b�q�	� �'�'����(8�9� �(�(�/�/��0J�0J�9�1;�<��q��S���$�$�+�+�F�,G�,G�3�-5�6� 3�5�#�>���u��%�!'��E�"�1�I��#�#�G�U�G�$4�5��$�$�+�+�F�,F�,F�5�-7�8��/	8�s�B7�7E1H,�+H,c���t�}|s$tjdj|���|ddk7r$tjdj|���|j	tdd��|dd}t
|�\}}|j	|�|r|ddk7r$tjd	j|���|j	tdd
��||ddfS)z& no-fold-literal = "[" *dtext "]"
    z'expected no-fold-literal but found '{}'rr*z;expected '[' at the start of no-fold-literal but found '{}'zno-fold-literal-startr�Nr%z9expected ']' at the end of no-fold-literal but found '{}'zno-fold-literal-end)rrr�r7r�r�r#)r�no_fold_literalrMs   r�get_no_fold_literalrY
s���$�o�O���%�%�5�<�<�U�C�E�	E��Q�x�3���%�%�
�#�V�E�]�,�	,����=��.E�F�G��!�"�I�E��U�#�L�E�5����5�!��E�!�H��O��%�%�
�#�V�E�]�,�	,����=��.C�D�E��E�!�"�I�%�%rc�F�t�}|r*|dtvrt|�\}}|j|�|r|ddk7r$t	j
dj
|���|jtdd��|dd}	t|�\}}|j|�|r|dd	k7r\|jjt	jd
��|r(|ddk(r |jtdd��|dd}||fS|jtd	d
��|dd}	t|�\}}|j|�|r|ddk(r|dd}n.|jjt	jd��|jtdd��|r*|dtvrt|�\}}|j|�||fS#tj
$r}	t|�\}}|jjt	jd��n;#tj
$r%t	j
dj
|���wxYwY���wxYw#tj
$r�	t|�\}}n�#tj
$r|	t|�\}}|jjt	jd��n;#tj
$r%t	j
dj
|���wxYwYnwxYwY���wxYw)z�msg-id = [CFWS] "<" id-left '@' id-right  ">" [CFWS]
       id-left = dot-atom-text / obs-id-left
       id-right = dot-atom-text / no-fold-literal / obs-id-right
       no-fold-literal = "[" *dtext "]"
    rr8zexpected msg-id but found '{}'zmsg-id-startr�Nzobsolete id-left in msg-idz4expected dot-atom-text or obs-id-left but found '{}'r(zmsg-id with no id-rightr9z
msg-id-endr/zobsolete id-right in msg-idzFexpected dot-atom-text, no-fold-literal or obs-id-right but found '{}'zmissing trailing '>' on msg-id)r�rrr�rr�r7r�rrr!rrprYr-)r�msg_idrMs   r�
get_msg_idr\#s����W�F���q��[�(������u��
�
�e���E�!�H��O��%�%�,�3�3�E�:�<�	<�
�M�M�-��^�4�5��!�"�I�E�1�(��/���u��M�M�%���E�!�H��O������f�8�8�%�'�	(�
�U�1�X��_��M�M�-��\�:�;��!�"�I�E��u�}��
�M�M�-��%8�9�:��!�"�I�E�
5�(��/���u��M�M�%����q��S���a�b�	�������f�8�8�,�.�	/�
�M�M�-��\�2�3���q��[�(������u��
�
�e���5�=���a�"�"�	1�	1�-�e�4�L�E�5��N�N�!�!�&�"=�"=�,�#.�
/���&�&�	1��)�)�"�"(�&��-�1�
1�	1��
/�		1��4�"�"�5�
	5�.�u�5�L�E�5���&�&�	5�
5�)�%�0���u����%�%�f�&A�&A�1�'3�4���*�*�
5��-�-�&�&,�f�U�m�5�5�
5��4�	5��5�sx�G�,I'�I$�(<H%�$I$�%8I�I$�#I$�'L �;J
�	L �
L�<K�L�8L�L�L �L�L �L c��t�}	t|�\}}|j|�|r=|jjt	j
dj
|���|S#tj$r^}t|�}t|�}|jjt	j
dj
|���Yd}~|Sd}~wwxYw)z2message-id      =   "Message-ID:" msg-id CRLF
    zUnexpected {!r}zInvalid msg-id: {!r}N)
r�r\r�r!rrpr7r�r�r�)r�
message_idrM�exs    r�parse_message_idr`hs�����J�2�!�%�(���u����%� �����%�%�f�&@�&@�!�(�(��/�'1�
2�����"�"�K� ��'��%�e�,�
����!�!��&�&�'=�'D�'D�R�'H�I�	K�	K����K�s�A,�,C�?AC�Cc�j�t�}|s0|jjtjd��|S|dt
vrOt
|�\}}|j|�|s.|jjtjd��d}|r6|ddk7r.|dt
vr#||dz
}|dd}|r|ddk7r|dt
vr�#|j�sY|jjtjdj|���|jt|d	��n+t|�|_|jt|d
��|r*|dt
vrt
|�\}}|j|�|r|ddk7rY|j�.|jjtjd��|r|jt|d	��|S|jtdd��|dd}|r*|dt
vrt
|�\}}|j|�|s<|j�.|jjtjd��|Sd}|r&|dt
vr||dz
}|dd}|r|dt
vr�|j�sY|jjtjd
j|���|jt|d	��n+t|�|_
|jt|d
��|r*|dt
vrt
|�\}}|j|�|rI|jjtjd��|jt|d	��|S)zE mime-version = [CFWS] 1*digit [CFWS] "." [CFWS] 1*digit [CFWS]

    z%Missing MIME version number (eg: 1.0)rz0Expected MIME version number but found only CFWSr'r	r�Nz1Expected MIME major version number but found {!r}r��digitsz0Incomplete MIME version; found only major numberzversion-separatorz1Expected MIME minor version number but found {!r}z'Excess non-CFWS text after MIME version)rHr!r�r�HeaderMissingRequiredValuerr�isdigitrpr7r��intrIrJ)r�mime_versionrMrbs    r�parse_mime_versionrg�sp���=�L�����#�#�F�$E�$E�3�%5�	6����Q�x�;�������u����E�"��� � �'�'��(I�(I�B�)D�
E�
�F�
�E�!�H��O��a���(C��%��(����a�b�	���E�!�H��O��a���(C��>�>�����#�#�F�$>�$>�?�F�F�v�N�%P�	Q����M�&�'�:�;� ��[������M�&�(�;�<���q��[�(������u����E�"��E�!�H��O����)�� � �'�'��(B�(B�B�)D�
E�����
�e�W� =�>������
�c�+>�?�@��!�"�I�E���q��[�(������u����E�"�����)�� � �'�'��(B�(B�B�)D�
E���
�F�
�E�!�H�K�/��%��(����a�b�	���E�!�H�K�/��>�>�����#�#�F�$>�$>�?�F�F�v�N�%P�	Q����M�&�'�:�;� ��[������M�&�(�;�<���q��[�(������u����E�"�����#�#�F�$>�$>�5�%7�	8����M�%��9�:��rc���t�}|ra|ddk7rY|dtvr$|jt|dd��|dd}nt	|�\}}|j|�|r	|ddk7r�Y||fS)z� Read everything up to the next ';'.

    This is outside the formal grammar.  The InvalidParameter TokenList that is
    returned acts like a Parameter, but the data attributes are None.

    rrJr r�N)rWrr�r�r)r�invalid_parameterrMs   r�get_invalid_parameterrj�s���)�*��
�E�!�H��O���8�{�"��$�$�]�5��8�3F�&H�
I��!�"�I�E�%�e�,�L�E�5��$�$�U�+��E�!�H��O��e�#�#rc���t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)a8ttext = <matches _ttext_matcher>

    We allow any non-TOKEN_ENDS in ttext, but add defects to the token's
    defects list if we find non-ttext characters.  We also register defects for
    *any* non-printables even though the RFC doesn't exclude all of them,
    because we follow the spirit of RFC 5322.

    zexpected ttext but found '{}'N�ttext)�_non_token_end_matcherrr�r7r�r�r�r�)rr�rls   r�	get_ttextrn�sk��	�u�%�A���%�%�+�2�2�5�9�;�	;�
�G�G�I�E��#�e�*�+��E��%��)�E��E���%�<�rc�n�t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���t|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS)z�token = [CFWS] 1*ttext [CFWS]

    The RFC equivalent of ttext is any US-ASCII chars except space, ctls, or
    tspecials.  We also exclude tabs even though the RFC doesn't.

    The RFC implies the CFWS but is not explicit about it in the BNF.

    r�expected token but found '{}')	r�rrr��
TOKEN_ENDSrr�r7rn)r�mtokenrMs   r�	get_tokenrs�s����W�F���q��[�(������u��
�
�e����q��Z�'��%�%�+�2�2�5�9�;�	;��U�#�L�E�5�
�M�M�%����q��[�(������u��
�
�e���5�=�rc���t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)aQattrtext = 1*(any non-ATTRIBUTE_ENDS character)

    We allow any non-ATTRIBUTE_ENDS in attrtext, but add defects to the
    token's defects list if we find non-attrtext characters.  We also register
    defects for *any* non-printables even though the RFC doesn't exclude all of
    them, because we follow the spirit of RFC 5322.

    z expected attrtext but found {!r}Nr])�_non_attribute_end_matcherrr�r7r�r�r�r��rr�r]s   r�get_attrtextrw	sk��	#�5�)�A���%�%�.�5�5�e�<�>�	>��w�w�y�H��#�h�-�.�!�E��X�z�2�H��H���U�?�rc�n�t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���t|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS)aH [CFWS] 1*attrtext [CFWS]

    This version of the BNF makes the CFWS explicit, and as usual we use a
    value terminal for the actual run of characters.  The RFC equivalent of
    attrtext is the token characters, with the subtraction of '*', "'", and '%'.
    We include tab in the excluded set just as we do for token.

    rrp)	rZrrr��ATTRIBUTE_ENDSrr�r7rw�rr[rMs   r�
get_attributer{	s�����I���q��[�(������u��������q��^�+��%�%�+�2�2�5�9�;�	;���&�L�E�5�
���U����q��[�(������u�������e��rc���t|�}|s$tjdj|���|j	�}|t|�d}t
|d�}t|�||fS)z�attrtext = 1*(any non-ATTRIBUTE_ENDS character plus '%')

    This is a special parsing routine so that we get a value that
    includes % escapes as a single string (which we decode as a single
    string later).

    z)expected extended attrtext but found {!r}N�extended-attrtext)�#_non_extended_attribute_end_matcherrr�r7r�r�r�r�rvs   r�get_extended_attrtextr.	sn��	,�E�2�A���%�%�7�>�>�u�E�G�	G��w�w�y�H��#�h�-�.�!�E��X�':�;�H��H���U�?�rc�n�t�}|r*|dtvrt|�\}}|j|�|r/|dtvr$tjdj|���t|�\}}|j|�|r*|dtvrt|�\}}|j|�||fS)z� [CFWS] 1*extended_attrtext [CFWS]

    This is like the non-extended version except we allow % characters, so that
    we can pick up an encoded value as a single string.

    rrp)	rZrrr��EXTENDED_ATTRIBUTE_ENDSrr�r7rrzs   r�get_extended_attributer�@	s�����I���q��[�(������u��������q��4�4��%�%�+�2�2�5�9�;�	;�(��/�L�E�5�
���U����q��[�(������u�������e��rc�l�t�}|r|ddk7r$tjdj|���|j	tdd��|dd}|r|dj
�s$tjdj|���d}|r6|dj
�r#||dz
}|dd}|r|dj
�r�#|dd	k(r3|d	k7r.|jj	tjd
��t|�|_
|j	t|d��||fS)a6 '*' digits

    The formal BNF is more complicated because leading 0s are not allowed.  We
    check for that and add a defect.  We also assume no CFWS is allowed between
    the '*' and the digits, though the RFC is not crystal clear on that.
    The caller should already have dealt with leading CFWS.

    r�*zExpected section but found {}zsection-markerr�Nz$Expected section number but found {}r'�0z'section number has an invalid leading 0rb)rarr�r7r�r�rdr!rprerQ)rrbrbs   r�get_sectionr�V	s2���i�G��E�!�H��O��%�%�&E�&L�&L�(-�'/�0�	0��N�N�=��&6�7�8��!�"�I�E���a��(�(�*��%�%�'1�17����@�	@�
�F�
�E�!�H�$�$�&��%��(����a�b�	���E�!�H�$�$�&��a�y�C��F�c�M������v�9�9�9� ;�	<���[�G�N��N�N�=���2�3��E�>�rc�J�t�}|stjd��d}|dtvrt	|�\}}|s$tjdj|���|ddk(rt
|�\}}nt|�\}}|�|g|dd|j|�||fS)z  quoted-string / attribute

    z&Expected value but found end of stringNrz Expected value but found only {}r)	rdrr�rrr7rr�r�)r�vrrMs    r�	get_valuer�t	s���	��A���%�%�&N�O�O�
�F��Q�x�;�� ���
�����%�%�'0�06��v��@�	@��Q�x�3��(��/���u�-�e�4���u�
���H��b�q�	��H�H�U�O��e�8�Orc�
�t�}t|�\}}|j|�|r|ddk(rA|jjt	j
dj
|���||fS|ddk(rm	t|�\}}d|_|j|�|st	jd��|ddk(r'|jtdd��|dd	}d|_|dd
k7rt	jd��|jtd
d��|dd	}|r*|dtvrt|�\}}|j|�d	}|}|j�r|�r|dd
k(r�t|�\}}|j}d}|j dk(r(|r|ddk(rd}n/t#|�\}}|r|ddk(rd}n	t%|�\}}|sd}	|ra|jjt	j
d��|j|�|D]}	|	j&dk(s�g|	d	d	|	}n|}n0d	}|jjt	j
d��|r|ddk(rd	}nt)|�\}}|jr|j dkDrQ|r|ddk7r|j|�|�|}||fS|jjt	j
d��|sF|jjt	j
d��|j|�|��#||fS|�I|D]}	|	j&dk(s�n	j&dk(|j|	�|	j*|_|ddk7r$t	jdj
|���|jtdd��|dd	}|rf|ddk7r^t#|�\}}|j|�|j*|_|r|ddk7r$t	jdj
|���|jtdd��|dd	}|�et1�}
|rV|dt2vrt5|�\}}n(|dd
k(rtd
d�}|dd	}nt7|�\}}|
j|�|r�V|
}nt)|�\}}|j|�|�|}||fS#tj$rY��WwxYw#Y��.xYw)aY attribute [section] ["*"] [CFWS] "=" value

    The CFWS is implied by the RFC but not made explicit in the BNF.  This
    simplified form of the BNF from the RFC is made to conform with the RFC BNF
    through some extra checks.  We do it this way because it makes both error
    recovery and working with the resulting parse tree easier.
    rrJz)Parameter contains name ({}) but no valuer�TzIncomplete parameterzextended-parameter-markerr�N�=zParameter not followed by '='�parameter-separatorrF�'z5Quoted string value for extended parameter is invalidr�zZParameter marked as extended but appears to have a quoted string value that is non-encodedzcApparent initial-extended-value but attribute was not marked as extended or was not initial sectionz(Missing required charset/lang delimitersr}r]z=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {}�DQUOTE)rLr{r�r!rrpr7r�rPr�r�rUrrrr�rRrwrr^r�rr�r�rdr�r�r�)rr�rMr��appendto�qstring�inner_value�
semi_validr��tr�s           r�
get_parameterr��	s��
�K�E� ��'�L�E�5�	�L�L����E�!�H��O�
�
�
���V�7�7�9%�%+�V�E�]�4�	5��e�|���Q�x�3��	�&�u�-�L�E�5�"�E�O��L�L�����)�)�*@�A�A���8�s�?��L�L��s�,G�H�I��!�"�I�E�!�E�N��Q�x�3���%�%�&E�F�F�	�L�L��s�$9�:�;��!�"�I�E���q��[�(������u�
���U���I��H��~�~�%�E�!�H��O�/�u�5�����,�,���
����1�$��{�1�~��4�!�
�*�;�7���t��D��G�s�N�!%�J�
&�3�K�@���t��!%�J���M�M� � ��!;�!;�G�"I�
J��L�L��!����<�<�#7�7��A�a�D� �H��	�
 �E��I��M�M� � ��!;�!;�:�";�
<�
��q��S���� ��'���u��>�>�U�1�1�A�5���a��C���O�O�E�"��$�!���%�<��
�
�
���V�7�7�
D�E�	F��
�
�
���V�7�7�6�8�	9���������%�<�������<�<�#6�6���
�L�L�J�&��O�O�A���G�G�E�M���8�s�?��)�)�+F�FL�f�U�m�U�
U����
�c�+>�?�@��a�b�	���U�1�X��_�'��.�L�E�5��O�O�E�"����E�J��E�!�H��O��-�-�/<�<B�F�5�M�K�K����
�c�+>�?�@��a�b�	�����G����Q�x�3��&�u�~���u��q��S��%�c�8�4���a�b�	��+�E�2���u�
�H�H�U�O���� ��'���u��O�O�E�������%�<���i�&�&�	��	��D
��s�>&S%�S?�%S<�;S<�?Tc��t�}|r�	t|�\}}|j|�|rp|ddk7rh|d}d|_t|�\}}|j|�|jjtjdj|���|r |jtdd	��|d
d}|r��|S#tj$r�d}|dt
vrt
|�\}}|s|j|�|cYS|ddk(rB|�|j|�|jjtjd��ndt|�\}}|r|g|dd|j|�|jjtjdj|���Y���wxYw)a! parameter *( ";" parameter )

    That BNF is meant to indicate this routine should only be called after
    finding and handling the leading ';'.  There is no corresponding rule in
    the formal RFC grammar, but it is more convenient for us for the set of
    parameters to be treated as its own TokenList.

    This is 'parse' routine because it consumes the remaining value, but it
    would never be called to parse a full header.  Instead it is called to
    parse everything after the non-parameter value of a specific MIME header.

    NrrJzparameter entry with no contentzinvalid parameter {!r}r�rXz)parameter with invalid trailing text {!r}r�r�)rgr�r�rr�rrr!rprjr7r^rKr�)r�mime_parametersrMrr�s     r�parse_mime_parametersr�
s���%�&�O�
�	=�(��/�L�E�5��"�"�5�)�(�U�1�X��_�$�B�'�E�2�E��0��7�L�E�5��L�L����#�#�*�*�6�+E�+E�;�B�B�5�I�,K�
L���"�"�=��6K�#L�M��!�"�I�E�G�H���A�&�&�	=��F��Q�x�;�&� (���
�����&�&�v�.�&�&��Q�x�3���%�#�*�*�6�2��'�'�.�.�v�/I�/I�5�07�8� 5�U�;���u��!'��E�"�1�I��&�&�u�-��'�'�.�.�v�/I�/I�,�3�3�E�:�0<�=��#	=�s�C�AF=�B.F=�<F=c�@�|ra|ddk7rY|dtvr$|jt|dd��|dd}nt|�\}}|j|�|r	|ddk7r�Y|sy|jtdd��|jt	|dd��y)zBDo our best to find the parameters in an invalid MIME header

    rrJr r�Nr�)rr�r�rr�)�	tokenlistrrMs   r�_find_mime_parametersr�K
s����E�!�H��O���8�{�"����]�5��8�5H�I�J��!�"�I�E�%�e�,�L�E�5����U�#�
�E�!�H��O���
���]�3�(=�>�?�
���*�5���9�5�6rc�8�t�}|s0|jjtjd��|S	t|�\}}|j|�|r|ddk7r>|jjtjd��|rt||�|S|jj�j�|_
|jtdd��|dd}	t|�\}}|j|�|jj�j�|_|s|S|dd
k7rO|jjtjdj|���|`
|`t||�|S|jtd
d��|jt!|dd��|S#tj$rN|jjtjdj|���t||�|cYSwxYw#tj$rN|jjtjd	j|���t||�|cYSwxYw)
z� maintype "/" subtype *( ";" parameter )

    The maintype and substype are tokens.  Theoretically they could
    be checked against the official IANA list + x-token, but we
    don't do that.
    z"Missing content type specificationz(Expected content maintype but found {!r}rr�zInvalid content typezcontent-type-separatorr�Nz'Expected content subtype but found {!r}rJz<Only parameters are valid after content type, but found {!r}r�)r�r!r�rrcrsr�rpr7r�rrm�lowerr�r�r�r�)r�ctyperMs   r�parse_content_type_headerr�[
sH��
�M�E��
�
�
���V�>�>�0�2�	3���� ��'���u�
�L�L����E�!�H��O�
�
�
���V�7�7�"�$�	%��!�%��/����[�[�&�&�(�.�.�0�E�N�	�L�L��s�$<�=�>��!�"�I�E�� ��'���u�
�L�L����K�K�%�%�'�-�-�/�E�M�����Q�x�3��
�
�
���V�7�7�
�����(�	)�
�N�E�M��e�U�+���	�L�L��s�$9�:�;�	�L�L�&�u�Q�R�y�1�2��L��Q�"�"��
�
�
���V�7�7�6�=�=�e�D�F�	G��e�U�+���	��&�"�"��
�
�
���V�7�7�5�<�<�U�C�E�	F��e�U�+���	�s%�G�3H8�AH5�4H5�8AJ�Jc��t�}|s0|jjtjd��|S	t|�\}}|j|�|jj�j�|_
|s|S|ddk7rK|jjtjdj|���t||�|S|jtdd��|jt|dd��|S#tj$rN|jjtjdj|���t||�|cYSwxYw)	z* disposition-type *( ";" parameter )

    zMissing content dispositionz+Expected content disposition but found {!r}rrJzCOnly parameters are valid after content disposition, but found {!r}r�r�N)r�r!r�rrcrsr�rpr7r�rrmr�r�r�r�)r�disp_headerrMs   r� parse_content_disposition_headerr��
s]��%�&�K�����"�"�6�#D�#D�)�$+�	,���� ��'���u����u��&+�k�k�&7�&7�&9�&?�&?�&A�K�#�����Q�x�3�����"�"�6�#=�#=�
�����$(�	)�	�k�5�1������}�S�*?�@�A����,�U�1�2�Y�7�8����#�"�"�����"�"�6�#=�#=�9�@�@��G�$I�	J��k�5�1���	�s�D�AE<�;E<c���t�}|s0|jjtjd��|S	t|�\}}|j|�|jj�j�|_	|s|S|r|jjtjd��|dtvr$|jt|dd��|dd}nt|�\}}|j|�|r�|S#tj$r@|jjtjdj|���Y��wxYw)z mechanism

    z!Missing content transfer encodingz1Expected content transfer encoding but found {!r}z*Extra text after content transfer encodingrr r�N)r�r!r�rrcrsrrmr�r�r�rpr7rr�r)r�
cte_headerrMs   r�&parse_content_transfer_encoding_headerr��
sM��
)�*�J�����!�!�&�"C�"C�/�#1�	2���5� ��'���u�
	���%� ����*�*�,�2�2�4�
�����
����!�!�&�"<�"<�8�#:�	;���8�{�"����m�E�!�H�6I�J�K��!�"�I�E�%�e�,�L�E�5����e�$�����#�"�"�P����!�!�&�"<�"<�?�F�F�u�M�#O�	P�P�s�D�AE$�#E$c�Z�d}|r&|dr!|ddtvr|dd}|ddd|d<|S)Nr'r�)r�)�lines�wsps  r�_steal_trailing_WSP_if_existsr��
sD��
�C���r��u�R�y��}��3��B�i��m���"�I�c�r�N��b�	��Jrc	��|jxstj}|jrdnd}dg}d}d}d}d}d}	t	dd�}
t|�}|�rL|j
d�}||
ur|dz}�t|�}
|	s;|jd	vrtj|
�}	ntj|
�}		|
j|�|}|jd
k(rt!||||���|	�r|�s|j"s�d}	d}|j$r|j'|��dt)|j*�}|j*|vrHt)|�|t)|d�z
kDrt-|�}|j/|�|dxx|z
cc<��9t1|d�st|�|z}d}	��W|j"r;|�||k7r|dk(s
|dk(r|dk7rd}t3|
||||j4||�}d}|}d}	���d}d}	t)|
�|t)|d�z
kr|dxx|
z
cc<���d}|j$r~t)|
�dz|krmt-|�}|s|j7�rP|j/||
z�g}|dD]}|t8vrn|j/|��dj;|�}d}��Zt1|d�s�t|�}|jdk(r?t=dd�g|D�cgc]}t=t?|�d���c}zt=dd�gz}|j"s|dz
}|j/|
�||z}���|j"r|s|jAd|�d}	��t-|�}|s|j7�r|j/||
z�n
|dxx|
z
cc<|r��L|j*j;|�|j*zS#t$r'td
�|jD��rd}nd}d}	Y��,wxYwcc}w)zLReturn string of contents of parse_tree folded according to RFC rules.

    �utf-8rNr'NrF�wrap_as_ew_blockedr�)rEr�c3�PK�|]}t|tj���� y�wr)r3rrxr*s  rr-z%_refold_parse_tree.<locals>.<genexpr>
s%����.�,�q��a��!>�!>�?�,�rC�unknown-8bitTrhrOr�rr�rrE)!�max_line_length�sys�maxsize�utf8r�r�r2rr^�
SPECIALSNL�
isdisjoint�NLSETrrvrDr?�_fold_mime_parametersrGrdrSr�r�r�r�r_�_fold_as_ewrerDr�r1r�r�insert)�
parse_treerP�maxlenrlr��leading_whitespace�last_ew�last_charsetr��
want_encoding�end_ew_not_allowedr|rH�tstrr��encoded_part�newline�whitespace_accumulator�char�newparts�ps                     rrQrQ�
sS��
�
#�
#�
2�s�{�{�F� �+�+�w�:�H�
�D�E����G��L����M�!�"�&:�;�����E�
��y�y��|���%�%��!�#����4�y������"4�4�$.�$9�$9�$�$?� ?�
�%*�$4�$4�T�$:� :�
�	!��K�K��!��G��?�?�/�/�!�$��v�x�@���!3��%�%� %�
����'�'�#'�9�9�F�9�#;�<Q�c�&�.�.�>Q�=Q�#R�L��~�~�\�9��|�,�v��E�"�I��/F�F�&C�E�&J�G�!�L�L��1��b�	�\�1�	� �
�4��*��T�
�U�*�� %�
���#�#��'��|�+�!�^�3�!�W�,��J�1F�"�G�%�d�E�6�7�&*�&=�&=�w�HZ�\��&(�"�&�� %�
���� %�
��t�9���U�2�Y��/�/��"�I���I��
 ��� � ��D�	�A�
��'�3�E�:�G��$�-�-�/�
���W�t�^�,�)+�&�!�"�I�D��3���*�1�1�$�7�&�&(�W�W�-C�%D�"�����t�X�&��D�z�H����"6�6�
#�3��0�1�&�(�&��#�#4�Q�#7��A�&�(�(�#�3��0�1�2��
�%�%�"�a�'�"���� 2�3��u�$�E�����&8�
�L�L��D�!� �M��/��6���d�)�)�+��L�L��4��(�
�"�I���I�K�N�>�>���u�%����6�6��o"�	!��.� �,�,�.�.�(��"�� �M�	!��B(s�:O
�#O=�
,O:�9O:c��|�+|r)tt|d|d|z��}|dd||d<nM|dtvrB|d}|dd}t|d�|k(r|j	t|��|dxx|z
cc<d}|dtvr
|d}|dd}|�t|d�n|}	|dk(rdn|}
t|
�dz}|dz|k\rt
jd	��|�r!|t|d�z
}||z
t|�z
}
|
dkr|j	d
��<t|�dkDr9t|d�dk(r(|r&tj||
��}|dxx|z
cc<d}|d|
}tj||
��}t|�|z
}|dkDr0|dd}tj||
��}t|�|z
}|dkDr�0|dxx|z
cc<|t|�d}d}|r|j	d
�t|d�}	|r��!|dxx|z
cc<|r|	SdS)a�Fold string to_encode into lines as encoded word, combining if allowed.
    Return the new value for last_ew, or None if ew_combine_allowed is False.

    If there is already an encoded word in the last line of lines (indicated by
    a non-None value for last_ew) and ew_combine_allowed is true, decode the
    existing ew, combine it with to_encode, and re-encode.  Otherwise, encode
    to_encode.  In either case, split to_encode as necessary so that the
    encoded segments fit within maxlen.

    Nr�rr�r'rNr��z3max_line_length is too small to fit an encoded wordrm)r�)
rr�r�r�r�r�rr�r�r)�	to_encoder�r�r�rer�r��leading_wsp�trailing_wsp�new_last_ew�	encode_as�
chrome_len�remaining_space�
text_space�encoded_word�to_encode_word�excesss                 rr�r��sd����1���U�2�Y�w�x�0�9�<�=�?�	��"�I�h�w�'��b�	�	�1���	� ��l���a�b�M�	���b�	�N�f�$��L�L�6�u�=�>�
�b�	�[� �	��L���}��� ��}���c�r�N�	�$+�O�#�e�B�i�.��K�"�j�0��g�I��Y��!�#�J��Q��6�!��%�%�A�C�	C�� �3�u�R�y�>�1��$�z�1�C�8J�4K�K�
���?��L�L�����u�:��>�c�%��)�n��1�6H��:�:�&8�)�L�L��"�I��%�I�!#��"�;�J�/���z�z�.�)�D���\�"�_�4���q�j�,�C�R�0�N��:�:�n�i�H�L���&��8�F��q�j�	�b�	�\�!�	��c�.�1�2�3�	�����L�L����e�B�i�.�K�?�@
�"�I���I�,�;�6�$�6rc	��|jD�]�\}}|dj�jd�s
|dxxdz
cc<|}d}	|j|�d}|r6tjj|d	|�
�}	dj|||	�}
ndj|t|��}
t|d�t|
�zd
z|kr|ddz|
z|d<��t|
�dz|kr|jd|
z���d}|dz}|s��t|�tt|��zdzt|�z}
||
dzkrd}||
z
dz
x}}	|d|}tjj|d	|�
�}	t|	�|krn|d
z}�<|jdj||||	��d	}|d
z
}||d}|r
|dxxdz
cc<|r�����y#t$r"d}tj|�rd}d}nd}Y���wxYw)a>Fold TokenList 'part' into the 'lines' list as mime parameters.

    Using the decoded list of parameters and values, format them according to
    the RFC rules, including using RFC2231 encoding if the value cannot be
    expressed in 'encoding' and/or the parameter+value is too long to fit
    within 'maxlen'.

    r�rJ�strictFTr�rkr�r')�saferz
{}*={}''{}r�r�rmr�rz''r#�NNz {}*{}*={}{})rzr%r^rrvrrwrqrrr�r7rr�r�r)rHr�r�rlr{rr��
error_handler�encoding_required�
encoded_valuer�rb�extra_chromer��
splitpoint�maxchars�partials                 rr�r��sA���{�{���e��R�y���!�*�*�3�/��"�I���I��� �
�		"��L�L��"� %���"�L�L�.�.��B�}�/�6�M��&�&�t�W�m�D�D��>�>�$��U�(;�<�D��u�R�y�>�C��I�%��)�F�2��b�	�C��$�.�E�"�I��
��Y��]�f�
$��L�L��t��$������~����T��S��W��%6�6��:�S��=N�N�J���a��'�
��$*�Z�$7�!�$;�;�J������,�� &��� 2� 2��"�]�!3�!<�
��}�%��1���a��
�
�
�L�L��.�.��g�|�]�<�
=��L��q�L�G��*�+�&�E���b�	�S� �	�-�I#��"�	"� $���$�$�U�+�(�� 1�
�!���
	"�s�G�'G>�=G>)r�)�r��rer�rq�stringr�operatorr�emailrr�rrr)r�rrrr*r�	TSPECIALSrq�	ASPECIALSryr�r�r�rr�compile�VERBOSE�	MULTILINEr�r�rrjrvrzr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr
rrrrr r.r0r8rBrHrLrWrZrardrgr�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r<r3rGrdr4r7r1rr�r��matchr��findallr�rmrur~r�r�r�r�r�r�r�r�r�r�rrrrrrrrrr#r(r+r-r0r6r;r=r@rErHrLrOrQrSrVrYr\r`rgrjrnrsrwr{rr�r�r�r�r�r�r�r�r�r�rQr�r�rnrr�<module>r�s5��C�J
�
�
���'���
�%�j���C��H�n���� ���s�N�	��C��H�$�
���U��#��
��E�
�
"�c�#�h�.�	�
��_�
���E�
�"�	��S���(�3�s�8�3��	
�t���
��
�
�@�
��"�*�*���Z�Z�"�,�,�� ��@,��@,�FD�)�D� �I� ��Y���9���"���9���I��
�)��#�9�#�6	-�|�	-��!��4C�)�C�&%�i�%�2?�)�?�%�	�%�"$�I�$�*"�y�"�6�	��DD�y�D�!�i�!�6;�Y�;�.�Y�.��i���)��
�I��
�y��B�9��-!�&�-!�`!�	�!�H
�I�
� �)���	��8%�y�%�
#�	�#��i���I��S.�Y�S.�l�y���*���1���i���)��
*�I�*����&�y�&��Y��(+�s�(+�V����H���-��<�f�-�-�<��C�����c�#3�4�
�#�
�� %�
��$�S�*B�C��.��
�
�:�,�,�R�W�W�S�\�:�;�A�A�
�"��
�
�9�#3�#3�
�B�I�I�b�g�g�i� �!�$#�$�$)�E��"��
�
�#5�6�>�>��#����I�$4�$4�
�B�I�I�b�g�g�j�!�"�%$�%�%*�U��'�R�Z�Z�	�(8�(8�
�B�I�I�b�g�g�n�%�&�)(�)�).���&0�b�j�j��1A�1A�
�B�I�I�b�g�g�-�.�/�21�'2�27�%�$�;�J�<
�/�bA�F�"
�� ))�V�2� �$�6 �&�2 �D$�L%�N2!�h�(�%!�N$�L� ) �V,�\�"�H�*"�$6�r#�J�<�:4�n&�,B�J�8B�H$�$�&�.�&�.�$�,�<�,K�Z2�h7� 6�p�<�^�Y7�vJ7�XI!r__pycache__/_parseaddr.cpython-312.opt-2.pyc000064400000047670151706203560014546 0ustar00�

T��h�E���	gd�ZddlZddlZdZdZdZgd�Zgd�Zdddddd	d
ddd
ddd
dd�Zd�Z	d�Z
d�Zd�Zd�Z
Gd�d�ZGd�de�Zy))�	mktime_tz�	parsedate�parsedate_tz�quote�N� �z, )�jan�feb�mar�apr�may�jun�jul�aug�sep�oct�nov�dec�january�february�march�aprilr
�june�july�august�	september�october�november�december)�mon�tue�wed�thu�fri�sat�sunip���i���i���i����iD���i��)�UT�UTC�GMT�Z�AST�ADT�EST�EDT�CST�CDT�MST�MDT�PST�PDTc�J�	t|�}|sy|d�d|d<t|�S)N�	r)�
_parsedate_tz�tuple)�data�ress  �)/usr/lib64/python3.12/email/_parseaddr.pyrr-s5�����
�C���
�1�v�~���A����:��c
��	|sy|j�}|sy|djd�s|dj�tvr|d=n'|dj	d�}|dk\r|d|dzd|d<t|�dk(r*|djd�}t|�dk(r||ddz}t|�dk(rP|d}|j
d�}|dk(r|j
d�}|dkDr|d|||dg|ddn|jd	�t|�d
kry|dd
}|\}}}}}|r|r|sy|j�}|tvr||j�}}|tvrytj|�dz}|dkDr|dz}|ddk(r|dd}|j
d�}|dkDr||}}|ddk(r|dd}|sy|dj�s||}}|ddk(r|dd}|jd�}t|�d
k(r|\}	}
d}nkt|�dk(r|\}	}
}nVt|�dk(rGd|dvr@|djd�}t|�d
k(r|\}	}
d}nt|�dk(r|\}	}
}nyy	t|�}t|�}t|	�}	t|
�}
t|�}|dkr|dkDr|dz
}n|dz
}d}|j�}|tvr
t|}n$	t|�}|dk(r|jd�rd}|r!|dkrd}
|}nd}
|
|dzdz|dzdzzz}||||	|
|ddd|g
S#t$rYywxYw#t$rY�awxYw)Nr�,���-��+���r���:��0�.�d�Dili�i�<)�split�endswith�lower�	_daynames�rfind�len�find�append�_monthnames�index�isdigit�int�
ValueError�upper�
_timezones�
startswith)r9�i�stuff�s�dd�mm�yy�tm�tz�thh�tmm�tss�tzoffset�tzsigns              r;r7r79s�������:�:�<�D����A�w������Q��
�
��9� <���G���G�M�M�#�����6��1�g�a��c�d�m�D��G�
�4�y�A�~��Q��
�
�c�"���u�:��?��4���8�#�D�
�4�y�A�~���G��
�F�F�3�K����7����s��A��q�5��"�1��q���u�~�D���H��K�K��O�
�4�y�1�}�����8�D���R��R��R��2�"��	����B�	����R�X�X�Z�B��
�[� ��	�	�	�2�	��	"�B�	�B�w�
�b���	�"�v��}�
���W��
�����A��1�u��R�B��	�"�v��}�
���W����
�a�5�=�=�?��R�B��	�"�v��}�
���W��	���#��B�
�2�w�!�|��
��c���	�R��A�����c�3�	�R��A��#��A��,�
��U�[�[��
���r�7�a�<��J�S�#��C�
��W��\� �O�S�#�s����
��W��
��W���#�h���#�h���#�h��
�C�x�
��7��$�J�B�
�$�J�B��H�	����B�	�Z���b�>��	��2�w�H��Q�;�2�=�=��-��H���a�<��F� �y�H��F��x��}�d�2�h��n�b�5H�H�I����B��S�#�q�!�R��:�:��E�����*�	��	�s$�,7L/�L>�/	L;�:L;�>	M
�	M
c�H�	t|�}t|t�r|ddS|S)Nr6)r�
isinstancer8�r9�ts  r;rr�s)��0��T��A��!�U����!�u���r<c�~�	|d�tj|dddz�Stj|�}||dz
S)Nr6�)rD)�time�mktime�calendar�timegmrms  r;rr�sD��O��A�w���{�{�4���8�e�+�,�,��O�O�D�!���4��7�{�r<c�H�	|jdd�jdd�S)N�\z\\�"z\")�replace)�strs r;rr�s'����;�;�t�V�$�,�,�S�%�8�8r<c�`�eZdZ	d�Zd�Zd�Zd�Zd�Zd�Zd�Z	dd�Z
d	�Zd
�Zd�Z
dd
�Zd�Zy)�
AddrlistClassc�.�	d|_d|_d|_d|_|j|jz|_|j|jz|jz|_|j
j
dd�|_||_g|_	y)Nz()<>@,:;."[]rz 	z
rJr)
�specials�pos�LWS�CR�FWS�atomendsrx�
phraseends�field�commentlist��selfr�s  r;�__init__zAddrlistClass.__init__�s��	�
(��
�����������8�8�d�g�g�%����
�
����0�4�7�7�:��
��-�-�/�/��R�8�����
���r<c�L�	g}|jt|j�kr�|j|j|jdzvrY|j|jdvr(|j	|j|j�|xjdz
c_nG|j|jdk(r*|j
j	|j
��nn#|jt|j�kr��tj|�S)Nz

r?�()	r~rSr�rrUr��
getcomment�EMPTYSTRING�join)r��wslists  r;�gotonextzAddrlistClass.gotonext�s���4����h�h��T�Z�Z��(��z�z�$�(�(�#�t�x�x�&�'8�8��:�:�d�h�h�'�v�5��M�M�$�*�*�T�X�X�"6�7����A�
�����D�H�H�%��,�� � �'�'����(9�:���h�h��T�Z�Z��(�����'�'r<c���	g}|jt|j�krL|j�}|r||z
}n|j	d�|jt|j�kr�L|S)N)rr)r~rSr��
getaddressrU)r��result�ads   r;�getaddrlistzAddrlistClass.getaddrlist�sc��	����h�h��T�Z�Z��(����"�B���"����
�
�h�'��h�h��T�Z�Z��(��
r<c��	g|_|j�|j}|j}|j�}|j�g}|jt	|j
�k\r*|�rftj|j�|dfg}�n?|j
|jdvrB||_||_|j�}tj|j�|fg}�n�|j
|jdk(r�g}t	|j
�}|xjdz
c_|jt	|j
�k�rw|j�|j|kr3|j
|jdk(r|xjdz
c_�n%||j�z}|jt	|j
�kr��n�|j
|jdk(rp|j�}|jr;tj|�dzdj|j�zd	z|fg}n{tj|�|fg}nb|r&tj|j�|dfg}n:|j
|j|jvr|xjdz
c_|j�|jt	|j
�kr1|j
|jd
k(r|xjdz
c_|S)Nrz.@rGr?�;�<z (r�)r>)r�r�r~�
getphraselistrSr��SPACEr��getaddrspecr��getrouteaddrr})r��oldpos�oldcl�plist�
returnlist�addrspec�fieldlen�	routeaddrs        r;r�zAddrlistClass.getaddresss���%�����
�
������� � ���"�"�$���
�
���
��8�8�s�4�:�:��&��$�z�z�$�*:�*:�;�U�1�X�F�G�
�
�Z�Z����
!�T�
)��D�H�$�D���'�'�)�H� �:�:�d�&6�&6�7��B�C�J�
�Z�Z����
!�S�
(��J��4�:�:��H��H�H��M�H��(�(�S����_�,��
�
���8�8�h�&�4�:�:�d�h�h�+?�3�+F��H�H��M�H��'�$�/�/�*;�;�
��(�(�S����_�,��Z�Z����
!�S�
(��)�)�+�I����$�z�z�%�0�4�7�"�x�x��(8�(8�9� :�<?� @�AJ�L�M�
� %�z�z�%�0�)�<�=�
��$�z�z�$�*:�*:�;�U�1�X�F�G�
����D�H�H�%����6����A�
���
�
���8�8�c�$�*�*�o�%�$�*�*�T�X�X�*>�#�*E��H�H��M�H��r<c���	|j|jdk7ryd}|xjdz
c_|j�d}|jt|j�k�r|r|j	�d}n�|j|jdk(r|xjdz
c_	|S|j|jdk(r|xjdz
c_d}nZ|j|jdk(r|xjdz
c_n(|j�}|xjdz
c_	|S|j�|jt|j�kr��|S)	Nr�Fr?r�>�@TrG)r�r~r�rS�	getdomainr�)r��expectroute�adlists   r;r�zAddrlistClass.getrouteaddrGs+��	��:�:�d�h�h��3�&�������A�
���
�
�����h�h��T�Z�Z��(����� �#�����D�H�H�%��,����A�
����
����D�H�H�%��,����A�
��"�����D�H�H�%��,����A�
���)�)�+�����A�
����
�
�M�M�O�!�h�h��T�Z�Z��(�$�
r<c��	g}|j�|jt|j�k�rgd}|j|jdk(rN|r#|dj	�s|j�|j
d�|xjdz
c_d}n�|j|jdk(r,|j
dt|j��z�nj|j|j|jvr&|r#|dj	�s|j�nh|j
|j��|j�}|r|r|j
|�|jt|j�kr��g|jt|j�k\s|j|jdk7rtj|�S|j
d�|xjdz
c_|j�|j�}|stStj|�|zS)	NTrJrDr?Frwz"%s"r�)r�r~rSr��strip�poprUr�getquoter��getatomr�r�r�)r��aslist�preserve_ws�ws�domains     r;r�zAddrlistClass.getaddrspecgs���*����
�
���h�h��T�Z�Z��(��K��z�z�$�(�(�#�s�*��&��*�"2�"2�"4��J�J�L��
�
�c�"����A�
��#�����D�H�H�%��,��
�
�f�u�T�]�]�_�'=�=�>����D�H�H�%����6��&��*�"2�"2�"4��J�J�L���
�
�d�l�l�n�-�����B��r��
�
�b�!�%�h�h��T�Z�Z��(�(�8�8�s�4�:�:��&�$�*�*�T�X�X�*>�#�*E��#�#�F�+�+��
�
�c�����A�
���
�
�����!���������'�&�0�0r<c��	g}|jt|j�k�r�|j|j|jvr|xjdz
c_�n,|j|jdk(r*|jj|j
��n�|j|jdk(r |j|j��n�|j|jdk(r'|xjdz
c_|jd�ng|j|jdk(rtS|j|j|jvrnC|j|j��|jt|j�kr���tj|�S)Nr?r��[rJr�)r~rSr�rr�rUr��getdomainliteralr�r�r�r�)r��sdlists  r;r�zAddrlistClass.getdomain�s@��;����h�h��T�Z�Z��(��z�z�$�(�(�#�t�x�x�/����A�
�����D�H�H�%��,�� � �'�'����(9�:����D�H�H�%��,��
�
�d�3�3�5�6����D�H�H�%��,����A�
���
�
�c�"����D�H�H�%��,�#�"����D�H�H�%����6���
�
�d�l�l�n�-�#�h�h��T�Z�Z��(�$����'�'r<c��	|j|j|k7rydg}d}|xjdz
c_|jt|j�k�r|r+|j|j|j�d}n�|j|j|vr|xjdz
c_n�|r<|j|jdk(r |j|j	����|j|jdk(rd}n(|j|j|j�|xjdz
c_|jt|j�kr��t
j
|�S)NrFr?r�rvT)r�r~rSrUr�r�r�)r��	beginchar�endchars�
allowcomments�slistrs      r;�getdelimitedzAddrlistClass.getdelimited�s*��	��:�:�d�h�h��9�,����������A�
���h�h��T�Z�Z��(�����T�Z�Z����1�2������D�H�H�%��1����A�
����4�:�:�d�h�h�#7�3�#>����T�_�_�.�/�����D�H�H�%��-������T�Z�Z����1�2��H�H��M�H��h�h��T�Z�Z��(� ����&�&r<c�*�	|jddd�S)Nrwz"
F�r��r�s r;r�zAddrlistClass.getquote�s��?�� � ��e�U�3�3r<c�*�	|jddd�S)Nr�z)
Tr�r�s r;r�zAddrlistClass.getcomment�s��E�� � ��e�T�2�2r<c�0�	d|jddd�zS)Nz[%s]r�z]
Fr�r�s r;r�zAddrlistClass.getdomainliteral�s��/���)�)�#�u�e�<�<�<r<Nc��	dg}|�|j}|jt|j�kr||j|j|vrn`|j	|j|j�|xjdz
c_|jt|j�kr�|t
j
|�S)Nrr?)r�r~rSr�rUr�r�)r�r��atomlists   r;r�zAddrlistClass.getatom�s���	!��4�����}�}�H��h�h��T�Z�Z��(��z�z�$�(�(�#�x�/������
�
�4�8�8� 4�5��H�H��M�H��h�h��T�Z�Z��(�����)�)r<c��	g}|jt|j�k�r3|j|j|jvr|xjdz
c_n�|j|jdk(r |j	|j��n�|j|jdk(r*|jj	|j��nR|j|j|jvr	|S|j	|j|j��|jt|j�kr��3|S)Nr?rwr�)
r~rSr�r�rUr�r�r�r�r�)r�r�s  r;r�zAddrlistClass.getphraselist�s���	����h�h��T�Z�Z��(��z�z�$�(�(�#�t�x�x�/����A�
�����D�H�H�%��,����T�]�]�_�-����D�H�H�%��,�� � �'�'����(9�:����D�H�H�%����8�������T�\�\�$�/�/�:�;��h�h��T�Z�Z��(��r<)T�N)�__name__�
__module__�__qualname__r�r�r�r�r�r�r�r�r�r�r�r�r��r<r;r{r{�sL����&(��9�v�@$1�L(�.#'�J4�3�=�*�(r<r{c�8�eZdZ	d�Zd�Zd�Zd�Zd�Zd�Zd�Z	y)	�AddressListc�n�tj||�|r|j�|_yg|_yr�)r{r�r��addresslistr�s  r;r�zAddressList.__init__s.�����t�U�+��#�/�/�1�D��!�D�r<c�,�t|j�Sr�)rSr�r�s r;�__len__zAddressList.__len__	s���4�#�#�$�$r<c��td�}|jdd|_|jD],}||jvs�|jj|��.|Sr��r�r�rU�r��other�newaddr�xs    r;�__add__zAddressList.__add__sX���d�#��"�.�.�q�1����"�"�A���(�(�(��#�#�*�*�1�-�#��r<c�|�|jD],}||jvs�|jj|��.|Sr�)r�rU�r�r�r�s   r;�__iadd__zAddressList.__iadd__s;���"�"�A���(�(�(�� � �'�'��*�#��r<c��td�}|jD],}||jvs�|jj|��.|Sr�r�r�s    r;�__sub__zAddressList.__sub__sE���d�#���!�!�A���)�)�)��#�#�*�*�1�-�"��r<c�|�|jD],}||jvs�|jj|��.|Sr�)r��remover�s   r;�__isub__zAddressList.__isub__$s;���"�"�A��D�$�$�$�� � �'�'��*�#��r<c� �|j|Sr�)r�)r�rWs  r;�__getitem__zAddressList.__getitem__+s������&�&r<N)
r�r�r�r�r�r�r�r�r�r�r�r<r;r�r�s(��J�"�%�����'r<r�)�__all__rqrsr�r��
COMMASPACErVrQr\rr7rrrr{r�r�r<r;�<module>r�s����
�������
�
�I��

>�	��A�Q�A��$��$��$��$��$��
�
�z;�z��9�k�k�Z	-'�-�-'r<__pycache__/_policybase.cpython-312.opt-2.pyc000064400000022452151706203560014722 0ustar00�

T��h�<���	ddlZddlmZddlmZddlmZgd�ZGd�d�Zd�Z	d	�Z
Gd
�deej��Ze
Gd
�de��Z
e
�Zy)�N)�header)�charset)�_has_surrogates)�Policy�Compat32�compat32c�8��eZdZ	�fd�Zd�Zd�Zd�Zd�Z�xZS)�_PolicyBasec����	|j�D]T\}}t||�rtt|�||��'tdj
||jj���y�Nz*{!r} is an invalid keyword argument for {})	�items�hasattr�superr
�__setattr__�	TypeError�format�	__class__�__name__)�self�kw�name�valuers    ��*/usr/lib64/python3.12/email/_policybase.py�__init__z_PolicyBase.__init__)sc���	�
�8�8�:�K�D�%��t�T�"��k�$�3�D�%�@��@�G�G��d�n�n�5�5�7�8�8�	&�c���|jj�D��cgc]\}}dj||���}}}dj|jjdj|��Scc}}w)Nz{}={!r}z{}({})z, )�__dict__r
rrr�join)rrr�argss    r�__repr__z_PolicyBase.__repr__7sh��$(�M�M�$7�$7�$9�<�$9�[�T�5��!�!�$��.�$9�	
�<����t�~�~�6�6��	�	�$��H�H��<s�A2c��	|jj|j�}|jj�D]\}}tj|||��|j�D]W\}}t
||�s/tdj||jj���tj|||��Y|Sr)
r�__new__rr
�objectrrrrr)rr�	newpolicy�attrrs     r�clonez_PolicyBase.clone<s���	��N�N�*�*�4�>�>�:�	��=�=�.�.�0�K�D�%����y�$��6�1��8�8�:�K�D�%��4��&��@�G�G��d�n�n�5�5�7�8�8�
���y�$��6�&��rc��t||�rd}nd}t|j|jj|���)Nz'{!r} object attribute {!r} is read-onlyz!{!r} object has no attribute {!r})r�AttributeErrorrrr)rrr�msgs    rrz_PolicyBase.__setattr__Ns6���4���;�C�5�C��S�Z�Z����(?�(?��F�G�Grc�<�	|jdi|j��S)N�)r&r)r�others  r�__add__z_PolicyBase.__add__Us!��	�
�t�z�z�+�E�N�N�+�+r)	r�
__module__�__qualname__rr r&rr-�
__classcell__)rs@rr
r
s#����*8�I�
�$H�,rr
c�f�|jdd�d}|jdd�d}|dz|zS)N�
�r)�rsplit�split)�doc�	added_docs  r�_append_docr8^s;��

�*�*�T�1�
�a�
 �C�����a�(��+�I���:�	�!�!rc���|jrM|jjd�r2t|jdj|j�|_|jj�D]{\}}|js�|jjd�s�/d�|jD�D]7}t
t
||�d�}|s�t||j�|_�{�}|S)N�+rc3�JK�|]}|j�D]}|����y�w�N)�mro)�.0�base�cs   r�	<genexpr>z%_extend_docstrings.<locals>.<genexpr>hs����F�M�D�4�8�8�:�a�a�:�a�M�s�!#�__doc__)rB�
startswithr8�	__bases__rr
�getattr)�clsrr%r@r6s     r�_extend_docstringsrGcs���
�{�{�s�{�{�-�-�c�2�!�#�-�-��"2�":�":�C�K�K�H����l�l�(�(�*�
��d��<�<�D�L�L�3�3�C�8�F�C�M�M�F���g�a��.�	�:���#.�s�D�L�L�#A�D�L��	G�+��Jrc���eZdZ	dZdZdZdZdZdZdZ	d�Z
d�Zd	�Ze
jd
��Ze
jd��Ze
jd��Ze
jd
��Ze
jd��Zy)rFr2�8bit�NNTc�F�	|jr|�|j||�yr<)�raise_on_defect�register_defect�r�obj�defects   r�
handle_defectzPolicy.handle_defect�s'��
	�����L����S�&�)rc�<�	|jj|�yr<)�defects�appendrNs   rrMzPolicy.register_defect�s��		�	�����6�"rc��	yr<r+)rrs  r�header_max_countzPolicy.header_max_count�s��	� rc��	t�r<��NotImplementedError)r�sourceliness  r�header_source_parsezPolicy.header_source_parse����	�"�!rc��	t�r<rX�rrrs   r�header_store_parsezPolicy.header_store_parse�s��	�"�!rc��	t�r<rXr^s   r�header_fetch_parsezPolicy.header_fetch_parse�s��	�"�!rc��	t�r<rXr^s   r�foldzPolicy.folds��	�"�!rc��	t�r<rXr^s   r�fold_binaryzPolicy.fold_binaryr\r)rr.r/rL�linesep�cte_type�max_line_length�mangle_from_�message_factory�verify_generated_headersrQrMrV�abc�abstractmethodr[r_rarcrer+rrrrps���5�n�O��G��H��O��L��O�#��*�&#��&	���"��"�	���"��"�	���"��"�	���	"��	"�	���"��"rr)�	metaclassc�<�eZdZ	dZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
rTc��t|t�s|St|�r&tj|t
j|��S|S)N�r�header_name)�
isinstance�strrr�Header�_charset�UNKNOWN8BITr^s   r�_sanitize_headerzCompat32._sanitize_header!s@���%��%��L��5�!��=�=���0D�0D�-1�3�
3��Lrc��	|djdd�\}}dj|g|dd���jd�}||jd�fS)Nr�:r3�z 	
z
)r5r�lstrip�rstrip)rrZrrs    rr[zCompat32.header_source_parse-s^��	�"�!�n�*�*�3��2���e�����1��Q�R��1�2�9�9�)�D���e�l�l�6�*�+�+rc��	||fSr<r+r^s   rr_zCompat32.header_store_parse9s��	��e�}�rc�(�	|j||�Sr<)rxr^s   rrazCompat32.header_fetch_parse?s��	��$�$�T�5�1�1rc�,�	|j||d��S)NT��sanitize)�_foldr^s   rrcz
Compat32.foldFs��	��z�z�$���z�5�5rc�j�	|j|||jdk(��}|jdd�S)N�7bitr��ascii�surrogateescape)r�rg�encode)rrr�foldeds    rrezCompat32.fold_binaryPs8��	����D�%�$�-�-��2G��H���}�}�W�&7�8�8rc��g}|jd|z�t|t�r`t|�r=|r't	j
|tj|��}n.|j|�d}nt	j
||��}n|}|�Fd}|j�|j}|j|j|j|���|j|j�dj|�S)Nz%s: rq)rrr)rf�
maxlinelenr{)rTrsrtrrrurvrwrhr�rfr)rrrr��parts�hr�s       rr�zCompat32._fold\s�����
���V�d�]�#��e�S�!��u�%���
�
�e�.6�.B�.B�26�8�A��L�L��'��A��M�M�%�T�:���A��=��J��#�#�/�!�1�1�
��L�L����$�,�,�:��N�O�
���T�\�\�"��w�w�u�~�rN)rr.r/rirxr[r_rarcrer�r+rrrrs1���
�L�
�
,��2�6�
9�rr)rl�emailrrrv�email.utilsr�__all__r
r8rG�ABCMetarrrr+rr�<module>r�ss���
��%�'���I,�I,�X"�

�d"�[�C�K�K�d"�N�c�v�c��c�L�:�r__pycache__/_policybase.cpython-312.pyc000064400000044314151706203560013763 0ustar00�

T��h�<���dZddlZddlmZddlmZddlmZgd�ZGd�d�Z	d	�Z
d
�ZGd�de	ej�
�Z
eGd�de
��Ze�Zy)zwPolicy framework for the email package.

Allows fine grained feature control of how the package parses and emits data.
�N)�header)�charset)�_has_surrogates)�Policy�Compat32�compat32c�:��eZdZdZ�fd�Zd�Zd�Zd�Zd�Z�xZ	S)�_PolicyBasea�Policy Object basic framework.

    This class is useless unless subclassed.  A subclass should define
    class attributes with defaults for any values that are to be
    managed by the Policy object.  The constructor will then allow
    non-default values to be set for these attributes at instance
    creation time.  The instance will be callable, taking these same
    attributes keyword arguments, and returning a new instance
    identical to the called instance except for those values changed
    by the keyword arguments.  Instances may be added, yielding new
    instances with any non-default values from the right hand
    operand overriding those in the left hand operand.  That is,

        A + B == A(<non-default values of B>)

    The repr of an instance can be used to reconstruct the object
    if and only if the repr of the values can be used to reconstruct
    those values.

    c����|j�D]T\}}t||�rtt|�||��'tdj
||jj���y)z�Create new Policy, possibly overriding some defaults.

        See class docstring for a list of overridable attributes.

        �*{!r} is an invalid keyword argument for {}N)	�items�hasattr�superr
�__setattr__�	TypeError�format�	__class__�__name__)�self�kw�name�valuers    ��*/usr/lib64/python3.12/email/_policybase.py�__init__z_PolicyBase.__init__)s^����8�8�:�K�D�%��t�T�"��k�$�3�D�%�@��@�G�G��d�n�n�5�5�7�8�8�	&�c���|jj�D��cgc]\}}dj||���}}}dj|jjdj|��Scc}}w)Nz{}={!r}z{}({})z, )�__dict__r
rrr�join)rrr�argss    r�__repr__z_PolicyBase.__repr__7sh��$(�M�M�$7�$7�$9�<�$9�[�T�5��!�!�$��.�$9�	
�<����t�~�~�6�6��	�	�$��H�H��<s�A2c��|jj|j�}|jj�D]\}}tj|||��|j�D]W\}}t
||�s/tdj||jj���tj|||��Y|S)z�Return a new instance with specified attributes changed.

        The new instance has the same attribute values as the current object,
        except for the changes passed in as keyword arguments.

        r)
r�__new__rr
�objectrrrrr)rr�	newpolicy�attrrs     r�clonez_PolicyBase.clone<s����N�N�*�*�4�>�>�:�	��=�=�.�.�0�K�D�%����y�$��6�1��8�8�:�K�D�%��4��&��@�G�G��d�n�n�5�5�7�8�8�
���y�$��6�&��rc��t||�rd}nd}t|j|jj|���)Nz'{!r} object attribute {!r} is read-onlyz!{!r} object has no attribute {!r})r�AttributeErrorrrr)rrr�msgs    rrz_PolicyBase.__setattr__Ns6���4���;�C�5�C��S�Z�Z����(?�(?��F�G�Grc�:�|jdi|j��S)z�Non-default values from right operand override those from left.

        The object returned is a new instance of the subclass.

        �)r&r)r�others  r�__add__z_PolicyBase.__add__Us���t�z�z�+�E�N�N�+�+r)
r�
__module__�__qualname__�__doc__rr r&rr-�
__classcell__)rs@rr
r
s#����*8�I�
�$H�,rr
c�f�|jdd�d}|jdd�d}|dz|zS)N�
�r)�rsplit�split)�doc�	added_docs  r�_append_docr9^s;��

�*�*�T�1�
�a�
 �C�����a�(��+�I���:�	�!�!rc���|jrM|jjd�r2t|jdj|j�|_|jj�D]{\}}|js�|jjd�s�/d�|jD�D]7}t
t
||�d�}|s�t||j�|_�{�}|S)N�+rc3�JK�|]}|j�D]}|����y�w)N)�mro)�.0�base�cs   r�	<genexpr>z%_extend_docstrings.<locals>.<genexpr>hs����F�M�D�4�8�8�:�a�a�:�a�M�s�!#r0)r0�
startswithr9�	__bases__rr
�getattr)�clsrr%r@r7s     r�_extend_docstringsrFcs���
�{�{�s�{�{�-�-�c�2�!�#�-�-��"2�":�":�C�K�K�H����l�l�(�(�*�
��d��<�<�D�L�L�3�3�C�8�F�C�M�M�F���g�a��.�	�:���#.�s�D�L�L�#A�D�L��	G�+��Jrc���eZdZdZdZdZdZdZdZdZ	dZ
d�Zd	�Zd
�Z
ejd��Zejd��Zejd
��Zejd��Zejd��Zy)ra�
Controls for how messages are interpreted and formatted.

    Most of the classes and many of the methods in the email package accept
    Policy objects as parameters.  A Policy object contains a set of values and
    functions that control how input is interpreted and how output is rendered.
    For example, the parameter 'raise_on_defect' controls whether or not an RFC
    violation results in an error being raised or not, while 'max_line_length'
    controls the maximum length of output lines when a Message is serialized.

    Any valid attribute may be overridden when a Policy is created by passing
    it as a keyword argument to the constructor.  Policy objects are immutable,
    but a new Policy object can be created with only certain values changed by
    calling the Policy instance with keyword arguments.  Policy objects can
    also be added, producing a new Policy object in which the non-default
    attributes set in the right hand operand overwrite those specified in the
    left operand.

    Settable attributes:

    raise_on_defect     -- If true, then defects should be raised as errors.
                           Default: False.

    linesep             -- string containing the value to use as separation
                           between output lines.  Default '\n'.

    cte_type            -- Type of allowed content transfer encodings

                           7bit  -- ASCII only
                           8bit  -- Content-Transfer-Encoding: 8bit is allowed

                           Default: 8bit.  Also controls the disposition of
                           (RFC invalid) binary data in headers; see the
                           documentation of the binary_fold method.

    max_line_length     -- maximum length of lines, excluding 'linesep',
                           during serialization.  None or 0 means no line
                           wrapping is done.  Default is 78.

    mangle_from_        -- a flag that, when True escapes From_ lines in the
                           body of the message by putting a `>' in front of
                           them. This is used when the message is being
                           serialized by a generator. Default: False.

    message_factory     -- the class to use to create new message objects.
                           If the value is None, the default is Message.

    verify_generated_headers
                        -- if true, the generator verifies that each header
                           they are properly folded, so that a parser won't
                           treat it as multiple headers, start-of-body, or
                           part of another header.
                           This is a check against custom Header & fold()
                           implementations.
    Fr3�8bit�NNTc�D�|jr|�|j||�y)aZBased on policy, either raise defect or call register_defect.

            handle_defect(obj, defect)

        defect should be a Defect subclass, but in any case must be an
        Exception subclass.  obj is the object on which the defect should be
        registered if it is not raised.  If the raise_on_defect is True, the
        defect is raised as an error, otherwise the object and the defect are
        passed to register_defect.

        This method is intended to be called by parsers that discover defects.
        The email package parsers always call it with Defect instances.

        N)�raise_on_defect�register_defect�r�obj�defects   r�
handle_defectzPolicy.handle_defect�s"������L����S�&�)rc�:�|jj|�y)a�Record 'defect' on 'obj'.

        Called by handle_defect if raise_on_defect is False.  This method is
        part of the Policy API so that Policy subclasses can implement custom
        defect handling.  The default implementation calls the append method of
        the defects attribute of obj.  The objects used by the email package by
        default that get passed to this method will always have a defects
        attribute with an append method.

        N)�defects�appendrMs   rrLzPolicy.register_defect�s��	�����6�"rc��y)a[Return the maximum allowed number of headers named 'name'.

        Called when a header is added to a Message object.  If the returned
        value is not 0 or None, and there are already a number of headers with
        the name 'name' equal to the value returned, a ValueError is raised.

        Because the default behavior of Message's __setitem__ is to append the
        value to the list of headers, it is easy to create duplicate headers
        without realizing it.  This method allows certain headers to be limited
        in the number of instances of that header that may be added to a
        Message programmatically.  (The limit is not observed by the parser,
        which will faithfully produce as many headers as exist in the message
        being parsed.)

        The default implementation returns None for all header names.
        Nr+)rrs  r�header_max_countzPolicy.header_max_count�s��"rc��t�)aZGiven a list of linesep terminated strings constituting the lines of
        a single header, return the (name, value) tuple that should be stored
        in the model.  The input lines should retain their terminating linesep
        characters.  The lines passed in by the email package may contain
        surrogateescaped binary data.
        ��NotImplementedError)r�sourceliness  r�header_source_parsezPolicy.header_source_parse��
��"�!rc��t�)z�Given the header name and the value provided by the application
        program, return the (name, value) that should be stored in the model.
        rW�rrrs   r�header_store_parsezPolicy.header_store_parse�s
��
"�!rc��t�)awGiven the header name and the value from the model, return the value
        to be returned to the application program that is requesting that
        header.  The value passed in by the email package may contain
        surrogateescaped binary data if the lines were parsed by a BytesParser.
        The returned value should not contain any surrogateescaped data.

        rWr]s   r�header_fetch_parsezPolicy.header_fetch_parse�s
��"�!rc��t�)a�Given the header name and the value from the model, return a string
        containing linesep characters that implement the folding of the header
        according to the policy controls.  The value passed in by the email
        package may contain surrogateescaped binary data if the lines were
        parsed by a BytesParser.  The returned value should not contain any
        surrogateescaped data.

        rWr]s   r�foldzPolicy.folds
��"�!rc��t�)a%Given the header name and the value from the model, return binary
        data containing linesep characters that implement the folding of the
        header according to the policy controls.  The value passed in by the
        email package may contain surrogateescaped binary data.

        rWr]s   r�fold_binaryzPolicy.fold_binaryr[r)rr.r/r0rK�linesep�cte_type�max_line_length�mangle_from_�message_factory�verify_generated_headersrPrLrU�abc�abstractmethodrZr^r`rbrdr+rrrrps���5�n�O��G��H��O��L��O�#��*�&#��&	���"��"�	���"��"�	���"��"�	���	"��	"�	���"��"rr)�	metaclassc�>�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)rz�+
    This particular policy is the backward compatibility Policy.  It
    replicates the behavior of the email package version 5.1.
    Tc��t|t�s|St|�r&tj|t
j|��S|S)N�r�header_name)�
isinstance�strrr�Header�_charset�UNKNOWN8BITr]s   r�_sanitize_headerzCompat32._sanitize_header!s@���%��%��L��5�!��=�=���0D�0D�-1�3�
3��Lrc��|djdd�\}}dj|g|dd���jd�}||jd�fS)a4+
        The name is parsed as everything up to the ':' and returned unmodified.
        The value is determined by stripping leading whitespace off the
        remainder of the first line joined with all subsequent lines, and
        stripping any trailing carriage return or linefeed characters.

        r�:r4�Nz 	
z
)r6r�lstrip�rstrip)rrYrrs    rrZzCompat32.header_source_parse-sY��"�!�n�*�*�3��2���e�����1��Q�R��1�2�9�9�)�D���e�l�l�6�*�+�+rc�
�||fS)z>+
        The name and value are returned unmodified.
        r+r]s   rr^zCompat32.header_store_parse9s���e�}�rc�&�|j||�S)z�+
        If the value contains binary data, it is converted into a Header object
        using the unknown-8bit charset.  Otherwise it is returned unmodified.
        )rwr]s   rr`zCompat32.header_fetch_parse?s��
�$�$�T�5�1�1rc�*�|j||d��S)a+
        Headers are folded using the Header folding algorithm, which preserves
        existing line breaks in the value, and wraps each resulting line to the
        max_line_length.  Non-ASCII binary data are CTE encoded using the
        unknown-8bit charset.

        T��sanitize)�_foldr]s   rrbz
Compat32.foldFs���z�z�$���z�5�5rc�h�|j|||jdk(��}|jdd�S)a�+
        Headers are folded using the Header folding algorithm, which preserves
        existing line breaks in the value, and wraps each resulting line to the
        max_line_length.  If cte_type is 7bit, non-ascii binary data is CTE
        encoded using the unknown-8bit charset.  Otherwise the original source
        header is used, with its existing line breaks and/or binary data.

        �7bitr��ascii�surrogateescape)r�rf�encode)rrr�foldeds    rrdzCompat32.fold_binaryPs3�����D�%�$�-�-��2G��H���}�}�W�&7�8�8rc��g}|jd|z�t|t�r`t|�r=|r't	j
|tj|��}n.|j|�d}nt	j
||��}n|}|�Fd}|j�|j}|j|j|j|���|j|j�dj|�S)Nz%s: rp)rqr)re�
maxlinelenrz)rSrrrsrrrtrurvrgr�rer)rrrr��parts�hr�s       rr�zCompat32._fold\s�����
���V�d�]�#��e�S�!��u�%���
�
�e�.6�.B�.B�26�8�A��L�L��'��A��M�M�%�T�:���A��=��J��#�#�/�!�1�1�
��L�L����$�,�,�:��N�O�
���T�\�\�"��w�w�u�~�rN)rr.r/r0rhrwrZr^r`rbrdr�r+rrrrs1���
�L�
�
,��2�6�
9�rr)r0rk�emailrrru�email.utilsr�__all__r
r9rF�ABCMetarrrr+rr�<module>r�ss���
��%�'���I,�I,�X"�

�d"�[�C�K�K�d"�N�c�v�c��c�L�:�r__pycache__/base64mime.cpython-312.opt-1.pyc000064400000007553151706203560014371 0ustar00�

T��h�
��d�dZgd�ZddlmZddlmZmZdZdZdZ	dZ
d	�Zdd
�Zdefd�Z
d
�ZeZeZy)a�Base64 content transfer encoding per RFCs 2045-2047.

This module handles the content transfer encoding method defined in RFC 2045
to encode arbitrary 8-bit data using the three 8-bit bytes in four 7-bit
characters encoding known as Base64.

It is used in the MIME standards for email to attach images, audio, and text
using some 8-bit character sets to messages.

This module provides an interface to encode and decode both headers and bodies
with Base64 encoding.

RFC 2045 defines a method for including character set information in an
`encoded-word' in a header.  This method is commonly used for 8-bit real names
in To:, From:, Cc:, etc. fields, as well as Subject: lines.

This module does not do the line wrapping or end-of-line character conversion
necessary for proper internationalized headers; it only does dumb encoding and
decoding.  To deal with the various line wrapping issues, use the email.header
module.
)�body_decode�body_encode�decode�decodestring�
header_encode�
header_length�)�	b64encode)�
b2a_base64�
a2b_base64z
�
��c�N�tt|�d�\}}|dz}|r|dz
}|S)z6Return the length of s when it is encoded with base64.��)�divmod�len)�	bytearray�groups_of_3�leftover�ns    �)/usr/lib64/python3.12/email/base64mime.pyrr1s1��"�3�y�>�1�5��K���a��A��	�Q����H�c��|syt|t�r|j|�}t|�j	d�}d|�d|�d�S)z�Encode a single header line with Base64 encoding in a given charset.

    charset names the character set to use to encode the header.  It defaults
    to iso-8859-1.  Base64 encoding is defined in RFC 2045.
    r
�asciiz=?z?b?z?=)�
isinstance�str�encoder	r)�header_bytes�charset�encodeds   rrr;sD�����,��$�#�*�*�7�3����%�,�,�W�5�G�#�W�-�-r�Lc�*�|syg}|dzdz}tdt|�|�D]Y}t||||z�jd�}|j	t
�r|t
k7r|dd|z}|j
|��[tj|�S)a1Encode a string with base64.

    Each line will be wrapped at, at most, maxlinelen characters (defaults to
    76 characters).

    Each line of encoded text will end with eol, which defaults to "\n".  Set
    this to "\r\n" if you will be using the result of this function directly
    in an email.
    r
rrrrN���)	�rangerr
r�endswith�NL�append�EMPTYSTRING�join)�s�
maxlinelen�eol�encvec�
max_unencoded�i�encs       rrrIs���
��
�F���N�a�'�M�
�1�c�!�f�m�
,����1�Q��.�/�0�7�7��@���<�<����r�	��c�r�(�S�.�C��
�
�c��
-����F�#�#rc��|s
t�St|t�rt|j	d��St|�S)z�Decode a raw base64 string, returning a bytes object.

    This function does not parse a full MIME header value encoded with
    base64 (like =?iso-8859-1?b?bmloISBuaWgh?=) -- please use the high
    level email.header class for that functionality.
    zraw-unicode-escape)�bytesrrrr)�strings rrrbs8����w��	�F�C�	 ��&�-�-�(<�=�>�>��&�!�!rN)z
iso-8859-1)�__doc__�__all__�base64r	�binasciir
r�CRLFr'r)�MISC_LENrrrrrr�rr�<module>r<sV��
�,���+�
��	����
��
�.�!�b�$�2"� ���r__pycache__/base64mime.cpython-312.opt-2.pyc000064400000004231151706203560014360 0ustar00�

T��h�
��b�	gd�ZddlmZddlmZmZdZdZdZdZ	d�Z
dd	�Zd
efd�Zd�Z
e
Ze
Zy
))�body_decode�body_encode�decode�decodestring�
header_encode�
header_length�)�	b64encode)�
b2a_base64�
a2b_base64z
�
��c�P�	tt|�d�\}}|dz}|r|dz
}|S)N��)�divmod�len)�	bytearray�groups_of_3�leftover�ns    �)/usr/lib64/python3.12/email/base64mime.pyrr1s4��@�"�3�y�>�1�5��K���a��A��	�Q����H�c��	|syt|t�r|j|�}t|�j	d�}d|�d|�d�S)Nr
�asciiz=?z?b?z?=)�
isinstance�str�encoder	r)�header_bytes�charset�encodeds   rrr;sI���
���,��$�#�*�*�7�3����%�,�,�W�5�G�#�W�-�-r�Lc�,�	|syg}|dzdz}tdt|�|�D]Y}t||||z�jd�}|j	t
�r|t
k7r|dd|z}|j
|��[tj|�S)Nr
rrrr���)	�rangerr
r�endswith�NL�append�EMPTYSTRING�join)�s�
maxlinelen�eol�encvec�
max_unencoded�i�encs       rrrIs����
��
�F���N�a�'�M�
�1�c�!�f�m�
,����1�Q��.�/�0�7�7��@���<�<����r�	��c�r�(�S�.�C��
�
�c��
-����F�#�#rc��	|s
t�St|t�rt|j	d��St|�S)Nzraw-unicode-escape)�bytesrrrr)�strings rrrbs=�����w��	�F�C�	 ��&�-�-�(<�=�>�>��&�!�!rN)z
iso-8859-1)�__all__�base64r	�binasciir
r�CRLFr'r)�MISC_LENrrrrrr�rr�<module>r;sV��
�,���+�
��	����
��
�.�!�b�$�2"� ���r__pycache__/contentmanager.cpython-312.opt-2.pyc000064400000030114151706203560015430 0ustar00�

T��h\)��F�ddlZddlZddlZddlZddlmZGd�d�Ze�Zdd�Zejde�d�Z
dj�D]Zejee
��[d	�Z
d
j�D]Zejdeze
��[d�Zejd
e�d�Zd�Zd�Zd�Z			dd�Zej+ee�			dd�Zej+ej0j2e�			dd�ZeeefD]Zej+ee��[y)�N)�
quoprimimec�0�eZdZd�Zd�Zd�Zd�Zd�Zd�Zy)�ContentManagerc� �i|_i|_y�N)�get_handlers�set_handlers)�selfs �-/usr/lib64/python3.12/email/contentmanager.py�__init__zContentManager.__init__	s��������c�"�||j|<yr)r)r
�key�handlers   r�add_get_handlerzContentManager.add_get_handler
s��!(����#�r
c�B�|j�}||jvr|j||g|��i|��S|j�}||jvr|j||g|��i|��Sd|jvr|jd|g|��i|��St|��)N�)�get_content_typer�get_content_maintype�KeyError)r
�msg�args�kw�content_type�maintypes      r�get_contentzContentManager.get_contents����+�+�-���4�,�,�,�2�4�$�$�\�2�3�D��D��D�D��+�+�-���t�(�(�(�.�4�$�$�X�.�s�@�T�@�R�@�@�
��"�"�"�(�4�$�$�R�(��:�t�:�r�:�:��|�$�$r
c�"�||j|<yr)r	)r
�typekeyrs   r�add_set_handlerzContentManager.add_set_handlers��%,����'�"r
c��|j�dk(rtd��|j||�}|j�|||g|��i|��y)N�	multipartz"set_content not valid on multipart)r�	TypeError�_find_set_handler�
clear_content)r
r�objrrrs      r�set_contentzContentManager.set_contentsS���#�#�%��4��@�A�A��(�(��c�2��������S�&�4�&�2�&r
c��d}t|�jD]�}||jvr|j|cS|j}t	|dd�}|rdj||f�n|}|�|}||jvr|j|cS||jvr|j|cS|j}||jvs��|j|cSd|jvr|jdSt|��)N�
__module__r�.)�type�__mro__r	�__qualname__�getattr�join�__name__r)	r
rr%�full_path_for_error�typ�qname�modname�	full_path�names	         rr#z ContentManager._find_set_handler's
��"����9�$�$�C��d�'�'�'��(�(��-�-��$�$�E��c�<��4�G�6=����'�5�!1�2�5�I�"�*�&/�#��D�-�-�-��(�(��3�3���)�)�)��(�(��/�/��<�<�D��t�(�(�(��(�(��.�.�%��4�$�$�$��$�$�T�*�*��*�+�+r
N)	r/r(r,rrrrr&r#�r
rrrs ���)�	%�-�'�,r
rc�p�|jd��}|jdd�}|j||��S)NT��decode�charset�ASCII)�errors)�get_payload�	get_paramr9)rr<�contentr:s    r�get_text_contentr@@s5���o�o�T�o�*�G��m�m�I�w�/�G��>�>�'�&�>�1�1r
�textc�&�|jd��S)NTr8�r=�rs r�get_non_text_contentrEGs���?�?�$�?�'�'r
zaudio image video applicationc�$�|jd�S�NrrCrDs r�get_message_contentrHNs���?�?�1��r
zrfc822 external-bodyzmessage/c�6�t|jd��SrG)�bytesr=rDs r�%get_and_fixup_unknown_message_contentrKUs�������#�$�$r
�messagec���dj||f�|d<|rzt|dd�s8|j}|D�cgc]!}|j|j	|g����#}}	|D],}|j
r|j
d�|||j<�.yycc}w#tjj$r:}tdjj|j����|�d}~wwxYw)N�/zContent-Typerr5zInvalid header: {})�policy)
r.�hasattrrO�header_factory�header_source_parse�defectsr5�emailr<�HeaderDefect�
ValueError�format�fold)rr�subtype�headers�mp�header�excs       r�_prepare_setr^as����(�(�H�g�#6�7�C�����w�q�z�6�*����B�%,�.�%,�6�)�r�(�(�"�*@�*@�&��*J�K�%,�
�.�	J�!���>�>� �.�.��+�+�#)��F�K�K� �"�
��.���|�|�(�(�	J��1�8�8� &���3�:�:�� >�@�A�FI�
J��	J�s�&B�!1B�C0�65C+�+C0c��|�|�d}|�||d<|�|jd|dd��|�||d<|�+|j�D]\}}|j||��yy)N�
attachmentzContent-Disposition�filenameT)r\�replacez
Content-ID)�	set_param�items)r�dispositionra�cid�paramsr�values       r�
_finalize_setrirs�����x�3�"����%0��!�"����
�
�j��2�"�	�	$�����L��
�� �,�,�.�J�C���M�M�#�u�%�)�r
c���g}|dzdz}tdt|�|�D]=}||||z}|jtj|�jd���?dj
|�S)N��r�asciir)�range�len�append�binascii�
b2a_base64r9r.)�data�max_line_length�
encoded_lines�unencoded_bytes_per_line�i�thislines      r�_encode_base64ry�sv���M�.�!�3�a�7��
�1�c�$�i�!9�
:����!�4�4�5�����X�0�0��:�A�A�'�J�K�;��7�7�=�!�!r
c����|j|�j�}|jjd���fd�}d�}|��td�|D�d��|jkr	d||�jd�fS||dd
�}tj|jd�|j�}tj|�}	t|�t|	�kDrd}nd
}t|�d
kr||fS|dk(r||�jd�}
||
fS|dk(r||�jdd	�}
||
fS|d
k(r9tj||�jd�|j�}
||
fS|dk(r t||�|j�}
||
fStdj|���#t$rYnwxYw|jdk(s��[d||�jdd	�fS)Nrmc�,���j|��zSr�r.)�lines�lineseps �r�
embedded_bodyz#_encode_text.<locals>.embedded_body�s���W�\�\�%�%8�7�%B�Br
c�*�dj|�dzS)N�
r|)r}s r�normal_bodyz!_encode_text.<locals>.normal_body�s��5�:�:�e�#4�u�#<�<r
c3�2K�|]}t|����y�wr)ro)�.0�xs  r�	<genexpr>z_encode_text.<locals>.<genexpr>�s����&��1��A���s�r)�default�7bit�8bit�surrogateescape�
zlatin-1�base64�quoted-printablez$Unknown content transfer encoding {})�encode�
splitlinesr~�maxrtr9�UnicodeDecodeError�cte_typer�body_encoderqrrroryrVrW)�stringr:�cterOr}rr��sniff�sniff_qp�sniff_base64rsr~s           @r�_encode_textr��s����M�M�'�"�-�-�/�E��n�n�#�#�G�,�G�B�<�
�{��&��&��2�f�6L�6L�L�
��{�5�1�8�8��A�A�A�
�e�C�R�j�)���)�)�%�,�,�y�*A�*0�*@�*@�B���*�*�5�1���x�=�3�|�,�,��C�$�C��5�z�R���H�}�$�
�f�}��5�!�(�(��1����9��

����5�!�(�(��2C�D����9��

�"�	"��%�%�k�%�&8�&?�&?�	�&J�&,�&<�&<�>����9��	

����m�E�2�F�4J�4J�K����9���?�F�F�s�K�L�L��3&�
��
�����&�(��{�5�1�8�8��BS�T�T�Ts�(F<�<	G�Gc
��t|d||	�t||||j�\}}
|j|
�|j	dt
jjj||�d��||d<t|||||�y)NrAr:T�rb�Content-Transfer-Encoding)
r^r�rO�set_payloadrcrTr:�ALIASES�getri)rr�rYr:r�rerarfrgrZ�payloads           r�set_text_contentr��s�����f�g�w�/�����c�j�j�A�L�C���O�O�G���M�M�)��-�-�'�'�+�+�G�W�=��� �(+�C�#�$��#�{�H�c�6�:r
c	�4�|dk(rtd��|dk(r%|dvrtdj|���|�dn|}n*|dk(r!|dvrtd	j|���d
}n|�d
}t|d||�|j|g�||d<t	|||||�y)
N�partialz4message/partial is not supported for Message objects�rfc822)Nr�r��binaryz*message/rfc822 parts do not support cte={}r�z
external-body)Nr�z1message/external-body parts do not support cte={}r�rLr�)rVrWr^r�ri)	rrLrYr�rerarfrgrZs	         r�set_message_contentr��s����)���O�P�P��(���6�6��<�C�C�C�H�J�
J���f���	�O�	#��n�$��C�J�J�3�O�Q�
Q���	������i��'�2��O�O�W�I��'*�C�#�$��#�{�H�c�6�:r
c
�r�t||||	�|dk(r"t||jj��}n]|dk(r+t	j
|ddd��}|j
d�}n-|dk(r|j
d�}n|d	vr|j
dd
�}|j|�||d<t|||||�y)Nr�)rtr�FT)�istextr\�	quotetabsrmr�)r�r�r�r�)	r^ryrOrtrq�b2a_qpr9r�ri)
rrsrrYr�rerarfrgrZs
          r�set_bytes_contentr��s�����h���1�
�h���d�C�J�J�4N�4N�O��	�"�	"����t�E�%�4�P���{�{�7�#��	����{�{�7�#��	�"�	"��{�{�7�$5�6���O�O�D��'*�C�#�$��#�{�H�c�6�:r
r�)�plainzutf-8NNNNNN)r�NNNNNN)r�NNNNN)rq�
email.charsetrT�
email.message�email.errorsrr�raw_data_managerr@rrE�splitrrHrYrKr^riryr�r�r�strr�rL�Messager�rJ�	bytearray�
memoryviewr1r6r
r�<module>r�s[�������3,�3,�l"�#��2�� � ��)9�:�(�/�5�5�7�H��$�$�X�/C�D�8���%�+�+�-�G��$�$�Z��%7�9L�M�.��%�� � ��!F�H�J�"&�*"�$�NIM�:>�*.�
;�� � ��&6�7�=A�<@�,0�;�<� � ����!6�!6�8K�L�9A�:>�*.�;�&
�9�j�)�C��$�$�S�*;�<�*�r
__pycache__/contentmanager.cpython-312.pyc000064400000030114151706203560014470 0ustar00�

T��h\)��F�ddlZddlZddlZddlZddlmZGd�d�Ze�Zdd�Zejde�d�Z
dj�D]Zejee
��[d	�Z
d
j�D]Zejdeze
��[d�Zejd
e�d�Zd�Zd�Zd�Z			dd�Zej+ee�			dd�Zej+ej0j2e�			dd�ZeeefD]Zej+ee��[y)�N)�
quoprimimec�0�eZdZd�Zd�Zd�Zd�Zd�Zd�Zy)�ContentManagerc� �i|_i|_y�N)�get_handlers�set_handlers)�selfs �-/usr/lib64/python3.12/email/contentmanager.py�__init__zContentManager.__init__	s��������c�"�||j|<yr)r)r
�key�handlers   r�add_get_handlerzContentManager.add_get_handler
s��!(����#�r
c�B�|j�}||jvr|j||g|��i|��S|j�}||jvr|j||g|��i|��Sd|jvr|jd|g|��i|��St|��)N�)�get_content_typer�get_content_maintype�KeyError)r
�msg�args�kw�content_type�maintypes      r�get_contentzContentManager.get_contents����+�+�-���4�,�,�,�2�4�$�$�\�2�3�D��D��D�D��+�+�-���t�(�(�(�.�4�$�$�X�.�s�@�T�@�R�@�@�
��"�"�"�(�4�$�$�R�(��:�t�:�r�:�:��|�$�$r
c�"�||j|<yr)r	)r
�typekeyrs   r�add_set_handlerzContentManager.add_set_handlers��%,����'�"r
c��|j�dk(rtd��|j||�}|j�|||g|��i|��y)N�	multipartz"set_content not valid on multipart)r�	TypeError�_find_set_handler�
clear_content)r
r�objrrrs      r�set_contentzContentManager.set_contentsS���#�#�%��4��@�A�A��(�(��c�2��������S�&�4�&�2�&r
c��d}t|�jD]�}||jvr|j|cS|j}t	|dd�}|rdj||f�n|}|�|}||jvr|j|cS||jvr|j|cS|j}||jvs��|j|cSd|jvr|jdSt|��)N�
__module__r�.)�type�__mro__r	�__qualname__�getattr�join�__name__r)	r
rr%�full_path_for_error�typ�qname�modname�	full_path�names	         rr#z ContentManager._find_set_handler's
��"����9�$�$�C��d�'�'�'��(�(��-�-��$�$�E��c�<��4�G�6=����'�5�!1�2�5�I�"�*�&/�#��D�-�-�-��(�(��3�3���)�)�)��(�(��/�/��<�<�D��t�(�(�(��(�(��.�.�%��4�$�$�$��$�$�T�*�*��*�+�+r
N)	r/r(r,rrrrr&r#�r
rrrs ���)�	%�-�'�,r
rc�p�|jd��}|jdd�}|j||��S)NT��decode�charset�ASCII)�errors)�get_payload�	get_paramr9)rr<�contentr:s    r�get_text_contentr@@s5���o�o�T�o�*�G��m�m�I�w�/�G��>�>�'�&�>�1�1r
�textc�&�|jd��S)NTr8�r=�rs r�get_non_text_contentrEGs���?�?�$�?�'�'r
zaudio image video applicationc�$�|jd�S�NrrCrDs r�get_message_contentrHNs���?�?�1��r
zrfc822 external-bodyzmessage/c�6�t|jd��SrG)�bytesr=rDs r�%get_and_fixup_unknown_message_contentrKUs�������#�$�$r
�messagec���dj||f�|d<|rzt|dd�s8|j}|D�cgc]!}|j|j	|g����#}}	|D],}|j
r|j
d�|||j<�.yycc}w#tjj$r:}tdjj|j����|�d}~wwxYw)N�/zContent-Typerr5zInvalid header: {})�policy)
r.�hasattrrO�header_factory�header_source_parse�defectsr5�emailr<�HeaderDefect�
ValueError�format�fold)rr�subtype�headers�mp�header�excs       r�_prepare_setr^as����(�(�H�g�#6�7�C�����w�q�z�6�*����B�%,�.�%,�6�)�r�(�(�"�*@�*@�&��*J�K�%,�
�.�	J�!���>�>� �.�.��+�+�#)��F�K�K� �"�
��.���|�|�(�(�	J��1�8�8� &���3�:�:�� >�@�A�FI�
J��	J�s�&B�!1B�C0�65C+�+C0c��|�|�d}|�||d<|�|jd|dd��|�||d<|�+|j�D]\}}|j||��yy)N�
attachmentzContent-Disposition�filenameT)r\�replacez
Content-ID)�	set_param�items)r�dispositionra�cid�paramsr�values       r�
_finalize_setrirs�����x�3�"����%0��!�"����
�
�j��2�"�	�	$�����L��
�� �,�,�.�J�C���M�M�#�u�%�)�r
c���g}|dzdz}tdt|�|�D]=}||||z}|jtj|�jd���?dj
|�S)N��r�asciir)�range�len�append�binascii�
b2a_base64r9r.)�data�max_line_length�
encoded_lines�unencoded_bytes_per_line�i�thislines      r�_encode_base64ry�sv���M�.�!�3�a�7��
�1�c�$�i�!9�
:����!�4�4�5�����X�0�0��:�A�A�'�J�K�;��7�7�=�!�!r
c����|j|�j�}|jjd���fd�}d�}|��td�|D�d��|jkr	d||�jd�fS||dd
�}tj|jd�|j�}tj|�}	t|�t|	�kDrd}nd
}t|�d
kr||fS|dk(r||�jd�}
||
fS|dk(r||�jdd	�}
||
fS|d
k(r9tj||�jd�|j�}
||
fS|dk(r t||�|j�}
||
fStdj|���#t$rYnwxYw|jdk(s��[d||�jdd	�fS)Nrmc�,���j|��zSr�r.)�lines�lineseps �r�
embedded_bodyz#_encode_text.<locals>.embedded_body�s���W�\�\�%�%8�7�%B�Br
c�*�dj|�dzS)N�
r|)r}s r�normal_bodyz!_encode_text.<locals>.normal_body�s��5�:�:�e�#4�u�#<�<r
c3�2K�|]}t|����y�wr)ro)�.0�xs  r�	<genexpr>z_encode_text.<locals>.<genexpr>�s����&��1��A���s�r)�default�7bit�8bit�surrogateescape�
zlatin-1�base64�quoted-printablez$Unknown content transfer encoding {})�encode�
splitlinesr~�maxrtr9�UnicodeDecodeError�cte_typer�body_encoderqrrroryrVrW)�stringr:�cterOr}rr��sniff�sniff_qp�sniff_base64rsr~s           @r�_encode_textr��s����M�M�'�"�-�-�/�E��n�n�#�#�G�,�G�B�<�
�{��&��&��2�f�6L�6L�L�
��{�5�1�8�8��A�A�A�
�e�C�R�j�)���)�)�%�,�,�y�*A�*0�*@�*@�B���*�*�5�1���x�=�3�|�,�,��C�$�C��5�z�R���H�}�$�
�f�}��5�!�(�(��1����9��

����5�!�(�(��2C�D����9��

�"�	"��%�%�k�%�&8�&?�&?�	�&J�&,�&<�&<�>����9��	

����m�E�2�F�4J�4J�K����9���?�F�F�s�K�L�L��3&�
��
�����&�(��{�5�1�8�8��BS�T�T�Ts�(F<�<	G�Gc
��t|d||	�t||||j�\}}
|j|
�|j	dt
jjj||�d��||d<t|||||�y)NrAr:T�rb�Content-Transfer-Encoding)
r^r�rO�set_payloadrcrTr:�ALIASES�getri)rr�rYr:r�rerarfrgrZ�payloads           r�set_text_contentr��s�����f�g�w�/�����c�j�j�A�L�C���O�O�G���M�M�)��-�-�'�'�+�+�G�W�=��� �(+�C�#�$��#�{�H�c�6�:r
c	�4�|dk(rtd��|dk(r%|dvrtdj|���|�dn|}n*|dk(r!|dvrtd	j|���d
}n|�d
}t|d||�|j|g�||d<t	|||||�y)
N�partialz4message/partial is not supported for Message objects�rfc822)Nr�r��binaryz*message/rfc822 parts do not support cte={}r�z
external-body)Nr�z1message/external-body parts do not support cte={}r�rLr�)rVrWr^r�ri)	rrLrYr�rerarfrgrZs	         r�set_message_contentr��s����)���O�P�P��(���6�6��<�C�C�C�H�J�
J���f���	�O�	#��n�$��C�J�J�3�O�Q�
Q���	������i��'�2��O�O�W�I��'*�C�#�$��#�{�H�c�6�:r
c
�r�t||||	�|dk(r"t||jj��}n]|dk(r+t	j
|ddd��}|j
d�}n-|dk(r|j
d�}n|d	vr|j
dd
�}|j|�||d<t|||||�y)Nr�)rtr�FT)�istextr\�	quotetabsrmr�)r�r�r�r�)	r^ryrOrtrq�b2a_qpr9r�ri)
rrsrrYr�rerarfrgrZs
          r�set_bytes_contentr��s�����h���1�
�h���d�C�J�J�4N�4N�O��	�"�	"����t�E�%�4�P���{�{�7�#��	����{�{�7�#��	�"�	"��{�{�7�$5�6���O�O�D��'*�C�#�$��#�{�H�c�6�:r
r�)�plainzutf-8NNNNNN)r�NNNNNN)r�NNNNN)rq�
email.charsetrT�
email.message�email.errorsrr�raw_data_managerr@rrE�splitrrHrYrKr^riryr�r�r�strr�rL�Messager�rJ�	bytearray�
memoryviewr1r6r
r�<module>r�s[�������3,�3,�l"�#��2�� � ��)9�:�(�/�5�5�7�H��$�$�X�/C�D�8���%�+�+�-�G��$�$�Z��%7�9L�M�.��%�� � ��!F�H�J�"&�*"�$�NIM�:>�*.�
;�� � ��&6�7�=A�<@�,0�;�<� � ����!6�!6�8K�L�9A�:>�*.�;�&
�9�j�)�C��$�$�S�*;�<�*�r
__pycache__/encoders.cpython-312.opt-1.pyc000064400000004053151706203560014227 0ustar00�

T��h���F�dZgd�ZddlmZddlmZd�Zd�Z	d�Z
d�Zd	�Zy
)z Encodings and related functions.)�encode_7or8bit�
encode_base64�encode_noop�
encode_quopri�)�encodebytes)�encodestringc�@�t|d��}|jdd�S)NT)�	quotetabs� s=20)�
_encodestring�replace)�s�encs  �'/usr/lib64/python3.12/email/encoders.py�_qencoders��
��T�
*�C��;�;�t�V�$�$�c�~�|jd��}tt|�d�}|j|�d|d<y)zlEncode the message's payload in Base64.

    Also, add an appropriate Content-Transfer-Encoding header.
    T��decode�ascii�base64�Content-Transfer-EncodingN)�get_payload�str�_bencode�set_payload��msg�orig�encdatas   rrrs;��
�?�?�$�?�'�D��(�4�.�'�*�G��O�O�G��'/�C�#�$rc�j�|jd��}t|�}|j|�d|d<y)zvEncode the message's payload in quoted-printable.

    Also, add an appropriate Content-Transfer-Encoding header.
    Trzquoted-printablerN)rrrrs   rrr$s4��
�?�?�$�?�'�D��t�n�G��O�O�G��'9�C�#�$rc��|jd��}|�d|d<y	|jd�d|d<y#t$rd|d<YywxYw)z9Set the Content-Transfer-Encoding header to 7bit or 8bit.TrN�7bitrr�8bit)rr�UnicodeError)rrs  rrr/s_���?�?�$�?�'�D��|�+1��'�(��2����G��,2��'�(���2�+1��'�(�2�s�3�A�Ac��y)zDo nothing.N�)rs rrr@s�rN)
�__doc__�__all__rrr�quoprirrrrrrrr'rr�<module>r+s2��
'���+�0�%�0�:�2�"r__pycache__/encoders.cpython-312.opt-2.pyc000064400000003346151706203560014234 0ustar00�

T��h���D�	gd�ZddlmZddlmZd�Zd�Zd�Z	d�Z
d�Zy	)
)�encode_7or8bit�
encode_base64�encode_noop�
encode_quopri�)�encodebytes)�encodestringc�@�t|d��}|jdd�S)NT)�	quotetabs� s=20)�
_encodestring�replace)�s�encs  �'/usr/lib64/python3.12/email/encoders.py�_qencoders��
��T�
*�C��;�;�t�V�$�$�c��	|jd��}tt|�d�}|j|�d|d<y)NT��decode�ascii�base64�Content-Transfer-Encoding)�get_payload�str�_bencode�set_payload��msg�orig�encdatas   rrrs@����?�?�$�?�'�D��(�4�.�'�*�G��O�O�G��'/�C�#�$rc�l�	|jd��}t|�}|j|�d|d<y)NTrzquoted-printabler)rrrrs   rrr$s9����?�?�$�?�'�D��t�n�G��O�O�G��'9�C�#�$rc��	|jd��}|�d|d<y	|jd�d|d<y#t$rd|d<YywxYw)NTr�7bitrr�8bit)rr�UnicodeError)rrs  rrr/sb��C��?�?�$�?�'�D��|�+1��'�(��2����G��,2��'�(���2�+1��'�(�2�s�4�A�Ac��y)N�)rs rrr@s��rN)�__all__rrr�quoprirrrrrrrr'rr�<module>r*s2��
'���+�0�%�0�:�2�"r__pycache__/encoders.cpython-312.pyc000064400000004053151706203560013270 0ustar00�

T��h���F�dZgd�ZddlmZddlmZd�Zd�Z	d�Z
d�Zd	�Zy
)z Encodings and related functions.)�encode_7or8bit�
encode_base64�encode_noop�
encode_quopri�)�encodebytes)�encodestringc�@�t|d��}|jdd�S)NT)�	quotetabs� s=20)�
_encodestring�replace)�s�encs  �'/usr/lib64/python3.12/email/encoders.py�_qencoders��
��T�
*�C��;�;�t�V�$�$�c�~�|jd��}tt|�d�}|j|�d|d<y)zlEncode the message's payload in Base64.

    Also, add an appropriate Content-Transfer-Encoding header.
    T��decode�ascii�base64�Content-Transfer-EncodingN)�get_payload�str�_bencode�set_payload��msg�orig�encdatas   rrrs;��
�?�?�$�?�'�D��(�4�.�'�*�G��O�O�G��'/�C�#�$rc�j�|jd��}t|�}|j|�d|d<y)zvEncode the message's payload in quoted-printable.

    Also, add an appropriate Content-Transfer-Encoding header.
    Trzquoted-printablerN)rrrrs   rrr$s4��
�?�?�$�?�'�D��t�n�G��O�O�G��'9�C�#�$rc��|jd��}|�d|d<y	|jd�d|d<y#t$rd|d<YywxYw)z9Set the Content-Transfer-Encoding header to 7bit or 8bit.TrN�7bitrr�8bit)rr�UnicodeError)rrs  rrr/s_���?�?�$�?�'�D��|�+1��'�(��2����G��,2��'�(���2�+1��'�(�2�s�3�A�Ac��y)zDo nothing.N�)rs rrr@s�rN)
�__doc__�__all__rrr�quoprirrrrrrrr'rr�<module>r+s2��
'���+�0�%�0�:�2�"r__pycache__/errors.cpython-312.opt-1.pyc000064400000015557151706203560013754 0ustar00�

T��h���`�dZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd	�d
ee�ZGd�de�ZGd
�de�Z	Gd�de
�ZGd�de�ZGd�de�Z
Gd�de�ZGd�de�ZGd�de�ZGd�de�ZeZGd�de�ZGd�d e�ZGd!�d"e�ZGd#�d$e�ZGd%�d&e�ZGd'�d(e�ZGd)�d*e�ZGd+�d,e�ZGd-�d.e�ZGd/�d0e�ZGd1�d2e�ZGd3�d4e�ZGd5�d6e�Zy7)8z email package exception classes.c��eZdZdZy)�MessageErrorz+Base class for errors in the email package.N��__name__�
__module__�__qualname__�__doc__���%/usr/lib64/python3.12/email/errors.pyrr���5r
rc��eZdZdZy)�MessageParseErrorz&Base class for message parsing errors.Nrr	r
rrrs��0r
rc��eZdZdZy)�HeaderParseErrorzError while parsing headers.Nrr	r
rrr���&r
rc��eZdZdZy)�
BoundaryErrorz#Couldn't find terminating boundary.Nrr	r
rrrs��-r
rc��eZdZdZy)�MultipartConversionErrorz(Conversion to a multipart is prohibited.Nrr	r
rrr���2r
rc��eZdZdZy)�CharsetErrorzAn illegal charset was given.Nrr	r
rrrs��'r
rc��eZdZdZy)�HeaderWriteErrorzError while writing headers.Nrr	r
rrr rr
rc�$��eZdZdZd�fd�	Z�xZS)�
MessageDefectz Base class for a message defect.c�6��|�t�|�|�||_y�N)�super�__init__�line)�selfr!�	__class__s  �rr zMessageDefect.__init__(s������G��T�"���	r
r�rrrrr �
__classcell__�r#s@rrr%s���*��r
rc��eZdZdZy)�NoBoundaryInMultipartDefectzBA message claimed to be a multipart but had no boundary parameter.Nrr	r
rr(r(-s��Lr
r(c��eZdZdZy)�StartBoundaryNotFoundDefectz+The claimed start boundary was never found.Nrr	r
rr*r*0rr
r*c��eZdZdZy)�CloseBoundaryNotFoundDefectzEA start boundary was found, but not the corresponding close boundary.Nrr	r
rr,r,3���Or
r,c��eZdZdZy)�#FirstHeaderLineIsContinuationDefectz;A message had a continuation line as its first header line.Nrr	r
rr/r/6s��Er
r/c��eZdZdZy)�MisplacedEnvelopeHeaderDefectz?A 'Unix-from' header was found in the middle of a header block.Nrr	r
rr1r19���Ir
r1c��eZdZdZy)� MissingHeaderBodySeparatorDefectzEFound line with no leading whitespace and no colon before blank line.Nrr	r
rr4r4<r-r
r4c��eZdZdZy)�!MultipartInvariantViolationDefectz?A message claimed to be a multipart but no subparts were found.Nrr	r
rr6r6Ar2r
r6c��eZdZdZy)�-InvalidMultipartContentTransferEncodingDefectzEAn invalid content transfer encoding was set on the multipart itself.Nrr	r
rr8r8Dr-r
r8c��eZdZdZy)�UndecodableBytesDefectz0Header contained bytes that could not be decodedNrr	r
rr:r:G���:r
r:c��eZdZdZy)�InvalidBase64PaddingDefectz/base64 encoded sequence had an incorrect lengthNrr	r
rr=r=Js��9r
r=c��eZdZdZy)�InvalidBase64CharactersDefectz=base64 encoded sequence had characters not in base64 alphabetNrr	r
rr?r?Ms��Gr
r?c��eZdZdZy)�InvalidBase64LengthDefectz4base64 encoded sequence had invalid length (1 mod 4)Nrr	r
rrArAPs��>r
rAc�"��eZdZdZ�fd�Z�xZS)�HeaderDefectzBase class for a header defect.c�$��t�|�|i|��yr)rr )r"�args�kwr#s   �rr zHeaderDefect.__init__Xs���
���$�%�"�%r
r$r&s@rrCrCUs���)�&�&r
rCc��eZdZdZy)�InvalidHeaderDefectz+Header is not valid, message gives details.Nrr	r
rrHrH[rr
rHc��eZdZdZy)�HeaderMissingRequiredValuez(A header that must have a value had noneNrr	r
rrJrJ^rr
rJc�(��eZdZdZ�fd�Zd�Z�xZS)�NonPrintableDefectz8ASCII characters outside the ascii-printable range foundc�2��t�|�|�||_yr)rr �non_printables)r"rNr#s  �rr zNonPrintableDefect.__init__ds���
����(�,��r
c�8�dj|j�S)Nz6the following ASCII non-printables found in header: {})�formatrN)r"s r�__str__zNonPrintableDefect.__str__hs������+�+�,�	.r
)rrrrr rQr%r&s@rrLrLas���B�-�.r
rLc��eZdZdZy)�ObsoleteHeaderDefectz0Header uses syntax declared obsolete by RFC 5322Nrr	r
rrSrSlr;r
rSc��eZdZdZy)�NonASCIILocalPartDefectz(local_part contains non-ASCII charactersNrr	r
rrUrUorr
rUc��eZdZdZy)�InvalidDateDefectz%Header has unparsable or invalid dateNrr	r
rrWrWts��/r
rWN) r�	Exceptionrrrr�	TypeErrorrrr�
ValueErrorrr(r*r,r/r1r4�MalformedHeaderDefectr6r8r:r=r?rArCrHrJrLrSrUrWr	r
r�<module>r\sj��
'�6�9�6�1��1�'�(�'�.�%�.�3�|�Y�3�(�<�(�'�|�'�
�J��M�-�M�6�-�6�P�-�P�F�-�F�J�M�J�P�}�P�9��J�
�J�P�M�P�;�]�;�:��:�H�M�H�?�
�?�
&�=�&�6�,�6�3��3�	.��	.�;�<�;�3�l�3�
0��0r
__pycache__/errors.cpython-312.opt-2.pyc000064400000012632151706203560013744 0ustar00�

T��h���^�	Gd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�d	ee�ZGd
�de�ZGd�d
e�ZGd�de	�Z
Gd�de
�ZGd�de
�ZGd�de
�Z
Gd�de
�ZGd�de
�ZGd�de
�ZeZGd�de
�ZGd�de
�ZGd �d!e
�ZGd"�d#e
�ZGd$�d%e
�ZGd&�d'e
�ZGd(�d)e
�ZGd*�d+e�ZGd,�d-e�ZGd.�d/e�ZGd0�d1e�ZGd2�d3e�ZGd4�d5e�Zy6)7c��eZdZy)�MessageErrorN��__name__�
__module__�__qualname__���%/usr/lib64/python3.12/email/errors.pyrr���5r	rc��eZdZy)�MessageParseErrorNrrr	r
r
r
s��0r	r
c��eZdZy)�HeaderParseErrorNrrr	r
rr���&r	rc��eZdZy)�
BoundaryErrorNrrr	r
rrs��-r	rc��eZdZy)�MultipartConversionErrorNrrr	r
rr���2r	rc��eZdZy)�CharsetErrorNrrr	r
rrs��'r	rc��eZdZy)�HeaderWriteErrorNrrr	r
rr rr	rc�"��eZdZ	d�fd�	Z�xZS)�
MessageDefectc�6��|�t�|�|�||_y�N)�super�__init__�line)�selfr �	__class__s  �r
rzMessageDefect.__init__(s������G��T�"���	r	r�rrrr�
__classcell__�r"s@r
rr%s���*��r	rc��eZdZy)�NoBoundaryInMultipartDefectNrrr	r
r'r'-s��Lr	r'c��eZdZy)�StartBoundaryNotFoundDefectNrrr	r
r)r)0rr	r)c��eZdZy)�CloseBoundaryNotFoundDefectNrrr	r
r+r+3���Or	r+c��eZdZy)�#FirstHeaderLineIsContinuationDefectNrrr	r
r.r.6s��Er	r.c��eZdZy)�MisplacedEnvelopeHeaderDefectNrrr	r
r0r09���Ir	r0c��eZdZy)� MissingHeaderBodySeparatorDefectNrrr	r
r3r3<r,r	r3c��eZdZy)�!MultipartInvariantViolationDefectNrrr	r
r5r5Ar1r	r5c��eZdZy)�-InvalidMultipartContentTransferEncodingDefectNrrr	r
r7r7Dr,r	r7c��eZdZy)�UndecodableBytesDefectNrrr	r
r9r9G���:r	r9c��eZdZy)�InvalidBase64PaddingDefectNrrr	r
r<r<Js��9r	r<c��eZdZy)�InvalidBase64CharactersDefectNrrr	r
r>r>Ms��Gr	r>c��eZdZy)�InvalidBase64LengthDefectNrrr	r
r@r@Ps��>r	r@c� ��eZdZ	�fd�Z�xZS)�HeaderDefectc�$��t�|�|i|��yr)rr)r!�args�kwr"s   �r
rzHeaderDefect.__init__Xs���
���$�%�"�%r	r#r%s@r
rBrBUs���)�&�&r	rBc��eZdZy)�InvalidHeaderDefectNrrr	r
rGrG[rr	rGc��eZdZy)�HeaderMissingRequiredValueNrrr	r
rIrI^rr	rIc�&��eZdZ	�fd�Zd�Z�xZS)�NonPrintableDefectc�2��t�|�|�||_yr)rr�non_printables)r!rMr"s  �r
rzNonPrintableDefect.__init__ds���
����(�,��r	c�8�dj|j�S)Nz6the following ASCII non-printables found in header: {})�formatrM)r!s r
�__str__zNonPrintableDefect.__str__hs������+�+�,�	.r	)rrrrrPr$r%s@r
rKrKas���B�-�.r	rKc��eZdZy)�ObsoleteHeaderDefectNrrr	r
rRrRlr:r	rRc��eZdZy)�NonASCIILocalPartDefectNrrr	r
rTrTorr	rTc��eZdZy)�InvalidDateDefectNrrr	r
rVrVts��/r	rVN)�	Exceptionrr
rr�	TypeErrorrrr�
ValueErrorrr'r)r+r.r0r3�MalformedHeaderDefectr5r7r9r<r>r@rBrGrIrKrRrTrVrr	r
�<module>r[sj��
'�6�9�6�1��1�'�(�'�.�%�.�3�|�Y�3�(�<�(�'�|�'�
�J��M�-�M�6�-�6�P�-�P�F�-�F�J�M�J�P�}�P�9��J�
�J�P�M�P�;�]�;�:��:�H�M�H�?�
�?�
&�=�&�6�,�6�3��3�	.��	.�;�<�;�3�l�3�
0��0r	__pycache__/feedparser.cpython-312.opt-1.pyc000064400000046231151706203560014551 0ustar00�

T��hY��R�dZddgZddlZddlmZddlmZddlmZddl	m
Z
ejd	�Zejd
�Z
ejd�Zejd
�Zejd�Zd
ZdZe�ZGd�de�ZGd�d�ZGd�de�Zy)aFeedParser - An email feed parser.

The feed parser implements an interface for incrementally parsing an email
message, line by line.  This has advantages for certain applications, such as
those reading email messages off a socket.

FeedParser.feed() is the primary interface for pushing new data into the
parser.  It returns when there's nothing more it can do with the available
data.  When you have no more data to push into the parser, call .close().
This completes the parsing and returns the root message object.

The other advantage of this parser is that it will never raise a parsing
exception.  Instead, when it finds something unexpected, it adds a 'defect' to
the current message.  Defects are just instances that live on the message
object's .defects attribute.
�
FeedParser�BytesFeedParser�N)�errors)�compat32)�deque)�StringIOz
\r\n|\r|\nz(\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ])��
c�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�BufferedSubFileakA file-ish object that can have new data loaded into it.

    You can also push and pop line-matching predicates onto a stack.  When the
    current predicate matches the current line, a false EOF response
    (i.e. empty string) is returned instead.  This lets the parser adhere to a
    simple abstraction -- it parses until EOF closes the current message.
    c�`�td��|_t�|_g|_d|_y)Nr	)�newlineF)r�_partialr�_lines�	_eofstack�_closed��selfs �)/usr/lib64/python3.12/email/feedparser.py�__init__zBufferedSubFile.__init__4s'��!��,��
��g���������c�:�|jj|�y�N)r�append)r�preds  r�push_eof_matcherz BufferedSubFile.push_eof_matcher?s�������d�#rc�6�|jj�Sr)r�poprs r�pop_eof_matcherzBufferedSubFile.pop_eof_matcherBs���~�~�!�!�#�#rc��|jjd�|j|jj��|jjd�|jj	�d|_y)NrT)r�seek�	pushlines�	readlines�truncaterrs r�closezBufferedSubFile.closeEsV���
�
���1�����t�}�}�.�.�0�1��
�
���1���
�
��� ���rc��|js|jrytS|jj�}t	|j
�D]'}||�s�|jj
|�y|S�Nr	)rr�NeedMoreData�popleft�reversedr�
appendleft)r�line�ateofs   r�readlinezBufferedSubFile.readlineMse���{�{��|�|�����{�{�"�"�$���d�n�n�-�E��T�{����&�&�t�,��	.�
�rc�:�|jj|�yr)rr+�rr,s  r�
unreadlinezBufferedSubFile.unreadline_s��	
�����t�$rc��|jj|�d|vrd|vry|jjd�|jj�}|jjd�|jj	�|djd�s)|jj|j
��|j|�y)z$Push some new data into this object.r
�
Nr���)r�writer!r#r$�endswithrr")r�data�partss   r�pushzBufferedSubFile.pushds����
�
���D�!��t���D� 0��	
�
�
���1���
�
�'�'�)���
�
���1���
�
��� ��R�y�!�!�$�'��M�M����	�	��,����u�rc�:�|jj|�yr)r�extend)r�liness  rr"zBufferedSubFile.pushlinesys�������5�!rc��|Sr�rs r�__iter__zBufferedSubFile.__iter__|s���rc�<�|j�}|dk(rt�|Sr')r.�
StopIterationr0s  r�__next__zBufferedSubFile.__next__s���}�}����2�:����rN)�__name__�
__module__�__qualname__�__doc__rrrr%r.r1r9r"r?rBr>rrrr,s9���	�$�$���$%�
�*"��rrc�N�eZdZdZd
ed�d�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
y)rzA feed-style parser of email.N��policyc�r�||_d|_|�,|j�ddlm}||_n-|j|_n||_	||j��t�|_g|_	|j�j|_d|_
d|_d|_y#t$r
d|_Y�]wxYw)a_factory is called with no arguments to create a new message obj

        The policy keyword specifies a policy object that controls a number of
        aspects of the parser's operation.  The default policy maintains
        backward compatibility.

        FNr)�MessagerHT)rI�_old_style_factory�message_factory�
email.messagerK�_factory�	TypeErrorr�_input�	_msgstack�	_parsegenrB�_parse�_cur�_last�_headersonly)rrOrIrKs    rrzFeedParser.__init__�s������"'������%�%�-�1� '��
� &� 6� 6��
�$�D�M�
/�����,�&�'�������n�n�&�/�/�����	���
�!�����
/�*.��'�
/�s�B#�#B6�5B6c��d|_y)NT)rWrs r�_set_headersonlyzFeedParser._set_headersonly�s
�� ��rc�Z�|jj|�|j�y)zPush more data into the parser.N)rQr9�_call_parse)rr7s  r�feedzFeedParser.feed�s ������������rc�D�	|j�y#t$rYywxYwr)rTrArs rr[zFeedParser._call_parse�s"��	��K�K�M���	��	�s��	�c�8�|jj�|j�|j�}|j	�dk(rL|j�s<|js0tj�}|jj||�|S)z<Parse all remaining data and return the root message object.�	multipart)rQr%r[�_pop_message�get_content_maintype�is_multipartrWr�!MultipartInvariantViolationDefectrI�
handle_defect)r�root�defects   rr%zFeedParser.close�sz������������� � �"���$�$�&�+�5��(�(�*�4�3D�3D��=�=�?�F��K�K�%�%�d�F�3��rc��|jr|j�}n|j|j��}|jr.|jj	�dk(r|jd�|jr|jdj|�|jj|�||_||_	y)NrHzmultipart/digestzmessage/rfc822r4)
rLrOrIrU�get_content_type�set_default_typerR�attachrrV)r�msgs  r�_new_messagezFeedParser._new_message�s����"�"��-�-�/�C��-�-�t�{�{�-�3�C��9�9����3�3�5�9K�K�� � �!1�2��>�>��N�N�2��%�%�c�*������c�"���	���
rc��|jj�}|jr|jd|_|Sd|_|S)Nr4)rRrrU)r�retvals  rr`zFeedParser._pop_message�s@�����#�#�%���>�>����r�*�D�I��
��D�I��
rc#�BK�|j�g}|jD]�}|tur	t���tj	|�slt
j	|�sUt
j�}|jj|j|�|jj|�n|j|���|j|�|jrug}	|jj�}|tur	t���,|dk(rn|j|��C|jj!t"j%|��y|jj'�dk(r�	|jj)t
j�|j+�D]}|tur	t���n|j-�|jj/�	|jj�}|tur	t���,		|jj�}|tur	t���,	|dk(r	y|jj|���|jj1�dk(r8|j+�D]}|tur	t���n|j-�y|jj1�dk(�r�|jj3�}|��t
j4�}|jj|j|�g}|jD]$}|tur	t���|j|��&|jj!t"j%|��yt7|jj9dd��j;�dvr:t
j<�}|jj|j|�d	|z}t?j@d
t?jB|�zdz�}d}	g}
d}d}	|jj�}|tur	t���,|dk(r�n�|j	|�}
|
�r�|
jEd
�rd}|
jEd�}�ny|	r�|
ra|
d}tFjI|�}|r!|dtK|jEd��|
d<t"j%|
�|j_&d}	|jj|���	|jj�}|tur	t���,|j	|�}
|
s|jj|�n�[|jj)|j�|j+�D]}|tur	t���n|jNj1�dk(rv|jNjP}|dk(rd|jN_(n�|��tFjI|�}
|
r�tK|
jEd��}|d||jN_(nl|jNjR}tU|t6�rFtFjI|�}
|
r/|dtK|
jEd��}||jN_)|jj/�|j-�|j|_'n|
j|����|	r�t
jV�}|jj|j|�|jj!t"j%|
��g}|jD]}|tus�t���t"j%|�|j_(y|s;t
jX�}|jj|j|�y|rdg}ng}|jD]$}|tur	t���|j|��&|r<|d}tZj	|�}|r |tK|jEd��d|d<t"j%|�|j_(yg}|jD]$}|tur	t���|j|��&|jj!t"j%|��y�w)NTr	zmessage/delivery-status�messager_zcontent-transfer-encoding�8bit)�7bitrq�binaryz--z(?P<sep>z4)(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$F�end�linesepr4r).rlrQr(�headerRE�match�NLCREr� MissingHeaderBodySeparatorDefectrIrdrUr1r�_parse_headersrWr.�set_payload�EMPTYSTRING�joinrhrrSr`rra�get_boundary�NoBoundaryInMultipartDefect�str�get�lower�-InvalidMultipartContentTransferEncodingDefect�re�compile�escape�group�	NLCRE_eol�search�len�preamblerV�epilogue�_payload�
isinstance�StartBoundaryNotFoundDefect�CloseBoundaryNotFoundDefect�	NLCRE_bol)r�headersr,rfr<rn�boundary�	separator�
boundaryre�capturing_preambler�ru�close_boundary_seen�mo�lastline�eolmor�rt�payload�	firstline�bolmos                     rrSzFeedParser._parsegen�s������������K�K�D��|�#�"�"���>�>�$�'��{�{�4�(�#�D�D�F�F��K�K�-�-�d�i�i��@��K�K�*�*�4�0���N�N�4� � � 	
���G�$�����E���{�{�+�+�-���<�'�&�&���2�:�����T�"��
�I�I�!�!�+�"2�"2�5�"9�:���9�9�%�%�'�+D�D�����,�,�U�[�[�9�"�n�n�.�F���-�*�*� ��	/�
�!�!�#����+�+�-�
��;�;�/�/�1�D��|�+�*�*� ����;�;�/�/�1�D��|�+�*�*� ���2�:��
����&�&�t�,�?�B�9�9�)�)�+�y�8��.�.�*���\�)�&�&���	+�

������9�9�)�)�+�{�:��y�y�-�-�/�H���
 �;�;�=�����)�)�$�)�)�V�<��� �K�K�D��|�+�*�*� ��L�L��&�	(�
�	�	�%�%�k�&6�&6�u�&=�>���D�I�I�M�M�"=�v�F�G�M�M�O�5�6��M�M�O�����)�)�$�)�)�V�<�
�x��I�����R�Y�Y�y�1�1�G�H�I�J�"&���H��G�"'����{�{�+�+�-���<�'�&�&���2�:���%�%�d�+���
�x�x���.2�+�"$�(�(�9�"5���)�#�(0��|�H�$-�$4�$4�X�$>�E�$�/7�8M�#�e�k�k�!�n�:M�9M�/N����1<�1A�1A�(�1K�D�I�I�.�-2�*����.�.�t�4� �
�#�{�{�3�3�5���<�/�".�.�$�'�-�-�d�3��!� �K�K�2�2�4�8�!���K�K�0�0��1A�1A�B�"&�.�.�"2��!�\�1�".�.�$��	#3��z�z�6�6�8�K�G�#'�:�:�#6�#6��#�r�>�26�D�J�J�/�%�1�!*�!1�!1�(�!;�B�!�&)�"�(�(�1�+�&6��6>�u���o��
�
� 3�"&�*�*�"5�"5��%�g�s�3�!*�!1�!1�'�!:�B�!�*1�2D�C������4D�3D�*E��6=��
�
� 3��K�K�/�/�1��%�%�'�"&���D�J��O�O�D�)�_�f"��;�;�=�����)�)�$�)�)�V�<��	�	�%�%�k�&6�&6�x�&@�A��� �K�K�D��|�+�*�*� �(�&1�%5�%5�h�%?��	�	�"��'��;�;�=�����)�)�$�)�)�V�<����4���������<�'�&�&������%�	$��$�Q�K�	�!���	�2���"+�C����A��,?�,@�"A�H�Q�K�!,�!1�!1�(�!;�D�I�I������K�K�D��|�#�"�"���L�L���	 �
	
�	�	���k�.�.�u�5�6�s
�^.d�1E.dc��d}g}t|�D�]�\}}|ddvrP|s<tj|�}|jj	|j
|��L|j
|��^|r6|j
j|jj|��dg}}|jd�r�|dk(rQtj|�}|r|dt|jd��}|j
j|���|t|�dz
k(r|jj!|�ytj"|�}|j
j$j
|���g|j'd�}|dk(r<tj(d�}|j
j$j
|����|d|}|g}���|r3|j
j|jj|��yy)Nr	rz 	zFrom ��:zMissing header name.)�	enumerater�#FirstHeaderLineIsContinuationDefectrIrdrUr�set_raw�header_source_parse�
startswithr�r�r�r��set_unixfromrQr1�MisplacedEnvelopeHeaderDefect�defects�find�InvalidHeaderDefect)	rr<�
lastheader�	lastvalue�linenor,rfr��is	         rrzzFeedParser._parse_headers�s����
��	�%�e�,�L�F�D��A�w�%��!�$�G�G��M�F��K�K�-�-�d�i�i��@��� � ��&���!��	�	�!�!�4�;�;�#B�#B�9�#M�N�(*�B�I�
����w�'��Q�;�"�)�)�$�/�B��#�$6�c�"�(�(�1�+�&6�%6�7���I�I�*�*�4�0���s�5�z�A�~�-��K�K�*�*�4�0��$�A�A�$�G�F��I�I�%�%�,�,�V�4���	�	�#��A�
�A�v��3�3�4J�K���	�	�!�!�(�(��0���b�q��J���I�g-�j��D�I�I���t�{�{�>�>�y�I�J�rr)rCrDrErFrrrYr\r[r%rlr`rSrzr>rrrr�s<��'�"��"�>!��
����{7�z:Krc�"��eZdZdZ�fd�Z�xZS)rz(Like FeedParser, but feed accepts bytes.c�D��t�|�|jdd��y)N�ascii�surrogateescape)�superr\�decode)rr7�	__class__s  �rr\zBytesFeedParser.feeds���
���T�[�[��*;�<�=r)rCrDrErFr\�
__classcell__)r�s@rrrs���2�>�>r)rF�__all__r��emailr�email._policybaser�collectionsr�iorr�rxr�r��NLCRE_crackrvr|�NL�objectr(rrrr>rr�<module>r�s���
�"�*�
+��	��&�����
�
�=�!���B�J�J��'�	��B�J�J�(�)�	��b�j�j��)���2�:�:�>�?����	���x��W�f�W�tIK�IK�X>�j�>r__pycache__/generator.cpython-312.opt-2.pyc000064400000042251151706203560014416 0ustar00�

��i�S���	gd�ZddlZddlZddlZddlZddlmZddlmZm	Z	ddl
mZddlm
Z
dZdZej d	�Zej d
ej$�Zej d�Zej d�ZGd
�d�ZGd�de�ZdZGd�de�Zeeej8dz
��ZdezZej>Zy))�	Generator�DecodedGenerator�BytesGenerator�N)�deepcopy)�StringIO�BytesIO)�_has_surrogates)�HeaderWriteError�_�
z
\r\n|\r|\nz^From z\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]s\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]c��eZdZ	ddd�d�Zd�Zdd�Zd�Zd�Zd�Zd	�Z	d
�Z
d�Zd�Zd
�Z
e
Zd�Zd�Zd�Zd�Zedd��Zed��Zy)rN��policyc�b�	|�|�dn|j}||_||_||_||_y)NT)�mangle_from_�_fp�
_mangle_from_�maxheaderlenr)�self�outfprrrs     �(/usr/lib64/python3.12/email/generator.py�__init__zGenerator.__init__&s>��	�.��#)�>�4�v�7J�7J�L����)���(������c�:�|jj|�y�N)r�write�r�ss  rrzGenerator.writeFs�������q�rc���	|j�|jn|j}|�|j|��}|j�|j|j��}|j|_|j|j�|_d|_|j|j�|_|j}|j}	||_||_|rZ|j�}|s*dtjtj��z}|j||jz�|j|�||_||_y#||_||_wxYw)N)�linesep��max_line_length�zFrom nobody )r�clonerr �_NL�_encode�_encoded_NL�_EMPTY�_encoded_EMPTY�get_unixfrom�time�ctimer�_write)r�msg�unixfromr r�old_gen_policy�old_msg_policy�ufroms        r�flattenzGenerator.flattenJs*��	�( $�{�{�2�����������\�\�'�\�2�F����(��\�\�$�2C�2C�\�D�F��>�>����<�<����1������"�l�l�4�;�;�7���
��������	(� �D�K��C�J���(�(�*���*�T�Z�Z��	�	��-D�D�E��
�
�5�4�8�8�+�,��K�K���(�D�K�'�C�J��)�D�K�'�C�J�s
�A;E�E-c�V�	|j||jd|j��S�Nr)�	__class__rr)r�fps  rr$zGenerator.clone{s0��?��~�~�b�"�0�0�"�%)�[�[��2�	2rc��t�Sr)r�rs r�_new_bufferzGenerator._new_buffer�s
���z�rc��|Sr�rs  rr&zGenerator._encode�s���rc���|sytj|�}|ddD].}|j|�|j|j��0|dr|j|d�yy)N���)�NLCRE�splitrr%)r�lines�lines   r�_write_lineszGenerator._write_lines�s`�������E�"���#�2�J�D��J�J�t���J�J�t�x�x� ����9��J�J�u�R�y�!�rc� �|j}	d|_|j�x|_}|j|�||_|j}|`|rOt	|�}|jd��	|d|d<n|j
d|d�|j
d|d�t|dd�}|�|j|�n||�|jj|j��y#||_|j}|`wxYw)N�content-transfer-encodingr�Content-Transfer-Encoding�content-type��_write_headers)r�
_munge_cter:�	_dispatchr�get�replace_header�getattrrIr�getvalue)rr.�oldfp�sfp�	munge_cte�meths      rr-zGenerator._write�s�������	 �"�D�O�!�-�-�/�/�D�H�s��N�N�3���D�H����I�����3�-�C��w�w�2�3�;�3<�Q�<��/�0��"�"�#>�	�!��M����~�y��|�<��s�,�d�3���<�����$���J������s�|�|�~�&��'�D�H����I���s�/C6�6D
c�&�|j�}|j�}tj||f�j	dd�}t|d|zd�}|�0|j	dd�}t|d|zd�}|�|j}||�y)N�-r�_handle_)�get_content_maintype�get_content_subtype�
UNDERSCORE�join�replacerN�
_writeBody)rr.�main�sub�specificrS�generics       rrKzGenerator._dispatch�s���
�'�'�)���%�%�'���?�?�D�#�;�/�7�7��S�A���t�Z�(�2�D�9���<��l�l�3��,�G��4��g�!5�t�<�D��|������S�	rc���|j�D]�\}}|jj||�}|jjr~|jj}|j|jj�st
d|�d|����tj|j|��rt
d|����|j|���|j|j�y�Nz folded header does not end with z: z folded header contains newline: )�	raw_itemsr�fold�verify_generated_headersr �endswithr
�NEWLINE_WITHOUT_FWSP�search�removesuffixrr%�rr.�h�v�foldedr s      rrIzGenerator._write_headers�s����M�M�O�D�A�q��[�[�%�%�a��+�F��{�{�3�3��+�+�-�-�����t�{�{�':�':�;�*�:�7�+�R��z�R�T�T�'�.�.�v�/B�/B�7�/K�L�*�:�6�*�E�G�G��J�J�v��$�	
�
�
�4�8�8�rc��|j�}|�yt|t�stdt	|�z��t|j�r\|jd�}|�It|�}|d=|j|j|�|j�}|d|df|_
|jrtjd|�}|j|�y)Nzstring payload expected: %s�charsetrErG�>From )�get_payload�
isinstance�str�	TypeError�typer	�_payload�	get_paramr�set_payloadrJr�fcrer^rC)rr.�payloadros    r�_handle_textzGenerator._handle_text�s����/�/�#���?���'�3�'��9�D��M�I�J�J��3�<�<�(��m�m�I�.�G��"��s�m���3�4�������g�6��/�/�+��#&�'B�#C�#&�~�#6�#8�������h�h�x��1�G����'�"rc�0�g}|j�}|�g}n5t|t�r|j|�yt|t�s|g}|D]`}|j�}|j
|�}|j|d|j��|j|j���b|j�}|s=|jj|�}|j|�}|j|�|j �e|j"r!t$j'd|j �}	n|j }	|j)|	�|j|j�|jd|z|jz�|r*|j*j|j-d��|D]K}
|j|jdz|z|jz�|j*j|
��M|j|jdz|zdz|jz�|j.�K|j"r!t$j'd|j.�}n|j.}|j)|�yy)NF�r/r rpz--r)rqrrrsr�listr:r$r3r%�appendrO�get_boundaryr'rZ�_make_boundary�set_boundary�preamblerryr^rCr�pop�epilogue)rr.�msgtexts�subparts�partr�g�boundary�alltextr��	body_partr�s            r�_handle_multipartzGenerator._handle_multipart
s�����?�?�$�����H�
��#�
&��J�J�x� ���H�d�+� �z�H��D�� � �"�A��
�
�1�
�A�
�I�I�d�U�D�H�H�I�=��O�O�A�J�J�L�)�	��#�#�%����&�&�+�+�H�5�G��*�*�7�3�H����X�&��<�<�#��!�!��8�8�H�c�l�l�;���<�<�����h�'��J�J�t�x�x� ��
�
�4�(�?�T�X�X�-�.���H�H�N�N�8�<�<��?�+�"�I��J�J�t�x�x�$���1�D�H�H�<�=��H�H�N�N�9�%�	"�	
�
�
�4�8�8�d�?�X�-��4�t�x�x�?�@��<�<�#��!�!��8�8�H�c�l�l�;���<�<�����h�'�$rc��|j}|jd��|_	|j|�||_y#||_wxYw)Nrr!)rr$r�)rr.�ps   r�_handle_multipart_signedz"Generator._handle_multipart_signedGsA��
�K�K���g�g�a�g�0���	��"�"�3�'��D�K��!�D�K�s	�>�	Ac��g}|j�D]�}|j�}|j|�}|j|d|j��|j�}|j
|j�}|r@|d|jk(r.|j|jj|dd����|j|���|jj|jj|��y)NFr}r>)
rqr:r$r3r%rOr@r'r)rrZrr)rr.�blocksr�rr��textrAs        r�_handle_message_delivery_statusz)Generator._handle_message_delivery_statusRs������O�O�%�D�� � �"�A��
�
�1�
�A�
�I�I�d�U�D�H�H�I�=��:�:�<�D��J�J�t�/�/�0�E���r��d�&9�&9�9��
�
�d�.�.�3�3�E�#�2�J�?�@��
�
�d�#�&�	
�����t�'�'�,�,�V�4�5rc�R�|j�}|j|�}|j}t|t�r>|j|j
d�d|j��|j�}n|j|�}|jj|�y)NrFr})r:r$rvrrr~r3rqr%rOr&rr)rr.rr�rzs     r�_handle_messagezGenerator._handle_messagegsz��������J�J�q�M���,�,���g�t�$�
�I�I�c�o�o�a�(�5�$�(�(�I�K��j�j�l�G��l�l�7�+�G������w�rc�@�tjtj�}dt|zzdz}|�|S|}d}	|jdt
j|�zdztj�}|j|�s	|S|dzt|�z}|dz
}�d)Nz===============z==rz^--z(--)?$�.rH)�random�	randrange�sys�maxsize�_fmt�_compile_re�re�escape�	MULTILINErhrs)�clsr��tokenr��b�counter�cres       rr�zGenerator._make_boundary�s���� � ����-������.��5���<��O�������/�/�%�"�)�)�A�,�"6��"A�2�<�<�P�C��:�:�d�#�����3���W��-�A��q�L�G�rc�.�tj||�Sr)r��compile�r�r�flagss   rr�zGenerator._compile_re�s���z�z�!�U�#�#r)NN)FNr)�__name__�
__module__�__qualname__rrr3r$r:r&rCr-rKrIr{r\r�r�r�r��classmethodr�r�r<rrrrs�������@�/(�b2�(��	"� %'�N�(
�&#�,�J�8(�t	�6�* �2����"�$��$rrc�L��eZdZ	d�Zd�Zd�Zd�Z�fd�ZeZe	d��Z
�xZS)rc�Z�|jj|jdd��y)N�ascii�surrogateescape)rr�encoders  rrzBytesGenerator.write�s�������q�x�x��):�;�<rc��t�Sr)rr9s rr:zBytesGenerator._new_buffer�s
���y�rc�$�|jd�S�Nr�)r�rs  rr&zBytesGenerator._encode�s���x�x�� � rc���|j�D]�\}}|jj||�}|jjrx|jjj�}|j
|�std|�d|����tj|j|��rtd|����|jj|���|j|j�yrb)rcr�fold_binaryrer r�rfr
�NEWLINE_WITHOUT_FWSP_BYTESrhrirrr%rjs      rrIzBytesGenerator._write_headers�s����M�M�O�D�A�q��[�[�,�,�Q��2�F��{�{�3�3��+�+�-�-�4�4�6�����w�/�*�:�7�+�R��z�R�T�T�-�4�4�V�5H�5H��5Q�R�*�:�6�*�E�G�G��H�H�N�N�6�"�$�	
�
�
�4�8�8�rc�<��|j�yt|j�rf|jjdk(sM|jr%t
j
d|j�|_|j|j�ytt|�+|�y)N�7bitrp)rvr	r�cte_typerryr^rC�superrr{)rr.r6s  �rr{zBytesGenerator._handle_text�so����<�<����3�<�<�(����1E�1E�v�1M��!�!�#�x�x��#�,�,�?������c�l�l�+��.��3�C�8rc�L�tj|jd�|�Sr�)r�r�r�r�s   rr�zBytesGenerator._compile_re�s���z�z�!�(�(�7�+�U�3�3r)r�r�r�rr:r&rIr{r\r�r��
__classcell__)r6s@rrr�s:���
�=��!��"
9��J��4��4rrzD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c�"�eZdZ	ddd�d�Zd�Zy)rNrc�d�	tj|||||��|�t|_y||_yr5)rr�_FMTr�)rrrr�fmtrs      rrzDecodedGenerator.__init__�s:��	�*	���4���l�"(�	�	*��;��D�I��D�Irc
��|j�D]�}|j�}|dk(rt|jd��|���6|dk(r�<t|j|j�|j�|j
�|jd�|jdd�|jd	d
�d�z|����y)Nr�F)�decode)�file�	multipartz
[no filename]zContent-Descriptionz[no description]rFz
[no encoding])ru�maintype�subtype�filename�description�encoding)	�walkrW�printrqr��get_content_typerX�get_filenamerL)rr.r�r�s    rrKzDecodedGenerator._dispatch�s����H�H�J�D��0�0�2�H��6�!��d�&�&�e�&�4�4�@��[�(���d�i�i�#'�#8�#8�#:�#'�#<�#<�#>�#'�#;�#;�#=�#'�#4�#4�_�#E�#'�8�8�,A�,>�$@�#'�8�8�,G�,;�$=�	#�	�!�	"�r)NNN)r�r�r�rrKr<rrrr�s���
���<"rrrHz%%0%dd) �__all__r�r�r+r��copyr�iorr�email.utilsr	�email.errorsr
rY�NLr�r?r�ryrgr�rrr�r�len�reprr��_widthr�r�r<rr�<module>r�s���
A�
=��	�
��
�� �'�)�
�
�	����
�
�=�!���r�z�z�)�R�\�\�*��!�r�z�z�"C�D��'�R�Z�Z�(J�K��x$�x$�v84�Y�84�vN��6"�y�6"�t

�T�#�+�+�a�-�
 �	!���&����)�)�r__pycache__/header.cpython-312.opt-2.pyc000064400000044771151706203560013671 0ustar00�

T��h^���	gd�ZddlZddlZddlZddlZddlmZddlmZ	e	jZ
dZdZdZ
dZd	Zd
ZdZe
d�Ze
d
�Zej(dej*ej,z�Zej(d�Zej(d�Zej4j6Zd�Z		dd�ZGd�d�ZGd�d�ZGd�de �Z!y))�Header�
decode_header�make_header�N)�HeaderParseError)�charset�
� � z        ��Nz 	�us-asciizutf-8ai
  =\?                   # literal =?
  (?P<charset>[^?]*?)   # non-greedy up to the next ? is the charset
  \?                    # literal ?
  (?P<encoding>[qQbB])  # either a "q" or a "b", case insensitive
  \?                    # literal ?
  (?P<encoded>.*?)      # non-greedy up to the next ?= is the encoded string
  \?=                   # literal ?=
  z[\041-\176]+:$z
\n[^ \t]+:c
��	t|d�rG|jD��cgc]/\}}tj|t	|��t	|�f��1c}}St
j
|�s|dfgSg}|j�D]�}t
j|�}d}|s�|jd�}|r|j�}d}|r|j|ddf�|rc|jd�j�}|jd�j�}|jd�}	|j|	||f�|r����g}
t|�D]K\}}|dkDs�|ds�||dz
ds�||dz
dj�s�8|
j|dz
��Mt|
�D]}
||
=�g}|D]�\}}}|�|j||f��|dk(r3t j"j%|�}|j||f��U|dk(rOt'|�d	z}|r|d
dd	|z
z
}	t j(j+|�}|j||f���t3d|z��g}dx}}|D]Y\}}t5|t�rt7|d
�}|�|}|}�)||k7r|j||f�|}|}�F|�
|t8|zz
}�U||z
}�[|j||f�|Scc}}w#t,j.$rt1d��wxYw)N�_chunksTrF���q�b�z===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)�hasattrr�_charset�_encode�str�ecre�search�
splitlines�split�pop�lstrip�append�lower�	enumerate�isspace�reversed�email�
quoprimime�
header_decode�len�
base64mime�decode�binascii�Errorr�AssertionError�
isinstance�bytes�BSPACE)�header�stringr�words�line�parts�first�	unencoded�encoding�encoded�droplist�n�w�d�
decoded_words�encoded_string�word�paderr�	collapsed�	last_word�last_charsets                     �%/usr/lib64/python3.12/email/header.pyrr;s=����v�y�!�+1�>�>�;�+9�����!�!�&�#�g�,�7��W��F�+9�;�	;��;�;�v�������
�E��!�!�#���
�
�4� ������	�	�!��I��%�,�,�.�	�������i��t�4�5���)�)�A�,�,�,�.�� �9�9�Q�<�-�-�/���)�)�A�,�����g�x��9�:��$�"�H��%� ���1��Q�3�1�Q�4�E�!�A�#�J�q�M�e�A�a�C�j��m�.C�.C�.E��O�O�A�a�C� �!��h�
���!�H� ��M�-2�)���'���� � �.�'�!:�;�
��_��#�#�1�1�.�A�D�� � �$���1�
��_���(�1�,�F���%���V��"4�4��
6��'�'�.�.�~�>���$�$�d�G�_�5� �!8�8�!C�D�D�%.3�*�I�#�#�I��&�
��g��d�C� ���3�4�D����I�"�L�
��
$����i��6�7��I�"�L�
�
!���$��&�I����I�'����i��.�/����W;��d�>�>�
@�&�'>�?�?�
@�s�4K&�+K,�,Lc��	t|||��}|D]4\}}|�t|t�st|�}|j||��6|S)N)�
maxlinelen�header_name�continuation_ws)rr-�Charsetr)�decoded_seqrFrGrH�h�srs       rDrr�sV��	�	�*�+�.�	0�A�!�
��7���z�'�7�'C��g�&�G�	����G��	"�

�H�c�B�eZdZ			d	d�Zd�Zd�Zd
d�Zd�Zdd�Zd�Z	y)rNc��	|�t}nt|t�st|�}||_||_g|_|�|j
|||�|�t}||_|�d|_	yt|�dz|_	y)Nrr)�USASCIIr-rIr�_continuation_wsrr�
MAXLINELEN�_maxlinelen�
_headerlenr')�selfrLrrFrGrH�errorss       rD�__init__zHeader.__init__�s���	�4�?��G��G�W�-��g�&�G���
� /�������=��K�K��7�F�+���#�J�%������D�O�"�+�.��2�D�OrMc��	|j�g}d}d}|jD]�\}}|}|tjk(r$|j	dd�}|jdd�}|rU|xr|j
|d�}|dvr|dvr5|s3|jt�d}n|dvr|s|jt�|xr|j
|d�}|}|j|���tj|�S)N�ascii�surrogateescape�replacer�Nr
���)�
_normalizerr�UNKNOWN8BIT�encoder)�	_nonctextr�SPACE�EMPTYSTRING�join)	rU�uchunks�lastcs�	lastspacer1r�nextcs�original_bytes�hasspaces	         rD�__str__zHeader.__str__�s���4����������	�#�|�|�O�F�G��F���-�-�-�!'���w�8I�!J��'�.�.�w�	�B���!�?�d�n�n�V�A�Y�&?���!3�3��!3�3�H����u�-�!%���#5�5�i��N�N�5�)��=�4�>�>�&��*�#=�I��F��N�N�6�"�+ ,�,����(�(rMc��|t|�k(S�N)r)rU�others  rD�__eq__z
Header.__eq__�s����D�	�!�!rMc���	|�
|j}nt|t�st|�}t|t�sH|jxsd}|tj
k(r|j
dd�}n|j
||�}|jxsd}|tj
k7r	|j||�|jj||f�y#t$r|dk7r�t}Y�5wxYw)Nr
rZ)
rr-rIr�input_codecr_r)�output_codecr`�UnicodeEncodeError�UTF8rr)rUrLrrV�
input_charset�output_charsets      rDrz
Header.appends���	�(�?��m�m�G��G�W�-��g�&�G��!�S�!�#�/�/�=�:�M��� 4� 4�4��H�H�Z�):�;���H�H�]�F�3��!�-�-�;����X�1�1�1�
������0�
	
�����Q��L�)��	&�
�!�:�-����
�s�(C�C0�/C0c�0�	|j�xs|dvS)N)�(�)�\)r")rUrLs  rDrazHeader._nonctext0s��	��y�y�{�3�a�#3�3�3rMc�0�	|j�|�|j}|dk(rd}t|j||j|�}d}dx}}|j
D�][\}}	|�I|xr|j
|d�}|dvr|r|	dvr'|j�n|	dvr|s|j�|xr|j
|d�}|	}d}|j�}
|
r|jd|
d|	�n|jdd|	�|
ddD]�}|j�|	j�/|j|jd|j�z|	��N|j�}|dt|�t|�z
}
|j|
||	���t|
�dkDs��L|j���^|j
r|j�|j|�}tj!|�rt#d	j%|���|S)
Nri@Br\r]Frrr	z8header value appears to contain an embedded header: {!r})r^rS�_ValueFormatterrTrQrra�add_transitionr�feed�newline�header_encodingrr'�_str�_embedded_headerrr�format)rU�
splitcharsrF�linesep�	formatterrfrjrgr1r�linesr3�sline�fws�values               rDr`z
Header.encode5s	��	�@	
�������)�)�J���?� �J�#�D�O�O�Z�$(�$9�$9�:�G�	���#�#��9�#�|�|�O�F�G��#�!�?�d�n�n�V�A�Y�&?���!3�3�#�w�6H�'H�!�0�0�2��$6�6�y��,�,�.��=�4�>�>�&��*�#=�I��F��H��%�%�'�E�����r�5��8�W�5����r�2�w�/��a�b�	���!�!�#��*�*�6��N�N�4�#8�#8�#����
�:M�#*�,�!�K�K�M�E��4��D�	�#�e�*� 4�5�C��N�N�3��w�7�"��5�z�A�~��!�!�#�5 ,�6�<�<��$�$�&����w�'���"�"�5�)�"�$+�+1�6�%�=�:�
:��rMc��g}d}g}|jD]I\}}||k(r|j|��|�&|jtj|�|f�|g}|}�K|r&|jtj|�|f�||_yrm)rrrbrd)rU�chunksrC�
last_chunkr1rs      rDr^zHeader._normalize�s��������
�#�|�|�O�F�G��,�&��!�!�&�)��+��M�M�5�:�:�j�#9�<�"H�I�$�X�
�&�� ,���M�M�5�:�:�j�1�<�@�A���rM)NNNNr	�strict)Nr�)z;, 	Nr)
�__name__�
__module__�__qualname__rWrkrorrar`r^�rMrDrr�s3��'+�.2�-5�-3�^)�@"�)*�V4�
N�`rMrc�B�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)r|c�|�||_||_t|�|_||_g|_t
|�|_yrm)�_maxlenrQr'�_continuation_ws_len�_splitchars�_lines�_Accumulator�
_current_line)rU�	headerlen�maxlenrHr�s     rDrWz_ValueFormatter.__init__�s:����� /���$'��$8��!�%������)�)�4��rMc�X�|j�|j|j�Srm)rrdr�)rUr�s  rDr�z_ValueFormatter._str�s�������|�|�D�K�K�(�(rMc�,�|jt�Srm)r��NL�rUs rDrkz_ValueFormatter.__str__�s���y�y��}�rMc���|jj�}|dk7r|jj|�t|j�dkDr|jj	�r7|j
r+|j
dxxt
|j�z
cc<n.|j
jt
|j��|jj�y)N)r	rrr])	r�r�pushr'�	is_onlywsr�rr�reset)rU�end_of_lines  rDrz_ValueFormatter.newline�s����(�(�,�,�.���)�#�#�D���#�#�[�1��t�!�!�"�Q�&��!�!�+�+�-�$�+�+����B��3�t�'9�'9�#:�:�����"�"�3�t�'9�'9�#:�;���� � �"rMc�<�|jjdd�y)Nr	r)r�r�r�s rDr}z_ValueFormatter.add_transition�s��������R�(rMc��|j�|j|||j�y|j||j	��}	|jd�}|�|j||�	|j�}|j�|jj|j|�|D]*}|jj|j|z��,y#t$rYywxYw#t$rYywxYw�Nr)r��_ascii_splitr��header_encode_lines�_maxlengthsr�
IndexError�
_append_chunkrr�r�rQr�r)rUr�r1r�
encoded_lines�
first_line�	last_liner3s        rDr~z_ValueFormatter.feed�s����"�"�*����c�6�4�+;�+;�<�� �3�3�F�D�<L�<L�<N�O�
�	�&�*�*�1�-�J��!����s�J�/�	�%�)�)�+�I�	
���������� 5� 5�y�A�!�D��K�K���t�4�4�t�;�<�"���	��	���	��	�s$�C(�2C7�(	C4�3C4�7	D�Dc#�K�|jt|j�z
��	|j|jz
����wrm)r�r'r�r�r�s rDr�z_ValueFormatter._maxlengths�s=�����l�l�S��!3�!3�4�4�4���,�,��!:�!:�:�:��s�AAc���tjdtzdz||z�}|drdg|ddn|jd�t	t|�gdz�D]\}}|j
||��y)Nz([z]+)rrr)�rer�FWSr�zip�iterr�)rUr�r1r�r4�parts      rDr�z_ValueFormatter._ascii_split�sl������c��%���V��4����8���E�"�1�I��I�I�a�L��t�E�{�m�A�o�.�I�C�����s�D�)�/rMc�:�|jj||�t|j�|jkD�r\|jD]�}t|jj
�dz
dd�D]R}|j�r|j|d}|r
|d|k(rn%|j|dz
d}|s�I|d|k(s�Rn��nh|jj�\}}|jjdkDr|j�|sd}|jj||�y|jj|�}|jjt|j��|jj|�yy)Nrrr]r	)r�r�r'r�r��range�
part_countr"r�
_initial_sizer�pop_fromr�rrr�)rUr�r1�ch�i�prevpartr��	remainders        rDr�z_ValueFormatter._append_chunk�so��������V�,��t�!�!�"�T�\�\�1��&�&���t�1�1�<�<�>�q�@�!�R�H�A��z�z�|�"�0�0��3�A�6���3�q�6�2�:�!�#�1�1�!�A�#�6�q�9�H��H�R�L�"�$4��I���'�!�.�.�2�2�4�	��T��%�%�3�3�a�7��L�L�N��"���"�"�'�'��T�2���*�*�3�3�A�6�I��K�K���s�4�#5�#5�6�7����$�$�Y�/�92rMN)r�r�r�rWr�rkrr}r~r�r�r�r�rMrDr|r|�s0��5�)��	#�)�#=�J;�*�,0rMr|c�\��eZdZd
�fd�	Zd�Zd
d�Z�fd�Zd�Zd�Zdd�Z	d�Z
�fd	�Z�xZS)r�c�0��||_t�|�	�yrm)r��superrW)rU�initial_size�	__class__s  �rDrWz_Accumulator.__init__s���)���
���rMc�*�|j||f�yrm)r)rUr�r1s   rDr�z_Accumulator.pushs�����S�&�M�"rMc��||d}g||d|Srmr�)rUr��poppeds   rDr�z_Accumulator.pop_from!s���a�b�����Q�R���
rMc�H��|j�dk(ryt�|�	�S)Nr)rr)r�r�r�rUr�s �rDrz_Accumulator.pop&s!����?�?��a����w�{�}�rMc�<�td�|D�|j�S)Nc3�PK�|]\}}t|�t|�z��� y�wrm)r'��.0r�r�s   rD�	<genexpr>z'_Accumulator.__len__.<locals>.<genexpr>,s"����=��9�3��C��H�S��Y�&����$&)�sumr�r�s rD�__len__z_Accumulator.__len__+s ���=��=��%�%�'�	'rMc�:�tjd�|D��S)Nc3�PK�|]\}}tj||f���� y�wrm�rcrdr�s   rDr�z'_Accumulator.__str__.<locals>.<genexpr>0s+����!7�15�I�C��"-�!1�!1�3��+�!>�15�r�r�r�s rDrkz_Accumulator.__str__/s"�����!7�15�!7�8�	8rMc�$�|�g}||ddd|_yr�)r�)rU�startvals  rDr�z_Accumulator.reset3s�����H���Q����rMc�`�|jdk(xr|xst|�j�Sr�)r�rr"r�s rDr�z_Accumulator.is_onlyws9s,���!�!�1�$�J�d�(�*I�c�$�i�6G�6G�6I�JrMc� ��t�|��Srm)r�r�r�s �rDr�z_Accumulator.part_count<s����w�� � rM)rrm)
r�r�r�rWr�r�rr�rkr�r�r��
__classcell__)r�s@rDr�r�s6����#��
�
'�8��K�!�!rMr�)NNr	)"�__all__r�r*�email.quoprimimer$�email.base64mime�email.errorsrrrrIr�rbr/�SPACE8rcrRr�rPrt�compile�VERBOSE�	MULTILINEr�fcrer�r%�_max_appendrrrr|�listr�r�rMrD�<module>r�s��
2���
����)�%�
�
�
��	����	
��	����
�
���
�*�
���w����r�z�z��
�z�z�B�L�L� �"���r�z�z�#�$���2�:�:�m�,�����*�*��[�|;?� #�
�,f�f�R}0�}0�@%!�4�%!rM__pycache__/header.cpython-312.pyc000064400000057677151706203560012742 0ustar00�

T��h^���dZgd�ZddlZddlZddlZddlZddlmZddlm	Z
e
jZdZdZ
dZd	Zd
ZdZdZed
�Zed�Zej*dej,ej.z�Zej*d�Zej*d�Zej6j8Zd�Z		dd�ZGd�d�ZGd�d�Z Gd�de!�Z"y)z+Header encoding and decoding functionality.)�Header�
decode_header�make_header�N)�HeaderParseError)�charset�
� � z        ��Nz 	�us-asciizutf-8ai
  =\?                   # literal =?
  (?P<charset>[^?]*?)   # non-greedy up to the next ? is the charset
  \?                    # literal ?
  (?P<encoding>[qQbB])  # either a "q" or a "b", case insensitive
  \?                    # literal ?
  (?P<encoded>.*?)      # non-greedy up to the next ?= is the encoded string
  \?=                   # literal ?=
  z[\041-\176]+:$z
\n[^ \t]+:c
��t|d�rG|jD��cgc]/\}}tj|t	|��t	|�f��1c}}St
j
|�s|dfgSg}|j�D]�}t
j|�}d}|s�|jd�}|r|j�}d}|r|j|ddf�|rc|jd�j�}|jd�j�}|jd�}	|j|	||f�|r����g}
t|�D]K\}}|dkDs�|ds�||dz
ds�||dz
dj�s�8|
j|dz
��Mt|
�D]}
||
=�g}|D]�\}}}|�|j||f��|dk(r3t j"j%|�}|j||f��U|d	k(rOt'|�d
z}|r|ddd
|z
z
}	t j(j+|�}|j||f���t3d
|z��g}dx}}|D]Y\}}t5|t�rt7|d�}|�|}|}�)||k7r|j||f�|}|}�F|�
|t8|zz
}�U||z
}�[|j||f�|Scc}}w#t,j.$rt1d��wxYw)a;Decode a message header value without converting charset.

    Returns a list of (string, charset) pairs containing each of the decoded
    parts of the header.  Charset is None for non-encoded parts of the header,
    otherwise a lower-case string containing the name of the character set
    specified in the encoded string.

    header may be a string that may or may not contain RFC2047 encoded words,
    or it may be a Header object.

    An email.errors.HeaderParseError may be raised when certain decoding error
    occurs (e.g. a base64 decoding exception).
    �_chunksNTrF���q�b�z===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)�hasattrr�_charset�_encode�str�ecre�search�
splitlines�split�pop�lstrip�append�lower�	enumerate�isspace�reversed�email�
quoprimime�
header_decode�len�
base64mime�decode�binascii�Errorr�AssertionError�
isinstance�bytes�BSPACE)�header�stringr�words�line�parts�first�	unencoded�encoding�encoded�droplist�n�w�d�
decoded_words�encoded_string�word�paderr�	collapsed�	last_word�last_charsets                     �%/usr/lib64/python3.12/email/header.pyrr;s8���v�y�!�+1�>�>�;�+9�����!�!�&�#�g�,�7��W��F�+9�;�	;��;�;�v�������
�E��!�!�#���
�
�4� ������	�	�!��I��%�,�,�.�	�������i��t�4�5���)�)�A�,�,�,�.�� �9�9�Q�<�-�-�/���)�)�A�,�����g�x��9�:��$�"�H��%� ���1��Q�3�1�Q�4�E�!�A�#�J�q�M�e�A�a�C�j��m�.C�.C�.E��O�O�A�a�C� �!��h�
���!�H� ��M�-2�)���'���� � �.�'�!:�;�
��_��#�#�1�1�.�A�D�� � �$���1�
��_���(�1�,�F���%���V��"4�4��
6��'�'�.�.�~�>���$�$�d�G�_�5� �!8�8�!C�D�D�%.3�*�I�#�#�I��&�
��g��d�C� ���3�4�D����I�"�L�
��
$����i��6�7��I�"�L�
�
!���$��&�I����I�'����i��.�/����W;��d�>�>�
@�&�'>�?�?�
@�s�4K%�*K+�+L
c��t|||��}|D]4\}}|�t|t�st|�}|j||��6|S)a�Create a Header from a sequence of pairs as returned by decode_header()

    decode_header() takes a header value string and returns a sequence of
    pairs of the format (decoded_string, charset) where charset is the string
    name of the character set.

    This function takes one of those sequence of pairs and returns a Header
    instance.  Optional maxlinelen, header_name, and continuation_ws are as in
    the Header constructor.
    )�
maxlinelen�header_name�continuation_ws)rr-�Charsetr)�decoded_seqrFrGrH�h�srs       rDrr�sQ��	�*�+�.�	0�A�!�
��7���z�'�7�'C��g�&�G�	����G��	"�

�H�c�B�eZdZ			d	d�Zd�Zd�Zd
d�Zd�Zdd�Zd�Z	y)rNc��|�t}nt|t�st|�}||_||_g|_|�|j
|||�|�t}||_|�d|_	yt|�dz|_	y)aDCreate a MIME-compliant header that can contain many character sets.

        Optional s is the initial header value.  If None, the initial header
        value is not set.  You can later append to the header with .append()
        method calls.  s may be a byte string or a Unicode string, but see the
        .append() documentation for semantics.

        Optional charset serves two purposes: it has the same meaning as the
        charset argument to the .append() method.  It also sets the default
        character set for all subsequent .append() calls that omit the charset
        argument.  If charset is not provided in the constructor, the us-ascii
        charset is used both as s's initial charset and as the default for
        subsequent .append() calls.

        The maximum line length can be specified explicitly via maxlinelen. For
        splitting the first line to a shorter value (to account for the field
        header which isn't included in s, e.g. `Subject') pass in the name of
        the field in header_name.  The default maxlinelen is 78 as recommended
        by RFC 2822.

        continuation_ws must be RFC 2822 compliant folding whitespace (usually
        either a space or a hard tab) which will be prepended to continuation
        lines.

        errors is passed through to the .append() call.
        Nrr)�USASCIIr-rIr�_continuation_wsrr�
MAXLINELEN�_maxlinelen�
_headerlenr')�selfrLrrFrGrH�errorss       rD�__init__zHeader.__init__�s���:�?��G��G�W�-��g�&�G���
� /�������=��K�K��7�F�+���#�J�%������D�O�"�+�.��2�D�OrMc��|j�g}d}d}|jD]�\}}|}|tjk(r$|j	dd�}|jdd�}|rU|xr|j
|d�}|dvr|dvr5|s3|jt�d}n|dvr|s|jt�|xr|j
|d�}|}|j|���tj|�S)z&Return the string value of the header.N�ascii�surrogateescape�replacer�Nr
���)�
_normalizerr�UNKNOWN8BIT�encoder)�	_nonctextr�SPACE�EMPTYSTRING�join)	rU�uchunks�lastcs�	lastspacer1r�nextcs�original_bytes�hasspaces	         rD�__str__zHeader.__str__�s������������	�#�|�|�O�F�G��F���-�-�-�!'���w�8I�!J��'�.�.�w�	�B���!�?�d�n�n�V�A�Y�&?���!3�3��!3�3�H����u�-�!%���#5�5�i��N�N�5�)��=�4�>�>�&��*�#=�I��F��N�N�6�"�+ ,�,����(�(rMc��|t|�k(S�N)r)rU�others  rD�__eq__z
Header.__eq__�s����D�	�!�!rMc���|�
|j}nt|t�st|�}t|t�sH|jxsd}|tj
k(r|j
dd�}n|j
||�}|jxsd}|tj
k7r	|j||�|jj||f�y#t$r|dk7r�t}Y�5wxYw)a.Append a string to the MIME header.

        Optional charset, if given, should be a Charset instance or the name
        of a character set (which will be converted to a Charset instance).  A
        value of None (the default) means that the charset given in the
        constructor is used.

        s may be a byte string or a Unicode string.  If it is a byte string
        (i.e. isinstance(s, str) is false), then charset is the encoding of
        that byte string, and a UnicodeError will be raised if the string
        cannot be decoded with that charset.  If s is a Unicode string, then
        charset is a hint specifying the character set of the characters in
        the string.  In either case, when producing an RFC 2822 compliant
        header using RFC 2047 rules, the string will be encoded using the
        output codec of the charset.  If the string cannot be encoded to the
        output codec, a UnicodeError will be raised.

        Optional `errors' is passed as the errors argument to the decode
        call if s is a byte string.
        Nr
rZ)
rr-rIr�input_codecr_r)�output_codecr`�UnicodeEncodeError�UTF8rr)rUrLrrV�
input_charset�output_charsets      rDrz
Header.appends���*�?��m�m�G��G�W�-��g�&�G��!�S�!�#�/�/�=�:�M��� 4� 4�4��H�H�Z�):�;���H�H�]�F�3��!�-�-�;����X�1�1�1�
������0�
	
�����Q��L�)��	&�
�!�:�-����
�s�'C�C/�.C/c�.�|j�xs|dvS)z=True if string s is not a ctext character of RFC822.
        )�(�)�\)r")rUrLs  rDrazHeader._nonctext0s���y�y�{�3�a�#3�3�3rMc�.�|j�|�|j}|dk(rd}t|j||j|�}d}dx}}|j
D�][\}}	|�I|xr|j
|d�}|dvr|r|	dvr'|j�n|	dvr|s|j�|xr|j
|d�}|	}d}|j�}
|
r|jd|
d|	�n|jdd|	�|
ddD]�}|j�|	j�/|j|jd	|j�z|	��N|j�}|dt|�t|�z
}
|j|
||	���t|
�dkDs��L|j���^|j
r|j�|j|�}tj!|�rt#d
j%|���|S)a�Encode a message header into an RFC-compliant format.

        There are many issues involved in converting a given string for use in
        an email header.  Only certain character sets are readable in most
        email clients, and as header strings can only contain a subset of
        7-bit ASCII, care must be taken to properly convert and encode (with
        Base64 or quoted-printable) header strings.  In addition, there is a
        75-character length limit on any given encoded header field, so
        line-wrapping must be performed, even with double-byte character sets.

        Optional maxlinelen specifies the maximum length of each generated
        line, exclusive of the linesep string.  Individual lines may be longer
        than maxlinelen if a folding point cannot be found.  The first line
        will be shorter by the length of the header name plus ": " if a header
        name was specified at Header construction time.  The default value for
        maxlinelen is determined at header construction time.

        Optional splitchars is a string containing characters which should be
        given extra weight by the splitting algorithm during normal header
        wrapping.  This is in very rough support of RFC 2822's `higher level
        syntactic breaks':  split points preceded by a splitchar are preferred
        during line splitting, with the characters preferred in the order in
        which they appear in the string.  Space and tab may be included in the
        string to indicate whether preference should be given to one over the
        other as a split point when other split chars do not appear in the line
        being split.  Splitchars does not affect RFC 2047 encoded lines.

        Optional linesep is a string to be used to separate the lines of
        the value.  The default value is the most useful for typical
        Python applications, but it can be set to \r\n to produce RFC-compliant
        line separators when needed.
        Nri@Br\r]Frrr	z8header value appears to contain an embedded header: {!r})r^rS�_ValueFormatterrTrQrra�add_transitionr�feed�newline�header_encodingrr'�_str�_embedded_headerrr�format)rU�
splitcharsrF�linesep�	formatterrfrjrgr1r�linesr3�sline�fws�values               rDr`z
Header.encode5s��B	
�������)�)�J���?� �J�#�D�O�O�Z�$(�$9�$9�:�G�	���#�#��9�#�|�|�O�F�G��#�!�?�d�n�n�V�A�Y�&?���!3�3�#�w�6H�'H�!�0�0�2��$6�6�y��,�,�.��=�4�>�>�&��*�#=�I��F��H��%�%�'�E�����r�5��8�W�5����r�2�w�/��a�b�	���!�!�#��*�*�6��N�N�4�#8�#8�#����
�:M�#*�,�!�K�K�M�E��4��D�	�#�e�*� 4�5�C��N�N�3��w�7�"��5�z�A�~��!�!�#�5 ,�6�<�<��$�$�&����w�'���"�"�5�)�"�$+�+1�6�%�=�:�
:��rMc��g}d}g}|jD]I\}}||k(r|j|��|�&|jtj|�|f�|g}|}�K|r&|jtj|�|f�||_yrm)rrrbrd)rU�chunksrC�
last_chunkr1rs      rDr^zHeader._normalize�s��������
�#�|�|�O�F�G��,�&��!�!�&�)��+��M�M�5�:�:�j�#9�<�"H�I�$�X�
�&�� ,���M�M�5�:�:�j�1�<�@�A���rM)NNNNr	�strict)Nr�)z;, 	Nr)
�__name__�
__module__�__qualname__rWrkrorrar`r^�rMrDrr�s3��'+�.2�-5�-3�^)�@"�)*�V4�
N�`rMrc�B�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)r|c�|�||_||_t|�|_||_g|_t
|�|_yrm)�_maxlenrQr'�_continuation_ws_len�_splitchars�_lines�_Accumulator�
_current_line)rU�	headerlen�maxlenrHr�s     rDrWz_ValueFormatter.__init__�s:����� /���$'��$8��!�%������)�)�4��rMc�X�|j�|j|j�Srm)rrdr�)rUr�s  rDr�z_ValueFormatter._str�s�������|�|�D�K�K�(�(rMc�,�|jt�Srm)r��NL�rUs rDrkz_ValueFormatter.__str__�s���y�y��}�rMc���|jj�}|dk7r|jj|�t|j�dkDr|jj	�r7|j
r+|j
dxxt
|j�z
cc<n.|j
jt
|j��|jj�y)N)r	rrr])	r�r�pushr'�	is_onlywsr�rr�reset)rU�end_of_lines  rDrz_ValueFormatter.newline�s����(�(�,�,�.���)�#�#�D���#�#�[�1��t�!�!�"�Q�&��!�!�+�+�-�$�+�+����B��3�t�'9�'9�#:�:�����"�"�3�t�'9�'9�#:�;���� � �"rMc�<�|jjdd�y)Nr	r)r�r�r�s rDr}z_ValueFormatter.add_transition�s��������R�(rMc��|j�|j|||j�y|j||j	��}	|jd�}|�|j||�	|j�}|j�|jj|j|�|D]*}|jj|j|z��,y#t$rYywxYw#t$rYywxYw�Nr)r��_ascii_splitr��header_encode_lines�_maxlengthsr�
IndexError�
_append_chunkrr�r�rQr�r)rUr�r1r�
encoded_lines�
first_line�	last_liner3s        rDr~z_ValueFormatter.feed�s����"�"�*����c�6�4�+;�+;�<�� �3�3�F�D�<L�<L�<N�O�
�	�&�*�*�1�-�J��!����s�J�/�	�%�)�)�+�I�	
���������� 5� 5�y�A�!�D��K�K���t�4�4�t�;�<�"���	��	���	��	�s$�C(�2C7�(	C4�3C4�7	D�Dc#�K�|jt|j�z
��	|j|jz
����wrm)r�r'r�r�r�s rDr�z_ValueFormatter._maxlengths�s=�����l�l�S��!3�!3�4�4�4���,�,��!:�!:�:�:��s�AAc���tjdtzdz||z�}|drdg|ddn|jd�t	t|�gdz�D]\}}|j
||��y)Nz([z]+)rrr)�rer�FWSr�zip�iterr�)rUr�r1r�r4�parts      rDr�z_ValueFormatter._ascii_split�sl������c��%���V��4����8���E�"�1�I��I�I�a�L��t�E�{�m�A�o�.�I�C�����s�D�)�/rMc�:�|jj||�t|j�|jkD�r\|jD]�}t|jj
�dz
dd�D]R}|j�r|j|d}|r
|d|k(rn%|j|dz
d}|s�I|d|k(s�Rn��nh|jj�\}}|jjdkDr|j�|sd}|jj||�y|jj|�}|jjt|j��|jj|�yy)Nrrr]r	)r�r�r'r�r��range�
part_countr"r�
_initial_sizer�pop_fromr�rrr�)rUr�r1�ch�i�prevpartr��	remainders        rDr�z_ValueFormatter._append_chunk�so��������V�,��t�!�!�"�T�\�\�1��&�&���t�1�1�<�<�>�q�@�!�R�H�A��z�z�|�"�0�0��3�A�6���3�q�6�2�:�!�#�1�1�!�A�#�6�q�9�H��H�R�L�"�$4��I���'�!�.�.�2�2�4�	��T��%�%�3�3�a�7��L�L�N��"���"�"�'�'��T�2���*�*�3�3�A�6�I��K�K���s�4�#5�#5�6�7����$�$�Y�/�92rMN)r�r�r�rWr�rkrr}r~r�r�r�r�rMrDr|r|�s0��5�)��	#�)�#=�J;�*�,0rMr|c�\��eZdZd
�fd�	Zd�Zd
d�Z�fd�Zd�Zd�Zdd�Z	d�Z
�fd	�Z�xZS)r�c�0��||_t�|�	�yrm)r��superrW)rU�initial_size�	__class__s  �rDrWz_Accumulator.__init__s���)���
���rMc�*�|j||f�yrm)r)rUr�r1s   rDr�z_Accumulator.pushs�����S�&�M�"rMc��||d}g||d|Srmr�)rUr��poppeds   rDr�z_Accumulator.pop_from!s���a�b�����Q�R���
rMc�H��|j�dk(ryt�|�	�S)Nr)rr)r�r�r�rUr�s �rDrz_Accumulator.pop&s!����?�?��a����w�{�}�rMc�<�td�|D�|j�S)Nc3�PK�|]\}}t|�t|�z��� y�wrm)r'��.0r�r�s   rD�	<genexpr>z'_Accumulator.__len__.<locals>.<genexpr>,s"����=��9�3��C��H�S��Y�&����$&)�sumr�r�s rD�__len__z_Accumulator.__len__+s ���=��=��%�%�'�	'rMc�:�tjd�|D��S)Nc3�PK�|]\}}tj||f���� y�wrm�rcrdr�s   rDr�z'_Accumulator.__str__.<locals>.<genexpr>0s+����!7�15�I�C��"-�!1�!1�3��+�!>�15�r�r�r�s rDrkz_Accumulator.__str__/s"�����!7�15�!7�8�	8rMc�$�|�g}||ddd|_yr�)r�)rU�startvals  rDr�z_Accumulator.reset3s�����H���Q����rMc�`�|jdk(xr|xst|�j�Sr�)r�rr"r�s rDr�z_Accumulator.is_onlyws9s,���!�!�1�$�J�d�(�*I�c�$�i�6G�6G�6I�JrMc� ��t�|��Srm)r�r�r�s �rDr�z_Accumulator.part_count<s����w�� � rM)rrm)
r�r�r�rWr�r�rr�rkr�r�r��
__classcell__)r�s@rDr�r�s6����#��
�
'�8��K�!�!rMr�)NNr	)#�__doc__�__all__r�r*�email.quoprimimer$�email.base64mime�email.errorsrrrrIr�rbr/�SPACE8rcrRr�rPrt�compile�VERBOSE�	MULTILINEr�fcrer�r%�_max_appendrrrr|�listr�r�rMrD�<module>r�s��
2���
����)�%�
�
�
��	����	
��	����
�
���
�*�
���w����r�z�z��
�z�z�B�L�L� �"���r�z�z�#�$���2�:�:�m�,�����*�*��[�|;?� #�
�,f�f�R}0�}0�@%!�4�%!rM__pycache__/headerregistry.cpython-312.opt-1.pyc000064400000074301151706203560015451 0ustar00�

T��hSQ��,�dZddlmZddlmZddlmZddlmZGd�d�ZGd�d	�Z	Gd
�de
�Zd�ZGd
�d�Z
Gd�de
�ZGd�d�ZGd�de�ZGd�d�ZGd�de�ZGd�de�ZGd�de�ZGd�d�ZGd�d �ZGd!�d"e�ZGd#�d$e�ZGd%�d&�ZGd'�d(�Zid)e�d*e�d+e�d,e�d-e�d.e�d/e�d0e�d1e�d2e�d3e�d4e�d5e�d6e�d7e�d8e�d9e�eeed:��ZGd;�d<�Zy=)>z�Representing and manipulating email headers via custom objects.

This module provides an implementation of the HeaderRegistry API.
The implementation is designed to flexibly follow RFC5322 rules.
�)�MappingProxyType)�utils)�errors)�_header_value_parserc�f�eZdZd
d�Zed��Zed��Zed��Zed��Zd�Z	d�Z
d	�Zy)�AddressNc	��djtd||||f��}d|vsd|vrtd��|�w|s|rtd��t	j
|�\}}|rtdj
||���|jr|jd�|j}|j}||_
||_||_y)	a�Create an object representing a full email address.

        An address can have a 'display_name', a 'username', and a 'domain'.  In
        addition to specifying the username and domain separately, they may be
        specified together by using the addr_spec keyword *instead of* the
        username and domain keywords.  If an addr_spec string is specified it
        must be properly quoted according to RFC 5322 rules; an error will be
        raised if it is not.

        An Address object has display_name, username, domain, and addr_spec
        attributes, all of which are read-only.  The addr_spec and the string
        value of the object are both quoted according to RFC5322 rules, but
        without any Content Transfer Encoding.

        �N�
�
z8invalid arguments; address parts cannot contain CR or LFz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r)
�join�filter�
ValueError�	TypeError�parser�
get_addr_spec�format�all_defects�
local_part�domain�
_display_name�	_username�_domain)�self�display_name�usernamer�	addr_spec�inputs�a_s�rests        �-/usr/lib64/python3.12/email/headerregistry.py�__init__zAddress.__init__s���"�����|�X�v�y�&Q�R�S���6�>�T�V�^��W�X�X�� ��6��!8�9�9��,�,�Y�7�I�C��� �"=�=C�V�$'��>4�5�5�����o�o�a�(�(��~�~�H��Z�Z�F�)���!������c��|jS�N�r�rs r!rzAddress.display_name8����!�!�!r#c��|jSr%)rr's r!rzAddress.username<����~�~�r#c��|jSr%)rr's r!rzAddress.domain@����|�|�r#c���|j}tjj|�stj|�}|j
r|dz|j
zS|sy|S)z�The addr_spec (username@domain) portion of the address, quoted
        according to RFC 5322 rules, but with no Content Transfer Encoding.
        �@�<>)rr�
DOT_ATOM_ENDS�
isdisjoint�quote_stringr)r�lps  r!rzAddress.addr_specDsV��
�]�]���#�#�.�.�r�2��$�$�R�(�B��;�;���8�d�k�k�)�)����	r#c��dj|jj|j|j|j
�S)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r�	__class__�__name__rrrr's r!�__repr__zAddress.__repr__Rs9��B�I�I����/�/��)�)�4�=�=�$�+�+�G�	Gr#c��|j}tjj|�stj|�}|r/|j
dk(rdn|j
}dj
||�S|j
S)Nr/r
z{} <{}>)rr�SPECIALSr1r2rr)r�disprs   r!�__str__zAddress.__str__Wse��� � �����)�)�$�/��&�&�t�,�D��"�n�n�d�2�����I��#�#�D�)�4�4��~�~�r#c���t|t�stS|j|jk(xr4|j|jk(xr|j
|j
k(Sr%)�
isinstancer�NotImplementedrrr�r�others  r!�__eq__zAddress.__eq__`sU���%��)�!�!��!�!�U�%7�%7�7�,��
�
����/�,����u�|�|�+�	-r#)r
r
r
N)r6�
__module__�__qualname__r"�propertyrrrrr7r;rA�r#r!rrsh��(�T�"��"�������������G�
�-r#rc�F�eZdZdd�Zed��Zed��Zd�Zd�Zd�Z	y)	�GroupNc�V�||_|rt|�|_yt�|_y)aCreate an object representing an address group.

        An address group consists of a display_name followed by colon and a
        list of addresses (see Address) terminated by a semi-colon.  The Group
        is created by specifying a display_name and a possibly empty list of
        Address objects.  A Group can also be used to represent a single
        address that is not in a group, which is convenient when manipulating
        lists that are a combination of Groups and individual Addresses.  In
        this case the display_name should be set to None.  In particular, the
        string representation of a Group whose display_name is None is the same
        as the Address object, if there is one and only one Address object in
        the addresses list.

        N)r�tuple�
_addresses)rr�	addressess   r!r"zGroup.__init__js"��*���.7�%�	�*���U�W��r#c��|jSr%r&r's r!rzGroup.display_name|r(r#c��|jSr%)rJr's r!rKzGroup.addresses�s�����r#c�x�dj|jj|j|j�S)Nz${}(display_name={!r}, addresses={!r})rr5r6rrKr's r!r7zGroup.__repr__�s1��5�<�<����(�(��"�"�D�N�N�4�	4r#c�x�|j�0t|j�dk(rt|jd�S|j}|�4tj
j
|�st	j|�}djd�|jD��}|rd|zn|}dj||�S)N�r�, c3�2K�|]}t|����y�wr%)�str)�.0�xs  r!�	<genexpr>z Group.__str__.<locals>.<genexpr>�s����:�>�a�3�q�6�>�s�� z{}:{};)
r�lenrKrSrr9r1r2r
r)rr:�adrstrs   r!r;z
Group.__str__�s������$��T�^�^�)<�a�)?��t�~�~�a�(�)�)�� � ����F�O�O�$>�$>�t�$D��&�&�t�,�D����:�4�>�>�:�:��!'��v��V�����t�V�,�,r#c��t|t�stS|j|jk(xr|j|jk(Sr%)r=rGr>rrKr?s  r!rAzGroup.__eq__�s@���%��'�!�!��!�!�U�%7�%7�7�2����%�/�/�1�	3r#)NN)
r6rBrCr"rDrrKr7r;rArEr#r!rGrGhs?��E�$�"��"�����4�
-�3r#rGc�X�eZdZdZd�Zd�Zed��Zed��Zd�Z	e
d��Zd�Zy	)
�
BaseHeadera|Base class for message headers.

    Implements generic behavior and provides tools for subclasses.

    A subclass must define a classmethod named 'parse' that takes an unfolded
    value string and a dictionary as its arguments.  The dictionary will
    contain one key, 'defects', initialized to an empty list.  After the call
    the dictionary must contain two additional keys: parse_tree, set to the
    parse tree obtained from parsing the header, and 'decoded', set to the
    string value of the idealized representation of the data from the value.
    (That is, encoded words are decoded, and values that have canonical
    representations are so represented.)

    The defects key is intended to collect parsing defects, which the message
    parser will subsequently dispose of as appropriate.  The parser should not,
    insofar as practical, raise any errors.  Defects should be added to the
    list instead.  The standard header parsers register defects for RFC
    compliance issues, for obsolete RFC syntax, and for unrecoverable parsing
    errors.

    The parse method may add additional keys to the dictionary.  In this case
    the subclass must define an 'init' method, which will be passed the
    dictionary as its keyword arguments.  The method should use (usually by
    setting them as the value of similarly named attributes) and remove all the
    extra keys added by its parse method, and then use super to call its parent
    class with the remaining arguments and keywords.

    The subclass should also make sure that a 'max_count' attribute is defined
    that is either None or 1. XXX: need to better define this API.

    c��dgi}|j||�tj|d�rtj|d�|d<tj||d�}|d=|j|fi|��|S)N�defects�decoded)�parser�_has_surrogates�	_sanitizerS�__new__�init)�cls�name�value�kwdsrs     r!rczBaseHeader.__new__�st���2����	�	�%���� � ��i��1�#�o�o�d�9�o�>�D��O��{�{�3��Y��0����O���	�	�$��$���r#c�.�||_||_||_yr%)�_name�_parse_tree�_defects)rrf�
parse_treer^s    r!rdzBaseHeader.init�s����
�%�����
r#c��|jSr%)rjr's r!rfzBaseHeader.name�s���z�z�r#c�,�t|j�Sr%)rIrlr's r!r^zBaseHeader.defects�s���T�]�]�#�#r#c��t|jj|jjt	|�f|j�fSr%)�_reconstruct_headerr5r6�	__bases__rS�__getstate__r's r!�
__reduce__zBaseHeader.__reduce__�sC������'�'����(�(��D�	�
�

����!�	!r#c�.�tj||�Sr%)rSrc)rergs  r!�_reconstructzBaseHeader._reconstruct�s���{�{�3��&�&r#c	��tjtjtj|jd�tjdd�g�g�}|j
r9|j
tjtjdd�g��|j
|j
�|j|��S)atFold header according to policy.

        The parsed representation of the header is folded according to
        RFC5322 rules, as modified by the policy.  If the parse tree
        contains surrogateescaped bytes, the bytes are CTE encoded using
        the charset 'unknown-8bit".

        Any non-ASCII characters in the parse tree are CTE encoded using
        charset utf-8. XXX: make this a policy setting.

        The returned value is an ASCII-only string possibly containing linesep
        characters, and ending with a linesep character.  The string includes
        the header name and the ': ' separator.

        zheader-name�:z
header-seprW�fws)�policy)
r�Header�HeaderLabel�
ValueTerminalrfrk�append�CFWSList�WhiteSpaceTerminal�fold)rrz�headers   r!r�zBaseHeader.fold�s���"�������$�$�T�Y�Y�
�>��$�$�S�,�7� 9�
:� ���
����M�M�����!:�!:�3��!F� G�H�
J��
�
�d�&�&�'��{�{�&�{�)�)r#N)
r6rBrC�__doc__rcrdrDrfr^rt�classmethodrvr�rEr#r!r\r\�sX���@� �
�����$��$�!��'��'�*r#r\c�:�t||i�j|�Sr%)�typerv)�cls_name�basesrgs   r!rqrqs����%��$�1�1�%�8�8r#c�D�eZdZdZeej�Zed��Z	y)�UnstructuredHeaderNc�N�|j|�|d<t|d�|d<y)Nrmr_)�value_parserrS�rergrhs   r!r`zUnstructuredHeader.parse	s*�� �-�-�e�4��\���d�<�0�1��Y�r#)
r6rBrC�	max_count�staticmethodr�get_unstructuredr�r�r`rEr#r!r�r�s)���I��� 7� 7�8�L��2��2r#r�c��eZdZdZy)�UniqueUnstructuredHeaderrPN�r6rBrCr�rEr#r!r�r�����Ir#r�c�j��eZdZdZdZeej�Ze	d��Z
�fd�Zed��Z
�xZS)�
DateHeadera�Header whose value consists of a single timestamp.

    Provides an additional attribute, datetime, which is either an aware
    datetime using a timezone, or a naive datetime if the timezone
    in the input string is -0000.  Also accepts a datetime as input.
    The 'value' attribute is the normalized form of the timestamp,
    which means it is the output of format_datetime on the datetime.
    Nc��|sH|djtj��d|d<d|d<tj�|d<yt|t�r||d<	tj|�}||d<tj|d�|d<|j|d�|d<y#t$rF|djtjd��d|d<tj�|d<YywxYw)Nr^�datetimer
r_rmzInvalid date value or format)
r~r�HeaderMissingRequiredValuer�	TokenListr=rSr�parsedate_to_datetimer�InvalidDateDefect�format_datetimer�r�s   r!r`zDateHeader.parse$s������O�"�"�6�#D�#D�#F�G�#�D��� �D��O�!'�!1�!1�!3�D�����e�S�!�#�D��O�
��3�3�E�:��!��Z���/�/��Z�0@�A��Y�� �-�-�d�9�o�>��\����
��Y��&�&�v�'?�'?�@^�'_�`�#'��Z� �%+�%5�%5�%7��\�"��	
�s�!B.�.AC=�<C=c�P��|jd�|_t�|�|i|��y)Nr�)�pop�	_datetime�superrd�r�args�kwr5s   �r!rdzDateHeader.init9s$������
�+���
���d�!�b�!r#c��|jSr%)r�r's r!r�zDateHeader.datetime=r*r#)r6rBrCr�r�r�rr�r�r�r`rdrDr��
__classcell__�r5s@r!r�r�sL�����I� �� 7� 7�8�L��?��?�("����r#r�c��eZdZdZy)�UniqueDateHeaderrPNr�rEr#r!r�r�Br�r#r�c�b��eZdZdZed��Zed��Z�fd�Ze	d��Z
e	d��Z�xZS)�
AddressHeaderNc�6�tj|�\}}|Sr%)r�get_address_list)rg�address_lists  r!r�zAddressHeader.value_parserKs��$�5�5�e�<���e��r#c��t|t�r�|j|�x|d<}g}|jD]t}|j	t|j|jD�cgc]9}t|jxsd|jxsd|jxsd���;c}���vt|j�}n9t|d�s|g}|D�cgc]}t|d�s
td|g�n|��}}g}||d<||d<dj|D�cgc]
}t|���c}�|d<d|vr|j|d�|d<yycc}wcc}wcc}w)	Nrmr
�__iter__rK�groupsr^rQr_)r=rSr�rKr~rGr�
all_mailboxesrrr�listr�hasattrr
)	rergrhr�r��addr�mbr^�items	         r!r`zAddressHeader.parseQs����e�S�!�14�0@�0@��0G�G�D�����F�$�.�.���
�
�e�D�$5�$5�04�/A�/A�%C�0B��&-�R�_�_�-B��-/�]�]�-@�b�-/�Y�Y�_�"�&>�0B�%C�D�E�/��<�3�3�4�G��5�*�-����16�7�05��29��{�1K�e�D�4�&�)�/3�4�05�
�7��G���X��!��Y���)�)�6�$B�6�4�S��Y�6�$B�C��Y���t�#�!$�!1�!1�$�y�/�!B�D���$��!%C��7��%Cs�!>E
�"E�Ec�p��t|jd��|_d|_t	�|�|i|��y)Nr�)rIr��_groupsrJr�rdr�s   �r!rdzAddressHeader.initms0����R�V�V�H�-�.������
���d�!�b�!r#c��|jSr%)r�r's r!r�zAddressHeader.groupsrr,r#c�t�|j�!td�|jD��|_|jS)Nc3�BK�|]}|jD]}|����y�wr%)rK)rT�group�addresss   r!rVz*AddressHeader.addresses.<locals>.<genexpr>ys(����$L���;@�?�?��%,�;J�%,��s�)rJrIr�r's r!rKzAddressHeader.addressesvs5���?�?�"�#�$L����$L�L�D�O����r#)
r6rBrCr�r�r�r�r`rdrDr�rKr�r�s@r!r�r�Gs]����I�����
�C��C�6"�
�������r#r�c��eZdZdZy)�UniqueAddressHeaderrPNr�rEr#r!r�r�~r�r#r�c��eZdZed��Zy)�SingleAddressHeaderc��t|j�dk7r$tdj|j���|jdS)NrPz9value of single address header {} is not a single addressr)rXrKrrrfr's r!r�zSingleAddressHeader.address�sB���t�~�~���!��#�$*�F�4�9�9�$5�7�
7��~�~�a� � r#N)r6rBrCrDr�rEr#r!r�r��s��
�!��!r#r�c��eZdZdZy)�UniqueSingleAddressHeaderrPNr�rEr#r!r�r��r�r#r�c���eZdZdZeej�Zed��Z	�fd�Z
ed��Zed��Z
ed��Z�xZS)�MIMEVersionHeaderrPc�:�|j|�x|d<}t|�|d<|dj|j�|j�dn|j
|d<|j|d<|j�dj
|d|d�|d<yd|d<y)Nrmr_r^�major�minorz{}.{}�version)r�rS�extendrr�r�r�rergrhrms    r!r`zMIMEVersionHeader.parse�s���*-�*:�*:�5�*A�A��\��Z��j�/��Y���Y����z�5�5�6� *� 0� 0� 8��j�>N�>N��W�
�"�(�(��W�
����'�%�n�n�T�'�]�D��M�J�D��O�"�D��Or#c���|jd�|_|jd�|_|jd�|_t	�|�|i|��y)Nr�r�r�)r��_version�_major�_minorr�rdr�s   �r!rdzMIMEVersionHeader.init�sB������y�)��
��f�f�W�o����f�f�W�o���
���d�!�b�!r#c��|jSr%)r�r's r!r�zMIMEVersionHeader.major�����{�{�r#c��|jSr%)r�r's r!r�zMIMEVersionHeader.minor�r�r#c��|jSr%)r�r's r!r�zMIMEVersionHeader.version�����}�}�r#)r6rBrCr�r�r�parse_mime_versionr�r�r`rdrDr�r�r�r�r�s@r!r�r��sk����I��� 9� 9�:�L��	#��	#�"������������r#r�c�B��eZdZdZed��Z�fd�Zed��Z�xZ	S)�ParameterizedMIMEHeaderrPc�f�|j|�x|d<}t|�|d<|dj|j�|j�i|d<y|jD��cic]<\}}tj|�j�tj|���>c}}|d<ycc}}w)Nrmr_r^�params)r�rSr�rr�rrb�lower)rergrhrmrfs     r!r`zParameterizedMIMEHeader.parse�s���*-�*:�*:�5�*A�A��\��Z��j�/��Y���Y����z�5�5�6����$��D��N�
3=�2C�2C�E�2C�;�4��$�o�o�d�3�9�9�;�$)�O�O�E�$:�;�2C�E�D��N��Es�$AB-c�P��|jd�|_t�|�|i|��y)Nr�)r��_paramsr�rdr�s   �r!rdzParameterizedMIMEHeader.init�s$����v�v�h�'���
���d�!�b�!r#c�,�t|j�Sr%)rr�r's r!r�zParameterizedMIMEHeader.params�s������-�-r#)
r6rBrCr�r�r`rdrDr�r�r�s@r!r�r��s7���
�I��
E��
E�"��.��.r#r�c�r��eZdZeej
�Z�fd�Zed��Z	ed��Z
ed��Z�xZS)�ContentTypeHeaderc����t�|�|i|��tj|jj
�|_tj|jj�|_yr%)	r�rdrrbrk�maintype�	_maintype�subtype�_subtyper�s   �r!rdzContentTypeHeader.init�sL���
���d�!�b�!�����)9�)9�)B�)B�C�������(8�(8�(@�(@�A��
r#c��|jSr%)r�r's r!r�zContentTypeHeader.maintype�r*r#c��|jSr%)r�r's r!r�zContentTypeHeader.subtype�r�r#c�:�|jdz|jzS)N�/)r�r�r's r!�content_typezContentTypeHeader.content_type�s���}�}�s�"�T�\�\�1�1r#)
r6rBrCr�r�parse_content_type_headerr�rdrDr�r�r�r�r�s@r!r�r��sU����� @� @�A�L�B�
���������2��2r#r�c�R��eZdZeej
�Z�fd�Zed��Z	�xZ
S)�ContentDispositionHeaderc���t�|�|i|��|jj}|�||_yt	j
|�|_yr%)r�rdrk�content_dispositionrrb�_content_disposition)rr�r��cdr5s    �r!rdzContentDispositionHeader.init�sA���
���d�!�b�!�
�
�
�
1�
1��*,�*�B��!�%�/�/�"�:M��!r#c��|jSr%)r�r's r!r�z,ContentDispositionHeader.content_disposition�s���(�(�(r#)r6rBrCr�r� parse_content_disposition_headerr�rdrDr�r�r�s@r!r�r��s-����� G� G�H�L�N�
�)��)r#r�c�f��eZdZdZeej�Zed��Z	�fd�Z
ed��Z�xZ
S)�ContentTransferEncodingHeaderrPc��|j|�x|d<}t|�|d<|dj|j�y�Nrmr_r^�r�rSr�rr�s    r!r`z#ContentTransferEncodingHeader.parse��A��*-�*:�*:�5�*A�A��\��Z��j�/��Y���Y����z�5�5�6r#c���t�|�|i|��tj|jj
�|_yr%)r�rdrrbrk�cte�_cter�s   �r!rdz"ContentTransferEncodingHeader.inits0���
���d�!�b�!��O�O�D�$4�$4�$8�$8�9��	r#c��|jSr%)r�r's r!r�z!ContentTransferEncodingHeader.ctes���y�y�r#)r6rBrCr�r�r�&parse_content_transfer_encoding_headerr�r�r`rdrDr�r�r�s@r!r�r��sC����I��� M� M�N�L��7��7�
:����r#r�c�D�eZdZdZeej�Zed��Z	y)�MessageIDHeaderrPc��|j|�x|d<}t|�|d<|dj|j�yr�r�r�s    r!r`zMessageIDHeader.parser�r#N)
r6rBrCr�r�r�parse_message_idr�r�r`rEr#r!rr
s)���I��� 7� 7�8�L��7��7r#r�subject�datezresent-datez	orig-date�senderz
resent-sender�toz	resent-to�ccz	resent-cc�bccz
resent-bcc�fromzresent-fromzreply-tozmime-versionzcontent-type)zcontent-dispositionzcontent-transfer-encodingz
message-idc�0�eZdZdZeedfd�Zd�Zd�Zd�Z	y)�HeaderRegistryz%A header_factory and header registry.Tc�r�i|_||_||_|r |jjt�yy)a�Create a header_factory that works with the Policy API.

        base_class is the class that will be the last class in the created
        header class's __bases__ list.  default_class is the class that will be
        used if "name" (see __call__) does not appear in the registry.
        use_default_map controls whether or not the default mapping of names to
        specialized classes is copied in to the registry when the factory is
        created.  The default is True.

        N)�registry�
base_class�
default_class�update�_default_header_map)rrr�use_default_maps    r!r"zHeaderRegistry.__init__6s5����
�$���*�����M�M� � �!4�5�r#c�>�||j|j�<y)zLRegister cls as the specialized class for handling "name" headers.

        N)rr��rrfres   r!�map_to_typezHeaderRegistry.map_to_typeHs��'*��
�
�d�j�j�l�#r#c��|jj|j�|j�}t	d|j
z||jfi�S)N�_)r�getr�rr�r6rrs   r!�__getitem__zHeaderRegistry.__getitem__NsE���m�m����
�
��d�.@�.@�A���C����$�s�D�O�O�&<�b�A�Ar#c��||||�S)a�Create a header instance for header 'name' from 'value'.

        Creates a header instance by creating a specialized class for parsing
        and representing the specified header by combining the factory
        base_class with a specialized class from the registry or the
        default_class, and passing the name and value to the constructed
        class's constructor.

        rE)rrfrgs   r!�__call__zHeaderRegistry.__call__Rs���t�D�z�$��&�&r#N)
r6rBrCr�r\r�r"rrrrEr#r!rr2s#��/�",�<N�'+�6�$*�B�
'r#rN)r��typesr�emailrrrrrrGrSr\rqr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrEr#r!�<module>rs����
#���0�Y-�Y-�x/3�/3�ha*��a*�H9�2�2��1��
+�+�\�z��
4�4�n�-��
!�-�!�� 3��
"�"�J.�.�:2�/�2�,)�6�)���*	7�	7��
�$<��
�$4���J���$4�	�

�$=���$7�
�	�$7���M��	�$7���M��
�$7���M���$7���M���$7�� �$5�!�"�$5�#�$%=�$A�$3�)��.*'�*'r#__pycache__/message.cpython-312.opt-1.pyc000064400000147500151706203560014056 0ustar00�

T��hW����dZddgZddlZddlZddlZddlmZmZddlm	Z	ddlm
Z
ddlmZdd	lm
Zdd
lmZej"ZdZej&d�Zd
�Zdd�Zd�Zd�Zd�ZGd�d�ZGd�de�ZGd�de�Zy)z8Basic message object for the email package object model.�Message�EmailMessage�N)�BytesIO�StringIO)�utils)�errors)�compat32��charset)�decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]c��t|�jd�\}}}|s|j�dfS|j�|j�fS)N�;)�str�	partition�strip)�param�a�sep�bs    �&/usr/lib64/python3.12/email/message.py�_splitparamrsH��
�E�
�$�$�S�)�I�A�s�A���w�w�y�$����7�7�9�a�g�g�i���c��|��t|�dkDr�t|t�r,|dz
}tj|d|d|d�}|�d|��S	|jd�|stj|�r|�d	tj|��d
�S|�d|��S|S#t$r&|dz
}tj|dd�}|�d|��cYSwxYw)a~Convenience function to format and return a key=value pair.

    This will quote the value if needed or if quote is true.  If value is a
    three tuple (charset, language, value), it will be encoded according
    to RFC2231 rules.  If it contains non-ascii characters it will likewise
    be encoded according to RFC2231 rules, using the utf-8 charset and
    a null language.
    r�*���=�asciizutf-8�z="�")
�len�
isinstance�tupler�encode_rfc2231�encode�UnicodeEncodeError�	tspecials�search�quote)r�valuer)s   r�_formatparamr+'s���
��S��Z�!�^��e�U�#��S�L�E��(�(��q��5��8�U�1�X�F�E�#�U�+�+�
0����W�%��I�$�$�U�+� %�u�{�{�5�'9�:�:�#�U�+�+����&�
0������,�,�U�G�R�@��"'��/�/�
0�s�B�,C	�C	c�r�dt|�z}g}|dddk(�r|dd}|jd�}|dkDro|jdd|�|jdd|�z
dzrE|jd|dz�}|dkDr+|jdd|�|jdd|�z
dzr�E|dkrt|�}|d|}d|vrL|j	d�}|d|j�j
�dz||dzdj�z}|j|j��||d}|dddk(r��|S)Nrrrr z\"rr)r�find�countr!�indexr�lower�append)�s�plist�end�f�is     r�_parseparamr7Is?���c�!�f��A��E�
�B�Q�%�3�,�
�a�b�E���f�f�S�k���A�g�1�7�7�3��3�/�!�'�'�%��C�2H�H�A�M��&�&��c�A�g�&�C��A�g�1�7�7�3��3�/�!�'�'�%��C�2H�H�A�M���7��a�&�C�
�d�s�G���!�8������A��"�1����
�#�#�%��+�a��!���g�m�m�o�=�A�
���Q�W�W�Y��
�c�d�G���B�Q�%�3�,��Lrc��t|t�r!|d|dtj|d�fStj|�S)Nrrr)r"r#r�unquote)r*s r�
_unquotevaluer:]s?��
�%����Q�x��q��5�=�=��q��#:�:�:��}�}�U�#�#rc�R�g}t|j��}|D]G}|jd�s�|jd�j	d�\}}}	t|d��nt
d��|D]L}|st
d��|jd�dk(rn)	tj|�}|j|��Ndj|�S#t$rY��wxYw#tj$r/|d	d
z
dzdzd
zdz}tj|d|�}Y�twxYw)zDecode uuencoded data.sbegin � �)�basez`begin` line not foundzTruncated inputs 	
sendr� �?���Nr)
�iter�
splitlines�
startswith�removeprefixr�int�
ValueErrorr�binascii�a2b_uu�Errorr1�join)	�encoded�
decoded_lines�encoded_lines_iter�line�mode�_�path�decoded_line�nbytess	         r�
_decode_uurWhs2���M��g�0�0�2�3��"���?�?�9�%� �-�-�i�8�B�B�4�H�M�D�!�T�
��D�q�!��#��1�2�2�"����.�/�/�
�Z�Z��
%��
/��	:�#�?�?�4�0�L�
	���\�*�#��8�8�M�"�"��'�
��
���~�~�	:��Q���
�b�(�A�-��1�a�7�F�#�?�?�4���=�9�L�	:�s$�
C�C$�	C!� C!�$?D&�%D&c�T�eZdZdZefd�Zd�Zd2d�Zd�Zd3d�Z	d	�Z
d
�Zd�Zd�Z
d4d
�Zd5d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd5d�Zd�Zd�Zd5d�Zd�Zd�Z d �Z!d!�Z"d"�Z#d#�Z$d$�Z%d%�Z&d6d&�Z'		d6d'�Z(		d7d(�Z)d8d)�Z*d9d*�Z+d5d+�Z,d5d,�Z-d-�Z.d5d.�Z/d5d/�Z0d0�Z1dd1l2m3Z3y):ra�Basic message object.

    A message object is defined as something that has a bunch of RFC 2822
    headers and a payload.  It may optionally have an envelope header
    (a.k.a. Unix-From or From_ header).  If the message is a container (i.e. a
    multipart or a message/rfc822), then the payload is a list of Message
    objects, otherwise it is a string.

    Message objects implement part of the `mapping' interface, which assumes
    there is exactly one occurrence of the header per message.  Some headers
    do in fact appear multiple times (e.g. Received) and for those headers,
    you must use the explicit API to set or get all the headers.  Not all of
    the mapping methods are implemented.
    c��||_g|_d|_d|_d|_dx|_|_g|_d|_y)N�
text/plain)	�policy�_headers�	_unixfrom�_payload�_charset�preamble�epilogue�defects�
_default_type)�selfr[s  r�__init__zMessage.__init__�sB�������
������
���
�(,�,��
��
����)��rc�"�|j�S)z9Return the entire formatted message as a string.
        )�	as_string�rds r�__str__zMessage.__str__�s���~�~��rrNc��ddlm}|�|jn|}t�}||d||��}|j	||��|j�S)a�Return the entire formatted message as a string.

        Optional 'unixfrom', when true, means include the Unix From_ envelope
        header.  For backward compatibility reasons, if maxheaderlen is
        not specified it defaults to 0, so you must override it explicitly
        if you want a different maxheaderlen.  'policy' is passed to the
        Generator instance used to serialize the message; if it is not
        specified the policy associated with the message instance is used.

        If the message object contains binary data that is not encoded
        according to RFC standards, the non-compliant data will be replaced by
        unicode "unknown character" code points.
        r)�	GeneratorF)�mangle_from_�maxheaderlenr[��unixfrom)�email.generatorrkr[r�flatten�getvalue)rdrormr[rk�fp�gs       rrgzMessage.as_string�sP��	.� &�����F��
�Z���b�#(�#/�#�
%��	
�	�	�$��	�*��{�{�}�rc�"�|j�S)z?Return the entire formatted message as a bytes object.
        )�as_bytesrhs r�	__bytes__zMessage.__bytes__�s���}�}��rc��ddlm}|�|jn|}t�}||d|��}|j	||��|j�S)aJReturn the entire formatted message as a bytes object.

        Optional 'unixfrom', when true, means include the Unix From_ envelope
        header.  'policy' is passed to the BytesGenerator instance used to
        serialize the message; if not specified the policy associated with
        the message instance is used.
        r)�BytesGeneratorF)rlr[rn)rpryr[rrqrr)rdror[ryrsrts      rrvzMessage.as_bytes�sG��	3� &�����F��
�Y���2�E�&�A��	�	�	�$��	�*��{�{�}�rc�6�t|jt�S)z6Return True if the message consists of multiple parts.)r"r^�listrhs r�is_multipartzMessage.is_multipart�s���$�-�-��.�.rc��||_y�N�r])rdros  r�set_unixfromzMessage.set_unixfrom�s	��!��rc��|jSr~rrhs r�get_unixfromzMessage.get_unixfrom�s���~�~�rc��|j�	|g|_y	|jj|�y#t$rtd��wxYw)z�Add the given payload to the current payload.

        The current payload will always be a list of objects after this method
        is called.  If you want to set the payload to a scalar object, use
        set_payload() instead.
        Nz=Attach is not valid on a message with a non-multipart payload)r^r1�AttributeError�	TypeError)rd�payloads  r�attachzMessage.attach�sO���=�=� �$�I�D�M�
:��
�
�$�$�W�-��!�
:��!9�:�:�
:�s	�3�Ac��|j�r |ry|�|jS|j|S|�;t|jt�s!t	dt|j�z��|j}|j
dd�}t|d�r
|j}n't|�j�j�}|s^t|t�rLtj|�r7	|jdd�}	|j|j!d�d�}|S|St|t�r	|jdd�}|d
k(rt'j(�S|dk(rPt+dj-j/���\}}|D]}|j0j3||�� |S|d
vr	t5�St|t�rS|S#t"$r|jdd�}Y|SwxYw#t$$rY|SwxYw#t$$r|jd	�}Y��wxYw#t6$rcYSwxYw)aZReturn a reference to the payload.

        The payload will either be a list object or a string.  If you mutate
        the list object, you modify the message's payload in place.  Optional
        i returns that index into the payload.

        Optional decode is a flag indicating whether the payload should be
        decoded or not, according to the Content-Transfer-Encoding header
        (default is False).

        When True and the message is not a multipart, the payload will be
        decoded if this header's value is `quoted-printable' or `base64'.  If
        some other encoding is used, or the header is missing, or if the
        payload has bogus data (i.e. bogus base64 or uuencoded data), the
        payload is returned as-is.

        If the message is a multipart and the decode flag is True, then None
        is returned.
        NzExpected list, got %szcontent-transfer-encodingr�cter�surrogateescape�replace�raw-unicode-escapezquoted-printable�base64r)z
x-uuencode�uuencode�uuezx-uue)r|r^r"r{r��type�get�hasattrr�rrr0r�_has_surrogatesr%�decode�get_content_charset�LookupErrorr&�quopri�decodestringrrMrEr[�
handle_defectrWrI)	rdr6r�r�r��bpayloadr*rb�defects	         r�get_payloadzMessage.get_payload�s8��D�������y��}�}�$��}�}�Q�'�'�
�=��D�M�M�4�!@��3�d�4�=�=�6I�I�J�J��-�-���h�h�2�B�7���3����'�'�C��c�(�.�.�"�(�(�*�C���'�3�'�E�,A�,A�'�,J��&�~�~�g�7H�I�H�F�"*�/�/�$�2J�2J�7�2S�U^�"_��
�N�7�N��g�s�#�
@�"�>�>�'�3D�E���$�$��&�&�x�0�0�
�H�_�&�c�h�h�x�/B�/B�/D�&E�F�N�E�7�!�����)�)�$��7�"��L�
�>�
>�
 �!�(�+�+��g�s�#��O����?'�F�"*�/�/�'�9�"E���N�	F��)����N���&�
@�
#�>�>�*>�?��
@��$�
 ���
 �sT�4H�!G"�=H�
H4�"H�=H�H�H�	H�H�H1�0H1�4I�Ic��t|d�rA|�||_yt|t�st|�}|j	|j
d�}t|d�r|j
dd�|_n||_|�|j|�yy)z�Set the payload to the given value.

        Optional charset sets the message's default character set.  See
        set_charset() for details.
        r%Nr�r�r)r�r^r"�Charsetr%�output_charsetr��set_charset)rdr�rs   r�set_payloadzMessage.set_payloadOs����7�H�%��� '��
���g�w�/�!�'�*���n�n�W�%;�%;�=N�O�G��7�H�%�#�N�N�7�4E�F�D�M�#�D�M������W�%�rc���|�|jd�d|_yt|t�st|�}||_d|vr|j	dd�d|vr#|j	dd|j���n |j
d|j��||j�k7r |j|j�|_d|vr|j�}	||�yy#t$rw|j}|r>	|jd	d
�}n*#t$r|j|j�}YnwxYw|j|�|_|j	d|�YywxYw)a�Set the charset of the payload to a given character set.

        charset can be a Charset instance, a string naming a character set, or
        None.  If it is a string it will be converted to a Charset instance.
        If charset is None, the charset parameter will be removed from the
        Content-Type field.  Anything else will generate a TypeError.

        The message will be assumed to be of type text/* encoded with
        charset.input_charset.  It will be converted to charset.output_charset
        and encoded properly, if needed, when generating the plain text
        representation of the message.  MIME headers (MIME-Version,
        Content-Type, Content-Transfer-Encoding) will be added as needed.
        Nr�MIME-Version�1.0�Content-TyperZr
zContent-Transfer-Encodingrr�)�	del_paramr_r"r��
add_header�get_output_charset�	set_param�body_encoder^�get_body_encodingr�r%�UnicodeErrorr�)rdrr�r�s    rr�zMessage.set_charsetcs`���?��N�N�9�%� �D�M���'�7�+��g�&�G���
���%��O�O�N�E�2���%��O�O�N�L�$+�$>�$>�$@�
�
B�
�N�N�9�g�&@�&@�&B�C��g�0�0�2�2�#�/�/��
�
�>�D�M�&�d�2��+�+�-�C�

B��D�	�3���
B��-�-���I�")�.�.��:K�"L���'�I�")�.�.��1G�1G�"H��I�� '� 3� 3�G� <��
���� ;�S�A�
B�s6�#C-�-E-�D�E-�$D?�<E-�>D?�?+E-�,E-c��|jS)zKReturn the Charset instance associated with the message's payload.
        )r_rhs r�get_charsetzMessage.get_charset�s���}�}�rc�,�t|j�S)z9Return the total number of headers, including duplicates.)r!r\rhs r�__len__zMessage.__len__�s���4�=�=�!�!rc�$�|j|�S)a-Get a header value.

        Return None if the header is missing instead of raising an exception.

        Note that if the header appeared multiple times, exactly which
        occurrence gets returned is undefined.  Use get_all() to get all
        the values matching a header field name.
        )r�)rd�names  r�__getitem__zMessage.__getitem__�s���x�x��~�rc�f�|jj|�}|r_|j�}d}|jD]>\}}|j�|k(s�|dz
}||k\s�%t	dj||���|jj
|jj||��y)z�Set the value of a header.

        Note: this does not overwrite an existing header with the same field
        name.  Use __delitem__() first to delete any existing headers.
        rrz/There may be at most {} {} headers in a messageN)r[�header_max_countr0r\rI�formatr1�header_store_parse)rdr��val�	max_count�lname�found�k�vs        r�__setitem__zMessage.__setitem__�s����K�K�0�0��6�	���J�J�L�E��E��
�
���1��7�7�9��%��Q�J�E��	�)�(�*8�8>��y�$�8O�Q�Q�	&�	
�
�
���T�[�[�;�;�D�#�F�Grc��|j�}g}|jD],\}}|j�|k7s�|j||f��.||_y)zwDelete all occurrences of a header, if present.

        Does not raise an exception if the header is missing.
        N)r0r\r1)rdr��
newheadersr�r�s     r�__delitem__zMessage.__delitem__�sO��
�z�z�|���
��M�M�D�A�q��w�w�y�D� ��!�!�1�a�&�)�"�#��
rc�v�|j�}|jD]\}}||j�k(s�yy)NTF)r0r\)rdr��
name_lowerr�r�s     r�__contains__zMessage.__contains__�s5���Z�Z�\�
��M�M�D�A�q��Q�W�W�Y�&��"�rc#�<K�|jD]	\}}|���y�wr~�r\)rd�fieldr*s   r�__iter__zMessage.__iter__�s���� �M�M�L�E�5��K�*�s�c�L�|jD��cgc]\}}|��	c}}Scc}}w)a.Return a list of all the message's header field names.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        r��rdr�r�s   r�keyszMessage.keys�s$��#�m�m�,�m�d�a���m�,�,��,s� c��|jD��cgc]!\}}|jj||���#c}}Scc}}w)a)Return a list of all the message's header values.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        �r\r[�header_fetch_parser�s   r�valueszMessage.values�sB��!�M�M�+�)�D�A�q����.�.�q�!�4�)�+�	+��+s�&:c	��|jD��cgc]#\}}||jj||�f��%c}}Scc}}w)a'Get all the message's header fields and values.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        r�r�s   r�itemsz
Message.items�sG��!�M�M�+�)�D�A�q��D�K�K�2�2�1�a�8�9�)�+�	+��+s�(<c��|j�}|jD]6\}}|j�|k(s�|jj||�cS|S)z~Get a header value.

        Like __getitem__() but return failobj instead of None when the field
        is missing.
        )r0r\r[r�)rdr��failobjr�r�s     rr�zMessage.get�sM���z�z�|���M�M�D�A�q��w�w�y�D� ��{�{�5�5�a��;�;�"��rc�>�|jj||f�y)z�Store name and value in the model without modification.

        This is an "internal" API, intended only for use by a parser.
        N)r\r1)rdr�r*s   r�set_rawzMessage.set_raws��
	
�
�
���d�E�]�+rc�H�t|jj��S)z�Return the (name, value) header pairs without modification.

        This is an "internal" API, intended only for use by a generator.
        )rDr\�copyrhs r�	raw_itemszMessage.raw_items
s��
�D�M�M�&�&�(�)�)rc���g}|j�}|jD]D\}}|j�|k(s�|j|jj	||���F|s|S|S)aQReturn a list of all the values for the named field.

        These will be sorted in the order they appeared in the original
        message, and may contain duplicates.  Any fields deleted and
        re-inserted are always appended to the header list.

        If no such fields exist, failobj is returned (defaults to None).
        )r0r\r1r[r�)rdr�r�r�r�r�s      r�get_allzMessage.get_alls`�����z�z�|���M�M�D�A�q��w�w�y�D� ��
�
�d�k�k�<�<�Q��B�C�"���N��
rc	�.�g}|j�D]T\}}|�"|j|jdd���*|jt|jdd�|���V|�|j	d|�t
j
|�||<y)u�Extended header setting.

        name is the header field to add.  keyword arguments can be used to set
        additional parameters for the header field, with underscores converted
        to dashes.  Normally the parameter will be added as key="value" unless
        value is None, in which case only the key will be added.  If a
        parameter value contains non-ASCII characters it can be specified as a
        three-tuple of (charset, language, value), in which case it will be
        encoded according to RFC2231 rules.  Otherwise it will be encoded using
        the utf-8 charset and a language of ''.

        Examples:

        msg.add_header('content-disposition', 'attachment', filename='bud.gif')
        msg.add_header('content-disposition', 'attachment',
                       filename=('utf-8', '', Fußballer.ppt'))
        msg.add_header('content-disposition', 'attachment',
                       filename='Fußballer.ppt'))
        NrS�-r)r�r1r�r+�insert�	SEMISPACErM)rd�_name�_value�_params�partsr�r�s       rr�zMessage.add_header's��(���M�M�O�D�A�q��y����Q�Y�Y�s�C�0�1����\�!�)�)�C��*=�q�A�B�	$�
���L�L��F�#��n�n�U�+��U�rc�.�|j�}ttt|j��|j�D]F\}\}}|j�|k(s�|j
j
||�|j|<yt|��)z�Replace a header.

        Replace the first matching header found in the message, retaining
        header order and case.  If no matching header was found, a KeyError is
        raised.
        N)r0�zip�ranger!r\r[r��KeyError)rdr�r�r6r�r�s      r�replace_headerzMessage.replace_headerEsw�����
���U�3�t�}�}�#5�6��
�
�F�I�A�v��1��w�w�y�E�!�#'�;�;�#A�#A�!�V�#L��
�
�a� ��G�
�5�/�!rc���t�}|jd|�}||ur|j�St|�dj	�}|jd�dk7ry|S)a0Return the message's content type.

        The returned string is coerced to lower case of the form
        `maintype/subtype'.  If there was no Content-Type header in the
        message, the default type as given by get_default_type() will be
        returned.  Since according to RFC 2045, messages always have a default
        type this will always return a value.

        RFC 2045 defines a message's default type to be text/plain unless it
        appears inside a multipart/digest container, in which case it would be
        message/rfc822.
        �content-typer�/rrZ)�objectr��get_default_typerr0r.)rd�missingr*�ctypes    r�get_content_typezMessage.get_content_typeXsc���(�������1���G���(�(�*�*��E�"�1�%�+�+�-���;�;�s��q� ���rc�J�|j�}|jd�dS)z�Return the message's main content type.

        This is the `maintype' part of the string returned by
        get_content_type().
        r�r�r��split�rdr�s  r�get_content_maintypezMessage.get_content_maintypep�&���%�%�'���{�{�3���"�"rc�J�|j�}|jd�dS)z�Returns the message's sub-content type.

        This is the `subtype' part of the string returned by
        get_content_type().
        r�rr�r�s  r�get_content_subtypezMessage.get_content_subtypeyr�rc��|jS)aReturn the `default' content type.

        Most messages have a default content type of text/plain, except for
        messages that are subparts of multipart/digest containers.  Such
        subparts have a default content type of message/rfc822.
        �rcrhs rr�zMessage.get_default_type�s���!�!�!rc��||_y)z�Set the `default' content type.

        ctype should be either "text/plain" or "message/rfc822", although this
        is not enforced.  The default content type is not stored in the
        Content-Type header.
        Nr�r�s  r�set_default_typezMessage.set_default_type�s��#��rc�l�t�}|j||�}||ur|Sg}t|�D]K}	|jdd�\}}|j	�}|j	�}|j
||f��Mtj|�}|S#t
$r|j	�}d}Y�IwxYw)Nrrr)	r�r�r7r�rrIr1r�
decode_params)	rdr��headerr�r*�params�pr�r�s	         r�_get_params_preservezMessage._get_params_preserve�s����(�������)���G���N����U�#�A�
��G�G�C��O�	��c��z�z�|���i�i�k��

�M�M�4��+�&�$��$�$�V�,���
��
�
��w�w�y����
�s�5B�B3�2B3c��t�}|j||�}||ur|S|r |D��cgc]\}}|t|�f��c}}S|Scc}}w)amReturn the message's Content-Type parameters, as a list.

        The elements of the returned list are 2-tuples of key/value pairs, as
        split on the `=' sign.  The left hand side of the `=' is the key,
        while the right hand side is the value.  If there is no `=' sign in
        the parameter the value is the empty string.  The value is as
        described in the get_param() method.

        Optional failobj is the object to return if there is no Content-Type
        header.  Optional header is the header to search instead of
        Content-Type.  If unquote is True, the value is unquoted.
        )r�rr:)rdr�r�r9r�r�r�r�s        r�
get_paramszMessage.get_params�sZ���(���*�*�7�F�;���W���N��6<�=�f�d�a��Q�
�a�(�)�f�=�=��M��>s�Ac��||vr|S|j||�D]9\}}|j�|j�k(s�(|r
t|�cS|cS|S)a�Return the parameter value if found in the Content-Type header.

        Optional failobj is the object to return if there is no Content-Type
        header, or the Content-Type header has no such parameter.  Optional
        header is the header to search instead of Content-Type.

        Parameter keys are always compared case insensitively.  The return
        value can either be a string, or a 3-tuple if the parameter was RFC
        2231 encoded.  When it's a 3-tuple, the elements of the value are of
        the form (CHARSET, LANGUAGE, VALUE).  Note that both CHARSET and
        LANGUAGE can be None, in which case you should consider VALUE to be
        encoded in the us-ascii charset.  You can usually ignore LANGUAGE.
        The parameter value (either the returned string, or the VALUE item in
        the 3-tuple) is always unquoted, unless unquote is set to False.

        If your application doesn't care whether the parameter was RFC 2231
        encoded, it can turn the return value into a string as follows:

            rawparam = msg.get_param('foo')
            param = email.utils.collapse_rfc2231_value(rawparam)

        )rr0r:)rdrr�r�r9r�r�s       r�	get_paramzMessage.get_param�sZ��0����N��-�-�g�v�>�D�A�q��w�w�y�E�K�K�M�)��(��+�+��H�?��rc�f�t|t�s|r|||f}||vr|j�dk(rd}n|j|�}|j	||��s3|st|||�}n�tj|t|||�g�}nwd}|j||��D]_\}	}
d}|	j�|j�k(rt|||�}n
t|	|
|�}|s|}�Itj||g�}�a||j|�k7r|r|j||�y||=|||<yy)a�Set a parameter in the Content-Type header.

        If the parameter already exists in the header, its value will be
        replaced with the new value.

        If header is Content-Type and has not yet been defined for this
        message, it will be set to "text/plain" and the new parameter and
        value will be appended as per RFC 2045.

        An alternate header can be specified in the header argument, and all
        parameters will be quoted as necessary unless requote is False.

        If charset is specified, the parameter will be encoded according to RFC
        2231.  Optional language specifies the RFC 2231 language, defaulting
        to the empty string.  Both charset and language should be strings.
        r�rZ)r�r�r�r9N)
r"r#r0r�rr+r�rMrr�)rdrr*r��requoter�languager�r��	old_param�	old_value�append_params            rr�zMessage.set_param�s<��$�%��'�G��h��.�E����&�,�,�.�N�"B� �E��H�H�V�$�E��~�~�e�F�~�3��$�U�E�7�;��!����L���w�?�@�B���E�(,���v�@G�)8�)I�$�	�9�!���?�?�$����
�5�#/��u�g�#F�L�#/�	�9�g�#N�L��(�E�%�N�N�E�<�+@�A�E�)I��D�H�H�V�$�$���#�#�F�E�2���L�$��V��%rc	�*�||vryd}|j||��D]Y\}}|j�|j�k7s�(|st|||�}�8tj	|t|||�g�}�[||j|�k7r	||=|||<yy)a>Remove the given parameter completely from the Content-Type header.

        The header will be re-written in place without the parameter or its
        value. All values will be quoted as necessary unless requote is
        False.  Optional header specifies an alternative to the Content-Type
        header.
        Nrr)rr0r+r�rMr�)rdrr�r�	new_ctyperr�s       rr�zMessage.del_params��������	��O�O�6�7�O�C�D�A�q��w�w�y�E�K�K�M�)� � ,�Q��7� ;�I� )���	�0<�Q��7�0K�0M�!N�I�D������(�(��V��$�D��L�)rc��|jd�dk(st�|j�dk(r|d=d|d<||vr|||<y|j||��}||=|||<|ddD]\}}|j	||||��y)	aKSet the main type and subtype for the Content-Type header.

        type must be a string in the form "maintype/subtype", otherwise a
        ValueError is raised.

        This method replaces the Content-Type header, keeping all the
        parameters in place.  If requote is False, this leaves the existing
        header's quoting as is.  Otherwise, the parameters will be quoted (the
        default).

        An alternative header can be specified in the header argument.  When
        the Content-Type header is set, we'll always also add a MIME-Version
        header.
        r�rr�zmime-versionr�r�Nr)r.rIr0rr�)rdr�r�rr�rr�s       r�set_typezMessage.set_type*s��� �z�z�#��!�#����<�<�>�^�+��^�$�#(�D�� �����D��L��������@����L���V���1�2�J�D�A�q��N�N�1�a���1�rc��t�}|jd|d�}||ur|jd|d�}||ur|Stj|�j	�S)a@Return the filename associated with the payload if present.

        The filename is extracted from the Content-Disposition header's
        `filename' parameter, and it is unquoted.  If that header is missing
        the `filename' parameter, this method falls back to looking for the
        `name' parameter.
        �filename�content-dispositionr�r�)r�rr�collapse_rfc2231_valuer)rdr�r�rs    r�get_filenamezMessage.get_filenameJs_���(���>�>�*�g�7L�M���w���~�~�f�g�~�F�H��w���N��+�+�H�5�;�;�=�=rc��t�}|jd|�}||ur|Stj|�j	�S)z�Return the boundary associated with the payload if present.

        The boundary is extracted from the Content-Type header's `boundary'
        parameter, and it is unquoted.
        �boundary)r�rrr�rstrip)rdr�r�rs    r�get_boundaryzMessage.get_boundaryZsB���(���>�>�*�g�6���w���N��+�+�H�5�<�<�>�>rc��t�}|j|d�}||urtjd��g}d}|D]D\}}|j	�dk(r|jdd|zf�d}�2|j||f��F|s|jdd|zf�g}|jD]�\}	}
|	j	�dk(rzg}|D]2\}}
|
dk(r|j|��|j|�d|
����4tj|�}
|j|jj|	|
����|j|	|
f���||_y	)
a�Set the boundary parameter in Content-Type to 'boundary'.

        This is subtly different than deleting the Content-Type header and
        adding a new one with a new boundary parameter via add_header().  The
        main difference is that using the set_boundary() method preserves the
        order of the Content-Type header in the original message.

        HeaderParseError is raised if the message has no Content-Type header.
        r�zNo Content-Type header foundFrz"%s"TrrN)r�rr�HeaderParseErrorr0r1r\r�rMr[r�)rdrr�r��	newparams�foundp�pk�pvr��hr�r�r�r�s              r�set_boundaryzMessage.set_boundarygsT���(���*�*�7�N�C���W���)�)�*H�I�I��	����F�B���x�x�z�Z�'�� � �*�f�x�.?�!@�A���� � �"�b��*���
���j�&�8�*;�<�=��
��M�M�D�A�q��w�w�y�N�*���%�D�A�q��B�w����Q������1�%5�6�	&�
 �n�n�U�+���!�!�$�+�+�"@�"@��C�"H�I��!�!�1�a�&�)�"�#��
rc�T�t�}|jd|�}||ur|St|t�r*|dxsd}	|dj	d�}t||�}	|j	d�|j�S#ttf$r|d}Y�8wxYw#t$r|cYSwxYw)z�Return the charset parameter of the Content-Type header.

        The returned string is always coerced to lower case.  If there is no
        Content-Type header, or if that header has no charset parameter,
        failobj is returned.
        rrzus-asciirr�)	r�rr"r#r%rr�r�r0)rdr�r�r�pcharsetrvs      rr�zMessage.get_content_charset�s����(���.�.��G�4���g���N��g�u�%��q�z�/�Z�H�
%�#�1�:�,�,�-A�B���h��1��	��N�N�:�&��}�}���� ��.�
%�!�!�*��
%��
�	��N�	�s#� A?�B�?B�B�B'�&B'c�f�|j�D�cgc]}|j|���c}Scc}w)a�Return a list containing the charset(s) used in this message.

        The returned list of items describes the Content-Type headers'
        charset parameter for this message and all the subparts in its
        payload.

        Each item will either be a string (the value of the charset parameter
        in the Content-Type header of that part) or the value of the
        'failobj' parameter (defaults to None), if the part does not have a
        main MIME type of "text", or the charset is not defined.

        The list will contain one string for each part of the message, plus
        one for the container message (i.e. self), so that a non-multipart
        message will still return a list of length 1.
        )�walkr�)rdr��parts   r�get_charsetszMessage.get_charsets�s.�� ?C�i�i�k�J�k�d��(�(��1�k�J�J��Js�.c�f�|jd�}|�yt|�dj�}|S)z�Return the message's content-disposition if it exists, or None.

        The return values can be either 'inline', 'attachment' or None
        according to the rfc2183.
        rNr)r�rr0)rdr*�c_ds   r�get_content_dispositionzMessage.get_content_disposition�s8�����.�/���=���%� ��#�)�)�+���
r)r%)FrN)FN)NFr~)Nr�T)r�TNrF)r�T)r�T)4�__name__�
__module__�__qualname__�__doc__r	rerirgrwrvr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�r�rrrr!r�r'r*�email.iteratorsr%�rrrr�s��
�'�
*� �
�0�

�/�"��:� Z�x&�(-B�^�"�	�H�$
#���-�	+�	+�
�",�*��$,�<
"�&�0#�#�"�#��*�,5C�� �DFJ�5:�1%�f%�,2�@>� ?�,#�\�<K�$
�%rc���eZdZd�fd�	Zd�fd�	Zd�Zd�Zd�Zdd�Zhd�Z	d	�Z
d
�Zdd�d�Zdd�d
�Z
d�Zdd�Zdd�Zdd�Zdd�d�Zd�Zd�Zd�Zd�Zd�Z�xZS)�MIMEPartNc�8��|�ddlm}|}t�|�
|�y)Nr)�default)�email.policyr4�superre)rdr[r4�	__class__s   �rrezMIMEPart.__init__�s����>�,��F�
���� rc�b��|�|jn|}|�|j}t�|�
|||�S)aReturn the entire formatted message as a string.

        Optional 'unixfrom', when true, means include the Unix From_ envelope
        header.  maxheaderlen is retained for backward compatibility with the
        base Message class, but defaults to None, meaning that the policy value
        for max_line_length controls the header maximum length.  'policy' is
        passed to the Generator instance used to serialize the message; if it
        is not specified the policy associated with the message instance is
        used.
        )r[�max_line_lengthr6rg)rdrormr[r7s    �rrgzMIMEPart.as_string�s9���!'�����F����!�1�1�L��w� ��<��@�@rc�Z�|j|jjd����S)NT)�utf8�r[)rgr[�clonerhs rrizMIMEPart.__str__�s%���~�~�T�[�[�%6�%6�D�%6�%A�~�B�Brc�J�|jd�}|�dS|jdk(S)NrF�
attachment)r��content_disposition)rdr)s  r�
is_attachmentzMIMEPart.is_attachment�s+���h�h�,�-����u�P��)@�)@�L�)P�Prc#�\K�|j�ry|j�jd�\}}|dk(r||vr|j|�|f��y|dk7s|j	�sy|dk7r0|j�D]}|j
||�Ed{����yd|vr|jd�|f��d}|jd�}|r!|j�D]}|d|k(s�|}n|�|j�}|r|dnd}|�|j
||�Ed{���yy7��7��w)Nr��text�	multipart�related�start�
content-idr)	rAr�r�r/r|�
iter_parts�
_find_bodyrr�)	rdr&�preferencelist�maintype�subtype�subpart�	candidaterF�subpartss	         rrIzMIMEPart._find_body�sK��������� �1�1�3�9�9�#�>���'��v���.�(�%�+�+�G�4�d�;�;���{�"�$�*;�*;�*=���i���?�?�,���?�?�7�N�C�C�C�-����&�!�'�'�	�2�D�9�9��	����w�'����?�?�,���<�(�E�1� '�I��-����'�'�)�H�'/����T�I�� ����y�.�A�A�A�!�D��
B�s+�BD,�D(�AD,�*7D,�!D*�"D,�*D,c�x�t|�}d}|j||�D]\}}||ks�|}|}|dk(s�|S|S)aReturn best candidate mime part for display as 'body' of message.

        Do a depth first search, starting with self, looking for the first part
        matching each of the items in preferencelist, and return the part
        corresponding to the first item that has a match, or None if no items
        have a match.  If 'related' is not included in preferencelist, consider
        the root part of any multipart/related encountered as a candidate
        match.  Ignore parts with 'Content-Disposition: attachment'.
        Nr)r!rI)rdrJ�	best_prio�body�prior&s      r�get_bodyzMIMEPart.get_bodysU����'�	����/�/�$��?�J�D�$��i�� �	����1�9����
@��r>�rC�html�rC�plain�rDrE�rD�alternativec#�K�|j�jd�\}}|dk7s|dk(ry|j�}	|j�}|dk(rt|dk(ro|jd�}|r@d}g}|D]*}|j
d�|k(rd	}�|j|��,|r|Ed{���y|jd
�|Ed{���yg}	|D]^}|j�jd�\}}||f|jvr&|j�s||	vr|	j|��[|���`y#t$rYywxYw7��7�|�w)aReturn an iterator over the non-main parts of a multipart.

        Skip the first of each occurrence of text/plain, text/html,
        multipart/related, or multipart/alternative in the multipart (unless
        they have a 'Content-Disposition: attachment' header) and include all
        remaining subparts in the returned iterator.  When applied to a
        multipart/related, return all parts except the root part.  Return an
        empty iterator when applied to a multipart/alternative or a
        non-multipart.
        r�rDr[NrErFFrGTr)r�r�r�r�r�rr�r1�pop�_body_typesrA)
rdrKrLr�r�rFr��attachmentsr&�seens
          r�iter_attachmentszMIMEPart.iter_attachments*sb����!�1�1�3�9�9�#�>���'��{�"�g��&>���"�"�$��	��L�L�N�E�
�{�"�w�)�';��N�N�7�+�E���� ��!�D��x�x��-��6� $��#�*�*�4�0�	"�
�*�*�*���I�I�a�L��������D� $� 5� 5� 7� =� =�c� B��H�g��7�#�t�'7�'7�7��*�*�,���1D����G�$���J�
��7�	��	��$+��
�sI�>E�D0�AE�(D?�)E�E�A+E�0	D<�9E�;D<�<E�Ec#�bK�|j�r|j�Ed{���yy7��w)z~Return an iterator over all immediate subparts of a multipart.

        Return an empty iterator for a non-multipart.
        N)r|r�rhs rrHzMIMEPart.iter_partsas.����
�����'�'�)�)�)��)�s�$/�-�/)�content_managerc�^�|�|jj}|j|g|��i|��Sr~)r[rc�get_content�rdrc�args�kws    rrezMIMEPart.get_contentis4���"�"�k�k�9�9�O�*��*�*�4�=�$�=�"�=�=rc�`�|�|jj}|j|g|��i|��yr~)r[rc�set_contentrfs    rrjzMIMEPart.set_contentns1���"�"�k�k�9�9�O�#��#�#�D�6�4�6�2�6rc�$�|j�dk(r5|j�}||fz}||vrtdj||���g}g}|jD]K\}}|j�j
d�r|j||f��9|j||f��M|r=t|�|j��}	||	_|j|	_
|	g|_
ng|_
||_d|z|d<|�|jd|�yy)NrDzCannot convert {} to {}�content-r<z
multipart/r�r)r�r�rIr�r\r0rFr1r�r[r^r�)
rdrL�disallowed_subtypesr�existing_subtype�keep_headers�part_headersr�r*r&s
          r�_make_multipartzMIMEPart._make_multipartss���$�$�&�+�5�#�7�7�9��"5��
�"B���#6�6� �!:�!A�!A�$�g�"/�0�0������=�=�K�D�%��z�z�|�&�&�z�2��#�#�T�5�M�2��#�#�T�5�M�2�	)�
��4��:�T�[�[�1�D�(�D�M� �M�M�D�M�!�F�D�M��D�M�$��
�+�g�5��^�����N�N�:�x�0� rc�*�|jdd|�y)NrE)r[�mixed�rq�rdrs  r�make_relatedzMIMEPart.make_related�s�����Y�(@�(�Krc�*�|jdd|�y)Nr[)rsrtrus  r�make_alternativezMIMEPart.make_alternative�s�����]�J��Arc�*�|jdd|�y)Nrsr0rtrus  r�
make_mixedzMIMEPart.make_mixed�s�����W�b�(�3r)�_dispc��|j�dk7s|j�|k7rt|d|z��t|�|j��}|j
|i|��|r	d|vr||d<|j
|�y)NrD�make_r<rzContent-Disposition)r�r��getattrr�r[rjr�)rd�_subtyper{rgrhr&s      r�_add_multipartzMIMEPart._add_multipart�s����%�%�'�;�6��(�(�*�h�6�-�G�D�'�H�,�-�/��t�D�z����-������$�%�"�%��*�$�6�*/�D�&�'����D�rc�4�|jdg|��ddi|��y)NrEr{�inline�r��rdrgrhs   r�add_relatedzMIMEPart.add_related�s!������I�C��C�H�C��Crc�0�|jdg|��i|��y)Nr[r�r�s   r�add_alternativezMIMEPart.add_alternative�s������M�7�D�7�B�7rc�4�|jdg|��ddi|��y)Nrsr{r?r�r�s   r�add_attachmentzMIMEPart.add_attachment�s!������G�E�d�E�,�E�"�Erc� �g|_d|_yr~)r\r^rhs r�clearzMIMEPart.clear�s����
���
rc��|jD��cgc](\}}|j�jd�s||f��*c}}|_d|_ycc}}w)Nrl)r\r0rFr^)rd�nr�s   r�
clear_contentzMIMEPart.clear_content�sN��,0�M�M�B�M�D�A�q� !���	� 4� 4�Z� @��Q��M�B��
���
��Bs�-Ar~)FNN))rErVrX)r+r,r-rergrirArIrTr^rarHrerjrqrvrxrzr�r�r�r�r�r��
__classcell__�r7s@rr2r2�s����!�A� C�Q�B�:�(1�K�5�n*�26�>�
26�7�
1�6L�B�4�59��D�8�F��rr2c���eZdZ�fd�Z�xZS)rc�8��t�|�|i|��d|vrd|d<yy)Nr�r�)r6rj)rdrgrhr7s   �rrjzEmailMessage.set_content�s,���
���T�(�R�(���%�#(�D�� �&r)r+r,r-rjr�r�s@rrr�s
���)�)r)NT)r.�__all__rJ�rer��iorr�emailrr�email._policybaser	rr_�email._encoded_wordsrr�r��compiler'rr+r7r:rWrr2rr0rr�<module>r�s���
?��n�
%���	�
� ���&�%�)�
�
�
���	�
�B�J�J�2�3�	� � �D�($�#�>K
%�K
%�\\�w�\�~)�8�)r__pycache__/message.cpython-312.opt-2.pyc000064400000107673151706203560014066 0ustar00�

T��hW����	ddgZddlZddlZddlZddlmZmZddlmZddlm	Z	ddl
mZddlmZ
dd	lmZe
j Zd
Zej$d�Zd�Zdd
�Zd�Zd�Zd�ZGd�d�ZGd�de�ZGd�de�Zy)�Message�EmailMessage�N)�BytesIO�StringIO)�utils)�errors)�compat32��charset)�decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]c��t|�jd�\}}}|s|j�dfS|j�|j�fS)N�;)�str�	partition�strip)�param�a�sep�bs    �&/usr/lib64/python3.12/email/message.py�_splitparamrsH��
�E�
�$�$�S�)�I�A�s�A���w�w�y�$����7�7�9�a�g�g�i���c��	|��t|�dkDr�t|t�r,|dz
}tj|d|d|d�}|�d|��S	|jd�|stj|�r|�d	tj|��d
�S|�d|��S|S#t$r&|dz
}tj|dd�}|�d|��cYSwxYw)Nr�*���=�asciizutf-8�z="�")
�len�
isinstance�tupler�encode_rfc2231�encode�UnicodeEncodeError�	tspecials�search�quote)r�valuer)s   r�_formatparamr+'s����
��S��Z�!�^��e�U�#��S�L�E��(�(��q��5��8�U�1�X�F�E�#�U�+�+�
0����W�%��I�$�$�U�+� %�u�{�{�5�'9�:�:�#�U�+�+����&�
0������,�,�U�G�R�@��"'��/�/�
0�s�B�,C
�	C
c�r�dt|�z}g}|dddk(�r|dd}|jd�}|dkDro|jdd|�|jdd|�z
dzrE|jd|dz�}|dkDr+|jdd|�|jdd|�z
dzr�E|dkrt|�}|d|}d|vrL|j	d�}|d|j�j
�dz||dzdj�z}|j|j��||d}|dddk(r��|S)Nrrrr z\"rr)r�find�countr!�indexr�lower�append)�s�plist�end�f�is     r�_parseparamr7Is?���c�!�f��A��E�
�B�Q�%�3�,�
�a�b�E���f�f�S�k���A�g�1�7�7�3��3�/�!�'�'�%��C�2H�H�A�M��&�&��c�A�g�&�C��A�g�1�7�7�3��3�/�!�'�'�%��C�2H�H�A�M���7��a�&�C�
�d�s�G���!�8������A��"�1����
�#�#�%��+�a��!���g�m�m�o�=�A�
���Q�W�W�Y��
�c�d�G���B�Q�%�3�,��Lrc��t|t�r!|d|dtj|d�fStj|�S)Nrrr)r"r#r�unquote)r*s r�
_unquotevaluer:]s?��
�%����Q�x��q��5�=�=��q��#:�:�:��}�}�U�#�#rc�T�	g}t|j��}|D]G}|jd�s�|jd�j	d�\}}}	t|d��nt
d��|D]L}|st
d��|jd�dk(rn)	tj|�}|j|��Ndj|�S#t$rY��wxYw#tj$r/|d	d
z
dzdzd
zdz}tj|d|�}Y�twxYw)Nsbegin � �)�basez`begin` line not foundzTruncated inputs 	
sendr� �?���r)
�iter�
splitlines�
startswith�removeprefixr�int�
ValueErrorr�binascii�a2b_uu�Errorr1�join)	�encoded�
decoded_lines�encoded_lines_iter�line�mode�_�path�decoded_line�nbytess	         r�
_decode_uurWhs5�� ��M��g�0�0�2�3��"���?�?�9�%� �-�-�i�8�B�B�4�H�M�D�!�T�
��D�q�!��#��1�2�2�"����.�/�/�
�Z�Z��
%��
/��	:�#�?�?�4�0�L�
	���\�*�#��8�8�M�"�"��'�
��
���~�~�	:��Q���
�b�(�A�-��1�a�7�F�#�?�?�4���=�9�L�	:�s$�
C�C%�	C"�!C"�%?D'�&D'c�R�eZdZ	efd�Zd�Zd1d�Zd�Zd2d�Zd�Z	d	�Z
d
�Zd�Zd3d�Z
d4d
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd4d�Zd�Zd�Zd4d�Zd�Zd�Zd�Z d �Z!d!�Z"d"�Z#d#�Z$d$�Z%d5d%�Z&		d5d&�Z'		d6d'�Z(d7d(�Z)d8d)�Z*d4d*�Z+d4d+�Z,d,�Z-d4d-�Z.d4d.�Z/d/�Z0dd0l1m2Z2y)9rc��||_g|_d|_d|_d|_dx|_|_g|_d|_y)N�
text/plain)	�policy�_headers�	_unixfrom�_payload�_charset�preamble�epilogue�defects�
_default_type)�selfr[s  r�__init__zMessage.__init__�sB�������
������
���
�(,�,��
��
����)��rc�$�	|j�S�N)�	as_string�rds r�__str__zMessage.__str__�s��	��~�~��rrNc��	ddlm}|�|jn|}t�}||d||��}|j	||��|j�S)Nr)�	GeneratorF)�mangle_from_�maxheaderlenr[��unixfrom)�email.generatorrlr[r�flatten�getvalue)rdrprnr[rl�fp�gs       rrhzMessage.as_string�sU��	�	.� &�����F��
�Z���b�#(�#/�#�
%��	
�	�	�$��	�*��{�{�}�rc�$�	|j�Srg)�as_bytesris r�	__bytes__zMessage.__bytes__�s��	��}�}��rc��	ddlm}|�|jn|}t�}||d|��}|j	||��|j�S)Nr)�BytesGeneratorF)rmr[ro)rqrzr[rrrrs)rdrpr[rzrtrus      rrwzMessage.as_bytes�sL��	�	3� &�����F��
�Y���2�E�&�A��	�	�	�$��	�*��{�{�}�rc�8�	t|jt�Srg)r"r^�listris r�is_multipartzMessage.is_multipart�s��D��$�-�-��.�.rc��||_yrg�r])rdrps  r�set_unixfromzMessage.set_unixfrom�s	��!��rc��|jSrgrris r�get_unixfromzMessage.get_unixfrom�s���~�~�rc��	|j�	|g|_y	|jj|�y#t$rtd��wxYw)Nz=Attach is not valid on a message with a non-multipart payload)r^r1�AttributeError�	TypeError)rd�payloads  r�attachzMessage.attach�sT��	��=�=� �$�I�D�M�
:��
�
�$�$�W�-��!�
:��!9�:�:�
:�s	�4�A	c��	|j�r |ry|�|jS|j|S|�;t|jt�s!t	dt|j�z��|j}|j
dd�}t|d�r
|j}n't|�j�j�}|s^t|t�rLtj|�r7	|jdd�}	|j|j!d�d�}|S|St|t�r	|jdd�}|d	k(rt'j(�S|d
k(rPt+dj-j/���\}}|D]}|j0j3||�� |S|dvr	t5�St|t�rS|S#t"$r|jdd�}Y|SwxYw#t$$rY|SwxYw#t$$r|jd�}Y��wxYw#t6$rcYSwxYw)
NzExpected list, got %szcontent-transfer-encodingr�cter�surrogateescape�replace�raw-unicode-escapezquoted-printable�base64r)z
x-uuencode�uuencode�uuezx-uue)r}r^r"r|r��type�get�hasattrr�rrr0r�_has_surrogatesr%�decode�get_content_charset�LookupErrorr&�quopri�decodestringrrMrEr[�
handle_defectrWrI)	rdr6r�r�r��bpayloadr*rb�defects	         r�get_payloadzMessage.get_payload�s=��	�B�������y��}�}�$��}�}�Q�'�'�
�=��D�M�M�4�!@��3�d�4�=�=�6I�I�J�J��-�-���h�h�2�B�7���3����'�'�C��c�(�.�.�"�(�(�*�C���'�3�'�E�,A�,A�'�,J��&�~�~�g�7H�I�H�F�"*�/�/�$�2J�2J�7�2S�U^�"_��
�N�7�N��g�s�#�
@�"�>�>�'�3D�E���$�$��&�&�x�0�0�
�H�_�&�c�h�h�x�/B�/B�/D�&E�F�N�E�7�!�����)�)�$��7�"��L�
�>�
>�
 �!�(�+�+��g�s�#��O����?'�F�"*�/�/�'�9�"E���N�	F��)����N���&�
@�
#�>�>�*>�?��
@��$�
 ���
 �sT�5H�!G#�>H�
H5�#H�>H�H�H�	H�H�H2�1H2�5I�Ic��	t|d�rA|�||_yt|t�st|�}|j	|j
d�}t|d�r|j
dd�|_n||_|�|j|�yy)Nr%r�r�r)r�r^r"�Charsetr%�output_charsetr��set_charset)rdr�rs   r�set_payloadzMessage.set_payloadOs���	�
�7�H�%��� '��
���g�w�/�!�'�*���n�n�W�%;�%;�=N�O�G��7�H�%�#�N�N�7�4E�F�D�M�#�D�M������W�%�rc���	|�|jd�d|_yt|t�st|�}||_d|vr|j	dd�d|vr#|j	dd|j���n |j
d|j��||j�k7r |j|j�|_d|vr|j�}	||�yy#t$rw|j}|r>	|jdd	�}n*#t$r|j|j�}YnwxYw|j|�|_|j	d|�YywxYw)
Nr�MIME-Version�1.0�Content-TyperZr
zContent-Transfer-Encodingrr�)�	del_paramr_r"r��
add_header�get_output_charset�	set_param�body_encoder^�get_body_encodingr�r%�UnicodeErrorr�)rdrr�r�s    rr�zMessage.set_charsetcse��	��?��N�N�9�%� �D�M���'�7�+��g�&�G���
���%��O�O�N�E�2���%��O�O�N�L�$+�$>�$>�$@�
�
B�
�N�N�9�g�&@�&@�&B�C��g�0�0�2�2�#�/�/��
�
�>�D�M�&�d�2��+�+�-�C�

B��D�	�3���
B��-�-���I�")�.�.��:K�"L���'�I�")�.�.��1G�1G�"H��I�� '� 3� 3�G� <��
���� ;�S�A�
B�s6�$C.�.E.�D�E.�$E�=E.�?E�+E.�-E.c��	|jSrg)r_ris r�get_charsetzMessage.get_charset�s��	��}�}�rc�.�	t|j�Srg)r!r\ris r�__len__zMessage.__len__�s��G��4�=�=�!�!rc�&�	|j|�Srg)r�)rd�names  r�__getitem__zMessage.__getitem__�s��	��x�x��~�rc�h�	|jj|�}|r_|j�}d}|jD]>\}}|j�|k(s�|dz
}||k\s�%t	dj||���|jj
|jj||��y)Nrrz/There may be at most {} {} headers in a message)r[�header_max_countr0r\rI�formatr1�header_store_parse)rdr��val�	max_count�lname�found�k�vs        r�__setitem__zMessage.__setitem__�s���	�
�K�K�0�0��6�	���J�J�L�E��E��
�
���1��7�7�9��%��Q�J�E��	�)�(�*8�8>��y�$�8O�Q�Q�	&�	
�
�
���T�[�[�;�;�D�#�F�Grc��	|j�}g}|jD],\}}|j�|k7s�|j||f��.||_yrg)r0r\r1)rdr��
newheadersr�r�s     r�__delitem__zMessage.__delitem__�sT��	��z�z�|���
��M�M�D�A�q��w�w�y�D� ��!�!�1�a�&�)�"�#��
rc�v�|j�}|jD]\}}||j�k(s�yy)NTF)r0r\)rdr��
name_lowerr�r�s     r�__contains__zMessage.__contains__�s5���Z�Z�\�
��M�M�D�A�q��Q�W�W�Y�&��"�rc#�<K�|jD]	\}}|���y�wrg�r\)rd�fieldr*s   r�__iter__zMessage.__iter__�s���� �M�M�L�E�5��K�*�s�c�N�	|jD��cgc]\}}|��	c}}Scc}}wrgr��rdr�r�s   r�keyszMessage.keys�s)��	�#�m�m�,�m�d�a���m�,�,��,s�!c��	|jD��cgc]!\}}|jj||���#c}}Scc}}wrg�r\r[�header_fetch_parser�s   r�valueszMessage.values�sG��	�!�M�M�+�)�D�A�q����.�.�q�!�4�)�+�	+��+s�&;c	��	|jD��cgc]#\}}||jj||�f��%c}}Scc}}wrgr�r�s   r�itemsz
Message.items�sL��	�!�M�M�+�)�D�A�q��D�K�K�2�2�1�a�8�9�)�+�	+��+s�(=c��	|j�}|jD]6\}}|j�|k(s�|jj||�cS|Srg)r0r\r[r�)rdr��failobjr�r�s     rr�zMessage.get�sR��	�
�z�z�|���M�M�D�A�q��w�w�y�D� ��{�{�5�5�a��;�;�"��rc�@�	|jj||f�yrg)r\r1)rdr�r*s   r�set_rawzMessage.set_raws��	�	
�
�
���d�E�]�+rc�J�	t|jj��Srg)rDr\�copyris r�	raw_itemszMessage.raw_items
s!��	��D�M�M�&�&�(�)�)rc���	g}|j�}|jD]D\}}|j�|k(s�|j|jj	||���F|s|S|Srg)r0r\r1r[r�)rdr�r�r�r�r�s      r�get_allzMessage.get_allse��	����z�z�|���M�M�D�A�q��w�w�y�D� ��
�
�d�k�k�<�<�Q��B�C�"���N��
rc	�0�	g}|j�D]T\}}|�"|j|jdd���*|jt|jdd�|���V|�|j	d|�t
j
|�||<y)NrS�-r)r�r1r�r+�insert�	SEMISPACErM)rd�_name�_value�_params�partsr�r�s       rr�zMessage.add_header's���	�&���M�M�O�D�A�q��y����Q�Y�Y�s�C�0�1����\�!�)�)�C��*=�q�A�B�	$�
���L�L��F�#��n�n�U�+��U�rc�0�	|j�}ttt|j��|j�D]F\}\}}|j�|k(s�|j
j
||�|j|<yt|��rg)r0�zip�ranger!r\r[r��KeyError)rdr�r�r6r�r�s      r�replace_headerzMessage.replace_headerEs|��	����
���U�3�t�}�}�#5�6��
�
�F�I�A�v��1��w�w�y�E�!�#'�;�;�#A�#A�!�V�#L��
�
�a� ��G�
�5�/�!rc���	t�}|jd|�}||ur|j�St|�dj	�}|jd�dk7ry|S)N�content-typer�/rrZ)�objectr��get_default_typerr0r.)rd�missingr*�ctypes    r�get_content_typezMessage.get_content_typeXsh��	��(�������1���G���(�(�*�*��E�"�1�%�+�+�-���;�;�s��q� ���rc�L�	|j�}|jd�dS)Nr�r�r��split�rdr�s  r�get_content_maintypezMessage.get_content_maintypep�+��	�
�%�%�'���{�{�3���"�"rc�L�	|j�}|jd�dS)Nr�rr�r�s  r�get_content_subtypezMessage.get_content_subtypeyr�rc��	|jSrg�rcris rr�zMessage.get_default_type�s��	��!�!�!rc��	||_yrgr�r�s  r�set_default_typezMessage.set_default_type�s��	�#��rc�l�t�}|j||�}||ur|Sg}t|�D]K}	|jdd�\}}|j	�}|j	�}|j
||f��Mtj|�}|S#t
$r|j	�}d}Y�IwxYw)Nrrr)	r�r�r7r�rrIr1r�
decode_params)	rdr��headerr�r*�params�pr�r�s	         r�_get_params_preservezMessage._get_params_preserve�s����(�������)���G���N����U�#�A�
��G�G�C��O�	��c��z�z�|���i�i�k��

�M�M�4��+�&�$��$�$�V�,���
��
�
��w�w�y����
�s�5B�B3�2B3c��	t�}|j||�}||ur|S|r |D��cgc]\}}|t|�f��c}}S|Scc}}wrg)r�rr:)rdr�r�r9r�r�r�r�s        r�
get_paramszMessage.get_params�s_��	��(���*�*�7�F�;���W���N��6<�=�f�d�a��Q�
�a�(�)�f�=�=��M��>s�Ac��	||vr|S|j||�D]9\}}|j�|j�k(s�(|r
t|�cS|cS|Srg)rr0r:)rdrr�r�r9r�r�s       r�	get_paramzMessage.get_param�s_��	�,����N��-�-�g�v�>�D�A�q��w�w�y�E�K�K�M�)��(��+�+��H�?��rc�h�	t|t�s|r|||f}||vr|j�dk(rd}n|j|�}|j	||��s3|st|||�}n�tj|t|||�g�}nwd}|j||��D]_\}	}
d}|	j�|j�k(rt|||�}n
t|	|
|�}|s|}�Itj||g�}�a||j|�k7r|r|j||�y||=|||<yy)Nr�rZ)r�r�r�r9)
r"r#r0r�rr+r�rMrr�)rdrr*r��requoter�languager�r��	old_param�	old_value�append_params            rr�zMessage.set_param�sA��	� �%��'�G��h��.�E����&�,�,�.�N�"B� �E��H�H�V�$�E��~�~�e�F�~�3��$�U�E�7�;��!����L���w�?�@�B���E�(,���v�@G�)8�)I�$�	�9�!���?�?�$����
�5�#/��u�g�#F�L�#/�	�9�g�#N�L��(�E�%�N�N�E�<�+@�A�E�)I��D�H�H�V�$�$���#�#�F�E�2���L�$��V��%rc	�,�	||vryd}|j||��D]Y\}}|j�|j�k7s�(|st|||�}�8tj	|t|||�g�}�[||j|�k7r	||=|||<yy)Nrr)rr0r+r�rMr�)rdrr�r�	new_ctyperr�s       rr�zMessage.del_params���	������	��O�O�6�7�O�C�D�A�q��w�w�y�E�K�K�M�)� � ,�Q��7� ;�I� )���	�0<�Q��7�0K�0M�!N�I�D������(�(��V��$�D��L�)rc��	|jd�dk(st�|j�dk(r|d=d|d<||vr|||<y|j||��}||=|||<|ddD]\}}|j	||||��y)Nr�rr�zmime-versionr�r�r)r.rIr0rr�)rdr�r�rr�rr�s       r�set_typezMessage.set_type*s���
	��z�z�#��!�#����<�<�>�^�+��^�$�#(�D�� �����D��L��������@����L���V���1�2�J�D�A�q��N�N�1�a���1�rc��	t�}|jd|d�}||ur|jd|d�}||ur|Stj|�j	�S)N�filename�content-dispositionr�r�)r�rr�collapse_rfc2231_valuer)rdr�r�rs    r�get_filenamezMessage.get_filenameJsd��	��(���>�>�*�g�7L�M���w���~�~�f�g�~�F�H��w���N��+�+�H�5�;�;�=�=rc��	t�}|jd|�}||ur|Stj|�j	�S)N�boundary)r�rrr�rstrip)rdr�r�rs    r�get_boundaryzMessage.get_boundaryZsG��	�
�(���>�>�*�g�6���w���N��+�+�H�5�<�<�>�>rc��	t�}|j|d�}||urtjd��g}d}|D]D\}}|j	�dk(r|jdd|zf�d}�2|j||f��F|s|jdd|zf�g}|jD]�\}	}
|	j	�dk(rzg}|D]2\}}
|
dk(r|j|��|j|�d|
����4tj|�}
|j|jj|	|
����|j|	|
f���||_y)	Nr�zNo Content-Type header foundFrz"%s"Trr)r�rr�HeaderParseErrorr0r1r\r�rMr[r�)rdrr�r��	newparams�foundp�pk�pvr��hr�r�r�r�s              r�set_boundaryzMessage.set_boundarygsY��	��(���*�*�7�N�C���W���)�)�*H�I�I��	����F�B���x�x�z�Z�'�� � �*�f�x�.?�!@�A���� � �"�b��*���
���j�&�8�*;�<�=��
��M�M�D�A�q��w�w�y�N�*���%�D�A�q��B�w����Q������1�%5�6�	&�
 �n�n�U�+���!�!�$�+�+�"@�"@��C�"H�I��!�!�1�a�&�)�"�#��
rc�V�	t�}|jd|�}||ur|St|t�r*|dxsd}	|dj	d�}t||�}	|j	d�|j�S#ttf$r|d}Y�8wxYw#t$r|cYSwxYw)Nrrzus-asciirr�)	r�rr"r#r%rr�r�r0)rdr�r�r�pcharsetrws      rr�zMessage.get_content_charset�s���	��(���.�.��G�4���g���N��g�u�%��q�z�/�Z�H�
%�#�1�:�,�,�-A�B���h��1��	��N�N�:�&��}�}���� ��.�
%�!�!�*��
%��
�	��N�	�s#� B�B�B�B�B(�'B(c�h�	|j�D�cgc]}|j|���c}Scc}wrg)�walkr�)rdr��parts   r�get_charsetszMessage.get_charsets�s3��	�?C�i�i�k�J�k�d��(�(��1�k�J�J��Js�/c�h�	|jd�}|�yt|�dj�}|S)Nrr)r�rr0)rdr*�c_ds   r�get_content_dispositionzMessage.get_content_disposition�s=��	�
���.�/���=���%� ��#�)�)�+���
r)r%)FrN)FN)NFrg)Nr�T)r�TNrF)r�T)r�T)3�__name__�
__module__�__qualname__r	rerjrhrxrwr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�r�rrrr!r�r'r*�email.iteratorsr%�rrrr�s��
�'�
*� �
�0�

�/�"��:� Z�x&�(-B�^�"�	�H�$
#���-�	+�	+�
�",�*��$,�<
"�&�0#�#�"�#��*�,5C�� �DFJ�5:�1%�f%�,2�@>� ?�,#�\�<K�$
�%rc���eZdZd�fd�	Zd�fd�	Zd�Zd�Zd�Zdd�Zhd�Z	d	�Z
d
�Zdd�d�Zdd�d
�Z
d�Zdd�Zdd�Zdd�Zdd�d�Zd�Zd�Zd�Zd�Zd�Z�xZS)�MIMEPartNc�8��|�ddlm}|}t�|�
|�y)Nr)�default)�email.policyr3�superre)rdr[r3�	__class__s   �rrezMIMEPart.__init__�s����>�,��F�
���� rc�d��	|�|jn|}|�|j}t�|�
|||�Srg)r[�max_line_lengthr5rh)rdrprnr[r6s    �rrhzMIMEPart.as_string�s>���		�!'�����F����!�1�1�L��w� ��<��@�@rc�Z�|j|jjd����S)NT)�utf8�r[)rhr[�cloneris rrjzMIMEPart.__str__�s%���~�~�T�[�[�%6�%6�D�%6�%A�~�B�Brc�J�|jd�}|�dS|jdk(S)NrF�
attachment)r��content_disposition)rdr)s  r�
is_attachmentzMIMEPart.is_attachment�s+���h�h�,�-����u�P��)@�)@�L�)P�Prc#�\K�|j�ry|j�jd�\}}|dk(r||vr|j|�|f��y|dk7s|j	�sy|dk7r0|j�D]}|j
||�Ed{����yd|vr|jd�|f��d}|jd�}|r!|j�D]}|d|k(s�|}n|�|j�}|r|dnd}|�|j
||�Ed{���yy7��7��w)Nr��text�	multipart�related�start�
content-idr)	r@r�r�r/r}�
iter_parts�
_find_bodyrr�)	rdr&�preferencelist�maintype�subtype�subpart�	candidaterE�subpartss	         rrHzMIMEPart._find_body�sK��������� �1�1�3�9�9�#�>���'��v���.�(�%�+�+�G�4�d�;�;���{�"�$�*;�*;�*=���i���?�?�,���?�?�7�N�C�C�C�-����&�!�'�'�	�2�D�9�9��	����w�'����?�?�,���<�(�E�1� '�I��-����'�'�)�H�'/����T�I�� ����y�.�A�A�A�!�D��
B�s+�BD,�D(�AD,�*7D,�!D*�"D,�*D,c�z�	t|�}d}|j||�D]\}}||ks�|}|}|dk(s�|S|S)Nr)r!rH)rdrI�	best_prio�body�prior&s      r�get_bodyzMIMEPart.get_bodysZ��	���'�	����/�/�$��?�J�D�$��i�� �	����1�9����
@��r>�rB�html�rB�plain�rCrD�rC�alternativec#�K�	|j�jd�\}}|dk7s|dk(ry|j�}	|j�}|dk(rt|dk(ro|jd�}|r@d}g}|D]*}|j
d�|k(rd}�|j|��,|r|Ed{���y|jd	�|Ed{���yg}	|D]^}|j�jd�\}}||f|jvr&|j�s||	vr|	j|��[|���`y#t$rYywxYw7��7�|�w)
Nr�rCrZrDrEFrFTr)r�r�r�r�r�rr�r1�pop�_body_typesr@)
rdrJrKr�r�rEr��attachmentsr&�seens
          r�iter_attachmentszMIMEPart.iter_attachments*sg����		�!�1�1�3�9�9�#�>���'��{�"�g��&>���"�"�$��	��L�L�N�E�
�{�"�w�)�';��N�N�7�+�E���� ��!�D��x�x��-��6� $��#�*�*�4�0�	"�
�*�*�*���I�I�a�L��������D� $� 5� 5� 7� =� =�c� B��H�g��7�#�t�'7�'7�7��*�*�,���1D����G�$���J�
��7�	��	��$+��
�sI�?E�D1�AE�)E�*E�E�A+E�1	D=�:E�<D=�=E�Ec#�dK�	|j�r|j�Ed{���yy7��wrg)r}r�ris rrGzMIMEPart.iter_partsas3����	������'�'�)�)�)��)�s�%0�.�0)�content_managerc�^�|�|jj}|j|g|��i|��Srg)r[rb�get_content�rdrb�args�kws    rrdzMIMEPart.get_contentis4���"�"�k�k�9�9�O�*��*�*�4�=�$�=�"�=�=rc�`�|�|jj}|j|g|��i|��yrg)r[rb�set_contentres    rrizMIMEPart.set_contentns1���"�"�k�k�9�9�O�#��#�#�D�6�4�6�2�6rc�$�|j�dk(r5|j�}||fz}||vrtdj||���g}g}|jD]K\}}|j�j
d�r|j||f��9|j||f��M|r=t|�|j��}	||	_|j|	_
|	g|_
ng|_
||_d|z|d<|�|jd|�yy)NrCzCannot convert {} to {}�content-r;z
multipart/r�r)r�r�rIr�r\r0rFr1r�r[r^r�)
rdrK�disallowed_subtypesr�existing_subtype�keep_headers�part_headersr�r*r&s
          r�_make_multipartzMIMEPart._make_multipartss���$�$�&�+�5�#�7�7�9��"5��
�"B���#6�6� �!:�!A�!A�$�g�"/�0�0������=�=�K�D�%��z�z�|�&�&�z�2��#�#�T�5�M�2��#�#�T�5�M�2�	)�
��4��:�T�[�[�1�D�(�D�M� �M�M�D�M�!�F�D�M��D�M�$��
�+�g�5��^�����N�N�:�x�0� rc�*�|jdd|�y)NrD)rZ�mixed�rp�rdrs  r�make_relatedzMIMEPart.make_related�s�����Y�(@�(�Krc�*�|jdd|�y)NrZ)rrrsrts  r�make_alternativezMIMEPart.make_alternative�s�����]�J��Arc�*�|jdd|�y)Nrrr/rsrts  r�
make_mixedzMIMEPart.make_mixed�s�����W�b�(�3r)�_dispc��|j�dk7s|j�|k7rt|d|z��t|�|j��}|j
|i|��|r	d|vr||d<|j
|�y)NrC�make_r;rzContent-Disposition)r�r��getattrr�r[rir�)rd�_subtyperzrfrgr&s      r�_add_multipartzMIMEPart._add_multipart�s����%�%�'�;�6��(�(�*�h�6�-�G�D�'�H�,�-�/��t�D�z����-������$�%�"�%��*�$�6�*/�D�&�'����D�rc�4�|jdg|��ddi|��y)NrDrz�inline�r�rdrfrgs   r�add_relatedzMIMEPart.add_related�s!������I�C��C�H�C��Crc�0�|jdg|��i|��y)NrZr�r�s   r�add_alternativezMIMEPart.add_alternative�s������M�7�D�7�B�7rc�4�|jdg|��ddi|��y)Nrrrzr>r�r�s   r�add_attachmentzMIMEPart.add_attachment�s!������G�E�d�E�,�E�"�Erc� �g|_d|_yrg)r\r^ris r�clearzMIMEPart.clear�s����
���
rc��|jD��cgc](\}}|j�jd�s||f��*c}}|_d|_ycc}}w)Nrk)r\r0rFr^)rd�nr�s   r�
clear_contentzMIMEPart.clear_content�sN��,0�M�M�B�M�D�A�q� !���	� 4� 4�Z� @��Q��M�B��
���
��Bs�-Arg)FNN))rDrUrW)r+r,r-rerhrjr@rHrSr]r`rGrdrirprurwryrr�r�r�r�r��
__classcell__�r6s@rr1r1�s����!�A� C�Q�B�:�(1�K�5�n*�26�>�
26�7�
1�6L�B�4�59��D�8�F��rr1c���eZdZ�fd�Z�xZS)rc�8��t�|�|i|��d|vrd|d<yy)Nr�r�)r5ri)rdrfrgr6s   �rrizEmailMessage.set_content�s,���
���T�(�R�(���%�#(�D�� �&r)r+r,r-rir�r�s@rrr�s
���)�)r)NT)�__all__rJ�rer��iorr�emailrr�email._policybaser	rr_�email._encoded_wordsrr�r��compiler'rr+r7r:rWrr1rr/rr�<module>r�s���
?��n�
%���	�
� ���&�%�)�
�
�
���	�
�B�J�J�2�3�	� � �D�($�#�>K
%�K
%�\\�w�\�~)�8�)r__pycache__/parser.cpython-312.opt-1.pyc000064400000015134151706203560013723 0ustar00�

T��ho���dZgd�ZddlmZmZddlmZmZddlm	Z	Gd�d�Z
Gd�d	e
�ZGd
�d�ZGd�d
e�Z
y)z-A parser of RFC 2822 and MIME email messages.)�Parser�HeaderParser�BytesParser�BytesHeaderParser�
FeedParser�BytesFeedParser�)�StringIO�
TextIOWrapper)rr)�compat32c�*�eZdZded�d�Zdd�Zdd�Zy)rN��policyc� �||_||_y)a�Parser of RFC 2822 and MIME email messages.

        Creates an in-memory object tree representing the email message, which
        can then be manipulated and turned over to a Generator to return the
        textual representation of the message.

        The string must be formatted as a block of RFC 2822 headers and header
        continuation lines, optionally preceded by a `Unix-from' header.  The
        header block is terminated either by the end of the string or by a
        blank line.

        _class is the class to instantiate for new message objects when they
        must be created.  This class must have a constructor that can take
        zero arguments.  Default is Message.Message.

        The policy keyword specifies a policy object that controls a number of
        aspects of the parser's operation.  The default policy maintains
        backward compatibility.

        N)�_classr)�selfrrs   �%/usr/lib64/python3.12/email/parser.py�__init__zParser.__init__s��*������c��t|j|j��}|r|j�|j	d�x}r%|j|�|j	d�x}r�%|j
�S)a\Create a message structure from the data in a file.

        Reads all the data from the file and returns the root of the message
        structure.  Optional headersonly is a flag specifying whether to stop
        parsing after reading the headers or not.  The default is False,
        meaning it parses the entire contents of the file.
        r
i )rrr�_set_headersonly�read�feed�close)r�fp�headersonly�
feedparser�datas     r�parsezParser.parse)sj�� ����D�K�K�@�
���'�'�)��g�g�d�m�#�d�#��O�O�D�!��g�g�d�m�#�d�#����!�!rc�:�|jt|�|��S)a-Create a message structure from a string.

        Returns the root of the message structure.  Optional headersonly is a
        flag specifying whether to stop parsing after reading the headers or
        not.  The default is False, meaning it parses the entire contents of
        the file.
        �r)rr	�r�textrs   r�parsestrzParser.parsestr8s���z�z�(�4�.�k�z�B�Br)N�F)�__name__�
__module__�__qualname__rrrr#�rrrrs���h��0
"�Crrc��eZdZdd�Zdd�Zy)rc�0�tj||d�S�NT)rr�rrrs   rrzHeaderParser.parseDs���|�|�D�"�d�+�+rc�0�tj||d�Sr+)rr#r!s   rr#zHeaderParser.parsestrGs�����t�T�4�0�0rN�T)r%r&r'rr#r(rrrrCs��,�1rrc�"�eZdZd�Zdd�Zdd�Zy)rc�$�t|i|��|_y)a�Parser of binary RFC 2822 and MIME email messages.

        Creates an in-memory object tree representing the email message, which
        can then be manipulated and turned over to a Generator to return the
        textual representation of the message.

        The input must be formatted as a block of RFC 2822 headers and header
        continuation lines, optionally preceded by a `Unix-from' header.  The
        header block is terminated either by the end of the input or by a
        blank line.

        _class is the class to instantiate for new message objects when they
        must be created.  This class must have a constructor that can take
        zero arguments.  Default is Message.Message.
        N)r�parser)r�args�kws   rrzBytesParser.__init__Ms�� �d�)�b�)��rc��t|dd��}	|jj||�|j�S#|j�wxYw)acCreate a message structure from the data in a binary file.

        Reads all the data from the file and returns the root of the message
        structure.  Optional headersonly is a flag specifying whether to stop
        parsing after reading the headers or not.  The default is False,
        meaning it parses the entire contents of the file.
        �ascii�surrogateescape)�encoding�errors)r
r1r�detachr,s   rrzBytesParser.parse_s?���2��8I�
J��	��;�;�$�$�R��5��I�I�K��B�I�I�K�s	�<�Ac�`�|jdd��}|jj||�S)a2Create a message structure from a byte string.

        Returns the root of the message structure.  Optional headersonly is a
        flag specifying whether to stop parsing after reading the headers or
        not.  The default is False, meaning it parses the entire contents of
        the file.
        �ASCIIr6)r8)�decoder1r#r!s   r�
parsebyteszBytesParser.parsebytesns.���{�{�7�+<�{�=���{�{�#�#�D�+�6�6rNr$)r%r&r'rrr=r(rrrrKs��*�$�	7rrc��eZdZdd�Zdd�Zy)rc�2�tj||d��S�NTr )rrr,s   rrzBytesHeaderParser.parse{s��� � ��r�t� �<�<rc�2�tj||d��Sr@)rr=r!s   rr=zBytesHeaderParser.parsebytes~s���%�%�d�D�d�%�C�CrNr.)r%r&r'rr=r(rrrrzs
��=�DrrN)�__doc__�__all__�ior	r
�email.feedparserrr�email._policybaserrrrrr(rr�<module>rGsN��
4�,��'�8�&�0C�0C�f1�6�1�,7�,7�^D��Dr__pycache__/parser.cpython-312.opt-2.pyc000064400000007303151706203560013723 0ustar00�

T��ho���	gd�ZddlmZmZddlmZmZddlmZGd�d�Z	Gd�de	�Z
Gd	�d
�ZGd�de�Zy
))�Parser�HeaderParser�BytesParser�BytesHeaderParser�
FeedParser�BytesFeedParser�)�StringIO�
TextIOWrapper)rr)�compat32c�*�eZdZded�d�Zdd�Zdd�Zy)rN��policyc�"�	||_||_y�N)�_classr)�selfrrs   �%/usr/lib64/python3.12/email/parser.py�__init__zParser.__init__s��	�(������c��	t|j|j��}|r|j�|j	d�x}r%|j|�|j	d�x}r�%|j
�S)Nr
i )rrr�_set_headersonly�read�feed�close)r�fp�headersonly�
feedparser�datas     r�parsezParser.parse)so��	� ����D�K�K�@�
���'�'�)��g�g�d�m�#�d�#��O�O�D�!��g�g�d�m�#�d�#����!�!rc�<�	|jt|�|��S)N�r)rr	�r�textrs   r�parsestrzParser.parsestr8s ��	��z�z�(�4�.�k�z�B�Brr�F)�__name__�
__module__�__qualname__rrrr$�rrrrs���h��0
"�Crrc��eZdZdd�Zdd�Zy)rc�0�tj||d�S�NT)rr�rrrs   rrzHeaderParser.parseDs���|�|�D�"�d�+�+rc�0�tj||d�Sr,)rr$r"s   rr$zHeaderParser.parsestrGs�����t�T�4�0�0rN�T)r&r'r(rr$r)rrrrCs��,�1rrc�"�eZdZd�Zdd�Zdd�Zy)rc�&�	t|i|��|_yr)r�parser)r�args�kws   rrzBytesParser.__init__Ms��	��d�)�b�)��rc��	t|dd��}	|jj||�|j�S#|j�wxYw)N�ascii�surrogateescape)�encoding�errors)r
r2r�detachr-s   rrzBytesParser.parse_sD��	��2��8I�
J��	��;�;�$�$�R��5��I�I�K��B�I�I�K�s	�=�Ac�b�	|jdd��}|jj||�S)N�ASCIIr7)r9)�decoder2r$r"s   r�
parsebyteszBytesParser.parsebytesns3��	��{�{�7�+<�{�=���{�{�#�#�D�+�6�6rNr%)r&r'r(rrr>r)rrrrKs��*�$�	7rrc��eZdZdd�Zdd�Zy)rc�2�tj||d��S�NTr!)rrr-s   rrzBytesHeaderParser.parse{s��� � ��r�t� �<�<rc�2�tj||d��SrA)rr>r"s   rr>zBytesHeaderParser.parsebytes~s���%�%�d�D�d�%�C�CrNr/)r&r'r(rr>r)rrrrzs
��=�DrrN)
�__all__�ior	r
�email.feedparserrr�email._policybaserrrrrr)rr�<module>rGsN��
4�,��'�8�&�0C�0C�f1�6�1�,7�,7�^D��Dr__pycache__/policy.cpython-312.opt-1.pyc000064400000027034151706203560013730 0ustar00�

T��hv)��P�dZddlZddlZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZgd�Zej"d	�ZeGd
�de��Ze�Ze`ej-d�
�Zej-d��Zej-dd��Zej-d��Zy)zcThis will be the home for the policy that hooks in the new
code that adds all the email6 features.
�N)�Policy�Compat32�compat32�_extend_docstrings)�_has_surrogates)�HeaderRegistry)�raw_data_manager)�EmailMessage)rrr�EmailPolicy�default�strict�SMTP�HTTPz\n|\r\n?c�l��eZdZdZeZdZdZe�Z	e
Z�fd�Zd�Z
d�Zd�Zd�Zd	�Zd
�Zdd�Z�xZS)
raQ+
    PROVISIONAL

    The API extensions enabled by this policy are currently provisional.
    Refer to the documentation for details.

    This policy adds new header parsing and folding algorithms.  Instead of
    simple strings, headers are custom objects with custom attributes
    depending on the type of the field.  The folding algorithm fully
    implements RFCs 2047 and 5322.

    In addition to the settable attributes listed above that apply to
    all Policies, this policy adds the following additional attributes:

    utf8                -- if False (the default) message headers will be
                           serialized as ASCII, using encoded words to encode
                           any non-ASCII characters in the source strings.  If
                           True, the message headers will be serialized using
                           utf8 and will not contain encoded words (see RFC
                           6532 for more on this serialization format).

    refold_source       -- if the value for a header in the Message object
                           came from the parsing of some source, this attribute
                           indicates whether or not a generator should refold
                           that value when transforming the message back into
                           stream form.  The possible values are:

                           none  -- all source values use original folding
                           long  -- source values that have any line that is
                                    longer than max_line_length will be
                                    refolded
                           all  -- all values are refolded.

                           The default is 'long'.

    header_factory      -- a callable that takes two arguments, 'name' and
                           'value', where 'name' is a header field name and
                           'value' is an unfolded header field value, and
                           returns a string-like object that represents that
                           header.  A default header_factory is provided that
                           understands some of the RFC5322 header field types.
                           (Currently address fields and date fields have
                           special treatment, while all other fields are
                           treated as unstructured.  This list will be
                           completed before the extension is marked stable.)

    content_manager     -- an object with at least two methods: get_content
                           and set_content.  When the get_content or
                           set_content method of a Message object is called,
                           it calls the corresponding method of this object,
                           passing it the message object as its first argument,
                           and any arguments or keywords that were passed to
                           it as additional arguments.  The default
                           content_manager is
                           :data:`~email.contentmanager.raw_data_manager`.

    F�longc�j��d|vrtj|dt��t�|�di|��y)N�header_factory�)�object�__setattr__r�super�__init__)�self�kw�	__class__s  ��%/usr/lib64/python3.12/email/policy.pyrzEmailPolicy.__init__]s3����2�%����t�%5�~�7G�H�
����2��c�4�|j|jS)z�+
        The implementation for this class returns the max_count attribute from
        the specialized header class that would be used to construct a header
        of type 'name'.
        )r�	max_count)r�names  r�header_max_countzEmailPolicy.header_max_countds���"�"�4�(�2�2�2rc��|djdd�\}}dj|g|dd���jd�}||jd�fS)a]+
        The name is parsed as everything up to the ':' and returned unmodified.
        The value is determined by stripping leading whitespace off the
        remainder of the first line joined with all subsequent lines, and
        stripping any trailing carriage return or linefeed characters.  (This
        is the same as Compat32).

        r�:��Nz 	
�
)�split�join�lstrip�rstrip)r�sourcelinesr �values    r�header_source_parsezEmailPolicy.header_source_parsevsY��"�!�n�*�*�3��2���e�����1��Q�R��1�2�9�9�)�D���e�l�l�6�*�+�+rc��t|d�r/|jj�|j�k(r||fSt|t�r't|j
��dkDrtd��||j||�fS)a�+
        The name is returned unchanged.  If the input value has a 'name'
        attribute and it matches the name ignoring case, the value is returned
        unchanged.  Otherwise the name and value are passed to header_factory
        method, and the resulting custom header object is returned as the
        value.  In this case a ValueError is raised if the input value contains
        CR or LF characters.

        r r$zDHeader values may not contain linefeed or carriage return characters)	�hasattrr �lower�
isinstance�str�len�
splitlines�
ValueErrorr�rr r,s   r�header_store_parsezEmailPolicy.header_store_parse�s}���5�&�!�e�j�j�&6�&6�&8�D�J�J�L�&H��%�=� ��e�S�!�c�%�*:�*:�*<�&=�a�&?��=�>�
>��d�)�)�$��6�7�7rc��t|d�r|Sdjtj|��}|j	||�S)ai+
        If the value has a 'name' attribute, it is returned to unmodified.
        Otherwise the name and the value with any linesep characters removed
        are passed to the header_factory method, and the resulting custom
        header object is returned.  Any surrogateescaped bytes get turned
        into the unicode unknown-character glyph.

        r r%)r/r(�linesep_splitterr'rr6s   r�header_fetch_parsezEmailPolicy.header_fetch_parse�s@���5�&�!��L����(�.�.�u�5�6���"�"�4��/�/rc�*�|j||d��S)a+
        Header folding is controlled by the refold_source policy setting.  A
        value is considered to be a 'source value' if and only if it does not
        have a 'name' attribute (having a 'name' attribute means it is a header
        object of some sort).  If a source value needs to be refolded according
        to the policy, it is converted into a custom header object by passing
        the name and the value with any linesep characters removed to the
        header_factory method.  Folding of a custom header object is done by
        calling its fold method with the current policy.

        Source values are split into lines using splitlines.  If the value is
        not to be refolded, the lines are rejoined using the linesep from the
        policy and returned.  The exception is lines containing non-ascii
        binary data.  In that case the value is refolded regardless of the
        refold_source setting, which causes the binary data to be CTE encoded
        using the unknown-8bit charset.

        T��
refold_binary)�_foldr6s   r�foldzEmailPolicy.fold�s��&�z�z�$��T�z�:�:rc��|j|||jdk(��}|jrdnd}|j|d�S)a+
        The same as fold if cte_type is 7bit, except that the returned value is
        bytes.

        If cte_type is 8bit, non-ASCII binary data is converted back into
        bytes.  Headers with binary data are not refolded, regardless of the
        refold_header setting, since there is no way to know whether the binary
        data consists of single byte characters or multibyte characters.

        If utf8 is true, headers are encoded to utf8, otherwise to ascii with
        non-ASCII unicode rendered as encoded words.

        �7bitr<�utf8�ascii�surrogateescape)r>�cte_typerB�encode)rr r,�folded�charsets     r�fold_binaryzEmailPolicy.fold_binary�s@�����D�%�t�}�}�f�7L��M�� �I�I�&�7���}�}�W�&7�8�8rc���t|d�r|j|��S|jr|jntj�t
j
|�}|jdk(xsN|jdk(xr=|xr t|d�t|�zdz�kDxst�fd�|ddD��}|s+|js|j�}n
|rt|�}|r1|j|d	j|��j|��S|d
z|jj|�z|jzS)Nr )�policy�allrr�c3�:�K�|]}t|��kD���y�w)N)r3)�.0�x�maxlens  �r�	<genexpr>z$EmailPolicy._fold.<locals>.<genexpr>�s�����<�)�Q��Q��&��)�s�r$r%z: )r/r?�max_line_length�sys�maxsizer9r'�
refold_sourcer3�anyrB�isasciirrr(�linesep)rr r,r=�lines�refoldrQs      @rr>zEmailPolicy._fold�s(����5�&�!��:�:�T�:�*�*�)-�)=�)=��%�%�3�;�;�� �&�&�u�-���$�$��-�>��$�$��.�>��A�s�5��8�}�S��Y�6�q�8�6�A�=��<�%���)�<�<�	�
��9�9�"�]�]�_�,���(��/����&�&�t�R�W�W�U�^�<�A�A��A�N�N��d�{�T�\�\�.�.�u�5�5����D�Dr)F)�__name__�
__module__�__qualname__�__doc__r
�message_factoryrBrVrrr	�content_managerrr!r-r7r:r?rIr>�
__classcell__)rs@rrrsP���8�t#�O��D��M�#�%�N�&�O��3�$,�8�&
0�;�*9�$ErrT)�raise_on_defectr&)rY)rYrS)rB)r_�rerT�email._policybaserrrr�email.utilsr�email.headerregistryr�email.contentmanagerr	�
email.messager
�__all__�compiler9rrr�cloner
rr�SMTPUTF8rrr�<module>rns����
�
�L�L�'�A�1�&�	���2�:�:�k�*���DE�&�DE��DE�N�-����	���t��	,���}�}�V�}�$���}�}�V�T�}�:���:�:�4�:� �r__pycache__/policy.cpython-312.opt-2.pyc000064400000013015151706203560013723 0ustar00�

T��hv)��N�	ddlZddlZddlmZmZmZmZddlmZddl	m
Z
ddlmZddl
mZgd�Zej d�ZeGd	�d
e��Ze�Ze`ej+d��Zej+d
��Zej+d
d��Zej+d��Zy)�N)�Policy�Compat32�compat32�_extend_docstrings)�_has_surrogates)�HeaderRegistry)�raw_data_manager)�EmailMessage)rrr�EmailPolicy�default�strict�SMTP�HTTPz\n|\r\n?c�j��eZdZ	eZdZdZe�Ze	Z
�fd�Zd�Zd�Z
d�Zd�Zd�Zd	�Zdd
�Z�xZS)rF�longc�j��d|vrtj|dt��t�|�di|��y)N�header_factory�)�object�__setattr__r�super�__init__)�self�kw�	__class__s  ��%/usr/lib64/python3.12/email/policy.pyrzEmailPolicy.__init__]s3����2�%����t�%5�~�7G�H�
����2��c�6�	|j|jS�N)r�	max_count)r�names  r�header_max_countzEmailPolicy.header_max_countds ��	�
�"�"�4�(�2�2�2rc��	|djdd�\}}dj|g|dd���jd�}||jd�fS)Nr�:��z 	
�
)�split�join�lstrip�rstrip)r�sourcelinesr!�values    r�header_source_parsezEmailPolicy.header_source_parsevs^��	�"�!�n�*�*�3��2���e�����1��Q�R��1�2�9�9�)�D���e�l�l�6�*�+�+rc��	t|d�r/|jj�|j�k(r||fSt|t�r't|j
��dkDrtd��||j||�fS)Nr!r%zDHeader values may not contain linefeed or carriage return characters)	�hasattrr!�lower�
isinstance�str�len�
splitlines�
ValueErrorr�rr!r-s   r�header_store_parsezEmailPolicy.header_store_parse�s���	��5�&�!�e�j�j�&6�&6�&8�D�J�J�L�&H��%�=� ��e�S�!�c�%�*:�*:�*<�&=�a�&?��=�>�
>��d�)�)�$��6�7�7rc��	t|d�r|Sdjtj|��}|j	||�S)Nr!r&)r0r)�linesep_splitterr(rr7s   r�header_fetch_parsezEmailPolicy.header_fetch_parse�sE��	��5�&�!��L����(�.�.�u�5�6���"�"�4��/�/rc�,�	|j||d��S)NT��
refold_binary)�_foldr7s   r�foldzEmailPolicy.fold�s��	�$�z�z�$��T�z�:�:rc��	|j|||jdk(��}|jrdnd}|j|d�S)N�7bitr=�utf8�ascii�surrogateescape)r?�cte_typerC�encode)rr!r-�folded�charsets     r�fold_binaryzEmailPolicy.fold_binary�sE��	����D�%�t�}�}�f�7L��M�� �I�I�&�7���}�}�W�&7�8�8rc���t|d�r|j|��S|jr|jntj�t
j
|�}|jdk(xsN|jdk(xr=|xr t|d�t|�zdz�kDxst�fd�|ddD��}|s+|js|j�}n
|rt|�}|r1|j|d	j|��j|��S|d
z|jj|�z|jzS)Nr!)�policy�allrr�c3�:�K�|]}t|��kD���y�wr)r4)�.0�x�maxlens  �r�	<genexpr>z$EmailPolicy._fold.<locals>.<genexpr>�s�����<�)�Q��Q��&��)�s�r%r&z: )r0r@�max_line_length�sys�maxsizer:r(�
refold_sourcer4�anyrC�isasciirrr)�linesep)rr!r-r>�lines�refoldrRs      @rr?zEmailPolicy._fold�s(����5�&�!��:�:�T�:�*�*�)-�)=�)=��%�%�3�;�;�� �&�&�u�-���$�$��-�>��$�$��.�>��A�s�5��8�}�S��Y�6�q�8�6�A�=��<�%���)�<�<�	�
��9�9�"�]�]�_�,���(��/����&�&�t�R�W�W�U�^�<�A�A��A�N�N��d�{�T�\�\�.�.�u�5�5����D�Dr)F)�__name__�
__module__�__qualname__r
�message_factoryrCrWrrr	�content_managerrr"r.r8r;r@rJr?�
__classcell__)rs@rrrsP���8�t#�O��D��M�#�%�N�&�O��3�$,�8�&
0�;�*9�$ErrT)�raise_on_defectr')rZ)rZrT)rC)�rerU�email._policybaserrrr�email.utilsr�email.headerregistryr�email.contentmanagerr	�
email.messager
�__all__�compiler:rrr�cloner
rr�SMTPUTF8rrr�<module>rns����
�
�L�L�'�A�1�&�	���2�:�:�k�*���DE�&�DE��DE�N�-����	���t��	,���}�}�V�}�$���}�}�V�T�}�:���:�:�4�:� �r__pycache__/quoprimime.cpython-312.opt-1.pyc000064400000023340151706203560014614 0ustar00�

T��h�&���dZgd�ZddlZddlmZmZmZdZdZdZ	e
d�D�cgc]}d	|z��	c}ZeddZeddZ
d
ejd�zejd�zD]
Zee�ee<�deed
�<dD]
Zee�e
e<�d�Zd�Zd�Zd�Zdd�Zd�Zd�Zdd�Ze
ddZdD]
Zee�ee<�[defd�Zefd�ZeZeZd�Zd�Z ycc}w)aFQuoted-printable content transfer encoding per RFCs 2045-2047.

This module handles the content transfer encoding method defined in RFC 2045
to encode US ASCII-like 8-bit data called `quoted-printable'.  It is used to
safely encode text that is in a character set similar to the 7-bit US ASCII
character set, but that includes some 8-bit characters that are normally not
allowed in email bodies or headers.

Quoted-printable is very space-inefficient for encoding binary files; use the
email.base64mime module for that instead.

This module provides an interface to encode and decode both headers and bodies
with quoted-printable encoding.

RFC 2045 defines a method for including character set information in an
`encoded-word' in a header.  This method is commonly used for 8-bit real names
in To:/From:/Cc: etc. fields, as well as Subject: lines.

This module does not do the line wrapping or end-of-line character
conversion necessary for proper internationalized headers; it only
does dumb encoding and decoding.  To deal with the various line
wrapping issues, use the email.header module.
)
�body_decode�body_encode�body_length�decode�decodestring�
header_decode�
header_encode�
header_length�quote�unquote�N)�
ascii_letters�digits�	hexdigits�
�
��z=%02Xs-!*+/�ascii�_� s_ !"#$%&'()*+,-./0123456789:;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~	c�,�t|�t|k7S)z>Return True if the octet should be escaped with header quopri.)�chr�_QUOPRI_HEADER_MAP��octets �)/usr/lib64/python3.12/email/quoprimime.py�header_checkrJs���u�:�+�E�2�2�2�c�,�t|�t|k7S)z<Return True if the octet should be escaped with body quopri.)r�_QUOPRI_BODY_MAPrs r�
body_checkr!Os���u�:�)�%�0�0�0rc�&�td�|D��S)a:Return a header quoted-printable encoding length.

    Note that this does not include any RFC 2047 chrome added by
    `header_encode()`.

    :param bytearray: An array of bytes (a.k.a. octets).
    :return: The length in bytes of the byte array when it is encoded with
        quoted-printable for headers.
    c3�@K�|]}tt|����y�w�N)�lenr��.0rs  r�	<genexpr>z header_length.<locals>.<genexpr>^s����E�9�%�s�%�e�,�-�9�����sum��	bytearrays rr	r	Ts���E�9�E�E�Erc�&�td�|D��S)z�Return a body quoted-printable encoding length.

    :param bytearray: An array of bytes (a.k.a. octets).
    :return: The length in bytes of the byte array when it is encoded with
        quoted-printable for bodies.
    c3�@K�|]}tt|����y�wr$)r%r r&s  rr(zbody_length.<locals>.<genexpr>hs����C���s�#�E�*�+��r)r*r,s rrras���C��C�C�Crc��t|t�st|�}|s |j|j	��yt|d�t|�z|kr|dxx||zz
cc<y|j|j	��y)N���)�
isinstance�strr�append�lstripr%)�L�s�maxlen�extras    r�_max_appendr:ksg���a�����F���	��������	�Q�r�U��c�!�f�	��	&�	�"�������	�������rc�2�tt|ddd��S)zDTurn a string in the form =AB to the ASCII character with value 0xab���)r�int�r7s rrrvs���s�1�Q�q�6�2���rc�&�tt|�Sr$)�_QUOPRI_MAP�ord��cs rr
r
{s���s�1�v��rc�b�|sy|jd�jt�}d|�d|�d�S)a�Encode a single header line with quoted-printable (like) encoding.

    Defined in RFC 2045, this `Q' encoding is similar to quoted-printable, but
    used specifically for email header fields to allow charsets with mostly 7
    bit characters (and some 8 bit) to remain more or less readable in non-RFC
    2045 aware mail clients.

    charset names the character set to use in the RFC 2046 header.  It
    defaults to iso-8859-1.
    r�latin1z=?z?q?z?=)r�	translater)�header_bytes�charset�encodeds   rrrs3�����!�!�(�+�5�5�6H�I�G�$�W�-�-rs
�Lc��|dkrtd��|s|S|jt�}d|z}|dz
}g}|j}|j	�D]�}d}t|�dz
|z
}	||	krV||z}
||
dz
dk(r||||
dz
�|
dz
}n,||
dz
dk(r||||
�|
dz
}n||||
dz�|
}||	kr�V|rN|ddvrG||	z
}|d	k\rt
|d�}n|dk(r	|d|z}n|t
|d�z}|||d|z���|||d
���|dtvr|d�|j|�S)a�Encode with quoted-printable, wrapping at maxlinelen characters.

    Each line of encoded text will end with eol, which defaults to "\n".  Set
    this to "\r\n" if you will be using the result of this function directly
    in an email.

    Each line will be wrapped at, at most, maxlinelen characters before the
    eol string (maxlinelen defaults to 76 characters, the maximum value
    permitted by RFC 2045).  Long lines will have the 'soft line break'
    quoted-printable character "=" appended to them, so the decoded text will
    be identical to the original text.

    The minimum maxlinelen is 4 to have room for a quoted character ("=XX")
    followed by a soft line break.  Smaller values will generate a
    ValueError.

    �zmaxlinelen must be at least 4�=r<r�r1z 	r=Nr)	�
ValueErrorrH�_QUOPRI_BODY_ENCODE_MAPr4�
splitlinesr%r
�CRLF�join)
�body�
maxlinelen�eol�
soft_break�maxlinelen1�encoded_bodyr4�line�start�	laststart�stop�room�qs
             rrr�s���&�A�~��8�9�9�����>�>�1�2�D��s��J��q�.�K��L�
�
 �
 �F����!������I��M�J�.�	��y� ��;�&�D��D�1�H�~��$��t�E�$��(�+�,��q����d�Q�h��3�&��t�E�$�'�(��q����t�E�$�'�#�-�.����y� ��D��H��%��9�$�D��q�y��$�r�(�O�������H�z�)����t�B�x��0���4��b�>�A�%�&��4���<� �C"�H�B�x�4���r�
��8�8�L�!�!rc���|s|Sd}|j�D]�}|j�}|s||z
}�d}t|�}||ks�.||}|dk7r||z
}|dz
}nV|dz|k(r|dz
}�)|dz|kr6||dztvr(||dztvr|t	|||dz�z
}|dz
}n
||z
}|dz
}||k(r||z
}||kr�{��|ddvr|j|�r|d	d}|S)
z_Decode a quoted-printable string.

    Lines are separated with eol, which defaults to \n.
    rrrOr<rPr=r1rN)rS�rstripr%rr�endswith)rKrX�decodedr\�i�nrEs       rrr�s3��
����G��"�"�$���{�{�}����s�N�G��
����I���!�e��Q��A��C�x��1����Q����1�����Q�����1��q��T�!�A�#�Y�)�3��Q�q�S�	�Y�8N��7�4��!�A�#�;�/�/���Q����1����Q����A�v��3���)�!�e�%�<�r�{�&� �W�%5�%5�c�%:��#�2�,���Nrc�:�|jd�}t|�S)zCTurn a match in the form =AB to the ASCII character with value 0xabr)�groupr)�matchr7s  r�_unquote_matchrks��
���A��A��1�:�rc�|�|jdd�}tjdt|tj��S)aDecode a string encoded with RFC 2045 MIME header `Q' encoding.

    This function does not parse a full MIME header value encoded with
    quoted-printable (like =?iso-8859-1?q?Hello_World?=) -- please use
    the high level email.header class for that functionality.
    rrz=[a-fA-F0-9]{2})�flags)�replace�re�subrk�ASCIIr@s rrr$s.��	
�	�	�#�s��A�
�6�6�$�n�a�r�x�x�H�Hr)r)z
iso-8859-1)!�__doc__�__all__ro�stringr
rrrT�NL�EMPTYSTRING�rangerBrr �encoderErrCrr!r	rr:rr
rrRrrrrrkrrDs0r�<module>rysQ��
�0��
�3�3�
��	����%*�#�J�/�J�q�w��{�J�/�� ��^���q�>��
�(�M�(�(��1�	1�M�F�M�M�'�4J�	J�A���F��q��
K� #��3�s�8��.�A��a�&��Q��.�3�
1�

F�D�� �
�.�*+�1�-��	�A�!$�Q���A��
��!#��I"�^�,�`�����I��[0s�C__pycache__/quoprimime.cpython-312.opt-2.pyc000064400000014621151706203560014617 0ustar00�

T��h�&���	gd�ZddlZddlmZmZmZdZdZdZe	d�D�cgc]}d|z��	c}Z
e
ddZe
ddZd	ejd
�zejd
�zD]
Zee�ee<�deed�<d
D]
Zee�ee<�d�Zd�Zd�Zd�Zdd�Zd�Zd�Zdd�ZeddZdD]
Zee�ee<�[defd�Zefd�ZeZeZd�Zd�Zycc}w))
�body_decode�body_encode�body_length�decode�decodestring�
header_decode�
header_encode�
header_length�quote�unquote�N)�
ascii_letters�digits�	hexdigits�
�
��z=%02Xs-!*+/�ascii�_� s_ !"#$%&'()*+,-./0123456789:;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~	c�.�	t|�t|k7S�N)�chr�_QUOPRI_HEADER_MAP��octets �)/usr/lib64/python3.12/email/quoprimime.py�header_checkrJs��H��u�:�+�E�2�2�2�c�.�	t|�t|k7Sr)r�_QUOPRI_BODY_MAPrs r�
body_checkr"Os��F��u�:�)�%�0�0�0rc�(�	td�|D��S)Nc3�@K�|]}tt|����y�wr)�lenr��.0rs  r�	<genexpr>z header_length.<locals>.<genexpr>^s����E�9�%�s�%�e�,�-�9�����sum��	bytearrays rr	r	Ts����E�9�E�E�Erc�(�	td�|D��S)Nc3�@K�|]}tt|����y�wr)r%r!r&s  rr(zbody_length.<locals>.<genexpr>hs����C���s�#�E�*�+��r)r*r,s rrras����C��C�C�Crc��t|t�st|�}|s |j|j	��yt|d�t|�z|kr|dxx||zz
cc<y|j|j	��y)N���)�
isinstance�strr�append�lstripr%)�L�s�maxlen�extras    r�_max_appendr:ksg���a�����F���	��������	�Q�r�U��c�!�f�	��	&�	�"�������	�������rc�4�	tt|ddd��S)N���)r�int�r7s rrrvs��N��s�1�Q�q�6�2���rc�&�tt|�Sr)�_QUOPRI_MAP�ord��cs rr
r
{s���s�1�v��rc�d�	|sy|jd�jt�}d|�d|�d�S)Nr�latin1z=?z?q?z?=)r�	translater)�header_bytes�charset�encodeds   rrrs8��	����!�!�(�+�5�5�6H�I�G�$�W�-�-rs
�Lc��	|dkrtd��|s|S|jt�}d|z}|dz
}g}|j}|j	�D]�}d}t|�dz
|z
}	||	krV||z}
||
dz
dk(r||||
dz
�|
dz
}n,||
dz
dk(r||||
�|
dz
}n||||
dz�|
}||	kr�V|rN|ddvrG||	z
}|d	k\rt
|d�}n|dk(r	|d|z}n|t
|d�z}|||d|z���|||d���|dtvr|d
�|j|�S)N�zmaxlinelen must be at least 4�=r<r�r1z 	r=r)	�
ValueErrorrH�_QUOPRI_BODY_ENCODE_MAPr4�
splitlinesr%r
�CRLF�join)
�body�
maxlinelen�eol�
soft_break�maxlinelen1�encoded_bodyr4�line�start�	laststart�stop�room�qs
             rrr�s����$�A�~��8�9�9�����>�>�1�2�D��s��J��q�.�K��L�
�
 �
 �F����!������I��M�J�.�	��y� ��;�&�D��D�1�H�~��$��t�E�$��(�+�,��q����d�Q�h��3�&��t�E�$�'�(��q����t�E�$�'�#�-�.����y� ��D��H��%��9�$�D��q�y��$�r�(�O�������H�z�)����t�B�x��0���4��b�>�A�%�&��4���<� �C"�H�B�x�4���r�
��8�8�L�!�!rc���	|s|Sd}|j�D]�}|j�}|s||z
}�d}t|�}||ks�.||}|dk7r||z
}|dz
}nV|dz|k(r|dz
}�)|dz|kr6||dztvr(||dztvr|t	|||dz�z
}|dz
}n
||z
}|dz
}||k(r||z
}||kr�{��|ddvr|j|�r|dd}|S)	NrrrOr<rPr=r1r)rS�rstripr%rr�endswith)rKrX�decodedr\�i�nrEs       rrr�s8�������G��"�"�$���{�{�}����s�N�G��
����I���!�e��Q��A��C�x��1����Q����1�����Q�����1��q��T�!�A�#�Y�)�3��Q�q�S�	�Y�8N��7�4��!�A�#�;�/�/���Q����1����Q����A�v��3���)�!�e�%�<�r�{�&� �W�%5�%5�c�%:��#�2�,���Nrc�<�	|jd�}t|�S)Nr)�groupr)�matchr7s  r�_unquote_matchrks��M�
���A��A��1�:�rc�~�	|jdd�}tjdt|tj��S)Nrrz=[a-fA-F0-9]{2})�flags)�replace�re�subrk�ASCIIr@s rrr$s3���	
�	�	�#�s��A�
�6�6�$�n�a�r�x�x�H�Hr)r)z
iso-8859-1) �__all__ro�stringr
rrrT�NL�EMPTYSTRING�rangerBrr!�encoderErrCrr"r	rr:rr
rrRrrrrrkrrDs0r�<module>rxsQ��
�0��
�3�3�
��	����%*�#�J�/�J�q�w��{�J�/�� ��^���q�>��
�(�M�(�(��1�	1�M�F�M�M�'�4J�	J�A���F��q��
K� #��3�s�8��.�A��a�&��Q��.�3�
1�

F�D�� �
�.�*+�1�-��	�A�!$�Q���A��
��!#��I"�^�,�`�����I��[0s�C__pycache__/utils.cpython-312.opt-1.pyc000064400000037144151706203560013574 0ustar00�

T��h�>����dZgd�ZddlZddlZddlZddlZddlZddlZddlZ	ddl
mZddl
mZ
ddl
mZddl
mZmZmZddlmZd	Zd
Zd
ZdZdZej2d
�Zej2d�Zd�Zd�Zd'd�Zd�Zd�Z dZ!dd�d�Z"d�Z#d�Z$d�Z%d�Z&d(d�Z'd)d�Z(d*d�Z)d�Z*dd�d�Z+d �Z,d!�Z-d*d"�Z.ej2d#ej^�Z0d$�Z1		d+d%�Z2d*d&�Z3y),zMiscellaneous utilities.)�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�D�	|j�y#t$rYywxYw)z;Return True if s may contain surrogate-escaped binary data.FT)�encode�UnicodeEncodeError)�ss �$/usr/lib64/python3.12/email/utils.py�_has_surrogatesr4s%��
�	���
�������s��	�c�J�|jdd�}|jdd�S)N�utf-8�surrogateescape�replace)r�decode)�string�original_bytess  r�	_sanitizer%As(��
�]�]�7�,=�>�N�� � ��)�4�4�c�V�|\}}|jd�|rM	|jd�d}tj|�rd}tj	d|�}|�|�|�d|�d�S|S#t
$r7t
|t�rt|�}|j|�}|�d|�d�cYSwxYw)a�The inverse of parseaddr(), this takes a 2-tuple of the form
    (realname, email_address) and returns the string value suitable
    for an RFC 2822 From, To or Cc header.

    If the first element of pair is false, then the second element is
    returned unmodified.

    The optional charset is the character set that is used to encode
    realname in case realname is not ASCII safe.  Can be an instance of str or
    a Charset-like object which has a header_encode method.  Default is
    'utf-8'.
    �asciir�"z\\\g<0>z <�>)
r�
specialsre�search�	escapesre�subr�
isinstance�strr�
header_encode)�pair�charset�name�address�quotes�encoded_names      rrrMs����M�D�'��N�N�7���	C��K�K�� ��F�� � ��&����=�=��T�2�D�$*�D�&�'�B�B��N��"�	7��'�3�'�!�'�*��"�0�0��6�L� ,�g�6�6�		7�s�A(�(=B(�'B(c#�K�d}d}t|�D]!\}}|r|d|zf��d}�|dk(rd}�||f���#|r|df��yy�w)NrF�\T)�	enumerate)�addr�pos�escape�chs    r�_iter_escaped_charsr?nsb����
�C�
�F��T�?���R����r�	�"�"��F�
�4�Z��F���)�O�#���D�k���s�>Ac��d|vr|Sd}d}g}t|�D]0\}}|dk(s�|�|}�||k7r|j|||�|dz}d}�2|t|�kr|j||d�dj|�S)z Strip real names between quotes.r)rN�r)r?�append�len�join)r;�start�open_pos�resultr<r>s      r�_strip_quoted_realnamesrH}s���
�$����
�E��H�
�F�&�t�,���R�
��9������H�$��M�M�$�u�X�"6�7��a�����-�
�s�4�y���
�
�d�5�6�l�#�
�7�7�6�?�r&T)�strictc��|s3tjd�|D��}t|�}|jS|D�cgc]
}t	|���}}t|�}tj|�}t|�}t
|j�}d}|D]$}t|�}|d|jd�zz
}�&t|�|k7rdgS|Scc}w)z�Return a list of (REALNAME, EMAIL) or ('','') for each fieldvalue.

    When parsing fails for a fieldvalue, a 2-tuple of ('', '') is returned in
    its place.

    If strict is true, use a strict parser which rejects malformed inputs.
    c3�2K�|]}t|����y�w)N�r0)�.0�vs  r�	<genexpr>zgetaddresses.<locals>.<genexpr>�s����:�k��c�!�f�k�s�rrA�,�rr)
�
COMMASPACErD�_AddressList�addresslistr0�_pre_parse_validation�_post_parse_validationrH�countrC)�fieldvaluesrI�all�arNr;rG�ns        rr	r	�s���$��o�o�:�k�:�:�������}�}��#.�/�;�a�3�q�6�;�K�/�'��4�K��?�?�;�'�D��T��A�
#�A�M�M�
2�F�	
�A�
��
$�A�&��	�Q������
�����6�{�a���z���M��%0s�Cc��t|�}d}t|�D]"\}}|dk(r|dz
}�|dk(s�|dz}|dks�"y|dk(S)Nr�(rA�)F)rHr?)r;�opensr<r>s    r�_check_parenthesisr`�sZ��"�4�(�D�
�E�&�t�,���R�
��9��Q�J�E�
�3�Y��Q�J�E��q�y��
-�
�Q�J�r&c�T�g}|D] }t|�sd}|j|��"|S)Nz('', ''))r`rB)�email_header_fields�accepted_valuesrNs   rrUrU�s4���O�
 ��!�!�$��A����q�!�!�
�r&c�L�g}|D]}d|dvrd}|j|��|S)N�[rArQ)rB)�parsed_email_header_tuplesrcrNs   rrVrV�s9���O�(���!�A�$�;��A����q�!�(�
�r&c	�`�dgd�|d|dgd�|ddz
|d|d|d	|d
|fzS)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�DecrAr����)�	timetuple�zones  r�_format_timetuple_and_zoner��sZ��/�9�)�A�,�G��!��	3�3<�Q�<�!�3C�	E��!��i��l�I�a�L�)�A�,��
3��r&c��|�tj�}tjj|tjj�}|r|j�}d}n|s|j
d��}t||�S)a�Returns a date string as specified by RFC 2822, e.g.:

    Fri, 09 Nov 2001 01:08:47 -0000

    Optional timeval if given is a floating-point time value as accepted by
    gmtime() and localtime(), otherwise the current time is used.

    Optional localtime is a flag that when True, interprets timeval, and
    returns a date relative to the local timezone instead of UTC, properly
    taking daylight savings time into account.

    Optional argument usegmt means that the timezone is written out as
    an ascii string, not numeric one (so "GMT" instead of "+0000"). This
    is needed for HTTP, and is only used when localtime==False.
    NF)�tzinfo)�time�datetime�
fromtimestamp�timezone�utc�
astimezoner!r)�timeval�	localtime�usegmt�dts    rrr�sk��$���)�)�+��	�	�	�	(�	(��(�2C�2C�2G�2G�	H�B��
�]�]�_����
�
�Z�Z�t�Z�
$���2�v�&�&r&c��|j�}|rA|j�'|jtjjk7rtd��d}n |j�d}n|j
d�}t||�S)a$Turn a datetime into a date string as specified in RFC 2822.

    If usegmt is True, dt must be an aware datetime with an offset of zero.  In
    this case 'GMT' will be rendered instead of the normal +0000 required by
    RFC2822.  This is to support HTTP headers involving date stamps.
    z%usegmt option requires a UTC datetime�GMTz-0000z%z)r�r�r�r�r��
ValueError�strftimer�)r�r��nowr�s    rrrsn��
�,�,�.�C�
�
�9�9���	�	�X�->�->�-B�-B� B��D�E�E���	���	����{�{�4� ��%�c�4�0�0r&c���ttj�dz�}tj�}t	j
d�}|�d}nd|z}|�t
j�}d|||||fz}|S)a{Returns a string suitable for RFC 2822 compliant Message-ID, e.g:

    <142480216486.20800.16526388040877946887@nightshade.la.mastaler.com>

    Optional idstring if given is a string used to strengthen the
    uniqueness of the message id.  Optional domain if given provides the
    portion of the message id after the '@'.  It defaults to the locally
    defined hostname.
    �d�@r�.z<%d.%d.%d%s@%s>)�intr��os�getpid�random�getrandbits�socket�getfqdn)�idstring�domainr��pid�randint�msgids      rr
r
"sr���$�)�)�+�c�/�"�G�
�)�)�+�C�� � ��$�G�������>��
�~����!����#�w��&� I�I�E��Lr&c	��t|�}|�tdt|�z��|�^}}|�tj|dd�Stj|dddtjtj
|���i�S)Nz!Invalid date value or format "%s"ror�)�seconds)rr�r0r�r��	timedelta)�data�parsed_date_tz�dtuple�tzs    rrr9s���"�4�(�N����<�s�4�y�H�I�I� �K�V�R�	�z�� � �&��!�*�-�-����f�R�a�j�F��$�$�X�%7�%7��%C�D�F�Fr&c��|st|�j}|sy|dSt|t�r|d}t|t�syt|g�d}t
t|�j�}|rt|�dkDry|dS)a
    Parse addr into its constituent realname and email address parts.

    Return a tuple of realname and email address, unless the parse fails, in
    which case return a 2-tuple of ('', '').

    If strict is True, use a strict parser which rejects malformed inputs.
    rQrrA)rSrTr/�listr0rUrVrC)r;rI�addrss   rrrDs�����T�"�.�.�����Q�x���$����A�w���d�C� �� �$��(��+�D�"�<��#5�#A�#A�B�E��C��J��N����8�Or&c��t|�dkDrn|jd�r6|jd�r%|ddjdd�jdd�S|jd�r|jd�r|ddS|S)	zRemove quotes from a string.rAr)���z\\r9z\"�<r*)rC�
startswith�endswithr!rLs rrrcsr��
�3�x�!�|��>�>�#��3�<�<��#4��q��9�$�$�V�T�2�:�:�5�#�F�F��>�>�#��3�<�<��#4��q��9���Jr&c�X�|jtd�}t|�dkrdd|fS|S)z#Decode string according to RFC 2231rpN)�split�TICKrC)r�partss  rrros.��
�G�G�D�!��E�
�5�z�Q���T�1�}���Lr&c�v�tjj|d|xsd��}|�|�|S|�d}|�d|�d|��S)z�Encode string according to RFC 2231.

    If neither charset nor language is given, then s is returned as-is.  If
    charset is given but not language, the string is encoded using the empty
    string for language.
    rr()�safe�encodingr)�urllib�parser)rr3�languages   rrrwsK��	�����1�2��0B�7��C�A���8�+������� �(�A�.�.r&z&^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$c��|dg}i}|ddD]�\}}|jd�}t|�}tj|�}|rG|j	dd�\}}|�t|�}|j
|g�j|||f���|j|dt|�zf���|r�|j�D]�\}}g}d}	|j�|D]<\}}
}|r#tjj|
d	�
�}
d}	|j|
��>ttj|��}|	r)t|�\}}}|j|||d|zff���|j|d|zf���|S)zDecode parameters list according to RFC 2231.

    params is a sequence of 2-tuples containing (param name, string value).
    rrAN�*r4�numz"%s"Fzlatin-1)r�T)r�r�rfc2231_continuation�match�groupr��
setdefaultrBr�items�sortr�r��EMPTYSTRINGrDr)
�params�
new_params�rfc2231_paramsr4�value�encoded�mor��
continuations�extendedrr3r�s
             rrr�s���
��)��J��N��a�b�z���e��-�-��$������
!�
'�
'��
-��
������/�I�D�#����#�h���%�%�d�B�/�6�6��U�G�7L�M����t�V�e�E�l�%:�;�<�"��#1�#7�#7�#9��D�-��E��H���� �$1���Q������,�,�Q��,�C�A�#�H����Q��$1��+�*�*�5�1�2�E��+9�%�+@�(���5��!�!�4�'�8�V�e�^�)L�"M�N��!�!�4��%��"8�9�/$:�0�r&c���t|t�rt|�dk7rt|�S|\}}}|�|}t	|d�}	t|||�S#t$rt|�cYSwxYw)Nr}zraw-unicode-escape)r/�tuplerCr�bytesr0�LookupError)r��errors�fallback_charsetr3r��text�rawbytess       rrr�st���e�U�#�s�5�z�Q���u�~��$��G�X�t���#���T�/�0�H���8�W�f�-�-�����t�}���s�A�A%�$A%c��|�ddl}|jddd��|�tjj�}|j	�S)a}Return local time as an aware datetime object.

    If called without arguments, return current time.  Otherwise *dt*
    argument should be a datetime instance, and it is converted to the
    local time zone according to the system time zone database.  If *dt* is
    naive (that is, dt.tzinfo is None), it is assumed to be in local time.
    The isdst parameter is ignored.

    Nrz$The 'isdst' parameter to 'localtime'z>{name} is deprecated and slated for removal in Python {remove})r}�)�message�remove)�warnings�_deprecatedr�r�r�)r��isdstr�s   rr�r��sP��
������2�T��	�	�

�z�
�
�
�
"�
"�
$��
�=�=�?�r&)r)NFF)F)NN)r!zus-ascii)4�__doc__�__all__r��rer�r�r�r��urllib.parser��email._parseaddrrrrSrr
rr�
email.charsetrrRr��UEMPTYSTRING�CRLFr��compiler+r-rr%rr?rH�supports_strict_parsingr	r`rUrVr�rrr
rrrrr�ASCIIr�rrr�r�r&r�<module>r�s��
���$
�	��
�
���"�8�&�C�C�"�
�
�����
��
��
�R�Z�Z�+�
,�
��B�J�J�x� �	�	�5��B��2��(,�)�X��	��'�:1�&�.F�#��>��/�"�r�z�z�"K��H�H���.�`*3�,6��4r&__pycache__/utils.cpython-312.opt-2.pyc000064400000030735151706203560013574 0ustar00�

T��h�>���	gd�ZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddl	mZddl	m
Z
ddl	mZmZmZddlmZdZd	Zd	Zd
ZdZej0d�Zej0d
�Zd�Zd�Zd&d�Zd�Zd�ZdZ dd�d�Z!d�Z"d�Z#d�Z$d�Z%d'd�Z&d(d�Z'd)d�Z(d�Z)dd�d�Z*d�Z+d �Z,d)d!�Z-ej0d"ej\�Z/d#�Z0		d*d$�Z1d)d%�Z2y)+)�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�F�		|j�y#t$rYywxYw)NFT)�encode�UnicodeEncodeError)�ss �$/usr/lib64/python3.12/email/utils.py�_has_surrogatesr4s(��E��	���
�������s��	 � c�J�|jdd�}|jdd�S)N�utf-8�surrogateescape�replace)r�decode)�string�original_bytess  r�	_sanitizer%As(��
�]�]�7�,=�>�N�� � ��)�4�4�c�X�	|\}}|jd�|rM	|jd�d}tj|�rd}tj	d|�}|�|�|�d|�d�S|S#t
$r7t
|t�rt|�}|j|�}|�d|�d�cYSwxYw)N�asciir�"z\\\g<0>z <�>)
r�
specialsre�search�	escapesre�subr�
isinstance�strr�
header_encode)�pair�charset�name�address�quotes�encoded_names      rrrMs�����M�D�'��N�N�7���	C��K�K�� ��F�� � ��&����=�=��T�2�D�$*�D�&�'�B�B��N��"�	7��'�3�'�!�'�*��"�0�0��6�L� ,�g�6�6�		7�s�A)�)=B)�(B)c#�K�d}d}t|�D]!\}}|r|d|zf��d}�|dk(rd}�||f���#|r|df��yy�w)NrF�\T)�	enumerate)�addr�pos�escape�chs    r�_iter_escaped_charsr?nsb����
�C�
�F��T�?���R����r�	�"�"��F�
�4�Z��F���)�O�#���D�k���s�>Ac��	d|vr|Sd}d}g}t|�D]0\}}|dk(s�|�|}�||k7r|j|||�|dz}d}�2|t|�kr|j||d�dj|�S)Nr)r�r)r?�append�len�join)r;�start�open_pos�resultr<r>s      r�_strip_quoted_realnamesrH}s���*�
�$����
�E��H�
�F�&�t�,���R�
��9������H�$��M�M�$�u�X�"6�7��a�����-�
�s�4�y���
�
�d�5�6�l�#�
�7�7�6�?�r&T)�strictc��	|s3tjd�|D��}t|�}|jS|D�cgc]
}t	|���}}t|�}tj|�}t|�}t
|j�}d}|D]$}t|�}|d|jd�zz
}�&t|�|k7rdgS|Scc}w)Nc3�2K�|]}t|����y�w)N�r0)�.0�vs  r�	<genexpr>zgetaddresses.<locals>.<genexpr>�s����:�k��c�!�f�k�s�rrA�,�rr)
�
COMMASPACErD�_AddressList�addresslistr0�_pre_parse_validation�_post_parse_validationrH�countrC)�fieldvaluesrI�all�arNr;rG�ns        rr	r	�s����"��o�o�:�k�:�:�������}�}��#.�/�;�a�3�q�6�;�K�/�'��4�K��?�?�;�'�D��T��A�
#�A�M�M�
2�F�	
�A�
��
$�A�&��	�Q������
�����6�{�a���z���M��%0s�C
c��t|�}d}t|�D]"\}}|dk(r|dz
}�|dk(s�|dz}|dks�"y|dk(S)Nr�(rA�)F)rHr?)r;�opensr<r>s    r�_check_parenthesisr`�sZ��"�4�(�D�
�E�&�t�,���R�
��9��Q�J�E�
�3�Y��Q�J�E��q�y��
-�
�Q�J�r&c�T�g}|D] }t|�sd}|j|��"|S)Nz('', ''))r`rB)�email_header_fields�accepted_valuesrNs   rrUrU�s4���O�
 ��!�!�$��A����q�!�!�
�r&c�L�g}|D]}d|dvrd}|j|��|S)N�[rArQ)rB)�parsed_email_header_tuplesrcrNs   rrVrV�s9���O�(���!�A�$�;��A����q�!�(�
�r&c	�`�dgd�|d|dgd�|ddz
|d|d|d	|d
|fzS)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�DecrAr����)�	timetuple�zones  r�_format_timetuple_and_zoner��sZ��/�9�)�A�,�G��!��	3�3<�Q�<�!�3C�	E��!��i��l�I�a�L�)�A�,��
3��r&c�
�	|�tj�}tjj|tjj�}|r|j�}d}n|s|j
d��}t||�S)NF)�tzinfo)�time�datetime�
fromtimestamp�timezone�utc�
astimezoner!r)�timeval�	localtime�usegmt�dts    rrr�sp���"���)�)�+��	�	�	�	(�	(��(�2C�2C�2G�2G�	H�B��
�]�]�_����
�
�Z�Z�t�Z�
$���2�v�&�&r&c��	|j�}|rA|j�'|jtjjk7rtd��d}n |j�d}n|j
d�}t||�S)Nz%usegmt option requires a UTC datetime�GMTz-0000z%z)r�r�r�r�r��
ValueError�strftimer�)r�r��nowr�s    rrrss���
�,�,�.�C�
�
�9�9���	�	�X�->�->�-B�-B� B��D�E�E���	���	����{�{�4� ��%�c�4�0�0r&c���	ttj�dz�}tj�}t	j
d�}|�d}nd|z}|�t
j�}d|||||fz}|S)N�d�@r�.z<%d.%d.%d%s@%s>)�intr��os�getpid�random�getrandbits�socket�getfqdn)�idstring�domainr��pid�randint�msgids      rr
r
"sw����$�)�)�+�c�/�"�G�
�)�)�+�C�� � ��$�G�������>��
�~����!����#�w��&� I�I�E��Lr&c	��t|�}|�tdt|�z��|�^}}|�tj|dd�Stj|dddtjtj
|���i�S)Nz!Invalid date value or format "%s"ror�)�seconds)rr�r0r�r��	timedelta)�data�parsed_date_tz�dtuple�tzs    rrr9s���"�4�(�N����<�s�4�y�H�I�I� �K�V�R�	�z�� � �&��!�*�-�-����f�R�a�j�F��$�$�X�%7�%7��%C�D�F�Fr&c��	|st|�j}|sy|dSt|t�r|d}t|t�syt|g�d}t
t|�j�}|rt|�dkDry|dS)NrQrrA)rSrTr/�listr0rUrVrC)r;rI�addrss   rrrDs������T�"�.�.�����Q�x���$����A�w���d�C� �� �$��(��+�D�"�<��#5�#A�#A�B�E��C��J��N����8�Or&c��	t|�dkDrn|jd�r6|jd�r%|ddjdd�jdd�S|jd�r|jd�r|ddS|S)	NrAr)���z\\r9z\"�<r*)rC�
startswith�endswithr!rLs rrrcsu��&�
�3�x�!�|��>�>�#��3�<�<��#4��q��9�$�$�V�T�2�:�:�5�#�F�F��>�>�#��3�<�<��#4��q��9���Jr&c�Z�	|jtd�}t|�dkrdd|fS|S)Nrp)�split�TICKrC)r�partss  rrros1��-�
�G�G�D�!��E�
�5�z�Q���T�1�}���Lr&c�x�	tjj|d|xsd��}|�|�|S|�d}|�d|�d|��S)Nrr()�safe�encodingr)�urllib�parser)rr3�languages   rrrwsP���	�����1�2��0B�7��C�A���8�+������� �(�A�.�.r&z&^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$c��	|dg}i}|ddD]�\}}|jd�}t|�}tj|�}|rG|j	dd�\}}|�t|�}|j
|g�j|||f���|j|dt|�zf���|r�|j�D]�\}}g}d}	|j�|D]<\}}
}|r#tjj|
d�	�}
d
}	|j|
��>ttj|��}|	r)t|�\}}}|j|||d|zff���|j|d|zf���|S)NrrA�*r4�numz"%s"Fzlatin-1)r�T)r�r�rfc2231_continuation�match�groupr��
setdefaultrBr�items�sortr�r��EMPTYSTRINGrDr)
�params�
new_params�rfc2231_paramsr4�value�encoded�mor��
continuations�extendedrr3r�s
             rrr�s������)��J��N��a�b�z���e��-�-��$������
!�
'�
'��
-��
������/�I�D�#����#�h���%�%�d�B�/�6�6��U�G�7L�M����t�V�e�E�l�%:�;�<�"��#1�#7�#7�#9��D�-��E��H���� �$1���Q������,�,�Q��,�C�A�#�H����Q��$1��+�*�*�5�1�2�E��+9�%�+@�(���5��!�!�4�'�8�V�e�^�)L�"M�N��!�!�4��%��"8�9�/$:�0�r&c���t|t�rt|�dk7rt|�S|\}}}|�|}t	|d�}	t|||�S#t$rt|�cYSwxYw)Nr}zraw-unicode-escape)r/�tuplerCr�bytesr0�LookupError)r��errors�fallback_charsetr3r��text�rawbytess       rrr�st���e�U�#�s�5�z�Q���u�~��$��G�X�t���#���T�/�0�H���8�W�f�-�-�����t�}���s�A�A%�$A%c��	|�ddl}|jddd��|�tjj�}|j	�S)Nrz$The 'isdst' parameter to 'localtime'z>{name} is deprecated and slated for removal in Python {remove})r}�)�message�remove)�warnings�_deprecatedr�r�r�)r��isdstr�s   rr�r��sU���
������2�T��	�	�

�z�
�
�
�
"�
"�
$��
�=�=�?�r&)r)NFF)F)NN)r!zus-ascii)3�__all__r��rer�r�r�r��urllib.parser��email._parseaddrrrrSrr
rr�
email.charsetrrRr��UEMPTYSTRING�CRLFr��compiler+r-rr%rr?rH�supports_strict_parsingr	r`rUrVr�rrr
rrrrr�ASCIIr�rrr�r�r&r�<module>r�s��
���$
�	��
�
���"�8�&�C�C�"�
�
�����
��
��
�R�Z�Z�+�
,�
��B�J�J�x� �	�	�5��B��2��(,�)�X��	��'�:1�&�.F�#��>��/�"�r�z�z�"K��H�H���.�`*3�,6��4r&__pycache__/__init__.cpython-312.opt-1.pyc000064400000003601151706203560014162 0ustar00�

T��h���(�dZgd�Zd�Zd�Zd�Zd�Zy)z?A package for parsing, handling, and generating email messages.)�
base64mime�charset�encoders�errors�
feedparser�	generator�header�	iterators�message�message_from_file�message_from_binary_file�message_from_string�message_from_bytes�mime�parser�
quoprimime�utilsc�<�ddlm}||i|��j|�S)zvParse a string into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    ���Parser)�email.parserr�parsestr)�s�args�kwsrs    �'/usr/lib64/python3.12/email/__init__.pyr
r
s"��
$��4��3��(�(��+�+�c�<�ddlm}||i|��j|�S)z|Parse a bytes string into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    r��BytesParser)rr �
parsebytes)rrrr s    rrr's"��
)���$��$�/�/��2�2rc�<�ddlm}||i|��j|�S)z�Read a file and parse its contents into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    rr)rr�parse)�fprrrs    rrr/s"��
$��4��3��%�%�b�)�)rc�<�ddlm}||i|��j|�S)z�Read a binary file and parse its contents into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    rr)rr r#)r$rrr s    rrr7s"��
)���$��$�*�*�2�.�.rN)�__doc__�__all__r
rrr�rr�<module>r)s&��
F���0,�3�*�/r__pycache__/__init__.cpython-312.opt-2.pyc000064400000002460151706203560014165 0ustar00�

T��h���&�	gd�Zd�Zd�Zd�Zd�Zy))�
base64mime�charset�encoders�errors�
feedparser�	generator�header�	iterators�message�message_from_file�message_from_binary_file�message_from_string�message_from_bytes�mime�parser�
quoprimime�utilsc�>�	ddlm}||i|��j|�S�N�)�Parser)�email.parserr�parsestr)�s�args�kwsrs    �'/usr/lib64/python3.12/email/__init__.pyr
r
s'���$��4��3��(�(��+�+�c�>�	ddlm}||i|��j|�S�Nr)�BytesParser)rr �
parsebytes)rrrr s    rrr's'���)���$��$�/�/��2�2rc�>�	ddlm}||i|��j|�Sr)rr�parse)�fprrrs    rrr/s'���$��4��3��%�%�b�)�)rc�>�	ddlm}||i|��j|�Sr)rr r#)r$rrr s    rrr7s'���)���$��$�*�*�2�.�.rN)�__all__r
rrr�rr�<module>r(s&��
F���0,�3�*�/r__pycache__/__init__.cpython-312.pyc000064400000003601151706203560013223 0ustar00�

T��h���(�dZgd�Zd�Zd�Zd�Zd�Zy)z?A package for parsing, handling, and generating email messages.)�
base64mime�charset�encoders�errors�
feedparser�	generator�header�	iterators�message�message_from_file�message_from_binary_file�message_from_string�message_from_bytes�mime�parser�
quoprimime�utilsc�<�ddlm}||i|��j|�S)zvParse a string into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    ���Parser)�email.parserr�parsestr)�s�args�kwsrs    �'/usr/lib64/python3.12/email/__init__.pyr
r
s"��
$��4��3��(�(��+�+�c�<�ddlm}||i|��j|�S)z|Parse a bytes string into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    r��BytesParser)rr �
parsebytes)rrrr s    rrr's"��
)���$��$�/�/��2�2rc�<�ddlm}||i|��j|�S)z�Read a file and parse its contents into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    rr)rr�parse)�fprrrs    rrr/s"��
$��4��3��%�%�b�)�)rc�<�ddlm}||i|��j|�S)z�Read a binary file and parse its contents into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    rr)rr r#)r$rrr s    rrr7s"��
)���$��$�*�*�2�.�.rN)�__doc__�__all__r
rrr�rr�<module>r)s&��
F���0,�3�*�/rmime/__pycache__/text.cpython-312.pyc000064400000002733151706203560013404 0ustar00�

T��hr��0�dZdgZddlmZGd�de�Zy)z.Class representing text/* type MIME documents.�MIMEText�)�MIMENonMultipartc��eZdZdZddd�d�Zy)rz0Class for generating text/* type MIME documents.N)�policyc	��|�	|jd�d}tj|d||t	|���|j||�y#t$rd}Y�CwxYw)a~Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.
        Nzus-asciizutf-8�text)r�charset)�encode�UnicodeEncodeErrorr�__init__�str�set_payload)�self�_text�_subtype�_charsetrs     �(/usr/lib64/python3.12/email/mime/text.pyrzMIMEText.__init__sg����
#����Z�(�%��	�!�!�$����*-�h�-�	9�	
�����)��
&�
#�"��
#�s�A
�
A�A)�plainN)�__name__�
__module__�__qualname__�__doc__r��rrrs��:�*��*rN)r�__all__�email.mime.nonmultipartrrrrr�<module>rs!��
5��,��4�*��*rmime/__pycache__/__init__.cpython-312.opt-1.pyc000064400000000215151706203560015107 0ustar00�

J�i���y)N�r��,/usr/lib64/python3.12/email/mime/__init__.py�<module>rs�rmime/__pycache__/__init__.cpython-312.opt-2.pyc000064400000000215151706203560015110 0ustar00�

J�i���y)N�r��,/usr/lib64/python3.12/email/mime/__init__.py�<module>rs�rmime/__pycache__/__init__.cpython-312.pyc000064400000000215151706203560014150 0ustar00�

J�i���y)N�r��,/usr/lib64/python3.12/email/mime/__init__.py�<module>rs�rmime/__pycache__/application.cpython-312.opt-1.pyc000064400000003203151706203560015653 0ustar00�

T��h)��<�dZdgZddlmZddlmZGd�de�Zy)z5Class representing application/* type MIME documents.�MIMEApplication�)�encoders)�MIMENonMultipartc�6�eZdZdZdej
fdd�d�Zy)rz2Class for generating application/* MIME documents.zoctet-streamN)�policyc��|�td��tj|d|fd|i|��|j|�||�y)aCreate an application/* type MIME document.

        _data contains the bytes for the raw application data.

        _subtype is the MIME content type subtype, defaulting to
        'octet-stream'.

        _encoder is a function which will perform the actual encoding for
        transport of the application data, defaulting to base64 encoding.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        Nz Invalid application MIME subtype�applicationr)�	TypeErrorr�__init__�set_payload)�self�_data�_subtype�_encoderr�_paramss      �//usr/lib64/python3.12/email/mime/application.pyrzMIMEApplication.__init__sN�� ���>�?�?��!�!�$�
�x�	-��	-�$+�	-���������)�__name__�
__module__�__qualname__�__doc__r�
encode_base64r�rrrr
s��<�'5�"�0�0��<@�rN)r�__all__�emailr�email.mime.nonmultipartrrrrr�<module>rs%��
<��
���4��&�rmime/__pycache__/application.cpython-312.opt-2.pyc000064400000002004151706203560015652 0ustar00�

T��h)��:�	dgZddlmZddlmZGd�de�Zy)�MIMEApplication�)�encoders)�MIMENonMultipartc�4�eZdZ	dejfdd�d�Zy)rzoctet-streamN)�policyc��	|�td��tj|d|fd|i|��|j|�||�y)Nz Invalid application MIME subtype�applicationr)�	TypeErrorr�__init__�set_payload)�self�_data�_subtype�_encoderr�_paramss      �//usr/lib64/python3.12/email/mime/application.pyrzMIMEApplication.__init__sS��
	����>�?�?��!�!�$�
�x�	-��	-�$+�	-���������)�__name__�
__module__�__qualname__r�
encode_base64r�rrrr
s��<�'5�"�0�0��<@�rN)�__all__�emailr�email.mime.nonmultipartrrrrr�<module>rs%��
<��
���4��&�rmime/__pycache__/application.cpython-312.pyc000064400000003203151706203560014714 0ustar00�

T��h)��<�dZdgZddlmZddlmZGd�de�Zy)z5Class representing application/* type MIME documents.�MIMEApplication�)�encoders)�MIMENonMultipartc�6�eZdZdZdej
fdd�d�Zy)rz2Class for generating application/* MIME documents.zoctet-streamN)�policyc��|�td��tj|d|fd|i|��|j|�||�y)aCreate an application/* type MIME document.

        _data contains the bytes for the raw application data.

        _subtype is the MIME content type subtype, defaulting to
        'octet-stream'.

        _encoder is a function which will perform the actual encoding for
        transport of the application data, defaulting to base64 encoding.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        Nz Invalid application MIME subtype�applicationr)�	TypeErrorr�__init__�set_payload)�self�_data�_subtype�_encoderr�_paramss      �//usr/lib64/python3.12/email/mime/application.pyrzMIMEApplication.__init__sN�� ���>�?�?��!�!�$�
�x�	-��	-�$+�	-���������)�__name__�
__module__�__qualname__�__doc__r�
encode_base64r�rrrr
s��<�'5�"�0�0��<@�rN)r�__all__�emailr�email.mime.nonmultipartrrrrr�<module>rs%��
<��
���4��&�rmime/__pycache__/audio.cpython-312.opt-1.pyc000064400000006567151706203560014471 0ustar00�

T��h���dZdgZddlmZddlmZddlmZGd�de�ZgZ	d�Z
d�Zed	��Zed
��Z
ed��Zy)
z/Class representing audio/* type MIME documents.�	MIMEAudio�)�BytesIO)�encoders)�MIMENonMultipartc�6�eZdZdZdej
fdd�d�Zy)rz,Class for generating audio/* MIME documents.N)�policyc��|�t|�}|�td��tj|d|fd|i|��|j	|�||�y)a�Create an audio/* type MIME document.

        _audiodata contains the bytes for the raw audio data.  If this data
        can be decoded as au, wav, aiff, or aifc, then the
        subtype will be automatically included in the Content-Type header.
        Otherwise, you can specify  the specific audio subtype via the
        _subtype parameter.  If _subtype is not given, and no subtype can be
        guessed, a TypeError is raised.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        Nz!Could not find audio MIME subtype�audior)�_what�	TypeErrorr�__init__�set_payload)�self�
_audiodata�_subtype�_encoderr�_paramss      �)/usr/lib64/python3.12/email/mime/audio.pyr
zMIMEAudio.__init__s^��,���Z�(�H����?�@�@��!�!�$���	-�&�	-�$+�	-�����$����)�__name__�
__module__�__qualname__�__doc__r�
encode_base64r
�rrrrs��6�,0�"�0�0��<@�rc�X�|dd}t|�}tD]}|||�x}s�|cSy)Ni)r�_rules)�data�hdr�fakefile�testfn�ress     rrr8s>���t��*�C��s�|�H�����h�'�'�3�'��J��rc�0�tj|�|S)N)r�append)�rulefuncs r�ruler&Gs��
�M�M�(���Orc�8�|jd�sy|dddvryy)NsFORM��>�AIFC�AIFFzx-aiff��
startswith��h�fs  r�_aiffr1Ls&���<�<�� ����2�w�$�$��rc�(�|jd�ryy)Ns.snd�basicr,r.s  r�_aur4Vs���|�|�G���rc�H�|jd�r|dddk7s|dddk7ryy)NsRIFFr(r)sWAVE�sfmt zx-wavr,r.s  r�_wavr7^s0��
�<�<�� �A�a��G�w�$6�!�B�r�(�g�:M��rN)r�__all__�ior�emailr�email.mime.nonmultipartrrrrr&r1r4r7rrr�<module>r<su��
6��-����4� � � �F
����
�����������rmime/__pycache__/audio.cpython-312.opt-2.pyc000064400000004411151706203560014454 0ustar00�

T��h���	dgZddlmZddlmZddlmZGd�de�ZgZd�Z	d�Z
e
d��Ze
d	��Ze
d
��Z
y)�	MIMEAudio�)�BytesIO)�encoders)�MIMENonMultipartc�4�eZdZ	dejfdd�d�Zy)rN)�policyc��	|�t|�}|�td��tj|d|fd|i|��|j	|�||�y)Nz!Could not find audio MIME subtype�audior)�_what�	TypeErrorr�__init__�set_payload)�self�
_audiodata�_subtype�_encoderr�_paramss      �)/usr/lib64/python3.12/email/mime/audio.pyr
zMIMEAudio.__init__sc��	�(���Z�(�H����?�@�@��!�!�$���	-�&�	-�$+�	-�����$����)�__name__�
__module__�__qualname__r�
encode_base64r
�rrrrs��6�,0�"�0�0��<@�rc�X�|dd}t|�}tD]}|||�x}s�|cSy)Ni)r�_rules)�data�hdr�fakefile�testfn�ress     rrr8s>���t��*�C��s�|�H�����h�'�'�3�'��J��rc�0�tj|�|S)N)r�append)�rulefuncs r�ruler%Gs��
�M�M�(���Orc�8�|jd�sy|dddvryy)NsFORM��>�AIFC�AIFFzx-aiff��
startswith��h�fs  r�_aiffr0Ls&���<�<�� ����2�w�$�$��rc�(�|jd�ryy)Ns.snd�basicr+r-s  r�_aur3Vs���|�|�G���rc�H�|jd�r|dddk7s|dddk7ryy)NsRIFFr'r(sWAVE�sfmt zx-wavr+r-s  r�_wavr6^s0��
�<�<�� �A�a��G�w�$6�!�B�r�(�g�:M��rN)�__all__�ior�emailr�email.mime.nonmultipartrrrrr%r0r3r6rrr�<module>r;su��
6��-����4� � � �F
����
�����������rmime/__pycache__/audio.cpython-312.pyc000064400000006567151706203560013532 0ustar00�

T��h���dZdgZddlmZddlmZddlmZGd�de�ZgZ	d�Z
d�Zed	��Zed
��Z
ed��Zy)
z/Class representing audio/* type MIME documents.�	MIMEAudio�)�BytesIO)�encoders)�MIMENonMultipartc�6�eZdZdZdej
fdd�d�Zy)rz,Class for generating audio/* MIME documents.N)�policyc��|�t|�}|�td��tj|d|fd|i|��|j	|�||�y)a�Create an audio/* type MIME document.

        _audiodata contains the bytes for the raw audio data.  If this data
        can be decoded as au, wav, aiff, or aifc, then the
        subtype will be automatically included in the Content-Type header.
        Otherwise, you can specify  the specific audio subtype via the
        _subtype parameter.  If _subtype is not given, and no subtype can be
        guessed, a TypeError is raised.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        Nz!Could not find audio MIME subtype�audior)�_what�	TypeErrorr�__init__�set_payload)�self�
_audiodata�_subtype�_encoderr�_paramss      �)/usr/lib64/python3.12/email/mime/audio.pyr
zMIMEAudio.__init__s^��,���Z�(�H����?�@�@��!�!�$���	-�&�	-�$+�	-�����$����)�__name__�
__module__�__qualname__�__doc__r�
encode_base64r
�rrrrs��6�,0�"�0�0��<@�rc�X�|dd}t|�}tD]}|||�x}s�|cSy)Ni)r�_rules)�data�hdr�fakefile�testfn�ress     rrr8s>���t��*�C��s�|�H�����h�'�'�3�'��J��rc�0�tj|�|S)N)r�append)�rulefuncs r�ruler&Gs��
�M�M�(���Orc�8�|jd�sy|dddvryy)NsFORM��>�AIFC�AIFFzx-aiff��
startswith��h�fs  r�_aiffr1Ls&���<�<�� ����2�w�$�$��rc�(�|jd�ryy)Ns.snd�basicr,r.s  r�_aur4Vs���|�|�G���rc�H�|jd�r|dddk7s|dddk7ryy)NsRIFFr(r)sWAVE�sfmt zx-wavr,r.s  r�_wavr7^s0��
�<�<�� �A�a��G�w�$6�!�B�r�(�g�:M��rN)r�__all__�ior�emailr�email.mime.nonmultipartrrrrr&r1r4r7rrr�<module>r<su��
6��-����4� � � �F
����
�����������rmime/__pycache__/base.cpython-312.opt-1.pyc000064400000002424151706203560014266 0ustar00�

T��h���L�dZdgZddlZddlmZGd�dej
�Zy)�$Base class for MIME specializations.�MIMEBase�N)�messagec��eZdZdZdd�d�Zy)rrN��policyc��|�tjj}tjj||��|�d|��}|jd|fi|��d|d<y)z�This constructor adds a Content-Type: and a MIME-Version: header.

        The Content-Type: header is taken from the _maintype and _subtype
        arguments.  Additional parameters for this header are taken from the
        keyword arguments.
        Nr�/zContent-Typez1.0zMIME-Version)�emailr�compat32r�Message�__init__�
add_header)�self�	_maintype�_subtyper�_params�ctypes      �(/usr/lib64/python3.12/email/mime/base.pyrzMIMEBase.__init__sX���>��\�\�*�*�F���� � ��f� �5�$�h�/��������9��9�$��^��)�__name__�
__module__�__qualname__�__doc__r�rrrrs
��.�6:�%r)r�__all__�email.policyrrr
rrrr�<module>rs'��
+��,����%�w���%rmime/__pycache__/base.cpython-312.opt-2.pyc000064400000001737151706203570014276 0ustar00�

T��h���J�	dgZddlZddlmZGd�dej�Zy)�MIMEBase�N)�messagec��eZdZ	dd�d�Zy)rN��policyc��	|�tjj}tjj||��|�d|��}|jd|fi|��d|d<y)Nr�/zContent-Typez1.0zMIME-Version)�emailr�compat32r�Message�__init__�
add_header)�self�	_maintype�_subtyper�_params�ctypes      �(/usr/lib64/python3.12/email/mime/base.pyr
zMIMEBase.__init__s]��	��>��\�\�*�*�F���� � ��f� �5�$�h�/��������9��9�$��^��)�__name__�
__module__�__qualname__r
�rrrrs
��.�6:�%r)�__all__�email.policyr
rrrrrr�<module>rs'��
+��,����%�w���%rmime/__pycache__/base.cpython-312.pyc000064400000002424151706203570013330 0ustar00�

T��h���L�dZdgZddlZddlmZGd�dej
�Zy)�$Base class for MIME specializations.�MIMEBase�N)�messagec��eZdZdZdd�d�Zy)rrN��policyc��|�tjj}tjj||��|�d|��}|jd|fi|��d|d<y)z�This constructor adds a Content-Type: and a MIME-Version: header.

        The Content-Type: header is taken from the _maintype and _subtype
        arguments.  Additional parameters for this header are taken from the
        keyword arguments.
        Nr�/zContent-Typez1.0zMIME-Version)�emailr�compat32r�Message�__init__�
add_header)�self�	_maintype�_subtyper�_params�ctypes      �(/usr/lib64/python3.12/email/mime/base.pyrzMIMEBase.__init__sX���>��\�\�*�*�F���� � ��f� �5�$�h�/��������9��9�$��^��)�__name__�
__module__�__qualname__�__doc__r�rrrrs
��.�6:�%r)r�__all__�email.policyrrr
rrrr�<module>rs'��
+��,����%�w���%rmime/__pycache__/image.cpython-312.opt-1.pyc000064400000013117151706203570014440 0ustar00�

T��h����dZdgZddlmZddlmZGd�de�ZgZd�Zd�Z	e	d��Z
e	d	��Ze	d
��Ze	d��Z
e	d��Ze	d
��Ze	d��Ze	d��Ze	d��Ze	d��Ze	d��Ze	d��Ze	d��Zy)z/Class representing image/* type MIME documents.�	MIMEImage�)�encoders)�MIMENonMultipartc�6�eZdZdZdej
fdd�d�Zy)rz1Class for generating image/* type MIME documents.N)�policyc��|�t|�n|}|�td��tj|d|fd|i|��|j	|�||�y)a�Create an image/* type MIME document.

        _imagedata contains the bytes for the raw image data.  If the data
        type can be detected (jpeg, png, gif, tiff, rgb, pbm, pgm, ppm,
        rast, xbm, bmp, webp, and exr attempted), then the subtype will be
        automatically included in the Content-Type header. Otherwise, you can
        specify the specific image subtype via the _subtype parameter.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        Nz"Could not guess image MIME subtype�imager)�_what�	TypeErrorr�__init__�set_payload)�self�
_imagedata�_subtype�_encoderr�_paramss      �)/usr/lib64/python3.12/email/mime/image.pyrzMIMEImage.__init__s_��*)1�(8�5��$�h�����@�A�A��!�!�$���	-�&�	-�$+�	-�����$����)�__name__�
__module__�__qualname__�__doc__r�
encode_base64r�rrrr
s��;�,0�"�0�0��<@�rc�6�tD]}||�x}s�|cSy�N)�_rules)�data�rule�ress   rr
r
2s%�����t�*��3���J��rc�0�tj|�|Sr)r�append)�rulefuncs rrr:s��
�M�M�(���Orc�&�|dddvry|dddk(ryy)z1JPEG data with JFIF or Exif markers; and raw JPEG��
)sJFIFsExif�jpegN�s���r��hs r�_jpegr+?s-��	��2�w�$�$��	
�2�A��%�	%��
&rc�(�|jd�ryy)Ns�PNG

�png��
startswithr)s r�_pngr0Hs���|�|�(�)��*rc��|dddvryy)zGIF ('87 and '89 variants)Nr%)sGIF87asGIF89a�gifrr)s r�_gifr3Ns��	��!�u�&�&��'rc��|dddvryy)z-TIFF (can be in Motorola or Intel byte order)N�)sMMsII�tiffrr)s r�_tiffr7Us��	��!�u����rc�(�|jd�ryy)zSGI image librarys��rgbNr.r)s r�_rgbr:\���	�|�|�K� ��!rc�f�t|�dk\r#|dtd�k(r|ddvr	|ddvryy	y	y	y	)
zPBM (portable bitmap)�r�P�s14r5� 	

�pbmN��len�ordr)s r�_pbmrEc�G���1�v��{�
�a�D�C��I��!�A�$�%�-�A�a�D�J�4F��5G�-��rc�f�t|�dk\r#|dtd�k(r|ddvr	|ddvryy	y	y	y	)
zPGM (portable graymap)r=rr>r?s25r5r@�pgmNrBr)s r�_pgmrIkrFrc�f�t|�dk\r#|dtd�k(r|ddvr	|ddvryy	y	y	y	)
zPPM (portable pixmap)r=rr>r?s36r5r@�ppmNrBr)s r�_ppmrLsrFrc�(�|jd�ryy)zSun raster filesY�j��rastNr.r)s r�_rastrO{s��	�|�|�'�(��)rc�(�|jd�ryy)zX bitmap (X10 or X11)s#define �xbmNr.r)s r�_xbmrR�r;rc�(�|jd�ryy)NsBM�bmpr.r)s r�_bmprU�s���|�|�E���rc�:�|jd�r
|dddk(ryyy)NsRIFF��sWEBP�webpr.r)s r�_webprZ�s&���|�|�G���1�R��G�!3��"4�rc�(�|jd�ryy)Nsv/1�exrr.r)s r�_exrr]�s���|�|�'�(��)rN)r�__all__�emailr�email.mime.nonmultipartrrrr
rr+r0r3r7r:rErIrLrOrRrUrZr]rrr�<module>ras:��
6��-���4�� ��B
����
��������
������������������������������������
����
���rmime/__pycache__/image.cpython-312.opt-2.pyc000064400000010561151706203570014441 0ustar00�

T��h����	dgZddlmZddlmZGd�de�ZgZd�Zd�Zed��Z	ed��Z
ed	��Zed
��Zed��Z
ed��Zed
��Zed��Zed��Zed��Zed��Zed��Zed��Zy)�	MIMEImage�)�encoders)�MIMENonMultipartc�4�eZdZ	dejfdd�d�Zy)rN)�policyc��	|�t|�n|}|�td��tj|d|fd|i|��|j	|�||�y)Nz"Could not guess image MIME subtype�imager)�_what�	TypeErrorr�__init__�set_payload)�self�
_imagedata�_subtype�_encoderr�_paramss      �)/usr/lib64/python3.12/email/mime/image.pyrzMIMEImage.__init__sd��	�&)1�(8�5��$�h�����@�A�A��!�!�$���	-�&�	-�$+�	-�����$����)�__name__�
__module__�__qualname__r�
encode_base64r�rrrr
s��;�,0�"�0�0��<@�rc�6�tD]}||�x}s�|cSy�N)�_rules)�data�rule�ress   rr
r
2s%�����t�*��3���J��rc�0�tj|�|Sr)r�append)�rulefuncs rrr:s��
�M�M�(���Orc�(�	|dddvry|dddk(ryy)N��
)sJFIFsExif�jpeg�s���r��hs r�_jpegr*?s.��;���2�w�$�$��	
�2�A��%�	%��
&rc�(�|jd�ryy)Ns�PNG

�png��
startswithr(s r�_pngr/Hs���|�|�(�)��*rc��	|dddvryy)Nr$)sGIF87asGIF89a�gifrr(s r�_gifr2Ns��$���!�u�&�&��'rc��	|dddvryy)N�)sMMsII�tiffrr(s r�_tiffr6Us��7���!�u����rc�*�	|jd�ryy)Ns��rgbr-r(s r�_rgbr9\s����|�|�K� ��!rc�h�	t|�dk\r#|dtd�k(r|ddvr	|ddvryyyyy)	N�r�P�s14r4� 	

�pbm��len�ordr(s r�_pbmrCc�H���
�1�v��{�
�a�D�C��I��!�A�$�%�-�A�a�D�J�4F��5G�-��rc�h�	t|�dk\r#|dtd�k(r|ddvr	|ddvryyyyy)	Nr;rr<r=s25r4r>�pgmr@r(s r�_pgmrGksH�� �
�1�v��{�
�a�D�C��I��!�A�$�%�-�A�a�D�J�4F��5G�-��rc�h�	t|�dk\r#|dtd�k(r|ddvr	|ddvryyyyy)	Nr;rr<r=s36r4r>�ppmr@r(s r�_ppmrJsrDrc�*�	|jd�ryy)NsY�j��rastr-r(s r�_rastrM{s����|�|�'�(��)rc�*�	|jd�ryy)Ns#define �xbmr-r(s r�_xbmrP�s����|�|�K� ��!rc�(�|jd�ryy)NsBM�bmpr-r(s r�_bmprS�s���|�|�E���rc�:�|jd�r
|dddk(ryyy)NsRIFF��sWEBP�webpr-r(s r�_webprX�s&���|�|�G���1�R��G�!3��"4�rc�(�|jd�ryy)Nsv/1�exrr-r(s r�_exrr[�s���|�|�'�(��)rN)�__all__�emailr�email.mime.nonmultipartrrrr
rr*r/r2r6r9rCrGrJrMrPrSrXr[rrr�<module>r_s:��
6��-���4�� ��B
����
��������
������������������������������������
����
���rmime/__pycache__/image.cpython-312.pyc000064400000013117151706203570013501 0ustar00�

T��h����dZdgZddlmZddlmZGd�de�ZgZd�Zd�Z	e	d��Z
e	d	��Ze	d
��Ze	d��Z
e	d��Ze	d
��Ze	d��Ze	d��Ze	d��Ze	d��Ze	d��Ze	d��Ze	d��Zy)z/Class representing image/* type MIME documents.�	MIMEImage�)�encoders)�MIMENonMultipartc�6�eZdZdZdej
fdd�d�Zy)rz1Class for generating image/* type MIME documents.N)�policyc��|�t|�n|}|�td��tj|d|fd|i|��|j	|�||�y)a�Create an image/* type MIME document.

        _imagedata contains the bytes for the raw image data.  If the data
        type can be detected (jpeg, png, gif, tiff, rgb, pbm, pgm, ppm,
        rast, xbm, bmp, webp, and exr attempted), then the subtype will be
        automatically included in the Content-Type header. Otherwise, you can
        specify the specific image subtype via the _subtype parameter.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        Nz"Could not guess image MIME subtype�imager)�_what�	TypeErrorr�__init__�set_payload)�self�
_imagedata�_subtype�_encoderr�_paramss      �)/usr/lib64/python3.12/email/mime/image.pyrzMIMEImage.__init__s_��*)1�(8�5��$�h�����@�A�A��!�!�$���	-�&�	-�$+�	-�����$����)�__name__�
__module__�__qualname__�__doc__r�
encode_base64r�rrrr
s��;�,0�"�0�0��<@�rc�6�tD]}||�x}s�|cSy�N)�_rules)�data�rule�ress   rr
r
2s%�����t�*��3���J��rc�0�tj|�|Sr)r�append)�rulefuncs rrr:s��
�M�M�(���Orc�&�|dddvry|dddk(ryy)z1JPEG data with JFIF or Exif markers; and raw JPEG��
)sJFIFsExif�jpegN�s���r��hs r�_jpegr+?s-��	��2�w�$�$��	
�2�A��%�	%��
&rc�(�|jd�ryy)Ns�PNG

�png��
startswithr)s r�_pngr0Hs���|�|�(�)��*rc��|dddvryy)zGIF ('87 and '89 variants)Nr%)sGIF87asGIF89a�gifrr)s r�_gifr3Ns��	��!�u�&�&��'rc��|dddvryy)z-TIFF (can be in Motorola or Intel byte order)N�)sMMsII�tiffrr)s r�_tiffr7Us��	��!�u����rc�(�|jd�ryy)zSGI image librarys��rgbNr.r)s r�_rgbr:\���	�|�|�K� ��!rc�f�t|�dk\r#|dtd�k(r|ddvr	|ddvryy	y	y	y	)
zPBM (portable bitmap)�r�P�s14r5� 	

�pbmN��len�ordr)s r�_pbmrEc�G���1�v��{�
�a�D�C��I��!�A�$�%�-�A�a�D�J�4F��5G�-��rc�f�t|�dk\r#|dtd�k(r|ddvr	|ddvryy	y	y	y	)
zPGM (portable graymap)r=rr>r?s25r5r@�pgmNrBr)s r�_pgmrIkrFrc�f�t|�dk\r#|dtd�k(r|ddvr	|ddvryy	y	y	y	)
zPPM (portable pixmap)r=rr>r?s36r5r@�ppmNrBr)s r�_ppmrLsrFrc�(�|jd�ryy)zSun raster filesY�j��rastNr.r)s r�_rastrO{s��	�|�|�'�(��)rc�(�|jd�ryy)zX bitmap (X10 or X11)s#define �xbmNr.r)s r�_xbmrR�r;rc�(�|jd�ryy)NsBM�bmpr.r)s r�_bmprU�s���|�|�E���rc�:�|jd�r
|dddk(ryyy)NsRIFF��sWEBP�webpr.r)s r�_webprZ�s&���|�|�G���1�R��G�!3��"4�rc�(�|jd�ryy)Nsv/1�exrr.r)s r�_exrr]�s���|�|�'�(��)rN)r�__all__�emailr�email.mime.nonmultipartrrrr
rr+r0r3r7r:rErIrLrOrRrUrZr]rrr�<module>ras:��
6��-���4�� ��B
����
��������
������������������������������������
����
���rmime/__pycache__/message.cpython-312.opt-1.pyc000064400000003034151706203570014777 0ustar00�

T��h#��<�dZdgZddlmZddlmZGd�de�Zy)�,Class representing message/* MIME documents.�MIMEMessage�)�message)�MIMENonMultipartc��eZdZdZddd�d�Zy)rrN��policyc���tj|d||��t|tj�std��tjj
||�|jd�y)a�Create a message/* type MIME document.

        _msg is a message object and must be an instance of Message, or a
        derived class of Message, otherwise a TypeError is raised.

        Optional _subtype defines the subtype of the contained message.  The
        default is "rfc822" (this is defined by the MIME standard, even though
        the term "rfc822" is technically outdated by RFC 2822).
        rrz&Argument is not an instance of Messagezmessage/rfc822N)r�__init__�
isinstancer�Message�	TypeError�attach�set_default_type)�self�_msg�_subtyper	s    �+/usr/lib64/python3.12/email/mime/message.pyrzMIMEMessage.__init__sW��	�!�!�$�	�8�F�K��$����0��D�E�E�	�����t�T�*����.�/�)�rfc822)�__name__�
__module__�__qualname__�__doc__r�rrrr
s��6�0�$�0rN)r�__all__�emailr�email.mime.nonmultipartrrrrr�<module>rs$��
3��/���4�0�"�0rmime/__pycache__/message.cpython-312.opt-2.pyc000064400000002077151706203570015006 0ustar00�

T��h#��:�	dgZddlmZddlmZGd�de�Zy)�MIMEMessage�)�message)�MIMENonMultipartc��eZdZ	ddd�d�Zy)rN��policyc���	tj|d||��t|tj�std��tjj
||�|jd�y)Nrrz&Argument is not an instance of Messagezmessage/rfc822)r�__init__�
isinstancer�Message�	TypeError�attach�set_default_type)�self�_msg�_subtypers    �+/usr/lib64/python3.12/email/mime/message.pyr
zMIMEMessage.__init__s\��	�	�!�!�$�	�8�F�K��$����0��D�E�E�	�����t�T�*����.�/�)�rfc822)�__name__�
__module__�__qualname__r
�rrrr
s��6�0�$�0rN)�__all__�emailr�email.mime.nonmultipartrrrrr�<module>rs$��
3��/���4�0�"�0rmime/__pycache__/message.cpython-312.pyc000064400000003034151706203570014040 0ustar00�

T��h#��<�dZdgZddlmZddlmZGd�de�Zy)�,Class representing message/* MIME documents.�MIMEMessage�)�message)�MIMENonMultipartc��eZdZdZddd�d�Zy)rrN��policyc���tj|d||��t|tj�std��tjj
||�|jd�y)a�Create a message/* type MIME document.

        _msg is a message object and must be an instance of Message, or a
        derived class of Message, otherwise a TypeError is raised.

        Optional _subtype defines the subtype of the contained message.  The
        default is "rfc822" (this is defined by the MIME standard, even though
        the term "rfc822" is technically outdated by RFC 2822).
        rrz&Argument is not an instance of Messagezmessage/rfc822N)r�__init__�
isinstancer�Message�	TypeError�attach�set_default_type)�self�_msg�_subtyper	s    �+/usr/lib64/python3.12/email/mime/message.pyrzMIMEMessage.__init__sW��	�!�!�$�	�8�F�K��$����0��D�E�E�	�����t�T�*����.�/�)�rfc822)�__name__�
__module__�__qualname__�__doc__r�rrrr
s��6�0�$�0rN)r�__all__�emailr�email.mime.nonmultipartrrrrr�<module>rs$��
3��/���4�0�"�0rmime/__pycache__/multipart.cpython-312.opt-1.pyc000064400000003253151706203570015377 0ustar00�

T��hS��0�dZdgZddlmZGd�de�Zy)�.Base class for MIME multipart/* type messages.�
MIMEMultipart�)�MIMEBasec��eZdZdZddd�d�Zy)rrN)�policyc��tj|d|fd|i|��g|_|r|D]}|j|��|r|j	|�yy)a�Creates a multipart/* type message.

        By default, creates a multipart/mixed message, with proper
        Content-Type and MIME-Version headers.

        _subtype is the subtype of the multipart content type, defaulting to
        `mixed'.

        boundary is the multipart boundary string.  By default it is
        calculated as needed.

        _subparts is a sequence of initial subparts for the payload.  It
        must be an iterable object, such as a list.  You can always
        attach new subparts to the message by using the attach() method.

        Additional parameters for the Content-Type header are taken from the
        keyword arguments (or passed into the _params argument).
        �	multipartrN)r�__init__�_payload�attach�set_boundary)�self�_subtype�boundary�	_subpartsr�_params�ps       �-/usr/lib64/python3.12/email/mime/multipart.pyr
zMIMEMultipart.__init__sW��*	���$��X�P�f�P��P�
��
�������A�������h�'��)�mixedNN)�__name__�
__module__�__qualname__�__doc__r
�rrrrs��8� (�� (rN)r�__all__�email.mime.baserrrrr�<module>rs!��
5��
��$�#(�H�#(rmime/__pycache__/multipart.cpython-312.opt-2.pyc000064400000001636151706203570015403 0ustar00�

T��hS��.�	dgZddlmZGd�de�Zy)�
MIMEMultipart�)�MIMEBasec��eZdZ	ddd�d�Zy)rN)�policyc��	tj|d|fd|i|��g|_|r|D]}|j|��|r|j	|�yy)N�	multipartr)r�__init__�_payload�attach�set_boundary)�self�_subtype�boundary�	_subpartsr�_params�ps       �-/usr/lib64/python3.12/email/mime/multipart.pyr	zMIMEMultipart.__init__s\��	�$	���$��X�P�f�P��P�
��
�������A�������h�'��)�mixedNN)�__name__�
__module__�__qualname__r	�rrrrs��8� (�� (rN)�__all__�email.mime.baserrrrr�<module>rs!��
5��
��$�#(�H�#(rmime/__pycache__/multipart.cpython-312.pyc000064400000003253151706203570014440 0ustar00�

T��hS��0�dZdgZddlmZGd�de�Zy)�.Base class for MIME multipart/* type messages.�
MIMEMultipart�)�MIMEBasec��eZdZdZddd�d�Zy)rrN)�policyc��tj|d|fd|i|��g|_|r|D]}|j|��|r|j	|�yy)a�Creates a multipart/* type message.

        By default, creates a multipart/mixed message, with proper
        Content-Type and MIME-Version headers.

        _subtype is the subtype of the multipart content type, defaulting to
        `mixed'.

        boundary is the multipart boundary string.  By default it is
        calculated as needed.

        _subparts is a sequence of initial subparts for the payload.  It
        must be an iterable object, such as a list.  You can always
        attach new subparts to the message by using the attach() method.

        Additional parameters for the Content-Type header are taken from the
        keyword arguments (or passed into the _params argument).
        �	multipartrN)r�__init__�_payload�attach�set_boundary)�self�_subtype�boundary�	_subpartsr�_params�ps       �-/usr/lib64/python3.12/email/mime/multipart.pyr
zMIMEMultipart.__init__sW��*	���$��X�P�f�P��P�
��
�������A�������h�'��)�mixedNN)�__name__�
__module__�__qualname__�__doc__r
�rrrrs��8� (�� (rN)r�__all__�email.mime.baserrrrr�<module>rs!��
5��
��$�#(�H�#(rmime/__pycache__/nonmultipart.cpython-312.opt-1.pyc000064400000001535151706203570016113 0ustar00�

T��h���<�dZdgZddlmZddlmZGd�de�Zy)z9Base class for MIME type messages that are not multipart.�MIMENonMultipart�)�errors)�MIMEBasec��eZdZdZd�Zy)rz0Base class for MIME non-multipart type messages.c�,�tjd��)Nz4Cannot attach additional subparts to non-multipart/*)r�MultipartConversionError)�self�payloads  �0/usr/lib64/python3.12/email/mime/nonmultipart.py�attachzMIMENonMultipart.attachs���-�-�B�D�	D�N)�__name__�
__module__�__qualname__�__doc__r�r
rrr
s��:�Dr
N)r�__all__�emailr�email.mime.baserrrr
r�<module>rs'��
@��
���$�D�x�Dr
mime/__pycache__/nonmultipart.cpython-312.opt-2.pyc000064400000001336151706203570016113 0ustar00�

T��h���:�	dgZddlmZddlmZGd�de�Zy)�MIMENonMultipart�)�errors)�MIMEBasec��eZdZ	d�Zy)rc�,�tjd��)Nz4Cannot attach additional subparts to non-multipart/*)r�MultipartConversionError)�self�payloads  �0/usr/lib64/python3.12/email/mime/nonmultipart.py�attachzMIMENonMultipart.attachs���-�-�B�D�	D�N)�__name__�
__module__�__qualname__r�r
rrr
s��:�Dr
N)�__all__�emailr�email.mime.baserrrr
r�<module>rs'��
@��
���$�D�x�Dr
mime/__pycache__/nonmultipart.cpython-312.pyc000064400000001535151706203570015154 0ustar00�

T��h���<�dZdgZddlmZddlmZGd�de�Zy)z9Base class for MIME type messages that are not multipart.�MIMENonMultipart�)�errors)�MIMEBasec��eZdZdZd�Zy)rz0Base class for MIME non-multipart type messages.c�,�tjd��)Nz4Cannot attach additional subparts to non-multipart/*)r�MultipartConversionError)�self�payloads  �0/usr/lib64/python3.12/email/mime/nonmultipart.py�attachzMIMENonMultipart.attachs���-�-�B�D�	D�N)�__name__�
__module__�__qualname__�__doc__r�r
rrr
s��:�Dr
N)r�__all__�emailr�email.mime.baserrrr
r�<module>rs'��
@��
���$�D�x�Dr
mime/__pycache__/text.cpython-312.opt-1.pyc000064400000002733151706203570014344 0ustar00�

T��hr��0�dZdgZddlmZGd�de�Zy)z.Class representing text/* type MIME documents.�MIMEText�)�MIMENonMultipartc��eZdZdZddd�d�Zy)rz0Class for generating text/* type MIME documents.N)�policyc	��|�	|jd�d}tj|d||t	|���|j||�y#t$rd}Y�CwxYw)a~Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.
        Nzus-asciizutf-8�text)r�charset)�encode�UnicodeEncodeErrorr�__init__�str�set_payload)�self�_text�_subtype�_charsetrs     �(/usr/lib64/python3.12/email/mime/text.pyrzMIMEText.__init__sg����
#����Z�(�%��	�!�!�$����*-�h�-�	9�	
�����)��
&�
#�"��
#�s�A
�
A�A)�plainN)�__name__�
__module__�__qualname__�__doc__r��rrrs��:�*��*rN)r�__all__�email.mime.nonmultipartrrrrr�<module>rs!��
5��,��4�*��*rmime/__pycache__/text.cpython-312.opt-2.pyc000064400000001753151706203570014346 0ustar00�

T��hr��.�	dgZddlmZGd�de�Zy)�MIMEText�)�MIMENonMultipartc��eZdZ	ddd�d�Zy)rN)�policyc	��	|�	|jd�d}tj|d||t	|���|j||�y#t$rd}Y�CwxYw)Nzus-asciizutf-8�text)r�charset)�encode�UnicodeEncodeErrorr�__init__�str�set_payload)�self�_text�_subtype�_charsetrs     �(/usr/lib64/python3.12/email/mime/text.pyrzMIMEText.__init__sl��		���
#����Z�(�%��	�!�!�$����*-�h�-�	9�	
�����)��
&�
#�"��
#�s�A�A�A)�plainN)�__name__�
__module__�__qualname__r��rrrs��:�*��*rN)�__all__�email.mime.nonmultipartrrrrr�<module>rs!��
5��,��4�*��*rmime/__init__.py000064400000000000151706203570007600 0ustar00mime/application.py000064400000002451151706203570010360 0ustar00# Copyright (C) 2001-2006 Python Software Foundation
# Author: Keith Dart
# Contact: email-sig@python.org

"""Class representing application/* type MIME documents."""

__all__ = ["MIMEApplication"]

from email import encoders
from email.mime.nonmultipart import MIMENonMultipart


class MIMEApplication(MIMENonMultipart):
    """Class for generating application/* MIME documents."""

    def __init__(self, _data, _subtype='octet-stream',
                 _encoder=encoders.encode_base64, *, policy=None, **_params):
        """Create an application/* type MIME document.

        _data contains the bytes for the raw application data.

        _subtype is the MIME content type subtype, defaulting to
        'octet-stream'.

        _encoder is a function which will perform the actual encoding for
        transport of the application data, defaulting to base64 encoding.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            raise TypeError('Invalid application MIME subtype')
        MIMENonMultipart.__init__(self, 'application', _subtype, policy=policy,
                                  **_params)
        self.set_payload(_data)
        _encoder(self)
mime/audio.py000064400000006026151706203570007160 0ustar00# Copyright (C) 2001-2007 Python Software Foundation
# Author: Anthony Baxter
# Contact: email-sig@python.org

"""Class representing audio/* type MIME documents."""

__all__ = ['MIMEAudio']

from io import BytesIO
from email import encoders
from email.mime.nonmultipart import MIMENonMultipart


class MIMEAudio(MIMENonMultipart):
    """Class for generating audio/* MIME documents."""

    def __init__(self, _audiodata, _subtype=None,
                 _encoder=encoders.encode_base64, *, policy=None, **_params):
        """Create an audio/* type MIME document.

        _audiodata contains the bytes for the raw audio data.  If this data
        can be decoded as au, wav, aiff, or aifc, then the
        subtype will be automatically included in the Content-Type header.
        Otherwise, you can specify  the specific audio subtype via the
        _subtype parameter.  If _subtype is not given, and no subtype can be
        guessed, a TypeError is raised.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            _subtype = _what(_audiodata)
        if _subtype is None:
            raise TypeError('Could not find audio MIME subtype')
        MIMENonMultipart.__init__(self, 'audio', _subtype, policy=policy,
                                  **_params)
        self.set_payload(_audiodata)
        _encoder(self)


_rules = []


# Originally from the sndhdr module.
#
# There are others in sndhdr that don't have MIME types. :(
# Additional ones to be added to sndhdr? midi, mp3, realaudio, wma??
def _what(data):
    # Try to identify a sound file type.
    #
    # sndhdr.what() had a pretty cruddy interface, unfortunately.  This is why
    # we re-do it here.  It would be easier to reverse engineer the Unix 'file'
    # command and use the standard 'magic' file, as shipped with a modern Unix.
    hdr = data[:512]
    fakefile = BytesIO(hdr)
    for testfn in _rules:
        if res := testfn(hdr, fakefile):
            return res
    else:
        return None


def rule(rulefunc):
    _rules.append(rulefunc)
    return rulefunc


@rule
def _aiff(h, f):
    if not h.startswith(b'FORM'):
        return None
    if h[8:12] in {b'AIFC', b'AIFF'}:
        return 'x-aiff'
    else:
        return None


@rule
def _au(h, f):
    if h.startswith(b'.snd'):
        return 'basic'
    else:
        return None


@rule
def _wav(h, f):
    # 'RIFF' <len> 'WAVE' 'fmt ' <len>
    if not h.startswith(b'RIFF') or h[8:12] != b'WAVE' or h[12:16] != b'fmt ':
        return None
    else:
        return "x-wav"
mime/base.py000064400000001622151706203570006766 0ustar00# Copyright (C) 2001-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Base class for MIME specializations."""

__all__ = ['MIMEBase']

import email.policy

from email import message


class MIMEBase(message.Message):
    """Base class for MIME specializations."""

    def __init__(self, _maintype, _subtype, *, policy=None, **_params):
        """This constructor adds a Content-Type: and a MIME-Version: header.

        The Content-Type: header is taken from the _maintype and _subtype
        arguments.  Additional parameters for this header are taken from the
        keyword arguments.
        """
        if policy is None:
            policy = email.policy.compat32
        message.Message.__init__(self, policy=policy)
        ctype = '%s/%s' % (_maintype, _subtype)
        self.add_header('Content-Type', ctype, **_params)
        self['MIME-Version'] = '1.0'
mime/image.py000064400000007216151706203570007143 0ustar00# Copyright (C) 2001-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Class representing image/* type MIME documents."""

__all__ = ['MIMEImage']

from email import encoders
from email.mime.nonmultipart import MIMENonMultipart


class MIMEImage(MIMENonMultipart):
    """Class for generating image/* type MIME documents."""

    def __init__(self, _imagedata, _subtype=None,
                 _encoder=encoders.encode_base64, *, policy=None, **_params):
        """Create an image/* type MIME document.

        _imagedata contains the bytes for the raw image data.  If the data
        type can be detected (jpeg, png, gif, tiff, rgb, pbm, pgm, ppm,
        rast, xbm, bmp, webp, and exr attempted), then the subtype will be
        automatically included in the Content-Type header. Otherwise, you can
        specify the specific image subtype via the _subtype parameter.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        _subtype = _what(_imagedata) if _subtype is None else _subtype
        if _subtype is None:
            raise TypeError('Could not guess image MIME subtype')
        MIMENonMultipart.__init__(self, 'image', _subtype, policy=policy,
                                  **_params)
        self.set_payload(_imagedata)
        _encoder(self)


_rules = []


# Originally from the imghdr module.
def _what(data):
    for rule in _rules:
        if res := rule(data):
            return res
    else:
        return None


def rule(rulefunc):
    _rules.append(rulefunc)
    return rulefunc


@rule
def _jpeg(h):
    """JPEG data with JFIF or Exif markers; and raw JPEG"""
    if h[6:10] in (b'JFIF', b'Exif'):
        return 'jpeg'
    elif h[:4] == b'\xff\xd8\xff\xdb':
        return 'jpeg'


@rule
def _png(h):
    if h.startswith(b'\211PNG\r\n\032\n'):
        return 'png'


@rule
def _gif(h):
    """GIF ('87 and '89 variants)"""
    if h[:6] in (b'GIF87a', b'GIF89a'):
        return 'gif'


@rule
def _tiff(h):
    """TIFF (can be in Motorola or Intel byte order)"""
    if h[:2] in (b'MM', b'II'):
        return 'tiff'


@rule
def _rgb(h):
    """SGI image library"""
    if h.startswith(b'\001\332'):
        return 'rgb'


@rule
def _pbm(h):
    """PBM (portable bitmap)"""
    if len(h) >= 3 and \
            h[0] == ord(b'P') and h[1] in b'14' and h[2] in b' \t\n\r':
        return 'pbm'


@rule
def _pgm(h):
    """PGM (portable graymap)"""
    if len(h) >= 3 and \
            h[0] == ord(b'P') and h[1] in b'25' and h[2] in b' \t\n\r':
        return 'pgm'


@rule
def _ppm(h):
    """PPM (portable pixmap)"""
    if len(h) >= 3 and \
            h[0] == ord(b'P') and h[1] in b'36' and h[2] in b' \t\n\r':
        return 'ppm'


@rule
def _rast(h):
    """Sun raster file"""
    if h.startswith(b'\x59\xA6\x6A\x95'):
        return 'rast'


@rule
def _xbm(h):
    """X bitmap (X10 or X11)"""
    if h.startswith(b'#define '):
        return 'xbm'


@rule
def _bmp(h):
    if h.startswith(b'BM'):
        return 'bmp'


@rule
def _webp(h):
    if h.startswith(b'RIFF') and h[8:12] == b'WEBP':
        return 'webp'


@rule
def _exr(h):
    if h.startswith(b'\x76\x2f\x31\x01'):
        return 'exr'
mime/message.py000064400000002443151706203570007502 0ustar00# Copyright (C) 2001-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Class representing message/* MIME documents."""

__all__ = ['MIMEMessage']

from email import message
from email.mime.nonmultipart import MIMENonMultipart


class MIMEMessage(MIMENonMultipart):
    """Class representing message/* MIME documents."""

    def __init__(self, _msg, _subtype='rfc822', *, policy=None):
        """Create a message/* type MIME document.

        _msg is a message object and must be an instance of Message, or a
        derived class of Message, otherwise a TypeError is raised.

        Optional _subtype defines the subtype of the contained message.  The
        default is "rfc822" (this is defined by the MIME standard, even though
        the term "rfc822" is technically outdated by RFC 2822).
        """
        MIMENonMultipart.__init__(self, 'message', _subtype, policy=policy)
        if not isinstance(_msg, message.Message):
            raise TypeError('Argument is not an instance of Message')
        # It's convenient to use this base class method.  We need to do it
        # this way or we'll get an exception
        message.Message.attach(self, _msg)
        # And be sure our default type is set correctly
        self.set_default_type('message/rfc822')
mime/multipart.py000064400000003123151706203570010073 0ustar00# Copyright (C) 2002-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Base class for MIME multipart/* type messages."""

__all__ = ['MIMEMultipart']

from email.mime.base import MIMEBase


class MIMEMultipart(MIMEBase):
    """Base class for MIME multipart/* type messages."""

    def __init__(self, _subtype='mixed', boundary=None, _subparts=None,
                 *, policy=None,
                 **_params):
        """Creates a multipart/* type message.

        By default, creates a multipart/mixed message, with proper
        Content-Type and MIME-Version headers.

        _subtype is the subtype of the multipart content type, defaulting to
        `mixed'.

        boundary is the multipart boundary string.  By default it is
        calculated as needed.

        _subparts is a sequence of initial subparts for the payload.  It
        must be an iterable object, such as a list.  You can always
        attach new subparts to the message by using the attach() method.

        Additional parameters for the Content-Type header are taken from the
        keyword arguments (or passed into the _params argument).
        """
        MIMEBase.__init__(self, 'multipart', _subtype, policy=policy, **_params)

        # Initialise _payload to an empty list as the Message superclass's
        # implementation of is_multipart assumes that _payload is a list for
        # multipart messages.
        self._payload = []

        if _subparts:
            for p in _subparts:
                self.attach(p)
        if boundary:
            self.set_boundary(boundary)
mime/nonmultipart.py000064400000001261151706203570010607 0ustar00# Copyright (C) 2002-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Base class for MIME type messages that are not multipart."""

__all__ = ['MIMENonMultipart']

from email import errors
from email.mime.base import MIMEBase


class MIMENonMultipart(MIMEBase):
    """Base class for MIME non-multipart type messages."""

    def attach(self, payload):
        # The public API prohibits attaching multiple subparts to MIMEBase
        # derived subtypes since none of them are, by definition, of content
        # type multipart/*
        raise errors.MultipartConversionError(
            'Cannot attach additional subparts to non-multipart/*')
mime/text.py000064400000002562151706203570007044 0ustar00# Copyright (C) 2001-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Class representing text/* type MIME documents."""

__all__ = ['MIMEText']

from email.mime.nonmultipart import MIMENonMultipart


class MIMEText(MIMENonMultipart):
    """Class for generating text/* type MIME documents."""

    def __init__(self, _text, _subtype='plain', _charset=None, *, policy=None):
        """Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.
        """

        # If no _charset was specified, check to see if there are non-ascii
        # characters present. If not, use 'us-ascii', otherwise use utf-8.
        # XXX: This can be removed once #7304 is fixed.
        if _charset is None:
            try:
                _text.encode('us-ascii')
                _charset = 'us-ascii'
            except UnicodeEncodeError:
                _charset = 'utf-8'

        MIMENonMultipart.__init__(self, 'text', _subtype, policy=policy,
                                  charset=str(_charset))

        self.set_payload(_text, _charset)
__init__.py000064400000003344151706203570006667 0ustar00# Copyright (C) 2001-2007 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""A package for parsing, handling, and generating email messages."""

__all__ = [
    'base64mime',
    'charset',
    'encoders',
    'errors',
    'feedparser',
    'generator',
    'header',
    'iterators',
    'message',
    'message_from_file',
    'message_from_binary_file',
    'message_from_string',
    'message_from_bytes',
    'mime',
    'parser',
    'quoprimime',
    'utils',
    ]


# Some convenience routines.  Don't import Parser and Message as side-effects
# of importing email since those cascadingly import most of the rest of the
# email package.
def message_from_string(s, *args, **kws):
    """Parse a string into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    """
    from email.parser import Parser
    return Parser(*args, **kws).parsestr(s)

def message_from_bytes(s, *args, **kws):
    """Parse a bytes string into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    """
    from email.parser import BytesParser
    return BytesParser(*args, **kws).parsebytes(s)

def message_from_file(fp, *args, **kws):
    """Read a file and parse its contents into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    """
    from email.parser import Parser
    return Parser(*args, **kws).parse(fp)

def message_from_binary_file(fp, *args, **kws):
    """Read a binary file and parse its contents into a Message object model.

    Optional _class and strict are passed to the Parser constructor.
    """
    from email.parser import BytesParser
    return BytesParser(*args, **kws).parse(fp)
_encoded_words.py000064400000020535151706203570010107 0ustar00""" Routines for manipulating RFC2047 encoded words.

This is currently a package-private API, but will be considered for promotion
to a public API if there is demand.

"""

# An ecoded word looks like this:
#
#        =?charset[*lang]?cte?encoded_string?=
#
# for more information about charset see the charset module.  Here it is one
# of the preferred MIME charset names (hopefully; you never know when parsing).
# cte (Content Transfer Encoding) is either 'q' or 'b' (ignoring case).  In
# theory other letters could be used for other encodings, but in practice this
# (almost?) never happens.  There could be a public API for adding entries
# to the CTE tables, but YAGNI for now.  'q' is Quoted Printable, 'b' is
# Base64.  The meaning of encoded_string should be obvious.  'lang' is optional
# as indicated by the brackets (they are not part of the syntax) but is almost
# never encountered in practice.
#
# The general interface for a CTE decoder is that it takes the encoded_string
# as its argument, and returns a tuple (cte_decoded_string, defects).  The
# cte_decoded_string is the original binary that was encoded using the
# specified cte.  'defects' is a list of MessageDefect instances indicating any
# problems encountered during conversion.  'charset' and 'lang' are the
# corresponding strings extracted from the EW, case preserved.
#
# The general interface for a CTE encoder is that it takes a binary sequence
# as input and returns the cte_encoded_string, which is an ascii-only string.
#
# Each decoder must also supply a length function that takes the binary
# sequence as its argument and returns the length of the resulting encoded
# string.
#
# The main API functions for the module are decode, which calls the decoder
# referenced by the cte specifier, and encode, which adds the appropriate
# RFC 2047 "chrome" to the encoded string, and can optionally automatically
# select the shortest possible encoding.  See their docstrings below for
# details.

import re
import base64
import binascii
import functools
from string import ascii_letters, digits
from email import errors

__all__ = ['decode_q',
           'encode_q',
           'decode_b',
           'encode_b',
           'len_q',
           'len_b',
           'decode',
           'encode',
           ]

#
# Quoted Printable
#

# regex based decoder.
_q_byte_subber = functools.partial(re.compile(br'=([a-fA-F0-9]{2})').sub,
        lambda m: bytes.fromhex(m.group(1).decode()))

def decode_q(encoded):
    encoded = encoded.replace(b'_', b' ')
    return _q_byte_subber(encoded), []


# dict mapping bytes to their encoded form
class _QByteMap(dict):

    safe = b'-!*+/' + ascii_letters.encode('ascii') + digits.encode('ascii')

    def __missing__(self, key):
        if key in self.safe:
            self[key] = chr(key)
        else:
            self[key] = "={:02X}".format(key)
        return self[key]

_q_byte_map = _QByteMap()

# In headers spaces are mapped to '_'.
_q_byte_map[ord(' ')] = '_'

def encode_q(bstring):
    return ''.join(_q_byte_map[x] for x in bstring)

def len_q(bstring):
    return sum(len(_q_byte_map[x]) for x in bstring)


#
# Base64
#

def decode_b(encoded):
    # First try encoding with validate=True, fixing the padding if needed.
    # This will succeed only if encoded includes no invalid characters.
    pad_err = len(encoded) % 4
    missing_padding = b'==='[:4-pad_err] if pad_err else b''
    try:
        return (
            base64.b64decode(encoded + missing_padding, validate=True),
            [errors.InvalidBase64PaddingDefect()] if pad_err else [],
        )
    except binascii.Error:
        # Since we had correct padding, this is likely an invalid char error.
        #
        # The non-alphabet characters are ignored as far as padding
        # goes, but we don't know how many there are.  So try without adding
        # padding to see if it works.
        try:
            return (
                base64.b64decode(encoded, validate=False),
                [errors.InvalidBase64CharactersDefect()],
            )
        except binascii.Error:
            # Add as much padding as could possibly be necessary (extra padding
            # is ignored).
            try:
                return (
                    base64.b64decode(encoded + b'==', validate=False),
                    [errors.InvalidBase64CharactersDefect(),
                     errors.InvalidBase64PaddingDefect()],
                )
            except binascii.Error:
                # This only happens when the encoded string's length is 1 more
                # than a multiple of 4, which is invalid.
                #
                # bpo-27397: Just return the encoded string since there's no
                # way to decode.
                return encoded, [errors.InvalidBase64LengthDefect()]

def encode_b(bstring):
    return base64.b64encode(bstring).decode('ascii')

def len_b(bstring):
    groups_of_3, leftover = divmod(len(bstring), 3)
    # 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
    return groups_of_3 * 4 + (4 if leftover else 0)


_cte_decoders = {
    'q': decode_q,
    'b': decode_b,
    }

def decode(ew):
    """Decode encoded word and return (string, charset, lang, defects) tuple.

    An RFC 2047/2243 encoded word has the form:

        =?charset*lang?cte?encoded_string?=

    where '*lang' may be omitted but the other parts may not be.

    This function expects exactly such a string (that is, it does not check the
    syntax and may raise errors if the string is not well formed), and returns
    the encoded_string decoded first from its Content Transfer Encoding and
    then from the resulting bytes into unicode using the specified charset.  If
    the cte-decoded string does not successfully decode using the specified
    character set, a defect is added to the defects list and the unknown octets
    are replaced by the unicode 'unknown' character \\uFDFF.

    The specified charset and language are returned.  The default for language,
    which is rarely if ever encountered, is the empty string.

    """
    _, charset, cte, cte_string, _ = ew.split('?')
    charset, _, lang = charset.partition('*')
    cte = cte.lower()
    # Recover the original bytes and do CTE decoding.
    bstring = cte_string.encode('ascii', 'surrogateescape')
    bstring, defects = _cte_decoders[cte](bstring)
    # Turn the CTE decoded bytes into unicode.
    try:
        string = bstring.decode(charset)
    except UnicodeDecodeError:
        defects.append(errors.UndecodableBytesDefect("Encoded word "
            f"contains bytes not decodable using {charset!r} charset"))
        string = bstring.decode(charset, 'surrogateescape')
    except (LookupError, UnicodeEncodeError):
        string = bstring.decode('ascii', 'surrogateescape')
        if charset.lower() != 'unknown-8bit':
            defects.append(errors.CharsetError(f"Unknown charset {charset!r} "
                f"in encoded word; decoded as unknown bytes"))
    return string, charset, lang, defects


_cte_encoders = {
    'q': encode_q,
    'b': encode_b,
    }

_cte_encode_length = {
    'q': len_q,
    'b': len_b,
    }

def encode(string, charset='utf-8', encoding=None, lang=''):
    """Encode string using the CTE encoding that produces the shorter result.

    Produces an RFC 2047/2243 encoded word of the form:

        =?charset*lang?cte?encoded_string?=

    where '*lang' is omitted unless the 'lang' parameter is given a value.
    Optional argument charset (defaults to utf-8) specifies the charset to use
    to encode the string to binary before CTE encoding it.  Optional argument
    'encoding' is the cte specifier for the encoding that should be used ('q'
    or 'b'); if it is None (the default) the encoding which produces the
    shortest encoded sequence is used, except that 'q' is preferred if it is up
    to five characters longer.  Optional argument 'lang' (default '') gives the
    RFC 2243 language string to specify in the encoded word.

    """
    if charset == 'unknown-8bit':
        bstring = string.encode('ascii', 'surrogateescape')
    else:
        bstring = string.encode(charset)
    if encoding is None:
        qlen = _cte_encode_length['q'](bstring)
        blen = _cte_encode_length['b'](bstring)
        # Bias toward q.  5 is arbitrary.
        encoding = 'q' if qlen - blen < 5 else 'b'
    encoded = _cte_encoders[encoding](bstring)
    if lang:
        lang = '*' + lang
    return "=?{}{}?{}?{}?=".format(charset, lang, encoding, encoded)
_header_value_parser.py000064400000331020151706203570011262 0ustar00"""Header value parser implementing various email-related RFC parsing rules.

The parsing methods defined in this module implement various email related
parsing rules.  Principal among them is RFC 5322, which is the followon
to RFC 2822 and primarily a clarification of the former.  It also implements
RFC 2047 encoded word decoding.

RFC 5322 goes to considerable trouble to maintain backward compatibility with
RFC 822 in the parse phase, while cleaning up the structure on the generation
phase.  This parser supports correct RFC 5322 generation by tagging white space
as folding white space only when folding is allowed in the non-obsolete rule
sets.  Actually, the parser is even more generous when accepting input than RFC
5322 mandates, following the spirit of Postel's Law, which RFC 5322 encourages.
Where possible deviations from the standard are annotated on the 'defects'
attribute of tokens that deviate.

The general structure of the parser follows RFC 5322, and uses its terminology
where there is a direct correspondence.  Where the implementation requires a
somewhat different structure than that used by the formal grammar, new terms
that mimic the closest existing terms are used.  Thus, it really helps to have
a copy of RFC 5322 handy when studying this code.

Input to the parser is a string that has already been unfolded according to
RFC 5322 rules.  According to the RFC this unfolding is the very first step, and
this parser leaves the unfolding step to a higher level message parser, which
will have already detected the line breaks that need unfolding while
determining the beginning and end of each header.

The output of the parser is a TokenList object, which is a list subclass.  A
TokenList is a recursive data structure.  The terminal nodes of the structure
are Terminal objects, which are subclasses of str.  These do not correspond
directly to terminal objects in the formal grammar, but are instead more
practical higher level combinations of true terminals.

All TokenList and Terminal objects have a 'value' attribute, which produces the
semantically meaningful value of that part of the parse subtree.  The value of
all whitespace tokens (no matter how many sub-tokens they may contain) is a
single space, as per the RFC rules.  This includes 'CFWS', which is herein
included in the general class of whitespace tokens.  There is one exception to
the rule that whitespace tokens are collapsed into single spaces in values: in
the value of a 'bare-quoted-string' (a quoted-string with no leading or
trailing whitespace), any whitespace that appeared between the quotation marks
is preserved in the returned value.  Note that in all Terminal strings quoted
pairs are turned into their unquoted values.

All TokenList and Terminal objects also have a string value, which attempts to
be a "canonical" representation of the RFC-compliant form of the substring that
produced the parsed subtree, including minimal use of quoted pair quoting.
Whitespace runs are not collapsed.

Comment tokens also have a 'content' attribute providing the string found
between the parens (including any nested comments) with whitespace preserved.

All TokenList and Terminal objects have a 'defects' attribute which is a
possibly empty list all of the defects found while creating the token.  Defects
may appear on any token in the tree, and a composite list of all defects in the
subtree is available through the 'all_defects' attribute of any node.  (For
Terminal notes x.defects == x.all_defects.)

Each object in a parse tree is called a 'token', and each has a 'token_type'
attribute that gives the name from the RFC 5322 grammar that it represents.
Not all RFC 5322 nodes are produced, and there is one non-RFC 5322 node that
may be produced: 'ptext'.  A 'ptext' is a string of printable ascii characters.
It is returned in place of lists of (ctext/quoted-pair) and
(qtext/quoted-pair).

XXX: provide complete list of token types.
"""

import re
import sys
import urllib   # For urllib.parse.unquote
from string import hexdigits
from operator import itemgetter
from email import _encoded_words as _ew
from email import errors
from email import utils

#
# Useful constants and functions
#

WSP = set(' \t')
CFWS_LEADER = WSP | set('(')
SPECIALS = set(r'()<>@,:;.\"[]')
ATOM_ENDS = SPECIALS | WSP
DOT_ATOM_ENDS = ATOM_ENDS - set('.')
# '.', '"', and '(' do not end phrases in order to support obs-phrase
PHRASE_ENDS = SPECIALS - set('."(')
TSPECIALS = (SPECIALS | set('/?=')) - set('.')
TOKEN_ENDS = TSPECIALS | WSP
ASPECIALS = TSPECIALS | set("*'%")
ATTRIBUTE_ENDS = ASPECIALS | WSP
EXTENDED_ATTRIBUTE_ENDS = ATTRIBUTE_ENDS - set('%')
NLSET = {'\n', '\r'}
SPECIALSNL = SPECIALS | NLSET


def make_quoted_pairs(value):
    """Escape dquote and backslash for use within a quoted-string."""
    return str(value).replace('\\', '\\\\').replace('"', '\\"')


def quote_string(value):
    escaped = make_quoted_pairs(value)
    return f'"{escaped}"'


# Match a RFC 2047 word, looks like =?utf-8?q?someword?=
rfc2047_matcher = re.compile(r'''
   =\?            # literal =?
   [^?]*          # charset
   \?             # literal ?
   [qQbB]         # literal 'q' or 'b', case insensitive
   \?             # literal ?
  .*?             # encoded word
  \?=             # literal ?=
''', re.VERBOSE | re.MULTILINE)


#
# TokenList and its subclasses
#

class TokenList(list):

    token_type = None
    syntactic_break = True
    ew_combine_allowed = True

    def __init__(self, *args, **kw):
        super().__init__(*args, **kw)
        self.defects = []

    def __str__(self):
        return ''.join(str(x) for x in self)

    def __repr__(self):
        return '{}({})'.format(self.__class__.__name__,
                             super().__repr__())

    @property
    def value(self):
        return ''.join(x.value for x in self if x.value)

    @property
    def all_defects(self):
        return sum((x.all_defects for x in self), self.defects)

    def startswith_fws(self):
        return self[0].startswith_fws()

    @property
    def as_ew_allowed(self):
        """True if all top level tokens of this part may be RFC2047 encoded."""
        return all(part.as_ew_allowed for part in self)

    @property
    def comments(self):
        comments = []
        for token in self:
            comments.extend(token.comments)
        return comments

    def fold(self, *, policy):
        return _refold_parse_tree(self, policy=policy)

    def pprint(self, indent=''):
        print(self.ppstr(indent=indent))

    def ppstr(self, indent=''):
        return '\n'.join(self._pp(indent=indent))

    def _pp(self, indent=''):
        yield '{}{}/{}('.format(
            indent,
            self.__class__.__name__,
            self.token_type)
        for token in self:
            if not hasattr(token, '_pp'):
                yield (indent + '    !! invalid element in token '
                                        'list: {!r}'.format(token))
            else:
                yield from token._pp(indent+'    ')
        if self.defects:
            extra = ' Defects: {}'.format(self.defects)
        else:
            extra = ''
        yield '{}){}'.format(indent, extra)


class WhiteSpaceTokenList(TokenList):

    @property
    def value(self):
        return ' '

    @property
    def comments(self):
        return [x.content for x in self if x.token_type=='comment']


class UnstructuredTokenList(TokenList):
    token_type = 'unstructured'


class Phrase(TokenList):
    token_type = 'phrase'

class Word(TokenList):
    token_type = 'word'


class CFWSList(WhiteSpaceTokenList):
    token_type = 'cfws'


class Atom(TokenList):
    token_type = 'atom'


class Token(TokenList):
    token_type = 'token'
    encode_as_ew = False


class EncodedWord(TokenList):
    token_type = 'encoded-word'
    cte = None
    charset = None
    lang = None


class QuotedString(TokenList):

    token_type = 'quoted-string'

    @property
    def content(self):
        for x in self:
            if x.token_type == 'bare-quoted-string':
                return x.value

    @property
    def quoted_value(self):
        res = []
        for x in self:
            if x.token_type == 'bare-quoted-string':
                res.append(str(x))
            else:
                res.append(x.value)
        return ''.join(res)

    @property
    def stripped_value(self):
        for token in self:
            if token.token_type == 'bare-quoted-string':
                return token.value


class BareQuotedString(QuotedString):

    token_type = 'bare-quoted-string'

    def __str__(self):
        return quote_string(''.join(str(x) for x in self))

    @property
    def value(self):
        return ''.join(str(x) for x in self)


class Comment(WhiteSpaceTokenList):

    token_type = 'comment'

    def __str__(self):
        return ''.join(sum([
                            ["("],
                            [self.quote(x) for x in self],
                            [")"],
                            ], []))

    def quote(self, value):
        if value.token_type == 'comment':
            return str(value)
        return str(value).replace('\\', '\\\\').replace(
                                  '(', r'\(').replace(
                                  ')', r'\)')

    @property
    def content(self):
        return ''.join(str(x) for x in self)

    @property
    def comments(self):
        return [self.content]

class AddressList(TokenList):

    token_type = 'address-list'

    @property
    def addresses(self):
        return [x for x in self if x.token_type=='address']

    @property
    def mailboxes(self):
        return sum((x.mailboxes
                    for x in self if x.token_type=='address'), [])

    @property
    def all_mailboxes(self):
        return sum((x.all_mailboxes
                    for x in self if x.token_type=='address'), [])


class Address(TokenList):

    token_type = 'address'

    @property
    def display_name(self):
        if self[0].token_type == 'group':
            return self[0].display_name

    @property
    def mailboxes(self):
        if self[0].token_type == 'mailbox':
            return [self[0]]
        elif self[0].token_type == 'invalid-mailbox':
            return []
        return self[0].mailboxes

    @property
    def all_mailboxes(self):
        if self[0].token_type == 'mailbox':
            return [self[0]]
        elif self[0].token_type == 'invalid-mailbox':
            return [self[0]]
        return self[0].all_mailboxes

class MailboxList(TokenList):

    token_type = 'mailbox-list'

    @property
    def mailboxes(self):
        return [x for x in self if x.token_type=='mailbox']

    @property
    def all_mailboxes(self):
        return [x for x in self
            if x.token_type in ('mailbox', 'invalid-mailbox')]


class GroupList(TokenList):

    token_type = 'group-list'

    @property
    def mailboxes(self):
        if not self or self[0].token_type != 'mailbox-list':
            return []
        return self[0].mailboxes

    @property
    def all_mailboxes(self):
        if not self or self[0].token_type != 'mailbox-list':
            return []
        return self[0].all_mailboxes


class Group(TokenList):

    token_type = "group"

    @property
    def mailboxes(self):
        if self[2].token_type != 'group-list':
            return []
        return self[2].mailboxes

    @property
    def all_mailboxes(self):
        if self[2].token_type != 'group-list':
            return []
        return self[2].all_mailboxes

    @property
    def display_name(self):
        return self[0].display_name


class NameAddr(TokenList):

    token_type = 'name-addr'

    @property
    def display_name(self):
        if len(self) == 1:
            return None
        return self[0].display_name

    @property
    def local_part(self):
        return self[-1].local_part

    @property
    def domain(self):
        return self[-1].domain

    @property
    def route(self):
        return self[-1].route

    @property
    def addr_spec(self):
        return self[-1].addr_spec


class AngleAddr(TokenList):

    token_type = 'angle-addr'

    @property
    def local_part(self):
        for x in self:
            if x.token_type == 'addr-spec':
                return x.local_part

    @property
    def domain(self):
        for x in self:
            if x.token_type == 'addr-spec':
                return x.domain

    @property
    def route(self):
        for x in self:
            if x.token_type == 'obs-route':
                return x.domains

    @property
    def addr_spec(self):
        for x in self:
            if x.token_type == 'addr-spec':
                if x.local_part:
                    return x.addr_spec
                else:
                    return quote_string(x.local_part) + x.addr_spec
        else:
            return '<>'


class ObsRoute(TokenList):

    token_type = 'obs-route'

    @property
    def domains(self):
        return [x.domain for x in self if x.token_type == 'domain']


class Mailbox(TokenList):

    token_type = 'mailbox'

    @property
    def display_name(self):
        if self[0].token_type == 'name-addr':
            return self[0].display_name

    @property
    def local_part(self):
        return self[0].local_part

    @property
    def domain(self):
        return self[0].domain

    @property
    def route(self):
        if self[0].token_type == 'name-addr':
            return self[0].route

    @property
    def addr_spec(self):
        return self[0].addr_spec


class InvalidMailbox(TokenList):

    token_type = 'invalid-mailbox'

    @property
    def display_name(self):
        return None

    local_part = domain = route = addr_spec = display_name


class Domain(TokenList):

    token_type = 'domain'
    as_ew_allowed = False

    @property
    def domain(self):
        return ''.join(super().value.split())


class DotAtom(TokenList):
    token_type = 'dot-atom'


class DotAtomText(TokenList):
    token_type = 'dot-atom-text'
    as_ew_allowed = True


class NoFoldLiteral(TokenList):
    token_type = 'no-fold-literal'
    as_ew_allowed = False


class AddrSpec(TokenList):

    token_type = 'addr-spec'
    as_ew_allowed = False

    @property
    def local_part(self):
        return self[0].local_part

    @property
    def domain(self):
        if len(self) < 3:
            return None
        return self[-1].domain

    @property
    def value(self):
        if len(self) < 3:
            return self[0].value
        return self[0].value.rstrip()+self[1].value+self[2].value.lstrip()

    @property
    def addr_spec(self):
        nameset = set(self.local_part)
        if len(nameset) > len(nameset-DOT_ATOM_ENDS):
            lp = quote_string(self.local_part)
        else:
            lp = self.local_part
        if self.domain is not None:
            return lp + '@' + self.domain
        return lp


class ObsLocalPart(TokenList):

    token_type = 'obs-local-part'
    as_ew_allowed = False


class DisplayName(Phrase):

    token_type = 'display-name'
    ew_combine_allowed = False

    @property
    def display_name(self):
        res = TokenList(self)
        if len(res) == 0:
            return res.value
        if res[0].token_type == 'cfws':
            res.pop(0)
        else:
            if (isinstance(res[0], TokenList) and
                    res[0][0].token_type == 'cfws'):
                res[0] = TokenList(res[0][1:])
        if res[-1].token_type == 'cfws':
            res.pop()
        else:
            if (isinstance(res[-1], TokenList) and
                    res[-1][-1].token_type == 'cfws'):
                res[-1] = TokenList(res[-1][:-1])
        return res.value

    @property
    def value(self):
        quote = False
        if self.defects:
            quote = True
        else:
            for x in self:
                if x.token_type == 'quoted-string':
                    quote = True
        if len(self) != 0 and quote:
            pre = post = ''
            if (self[0].token_type == 'cfws' or
                isinstance(self[0], TokenList) and
                self[0][0].token_type == 'cfws'):
                pre = ' '
            if (self[-1].token_type == 'cfws' or
                isinstance(self[-1], TokenList) and
                self[-1][-1].token_type == 'cfws'):
                post = ' '
            return pre+quote_string(self.display_name)+post
        else:
            return super().value


class LocalPart(TokenList):

    token_type = 'local-part'
    as_ew_allowed = False

    @property
    def value(self):
        if self[0].token_type == "quoted-string":
            return self[0].quoted_value
        else:
            return self[0].value

    @property
    def local_part(self):
        # Strip whitespace from front, back, and around dots.
        res = [DOT]
        last = DOT
        last_is_tl = False
        for tok in self[0] + [DOT]:
            if tok.token_type == 'cfws':
                continue
            if (last_is_tl and tok.token_type == 'dot' and
                    last[-1].token_type == 'cfws'):
                res[-1] = TokenList(last[:-1])
            is_tl = isinstance(tok, TokenList)
            if (is_tl and last.token_type == 'dot' and
                    tok[0].token_type == 'cfws'):
                res.append(TokenList(tok[1:]))
            else:
                res.append(tok)
            last = res[-1]
            last_is_tl = is_tl
        res = TokenList(res[1:-1])
        return res.value


class DomainLiteral(TokenList):

    token_type = 'domain-literal'
    as_ew_allowed = False

    @property
    def domain(self):
        return ''.join(super().value.split())

    @property
    def ip(self):
        for x in self:
            if x.token_type == 'ptext':
                return x.value


class MIMEVersion(TokenList):

    token_type = 'mime-version'
    major = None
    minor = None


class Parameter(TokenList):

    token_type = 'parameter'
    sectioned = False
    extended = False
    charset = 'us-ascii'

    @property
    def section_number(self):
        # Because the first token, the attribute (name) eats CFWS, the second
        # token is always the section if there is one.
        return self[1].number if self.sectioned else 0

    @property
    def param_value(self):
        # This is part of the "handle quoted extended parameters" hack.
        for token in self:
            if token.token_type == 'value':
                return token.stripped_value
            if token.token_type == 'quoted-string':
                for token in token:
                    if token.token_type == 'bare-quoted-string':
                        for token in token:
                            if token.token_type == 'value':
                                return token.stripped_value
        return ''


class InvalidParameter(Parameter):

    token_type = 'invalid-parameter'


class Attribute(TokenList):

    token_type = 'attribute'

    @property
    def stripped_value(self):
        for token in self:
            if token.token_type.endswith('attrtext'):
                return token.value

class Section(TokenList):

    token_type = 'section'
    number = None


class Value(TokenList):

    token_type = 'value'

    @property
    def stripped_value(self):
        token = self[0]
        if token.token_type == 'cfws':
            token = self[1]
        if token.token_type.endswith(
                ('quoted-string', 'attribute', 'extended-attribute')):
            return token.stripped_value
        return self.value


class MimeParameters(TokenList):

    token_type = 'mime-parameters'
    syntactic_break = False

    @property
    def params(self):
        # The RFC specifically states that the ordering of parameters is not
        # guaranteed and may be reordered by the transport layer.  So we have
        # to assume the RFC 2231 pieces can come in any order.  However, we
        # output them in the order that we first see a given name, which gives
        # us a stable __str__.
        params = {}  # Using order preserving dict from Python 3.7+
        for token in self:
            if not token.token_type.endswith('parameter'):
                continue
            if token[0].token_type != 'attribute':
                continue
            name = token[0].value.strip()
            if name not in params:
                params[name] = []
            params[name].append((token.section_number, token))
        for name, parts in params.items():
            parts = sorted(parts, key=itemgetter(0))
            first_param = parts[0][1]
            charset = first_param.charset
            # Our arbitrary error recovery is to ignore duplicate parameters,
            # to use appearance order if there are duplicate rfc 2231 parts,
            # and to ignore gaps.  This mimics the error recovery of get_param.
            if not first_param.extended and len(parts) > 1:
                if parts[1][0] == 0:
                    parts[1][1].defects.append(errors.InvalidHeaderDefect(
                        'duplicate parameter name; duplicate(s) ignored'))
                    parts = parts[:1]
                # Else assume the *0* was missing...note that this is different
                # from get_param, but we registered a defect for this earlier.
            value_parts = []
            i = 0
            for section_number, param in parts:
                if section_number != i:
                    # We could get fancier here and look for a complete
                    # duplicate extended parameter and ignore the second one
                    # seen.  But we're not doing that.  The old code didn't.
                    if not param.extended:
                        param.defects.append(errors.InvalidHeaderDefect(
                            'duplicate parameter name; duplicate ignored'))
                        continue
                    else:
                        param.defects.append(errors.InvalidHeaderDefect(
                            "inconsistent RFC2231 parameter numbering"))
                i += 1
                value = param.param_value
                if param.extended:
                    try:
                        value = urllib.parse.unquote_to_bytes(value)
                    except UnicodeEncodeError:
                        # source had surrogate escaped bytes.  What we do now
                        # is a bit of an open question.  I'm not sure this is
                        # the best choice, but it is what the old algorithm did
                        value = urllib.parse.unquote(value, encoding='latin-1')
                    else:
                        try:
                            value = value.decode(charset, 'surrogateescape')
                        except (LookupError, UnicodeEncodeError):
                            # XXX: there should really be a custom defect for
                            # unknown character set to make it easy to find,
                            # because otherwise unknown charset is a silent
                            # failure.
                            value = value.decode('us-ascii', 'surrogateescape')
                        if utils._has_surrogates(value):
                            param.defects.append(errors.UndecodableBytesDefect())
                value_parts.append(value)
            value = ''.join(value_parts)
            yield name, value

    def __str__(self):
        params = []
        for name, value in self.params:
            if value:
                params.append('{}={}'.format(name, quote_string(value)))
            else:
                params.append(name)
        params = '; '.join(params)
        return ' ' + params if params else ''


class ParameterizedHeaderValue(TokenList):

    # Set this false so that the value doesn't wind up on a new line even
    # if it and the parameters would fit there but not on the first line.
    syntactic_break = False

    @property
    def params(self):
        for token in reversed(self):
            if token.token_type == 'mime-parameters':
                return token.params
        return {}


class ContentType(ParameterizedHeaderValue):
    token_type = 'content-type'
    as_ew_allowed = False
    maintype = 'text'
    subtype = 'plain'


class ContentDisposition(ParameterizedHeaderValue):
    token_type = 'content-disposition'
    as_ew_allowed = False
    content_disposition = None


class ContentTransferEncoding(TokenList):
    token_type = 'content-transfer-encoding'
    as_ew_allowed = False
    cte = '7bit'


class HeaderLabel(TokenList):
    token_type = 'header-label'
    as_ew_allowed = False


class MsgID(TokenList):
    token_type = 'msg-id'
    as_ew_allowed = False

    def fold(self, policy):
        # message-id tokens may not be folded.
        return str(self) + policy.linesep


class MessageID(MsgID):
    token_type = 'message-id'


class InvalidMessageID(MessageID):
    token_type = 'invalid-message-id'


class Header(TokenList):
    token_type = 'header'


#
# Terminal classes and instances
#

class Terminal(str):

    as_ew_allowed = True
    ew_combine_allowed = True
    syntactic_break = True

    def __new__(cls, value, token_type):
        self = super().__new__(cls, value)
        self.token_type = token_type
        self.defects = []
        return self

    def __repr__(self):
        return "{}({})".format(self.__class__.__name__, super().__repr__())

    def pprint(self):
        print(self.__class__.__name__ + '/' + self.token_type)

    @property
    def all_defects(self):
        return list(self.defects)

    def _pp(self, indent=''):
        return ["{}{}/{}({}){}".format(
            indent,
            self.__class__.__name__,
            self.token_type,
            super().__repr__(),
            '' if not self.defects else ' {}'.format(self.defects),
            )]

    def pop_trailing_ws(self):
        # This terminates the recursion.
        return None

    @property
    def comments(self):
        return []

    def __getnewargs__(self):
        return(str(self), self.token_type)


class WhiteSpaceTerminal(Terminal):

    @property
    def value(self):
        return ' '

    def startswith_fws(self):
        return True


class ValueTerminal(Terminal):

    @property
    def value(self):
        return self

    def startswith_fws(self):
        return False


class EWWhiteSpaceTerminal(WhiteSpaceTerminal):

    @property
    def value(self):
        return ''

    def __str__(self):
        return ''


class _InvalidEwError(errors.HeaderParseError):
    """Invalid encoded word found while parsing headers."""


# XXX these need to become classes and used as instances so
# that a program can't change them in a parse tree and screw
# up other parse trees.  Maybe should have  tests for that, too.
DOT = ValueTerminal('.', 'dot')
ListSeparator = ValueTerminal(',', 'list-separator')
ListSeparator.as_ew_allowed = False
ListSeparator.syntactic_break = False
RouteComponentMarker = ValueTerminal('@', 'route-component-marker')

#
# Parser
#

# Parse strings according to RFC822/2047/2822/5322 rules.
#
# This is a stateless parser.  Each get_XXX function accepts a string and
# returns either a Terminal or a TokenList representing the RFC object named
# by the method and a string containing the remaining unparsed characters
# from the input.  Thus a parser method consumes the next syntactic construct
# of a given type and returns a token representing the construct plus the
# unparsed remainder of the input string.
#
# For example, if the first element of a structured header is a 'phrase',
# then:
#
#     phrase, value = get_phrase(value)
#
# returns the complete phrase from the start of the string value, plus any
# characters left in the string after the phrase is removed.

_wsp_splitter = re.compile(r'([{}]+)'.format(''.join(WSP))).split
_non_atom_end_matcher = re.compile(r"[^{}]+".format(
    re.escape(''.join(ATOM_ENDS)))).match
_non_printable_finder = re.compile(r"[\x00-\x20\x7F]").findall
_non_token_end_matcher = re.compile(r"[^{}]+".format(
    re.escape(''.join(TOKEN_ENDS)))).match
_non_attribute_end_matcher = re.compile(r"[^{}]+".format(
    re.escape(''.join(ATTRIBUTE_ENDS)))).match
_non_extended_attribute_end_matcher = re.compile(r"[^{}]+".format(
    re.escape(''.join(EXTENDED_ATTRIBUTE_ENDS)))).match

def _validate_xtext(xtext):
    """If input token contains ASCII non-printables, register a defect."""

    non_printables = _non_printable_finder(xtext)
    if non_printables:
        xtext.defects.append(errors.NonPrintableDefect(non_printables))
    if utils._has_surrogates(xtext):
        xtext.defects.append(errors.UndecodableBytesDefect(
            "Non-ASCII characters found in header token"))

def _get_ptext_to_endchars(value, endchars):
    """Scan printables/quoted-pairs until endchars and return unquoted ptext.

    This function turns a run of qcontent, ccontent-without-comments, or
    dtext-with-quoted-printables into a single string by unquoting any
    quoted printables.  It returns the string, the remaining value, and
    a flag that is True iff there were any quoted printables decoded.

    """
    fragment, *remainder = _wsp_splitter(value, 1)
    vchars = []
    escape = False
    had_qp = False
    for pos in range(len(fragment)):
        if fragment[pos] == '\\':
            if escape:
                escape = False
                had_qp = True
            else:
                escape = True
                continue
        if escape:
            escape = False
        elif fragment[pos] in endchars:
            break
        vchars.append(fragment[pos])
    else:
        pos = pos + 1
    return ''.join(vchars), ''.join([fragment[pos:]] + remainder), had_qp

def get_fws(value):
    """FWS = 1*WSP

    This isn't the RFC definition.  We're using fws to represent tokens where
    folding can be done, but when we are parsing the *un*folding has already
    been done so we don't need to watch out for CRLF.

    """
    newvalue = value.lstrip()
    fws = WhiteSpaceTerminal(value[:len(value)-len(newvalue)], 'fws')
    return fws, newvalue

def get_encoded_word(value, terminal_type='vtext'):
    """ encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

    """
    ew = EncodedWord()
    if not value.startswith('=?'):
        raise errors.HeaderParseError(
            "expected encoded word but found {}".format(value))
    tok, *remainder = value[2:].split('?=', 1)
    if tok == value[2:]:
        raise errors.HeaderParseError(
            "expected encoded word but found {}".format(value))
    remstr = ''.join(remainder)
    if (len(remstr) > 1 and
        remstr[0] in hexdigits and
        remstr[1] in hexdigits and
        tok.count('?') < 2):
        # The ? after the CTE was followed by an encoded word escape (=XX).
        rest, *remainder = remstr.split('?=', 1)
        tok = tok + '?=' + rest
    if len(tok.split()) > 1:
        ew.defects.append(errors.InvalidHeaderDefect(
            "whitespace inside encoded word"))
    ew.cte = value
    value = ''.join(remainder)
    try:
        text, charset, lang, defects = _ew.decode('=?' + tok + '?=')
    except (ValueError, KeyError):
        raise _InvalidEwError(
            "encoded word format invalid: '{}'".format(ew.cte))
    ew.charset = charset
    ew.lang = lang
    ew.defects.extend(defects)
    while text:
        if text[0] in WSP:
            token, text = get_fws(text)
            ew.append(token)
            continue
        chars, *remainder = _wsp_splitter(text, 1)
        vtext = ValueTerminal(chars, terminal_type)
        _validate_xtext(vtext)
        ew.append(vtext)
        text = ''.join(remainder)
    # Encoded words should be followed by a WS
    if value and value[0] not in WSP:
        ew.defects.append(errors.InvalidHeaderDefect(
            "missing trailing whitespace after encoded-word"))
    return ew, value

def get_unstructured(value):
    """unstructured = (*([FWS] vchar) *WSP) / obs-unstruct
       obs-unstruct = *((*LF *CR *(obs-utext) *LF *CR)) / FWS)
       obs-utext = %d0 / obs-NO-WS-CTL / LF / CR

       obs-NO-WS-CTL is control characters except WSP/CR/LF.

    So, basically, we have printable runs, plus control characters or nulls in
    the obsolete syntax, separated by whitespace.  Since RFC 2047 uses the
    obsolete syntax in its specification, but requires whitespace on either
    side of the encoded words, I can see no reason to need to separate the
    non-printable-non-whitespace from the printable runs if they occur, so we
    parse this into xtext tokens separated by WSP tokens.

    Because an 'unstructured' value must by definition constitute the entire
    value, this 'get' routine does not return a remaining value, only the
    parsed TokenList.

    """
    # XXX: but what about bare CR and LF?  They might signal the start or
    # end of an encoded word.  YAGNI for now, since our current parsers
    # will never send us strings with bare CR or LF.

    unstructured = UnstructuredTokenList()
    while value:
        if value[0] in WSP:
            token, value = get_fws(value)
            unstructured.append(token)
            continue
        valid_ew = True
        if value.startswith('=?'):
            try:
                token, value = get_encoded_word(value, 'utext')
            except _InvalidEwError:
                valid_ew = False
            except errors.HeaderParseError:
                # XXX: Need to figure out how to register defects when
                # appropriate here.
                pass
            else:
                have_ws = True
                if len(unstructured) > 0:
                    if unstructured[-1].token_type != 'fws':
                        unstructured.defects.append(errors.InvalidHeaderDefect(
                            "missing whitespace before encoded word"))
                        have_ws = False
                if have_ws and len(unstructured) > 1:
                    if unstructured[-2].token_type == 'encoded-word':
                        unstructured[-1] = EWWhiteSpaceTerminal(
                            unstructured[-1], 'fws')
                unstructured.append(token)
                continue
        tok, *remainder = _wsp_splitter(value, 1)
        # Split in the middle of an atom if there is a rfc2047 encoded word
        # which does not have WSP on both sides. The defect will be registered
        # the next time through the loop.
        # This needs to only be performed when the encoded word is valid;
        # otherwise, performing it on an invalid encoded word can cause
        # the parser to go in an infinite loop.
        if valid_ew and rfc2047_matcher.search(tok):
            tok, *remainder = value.partition('=?')
        vtext = ValueTerminal(tok, 'utext')
        _validate_xtext(vtext)
        unstructured.append(vtext)
        value = ''.join(remainder)
    return unstructured

def get_qp_ctext(value):
    r"""ctext = <printable ascii except \ ( )>

    This is not the RFC ctext, since we are handling nested comments in comment
    and unquoting quoted-pairs here.  We allow anything except the '()'
    characters, but if we find any ASCII other than the RFC defined printable
    ASCII, a NonPrintableDefect is added to the token's defects list.  Since
    quoted pairs are converted to their unquoted values, what is returned is
    a 'ptext' token.  In this case it is a WhiteSpaceTerminal, so it's value
    is ' '.

    """
    ptext, value, _ = _get_ptext_to_endchars(value, '()')
    ptext = WhiteSpaceTerminal(ptext, 'ptext')
    _validate_xtext(ptext)
    return ptext, value

def get_qcontent(value):
    """qcontent = qtext / quoted-pair

    We allow anything except the DQUOTE character, but if we find any ASCII
    other than the RFC defined printable ASCII, a NonPrintableDefect is
    added to the token's defects list.  Any quoted pairs are converted to their
    unquoted values, so what is returned is a 'ptext' token.  In this case it
    is a ValueTerminal.

    """
    ptext, value, _ = _get_ptext_to_endchars(value, '"')
    ptext = ValueTerminal(ptext, 'ptext')
    _validate_xtext(ptext)
    return ptext, value

def get_atext(value):
    """atext = <matches _atext_matcher>

    We allow any non-ATOM_ENDS in atext, but add an InvalidATextDefect to
    the token's defects list if we find non-atext characters.
    """
    m = _non_atom_end_matcher(value)
    if not m:
        raise errors.HeaderParseError(
            "expected atext but found '{}'".format(value))
    atext = m.group()
    value = value[len(atext):]
    atext = ValueTerminal(atext, 'atext')
    _validate_xtext(atext)
    return atext, value

def get_bare_quoted_string(value):
    """bare-quoted-string = DQUOTE *([FWS] qcontent) [FWS] DQUOTE

    A quoted-string without the leading or trailing white space.  Its
    value is the text between the quote marks, with whitespace
    preserved and quoted pairs decoded.
    """
    if not value or value[0] != '"':
        raise errors.HeaderParseError(
            "expected '\"' but found '{}'".format(value))
    bare_quoted_string = BareQuotedString()
    value = value[1:]
    if value and value[0] == '"':
        token, value = get_qcontent(value)
        bare_quoted_string.append(token)
    while value and value[0] != '"':
        if value[0] in WSP:
            token, value = get_fws(value)
        elif value[:2] == '=?':
            valid_ew = False
            try:
                token, value = get_encoded_word(value)
                bare_quoted_string.defects.append(errors.InvalidHeaderDefect(
                    "encoded word inside quoted string"))
                valid_ew = True
            except errors.HeaderParseError:
                token, value = get_qcontent(value)
            # Collapse the whitespace between two encoded words that occur in a
            # bare-quoted-string.
            if valid_ew and len(bare_quoted_string) > 1:
                if (bare_quoted_string[-1].token_type == 'fws' and
                        bare_quoted_string[-2].token_type == 'encoded-word'):
                    bare_quoted_string[-1] = EWWhiteSpaceTerminal(
                        bare_quoted_string[-1], 'fws')
        else:
            token, value = get_qcontent(value)
        bare_quoted_string.append(token)
    if not value:
        bare_quoted_string.defects.append(errors.InvalidHeaderDefect(
            "end of header inside quoted string"))
        return bare_quoted_string, value
    return bare_quoted_string, value[1:]

def get_comment(value):
    """comment = "(" *([FWS] ccontent) [FWS] ")"
       ccontent = ctext / quoted-pair / comment

    We handle nested comments here, and quoted-pair in our qp-ctext routine.
    """
    if value and value[0] != '(':
        raise errors.HeaderParseError(
            "expected '(' but found '{}'".format(value))
    comment = Comment()
    value = value[1:]
    while value and value[0] != ")":
        if value[0] in WSP:
            token, value = get_fws(value)
        elif value[0] == '(':
            token, value = get_comment(value)
        else:
            token, value = get_qp_ctext(value)
        comment.append(token)
    if not value:
        comment.defects.append(errors.InvalidHeaderDefect(
            "end of header inside comment"))
        return comment, value
    return comment, value[1:]

def get_cfws(value):
    """CFWS = (1*([FWS] comment) [FWS]) / FWS

    """
    cfws = CFWSList()
    while value and value[0] in CFWS_LEADER:
        if value[0] in WSP:
            token, value = get_fws(value)
        else:
            token, value = get_comment(value)
        cfws.append(token)
    return cfws, value

def get_quoted_string(value):
    """quoted-string = [CFWS] <bare-quoted-string> [CFWS]

    'bare-quoted-string' is an intermediate class defined by this
    parser and not by the RFC grammar.  It is the quoted string
    without any attached CFWS.
    """
    quoted_string = QuotedString()
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        quoted_string.append(token)
    token, value = get_bare_quoted_string(value)
    quoted_string.append(token)
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        quoted_string.append(token)
    return quoted_string, value

def get_atom(value):
    """atom = [CFWS] 1*atext [CFWS]

    An atom could be an rfc2047 encoded word.
    """
    atom = Atom()
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        atom.append(token)
    if value and value[0] in ATOM_ENDS:
        raise errors.HeaderParseError(
            "expected atom but found '{}'".format(value))
    if value.startswith('=?'):
        try:
            token, value = get_encoded_word(value)
        except errors.HeaderParseError:
            # XXX: need to figure out how to register defects when
            # appropriate here.
            token, value = get_atext(value)
    else:
        token, value = get_atext(value)
    atom.append(token)
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        atom.append(token)
    return atom, value

def get_dot_atom_text(value):
    """ dot-text = 1*atext *("." 1*atext)

    """
    dot_atom_text = DotAtomText()
    if not value or value[0] in ATOM_ENDS:
        raise errors.HeaderParseError("expected atom at a start of "
            "dot-atom-text but found '{}'".format(value))
    while value and value[0] not in ATOM_ENDS:
        token, value = get_atext(value)
        dot_atom_text.append(token)
        if value and value[0] == '.':
            dot_atom_text.append(DOT)
            value = value[1:]
    if dot_atom_text[-1] is DOT:
        raise errors.HeaderParseError("expected atom at end of dot-atom-text "
            "but found '{}'".format('.'+value))
    return dot_atom_text, value

def get_dot_atom(value):
    """ dot-atom = [CFWS] dot-atom-text [CFWS]

    Any place we can have a dot atom, we could instead have an rfc2047 encoded
    word.
    """
    dot_atom = DotAtom()
    if value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        dot_atom.append(token)
    if value.startswith('=?'):
        try:
            token, value = get_encoded_word(value)
        except errors.HeaderParseError:
            # XXX: need to figure out how to register defects when
            # appropriate here.
            token, value = get_dot_atom_text(value)
    else:
        token, value = get_dot_atom_text(value)
    dot_atom.append(token)
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        dot_atom.append(token)
    return dot_atom, value

def get_word(value):
    """word = atom / quoted-string

    Either atom or quoted-string may start with CFWS.  We have to peel off this
    CFWS first to determine which type of word to parse.  Afterward we splice
    the leading CFWS, if any, into the parsed sub-token.

    If neither an atom or a quoted-string is found before the next special, a
    HeaderParseError is raised.

    The token returned is either an Atom or a QuotedString, as appropriate.
    This means the 'word' level of the formal grammar is not represented in the
    parse tree; this is because having that extra layer when manipulating the
    parse tree is more confusing than it is helpful.

    """
    if value[0] in CFWS_LEADER:
        leader, value = get_cfws(value)
    else:
        leader = None
    if not value:
        raise errors.HeaderParseError(
            "Expected 'atom' or 'quoted-string' but found nothing.")
    if value[0]=='"':
        token, value = get_quoted_string(value)
    elif value[0] in SPECIALS:
        raise errors.HeaderParseError("Expected 'atom' or 'quoted-string' "
                                      "but found '{}'".format(value))
    else:
        token, value = get_atom(value)
    if leader is not None:
        token[:0] = [leader]
    return token, value

def get_phrase(value):
    """ phrase = 1*word / obs-phrase
        obs-phrase = word *(word / "." / CFWS)

    This means a phrase can be a sequence of words, periods, and CFWS in any
    order as long as it starts with at least one word.  If anything other than
    words is detected, an ObsoleteHeaderDefect is added to the token's defect
    list.  We also accept a phrase that starts with CFWS followed by a dot;
    this is registered as an InvalidHeaderDefect, since it is not supported by
    even the obsolete grammar.

    """
    phrase = Phrase()
    try:
        token, value = get_word(value)
        phrase.append(token)
    except errors.HeaderParseError:
        phrase.defects.append(errors.InvalidHeaderDefect(
            "phrase does not start with word"))
    while value and value[0] not in PHRASE_ENDS:
        if value[0]=='.':
            phrase.append(DOT)
            phrase.defects.append(errors.ObsoleteHeaderDefect(
                "period in 'phrase'"))
            value = value[1:]
        else:
            try:
                token, value = get_word(value)
            except errors.HeaderParseError:
                if value[0] in CFWS_LEADER:
                    token, value = get_cfws(value)
                    phrase.defects.append(errors.ObsoleteHeaderDefect(
                        "comment found without atom"))
                else:
                    raise
            phrase.append(token)
    return phrase, value

def get_local_part(value):
    """ local-part = dot-atom / quoted-string / obs-local-part

    """
    local_part = LocalPart()
    leader = None
    if value and value[0] in CFWS_LEADER:
        leader, value = get_cfws(value)
    if not value:
        raise errors.HeaderParseError(
            "expected local-part but found '{}'".format(value))
    try:
        token, value = get_dot_atom(value)
    except errors.HeaderParseError:
        try:
            token, value = get_word(value)
        except errors.HeaderParseError:
            if value[0] != '\\' and value[0] in PHRASE_ENDS:
                raise
            token = TokenList()
    if leader is not None:
        token[:0] = [leader]
    local_part.append(token)
    if value and (value[0]=='\\' or value[0] not in PHRASE_ENDS):
        obs_local_part, value = get_obs_local_part(str(local_part) + value)
        if obs_local_part.token_type == 'invalid-obs-local-part':
            local_part.defects.append(errors.InvalidHeaderDefect(
                "local-part is not dot-atom, quoted-string, or obs-local-part"))
        else:
            local_part.defects.append(errors.ObsoleteHeaderDefect(
                "local-part is not a dot-atom (contains CFWS)"))
        local_part[0] = obs_local_part
    try:
        local_part.value.encode('ascii')
    except UnicodeEncodeError:
        local_part.defects.append(errors.NonASCIILocalPartDefect(
                "local-part contains non-ASCII characters)"))
    return local_part, value

def get_obs_local_part(value):
    """ obs-local-part = word *("." word)
    """
    obs_local_part = ObsLocalPart()
    last_non_ws_was_dot = False
    while value and (value[0]=='\\' or value[0] not in PHRASE_ENDS):
        if value[0] == '.':
            if last_non_ws_was_dot:
                obs_local_part.defects.append(errors.InvalidHeaderDefect(
                    "invalid repeated '.'"))
            obs_local_part.append(DOT)
            last_non_ws_was_dot = True
            value = value[1:]
            continue
        elif value[0]=='\\':
            obs_local_part.append(ValueTerminal(value[0],
                                                'misplaced-special'))
            value = value[1:]
            obs_local_part.defects.append(errors.InvalidHeaderDefect(
                "'\\' character outside of quoted-string/ccontent"))
            last_non_ws_was_dot = False
            continue
        if obs_local_part and obs_local_part[-1].token_type != 'dot':
            obs_local_part.defects.append(errors.InvalidHeaderDefect(
                "missing '.' between words"))
        try:
            token, value = get_word(value)
            last_non_ws_was_dot = False
        except errors.HeaderParseError:
            if value[0] not in CFWS_LEADER:
                raise
            token, value = get_cfws(value)
        obs_local_part.append(token)
    if not obs_local_part:
        raise errors.HeaderParseError(
            "expected obs-local-part but found '{}'".format(value))
    if (obs_local_part[0].token_type == 'dot' or
            obs_local_part[0].token_type=='cfws' and
            len(obs_local_part) > 1 and
            obs_local_part[1].token_type=='dot'):
        obs_local_part.defects.append(errors.InvalidHeaderDefect(
            "Invalid leading '.' in local part"))
    if (obs_local_part[-1].token_type == 'dot' or
            obs_local_part[-1].token_type=='cfws' and
            len(obs_local_part) > 1 and
            obs_local_part[-2].token_type=='dot'):
        obs_local_part.defects.append(errors.InvalidHeaderDefect(
            "Invalid trailing '.' in local part"))
    if obs_local_part.defects:
        obs_local_part.token_type = 'invalid-obs-local-part'
    return obs_local_part, value

def get_dtext(value):
    r""" dtext = <printable ascii except \ [ ]> / obs-dtext
        obs-dtext = obs-NO-WS-CTL / quoted-pair

    We allow anything except the excluded characters, but if we find any
    ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is
    added to the token's defects list.  Quoted pairs are converted to their
    unquoted values, so what is returned is a ptext token, in this case a
    ValueTerminal.  If there were quoted-printables, an ObsoleteHeaderDefect is
    added to the returned token's defect list.

    """
    ptext, value, had_qp = _get_ptext_to_endchars(value, '[]')
    ptext = ValueTerminal(ptext, 'ptext')
    if had_qp:
        ptext.defects.append(errors.ObsoleteHeaderDefect(
            "quoted printable found in domain-literal"))
    _validate_xtext(ptext)
    return ptext, value

def _check_for_early_dl_end(value, domain_literal):
    if value:
        return False
    domain_literal.append(errors.InvalidHeaderDefect(
        "end of input inside domain-literal"))
    domain_literal.append(ValueTerminal(']', 'domain-literal-end'))
    return True

def get_domain_literal(value):
    """ domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]

    """
    domain_literal = DomainLiteral()
    if value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        domain_literal.append(token)
    if not value:
        raise errors.HeaderParseError("expected domain-literal")
    if value[0] != '[':
        raise errors.HeaderParseError("expected '[' at start of domain-literal "
                "but found '{}'".format(value))
    value = value[1:]
    if _check_for_early_dl_end(value, domain_literal):
        return domain_literal, value
    domain_literal.append(ValueTerminal('[', 'domain-literal-start'))
    if value[0] in WSP:
        token, value = get_fws(value)
        domain_literal.append(token)
    token, value = get_dtext(value)
    domain_literal.append(token)
    if _check_for_early_dl_end(value, domain_literal):
        return domain_literal, value
    if value[0] in WSP:
        token, value = get_fws(value)
        domain_literal.append(token)
    if _check_for_early_dl_end(value, domain_literal):
        return domain_literal, value
    if value[0] != ']':
        raise errors.HeaderParseError("expected ']' at end of domain-literal "
                "but found '{}'".format(value))
    domain_literal.append(ValueTerminal(']', 'domain-literal-end'))
    value = value[1:]
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        domain_literal.append(token)
    return domain_literal, value

def get_domain(value):
    """ domain = dot-atom / domain-literal / obs-domain
        obs-domain = atom *("." atom))

    """
    domain = Domain()
    leader = None
    if value and value[0] in CFWS_LEADER:
        leader, value = get_cfws(value)
    if not value:
        raise errors.HeaderParseError(
            "expected domain but found '{}'".format(value))
    if value[0] == '[':
        token, value = get_domain_literal(value)
        if leader is not None:
            token[:0] = [leader]
        domain.append(token)
        return domain, value
    try:
        token, value = get_dot_atom(value)
    except errors.HeaderParseError:
        token, value = get_atom(value)
    if value and value[0] == '@':
        raise errors.HeaderParseError('Invalid Domain')
    if leader is not None:
        token[:0] = [leader]
    domain.append(token)
    if value and value[0] == '.':
        domain.defects.append(errors.ObsoleteHeaderDefect(
            "domain is not a dot-atom (contains CFWS)"))
        if domain[0].token_type == 'dot-atom':
            domain[:] = domain[0]
        while value and value[0] == '.':
            domain.append(DOT)
            token, value = get_atom(value[1:])
            domain.append(token)
    return domain, value

def get_addr_spec(value):
    """ addr-spec = local-part "@" domain

    """
    addr_spec = AddrSpec()
    token, value = get_local_part(value)
    addr_spec.append(token)
    if not value or value[0] != '@':
        addr_spec.defects.append(errors.InvalidHeaderDefect(
            "addr-spec local part with no domain"))
        return addr_spec, value
    addr_spec.append(ValueTerminal('@', 'address-at-symbol'))
    token, value = get_domain(value[1:])
    addr_spec.append(token)
    return addr_spec, value

def get_obs_route(value):
    """ obs-route = obs-domain-list ":"
        obs-domain-list = *(CFWS / ",") "@" domain *("," [CFWS] ["@" domain])

        Returns an obs-route token with the appropriate sub-tokens (that is,
        there is no obs-domain-list in the parse tree).
    """
    obs_route = ObsRoute()
    while value and (value[0]==',' or value[0] in CFWS_LEADER):
        if value[0] in CFWS_LEADER:
            token, value = get_cfws(value)
            obs_route.append(token)
        elif value[0] == ',':
            obs_route.append(ListSeparator)
            value = value[1:]
    if not value or value[0] != '@':
        raise errors.HeaderParseError(
            "expected obs-route domain but found '{}'".format(value))
    obs_route.append(RouteComponentMarker)
    token, value = get_domain(value[1:])
    obs_route.append(token)
    while value and value[0]==',':
        obs_route.append(ListSeparator)
        value = value[1:]
        if not value:
            break
        if value[0] in CFWS_LEADER:
            token, value = get_cfws(value)
            obs_route.append(token)
        if not value:
            break
        if value[0] == '@':
            obs_route.append(RouteComponentMarker)
            token, value = get_domain(value[1:])
            obs_route.append(token)
    if not value:
        raise errors.HeaderParseError("end of header while parsing obs-route")
    if value[0] != ':':
        raise errors.HeaderParseError( "expected ':' marking end of "
            "obs-route but found '{}'".format(value))
    obs_route.append(ValueTerminal(':', 'end-of-obs-route-marker'))
    return obs_route, value[1:]

def get_angle_addr(value):
    """ angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
        obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS]

    """
    angle_addr = AngleAddr()
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        angle_addr.append(token)
    if not value or value[0] != '<':
        raise errors.HeaderParseError(
            "expected angle-addr but found '{}'".format(value))
    angle_addr.append(ValueTerminal('<', 'angle-addr-start'))
    value = value[1:]
    # Although it is not legal per RFC5322, SMTP uses '<>' in certain
    # circumstances.
    if value and value[0] == '>':
        angle_addr.append(ValueTerminal('>', 'angle-addr-end'))
        angle_addr.defects.append(errors.InvalidHeaderDefect(
            "null addr-spec in angle-addr"))
        value = value[1:]
        return angle_addr, value
    try:
        token, value = get_addr_spec(value)
    except errors.HeaderParseError:
        try:
            token, value = get_obs_route(value)
            angle_addr.defects.append(errors.ObsoleteHeaderDefect(
                "obsolete route specification in angle-addr"))
        except errors.HeaderParseError:
            raise errors.HeaderParseError(
                "expected addr-spec or obs-route but found '{}'".format(value))
        angle_addr.append(token)
        token, value = get_addr_spec(value)
    angle_addr.append(token)
    if value and value[0] == '>':
        value = value[1:]
    else:
        angle_addr.defects.append(errors.InvalidHeaderDefect(
            "missing trailing '>' on angle-addr"))
    angle_addr.append(ValueTerminal('>', 'angle-addr-end'))
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        angle_addr.append(token)
    return angle_addr, value

def get_display_name(value):
    """ display-name = phrase

    Because this is simply a name-rule, we don't return a display-name
    token containing a phrase, but rather a display-name token with
    the content of the phrase.

    """
    display_name = DisplayName()
    token, value = get_phrase(value)
    display_name.extend(token[:])
    display_name.defects = token.defects[:]
    return display_name, value


def get_name_addr(value):
    """ name-addr = [display-name] angle-addr

    """
    name_addr = NameAddr()
    # Both the optional display name and the angle-addr can start with cfws.
    leader = None
    if not value:
        raise errors.HeaderParseError(
            "expected name-addr but found '{}'".format(value))
    if value[0] in CFWS_LEADER:
        leader, value = get_cfws(value)
        if not value:
            raise errors.HeaderParseError(
                "expected name-addr but found '{}'".format(leader))
    if value[0] != '<':
        if value[0] in PHRASE_ENDS:
            raise errors.HeaderParseError(
                "expected name-addr but found '{}'".format(value))
        token, value = get_display_name(value)
        if not value:
            raise errors.HeaderParseError(
                "expected name-addr but found '{}'".format(token))
        if leader is not None:
            if isinstance(token[0], TokenList):
                token[0][:0] = [leader]
            else:
                token[:0] = [leader]
            leader = None
        name_addr.append(token)
    token, value = get_angle_addr(value)
    if leader is not None:
        token[:0] = [leader]
    name_addr.append(token)
    return name_addr, value

def get_mailbox(value):
    """ mailbox = name-addr / addr-spec

    """
    # The only way to figure out if we are dealing with a name-addr or an
    # addr-spec is to try parsing each one.
    mailbox = Mailbox()
    try:
        token, value = get_name_addr(value)
    except errors.HeaderParseError:
        try:
            token, value = get_addr_spec(value)
        except errors.HeaderParseError:
            raise errors.HeaderParseError(
                "expected mailbox but found '{}'".format(value))
    if any(isinstance(x, errors.InvalidHeaderDefect)
                       for x in token.all_defects):
        mailbox.token_type = 'invalid-mailbox'
    mailbox.append(token)
    return mailbox, value

def get_invalid_mailbox(value, endchars):
    """ Read everything up to one of the chars in endchars.

    This is outside the formal grammar.  The InvalidMailbox TokenList that is
    returned acts like a Mailbox, but the data attributes are None.

    """
    invalid_mailbox = InvalidMailbox()
    while value and value[0] not in endchars:
        if value[0] in PHRASE_ENDS:
            invalid_mailbox.append(ValueTerminal(value[0],
                                                 'misplaced-special'))
            value = value[1:]
        else:
            token, value = get_phrase(value)
            invalid_mailbox.append(token)
    return invalid_mailbox, value

def get_mailbox_list(value):
    """ mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list
        obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS])

    For this routine we go outside the formal grammar in order to improve error
    handling.  We recognize the end of the mailbox list only at the end of the
    value or at a ';' (the group terminator).  This is so that we can turn
    invalid mailboxes into InvalidMailbox tokens and continue parsing any
    remaining valid mailboxes.  We also allow all mailbox entries to be null,
    and this condition is handled appropriately at a higher level.

    """
    mailbox_list = MailboxList()
    while value and value[0] != ';':
        try:
            token, value = get_mailbox(value)
            mailbox_list.append(token)
        except errors.HeaderParseError:
            leader = None
            if value[0] in CFWS_LEADER:
                leader, value = get_cfws(value)
                if not value or value[0] in ',;':
                    mailbox_list.append(leader)
                    mailbox_list.defects.append(errors.ObsoleteHeaderDefect(
                        "empty element in mailbox-list"))
                else:
                    token, value = get_invalid_mailbox(value, ',;')
                    if leader is not None:
                        token[:0] = [leader]
                    mailbox_list.append(token)
                    mailbox_list.defects.append(errors.InvalidHeaderDefect(
                        "invalid mailbox in mailbox-list"))
            elif value[0] == ',':
                mailbox_list.defects.append(errors.ObsoleteHeaderDefect(
                    "empty element in mailbox-list"))
            else:
                token, value = get_invalid_mailbox(value, ',;')
                if leader is not None:
                    token[:0] = [leader]
                mailbox_list.append(token)
                mailbox_list.defects.append(errors.InvalidHeaderDefect(
                    "invalid mailbox in mailbox-list"))
        if value and value[0] not in ',;':
            # Crap after mailbox; treat it as an invalid mailbox.
            # The mailbox info will still be available.
            mailbox = mailbox_list[-1]
            mailbox.token_type = 'invalid-mailbox'
            token, value = get_invalid_mailbox(value, ',;')
            mailbox.extend(token)
            mailbox_list.defects.append(errors.InvalidHeaderDefect(
                "invalid mailbox in mailbox-list"))
        if value and value[0] == ',':
            mailbox_list.append(ListSeparator)
            value = value[1:]
    return mailbox_list, value


def get_group_list(value):
    """ group-list = mailbox-list / CFWS / obs-group-list
        obs-group-list = 1*([CFWS] ",") [CFWS]

    """
    group_list = GroupList()
    if not value:
        group_list.defects.append(errors.InvalidHeaderDefect(
            "end of header before group-list"))
        return group_list, value
    leader = None
    if value and value[0] in CFWS_LEADER:
        leader, value = get_cfws(value)
        if not value:
            # This should never happen in email parsing, since CFWS-only is a
            # legal alternative to group-list in a group, which is the only
            # place group-list appears.
            group_list.defects.append(errors.InvalidHeaderDefect(
                "end of header in group-list"))
            group_list.append(leader)
            return group_list, value
        if value[0] == ';':
            group_list.append(leader)
            return group_list, value
    token, value = get_mailbox_list(value)
    if len(token.all_mailboxes)==0:
        if leader is not None:
            group_list.append(leader)
        group_list.extend(token)
        group_list.defects.append(errors.ObsoleteHeaderDefect(
            "group-list with empty entries"))
        return group_list, value
    if leader is not None:
        token[:0] = [leader]
    group_list.append(token)
    return group_list, value

def get_group(value):
    """ group = display-name ":" [group-list] ";" [CFWS]

    """
    group = Group()
    token, value = get_display_name(value)
    if not value or value[0] != ':':
        raise errors.HeaderParseError("expected ':' at end of group "
            "display name but found '{}'".format(value))
    group.append(token)
    group.append(ValueTerminal(':', 'group-display-name-terminator'))
    value = value[1:]
    if value and value[0] == ';':
        group.append(ValueTerminal(';', 'group-terminator'))
        return group, value[1:]
    token, value = get_group_list(value)
    group.append(token)
    if not value:
        group.defects.append(errors.InvalidHeaderDefect(
            "end of header in group"))
    elif value[0] != ';':
        raise errors.HeaderParseError(
            "expected ';' at end of group but found {}".format(value))
    group.append(ValueTerminal(';', 'group-terminator'))
    value = value[1:]
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        group.append(token)
    return group, value

def get_address(value):
    """ address = mailbox / group

    Note that counter-intuitively, an address can be either a single address or
    a list of addresses (a group).  This is why the returned Address object has
    a 'mailboxes' attribute which treats a single address as a list of length
    one.  When you need to differentiate between to two cases, extract the single
    element, which is either a mailbox or a group token.

    """
    # The formal grammar isn't very helpful when parsing an address.  mailbox
    # and group, especially when allowing for obsolete forms, start off very
    # similarly.  It is only when you reach one of @, <, or : that you know
    # what you've got.  So, we try each one in turn, starting with the more
    # likely of the two.  We could perhaps make this more efficient by looking
    # for a phrase and then branching based on the next character, but that
    # would be a premature optimization.
    address = Address()
    try:
        token, value = get_group(value)
    except errors.HeaderParseError:
        try:
            token, value = get_mailbox(value)
        except errors.HeaderParseError:
            raise errors.HeaderParseError(
                "expected address but found '{}'".format(value))
    address.append(token)
    return address, value

def get_address_list(value):
    """ address_list = (address *("," address)) / obs-addr-list
        obs-addr-list = *([CFWS] ",") address *("," [address / CFWS])

    We depart from the formal grammar here by continuing to parse until the end
    of the input, assuming the input to be entirely composed of an
    address-list.  This is always true in email parsing, and allows us
    to skip invalid addresses to parse additional valid ones.

    """
    address_list = AddressList()
    while value:
        try:
            token, value = get_address(value)
            address_list.append(token)
        except errors.HeaderParseError:
            leader = None
            if value[0] in CFWS_LEADER:
                leader, value = get_cfws(value)
                if not value or value[0] == ',':
                    address_list.append(leader)
                    address_list.defects.append(errors.ObsoleteHeaderDefect(
                        "address-list entry with no content"))
                else:
                    token, value = get_invalid_mailbox(value, ',')
                    if leader is not None:
                        token[:0] = [leader]
                    address_list.append(Address([token]))
                    address_list.defects.append(errors.InvalidHeaderDefect(
                        "invalid address in address-list"))
            elif value[0] == ',':
                address_list.defects.append(errors.ObsoleteHeaderDefect(
                    "empty element in address-list"))
            else:
                token, value = get_invalid_mailbox(value, ',')
                if leader is not None:
                    token[:0] = [leader]
                address_list.append(Address([token]))
                address_list.defects.append(errors.InvalidHeaderDefect(
                    "invalid address in address-list"))
        if value and value[0] != ',':
            # Crap after address; treat it as an invalid mailbox.
            # The mailbox info will still be available.
            mailbox = address_list[-1][0]
            mailbox.token_type = 'invalid-mailbox'
            token, value = get_invalid_mailbox(value, ',')
            mailbox.extend(token)
            address_list.defects.append(errors.InvalidHeaderDefect(
                "invalid address in address-list"))
        if value:  # Must be a , at this point.
            address_list.append(ListSeparator)
            value = value[1:]
    return address_list, value


def get_no_fold_literal(value):
    """ no-fold-literal = "[" *dtext "]"
    """
    no_fold_literal = NoFoldLiteral()
    if not value:
        raise errors.HeaderParseError(
            "expected no-fold-literal but found '{}'".format(value))
    if value[0] != '[':
        raise errors.HeaderParseError(
            "expected '[' at the start of no-fold-literal "
            "but found '{}'".format(value))
    no_fold_literal.append(ValueTerminal('[', 'no-fold-literal-start'))
    value = value[1:]
    token, value = get_dtext(value)
    no_fold_literal.append(token)
    if not value or value[0] != ']':
        raise errors.HeaderParseError(
            "expected ']' at the end of no-fold-literal "
            "but found '{}'".format(value))
    no_fold_literal.append(ValueTerminal(']', 'no-fold-literal-end'))
    return no_fold_literal, value[1:]

def get_msg_id(value):
    """msg-id = [CFWS] "<" id-left '@' id-right  ">" [CFWS]
       id-left = dot-atom-text / obs-id-left
       id-right = dot-atom-text / no-fold-literal / obs-id-right
       no-fold-literal = "[" *dtext "]"
    """
    msg_id = MsgID()
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        msg_id.append(token)
    if not value or value[0] != '<':
        raise errors.HeaderParseError(
            "expected msg-id but found '{}'".format(value))
    msg_id.append(ValueTerminal('<', 'msg-id-start'))
    value = value[1:]
    # Parse id-left.
    try:
        token, value = get_dot_atom_text(value)
    except errors.HeaderParseError:
        try:
            # obs-id-left is same as local-part of add-spec.
            token, value = get_obs_local_part(value)
            msg_id.defects.append(errors.ObsoleteHeaderDefect(
                "obsolete id-left in msg-id"))
        except errors.HeaderParseError:
            raise errors.HeaderParseError(
                "expected dot-atom-text or obs-id-left"
                " but found '{}'".format(value))
    msg_id.append(token)
    if not value or value[0] != '@':
        msg_id.defects.append(errors.InvalidHeaderDefect(
            "msg-id with no id-right"))
        # Even though there is no id-right, if the local part
        # ends with `>` let's just parse it too and return
        # along with the defect.
        if value and value[0] == '>':
            msg_id.append(ValueTerminal('>', 'msg-id-end'))
            value = value[1:]
        return msg_id, value
    msg_id.append(ValueTerminal('@', 'address-at-symbol'))
    value = value[1:]
    # Parse id-right.
    try:
        token, value = get_dot_atom_text(value)
    except errors.HeaderParseError:
        try:
            token, value = get_no_fold_literal(value)
        except errors.HeaderParseError:
            try:
                token, value = get_domain(value)
                msg_id.defects.append(errors.ObsoleteHeaderDefect(
                    "obsolete id-right in msg-id"))
            except errors.HeaderParseError:
                raise errors.HeaderParseError(
                    "expected dot-atom-text, no-fold-literal or obs-id-right"
                    " but found '{}'".format(value))
    msg_id.append(token)
    if value and value[0] == '>':
        value = value[1:]
    else:
        msg_id.defects.append(errors.InvalidHeaderDefect(
            "missing trailing '>' on msg-id"))
    msg_id.append(ValueTerminal('>', 'msg-id-end'))
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        msg_id.append(token)
    return msg_id, value


def parse_message_id(value):
    """message-id      =   "Message-ID:" msg-id CRLF
    """
    message_id = MessageID()
    try:
        token, value = get_msg_id(value)
        message_id.append(token)
    except errors.HeaderParseError as ex:
        token = get_unstructured(value)
        message_id = InvalidMessageID(token)
        message_id.defects.append(
            errors.InvalidHeaderDefect("Invalid msg-id: {!r}".format(ex)))
    else:
        # Value after parsing a valid msg_id should be None.
        if value:
            message_id.defects.append(errors.InvalidHeaderDefect(
                "Unexpected {!r}".format(value)))

    return message_id

#
# XXX: As I begin to add additional header parsers, I'm realizing we probably
# have two level of parser routines: the get_XXX methods that get a token in
# the grammar, and parse_XXX methods that parse an entire field value.  So
# get_address_list above should really be a parse_ method, as probably should
# be get_unstructured.
#

def parse_mime_version(value):
    """ mime-version = [CFWS] 1*digit [CFWS] "." [CFWS] 1*digit [CFWS]

    """
    # The [CFWS] is implicit in the RFC 2045 BNF.
    # XXX: This routine is a bit verbose, should factor out a get_int method.
    mime_version = MIMEVersion()
    if not value:
        mime_version.defects.append(errors.HeaderMissingRequiredValue(
            "Missing MIME version number (eg: 1.0)"))
        return mime_version
    if value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        mime_version.append(token)
        if not value:
            mime_version.defects.append(errors.HeaderMissingRequiredValue(
                "Expected MIME version number but found only CFWS"))
    digits = ''
    while value and value[0] != '.' and value[0] not in CFWS_LEADER:
        digits += value[0]
        value = value[1:]
    if not digits.isdigit():
        mime_version.defects.append(errors.InvalidHeaderDefect(
            "Expected MIME major version number but found {!r}".format(digits)))
        mime_version.append(ValueTerminal(digits, 'xtext'))
    else:
        mime_version.major = int(digits)
        mime_version.append(ValueTerminal(digits, 'digits'))
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        mime_version.append(token)
    if not value or value[0] != '.':
        if mime_version.major is not None:
            mime_version.defects.append(errors.InvalidHeaderDefect(
                "Incomplete MIME version; found only major number"))
        if value:
            mime_version.append(ValueTerminal(value, 'xtext'))
        return mime_version
    mime_version.append(ValueTerminal('.', 'version-separator'))
    value = value[1:]
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        mime_version.append(token)
    if not value:
        if mime_version.major is not None:
            mime_version.defects.append(errors.InvalidHeaderDefect(
                "Incomplete MIME version; found only major number"))
        return mime_version
    digits = ''
    while value and value[0] not in CFWS_LEADER:
        digits += value[0]
        value = value[1:]
    if not digits.isdigit():
        mime_version.defects.append(errors.InvalidHeaderDefect(
            "Expected MIME minor version number but found {!r}".format(digits)))
        mime_version.append(ValueTerminal(digits, 'xtext'))
    else:
        mime_version.minor = int(digits)
        mime_version.append(ValueTerminal(digits, 'digits'))
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        mime_version.append(token)
    if value:
        mime_version.defects.append(errors.InvalidHeaderDefect(
            "Excess non-CFWS text after MIME version"))
        mime_version.append(ValueTerminal(value, 'xtext'))
    return mime_version

def get_invalid_parameter(value):
    """ Read everything up to the next ';'.

    This is outside the formal grammar.  The InvalidParameter TokenList that is
    returned acts like a Parameter, but the data attributes are None.

    """
    invalid_parameter = InvalidParameter()
    while value and value[0] != ';':
        if value[0] in PHRASE_ENDS:
            invalid_parameter.append(ValueTerminal(value[0],
                                                   'misplaced-special'))
            value = value[1:]
        else:
            token, value = get_phrase(value)
            invalid_parameter.append(token)
    return invalid_parameter, value

def get_ttext(value):
    """ttext = <matches _ttext_matcher>

    We allow any non-TOKEN_ENDS in ttext, but add defects to the token's
    defects list if we find non-ttext characters.  We also register defects for
    *any* non-printables even though the RFC doesn't exclude all of them,
    because we follow the spirit of RFC 5322.

    """
    m = _non_token_end_matcher(value)
    if not m:
        raise errors.HeaderParseError(
            "expected ttext but found '{}'".format(value))
    ttext = m.group()
    value = value[len(ttext):]
    ttext = ValueTerminal(ttext, 'ttext')
    _validate_xtext(ttext)
    return ttext, value

def get_token(value):
    """token = [CFWS] 1*ttext [CFWS]

    The RFC equivalent of ttext is any US-ASCII chars except space, ctls, or
    tspecials.  We also exclude tabs even though the RFC doesn't.

    The RFC implies the CFWS but is not explicit about it in the BNF.

    """
    mtoken = Token()
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        mtoken.append(token)
    if value and value[0] in TOKEN_ENDS:
        raise errors.HeaderParseError(
            "expected token but found '{}'".format(value))
    token, value = get_ttext(value)
    mtoken.append(token)
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        mtoken.append(token)
    return mtoken, value

def get_attrtext(value):
    """attrtext = 1*(any non-ATTRIBUTE_ENDS character)

    We allow any non-ATTRIBUTE_ENDS in attrtext, but add defects to the
    token's defects list if we find non-attrtext characters.  We also register
    defects for *any* non-printables even though the RFC doesn't exclude all of
    them, because we follow the spirit of RFC 5322.

    """
    m = _non_attribute_end_matcher(value)
    if not m:
        raise errors.HeaderParseError(
            "expected attrtext but found {!r}".format(value))
    attrtext = m.group()
    value = value[len(attrtext):]
    attrtext = ValueTerminal(attrtext, 'attrtext')
    _validate_xtext(attrtext)
    return attrtext, value

def get_attribute(value):
    """ [CFWS] 1*attrtext [CFWS]

    This version of the BNF makes the CFWS explicit, and as usual we use a
    value terminal for the actual run of characters.  The RFC equivalent of
    attrtext is the token characters, with the subtraction of '*', "'", and '%'.
    We include tab in the excluded set just as we do for token.

    """
    attribute = Attribute()
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        attribute.append(token)
    if value and value[0] in ATTRIBUTE_ENDS:
        raise errors.HeaderParseError(
            "expected token but found '{}'".format(value))
    token, value = get_attrtext(value)
    attribute.append(token)
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        attribute.append(token)
    return attribute, value

def get_extended_attrtext(value):
    """attrtext = 1*(any non-ATTRIBUTE_ENDS character plus '%')

    This is a special parsing routine so that we get a value that
    includes % escapes as a single string (which we decode as a single
    string later).

    """
    m = _non_extended_attribute_end_matcher(value)
    if not m:
        raise errors.HeaderParseError(
            "expected extended attrtext but found {!r}".format(value))
    attrtext = m.group()
    value = value[len(attrtext):]
    attrtext = ValueTerminal(attrtext, 'extended-attrtext')
    _validate_xtext(attrtext)
    return attrtext, value

def get_extended_attribute(value):
    """ [CFWS] 1*extended_attrtext [CFWS]

    This is like the non-extended version except we allow % characters, so that
    we can pick up an encoded value as a single string.

    """
    # XXX: should we have an ExtendedAttribute TokenList?
    attribute = Attribute()
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        attribute.append(token)
    if value and value[0] in EXTENDED_ATTRIBUTE_ENDS:
        raise errors.HeaderParseError(
            "expected token but found '{}'".format(value))
    token, value = get_extended_attrtext(value)
    attribute.append(token)
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        attribute.append(token)
    return attribute, value

def get_section(value):
    """ '*' digits

    The formal BNF is more complicated because leading 0s are not allowed.  We
    check for that and add a defect.  We also assume no CFWS is allowed between
    the '*' and the digits, though the RFC is not crystal clear on that.
    The caller should already have dealt with leading CFWS.

    """
    section = Section()
    if not value or value[0] != '*':
        raise errors.HeaderParseError("Expected section but found {}".format(
                                        value))
    section.append(ValueTerminal('*', 'section-marker'))
    value = value[1:]
    if not value or not value[0].isdigit():
        raise errors.HeaderParseError("Expected section number but "
                                      "found {}".format(value))
    digits = ''
    while value and value[0].isdigit():
        digits += value[0]
        value = value[1:]
    if digits[0] == '0' and digits != '0':
        section.defects.append(errors.InvalidHeaderDefect(
                "section number has an invalid leading 0"))
    section.number = int(digits)
    section.append(ValueTerminal(digits, 'digits'))
    return section, value


def get_value(value):
    """ quoted-string / attribute

    """
    v = Value()
    if not value:
        raise errors.HeaderParseError("Expected value but found end of string")
    leader = None
    if value[0] in CFWS_LEADER:
        leader, value = get_cfws(value)
    if not value:
        raise errors.HeaderParseError("Expected value but found "
                                      "only {}".format(leader))
    if value[0] == '"':
        token, value = get_quoted_string(value)
    else:
        token, value = get_extended_attribute(value)
    if leader is not None:
        token[:0] = [leader]
    v.append(token)
    return v, value

def get_parameter(value):
    """ attribute [section] ["*"] [CFWS] "=" value

    The CFWS is implied by the RFC but not made explicit in the BNF.  This
    simplified form of the BNF from the RFC is made to conform with the RFC BNF
    through some extra checks.  We do it this way because it makes both error
    recovery and working with the resulting parse tree easier.
    """
    # It is possible CFWS would also be implicitly allowed between the section
    # and the 'extended-attribute' marker (the '*') , but we've never seen that
    # in the wild and we will therefore ignore the possibility.
    param = Parameter()
    token, value = get_attribute(value)
    param.append(token)
    if not value or value[0] == ';':
        param.defects.append(errors.InvalidHeaderDefect("Parameter contains "
            "name ({}) but no value".format(token)))
        return param, value
    if value[0] == '*':
        try:
            token, value = get_section(value)
            param.sectioned = True
            param.append(token)
        except errors.HeaderParseError:
            pass
        if not value:
            raise errors.HeaderParseError("Incomplete parameter")
        if value[0] == '*':
            param.append(ValueTerminal('*', 'extended-parameter-marker'))
            value = value[1:]
            param.extended = True
    if value[0] != '=':
        raise errors.HeaderParseError("Parameter not followed by '='")
    param.append(ValueTerminal('=', 'parameter-separator'))
    value = value[1:]
    if value and value[0] in CFWS_LEADER:
        token, value = get_cfws(value)
        param.append(token)
    remainder = None
    appendto = param
    if param.extended and value and value[0] == '"':
        # Now for some serious hackery to handle the common invalid case of
        # double quotes around an extended value.  We also accept (with defect)
        # a value marked as encoded that isn't really.
        qstring, remainder = get_quoted_string(value)
        inner_value = qstring.stripped_value
        semi_valid = False
        if param.section_number == 0:
            if inner_value and inner_value[0] == "'":
                semi_valid = True
            else:
                token, rest = get_attrtext(inner_value)
                if rest and rest[0] == "'":
                    semi_valid = True
        else:
            try:
                token, rest = get_extended_attrtext(inner_value)
            except:
                pass
            else:
                if not rest:
                    semi_valid = True
        if semi_valid:
            param.defects.append(errors.InvalidHeaderDefect(
                "Quoted string value for extended parameter is invalid"))
            param.append(qstring)
            for t in qstring:
                if t.token_type == 'bare-quoted-string':
                    t[:] = []
                    appendto = t
                    break
            value = inner_value
        else:
            remainder = None
            param.defects.append(errors.InvalidHeaderDefect(
                "Parameter marked as extended but appears to have a "
                "quoted string value that is non-encoded"))
    if value and value[0] == "'":
        token = None
    else:
        token, value = get_value(value)
    if not param.extended or param.section_number > 0:
        if not value or value[0] != "'":
            appendto.append(token)
            if remainder is not None:
                assert not value, value
                value = remainder
            return param, value
        param.defects.append(errors.InvalidHeaderDefect(
            "Apparent initial-extended-value but attribute "
            "was not marked as extended or was not initial section"))
    if not value:
        # Assume the charset/lang is missing and the token is the value.
        param.defects.append(errors.InvalidHeaderDefect(
            "Missing required charset/lang delimiters"))
        appendto.append(token)
        if remainder is None:
            return param, value
    else:
        if token is not None:
            for t in token:
                if t.token_type == 'extended-attrtext':
                    break
            t.token_type == 'attrtext'
            appendto.append(t)
            param.charset = t.value
        if value[0] != "'":
            raise errors.HeaderParseError("Expected RFC2231 char/lang encoding "
                                          "delimiter, but found {!r}".format(value))
        appendto.append(ValueTerminal("'", 'RFC2231-delimiter'))
        value = value[1:]
        if value and value[0] != "'":
            token, value = get_attrtext(value)
            appendto.append(token)
            param.lang = token.value
            if not value or value[0] != "'":
                raise errors.HeaderParseError("Expected RFC2231 char/lang encoding "
                                  "delimiter, but found {}".format(value))
        appendto.append(ValueTerminal("'", 'RFC2231-delimiter'))
        value = value[1:]
    if remainder is not None:
        # Treat the rest of value as bare quoted string content.
        v = Value()
        while value:
            if value[0] in WSP:
                token, value = get_fws(value)
            elif value[0] == '"':
                token = ValueTerminal('"', 'DQUOTE')
                value = value[1:]
            else:
                token, value = get_qcontent(value)
            v.append(token)
        token = v
    else:
        token, value = get_value(value)
    appendto.append(token)
    if remainder is not None:
        assert not value, value
        value = remainder
    return param, value

def parse_mime_parameters(value):
    """ parameter *( ";" parameter )

    That BNF is meant to indicate this routine should only be called after
    finding and handling the leading ';'.  There is no corresponding rule in
    the formal RFC grammar, but it is more convenient for us for the set of
    parameters to be treated as its own TokenList.

    This is 'parse' routine because it consumes the remaining value, but it
    would never be called to parse a full header.  Instead it is called to
    parse everything after the non-parameter value of a specific MIME header.

    """
    mime_parameters = MimeParameters()
    while value:
        try:
            token, value = get_parameter(value)
            mime_parameters.append(token)
        except errors.HeaderParseError:
            leader = None
            if value[0] in CFWS_LEADER:
                leader, value = get_cfws(value)
            if not value:
                mime_parameters.append(leader)
                return mime_parameters
            if value[0] == ';':
                if leader is not None:
                    mime_parameters.append(leader)
                mime_parameters.defects.append(errors.InvalidHeaderDefect(
                    "parameter entry with no content"))
            else:
                token, value = get_invalid_parameter(value)
                if leader:
                    token[:0] = [leader]
                mime_parameters.append(token)
                mime_parameters.defects.append(errors.InvalidHeaderDefect(
                    "invalid parameter {!r}".format(token)))
        if value and value[0] != ';':
            # Junk after the otherwise valid parameter.  Mark it as
            # invalid, but it will have a value.
            param = mime_parameters[-1]
            param.token_type = 'invalid-parameter'
            token, value = get_invalid_parameter(value)
            param.extend(token)
            mime_parameters.defects.append(errors.InvalidHeaderDefect(
                "parameter with invalid trailing text {!r}".format(token)))
        if value:
            # Must be a ';' at this point.
            mime_parameters.append(ValueTerminal(';', 'parameter-separator'))
            value = value[1:]
    return mime_parameters

def _find_mime_parameters(tokenlist, value):
    """Do our best to find the parameters in an invalid MIME header

    """
    while value and value[0] != ';':
        if value[0] in PHRASE_ENDS:
            tokenlist.append(ValueTerminal(value[0], 'misplaced-special'))
            value = value[1:]
        else:
            token, value = get_phrase(value)
            tokenlist.append(token)
    if not value:
        return
    tokenlist.append(ValueTerminal(';', 'parameter-separator'))
    tokenlist.append(parse_mime_parameters(value[1:]))

def parse_content_type_header(value):
    """ maintype "/" subtype *( ";" parameter )

    The maintype and substype are tokens.  Theoretically they could
    be checked against the official IANA list + x-token, but we
    don't do that.
    """
    ctype = ContentType()
    if not value:
        ctype.defects.append(errors.HeaderMissingRequiredValue(
            "Missing content type specification"))
        return ctype
    try:
        token, value = get_token(value)
    except errors.HeaderParseError:
        ctype.defects.append(errors.InvalidHeaderDefect(
            "Expected content maintype but found {!r}".format(value)))
        _find_mime_parameters(ctype, value)
        return ctype
    ctype.append(token)
    # XXX: If we really want to follow the formal grammar we should make
    # mantype and subtype specialized TokenLists here.  Probably not worth it.
    if not value or value[0] != '/':
        ctype.defects.append(errors.InvalidHeaderDefect(
            "Invalid content type"))
        if value:
            _find_mime_parameters(ctype, value)
        return ctype
    ctype.maintype = token.value.strip().lower()
    ctype.append(ValueTerminal('/', 'content-type-separator'))
    value = value[1:]
    try:
        token, value = get_token(value)
    except errors.HeaderParseError:
        ctype.defects.append(errors.InvalidHeaderDefect(
            "Expected content subtype but found {!r}".format(value)))
        _find_mime_parameters(ctype, value)
        return ctype
    ctype.append(token)
    ctype.subtype = token.value.strip().lower()
    if not value:
        return ctype
    if value[0] != ';':
        ctype.defects.append(errors.InvalidHeaderDefect(
            "Only parameters are valid after content type, but "
            "found {!r}".format(value)))
        # The RFC requires that a syntactically invalid content-type be treated
        # as text/plain.  Perhaps we should postel this, but we should probably
        # only do that if we were checking the subtype value against IANA.
        del ctype.maintype, ctype.subtype
        _find_mime_parameters(ctype, value)
        return ctype
    ctype.append(ValueTerminal(';', 'parameter-separator'))
    ctype.append(parse_mime_parameters(value[1:]))
    return ctype

def parse_content_disposition_header(value):
    """ disposition-type *( ";" parameter )

    """
    disp_header = ContentDisposition()
    if not value:
        disp_header.defects.append(errors.HeaderMissingRequiredValue(
            "Missing content disposition"))
        return disp_header
    try:
        token, value = get_token(value)
    except errors.HeaderParseError:
        disp_header.defects.append(errors.InvalidHeaderDefect(
            "Expected content disposition but found {!r}".format(value)))
        _find_mime_parameters(disp_header, value)
        return disp_header
    disp_header.append(token)
    disp_header.content_disposition = token.value.strip().lower()
    if not value:
        return disp_header
    if value[0] != ';':
        disp_header.defects.append(errors.InvalidHeaderDefect(
            "Only parameters are valid after content disposition, but "
            "found {!r}".format(value)))
        _find_mime_parameters(disp_header, value)
        return disp_header
    disp_header.append(ValueTerminal(';', 'parameter-separator'))
    disp_header.append(parse_mime_parameters(value[1:]))
    return disp_header

def parse_content_transfer_encoding_header(value):
    """ mechanism

    """
    # We should probably validate the values, since the list is fixed.
    cte_header = ContentTransferEncoding()
    if not value:
        cte_header.defects.append(errors.HeaderMissingRequiredValue(
            "Missing content transfer encoding"))
        return cte_header
    try:
        token, value = get_token(value)
    except errors.HeaderParseError:
        cte_header.defects.append(errors.InvalidHeaderDefect(
            "Expected content transfer encoding but found {!r}".format(value)))
    else:
        cte_header.append(token)
        cte_header.cte = token.value.strip().lower()
    if not value:
        return cte_header
    while value:
        cte_header.defects.append(errors.InvalidHeaderDefect(
            "Extra text after content transfer encoding"))
        if value[0] in PHRASE_ENDS:
            cte_header.append(ValueTerminal(value[0], 'misplaced-special'))
            value = value[1:]
        else:
            token, value = get_phrase(value)
            cte_header.append(token)
    return cte_header


#
# Header folding
#
# Header folding is complex, with lots of rules and corner cases.  The
# following code does its best to obey the rules and handle the corner
# cases, but you can be sure there are few bugs:)
#
# This folder generally canonicalizes as it goes, preferring the stringified
# version of each token.  The tokens contain information that supports the
# folder, including which tokens can be encoded in which ways.
#
# Folded text is accumulated in a simple list of strings ('lines'), each
# one of which should be less than policy.max_line_length ('maxlen').
#

def _steal_trailing_WSP_if_exists(lines):
    wsp = ''
    if lines and lines[-1] and lines[-1][-1] in WSP:
        wsp = lines[-1][-1]
        lines[-1] = lines[-1][:-1]
    return wsp

def _refold_parse_tree(parse_tree, *, policy):
    """Return string of contents of parse_tree folded according to RFC rules.

    """
    # max_line_length 0/None means no limit, ie: infinitely long.
    maxlen = policy.max_line_length or sys.maxsize
    encoding = 'utf-8' if policy.utf8 else 'us-ascii'
    lines = ['']  # Folded lines to be output
    leading_whitespace = ''  # When we have whitespace between two encoded
                             # words, we may need to encode the whitespace
                             # at the beginning of the second word.
    last_ew = None  # Points to the last encoded character if there's an ew on
                    # the line
    last_charset = None
    wrap_as_ew_blocked = 0
    want_encoding = False  # This is set to True if we need to encode this part
    end_ew_not_allowed = Terminal('', 'wrap_as_ew_blocked')
    parts = list(parse_tree)
    while parts:
        part = parts.pop(0)
        if part is end_ew_not_allowed:
            wrap_as_ew_blocked -= 1
            continue
        tstr = str(part)
        if not want_encoding:
            if part.token_type in ('ptext', 'vtext'):
                # Encode if tstr contains special characters.
                want_encoding = not SPECIALSNL.isdisjoint(tstr)
            else:
                # Encode if tstr contains newlines.
                want_encoding = not NLSET.isdisjoint(tstr)
        try:
            tstr.encode(encoding)
            charset = encoding
        except UnicodeEncodeError:
            if any(isinstance(x, errors.UndecodableBytesDefect)
                   for x in part.all_defects):
                charset = 'unknown-8bit'
            else:
                # If policy.utf8 is false this should really be taken from a
                # 'charset' property on the policy.
                charset = 'utf-8'
            want_encoding = True

        if part.token_type == 'mime-parameters':
            # Mime parameter folding (using RFC2231) is extra special.
            _fold_mime_parameters(part, lines, maxlen, encoding)
            continue

        if want_encoding and not wrap_as_ew_blocked:
            if not part.as_ew_allowed:
                want_encoding = False
                last_ew = None
                if part.syntactic_break:
                    encoded_part = part.fold(policy=policy)[:-len(policy.linesep)]
                    if policy.linesep not in encoded_part:
                        # It fits on a single line
                        if len(encoded_part) > maxlen - len(lines[-1]):
                            # But not on this one, so start a new one.
                            newline = _steal_trailing_WSP_if_exists(lines)
                            # XXX what if encoded_part has no leading FWS?
                            lines.append(newline)
                        lines[-1] += encoded_part
                        continue
                # Either this is not a major syntactic break, so we don't
                # want it on a line by itself even if it fits, or it
                # doesn't fit on a line by itself.  Either way, fall through
                # to unpacking the subparts and wrapping them.
            if not hasattr(part, 'encode'):
                # It's not a Terminal, do each piece individually.
                parts = list(part) + parts
                want_encoding = False
                continue
            elif part.as_ew_allowed:
                # It's a terminal, wrap it as an encoded word, possibly
                # combining it with previously encoded words if allowed.
                if (last_ew is not None and
                    charset != last_charset and
                    (last_charset == 'unknown-8bit' or
                     last_charset == 'utf-8' and charset != 'us-ascii')):
                    last_ew = None
                last_ew = _fold_as_ew(tstr, lines, maxlen, last_ew,
                                      part.ew_combine_allowed, charset, leading_whitespace)
                # This whitespace has been added to the lines in _fold_as_ew()
                # so clear it now.
                leading_whitespace = ''
                last_charset = charset
                want_encoding = False
                continue
            else:
                # It's a terminal which should be kept non-encoded
                # (e.g. a ListSeparator).
                last_ew = None
                want_encoding = False
                # fall through

        if len(tstr) <= maxlen - len(lines[-1]):
            lines[-1] += tstr
            continue

        # This part is too long to fit.  The RFC wants us to break at
        # "major syntactic breaks", so unless we don't consider this
        # to be one, check if it will fit on the next line by itself.
        leading_whitespace = ''
        if (part.syntactic_break and
                len(tstr) + 1 <= maxlen):
            newline = _steal_trailing_WSP_if_exists(lines)
            if newline or part.startswith_fws():
                # We're going to fold the data onto a new line here.  Due to
                # the way encoded strings handle continuation lines, we need to
                # be prepared to encode any whitespace if the next line turns
                # out to start with an encoded word.
                lines.append(newline + tstr)

                whitespace_accumulator = []
                for char in lines[-1]:
                    if char not in WSP:
                        break
                    whitespace_accumulator.append(char)
                leading_whitespace = ''.join(whitespace_accumulator)
                last_ew = None
                continue
        if not hasattr(part, 'encode'):
            # It's not a terminal, try folding the subparts.
            newparts = list(part)
            if part.token_type == 'bare-quoted-string':
                # To fold a quoted string we need to create a list of terminal
                # tokens that will render the leading and trailing quotes
                # and use quoted pairs in the value as appropriate.
                newparts = (
                    [ValueTerminal('"', 'ptext')] +
                    [ValueTerminal(make_quoted_pairs(p), 'ptext')
                     for p in newparts] +
                    [ValueTerminal('"', 'ptext')])
            if not part.as_ew_allowed:
                wrap_as_ew_blocked += 1
                newparts.append(end_ew_not_allowed)
            parts = newparts + parts
            continue
        if part.as_ew_allowed and not wrap_as_ew_blocked:
            # It doesn't need CTE encoding, but encode it anyway so we can
            # wrap it.
            parts.insert(0, part)
            want_encoding = True
            continue
        # We can't figure out how to wrap, it, so give up.
        newline = _steal_trailing_WSP_if_exists(lines)
        if newline or part.startswith_fws():
            lines.append(newline + tstr)
        else:
            # We can't fold it onto the next line either...
            lines[-1] += tstr

    return policy.linesep.join(lines) + policy.linesep

def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset, leading_whitespace):
    """Fold string to_encode into lines as encoded word, combining if allowed.
    Return the new value for last_ew, or None if ew_combine_allowed is False.

    If there is already an encoded word in the last line of lines (indicated by
    a non-None value for last_ew) and ew_combine_allowed is true, decode the
    existing ew, combine it with to_encode, and re-encode.  Otherwise, encode
    to_encode.  In either case, split to_encode as necessary so that the
    encoded segments fit within maxlen.

    """
    if last_ew is not None and ew_combine_allowed:
        to_encode = str(
            get_unstructured(lines[-1][last_ew:] + to_encode))
        lines[-1] = lines[-1][:last_ew]
    elif to_encode[0] in WSP:
        # We're joining this to non-encoded text, so don't encode
        # the leading blank.
        leading_wsp = to_encode[0]
        to_encode = to_encode[1:]
        if (len(lines[-1]) == maxlen):
            lines.append(_steal_trailing_WSP_if_exists(lines))
        lines[-1] += leading_wsp

    trailing_wsp = ''
    if to_encode[-1] in WSP:
        # Likewise for the trailing space.
        trailing_wsp = to_encode[-1]
        to_encode = to_encode[:-1]
    new_last_ew = len(lines[-1]) if last_ew is None else last_ew

    encode_as = 'utf-8' if charset == 'us-ascii' else charset

    # The RFC2047 chrome takes up 7 characters plus the length
    # of the charset name.
    chrome_len = len(encode_as) + 7

    if (chrome_len + 1) >= maxlen:
        raise errors.HeaderParseError(
            "max_line_length is too small to fit an encoded word")

    while to_encode:
        remaining_space = maxlen - len(lines[-1])
        text_space = remaining_space - chrome_len - len(leading_whitespace)
        if text_space <= 0:
            lines.append(' ')
            continue

        # If we are at the start of a continuation line, prepend whitespace
        # (we only want to do this when the line starts with an encoded word
        # but if we're folding in this helper function, then we know that we
        # are going to be writing out an encoded word.)
        if len(lines) > 1 and len(lines[-1]) == 1 and leading_whitespace:
            encoded_word = _ew.encode(leading_whitespace, charset=encode_as)
            lines[-1] += encoded_word
            leading_whitespace = ''

        to_encode_word = to_encode[:text_space]
        encoded_word = _ew.encode(to_encode_word, charset=encode_as)
        excess = len(encoded_word) - remaining_space
        while excess > 0:
            # Since the chunk to encode is guaranteed to fit into less than 100 characters,
            # shrinking it by one at a time shouldn't take long.
            to_encode_word = to_encode_word[:-1]
            encoded_word = _ew.encode(to_encode_word, charset=encode_as)
            excess = len(encoded_word) - remaining_space
        lines[-1] += encoded_word
        to_encode = to_encode[len(to_encode_word):]
        leading_whitespace = ''

        if to_encode:
            lines.append(' ')
            new_last_ew = len(lines[-1])
    lines[-1] += trailing_wsp
    return new_last_ew if ew_combine_allowed else None

def _fold_mime_parameters(part, lines, maxlen, encoding):
    """Fold TokenList 'part' into the 'lines' list as mime parameters.

    Using the decoded list of parameters and values, format them according to
    the RFC rules, including using RFC2231 encoding if the value cannot be
    expressed in 'encoding' and/or the parameter+value is too long to fit
    within 'maxlen'.

    """
    # Special case for RFC2231 encoding: start from decoded values and use
    # RFC2231 encoding iff needed.
    #
    # Note that the 1 and 2s being added to the length calculations are
    # accounting for the possibly-needed spaces and semicolons we'll be adding.
    #
    for name, value in part.params:
        # XXX What if this ';' puts us over maxlen the first time through the
        # loop?  We should split the header value onto a newline in that case,
        # but to do that we need to recognize the need earlier or reparse the
        # header, so I'm going to ignore that bug for now.  It'll only put us
        # one character over.
        if not lines[-1].rstrip().endswith(';'):
            lines[-1] += ';'
        charset = encoding
        error_handler = 'strict'
        try:
            value.encode(encoding)
            encoding_required = False
        except UnicodeEncodeError:
            encoding_required = True
            if utils._has_surrogates(value):
                charset = 'unknown-8bit'
                error_handler = 'surrogateescape'
            else:
                charset = 'utf-8'
        if encoding_required:
            encoded_value = urllib.parse.quote(
                value, safe='', errors=error_handler)
            tstr = "{}*={}''{}".format(name, charset, encoded_value)
        else:
            tstr = '{}={}'.format(name, quote_string(value))
        if len(lines[-1]) + len(tstr) + 1 < maxlen:
            lines[-1] = lines[-1] + ' ' + tstr
            continue
        elif len(tstr) + 2 <= maxlen:
            lines.append(' ' + tstr)
            continue
        # We need multiple sections.  We are allowed to mix encoded and
        # non-encoded sections, but we aren't going to.  We'll encode them all.
        section = 0
        extra_chrome = charset + "''"
        while value:
            chrome_len = len(name) + len(str(section)) + 3 + len(extra_chrome)
            if maxlen <= chrome_len + 3:
                # We need room for the leading blank, the trailing semicolon,
                # and at least one character of the value.  If we don't
                # have that, we'd be stuck, so in that case fall back to
                # the RFC standard width.
                maxlen = 78
            splitpoint = maxchars = maxlen - chrome_len - 2
            while True:
                partial = value[:splitpoint]
                encoded_value = urllib.parse.quote(
                    partial, safe='', errors=error_handler)
                if len(encoded_value) <= maxchars:
                    break
                splitpoint -= 1
            lines.append(" {}*{}*={}{}".format(
                name, section, extra_chrome, encoded_value))
            extra_chrome = ''
            section += 1
            value = value[splitpoint:]
            if value:
                lines[-1] += ';'
_parseaddr.py000064400000042635151706203570007242 0ustar00# Copyright (C) 2002-2007 Python Software Foundation
# Contact: email-sig@python.org

"""Email address parsing code.

Lifted directly from rfc822.py.  This should eventually be rewritten.
"""

__all__ = [
    'mktime_tz',
    'parsedate',
    'parsedate_tz',
    'quote',
    ]

import time, calendar

SPACE = ' '
EMPTYSTRING = ''
COMMASPACE = ', '

# Parse a date field
_monthnames = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul',
               'aug', 'sep', 'oct', 'nov', 'dec',
               'january', 'february', 'march', 'april', 'may', 'june', 'july',
               'august', 'september', 'october', 'november', 'december']

_daynames = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']

# The timezone table does not include the military time zones defined
# in RFC822, other than Z.  According to RFC1123, the description in
# RFC822 gets the signs wrong, so we can't rely on any such time
# zones.  RFC1123 recommends that numeric timezone indicators be used
# instead of timezone names.

_timezones = {'UT':0, 'UTC':0, 'GMT':0, 'Z':0,
              'AST': -400, 'ADT': -300,  # Atlantic (used in Canada)
              'EST': -500, 'EDT': -400,  # Eastern
              'CST': -600, 'CDT': -500,  # Central
              'MST': -700, 'MDT': -600,  # Mountain
              'PST': -800, 'PDT': -700   # Pacific
              }


def parsedate_tz(data):
    """Convert a date string to a time tuple.

    Accounts for military timezones.
    """
    res = _parsedate_tz(data)
    if not res:
        return
    if res[9] is None:
        res[9] = 0
    return tuple(res)

def _parsedate_tz(data):
    """Convert date to extended time tuple.

    The last (additional) element is the time zone offset in seconds, except if
    the timezone was specified as -0000.  In that case the last element is
    None.  This indicates a UTC timestamp that explicitly declaims knowledge of
    the source timezone, as opposed to a +0000 timestamp that indicates the
    source timezone really was UTC.

    """
    if not data:
        return None
    data = data.split()
    if not data:  # This happens for whitespace-only input.
        return None
    # The FWS after the comma after the day-of-week is optional, so search and
    # adjust for this.
    if data[0].endswith(',') or data[0].lower() in _daynames:
        # There's a dayname here. Skip it
        del data[0]
    else:
        i = data[0].rfind(',')
        if i >= 0:
            data[0] = data[0][i+1:]
    if len(data) == 3: # RFC 850 date, deprecated
        stuff = data[0].split('-')
        if len(stuff) == 3:
            data = stuff + data[1:]
    if len(data) == 4:
        s = data[3]
        i = s.find('+')
        if i == -1:
            i = s.find('-')
        if i > 0:
            data[3:] = [s[:i], s[i:]]
        else:
            data.append('') # Dummy tz
    if len(data) < 5:
        return None
    data = data[:5]
    [dd, mm, yy, tm, tz] = data
    if not (dd and mm and yy):
        return None
    mm = mm.lower()
    if mm not in _monthnames:
        dd, mm = mm, dd.lower()
        if mm not in _monthnames:
            return None
    mm = _monthnames.index(mm) + 1
    if mm > 12:
        mm -= 12
    if dd[-1] == ',':
        dd = dd[:-1]
    i = yy.find(':')
    if i > 0:
        yy, tm = tm, yy
    if yy[-1] == ',':
        yy = yy[:-1]
        if not yy:
            return None
    if not yy[0].isdigit():
        yy, tz = tz, yy
    if tm[-1] == ',':
        tm = tm[:-1]
    tm = tm.split(':')
    if len(tm) == 2:
        [thh, tmm] = tm
        tss = '0'
    elif len(tm) == 3:
        [thh, tmm, tss] = tm
    elif len(tm) == 1 and '.' in tm[0]:
        # Some non-compliant MUAs use '.' to separate time elements.
        tm = tm[0].split('.')
        if len(tm) == 2:
            [thh, tmm] = tm
            tss = 0
        elif len(tm) == 3:
            [thh, tmm, tss] = tm
        else:
            return None
    else:
        return None
    try:
        yy = int(yy)
        dd = int(dd)
        thh = int(thh)
        tmm = int(tmm)
        tss = int(tss)
    except ValueError:
        return None
    # Check for a yy specified in two-digit format, then convert it to the
    # appropriate four-digit format, according to the POSIX standard. RFC 822
    # calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822)
    # mandates a 4-digit yy. For more information, see the documentation for
    # the time module.
    if yy < 100:
        # The year is between 1969 and 1999 (inclusive).
        if yy > 68:
            yy += 1900
        # The year is between 2000 and 2068 (inclusive).
        else:
            yy += 2000
    tzoffset = None
    tz = tz.upper()
    if tz in _timezones:
        tzoffset = _timezones[tz]
    else:
        try:
            tzoffset = int(tz)
        except ValueError:
            pass
        if tzoffset==0 and tz.startswith('-'):
            tzoffset = None
    # Convert a timezone offset into seconds ; -0500 -> -18000
    if tzoffset:
        if tzoffset < 0:
            tzsign = -1
            tzoffset = -tzoffset
        else:
            tzsign = 1
        tzoffset = tzsign * ( (tzoffset//100)*3600 + (tzoffset % 100)*60)
    # Daylight Saving Time flag is set to -1, since DST is unknown.
    return [yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset]


def parsedate(data):
    """Convert a time string to a time tuple."""
    t = parsedate_tz(data)
    if isinstance(t, tuple):
        return t[:9]
    else:
        return t


def mktime_tz(data):
    """Turn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp."""
    if data[9] is None:
        # No zone info, so localtime is better assumption than GMT
        return time.mktime(data[:8] + (-1,))
    else:
        t = calendar.timegm(data)
        return t - data[9]


def quote(str):
    """Prepare string to be used in a quoted string.

    Turns backslash and double quote characters into quoted pairs.  These
    are the only characters that need to be quoted inside a quoted string.
    Does not add the surrounding double quotes.
    """
    return str.replace('\\', '\\\\').replace('"', '\\"')


class AddrlistClass:
    """Address parser class by Ben Escoto.

    To understand what this class does, it helps to have a copy of RFC 2822 in
    front of you.

    Note: this class interface is deprecated and may be removed in the future.
    Use email.utils.AddressList instead.
    """

    def __init__(self, field):
        """Initialize a new instance.

        `field' is an unparsed address header field, containing
        one or more addresses.
        """
        self.specials = '()<>@,:;.\"[]'
        self.pos = 0
        self.LWS = ' \t'
        self.CR = '\r\n'
        self.FWS = self.LWS + self.CR
        self.atomends = self.specials + self.LWS + self.CR
        # Note that RFC 2822 now specifies `.' as obs-phrase, meaning that it
        # is obsolete syntax.  RFC 2822 requires that we recognize obsolete
        # syntax, so allow dots in phrases.
        self.phraseends = self.atomends.replace('.', '')
        self.field = field
        self.commentlist = []

    def gotonext(self):
        """Skip white space and extract comments."""
        wslist = []
        while self.pos < len(self.field):
            if self.field[self.pos] in self.LWS + '\n\r':
                if self.field[self.pos] not in '\n\r':
                    wslist.append(self.field[self.pos])
                self.pos += 1
            elif self.field[self.pos] == '(':
                self.commentlist.append(self.getcomment())
            else:
                break
        return EMPTYSTRING.join(wslist)

    def getaddrlist(self):
        """Parse all addresses.

        Returns a list containing all of the addresses.
        """
        result = []
        while self.pos < len(self.field):
            ad = self.getaddress()
            if ad:
                result += ad
            else:
                result.append(('', ''))
        return result

    def getaddress(self):
        """Parse the next address."""
        self.commentlist = []
        self.gotonext()

        oldpos = self.pos
        oldcl = self.commentlist
        plist = self.getphraselist()

        self.gotonext()
        returnlist = []

        if self.pos >= len(self.field):
            # Bad email address technically, no domain.
            if plist:
                returnlist = [(SPACE.join(self.commentlist), plist[0])]

        elif self.field[self.pos] in '.@':
            # email address is just an addrspec
            # this isn't very efficient since we start over
            self.pos = oldpos
            self.commentlist = oldcl
            addrspec = self.getaddrspec()
            returnlist = [(SPACE.join(self.commentlist), addrspec)]

        elif self.field[self.pos] == ':':
            # address is a group
            returnlist = []

            fieldlen = len(self.field)
            self.pos += 1
            while self.pos < len(self.field):
                self.gotonext()
                if self.pos < fieldlen and self.field[self.pos] == ';':
                    self.pos += 1
                    break
                returnlist = returnlist + self.getaddress()

        elif self.field[self.pos] == '<':
            # Address is a phrase then a route addr
            routeaddr = self.getrouteaddr()

            if self.commentlist:
                returnlist = [(SPACE.join(plist) + ' (' +
                               ' '.join(self.commentlist) + ')', routeaddr)]
            else:
                returnlist = [(SPACE.join(plist), routeaddr)]

        else:
            if plist:
                returnlist = [(SPACE.join(self.commentlist), plist[0])]
            elif self.field[self.pos] in self.specials:
                self.pos += 1

        self.gotonext()
        if self.pos < len(self.field) and self.field[self.pos] == ',':
            self.pos += 1
        return returnlist

    def getrouteaddr(self):
        """Parse a route address (Return-path value).

        This method just skips all the route stuff and returns the addrspec.
        """
        if self.field[self.pos] != '<':
            return

        expectroute = False
        self.pos += 1
        self.gotonext()
        adlist = ''
        while self.pos < len(self.field):
            if expectroute:
                self.getdomain()
                expectroute = False
            elif self.field[self.pos] == '>':
                self.pos += 1
                break
            elif self.field[self.pos] == '@':
                self.pos += 1
                expectroute = True
            elif self.field[self.pos] == ':':
                self.pos += 1
            else:
                adlist = self.getaddrspec()
                self.pos += 1
                break
            self.gotonext()

        return adlist

    def getaddrspec(self):
        """Parse an RFC 2822 addr-spec."""
        aslist = []

        self.gotonext()
        while self.pos < len(self.field):
            preserve_ws = True
            if self.field[self.pos] == '.':
                if aslist and not aslist[-1].strip():
                    aslist.pop()
                aslist.append('.')
                self.pos += 1
                preserve_ws = False
            elif self.field[self.pos] == '"':
                aslist.append('"%s"' % quote(self.getquote()))
            elif self.field[self.pos] in self.atomends:
                if aslist and not aslist[-1].strip():
                    aslist.pop()
                break
            else:
                aslist.append(self.getatom())
            ws = self.gotonext()
            if preserve_ws and ws:
                aslist.append(ws)

        if self.pos >= len(self.field) or self.field[self.pos] != '@':
            return EMPTYSTRING.join(aslist)

        aslist.append('@')
        self.pos += 1
        self.gotonext()
        domain = self.getdomain()
        if not domain:
            # Invalid domain, return an empty address instead of returning a
            # local part to denote failed parsing.
            return EMPTYSTRING
        return EMPTYSTRING.join(aslist) + domain

    def getdomain(self):
        """Get the complete domain name from an address."""
        sdlist = []
        while self.pos < len(self.field):
            if self.field[self.pos] in self.LWS:
                self.pos += 1
            elif self.field[self.pos] == '(':
                self.commentlist.append(self.getcomment())
            elif self.field[self.pos] == '[':
                sdlist.append(self.getdomainliteral())
            elif self.field[self.pos] == '.':
                self.pos += 1
                sdlist.append('.')
            elif self.field[self.pos] == '@':
                # bpo-34155: Don't parse domains with two `@` like
                # `a@malicious.org@important.com`.
                return EMPTYSTRING
            elif self.field[self.pos] in self.atomends:
                break
            else:
                sdlist.append(self.getatom())
        return EMPTYSTRING.join(sdlist)

    def getdelimited(self, beginchar, endchars, allowcomments=True):
        """Parse a header fragment delimited by special characters.

        `beginchar' is the start character for the fragment.
        If self is not looking at an instance of `beginchar' then
        getdelimited returns the empty string.

        `endchars' is a sequence of allowable end-delimiting characters.
        Parsing stops when one of these is encountered.

        If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed
        within the parsed fragment.
        """
        if self.field[self.pos] != beginchar:
            return ''

        slist = ['']
        quote = False
        self.pos += 1
        while self.pos < len(self.field):
            if quote:
                slist.append(self.field[self.pos])
                quote = False
            elif self.field[self.pos] in endchars:
                self.pos += 1
                break
            elif allowcomments and self.field[self.pos] == '(':
                slist.append(self.getcomment())
                continue        # have already advanced pos from getcomment
            elif self.field[self.pos] == '\\':
                quote = True
            else:
                slist.append(self.field[self.pos])
            self.pos += 1

        return EMPTYSTRING.join(slist)

    def getquote(self):
        """Get a quote-delimited fragment from self's field."""
        return self.getdelimited('"', '"\r', False)

    def getcomment(self):
        """Get a parenthesis-delimited fragment from self's field."""
        return self.getdelimited('(', ')\r', True)

    def getdomainliteral(self):
        """Parse an RFC 2822 domain-literal."""
        return '[%s]' % self.getdelimited('[', ']\r', False)

    def getatom(self, atomends=None):
        """Parse an RFC 2822 atom.

        Optional atomends specifies a different set of end token delimiters
        (the default is to use self.atomends).  This is used e.g. in
        getphraselist() since phrase endings must not include the `.' (which
        is legal in phrases)."""
        atomlist = ['']
        if atomends is None:
            atomends = self.atomends

        while self.pos < len(self.field):
            if self.field[self.pos] in atomends:
                break
            else:
                atomlist.append(self.field[self.pos])
            self.pos += 1

        return EMPTYSTRING.join(atomlist)

    def getphraselist(self):
        """Parse a sequence of RFC 2822 phrases.

        A phrase is a sequence of words, which are in turn either RFC 2822
        atoms or quoted-strings.  Phrases are canonicalized by squeezing all
        runs of continuous whitespace into one space.
        """
        plist = []

        while self.pos < len(self.field):
            if self.field[self.pos] in self.FWS:
                self.pos += 1
            elif self.field[self.pos] == '"':
                plist.append(self.getquote())
            elif self.field[self.pos] == '(':
                self.commentlist.append(self.getcomment())
            elif self.field[self.pos] in self.phraseends:
                break
            else:
                plist.append(self.getatom(self.phraseends))

        return plist

class AddressList(AddrlistClass):
    """An AddressList encapsulates a list of parsed RFC 2822 addresses."""
    def __init__(self, field):
        AddrlistClass.__init__(self, field)
        if field:
            self.addresslist = self.getaddrlist()
        else:
            self.addresslist = []

    def __len__(self):
        return len(self.addresslist)

    def __add__(self, other):
        # Set union
        newaddr = AddressList(None)
        newaddr.addresslist = self.addresslist[:]
        for x in other.addresslist:
            if not x in self.addresslist:
                newaddr.addresslist.append(x)
        return newaddr

    def __iadd__(self, other):
        # Set union, in-place
        for x in other.addresslist:
            if not x in self.addresslist:
                self.addresslist.append(x)
        return self

    def __sub__(self, other):
        # Set difference
        newaddr = AddressList(None)
        for x in self.addresslist:
            if not x in other.addresslist:
                newaddr.addresslist.append(x)
        return newaddr

    def __isub__(self, other):
        # Set difference, in-place
        for x in other.addresslist:
            if x in self.addresslist:
                self.addresslist.remove(x)
        return self

    def __getitem__(self, index):
        # Make indexing, slices, and 'in' work
        return self.addresslist[index]
_policybase.py000064400000036257151706203570007432 0ustar00"""Policy framework for the email package.

Allows fine grained feature control of how the package parses and emits data.
"""

import abc
from email import header
from email import charset as _charset
from email.utils import _has_surrogates

__all__ = [
    'Policy',
    'Compat32',
    'compat32',
    ]


class _PolicyBase:

    """Policy Object basic framework.

    This class is useless unless subclassed.  A subclass should define
    class attributes with defaults for any values that are to be
    managed by the Policy object.  The constructor will then allow
    non-default values to be set for these attributes at instance
    creation time.  The instance will be callable, taking these same
    attributes keyword arguments, and returning a new instance
    identical to the called instance except for those values changed
    by the keyword arguments.  Instances may be added, yielding new
    instances with any non-default values from the right hand
    operand overriding those in the left hand operand.  That is,

        A + B == A(<non-default values of B>)

    The repr of an instance can be used to reconstruct the object
    if and only if the repr of the values can be used to reconstruct
    those values.

    """

    def __init__(self, **kw):
        """Create new Policy, possibly overriding some defaults.

        See class docstring for a list of overridable attributes.

        """
        for name, value in kw.items():
            if hasattr(self, name):
                super(_PolicyBase,self).__setattr__(name, value)
            else:
                raise TypeError(
                    "{!r} is an invalid keyword argument for {}".format(
                        name, self.__class__.__name__))

    def __repr__(self):
        args = [ "{}={!r}".format(name, value)
                 for name, value in self.__dict__.items() ]
        return "{}({})".format(self.__class__.__name__, ', '.join(args))

    def clone(self, **kw):
        """Return a new instance with specified attributes changed.

        The new instance has the same attribute values as the current object,
        except for the changes passed in as keyword arguments.

        """
        newpolicy = self.__class__.__new__(self.__class__)
        for attr, value in self.__dict__.items():
            object.__setattr__(newpolicy, attr, value)
        for attr, value in kw.items():
            if not hasattr(self, attr):
                raise TypeError(
                    "{!r} is an invalid keyword argument for {}".format(
                        attr, self.__class__.__name__))
            object.__setattr__(newpolicy, attr, value)
        return newpolicy

    def __setattr__(self, name, value):
        if hasattr(self, name):
            msg = "{!r} object attribute {!r} is read-only"
        else:
            msg = "{!r} object has no attribute {!r}"
        raise AttributeError(msg.format(self.__class__.__name__, name))

    def __add__(self, other):
        """Non-default values from right operand override those from left.

        The object returned is a new instance of the subclass.

        """
        return self.clone(**other.__dict__)


def _append_doc(doc, added_doc):
    doc = doc.rsplit('\n', 1)[0]
    added_doc = added_doc.split('\n', 1)[1]
    return doc + '\n' + added_doc

def _extend_docstrings(cls):
    if cls.__doc__ and cls.__doc__.startswith('+'):
        cls.__doc__ = _append_doc(cls.__bases__[0].__doc__, cls.__doc__)
    for name, attr in cls.__dict__.items():
        if attr.__doc__ and attr.__doc__.startswith('+'):
            for c in (c for base in cls.__bases__ for c in base.mro()):
                doc = getattr(getattr(c, name), '__doc__')
                if doc:
                    attr.__doc__ = _append_doc(doc, attr.__doc__)
                    break
    return cls


class Policy(_PolicyBase, metaclass=abc.ABCMeta):

    r"""Controls for how messages are interpreted and formatted.

    Most of the classes and many of the methods in the email package accept
    Policy objects as parameters.  A Policy object contains a set of values and
    functions that control how input is interpreted and how output is rendered.
    For example, the parameter 'raise_on_defect' controls whether or not an RFC
    violation results in an error being raised or not, while 'max_line_length'
    controls the maximum length of output lines when a Message is serialized.

    Any valid attribute may be overridden when a Policy is created by passing
    it as a keyword argument to the constructor.  Policy objects are immutable,
    but a new Policy object can be created with only certain values changed by
    calling the Policy instance with keyword arguments.  Policy objects can
    also be added, producing a new Policy object in which the non-default
    attributes set in the right hand operand overwrite those specified in the
    left operand.

    Settable attributes:

    raise_on_defect     -- If true, then defects should be raised as errors.
                           Default: False.

    linesep             -- string containing the value to use as separation
                           between output lines.  Default '\n'.

    cte_type            -- Type of allowed content transfer encodings

                           7bit  -- ASCII only
                           8bit  -- Content-Transfer-Encoding: 8bit is allowed

                           Default: 8bit.  Also controls the disposition of
                           (RFC invalid) binary data in headers; see the
                           documentation of the binary_fold method.

    max_line_length     -- maximum length of lines, excluding 'linesep',
                           during serialization.  None or 0 means no line
                           wrapping is done.  Default is 78.

    mangle_from_        -- a flag that, when True escapes From_ lines in the
                           body of the message by putting a `>' in front of
                           them. This is used when the message is being
                           serialized by a generator. Default: False.

    message_factory     -- the class to use to create new message objects.
                           If the value is None, the default is Message.

    verify_generated_headers
                        -- if true, the generator verifies that each header
                           they are properly folded, so that a parser won't
                           treat it as multiple headers, start-of-body, or
                           part of another header.
                           This is a check against custom Header & fold()
                           implementations.
    """

    raise_on_defect = False
    linesep = '\n'
    cte_type = '8bit'
    max_line_length = 78
    mangle_from_ = False
    message_factory = None
    verify_generated_headers = True

    def handle_defect(self, obj, defect):
        """Based on policy, either raise defect or call register_defect.

            handle_defect(obj, defect)

        defect should be a Defect subclass, but in any case must be an
        Exception subclass.  obj is the object on which the defect should be
        registered if it is not raised.  If the raise_on_defect is True, the
        defect is raised as an error, otherwise the object and the defect are
        passed to register_defect.

        This method is intended to be called by parsers that discover defects.
        The email package parsers always call it with Defect instances.

        """
        if self.raise_on_defect:
            raise defect
        self.register_defect(obj, defect)

    def register_defect(self, obj, defect):
        """Record 'defect' on 'obj'.

        Called by handle_defect if raise_on_defect is False.  This method is
        part of the Policy API so that Policy subclasses can implement custom
        defect handling.  The default implementation calls the append method of
        the defects attribute of obj.  The objects used by the email package by
        default that get passed to this method will always have a defects
        attribute with an append method.

        """
        obj.defects.append(defect)

    def header_max_count(self, name):
        """Return the maximum allowed number of headers named 'name'.

        Called when a header is added to a Message object.  If the returned
        value is not 0 or None, and there are already a number of headers with
        the name 'name' equal to the value returned, a ValueError is raised.

        Because the default behavior of Message's __setitem__ is to append the
        value to the list of headers, it is easy to create duplicate headers
        without realizing it.  This method allows certain headers to be limited
        in the number of instances of that header that may be added to a
        Message programmatically.  (The limit is not observed by the parser,
        which will faithfully produce as many headers as exist in the message
        being parsed.)

        The default implementation returns None for all header names.
        """
        return None

    @abc.abstractmethod
    def header_source_parse(self, sourcelines):
        """Given a list of linesep terminated strings constituting the lines of
        a single header, return the (name, value) tuple that should be stored
        in the model.  The input lines should retain their terminating linesep
        characters.  The lines passed in by the email package may contain
        surrogateescaped binary data.
        """
        raise NotImplementedError

    @abc.abstractmethod
    def header_store_parse(self, name, value):
        """Given the header name and the value provided by the application
        program, return the (name, value) that should be stored in the model.
        """
        raise NotImplementedError

    @abc.abstractmethod
    def header_fetch_parse(self, name, value):
        """Given the header name and the value from the model, return the value
        to be returned to the application program that is requesting that
        header.  The value passed in by the email package may contain
        surrogateescaped binary data if the lines were parsed by a BytesParser.
        The returned value should not contain any surrogateescaped data.

        """
        raise NotImplementedError

    @abc.abstractmethod
    def fold(self, name, value):
        """Given the header name and the value from the model, return a string
        containing linesep characters that implement the folding of the header
        according to the policy controls.  The value passed in by the email
        package may contain surrogateescaped binary data if the lines were
        parsed by a BytesParser.  The returned value should not contain any
        surrogateescaped data.

        """
        raise NotImplementedError

    @abc.abstractmethod
    def fold_binary(self, name, value):
        """Given the header name and the value from the model, return binary
        data containing linesep characters that implement the folding of the
        header according to the policy controls.  The value passed in by the
        email package may contain surrogateescaped binary data.

        """
        raise NotImplementedError


@_extend_docstrings
class Compat32(Policy):

    """+
    This particular policy is the backward compatibility Policy.  It
    replicates the behavior of the email package version 5.1.
    """

    mangle_from_ = True

    def _sanitize_header(self, name, value):
        # If the header value contains surrogates, return a Header using
        # the unknown-8bit charset to encode the bytes as encoded words.
        if not isinstance(value, str):
            # Assume it is already a header object
            return value
        if _has_surrogates(value):
            return header.Header(value, charset=_charset.UNKNOWN8BIT,
                                 header_name=name)
        else:
            return value

    def header_source_parse(self, sourcelines):
        """+
        The name is parsed as everything up to the ':' and returned unmodified.
        The value is determined by stripping leading whitespace off the
        remainder of the first line joined with all subsequent lines, and
        stripping any trailing carriage return or linefeed characters.

        """
        name, value = sourcelines[0].split(':', 1)
        value = ''.join((value, *sourcelines[1:])).lstrip(' \t\r\n')
        return (name, value.rstrip('\r\n'))

    def header_store_parse(self, name, value):
        """+
        The name and value are returned unmodified.
        """
        return (name, value)

    def header_fetch_parse(self, name, value):
        """+
        If the value contains binary data, it is converted into a Header object
        using the unknown-8bit charset.  Otherwise it is returned unmodified.
        """
        return self._sanitize_header(name, value)

    def fold(self, name, value):
        """+
        Headers are folded using the Header folding algorithm, which preserves
        existing line breaks in the value, and wraps each resulting line to the
        max_line_length.  Non-ASCII binary data are CTE encoded using the
        unknown-8bit charset.

        """
        return self._fold(name, value, sanitize=True)

    def fold_binary(self, name, value):
        """+
        Headers are folded using the Header folding algorithm, which preserves
        existing line breaks in the value, and wraps each resulting line to the
        max_line_length.  If cte_type is 7bit, non-ascii binary data is CTE
        encoded using the unknown-8bit charset.  Otherwise the original source
        header is used, with its existing line breaks and/or binary data.

        """
        folded = self._fold(name, value, sanitize=self.cte_type=='7bit')
        return folded.encode('ascii', 'surrogateescape')

    def _fold(self, name, value, sanitize):
        parts = []
        parts.append('%s: ' % name)
        if isinstance(value, str):
            if _has_surrogates(value):
                if sanitize:
                    h = header.Header(value,
                                      charset=_charset.UNKNOWN8BIT,
                                      header_name=name)
                else:
                    # If we have raw 8bit data in a byte string, we have no idea
                    # what the encoding is.  There is no safe way to split this
                    # string.  If it's ascii-subset, then we could do a normal
                    # ascii split, but if it's multibyte then we could break the
                    # string.  There's no way to know so the least harm seems to
                    # be to not split the string and risk it being too long.
                    parts.append(value)
                    h = None
            else:
                h = header.Header(value, header_name=name)
        else:
            # Assume it is a Header-like object.
            h = value
        if h is not None:
            # The Header class interprets a value of None for maxlinelen as the
            # default value of 78, as recommended by RFC 2822.
            maxlinelen = 0
            if self.max_line_length is not None:
                maxlinelen = self.max_line_length
            parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
        parts.append(self.linesep)
        return ''.join(parts)


compat32 = Compat32()
architecture.rst000064400000022531151706203570007771 0ustar00:mod:`email` Package Architecture
=================================

Overview
--------

The email package consists of three major components:

    Model
        An object structure that represents an email message, and provides an
        API for creating, querying, and modifying a message.

    Parser
        Takes a sequence of characters or bytes and produces a model of the
        email message represented by those characters or bytes.

    Generator
        Takes a model and turns it into a sequence of characters or bytes.  The
        sequence can either be intended for human consumption (a printable
        unicode string) or bytes suitable for transmission over the wire.  In
        the latter case all data is properly encoded using the content transfer
        encodings specified by the relevant RFCs.

Conceptually the package is organized around the model.  The model provides both
"external" APIs intended for use by application programs using the library,
and "internal" APIs intended for use by the Parser and Generator components.
This division is intentionally a bit fuzzy; the API described by this
documentation is all a public, stable API.  This allows for an application
with special needs to implement its own parser and/or generator.

In addition to the three major functional components, there is a third key
component to the architecture:

    Policy
        An object that specifies various behavioral settings and carries
        implementations of various behavior-controlling methods.

The Policy framework provides a simple and convenient way to control the
behavior of the library, making it possible for the library to be used in a
very flexible fashion while leveraging the common code required to parse,
represent, and generate message-like objects.  For example, in addition to the
default :rfc:`5322` email message policy, we also have a policy that manages
HTTP headers in a fashion compliant with :rfc:`2616`.  Individual policy
controls, such as the maximum line length produced by the generator, can also
be controlled individually to meet specialized application requirements.


The Model
---------

The message model is implemented by the :class:`~email.message.Message` class.
The model divides a message into the two fundamental parts discussed by the
RFC: the header section and the body.  The `Message` object acts as a
pseudo-dictionary of named headers.  Its dictionary interface provides
convenient access to individual headers by name.  However, all headers are kept
internally in an ordered list, so that the information about the order of the
headers in the original message is preserved.

The `Message` object also has a `payload` that holds the body.  A `payload` can
be one of two things: data, or a list of `Message` objects.  The latter is used
to represent a multipart MIME message.  Lists can be nested arbitrarily deeply
in order to represent the message, with all terminal leaves having non-list
data payloads.


Message Lifecycle
-----------------

The general lifecycle of a message is:

    Creation
        A `Message` object can be created by a Parser, or it can be
        instantiated as an empty message by an application.

    Manipulation
        The application may examine one or more headers, and/or the
        payload, and it may modify one or more headers and/or
        the payload.  This may be done on the top level `Message`
        object, or on any sub-object.

    Finalization
        The Model is converted into a unicode or binary stream,
        or the model is discarded.



Header Policy Control During Lifecycle
--------------------------------------

One of the major controls exerted by the Policy is the management of headers
during the `Message` lifecycle.  Most applications don't need to be aware of
this.

A header enters the model in one of two ways: via a Parser, or by being set to
a specific value by an application program after the Model already exists.
Similarly, a header exits the model in one of two ways: by being serialized by
a Generator, or by being retrieved from a Model by an application program.  The
Policy object provides hooks for all four of these pathways.

The model storage for headers is a list of (name, value) tuples.

The Parser identifies headers during parsing, and passes them to the
:meth:`~email.policy.Policy.header_source_parse` method of the Policy.  The
result of that method is the (name, value) tuple to be stored in the model.

When an application program supplies a header value (for example, through the
`Message` object `__setitem__` interface), the name and the value are passed to
the :meth:`~email.policy.Policy.header_store_parse` method of the Policy, which
returns the (name, value) tuple to be stored in the model.

When an application program retrieves a header (through any of the dict or list
interfaces of `Message`), the name and value are passed to the
:meth:`~email.policy.Policy.header_fetch_parse` method of the Policy to
obtain the value returned to the application.

When a Generator requests a header during serialization, the name and value are
passed to the :meth:`~email.policy.Policy.fold` method of the Policy, which
returns a string containing line breaks in the appropriate places.  The
:meth:`~email.policy.Policy.cte_type` Policy control determines whether or
not Content Transfer Encoding is performed on the data in the header.  There is
also a :meth:`~email.policy.Policy.binary_fold` method for use by generators
that produce binary output, which returns the folded header as binary data,
possibly folded at different places than the corresponding string would be.


Handling Binary Data
--------------------

In an ideal world all message data would conform to the RFCs, meaning that the
parser could decode the message into the idealized unicode message that the
sender originally wrote.  In the real world, the email package must also be
able to deal with badly formatted messages, including messages containing
non-ASCII characters that either have no indicated character set or are not
valid characters in the indicated character set.

Since email messages are *primarily* text data, and operations on message data
are primarily text operations (except for binary payloads of course), the model
stores all text data as unicode strings.  Un-decodable binary inside text
data is handled by using the `surrogateescape` error handler of the ASCII
codec.  As with the binary filenames the error handler was introduced to
handle, this allows the email package to "carry" the binary data received
during parsing along until the output stage, at which time it is regenerated
in its original form.

This carried binary data is almost entirely an implementation detail.  The one
place where it is visible in the API is in the "internal" API.  A Parser must
do the `surrogateescape` encoding of binary input data, and pass that data to
the appropriate Policy method.  The "internal" interface used by the Generator
to access header values preserves the `surrogateescaped` bytes.  All other
interfaces convert the binary data either back into bytes or into a safe form
(losing information in some cases).


Backward Compatibility
----------------------

The :class:`~email.policy.Policy.Compat32` Policy provides backward
compatibility with version 5.1 of the email package.  It does this via the
following implementation of the four+1 Policy methods described above:

header_source_parse
    Splits the first line on the colon to obtain the name, discards any spaces
    after the colon, and joins the remainder of the line with all of the
    remaining lines, preserving the linesep characters to obtain the value.
    Trailing carriage return and/or linefeed characters are stripped from the
    resulting value string.

header_store_parse
    Returns the name and value exactly as received from the application.

header_fetch_parse
    If the value contains any `surrogateescaped` binary data, return the value
    as a :class:`~email.header.Header` object, using the character set
    `unknown-8bit`.  Otherwise just returns the value.

fold
    Uses :class:`~email.header.Header`'s folding to fold headers in the
    same way the email5.1 generator did.

binary_fold
    Same as fold, but encodes to 'ascii'.


New Algorithm
-------------

header_source_parse
    Same as legacy behavior.

header_store_parse
    Same as legacy behavior.

header_fetch_parse
    If the value is already a header object, returns it.  Otherwise, parses the
    value using the new parser, and returns the resulting object as the value.
    `surrogateescaped` bytes get turned into unicode unknown character code
    points.

fold
    Uses the new header folding algorithm, respecting the policy settings.
    surrogateescaped bytes are encoded using the ``unknown-8bit`` charset for
    ``cte_type=7bit`` or ``8bit``.  Returns a string.

    At some point there will also be a ``cte_type=unicode``, and for that
    policy fold will serialize the idealized unicode message with RFC-like
    folding, converting any surrogateescaped bytes into the unicode
    unknown character glyph.

binary_fold
    Uses the new header folding algorithm, respecting the policy settings.
    surrogateescaped bytes are encoded using the `unknown-8bit` charset for
    ``cte_type=7bit``, and get turned back into bytes for ``cte_type=8bit``.
    Returns bytes.

    At some point there will also be a ``cte_type=unicode``, and for that
    policy binary_fold will serialize the message according to :rfc:``5335``.
base64mime.py000064400000006737151706203570007075 0ustar00# Copyright (C) 2002-2007 Python Software Foundation
# Author: Ben Gertzfield
# Contact: email-sig@python.org

"""Base64 content transfer encoding per RFCs 2045-2047.

This module handles the content transfer encoding method defined in RFC 2045
to encode arbitrary 8-bit data using the three 8-bit bytes in four 7-bit
characters encoding known as Base64.

It is used in the MIME standards for email to attach images, audio, and text
using some 8-bit character sets to messages.

This module provides an interface to encode and decode both headers and bodies
with Base64 encoding.

RFC 2045 defines a method for including character set information in an
`encoded-word' in a header.  This method is commonly used for 8-bit real names
in To:, From:, Cc:, etc. fields, as well as Subject: lines.

This module does not do the line wrapping or end-of-line character conversion
necessary for proper internationalized headers; it only does dumb encoding and
decoding.  To deal with the various line wrapping issues, use the email.header
module.
"""

__all__ = [
    'body_decode',
    'body_encode',
    'decode',
    'decodestring',
    'header_encode',
    'header_length',
    ]


from base64 import b64encode
from binascii import b2a_base64, a2b_base64

CRLF = '\r\n'
NL = '\n'
EMPTYSTRING = ''

# See also Charset.py
MISC_LEN = 7


# Helpers
def header_length(bytearray):
    """Return the length of s when it is encoded with base64."""
    groups_of_3, leftover = divmod(len(bytearray), 3)
    # 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
    n = groups_of_3 * 4
    if leftover:
        n += 4
    return n


def header_encode(header_bytes, charset='iso-8859-1'):
    """Encode a single header line with Base64 encoding in a given charset.

    charset names the character set to use to encode the header.  It defaults
    to iso-8859-1.  Base64 encoding is defined in RFC 2045.
    """
    if not header_bytes:
        return ""
    if isinstance(header_bytes, str):
        header_bytes = header_bytes.encode(charset)
    encoded = b64encode(header_bytes).decode("ascii")
    return '=?%s?b?%s?=' % (charset, encoded)


def body_encode(s, maxlinelen=76, eol=NL):
    r"""Encode a string with base64.

    Each line will be wrapped at, at most, maxlinelen characters (defaults to
    76 characters).

    Each line of encoded text will end with eol, which defaults to "\n".  Set
    this to "\r\n" if you will be using the result of this function directly
    in an email.
    """
    if not s:
        return ""

    encvec = []
    max_unencoded = maxlinelen * 3 // 4
    for i in range(0, len(s), max_unencoded):
        # BAW: should encode() inherit b2a_base64()'s dubious behavior in
        # adding a newline to the encoded string?
        enc = b2a_base64(s[i:i + max_unencoded]).decode("ascii")
        if enc.endswith(NL) and eol != NL:
            enc = enc[:-1] + eol
        encvec.append(enc)
    return EMPTYSTRING.join(encvec)


def decode(string):
    """Decode a raw base64 string, returning a bytes object.

    This function does not parse a full MIME header value encoded with
    base64 (like =?iso-8859-1?b?bmloISBuaWgh?=) -- please use the high
    level email.header class for that functionality.
    """
    if not string:
        return bytes()
    elif isinstance(string, str):
        return a2b_base64(string.encode('raw-unicode-escape'))
    else:
        return a2b_base64(string)


# For convenience and backwards compatibility w/ standard base64 module
body_decode = decode
decodestring = decode
charset.py000064400000041247151706203570006565 0ustar00# Copyright (C) 2001-2007 Python Software Foundation
# Author: Ben Gertzfield, Barry Warsaw
# Contact: email-sig@python.org

__all__ = [
    'Charset',
    'add_alias',
    'add_charset',
    'add_codec',
    ]

from functools import partial

import email.base64mime
import email.quoprimime

from email import errors
from email.encoders import encode_7or8bit


# Flags for types of header encodings
QP          = 1 # Quoted-Printable
BASE64      = 2 # Base64
SHORTEST    = 3 # the shorter of QP and base64, but only for headers

# In "=?charset?q?hello_world?=", the =?, ?q?, and ?= add up to 7
RFC2047_CHROME_LEN = 7

DEFAULT_CHARSET = 'us-ascii'
UNKNOWN8BIT = 'unknown-8bit'
EMPTYSTRING = ''


# Defaults
CHARSETS = {
    # input        header enc  body enc output conv
    'iso-8859-1':  (QP,        QP,      None),
    'iso-8859-2':  (QP,        QP,      None),
    'iso-8859-3':  (QP,        QP,      None),
    'iso-8859-4':  (QP,        QP,      None),
    # iso-8859-5 is Cyrillic, and not especially used
    # iso-8859-6 is Arabic, also not particularly used
    # iso-8859-7 is Greek, QP will not make it readable
    # iso-8859-8 is Hebrew, QP will not make it readable
    'iso-8859-9':  (QP,        QP,      None),
    'iso-8859-10': (QP,        QP,      None),
    # iso-8859-11 is Thai, QP will not make it readable
    'iso-8859-13': (QP,        QP,      None),
    'iso-8859-14': (QP,        QP,      None),
    'iso-8859-15': (QP,        QP,      None),
    'iso-8859-16': (QP,        QP,      None),
    'windows-1252':(QP,        QP,      None),
    'viscii':      (QP,        QP,      None),
    'us-ascii':    (None,      None,    None),
    'big5':        (BASE64,    BASE64,  None),
    'gb2312':      (BASE64,    BASE64,  None),
    'euc-jp':      (BASE64,    None,    'iso-2022-jp'),
    'shift_jis':   (BASE64,    None,    'iso-2022-jp'),
    'iso-2022-jp': (BASE64,    None,    None),
    'koi8-r':      (BASE64,    BASE64,  None),
    'utf-8':       (SHORTEST,  BASE64, 'utf-8'),
    }

# Aliases for other commonly-used names for character sets.  Map
# them to the real ones used in email.
ALIASES = {
    'latin_1': 'iso-8859-1',
    'latin-1': 'iso-8859-1',
    'latin_2': 'iso-8859-2',
    'latin-2': 'iso-8859-2',
    'latin_3': 'iso-8859-3',
    'latin-3': 'iso-8859-3',
    'latin_4': 'iso-8859-4',
    'latin-4': 'iso-8859-4',
    'latin_5': 'iso-8859-9',
    'latin-5': 'iso-8859-9',
    'latin_6': 'iso-8859-10',
    'latin-6': 'iso-8859-10',
    'latin_7': 'iso-8859-13',
    'latin-7': 'iso-8859-13',
    'latin_8': 'iso-8859-14',
    'latin-8': 'iso-8859-14',
    'latin_9': 'iso-8859-15',
    'latin-9': 'iso-8859-15',
    'latin_10':'iso-8859-16',
    'latin-10':'iso-8859-16',
    'cp949':   'ks_c_5601-1987',
    'euc_jp':  'euc-jp',
    'euc_kr':  'euc-kr',
    'ascii':   'us-ascii',
    }


# Map charsets to their Unicode codec strings.
CODEC_MAP = {
    'gb2312':      'eucgb2312_cn',
    'big5':        'big5_tw',
    # Hack: We don't want *any* conversion for stuff marked us-ascii, as all
    # sorts of garbage might be sent to us in the guise of 7-bit us-ascii.
    # Let that stuff pass through without conversion to/from Unicode.
    'us-ascii':    None,
    }


# Convenience functions for extending the above mappings
def add_charset(charset, header_enc=None, body_enc=None, output_charset=None):
    """Add character set properties to the global registry.

    charset is the input character set, and must be the canonical name of a
    character set.

    Optional header_enc and body_enc is either charset.QP for
    quoted-printable, charset.BASE64 for base64 encoding, charset.SHORTEST for
    the shortest of qp or base64 encoding, or None for no encoding.  SHORTEST
    is only valid for header_enc.  It describes how message headers and
    message bodies in the input charset are to be encoded.  Default is no
    encoding.

    Optional output_charset is the character set that the output should be
    in.  Conversions will proceed from input charset, to Unicode, to the
    output charset when the method Charset.convert() is called.  The default
    is to output in the same character set as the input.

    Both input_charset and output_charset must have Unicode codec entries in
    the module's charset-to-codec mapping; use add_codec(charset, codecname)
    to add codecs the module does not know about.  See the codecs module's
    documentation for more information.
    """
    if body_enc == SHORTEST:
        raise ValueError('SHORTEST not allowed for body_enc')
    CHARSETS[charset] = (header_enc, body_enc, output_charset)


def add_alias(alias, canonical):
    """Add a character set alias.

    alias is the alias name, e.g. latin-1
    canonical is the character set's canonical name, e.g. iso-8859-1
    """
    ALIASES[alias] = canonical


def add_codec(charset, codecname):
    """Add a codec that map characters in the given charset to/from Unicode.

    charset is the canonical name of a character set.  codecname is the name
    of a Python codec, as appropriate for the second argument to the unicode()
    built-in, or to the encode() method of a Unicode string.
    """
    CODEC_MAP[charset] = codecname


# Convenience function for encoding strings, taking into account
# that they might be unknown-8bit (ie: have surrogate-escaped bytes)
def _encode(string, codec):
    if codec == UNKNOWN8BIT:
        return string.encode('ascii', 'surrogateescape')
    else:
        return string.encode(codec)


class Charset:
    """Map character sets to their email properties.

    This class provides information about the requirements imposed on email
    for a specific character set.  It also provides convenience routines for
    converting between character sets, given the availability of the
    applicable codecs.  Given a character set, it will do its best to provide
    information on how to use that character set in an email in an
    RFC-compliant way.

    Certain character sets must be encoded with quoted-printable or base64
    when used in email headers or bodies.  Certain character sets must be
    converted outright, and are not allowed in email.  Instances of this
    module expose the following information about a character set:

    input_charset: The initial character set specified.  Common aliases
                   are converted to their `official' email names (e.g. latin_1
                   is converted to iso-8859-1).  Defaults to 7-bit us-ascii.

    header_encoding: If the character set must be encoded before it can be
                     used in an email header, this attribute will be set to
                     charset.QP (for quoted-printable), charset.BASE64 (for
                     base64 encoding), or charset.SHORTEST for the shortest of
                     QP or BASE64 encoding.  Otherwise, it will be None.

    body_encoding: Same as header_encoding, but describes the encoding for the
                   mail message's body, which indeed may be different than the
                   header encoding.  charset.SHORTEST is not allowed for
                   body_encoding.

    output_charset: Some character sets must be converted before they can be
                    used in email headers or bodies.  If the input_charset is
                    one of them, this attribute will contain the name of the
                    charset output will be converted to.  Otherwise, it will
                    be None.

    input_codec: The name of the Python codec used to convert the
                 input_charset to Unicode.  If no conversion codec is
                 necessary, this attribute will be None.

    output_codec: The name of the Python codec used to convert Unicode
                  to the output_charset.  If no conversion codec is necessary,
                  this attribute will have the same value as the input_codec.
    """
    def __init__(self, input_charset=DEFAULT_CHARSET):
        # RFC 2046, $4.1.2 says charsets are not case sensitive.  We coerce to
        # unicode because its .lower() is locale insensitive.  If the argument
        # is already a unicode, we leave it at that, but ensure that the
        # charset is ASCII, as the standard (RFC XXX) requires.
        try:
            if isinstance(input_charset, str):
                input_charset.encode('ascii')
            else:
                input_charset = str(input_charset, 'ascii')
        except UnicodeError:
            raise errors.CharsetError(input_charset)
        input_charset = input_charset.lower()
        # Set the input charset after filtering through the aliases
        self.input_charset = ALIASES.get(input_charset, input_charset)
        # We can try to guess which encoding and conversion to use by the
        # charset_map dictionary.  Try that first, but let the user override
        # it.
        henc, benc, conv = CHARSETS.get(self.input_charset,
                                        (SHORTEST, BASE64, None))
        if not conv:
            conv = self.input_charset
        # Set the attributes, allowing the arguments to override the default.
        self.header_encoding = henc
        self.body_encoding = benc
        self.output_charset = ALIASES.get(conv, conv)
        # Now set the codecs.  If one isn't defined for input_charset,
        # guess and try a Unicode codec with the same name as input_codec.
        self.input_codec = CODEC_MAP.get(self.input_charset,
                                         self.input_charset)
        self.output_codec = CODEC_MAP.get(self.output_charset,
                                          self.output_charset)

    def __repr__(self):
        return self.input_charset.lower()

    def __eq__(self, other):
        return str(self) == str(other).lower()

    def get_body_encoding(self):
        """Return the content-transfer-encoding used for body encoding.

        This is either the string `quoted-printable' or `base64' depending on
        the encoding used, or it is a function in which case you should call
        the function with a single argument, the Message object being
        encoded.  The function should then set the Content-Transfer-Encoding
        header itself to whatever is appropriate.

        Returns "quoted-printable" if self.body_encoding is QP.
        Returns "base64" if self.body_encoding is BASE64.
        Returns conversion function otherwise.
        """
        assert self.body_encoding != SHORTEST
        if self.body_encoding == QP:
            return 'quoted-printable'
        elif self.body_encoding == BASE64:
            return 'base64'
        else:
            return encode_7or8bit

    def get_output_charset(self):
        """Return the output character set.

        This is self.output_charset if that is not None, otherwise it is
        self.input_charset.
        """
        return self.output_charset or self.input_charset

    def header_encode(self, string):
        """Header-encode a string by converting it first to bytes.

        The type of encoding (base64 or quoted-printable) will be based on
        this charset's `header_encoding`.

        :param string: A unicode string for the header.  It must be possible
            to encode this string to bytes using the character set's
            output codec.
        :return: The encoded string, with RFC 2047 chrome.
        """
        codec = self.output_codec or 'us-ascii'
        header_bytes = _encode(string, codec)
        # 7bit/8bit encodings return the string unchanged (modulo conversions)
        encoder_module = self._get_encoder(header_bytes)
        if encoder_module is None:
            return string
        return encoder_module.header_encode(header_bytes, codec)

    def header_encode_lines(self, string, maxlengths):
        """Header-encode a string by converting it first to bytes.

        This is similar to `header_encode()` except that the string is fit
        into maximum line lengths as given by the argument.

        :param string: A unicode string for the header.  It must be possible
            to encode this string to bytes using the character set's
            output codec.
        :param maxlengths: Maximum line length iterator.  Each element
            returned from this iterator will provide the next maximum line
            length.  This parameter is used as an argument to built-in next()
            and should never be exhausted.  The maximum line lengths should
            not count the RFC 2047 chrome.  These line lengths are only a
            hint; the splitter does the best it can.
        :return: Lines of encoded strings, each with RFC 2047 chrome.
        """
        # See which encoding we should use.
        codec = self.output_codec or 'us-ascii'
        header_bytes = _encode(string, codec)
        encoder_module = self._get_encoder(header_bytes)
        encoder = partial(encoder_module.header_encode, charset=codec)
        # Calculate the number of characters that the RFC 2047 chrome will
        # contribute to each line.
        charset = self.get_output_charset()
        extra = len(charset) + RFC2047_CHROME_LEN
        # Now comes the hard part.  We must encode bytes but we can't split on
        # bytes because some character sets are variable length and each
        # encoded word must stand on its own.  So the problem is you have to
        # encode to bytes to figure out this word's length, but you must split
        # on characters.  This causes two problems: first, we don't know how
        # many octets a specific substring of unicode characters will get
        # encoded to, and second, we don't know how many ASCII characters
        # those octets will get encoded to.  Unless we try it.  Which seems
        # inefficient.  In the interest of being correct rather than fast (and
        # in the hope that there will be few encoded headers in any such
        # message), brute force it. :(
        lines = []
        current_line = []
        maxlen = next(maxlengths) - extra
        for character in string:
            current_line.append(character)
            this_line = EMPTYSTRING.join(current_line)
            length = encoder_module.header_length(_encode(this_line, charset))
            if length > maxlen:
                # This last character doesn't fit so pop it off.
                current_line.pop()
                # Does nothing fit on the first line?
                if not lines and not current_line:
                    lines.append(None)
                else:
                    joined_line = EMPTYSTRING.join(current_line)
                    header_bytes = _encode(joined_line, codec)
                    lines.append(encoder(header_bytes))
                current_line = [character]
                maxlen = next(maxlengths) - extra
        joined_line = EMPTYSTRING.join(current_line)
        header_bytes = _encode(joined_line, codec)
        lines.append(encoder(header_bytes))
        return lines

    def _get_encoder(self, header_bytes):
        if self.header_encoding == BASE64:
            return email.base64mime
        elif self.header_encoding == QP:
            return email.quoprimime
        elif self.header_encoding == SHORTEST:
            len64 = email.base64mime.header_length(header_bytes)
            lenqp = email.quoprimime.header_length(header_bytes)
            if len64 < lenqp:
                return email.base64mime
            else:
                return email.quoprimime
        else:
            return None

    def body_encode(self, string):
        """Body-encode a string by converting it first to bytes.

        The type of encoding (base64 or quoted-printable) will be based on
        self.body_encoding.  If body_encoding is None, we assume the
        output charset is a 7bit encoding, so re-encoding the decoded
        string using the ascii codec produces the correct string version
        of the content.
        """
        if not string:
            return string
        if self.body_encoding is BASE64:
            if isinstance(string, str):
                string = string.encode(self.output_charset)
            return email.base64mime.body_encode(string)
        elif self.body_encoding is QP:
            # quopromime.body_encode takes a string, but operates on it as if
            # it were a list of byte codes.  For a (minimal) history on why
            # this is so, see changeset 0cf700464177.  To correctly encode a
            # character set, then, we must turn it into pseudo bytes via the
            # latin1 charset, which will encode any byte as a single code point
            # between 0 and 255, which is what body_encode is expecting.
            if isinstance(string, str):
                string = string.encode(self.output_charset)
            string = string.decode('latin1')
            return email.quoprimime.body_encode(string)
        else:
            if isinstance(string, str):
                string = string.encode(self.output_charset).decode('ascii')
            return string
contentmanager.py000064400000024534151706203570010141 0ustar00import binascii
import email.charset
import email.message
import email.errors
from email import quoprimime

class ContentManager:

    def __init__(self):
        self.get_handlers = {}
        self.set_handlers = {}

    def add_get_handler(self, key, handler):
        self.get_handlers[key] = handler

    def get_content(self, msg, *args, **kw):
        content_type = msg.get_content_type()
        if content_type in self.get_handlers:
            return self.get_handlers[content_type](msg, *args, **kw)
        maintype = msg.get_content_maintype()
        if maintype in self.get_handlers:
            return self.get_handlers[maintype](msg, *args, **kw)
        if '' in self.get_handlers:
            return self.get_handlers[''](msg, *args, **kw)
        raise KeyError(content_type)

    def add_set_handler(self, typekey, handler):
        self.set_handlers[typekey] = handler

    def set_content(self, msg, obj, *args, **kw):
        if msg.get_content_maintype() == 'multipart':
            # XXX: is this error a good idea or not?  We can remove it later,
            # but we can't add it later, so do it for now.
            raise TypeError("set_content not valid on multipart")
        handler = self._find_set_handler(msg, obj)
        msg.clear_content()
        handler(msg, obj, *args, **kw)

    def _find_set_handler(self, msg, obj):
        full_path_for_error = None
        for typ in type(obj).__mro__:
            if typ in self.set_handlers:
                return self.set_handlers[typ]
            qname = typ.__qualname__
            modname = getattr(typ, '__module__', '')
            full_path = '.'.join((modname, qname)) if modname else qname
            if full_path_for_error is None:
                full_path_for_error = full_path
            if full_path in self.set_handlers:
                return self.set_handlers[full_path]
            if qname in self.set_handlers:
                return self.set_handlers[qname]
            name = typ.__name__
            if name in self.set_handlers:
                return self.set_handlers[name]
        if None in self.set_handlers:
            return self.set_handlers[None]
        raise KeyError(full_path_for_error)


raw_data_manager = ContentManager()


def get_text_content(msg, errors='replace'):
    content = msg.get_payload(decode=True)
    charset = msg.get_param('charset', 'ASCII')
    return content.decode(charset, errors=errors)
raw_data_manager.add_get_handler('text', get_text_content)


def get_non_text_content(msg):
    return msg.get_payload(decode=True)
for maintype in 'audio image video application'.split():
    raw_data_manager.add_get_handler(maintype, get_non_text_content)
del maintype


def get_message_content(msg):
    return msg.get_payload(0)
for subtype in 'rfc822 external-body'.split():
    raw_data_manager.add_get_handler('message/'+subtype, get_message_content)
del subtype


def get_and_fixup_unknown_message_content(msg):
    # If we don't understand a message subtype, we are supposed to treat it as
    # if it were application/octet-stream, per
    # tools.ietf.org/html/rfc2046#section-5.2.4.  Feedparser doesn't do that,
    # so do our best to fix things up.  Note that it is *not* appropriate to
    # model message/partial content as Message objects, so they are handled
    # here as well.  (How to reassemble them is out of scope for this comment :)
    return bytes(msg.get_payload(0))
raw_data_manager.add_get_handler('message',
                                 get_and_fixup_unknown_message_content)


def _prepare_set(msg, maintype, subtype, headers):
    msg['Content-Type'] = '/'.join((maintype, subtype))
    if headers:
        if not hasattr(headers[0], 'name'):
            mp = msg.policy
            headers = [mp.header_factory(*mp.header_source_parse([header]))
                       for header in headers]
        try:
            for header in headers:
                if header.defects:
                    raise header.defects[0]
                msg[header.name] = header
        except email.errors.HeaderDefect as exc:
            raise ValueError("Invalid header: {}".format(
                                header.fold(policy=msg.policy))) from exc


def _finalize_set(msg, disposition, filename, cid, params):
    if disposition is None and filename is not None:
        disposition = 'attachment'
    if disposition is not None:
        msg['Content-Disposition'] = disposition
    if filename is not None:
        msg.set_param('filename',
                      filename,
                      header='Content-Disposition',
                      replace=True)
    if cid is not None:
        msg['Content-ID'] = cid
    if params is not None:
        for key, value in params.items():
            msg.set_param(key, value)


# XXX: This is a cleaned-up version of base64mime.body_encode (including a bug
# fix in the calculation of unencoded_bytes_per_line).  It would be nice to
# drop both this and quoprimime.body_encode in favor of enhanced binascii
# routines that accepted a max_line_length parameter.
def _encode_base64(data, max_line_length):
    encoded_lines = []
    unencoded_bytes_per_line = max_line_length // 4 * 3
    for i in range(0, len(data), unencoded_bytes_per_line):
        thisline = data[i:i+unencoded_bytes_per_line]
        encoded_lines.append(binascii.b2a_base64(thisline).decode('ascii'))
    return ''.join(encoded_lines)


def _encode_text(string, charset, cte, policy):
    lines = string.encode(charset).splitlines()
    linesep = policy.linesep.encode('ascii')
    def embedded_body(lines): return linesep.join(lines) + linesep
    def normal_body(lines): return b'\n'.join(lines) + b'\n'
    if cte is None:
        # Use heuristics to decide on the "best" encoding.
        if max((len(x) for x in lines), default=0) <= policy.max_line_length:
            try:
                return '7bit', normal_body(lines).decode('ascii')
            except UnicodeDecodeError:
                pass
            if policy.cte_type == '8bit':
                return '8bit', normal_body(lines).decode('ascii', 'surrogateescape')
        sniff = embedded_body(lines[:10])
        sniff_qp = quoprimime.body_encode(sniff.decode('latin-1'),
                                          policy.max_line_length)
        sniff_base64 = binascii.b2a_base64(sniff)
        # This is a little unfair to qp; it includes lineseps, base64 doesn't.
        if len(sniff_qp) > len(sniff_base64):
            cte = 'base64'
        else:
            cte = 'quoted-printable'
            if len(lines) <= 10:
                return cte, sniff_qp
    if cte == '7bit':
        data = normal_body(lines).decode('ascii')
    elif cte == '8bit':
        data = normal_body(lines).decode('ascii', 'surrogateescape')
    elif cte == 'quoted-printable':
        data = quoprimime.body_encode(normal_body(lines).decode('latin-1'),
                                      policy.max_line_length)
    elif cte == 'base64':
        data = _encode_base64(embedded_body(lines), policy.max_line_length)
    else:
        raise ValueError("Unknown content transfer encoding {}".format(cte))
    return cte, data


def set_text_content(msg, string, subtype="plain", charset='utf-8', cte=None,
                     disposition=None, filename=None, cid=None,
                     params=None, headers=None):
    _prepare_set(msg, 'text', subtype, headers)
    cte, payload = _encode_text(string, charset, cte, msg.policy)
    msg.set_payload(payload)
    msg.set_param('charset',
                  email.charset.ALIASES.get(charset, charset),
                  replace=True)
    msg['Content-Transfer-Encoding'] = cte
    _finalize_set(msg, disposition, filename, cid, params)
raw_data_manager.add_set_handler(str, set_text_content)


def set_message_content(msg, message, subtype="rfc822", cte=None,
                       disposition=None, filename=None, cid=None,
                       params=None, headers=None):
    if subtype == 'partial':
        raise ValueError("message/partial is not supported for Message objects")
    if subtype == 'rfc822':
        if cte not in (None, '7bit', '8bit', 'binary'):
            # http://tools.ietf.org/html/rfc2046#section-5.2.1 mandate.
            raise ValueError(
                "message/rfc822 parts do not support cte={}".format(cte))
        # 8bit will get coerced on serialization if policy.cte_type='7bit'.  We
        # may end up claiming 8bit when it isn't needed, but the only negative
        # result of that should be a gateway that needs to coerce to 7bit
        # having to look through the whole embedded message to discover whether
        # or not it actually has to do anything.
        cte = '8bit' if cte is None else cte
    elif subtype == 'external-body':
        if cte not in (None, '7bit'):
            # http://tools.ietf.org/html/rfc2046#section-5.2.3 mandate.
            raise ValueError(
                "message/external-body parts do not support cte={}".format(cte))
        cte = '7bit'
    elif cte is None:
        # http://tools.ietf.org/html/rfc2046#section-5.2.4 says all future
        # subtypes should be restricted to 7bit, so assume that.
        cte = '7bit'
    _prepare_set(msg, 'message', subtype, headers)
    msg.set_payload([message])
    msg['Content-Transfer-Encoding'] = cte
    _finalize_set(msg, disposition, filename, cid, params)
raw_data_manager.add_set_handler(email.message.Message, set_message_content)


def set_bytes_content(msg, data, maintype, subtype, cte='base64',
                     disposition=None, filename=None, cid=None,
                     params=None, headers=None):
    _prepare_set(msg, maintype, subtype, headers)
    if cte == 'base64':
        data = _encode_base64(data, max_line_length=msg.policy.max_line_length)
    elif cte == 'quoted-printable':
        # XXX: quoprimime.body_encode won't encode newline characters in data,
        # so we can't use it.  This means max_line_length is ignored.  Another
        # bug to fix later.  (Note: encoders.quopri is broken on line ends.)
        data = binascii.b2a_qp(data, istext=False, header=False, quotetabs=True)
        data = data.decode('ascii')
    elif cte == '7bit':
        data = data.decode('ascii')
    elif cte in ('8bit', 'binary'):
        data = data.decode('ascii', 'surrogateescape')
    msg.set_payload(data)
    msg['Content-Transfer-Encoding'] = cte
    _finalize_set(msg, disposition, filename, cid, params)
for typ in (bytes, bytearray, memoryview):
    raw_data_manager.add_set_handler(typ, set_bytes_content)
del typ
encoders.py000064400000003362151706203570006732 0ustar00# Copyright (C) 2001-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Encodings and related functions."""

__all__ = [
    'encode_7or8bit',
    'encode_base64',
    'encode_noop',
    'encode_quopri',
    ]


from base64 import encodebytes as _bencode
from quopri import encodestring as _encodestring


def _qencode(s):
    enc = _encodestring(s, quotetabs=True)
    # Must encode spaces, which quopri.encodestring() doesn't do
    return enc.replace(b' ', b'=20')


def encode_base64(msg):
    """Encode the message's payload in Base64.

    Also, add an appropriate Content-Transfer-Encoding header.
    """
    orig = msg.get_payload(decode=True)
    encdata = str(_bencode(orig), 'ascii')
    msg.set_payload(encdata)
    msg['Content-Transfer-Encoding'] = 'base64'


def encode_quopri(msg):
    """Encode the message's payload in quoted-printable.

    Also, add an appropriate Content-Transfer-Encoding header.
    """
    orig = msg.get_payload(decode=True)
    encdata = _qencode(orig)
    msg.set_payload(encdata)
    msg['Content-Transfer-Encoding'] = 'quoted-printable'


def encode_7or8bit(msg):
    """Set the Content-Transfer-Encoding header to 7bit or 8bit."""
    orig = msg.get_payload(decode=True)
    if orig is None:
        # There's no payload.  For backwards compatibility we use 7bit
        msg['Content-Transfer-Encoding'] = '7bit'
        return
    # We play a trick to make this go fast.  If decoding from ASCII succeeds,
    # we know the data must be 7bit, otherwise treat it as 8bit.
    try:
        orig.decode('ascii')
    except UnicodeError:
        msg['Content-Transfer-Encoding'] = '8bit'
    else:
        msg['Content-Transfer-Encoding'] = '7bit'


def encode_noop(msg):
    """Do nothing."""
errors.py000064400000007346151706203570006452 0ustar00# Copyright (C) 2001-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""email package exception classes."""


class MessageError(Exception):
    """Base class for errors in the email package."""


class MessageParseError(MessageError):
    """Base class for message parsing errors."""


class HeaderParseError(MessageParseError):
    """Error while parsing headers."""


class BoundaryError(MessageParseError):
    """Couldn't find terminating boundary."""


class MultipartConversionError(MessageError, TypeError):
    """Conversion to a multipart is prohibited."""


class CharsetError(MessageError):
    """An illegal charset was given."""


class HeaderWriteError(MessageError):
    """Error while writing headers."""


# These are parsing defects which the parser was able to work around.
class MessageDefect(ValueError):
    """Base class for a message defect."""

    def __init__(self, line=None):
        if line is not None:
            super().__init__(line)
        self.line = line

class NoBoundaryInMultipartDefect(MessageDefect):
    """A message claimed to be a multipart but had no boundary parameter."""

class StartBoundaryNotFoundDefect(MessageDefect):
    """The claimed start boundary was never found."""

class CloseBoundaryNotFoundDefect(MessageDefect):
    """A start boundary was found, but not the corresponding close boundary."""

class FirstHeaderLineIsContinuationDefect(MessageDefect):
    """A message had a continuation line as its first header line."""

class MisplacedEnvelopeHeaderDefect(MessageDefect):
    """A 'Unix-from' header was found in the middle of a header block."""

class MissingHeaderBodySeparatorDefect(MessageDefect):
    """Found line with no leading whitespace and no colon before blank line."""
# XXX: backward compatibility, just in case (it was never emitted).
MalformedHeaderDefect = MissingHeaderBodySeparatorDefect

class MultipartInvariantViolationDefect(MessageDefect):
    """A message claimed to be a multipart but no subparts were found."""

class InvalidMultipartContentTransferEncodingDefect(MessageDefect):
    """An invalid content transfer encoding was set on the multipart itself."""

class UndecodableBytesDefect(MessageDefect):
    """Header contained bytes that could not be decoded"""

class InvalidBase64PaddingDefect(MessageDefect):
    """base64 encoded sequence had an incorrect length"""

class InvalidBase64CharactersDefect(MessageDefect):
    """base64 encoded sequence had characters not in base64 alphabet"""

class InvalidBase64LengthDefect(MessageDefect):
    """base64 encoded sequence had invalid length (1 mod 4)"""

# These errors are specific to header parsing.

class HeaderDefect(MessageDefect):
    """Base class for a header defect."""

    def __init__(self, *args, **kw):
        super().__init__(*args, **kw)

class InvalidHeaderDefect(HeaderDefect):
    """Header is not valid, message gives details."""

class HeaderMissingRequiredValue(HeaderDefect):
    """A header that must have a value had none"""

class NonPrintableDefect(HeaderDefect):
    """ASCII characters outside the ascii-printable range found"""

    def __init__(self, non_printables):
        super().__init__(non_printables)
        self.non_printables = non_printables

    def __str__(self):
        return ("the following ASCII non-printables found in header: "
            "{}".format(self.non_printables))

class ObsoleteHeaderDefect(HeaderDefect):
    """Header uses syntax declared obsolete by RFC 5322"""

class NonASCIILocalPartDefect(HeaderDefect):
    """local_part contains non-ASCII characters"""
    # This defect only occurs during unicode parsing, not when
    # parsing messages decoded from binary.

class InvalidDateDefect(HeaderDefect):
    """Header has unparsable or invalid date"""
feedparser.py000064400000054414151706203570007254 0ustar00# Copyright (C) 2004-2006 Python Software Foundation
# Authors: Baxter, Wouters and Warsaw
# Contact: email-sig@python.org

"""FeedParser - An email feed parser.

The feed parser implements an interface for incrementally parsing an email
message, line by line.  This has advantages for certain applications, such as
those reading email messages off a socket.

FeedParser.feed() is the primary interface for pushing new data into the
parser.  It returns when there's nothing more it can do with the available
data.  When you have no more data to push into the parser, call .close().
This completes the parsing and returns the root message object.

The other advantage of this parser is that it will never raise a parsing
exception.  Instead, when it finds something unexpected, it adds a 'defect' to
the current message.  Defects are just instances that live on the message
object's .defects attribute.
"""

__all__ = ['FeedParser', 'BytesFeedParser']

import re

from email import errors
from email._policybase import compat32
from collections import deque
from io import StringIO

NLCRE = re.compile(r'\r\n|\r|\n')
NLCRE_bol = re.compile(r'(\r\n|\r|\n)')
NLCRE_eol = re.compile(r'(\r\n|\r|\n)\Z')
NLCRE_crack = re.compile(r'(\r\n|\r|\n)')
# RFC 2822 $3.6.8 Optional fields.  ftext is %d33-57 / %d59-126, Any character
# except controls, SP, and ":".
headerRE = re.compile(r'^(From |[\041-\071\073-\176]*:|[\t ])')
EMPTYSTRING = ''
NL = '\n'

NeedMoreData = object()


class BufferedSubFile(object):
    """A file-ish object that can have new data loaded into it.

    You can also push and pop line-matching predicates onto a stack.  When the
    current predicate matches the current line, a false EOF response
    (i.e. empty string) is returned instead.  This lets the parser adhere to a
    simple abstraction -- it parses until EOF closes the current message.
    """
    def __init__(self):
        # Text stream of the last partial line pushed into this object.
        # See issue 22233 for why this is a text stream and not a list.
        self._partial = StringIO(newline='')
        # A deque of full, pushed lines
        self._lines = deque()
        # The stack of false-EOF checking predicates.
        self._eofstack = []
        # A flag indicating whether the file has been closed or not.
        self._closed = False

    def push_eof_matcher(self, pred):
        self._eofstack.append(pred)

    def pop_eof_matcher(self):
        return self._eofstack.pop()

    def close(self):
        # Don't forget any trailing partial line.
        self._partial.seek(0)
        self.pushlines(self._partial.readlines())
        self._partial.seek(0)
        self._partial.truncate()
        self._closed = True

    def readline(self):
        if not self._lines:
            if self._closed:
                return ''
            return NeedMoreData
        # Pop the line off the stack and see if it matches the current
        # false-EOF predicate.
        line = self._lines.popleft()
        # RFC 2046, section 5.1.2 requires us to recognize outer level
        # boundaries at any level of inner nesting.  Do this, but be sure it's
        # in the order of most to least nested.
        for ateof in reversed(self._eofstack):
            if ateof(line):
                # We're at the false EOF.  But push the last line back first.
                self._lines.appendleft(line)
                return ''
        return line

    def unreadline(self, line):
        # Let the consumer push a line back into the buffer.
        assert line is not NeedMoreData
        self._lines.appendleft(line)

    def push(self, data):
        """Push some new data into this object."""
        self._partial.write(data)
        if '\n' not in data and '\r' not in data:
            # No new complete lines, wait for more.
            return

        # Crack into lines, preserving the linesep characters.
        self._partial.seek(0)
        parts = self._partial.readlines()
        self._partial.seek(0)
        self._partial.truncate()

        # If the last element of the list does not end in a newline, then treat
        # it as a partial line.  We only check for '\n' here because a line
        # ending with '\r' might be a line that was split in the middle of a
        # '\r\n' sequence (see bugs 1555570 and 1721862).
        if not parts[-1].endswith('\n'):
            self._partial.write(parts.pop())
        self.pushlines(parts)

    def pushlines(self, lines):
        self._lines.extend(lines)

    def __iter__(self):
        return self

    def __next__(self):
        line = self.readline()
        if line == '':
            raise StopIteration
        return line


class FeedParser:
    """A feed-style parser of email."""

    def __init__(self, _factory=None, *, policy=compat32):
        """_factory is called with no arguments to create a new message obj

        The policy keyword specifies a policy object that controls a number of
        aspects of the parser's operation.  The default policy maintains
        backward compatibility.

        """
        self.policy = policy
        self._old_style_factory = False
        if _factory is None:
            if policy.message_factory is None:
                from email.message import Message
                self._factory = Message
            else:
                self._factory = policy.message_factory
        else:
            self._factory = _factory
            try:
                _factory(policy=self.policy)
            except TypeError:
                # Assume this is an old-style factory
                self._old_style_factory = True
        self._input = BufferedSubFile()
        self._msgstack = []
        self._parse = self._parsegen().__next__
        self._cur = None
        self._last = None
        self._headersonly = False

    # Non-public interface for supporting Parser's headersonly flag
    def _set_headersonly(self):
        self._headersonly = True

    def feed(self, data):
        """Push more data into the parser."""
        self._input.push(data)
        self._call_parse()

    def _call_parse(self):
        try:
            self._parse()
        except StopIteration:
            pass

    def close(self):
        """Parse all remaining data and return the root message object."""
        self._input.close()
        self._call_parse()
        root = self._pop_message()
        assert not self._msgstack
        # Look for final set of defects
        if root.get_content_maintype() == 'multipart' \
               and not root.is_multipart() and not self._headersonly:
            defect = errors.MultipartInvariantViolationDefect()
            self.policy.handle_defect(root, defect)
        return root

    def _new_message(self):
        if self._old_style_factory:
            msg = self._factory()
        else:
            msg = self._factory(policy=self.policy)
        if self._cur and self._cur.get_content_type() == 'multipart/digest':
            msg.set_default_type('message/rfc822')
        if self._msgstack:
            self._msgstack[-1].attach(msg)
        self._msgstack.append(msg)
        self._cur = msg
        self._last = msg

    def _pop_message(self):
        retval = self._msgstack.pop()
        if self._msgstack:
            self._cur = self._msgstack[-1]
        else:
            self._cur = None
        return retval

    def _parsegen(self):
        # Create a new message and start by parsing headers.
        self._new_message()
        headers = []
        # Collect the headers, searching for a line that doesn't match the RFC
        # 2822 header or continuation pattern (including an empty line).
        for line in self._input:
            if line is NeedMoreData:
                yield NeedMoreData
                continue
            if not headerRE.match(line):
                # If we saw the RFC defined header/body separator
                # (i.e. newline), just throw it away. Otherwise the line is
                # part of the body so push it back.
                if not NLCRE.match(line):
                    defect = errors.MissingHeaderBodySeparatorDefect()
                    self.policy.handle_defect(self._cur, defect)
                    self._input.unreadline(line)
                break
            headers.append(line)
        # Done with the headers, so parse them and figure out what we're
        # supposed to see in the body of the message.
        self._parse_headers(headers)
        # Headers-only parsing is a backwards compatibility hack, which was
        # necessary in the older parser, which could raise errors.  All
        # remaining lines in the input are thrown into the message body.
        if self._headersonly:
            lines = []
            while True:
                line = self._input.readline()
                if line is NeedMoreData:
                    yield NeedMoreData
                    continue
                if line == '':
                    break
                lines.append(line)
            self._cur.set_payload(EMPTYSTRING.join(lines))
            return
        if self._cur.get_content_type() == 'message/delivery-status':
            # message/delivery-status contains blocks of headers separated by
            # a blank line.  We'll represent each header block as a separate
            # nested message object, but the processing is a bit different
            # than standard message/* types because there is no body for the
            # nested messages.  A blank line separates the subparts.
            while True:
                self._input.push_eof_matcher(NLCRE.match)
                for retval in self._parsegen():
                    if retval is NeedMoreData:
                        yield NeedMoreData
                        continue
                    break
                self._pop_message()
                # We need to pop the EOF matcher in order to tell if we're at
                # the end of the current file, not the end of the last block
                # of message headers.
                self._input.pop_eof_matcher()
                # The input stream must be sitting at the newline or at the
                # EOF.  We want to see if we're at the end of this subpart, so
                # first consume the blank line, then test the next line to see
                # if we're at this subpart's EOF.
                while True:
                    line = self._input.readline()
                    if line is NeedMoreData:
                        yield NeedMoreData
                        continue
                    break
                while True:
                    line = self._input.readline()
                    if line is NeedMoreData:
                        yield NeedMoreData
                        continue
                    break
                if line == '':
                    break
                # Not at EOF so this is a line we're going to need.
                self._input.unreadline(line)
            return
        if self._cur.get_content_maintype() == 'message':
            # The message claims to be a message/* type, then what follows is
            # another RFC 2822 message.
            for retval in self._parsegen():
                if retval is NeedMoreData:
                    yield NeedMoreData
                    continue
                break
            self._pop_message()
            return
        if self._cur.get_content_maintype() == 'multipart':
            boundary = self._cur.get_boundary()
            if boundary is None:
                # The message /claims/ to be a multipart but it has not
                # defined a boundary.  That's a problem which we'll handle by
                # reading everything until the EOF and marking the message as
                # defective.
                defect = errors.NoBoundaryInMultipartDefect()
                self.policy.handle_defect(self._cur, defect)
                lines = []
                for line in self._input:
                    if line is NeedMoreData:
                        yield NeedMoreData
                        continue
                    lines.append(line)
                self._cur.set_payload(EMPTYSTRING.join(lines))
                return
            # Make sure a valid content type was specified per RFC 2045:6.4.
            if (str(self._cur.get('content-transfer-encoding', '8bit')).lower()
                    not in ('7bit', '8bit', 'binary')):
                defect = errors.InvalidMultipartContentTransferEncodingDefect()
                self.policy.handle_defect(self._cur, defect)
            # Create a line match predicate which matches the inter-part
            # boundary as well as the end-of-multipart boundary.  Don't push
            # this onto the input stream until we've scanned past the
            # preamble.
            separator = '--' + boundary
            boundaryre = re.compile(
                '(?P<sep>' + re.escape(separator) +
                r')(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$')
            capturing_preamble = True
            preamble = []
            linesep = False
            close_boundary_seen = False
            while True:
                line = self._input.readline()
                if line is NeedMoreData:
                    yield NeedMoreData
                    continue
                if line == '':
                    break
                mo = boundaryre.match(line)
                if mo:
                    # If we're looking at the end boundary, we're done with
                    # this multipart.  If there was a newline at the end of
                    # the closing boundary, then we need to initialize the
                    # epilogue with the empty string (see below).
                    if mo.group('end'):
                        close_boundary_seen = True
                        linesep = mo.group('linesep')
                        break
                    # We saw an inter-part boundary.  Were we in the preamble?
                    if capturing_preamble:
                        if preamble:
                            # According to RFC 2046, the last newline belongs
                            # to the boundary.
                            lastline = preamble[-1]
                            eolmo = NLCRE_eol.search(lastline)
                            if eolmo:
                                preamble[-1] = lastline[:-len(eolmo.group(0))]
                            self._cur.preamble = EMPTYSTRING.join(preamble)
                        capturing_preamble = False
                        self._input.unreadline(line)
                        continue
                    # We saw a boundary separating two parts.  Consume any
                    # multiple boundary lines that may be following.  Our
                    # interpretation of RFC 2046 BNF grammar does not produce
                    # body parts within such double boundaries.
                    while True:
                        line = self._input.readline()
                        if line is NeedMoreData:
                            yield NeedMoreData
                            continue
                        mo = boundaryre.match(line)
                        if not mo:
                            self._input.unreadline(line)
                            break
                    # Recurse to parse this subpart; the input stream points
                    # at the subpart's first line.
                    self._input.push_eof_matcher(boundaryre.match)
                    for retval in self._parsegen():
                        if retval is NeedMoreData:
                            yield NeedMoreData
                            continue
                        break
                    # Because of RFC 2046, the newline preceding the boundary
                    # separator actually belongs to the boundary, not the
                    # previous subpart's payload (or epilogue if the previous
                    # part is a multipart).
                    if self._last.get_content_maintype() == 'multipart':
                        epilogue = self._last.epilogue
                        if epilogue == '':
                            self._last.epilogue = None
                        elif epilogue is not None:
                            mo = NLCRE_eol.search(epilogue)
                            if mo:
                                end = len(mo.group(0))
                                self._last.epilogue = epilogue[:-end]
                    else:
                        payload = self._last._payload
                        if isinstance(payload, str):
                            mo = NLCRE_eol.search(payload)
                            if mo:
                                payload = payload[:-len(mo.group(0))]
                                self._last._payload = payload
                    self._input.pop_eof_matcher()
                    self._pop_message()
                    # Set the multipart up for newline cleansing, which will
                    # happen if we're in a nested multipart.
                    self._last = self._cur
                else:
                    # I think we must be in the preamble
                    assert capturing_preamble
                    preamble.append(line)
            # We've seen either the EOF or the end boundary.  If we're still
            # capturing the preamble, we never saw the start boundary.  Note
            # that as a defect and store the captured text as the payload.
            if capturing_preamble:
                defect = errors.StartBoundaryNotFoundDefect()
                self.policy.handle_defect(self._cur, defect)
                self._cur.set_payload(EMPTYSTRING.join(preamble))
                epilogue = []
                for line in self._input:
                    if line is NeedMoreData:
                        yield NeedMoreData
                        continue
                self._cur.epilogue = EMPTYSTRING.join(epilogue)
                return
            # If we're not processing the preamble, then we might have seen
            # EOF without seeing that end boundary...that is also a defect.
            if not close_boundary_seen:
                defect = errors.CloseBoundaryNotFoundDefect()
                self.policy.handle_defect(self._cur, defect)
                return
            # Everything from here to the EOF is epilogue.  If the end boundary
            # ended in a newline, we'll need to make sure the epilogue isn't
            # None
            if linesep:
                epilogue = ['']
            else:
                epilogue = []
            for line in self._input:
                if line is NeedMoreData:
                    yield NeedMoreData
                    continue
                epilogue.append(line)
            # Any CRLF at the front of the epilogue is not technically part of
            # the epilogue.  Also, watch out for an empty string epilogue,
            # which means a single newline.
            if epilogue:
                firstline = epilogue[0]
                bolmo = NLCRE_bol.match(firstline)
                if bolmo:
                    epilogue[0] = firstline[len(bolmo.group(0)):]
            self._cur.epilogue = EMPTYSTRING.join(epilogue)
            return
        # Otherwise, it's some non-multipart type, so the entire rest of the
        # file contents becomes the payload.
        lines = []
        for line in self._input:
            if line is NeedMoreData:
                yield NeedMoreData
                continue
            lines.append(line)
        self._cur.set_payload(EMPTYSTRING.join(lines))

    def _parse_headers(self, lines):
        # Passed a list of lines that make up the headers for the current msg
        lastheader = ''
        lastvalue = []
        for lineno, line in enumerate(lines):
            # Check for continuation
            if line[0] in ' \t':
                if not lastheader:
                    # The first line of the headers was a continuation.  This
                    # is illegal, so let's note the defect, store the illegal
                    # line, and ignore it for purposes of headers.
                    defect = errors.FirstHeaderLineIsContinuationDefect(line)
                    self.policy.handle_defect(self._cur, defect)
                    continue
                lastvalue.append(line)
                continue
            if lastheader:
                self._cur.set_raw(*self.policy.header_source_parse(lastvalue))
                lastheader, lastvalue = '', []
            # Check for envelope header, i.e. unix-from
            if line.startswith('From '):
                if lineno == 0:
                    # Strip off the trailing newline
                    mo = NLCRE_eol.search(line)
                    if mo:
                        line = line[:-len(mo.group(0))]
                    self._cur.set_unixfrom(line)
                    continue
                elif lineno == len(lines) - 1:
                    # Something looking like a unix-from at the end - it's
                    # probably the first line of the body, so push back the
                    # line and stop.
                    self._input.unreadline(line)
                    return
                else:
                    # Weirdly placed unix-from line.  Note this as a defect
                    # and ignore it.
                    defect = errors.MisplacedEnvelopeHeaderDefect(line)
                    self._cur.defects.append(defect)
                    continue
            # Split the line on the colon separating field name from value.
            # There will always be a colon, because if there wasn't the part of
            # the parser that calls us would have started parsing the body.
            i = line.find(':')

            # If the colon is on the start of the line the header is clearly
            # malformed, but we might be able to salvage the rest of the
            # message. Track the error but keep going.
            if i == 0:
                defect = errors.InvalidHeaderDefect("Missing header name.")
                self._cur.defects.append(defect)
                continue

            assert i>0, "_parse_headers fed line with no : and no leading WS"
            lastheader = line[:i]
            lastvalue = [line]
        # Done with all the lines, so handle the last header.
        if lastheader:
            self._cur.set_raw(*self.policy.header_source_parse(lastvalue))


class BytesFeedParser(FeedParser):
    """Like FeedParser, but feed accepts bytes."""

    def feed(self, data):
        super().feed(data.decode('ascii', 'surrogateescape'))
generator.py000064400000051633151706203570007122 0ustar00# Copyright (C) 2001-2010 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Classes to generate plain text from a message object tree."""

__all__ = ['Generator', 'DecodedGenerator', 'BytesGenerator']

import re
import sys
import time
import random

from copy import deepcopy
from io import StringIO, BytesIO
from email.utils import _has_surrogates
from email.errors import HeaderWriteError

UNDERSCORE = '_'
NL = '\n'  # XXX: no longer used by the code below.

NLCRE = re.compile(r'\r\n|\r|\n')
fcre = re.compile(r'^From ', re.MULTILINE)
NEWLINE_WITHOUT_FWSP = re.compile(r'\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]')
NEWLINE_WITHOUT_FWSP_BYTES = re.compile(br'\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]')


class Generator:
    """Generates output from a Message object tree.

    This basic generator writes the message to the given file object as plain
    text.
    """
    #
    # Public interface
    #

    def __init__(self, outfp, mangle_from_=None, maxheaderlen=None, *,
                 policy=None):
        """Create the generator for message flattening.

        outfp is the output file-like object for writing the message to.  It
        must have a write() method.

        Optional mangle_from_ is a flag that, when True (the default if policy
        is not set), escapes From_ lines in the body of the message by putting
        a `>' in front of them.

        Optional maxheaderlen specifies the longest length for a non-continued
        header.  When a header line is longer (in characters, with tabs
        expanded to 8 spaces) than maxheaderlen, the header will split as
        defined in the Header class.  Set maxheaderlen to zero to disable
        header wrapping.  The default is 78, as recommended (but not required)
        by RFC 2822.

        The policy keyword specifies a policy object that controls a number of
        aspects of the generator's operation.  If no policy is specified,
        the policy associated with the Message object passed to the
        flatten method is used.

        """

        if mangle_from_ is None:
            mangle_from_ = True if policy is None else policy.mangle_from_
        self._fp = outfp
        self._mangle_from_ = mangle_from_
        self.maxheaderlen = maxheaderlen
        self.policy = policy

    def write(self, s):
        # Just delegate to the file object
        self._fp.write(s)

    def flatten(self, msg, unixfrom=False, linesep=None):
        r"""Print the message object tree rooted at msg to the output file
        specified when the Generator instance was created.

        unixfrom is a flag that forces the printing of a Unix From_ delimiter
        before the first object in the message tree.  If the original message
        has no From_ delimiter, a `standard' one is crafted.  By default, this
        is False to inhibit the printing of any From_ delimiter.

        Note that for subobjects, no From_ line is printed.

        linesep specifies the characters used to indicate a new line in
        the output.  The default value is determined by the policy specified
        when the Generator instance was created or, if none was specified,
        from the policy associated with the msg.

        """
        # We use the _XXX constants for operating on data that comes directly
        # from the msg, and _encoded_XXX constants for operating on data that
        # has already been converted (to bytes in the BytesGenerator) and
        # inserted into a temporary buffer.
        policy = msg.policy if self.policy is None else self.policy
        if linesep is not None:
            policy = policy.clone(linesep=linesep)
        if self.maxheaderlen is not None:
            policy = policy.clone(max_line_length=self.maxheaderlen)
        self._NL = policy.linesep
        self._encoded_NL = self._encode(self._NL)
        self._EMPTY = ''
        self._encoded_EMPTY = self._encode(self._EMPTY)
        # Because we use clone (below) when we recursively process message
        # subparts, and because clone uses the computed policy (not None),
        # submessages will automatically get set to the computed policy when
        # they are processed by this code.
        old_gen_policy = self.policy
        old_msg_policy = msg.policy
        try:
            self.policy = policy
            msg.policy = policy
            if unixfrom:
                ufrom = msg.get_unixfrom()
                if not ufrom:
                    ufrom = 'From nobody ' + time.ctime(time.time())
                self.write(ufrom + self._NL)
            self._write(msg)
        finally:
            self.policy = old_gen_policy
            msg.policy = old_msg_policy

    def clone(self, fp):
        """Clone this generator with the exact same options."""
        return self.__class__(fp,
                              self._mangle_from_,
                              None, # Use policy setting, which we've adjusted
                              policy=self.policy)

    #
    # Protected interface - undocumented ;/
    #

    # Note that we use 'self.write' when what we are writing is coming from
    # the source, and self._fp.write when what we are writing is coming from a
    # buffer (because the Bytes subclass has already had a chance to transform
    # the data in its write method in that case).  This is an entirely
    # pragmatic split determined by experiment; we could be more general by
    # always using write and having the Bytes subclass write method detect when
    # it has already transformed the input; but, since this whole thing is a
    # hack anyway this seems good enough.

    def _new_buffer(self):
        # BytesGenerator overrides this to return BytesIO.
        return StringIO()

    def _encode(self, s):
        # BytesGenerator overrides this to encode strings to bytes.
        return s

    def _write_lines(self, lines):
        # We have to transform the line endings.
        if not lines:
            return
        lines = NLCRE.split(lines)
        for line in lines[:-1]:
            self.write(line)
            self.write(self._NL)
        if lines[-1]:
            self.write(lines[-1])
        # XXX logic tells me this else should be needed, but the tests fail
        # with it and pass without it.  (NLCRE.split ends with a blank element
        # if and only if there was a trailing newline.)
        #else:
        #    self.write(self._NL)

    def _write(self, msg):
        # We can't write the headers yet because of the following scenario:
        # say a multipart message includes the boundary string somewhere in
        # its body.  We'd have to calculate the new boundary /before/ we write
        # the headers so that we can write the correct Content-Type:
        # parameter.
        #
        # The way we do this, so as to make the _handle_*() methods simpler,
        # is to cache any subpart writes into a buffer.  Then we write the
        # headers and the buffer contents.  That way, subpart handlers can
        # Do The Right Thing, and can still modify the Content-Type: header if
        # necessary.
        oldfp = self._fp
        try:
            self._munge_cte = None
            self._fp = sfp = self._new_buffer()
            self._dispatch(msg)
        finally:
            self._fp = oldfp
            munge_cte = self._munge_cte
            del self._munge_cte
        # If we munged the cte, copy the message again and re-fix the CTE.
        if munge_cte:
            msg = deepcopy(msg)
            # Preserve the header order if the CTE header already exists.
            if msg.get('content-transfer-encoding') is None:
                msg['Content-Transfer-Encoding'] = munge_cte[0]
            else:
                msg.replace_header('content-transfer-encoding', munge_cte[0])
            msg.replace_header('content-type', munge_cte[1])
        # Write the headers.  First we see if the message object wants to
        # handle that itself.  If not, we'll do it generically.
        meth = getattr(msg, '_write_headers', None)
        if meth is None:
            self._write_headers(msg)
        else:
            meth(self)
        self._fp.write(sfp.getvalue())

    def _dispatch(self, msg):
        # Get the Content-Type: for the message, then try to dispatch to
        # self._handle_<maintype>_<subtype>().  If there's no handler for the
        # full MIME type, then dispatch to self._handle_<maintype>().  If
        # that's missing too, then dispatch to self._writeBody().
        main = msg.get_content_maintype()
        sub = msg.get_content_subtype()
        specific = UNDERSCORE.join((main, sub)).replace('-', '_')
        meth = getattr(self, '_handle_' + specific, None)
        if meth is None:
            generic = main.replace('-', '_')
            meth = getattr(self, '_handle_' + generic, None)
            if meth is None:
                meth = self._writeBody
        meth(msg)

    #
    # Default handlers
    #

    def _write_headers(self, msg):
        for h, v in msg.raw_items():
            folded = self.policy.fold(h, v)
            if self.policy.verify_generated_headers:
                linesep = self.policy.linesep
                if not folded.endswith(self.policy.linesep):
                    raise HeaderWriteError(
                        f'folded header does not end with {linesep!r}: {folded!r}')
                if NEWLINE_WITHOUT_FWSP.search(folded.removesuffix(linesep)):
                    raise HeaderWriteError(
                        f'folded header contains newline: {folded!r}')
            self.write(folded)
        # A blank line always separates headers from body
        self.write(self._NL)

    #
    # Handlers for writing types and subtypes
    #

    def _handle_text(self, msg):
        payload = msg.get_payload()
        if payload is None:
            return
        if not isinstance(payload, str):
            raise TypeError('string payload expected: %s' % type(payload))
        if _has_surrogates(msg._payload):
            charset = msg.get_param('charset')
            if charset is not None:
                # XXX: This copy stuff is an ugly hack to avoid modifying the
                # existing message.
                msg = deepcopy(msg)
                del msg['content-transfer-encoding']
                msg.set_payload(msg._payload, charset)
                payload = msg.get_payload()
                self._munge_cte = (msg['content-transfer-encoding'],
                                   msg['content-type'])
        if self._mangle_from_:
            payload = fcre.sub('>From ', payload)
        self._write_lines(payload)

    # Default body handler
    _writeBody = _handle_text

    def _handle_multipart(self, msg):
        # The trick here is to write out each part separately, merge them all
        # together, and then make sure that the boundary we've chosen isn't
        # present in the payload.
        msgtexts = []
        subparts = msg.get_payload()
        if subparts is None:
            subparts = []
        elif isinstance(subparts, str):
            # e.g. a non-strict parse of a message with no starting boundary.
            self.write(subparts)
            return
        elif not isinstance(subparts, list):
            # Scalar payload
            subparts = [subparts]
        for part in subparts:
            s = self._new_buffer()
            g = self.clone(s)
            g.flatten(part, unixfrom=False, linesep=self._NL)
            msgtexts.append(s.getvalue())
        # BAW: What about boundaries that are wrapped in double-quotes?
        boundary = msg.get_boundary()
        if not boundary:
            # Create a boundary that doesn't appear in any of the
            # message texts.
            alltext = self._encoded_NL.join(msgtexts)
            boundary = self._make_boundary(alltext)
            msg.set_boundary(boundary)
        # If there's a preamble, write it out, with a trailing CRLF
        if msg.preamble is not None:
            if self._mangle_from_:
                preamble = fcre.sub('>From ', msg.preamble)
            else:
                preamble = msg.preamble
            self._write_lines(preamble)
            self.write(self._NL)
        # dash-boundary transport-padding CRLF
        self.write('--' + boundary + self._NL)
        # body-part
        if msgtexts:
            self._fp.write(msgtexts.pop(0))
        # *encapsulation
        # --> delimiter transport-padding
        # --> CRLF body-part
        for body_part in msgtexts:
            # delimiter transport-padding CRLF
            self.write(self._NL + '--' + boundary + self._NL)
            # body-part
            self._fp.write(body_part)
        # close-delimiter transport-padding
        self.write(self._NL + '--' + boundary + '--' + self._NL)
        if msg.epilogue is not None:
            if self._mangle_from_:
                epilogue = fcre.sub('>From ', msg.epilogue)
            else:
                epilogue = msg.epilogue
            self._write_lines(epilogue)

    def _handle_multipart_signed(self, msg):
        # The contents of signed parts has to stay unmodified in order to keep
        # the signature intact per RFC1847 2.1, so we disable header wrapping.
        # RDM: This isn't enough to completely preserve the part, but it helps.
        p = self.policy
        self.policy = p.clone(max_line_length=0)
        try:
            self._handle_multipart(msg)
        finally:
            self.policy = p

    def _handle_message_delivery_status(self, msg):
        # We can't just write the headers directly to self's file object
        # because this will leave an extra newline between the last header
        # block and the boundary.  Sigh.
        blocks = []
        for part in msg.get_payload():
            s = self._new_buffer()
            g = self.clone(s)
            g.flatten(part, unixfrom=False, linesep=self._NL)
            text = s.getvalue()
            lines = text.split(self._encoded_NL)
            # Strip off the unnecessary trailing empty line
            if lines and lines[-1] == self._encoded_EMPTY:
                blocks.append(self._encoded_NL.join(lines[:-1]))
            else:
                blocks.append(text)
        # Now join all the blocks with an empty line.  This has the lovely
        # effect of separating each block with an empty line, but not adding
        # an extra one after the last one.
        self._fp.write(self._encoded_NL.join(blocks))

    def _handle_message(self, msg):
        s = self._new_buffer()
        g = self.clone(s)
        # The payload of a message/rfc822 part should be a multipart sequence
        # of length 1.  The zeroth element of the list should be the Message
        # object for the subpart.  Extract that object, stringify it, and
        # write it out.
        # Except, it turns out, when it's a string instead, which happens when
        # and only when HeaderParser is used on a message of mime type
        # message/rfc822.  Such messages are generated by, for example,
        # Groupwise when forwarding unadorned messages.  (Issue 7970.)  So
        # in that case we just emit the string body.
        payload = msg._payload
        if isinstance(payload, list):
            g.flatten(msg.get_payload(0), unixfrom=False, linesep=self._NL)
            payload = s.getvalue()
        else:
            payload = self._encode(payload)
        self._fp.write(payload)

    # This used to be a module level function; we use a classmethod for this
    # and _compile_re so we can continue to provide the module level function
    # for backward compatibility by doing
    #   _make_boundary = Generator._make_boundary
    # at the end of the module.  It *is* internal, so we could drop that...
    @classmethod
    def _make_boundary(cls, text=None):
        # Craft a random boundary.  If text is given, ensure that the chosen
        # boundary doesn't appear in the text.
        token = random.randrange(sys.maxsize)
        boundary = ('=' * 15) + (_fmt % token) + '=='
        if text is None:
            return boundary
        b = boundary
        counter = 0
        while True:
            cre = cls._compile_re('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
            if not cre.search(text):
                break
            b = boundary + '.' + str(counter)
            counter += 1
        return b

    @classmethod
    def _compile_re(cls, s, flags):
        return re.compile(s, flags)


class BytesGenerator(Generator):
    """Generates a bytes version of a Message object tree.

    Functionally identical to the base Generator except that the output is
    bytes and not string.  When surrogates were used in the input to encode
    bytes, these are decoded back to bytes for output.  If the policy has
    cte_type set to 7bit, then the message is transformed such that the
    non-ASCII bytes are properly content transfer encoded, using the charset
    unknown-8bit.

    The outfp object must accept bytes in its write method.
    """

    def write(self, s):
        self._fp.write(s.encode('ascii', 'surrogateescape'))

    def _new_buffer(self):
        return BytesIO()

    def _encode(self, s):
        return s.encode('ascii')

    def _write_headers(self, msg):
        # This is almost the same as the string version, except for handling
        # strings with 8bit bytes.
        for h, v in msg.raw_items():
            folded = self.policy.fold_binary(h, v)
            if self.policy.verify_generated_headers:
                linesep = self.policy.linesep.encode()
                if not folded.endswith(linesep):
                    raise HeaderWriteError(
                        f'folded header does not end with {linesep!r}: {folded!r}')
                if NEWLINE_WITHOUT_FWSP_BYTES.search(folded.removesuffix(linesep)):
                    raise HeaderWriteError(
                        f'folded header contains newline: {folded!r}')
            self._fp.write(folded)
        # A blank line always separates headers from body
        self.write(self._NL)

    def _handle_text(self, msg):
        # If the string has surrogates the original source was bytes, so
        # just write it back out.
        if msg._payload is None:
            return
        if _has_surrogates(msg._payload) and not self.policy.cte_type=='7bit':
            if self._mangle_from_:
                msg._payload = fcre.sub(">From ", msg._payload)
            self._write_lines(msg._payload)
        else:
            super(BytesGenerator,self)._handle_text(msg)

    # Default body handler
    _writeBody = _handle_text

    @classmethod
    def _compile_re(cls, s, flags):
        return re.compile(s.encode('ascii'), flags)


_FMT = '[Non-text (%(type)s) part of message omitted, filename %(filename)s]'

class DecodedGenerator(Generator):
    """Generates a text representation of a message.

    Like the Generator base class, except that non-text parts are substituted
    with a format string representing the part.
    """
    def __init__(self, outfp, mangle_from_=None, maxheaderlen=None, fmt=None, *,
                 policy=None):
        """Like Generator.__init__() except that an additional optional
        argument is allowed.

        Walks through all subparts of a message.  If the subpart is of main
        type `text', then it prints the decoded payload of the subpart.

        Otherwise, fmt is a format string that is used instead of the message
        payload.  fmt is expanded with the following keywords (in
        %(keyword)s format):

        type       : Full MIME type of the non-text part
        maintype   : Main MIME type of the non-text part
        subtype    : Sub-MIME type of the non-text part
        filename   : Filename of the non-text part
        description: Description associated with the non-text part
        encoding   : Content transfer encoding of the non-text part

        The default value for fmt is None, meaning

        [Non-text (%(type)s) part of message omitted, filename %(filename)s]
        """
        Generator.__init__(self, outfp, mangle_from_, maxheaderlen,
                           policy=policy)
        if fmt is None:
            self._fmt = _FMT
        else:
            self._fmt = fmt

    def _dispatch(self, msg):
        for part in msg.walk():
            maintype = part.get_content_maintype()
            if maintype == 'text':
                print(part.get_payload(decode=False), file=self)
            elif maintype == 'multipart':
                # Just skip this
                pass
            else:
                print(self._fmt % {
                    'type'       : part.get_content_type(),
                    'maintype'   : part.get_content_maintype(),
                    'subtype'    : part.get_content_subtype(),
                    'filename'   : part.get_filename('[no filename]'),
                    'description': part.get('Content-Description',
                                            '[no description]'),
                    'encoding'   : part.get('Content-Transfer-Encoding',
                                            '[no encoding]'),
                    }, file=self)


# Helper used by Generator._make_boundary
_width = len(repr(sys.maxsize-1))
_fmt = '%%0%dd' % _width

# Backward compatibility
_make_boundary = Generator._make_boundary
header.py000064400000057034151706203570006365 0ustar00# Copyright (C) 2002-2007 Python Software Foundation
# Author: Ben Gertzfield, Barry Warsaw
# Contact: email-sig@python.org

"""Header encoding and decoding functionality."""

__all__ = [
    'Header',
    'decode_header',
    'make_header',
    ]

import re
import binascii

import email.quoprimime
import email.base64mime

from email.errors import HeaderParseError
from email import charset as _charset
Charset = _charset.Charset

NL = '\n'
SPACE = ' '
BSPACE = b' '
SPACE8 = ' ' * 8
EMPTYSTRING = ''
MAXLINELEN = 78
FWS = ' \t'

USASCII = Charset('us-ascii')
UTF8 = Charset('utf-8')

# Match encoded-word strings in the form =?charset?q?Hello_World?=
ecre = re.compile(r'''
  =\?                   # literal =?
  (?P<charset>[^?]*?)   # non-greedy up to the next ? is the charset
  \?                    # literal ?
  (?P<encoding>[qQbB])  # either a "q" or a "b", case insensitive
  \?                    # literal ?
  (?P<encoded>.*?)      # non-greedy up to the next ?= is the encoded string
  \?=                   # literal ?=
  ''', re.VERBOSE | re.MULTILINE)

# Field name regexp, including trailing colon, but not separating whitespace,
# according to RFC 2822.  Character range is from tilde to exclamation mark.
# For use with .match()
fcre = re.compile(r'[\041-\176]+:$')

# Find a header embedded in a putative header value.  Used to check for
# header injection attack.
_embedded_header = re.compile(r'\n[^ \t]+:')


# Helpers
_max_append = email.quoprimime._max_append


def decode_header(header):
    """Decode a message header value without converting charset.

    Returns a list of (string, charset) pairs containing each of the decoded
    parts of the header.  Charset is None for non-encoded parts of the header,
    otherwise a lower-case string containing the name of the character set
    specified in the encoded string.

    header may be a string that may or may not contain RFC2047 encoded words,
    or it may be a Header object.

    An email.errors.HeaderParseError may be raised when certain decoding error
    occurs (e.g. a base64 decoding exception).
    """
    # If it is a Header object, we can just return the encoded chunks.
    if hasattr(header, '_chunks'):
        return [(_charset._encode(string, str(charset)), str(charset))
                    for string, charset in header._chunks]
    # If no encoding, just return the header with no charset.
    if not ecre.search(header):
        return [(header, None)]
    # First step is to parse all the encoded parts into triplets of the form
    # (encoded_string, encoding, charset).  For unencoded strings, the last
    # two parts will be None.
    words = []
    for line in header.splitlines():
        parts = ecre.split(line)
        first = True
        while parts:
            unencoded = parts.pop(0)
            if first:
                unencoded = unencoded.lstrip()
                first = False
            if unencoded:
                words.append((unencoded, None, None))
            if parts:
                charset = parts.pop(0).lower()
                encoding = parts.pop(0).lower()
                encoded = parts.pop(0)
                words.append((encoded, encoding, charset))
    # Now loop over words and remove words that consist of whitespace
    # between two encoded strings.
    droplist = []
    for n, w in enumerate(words):
        if n>1 and w[1] and words[n-2][1] and words[n-1][0].isspace():
            droplist.append(n-1)
    for d in reversed(droplist):
        del words[d]

    # The next step is to decode each encoded word by applying the reverse
    # base64 or quopri transformation.  decoded_words is now a list of the
    # form (decoded_word, charset).
    decoded_words = []
    for encoded_string, encoding, charset in words:
        if encoding is None:
            # This is an unencoded word.
            decoded_words.append((encoded_string, charset))
        elif encoding == 'q':
            word = email.quoprimime.header_decode(encoded_string)
            decoded_words.append((word, charset))
        elif encoding == 'b':
            paderr = len(encoded_string) % 4   # Postel's law: add missing padding
            if paderr:
                encoded_string += '==='[:4 - paderr]
            try:
                word = email.base64mime.decode(encoded_string)
            except binascii.Error:
                raise HeaderParseError('Base64 decoding error')
            else:
                decoded_words.append((word, charset))
        else:
            raise AssertionError('Unexpected encoding: ' + encoding)
    # Now convert all words to bytes and collapse consecutive runs of
    # similarly encoded words.
    collapsed = []
    last_word = last_charset = None
    for word, charset in decoded_words:
        if isinstance(word, str):
            word = bytes(word, 'raw-unicode-escape')
        if last_word is None:
            last_word = word
            last_charset = charset
        elif charset != last_charset:
            collapsed.append((last_word, last_charset))
            last_word = word
            last_charset = charset
        elif last_charset is None:
            last_word += BSPACE + word
        else:
            last_word += word
    collapsed.append((last_word, last_charset))
    return collapsed


def make_header(decoded_seq, maxlinelen=None, header_name=None,
                continuation_ws=' '):
    """Create a Header from a sequence of pairs as returned by decode_header()

    decode_header() takes a header value string and returns a sequence of
    pairs of the format (decoded_string, charset) where charset is the string
    name of the character set.

    This function takes one of those sequence of pairs and returns a Header
    instance.  Optional maxlinelen, header_name, and continuation_ws are as in
    the Header constructor.
    """
    h = Header(maxlinelen=maxlinelen, header_name=header_name,
               continuation_ws=continuation_ws)
    for s, charset in decoded_seq:
        # None means us-ascii but we can simply pass it on to h.append()
        if charset is not None and not isinstance(charset, Charset):
            charset = Charset(charset)
        h.append(s, charset)
    return h


class Header:
    def __init__(self, s=None, charset=None,
                 maxlinelen=None, header_name=None,
                 continuation_ws=' ', errors='strict'):
        """Create a MIME-compliant header that can contain many character sets.

        Optional s is the initial header value.  If None, the initial header
        value is not set.  You can later append to the header with .append()
        method calls.  s may be a byte string or a Unicode string, but see the
        .append() documentation for semantics.

        Optional charset serves two purposes: it has the same meaning as the
        charset argument to the .append() method.  It also sets the default
        character set for all subsequent .append() calls that omit the charset
        argument.  If charset is not provided in the constructor, the us-ascii
        charset is used both as s's initial charset and as the default for
        subsequent .append() calls.

        The maximum line length can be specified explicitly via maxlinelen. For
        splitting the first line to a shorter value (to account for the field
        header which isn't included in s, e.g. `Subject') pass in the name of
        the field in header_name.  The default maxlinelen is 78 as recommended
        by RFC 2822.

        continuation_ws must be RFC 2822 compliant folding whitespace (usually
        either a space or a hard tab) which will be prepended to continuation
        lines.

        errors is passed through to the .append() call.
        """
        if charset is None:
            charset = USASCII
        elif not isinstance(charset, Charset):
            charset = Charset(charset)
        self._charset = charset
        self._continuation_ws = continuation_ws
        self._chunks = []
        if s is not None:
            self.append(s, charset, errors)
        if maxlinelen is None:
            maxlinelen = MAXLINELEN
        self._maxlinelen = maxlinelen
        if header_name is None:
            self._headerlen = 0
        else:
            # Take the separating colon and space into account.
            self._headerlen = len(header_name) + 2

    def __str__(self):
        """Return the string value of the header."""
        self._normalize()
        uchunks = []
        lastcs = None
        lastspace = None
        for string, charset in self._chunks:
            # We must preserve spaces between encoded and non-encoded word
            # boundaries, which means for us we need to add a space when we go
            # from a charset to None/us-ascii, or from None/us-ascii to a
            # charset.  Only do this for the second and subsequent chunks.
            # Don't add a space if the None/us-ascii string already has
            # a space (trailing or leading depending on transition)
            nextcs = charset
            if nextcs == _charset.UNKNOWN8BIT:
                original_bytes = string.encode('ascii', 'surrogateescape')
                string = original_bytes.decode('ascii', 'replace')
            if uchunks:
                hasspace = string and self._nonctext(string[0])
                if lastcs not in (None, 'us-ascii'):
                    if nextcs in (None, 'us-ascii') and not hasspace:
                        uchunks.append(SPACE)
                        nextcs = None
                elif nextcs not in (None, 'us-ascii') and not lastspace:
                    uchunks.append(SPACE)
            lastspace = string and self._nonctext(string[-1])
            lastcs = nextcs
            uchunks.append(string)
        return EMPTYSTRING.join(uchunks)

    # Rich comparison operators for equality only.  BAW: does it make sense to
    # have or explicitly disable <, <=, >, >= operators?
    def __eq__(self, other):
        # other may be a Header or a string.  Both are fine so coerce
        # ourselves to a unicode (of the unencoded header value), swap the
        # args and do another comparison.
        return other == str(self)

    def append(self, s, charset=None, errors='strict'):
        """Append a string to the MIME header.

        Optional charset, if given, should be a Charset instance or the name
        of a character set (which will be converted to a Charset instance).  A
        value of None (the default) means that the charset given in the
        constructor is used.

        s may be a byte string or a Unicode string.  If it is a byte string
        (i.e. isinstance(s, str) is false), then charset is the encoding of
        that byte string, and a UnicodeError will be raised if the string
        cannot be decoded with that charset.  If s is a Unicode string, then
        charset is a hint specifying the character set of the characters in
        the string.  In either case, when producing an RFC 2822 compliant
        header using RFC 2047 rules, the string will be encoded using the
        output codec of the charset.  If the string cannot be encoded to the
        output codec, a UnicodeError will be raised.

        Optional `errors' is passed as the errors argument to the decode
        call if s is a byte string.
        """
        if charset is None:
            charset = self._charset
        elif not isinstance(charset, Charset):
            charset = Charset(charset)
        if not isinstance(s, str):
            input_charset = charset.input_codec or 'us-ascii'
            if input_charset == _charset.UNKNOWN8BIT:
                s = s.decode('us-ascii', 'surrogateescape')
            else:
                s = s.decode(input_charset, errors)
        # Ensure that the bytes we're storing can be decoded to the output
        # character set, otherwise an early error is raised.
        output_charset = charset.output_codec or 'us-ascii'
        if output_charset != _charset.UNKNOWN8BIT:
            try:
                s.encode(output_charset, errors)
            except UnicodeEncodeError:
                if output_charset!='us-ascii':
                    raise
                charset = UTF8
        self._chunks.append((s, charset))

    def _nonctext(self, s):
        """True if string s is not a ctext character of RFC822.
        """
        return s.isspace() or s in ('(', ')', '\\')

    def encode(self, splitchars=';, \t', maxlinelen=None, linesep='\n'):
        r"""Encode a message header into an RFC-compliant format.

        There are many issues involved in converting a given string for use in
        an email header.  Only certain character sets are readable in most
        email clients, and as header strings can only contain a subset of
        7-bit ASCII, care must be taken to properly convert and encode (with
        Base64 or quoted-printable) header strings.  In addition, there is a
        75-character length limit on any given encoded header field, so
        line-wrapping must be performed, even with double-byte character sets.

        Optional maxlinelen specifies the maximum length of each generated
        line, exclusive of the linesep string.  Individual lines may be longer
        than maxlinelen if a folding point cannot be found.  The first line
        will be shorter by the length of the header name plus ": " if a header
        name was specified at Header construction time.  The default value for
        maxlinelen is determined at header construction time.

        Optional splitchars is a string containing characters which should be
        given extra weight by the splitting algorithm during normal header
        wrapping.  This is in very rough support of RFC 2822's `higher level
        syntactic breaks':  split points preceded by a splitchar are preferred
        during line splitting, with the characters preferred in the order in
        which they appear in the string.  Space and tab may be included in the
        string to indicate whether preference should be given to one over the
        other as a split point when other split chars do not appear in the line
        being split.  Splitchars does not affect RFC 2047 encoded lines.

        Optional linesep is a string to be used to separate the lines of
        the value.  The default value is the most useful for typical
        Python applications, but it can be set to \r\n to produce RFC-compliant
        line separators when needed.
        """
        self._normalize()
        if maxlinelen is None:
            maxlinelen = self._maxlinelen
        # A maxlinelen of 0 means don't wrap.  For all practical purposes,
        # choosing a huge number here accomplishes that and makes the
        # _ValueFormatter algorithm much simpler.
        if maxlinelen == 0:
            maxlinelen = 1000000
        formatter = _ValueFormatter(self._headerlen, maxlinelen,
                                    self._continuation_ws, splitchars)
        lastcs = None
        hasspace = lastspace = None
        for string, charset in self._chunks:
            if hasspace is not None:
                hasspace = string and self._nonctext(string[0])
                if lastcs not in (None, 'us-ascii'):
                    if not hasspace or charset not in (None, 'us-ascii'):
                        formatter.add_transition()
                elif charset not in (None, 'us-ascii') and not lastspace:
                    formatter.add_transition()
            lastspace = string and self._nonctext(string[-1])
            lastcs = charset
            hasspace = False
            lines = string.splitlines()
            if lines:
                formatter.feed('', lines[0], charset)
            else:
                formatter.feed('', '', charset)
            for line in lines[1:]:
                formatter.newline()
                if charset.header_encoding is not None:
                    formatter.feed(self._continuation_ws, ' ' + line.lstrip(),
                                   charset)
                else:
                    sline = line.lstrip()
                    fws = line[:len(line)-len(sline)]
                    formatter.feed(fws, sline, charset)
            if len(lines) > 1:
                formatter.newline()
        if self._chunks:
            formatter.add_transition()
        value = formatter._str(linesep)
        if _embedded_header.search(value):
            raise HeaderParseError("header value appears to contain "
                "an embedded header: {!r}".format(value))
        return value

    def _normalize(self):
        # Step 1: Normalize the chunks so that all runs of identical charsets
        # get collapsed into a single unicode string.
        chunks = []
        last_charset = None
        last_chunk = []
        for string, charset in self._chunks:
            if charset == last_charset:
                last_chunk.append(string)
            else:
                if last_charset is not None:
                    chunks.append((SPACE.join(last_chunk), last_charset))
                last_chunk = [string]
                last_charset = charset
        if last_chunk:
            chunks.append((SPACE.join(last_chunk), last_charset))
        self._chunks = chunks


class _ValueFormatter:
    def __init__(self, headerlen, maxlen, continuation_ws, splitchars):
        self._maxlen = maxlen
        self._continuation_ws = continuation_ws
        self._continuation_ws_len = len(continuation_ws)
        self._splitchars = splitchars
        self._lines = []
        self._current_line = _Accumulator(headerlen)

    def _str(self, linesep):
        self.newline()
        return linesep.join(self._lines)

    def __str__(self):
        return self._str(NL)

    def newline(self):
        end_of_line = self._current_line.pop()
        if end_of_line != (' ', ''):
            self._current_line.push(*end_of_line)
        if len(self._current_line) > 0:
            if self._current_line.is_onlyws() and self._lines:
                self._lines[-1] += str(self._current_line)
            else:
                self._lines.append(str(self._current_line))
        self._current_line.reset()

    def add_transition(self):
        self._current_line.push(' ', '')

    def feed(self, fws, string, charset):
        # If the charset has no header encoding (i.e. it is an ASCII encoding)
        # then we must split the header at the "highest level syntactic break"
        # possible. Note that we don't have a lot of smarts about field
        # syntax; we just try to break on semi-colons, then commas, then
        # whitespace.  Eventually, this should be pluggable.
        if charset.header_encoding is None:
            self._ascii_split(fws, string, self._splitchars)
            return
        # Otherwise, we're doing either a Base64 or a quoted-printable
        # encoding which means we don't need to split the line on syntactic
        # breaks.  We can basically just find enough characters to fit on the
        # current line, minus the RFC 2047 chrome.  What makes this trickier
        # though is that we have to split at octet boundaries, not character
        # boundaries but it's only safe to split at character boundaries so at
        # best we can only get close.
        encoded_lines = charset.header_encode_lines(string, self._maxlengths())
        # The first element extends the current line, but if it's None then
        # nothing more fit on the current line so start a new line.
        try:
            first_line = encoded_lines.pop(0)
        except IndexError:
            # There are no encoded lines, so we're done.
            return
        if first_line is not None:
            self._append_chunk(fws, first_line)
        try:
            last_line = encoded_lines.pop()
        except IndexError:
            # There was only one line.
            return
        self.newline()
        self._current_line.push(self._continuation_ws, last_line)
        # Everything else are full lines in themselves.
        for line in encoded_lines:
            self._lines.append(self._continuation_ws + line)

    def _maxlengths(self):
        # The first line's length.
        yield self._maxlen - len(self._current_line)
        while True:
            yield self._maxlen - self._continuation_ws_len

    def _ascii_split(self, fws, string, splitchars):
        # The RFC 2822 header folding algorithm is simple in principle but
        # complex in practice.  Lines may be folded any place where "folding
        # white space" appears by inserting a linesep character in front of the
        # FWS.  The complication is that not all spaces or tabs qualify as FWS,
        # and we are also supposed to prefer to break at "higher level
        # syntactic breaks".  We can't do either of these without intimate
        # knowledge of the structure of structured headers, which we don't have
        # here.  So the best we can do here is prefer to break at the specified
        # splitchars, and hope that we don't choose any spaces or tabs that
        # aren't legal FWS.  (This is at least better than the old algorithm,
        # where we would sometimes *introduce* FWS after a splitchar, or the
        # algorithm before that, where we would turn all white space runs into
        # single spaces or tabs.)
        parts = re.split("(["+FWS+"]+)", fws+string)
        if parts[0]:
            parts[:0] = ['']
        else:
            parts.pop(0)
        for fws, part in zip(*[iter(parts)]*2):
            self._append_chunk(fws, part)

    def _append_chunk(self, fws, string):
        self._current_line.push(fws, string)
        if len(self._current_line) > self._maxlen:
            # Find the best split point, working backward from the end.
            # There might be none, on a long first line.
            for ch in self._splitchars:
                for i in range(self._current_line.part_count()-1, 0, -1):
                    if ch.isspace():
                        fws = self._current_line[i][0]
                        if fws and fws[0]==ch:
                            break
                    prevpart = self._current_line[i-1][1]
                    if prevpart and prevpart[-1]==ch:
                        break
                else:
                    continue
                break
            else:
                fws, part = self._current_line.pop()
                if self._current_line._initial_size > 0:
                    # There will be a header, so leave it on a line by itself.
                    self.newline()
                    if not fws:
                        # We don't use continuation_ws here because the whitespace
                        # after a header should always be a space.
                        fws = ' '
                self._current_line.push(fws, part)
                return
            remainder = self._current_line.pop_from(i)
            self._lines.append(str(self._current_line))
            self._current_line.reset(remainder)


class _Accumulator(list):

    def __init__(self, initial_size=0):
        self._initial_size = initial_size
        super().__init__()

    def push(self, fws, string):
        self.append((fws, string))

    def pop_from(self, i=0):
        popped = self[i:]
        self[i:] = []
        return popped

    def pop(self):
        if self.part_count()==0:
            return ('', '')
        return super().pop()

    def __len__(self):
        return sum((len(fws)+len(part) for fws, part in self),
                   self._initial_size)

    def __str__(self):
        return EMPTYSTRING.join((EMPTYSTRING.join((fws, part))
                                for fws, part in self))

    def reset(self, startval=None):
        if startval is None:
            startval = []
        self[:] = startval
        self._initial_size = 0

    def is_onlyws(self):
        return self._initial_size==0 and (not self or str(self).isspace())

    def part_count(self):
        return super().__len__()
headerregistry.py000064400000050523151706203570010152 0ustar00"""Representing and manipulating email headers via custom objects.

This module provides an implementation of the HeaderRegistry API.
The implementation is designed to flexibly follow RFC5322 rules.
"""
from types import MappingProxyType

from email import utils
from email import errors
from email import _header_value_parser as parser

class Address:

    def __init__(self, display_name='', username='', domain='', addr_spec=None):
        """Create an object representing a full email address.

        An address can have a 'display_name', a 'username', and a 'domain'.  In
        addition to specifying the username and domain separately, they may be
        specified together by using the addr_spec keyword *instead of* the
        username and domain keywords.  If an addr_spec string is specified it
        must be properly quoted according to RFC 5322 rules; an error will be
        raised if it is not.

        An Address object has display_name, username, domain, and addr_spec
        attributes, all of which are read-only.  The addr_spec and the string
        value of the object are both quoted according to RFC5322 rules, but
        without any Content Transfer Encoding.

        """

        inputs = ''.join(filter(None, (display_name, username, domain, addr_spec)))
        if '\r' in inputs or '\n' in inputs:
            raise ValueError("invalid arguments; address parts cannot contain CR or LF")

        # This clause with its potential 'raise' may only happen when an
        # application program creates an Address object using an addr_spec
        # keyword.  The email library code itself must always supply username
        # and domain.
        if addr_spec is not None:
            if username or domain:
                raise TypeError("addrspec specified when username and/or "
                                "domain also specified")
            a_s, rest = parser.get_addr_spec(addr_spec)
            if rest:
                raise ValueError("Invalid addr_spec; only '{}' "
                                 "could be parsed from '{}'".format(
                                    a_s, addr_spec))
            if a_s.all_defects:
                raise a_s.all_defects[0]
            username = a_s.local_part
            domain = a_s.domain
        self._display_name = display_name
        self._username = username
        self._domain = domain

    @property
    def display_name(self):
        return self._display_name

    @property
    def username(self):
        return self._username

    @property
    def domain(self):
        return self._domain

    @property
    def addr_spec(self):
        """The addr_spec (username@domain) portion of the address, quoted
        according to RFC 5322 rules, but with no Content Transfer Encoding.
        """
        lp = self.username
        if not parser.DOT_ATOM_ENDS.isdisjoint(lp):
            lp = parser.quote_string(lp)
        if self.domain:
            return lp + '@' + self.domain
        if not lp:
            return '<>'
        return lp

    def __repr__(self):
        return "{}(display_name={!r}, username={!r}, domain={!r})".format(
                        self.__class__.__name__,
                        self.display_name, self.username, self.domain)

    def __str__(self):
        disp = self.display_name
        if not parser.SPECIALS.isdisjoint(disp):
            disp = parser.quote_string(disp)
        if disp:
            addr_spec = '' if self.addr_spec=='<>' else self.addr_spec
            return "{} <{}>".format(disp, addr_spec)
        return self.addr_spec

    def __eq__(self, other):
        if not isinstance(other, Address):
            return NotImplemented
        return (self.display_name == other.display_name and
                self.username == other.username and
                self.domain == other.domain)


class Group:

    def __init__(self, display_name=None, addresses=None):
        """Create an object representing an address group.

        An address group consists of a display_name followed by colon and a
        list of addresses (see Address) terminated by a semi-colon.  The Group
        is created by specifying a display_name and a possibly empty list of
        Address objects.  A Group can also be used to represent a single
        address that is not in a group, which is convenient when manipulating
        lists that are a combination of Groups and individual Addresses.  In
        this case the display_name should be set to None.  In particular, the
        string representation of a Group whose display_name is None is the same
        as the Address object, if there is one and only one Address object in
        the addresses list.

        """
        self._display_name = display_name
        self._addresses = tuple(addresses) if addresses else tuple()

    @property
    def display_name(self):
        return self._display_name

    @property
    def addresses(self):
        return self._addresses

    def __repr__(self):
        return "{}(display_name={!r}, addresses={!r}".format(
                 self.__class__.__name__,
                 self.display_name, self.addresses)

    def __str__(self):
        if self.display_name is None and len(self.addresses)==1:
            return str(self.addresses[0])
        disp = self.display_name
        if disp is not None and not parser.SPECIALS.isdisjoint(disp):
            disp = parser.quote_string(disp)
        adrstr = ", ".join(str(x) for x in self.addresses)
        adrstr = ' ' + adrstr if adrstr else adrstr
        return "{}:{};".format(disp, adrstr)

    def __eq__(self, other):
        if not isinstance(other, Group):
            return NotImplemented
        return (self.display_name == other.display_name and
                self.addresses == other.addresses)


# Header Classes #

class BaseHeader(str):

    """Base class for message headers.

    Implements generic behavior and provides tools for subclasses.

    A subclass must define a classmethod named 'parse' that takes an unfolded
    value string and a dictionary as its arguments.  The dictionary will
    contain one key, 'defects', initialized to an empty list.  After the call
    the dictionary must contain two additional keys: parse_tree, set to the
    parse tree obtained from parsing the header, and 'decoded', set to the
    string value of the idealized representation of the data from the value.
    (That is, encoded words are decoded, and values that have canonical
    representations are so represented.)

    The defects key is intended to collect parsing defects, which the message
    parser will subsequently dispose of as appropriate.  The parser should not,
    insofar as practical, raise any errors.  Defects should be added to the
    list instead.  The standard header parsers register defects for RFC
    compliance issues, for obsolete RFC syntax, and for unrecoverable parsing
    errors.

    The parse method may add additional keys to the dictionary.  In this case
    the subclass must define an 'init' method, which will be passed the
    dictionary as its keyword arguments.  The method should use (usually by
    setting them as the value of similarly named attributes) and remove all the
    extra keys added by its parse method, and then use super to call its parent
    class with the remaining arguments and keywords.

    The subclass should also make sure that a 'max_count' attribute is defined
    that is either None or 1. XXX: need to better define this API.

    """

    def __new__(cls, name, value):
        kwds = {'defects': []}
        cls.parse(value, kwds)
        if utils._has_surrogates(kwds['decoded']):
            kwds['decoded'] = utils._sanitize(kwds['decoded'])
        self = str.__new__(cls, kwds['decoded'])
        del kwds['decoded']
        self.init(name, **kwds)
        return self

    def init(self, name, *, parse_tree, defects):
        self._name = name
        self._parse_tree = parse_tree
        self._defects = defects

    @property
    def name(self):
        return self._name

    @property
    def defects(self):
        return tuple(self._defects)

    def __reduce__(self):
        return (
            _reconstruct_header,
            (
                self.__class__.__name__,
                self.__class__.__bases__,
                str(self),
            ),
            self.__getstate__())

    @classmethod
    def _reconstruct(cls, value):
        return str.__new__(cls, value)

    def fold(self, *, policy):
        """Fold header according to policy.

        The parsed representation of the header is folded according to
        RFC5322 rules, as modified by the policy.  If the parse tree
        contains surrogateescaped bytes, the bytes are CTE encoded using
        the charset 'unknown-8bit".

        Any non-ASCII characters in the parse tree are CTE encoded using
        charset utf-8. XXX: make this a policy setting.

        The returned value is an ASCII-only string possibly containing linesep
        characters, and ending with a linesep character.  The string includes
        the header name and the ': ' separator.

        """
        # At some point we need to put fws here if it was in the source.
        header = parser.Header([
            parser.HeaderLabel([
                parser.ValueTerminal(self.name, 'header-name'),
                parser.ValueTerminal(':', 'header-sep')]),
            ])
        if self._parse_tree:
            header.append(
                parser.CFWSList([parser.WhiteSpaceTerminal(' ', 'fws')]))
        header.append(self._parse_tree)
        return header.fold(policy=policy)


def _reconstruct_header(cls_name, bases, value):
    return type(cls_name, bases, {})._reconstruct(value)


class UnstructuredHeader:

    max_count = None
    value_parser = staticmethod(parser.get_unstructured)

    @classmethod
    def parse(cls, value, kwds):
        kwds['parse_tree'] = cls.value_parser(value)
        kwds['decoded'] = str(kwds['parse_tree'])


class UniqueUnstructuredHeader(UnstructuredHeader):

    max_count = 1


class DateHeader:

    """Header whose value consists of a single timestamp.

    Provides an additional attribute, datetime, which is either an aware
    datetime using a timezone, or a naive datetime if the timezone
    in the input string is -0000.  Also accepts a datetime as input.
    The 'value' attribute is the normalized form of the timestamp,
    which means it is the output of format_datetime on the datetime.
    """

    max_count = None

    # This is used only for folding, not for creating 'decoded'.
    value_parser = staticmethod(parser.get_unstructured)

    @classmethod
    def parse(cls, value, kwds):
        if not value:
            kwds['defects'].append(errors.HeaderMissingRequiredValue())
            kwds['datetime'] = None
            kwds['decoded'] = ''
            kwds['parse_tree'] = parser.TokenList()
            return
        if isinstance(value, str):
            kwds['decoded'] = value
            try:
                value = utils.parsedate_to_datetime(value)
            except ValueError:
                kwds['defects'].append(errors.InvalidDateDefect('Invalid date value or format'))
                kwds['datetime'] = None
                kwds['parse_tree'] = parser.TokenList()
                return
        kwds['datetime'] = value
        kwds['decoded'] = utils.format_datetime(kwds['datetime'])
        kwds['parse_tree'] = cls.value_parser(kwds['decoded'])

    def init(self, *args, **kw):
        self._datetime = kw.pop('datetime')
        super().init(*args, **kw)

    @property
    def datetime(self):
        return self._datetime


class UniqueDateHeader(DateHeader):

    max_count = 1


class AddressHeader:

    max_count = None

    @staticmethod
    def value_parser(value):
        address_list, value = parser.get_address_list(value)
        assert not value, 'this should not happen'
        return address_list

    @classmethod
    def parse(cls, value, kwds):
        if isinstance(value, str):
            # We are translating here from the RFC language (address/mailbox)
            # to our API language (group/address).
            kwds['parse_tree'] = address_list = cls.value_parser(value)
            groups = []
            for addr in address_list.addresses:
                groups.append(Group(addr.display_name,
                                    [Address(mb.display_name or '',
                                             mb.local_part or '',
                                             mb.domain or '')
                                     for mb in addr.all_mailboxes]))
            defects = list(address_list.all_defects)
        else:
            # Assume it is Address/Group stuff
            if not hasattr(value, '__iter__'):
                value = [value]
            groups = [Group(None, [item]) if not hasattr(item, 'addresses')
                                          else item
                                    for item in value]
            defects = []
        kwds['groups'] = groups
        kwds['defects'] = defects
        kwds['decoded'] = ', '.join([str(item) for item in groups])
        if 'parse_tree' not in kwds:
            kwds['parse_tree'] = cls.value_parser(kwds['decoded'])

    def init(self, *args, **kw):
        self._groups = tuple(kw.pop('groups'))
        self._addresses = None
        super().init(*args, **kw)

    @property
    def groups(self):
        return self._groups

    @property
    def addresses(self):
        if self._addresses is None:
            self._addresses = tuple(address for group in self._groups
                                            for address in group.addresses)
        return self._addresses


class UniqueAddressHeader(AddressHeader):

    max_count = 1


class SingleAddressHeader(AddressHeader):

    @property
    def address(self):
        if len(self.addresses)!=1:
            raise ValueError(("value of single address header {} is not "
                "a single address").format(self.name))
        return self.addresses[0]


class UniqueSingleAddressHeader(SingleAddressHeader):

    max_count = 1


class MIMEVersionHeader:

    max_count = 1

    value_parser = staticmethod(parser.parse_mime_version)

    @classmethod
    def parse(cls, value, kwds):
        kwds['parse_tree'] = parse_tree = cls.value_parser(value)
        kwds['decoded'] = str(parse_tree)
        kwds['defects'].extend(parse_tree.all_defects)
        kwds['major'] = None if parse_tree.minor is None else parse_tree.major
        kwds['minor'] = parse_tree.minor
        if parse_tree.minor is not None:
            kwds['version'] = '{}.{}'.format(kwds['major'], kwds['minor'])
        else:
            kwds['version'] = None

    def init(self, *args, **kw):
        self._version = kw.pop('version')
        self._major = kw.pop('major')
        self._minor = kw.pop('minor')
        super().init(*args, **kw)

    @property
    def major(self):
        return self._major

    @property
    def minor(self):
        return self._minor

    @property
    def version(self):
        return self._version


class ParameterizedMIMEHeader:

    # Mixin that handles the params dict.  Must be subclassed and
    # a property value_parser for the specific header provided.

    max_count = 1

    @classmethod
    def parse(cls, value, kwds):
        kwds['parse_tree'] = parse_tree = cls.value_parser(value)
        kwds['decoded'] = str(parse_tree)
        kwds['defects'].extend(parse_tree.all_defects)
        if parse_tree.params is None:
            kwds['params'] = {}
        else:
            # The MIME RFCs specify that parameter ordering is arbitrary.
            kwds['params'] = {utils._sanitize(name).lower():
                                    utils._sanitize(value)
                               for name, value in parse_tree.params}

    def init(self, *args, **kw):
        self._params = kw.pop('params')
        super().init(*args, **kw)

    @property
    def params(self):
        return MappingProxyType(self._params)


class ContentTypeHeader(ParameterizedMIMEHeader):

    value_parser = staticmethod(parser.parse_content_type_header)

    def init(self, *args, **kw):
        super().init(*args, **kw)
        self._maintype = utils._sanitize(self._parse_tree.maintype)
        self._subtype = utils._sanitize(self._parse_tree.subtype)

    @property
    def maintype(self):
        return self._maintype

    @property
    def subtype(self):
        return self._subtype

    @property
    def content_type(self):
        return self.maintype + '/' + self.subtype


class ContentDispositionHeader(ParameterizedMIMEHeader):

    value_parser = staticmethod(parser.parse_content_disposition_header)

    def init(self, *args, **kw):
        super().init(*args, **kw)
        cd = self._parse_tree.content_disposition
        self._content_disposition = cd if cd is None else utils._sanitize(cd)

    @property
    def content_disposition(self):
        return self._content_disposition


class ContentTransferEncodingHeader:

    max_count = 1

    value_parser = staticmethod(parser.parse_content_transfer_encoding_header)

    @classmethod
    def parse(cls, value, kwds):
        kwds['parse_tree'] = parse_tree = cls.value_parser(value)
        kwds['decoded'] = str(parse_tree)
        kwds['defects'].extend(parse_tree.all_defects)

    def init(self, *args, **kw):
        super().init(*args, **kw)
        self._cte = utils._sanitize(self._parse_tree.cte)

    @property
    def cte(self):
        return self._cte


class MessageIDHeader:

    max_count = 1
    value_parser = staticmethod(parser.parse_message_id)

    @classmethod
    def parse(cls, value, kwds):
        kwds['parse_tree'] = parse_tree = cls.value_parser(value)
        kwds['decoded'] = str(parse_tree)
        kwds['defects'].extend(parse_tree.all_defects)


# The header factory #

_default_header_map = {
    'subject':                      UniqueUnstructuredHeader,
    'date':                         UniqueDateHeader,
    'resent-date':                  DateHeader,
    'orig-date':                    UniqueDateHeader,
    'sender':                       UniqueSingleAddressHeader,
    'resent-sender':                SingleAddressHeader,
    'to':                           UniqueAddressHeader,
    'resent-to':                    AddressHeader,
    'cc':                           UniqueAddressHeader,
    'resent-cc':                    AddressHeader,
    'bcc':                          UniqueAddressHeader,
    'resent-bcc':                   AddressHeader,
    'from':                         UniqueAddressHeader,
    'resent-from':                  AddressHeader,
    'reply-to':                     UniqueAddressHeader,
    'mime-version':                 MIMEVersionHeader,
    'content-type':                 ContentTypeHeader,
    'content-disposition':          ContentDispositionHeader,
    'content-transfer-encoding':    ContentTransferEncodingHeader,
    'message-id':                   MessageIDHeader,
    }

class HeaderRegistry:

    """A header_factory and header registry."""

    def __init__(self, base_class=BaseHeader, default_class=UnstructuredHeader,
                       use_default_map=True):
        """Create a header_factory that works with the Policy API.

        base_class is the class that will be the last class in the created
        header class's __bases__ list.  default_class is the class that will be
        used if "name" (see __call__) does not appear in the registry.
        use_default_map controls whether or not the default mapping of names to
        specialized classes is copied in to the registry when the factory is
        created.  The default is True.

        """
        self.registry = {}
        self.base_class = base_class
        self.default_class = default_class
        if use_default_map:
            self.registry.update(_default_header_map)

    def map_to_type(self, name, cls):
        """Register cls as the specialized class for handling "name" headers.

        """
        self.registry[name.lower()] = cls

    def __getitem__(self, name):
        cls = self.registry.get(name.lower(), self.default_class)
        return type('_'+cls.__name__, (cls, self.base_class), {})

    def __call__(self, name, value):
        """Create a header instance for header 'name' from 'value'.

        Creates a header instance by creating a specialized class for parsing
        and representing the specified header by combining the factory
        base_class with a specialized class from the registry or the
        default_class, and passing the name and value to the constructed
        class's constructor.

        """
        return self[name](name, value)
iterators.py000064400000004121151706203570007136 0ustar00# Copyright (C) 2001-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Various types of useful iterators and generators."""

__all__ = [
    'body_line_iterator',
    'typed_subpart_iterator',
    'walk',
    # Do not include _structure() since it's part of the debugging API.
    ]

import sys
from io import StringIO


# This function will become a method of the Message class
def walk(self):
    """Walk over the message tree, yielding each subpart.

    The walk is performed in depth-first order.  This method is a
    generator.
    """
    yield self
    if self.is_multipart():
        for subpart in self.get_payload():
            yield from subpart.walk()


# These two functions are imported into the Iterators.py interface module.
def body_line_iterator(msg, decode=False):
    """Iterate over the parts, returning string payloads line-by-line.

    Optional decode (default False) is passed through to .get_payload().
    """
    for subpart in msg.walk():
        payload = subpart.get_payload(decode=decode)
        if isinstance(payload, str):
            yield from StringIO(payload)


def typed_subpart_iterator(msg, maintype='text', subtype=None):
    """Iterate over the subparts with a given MIME type.

    Use `maintype' as the main MIME type to match against; this defaults to
    "text".  Optional `subtype' is the MIME subtype to match against; if
    omitted, only the main type is matched.
    """
    for subpart in msg.walk():
        if subpart.get_content_maintype() == maintype:
            if subtype is None or subpart.get_content_subtype() == subtype:
                yield subpart


def _structure(msg, fp=None, level=0, include_default=False):
    """A handy debugging aid"""
    if fp is None:
        fp = sys.stdout
    tab = ' ' * (level * 4)
    print(tab + msg.get_content_type(), end='', file=fp)
    if include_default:
        print(' [%s]' % msg.get_default_type(), file=fp)
    else:
        print(file=fp)
    if msg.is_multipart():
        for subpart in msg.get_payload():
            _structure(subpart, fp, level+1, include_default)
message.py000064400000136127151706203570006562 0ustar00# Copyright (C) 2001-2007 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Basic message object for the email package object model."""

__all__ = ['Message', 'EmailMessage']

import binascii
import re
import quopri
from io import BytesIO, StringIO

# Intrapackage imports
from email import utils
from email import errors
from email._policybase import compat32
from email import charset as _charset
from email._encoded_words import decode_b
Charset = _charset.Charset

SEMISPACE = '; '

# Regular expression that matches `special' characters in parameters, the
# existence of which force quoting of the parameter value.
tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]')


def _splitparam(param):
    # Split header parameters.  BAW: this may be too simple.  It isn't
    # strictly RFC 2045 (section 5.1) compliant, but it catches most headers
    # found in the wild.  We may eventually need a full fledged parser.
    # RDM: we might have a Header here; for now just stringify it.
    a, sep, b = str(param).partition(';')
    if not sep:
        return a.strip(), None
    return a.strip(), b.strip()

def _formatparam(param, value=None, quote=True):
    """Convenience function to format and return a key=value pair.

    This will quote the value if needed or if quote is true.  If value is a
    three tuple (charset, language, value), it will be encoded according
    to RFC2231 rules.  If it contains non-ascii characters it will likewise
    be encoded according to RFC2231 rules, using the utf-8 charset and
    a null language.
    """
    if value is not None and len(value) > 0:
        # A tuple is used for RFC 2231 encoded parameter values where items
        # are (charset, language, value).  charset is a string, not a Charset
        # instance.  RFC 2231 encoded values are never quoted, per RFC.
        if isinstance(value, tuple):
            # Encode as per RFC 2231
            param += '*'
            value = utils.encode_rfc2231(value[2], value[0], value[1])
            return '%s=%s' % (param, value)
        else:
            try:
                value.encode('ascii')
            except UnicodeEncodeError:
                param += '*'
                value = utils.encode_rfc2231(value, 'utf-8', '')
                return '%s=%s' % (param, value)
        # BAW: Please check this.  I think that if quote is set it should
        # force quoting even if not necessary.
        if quote or tspecials.search(value):
            return '%s="%s"' % (param, utils.quote(value))
        else:
            return '%s=%s' % (param, value)
    else:
        return param

def _parseparam(s):
    # RDM This might be a Header, so for now stringify it.
    s = ';' + str(s)
    plist = []
    while s[:1] == ';':
        s = s[1:]
        end = s.find(';')
        while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
            end = s.find(';', end + 1)
        if end < 0:
            end = len(s)
        f = s[:end]
        if '=' in f:
            i = f.index('=')
            f = f[:i].strip().lower() + '=' + f[i+1:].strip()
        plist.append(f.strip())
        s = s[end:]
    return plist


def _unquotevalue(value):
    # This is different than utils.collapse_rfc2231_value() because it doesn't
    # try to convert the value to a unicode.  Message.get_param() and
    # Message.get_params() are both currently defined to return the tuple in
    # the face of RFC 2231 parameters.
    if isinstance(value, tuple):
        return value[0], value[1], utils.unquote(value[2])
    else:
        return utils.unquote(value)


def _decode_uu(encoded):
    """Decode uuencoded data."""
    decoded_lines = []
    encoded_lines_iter = iter(encoded.splitlines())
    for line in encoded_lines_iter:
        if line.startswith(b"begin "):
            mode, _, path = line.removeprefix(b"begin ").partition(b" ")
            try:
                int(mode, base=8)
            except ValueError:
                continue
            else:
                break
    else:
        raise ValueError("`begin` line not found")
    for line in encoded_lines_iter:
        if not line:
            raise ValueError("Truncated input")
        elif line.strip(b' \t\r\n\f') == b'end':
            break
        try:
            decoded_line = binascii.a2b_uu(line)
        except binascii.Error:
            # Workaround for broken uuencoders by /Fredrik Lundh
            nbytes = (((line[0]-32) & 63) * 4 + 5) // 3
            decoded_line = binascii.a2b_uu(line[:nbytes])
        decoded_lines.append(decoded_line)

    return b''.join(decoded_lines)


class Message:
    """Basic message object.

    A message object is defined as something that has a bunch of RFC 2822
    headers and a payload.  It may optionally have an envelope header
    (a.k.a. Unix-From or From_ header).  If the message is a container (i.e. a
    multipart or a message/rfc822), then the payload is a list of Message
    objects, otherwise it is a string.

    Message objects implement part of the `mapping' interface, which assumes
    there is exactly one occurrence of the header per message.  Some headers
    do in fact appear multiple times (e.g. Received) and for those headers,
    you must use the explicit API to set or get all the headers.  Not all of
    the mapping methods are implemented.
    """
    def __init__(self, policy=compat32):
        self.policy = policy
        self._headers = []
        self._unixfrom = None
        self._payload = None
        self._charset = None
        # Defaults for multipart messages
        self.preamble = self.epilogue = None
        self.defects = []
        # Default content type
        self._default_type = 'text/plain'

    def __str__(self):
        """Return the entire formatted message as a string.
        """
        return self.as_string()

    def as_string(self, unixfrom=False, maxheaderlen=0, policy=None):
        """Return the entire formatted message as a string.

        Optional 'unixfrom', when true, means include the Unix From_ envelope
        header.  For backward compatibility reasons, if maxheaderlen is
        not specified it defaults to 0, so you must override it explicitly
        if you want a different maxheaderlen.  'policy' is passed to the
        Generator instance used to serialize the message; if it is not
        specified the policy associated with the message instance is used.

        If the message object contains binary data that is not encoded
        according to RFC standards, the non-compliant data will be replaced by
        unicode "unknown character" code points.
        """
        from email.generator import Generator
        policy = self.policy if policy is None else policy
        fp = StringIO()
        g = Generator(fp,
                      mangle_from_=False,
                      maxheaderlen=maxheaderlen,
                      policy=policy)
        g.flatten(self, unixfrom=unixfrom)
        return fp.getvalue()

    def __bytes__(self):
        """Return the entire formatted message as a bytes object.
        """
        return self.as_bytes()

    def as_bytes(self, unixfrom=False, policy=None):
        """Return the entire formatted message as a bytes object.

        Optional 'unixfrom', when true, means include the Unix From_ envelope
        header.  'policy' is passed to the BytesGenerator instance used to
        serialize the message; if not specified the policy associated with
        the message instance is used.
        """
        from email.generator import BytesGenerator
        policy = self.policy if policy is None else policy
        fp = BytesIO()
        g = BytesGenerator(fp, mangle_from_=False, policy=policy)
        g.flatten(self, unixfrom=unixfrom)
        return fp.getvalue()

    def is_multipart(self):
        """Return True if the message consists of multiple parts."""
        return isinstance(self._payload, list)

    #
    # Unix From_ line
    #
    def set_unixfrom(self, unixfrom):
        self._unixfrom = unixfrom

    def get_unixfrom(self):
        return self._unixfrom

    #
    # Payload manipulation.
    #
    def attach(self, payload):
        """Add the given payload to the current payload.

        The current payload will always be a list of objects after this method
        is called.  If you want to set the payload to a scalar object, use
        set_payload() instead.
        """
        if self._payload is None:
            self._payload = [payload]
        else:
            try:
                self._payload.append(payload)
            except AttributeError:
                raise TypeError("Attach is not valid on a message with a"
                                " non-multipart payload")

    def get_payload(self, i=None, decode=False):
        """Return a reference to the payload.

        The payload will either be a list object or a string.  If you mutate
        the list object, you modify the message's payload in place.  Optional
        i returns that index into the payload.

        Optional decode is a flag indicating whether the payload should be
        decoded or not, according to the Content-Transfer-Encoding header
        (default is False).

        When True and the message is not a multipart, the payload will be
        decoded if this header's value is `quoted-printable' or `base64'.  If
        some other encoding is used, or the header is missing, or if the
        payload has bogus data (i.e. bogus base64 or uuencoded data), the
        payload is returned as-is.

        If the message is a multipart and the decode flag is True, then None
        is returned.
        """
        # Here is the logic table for this code, based on the email5.0.0 code:
        #   i     decode  is_multipart  result
        # ------  ------  ------------  ------------------------------
        #  None   True    True          None
        #   i     True    True          None
        #  None   False   True          _payload (a list)
        #   i     False   True          _payload element i (a Message)
        #   i     False   False         error (not a list)
        #   i     True    False         error (not a list)
        #  None   False   False         _payload
        #  None   True    False         _payload decoded (bytes)
        # Note that Barry planned to factor out the 'decode' case, but that
        # isn't so easy now that we handle the 8 bit data, which needs to be
        # converted in both the decode and non-decode path.
        if self.is_multipart():
            if decode:
                return None
            if i is None:
                return self._payload
            else:
                return self._payload[i]
        # For backward compatibility, Use isinstance and this error message
        # instead of the more logical is_multipart test.
        if i is not None and not isinstance(self._payload, list):
            raise TypeError('Expected list, got %s' % type(self._payload))
        payload = self._payload
        cte = self.get('content-transfer-encoding', '')
        if hasattr(cte, 'cte'):
            cte = cte.cte
        else:
            # cte might be a Header, so for now stringify it.
            cte = str(cte).strip().lower()
        # payload may be bytes here.
        if not decode:
            if isinstance(payload, str) and utils._has_surrogates(payload):
                try:
                    bpayload = payload.encode('ascii', 'surrogateescape')
                    try:
                        payload = bpayload.decode(self.get_content_charset('ascii'), 'replace')
                    except LookupError:
                        payload = bpayload.decode('ascii', 'replace')
                except UnicodeEncodeError:
                    pass
            return payload
        if isinstance(payload, str):
            try:
                bpayload = payload.encode('ascii', 'surrogateescape')
            except UnicodeEncodeError:
                # This won't happen for RFC compliant messages (messages
                # containing only ASCII code points in the unicode input).
                # If it does happen, turn the string into bytes in a way
                # guaranteed not to fail.
                bpayload = payload.encode('raw-unicode-escape')
        if cte == 'quoted-printable':
            return quopri.decodestring(bpayload)
        elif cte == 'base64':
            # XXX: this is a bit of a hack; decode_b should probably be factored
            # out somewhere, but I haven't figured out where yet.
            value, defects = decode_b(b''.join(bpayload.splitlines()))
            for defect in defects:
                self.policy.handle_defect(self, defect)
            return value
        elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
            try:
                return _decode_uu(bpayload)
            except ValueError:
                # Some decoding problem.
                return bpayload
        if isinstance(payload, str):
            return bpayload
        return payload

    def set_payload(self, payload, charset=None):
        """Set the payload to the given value.

        Optional charset sets the message's default character set.  See
        set_charset() for details.
        """
        if hasattr(payload, 'encode'):
            if charset is None:
                self._payload = payload
                return
            if not isinstance(charset, Charset):
                charset = Charset(charset)
            payload = payload.encode(charset.output_charset, 'surrogateescape')
        if hasattr(payload, 'decode'):
            self._payload = payload.decode('ascii', 'surrogateescape')
        else:
            self._payload = payload
        if charset is not None:
            self.set_charset(charset)

    def set_charset(self, charset):
        """Set the charset of the payload to a given character set.

        charset can be a Charset instance, a string naming a character set, or
        None.  If it is a string it will be converted to a Charset instance.
        If charset is None, the charset parameter will be removed from the
        Content-Type field.  Anything else will generate a TypeError.

        The message will be assumed to be of type text/* encoded with
        charset.input_charset.  It will be converted to charset.output_charset
        and encoded properly, if needed, when generating the plain text
        representation of the message.  MIME headers (MIME-Version,
        Content-Type, Content-Transfer-Encoding) will be added as needed.
        """
        if charset is None:
            self.del_param('charset')
            self._charset = None
            return
        if not isinstance(charset, Charset):
            charset = Charset(charset)
        self._charset = charset
        if 'MIME-Version' not in self:
            self.add_header('MIME-Version', '1.0')
        if 'Content-Type' not in self:
            self.add_header('Content-Type', 'text/plain',
                            charset=charset.get_output_charset())
        else:
            self.set_param('charset', charset.get_output_charset())
        if charset != charset.get_output_charset():
            self._payload = charset.body_encode(self._payload)
        if 'Content-Transfer-Encoding' not in self:
            cte = charset.get_body_encoding()
            try:
                cte(self)
            except TypeError:
                # This 'if' is for backward compatibility, it allows unicode
                # through even though that won't work correctly if the
                # message is serialized.
                payload = self._payload
                if payload:
                    try:
                        payload = payload.encode('ascii', 'surrogateescape')
                    except UnicodeError:
                        payload = payload.encode(charset.output_charset)
                self._payload = charset.body_encode(payload)
                self.add_header('Content-Transfer-Encoding', cte)

    def get_charset(self):
        """Return the Charset instance associated with the message's payload.
        """
        return self._charset

    #
    # MAPPING INTERFACE (partial)
    #
    def __len__(self):
        """Return the total number of headers, including duplicates."""
        return len(self._headers)

    def __getitem__(self, name):
        """Get a header value.

        Return None if the header is missing instead of raising an exception.

        Note that if the header appeared multiple times, exactly which
        occurrence gets returned is undefined.  Use get_all() to get all
        the values matching a header field name.
        """
        return self.get(name)

    def __setitem__(self, name, val):
        """Set the value of a header.

        Note: this does not overwrite an existing header with the same field
        name.  Use __delitem__() first to delete any existing headers.
        """
        max_count = self.policy.header_max_count(name)
        if max_count:
            lname = name.lower()
            found = 0
            for k, v in self._headers:
                if k.lower() == lname:
                    found += 1
                    if found >= max_count:
                        raise ValueError("There may be at most {} {} headers "
                                         "in a message".format(max_count, name))
        self._headers.append(self.policy.header_store_parse(name, val))

    def __delitem__(self, name):
        """Delete all occurrences of a header, if present.

        Does not raise an exception if the header is missing.
        """
        name = name.lower()
        newheaders = []
        for k, v in self._headers:
            if k.lower() != name:
                newheaders.append((k, v))
        self._headers = newheaders

    def __contains__(self, name):
        name_lower = name.lower()
        for k, v in self._headers:
            if name_lower == k.lower():
                return True
        return False

    def __iter__(self):
        for field, value in self._headers:
            yield field

    def keys(self):
        """Return a list of all the message's header field names.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        """
        return [k for k, v in self._headers]

    def values(self):
        """Return a list of all the message's header values.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        """
        return [self.policy.header_fetch_parse(k, v)
                for k, v in self._headers]

    def items(self):
        """Get all the message's header fields and values.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        """
        return [(k, self.policy.header_fetch_parse(k, v))
                for k, v in self._headers]

    def get(self, name, failobj=None):
        """Get a header value.

        Like __getitem__() but return failobj instead of None when the field
        is missing.
        """
        name = name.lower()
        for k, v in self._headers:
            if k.lower() == name:
                return self.policy.header_fetch_parse(k, v)
        return failobj

    #
    # "Internal" methods (public API, but only intended for use by a parser
    # or generator, not normal application code.
    #

    def set_raw(self, name, value):
        """Store name and value in the model without modification.

        This is an "internal" API, intended only for use by a parser.
        """
        self._headers.append((name, value))

    def raw_items(self):
        """Return the (name, value) header pairs without modification.

        This is an "internal" API, intended only for use by a generator.
        """
        return iter(self._headers.copy())

    #
    # Additional useful stuff
    #

    def get_all(self, name, failobj=None):
        """Return a list of all the values for the named field.

        These will be sorted in the order they appeared in the original
        message, and may contain duplicates.  Any fields deleted and
        re-inserted are always appended to the header list.

        If no such fields exist, failobj is returned (defaults to None).
        """
        values = []
        name = name.lower()
        for k, v in self._headers:
            if k.lower() == name:
                values.append(self.policy.header_fetch_parse(k, v))
        if not values:
            return failobj
        return values

    def add_header(self, _name, _value, **_params):
        """Extended header setting.

        name is the header field to add.  keyword arguments can be used to set
        additional parameters for the header field, with underscores converted
        to dashes.  Normally the parameter will be added as key="value" unless
        value is None, in which case only the key will be added.  If a
        parameter value contains non-ASCII characters it can be specified as a
        three-tuple of (charset, language, value), in which case it will be
        encoded according to RFC2231 rules.  Otherwise it will be encoded using
        the utf-8 charset and a language of ''.

        Examples:

        msg.add_header('content-disposition', 'attachment', filename='bud.gif')
        msg.add_header('content-disposition', 'attachment',
                       filename=('utf-8', '', Fußballer.ppt'))
        msg.add_header('content-disposition', 'attachment',
                       filename='Fußballer.ppt'))
        """
        parts = []
        for k, v in _params.items():
            if v is None:
                parts.append(k.replace('_', '-'))
            else:
                parts.append(_formatparam(k.replace('_', '-'), v))
        if _value is not None:
            parts.insert(0, _value)
        self[_name] = SEMISPACE.join(parts)

    def replace_header(self, _name, _value):
        """Replace a header.

        Replace the first matching header found in the message, retaining
        header order and case.  If no matching header was found, a KeyError is
        raised.
        """
        _name = _name.lower()
        for i, (k, v) in zip(range(len(self._headers)), self._headers):
            if k.lower() == _name:
                self._headers[i] = self.policy.header_store_parse(k, _value)
                break
        else:
            raise KeyError(_name)

    #
    # Use these three methods instead of the three above.
    #

    def get_content_type(self):
        """Return the message's content type.

        The returned string is coerced to lower case of the form
        `maintype/subtype'.  If there was no Content-Type header in the
        message, the default type as given by get_default_type() will be
        returned.  Since according to RFC 2045, messages always have a default
        type this will always return a value.

        RFC 2045 defines a message's default type to be text/plain unless it
        appears inside a multipart/digest container, in which case it would be
        message/rfc822.
        """
        missing = object()
        value = self.get('content-type', missing)
        if value is missing:
            # This should have no parameters
            return self.get_default_type()
        ctype = _splitparam(value)[0].lower()
        # RFC 2045, section 5.2 says if its invalid, use text/plain
        if ctype.count('/') != 1:
            return 'text/plain'
        return ctype

    def get_content_maintype(self):
        """Return the message's main content type.

        This is the `maintype' part of the string returned by
        get_content_type().
        """
        ctype = self.get_content_type()
        return ctype.split('/')[0]

    def get_content_subtype(self):
        """Returns the message's sub-content type.

        This is the `subtype' part of the string returned by
        get_content_type().
        """
        ctype = self.get_content_type()
        return ctype.split('/')[1]

    def get_default_type(self):
        """Return the `default' content type.

        Most messages have a default content type of text/plain, except for
        messages that are subparts of multipart/digest containers.  Such
        subparts have a default content type of message/rfc822.
        """
        return self._default_type

    def set_default_type(self, ctype):
        """Set the `default' content type.

        ctype should be either "text/plain" or "message/rfc822", although this
        is not enforced.  The default content type is not stored in the
        Content-Type header.
        """
        self._default_type = ctype

    def _get_params_preserve(self, failobj, header):
        # Like get_params() but preserves the quoting of values.  BAW:
        # should this be part of the public interface?
        missing = object()
        value = self.get(header, missing)
        if value is missing:
            return failobj
        params = []
        for p in _parseparam(value):
            try:
                name, val = p.split('=', 1)
                name = name.strip()
                val = val.strip()
            except ValueError:
                # Must have been a bare attribute
                name = p.strip()
                val = ''
            params.append((name, val))
        params = utils.decode_params(params)
        return params

    def get_params(self, failobj=None, header='content-type', unquote=True):
        """Return the message's Content-Type parameters, as a list.

        The elements of the returned list are 2-tuples of key/value pairs, as
        split on the `=' sign.  The left hand side of the `=' is the key,
        while the right hand side is the value.  If there is no `=' sign in
        the parameter the value is the empty string.  The value is as
        described in the get_param() method.

        Optional failobj is the object to return if there is no Content-Type
        header.  Optional header is the header to search instead of
        Content-Type.  If unquote is True, the value is unquoted.
        """
        missing = object()
        params = self._get_params_preserve(missing, header)
        if params is missing:
            return failobj
        if unquote:
            return [(k, _unquotevalue(v)) for k, v in params]
        else:
            return params

    def get_param(self, param, failobj=None, header='content-type',
                  unquote=True):
        """Return the parameter value if found in the Content-Type header.

        Optional failobj is the object to return if there is no Content-Type
        header, or the Content-Type header has no such parameter.  Optional
        header is the header to search instead of Content-Type.

        Parameter keys are always compared case insensitively.  The return
        value can either be a string, or a 3-tuple if the parameter was RFC
        2231 encoded.  When it's a 3-tuple, the elements of the value are of
        the form (CHARSET, LANGUAGE, VALUE).  Note that both CHARSET and
        LANGUAGE can be None, in which case you should consider VALUE to be
        encoded in the us-ascii charset.  You can usually ignore LANGUAGE.
        The parameter value (either the returned string, or the VALUE item in
        the 3-tuple) is always unquoted, unless unquote is set to False.

        If your application doesn't care whether the parameter was RFC 2231
        encoded, it can turn the return value into a string as follows:

            rawparam = msg.get_param('foo')
            param = email.utils.collapse_rfc2231_value(rawparam)

        """
        if header not in self:
            return failobj
        for k, v in self._get_params_preserve(failobj, header):
            if k.lower() == param.lower():
                if unquote:
                    return _unquotevalue(v)
                else:
                    return v
        return failobj

    def set_param(self, param, value, header='Content-Type', requote=True,
                  charset=None, language='', replace=False):
        """Set a parameter in the Content-Type header.

        If the parameter already exists in the header, its value will be
        replaced with the new value.

        If header is Content-Type and has not yet been defined for this
        message, it will be set to "text/plain" and the new parameter and
        value will be appended as per RFC 2045.

        An alternate header can be specified in the header argument, and all
        parameters will be quoted as necessary unless requote is False.

        If charset is specified, the parameter will be encoded according to RFC
        2231.  Optional language specifies the RFC 2231 language, defaulting
        to the empty string.  Both charset and language should be strings.
        """
        if not isinstance(value, tuple) and charset:
            value = (charset, language, value)

        if header not in self and header.lower() == 'content-type':
            ctype = 'text/plain'
        else:
            ctype = self.get(header)
        if not self.get_param(param, header=header):
            if not ctype:
                ctype = _formatparam(param, value, requote)
            else:
                ctype = SEMISPACE.join(
                    [ctype, _formatparam(param, value, requote)])
        else:
            ctype = ''
            for old_param, old_value in self.get_params(header=header,
                                                        unquote=requote):
                append_param = ''
                if old_param.lower() == param.lower():
                    append_param = _formatparam(param, value, requote)
                else:
                    append_param = _formatparam(old_param, old_value, requote)
                if not ctype:
                    ctype = append_param
                else:
                    ctype = SEMISPACE.join([ctype, append_param])
        if ctype != self.get(header):
            if replace:
                self.replace_header(header, ctype)
            else:
                del self[header]
                self[header] = ctype

    def del_param(self, param, header='content-type', requote=True):
        """Remove the given parameter completely from the Content-Type header.

        The header will be re-written in place without the parameter or its
        value. All values will be quoted as necessary unless requote is
        False.  Optional header specifies an alternative to the Content-Type
        header.
        """
        if header not in self:
            return
        new_ctype = ''
        for p, v in self.get_params(header=header, unquote=requote):
            if p.lower() != param.lower():
                if not new_ctype:
                    new_ctype = _formatparam(p, v, requote)
                else:
                    new_ctype = SEMISPACE.join([new_ctype,
                                                _formatparam(p, v, requote)])
        if new_ctype != self.get(header):
            del self[header]
            self[header] = new_ctype

    def set_type(self, type, header='Content-Type', requote=True):
        """Set the main type and subtype for the Content-Type header.

        type must be a string in the form "maintype/subtype", otherwise a
        ValueError is raised.

        This method replaces the Content-Type header, keeping all the
        parameters in place.  If requote is False, this leaves the existing
        header's quoting as is.  Otherwise, the parameters will be quoted (the
        default).

        An alternative header can be specified in the header argument.  When
        the Content-Type header is set, we'll always also add a MIME-Version
        header.
        """
        # BAW: should we be strict?
        if not type.count('/') == 1:
            raise ValueError
        # Set the Content-Type, you get a MIME-Version
        if header.lower() == 'content-type':
            del self['mime-version']
            self['MIME-Version'] = '1.0'
        if header not in self:
            self[header] = type
            return
        params = self.get_params(header=header, unquote=requote)
        del self[header]
        self[header] = type
        # Skip the first param; it's the old type.
        for p, v in params[1:]:
            self.set_param(p, v, header, requote)

    def get_filename(self, failobj=None):
        """Return the filename associated with the payload if present.

        The filename is extracted from the Content-Disposition header's
        `filename' parameter, and it is unquoted.  If that header is missing
        the `filename' parameter, this method falls back to looking for the
        `name' parameter.
        """
        missing = object()
        filename = self.get_param('filename', missing, 'content-disposition')
        if filename is missing:
            filename = self.get_param('name', missing, 'content-type')
        if filename is missing:
            return failobj
        return utils.collapse_rfc2231_value(filename).strip()

    def get_boundary(self, failobj=None):
        """Return the boundary associated with the payload if present.

        The boundary is extracted from the Content-Type header's `boundary'
        parameter, and it is unquoted.
        """
        missing = object()
        boundary = self.get_param('boundary', missing)
        if boundary is missing:
            return failobj
        # RFC 2046 says that boundaries may begin but not end in w/s
        return utils.collapse_rfc2231_value(boundary).rstrip()

    def set_boundary(self, boundary):
        """Set the boundary parameter in Content-Type to 'boundary'.

        This is subtly different than deleting the Content-Type header and
        adding a new one with a new boundary parameter via add_header().  The
        main difference is that using the set_boundary() method preserves the
        order of the Content-Type header in the original message.

        HeaderParseError is raised if the message has no Content-Type header.
        """
        missing = object()
        params = self._get_params_preserve(missing, 'content-type')
        if params is missing:
            # There was no Content-Type header, and we don't know what type
            # to set it to, so raise an exception.
            raise errors.HeaderParseError('No Content-Type header found')
        newparams = []
        foundp = False
        for pk, pv in params:
            if pk.lower() == 'boundary':
                newparams.append(('boundary', '"%s"' % boundary))
                foundp = True
            else:
                newparams.append((pk, pv))
        if not foundp:
            # The original Content-Type header had no boundary attribute.
            # Tack one on the end.  BAW: should we raise an exception
            # instead???
            newparams.append(('boundary', '"%s"' % boundary))
        # Replace the existing Content-Type header with the new value
        newheaders = []
        for h, v in self._headers:
            if h.lower() == 'content-type':
                parts = []
                for k, v in newparams:
                    if v == '':
                        parts.append(k)
                    else:
                        parts.append('%s=%s' % (k, v))
                val = SEMISPACE.join(parts)
                newheaders.append(self.policy.header_store_parse(h, val))

            else:
                newheaders.append((h, v))
        self._headers = newheaders

    def get_content_charset(self, failobj=None):
        """Return the charset parameter of the Content-Type header.

        The returned string is always coerced to lower case.  If there is no
        Content-Type header, or if that header has no charset parameter,
        failobj is returned.
        """
        missing = object()
        charset = self.get_param('charset', missing)
        if charset is missing:
            return failobj
        if isinstance(charset, tuple):
            # RFC 2231 encoded, so decode it, and it better end up as ascii.
            pcharset = charset[0] or 'us-ascii'
            try:
                # LookupError will be raised if the charset isn't known to
                # Python.  UnicodeError will be raised if the encoded text
                # contains a character not in the charset.
                as_bytes = charset[2].encode('raw-unicode-escape')
                charset = str(as_bytes, pcharset)
            except (LookupError, UnicodeError):
                charset = charset[2]
        # charset characters must be in us-ascii range
        try:
            charset.encode('us-ascii')
        except UnicodeError:
            return failobj
        # RFC 2046, $4.1.2 says charsets are not case sensitive
        return charset.lower()

    def get_charsets(self, failobj=None):
        """Return a list containing the charset(s) used in this message.

        The returned list of items describes the Content-Type headers'
        charset parameter for this message and all the subparts in its
        payload.

        Each item will either be a string (the value of the charset parameter
        in the Content-Type header of that part) or the value of the
        'failobj' parameter (defaults to None), if the part does not have a
        main MIME type of "text", or the charset is not defined.

        The list will contain one string for each part of the message, plus
        one for the container message (i.e. self), so that a non-multipart
        message will still return a list of length 1.
        """
        return [part.get_content_charset(failobj) for part in self.walk()]

    def get_content_disposition(self):
        """Return the message's content-disposition if it exists, or None.

        The return values can be either 'inline', 'attachment' or None
        according to the rfc2183.
        """
        value = self.get('content-disposition')
        if value is None:
            return None
        c_d = _splitparam(value)[0].lower()
        return c_d

    # I.e. def walk(self): ...
    from email.iterators import walk


class MIMEPart(Message):

    def __init__(self, policy=None):
        if policy is None:
            from email.policy import default
            policy = default
        super().__init__(policy)


    def as_string(self, unixfrom=False, maxheaderlen=None, policy=None):
        """Return the entire formatted message as a string.

        Optional 'unixfrom', when true, means include the Unix From_ envelope
        header.  maxheaderlen is retained for backward compatibility with the
        base Message class, but defaults to None, meaning that the policy value
        for max_line_length controls the header maximum length.  'policy' is
        passed to the Generator instance used to serialize the message; if it
        is not specified the policy associated with the message instance is
        used.
        """
        policy = self.policy if policy is None else policy
        if maxheaderlen is None:
            maxheaderlen = policy.max_line_length
        return super().as_string(unixfrom, maxheaderlen, policy)

    def __str__(self):
        return self.as_string(policy=self.policy.clone(utf8=True))

    def is_attachment(self):
        c_d = self.get('content-disposition')
        return False if c_d is None else c_d.content_disposition == 'attachment'

    def _find_body(self, part, preferencelist):
        if part.is_attachment():
            return
        maintype, subtype = part.get_content_type().split('/')
        if maintype == 'text':
            if subtype in preferencelist:
                yield (preferencelist.index(subtype), part)
            return
        if maintype != 'multipart' or not self.is_multipart():
            return
        if subtype != 'related':
            for subpart in part.iter_parts():
                yield from self._find_body(subpart, preferencelist)
            return
        if 'related' in preferencelist:
            yield (preferencelist.index('related'), part)
        candidate = None
        start = part.get_param('start')
        if start:
            for subpart in part.iter_parts():
                if subpart['content-id'] == start:
                    candidate = subpart
                    break
        if candidate is None:
            subparts = part.get_payload()
            candidate = subparts[0] if subparts else None
        if candidate is not None:
            yield from self._find_body(candidate, preferencelist)

    def get_body(self, preferencelist=('related', 'html', 'plain')):
        """Return best candidate mime part for display as 'body' of message.

        Do a depth first search, starting with self, looking for the first part
        matching each of the items in preferencelist, and return the part
        corresponding to the first item that has a match, or None if no items
        have a match.  If 'related' is not included in preferencelist, consider
        the root part of any multipart/related encountered as a candidate
        match.  Ignore parts with 'Content-Disposition: attachment'.
        """
        best_prio = len(preferencelist)
        body = None
        for prio, part in self._find_body(self, preferencelist):
            if prio < best_prio:
                best_prio = prio
                body = part
                if prio == 0:
                    break
        return body

    _body_types = {('text', 'plain'),
                   ('text', 'html'),
                   ('multipart', 'related'),
                   ('multipart', 'alternative')}
    def iter_attachments(self):
        """Return an iterator over the non-main parts of a multipart.

        Skip the first of each occurrence of text/plain, text/html,
        multipart/related, or multipart/alternative in the multipart (unless
        they have a 'Content-Disposition: attachment' header) and include all
        remaining subparts in the returned iterator.  When applied to a
        multipart/related, return all parts except the root part.  Return an
        empty iterator when applied to a multipart/alternative or a
        non-multipart.
        """
        maintype, subtype = self.get_content_type().split('/')
        if maintype != 'multipart' or subtype == 'alternative':
            return
        payload = self.get_payload()
        # Certain malformed messages can have content type set to `multipart/*`
        # but still have single part body, in which case payload.copy() can
        # fail with AttributeError.
        try:
            parts = payload.copy()
        except AttributeError:
            # payload is not a list, it is most probably a string.
            return

        if maintype == 'multipart' and subtype == 'related':
            # For related, we treat everything but the root as an attachment.
            # The root may be indicated by 'start'; if there's no start or we
            # can't find the named start, treat the first subpart as the root.
            start = self.get_param('start')
            if start:
                found = False
                attachments = []
                for part in parts:
                    if part.get('content-id') == start:
                        found = True
                    else:
                        attachments.append(part)
                if found:
                    yield from attachments
                    return
            parts.pop(0)
            yield from parts
            return
        # Otherwise we more or less invert the remaining logic in get_body.
        # This only really works in edge cases (ex: non-text related or
        # alternatives) if the sending agent sets content-disposition.
        seen = []   # Only skip the first example of each candidate type.
        for part in parts:
            maintype, subtype = part.get_content_type().split('/')
            if ((maintype, subtype) in self._body_types and
                    not part.is_attachment() and subtype not in seen):
                seen.append(subtype)
                continue
            yield part

    def iter_parts(self):
        """Return an iterator over all immediate subparts of a multipart.

        Return an empty iterator for a non-multipart.
        """
        if self.is_multipart():
            yield from self.get_payload()

    def get_content(self, *args, content_manager=None, **kw):
        if content_manager is None:
            content_manager = self.policy.content_manager
        return content_manager.get_content(self, *args, **kw)

    def set_content(self, *args, content_manager=None, **kw):
        if content_manager is None:
            content_manager = self.policy.content_manager
        content_manager.set_content(self, *args, **kw)

    def _make_multipart(self, subtype, disallowed_subtypes, boundary):
        if self.get_content_maintype() == 'multipart':
            existing_subtype = self.get_content_subtype()
            disallowed_subtypes = disallowed_subtypes + (subtype,)
            if existing_subtype in disallowed_subtypes:
                raise ValueError("Cannot convert {} to {}".format(
                    existing_subtype, subtype))
        keep_headers = []
        part_headers = []
        for name, value in self._headers:
            if name.lower().startswith('content-'):
                part_headers.append((name, value))
            else:
                keep_headers.append((name, value))
        if part_headers:
            # There is existing content, move it to the first subpart.
            part = type(self)(policy=self.policy)
            part._headers = part_headers
            part._payload = self._payload
            self._payload = [part]
        else:
            self._payload = []
        self._headers = keep_headers
        self['Content-Type'] = 'multipart/' + subtype
        if boundary is not None:
            self.set_param('boundary', boundary)

    def make_related(self, boundary=None):
        self._make_multipart('related', ('alternative', 'mixed'), boundary)

    def make_alternative(self, boundary=None):
        self._make_multipart('alternative', ('mixed',), boundary)

    def make_mixed(self, boundary=None):
        self._make_multipart('mixed', (), boundary)

    def _add_multipart(self, _subtype, *args, _disp=None, **kw):
        if (self.get_content_maintype() != 'multipart' or
                self.get_content_subtype() != _subtype):
            getattr(self, 'make_' + _subtype)()
        part = type(self)(policy=self.policy)
        part.set_content(*args, **kw)
        if _disp and 'content-disposition' not in part:
            part['Content-Disposition'] = _disp
        self.attach(part)

    def add_related(self, *args, **kw):
        self._add_multipart('related', *args, _disp='inline', **kw)

    def add_alternative(self, *args, **kw):
        self._add_multipart('alternative', *args, **kw)

    def add_attachment(self, *args, **kw):
        self._add_multipart('mixed', *args, _disp='attachment', **kw)

    def clear(self):
        self._headers = []
        self._payload = None

    def clear_content(self):
        self._headers = [(n, v) for n, v in self._headers
                         if not n.lower().startswith('content-')]
        self._payload = None


class EmailMessage(MIMEPart):

    def set_content(self, *args, **kw):
        super().set_content(*args, **kw)
        if 'MIME-Version' not in self:
            self['MIME-Version'] = '1.0'
parser.py000064400000011557151706203570006431 0ustar00# Copyright (C) 2001-2007 Python Software Foundation
# Author: Barry Warsaw, Thomas Wouters, Anthony Baxter
# Contact: email-sig@python.org

"""A parser of RFC 2822 and MIME email messages."""

__all__ = ['Parser', 'HeaderParser', 'BytesParser', 'BytesHeaderParser',
           'FeedParser', 'BytesFeedParser']

from io import StringIO, TextIOWrapper

from email.feedparser import FeedParser, BytesFeedParser
from email._policybase import compat32


class Parser:
    def __init__(self, _class=None, *, policy=compat32):
        """Parser of RFC 2822 and MIME email messages.

        Creates an in-memory object tree representing the email message, which
        can then be manipulated and turned over to a Generator to return the
        textual representation of the message.

        The string must be formatted as a block of RFC 2822 headers and header
        continuation lines, optionally preceded by a `Unix-from' header.  The
        header block is terminated either by the end of the string or by a
        blank line.

        _class is the class to instantiate for new message objects when they
        must be created.  This class must have a constructor that can take
        zero arguments.  Default is Message.Message.

        The policy keyword specifies a policy object that controls a number of
        aspects of the parser's operation.  The default policy maintains
        backward compatibility.

        """
        self._class = _class
        self.policy = policy

    def parse(self, fp, headersonly=False):
        """Create a message structure from the data in a file.

        Reads all the data from the file and returns the root of the message
        structure.  Optional headersonly is a flag specifying whether to stop
        parsing after reading the headers or not.  The default is False,
        meaning it parses the entire contents of the file.
        """
        feedparser = FeedParser(self._class, policy=self.policy)
        if headersonly:
            feedparser._set_headersonly()
        while data := fp.read(8192):
            feedparser.feed(data)
        return feedparser.close()

    def parsestr(self, text, headersonly=False):
        """Create a message structure from a string.

        Returns the root of the message structure.  Optional headersonly is a
        flag specifying whether to stop parsing after reading the headers or
        not.  The default is False, meaning it parses the entire contents of
        the file.
        """
        return self.parse(StringIO(text), headersonly=headersonly)


class HeaderParser(Parser):
    def parse(self, fp, headersonly=True):
        return Parser.parse(self, fp, True)

    def parsestr(self, text, headersonly=True):
        return Parser.parsestr(self, text, True)


class BytesParser:

    def __init__(self, *args, **kw):
        """Parser of binary RFC 2822 and MIME email messages.

        Creates an in-memory object tree representing the email message, which
        can then be manipulated and turned over to a Generator to return the
        textual representation of the message.

        The input must be formatted as a block of RFC 2822 headers and header
        continuation lines, optionally preceded by a `Unix-from' header.  The
        header block is terminated either by the end of the input or by a
        blank line.

        _class is the class to instantiate for new message objects when they
        must be created.  This class must have a constructor that can take
        zero arguments.  Default is Message.Message.
        """
        self.parser = Parser(*args, **kw)

    def parse(self, fp, headersonly=False):
        """Create a message structure from the data in a binary file.

        Reads all the data from the file and returns the root of the message
        structure.  Optional headersonly is a flag specifying whether to stop
        parsing after reading the headers or not.  The default is False,
        meaning it parses the entire contents of the file.
        """
        fp = TextIOWrapper(fp, encoding='ascii', errors='surrogateescape')
        try:
            return self.parser.parse(fp, headersonly)
        finally:
            fp.detach()


    def parsebytes(self, text, headersonly=False):
        """Create a message structure from a byte string.

        Returns the root of the message structure.  Optional headersonly is a
        flag specifying whether to stop parsing after reading the headers or
        not.  The default is False, meaning it parses the entire contents of
        the file.
        """
        text = text.decode('ASCII', errors='surrogateescape')
        return self.parser.parsestr(text, headersonly)


class BytesHeaderParser(BytesParser):
    def parse(self, fp, headersonly=True):
        return BytesParser.parse(self, fp, headersonly=True)

    def parsebytes(self, text, headersonly=True):
        return BytesParser.parsebytes(self, text, headersonly=True)
policy.py000064400000024566151706203570006440 0ustar00"""This will be the home for the policy that hooks in the new
code that adds all the email6 features.
"""

import re
import sys
from email._policybase import Policy, Compat32, compat32, _extend_docstrings
from email.utils import _has_surrogates
from email.headerregistry import HeaderRegistry as HeaderRegistry
from email.contentmanager import raw_data_manager
from email.message import EmailMessage

__all__ = [
    'Compat32',
    'compat32',
    'Policy',
    'EmailPolicy',
    'default',
    'strict',
    'SMTP',
    'HTTP',
    ]

linesep_splitter = re.compile(r'\n|\r\n?')

@_extend_docstrings
class EmailPolicy(Policy):

    """+
    PROVISIONAL

    The API extensions enabled by this policy are currently provisional.
    Refer to the documentation for details.

    This policy adds new header parsing and folding algorithms.  Instead of
    simple strings, headers are custom objects with custom attributes
    depending on the type of the field.  The folding algorithm fully
    implements RFCs 2047 and 5322.

    In addition to the settable attributes listed above that apply to
    all Policies, this policy adds the following additional attributes:

    utf8                -- if False (the default) message headers will be
                           serialized as ASCII, using encoded words to encode
                           any non-ASCII characters in the source strings.  If
                           True, the message headers will be serialized using
                           utf8 and will not contain encoded words (see RFC
                           6532 for more on this serialization format).

    refold_source       -- if the value for a header in the Message object
                           came from the parsing of some source, this attribute
                           indicates whether or not a generator should refold
                           that value when transforming the message back into
                           stream form.  The possible values are:

                           none  -- all source values use original folding
                           long  -- source values that have any line that is
                                    longer than max_line_length will be
                                    refolded
                           all  -- all values are refolded.

                           The default is 'long'.

    header_factory      -- a callable that takes two arguments, 'name' and
                           'value', where 'name' is a header field name and
                           'value' is an unfolded header field value, and
                           returns a string-like object that represents that
                           header.  A default header_factory is provided that
                           understands some of the RFC5322 header field types.
                           (Currently address fields and date fields have
                           special treatment, while all other fields are
                           treated as unstructured.  This list will be
                           completed before the extension is marked stable.)

    content_manager     -- an object with at least two methods: get_content
                           and set_content.  When the get_content or
                           set_content method of a Message object is called,
                           it calls the corresponding method of this object,
                           passing it the message object as its first argument,
                           and any arguments or keywords that were passed to
                           it as additional arguments.  The default
                           content_manager is
                           :data:`~email.contentmanager.raw_data_manager`.

    """

    message_factory = EmailMessage
    utf8 = False
    refold_source = 'long'
    header_factory = HeaderRegistry()
    content_manager = raw_data_manager

    def __init__(self, **kw):
        # Ensure that each new instance gets a unique header factory
        # (as opposed to clones, which share the factory).
        if 'header_factory' not in kw:
            object.__setattr__(self, 'header_factory', HeaderRegistry())
        super().__init__(**kw)

    def header_max_count(self, name):
        """+
        The implementation for this class returns the max_count attribute from
        the specialized header class that would be used to construct a header
        of type 'name'.
        """
        return self.header_factory[name].max_count

    # The logic of the next three methods is chosen such that it is possible to
    # switch a Message object between a Compat32 policy and a policy derived
    # from this class and have the results stay consistent.  This allows a
    # Message object constructed with this policy to be passed to a library
    # that only handles Compat32 objects, or to receive such an object and
    # convert it to use the newer style by just changing its policy.  It is
    # also chosen because it postpones the relatively expensive full rfc5322
    # parse until as late as possible when parsing from source, since in many
    # applications only a few headers will actually be inspected.

    def header_source_parse(self, sourcelines):
        """+
        The name is parsed as everything up to the ':' and returned unmodified.
        The value is determined by stripping leading whitespace off the
        remainder of the first line joined with all subsequent lines, and
        stripping any trailing carriage return or linefeed characters.  (This
        is the same as Compat32).

        """
        name, value = sourcelines[0].split(':', 1)
        value = ''.join((value, *sourcelines[1:])).lstrip(' \t\r\n')
        return (name, value.rstrip('\r\n'))

    def header_store_parse(self, name, value):
        """+
        The name is returned unchanged.  If the input value has a 'name'
        attribute and it matches the name ignoring case, the value is returned
        unchanged.  Otherwise the name and value are passed to header_factory
        method, and the resulting custom header object is returned as the
        value.  In this case a ValueError is raised if the input value contains
        CR or LF characters.

        """
        if hasattr(value, 'name') and value.name.lower() == name.lower():
            return (name, value)
        if isinstance(value, str) and len(value.splitlines())>1:
            # XXX this error message isn't quite right when we use splitlines
            # (see issue 22233), but I'm not sure what should happen here.
            raise ValueError("Header values may not contain linefeed "
                             "or carriage return characters")
        return (name, self.header_factory(name, value))

    def header_fetch_parse(self, name, value):
        """+
        If the value has a 'name' attribute, it is returned to unmodified.
        Otherwise the name and the value with any linesep characters removed
        are passed to the header_factory method, and the resulting custom
        header object is returned.  Any surrogateescaped bytes get turned
        into the unicode unknown-character glyph.

        """
        if hasattr(value, 'name'):
            return value
        # We can't use splitlines here because it splits on more than \r and \n.
        value = ''.join(linesep_splitter.split(value))
        return self.header_factory(name, value)

    def fold(self, name, value):
        """+
        Header folding is controlled by the refold_source policy setting.  A
        value is considered to be a 'source value' if and only if it does not
        have a 'name' attribute (having a 'name' attribute means it is a header
        object of some sort).  If a source value needs to be refolded according
        to the policy, it is converted into a custom header object by passing
        the name and the value with any linesep characters removed to the
        header_factory method.  Folding of a custom header object is done by
        calling its fold method with the current policy.

        Source values are split into lines using splitlines.  If the value is
        not to be refolded, the lines are rejoined using the linesep from the
        policy and returned.  The exception is lines containing non-ascii
        binary data.  In that case the value is refolded regardless of the
        refold_source setting, which causes the binary data to be CTE encoded
        using the unknown-8bit charset.

        """
        return self._fold(name, value, refold_binary=True)

    def fold_binary(self, name, value):
        """+
        The same as fold if cte_type is 7bit, except that the returned value is
        bytes.

        If cte_type is 8bit, non-ASCII binary data is converted back into
        bytes.  Headers with binary data are not refolded, regardless of the
        refold_header setting, since there is no way to know whether the binary
        data consists of single byte characters or multibyte characters.

        If utf8 is true, headers are encoded to utf8, otherwise to ascii with
        non-ASCII unicode rendered as encoded words.

        """
        folded = self._fold(name, value, refold_binary=self.cte_type=='7bit')
        charset = 'utf8' if self.utf8 else 'ascii'
        return folded.encode(charset, 'surrogateescape')

    def _fold(self, name, value, refold_binary=False):
        if hasattr(value, 'name'):
            return value.fold(policy=self)
        maxlen = self.max_line_length if self.max_line_length else sys.maxsize
        # We can't use splitlines here because it splits on more than \r and \n.
        lines = linesep_splitter.split(value)
        refold = (self.refold_source == 'all' or
                  self.refold_source == 'long' and
                    (lines and len(lines[0])+len(name)+2 > maxlen or
                     any(len(x) > maxlen for x in lines[1:])))

        if not refold:
            if not self.utf8:
                refold = not value.isascii()
            elif refold_binary:
                refold = _has_surrogates(value)
        if refold:
            return self.header_factory(name, ''.join(lines)).fold(policy=self)

        return name + ': ' + self.linesep.join(lines) + self.linesep


default = EmailPolicy()
# Make the default policy use the class default header_factory
del default.header_factory
strict = default.clone(raise_on_defect=True)
SMTP = default.clone(linesep='\r\n')
HTTP = default.clone(linesep='\r\n', max_line_length=None)
SMTPUTF8 = SMTP.clone(utf8=True)
quoprimime.py000064400000023210151706203570007311 0ustar00# Copyright (C) 2001-2006 Python Software Foundation
# Author: Ben Gertzfield
# Contact: email-sig@python.org

"""Quoted-printable content transfer encoding per RFCs 2045-2047.

This module handles the content transfer encoding method defined in RFC 2045
to encode US ASCII-like 8-bit data called `quoted-printable'.  It is used to
safely encode text that is in a character set similar to the 7-bit US ASCII
character set, but that includes some 8-bit characters that are normally not
allowed in email bodies or headers.

Quoted-printable is very space-inefficient for encoding binary files; use the
email.base64mime module for that instead.

This module provides an interface to encode and decode both headers and bodies
with quoted-printable encoding.

RFC 2045 defines a method for including character set information in an
`encoded-word' in a header.  This method is commonly used for 8-bit real names
in To:/From:/Cc: etc. fields, as well as Subject: lines.

This module does not do the line wrapping or end-of-line character
conversion necessary for proper internationalized headers; it only
does dumb encoding and decoding.  To deal with the various line
wrapping issues, use the email.header module.
"""

__all__ = [
    'body_decode',
    'body_encode',
    'body_length',
    'decode',
    'decodestring',
    'header_decode',
    'header_encode',
    'header_length',
    'quote',
    'unquote',
    ]

import re

from string import ascii_letters, digits, hexdigits

CRLF = '\r\n'
NL = '\n'
EMPTYSTRING = ''

# Build a mapping of octets to the expansion of that octet.  Since we're only
# going to have 256 of these things, this isn't terribly inefficient
# space-wise.  Remember that headers and bodies have different sets of safe
# characters.  Initialize both maps with the full expansion, and then override
# the safe bytes with the more compact form.
_QUOPRI_MAP = ['=%02X' % c for c in range(256)]
_QUOPRI_HEADER_MAP = _QUOPRI_MAP[:]
_QUOPRI_BODY_MAP = _QUOPRI_MAP[:]

# Safe header bytes which need no encoding.
for c in b'-!*+/' + ascii_letters.encode('ascii') + digits.encode('ascii'):
    _QUOPRI_HEADER_MAP[c] = chr(c)
# Headers have one other special encoding; spaces become underscores.
_QUOPRI_HEADER_MAP[ord(' ')] = '_'

# Safe body bytes which need no encoding.
for c in (b' !"#$%&\'()*+,-./0123456789:;<>'
          b'?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`'
          b'abcdefghijklmnopqrstuvwxyz{|}~\t'):
    _QUOPRI_BODY_MAP[c] = chr(c)



# Helpers
def header_check(octet):
    """Return True if the octet should be escaped with header quopri."""
    return chr(octet) != _QUOPRI_HEADER_MAP[octet]


def body_check(octet):
    """Return True if the octet should be escaped with body quopri."""
    return chr(octet) != _QUOPRI_BODY_MAP[octet]


def header_length(bytearray):
    """Return a header quoted-printable encoding length.

    Note that this does not include any RFC 2047 chrome added by
    `header_encode()`.

    :param bytearray: An array of bytes (a.k.a. octets).
    :return: The length in bytes of the byte array when it is encoded with
        quoted-printable for headers.
    """
    return sum(len(_QUOPRI_HEADER_MAP[octet]) for octet in bytearray)


def body_length(bytearray):
    """Return a body quoted-printable encoding length.

    :param bytearray: An array of bytes (a.k.a. octets).
    :return: The length in bytes of the byte array when it is encoded with
        quoted-printable for bodies.
    """
    return sum(len(_QUOPRI_BODY_MAP[octet]) for octet in bytearray)


def _max_append(L, s, maxlen, extra=''):
    if not isinstance(s, str):
        s = chr(s)
    if not L:
        L.append(s.lstrip())
    elif len(L[-1]) + len(s) <= maxlen:
        L[-1] += extra + s
    else:
        L.append(s.lstrip())


def unquote(s):
    """Turn a string in the form =AB to the ASCII character with value 0xab"""
    return chr(int(s[1:3], 16))


def quote(c):
    return _QUOPRI_MAP[ord(c)]


def header_encode(header_bytes, charset='iso-8859-1'):
    """Encode a single header line with quoted-printable (like) encoding.

    Defined in RFC 2045, this `Q' encoding is similar to quoted-printable, but
    used specifically for email header fields to allow charsets with mostly 7
    bit characters (and some 8 bit) to remain more or less readable in non-RFC
    2045 aware mail clients.

    charset names the character set to use in the RFC 2046 header.  It
    defaults to iso-8859-1.
    """
    # Return empty headers as an empty string.
    if not header_bytes:
        return ''
    # Iterate over every byte, encoding if necessary.
    encoded = header_bytes.decode('latin1').translate(_QUOPRI_HEADER_MAP)
    # Now add the RFC chrome to each encoded chunk and glue the chunks
    # together.
    return '=?%s?q?%s?=' % (charset, encoded)


_QUOPRI_BODY_ENCODE_MAP = _QUOPRI_BODY_MAP[:]
for c in b'\r\n':
    _QUOPRI_BODY_ENCODE_MAP[c] = chr(c)
del c

def body_encode(body, maxlinelen=76, eol=NL):
    """Encode with quoted-printable, wrapping at maxlinelen characters.

    Each line of encoded text will end with eol, which defaults to "\\n".  Set
    this to "\\r\\n" if you will be using the result of this function directly
    in an email.

    Each line will be wrapped at, at most, maxlinelen characters before the
    eol string (maxlinelen defaults to 76 characters, the maximum value
    permitted by RFC 2045).  Long lines will have the 'soft line break'
    quoted-printable character "=" appended to them, so the decoded text will
    be identical to the original text.

    The minimum maxlinelen is 4 to have room for a quoted character ("=XX")
    followed by a soft line break.  Smaller values will generate a
    ValueError.

    """

    if maxlinelen < 4:
        raise ValueError("maxlinelen must be at least 4")
    if not body:
        return body

    # quote special characters
    body = body.translate(_QUOPRI_BODY_ENCODE_MAP)

    soft_break = '=' + eol
    # leave space for the '=' at the end of a line
    maxlinelen1 = maxlinelen - 1

    encoded_body = []
    append = encoded_body.append

    for line in body.splitlines():
        # break up the line into pieces no longer than maxlinelen - 1
        start = 0
        laststart = len(line) - 1 - maxlinelen
        while start <= laststart:
            stop = start + maxlinelen1
            # make sure we don't break up an escape sequence
            if line[stop - 2] == '=':
                append(line[start:stop - 1])
                start = stop - 2
            elif line[stop - 1] == '=':
                append(line[start:stop])
                start = stop - 1
            else:
                append(line[start:stop] + '=')
                start = stop

        # handle rest of line, special case if line ends in whitespace
        if line and line[-1] in ' \t':
            room = start - laststart
            if room >= 3:
                # It's a whitespace character at end-of-line, and we have room
                # for the three-character quoted encoding.
                q = quote(line[-1])
            elif room == 2:
                # There's room for the whitespace character and a soft break.
                q = line[-1] + soft_break
            else:
                # There's room only for a soft break.  The quoted whitespace
                # will be the only content on the subsequent line.
                q = soft_break + quote(line[-1])
            append(line[start:-1] + q)
        else:
            append(line[start:])

    # add back final newline if present
    if body[-1] in CRLF:
        append('')

    return eol.join(encoded_body)



# BAW: I'm not sure if the intent was for the signature of this function to be
# the same as base64MIME.decode() or not...
def decode(encoded, eol=NL):
    """Decode a quoted-printable string.

    Lines are separated with eol, which defaults to \\n.
    """
    if not encoded:
        return encoded
    # BAW: see comment in encode() above.  Again, we're building up the
    # decoded string with string concatenation, which could be done much more
    # efficiently.
    decoded = ''

    for line in encoded.splitlines():
        line = line.rstrip()
        if not line:
            decoded += eol
            continue

        i = 0
        n = len(line)
        while i < n:
            c = line[i]
            if c != '=':
                decoded += c
                i += 1
            # Otherwise, c == "=".  Are we at the end of the line?  If so, add
            # a soft line break.
            elif i+1 == n:
                i += 1
                continue
            # Decode if in form =AB
            elif i+2 < n and line[i+1] in hexdigits and line[i+2] in hexdigits:
                decoded += unquote(line[i:i+3])
                i += 3
            # Otherwise, not in form =AB, pass literally
            else:
                decoded += c
                i += 1

            if i == n:
                decoded += eol
    # Special case if original string did not end with eol
    if encoded[-1] not in '\r\n' and decoded.endswith(eol):
        decoded = decoded[:-1]
    return decoded


# For convenience and backwards compatibility w/ standard base64 module
body_decode = decode
decodestring = decode



def _unquote_match(match):
    """Turn a match in the form =AB to the ASCII character with value 0xab"""
    s = match.group(0)
    return unquote(s)


# Header decoding is done a bit differently
def header_decode(s):
    """Decode a string encoded with RFC 2045 MIME header `Q' encoding.

    This function does not parse a full MIME header value encoded with
    quoted-printable (like =?iso-8859-1?q?Hello_World?=) -- please use
    the high level email.header class for that functionality.
    """
    s = s.replace('_', ' ')
    return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s, flags=re.ASCII)
utils.py000064400000037307151706203570006276 0ustar00# Copyright (C) 2001-2010 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org

"""Miscellaneous utilities."""

__all__ = [
    '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',
    ]

import os
import re
import time
import random
import socket
import datetime
import urllib.parse

from email._parseaddr import quote
from email._parseaddr import AddressList as _AddressList
from email._parseaddr import mktime_tz

from email._parseaddr import parsedate, parsedate_tz, _parsedate_tz

# Intrapackage imports
from email.charset import Charset

COMMASPACE = ', '
EMPTYSTRING = ''
UEMPTYSTRING = ''
CRLF = '\r\n'
TICK = "'"

specialsre = re.compile(r'[][\\()<>@,:;".]')
escapesre = re.compile(r'[\\"]')


def _has_surrogates(s):
    """Return True if s may contain surrogate-escaped binary data."""
    # This check is based on the fact that unless there are surrogates, utf8
    # (Python's default encoding) can encode any string.  This is the fastest
    # way to check for surrogates, see bpo-11454 (moved to gh-55663) for timings.
    try:
        s.encode()
        return False
    except UnicodeEncodeError:
        return True

# How to deal with a string containing bytes before handing it to the
# application through the 'normal' interface.
def _sanitize(string):
    # Turn any escaped bytes into unicode 'unknown' char.  If the escaped
    # bytes happen to be utf-8 they will instead get decoded, even if they
    # were invalid in the charset the source was supposed to be in.  This
    # seems like it is not a bad thing; a defect was still registered.
    original_bytes = string.encode('utf-8', 'surrogateescape')
    return original_bytes.decode('utf-8', 'replace')



# Helpers

def formataddr(pair, charset='utf-8'):
    """The inverse of parseaddr(), this takes a 2-tuple of the form
    (realname, email_address) and returns the string value suitable
    for an RFC 2822 From, To or Cc header.

    If the first element of pair is false, then the second element is
    returned unmodified.

    The optional charset is the character set that is used to encode
    realname in case realname is not ASCII safe.  Can be an instance of str or
    a Charset-like object which has a header_encode method.  Default is
    'utf-8'.
    """
    name, address = pair
    # The address MUST (per RFC) be ascii, so raise a UnicodeError if it isn't.
    address.encode('ascii')
    if name:
        try:
            name.encode('ascii')
        except UnicodeEncodeError:
            if isinstance(charset, str):
                charset = Charset(charset)
            encoded_name = charset.header_encode(name)
            return "%s <%s>" % (encoded_name, address)
        else:
            quotes = ''
            if specialsre.search(name):
                quotes = '"'
            name = escapesre.sub(r'\\\g<0>', name)
            return '%s%s%s <%s>' % (quotes, name, quotes, address)
    return address


def _iter_escaped_chars(addr):
    pos = 0
    escape = False
    for pos, ch in enumerate(addr):
        if escape:
            yield (pos, '\\' + ch)
            escape = False
        elif ch == '\\':
            escape = True
        else:
            yield (pos, ch)
    if escape:
        yield (pos, '\\')


def _strip_quoted_realnames(addr):
    """Strip real names between quotes."""
    if '"' not in addr:
        # Fast path
        return addr

    start = 0
    open_pos = None
    result = []
    for pos, ch in _iter_escaped_chars(addr):
        if ch == '"':
            if open_pos is None:
                open_pos = pos
            else:
                if start != open_pos:
                    result.append(addr[start:open_pos])
                start = pos + 1
                open_pos = None

    if start < len(addr):
        result.append(addr[start:])

    return ''.join(result)


supports_strict_parsing = True

def getaddresses(fieldvalues, *, strict=True):
    """Return a list of (REALNAME, EMAIL) or ('','') for each fieldvalue.

    When parsing fails for a fieldvalue, a 2-tuple of ('', '') is returned in
    its place.

    If strict is true, use a strict parser which rejects malformed inputs.
    """

    # If strict is true, if the resulting list of parsed addresses is greater
    # than the number of fieldvalues in the input list, a parsing error has
    # occurred and consequently a list containing a single empty 2-tuple [('',
    # '')] is returned in its place. This is done to avoid invalid output.
    #
    # Malformed input: getaddresses(['alice@example.com <bob@example.com>'])
    # Invalid output: [('', 'alice@example.com'), ('', 'bob@example.com')]
    # Safe output: [('', '')]

    if not strict:
        all = COMMASPACE.join(str(v) for v in fieldvalues)
        a = _AddressList(all)
        return a.addresslist

    fieldvalues = [str(v) for v in fieldvalues]
    fieldvalues = _pre_parse_validation(fieldvalues)
    addr = COMMASPACE.join(fieldvalues)
    a = _AddressList(addr)
    result = _post_parse_validation(a.addresslist)

    # Treat output as invalid if the number of addresses is not equal to the
    # expected number of addresses.
    n = 0
    for v in fieldvalues:
        # When a comma is used in the Real Name part it is not a deliminator.
        # So strip those out before counting the commas.
        v = _strip_quoted_realnames(v)
        # Expected number of addresses: 1 + number of commas
        n += 1 + v.count(',')
    if len(result) != n:
        return [('', '')]

    return result


def _check_parenthesis(addr):
    # Ignore parenthesis in quoted real names.
    addr = _strip_quoted_realnames(addr)

    opens = 0
    for pos, ch in _iter_escaped_chars(addr):
        if ch == '(':
            opens += 1
        elif ch == ')':
            opens -= 1
            if opens < 0:
                return False
    return (opens == 0)


def _pre_parse_validation(email_header_fields):
    accepted_values = []
    for v in email_header_fields:
        if not _check_parenthesis(v):
            v = "('', '')"
        accepted_values.append(v)

    return accepted_values


def _post_parse_validation(parsed_email_header_tuples):
    accepted_values = []
    # The parser would have parsed a correctly formatted domain-literal
    # The existence of an [ after parsing indicates a parsing failure
    for v in parsed_email_header_tuples:
        if '[' in v[1]:
            v = ('', '')
        accepted_values.append(v)

    return accepted_values


def _format_timetuple_and_zone(timetuple, zone):
    return '%s, %02d %s %04d %02d:%02d:%02d %s' % (
        ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][timetuple[6]],
        timetuple[2],
        ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
         'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][timetuple[1] - 1],
        timetuple[0], timetuple[3], timetuple[4], timetuple[5],
        zone)

def formatdate(timeval=None, localtime=False, usegmt=False):
    """Returns a date string as specified by RFC 2822, e.g.:

    Fri, 09 Nov 2001 01:08:47 -0000

    Optional timeval if given is a floating-point time value as accepted by
    gmtime() and localtime(), otherwise the current time is used.

    Optional localtime is a flag that when True, interprets timeval, and
    returns a date relative to the local timezone instead of UTC, properly
    taking daylight savings time into account.

    Optional argument usegmt means that the timezone is written out as
    an ascii string, not numeric one (so "GMT" instead of "+0000"). This
    is needed for HTTP, and is only used when localtime==False.
    """
    # Note: we cannot use strftime() because that honors the locale and RFC
    # 2822 requires that day and month names be the English abbreviations.
    if timeval is None:
        timeval = time.time()
    dt = datetime.datetime.fromtimestamp(timeval, datetime.timezone.utc)

    if localtime:
        dt = dt.astimezone()
        usegmt = False
    elif not usegmt:
        dt = dt.replace(tzinfo=None)
    return format_datetime(dt, usegmt)

def format_datetime(dt, usegmt=False):
    """Turn a datetime into a date string as specified in RFC 2822.

    If usegmt is True, dt must be an aware datetime with an offset of zero.  In
    this case 'GMT' will be rendered instead of the normal +0000 required by
    RFC2822.  This is to support HTTP headers involving date stamps.
    """
    now = dt.timetuple()
    if usegmt:
        if dt.tzinfo is None or dt.tzinfo != datetime.timezone.utc:
            raise ValueError("usegmt option requires a UTC datetime")
        zone = 'GMT'
    elif dt.tzinfo is None:
        zone = '-0000'
    else:
        zone = dt.strftime("%z")
    return _format_timetuple_and_zone(now, zone)


def make_msgid(idstring=None, domain=None):
    """Returns a string suitable for RFC 2822 compliant Message-ID, e.g:

    <142480216486.20800.16526388040877946887@nightshade.la.mastaler.com>

    Optional idstring if given is a string used to strengthen the
    uniqueness of the message id.  Optional domain if given provides the
    portion of the message id after the '@'.  It defaults to the locally
    defined hostname.
    """
    timeval = int(time.time()*100)
    pid = os.getpid()
    randint = random.getrandbits(64)
    if idstring is None:
        idstring = ''
    else:
        idstring = '.' + idstring
    if domain is None:
        domain = socket.getfqdn()
    msgid = '<%d.%d.%d%s@%s>' % (timeval, pid, randint, idstring, domain)
    return msgid


def parsedate_to_datetime(data):
    parsed_date_tz = _parsedate_tz(data)
    if parsed_date_tz is None:
        raise ValueError('Invalid date value or format "%s"' % str(data))
    *dtuple, tz = parsed_date_tz
    if tz is None:
        return datetime.datetime(*dtuple[:6])
    return datetime.datetime(*dtuple[:6],
            tzinfo=datetime.timezone(datetime.timedelta(seconds=tz)))


def parseaddr(addr, *, strict=True):
    """
    Parse addr into its constituent realname and email address parts.

    Return a tuple of realname and email address, unless the parse fails, in
    which case return a 2-tuple of ('', '').

    If strict is True, use a strict parser which rejects malformed inputs.
    """
    if not strict:
        addrs = _AddressList(addr).addresslist
        if not addrs:
            return ('', '')
        return addrs[0]

    if isinstance(addr, list):
        addr = addr[0]

    if not isinstance(addr, str):
        return ('', '')

    addr = _pre_parse_validation([addr])[0]
    addrs = _post_parse_validation(_AddressList(addr).addresslist)

    if not addrs or len(addrs) > 1:
        return ('', '')

    return addrs[0]


# rfc822.unquote() doesn't properly de-backslash-ify in Python pre-2.3.
def unquote(str):
    """Remove quotes from a string."""
    if len(str) > 1:
        if str.startswith('"') and str.endswith('"'):
            return str[1:-1].replace('\\\\', '\\').replace('\\"', '"')
        if str.startswith('<') and str.endswith('>'):
            return str[1:-1]
    return str



# RFC2231-related functions - parameter encoding and decoding
def decode_rfc2231(s):
    """Decode string according to RFC 2231"""
    parts = s.split(TICK, 2)
    if len(parts) <= 2:
        return None, None, s
    return parts


def encode_rfc2231(s, charset=None, language=None):
    """Encode string according to RFC 2231.

    If neither charset nor language is given, then s is returned as-is.  If
    charset is given but not language, the string is encoded using the empty
    string for language.
    """
    s = urllib.parse.quote(s, safe='', encoding=charset or 'ascii')
    if charset is None and language is None:
        return s
    if language is None:
        language = ''
    return "%s'%s'%s" % (charset, language, s)


rfc2231_continuation = re.compile(r'^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$',
    re.ASCII)

def decode_params(params):
    """Decode parameters list according to RFC 2231.

    params is a sequence of 2-tuples containing (param name, string value).
    """
    new_params = [params[0]]
    # Map parameter's name to a list of continuations.  The values are a
    # 3-tuple of the continuation number, the string value, and a flag
    # specifying whether a particular segment is %-encoded.
    rfc2231_params = {}
    for name, value in params[1:]:
        encoded = name.endswith('*')
        value = unquote(value)
        mo = rfc2231_continuation.match(name)
        if mo:
            name, num = mo.group('name', 'num')
            if num is not None:
                num = int(num)
            rfc2231_params.setdefault(name, []).append((num, value, encoded))
        else:
            new_params.append((name, '"%s"' % quote(value)))
    if rfc2231_params:
        for name, continuations in rfc2231_params.items():
            value = []
            extended = False
            # Sort by number
            continuations.sort()
            # And now append all values in numerical order, converting
            # %-encodings for the encoded segments.  If any of the
            # continuation names ends in a *, then the entire string, after
            # decoding segments and concatenating, must have the charset and
            # language specifiers at the beginning of the string.
            for num, s, encoded in continuations:
                if encoded:
                    # Decode as "latin-1", so the characters in s directly
                    # represent the percent-encoded octet values.
                    # collapse_rfc2231_value treats this as an octet sequence.
                    s = urllib.parse.unquote(s, encoding="latin-1")
                    extended = True
                value.append(s)
            value = quote(EMPTYSTRING.join(value))
            if extended:
                charset, language, value = decode_rfc2231(value)
                new_params.append((name, (charset, language, '"%s"' % value)))
            else:
                new_params.append((name, '"%s"' % value))
    return new_params

def collapse_rfc2231_value(value, errors='replace',
                           fallback_charset='us-ascii'):
    if not isinstance(value, tuple) or len(value) != 3:
        return unquote(value)
    # While value comes to us as a unicode string, we need it to be a bytes
    # object.  We do not want bytes() normal utf-8 decoder, we want a straight
    # interpretation of the string as character bytes.
    charset, language, text = value
    if charset is None:
        # Issue 17369: if charset/lang is None, decode_rfc2231 couldn't parse
        # the value, so use the fallback_charset.
        charset = fallback_charset
    rawbytes = bytes(text, 'raw-unicode-escape')
    try:
        return str(rawbytes, charset, errors)
    except LookupError:
        # charset is not a known codec.
        return unquote(text)


#
# datetime doesn't provide a localtime function yet, so provide one.  Code
# adapted from the patch in issue 9527.  This may not be perfect, but it is
# better than not having it.
#

def localtime(dt=None, isdst=None):
    """Return local time as an aware datetime object.

    If called without arguments, return current time.  Otherwise *dt*
    argument should be a datetime instance, and it is converted to the
    local time zone according to the system time zone database.  If *dt* is
    naive (that is, dt.tzinfo is None), it is assumed to be in local time.
    The isdst parameter is ignored.

    """
    if isdst is not None:
        import warnings
        warnings._deprecated(
            "The 'isdst' parameter to 'localtime'",
            message='{name} is deprecated and slated for removal in Python {remove}',
            remove=(3, 14),
            )
    if dt is None:
        dt = datetime.datetime.now()
    return dt.astimezone()