@@ -44,11 +44,9 @@ def test_domain_extension_should_be_letters_only_from_2_to_4_chars(self):
4444self .assertFalse (is_email ('me@foo.___' ))
4545self .assertFalse (is_email ('me@foo.toolongext' ))
4646
47- def test_name_part_cannot_contain_bad_signs (self ):
48- self .assertFalse (is_email ('#me#@foo.com' ))
49- self .assertFalse (is_email ('me!@foo.com' ))
50- self .assertFalse (is_email ('[][]@foo.com' ))
51- self .assertFalse (is_email ('john%@john5music.net' ))
47+ def test_name_part_cannot_contain_suqare_brackets (self ):
48+ self .assertFalse (is_email ('[myemail@foo.com' ))
49+ self .assertFalse (is_email ('my]email@foo.com' ))
5250
5351def test_domain_part_cannot_contain_bad_signs (self ):
5452self .assertFalse (is_email ('me@#foo#.com' ))
@@ -74,3 +72,100 @@ def test_should_accept_valid_emails(self):
7472self .assertTrue (is_email ('foo@domamin.subdomain.com' ))
7573self .assertTrue (is_email ('is1email@domain.org' ))
7674self .assertTrue (is_email ('UPPER_CASE_EMAIL@somesite.com' ))
75+
76+ def test_max_email_length_is_respected (self ):
77+ invalid_email = ('a' * 320 )+ '@gmail.com'
78+ self .assertFalse (is_email (invalid_email ))
79+
80+ def test_local_part_length_is_respected (self ):
81+ # max local part is 64 (before "@")
82+ invalid_email = ('a' * 65 )+ '@gmail.com'
83+ self .assertFalse (is_email (invalid_email ))
84+
85+ def test_octects_part_length_is_respected (self ):
86+ # max octets part is 255 (after "@")
87+ invalid_email = 'a@{}.com' .format (255 * 'x' )
88+ self .assertFalse (is_email (invalid_email ))
89+
90+ def test_plus_is_valid_char_in_local_part (self ):
91+ self .assertTrue (is_email ("my+mail@gmail.com" ))
92+
93+ def test_minus_is_valid_char_in_local_part (self ):
94+ self .assertTrue (is_email ("my-mail@gmail.com" ))
95+
96+ def test_slash_is_valid_char_in_local_part (self ):
97+ self .assertTrue (is_email ("my/mail@gmail.com" ))
98+
99+ def test_back_slash_is_valid_char_in_local_part (self ):
100+ self .assertTrue (is_email ("my\\ mail@gmail.com" ))
101+
102+ def test_equal_is_valid_char_in_local_part (self ):
103+ self .assertTrue (is_email ("my=mail@gmail.com" ))
104+
105+ def test_question_mark_is_valid_char_in_local_part (self ):
106+ self .assertTrue (is_email ("my?mail@gmail.com" ))
107+
108+ def test_sharp_is_valid_char_in_local_part (self ):
109+ self .assertTrue (is_email ("my#mail@gmail.com" ))
110+
111+ def test_dollar_is_valid_char_in_local_part (self ):
112+ self .assertTrue (is_email ("my$mail@gmail.com" ))
113+
114+ def test_and_is_valid_char_in_local_part (self ):
115+ self .assertTrue (is_email ("my&mail@gmail.com" ))
116+
117+ def test_asterisk_is_valid_char_in_local_part (self ):
118+ self .assertTrue (is_email ("my*mail@gmail.com" ))
119+
120+ def test_apostrophe_is_valid_char_in_local_part (self ):
121+ self .assertTrue (is_email ("my'mail@gmail.com" ))
122+
123+ def test_acute_accent_is_valid_char_in_local_part (self ):
124+ self .assertTrue (is_email ("my`mail@gmail.com" ))
125+
126+ def test_percentage_is_valid_char_in_local_part (self ):
127+ self .assertTrue (is_email ("my%mail@gmail.com" ))
128+
129+ def test_exclamation_mark_is_valid_char_in_local_part (self ):
130+ self .assertTrue (is_email ("my!mail@gmail.com" ))
131+
132+ def test_caret_is_valid_char_in_local_part (self ):
133+ self .assertTrue (is_email ("my^mail@gmail.com" ))
134+
135+ def test_pipe_is_valid_char_in_local_part (self ):
136+ self .assertTrue (is_email ("my|mail@gmail.com" ))
137+
138+ def test_tilde_is_valid_char_in_local_part (self ):
139+ self .assertTrue (is_email ("my~mail@gmail.com" ))
140+
141+ def test_curly_braces_are_valid_char_in_local_part (self ):
142+ self .assertTrue (is_email ("my{mail@gmail.com" ))
143+ self .assertTrue (is_email ("my}mail@gmail.com" ))
144+ self .assertTrue (is_email ("{mymail}@gmail.com" ))
145+
146+ def test_local_part_cannot_start_with_period (self ):
147+ self .assertFalse (is_email ('.myemail@gmail.com' ))
148+
149+ def test_local_part_cannot_end_with_period (self ):
150+ self .assertFalse (is_email ('myemail.@gmail.com' ))
151+
152+ def test_local_part_cannot_have_multiple_consecutive_periods (self ):
153+ self .assertFalse (is_email ('my..email@gmail.com' ))
154+ self .assertFalse (is_email ('my.email...nope@gmail.com' ))
155+
156+ def test_empty_spaces_are_allowed_only_if_escaped (self ):
157+ self .assertFalse (is_email ('my mail@gmail.com' ))
158+ self .assertTrue (is_email ('my\\ mail@gmail.com' ))
159+ self .assertTrue (is_email ('"my mail"@gmail.com' ))
160+
161+ def test_local_part_can_be_quoted (self ):
162+ self .assertTrue (is_email ('"foo"@example.com' ))
163+
164+ def test_with_quoted_string_multiple_at_are_accepted (self ):
165+ self .assertTrue (is_email ('"Abc@def"@example.com' ))
166+
167+ def test_with_escape_multiple_at_are_accepted (self ):
168+ self .assertTrue (is_email ('Abc\\ @def@example.com' ))
169+
170+ def test_local_part_can_have_self_escape (self ):
171+ self .assertTrue (is_email ('Joe.\\ \\ Blow@example.com' ))