Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/mimify.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@s�dZdZdZdZddlZddlZejded�dd	d
dgZej	dej
�Zej	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�$j'ddkr�dl(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�#Z0q�e.d-kr�Z0q�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/sys/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/sys/lib/python2.7/mimify.pyR8s			(t__name__t
__module__t__doc__R
R(((s/sys/lib/python2.7/mimify.pyR/s	t
HeaderFilecBseZd�Zd�ZRS(cCs||_d|_dS(N(RRR(R	R((s/sys/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/sys/lib/python2.7/mimify.pyRLs	&
(RRR
R(((s/sys/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.RiiiN(t	mime_codetsearchRtstarttchrtinttgrouptend(R
tnewlinetpostres((s/sys/lib/python2.7/mimify.pytmime_decode^scCs�d}d}xtj||�}|dkr1Pn|jd�}dj|jd��}||||jd�!t|�}|jd�}q|||S(sDecode a header line to 8bit.RiiRt_N(	t	mime_headRRRtjointsplitRR R(R
RRRR((s/sys/lib/python2.7/mimify.pyRks$icCsEd}d}d}d}|jr=|jd tkr=t}nd}t|�}x
|j�}	|	shdS|r�|	t|� |kr�|	t|�}	|}
nd}
t|	�}	tj|	�r�d}qRn|r�	j|	�r�}qRn|j
|
|	�|rtj|	�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�q��Pq�|	r�r�|	d
dkr�	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.iiRNis--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/sys/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.Ri�Nt,tw(ttypetopentostpathR$trenameR#RRR-tflush(	tinfiletoutfileR2R0R@tdtfR1R;((s/sys/lib/python2.7/mimify.pyR�s$)s[=-�[=?-�Csf|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�||S(
sZCode a single line as quoted-printable.
    If header is set, quote some extra characters.RiisFrom s=%02xtFiiKiIt=s=
N(
tmime_header_chart	mime_charRtordtupperRRRRR(R
theadertregRRRti((s/sys/lib/python2.7/mimify.pytmime_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.Ris%s%s%s=?%s?Q?%s?=iiN(tmime_headerRRRRtCHARSETRQR(R
RRR((s/sys/lib/python2.7/mimify.pyRs"s^mime-version:s^content-transfer-encoding:s[-�Cs/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|jd�}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�jd	�j�d
krd|jd�t|jd�f}qqd
|jdd�}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�j|
�|
}x�r*||dkr�xA|j�}|sfdS|r~t|d�}n|j|�qPn||dkr�||�}t||d�|j}|s�Pn|j|�q7nx>|j�}|s�S|rt|d�}n|j|�q�7WdS(s@Convert an 8bit part of a MIME mail message to quoted-printable.iRis--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(RQRtmimify_partR(R0R1tis_mimethas_ctetis_qpR5R3tmust_quote_bodytmust_quote_headert
has_iso_charsRNt
header_endtmessagetmessage_endR8R
R:Rt
chrset_resR;((s/sys/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.Ri�NR<R=i(R>R?R@RAR$RBR#RRR[RC(RDRER0R@RFRGR1R;((s/sys/lib/python2.7/mimify.pyR�s$)t__main__s/Usage: mimify [-l len] -[ed] [infile [outfile]]isl:edbs-eRs-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
OverflowErrortstdintstdouttencode_args(((s/sys/lib/python2.7/mimify.pyt<module>s�	
	
	U	 		�4		


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].