
    F\h                        S r SrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKJrJrJr  SSKJr   SSKrSr/ SQrS	rSrS
rSrSrSrSr0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S_S"S_S#S_S$S_0 S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_S2S_S3S_S4S_S5S_ESSSSSSSSS6.Er\R8                  " S75      r\R8                  " S85      r\R8                  " S95      r\R8                  " S:\R@                  5      r!\R8                  " S;5      r"\R8                  " S<5      r#\R8                  " S=5      r$\R8                  " S>\R@                  5      r%S:r&S>r' " S? S@5      r(\(       a   " SA SB\(5      r)\RU                  SB5         " SC SD\(5      r+ " SE SF5      r,SGR[                  SH5      r.\/" \.SIS 5       V Vs0 s H  u  pURa                  5       U SI-   _M     snn r1SJ r2SK r3SL r4SM r5\6SN:X  Ga  SSK7r7SSK8r8 \7Rn                  " \Rr                  SIS SO5      u  r:r;Sr>\: H,  u  r?r=\?SQ:X  a
  \@" \=5      rM  \?SR:X  d  M  \=r>\;(       a  M)  \>4r;M.     \;(       d  SSr;\;S   rA\8R                  " 5       rC\8Rp                  " ST\C< SU\A=(       d    SV< SW35      rDSX\CSYSZ.-  rES[\C\D44S\S]S^S_S`SS\E44SaSbScSdSeSfSgShSi4rFSjSkSlSmS_SSS\E44ShSn4rGSo rH \>(       a	  \+" \>5      rIO\(" \A5      rI\IR                  Sp:X  a  \FSIS rF\IR                  Sq\IR                  -  5        \IR                  Sr\IR                  < 35        \F H  u  rNr;\H" \N\;5        M     \H" SsSt5       HL  rO\R                  " Su\O5      rQ\Q(       a  \QR                  SI5      rSO\OR[                  5       Sv   rS\H" Sw\S45        MN     \G HG  u  rNr;\H" \N\;5      rT\N\;4Sl:w  a  M  \TSv   R[                  5       rU\U(       d  M5  \H" SxS Sy\USv   -  Sz45        MI     \V" S{5        gg! \ a    Sr GNf = fs  snn f ! \7Rx                   a  r=SPu  r:r; Sr=C=GNSr=C=ff = f!   \V" S|5        \(       d  \V" S}\Rr                  S   -  5        e = f)~zIMAP4 client.

Based on RFC 2060.

Public class:           IMAP4
Public variable:        Debug
Public functions:       Internaldate2tuple
                        Int2AP
                        ParseFlags
                        Time2Internaldate
z2.58    N)datetimetimezone	timedelta)DEFAULT_BUFFER_SIZETF)IMAP4IMAP4_streamInternaldate2tupleInt2AP
ParseFlagsTime2Internaldate   
   i  )	IMAP4REV1r   i@B i   APPEND)AUTHSELECTEDAUTHENTICATE)NONAUTH
CAPABILITY)r   r   r   LOGOUTCHECK)r   CLOSECOPYCREATEDELETE	DELETEACLENABLE)r   EXAMINEEXPUNGEFETCHGETACLGETANNOTATIONGETQUOTAGETQUOTAROOTMYRIGHTSLISTLOGINr   LSUBMOVE	NAMESPACENOOPPARTIAL	PROXYAUTHRENAMESEARCHSELECTSETACLSETANNOTATIONSETQUOTASORT)STARTTLSSTATUSSTORE	SUBSCRIBETHREADUIDUNSUBSCRIBEUNSELECTs   \+( (?P<data>.*))?s   .*FLAGS \((?P<flags>[^\)]*)\)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])"s   .*{(?P<size>\d+)}$s
   \r\n|\r|\ns%   \[(?P<type>[A-Z-]+)( (?P<data>.*))?\]s$   \* (?P<type>[A-Z-]+)( (?P<data>.*))?s3   \* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?c                   P   \ rS rSrSr " S S\5      r " S S\5      r " S S\5      rS	\	S
4S jr
S rS rS rS rS rS rS rS	\	S
4S jrS rS rS rS rS rS rS rS rS rS rS rS rS  rS! r S" r!S# r"S$ r#S% r$S& r%S' r&S( r'S) r(S* r)SXS+ jr*S, r+S- r,S. r-S/ r.SXS0 jr/S1 r0S2 r1S3 r2S4 r3S5 r4S6 r5S7 r6SYS8 jr7S9 r8S: r9S; r:S< r;SZS= jr<S> r=S? r>S@ r?SA r@SB rASC rBSD rCSE rDSF rESG rFSH rGSI rHSJ rISK rJS[SL jrKSM rLSN rMSO rNSP rOSQ rPSR rQ SZSS jrRST rSSU rTSV rUSWrVg
)\r      a  IMAP4 client class.

Instantiate with: IMAP4([host[, port[, timeout=None]]])

        host - host's name (default: localhost);
        port - port number (default: standard IMAP4 port).
        timeout - socket timeout (default: None)
                  If timeout is not given or is None,
                  the global default socket timeout is used

All IMAP4rev1 commands are supported by methods of the same
name (in lowercase).

