Ñò
2mÈKc           @   s  d  Z  d Z d Z d Z d d k Z d d k Z e i d e d ƒ d d	 d
 d g Z e i	 d e i
 ƒ Z e i	 d e i
 ƒ Z e i	 d e i
 e i Bƒ Z e i	 d e i
 e i Bƒ Z e i	 d ƒ Z e i	 d e i
 ƒ Z e i	 d e i
 ƒ Z e i	 d e i
 ƒ Z d d0 d „  ƒ  YZ d d1 d „  ƒ  YZ d „  Z d „  Z d d „ Z d d „ Z e i	 d ƒ Z e i	 d ƒ Z d „  Z e i	 d  ƒ Z d! „  Z e i	 d" e i
 ƒ Z e i	 d# e i
 ƒ Z  e i	 d$ ƒ Z! d% „  Z" d& „  Z# d d k$ Z$ e% d' j p* e& e$ i' ƒ d j oõe$ i' d d j oád d k( Z( d( Z) d Z* e( i( e$ i' d) d* ƒ \ Z+ Z, e& e, ƒ d2 j o e) GHe$ i- d) ƒ n d3 e+ j d4 e+ j j p d5 e+ j o# d6 e+ j o e) GHe$ i- d) ƒ n x¨ e+ D]  \ Z. Z/ e. d+ j o
 e# Z0 qÒe. d- j o
 e Z0 qÒe. d/ j oB y e1 e/ ƒ Z Wqre2 e3 f j
 o e) GHe$ i- d) ƒ qrXqÒe. d. j o
 d) Z* qÒqÒWe& e, ƒ d j o e$ i4 e$ i5 f Z6 n? e& e, ƒ d) j o e, d e$ i5 f Z6 n e, d e, d) f Z6 e* o 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.6/mimify.pyt   __init__3   s    		c         C   s†   |  i  d  j	 o d S|  i i ƒ  } | p | S|  i oH | |  i d j o | |  _  d S| |  i d j o | |  _  d Sn | S(   Nt    s   
s   --
(   R   R   R   t   readlineR   (   R	   t   line(    (    s   /usr/lib/python2.6/mimify.pyR   8   s    
			(   t   __name__t
   __module__t   __doc__R
   R   (    (    (    s   /usr/lib/python2.6/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.6/mimify.pyR
   H   s    	c         C   sË   |  i  d  j	 o |  i  } d  |  _  n |  i i ƒ  } | p | St i | ƒ o | Sxn |  i i ƒ  |  _  t |  i  ƒ d j p( |  i  d d j o |  i  d d j o | S| |  i  } d  |  _  qY d  S(   Ni    t    s   	(   R   R   R   R   t   het   matcht   len(   R	   R   (    (    s   /usr/lib/python2.6/mimify.pyR   L   s    	((   R   R   R
   R   (    (    (    s   /usr/lib/python2.6/mimify.pyR   G   s   	c         C   s‡   d } d } xl t  i |  | ƒ } | d j o Pn | |  | | i d ƒ !t t | i d ƒ d ƒ ƒ } | i d ƒ } q | |  | 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.6/mimify.pyt   mime_decode^   s    c         C   sœ   d } d } x t  i |  | ƒ } | d j o Pn | i d ƒ } d i | i d ƒ ƒ } | |  | | i d ƒ !t | ƒ } | i d ƒ } q | |  | 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.6/mimify.pyR   k   s    $i    c      	   C   sw  d } d } d } d } |  i o |  i d  t j o
 t } n d } t |  ƒ } x| i ƒ  }	 |	 p d S| o1 |	 t | ƒ  | j o |	 t | ƒ }	 | }
 n d }
 t |	 ƒ }	 t i |	 ƒ o d } qU n | o t	 i |	 ƒ o d } qU n | i
 |
 |	 ƒ | o t i |	 ƒ o
 d } n t i |	 ƒ } | o d | i d ƒ } n t i |	 ƒ o PqU qU | o | p | o
 d } n xá|  i ƒ  }	 |	 p d St i t d |	 ƒ }	 | o1 |	 t | ƒ  | j o |	 t | ƒ }	 | }
 n d }
 x | o• |	 | d j o" | i
 |
 |	 ƒ d } d }	 Pn |	 | d	 j oL | i
 |
 |	 ƒ t |  | ƒ } t | | | ƒ | i }	 |	 p Pq q n Pq W|	 o{ | ot xa |	 d
 d j oO |	 d
  }	 |  i ƒ  } | t t ƒ  t j o | t t ƒ } n |	 | }	 q®Wt |	 ƒ }	 n |	 o. | o' |
 o d d k } | i |	 ƒ }	 n |	 o | i
 |
 |	 ƒ q’q’d 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.6/mimify.pyR-   z   s    




 	 
