Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_smtpd.cpython-35.opt-2.pyc



���]�@s�ddlZddlZddlmZmZddlZddlZddlZddlZGdd�dej	�Z
Gdd�de�ZGdd�de
�Z
Gd	d
�d
ej�ZGdd�dej�ZGd
d�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zejejd�Gdd�de��ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zed kr�ej�dS)!�N)�support�mock_socketc@s(eZdZdd�Zdd�ZdS)�DummyServercOsAtjj|||�g|_|jr4d|_n	d|_dS)Nz
return statuss
return status)�smtpd�
SMTPServer�__init__�messagesZ_decode_data�
return_status)�self�args�kwargs�r
�//opt/alt/python35/lib64/python3.5/test_smtpd.pyrs
		zDummyServer.__init__cKsS|jj||||f�||jkr/dSd|krOd|dkrOdSdS)Nz	250 OkishZmail_optionsZSMTPUTF8z250 SMTPUTF8 message okish)r�appendr	)r
Zpeer�mailfromZrcpttos�data�kwr
r
r�process_messages
zDummyServer.process_messageN)�__name__�
__module__�__qualname__rrr
r
r
rr
src@seZdZdS)�DummyDispatcherBrokenN)rrrr
r
r
rrsrc@seZdZdd�ZdS)�BrokenDummyServercCs
t��dS)N)r)r
�numr
r
r�listen szBrokenDummyServer.listenN)rrrrr
r
r
rrsrc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SMTPDServerTestcCstt_t_dS)N)rr�socket�asyncore)r
r
r
r�setUp%szSMTPDServerTest.setUpcs�tjtjdfddd�}|j�\}}tj|||dd���fdd�}|d�|d�|d	�|d
�|jt|d�dS)
Nr�b�decode_dataTcs�jj|��j�dS)N)r�
queue_recv�handle_read)�line)�channelr
r�
write_line.szFSMTPDServerTest.test_process_message_unimplemented.<locals>.write_linesHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesDATAs	spam
.
)rr)rrr�HOST�accept�SMTPChannel�assertRaises�NotImplementedError)r
�server�conn�addrr%r
)r$r�"test_process_message_unimplemented(s	



z2SMTPDServerTest.test_process_message_unimplementedcCs4|jt��tjtjdfd�WdQRXdS)Nrr)rr)�assertWarns�DeprecationWarningrrrr&)r
r
r
r�test_decode_data_default_warns8sz.SMTPDServerTest.test_decode_data_default_warnsc	Cs2|jttjtjdfddddd�dS)Nrr�enable_SMTPUTF8Tr )rr)r)�
ValueErrorrrrr&)r
r
r
r�+test_decode_data_and_enable_SMTPUTF8_raises<sz;SMTPDServerTest.test_decode_data_and_enable_SMTPUTF8_raisescCstj�tt_t_dS)N)r�	close_allrr)r
r
r
r�tearDownEs
zSMTPDServerTest.tearDownN)rrrrr.r1r4r6r
r
r
rr$s
	rc@sgeZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�DebuggingServerTestcCstt_t_dS)N)rrrr)r
r
r
rrLszDebuggingServerTest.setUpFcse�fdd�}|d�|r/|d�n
|d�|d�|d�||�|d�dS)	Ncs�jj|��j�dS)N)rr!r")r#)r$r
rr%Psz1DebuggingServerTest.send_data.<locals>.write_linesEHLO examples-MAIL From:eggs@example BODY=8BITMIME SMTPUTF8sMAIL From:eggs@examplesRCPT To:spam@examplesDATA�.r
)r
r$rr2r%r
)r$r�	send_dataOs





zDebuggingServerTest.send_datacCs�tjtjdfddd�}|j�\}}tj|||dd�}tj��}|j|d�WdQRX|j�}|j	|t
jd��dS)Nrrr TsFrom: test

hello
z�             ---------- MESSAGE FOLLOWS ----------
             From: test
             X-Peer: peer-address

             hello
             ------------ END MESSAGE ------------
             )rr)r�DebuggingServerrr&r'r(�captured_stdoutr9�getvalue�assertEqual�textwrap�dedent)r
r+r,r-r$�s�stdoutr
r
r�*test_process_message_with_decode_data_true]s	z>DebuggingServerTest.test_process_message_with_decode_data_truecCs�tjtjdfddd�}|j�\}}tj|||dd�}tj��}|j|d�WdQRX|j�}|j	|t
jd��dS)Nrrr FsFrom: test

héllo�
z�             ---------- MESSAGE FOLLOWS ----------
             b'From: test'
             b'X-Peer: peer-address'
             b''
             b'h\xc3\xa9llo\xff'
             ------------ END MESSAGE ------------
             )rr)rr:rr&r'r(r;r9r<r=r>r?)r
r+r,r-r$r@rAr
r
r�+test_process_message_with_decode_data_falsens	z?DebuggingServerTest.test_process_message_with_decode_data_falsecCs�tjtjdfddd�}|j�\}}tj|||dd�}tj��}|j|d�WdQRX|j�}|j	|t
jd��dS)Nrrr2TsFrom: test

héllo�
z�             ---------- MESSAGE FOLLOWS ----------
             b'From: test'
             b'X-Peer: peer-address'
             b''
             b'h\xc3\xa9llo\xff'
             ------------ END MESSAGE ------------
             )rr)rr:rr&r'r(r;r9r<r=r>r?)r