All 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 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)").

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.

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.
c                       \ rS rSrSrg)IMAP4.error    N__name__
__module____qualname____firstlineno____static_attributes__rB       /usr/lib/python3.13/imaplib.pyerrorr@      s    DrI   rK   c                       \ rS rSrSrg)IMAP4.abort   rB   NrC   rB   rI   rJ   abortrM      s    rI   rO   c                       \ rS rSrSrg)IMAP4.readonly   rB   NrC   rB   rI   rJ   readonlyrQ      s    4rI   rS    Nc                 P   [         U l        SU l        S U l        0 U l        0 U l        SU l        SU l        SU l        SU l	        U R                  5         U R                  XU5         U R                  5         g ! [         a#     U R                  5         e ! [         a     e f = ff = f)Nr   rT   Fr   )Debugdebugstateliteraltagged_commandsuntagged_responsescontinuation_responseis_readonlytagnum_tls_established_mode_asciiopen_connect	ExceptionshutdownOSErrorselfhostporttimeouts       rJ   __init__IMAP4.__init__   s    

!"$%'"  % 			$g&	MMO 	   	s0   'A8 8
B%BB%
B!B% B!!B%c                     SU l         SU l        [        R                  " [        [        R
                  5      U l        [        R                  " [        [        R
                  5      U l        g )NFascii)	utf8_enabled	_encodingrecompile_LiteralASCIILiteral_Untagged_statusUntagged_statusrg   s    rJ   r`   IMAP4._mode_ascii   s?    ! zz(BHH5!zz*:BHHErI   c                     SU l         SU l        [        R                  " [        5      U l        [        R                  " [        5      U l        g )NTutf-8)ro   rp   rq   rr   rs   ru   rv   rw   rx   s    rJ   
_mode_utf8IMAP4._mode_utf8   s3      zz(+!zz*:;rI   c                 "   [        [        R                  " SS5      5      U l        [        R
                  " SU R                  -   S-   [        R                  5      U l         SU l        SU l	        0 U l
        U R                  S:  a6  U R                  S[        -  5        U R                  S	U R                  -  5        U R                  5       U l        S
U R                   ;   a  SU l        O3SU R                   ;   a  SU l        OU R%                  U R                  5      eU R'                  5          U R                  S:  a  U R                  SU R(                  < 35        [*         H  nXR(                  ;  a  M  Xl          g    U R%                  S5      e)Ni   i  s   (?P<tag>s"   \d+) (?P<type>[A-Z]+) (?P<data>.*)
   r      zimaplib version %sznew IMAP4 connection, tag=%sPREAUTHr   OKr      zCAPABILITIES: zserver not IMAP4 compliant)r
   randomrandinttagprerq   rr   rt   tagre_cmd_log_len_cmd_log_idx_cmd_logrW   _mesg__version___get_responsewelcomer[   rX   rK   _get_capabilitiescapabilitiesAllowedVersionsPROTOCOL_VERSION)rg   versions     rJ   rb   IMAP4._connect   sI    V^^D%89ZZ++!&@!ABD((L
  "D !DDMzzQ

/+=>

9DKKGH))+///DJT,,,"DJ**T\\** zzQ

1B1BDE&G///$+!	 ' jj566rI   c                 d    U[         ;   a  [        XR                  5       5      $ [        SU-  5      e)NzUnknown IMAP4 command: '%s')CommandsgetattrlowerAttributeError)rg   attrs     rJ   __getattr__IMAP4.__getattr__  s,    84..:TABBrI   c                     U $ NrB   rx   s    rJ   	__enter__IMAP4.__enter__  s    rI   c                 h    U R                   S:X  a  g  U R                  5         g ! [         a     g f = f)Nr   )rX   logoutre   )rg   argss     rJ   __exit__IMAP4.__exit__  s1    ::!	KKM 		s   $ 
11c                 :   Ub  U(       d  [        S5      eU R                  (       d  S OU R                  n[        R                  " SX R                  U R                  5        X R                  4nUb  [
        R                  " X15      $ [
        R                  " U5      $ )Nz0Non-blocking socket (timeout=0) is not supportedzimaplib.open)
ValueErrorrh   sysauditri   socketcreate_connection)rg   rj   rh   addresss       rJ   _create_socketIMAP4._create_socket&  su     wOPP99t$))		.$		499=#++G==''00rI   c                     Xl         X l        U R                  U5      U l        U R                  R	                  S5      U l        g)zSetup connection to remote server on "host:port"
    (default: localhost:standard IMAP4 port).
This connection will be used by the routines:
    read, readline, send, shutdown.
rbN)rh   ri   r   sockmakefilefilerf   s       rJ   ra   
IMAP4.open3  s6     		''0	II&&t,	rI   c                    [        U[        5      nU R                  R                  U5      nX!:  aT  [	        U5      U:X  aE  [        X!U-
  5      nX0R                  R                  U5      -  nX$-  nX!:  a  [	        U5      U:X  a  ME  U$ zRead 'size' bytes from remote.)min_SAFE_BUF_SIZEr   readlen)rg   sizecursizedatadeltas        rJ   r   
IMAP4.read?  st    dN+yy~~g&nTg!50EIINN5))DG nTg!5 rI   c                     U R                   R                  [        S-   5      n[        U5      [        :  a  U R	                  S[        -  5      eU$ )Read line from remote.r   zgot more than %d bytes)r   readline_MAXLINEr   rK   rg   lines     rJ   r   IMAP4.readlineJ  s@    yy!!(Q,/t9x**5@AArI   c                 h    [         R                  " SX5        U R                  R                  U5        g)Send data to remote.zimaplib.sendN)r   r   r   sendallrg   r   s     rJ   send
IMAP4.sendR  s"    		.$-		$rI   c                    U R                   R                  5          U R                  R                  [        R
                  5        U R                  R                  5         g! [         a:  nUR                  [        R                  :w  a  [        USS5      S:w  a  e  SnANZSnAff = f! U R                  R                  5         f = f) Close I/O established in "open".winerrorr   i&'  N)
r   closer   rd   r   	SHUT_RDWRre   errnoENOTCONNr   )rg   excs     rJ   rd   IMAP4.shutdownX  s    		
	IIv//0 IIOO  	 		U^^+3
A.%7	 IIOOs)   )A   
B$*0BB' B$$B' 'Cc                     U R                   $ )zVReturn socket instance used to connect to IMAP4 server.

socket = <instance>.socket()
)r   rx   s    rJ   r   IMAP4.socketh  s    
 yyrI   c                     SnU R                  SS/U5      u  p#US   (       a  X#4$ U R                  5       u  p#U R                  X#U5      $ )zReturn most recent 'RECENT' responses if any exist,
else prompt server for an update using the 'NOOP' command.

(typ, [data]) = <instance>.recent()

'data' is None if no new messages,
else list of RECENT responses, most recent last.
RECENTr   N)_untagged_responsenooprg   nametypdats       rJ   recentIMAP4.recentt  sO     **4$>r78O99;&&s66rI   c                 F    U R                  US/UR                  5       5      $ )zReturn data for response 'code' if received, or None.

Old value for response 'code' is cleared.

(code, [data]) = <instance>.response(code)
N)r   upper)rg   codes     rJ   responseIMAP4.response  s!     &&tdVTZZ\BBrI   c                    SnU(       d  SnU(       a  US   US   4S:w  a  SU-  nOSnU(       a  [        U5      nOSn[        R                  [        U5      nU R                  (       a  SU-   S	-   nX`l        U R                  XQX#5      $ )
zAppend message to named mailbox.

(typ, [data]) = <instance>.append(mailbox, flags, date_time, message)

        All args except `message' can be None.
r   INBOXr   r   ()(%s)Ns   UTF8 (   ))r   MapCRLFsubCRLFro   rY   _simple_command)rg   mailboxflags	date_timemessager   rY   s          rJ   appendIMAP4.append  s     Gar#y0E))4II++dG,')D0G##D5DDrI   c                     UR                  5       n[        U5      R                  U l        U R	                  SU5      u  pEUS:w  a$  U R                  US   R                  SS5      5      eSU l        XE4$ )a#  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; the
response argument it is passed will be a bytes.  It should return bytes
data that will be base64 encoded and sent to the server.  It should
return None if the client abort response '*' should be sent instead.
r   r   r   r{   replacer   )r   _AuthenticatorprocessrY   r   rK   decoderX   )rg   	mechanism
authobjectmechr   r   s         rJ   authenticateIMAP4.authenticate  sk       
 &j199''=$;**SW^^GY?@@
xrI   c                 P    SnU R                  U5      u  p#U R                  X#U5      $ )zL(typ, [data]) = <instance>.capability()
Fetch capabilities list from server.r   r   r   r   s       rJ   
capabilityIMAP4.capability  s.     ''-&&s66rI   c                 $    U R                  S5      $ )zBCheckpoint mailbox on server.

(typ, [data]) = <instance>.check()
r   r   rx   s    rJ   checkIMAP4.check  s    
 ##G,,rI   c                 V     U R                  S5      u  pSU l        X4$ ! SU l        f = f)zClose currently selected mailbox.

Deleted messages are removed from writable mailbox.
This is the recommended command before 'LOGOUT'.

(typ, [data]) = <instance>.close()
r   r   r   rX   rg   r   r   s      rJ   r   IMAP4.close  s2    	 ++G4HCDJx  DJ    	(c                 &    U R                  SX5      $ )zrCopy 'message_set' messages onto end of 'new_mailbox'.

(typ, [data]) = <instance>.copy(message_set, new_mailbox)
r   r  )rg   message_setnew_mailboxs      rJ   copy
IMAP4.copy  s    
 ##FKEErI   c                 &    U R                  SU5      $ )z@Create new mailbox.

(typ, [data]) = <instance>.create(mailbox)
r   r  rg   r   s     rJ   createIMAP4.create      
 ##Hg66rI   c                 &    U R                  SU5      $ )z@Delete old mailbox.

(typ, [data]) = <instance>.delete(mailbox)
r   r  r  s     rJ   deleteIMAP4.delete  r  rI   c                 &    U R                  SX5      $ )zpDelete the ACLs (remove any rights) set for who on mailbox.

(typ, [data]) = <instance>.deleteacl(mailbox, who)
r   r  )rg   r   whos      rJ   	deleteaclIMAP4.deleteacl  s    
 ##K>>rI   c                     SU R                   ;  a  [        R                  S5      eU R                  SU5      u  p#US:X  a$  SUR	                  5       ;   a  U R                  5         X#4$ )z\Send an RFC5161 enable string to the server.

(typ, [data]) = <instance>.enable(capability)
r   zServer does not support ENABLEr   zUTF8=ACCEPT)r   r   rK   r   r   r|   )rg   r  r   r   s       rJ   enableIMAP4.enable  s_    
 4,,,++>??((:>	$;=J,<,<,>>OOyrI   c                 P    SnU R                  U5      u  p#U R                  X#U5      $ )zPermanently remove deleted items from selected mailbox.

Generates 'EXPUNGE' response for each deleted message.

(typ, [data]) = <instance>.expunge()

'data' is list of 'EXPUNGE'd message numbers in order received.
r   r  r   s       rJ   expungeIMAP4.expunge  s.     ''-&&s66rI   c                 R    SnU R                  X1U5      u  pEU R                  XEU5      $ )zFetch (parts of) messages.

(typ, [data, ...]) = <instance>.fetch(message_set, message_parts)

'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.
r    r  )rg   r  message_partsr   r   r   s         rJ   fetchIMAP4.fetch"  s0     ''=I&&s66rI   c                 N    U R                  SU5      u  p#U R                  X#S5      $ )zHGet the ACLs for a mailbox.

(typ, [data]) = <instance>.getacl(mailbox)
r!   ACLr  rg   r   r   r   s       rJ   getaclIMAP4.getacl1  s+    
 ''':&&s77rI   c                 P    U R                  SXU5      u  pEU R                  XES5      $ )zY(typ, [data]) = <instance>.getannotation(mailbox, entry, attribute)
Retrieve ANNOTATIONs.r"   
ANNOTATIONr  )rg   r   entry	attributer   r   s         rJ   getannotationIMAP4.getannotation:  s-     ''S&&s>>rI   c                 N    U R                  SU5      u  p#U R                  X#S5      $ )zGet the quota root's resource usage and limits.

Part of the IMAP4 QUOTA extension defined in rfc2087.

(typ, [data]) = <instance>.getquota(root)
r#   QUOTAr  )rg   rootr   r   s       rJ   getquotaIMAP4.getquotaB  s+     ''
D9&&s99rI   c                     U R                  SU5      u  p#U R                  X#S5      u  p$U R                  X#S5      u  p%X%U/4$ )zGet the list of quota roots for the named mailbox.

(typ, [[QUOTAROOT responses...], [QUOTA responses]]) = <instance>.getquotaroot(mailbox)
r$   r7  	QUOTAROOTr  )rg   r   r   r   quota	quotaroots         rJ   getquotarootIMAP4.getquotarootM  sN    
 ''@,,Sw?
00;G&&&rI   c                 R    SnU R                  X1U5      u  pEU R                  XEU5      $ )zList mailbox names in directory matching pattern.

(typ, [data]) = <instance>.list(directory='""', pattern='*')

'data' is list of LIST responses.
r&   r  rg   	directorypatternr   r   r   s         rJ   list
IMAP4.listX  0     ''A&&s66rI   c                     U R                  SXR                  U5      5      u  p4US:w  a  U R                  US   5      eSU l        X44$ )z|Identify client using plaintext password.

(typ, [data]) = <instance>.login(user, password)

NB: 'password' will be quoted.
r'   r   r   r   )r   _quoterK   rX   )rg   userpasswordr   r   s        rJ   loginIMAP4.logind  sI     ''{{87LM$;**SW%%
xrI   c                 V    XsU l         U l        U R                  SU R                  5      $ )zaForce use of CRAM-MD5 authentication.

(typ, [data]) = <instance>.login_cram_md5(user, password)
zCRAM-MD5)rJ  rK  r  _CRAM_MD5_AUTH)rg   rJ  rK  s      rJ   login_cram_md5IMAP4.login_cram_md5r  s+    
 $( 	4=  T-@-@AArI   c                     SSK n[        U R                  [        5      (       a  U R                  R	                  S5      OU R                  nU R
                  S-   UR                  X1S5      R                  5       -   $ )z0Authobject to use with CRAM-MD5 authentication. r   Nr{    md5)hmac
isinstancerK  strencoderJ  HMAC	hexdigest)rg   	challengerU  pwds       rJ   rO  IMAP4._CRAM_MD5_AUTH{  sZ    0:4==#0N0Nt}}##G,26-- 	yy335!A!K!K!MMMrI   c                 \    SU l         U R                  S5      u  pU R                  5         X4$ )zdShutdown connection to server.

(typ, [data]) = <instance>.logout()

Returns server 'BYE' response.
r   )rX   r   rd   r  s      rJ   r   IMAP4.logout  s-     
''1xrI   c                 R    SnU R                  X1U5      u  pEU R                  XEU5      $ )zList 'subscribed' mailbox names in directory matching pattern.

(typ, [data, ...]) = <instance>.lsub(directory='""', pattern='*')

'data' are tuples of message part envelope and data.
r(   r  rB  s         rJ   lsub
IMAP4.lsub  rG  rI   c                 N    U R                  SU5      u  p#U R                  X#S5      $ )zsShow my ACLs for a mailbox (i.e. the rights that I have on mailbox).

(typ, [data]) = <instance>.myrights(mailbox)
r%   r  r-  s       rJ   myrightsIMAP4.myrights  s+    
 &&z7;&&s<<rI   c                 P    SnU R                  U5      u  p#U R                  X#U5      $ )zQReturns IMAP namespaces ala rfc2342

(typ, [data, ...]) = <instance>.namespace()
r*   r  r   s       rJ   	namespaceIMAP4.namespace  s.    
 ''-&&s66rI   c                 |     U R                   S:  a  U R                  U R                  5        U R                  S5      $ )z6Send NOOP command.

(typ, [data]) = <instance>.noop()
r   r+   )rW   _dump_urr[   r   rx   s    rJ   r   
IMAP4.noop  s5    
 zzQd556##F++rI   c                 T    SnU R                  XQX#U5      u  pgU R                  XgS5      $ )zFetch truncated part of a message.

(typ, [data, ...]) = <instance>.partial(message_num, message_part, start, length)

'data' is tuple of message part envelope and data.
r,   r    r  )rg   message_nummessage_partstartlengthr   r   r   s           rJ   partialIMAP4.partial  s3     ''<PVW&&s99rI   c                 *    SnU R                  SU5      $ )zAssume authentication as "user".

Allows an authorised administrator to proxy into any user's
mailbox.

(typ, [data]) = <instance>.proxyauth(user)
r-   r  )rg   rJ  r   s      rJ   	proxyauthIMAP4.proxyauth  s     ##K66rI   c                 &    U R                  SX5      $ )z[Rename old mailbox name to new.

(typ, [data]) = <instance>.rename(oldmailbox, newmailbox)
r.   r  )rg   
oldmailbox
newmailboxs      rJ   renameIMAP4.rename  s    
 ##HjEErI   c                     SnU(       a>  U R                   (       a  [        R                  S5      eU R                  " USU/UQ76 u  pEOU R                  " U/UQ76 u  pEU R	                  XEU5      $ )zSearch mailbox for matching messages.

(typ, [data]) = <instance>.search(charset, criterion, ...)

'data' is space separated list of matching message numbers.
If UTF8 is enabled, charset MUST be None.
r/   z'Non-None charset not valid in UTF8 modeCHARSET)ro   r   rK   r   r   )rg   charsetcriteriar   r   r   s         rJ   searchIMAP4.search  sl       kk"KLL++D)WPxPHC++D<8<HC&&s66rI   c                 r   0 U l         X l        U(       a  SnOSnU R                  X15      u  pEUS:w  a
  SU l        XE4$ SU l        SU R                   ;   aG  U(       d@   U R                  S:  a  U R                  U R                   5        U R                  SU-  5      eX@R                   R                  S	S
/5      4$ )aD  Select a mailbox.

Flush all untagged responses.

(typ, [data]) = <instance>.select(mailbox='INBOX', readonly=False)

'data' is count of messages in mailbox ('EXISTS' response).

Mandated responses are ('FLAGS', 'EXISTS', 'RECENT', 'UIDVALIDITY'), so
other responses should be obtained via <instance>.response('FLAGS') etc.
r   r0   r   r   r   	READ-ONLYr   z%s is not writableEXISTSN)r[   r]   r   rX   rW   rj  rS   get)rg   r   rS   r   r   r   s         rJ   selectIMAP4.select  s     #%#DD''6$;DJ8O
$111 ::?MM$"9"9:-- 4w >??++//4&AAArI   c                 (    U R                  SXU5      $ )zJSet a mailbox acl.

(typ, [data]) = <instance>.setacl(mailbox, who, what)
r1   r  )rg   r   r  whats       rJ   setaclIMAP4.setacl  s    
 ##HgDAArI   c                 P    U R                   " S/UQ76 u  p#U R                  X#S5      $ )zW(typ, [data]) = <instance>.setannotation(mailbox[, entry, attribute]+)
Set ANNOTATIONs.r2   r1  r  )rg   r   r   r   s       rJ   setannotationIMAP4.setannotation  s.     ''?$?&&s>>rI   c                 N    U R                  SX5      u  p4U R                  X4S5      $ )zYSet the quota root's resource limits.

(typ, [data]) = <instance>.setquota(root, limits)
r3   r7  r  )rg   r8  limitsr   r   s        rJ   setquotaIMAP4.setquota  s+    
 ''
DA&&s99rI   c                 |    SnUS   US   4S:w  a  SU-  nU R                   " XAU/UQ76 u  pVU R                  XVU5      $ )zqIMAP4rev1 extension SORT command.

(typ, [data]) = <instance>.sort(sort_criteria, charset, search_criteria, ...)
r4   r   r   r   r   r  )rg   sort_criteriar}  search_criteriar   r   r   s          rJ   sort
IMAP4.sort$  sX    
  !]2./9<"]2M''WWW&&s66rI   c                 ,   Sn[         (       d  U R                  S5      eU R                  (       a  U R                  S5      eX R                  ;  a  U R                  S5      eUc  [
        R                  " 5       nU R                  U5      u  p4US:X  aa  UR                  U R                  U R                  S9U l	        U R                  R                  S5      U l        SU l        U R                  5         OU R                  S	5      eU R                  X4U5      $ )
Nr5   zSSL support missingzTLS session already establishedzTLS not supported by serverr   server_hostnamer   TzCouldn't establish TLS session)HAVE_SSLrK   r_   rO   r   ssl_create_stdlib_contextr   wrap_socketr   rh   r   r   r   r   )rg   ssl_contextr   r   r   s        rJ   starttlsIMAP4.starttls2  s    x**233  **>??(((**:;;446K''-$;#//		@D		 0 KDI		**40DI$(D!""$**=>>&&s66rI   c                 R    SnU R                  X1U5      u  pEU R                  XEU5      $ )z`Request named status conditions for mailbox.

(typ, [data]) = <instance>.status(mailbox, names)
r6   r  )rg   r   namesr   r   r   s         rJ   statusIMAP4.statusI  s2    
  ''u=&&s66rI   c                 v    US   US   4S:w  a  SU-  nU R                  SXU5      u  pEU R                  XES5      $ )zqAlters flag dispositions for messages in mailbox.