c   	      C   sÿ   t  |  ƒ t  d ƒ j o t |  ƒ } t  | ƒ t  d ƒ j oX |  | j oK d d k } | i i |  ƒ \ } } | i |  | i i | d | ƒ ƒ q  n |  } t  | ƒ t  d ƒ j o t | d ƒ } n | } t | d ƒ } t	 | | | ƒ | i
 ƒ  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.6/mimify.pyR   Ï   s    &+s   [=-ÿ]s   [=?-ÿ]c         C   sr  | o
 t  } n t } d } d } t |  ƒ d j o1 |  d  d j o  d t d ƒ i ƒ  } d } n xm | i |  | ƒ } | d j o Pn | |  | | i d ƒ !d t | i d ƒ ƒ i ƒ  } | i	 d ƒ } qj | |  | }  d } x| t |  ƒ d j oh d	 } x5 |  | d
 j p |  | d d
 j o | 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.6/mimify.pyt   mime_encodeä   s6    
$
   &
s<   ([ 	(]|^)([-a-zA-Z0-9_+]*[-ÿ][-a-zA-Z0-9_+-ÿ]*)(?=[ 	)]|
)c      	   C   s•   d } d } xz t  i |  | ƒ } | d j o Pn d | |  | | i d ƒ !| i d ƒ t t | i d ƒ d ƒ f } | i d ƒ } q | |  | 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.6/mimify.pyR     s    "s   ^mime-version:s   ^content-transfer-encoding:s   [-ÿ]c         C   s‚  d } } } d } d } } }	 g  }
 d } g  } d } t |  ƒ } xú | i ƒ  } | p Pn | o t i | ƒ o
 d } n t i | ƒ o
 d } n t i | ƒ o> d } t i | ƒ o
 d } që t	 i | ƒ o
 d } që n t
 i | ƒ } | o d | i d ƒ } n t i | ƒ o | } Pn |
 i | ƒ qI xR|  i ƒ  } | p Pn | o< | | d j o | } Pn | | d j o | } Pq¡n | o | i | ƒ qFn | ot xa | d d j oO | d  } |  i ƒ  } | t t ƒ  t j o | t t ƒ } n | | } qÆWt | ƒ } n | i | ƒ |	 p" t i | ƒ o d }	 } qmn | p! t | ƒ t j o
 d } q•qFqFx|
 D]ÿ } | o t | ƒ } n t i | ƒ } | oj |	 oI | i d	 ƒ i ƒ  d
 j o) d | i d ƒ t | i d ƒ f } q8q<d | i d d ƒ } n | oN t i | ƒ o> d } | o | d } q‘| o | d } q‘| d } n | i | ƒ qŸW| p | oO | oG | i d ƒ | i d ƒ |	 o | i d t ƒ qÿ| i d ƒ n | o | o | i d ƒ n | i | ƒ x5 | D]- } | o t | d ƒ } n | i | ƒ q3W| i | ƒ | } x| oü | | d j oI xF |  i ƒ  } | p d S| o t | d ƒ } n | i | ƒ q•n | | d j oH t |  | ƒ } t | | d ƒ | i } | p Pn | i | ƒ qzn xB |  i ƒ  } | p d S| o t | d ƒ } n | i | ƒ q7qz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.6/mimify.pyR[     sð    


	 
   	c         C   sÿ   t  |  ƒ t  d ƒ j o t |  ƒ } t  | ƒ t  d ƒ j oX |  | j oK d d k } | i i |  ƒ \ } } | i |  | i i | d | ƒ ƒ q  n |  } t  | ƒ t  d ƒ j o t | d ƒ } n | } t | d ƒ } t	 | | d ƒ | i
 ƒ  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.6/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.6/mimify.pyt   <module>   s†   	
		U	 		‡	7 

