a
    	3jC                    @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZm	Z	 G dd deZ
G dd	 d	ZG d
d deeZe	G dd deeZe	G dd deeZG dd deZedkre  dS )    N)_header_value_parser)errorspolicy)TestEmailBaseparameterizec                   @   s   e Zd Zdd ZdS )
TestTokensc                 C   sH   t dd}| |d | t|d | |jd | |jd d S )Nz 	fws )parserZEWWhiteSpaceTerminalassertEqualstrvalue
token_type)selfx r   e/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_email/test__header_value_parser.pytest_EWWhiteSpaceTerminal   s
    z$TestTokens.test_EWWhiteSpaceTerminalN)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   s*   e Zd ZdddZd	ddZd
ddZdS )TestParserMixinNc                 C   sR   |  t|| |  |j| | |j| |  || |d urN|  |j| d S N)r   r   r   assertDefectsEqualall_defectscomments)r   tlreststringr   defects	remainderr   r   r   r   _assert_results   s    zTestParserMixin._assert_resultsc           
   	   C   s(   ||\}}	| j ||	||||d d |S )N)r   r"   )
r   methodsourcer   r   r    r!   r   r   r   r   r   r   _test_get_x   s
    zTestParserMixin._test_get_xc              	   C   s"   ||}|  |d|||d| |S Nr
   r#   )r   r$   inputr   r   r    r   r   r   r   r   _test_parse_x&   s    zTestParserMixin._test_parse_x)N)N)N)r   r   r   r"   r&   r)   r   r   r   r   r      s    

 
 r   c                   @   sF  e Zd ZeedddZejej	 d Z
eed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 Z0dKdL Z1dMdN Z2dOdP Z3dQdR Z4dSdT Z5dUdV Z6dWdX Z7dYdZ Z8d[d\ Z9d]d^ Z:d_d` Z;dadb Z<dcdd Z=dedf Z>dgdh Z?didT Z5djdk Z@dldm ZAdndo ZBdpdq ZCdrds ZDdtdu ZEdvdw ZFdxdy ZGdzd{ ZHd|d} ZId~d ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd Zddd Zedd Zfdd Zgdd Zhdd Zidd Zjdd ZkddÄ Zlddń ZmddǄ ZnddɄ Zodd˄ Zpdd̈́ Zqddτ Zrddф Zsddӄ ZtddՄ Zuddׄ Zvddل Zwddۄ Zxdd݄ Zydd߄ Zzdd Z{dd Z|dd Z}dd Z~dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd 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.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE ZdFdG ZdHdI ZdJdK ZdLdM ZdNdO ZdPdQ ZdRdS ZdTdU ZdVdW ZdXdY ZdZd[ Zd\d] Zd^d_ Zd`da Zdbdc Zddde Zdfdg Zdhdi Zdjdk Zdldm Zdndo Zdpdq ZÐdrds ZĐdtdu ZŐdvdw ZƐdxdy Zǐdz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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ڐ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
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"d0d1 Z#d2d3 Z$d4d5 Z%d6d7 Z&d8d9 Z'd:d; Z(d<d= Z)d>d? Z*d@dA Z+dBdC Z,dDdE Z-dFdG Z.dHdI Z/dJdK Z0dLdM Z1dNdO Z2dPdQ Z3dRdS Z4dTdU Z5dVdW Z6dXdY Z7dZd[ Z8d\d] Z9d^d_ Z:d`da Z;dbdc Z<ddde Z=dfdg Z>dhdi Z?djdk Z@dldm ZAdnS (o  
TestParser!      asciiz!#$%&'*+-/=?^_`{}|~r
   z\[]c                 C   s   |  tdddg d S )Nfoo   r   r   Z_wsp_splitterr   r   r   r   test__wsp_splitter_one_word6   s    z&TestParser.test__wsp_splitter_one_wordc                 C   s   |  tddg d d S )Nzfoo defr/   )r.    defr0   r1   r   r   r   test__wsp_splitter_two_words9   s    z'TestParser.test__wsp_splitter_two_wordsc                 C   s   |  tddg d d S )Nzfoo 	 def jikr/   )r.    	 zdef jikr0   r1   r   r   r   test__wsp_splitter_ws_runs=   s    z%TestParser.test__wsp_splitter_ws_runsc                 C   s(   |  tjdddg d}| |jd d S )Nz 	  r3   r
   r	   )r&   r   get_fwsr   r   )r   r	   r   r   r   test_get_fws_onlyD   s    zTestParser.test_get_fws_onlyc                 C   s   |  tjdddg d d S )N foor3   r.   r&   r   r8   r1   r   r   r   test_get_fws_spaceH   s    zTestParser.test_get_fws_spacec                 C   s   |  tjdddg d d S )Nz 	 foo r6   r3   foo r;   r1   r   r   r   test_get_fws_ws_runK   s    zTestParser.test_get_fws_ws_runc                 C   s:   |  tj td W d    n1 s,0    Y  d S )NabcassertRaisesr   HeaderParseErrorr   get_encoded_wordr1   r   r   r   *test_get_encoded_word_missing_start_raisesP   s    z5TestParser.test_get_encoded_word_missing_start_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz=?abcr@   r1   r   r   r   (test_get_encoded_word_missing_end_raisesT   s    z3TestParser.test_get_encoded_word_missing_end_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz=?abc?=r@   r1   r   r   r   +test_get_encoded_word_missing_middle_raisesX   s    z6TestParser.test_get_encoded_word_missing_middle_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz=?utf-8?X?somevalue?=r@   r1   r   r   r   !test_get_encoded_word_invalid_cte\   s    z,TestParser.test_get_encoded_word_invalid_ctec                 C   s   |  tjdddg d d S )Nz#=?us-ascii?q?this_is_a_test?=  birdthis is a test  birdr&   r   rC   r1   r   r   r   test_get_encoded_word_valid_ew`   s    z)TestParser.test_get_encoded_word_valid_ewc                 C   s   |  tjdddtjgd d S )Nz#=?us-ascii?q?this is a test?=  birdrH   rI   r&   r   rC   r   InvalidHeaderDefectr1   r   r   r   %test_get_encoded_word_internal_spacesh   s    z0TestParser.test_get_encoded_word_internal_spacesc                 C   s   |  tjdddg d d S )Nz(=?us-ascii?q?first?=  =?utf-8?q?second?=firstz  =?utf-8?q?second?=rJ   r1   r   r   r    test_get_encoded_word_gets_firstp   s    z+TestParser.test_get_encoded_word_gets_firstc                 C   s   |  tjdddtjgd d S )Nz&=?us-ascii?q?first?==?utf-8?q?second?=rO   z=?utf-8?q?second?=rL   r1   r   r   r   1test_get_encoded_word_gets_first_even_if_no_spacex   s    z<TestParser.test_get_encoded_word_gets_first_even_if_no_spacec                 C   s6   |  tjdddg d}| |jd | |jd d S )Nz =?us-ascii*jive?q?first_second?=first secondr
   us-asciiZjiver&   r   rC   r   charsetlangr   Zewr   r   r   +test_get_encoded_word_sets_extra_attributes   s    z6TestParser.test_get_encoded_word_sets_extra_attributesc                 C   s6   |  tjdddg d}| |jd | |jd d S )Nz=?us-ascii?q?first_second?=rR   r
   rS   rT   rW   r   r   r   +test_get_encoded_word_lang_default_is_blank   s    z6TestParser.test_get_encoded_word_lang_default_is_blankc                 C   s   |  tjdddtjgd d S )Nz=?us-ascii?q?firstsecond?=zfirstsecondr
   )r&   r   rC   r   NonPrintableDefectr1   r   r   r   *test_get_encoded_word_non_printable_defect   s    z5TestParser.test_get_encoded_word_non_printable_defectc                 C   s   |  tjdddg d d S )Nz=?us-ascii?q?=20foo?=r:   r
   rJ   r1   r   r   r   ,test_get_encoded_word_leading_internal_space   s    z7TestParser.test_get_encoded_word_leading_internal_spacec                 C   s   |  tjdddg d d S )Nz=?utf-8?q?=C3=89ric?=   Éricr
   rJ   r1   r   r   r   3test_get_encoded_word_quopri_utf_escape_follows_cte   s    z>TestParser.test_get_encoded_word_quopri_utf_escape_follows_ctec                 C   s   t |}|dfS r'   )r   get_unstructured)r   r   tokenr   r   r   	_get_unst   s    
zTestParser._get_unstc                 C   s   |  | jdddg d d S r'   r&   ra   r1   r   r   r   test_get_unstructured_null   s    z%TestParser.test_get_unstructured_nullc                 C   s   |  | jdddg d d S Nr.   r
   rb   r1   r   r   r   test_get_unstructured_one_word   s    z)TestParser.test_get_unstructured_one_wordc                 C   s   |  | jdddg d d S )Nfoo bar birdr
   rb   r1   r   r   r   #test_get_unstructured_normal_phrase   s    
z.TestParser.test_get_unstructured_normal_phrasec                 C   s   |  | jdddg d d S )Nzfoo 	 bar      birdrf   r
   rb   r1   r   r   r   3test_get_unstructured_normal_phrase_with_whitespace   s    
z>TestParser.test_get_unstructured_normal_phrase_with_whitespacec                 C   s   |  | jdddg d d S )Nz	  foo barz foo barr
   rb   r1   r   r   r   (test_get_unstructured_leading_whitespace   s    
z3TestParser.test_get_unstructured_leading_whitespacec                 C   s   |  | jdddg d d S )N	foo bar  zfoo bar r
   rb   r1   r   r   r   )test_get_unstructured_trailing_whitespace   s    
z4TestParser.test_get_unstructured_trailing_whitespacec                 C   s   |  | jdddg d d S )Nz  foo bar  z	 foo bar r
   rb   r1   r   r   r   5test_get_unstructured_leading_and_trailing_whitespace   s    
z@TestParser.test_get_unstructured_leading_and_trailing_whitespacec                 C   s   |  | jdddg d d S )Nz=?us-ascii?q?bar?=barr
   rb   r1   r   r   r   (test_get_unstructured_one_valid_ew_no_ws   s    
z3TestParser.test_get_unstructured_one_valid_ew_no_wsc                 C   s   |  | jdddg d d S )Nz=?us-ascii?q?bar?=  bar  bar r
   rb   r1   r   r   r   (test_get_unstructured_one_ew_trailing_ws   s    
z3TestParser.test_get_unstructured_one_ew_trailing_wsc                 C   s   |  | jdddg d d S )Nz=?us-ascii?q?bar?= birdzbar birdr
   rb   r1   r   r   r   0test_get_unstructured_one_valid_ew_trailing_text   s    
z;TestParser.test_get_unstructured_one_valid_ew_trailing_textc                 C   s   |  | jdddg d d S )Nzfoo =?us-ascii?q?bar?= birdrf   r
   rb   r1   r   r   r   6test_get_unstructured_phrase_with_ew_in_middle_of_text   s    
zATestParser.test_get_unstructured_phrase_with_ew_in_middle_of_textc                 C   s   |  | jdddg d d S )Nz*foo =?us-ascii?q?bar?= =?us-ascii?q?bird?=foo barbirdr
   rb   r1   r   r   r   (test_get_unstructured_phrase_with_two_ew   s    z3TestParser.test_get_unstructured_phrase_with_two_ewc                 C   s   |  | jdddg d d S )Nz-foo =?us-ascii?q?bar?= =?us-ascii?q?bird?=   zfoo barbird   zfoo barbird r
   rb   r1   r   r   r   4test_get_unstructured_phrase_with_two_ew_trailing_ws   s    z?TestParser.test_get_unstructured_phrase_with_two_ew_trailing_wsc                 C   s   |  | jdddg d d S )Nz  =?us-ascii?q?bar?=z  bar barr
   rb   r1   r   r   r   4test_get_unstructured_phrase_with_ew_with_leading_ws  s    z?TestParser.test_get_unstructured_phrase_with_ew_with_leading_wsc                 C   s   |  | jdddg d d S )Nz-foo =?us-ascii?q?bar?= 	  =?us-ascii?q?bird?=rt   r
   rb   r1   r   r   r   1test_get_unstructured_phrase_with_two_ew_extra_ws  s    z<TestParser.test_get_unstructured_phrase_with_two_ew_extra_wsc                 C   s   |  | jdddg d d S )Nz-=?us-ascii?q?test?=   =?us-ascii?q?foo?=  valztestfoo  valztestfoo valr
   rb   r1   r   r   r   3test_get_unstructured_two_ew_extra_ws_trailing_text  s    z>TestParser.test_get_unstructured_two_ew_extra_ws_trailing_textc                 C   s   |  | jdddg d d S )Nz=?iso-8859-1?q?hello=20world?=zhello worldr
   rb   r1   r   r   r   )test_get_unstructured_ew_with_internal_ws   s    z4TestParser.test_get_unstructured_ew_with_internal_wsc                 C   s   |  | jdddg d d S )Nz6   =?us-ascii?q?=20test?=   =?us-ascii?q?=20foo?=  valz    test foo  valz  test foo valr
   rb   r1   r   r   r   1test_get_unstructured_ew_with_internal_leading_ws(  s    z<TestParser.test_get_unstructured_ew_with_internal_leading_wsc                 C   s   |  | jdddg d d S )Nz
