AlkantarClanX12

Your IP : 3.138.101.219


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

o

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

r5c@s�eZdZdZefdd�Zdd�Zddd	d
�Zdd�Zded
d�Z	dd�Z
dd�Zdd�Zdd�Z
dfdd�Zdgdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zdgd1d2�Zd3d4�Zd5d6�Zdgd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dhdKdL�Z'	I	JdhdMdN�Z(	J	didQdR�Z)djdSdT�Z*dkdUdV�Z+dgdWdX�Z,dgdYdZ�Z-d[d\�Z.dgd]d^�Z/dgd_d`�Z0dadb�Z1ddcl2m3Z3dS)lra�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.
    cCs:||_g|_d|_d|_d|_d|_|_g|_d|_dS)N�
text/plain)	�policy�_headers�	_unixfrom�_payload�_charsetZpreambleZepilogue�defects�
_default_type)�selfr7rrr�__init__xs
zMessage.__init__cC�|��S)z9Return the entire formatted message as a string.
        )�	as_string�r>rrr�__str__��zMessage.__str__FrNcCsJddlm}|dur
|jn|}t�}||d||d�}|j||d�|��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)�	GeneratorNF)�mangle_from_�maxheaderlenr7��unixfrom)�email.generatorrEr7r�flatten�getvalue)r>rIrGr7rE�fp�grrrrA�s�zMessage.as_stringcCr@)z?Return the entire formatted message as a bytes object.
        )�as_bytesrBrrr�	__bytes__�rDzMessage.__bytes__cCsHddlm}|dur
|jn|}t�}||d|d�}|j||d�|��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)�BytesGeneratorNF)rFr7rH)rJrQr7rrKrL)r>rIr7rQrMrNrrrrO�szMessage.as_bytescCst|jt�S)z6Return True if the message consists of multiple parts.)rr:�listrBrrr�is_multipart�szMessage.is_multipartcCs
||_dS�N�r9)r>rIrrr�set_unixfrom�s
zMessage.set_unixfromcC�|jSrTrUrBrrr�get_unixfrom�szMessage.get_unixfromcCs@|jdur|g|_dSz	|j�|�WdStytd��w)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:r.�AttributeError�	TypeError)r>�payloadrrr�attach�s
�zMessage.attachcCs�|��r|rdS|dur|jS|j|S|dur't|jt�s'tdt|j���|j}t|�dd����}t|t�r{t	�
|�rc|�dd�}|sbz|�|�
dd�d�}Wn(tya|�dd�}Ynwn|r{z|�d�}Wntyz|�d	�}Ynw|s|S|d
kr�t�|�S|dkr�td�|����\}}|D]	}|j�||�q�|S|d
vr�t|�}	t�}
z
tj|	|
dd�|
��WStjy�|YSwt|t�r�|S|S)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-encodingrr�surrogateescaper�replace�raw-unicode-escapezquoted-printable�base64�)z
x-uuencodeZuuencodeZuuezx-uueT)�quiet)rSr:rrRrZ�typer�getr-rZ_has_surrogatesr!�decode�	get_param�LookupError�UnicodeError�quopriZdecodestringr�join�
splitlinesr7Z
handle_defectr�uurL�Error)r>r2rer[�cteZbpayloadr&r<ZdefectZin_fileZout_filerrr�get_payload�s^"


���

�
zMessage.get_payloadcCstt|d�r|dur||_dSt|t�st|�}|�|j�}t|d�r*|�dd�|_n||_|dur8|�|�dSdS)z�Set the payload to the given value.

        Optional charset sets the message's default character set.  See
        set_charset() for details.
        r!Nrerr])�hasattrr:r�Charsetr!�output_charsetre�set_charset)r>r[rrrr�set_payload/s


�zMessage.set_payloadcCs|dur|�d�d|_dSt|t�st|�}||_d|vr$|�dd�d|vr3|jdd|��d�n|�d|���||��krH|�|j�|_d|vr�|�	�}z||�WdSt
y�|j}|r{z|�d	d
�}Wntyz|�|j
�}Ynw|�|�|_|�d|�YdSwdS)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-Typer6r
zContent-Transfer-Encodingrr])�	del_paramr;rrq�
add_headerZget_output_charset�	set_paramZbody_encoder:Zget_body_encodingrZr!rhrr)r>rrnr[rrrrsCs@

����zMessage.set_charsetcCrW)zKReturn the Charset instance associated with the message's payload.
        )r;rBrrr�get_charsetrszMessage.get_charsetcCs
