Your IP : 18.226.187.224


Current Path : /lib64/python3.8/__pycache__/
Upload File :
Current File : //lib64/python3.8/__pycache__/smtpd.cpython-38.opt-2.pyc

U

e5d���@sZddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
dddddgZejdZd	ZGd
d�d�Ze�adZd
ZdZd$dd�ZGdd�dej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�d�Zdd�Z e!dk�rVe �Z"e"j#Z#de#k�rle#�$d�Z%e&e#de%�e'�e(�dg�Z)e#e%dd�Z#nddl*Z)e+e)e#�Z,e,e"j-e"j.fe"j/e"j0fe"j1e"j2d�Z3e"j4�r2zddl5Z5Wn.e6k
�r�e7dej8d �e�9d�YnXe5�:d!�d"Z;ze�4e;�Wn.e<k
�r0e7d#ej8d �e�9d�YnXze�=�Wne>k
�rTYnXdS)%�N)�warn)�
get_addr_spec�get_angle_addr�SMTPChannel�
SMTPServer�DebuggingServer�	PureProxy�MailmanProxyzPython SMTP proxy version 0.3c@seZdZdd�Zdd�ZdS)�DevnullcCsdS�N���self�msgrr�/usr/lib64/python3.8/smtpd.py�writef�z
Devnull.writecCsdSrr�rrrr�flushgrz
Devnull.flushN)�__name__�
__module__�__qualname__rrrrrrr
esr
�
z, i�cCs4ttt�tjd�|r&t|tjd�t�|�dS)N��file)�print�__doc__�globals�sys�stderr�exit)�coderrrr�usagepsr#c@s�eZdZdZdZdZe�efdd��Ze	dd��Z
edd	d	fd
d�Zdd
�Z
dd�Ze	dd��Zejdd��Ze	dd��Zejdd��Ze	dd��Zejdd��Ze	dd��Zejdd��Ze	dd��Zejdd��Ze	dd ��Zejd!d ��Ze	d"d#��Zejd$d#��Ze	d%d&��Zejd'd&��Ze	d(d)��Zejd*d)��Ze	d+d,��Zejd-d,��Ze	d.d/��Zejd0d/��Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dS)Srr�icCs|Srr)�xrrr�<lambda>|rzSMTPChannel.<lambda>cCs0zt|j���WStk
r*|jYSXdSr)�max�command_size_limits�values�
ValueError�command_size_limitrrrr�max_command_size_limit~sz"SMTPChannel.max_command_size_limitNFc	
Cs&tjj|||d�||_||_||_||_||_||_|rF|rFt	d��|rdd|_
d|_d|_t
|_nd|_
d|_td�|_d	|_|��d|_d
|_|j��t��|_z|��|_WnBtk
r�}z$|��|jdtjkr�WY�dSd}~XYnXtdt |j�t!d
�|�"d|jt#f�dS)N��map�Fdecode_data and enable_SMTPUTF8 cannot be set to True at the same timer�
�.r�
�.�
FrzPeer:rz	220 %s %s)$�asynchat�
async_chat�__init__�smtp_server�conn�addr�data_size_limit�enable_SMTPUTF8�_decode_datar*�_emptystring�_linesep�_dotsep�NEWLINE�_newline�ord�_set_rset_state�
seen_greeting�
extended_smtpr(�clear�socketZgetfqdn�fqdnZgetpeername�peer�OSError�close�args�errnoZENOTCONNr�repr�DEBUGSTREAM�push�__version__)	rZserverr9r:r;r.r<�decode_data�errrrrr7�s@


