Ñò
mÈKc           @   s~  d  Z  d d k l Z e d d d ƒ[ d Z d Z d Z d	 Z d d
 k Z d d
 k Z d d
 k	 Z	 d d
 k
 Z
 d d
 k Z d d
 k Z d d k l Z d d d d g Z d e f d „  ƒ  YZ d f  d „  ƒ  YZ e	 i d ƒ Z d „  Z d f  d „  ƒ  YZ d e
 i f d „  ƒ  YZ d e f d „  ƒ  YZ d f  d „  ƒ  YZ d d „ Z d d „ Z d „  Z e d j o 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.6/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 j o
 t } n t i i | ƒ |  _ | d j o |  i d ƒ } n | p
 t } n t i i | ƒ o* | d d j o t i i	 d | ƒ } n t i i | ƒ } t i i
 | ƒ p 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.6/mhlib.pyt   __init__f   s     
  
% c         C   s   d |  i  |  i f S(   s   String representation.s
   MH(%r, %r)(   R   R   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyt   __repr__r   s    c         G   s   t  i i 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.6/mhlib.pyt   errorv   s    c         C   s   t  |  i | ƒ S(   s*   Return a profile entry, None if not found.(   t   picklineR   (   R   t   key(    (    s   /usr/lib/python2.6/mhlib.pyR   z   s    c         C   s   |  i  S(   s9   Return the path (the name of the collection's directory).(   R   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyt   getpath~   s    c         C   s9   t  t i i |  i ƒ  d ƒ d ƒ } | p
 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.6/mhlib.pyt
   getcontext‚   s
    	 
c         C   sI   t  i i |  i ƒ  d ƒ } t | d ƒ } | i d | ƒ | i ƒ  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.6/mhlib.pyt
   setcontext‰   s    c         C   ss   g  } |  i  ƒ  } xP t i | ƒ D]? } t i i | | ƒ } t i i | ƒ o | i | ƒ q" q" W| i ƒ  | 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.6/mhlib.pyt   listfolders   s     
c   	      C   sÚ   t  i i |  i | ƒ } t  i | ƒ i } | d j o g  Sg  } t  i | ƒ } xx | D]p } t  i i | | ƒ } t  i i | ƒ oB t  i i | | ƒ } | i | ƒ | d } | d j o PqÈ qX qX W| i ƒ  | 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.6/mhlib.pyt   listsubfolders›   s"     

