ó
è¾bc           @   s|  d  Z  d d l m Z e d d d ƒ[ d Z d Z d Z d	 Z d d
 l Z d d
 l Z d d
 l	 Z	 d d
 l
 Z
 d d
 l Z d d
 l Z d d l m Z d d d d g Z d e f d „  ƒ  YZ d f  d „  ƒ  YZ e	 j d ƒ Z d „  Z d f  d „  ƒ  YZ d e
 j f d „  ƒ  YZ d e f d „  ƒ  YZ d f  d „  ƒ  YZ d d „ Z d d „ Z d „  Z e d k rxe ƒ  n  d
 S(   sŸ	  MH interface -- purely object-oriented (well, almost)

Executive summary:

import mhlib

mh = mhlib.MH()         # use default mailbox directory and profile
mh = mhlib.MH(mailbox)  # override mailbox location (default from profile)
mh = mhlib.MH(mailbox, profile) # override mailbox and profile

mh.error(format, ...)   # print error message -- can be overridden
s = mh.getprofile(key)  # profile entry (None if not set)
path = mh.getpath()     # mailbox pathname
name = mh.getcontext()  # name of current folder
mh.setcontext(name)     # set name of current folder

list = mh.listfolders() # names of top-level folders
list = mh.listallfolders() # names of all folders, including subfolders
list = mh.listsubfolders(name) # direct subfolders of given folder
list = mh.listallsubfolders(name) # all subfolders of given folder

mh.makefolder(name)     # create new folder
mh.deletefolder(name)   # delete folder -- must have no subfolders

f = mh.openfolder(name) # new open folder object

f.error(format, ...)    # same as mh.error(format, ...)
path = f.getfullname()  # folder's full pathname
path = f.getsequencesfilename() # full pathname of folder's sequences file
path = f.getmessagefilename(n)  # full pathname of message n in folder

list = f.listmessages() # list of messages in folder (as numbers)
n = f.getcurrent()      # get current message
f.setcurrent(n)         # set current message
list = f.parsesequence(seq)     # parse msgs syntax into list of messages
n = f.getlast()         # get last message (0 if no messagse)
f.setlast(n)            # set last message (internal use only)

dict = f.getsequences() # dictionary of sequences in folder {name: list}
f.putsequences(dict)    # write sequences back to folder

f.createmessage(n, fp)  # add message from file f as number n
f.removemessages(list)  # remove messages in list from folder
f.refilemessages(list, tofolder) # move messages in list to other folder
f.movemessage(n, tofolder, ton)  # move one message to a given destination
f.copymessage(n, tofolder, ton)  # copy one message to a given destination

m = f.openmessage(n)    # new open message object (costs a file descriptor)
m is a derived class of mimetools.Message(rfc822.Message), with:
s = m.getheadertext()   # text of message's headers
s = m.getheadertext(pred) # text of message's headers, filtered by pred
s = m.getbodytext()     # text of message's body, decoded
s = m.getbodytext(0)    # text of message's body, not decoded
iÿÿÿÿ(   t   warnpy3ksO   the mhlib module has been removed in Python 3.0; use the mailbox module insteadt
   stackleveli   s   ~/.mh_profiles   ~/Mails   .mh_sequencesiÀ  N(   t   bisectt   MHt   Errort   Foldert   Messagec           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.7/mhlib.pyR   [   s   c           B   s’   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   s<  Class representing a particular collection of folders.
    Optional constructor arguments are the pathname for the directory
    containing the collection, and the MH profile to use.
    If either is omitted or empty a default is used; the default
    directory is taken from the MH profile if it is specified there.c         C   sÏ   | d k r t } n  t j j | ƒ |  _ | d k rH |  j d ƒ } n  | sW t } n  t j j | ƒ r’ | d d k r’ t j j	 d | ƒ } n  t j j | ƒ } t j j
 | ƒ sÂ t d ‚ n  | |  _ d S(   s   Constructor.t   Pathi    t   ~s   MH() path not foundN(   t   Nonet
   MH_PROFILEt   ost   patht
   expandusert   profilet
   getprofilet   PATHt   isabst   joint   isdirR   (   t   selfR   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   __init__f   s     	  	# c         C   s   d |  j  |  j f S(   s   String representation.s
   MH(%r, %r)(   R   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   __repr__r   s    c         G   s   t  j j d | | ƒ d S(   sA   Routine to print an error.  May be overridden by a derived class.s   MH error: %s
N(   t   syst   stderrt   write(   R   t   msgt   args(    (    s   /usr/lib/python2.7/mhlib.pyt   errorv   s    c         C   s   t  |  j | ƒ S(   s*   Return a profile entry, None if not found.(   t   picklineR   (   R   t   key(    (    s   /usr/lib/python2.7/mhlib.pyR   z   s    c         C   s   |  j  S(   s9   Return the path (the name of the collection's directory).(   R   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   getpath~   s    c         C   s7   t  t j j |  j ƒ  d ƒ d ƒ } | s3 d } n  | S(   s&   Return the name of the current folder.t   contexts   Current-Foldert   inbox(   R   R   R   R   R!   (   R   R"   (    (    s   /usr/lib/python2.7/mhlib.pyt
   getcontext‚   s
    	 	c         C   sI   t  j j |  j ƒ  d ƒ } t | d ƒ } | j d | ƒ | j ƒ  d S(   s#   Set the name of the current folder.R"   t   ws   Current-Folder: %s
N(   R   R   R   R!   t   openR   t   close(   R   R"   t   fnt   f(    (    s   /usr/lib/python2.7/mhlib.pyt
   setcontext‰   s    c         C   sq   g  } |  j  ƒ  } xN t j | ƒ D]= } t j j | | ƒ } t j j | ƒ r" | j | ƒ q" q" W| j ƒ  | S(   s*   Return the names of the top-level folders.(   R!   R   t   listdirR   R   R   t   appendt   sort(   R   t   foldersR   t   namet   fullname(    (    s   /usr/lib/python2.7/mhlib.pyt   listfolders   s    
c   	      C   sÔ   t  j j |  j | ƒ } t  j | ƒ j } | d k r: g  Sg  } t  j | ƒ } xt | D]l } t  j j | | ƒ } t  j j | ƒ rV t  j j | | ƒ } | j | ƒ | d } | d k rÂ PqÂ qV qV W| j ƒ  | S(   sc   Return the names of the subfolders in a given folder
        (prefixed with the given folder name).i   i   (	   R   R   R   t   statt   st_nlinkR+   R   R,   R-   (	   R   R/   R0   t   nlinkst
   subfolderst   subnamest   subnamet   fullsubnamet   name_subname(    (    s   /usr/lib/python2.7/mhlib.pyt   listsubfolders›   s     

c         C   s   |  j  d ƒ S(   s<   Return the names of all folders and subfolders, recursively.t    (   t   listallsubfolders(   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   listallfolders³   s    c   
      C   s$  t  j j |  j | ƒ } t  j | ƒ j } | d k r: g  Sg  } t  j | ƒ } xÄ | D]¼ } | d d k sV t | ƒ r~ qV n  t  j j | | ƒ } t  j j | ƒ rV t  j j | | ƒ } | j | ƒ t  j j	 | ƒ sõ |  j
 | ƒ }	 | |	 } n  | d } | d k rPqqV qV W| j ƒ  | S(   s>   Return the names of subfolders in a given folder, recursively.i   i    t   ,i   (   R   R   R   R2   R3   R+   t	   isnumericR   R,   t   islinkR<   R-   (
   R   R/   R0   R4   R5   R6   R7   R8   R9   t   subsubfolders(    (    s   /usr/lib/python2.7/mhlib.pyR<   ·   s,     	

c         C   s   t  |  | ƒ S(   s0   Return a new Folder object for the named folder.(   R   (   R   R/   (    (    s   /usr/lib/python2.7/mhlib.pyt
   openfolderÓ   s    c         C   se   t  |  j d ƒ } | r6 t | ƒ r6 t | d ƒ } n t } t j t j j |  j	 ƒ  | ƒ | ƒ d S(   s@   Create a new folder (or raise os.error if it cannot be created).s   Folder-Protecti   N(
   R   R   R?   t   intt   FOLDER_PROTECTR   t   mkdirR   R   R!   (   R   R/   t   protectt   mode(    (    s   /usr/lib/python2.7/mhlib.pyt
   makefolder×   s
    c         C   s”   t  j j |  j ƒ  | ƒ } xe t  j | ƒ D]T } t  j j | | ƒ } y t  j | ƒ Wq+ t  j k
 r~ |  j d | ƒ q+ Xq+ Wt  j | ƒ d S(   s‡   Delete a folder.  This removes files in the folder but not
        subdirectories.  Raise os.error if deleting the folder itself fails.s   %s not deleted, continuing...N(   R   R   R   R!   R+   t   unlinkR   t   rmdir(   R   R/   R0   R7   R8   (    (    s   /usr/lib/python2.7/mhlib.pyt   deletefolderà   s    	N(   R   R   t   __doc__R   R   R   R   R   R!   R$   R*   R1   R:   R=   R<   RB   RH   RK   (    (    (    s   /usr/lib/python2.7/mhlib.pyR   _   s   													s   ^[1-9][0-9]*$c         C   s   t  j |  ƒ d  k	 S(   N(   t   numericprogt   matchR   (   t   str(    (    s   /usr/lib/python2.7/mhlib.pyR?   ï   s    c           B   sò   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s'   Class representing a particular folder.c         C   s>   | |  _  | |  _ t j j |  j ƒ  ƒ s: t d | ‚ n  d S(   s   Constructor.s   no folder %sN(   t   mhR/   R   R   R   t   getfullnameR   (   R   RP   R/   (    (    s   /usr/lib/python2.7/mhlib.pyR   õ   s    		c         C   s   d |  j  |  j f S(   s   String representation.s   Folder(%r, %r)(   RP   R/   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR   ü   s    c         G   s   |  j  j | Œ  d S(   s   Error message handler.N(   RP   R   (   R   R   (    (    s   /usr/lib/python2.7/mhlib.pyR      s    c         C   s   t  j j |  j j |  j ƒ S(   s'   Return the full pathname of the folder.(   R   R   R   RP   R/   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyRQ     s    c         C   s   t  j j |  j ƒ  t ƒ S(   s8   Return the full pathname of the folder's sequences file.(   R   R   R   RQ   t   MH_SEQUENCES(   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   getsequencesfilename  s    c         C   s   t  j j |  j ƒ  t | ƒ ƒ S(   s4   Return the full pathname of a message in the folder.(   R   R   R   RQ   RO   (   R   t   n(    (    s   /usr/lib/python2.7/mhlib.pyt   getmessagefilename  s    c         C   s   |  j  j |  j ƒ S(   s!   Return list of direct subfolders.(   RP   R:   R/   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR:     s    c         C   s   |  j  j |  j ƒ S(   s   Return list of all subfolders.(   RP   R<   R/   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR<     s    c         C   s   g  } t  j } | j } x6 t j |  j ƒ  ƒ D] } | | ƒ r. | | ƒ q. q. Wt t | ƒ } | j ƒ  | r€ | d |  _	 n	 d |  _	 | S(   s€   Return the list of messages currently present in the folder.
        As a side effect, set self.last to the last message (or 0).iÿÿÿÿi    (
   RM   RN   R,   R   R+   RQ   t   mapRC   R-   t   last(   R   t   messagesRN   R,   R/   (    (    s   /usr/lib/python2.7/mhlib.pyt   listmessages  s    		
	c         C   sÕ   i  } |  j  ƒ  } y t | d ƒ } Wn t k
 r9 | SXx” | j ƒ  } | sS Pn  | j d ƒ } t | ƒ d k r” |  j d | | j ƒ  f ƒ n  | d j ƒ  } t | d j ƒ  d ƒ j	 ƒ  } | | | <q= W| S(   s+   Return the set of sequences for the folder.t   rt   :i   s   bad sequence in %s: %si    i   t    (
   RS   R&   t   IOErrort   readlinet   splitt   lenR   t   stript   IntSett   tolist(   R   t	   sequencesR0   R)   t   linet   fieldsR    t   value(    (    s   /usr/lib/python2.7/mhlib.pyt   getsequences)  s$     	c         C   s¿   |  j  ƒ  } d } xk | j ƒ  D]] \ } } t d d ƒ } | j | ƒ | s_ t | d ƒ } n  | j d | | j ƒ  f ƒ q W| s± y t j	 | ƒ Wq» t j
 k
 r­ q» Xn
 | j ƒ  d S(   s.   Write the set of sequences back to the folder.R;   R\   R%   s   %s: %s
N(   RS   R   t	   iteritemsRb   t   fromlistR&   R   t   tostringR   RI   R   R'   (   R   Rd   R0   R)   R    t   seqt   s(    (    s   /usr/lib/python2.7/mhlib.pyt   putsequences=  s     !c         C   sE   |  j  ƒ  } y t | d ƒ SWn  t t f k
 r@ t d ‚ n Xd S(   s<   Return the current message.  Raise Error when there is none.t   curs   no cur messageN(   Rh   t   maxt
   ValueErrort   KeyErrorR   (   R   t   seqs(    (    s   /usr/lib/python2.7/mhlib.pyt
   getcurrentN  s
    c         C   s#   t  |  j ƒ  d t | ƒ d ƒ d S(   s   Set the current message.Ro   i    N(   t
   updatelineRS   RO   (   R   RT   (    (    s   /usr/lib/python2.7/mhlib.pyt
   setcurrentV  s    c         C   sL  |  j  ƒ  } | s% t d |  j ‚ n  | d k r5 | S| j d ƒ } | d k r| |  d | | d } } } | d  d k r˜ | d  | d } } n  t | ƒ s´ t d | ‚ n  y t | ƒ } Wn# t t f k
 ré t | ƒ } n Xy |  j	 | | ƒ } Wn” t k
 r–}	 |  j
 ƒ  }
 | |
 k rV|	 s=d | }	 n  t |	 t j ƒ  d	 ‚ n  |
 | } | svt d
 | ‚ n  | d k r‹| | S| |  SqX| sµ| d k rµd } qµn  | d k rèt | | ƒ } | t d | | ƒ | !St | | d ƒ } | | | | !Sn  | j d ƒ } | d k r¡|  j	 | |  | ƒ } |  j	 | | d | ƒ } t | | d ƒ } t | | ƒ } | | | !} | st d | ‚ n  | Sy |  j	 | | ƒ } WnO t k
 r}	 |  j
 ƒ  }
 | |
 k r |	 sôd | }	 n  t |	 ‚ n  |
 | SX| | k rAt | ƒ r1t d | ‚ qHt d | ‚ n | g Sd S(   sä   Parse an MH sequence specification into a message list.
        Attempt to mimic mh-sequence(5) as close as possible.
        Also attempt to mimic observed behavior regarding which
        conditions cause which error messages.s   no messages in %st   allR[   i    R;   i   s   -+s   bad message list %si   s   sequence %s emptyt   -t   prevRW   s   message %d doesn't exists   no %s messageN(   Ry   RW   (   RY   R   R/   t   findR?   RC   Rq   t   OverflowErrorR`   t   _parseindexRh   R   t   exc_infoR   Rp   (   R   Rl   Rw   t   it   headt   dirt   tailt   countt   anchorR   Rs   t   msgst   begint   endt   jRZ   RT   (    (    s   /usr/lib/python2.7/mhlib.pyt   parsesequenceZ  s|    	 
		c         C   sL  t  | ƒ r; y t | ƒ SWq; t t f k
 r7 t j SXn  | d k rQ |  j ƒ  S| d k re | d S| d k ry | d S| d k rÌ |  j ƒ  } t | | ƒ } y | | SWqÌ t k
 rÈ t	 d ‚ qÌ Xn  | d	 k r?|  j ƒ  } t | | d
 ƒ } | d k rt	 d ‚ n  y | | d
 SWq?t k
 r;t	 d ‚ q?Xn  t	 d ‚ d S(   s7   Internal: parse a message number (or cur, first, etc.).Ro   t   .t   firsti    RW   iÿÿÿÿt   nexts   no next messageRy   i   s   no prev messageN(   Ro   R‰   (   R?   RC   R{   Rq   R   t   maxintRt   R   t
   IndexErrorR   R   (   R   Rl   Rw   RT   R~   (    (    s   /usr/lib/python2.7/mhlib.pyR|   ®  s8    
c         C   s   t  |  | ƒ S(   s+   Open a message -- returns a Message object.(   R   (   R   RT   (    (    s   /usr/lib/python2.7/mhlib.pyt   openmessageÍ  s    c         C   s  g  } g  } x¥ | D] } |  j  | ƒ } |  j  d t | ƒ ƒ } y t j | ƒ Wn t j k
 rh n Xy t j | | ƒ Wn# t j k
 r¢ } | j | ƒ q X| j | ƒ q W| rÊ |  j | ƒ n  | r
t | ƒ d k rõ t j | d ‚ q
t j d | f ‚ n  d S(   s2   Remove one or more messages -- may raise os.error.R>   i   i    s   multiple errors:N(	   RU   RO   R   RI   R   t   renameR,   t   removefromallsequencesR`   (   R   t   listt   errorst   deletedRT   R   t	   commapathR   (    (    s   /usr/lib/python2.7/mhlib.pyt   removemessagesÑ  s(    i    c         C   s„  g  } i  } xö | D]î } | j  ƒ  d } |  j | ƒ } | j | ƒ }	 y t j | |	 ƒ WnŒ t j k
 ré y! t j | |	 ƒ t j | ƒ Wqê t t j f k
 rå }
 | j	 |
 ƒ y t j |	 ƒ Wq t j k
 rÞ q Xq qê Xn X| j
 | ƒ | | | <q W| r@| r*| j |  | j ƒ  ƒ n  |  j | j ƒ  ƒ n  | r€t | ƒ d k rkt j | d ‚ q€t j d | f ‚ n  d S(   s_   Refile one or more messages -- may raise os.error.
        'tofolder' is an open folder object.i   i    s   multiple errors:N(   t   getlastRU   R   R   R   t   shutilt   copy2RI   R]   R,   t   setlastt   _copysequencest   itemsR   t   keysR`   (   R   R‘   t   tofoldert   keepsequencesR’   t   refiledRT   t   tonR   t   topathR   (    (    s   /usr/lib/python2.7/mhlib.pyt   refilemessagesê  s:    c         C   sÛ   | j  ƒ  } |  j  ƒ  } d } x  | j ƒ  D]’ \ } } y | | } d }	 Wn t k
 rj g  } d }	 n Xx6 | D]. \ }
 } |
 | k rr | j | ƒ d } qr qr W|	 r+ | r+ | | | <q+ q+ W| r× |  j | ƒ n  d S(   s.   Helper for refilemessages() to copy sequences.i    i   N(   Rh   R›   Rr   R,   Rn   (   R   t
   fromfoldert   refileditemst   fromsequencest   tosequencest   changedR/   Rl   t   toseqt   newt   fromnR    (    (    s   /usr/lib/python2.7/mhlib.pyRš     s$    


c   	      C   s#  |  j  | ƒ } t | ƒ } | j ƒ  ~ | j  | ƒ } | j  d | ƒ } y t j | | ƒ Wn t j k
 rt n Xy t j | | ƒ Wnƒ t j k
 rd } z' | j d ƒ t j	 | | ƒ d } Wd | sý y t j
 | ƒ Wqý t j k
 rù qý Xn  Xt j
 | ƒ n X|  j | g ƒ d S(   sa   Move one message over a specific destination message,
        which may or may not already exist.s   ,%di    i   N(   RU   R&   R'   R   R   R   R™   R   R—   R˜   RI   R   (	   R   RT   R   R    R   R)   R¡   t   backuptopatht   ok(    (    s   /usr/lib/python2.7/mhlib.pyt   movemessage"  s2    

c   	      C   sÛ   |  j  | ƒ } t | ƒ } | j ƒ  ~ | j  | ƒ } | j  d | ƒ } y t j | | ƒ Wn t j k
 rt n Xd } z' | j d ƒ t j	 | | ƒ d } Wd | sÖ y t j
 | ƒ WqÖ t j k
 rÒ qÖ Xn  Xd S(   sa   Copy one message over a specific destination message,
        which may or may not already exist.s   ,%di    i   N(   RU   R&   R'   R   R   R   R™   R   R—   R˜   RI   (	   R   RT   R   R    R   R)   R¡   R«   R¬   (    (    s   /usr/lib/python2.7/mhlib.pyt   copymessageB  s(    

c   	      C   sâ   |  j  | ƒ } |  j  d | ƒ } y t j | | ƒ Wn t j k
 rL n Xd } d } zP t | d ƒ } x* | j | ƒ } | s‡ Pn  | j | ƒ qn W| j ƒ  d } Wd | sÝ y t j | ƒ WqÝ t j k
 rÙ qÝ Xn  Xd S(	   s3   Create a message, with text from the open file txt.s   ,%di    i   i   R%   i   Ni @  (	   RU   R   R   R   R&   t   readR   R'   RI   (	   R   RT   t   txtR   t
   backuppathR¬   t   BUFSIZER)   t   buf(    (    s   /usr/lib/python2.7/mhlib.pyt   createmessage\  s,    

c         C   sÅ   t  |  d ƒ r' |  j | k r' |  ` n  |  j ƒ  } d } xo | j ƒ  D]a \ } } | d k rd qF n  x@ | D]8 } | | k rk | j | ƒ d } | s£ | | =q£ qk qk WqF W| rÁ |  j | ƒ n  d S(   s`   Remove one or more messages from all sequences (including last)
        -- but not from 'cur'!!!RW   i    Ro   i   N(   t   hasattrRW   Rh   R›   t   removeRn   (   R   R‘   Rd   R§   R/   Rl   RT   (    (    s   /usr/lib/python2.7/mhlib.pyR   v  s    	c         C   s#   t  |  d ƒ s |  j ƒ  n  |  j S(   s   Return the last message number.RW   (   Rµ   RY   RW   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR–   ‰  s    c         C   s4   | d k r' t |  d ƒ r0 |  ` q0 n	 | |  _ d S(   s   Set the last message number.RW   N(   R   Rµ   RW   (   R   RW   (    (    s   /usr/lib/python2.7/mhlib.pyR™     s    (   R   R   RL   R   R   R   RQ   RS   RU   R:   R<   RY   Rh   Rn   Rt   Rv   Rˆ   R|   RŽ   R•   R¢   Rš   R­   R®   R´   R   R–   R™   (    (    (    s   /usr/lib/python2.7/mhlib.pyR   ò   s4   														T			#		 				c           B   sG   e  Z d d  „ Z d „  Z d d „ Z d d „ Z d „  Z d „  Z RS(   c         C   sV   | |  _  | |  _ | d k r? | j | ƒ } t | d ƒ } n  t j j |  | ƒ d S(   s   Constructor.RZ   N(   t   foldert   numberR   RU   R&   t	   mimetoolsR   R   (   R   R)   RT   t   fpR   (    (    s   /usr/lib/python2.7/mhlib.pyR   ™  s    		c         C   s   d t  |  j ƒ |  j f S(   s   String representation.s   Message(%s, %s)(   t   reprR·   R¸   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR   ¢  s    c         C   s¦   | d k r d j |  j ƒ Sg  } d } xn |  j D]c } | d j ƒ  s | j d ƒ } | d k r | | |  j ƒ  ƒ } q n  | r2 | j | ƒ q2 q2 Wd j | ƒ S(   sá   Return the message's header text as a string.  If an
        argument is specified, it is used as a filter predicate to
        decide which headers to return (its argument is the header
        name converted to lower case).R;   i    R[   N(   R   R   t   headerst   isspaceRz   t   lowerR,   (   R   t   predR¼   t   hitRe   R~   (    (    s   /usr/lib/python2.7/mhlib.pyt   getheadertext¦  s     i   c         C   s    |  j  j |  j ƒ |  j ƒ  } | s2 | d k r? |  j  j ƒ  Sy d d l m } Wn! t k
 rv d d l m } n X| ƒ  } t j	 |  j  | | ƒ | j
 ƒ  S(   sß   Return the message's body text as string.  This undoes a
        Content-Transfer-Encoding, but does not interpret other MIME
        features (e.g. multipart messages).  To suppress decoding,
        pass 0 as an argument.R;   t   7bitt   8bitt   binaryiÿÿÿÿ(   t   StringIO(   R;   RÂ   RÃ   RÄ   (   Rº   t   seekt   startofbodyt   getencodingR¯   t	   cStringIORÅ   t   ImportErrorR¹   t   decodet   getvalue(   R   RË   t   encodingRÅ   t   output(    (    s   /usr/lib/python2.7/mhlib.pyt   getbodytext·  s    	c         C   s×   |  j  ƒ  d k r t d ‚ n  |  j d ƒ } | s? t d ‚ n  |  j j |  j ƒ t j |  j ƒ } | j | ƒ g  } xO | j	 ƒ  rÈ d |  j
 d t | ƒ f } t |  j | | ƒ } | j | ƒ qz W| j ƒ  | S(   s¥   Only for multipart messages: return the message's body as a
        list of SubMessage objects.  Each submessage object behaves
        (almost) as a Message object.t	   multiparts   Content-Type is not multipart/*t   boundarys"   multipart/* without boundary params   %s.%ri   (   t   getmaintypeR   t   getparamRº   RÆ   RÇ   t	   multifilet	   MultiFilet   pushR‹   R¸   R`   t
   SubMessageR·   R,   t   pop(   R   t   bdryt   mft   partsRT   t   part(    (    s   /usr/lib/python2.7/mhlib.pyt   getbodypartsÈ  s    
c         C   s*   |  j  ƒ  d k r |  j ƒ  S|  j ƒ  Sd S(   s3   Return body, either a string or a list of messages.RÐ   N(   RÒ   RÝ   RÏ   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   getbodyÜ  s    
N(	   R   R   R   R   R   RÁ   RÏ   RÝ   RÞ   (    (    (    s   /usr/lib/python2.7/mhlib.pyR   —  s   			R×   c           B   s8   e  Z d  „  Z d „  Z d d „ Z d „  Z d „  Z RS(   c         C   sk   t  j |  | | | ƒ |  j ƒ  d k r= t  j |  ƒ |  _ n t  j |  ƒ |  _ t  j |  d d ƒ|  _ d S(   s   Constructor.RÐ   RË   i    N(   R   R   RÒ   RÝ   t   bodyRÏ   t   bodyencoded(   R   R)   RT   Rº   (    (    s   /usr/lib/python2.7/mhlib.pyR   æ  s
    c         C   s.   |  j  |  j |  j } } } d | | | f S(   s   String representation.s   SubMessage(%s, %s, %s)(   R·   R¸   Rº   (   R   R)   RT   Rº   (    (    s   /usr/lib/python2.7/mhlib.pyR   ð  s    i   c         C   s3   | s |  j  St |  j ƒ t d ƒ k r/ |  j Sd  S(   NR;   (   Rà   t   typeRß   (   R   RË   (    (    s   /usr/lib/python2.7/mhlib.pyRÏ   õ  s    c         C   s&   t  |  j ƒ t  g  ƒ k r" |  j Sd  S(   N(   Rá   Rß   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyRÝ   û  s    c         C   s   |  j  S(   N(   Rß   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyRÞ   ÿ  s    (   R   R   R   R   RÏ   RÝ   RÞ   (    (    (    s   /usr/lib/python2.7/mhlib.pyR×   ä  s
   	
		Rb   c           B   s§   e  Z d  Z d d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s÷  Class implementing sets of integers.

    This is an efficient representation for sets consisting of several
    continuous ranges, e.g. 1-100,200-400,402-1000 is represented
    internally as a list of three pairs: [(1,100), (200,400),
    (402,1000)].  The internal representation is always kept normalized.

    The constructor has up to three arguments:
    - the string used to initialize the set (default ''),
    - the separator between ranges (default ',')
    - the separator between begin and end of a range (default '-')
    The separators must be strings (not regexprs) and should be different.

    The tostring() function yields a string that can be passed to another
    IntSet constructor; __repr__() is a valid IntSet constructor itself.
    R>   Rx   c         C   s5   g  |  _  | |  _ | |  _ | r1 |  j | ƒ n  d  S(   N(   t   pairst   sept   rngt
   fromstring(   R   t   dataRã   Rä   (    (    s   /usr/lib/python2.7/mhlib.pyR     s
    			 c         C   s   g  |  _  d  S(   N(   Râ   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   reset   s    c         C   s   t  |  j | j ƒ S(   N(   t   cmpRâ   (   R   t   other(    (    s   /usr/lib/python2.7/mhlib.pyt   __cmp__#  s    c         C   s   t  |  j ƒ S(   N(   t   hashRâ   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   __hash__&  s    c         C   s   d |  j  ƒ  |  j |  j f S(   Ns   IntSet(%r, %r, %r)(   Rk   Rã   Rä   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyR   )  s    c         C   s¤   |  j  j ƒ  d } xŠ | t |  j  ƒ k  rŸ |  j  | d \ } } |  j  | \ } } | | d k r’ | t | | ƒ f g |  j  | d | d +q | d } q Wd  S(   Ni   (   Râ   R-   R`   Rp   (   R   R~   t   alot   ahit   blot   bhi(    (    s   /usr/lib/python2.7/mhlib.pyt	   normalize,  s    -c         C   s|   d } xo |  j  D]d \ } } | | k r7 t | ƒ } n t | ƒ |  j t | ƒ } | rn | |  j | } q | } q W| S(   NR;   (   Râ   R»   Rä   Rã   (   R   Rm   t   lot   hit   t(    (    s   /usr/lib/python2.7/mhlib.pyRk   7  s      
c         C   sA   g  } x4 |  j  D]) \ } } t | | d ƒ } | | } q W| S(   Ni   (   Râ   t   range(   R   t   lRò   Ró   t   m(    (    s   /usr/lib/python2.7/mhlib.pyRc   @  s
    c         C   s"   x | D] } |  j  | ƒ q Wd  S(   N(   R,   (   R   R‘   R~   (    (    s   /usr/lib/python2.7/mhlib.pyRj   G  s    c         C   s   t  ƒ  } |  j | _ | S(   N(   Rb   Râ   (   R   R©   (    (    s   /usr/lib/python2.7/mhlib.pyt   cloneK  s    	c         C   s   |  j  d d S(   Ni    (   Râ   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyt   minP  s    c         C   s   |  j  d d S(   Niÿÿÿÿ(   Râ   (   R   (    (    s   /usr/lib/python2.7/mhlib.pyRp   S  s    c         C   s>   x7 |  j  D], \ } } | | k o- | k n r
 t Sq
 Wt S(   N(   Râ   t   Truet   False(   R   t   xRò   Ró   (    (    s   /usr/lib/python2.7/mhlib.pyt   containsV  s     c         C   sq  xø t  t |  j ƒ ƒ D]á } |  j | \ } } | | k  rç | d | k ra | | f |  j | <n |  j j | | | f ƒ | d k rã | d |  j | d d k rã |  j | d d |  j | d f g |  j | d | d +n  d  S| | k r d  Sq Wt |  j ƒ d } | d k rW|  j | \ } } | d | k rW| | f |  j | <d  Sn  |  j j | | f ƒ d  S(   Ni   i    (   Rõ   R`   Râ   t   insertR,   (   R   Rü   R~   Rò   Ró   (    (    s   /usr/lib/python2.7/mhlib.pyR,   [  s&    +,c         C   s4   | | k r d  S|  j  j | | f ƒ |  j ƒ  d  S(   N(   Râ   R,   Rñ   (   R   t   xlot   xhi(    (    s   /usr/lib/python2.7/mhlib.pyt   addpairt  s     c         C   s   g  } xÙ | j  |  j ƒ D]Å } g  } x9 | j  |  j ƒ D]% } | j ƒ  } | j t | ƒ ƒ q8 Wt | ƒ d k r‘ | j | d | d f ƒ q t | ƒ d k rÕ | d | d k rÕ | j | d | d f ƒ q t d ‚ q W|  j | |  _ |  j	 ƒ  d  S(   Ni   i    i   s   bad data passed to IntSet(
   R_   Rã   Rä   Ra   R,   RC   R`   Rq   Râ   Rñ   (   R   Ræ   R©   RÜ   R‘   t   subpRm   (    (    s   /usr/lib/python2.7/mhlib.pyRå   y  s    &N(   R   R   RL   R   R   Rç   Rê   Rì   R   Rñ   Rk   Rc   Rj   Rø   Rù   Rp   Rý   R,   R  Rå   (    (    (    s   /usr/lib/python2.7/mhlib.pyRb     s"   															i   c         C   sÝ   y t  |  d ƒ } Wn t k
 r' d  SXt j | ƒ d } t j | | oP t j ƒ } x€ | j ƒ  } | so Pn  | j | ƒ rY | t	 | ƒ d } x6 | j ƒ  } | s¹ | d j
 ƒ  r½ Pn  | | } q• W| j ƒ  SqY Wd  S(   NRZ   R[   i   i    (   R&   R]   R   t   ret   escapet   compilet
   IGNORECASER^   RN   R`   R½   Ra   (   t   fileR    t   casefoldR)   t   patt   progRe   t   text(    (    s   /usr/lib/python2.7/mhlib.pyR   Œ  s&     c         C   sa  y) t  |  d ƒ } | j ƒ  } | j ƒ  Wn t k
 rB g  } n Xt j | ƒ d } t j | | ok t j ƒ } | d  k r† d  } n d | | f } xs t	 t
 | ƒ ƒ D]C }	 | |	 }
 | j |
 ƒ r© | d  k rÞ | |	 =n
 | | |	 <Pq© q© W| d  k	 r| j | ƒ n  |  d } t  | d ƒ } x | D] }
 | j |
 ƒ q,W| j ƒ  t j | |  ƒ d  S(   NRZ   s   :(.*)
s   %s: %s
R
   R%   (   R&   t	   readlinesR'   R]   R  R  R  R  R   Rõ   R`   RN   R,   R   R   R   (   R  R    Rg   R  R)   t   linesR	  R
  t   newlineR~   Re   t   tempfile(    (    s   /usr/lib/python2.7/mhlib.pyRu      s4    
	




c    	      C   sÓ  t  j d ƒ t ƒ  a d „  }  |  d ƒ |  d ƒ d d d d d	 d
 g } x | D] } |  d | f ƒ qR W|  d ƒ |  d ƒ t j d ƒ a |  d ƒ |  d ƒ |  d ƒ t j ƒ  } t d d ƒ j ƒ  | d <| GHt j	 | ƒ |  d ƒ x% t
 | ƒ D] } |  d | f ƒ qü W|  d ƒ t j ƒ  } t j | ƒ a |  d ƒ x| d/ D]t } y |  d* | f ƒ Wn t k
 r†} d+ G| GHn Xt  j d, | f ƒ j ƒ  } t t | j ƒ  ƒ } | Gd- GHqMW|  d. ƒ d  S(0   Ns   rm -rf $HOME/Mail/@testc         S   s   |  GHt  |  ƒ GHd  S(   N(   t   eval(   Rm   (    (    s   /usr/lib/python2.7/mhlib.pyt   doÆ  s    s   mh.listfolders()s   mh.listallfolders()s   @tests   @test/test1s   @test/test2s   @test/test1/test11s   @test/test1/test12s   @test/test1/test11/test111s   mh.makefolder(%r)s   mh.listsubfolders('@test')s   mh.listallsubfolders('@test')s   f.listsubfolders()s   f.listallsubfolders()s   f.getsequences()s
   1-10 12-20R\   t   foos   mh.deletefolder(%r)s   mh.getcontext()s   f.getcurrent()RŠ   RW   Ro   R‰   Ry   R‹   s   first:3s   last:3s   cur:3s   cur:-3s   prev:3s   next:3s   1:3s   1:-3s   100:3s   100:-3s   10000:3s   10000:-3Rw   s   f.parsesequence(%r)s   Error:s   pick %r 2>/dev/nulls   <-- picks   f.listmessages()(   RŠ   RW   Ro   R‰   Ry   R‹   s   first:3s   last:3s   cur:3s   cur:-3s   prev:3s   next:3s   1:3s   1:-3s   100:3s   100:-3s   10000:3s   10000:-3Rw   (   R   t   systemR   RP   RB   R)   Rh   Rb   Rc   Rn   t   reversedR$   R   t   popenR¯   RV   RC   R_   (	   R  t   testfoldersRô   Rs   R"   Rl   R   t   stuffR‘   (    (    s   /usr/lib/python2.7/mhlib.pyt   testÂ  sP    		

		 





 

   
t   __main__(   RL   t   warningsR    R   R   RR   RD   R   R   R  R¹   RÔ   R—   R   t   __all__t	   ExceptionR   R   R  RM   R?   R   R   R×   Rb   R   Ru   R  R   (    (    (    s   /usr/lib/python2.7/mhlib.pyt   <module>6   s<   		ÿ ¦M‰"	*