a  zeC@sddlZddlZddlmZddlmZddlmZddlmZm Z GdddeZ Gdd d Z Gd d d e eZ e Gd d d e eZ e Gddde eZGdddeZedkredS)N)_header_value_parser)errorspolicy) TestEmailBase parameterizec@seZdZddZdS) TestTokenscCsHtdd}||d|t|d||jd||jddS)Nz fws)parserZEWWhiteSpaceTerminal assertEqualstrvalue token_type)selfxr]/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_email/test__header_value_parser.pytest_EWWhiteSpaceTerminal s   z$TestTokens.test_EWWhiteSpaceTerminalN)__name__ __module__ __qualname__rrrrrrsrc@s*eZdZdddZd ddZd ddZdS) TestParserMixinNcCsR|t||||j|||j|||||durN||j|dSN)r r rassertDefectsEqual all_defectscomments)rtlreststringrdefects remainderrrrr_assert_resultss  zTestParserMixin._assert_resultsc Cs(||\}} |j|| ||||dd|S)N)rr") rmethodsourcerrr r!rrrrrr _test_get_xs  zTestParserMixin._test_get_xc Cs"||}||d|||d||SNr r#)rr$inputrrr rrrrr _test_parse_x&szTestParserMixin._test_parse_x)N)N)N)rrrr"r&r)rrrrrs  rc@sF eZdZeedddZejej dZ e e dddZddZd d Zd d Zd dZddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Z d+d,Z!d-d.Z"d/d0Z#d1d2Z$d3d4Z%d5d6Z&d7d8Z'd9d:Z(d;d<Z)d=d>Z*d?d@Z+dAdBZ,dCdDZ-dEdFZ.dGdHZ/dIdJZ0dKdLZ1dMdNZ2dOdPZ3dQdRZ4dSdTZ5dUdVZ6dWdXZ7dYdZZ8d[d\Z9d]d^Z:d_d`Z;dadbZdgdhZ?didTZ5djdkZ@dldmZAdndoZBdpdqZCdrdsZDdtduZEdvdwZFdxdyZGdzd{ZHd|d}ZId~dZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYddZZddZ[ddZ\ddZ]ddZ^ddZ_ddZ`ddZaddZbddZcddZdddZeddZfddZgddZhddZiddZjddZkddÄZlddńZmddDŽZnddɄZodd˄Zpdd̈́ZqddτZrddфZsddӄZtddՄZuddׄZvddلZwddۄZxdd݄Zydd߄ZzddZ{ddZ|ddZ}ddZ~ddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZdd Zd d Zd d ZddZddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zd<d=Zd>d?Zd@dAZdBdCZdDdEZdFdGZdHdIZdJdKZdLdMZdNdOZdPdQZdRdSZdTdUZdVdWZdXdYZdZd[Zd\d]Zd^d_Zd`daZdbdcZdddeZdfdgZdhdiZdjdkZdldmZdndoZdpdqZÐdrdsZĐdtduZŐdvdwZƐdxdyZǐdzd{ZȐd|d}Zɐd~dZʐddZːddZ̐ddZ͐ddZΐddZϐddZАddZѐddZҐddZӐddZԐddZՐddZ֐ddZאddZؐddZِddZڐddZېddZܐddZݐddZސddZߐddZddZddZddZddZddZddZddZddZddZddZddZddÄZdĐdńZdƐdDŽZdȐdɄZdʐd˄Zd̐d̈́ZdΐdτZdАdфZdҐdӄZdԐdՄZd֐dׄZdؐdلZdڐdۄZdܐd݄Zdސd߄ZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZ ddZ ddZ ddZ ddZ ddZdd Zd d Zd d ZddZddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Z d,d-Z!d.d/Z"d0d1Z#d2d3Z$d4d5Z%d6d7Z&d8d9Z'd:d;Z(d<d=Z)d>d?Z*d@dAZ+dBdCZ,dDdEZ-dFdGZ.dHdIZ/dJdKZ0dLdMZ1dNdOZ2dPdQZ3dRdSZ4dTdUZ5dVdWZ6dXdYZ7dZd[Z8d\d]Z9d^d_Z:d`daZ;dbdcZ<dddeZ=dfdgZ>dhdiZ?djdkZ@dldmZAdnS(o TestParser!asciiz!#$%&'*+-/=?^_`{}|~r z\[]cCs|tdddgdS)Nfoor r Z _wsp_splitterrrrrtest__wsp_splitter_one_word6sz&TestParser.test__wsp_splitter_one_wordcCs|tddgddS)Nzfoo defr/)r. defr0r1rrrtest__wsp_splitter_two_words9sz'TestParser.test__wsp_splitter_two_wordscCs|tddgddS)Nz foo def jikr/)r. zdef jikr0r1rrrtest__wsp_splitter_ws_runs=sz%TestParser.test__wsp_splitter_ws_runscCs(|tjdddgd}||jddS)Nz r3r r )r&r get_fwsr r)rr rrrtest_get_fws_onlyDszTestParser.test_get_fws_onlycCs|tjdddgddS)N foor3r.r&r r8r1rrrtest_get_fws_spaceHszTestParser.test_get_fws_spacecCs|tjdddgddS)Nz foo r6r3foo r;r1rrrtest_get_fws_ws_runKszTestParser.test_get_fws_ws_runcCs:|tjtdWdn1s,0YdS)Nabc assertRaisesrHeaderParseErrorr get_encoded_wordr1rrr*test_get_encoded_word_missing_start_raisesPsz5TestParser.test_get_encoded_word_missing_start_raisescCs:|tjtdWdn1s,0YdS)Nz=?abcr@r1rrr(test_get_encoded_word_missing_end_raisesTsz3TestParser.test_get_encoded_word_missing_end_raisescCs:|tjtdWdn1s,0YdS)Nz=?abc?=r@r1rrr+test_get_encoded_word_missing_middle_raisesXsz6TestParser.test_get_encoded_word_missing_middle_raisescCs:|tjtdWdn1s,0YdS)Nz=?utf-8?X?somevalue?=r@r1rrr!test_get_encoded_word_invalid_cte\sz,TestParser.test_get_encoded_word_invalid_ctecCs|tjdddgddS)Nz#=?us-ascii?q?this_is_a_test?= birdthis is a test birdr&r rCr1rrrtest_get_encoded_word_valid_ew`sz)TestParser.test_get_encoded_word_valid_ewcCs|tjdddtjgddS)Nz#=?us-ascii?q?this is a test?= birdrHrIr&r rCrInvalidHeaderDefectr1rrr%test_get_encoded_word_internal_spaceshsz0TestParser.test_get_encoded_word_internal_spacescCs|tjdddgddS)Nz(=?us-ascii?q?first?= =?utf-8?q?second?=firstz =?utf-8?q?second?=rJr1rrr test_get_encoded_word_gets_firstpsz+TestParser.test_get_encoded_word_gets_firstcCs|tjdddtjgddS)Nz&=?us-ascii?q?first?==?utf-8?q?second?=rOz=?utf-8?q?second?=rLr1rrr1test_get_encoded_word_gets_first_even_if_no_spacexszTestParser.test_get_encoded_word_quopri_utf_escape_follows_ctecCst|}|dfSr')r get_unstructured)rrtokenrrr _get_unsts zTestParser._get_unstcCs||jdddgddSr'r&rar1rrrtest_get_unstructured_nullsz%TestParser.test_get_unstructured_nullcCs||jdddgddSNr.r rbr1rrrtest_get_unstructured_one_wordsz)TestParser.test_get_unstructured_one_wordcCs||jdddgddS)N foo bar birdr rbr1rrr#test_get_unstructured_normal_phrases  z.TestParser.test_get_unstructured_normal_phrasecCs||jdddgddS)Nzfoo bar birdrfr rbr1rrr3test_get_unstructured_normal_phrase_with_whitespaces  z>TestParser.test_get_unstructured_normal_phrase_with_whitespacecCs||jdddgddS)Nz foo barz foo barr rbr1rrr(test_get_unstructured_leading_whitespaces  z3TestParser.test_get_unstructured_leading_whitespacecCs||jdddgddS)N foo bar zfoo bar r rbr1rrr)test_get_unstructured_trailing_whitespaces  z4TestParser.test_get_unstructured_trailing_whitespacecCs||jdddgddS)Nz foo bar z foo bar r rbr1rrr5test_get_unstructured_leading_and_trailing_whitespaces  z@TestParser.test_get_unstructured_leading_and_trailing_whitespacecCs||jdddgddS)Nz=?us-ascii?q?bar?=barr rbr1rrr(test_get_unstructured_one_valid_ew_no_wss  z3TestParser.test_get_unstructured_one_valid_ew_no_wscCs||jdddgddS)Nz=?us-ascii?q?bar?= bar bar r rbr1rrr(test_get_unstructured_one_ew_trailing_wss  z3TestParser.test_get_unstructured_one_ew_trailing_wscCs||jdddgddS)Nz=?us-ascii?q?bar?= birdzbar birdr rbr1rrr0test_get_unstructured_one_valid_ew_trailing_texts  z;TestParser.test_get_unstructured_one_valid_ew_trailing_textcCs||jdddgddS)Nzfoo =?us-ascii?q?bar?= birdrfr rbr1rrr6test_get_unstructured_phrase_with_ew_in_middle_of_texts  zATestParser.test_get_unstructured_phrase_with_ew_in_middle_of_textcCs||jdddgddS)Nz*foo =?us-ascii?q?bar?= =?us-ascii?q?bird?= foo barbirdr rbr1rrr(test_get_unstructured_phrase_with_two_ewsz3TestParser.test_get_unstructured_phrase_with_two_ewcCs||jdddgddS)Nz-foo =?us-ascii?q?bar?= =?us-ascii?q?bird?= zfoo barbird z foo barbird r rbr1rrr4test_get_unstructured_phrase_with_two_ew_trailing_wssz?TestParser.test_get_unstructured_phrase_with_two_ew_trailing_wscCs||jdddgddS)Nz =?us-ascii?q?bar?=z bar barr rbr1rrr4test_get_unstructured_phrase_with_ew_with_leading_wssz?TestParser.test_get_unstructured_phrase_with_ew_with_leading_wscCs||jdddgddS)Nz-foo =?us-ascii?q?bar?= =?us-ascii?q?bird?=rtr rbr1rrr1test_get_unstructured_phrase_with_two_ew_extra_wsszTestParser.test_get_unstructured_two_ew_extra_ws_trailing_textcCs||jdddgddS)Nz=?iso-8859-1?q?hello=20world?=z hello worldr rbr1rrr)test_get_unstructured_ew_with_internal_ws sz4TestParser.test_get_unstructured_ew_with_internal_wscCs||jdddgddS)Nz6 =?us-ascii?q?=20test?= =?us-ascii?q?=20foo?= valz test foo valz test foo valr rbr1rrr1test_get_unstructured_ew_with_internal_leading_ws(sztest_get_unstructured_invalid_base64_character_and_bad_paddingYszITestParser.test_get_unstructured_invalid_base64_character_and_bad_paddingcCs||jdddtjgddS)Nz=?utf-8?b?abcde?=Zabcder )r&rarZInvalidBase64LengthDefectr1rrr+test_get_unstructured_invalid_base64_lengthbsz6TestParser.test_get_unstructured_invalid_base64_lengthcCs"||jdddtjtjgddS)Nz=?utf-8?q?foo?==?utf-8?q?bar?=foobarr r&rarrMr1rrr/test_get_unstructured_no_whitespace_between_ewsksz:TestParser.test_get_unstructured_no_whitespace_between_ewscCs||jdddtjgddS)Nz!nowhitespace=?utf-8?q?somevalue?=Znowhitespacesomevaluer rr1rrr3test_get_unstructured_ew_without_leading_whitespacetsz>TestParser.test_get_unstructured_ew_without_leading_whitespacecCs||jdddtjgddS)Nz!=?utf-8?q?somevalue?=nowhitespaceZsomevaluenowhitespacer rr1rrr4test_get_unstructured_ew_without_trailing_whitespace}sz?TestParser.test_get_unstructured_ew_without_trailing_whitespacecCs||jdddtjgddS)Nz=?utf-8?q?somevalue?=aaZ somevalueaar rr1rrr;test_get_unstructured_without_trailing_whitespace_hang_caseszFTestParser.test_get_unstructured_without_trailing_whitespace_hang_casecCs||jdddgddS)Nz=?utf-8?q?=somevalue?=r rbr1rrrr}scCs||jdddgddS)Nz=?utf-8?X?=somevalue?=r rbr1rrr$test_get_unstructured_invalid_ew_ctesz/TestParser.test_get_unstructured_invalid_ew_ctecCs(|tjdddgd}||jddS)Nrr3r ptext)r&r get_qp_ctextr rrrrrrtest_get_qp_ctext_onlys z!TestParser.test_get_qp_ctext_onlycCsB|jdd}|dd}|dd}|tj||jdgd}dS) N\\\(z\()z\)r3r )rfc_printable_asciireplacer&r rrZwith_qprrrr test_get_qp_ctext_all_printabless    z+TestParser.test_get_qp_ctext_all_printablescCs|tjdddgddS)Nfoo der.r3 der&r rr1rrr&test_get_qp_ctext_two_words_gets_firsts z1TestParser.test_get_qp_ctext_two_words_gets_firstcCs|tjdddgddS)Nfoo der.r3 derr1rrr)test_get_qp_ctext_following_wsp_preserveds z4TestParser.test_get_qp_ctext_following_wsp_preservedcCs|tjdddgddS)Nzfoo)r.r3rrr1rrr(test_get_qp_ctext_up_to_close_paren_onlys z3TestParser.test_get_qp_ctext_up_to_close_paren_onlycCs|tjdddgddS)Nzfoo )r.r3z )rr1rrr2test_get_qp_ctext_wsp_before_close_paren_preserveds z=TestParser.test_get_qp_ctext_wsp_before_close_paren_preservedcCs|tjdddgddS)Nzfoo)barr.r3z)barrr1rrr&test_get_qp_ctext_close_paren_mid_words z1TestParser.test_get_qp_ctext_close_paren_mid_wordcCs|tjdddgddS)Nzfoo(r.r3rrr1rrr'test_get_qp_ctext_up_to_open_paren_onlys z2TestParser.test_get_qp_ctext_up_to_open_paren_onlycCs|tjdddgddS)Nzfoo (r.r3z (rr1rrr1test_get_qp_ctext_wsp_before_open_paren_preserveds zTestParser.test_get_bare_quoted_string_following_wsp_preservedcCs|tjdddgddS)Nz "foo bar moo"z foo bar moor rr1rrr*test_get_bare_quoted_string_multiple_words1s z5TestParser.test_get_bare_quoted_string_multiple_wordscCs|tjdddgddS)Nz " foo moo "z foo moo r rr1rrr8test_get_bare_quoted_string_multiple_words_wsp_preserved5s zCTestParser.test_get_bare_quoted_string_multiple_words_wsp_preservedcCs|tjdddgddS)Nz"foo"barrr.rmrr1rrr/test_get_bare_quoted_string_end_dquote_mid_word9s z:TestParser.test_get_bare_quoted_string_end_dquote_mid_wordcCs|tjdddgddS)Nz "foo\"in"az "foo\"in"zfoo"inarr1rrr)test_get_bare_quoted_string_quoted_dquote=s z4TestParser.test_get_bare_quoted_string_quoted_dquotecCs|tjdddtjgddS)Nz"aa"zaar )r&r rrrZr1rrr*test_get_bare_quoted_string_non_printablesAsz5TestParser.test_get_bare_quoted_string_non_printablescCs8|tjdddtjgd|tjdddtjgddS)Nz"foorr.r z"foo z"foo "r=rr1rrr)test_get_bare_quoted_string_no_end_dquoteFsz4TestParser.test_get_bare_quoted_string_no_end_dquotecCs|tjdddgddSrrr1rrr(test_get_bare_quoted_string_empty_quotesNs z3TestParser.test_get_bare_quoted_string_empty_quotescCs"|tjdddtjtjgddS)Nz"=?utf-8?Q?not_really_valid?="z"not really valid"znot really validr rr1rrrtest_encoded_word_inside_quotesSsz*TestParser.test_encoded_word_inside_quotesc Cs,|tjdddgddg}||jddS)N (comment)r3r comment)r&r get_commentr rrrrrrtest_get_comment_only^sz TestParser.test_get_comment_onlycCsp|tjtdWdn1s,0Y|tjtdWdn1sb0YdS)Nrz (foo")rArrBr rr1rrr&test_get_comment_must_start_with_parencs(z1TestParser.test_get_comment_must_start_with_parenc Cs|tjdddgddgdS)Nz (comment) rr3 rr&r rr1rrr(test_get_comment_following_wsp_preservedisz3TestParser.test_get_comment_following_wsp_preservedc Cs|tjdddgddgdS)Nz (foo bar) (foo bar)r3rrrr1rrrtest_get_comment_multiple_wordsmsz*TestParser.test_get_comment_multiple_wordsc Cs|tjdddgddgdS)Nz( foo bar ) z ( foo bar )r3rz foo bar rr1rrr-test_get_comment_multiple_words_wsp_preservedqs z8TestParser.test_get_comment_multiple_words_wsp_preservedc Cs|tjdddgddgdS)Nz(foo)bar(foo)r3rmr.rr1rrr#test_get_comment_end_paren_mid_wordvsz.TestParser.test_get_comment_end_paren_mid_wordc Cs|tjdddgddgdS)Nz(foo\) \(\)bar)r3r z foo) ()barrr1rrrtest_get_comment_quoted_parenszsz)TestParser.test_get_comment_quoted_parensc Cs"|tjdddtjgddgdS)Nz (foobar)r3r zfoobar)r&r rrrZr1rrrtest_get_comment_non_printable~s z)TestParser.test_get_comment_non_printablec Cs@|tjdddtjgddg|tjdddtjgddgdS) Nz(foo barrr3r rz (foo bar z (foo bar )rjr&r rrrMr1rrrtest_get_comment_no_end_parens  z(TestParser.test_get_comment_no_end_parenc Cs0|tjdddgddg}||djddS)Nz (foo(bar))r3r zfoo(bar)r/rmr&r rr contentrrrrtest_get_comment_nested_commentsz*TestParser.test_get_comment_nested_commentc Cs0|tjdddgddg}||djddS)Nz(foo ( bar ) )r3r z foo ( bar ) r bar rrrrr#test_get_comment_nested_comment_wspsz.TestParser.test_get_comment_nested_comment_wspc Cs|tjdddgddgdS)Nz()r3r rr1rrrtest_get_comment_empty_commentsz)TestParser.test_get_comment_empty_commentc Csp|tjdddgddg}tdddD]6}||djd|d d d |d |d}q&||jd dS) N (((((foo)))))r3r ((((foo))))rrr/r.r)r&r rranger r)rrirrr!test_get_comment_multiple_nestings* z,TestParser.test_get_comment_multiple_nestingc Cs&|tjdddtjgdddgdS)Nz (((((foo)))rr3rr rrr1rrr'test_get_comment_missing_end_of_nestingsz2TestParser.test_get_comment_missing_end_of_nestingc Cs0|tjdddgddg}||djddS)Nz (foo (b\)))r3r z foo (b\))rzb)rrrrr%test_get_comment_qs_in_nested_commentsz0TestParser.test_get_comment_qs_in_nested_commentc Cs*|tjdddgdg}||jddS)Nz r3r cfws)r&r get_cfwsr rrrrrrtest_get_cfws_only_wss z TestParser.test_get_cfws_only_wsc Cs0|tjdddgddg}||djddS)Nrr3r r.rr&r rr rrrrrtest_get_cfws_only_commentsz%TestParser.test_get_cfws_only_commentc CsD|tjdddgdddg}||djd||djddS)Nz (foo ) ( bar) r3r r=rwr/rrrrrtest_get_cfws_only_mixeds  z#TestParser.test_get_cfws_only_mixedc Cs0|tjdddgddg}||djddS)Nz (foo) bar(foo) r3rmr.rrrrrr test_get_cfws_ends_at_non_leadersz+TestParser.test_get_cfws_ends_at_non_leaderc Cs0|tjdddgddg}||djddS)Nz(foo) r r3r.rrrrrr#test_get_cfws_ends_at_non_printablesz.TestParser.test_get_cfws_ends_at_non_printablec Cs4|tjdddtjgddg}||djddS)Nz(foo ) "test"z(foo ) r3z"test"zfoo r)r&r rrrZr rrrrr&test_get_cfws_non_printable_in_comments  z1TestParser.test_get_cfws_non_printable_in_commentc Cs4|tjdddtjgddg}||djddS)Nz (foo z (foo )r3r r=r/)r&r rrrMr rrrrr$test_get_cfws_header_ends_in_comments  z/TestParser.test_get_cfws_header_ends_in_commentc CsH|tjdddgdddg}||djdg||djdgdS)Nz(foo (bar)) ((a)(a))r3r z foo (bar)z(a)(a)rr)r&r rr rrrrr&test_get_cfws_multiple_nested_commentss z1TestParser.test_get_cfws_multiple_nested_commentscCsD|tjdddgd}||jd||jd||jddS)Nz"bob"bobr quoted-string)r&r get_quoted_stringr r quoted_valuerrqsrrrtest_get_quoted_string_onlys  z&TestParser.test_get_quoted_string_onlycCs6|tjdddgd}||jd||jddS)Nz "bob"  bob r  "bob" r)r&r rr rrrrrrtest_get_quoted_string_with_wsps  z*TestParser.test_get_quoted_string_with_wspcCsb|tjdddgd}||ddjd||ddjd||jd ||jd dS) Nz (foo) "bob"(bar)rr rr/r.rrmrrr&r rr rrrrrr,test_get_quoted_string_with_comments_and_wsps z7TestParser.test_get_quoted_string_with_comments_and_wspcCs`|tjdddgd}||djddg||djdg||jd ||jd dS) Nz (foo) (bar) "bob"(bird)rr rr.rmrbirdrrr&r rr rrrrrrr-test_get_quoted_string_with_multiple_commentssz8TestParser.test_get_quoted_string_with_multiple_commentscCsN|tjdddtjgd}||djdg||jd||jddS)Nz ( ) "bob" bobr r r "bob" r&r rrrZr rrrrrrr/test_get_quoted_string_non_printable_in_commentsz:TestParser.test_get_quoted_string_non_printable_in_commentcCsN|tjdddtjgd}||djdg||jd||jddS)Nz (a) "a " a r rrza z "a "r"rrrr0test_get_quoted_string_non_printable_in_qcontentsz;TestParser.test_get_quoted_string_non_printable_in_qcontentcCsJ|tjdddgd}||djdg||jd||jddS)Nz (a) "foo bar "z foo bar r rrz foo bar z "foo bar "rrrrr"test_get_quoted_string_internal_ws sz-TestParser.test_get_quoted_string_internal_wscCsb|tjdddtjgd}||djdg||djdg||jd||jd dS) Nz (a) "bob" (az (a) "bob" (a)rr rrrrr r&r rrrMr rrrrrrr-test_get_quoted_string_header_ends_in_commentsz8TestParser.test_get_quoted_string_header_ends_in_commentcCsN|tjdddtjgd}||djdg||jd||jddS) Nz (a) "bobz (a) "bob"rr rrrr!r'rrrr.test_get_quoted_string_header_ends_in_qcontentsz9TestParser.test_get_quoted_string_header_ends_in_qcontentcCs:|tjtdWdn1s,0YdS)Nz (ab) xyz)rArrBr rr1rrr'test_get_quoted_string_no_quoted_string$sz2TestParser.test_get_quoted_string_no_quoted_stringcCs6|tjdddgd}||jd||jddS)Nz "bob" feez "bob" rZfeerrrrrrr)test_get_quoted_string_qs_ends_at_noncfws(s  z4TestParser.test_get_quoted_string_qs_ends_at_noncfwscCs(|tjdddgd}||jddS)Nrr atom)r&r get_atomr rrr,rrrtest_get_atom_only0s zTestParser.test_get_atom_onlycCs|tjdddgddS)Nz bob rr r&r r-r1rrrtest_get_atom_with_wsp5s z!TestParser.test_get_atom_with_wspcCsF|tjdddgd}||ddjd||ddjddS) Nz (foo) bob(bar)rr rr/r.rrm)r&r r-r rr.rrr#test_get_atom_with_comments_and_wsp9s  z.TestParser.test_get_atom_with_comments_and_wspcCsD|tjdddgd}||djddg||djdgdS) Nz (foo) (bar) bob(bird)rr rr.rmrrr&r r-r rr.rrr$test_get_atom_with_multiple_comments?s z/TestParser.test_get_atom_with_multiple_commentscCs2|tjdddtjgd}||djdgdS)Nz ( ) bobrr rr r&r r-rrZr rr.rrr&test_get_atom_non_printable_in_commentFs z1TestParser.test_get_atom_non_printable_in_commentcCs2|tjdddtjgd}||djdgdS)Nz (a) a r$r rrr5r.rrr$test_get_atom_non_printable_in_atextLs z/TestParser.test_get_atom_non_printable_in_atextcCsF|tjdddtjgd}||djdg||djdgdS)Nz (a) bob (az (a) bob (a)rr rrr)r&r r-rrMr rr.rrr$test_get_atom_header_ends_in_commentRs z/TestParser.test_get_atom_header_ends_in_commentcCs:|tjtdWdn1s,0YdS)Nz (ab) rArrBr r-r1rrrtest_get_atom_no_atomYsz TestParser.test_get_atom_no_atomcCs:|tjtdWdn1s,0YdS)Nz (ab) @r9r1rrr$test_get_atom_no_atom_before_special]sz/TestParser.test_get_atom_no_atom_before_specialcCsB|tjdddgd}||djdg||djdgdS) Nz (foo) bob(bar) @bangz (foo) bob(bar) rz@bangrr.rrmr3r.rrr"test_get_atom_atom_ends_at_specialas  z-TestParser.test_get_atom_atom_ends_at_specialcCs|tjdddgddS)Nz bob fredzbob zbob Zfredr0r1rrr"test_get_atom_atom_ends_at_noncfwsgs z-TestParser.test_get_atom_atom_ends_at_noncfwscCs|tjdddgddSNz=?utf-8?q?=20bob?=rr r0r1rrrtest_get_atom_rfc2047_atomks z%TestParser.test_get_atom_rfc2047_atomcCs8|tjdddgd}||jd|t|ddS)Nz foo.bar.bangr z dot-atom-text)r&r get_dot_atom_textr rlenrZ dot_atom_textrrrtest_get_dot_atom_textqs  z!TestParser.test_get_dot_atom_textcCs|tjdddgd}dSrdr&r rArCrrr)test_get_dot_atom_text_lone_atom_is_validws z4TestParser.test_get_dot_atom_text_lone_atom_is_validcCs:|tjtdWdn1s,0YdS)Nz.foo.barrArrBr rAr1rrr,test_get_dot_atom_text_raises_on_leading_dot{sz7TestParser.test_get_dot_atom_text_raises_on_leading_dotcCs:|tjtdWdn1s,0YdS)Nzfoo.bar.rGr1rrr-test_get_dot_atom_text_raises_on_trailing_dotsz8TestParser.test_get_dot_atom_text_raises_on_trailing_dotcCs|tjtdWdn1s,0Y|tjtdWdn1sb0Y|tjtdWdn1s0YdS)Nz foo.barz@foo.barz "foo.bar"rGr1rrr2test_get_dot_atom_text_raises_on_leading_non_atexts ((z=TestParser.test_get_dot_atom_text_raises_on_leading_non_atextcCs|tjdddgd}dSrrErCrrr.test_get_dot_atom_text_trailing_text_preserveds z9TestParser.test_get_dot_atom_text_trailing_text_preservedcCs|tjdddgd}dS)Nzfoo .barr.z .barrErCrrr,test_get_dot_atom_text_trailing_ws_preserveds z7TestParser.test_get_dot_atom_text_trailing_ws_preservedcCs8|tjdddgd}||jd|t|ddS)Nz foo.bar.bingr zdot-atomr/)r&r get_dot_atomr rrB)rZdot_atomrrrtest_get_dot_atom_onlys  z!TestParser.test_get_dot_atom_onlycCs|tjdddgddS)Nz foo.bar.bing  foo.bar.bing r r&r rMr1rrrtest_get_dot_atom_with_wsps z%TestParser.test_get_dot_atom_with_wspcCs|tjdddgddS)Nz (sing) foo.bar.bing (here) rOr rPr1rrr'test_get_dot_atom_with_comments_and_wspsz2TestParser.test_get_dot_atom_with_comments_and_wspcCs|tjdddgddS)Nz (sing) foo.bar .bing (here) z (sing) foo.bar z foo.bar z .bing (here) rPr1rrr%test_get_dot_atom_space_ends_dot_atomsz0TestParser.test_get_dot_atom_space_ends_dot_atomcCs:|tjtdWdn1s,0YdSNz (foo) rArrBr rMr1rrr test_get_dot_atom_no_atom_raisessz+TestParser.test_get_dot_atom_no_atom_raisescCs:|tjtdWdn1s,0YdS)Nz (foo) .barrUr1rrr$test_get_dot_atom_leading_dot_raisessz/TestParser.test_get_dot_atom_leading_dot_raisescCs:|tjtdWdn1s,0YdS)Nz bar..bangrUr1rrr!test_get_dot_atom_two_dots_raisessz,TestParser.test_get_dot_atom_two_dots_raisescCs:|tjtdWdn1s,0YdS)Nz (foo) bar.bang. foorUr1rrr%test_get_dot_atom_trailing_dot_raisessz0TestParser.test_get_dot_atom_trailing_dot_raisescCs|tjdddgddSr>rPr1rrrtest_get_dot_atom_rfc2047_atoms z)TestParser.test_get_dot_atom_rfc2047_atomcCs:|tjdddgd}||jd||djddS)Nz (foo) bar (bang) :ahz (foo) bar (bang) rz:ahr,rr)r&r get_wordr rrZwordrrrtest_get_word_atom_yields_atoms  z)TestParser.test_get_word_atom_yields_atomcCs:|tjtdWdn1s,0YdS)Nz(Recipients list suppressed)rArrBr r[r1rrrtest_get_word_all_CFWSsz!TestParser.test_get_word_all_CFWScCsZ|tjdddgd}||jd||djd||djd||jddS) Nz"bar " (bang) ahz"bar " (bang) roZahrrrrp)r&r r[r rrrr\rrrtest_get_word_qs_yields_qss z%TestParser.test_get_word_qs_yields_qscCs|tjdddgddS)Nzfoo.r..)r&r r[r1rrrtest_get_word_ends_at_dots z$TestParser.test_get_word_ends_at_dotcCs(|tjdddgd}||jddS)N""Fred A. Johnson" is his name, oh."Fred A. Johnson" is his nameFred A. Johnson is his name, oh.phrase)r&r get_phraser rrrfrrrtest_get_phrase_simplesz!TestParser.test_get_phrase_simplecCsJ|tjdddgd}||ddjdg||ddjdgdS) N. (A) bird (in (my|your)) "hand " is messy <> + (A) bird (in (my|your)) "hand " is messy z bird hand is messy <> rAr in (my|your))r&r rgr rrhrrrtest_get_phrase_complexsz"TestParser.test_get_phrase_complexcCsF|tjdddtjgdd}|t|d||djdgdS)NFred A.(weird).O JohnsonFred A. .O Johnsonrr weirdr&r rgrObsoleteHeaderDefectr rBrrhrrrtest_get_phrase_obsoletes z#TestParser.test_get_phrase_obsoletec CsN|tjdddtjgtjgdd}|t|d||djdgdS)N(even weirder).namez .namerr rr even weirder) r&r rgrrMrur rBrrhrrr+test_get_phrase_pharse_must_start_with_wordsz6TestParser.test_get_phrase_pharse_must_start_with_wordcCsF|tjdddtjgdd}|t|d||djdgdS) N)simple phrase.(with trailing comment):boo%simple phrase.(with trailing comment)zsimple phrase. r:boorrwith trailing commentrtrhrrr$test_get_phrase_ending_with_obsoletes z/TestParser.test_get_phrase_ending_with_obsoletecCs:|tjtdWdn1s,0YdSrT)rArrBr rgr1rrrget_phrase_cfws_only_raises sz&TestParser.get_phrase_cfws_only_raisescCs6|tjdddgd}||jd||jddS)Nzdinsdale@python.orgdinsdale @python.org local-partr&r get_local_partr r local_partrrrrrtest_get_local_part_simples  z%TestParser.test_get_local_part_simplecCs(|tjdddgd}||jddS)NzFred.A.Johnson@python.orgFred.A.Johnsonrr&r rr rrrrrtest_get_local_part_with_dotsz'TestParser.test_get_local_part_with_dotcCs(|tjdddgd}||jddS)Nz Fred.A.Johnson @python.orgz Fred.A.Johnson  Fred.A.Johnson rrrrrrr#test_get_local_part_with_whitespacesz.TestParser.test_get_local_part_with_whitespacecCsX|tjdddgd}||jd||ddjdg||ddjd gdS) Nz/ (foo) Fred.A.Johnson (bar (bird)) @python.orgz$ (foo) Fred.A.Johnson (bar (bird)) rrrrr.r bar (bird)r&r rr rrrrrrtest_get_local_part_with_cfws(sz(TestParser.test_get_local_part_with_cfwscCs6|tjdddgd}||jd||jddS)Nz"dinsdale"@python.orgz "dinsdale"rrrrrrrr!test_get_local_part_simple_quoted3s  z,TestParser.test_get_local_part_simple_quotedcCs(|tjdddgd}||jddS)Nz"Fred.A.Johnson"@python.orgz"Fred.A.Johnson"rrrrrrr#test_get_local_part_with_quoted_dot9sz.TestParser.test_get_local_part_with_quoted_dotcCs(|tjdddgd}||jddS)Nz "Fred A. Johnson" @python.orgz "Fred A. Johnson" z "Fred A. Johnson" rzFred A. Johnsonrrrrr*test_get_local_part_quoted_with_whitespaceBsz5TestParser.test_get_local_part_quoted_with_whitespacecCsX|tjdddgd}||jd||ddjdg||ddjd gdS) Nz4 (foo) " Fred A. Johnson " (bar (bird)) @python.orgz) (foo) " Fred A. Johnson " (bar (bird)) z " Fred A. Johnson " rz Fred A. Johnson rr.rrrrrrr$test_get_local_part_quoted_with_cfwsKsz/TestParser.test_get_local_part_quoted_with_cfwscCs,|tjdddtjgd}||jddS)NzFred. A.Johnson@python.orgzFred. A.Johnsonrrr&r rrrur rrrrr#test_get_local_part_simple_obsoleteWsz.TestParser.test_get_local_part_simple_obsoletecCs,|tjdddtjgd}||jddS)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 rzFred.A.Johnson.and dogs rrrrr&test_get_local_part_complex_obsolete_1`sz1TestParser.test_get_local_part_complex_obsolete_1cCs0|tjdddtjgdd}||jddS)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 dogsrrzFred.A.Johnson and dogsr&r rrrMr rrrrr,test_get_local_part_complex_obsolete_invalidis z7TestParser.test_get_local_part_complex_obsolete_invalidcCs:|tjtdWdn1s,0YdSrTrArrBr rr1rrr"test_get_local_part_no_part_raisesrsz-TestParser.test_get_local_part_no_part_raisescCs:|tjtdWdn1s,0YdS)Nz (foo) @python.orgrr1rrr*test_get_local_part_special_instead_raisesvsz5TestParser.test_get_local_part_special_instead_raisescCs0|tjdddtjgdd}||jddS)Nz borris.@python.orgz borris.rrborris.rrrrr test_get_local_part_trailing_dotzs z+TestParser.test_get_local_part_trailing_dotcCs0|tjdddtjgdd}||jddS)Nz borris. @python.orgz borris. rrrrrrrr(test_get_local_part_trailing_dot_with_wss z3TestParser.test_get_local_part_trailing_dot_with_wscCs0|tjdddtjgdd}||jddS)Nz.borris@python.org.borrisrrrrrrrtest_get_local_part_leading_dots z*TestParser.test_get_local_part_leading_dotcCs0|tjdddtjgdd}||jddS)Nz .borris@python.orgz .borrisrrrrrrrr(test_get_local_part_leading_dot_after_wss z3TestParser.test_get_local_part_leading_dot_after_wscCs0|tjdddtjgdd}||jddS)Nz borris.(foo).natasha@python.orgz borris.(foo).natashaz borris. .natasharrzborris..natasharrrrr%test_get_local_part_double_dot_raisess z0TestParser.test_get_local_part_double_dot_raisescCs0|tjdddtjgdd}||jddS)N""example" example"@example.comz""example" example"example exampler @example.comrrrrr/test_get_local_part_quoted_strings_in_atom_lists z:TestParser.test_get_local_part_quoted_strings_in_atom_listcCs0|tjdddtjgdd}||jddS)Nz#"\\"example\\" example"@example.comz"\\"example\\" example"z\example\\ exampler@rrrrrr5test_get_local_part_valid_and_invalid_qp_in_atom_lists z@TestParser.test_get_local_part_valid_and_invalid_qp_in_atom_listcCs,|tjdddtjgd}||jddS)Nuexámple@example.comuexámpler)r&r rrZNonASCIILocalPartDefectr rrrrr"test_get_local_part_unicode_defectsz-TestParser.test_get_local_part_unicode_defectcCs(|tjdddgd}||jddSr)r&r get_dtextr rrZdtextrrrtest_get_dtext_onlys zTestParser.test_get_dtext_onlycCs |tj|j|j|jgd}dSr')r&r rrfc_dtext_charsrrrrtest_get_dtext_all_dtexts z#TestParser.test_get_dtext_all_dtextcCs|tjdddgddSrr&r rr1rrr#test_get_dtext_two_words_gets_firsts z.TestParser.test_get_dtext_two_words_gets_firstcCs|tjdddgddSrrr1rrr&test_get_dtext_following_wsp_preserveds z1TestParser.test_get_dtext_following_wsp_preservedcCs6|tjdddtjgd}||jdjdddS)Nzfoobar]r]rr)r&r rrrZr r rrrrrtest_get_dtext_non_printabless z(TestParser.test_get_dtext_non_printablescCs|tjdddtjgd}dS)Nzfoo\]\[\\bar\b\e\l\lz foo][\barbellr )r&r rrrurrrrtest_get_dtext_with_qpsz!TestParser.test_get_dtext_with_qpcCs|tjdddgddS)Nzfoo]r.rrr1rrr'test_get_dtext_up_to_close_bracket_onlys z2TestParser.test_get_dtext_up_to_close_bracket_onlycCs|tjdddgddS)Nzfoo ]r.z ]rr1rrr1test_get_dtext_wsp_before_close_bracket_preserveds z|tjdddtjgd}||jd||jddgdS)Nz?(foo),, (blue)@example.com (bar),@two.(foo) example.com (bird):z% ,, @example.com ,@two. example.com :r rrr)r&r rrrur rrrrrrtest_get_obs_route_complexsz%TestParser.test_get_obs_route_complexcCs:|tjtdWdn1s,0YdS)Nz(foo) @example.com,rArrBr rr1rrr-test_get_obs_route_no_route_before_end_raisessz8TestParser.test_get_obs_route_no_route_before_end_raisescCs:|tjtdWdn1s,0YdS)Nz (foo) [abc],rr1rrr1test_get_obs_route_no_route_before_special_raisesszr angle-addrrrr r&r get_angle_addrr rrr assertIsNonerouterrZ angle_addrrrrtest_get_angle_addr_simples z%TestParser.test_get_angle_addr_simplecCs^|tjdddtjgd}||jd||j||j ||j ||j ddS)N<>r r) r&r rrrMr rrrrrrrrrrtest_get_angle_addr_emptys   z$TestParser.test_get_angle_addr_emptycCs^|tjdddgd}||jd||jd||jd||j||j ddS)Nz<""@example.com>r rrz""@example.comrrrrr"test_get_angle_addr_qs_only_quotess z-TestParser.test_get_angle_addr_qs_only_quotescCs^|tjdddgd}||jd||jd||jd||j||j ddS)Nz" (foo) (bar)z r rrrrrrrrrtest_get_angle_addr_with_cfwss z(TestParser.test_get_angle_addr_with_cfwscCsP|tjdddgd}||jd||jd||j||jddS)Nz<"Fred Perfect"@[127.0.0.1]>r z Fred Perfectrz"Fred Perfect"@[127.0.0.1] r&r rr rrrrrrrrr)test_get_angle_addr_qs_and_domain_literal)s z4TestParser.test_get_angle_addr_qs_and_domain_literalcCsP|tjdddgd}||jd||jd||j||jddS)Nz!<(foo) dinsdale@example.com(bar)>z< dinsdale@example.com >r rrrrrrrr!test_get_angle_addr_internal_cfws5s z,TestParser.test_get_angle_addr_internal_cfwscCsZ|tjdddtjgd}||jd||jd||jddg||j ddS)NzI(foo)<@example.com, (bird) @two.example.com: dinsdale@example.com> (bar) z8 <@example.com, @two.example.com: dinsdale@example.com> r rrrr) r&r rrrur rrrrrrrrtest_get_angle_addr_obs_routeAsz(TestParser.test_get_angle_addr_obs_routecCsT|tjdddtjgd}||jd||jd||j ||j ddS)Nzzr rrrr rrrr3test_get_angle_addr_missing_closing_angle_with_cfwsYs z>TestParser.test_get_angle_addr_missing_closing_angle_with_cfwscCsP|tjdddgd}||jd||jd||j||jddS)Nz" (foo), nextz (foo)z rrrrrrrrr#test_get_angle_addr_ends_at_speciales z.TestParser.test_get_angle_addr_ends_at_specialcCs:|tjtdWdn1s,0YdSrrArrBr rr1rrr"test_get_angle_addr_no_angle_raiseqsz-TestParser.test_get_angle_addr_no_angle_raisecCs:|tjtdWdn1s,0YdS)Nz (foo) , nextrr1rrr2test_get_angle_addr_no_angle_before_special_raisesusz=TestParser.test_get_angle_addr_no_angle_before_special_raisescCs:|tjtdWdn1s,0YdS)Nrmrr1rrr#test_get_angle_addr_no_angle_raisesysz.TestParser.test_get_angle_addr_no_angle_raisescCs:|tjtdWdn1s,0YdS)Nz (foo) <, barrr1rrr.test_get_angle_addr_special_after_angle_raises}sz9TestParser.test_get_angle_addr_special_after_angle_raisescCs6|tjdddgd}||jd||jddS)NzFred A Johnsonr display-namer&r get_display_namer r display_namerrrrrtest_get_display_name_simplesz'TestParser.test_get_display_name_simplecCs6|tjdddgd}||jd||jddS)Nrbrcz"Fred A. Johnson is his name"rerrdrrrrrtest_get_display_name_complex1sz)TestParser.test_get_display_name_complex1cCsX|tjdddgd}||ddjdg||ddjdg||jd dS) Nrjrkz "bird hand is messy" rlrrmrrnzbird hand is messy)r&r rr rrrrrrtest_get_display_name_complex2sz)TestParser.test_get_display_name_complex2cCsT|tjdddtjgdd}|t|d||djdg||jddS)Nrpz"Fred A. .O Johnson"rr rrrsrq r&r rrrur rBrrrrrrtest_get_display_name_obsoletes z)TestParser.test_get_display_name_obsoletec Cs\|tjdddtjgtjgdd}|t|d||djdg||j ddS) Nrwz ".name"rr rrrxz.name) r&r rrrMrur rBrrrrrr1test_get_display_name_pharse_must_start_with_wordszr r!Dinsdalerrr) r&r r"r rrrrrrrr#rrrtest_get_name_addr_atom_names z'TestParser.test_get_name_addr_atom_namecCs^|tjdddgd}||jd||jd||jd||j||j ddS)Nz2(foo) Dinsdale (bar) (bird)z! Dinsdale r r%rrr r&r r"r rrrrrrr#rrr&test_get_name_addr_atom_name_with_cfwss z1TestParser.test_get_name_addr_atom_name_with_cfwscCsf|tjdddtjgdd}||jd||jd||jd| |j ||j ddS) Nz4(foo) Roy.A.Bear (bar) (bird)z% "Roy.A.Bear" rr Roy.A.Bearrrr) r&r r"rrur rrrrrrr#rrr*test_get_name_addr_name_with_cfws_and_dotss  z5TestParser.test_get_name_addr_name_with_cfws_and_dotscCs^|tjdddgd}||jd||jd||jd||j||j ddS)N#"Roy.A.Bear" r r)rrrr'r#rrrtest_get_name_addr_qs_names z%TestParser.test_get_name_addr_qs_namecCsf|tjdddtjgd}||jd||jd||jd||j dg||j ddS)Nz5"Roy.A.Bear" <@two.example.com: dinsdale@example.com>r r)rrrr) r&r r"rrur rrrrrr#rrrtest_get_name_addr_with_routesz(TestParser.test_get_name_addr_with_routecCs^|tjdddgd}||jd||jd||jd||j||j ddS)Nz)"Roy.A.Bear" , nextr+rr)rrrr'r#rrr"test_get_name_addr_ends_at_specials z-TestParser.test_get_name_addr_ends_at_specialcCs:|tjtdWdn1s,0YdSrTrArrBr r"r1rrr$test_get_name_addr_no_content_raises*sz/TestParser.test_get_name_addr_no_content_raisescCs:|tjtdWdn1s,0YdS)Nz (foo) ,r/r1rrr3test_get_name_addr_no_content_before_special_raises.sz>TestParser.test_get_name_addr_no_content_before_special_raisescCs:|tjtdWdn1s,0YdS)Nrr/r1rrr5test_get_name_addr_no_angle_after_display_name_raises2sz@TestParser.test_get_name_addr_no_angle_after_display_name_raisescCsj|tjdddgd}||jd||j||jd||jd||j ||j ddS)Nrr mailboxrr r&r get_mailboxr rrrrrrrrr3rrrtest_get_mailbox_addr_spec_only8s  z*TestParser.test_get_mailbox_addr_spec_onlycCsj|tjdddgd}||jd||j||jd||jd||j ||j ddS)Nrr r3rrrr4r6rrr test_get_mailbox_angle_addr_onlyFs  z+TestParser.test_get_mailbox_angle_addr_onlycCsl|tjdddgd}||jd||jd||jd||jd||j ||j ddS)N$"Roy A. Bear" r r3 Roy A. Bearrrr r&r r5r rrrrrrrr6rrrtest_get_mailbox_name_addrTs z%TestParser.test_get_mailbox_name_addrcCsl|tjdddgd}||jd||jd||jd||jd||j ||j ddS) Nz*"Roy A. Bear" , restr9z, restr3r:rrrr;r6rrr test_get_mailbox_ends_at_specialbs z+TestParser.test_get_mailbox_ends_at_specialcCsL|tjdddtjgdd}||jd||jd||jddSr) r&r r5rrMr rrrr6rrr,test_get_mailbox_quoted_strings_in_atom_listps z7TestParser.test_get_mailbox_quoted_strings_in_atom_listcCs|tjdddgd}||jd|t|jd|jd}||j||j d||j d||j ||j d||j|j dS)Nrr mailbox-listr/rrr)r&r get_mailbox_listr rrB mailboxesrrrrrr all_mailboxes)r mailbox_listr3rrr!test_get_mailbox_list_single_addr}s$   z,TestParser.test_get_mailbox_list_single_addrcCsr|tjdddgd}||jd|t|jd||jdjd||jdjd||j|jdS) Nz/dinsdale@example.com, dinsdale@test.example.comr r?rrrr/dinsdale@test.example.com) r&r r@r rrBrArrBrrCrrr%test_get_mailbox_list_two_simple_addrs$z0TestParser.test_get_mailbox_list_two_simple_addrcCs|tjdddgd}|t|jd||jdjd||jdjd||jdjd||jdjd ||j|jdS) NzS"Roy A. Bear" , "Fred Flintstone" r rrrr:r/rEFred Flintstone) r&r r@r rBrArrrBrFrrr#test_get_mailbox_list_two_name_addrs. z.TestParser.test_get_mailbox_list_two_name_addrcCs|tjdddtjgd}|t|jd||jdjd||jdj d||jdjd ||jdj d ||j|j dS) Nzd(foo) "Roy A. Bear" (bar), "Fred Flintstone" zV "Roy A. Bear" , "Fred Flintstone" r rrrr:r/rErH) r&r r@rrur rBrArrrBrFrrr!test_get_mailbox_list_two_complexs. z,TestParser.test_get_mailbox_list_two_complexc Cs|tjdddtjtjtjtjgd}|t|jd|t|j d||j dj d| |j dj ||j dj d| |j dj||j djd ||j d|jd||jdjd ||jdj d dS) NzY"Roy A. Bear"[] dinsdale@example.com, "Fred Flintstone" zT"Roy A. Bear"[] dinsdale@example.com, "Fred Flintstone" r r/rrinvalid-mailboxr:z "Roy A. Bear"rErH)r&r r@rrMrur rBrArBrrrrrrassertIsrFrrr.test_get_mailbox_list_unparseable_mailbox_nullsB  z9TestParser.test_get_mailbox_list_unparseable_mailbox_nullcCs|tjdddtjgd}|t|jd|t|jd||jdj d||jdj d||jdj d| |jd|jd||jdj d ||jdj d dS) NzU"Roy A. Bear" @@, "Fred Flintstone" r r/rrrr:rKrErH) r&r r@rrMr rBrArBrrrrLrFrrr.test_get_mailbox_list_junk_after_valid_addresss6  z9TestParser.test_get_mailbox_list_junk_after_valid_addresscCs|tjdddtjgdd}|t|jd||j|j||jdj d||jdj d||jdj d ||jdj d dS) Nz\"Roy A. Bear" , (bird),, "Fred Flintstone" zV"Roy A. Bear" , ,, "Fred Flintstone" rr rrr:r/rErH) r&r r@rrur rBrArBrrrFrrr(test_get_mailbox_list_empty_list_elements.  z3TestParser.test_get_mailbox_list_empty_list_elementcCsD|tjdddtjgdd}|t|jd||j|jdS)Nz (foo),, (bar)z ,, rr r) r&r r@rrur rBrArBrFrrr)test_get_mailbox_list_only_empty_elementss z4TestParser.test_get_mailbox_list_only_empty_elementscCsJ|tjdddgd}||jd|t|jd||j|jdS)Nz (hidden);z(hidden)r3; group-listr)r&r get_group_listr rrBrArBrZ group_listrrrtest_get_group_list_cfws_only%sz(TestParser.test_get_group_list_cfws_onlycCs^|tjdddgd}||jd|t|jd||j|j||jdjddS)Nz;dinsdale@example.org, "Fred A. Bear" r rRrr/ Fred A. Bear) r&r rSr rrBrArBrrTrrr test_get_group_list_mailbox_list1sz+TestParser.test_get_group_list_mailbox_listcCsN|tjdddtjgd}||jd|t|jd||j|j dS)Nz, (foo),,(bar)z, ,, r rRr) r&r rSrrur rrBrArBrTrrr"test_get_group_list_obs_group_list?sz-TestParser.test_get_group_list_obs_group_listcCsN|tjdddtjgd}||jd|t|jd||j|j dS)Nz(bar)r3r rRr) r&r rSrrMr rrBrArBrTrrr(test_get_group_list_comment_only_invalidKsz3TestParser.test_get_group_list_comment_only_invalidcCsX|tjdddgd}||jd||jd|t|jd||j|jdS)NMonty Python:;r group Monty Pythonr r&r get_groupr rrrBrArBrr[rrrtest_get_group_emptyYszTestParser.test_get_group_emptycCsd|tjdddtjgd}||jd|t|jd|t|j d||j dj ddS)Nzfoo: <>;r r.rr/r) r&r r^rrMr rrBrArBrr_rrrtest_get_group_null_addr_specfsz(TestParser.test_get_group_null_addr_speccCsX|tjdddgd}||jd||jd|t|jd||j|jdS)NzMonty Python: (hidden);Monty Python: ;r r[r\rr]r_rrrtest_get_group_cfws_onlyrsz#TestParser.test_get_group_cfws_onlycCsl|tjdddgd}||jd||jd|t|jd||j|j||jdj ddS)Nz4Monty Python: "Fred A. Bear" ;r r[r\r/rr) r&r r^r rrrBrArBrr_rrrtest_get_group_single_mailboxs z(TestParser.test_get_group_single_mailboxcCs|tjdddgd}||jd||jd|t|jd||j|j||jdjd||jd jd ||jd j d dS) NzhMonty Python: "Fred A. Bear" ,(foo) Roger , x@test.example.com;zcMonty Python: "Fred A. Bear" , Roger , x@test.example.com;r r[r\rrrVr/ZRogerrr) r&r r^r rrrBrArBrr_rrrtest_get_group_mixed_lists( z$TestParser.test_get_group_mixed_listcCs|tjdddtjtjgd}||jd||jd|t|j d|t|j d||j djd ||j d j d | |j d jdS) NzfMonty Python: "Fred A. Bear" ,(foo) Roger ping@exampele.com, x@test.example.com;zaMonty Python: "Fred A. Bear" , Roger ping@exampele.com, x@test.example.com;r r[r\rrrrVr/r) r&r r^rrMr rrrBrArBrrr_rrrtest_get_group_one_invalids$ z%TestParser.test_get_group_one_invalidcCs|tjdddtjgd}||jd||jd|t|j d||j |j ||j dj d||j djd ||j d j d ||j d jd ||j d j ddS)NzSMonty Python:"Fred A. Bear" ,eric@where.test,John zTMonty Python:"Fred A. Bear" ,eric@where.test,John ;r r[r\rrrrVr/zeric@where.testrZJohnz jdoe@test) r&r r^rrMr rrrBrArBrr_rrr$test_get_group_missing_final_semicols8 z/TestParser.test_get_group_missing_final_semicolcCsp|tjdddgd}||jd|t|jd||j|j||jdjd||djddS)Nrr addressr/rrr3 r&r get_addressr rrBrArBrrrhrrrtest_get_address_simples$ z"TestParser.test_get_address_simplecCsp|tjdddgd}||jd|t|jd||j|j||jdjd||djddS) Nz1(foo) "Fred A. Bear" <(bird)dinsdale@example.com>z' "Fred A. Bear" < dinsdale@example.com>r rhr/rrVr3 r&r rjr rrBrArBrrkrrrtest_get_address_complexs$ z#TestParser.test_get_address_complexcCsp|tjdddgd}||jd|t|jd||j|j||jdjd||djddS) Nz'=?utf-8?q?=C3=89ric?= uÉric r rhr/rr]r3rmrkrrr%test_get_address_rfc2047_display_names$ z0TestParser.test_get_address_rfc2047_display_namecCsn|tjdddgd}||jd|t|jd||j|j||djd||djddS)NrZr rhrr[r\rmrkrrrtest_get_address_empty_group s$  z'TestParser.test_get_address_empty_groupcCs|tjdddgd}||jd|t|jd||j|j||djd||djd||jdj ddS) Nz+Monty Python: x@example.com, y@example.com;r rhrrr[r\r) r&r rjr rrBrArBrrrkrrrtest_get_address_group s&  z!TestParser.test_get_address_groupcCs|tjdddgd}||jd|t|jd||j|j||jdjd||jdj d||djddS) Nz"foo bar"@example.comr rhr/rrrr3) r&r rjr rrBrArBrrrkrrr"test_get_address_quoted_local_part# s&z-TestParser.test_get_address_quoted_local_partcCsp|tjdddgd}||jd|t|jd||j|j||jdjd||djddS) Nzdinsdale@example.com, nextrrrhr/rrr3rirkrrr test_get_address_ends_at_special4 s z+TestParser.test_get_address_ends_at_specialc Cs|tjdddtjtjtjgd}||jd|t|jd|t|j d| |j dj ||j dj d||djddS)Nzping example.com, nextzping example.comrrhrr/rK) r&r rjrrMr rrBrArBrrrrkrrr(test_get_address_invalid_mailbox_invalidC s  z3TestParser.test_get_address_invalid_mailbox_invalidcCs^|tjdddtjgdd}||jdjd||jdjd||jdj ddS) Nrrrr rrrr) r&r rjrrMr rBrrrrkrrr,test_get_address_quoted_strings_in_atom_listT s z7TestParser.test_get_address_quoted_strings_in_atom_listcCsN|tjdddtjgd}||jd|t|jd||j|j dS)Nz(Recipient list suppressed)r3r address-listr) r&r get_address_listrrur rrBrArBrZ address_listrrrtest_get_address_list_CFWSb sz%TestParser.test_get_address_list_CFWScCs|tjdddgd}||jd|t|jd||j|j|dd|jDdd|jD||jdj d ||djd | |dj dS) Nrr rvr/cSsg|] }t|qSrr .0rrrr x zETestParser.test_get_address_list_mailboxes_simple..cSsg|] }t|qSrrzr{rrrr}y r~rrrh) r&r rwr rrBrArB addressesrrrrxrrr&test_get_address_list_mailboxes_simplem s$z1TestParser.test_get_address_list_mailboxes_simplecCs|tjdddgd}||jd|t|jd||j|j|dd|jDdd|jD||jdj d ||jd j d dS) Nz0foo@example.com, "Fred A. Bar" r rvrcSsg|] }t|qSrrzr{rrrr} r~zITestParser.test_get_address_list_mailboxes_two_simple..cSsg|] }t|qSrrzr{rrrr} r~rr.r/z Fred A. Bar) r&r rwr rrBrArBrrrrxrrr*test_get_address_list_mailboxes_two_simple~ s"z5TestParser.test_get_address_list_mailboxes_two_simplecCs|tjdddtjtjgd}||jd|t|jd||j|j |dd|jDdd|j D||jd j d ||jd jd ||j d jd ||jd j d||jdj ddS)Nzn"Roy A. Bear" , (ping) Foo ,Nobody Is. Special z_"Roy A. Bear" , Foo ,"Nobody Is. Special" r rvrcSsg|] }t|qSrrzr{rrrr} r~zFTestParser.test_get_address_list_mailboxes_complex..cSsg|] }t|qSrrzr{rrrr} r~rrr3rhr/rrNobody Is. Special)r&r rwrrur rrBrArBrrrrrxrrr'test_get_address_list_mailboxes_complex s0 z2TestParser.test_get_address_list_mailboxes_complexc CsT|tjdddtjtjtjtjtjtjgd}||jd|t|j d|t|j d|dd|j Dd d|j D||j d j d ||j d jd ||j d jd ||j djd |t|j d j d|t|j dj d |t|j dj d ||j dj d j d||j dj d jddS)Nzl"Roy A. Bear" , (ping) Foo x@example.com[],Nobody Is. Special <(bird)example.(bad)com>z^"Roy A. Bear" , Foo x@example.com[],"Nobody Is. Special" < example. com>r rvr/rcSsg|] }t|qSrrzr{rrrr} r~zPTestParser.test_get_address_list_mailboxes_invalid_addresses..cSsg|] }t|qSrrzr{rrrr} r~rrr3rhzFoo xrr)r&r rwrrMrur rrBrArBrrrrrxrrr1test_get_address_list_mailboxes_invalid_addresses sBz;, Abe , Bee r rvrrrrr\rr/Zflintrry) r&r rwr rrBrArBrrrrr rxrrr)test_get_address_list_group_and_mailboxes s@  z4TestParser.test_get_address_list_group_and_mailboxescCs |tjdddtjgd}dS)Nz ;attachmentz ; attachmentr)r)r parse_content_disposition_headerrrM)rZ content_disprrr test_invalid_content_disposition s  z+TestParser.test_invalid_content_dispositioncCs |tjdddtjgd}dS)Nz;foor)r)r Z&parse_content_transfer_encoding_headerrrM)rZcterrr&test_invalid_content_transfer_encoding sz1TestParser.test_invalid_content_transfer_encodingcCs:|tjtdWdn1s,0YdSr'rArrBr get_msg_idr1rrrtest_get_msg_id_empty sz TestParser.test_get_msg_id_emptycCs(|tjdddgd}||jddS)Nz%r msg-idr&r rr rrmsg_idrrrtest_get_msg_id_valid sz TestParser.test_get_msg_id_validcCs,|tjdddtjgd}||jddS)Nz<"simeple.local"@example.com>zr r)r&r rrrur rrrrrtest_get_msg_id_obsolete_local* sz)TestParser.test_get_msg_id_obsolete_localcCs(|tjdddgd}||jddS)Nz&r rrrrrr*test_get_msg_id_non_folding_literal_domain5 sz5TestParser.test_get_msg_id_non_folding_literal_domaincCs|tjdddtjgd}dS)Nzzr )r&r rrrurrrr$test_get_msg_id_obsolete_domain_partA sz/TestParser.test_get_msg_id_obsolete_domain_partcCs,|tjdddtjgd}||jddS)Nz r rr&r rrrMr rrrrr test_get_msg_id_no_id_right_partK sz+TestParser.test_get_msg_id_no_id_right_partcCs$d}t|}||jtjgdS)N3935-XPB-567:0:45327:9:90305:17843586-40@example.com)r parse_message_idrrrrM)rtextrrrr1test_get_msg_id_invalid_expected_msg_id_not_foundV s  z message-id)r)r rr rrrrrtest_parse_valid_message_idg sz&TestParser.test_parse_valid_message_idcCsB|tjdddtjgg}||jd|t|jdddS)Nz%thensomethingzrrzUnexpected 'thensomething') r)r rrrMr rr rrrrr$test_parse_message_id_with_remainingq sz/TestParser.test_parse_message_id_with_remainingcCs:|tjtdWdn1s,0YdS)NZmsgwithnoanklerr1rrrtest_get_msg_id_no_angle_start~ sz)TestParser.test_get_msg_id_no_angle_startcCs,|tjdddtjgd}||jddS)Nzr rrrrrrtest_get_msg_id_no_angle_end sz'TestParser.test_get_msg_id_no_angle_endN(Brrrbytesrrrr ascii_lettersdigitsr translater maketransrr2r5r7r9r<r>rDrErFrGrKrNrPrQrXrYr[r\r^rarcrergrhrirkrlrnrqrrrsrurvrxryrzr{r|r}rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r rrrrrrr#r%r&r(r)r*r+r/r1r2r4r6r7r8r:r;r<r=r?rDrFrHrIrJrKrLrNrQrRrSrVrWrXrYrZr]r^r_rarirorvryr~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r r rrrrrrrrrrrr r$r&r(r*r,r-r.r0r1r2r7r8r<r=r>rDrGrIrJrMrNrOrPrUrWrXrYr`rarcrdrerfrgrlrnrorprqrrrsrtruryrrrrrrrrrrrrrrrrrrrrrrrrrr*-sr                                                                                         $        r*c@seZdZddZddddggfddd dd ggfd d d d ggfddddgejgfdd dd gejgfddddgejgfddddgejgfdd dd gejgfddddgejgdfddddgejgdfdd d!d"gejgdfd# Zd$S)%Test_parse_mime_parameterscCs8|tj||||}||jd|t|j|dS)Nzmime-parameters)r)r Zparse_mime_parametersr rlistparams)rrtl_strtl_valuerr Zmime_parametersrrrmime_parameters_as_value s z3Test_parse_mime_parameters.mime_parameters_as_valuezfilename="abc.py"z filename="abc.py"zfilename=abc.py)filenamezabc.pyzfilename="abc.py"; xyz=abcz filename="abc.py"; xyz="abc"zfilename=abc.py; xyz=abc)Zxyzr?z;filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66z filename="201.tif")rz201.tifz#filename=abc.gif; filename=def.tiffz filename="abc.gif")rzabc.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")rz201.tifabc.gifzrzabc rr rwr1rrrtest_simple_addressh szTestFolding.test_simple_addresscCs|tddddS)Nzabc , "Fred Blunt" , "J.P.Cool" , "K<>y" , Firesale , rzabc , "Fred Blunt" , "J.P.Cool" , "K<>y" , Firesale , rr1rrr#test_address_list_folding_at_commasl s  z/TestFolding.test_address_list_folding_at_commascCs|tddddS)NuIHübsch Kaktus , beißt beißt ro=?utf-8?q?H=C3=BCbsch?= Kaktus , =?utf-8?q?bei=C3=9Ft_bei=C3=9Ft?= rr1rrr$test_address_list_with_unicode_namesw sz0TestFolding.test_address_list_with_unicode_namescCs|tddddS)NuM"Hübsch Kaktus" , "beißt" beißt rrrr1rrr.test_address_list_with_unicode_names_in_quotes~ sz:TestFolding.test_address_list_with_unicode_names_in_quotesc CsJtd}tttddgttddg|g}||ddS)NzP xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxztest:rr3r zXtest: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx )r r_ZHeaderZ HeaderLabelZ ValueTerminalZCFWSListZWhiteSpaceTerminalr)rbodyheaderrrr7test_split_at_whitespace_after_header_before_long_token s  zCTestFolding.test_split_at_whitespace_after_header_before_long_tokencCs|tdddS)NzSxxx yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzUxxx yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy rr1rrr*test_split_at_whitespace_before_long_token s z6TestFolding.test_split_at_whitespace_before_long_tokencCsjd}d}t|d}|t|}|t|d||dd|dd|dd d|ddS) Nzxxx z =?utf-8?q?rZPyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyrNz?= r3P)rBrr r_)rZfirst_token_with_whitespaceZ chrome_leaderZ len_chromeZ len_non_yrrr#test_overlong_encodeable_is_wrapped s*    z/TestFolding.test_overlong_encodeable_is_wrappedcCs|tdddS)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 )rr rr1rrrtest_long_filename_attachment s z)TestFolding.test_long_filename_attachmentN)rrrrdefaultrrrrrrrrrrrrrrrrrrr? s     r__main__)rZunittestZemailrr rrZtest.test_emailrrrrr*rrrrmainrrrrsF    vr<j