ó ù^‚Rc@s6dZdddgZddlZddlZddlZddlZddlmZddl m Z dZ d Z d Z d d Zd Zd Ze dƒZe dƒZejdejejBejBƒZejdƒZejdƒZejjZd„Zeed d„Zdfd„ƒYZd„Z d„Z!dS(s+Header encoding and decoding functionality.tHeadert decode_headert make_headeriÿÿÿÿN(tHeaderParseError(tCharsets t u iuiLsus-asciisutf-8s§ =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the encoded string \?= # literal ?= (?=[ \t]|$) # whitespace or the end of the string s[\041-\176]+:$s \n[^ \t]+:c CsGt|ƒ}tj|ƒs(|d fgSg}d}x |jƒD]þ}tj|ƒso|j|d fƒqAntj|ƒ}x¾|r>|jdƒjƒ}|rõ|rß|ddd krß|ddt |d f|dAppend 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 true), 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 this case, when producing an RFC 2822 compliant header using RFC 2047 rules, the Unicode string will be encoded using the following charsets in order: us-ascii, the charset hint, utf-8. The first character set not to provoke a UnicodeError is used. Optional `errors' is passed as the third argument to any unicode() or ustr.encode() call. t8bitsus-asciisutf-8 conversion failedN(R R/R*RR t input_codecR>t output_codecR;R.tUTF8t UnicodeErrortFalsetAssertionErrorR3R(R7R"R#R8tincodectustrtoutcodec((s"/usr/lib/python2.7/email/header.pyRés(    cCs0|j|ƒ}|j|tƒ}|j|ƒ}||krI||fgS|dkrb||fgS|dkr„|j||||ƒS|t|ƒkrË|}|j|| tƒ} |j||tƒ} nt|||ƒ\} } |j| ƒ} |j| tƒ} | |fg} | |j| ||j |ƒS(NRHsus-ascii( t to_splittabletfrom_splittabletTruetencoded_header_lent _split_asciiRRMt _binsplitt_splitR6(R7R"R#R't splitcharst splittableR%telentsplitpnttfirsttlastt fsplittabletfencodedtchunk((s"/usr/lib/python2.7/email/header.pyRX s$    cCs8t|||j|j|ƒ}t||gt|ƒƒS(N(RVR6R0tzipR(R7R"R#tfirstlenRYtchunks((s"/usr/lib/python2.7/email/header.pyRVNsc Cs±g}xŽ|D]†\}}|s%q n|dks@|jdkrI|}n|j|ƒ}|rz|djdƒrzd}nd}t||||ƒq Wt|j}|j|ƒS(NiÿÿÿÿRR(R theader_encodingt header_encodetendswitht _max_appendtNLR0R@( R7t newchunksR'RdRR#R"textratjoiner((s"/usr/lib/python2.7/email/header.pyt_encode_chunksSs   s;, c CsÓg}|j}d}x~|jD]s\}}||d}||jdƒkrW|}n||j||||ƒ7}|d\}} | j|ƒ}qW|j||ƒ} tj| ƒrÏtdj| ƒƒ‚n| S(s‡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. This method will do its best to convert the string to the correct character set used in email, and encode and line wrap it safely with the appropriate scheme for that character set. If the given charset is not known or an error occurs during conversion, this function will return the header untouched. Optional splitchars is a string containing characters to split long ASCII lines on, in rough support of RFC 2822's `highest level syntactic breaks'. This doesn't affect RFC 2047 encoded lines. iiRiÿÿÿÿs8header value appears to contain an embedded header: {!r}( R5R3RURXRmt_embeded_headerR Rtformat( R7RYRjR'tlastlenR"R#t targetlent lastchunkt lastcharsettvalue((s"/usr/lib/python2.7/email/header.pyR;vs   N( t__name__t __module__R R:R<RDRFRGRRXRVRmR;(((s"/usr/lib/python2.7/email/header.pyRs3    7 .  #c Cs|g}|}xi|jƒD][}|jƒ}t|ƒ|krV|j|ƒ|}qnx4|D]}||kr]Pq]q]W|j|ƒ|}qtjd|ƒ} |dkrµ|} nd} | d} t| ƒ} t|jdtƒƒ} g}d}x]| j|ƒD]L}|t dt|ƒdƒ| }t|ƒ}| }|dkr|rt|ƒdkrt j |dƒr|j|ƒ||7}q|||kr:|rÃ|j| j |ƒ| ƒn||kr|dkrt ||||dƒ}|j|d ƒ|dg}n |g}| t|dƒ}|}q|j|ƒ||7}qW|r|j| j |ƒƒqqW|S( Ns%s\s*s;,RRs iiiÿÿÿÿ(R tlstripRRtretcompileR1R2RtmaxtfcretmatchR@RVtextend(R"RctrestlenR)RYtlinestmaxlenRtchtcreteolRltjoinlentwslentthistlinelentparttcurlentpartlent onfirstlinetsubl((s"/usr/lib/python2.7/email/header.pyRV¢s^         ! %       c Cs±d}t|ƒ}xf||krz||dd?}|j|| tƒ}|j|ƒ}||krm|}q|d}qW|j|| tƒ}|j||tƒ} || fS(Nii(RRSRTRURM( RZR#R'titjtmRatchunklenR]R^((s"/usr/lib/python2.7/email/header.pyRWès    ("t__doc__t__all__RxRtemail.quoprimimeRtemail.base64mimet email.errorsRt email.charsetRRiRR=R2R?R4R.RKRytVERBOSEt IGNORECASEt MULTILINER R{RnRRhRR RRRVRW(((s"/usr/lib/python2.7/email/header.pyts:           < ÿ F