(typ, [data]) = <instance>.store(message_set, command, flags)
r   r   r   r   r7   r    r  )rg   r  commandr   r   r   s         rJ   storeIMAP4.storeU  sK    
 !HU2Y9,UNE''uM&&s99rI   c                 &    U R                  SU5      $ )zISubscribe to new mailbox.

(typ, [data]) = <instance>.subscribe(mailbox)
r8   r  r  s     rJ   	subscribeIMAP4.subscribe`  s    
 ##K99rI   c                 V    SnU R                   " XAU/UQ76 u  pVU R                  XVU5      $ )z{IMAPrev1 extension THREAD command.

(type, [data]) = <instance>.thread(threading_algorithm, charset, search_criteria, ...)
r9   r  )rg   threading_algorithmr}  r  r   r   r   s          rJ   threadIMAP4.threadh  s5    
 ''7]_]&&s66rI   c                 n   UR                  5       nU[        ;  a  U R                  SU-  5      eU R                  [        U   ;  a=  U R                  SU< SU R                  < SSR	                  [        U   5      < 35      eSnU R
                  " X1/UQ76 u  pEUS;   a  UnOSnU R                  XEU5      $ )	zExecute "command arg ..." with messages identified by UID,
        rather than message number.

(typ, [data]) = <instance>.uid(command, arg1, arg2, ...)

Returns response appropriate to 'command'.
zUnknown IMAP4 UID command: %scommand  illegal in state , only allowed in states , r:   )r/   r4   r9   r    )r   r   rK   rX   joinr   r   )rg   r  r   r   r   r   s         rJ   uid	IMAP4.uidr  s     --/("**<wFGG::Xg..**%tzz"ii(9:< = = ''==22DD&&s66rI   c                 &    U R                  SU5      $ )zOUnsubscribe from old mailbox.

(typ, [data]) = <instance>.unsubscribe(mailbox)
r;   r  r  s     rJ   unsubscribeIMAP4.unsubscribe  s    
 ##M7;;rI   c                 V     U R                  S5      u  pSU l        X4$ ! SU l        f = f)a  Free server's resources associated with the selected mailbox
and returns the server to the authenticated state.
This command performs the same actions as CLOSE, except
that no messages are permanently removed from the currently
selected mailbox.

(typ, [data]) = <instance>.unselect()
r<   r   r  )rg   r   r   s      rJ   unselectIMAP4.unselect  s3    	 ,,Z8ICDJy  DJr  c                     UR                  5       nU[        ;  a  U R                  4[        U'   U R                  " U/UQ76 $ )zAllow simple extension commands
        notified by server in CAPABILITY response.

Assumes command is legal in current state.

(typ, [data]) = <instance>.xatom(name, arg, ...)

Returns response appropriate to extension command `name'.
)r   r   rX   r   rg   r   r   s      rJ   xatomIMAP4.xatom  s>     zz| x"jj]HTN##D0400rI   c                     Uc  SnU R                   n U R                  S:  a7  U R                  SU< S[        UR	                  US5      5      < SU< S35        X;   a  X1   R                  U5        g U/X1'   g )NrI      untagged_responses[z] rT   z += ["z"])r[   rW   r   r   r  r   )rg   r   r   urs       rJ   _append_untaggedIMAP4._append_untagged  sh    ;C$$zzQ

