
?]c           @   st  d  Z  d d d d d d d d d	 f	 Z d
 Z d Z d Z d Z d Z d Z d 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 d d l Z d d l Z e e k r d d l Z e Z n d d l Z e Z e Z d Z e Z d Z d Z d Z  d d Z! d Z" d Z# d Z$ d Z% d Z& d Z' d d f Z( d  Z) d! Z* d" d# d$ d% f \ Z+ Z, Z- Z. i+ e, e- f e/ f d& 6e+ f e/ f d' 6e+ e, e- f e0 f d( 6e- f e0 f d) 6e- f e/ f d* 6e, f e/ f d+ 6e- f e0 f d, 6e, e- f e0 f d- 6e, e- f e0 f d. 6e, e- f e0 f d/ 6e, f e/ f d0 6e, e- f e/ f d1 6e- f e0 f d2 6e- f e0 f d3 6e, e- f e0 f d4 6e, e- f e0 f d5 6e, e- f e0 f d6 6e, e- f e0 f d7 6e+ e, e. e- f e0 f d8 6e- f e/ f d9 6e, e- f e0 f d: 6e+ f e/ f d; 6e+ e, e. e- f e/ f d% 6e, e- f e0 f d< 6e, e- f e0 f d= 6e, e- f e0 f d> 6e+ e, e- f e0 f d? 6e- f e0 f d@ 6e, f e/ f dA 6e, e- f e0 f dB 6e- f e0 f dC 6e, e- f e/ f dD 6e, e- f e/ f dE 6e, e- f e0 f dF 6e, e- f e/ f dG 6e- f e0 f dH 6e+ f e/ f dI 6e, e- f e0 f dJ 6e- f e0 f dK 6e, e- f e/ f dL 6e- f e0 f dM 6e- f e0 f dN 6e, e- f e/ f dO 6Z1 dC dH dM f Z2 dP   Z3 dQ e4 f dR     YZ5 d e4 f dS     YZ6 d e6 f dT     YZ7 d e6 f dU     YZ8 dV e4 f dW     YZ9 dX e4 f dY     YZ: e dZ d[ d\ d] d^ d_ d` da db dc dd de g Z; e< e= e> df   e; d! D e= e? d! dg      Z@ e jA dh  ZB di   ZC eC ZD dj   ZE e jA dk  ZF dl   ZG eH dm k rpeI reJ dn   n  d d lK ZK d d lL ZL y# eK jK e jM d! do  \ ZN ZO Wn( eK jP k
 rjZQ f  f  f \ ZN ZO n Xe f dp \ ZR ZS ZT ZU ZV ZW ZX x eN D] \ ZY ZQ eY dq k reZ eQ  ZR eR d! ZS n eY dr k rd! ZX n eY ds k r(y eQ j[ dt  \ ZV ZW Wn# eJ k
 r$eQ eQ f \ ZV ZW n XnC eY du k rCeZ eQ  ZT n( eY dv k rkeQ ZU eO rheU f ZO n  n  qWeO rdw f ZO n  eT reV e k	 oe pe ZT n  eO d  Z\ eL j]   Z^ e_ e j` ja dx  odx peb  jc dy  Zd dz i e^ d{ 6d| d} 6ed d~ 6Ze d d d f f d d d f f d d f f d d d f f d- d f f d d e e ee f f d dw d f f d d f f d e d d f f d d d f f d d d d f f d f  f d f  f d f  f d f  f g Zf d f  f d d f f d d f f d e e e ee f f d f  f d f  f d d d f f d f  f d f  f d dC d d f f d dC d f f d dM d d d f f d f  f f Zg e e f \ ah Zi d   Zj e0 d  Zk yne jl   jm d  eV e k	 r7
eV r	e ZV n  eW r	e ZW n  e7 d e\ d eT d eV d eW d d d eR d dw d d d eS d d  
Zi nZ eU rd
e8 eU d eR d dw d d d eS Zi n- e6 d e\ d eT d eR d dw d d d eS  Zi ei jn d# k r
eL jL d e^ e\ p
d f  Zo ef jp d  d e^ eo f f  n  ei jq d  d ei jr  d ei js k rei jt   n  x! ef D] \ Zu ZO ek eu eO  qWxm ek d dw d f d e/ D]P Zv e jw d ev  Zx ex rex jy d!  Z` n ev j[   d Z` ek d e` f  qQWd8 ei js k rek d f   ek d d f  ek d d e d e jz   d  f  n  x eg D] \ Zu ZO eu eO f d dC d d f f k r>ek eu eO  qn  ek eu eO d e/ Z{ e{ d j[   Z| e| rpqn  ek d d3 e| d d f  ek d dK e| d d d f  ek d f   qWd9 ei js k r~ek d d f d e/ ek d d f  e j} d!  ek d f  d e/ ek d e e e ee f d e/ ek d e d f d e/ d  j[   d  Z~ ek d e~ d f d e/ Z{ ei j d e~ e e{  f  ek d d f  ek d e~ d d f d e/ f ek d e~ d f d e/ Z{ ei j d e~ e e{  f  ek d dK e~ d d f  ek d f   eX r{ei j d  y ek d d f d e/ Wn. e k
 rwei j d  ei j dw    n Xn  n eX rei j d  n  ek d f  d e/ eR rei j dw  ei j   ei j dw  ei j d  x1 ei j   D]# \ Z Z{ ei j d e e{ f  qWn  d GHWnO eX pAei e k pAd9 ei js k rid GHeR rcd e jM d  GHn    n  n Xn  d S(   s  Threaded IMAP4 client.

Based on RFC 3501 and original imaplib module.

Public classes:   IMAP4
                  IMAP4_SSL
                  IMAP4_stream

Public functions: Internaldate2Time
                  ParseFlags
                  Time2Internaldate
t   IMAP4t	   IMAP4_SSLt   IMAP4_streamt   Internaldate2Timet
   ParseFlagst   Time2Internaldatet   Mon2numt
   MonthNamest   InternalDates   2.57t   2t   57s
  
Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998.
String method conversion by ESR, February 2001.
GET/SETACL contributed by Anthony Baxter <anthony@interlink.com.au> April 2001.
IMAP4_SSL contributed by Tino Lange <Tino.Lange@isg.de> March 2002.
GET/SETQUOTA contributed by Andreas Zeidler <az@kreativkombinat.de> June 2002.
PROXYAUTH contributed by Rick Holbert <holbert.13@osu.edu> November 2002.
IDLE via threads suggested by Philippe Normand <phil@respyre.org> January 2005.
GET/SETANNOTATION contributed by Tomas Lindroos <skitta@abo.fi> June 2005.
COMPRESS/DEFLATE contributed by Bron Gondwana <brong@brong.net> May 2009.
STARTTLS from Jython's imaplib by Alan Kennedy.
ID contributed by Dave Baggett <dave@baggett.org> November 2009.
Improved untagged responses handling suggested by Dave Baggett <dave@baggett.org> November 2009.
Improved thread naming, and 0 read detection contributed by Grant Edwards <grant.b.edwards@gmail.com> June 2010.
Improved timeout handling contributed by Ivan Vovnenko <ivovnenko@gmail.com> October 2010.
Timeout handling further improved by Ethan Glasser-Camp <glasse@cs.rpi.edu> December 2010.
Time2Internaldate() patch to match RFC2060 specification of English month names from bugs.python.org/issue11024 March 2011.
starttls() bug fixed with the help of Sebastian Spaeth <sebastian@sspaeth.de> April 2011.
Threads now set the "daemon" flag (suggested by offlineimap-project) April 2011.
Single quoting introduced with the help of Vladimir Marek <vladimir.marek@oracle.com> August 2011.
Support for specifying SSL version by Ryan Kavanagh <rak@debian.org> July 2013.
Fix for gmail "read 0" error provided by Jim Greenleaf <james.a.greenleaf@gmail.com> August 2013.
Fix for offlineimap "indexerror: string index out of range" bug provided by Eygene Ryabinkin <rea@codelabs.ru> August 2013.
Fix for missing idle_lock in _handler() provided by Franklin Brook <franklin@brook.se> August 2014.
Conversion to Python3 provided by F. Malina <fmalina@gmail.com> February 2015.
Fix for READ-ONLY error from multiple EXAMINE/SELECT calls by Pierre-Louis Bonicoli <pierre-louis.bonicoli@gmx.fr> March 2015.
Fix for null strings appended to untagged responses by Pierre-Louis Bonicoli <pierre-louis.bonicoli@gmx.fr> March 2015.
Fix for correct byte encoding for _CRAM_MD5_AUTH taken from python3.5 imaplib.py June 2015.
Fix for correct Python 3 exception handling by Tobias Brink <tobias.brink@gmail.com> August 2015.
Fix to allow interruptible IDLE command by Tim Peoples <dromedary512@users.sf.net> September 2015.
Add support for TLS levels by Ben Boeckel <mathstuf@gmail.com> September 2015.
Fix for shutown exception by Sebastien Gross <seb@chezwam.org> November 2015.s!   Piers Lauder <piers@janeelix.com>s   http://imaplib2.sourceforge.nets   Python LicenseiNs   
i   i  s   * IDLE TIMEOUT
i<   i   i   i   i   t
   tls_securet
   tls_no_sslt
   tls_compatt	   IMAP4REV1i    i   t   NONAUTHt   AUTHt   SELECTEDt   LOGOUTt   APPENDt   AUTHENTICATEt
   CAPABILITYt   CHECKt   CLOSEt   COMPRESSt   COPYt   CREATEt   DELETEt	   DELETEACLt   ENABLEt   EXAMINEt   EXPUNGEt   FETCHt   GETACLt   GETANNOTATIONt   GETQUOTAt   GETQUOTAROOTt   IDt   IDLEt   LISTt   LOGINt   LSUBt   MYRIGHTSt	   NAMESPACEt   NOOPt   PARTIALt	   PROXYAUTHt   RENAMEt   SEARCHt   SELECTt   SETACLt   SETANNOTATIONt   SETQUOTAt   SORTt   STARTTLSt   STATUSt   STOREt	   SUBSCRIBEt   THREADt   UIDt   UNSUBSCRIBEc         C   sb   g  d } } t  t |    }  x3 |  rT t |  d  \ }  } | j d | |  q" Wd j |  S(   sg   string = Int2AP(num)
    Return 'num' converted to a string using characters from the set 'A'..'P'
    t   ABCDEFGHIJKLMNOPi   i    t    (   t   intt   abst   divmodt   insertt   join(   t   numt   valt   a2pt   mod(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   Int2AP   s    	t   Requestc           B   sA   e  Z d  Z d d d e d  Z d   Z d d  Z d   Z RS(   s7   Private class to represent a request awaiting response.c         C   s   | |  _  | |  _ | |  _ | s- | |  _ n |  | f |  _ d | j | j f |  _ | j d 7_ t j   |  _	 d  |  _ d  |  _ d  |  _ d  S(   Ns   %s%si   (   t   parentt   namet   callbackt   callback_argt   tagpret   tagnumt   tagt	   threadingt   Eventt   readyt   Nonet   responset   abortedt   data(   t   selfRJ   RK   RL   t   cb_argt   cb_self(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   __init__   s    					c         C   s    | | f |  _  |  j d   d  S(   N(   RV   t   deliverRT   (   RX   t   typRE   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   abort   s    c         C   s   d  |  _ |  j j d d |  j |  j f  |  j j   |  j d  k	 r |  j \ } } | d  k rp d | } n  | | t	 |    n  |  j
 S(   Ni   s   %s:%s.ready.waits   %s - %%s(   RT   RL   RJ   t   _logRK   RP   RS   t   waitRV   t   strRU   (   RX   t   exc_fmtR]   RE   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   get_response   s    	#c         C   sl   |  j  d  k	 r/ |  j  | |  j |  j f  d  S| |  _ |  j j   |  j j d d |  j	 |  j
 f  d  S(   Ni   s   %s:%s.ready.set(   RL   RT   RM   RV   RU   RS   t   setRJ   R_   RK   RP   (   RX   RU   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR\      s    	N(	   t   __name__t
   __module__t   __doc__RT   t   FalseR[   R^   Rc   R\   (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyRI      s
   	c           B   s@  e  Z d  Z d e f d     YZ d e f d     YZ d e f d     YZ d Z d Z e	 j
 d	  Z e	 j
 d
  Z e	 j
 d  Z e	 j
 d  Z e	 j
 d  Z dm dm dm dm dm dm dm d  Z d   Z d   Z d   Z dm dm 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'   Z* d( d)  Z+ d*   Z, d+   Z- d,   Z. d-   Z/ d.   Z0 d/   Z1 d0   Z2 dm d1  Z3 d2 d3 d4  Z4 d5   Z5 d6   Z6 d7   Z7 d8   Z8 d2 d3 d9  Z9 d:   Z: d;   Z; d<   Z< d=   Z= d>   Z> d?   Z? d@   Z@ d( eA dA  ZB dB   ZC dC   ZD dD   ZE dE   ZF dm dm dm dm dF eG dG  ZH dH   ZI dI   ZJ dJ   ZK dK   ZL dL   ZM dM   ZN dN   ZO dO   ZP dP   ZQ dQ   ZR dR   ZS dS   ZT dT   ZU dU   ZV dV   ZW dW   ZX dX   ZY eA dY  ZZ dZ   Z[ d[   Z\ d\   Z] d]   Z^ d^   Z_ dm dm d_  Z` d`   Za da   Zb db   Zc dc   Zd ee ef dd  rde   Zg n	 df   Zg dg   Zh dm dm dm dh  Zi di   Zj dj   Zk dm dm dk  Zl dl   Zm RS(n   s6  Threaded IMAP4 client class.

    Instantiate with:
        IMAP4(host=None, port=None, debug=None, debug_file=None, identifier=None, timeout=None, debug_buf_lvl=None)

        host          - host's name (default: localhost);
        port          - port number (default: standard IMAP4 port);
        debug         - debug level (default: 0 - no debug);
        debug_file    - debug stream (default: sys.stderr);
        identifier    - thread identifier prefix (default: host);
        timeout       - timeout in seconds when expecting a command response (default: no timeout),
        debug_buf_lvl - debug level at which buffering is turned off.

    All IMAP4rev1 commands are supported by methods of the same name.

    Each command returns a tuple: (type, [data, ...]) where 'type'
    is usually 'OK' or 'NO', and 'data' is either the text from the
    tagged response, or untagged results from command. Each 'data' is
    either a string, or a tuple. If a tuple, then the first part is the
    header of the response, and the second part contains the data (ie:
    'literal' value).

    Errors raise the exception class <instance>.error("<reason>").
    IMAP4 server errors raise <instance>.abort("<reason>"), which is
    a sub-class of 'error'. Mailbox status changes from READ-WRITE to
    READ-ONLY raise the exception class <instance>.readonly("<reason>"),
    which is a sub-class of 'abort'.

    "error" exceptions imply a program error.
    "abort" exceptions imply the connection should be reset, and
            the command re-tried.
    "readonly" exceptions imply the command should be re-tried.

    All commands take two optional named arguments:
        'callback' and 'cb_arg'
    If 'callback' is provided then the command is asynchronous, so after
    the command is queued for transmission, the call returns immediately
    with the tuple (None, None).
    The result will be posted by invoking "callback" with one arg, a tuple:
        callback((result, cb_arg, None))
    or, if there was a problem:
        callback((None, cb_arg, (exception class, reason)))

    Otherwise the command is synchronous (waits for result). But note
    that state-changing commands will both block until previous commands
    have completed, and block subsequent commands until they have finished.

    All (non-callback) arguments to commands are converted to strings,
    except for AUTHENTICATE, and the last argument to APPEND which is
    passed as an IMAP4 literal.  If necessary (the string contains any
    non-printing characters or white-space and isn't enclosed with
    either parentheses or double or single quotes) each string is
    quoted.  However, the 'password' argument to the LOGIN command is
    always quoted.  If you want to avoid having an argument string
    quoted (eg: the 'flags' argument to STORE) then enclose the string
    in parentheses (eg: "(\Deleted)"). If you are using "sequence sets"
    containing the wildcard character '*', then enclose the argument
    in single quotes: the quotes will be removed and the resulting
    string passed unquoted. Note also that you can pass in an argument
    with a type that doesn't evaluate to 'string_types' (eg: 'bytearray')
    and it will be converted to a string without quoting.

    There is one instance variable, 'state', that is useful for tracking
    whether the client needs to login to the server. If it has the
    value "AUTH" after instantiating the class, then the connection
    is pre-authenticated (otherwise it will be "NONAUTH"). Selecting a
    mailbox changes the state to be "SELECTED", closing a mailbox changes
    back to "AUTH", and once the client has logged out, the state changes
    to "LOGOUT" and no further commands may be issued.

    Note: to use this module, you must read the RFCs pertaining to the
    IMAP4 protocol, as the semantics of the arguments to each IMAP4
    command are left to the invoker, not to mention the results. Also,
    most IMAP servers implement a sub-set of the commands available here.

    Note also that you must call logout() to shut down threads before
    discarding an instance.
    t   errorc           B   s   e  Z RS(    (   Re   Rf   (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyRi   *  s    R^   c           B   s   e  Z RS(    (   Re   Rf   (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR^   +  s    t   readonlyc           B   s   e  Z RS(    (   Re   Rf   (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyRj   ,  s    s   .*{(?P<size>\d+)}$s3   \* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?s   \+( (?P<data>.*))?s
   \r\n|\r|\ns%   [^!#$&'+,./0-9:;<=>?@A-Z\[^_`a-z|}~-]s)   \[(?P<type>[A-Z-]+)( (?P<data>[^\]]*))?\]s$   \* (?P<type>[A-Z-]+)( (?P<data>.*))?c         C   s   t  |  _ d  |  _ i  |  _ g  |  _ d  |  _ t |  _ d  |  _	 d  |  _
 t |  _ d |  _ g  |  _ d  |  _ d  |  _ d  |  _ t |  _ d |  _ t t j d d   |  _ t j d |  j d  |  _ |  j   |  j | | |  | |  _ | d  k	 r| t k  r| |  _ n	 t |  _ t |  _  |  j! | |  | rZ|  j" d |  j# |  j$ f  n  | d  k	 rr| |  _% n |  j# |  _% |  j% r|  j% d 7_% n  t |  _& |  _' t( j)   |  _* t( j+   |  _, t( j+   |  _- t( j+   |  _. t/ j0 d  |  _1 t/ j0   |  _2 t( j3 d	 |  j4  |  _5 |  j5 j6 t7  |  j5 j8   t( j3 d	 |  j9  |  _: |  j: j6 t7  |  j: j8   t( j3 d	 |  j;  |  _< |  j< j6 t7  |  j< j8   y@|  j= d
 d d d  j> d  d |  _? |  j@ d  rtA |  _ |  jB d d  n> |  j@ d  r|  jB d d  n |  jC d tD |  j?    |  jE   \ } }	 |	 d  g k rl|  jC d   n  tF |	 d jG   jH    |  _I |  jB d d |  jI f  x< tJ D]% }
 |
 |  jI k rqn  |
 |  _K PqW|  jC d   Wn |  jL     n Xd  S(   Ni    i   i  s   (?P<tag>s"   \d+) (?P<type>[A-Z]+) (?P<data>.*)s   connected to %s on port %st    i
   t   targetRK   t   welcomeRP   t   continuations   IMAP4 protocol error: %si   t   PREAUTHs   state => AUTHt   OKs   state => NONAUTHs'   unrecognised server welcome message: %ss"   no CAPABILITY response from serveris   CAPABILITY: %rs   server not IMAP4 compliant(M   R   t   stateRT   t   literalt   tagged_commandst   untagged_responsest   mailboxRh   t   is_readonlyt   idle_rqbt   idle_timeoutt   _expecting_datat   _expecting_data_lent   _accumulated_datat   _literal_expectedt
   compressort   decompressort   _tls_establishedRO   RH   t   randomt   randintRN   t   ret   compilet   tagret   _mode_asciit   _init_debugt   resp_timeoutt   READ_POLL_TIMEOUTt   read_poll_timeoutt	   READ_SIZEt	   read_sizet   opent   _mesgt   hostt   portt
   identifiert	   Terminatet   TerminateReaderRQ   RR   t   state_change_freet   Lockt   state_change_pendingt   commands_lockt	   idle_lockt   queuet   Queuet   ouqt   inqt   Threadt   _writert   wrtht	   setDaemont   Truet   startt   _readert   rdtht   _handlert   intht   _request_pushRc   Rm   t   _get_untagged_responseR   R_   Ri   t   reprt
   capabilityt   tuplet   uppert   splitt   capabilitiest   AllowedVersionst   PROTOCOL_VERSIONt   _close_threads(   RX   R   R   t   debugt
   debug_fileR   t   timeoutt   debug_buf_lvlR]   t   datt   version(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR[   =  s    																
			 	(		
c         C   s3   | t  k r t |  | j    St d |   d  S(   Ns   Unknown IMAP4 command: '%s'(   t   Commandst   getattrt   lowert   AttributeError(   RX   t   attr(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   __getattr__  s    c         C   s   t  |  _ d |  _ t t k rW t j |  j t j  |  _	 t j |  j
 t j  |  _ n* t j |  j  |  _	 t j |  j
  |  _ d  S(   Nt   ascii(   Rh   t   utf8_enabledt	   _encodingt   bytesRa   R   R   t   _literalt   ASCIIt   literal_cret   _untagged_statust   untagged_status_cre(   RX   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    		c         C   s   t  |  _ d |  _ t t k rK t j |  j  |  _ t j |  j	  |  _
 n6 t j |  j t j  |  _ t j |  j	 t j  |  _
 d  S(   Ns   utf-8(   R   R   R   R   Ra   R   R   R   R   R   R   t   UNICODE(   RX   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt
   _mode_utf8  s    		c         C   sO   |  j  d |  |  _ |  j  t |  |  _ |  j   |  _ |  j j   |  _ d S(   s   open(host=None, port=None)
        Setup connection to remote server on "host:port"
            (default: localhost:standard IMAP4 port).
        This connection will be used by the routines:
            read, send, shutdown, socket.R>   N(   t   _choose_nonull_or_dfltR   t
   IMAP4_PORTR   t   open_sockett   sockt   filenot   read_fd(   RX   R   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    c         C   sK  d } x>t  j |  j |  j t  j t  j  D]	} | \ } } } } } y t  j  | | |  } Wn t  j k
 r }	 |	 } q+ n Xy x d D]h }
 y | j |  PWq t  j k
 r }	 |	 } t | j	  d k  s | j	 d t
 j k r   q q Xq Wt  j |   Wn) t  j k
 r2}	 |	 } | j   q+ n XPq+ Wt  j |   | S(   sJ   open_socket()
        Open socket choosing first address family available.is   could not open socketi    i   i   (   is   could not open socket(   i    i   (   t   sockett   getaddrinfoR   R   t	   AF_UNSPECt   SOCK_STREAMRi   t   connectt   lent   argst   errnot   EINTRt   close(   RX   t   msgt   rest   aft   socktypet   protot	   canonnamet   sat   st   mt   i(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s2    ++
c      
   C   s  ycd d  l  } i  } t | d  rE i | j d 6| j d 6| t <n
 i  | t <| t j   | t <| t j i | j d 6 | t j   | t	 <| t	 j i | j
 d 6| j
 d  6 t | d  r | t	 j i | j d 6 n  |  j d  k	 r | j } n	 | j } |  j | k r-t d	 |  j   n  |  j | |  j k ret j d
 |  j |  j f   n  | |  j |  j } t | d t  r| j |  } | | _ |  j d  k	 r| j |  j  n  |  j s|  j r| j |  j |  j  n  | j |  j d |  j |  _ n6 | j |  j |  j |  j d |  j d | d | |  _ | j  } |  j j!   |  _" Wn  t# k
 rt j d   n X|  j$ d  k	 r|  j$ |  j j%   |  j  } | r| |   qn  |  j j& t j' t j( d  d  S(   Nit   PROTOCOL_TLSv1_2t   tls1_2t   tls1_1t   tls1t   ssl23t   PROTOCOL_SSLv3t   ssl3s   unknown tls_level: %ss7   Invalid SSL version '%s' requested for tls_version '%s't   HAS_SNIt   server_hostnamet   ca_certst	   cert_reqst   ssl_versions1   imaplib SSL mode does not work without ssl modulei   ()   t   sslt   hasattrR   t   PROTOCOL_TLSv1_1t
   TLS_SECUREt   copyt
   TLS_NO_SSLt   updatet   PROTOCOL_TLSv1t
   TLS_COMPATt   PROTOCOL_SSLv23RT   R   R   t   CERT_REQUIREDt	   CERT_NONEt	   tls_levelt   RuntimeErrorR   R   t   sslerrorR   Rh   t
   SSLContextt   verify_modet   load_verify_locationst   certfilet   keyfilet   load_cert_chaint   wrap_socketR   R   t   SSLErrorR   R   t   ImportErrort   cert_verify_cbt   getpeercertt
   setsockoptt
   SOL_SOCKETt   SO_KEEPALIVE(   RX   R   t   TLS_MAPR   R   t   ctxt   ssl_exct   cert_err(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   ssl_wrap_socket  sX    


	"	!6	c         C   s4   t  j d  |  _ t  j t  j t  j d  |  _ d S(   sP   start_compressing()
        Enable deflate compression on the socket (RFC 4978).iN(   t   zlibt   decompressobjR~   t   compressobjt   Z_DEFAULT_COMPRESSIONt   DEFLATEDR}   (   RX   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   start_compressing>  s    c         C   s_   |  j  d k r |  j j |  S|  j  j r: |  j  j } n |  j j t  } |  j  j | |  S(   s@   data = read(size)
        Read at most 'size' bytes from remote.N(   R~   RT   R   t   recvt   unconsumed_tailR   t
   decompress(   RX   t   sizeRW   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   readG  s    c         C   so   |  j  d k	 r= |  j  j |  } | |  j  j t j  7} n  t t k r[ t | d  } n  |  j j	 |  d S(   s)   send(data)
        Send 'data' to remote.R   N(
   R}   RT   t   compresst   flushR  t   Z_SYNC_FLUSHR   Ra   R   t   sendall(   RX   RW   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   sendV  s    c         C   s^   zI y |  j  j t j  Wn+ t k
 rG } | j t j k rH   qH n XWd |  j  j   Xd S(   s3   shutdown()
        Close I/O established in "open".N(   R   t   shutdownR   t	   SHUT_RDWRt	   ExceptionR   t   ENOTCONNR   (   RX   t   e(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   d  s     c         C   s   |  j  S(   sQ   socket = socket()
        Return socket instance used to connect to IMAP4 server.(   R   (   RX   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   r  s    c         C   sW   zE |  j  d d  \ } } | d k rD |  j   |  j d d  n  Wd |  j   Xd S(   s  enable_compression()
        Ask the server to start compressing the connection.
        Should be called from user of this class after instantiation, as in:
            if 'COMPRESS=DEFLATE' in imapobj.capabilities:
                imapobj.enable_compression()R   t   DEFLATERp   i   s   Enabled COMPRESS=DEFLATEN(   t   _simple_commandR  R_   t   _release_state_change(   RX   R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   enable_compression}  s    
c         c   sG   x@ |  j  rB |  j j   z |  j  j d  VWd |  j j   Xq Wd S(   s    for typ,data in pop_untagged_responses(): pass
        Generator for any remaining untagged responses.
        Returns and removes untagged responses in order of reception.
        Use at your own risk!i    N(   Rt   R   t   acquiret   popt   release(   RX   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   pop_untagged_responses  s
    c         K   s]   d } |  j  d d g |  \ } } | d g k rF |  j | | |  S| | d <|  j |   S(   s   (typ, [data]) = recent()
        Return 'RECENT' responses if any exist,
        else prompt server for an update using the 'NOOP' command.
        'data' is None if no new messages,
        else list of RECENT responses, most recent last.t   RECENTt   untagged_responseN(   t   _untagged_responseRT   t   _deliver_datt   noop(   RX   t   kwRK   R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   recent  s    
c         K   s7   |  j  | d g | j    \ } } |  j | | |  S(   s   (code, [data]) = response(code)
        Return data for response 'code' if received, or None.
        Old value for response 'code' is cleared.N(   R/  RT   R   R0  (   RX   t   codeR2  R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyRU     s    $c         K   s   d } | s d } n  | rE | d | d f d
 k rK d | } qK n d	 } | r` t |  } n d	 } |  j j t |  } |  j r d | d } n  | |  _ z |  j | | | | |  SWd	 |  j   Xd	 S(   s   (typ, [data]) = append(mailbox, flags, date_time, message)
        Append message to named mailbox.
        All args except `message' can be None.R   t   INBOXi    it   (t   )s   (%s)s   UTF8 (N(   R6  R7  (	   RT   R   t   mapCRLF_cret   subt   CRLFR   Rr   R&  R'  (   RX   Ru   t   flagst	   date_timet   messageR2  RK   Rr   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   append  s"    			c         K   s   t  |  j |  _ zd |  j d | j    \ } } | d k r\ |  j |  j | d |  n  t |  _ |  j	 d d  Wd |  j
   X|  j | | |  S(   s_  (typ, [data]) = authenticate(mechanism, authobject)
        Authenticate command - requires response processing.

        'mechanism' specifies which authentication mechanism is to
        be used - it must appear in <instance>.capabilities in the
        form AUTH=<mechanism>.

        'authobject' must be a callable object:

                data = authobject(response)

        It will be called to process server continuation responses.
        It should return data that will be encoded and sent to server.
        It should return None if the client abort response '*' should
        be sent instead.R   Rp   ii   s   state => AUTHN(   t   _Authenticatort   processRr   R&  R   t   _deliver_excRi   R   Rq   R_   R'  R0  (   RX   t	   mechanismt
   authobjectR2  R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   authenticate  s    	c         K   s    d } | | d <|  j  | |  S(   sI   (typ, [data]) = capability()
        Fetch capabilities list from server.R   R.  (   R&  (   RX   R2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    
c         K   s   |  j  d |  S(   s=   (typ, [data]) = check()
        Checkpoint mailbox on server.R   (   R&  (   RX   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   check  s    c         K   st   |  j  d k r! |  j d   n  z |  j d  \ } } Wd t |  _  |  j d d  |  j   X|  j | | |  S(   s   (typ, [data]) = close()
        Close currently selected mailbox.

        Deleted messages are removed from writable mailbox.
        This is the recommended command before 'LOGOUT'.R   s   No mailbox selected.R   Ni   s   state => AUTH(   Rq   Ri   R&  R   R_   R'  R0  (   RX   R2  R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR      s    	c         K   s   |  j  d | | |  S(   sm   (typ, [data]) = copy(message_set, new_mailbox)
        Copy 'message_set' messages onto end of 'new_mailbox'.R   (   R&  (   RX   t   message_sett   new_mailboxR2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    c         K   s   |  j  d | |  S(   s;   (typ, [data]) = create(mailbox)
        Create new mailbox.R   (   R&  (   RX   Ru   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   create  s    c         K   s   |  j  d | |  S(   s;   (typ, [data]) = delete(mailbox)
        Delete old mailbox.R   (   R&  (   RX   Ru   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   delete   s    c         K   s   |  j  d | | |  S(   sk   (typ, [data]) = deleteacl(mailbox, who)
        Delete the ACLs (remove any rights) set for who on mailbox.R   (   R&  (   RX   Ru   t   whoR2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt	   deleteacl'  s    c         C   sn   d |  j  k r! |  j d   n  |  j d |  \ } } | d k rd d | j   k rd |  j   n  | | f S(   sk   Send an RFC5161 enable string to the server.

        (typ, [data]) = <intance>.enable(capability)
        R   s   Server does not support ENABLERp   s   UTF8=ACCEPT(   R   Ri   R&  R   R   (   RX   R   R]   RW   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   enable.  s    R5  c         K   s   |  j  d | d t |  S(   sU  (typ, [data]) = examine(mailbox='INBOX')
        Select a mailbox for READ-ONLY access. (Flushes all untagged responses.)
        'data' is count of messages in mailbox ('EXISTS' response).
        Mandated responses are ('FLAGS', 'EXISTS', 'RECENT', 'UIDVALIDITY'), so
        other responses should be obtained via "response('FLAGS')" etc.Ru   Rj   (   t   selectR   (   RX   Ru   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   examine;  s    c         K   s    d } | | d <|  j  | |  S(   s   (typ, [data]) = expunge()
        Permanently remove deleted items from selected mailbox.
        Generates 'EXPUNGE' response for each deleted message.
        'data' is list of 'EXPUNGE'd message numbers in order received.R   R.  (   R&  (   RX   R2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   expungeE  s    
c         K   s&   d } | | d <|  j  | | | |  S(   sA  (typ, [data, ...]) = fetch(message_set, message_parts)
        Fetch (parts of) messages.
        'message_parts' should be a string of selected parts
        enclosed in parentheses, eg: "(UID BODY[TEXT])".
        'data' are tuples of message part envelope and data,
        followed by a string containing the trailer.R    R.  (   R&  (   RX   RF  t   message_partsR2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   fetchP  s    
c         K   s   d | d <|  j  d | |  S(   sC   (typ, [data]) = getacl(mailbox)
        Get the ACLs for a mailbox.t   ACLR.  R!   (   R&  (   RX   Ru   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   getacl]  s    
c         K   s#   d | d <|  j  d | | | |  S(   sV   (typ, [data]) = getannotation(mailbox, entry, attribute)
        Retrieve ANNOTATIONs.t
   ANNOTATIONR.  R"   (   R&  (   RX   Ru   t   entryt	   attributeR2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   getannotatione  s    
c         K   s   d | d <|  j  d | |  S(   s   (typ, [data]) = getquota(root)
        Get the quota root's resource usage and limits.
        (Part of the IMAP4 QUOTA extension defined in rfc2087.)t   QUOTAR.  R#   (   R&  (   RX   t   rootR2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   getquotam  s    
c         K   sg   |  j  d |  \ } } |  j | | d  \ } } |  j | | d  \ } } |  j | | | g |  S(   s   (typ, [[QUOTAROOT responses...], [QUOTA responses...]]) = getquotaroot(mailbox)
        Get the list of quota roots for the named mailbox.R$   RX  t	   QUOTAROOT(   R&  R/  R0  (   RX   Ru   R2  R]   R   t   quotat	   quotaroot(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   getquotarootv  s    c         O   s   d } | | d <| s d } nZ t  |  d k r> | d } n; d d j g  | D]! } | ri |  j |  pl d ^ qN  } |  j | | |  S(   s  (typ, [data]) = <instance>.id(kv_pairs)
        'kv_pairs' is a possibly empty list of keys and values.
        'data' is a list of ID key value pairs or NIL.
        NB: a single argument is assumed to be correctly formatted and is passed through unchanged
        (for backward compatibility with earlier version).
        Exchange information for problem analysis and determination.
        The ID extension is defined in RFC 2971. R%   R.  t   NILi   i    s   (%s)Rk   (   R   RC   t   _quoteR&  (   RX   t   kv_pairsR2  RK   RW   t   arg(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   id  s    	
	;c         K   sA   d } t  |  |  j |  _ z |  j | |  SWd |  j   Xd S(   s   "(typ, [data]) = idle(timeout=None)
        Put server into IDLE mode until server notifies some change,
        or 'timeout' (secs) occurs (default: 29 minutes),
        or another IMAP4 command is scheduled.R&   N(   t	   _IdleContR@  Rr   R&  R'  (   RX   R   R2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   idle  s
    s   ""t   *c         K   s&   d } | | d <|  j  | | | |  S(   sN  (typ, [data]) = list(directory='""', pattern='*')
        List mailbox names in directory matching pattern.
        'data' is list of LIST responses.

        NB: for 'pattern':
        % matches all except separator ( so LIST "" "%" returns names at root)
        * matches all (so LIST "" "*" returns whole directory tree from root)R'   R.  (   R&  (   RX   t	   directoryt   patternR2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   list  s    	
c         K   s   zj |  j  d | |  j |   \ } } | d k rP |  j |  j | d |  n  t |  _ |  j d d  Wd |  j   X|  j | | |  S(   s~   (typ, [data]) = login(user, password)
        Identify client using plaintext password.
        NB: 'password' will be quoted.R(   Rp   ii   s   state => AUTHN(	   R&  R`  RA  Ri   R   Rq   R_   R'  R0  (   RX   t   usert   passwordR2  R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   login  s    $	c         K   s)   | | |  _  |  _ |  j d |  j |  S(   s\   (typ, [data]) = login_cram_md5(user, password)
        Force use of CRAM-MD5 authentication.s   CRAM-MD5(   Rj  Rk  RD  t   _CRAM_MD5_AUTH(   RX   Rj  Rk  R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   login_cram_md5  s    c         C   s]   d d l  } t |  j t  r0 |  j j d  n |  j } |  j d | j | | d  j   S(   s/   Authobject to use with CRAM-MD5 authentication.iNR   Rk   t   md5(   t   hmact
   isinstanceRk  Ra   t   encodeRj  t   HMACt	   hexdigest(   RX   t	   challengeRp  t   pwd(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyRm    s    $	c         K   s   t  |  _ |  j d d  z_ y |  j d  \ } } Wn5 d d t j   d  g } } |  j d |  n X|  j   Wd |  j   X|  j d d  |  j d	 d
 t	 } | r d	 | } } n  |  j
 | | |  S(   s   (typ, [data]) = logout()
        Shutdown connection to server.
        Returns server 'BYE' response.
        NB: You must call this to shut down threads before discarding an instance.i   s   state => LOGOUTR   t   NOs   %s: %si   Ns   connection closedt   BYEt   leave(   R   Rq   R_   R&  t   syst   exc_infoR   R'  R   R   R0  (   RX   R2  R]   R   t   bye(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   logout  s    	c         K   s&   d } | | d <|  j  | | | |  S(   s   (typ, [data, ...]) = lsub(directory='""', pattern='*')
        List 'subscribed' mailbox names in directory matching pattern.
        'data' are tuples of message part envelope and data.R)   R.  (   R&  (   RX   Rg  Rh  R2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   lsub  s    
c         K   s#   d } | | d <|  j  | | |  S(   sn   (typ, [data]) = myrights(mailbox)
        Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).R*   R.  (   R&  (   RX   Ru   R2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   myrights  s    
c         K   s    d } | | d <|  j  | |  S(   sM   (typ, [data, ...]) = namespace()
        Returns IMAP namespaces ala rfc2342.R+   R.  (   R&  (   RX   R2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt	   namespace  s    
c         K   s   |  j  d  |  j d |  S(   s1   (typ, [data]) = noop()
        Send NOOP command.i   R,   (   t   _dump_urR&  (   RX   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR1    s    c         K   s,   d } d | d <|  j  | | | | | |  S(   s   (typ, [data, ...]) = partial(message_num, message_part, start, length)
        Fetch truncated part of a message.
        'data' is tuple of message part envelope and data.
        NB: obsolete.R-   R    R.  (   R&  (   RX   t   message_numt   message_partR   t   lengthR2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   partial  s    
c         K   s)   z |  j  d | |  SWd |  j   Xd S(   s   (typ, [data]) = proxyauth(user)
        Assume authentication as 'user'.
        (Allows an authorised administrator to proxy into any user's mailbox.)R.   N(   R&  R'  (   RX   Rj  R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt	   proxyauth!  s    c         K   s   |  j  d | | |  S(   sV   (typ, [data]) = rename(oldmailbox, newmailbox)
        Rename old mailbox name to new.R/   (   R&  (   RX   t
   oldmailboxt
   newmailboxR2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   rename,  s    c         O   s]   d } | | d <| rJ |  j  r1 |  j d   n  |  j | d | | |  S|  j | | |  S(   s   (typ, [data]) = search(charset, criterion, ...)
        Search mailbox for matching messages.
        If UTF8 is enabled, charset MUST be None.
        'data' is space separated list of matching message numbers.R0   R.  s'   Non-None charset not valid in UTF8 modet   CHARSET(   R   Ri   R&  (   RX   t   charsett   criteriaR2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   search3  s    
	c         K   s|  | |  _  t |  |  _ | r' d } n d } z |  j | |  } | j d | j  \ } } | d k r |  j t k r t |  _ n  |  j	 d d  | d k r |  j
 |  j d | | | | f |  n  |  j | | |  St |  _ |  j	 d d	  Wd
 |  j   X|  j d d t rK| rK|  j d  |  j
 |  j d | |  n  |  j | d
 g d  \ } } |  j | | |  S(   sO  (typ, [data]) = select(mailbox='INBOX', readonly=False)
        Select a mailbox. (Flushes all untagged responses.)
        'data' is count of messages in mailbox ('EXISTS' response).
        Mandated responses are ('FLAGS', 'EXISTS', 'RECENT', 'UIDVALIDITY'), so
        other responses should be obtained via "response('FLAGS')" etc.R   R1   s   command: %s => %%sRp   i   s   state => AUTHt   BADs%   %s command error: %s %s. Data: %.100ss   state => SELECTEDNs	   READ-ONLYRy  s   %s is not writablet   EXISTS(   Ru   t   boolRv   t   _commandRc   RK   Rq   R   R   R_   RA  Ri   R0  R'  R   R   R  Rj   R/  RT   (   RX   Ru   Rj   R2  RK   t   rqbR]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyRM  B  s.    		)	c         K   s/   z |  j  d | | | |  SWd |  j   Xd S(   sE   (typ, [data]) = setacl(mailbox, who, what)
        Set a mailbox acl.R2   N(   R&  R'  (   RX   Ru   RJ  t   whatR2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   setaclf  s    c         O   s   d | d <|  j  d | |  S(   sT   (typ, [data]) = setannotation(mailbox[, entry, attribute]+)
        Set ANNOTATIONs.RT  R.  R3   (   R&  (   RX   R   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   setannotationp  s    
c         K   s6   d | d <z |  j  d | | |  SWd |  j   Xd S(   sT   (typ, [data]) = setquota(root, limits)
        Set the quota root's resource limits.RX  R.  R4   N(   R&  R'  (   RX   RY  t   limitsR2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   setquotax  s    
c         O   sP   d } | d | d f d k r- d | } n  | | d <|  j  | | | | |  S(	   sl   (typ, [data]) = sort(sort_criteria, charset, search_criteria, ...)
        IMAP4rev1 extension SORT command.R5   i    iR6  R7  s   (%s)R.  (   R6  R7  (   R&  (   RX   t   sort_criteriaR  t   search_criteriaR2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   sort  s
    
R   c         K   s  d } | |  j  k r' |  j d   n  |  j rB |  j d   n  d |  _ t |  _ z |  j |  \ }	 }
 Wd |  j   |  j j	   t
 |  _ t |  _ X|	 d k r t j d |  j  |  _ |  j j t  |  j j   |  j d |
   n  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ z |  j   Wd t j d |  j  |  _ |  j j t  |  j j   X|  j   \ }	 }
 |
 d g k r|  j d	   n  t |
 d
 j   j    |  _  t |  _ |  j |	 |
 |  \ }	 }
 |  j |	 |
 |  S(   s   (typ, [data]) = starttls(keyfile=None, certfile=None, ca_certs=None, cert_verify_cb=None, ssl_version="ssl23", tls_level="tls_compat")
        Start TLS negotiation as per RFC 2595.R6   s   TLS not supported by servers   TLS session already establishedi   NRp   Rl   s"   Couldn't establish TLS session: %ss"   no CAPABILITY response from serveri(    R   R^   R   R   R   R   R&  R'  R   RC   Rh   R   RQ   R   R   R   R   Ri   R  R   R   R  R   R   R  R   RT   R   R   R   R/  R0  (   RX   R  R   R   R  R   R   R2  RK   R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   starttls  sH    			
	
							c         K   s&   d } | | d <|  j  | | | |  S(   s[   (typ, [data]) = status(mailbox, names)
        Request named status conditions for mailbox.R7   R.  (   R&  (   RX   Ru   t   namesR2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   status  s    
c         K   sJ   | d | d f d	 k r' d | } n  d | d <|  j  d | | | |  S(
   sl   (typ, [data]) = store(message_set, command, flags)
        Alters flag dispositions for messages in mailbox.i    iR6  R7  s   (%s)R    R.  R8   (   R6  R7  (   R&  (   RX   RF  t   commandR;  R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   store  s    
c         K   s)   z |  j  d | |  SWd |  j   Xd S(   sD   (typ, [data]) = subscribe(mailbox)
        Subscribe to new mailbox.R9   N(   R&  R'  (   RX   Ru   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt	   subscribe  s    c         O   s)   d } | | d <|  j  | | | | |  S(   sv   (type, [data]) = thread(threading_alogrithm, charset, search_criteria, ...)
        IMAPrev1 extension THREAD command.R:   R.  (   R&  (   RX   t   threading_algorithmR  R  R2  RK   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   thread  s    
c         O   sG   | j    } | t k r! | } n d } | | d <|  j d | | |  S(   s   (typ, [data]) = uid(command, arg, ...)
        Execute "command arg ..." with messages identified by UID,
            rather than message number.
        Assumes 'command' is legal in current state.
        Returns response appropriate to 'command'.R    R.  R;   (   R   t
   UID_directR&  (   RX   R  R   R2  t   resp(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   uid  s    	
c         K   s)   z |  j  d | |  SWd |  j   Xd S(   sJ   (typ, [data]) = unsubscribe(mailbox)
        Unsubscribe from old mailbox.R<   N(   R&  R'  (   RX   Ru   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   unsubscribe  s    c         O   sZ   | j    } | t k r1 |  j f t f t | <n  z |  j | | |  SWd |  j   Xd S(   s   (typ, [data]) = xatom(name, arg, ...)
        Allow simple extension commands notified by server in CAPABILITY response.
        Assumes extension command 'name' is legal in current state.
        Returns response appropriate to extension command 'name'.N(   R   R   Rq   Rh   R&  R'  (   RX   RK   R   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   xatom  s    c         C   s   | d  k r d } n  |  j j   |  j rV |  j d \ } } | | k r\ d  } q\ n d  } | d  k r g  } |  j j | | g  n  | j |  |  j j   |  j d d | t |  d | f  d  S(   NR>   ii   s&   untagged_responses[%s] %s += ["%.80s"]i   (   RT   R   R)  Rt   R>  R+  R_   R   (   RX   R]   R   t   urnt   urd(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   _append_untagged  s     		c         C   sc   |  j  d d t } | r_ t t k rI |  j | d j d d    q_ |  j | d   n  d  S(   NRx  Ry  iR   t   replace(   R   R   Ra   R   R^   t   decode(   RX   R|  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt
   _check_bye6  s
    "c         C   s   t  | t  s | St |  d k rI | d | d f d	 d
 f k rI | St |  d k r | d | d f d k r | d d !S| r |  j j |  d  k r | S|  j |  S(   Ni   i    iR6  R7  t   "t   'i   (   R6  R7  (   R  R  (   R  R  (   (   R  R  (   Rq  t   string_typesR   t   mustquote_creR  RT   R`  (   RX   Rb  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   _checkquote@  s    2,c         G   s{   t  | t  r t } n t |  } xP | D]H } | d  k	 r+ t  | |  rP | S|  j d d t |  | f  q+ q+ W| S(   Ni    s   bad arg is %s, expecting %s(   Rq  R  t   typeRT   R_   (   RX   t   dfltR   t   dflttypRb  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   P  s    	'c         O   sO  t  | t r d } n d } |  j d d | | | f  |  j d d  |  j j   |  j   | d k r |  j j   |  j d d  n |  j   |  j j   |  j	 r |  j
 j   t } n t } |  j j   | r|  j d d |  |  j
 j   |  j d d	 |  n  |  j t  | t k rgd  |  _ |  j d
 | |  j d j t  | t  f   n  |  j   | d" k r|  j j   g  |  _ |  j j   nd x' d# D] } x |  j |  rqqWqW|  j r|  j d d t rd  |  _ |  j d   n  |  j r"|  j d   n  |  j d | |  } d | j | f } x9 | D]1 }	 |	 d  k riqQn  d | |  j |	  f } qQW|  j }
 |
 d  k	 rd  |  _ t |
 t  rd  } d | t  |
  f } q|
 } n  |  j d d |  d | t! f | _" |
 d  k r"|  j# j$ |  | S|  j d | d d  } |  j# j$ |  x t rJ| j% d |  \ } } |  j d d | | f  | sPn  | d k rd  } n  | d  k	 r| | |  }
 n  |
 d  k rPn  | d  k	 r|  j d | d d  } n  |  j d d! t  |
   d |
 t! f | _" |  j# j$ |  | d  k rMPqMqMW| S($   Nt   asynct   synci   s
   [%s] %s %si   s   state_change_pending.acquires   state_change_pending.releases,   sync command %s waiting for empty commands Qs   sync command %s proceedings9   command %s illegal in state %s, only allowed in states %ss   , R   R1   Rp   Rw  R  s	   READ-ONLYRy  s#   mailbox status changed to READ-ONLYs   connection closedRK   s   %s %ss   %s {%s}i   s   data=%ss   %s%sRP   Rn   s   command: %s => %%ss   continuation => %s, %ss   go aheadR>   s   write literal size %s(   R   R1   (   Rp   Rw  R  (&   R   t   CMD_VAL_ASYNCR_   R   R)  t	   _end_idleR+  R  R   Rs   R   t   clearR   Rh   R`   Rq   t   CMD_VAL_STATESRT   Rr   Ri   RC   Rt   R   Rv   Rj   R   R^   R   RP   R  Rq  R  R   R:  RW   R   t   putRc   (   RX   RK   R   R2  t   cmdtypt
   need_eventR]   R  RW   Rb  Rr   t	   literatort   crqbt   ok(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR  ]  s    	

				*
			 					c         C   s   |  j    | j d | j  \ } } | d k rd |  j   |  j d | j | | | j f   n  d | k r |  j | | | d  S| | f S(   Ns   command: %s => %%sR  s%   %s command error: %s %s. Data: %.100sR.  (   R  Rc   RK   t
   _print_logRi   RW   R/  (   RX   R  R2  R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   _command_complete  s    

(c         C   s  | \ } } } | \ } } | d | _  | j d  | _ | d  k	 rp |  j   | \ } } | j | |  d  S|  j d d t }	 |	 r t t	 k r | j |  j |	 d j
 d d   n | j |  j |	 d  d  S| \ } }
 | d k r'|  j   | j |  j d	 | j | |
 | j f  d  S|  j d
 d | | | j f  d | k ro|  j | |
 | d  } n  | j |  d  S(   NRL   RY   Rx  Ry  iR   R  R  s%   %s command error: %s %s. Data: %.100si   s%   _command_completer(%s, %s, None) = %sR.  (   RL   t   getRM   RT   R  R^   R   R   Ra   R   R  Ri   RK   RW   R_   RP   R/  R\   (   RX   t   cb_arg_listRU   RY   Ri   R  R2  R]   RE   R|  R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   _command_completer  s0    
&
) c         C   s?   d | k r5 | d | | f | j  d  d  f  n  | | f S(   NRL   RY   (   R  RT   (   RX   R]   R   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR0    s    )c         C   sE   d | k r5 | d d  | j d  | | f f  n  | |   d  S(   NRL   RY   (   RT   R  (   RX   t   excR   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyRA    s    )c         C   s   |  j  j   |  j } | d  k r3 |  j  j   d  Sd  |  _ d  |  _ |  j  j   d t | _ |  j j	 |  |  j
 d d  d  S(   Ns   DONE%si   s   server IDLE finished(   R   R)  Rw   RT   R+  Rx   R:  RW   R   R  R_   (   RX   t   irqb(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR    s    			c         C   s   |  j  j   xm t |  j  D]\ \ } \ } } | | k r | sN |  j | =n  |  j  j   |  j d d | | f  | Sq W|  j  j   d  S(   Ni   s#   _get_untagged_response(%s) => %.80s(   R   R)  t	   enumerateRt   R+  R_   RT   (   RX   RK   Ry  R   R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    "c         C   s   | j  |  |  _ |  j d  k	 S(   N(   t   matcht   moRT   (   RX   t   creR   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   _match.  s    c   	      C   s  |  j  r t |  } t |  j |  } |  j d d |  j | f  |  j | 8_ |  j d k |  _  | | k r |  j j |  d  S|  j j | |   | | } n  |  j r |  j \ } } |  j | | d j	 |  j  f  g  |  _ n  | d  } |  j d d |  d |  j
 k r"t } n t } |  j d  k	 r| } |  j |  j |  r| |  j d <t |  _  t |  j j d	   |  _ |  j d
 d |  j  d  S|  j d } d  |  _ | r|  j | |  n  |  j d
 d  n|  j |  j |  r|  j j d  } |  j j d  } |  j j d  } | d k rw|  j |  j |  rw|  j |  j j d  |  j j d   n  | |  j
 k r|  j d d |  q|  j | | | g f  nd  } |  j |  j |  s|  j |  j |  r|  j j d  } qn  |  j d  k r|  j |  j |  ri| sC|  j d d |  d  S|  j d t |  j j d  f  d  S|  j d d |  d  S|  j j d  } |  j j d  } | d  k rd } n  | r| d | } n  |  j |  j |  r4t |  _  t |  j j d	   |  _ |  j d
 d |  j  | | g |  _ d  S|  j | |  | d k r|  j |  j |  r|  j |  j j d  |  j j d   n  | d k r|  j   n  | r|  j d t | f  n  | d k r	| d k rt |  _ n  |  j d d | | f  n  d  S(   Ni   s+   _put_response expecting data len %s, got %si    R>   is   _put_response(%s)Rn   i   R  i   s   expecting literal size %ss   literal completedRP   R  RW   Rp   Rw  R  s   unexpected tagged response: %st   data2s&   unexpected continuation response: '%s's   unexpected response: '%s'Rk   s   read literal size %sRx  s   %s response: %s(   Rp   Rw  R  (   Rp   Rw  R  (   Rw  R  Rx  (   Ry   R   t   minRz   R_   R{   R>  R|   R  RC   Rs   R   Rh   RT   R  R   R?   R  t   groupR   t   response_code_cret   _request_popt   untagged_response_creR   t   continuation_creR  R   (	   RX   R  t   rlent   dlenR]   R   t   continuation_expectedRP   t   dat2(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   _put_response7  s    		"
			!+" 	 	!+c         C   s    d | j  d d  j  d d  S(   Ns   "%s"s   \s   \\R  s   \"(   R  (   RX   Rb  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR`    s    c         C   s3   |  j  j   r/ |  j  j   |  j d d  n  d  S(   Ni   s   state_change_pending.release(   R   t   lockedR+  R_   (   RX   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR'    s    c         C   s   |  j  j   |  j j |  } |  j s1 t } n t } |  j  j   |  j d d | | t |  j  | j	 f  | j
 |  | r |  j d d  |  j j   n  d  S(   Ni   s   _request_pop(%s, %s) [%d] = %si   s   state_change_free.set(   R   R)  Rs   R*  R   Rh   R+  R_   R   RP   R\   R   Rd   (   RX   RK   RW   R  R  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR    s    		,c         K   s   |  j  j   t |  d | | } | d  k r: | j } n  | |  j | <|  j  j   |  j d d | | t |  | j f  | S(   NRK   i   s   _request_push(%s, %s, %s) = %s(	   R   R)  RI   RT   RP   Rs   R+  R_   R   (   RX   RP   RK   R2  R  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    )c      	   O   sQ   d | k r5 |  j  | d |  j d | d t | d S|  j |  j  | |  |  S(   NRL   RY   RZ   (   NN(   R  R  R   RT   R  (   RX   RK   R   R2  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR&    s    %c         C   s   | d k r | | f S|  j  |  } | s8 | d  g f Sx- t rg |  j  |  } | sZ Pn  | | 7} q; W|  j d d | | | f  | | f S(   NRw  i   s&   _untagged_response(%s, ?, %s) => %.80s(   R   RT   R   R_   (   RX   R]   R   RK   RW   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR/    s    
	c         C   se   |  j  d d  |  j j d   |  j j   |  j  d d  |  j   |  j j   |  j j   d  S(   Ni   R   s   call shutdown(	   R_   R   R  RT   R   RC   R   R   R   (   RX   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    
c   	      C   s,  |  j  } t j   j |  j d  t j d  |  j d d  |  j d } } x|  j	 s|  j
 j   |  j d  k	 r |  j t j   } | d k r d } n  |  j d  k	 r |  j d d |  q n | } |  j
 j   y |  j j t |  } Wn t j k
 r|  j d  k rZ| d  k	 rS |  j rS |  j d d	  |  j d
 | } } PqS qS n  |  j t j   k ruqS n  |  j d d  t } n X| d  k r|  j d d  Pn  t | t  s| \ } } Pn  y |  j |  WqS |  j d t j   d  } } PqS XqS Wt |  _	 |  j d d t |   x] |  j j   sy2 |  j j    } | d  k	 rr| j | |  n  Wq2t j k
 rPq2Xq2W|  j j! d   |  j" j   x? t# |  j j$    D]( } |  j j% |  } | j | |  qW|  j& j'   |  j" j   |  j d d  |  j d d  d  S(   Nt   handlerg?i   t   startings   connection terminatedi    i   s   server IDLING, timeout=%.2fs   response timeouts   no response after %s secsi   s   server IDLE timedouts   inq None - terminatings   program error: %s - %ss   terminating: %si   s   state_change_free.sett   finished((   R   RQ   t   currentThreadt   setNameR   t   timet   sleepR_   R^   R   R   R)  Rx   RT   Rw   R+  R   R  R   R   t   EmptyRs   t   IDLE_TIMEOUT_RESPONSERq  R  R  Ri   Rz  R{  R   R   t   emptyt
   get_nowaitR  R   Ri  t   keysR*  R   Rd   (	   RX   R   R]   RE   R   t   linet   qelRK   R  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     sr    		
			t   pollc         C   sh  t  j   j |  j d  |  j d d  d   } t t k rH d } n d } t j   } | j	 |  j
 t j  d } t } |  j d } x| p |  j sC|  j t k r d } n | } y| j |  } |  j d	 d
 t |   | s w n  | d \ }	 }
 |
 t j @r|  j |  j  } d } t |  } |  j d	 d |  | d k r| d 7} | d	 k rwt d   n  t j d  w n  d } xt rt t k r| j d |  } | d k  r| | | 7} Pn  | d 7} d | | | | | !j d d  } } } nY | j d |  } | d k  r=| | | 7} Pn  | d 7} d | | | | | !} } } |  j d d |  |  j j |  |  j rt } qqWn  |
 t j @rt | |
    n  Wq d t j   d  } |  j s"|  j    |  j! r|  j! d 7_! n  |  j d |  n  |  j j |  j" | f  Pq Xq W| j# |  j
  |  j d d  d  S(   Nt   readeri   s   starting using pollc         S   sX   i d t  j 6d t  j 6d t  j 6} d j g  | j   D] } | |  @r7 | | ^ q7  S(   Nt   Errors   Hang ups$   Invalid request: descriptor not openRk   (   RM  t   POLLERRt   POLLHUPt   POLLNVALRC   R  (   Rq   t
   PollErrorsR   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt
   poll_errorP  s
    

R>   i    i  i
   i   s
   poll => %ss   rcvd %ss   Too many read 0g?s   
t   errorst   ignorei   s   < %ss   socket error: %s - %si   R  ($   RQ   R  R  R   R_   R   Ra   RM  R  t   registerR   t   POLLINRh   R   R   Rq   R   R   R  R   R   t   IOErrorR  R  R   t   findR  R   R  R   Rz  R{  R  R   R^   t
   unregister(   RX   R  t	   line_partR  t   rxzerot	   terminateR   R   t   rt   fdRq   RW   R   R  t   stopR  t   reason(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   J  s    			
	
.
		
	 	c         C   s  t  j   j |  j d  |  j d d  t t k r? d } n d } d } t } x| p` |  j s|  j	 t
 k r{ d } n	 |  j } yt j |  j g g  g  |  \ } } } |  j d d | | | f  | s wT n  |  j |  j  } d }	 t |  }
 |  j d d |
  |
 d k rS| d 7} | d k r@t d	   n  t j d
  wT n  d } xt rht t k r| j d |	  } | d k  r| | |	 7} Pn  | d 7} d | | | |	 | !j d d  } }	 } nY | j d |	  } | d k  r| | |	 7} Pn  | d 7} d | | | |	 | !} }	 } |  j d d |  |  j j |  |  j r\t } q\q\WWqT d t j   d  } |  j s|  j   |  j r|  j d 7_ n  |  j d |  n  |  j j |  j | f  PqT XqT W|  j d d  d  S(   NR  i   s   starting using selectR>   i    i   s   select => %s, %s, %ss   rcvd %ss   Too many read 0g?s   
R  R  i   s   < %ss   socket error: %s - %si   R  (   RQ   R  R  R   R_   R   Ra   Rh   R   Rq   R   R   RM  R   R  R   R   R  R  R  R   R  R  R   R  R   Rz  R{  R  R   R^   (   RX   R  R  R  R   R  t   wR$  RW   R   R  R  R  R  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     sn    			'
	
.
		
	 	c         C   s*  t  j   j |  j d  |  j d d  d } x |  j s |  j j   } | d  k r[ Pn  y+ |  j	 | j
  |  j d d | j
  Wq3 d t j   d  } |  j s |  j   |  j r |  j d 7_ n  |  j d |  n  | j |  j |  Pq3 Xq3 W|  j j |  j | f  |  j d d	  d  S(
   Nt   writeri   R  t
   Terminatedi   s   > %ss   socket error: %s - %si   R  (   RQ   R  R  R   R_   R   R   R  RT   R  RW   Rz  R{  R  R   R^   R   R  (   RX   R  R  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s*    	
	 	c         C   s   t  j   |  _ |  j d | t  |  _ |  j t j |  |  _ |  j t	 |  |  _
 d |  _ d |  _ i  |  _ |  j r |  j d t  |  j d |  j |  j
 f  n  d  S(   Ni    i   s   imaplib2 version %ss(   imaplib2 debug level %s, buffer level %s(   RQ   R   t
   debug_lockR   t   DebugR   Rz  t   stderrR   t   DFLT_DEBUG_BUF_LVLR   t   _cmd_log_lent   _cmd_log_idxt   _cmd_logR   t   __version__(   RX   R   R   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    				c         C   s   | |  j  k r d  S|  j } | s& d  Sd } g  | D]; } d | d | d d rd d j | d  pg d f ^ q3 } |  j j   |  j d | | j |  f  |  j j   d  S(   Ns   
		s   %s: "%s"i    i   s   " "R>   s   untagged responses dump:%s%s(   R   Rt   RC   R  R)  R   R+  (   RX   t   lvlt   lt   tt   x(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR  $  s    	H c         C   s  | |  j  k r d  S| d t k r4 | d  d } n  t j   j   } | d k sd |  j  |  j k r |  j j   |  j | |  |  j j	   | d k r d  Sn  |  j j   | | t
 j
   f |  j |  j <|  j d 7_ |  j |  j k r d |  _ n  |  j j	   d  S(   Nis   \r\ni   i    (   R   R:  RQ   R  t   getNameR   R  R)  R   R+  R  R  R  R  (   RX   R
  R  t   tn(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR_   3  s"    c         C   s   | d  k r t j   } n  | d  k r< t j   j   } n  t j d t j |   } z9 |  j j d | | d d | | f  |  j j	   Wd  Xd  S(   Ns   %M:%Ss     %s.%02d %s %s
id   (
   RT   R  RQ   R  R  t   strftimet	   localtimeR   t   writeR  (   RX   R   R  t   secst   tm(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   L  s    (c         C   s   |  j  j   |  j |  j } } | r: |  j d |  n  xX | r y |  j |  j |   Wn n X| d 7} | |  j k r d } n  | d 8} q= W|  j  j   d  S(   Ns   last %d log messages:i   i    (   R  R)  R  R  R   R  R+  (   RX   R   t   n(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR  Y  s     	
	N(n   Re   Rf   Rg   R"  Ri   R^   Rj   R   R   R   R   R  R8  R  R  R  RT   R[   R   R   R   R   R   R  R  R  R  R   R   R(  R,  R3  RU   R>  RD  R   RE  R   R   RH  RI  RK  RL  RN  RO  RQ  RS  RW  RZ  R^  Rc  Re  Ri  Rl  Rn  Rm  R}  R~  R  R  R1  R  R  R  R  Rh   RM  R  R  R  R  R   R  R  R  R  R  R  R  R  R  R  R  R   R  R  R  R0  RA  R  R   R  R  R`  R'  R  R   R&  R/  R   R   R   t   select_moduleR   R   R   R  R_   R   R  (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR       s   On				"	C																					
												
									$	
			:			
	
				
			
			x								m								N_	G	%		c           B   sh   e  Z d  Z d d d d d d d d d d d d e d  Z d d d  Z d   Z d   Z d   Z	 RS(   sJ  IMAP4 client class over SSL connection

    Instantiate with:
        IMAP4_SSL(host=None, port=None, keyfile=None, certfile=None, ca_certs=None, cert_verify_cb=None, ssl_version="ssl23", debug=None, debug_file=None, identifier=None, timeout=None, debug_buf_lvl=None, tls_level="tls_compat")

        host           - host's name (default: localhost);
        port           - port number (default: standard IMAP4 SSL port);
        keyfile        - PEM formatted file that contains your private key (default: None);
        certfile       - PEM formatted certificate chain file (default: None);
        ca_certs       - PEM formatted certificate chain file used to validate server certificates (default: None);
        cert_verify_cb - function to verify authenticity of server certificates (default: None);
        ssl_version    - SSL version to use (default: "ssl23", choose from: "tls1","ssl3","ssl23");
        debug          - debug level (default: 0 - no debug);
        debug_file     - debug stream (default: sys.stderr);
        identifier     - thread identifier prefix (default: host);
        timeout        - timeout in seconds when expecting a command response.
        debug_buf_lvl  - debug level at which buffering is turned off.
        tls_level      - TLS security level (default: "tls_compat").

    The recognized values for tls_level are:
        tls_secure: accept only TLS protocols recognized as "secure"
        tls_no_ssl: disable SSLv2 and SSLv3 support
        tls_compat: accept all SSL/TLS versions

    For more documentation see the docstring of the parent class IMAP4.
    R   c      	   C   s\   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ t j |  | | | |	 |
 | |  d  S(   N(   R  R   R   R  R   R   R    R[   (   RX   R   R   R  R   R   R  R   R   R   R   R   R   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR[     s    						c         C   sG   |  j  d |  |  _ |  j  t |  |  _ |  j   |  _ |  j   d S(   s   open(host=None, port=None)
        Setup secure connection to remote server on "host:port"
            (default: localhost:standard IMAP4 SSL port).
        This connection will be used by the routines:
            read, send, shutdown, socket, ssl.R>   N(   R   R   t   IMAP4_SSL_PORTR   R   R   R  (   RX   R   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    c         C   s_   |  j  d k r |  j j |  S|  j  j r: |  j  j } n |  j j t  } |  j  j | |  S(   s@   data = read(size)
        Read at most 'size' bytes from remote.N(   R~   RT   R   R  R  R   R  (   RX   R  RW   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR    s    c         C   s   |  j  d k	 r= |  j  j |  } | |  j  j t j  7} n  t t k r[ t | d  } n  t |  j	 d  r |  j	 j
 |  nU t |  } xF | d k r |  j	 j |  } | | k r Pn  | | } | | } q Wd S(   s)   send(data)
        Send 'data' to remote.t   utf8R  i    N(   R}   RT   R  R  R  R  R   Ra   R   R   R  R   R  (   RX   RW   R  t   sent(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR    s    
c         C   s   |  j  S(   sR   ssl = ssl()
        Return ssl instance used to communicate with the IMAP4 server.(   R   (   RX   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s    N(
   Re   Rf   Rg   RT   R   R[   R   R  R  R   (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   j  s   0
		c           B   sP   e  Z d  Z d d d d d d  Z d d d  Z d   Z d   Z d   Z RS(   s  IMAP4 client class over a stream

    Instantiate with:
        IMAP4_stream(command, debug=None, debug_file=None, identifier=None, timeout=None, debug_buf_lvl=None)

        command        - string that can be passed to subprocess.Popen();
        debug          - debug level (default: 0 - no debug);
        debug_file     - debug stream (default: sys.stderr);
        identifier     - thread identifier prefix (default: host);
        timeout        - timeout in seconds when expecting a command response.
        debug_buf_lvl  - debug level at which buffering is turned off.

    For more documentation see the docstring of the parent class IMAP4.
    c      	   C   se   | |  _  | |  _ d  |  _ d  |  _ d \ |  _ |  _ d  |  _ t j	 |  d  d  | | | | |  d  S(   N(   NN(
   R  R   RT   R   R   t	   writefilet   readfileR   R    R[   (   RX   R  R   R   R   R   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR[     s    					c      
   C   s   d d l  m } m } |  j d d |  j  | |  j d t d | d | d t |  _ |  j j |  j j |  _	 |  _
 |  j
 j   |  _ d	 S(
   s   open(host=None, port=None)
        Setup a stream connection via 'self.command'.
        This connection will be used by the routines:
            read, send, shutdown, socket.i(   t   Popent   PIPEi    s    opening stream from command "%s"t   shellt   stdint   stdoutt	   close_fdsN(   t
   subprocessR  R  R_   R  R   t   _PR  R   R  R  R   R   (   RX   R   R   R  R  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s
    *c         C   se   |  j  d k r" t j |  j |  S|  j  j r= |  j  j } n t j |  j t  } |  j  j | |  S(   s   Read 'size' bytes from remote.N(   R~   RT   t   osR  R   R  R   R  (   RX   R  RW   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR    s    c         C   s|   |  j  d k	 r= |  j  j |  } | |  j  j t j  7} n  t t k r[ t | d  } n  |  j j	 |  |  j j   d S(   s   Send data to remote.R  N(
   R}   RT   R  R  R  R  R   Ra   R  R  (   RX   RW   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR  	  s    c         C   s   |  j  j   |  j j   d S(   s    Close I/O established in "open".N(   R  R   R  (   RX   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   	  s    N(	   Re   Rf   Rg   RT   R[   R   R  R  R   (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR     s   
		R?  c           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sQ   Private class to provide en/de-coding
    for base64 authentication conversation.c         C   s   | |  _  d  S(   N(   t   mech(   RX   t   mechinst(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR[   	  s    c         C   s5   |  j  |  j |   } | d  k r( d S|  j |  S(   NRf  (   R%  R  RT   Rr  (   RX   RW   R  t   ret(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR@  "	  s    c         C   s   t  t k r d } n d } xe | r t |  d k rM | d  } | d } n | } d } t j |  } | r | | d  } q q W| S(   NR>   i0   i(   R   Ra   R   t   binasciit
   b2a_base64(   RX   t   inpt   oupR  R$  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyRr  (	  s    			
c         C   s   | s
 d St  j |  S(   NR>   (   R(  t
   a2b_base64(   RX   R*  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR  A	  s    (   Re   Rf   Rg   R[   R@  Rr  R  (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR?  	  s
   			Rd  c           B   s    e  Z d  Z d   Z d   Z RS(   sW   When process is called, server is in IDLE state
    and will send asynchronous changes.c         C   s;   | |  _  | j t |  |  _ |  j t j   |  j  _ d  S(   N(   RJ   R   t   IDLE_TIMEOUTR   R  Rx   (   RX   RJ   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR[   N	  s    	c         C   sc   |  j  j j   | |  j  _ |  j t j   |  j  _ |  j  j j   |  j  j d d |  j  d  S(   Ni   s)   server IDLE started, timeout in %.2f secs(
   RJ   R   R)  Rw   R   R  Rx   R+  R_   RT   (   RX   RW   R  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR@  S	  s    (   Re   Rf   Rg   R[   R@  (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyRd  I	  s   	t   Jant   Febt   Mart   Aprt   Mayt   Junt   Jult   Augt   Sept   Octt   Novt   Decc         c   s   |  ] } | Vq d  S(   N(    (   t   .0R  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pys	   <genexpr>`	  s    i   s   .*INTERNALDATE "(?P<day>[ 0123][0-9])-(?P<mon>[A-Z][a-z][a-z])-(?P<year>[0-9][0-9][0-9][0-9]) (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9]) (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])"c      	   C   sv  t  j |   } | s d St | j d  } | j d  } t | j d   } t | j d   } t | j d   } t | j d   } t | j d   } t | j d   }	 t | j d	   }
 |	 d
 |
 d
 } | d k r | } n  | | | | | | d d d f	 } t j |  } t j |  } t j	 rX| d rX| t j
 } n | t j } t j | |  S(   sJ   time_tuple = Internaldate2Time(resp)
    Convert IMAP4 INTERNALDATE to UT.t   mont   zonent   dayt   yeart   hourR  t   sect   zoneht   zonemi<   t   -iN(   R   R  RT   R   R  R?   R  t   mktimeR  t   daylightt   altzonet   timezone(   R  R  R;  R<  R=  R>  R?  R  R@  RA  RB  t   zonet   ttt   utct   lt(    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   i	  s,    
!c         C   s   t  |  t t f  r' t j |   } nZ t  |  t t j f  rH |  } n9 t  |  t  ru |  d |  d f d k ru |  St d   t j	 r | d r t j
 } n
 t j } d | d t | d | d f | d d	 !t | d
 d
  S(   s{   '"DD-Mmm-YYYY HH:MM:SS +HHMM"' = Time2Internaldate(date_time)
    Convert 'date_time' to IMAP4 INTERNALDATE representation.i    iR  s   date_time not of a known types&   "%2d-%s-%04d %02d:%02d:%02d %+03d%02d"i   i   i   i   i<   (   R  R  (   Rq  R?   t   floatR  R  R   t   struct_timeRa   t
   ValueErrorRE  RF  RG  R   RA   (   R<  RI  RH  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   	  s    	)
's   .*FLAGS \((?P<flags>[^\)]*)\)c         C   s2   t  j |   } | s d St | j d  j    S(   sR   ('flag', ...) = ParseFlags(line)
    Convert IMAP4 flags response to python tuple.R;  (    (   t	   FLAGS_creR  R   R  R   (   R  R  (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyR   	  s    t   __main__s   Please run without -Os	   d:il:s:p:i   s   -ds   -is   -lt   :s   -ps   -sR>   s	   test.datai  sE   From: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)s%(data)sRj  s   
t   lfRW   Ri  s   ""t   %RH  t   imaplib2_test0R  t   imaplib2_test1t   imaplib2_test2R>  s   imaplib2_test%RM  R  t   SUBJECTs
   IMAP4 testRQ  s   '1:*'s   (FLAGS INTERNALDATE RFC822)R  t   1t   FLAGSs
   (\Deleted)R  RO  R3  R   RU   t   UIDVALIDITYR  RN  s   (FLAGS UID)R  t   ALLt
   referencess   UTF-8s   (SEEN)c         C   s   |  \ } } } | \ } } | d  k	 rN | a t j d d | | | f  d  S| \ } } t j d d | | | | f  | d k r t | d f a n  d  S(   Ni    s   [cb] ERROR %s %.100s => %ss   [cb] %s %.100s => %s %.100sRw  (   RT   t
   AsyncErrort   MR_   R"  (   R  RU   RY   Ri   t   cmdR   R]   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt	   responder
  s     c         C   sr  t  rE t j d d t t    t j   t  \ } } | |   n  t j sk t j d d |  | f  n  y | r t t |   d t d |  | f |  \ } } t j d d |  | | | f  n; t t |   |   \ } } t j d d |  | | | f  Wn2 t j d d t j	   d	   t j     n X| d
 k rnt j d d
  t j   t
 | d   n  | S(   Ni   s   AsyncError %si    s	   %s %.100sRL   RY   s   %s %.100s => %s %.100ss   %s - %si   Rw  (   R]  R^  R_   R   R}  R   R   R`  Rz  R{  R"  (   R_  R   t   cbR]   RE   R   (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   run 
  s,    
	 -#$

t   mainR   R   R  R   R   R   R   R   R   i
   R   R   s   IMAP password for %s on %s: t	   localhostRl  s   PROTOCOL_VERSION = %ss   COMPRESS=DEFLATERa  s   .*"([^"]+)"$RI  Rc  s   (name imaplib2)R   R$  s:   (FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)Re  i   ic   R1  s   fetch %s => %ss   -FLAGSs   (\Seen)s   HIT CTRL-C to interrupt IDLEs   Thanks!s-   chosen server does not report IDLE capabilityR}  s5   unused untagged responses in order, most recent last:s   	%s %ss   All tests OK.s   Tests failed.s8   
If you would like to see debugging output,
try: %s -d5
(   Rg   t   __all__R	  t   __release__t   __revision__t   __credits__t
   __author__t   __URL__t   __license__R(  R   R$  R   R   RM  R   Rz  R  RQ   R  R   Ra   R   R  R   t
   basestringR  R:  RT   R  R   R  R  R-  R   R   R  R   R   R   R   R  R  R   R   R   R   Rh   R   R   R  RH   t   objectRI   R    R   R   R?  Rd  R   t   dictRi  t   zipt   rangeR   R   R   R   t   Internaldate2tupleR   RO  R   Re   t	   __debug__RN  t   getoptt   getpasst   argvt   optlistR   Ri   RE   R   R   R   t   stream_commandR  R   t	   idle_intrt   optR?   R   R   t   getusert   USERR   t   patht   existst   __file__R  RW   t	   test_mesgt	   test_seq1t	   test_seq2R]  R^  R`  Rb  R  R  Rq   t   PASSWDRB   R_   R   R   R(  R_  t   mlR  R  R  t   unameR   R  R  RD   R   R   t   KeyboardInterruptR  R,  R]   (    (    (    s,   /usr/lib/python2.7/dist-packages/imaplib2.pyt   <module>   s  		 	
	5       cM/8	)		
#"	   
-									 	 	H'-" &! 
)
 	#