B
    u9a”   ã               @   sl  d dl Z d dlZd dlmZmZ d dlZd dlZd dlZd dlZG dd„ dej	ƒZ
G dd„ deƒZG dd„ de
ƒZG d	d
„ d
e jƒZG dd„ de jƒZG dd„ de jƒZG dd„ de jƒZG dd„ de jƒZG dd„ de jƒZe  ejd¡G dd„ deƒƒZG dd„ de jƒZG dd„ de jƒZG dd„ de jƒZG dd„ de jƒZG d d!„ d!e jƒZed"krhe  ¡  dS )#é    N)ÚsupportÚmock_socketc               @   s   e Zd Zdd„ Zdd„ ZdS )ÚDummyServerc             O   s2   t jj| f|ž|Ž g | _| jr(d| _nd| _d S )Nzreturn statuss   return status)ÚsmtpdÚ
SMTPServerÚ__init__ÚmessagesZ_decode_dataÚreturn_status)ÚselfÚargsÚkwargs© r   ú /usr/lib/python3.7/test_smtpd.pyr      s
    zDummyServer.__init__c             K   s>   | j  ||||f¡ || jkr"dS d|kr:d|d kr:dS d S )Nz	250 OkishZmail_optionsZSMTPUTF8z250 SMTPUTF8 message okish)r   Úappendr	   )r
   ZpeerÚmailfromZrcpttosÚdataÚkwr   r   r   Úprocess_message   s
    
zDummyServer.process_messageN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   
   s   r   c               @   s   e Zd ZdS )ÚDummyDispatcherBrokenN)r   r   r   r   r   r   r   r      s   r   c               @   s   e Zd Zdd„ ZdS )ÚBrokenDummyServerc             C   s
   t ƒ ‚d S )N)r   )r
   Znumr   r   r   Úlisten    s    zBrokenDummyServer.listenN)r   r   r   r   r   r   r   r   r      s   r   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚSMTPDServerTestc             C   s   t  t_t_d S )N)r   r   ÚsocketÚasyncore)r
   r   r   r   ÚsetUp%   s    zSMTPDServerTest.setUpc                sr   t jtjdfddd}| ¡ \}}t j|||dd‰ ‡ fdd„}|dƒ |dƒ |d	ƒ |d
ƒ |  t|d¡ d S )Nr   )Úbr   T)Údecode_datac                s   ˆ j  | ¡ ˆ  ¡  d S )N)r   Ú
queue_recvÚhandle_read)Úline)Úchannelr   r   Ú
write_line.   s    zFSMTPDServerTest.test_process_message_unimplemented.<locals>.write_lines   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   DATAs	   spam
.
)r   r   r   ÚHOSTÚacceptÚSMTPChannelÚassertRaisesÚNotImplementedError)r
   ÚserverÚconnÚaddrr$   r   )r#   r   Ú"test_process_message_unimplemented(   s    z2SMTPDServerTest.test_process_message_unimplementedc             C   s"   | j ttjtjdfdddd d S )Nr   )r   r   T)Úenable_SMTPUTF8r   )r(   Ú
ValueErrorr   r   r   r%   )r
   r   r   r   Ú+test_decode_data_and_enable_SMTPUTF8_raises8   s    z;SMTPDServerTest.test_decode_data_and_enable_SMTPUTF8_raisesc             C   s   t  ¡  t t _t_d S )N)r   Ú	close_allr   r   )r
   r   r   r   ÚtearDownA   s    zSMTPDServerTest.tearDownN)r   r   r   r   r-   r0   r2   r   r   r   r   r   $   s   	r   c               @   sF   e Zd Zdd„ Zddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dS )ÚDebuggingServerTestc             C   s   t  t_t_d S )N)r   r   r   r   )r
   r   r   r   r   H   s    zDebuggingServerTest.setUpFc                sN   ‡ fdd„}|dƒ |r"|dƒ n|dƒ |dƒ |dƒ ||ƒ |dƒ d S )	Nc                s   ˆ j  | ¡ ˆ  ¡  d S )N)r   r    r!   )r"   )r#   r   r   r$   L   s    z1DebuggingServerTest.send_data.<locals>.write_lines   EHLO examples-   MAIL From:eggs@example BODY=8BITMIME SMTPUTF8s   MAIL From:eggs@examples   RCPT To:spam@examples   DATAó   .r   )r
   r#   r   r.   r$   r   )r#   r   Ú	send_dataK   s    
zDebuggingServerTest.send_datac          	   C   sr   t jtjdfddd}| ¡ \}}t j|||dd}t ¡ }|  |d¡ W d Q R X | ¡ }|  	|t
 d¡¡ d S )Nr   )r   r   T)r   s   From: test

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

             hello
             ------------ END MESSAGE ------------
             )r   ÚDebuggingServerr   r%   r&   r'   Úcaptured_stdoutr5   ÚgetvalueÚassertEqualÚtextwrapÚdedent)r
   r*   r+   r,   r#   ÚsÚstdoutr   r   r   Ú*test_process_message_with_decode_data_trueY   s    

z>DebuggingServerTest.test_process_message_with_decode_data_truec          	   C   sj   t  tjdfd¡}| ¡ \}}t  |||¡}t ¡ }|  |d¡ W d Q R X | ¡ }|  	|t
 d¡¡ d S )Nr   )r   r   s   From: test

hÃ©lloÿ
zå             ---------- MESSAGE FOLLOWS ----------
             b'From: test'
             b'X-Peer: peer-address'
             b''
             b'h\xc3\xa9llo\xff'
             ------------ END MESSAGE ------------
             )r   r6   r   r%   r&   r'   r7   r5   r8   r9   r:   r;   )r
   r*   r+   r,   r#   r<   r=   r   r   r   Ú+test_process_message_with_decode_data_falsej   s    