zSMTPChannel.__init__cCs.|j|_d|_g|_d|_d|_|�d�dS)NFrr2)�COMMAND�
smtp_state�mailfrom�rcpttos�require_SMTPUTF8�	num_bytes�set_terminatorrrrr�_set_post_data_state�sz SMTPChannel._set_post_data_statecCs|��d|_g|_dS�Nr)r\�
received_data�received_linesrrrrrD�szSMTPChannel._set_rset_statecCstdtd�|jS)NzTAccess to __server attribute on SMTPChannel is deprecated, use 'smtp_server' instead��r�DeprecationWarningr8rrrr�__server�s
�zSMTPChannel.__servercCstdtd�||_dS)NzRSetting __server attribute on SMTPChannel is deprecated, set 'smtp_server' insteadr`ra�r�valuerrrrc�s
�cCstdtd�|jS)NzUAccess to __line attribute on SMTPChannel is deprecated, use 'received_lines' insteadr`�rrbr_rrrr�__line�s
�zSMTPChannel.__linecCstdtd�||_dS)NzSSetting __line attribute on SMTPChannel is deprecated, set 'received_lines' insteadr`rfrdrrrrg�s
�cCstdtd�|jS)NzRAccess to __state attribute on SMTPChannel is deprecated, use 'smtp_state' insteadr`�rrbrVrrrr�__state�s
�zSMTPChannel.__statecCstdtd�||_dS)NzPSetting __state attribute on SMTPChannel is deprecated, set 'smtp_state' insteadr`rhrdrrrri�s
�cCstdtd�|jS)NzXAccess to __greeting attribute on SMTPChannel is deprecated, use 'seen_greeting' insteadr`�rrbrErrrr�
__greeting�s
�zSMTPChannel.__greetingcCstdtd�||_dS)NzVSetting __greeting attribute on SMTPChannel is deprecated, set 'seen_greeting' insteadr`rjrdrrrrk�s
�cCstdtd�|jS)NzSAccess to __mailfrom attribute on SMTPChannel is deprecated, use 'mailfrom' insteadr`�rrbrWrrrr�
__mailfrom�s
�zSMTPChannel.__mailfromcCstdtd�||_dS)NzQSetting __mailfrom attribute on SMTPChannel is deprecated, set 'mailfrom' insteadr`rlrdrrrrm�s
�cCstdtd�|jS)NzQAccess to __rcpttos attribute on SMTPChannel is deprecated, use 'rcpttos' insteadr`�rrbrXrrrr�	__rcpttos�s
�zSMTPChannel.__rcpttoscCstdtd�||_dS)NzOSetting __rcpttos attribute on SMTPChannel is deprecated, set 'rcpttos' insteadr`rnrdrrrro�s
�cCstdtd�|jS)NzTAccess to __data attribute on SMTPChannel is deprecated, use 'received_data' insteadr`�rrbr^rrrr�__data�s
�zSMTPChannel.__datacCstdtd�||_dS)NzRSetting __data attribute on SMTPChannel is deprecated, set 'received_data' insteadr`rprdrrrrqs
�cCstdtd�|jS)NzKAccess to __fqdn attribute on SMTPChannel is deprecated, use 'fqdn' insteadr`�rrbrIrrrr�__fqdn
s
�zSMTPChannel.__fqdncCstdtd�||_dS)NzISetting __fqdn attribute on SMTPChannel is deprecated, set 'fqdn' insteadr`rrrdrrrrss
�cCstdtd�|jS)NzKAccess to __peer attribute on SMTPChannel is deprecated, use 'peer' insteadr`�rrbrJrrrr�__peers
�zSMTPChannel.__peercCstdtd�||_dS)NzISetting __peer attribute on SMTPChannel is deprecated, set 'peer' insteadr`rtrdrrrrus
�cCstdtd�|jS)NzKAccess to __conn attribute on SMTPChannel is deprecated, use 'conn' insteadr`�rrbr9rrrr�__conn s
�zSMTPChannel.__conncCstdtd�||_dS)NzISetting __conn attribute on SMTPChannel is deprecated, set 'conn' insteadr`rvrdrrrrw%s
�cCstdtd�|jS)NzKAccess to __addr attribute on SMTPChannel is deprecated, use 'addr' insteadr`�rrbr:rrrr�__addr+s
�zSMTPChannel.__addrcCstdtd�||_dS)NzISetting __addr attribute on SMTPChannel is deprecated, set 'addr' insteadr`rxrdrrrry0s
�cCs&tj�|t|d|jrdnd��dS)Nr0�utf-8�ascii)r5r6rQ�bytesrYr
rrrrQ7s
�zSMTPChannel.pushcCs|d}|j|jkr|j}n|j|jkr*|j}|r<|j|kr<dS|rR|jt|�7_|jrl|j�	t
|d��n|j�	|�dS)Nrz)rVrUr,�DATAr;rZ�lenr=r_�append�str)r�data�limitrrr�collect_incoming_data<sz!SMTPChannel.collect_incoming_datac
Cs|j�|j�}tdt|�td�g|_|j|jk�r|jd}|_|sT|�	d�dS|j
sdt|d�}|�d�}|dkr�|�
�}d}n$|d|��
�}||dd���}|jr�|j|n|j}||kr�|�	d�dSt|d	|d�}|s�|�	d
|�dS||�dS|j|jk�r(|�	d�d|_dS|j�rR|j|jk�rR|�	d�d|_dSg}|�|j�D]:}	|	�r�|	d|jk�r�|�|	dd��n
|�|	��qb|j�|�|_|j|j|j|jf}
i}|j
�s�|j|jd
�}|j j!|
|�}|�"�|�s|�	d�n
|�	|�dS)NzData:rrz500 Error: bad syntaxrz� r$z500 Error: line too longZsmtp_z&500 Error: command "%s" not recognizedz451 Internal confusionz552 Error: Too much mail data)�mail_options�rcpt_options�250 OK)#r>�joinr_rrOrPrVrUrZrQr=r��find�upper�striprFr(r+�getattrr}r;�splitr?r@rrBr^rJrWrXr�r�r8�process_messager\)
r�lineZsz�i�command�argZmax_sz�methodr��textrM�kwargsZstatusrrr�found_terminatorLsl


��


�zSMTPChannel.found_terminatorcCsH|s|�d�dS|jr&|�d�dS|��||_|�d|j�dS)Nz501 Syntax: HELO hostname�503 Duplicate HELO/EHLOz250 %s)rQrErDrI�rr�rrr�	smtp_HELO�s

zSMTPChannel.smtp_HELOcCs�|s|�d�dS|jr&|�d�dS|��||_d|_|�d|j�|jrr|�d|j�|jdd7<|js�|�d�|jr�|�d	�|jdd
7<|�d�dS)Nz501 Syntax: EHLO hostnamer�Tz250-%sz250-SIZE %s�MAIL�z250-8BITMIMEz250-SMTPUTF8�
z250 HELP)	rQrErDrFrIr;r(r=r<r�rrr�	smtp_EHLO�s&



zSMTPChannel.smtp_EHLOcCs|r|�d�n
|�d�dS)Nz501 Syntax: NOOPr��rQr�rrr�	smtp_NOOP�szSMTPChannel.smtp_NOOPcCs|�d�|��dS)Nz221 Bye)rQZclose_when_doner�rrr�	smtp_QUIT�s
zSMTPChannel.smtp_QUITcCs0t|�}|d|���|kr,||d���SdSr])r~r�r�)r�keywordr�Zkeylenrrr�_strip_command_keyword�sz"SMTPChannel._strip_command_keywordcCsF|sdS|���d�r$t|�\}}nt|�\}}|s<||fS|j|fS)N)rr�<)�lstrip�
startswithrrZ	addr_spec)rr��address�restrrr�_getaddr�szSMTPChannel._getaddrcCsHi}|D]:}|�d�\}}}|��r,|r2|s2dS|r:|nd||<q|S)N�=T)�	partition�isalnum)r�params�resultZparam�eqrerrr�
_getparams�szSMTPChannel._getparamscCs|r�d}|��}|dkr$|�d�q�|dkr8|�d�q�|dkr^d}|jrR||7}|�|�q�|dkr�d	}|jrx||7}|�|�q�|d
kr�|�d�q�|dkr�|�d
�q�|dkr�|�d�q�|dkr�|�d�q�|dkr�|�d�q�|�d�n
|�d�dS)N� [SP <mail-parameters>]ZEHLOz250 Syntax: EHLO hostnameZHELOz250 Syntax: HELO hostnamer�z 250 Syntax: MAIL FROM: <address>ZRCPTz250 Syntax: RCPT TO: <address>r}z250 Syntax: DATAZRSETz250 Syntax: RSETZNOOPz250 Syntax: NOOPZQUITz250 Syntax: QUITZVRFYz250 Syntax: VRFY <address>zD501 Supported commands: EHLO HELO MAIL RCPT DATA RSET NOOP QUIT VRFYzD250 Supported commands: EHLO HELO MAIL RCPT DATA RSET NOOP QUIT VRFY)r�rQrF)rr�ZextendedZlc_argrrrr�	smtp_HELP�s:zSMTPChannel.smtp_HELPcCs@|r2|�|�\}}|r"|�d�q<|�d|�n
|�d�dS)NzB252 Cannot VRFY user, but will accept message and attempt deliveryz502 Could not VRFY %sz501 Syntax: VRFY <address>)r�rQ)rr�r�r�rrr�	smtp_VRFY�szSMTPChannel.smtp_VRFYcCs�|js|�d�dStd|td�d}|jr4|d7}|dkrJ|�|�dS|�d|�}|�|�\}}|sv|�|�dS|js�|r�|�|�dS|jr�|�d�dS|���	�|_
|�|j
�}|dkr�|�|�dS|js�|�
dd	�}|d
kr�|�d�dS|j�r8|�
dd
�}|dk�r d|_n|d
k	�r8|�d�dS|�
dd�}|�r�|���sb|�|�dS|j�r�t|�|jk�r�|�d�dSt|���dk�r�|�d�dS||_td|jtd�|�d�dS)N�503 Error: send HELO firstz	===> MAILrz 501 Syntax: MAIL FROM: <address>r�zFROM:z503 Error: nested MAIL commandZBODY�7BIT)r�Z8BITMIMEz1501 Error: BODY can only be one of 7BIT, 8BITMIMEZSMTPUTF8FTz&501 Error: SMTPUTF8 takes no argumentsZSIZEz:552 Error: message size exceeds fixed maximum message sizerz:555 MAIL FROM parameters not recognized or not implementedzsender:r�)rErQrrPrFr�r�rWr�r�r�r�r=�popr<rY�isdigitr;�intr~�keys)rr��	syntaxerrr�r�Zbody�smtputf8�sizerrr�	smtp_MAILsh














zSMTPChannel.smtp_MAILcCs|js|�d�dStd|td�|js6|�d�dSd}|jrH|d7}|dkr^|�|�dS|�d|�}|�|�\}}|s�|�|�dS|js�|r�|�|�dS|���	�|_
|�|j
�}|dkr�|�|�dSt|�
��dkr�|�d	�dS|j�|�td
|jtd�|�d�dS)Nr�z	===> RCPTrz503 Error: need MAIL commandz501 Syntax: RCPT TO: <address>r�zTO:rz8555 RCPT TO parameters not recognized or not implementedzrecips:r�)rErQrrPrWrFr�r�r�r�r�r�r~r�rXr)rr�r�r�r�rrr�	smtp_RCPT7s@







zSMTPChannel.smtp_RCPTcCs(|r|�d�dS|��|�d�dS)Nz501 Syntax: RSETr�)rQrDr�rrr�	smtp_RSETZs

zSMTPChannel.smtp_RSETcCsZ|js|�d�dS|js(|�d�dS|r:|�d�dS|j|_|�d�|�d�dS)Nr�z503 Error: need RCPT commandz501 Syntax: DATAs
.
z#354 End data with <CR><LF>.<CR><LF>)rErQrXr}rVr[r�rrr�	smtp_DATAas



zSMTPChannel.smtp_DATAcCs|�d�dS)Nz502 EXPN not implementedr�r�rrr�	smtp_EXPNpszSMTPChannel.smtp_EXPN),rrrrUr}r+�collections�defaultdictr(�propertyr,�DATA_SIZE_DEFAULTr7r\rDZ_SMTPChannel__server�setterZ_SMTPChannel__lineZ_SMTPChannel__stateZ_SMTPChannel__greetingZ_SMTPChannel__mailfromZ_SMTPChannel__rcpttosZ_SMTPChannel__dataZ_SMTPChannel__fqdnZ_SMTPChannel__peerZ_SMTPChannel__connZ_SMTPChannel__addrrQr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrws�
�
'	





















>#6#c@s2eZdZeZedddfdd�Zdd�Zdd�ZdS)	rNFcCs�||_||_||_||_||_|r.|r.td��tjj||d�zNt	j
|dt	ji�}|�|dd|dd�|�
�|�|�|�d�Wn|���Yn(Xtd|jjt�t���||ftd�dS)	Nr/r-�typerr$�z0%s started at %s
	Local addr: %s
	Remote addr:%sr)Z
_localaddr�_remoteaddrr;r<r=r*�asyncore�
dispatcherr7rHZgetaddrinfoZSOCK_STREAMZ
create_socketZset_reuse_addrZbindZlistenrLr�	__class__r�time�ctimerP)rZ	localaddrZ
remoteaddrr;r.r<rSZgai_resultsrrrr7xs6�
��zSMTPServer.__init__c	Cs6tdt|�td�|�||||j|j|j|j�}dS)NzIncoming connection from %sr)rrOrP�
channel_classr;�_mapr<r=)rr9r:Zchannelrrr�handle_accepted�s�zSMTPServer.handle_acceptedcKst�dSr)�NotImplementedError�rrJrWrXr�r�rrrr��szSMTPServer.process_message)	rrrrr�r�r7r�r�rrrrrts�
c@seZdZdd�Zdd�ZdS)rcCsld}|��}|D]V}|rL|sLd|d}t|t�s@t|�d��}t|�d}t|t�s^t|�}t|�qdS)Nr$zX-Peer: rrz)�
splitlines�
isinstancer�rO�encoder)rrJr�Z	inheaders�linesr�Z
peerheaderrrr�_print_message_content�s

z&DebuggingServer._print_message_contentcKsXtd�|r@|�d�r&td|d�|�d�r@td|d�|�||�td�dS)Nz%---------- MESSAGE FOLLOWS ----------r�zmail options: %sr�zrcpt options: %s
z%------------ END MESSAGE ------------)r�getr�r�rrrr��s

zDebuggingServer.process_messageN)rrrr�r�rrrrr�scs,eZdZ�fdd�Zdd�Zdd�Z�ZS)rcs.d|kr|drtd��tt|�j||�dS)Nr<z$PureProxy does not support SMTPUTF8.�r*�superrr7�rrMr��r�rrr7�szPureProxy.__init__c	Csf|�d�}d}|D]}|sq(|d7}q|�|d|d�t�|�}|�|||�}td|td�dS)Nrrr$z
X-Peer: %szwe got some refusals:r)r��insertrAr��_deliverrrP)	rrJrWrXr�r�r�r��refusedrrrr��s


zPureProxy.process_messagec
Cs�ddl}i}zB|��}|�|jd|jd�z|�|||�}W5|��XWn�|jk
r�}ztdtd�|j	}W5d}~XYnft
|jfk
r�}zBtd|jtd�t
|dd�}t
|dd	�}	|D]}
||	f||
<q�W5d}~XYnX|S)
Nrr$zgot SMTPRecipientsRefusedrZgotZ	smtp_code���Z
smtp_error�ignore)�smtplibZSMTPZconnectr��quitZsendmailZSMTPRecipientsRefusedrrPZ
recipientsrKZ
SMTPExceptionr�r�)rrWrXr�r�r��s�eZerrcode�errmsg�rrrrr��s$ zPureProxy._deliver)rrrr7r�r��
__classcell__rrr�rr�scs$eZdZ�fdd�Zdd�Z�ZS)r	cs.d|kr|drtd��tt|�j||�dS)Nr<z'MailmanProxy does not support SMTPUTF8.r�r�r�rrr7
szMailmanProxy.__init__cCs*ddlm}ddlm}ddlm}ddlm}g}	|D]t}
|
���d�d}|�d�}t|�dkrfq8|d}
t|�dkr�|d	}nd
}|�	|
�r8|dkr�q8|	�
|
|
|f�q8|	D]\}
}
}|�|
�q�tdd
�
|�td�|r�|�|||�}td|td�i}||�}|�|�}|�d��s&||d<|�d��sDt�t���|d<|	D]�\}
}
}td|
td�|�|
�}|�s�|j|
dd�}|||
<|d
k�r�|j|d	d�n�|dk�r�|j|d	d�nh|dk�r�|j|d	d�nN|dk�r�|j|d	d�n4|dk�rH|dk�rd|d <nd!|d <|j|d	d��qHdS)"Nr)�StringIO)�Utils)�Message)�MailList�@�-r`r$r)r�admin�owner�requestr��leavezforwarding recips:r�rzwe got refusals:�fromZFrom�dateZDatezsending message to)�lock)�tolistr�)Ztoadminr�)Ztoownerr�)Z	torequest)r�r�r�Z	subscribeZSubjectZunsubscribe)�ior�ZMailmanr�r�r��lowerr�r~Zlist_existsr�removerr�rPr�r�r�r�ZEnqueue)rrJrWrXr�r�r�r�r�Z	listnamesZrcptZlocal�partsZlistnamer�r�Zmlistsr�rZmlistrrrr�sb










