3 ^@sdZddgZddlZddlZddlZddlmZmZddlm Z ddlm Z ddl m Z m Z dd lmZdd lmZejZd Zejd Zd dZdddZddZddZGdddZGdddeZGdddeZdS)z8Basic message object for the email package object model.Message EmailMessageN)BytesIOStringIO)utils)errors)Policycompat32)charset)decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]cCs4t|jd\}}}|s$|jdfS|j|jfS)N;)str partitionstrip)paramasepbr%/usr/lib64/python3.6/email/message.py _splitparams rTc Cs|dk rt|dkrt|trL|d7}tj|d|d|d}d||fSy|jdWn2tk r|d7}tj|dd }d||fSX|stj|rd |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=%sasciizutf-8z%s="%s") len isinstancetuplerZencode_rfc2231encodeUnicodeEncodeError tspecialssearchquote)rvaluer#rrr _formatparam's   r%cCsdt|}g}x|dddkr|dd}|jd}x<|dkrt|jdd||jdd|drt|jd|d}q:W|dkrt|}|d|}d|kr|jd}|d|jjd||ddj}|j|j||d}qW|S)Nr rr"z\"r=)r findcountrindexrlowerappend)sZplistendfirrr _parseparamIs    *  ,r1cCs4t|tr&|d|dtj|dfStj|SdS)Nrrr)rrrunquote)r$rrr _unquotevalue]s r3c@seZdZdZefddZddZddd d Zd d Zded dZ ddZ ddZ ddZ ddZ dfddZdgddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zdhd1d2Zd3d4Zd5d6Zdid7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&djdKdLZ'dkdMdNZ(dldQdRZ)dmdSdTZ*dndUdVZ+dodWdXZ,dpdYdZZ-d[d\Z.dqd]d^Z/drd_d`Z0dadbZ1ddcl2m3Z3dS)sraBasic 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)Nz text/plain) policy_headers _unixfrom_payload_charsetZpreambleZepiloguedefects _default_type)selfr4rrr__init__xs zMessage.__init__cCs|jS)z9Return the entire formatted message as a string. ) as_string)r;rrr__str__szMessage.__str__FrNcCsJddlm}|dkr|jn|}t}||d||d}|j||d|jS)aReturn 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) GeneratorNF) mangle_from_ maxheaderlenr4)unixfrom)email.generatorr?r4rflattengetvalue)r;rBrAr4r?fpgrrrr=s zMessage.as_stringcCs|jS)z?Return the entire formatted message as a bytes object. )as_bytes)r;rrr __bytes__szMessage.__bytes__cCsHddlm}|dkr|jn|}t}||d|d}|j||d|jS)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)r@r4)rB)rCrJr4rrDrE)r;rBr4rJrFrGrrrrHs  zMessage.as_bytescCs t|jtS)z6Return True if the message consists of multiple parts.)rr7list)r;rrr is_multipartszMessage.is_multipartcCs ||_dS)N)r6)r;rBrrr set_unixfromszMessage.set_unixfromcCs|jS)N)r6)r;rrr get_unixfromszMessage.get_unixfromc CsF|jdkr|g|_n.y|jj|Wntk r@tdYnXdS)zAdd 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)r7r,AttributeError TypeError)r;payloadrrrattachs   zMessage.attachc Cs|jr(|rdS|dkr|jS|j|S|dk rPt|jt rPtdt|j|j}t|jddj}t|trt j |r|j dd}|sy|j |j ddd}Wn tk r|j dd}YnXn6|ry|j d}Wn tk r|j d }YnX|s |S|d kr tj|S|d krbtd j|j\}}x|D]}|jj||qFW|S|dkrt|} t} ytj | | dd| jStjk r|SXt|tr|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-encodingrrsurrogateescaper replacezraw-unicode-escapezquoted-printablebase64 x-uuencodeuuencodeuuex-uueT)quiet)rWrXrYrZ)rLr7rrKrPtyper getr+rZ_has_surrogatesrdecode get_param LookupError UnicodeErrorquopriZ decodestringr join splitlinesr4Z handle_defectruurEError) r;r0r^rQcteZbpayloadr$r9ZdefectZin_fileZout_filerrr get_payloadsV"          zMessage.get_payloadcCspt|dr:|dkr||_dSt|ts.t|}|j|j}t|drT|jdd|_n||_|dk rl|j|dS)zSet the payload to the given value. Optional charset sets the message's default character set. See set_charset() for details. rNr^rrS)hasattrr7rCharsetroutput_charsetr^ set_charset)r;rQr rrr set_payload/s    zMessage.set_payloadcCs|dkr|jdd|_dSt|ts.t|}||_d|krH|jddd|krf|jdd|jdn|jd|j||jkr|j|j|_d|kr|j }y ||Wnjt k r|j}|ry|j d d }Wn t k r|j |j }YnX|j||_|jd|YnXdS) aSet 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 z MIME-Versionz1.0z Content-Typez text/plain)r zContent-Transfer-EncodingrrS) del_paramr8rrj add_headerZget_output_charset set_paramZ body_encoder7Zget_body_encodingrPrrark)r;r rgrQrrrrlCs8       zMessage.set_charsetcCs|jS)zKReturn the Charset instance associated with the message's payload. )r8)r;rrr get_charsetrszMessage.get_charsetcCs t|jS)z9Return the total number of headers, including duplicates.)rr5)r;rrr__len__zszMessage.__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])r;namerrr __getitem__~s zMessage.__getitem__cCsv|jj|}|r\|j}d}x>|jD]4\}}|j|kr$|d7}||kr$tdj||q$W|jj|jj||dS)zSet 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)r4Zheader_max_countr+r5 ValueErrorformatr,header_store_parse)r;rsvalZ max_countZlnamefoundkvrrr __setitem__s  zMessage.__setitem__cCsD|j}g}x,|jD]"\}}|j|kr|j||fqW||_dS)zwDelete all occurrences of a header, if present. Does not raise an exception if the header is missing. N)r+r5r,)r;rs newheadersrzr{rrr __delitem__s  zMessage.__delitem__cCs|jdd|jDkS)NcSsg|]\}}|jqSr)r+).0rzr{rrr sz(Message.__contains__..)r+r5)r;rsrrr __contains__szMessage.__contains__ccsx|jD]\}}|VqWdS)N)r5)r;Zfieldr$rrr__iter__szMessage.__iter__cCsdd|jDS)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)rrzr{rrrrsz Message.keys..)r5)r;rrrkeyssz Message.keyscsfddjDS)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|]\}}jj||qSr)r4header_fetch_parse)rrzr{)r;rrrsz"Message.values..)r5)r;r)r;rvaluess zMessage.valuescsfddjDS)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|]\}}|jj||fqSr)r4r)rrzr{)r;rrrsz!Message.items..)r5)r;r)r;ritemss z Message.itemscCs:|j}x,|jD]"\}}|j|kr|jj||SqW|S)z~Get a header value. Like __getitem__() but return failobj instead of None when the field is missing. )r+r5r4r)r;rsfailobjrzr{rrrr]s  z Message.getcCs|jj||fdS)zStore name and value in the model without modification. This is an "internal" API, intended only for use by a parser. N)r5r,)r;rsr$rrrset_rawszMessage.set_rawcCst|jjS)zReturn the (name, value) header pairs without modification. This is an "internal" API, intended only for use by a generator. )iterr5copy)r;rrr raw_itemsszMessage.raw_itemscCsLg}|j}x2|jD](\}}|j|kr|j|jj||qW|sH|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+r5r,r4r)r;rsrrrzr{rrrget_alls  zMessage.get_allcKstg}xH|jD]<\}}|dkr2|j|jddq|jt|jdd|qW|dk rb|jd|tj|||<dS)uExtended 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)rr,rTr%insert SEMISPACErc)r;_name_valueZ_paramspartsrzr{rrrros zMessage.add_headercCs^|j}xPttt|j|jD].\}\}}|j|kr |jj|||j|<Pq Wt|dS)zReplace 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+ziprangerr5r4rwKeyError)r;rrr0rzr{rrrreplace_header!s $ zMessage.replace_headercCsHt}|jd|}||kr"|jSt|dj}|jddkrDdS|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))r;missingr$ctyperrrget_content_type4s  zMessage.get_content_typecCs|j}|jddS)zReturn the message's main content type. This is the `maintype' part of the string returned by get_content_type(). rr)rsplit)r;rrrrget_content_maintypeLszMessage.get_content_maintypecCs|j}|jddS)zReturns the message's sub-content type. This is the `subtype' part of the string returned by get_content_type(). rr)rr)r;rrrrget_content_subtypeUszMessage.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. )r:)r;rrrr^szMessage.get_default_typecCs ||_dS)zSet 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)r:)r;rrrrset_default_typegszMessage.set_default_typec Cst}|j||}||kr|Sg}xdt|D]X}y$|jdd\}}|j}|j}Wn tk rt|j}d}YnX|j||fq,Wtj|}|S)Nr'rr) rr]r1rrrur,rZ decode_params) r;rheaderrr$paramsprsrxrrr_get_params_preserveps     zMessage._get_params_preserve content-typeTcCs8t}|j||}||kr|S|r0dd|DS|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. cSsg|]\}}|t|fqSr)r3)rrzr{rrrrsz&Message.get_params..N)rr)r;rrr2rrrrr get_paramss  zMessage.get_paramscCsJ||kr |Sx8|j||D](\}}|j|jkr|r>t|S|SqW|S)aReturn 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) )rr+r3)r;rrrr2rzr{rrrr_szMessage.get_param Content-Typerc Cst|t r|r|||f}||kr4|jdkr4d}n |j|}|j||dsv|s^t|||}qtj|t|||g}nfd}x`|j||dD]N\} } d} | j|jkrt|||} n t| | |} |s| }qtj|| g}qW||j|kr|r|j ||n||=|||<dS)aSet 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. z content-typez text/plain)rr)rr2N) rrr+r]r_r%rrcrr) r;rr$rrequoter ZlanguagerTrZ old_paramZ old_valueZ append_paramrrrrps2   zMessage.set_paramcCs||kr dSd}xR|j||dD]@\}}|j|jkr |sJt|||}q tj|t|||g}q W||j|kr||=|||<dS)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. Nr)rr2)rr+r%rrcr])r;rrrZ new_ctyperr{rrrrnszMessage.del_paramcCs|jddkst|jdkr,|d=d|d<||kr@|||<dS|j||d}||=|||<x(|ddD]\}}|j||||qjWdS) 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. rrz content-typez mime-versionz1.0z MIME-VersionN)rr2)r)rur+rrp)r;r\rrrrr{rrrset_types zMessage.set_typecCsDt}|jd|d}||kr*|jd|d}||kr6|Stj|jS)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-dispositionrsz content-type)rr_rcollapse_rfc2231_valuer)r;rrrrrr get_filename&szMessage.get_filenamecCs,t}|jd|}||kr|Stj|jS)zReturn 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)rr_rrrstrip)r;rrrrrr get_boundary6s  zMessage.get_boundarycCs t}|j|d}||kr$tjdg}d}xB|D]:\}}|jdkr^|jdd|fd}q2|j||fq2W|s|jdd|fg}x|jD]\} } | jdkrg} x6|D].\} } | dkr| j| q| jd| | fqWtj| } |j|j j | | q|j| | fqW||_d S) aSet 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 foundFrz"%s"Trz%s=%sN) rrrZHeaderParseErrorr+r,r5rrcr4rw)r;rrrZ newparamsZfoundpZpkZpvr}hr{rrzrxrrr set_boundaryCs2      zMessage.set_boundarycCst}|jd|}||kr|St|trr|dp2d}y|djd}t||}Wn ttfk rp|d}YnXy|jdWntk r|SX|jS)zReturn 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. r rzus-asciirzraw-unicode-escape) rr_rrrr r`rar+)r;rrr ZpcharsetrHrrrget_content_charsetqs    zMessage.get_content_charsetcsfdd|jDS)aReturn 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|]}|jqSr)r)rpart)rrrrsz(Message.get_charsets..)walk)r;rr)rr get_charsetsszMessage.get_charsetscCs*|jd}|dkrdSt|dj}|S)zReturn the message's content-disposition if it exists, or None. The return values can be either 'inline', 'attachment' or None according to the rfc2183. zcontent-dispositionNr)r]rr+)r;r$c_drrrget_content_dispositions  zMessage.get_content_disposition)r)FrN)FN)NF)N)N)N)NrT)NrT)rTNrF)rT)rT)N)N)N)N)4__name__ __module__ __qualname____doc__r r<r>r=rIrHrLrMrNrRrhrmrlrqrrrtr|r~rrrrrr]rrrrorrrrrrrrr_rprnrrrrrrrZemail.iteratorsrrrrrrisb    Z /            ! 2   .   cseZdZd3ddZd4fdd ZddZd d Zd d Zd6ddZd7d8d9d:hZ ddZ ddZ ddddZ ddddZ ddZd;d d!ZdMIMEPartNcCs(|dkrddlm}|}tj||dS)Nr)default)Z email.policyrrr<)r;r4rrrrr<s zMIMEPart.__init__Fcs0|dkr|jn|}|dkr |j}tj||dS)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 mesasge; if it is not specified the policy associated with the message instance is used. N)rAr4)r4Zmax_line_lengthsuperr=)r;rBrAr4) __class__rrr=s zMIMEPart.as_stringcCs|j|jjdddS)NT)utf8)r4)r=r4Zclone)r;rrrr>szMIMEPart.__str__cCs |jd}|dkrdS|jdkS)Nzcontent-dispositionF attachment)r]Zcontent_disposition)r;rrrr is_attachments zMIMEPart.is_attachmentc cs |jr dS|jjd\}}|dkrB||kr>|j||fVdS|dkrNdS|dkr~x"|jD]}|j||EdHq`WdSd|kr|jd|fVd}|jd}|rx"|jD]}|d|kr|}PqW|dkr|j}|r|dnd}|dk r|j||EdHdS)Nrtext multipartrelatedstartz content-idr)rrrr* iter_parts _find_bodyr_rh) r;rpreferencelistmaintypesubtypeZsubpart candidaterZsubpartsrrrrs6   zMIMEPart._find_bodyrhtmlplaincCsDt|}d}x2|j||D]"\}}||kr|}|}|dkrPqW|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;rZ best_prioZbodyZpriorrrrget_bodys zMIMEPart.get_bodyrr alternativec cs|jjd\}}|dks"|dkr&dS|jj}|dkr|dkr|jd}|rd}g}x*|D]"}|jd|krvd }q^|j|q^W|r|EdHdS|jd |EdHdSg}xP|D]H}|jjd\}}||f|jkr|j r||kr|j|q|VqWdS) 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. rrrNrrFz content-idTr) rrrhrr_r]r,pop _body_typesr) r;rrrrryZ attachmentsrseenrrriter_attachmentss6         zMIMEPart.iter_attachmentsccs|jdkr|jEdHdS)z~Return an iterator over all immediate subparts of a multipart. Return an empty iterator for a non-multipart. rN)rrh)r;rrrr4s zMIMEPart.iter_parts)content_managercOs"|dkr|jj}|j|f||S)N)r4r get_content)r;rargskwrrrr<szMIMEPart.get_contentcOs&|dkr|jj}|j|f||dS)N)r4r set_content)r;rrrrrrrAszMIMEPart.set_contentc Cs|jdkr6|j}||f}||kr6tdj||g}g}x>|jD]4\}}|jjdrl|j||fqF|j||fqFW|rt||j d} || _|j | _ | g|_ ng|_ ||_d||d<|dk r|j d|dS)NrzCannot convert {} to {}zcontent-)r4z multipart/z Content-Typer) rrrurvr5r+ startswithr,r\r4r7rp) r;rZdisallowed_subtypesrZexisting_subtypeZ keep_headersZ part_headersrsr$rrrr_make_multipartFs,     zMIMEPart._make_multipartcCs|jdd|dS)Nrrmixed)rr)r)r;rrrr make_relatedaszMIMEPart.make_relatedcCs|jdd|dS)Nrr)r)r)r;rrrrmake_alternativedszMIMEPart.make_alternativecCs|jdf|dS)Nr)r)r;rrrr make_mixedgszMIMEPart.make_mixed)_dispcOsf|jdks|j|kr(t|d|t||jd}|j|||rXd|krX||d<|j|dS)NrZmake_)r4zcontent-dispositionzContent-Disposition)rrgetattrr\r4rrR)r;Z_subtyperrrrrrr_add_multipartjs    zMIMEPart._add_multipartcOs|jd|ddi|dS)NrrZinline)r)r)r;rrrrr add_relatedtszMIMEPart.add_relatedcOs|jd||dS)Nr)r)r)r;rrrrradd_alternativewszMIMEPart.add_alternativecOs|jd|ddi|dS)Nrrr)r)r)r;rrrrradd_attachmentzszMIMEPart.add_attachmentcCsg|_d|_dS)N)r5r7)r;rrrclear}szMIMEPart.clearcCsdd|jD|_d|_dS)NcSs&g|]\}}|jjds||fqS)zcontent-)r+r)rnr{rrrrsz*MIMEPart.clear_content..)r5r7)r;rrr clear_contentszMIMEPart.clear_content)N)FNNrrr)r)rr)rr)rr)rr)N)N)N)rrrr<r=r>rrrrrrrrrrrrrrrrrr __classcell__rr)rrrs0  .    rcseZdZfddZZS)rcs"tj||d|krd|d<dS)Nz MIME-Versionz1.0)rr)r;rr)rrrrszEmailMessage.set_content)rrrrrrr)rrrs)NT)r__all__rererbiorrZemailrrZemail._policybaserr r r8Zemail._encoded_wordsr rjrcompiler!rr%r1r3rrrrrrrs6      " NW