ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python34/lib64/python3.4/email/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python34/lib64/python3.4/email/__pycache__/message.cpython-34.pyc

�
e fN��@sOdZdgZddlZddlZddlZddlZddlmZmZddl	m
Z
ddl	mZddlm
Z
ddl	mZdd	lmZejZd
Zejd�Zdd
�Zdddd�Zdd�Zdd�ZGdd�d�ZGdd�d�ZGdd�de�ZGdd�de�ZdS)z8Basic message object for the email package object model.�Message�N)�BytesIO�StringIO)�utils)�errors)�compat32)�charset)�decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]cCsJt|�jd�\}}}|s4|j�dfS|j�|j�fS)N�;)�str�	partition�strip)�param�a�sep�b�r�2/opt/alt/python34/lib64/python3.4/email/message.py�_splitparamsrTcCs�|dk	r�t|�dkr�t|t�rf|d7}tj|d|d|d�}d||fSy|jd�Wn?tk
r�|d7}tj|dd	�}d||fSYnX|s�tj|�r�d
|tj	|�fSd||fSn|SdS)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�*��z%s=%s�asciizutf-8�z%s="%s")
�len�
isinstance�tuplerZencode_rfc2231�encode�UnicodeEncodeError�	tspecials�search�quote)r�valuer!rrr�_formatparam(s	
!

r#cCsOdt|�}g}x2|dd�dkrJ|dd�}|jd�}xR|dkr�|jdd|�|jdd|�dr�|jd|d�}qQW|dkr�t|�}n|d|�}d|kr$|jd�}|d|�j�j�d||dd�j�}n|j|j��||d�}qW|S)Nr
rr�"z\"r�=)r�find�countr�indexr
�lower�append)�sZplist�end�f�irrr�_parseparamJs ;;r/cCsBt|t�r1|d|dtj|d�fStj|�SdS)Nrrr)rrr�unquote)r"rrr�
_unquotevalue^s"r1c@s�eZdZdZedd�Zdd�Zdddd	d
�Zdd�Zddd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dddd�Zddd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zdd1d2�Zd3d4�Zd5d6�Zdd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&ddIdJdKdL�Z'ddIdJdMdN�Z(dOdJddPddQdR�Z)dIdJdSdT�Z*dOdJdUdV�Z+ddWdX�Z,ddYdZ�Z-d[d\�Z.dd]d^�Z/dd_d`�Z0ddal1m2Z2dS)bra�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.
    cCsS||_g|_d|_d|_d|_d|_|_g|_d|_dS)Nz
text/plain)	�policy�_headers�	_unixfrom�_payload�_charsetZpreambleZepilogue�defects�
_default_type)�selfr2rrr�__init__ys						zMessage.__init__cCs
|j�S)z9Return the entire formatted message as a string.
        )�	as_string)r9rrr�__str__�szMessage.__str__FrNcCsoddlm}|dkr%|jn|}t�}||ddd|d|�}|j|d|�|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 mesasge; 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)�	GeneratorN�mangle_from_F�maxheaderlenr2�unixfrom)�email.generatorr=r2r�flatten�getvalue)r9r@r?r2r=�fp�grrrr;�s			zMessage.as_stringcCs
|j�S)z?Return the entire formatted message as a bytes object.
        )�as_bytes)r9rrr�	__bytes__�szMessage.__bytes__cCsiddlm}|dkr%|jn|}t�}||ddd|�}|j|d|�|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)�BytesGeneratorNr>Fr2r@)rArHr2rrBrC)r9r@r2rHrDrErrrrF�s	zMessage.as_bytescCst|jt�S)z6Return True if the message consists of multiple parts.)rr5�list)r9rrr�is_multipart�szMessage.is_multipartcCs
