Ñò
ïžòKc        !   @   s´  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 Z d d k Z d d k	 Z d d k
 Z d d k Z d d k Z y* e i d j o
 e ‚ n d d k Z Wn e j
 o e Z n Xd d d d d d	 d
 d d d d d d d d d d g Z d f  d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d
 e i i f d „  ƒ  YZ d e f d  „  ƒ  YZ d! e f d" „  ƒ  YZ d e f d# „  ƒ  YZ d e f d$ „  ƒ  YZ d e f d% „  ƒ  YZ  d e f d& „  ƒ  YZ! d' f  d( „  ƒ  YZ" d) e" f d* „  ƒ  YZ# e$ d+ „ Z% d, „  Z& d- „  Z' d. „  Z( d/ „  Z) d0 „  Z* d1 f  d2 „  ƒ  YZ+ d e+ f d3 „  ƒ  YZ, d e, f d4 „  ƒ  YZ- d e+ f d5 „  ƒ  YZ. d f  d6 „  ƒ  YZ/ d e+ f d7 „  ƒ  YZ0 d8 e1 f d9 „  ƒ  YZ2 d: e2 f d; „  ƒ  YZ3 d< e2 f d= „  ƒ  YZ4 d> e2 f d? „  ƒ  YZ5 d@ e2 f dA „  ƒ  YZ6 d S(B   sD   Read/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes.iÿÿÿÿNt   os2emxt   Mailboxt   Maildirt   mboxt   MHt   Babylt   MMDFt   Messaget   MaildirMessaget   mboxMessaget	   MHMessaget   BabylMessaget   MMDFMessaget   UnixMailboxt   PortableUnixMailboxt   MmdfMailboxt	   MHMailboxt   BabylMailboxc           B   s.  e  Z d  Z d e 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 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d d „ Z d „  Z d „  Z d „  Z  d „  Z! e" d „ Z# RS(    s*   A group of messages in a particular place.c         C   s.   t  i i t  i i | ƒ ƒ |  _ | |  _ d S(   s   Initialize a Mailbox instance.N(   t   ost   patht   abspatht
   expandusert   _patht   _factory(   t   selfR   t   factoryt   create(    (    s   scripts/common/Lib/mailbox.pyt   __init__'   s    !c         C   s   t  d ƒ ‚ d S(   s$   Add message and return assigned key.s&   Method must be implemented by subclassN(   t   NotImplementedError(   R   t   message(    (    s   scripts/common/Lib/mailbox.pyt   add,   s    c         C   s   t  d ƒ ‚ d S(   s=   Remove the keyed message; raise KeyError if it doesn't exist.s&   Method must be implemented by subclassN(   R   (   R   t   key(    (    s   scripts/common/Lib/mailbox.pyt   remove0   s    c         C   s   |  i  | ƒ d  S(   N(   R    (   R   R   (    (    s   scripts/common/Lib/mailbox.pyt   __delitem__4   s    c         C   s+   y |  i  | ƒ Wn t j
 o n Xd S(   s'   If the keyed message exists, remove it.N(   R    t   KeyError(   R   R   (    (    s   scripts/common/Lib/mailbox.pyt   discard7   s    c         C   s   t  d ƒ ‚ d S(   s>   Replace the keyed message; raise KeyError if it doesn't exist.s&   Method must be implemented by subclassN(   R   (   R   R   R   (    (    s   scripts/common/Lib/mailbox.pyt   __setitem__>   s    c         C   s,   y |  i  | ƒ SWn t j
 o | SXd S(   s9   Return the keyed message, or default if it doesn't exist.N(   t   __getitem__R"   (   R   R   t   default(    (    s   scripts/common/Lib/mailbox.pyt   getB   s    c         C   s2   |  i  p |  i | ƒ S|  i  |  i | ƒ ƒ Sd S(   s=   Return the keyed message; raise KeyError if it doesn't exist.N(   R   t   get_messaget   get_file(   R   R   (    (    s   scripts/common/Lib/mailbox.pyR%   I   s    
c         C   s   t  d ƒ ‚ d S(   s4   Return a Message representation or raise a KeyError.s&   Method must be implemented by subclassN(   R   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR(   P   s    c         C   s   t  d ƒ ‚ d S(   s3   Return a string representation or raise a KeyError.s&   Method must be implemented by subclassN(   R   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyt
   get_stringT   s    c         C   s   t  d ƒ ‚ d S(   s6   Return a file-like representation or raise a KeyError.s&   Method must be implemented by subclassN(   R   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR)   X   s    c         C   s   t  d ƒ ‚ d S(   s   Return an iterator over keys.s&   Method must be implemented by subclassN(   R   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   iterkeys\   s    c         C   s   t  |  i ƒ  ƒ S(   s   Return a list of keys.(   t   listR+   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   keys`   s    c         c   sG   x@ |  i  ƒ  D]2 } y |  | } Wn t j
 o
 q n X| Vq Wd S(   s%   Return an iterator over all messages.N(   R+   R"   (   R   R   t   value(    (    s   scripts/common/Lib/mailbox.pyt
   itervaluesd   s     c         C   s
   |  i  ƒ  S(   N(   R/   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   __iter__m   s    c         C   s   t  |  i ƒ  ƒ S(   s,   Return a list of messages. Memory intensive.(   R,   R/   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   valuesp   s    c         c   sM   xF |  i  ƒ  D]8 } y |  | } Wn t j
 o
 q n X| | f Vq Wd S(   s.   Return an iterator over (key, message) tuples.N(   R+   R"   (   R   R   R.   (    (    s   scripts/common/Lib/mailbox.pyt	   iteritemst   s     c         C   s   t  |  i ƒ  ƒ S(   s9   Return a list of (key, message) tuples. Memory intensive.(   R,   R2   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   items}   s    c         C   s   t  d ƒ ‚ d S(   s9   Return True if the keyed message exists, False otherwise.s&   Method must be implemented by subclassN(   R   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyt   has_key�   s    c         C   s   |  i  | ƒ S(   N(   R4   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyt   __contains__…   s    c         C   s   t  d ƒ ‚ d S(   s*   Return a count of messages in the mailbox.s&   Method must be implemented by subclassN(   R   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   __len__ˆ   s    c         C   s(   x! |  i  ƒ  D] } |  i | ƒ q Wd S(   s   Delete all messages.N(   R+   R#   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyt   clearŒ   s     c         C   s6   y |  | } Wn t  j
 o | SX|  i | ƒ | S(   s3   Delete the keyed message and return it, or default.(   R"   R#   (   R   R   R&   t   result(    (    s   scripts/common/Lib/mailbox.pyt   pop‘   s    c         C   s7   x0 |  i  ƒ  D] } | |  i | ƒ f SWt d ƒ ‚ d S(   s6   Delete an arbitrary (key, message) pair and return it.s   No messages in mailboxN(   R+   R9   R"   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyt   popitemš   s     c         C   s¨   t  | d ƒ o | i ƒ  } n' t  | d ƒ o | i ƒ  } n | } t } x> | D]6 \ } } y | |  | <WqS t j
 o t } qS XqS W| o t d ƒ ‚ n d S(   s4   Change the messages that correspond to certain keys.R2   R3   s   No message with key(s)N(   t   hasattrR2   R3   t   FalseR"   t   True(   R   t   argt   sourcet   bad_keyR   R   (    (    s   scripts/common/Lib/mailbox.pyt   update¡   s     c         C   s   t  d ƒ ‚ d S(   s&   Write any pending changes to the disk.s&   Method must be implemented by subclassN(   R   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   flush²   s    c         C   s   t  d ƒ ‚ d S(   s   Lock the mailbox.s&   Method must be implemented by subclassN(   R   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   lock¶   s    c         C   s   t  d ƒ ‚ d S(   s#   Unlock the mailbox if it is locked.s&   Method must be implemented by subclassN(   R   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   unlockº   s    c         C   s   t  d ƒ ‚ d S(   s   Flush and close the mailbox.s&   Method must be implemented by subclassN(   R   (   R   (    (    s   scripts/common/Lib/mailbox.pyt   close¾   s    c         C   ss  t  | t i i ƒ od t i ƒ  } t i i | | d ƒ } | i | ƒ | i d ƒ | i	 | i
 ƒ  i d t i ƒ ƒ nö t  | t ƒ oC | o | i d d ƒ } n | i d t i ƒ } | i	 | ƒ n£ t | d ƒ o| x� t om | i ƒ  } | d j o Pn | o" | i d ƒ o d | d	 } n | i d t i ƒ } | i	 | ƒ qà Wn t d
 t | ƒ ƒ ‚ d S(   s%   Dump message contents to target file.i    s   
s   
From s   
>From t   readt    s   From s   >From i   s   Invalid message type: %sN(   t
   isinstancet   emailR   R   t   StringIOt	   generatort	   Generatort   flattent   seekt   writeRF   t   replaceR   t   linesept   strR;   R=   t   readlinet
   startswitht	   TypeErrort   type(   R   R   t   targett   mangle_from_t   buffert   gent   line(    (    s   scripts/common/Lib/mailbox.pyt   _dump_messageÂ   s,    & N($   t   __name__t
   __module__t   __doc__t   NoneR=   R   R   R    R!   R#   R$   R'   R%   R(   R*   R)   R+   R-   R/   R0   R1   R2   R3   R4   R5   R6   R7   R9   R:   RA   RB   RC   RD   RE   R<   R\   (    (    (    s   scripts/common/Lib/mailbox.pyR   $   s>   																												c           B   sû   e  Z d  Z d Z e i e 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 „  Z d „  Z d Z d „  Z d „  Z d „  Z d „  Z RS(   s   A qmail-style Maildir mailbox.t   :c         C   sÐ   t  i |  | | | ƒ t i i |  i ƒ p— | o} t i |  i d ƒ t i t i i |  i d ƒ d ƒ t i t i i |  i d ƒ d ƒ t i t i i |  i d ƒ d ƒ qÃ t |  i ƒ ‚ n h  |  _	 d S(   s   Initialize a Maildir instance.iÀ  t   tmpt   newt   curN(
   R   R   R   R   t   existsR   t   mkdirt   joint   NoSuchMailboxErrort   _toc(   R   t   dirnameR   R   (    (    s   scripts/common/Lib/mailbox.pyR   ä   s    ""&c      
   C   s«  |  i  ƒ  } z |  i | | ƒ Wd t | ƒ Xt | t ƒ o= | i ƒ  } |  i | i ƒ  } | |  i j o
 d } q‡ n d } d } t i	 i
 | i ƒ i |  i ƒ d } t i	 i |  i | | | ƒ } yN t t d ƒ o' t i | i | ƒ t i | i ƒ n t i | i | ƒ WnO t j
 oC } t i | i ƒ | i t i j o t d | ƒ ‚ qk‚  n Xt | t ƒ o, t i | t i	 i | ƒ | i ƒ  f ƒ n | S(   s$   Add message and return assigned key.NRG   Rc   i    t   links$   Name clash with existing message: %s(   t   _create_tmpR\   t   _sync_closeRH   R   t
   get_subdirt   colont   get_infoR   R   t   basenamet   namet   splitRg   R   R;   Rk   R    t   renamet   OSErrort   errnot   EEXISTt   ExternalClashErrort   utimet   getatimet   get_date(   R   R   t   tmp_filet   subdirt   suffixt   uniqt   destt   e(    (    s   scripts/common/Lib/mailbox.pyR   ñ   s6    %,c         C   s,   t  i t  i i |  i |  i | ƒ ƒ ƒ d S(   s=   Remove the keyed message; raise KeyError if it doesn't exist.N(   R   R    R   Rg   R   t   _lookup(   R   R   (    (    s   scripts/common/Lib/mailbox.pyR      s    c         C   sY   y |  i  | ƒ WnA t j
 o n0 t j
 o# } | i t i j o ‚  qU n Xd S(   s'   If the keyed message exists, remove it.N(   R    R"   Ru   Rv   t   ENOENT(   R   R   R�   (    (    s   scripts/common/Lib/mailbox.pyR#     s    c   
      C   s$  |  i  | ƒ } |  i | ƒ } |  i  | ƒ } t | t ƒ o
 | } n | } t i i | ƒ } |  i | j o! |  i | i |  i ƒ d } n d } |  i	 | ƒ t i i
 |  i | | | ƒ }	 t i t i i
 |  i | ƒ |	 ƒ t | t ƒ o, t i |	 t i i |	 ƒ | i ƒ  f ƒ n d S(   s>   Replace the keyed message; raise KeyError if it doesn't exist.iÿÿÿÿRG   N(   R‚   R   RH   R   R   R   Rj   Ro   Rs   R#   Rg   R   Rt   Ry   Rz   R{   (
   R   R   R   t   old_subpatht   temp_keyt   temp_subpatht   dominant_subpathR}   R~   t   new_path(    (    s   scripts/common/Lib/mailbox.pyR$   "  s     
!"c         C   sð   |  i  | ƒ } t t i i |  i | ƒ d ƒ } z- |  i o |  i | ƒ } n t | ƒ } Wd | i ƒ  Xt i i	 | ƒ \ } } | i
 | ƒ |  i | j o! | i | i	 |  i ƒ d ƒ n | i t i i t i i |  i | ƒ ƒ ƒ | S(   s4   Return a Message representation or raise a KeyError.t   rNiÿÿÿÿ(   R‚   t   openR   R   Rg   R   R   R   RE   Rs   t
   set_subdirRo   t   set_infot   set_datet   getmtime(   R   R   t   subpatht   ft   msgR}   Rr   (    (    s   scripts/common/Lib/mailbox.pyR(   9  s    !
!+c         C   sJ   t  t i i |  i |  i | ƒ ƒ d ƒ } z | i ƒ  SWd | i ƒ  Xd S(   s3   Return a string representation or raise a KeyError.R‰   N(   RŠ   R   R   Rg   R   R‚   RF   RE   (   R   R   R�   (    (    s   scripts/common/Lib/mailbox.pyR*   K  s    *c         C   s4   t  t i i |  i |  i | ƒ ƒ d ƒ } t | ƒ S(   s6   Return a file-like representation or raise a KeyError.t   rb(   RŠ   R   R   Rg   R   R‚   t
   _ProxyFile(   R   R   R�   (    (    s   scripts/common/Lib/mailbox.pyR)   S  s    *c         c   sQ   |  i  ƒ  x@ |  i D]5 } y |  i | ƒ Wn t j
 o
 q n X| Vq Wd S(   s   Return an iterator over keys.N(   t   _refreshRi   R‚   R"   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR+   X  s    

 c         C   s   |  i  ƒ  | |  i j S(   s9   Return True if the keyed message exists, False otherwise.(   R”   Ri   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR4   b  s    
c         C   s   |  i  ƒ  t |  i ƒ S(   s*   Return a count of messages in the mailbox.(   R”   t   lenRi   (   R   (    (    s   scripts/common/Lib/mailbox.pyR6   g  s    
c         C   s   d S(   s"   Write any pending changes to disk.N(    (   R   (    (    s   scripts/common/Lib/mailbox.pyRB   l  s    c         C   s   d S(   s   Lock the mailbox.N(    (   R   (    (    s   scripts/common/Lib/mailbox.pyRC   p  s    c         C   s   d S(   s#   Unlock the mailbox if it is locked.N(    (   R   (    (    s   scripts/common/Lib/mailbox.pyRD   t  s    c         C   s   d S(   s   Flush and close the mailbox.N(    (   R   (    (    s   scripts/common/Lib/mailbox.pyRE   x  s    c         C   s…   g  } xx t  i |  i ƒ D]d } t | ƒ d j oK | d d j o: t  i i t  i i |  i | ƒ ƒ o | i | d ƒ q q W| S(   s   Return a list of folder names.i   i    t   .(   R   t   listdirR   R•   R   t   isdirRg   t   append(   R   R8   t   entry(    (    s   scripts/common/Lib/mailbox.pyt   list_folders|  s     $%c         C   s/   t  t i i |  i d | ƒ d |  i d t ƒS(   s/   Return a Maildir instance for the named folder.R–   R   R   (   R   R   R   Rg   R   R   R<   (   R   t   folder(    (    s   scripts/common/Lib/mailbox.pyt
   get_folder…  s    	c         C   s‡   t  i i |  i d | ƒ } t | d |  i ƒ} t  i i | d ƒ } t  i i | ƒ p* t  i t  i | t  i	 t  i
 Bd ƒ ƒ n | S(   s>   Create a folder and return a Maildir instance representing it.R–   R   t   maildirfolderi¶  (   R   R   Rg   R   R   R   Re   RE   RŠ   t   O_CREATt   O_WRONLY(   R   Rœ   R   R8   t   maildirfolder_path(    (    s   scripts/common/Lib/mailbox.pyt
   add_folder‹  s    c         C   sª  t  i i |  i d | ƒ } xz t  i t  i i | d ƒ ƒ t  i t  i i | d ƒ ƒ D]> } t | ƒ d j  p | d d j o t d | ƒ ‚ qW qW Wxz t  i | ƒ D]i } | d j oV | d j oI | d j o< t  i i t  i i | | ƒ ƒ o t d | | f ƒ ‚ q© q© Wx€ t  i | d	 t	 ƒD]i \ } } } x* | D]" } t  i
 t  i i | | ƒ ƒ qBWx* | D]" } t  i t  i i | | ƒ ƒ qoWq,Wt  i | ƒ d
 S(   s-   Delete the named folder, which must be empty.R–   Rc   Rd   i   i    s   Folder contains message(s): %sRb   s%   Folder contains subdirectory '%s': %st   topdownN(   R   R   Rg   R   R—   R•   t   NotEmptyErrorR˜   t   walkR<   R    t   rmdir(   R   Rœ   R   Rš   t   roott   dirst   files(    (    s   scripts/common/Lib/mailbox.pyt   remove_folder•  s*     $ '"    $c         C   s…   t  i  ƒ  } xr t i t i i |  i d ƒ ƒ D]O } t i i |  i d | ƒ } | t i i | ƒ d j o t i | ƒ q. q. Wd S(   s   Delete old files in "tmp".Rb   i@ú N(   t   timeR   R—   R   Rg   R   Rz   R    (   R   t   nowRš   R   (    (    s   scripts/common/Lib/mailbox.pyt   clean¨  s    " i   c         C   sU  t  i  ƒ  } t i ƒ  } d | j o | i d d ƒ } n d | j o | i d d ƒ } n d t | ƒ t | d d ƒ t i ƒ  t i | f } t i	 i
 |  i d | ƒ } y t i | ƒ Wn~ t j
 or } | i t i j oS t i d 7_ y t | ƒ SWq<t j
 o# } | i t i j o ‚  q5q<XqA‚  n Xt d	 | ƒ ‚ d
 S(   s=   Create a file in the tmp subdirectory and open and return it.t   /s   \057Ra   s   \072s   %s.M%sP%sQ%s.%si   g    €„.ARb   s&   Name clash prevented file creation: %sN(   R«   t   sockett   gethostnameRP   t   intR   t   getpidR   t   _countR   Rg   R   t   statRu   Rv   Rƒ   t   _create_carefullyRw   Rx   (   R   R¬   t   hostnameR   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRl   ²  s,    &c         C   s±   h  |  _  x¡ d D]™ } t i i |  i | ƒ } xx t i | ƒ D]g } t i i | | ƒ } t i i | ƒ o q> n | i |  i ƒ d } t i i | | ƒ |  i  | <q> Wq Wd S(   s!   Update table of contents mapping.Rc   Rd   i    N(   s   news   cur(	   Ri   R   R   Rg   R   R—   R˜   Rs   Ro   (   R   R}   t   subdir_pathRš   t   pR   (    (    s   scripts/common/Lib/mailbox.pyR”   Î  s    	  c         C   s•   y< t  i i t  i i |  i |  i | ƒ ƒ o |  i | SWn t j
 o n X|  i ƒ  y |  i | SWn# t j
 o t d | ƒ ‚ n Xd S(   s=   Use TOC to return subpath for given key, or raise a KeyError.s   No message with key: %sN(   R   R   Re   Rg   R   Ri   R"   R”   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR‚   Ú  s    ,
c         C   sw   t  |  d ƒ p |  i ƒ  |  _ n xM t oE y |  |  i i ƒ  SWq& t j
 o d St j
 o
 q& q& Xq& Wd S(   s0   Return the next message in a one-time iteration.t   _onetime_keysN(   R;   R+   R¹   R=   t   nextt   StopIterationR`   R"   (   R   (    (    s   scripts/common/Lib/mailbox.pyRº   è  s     (    R]   R^   R_   Ro   t   rfc822R   R=   R   R   R    R#   R$   R(   R*   R)   R+   R4   R6   RB   RC   RD   RE   R›   R�   R¢   Rª   R­   R³   Rl   R”   R‚   Rº   (    (    (    s   scripts/common/Lib/mailbox.pyR   ß   s6   	"							
										
					t   _singlefileMailboxc           B   s§   e  Z d  Z d e 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 RS(   s   A single-file mailbox.c         C   sí   t  i |  | | | ƒ y t |  i d ƒ } Wn„ t j
 ox } | i t i j o0 | o t |  i d ƒ } q® t |  i ƒ ‚ q³ | i t i j o t |  i d ƒ } q³ ‚  n X| |  _	 d |  _ d |  _ t |  _ t |  _ d |  _ d S(   s!   Initialize a single-file mailbox.s   rb+s   wb+R’   i    N(   R   R   RŠ   R   t   IOErrorRv   Rƒ   Rh   t   EACCESt   _fileR`   Ri   t	   _next_keyR<   t   _pendingt   _lockedt   _file_length(   R   R   R   R   R�   R�   (    (    s   scripts/common/Lib/mailbox.pyR   ø  s"    					c         C   sF   |  i  ƒ  |  i | ƒ |  i |  i <|  i d 7_ t |  _ |  i d S(   s$   Add message and return assigned key.i   (   R‚   t   _append_messageRi   RÁ   R=   RÂ   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR     s
    
	c         C   s$   |  i  | ƒ |  i | =t |  _ d S(   s=   Remove the keyed message; raise KeyError if it doesn't exist.N(   R‚   Ri   R=   RÂ   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR      s    
c         C   s0   |  i  | ƒ |  i | ƒ |  i | <t |  _ d S(   s>   Replace the keyed message; raise KeyError if it doesn't exist.N(   R‚   RÅ   Ri   R=   RÂ   (   R   R   R   (    (    s   scripts/common/Lib/mailbox.pyR$     s    c         c   s-   |  i  ƒ  x |  i i ƒ  D] } | Vq Wd S(   s   Return an iterator over keys.N(   R‚   Ri   R-   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR+   "  s    
 c         C   s   |  i  ƒ  | |  i j S(   s9   Return True if the keyed message exists, False otherwise.(   R‚   Ri   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR4   (  s    
c         C   s   |  i  ƒ  t |  i ƒ S(   s*   Return a count of messages in the mailbox.(   R‚   R•   Ri   (   R   (    (    s   scripts/common/Lib/mailbox.pyR6   -  s    
c         C   s(   |  i  p t |  i ƒ t |  _  n d S(   s   Lock the mailbox.N(   RÃ   t
   _lock_fileRÀ   R=   (   R   (    (    s   scripts/common/Lib/mailbox.pyRC   2  s    
c         C   s(   |  i  o t |  i ƒ t |  _  n d S(   s#   Unlock the mailbox if it is locked.N(   RÃ   t   _unlock_fileRÀ   R<   (   R   (    (    s   scripts/common/Lib/mailbox.pyRD   8  s    
c   
      C   s�  |  i  p d S|  i d j	 p t ‚ |  i i d d ƒ |  i i ƒ  } | |  i j o t d |  i | f ƒ ‚ n t	 |  i
 ƒ } yì h  } |  i | ƒ xÒ t |  i i ƒ  ƒ D]» } |  i | \ } } |  i i | ƒ |  i | ƒ | i ƒ  } xS t oK |  i i t d | |  i i ƒ  ƒ ƒ } | d j o Pn | i | ƒ qõ W| | i ƒ  f | | <|  i | ƒ q° WWn$ | i ƒ  t i | i ƒ ‚  n Xt | ƒ |  i i ƒ  y t i | i |  i
 ƒ Wnx t j
 ol }	 |	 i t i j p# t i d j o= |	 i t i j o* t i |  i
 ƒ t i | i |  i
 ƒ qC‚  n Xt |  i
 d ƒ |  _ | |  _ t |  _  |  i  o t! |  i d	 t ƒn d S(
   s"   Write any pending changes to disk.Ni    i   s4   Size of mailbox file changed (expected %i, found %i)i   RG   t   os2s   rb+t   dotlock("   RÂ   Ri   R`   t   AssertionErrorRÀ   RN   t   tellRÄ   Rx   t   _create_temporaryR   t   _pre_mailbox_hookt   sortedR-   t   _pre_message_hookR=   RF   t   minRO   t   _post_message_hookRE   R   R    Rr   Rm   Rt   Ru   Rv   Rw   R¿   RŠ   R<   RÃ   RÆ   (
   R   t   cur_lent   new_filet   new_tocR   t   startt   stopt	   new_startRY   R�   (    (    s   scripts/common/Lib/mailbox.pyRB   >  s\    
  

#		
c         C   s   d S(   s,   Called before writing the mailbox to file f.N(    (   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRÍ   x  s    c         C   s   d S(   s-   Called before writing each message to file f.N(    (   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRÏ   |  s    c         C   s   d S(   s,   Called after writing each message to file f.N(    (   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRÑ   €  s    c         C   s3   |  i  ƒ  |  i o |  i ƒ  n |  i i ƒ  d S(   s   Flush and close the mailbox.N(   RB   RÃ   RD   RÀ   RE   (   R   (    (    s   scripts/common/Lib/mailbox.pyRE   „  s    

c         C   sh   |  i  d j o |  i ƒ  n | d j	 o9 y |  i  | SWqd t j
 o t d | ƒ ‚ qd Xn d S(   s'   Return (start, stop) or raise KeyError.s   No message with key: %sN(   Ri   R`   t   _generate_tocR"   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR‚   ‹  s    c         C   se   |  i  i d d ƒ |  i |  i  ƒ |  i | ƒ } |  i |  i  ƒ |  i  i ƒ  |  i  i ƒ  |  _ | S(   s;   Append message to mailbox and return (start, stop) offsets.i    i   (   RÀ   RN   RÏ   t   _install_messageRÑ   RB   RË   RÄ   (   R   R   t   offsets(    (    s   scripts/common/Lib/mailbox.pyRÅ   •  s    N(   R]   R^   R_   R`   R=   R   R   R    R$   R+   R4   R6   RC   RD   RB   RÍ   RÏ   RÑ   RE   R‚   RÅ   (    (    (    s   scripts/common/Lib/mailbox.pyR½   õ  s"   									:				
t	   _mboxMMDFc           B   s>   e  Z d  Z e Z d „  Z e d „ Z e d „ Z d „  Z	 RS(   s   An mbox or MMDF mailbox.c         C   s•   |  i  | ƒ \ } } |  i i | ƒ |  i i ƒ  i t i d ƒ } |  i i | |  i i ƒ  ƒ } |  i	 | i t i d ƒ ƒ } | i
 | d ƒ | S(   s4   Return a Message representation or raise a KeyError.RG   s   
i   (   R‚   RÀ   RN   RS   RP   R   RQ   RF   RË   t   _message_factoryt   set_from(   R   R   RÕ   RÖ   t	   from_linet   stringR‘   (    (    s   scripts/common/Lib/mailbox.pyR(   ¦  s    c         C   so   |  i  | ƒ \ } } |  i i | ƒ | p |  i i ƒ  n |  i i | |  i i ƒ  ƒ } | i t i d ƒ S(   s3   Return a string representation or raise a KeyError.s   
(	   R‚   RÀ   RN   RS   RF   RË   RP   R   RQ   (   R   R   t   from_RÕ   RÖ   Rß   (    (    s   scripts/common/Lib/mailbox.pyR*   °  s    c         C   sY   |  i  | ƒ \ } } |  i i | ƒ | p |  i i ƒ  n t |  i |  i i ƒ  | ƒ S(   s6   Return a file-like representation or raise a KeyError.(   R‚   RÀ   RN   RS   t   _PartialFileRË   (   R   R   Rà   RÕ   RÖ   (    (    s   scripts/common/Lib/mailbox.pyR)   ¹  s
    c         C   s:  d } t | t ƒ oX | i d ƒ oH | i d ƒ } | d j o | |  } | | d } q¸ | } d } nK t | t ƒ o d | i ƒ  } n' t | t i i	 ƒ o | i
 ƒ  } n | d j o d t i t i ƒ  ƒ } n |  i i ƒ  } |  i i | t i ƒ |  i | |  i |  i ƒ |  i i ƒ  } | | f S(   s1   Format a message and blindly write to self._file.s   From s   
iÿÿÿÿi   RG   s   From MAILER-DAEMON %sN(   R`   RH   RR   RT   t   findt   _mboxMMDFMessaget   get_fromRI   R   R   t   get_unixfromR«   t   asctimet   gmtimeRÀ   RË   RO   R   RQ   R\   t   _mangle_from_(   R   R   RÞ   t   newlineRÕ   RÖ   (    (    s   scripts/common/Lib/mailbox.pyRÙ   Á  s&     

(
   R]   R^   R_   R=   Rè   R(   R<   R*   R)   RÙ   (    (    (    s   scripts/common/Lib/mailbox.pyRÛ   ¡  s   	
	c           B   s5   e  Z d  Z e Z d e d „ Z d „  Z d „  Z RS(   s   A classic mbox mailbox.c         C   s#   t  |  _ t i |  | | | ƒ d S(   s   Initialize an mbox mailbox.N(   R	   RÜ   RÛ   R   (   R   R   R   R   (    (    s   scripts/common/Lib/mailbox.pyR   Þ  s    	c         C   s+   | i  ƒ  d j o | i t i ƒ n d S(   s-   Called before writing each message to file f.i    N(   RË   RO   R   RQ   (   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRÏ   ã  s    c         C   s  g  g  } } |  i  i d ƒ x¡ t o™ |  i  i ƒ  } |  i  i ƒ  } | i d ƒ oH t | ƒ t | ƒ j  o | i | t t i	 ƒ ƒ n | i | ƒ q  | d j o | i | ƒ Pq  q  Wt
 t t | | ƒ ƒ ƒ |  _ t |  i ƒ |  _ |  i  i ƒ  |  _ d S(   s0   Generate key-to-(start, stop) table of contents.i    s   From RG   N(   RÀ   RN   R=   RË   RS   RT   R•   R™   R   RQ   t   dictt	   enumeratet   zipRi   RÁ   RÄ   (   R   t   startst   stopst   line_posR[   (    (    s   scripts/common/Lib/mailbox.pyRØ   è  s      
N(	   R]   R^   R_   R=   Rè   R`   R   RÏ   RØ   (    (    (    s   scripts/common/Lib/mailbox.pyR   Ù  s
   	c           B   s8   e  Z d  Z d e d „ Z d „  Z d „  Z d „  Z RS(   s   An MMDF mailbox.c         C   s#   t  |  _ t i |  | | | ƒ d S(   s   Initialize an MMDF mailbox.N(   R   RÜ   RÛ   R   (   R   R   R   R   (    (    s   scripts/common/Lib/mailbox.pyR   þ  s    	c         C   s   | i  d t i ƒ d S(   s-   Called before writing each message to file f.s   N(   RO   R   RQ   (   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRÏ     s    c         C   s   | i  t i d t i ƒ d S(   s,   Called after writing each message to file f.s   N(   RO   R   RQ   (   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRÑ     s    c         C   sn  g  g  } } |  i  i d ƒ d } xï t oç | } |  i  i ƒ  } |  i  i ƒ  } | i d t i ƒ o– | i | ƒ x˜ t oz | } |  i  i ƒ  } |  i  i ƒ  } | d t i j o | i | t	 t i ƒ ƒ Pqx | d j o | i | ƒ Pqx qx Wq& | d j o Pq& q& Wt
 t t | | ƒ ƒ ƒ |  _ t	 |  i ƒ |  _ |  i  i d d ƒ |  i  i ƒ  |  _ d S(   s0   Generate key-to-(start, stop) table of contents.i    s   RG   i   N(   RÀ   RN   R=   RS   RË   RT   R   RQ   R™   R•   Rê   Rë   Rì   Ri   RÁ   RÄ   (   R   Rí   Rî   t   next_posRï   R[   (    (    s   scripts/common/Lib/mailbox.pyRØ     s6      
N(	   R]   R^   R_   R`   R=   R   RÏ   RÑ   RØ   (    (    (    s   scripts/common/Lib/mailbox.pyR   û  s
   		c           B   sÚ   e  Z d  Z d e 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 „  Z d „  Z d „  Z d „  Z RS(   s   An MH mailbox.c         C   s©   t  i |  | | | ƒ t i i |  i ƒ pp | oV t i |  i d ƒ t i t i t i i	 |  i d ƒ t i
 t i Bt i Bd ƒ ƒ qœ t |  i ƒ ‚ n t |  _ d S(   s   Initialize an MH instance.iÀ  s   .mh_sequencesi€  N(   R   R   R   R   Re   R   Rf   RE   RŠ   Rg   RŸ   t   O_EXCLR    Rh   R<   RÃ   (   R   R   R   R   (    (    s   scripts/common/Lib/mailbox.pyR   +  s    !"c      	   C   så   |  i  ƒ  } t | ƒ d j o
 d } n t | ƒ d } t i i |  i t | ƒ ƒ } t | ƒ } zp |  i	 o t
 | ƒ n z8 |  i | | ƒ t | t ƒ o |  i | | ƒ n Wd |  i	 o t | ƒ n XWd t | ƒ X| S(   s$   Add message and return assigned key.i    i   N(   R-   R•   t   maxR   R   Rg   R   RR   Rµ   RÃ   RÆ   R\   RH   R
   t   _dump_sequencesRÇ   Rm   (   R   R   R-   t   new_keyRˆ   R�   (    (    s   scripts/common/Lib/mailbox.pyR   7  s"    


c         C   sð   t  i i |  i t | ƒ ƒ } y t | d ƒ } Wn? t j
 o3 } | i t i j o t	 d | ƒ ‚ qs ‚  n Xzk |  i
 o t | ƒ n z3 | i ƒ  t  i t  i i |  i t | ƒ ƒ ƒ Wd |  i
 o t | ƒ n XWd | i ƒ  Xd S(   s=   Remove the keyed message; raise KeyError if it doesn't exist.s   rb+s   No message with key: %sN(   R   R   Rg   R   RR   RŠ   R¾   Rv   Rƒ   R"   RÃ   RÆ   RE   R    RÇ   (   R   R   R   R�   R�   (    (    s   scripts/common/Lib/mailbox.pyR    N  s     

)
c         C   s  t  i i |  i t | ƒ ƒ } y t | d ƒ } Wn? t j
 o3 } | i t i j o t	 d | ƒ ‚ qs ‚  n Xz“ |  i
 o t | ƒ n z[ t  i t  i | t  i t  i Bƒ ƒ |  i | | ƒ t | t ƒ o |  i | | ƒ n Wd |  i
 o t | ƒ n XWd t | ƒ Xd S(   s>   Replace the keyed message; raise KeyError if it doesn't exist.s   rb+s   No message with key: %sN(   R   R   Rg   R   RR   RŠ   R¾   Rv   Rƒ   R"   RÃ   RÆ   RE   R    t   O_TRUNCR\   RH   R
   Ró   RÇ   Rm   (   R   R   R   R   R�   R�   (    (    s   scripts/common/Lib/mailbox.pyR$   d  s$    
#
c         C   s=  y` |  i  o+ t t i i |  i t | ƒ ƒ d ƒ } n( t t i i |  i t | ƒ ƒ d ƒ } Wn? t j
 o3 } | i t i	 j o t
 d | ƒ ‚ q¢ ‚  n XzH |  i  o t | ƒ n z t | ƒ } Wd |  i  o t | ƒ n XWd | i ƒ  Xx> |  i ƒ  i ƒ  D]* \ } } | | j o | i | ƒ qqW| S(   s4   Return a Message representation or raise a KeyError.s   r+R‰   s   No message with key: %sN(   RÃ   RŠ   R   R   Rg   R   RR   R¾   Rv   Rƒ   R"   RÆ   R
   RÇ   RE   t   get_sequencesR2   t   add_sequence(   R   R   R�   R�   R‘   Rr   t   key_list(    (    s   scripts/common/Lib/mailbox.pyR(   |  s*    
++

 c         C   sú   y` |  i  o+ t t i i |  i t | ƒ ƒ d ƒ } n( t t i i |  i t | ƒ ƒ d ƒ } Wn? t j
 o3 } | i t i	 j o t
 d | ƒ ‚ q¢ ‚  n XzF |  i  o t | ƒ n z | i ƒ  SWd |  i  o t | ƒ n XWd | i ƒ  Xd S(   s3   Return a string representation or raise a KeyError.s   r+R‰   s   No message with key: %sN(   RÃ   RŠ   R   R   Rg   R   RR   R¾   Rv   Rƒ   R"   RÆ   RF   RÇ   RE   (   R   R   R�   R�   (    (    s   scripts/common/Lib/mailbox.pyR*   —  s     
++

c         C   sw   y+ t  t i i |  i t | ƒ ƒ d ƒ } Wn? t j
 o3 } | i t i j o t	 d | ƒ ‚ qm ‚  n Xt
 | ƒ S(   s6   Return a file-like representation or raise a KeyError.R’   s   No message with key: %s(   RŠ   R   R   Rg   R   RR   R¾   Rv   Rƒ   R"   R“   (   R   R   R�   R�   (    (    s   scripts/common/Lib/mailbox.pyR)   ®  s    +c         C   s&   t  t d „  t i |  i ƒ Dƒ ƒ ƒ S(   s   Return an iterator over keys.c         s   s0   x) |  ]" } | i  ƒ  o t | ƒ Vq q Wd  S(   N(   t   isdigitR±   (   t   .0Rš   (    (    s   scripts/common/Lib/mailbox.pys	   <genexpr>»  s   	 (   t   iterRÎ   R   R—   R   (   R   (    (    s   scripts/common/Lib/mailbox.pyR+   ¹  s    c         C   s(   t  i i t  i i |  i t | ƒ ƒ ƒ S(   s9   Return True if the keyed message exists, False otherwise.(   R   R   Re   Rg   R   RR   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR4   ¾  s    c         C   s   t  t |  i ƒ  ƒ ƒ S(   s*   Return a count of messages in the mailbox.(   R•   R,   R+   (   R   (    (    s   scripts/common/Lib/mailbox.pyR6   Â  s    c         C   sL   |  i  p> t t i i |  i d ƒ d ƒ |  _ t |  i ƒ t |  _  n d S(   s   Lock the mailbox.s   .mh_sequencess   rb+N(	   RÃ   RŠ   R   R   Rg   R   RÀ   RÆ   R=   (   R   (    (    s   scripts/common/Lib/mailbox.pyRC   Æ  s    
$c         C   s;   |  i  o- t |  i ƒ t |  i ƒ |  ` t |  _  n d S(   s#   Unlock the mailbox if it is locked.N(   RÃ   RÇ   RÀ   Rm   R<   (   R   (    (    s   scripts/common/Lib/mailbox.pyRD   Í  s
    
c         C   s   d S(   s&   Write any pending changes to the disk.N(    (   R   (    (    s   scripts/common/Lib/mailbox.pyRB   Õ  s    c         C   s   |  i  o |  i ƒ  n d S(   s   Flush and close the mailbox.N(   RÃ   RD   (   R   (    (    s   scripts/common/Lib/mailbox.pyRE   Ù  s    
c         C   s]   g  } xP t  i |  i ƒ D]< } t  i i t  i i |  i | ƒ ƒ o | i | ƒ q q W| S(   s   Return a list of folder names.(   R   R—   R   R   R˜   Rg   R™   (   R   R8   Rš   (    (    s   scripts/common/Lib/mailbox.pyR›   Þ  s     %c         C   s+   t  t i i |  i | ƒ d |  i d t ƒS(   s+   Return an MH instance for the named folder.R   R   (   R   R   R   Rg   R   R   R<   (   R   Rœ   (    (    s   scripts/common/Lib/mailbox.pyR�   æ  s    c         C   s%   t  t i i |  i | ƒ d |  i ƒS(   s:   Create a folder and return an MH instance representing it.R   (   R   R   R   Rg   R   R   (   R   Rœ   (    (    s   scripts/common/Lib/mailbox.pyR¢   ë  s    c         C   sŒ   t  i i |  i | ƒ } t  i | ƒ } | d g j o  t  i t  i i | d ƒ ƒ n% | g  j o n t d |  i ƒ ‚ t  i | ƒ d S(   s-   Delete the named folder, which must be empty.s   .mh_sequencess   Folder not empty: %sN(   R   R   Rg   R   R—   R    R¤   R¦   (   R   Rœ   R   t   entries(    (    s   scripts/common/Lib/mailbox.pyRª   ð  s     c         C   s€  h  } t  t i i |  i d ƒ d ƒ } zGt |  i ƒ  ƒ } x.| D]&} yô | i d ƒ \ } } t ƒ  } xq | i ƒ  D]c } | i ƒ  o | i	 t
 | ƒ ƒ qw d „  | i d ƒ Dƒ \ }	 }
 | i t |	 |
 d ƒ ƒ qw Wg  } t | ƒ D] } | | j o | | qï qï ~ | | <t | | ƒ d j o | | =n WqC t j
 o t d | i ƒ  ƒ ‚ qC XqC WWd	 | i ƒ  X| S(
   s=   Return a name-to-key-list dictionary to define each sequence.s   .mh_sequencesR‰   Ra   c         s   s   x |  ] } t  | ƒ Vq Wd  S(   N(   R±   (   Rú   t   x(    (    s   scripts/common/Lib/mailbox.pys	   <genexpr>
  s   	 t   -i   i    s"   Invalid sequence specification: %sN(   RŠ   R   R   Rg   R   t   setR-   Rs   Rù   R   R±   RA   t   rangeRÎ   R•   t
   ValueErrort   FormatErrort   rstripRE   (   R   t   resultsR�   t   all_keysR[   Rr   t   contentsR-   t   specRÕ   RÖ   t   _[1]R   (    (    s   scripts/common/Lib/mailbox.pyRö   ü  s0    ! 	 %c      	   C   so  t  t i i |  i d ƒ d ƒ } z<t i t i  | i t i t i Bƒ ƒ x| i	 ƒ  D]\ } } t
 | ƒ d j o qW n | i d | ƒ d
 } t } xŒ t t | ƒ ƒ D]x } | d | j o" | p t } | i d ƒ qn: | o! t } | i d | | f ƒ n | i d | ƒ | } q­ W| o | i t | ƒ d	 ƒ qW | i d	 ƒ qW WWd
 t | ƒ Xd
 S(   s:   Set sequences using the given name-to-key-list dictionary.s   .mh_sequencess   r+i    s   %s:i   Rþ   s   %s %ss    %ss   
N(   RŠ   R   R   Rg   R   RE   Rr   R    Rõ   R2   R•   RO   R`   R<   RÎ   Rÿ   R=   RR   Rm   (   R   t	   sequencesR�   Rr   R-   t   prevt
   completingR   (    (    s   scripts/common/Lib/mailbox.pyt   set_sequences  s2    !&  
c   	      C   s´  |  i  ƒ  } d } g  } x|  i ƒ  D]ý } | d | j oÜ | i | | d f ƒ t t d ƒ om t i t i i |  i t	 | ƒ ƒ t i i |  i t	 | d ƒ ƒ ƒ t i
 t i i |  i t	 | ƒ ƒ ƒ qt i t i i |  i t	 | ƒ ƒ t i i |  i t	 | d ƒ ƒ ƒ n | d 7} q% W| d |  _ t | ƒ d j o d SxU | i ƒ  D]G \ } } x8 | D]0 \ } } | | j o | | | i | ƒ <qkqkWqXW|  i | ƒ d S(   s?   Re-name messages to eliminate numbering gaps. Invalidates keys.i    i   Rk   N(   Rö   R+   R™   R;   R   Rk   R   Rg   R   RR   t   unlinkRt   RÁ   R•   R3   t   indexR  (	   R   R	  R
  t   changesR   Rr   Rø   t   oldRc   (    (    s   scripts/common/Lib/mailbox.pyt   pack4  s0     !#)!'  c         C   s´   | i  ƒ  } |  i  ƒ  } xY | i ƒ  D]K \ } } | | j o | i | ƒ q% | | j o | | i | ƒ =q% q% Wx, | D]$ } | | j o | g | | <q{ q{ W|  i | ƒ d S(   s;   Inspect a new MHMessage and update sequences appropriately.N(   Rö   R2   R™   R  R  (   R   R   R   t   pending_sequencest   all_sequencesRr   Rø   t   sequence(    (    s   scripts/common/Lib/mailbox.pyRó   M  s      N(   R]   R^   R_   R`   R=   R   R   R    R$   R(   R*   R)   R+   R4   R6   RC   RD   RB   RE   R›   R�   R¢   Rª   Rö   R  R  Ró   (    (    (    s   scripts/common/Lib/mailbox.pyR   (  s.   																				c           B   s•   e  Z d  Z e d ƒ Z d e 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   An Rmail-style Babyl mailbox.t   unseent   deletedt   filedt   answeredt	   forwardedt   editedt   resentc         C   s#   t  i |  | | | ƒ h  |  _ d S(   s   Initialize a Babyl mailbox.N(   R½   R   t   _labels(   R   R   R   R   (    (    s   scripts/common/Lib/mailbox.pyR   b  s    c         C   s=   t  i |  | ƒ } t | t ƒ o | i ƒ  |  i | <n | S(   s$   Add message and return assigned key.(   R½   R   RH   R   t
   get_labelsR  (   R   R   R   (    (    s   scripts/common/Lib/mailbox.pyR   g  s    c         C   s2   t  i |  | ƒ | |  i j o |  i | =n d S(   s=   Remove the keyed message; raise KeyError if it doesn't exist.N(   R½   R    R  (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR    n  s    c         C   s>   t  i |  | | ƒ t | t ƒ o | i ƒ  |  i | <n d S(   s>   Replace the keyed message; raise KeyError if it doesn't exist.N(   R½   R$   RH   R   R  R  (   R   R   R   (    (    s   scripts/common/Lib/mailbox.pyR$   t  s    c   	      C   s‰  |  i  | ƒ \ } } |  i i | ƒ |  i i ƒ  t i ƒ  } x] t oU |  i i ƒ  } | d t i j p | d j o Pn | i | i	 t i d ƒ ƒ qA Wt i ƒ  } xY t oQ |  i i ƒ  } | t i j p | d j o Pn | i | i	 t i d ƒ ƒ q­ W|  i i
 | |  i i ƒ  ƒ i	 t i d ƒ } t | i ƒ  | ƒ } | i | i ƒ  ƒ | |  i j o | i |  i | ƒ n | S(   s4   Return a Message representation or raise a KeyError.s   *** EOOH ***RG   s   
(   R‚   RÀ   RN   RS   RJ   R=   R   RQ   RO   RP   RF   RË   R   t   getvaluet   set_visibleR  t
   set_labels(	   R   R   RÕ   RÖ   t   original_headersR[   t   visible_headerst   bodyR‘   (    (    s   scripts/common/Lib/mailbox.pyR(   z  s0     !! !%	c         C   s  |  i  | ƒ \ } } |  i i | ƒ |  i i ƒ  t i ƒ  } x] t oU |  i i ƒ  } | d t i j p | d j o Pn | i | i	 t i d ƒ ƒ qA Wx= t o5 |  i i ƒ  } | t i j p | d j o Pq¡ q¡ W| i
 ƒ  |  i i | |  i i ƒ  ƒ i	 t i d ƒ S(   s3   Return a string representation or raise a KeyError.s   *** EOOH ***RG   s   
(   R‚   RÀ   RN   RS   RJ   R=   R   RQ   RO   RP   R  RF   RË   (   R   R   RÕ   RÖ   R!  R[   (    (    s   scripts/common/Lib/mailbox.pyR*   “  s$     !! 
	%c         C   s%   t  i  |  i | ƒ i d t i ƒ ƒ S(   s6   Return a file-like representation or raise a KeyError.s   
(   RJ   R*   RP   R   RQ   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR)   ¦  s    c         C   sT   |  i  ƒ  t ƒ  } x$ |  i i ƒ  D] } | i | ƒ q# W| i |  i ƒ t | ƒ S(   s4   Return a list of user-defined labels in the mailbox.(   R‚   Rÿ   R  R1   RA   t   difference_updatet   _special_labelsR,   (   R   t   labelst
   label_list(    (    s   scripts/common/Lib/mailbox.pyR  «  s    
	 c   
      C   s  g  g  } } |  i  i d ƒ d } g  } xut om| } |  i  i ƒ  } |  i  i ƒ  } | d t i j o© t | ƒ t | ƒ j  o | i | t t i ƒ ƒ n | i | ƒ g  } |  i  i ƒ  d i	 d ƒ D]* } | i
 ƒ  d j o | | i
 ƒ  qÐ qÐ ~ }	 | i |	 ƒ q, | d j p | d t i j o; t | ƒ t | ƒ j  o | i | t t i ƒ ƒ qœq, | d j o | i | t t i ƒ ƒ Pq, q, Wt t t | | ƒ ƒ ƒ |  _ t t | ƒ ƒ |  _ t |  i ƒ |  _ |  i  i d d ƒ |  i  i ƒ  |  _ d S(	   s0   Generate key-to-(start, stop) table of contents.i    s   i   t   ,RG   s   i   N(   RÀ   RN   R=   RS   RË   R   RQ   R•   R™   Rs   t   stripRê   Rë   Rì   Ri   R  RÁ   RÄ   (
   R   Rí   Rî   Rð   t   label_listsRï   R[   R  t   labelR&  (    (    s   scripts/common/Lib/mailbox.pyRØ   ´  s8      -!"
c         C   s9   | i  d t i t i d i |  i ƒ  ƒ t i f ƒ d S(   s,   Called before writing the mailbox to file f.s(   BABYL OPTIONS:%sVersion: 5%sLabels:%s%sR(  N(   RO   R   RQ   Rg   R  (   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRÍ   Ò  s    	c         C   s   | i  d t i ƒ d S(   s-   Called before writing each message to file f.s   N(   RO   R   RQ   (   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRÏ   Ø  s    c         C   s   | i  t i d ƒ d S(   s,   Called after writing each message to file f.s   N(   RO   R   RQ   (   R   R�   (    (    s   scripts/common/Lib/mailbox.pyRÑ   Ü  s    c         C   sX  |  i  i ƒ  } t | t ƒ oÖ g  } g  } xB | i ƒ  D]4 } | |  i j o | i | ƒ q8 | i | ƒ q8 W|  i  i d ƒ x" | D] } |  i  i d | ƒ q‡ W|  i  i d ƒ x& | D] } |  i  i d | d ƒ q¼ W|  i  i t i	 ƒ n |  i  i d t i	 ƒ t | t
 i i ƒ ot i ƒ  } t
 i i | t d ƒ } | i | ƒ | i d ƒ xV t oN | i ƒ  } |  i  i | i d t i	 ƒ ƒ | d j p | d	 j o PqcqcW|  i  i d
 t i	 ƒ t | t ƒ o” t i ƒ  }	 t
 i i |	 t d ƒ }
 |
 i | i ƒ  ƒ xÀ t oN |	 i ƒ  } |  i  i | i d t i	 ƒ ƒ | d j p | d	 j o PqqWng | i d ƒ xV t oN | i ƒ  } |  i  i | i d t i	 ƒ ƒ | d j p | d	 j o Pq„q„Wxbt oD | i d ƒ } | d	 j o Pn |  i  i | i d t i	 ƒ ƒ qÝWnt | t ƒ oé | i d ƒ d } | d d j o„ |  i  i | |  i d t i	 ƒ ƒ |  i  i d
 t i	 ƒ |  i  i | |  i d t i	 ƒ ƒ |  i  i | | i d t i	 ƒ ƒ q?|  i  i d
 t i	 t i	 ƒ |  i  i | i d t i	 ƒ ƒ nt | d ƒ oó | i ƒ  } t } x‹ t oƒ | i ƒ  } |  i  i | i d t i	 ƒ ƒ | d j p | d	 j o: |  i  i d
 t i	 ƒ | o t } | i | ƒ qÑPqKqKWxf t oD | i d ƒ } | d	 j o Pn |  i  i | i d t i	 ƒ ƒ qÙWn t d t | ƒ ƒ ‚ |  i  i ƒ  } | | f S(   s0   Write message contents and return (start, stop).t   1s   , s   ,,t    R(  s   1,,i    s   
RG   s   *** EOOH ***i   s   

i   iÿÿÿÿRS   s   Invalid message type: %s(   RÀ   RË   RH   R   R  R%  R™   RO   R   RQ   RI   R   R   RJ   RK   RL   R<   RM   RN   R=   RS   RP   t   get_visibleRF   RR   Râ   R;   RU   RV   (   R   R   RÕ   t   special_labelsR&  R+  t   orig_buffert   orig_generatorR[   t
   vis_buffert   vis_generatorRY   t
   body_startt   original_post
   first_passRÖ   (    (    s   scripts/common/Lib/mailbox.pyRÙ   à  s°        
  
 (# 
 ((   R  R  R  R  R  R  R  N(   R]   R^   R_   t	   frozensetR%  R`   R=   R   R   R    R$   R(   R*   R)   R  RØ   RÍ   RÏ   RÑ   RÙ   (    (    (    s   scripts/common/Lib/mailbox.pyR   \  s    													c           B   s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   s0   Message with mailbox-format-specific properties.c         C   sã   t  | t i i ƒ o; |  i t i | ƒ ƒ t  | t ƒ o | i |  ƒ qß n� t  | t ƒ o |  i t i	 | ƒ ƒ ne t
 | d ƒ o |  i t i | ƒ ƒ n; | d j o t i i i |  ƒ n t d t | ƒ ƒ ‚ d S(   s   Initialize a Message instance.RF   s   Invalid message type: %sN(   RH   RI   R   R   t   _become_messaget   copyt   deepcopyt   _explain_toRR   t   message_from_stringR;   t   message_from_fileR`   R   RU   RV   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR   <  s    c         C   s)   x" d
 D] } | i  | |  i  | <q Wd	 S(   s0   Assume the non-format-specific state of message.t   _headerst	   _unixfromt   _payloadt   _charsett   preamblet   epiloguet   defectst   _default_typeN(   R>  R?  R@  RA  RB  RC  RD  RE  (   t   __dict__(   R   R   Rr   (    (    s   scripts/common/Lib/mailbox.pyR8  K  s     c         C   s%   t  | t ƒ o d St d ƒ ‚ d S(   s:   Copy format-specific state to message insofar as possible.Ns    Cannot convert to specified type(   RH   R   RU   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR;  Q  s    N(   R]   R^   R_   R`   R   R8  R;  (    (    (    s   scripts/common/Lib/mailbox.pyR   9  s   	c           B   s}   e  Z d  Z 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 RS(   s)   Message with Maildir-specific properties.c         C   s5   d |  _  d |  _ t i ƒ  |  _ t i |  | ƒ d S(   s%   Initialize a MaildirMessage instance.Rc   RG   N(   t   _subdirt   _infoR«   t   _dateR   R   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR   \  s    		c         C   s   |  i  S(   s   Return 'new' or 'cur'.(   RG  (   R   (    (    s   scripts/common/Lib/mailbox.pyRn   c  s    c         C   s;   | d j p | d j o | |  _  n t d | ƒ ‚ d S(   s   Set subdir to 'new' or 'cur'.Rc   Rd   s!   subdir must be 'new' or 'cur': %sN(   RG  R  (   R   R}   (    (    s   scripts/common/Lib/mailbox.pyR‹   g  s    c         C   s'   |  i  i d ƒ o |  i  d Sd Sd S(   s*   Return as a string the flags that are set.s   2,i   RG   N(   RH  RT   (   R   (    (    s   scripts/common/Lib/mailbox.pyt	   get_flagsn  s    c         C   s    d d i  t | ƒ ƒ |  _ d S(   s)   Set the given flags and unset all others.s   2,RG   N(   Rg   RÎ   RH  (   R   t   flags(    (    s   scripts/common/Lib/mailbox.pyt	   set_flagsu  s    c         C   s0   |  i  d i t |  i ƒ  ƒ t | ƒ Bƒ ƒ d S(   s.   Set the given flag(s) without changing others.RG   N(   RL  Rg   Rÿ   RJ  (   R   t   flag(    (    s   scripts/common/Lib/mailbox.pyt   add_flagy  s    c         C   sG   |  i  ƒ  d j o0 |  i d i t |  i  ƒ  ƒ t | ƒ ƒ ƒ n d S(   s7   Unset the given string flag(s) without changing others.RG   N(   RJ  RL  Rg   Rÿ   (   R   RM  (    (    s   scripts/common/Lib/mailbox.pyt   remove_flag}  s    c         C   s   |  i  S(   s<   Return delivery date of message, in seconds since the epoch.(   RI  (   R   (    (    s   scripts/common/Lib/mailbox.pyR{   ‚  s    c         C   s=   y t  | ƒ |  _ Wn# t j
 o t d | ƒ ‚ n Xd S(   s9   Set delivery date of message, in seconds since the epoch.s   can't convert to float: %sN(   t   floatRI  R  RU   (   R   t   date(    (    s   scripts/common/Lib/mailbox.pyR�   †  s    c         C   s   |  i  S(   s%   Get the message's "info" as a string.(   RH  (   R   (    (    s   scripts/common/Lib/mailbox.pyRp   �  s    c         C   s7   t  | t ƒ o | |  _ n t d t | ƒ ƒ ‚ d S(   s    Set the message's "info" string.s   info must be a string: %sN(   RH   RR   RH  RU   RV   (   R   t   info(    (    s   scripts/common/Lib/mailbox.pyRŒ   ‘  s    c         C   sz  t  | t ƒ o= | i |  i ƒ  ƒ | i |  i ƒ  ƒ | i |  i ƒ  ƒ n*t  | t ƒ oÑ t	 |  i ƒ  ƒ } d | j o | i
 d ƒ n |  i ƒ  d j o | i
 d ƒ n d | j o | i
 d ƒ n d | j o | i
 d ƒ n d | j o | i
 d ƒ n | i d	 t i |  i ƒ  ƒ ƒ nIt  | t ƒ op t	 |  i ƒ  ƒ } d | j o | i d
 ƒ n d | j o | i d ƒ n d | j o | i d ƒ qvnÉ t  | t ƒ oŽ t	 |  i ƒ  ƒ } d | j o | i d
 ƒ n d | j o | i d ƒ n d | j o | i d ƒ n d | j o | i d ƒ qvn+ t  | t ƒ o n t d t | ƒ ƒ ‚ d S(   s;   Copy Maildir-specific state to message insofar as possible.t   St   RRd   t   Ot   Tt   Dt   Ft   As   MAILER-DAEMONR  t   repliedt   flaggedR  R  t   PR  s$   Cannot convert to specified type: %sN(   RH   R   RL  RJ  R‹   Rn   R�   R{   Rã   Rÿ   RN  RÝ   R«   Rç   R
   R÷   R   t	   add_labelR   RU   RV   (   R   R   RK  (    (    s   scripts/common/Lib/mailbox.pyR;  ˜  sN    #N(   R]   R^   R_   R`   R   Rn   R‹   RJ  RL  RN  RO  R{   R�   Rp   RŒ   R;  (    (    (    s   scripts/common/Lib/mailbox.pyR   Y  s   										Rã   c           B   s\   e  Z d  Z d	 d „ Z d „  Z d	 d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(
   s/   Message with mbox- or MMDF-specific properties.c         C   s|   |  i  d t ƒ t | t i i ƒ oB | i ƒ  } | d j	 o% | i d ƒ o |  i  | d ƒ qh n t i	 |  | ƒ d S(   s'   Initialize an mboxMMDFMessage instance.s   MAILER-DAEMONs   From i   N(
   RÝ   R=   RH   RI   R   R   Rå   R`   RT   R   (   R   R   t   unixfrom(    (    s   scripts/common/Lib/mailbox.pyR   Ç  s    c         C   s   |  i  S(   s    Return contents of "From " line.(   t   _from(   R   (    (    s   scripts/common/Lib/mailbox.pyRä   Ð  s    c         C   sR   | d j	 o8 | t j o t i ƒ  } n | d t i | ƒ 7} n | |  _ d S(   s>   Set "From " line, formatting and appending time_ if specified.R-  N(   R`   R=   R«   Rç   Ræ   R_  (   R   Rà   t   time_(    (    s   scripts/common/Lib/mailbox.pyRÝ   Ô  s
    c         C   s    |  i  d d ƒ |  i  d d ƒ S(   s*   Return as a string the flags that are set.t   StatusRG   s   X-Status(   R'   (   R   (    (    s   scripts/common/Lib/mailbox.pyRJ  Ü  s    c         C   s  t  | ƒ } d
 \ } } x6 d D]. } | | j o | | 7} | i | ƒ q q Wx6 d D]. } | | j o | | 7} | i | ƒ qX qX W| d i t | ƒ ƒ 7} y |  i d | ƒ Wn# t j
 o |  i d | ƒ n Xy |  i d | ƒ Wn# t j
 o |  i d | ƒ n Xd	 S(   s)   Set the given flags and unset all others.RG   RT  RU  RW  RX  RY  Ra  s   X-StatusN(   RG   RG   (   RT  RU  (   RW  RX  RY  (   Rÿ   R    Rg   RÎ   t   replace_headerR"   t
   add_header(   R   RK  t   status_flagst   xstatus_flagsRM  (    (    s   scripts/common/Lib/mailbox.pyRL  à  s*     
 
c         C   s0   |  i  d i t |  i ƒ  ƒ t | ƒ Bƒ ƒ d S(   s.   Set the given flag(s) without changing others.RG   N(   RL  Rg   Rÿ   RJ  (   R   RM  (    (    s   scripts/common/Lib/mailbox.pyRN  ö  s    c         C   sN   d |  j p d |  j o0 |  i  d i t |  i ƒ  ƒ t | ƒ ƒ ƒ n d S(   s7   Unset the given string flag(s) without changing others.Ra  s   X-StatusRG   N(   RL  Rg   Rÿ   RJ  (   R   RM  (    (    s   scripts/common/Lib/mailbox.pyRO  ú  s    c      	   C   s¯  t  | t ƒ ot |  i ƒ  ƒ } d | j o | i d ƒ n d | j o | i d ƒ n d | j o | i d ƒ n d | j o | i d ƒ n d | j o | i d ƒ n | d	 =| d
 =d i |  i ƒ  i ƒ  d ƒ } y& | i	 t
 i t i | d ƒ ƒ ƒ Wq«t t f j
 o q«Xn�t  | t ƒ o* | i |  i ƒ  ƒ | i |  i ƒ  ƒ nGt  | t ƒ o~ t |  i ƒ  ƒ } d | j o | i d ƒ n d | j o | i d ƒ n d | j o | i d ƒ n | d	 =| d
 =n¹ t  | t ƒ o~ t |  i ƒ  ƒ } d | j o | i d ƒ n d | j o | i d ƒ n d | j o | i d ƒ n | d	 =| d
 =n+ t  | t ƒ o n t d t | ƒ ƒ ‚ d S(   sA   Copy mbox- or MMDF-specific state to message insofar as possible.RU  Rd   RX  RY  RT  RS  RW  RV  t   statuss   x-statusR-  iûÿÿÿs   %a %b %d %H:%M:%S %YR  RZ  R[  R  R  s$   Cannot convert to specified type: %sN(   RH   R   Rÿ   RJ  R‹   RN  Rg   Rä   Rs   R�   t   calendart   timegmR«   t   strptimeR  t   OverflowErrorRã   RL  RÝ   R
   R÷   R   R]  R   RU   RV   (   R   R   RK  t
   maybe_date(    (    s   scripts/common/Lib/mailbox.pyR;  ÿ  s^    	N(   R]   R^   R_   R`   R   Rä   RÝ   RJ  RL  RN  RO  R;  (    (    (    s   scripts/common/Lib/mailbox.pyRã   Ä  s   						c           B   s   e  Z d  Z RS(   s&   Message with mbox-specific properties.(   R]   R^   R_   (    (    (    s   scripts/common/Lib/mailbox.pyR	   3  s   c           B   sG   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s$   Message with MH-specific properties.c         C   s   g  |  _  t i |  | ƒ d S(   s!   Initialize an MHMessage instance.N(   t
   _sequencesR   R   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR   :  s    	c         C   s   |  i  S(   s4   Return a list of sequences that include the message.(   Rl  (   R   (    (    s   scripts/common/Lib/mailbox.pyRö   ?  s    c         C   s   t  | ƒ |  _ d S(   s3   Set the list of sequences that include the message.N(   R,   Rl  (   R   R	  (    (    s   scripts/common/Lib/mailbox.pyR  C  s    c         C   sR   t  | t ƒ o( | |  i j o |  i i | ƒ qN n t d t | ƒ ƒ ‚ d S(   s8   Add sequence to list of sequences including the message.s   sequence must be a string: %sN(   RH   RR   Rl  R™   RU   RV   (   R   R  (    (    s   scripts/common/Lib/mailbox.pyR÷   G  s    c         C   s.   y |  i  i | ƒ Wn t j
 o n Xd S(   sA   Remove sequence from the list of sequences including the message.N(   Rl  R    R  (   R   R  (    (    s   scripts/common/Lib/mailbox.pyt   remove_sequenceO  s    c         C   sï  t  | t ƒ oŠ t |  i ƒ  ƒ } d | j o | i d ƒ n | i d ƒ | i d ƒ d | j o | i d ƒ n d | j o | i d ƒ qënRt  | t ƒ o} t |  i ƒ  ƒ } d | j o | i d ƒ n | i d	 ƒ d | j o | i d ƒ n d | j o | i d
 ƒ qënÅ t  | t ƒ o( x± |  i ƒ  D] } | i | ƒ qDWn� t  | t	 ƒ oR t |  i ƒ  ƒ } d | j o | i
 d ƒ n d | j o | i
 d ƒ qën+ t  | t ƒ o n t d t | ƒ ƒ ‚ d S(   s6   Copy MH-specific state to message insofar as possible.R  Rd   RS  R[  RX  RZ  RT  t   RORU  RY  R  s$   Cannot convert to specified type: %sN(   RH   R   Rÿ   Rö   R‹   RN  Rã   R
   R÷   R   R]  R   RU   RV   (   R   R   R	  R  (    (    s   scripts/common/Lib/mailbox.pyR;  V  sB     N(
   R]   R^   R_   R`   R   Rö   R  R÷   Rm  R;  (    (    (    s   scripts/common/Lib/mailbox.pyR
   7  s   				c           B   sb   e  Z d  Z d
 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z RS(   s'   Message with Babyl-specific properties.c         C   s)   g  |  _  t ƒ  |  _ t i |  | ƒ d S(   s$   Initialize an BabylMessage instance.N(   R  R   t   _visibleR   (   R   R   (    (    s   scripts/common/Lib/mailbox.pyR   €  s    	c         C   s   |  i  S(   s'   Return a list of labels on the message.(   R  (   R   (    (    s   scripts/common/Lib/mailbox.pyR  †  s    c         C   s   t  | ƒ |  _ d S(   s&   Set the list of labels on the message.N(   R,   R  (   R   R&  (    (    s   scripts/common/Lib/mailbox.pyR   Š  s    c         C   sR   t  | t ƒ o( | |  i j o |  i i | ƒ qN n t d t | ƒ ƒ ‚ d S(   s+   Add label to list of labels on the message.s   label must be a string: %sN(   RH   RR   R  R™   RU   RV   (   R   R+  (    (    s   scripts/common/Lib/mailbox.pyR]  Ž  s    c         C   s.   y |  i  i | ƒ Wn t j
 o n Xd S(   s4   Remove label from the list of labels on the message.N(   R  R    R  (   R   R+  (    (    s   scripts/common/Lib/mailbox.pyt   remove_label–  s    c         C   s   t  |  i ƒ S(   s3   Return a Message representation of visible headers.(   R   Ro  (   R   (    (    s   scripts/common/Lib/mailbox.pyR.  �  s    c         C   s   t  | ƒ |  _ d S(   s2   Set the Message representation of visible headers.N(   R   Ro  (   R   t   visible(    (    s   scripts/common/Lib/mailbox.pyR  ¡  s    c         C   s“   xI |  i  i ƒ  D]8 } | |  j o |  i  i | |  | ƒ q |  i  | =q Wx@ d D]8 } | |  j o% | |  i  j o |  | |  i  | <qS qS Wd S(	   s9   Update and/or sensibly generate a set of visible headers.t   Datet   Froms   Reply-Tot   Tot   CCt   SubjectN(   Rr  Rs  s   Reply-ToRt  Ru  Rv  (   Ro  R-   Rb  (   R   t   header(    (    s   scripts/common/Lib/mailbox.pyt   update_visible¥  s      c         C   s-  t  | t ƒ oµ t |  i ƒ  ƒ } d | j o | i d ƒ n | i d ƒ | i d ƒ d | j p d | j o | i d ƒ n d | j o | i d ƒ n d	 | j o | i d
 ƒ q)net  | t ƒ o} t |  i ƒ  ƒ } d | j o | i d ƒ n | i d ƒ d	 | j o | i d ƒ n d | j o | i d ƒ q)nØ t  | t ƒ oR t |  i ƒ  ƒ } d | j o | i d ƒ n d | j o | i d ƒ q)nv t  | t	 ƒ o; | i
 |  i ƒ  ƒ xO |  i ƒ  D] } | i | ƒ qäWn+ t  | t ƒ o n t d t | ƒ ƒ ‚ d S(   s9   Copy Babyl-specific state to message insofar as possible.R  Rd   RS  R  R  R\  R  RT  R  RV  Rn  RU  RW  RY  RZ  s$   Cannot convert to specified type: %sN(   RH   R   Rÿ   R  R‹   RN  Rã   R
   R÷   R   R  R.  R]  R   RU   RV   (   R   R   R&  R+  (    (    s   scripts/common/Lib/mailbox.pyR;  °  sH     N(   R]   R^   R_   R`   R   R  R   R]  Rp  R.  R  Rx  R;  (    (    (    s   scripts/common/Lib/mailbox.pyR   }  s   							c           B   s   e  Z d  Z RS(   s&   Message with MMDF-specific properties.(   R]   R^   R_   (    (    (    s   scripts/common/Lib/mailbox.pyR   Ú  s   R“   c           B   sn   e  Z d  Z d d „ Z d d „ Z d d „ Z d d „ Z d „  Z d „  Z	 d d „ Z
 d	 „  Z d
 „  Z RS(   s   A read-only wrapper of a file.c         C   s6   | |  _  | d j o | i ƒ  |  _ n
 | |  _ d S(   s   Initialize a _ProxyFile.N(   RÀ   R`   RË   t   _pos(   R   R�   t   pos(    (    s   scripts/common/Lib/mailbox.pyR   á  s    	c         C   s   |  i  | |  i i ƒ S(   s   Read bytes.(   t   _readRÀ   RF   (   R   t   size(    (    s   scripts/common/Lib/mailbox.pyRF   é  s    c         C   s   |  i  | |  i i ƒ S(   s   Read a line.(   R{  RÀ   RS   (   R   R|  (    (    s   scripts/common/Lib/mailbox.pyRS   í  s    c         C   s[   g  } xN |  D]F } | i  | ƒ | d j	 o& | t | ƒ 8} | d j o PqS q q W| S(   s   Read multiple lines.i    N(   R™   R`   R•   (   R   t   sizehintR8   R[   (    (    s   scripts/common/Lib/mailbox.pyt	   readlinesñ  s     c         C   s   t  |  i d ƒ S(   s   Iterate over lines.RG   (   Rû   RS   (   R   (    (    s   scripts/common/Lib/mailbox.pyR0   ü  s    c         C   s   |  i  S(   s   Return the position.(   Ry  (   R   (    (    s   scripts/common/Lib/mailbox.pyRË      s    i    c         C   sM   | d j o |  i  i |  i ƒ n |  i  i | | ƒ |  i  i ƒ  |  _ d S(   s   Change position.i   N(   RÀ   RN   Ry  RË   (   R   t   offsett   whence(    (    s   scripts/common/Lib/mailbox.pyRN     s    c         C   s
   |  `  d S(   s   Close the file.N(   RÀ   (   R   (    (    s   scripts/common/Lib/mailbox.pyRE     s    c         C   sL   | d j o
 d } n |  i i |  i ƒ | | ƒ } |  i i ƒ  |  _ | S(   s"   Read size bytes using read_method.iÿÿÿÿN(   R`   RÀ   RN   Ry  RË   (   R   R|  t   read_methodR8   (    (    s   scripts/common/Lib/mailbox.pyR{    s    
N(   R]   R^   R_   R`   R   RF   RS   R~  R0   RË   RN   RE   R{  (    (    (    s   scripts/common/Lib/mailbox.pyR“   Þ  s   			Rá   c           B   s;   e  Z d  Z d d d „ Z d „  Z d d „ Z d „  Z RS(   s&   A read-only wrapper of part of a file.c         C   s)   t  i |  | | ƒ | |  _ | |  _ d S(   s   Initialize a _PartialFile.N(   R“   R   t   _startt   _stop(   R   R�   RÕ   RÖ   (    (    s   scripts/common/Lib/mailbox.pyR     s    	c         C   s   t  i |  ƒ |  i S(   s*   Return the position with respect to start.(   R“   RË   R‚  (   R   (    (    s   scripts/common/Lib/mailbox.pyRË   "  s    i    c         C   s]   | d j o |  i  |  _ d } n$ | d j o |  i |  _ d } n t i |  | | ƒ d S(   s8   Change position, possibly with respect to start or stop.i    i   i   N(   R‚  Ry  Rƒ  R“   RN   (   R   R  R€  (    (    s   scripts/common/Lib/mailbox.pyRN   &  s    

c         C   sf   |  i  |  i } | d j o d S| d j p | d j  p | | j o
 | } n t i |  | | ƒ S(   s;   Read size bytes using read_method, honoring start and stop.i    RG   N(   Rƒ  Ry  R`   R“   R{  (   R   R|  R�  t	   remaining(    (    s   scripts/common/Lib/mailbox.pyR{  0  s    '
N(   R]   R^   R_   R`   R   RË   RN   R{  (    (    (    s   scripts/common/Lib/mailbox.pyRá     s
   	
c         C   s  t  } yºt op y t i |  t i t i Bƒ Wq€ t j
 o? } | i t i t i f j o t	 d |  i
 ƒ ‚ q| ‚  q€ Xn | o8y! t |  i
 d ƒ } | i ƒ  Wn0 t j
 o$ } | i t i j o d S‚  n Xyh t t d ƒ o4 t i | i
 |  i
 d ƒ t } t i | i
 ƒ n! t i | i
 |  i
 d ƒ t } Wq¿t j
 oi } | i t i j p# t i
 d j o: | i t i j o' t i | i
 ƒ t	 d |  i
 ƒ ‚ q»‚  q¿Xn WnG t o t i |  t i ƒ n | o t i |  i
 d ƒ n ‚  n Xd S(   s(   Lock file f using lockf and dot locking.s   lockf: lock unavailable: %ss   .lockNRk   RÈ   s   dot lock unavailable: %s(   R<   t   fcntlt   lockft   LOCK_EXt   LOCK_NBR¾   Rv   t   EAGAINR¿   Rx   Rr   RÌ   RE   R;   R   Rk   R=   R  Rt   Ru   Rw   R    t   LOCK_UN(   R�   RÉ   t   dotlock_doneR�   t   pre_lock(    (    s   scripts/common/Lib/mailbox.pyRÆ   :  sL    
#c         C   sT   t  o t  i |  t  i ƒ n t i i |  i d ƒ o t i |  i d ƒ n d S(   s*   Unlock file f using lockf and dot locking.s   .lockN(   R…  R†  RŠ  R   R   Re   Rr   R    (   R�   (    (    s   scripts/common/Lib/mailbox.pyRÇ   g  s    c         C   sL   t  i |  t  i t  i Bt  i Bd ƒ } z t |  d ƒ SWd t  i | ƒ Xd S(   sC   Create a file if it doesn't exist and open for reading and writing.i¶  s   rb+N(   R   RŠ   RŸ   Rñ   t   O_RDWRRE   (   R   t   fd(    (    s   scripts/common/Lib/mailbox.pyRµ   n  s    &c         C   s2   t  d |  t t i ƒ  ƒ t i ƒ  t i ƒ  f ƒ S(   sB   Create a temp file based on path and open for reading and writing.s   %s.%s.%s.%s(   Rµ   R±   R«   R¯   R°   R   R²   (   R   (    (    s   scripts/common/Lib/mailbox.pyRÌ   v  s    	c         C   s5   |  i  ƒ  t t d ƒ o t i |  i ƒ  ƒ n d S(   s0   Ensure changes to file f are physically on disk.t   fsyncN(   RB   R;   R   R�  t   fileno(   R�   (    (    s   scripts/common/Lib/mailbox.pyt   _sync_flush|  s    
c         C   s   t  |  ƒ |  i ƒ  d S(   s:   Close file f, ensuring all changes are physically on disk.N(   R‘  RE   (   R�   (    (    s   scripts/common/Lib/mailbox.pyRm   ‚  s    
t   _Mailboxc           B   s)   e  Z e i d  „ Z d „  Z d „  Z RS(   c         C   s   | |  _  d |  _ | |  _ d  S(   Ni    (   t   fpt   seekpR   (   R   R“  R   (    (    s   scripts/common/Lib/mailbox.pyR   Ž  s    		c         C   s   t  |  i d  ƒ S(   N(   Rû   Rº   R`   (   R   (    (    s   scripts/common/Lib/mailbox.pyR0   “  s    c         C   s­   xŽ |  i  i |  i ƒ y |  i ƒ  Wn& t j
 o |  i  i ƒ  |  _ d  SX|  i  i ƒ  } |  i ƒ  |  i  i ƒ  |  _ } | | j o Pq q |  i t	 |  i  | | ƒ ƒ S(   N(
   R“  RN   R”  t   _search_startt   EOFErrorRË   R`   t   _search_endR   Rá   (   R   RÕ   RÖ   (    (    s   scripts/common/Lib/mailbox.pyRº   –  s    
(   R]   R^   R¼   R   R   R0   Rº   (    (    (    s   scripts/common/Lib/mailbox.pyR’  Œ  s   	c           B   s>   e  Z d  „  Z d „  Z d Z d Z d „  Z d „  Z e Z	 RS(   c         C   so   xh |  i  i ƒ  } |  i  i ƒ  } | p
 t ‚ n | d  d j o% |  i | ƒ o |  i  i | ƒ d  Sq d  S(   Ni   s   From (   R“  RË   RS   R–  t   _isrealfromlineRN   (   R   Rz  R[   (    (    s   scripts/common/Lib/mailbox.pyR•  ¨  s    
!c         C   sw   |  i  i ƒ  xc |  i  i ƒ  } |  i  i ƒ  } | p d  S| d  d j o% |  i | ƒ o |  i  i | ƒ d  Sq d  S(   Ni   s   From (   R“  RS   RË   R˜  RN   (   R   Rz  R[   (    (    s   scripts/common/Lib/mailbox.pyR—  ²  s    !sa   From \s*[^\s]+\s+\w\w\w\s+\w\w\w\s+\d?\d\s+\d?\d:\d\d(:\d\d)?(\s+[^\s]+)?\s+\d\d\d\d\s*[^\s]*\s*$c         C   s?   |  i  p% d d  k } | i |  i ƒ |  _  n |  i  i | ƒ S(   Niÿÿÿÿ(   t   _regexpt   ret   compilet   _fromlinepatternt   match(   R   R[   Rš  (    (    s   scripts/common/Lib/mailbox.pyt   _strict_isrealfromlineÜ  s    
c         C   s   t  S(   N(   R=   (   R   R[   (    (    s   scripts/common/Lib/mailbox.pyt   _portable_isrealfromlineâ  s    N(
   R]   R^   R•  R—  Rœ  R`   R™  Rž  RŸ  R˜  (    (    (    s   scripts/common/Lib/mailbox.pyR   ¦  s   	
	$		c           B   s   e  Z e i Z RS(    (   R]   R^   R   RŸ  R˜  (    (    (    s   scripts/common/Lib/mailbox.pyR   è  s   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s@   x9 |  i  i ƒ  } | p
 t ‚ n | d  d j o d  Sq d  S(   Ni   s   
(   R“  RS   R–  (   R   R[   (    (    s   scripts/common/Lib/mailbox.pyR•  î  s    
c         C   sV   xO |  i  i ƒ  } |  i  i ƒ  } | p d  S| d j o |  i  i | ƒ d  Sq d  S(   Ns   
(   R“  RË   RS   RN   (   R   Rz  R[   (    (    s   scripts/common/Lib/mailbox.pyR—  ö  s    (   R]   R^   R•  R—  (    (    (    s   scripts/common/Lib/mailbox.pyR   ì  s   	c           B   s)   e  Z e i d  „ Z d „  Z d „  Z RS(   c         C   s�   d d  k  } | i d ƒ } | |  _ t i |  i ƒ } t | i | ƒ } t t | ƒ } | i	 ƒ  t t
 | ƒ |  _ |  i i ƒ  | |  _ d  S(   Niÿÿÿÿs   ^[1-9][0-9]*$(   Rš  R›  Rj   R   R—   t   filterR�  t   mapt   longt   sortRR   t   boxest   reverseR   (   R   Rj   R   Rš  t   patR,   (    (    s   scripts/common/Lib/mailbox.pyR     s    	
c         C   s   t  |  i d  ƒ S(   N(   Rû   Rº   R`   (   R   (    (    s   scripts/common/Lib/mailbox.pyR0     s    c         C   sx   |  i  p d  S|  i  i ƒ  } t t i i |  i | ƒ ƒ } |  i | ƒ } y | | _	 Wn t
 t f j
 o n X| S(   N(   R¤  R`   R9   RŠ   R   R   Rg   Rj   R   t	   _mh_msgnot   AttributeErrorRU   (   R   t   fnR“  R‘   (    (    s   scripts/common/Lib/mailbox.pyRº     s    
(   R]   R^   R¼   R   R   R0   Rº   (    (    (    s   scripts/common/Lib/mailbox.pyR     s   	c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s<   x5 |  i  i ƒ  } | p
 t ‚ n | d j o d  Sq d  S(   Ns   *** EOOH ***
(   R“  RS   R–  (   R   R[   (    (    s   scripts/common/Lib/mailbox.pyR•  %  s    
c         C   sc   x\ |  i  i ƒ  } |  i  i ƒ  } | p d  S| d j p | d j o |  i  i | ƒ d  Sq d  S(   Ns   
s   (   R“  RË   RS   RN   (   R   Rz  R[   (    (    s   scripts/common/Lib/mailbox.pyR—  -  s    (   R]   R^   R•  R—  (    (    (    s   scripts/common/Lib/mailbox.pyR   #  s   	t   Errorc           B   s   e  Z d  Z RS(   s"   Raised for module-specific errors.(   R]   R^   R_   (    (    (    s   scripts/common/Lib/mailbox.pyRª  :  s   Rh   c           B   s   e  Z d  Z RS(   s:   The specified mailbox does not exist and won't be created.(   R]   R^   R_   (    (    (    s   scripts/common/Lib/mailbox.pyRh   =  s   R¤   c           B   s   e  Z d  Z RS(   s>   The specified mailbox is not empty and deletion was requested.(   R]   R^   R_   (    (    (    s   scripts/common/Lib/mailbox.pyR¤   @  s   Rx   c           B   s   e  Z d  Z RS(   s)   Another process caused an action to fail.(   R]   R^   R_   (    (    (    s   scripts/common/Lib/mailbox.pyRx   C  s   R  c           B   s   e  Z d  Z RS(   s)   A file appears to have an invalid format.(   R]   R^   R_   (    (    (    s   scripts/common/Lib/mailbox.pyR  F  s   (7   R_   t   sysR   R«   Rg  R¯   Rv   R9  RI   t   email.messaget   email.generatorR¼   RJ   t   platformt   ImportErrorR…  R`   t   __all__R   R   R½   RÛ   R   R   R   R   R   R   R   Rã   R	   R
   R   R   R“   Rá   R=   RÆ   RÇ   Rµ   RÌ   R‘  Rm   R’  R   R   R   R   R   t	   ExceptionRª  Rh   R¤   Rx   R  (    (    (    s   scripts/common/Lib/mailbox.pyt   <module>   st   
	»ÿ ¬8"-ÿ 5Ý koF];!-					
B"