Your IP : 3.22.42.25


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/smtpd.cpython-310.opt-2.pyc

o

6��fj��@s^	ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZgd�Zede
dd�ddlZddlZejdZdZGd	d
�d
�Ze�adZdZd
Zd'dd�ZGdd�dej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�d�Z dd�Z!e"dk�r-e!�Z#e#j$Z$d e$vr�e$�%d �Z&e'e$de&�e(�e)�dg�Z*e$e&d!d�Z$nddl+Z*e,e*e$�Z-e-e#j.e#j/fe#j0e#j1fe#j2e#j3d"�Z4e#j5�rzddl6Z6Wne7y�e8d#ej9d$�e�:d!�Ynwe6�;d%�dZ<ze�5e<�Wne=�ye8d&ej9d$�e�:d!�Ynwze�>�WdSe?�y,YdSwdS)(�N)�warn)�
get_addr_spec�get_angle_addr)�SMTPChannel�
SMTPServer�DebuggingServer�	PureProxy�MailmanProxyz�The smtpd module is deprecated and unmaintained and will be removed in Python 3.12.  Please see aiosmtpd (https://aiosmtpd.readthedocs.io/) for the recommended replacement.�)�
stacklevelzPython SMTP proxy version 0.3c@�eZdZdd�Zdd�ZdS)�DevnullcC�dS�N���self�msgrr�,/opt/alt/python310/lib64/python3.10/smtpd.py�writer�z
Devnull.writecCrrr�rrrr�flushsrz
Devnull.flushN)�__name__�
__module__�__qualname__rrrrrrr
qsr
�
z, i�cCs4ttt�tjd�|rt|tjd�t�|�dS)N��file)�print�__doc__�globals�sys�stderr�exit)�coderrrr�usage|sr'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)�xrrr�<lambda>�rzSMTPChannel.<lambda>cCs*zt|j���WSty|jYSwr)�max�command_size_limits�values�
ValueError�command_size_limitrrrr�max_command_size_limit�s

�z"SMTPChannel.max_command_size_limitNFc	
Cs tjj|||d�||_||_||_||_||_||_|r#|r#t	d��|r2d|_
d|_d|_t
|_nd|_
d|_td�|_d	|_|��d|_d
|_|j��t��|_z|��|_Wntyy}z|��|jtjkrn�WYd}~dSd}~wwtdt|j�t d�|�!d
|jt"f�dS)N��map�Fdecode_data and enable_SMTPUTF8 cannot be set to True at the same timer�
�.��
�.�
FzPeer: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�errnoZENOTCONNr �repr�DEBUGSTREAM�push�__version__)	rZserverr>r?r@r2rA�decode_data�errrrrr<�sD


