a �DOg]��@sVddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Zgd�ZdZdZdZdZdZd Ze�d ej�ZGd d �d e�ZGd d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd�de�Z#dd �Z$d!d"�Z%d#d$�Z&d%d&�Z'd'd(�Z(z ddl)Z)Wne*�y~d)Z+Yn0d*Z+Gd+d,�d,�Z,e+�r�Gd-d.�d.e,�Z-e�.d.�d/Z/Gd0d1�d1e,�Z0e1d2k�rRd3d4�Z2e2d5�Z3e2d6��4d7�Z5e6d8�d9Z7e j8�9�Z:e:�s�qe7e:Z7�q�e6d:e;e7��e,d;�Ze3e5e7�e<�?�dS)=�N)� body_encode) � SMTPException�SMTPNotSupportedError�SMTPServerDisconnected�SMTPResponseException�SMTPSenderRefused�SMTPRecipientsRefused� SMTPDataError�SMTPConnectError� SMTPHeloError�SMTPAuthenticationError� quoteaddr� quotedata�SMTP�i�� s i �z auth=(.*)c@s eZdZdS)rN��__name__� __module__� __qualname__�rr�/usr/lib64/python3.9/smtplib.pyrHsrc@s eZdZdS)rNrrrrrrKsrc@s eZdZdS)rNrrrrrrRsrc@seZdZdd�ZdS)rcCs||_||_||f|_dS�N)� smtp_code� smtp_error�args)�self�code�msgrrr�__init__cszSMTPResponseException.__init__N�rrrr rrrrrZs rc@seZdZdd�ZdS)rcCs"||_||_||_|||f|_dSr)rr�senderr)rrrr"rrrr oszSMTPSenderRefused.__init__Nr!rrrrrhsrc@seZdZdd�ZdS)rcCs||_|f|_dSr)� recipientsr)rr#rrrr }szSMTPRecipientsRefused.__init__Nr!rrrrrusrc@s eZdZdS)r Nrrrrrr �sr c@s eZdZdS)r Nrrrrrr �sr c@s eZdZdS)r Nrrrrrr �sr c@s eZdZdS)r Nrrrrrr �sr cCs>tj�|�\}}||fdkr6|���d�r.|Sd|Sd|S)N��r%�)�email�utils� parseaddr�strip� startswith�Z addrstringZ displayname�addrrrrr �s  r cCs$tj�|�\}}||fdkr |S|S)Nr$)r'r(r)r,rrr� _addr_only�s r.c Cst�ddt�dt|��S)Nz(?m)^\.z..�(?:\r\n|\n|\r(?!\n))��re�sub�CRLF��datarrrr�s �rcCst�dd|�S)Ns(?m)^\.s..)r1r2)Zbindatarrr�_quote_periods�sr6cCst�dt|�S)Nr/r0r4rrr� _fix_eols�sr7FTc@sveZdZdZdZdZdZdZdZdZ e Z ddde j dfdd�Zdd�Zd d �Zd d �Zd d�Zdd�ZdMdd�Zdd�ZdNdd�Zdd�ZdOdd�ZdPdd�ZdQdd�Zd d!�ZdRd"d#�Zd$d%�Zd&d'�Zd(d)�ZdSd+d,�Z dTd-d.�Z!d/d0�Z"d1d2�Z#e#Z$d3d4�Z%d5d6�Z&d7d8�d9d:�Z'dUd;d<�Z(dVd=d>�Z)dWd?d@�Z*d7d8�dAdB�Z+dXdCdD�Z,dYdEdF�Z-dZdGdH�Z.dIdJ�Z/dKdL�Z0dS)[rrN�ehlor%c Cs�||_||_i|_d|_||_d|_|rR|�||�\}}|dkrR|��t||��|durb||_ nNt � �}d|vrz||_ n6d} zt � t � ��} Wnt jy�Yn0d| |_ dS)N�asciir���.z 127.0.0.1z[%s])�_host�timeout�esmtp_features�command_encoding�source_address�_auth_challenge_count�connect�closer �local_hostname�socket�getfqdn� gethostbyname� gethostname�gaierror) r�host�portrDr=r@rrZfqdnr-rrrr �s, z SMTP.__init__cCs|Srr�rrrr� __enter__szSMTP.__enter__cGsTzDz$|�d�\}}|dkr$t||��Wnty8Yn0W|��n |��0dS)NZQUIT��)�docmdrrrC)rrr�messagerrr�__exit__s z SMTP.__exit__cCs ||_dSr)� debuglevel)rrRrrr�set_debuglevel"szSMTP.set_debuglevelcGsB|jdkr.ttj����g|�Rdtji�nt|dtji�dS)N��file)rR�print�datetimeZnow�time�sys�stderr�rrrrr� _print_debug+s $zSMTP._print_debugcCsF|dur|std��|jdkr2|�d||f|j�t�||f||j�S)N�0Non-blocking socket (timeout=0) is not supportedrz connect: to)� ValueErrorrRr\r@rE�create_connection)rrJrKr=rrr� _get_socket1s   �zSMTP._get_socket� localhostcCs�|r ||_|sz|�d�|�d�krz|�d�}|dkrz|d|�||dd�}}z t|�}Wntyxtd��Yn0|s�|j}t�d|||�|� |||j �|_ d|_ |� �\}}|jdkr�|�dt|��||fS)N�:rrTznonnumeric portzsmtplib.connect�connect:)r@�find�rfind�intr^�OSError� default_portrY�auditr`r=�sockrU�getreplyrRr\�repr)rrJrKr@�irrrrrrB;s&      z SMTP.connectcCs�|jdkr|�dt|��|jrzt|t�r6|�|j�}t� d||�z|j� |�Wq�t yv|� �t d��Yq�0nt d��dS)Nrzsend:z smtplib.send�Server not connectedzplease run connect() first)rRr\rlrj� isinstance�str�encoder?rYri�sendallrgrCr)r�srrr�send\s    z SMTP.sendcCsd|dkr|}n|�d|��}d|vs,d|vrN|�dd��dd�}td|����|�|�t���dS)Nr%� � � z\nz\rz=command and arguments contain prohibited newline characters: )�replacer^rtr3)r�cmdrrsrrr�putcmdos�z SMTP.putcmdc CsPg}|jdur|j�d�|_z|j�td�}Wn<tyl}z$|��tdt|���WYd}~n d}~00|s�|��td��|j dkr�|� dt |��t |�tkr�|��t dd��|�|d d��d ��|dd �}z t|�}Wnt�yd }Y�q Yn0|d d �d kr�q qd�|�}|j dk�rH|� d||f�||fS)N�rbrTz Connection unexpectedly closed: zConnection unexpectedly closedrzreply:i�zLine too long.�s �������-� zreply: retcode (%s); Msg: %a)rUrj�makefile�readline�_MAXLINErgrCrrprRr\rl�lenr�appendr*rfr^�join)r�resp�line�erZerrcode�errmsgrrrrk|s>  �        z SMTP.getreplycCs|�||�|��Sr�rzrk)rryrrrrrO�s z SMTP.docmdcCs,|�d|p|j�|��\}}||_||fS)N�helo)rzrDrk� helo_resp)r�namerrrrrr��s z SMTP.heloc Cs.i|_|�|j|p|j�|��\}}|dkrJt|�dkrJ|��td��||_|dkr`||fSd|_ |j� d�� d�}|d=|D]�}t � |�}|r�|j�dd �d |�d�d|jd<q�t� d |�}|r�|�d ���}|j|�d �d���} |dk�r|j�|d �d | |j|<q�| |j|<q�||fS) Nr~rrn��rTzlatin-1rw�authr%ruz((?P[A-Za-z0-9][A-Za-z0-9\-]*) ?�feature)r>rz�ehlo_msgrDrkr�rCr� ehlo_resp� does_esmtp�decode�split� OLDSTYLE_AUTH�match�get�groupsr1�group�lower�string�endr*) rr�rrr��eachZ auth_match�mr��paramsrrrr8�sB   � �    ��  z SMTP.ehlocCs|��|jvSr)r�r>)r�optrrr�has_extn�sz SMTP.has_extncCs|�d|�|��dS)N�helprTr�r[rrrr��s z SMTP.helpcCsd|_|�d�S)Nr9�rset)r?rOrLrrrr��sz SMTP.rsetcCs$z |��WntyYn0dSr)r�rrLrrr�_rset�s  z SMTP._rsetcCs |�d�S)N�noop)rOrLrrrr� sz SMTP.nooprcCshd}|rH|jrHtdd�|D��r:|�d�r2d|_ntd��dd�|�}|�dd t|�|f�|��S) Nr%css|]}|��dkVqdS)�smtputf8N)r�)�.0�xrrr� �zSMTP.mail..r�zutf-8z SMTPUTF8 not supported by serverru�mailz FROM:%s%s) r��anyr�r?rr�rzr rk)rr"�options� optionlistrrrr�s   �z SMTP.mailcCs<d}|r|jrdd�|�}|�ddt|�|f�|��S)Nr%ru�rcptzTO:%s%s)r�r�rzr rk)rZrecipr�r�rrrr�$s  z SMTP.rcptcCs�|�d�|��\}}|jdkr0|�d||f�|dkrDt||��n|t|t�r\t|��d�}t |�}|dd�t kr||t }|dt }|� |�|��\}}|jdkr�|�d||f�||fSdS)Nr5rzdata:ibr9������.) rzrkrRr\r rorpr7rqr6�bCRLFrt)rrr�repl�qrrrr5,s"         z SMTP.datacCs|�dt|��|��S)N�vrfy�rzr.rk�r�addressrrr�verifyIsz SMTP.verifycCs|�dt|��|��S)N�expnr�r�rrrr�Psz SMTP.expncCsb|jdur^|jdur^d|��dkr0dks^n|��\}}d|krRdks^nt||��dS)N��ri+)r�r�r8r�r )rrr�rrr�ehlo_or_helo_if_neededWs  zSMTP.ehlo_or_helo_if_neededT��initial_response_okc Cs�|��}|r|�nd}|durPt|�d�dd�}|�d|d|�\}}d|_n|�d|�\}}d|_|dkr�|jd7_t�|�}t||��d�dd�}|�|�\}}|jtkrftd t ||f���qf|d vr�||fSt ||��dS) Nr9r%)ZeolZAUTHrurTriNz4Server AUTH mechanism infinite loop. Last response: ���i�) �upper� encode_base64rqrOrA�base64Z decodebytes� _MAXCHALLENGErrlr ) rZ mechanismZ authobjectr�Zinitial_response�responserr�� challengerrrr�hs0 �  ��z SMTP.authcCs0|dur dS|jdt�|j�d�|d���S)Nrur9�md5)�user�hmac�HMAC�passwordrq� hexdigest�rr�rrr� auth_cram_md5�s  �zSMTP.auth_cram_md5cCsd|j|jfS)Nz%s%s)r�r�r�rrr� auth_plain�szSMTP.auth_plaincCs"|dus|jdkr|jS|jSdS)N�)rAr�r�r�rrr� auth_login�szSMTP.auth_loginc s�|��|�d�std��|jd���gd�}�fdd�|D�}|sNtd��|||_|_|D]v}d|��� dd �}z4|j |t ||�|d �\}} |d vr�|| fWSWq`t y�} z| } WYd} ~ q`d} ~ 00q`| �dS) Nr�z,SMTP AUTH extension not supported by server.)zCRAM-MD5ZPLAINZLOGINcsg|]}|�vr|�qSrr)r�r��Zadvertised_authlistrr� �s�zSMTP.login..z(No suitable authentication method found.Zauth_�-�_r�r�) r�r�rr>r�rr�r�r�rxr��getattrr ) rr�r�r�Zpreferred_authsZauthlistZ authmethodZ method_namerr�r�Zlast_exceptionrr�r�login�s. � � z SMTP.logincCs�|��|�d�std��|�d�\}}|dkr�tsr�r)rr�r��contextr�Zreplyr�rrrr��s@ ���� z SMTP.starttlsc Cs^|��g}t|t�r$t|��d�}|jrZ|�d�rF|�dt|��|D]}|�|�qJ|� ||�\}} |dkr�|dkr�|� �n|� �t || |��i} t|t�r�|g}|D]H} |� | |�\}} |dkr�|dkr�|| f| | <|dkr�|� �t| ��q�t| �t|�k�r|� �t| ��|�|�\}} |dk�rZ|dk�rH|� �n|� �t|| ��| S)Nr9�sizezsize=%dr�i���)r�rorpr7rqr�r�r�r�r�rCr�rr�rr5r ) r� from_addr�to_addrsr� mail_options� rcpt_optionsZ esmtp_opts�optionrr�Zsenderrsr�rrr�sendmail(sF@            z SMTP.sendmailcCs�|��|�d�}|dur d}nt|�dkr2d}ntd��|dur||d|vrZ||dn ||d}tj�|g�dd}|dur�d d �||d ||d ||d fD�}dd �tj�|�D�}t�|�} | d =| d=d} zd�|g|��� d�Wn,t �y&|� d��st d��d} Yn0t ���f} | �rftjj| |jjdd�d�} g|�d�d�R}n tj�| �} | j| dd�| ��} Wd�n1�s�0Y|�||| ||�S)Nz Resent-Dater%rTzResent-z0message has more than one 'Resent-' header blockZSender�FromrcSsg|]}|dur|�qSrr)r��frrrr��s�z%SMTP.send_message..�ToZBccZCccSsg|] }|d�qS)rTr)r��arrrr��r�z Resent-BccFr9r�z�One or more source or delivery addresses require internationalized email support, but the server does not advertise the required SMTPUTF8 capabilityT)�utf8)�policyZSMTPUTF8z BODY=8BITMIMEr)�linesep)r�Zget_allr�r^r'r(Z getaddresses�copyr�rq�UnicodeEncodeErrorr�r�io�BytesIO� generatorZBytesGeneratorr�ZcloneZflatten�getvaluer�)rrr�r�r�r�ZresentZ header_prefixZ addr_fieldsZmsg_copy� internationalZbytesmsg�gZflatmsgrrr� send_message�sV   � �  �  �  � ( �zSMTP.send_messagecCsTz4|j}d|_|r|��W|j}d|_|rP|��n|j}d|_|rN|��0dSr)rUrCrj)rrUrjrrrrC�s  �z SMTP.closecCs.|�d�}d|_|_i|_d|_|��|S)N�quitF)rOr�r�r>r�rC)r�resrrrr�s   z SMTP.quit)rarN)r%)r%)r%)r%)r%)r)r)N)N)N)NNN)rr)NNrr)1rrrrRrjrUr�r�r�r�� SMTP_PORTrhrE�_GLOBAL_DEFAULT_TIMEOUTr rMrQrSr\r`rBrtrzrkrOr�r8r�r�r�r�r�r�r�r5r�r�r�r�r�r�r�r�r�r�r�rrCrrrrrr�sd� 0   ! 1  3    0  B 8� h� M rcs<eZdZeZdddddejddfdd�Z�fdd�Z�Z S)�SMTP_SSLr%rNc Cs�|dur|durtd��|dur0|dur0td��|dus@|durVddl} | �dtd�||_||_|durxtj||d�}||_t � ||||||�dS)Nr�r�rr�r�r�) r^r�r�r�r�r�r�r�r�rr ) rrJrKrDr�r�r=r@r�r�rrrr s&���zSMTP_SSL.__init__cs@|jdkr|�d||f�t��|||�}|jj||jd�}|S)Nrrcr�)rRr\�superr`r�r�r<)rrJrKr=Z new_socket�� __class__rrr`s �zSMTP_SSL._get_socket) rrr� SMTP_SSL_PORTrhrErr r`� __classcell__rrr rr�s� ri�cs<eZdZdZdeddejf�fdd� Zd �fdd � Z�Z S) �LMTPZlhlor%Ncst�j|||||d�dS)N)rDr@r=)rr )rrJrKrDr@r=r rrr <s �z LMTP.__init__rarcs�|ddkrt�j|||d�S|jdur6|js6td��zBt�tjtj�|_|jtjurd|j� |j�d|_ |j�|�Wn@t y�|j dkr�|� d|�|jr�|j��d|_�Yn0|��\}}|j dkr�|� d|�||fS)Nr�/)r@r]z connect fail:rc)rrBr=r^rE�AF_UNIX� SOCK_STREAMrjr� settimeoutrUrgrRr\rCrk)rrJrKr@rrr rrrBBs*         z LMTP.connect)rarN) rrrr�� LMTP_PORTrErr rBr rrr rr ,s �r �__main__cCs(tj�|d�tj��tj����S)Nz: )rY�stdout�write�flush�stdinr�r*)�promptrrrras rr�r��,zEnter message, end with ^D:r%zMessage length is %drarT)@rEr�r1Z email.utilsr'Z email.messageZemail.generatorr�r�r�rWrYZemail.base64mimerr��__all__rr r3r�r�r��compile�Ir�rgrrrrrrr r r r r r.rr6r7r�� ImportErrorr�rrr�rr rrZfromaddrr�ZtoaddrsrVrrr�r�r�ZserverrSr�rrrrr�,s�       </ 4