AlkantarClanX12

Your IP : 18.117.154.134


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/smtpd.cpython-34.pyc

�
e f'u�@s'dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZddddgZejdZd	ZGd
d�d�Ze�adZd
ZdZdZd
dd�ZGdd�dej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�d�Z!dd�Z"e#dkr#e"�Z$e$j%Z%de%kre%j&d�Z'e(e%de'�e)�e*�d
g�Z+e%e'dd�Z%nddl,Z+e-e+e%�Z.e.e$j/e$j0fe$j1e$j2fe$j3�Z4e$j5r�yddl6Z6Wn2e7k
r�e8dd ej9�ej:d�YnXe6j;d!�d"Z<yej5e<�Wn2e=k
r�e8d#d ej9�ej:d�YnXnyej>�Wne?k
rYnXndS)$aAn RFC 5321 smtp proxy.

Usage: %(program)s [options] [localhost:localport [remotehost:remoteport]]

Options:

    --nosetuid
    -n
        This program generally tries to setuid `nobody', unless this flag is
        set.  The setuid call will fail if this program is not run as root (in
        which case, use this flag).

    --version
    -V
        Print the version number and exit.

    --class classname
    -c classname
        Use `classname' as the concrete SMTP proxy class.  Uses `PureProxy' by
        default.

    --size limit
    -s limit
        Restrict the total size of the incoming message to "limit" number of
        bytes via the RFC 1870 SIZE extension.  Defaults to 33554432 bytes.

    --debug
    -d
        Turn on debugging prints.

    --help
    -h
        Print this message and exit.

Version: %(__version__)s