=?test valr
   rb   r1   r   r   r    test_get_unstructured_invalid_ew0  s    z+TestParser.test_get_unstructured_invalid_ewc                 C   s&   |  | jdddddtjgd d S )Ns   test foo  valr-   surrogateescapeu   test foo  valu   test foo valr
   r&   ra   decoder   ZUndecodableBytesDefectr1   r   r   r   'test_get_unstructured_undecodable_bytes8  s    
z2TestParser.test_get_unstructured_undecodable_bytesc                 C   s*   |  | jdddddtjgd d d S )Ns4   =?us-ascii?q?=20test?=   =?us-ascii?q?=20foo?=  valr-   r~   u    test foo  valu    test foo val   r
   r   r1   r   r   r   -test_get_unstructured_undecodable_bytes_in_EW@  s    
z8TestParser.test_get_unstructured_undecodable_bytes_in_EWc                 C   s   |  | jdddtjgd d S )Nz=?utf-8?b?dmk?=vir
   )r&   ra   r   InvalidBase64PaddingDefectr1   r   r   r   ,test_get_unstructured_missing_base64_paddingI  s    z7TestParser.test_get_unstructured_missing_base64_paddingc                 C   s   |  | jdddtjgd d S )Nz=?utf-8?b?dmk===?=r   r
   )r&   ra   r   InvalidBase64CharactersDefectr1   r   r   r   .test_get_unstructured_invalid_base64_characterQ  s    z9TestParser.test_get_unstructured_invalid_base64_characterc                 C   s"   |  | jdddtjtjgd d S )Nz=?utf-8?b?dmk?=r   r
   )r&   ra   r   r   r   r1   r   r   r   >test_get_unstructured_invalid_base64_character_and_bad_paddingY  s    zITestParser.test_get_unstructured_invalid_base64_character_and_bad_paddingc                 C   s   |  | jdddtjgd d S )Nz=?utf-8?b?abcde?=Zabcder
   )r&   ra   r   ZInvalidBase64LengthDefectr1   r   r   r   +test_get_unstructured_invalid_base64_lengthb  s    z6TestParser.test_get_unstructured_invalid_base64_lengthc                 C   s"   |  | jdddtjtjgd d S )Nz=?utf-8?q?foo?==?utf-8?q?bar?=foobarr
   r&   ra   r   rM   r1   r   r   r   /test_get_unstructured_no_whitespace_between_ewsk  s    z:TestParser.test_get_unstructured_no_whitespace_between_ewsc                 C   s   |  | jdddtjgd d S )Nz!nowhitespace=?utf-8?q?somevalue?=Znowhitespacesomevaluer
   r   r1   r   r   r   3test_get_unstructured_ew_without_leading_whitespacet  s    z>TestParser.test_get_unstructured_ew_without_leading_whitespacec                 C   s   |  | jdddtjgd d S )Nz!=?utf-8?q?somevalue?=nowhitespaceZsomevaluenowhitespacer
   r   r1   r   r   r   4test_get_unstructured_ew_without_trailing_whitespace}  s    z?TestParser.test_get_unstructured_ew_without_trailing_whitespacec                 C   s   |  | jdddtjgd d S )Nz=?utf-8?q?somevalue?=aaZsomevalueaar
   r   r1   r   r   r   ;test_get_unstructured_without_trailing_whitespace_hang_case  s    zFTestParser.test_get_unstructured_without_trailing_whitespace_hang_casec                 C   s   |  | jdddg d d S )Nz=?utf-8?q?=somevalue?=r
   rb   r1   r   r   r   r}     s    c                 C   s   |  | jdddg d d S )Nz=?utf-8?X?=somevalue?=r
   rb   r1   r   r   r   $test_get_unstructured_invalid_ew_cte  s    z/TestParser.test_get_unstructured_invalid_ew_ctec                 C   s(   |  tjdddg d}| |jd d S )Nr   r3   r
   ptext)r&   r   get_qp_ctextr   r   r   r   r   r   r   test_get_qp_ctext_only  s    
z!TestParser.test_get_qp_ctext_onlyc                 C   sB   | j dd}|dd}|dd}| tj|| j dg d}d S )	N\\\(z\()z\)r3   r
   )rfc_printable_asciireplacer&   r   r   r   Zwith_qpr   r   r   r    test_get_qp_ctext_all_printables  s    z+TestParser.test_get_qp_ctext_all_printablesc                 C   s   |  tjdddg d d S )Nfoo der.   r3    der&   r   r   r1   r   r   r   &test_get_qp_ctext_two_words_gets_first  s    
z1TestParser.test_get_qp_ctext_two_words_gets_firstc                 C   s   |  tjdddg d d S )Nfoo 		der.   r3    		der   r1   r   r   r   )test_get_qp_ctext_following_wsp_preserved  s    
z4TestParser.test_get_qp_ctext_following_wsp_preservedc                 C   s   |  tjdddg d d S )Nzfoo)r.   r3   r   r   r1   r   r   r   (test_get_qp_ctext_up_to_close_paren_only  s    
z3TestParser.test_get_qp_ctext_up_to_close_paren_onlyc                 C   s   |  tjdddg d d S )Nzfoo  )r.   r3   z  )r   r1   r   r   r   2test_get_qp_ctext_wsp_before_close_paren_preserved  s    
z=TestParser.test_get_qp_ctext_wsp_before_close_paren_preservedc                 C   s   |  tjdddg d d S )Nzfoo)barr.   r3   z)barr   r1   r   r   r   &test_get_qp_ctext_close_paren_mid_word  s    
z1TestParser.test_get_qp_ctext_close_paren_mid_wordc                 C   s   |  tjdddg d d S )Nzfoo(r.   r3   r   r   r1   r   r   r   'test_get_qp_ctext_up_to_open_paren_only  s    
z2TestParser.test_get_qp_ctext_up_to_open_paren_onlyc                 C   s   |  tjdddg d d S )Nzfoo  (r.   r3   z  (r   r1   r   r   r   1test_get_qp_ctext_wsp_before_open_paren_preserved  s    
z<TestParser.test_get_qp_ctext_wsp_before_open_paren_preservedc                 C   s   |  tjdddg d d S )Nzfoo(barr.   r3   z(barr   r1   r   r   r   %test_get_qp_ctext_open_paren_mid_word  s    
z0TestParser.test_get_qp_ctext_open_paren_mid_wordc                 C   s6   |  tjdddtjgd}| |jd jd d d S )Nzfoo bar)foo barr3   r   r    )r&   r   r   r   rZ   r   r    non_printablesr   r   r   r    test_get_qp_ctext_non_printables  s
    z+TestParser.test_get_qp_ctext_non_printablesc                 C   s(   |  tjdddg d}| |jd d S Nr   r
   r   )r&   r   get_qcontentr   r   r   r   r   r   test_get_qcontent_only  s    
z!TestParser.test_get_qcontent_onlyc                 C   s8   | j dd}|dd}| tj|| j | j g d}d S )Nr   r   "z\"r
   )r   r   r&   r   r   r   r   r   r    test_get_qcontent_all_printables  s    
z+TestParser.test_get_qcontent_all_printablesc                 C   s   |  tjdddg d d S )Nr   r.   r   r&   r   r   r1   r   r   r   &test_get_qcontent_two_words_gets_first  s    
z1TestParser.test_get_qcontent_two_words_gets_firstc                 C   s   |  tjdddg d d S )Nr   r.   r   r   r1   r   r   r   )test_get_qcontent_following_wsp_preserved  s    
z4TestParser.test_get_qcontent_following_wsp_preservedc                 C   s   |  tjdddg d d S )Nfoo"r.   r   r   r1   r   r   r   #test_get_qcontent_up_to_dquote_only  s    
z.TestParser.test_get_qcontent_up_to_dquote_onlyc                 C   s   |  tjdddg d d S )Nzfoo  "r.   z  "r   r1   r   r   r   2test_get_qcontent_wsp_before_close_paren_preserved  s    
z=TestParser.test_get_qcontent_wsp_before_close_paren_preservedc                 C   s   |  tjdddg d d S )Nzfoo"barr.   z"barr   r1   r   r   r   &test_get_qcontent_close_paren_mid_word  s    
z1TestParser.test_get_qcontent_close_paren_mid_wordc                 C   s6   |  tjdddtjgd}| |jd jd d d S )Nzfoo fg"zfoo fgr   r   r   )r&   r   r   r   rZ   r   r    r   r   r   r   r    test_get_qcontent_non_printables  s
    z+TestParser.test_get_qcontent_non_printablesc                 C   s(   |  tjdddg d}| |jd d S )Nr   r
   atext)r&   r   	get_atextr   r   r   r   r   r   r   test_get_atext_only  s    
zTestParser.test_get_atext_onlyc                 C   s    |  tj| j| j| jg d}d S r'   )r&   r   r   rfc_atext_charsr   r   r   r   test_get_atext_all_atext  s    z#TestParser.test_get_atext_all_atextc                 C   s   |  tjdddg d d S Nfoo barr.   rw   r&   r   r   r1   r   r   r   #test_get_atext_two_words_gets_first  s    
z.TestParser.test_get_atext_two_words_gets_firstc                 C   s   |  tjdddg d d S Nz	foo 		barr.   z 		barr   r1   r   r   r   &test_get_atext_following_wsp_preserved
  s    
z1TestParser.test_get_atext_following_wsp_preservedc                 C   s   |  tjdddg d d S Nzfoo@barr.   z@barr   r1   r   r   r   test_get_atext_up_to_special  s    
z'TestParser.test_get_atext_up_to_specialc                 C   s6   |  tjdddtjgd}| |jd jd d d S )Nzfoo bar(r   r   r   r   )r&   r   r   r   rZ   r   r    r   r   r   r   r   test_get_atext_non_printables  s
    z(TestParser.test_get_atext_non_printablesc                 C   s(   |  tjdddg d}| |jd d S )N"foo"r.   r
   bare-quoted-string)r&   r   get_bare_quoted_stringr   r   )r   Zbqsr   r   r    test_get_bare_quoted_string_only  s    
z+TestParser.test_get_bare_quoted_string_onlyc                 C   sp   |  tj td W d    n1 s,0    Y  |  tj td W d    n1 sb0    Y  d S )Nr   z  "foo")rA   r   rB   r   r   r1   r   r   r   2test_get_bare_quoted_string_must_start_with_dquote  s    (z=TestParser.test_get_bare_quoted_string_must_start_with_dquotec                 C   s   |  tjdddg d d S N""r
   r&   r   r   r1   r   r   r   'test_get_bare_quoted_string_only_quotes%  s    
z2TestParser.test_get_bare_quoted_string_only_quotesc                 C   s   |  tjdddtjgd d S )Nr   r   r
   r&   r   r   r   rM   r1   r   r   r   -test_get_bare_quoted_string_missing_endquotes)  s    z8TestParser.test_get_bare_quoted_string_missing_endquotesc                 C   s   |  tjdddg d d S )Nz
"foo"	 barr   r.   z	 barr   r1   r   r   r   3test_get_bare_quoted_string_following_wsp_preserved-  s    
z>TestParser.test_get_bare_quoted_string_following_wsp_preservedc                 C   s   |  tjdddg d d S )Nz"foo bar moo"zfoo bar moor
   r   r1   r   r   r   *test_get_bare_quoted_string_multiple_words1  s    
z5TestParser.test_get_bare_quoted_string_multiple_wordsc                 C   s   |  tjdddg d d S )Nz" foo  moo	"z
 foo  moo	r
   r   r1   r   r   r   8test_get_bare_quoted_string_multiple_words_wsp_preserved5  s    
zCTestParser.test_get_bare_quoted_string_multiple_words_wsp_preservedc                 C   s   |  tjdddg d d S )Nz"foo"barr   r.   rm   r   r1   r   r   r   /test_get_bare_quoted_string_end_dquote_mid_word9  s    
z:TestParser.test_get_bare_quoted_string_end_dquote_mid_wordc                 C   s   |  tjdddg d d S )Nz
"foo\"in"az	"foo\"in"zfoo"inar   r1   r   r   r   )test_get_bare_quoted_string_quoted_dquote=  s    
z4TestParser.test_get_bare_quoted_string_quoted_dquotec                 C   s   |  tjdddtjgd d S )Nz"aa"zaar
   )r&   r   r   r   rZ   r1   r   r   r   *test_get_bare_quoted_string_non_printablesA  s    z5TestParser.test_get_bare_quoted_string_non_printablesc                 C   s8   |  tjdddtjgd |  tjdddtjgd d S )Nz"foor   r.   r
   z"foo z"foo "r=   r   r1   r   r   r   )test_get_bare_quoted_string_no_end_dquoteF  s    z4TestParser.test_get_bare_quoted_string_no_end_dquotec                 C   s   |  tjdddg d d S r   r   r1   r   r   r   (test_get_bare_quoted_string_empty_quotesN  s    