z?DebuggingServerTest.test_process_message_with_decode_data_falsec          	   C   sr   t jtjdfddd}| ¡ \}}t j|||dd}t ¡ }|  |d¡ W d Q R X | ¡ }|  	|t
 d¡¡ d S )Nr   )r   r   T)r.   s   From: test

hÃ©lloÿ
zå             ---------- MESSAGE FOLLOWS ----------
             b'From: test'
             b'X-Peer: peer-address'
             b''
             b'h\xc3\xa9llo\xff'
             ------------ END MESSAGE ------------
             )r   r6   r   r%   r&   r'   r7   r5   r8   r9   r:   r;   )r
   r*   r+   r,   r#   r<   r=   r   r   r   Ú.test_process_message_with_enable_SMTPUTF8_truez   s    

zBDebuggingServerTest.test_process_message_with_enable_SMTPUTF8_truec          	   C   sv   t jtjdfddd}| ¡ \}}t j|||dd}t ¡ }| j|ddd W d Q R X | ¡ }|  	|t
 d¡¡ d S )Nr   )r   r   T)r.   s   From: 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 ------------
             )r   r6   r   r%   r&   r'   r7   r5   r8   r9   r:   r;   )r
   r*   r+   r,   r#   r<   r=   r   r   r   Ú7test_process_SMTPUTF8_message_with_enable_SMTPUTF8_true‹   s    

zKDebuggingServerTest.test_process_SMTPUTF8_message_with_enable_SMTPUTF8_truec             C   s   t  ¡  t t _t_d S )N)r   r1   r   r   )r
   r   r   r   r2   ž   s    zDebuggingServerTest.tearDownN)F)
r   r   r   r   r5   r>   r?   r@   rA   r2   r   r   r   r   r3   F   s   
r3   c               @   s:   e Zd Zdd„ Zdd„ Ze ejd¡dd„ ƒZ	dd	„ Z
d
S )ÚTestFamilyDetectionc             C   s   t  t_t_d S )N)r   r   r   r   )r
   r   r   r   r   ¤   s    zTestFamilyDetection.setUpc             C   s   t  ¡  t t _t_d S )N)r   r1   r   r   )r
   r   r   r   r2   §   s    zTestFamilyDetection.tearDownzIPv6 not enabledc             C   s.   t  tjdftjdf¡}|  |jjtj¡ d S )Nr   )	r   r   r   ÚHOSTv6ÚHOSTv4r9   r   ÚfamilyZAF_INET6)r
   r*   r   r   r   Útest_socket_uses_IPv6«   s    z)TestFamilyDetection.test_socket_uses_IPv6c             C   s.   t  tjdftjdf¡}|  |jjtj¡ d S )Nr   )	r   r   r   rD   rC   r9   r   rE   ZAF_INET)r
   r*   r   r   r   Útest_socket_uses_IPv4°   s    z)TestFamilyDetection.test_socket_uses_IPv4N)r   r   r   r   r2   ÚunittestÚ
skipUnlessr   ÚIPV6_ENABLEDrF   rG   r   r   r   r   rB   £   s   rB   c               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚTestRcptOptionParsings:   555 RCPT TO parameters not recognized or not implemented
c             C   s(   t  t_t_tj| _t ¡  | _t_d S )N)	r   r   r   r   ÚDEBUGSTREAMÚold_debugstreamÚioÚStringIOÚdebug)r
   r   r   r   r   ¹   s    zTestRcptOptionParsing.setUpc             C   s    t  ¡  t t _t_| jt_d S )N)r   r1   r   r   rM   rL   )r
   r   r   r   r2   ¾   s    zTestRcptOptionParsing.tearDownc             C   s   |j  |¡ | ¡  d S )N)r   r    r!   )r
   r#   r"   r   r   r   r$   Ã   s    z TestRcptOptionParsing.write_linec             C   sd   t tjdfdƒ}| ¡ \}}t |||¡}|  |d¡ |  |d¡ |  |d¡ |  |jj	| j
¡ d S )Nr   )r   r   s   EHLO examples$   MAIL from: <foo@example.com> size=20s"   RCPT to: <foo@example.com> foo=bar)r   r   r%   r&   r   r'   r$   r9   r   ÚlastÚerror_response)r
   r*   r+   r,   r#   r   r   r   Útest_params_rejectedÇ   s    z*TestRcptOptionParsing.test_params_rejectedc             C   sb   t tjdfdƒ}| ¡ \}}t |||¡}|  |d¡ |  |d¡ |  |d¡ |  |jj	d¡ d S )Nr   )r   r   s   EHLO examples$   MAIL from: <foo@example.com> size=20s   RCPT to: <foo@example.com>s   250 OK
)
r   r   r%   r&   r   r'   r$   r9   r   rQ   )r
   r*   r+   r,   r#   r   r   r   Útest_nothing_acceptedÐ   s    z+TestRcptOptionParsing.test_nothing_acceptedN)	r   r   r   rR   r   r2   r$   rS   rT   r   r   r   r   rK   µ   s   	rK   c               @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚTestMailOptionParsings<   555 MAIL FROM parameters not recognized or not implemented
c             C   s(   t  t_t_tj| _t ¡  | _t_d S )N)	r   r   r   r   rL   rM   rN   rO   rP   )r
   r   r   r   r   Þ   s    zTestMailOptionParsing.setUpc             C   s    t  ¡  t t _t_| jt_d S )N)r   r1   r   r   rM   rL   )r
   r   r   r   r2   ã   s    zTestMailOptionParsing.tearDownc             C   s   |j  |¡ | ¡  d S )N)r   r    r!   )r
   r#   r"   r   r   r   r$   è   s    z TestMailOptionParsing.write_linec             C   sŠ   t tjdfddd}| ¡ \}}tj|||dd}|  |d¡ x*dD ]"}|  ||¡ |  |jj	| j