r+r,r-r$r@rAr
r
r�.test_process_message_with_enable_SMTPUTF8_trues	zBDebuggingServerTest.test_process_message_with_enable_SMTPUTF8_truecCs�tjtjdfddd�}|j�\}}tj|||dd�}tj��}|j|ddd�WdQRX|j�}|j	|t
jd��dS)Nrrr2TsFrom: test

héllo�
a             ---------- MESSAGE FOLLOWS ----------
             mail options: ['BODY=8BITMIME', 'SMTPUTF8']
             b'From: test'
             b'X-Peer: peer-address'
             b''
             b'h\xc3\xa9llo\xff'
             ------------ END MESSAGE ------------
             )rr)rr:rr&r'r(r;r9r<r=r>r?)r
r+r,r-r$r@rAr
r
r�7test_process_SMTPUTF8_message_with_enable_SMTPUTF8_true�s	zKDebuggingServerTest.test_process_SMTPUTF8_message_with_enable_SMTPUTF8_truecCstj�tt_t_dS)N)rr5rr)r
r
r
rr6�s
zDebuggingServerTest.tearDownN)
rrrrr9rBrCrDrEr6r
r
r
rr7Jsr7c@sUeZdZdd�Zdd�Zejejd�dd��Z	dd	�Z
d
S)�TestFamilyDetectioncCstt_t_dS)N)rrrr)r
r
r
rr�szTestFamilyDetection.setUpcCstj�tt_t_dS)N)rr5rr)r
r
r
rr6�s
zTestFamilyDetection.tearDownzIPv6 not enabledcCsGtjtjdftjdfdd�}|j|jjtj�dS)Nrr F)	rrr�HOSTv6r&r=r�family�AF_INET6)r
r+r
r
r�test_socket_uses_IPv6�s!	z)TestFamilyDetection.test_socket_uses_IPv6cCsGtjtjdftjdfdd�}|j|jjtj�dS)Nrr F)	rrrr&rGr=rrH�AF_INET)r
r+r
r
r�test_socket_uses_IPv4�s!	z)TestFamilyDetection.test_socket_uses_IPv4N)rrrrr6�unittest�
skipUnlessr�IPV6_ENABLEDrJrLr
r
r
rrF�s!rFc@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�TestRcptOptionParsings:555 RCPT TO parameters not recognized or not implemented
cCs6tt_t_tj|_tj�|_t_dS)N)	rrrr�DEBUGSTREAM�old_debugstream�io�StringIO�debug)r
r
r
rr�szTestRcptOptionParsing.setUpcCs*tj�tt_t_|jt_dS)N)rr5rrrRrQ)r
r
r
rr6�s
zTestRcptOptionParsing.tearDowncCs|jj|�|j�dS)N)rr!r")r
r$r#r
r
rr%�sz TestRcptOptionParsing.write_linecCs�ttjdfddd�}|j�\}}tj|||dd�}|j|d�|j|d�|j|d�|j|jj	|j
�dS)	Nrrr FsEHLO examples$MAIL from: <foo@example.com> size=20s"RCPT to: <foo@example.com> foo=bar)rr)rrr&r'rr(r%r=r�last�error_response)r
r+r,r-r$r
r
r�test_params_rejected�sz*TestRcptOptionParsing.test_params_rejectedcCs�ttjdfd	dd�}|j�\}}tj|||dd�}|j|d�|j|d�|j|d�|j|jj	d�dS)
Nrrr FsEHLO examples$MAIL from: <foo@example.com> size=20sRCPT to: <foo@example.com>s250 OK
)rr)
rrr&r'rr(r%r=rrV)r
r+r,r-r$r
r
r�test_nothing_accepted�sz+TestRcptOptionParsing.test_nothing_acceptedN)	rrrrWrr6r%rXrYr
r
r
rrP�s	rPc@s^eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�TestMailOptionParsings<555 MAIL FROM parameters not recognized or not implemented
cCs6tt_t_tj|_tj�|_t_dS)N)	rrrrrQrRrSrTrU)r
r
r
rr�szTestMailOptionParsing.setUpcCs*tj�tt_t_|jt_dS)N)rr5rrrRrQ)r
r
r
rr6�s
zTestMailOptionParsing.tearDowncCs|jj|�|j�dS)N)rr!r")r
r$r#r
r
rr%�sz TestMailOptionParsing.write_linecCs�ttjdfddd�}|j�\}}tj|||dd�}|j|d�xCdddd	gD]/}|j||�|j|jj	|j
�qnW|j|d
�|j|jj	d�dS)
Nrrr TsEHLO examples-MAIL from: <foo@example.com> size=20 SMTPUTF8s;MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=8BITMIMEs1MAIL from: <foo@example.com> size=20 BODY=UNKNOWNs2MAIL from: <foo@example.com> size=20 body=8bitmimes$MAIL from: <foo@example.com> size=20s250 OK
)rr)rrr&r'rr(r%r=rrVrW)r
r+r,r-r$r#r
r
r�test_with_decode_data_true�s
z0TestMailOptionParsing.test_with_decode_data_truecCs�ttjdfddd�}|j�\}}tj|||dd�}|j|d�x=ddgD]/}|j||�|j|jj	|j
�qhW|j|d�|j|jj	d	�|j|d
�|j|jj	d�dS)
Nrrr FsEHLO examples-MAIL from: <foo@example.com> size=20 SMTPUTF8s;MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=8BITMIMEs:MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=UNKNOWNs3501 Error: BODY can only be one of 7BIT, 8BITMIME
s2MAIL from: <foo@example.com> size=20 body=8bitmimes250 OK
)rr)rrr&r'rr(r%r=rrVrW)r
r+r,r-r$r#r
r
r�test_with_decode_data_falses$
	