||_dS)N)r4)r9r@rrr�set_unixfrom�szMessage.set_unixfromcCs|jS)N)r4)r9rrr�get_unixfrom�szMessage.get_unixfromcCsW|jdkr|g|_n5y|jj|�Wntk
rRtd��YnXdS)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)r5r*�AttributeError�	TypeError)r9�payloadrrr�attach�s
zMessage.attachcCsT|j�r7|rdS|dkr)|jS|j|Sn|dk	rrt|jt�rrtdt|j���n|j}t|jdd��j�}t|t�rat	j
|�r|jdd�}|s^y"|j|j
dd�d�}Wqtk
r|jdd�}YqXq^qa|ray|jd�}Wq^tk
rZ|jd	�}Yq^Xqan|sk|S|d
kr�tj|�S|dkr�tdj|j���\}}x!|D]}|jj||�q�W|S|dkr=t|�}	t�}
y$tj|	|
dd�|
j�SWq=tjk
r9|SYq=Xnt|t�rP|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�replacezraw-unicode-escapezquoted-printable�base64��
x-uuencode�uuencode�uue�x-uue�quietT)rUrVrWrX)rJr5rrIrN�typer�getr)rZ_has_surrogatesr�decode�	get_param�LookupError�UnicodeError�quopriZdecodestringr	�join�
splitlinesr2Z
handle_defectr�uurC�Error)r9r.r\rO�cteZbpayloadr"r7ZdefectZin_fileZout_filerrr�get_payload�sV"	"


!
	zMessage.get_payloadcCs�t|d�r[|dkr(||_dSt|t�sFt|�}n|j|j�}nt|d�r�|jdd�|_n	||_|dk	r�|j|�ndS)z�Set the payload to the given value.

        Optional charset sets the message's default character set.  See
        set_charset() for details.
        rNr\rrQ)�hasattrr5r�Charsetr�output_charsetr\�set_charset)r9rOrrrr�set_payload0s		zMessage.set_payloadcCs�|dkr&|jd�d|_dSt|t�sDt|�}n||_d|krl|jdd�nd|kr�|jddd|j��n|jd|j��||j�kr�|j|j�|_nd|kr�|j	�}y||�Wq�t
k
r�|j}|r\y|jdd	�}Wq\tk
rX|j|j
�}Yq\Xn|j|�|_|jd|�Yq�XndS)
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.
        NrzMIME-Versionz1.0zContent-Typez
text/plainzContent-Transfer-EncodingrrQ)�	del_paramr6rrh�
add_headerZget_output_charset�	set_paramZbody_encoder5Zget_body_encodingrNrr_ri)r9rrerOrrrrjDs8
		
	
zMessage.set_charsetcCs|jS)zKReturn the Charset instance associated with the message's payload.
        )r6)r9rrr�get_charsetsszMessage.get_charsetcCs