¡ qDW |  |d¡ |  |jj	d¡ d S )	Nr   )r   r   T)r   s   EHLO example)s-   MAIL from: <foo@example.com> size=20 SMTPUTF8s;   MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=8BITMIMEs1   MAIL from: <foo@example.com> size=20 BODY=UNKNOWNs2   MAIL from: <foo@example.com> size=20 body=8bitmimes$   MAIL from: <foo@example.com> size=20s   250 OK
)r   r   r%   r&   r   r'   r$   r9   r   rQ   rR   )r
   r*   r+   r,   r#   r"   r   r   r   Útest_with_decode_data_trueì   s    
z0TestMailOptionParsing.test_with_decode_data_truec             C   sž   t tjdfdƒ}| ¡ \}}t |||¡}|  |d¡ x*dD ]"}|  ||¡ |  |jj	| j
¡ q<W |  |d¡ |  |jj	d¡ |  |d¡ |  |jj	d¡ d S )	Nr   )r   r   s   EHLO example)s-   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=UNKNOWNs3   501 Error: BODY can only be one of 7BIT, 8BITMIME
s2   MAIL from: <foo@example.com> size=20 body=8bitmimes   250 OK
)r   r   r%   r&   r   r'   r$   r9   r   rQ   rR   )r
   r*   r+   r,   r#   r"   r   r   r   Útest_with_decode_data_falseü   s     
z1TestMailOptionParsing.test_with_decode_data_falsec             C   s^   t tjdfddd}| ¡ \}}tj|||dd}|  |d¡ |  |d¡ |  |jj	d¡ d S )Nr   )r   r   T)r.   s   EHLO examples;   MAIL from: <foo@example.com> size=20 body=8bitmime smtputf8s   250 OK
)
r   r   r%   r&   r   r'   r$   r9   r   rQ   )r
   r*   r+   r,   r#   r   r   r   Útest_with_enable_smtputf8_true  s    z4TestMailOptionParsing.test_with_enable_smtputf8_trueN)
r   r   r   rR   r   r2   r$   rV   rW   rX   r   r   r   r   rU   Ú   s   rU   c               @   s$  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;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~„ ZAdd€„ ZBdd‚„ ZCdƒd„„ ZDd…d†„ ZEd‡S )ˆÚSMTPDChannelTestc             C   sb   t  t_t_tj| _t ¡  | _t_t	t
jdfddd| _| j ¡ \}}tj| j||dd| _d S )Nr   )r   r   T)r   )r   r   r   r   rL   rM   rN   rO   rP   r   r   r%   r*   r&   r'   r#   )r
   r+   r,   r   r   r   r     s    
zSMTPDChannelTest.setUpc             C   s    t  ¡  t t _t_| jt_d S )N)r   r1   r   r   rM   rL   )r
   r   r   r   r2   '  s    zSMTPDChannelTest.tearDownc             C   s   | j j |¡ | j  ¡  d S )N)r#   r   r    r!   )r
   r"   r   r   r   r$   ,  s    zSMTPDChannelTest.write_linec             C   s   | j tttjdfddd d S )Nr   )r   r   T)r   )r(   r   r   r   r%   )r
   r   r   r   Útest_broken_connect0  s    z$SMTPDChannelTest.test_broken_connectc          	   C   s(   | j ttj| j| jj| jjddd d S )NT)r.   r   )r(   r/   r   r'   r*   r#   r+   r,   )r
   r   r   r   r0   5  s    z<SMTPDChannelTest.test_decode_data_and_enable_SMTPUTF8_raisesc             C   s   | j  ¡  d S )N)r*   Zhandle_accept)r
   r   r   r   Útest_server_accept;  s    z#SMTPDChannelTest.test_server_acceptc             C   s    |   d¡ |  | jjjd¡ d S )Nó    s   500 Error: bad syntax
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_missing_data>  s    
z"SMTPDChannelTest.test_missing_datac             C   s    |   d¡ |  | jjjd¡ d S )Ns   EHLO examples
   250 HELP
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú	test_EHLOC  s    
zSMTPDChannelTest.test_EHLOc             C   s    |   d¡ |  | jjjd¡ d S )Ns   EHLOs   501 Syntax: EHLO hostname
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_EHLO_bad_syntaxG  s    
z%SMTPDChannelTest.test_EHLO_bad_syntaxc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   EHLO examples   503 Duplicate HELO/EHLO
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_EHLO_duplicateL  s    

z$SMTPDChannelTest.test_EHLO_duplicatec             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   EHLO examples   HELO examples   503 Duplicate HELO/EHLO
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_EHLO_HELO_duplicateR  s    

z)SMTPDChannelTest.test_EHLO_HELO_duplicatec             C   s6   t j ¡ }|  d¡ |  | jjjd |¡ d¡¡ d S )Ns   HELO examplez250 {}
Úascii)	r   r   Zgetfqdnr$   r9   r#   rQ   ÚformatÚencode)r
   Únamer   r   r   Ú	test_HELOX  s    

zSMTPDChannelTest.test_HELOc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   EHLO examples   503 Duplicate HELO/EHLO
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_HELO_EHLO_duplicate^  s    

