• File: imaplib.cpython-38.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/proc/self/root/opt/alt/python38/lib64/python3.8/__pycache__/imaplib.cpython-38.pyc
  • Date Modified: 10/26/2026 8:15 PM
  • File size: 40.51 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
U

j*@sdZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZm
Z
ddlmZzddlZdZWnek
rdZYnXdd	d
ddd
gZdZdZdZdZdZdZdddddddddddddddddddddddddddddddddddddddddd)ZedZedZedZedejZ edZ!edZ"edZ#ed ejZ$dZ%d Z&ed!Z'Gd"ddZ(erGd#d$d$e(Z)e*d$Gd%d	d	e(Z+Gd&d'd'Z,d(-d)Z.d*d+e/e.d,dDZ0d-d
Z1d.dZ2d/dZ3d0d
Z4e5d1krddl6Z6ddl7Z7ze66ej8d,dd2\Z9Z:Wn.e6j;k
rzZ<zd3\Z9Z:W5dZ<[<XYnXdZ=e9D]8\Z>Z<e>d4kre?e<Zne>d5kre<Z=e:se=fZ:qe:sd6Z:e:dZ@e7AZBe77d7eBe@pd8fZCd9eBd:d;ZDd<eBeCffd=d>d?d@dAddeDffdBdCdDdEdFdGdHdIdJfZEdKdLdMdNd@dddeDffdIdOfZFdPdQZGze=rle+e=ZHne(e@ZHeHjIdRkreEd,dZEeHJdSeHjKeHJdTeHjLfeED]\ZMZ:eGeMe:qeGdUdVD]<ZNeOdWeNZPePrePQd,ZRneN-dXZReGdYeRfqeFD]T\ZMZ:eGeMe:ZSeMe:fdMkr8qeSdX-ZTeTsNqeGdZd[d\eTdXd]fqeUd^Wn.eUd_eseUd`ej8dYnXdS)azIMAP4 client.

Based on RFC 2060.

Public class:           IMAP4
Public variable:        Debug
Public functions:       Internaldate2tuple
                        Int2AP
                        ParseFlags
                        Time2Internaldate
z2.58N)datetimetimezone	timedelta)DEFAULT_BUFFER_SIZETFIMAP4IMAP4_streamInternaldate2tupleInt2AP
ParseFlagsTime2Internaldate
i)Z	IMAP4REV1ri@B)AUTHSELECTED)NONAUTH)rrrLOGOUT)r)r))APPENDAUTHENTICATE
CAPABILITYCHECKCLOSECOPYCREATEDELETE	DELETEACLENABLEEXAMINEEXPUNGEFETCHGETACL
GETANNOTATIONGETQUOTAGETQUOTAROOTMYRIGHTSLISTLOGINrLSUBZMOVE	NAMESPACENOOPPARTIAL	PROXYAUTHRENAMESEARCHSELECTSETACL
SETANNOTATIONSETQUOTASORTSTARTTLSSTATUSSTORE	SUBSCRIBETHREADUIDUNSUBSCRIBEs\+( (?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>.*))?s[-]c@seZdZdZGdddeZGdddeZGdddeZdefd	d
Z	ddZ
d
dZddZddZ
ddZddZddZdefddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Z d9d:Z!d;d<Z"d=d>Z#d?d@Z$dAdBZ%dCdDZ&dEdFZ'dGdHZ(ddKdLZ)dMdNZ*dOdPZ+dQdRZ,dSdTZ-ddUdVZ.dWdXZ/dYdZZ0d[d\Z1d]d^Z2d_d`Z3dadbZ4dcddZ5ddgdhZ6didjZ7dkdlZ8dmdnZ9dodpZ:ddrdsZ;dtduZ<dvdwZ=dxdyZ>dzd{Z?d|d}Z@d~dZAddZBddZCddZDddZEddZFddZGddZHdddZIddZJddZKddZLddZMddZNddZOdddZPddZQddZRddZSdqS)raIMAP4 client class.

    Instantiate with: IMAP4([host[, port]])

            host - host's name (default: localhost);
            port - port number (default: standard IMAP4 port).

    All IMAP4rev1 commands are supported by methods of the same
    name (in lower-case).

    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@seZdZdS)zIMAP4.errorN__name__