If localhost is not given then `localhost' is used, and if localport is not
given then 8025 is used.  If remotehost is not given then `localhost' is used,
and if remoteport is not given, then 25 is used.
�N)�warn)�
get_addr_spec�get_angle_addr�
SMTPServer�DebuggingServer�	PureProxy�MailmanProxyzPython SMTP proxy version 0.3c@s(eZdZdd�Zdd�ZdS)�DevnullcCsdS)N�)�self�msgr
r
�*/opt/alt/python34/lib64/python3.4/smtpd.py�write_sz
Devnull.writecCsdS)Nr
)rr
r
r
�flush`sz
Devnull.flushN)�__name__�
__module__�__qualname__rrr
r
r
r
r	^sr	�
�z, icCsGttt�dtj�|r6t|dtj�ntj|�dS)N�file)�print�__doc__�globals�sys�stderr�exit)�coderr
r
r
�usagejsrc@s�eZdZdZdZdZejedd��Zej	iedd6�e
ej��Ze
dd	d
�Zedd��Zejd
d��Zedd��Zejdd��Zedd��Zejdd��Zedd��Zejdd��Zedd��Zejdd��Zedd��Zejdd��Zedd��Zejdd��Zed d!��Zejd"d!��Zed#d$��Zejd%d$��Zed&d'��Zejd(d'��Zed)d*��Zejd+d*��Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Z d6d7�Z!d8d9�Z"d:d;�Z#d<d=�Z$d>d?�Z%d@dA�Z&dBdC�Z'dDdE�Z(dFdG�Z)dHdI�Z*dJdK�Z+dLdM�Z,dS)N�SMTPChannelr�icCs|S)Nr
)�xr
r
r
�<lambda>vszSMTPChannel.<lambda>��MAILNcCsCtjj||d|�||_||_||_||_g|_|j|_	d|_
d|_g|_d|_
tj�|_d|_y|j�|_WnOtk
r�}z/|j�|jdtjkr��ndSWYdd}~XnXtdt|j�dt�|jd|jtf�|jd�d|_dS)	N�maprrzPeer:rz	220 %s %ss
F) �asynchat�
async_chat�__init__�smtp_server�conn�addr�data_size_limit�received_lines�COMMAND�
smtp_state�
seen_greeting�mailfrom�rcpttos�
received_data�socketZgetfqdn�fqdn�	num_bytesZgetpeername�peer�OSError�close�args�errnoZENOTCONNr�repr�DEBUGSTREAM�push�__version__�set_terminator�
extended_smtp)rZserverr)r*r+r$�errr
r
r
r'|s0										

zSMTPChannel.__init__cCstdtd�|jS)NzTAccess to __server attribute on SMTPChannel is deprecated, use 'smtp_server' instead�)r�DeprecationWarningr()rr
r
r
�__server�s
zSMTPChannel.__servercCstdtd�||_dS)NzRSetting __server attribute on SMTPChannel is deprecated, set 'smtp_server' insteadrB)rrCr()r�valuer
r
r
rD�s
cCstdtd�|jS)NzUAccess to __line attribute on SMTPChannel is deprecated, use 'received_lines' insteadrB)rrCr,)rr
r
r
�__line�s
zSMTPChannel.__linecCstdtd�||_dS)NzSSetting __line attribute on SMTPChannel is deprecated, set 'received_lines' insteadrB)rrCr,)rrEr
r
r
rF�s
cCstdtd�|jS)NzRAccess to __state attribute on SMTPChannel is deprecated, use 'smtp_state' insteadrB)rrCr.)rr
r
r
�__state�s
zSMTPChannel.__statecCstdtd�||_dS)NzPSetting __state attribute on SMTPChannel is deprecated, set 'smtp_state' insteadrB)rrCr.)rrEr
r
r
rG�s
cCstdtd�|jS)NzXAccess to __greeting attribute on SMTPChannel is deprecated, use 'seen_greeting' insteadrB)rrCr/)rr
r
r
�
__greeting�s
zSMTPChannel.__greetingcCstdtd�||_dS)NzVSetting __greeting attribute on SMTPChannel is deprecated, set 'seen_greeting' insteadrB)rrCr/)rrEr
r
r
rH�s
cCstdtd�|jS)NzSAccess to __mailfrom attribute on SMTPChannel is deprecated, use 'mailfrom' insteadrB)rrCr0)rr
r
r
�
__mailfrom�s
zSMTPChannel.__mailfromcCstdtd�||_dS)NzQSetting __mailfrom attribute on SMTPChannel is deprecated, set 'mailfrom' insteadrB)rrCr0)rrEr
r
r
rI�s
cCstdtd�|jS)NzQAccess to __rcpttos attribute on SMTPChannel is deprecated, use 'rcpttos' insteadrB)rrCr1)rr
r
r
�	__rcpttos�s
zSMTPChannel.__rcpttoscCstdtd�||_dS)NzOSetting __rcpttos attribute on SMTPChannel is deprecated, set 'rcpttos' insteadrB)rrCr1)rrEr
r
r
rJ�s
cCstdtd�|jS)NzTAccess to __data attribute on SMTPChannel is deprecated, use 'received_data' insteadrB)rrCr2)rr
r
r
�__data�s
zSMTPChannel.__datacCstdtd�||_dS)NzRSetting __data attribute on SMTPChannel is deprecated, set 'received_data' insteadrB)rrCr2)rrEr
r
r
rK�s
cCstdtd�|jS)NzKAccess to __fqdn attribute on SMTPChannel is deprecated, use 'fqdn' insteadrB)rrCr4)rr
r
r
�__fqdn�s
zSMTPChannel.__fqdncCstdtd�||_dS)NzISetting __fqdn attribute on SMTPChannel is deprecated, set 'fqdn' insteadrB)rrCr4)rrEr
r
r
rL�s
cCstdtd�|jS)NzKAccess to __peer attribute on SMTPChannel is deprecated, use 'peer' insteadrB)rrCr6)rr
r
r
�__peer�s
zSMTPChannel.__peercCstdtd�||_dS)NzISetting __peer attribute on SMTPChannel is deprecated, set 'peer' insteadrB)rrCr6)rrEr
r
r
rM�s
cCstdtd�|jS)NzKAccess to __conn attribute on SMTPChannel is deprecated, use 'conn' insteadrB)rrCr))rr
r
r
�__conn�s
zSMTPChannel.__conncCstdtd�||_dS)NzISetting __conn attribute on SMTPChannel is deprecated, set 'conn' insteadrB)rrCr))rrEr
r
r
rNs
cCstdtd�|jS)NzKAccess to __addr attribute on SMTPChannel is deprecated, use 'addr' insteadrB)rrCr*)rr
r
r
�__addrs
zSMTPChannel.__addrcCstdtd�||_dS)NzISetting __addr attribute on SMTPChannel is deprecated, set 'addr' insteadrB)rrCr*)rrEr
r
r
rO
s
cCs$tjj|t|dd��dS)Nz
�ascii)r%r&r=�bytes)rrr
r
r
r=szSMTPChannel.pushcCs�d}|j|jkr$|j}n|j|jkrB|j}n|r[|j|kr[dS|ry|jt|�7_n|jjt	|d��dS)Nzutf-8)
r.r-�max_command_size_limit�DATAr+r5�lenr,�append�str)r�data�limitr
r
r
�collect_incoming_datasz!SMTPChannel.collect_incoming_datacCs�tj|j�}tdt|�dt�g|_|j|jkrQ|jd}|_|sp|j	d�dSd}|j
d�}|dkr�|j�}d}n0|d|�j�}||dd�j�}|j
r�|j|n|j}||kr|j	d�dSt|d|d�}|sC|j	d	|�dS||�dS|j|jkr}|j	d
�d|_dS|jr�|j|jkr�|j	d�d|_dSg}xT|jd�D]C}	|	r�|	dd
kr�|j|	dd��q�|j|	�q�Wtj|�|_|jj|j|j|j|j�}
g|_d|_|j|_d|_|jd�|
s�|j	d�n
|j	|
�dS)NzData:rrz500 Error: bad syntax� rz500 Error: line too longZsmtp_z&500 Error: command "%s" not recognizedz451 Internal confusionz552 Error: Too much mail dataz
�.s
z250 OK)�EMPTYSTRING�joinr,rr;r<r.r-r5r=�find�upper�stripr@�command_size_limits�command_size_limit�getattrrSr+�splitrU�NEWLINEr2r(�process_messager6r0r1r?)r�lineZsz�method�i�command�argZmax_szrW�textZstatusr
r
r
�found_terminator%sf	
	


	
				
zSMTPChannel.found_terminatorcCsZ|s|jd�dS|jr0|jd�n&||_d|_|jd|j�dS)Nz501 Syntax: HELO hostnamez503 Duplicate HELO/EHLOFz250 %s)r=r/r@r4)rrkr
r
r
�	smtp_HELObs
			zSMTPChannel.smtp_HELOcCs�|s|jd�dS|jr0|jd�nS||_d|_|jd|j�|jrv|jd|j�n|jd�dS)Nz501 Syntax: EHLO hostnamez503 Duplicate HELO/EHLOTz250-%sz250-SIZE %sz250 HELP)r=r/r@r4r+)rrkr
r
r
�	smtp_EHLOms
				zSMTPChannel.smtp_EHLOcCs'|r|jd�n
|jd�dS)Nz501 Syntax: NOOPz250 OK)r=)rrkr
r
r
�	smtp_NOOP{szSMTPChannel.smtp_NOOPcCs|jd�|j�dS)Nz221 Bye)r=Zclose_when_done)rrkr
r
r
�	smtp_QUIT�s
zSMTPChannel.smtp_QUITcCs@t|�}|d|�j�|kr<||d�j�SdS)Nr)rTr_r`)r�keywordrkZkeylenr
r
r
�_strip_command_keyword�sz"SMTPChannel._strip_command_keywordcCsc|s
dS|j�jd�r4t|�\}}nt|�\}}|sV||fS|j|fS)Nr�<)rr)�lstrip�
startswithrrZ	addr_spec)rrk�address�restr
r
r
�_getaddr�s
zSMTPChannel._getaddrcCs*dd�|j�D�}dd�|D�S)NcSs.g|]$}d|kr|jdd��qS)�=r)rd)�.0Zparamr
r
r
�
<listcomp>�s	z*SMTPChannel._getparams.<locals>.<listcomp>cSs+i|]!\}}|j�r||�qSr
)�isalnum)r{�k�vr
r
r
�
<dictcomp>�s	z*SMTPChannel._getparams.<locals>.<dictcomp>)rd)r�paramsr
r
r
�
_getparams�szSMTPChannel._getparamscCsm|r\d}|j�}|dkr4|jd�qi|dkrP|jd�qi|dkr�d}|jrx||7}n|j|�qi|dkr�d	}|jr�||7}n|j|�qi|d
kr�|jd�qi|dkr�|jd
�qi|dkr|jd�qi|dkr0|jd�qi|dkrL|jd�qi|jd�n
|jd�dS)Nz [SP <mail-parameters>]ZEHLOz250 Syntax: EHLO hostnameZHELOz250 Syntax: HELO hostnamer#z 250 Syntax: MAIL FROM: <address>ZRCPTz250 Syntax: RCPT TO: <address>rSz250 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_r=r@)rrkZextendedZlc_argrr
r
r
�	smtp_HELP�s:	
	
