Your IP : 18.218.162.180
a
?�g^;�@sjdZddlZddlZddlZddlZzddlZdZWneyJdZYn0ddgZGdd�de �Z
dZd Zd
Z
dZe
eZdZGd
d�d�Zer�Gdd�de�Ze�d�edk�rfddlZeejd�Zee���e�ejd�e�ejd�e��e��\ZZeded�D]BZ e�!e �\Z"Z#Z$ede �e#D]Z%ede%��q>ed��qe�&�dS)z@A POP3 client class.
Based on the J. Myers POP3 draft, Jan. 96
�NTF�POP3�error_protoc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�+/opt/alt/python39/lib64/python3.9/poplib.pyr��ni��
�
ic@seZdZdZdZeejfdd�Zdd�Z dd�Z
d d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd=d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Ze�d0�Z d1d2�Z!d3d4�Z"d>d5d6�Z#d7d8�Z$d9d:�Z%d?d;d<�Z&dS)@raPThis class supports both the minimal and optional command sets.
Arguments can be strings or integers (where appropriate)
(e.g.: retr(1) and retr('1') both work equally well.
Minimal Command Set:
USER name user(name)
PASS string pass_(string)
STAT stat()
LIST [msg] list(msg = None)
RETR msg retr(msg)
DELE msg dele(msg)
NOOP noop()
RSET rset()
QUIT quit()
Optional Commands (some servers support these):
RPOP name rpop(name)
APOP name digest apop(name, digest)
TOP msg n top(msg, n)
UIDL [msg] uidl(msg = None)
CAPA capa()
STLS stls()
UTF8 utf8()
Raises one exception: 'error_proto'.
Instantiate with:
POP3(hostname, port=110)
NB: the POP protocol locks the mailbox from user
authorization until QUIT, so be sure to get in, suck
the messages, and quit, each time you access the
mailbox.
POP is a line-based protocol, which means large mail
messages consume lots of python cycles reading them
line-by-line.
If it's available on your mail server, use IMAP4
instead, it doesn't suffer from the two problems
above.
zUTF-8cCsP||_||_d|_t�d|||�|�|�|_|j�d�|_d|_ |�
�|_dS)NFzpoplib.connect�rbr)�host�port�_tls_established�sys�audit�_create_socket�sock�makefile�file�
_debugging�_getresp�welcome)�selfrr�timeoutrrr�__init__bsz
POP3.__init__cCs(|dur|std��t�|j|jf|�S)Nz0Non-blocking socket (timeout=0) is not supported)�
ValueError�socketZcreate_connectionrr)rrrrrrmszPOP3._create_socketcCs:|jdkrtdt|��t�d||�|j�|t�dS)N�z*put*zpoplib.putline)r�print�reprrrrZsendall�CRLF�r�linerrr�_putlinersz
POP3._putlinecCs.|jrtdt|��t||j�}|�|�dS)Nz*cmd*)rr r!�bytes�encodingr%r#rrr�_putcmdzszPOP3._putcmdcCs�|j�td�}t|�tkr$td��|jdkr<tdt|��|sHtd��t|�}|dd�tkrp|dd�|fS|dd�t kr�|dd�|fS|dd�|fS)Nrz
line too longz*get*z-ERR EOF������)
r�readline�_MAXLINE�lenrrr r!r"�CR)rr$�octetsrrr�_getline�sz
POP3._getlinecCs:|��\}}|jdkr$tdt|��|�d�s6t|��|S)Nrz*resp*�+)r0rr r!�
startswithr)r�resp�orrrr�s
z
POP3._getrespcCsl|��}g}d}|��\}}|dkrb|�d�rB|d}|dd�}||}|�|�|��\}}q|||fS)Nr�.s..r)rr0r2�append)rr3�listr/r$r4rrr�_getlongresp�s
zPOP3._getlongrespcCs|�|�|��S�N)r(rr#rrr� _shortcmd�s
zPOP3._shortcmdcCs|�|�|��Sr9)r(r8r#rrr�_longcmd�s
z
POP3._longcmdcCs|jSr9)r�rrrr�
getwelcome�szPOP3.getwelcomecCs
||_dSr9)r)r�levelrrr�set_debuglevel�szPOP3.set_debuglevelcCs|�d|�S)zVSend user name, return response
(should indicate password required).
zUSER %s�r:�r�userrrrrB�sz POP3.usercCs|�d|�S)z�Send password, return response
(response includes message count, mailbox size).
NB: mailbox is locked by server from here to 'quit()'
zPASS %sr@)rZpswdrrr�pass_�sz
POP3.pass_cCsF|�d�}|��}|jr&tdt|��t|d�}t|d�}||fS)z]Get mailbox status.
Result is tuple of 2 ints (message count, mailbox size)
ZSTATz*stat*r�)r:�splitrr r!�int)rZretvalZretsZnumMessagesZsizeMessagesrrr�stat�s
z POP3.statNcCs |dur|�d|�S|�d�S)aRequest listing, return result.
Result without a message number argument is in form
['response', ['mesg_num octets', ...], octets].
Result when a message number argument is given is a
single response: the "scan listing" for that message.
NzLIST %sZLIST�r:r;�r�whichrrrr7�s z POP3.listcCs|�d|�S)zoRetrieve whole message number 'which'.
Result is in form ['response', ['line', ...], octets].
zRETR %s�r;rIrrr�retr�sz POP3.retrcCs|�d|�S)zFDelete message number 'which'.
Result is 'response'.
zDELE %sr@rIrrr�delesz POP3.delecCs
|�d�S)zXDoes nothing.
One supposes the response indicates the server is alive.
ZNOOPr@r<rrr�noopsz POP3.noopcCs
|�d�S)z(Unmark all messages marked for deletion.ZRSETr@r<rrr�rsetsz POP3.rsetcCs|�d�}|��|S)zDSignoff: commit changes on server, unlock mailbox, close connection.ZQUIT)r:�close)rr3rrr�quits
z POP3.quitcCs,z�|j}d|_|dur|��W|j}d|_|dur�z`z|�tj�WnBty�}z*|jtjkrtt |dd�dkrt�WYd}~n
d}~00W|��n
|��0n�|j}d|_|du�r&zbz|�tj�WnDt�y}z*|jtjkr�t |dd�dkr��WYd}~n
d}~00W|��n
|��00dS)z8Close the connection without assuming anything about it.NZwinerrorri&')
rrPrZshutdownrZ SHUT_RDWR�OSError�errnoZENOTCONN�getattr)rrr�excrrrrPs6
��
�z
POP3.closecCs|�d|�S)zNot sure what this does.zRPOP %sr@rArrr�rpop7sz POP3.rpops\+OK.[^<]*(<.*>)cCs\t||j�}|j�|j�}|s&td��ddl}|�d�|}|�|�� �}|�
d||f�S)aAuthorisation
- only possible if server has supplied a timestamp in initial greeting.
Args:
user - mailbox user;
password - mailbox password.
NB: mailbox is locked by server from here to 'quit()'
z!-ERR APOP not supported by serverrNrz
APOP %s %s)r&r'� timestamp�matchrr�hashlib�groupZmd5Z hexdigestr:)rrBZpasswordZsecret�mrYZdigestrrr�apop>sz POP3.apopcCs|�d||f�S)z�Retrieve message header of message number 'which'
and first 'howmuch' lines of message body.
Result is in form ['response', ['line', ...], octets].
z TOP %s %srK)rrJZhowmuchrrr�topSszPOP3.topcCs |dur|�d|�S|�d�S)z�Return message digest (unique id) list.
If 'which', result contains unique id for that message
in the form 'response mesgnum uid', otherwise result is
the list ['response', ['mesgnum uid', ...], octets]
NzUIDL %sZUIDLrHrIrrr�uidl\sz POP3.uidlcCs
|�d�S)zITry to enter UTF-8 mode (see RFC 6856). Returns server response.
ZUTF8r@r<rrr�utf8hsz POP3.utf8cCs`dd�}i}z4|�d�}|d}|D]}||�\}}|||<q$WntyZtd��Yn0|S)aReturn server capabilities (RFC 2449) as a dictionary
>>> c=poplib.POP3('localhost')
>>> c.capa()
{'IMPLEMENTATION': ['Cyrus', 'POP3', 'server', 'v2.2.12'],
'TOP': [], 'LOGIN-DELAY': ['0'], 'AUTH-RESP-CODE': [],
'EXPIRE': ['NEVER'], 'USER': [], 'STLS': [], 'PIPELINING': [],
'UIDL': [], 'RESP-CODES': []}
>>>
Really, according to RFC 2449, the cyrus folks should avoid
having the implementation split into multiple arguments...
cSs"|�d���}|d|dd�fS)N�asciirr)�decoderE)r$Zlstrrr� _parsecap{szPOP3.capa.<locals>._parsecapZCAPArz!-ERR CAPA not supported by server)r;r)rrb�capsr3ZrawcapsZcaplineZcapnmZcapargsrrr�capans
z POP3.capacCsxtstd��|jrtd��|��}d|vr2td��|durBt��}|�d�}|j|j|j d�|_|j�
d�|_d|_|S) z{Start a TLS session on the active connection as specified in RFC 2595.
context - a ssl.SSLContext
z-ERR TLS support missing�$-ERR TLS session already establishedZSTLSz!-ERR STLS not supported by serverN�Zserver_hostnamer
T)�HAVE_SSLrrrd�ssl�_create_stdlib_contextr:�wrap_socketrrrr)r�contextrcr3rrr�stls�s
�z POP3.stls)N)N)N)'rrr�__doc__r'� POP3_PORTr�_GLOBAL_DEFAULT_TIMEOUTrrr%r(r0rr8r:r;r=r?rBrCrGr7rLrMrNrOrQrPrV�re�compilerWr\r]r^r_rdrlrrrrr3sB+�
c@s8eZdZdZeddejdfdd�Zdd�Zd dd�Z dS)
�POP3_SSLaPOP3 client class over SSL connection
Instantiate with: POP3_SSL(hostname, port=995, keyfile=None, certfile=None,
context=None)
hostname - the hostname of the pop3 over ssl server
port - port number
keyfile - PEM formatted file that contains your private key
certfile - PEM formatted certificate chain file
context - a ssl.SSLContext
See the methods of the parent class POP3 for more documentation.
NcCs�|dur|durtd��|dur0|dur0td��|dus@|durVddl}|�dtd�||_||_|durxtj||d�}||_t �
||||�dS)Nz4context and keyfile arguments are mutually exclusivez5context and certfile arguments are mutually exclusiverzAkeyfile and certfile are deprecated, use a custom context insteadrD)�certfile�keyfile)r�warnings�warn�DeprecationWarningrtrsrhrirkrr)rrrrtrsrrkrurrrr�s"��zPOP3_SSL.__init__cCs"t�||�}|jj||jd�}|S)Nrf)rrrkrjr)rrrrrrr�s
�zPOP3_SSL._create_socketcCstd��dS)z�The method unconditionally raises an exception since the
STLS command doesn't make any sense on an already established
SSL/TLS session.
reN)r)rrtrsrkrrrrl�sz
POP3_SSL.stls)NNN)
rrrrm�
POP3_SSL_PORTrrorrrlrrrrrr�s�
rr�__main__rrD�zMessage %d:z z-----------------------)'rmrSrprrrhrg�ImportError�__all__� Exceptionrrnrxr.ZLFr"r,rrrr6r�argv�ar r=rBrCr7rGZnumMsgsZ totalSize�range�irL�header�msgr/r$rQrrrr�<module>sL
p0
?>