__module____qualname__r=r=,/opt/alt/python38/lib64/python3.8/imaplib.pyerrorsr?c@seZdZdS)zIMAP4.abortNr9r=r=r=r>abortsr@c@seZdZdS)zIMAP4.readonlyNr9r=r=r=r>readonlysrAcCst|_d|_d|_i|_i|_d|_d|_d|_d|_	|
|||z|Wn8t
k
rz|Wntk
rYnXYnXdS)NrrBFr)Debugdebugstateliteraltagged_commandsuntagged_responsescontinuation_responseis_readonlytagnum_tls_established_mode_asciiopen_connect	ExceptionshutdownOSErrorselfhostportr=r=r>__init__s&zIMAP4.__init__cCs0d|_d|_tttj|_tttj|_dS)NFascii)	utf8_enabled	_encodingrecompile_LiteralASCIILiteral_Untagged_statusUntagged_statusrTr=r=r>rMszIMAP4._mode_asciicCs(d|_d|_tt|_tt|_dS)NTutf-8)rYrZr[r\r]r_r`rarbr=r=r>
_mode_utf8szIMAP4._mode_utf8cCsttdd|_td|jdtj|_d|_d|_	i|_
|jdkrf|dt
|d	|j||_d
|jkrd|_nd|jkrd
|_n||j||jdkr|d|jftD]}||jkrq||_dS|ddS)Niis(?P<tag>s"\d+) (?P<type>[A-Z]+) (?P<data>.*)
rzimaplib version %sznew IMAP4 connection, tag=%sZPREAUTHrOKrzCAPABILITIES: %rzserver not IMAP4 compliant)r	randomZrandinttagprer[r\r^tagre_cmd_log_len_cmd_log_idx_cmd_logrD_mesg__version__
_get_responseZwelcomerHrEr?_get_capabilitiescapabilitiesAllowedVersionsPROTOCOL_VERSION)rTversionr=r=r>rOs:





zIMAP4._connectcCs&|tkrt||Std|dS)NzUnknown IMAP4 command: '%s')CommandsgetattrlowerAttributeError)rTattrr=r=r>__getattr__
szIMAP4.__getattr__cCs|SNr=rbr=r=r>	__enter__szIMAP4.__enter__cGs4|jdkrdSz|Wntk
r.YnXdS)Nr)rElogoutrR)rTargsr=r=r>__exit__s
zIMAP4.__exit__cCs4|js
dn|j}td||j|jt||jfS)Nzimaplib.open)rUsysauditrVsocketZcreate_connection)rTrUr=r=r>_create_socket szIMAP4._create_socketcCs(||_||_||_|jd|_dS)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)rUrVrsockmakefilefilerSr=r=r>rN(s
z
IMAP4.opencCs|j|SzRead 'size' bytes from remote.)rreadrTsizer=r=r>r4sz
IMAP4.readcCs.|jtd}t|tkr*|dt|S)Read line from remote.rfzgot more than %d bytes)rreadline_MAXLINElenr?rTliner=r=r>r9szIMAP4.readlinecCstd|||j|dS)Send data to remote.zimaplib.sendN)rrrZsendallrTdatar=r=r>sendAsz
IMAP4.sendc
Cst|jzXz|jtjWn@tk
r^}z"|jtjkrNt	|dddkrNW5d}~XYnXW5|jXdS) Close I/O established in "open".Zwinerrorri&'N)
rcloserrQrZ	SHUT_RDWRrRerrnoZENOTCONNrx)rTexcr=r=r>rQGs
zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server.

        socket = <instance>.socket()
        )rrbr=r=r>rWszIMAP4.socketcCsBd}|ddg|\}}|dr(||fS|\}}||||S)aReturn 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.
        ZRECENTrgN)_untagged_responsenooprTnametypdatr=r=r>recentcs	zIMAP4.recentcCs||dg|S)zReturn data for response 'code' if received, or None.

        Old value for response 'code' is cleared.

        (code, [data]) = <instance>.response(code)
        N)rupper)rTcoder=r=r>responsetszIMAP4.responsecCsxd}|sd}|r.|d|dfdkr2d|}nd}|r@t|}nd}tt|}|jrbd|d	}||_|||||S)
zAppend message to named mailbox.

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

                All args except `message' can be None.
        rINBOXrr()(%s)NsUTF8 ())rMapCRLFsubCRLFrYrF_simple_command)rTmailboxflags	date_timemessagerrFr=r=r>appends