z3TestParser.test_get_bare_quoted_string_empty_quotesc                 C   s"   |  tjdddtjtjgd d S )Nz"=?utf-8?Q?not_really_valid?="z"not really valid"znot really validr
   r   r1   r   r   r   test_encoded_word_inside_quotesS  s    z*TestParser.test_encoded_word_inside_quotesc              	   C   s,   |  tjdddg ddg}| |jd d S )N	(comment)r3   r
   comment)r&   r   get_commentr   r   r   r   r   r   r   test_get_comment_only^  s    z TestParser.test_get_comment_onlyc                 C   sp   |  tj td W d    n1 s,0    Y  |  tj td W d    n1 sb0    Y  d S )Nr   z  (foo")rA   r   rB   r   r   r1   r   r   r   &test_get_comment_must_start_with_parenc  s    (z1TestParser.test_get_comment_must_start_with_parenc              	   C   s   |  tjdddg ddg d S )Nz(comment)  	r   r3     	r   r&   r   r   r1   r   r   r   (test_get_comment_following_wsp_preservedi  s    z3TestParser.test_get_comment_following_wsp_preservedc              	   C   s   |  tjdddg ddg d S )Nz(foo bar)  		(foo bar)r3   r   r   r   r1   r   r   r   test_get_comment_multiple_wordsm  s    z*TestParser.test_get_comment_multiple_wordsc              	   C   s   |  tjdddg ddg d S )Nz( foo  bar	 )  	z( foo  bar	 )r3   r   z foo  bar	 r   r1   r   r   r   -test_get_comment_multiple_words_wsp_preservedq  s    
z8TestParser.test_get_comment_multiple_words_wsp_preservedc              	   C   s   |  tjdddg ddg d S )Nz(foo)bar(foo)r3   rm   r.   r   r1   r   r   r   #test_get_comment_end_paren_mid_wordv  s    z.TestParser.test_get_comment_end_paren_mid_wordc              	   C   s   |  tjdddg ddg d S )Nz(foo\) \(\)bar)r3   r
   z
foo) ()barr   r1   r   r   r   test_get_comment_quoted_parensz  s    z)TestParser.test_get_comment_quoted_parensc              	   C   s"   |  tjdddtjgddg d S )Nz	(foobar)r3   r
   zfoobar)r&   r   r   r   rZ   r1   r   r   r   test_get_comment_non_printable~  s    z)TestParser.test_get_comment_non_printablec              	   C   s@   |  tjdddtjgddg |  tjdddtjgddg d S )	Nz(foo barr   r3   r
   r   z
(foo bar  z(foo bar  )rj   r&   r   r   r   rM   r1   r   r   r   test_get_comment_no_end_paren  s    z(TestParser.test_get_comment_no_end_parenc              	   C   s0   |  tjdddg ddg}| |d jd d S )Nz
(foo(bar))r3   r
   zfoo(bar)r/   rm   r&   r   r   r   contentr   r   r   r   test_get_comment_nested_comment  s    z*TestParser.test_get_comment_nested_commentc              	   C   s0   |  tjdddg ddg}| |d jd d S )Nz(foo ( bar ) )r3   r
   zfoo ( bar ) r    bar r   r   r   r   r   #test_get_comment_nested_comment_wsp  s    z.TestParser.test_get_comment_nested_comment_wspc              	   C   s   |  tjdddg ddg d S )Nz()r3   r
   r   r1   r   r   r   test_get_comment_empty_comment  s    z)TestParser.test_get_comment_empty_commentc              	   C   sp   |  tjdddg ddg}tdddD ]6}| |d jd|d	  d
 d|d	    |d }q&| |jd
 d S )N(((((foo)))))r3   r
   ((((foo))))   r   r   r/   r.   r   )r&   r   r   ranger   r   )r   r   ir   r   r   !test_get_comment_multiple_nesting  s    *
z,TestParser.test_get_comment_multiple_nestingc              	   C   s&   |  tjdddtjgd ddg d S )Nz(((((foo)))r   r3   r   r
   r   r   r1   r   r   r   'test_get_comment_missing_end_of_nesting  s    z2TestParser.test_get_comment_missing_end_of_nestingc              	   C   s0   |  tjdddg ddg}| |d jd d S )Nz(foo (b\)))r3   r
   z	foo (b\))r   zb)r   r   r   r   r   %test_get_comment_qs_in_nested_comment  s    z0TestParser.test_get_comment_qs_in_nested_commentc              	   C   s*   |  tjdddg dg }| |jd d S )Nz  	 	r3   r
   cfws)r&   r   get_cfwsr   r   r   r  r   r   r   test_get_cfws_only_ws  s    z TestParser.test_get_cfws_only_wsc              	   C   s0   |  tjdddg ddg}| |d jd d S )Nr   r3   r
   r.   r   r&   r   r  r   r   r  r   r   r   test_get_cfws_only_comment  s    z%TestParser.test_get_cfws_only_commentc              
   C   sD   |  tjdddg dddg}| |d jd | |d jd d S )Nz (foo )  ( bar) r3   r
   r=   rw   r/      r  r  r   r   r   test_get_cfws_only_mixed  s    
z#TestParser.test_get_cfws_only_mixedc              	   C   s0   |  tjdddg ddg}| |d jd d S )Nz	(foo) bar(foo) r3   rm   r.   r   r  r  r   r   r    test_get_cfws_ends_at_non_leader  s    z+TestParser.test_get_cfws_ends_at_non_leaderc              	   C   s0   |  tjdddg ddg}| |d jd d S )Nz(foo) r	  r3   r.   r   r  r  r   r   r   #test_get_cfws_ends_at_non_printable  s    z.TestParser.test_get_cfws_ends_at_non_printablec              	   C   s4   |  tjdddtjgddg}| |d jd d S )Nz(foo ) "test"z(foo ) r3   z"test"zfoo r   )r&   r   r  r   rZ   r   r   r  r   r   r   &test_get_cfws_non_printable_in_comment  s
    z1TestParser.test_get_cfws_non_printable_in_commentc              	   C   s4   |  tjdddtjgddg}| |d jd d S )Nz  (foo z  (foo )r3   r
   r=   r/   )r&   r   r  r   rM   r   r   r  r   r   r   $test_get_cfws_header_ends_in_comment  s
    z/TestParser.test_get_cfws_header_ends_in_commentc              
   C   sH   |  tjdddg dddg}| |d jdg | |d jdg d S )Nz(foo (bar)) ((a)(a))r3   r
   z	foo (bar)z(a)(a)r   r   )r&   r   r  r   r   r  r   r   r   &test_get_cfws_multiple_nested_comments  s    z1TestParser.test_get_cfws_multiple_nested_commentsc                 C   sD   |  tjdddg d}| |jd | |jd | |jd d S )Nz"bob"bobr
   quoted-string)r&   r   get_quoted_stringr   r   quoted_valuer   r   qsr   r   r   test_get_quoted_string_only  s    
z&TestParser.test_get_quoted_string_onlyc                 C   s6   |  tjdddg d}| |jd | |jd d S )Nz		 "bob"   bob r
    "bob" r  )r&   r   r  r   r  r   r  r   r   r   test_get_quoted_string_with_wsp  s
    
z*TestParser.test_get_quoted_string_with_wspc                 C   sb   |  tjdddg d}| |d d jd | |d d jd | |jd	 | |jd
 d S )Nz (foo) "bob"(bar)r  r
   r   r/   r.   r   rm   r  r  r&   r   r  r   r   r  r  r   r   r   ,test_get_quoted_string_with_comments_and_wsp  s    