z)SMTPDChannelTest.test_HELO_EHLO_duplicatec             C   s    |   d¡ |  | jjjd¡ d S )Ns   HELPsF   250 Supported commands: EHLO HELO MAIL RCPT DATA RSET NOOP QUIT VRFY
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú	test_HELPd  s    
zSMTPDChannelTest.test_HELPc             C   s    |   d¡ |  | jjjd¡ d S )Ns	   HELP MAILs"   250 Syntax: MAIL FROM: <address>
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_HELP_commandj  s    
z"SMTPDChannelTest.test_HELP_commandc             C   s    |   d¡ |  | jjjd¡ d S )Ns	   HELP SPAMsF   501 Supported commands: EHLO HELO MAIL RCPT DATA RSET NOOP QUIT VRFY
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_HELP_command_unknowno  s    
z*SMTPDChannelTest.test_HELP_command_unknownc             C   s    |   d¡ |  | jjjd¡ d S )Ns   HELOs   501 Syntax: HELO hostname
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_HELO_bad_syntaxu  s    
z%SMTPDChannelTest.test_HELO_bad_syntaxc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   503 Duplicate HELO/EHLO
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_HELO_duplicatez  s    

z$SMTPDChannelTest.test_HELO_duplicatec             C   s0   d| _ |  d¡ |  d¡ |  | jjjd¡ d S )NFs   HELO examples%   MAIL from:<foo@example.com> SIZE=1234s"   501 Syntax: MAIL FROM: <address>
)Zextended_smtpr$   r9   r#   r   rQ   )r
   r   r   r   Ú8test_HELO_parameter_rejected_when_extensions_not_enabled€  s
    

zISMTPDChannelTest.test_HELO_parameter_rejected_when_extensions_not_enabledc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL from:   <foo@example.com>s   250 OK
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú"test_MAIL_allows_space_after_colon‡  s    

z3SMTPDChannelTest.test_MAIL_allows_space_after_colonc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   EHLO examples&   MAIL from:   <foo@example.com> size=20s   250 OK
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú+test_extended_MAIL_allows_space_after_colon  s    

z<SMTPDChannelTest.test_extended_MAIL_allows_space_after_colonc             C   s    |   d¡ |  | jjjd¡ d S )Ns   NOOPs   250 OK
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú	test_NOOP“  s    
zSMTPDChannelTest.test_NOOPc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   NOOPs   250 OK
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_HELO_NOOP—  s    

zSMTPDChannelTest.test_HELO_NOOPc             C   s    |   d¡ |  | jjjd¡ d S )Ns   NOOP his   501 Syntax: NOOP
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_NOOP_bad_syntaxœ  s    
z%SMTPDChannelTest.test_NOOP_bad_syntaxc             C   s    |   d¡ |  | jjjd¡ d S )Ns   QUITs	   221 Bye
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú	test_QUIT¡  s    
zSMTPDChannelTest.test_QUITc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   QUITs	   221 Bye
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_HELO_QUIT¥  s    

zSMTPDChannelTest.test_HELO_QUITc             C   s    |   d¡ |  | jjjd¡ d S )Ns   QUIT bye byes	   221 Bye
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_QUIT_arg_ignoredª  s    
z&SMTPDChannelTest.test_QUIT_arg_ignoredc             C   s(   d| j _|  d¡ |  | j jjd¡ d S )Nz	BAD STATEs   HELO examples   451 Internal confusion
)r#   Z
smtp_stater$   r9   r   rQ   )r
   r   r   r   Útest_bad_state®  s    
zSMTPDChannelTest.test_bad_statec             C   s:   |   d¡ |   dd| jj  d ¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL from: ó   as   @examples   500 Error: line too long
)r$   r#   Úcommand_size_limitr9   r   rQ   )r
   r   r   r   Útest_command_too_long´  s    
z&SMTPDChannelTest.test_command_too_longc             C   sr   |   d¡ | jjtdƒ }|   dd|  d ¡ |  | jjjd¡ |   dd|d   d ¡ |  | jjjd¡ d S )	Ns   EHLO examplezMAIL from:<@example>s   MAIL from:<rw   s   @example> SIZE=1234s   250 OK
é   s   500 Error: line too long
)r$   r#   rx   Úlenr9   r   rQ   )r
   Úfill_lenr   r   r   Ú*test_MAIL_command_limit_extended_with_SIZE¼  s    

z;SMTPDChannelTest.test_MAIL_command_limit_extended_with_SIZEc             C   s2   |   d¡ |   d¡ |  | jjjdd… d¡ d S )Ns   EHLO examples5   MAIL from: <naive@example.com> BODY=8BITMIME SMTPUTF8r   é   ó   5)r$   r9   r#   r   rQ   )r
   r   r   r   Ú-test_MAIL_command_rejects_SMTPUTF8_by_defaultÊ  s    
z>SMTPDChannelTest.test_MAIL_command_rejects_SMTPUTF8_by_defaultc             C   s\   d| j _|  d¡ |  d¡ |  d¡ |  d¡ |  d| j j d ¡ |  | j jjd¡ d S )	Ni  s   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   DATAó   As   A
.s   552 Error: Too much mail data
)r#   Údata_size_limitr$   r9   r   rQ   )r
   r   r   r   Ú-test_data_longer_than_default_data_size_limitÐ  s    



z>SMTPDChannelTest.test_data_longer_than_default_data_size_limitc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   EHLO examples!   MAIL FROM:<eggs@example> SIZE=512s   250 OK
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_MAIL_size_parameterÜ  s    

z)SMTPDChannelTest.test_MAIL_size_parameterc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   EHLO examples%   MAIL FROM:<eggs@example> SIZE=invalids9   501 Syntax: MAIL FROM: <address> [SP <mail-parameters>]
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú test_MAIL_invalid_size_parameterâ  s    

