³ò
®µGc           @   sä  d  Z  d d d d d d d d d	 d
 g
 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 Td d k Td d k Td d k Td d k l Z l Z d d k Td# Z 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 f d „  ƒ  YZ d e f d  „  ƒ  YZ d e f d! „  ƒ  YZ e i  d" j o
 e Z! n e Z! d S($   sÀ  Base and mix-in classes implementing retrievers (message sources getmail can
retrieve mail from).

None of these classes can be instantiated directly.  In this module:

Mix-in classes for SSL/non-SSL initialization:

  POP3initMixIn
  Py23POP3SSLinitMixIn
  Py24POP3SSLinitMixIn
  IMAPinitMixIn
  IMAPSSLinitMixIn

Base classes:

  RetrieverSkeleton
  POP3RetrieverBase
  MultidropPOP3RetrieverBase
  IMAPRetrieverBase
  MultidropIMAPRetrieverBase
t   IMAPinitMixInt   IMAPRetrieverBaset   IMAPSSLinitMixInt   MultidropPOP3RetrieverBaset   MultidropIMAPRetrieverBaset   POP3_ssl_portt   POP3initMixInt   POP3RetrieverBaset   POP3SSLinitMixInt   RetrieverSkeletoniÿÿÿÿN(   t   *(   t   POP3SSLR   t   tot   cct   bcct   receiveds	   resent-tos	   resent-ccs
   resent-bccc           B   s   e  Z d  Z d „  Z RS(   s4   Mix-In class to do POP3 non-SSL initialization.
    c         C   sÖ   |  i  i ƒ  y' t i |  i d |  i d ƒ |  _ Wn} t i j
 o } t d | ƒ ‚ nW t i	 j
 o t d ƒ ‚ n6 t i
 j
 o& } t d |  i d | f ƒ ‚ n X|  i  i d |  i t i ƒ d  S(   Nt   servert   ports   POP error (%s)s   timeout during connects+   error resolving name %s during connect (%s)s   POP3 connection %s established(   t   logt   tracet   poplibt   POP3t   conft   connt   error_protot   getmailOperationErrort   sockett   timeoutt   gaierrort   ost   linesep(   t   selft   o(    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _connectG   s    '(   t   __name__t
   __module__t   __doc__R!   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR   D   s   t   Py24POP3SSLinitMixInc           B   s   e  Z d  Z d „  Z RS(   sa   Mix-In class to do POP3 over SSL initialization with Python 2.4's
    poplib.POP3_SSL class.
    c      	   C   s¶  |  i  i ƒ  t t d ƒ p t d ƒ ‚ n t |  i ƒ \ } } y¿ | ob |  i  i d |  i d |  i d | | f t i ƒ t	 i
 |  i d |  i d | | ƒ |  _ nS |  i  i d |  i d |  i d f t i ƒ t	 i
 |  i d |  i d ƒ |  _ Wn} t	 i j
 o } t d | ƒ ‚ nW t i j
 o t d ƒ ‚ n6 t i j
 o& } t d	 |  i d | f ƒ ‚ n X|  i i i d
 ƒ |  i  i d |  i t i ƒ d  S(   Nt   ssls0   SSL not supported by this installation of PythonsF   establishing POP3 SSL connection to %s:%d with keyfile %s, certfile %sR   R   s)   establishing POP3 SSL connection to %s:%ds   POP error (%s)s   timeout during connects+   error resolving name %s during connect (%s)i   s   POP3 connection %s established(   R   R   t   hasattrR   t   getmailConfigurationErrort   check_ssl_key_and_certR   R   R   R   t   POP3_SSLR   R   R   R   R   t   sockt   setblocking(   R   t   keyfilet   certfileR    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR!   [   s2    '(   R"   R#   R$   R!   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR%   W   s   t   Py23POP3SSLinitMixInc           B   s   e  Z d  Z d „  Z RS(   s‰   Mix-In class to do POP3 over SSL initialization with custom-implemented
    code to support SSL with Python 2.3's poplib.POP3 class.
    c      	   C   s·  |  i  i ƒ  t t d ƒ p t d ƒ ‚ n t |  i ƒ \ } } y¹ | o_ |  i  i d |  i d |  i d | | f t i ƒ t	 |  i d |  i d | | ƒ |  _
 nP |  i  i d |  i d |  i d f t i ƒ t	 |  i d |  i d ƒ |  _
 Wn— t i j
 o } t d | ƒ ‚ nq t i j
 o t d ƒ ‚ nP t i j
 o } t d	 | ƒ ‚ n) t i j
 o } t d
 | ƒ ‚ n X|  i  i d |  i
 t i ƒ d  S(   NR&   s0   SSL not supported by this installation of PythonsF   establishing POP3 SSL connection to %s:%d with keyfile %s, certfile %sR   R   s)   establishing POP3 SSL connection to %s:%ds   POP error (%s)s   timeout during connects    socket error during connect (%s)s#   socket sslerror during connect (%s)s"   POP3 SSL connection %s established(   R   R   R'   R   R(   R)   R   R   R   R   R   R   R   R   R   R   t   sslerror(   R   R-   R.   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR!      s4    