c"&&R.138 99GNN3eBGrI   c                     U R                   R                  S5      nU(       a.  U R                  US   R                  U R                  S5      5      eg )NBYEr   r   )r[   r  rO   r   rp   )rg   byes     rJ   
_check_byeIMAP4._check_bye  sB    %%))%0**SW^^DNNIFGG rI   c                    U R                   [        U   ;  aD  S U l        U R                  SU< SU R                   < SSR	                  [        U   5      < 35      eS H!  nX0R
                  ;   d  M  U R
                  U	 M#     SU R
                  ;   a"  U R                  (       d  U R                  S5      eU R                  5       n[        XR                  5      nUS-   U-   nU H:  nUc  M  [        U[        5      (       a  [        X`R                  5      nUS-   U-   nM<     U R                  nUbR  S U l        [        U5      [        U R                  5      L a  UnO'S nU[        S	[        U5      -  U R                  5      -   n U R                   S
:  a  U R#                  SU-  5        OU R%                  SU-  5         U R'                  U[(        -   5        Uc  U$  U R/                  5       (       a-  U R0                  U   (       a  U$ U R/                  5       (       a  M-  W(       a  U" U R2                  5      n U R                   S
:  a  U R#                  S[        U5      -  5         U R'                  U5        U R'                  [(        5        U(       d   U$ M  ! [*         a  n	U R-                  SU	-  5      eS n	A	ff = f! [*         a  n	U R-                  SU	-  5      eS n	A	ff = f)Nr  r  r  r  r   NOBADr  z#mailbox status changed to READ-ONLY    z {%s}   z> %rzsocket error: %szwrite literal size %s)rX   r   rY   rK   r  r[   r]   rS   _new_tagbytesrp   rV  rW  type_commandr   rW   r   _logr   r   re   rO   r   rZ   r\   )
rg   r   r   r   tagr   argrY   	literatorvals
             rJ   r  IMAP4._command  s   ::Xd^+DL**"DJJ"ii79 : :
 'C---++C0 ' $111  -- EFFmmoT>>*TzD C{H#s##C0$;$D	  ,,DLG}T]] 33#	 	eGc'l$:DNNKKzzQ

6D=)		&4-(	7IIdTk" ?J $$&&'',J $$&& #D$>$>?::?JJ6WEF;		'"		$ 
3   	7**/#566	72  ;jj!3c!9::;s0   >J &&J> 
J;"J66J;>
K!KK!c                    US:H  nU(       d  U R                  5          U R                  X#S9u  pEU(       d  U R                  5         US:X  a  U R                  U< SU< SU< 35      eXE4$ ! U R                   a  nU R                  SU< SU< 35      eS nAfU R                   a  nU R                  SU< SU< 35      eS nAff = f)Nr   )
expect_byez	command:  => r  z command error: rS  )r  _get_tagged_responserO   rK   )rg   r   r  r   r   r   r  s          rJ   _command_completeIMAP4._command_complete  s    ("OO	@11#1IIC
 OO%<**$TJKKy zz 	@**D#>??zz 	@**D#>??	@s#   A+ +C;BC'C  Cc                     U R                  5       u  pUS /:X  a  U R                  S5      e[        US   U R                  5      nUR	                  5       n[        UR                  5       5      U l        g )Nz"no CAPABILITY response from serverr   )r  rK   rW  rp   r   tuplesplitr   r  s      rJ   r   IMAP4._get_capabilities,  s[    ??$4&=**ABB#b'4>>*iik!#))+.rI   c                    U R                  5       nU R                  U R                  U5      (       a  U R                  R	                  S5      nX R
                  ;  a  U R                  SU-  5      eU R                  R	                  S5      n[        X0R                  5      nU R                  R	                  S5      nX4/4U R
                  U'   GOS nU R                  [        U5      (       d<  U R                  U R                  U5      (       a  U R                  R	                  S5      nU R                  cP  U R                  [        U5      (       a!  U R                  R	                  S5      U l        g U R                  SU-  5      eU R                  R	                  S5      n[        X0R                  5      nU R                  R	                  S5      nUc  SnU(       a  US-   U-   nU R                  U R                  U5      (       a  [        U R                  R	                  S	5      5      n U R                  S
:  a  U R!                  SU-  5        U R#                  U5      nU R%                  X4U45        U R                  5       nU R                  U R                  U5      (       a  M  U R%                  X45        US;   au  U R                  [&        U5      (       aZ  U R                  R	                  S5      n[        X0R                  5      nU R%                  X0R                  R	                  S5      5         U R                  S:  a  US;   a  U R!                  U< SU< 35        U$ )Nr  zunexpected tagged response: %rr  r   data2zunexpected response: %rrI   r  r   r  zread literal size %sr  r   )r  r  r  z response: )	_get_line_matchr   mogrouprZ   rO   rW  rp   Untagged_responserw   Continuationr\   ru   intrW   r   r   r  Response_code)rg   respr  r   r   dat2r   r   s           rJ   r   IMAP4._get_response5  s    ~~ ;;tzz4((''--&C...jj!AD!HII''--'Cc>>*C''--'C),eD  %D ;;0$77;;t33T::77==1Dww ;;|T2215v1FD.jj!:T!ABB''--'Cc>>*C''--'C{#C3:,S ++dllC00 477==01zzQ

#9D#@Ayy %%c;7 nn&! ++dllC00$ !!#+ %%$++mS*I*I''--'Cc>>*C!!#ww}}V'<=zzQ3*>#>

S9:rI   c                 V    U R                   U   nUb  U R                   U	 U$ U(       a$  SnU R                  R                  US 5      nUb  XE4$ U R                  5          U R	                  5         Mo  ! U R
                   a'  n U R                  S:  a  U R                  5         e S nAff = f)Nr   r  )rZ   r[   popr  r   rO   rW   	print_log)rg   r  r  resultr   r  r  s          rJ   r  IMAP4._get_tagged_response  s    ))#.F!((---11#t<?:% OO""$/ 0 :: zzQ(	s   A1 1B("B##B(c                 *   U R                  5       nU(       d  U R                  S5      eUR                  S5      (       d  U R                  SU-  5      eUS S n U R                  S:  a  U R	                  SU-  5        U$ U R                  SU-  5        U$ )Nzsocket error: EOFr   z#socket error: unterminated line: %rr  z< %r)r   rO   endswithrW   r   r  r   s     rJ   r  IMAP4._get_line  s    }}**011 }}W%%**BTIJJCRyzzQ

6D=)  		&4-(rI   c                     UR                  U5      U l         U R                  bK  U R                  S:  a;  U R                  SUR                  < SU R                  R                  5       < 35        U R                  S L$ )Nr  z		matched r  )matchr  rW   r   rD  groups)rg   cress      rJ   r  IMAP4._match  sY    
 ))A,ww"tzzQ

