³ò
™›\Kc           @   sy  d  Z  d d k Z d d k Z d d d g Z d e f d „  ƒ  YZ d Z d Z d	 Z d
 Z	 e e	 Z
 d f  d „  ƒ  YZ d e f d „  ƒ  YZ e d j oÚ d d k Z e e i d ƒ Z e i ƒ  GHe i e i d ƒ e i e i d ƒ e i ƒ  e i ƒ  \ Z Z x[ e d e d ƒ D]F Z e i e ƒ \ Z Z Z d e GHx e D] Z d e GHqKWd GHqWe i ƒ  n d S(   s@   A POP3 client class.

Based on the J. Myers POP3 draft, Jan. 96
iÿÿÿÿNt   POP3t   error_protot   POP3_SSLc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.5/poplib.pyR      s    in   iã  s   s   
c           B   sõ   e  Z d  Z 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 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e i d ƒ Z d „  Z d „  Z d d „ Z RS(   sÏ  This class supports both the minimal and optional command sets.
    Arguments can be strings or integers (where appropriate)
    (e.g.: retr(1) and retr('1') both work equally well.

    Minimal Command Set:
            USER name               user(name)
            PASS string             pass_(string)
            STAT                    stat()
            LIST [msg]              list(msg = None)
            RETR msg                retr(msg)
            DELE msg                dele(msg)
            NOOP                    noop()
            RSET                    rset()
            QUIT                    quit()

    Optional Commands (some servers support these):
            RPOP name               rpop(name)
            APOP name digest        apop(name, digest)
            TOP msg n               top(msg, n)
            UIDL [msg]              uidl(msg = None)

    Raises one exception: 'error_proto'.

    Instantiate with:
            POP3(hostname, port=110)

    NB:     the POP protocol locks the mailbox from user
            authorization until QUIT, so be sure to get in, suck
            the messages, and quit, each time you access the
            mailbox.

            POP is a line-based protocol, which means large mail
            messages consume lots of python cycles reading them
            line-by-line.

            If it's available on your mail server, use IMAP4
            instead, it doesn't suffer from the two problems
            above.
    c   
      C   s  | |  _  | |  _ d } d  |  _ x­ t i |  i  |  i d t i ƒ D]Š } | \ } } } } }	 y, t i | | | ƒ |  _ |  i i |	 ƒ Wn? t i j
 o0 } |  i o |  i i	 ƒ  n d  |  _ qC n XPqC W|  i p t i | ‚ n |  i i
 d ƒ |  _ d |  _ |  i ƒ  |  _ d  S(   Ns!   getaddrinfo returns an empty listi    t   rb(   t   hostt   portt   Nonet   sockt   sockett   getaddrinfot   SOCK_STREAMt   connectt   errort   closet   makefilet   filet
   _debuggingt   _getrespt   welcome(
   t   selfR   R   t   msgt   rest   aft   socktypet   protot	   canonnamet   sa(    (    s   /usr/lib/python2.5/poplib.pyt   __init__O   s*    			" 
	
	c         C   sA   |  i  d j o d Gt | ƒ GHn |  i i d | t f ƒ d  S(   Ni   s   *put*s   %s%s(   R   t   reprR	   t   sendallt   CRLF(   R   t   line(    (    s   /usr/lib/python2.5/poplib.pyt   _putlinef   s     c         C   s.   |  i  o d Gt | ƒ GHn |  i | ƒ d  S(   Ns   *cmd*(   R   R   R"   (   R   R!   (    (    s   /usr/lib/python2.5/poplib.pyt   _putcmdm   s    
 c         C   s¬   |  i  i ƒ  } |  i d j o d Gt | ƒ GHn | p t d ƒ ‚ n t | ƒ } | d t j o | d  | f Sn | d t j o | d d !| f Sn | d  | f S(   Ni   s   *get*s   -ERR EOFiþÿÿÿi    iÿÿÿÿ(   R   t   readlineR   R   R   t   lenR    t   CR(   R   R!   t   octets(    (    s   /usr/lib/python2.5/poplib.pyt   _getlinev   s      c         C   s`   |  i  ƒ  \ } } |  i d j o d Gt | ƒ GHn | d  } | d j o t | ƒ ‚ n | S(   Ni   s   *resp*t   +(   R(   R   R   R   (   R   t   respt   ot   c(    (    s   /usr/lib/python2.5/poplib.pyR   ˆ   s     
c         C   sž   |  i  ƒ  } g  } d } |  i ƒ  \ } } xd | d j oV | d  d j o | d } | d } n | | } | i | ƒ |  i ƒ  \ } } q- W| | | f S(   Ni    t   .i   s   ..i   (   R   R(   t   append(   R   R*   t   listR'   R!   R+   (    (    s   /usr/lib/python2.5/poplib.pyt   _getlongresp“   s      

c         C   s   |  i  | ƒ |  i ƒ  S(   N(   R#   R   (   R   R!   (    (    s   /usr/lib/python2.5/poplib.pyt	   _shortcmd£   s    c         C   s   |  i  | ƒ |  i ƒ  S(   N(   R#   R0   (   R   R!   (    (    s   /usr/lib/python2.5/poplib.pyt   _longcmdª   s    c         C   s   |  i  S(   N(   R   (   R   (    (    s   /usr/lib/python2.5/poplib.pyt
   getwelcome±   s    c         C   s   | |  _  d  S(   N(   R   (   R   t   level(    (    s   /usr/lib/python2.5/poplib.pyt   set_debuglevelµ   s    c         C   s   |  i  d | ƒ S(   sV   Send user name, return response

        (should indicate password required).
        s   USER %s(   R1   (   R   t   user(    (    s   /usr/lib/python2.5/poplib.pyR6   »   s    c         C   s   |  i  d | ƒ S(   s    Send password, return response

        (response includes message count, mailbox size).

        NB: mailbox is locked by server from here to 'quit()'
        s   PASS %s(   R1   (   R   t   pswd(    (    s   /usr/lib/python2.5/poplib.pyt   pass_Ã   s    c         C   sb   |  i  d ƒ } | i ƒ  } |  i o d Gt | ƒ GHn t | d ƒ } t | d ƒ } | | f S(   s]   Get mailbox status.

        Result is tuple of 2 ints (message count, mailbox size)
        t   STATs   *stat*i   i   (   R1   t   splitR   R   t   int(   R   t   retvalt   retst   numMessagest   sizeMessages(    (    s   /usr/lib/python2.5/poplib.pyt   statÍ   s    
 c         C   s/   | d j	 o |  i d | ƒ Sn |  i d ƒ S(   s  Request listing, return result.

        Result without a message number argument is in form
        ['response', ['mesg_num octets', ...], octets].

        Result when a message number argument is given is a
        single response: the "scan listing" for that message.
        s   LIST %st   LISTN(   R   R1   R2   (   R   t   which(    (    s   /usr/lib/python2.5/poplib.pyR/   Ú   s    	c         C   s   |  i  d | ƒ S(   so   Retrieve whole message number 'which'.

        Result is in form ['response', ['line', ...], octets].
        s   RETR %s(   R2   (   R   RB   (    (    s   /usr/lib/python2.5/poplib.pyt   retrè   s    c         C   s   |  i  d | ƒ S(   sF   Delete message number 'which'.

        Result is 'response'.
        s   DELE %s(   R1   (   R   RB   (    (    s   /usr/lib/python2.5/poplib.pyt   deleð   s    c         C   s   |  i  d ƒ S(   sX   Does nothing.

        One supposes the response indicates the server is alive.
        t   NOOP(   R1   (   R   (    (    s   /usr/lib/python2.5/poplib.pyt   noopø   s    c         C   s   |  i  d ƒ S(   s   Not sure what this does.t   RSET(   R1   (   R   (    (    s   /usr/lib/python2.5/poplib.pyt   rset   s    c         C   s[   y |  i  d ƒ } Wn t j
 o } | } n X|  i i ƒ  |  i i ƒ  |  ` |  ` | S(   sD   Signoff: commit changes on server, unlock mailbox, close connection.t   QUIT(   R1   R   R   R   R	   (   R   R*   t   val(    (    s   /usr/lib/python2.5/poplib.pyt   quit  s    c         C   s   |  i  d | ƒ S(   s   Not sure what this does.s   RPOP %s(   R1   (   R   R6   (    (    s   /usr/lib/python2.5/poplib.pyt   rpop  s    s   \+OK.*(<[^>]+>)c         C   sŒ   |  i  i |  i ƒ } | p t d ƒ ‚ n d d k } | i | i d ƒ | ƒ i ƒ  } d i t	 d „  | ƒ ƒ } |  i
 d | | f ƒ S(   s   Authorisation

        - only possible if server has supplied a timestamp in initial greeting.

        Args:
                user    - mailbox user;
                secret  - secret shared between client and server.

        NB: mailbox is locked by server from here to 'quit()'
        s!   -ERR APOP not supported by serveriÿÿÿÿNi   t    c         S   s   d  t  |  ƒ S(   s   %02x(   t   ord(   t   x(    (    s   /usr/lib/python2.5/poplib.pyt   <lambda>,  s    s
   APOP %s %s(   t	   timestampt   matchR   R   t   hashlibt   md5t   groupt   digestt   joint   mapR1   (   R   R6   t   secrett   mRS   RV   (    (    s   /usr/lib/python2.5/poplib.pyt   apop  s    "c         C   s   |  i  d | | f ƒ S(   s­   Retrieve message header of message number 'which'
        and first 'howmuch' lines of message body.

        Result is in form ['response', ['line', ...], octets].
        s	   TOP %s %s(   R2   (   R   RB   t   howmuch(    (    s   /usr/lib/python2.5/poplib.pyt   top0  s    c         C   s/   | d j	 o |  i d | ƒ Sn |  i d ƒ S(   sì   Return message digest (unique id) list.

        If 'which', result contains unique id for that message
        in the form 'response mesgnum uid', otherwise result is
        the list ['response', ['mesgnum uid', ...], octets]
        s   UIDL %st   UIDLN(   R   R1   R2   (   R   RB   (    (    s   /usr/lib/python2.5/poplib.pyt   uidl9  s    N(   R   R   t   __doc__t	   POP3_PORTR   R"   R#   R(   R   R0   R1   R2   R3   R5   R6   R8   R@   R   R/   RC   RD   RF   RH   RK   RL   t   ret   compileRQ   R[   R]   R_   (    (    (    s   /usr/lib/python2.5/poplib.pyR    $   s2   (												
										c           B   sD   e  Z d  Z e d d d „ Z d „  Z d „  Z d „  Z d „  Z	 RS(   s¦  POP3 client class over SSL connection

    Instantiate with: POP3_SSL(hostname, port=995, keyfile=None, certfile=None)

           hostname - the hostname of the pop3 over ssl server
           port - port number
           keyfile - PEM formatted file that countains your private key
           certfile - PEM formatted certificate chain file

        See the methods of the parent class POP3 for more documentation.
    c         C   sX  | |  _  | |  _ | |  _ | |  _ d |  _ d } d  |  _ x­ t i |  i  |  i d t i	 ƒ D]Š } | \ } } }	 }
 } y, t i | | |	 ƒ |  _ |  i i
 | ƒ Wn? t i j
 o0 } |  i o |  i i ƒ  n d  |  _ q^ n XPq^ W|  i p t i | ‚ n |  i i d ƒ |  _ t i |  i |  i |  i ƒ |  _ d |  _ |  i ƒ  |  _ d  S(   NRM   s!   getaddrinfo returns an empty listi    R   (   R   R   t   keyfilet   certfilet   bufferR   R	   R
   R   R   R   R   R   R   R   t   sslt   sslobjR   R   R   (   R   R   R   Rd   Re   R   R   R   R   R   R   R   (    (    s   /usr/lib/python2.5/poplib.pyR   Q  s2    						" 
	
!	c         C   sE   |  i  i ƒ  } t | ƒ d j o t d ƒ ‚ n |  i | 7_ d  S(   Ni    s   -ERR EOF(   Rh   t   readR%   R   Rf   (   R   t   localbuf(    (    s   /usr/lib/python2.5/poplib.pyt   _fillBufferk  s    c         C   s  d } t  i d ƒ } | i |  i ƒ } x( | p  |  i ƒ  | i |  i ƒ } q* W| i d ƒ } | i d |  i d ƒ |  _ |  i d j o d Gt | ƒ GHn t	 | ƒ } | d t
 j o | d  | f Sn | d t j o | d d !| f Sn | d  | f S(   NRM   s   .*?\ni    i   s   *get*iþÿÿÿiÿÿÿÿ(   Rb   Rc   RR   Rf   Rk   RU   t   subR   R   R%   R    R&   (   R   R!   t	   renewlineRR   R'   (    (    s   /usr/lib/python2.5/poplib.pyR(   q  s"     
 c         C   sŠ   |  i  d j o d Gt | ƒ GHn | t 7} t | ƒ } xJ | d j o< |  i i | ƒ } | | j o Pn | | } | | } q< Wd  S(   Ni   s   *put*i    (   R   R   R    R%   Rh   t   write(   R   R!   t   bytest   sent(    (    s   /usr/lib/python2.5/poplib.pyR"   ƒ  s     
 
c         C   sN   y |  i  d ƒ } Wn t j
 o } | } n X|  i i ƒ  |  ` |  ` | S(   sD   Signoff: commit changes on server, unlock mailbox, close connection.RI   (   R1   R   R	   R   Rh   (   R   R*   RJ   (    (    s   /usr/lib/python2.5/poplib.pyRK   Ž  s    N(
   R   R   R`   t   POP3_SSL_PORTR   R   Rk   R(   R"   RK   (    (    (    s   /usr/lib/python2.5/poplib.pyR   D  s   			t   __main__i   i   i   s   Message %d:s      s   -----------------------(    R`   Rb   R
   t   __all__t	   ExceptionR   Ra   Rq   R&   t   LFR    R    R   R   t   syst   argvt   aR3   R6   R8   R/   R@   t   numMsgst	   totalSizet   ranget   iRC   t   headerR   R'   R!   RK   (    (    (    s   /usr/lib/python2.5/poplib.pys   <module>   s8   
ÿ !U
 	 	