��zSMTPChannel.__init__cCs0	|j|_d|_g|_d|_d|_|�d�dS)NFrr7)�COMMAND�
smtp_state�mailfrom�rcpttos�require_SMTPUTF8�	num_bytes�set_terminatorrrrr�_set_post_data_state�sz SMTPChannel._set_post_data_statecCs	|��d|_g|_dS�Nr)r`�
received_data�received_linesrrrrrI�s
zSMTPChannel._set_rset_statecC�tdtd�|jS)NzTAccess to __server attribute on SMTPChannel is deprecated, use 'smtp_server' insteadr
�r�DeprecationWarningr=rrrr�__server���zSMTPChannel.__servercC�tdtd�||_dS)NzRSetting __server attribute on SMTPChannel is deprecated, set 'smtp_server' insteadr
re�r�valuerrrrg���
cCrd)NzUAccess to __line attribute on SMTPChannel is deprecated, use 'received_lines' insteadr
�rrfrcrrrr�__line�rhzSMTPChannel.__linecCri)NzSSetting __line attribute on SMTPChannel is deprecated, set 'received_lines' insteadr
rmrjrrrrn�rlcCrd)NzRAccess to __state attribute on SMTPChannel is deprecated, use 'smtp_state' insteadr
�rrfrZrrrr�__state�rhzSMTPChannel.__statecCri)NzPSetting __state attribute on SMTPChannel is deprecated, set 'smtp_state' insteadr
rorjrrrrp�rlcCrd)NzXAccess to __greeting attribute on SMTPChannel is deprecated, use 'seen_greeting' insteadr
�rrfrJrrrr�
__greeting�rhzSMTPChannel.__greetingcCri)NzVSetting __greeting attribute on SMTPChannel is deprecated, set 'seen_greeting' insteadr
rqrjrrrrr�rlcCrd)NzSAccess to __mailfrom attribute on SMTPChannel is deprecated, use 'mailfrom' insteadr
�rrfr[rrrr�
__mailfrom�rhzSMTPChannel.__mailfromcCri)NzQSetting __mailfrom attribute on SMTPChannel is deprecated, set 'mailfrom' insteadr
rsrjrrrrt�rlcCrd)NzQAccess to __rcpttos attribute on SMTPChannel is deprecated, use 'rcpttos' insteadr
�rrfr\rrrr�	__rcpttosrhzSMTPChannel.__rcpttoscCri)NzOSetting __rcpttos attribute on SMTPChannel is deprecated, set 'rcpttos' insteadr
rurjrrrrvrlcCrd)NzTAccess to __data attribute on SMTPChannel is deprecated, use 'received_data' insteadr
�rrfrbrrrr�__datarhzSMTPChannel.__datacCri)NzRSetting __data attribute on SMTPChannel is deprecated, set 'received_data' insteadr
rwrjrrrrxrlcCrd)NzKAccess to __fqdn attribute on SMTPChannel is deprecated, use 'fqdn' insteadr
�rrfrNrrrr�__fqdnrhzSMTPChannel.__fqdncCri)NzISetting __fqdn attribute on SMTPChannel is deprecated, set 'fqdn' insteadr
ryrjrrrrzrlcCrd)NzKAccess to __peer attribute on SMTPChannel is deprecated, use 'peer' insteadr
�rrfrOrrrr�__peer!rhzSMTPChannel.__peercCri)NzISetting __peer attribute on SMTPChannel is deprecated, set 'peer' insteadr
r{rjrrrr|&rlcCrd)NzKAccess to __conn attribute on SMTPChannel is deprecated, use 'conn' insteadr
�rrfr>rrrr�__conn,rhzSMTPChannel.__conncCri)NzISetting __conn attribute on SMTPChannel is deprecated, set 'conn' insteadr
r}rjrrrr~1rlcCrd)NzKAccess to __addr attribute on SMTPChannel is deprecated, use 'addr' insteadr
�rrfr?rrrr�__addr7rhzSMTPChannel.__addrcCri)NzISetting __addr attribute on SMTPChannel is deprecated, set 'addr' insteadr
rrjrrrr�<rlcCs&tj�|t|d|jr
dnd��dS)Nr4�utf-8�ascii)r:r;rU�bytesr]rrrrrUCs

�zSMTPChannel.pushcCs~d}|j|jkr|j}n	|j|jkr|j}|r|j|krdS|r)|jt|�7_|jr7|j�	t
|d��dS|j�	|�dS)Nr�)rZrYr0�DATAr@r^�lenrBrc�append�str)r�data�limitrrr�collect_incoming_dataHsz!SMTPChannel.collect_incoming_datac
Cs|j�|j�}tdt|�td�g|_|j|jkr�|jd}|_|s)|�	d�dS|j
s1t|d�}|�d�}|dkrA|�
�}d}n|d|��
�}||dd���}|jr[|j|n|j}||kri|�	d�dSt|d	|d�}|s||�	d
|�dS||�dS|j|jkr�|�	d�d|_dS|jr�|j|jkr�|�	d�d|_dSg}|�|j�D]}	|	r�|	d|jkr�|�|	dd��q�|�|	�q�|j�|�|_|j|j|j|jf}
i}|j
s�|j|jd
�}|j j!|
i|��}|�"�|s�|�	d�dS|�	|�dS)NzData:rrz500 Error: bad syntaxr�� 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)#rC�joinrcr rSrTrZrYr^rUrBr��find�upper�striprKr,r/�getattrr�r@�splitrDrEr�rGrbrOr[r\r�r�r=�process_messager`)
r�lineZsz�i�command�argZmax_sz�methodr��text�args�kwargsZstatusrrr�found_terminatorXsl


��


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

zSMTPChannel.smtp_HELOcCs�|s	|�d�dS|jr|�d�dS|��||_d|_|�d|j�|jr9|�d|j�|jdd7<|jsA|�d�|jrR|�d	�|jdd
7<|�d�dS)Nz501 Syntax: EHLO hostnamer�Tz250-%sz250-SIZE %s�MAIL�z250-8BITMIMEz250-SMTPUTF8�
z250 HELP)	rUrJrIrKrNr@r,rBrAr�rrr�	smtp_EHLO�s&