zSMTPChannel.smtp_HELPcCsV|rE|j|�\}}|r1|jd�qR|jd|�n
|jd�dS)NzB252 Cannot VRFY user, but will accept message and attempt deliveryz502 Could not VRFY %sz501 Syntax: VRFY <address>)ryr=)rrkrwr�r
r
r
�	smtp_VRFY�szSMTPChannel.smtp_VRFYcCs�|js|jd�dStd|dt�d}|jrI|d7}n|dkrf|j|�dS|jd|�}|j|�\}}|s�|j|�dS|jr�|r�|j|�dS|jr�|jd�dS|j|j	��}|dkr|j|�dS|j
dd�}|rx|j�sF|j|�dS|jrxt
|�|jkrx|jd	�dSnt|j��d
kr�|jd�dS||_td|jdt�|jd
�dS)Nz503 Error: send HELO firstz	===> MAILrz 501 Syntax: MAIL FROM: <address>z [SP <mail-parameters>]zFROM:z503 Error: nested MAIL commandZSIZEz:552 Error: message size exceeds fixed maximum message sizerz:555 MAIL FROM parameters not recognized or not implementedzsender:z250 OK)r/r=rr<r@rsryr0r�r_�pop�isdigitr+�intrT�keys)rrk�	syntaxerrrwr��sizer
r
r
�	smtp_MAIL�sN	
	



	




	zSMTPChannel.smtp_MAILcCs||js|jd�dStd|dt�|jsG|jd�dSd}|jrc|d7}n|dkr�|j|�dS|jd|�}|j|�\}}|s�|j|�dS|r|jr|j|j	��}|dkr|j|�dSq|j|�dSn|rEt