t|j�S)z9Return the total number of headers, including duplicates.)rr3)r9rrr�__len__{szMessage.__len__cCs
|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[)r9�namerrr�__getitem__s	zMessage.__getitem__cCs�|jj|�}|r�|j�}d}x`|jD]R\}}|j�|kr4|d7}||kr�tdj||���q�q4q4Wn|jj|jj||��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)r2Zheader_max_countr)r3�
ValueError�formatr*�header_store_parse)r9rq�valZ	max_countZlname�found�k�vrrr�__setitem__�s
	zMessage.__setitem__cCsa|j�}g}x?|jD]4\}}|j�|kr|j||f�qqW||_dS)zwDelete all occurrences of a header, if present.

        Does not raise an exception if the header is missing.
        N)r)r3r*)r9rq�
newheadersrxryrrr�__delitem__�szMessage.__delitem__cCs |j�dd�|jD�kS)NcSs"g|]\}}|j��qSr)r))�.0rxryrrr�
<listcomp>�s	z(Message.__contains__.<locals>.<listcomp>)r)r3)r9rqrrr�__contains__�szMessage.__contains__ccs#x|jD]\}}|Vq
WdS)N)r3)r9Zfieldr"rrr�__iter__�szMessage.__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|]\}}|�qSrr)r}rxryrrrr~�s	z Message.keys.<locals>.<listcomp>)r3)r9rrr�keys�szMessage.keyscs�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.
        cs+g|]!\}}�jj||��qSr)r2�header_fetch_parse)r}rxry)r9rrr~�s	z"Message.values.<locals>.<listcomp>)r3)r9r)r9r�values�szMessage.valuescs�fdd��jD�S)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.
        cs1g|]'\}}|�jj||�f�qSr)r2r�)r}rxry)r9rrr~�s	z!Message.items.<locals>.<listcomp>)r3)r9r)r9r�items�sz
Message.itemscCsO|j�}x<|jD]1\}}|j�|kr|jj||�SqW|S)z~Get a header value.

        Like __getitem__() but return failobj instead of None when the field
        is missing.
        )r)r3r2r�)r9rq�failobjrxryrrrr[�s
zMessage.getcCs|jj||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)r3r*)r9rqr"rrr�set_raw�szMessage.set_rawcCst|jj��S)z�Return the (name, value) header pairs without modification.

        This is an "internal" API, intended only for use by a generator.
        )�iterr3�copy)r9rrr�	raw_items�szMessage.raw_itemscCskg}|j�}xH|jD]=\}}|j�|kr|j|jj||��qqW|sg|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)r3r*r2r�)r9rqr�r�rxryrrr�get_all�s	#zMessage.get_allcKs�g}xd|j�D]V\}}|dkrG|j|jdd��q|jt|jdd�|��qW|dk	r�|jd|�ntj|�||<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*rRr#�insert�	SEMISPACEra)r9�_name�_valueZ_params�partsrxryrrrrms&zMessage.add_headercCs�|j�}xsttt|j��|j�D]D\}\}}|j�|kr.|jj||�|j|<Pq.q.Wt|��dS)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�rangerr3r2ru�KeyError)r9r�r�r.rxryrrr�replace_header"s4zMessage.replace_headercCsdt�}|jd|�}||kr1|j�St|�dj�}|jd�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.
        zcontent-typer�/rz
text/plain)�objectr[�get_default_typerr)r')r9�missingr"�ctyperrr�get_content_type5s
	
zMessage.get_content_typecCs|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)r9r�rrr�get_content_maintypeMszMessage.get_content_maintypecCs|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�r)r�r�)r9r�rrr�get_content_subtypeVszMessage.get_content_subtypecCs|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.
        )r8)r9rrrr�_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.
        N)r8)r9r�rrr�set_default_typehszMessage.set_default_typec	Cs�t�}|j||�}||kr+|Sg}x�t|�D]t}y4|jdd�\}}|j�}|j�}Wn$tk
r�|j�}d}YnX|j||f�q>Wtj|�}|S)Nr%rr)	r�r[r/r�r
rsr*rZ
decode_params)	r9r��headerr�r"�params�prqrvrrr�_get_params_preserveqs 	
zMessage._get_params_preservezcontent-typeTcCsJt�}|j||�}||kr+|S|rBdd�|D�S|SdS)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.
        cSs(g|]\}}|t|�f�qSr)r1)r}rxryrrrr~�s	z&Message.get_params.<locals>.<listcomp>N)r�r�)r9r�r�r0r�r�rrr�
get_params�s
	zMessage.get_paramscCsf||kr|SxO|j||�D];\}}|j�|j�kr#|rWt|�S|Sq#q#W|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)r1)r9rr�r�r0rxryrrrr]�s
zMessage.get_paramzContent-TypercCs�t|t�r(|r(|||f}n||krO|j�dkrOd}n|j|�}|j|d|�s�|s�t|||�}qJtj|t|||�g�}n�d}x�|jd|d|�D]u\}	}
d}|	j�|j�krt|||�}nt|	|
|�}|s1|}q�tj||g�}q�W||j|�kr�|rx|j	||�q�||=|||<ndS)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 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.
        zcontent-typez
text/plainr�rr0N)
rrr)r[r]r#r�rar�r�)r9rr"r��requoterZlanguagerRr�Z	old_paramZ	old_valueZappend_paramrrrrn�s2		zMessage.set_paramcCs�||krdSd}x}|jd|d|�D]c\}}|j�|j�kr/|snt|||�}q�tj|t|||�g�}q/q/W||j|�kr�||=|||<ndS)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�r0)r�r)r#r�rar[)r9rr�r�Z	new_ctyper�ryrrrrl�s%	zMessage.del_paramcCs�|jd�dkst�n|j�dkrD|d=d|d<n||kr^|||<dS|jd|d	|�}||=|||<x4|dd�D]"\}}|j||||�q�WdS)
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�rzcontent-typezmime-versionz1.0zMIME-VersionNr�r0)r'rsr)r�rn)r9rZr�r�r�r�ryrrr�set_types	


zMessage.set_typecCset�}|jd|d�}||krB|jd|d�}n||krR|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.
        �filenamezcontent-dispositionrqzcontent-type)r�r]r�collapse_rfc2231_valuer
)r9r�r�r�rrr�get_filename's	zMessage.get_filenamecCs>t�}|jd|�}||kr+|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�r]rr��rstrip)r9r�r�r�rrr�get_boundary7s
	zMessage.get_boundarycCs�t�}|j|d�}||kr9tjd��ng}d}xY|D]Q\}}|j�dkr�|jdd|f�d}qL|j||f�qLW|s�|jdd|f�ng}x�|jD]�\}	}
|	j�dkrmg}xG|D]?\}}
|
dkr$|j|�q�|jd||
f�q�Wtj|�}
|j|j	j
|	|
��q�|j|	|
f�q�W||_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.
        zcontent-typezNo Content-Type header foundFr�z"%s"Trz%s=%sN)r�r�rZHeaderParseErrorr)r*r3r�rar2ru)r9r�r�r�Z	newparamsZfoundpZpkZpvr{�hryr�rxrvrrr�set_boundaryDs2
		zMessage.set_boundarycCs�t�}|jd|�}||kr+|St|t�r�|dpGd}y&|djd�}t||�}Wq�ttfk
r�|d}Yq�Xny|jd�Wntk
r�|SYnX|j�S)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-asciirzraw-unicode-escape)	r�r]rrrrr^r_r))r9r�r�rZpcharsetrFrrr�get_content_charsetrs 	
	zMessage.get_content_charsetcs�fdd�|j�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|]}|j���qSr)r�)r}�part)r�rrr~�s	z(Message.get_charsets.<locals>.<listcomp>)�walk)r9r�r)r�r�get_charsets�szMessage.get_charsets)r�)3�__name__�
__module__�__qualname__�__doc__rr:r<r;rGrFrJrKrLrPrfrkrjrorprrrzr|rr�r�r�r�r[r�r�r�rmr�r�r�r�r�r�r�r�r]rnrlr�r�r�r�r�r�Zemail.iteratorsr�rrrrrjs`Z/
				!2 