zSMTPChannel.smtp_EHLOcCs |r	|�d�dS|�d�dS)Nz501 Syntax: NOOPr��rUr�rrr�	smtp_NOOP�szSMTPChannel.smtp_NOOPcCs|�d�|��dS)Nz221 Bye)rUZclose_when_doner�rrr�	smtp_QUIT�s
zSMTPChannel.smtp_QUITcCs0t|�}|d|���|kr||d���SdSra)r�r�r�)r�keywordr�Zkeylenrrr�_strip_command_keyword�sz"SMTPChannel._strip_command_keywordcCsF|sdS|���d�rt|�\}}nt|�\}}|s||fS|j|fS)N)rr�<)�lstrip�
startswithrrZ	addr_spec)rr��address�restrrr�_getaddr�s
zSMTPChannel._getaddrcCsHi}|D]}|�d�\}}}|��r|r|sdS|r|nd||<q|S)N�=T)�	partition�isalnum)r�params�resultZparam�eqrkrrr�
_getparams�szSMTPChannel._getparamscCs|r�d}|��}|dkr|�d�dS|dkr|�d�dS|dkr2d}|jr+||7}|�|�dS|dkrFd	}|jr?||7}|�|�dS|d
krQ|�d�dS|dkr\|�d
�dS|dkrg|�d�dS|dkrr|�d�dS|dkr}|�d�dS|�d�dS|�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�rUrK)rr�ZextendedZlc_argrrrr�	smtp_HELP�s:zSMTPChannel.smtp_HELPcCsD|r|�|�\}}|r|�d�dS|�d|�dS|�d�dS)NzB252 Cannot VRFY user, but will accept message and attempt deliveryz502 Could not VRFY %sz501 Syntax: VRFY <address>)r�rU)rr�r�r�rrr�	smtp_VRFYszSMTPChannel.smtp_VRFYcCs�|js
|�d�dStd|td�d}|jr|d7}|dur%|�|�dS|�d|�}|�|�\}}|s;|�|�dS|jsG|rG|�|�dS|jrQ|�d�dS|���	�|_
|�|j
�}|duri|�|�dS|js}|�
dd	�}|d
vr}|�d�dS|jr�|�
dd
�}|dur�d|_n|d
ur�|�d�dS|�
dd�}|r�|��s�|�|�dS|jr�t|�|jkr�|�d�dSt|���dkr�|�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�)rJrUr rTrKr�r�r[r�r�r�r�rB�poprAr]�isdigitr@�intr��keys)rr��	syntaxerrr�r��body�smtputf8�sizerrr�	smtp_MAIL
sh











zSMTPChannel.smtp_MAILcCs|js
|�d�dStd|td�|js|�d�dSd}|jr$|d7}|dur/|�|�dS|�d|�}|�|�\}}|sE|�|�dS|jsQ|rQ|�|�dS|���	�|_
|�|j
�}|duri|�|�dSt|�
��dkrx|�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�)rJrUr rTr[rKr�r�r�r�r�r�r�r�r\r�)rr�r�r�r�rrr�	smtp_RCPTCs@







zSMTPChannel.smtp_RCPTcCs(|r	|�d�dS|��|�d�dS)Nz501 Syntax: RSETr�)rUrIr�rrr�	smtp_RSETfs

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>)rJrUr\r�rZr_r�rrr�	smtp_DATAms