3;;@PQRwwd""rI   c                     U R                   [        [        U R                  5      U R                  5      -   nU R                  S-   U l        S U R
                  U'   U$ )Nr   )r   r  rW  r^   rp   rZ   )rg   r  s     rJ   r  IMAP4._new_tag  sH    kkE#dkk"2DNNCCkkAo$(S!
rI   c                 Z    UR                  SS5      nUR                  SS5      nSU-   S-   $ )N\z\\"z\")r   )rg   r  s     rJ   rI  IMAP4._quote  s0    kk$'kk#u%Sy3rI   c                 F    U R                  XR                  " U/UQ76 5      $ r   )r  r  r  s      rJ   r   IMAP4._simple_command  s!    %%dMM$,F,FGGrI   c                     US:X  a  X4$ X0R                   ;  a  US /4$ U R                   R                  U5      n U R                  S:  a  U R                  SU< SU< 35        X4$ )Nr  r  r  z] => )r[   r  rW   r   )rg   r   r   r   r   s        rJ   r   IMAP4._untagged_response  se    $;8O...;&&**40zzQ

T4HIyrI   c                    Uc  [         R                   " 5       n[         R                  " S[         R                  " U5      5      n[        R                  R                  SX2S-  S-  U4-  5        [        R                  R                  5         g )Nz%M:%Sz  %s.%02d %s
d   )timestrftime	localtimer   stderrwriteflush)rg   r  secstms       rJ   r   IMAP4._mesg  s`    |yy{wt(<=BJJ-3h^Q0GGHJJrI   c                     U(       d  g S UR                  5        5       nU R                  SSR                  U5      -   5        g )Nc              3   6   #    U  H  u  pU S U< 3v   M     g7f): NrB   ).0keyvalues      rJ   	<genexpr>!IMAP4._dump_ur.<locals>.<genexpr>  s%      B&@
 uBui(&@s   zuntagged responses dump:z
		)itemsr   r  )rg   untagged_resp_dictr   s      rJ   rj  IMAP4._dump_ur  s=    %B&8&>&>&@BEJJ1HMM%4HHIrI   c                     U[         R                   " 5       4U R                  U R                  '   U =R                  S-  sl        U R                  U R                  :  a  SU l        g g )Nr   r   )r  r   r   r   r   s     rJ   r  
IMAP4._log  sS    04diik/BDMM$++,"  D$5$55$%! 6rI   c                     U R                  S[        U R                  5      -  5        U R                  U R                  p!U(       aB   U R                   " U R                  U   6   US-  nXR                  :  a  SnUS-  nU(       a  MA  g g !    N*= f)Nzlast %d IMAP4 interactions:r   r   )r   r   r   r   r   )rg   ins      rJ   r  IMAP4.print_log  s    JJ4s4==7IIJ$$d&7&7qJJa 01 Q)))AQ !s   B	 	B)ru   r   rw   r   r   r   rp   r_   r   r\   rW   r   rh   r]   rY   r  rK  ri   r   rX   rZ   r^   r   r   r[   rJ  ro   r   )z""*)r   Fr   )F)WrD   rE   rF   rG   __doc__rc   rK   rO   rS   
IMAP4_PORTrk   r`   r|   rb   r   r   r   r   ra   r   r   r   rd   r   r   r   r   r  r  r	  r   r  r  r  r  r"  r%  r)  r.  r4  r9  r?  rE  rL  rP  rO  r   ra  rd  rg  r   rq  rt  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r  r  r  rI  r   r   r   rj  r  r  rH   rB   rI   rJ   r   r      s   -^ !	 5Z 2F<'7TC1 T 	-  7"CE4:7-F77?
778?:'	7BN
	7=7,	:
