Ńň
mČKc           @   sŠ  d  Z  d d k Z d d k Z d d g Z d e f d     YZ d Z d Z d Z d	 Z	 e e	 Z
 d f  d
     YZ y d d k Z Wn e j
 o n% Xd e f d     YZ e i d  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! GHq{Wd GHqMWe i"   n d S(   s@   A POP3 client class.

Based on the J. Myers POP3 draft, Jan. 96
i˙˙˙˙Nt   POP3t   error_protoc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.6/poplib.pyR      s    in   iă  s   s   
c           B   sű   e  Z d  Z e e i 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^   | |  _  | |  _ t i | | f |  |  _ |  i i d  |  _ d |  _ |  i   |  _	 d  S(   Nt   rbi    (
   t   hostt   portt   sockett   create_connectiont   sockt   makefilet   filet
   _debuggingt   _getrespt   welcome(   t   selfR   R   t   timeout(    (    s   /usr/lib/python2.6/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.6/poplib.pyt   _putlineY   s     c         C   s.   |  i  o d Gt |  GHn |  i |  d  S(   Ns   *cmd*(   R   R   R   (   R   R   (    (    s   /usr/lib/python2.6/poplib.pyt   _putcmd`   s    
 c         C   sŚ   |  i  i   } |  i d j o d Gt |  GHn | p t d   n t |  } | d t j o | d  | f S| d t j o | d d !| f S| 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.6/poplib.pyt   _getlinei   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.6/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.6/poplib.pyt   _getlongresp   s      

c         C   s   |  i  |  |  i   S(   N(   R   R   (   R   R   (    (    s   /usr/lib/python2.6/poplib.pyt	   _shortcmd   s    c         C   s   |  i  |  |  i   S(   N(   R   R$   (   R   R   (    (    s   /usr/lib/python2.6/poplib.pyt   _longcmd   s    c         C   s   |  i  S(   N(   R   (   R   (    (    s   /usr/lib/python2.6/poplib.pyt
   getwelcome¤   s    c         C   s   | |  _  d  S(   N(   R   (   R   t   level(    (    s   /usr/lib/python2.6/poplib.pyt   set_debuglevel¨   s    c         C   s   |  i  d |  S(   sV   Send user name, return response

        (should indicate password required).
        s   USER %s(   R%   (   R   t   user(    (    s   /usr/lib/python2.6/poplib.pyR*   Ž   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(   R%   (   R   t   pswd(    (    s   /usr/lib/python2.6/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   (   R%   t   splitR   R   t   int(   R   t   retvalt   retst   numMessagest   sizeMessages(    (    s   /usr/lib/python2.6/poplib.pyt   statŔ   s    
 c         C   s,   | d j	 o |  i d |  S|  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(   t   NoneR%   R&   (   R   t   which(    (    s   /usr/lib/python2.6/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(   R&   (   R   R7   (    (    s   /usr/lib/python2.6/poplib.pyt   retrŰ   s    c         C   s   |  i  d |  S(   sF   Delete message number 'which'.

        Result is 'response'.
        s   DELE %s(   R%   (   R   R7   (    (    s   /usr/lib/python2.6/poplib.pyt   deleă   s    c         C   s   |  i  d  S(   sX   Does nothing.

        One supposes the response indicates the server is alive.
        t   NOOP(   R%   (   R   (    (    s   /usr/lib/python2.6/poplib.pyt   noopë   s    c         C   s   |  i  d  S(   s(   Unmark all messages marked for deletion.t   RSET(   R%   (   R   (    (    s   /usr/lib/python2.6/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(   R%   R   R   t   closeR	   (   R   R   t   val(    (    s   /usr/lib/python2.6/poplib.pyt   quitř   s    c         C   s   |  i  d |  S(   s   Not sure what this does.s   RPOP %s(   R%   (   R   R*   (    (    s   /usr/lib/python2.6/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.6/poplib.pyt   <lambda>  s    s
   APOP %s %s(   t	   timestampt   matchR   R   t   hashlibt   md5t   groupt   digestt   joint   mapR%   (   R   R*   t   secrett   mRI   RL   (    (    s   /usr/lib/python2.6/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(   R&   (   R   R7   t   howmuch(    (    s   /usr/lib/python2.6/poplib.pyt   top#  s    c         C   s,   | d j	 o |  i d |  S|  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(   R6   R%   R&   (   R   R7   (    (    s   /usr/lib/python2.6/poplib.pyt   uidl,  s    N(!   R   R   t   __doc__t	   POP3_PORTR   t   _GLOBAL_DEFAULT_TIMEOUTR   R   R   R   R   R$   R%   R&   R'   R)   R*   R,   R4   R6   R#   R8   R9   R;   R=   RA   RB   t   ret   compileRG   RQ   RS   RU   (    (    (    s   /usr/lib/python2.6/poplib.pyR    $   s4   (													
										t   POP3_SSLc           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(   NRC   s!   getaddrinfo returns an empty listi    R   (   R   R   t   keyfilet   certfilet   bufferR6   R	   R   t   getaddrinfot   SOCK_STREAMt   connectt   errorR?   R
   R   t   sslt   wrap_sockett   sslobjR   R   R   (   R   R   R   R\   R]   t   msgt   rest   aft   socktypet   protot	   canonnamet   sa(    (    s   /usr/lib/python2.6/poplib.pyR   J  s2    						" 
	
!	c         C   sE   |  i  i   } t |  d j o t d   n |  i | 7_ d  S(   Ni    s   -ERR EOF(   Re   t   readR   R   R^   (   R   t   localbuf(    (    s   /usr/lib/python2.6/poplib.pyt   _fillBufferd  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 S| d t j o | d d !| f S| d  | f S(   NRC   s   .*?\ni    i   s   *get*iţ˙˙˙i˙˙˙˙(   RY   RZ   RH   R^   Ro   RK   t   subR   R   R   R   R   (   R   R   t	   renewlineRH   R   (    (    s   /usr/lib/python2.6/poplib.pyR   j  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   Re   t   write(   R   R   t   bytest   sent(    (    s   /usr/lib/python2.6/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.R>   (   R%   R   R	   R?   Re   (   R   R   R@   (    (    s   /usr/lib/python2.6/poplib.pyRA     s    N(
   R   R   RV   t   POP3_SSL_PORTR6   R   Ro   R   R   RA   (    (    (    s   /usr/lib/python2.6/poplib.pyR[   =  s   			t   __main__i   i   i   s   Message %d:s      s   -----------------------(#   RV   RY   R   t   __all__t	   ExceptionR   RW   Ru   R   t   LFR   R    Rc   t   ImportErrorR[   R"   R   t   syst   argvt   aR'   R*   R,   R#   R4   t   numMsgst	   totalSizet   ranget   iR8   t   headerRf   R   R   RA   (    (    (    s   /usr/lib/python2.6/poplib.pyt   <module>   sB   
˙ T
 	 	