z7TestParser.test_get_quoted_string_with_comments_and_wspc                 C   s`   |  tjdddg d}| |d jddg | |d jdg | |jd	 | |jd
 d S )Nz (foo) (bar) "bob"(bird)r  r
   r   r.   rm   r   birdr  r  r&   r   r  r   r   r   r  r  r   r   r   -test_get_quoted_string_with_multiple_comments  s    z8TestParser.test_get_quoted_string_with_multiple_commentsc                 C   sN   |  tjdddtjgd}| |d jdg | |jd | |jd d S )Nz
 (
) "bob" bobr
   r   
r   "bob"	r&   r   r  r   rZ   r   r   r   r  r  r   r   r   /test_get_quoted_string_non_printable_in_comment  s    z:TestParser.test_get_quoted_string_non_printable_in_commentc                 C   sN   |  tjdddtjgd}| |d jdg | |jd | |jd d S )Nz	 (a) "a" ar
   r   r   zaz "a"r"  r  r   r   r   0test_get_quoted_string_non_printable_in_qcontent  s    z;TestParser.test_get_quoted_string_non_printable_in_qcontentc                 C   sJ   |  tjdddg d}| |d jdg | |jd | |jd d S )Nz (a) "foo  bar "z
 foo  bar r
   r   r   z	foo  bar z "foo  bar "r  r  r   r   r   "test_get_quoted_string_internal_ws  s    z-TestParser.test_get_quoted_string_internal_wsc                 C   sb   |  tjdddtjgd}| |d jdg | |d jdg | |jd | |jd	 d S )
Nz (a) "bob" (az (a) "bob" (a)r  r
   r   r   r   r  r  	r&   r   r  r   rM   r   r   r   r  r  r   r   r   -test_get_quoted_string_header_ends_in_comment  s    z8TestParser.test_get_quoted_string_header_ends_in_commentc                 C   sN   |  tjdddtjgd}| |d jdg | |jd | |jd d S )	Nz	 (a) "bobz
 (a) "bob"r  r
   r   r   r  r!  r'  r  r   r   r   .test_get_quoted_string_header_ends_in_qcontent  s    z9TestParser.test_get_quoted_string_header_ends_in_qcontentc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz	 (ab) xyz)rA   r   rB   r   r  r1   r   r   r   'test_get_quoted_string_no_quoted_string$  s    z2TestParser.test_get_quoted_string_no_quoted_stringc                 C   s6   |  tjdddg d}| |jd | |jd d S )Nz	 "bob" feez	 "bob" r  Zfeer  r  r  r  r   r   r   )test_get_quoted_string_qs_ends_at_noncfws(  s
    
z4TestParser.test_get_quoted_string_qs_ends_at_noncfwsc                 C   s(   |  tjdddg d}| |jd d S )Nr  r
   atom)r&   r   get_atomr   r   r   r,  r   r   r   test_get_atom_only0  s    
zTestParser.test_get_atom_onlyc                 C   s   |  tjdddg d d S )Nz	 bob  r  r
   r&   r   r-  r1   r   r   r   test_get_atom_with_wsp5  s    
z!TestParser.test_get_atom_with_wspc                 C   sF   |  tjdddg d}| |d d jd | |d d jd d S )	Nz (foo) bob(bar)r  r
   r   r/   r.   r   rm   )r&   r   r-  r   r   r.  r   r   r   #test_get_atom_with_comments_and_wsp9  s
    
z.TestParser.test_get_atom_with_comments_and_wspc                 C   sD   |  tjdddg d}| |d jddg | |d jdg d S )	Nz (foo) (bar) bob(bird)r  r
   r   r.   rm   r   r  r&   r   r-  r   r   r.  r   r   r   $test_get_atom_with_multiple_comments?  s    z/TestParser.test_get_atom_with_multiple_commentsc                 C   s2   |  tjdddtjgd}| |d jdg d S )Nz (
) bobr  r
   r   r   r&   r   r-  r   rZ   r   r   r.  r   r   r   &test_get_atom_non_printable_in_commentF  s
    z1TestParser.test_get_atom_non_printable_in_commentc                 C   s2   |  tjdddtjgd}| |d jdg d S )Nz (a) ar$  r
   r   r   r5  r.  r   r   r   $test_get_atom_non_printable_in_atextL  s
    z/TestParser.test_get_atom_non_printable_in_atextc                 C   sF   |  tjdddtjgd}| |d jdg | |d jdg d S )Nz (a) bob (az (a) bob (a)r  r
   r   r   r   )r&   r   r-  r   rM   r   r   r.  r   r   r   $test_get_atom_header_ends_in_commentR  s    z/TestParser.test_get_atom_header_ends_in_commentc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz (ab) rA   r   rB   r   r-  r1   r   r   r   test_get_atom_no_atomY  s    z TestParser.test_get_atom_no_atomc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz (ab) @r9  r1   r   r   r   $test_get_atom_no_atom_before_special]  s    z/TestParser.test_get_atom_no_atom_before_specialc                 C   sB   |  tjdddg d}| |d jdg | |d jdg d S )	Nz (foo) bob(bar)  @bangz (foo) bob(bar)  r  z@bangr   r.   r   rm   r3  r.  r   r   r   "test_get_atom_atom_ends_at_speciala  s
    
z-TestParser.test_get_atom_atom_ends_at_specialc                 C   s   |  tjdddg d d S )Nz	bob  fredzbob  zbob Zfredr0  r1   r   r   r   "test_get_atom_atom_ends_at_noncfwsg  s    
z-TestParser.test_get_atom_atom_ends_at_noncfwsc                 C   s   |  tjdddg d d S Nz=?utf-8?q?=20bob?=r  r
   r0  r1   r   r   r   test_get_atom_rfc2047_atomk  s    
z%TestParser.test_get_atom_rfc2047_atomc                 C   s8   |  tjdddg d}| |jd | t|d d S )Nzfoo.bar.bangr
   zdot-atom-text   )r&   r   get_dot_atom_textr   r   lenr   Zdot_atom_textr   r   r   test_get_dot_atom_textq  s
    
z!TestParser.test_get_dot_atom_textc                 C   s   |  tjdddg d}d S rd   r&   r   rA  rC  r   r   r   )test_get_dot_atom_text_lone_atom_is_validw  s    
z4TestParser.test_get_dot_atom_text_lone_atom_is_validc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz.foo.barrA   r   rB   r   rA  r1   r   r   r   ,test_get_dot_atom_text_raises_on_leading_dot{  s    z7TestParser.test_get_dot_atom_text_raises_on_leading_dotc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nzfoo.bar.rG  r1   r   r   r   -test_get_dot_atom_text_raises_on_trailing_dot  s    z8TestParser.test_get_dot_atom_text_raises_on_trailing_dotc                 C   s   |  tj td W d    n1 s,0    Y  |  tj td W d    n1 sb0    Y  |  tj td W d    n1 s0    Y  d S )Nz foo.barz@foo.barz	"foo.bar"rG  r1   r   r   r   2test_get_dot_atom_text_raises_on_leading_non_atext  s    ((z=TestParser.test_get_dot_atom_text_raises_on_leading_non_atextc                 C   s   |  tjdddg d}d S r   rE  rC  r   r   r   .test_get_dot_atom_text_trailing_text_preserved  s    
z9TestParser.test_get_dot_atom_text_trailing_text_preservedc                 C   s   |  tjdddg d}d S )Nzfoo .barr.   z .barrE  rC  r   r   r   ,test_get_dot_atom_text_trailing_ws_preserved  s    
z7TestParser.test_get_dot_atom_text_trailing_ws_preservedc                 C   s8   |  tjdddg d}| |jd | t|d d S )Nzfoo.bar.bingr
   zdot-atomr/   )r&   r   get_dot_atomr   r   rB  )r   Zdot_atomr   r   r   test_get_dot_atom_only  s
    
z!TestParser.test_get_dot_atom_onlyc                 C   s   |  tjdddg d d S )Nz	  foo.bar.bing   foo.bar.bing r
   r&   r   rM  r1   r   r   r   test_get_dot_atom_with_wsp  s    
z%TestParser.test_get_dot_atom_with_wspc                 C   s   |  tjdddg d d S )Nz (sing)  foo.bar.bing (here) rO  r
   rP  r1   r   r   r   'test_get_dot_atom_with_comments_and_wsp  s    z2TestParser.test_get_dot_atom_with_comments_and_wspc                 C   s   |  tjdddg d d S )Nz (sing)  foo.bar .bing (here) z (sing)  foo.bar z	 foo.bar z.bing (here) rP  r1   r   r   r   %test_get_dot_atom_space_ends_dot_atom  s    z0TestParser.test_get_dot_atom_space_ends_dot_atomc                 C   s:   |  tj td W d    n1 s,0    Y  d S Nz (foo) rA   r   rB   r   rM  r1   r   r   r    test_get_dot_atom_no_atom_raises  s    z+TestParser.test_get_dot_atom_no_atom_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz (foo) .barrU  r1   r   r   r   $test_get_dot_atom_leading_dot_raises  s    z/TestParser.test_get_dot_atom_leading_dot_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz	bar..bangrU  r1   r   r   r   !test_get_dot_atom_two_dots_raises  s    z,TestParser.test_get_dot_atom_two_dots_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz (foo) bar.bang. foorU  r1   r   r   r   %test_get_dot_atom_trailing_dot_raises  s    z0TestParser.test_get_dot_atom_trailing_dot_raisesc                 C   s   |  tjdddg d d S r>  rP  r1   r   r   r   test_get_dot_atom_rfc2047_atom  s    
z)TestParser.test_get_dot_atom_rfc2047_atomc                 C   s:   |  tjdddg d}| |jd | |d jd d S )Nz (foo) bar (bang) :ahz (foo) bar (bang) r   z:ahr,  r   r  )r&   r   get_wordr   r   r   Zwordr   r   r   test_get_word_atom_yields_atom  s
    
z)TestParser.test_get_word_atom_yields_atomc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz(Recipients list suppressed)rA   r   rB   r   r[  r1   r   r   r   test_get_word_all_CFWS  s    z!TestParser.test_get_word_all_CFWSc                 C   sZ   |  tjdddg d}| |jd | |d jd | |d jd | |jd d S )	Nz"bar " (bang) ahz"bar " (bang) ro   Zahr  r   r   rp   )r&   r   r[  r   r   r   r   r\  r   r   r   test_get_word_qs_yields_qs  s    
z%TestParser.test_get_word_qs_yields_qsc                 C   s   |  tjdddg d d S )Nzfoo.r.   .)r&   r   r[  r1   r   r   r   test_get_word_ends_at_dot  s    
z$TestParser.test_get_word_ends_at_dotc                 C   s(   |  tjdddg d}| |jd d S )N""Fred A. Johnson" is his name, oh."Fred A. Johnson" is his nameFred A. Johnson is his name, oh.phrase)r&   r   
get_phraser   r   r   rf  r   r   r   test_get_phrase_simple  s    z!TestParser.test_get_phrase_simplec                 C   sJ   |  tjdddg d}| |d d jdg | |d d jdg d S )	N. (A) bird (in (my|your)) "hand  " is messy	<>	+ (A) bird (in (my|your)) "hand  " is messy	z bird hand   is messy <>	r   Ar   in (my|your))r&   r   rg  r   r   rh  r   r   r   test_get_phrase_complex  s    z"TestParser.test_get_phrase_complexc                 C   sF   |  tjdddtjgd d}| t|d | |d jdg d S )NFred A.(weird).O JohnsonFred A. .O Johnsonr  r
      weirdr&   r   rg  r   ObsoleteHeaderDefectr   rB  r   rh  r   r   r   test_get_phrase_obsolete  s    
z#TestParser.test_get_phrase_obsoletec              	   C   sN   |  tjdddtjgtjgd  d}| t|d | |d jdg d S )N(even weirder).namez .namer   r
   r  r   even weirder)	r&   r   rg  r   rM   ru  r   rB  r   rh  r   r   r   +test_get_phrase_pharse_must_start_with_word  s    z6TestParser.test_get_phrase_pharse_must_start_with_wordc                 C   sF   |  tjdddtjgd d}| t|d | |d jdg d S )	N)simple phrase.(with trailing comment):boo%simple phrase.(with trailing comment)zsimple phrase. r   :boor   r  with trailing commentrt  rh  r   r   r   $test_get_phrase_ending_with_obsolete   s    
z/TestParser.test_get_phrase_ending_with_obsoletec                 C   s:   |  tj td W d    n1 s,0    Y  d S rT  )rA   r   rB   r   rg  r1   r   r   r   get_phrase_cfws_only_raises
  s    z&TestParser.get_phrase_cfws_only_raisesc                 C   s6   |  tjdddg d}| |jd | |jd d S )Nzdinsdale@python.orgdinsdale@python.org
local-partr&   r   get_local_partr   r   
local_partr   r  r   r   r   test_get_local_part_simple  s
    
z%TestParser.test_get_local_part_simplec                 C   s(   |  tjdddg d}| |jd d S )NzFred.A.Johnson@python.orgFred.A.Johnsonr  r&   r   r  r   r  r  r   r   r   test_get_local_part_with_dot  s    z'TestParser.test_get_local_part_with_dotc                 C   s(   |  tjdddg d}| |jd d S )Nz Fred.A.Johnson  @python.orgz Fred.A.Johnson   Fred.A.Johnson r  r  r  r  r   r   r   #test_get_local_part_with_whitespace  s    z.TestParser.test_get_local_part_with_whitespacec                 C   sX   |  tjdddg d}| |jd | |d d jdg | |d d jd	g d S )
Nz/ (foo) Fred.A.Johnson (bar (bird))  @python.orgz$ (foo) Fred.A.Johnson (bar (bird))  r  r  r  r   r.   r   
bar (bird)r&   r   r  r   r  r   r  r   r   r   test_get_local_part_with_cfws(  s    z(TestParser.test_get_local_part_with_cfwsc                 C   s6   |  tjdddg d}| |jd | |jd d S )Nz"dinsdale"@python.orgz
"dinsdale"r  r  r  r  r  r   r   r   !test_get_local_part_simple_quoted3  s
    
z,TestParser.test_get_local_part_simple_quotedc                 C   s(   |  tjdddg d}| |jd d S )Nz"Fred.A.Johnson"@python.orgz"Fred.A.Johnson"r  r  r  r  r   r   r   #test_get_local_part_with_quoted_dot9  s    z.TestParser.test_get_local_part_with_quoted_dotc                 C   s(   |  tjdddg d}| |jd d S )Nz "Fred A. Johnson"  @python.orgz "Fred A. Johnson"  z "Fred A. Johnson" r  zFred A. Johnsonr  r  r   r   r   *test_get_local_part_quoted_with_whitespaceB  s    z5TestParser.test_get_local_part_quoted_with_whitespacec                 C   sX   |  tjdddg d}| |jd | |d d jdg | |d d jd	g d S )
Nz4 (foo) " Fred A. Johnson " (bar (bird))  @python.orgz) (foo) " Fred A. Johnson " (bar (bird))  z " Fred A. Johnson " r  z Fred A. Johnson r   r.   r   r  r  r  r   r   r   $test_get_local_part_quoted_with_cfwsK  s    z/TestParser.test_get_local_part_quoted_with_cfwsc                 C   s,   |  tjdddtjgd}| |jd d S )NzFred. A.Johnson@python.orgzFred. A.Johnsonr  r  r&   r   r  r   ru  r   r  r  r   r   r   #test_get_local_part_simple_obsoleteW  s    z.TestParser.test_get_local_part_simple_obsoletec                 C   s,   |  tjdddtjgd}| |jd d S )NzA (foo )Fred (bar).(bird) A.(sheep)Johnson."and  dogs "@python.orgz6 (foo )Fred (bar).(bird) A.(sheep)Johnson."and  dogs "z Fred . A. Johnson.and  dogs r  zFred.A.Johnson.and  dogs r  r  r   r   r   &test_get_local_part_complex_obsolete_1`  s    z1TestParser.test_get_local_part_complex_obsolete_1c                 C   s0   |  tjdddtjgd d}| |jd d S )Nz@ (foo )Fred (bar).(bird) A.(sheep)Johnson "and  dogs"@python.orgz5 (foo )Fred (bar).(bird) A.(sheep)Johnson "and  dogs"z Fred . A. Johnson and  dogsr   r  zFred.A.Johnson and  dogsr&   r   r  r   rM   r   r  r  r   r   r   ,test_get_local_part_complex_obsolete_invalidi  s    
z7TestParser.test_get_local_part_complex_obsolete_invalidc                 C   s:   |  tj td W d    n1 s,0    Y  d S rT  rA   r   rB   r   r  r1   r   r   r   "test_get_local_part_no_part_raisesr  s    z-TestParser.test_get_local_part_no_part_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz (foo) @python.orgr  r1   r   r   r   *test_get_local_part_special_instead_raisesv  s    z5TestParser.test_get_local_part_special_instead_raisesc                 C   s0   |  tjdddtjgd d}| |jd d S )Nz borris.@python.orgz borris.r   r  borris.r  r  r   r   r    test_get_local_part_trailing_dotz  s    
z+TestParser.test_get_local_part_trailing_dotc                 C   s0   |  tjdddtjgd d}| |jd d S )Nz borris. @python.orgz	 borris. r   r  r  r  r  r   r   r   (test_get_local_part_trailing_dot_with_ws  s    
z3TestParser.test_get_local_part_trailing_dot_with_wsc                 C   s0   |  tjdddtjgd d}| |jd d S )Nz.borris@python.org.borrisr   r  r  r  r   r   r   test_get_local_part_leading_dot  s    
z*TestParser.test_get_local_part_leading_dotc                 C   s0   |  tjdddtjgd d}| |jd d S )Nz .borris@python.orgz .borrisr   r  r  r  r  r   r   r   (test_get_local_part_leading_dot_after_ws  s    
z3TestParser.test_get_local_part_leading_dot_after_wsc                 C   s0   |  tjdddtjgd d}| |jd d S )Nz  borris.(foo).natasha@python.orgz borris.(foo).natashaz borris. .natashar   r  zborris..natashar  r  r   r   r   %test_get_local_part_double_dot_raises  s    
z0TestParser.test_get_local_part_double_dot_raisesc                 C   s0   |  tjdddtjgd d}| |jd d S )N""example" example"@example.comz""example" example"example exampler  @example.comr  r  r   r   r   /test_get_local_part_quoted_strings_in_atom_list  s    
z:TestParser.test_get_local_part_quoted_strings_in_atom_listc                 C   s0   |  tjdddtjgd d}| |jd d S )Nz#"\\"example\\" example"@example.comz"\\"example\\" example"z\example\\ exampler@  r  r  r  r   r   r   5test_get_local_part_valid_and_invalid_qp_in_atom_list  s    
z@TestParser.test_get_local_part_valid_and_invalid_qp_in_atom_listc                 C   s,   |  tjdddtjgd}| |jd d S )Nu   exámple@example.comu   exámpler  )r&   r   r  r   ZNonASCIILocalPartDefectr   r  r  r   r   r   "test_get_local_part_unicode_defect  s    z-TestParser.test_get_local_part_unicode_defectc                 C   s(   |  tjdddg d}| |jd d S r   )r&   r   	get_dtextr   r   r   Zdtextr   r   r   test_get_dtext_only  s    
zTestParser.test_get_dtext_onlyc                 C   s    |  tj| j| j| jg d}d S r'   )r&   r   r  rfc_dtext_charsr  r   r   r   test_get_dtext_all_dtext  s    z#TestParser.test_get_dtext_all_dtextc                 C   s   |  tjdddg d d S r   r&   r   r  r1   r   r   r   #test_get_dtext_two_words_gets_first  s    
z.TestParser.test_get_dtext_two_words_gets_firstc                 C   s   |  tjdddg d d S r   r  r1   r   r   r   &test_get_dtext_following_wsp_preserved  s    
z1TestParser.test_get_dtext_following_wsp_preservedc                 C   s6   |  tjdddtjgd}| |jd jd d d S )Nzfoo bar]r   ]r   r   )r&   r   r  r   rZ   r   r    r   r  r   r   r   test_get_dtext_non_printables  s
    z(TestParser.test_get_dtext_non_printablesc                 C   s   |  tjdddtjgd}d S )Nzfoo\]\[\\bar\b\e\l\lzfoo][\barbellr
   )r&   r   r  r   ru  r   r   r   r   test_get_dtext_with_qp  s    z!TestParser.test_get_dtext_with_qpc                 C   s   |  tjdddg d d S )Nzfoo]r.   r  r  r1   r   r   r   'test_get_dtext_up_to_close_bracket_only  s    