z1SMTPDChannelTest.test_MAIL_invalid_size_parameterc             C   sP   |   d¡ |   d¡ |  | jjjd¡ |   d¡ |   d¡ |  | jjjd¡ d S )Ns   EHLO examples"   MAIL FROM:<eggs@example> ham=greens<   555 MAIL FROM parameters not recognized or not implemented
s   MAIL FROM:<eggs@example>s    RCPT TO:<eggs@example> ham=greens:   555 RCPT TO parameters not recognized or not implemented
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú!test_MAIL_RCPT_unknown_parametersè  s    



z2SMTPDChannelTest.test_MAIL_RCPT_unknown_parametersc             C   s2   d| j _|  d¡ |  d¡ |  | j jjd¡ d S )Ni  s   EHLO examples"   MAIL FROM:<eggs@example> SIZE=2096s<   552 Error: message size exceeds fixed maximum message size
)r#   r‚   r$   r9   r   rQ   )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_limitc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   RCPT to:spam@examples   503 Error: need MAIL command
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_need_MAILú  s    

zSMTPDChannelTest.test_need_MAILc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL from eggs@examples"   501 Syntax: MAIL FROM: <address>
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_MAIL_syntax_HELO   s    

z&SMTPDChannelTest.test_MAIL_syntax_HELOc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   EHLO examples   MAIL from eggs@examples9   501 Syntax: MAIL FROM: <address> [SP <mail-parameters>]
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_MAIL_syntax_EHLO  s    

z&SMTPDChannelTest.test_MAIL_syntax_EHLOc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples
   MAIL from:s"   501 Syntax: MAIL FROM: <address>
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_MAIL_missing_address  s    

z*SMTPDChannelTest.test_MAIL_missing_addressc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL from:<eggs@example>s   250 OK
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_MAIL_chevrons  s    

z#SMTPDChannelTest.test_MAIL_chevronsc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   EHLO examples   MAIL from:<>s   250 OK
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_MAIL_empty_chevrons  s    

z)SMTPDChannelTest.test_MAIL_empty_chevronsc             C   s:   |   d¡ |   d¡ |  | jjjd¡ |  | jjd¡ d S )Ns   EHLO examples%   MAIL from: <"Fred Blogs"@example.com>s   250 OK
z"Fred Blogs"@example.com)r$   r9   r#   r   rQ   r   )r
   r   r   r   Útest_MAIL_quoted_localpart  s    

z+SMTPDChannelTest.test_MAIL_quoted_localpartc             C   s:   |   d¡ |   d¡ |  | jjjd¡ |  | jjd¡ d S )Ns   EHLO examples#   MAIL from: "Fred Blogs"@example.coms   250 OK
z"Fred Blogs"@example.com)r$   r9   r#   r   rQ   r   )r
   r   r   r   Ú$test_MAIL_quoted_localpart_no_angles"  s    

z5SMTPDChannelTest.test_MAIL_quoted_localpart_no_anglesc             C   s:   |   d¡ |   d¡ |  | jjjd¡ |  | jjd¡ d S )Ns   EHLO examples/   MAIL from: <"Fred Blogs"@example.com> SIZE=1000s   250 OK
z"Fred Blogs"@example.com)r$   r9   r#   r   rQ   r   )r
   r   r   r   Ú$test_MAIL_quoted_localpart_with_size(  s    

z5SMTPDChannelTest.test_MAIL_quoted_localpart_with_sizec             C   s:   |   d¡ |   d¡ |  | jjjd¡ |  | jjd¡ d S )Ns   EHLO examples-   MAIL from: "Fred Blogs"@example.com SIZE=1000s   250 OK
z"Fred Blogs"@example.com)r$   r9   r#   r   rQ   r   )r
   r   r   r   Ú.test_MAIL_quoted_localpart_with_size_no_angles.  s    

z?SMTPDChannelTest.test_MAIL_quoted_localpart_with_size_no_anglesc             C   s4   |   d¡ |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL from:eggs@examples   MAIL from:spam@examples    503 Error: nested MAIL command
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_nested_MAIL4  s
    


z!SMTPDChannelTest.test_nested_MAILc             C   s    |   d¡ |  | jjjd¡ d S )Ns   VRFY eggs@examplesD   252 Cannot VRFY user, but will accept message and attempt delivery
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú	test_VRFY;  s    
zSMTPDChannelTest.test_VRFYc             C   s    |   d¡ |  | jjjd¡ d S )Ns   VRFYs   501 Syntax: VRFY <address>
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_VRFY_syntaxA  s    
z!SMTPDChannelTest.test_VRFY_syntaxc             C   s    |   d¡ |  | jjjd¡ d S )Ns   EXPNs   502 EXPN not implemented
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_EXPN_not_implementedF  s    
z*SMTPDChannelTest.test_EXPN_not_implementedc             C   s    |   d¡ |  | jjjd¡ d S )Ns   MAIL from:<foo@example.com>s   503 Error: send HELO first
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_no_HELO_MAILK  s    
z"SMTPDChannelTest.test_no_HELO_MAILc             C   s4   |   d¡ |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL From:eggs@examples   DATAs   503 Error: need RCPT command
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_need_RCPTP  s
    


zSMTPDChannelTest.test_need_RCPTc             C   s4   |   d¡ |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL From: eggs@examples   RCPT to eggs@examples    501 Syntax: RCPT TO: <address>
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_RCPT_syntax_HELOW  s
    


z&SMTPDChannelTest.test_RCPT_syntax_HELOc             C   s4   |   d¡ |   d¡ |   d¡ |  | jjjd¡ d S )Ns   EHLO examples   MAIL From: eggs@examples   RCPT to eggs@examples7   501 Syntax: RCPT TO: <address> [SP <mail-parameters>]
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_RCPT_syntax_EHLO^  s
    