z1TestMailOptionParsing.test_with_decode_data_falsecCs�ttjdfddd�}|j�\}}tj|||dd�}|j|d�|j|d�|j|jj	d�dS)	Nrrr2TsEHLO examples;MAIL from: <foo@example.com> size=20 body=8bitmime smtputf8s250 OK
)rr)
rrr&r'rr(r%r=rrV)r
r+r,r-r$r
r
r�test_with_enable_smtputf8_truesz4TestMailOptionParsing.test_with_enable_smtputf8_trueN)
rrrrWrr6r%r[r\r]r
r
r
rrZ�srZc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�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+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<dudv�Z=dwdx�Z>dydz�Z?d{d|�Z@d}d~�ZAdd��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�S)��SMTPDChannelTestcCs�tt_t_tj|_tj�|_t_t	t
jdfddd�|_|jj
�\}}tj|j||dd�|_dS)Nrrr T)rr)rrrrrQrRrSrTrUrrr&r+r'r(r$)r
r,r-r
r
rr$szSMTPDChannelTest.setUpcCs*tj�tt_t_|jt_dS)N)rr5rrrRrQ)r
r
r
rr6.s
zSMTPDChannelTest.tearDowncCs$|jjj|�|jj�dS)N)r$rr!r")r
r#r
r
rr%3szSMTPDChannelTest.write_linecCs)|jtttjdfddd�dS)Nrrr T)rr)r)rrrr&)r
r
r
r�test_broken_connect7sz$SMTPDChannelTest.test_broken_connectc
Cs;|jttj|j|jj|jjdddd�dS)Nr2Tr )r)r3rr(r+r$r,r-)r
r
r
rr4<s	z<SMTPDChannelTest.test_decode_data_and_enable_SMTPUTF8_raisescCs|jj�dS)N)r+Z
handle_accept)r
r
r
r�test_server_acceptBsz#SMTPDChannelTest.test_server_acceptcCs*|jd�|j|jjjd�dS)N�s500 Error: bad syntax
)r%r=r$rrV)r
r
r
r�test_missing_dataEs
z"SMTPDChannelTest.test_missing_datacCs*|jd�|j|jjjd�dS)NsEHLO examples
250 HELP
)r%r=r$rrV)r
r
r
r�	test_EHLOJs
zSMTPDChannelTest.test_EHLOcCs*|jd�|j|jjjd�dS)NsEHLOs501 Syntax: EHLO hostname
)r%r=r$rrV)r
r
r
r�test_EHLO_bad_syntaxNs
z%SMTPDChannelTest.test_EHLO_bad_syntaxcCs7|jd�|jd�|j|jjjd�dS)NsEHLO examples503 Duplicate HELO/EHLO
)r%r=r$rrV)r
r
r
r�test_EHLO_duplicateSs

z$SMTPDChannelTest.test_EHLO_duplicatecCs7|jd�|jd�|j|jjjd�dS)NsEHLO examplesHELO examples503 Duplicate HELO/EHLO
)r%r=r$rrV)r
r
r
r�test_EHLO_HELO_duplicateYs

z)SMTPDChannelTest.test_EHLO_HELO_duplicatecCsKtjj�}|jd�|j|jjjdj|�jd��dS)NsHELO examplez250 {}
�ascii)	rr�getfqdnr%r=r$rV�format�encode)r
�namer
r
r�	test_HELO_s
zSMTPDChannelTest.test_HELOcCs7|jd�|jd�|j|jjjd�dS)NsHELO examplesEHLO examples503 Duplicate HELO/EHLO
)r%r=r$rrV)r
r
r
r�test_HELO_EHLO_duplicatees

z)SMTPDChannelTest.test_HELO_EHLO_duplicatecCs.|jd�|j|jjjdd�dS)NsHELPs,250 Supported commands: EHLO HELO MAIL RCPT sDATA RSET NOOP QUIT VRFY
)r%r=r$rrV)r
r
r
r�	test_HELPks
zSMTPDChannelTest.test_HELPcCs*|jd�|j|jjjd�dS)Ns	HELP MAILs"250 Syntax: MAIL FROM: <address>
)r%r=r$rrV)r
r
r
r�test_HELP_commandqs
z"SMTPDChannelTest.test_HELP_commandcCs.|jd�|j|jjjdd�dS)Ns	HELP SPAMs,501 Supported commands: EHLO HELO MAIL RCPT sDATA RSET NOOP QUIT VRFY
)r%r=r$rrV)r
r
r
r�test_HELP_command_unknownvs
z*SMTPDChannelTest.test_HELP_command_unknowncCs*|jd�|j|jjjd�dS)NsHELOs501 Syntax: HELO hostname
)r%r=r$rrV)r
r
r
r�test_HELO_bad_syntax|s
z%SMTPDChannelTest.test_HELO_bad_syntaxcCs7|jd�|jd�|j|jjjd�dS)NsHELO examples503 Duplicate HELO/EHLO
)r%r=r$rrV)r
r
r
r�test_HELO_duplicate�s