zIMAP4.appendcCsP|}t|j|_|d|\}}|dkrB||dddd|_||fS)asAuthenticate 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.
        rrgrrcreplacer)r_AuthenticatorprocessrFrr?decoderE)rTZ	mechanismZ
authobjectmechrrr=r=r>authenticateszIMAP4.authenticatecCs d}||\}}||||S)zT(typ, [data]) = <instance>.capability()
        Fetch capabilities list from server.rrrrr=r=r>
capabilityszIMAP4.capabilitycCs
|dS)zRCheckpoint mailbox on server.

        (typ, [data]) = <instance>.check()
        rrrbr=r=r>checkszIMAP4.checkcCs$z|d\}}W5d|_X||fS)zClose currently selected mailbox.

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

        (typ, [data]) = <instance>.close()
        rr)rErrTrrr=r=r>rszIMAP4.closecCs|d||S)zCopy 'message_set' messages onto end of 'new_mailbox'.

        (typ, [data]) = <instance>.copy(message_set, new_mailbox)
        rr)rTmessage_setZnew_mailboxr=r=r>copysz
IMAP4.copycCs|d|S)zPCreate new mailbox.

        (typ, [data]) = <instance>.create(mailbox)
        rrrTrr=r=r>createszIMAP4.createcCs|d|S)zPDelete old mailbox.

        (typ, [data]) = <instance>.delete(mailbox)
        rrrr=r=r>deleteszIMAP4.deletecCs|d||S)zDelete the ACLs (remove any rights) set for who on mailbox.

        (typ, [data]) = <instance>.deleteacl(mailbox, who)
        rr)rTrwhor=r=r>	deleteaclszIMAP4.deleteaclcCsHd|jkrtd|d|\}}|dkr@d|kr@|||fS)zkSend an RFC5161 enable string to the server.

        (typ, [data]) = <intance>.enable(capability)
        rzServer does not support ENABLErgzUTF8=ACCEPT)rsrr?rrrd)rTrrrr=r=r>enables

zIMAP4.enablecCs d}||\}}||||S)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.
        rrrr=r=r>expunges	z
IMAP4.expungecCs$d}||||\}}||||S)a#Fetch (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.
        rr)rTrZ
message_partsrrrr=r=r>fetchs
zIMAP4.fetchcCs|d|\}}|||dS)zXGet the ACLs for a mailbox.

        (typ, [data]) = <instance>.getacl(mailbox)
        rZACLrrTrrrr=r=r>getacl szIMAP4.getaclcCs"|d|||\}}|||dS)za(typ, [data]) = <instance>.getannotation(mailbox, entry, attribute)
        Retrieve ANNOTATIONs.r 
ANNOTATIONr)rTrentryZ	attributerrr=r=r>
getannotation)szIMAP4.getannotationcCs|d|\}}|||dS)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)rTrootrrr=r=r>getquota1szIMAP4.getquotacCs@|d|\}}|||d\}}|||d\}}|||gfS)zGet the list of quota roots for the named mailbox.

        (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = <instance>.getquotaroot(mailbox)
        r"rZ	QUOTAROOTr)rTrrrZquotaZ	quotarootr=r=r>getquotaroot<szIMAP4.getquotaroot""*cCs$d}||||\}}||||S)zList mailbox names in directory matching pattern.

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

        'data' is list of LIST responses.
        r$rrTZ	directorypatternrrrr=r=r>listGsz
IMAP4.listcCs<|d|||\}}|dkr.||dd|_||fS)zIdentify client using plaintext password.

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

        NB: 'password' will be quoted.
        r%rgrr)r_quoter?rE)rTuserpasswordrrr=r=r>loginSs
zIMAP4.logincCs|||_|_|d|jS)zr Force use of CRAM-MD5 authentication.

        (typ, [data]) = <instance>.login_cram_md5(user, password)
        zCRAM-MD5)rrr_CRAM_MD5_AUTH)rTrrr=r=r>login_cram_md5aszIMAP4.login_cram_md5cCsBddl}t|jtr |jdn|j}|jd|||dS)z1 Authobject to use with CRAM-MD5 authentication. rNrc Zmd5)hmac
isinstancerstrencoderZHMACZ	hexdigest)rTZ	challengerpwdr=r=r>rjs
zIMAP4._CRAM_MD5_AUTHcCs$d|_|d\}}|||fS)z|Shutdown connection to server.

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

        Returns server 'BYE' response.
        r)rErrQrr=r=r>rrszIMAP4.logoutcCs$d}||||\}}||||S)zList 'subscribed' mailbox names in directory matching pattern.

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

        'data' are tuples of message part envelope and data.
        r&rrr=r=r>lsubsz