|j��dkrE|jd	�dS|jj
|�td
|jdt�|jd�dS)Nz503 Error: send HELO firstz	===> RCPTrz503 Error: need MAIL commandz501 Syntax: RCPT TO: <address>z [SP <mail-parameters>]zTO:rz8555 RCPT TO parameters not recognized or not implementedzrecips:z250 OK)r/r=rr<r0r@rsryr�r_rTr�r1rU)rrkr�rwr�r
r
r
�	smtp_RCPT�s@	
	
	


	


zSMTPChannel.smtp_RCPTcCsO|r|jd�dSd|_g|_d|_|j|_|jd�dS)Nz501 Syntax: RSETrz250 OK)r=r0r1r2r-r.)rrkr
r
r
�	smtp_RSETs
			zSMTPChannel.smtp_RSETcCsu|js|jd�dS|js4|jd�dS|rK|jd�dS|j|_|jd�|jd�dS)Nz503 Error: send HELO firstz503 Error: need RCPT commandz501 Syntax: DATAs
.
z#354 End data with <CR><LF>.<CR><LF>)r/r=r1rSr.r?)rrkr
r
r
�	smtp_DATA#s	
	


zSMTPChannel.smtp_DATAcCs|jd�dS)Nz502 EXPN not implemented)r=)rrkr
r
r
�	smtp_EXPN2szSMTPChannel.smtp_EXPN)-rrrr-rSrb�collections�defaultdictra�update�max�valuesrR�DATA_SIZE_DEFAULTr'�propertyZ_SMTPChannel__server�setterZ_SMTPChannel__lineZ_SMTPChannel__stateZ_SMTPChannel__greetingZ_SMTPChannel__mailfromZ_SMTPChannel__rcpttosZ_SMTPChannel__dataZ_SMTPChannel__fqdnZ_SMTPChannel__peerZ_SMTPChannel__connZ_SMTPChannel__addrr=rYrmrnrorprqrsryr�r�r�r�r�r�r�r�r
r
r
r
rqs`	
=#)#rc@s@eZdZeZeddd�Zdd�Zdd�ZdS)rNcCs�||_||_||_tjj|d|�y>|jtjtj	�|j
�|j|�|jd�Wn|j
��Yn6Xtd|jjtjtj��||fdt�dS)Nr$�z0%s started at %s
	Local addr: %s
	Remote addr:%sr)Z
_localaddr�_remoteaddrr+�asyncore�
dispatcherr'Z
create_socketr3ZAF_INETZSOCK_STREAMZset_reuse_addrZbindZlistenr8r�	__class__r�time�ctimer<)rZ	localaddrZ
remoteaddrr+r$r
r
r
r':s			


zSMTPServer.__init__cCs?tdt|�dt�|j||||j|j�}dS)NzIncoming connection from %sr)rr;r<�
channel_classr+Z_map)rr)r*Zchannelr
r
r
�handle_acceptedNszSMTPServer.handle_acceptedcCs
t�dS)aIOverride this abstract method to handle messages from the client.

        peer is a tuple containing (ipaddr, port) of the client that made the
        socket connection to our smtp port.

        mailfrom is the raw address the client claims the message is coming
        from.

        rcpttos is a list of raw addresses the client wishes to deliver the
        message to.

        data is a string containing the entire full text of the message,
        headers (if supplied) and all.  It has been `de-transparencied'
        according to RFC 821, Section 4.5.2.  In other words, a line
        containing a `.' followed by other text has had the leading dot
        removed.

        This function should return None, for a normal `250 Ok' response;
        otherwise it returns the desired response string in RFC 821 format.

        N)�NotImplementedError)rr6r0r1rWr