zSMTPChannel.smtp_DATAcCs|�d�dS)Nz502 EXPN not implementedr�r�rrr�	smtp_EXPN|szSMTPChannel.smtp_EXPN),rrrrYr�r/�collections�defaultdictr,�propertyr0�DATA_SIZE_DEFAULTr<r`rIZ_SMTPChannel__server�setterZ_SMTPChannel__lineZ_SMTPChannel__stateZ_SMTPChannel__greetingZ_SMTPChannel__mailfromZ_SMTPChannel__rcpttosZ_SMTPChannel__dataZ_SMTPChannel__fqdnZ_SMTPChannel__peerZ_SMTPChannel__connZ_SMTPChannel__addrrUr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s�

�'	





















>#6#rc@s2eZdZeZedddfdd�Zdd�Zdd�ZdS)	rNFcCs�||_||_||_||_||_|r|rtd��tjj||d�z't	j
|dt	ji�}|�|dd|dd�|�
�|�|�|�d�Wn|���td|jjt�t���||ftd�dS)	Nr3r1�typerr(�z0%s started at %s
	Local addr: %s
	Remote addr:%sr)Z
_localaddr�_remoteaddrr@rArBr.�asyncore�
dispatcherr<rMZgetaddrinfoZSOCK_STREAMZ
create_socketZset_reuse_addrZbindZlistenrQr �	__class__r�time�ctimerT)rZ	localaddrZ
remoteaddrr@r2rArWZgai_resultsrrrr<�s2�
�
�zSMTPServer.__init__c	Cs6tdt|�td�|�||||j|j|j|j�}dS)NzIncoming connection from %sr)r rSrT�
channel_classr@�_maprArB)rr>r?Zchannelrrr�handle_accepted�s�zSMTPServer.handle_acceptedcKs	t�r)�NotImplementedError�rrOr[r\r�r�rrrr��szSMTPServer.process_message)	rrrrr�r�r<r�r�rrrrr�s
�rc@r)rcCsld}|��}|D]+}|r&|s&d|d}t|t�s t|�d��}t|�d}t|t�s/t|�}t|�qdS)Nr(zX-Peer: rr�)�
splitlines�
isinstancer�rS�encoder )rrOr�Z	inheaders�linesr�Z
peerheaderrrr�_print_message_content�s


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

zDebuggingServer.process_messageN)rrrr�r�rrrrr�srcs,eZdZ�fdd�Zdd�Zdd�Z�ZS)rcs2d|vr|drtd��tt|�j|i|��dS)NrAz$PureProxy does not support SMTPUTF8.)r.�superrr<�rr�r��r�rrr<�szPureProxy.__init__c	Csf|�d�}d}|D]
}|sn|d7}q	|�|d|d�t�|�}|�|||�}td|td�dS)Nrrr(z
X-Peer: %szwe got some refusals:r)r��insertrFr��_deliverr rT)	rrOr[r\r�r�r�r��refusedrrrr��s


zPureProxy.process_messagec
Cs�ddl}i}z%|��}|�|jd|jd�z|�|||�}W|��W|S|��w|jyH}ztdtd�|j	}WYd}~|Sd}~wt
|jfy|}z&td|jtd�t
|dd�}t
|dd	�}	|D]}
||	f||
<qhWYd}~|Sd}~ww)
Nrr(zgot SMTPRecipientsRefusedrZgotZ	smtp_code���Z
smtp_error�ignore)�smtplibZSMTPZconnectr�Zsendmail�quitZSMTPRecipientsRefusedr rTZ
recipientsrPZ
SMTPExceptionr�r�)rr[r\r�r�r��s�eZerrcode�errmsg�rrrrr��s2

�
��
���zPureProxy._deliver)rrrr<r�r��
__classcell__rrr�rr�srcs$eZdZ�fdd�Zdd�Z�ZS)r	cs>tdtd�d|vr|drtd��tt|�j|i|��dS)Nz8MailmanProxy is deprecated and will be removed in futurer
rAz'MailmanProxy does not support SMTPUTF8.)rrfr.r�rr<r�r�rrr<s�zMailmanProxy.__init__cCsddlm}ddlm}ddlm}ddlm}g}	|D]:}
|
���d�d}|�d�}t|�dkr3q|d}
t|�dkrB|d	}nd
}|�	|
�rM|dvrNq|	�
|
|
|f�q|	D]
\}
}
}|�|
�qYtdd
�
|�td�|r~|�|||�}td|td�i}||�}|�|�}|�d�s�||d<|�d�s�t�t���|d<|	D]g\}
}
}td|
td�|�|
�}|s�|j|
dd�}|||
<|d
kr�|j|d	d�q�|dkr�|j|d	d�q�|dkr�|j|d	d�q�|dkr�|j|d	d�q�|dv�r	|dkr�d|d <nd!|d <|j|d	d�q�dS)"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��remover r�rTr�r�r�r�ZEnqueue)rrOr[r\r�r�r�r�r�Z	listnamesZrcptZlocal�partsZlistnamer�r�Zmlistsr�rZmlistrrrr� sf







��zMailmanProxy.process_message)rrrr<r�r�rrr�rr	sr	c@seZdZdZdZdZdZdS)�OptionsTrNF)rrr�setuid�	classname�
size_limitrArrrrrms
rc

CsXzt�tjdd�dgd��\}}Wntjy*}ztd|�WYd}~nd}~wwt�}|D]\\}}|dvr=td�q0|dvrKtt�t�d�q0|dvrSd|_	q0|d	vr[||_
q0|d
vrctjaq0|dvrkd|_
q0|d
vr�z	t|�}||_Wq0td|tjd�t�d�Yq0q0t|�dkr�d}d}n&t|�dkr�|d}d}nt|�dkr�|d}|d}n
tddt�|��|�d�}	|	dkr�tdd|�|d|	�|_z
t||	dd��|_Wnty�tdd|�Ynw|�d�}	|	dk�rtdd|�|d|	�|_zt||	dd��|_W|St�y+tdd|�Y|Sw)Nr(z	nVhc:s:du)zclass=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'rr rVr%rrr$rTrAr�rr��
COMMASPACEr�r��	localhost�	localportr.�
remotehost�
remoteport)
Zoptsr�r��options�optr�Zint_sizeZ	localspecZ
remotespecr�rrr�	parseargsts|���

�	

�

��r�__main__r5r()rAz7Cannot import module "pwd"; try running with -n option.r�nobodyz3Cannot setuid "nobody"; try running with -n option.)r)@r#�osrRrr�rMr��warningsrZemail._header_value_parserrr�__all__rfr�r:r
ZprogramrVr
rTrFrr�r'r;rr�rrrr	rrrrr�rfindZlastdot�
__import__r"�locals�modrr�Zclass_rrrrrrA�proxyr�pwd�ImportErrorr r$r%�getpwnamr�PermissionErrorZloop�KeyboardInterruptrrrr�<module>s�N�


M-U
B


�����

?>