IMAP4.lsubcCs|d|\}}|||dS)zShow my ACLs for a mailbox (i.e. the rights that I have on mailbox).

        (typ, [data]) = <instance>.myrights(mailbox)
        r#rrr=r=r>myrightsszIMAP4.myrightscCs d}||\}}||||S)zb Returns IMAP namespaces ala rfc2342

        (typ, [data, ...]) = <instance>.namespace()
        r'rrr=r=r>	namespaceszIMAP4.namespacecCs |jdkr||j|dS)zFSend NOOP command.

        (typ, [data]) = <instance>.noop()
        rhr()rD_dump_urrHrrbr=r=r>rs
z
IMAP4.noopcCs(d}||||||\}}|||dS)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)rr)rTZmessage_numZmessage_partstartZlengthrrrr=r=r>partialsz
IMAP4.partialcCsd}|d|S)zAssume authentication as "user".

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

        (typ, [data]) = <instance>.proxyauth(user)
        r*r)rTrrr=r=r>	proxyauths	zIMAP4.proxyauthcCs|d||S)zkRename old mailbox name to new.

        (typ, [data]) = <instance>.rename(oldmailbox, newmailbox)
        r+r)rTZ
oldmailboxZ
newmailboxr=r=r>renameszIMAP4.renamecGsTd}|r2|jrtd|j|d|f|\}}n|j|f|\}}||||S)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 modeCHARSET)rYrr?rr)rTcharsetZcriteriarrrr=r=r>searchs
zIMAP4.searchrFcCsi|_||_|rd}nd}|||\}}|dkr@d|_||fSd|_d|jkrx|sx|jdkrj||j|d|||jd	d
gfS)atSelect 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.
        rr-rgrr	READ-ONLYrfz%s is not writableEXISTSN)rHrJrrErDrrAget)rTrrArrrr=r=r>selects"

zIMAP4.selectcCs|d|||S)zZSet a mailbox acl.

        (typ, [data]) = <instance>.setacl(mailbox, who, what)
        r.r)rTrrZwhatr=r=r>setaclszIMAP4.setaclcGs |jd|\}}|||dS)z_(typ, [data]) = <instance>.setannotation(mailbox[, entry, attribute]+)
        Set ANNOTATIONs.r/r)r/r)rTrrrr=r=r>
setannotationszIMAP4.setannotationcCs |d||\}}|||dS)ziSet the quota root's resource limits.

        (typ, [data]) = <instance>.setquota(root, limits)
        r0rr)rTrZlimitsrrr=r=r>setquota
szIMAP4.setquotacGsFd}|d|dfdkr d|}|j|||f|\}}||||S)zIMAP4rev1 extension SORT command.

        (typ, [data]) = <instance>.sort(sort_criteria, charset, search_criteria, ...)
        r1rrrrr)rTZ
sort_criteriarsearch_criteriarrrr=r=r>sorts
z
IMAP4.sortNcCsd}ts|d|jr"|d||jkr6|d|dkrFt}||\}}|dkr|j|j	|j
d|_	|j	d|_d|_|
n
|d	||||S)
Nr2zSSL support missingzTLS session already establishedzTLS not supported by serverrgZserver_hostnamerTzCouldn't establish TLS session)HAVE_SSLr?rLr@rsssl_create_stdlib_contextrwrap_socketrrUrrrrr)rTssl_contextrrrr=r=r>starttls!s&





