;
Êâ"Ic               @   sµ  d  Z  d d l Z d d l Z d d g Z Gd „  d e ƒ Z d Z d Z d Z d	 Z	 e e	 Z
 Gd
 „  d ƒ Z y d d l Z Wn e k
 o Yn" XGd „  d e ƒ Z e j d ƒ e d k oî d d l Z e e j d ƒ Z e e j ƒ  ƒ e j e j d ƒ e j e j d ƒ e j ƒ  e j ƒ  \ Z Z xj e d e d ƒ D]U Z e j e ƒ \ Z Z  Z! e d e ƒ x e  D] Z" e d e" ƒ q}We d ƒ qJWe j# ƒ  n d S(   u@   A POP3 client class.

Based on the J. Myers POP3 draft, Jan. 96
i    Nu   POP3u   error_protoc             B   s   |  Ee  Z d  S(   N(   u   __name__u
   __module__(   u
   __locals__(    (    u#   /mit/python/lib/python3.0/poplib.pyu   error_proto   s   
 in   iã  s   s   
c             B   s  |  Ee  Z d  Z d Z e e j d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e j d ƒ Z d „  Z  d „  Z! d d „ Z" d S(   uÏ  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.
    u   UTF-8c             C   sU   | |  _  | |  _ |  j | ƒ |  _ |  j j d ƒ |  _ d |  _ |  j ƒ  |  _ d  S(   Nu   rbi    (	   u   hostu   portu   _create_socketu   socku   makefileu   fileu
   _debuggingu   _getrespu   welcome(   u   selfu   hostu   portu   timeout(    (    u#   /mit/python/lib/python3.0/poplib.pyu   __init__P   s    			c             C   s   t  j |  j |  j f | ƒ S(   N(   u   socketu   create_connectionu   hostu   port(   u   selfu   timeout(    (    u#   /mit/python/lib/python3.0/poplib.pyu   _create_socketY   s    c             C   s?   |  j  d k o t d t | ƒ ƒ n |  j j | t ƒ d  S(   Ni   u   *put*(   u
   _debuggingu   printu   repru   socku   sendallu   CRLF(   u   selfu   line(    (    u#   /mit/python/lib/python3.0/poplib.pyu   _putline\   s     c             C   sD   |  j  o t d t | ƒ ƒ n t | |  j ƒ } |  j | ƒ d  S(   Nu   *cmd*(   u
   _debuggingu   printu   repru   bytesu   encodingu   _putline(   u   selfu   line(    (    u#   /mit/python/lib/python3.0/poplib.pyu   _putcmdc   s    
 c             C   s¿   |  j  j ƒ  } |  j d k o t d t | ƒ ƒ n | p t d ƒ ‚ n t | ƒ } | d d  … t k o | d  d … | f S| d t k o | d d … | f S| d  d … | f S(   Ni   u   *get*u   -ERR EOFiþÿÿÿi    iÿÿÿÿ(	   u   fileu   readlineu
   _debuggingu   printu   repru   error_protou   lenu   CRLFu   CR(   u   selfu   lineu   octets(    (    u#   /mit/python/lib/python3.0/poplib.pyu   _getlinem   s      c             C   s]   |  j  ƒ  \ } } |  j d k o t d t | ƒ ƒ n | j d ƒ p t | ƒ ‚ n | S(   Ni   u   *resp*s   +(   u   _getlineu
   _debuggingu   printu   repru
   startswithu   error_proto(   u   selfu   respu   o(    (    u#   /mit/python/lib/python3.0/poplib.pyu   _getresp   s     c             C   s£   |  j  ƒ  } g  } d } |  j ƒ  \ } } xi | d k o[ | j d ƒ o | d } | d d  … } n | | } | j | ƒ |  j ƒ  \ } } q- W| | | f S(   Ni    s   .s   ..i   (   u   _getrespu   _getlineu
   startswithu   append(   u   selfu   respu   listu   octetsu   lineu   o(    (    u#   /mit/python/lib/python3.0/poplib.pyu   _getlongresp‰   s      

c             C   s   |  j  | ƒ |  j ƒ  S(   N(   u   _putcmdu   _getresp(   u   selfu   line(    (    u#   /mit/python/lib/python3.0/poplib.pyu	   _shortcmd™   s    c             C   s   |  j  | ƒ |  j ƒ  S(   N(   u   _putcmdu   _getlongresp(   u   selfu   line(    (    u#   /mit/python/lib/python3.0/poplib.pyu   _longcmd    s    c             C   s   |  j  S(   N(   u   welcome(   u   self(    (    u#   /mit/python/lib/python3.0/poplib.pyu
   getwelcome§   s    c             C   s   | |  _  d  S(   N(   u
   _debugging(   u   selfu   level(    (    u#   /mit/python/lib/python3.0/poplib.pyu   set_debuglevel«   s    c             C   s   |  j  d | ƒ S(   uV   Send user name, return response

        (should indicate password required).
        u   USER %s(   u	   _shortcmd(   u   selfu   user(    (    u#   /mit/python/lib/python3.0/poplib.pyu   user±   s    c             C   s   |  j  d | ƒ S(   u    Send password, return response

        (response includes message count, mailbox size).

        NB: mailbox is locked by server from here to 'quit()'
        u   PASS %s(   u	   _shortcmd(   u   selfu   pswd(    (    u#   /mit/python/lib/python3.0/poplib.pyu   pass_¹   s    c             C   sf   |  j  d ƒ } | j ƒ  } |  j o t d t | ƒ ƒ n t | d ƒ } t | d ƒ } | | f S(   u]   Get mailbox status.

        Result is tuple of 2 ints (message count, mailbox size)
        u   STATu   *stat*i   i   (   u	   _shortcmdu   splitu
   _debuggingu   printu   repru   int(   u   selfu   retvalu   retsu   numMessagesu   sizeMessages(    (    u#   /mit/python/lib/python3.0/poplib.pyu   statÃ   s    
 c             C   s,   | d k	 o |  j d | ƒ S|  j d ƒ S(   u  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.
        u   LIST %su   LISTN(   u   Noneu	   _shortcmdu   _longcmd(   u   selfu   which(    (    u#   /mit/python/lib/python3.0/poplib.pyu   listÐ   s    	c             C   s   |  j  d | ƒ S(   uo   Retrieve whole message number 'which'.

        Result is in form ['response', ['line', ...], octets].
        u   RETR %s(   u   _longcmd(   u   selfu   which(    (    u#   /mit/python/lib/python3.0/poplib.pyu   retrÞ   s    c             C   s   |  j  d | ƒ S(   uF   Delete message number 'which'.

        Result is 'response'.
        u   DELE %s(   u	   _shortcmd(   u   selfu   which(    (    u#   /mit/python/lib/python3.0/poplib.pyu   deleæ   s    c             C   s   |  j  d ƒ S(   uX   Does nothing.

        One supposes the response indicates the server is alive.
        u   NOOP(   u	   _shortcmd(   u   self(    (    u#   /mit/python/lib/python3.0/poplib.pyu   noopî   s    c             C   s   |  j  d ƒ S(   u(   Unmark all messages marked for deletion.u   RSET(   u	   _shortcmd(   u   self(    (    u#   /mit/python/lib/python3.0/poplib.pyu   rsetö   s    c             C   sm   y |  j  d ƒ } Wn- t k
 o! } z | } WYd d } ~ Xn X|  j j ƒ  |  j j ƒ  |  ` |  ` | S(   uD   Signoff: commit changes on server, unlock mailbox, close connection.u   QUITN(   u	   _shortcmdu   error_protou   fileu   closeu   sock(   u   selfu   respu   val(    (    u#   /mit/python/lib/python3.0/poplib.pyu   quitû   s    c             C   s   |  j  d | ƒ S(   u   Not sure what this does.u   RPOP %s(   u	   _shortcmd(   u   selfu   user(    (    u#   /mit/python/lib/python3.0/poplib.pyu   rpop  s    s   \+OK.*(<[^>]+>)c             C   s‰   t  | |  j ƒ } |  j j |  j ƒ } | p t d ƒ ‚ n d d l } | j d ƒ | } | j | ƒ j	 ƒ  } |  j
 d | | f ƒ S(   u  Authorisation

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

        Args:
                user     - mailbox user;
                password - mailbox password.

        NB: mailbox is locked by server from here to 'quit()'
        u!   -ERR APOP not supported by serveri    Ni   u
   APOP %s %s(   u   bytesu   encodingu	   timestampu   matchu   welcomeu   error_protou   hashlibu   groupu   md5u	   hexdigestu	   _shortcmd(   u   selfu   useru   passwordu   secretu   mu   hashlibu   digest(    (    u#   /mit/python/lib/python3.0/poplib.pyu   apop  s    c             C   s   |  j  d | | f ƒ S(   u­   Retrieve message header of message number 'which'
        and first 'howmuch' lines of message body.

        Result is in form ['response', ['line', ...], octets].
        u	   TOP %s %s(   u   _longcmd(   u   selfu   whichu   howmuch(    (    u#   /mit/python/lib/python3.0/poplib.pyu   top'  s    c             C   s,   | d k	 o |  j d | ƒ S|  j d ƒ S(   uì   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]
        u   UIDL %su   UIDLN(   u   Noneu	   _shortcmdu   _longcmd(   u   selfu   which(    (    u#   /mit/python/lib/python3.0/poplib.pyu   uidl0  s    N(#   u   __name__u
   __module__u   __doc__u   encodingu	   POP3_PORTu   socketu   _GLOBAL_DEFAULT_TIMEOUTu   __init__u   _create_socketu   _putlineu   _putcmdu   _getlineu   _getrespu   _getlongrespu	   _shortcmdu   _longcmdu
   getwelcomeu   set_debuglevelu   useru   pass_u   statu   Noneu   listu   retru   deleu   noopu   rsetu   quitu   rpopu   reu   compileu	   timestampu   apopu   topu   uidl(   u
   __locals__(    (    u#   /mit/python/lib/python3.0/poplib.pyu   POP3$   s8   
(			
		
							
										c             B   s5   |  Ee  Z d  Z e d d e j d „ Z d „  Z d S(   u¾  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   s,   | |  _  | |  _ t j |  | | | ƒ d  S(   N(   u   keyfileu   certfileu   POP3u   __init__(   u   selfu   hostu   portu   keyfileu   certfileu   timeout(    (    u#   /mit/python/lib/python3.0/poplib.pyu   __init__N  s    		c             C   s+   t  j |  | ƒ } t j | |  j |  j ƒ S(   N(   u   POP3u   _create_socketu   sslu   wrap_socketu   keyfileu   certfile(   u   selfu   timeoutu   sock(    (    u#   /mit/python/lib/python3.0/poplib.pyu   _create_socketU  s    N(	   u   __name__u
   __module__u   __doc__u   POP3_SSL_PORTu   Noneu   socketu   _GLOBAL_DEFAULT_TIMEOUTu   __init__u   _create_socket(   u
   __locals__(    (    u#   /mit/python/lib/python3.0/poplib.pyu   POP3_SSLA  s
   
u   POP3_SSLu   __main__i   i   i   u   Message %d:u      u   -----------------------($   u   __doc__u   reu   socketu   __all__u	   Exceptionu   error_protou	   POP3_PORTu   POP3_SSL_PORTu   CRu   LFu   CRLFu   POP3u   sslu   ImportErroru   POP3_SSLu   appendu   __name__u   sysu   argvu   au   printu
   getwelcomeu   useru   pass_u   listu   statu   numMsgsu	   totalSizeu   rangeu   iu   retru   headeru   msgu   octetsu   lineu   quit(    (    (    u#   /mit/python/lib/python3.0/poplib.pyu   <module>   sB   
ÿ 
  