t|j�S)z9Return the total number of headers, including duplicates.)rr8rBrrr�__len__zs
zMessage.__len__cCs
|�|�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.
        )rd�r>�namerrr�__getitem__~s
	zMessage.__getitem__cCsr|j�|�}|r,|��}d}|jD]\}}|��|kr+|d7}||kr+td�||���q|j�|j�||��dS)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)r7Zheader_max_countr-r8�
ValueError�formatr.�header_store_parse)r>r~�valZ	max_countZlname�found�k�vrrr�__setitem__�s��zMessage.__setitem__cCs@|��}g}|jD]\}}|��|kr|�||f�q	||_dS)zwDelete all occurrences of a header, if present.

        Does not raise an exception if the header is missing.
        N)r-r8r.)r>r~�
newheadersr�r�rrr�__delitem__�s�
zMessage.__delitem__cCs|��dd�|jD�vS)NcSsg|]\}}|���qSr)r-��.0r�r�rrr�
<listcomp>�sz(Message.__contains__.<locals>.<listcomp>)r-r8r}rrr�__contains__�szMessage.__contains__ccs�|jD]\}}|VqdSrT�r8)r>Zfieldr&rrr�__iter__�s��zMessage.__iter__cCsdd�|jD�S)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.
        cSsg|]\}}|�qSrrr�rrrr��sz Message.keys.<locals>.<listcomp>r�rBrrr�keys�szMessage.keysc��fdd��jD�S)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.
        csg|]\}}�j�||��qSr�r7�header_fetch_parser�rBrrr��s�z"Message.values.<locals>.<listcomp>r�rBrrBr�values��
�zMessage.valuescr�)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.
        cs"g|]
\}}|�j�||�f�qSrr�r�rBrrr��s�z!Message.items.<locals>.<listcomp>r�rBrrBr�items�r�z
Message.itemscCs:|��}|jD]\}}|��|kr|j�||�Sq|S)z~Get a header value.

        Like __getitem__() but return failobj instead of None when the field
        is missing.
        )r-r8r7r�)r>r~�failobjr�r�rrrrd�s�zMessage.getcCs|j�||f�dS)z�Store name and value in the model without modification.

        This is an "internal" API, intended only for use by a parser.
        N)r8r.)r>r~r&rrr�set_raw�szMessage.set_rawcCst|j���S)z�Return the (name, value) header pairs without modification.

        This is an "internal" API, intended only for use by a generator.
        )�iterr8�copyrBrrr�	raw_items�szMessage.raw_itemscCsHg}|��}|jD]\}}|��|kr|�|j�||��q	|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).
        )r-r8r.r7r�)r>r~r�r�r�r�rrr�get_all�s	�zMessage.get_allcKspg}|��D]\}}|dur|�|�dd��q|�t|�dd�|��q|dur/|�d|�t�|�||<dS)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'))
        N�_�-r)r�r.r^r'�insert�	SEMISPACErj)r>�_name�_valueZ_params�partsr�r�rrrryszMessage.add_headercCsZ|��}ttt|j��|j�D]\}\}}|��|kr(|j�||�|j|<dSqt|��)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)r-�zip�rangerr8r7r��KeyError)r>r�r�r2r�r�rrr�replace_header!s"�zMessage.replace_headercCsHt�}|�d|�}||ur|��St|�d��}|�d�dkr"dS|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�/rr6)�objectrd�get_default_typerr-r+)r>�missingr&�ctyperrr�get_content_type4s