z$SMTPDChannelTest.test_HELO_duplicatecCs@d|_|jd�|jd�|j|jjjd�dS)NFsHELO examples%MAIL from:<foo@example.com> SIZE=1234s"501 Syntax: MAIL FROM: <address>
)Z
extended_smtpr%r=r$rrV)r
r
r
r�8test_HELO_parameter_rejected_when_extensions_not_enabled�s
	

zISMTPDChannelTest.test_HELO_parameter_rejected_when_extensions_not_enabledcCs7|jd�|jd�|j|jjjd�dS)NsHELO examplesMAIL from:   <foo@example.com>s250 OK
)r%r=r$rrV)r
r
r
r�"test_MAIL_allows_space_after_colon�s

z3SMTPDChannelTest.test_MAIL_allows_space_after_coloncCs7|jd�|jd�|j|jjjd�dS)NsEHLO examples&MAIL from:   <foo@example.com> size=20s250 OK
)r%r=r$rrV)r
r
r
r�+test_extended_MAIL_allows_space_after_colon�s

z<SMTPDChannelTest.test_extended_MAIL_allows_space_after_coloncCs*|jd�|j|jjjd�dS)NsNOOPs250 OK
)r%r=r$rrV)r
r
r
r�	test_NOOP�s
zSMTPDChannelTest.test_NOOPcCs7|jd�|jd�|j|jjjd�dS)NsHELO examplesNOOPs250 OK
)r%r=r$rrV)r
r
r
r�test_HELO_NOOP�s

zSMTPDChannelTest.test_HELO_NOOPcCs*|jd�|j|jjjd�dS)NsNOOP his501 Syntax: NOOP
)r%r=r$rrV)r
r
r
r�test_NOOP_bad_syntax�s
z%SMTPDChannelTest.test_NOOP_bad_syntaxcCs*|jd�|j|jjjd�dS)NsQUITs	221 Bye
)r%r=r$rrV)r
r
r
r�	test_QUIT�s
zSMTPDChannelTest.test_QUITcCs7|jd�|jd�|j|jjjd�dS)NsHELO examplesQUITs	221 Bye
)r%r=r$rrV)r
r
r
r�test_HELO_QUIT�s

zSMTPDChannelTest.test_HELO_QUITcCs*|jd�|j|jjjd�dS)NsQUIT bye byes	221 Bye
)r%r=r$rrV)r
r
r
r�test_QUIT_arg_ignored�s
z&SMTPDChannelTest.test_QUIT_arg_ignoredcCs6d|j_|jd�|j|jjjd�dS)Nz	BAD STATEsHELO examples451 Internal confusion
)r$Z
smtp_stater%r=rrV)r
r
r
r�test_bad_state�s
zSMTPDChannelTest.test_bad_statecCsI|jd�|jdd|jjd�|j|jjjd�dS)NsHELO examplesMAIL from: �as@examples500 Error: line too long
)r%r$�command_size_limitr=rrV)r
r
r
r�test_command_too_long�s
z&SMTPDChannelTest.test_command_too_longcCs�|jd�|jjtd�}|jdd|d�|j|jjjd�|jdd|dd�|j|jjjd�dS)	NsEHLO examplezMAIL from:<@example>sMAIL from:<r}s@example> SIZE=1234s250 OK
�s500 Error: line too long
)r%r$r~�lenr=rrV)r
�fill_lenr
r
r�*test_MAIL_command_limit_extended_with_SIZE�s
z;SMTPDChannelTest.test_MAIL_command_limit_extended_with_SIZEcCsA|jd�|jd�|j|jjjdd�d�dS)NsEHLO examples5MAIL from: <naive@example.com> BODY=8BITMIME SMTPUTF8r��5)r%r=r$rrV)r
r
r
r�-test_MAIL_command_rejects_SMTPUTF8_by_default�s
z>SMTPDChannelTest.test_MAIL_command_rejects_SMTPUTF8_by_defaultcCsxd|j_|jd�|jd�|jd�|jd�|jd|jjd�|j|jjjd�dS)	NisHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesDATA�AsA
.s552 Error: Too much mail data
)r$�data_size_limitr%r=rrV)r
r
r
r�-test_data_longer_than_default_data_size_limit�s



z>SMTPDChannelTest.test_data_longer_than_default_data_size_limitcCs7|jd�|jd�|j|jjjd�dS)NsEHLO examples!MAIL FROM:<eggs@example> SIZE=512s250 OK
)r%r=r$rrV)r
r
r
r�test_MAIL_size_parameter�s

z)SMTPDChannelTest.test_MAIL_size_parametercCs7|jd�|jd�|j|jjjd�dS)NsEHLO examples%MAIL FROM:<eggs@example> SIZE=invalids9501 Syntax: MAIL FROM: <address> [SP <mail-parameters>]
)r%r=r$rrV)r
r
r
r� test_MAIL_invalid_size_parameter�s

z1SMTPDChannelTest.test_MAIL_invalid_size_parametercCsj|jd�|jd�|j|jjjd�|jd�|jd�|j|jjjd�dS)NsEHLO examples"MAIL FROM:<eggs@example> ham=greens<555 MAIL FROM parameters not recognized or not implemented
sMAIL FROM:<eggs@example>s RCPT TO:<eggs@example> ham=greens:555 RCPT TO parameters not recognized or not implemented
)r%r=r$rrV)r
r
r
r�!test_MAIL_RCPT_unknown_parameters�s