r
r
rfTszSMTPServer.process_message)	rrrrr�r�r'r�rfr
r
r
r
r6sc@seZdZdd�ZdS)rcCsod}|jd�}td�x?|D]7}|rS|rStd|d�d}nt|�q&Wtd�dS)Nrrz%---------- MESSAGE FOLLOWS ----------zX-Peer:rz%------------ END MESSAGE ------------)rdr)rr6r0r1rWZ	inheaders�linesrgr
r
r
rfos


	zDebuggingServer.process_messageN)rrrrfr
r
r
r
rmsc@s(eZdZdd�Zdd�ZdS)rc	Cs�|jd�}d}x"|D]}|s,Pn|d7}qW|j|d|d�tj|�}|j|||�}td|dt�dS)Nrrrz
X-Peer: %szwe got some refusals:r)rd�insertrer]�_deliverrr<)	rr6r0r1rWr�rirg�refusedr
r
r
rf}s
zPureProxy.process_messagecCs7ddl}i}yU|j�}|j|jd|jd�z|j|||�}Wd|j�XWn�|jk
r�}ztddt�|j	}WYdd}~Xn�t
|jfk
r2}z`td|jdt�t
|dd	�}t
|dd�}	x|D]}
||	f||
<qWWYdd}~XnX|S)
Nrrzgot SMTPRecipientsRefusedrZgotZ	smtp_codeZ
smtp_error�ignore���)�smtplibZSMTPZconnectr�Zsendmail�quitZSMTPRecipientsRefusedrr<Z
recipientsr7Z
SMTPExceptionr�rc)rr0r1rWr�r��s�eZerrcode�errmsg�rr
r
r
r��s$
'zPureProxy._deliverN)rrrrfr�r
r
r
r
r|sc@seZdZdd�ZdS)rcCsddlm}ddlm}ddlm}ddlm}g}	x�|D]�}
|
j�jd�d}|jd�}t|�dkr�qMn|d}
t|�dkr�|d	}nd
}|j	|
�sM|d!kr�qMn|	j
|
|
|f�qMWx$|	D]\}
}
}|j|
�qWtddj
|�dt�|rr|j|||�}td|dt�ni}||�}|j|�}|jd�s�||d<n|jd�s�tjtj��|d<nx.|	D]&\}
}
}td|
dt�|j|
�}|s:|j|
dd�}|||
<n|d
kr\|j|dd	�q�|dkr~|j|dd	�q�|dkr�|j|dd	�q�|d
kr�|j|dd	�q�|d"kr�|dkr�d|d<n
d |d<|j|dd	�q�q�WdS)#Nr)�StringIO)�Utils)�Message)�MailList�@�-rBrr�admin�owner�requestr]�leavezforwarding recips:rZrzwe got refusals:�fromZFromZdateZDatezsending message to�lock�tolistZtoadminZtoownerZ	torequestZ	subscribeZSubjectZunsubscribe)rr�zownerr��joinr�)r�r�)�ior�ZMailmanr�r�r��lowerrdrTZlist_existsrU�removerr]r<r��getr�r�ZEnqueue)rr6r0r1rWr�r�r�r�Z	listnamesZrcptZlocal�partsZlistnamerjr�Zmlistsr�rZmlistr
r
r
rf�sd


	



zMailmanProxy.process_messageN)rrrrfr
r
r
r
r�sc@s"eZdZdZdZdZdS)�OptionsrrN)rrr�setuid�	classname�
size_limitr
r
r
r
r��sr�c
!Csy>tjtjdd�dddddddg�\}}Wn5tjk
ru}ztd|�WYdd}~XnXt�}x�|D]�\}}|d"kr�td�q�|d#kr�tt�tjd�q�|d$kr�d|_	q�|d%kr||_
q�|d&krtjaq�|d'kr�yt
|�}||_Wqptd|dtj�tjd�YqpXq�q�Wt|�dkr�d}d}nht|�dkr�|d}d}nCt|�dkr�|d}|d}ntddtj|��|jd�}	|	dkr,tdd|�n|d|	�|_y!t
||	dd��|_Wn#tk
r�tdd|�YnX|jd�}	|	dkr�tdd |�n|d|	�|_y!t
||	dd��|_Wn#tk
rtdd!|�YnX|S)(NrznVhc:s:dzclass=Znosetuid�version�helpzsize=�debug�-h�--helpr�-V�	--version�-n�
--nosetuid�-c�--class�-d�--debug�-s�--sizezInvalid size: rzlocalhost:8025zlocalhost:25rB�zInvalid arguments: %s�:zBad local spec: %szBad local port: %szBad remote spec: %szBad remote port: %s)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)�getoptr�argv�errorrr�rr>rr�r�rr<r�r�rT�
COMMASPACEr]r^�	localhost�	localport�
ValueError�
remotehost�
remoteport)
Zoptsr9r��optionsZoptrkZint_sizeZ	localspecZ
remotespecrir
r
r
�	parseargs�sj% 	


	
	

!
!
r��__main__r[rz7Cannot import module "pwd"; try running with -n option.r�nobodyrBz3Cannot setuid "nobody"; try running with -n option.)@rr�osr:r�r�r3r�r%r��warningsrZemail._header_value_parserrr�__all__r�Zprogramr>r	r<rer\r�r�rr&rr�rrrrr�r�rr�r��rfindZlastdot�
__import__r�locals�modr�rcZclass_r�r�r�r�r��proxyr��pwd�ImportErrorrrr�getpwnamr��PermissionErrorZloop�KeyboardInterruptr
r
r
r
�<module>)sr#
	��7(N?		(