ó zfc@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/lib64/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/lib64/python2.7/mimify.pyR 8s   (t__name__t __module__t__doc__R R (((s/usr/lib64/python2.7/mimify.pyR/s t HeaderFilecBseZd„Zd„ZRS(cCs||_d|_dS(N(RRR(R R((s/usr/lib64/python2.7/mimify.pyR Hs cCsÂ|jdk r$|j}d|_n|jjƒ}|s=|Stj|ƒrP|Sxk|jjƒ|_t|jƒdks |jddkr¤|jddkr¤|S||j}d|_qSWdS(Nit s (RRRR thetmatchtlen(R R ((s/usr/lib64/python2.7/mimify.pyR Ls  & (RRR R (((s/usr/lib64/python2.7/mimify.pyRGs cCs†d}d}xktj||ƒ}|dkr1Pn||||jdƒ!tt|jdƒdƒƒ}|jdƒ}qW|||S(s6Decode a single line of quoted-printable text to 8bit.R iiiN(t mime_codetsearchRtstarttchrtinttgrouptend(R tnewlinetpostres((s/usr/lib64/python2.7/mimify.pyt mime_decode^s cCs›d}d}x€tj||ƒ}|dkr1Pn|jdƒ}dj|jdƒƒ}||||jdƒ!t|ƒ}|jdƒ}qW|||S(sDecode a header line to 8bit.R iiRt_N( t mime_headRRRtjointsplitRR R(R RRRR((s/usr/lib64/python2.7/mimify.pyRks $icCsGd}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| ƒrRPqRqRW|rx|so|rxd}nxÈ|jƒ} | s‘dStjtd| ƒ} |rÛ| t|ƒ |krÛ| t|ƒ} |} nd} x•|rx| |dkr|j | | ƒd}d} Pn| |d krt|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| r{|j | | ƒq{q{WdS( 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/lib64/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/lib64/python2.7/mimify.pyRÏs $ )s[=-ÿ]s[=?-ÿ]cCsg|rt}nt}d}d}t|ƒdkrb|d dkrbdtdƒjƒ}d}nxl|j||ƒ}|d kr‡Pn||||jdƒ!dt|jdƒƒjƒ}|j dƒ}qeW|||}d}xwt|ƒdkr^d }x2||d ks'||dd kr4|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/lib64/python2.7/mimify.pyt mime_encodeäs2 "   ' s<([ (]|^)([-a-zA-Z0-9_+]*[-ÿ][-a-zA-Z0-9_+-ÿ]*)(?=[ )]| )cCs”d}d}xytj||ƒ}|dkr1Pnd||||jdƒ!|jdƒtt|jdƒdƒf}|jdƒ}qW|||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/lib64/python2.7/mimify.pyRs "s^mime-version:s^content-transfer-encoding:s[-ÿ]cCs3d}}}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 |ƒqIWx;|jƒ}|sLPn|r‰||dkrl|} Pn||dkr‰|} Pq‰n|r¢| j |ƒq6n|rx]|ddkr|d }|jƒ}|ttƒ tkrú|ttƒ}n||}q«Wt|ƒ}n| j |ƒ| sItj|ƒrId} }qIn|s6t|ƒtkrmd}qmq6q6Wxø| D]ð}|r“t|ƒ}ntj|ƒ}|r | rô|j d ƒjƒd kr d |j dƒt|j d ƒf}q q d |j dd ƒ}n|r[tj|ƒr[d}|r;|d}q[|rN|d}q[|d}n|j|ƒqxW|sx|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”xB|jƒ}|shdS|r€t|dƒ}n|j|ƒqRWn||dkrét||ƒ}t||dƒ|j}|sÖPn|j|ƒq9nx?|jƒ}|sdS|rt|dƒ}n|j|ƒqìWq9WdS(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/lib64/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/lib64/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/lib64/python2.7/mimify.pyts„      U    ‡  4