mò &U²Ic@sÿdZdkZdkZdkZdkZdklZdkl Z dZ dZ dZ ddZ dZd Ze d ƒZe d ƒZeid eieiBƒZeid ƒZeiiZd„Zeedd„Zdfd„ƒYZd„Zd„ZdS(s+Header encoding and decoding functionality.N(sHeaderParseError(sCharsets t u iuiLsus-asciisutf-8si =\? # 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 ?= s[\041-\176]+:$c Cs?t|ƒ}ti|ƒp|d fgSng}d} xÿ|iƒD]ñ} ti| ƒp|i | d fƒqFnti | ƒ}x¯|o§|i dƒi ƒ}|oW|o9|ddd jo$|ddt|d f|dRR@R?((R"t __unicode__»s       cCs||iƒjS(N(totherR/R<(R/RF((R"t__eq__ÒscCs ||j S(N(R/RF(R/RF((R"t__ne__×scCs7|djo |i}n!t|tƒpt|ƒ}n|djoÖt|tƒoF|ipd}t |||ƒ}|i pd}|i||ƒqt|t ƒolxit|tfD]C}y'|i pd}|i||ƒ}PWq½tj oq½Xq½Wtp td‚qn|ii||fƒdS(s>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 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(RRR/R0R*R+RRt input_codectincodecRBR7tustrt output_codectoutcodecR<R.tUTF8t UnicodeErrortFalsetAssertionErrorR6R (R/RRR7RLRNRK((R"R Ús,    cCsA|i|ƒ}|i|tƒ} |i| ƒ} | |jo| |fgSn|djo||fgSn‰|djo|i ||||ƒSnb| t |ƒjo6|} |i|| tƒ} |i|| tƒ}nt|||ƒ\} }|i| ƒ}|i|tƒ}||fg} | |i|||i|ƒS(NRIsus-ascii(Rt to_splittableRt splittabletfrom_splittabletTrueRtencoded_header_lentelenR$R/t _split_asciit splitcharsR2tsplitpntRQtfirsttlastt _binsplitt fsplittabletfencodedtchunkt_splitR:(R/RRR$RZR]RTR_R`RXR[RRaR\((R"Rbs$   cCs8t|||i|i|ƒ}t||gt |ƒƒS(N( RYRtfirstlenR/R:R1RZtchunkstzipRR2(R/RRRcRZRd((R"RY?sc Cs¹g}x–|D]Ž\}}|pq n|djp|idjo |}n|i|ƒ}|o|didƒo d}nd}t ||||ƒq Wt |i}|i|ƒS(NiÿÿÿÿRR(Rdt newchunksRRRtheader_encodingRt header_encodetendswithtextrat _max_appendR$tNLR/R1tjoinerRD( R/RfR$RjRRRRdRm((R"t_encode_chunksDs    s;, c Cs¨g}|i}d} x€|iD]u\}}|| d}||i dƒjo |}n||i ||||ƒ7}|d\}}|i |ƒ} qW|i||ƒ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ÿÿÿÿN(RfR/R9R$tlastlenR6RRt targetlenRWRbRZt lastchunkt lastcharsetRn( R/RZR$RqRrRRfRRpRo((R"R<gs   ( t__name__t __module__RR;R=RERGRHR RbRYRnR<(((R"R's5    7 .  #cCsg} |}x}|iƒD]o} | iƒ} t| ƒ|jo| i| ƒ|}qnx6|D]}|| joPq_q_W| i| ƒ|}qt i d|ƒ}|djo |}nd}|d}t|ƒ}t|idtƒƒ}g} d} xi|i| ƒD]X} | tdt| ƒdƒ|}t| ƒ}| }|djoI|oBt| ƒdjo/ti| dƒo| i| ƒ| |7} q |||jo | o| i|i | ƒ|ƒn||joG|djo:t!| |||dƒ}| i#|d ƒ|dg} n | g} |t| dƒ} |}q | i| ƒ| |7} q W| o| i|i | ƒƒqqW| S( Ns%s\s*s;,RRs iiiÿÿÿÿ($tlinesRctmaxlenRR R tlstripR2R trestlenRZtchtretcompiletcreteolRmtjoinlenR&R3R4twslentthistlinelenRtparttmaxtcurlentpartlent onfirstlinetfcretmatchRDRYtsubltextend(RRcRxR&RZRyR‰RR~RR‚R R€RuR}RvR…R|RmR†R„((R"RYsb          ! ;      c Csµd}t|ƒ}xj||jo\||dd?}|i|| tƒ}|i |ƒ}||jo |}q|d}qW|i|| t ƒ} |i||t ƒ}| |fS(Nii(tiR2RTtjtmRRURVRaRWtchunklenR$RQR\R]( RTRR$R‹RaRRŒRŽR]R\((R"R^Õs    (t__doc__RzRtemail.quopriMIMERtemail.base64MIMEt email.ErrorsR!t email.CharsetR+RlRRAR4RCR8R.ROR{tVERBOSEt IGNORECASERR‡RRkR#RR,R'RYR^(RCR,R+R!RARkRlROR.RRzR^RR8RRYR‡RR'R#R4((R"t?s.            9ÿ F