z2TestParser.test_get_dtext_up_to_close_bracket_onlyc                 C   s   |  tjdddg d d S )Nzfoo  ]r.   z  ]r  r1   r   r   r   1test_get_dtext_wsp_before_close_bracket_preserved  s    
z<TestParser.test_get_dtext_wsp_before_close_bracket_preservedc                 C   s   |  tjdddg d d S )Nzfoo]barr.   z]barr  r1   r   r   r   %test_get_dtext_close_bracket_mid_word  s    
z0TestParser.test_get_dtext_close_bracket_mid_wordc                 C   s   |  tjdddg d d S )Nzfoo[r.   [r  r1   r   r   r   &test_get_dtext_up_to_open_bracket_only  s    
z1TestParser.test_get_dtext_up_to_open_bracket_onlyc                 C   s   |  tjdddg d d S )Nzfoo  [r.   z  [r  r1   r   r   r   0test_get_dtext_wsp_before_open_bracket_preserved  s    
z;TestParser.test_get_dtext_wsp_before_open_bracket_preservedc                 C   s   |  tjdddg d d S )Nzfoo[barr.   z[barr  r1   r   r   r   $test_get_dtext_open_bracket_mid_word  s    
z/TestParser.test_get_dtext_open_bracket_mid_wordc                 C   sH   |  tjdddg d }}| |jd | |jd | |jd d S )N[127.0.0.1]r
   zdomain-literal	127.0.0.1)r&   r   get_domain_literalr   r   domainipr   Zdomain_literalr   r   r   test_get_domain_literal_only   s    z'TestParser.test_get_domain_literal_onlyc                 C   s6   |  tjdddg d}| |jd | |jd d S )Nz[  127.0.0.1	 ]z[ 127.0.0.1 ]r
   r  r  r&   r   r  r   r  r  r  r   r   r   (test_get_domain_literal_with_internal_ws  s    z3TestParser.test_get_domain_literal_with_internal_wsc                 C   s6   |  tjdddg d}| |jd | |jd d S )Nz(foo)[  127.0.0.1] (bar)z [ 127.0.0.1] r
   r  r  r  r  r   r   r   -test_get_domain_literal_with_surrounding_cfws  s    z8TestParser.test_get_domain_literal_with_surrounding_cfwsc                 C   s:   |  tj td W d    n1 s,0    Y  d S Nr	  rA   r   rB   r   r  r1   r   r   r   ,test_get_domain_literal_no_start_char_raises  s    z7TestParser.test_get_domain_literal_no_start_char_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz(foo) @r  r1   r   r   r   ;test_get_domain_literal_no_start_char_before_special_raises#  s    zFTestParser.test_get_domain_literal_no_start_char_before_special_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz(foo) [abc[@r  r1   r   r   r   <test_get_domain_literal_bad_dtext_char_before_special_raises'  s    zGTestParser.test_get_domain_literal_bad_dtext_char_before_special_raisesc                 C   s6   |  tjdddg d}| |jd | |jd d S )Nexample.comr
   r  r&   r   
get_domainr   r   r  r   r  r   r   r   #test_get_domain_regular_domain_only-  s    z.TestParser.test_get_domain_regular_domain_onlyc                 C   s6   |  tjdddg d}| |jd | |jd d S )Nr  r
   r  r  r  r   r   r   #test_get_domain_domain_literal_only7  s    z.TestParser.test_get_domain_domain_literal_onlyc                 C   s(   |  tjdddg d}| |jd d S )Nz(foo) example.com(bar)	 example.com r
   r  r&   r   r  r   r  r  r   r   r   test_get_domain_with_cfwsA  s    z$TestParser.test_get_domain_with_cfwsc                 C   s(   |  tjdddg d}| |jd d S )N(foo)[127.0.0.1]	(bar) [127.0.0.1] r
   r  r  r  r   r   r   (test_get_domain_domain_literal_with_cfwsJ  s    z3TestParser.test_get_domain_domain_literal_with_cfwsc                 C   s(   |  tjdddg d}| |jd d S )Nz(foo)example.com	(bar), nextz(foo)example.com	(bar)r  , nextr  r  r  r   r   r   0test_get_domain_domain_with_cfws_ends_at_specialS  s    z;TestParser.test_get_domain_domain_with_cfws_ends_at_specialc                 C   s(   |  tjdddg d}| |jd d S )Nz(foo)[127.0.0.1]	(bar), nextr  r  r  r  r  r  r   r   r   8test_get_domain_domain_literal_with_cfws_ends_at_special\  s    zCTestParser.test_get_domain_domain_literal_with_cfws_ends_at_specialc                 C   s,   |  tjdddtjgd}| |jd d S )Nz(foo) example . (bird)com(bar)	z example . com r
   r  )r&   r   r  r   ru  r   r  r  r   r   r   test_get_domain_obsoletee  s    z#TestParser.test_get_domain_obsoletec                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz  (foo)	rA   r   rB   r   r  r1   r   r   r   "test_get_domain_no_non_cfws_raisesn  s    z-TestParser.test_get_domain_no_non_cfws_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz  (foo)	, brokenr  r1   r   r   r   test_get_domain_no_atom_raisesr  s    z)TestParser.test_get_domain_no_atom_raisesc                 C   sR   |  tjdddg d}| |jd | |jd | |jd | |jd d S )Ndinsdale@example.comr
   z	addr-specr  r  )r&   r   get_addr_specr   r   r  r  	addr_specr   r  r   r   r   test_get_addr_spec_normaly  s    z$TestParser.test_get_addr_spec_normalc                 C   sD   |  tjdddg d}| |jd | |jd | |jd d S )Nzdinsdale@[127.0.0.1]r
   r  r  r&   r   r  r   r  r  r  r  r   r   r   &test_get_addr_spec_with_doamin_literal  s    z1TestParser.test_get_addr_spec_with_doamin_literalc                 C   sD   |  tjdddg d}| |jd | |jd | |jd d S )Nz-(foo) dinsdale(bar)@ (bird) example.com (bog)z dinsdale@example.com r
   r  r  r  r  r  r   r   r   test_get_addr_spec_with_cfws  s    z'TestParser.test_get_addr_spec_with_cfwsc                 C   sD   |  tjdddg d}| |jd | |jd | |jd d S )Nz0(foo) "roy a bug"(bar)@ (bird) example.com (bog) "roy a bug"@example.com r
   	roy a bugr  "roy a bug"@example.comr  r  r   r   r   /test_get_addr_spec_with_qouoted_string_and_cfws  s    z:TestParser.test_get_addr_spec_with_qouoted_string_and_cfwsc                 C   sD   |  tjdddg d}| |jd | |jd | |jd d S )Nz7(foo) "roy a bug"(bar)@ (bird) example.com (bog) , nextz1(foo) "roy a bug"(bar)@ (bird) example.com (bog) r  r  r  r  r  r  r  r   r   r   "test_get_addr_spec_ends_at_special  s    z-TestParser.test_get_addr_spec_ends_at_specialc                 C   sL   |  tjdddtjgd d}| |jd | |jd | |jd d S Nr  example example@example.comr  r
   r  r  "example example"@example.com)	r&   r   r  r   rM   r   r  r  r  r  r   r   r   .test_get_addr_spec_quoted_strings_in_atom_list  s    
z9TestParser.test_get_addr_spec_quoted_strings_in_atom_listc                 C   sD   |  tjdddg d}| |jd | |jd | |jd d S )Nzstar.a.star@example.comr
   zstar.a.starr  r  r  r   r   r   test_get_addr_spec_dot_atom  s    z&TestParser.test_get_addr_spec_dot_atomc                 C   s   |  tj td W d    n1 s,0    Y  |  tj td W d    n1 sb0    Y  |  tj td W d    n1 s0    Y  d S )Nzstar@a.star@example.comzstar@a@example.comzstar@172.17.0.1@example.com)rA   r   rB   r   r  r1   r   r   r   #test_get_addr_spec_multiple_domains  s    ((z.TestParser.test_get_addr_spec_multiple_domainsc                 C   s:   |  tjdddg d}| |jd | |jddg d S )Nz@example.com, @two.example.com:r
   	obs-router  two.example.com)r&   r   get_obs_router   r   domainsr   Z	obs_router   r   r   test_get_obs_route_simple  s    z$TestParser.test_get_obs_route_simplec                 C   s>   |  tjdddtjgd}| |jd | |jddg d S )Nz?(foo),, (blue)@example.com (bar),@two.(foo) example.com (bird):z% ,, @example.com ,@two. example.com :r
   r  r  r  )r&   r   r  r   ru  r   r   r  r  r   r   r   test_get_obs_route_complex  s    z%TestParser.test_get_obs_route_complexc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz(foo) @example.com,rA   r   rB   r   r  r1   r   r   r   -test_get_obs_route_no_route_before_end_raises  s    z8TestParser.test_get_obs_route_no_route_before_end_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz(foo) [abc],r  r1   r   r   r   1test_get_obs_route_no_route_before_special_raises  s    z<TestParser.test_get_obs_route_no_route_before_special_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz(foo) @example.com [abc],r  r1   r   r   r   2test_get_obs_route_no_route_before_special_raises2  s    z=TestParser.test_get_obs_route_no_route_before_special_raises2c                 C   s^   |  tjdddg d}| |jd | |jd | |jd | |j | |j	d d S )N<dinsdale@example.com>r
   
angle-addrr  r  r  
r&   r   get_angle_addrr   r   r  r  assertIsNonerouter  r   Z
angle_addrr   r   r   test_get_angle_addr_simple  s    z%TestParser.test_get_angle_addr_simplec                 C   s^   |  tjdddtjgd}| |jd | |j | |j	 | |j
 | |jd d S )N<>r
   r  )r&   r   r  r   rM   r   r   r  r  r  r   r  r  r   r   r   test_get_angle_addr_empty  s    z$TestParser.test_get_angle_addr_emptyc                 C   s^   |  tjdddg d}| |jd | |jd | |jd | |j | |j	d d S )Nz<""@example.com>r
   r  r  z""@example.comr  r  r   r   r   "test_get_angle_addr_qs_only_quotes  s    z-TestParser.test_get_angle_addr_qs_only_quotesc                 C   s^   |  tjdddg d}| |jd | |jd | |jd | |j | |j	d d S )Nz" (foo) <dinsdale@example.com>(bar)z <dinsdale@example.com> r
   r  r  r  r  r  r  r   r   r   test_get_angle_addr_with_cfws  s    z(TestParser.test_get_angle_addr_with_cfwsc                 C   sP   |  tjdddg d}| |jd | |jd | |j | |jd d S )Nz<"Fred Perfect"@[127.0.0.1]>r
   zFred Perfectr  z"Fred Perfect"@[127.0.0.1]	r&   r   r  r   r  r  r  r   r  r  r   r   r   )test_get_angle_addr_qs_and_domain_literal)  s    z4TestParser.test_get_angle_addr_qs_and_domain_literalc                 C   sP   |  tjdddg d}| |jd | |jd | |j | |jd d S )Nz!<(foo) dinsdale@example.com(bar)>z< dinsdale@example.com >r
   r  r  r  r  r  r   r   r   !test_get_angle_addr_internal_cfws5  s    z,TestParser.test_get_angle_addr_internal_cfwsc                 C   sZ   |  tjdddtjgd}| |jd | |jd | |jddg | |j	d d S )NzI(foo)<@example.com, (bird) @two.example.com: dinsdale@example.com> (bar) z8 <@example.com, @two.example.com: dinsdale@example.com> r
   r  r  r  r  )
r&   r   r  r   ru  r   r  r  r   r  r  r   r   r   test_get_angle_addr_obs_routeA  s    z(TestParser.test_get_angle_addr_obs_routec                 C   sT   |  tjdddtjgd}| |jd | |jd | |j	 | |j
d d S )Nz<dinsdale@example.comr  r
   r  r  r  r&   r   r  r   rM   r   r  r  r  r   r  r  r   r   r   )test_get_angle_addr_missing_closing_angleM  s    z4TestParser.test_get_angle_addr_missing_closing_anglec                 C   sT   |  tjdddtjgd}| |jd | |jd | |j	 | |j
