ó
čžbc           @   sí  d  Z  d Z d Z d Z d d l Z d d l Z e j d e d  d d	 d
 d g Z e j	 d e j
  Z e j	 d e j
  Z e j	 d e j
 e j B Z e j	 d e j
 e j B Z e j	 d  Z e j	 d e j
  Z e j	 d e j
  Z e j	 d e j
  Z d d0 d     YZ d d1 d     YZ d   Z d   Z d d  Z d d  Z e j	 d  Z e j	 d  Z d   Z e j	 d   Z d!   Z e j	 d" e j
  Z e j	 d# e j
  Z  e j	 d$  Z! d%   Z" d&   Z# d d l$ Z$ e% d' k se& e$ j'  d k rée$ j' d d k réd d l( Z( d( Z) d Z* e( j( e$ j' d) d*  \ Z+ Z, e& e,  d2 k r}e) GHe$ j- d)  n  d3 e+ k d4 e+ k k s­d5 e+ k rÂd6 e+ k rÂe) GHe$ j- d)  n  x e+ D] \ Z. Z/ e. d+ k ręe# Z0 qÉe. d- k r˙e Z0 qÉe. d/ k rJy e1 e/  Z Wq_e2 e3 f k
 rFe) GHe$ j- d)  q_XqÉe. d. k rÉd) Z* qÉqÉWe& e,  d k re$ j4 e$ j5 f Z6 n< e& e,  d) k r˛e, d e$ j5 f Z6 n e, d e, d) f Z6 e* rÜe6 e* f Z6 n  e0 e6   n  d S(7   sž  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 insteadi   t   mimifyt   unmimifyt   mime_encode_headert   mime_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: t   Filec           B   s    e  Z d  Z d   Z d   Z RS(   s{   A simple fake file object that knows about limited read-ahead and
    boundaries.  The only supported method is readline().c         C   s   | |  _  | |  _ d  |  _ d  S(   N(   t   filet   boundaryt   Nonet   peek(   t   selfR   R   (    (    s   /usr/lib/python2.7/mimify.pyt   __init__3   s    		c         C   s|   |  j  d  k	 r d S|  j j   } | s, | S|  j rx | |  j d k rU | |  _  d S| |  j d k rx | |  _  d Sn  | S(   Nt    s   
s   --
(   R   R   R   t   readlineR   (   R	   t   line(    (    s   /usr/lib/python2.7/mimify.pyR   8   s    			(   t   __name__t
   __module__t   __doc__R
   R   (    (    (    s   /usr/lib/python2.7/mimify.pyR   /   s   	t
   HeaderFilec           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  |  _ d  S(   N(   R   R   R   (   R	   R   (    (    s   /usr/lib/python2.7/mimify.pyR
   H   s    	c         C   sÂ   |  j  d  k	 r$ |  j  } d  |  _  n |  j j   } | s= | St j |  rP | Sxk |  j j   |  _  t |  j   d k s  |  j  d d k r¤ |  j  d d k r¤ | S| |  j  } d  |  _  qS Wd  S(   Ni    t    s   	(   R   R   R   R   t   het   matcht   len(   R	   R   (    (    s   /usr/lib/python2.7/mimify.pyR   L   s    	&(   R   R   R
   R   (    (    (    s   /usr/lib/python2.7/mimify.pyR   G   s   	c         C   s   d } d } xk t  j |  |  } | d k r1 Pn  | |  | | j d  !t t | j d  d   } | j d  } q W| |  | S(   s6   Decode a single line of quoted-printable text to 8bit.R   i    i   i   N(   t	   mime_codet   searchR   t   startt   chrt   intt   groupt   end(   R   t   newlinet   post   res(    (    s   /usr/lib/python2.7/mimify.pyt   mime_decode^   s    c         C   s   d } d } x t  j |  |  } | d k r1 Pn  | j d  } d j | j d   } | |  | | j d  !t |  } | j d  } q W| |  | S(   s   Decode a header line to 8bit.R   i    i   R   t   _N(	   t	   mime_headR   R   R   t   joint   splitR   R    R   (   R   R   R   R   R   (    (    s   /usr/lib/python2.7/mimify.pyR   k   s    $i    c         C   sG  d } d } d } d } |  j r= |  j d  t k r= t } n d } t |   } x| j   }	 |	 sh d S| r |	 t |   | k r |	 t |  }	 | }
 n d }
 t |	  }	 t j |	  rĘ d } qR n  | rë t	 j |	  rë d } qR n  | j
 |
 |	  | rt j |	  rd } n  t j |	  } | rFd | j d  } n  t j |	  rR PqR qR W| rx| so| rxd } n  xČ|  j   }	 |	 sd St j t d |	  }	 | rŰ|	 t |   | k rŰ|	 t |  }	 | }
 n d }
 x | rx|	 | d k r| j
 |
 |	  d } d }	 Pn  |	 | d	 k rt| j
 |
 |	  t |  |  } t | | |  | j }	 |	 säPqäqän  PqäW|	 rô| rôx] |	 d
 d k rä|	 d
  }	 |  j   } | t t   t k r×| t t  } n  |	 | }	 qWt |	  }	 n  |	 r%| r%|
 r%d d l } | j |	  }	 n  |	 r{| j
 |
 |	  q{q{Wd S(   s?   Convert a quoted-printable part of a MIME mail message to 8bit.i    i   R   Ni   s   --s   \1s   --
s   
iţ˙˙˙s   =
i˙˙˙˙(   R   R   t   QUOTER   R   R   R   t   qpR   t	   base64_ret   writet   replt   mpR   R   t   ret   subR"   R   t   unmimify_partR   R    t   base64t   decodestring(   t   ifilet   ofilet   decode_base64t	   multipartt   quoted_printablet	   is_base64t   is_replt   prefixt   hfileR   t   preft   mp_rest   nifileR   R.   (    (    s   /usr/lib/python2.7/mimify.pyR-   z   s    							
c   	      C   sř   t  |   t  d  k r t |   } t  |  t  d  k r |  | k r d d l } | j j |   \ } } | j |  | j j | d |   q n |  } t  |  t  d  k rĹ t | d  } n | } t | d  } t	 | | |  | j
   d S(   s>   Convert quoted-printable parts of a MIME mail message to 8bit.R   i˙˙˙˙Nt   ,t   w(   t   typet   opent   ost   pathR$   t   renameR#   R   R   R-   t   flush(	   t   infilet   outfileR2   R0   R@   t   dt   fR1   R;   (    (    s   /usr/lib/python2.7/mimify.pyR   Ď   s    $)s   [=-˙]s   [=?-˙]c         C   sg  | r t  } n t } d } d } t |   d k rb |  d  d k rb d t d  j   } d } n  xl | j |  |  } | d k r Pn  | |  | | j d  !d t | j d   j   } | j	 d  } qe W| |  | }  d } xw t |   d k r^d	 } x2 |  | d
 k s'|  | d d
 k r4| d } qW| d } | |  |  d } |  | }  qč W| |  S(   sZ   Code a single line as quoted-printable.
    If header is set, quote some extra characters.R   i    i   s   From s   =%02xt   Fi   iK   iI   t   =s   =
N(
   t   mime_header_chart	   mime_charR   t   ordt   upperR   R   R   R   R   (   R   t   headert   regR   R   R   t   i(    (    s   /usr/lib/python2.7/mimify.pyt   mime_encodeä   s2    	"	 '
s<   ([ 	(]|^)([-a-zA-Z0-9_+]*[-˙][-a-zA-Z0-9_+-˙]*)(?=[ 	)]|
)c         C   s   d } d } xy t  j |  |  } | d k r1 Pn  d | |  | | j d  !| j d  t t | j d  d  f } | j d  } q W| |  | S(   s.   Code a single header line as quoted-printable.R   i    s   %s%s%s=?%s?Q?%s?=i   i   N(   t   mime_headerR   R   R   R   t   CHARSETRQ   R   (   R   R   R   R   (    (    s   /usr/lib/python2.7/mimify.pyR     s    "s   ^mime-version:s   ^content-transfer-encoding:s   [-˙]c         C   s3  d } } } d } d } } }	 g  }
 d } g  } d } t |   } xę | j   } | s_ Pn  | r~ t j |  r~ d } n  t j |  r d } n  t j |  rŢ d } t j |  rĂ d } qŢ t	 j |  rŢ d } qŢ n  t
 j |  } | r	d | j d  } n  t j |  r"| } Pn  |
 j |  qI Wx;|  j   } | sLPn  | r| | d k rl| } Pn  | | d k r| } Pqn  | r˘| j |  q6n  | rx] | d d k r| d  } |  j   } | t t   t k rú| t t  } n  | | } qŤWt |  } n  | j |  |	 sIt j |  rId }	 } qIn  | s6t |  t k rmd } qmq6q6Wxř |
 D]đ } | rt |  } n  t j |  } | r|	 rô| j d	  j   d
 k r