z&SMTPDChannelTest.test_RCPT_syntax_EHLOc             C   s4   |   d¡ |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL From: eggs@examples   RCPT to: <eggs@example>s   250 OK
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_RCPT_lowercase_to_OKe  s    


z*SMTPDChannelTest.test_RCPT_lowercase_to_OKc             C   s    |   d¡ |  | jjjd¡ d S )Ns   RCPT to eggs@examples   503 Error: send HELO first
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_no_HELO_RCPTk  s    
z"SMTPDChannelTest.test_no_HELO_RCPTc             C   sš   |   d¡ |   d¡ |  | jjjd¡ |   d¡ |  | jjjd¡ |   d¡ |  | jjjd¡ |   d¡ |  | jjjd¡ |  | jjdd	d
gdfg¡ d S )Ns   HELO examples   MAIL From:eggs@examples   250 OK
s   RCPT To:spam@examples   DATAs%   354 End data with <CR><LF>.<CR><LF>
s   data
more
.)zpeer-addressz	peer-portzeggs@examplezspam@examplez	data
more)r$   r9   r#   r   rQ   r*   r   )r
   r   r   r   Útest_data_dialogp  s    





z!SMTPDChannelTest.test_data_dialogc             C   s>   |   d¡ |   d¡ |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples	   DATA spams   501 Syntax: DATA
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_DATA_syntax‚  s
    



z!SMTPDChannelTest.test_DATA_syntaxc             C   s    |   d¡ |  | jjjd¡ d S )Ns	   DATA spams   503 Error: send HELO first
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_no_HELO_DATA‰  s    
z"SMTPDChannelTest.test_no_HELO_DATAc             C   sF   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |  | jjd¡ d S )Ns   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   DATAs   ..
.
Ú.)r$   r9   r#   Úreceived_data)r
   r   r   r   Ú$test_data_transparency_section_4_5_2Ž  s    




z5SMTPDChannelTest.test_data_transparency_section_4_5_2c             C   s^   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |  | jjddd	d
gdfg¡ d S )Ns   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   RCPT To:ham@examples   DATAs   data
.)zpeer-addressz	peer-portzeggs@examplezspam@examplezham@exampler   )r$   r9   r*   r   )r
   r   r   r   Útest_multiple_RCPT–  s    






z#SMTPDChannelTest.test_multiple_RCPTc             C   sH   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   DATAs   return status
.s   250 Okish
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_manual_status£  s    




z#SMTPDChannelTest.test_manual_statusc             C   s‚   |   d¡ |   d¡ |   d¡ |   d¡ |  | jjjd¡ |   d¡ |   d¡ |   d¡ |   d	¡ |  | jjd
ddgdfg¡ d S )Ns   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   RSETs   250 OK
s   MAIL From:foo@examples   RCPT To:eggs@examples   DATAs   data
.)zpeer-addressz	peer-portzfoo@examplezeggs@exampler   )r$   r9   r#   r   rQ   r*   r   )r
   r   r   r   Ú	test_RSET¬  s    








zSMTPDChannelTest.test_RSETc             C   s*   |   d¡ |   d¡ |  | jjjd¡ d S )Ns   HELO examples   RSETs   250 OK
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_HELO_RSET¼  s    

zSMTPDChannelTest.test_HELO_RSETc             C   s    |   d¡ |  | jjjd¡ d S )Ns   RSET his   501 Syntax: RSET
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_RSET_syntaxÁ  s    
z!SMTPDChannelTest.test_RSET_syntaxc             C   s    |   d¡ |  | jjjd¡ d S )Ns   UNKNOWN_CMDs1   500 Error: command "UNKNOWN_CMD" not recognized
)r$   r9   r#   r   rQ   )r
   r   r   r   Útest_unknown_commandÅ  s    
z%SMTPDChannelTest.test_unknown_commandc          	   C   sð  t  dtf¡ | jj}W d Q R X t  dtf¡ d| j_W d Q R X t  dtf¡ | jj}W d Q R X t  dtf¡ d| j_W d Q R X t  dtf¡ | jj}W d Q R X t  dtf¡ d| j_W d Q R X t  dtf¡ | jj}W d Q R X t  dtf¡ d| j_W d Q R X t  dtf¡ | jj}W d Q R X t  dtf¡ d| j_W d Q R X t  dtf¡ | jj	}W d Q R X t  dtf¡ d| j_	W d Q R X t  dtf¡ | jj
}W d Q R X t  dtf¡ d| j_
W d Q R X t  dtf¡ | jj}W d Q R X t  dtf¡ d| j_W d Q R X t  dtf¡ | jj}W d Q R X t  dtf¡ d| j_W d Q R X t  dtf¡ | jj}W d Q R X t  dtf¡ d| j_W d Q R X t  dtf¡ | jj}W d Q R X t  dtf¡ d| j_W d Q R X d S )NÚ Úspam)r   Zcheck_warningsÚDeprecationWarningr#   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Ë  sX    z,SMTPDChannelTest.test_attribute_deprecationsN)Fr   r   r   r   r2   r$   rZ   r0   r[   r]   r^   r_   r`   ra   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   ry   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   r   rY     s†   
	rY   zIPv6 not enabledc               @   s   e Zd Zdd„ ZdS )ÚSMTPDChannelIPv6Testc             C   sb   t  t_t_tj| _t ¡  | _t_t	t
jdfddd| _| j ¡ \}}tj| j||dd| _d S )Nr   )r   r   T)r   )r   r   r   r   rL   rM   rN   rO   rP   r   r   rC   r*   r&   r'   r#   )r
   r+   r,   r   r   r   r   û  s    