zIMAP4.starttlscCs$d}||||\}}||||S)zpRequest named status conditions for mailbox.

        (typ, [data]) = <instance>.status(mailbox, names)
        r3r)rTrnamesrrrr=r=r>status8szIMAP4.statuscCs>|d|dfdkrd|}|d|||\}}|||dS)zAlters flag dispositions for messages in mailbox.

        (typ, [data]) = <instance>.store(message_set, command, flags)
        rrrrr4rr)rTrcommandrrrr=r=r>storeDszIMAP4.storecCs|d|S)zYSubscribe to new mailbox.

        (typ, [data]) = <instance>.subscribe(mailbox)
        r5rrr=r=r>	subscribeOszIMAP4.subscribecGs*d}|j|||f|\}}||||S)zIMAPrev1 extension THREAD command.

        (type, [data]) = <instance>.thread(threading_algorithm, charset, search_criteria, ...)
        r6r)rTZthreading_algorithmrrrrrr=r=r>threadWszIMAP4.threadc	Gs|}|tkr|d||jt|krL|d||jdt|fd}|j||f|\}}|dkrt|}nd}||||S)zExecute "command arg ..." with messages identified by UID,
                rather than message number.

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

        Returns response appropriate to 'command'.
        zUnknown IMAP4 UID command: %s9command %s illegal in state %s, only allowed in states %s, r7)r,r1r6r)rrwr?rEjoinrr)rTrrrrrr=r=r>uidasz	IMAP4.uidcCs|d|S)z_Unsubscribe from old mailbox.

        (typ, [data]) = <instance>.unsubscribe(mailbox)
        r8rrr=r=r>unsubscribezszIMAP4.unsubscribecGs,|}|tkr|jft|<|j|f|S)aAllow 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'.
        )rrwrErrTrrr=r=r>xatoms
zIMAP4.xatomc	Csb|dkrd}|j}|jdkr<|d|t||d|f||krT|||n
|g||<dS)Nz#untagged_responses[%s] %s += ["%r"]rB)rHrDrorrr)rTrrZurr=r=r>_append_untaggeds
zIMAP4._append_untaggedcCs,|jd}|r(||d|jddS)NBYErr)rHrr@rrZ)rTbyer=r=r>
_check_byeszIMAP4._check_byec

GsF|jt|kr4d|_|d||jdt|fdD]}||jkr8|j|=q8d|jkrj|jsj|d|}t	||j
}|d|}|D]B}|dkrqt|trt	||j
}t
|rtd|d|}q|j}|dk	rd|_t|t|jkr|}nd}|t	dt||j
}|jd	kr:|d
|n|d
|z||tWn2tk
r}	z|d|	W5d}	~	XYnX|dkr|S|r|j|r|Sq|r||j}|jd	kr|dt|z|||tWn2tk
r2}	z|d|	W5d}	~	XYnX|sqBq|S)
NrrrgNOBADrz#mailbox status changed to READ-ONLY z*Control characters not allowed in commandsz {%s}z> %rzsocket error: %szwrite literal size %s)rErwrFr?rrHrJrA_new_tagbytesrZrr_control_charsr
ValueErrortype_commandrrDro_logrrrRr@rqrGrI)
rTrrrtagrargrFZ	literatorvalr=r=r>rsp






 



 zIMAP4._commandc