$(   R"   R#   R$   R!   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR/   {   s   c           B   s   e  Z d  Z d „  Z RS(   s4   Mix-In class to do IMAP non-SSL initialization.
    c         C   sÌ   |  i  i ƒ  y' t i |  i d |  i d ƒ |  _ Wns t i i j
 o } t d | ƒ ‚ nJ t i	 j
 o t d ƒ ‚ n) t i
 j
 o } t d | ƒ ‚ n X|  i  i d |  i t i ƒ d  S(   NR   R   s   IMAP error (%s)s   timeout during connects    socket error during connect (%s)s   IMAP connection %s established(   R   R   t   imaplibt   IMAP4R   R   t   errorR   R   R   R   R   R   (   R   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR!   £   s    '(   R"   R#   R$   R!   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR        s   c           B   s   e  Z d  Z d „  Z RS(   s5   Mix-In class to do IMAP over SSL initialization.
    c      	   C   sÀ  |  i  i ƒ  t t d ƒ p t d ƒ ‚ n t |  i ƒ \ } } y¿ | ob |  i  i d |  i d |  i d | | f t i ƒ t	 i
 |  i d |  i d | | ƒ |  _ nS |  i  i d |  i d |  i d f t i ƒ t	 i
 |  i d |  i d ƒ |  _ Wnš t	 i i j
 o } t d | ƒ ‚ nq t i j
 o t d ƒ ‚ nP t i j
 o } t d	 | ƒ ‚ n) t i j
 o } t d
 | ƒ ‚ n X|  i  i d |  i t i ƒ d  S(   NR&   s0   SSL not supported by this installation of PythonsF   establishing IMAP SSL connection to %s:%d with keyfile %s, certfile %sR   R   s)   establishing IMAP SSL connection to %s:%ds   IMAP error (%s)s   timeout during connects    socket error during connect (%s)s#   socket sslerror during connect (%s)s"   IMAP SSL connection %s established(   R   R   R'   R   R(   R)   R   R   R   R1   t	   IMAP4_SSLR   R2   R3   R   R   R   R0   (   R   R-   R.   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR!   µ   s4    