zSMTPDChannelIPv6Test.setUpN)r   r   r   r   r   r   r   r   r¬   ù  s   r¬   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )Ú!SMTPDChannelWithDataSizeLimitTestc             C   sd   t  t_t_tj| _t ¡  | _t_t	t
jdfddd| _| j ¡ \}}tj| j||ddd| _d S )Nr   )r   r   T)r   é    )r   r   r   r   rL   rM   rN   rO   rP   r   r   r%   r*   r&   r'   r#   )r
   r+   r,   r   r   r   r     s    
z'SMTPDChannelWithDataSizeLimitTest.setUpc             C   s    t  ¡  t t _t_| jt_d S )N)r   r1   r   r   rM   rL   )r
   r   r   r   r2     s    z*SMTPDChannelWithDataSizeLimitTest.tearDownc             C   s   | j j |¡ | j  ¡  d S )N)r#   r   r    r!   )r
   r"   r   r   r   r$     s    z,SMTPDChannelWithDataSizeLimitTest.write_linec             C   sš   |   d¡ |   d¡ |  | jjjd¡ |   d¡ |  | jjjd¡ |   d¡ |  | jjjd¡ |   d¡ |  | jjjd¡ |  | jjdd	d
gdfg¡ d S )Ns   HELO examples   MAIL From:eggs@examples   250 OK
s   RCPT To:spam@examples   DATAs%   354 End data with <CR><LF>.<CR><LF>
s   data
more
.)zpeer-addressz	peer-portzeggs@examplezspam@examplez	data
more)r$   r9   r#   r   rQ   r*   r   )r
   r   r   r   Útest_data_limit_dialog  s    





z8SMTPDChannelWithDataSizeLimitTest.test_data_limit_dialogc             C   s~   |   d¡ |   d¡ |  | jjjd¡ |   d¡ |  | jjjd¡ |   d¡ |  | jjjd¡ |   d¡ |  | jjjd¡ d S )	Ns   HELO examples   MAIL From:eggs@examples   250 OK
s   RCPT To:spam@examples   DATAs%   354 End data with <CR><LF>.<CR><LF>
s'   This message is longer than 32 bytes
.s   552 Error: Too much mail data
)r$   r9   r#   r   rQ   )r
   r   r   r   Ú$test_data_limit_dialog_too_much_data-  s    




zFSMTPDChannelWithDataSizeLimitTest.test_data_limit_dialog_too_much_dataN)r   r   r   r   r2   r$   r¯   r°   r   r   r   r   r­     s
   r­   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚSMTPDChannelWithDecodeDataFalsec             C   sZ   t  t_t_tj| _t ¡  | _t_t	t
jdfdƒ| _| j ¡ \}}t | j||¡| _d S )Nr   )r   r   )r   r   r   r   rL   rM   rN   rO   rP   r   r   r%   r*   r&   r'   r#   )r
   r+   r,   r   r   r   r   >  s    z%SMTPDChannelWithDecodeDataFalse.setUpc             C   s    t  ¡  t t _t_| jt_d S )N)r   r1   r   r   rM   rL   )r
   r   r   r   r2   F  s    z(SMTPDChannelWithDecodeDataFalse.tearDownc             C   s   | j j |¡ | j  ¡  d S )N)r#   r   r    r!   )r
   r"   r   r   r   r$   K  s    z*SMTPDChannelWithDecodeDataFalse.write_linec             C   sP   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |  | jjd¡ d S )Ns   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   DATAs   plain ascii textr4   )r$   r9   r#   r    )r
   r   r   r   Útest_ascii_dataO  s    





z/SMTPDChannelWithDecodeDataFalse.test_ascii_datac             C   sZ   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |  | jjd¡ d S )	Ns   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   DATAs   utf8 enriched text: Å¼ÅºÄ‡s   and some plain asciir4   s/   utf8 enriched text: Å¼ÅºÄ‡
and some plain ascii)r$   r9   r#   r    )r
   r   r   r   Útest_utf8_dataX  s    






z.SMTPDChannelWithDecodeDataFalse.test_utf8_dataN)r   r   r   r   r2   r$   r²   r³   r   r   r   r   r±   <  s
   	r±   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚSMTPDChannelWithDecodeDataTruec             C   sb   t  t_t_tj| _t ¡  | _t_t	t
jdfddd| _| j ¡ \}}tj| j||dd| _d S )Nr   )r   r   T)r   )r   r   r   r   rL   rM   rN   rO   rP   r   r   r%   r*   r&   r'   r#   )r
   r+   r,   r   r   r   r   h  s    
z$SMTPDChannelWithDecodeDataTrue.setUpc             C   s    t  ¡  t t _t_| jt_d S )N)r   r1   r   r   rM   rL   )r
   r   r   r   r2   s  s    z'SMTPDChannelWithDecodeDataTrue.tearDownc             C   s   | j j |¡ | j  ¡  d S )N)r#   r   r    r!   )r
   r"   r   r   r   r$   x  s    z)SMTPDChannelWithDecodeDataTrue.write_linec             C   sP   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |  | jjd¡ d S )Ns   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   DATAs   plain ascii textr4   zplain ascii text)r$   r9   r#   r    )r
   r   r   r   r²   |  s    





z.SMTPDChannelWithDecodeDataTrue.test_ascii_datac             C   sZ   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |  | jjd¡ d S )	Ns   HELO examples   MAIL From:eggs@examples   RCPT To:spam@examples   DATAs   utf8 enriched text: Å¼ÅºÄ‡s   and some plain asciir4   u/   utf8 enriched text: Å¼ÅºÄ‡
and some plain ascii)r$   r9   r#   r    )r
   r   r   r   r³   …  s    