z2SMTPDChannelTest.test_MAIL_RCPT_unknown_parameterscCsCd|j_|jd�|jd�|j|jjjd�dS)NisEHLO examples"MAIL FROM:<eggs@example> SIZE=2096s<552 Error: message size exceeds fixed maximum message size
)r$r�r%r=rrV)r
r
r
r�<test_MAIL_size_parameter_larger_than_default_data_size_limit�s


zMSMTPDChannelTest.test_MAIL_size_parameter_larger_than_default_data_size_limitcCs7|jd�|jd�|j|jjjd�dS)NsHELO examplesRCPT to:spam@examples503 Error: need MAIL command
)r%r=r$rrV)r
r
r
r�test_need_MAILs

zSMTPDChannelTest.test_need_MAILcCs7|jd�|jd�|j|jjjd�dS)NsHELO examplesMAIL from eggs@examples"501 Syntax: MAIL FROM: <address>
)r%r=r$rrV)r
r
r
r�test_MAIL_syntax_HELOs

z&SMTPDChannelTest.test_MAIL_syntax_HELOcCs7|jd�|jd�|j|jjjd�dS)NsEHLO examplesMAIL from eggs@examples9501 Syntax: MAIL FROM: <address> [SP <mail-parameters>]
)r%r=r$rrV)r
r
r
r�test_MAIL_syntax_EHLO
s

z&SMTPDChannelTest.test_MAIL_syntax_EHLOcCs7|jd�|jd�|j|jjjd�dS)NsHELO examples
MAIL from:s"501 Syntax: MAIL FROM: <address>
)r%r=r$rrV)r
r
r
r�test_MAIL_missing_addresss

z*SMTPDChannelTest.test_MAIL_missing_addresscCs7|jd�|jd�|j|jjjd�dS)NsHELO examplesMAIL from:<eggs@example>s250 OK
)r%r=r$rrV)r
r
r
r�test_MAIL_chevronss

z#SMTPDChannelTest.test_MAIL_chevronscCs7|jd�|jd�|j|jjjd�dS)NsEHLO examplesMAIL from:<>s250 OK
)r%r=r$rrV)r
r
r
r�test_MAIL_empty_chevronss

z)SMTPDChannelTest.test_MAIL_empty_chevronscCsM|jd�|jd�|j|jjjd�|j|jjd�dS)NsEHLO examples%MAIL from: <"Fred Blogs"@example.com>s250 OK
z"Fred Blogs"@example.com)r%r=r$rrVr)r
r
r
r�test_MAIL_quoted_localpart#s

z+SMTPDChannelTest.test_MAIL_quoted_localpartcCsM|jd�|jd�|j|jjjd�|j|jjd�dS)NsEHLO examples#MAIL from: "Fred Blogs"@example.coms250 OK
z"Fred Blogs"@example.com)r%r=r$rrVr)r
r
r
r�$test_MAIL_quoted_localpart_no_angles)s

z5SMTPDChannelTest.test_MAIL_quoted_localpart_no_anglescCsM|jd�|jd�|j|jjjd�|j|jjd�dS)NsEHLO examples/MAIL from: <"Fred Blogs"@example.com> SIZE=1000s250 OK
z"Fred Blogs"@example.com)r%r=r$rrVr)r
r
r
r�$test_MAIL_quoted_localpart_with_size/s

z5SMTPDChannelTest.test_MAIL_quoted_localpart_with_sizecCsM|jd�|jd�|j|jjjd�|j|jjd�dS)NsEHLO examples-MAIL from: "Fred Blogs"@example.com SIZE=1000s250 OK
z"Fred Blogs"@example.com)r%r=r$rrVr)r
r
r
r�.test_MAIL_quoted_localpart_with_size_no_angles5s

z?SMTPDChannelTest.test_MAIL_quoted_localpart_with_size_no_anglescCsD|jd�|jd�|jd�|j|jjjd�dS)NsHELO examplesMAIL from:eggs@examplesMAIL from:spam@examples 503 Error: nested MAIL command
)r%r=r$rrV)r
r
r
r�test_nested_MAIL;s



z!SMTPDChannelTest.test_nested_MAILcCs.|jd�|j|jjjdd�dS)NsVRFY eggs@examples:252 Cannot VRFY user, but will accept message and attempt s
delivery
)r%r=r$rrV)r
r
r
r�	test_VRFYBs
zSMTPDChannelTest.test_VRFYcCs*|jd�|j|jjjd�dS)NsVRFYs501 Syntax: VRFY <address>
)r%r=r$rrV)r
r
r
r�test_VRFY_syntaxHs
z!SMTPDChannelTest.test_VRFY_syntaxcCs*|jd�|j|jjjd�dS)NsEXPNs502 EXPN not implemented
)r%r=r$rrV)r
r
r
r�test_EXPN_not_implementedMs
z*SMTPDChannelTest.test_EXPN_not_implementedcCs*|jd�|j|jjjd�dS)NsMAIL from:<foo@example.com>s503 Error: send HELO first
)r%r=r$rrV)r
r
r
r�test_no_HELO_MAILRs
z"SMTPDChannelTest.test_no_HELO_MAILcCsD|jd�|jd�|jd�|j|jjjd�dS)NsHELO examplesMAIL From:eggs@examplesDATAs503 Error: need RCPT command
)r%r=r$rrV)r
r
r
r�test_need_RCPTWs