#(   R"   R#   R$   R!   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR   ²   s   c           B   s†   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 d „ Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   s&
  Base class for implementing message-retrieval classes.

    Sub-classes should provide the following data attributes and methods:

      _confitems - a tuple of dictionaries representing the parameters the class
                   takes.  Each dictionary should contain the following key,
                   value pairs:
                     - name - parameter name
                     - type - a type function to compare the parameter value
                     against (i.e. str, int, bool)
                     - default - optional default value.  If not preseent, the
                     parameter is required.

      __str__(self) - return a simple string representing the class instance.

      _getmsglist(self) - retieve a list of all available messages, and store
                          unique message identifiers in the dict 
                          self.msgnum_by_msgid.
                          Message identifiers must be unique and persistent
                          across instantiations.  Also store message sizes (in
                          octets) in a dictionary self.msgsizes, using the
                          message identifiers as keys.

      _delmsgbyid(self, msgid) - delete a message from the message store based
                                 on its message identifier.

      _getmsgbyid(self, msgid) - retreive and return a message from the message
                                 store based on its message identifier.  The
                                 message is returned as a Message() class
                                 object. The message will have additional data
                                 attributes "sender" and "recipient".  sender
                                 should be present or "unknown".  recipient
                                 should be non-None if (and only if) the
                                 protocol/method of message retrieval preserves
                                 the original message envelope.

      _getheaderbyid(self, msgid) - similar to _getmsgbyid() above, but only the
                                 message header should be retrieved, if
                                 possible.  It should be returned in the same
                                 format.

      showconf(self) - should invoke self.log.info() to display the
                                configuration of the class instance.

    Sub-classes may also wish to extend or over-ride the following base class
    methods:

      __init__(self, **args)
      __del__(self)
      initialize(self)
      checkconf(self)
    c         K   sƒ   h  |  _  h  |  _ h  |  _ h  |  _ h  |  _ h  |  _ h  |  _ t t i ƒ  ƒ |  _	 t
 |  _ t
 |  _ t
 |  _ t i |  |  d  S(   N(   t   msgnum_by_msgidt   msgid_by_msgnumt   msgsizest   headercachet   oldmailt   deletedt   _RetrieverSkeleton__deliveredt   intt   timet	   timestampt   Falset#   _RetrieverSkeleton__oldmail_writtent   _RetrieverSkeleton__initializedt
   gotmsglistt   ConfigurableBaset   __init__(   R   t   args(    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRD     s    										c         C   s   |  i  i ƒ  |  i ƒ  d  S(   N(   R   R   t   write_oldmailfile(   R   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   __del__  s    c         C   s   |  i  i ƒ  t |  i ƒ S(   N(   R   R   t   strR   (   R   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   __str__"  s    c         C   s   |  i  i ƒ  t |  i ƒ S(   N(   R   R   t   lenR5   (   R   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   __len__&  s    c         C   sI   |  i  i d | ƒ |  i p t d ƒ ‚ n t |  i i ƒ  ƒ | d S(   Ns   i == %ds   not initializedi   (   R   R   RA   R   t   sortedR6   t   items(   R   t   i(    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   __getitem__*  s    
c         C   s÷   |  i  i ƒ  yµ x„ g  } t |  i d ƒ D]C } | i ƒ  d j o* d | j o | | i ƒ  i d d ƒ q* q* ~ D] \ } } t | ƒ |  i | <qt W|  i  i d t	 |  i ƒ |  f t
 i ƒ Wn. t j
 o" |  i  i d |  t
 i ƒ n Xd S(   s   Read contents of oldmail file.t   rbt    t    i   s   read %i uids for %ss   no oldmail file for %sN(   R   R   t   opent   oldmail_filenamet   stript   splitR<   R9   t   moreinfoRJ   R   R   t   IOError(   R   t   _[1]t   linet   msgidR>   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _read_oldmailfile0  s    
D c      	   C   s°  |  i  i ƒ  |  i p |  i p |  i o d Sn d } y%t |  i ƒ } t i |  i	 i
 ƒ  ƒ i t i |  i i
 ƒ  ƒ ƒ } x± | D]© } |  i  i d | ƒ | o. | |  i j o |  i  i d t i ƒ q‡ n |  i i | |  i ƒ } |  i  i d | t i ƒ | i d | | t i f ƒ | d 7} q‡ W| i ƒ  |  i  i d | |  f t i ƒ Wn@ t j
 o4 } |  i  i d	 |  | f t i ƒ | i ƒ  n Xt |  _ d S(
   s#   Write oldmail info to oldmail file.Ni    s   msgid %s ...s    was deleted, skippings    timestamp %ss   %s %i%si   s   wrote %i uids for %ss'   failed writing oldmail file for %s (%s)(   R   R   R@   RA   RB   t
   updatefileRT   t   setst   ImmutableSetR;   t   keyst   unionR9   t   debugR:   R   R   t   getR>   t   writet   closeRW   RX   R3   t   abortt   True(   R   t   forget_deletedt   wrotet   ft   msgidsR[   t   tR    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRF   =  s8    
 
c         C   sÚ   |  i  i ƒ  |  i ƒ  d |  i j o t i |  i d ƒ n t i d  ƒ t i i	 |  i d d |  i i
 d d ƒ i
 d d ƒ ƒ |  _ |  i ƒ  d |  i d t i |  i d d  ƒ d	 d
 d	 f |  _ t |  _ d  S(   NR   t
   getmaildirs(   oldmail-%(server)s-%(port)i-%(username)st   /t   -t   :s   %s (%s)R   i    i   (   R   R   t	   checkconfR   R   t   setdefaulttimeoutt   NoneR   t   patht   joint   replaceRT   R\   t   getaddrinfot   received_fromRg   RA   (   R   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt
   initialize^  s    
	

,c         C   s   d  |  i | <d  S(   N(   Rs   R;   (   R   R[   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt	   deliveredq  s    c         C   sO   |  i  p t d ƒ ‚ n | |  i j o |  i | ƒ |  i | <n |  i | S(   Ns   not initialized(   RA   R   R8   t   _getheaderbyid(   R   R[   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt	   getheadert  s
    
c         C   s'   |  i  p t d ƒ ‚ n |  i | ƒ S(   Ns   not initialized(   RA   R   t   _getmsgbyid(   R   R[   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   getmsg{  s    
c         C   sS   |  i  p t d ƒ ‚ n y |  i | SWn# t j
 o t d | ƒ ‚ n Xd  S(   Ns   not initializeds   no such message ID %s(   RA   R   R7   t   KeyError(   R   R[   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt
   getmsgsize€  s    
c         C   s8   |  i  p t d ƒ ‚ n |  i | ƒ t |  i | <d  S(   Ns   not initialized(   RA   R   t   _delmsgbyidRg   R:   (   R   R[   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   delmsgˆ  s    
(   R"   R#   R$   RD   RG   RI   RK   RO   R\   Rg   RF   Ry   Rz   R|   R~   R€   R‚   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR	   Ú   s   4						!					c           B   sh   e  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/   Base class for single-user POP3 mailboxes.
    c         K   s!   t  i |  |  |  i i ƒ  d  S(   N(   R	   RD   R   R   (   R   RE   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRD   ’  s    c         C   s   t  i |  ƒ d  S(   N(   R	   RG   (   R   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRG   –  s    c         C   s<   |  i  i ƒ  | |  i j o t d | ƒ ‚ n |  i | S(   Ns   no such message ID %s(   R   R   R5   R   (   R   R[   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _getmsgnumbyid™  s    c   
      C   s  |  i  i ƒ  yÐ|  i i ƒ  \ } } } |  i  i d | | f t i ƒ xý t | ƒ D]ï \ } } y | i d  d ƒ \ } } Wn) t
 j
 o t d |  | f ƒ ‚ n Xt | ƒ } | |  i j oe |  i i d t ƒ o5 |  i  i d | | f t i ƒ |  i i | ƒ qEt d |  | f ƒ ‚ qV | |  i | <| |  i | <qV W|  i  i d t |  i i ƒ  ƒ t i ƒ |  i i ƒ  \ } } } xN | D]F } t | i ƒ  d ƒ } t | i ƒ  d ƒ } | |  i |  i | <q’WWn( t i j
 o }	 t d	 |	 ƒ ‚ n Xt |  _ d  S(
   Ns   UIDL response "%s", %d octetsi   sq   %s failed to identify message index %d in UIDL output -- see documentation or use BrokenUIDLPOP3Retriever insteadt   delete_dup_msgidss+   deleting message %s with duplicate msgid %ssq   %s does not uniquely identify messages (got %s twice) -- see documentation or use BrokenUIDLPOP3Retriever insteads   Message IDs: %si    sf   POP error (%s) - if your server does not support the UIDL command, use BrokenUIDLPOP3Retriever instead(   R   R   R   t   uidlRb   R   R   t	   enumerateRV   Rs   t
   ValueErrorR   R<   R5   R   Rc   R?   t   deleR6   RL   R`   t   listR7   R   R   Rg   RB   (
   R   t   responset   msglistt   octetsRN   RZ   t   msgnumR[   t   msgsizeR    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _getmsglistŸ  sL     
 c         C   s0   |  i  i ƒ  |  i | ƒ } |  i i | ƒ d  S(   N(   R   R   Rƒ   R   Rˆ   (   R   R[   R   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR   Ñ  s    c         C   sÇ   |  i  i d | t i ƒ |  i | ƒ } |  i  i d | t i ƒ yS |  i i | ƒ \ } } } |  i  i d | | f t i ƒ t d | ƒ } | SWn( t i	 j
 o } t
 d | ƒ ‚ n Xd  S(   Ns   msgid %ss	   msgnum %is   RETR response "%s", %d octetst	   fromliness   POP error (%s)(   R   Rb   R   R   Rƒ   R   t   retrt   MessageR   R   R   (   R   R[   R   RŠ   t   linesRŒ   t   msgR    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR}   Ö  s    c         C   sb   |  i  i ƒ  |  i | ƒ } |  i i | d ƒ \ } } } t i i ƒ  } | i t	 i
 i | ƒ ƒ S(   Ni    (   R   R   Rƒ   R   t   topt   emailt   Parsert   HeaderParsert   parsestrR   R   Ru   (   R   R[   R   RŠ   t
   headerlistRŒ   t   parser(    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR{   ã  s
    c         C   sš  |  i  i ƒ  |  i i d d  ƒ d  j o t i d |  ƒ |  i d <n t i |  ƒ y|  i ƒ  |  i d o% |  i	 i
 |  i d |  i d ƒ n/ |  i	 i |  i d ƒ |  i	 i |  i d ƒ |  i ƒ  |  i  i d t |  i i ƒ  ƒ t i ƒ |  i  i d |  i t i ƒ xS |  i i ƒ  D]B } |  i i | ƒ p) |  i  i d | t i ƒ |  i | =q$q$WWn( t i j
 o } t d | ƒ ‚ n Xd  S(	   Nt   passwords   Enter password for %s:  t   use_apopt   usernames
   msgids: %ss   msgsizes: %ss   removing vanished message id %ss   POP error (%s)(   R   R   R   Rc   Rs   t   getpassR	   Ry   R!   R   t   apopt   usert   pass_R   Rb   RL   R5   R`   R   R   R7   R9   t   has_keyR   R   R   (   R   R[   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRy   ê  s.    	
%
 c         C   sY   |  i  i ƒ  y |  i i ƒ  |  i i ƒ  Wn! t i t i f j
 o	 } n X|  ` d  S(   N(	   R   R   R   t   rsett   quitR   R   R   R3   (   R   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRf     s    c         C   s–   |  i  i ƒ  |  i ƒ  t |  d d  ƒ p d  Sn y |  i i ƒ  d  |  _ WnC t i t	 i
 f j
 o } t d | ƒ ‚ n t j
 o n Xd  S(   NR   s   POP error (%s)(   R   R   RF   t   getattrRs   R   R¥   R   R   R   R3   R   t   AttributeError(   R   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR¥     s    
(   R"   R#   R$   RD   RG   Rƒ   R   R   R}   R{   Ry   Rf   R¥   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR     s   				2						c           B   s    e  Z d  Z d „  Z d „  Z RS(   s*  Base retriever class for multi-drop POP3 mailboxes.

    Envelope is reconstructed from Return-Path: (sender) and a header specified
    by the user (recipient).  This header is specified with the
    "envelope_recipient" parameter, which takes the form <field-name>[:<field-
    number>].  field-number defaults to 1 and is counted from top to bottom in
    the message.  For instance, if the envelope recipient is present in the
    second Delivered-To: header field of each message, envelope_recipient should
    be specified as "delivered-to:2".
    c         C   sù   |  i  i ƒ  t i |  ƒ |  i d i d ƒ d i ƒ  |  _ |  i t j o t	 d ƒ ‚ n d |  _
 yU t |  i d i d d ƒ d ƒ d |  _
 |  i
 d j  o t |  i d ƒ ‚ n Wn7 t j
 o n& t j
 o } t	 d | ƒ ‚ n Xd  S(   Nt   envelope_recipientRp   i    sB   the %s header field does not record the envelope recipient addressi   s4   invalid envelope_recipient specification format (%s)(   R   R   R   Ry   R   RV   t   lowert   envrecipnamet   NOT_ENVELOPE_RECIPIENT_HEADERSR(   t   envrecipnumR<   R‡   t
   IndexError(   R   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRy   (  s"    	c         C   sï   |  i  i ƒ  t i |  | ƒ } h  } xa | i ƒ  D]S \ } } | i ƒ  } | i ƒ  } | | j o | | i | ƒ q2 | g | | <q2 Wy | |  i |  i	 } Wn2 t
 t f j
 o  } t d |  i d ƒ ‚ n Xt | i ƒ  ƒ | _ | S(   Ns0   envelope_recipient specified header missing (%s)R¨   (   R   R   R   R}   t   headersR©   RU   t   appendRª   R¬   R   R­   R(   R   t   address_no_bracketst	   recipient(   R   R[   R”   t   datat   namet   valRZ   t   unused(    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR}   <  s"     (   R"   R#   R$   Ry   R}   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.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 RS(   s/   Base class for single-user IMAP mailboxes.
    c         K   s3   t  i |  |  |  i i ƒ  d  |  _ d  |  _ d  S(   N(   R	   RD   R   R   Rs   t   mailboxt   uidvalidity(   R   RE   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRD   T  s    	c         C   s   t  i |  ƒ d  S(   N(   R	   RG   (   R   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRG   Z  s    c         C   sN   |  i  i ƒ  | |  i j o t d | ƒ ‚ n |  i | \ } } | | f S(   Ns   no such message ID %s(   R   R   R5   R   t	   _mboxuids(   R   R[   R¶   t   uid(    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _getmboxuidbymsgid]  s
    c         G   sò   |  i  i ƒ  y" t |  i | ƒ | Œ  \ } } Wn+ t i i j
 o } t d | ƒ ‚ n X| d j o$ t d d | | f | f ƒ ‚ n | i ƒ  i	 d ƒ o |  i  i
 d | t i ƒ n, |  i  i
 d d | | f | f t i ƒ | S(   Ns   IMAP error (%s)t   OKs#   IMAP error (command %s returned %s)s   %s %st   logins   login command response %ss   command %s response %s(   R   R   R¦   R   R1   R2   R3   R   R©   t
   startswithRb   R   R   (   R   t   cmdRE   t   resultt   resplistR    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _parse_imapcmdresponsed  s    "c         G   sº   |  i  i ƒ  y |  i i | | Œ \ } } Wn+ t i i j
 o } t d | ƒ ‚ n X| d j o$ t d d | | f | f ƒ ‚ n |  i  i d d | | f | f t	 i
 ƒ | S(   Ns   IMAP error (%s)R»   s#   IMAP error (command %s returned %s)s   %s %ss   command uid %s response %s(   R   R   R   R¹   R1   R2   R3   R   Rb   R   R   (   R   R¾   RE   R¿   RÀ   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _parse_imapuidcmdresponset  s    c         C   s^  |  i  i d | t i ƒ h  } yð | | i d ƒ d | i d ƒ !i ƒ  } xÀ | o¸ | d i ƒ  d j oX | d i d ƒ oD x( | o  | d i	 d ƒ o | d =q… W| o | d =qP qP n t
 | ƒ d j o
 t ‚ n | i d ƒ i ƒ  } | i d ƒ | | <qP WWn+ t t f j
 o } t d | ƒ ‚ n X|  i  i d | t i ƒ | S(	   Ns#   parsing attributes response line %st   (i   t   )i    t   flagss3   IMAP error (failed to parse UID response line "%s")s   got %s(   R   R   R   R   t   indext   rindexRV   R©   R½   t   endswithRJ   R‡   t   popR­   R   (   R   RZ   t   rt   partsR³   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _parse_imapattrresponse  s.    ) + 
c         C   s0  |  i  i ƒ  | |  i j o d  Sn |  i d  j	 o |  i i ƒ  n |  i  i d | t i ƒ y@ |  i	 d | ƒ } t
 | d ƒ } |  i i d ƒ d d } WnU t i i j
 o } t d | ƒ ‚ n, t t f j
 o } t d | ƒ ‚ n X|  i  i d | | f t i ƒ | |  _ | |  _ | S(	   Ns   selecting mailbox "%s"t   SELECTi    t   UIDVALIDITYi   s   IMAP error (%s)s8   IMAP server failed to return correctSELECT response (%s)s'   select(%s) returned message count of %d(   R   R   R¶   Rs   R   Re   Rb   R   R   RÁ   R<   RŠ   R1   R2   R3   R   R­   R‡   R·   (   R   R¶   RŠ   t   countR·   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _selectmailbox›  s(    		c      
   C   s@  |  i  i ƒ  h  |  _ h  |  _ g  |  _ h  |  _ xÿ |  i d D]ð } y¼ |  i | ƒ } | o¢ |  i d d | d ƒ } x† | D]z } |  i	 | ƒ } d |  i
 | | d f } | | d f |  i | <|  i i | ƒ d  |  i | <t | d ƒ |  i | <q~ Wn Wq? t i i j
 o } t d | ƒ ‚ q? Xq? Wt |  _ d  S(	   Nt	   mailboxest   FETCHs   1:%ds   (UID RFC822.SIZE)s   %s/%s/%sR¹   s   rfc822.sizes   IMAP error (%s)(   R   R   R5   R¸   t   _mboxuidorderR7   R   RÐ   RÁ   RÌ   R·   R¯   Rs   R<   R1   R2   R3   R   Rg   RB   (   R   R¶   t   msgcountRŠ   RZ   RÊ   R[   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR   ²  s0    				 	 #c         C   s   |  i  | S(   N(   RÓ   (   R   RN   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRO   Ì  s    c         C   sè   |  i  i ƒ  y© |  i | ƒ \ } } |  i | ƒ |  i d oB |  i  i d |  i d t i ƒ |  i d | |  i d ƒ } n |  i  i d | t i ƒ |  i d | d d ƒ } Wn+ t	 i
 i j
 o } t d | ƒ ‚ n Xd  S(	   Nt   move_on_deletes   copying message to folder "%s"t   COPYs   deleting message "%s"t   STOREt   FLAGSs
   (\Deleted)s   IMAP error (%s)(   R   R   Rº   RÐ   R   Rb   R   R   RÂ   R1   R2   R3   R   (   R   R[   R¶   R¹   RŠ   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR   Ï  s    c         C   s°   |  i  i ƒ  yq |  i | ƒ \ } } |  i | ƒ |  i  i d | t i ƒ |  i d | | ƒ } t d | d d ƒ } | SWn+ t	 i
 i j
 o } t d | ƒ ‚ n Xd  S(   Ns    retrieving body for message "%s"RÒ   t
   fromstringi    i   s   IMAP error (%s)(   R   R   Rº   RÐ   Rb   R   R   RÂ   R’   R1   R2   R3   R   (   R   R[   t   partR¶   R¹   RŠ   R”   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyt   _getmsgpartbyidà  s    c         C   s   |  i  i ƒ  |  i | d ƒ S(   Ns   (RFC822)(   R   R   RÛ   (   R   R[   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR}   ù  s    c         C   s   |  i  i ƒ  |  i | d ƒ S(   Ns   (RFC822[header])(   R   R   RÛ   (   R   R[   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR{   ý  s    c         C   sÕ  |  i  i ƒ  |  i i d d  ƒ d  j o t i d |  ƒ |  i d <n t i |  ƒ yO|  i  i d t i	 ƒ |  i
 ƒ  |  i  i d t i	 ƒ |  i d o% |  i d |  i d |  i d ƒ n" |  i d |  i d |  i d ƒ |  i  i d	 t i	 ƒ |  i ƒ  |  i  i d
 t |  i i ƒ  ƒ t i	 ƒ |  i  i d |  i t i	 ƒ xS |  i i ƒ  D]B } |  i i | ƒ p) |  i  i d | t i	 ƒ |  i | =q\q\WWn+ t i i j
 o } t d | ƒ ‚ n Xd  S(   NRœ   s   Enter password for %s:  s   trying self._connect()s
   logging int   use_cram_md5t   login_cram_md5Rž   R¼   s   logged in, getting message lists
   msgids: %ss   msgsizes: %ss   removing vanished message id %ss   IMAP error (%s)(   R   R   R   Rc   Rs   RŸ   R	   Ry   R   R   R!   RÁ   R   Rb   RL   R5   R`   R7   R9   R£   R1   R2   R3   R   (   R   R[   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRy     s6    	
	
 c         C   sF   |  i  i ƒ  y |  i ƒ  Wn$ t i i t i f j
 o	 } n Xd  S(   N(   R   R   R¥   R1   R2   R3   R   (   R   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRf      s
    c         C   s–   |  i  i ƒ  |  i ƒ  t |  d d  ƒ p d  Sn y' |  i i ƒ  |  i i ƒ  d  |  _ Wn6 t i	 i
 j
 o$ } |  i  i d | t i ƒ n Xd  S(   NR   s   IMAP error during logout (%s)(   R   R   RF   R¦   Rs   R   Re   t   logoutR1   R2   R3   t   warningR   R   (   R   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR¥   '  s    
(   R"   R#   R$   RD   RG   Rº   RÁ   RÂ   RÌ   RÐ   R   RO   R   RÛ   R}   R{   Ry   Rf   R¥   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR   Q  s"   															c           B   s    e  Z d  Z d „  Z d „  Z RS(   s*  Base retriever class for multi-drop IMAP mailboxes.

    Envelope is reconstructed from Return-Path: (sender) and a header specified
    by the user (recipient).  This header is specified with the
    "envelope_recipient" parameter, which takes the form <field-name>[:<field-
    number>].  field-number defaults to 1 and is counted from top to bottom in
    the message.  For instance, if the envelope recipient is present in the
    second Delivered-To: header field of each message, envelope_recipient should
    be specified as "delivered-to:2".
    c         C   sù   |  i  i ƒ  t i |  ƒ |  i d i d ƒ d i ƒ  |  _ |  i t j o t	 d ƒ ‚ n d |  _
 yU t |  i d i d d ƒ d ƒ d |  _
 |  i
 d j  o t |  i d ƒ ‚ n Wn7 t j
 o n& t j
 o } t	 d | ƒ ‚ n Xd  S(   NR¨   Rp   i    sB   the %s header field does not record the envelope recipient addressi   s4   invalid envelope_recipient specification format (%s)(   R   R   R   Ry   R   RV   R©   Rª   R«   R(   R¬   R<   R‡   R­   (   R   R    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyRy   A  s"    	c         C   sï   |  i  i ƒ  t i |  | ƒ } h  } xa | i ƒ  D]S \ } } | i ƒ  } | i ƒ  } | | j o | | i | ƒ q2 | g | | <q2 Wy | |  i |  i	 } Wn2 t
 t f j
 o  } t d |  i d ƒ ‚ n Xt | i ƒ  ƒ | _ | S(   Ns0   envelope_recipient specified header missing (%s)R¨   (   R   R   R   R}   R®   R©   RU   R¯   Rª   R¬   R   R­   R(   R   R°   R±   (   R   R[   R”   R²   R³   R´   RZ   Rµ   (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR}   U  s"     (   R"   R#   R$   Ry   R}   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pyR   5  s   
	i  (   R   R   R   R   s	   resent-tos	   resent-ccs
   resent-bcc("   R$   t   __all__t   sysR   R   R=   RŸ   R–   R   R1   R^   t   getmailcore.exceptionst   getmailcore.constantst   getmailcore.messaget   getmailcore.utilitiest   getmailcore._pop3sslR   R   t   getmailcore.baseclassesR«   t   objectR   R%   R/   R    R   RC   R	   R   R   R   R   t
   hexversionR   (    (    (    s2   /usr/share/getmail4/getmailcore/_retrieverbases.pys   <module>   sZ   	




      $%(µ5ä6