c         C   s   |  i  d ƒ S(   s<   Return the names of all folders and subfolders, recursively.t    (   t   listallsubfolders(   R   (    (    s   /usr/lib/python2.6/mhlib.pyt   listallfolders³   s    c   
      C   s/  t  i i |  i | ƒ } t  i | ƒ i } | d j o g  Sg  } t  i | ƒ } xÍ | D]Å } | d d j p t | ƒ o qX n t  i i | | ƒ } t  i i | ƒ or t  i i | | ƒ } | i | ƒ t  i i	 | ƒ p |  i
 | ƒ }	 | |	 } n | d } | d j o PqqX qX W| i ƒ  | 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.6/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.6/mhlib.pyt
   openfolderÓ   s    c         C   sh   t  |  i d ƒ } | o  t | ƒ o t | d ƒ } n t } t i t i i |  i	 ƒ  | ƒ | ƒ 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.6/mhlib.pyt
   makefolder×   s
    c         C   s–   t  i i |  i ƒ  | ƒ } xg t  i | ƒ D]V } t  i i | | ƒ } y t  i | ƒ Wq+ t  i j
 o |  i d | ƒ q+ Xq+ Wt  i | ƒ 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.6/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.6/mhlib.pyR   _   s   													s   ^[1-9][0-9]*$c         C   s   t  i |  ƒ d  j	 S(   N(   t   numericprogt   matchR   (   t   str(    (    s   /usr/lib/python2.6/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 i i |  i ƒ  ƒ p 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.6/mhlib.pyR   õ   s    		c         C   s   d |  i  |  i f S(   s   String representation.s   Folder(%r, %r)(   RP   R/   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyR   ü   s    c         G   s   |  i  i | Œ  d S(   s   Error message handler.N(   RP   R   (   R   R   (    (    s   /usr/lib/python2.6/mhlib.pyR      s    c         C   s   t  i i |  i i |  i ƒ S(   s'   Return the full pathname of the folder.(   R   R   R   RP   R/   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyRQ     s    c         C   s   t  i i |  i ƒ  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.6/mhlib.pyt   getsequencesfilename  s    c         C   s   t  i i |  i ƒ  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.6/mhlib.pyt   getmessagefilename  s    c         C   s   |  i  i |  i ƒ S(   s!   Return list of direct subfolders.(   RP   R:   R/   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyR:     s    c         C   s   |  i  i |  i ƒ S(   s   Return list of all subfolders.(   RP   R<   R/   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyR<     s    c         C   s‘   g  } t  i } | i } x8 t i |  i ƒ  ƒ D]! } | | ƒ o | | ƒ q. q. Wt t | ƒ } | i ƒ  | o | 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.6/mhlib.pyt   listmessages  s    		 
	c         C   sÚ   h  } |  i  ƒ  } y t | d ƒ } Wn t j
 o | SXx— | i ƒ  } | p Pn | i d ƒ } t | ƒ d j o! |  i d | | i ƒ  f ƒ n | d i ƒ  } t | d i ƒ  d ƒ i	 ƒ  } | | | <q? | 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.6/mhlib.pyt   getsequences)  s$     	c         C   sÅ   |  i  ƒ  } d } xm | i ƒ  D]_ \ } } t d d ƒ } | i | ƒ | p t | d ƒ } n | i d | | i ƒ  f ƒ q W| p. y t i	 | ƒ WqÁ t i
 j
 o qÁ Xn | i ƒ  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.6/mhlib.pyt   putsequences=  s      !	c         C   sG   |  i  ƒ  } y t | d ƒ SWn" t t f j
 o 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.6/mhlib.pyt
   getcurrentN  s
    c         C   s#   t  |  i ƒ  d t | ƒ d ƒ d S(   s   Set the current message.Ro   i    N(   t
   updatelineRS   RO   (   R   RT   (    (    s   /usr/lib/python2.6/mhlib.pyt
   setcurrentV  s    c         C   sv  |  i  ƒ  } | p t d |  i ‚ n | d j o | S| i d ƒ } | d j oÔ| |  d | | d } } } | d  d j o | d  | d } } n t | ƒ p t d | ‚ n y t | ƒ } Wn% t t f j
 o t | ƒ } n Xy |  i	 | | ƒ } Wnž t j
 o’ }	 |  i
 ƒ  }
 | |
 j o/ |	 p d | }	 n t |	 t i ƒ  d	 ‚ n |
 | } | p t d
 | ‚ n | d j o
 | | S| |  Sq)X| p | d j o
 d } qÎn | d j o( t | | ƒ } | t d | | ƒ | !St | | d ƒ } | | | | !Sn | i d ƒ } | d j o| |  i	 | |  | ƒ } |  i	 | | d | ƒ } t | | d ƒ } t | | ƒ } | | | !} | p t d | ‚ n | Sy |  i	 | | ƒ } WnU t j
 oI }	 |  i
 ƒ  }
 | |
 j o" |	 p d | }	 n t |	 ‚ n |
 | SX| | j o/ t | ƒ o t d | ‚ qr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   s   last(   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.6/mhlib.pyt   parsesequenceZ  s|    	 


c         C   s`  t  | ƒ o2 y t | ƒ SWq? t t f j
 o t i SXn | d j o |  i ƒ  S| d j o	 | d S| d j o	 | d S| d j oJ |  i ƒ  } t | | ƒ } y | | SWqÚ t j
 o t	 d ‚ qÚ Xn | d	 j ol |  i ƒ  } t | | d
 ƒ } | d j o t	 d ‚ n y | | d
 SWqSt j
 o t	 d ‚ qS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(   s   curR‰   (   R?   RC   R{   Rq   R   t   maxintRt   R   t
   IndexErrorR   R   (   R   Rl   Rw   RT   R~   (    (    s   /usr/lib/python2.6/mhlib.pyR|   ®  s8    		c         C   s   t  |  | ƒ S(   s+   Open a message -- returns a Message object.(   R   (   R   RT   (    (    s   /usr/lib/python2.6/mhlib.pyt   openmessageÍ  s    c      
   C   s  g  } g  } x© | D]¡ } |  i  | ƒ } |  i  d t | ƒ ƒ } y t i | ƒ Wn t i j
 o n Xy t i | | ƒ Wn% t i j
 o } | i | ƒ q X| i | ƒ q W| o |  i | ƒ n | o= t | ƒ d j o t i | d ‚ qt i 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.6/mhlib.pyt   removemessagesÑ  s*     i    c         C   s’  g  } h  } xü | D]ô } | i  ƒ  d } |  i | ƒ } | i | ƒ }	 y t i | |	 ƒ Wn’ t i j
 oƒ y! t i | |	 ƒ t i | ƒ Wqð t t i f j
 oC }
 | i	 |
 ƒ y t i |	 ƒ Wq t i j
 o q Xq qð Xn X| i
 | ƒ | | | <q W| o8 | o | i |  | i ƒ  ƒ n |  i | i ƒ  ƒ n | o= t | ƒ d j o t i | d ‚ qŽt i 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.6/mhlib.pyt   refilemessagesê  s<     c      	   C   sä   | i  ƒ  } |  i  ƒ  } d } x§ | i ƒ  D]™ \ } } y | | } d }	 Wn t j
 o g  } d }	 n Xx8 | D]0 \ }
 } |
 | j o | i | ƒ d } qt qt W|	 o | o | | | <q+ q+ W| o |  i | ƒ 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.6/mhlib.pyRš     s(     

 c   	      C   s+  |  i  | ƒ } t | ƒ } | i ƒ  ~ | i  | ƒ } | i  d | ƒ } y t i | | ƒ Wn t i j
 o n Xy t i | | ƒ Wn‰ t i j
 oz d } z' | i d ƒ t i	 | | ƒ d } Wd | p. y t i
 | ƒ Wqt i j
 o qXn Xt i
 | ƒ n X|  i | 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.6/mhlib.pyt   movemessage"  s2    


c   	      C   sá   |  i  | ƒ } t | ƒ } | i ƒ  ~ | i  | ƒ } | i  d | ƒ } y t i | | ƒ Wn t i j
 o n Xd } z' | i d ƒ t i	 | | ƒ d } Wd | p. y t i
 | ƒ WqÜ t i j
 o 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.6/mhlib.pyt   copymessageB  s(    

c   	      C   sé   |  i  | ƒ } |  i  d | ƒ } y t i | | ƒ Wn t i j
 o n Xd } d } zQ t | d ƒ } x+ | i | ƒ } | p Pn | i | ƒ qp | i ƒ  d } Wd | p. y t i | ƒ Wqä t i j
 o 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.6/mhlib.pyt   createmessage\  s,    

c         C   sÐ   t  |  d ƒ o |  i | j o
 |  ` n |  i ƒ  } d } xu | i ƒ  D]g \ } } | d j o qI n xD | D]< } | | j o) | i | ƒ d } | p | | =q¬ qp qp WqI W| o |  i | ƒ 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.6/mhlib.pyR   v  s"     
  c         C   s%   t  |  d ƒ p |  i ƒ  n |  i S(   s   Return the last message number.RW   (   Rµ   RY   RW   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyR–   ‰  s    c         C   s8   | d j o t |  d ƒ o
 |  ` q4 n
 | |  _ d S(   s   Set the last message number.RW   N(   R   Rµ   RW   (   R   RW   (    (    s   /usr/lib/python2.6/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.6/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   sX   | |  _  | |  _ | d j o" | i | ƒ } t | d ƒ } n t i i |  | ƒ d S(   s   Constructor.RZ   N(   t   foldert   numberR   RU   R&   t	   mimetoolsR   R   (   R   R)   RT   t   fpR   (    (    s   /usr/lib/python2.6/mhlib.pyR   ™  s    		c         C   s   d t  |  i ƒ |  i f S(   s   String representation.s   Message(%s, %s)(   t   reprR·   R¸   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyR   ¢  s    c         C   s®   | d j o d i |  i ƒ Sg  } d } xt |  i D]i } | d i ƒ  p: | i d ƒ } | d j o | | |  i ƒ  ƒ } q… n | o | i | ƒ q4 q4 Wd i | ƒ 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.6/mhlib.pyt   getheadertext¦  s    
  i   c         C   s¥   |  i  i |  i ƒ |  i ƒ  } | p | d j o |  i  i ƒ  Sy d d k l } Wn# t j
 o d d k l } n X| ƒ  } t i	 |  i  | | ƒ | i
 ƒ  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.6/mhlib.pyt   getbodytext·  s    	c         C   sÝ   |  i  ƒ  d j o t d ‚ n |  i d ƒ } | p t d ‚ n |  i i |  i ƒ t i |  i ƒ } | i | ƒ g  } xQ | i	 ƒ  oC d |  i
 d t | ƒ f } t |  i | | ƒ } | i | ƒ q~ W| i ƒ  | 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.6/mhlib.pyt   getbodypartsÈ  s      
c         C   s,   |  i  ƒ  d j o |  i ƒ  S|  i ƒ  Sd S(   s3   Return body, either a string or a list of messages.RÐ   N(   RÒ   RÝ   RÏ   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyt   getbodyÜ  s    N(	   R   R   R   R   R   RÁ   RÏ   RÝ   RÞ   (    (    (    s   /usr/lib/python2.6/mhlib.pyR   —  s   			R×   c           B   s8   e  Z d  „  Z d „  Z d d „ Z d „  Z d „  Z RS(   c         C   sm   t  i |  | | | ƒ |  i ƒ  d j o t  i |  ƒ |  _ n t  i |  ƒ |  _ t  i |  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.6/mhlib.pyR   æ  s
    c         C   s.   |  i  |  i |  i } } } d | | | f S(   s   String representation.s   SubMessage(%s, %s, %s)(   R·   R¸   Rº   (   R   R)   RT   Rº   (    (    s   /usr/lib/python2.6/mhlib.pyR   ð  s    i   c         C   s7   | p |  i  St |  i ƒ t d ƒ j o |  i Sd  S(   NR;   (   Rà   t   typeRß   (   R   RË   (    (    s   /usr/lib/python2.6/mhlib.pyRÏ   õ  s    c         C   s(   t  |  i ƒ t  g  ƒ j o |  i Sd  S(   N(   Rá   Rß   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyRÝ   û  s    c         C   s   |  i  S(   N(   Rß   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyRÞ   ÿ  s    (   R   R   R   R   RÏ   RÝ   RÞ   (    (    (    s   /usr/lib/python2.6/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   s7   g  |  _  | |  _ | |  _ | o |  i | ƒ n d  S(   N(   t   pairst   sept   rngt
   fromstring(   R   t   dataRã   Rä   (    (    s   /usr/lib/python2.6/mhlib.pyR     s
    			 c         C   s   g  |  _  d  S(   N(   Râ   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyt   reset   s    c         C   s   t  |  i | i ƒ S(   N(   t   cmpRâ   (   R   t   other(    (    s   /usr/lib/python2.6/mhlib.pyt   __cmp__#  s    c         C   s   t  |  i ƒ S(   N(   t   hashRâ   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyt   __hash__&  s    c         C   s   d |  i  ƒ  |  i |  i f S(   Ns   IntSet(%r, %r, %r)(   Rk   Rã   Rä   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyR   )  s    c         C   s¨   |  i  i ƒ  d } xŽ | t |  i  ƒ j  ow |  i  | d \ } } |  i  | \ } } | | d j o. | t | | ƒ f g |  i  | d | d +q | d } q Wd  S(   Ni   (   Râ   R-   R`   Rp   (   R   R~   t   alot   ahit   blot   bhi(    (    s   /usr/lib/python2.6/mhlib.pyt	   normalize,  s     .c         C   s€   d } xs |  i  D]h \ } } | | j o t | ƒ } n t | ƒ |  i t | ƒ } | o | |  i | } q | } q W| S(   NR;   (   Râ   R»   Rä   Rã   (   R   Rm   t   lot   hit   t(    (    s   /usr/lib/python2.6/mhlib.pyRk   7  s    
   
c         C   sA   g  } x4 |  i  D]) \ } } t | | d ƒ } | | } q W| S(   Ni   (   Râ   t   range(   R   t   lRò   Ró   t   m(    (    s   /usr/lib/python2.6/mhlib.pyRc   @  s    
 c         C   s"   x | D] } |  i  | ƒ q Wd  S(   N(   R,   (   R   R‘   R~   (    (    s   /usr/lib/python2.6/mhlib.pyRj   G  s     c         C   s   t  ƒ  } |  i | _ | S(   N(   Rb   Râ   (   R   R©   (    (    s   /usr/lib/python2.6/mhlib.pyt   cloneK  s    	c         C   s   |  i  d d S(   Ni    (   Râ   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyt   minP  s    c         C   s   |  i  d d S(   Niÿÿÿÿ(   Râ   (   R   (    (    s   /usr/lib/python2.6/mhlib.pyRp   S  s    c         C   sA   x: |  i  D]/ \ } } | | j o
 | j n o t Sq
 Wt S(   N(   Râ   t   Truet   False(   R   t   xRò   Ró   (    (    s   /usr/lib/python2.6/mhlib.pyt   containsV  s
    
  	c         C   s~  xt  t |  i ƒ ƒ D]ê } |  i | \ } } | | j  o² | d | j o | | f |  i | <n |  i i | | | f ƒ | d j o_ | d |  i | d d j o? |  i | d d |  i | d f g |  i | d | d +n d  S| | j o d  Sq Wt |  i ƒ d } | d j o@ |  i | \ } } | d | j o | | f |  i | <d  Sn |  i i | | f ƒ d  S(   Ni   i    (   Rõ   R`   Râ   t   insertR,   (   R   Rü   R~   Rò   Ró   (    (    s   /usr/lib/python2.6/mhlib.pyR,   [  s(     --		c         C   s6   | | j o d  S|  i  i | | f ƒ |  i ƒ  d  S(   N(   Râ   R,   Rñ   (   R   t   xlot   xhi(    (    s   /usr/lib/python2.6/mhlib.pyt   addpairt  s     c         C   s  g  } xÞ | i  |  i ƒ D]Ê } g  } x9 | i  |  i ƒ D]% } | i ƒ  } | i t | ƒ ƒ q8 Wt | ƒ d j o | i | d | d f ƒ q t | ƒ d j o4 | d | d j o | i | d | d f ƒ q t d ‚ q W|  i | |  _ |  i	 ƒ  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.6/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.6/mhlib.pyRb     s"   															i   c         C   så   y t  |  d ƒ } Wn t j
 o d  SXt i | ƒ d } t i | | o t i ƒ } x… | i ƒ  } | p Pn | i | ƒ oZ | t	 | ƒ d } x8 | i ƒ  } | p | d i
 ƒ  o Pn | | } q› | i ƒ  Sq\ d  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.6/mhlib.pyR   Œ  s&     c      
   C   sl  y) t  |  d ƒ } | i ƒ  } | i ƒ  Wn t j
 o g  } n Xt i | ƒ d } t i | | o t i ƒ } | d  j o
 d  } n d | | f } xy t	 t
 | ƒ ƒ D]G }	 | |	 }
 | i |
 ƒ o' | d  j o | |	 =n | | |	 <Pq® q® W| d  j	 o | i | ƒ n |  d } t  | d ƒ } x | D] }
 | i |
 ƒ q7W| i ƒ  t i | |  ƒ 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.6/mhlib.pyRu      s8    
 

	
 
c    	      C   sÕ  t  i d ƒ t ƒ  a d „  }  |  d ƒ |  d ƒ d d d d d	 d
 g } x | D] } |  d | f ƒ qR W|  d ƒ |  d ƒ t i d ƒ a |  d ƒ |  d ƒ |  d ƒ t i ƒ  } t d d ƒ i ƒ  | d <| GHt i	 | ƒ |  d ƒ x% t
 | ƒ D] } |  d | f ƒ qü W|  d ƒ t i ƒ  } t i | ƒ a |  d ƒ x~ d/ D]v } y |  d* | f ƒ Wn t j
 o } d+ G| GHn Xt  i d, | f ƒ i ƒ  } t t | i ƒ  ƒ } | 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.6/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()(   s   firsts   lasts   curR‰   s   prevs   nexts   first:3s   last:3s   cur:3s   cur:-3s   prev:3s   next:3s   1:3s   1:-3s   100:3s   100:-3s   10000:3s   10000:-3s   all(   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.6/mhlib.pyt   testÂ  sV    		

		  





  

    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.6/mhlib.pyt   <module>6   s<   		ÿ ¦M‰"	*