.c@s4eZdZdd�Zdd�Zdd�ZdS)�
_IsAttachmentcCs
||_dS)N)r")r9r"rrrr:�sz_IsAttachment.__init__cCs|jS)N)r")r9rrr�__call__�sz_IsAttachment.__call__cCstjdtdd�|jS)Nz6is_attachment will be a method, not a property, in 3.5�
stacklevel�)�warnings�warn�DeprecationWarningr")r9rrr�__bool__�s	z_IsAttachment.__bool__N)r�r�r�r:r�r�rrrrr��sr�c@s!eZdZddd�Zedd��Zdd�Zd.dd�Zd/d0d1d2hZdd�Z	dd�Z
dddd�Zdddd�Zdd�Z
ddd�Zddd�Zddd �Zd!dd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�ZdS)3�MIMEPartNcCs9|dkr%ddlm}|}ntj||�dS)Nr)�default)Zemail.policyr�rr:)r9r2r�rrrr:�s	zMIMEPart.__init__cCs:|jd�}|dkr!dn|jdk}t|�S)Nzcontent-dispositionF�
attachment)r[Zcontent_dispositionr�)r9Zc_d�resultrrr�
is_attachment�s!zMIMEPart.is_attachmentc	csu|j�rdS|j�jd�\}}|dkr^||krZ|j|�|fVndS|dkrndS|dkr�x)|j�D]}|j||�DdHq�WdSd|kr�|jd�|fVnd}|jd�}|rx1|j�D] }|d|kr�|}Pq�q�Wn|dkrM|j�}|rD|dnd}n|dk	rq|j||�DdHndS)Nr��text�	multipart�related�startz
content-idr)r�r�r�r(�
iter_parts�
_find_bodyr]rf)	r9r��preferencelist�maintype�subtypeZsubpart�	candidater�Zsubpartsrrrr��s6zMIMEPart._find_bodyr��html�plaincCsdt|�}d}xK|j||�D]7\}}||kr%|}|}|dkr\Pq\q%q%W|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�)r9r�Z	best_prioZbodyZprior�rrr�get_body�s
zMIMEPart.get_bodyr�r��alternativec	csd|j�jd�\}}|dks3|dkr7dS|j�}|dkr�|dkr�|jd�}|r�d}g}x9|D]1}|jd�|kr�d	}q�|j|�q�W|r�|DdHdSn|jd
�|DdHdSg}xo|D]g}|j�jd�\}}||f|jkrW|j�rW||krW|j|�q�n|Vq�WdS)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�Fz
content-idTr)	r�r�rfr]r[r*�pop�_body_typesr�)	r9r�r�r�r�rwZattachmentsr��seenrrr�iter_attachments�s6
		
	