zSMTPDChannelTest.test_need_RCPTcCsD|jd�|jd�|jd�|j|jjjd�dS)NsHELO examplesMAIL From: eggs@examplesRCPT to eggs@examples 501 Syntax: RCPT TO: <address>
)r%r=r$rrV)r
r
r
r�test_RCPT_syntax_HELO^s



z&SMTPDChannelTest.test_RCPT_syntax_HELOcCsD|jd�|jd�|jd�|j|jjjd�dS)NsEHLO examplesMAIL From: eggs@examplesRCPT to eggs@examples7501 Syntax: RCPT TO: <address> [SP <mail-parameters>]
)r%r=r$rrV)r
r
r
r�test_RCPT_syntax_EHLOes



z&SMTPDChannelTest.test_RCPT_syntax_EHLOcCsD|jd�|jd�|jd�|j|jjjd�dS)NsHELO examplesMAIL From: eggs@examplesRCPT to: <eggs@example>s250 OK
)r%r=r$rrV)r
r
r
r�test_RCPT_lowercase_to_OKls


z*SMTPDChannelTest.test_RCPT_lowercase_to_OKcCs*|jd�|j|jjjd�dS)NsRCPT to eggs@examples503 Error: send HELO first
)r%r=r$rrV)r
r
r
r�test_no_HELO_RCPTrs
z"SMTPDChannelTest.test_no_HELO_RCPTcCs�|jd�|jd�|j|jjjd�|jd�|j|jjjd�|jd�|j|jjjd�|jd�|j|jjjd�|j|jjd
d
dgdfg�dS)NsHELO examplesMAIL From:eggs@examples250 OK
sRCPT To:spam@examplesDATAs%354 End data with <CR><LF>.<CR><LF>
s
data
more
.�peer-address�	peer-portzeggs@examplezspam@examplez	data
more)r�r�)r%r=r$rrVr+r)r
r
r
r�test_data_dialogws




z!SMTPDChannelTest.test_data_dialogcCsQ|jd�|jd�|jd�|jd�|j|jjjd�dS)NsHELO examplesMAIL From:eggs@examplesRCPT To:spam@examples	DATA spams501 Syntax: DATA
)r%r=r$rrV)r
r
r
r�test_DATA_syntax�s




z!SMTPDChannelTest.test_DATA_syntaxcCs*|jd�|j|jjjd�dS)Ns	DATA spams503 Error: send HELO first
)r%r=r$rrV)r
r
r
r�test_no_HELO_DATA�s
z"SMTPDChannelTest.test_no_HELO_DATAcCs[|jd�|jd�|jd�|jd�|jd�|j|jjd�dS)NsHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesDATAs..
.
�.)r%r=r$�
received_data)r
r
r
r�$test_data_transparency_section_4_5_2�s




z5SMTPDChannelTest.test_data_transparency_section_4_5_2cCs}|jd�|jd�|jd�|jd�|jd�|jd�|j|jjd
d	d
dgdfg�dS)NsHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesRCPT To:ham@examplesDATAsdata
.�peer-address�	peer-portzeggs@examplezspam@examplezham@exampler)r�r�)r%r=r+r)r
r
r
r�test_multiple_RCPT�s





	z#SMTPDChannelTest.test_multiple_RCPTcCs^|jd�|jd�|jd�|jd�|jd�|j|jjjd�dS)NsHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesDATAsreturn status
.s250 Okish
)r%r=r$rrV)r
r
r
r�test_manual_status�s




z#SMTPDChannelTest.test_manual_statuscCs�|jd�|jd�|jd�|jd�|j|jjjd�|jd�|jd�|jd�|jd	�|j|jjddd
gdfg�dS)NsHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesRSETs250 OK
sMAIL From:foo@examplesRCPT To:eggs@examplesDATAsdata
.�peer-address�	peer-portzfoo@examplezeggs@exampler)r�r�)r%r=r$rrVr+r)r
r
r
r�	test_RSET�s







zSMTPDChannelTest.test_RSETcCs7|jd�|jd�|j|jjjd�dS)NsHELO examplesRSETs250 OK
)r%r=r$rrV)r
r
r
r�test_HELO_RSET�s