d | j d  t | j d  f } q
qd | j d d  } n  | r[t j |  r[d } | r;| d } q[| rN| d } q[| d } n  | j |  qxW| sx| rĂ| rĂ| j d  | j d  |	 rł| j d t  qĂ| j d  n  | rŕ| rŕ| j d  n  | j |  x3 | D]+ } | rt | d  } n  | j |  qôW| j |  | } xö | r.| | d k rxB |  j   } | shd S| rt | d  } n  | j |  qRWn  | | d k rét |  |  } t | | d  | j } | sÖPn  | j |  q9n  x? |  j   } | sd S| rt | d  } n  | j |  qěWq9Wd S(   s@   Convert an 8bit part of a MIME mail message to quoted-printable.i    R   i   s   --s   --
s   
iţ˙˙˙s   =
i   s   us-asciis   %s%s%si   s   %sus-ascii%ss   Content-Transfer-Encoding: s   base64
s   quoted-printable
s   7bit
s   Mime-Version: 1.0
s   Content-Type: text/plain; s   charset="%s"
s   charset="us-ascii"
s,   Content-Transfer-Encoding: quoted-printable
N(   R   R   R   t   iso_charR   t   mvR   t   cteR&   R'   R*   R   R   t   appendR   R%   R    t   MAXLENR   t   chrsett   lowerRS   R(   RQ   R   t   mimify_partR   (   R0   R1   t   is_mimet   has_ctet   is_qpR5   R3   t   must_quote_bodyt   must_quote_headert   has_iso_charsRN   t
   header_endt   messaget   message_endR8   R   R:   R   t
   chrset_resR;   (    (    s   /usr/lib/python2.7/mimify.pyR[     sč    			
		c         C   sř   t  |   t  d  k r t |   } t  |  t  d  k r |  | k r d d l } | j j |   \ } } | j |  | j j | d |   q n |  } t  |  t  d  k rĹ t | d  } n | } t | d  } t	 | | d  | j
   d S(   s>   Convert 8bit parts of a MIME mail message to quoted-printable.R   i˙˙˙˙NR<   R=   i    (   R>   R?   R@   RA   R$   RB   R#   R   R   R[   RC   (   RD   RE   R0   R@   RF   RG   R1   R;   (    (    s   /usr/lib/python2.7/mimify.pyR      s    $)t   __main__s/   Usage: mimify [-l len] -[ed] [infile [outfile]]i   s   l:edbs   -eR   s   -ds   -bs   -l(    (    (   i    i   i   (   s   -eR   (   s   -dR   (   s   -bR   (   s   -dR   (7   R   RX   RS   R%   R+   t   warningst   warnt   DeprecationWarningt   __all__t   compilet   IR&   R'   t   SR*   RY   R   R   R"   R)   R   R   R    R   R-   R   RK   RJ   RQ   RR   R   RU   RV   RT   R[   R    t   sysR   R   t   argvt   getoptt   usageR2   t   optst   argst   exitt   ot   at   encodeR   t
   ValueErrort   OverflowErrort   stdint   stdoutt   encode_args(    (    (    s   /usr/lib/python2.7/mimify.pyt   <module>   s   	
		U	 			4		