z-SMTPDChannelWithDecodeDataTrue.test_utf8_dataN)r   r   r   r   r2   r$   r²   r³   r   r   r   r   r´   f  s
   	r´   c               @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )Ú&SMTPDChannelTestWithEnableSMTPUTF8Truec             C   sb   t  t_t_tj| _t ¡  | _t_t	t
jdfddd| _| j ¡ \}}tj| j||dd| _d S )Nr   )r   r   T)r.   )r   r   r   r   rL   rM   rN   rO   rP   r   r   r%   r*   r&   r'   r#   )r
   r+   r,   r   r   r   r   “  s    
z,SMTPDChannelTestWithEnableSMTPUTF8True.setUpc             C   s    t  ¡  t t _t_| jt_d S )N)r   r1   r   r   rM   rL   )r
   r   r   r   r2     s    z/SMTPDChannelTestWithEnableSMTPUTF8True.tearDownc             C   s   | j j |¡ | j  ¡  d S )N)r#   r   r    r!   )r
   r"   r   r   r   r$   ¢  s    z1SMTPDChannelTestWithEnableSMTPUTF8True.write_linec             C   s0   |   d¡ |   d d¡¡ |  | jjjd¡ d S )Ns   EHLO exampleu7   MAIL from: <naiÌˆve@example.com> BODY=8BITMIME SMTPUTF8zutf-8s   250 OK
)r$   rd   r9   r#   r   rQ   )r
   r   r   r   Ú1test_MAIL_command_accepts_SMTPUTF8_when_announced¦  s
    
zXSMTPDChannelTestWithEnableSMTPUTF8True.test_MAIL_command_accepts_SMTPUTF8_when_announcedc             C   sÄ   |   d¡ x´dD ]¬}|   d| ¡ |  | jjjdd… d¡ |   d¡ |  | jjjdd… d¡ |   d¡ |  | jjjdd… d	¡ |   d
¡ |dkrª|  | jjjd¡ q|  | jjjd¡ qW d S )Ns   EHLO example)r\   s   BODY=8BITMIME SMTPUTF8s   MAIL from: <a@example> r   é   s   250s   rcpt to:<b@example.com>s   datas   354s   c
.r\   s   250 OK
s   250 SMTPUTF8 message okish
)r$   r9   r#   r   rQ   )r
   Zmail_parametersr   r   r   Útest_process_smtputf8_message®  s    




zDSMTPDChannelTestWithEnableSMTPUTF8True.test_process_smtputf8_messagec             C   sª   |   d¡ |   d d¡¡ |  | jjjdd… d¡ |   d d¡¡ |  | jjjdd… d¡ |   d¡ |  | jjjdd… d	¡ |   d
¡ |   d¡ |  | jjd
¡ d S )Ns   EHLO exampleu2   MAIL From: naiÌˆve@examplÃ© BODY=8BITMIME SMTPUTF8zutf-8r   r·   s   250u   RCPT To:spÃ¤m@examplÃ©s   DATAs   354s   utf8 enriched text: Å¼ÅºÄ‡r4   )r$   rd   r9   r#   r   rQ   r    )r
   r   r   r   r³   ¾  s    



z5SMTPDChannelTestWithEnableSMTPUTF8True.test_utf8_datac             C   sn   |   d¡ dtdƒ }|   dd|d   d ¡ |  | jjjd¡ |   dd|  d ¡ |  | jjjd	¡ d S )
Ns   ehlo examplei$  zmail from:<@example>s   MAIL from:<rw   r~   s	   @example>s   500 Error: line too long
s   250 OK
)r$   r{   r9   r#   r   rQ   )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_SMTPUTF8c             C   sô   |   d¡ dtdƒ }xØdD ]Ð}|   d||  d ¡ |  | jjjdd… d	¡ |   d||  d
 ¡ |  | jjjdd… d¡ |   d¡ |  | jjjdd… d¡ |   d¡ |  | jjjdd… d¡ |   d¡ |  | jjjdd… d¡ qW d S )Ns   ehlo examplei$  zmail from:<@example>)rw   ó   bó   cs   MAIL from:<s
   a@example>r   r·   s   500s	   @example>s   250s   rcpt to:<hans@example.com>s   datas   354s   test
.)r$   r{   r9   r#   r   rQ   )r
   r|   Úcharr   r   r   Ú1test_multiple_emails_with_extended_command_lengthÚ  s    




zXSMTPDChannelTestWithEnableSMTPUTF8True.test_multiple_emails_with_extended_command_lengthN)r   r   r   r   r2   r$   r¶   r¸   r³   r¹   r½   r   r   r   r   rµ   ’  s   
rµ   c               @   s   e Zd Zdd„ ZdS )ÚMiscTestCasec          	   C   s*   ddddddddd	h	}t j| t|d
 d S )NZprogramZDevnullrL   ÚNEWLINEZ
COMMASPACEZDATA_SIZE_DEFAULTÚusageZOptionsZ	parseargs)Ú	blacklist)r   Zcheck__all__r   )r
   rÁ   r   r   r   Útest__all__ë  s    
zMiscTestCase.test__all__N)r   r   r   rÂ   r   r   r   r   r¾   ê  s   r¾   Ú__main__)rH   r:   Ztestr   r   r   rN   r   r   r   r   Ú	Exceptionr   r   ZTestCaser   r3   rB   rK   rU   rY   rI   rJ   r¬   r­   r±   r´   rµ   r¾   r   Úmainr   r   r   r   Ú<module>   s6   "]%B   `7*,X