zSMTPDChannelTest.test_HELO_RSETcCs*|jd�|j|jjjd�dS)NsRSET his501 Syntax: RSET
)r%r=r$rrV)r
r
r
r�test_RSET_syntax�s
z!SMTPDChannelTest.test_RSET_syntaxcCs.|jd�|j|jjjdd�dS)NsUNKNOWN_CMDs%500 Error: command "UNKNOWN_CMD" not srecognized
)r%r=r$rrV)r
r
r
r�test_unknown_command�s
z%SMTPDChannelTest.test_unknown_commandc�Cs�tjdtf��|jj}WdQRXtjdtf��d|j_WdQRXtjdtf��|jj}WdQRXtjdtf��d|j_WdQRXtjdtf��|jj}WdQRXtjdtf��d|j_WdQRXtjdtf��|jj}WdQRXtjdtf��d|j_WdQRXtjdtf��|jj}WdQRXtjdtf��d|j_WdQRXtjdtf��|jj	}WdQRXtjdtf��d|j_	WdQRXtjdtf��|jj
}WdQRXtjdtf��d|j_
WdQRXtjdtf��|jj}WdQRXtjdtf��d|j_WdQRXtjdtf��|jj}WdQRXtjdtf��d|j_WdQRXtjdtf��|jj
}WdQRXtjdtf��d|j_
WdQRXtjdtf��|jj}WdQRXtjdtf��d|j_WdQRXdS)N��spam)rZcheck_warningsr0r$Z_SMTPChannel__serverZ_SMTPChannel__lineZ_SMTPChannel__stateZ_SMTPChannel__greetingZ_SMTPChannel__mailfromZ_SMTPChannel__rcpttosZ_SMTPChannel__dataZ_SMTPChannel__fqdnZ_SMTPChannel__peerZ_SMTPChannel__connZ_SMTPChannel__addr)r
r�r
r
r�test_attribute_deprecations�sXz,SMTPDChannelTest.test_attribute_deprecationscCsr|jt��ttjdfd�}WdQRX|jj�\}}|jt��tj|||�WdQRXdS)Nrr)rr)	r/r0rrr&r+r'rr()r
r+r,r-r
r
r� test_decode_data_default_warnings
z1SMTPDChannelTest.test_decode_data_default_warningN)Grrrrr6r%r_r4r`rbrcrdrerfrlrmrnrorprqrrrsrtrurvrwrxryrzr{r|rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
r
r
rr^#s�

	.r^zIPv6 not enabledc@seZdZdd�ZdS)�SMTPDChannelIPv6TestcCs�tt_t_tj|_tj�|_t_t	t
jdfddd�|_|jj
�\}}tj|j||dd�|_dS)Nrrr T)rr)rrrrrQrRrSrTrUrrrGr+r'r(r$)r
r,r-r
r
rr	szSMTPDChannelIPv6Test.setUpN)rrrrr
r
r
rr�sr�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�!SMTPDChannelWithDataSizeLimitTestcCs�tt_t_tj|_tj�|_t_t	t
jdfddd�|_|jj
�\}}tj|j||ddd�|_dS)Nrrr T� )rr)rrrrrQrRrSrTrUrrr&r+r'r(r$)r
r,r-r
r
rrsz'SMTPDChannelWithDataSizeLimitTest.setUpcCs*tj�tt_t_|jt_dS)N)rr5rrrRrQ)r
r
r
rr6 s
z*SMTPDChannelWithDataSizeLimitTest.tearDowncCs$|jjj|�|jj�dS)N)r$rr!r")r
r#r
r
rr%%sz,SMTPDChannelWithDataSizeLimitTest.write_linecCs�|jd�|jd�|j|jjjd�|jd�|j|jjjd�|jd�|j|jjjd�|jd�|j|jjjd�|j|jjd
d
dgdfg�dS)NsHELO examplesMAIL From:eggs@examples250 OK
sRCPT To:spam@examplesDATAs%354 End data with <CR><LF>.<CR><LF>
s
data
more
.�peer-address�	peer-portzeggs@examplezspam@examplez	data
more)r�r�)r%r=r$rrVr+r)r
r
r
r�test_data_limit_dialog)s




z8SMTPDChannelWithDataSizeLimitTest.test_data_limit_dialogcCs�|jd�|jd�|j|jjjd�|jd�|j|jjjd�|jd�|j|jjjd�|jd�|j|jjjd�dS)	NsHELO examplesMAIL From:eggs@examples250 OK
sRCPT To:spam@examplesDATAs%354 End data with <CR><LF>.<CR><LF>
s'This message is longer than 32 bytes
.s552 Error: Too much mail data
)r%r=r$rrV)r
r
r
r�$test_data_limit_dialog_too_much_data;s




zFSMTPDChannelWithDataSizeLimitTest.test_data_limit_dialog_too_much_dataN)rrrrr6r%r�r�r
r
r
rr�s
r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SMTPDChannelWithDecodeDataFalsecCs�tt_t_tj|_tj�|_t_t	t
jdfddd�|_|jj
�\}}tj|j||dd�|_dS)Nrrr F)rr)rrrrrQrRrSrTrUrrr&r+r'r(r$)r
r,r-r
r
rrLsz%SMTPDChannelWithDecodeDataFalse.setUpcCs*tj�tt_t_|jt_dS)N)rr5rrrRrQ)r
r
r
rr6Ws
z(SMTPDChannelWithDecodeDataFalse.tearDowncCs$|jjj|�|jj�dS)N)r$rr!r")r
r#r
r
rr%\sz*SMTPDChannelWithDecodeDataFalse.write_linecCsh|jd�|jd�|jd�|jd�|jd�|jd�|j|jjd�dS)NsHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesDATAsplain ascii textr8)r%r=r$r�)r
r
r
r�test_ascii_data`s





z/SMTPDChannelWithDecodeDataFalse.test_ascii_datacCsu|jd�|jd�|jd�|jd�|jd�|jd�|jd�|j|jjd�dS)	NsHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesDATAsutf8 enriched text: żźćsand some plain asciir8s/utf8 enriched text: żźć
and some plain ascii)r%r=r$r�)r
r
r
r�test_utf8_datais






	z.SMTPDChannelWithDecodeDataFalse.test_utf8_dataN)rrrrr6r%r�r�r
r
r
rr�Js
	r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SMTPDChannelWithDecodeDataTruecCs�tt_t_tj|_tj�|_t_t	t