Cs|dk}|s|z|j||d\}}Wnj|jk
r`}z|d||fW5d}~XYn6|jk
r}z|d||fW5d}~XYnX|s||dkr|d|||f||fS)Nr)
expect_byezcommand: %s => %srz%s command error: %s %s)r_get_tagged_responser@r?)rTrrrrrr!r=r=r>_command_completes"$zIMAP4._command_completecCsJ|\}}|dgkr |dt|d|j}|}t||_dS)Nz"no CAPABILITY response from serverr)rr?rrZrtuplesplitrsrr=r=r>rr
s

zIMAP4._get_capabilitiescCs|}||j|rr|jd}||jkr:|d||jd}t||j}|jd}||gf|j|<nd}|t	|s||j
|r|jd}|jdkr|t|r|jd|_dS|d||jd}t||j}|jd}|dkrd}|r|d|}||j
|rvt|jd	}|jd
krP|d|||}||||f|}q||||dkr|t|r|jd}t||j}|||jd|jd
kr|dkr|d||f|S)Nrzunexpected tagged response: %rrrZdata2zunexpected response: %rr
rrrzread literal size %srrf)rrrz%s response: %r)	_get_line_matchrkmogrouprGr@rrZUntagged_responseraContinuationrIr_intrDrorr
Response_code)rTresprrrZdat2rrr=r=r>rqsP



zIMAP4._get_responsec
Cs|j|}|dk	r|j|=|S|rDd}|j|d}|dk	rD||fS|z|Wq|jk
r}z|jdkr~|W5d}~XYqXqdS)Nrrf)rGrHpoprrqr@rD	print_log)rTrr"resultrrr!r=r=r>r#fs 

zIMAP4._get_tagged_responsecCsf|}|s|d|ds.|d||dd}|jdkrT|d|n|d||S)Nzsocket error: EOFrz#socket error: unterminated line: %rrz< %r)rr@endswithrDrorrr=r=r>r's


zIMAP4._get_linecCsD|||_|jdk	r:|jdkr:|d|j|jf|jdk	S)Nrz	matched %r => %r)matchr)rDrorgroups)rTZcresr=r=r>r(szIMAP4._matchcCs2|jtt|j|j}|jd|_d|j|<|S)Nrf)rjrrrKrZrG)rTrr=r=r>rs
zIMAP4._new_tagcCs$|dd}|dd}d|dS)N\z\\"z\")r)rTr r=r=r>rszIMAP4._quotecGs|||j|f|Sr})r$rrr=r=r>rszIMAP4._simple_commandcCsT|dkr||fS||jkr$|dgfS|j|}|jdkrL|d||f||fS)Nrrzuntagged_responses[%s] => %s)rHr0rDro)rTrrrrr=r=r>rs


zIMAP4._untagged_responsecCsN|dkrt}tdt|}tjd||dd|ftjdS)Nz%M:%Sz
  %s.%02d %s
d)timestrftime	localtimerstderrwriteflush)rTr7ZsecsZtmr=r=r>ros
zIMAP4._mesgcCs>|}|sdSd}tdd|}|d|||fdS)Nz
		cSs*d|d|ddr"d|dp$dfS)Nz%s: "%s"rrfz" "rB)r)xr=r=r><lambda>r
z IMAP4._dump_ur.<locals>.<lambda>zuntagged responses dump:%s%s)itemsmapror)rTdictltr=r=r>rszIMAP4._dump_urcCs8|tf|j|j<|jd7_|j|jkr4d|_dS)Nrfr)r;rnrmrlrr=r=r>rsz
IMAP4._logcCsl|dt|j|j|j}}|rhz|j|j|WnYnX|d7}||jkr^d}|d8}q"dS)Nzlast %d IMAP4 interactions:rfr)rorrnrmrl)rTinr=r=r>r1s
zIMAP4.print_log)rr)rr)rF)N)F)N)Tr:r;r<__doc__rPr?r@rA
IMAP4_PORTrWrMrdrOr|r~rrrNrrrrQrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr	r
rrrrr$rrrqr#r'r(rrrrrorrr1r=r=r=r>rs,*
		
	



 	

O	P
!
c@s:eZdZdZdedddfddZddZdefdd	ZdS)
	IMAP4_SSLa3IMAP4 client class over SSL connection

        Instantiate with: IMAP4_SSL([host[, port[, keyfile[, certfile[, ssl_context]]]]])

                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);
                ssl_context - a SSLContext object that contains your certificate chain
                              and private key (default: None)
                Note: if ssl_context is provided, then parameters keyfile or
                certfile should not be set otherwise ValueError is raised.

        for more documentation see the docstring of the parent class IMAP4.
        rBNcCs|dk	r|dk	rtd|dk	r0|dk	r0td|dk	s@|dk	rVddl}|dtd||_||_|dkrxtj||d}||_t	
|||dS)Nz8ssl_context and keyfile arguments are mutually exclusivez9ssl_context and certfile arguments are mutually exclusiverzEkeyfile and certfile are deprecated, use a custom ssl_context instead)certfilekeyfile)rwarningswarnDeprecationWarningrOrNrrrrrW)rTrUrVrOrNrrPr=r=r>rWs$zIMAP4_SSL.__init__cCst|}|jj||jdS)Nr)rrrrrU)rTrr=r=r>rs
zIMAP4_SSL._create_socketcCst|||dS)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)rrNrSr=r=r>rNszIMAP4_SSL.open)r:r;r<rJIMAP4_SSL_PORTrWrrNr=r=r=r>rLs
rLc@sBeZdZdZddZdddZddZd	d
ZddZd
dZ	dS)rzIMAP4 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.
    cCs||_t|dSr})rrrW)rTrr=r=r>rW2szIMAP4_stream.__init__NcCsNd|_d|_d|_d|_tj|jttjtjddd|_	|j	j
|_|j	j|_
dS)zSetup a stream connection.
        This connection will be used by the routines:
            read, readline, send, shutdown.
        NT)bufsizestdinstdoutshellZ	close_fds)rUrVrr
subprocessPopenrrPIPErrU	writefilerVreadfilerSr=r=r>rN7s
zIMAP4_stream.opencCs|j|Sr)r\rrr=r=r>rGszIMAP4_stream.readcCs
|jS)r)r\rrbr=r=r>rLszIMAP4_stream.readlinecCs|j||jdS)rN)r[r?r@rr=r=r>rQszIMAP4_stream.sendcCs"|j|j|jdS)rN)r\rr[rwaitrbr=r=r>rQWs

zIMAP4_stream.shutdown)NN)
r:r;r<rJrWrNrrrrQr=r=r=r>r&s

c@s0eZdZdZddZddZddZdd	Zd
S)rzcPrivate class to provide en/decoding
            for base64-based authentication conversation.
    cCs
||_dSr})r)rTZmechinstr=r=r>rWesz_Authenticator.__init__cCs&|||}|dkrdS||S)N*)rrr)rTrZretr=r=r>rhsz_Authenticator.processcCsnd}t|tr|d}|rjt|dkrB|dd}|dd}n|}d}t|}|r||dd}q|S)Nr
rc0r)rrrrbinasciiZ
b2a_base64)rTinpZouprGer=r=r>rns	


z_Authenticator.encodecCs|sdSt|S)Nr
)r`Z
a2b_base64)rTrar=r=r>rsz_Authenticator.decodeN)r:r;r<rJrWrrrr=r=r=r>r_s
rz0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov DecrcCsi|]\}}||dqS)rf)r).0rIr7r=r=r>
<dictcomp>srdrfc	Cst|}|sdSt|d}|d}t|d}t|d}t|d}t|d}t|d}t|d	}	t|d
}
|	d|
d}|dkr|}||||||d
d
d
f	}t||}
t|
S)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.
    Nmonzonendayyearhourminseczonehzonem<-r)	InternalDater5Mon2numr*r-calendarZtimegmr;r=)r/r)rerfrgrhrirjrkrlrmZzoneZttutcr=r=r>rs$

