
>8Uc        
   @   s  d  Z  d d d d d d d d d	 d
 g
 Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 y1 e Z d d l Z d e e  k r e Z n  Wn e k
 r n Xy d d l Z Wn e k
 re Z n Xy d d l Z Wn e k
 r.e Z n Xe rny e j Z Wn& e k
 rjd d  Z d   Z n Xn  y d d l m Z Wn# e k
 rZ d d l m Z n Xd d l Td d l Td d l Td d l Td d l  Td d l! m" Z" m# Z# d d l$ Td d l% Z& d d d d d d d f Z' d d d d Z( d Z) d d f \ Z* Z+ e	 j, d   Z- e.   Z/ e0 e d! e/  Z1 e0 e d" e/  Z2 e0 e d# e/  Z3 d$ Z4 d d% >e _5 d e. f d&     YZ6 d' e j7 f d(     YZ8 d) e. f d*     YZ9 d+ e. f d,     YZ: d e. f d-     YZ; d. e j< f d/     YZ= d e. f d0     YZ> d
 e? f d1     YZ@ d e@ f d2     YZA d eA f d3     YZB d e@ f d4     YZC d eC f d5     YZD e jE d6 k re9 ZF n e: ZF d S(7   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   RetrieverSkeletoniNt   authGSSClientWrapi   c   
      C   sR  g  } |  s t  S|  j d  } | d } | d } | j d  } | | k rg t d t |     n  | s |  j   | j   k S| d k r | j d  nY | j d  s | j d  r | j t j	 |   n" | j t j	 |  j
 d d	   x$ | D] } | j t j	 |   q Wt j d
 d j |  d t j  }	 |	 j |  S(   sw   Matching according to RFC 6125, section 6.4.3
            http://tools.ietf.org/html/rfc6125#section-6.4.3
            t   .i    i   t   *s,   too many wildcards in certificate DNS name: s   [^.]+s   xn--s   \*s   [^.]*s   \As   \.s   \Z(   t   Falset   splitt   countt   getmailOperationErrort   reprt   lowert   appendt
   startswitht   ret   escapet   replacet   compilet   joint
   IGNORECASEt   match(
   t   dnt   hostnamet   max_wildcardst   patst   partst   leftmostt	   remaindert	   wildcardst   fragt   pat(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   _dnsname_matchJ   s*    

"&c         C   s[  |  s t  d   n  g  } |  j d d  } xC | D]; \ } } | d k r4 t | |  r_ d S| j |  q4 q4 W| s xc |  j d d  D]L } xC | D]; \ } } | d k r t | |  r d S| j |  q q Wq Wn  t |  d k rt d | d	 j t t |   f   n; t |  d k rKt d
 | | d f   n t d   d S(   si  Verify that *cert* (in decoded format as returned by
            SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and
            RFC 6125 rules are followed, but IP addresses are not accepted
            for *hostname*.
        
            getmailOperationError is raised on failure. On success, the function
            returns nothing.
            sy   empty or no certificate, ssl_match_hostname needs an SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIREDt   subjectAltNamet   DNSNt   subjectt
   commonNamei   s&   hostname %s doesn't match either of %ss   , s   hostname %s doesn't match %si    s=   no appropriate commonName or subjectAltName fields were found(    (    (	   t
   ValueErrort   getR&   R   t   lenR   R   t   mapR   (   t   certR   t   dnsnamest   sant   keyt   valuet   sub(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   ssl_match_hostname}   s.    	%(   t   decode_header(   R   (   t   POP3SSLR   t   tot   cct   bcct   receiveds	   resent-tos	   resent-ccs
   resent-bcci<   i   i   s
   [/\:;<>|]+i    sU   ^\s*\((?P<attributes>[^)]*)\)\s+"(?P<delimiter>[^"]+)"\s+("?)(?P<mailbox>.+?)("?)\s*$t
   EAI_NONAMEt
   EAI_NODATAt   EAI_FAILi  i   c           B   s   e  Z d  Z e Z d   Z RS(   s4   Mix-In class to do POP3 non-SSL initialization.
    c         C   s   |  j  j   y: t j |  j d |  j d  |  _ |  j |  j j  Wnn t j k
 ro } t	 d |   nI t
 j k
 r   n3 t
 j k
 r } t	 d |  j d | f   n X|  j  j d |  j t j  d  S(   Nt   servert   ports   POP error (%s)s+   error resolving name %s during connect (%s)s   POP3 connection %s established(   t   logt   tracet   poplibt   POP3t   conft   connt   setup_receivedt   sockt   error_protoR   t   sockett   timeoutt   gaierrort   ost   linesep(   t   selft   o(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   _connect   s    #(   t   __name__t
   __module__t   __doc__R   t   SSLRQ   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR      s   t   POP3_SSL_EXTENDEDc           B   s#   e  Z e d d d d d d   Z RS(   c         C   s  | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d |  _ d } d  |  _	 x t
 j |  j  |  j d t
 j  D] }	 |	 \ }
 } } } } y, t
 j
 |
 | |  |  _	 |  j	 j |  Wn; t
 j k
 r } |  j	 r |  j	 j   n  d  |  _	 qy n XPqy W|  j	 st
 j |   n  i  } |  j r=|  j | d <n  |  j rct j | d <|  j | d <n  |  j r||  j | d <n  |  j	 j d  |  _ t j |  j	 |  j |  j |  |  _ d |  _ |  j   |  _ d  S(	   Nt    s!   getaddrinfo returns an empty listi    t   ssl_versiont	   cert_reqst   ca_certst   cipherst   rb(   t   hostR@   t   keyfilet   certfileRX   RZ   t   ssl_cipherst   buffert   NoneRH   RJ   t   getaddrinfot   SOCK_STREAMt   connectt   errort   closet   sslt   CERT_REQUIREDt   makefilet   filet   wrap_sockett   sslobjt
   _debuggingt   _getrespt   welcome(   RO   R]   R@   R^   R_   RX   RZ   R`   t   msgt   rest   aft   socktypet   protot	   canonnamet   sat
   extra_args(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   __init__  sJ    																N(   RR   RS   t   POP3_SSL_PORTRb   Ry   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRV     s   	t   Py24POP3SSLinitMixInc           B   s   e  Z d  Z e 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  |  j  j   t t d  s+ t d   n  t |  j  \ } } t |  j  } t |  j  } t	 |  j  } t
 |  j  } t } y| s | s | rt } d } | r | d | | f 7} n  | r | r | d 7} n  | d |  j d j   7} n  | r!| r| d 7} n  | d | 7} n  |  j  j d	 |  j d
 |  j d | f t j  t |  j d
 |  j d | | | | |  |  _ n | r|  j  j d |  j d
 |  j d | | f t j  t j |  j d
 |  j d | |  |  _ nR |  j  j d |  j d
 |  j d f t j  t j |  j d
 |  j d  |  _ |  j |  j j  t rt r|  j j }	 |	 j t  }
 |	 j   } | rd | } n  |
 sd  } qt j |
  j   j   } n d  } d  } t r|  j d rt |  j j j   |  j d
  n  | ri| s!t  d   n  t } x# | D] } | | k r.t } q.q.W| sit  d |   qin  Wnn t j! k
 r} t  d |   nI t j" k
 r  n3 t j# k
 r} t  d |  j d
 | f   n X|  j j j$ d  |  j  j d |  j t j  d  S(   NRh   s0   SSL not supported by this installation of PythonRW   s   with keyfile %s, certfile %ss   , s   using protocol version %sRX   s   with ca_certs %ss,   establishing POP3 SSL connection to %s:%d %sR?   R@   sF   establishing POP3 SSL connection to %s:%d with keyfile %s, certfile %ss)   establishing POP3 SSL connection to %s:%ds   %s:%s:%sRZ   s3   socket ssl_fingerprints mismatch (no cert provided)s)   socket ssl_fingerprints mismatch (got %s)s   POP error (%s)s+   error resolving name %s during connect (%s)i   s   POP3 connection %s established(%   RA   RB   t   hasattrRJ   t   getmailConfigurationErrort   check_ssl_key_and_certRE   t   check_ca_certst   check_ssl_versiont   check_ssl_fingerprintst   check_ssl_ciphersR   t   Truet   upperRM   RN   RV   RF   RC   t   POP3_SSLRG   RH   Rh   t   hashlibRm   t   getpeercertt   cipherRb   t   sha256t	   hexdigestR   R5   R   RI   RK   RL   t   setblocking(   RO   R^   R_   RZ   RX   t   ssl_fingerprintsR`   t   using_extended_certs_interfaceRq   Rm   t   peercertt
   ssl_ciphert   actual_hasht   any_matchest   expected_hashRP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRQ   I  s    		&	(   RR   RS   RT   R   RU   RQ   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR{   D  s   t   Py23POP3SSLinitMixInc           B   s   e  Z d  Z e 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  |  j  j   t t d  s+ t d   n  t |  j  \ } } t |  j  } t |  j  } t	 |  j  } t
 |  j  } | s | s | s | r t d   n  y | r
|  j  j d |  j d |  j d | | f t j  t |  j d |  j d | |  |  _ nO |  j  j d |  j d |  j d f t j  t |  j d |  j d  |  _ |  j |  j j  Wn t j k
 r} t d |   na t j k
 r  nK t j k
 r} t d	 |   n& t j k
 r} t d
 |   n X|  j  j d |  j t j  d  S(   NRh   s0   SSL not supported by this installation of PythonsE   SSL extended options are 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    socket error during connect (%s)s#   socket sslerror during connect (%s)s"   POP3 SSL connection %s established(   RA   RB   R|   RJ   R}   R~   RE   R   R   R   R   RM   RN   R7   RF   RG   t   rawsockRC   RI   R   RK   RL   t   sslerror(   RO   R^   R_   RZ   RX   R   R`   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRQ     sL    	
	 (   RR   RS   RT   R   RU   RQ   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s   c           B   s   e  Z d  Z e Z d   Z RS(   s4   Mix-In class to do IMAP non-SSL initialization.
    c         C   s   |  j  j   y: t j |  j d |  j d  |  _ |  j |  j j  Wnd t j j k
 rr } t	 d |   n< t
 j k
 r   n& t
 j k
 r } t	 d |   n X|  j  j d |  j t j  d  S(   NR?   R@   s   IMAP error (%s)s    socket error during connect (%s)s   IMAP connection %s established(   RA   RB   t   imaplibt   IMAP4RE   RF   RG   RH   Rf   R   RJ   RK   RL   RM   RN   (   RO   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRQ     s    #(   RR   RS   RT   R   RU   RQ   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR      s   t   IMAP4_SSL_EXTENDEDc           B   s;   e  Z d  e j d d d d d d  Z d  e j d  Z RS(   RW   c         C   s;   | |  _  | |  _ | |  _ t j j |  | | | |  d  S(   N(   RX   RZ   R`   R   t	   IMAP4_SSLRy   (   RO   R]   R@   R^   R_   RX   RZ   R`   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRy   	  s    			c         C   s   | |  _  | |  _ t j | | f  |  _ i  } |  j rI |  j | d <n  |  j ro t j | d <|  j | d <n  |  j	 r |  j	 | d <n  t j
 |  j |  j |  j |  |  _ |  j j d  |  _ d  S(   NRX   RY   RZ   R[   R\   (   R]   R@   RJ   t   create_connectionRH   RX   RZ   Rh   Ri   R`   Rl   R^   R_   Rm   Rj   Rk   (   RO   R]   R@   Rx   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   open  s    					N(   RR   RS   R   t   IMAP4_SSL_PORTRb   Ry   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s   	c           B   s   e  Z d  Z e Z d   Z RS(   s5   Mix-In class to do IMAP over SSL initialization.
    c         C   s  |  j  j   t t d  s+ t d   n  t |  j  \ } } t |  j  } t |  j  } t	 |  j  } t
 |  j  } t } y| s | s | rt } d } | r | d | | f 7} n  | r | r | d 7} n  | d |  j d j   7} n  | r!| r| d 7} n  | d | 7} n  |  j  j d	 |  j d
 |  j d | f t j  t |  j d
 |  j d | | | | |  |  _ n | r|  j  j d |  j d
 |  j d | | f t j  t j |  j d
 |  j d | |  |  _ nR |  j  j d |  j d
 |  j d f t j  t j |  j d
 |  j d  |  _ |  j |  j j  t rt r|  j j   }	 |	 j t  }
 |	 j   } | rd | } n  |
 sd  } qt j |
  j   j   } n d  } d  } t r|  j d rt |  j j   j   |  j d
  n  | ro| s't d   n  t } x# | D] } | | k r4t } q4q4W| sot d |   qon  Wn t j  j! k
 r} t d |   n t j" k
 r  n t j# k
 r>} | d } | t$ t% f k rt& d |  j d
 | f   qd| t' k r+t( d |  j d
 | f   qdt d |   n& t j) k
 rc} t d |   n Xd |  j } | r| d | 7} n  | r| d | 7} n  | t j 7} |  j* d r|  j  j+ |  n |  j  j |  d  S(   NRh   s0   SSL not supported by this installation of PythonRW   s   with keyfile %s, certfile %ss   , s   using protocol version %sRX   s   with ca_certs %ss,   establishing IMAP SSL connection to %s:%d %sR?   R@   sF   establishing IMAP SSL connection to %s:%d with keyfile %s, certfile %ss)   establishing IMAP SSL connection to %s:%ds   %s:%s:%sRZ   s3   socket ssl_fingerprints mismatch (no cert provided)s)   socket ssl_fingerprints mismatch (got %s)s   IMAP error (%s)i    s   no address for %s (%s)s1   DNS server failure looking up address for %s (%s)s    socket error during connect (%s)s#   socket sslerror during connect (%s)s"   IMAP SSL connection %s establisheds    with fingerprint %ss    using cipher %st   fingerprint(,   RA   RB   R|   RJ   R}   R~   RE   R   R   R   R   R   R   R   RM   RN   R   RF   R   R   RG   RH   Rh   R   R   R   Rb   R   R   R   R5   R   R   Rf   RK   RL   R<   R=   t   getmailDnsLookupErrorR>   t   getmailDnsServerFailureR   t   app_optionst   info(   RO   R^   R_   RZ   RX   R   R`   R   Rq   Rm   R   R   R   R   R   RP   t   errcodet   fingerprint_message(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRQ   (  s    		
&	#	

(   RR   RS   RT   R   RU   RQ   (    (    (    s?   /usr/lib/python2.7/dist-packages/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 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 present, 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, options)
      checkconf(self)
    c         K   sr   i  |  _  i  |  _ t t j    |  _ t |  _ t |  _ t |  _ |  j	   d  |  _ t |  _ t j |  |  d  S(   N(   t   headercachet   deletedt   intt   timet	   timestampR   t#   _RetrieverSkeleton__oldmail_writtent   _RetrieverSkeleton__initializedt
   gotmsglistt   _clear_stateRb   RF   t   supports_idlet   ConfigurableBaseRy   (   RO   t   args(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRy     s    					
		c         C   sC   i  |  _  i  |  _ d |  _ i  |  _ i  |  _ i  |  _ t |  _ d  S(   N(    (   t   msgnum_by_msgidt   msgid_by_msgnumt   sorted_msgnum_msgidt   msgsizest   oldmailt   _RetrieverSkeleton__deliveredR   t   mailbox_selected(   RO   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s    						c         C   s   | j    } t |  d k r. d | |  _ nN t |  d k rT d | d  |  _ n( |  j j d t |   t |  |  _ d |  j d |  j f |  _ d  S(   Ni   s   %s:%si   s   [%s]:%ss!   unexpected peer address format %ss   %s (%s)R?   (   t   getpeernameR-   t
   remoteaddrRA   t   warnt   strRE   t   received_from(   RO   RH   t
   serveraddr(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRG     s    c         C   s   |  j  j   t |  j  S(   N(   RA   RB   R   RE   (   RO   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   __str__
  s    c         C   s   t  d   d  S(   Nt   virtual(   t   NotImplementedError(   RO   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   list_mailboxes  s    c         C   s   t  d   d  S(   NR   (   R   (   RO   t   mailbox(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   select_mailbox  s    c         C   s   |  j  j   t |  j  S(   N(   RA   RB   R-   R   (   RO   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   __len__  s    c         C   s;   |  j  j d |  |  j s, t d   n  |  j | d S(   Ns   i == %ds   not initializedi   (   RA   RB   R   R   R   (   RO   t   i(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   __getitem__  s    	c         C   s   | d  k sC t | t t f  r' | sC t d | t |  f   |  j } | d  k	 r t | t  ry | j d  } n  t j	 t
 d |  } | j d  } | d | 7} n  | S(   Ns   bad mailbox %s (%s)s   utf-8R   t   -(   Rb   t
   isinstanceR   t   unicodet   AssertionErrort   typet   oldmail_filenamet   decodeR   R4   t   STRIP_CHAR_REt   encode(   RO   R   t   filename(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   _oldmail_filename  s    	c         C   s   t  j j |  j |   S(   s<   Test whether an oldmail file exists for a specified mailbox.(   RM   t   patht   isfileR   (   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   oldmail_exists/  s    c   	      C   s  |  j  s# t d t |  j     |  j j d |  |  j |  } d |  | pU d f } y t | d  } Wn/ t k
 r |  j j d | t	 j
 f  d SXx | D] } | j   } | s d | k r q n  ys | j d d	  \ } } | j d
  d k r2| j d
  } d
 j | d | d g  } n  t |  |  j  | <Wq t k
 ry|  j j d | | t	 j
 f  q Xq W|  j j d t |  j   | t	 j
 f  |  j j d t |  j   | t	 j
 f  d S(   s^   Read contents of an oldmail file.  For POP, mailbox must be 
        explicitly None.
        s   still have %d unflushed oldmails
   mailbox=%ss   %s:%sRW   R\   s   no oldmail file for %s%sNt    i   t   /i   i    s$   skipped malformed line "%r" for %s%ss   read %i uids for %s%ss   read %i uids in total for %s%s(   R   R   R-   RA   RB   R   R   t   IOErrort   moreinfoRM   RN   t   stripR   R   R   R   R+   R   (	   RO   R   R   t   lognamet   ft   linet   msgidR   t   fields(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   read_oldmailfile3  s<     		c   
      C   s  |  j  j d |  |  j |  } d |  | p2 d f } d } d } t |  j j    j t |  j j     } y t	 |  } x| | D]t } |  j  j
 d |  |  j j | |  j  } |  j  j
 d | t j  | j d | | t j f  | d 7} q W| j   |  j  j d	 | | t j f  WnG t k
 rt}	 |  j  j d
 | |	 f t j  | ru| j   qun Xt |  _ d S(   s#   Write oldmail info to oldmail file.s
   mailbox=%ss   %s:%sRW   i    s   msgid %s ...s    timestamp %ss   %s %i%si   s   wrote %i uids for %s%ss'   failed writing oldmail file for %s (%s)N(   RA   RB   R   Rb   t	   frozensetR   t   keyst   unionR   t
   updatefilet   debugR,   R   RM   RN   t   writeRg   R   R   Rf   t   abortR   R   (
   RO   R   R   R   t   oldmailfilet   wrotet   msgidsR   t   tRP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   write_oldmailfilea  s2    
c         C   s   |  j  j   |  j   d |  j k r= t j |  j d  n t j d   t j t	 d d |  j  } t
 j j |  j d |  |  _ d  |  _ | |  _ t |  _ d  S(   NRK   R   s(   oldmail-%(server)s-%(port)i-%(username)st
   getmaildir(   RA   RB   t	   checkconfRE   RJ   t   setdefaulttimeoutRb   R   R4   R   RM   R   R   R   R   R   R   R   (   RO   t   optionsR   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt
   initialize  s    
		c         C   s0   |  j  t k	 r" |  j |  j   n  |  j   d  S(   N(   R   R   R   R   (   RO   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   quit  s    c         C   s   |  j    d S(   sp   On error conditions where you do not want modified state to be saved,
        call this before .quit().
        N(   R   (   RO   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s    c         C   s   d  |  j | <d  S(   N(   Rb   R   (   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt	   delivered  s    c         C   sK   |  j  s t d   n  | |  j k r@ |  j |  |  j | <n  |  j | S(   Ns   not initialized(   R   R   R   t   _getheaderbyid(   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt	   getheader  s
    	c         C   s%   |  j  s t d   n  |  j |  S(   Ns   not initialized(   R   R   t   _getmsgbyid(   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   getmsg  s    	c         C   sO   |  j  s t d   n  y |  j | SWn! t k
 rJ t d |   n Xd  S(   Ns   not initializeds   no such message ID %s(   R   R   R   t   KeyError(   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt
   getmsgsize  s    	c         C   s6   |  j  s t d   n  |  j |  t |  j | <d  S(   Ns   not initialized(   R   R   t   _delmsgbyidR   R   (   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   delmsg  s    	(   RR   RS   RT   Ry   R   RG   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/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  j |  |  |  j j   d  S(   N(   R	   Ry   RA   RB   (   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRy     s    c         C   s~   | d  k s t d |   |  j t k	 r> |  j |  j  n  |  j   |  j |  rg |  j |  n  | |  _ |  j   d  S(   Ns+   POP does not support mailbox selection (%s)(	   Rb   R   R   R   R   R   R   R   t   _getmsglist(   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s    
	c         C   s:   |  j  j   | |  j k r/ t d |   n  |  j | S(   Ns   no such message ID %s(   RA   RB   R   R   (   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   _getmsgnumbyid  s    c         C   s  |  j  j   y|  j j   \ } } } |  j  j d | | f t j  x	t |  D] \ } } y. | j d  d  \ } } | j
 d d  } Wn' t k
 r t d |  | f   n Xt |  } | |  j k r7|  j j d t  r|  j  j d | | f t j  |  j j |  qQt d |  | f   qV | |  j | <| |  j | <qV W|  j  j d	 t |  j j    t j  t |  j j    |  _ |  j j   \ } } } xk | D]c } t | j   d
  } t | j   d  } |  j j | d   } | d  k	 r| |  j | <qqWxx |  j j   D]g } |  j | }	 |  j |	 }
 |  j j |  r-|
 t k r-|  j  j d | t j  |  j | =q-q-WWn& t j k
 r} t d |   n Xt  |  _! d  S(   Ns   UIDL response "%s", %d octetsi   R   R   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    s#   removing vanished old message id %ssf   POP error (%s) - if your server does not support the UIDL command, use BrokenUIDLPOP3Retriever instead("   RA   RB   RF   t   uidlR   RM   RN   t	   enumerateR   Rb   R   R+   R   R   R   RE   R,   R   t   deleR   t   sortedR   t   itemsR   t   listR   R   R   t   has_keyt   VANISHED_AGERC   RI   R   R   (   RO   t   responset   msglistt   octetsR   R   t   msgnumR   t   msgsizeR   t   ageRP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s^    
c         C   s0   |  j  j   |  j |  } |  j j |  d  S(   N(   RA   RB   R   RF   R   (   RO   R   R  (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   (  s    c         C   s   |  j  j d | t j  |  j |  } |  j  j d | t j  yZ |  j j |  \ } } } |  j  j d | | f t j  t d | d g  } | SWn, t j	 k
 r } t
 d | | f   n Xd  S(   Ns   msgid %ss	   msgnum %is   RETR response "%s", %d octetst	   fromlinesRW   s+   failed to retrieve msgid %s; server said %s(   RA   R   RM   RN   R   RF   t   retrt   MessageRC   RI   t   getmailRetrievalError(   RO   R   R  R  t   linesR  Rq   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   -  s    c         C   sb   |  j  j   |  j |  } |  j j | d  \ } } } t j j   } | j t	 j
 j |   S(   Ni    (   RA   RB   R   RF   t   topt   emailt   Parsert   HeaderParsert   parsestrRM   RN   R   (   RO   R   R  R  t
   headerlistR  t   parser(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   =  s
    c         C   s  |  j  j   d	 |  _ |  j j d d   d  k rg t |  |  j d |  j d |  j |  j   |  j d <n  t j	 |  |  y|  j
   |  j d r |  j j |  j d |  j d  n. |  j j |  j d  |  j j |  j d  |  j   |  j  j d t |  j j    t j  |  j  j d |  j t j  xQ |  j j   D]@ } |  j j |  sE|  j  j d | t j  |  j | =qEqEWWn& t j k
 r} t d |   n Xd  S(
   Nt   passwordt   usernameR?   t   use_apops
   msgids: %ss   msgsizes: %ss   removing vanished message id %ss   POP error (%s)(   N(   RA   RB   Rb   t	   mailboxesRE   R,   t   get_passwordt   received_withR	   R   RQ   RF   t   apopt   usert   pass_R   R   R   R   R   RM   RN   R   R   R  RC   RI   R   (   RO   R   R   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   D  s0    	
$
c         C   st   |  j  j   t j |   |  j s' d  Sy |  j j   |  j j   Wn t j t	 j
 f k
 rf } n Xd  |  _ d  S(   N(   RA   RB   R	   R   RF   t   rsetR   RC   RI   RJ   Rf   Rb   (   RO   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   c  s    	c         C   s   t  j |   |  j j   |  j s' d  Sy |  j j   Wn? t j t j f k
 ri } t	 d |   n t
 k
 ry n Xd  |  _ d  S(   Ns   POP error (%s)(   R	   R   RA   RB   RF   RC   RI   RJ   Rf   R   t   AttributeErrorRb   (   RO   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   o  s    	(   RR   RS   RT   Ry   R   R   R   R   R   R   R   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s   				I					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   |  j  j   t j |  |  |  j d j d  d j   |  _ |  j t k r^ t	 d   n  d |  _
 yS t |  j d j d d  d  d |  _
 |  j
 d k  r t |  j d   n  Wn3 t k
 r n# t k
 r } t	 d |   n Xd  S(   Nt   envelope_recipientt   :i    sB   the %s header field does not record the envelope recipient addressi   s4   invalid envelope_recipient specification format (%s)(   RA   RB   R   R   RE   R   R   t   envrecipnamet   NOT_ENVELOPE_RECIPIENT_HEADERSR}   t   envrecipnumR   R+   t
   IndexError(   RO   R   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s$    #	
c         C   s   |  j  j   t j |  |  } i  } x_ | j   D]Q \ } } | j   } | j   } | | k rv | | j |  q2 | g | | <q2 Wy | |  j |  j	 } Wn0 t
 t f k
 r } t d |  j d   n Xt | j    | _ | S(   Ns0   envelope_recipient specified header missing (%s)R"  (   RA   RB   R   R   t   headersR   R   R   R$  R&  R   R'  R}   RE   t   address_no_bracketst	   recipient(   RO   R   Rq   t   datat   namet   valR   t   unused(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s"    (   RR   RS   RT   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/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 d   Z d   Z d   Z d   Z d d  Z d   Z RS(   s/   Base class for single-user IMAP mailboxes.
    c         K   s<   t  j |  |  |  j j   d |  _ d  |  _ t |  _ d  S(   Ni    (	   R	   Ry   RA   RB   t   gss_stepRb   t   gss_vcR   t   gssapi(   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRy     s
    		c         C   sk   t  j |   d  |  _ d  |  _ i  |  _ i  |  _ d |  _ i  |  _ g  |  _	 i  |  _
 i  |  _ i  |  _ d  S(   N(    (   R	   R   Rb   R   t   uidvalidityR   R   R   t	   _mboxuidst   _mboxuidorderR   R   t   _IMAPRetrieverBase__delivered(   RO   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s    									c         C   s4   t  j |   |  j d r0 t r0 t d   n  d  S(   Nt   use_kerberossa   cannot use kerberos authentication; Python kerberos support not installed or does not support GSS(   R	   R   RE   t   HAVE_KERBEROS_GSSR}   (   RO   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s    c         C   sB  t  s t d   n  d j t |  j d  j    } |  j t k r |  j s t	 j
 d |  j d  \ } |  _ t	 j |  j  } n  t	 j |  j |  } | t	 j k rt |  _ qnX |  j t k rt	 j |  j |  } t	 j |  j  } t	 j |  j | |  j d  } n  t	 j |  j  } | s5d } n  | j d  S(   Ns"   kerberos GSS support not availableRW   t   base64s   imap@%sR?   R  (   R7  R+   R   R   R   t
   splitlinesR/  t   GSS_STATE_STEPR0  t   kerberost   authGSSClientInitRE   t   authGSSClientResponset   authGSSClientStept   AUTH_GSS_CONTINUEt   GSS_STATE_WRAPt   authGSSClientUnwrapR
   R   (   RO   R  R+  t   rc(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   gssauth  s(    $		c         C   s@   |  j  j   | |  j k r/ t d |   n  |  j | } | S(   Ns   no such message ID %s(   RA   RB   R   R   R3  (   RO   R   t   uid(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   _getmboxuidbymsgid  s
    c         G   s  |  j  j   y" t |  j |  |   \ } } Wn; t j j k
 rl } | d k rY   qm t d |   n X| d k r t d d | | f | | f   n  | j   j	 d  r |  j  j
 d | t j  n+ |  j  j
 d d | | f | f t j  | S(   Nt   logins   IMAP error (%s)t   OKs&   IMAP error (command %s returned %s %s)s   %s %ss   login command response %ss   command %s response %s(   RA   RB   t   getattrRF   R   R   Rf   R   R   R   R   RM   RN   (   RO   t   cmdR   t   resultt   resplistRP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   _parse_imapcmdresponse  s$    " 	c         G   s   |  j  j   y |  j j | |  \ } } Wn; t j j k
 ri } | d k rV   qj t d |   n X| d k r t d d | | f | | f   n  |  j  j d d | | f | f t	 j
  | S(   NRF  s   IMAP error (%s)RG  s&   IMAP error (command %s returned %s %s)s   %s %ss   command uid %s response %s(   RA   RB   RF   RD  R   R   Rf   R   R   RM   RN   (   RO   RI  R   RJ  RK  RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   _parse_imapuidcmdresponse  s     c         C   sP  |  j  j d | t j  i  } y | | j d  d | j d  !j   } x | r| d j   d k r | d j d  r x% | r | d j	 d  r | d =q W| rP | d =qP qP n  t
 |  d k r t  n  | j d  j   } | j d  | | <qP WWn) t t f k
 r0} t d |   n X|  j  j d | t j  | S(	   Ns#   parsing attributes response line %st   (i   t   )i    t   flagss3   IMAP error (failed to parse UID response line "%s")s   got %s(   RA   RB   RM   RN   t   indext   rindexR   R   R   t   endswithR-   R+   t   popR'  R   (   RO   R   t   rR    R,  RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   _parse_imapattrresponse%  s*    )	)
	c   
      C   s   g  } d } |  j  |   } x | D] } t j |  } | sP t d |   n  | j   } | d j   } d | k r~ q" n  y$ | d j d  } | j |  Wq" t k
 r }	 t d | d   q" Xq" W| S(	   s*   List (selectable) IMAP folders in account.t   LISTs   no match for list response "%s"t
   attributess	   \NoselectR   s   imap4-utf-7s   error decoding mailbox "%s"(   RW  (	   RL  t   IMAP_LISTPARTSR   R   t	   groupdictR   R   R   t	   Exception(
   RO   R  RI  RK  t   itemt   mt   gRX  R   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   @  s&    c         C   s   |  j  j   |  j  j   |  j |  j  t |  _ d  |  _ d  |  _ i  |  _	 i  |  _
 d |  _ i  |  _ g  |  _ i  |  _ i  |  _ i  |  _ d  S(   N(    (   RF   t   expungeRg   R   R   R   Rb   R   R2  R   R   R   R3  R4  R   R   R5  (   RO   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   close_mailboxZ  s    										c         C   s  |  j  j   | |  j k s, t d |   |  j t k	 rH |  j   n  |  j   |  j |  rq |  j	 |  n  |  j  j
 d | t j  y |  j d s |  j d s |  j d r t } n t } |  j j | j d  |  \ } } | d k rt |   n  | |  _ t | d  } |  j j d	  d
 d } WnQ t j j k
 rc} t d |   n) t t f k
 r} t d |   n X|  j  j
 d | | f t j  | |  _ | |  _ |  j |  | S(   Ns   mailbox not in config (%s)s   selecting mailbox "%s"t   deletet   delete_aftert   delete_bigger_thans   imap4-utf-7t   NOit   UIDVALIDITYi   i    s   IMAP error (%s)s9   IMAP server failed to return correct SELECT response (%s)s'   select(%s) returned message count of %d(   RA   RB   R  R   R   R   R`  R   R   R   R   RM   RN   R   R   RF   t   selectR   t   getmailMailboxSelectErrorR   R  R   R   Rf   R   R'  R+   R   R2  R   (   RO   R   t	   read_onlyt   statusR   R2  RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   n  sB    
				c   
      C   su  |  j  j   y/| r |  j d d | d  } x | D] } |  j |  } | d j d d  } d |  j | f } | d |  j | <|  j j |  d  |  j
 | <t | d  |  j | <q6 Wn  xx |  j j   D]g } |  j | } |  j | } |  j j |  r | t k r |  j  j d	 | t j  |  j | =q q WWn) t j j k
 rg}	 t d
 |	   n Xt |  _ d  S(   Nt   FETCHs   1:%ds   (UID RFC822.SIZE)RD  R   R   s   %s/%ss   rfc822.sizes#   removing vanished old message id %ss   IMAP error (%s)(   RA   RB   RL  RV  R   R2  R3  R4  R   Rb   R   R   R   R   R   R   R  R  R   RM   RN   R   R   Rf   R   R   R   (
   RO   t   msgcountR  R   RU  RD  R   R   R
  RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s.    c         C   s   |  j  | S(   N(   R4  (   RO   R   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s    c         C   s   |  j  j   y |  j |  } |  j d rm |  j  j d |  j d t j  |  j d | |  j d  } n  |  j  j d | t j  |  j d | d d  } Wn) t j	 j
 k
 r } 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)(   RA   RB   RE  RE   R   RM   RN   RM  R   R   Rf   R   (   RO   R   RD  R  RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s    c         C   s  |  j  j   yv|  j |  } |  j  j d | t j  y |  j d | |  } Wn5 t j j	 t
 f k
 r } t d | | f   n Xyf y | d d } Wn t k
 r } d  } n X| s |  j  j	 d  t |  } n  t d |  } Wn# t k
 r} t d |   n X| j d	 |  j  d
 |  j j k r~|  j | |  } x- | j   D] \ }	 }
 | j |	 |
  q[Wn  | SWn) t j j	 k
 r} t
 d |   n Xd  S(   Ns    retrieving body for message "%s"Rj  s+   failed to retrieve msgid %s; server said %si    i   s   bad message from server!t
   fromstrings   failed to retrieve msgid %ss    X-getmail-retrieved-from-mailboxs
   X-GM-EXT-1s   IMAP error (%s)(   RA   RB   RE  R   RM   RN   RM  R   R   Rf   R   R  R[  Rb   R   R  t	   TypeErrort
   add_headerR   RF   t   capabilitiest   _getgmailmetadataR  (   RO   R   t   partRD  R  RP   t   sbodyRq   t   metadatat   headerR3   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   _getmsgpartbyid  s@    
	
c   	      C   s   y |  j  d | d  } Wn. t j j k
 rI } |  j j d |  i  SX| sT i  St j d | d  } | s |  j j d t |   i  S| j	   } i  } x9 d D]1 } | | k r | | r | | | d
 | <q q W| S(   s   
        Add Gmail labels and other metadata which Google exposes through an
        IMAP extension to headers in the message.
        
        See https://developers.google.com/google-apps/gmail/imap_extensions
        Rj  s#   (X-GM-LABELS X-GM-THRID X-GM-MSGID)s*   Could not fetch google imap extensions: %ssV   X-GM-THRID (?P<THRID>\d+) X-GM-MSGID (?P<MSGID>\d+) X-GM-LABELS \((?P<LABELS>.*)\) UIDi    s7   Could not parse google imap extensions. Server said: %st   LABELSt   THRIDt   MSGIDs
   X-GMAIL-%s(   Rz  R{  R|  (
   RM  R   R   Rf   RA   t   warningR   t   searchR   RZ  (	   RO   RD  Rq   R  RP   t   extt   resultsRw  R\  (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyRt    s,    	c         C   sA   |  j  j   |  j j d t  r+ d } n d } |  j | |  S(   Nt   use_peeks   (BODY.PEEK[])s   (RFC822)(   RA   RB   RE   R,   R   Ry  (   RO   R   Ru  (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   9  s
    	c         C   sA   |  j  j   |  j j d t  r+ d } n d } |  j | |  S(   NR  s   (BODY.PEEK[header])s   (RFC822[header])(   RA   RB   RE   R,   R   Ry  (   RO   R   Ru  (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   A  s
    	c         C   s  |  j  j   |  j j d d  |  _ |  j j d d   d  k r t oP |  j d r t |  |  j d |  j d |  j |  j   |  j d <n  t	 j
 |  |  y|  j  j d t j  |  j   y |  j  j d t j  |  j d rt r|  j j d	 |  j  nR |  j d
 r5|  j d |  j d |  j d  n! |  j d |  j d |  j d  WnI t j j k
 r~} t |   n% t j j k
 r} t |   n X|  j  j d t j  |  j j   \ } } | d  g k r|  j  j d  n" t | d j   j    |  j _ d |  j j k r>t |  _ d t j  d <n  |  j d k ret |  j!    |  _ n  Wn) t j j k
 r} t" d |   n Xd  S(   NR  t   INBOXR  R6  R  R?   s   trying self._connect()s
   logging int   GSSAPIt   use_cram_md5t   login_cram_md5RF  s	   logged ins.   no post-login CAPABILITY response from server
it   IDLEt   AUTHt   SELECTEDt   ALLs   IMAP error (%s)(   R  (   R  R  (   R  (#   RA   RB   RE   R,   R  Rb   R7  R  R  R	   R   RM   RN   RQ   RF   t   authenticateRC  RL  R   R   R   t   getmailLoginRefusedErrorRf   t   getmailCredentialErrort
   capabilityR   t   tupleR   R   Rs  R   R   t   CommandsR   R   (   RO   R   RP   t   typt   dat(    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR   I  sJ    
"	c         C   sg   |  j  j   t j |   |  j s' d  Sy |  j   Wn" t j j t	 j f k
 rY } n Xd  |  _ d  S(   N(   RA   RB   R	   R   RF   R   R   R   Rf   RJ   Rb   (   RO   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s    	i,  c   
      C   s  |  j  s( |  j j d  t d   n  |  j rC |  j j   } n |  j j   } i  |  j _ |  j j	 |  |  j j
 d  } |  j j   } | d
 k	 r t d |   n  |  j j d |  j j  y. d
 } t	 j	 | g g  g  |  \ } } } Wn t k
 r}	 |	 } n X| d
 k	 r1|  j j d  n- | rJ|  j j d  n |  j j d |  y3 i  |  j _ |  j j d	  |  j j d |  Wn t j j k
 r}	 t SX| r|  n  t S(   s|  Initiates IMAP's IDLE mode if the server supports it

        Waits until state of current mailbox changes, and then returns. Returns
        True if the connection still seems to be up, False otherwise.

        May throw getmailOperationError if the server refuses the IDLE setup
        (e.g. if the server does not support IDLE)

        Default timeout is 5 minutes.
        s"   IDLE not supported, so not idling
s1   IMAP4 IDLE requested, but not supported by serverR  s9   IMAP4 IDLE requested, but server refused IDLE request: %ss&   Entering IDLE mode (server says "%s")
s   IDLE mode cancelled
s   IDLE message received
s   IDLE timeout (%ds)
s   DONE
N(   R   RA   R}  R   RU   RF   Rh   RJ   t   untagged_responsesRf  t   _commandt   _get_responseRb   R   t   continuation_responset   KeyboardInterruptR   t   sendt   _command_completeR   R   Rf   R   R   (
   RO   t   folderRK   RH   t   tagR+  t   abortedt   readableR.  RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   go_idle  sH    		(
	c         C   s   |  j  j   |  j s d  Sy- |  j t k	 r9 |  j   n  |  j j   Wn4 t j j	 k
 r} } |  j  j
 d | t j  n Xt j |   d  |  _ d  S(   Ns   IMAP error during logout (%s)(   RA   RB   RF   R   R   R`  t   logoutR   R   Rf   R}  RM   RN   R	   R   Rb   (   RO   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s    	(   RR   RS   RT   Ry   R   R   RC  RE  RL  RM  RV  R   R`  R   R   R   R   Ry  Rt  R   R   R   R   R  R   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s.   											.	$			;	(			J	Bc           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   |  j  j   t j |  |  |  j d j d  d j   |  _ |  j t k r^ t	 d   n  d |  _
 yS t |  j d j d d  d  d |  _
 |  j
 d k  r t |  j d   n  Wn3 t k
 r n# t k
 r } t	 d |   n Xd  S(   NR"  R#  i    sB   the %s header field does not record the envelope recipient addressi   s4   invalid envelope_recipient specification format (%s)(   RA   RB   R   R   RE   R   R   R$  R%  R}   R&  R   R+   R'  (   RO   R   RP   (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s&    	
c   
      C   s  |  j  j   t j |  |  } i  } x| | j   D]n \ } } | j   } xS t |  D]E \ } } | j   } | | k r | | j |  qW | g | | <qW Wq2 Wy | |  j	 |  j
 } Wn0 t t f k
 r }	 t d |  j d   n Xt | j    | _ | S(   Ns0   envelope_recipient specified header missing (%s)R"  (   RA   RB   R   R   R(  R   R6   R   R   R$  R&  R   R'  R}   RE   R)  R*  (
   RO   R   Rq   R+  R,  t   encoded_valueR-  t   encodingR   R.  (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s$    (   RR   RS   RT   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyR     s   
	i  (G   RT   t   __all__t   sysRM   RJ   R   R  RC   R   R   Rf  R   R7  R;  t   dirR   t   ImportErrorRh   Rb   R   t   match_hostnameR5   R!  R&   t   email.headerR6   RP   t   email.Headert   getmailcore.compatibilityt   getmailcore.exceptionst   getmailcore.constantst   getmailcore.messaget   getmailcore.utilitiest   getmailcore._pop3sslR7   R   t   getmailcore.baseclassest   getmailcore.imap_utf7t   getmailcoreR%  R  R   R:  R@  R   RY  t   objectt   NO_OBJRH  R<   R=   R>   Rz   t   _MAXLINER   R   RV   R{   R   R    R   R   R   R   R	   R   R   R   R   t
   hexversionR   (    (    (    s?   /usr/lib/python2.7/dist-packages/getmailcore/_retrieverbases.pyt   <module>   s   	

3+





			1r: =  7=	