d d S )Nz<dinsdale@example.com (foo)z<dinsdale@example.com (foo)>z<dinsdale@example.com >r
   r  r  r  r  r  r   r   r   3test_get_angle_addr_missing_closing_angle_with_cfwsY  s    z>TestParser.test_get_angle_addr_missing_closing_angle_with_cfwsc                 C   sP   |  tjdddg d}| |jd | |jd | |j | |jd d S )Nz"<dinsdale@example.com> (foo), nextz<dinsdale@example.com> (foo)z<dinsdale@example.com> r  r  r  r  r  r  r   r   r   #test_get_angle_addr_ends_at_speciale  s    z.TestParser.test_get_angle_addr_ends_at_specialc                 C   s:   |  tj td W d    n1 s,0    Y  d S r  rA   r   rB   r   r  r1   r   r   r   "test_get_angle_addr_no_angle_raiseq  s    z-TestParser.test_get_angle_addr_no_angle_raisec                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz(foo) , nextr  r1   r   r   r   2test_get_angle_addr_no_angle_before_special_raisesu  s    z=TestParser.test_get_angle_addr_no_angle_before_special_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nrm   r  r1   r   r   r   #test_get_angle_addr_no_angle_raisesy  s    z.TestParser.test_get_angle_addr_no_angle_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz(foo) <, barr  r1   r   r   r   .test_get_angle_addr_special_after_angle_raises}  s    z9TestParser.test_get_angle_addr_special_after_angle_raisesc                 C   s6   |  tjdddg d}| |jd | |jd d S )NzFred A Johnsonr
   display-namer&   r   get_display_namer   r   display_namer   r  r   r   r   test_get_display_name_simple  s    z'TestParser.test_get_display_name_simplec                 C   s6   |  tjdddg d}| |jd | |jd d S )Nrb  rc  z"Fred A. Johnson is his name"re  r  rd  r  r  r   r   r   test_get_display_name_complex1  s    z)TestParser.test_get_display_name_complex1c                 C   sX   |  tjdddg d}| |d d jdg | |d d jdg | |jd	 d S )
Nrj  rk  z "bird hand   is messy" rl  r   rm  r   rn  zbird hand   is messy)r&   r   r  r   r   r  r  r   r   r   test_get_display_name_complex2  s    z)TestParser.test_get_display_name_complex2c                 C   sT   |  tjdddtjgd d}| t|d | |d jdg | |jd d S )Nrp  z"Fred A. .O Johnson"r  r
   rr  rs  rq  	r&   r   r  r   ru  r   rB  r   r  r  r   r   r   test_get_display_name_obsolete  s    
z)TestParser.test_get_display_name_obsoletec              	   C   s\   |  tjdddtjgtjgd  d}| t|d | |d jdg | |j	d d S )	Nrw  z ".name"r   r
   r  r   rx  z.name)
r&   r   r  r   rM   ru  r   rB  r   r  r  r   r   r   1test_get_display_name_pharse_must_start_with_word  s    z<TestParser.test_get_display_name_pharse_must_start_with_wordc                 C   sT   |  tjdddtjgd d}| t|d | |d jdg | |jd	 d S )
Nrz  r{  z"simple phrase." r   r|  r   r  r}  zsimple phrase.r  r  r   r   r   *test_get_display_name_ending_with_obsolete  s    
z5TestParser.test_get_display_name_ending_with_obsoletec                 C   s,   |  tjdddtjgd}| |jd d S )Nz:Foo r
   )r&   r   r  r   rM   r   r   r  r   r   r   /test_get_display_name_for_invalid_address_field  s
    z:TestParser.test_get_display_name_for_invalid_address_fieldc                 C   sj   |  tjdddg d}| |jd | |j | |jd | |jd | |j	 | |j
d d S )Nr  r
   	name-addrr  r  r  )r&   r   get_name_addrr   r   r  r  r  r  r   r  r   Z	name_addrr   r   r   "test_get_name_addr_angle_addr_only  s    z-TestParser.test_get_name_addr_angle_addr_onlyc                 C   sl   |  tjdddg d}| |jd | |jd | |jd | |jd | |j	 | |j
d d S )NzDinsdale <dinsdale@example.com>r
   r!  Dinsdaler  r  r  )r&   r   r"  r   r   r  r  r  r  r   r  r#  r   r   r   test_get_name_addr_atom_name  s    z'TestParser.test_get_name_addr_atom_namec                 C   s^   |  tjdddg d}| |jd | |jd | |jd | |j | |j	d d S )Nz2(foo) Dinsdale (bar) <dinsdale@example.com> (bird)z! Dinsdale <dinsdale@example.com> r
   r%  r  r  r  
r&   r   r"  r   r  r  r  r  r   r  r#  r   r   r   &test_get_name_addr_atom_name_with_cfws  s    z1TestParser.test_get_name_addr_atom_name_with_cfwsc                 C   sf   |  tjdddtjgd d}| |jd | |jd | |jd | 	|j
 | |jd d S )	Nz4(foo) Roy.A.Bear (bar) <dinsdale@example.com> (bird)z% "Roy.A.Bear" <dinsdale@example.com> r   r
   
Roy.A.Bearr  r  r  )r&   r   r"  r   ru  r   r  r  r  r  r   r  r#  r   r   r   *test_get_name_addr_name_with_cfws_and_dots  s    
z5TestParser.test_get_name_addr_name_with_cfws_and_dotsc                 C   s^   |  tjdddg d}| |jd | |jd | |jd | |j | |j	d d S )N#"Roy.A.Bear" <dinsdale@example.com>r
   r)  r  r  r  r'  r#  r   r   r   test_get_name_addr_qs_name  s    z%TestParser.test_get_name_addr_qs_namec                 C   sf   |  tjdddtjgd}| |jd | |jd | |jd | |j	dg | |j
d d S )Nz5"Roy.A.Bear" <@two.example.com: dinsdale@example.com>r
   r)  r  r  r  r  )r&   r   r"  r   ru  r   r  r  r  r   r  r#  r   r   r   test_get_name_addr_with_route  s    z(TestParser.test_get_name_addr_with_routec                 C   s^   |  tjdddg d}| |jd | |jd | |jd | |j | |j	d d S )Nz)"Roy.A.Bear" <dinsdale@example.com>, nextr+  r  r)  r  r  r  r'  r#  r   r   r   "test_get_name_addr_ends_at_special  s    z-TestParser.test_get_name_addr_ends_at_specialc                 C   s:   |  tj td W d    n1 s,0    Y  d S rT  rA   r   rB   r   r"  r1   r   r   r   $test_get_name_addr_no_content_raises*  s    z/TestParser.test_get_name_addr_no_content_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nz (foo) ,r/  r1   r   r   r   3test_get_name_addr_no_content_before_special_raises.  s    z>TestParser.test_get_name_addr_no_content_before_special_raisesc                 C   s:   |  tj td W d    n1 s,0    Y  d S )Nr   r/  r1   r   r   r   5test_get_name_addr_no_angle_after_display_name_raises2  s    z@TestParser.test_get_name_addr_no_angle_after_display_name_raisesc                 C   sj   |  tjdddg d}| |jd | |j | |jd | |jd | |j	 | |j
d d S )Nr  r
   mailboxr  r  r&   r   get_mailboxr   r   r  r  r  r  r   r  r   r3  r   r   r   test_get_mailbox_addr_spec_only8  s    z*TestParser.test_get_mailbox_addr_spec_onlyc                 C   sj   |  tjdddg d}| |jd | |j | |jd | |jd | |j	 | |j
d d S )Nr  r
   r3  r  r  r  r4  r6  r   r   r    test_get_mailbox_angle_addr_onlyF  s    z+TestParser.test_get_mailbox_angle_addr_onlyc                 C   sl   |  tjdddg d}| |jd | |jd | |jd | |jd | |j	 | |j
d d S )N$"Roy A. Bear" <dinsdale@example.com>r
   r3  Roy A. Bearr  r  r  r&   r   r5  r   r   r  r  r  r  r   r  r6  r   r   r   test_get_mailbox_name_addrT  s    z%TestParser.test_get_mailbox_name_addrc                 C   sl   |  tjdddg d}| |jd | |jd | |jd | |jd | |j	 | |j
d d S )	Nz*"Roy A. Bear" <dinsdale@example.com>, restr9  z, restr3  r:  r  r  r  r;  r6  r   r   r    test_get_mailbox_ends_at_specialb  s    z+TestParser.test_get_mailbox_ends_at_specialc                 C   sL   |  tjdddtjgd d}| |jd | |jd | |jd d S r  )	r&   r   r5  r   rM   r   r  r  r  r6  r   r   r   ,test_get_mailbox_quoted_strings_in_atom_listp  s    
z7TestParser.test_get_mailbox_quoted_strings_in_atom_listc                 C   s   |  tjdddg d}| |jd | t|jd |jd }| |j | |j	d | |j
d | |j | |jd | |j|j d S )Nr  r
   mailbox-listr/   r   r  r  )r&   r   get_mailbox_listr   r   rB  	mailboxesr  r  r  r  r   r  all_mailboxes)r   mailbox_listr3  r   r   r   !test_get_mailbox_list_single_addr}  s$    
z,TestParser.test_get_mailbox_list_single_addrc                 C   sr   |  tjdddg d}| |jd | t|jd | |jd jd | |jd jd | |j|j d S )	Nz/dinsdale@example.com, dinsdale@test.example.comr
   r?  r   r   r  r/   dinsdale@test.example.com)	r&   r   r@  r   r   rB  rA  r  rB  r   rC  r   r   r   %test_get_mailbox_list_two_simple_addr  s$    z0TestParser.test_get_mailbox_list_two_simple_addrc                 C   s   |  tjdddg d}| t|jd | |jd jd | |jd jd | |jd jd | |jd jd	 | |j|j d S )
NzS"Roy A. Bear" <dinsdale@example.com>, "Fred Flintstone" <dinsdale@test.example.com>r
   r   r   r  r:  r/   rE  Fred Flintstone)	r&   r   r@  r   rB  rA  r  r  rB  rF  r   r   r   #test_get_mailbox_list_two_name_addr  s.    	z.TestParser.test_get_mailbox_list_two_name_addrc                 C   s   |  tjdddtjgd}| t|jd | |jd jd | |jd j	d | |jd jd	 | |jd j	d
 | |j|j
 d S )Nzd(foo) "Roy A. Bear" <dinsdale@example.com>(bar), "Fred Flintstone" <dinsdale@test.(bird)example.com>zV "Roy A. Bear" <dinsdale@example.com> , "Fred Flintstone" <dinsdale@test. example.com>r
   r   r   r  r:  r/   rE  rH  )r&   r   r@  r   ru  r   rB  rA  r  r  rB  rF  r   r   r   !test_get_mailbox_list_two_complex  s.    	z,TestParser.test_get_mailbox_list_two_complexc              
   C   s   |  tjdddtjtjtjtjgd}| t|jd | t|j	d | |j	d j
d | |j	d j | |j	d jd | |j	d j | |j	d jd	 | |j	d |jd  | |jd jd
 | |jd jd d S )NzY"Roy A. Bear"[] dinsdale@example.com, "Fred Flintstone" <dinsdale@test.(bird)example.com>zT"Roy A. Bear"[] dinsdale@example.com, "Fred Flintstone" <dinsdale@test. example.com>r
   r/   r   r   invalid-mailboxr:  z"Roy A. Bear"rE  rH  )r&   r   r@  r   rM   ru  r   rB  rA  rB  r   r  r  r  r  r  assertIsrF  r   r   r   .test_get_mailbox_list_unparseable_mailbox_null  sB    z9TestParser.test_get_mailbox_list_unparseable_mailbox_nullc                 C   s   |  tjdddtjgd}| t|jd | t|jd | |jd j	d | |jd j
d | |jd jd | |jd |jd  | |jd j	d	 | |jd j
d
 d S )NzU"Roy A. Bear" <dinsdale@example.com>@@, "Fred Flintstone" <dinsdale@test.example.com>r
   r/   r   r   r  r:  rK  rE  rH  )r&   r   r@  r   rM   r   rB  rA  rB  r  r  r   rL  rF  r   r   r   .test_get_mailbox_list_junk_after_valid_address  s6    	z9TestParser.test_get_mailbox_list_junk_after_valid_addressc                 C   s   |  tjdddtjgd d}| t|jd | |j|j | |jd j	d | |jd j
d | |jd j	d	 | |jd j
d
 d S )Nz\"Roy A. Bear" <dinsdale@example.com>, (bird),, "Fred Flintstone" <dinsdale@test.example.com>zV"Roy A. Bear" <dinsdale@example.com>, ,, "Fred Flintstone" <dinsdale@test.example.com>r   r
   r   r  r:  r/   rE  rH  )r&   r   r@  r   ru  r   rB  rA  rB  r  r  rF  r   r   r   (test_get_mailbox_list_empty_list_element  s.    
	z3TestParser.test_get_mailbox_list_empty_list_elementc                 C   sD   |  tjdddtjgd d}| t|jd | |j|j d S )Nz(foo),, (bar)z ,, r  r
   r   )	r&   r   r@  r   ru  r   rB  rA  rB  rF  r   r   r   )test_get_mailbox_list_only_empty_elements  s    