7F7$B@B?:77.	7::772< 1,HJZ$/M`B&	#H
	 		J	&	rI   r   c                   F    \ rS rSrSrS\4SSS.S jjrS rS\S4S jrS	r	g)
	IMAP4_SSLi  a?  IMAP4 client class over SSL connection

Instantiate with: IMAP4_SSL([host[, port[, ssl_context[, timeout=None]]]])

        host - host's name (default: localhost);
        port - port number (default: standard IMAP4 SSL port);
        ssl_context - a SSLContext object that contains your certificate chain
                      and private key (default: None)
        timeout - socket timeout (default: None) If timeout is not given or is None,
                  the global default socket timeout is used

for more documentation see the docstring of the parent class IMAP4.
rT   N)r  rj   c                l    Uc  [         R                  " 5       nX0l        [        R	                  XX$5        g r   )r  r  r  r   rk   )rg   rh   ri   r  rj   s        rJ   rk   IMAP4_SSL.__init__  s*    "!88:*NN4t5rI   c                 t    [         R                  X5      nU R                  R                  UU R                  S9$ )Nr  )r   r   r  r  rh   )rg   rj   r   s      rJ   r   IMAP4_SSL._create_socket%  s;    ''6D##//@D		 0 K KrI   c                 0    [         R                  XX#5        g)zSetup connection to remote server on "host:port".
    (default: localhost:standard IMAP4 SSL port).
This connection will be used by the routines:
    read, readline, send, shutdown.
N)r   ra   rf   s       rJ   ra   IMAP4_SSL.open*  s     JJt41rI   )r  )
rD   rE   rF   rG   r*  IMAP4_SSL_PORTrk   r   ra   rH   rB   rI   rJ   r-  r-    s1    	 !# 	6$($	6	K
 ^T 	2rI   r-  c                   @    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
rg)r   i5  zIMAP4 client class over a stream

Instantiate with: IMAP4_stream(command)

        "command" - a string that can be passed to subprocess.Popen()

for more documentation see the docstring of the parent class IMAP4.
c                 :    Xl         [        R                  U 5        g r   )r  r   rk   )rg   r  s     rJ   rk   IMAP4_stream.__init__A  s    trI   Nc           	      8   SU l         SU l        SU l        SU l        [        R
                  " U R                  [        [        R                  [        R                  SSS9U l	        U R                  R                  U l        U R                  R                  U l        g)zmSetup a stream connection.
This connection will be used by the routines:
    read, readline, send, shutdown.
NT)bufsizestdinstdoutshell	close_fds)rh   ri   r   r   
subprocessPopenr  r   PIPEr   r:  	writefiler;  readfilerf   s       rJ   ra   IMAP4_stream.openF  sq    
 				!'''//*//$( ++++rI   c                 8    U R                   R                  U5      $ r   )rB  r   )rg   r   s     rJ   r   IMAP4_stream.readV  s    }}!!$''rI   c                 6    U R                   R                  5       $ )r   )rB  r   rx   s    rJ   r   IMAP4_stream.readline[  s    }}%%''rI   c                 n    U R                   R                  U5        U R                   R                  5         g)r   N)rA  r  r  r   s     rJ   r   IMAP4_stream.send`  s$    T"rI   c                     U R                   R                  5         U R                  R                  5         U R                  R	                  5         g)r   N)rB  r   rA  r   waitrx   s    rJ   rd   IMAP4_stream.shutdownf  s2    rI   )r  r   rh   ri   r   rB  r   rA  )NNN)rD   rE   rF   rG   r*  rk   ra   r   r   r   rd   rH   rB   rI   rJ   r   r   5  s%    
