� ���j�9���dZddlZddlZddlZddlZ ddlZdZddgZGd�de �Z dZ d Z d Z d Ze ezZd ZGd �d�ZerGd�de�Zej'd�edk(r�ddlZeej*d�Zeej1��ej3ej*d�ej5ej*d�ej7�ej9�\ZZededz�D]<Z ejCe �\Z"Z#Z$ede z�e#D] Z%ede%z��ed��>ejM�yy#e$rdZY��@wxYw)z@A POP3 client class. Based on the J. Myers POP3 draft, Jan. 96 �NTF�POP3� error_protoc� �eZdZy)rN)�__name__� __module__� __qualname__���/usr/lib64/python3.12/poplib.pyrrs�r �ni�� � ic��eZdZdZdZeejfd�Zd�Z d�Z d�Z d�Z d�Z d �Zd �Zd �Zd �Zd �Zd�Zd�Zd�Zd!d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zej>d�Z d�Z!d�Z"d!d�Z#d�Z$d�Z%d!d �Z&y)"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-8c��||_||_d|_tjd|||�|j |�|_|j jd�|_d|_ |j�|_ y)NFzpoplib.connect�rbr) �host�port�_tls_established�sys�audit�_create_socket�sock�makefile�file� _debugging�_getresp�welcome)�selfrr�timeouts r �__init__z POP3.__init__bsg���� ��� � %��� � � �"�D�$��5��'�'��0�� ��I�I�&�&�t�,�� �����}�}��� r c�x�|� |s td��tj|j|jf|�S)Nz0Non-blocking socket (timeout=0) is not supported)� ValueError�socket�create_connectionrr)rrs r rzPOP3._create_socketms6�� � �w��O�P� P��'�'����D�I�I�(>��H�Hr c��|jdkDrtdt|��tjd||�|j j |tz�y)N�z*put*zpoplib.putline)r�print�reprrrr�sendall�CRLF�r�lines r �_putlinez POP3._putlinersB�� �?�?�Q� ��g�t�D�z� :� � � �"�D�$�/� � � ���$��+�&r c���|jrtdt|��t||j�}t j d|�r td��|j|�y)Nz*cmd*s[-]z*Control characters not allowed in commands) rr'r(�bytes�encoding�re�searchr"r-r+s r �_putcmdz POP3._putcmdzsM�� �?�?�E�'�4��:�6��T�4�=�=�)�� �9�9�'�� .��I�J� J� � � �d�r c�R�|jjtdz�}t|�tkDr t d��|j dkDrt dt|��|s t d��t|�}|ddtk(r|dd|fS|ddtk(r|dd|fS|dd|fS)Nr&z line too longz*get*z-ERR EOF����������) r�readline�_MAXLINE�lenrrr'r(r*�CR)rr,�octetss r �_getlinez POP3._getline�s����y�y�!�!�(�Q�,�/�� �t�9�x� ��o�.� .� �?�?�Q� ��g�t�D�z� :��;�z�2�2��T��� ���9�� ����9�f�$� $� ���8�r�>���"�:�v�%� %��C�R�y�&� � r c��|j�\}}|jdkDrtdt|��|j d�s t |��|S)Nr&z*resp*�+)r<rr'r(� startswithr)r�resp�os r rz POP3._getresp�sF���-�-�/���a� �?�?�Q� ��h��T� � ;����t�$��d�#� #�� r c���|j�}g}d}|j�\}}|dk7rJ|jd�r |dz }|dd}||z}|j|�|j�\}}|dk7r�J|||fS)Nr�.s..r&)rr<r?�append)rr@�listr;r,rAs r � _getlongrespzPOP3._getlongresp�s����}�}�����A�6��-�-�/���a��d�l����u�%��a�C���A�B�x���a�Z�F� �K�K�� ��m�m�o�G�D�!� �d�l��T�6�!�!r c�D�|j|�|j�S�N)r3rr+s r � _shortcmdzPOP3._shortcmd�s�� � � �T���}�}��r c�D�|j|�|j�SrH)r3rFr+s r �_longcmdz POP3._longcmd�s�� � � �T��� � �"�"r c��|jSrH)r�rs r � getwelcomezPOP3.getwelcome�s ���|�|�r c��||_yrH)r)r�levels r �set_debuglevelzPOP3.set_debuglevel�s ����r c�*�|jd|z�S)zVSend user name, return response (should indicate password required). zUSER %s�rI�r�users r rUz POP3.user�s�� �~�~�i�$�.�/�/r c�*�|jd|z�S)z�Send password, return response (response includes message count, mailbox size). NB: mailbox is locked by server from here to 'quit()' zPASS %srS)r�pswds r �pass_z POP3.pass_�s���~�~�i�$�.�/�/r c�*�|jd�}|j�}|jrtdt |��t |�dkr t d�� t|d�}t|d�}||fS#t$r t d��wxYw)z]Get mailbox status. Result is tuple of 2 ints (message count, mailbox size) �STATz*stat*�zInvalid STAT response formatr&�z.Invalid STAT response data: non-numeric values) rI�splitrr'r(r9r�intr")r�retval�rets� numMessages� sizeMessagess r �statz POP3.stat�s��� ����'���|�|�~�� �?�?�E�(�D��J�7� �t�9�q�=��<�=� =� P��d�1�g�,�K��t�A�w�<�L��\�*�*��� P��N�O� O� P�s �A=�=BNc�P�|�|jd|z�S|jd�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. zLIST %s�LIST�rIrK�r�whichs r rEz POP3.list�s-�� � ��>�>�)�e�"3�4� 4��}�}�V�$�$r c�*�|jd|z�S)zoRetrieve whole message number 'which'. Result is in form ['response', ['line', ...], octets]. zRETR %s�rKrgs r �retrz POP3.retrs�� �}�}�Y��.�/�/r c�*�|jd|z�S)zFDelete message number 'which'. Result is 'response'. zDELE %srSrgs r �delez POP3.dele s�� �~�~�i�%�/�0�0r c�$�|jd�S)zXDoes nothing. One supposes the response indicates the server is alive. �NOOPrSrMs r �noopz POP3.noops�� �~�~�f�%�%r c�$�|jd�S)z(Unmark all messages marked for deletion.�RSETrSrMs r �rsetz POP3.rsets���~�~�f�%�%r c�H�|jd�}|j�|S)zDSignoff: commit changes on server, unlock mailbox, close connection.�QUIT)rI�close)rr@s r �quitz POP3.quit"s���~�~�f�%�� � � � �� r c��� |j}d|_|�|j�|j}d|_|�1 |jtj �|j�yy#t $r8}|jtjk7rt|dd�dk7r�Yd}~�Nd}~wwxYw#|j�wxYw#|j}d|_|�� |jtj �nD#t $r8}|jtjk7rt|dd�dk7r�Yd}~nd}~wwxYw|j�w#|j�wxYwwxYw)z8Close the connection without assuming anything about it.N�winerrorri&') rrvr�shutdownr#� SHUT_RDWR�OSError�errno�ENOTCONN�getattr)rrr�excs r rvz POP3.close(s)�� !��9�9�D��D�I���� � � ��9�9�D��D�I��� !��M�M�&�"2�"2�3��J�J�L� ����� � �U�^�^�3�"�3� �A�6�%�?���� ���J�J�L���9�9�D��D�I��� !��M�M�&�"2�"2�3����� � �U�^�^�3�"�3� �A�6�%�?���� ���J�J�L��D�J�J�L�� �sp�%C�A.�. B/�7.B*�%B2�*B/�/B2�2C�E)�C>�=E�> D?�.D:�5E�:D?�?E�E)�E%�%E)c�*�|jd|z�S)z?Send RPOP command to access the mailbox with an alternate user.zRPOP %srSrTs r �rpopz POP3.rpopDs���~�~�i�$�.�/�/r s\+OK.[^<]*(<.*>)c�.�t||j�}|jj|j�}|s t d��ddl}|jd�|z}|j|�j�}|jd|�d|���S)a Authorisation - only possible if server has supplied a timestamp in initial greeting. Args: user - mailbox user; password - mailbox password. NB: mailbox is locked by server from here to 'quit()' z!-ERR APOP not supported by serverrNr&zAPOP � ) r/r0� timestamp�matchrr�hashlib�group�md5� hexdigestrI)rrU�password�secret�mr��digests r �apopz POP3.apopKs{���x����/�� �N�N� � ���� .����A�B� B�������F�"�����V�$�.�.�0���~�~�d�F�;�<��>�)�e�"3�4� 4��}�}�V�$�$r c�$�|jd�S)zITry to enter UTF-8 mode (see RFC 6856). Returns server response. �UTF8rSrMs r �utf8z POP3.utf8us���~�~�f�%�%r c��d�}i} |jd�}|d}|D]}||�\}}|||<� |S#t$r td��wxYw)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... c�T�|jd�j�}|d|ddfS)N�asciirr&)�decoder])r,�lsts r � _parsecapzPOP3.capa.._parsecap�s-���+�+�g�&�,�,�.�C��q�6�3�q�r�7�?� "r �CAPAr&z!-ERR CAPA not supported by server)rKr)rr��capsr@�rawcaps�capline�capnm�capargss r �capaz POP3.capa{sr�� #��� C��=�=��(�D��1�g�G�"��!*�7�!3���w�%��U� �#� � ��� C��A�B� B� C�s �-7�A c��ts td��|jr td��|j�}d|vr td��|�t j �}|j d�}|j|j|j��|_|jjd�|_ 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 established�STLSz!-ERR STLS not supported by server��server_hostnamerT) �HAVE_SSLrrr��ssl�_create_stdlib_contextrI� wrap_socketrrrr)r�contextr�r@s r �stlsz POP3.stls�s��� ��8�9� 9� � � ��D�E� E��y�y�{����~��A�B� B� �?��0�0�2�G��~�~�f�%���'�'�� � �8<� � �(�C�� ��I�I�&�&�t�,�� � $���� r rH)'rrr�__doc__r0� POP3_PORTr#�_GLOBAL_DEFAULT_TIMEOUTr rr-r3r<rrFrIrKrNrQrUrXrcrErkrmrprsrwrvr�r1�compiler�r�r�r�r�r�r�r r r rr3s���)�V�H�"+��7�7� '�I� '��!�*� "� �#�� � 0�0�+�0 %�0�1�&�&� � !�80� �� � �/�0�I�=�*=� %�&� �:r c�D�eZdZdZefej dd�d�Zd�Zdd�Z y)�POP3_SSLaNPOP3 client class over SSL connection Instantiate with: POP3_SSL(hostname, port=995, context=None) hostname - the hostname of the pop3 over ssl server port - port number context - a ssl.SSLContext See the methods of the parent class POP3 for more documentation. N)rr�c�n�|�tj�}||_tj ||||�yrH)r�r�r�rr )rrrrr�s r r zPOP3_SSL.__init__�s.�����4�4�6��"�D�L� �M�M�$��d�G� 4r c��tj||�}|jj||j��}|S)Nr�)rrr�r�r)rrrs r rzPOP3_SSL._create_socket�s<���&�&�t�W�5�D��<�<�+�+�D�<@�I�I�,�G�D��Kr c��td��)z�The method unconditionally raises an exception since the STLS command doesn't make any sense on an already established SSL/TLS session. r�)r)rr�s r r�z POP3_SSL.stls�s�� �D�E� Er rH) rrrr�� POP3_SSL_PORTr#r�r rr�r r r r�r��s,�� �'4� 5� &� >� >�� 5� �  Fr r��__main__r&r\r[z Message %d:z z-----------------------)'r�r}r1r#rr�r�� ImportError�__all__� Exceptionrr�r�r:�LFr*r8rr�rDr�argv�ar'rNrUrXrErc�numMsgs� totalSize�range�irk�header�msgr;r,rwr r r �r�s|��� � � � ����H� �-� ��#�)�"� � �� � �� �� �"�u�� ��x�x�v  �F�4�F�@ �N�N�:�� �z��� �S�X�X�a�[��A� �!�,�,�.���F�F�3�8�8�A�;���G�G�C�H�H�Q�K���F�F�H��6�6�8��W�i� �1�g��k� "�� !���q� ����f� �m�a�� ��D� �%�$�,� �� �'�(� #� �F�F�H���u ���H��s�E�E�E