z4TestParser.test_get_mailbox_list_only_empty_elementsc                 C   sJ   |  tjdddg d}| |jd | t|jd | |j|j d S )Nz	(hidden);z(hidden)r3   ;
group-listr   )r&   r   get_group_listr   r   rB  rA  rB  r   Z
group_listr   r   r   test_get_group_list_cfws_only%  s    z(TestParser.test_get_group_list_cfws_onlyc                 C   s^   |  tjdddg d}| |jd | t|jd | |j|j | |jd jd d S )Nz;dinsdale@example.org, "Fred A. Bear" <dinsdale@example.org>r
   rR  r   r/   Fred A. Bear)	r&   r   rS  r   r   rB  rA  rB  r  rT  r   r   r    test_get_group_list_mailbox_list1  s    z+TestParser.test_get_group_list_mailbox_listc                 C   sN   |  tjdddtjgd}| |jd | t|jd | |j|j	 d S )Nz, (foo),,(bar)z, ,, r
   rR  r   )
r&   r   rS  r   ru  r   r   rB  rA  rB  rT  r   r   r   "test_get_group_list_obs_group_list?  s    z-TestParser.test_get_group_list_obs_group_listc                 C   sN   |  tjdddtjgd}| |jd | t|jd | |j|j	 d S )Nz(bar)r3   r
   rR  r   )
r&   r   rS  r   rM   r   r   rB  rA  rB  rT  r   r   r   (test_get_group_list_comment_only_invalidK  s    z3TestParser.test_get_group_list_comment_only_invalidc                 C   sX   |  tjdddg d}| |jd | |jd | t|jd | |j|j d S )NMonty Python:;r
   groupMonty Pythonr   	r&   r   	get_groupr   r   r  rB  rA  rB  r   r[  r   r   r   test_get_group_emptyY  s    zTestParser.test_get_group_emptyc                 C   sd   |  tjdddtjgd}| |jd | t|jd | t|j	d | |j	d j
d d S )Nzfoo: <>;r
   r.   r   r/   r  )r&   r   r^  r   rM   r   r  rB  rA  rB  r   r_  r   r   r   test_get_group_null_addr_specf  s    z(TestParser.test_get_group_null_addr_specc                 C   sX   |  tjdddg d}| |jd | |jd | t|jd | |j|j d S )NzMonty Python: (hidden);Monty Python: ;r
   r[  r\  r   r]  r_  r   r   r   test_get_group_cfws_onlyr  s    z#TestParser.test_get_group_cfws_onlyc                 C   sl   |  tjdddg d}| |jd | |jd | t|jd | |j|j | |jd j	d d S )Nz4Monty Python: "Fred A. Bear" <dinsdale@example.com>;r
   r[  r\  r/   r   r  )
r&   r   r^  r   r   r  rB  rA  rB  r  r_  r   r   r   test_get_group_single_mailbox  s     z(TestParser.test_get_group_single_mailboxc                 C   s   |  tjdddg d}| |jd | |jd | t|jd | |j|j | |jd jd | |jd	 jd
 | |jd j	d d S )NzhMonty Python: "Fred A. Bear" <dinsdale@example.com>,(foo) Roger <ping@exampele.com>, x@test.example.com;zcMonty Python: "Fred A. Bear" <dinsdale@example.com>, Roger <ping@exampele.com>, x@test.example.com;r
   r[  r\  r  r   rV  r/   ZRogerr   r   )
r&   r   r^  r   r   r  rB  rA  rB  r  r_  r   r   r   test_get_group_mixed_list  s(    	z$TestParser.test_get_group_mixed_listc                 C   s   |  tjdddtjtjgd}| |jd | |jd | t|j	d | t|j
d | |j	d jd	 | |j	d
 jd | |j
d
 j d S )NzfMonty Python: "Fred A. Bear" <dinsdale@example.com>,(foo) Roger ping@exampele.com, x@test.example.com;zaMonty Python: "Fred A. Bear" <dinsdale@example.com>, Roger ping@exampele.com, x@test.example.com;r
   r[  r\  r   r  r   rV  r/   r   )r&   r   r^  r   rM   r   r   r  rB  rA  rB  r  r  r_  r   r   r   test_get_group_one_invalid  s$    
z%TestParser.test_get_group_one_invalidc                 C   s   |  tjdddtjgd}| |jd | |jd | t|j	d | |j	|j
 | |j	d jd | |j	d jd	 | |j	d
 jd | |j	d jd | |j	d jd d S )NzSMonty Python:"Fred A. Bear" <dinsdale@example.com>,eric@where.test,John <jdoe@test>zTMonty Python:"Fred A. Bear" <dinsdale@example.com>,eric@where.test,John <jdoe@test>;r
   r[  r\  r  r   r  rV  r/   zeric@where.testr   ZJohnz	jdoe@test)r&   r   r^  r   rM   r   r   r  rB  rA  rB  r  r_  r   r   r   $test_get_group_missing_final_semicol  s8    	z/TestParser.test_get_group_missing_final_semicolc                 C   sp   |  tjdddg d}| |jd | t|jd | |j|j | |jd jd | |d jd d S )Nr  r
   addressr/   r   r  r3  	r&   r   get_addressr   r   rB  rA  rB  r  r   rh  r   r   r   test_get_address_simple  s$    z"TestParser.test_get_address_simplec                 C   sp   |  tjdddg d}| |jd | t|jd | |j|j | |jd jd | |d jd d S )	Nz1(foo) "Fred A. Bear" <(bird)dinsdale@example.com>z' "Fred A. Bear" < dinsdale@example.com>r
   rh  r/   r   rV  r3  	r&   r   rj  r   r   rB  rA  rB  r  rk  r   r   r   test_get_address_complex  s$    z#TestParser.test_get_address_complexc                 C   sp   |  tjdddg d}| |jd | t|jd | |j|j | |jd jd | |d jd d S )	Nz'=?utf-8?q?=C3=89ric?= <foo@example.com>u   Éric <foo@example.com>r
   rh  r/   r   r]   r3  rm  rk  r   r   r   %test_get_address_rfc2047_display_name  s$    z0TestParser.test_get_address_rfc2047_display_namec                 C   sn   |  tjdddg d}| |jd | t|jd | |j|j | |d jd | |d jd d S )NrZ  r
   rh  r   r[  r\  rm  rk  r   r   r   test_get_address_empty_group	  s$    z'TestParser.test_get_address_empty_groupc                 C   s   |  tjdddg d}| |jd | t|jd | |j|j | |d jd | |d jd | |jd j	d d S )	Nz+Monty Python: x@example.com, y@example.com;r
   rh  r   r   r[  r\  r   )
r&   r   rj  r   r   rB  rA  rB  r  r  rk  r   r   r   test_get_address_group	  s&    z!TestParser.test_get_address_groupc                 C   s   |  tjdddg d}| |jd | t|jd | |j|j | |jd jd | |jd j	d | |d jd d S )	Nz"foo bar"@example.comr
   rh  r/   r   r  r   r3  )
r&   r   rj  r   r   rB  rA  rB  r  r  rk  r   r   r   "test_get_address_quoted_local_part#	  s&    z-TestParser.test_get_address_quoted_local_partc                 C   sp   |  tjdddg d}| |jd | t|jd | |j|j | |jd jd | |d jd d S )	Nzdinsdale@example.com, nextr  r  rh  r/   r   r  r3  ri  rk  r   r   r    test_get_address_ends_at_special4	  s     z+TestParser.test_get_address_ends_at_specialc              	   C   s   |  tjdddtjtjtjgd}| |jd | t|jd | t|j	d | 
|j	d j | |j	d jd | |d jd d S )Nzping example.com, nextzping example.comr  rh  r   r/   rK  )r&   r   rj  r   rM   r   r   rB  rA  rB  r  r  r  rk  r   r   r   (test_get_address_invalid_mailbox_invalidC	  s     	z3TestParser.test_get_address_invalid_mailbox_invalidc                 C   s^   |  tjdddtjgd d}| |jd jd | |jd jd | |jd j	d d S )	Nr  r  r  r
   r   r  r  r  )
r&   r   rj  r   rM   r   rB  r  r  r  rk  r   r   r   ,test_get_address_quoted_strings_in_atom_listT	  s    
z7TestParser.test_get_address_quoted_strings_in_atom_listc                 C   sN   |  tjdddtjgd}| |jd | t|jd | |j|j	 d S )Nz(Recipient list suppressed)r3   r
   address-listr   )
r&   r   get_address_listr   ru  r   r   rB  rA  rB  r   Zaddress_listr   r   r   test_get_address_list_CFWSb	  s    z%TestParser.test_get_address_list_CFWSc                 C   s   |  tjdddg d}| |jd | t|jd | |j|j | dd |jD dd |jD  | |jd j	d	 | |d jd
 | 
|d j d S )Nr  r
   rv  r/   c                 S   s   g | ]}t |qS r   r   .0r   r   r   r   
<listcomp>x	      zETestParser.test_get_address_list_mailboxes_simple.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   rz  r{  r   r   r   r}  y	  r~  r   r  rh  )r&   r   rw  r   r   rB  rA  rB  	addressesr  r  r  rx  r   r   r   &test_get_address_list_mailboxes_simplem	  s$    z1TestParser.test_get_address_list_mailboxes_simplec                 C   s   |  tjdddg d}| |jd | t|jd | |j|j | dd |jD dd |jD  | |jd j	d	 | |jd
 j
d d S )Nz0foo@example.com, "Fred A. Bar" <bar@example.com>r
   rv  r   c                 S   s   g | ]}t |qS r   rz  r{  r   r   r   r}  	  r~  zITestParser.test_get_address_list_mailboxes_two_simple.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   rz  r{  r   r   r   r}  	  r~  r   r.   r/   zFred A. Bar)r&   r   rw  r   r   rB  rA  rB  r  r  r  rx  r   r   r   *test_get_address_list_mailboxes_two_simple~	  s"    z5TestParser.test_get_address_list_mailboxes_two_simplec                 C   s   |  tjdddtjtjgd}| |jd | t|jd | |j|j	 | dd |jD dd |j
D  | |jd	 jd
 | |jd	 jd | |j
d	 jd | |jd jd | |jd jd d S )Nzn"Roy A. Bear" <dinsdale@example.com>, (ping) Foo <x@example.com>,Nobody Is. Special <y@(bird)example.(bad)com>z_"Roy A. Bear" <dinsdale@example.com>, Foo <x@example.com>,"Nobody Is. Special" <y@example. com>r
   rv  r  c                 S   s   g | ]}t |qS r   rz  r{  r   r   r   r}  	  r~  zFTestParser.test_get_address_list_mailboxes_complex.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   rz  r{  r   r   r   r}  	  r~  r   r  r3  rh  r/   r   r   Nobody Is. Special)r&   r   rw  r   ru  r   r   rB  rA  rB  r  r  r  r  rx  r   r   r   'test_get_address_list_mailboxes_complex	  s0    z2TestParser.test_get_address_list_mailboxes_complexc                 C   sT  |  tjdddtjtjtjtjtjtjgd}| |jd | t|j	d | t|j
d | dd |j
D d	d |jD  | |j	d
 jd | |j	d
 jd | |jd
 jd | |jd jd | t|jd
 j	d | t|jd j	d
 | t|jd j	d
 | |jd j
d
 jd | |jd j
d
 jd d S )Nzl"Roy A. Bear" <dinsdale@example.com>, (ping) Foo x@example.com[],Nobody Is. Special <(bird)example.(bad)com>z^"Roy A. Bear" <dinsdale@example.com>, Foo x@example.com[],"Nobody Is. Special" < example. com>r
   rv  r/   r  c                 S   s   g | ]}t |qS r   rz  r{  r   r   r   r}  	  r~  zPTestParser.test_get_address_list_mailboxes_invalid_addresses.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   rz  r{  r   r   r   r}  	  r~  r   r  r3  rh  zFoo xr   r  )r&   r   rw  r   rM   ru  r   r   rB  rA  rB  r  r  r  r  rx  r   r   r   1test_get_address_list_mailboxes_invalid_addresses	  sB    z<TestParser.test_get_address_list_mailboxes_invalid_addressesc                 C   s   |  tjdddg d}| |jd | t|jd | |j|j | t|jd | |jd jd | |jd j	d | t|jd jd d S )Nrb  r
   rv  r   r/   rh  r\  )
r&   r   rw  r   r   rB  rA  rB  r  r  rx  r   r   r   !test_get_address_list_group_empty	  s     z,TestParser.test_get_address_list_group_emptyc                 C   s   |  tjdddg d}| |jd | t|jd | |j|j | |jd jd | |j	d j
d | |j	d jd jd d S )Nz#Monty Python: dinsdale@example.com;r
   rv  r/   r   r  r\  )r&   r   rw  r   r   rB  rA  rB  r  r  r  rx  r   r   r   "test_get_address_list_group_simple	  s&    z-TestParser.test_get_address_list_group_simplec                 C   s  |  tjdddg d}| |jd | t|jd | |j|j | t|jd | |jd j	d | |jd j