zMailmanProxy.process_message)rrrr7r�r�rrr�rr	sc@seZdZdZdZdZdZdS)�OptionsTrNF)rrr�setuid�	classname�
size_limitr<rrrrr�_sr�c
Cspz.t�tjdd�dddddddd	g�\}}Wn.tjk
r\}ztd|�W5d}~XYnXt�}|D]�\}}|d
kr�td�qh|dkr�tt�t�d�qh|d
kr�d|_	qh|dkr�||_
qh|dkr�tjaqh|dkr�d|_
qh|dkrhzt|�}||_Wqhtd|tjd�t�d�YqhXqht|�dk�r<d}d}nPt|�dk�rX|d}d}n4t|�dk�rx|d}|d}ntddt�|��|�d�}	|	dk�r�tdd|�|d|	�|_zt||	dd��|_Wn$tk
�r�tdd|�YnX|�d�}	|	dk�rtdd|�|d|	�|_zt||	dd��|_Wn$tk
�rjtdd|�YnX|S) Nr$z	nVhc:s:duzclass=Znosetuid�version�helpzsize=�debugr�)z-hz--helpr)z-Vz	--version)z-nz
--nosetuidF)z-cz--class)z-dz--debug)z-uz
--smtputf8T)z-sz--sizezInvalid size: rzlocalhost:8025zlocalhost:25r`�zInvalid arguments: %s�:zBad local spec: %szBad local port: %szBad remote spec: %szBad remote port: %s)�getoptr�argv�errorr#r�rrRr!r�r�r rPr<r�r�r~�
COMMASPACEr�r��	localhost�	localportr*�
remotehost�
remoteport)
ZoptsrMr��options�optr�Zint_sizeZ	localspecZ
remotespecr�rrr�	parseargsfsv��






r�__main__r1r$)r<z7Cannot import module "pwd"; try running with -n option.r�nobodyr`z3Cannot setuid "nobody"; try running with -n option.)r)?r�osrNrr�rHr�r5r��warningsrZemail._header_value_parserrr�__all__rZprogramrRr
rPrArr�r#r6rr�rrrr	r�rrrr��rfindZlastdot�
__import__r�locals�modrr�Zclass_rr	r
rr�r<�proxyr��pwd�ImportErrorrr r!�getpwnamr�PermissionErrorZloop�KeyboardInterruptrrrr�<module>Ps��

M-SB




�

?>