cCs@d}d}tt|}|r<t|d\}}|||d|}q|S)z-Convert integer to A-P string representation.r
sABCDEFGHIJKLMNOPrf)r-absdivmod)Znumr!ZAPmodr=r=r>r	scCs$t|}|sdSt|dS)z-Convert IMAP4 flags response to python tuple.r=r)Flagsr5r%r*r&)r/r)r=r=r>r
s
cCst|ttfr"t|tj}nt|trz
|j	}WnZt
k
rtjr|d}|dkrpt
t|d}tjtjf|}ntj}YnXt|d}t|dddt|i}nLt|tr|jdkrtd|}n*t|tr|d|dfd	kr|Std
dt|j}||S)aConvert 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)ZsecondsNtzinfozdate_time must be awarer)r9r9zdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z")rr-floatrZ
fromtimestamprrsZ
astimezoner%	tm_gmtoffrzr;daylightr=mktimealtzonerr{rrformatMonthsZmonthr<)rZdtZgmtoffZdstZdeltaZfmtr=r=r>rs2





__main__zd:s:)r=r=z-dz-s)rBzIMAP password for %s on %s: Z	localhostzJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)s
)rZlfr)r)
/tmp/xxx 1)r)rz/tmp/yyy)r
/tmp/yyz 2rr)r)z/tmpzyy*)rr)r)NZSUBJECTZtest)r)1z(FLAGS INTERNALDATE RFC822))r)rFLAGSz
(\Deleted))rr=)rr=)rr=)rr=)rr=)r)ZUIDVALIDITY)r	)r,ZALL)r)r)rr=cCsLtd||ftt||\}}td|||f|dkrH|d|S)Nz%s %sz%s => %s %srr)Mrorx)cmdrrrr=r=r>run*srrzPROTOCOL_VERSION = %szCAPABILITIES = %rr)z/tmp/zyy%z.*"([^"]+)"$rrr	rz%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
)VrJrpr`rrir[rrXrr;rrrrriorrrImportError__all__rrCrKrSrtrrwr\r,rxrpr^r_rr.r+rar]r`rrrLrrrr&r	enumeraterqrr	r
rr:ZgetoptZgetpassargvZoptlistrr?r!Zstream_commandoptr-rUZgetuserZUSERZPASSWDZ	test_mesgZ	test_seq1Z	test_seq2rrrErorursrZmlr5r)r*pathrr	printr=r=r=r><module>s\H
	/



	


n4
9,
#
)