d | |jd jd jd	 | |jd jd
 j	d | |jd
 jd j	d | |jd jd j	d | t|jd
 t|jd  d S )NziMonty Python: dinsdale@example.com, "Fred" <flint@example.com>;, Abe <x@example.com>, Bee <y@example.com>r
   rv  r   r  r   r  r\  r  r/   Zflintr   r   y)r&   r   rw  r   r   rB  rA  rB  r  r  r  r  r   rx  r   r   r   )test_get_address_list_group_and_mailboxes	  s@    	z4TestParser.test_get_address_list_group_and_mailboxesc                 C   s    |  tjdddtjgd }d S )Nz;attachmentz; attachmentr   )r)   r    parse_content_disposition_headerr   rM   )r   Zcontent_dispr   r   r    test_invalid_content_disposition
  s
    
z+TestParser.test_invalid_content_dispositionc                 C   s    |  tjdddtjgd }d S )Nz;foor  )r)   r   Z&parse_content_transfer_encoding_headerr   rM   )r   Zcter   r   r   &test_invalid_content_transfer_encoding
  s    z1TestParser.test_invalid_content_transfer_encodingc                 C   s:   |  tj td W d    n1 s,0    Y  d S r'   rA   r   rB   r   
get_msg_idr1   r   r   r   test_get_msg_id_empty
  s    z TestParser.test_get_msg_id_emptyc                 C   s(   |  tjdddg d}| |jd d S )Nz%<simeple.local@example.something.com>r
   msg-idr&   r   r  r   r   r   msg_idr   r   r   test_get_msg_id_valid
  s    z TestParser.test_get_msg_id_validc                 C   s,   |  tjdddtjgd}| |jd d S )Nz<"simeple.local"@example.com>z<simeple.local@example.com>r
   r  )r&   r   r  r   ru  r   r   r  r   r   r   test_get_msg_id_obsolete_local*
  s    z)TestParser.test_get_msg_id_obsolete_localc                 C   s(   |  tjdddg d}| |jd d S )Nz&<simple.local@[someexamplecom.domain]>r
   r  r  r  r   r   r   *test_get_msg_id_non_folding_literal_domain5
  s    z5TestParser.test_get_msg_id_non_folding_literal_domainc                 C   s   |  tjdddtjgd}d S )Nz<simplelocal@(old)example.com>z<simplelocal@ example.com>r
   )r&   r   r  r   ru  r  r   r   r   $test_get_msg_id_obsolete_domain_partA
  s    z/TestParser.test_get_msg_id_obsolete_domain_partc                 C   s,   |  tjdddtjgd}| |jd d S )Nz<simplelocal>r
   r  r&   r   r  r   rM   r   r   r  r   r   r    test_get_msg_id_no_id_right_partK
  s    z+TestParser.test_get_msg_id_no_id_right_partc                 C   s$   d}t |}| |jtjg d S )N3935-XPB-567:0:45327:9:90305:17843586-40@example.com)r   parse_message_idr   r   r   rM   )r   textr  r   r   r   1test_get_msg_id_invalid_expected_msg_id_not_foundV
  s    
z<TestParser.test_get_msg_id_invalid_expected_msg_id_not_foundc                 C   s*   |  tjdddtjg}| |jd d S )Nr  zinvalid-message-id)r)   r   r  r   rM   r   r   r   Z
message_idr   r   r   test_parse_invalid_message_id]
  s    z(TestParser.test_parse_invalid_message_idc                 C   s&   |  tjdddg }| |jd d S )Nz<aperson@somedomain>
message-id)r)   r   r  r   r   r  r   r   r   test_parse_valid_message_idg
  s    z&TestParser.test_parse_valid_message_idc                 C   sB   |  tjdddtjgg }| |jd | t|jd d d S )Nz%<validmessageid@example>thensomethingz<validmessageid@example>r  r   zUnexpected 'thensomething')	r)   r   r  r   rM   r   r   r   r   r  r   r   r   $test_parse_message_id_with_remainingq
  s    z/TestParser.test_parse_message_id_with_remainingc                 C   s:   |  tj td W d    n1 s,0    Y  d S )NZmsgwithnoankler  r1   r   r   r   test_get_msg_id_no_angle_start~
  s    z)TestParser.test_get_msg_id_no_angle_startc                 C   s,   |  tjdddtjgd}| |jd d S )Nz<simplelocal@domainz<simplelocal@domain>r
   r  r  r  r   r   r   test_get_msg_id_no_angle_end
  s    z'TestParser.test_get_msg_id_no_angle_endN(B  r   r   r   bytesr   r   r   r   ascii_lettersdigitsr   	translater   	maketransr  r2   r5   r7   r9   r<   r>   rD   rE   rF   rG   rK   rN   rP   rQ   rX   rY   r[   r\   r^   ra   rc   re   rg   rh   ri   rk   rl   rn   rq   rr   rs   ru   rv   rx   ry   rz   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   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)  r*  r+  r/  r1  r2  r4  r6  r7  r8  r:  r;  r<  r=  r?  rD  rF  rH  rI  rJ  rK  rL  rN  rQ  rR  rS  rV  rW  rX  rY  rZ  r]  r^  r_  ra  ri  ro  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  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   r$  r&  r(  r*  r,  r-  r.  r0  r1  r2  r7  r8  r<  r=  r>  rD  rG  rI  rJ  rM  rN  rO  rP  rU  rW  rX  rY  r`  ra  rc  rd  re  rf  rg  rl  rn  ro  rp  rq  rr  rs  rt  ru  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*   -   sr  


						
				



														



					




$


r*   c                   @   s   e Zd Zdd Zddddgg fddd	dd
gg fddddgg fddddgejgfddddgejgfddddgejgfddddgejgfddddgejgfddddgejgd fddddgejgd fdd d!d"gejgd fd#Zd$S )%Test_parse_mime_parametersc                 C   s8   |  tj||||}| |jd | t|j| d S )Nzmime-parameters)r)   r   Zparse_mime_parametersr   r   listparams)r   r   tl_strtl_valuer  r    Zmime_parametersr   r   r   mime_parameters_as_value
  s
    z3Test_parse_mime_parameters.mime_parameters_as_valuezfilename="abc.py"z filename="abc.py"zfilename=abc.py)filenamezabc.pyzfilename="abc.py"; xyz=abcz filename="abc.py"; xyz="abc"zfilename=abc.py; xyz=abc)Zxyzr?   z;filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66z filename="201.tif")r  z201.tifz#filename=abc.gif; filename=def.tiffz filename="abc.gif")r  zabc.gifzMfilename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66; filename=abc.gifzNfilename=abc.gif;  filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66zMfilename=abc.gif; filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66zPfilename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66; filename*1*=abc.gifz filename="201.tifabc.gif")r  z201.tifabc.gifz<filename*0*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66;zPfilename*0*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66; filename*3*=abc.gifr   zNfilename=abc.gif;  filename*2*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66z filename="abc.gif201.tif"zMfilename=abc.gif; filename*2*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66)r  zabc.gif201.tifr  z	r*="'a'\"z r="\""zr*='a'")rr   )simpleZmultiple_keysZsplit_valueZduplicate_keyZduplicate_key_with_split_valueZ*duplicate_key_with_split_value_other_orderZduplicate_in_split_valueZmissing_split_valueZ!duplicate_and_missing_split_valueZ!duplicate_with_broken_split_valueZextra_dquoteN)r   r   r   r  r   rM   Zmime_parameters_paramsr   r   r   r   r  
  s   





r  c                
   @   sd   e Zd Zdd Zdddddg fdddddg fddd	ddg fd
d
dddg fdddddejgfdZdS )Test_parse_mime_versionc                 C   s4   |  tj||||}| |j| | |j| d S r   )r)   r   Zparse_mime_versionr   majorminor)r   r   r  r  r  r  r    Zmime_versionr   r   r   mime_version_as_value  s
    z-Test_parse_mime_version.mime_version_as_valuez1.0r/   r   z1.0 (produced by MetaSend Vx.x)z1.0 z(produced by MetaSend Vx.x) 1.0z 1.0z1.(produced by MetaSend Vx.x)0z1. 0r
   N)Z
rfc_2045_1Z
RFC_2045_2Z
RFC_2045_3Z
RFC_2045_4empty)r   r   r   r  r   ZHeaderMissingRequiredValueZmime_version_paramsr   r   r   r   r    sJ   				r  c                   @   s   e Zd ZejZef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S )TestFoldingc                 C   s   |  |j|d||  d S )Nr   )r   ZfoldZppstr)r   r   Zfoldedr   r   r   r   _testC  s    zTestFolding._testc                 C   s   |  tdd d S )NzThis is a testzThis is a test
r  r   r_   r1   r   r   r   !test_simple_unstructured_no_foldsF  s    z-TestFolding.test_simple_unstructured_no_foldsc                 C   s   |  tdd d S )NzvThis is also a test, but this time there are enough words (and even some symbols) to make it wrap; at least in theory.zxThis is also a test, but this time there are enough words (and even some
 symbols) to make it wrap; at least in theory.
r  r1   r   r   r   test_simple_unstructured_foldedJ  s    z+TestFolding.test_simple_unstructured_foldedc                 C   s   |  tdd d S )Nu   hübsch kleiner beißtz+=?utf-8?q?h=C3=BCbsch_kleiner_bei=C3=9Ft?=
r  r1   r   r   r   'test_unstructured_with_unicode_no_foldsR  s    z3TestFolding.test_unstructured_with_unicode_no_foldsc                 C   s   |  tdd d S )NuQ   Mein kleiner Kaktus ist sehr hübsch.  Es hat viele Stacheln und oft beißt mich.zuMein kleiner Kaktus ist sehr =?utf-8?q?h=C3=BCbsch=2E?=  Es hat viele Stacheln
 und oft =?utf-8?q?bei=C3=9Ft?= mich.
r  r1   r   r   r   (test_one_ew_on_each_of_two_wrapped_linesV  s    z4TestFolding.test_one_ew_on_each_of_two_wrapped_linesc                 C   s   |  tdd d S )NuD   Mein Kaktus ist hübsch.  Es beißt mich.  And that's all I'm sayin.z\Mein Kaktus ist =?utf-8?q?h=C3=BCbsch=2E__Es_bei=C3=9Ft?= mich.  And that's
 all I'm sayin.
r  r1   r   r   r   test_ews_combined_before_wrap^  s    z)TestFolding.test_ews_combined_before_wrapc                 C   s   |  tdd d d S )Nzabc <xyz@example.com>r   zabc <xyz@example.com>
r  r   rw  r1   r   r   r   test_simple_addressh  s    zTestFolding.test_simple_addressc                 C   s   |  tdd d d S )Nzabc <xyz@example.com>, "Fred Blunt" <sharp@example.com>, "J.P.Cool" <hot@example.com>, "K<>y" <key@example.com>, Firesale <cheap@example.com>, <end@example.com>r   zabc <xyz@example.com>, "Fred Blunt" <sharp@example.com>,
 "J.P.Cool" <hot@example.com>, "K<>y" <key@example.com>,
 Firesale <cheap@example.com>, <end@example.com>
r  r1   r   r   r   #test_address_list_folding_at_commasl  s
    z/TestFolding.test_address_list_folding_at_commasc                 C   s   |  tdd d d S )NuI   Hübsch Kaktus <beautiful@example.com>, beißt beißt <biter@example.com>r   o=?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful@example.com>,
 =?utf-8?q?bei=C3=9Ft_bei=C3=9Ft?= <biter@example.com>
r  r1   r   r   r   $test_address_list_with_unicode_namesw  s    z0TestFolding.test_address_list_with_unicode_namesc                 C   s   |  tdd d d S )NuM   "Hübsch Kaktus" <beautiful@example.com>, "beißt" beißt <biter@example.com>r   r  r  r1   r   r   r   .test_address_list_with_unicode_names_in_quotes~  s    z:TestFolding.test_address_list_with_unicode_names_in_quotesc              	   C   sJ   t d}t t t ddgt t ddg|g}| |d d S )NzP   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxztest:r   r3   r	   zXtest:   
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
)r   r_   ZHeaderZHeaderLabelZValueTerminalZCFWSListZWhiteSpaceTerminalr  )r   bodyheaderr   r   r   7test_split_at_whitespace_after_header_before_long_token  s    
zCTestFolding.test_split_at_whitespace_after_header_before_long_tokenc                 C   s   |  tdd d S )NzSxxx   yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzUxxx  
 yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
r  r1   r   r   r   *test_split_at_whitespace_before_long_token  s    z6TestFolding.test_split_at_whitespace_before_long_tokenc                 C   sj   d}d}t |d }|t | }| t|d || dd|   d d | dd	d|    d  d S )
Nzxxx   z
=?utf-8?q?r   ZPyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyr  N   z?=
r3   P   )rB  r  r   r_   )r   Zfirst_token_with_whitespaceZchrome_leaderZ
len_chromeZ	len_non_yr   r   r   #test_overlong_encodeable_is_wrapped  s*    

z/TestFolding.test_overlong_encodeable_is_wrappedc                 C   s   |  tdd d S )NzZattachment; filename="TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TES.txt"zvattachment;
 filename*0*=us-ascii''TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST;
 filename*1*=_TEST_TES.txt
)r  r   r  r1   r   r   r   test_long_filename_attachment  s
    z)TestFolding.test_long_filename_attachmentN)r   r   r   r   defaultr  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  ?  s   
r  __main__)r   ZunittestZemailr   r   r   r   Ztest.test_emailr   r   r   r   r*   r  r  r  r   mainr   r   r   r   <module>   sF                       vr<j