zMessage.get_content_typecC�|��}|�d�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�r>r�rrr�get_content_maintypeL�zMessage.get_content_maintypecCr�)z�Returns the message's sub-content type.

        This is the `subtype' part of the string returned by
        get_content_type().
        r�rr�r�rrr�get_content_subtypeUr�zMessage.get_content_subtypecCrW)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.
        �r=rBrrrr�^szMessage.get_default_typecCs
||_dS)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�rrr�set_default_typegs
zMessage.set_default_typec		Cs�t�}|�||�}||ur|Sg}t|�D]+}z|�dd�\}}|��}|��}Wnty8|��}d}Ynw|�||f�qt�|�}|S)Nr)rr)	r�rdr3r�rr�r.rZ
decode_params)	r>r��headerr�r&�params�pr~r�rrr�_get_params_preserveps"�
zMessage._get_params_preserver�TcCs4t�}|�||�}||ur|S|rdd�|D�S|S)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.
        cSsg|]
\}}|t|�f�qSr)r5r�rrrr��sz&Message.get_params.<locals>.<listcomp>)r�r�)r>r�r�r4r�r�rrr�
get_params�s
zMessage.get_paramscCsN||vr|S|�||�D]\}}|��|��kr$|r t|�S|Sq|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)

        )r�r-r5)r>rr�r�r4r�r�rrrrf�s�zMessage.get_paramrwrcCst|t�s|r|||f}||vr|��dkrd}n|�|�}|j||d�s:|s.t|||�}n=t�|t|||�g�}n1d}|j||d�D]'\}	}
d}|	��|��krXt|||�}nt|	|
|�}|sc|}qCt�||g�}qC||�|�kr�|r||�	||�dS||=|||<dSdS)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�r6)r�r�r�r4N)
rr r-rdrfr'r�rjr�r�)r>rr&r��requoterZlanguager^r�Z	old_param�	old_valueZappend_paramrrrrz�s8

���zMessage.set_paramcCs�||vrdSd}|j||d�D] \}}|��|��kr/|s$t|||�}qt�|t|||�g�}q||�|�kr@||=|||<dSdS)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�)r�r-r'r�rjrd)r>rr�r�Z	new_ctyper�r�rrrrx�s
���zMessage.del_paramcCs�|�d�dks	t�|��dkr|d=d|d<||vr |||<dS|j||d�}||=|||<|dd�D]\}}|�||||�q4dS)	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-versionrvruNr�)r+r�r-r�rz)r>rcr�r�r�r�r�rrr�set_types�zMessage.set_typecCsDt�}|�d|d�}||ur|�d|d�}||ur|St�|���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�rfr�collapse_rfc2231_valuer)r>r�r�r�rrr�get_filename&szMessage.get_filenamecCs,t�}|�d|�}||ur|St�|���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�rfrr��rstrip)r>r�r�r�rrr�get_boundary6s
zMessage.get_boundarycCst�}|�|d�}||urt�d��g}d}|D]\}}|��dkr.|�dd|f�d}q|�||f�q|sA|�dd|f�g}|jD]=\}	}
|	��dkr|g}|D]\}}
|
dkrb|�|�qT|�d||
f�qTt�|�}
|�|j	�
|	|
��qF|�|	|
f�qF||_d	S)
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 foundFr�z"%s"TrrN)r�r�rZHeaderParseErrorr-r.r8r�rjr7r�)r>r�r�r�Z	newparamsZfoundpZpkZpvr��hr�r�r�r�rrr�set_boundaryCs2



zMessage.set_boundaryc	Cs�t�}|�d|�}||ur|St|t�r8|dpd}z|d�d�}t||�}Wnttfy7|d}Ynwz
|�d�W|��StyM|YSw)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�rfrr r!rrgrhr-)r>r�r�rZpcharsetrOrrr�get_content_charsetqs$
���zMessage.get_content_charsetcs�fdd�|��D�S)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.
        csg|]}|����qSr)r�)r��part�r�rrr��sz(Message.get_charsets.<locals>.<listcomp>��walk)r>r�rr�r�get_charsets�szMessage.get_charsetscCs*|�d�}|durdSt|�d��}|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.
        r�Nr)rdrr-)r>r&�c_drrr�get_content_disposition�s

zMessage.get_content_dispositionr�)FrN)FN)NFrT)Nr�T)rwTNrF)r�T)rwT)4�__name__�
__module__�__qualname__�__doc__r	r?rCrArPrOrSrVrXr\rortrsr{r|rr�r�r�r�r�r�r�rdr�r�r�ryr�r�r�r�r�r�r�r�rfrzrxr�r�r�r�r�r�r�Zemail.iteratorsr�rrrrrish



Z/


				

�"
�
3

 

.

cs�eZdZd/�fdd�	Zd0�fdd�	Zdd�Zd	d
�Zdd�Zd1dd�Zhd�Z	dd�Z
dd�Zdd�dd�Zdd�dd�Z
dd�Zd/dd�Zd/dd�Zd/d d!�Zdd"�d#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Z�ZS)2�MIMEPartNcs(|durddlm}|}t��|�dS)Nr)�default)Zemail.policyr��superr?)r>r7r���	__class__rrr?�szMIMEPart.__init__Fcs0|dur|jn|}|dur|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.
        N)r7Zmax_line_lengthr�rA)r>rIrGr7r�rrrA�szMIMEPart.as_stringcCs|j|jjdd�d�S)NT)�utf8�r7)rAr7ZclonerBrrrrC�szMIMEPart.__str__cCs |�d�}|durdS|jdkS)Nr�F�
attachment)rdZcontent_disposition)r>r�rrr�
is_attachment�s
zMIMEPart.is_attachmentc	cs�|��rdS|���d�\}}|dkr"||vr |�|�|fVdS|dks*|��s,dS|dkrB|��D]}|�||�EdHq4dSd|vrN|�d�|fVd}|�d�}|rh|��D]}|d|krg|}nq[|durx|��}|rv|dnd}|dur�|�||�EdHdSdS)Nr��text�	multipart�related�start�
content-idr)	r�r�r�r,rS�
iter_parts�
_find_bodyrfro)	r>r��preferencelist�maintype�subtypeZsubpart�	candidater�Zsubpartsrrrr��s<�
��zMIMEPart._find_body�r��html�plaincCsDt|�}d}|�||�D]\}}||kr|}|}|dkr|Sq|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)rr�)r>r�Z	best_prio�bodyZprior�rrr�get_body�s
�zMIMEPart.get_body>)r�r�)r�r�)r�r�)r��alternativec
cs�|���d�\}}|dks|dkrdS|��}z|��}Wn
ty(YdSw|dkre|dkre|�d�}|rYd}g}|D]}|�d�|krJd	}q>|�|�q>|rY|EdHdS|�d
�|EdHdSg}	|D]#}|���d�\}}||f|j	vr�|�
�s�||	vr�|	�|�qi|VqidS)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�r�r�Nr�r�Fr�Tr)r�r�ror�rYrfrdr.�pop�_body_typesr�)
r>r�r�r[r�r�r�Zattachmentsr��seenrrr�iter_attachmentssH��



�
�zMIMEPart.iter_attachmentsccs �|��r|��EdHdSdS)z~Return an iterator over all immediate subparts of a multipart.

        Return an empty iterator for a non-multipart.
        N)rSrorBrrrr�=s��zMIMEPart.iter_parts)�content_managercOs(|dur|jj}|j|g|�Ri|��SrT)r7r��get_content�r>r��args�kwrrrr�EszMIMEPart.get_contentcOs,|dur|jj}|j|g|�Ri|��dSrT)r7r��set_contentr�rrrr�JszMIMEPart.set_contentc
Cs�|��dkr|��}||f}||vrtd�||���g}g}|jD]\}}|���d�r5|�||f�q"|�||f�q"|rSt|�|j	d�}	||	_|j
|	_
|	g|_
ng|_
||_d||d<|durk|�d|�dSdS)Nr�zCannot convert {} to {}�content-r�z
multipart/rwr�)r�r�r�r�r8r-�
startswithr.rcr7r:rz)
r>r�Zdisallowed_subtypesr�Zexisting_subtypeZkeep_headersZpart_headersr~r&r�rrr�_make_multipartOs0
�
�zMIMEPart._make_multipartcC�|�dd|�dS)Nr�)r��mixed�r��r>r�rrr�make_relatedj�zMIMEPart.make_relatedcCr�)Nr�)r�r�rrrr�make_alternativemrzMIMEPart.make_alternativecCr�)Nr�rr�rrrr�
make_mixedprzMIMEPart.make_mixed)�_dispcOsj|��dks|��|krt|d|��t|�|jd�}|j|i|��|r.d|vr.||d<|�|�dS)Nr�Zmake_r�r�zContent-Disposition)r�r��getattrrcr7r�r\)r>Z_subtyperr�r�r�rrr�_add_multipartsszMIMEPart._add_multipartcO� |jdg|�Rddi|��dS)Nr�rZinline�r�r>r�r�rrr�add_related}� zMIMEPart.add_relatedcOs|jdg|�Ri|��dS)Nr�r	r
rrr�add_alternative�szMIMEPart.add_alternativecOr)Nr�rr�r	r
rrr�add_attachment�rzMIMEPart.add_attachmentcCsg|_d|_dSrT�r8r:rBrrr�clear�s
zMIMEPart.clearcCsdd�|jD�|_d|_dS)NcSs&g|]\}}|���d�s||f�qS)r�)r-r�)r��nr�rrrr��s�z*MIMEPart.clear_content.<locals>.<listcomp>rrBrrr�
clear_content�s
zMIMEPart.clear_contentrT)FNN)r�)r�r�r�r?rArCr�r�r�r�r�r�r�r�r�rrrrrr
rrr�
__classcell__rrr�rr��s,
7



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


"N`