zMIMEPart.iter_attachmentsccs(|j�dkr$|j�DdHndS)z~Return an iterator over all immediate subparts of a multipart.

        Return an empty iterator for a non-multipart.
        r�N)r�rf)r9rrrr�#szMIMEPart.iter_parts�content_managercOs.|dkr|jj}n|j|||�S)N)r2r��get_content)r9r��args�kwrrrr�+szMIMEPart.get_contentcOs2|dkr|jj}n|j|||�dS)N)r2r��set_content)r9r�r�r�rrrr�0szMIMEPart.set_contentc
Cs>|j�dkrU|j�}||f}||krUtdj||���qUng}g}xU|jD]J\}}|j�jd�r�|j||f�qk|j||f�qkW|r�t|�d|j	�}	||	_|j
|	_
|	g|_
n	g|_
||_d||d<|dk	r:|jd|�ndS)Nr�zCannot convert {} to {}zcontent-r2z
multipart/zContent-Typer�)r�r�rsrtr3r)�
startswithr*rZr2r5rn)
r9r�Zdisallowed_subtypesr�Zexisting_subtypeZkeep_headersZpart_headersrqr"r�rrr�_make_multipart5s,
				zMIMEPart._make_multipartcCs|jdd|�dS)Nr�r��mixed)zalternativer�)r�)r9r�rrr�make_relatedPszMIMEPart.make_relatedcCs|jdd|�dS)Nr�r�)zmixed)r�)r9r�rrr�make_alternativeSszMIMEPart.make_alternativecCs|jdf|�dS)Nr�)r�)r9r�rrr�
make_mixedVszMIMEPart.make_mixed�_dispcOs�|j�dks$|j�|kr;t|d|��nt|�d|j�}|j||�|r�d|kr�||d<n|j|�dS)Nr�Zmake_r2zcontent-dispositionzContent-Disposition)r�r��getattrrZr2r�rP)r9Z_subtyper�r�r�r�rrr�_add_multipartYs
zMIMEPart._add_multipartcOs|jddd||�dS)Nr�r�Zinline)r�)r9r�r�rrr�add_relatedcszMIMEPart.add_relatedcOs|jd||�dS)Nr�)r�)r9r�r�rrr�add_alternativefszMIMEPart.add_alternativecOs|jddd||�dS)Nr�r�r�)r�)r9r�r�rrr�add_attachmentiszMIMEPart.add_attachmentcCsg|_d|_dS)N)r3r5)r9rrr�clearls	zMIMEPart.clearcCs&dd�|jD�|_d|_dS)NcSs7g|]-\}}|j�jd�s||f�qS)zcontent-)r)r�)r}�nryrrrr~qs		z*MIMEPart.clear_content.<locals>.<listcomp>)r3r5)r9rrr�
clear_contentpszMIMEPart.clear_content)�relatedr�r�)�textr�)r�r�)�	multipartr�)r�zalternative)r�r�r�r:�propertyr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s,	.
r�cs"eZdZ�fdd�Z�S)�EmailMessagecs0t�j||�d|kr,d|d<ndS)NzMIME-Versionz1.0)�superr�)r9r�r�)�	__class__rrr�xszEmailMessage.set_content)r�r�r�r�rr)r�rr�vsr�)r��__all__�rercr`r��iorrZemailrrZemail._policybaserrr6Zemail._encoded_wordsr	rhr��compilerrr#r/r1rr�r�r�rrrr�<module>s2		
"���?�

Zerion Mini Shell 1.0