jdfddd�|_|jj
�\}}tj|j||dd�|_dS)Nrrr T)rr)rrrrrQrRrSrTrUrrr&r+r'r(r$)r
r,r-r
r
rrysz$SMTPDChannelWithDecodeDataTrue.setUpcCs*tj�tt_t_|jt_dS)N)rr5rrrRrQ)r
r
r
rr6�s
z'SMTPDChannelWithDecodeDataTrue.tearDowncCs$|jjj|�|jj�dS)N)r$rr!r")r
r#r
r
rr%�sz)SMTPDChannelWithDecodeDataTrue.write_linecCsh|jd�|jd�|jd�|jd�|jd�|jd�|j|jjd�dS)NsHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesDATAsplain ascii textr8zplain ascii text)r%r=r$r�)r
r
r
rr��s





z.SMTPDChannelWithDecodeDataTrue.test_ascii_datacCsu|jd�|jd�|jd�|jd�|jd�|jd�|jd�|j|jjd�dS)	NsHELO examplesMAIL From:eggs@examplesRCPT To:spam@examplesDATAsutf8 enriched text: żźćsand some plain asciir8u/utf8 enriched text: żźć
and some plain ascii)r%r=r$r�)r
r
r
rr��s






	z-SMTPDChannelWithDecodeDataTrue.test_utf8_dataN)rrrrr6r%r�r�r
r
r
rr�ws
	r�c@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�&SMTPDChannelTestWithEnableSMTPUTF8TruecCs�tt_t_tj|_tj�|_t_t	t
jdfddd�|_|jj
�\}}tj|j||dd�|_dS)Nrrr2T)rr)rrrrrQrRrSrTrUrrr&r+r'r(r$)r
r,r-r
r
rr�sz,SMTPDChannelTestWithEnableSMTPUTF8True.setUpcCs*tj�tt_t_|jt_dS)N)rr5rrrRrQ)r
r
r
rr6�s
z/SMTPDChannelTestWithEnableSMTPUTF8True.tearDowncCs$|jjj|�|jj�dS)N)r$rr!r")r
r#r
r
rr%�sz1SMTPDChannelTestWithEnableSMTPUTF8True.write_linecCs@|jd�|jdjd��|j|jjjd�dS)NsEHLO exampleu7MAIL from: <naïve@example.com> BODY=8BITMIME SMTPUTF8zutf-8s250 OK
)r%rjr=r$rrV)r
r
r
r�1test_MAIL_command_accepts_SMTPUTF8_when_announced�s


zXSMTPDChannelTestWithEnableSMTPUTF8True.test_MAIL_command_accepts_SMTPUTF8_when_announcedcCs
|jd�x�ddgD]�}|jd|�|j|jjjdd�d�|jd�|j|jjjdd�d�|jd	�|j|jjjdd�d
�|jd�|dkr�|j|jjjd�q|j|jjjd
�qWdS)NsEHLO examplerasBODY=8BITMIME SMTPUTF8sMAIL from: <a@example> r�s250srcpt to:<b@example.com>sdatas354sc
.s250 OK
s250 SMTPUTF8 message okish
)r%r=r$rrV)r
Zmail_parametersr
r
r�test_process_smtputf8_message�s
#
#
#
zDSMTPDChannelTestWithEnableSMTPUTF8True.test_process_smtputf8_messagecCs�|jd�|jdjd��|j|jjjdd�d�|jdjd��|j|jjjdd�d�|jd�|j|jjjdd�d	�|jd
�|jd�|j|jjd
�dS)NsEHLO exampleu2MAIL From: naïve@examplé BODY=8BITMIME SMTPUTF8zutf-8rr�s250uRCPT To:späm@examplésDATAs354sutf8 enriched text: żźćr8)r%rjr=r$rrVr�)r
r
r
rr��s
##
#

	z5SMTPDChannelTestWithEnableSMTPUTF8True.test_utf8_datacCs�|jd�d
td�}|jdd|dd	�|j|jjjd
�|jdd|d	�|j|jjjd�dS)Nsehlo exampleir��
zmail from:<@example>sMAIL from:<r}r�s	@example>s500 Error: line too long
s250 OK
ii$)r%r�r=r$rrV)r
r�r
r
r�7test_MAIL_command_limit_extended_with_SIZE_and_SMTPUTF8�s
z^SMTPDChannelTestWithEnableSMTPUTF8True.test_MAIL_command_limit_extended_with_SIZE_and_SMTPUTF8cCsC|jd�dtd�}xdddgD]}|jd	||d
�|j|jjjdd�d
�|jd	||d�|j|jjjdd�d�|jd�|j|jjjdd�d�|jd�|j|jjjdd�d�|jd�|j|jjjdd�d�q-WdS)Nsehlo exampleir�r�zmail from:<@example>r}�b�csMAIL from:<s
a@example>rr�s500s	@example>s250srcpt to:<hans@example.com>sdatas354stest
.ii$)r%r�r=r$rrV)r
r��charr
r
r�1test_multiple_emails_with_extended_command_length�s
##
#
#
zXSMTPDChannelTestWithEnableSMTPUTF8True.test_multiple_emails_with_extended_command_lengthN)rrrrr6r%r�r�r�r�r�r
r
r
rr��s

r��__main__)rMr>ZtestrrrrSrrrr�	ExceptionrrZTestCaserr7rFrPrZr^rNrOr�r�r�r�r�r�mainr
r
r
r�<module>s0&^%B��7-,W