, (
(
rI   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	r   in  zSPrivate class to provide en/decoding
for base64-based authentication conversation.
c                     Xl         g r   r   )rg   mechinsts     rJ   rk   _Authenticator.__init__t  s    	rI   c                 l    U R                  U R                  U5      5      nUc  gU R                  U5      $ )N   *)r   r   rX  )rg   r   rets      rJ   r   _Authenticator.processw  s0    iiD)*;{{3rI   c                     Sn[        U[        5      (       a  UR                  S5      nU(       aK  [        U5      S:  a  US S nUSS  nOUnSn[        R
                  " U5      nU(       a  X$S S -   nU(       a  MK  U$ )NrI   r{   0   r   )rV  rW  rX  r   binascii
b2a_base64)rg   inpouptes        rJ   rX  _Authenticator.encode}  s     c3**W%C3x"}H"#h##A&AcrFl c 
rI   c                 >    U(       d  g[         R                  " U5      $ )NrI   )rX  
a2b_base64)rg   rZ  s     rJ   r   _Authenticator.decode  s    ""3''rI   rO  N)
rD   rE   rF   rG   r*  rk   r   rX  r   rH   rB   rI   rJ   r   r   n  s     0(rI   r   z0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov DecrS  r   c           	         [         R                  U 5      nU(       d  g[        UR                  S5         nUR                  S5      n[	        UR                  S5      5      n[	        UR                  S5      5      n[	        UR                  S5      5      n[	        UR                  S5      5      n[	        UR                  S5      5      n[	        UR                  S	5      5      n	[	        UR                  S
5      5      n
U	S-  U
-   S-  nUS:X  a  U* nXRXFXxSSS4	n[
        R                  " U5      U-
  n[        R                  " U5      $ )zParse an IMAP4 INTERNALDATE string.

Return corresponding local time.  The return value is a
time.struct_time tuple or None if the string has wrong format.
Nmonzonendayyearhourr   seczonehzonem<      -r   )	InternalDater  Mon2numr  r  calendartimegmr  r  )r  r  rc  rd  re  rf  rg  r   rh  ri  rj  zonettutcs                 rJ   r	   r	     s    
		D	!B
"((5/
"CHHWE
bhhuo
Crxx Drxx D
bhhuo
C
bhhuo
C!"E!"E "Hub D}u
S"b"	5B
//"

$C>>#rI   c                     SnSn[        [        U 5      5      n U (       a!  [        U S5      u  pX#US-    U-   nU (       a  M!  U$ )z-Convert integer to A-P string representation.rI   s   ABCDEFGHIJKLMNOP   r   )r  absdivmod)numr  APmods       rJ   r
   r
     sK     C'r
c#h-C
#r?SUmc! # JrI   c                     [         R                  U 5      nU(       d  g[        UR                  S5      R	                  5       5      $ )z-Convert IMAP4 flags response to python tuple.rB   r   )Flagsr  r  r  r  )r  r  s     rJ   r   r     s5     
T	B'"((*++rI   c                 x   [        U [        [        45      (       a4  [        R                  " U [
        R                  5      R                  5       nO[        U [        5      (       a.   U R                  n[!        US9n[        U SS S[        U5      06nO`[        U [        5      (       a  U R"                  c  [%        S5      eU nO0[        U [&        5      (       a  U S   U S   4S	:X  a  U $ [%        S
5      eSR)                  [*        UR,                     5      nUR/                  U5      $ ! [         a    [        R                  (       a_  U S   nUS:X  a-  [        R                  " [        R                  " U 5      5      S   n[        R
                  [        R                  4U   * n GN2[        R
                  * n GNFf = f)a  Convert date_time to IMAP4 INTERNALDATE representation.

Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'.  The
date_time argument can be a number (int or float) representing
seconds since epoch (as returned by time.time()), a 9-tuple
representing local time, an instance of time.struct_time (as
returned by time.localtime()), an aware datetime instance or a
double-quoted string.  In the last case, it is assumed to already
be in the correct format.
   r   )secondsN   tzinfozdate_time must be awarer   )r  r  zdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z")rV  r  floatr   fromtimestampr   rs  
astimezoner  	tm_gmtoffr   r  daylightr  mktimealtzoner   r  r   rW  formatMonthsmonthr  )r   dtgmtoffdstr   fmts         rJ   r   r     sh    )c5\**##I$,LL22<*, 		Iu	%	%		(((F &)y!}=Xe_=	Ix	(	(#677	Is	#	#1im(D	(Q899
"
)
)&*:
;C;;s'  	(}}l"9..Y)?@CC==$,,7<<--	(s   &D& &A;F9$F98F9__main__zd:s:)rB   rB   z-dz-s)rT   zIMAP password for z on 	localhostr  zJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)s
)rJ  lfrL  )r  )
/tmp/xxx 1)ry  )r  z/tmp/yyy)r   
/tmp/yyz 2r   r  )rE  )z/tmpzyy*)r  r  )r  )NSUBJECTtest)r)  )1z(FLAGS INTERNALDATE RFC822))r  )r  FLAGSz
(\Deleted))rg  rB   )r%  rB   )r   rB   )r   rB   )r  rB   )r   )UIDVALIDITY)r  )r/   ALL)r   )r  )r   rB   c                     [         R                  U < SU< 35        [        [         U 5      " U6 u  p#[         R                  U < SU< SU< 35        US:X  a  US   eU$ )NrS  r  r  r   )Mr   r   )cmdr   r   r   s       rJ   runr  9  sL    	3%&1c?D)	c3/0$;c!f
rI   r   zPROTOCOL_VERSION = %szCAPABILITIES = rE  )z/tmp/zyy%z.*"([^"]+)"$r   r  r  z%sz:(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)z
All tests OK.z
Tests failed.z8
If you would like to see debugging output,
try: %s -d5
)Wr*  r   rX  r   r   rq   r   r>  r   r  ro  r   r   r   ior   r  r  ImportError__all__r   rV   r+  r4  r   r   r   r   rr   r  r|  rm  rt   ru   r   r  r  rw   rs   rv   r   r-  r   r   r   r  r  	enumeraterX  rn  r	   r
   r   r   rD   getoptgetpassargvoptlistr   rK   r  stream_commandoptr  rh   getuserUSERPASSWD	test_mesg	test_seq1	test_seq2r  r  rX   r   r   r   r  mlr  r  r  pathr   r  print)r'  r  s   00rJ   <module>r     sU  
,  K K K K K 2 2 "H8
 	
(  ,
,,
 	,
 	A	,

 	,
 	,
 	,
 	,,
 	,,
 	,,
 	
,
 	,,
 	,
 	,
 	,,
  	,!,
" 	,#,
$ 	,%,
& 	,',
( 	,),
* 	+,
, 	A-,
. 	,/,
0 	1,
2 	,3,
4 	A5,
6 	7,
8 		9,
: 	,;,
< 	=,
> 	,?,
@ 	,A,
B 	,C,
D 	,E,
F 	G,
H %,%,%%,%W,
` zz01


45zz   **+RXX
6
**^
$ 

DEJJGH **;RXXG "J ~ ~B$ #2E #2J NN;55 5r*( *(X 
<	A	A#	F&/qr
&;
<&;da188:ac>&;
<F	,%R z chhqrlF; NC$;HED[ N4 1  7D??D__tTEX[EXYZF\gkrv_wwItVn*dD)45)3,I$ !dD),-I)^,AdA77f!!"I	'!*<*<<=	q~~78!HCTN " f./B/2.B"((1+4B$4'"	 0 "HCc4.CDz77b'--/CBPR S " 	 { C/  Hv+ =` << j	   
hhqk 
 	s<   P  P#P% !D-Q PP%Q5Q  Q*Q2