ó ő^‚Rc @sídZdZdZdZddlZddlZejdedƒdd d d gZej d ej ƒZ ej d ej ƒZ ej dej ej BƒZej dej ej BƒZej dƒZej dej ƒZej dej ƒZej dej ƒZdd0d„ƒYZdd1d„ƒYZd„Zd„Zdd„Zdd„Zej dƒZej dƒZd„Zej d ƒZd!„Zej d"ej ƒZej d#ej ƒZ ej d$ƒZ!d%„Z"d&„Z#ddl$Z$e%d'kse&e$j'ƒdkrée$j'ddkréddl(Z(d(Z)dZ*e(j(e$j'd)d*ƒ\Z+Z,e&e,ƒd2kr}e)GHe$j-d)ƒnd3e+kd4e+kks­d5e+krÂd6e+krÂe)GHe$j-d)ƒnxže+D]–\Z.Z/e.d+kręe#Z0qÉe.d-kr˙eZ0qÉe.d/krJye1e/ƒZWq_e2e3fk rFe)GHe$j-d)ƒq_XqÉe.d.krÉd)Z*qÉqÉWe&e,ƒdkrŠe$j4e$j5fZ6n<e&e,ƒd)kr˛e,de$j5fZ6ne,de,d)fZ6e*rÜe6e*fZ6ne0e6ŒndS(7sžMimification and unmimification of mail messages. Decode quoted-printable parts of a mail message or encode using quoted-printable. Usage: mimify(input, output) unmimify(input, output, decode_base64 = 0) to encode and decode respectively. Input and output may be the name of a file or an open file object. Only a readline() method is used on the input file, only a write() method is used on the output file. When using file names, the input and output file names may be the same. Interactive usage: mimify.py -e [infile [outfile]] mimify.py -d [infile [outfile]] to encode and decode respectively. Infile defaults to standard input and outfile to standard output. iČs ISO-8859-1s> i˙˙˙˙Ns>the mimify module is deprecated; use the email package insteaditmimifytunmimifytmime_encode_headertmime_decode_headers.^content-transfer-encoding:\s*quoted-printables$^content-transfer-encoding:\s*base64s0^content-type:.*multipart/.*boundary="?([^;" ]*)s:^(content-type:.*charset=")(us-ascii|iso-8859-[0-9]+)(".*)s^-* s=([0-9a-f][0-9a-f])s=\?iso-8859-1\?q\?([^? ]+)\?=s^subject:\s+re: tFilecBs eZdZd„Zd„ZRS(s{A simple fake file object that knows about limited read-ahead and boundaries. The only supported method is readline().cCs||_||_d|_dS(N(tfiletboundarytNonetpeek(tselfRR((s/usr/lib/python2.7/mimify.pyt__init__3s  cCs||jdk rdS|jjƒ}|s,|S|jrx||jdkrU||_dS||jdkrx||_dSn|S(Nts s-- (RRRtreadlineR(R tline((s/usr/lib/python2.7/mimify.pyR 8s   (t__name__t __module__t__doc__R R (((s/usr/lib/python2.7/mimify.pyR/s t HeaderFilecBseZd„Zd„ZRS(cCs||_d|_dS(N(RRR(R R((s/usr/lib/python2.7/mimify.pyR Hs cCsÁ|jdk r$|j}d|_n|jjƒ}|s=|Stj|ƒrP|Sxj|jjƒ|_t|jƒdks |jddkr¤|jddkr¤|S||j}d|_qSdS(Nit s (RRRR thetmatchtlen(R R ((s/usr/lib/python2.7/mimify.pyR Ls  & (RRR R (((s/usr/lib/python2.7/mimify.pyRGs cCs…d}d}xjtj||ƒ}|dkr1Pn||||jdƒ!tt|jdƒdƒƒ}|jdƒ}q|||S(s6Decode a single line of quoted-printable text to 8bit.R iiiN(t mime_codetsearchRtstarttchrtinttgrouptend(R tnewlinetpostres((s/usr/lib/python2.7/mimify.pyt mime_decode^s cCsšd}d}xtj||ƒ}|dkr1Pn|jdƒ}dj|jdƒƒ}||||jdƒ!t|ƒ}|jdƒ}q|||S(sDecode a header line to 8bit.R iiRt_N( t mime_headRRRtjointsplitRR R(R RRRR((s/usr/lib/python2.7/mimify.pyRks $ic CsEd}d}d}d}|jr=|jd tkr=t}nd}t|ƒ}x |jƒ} | shdS|r| t|ƒ |kr| t|ƒ} |} nd} t| ƒ} tj| ƒrĘd}qRn|rët j| ƒrëd}qRn|j | | ƒ| rt j| ƒrd}nt j| ƒ} | rFd| j dƒ}ntj| ƒrRPqRqR|rw|sn|rwd}nxÇ|jƒ} | sdStjtd| ƒ} |rÚ| t|ƒ |krÚ| t|ƒ} |} nd} x•|rw| |dkr|j | | ƒd}d} Pn| |d krs|j | | ƒt||ƒ} t| ||ƒ| j} | săPqăqănPqăW| ró|róx]| d d kră| d } |jƒ} | ttƒ tkrÖ| ttƒ} n| | } q‡Wt| ƒ} n| r$|r$| r$d dl}|j| ƒ} n| rz|j | | ƒqzqzdS( s?Convert a quoted-printable part of a MIME mail message to 8bit.iiR Nis--s\1s-- s iţ˙˙˙s= i˙˙˙˙(RRtQUOTERR RRtqpRt base64_retwritetrepltmpRRtretsubR"Rt unmimify_partRR tbase64t decodestring(tifiletofilet decode_base64t multiparttquoted_printablet is_base64tis_repltprefixthfileR tpreftmp_restnifileRR.((s/usr/lib/python2.7/mimify.pyR-zsŒ               c Csřt|ƒtdƒkr•t|ƒ}t|ƒtdƒkr›||kr›ddl}|jj|ƒ\}}|j||jj|d|ƒƒq›n|}t|ƒtdƒkrĹt|dƒ}n|}t|dƒ}t |||ƒ|j ƒdS(s>Convert quoted-printable parts of a MIME mail message to 8bit.R i˙˙˙˙Nt,tw( ttypetopentostpathR$trenameR#RRR-tflush( tinfiletoutfileR2R0R@tdtfR1R;((s/usr/lib/python2.7/mimify.pyRĎs $ )s[=-˙]s[=?-˙]cCsf|rt}nt}d}d}t|ƒdkrb|d dkrbdtdƒjƒ}d}nxk|j||ƒ}|d kr‡Pn||||jdƒ!dt|jdƒƒjƒ}|j dƒ}qe|||}d}xwt|ƒdkr]d }x2||d ks&||dd kr3|d}qW|d}||| d }||}qçW||S( sZCode a single line as quoted-printable. If header is set, quote some extra characters.R iisFrom s=%02xtFiiKiIt=s= N( tmime_header_chart mime_charRtordtupperRRRRR(R theadertregRRRti((s/usr/lib/python2.7/mimify.pyt mime_encodeäs2 "   ' s<([ (]|^)([-a-zA-Z0-9_+]*[-˙][-a-zA-Z0-9_+-˙]*)(?=[ )]| )cCs“d}d}xxtj||ƒ}|dkr1Pnd||||jdƒ!|jdƒtt|jdƒdƒf}|jdƒ}q|||S(s.Code a single header line as quoted-printable.R is%s%s%s=?%s?Q?%s?=iiN(t mime_headerRRRRtCHARSETRQR(R RRR((s/usr/lib/python2.7/mimify.pyRs "s^mime-version:s^content-transfer-encoding:s[-˙]cCs/d}}}d}d}}} g} d} g} d} t|ƒ}xé|jƒ}|s_Pn| r~tj|ƒr~d}ntj|ƒr–d}ntj|ƒrŢd}tj|ƒrĂd}qŢt j|ƒrŢd}qŢnt j|ƒ}|r d|j dƒ}nt j|ƒr"|} Pn| j |ƒqIx:|jƒ}|sKPn|rˆ||dkrk|} Pn||dkrˆ|} Pqˆn|rĄ| j |ƒq5n|rx]|ddkr|d }|jƒ}|ttƒ tkrů|ttƒ}n||}qŞWt|ƒ}n| j |ƒ| sHtj|ƒrHd} }qHn|s5t|ƒtkrld}qlq5q5xř| D]đ}|r‘t|ƒ}ntj|ƒ}|r | rň|j d ƒjƒd krd |j dƒt|j d ƒf}qq d |j dd ƒ}n|rYtj|ƒrYd}|r9|d}qY|rL|d}qY|d}n|j|ƒqvW|sv|rÁ| rÁ|jdƒ|jdƒ| rą|jdtƒqÁ|jdƒn|rŢ| rŢ|jdƒn|j| ƒx3| D]+}|rt|dƒ}n|j|ƒqňW|j| ƒ| }xô|r*||dkr‘xA|jƒ}|sfdS|r~t|dƒ}n|j|ƒqPn||dkrćt||ƒ}t||dƒ|j}|sÓPn|j|ƒq7nx>|jƒ}|s˙dS|rt|dƒ}n|j|ƒqéq7WdS(s@Convert an 8bit part of a MIME mail message to quoted-printable.iR is--s-- s iţ˙˙˙s= isus-asciis%s%s%sis %sus-ascii%ssContent-Transfer-Encoding: sbase64 squoted-printable s7bit sMime-Version: 1.0 sContent-Type: text/plain; s charset="%s" scharset="us-ascii" s,Content-Transfer-Encoding: quoted-printable N(RRR tiso_charRtmvRtcteR&R'R*RRtappendRR%R tMAXLENRtchrsettlowerRSR(RQRt mimify_partR(R0R1tis_mimethas_ctetis_qpR5R3tmust_quote_bodytmust_quote_headert has_iso_charsRNt header_endtmessaget message_endR8R R:Rt chrset_resR;((s/usr/lib/python2.7/mimify.pyR[sč                          cCsřt|ƒtdƒkr•t|ƒ}t|ƒtdƒkr›||kr›ddl}|jj|ƒ\}}|j||jj|d|ƒƒq›n|}t|ƒtdƒkrĹt|dƒ}n|}t|dƒ}t ||dƒ|j ƒdS(s>Convert 8bit parts of a MIME mail message to quoted-printable.R i˙˙˙˙NR<R=i( R>R?R@RAR$RBR#RRR[RC(RDRER0R@RFRGR1R;((s/usr/lib/python2.7/mimify.pyRŸs $ )t__main__s/Usage: mimify [-l len] -[ed] [infile [outfile]]isl:edbs-eR s-ds-bs-l(((iii(s-eR (s-dR (s-bR (s-dR (7RRXRSR%R+twarningstwarntDeprecationWarningt__all__tcompiletIR&R'tSR*RYRRR"R)RRR RR-RRKRJRQRRRRURVRTR[RtsysRRtargvtgetopttusageR2toptstargstexittotatencodeRt ValueErrort OverflowErrortstdintstdoutt encode_args(((s/usr/lib/python2.7/mimify.pyts„      U    ‡  4