File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -1520,13 +1520,18 @@ def get_obs_local_part(value):
15201520 raise
15211521 token , value = get_cfws (value )
15221522 obs_local_part .append (token )
1523+ if not obs_local_part :
1524+ raise errors .HeaderParseError (
1525+ "expected obs-local-part but found '{}'" .format (value ))
15231526 if (obs_local_part [0 ].token_type == 'dot' or
15241527 obs_local_part [0 ].token_type == 'cfws' and
1528+ len (obs_local_part ) > 1 and
15251529 obs_local_part [1 ].token_type == 'dot' ):
15261530 obs_local_part .defects .append (errors .InvalidHeaderDefect (
15271531 "Invalid leading '.' in local part" ))
15281532 if (obs_local_part [- 1 ].token_type == 'dot' or
15291533 obs_local_part [- 1 ].token_type == 'cfws' and
1534+ len (obs_local_part ) > 1 and
15301535 obs_local_part [- 2 ].token_type == 'dot' ):
15311536 obs_local_part .defects .append (errors .InvalidHeaderDefect (
15321537 "Invalid trailing '.' in local part" ))
Original file line number Diff line number Diff line change @@ -2724,6 +2724,31 @@ def test_get_msg_id_no_angle_end(self):
27242724 )
27252725 self .assertEqual (msg_id .token_type , 'msg-id' )
27262726
2727+ def test_get_msg_id_empty_id_left (self ):
2728+ with self .assertRaises (errors .HeaderParseError ):
2729+ parser .get_msg_id ("<@domain>" )
2730+
2731+ def test_get_msg_id_empty_id_right (self ):
2732+ with self .assertRaises (errors .HeaderParseError ):
2733+ parser .get_msg_id ("<simplelocal@>" )
2734+
2735+ def test_get_msg_id_with_brackets (self ):
2736+ # Microsof Outlook generates non-standard one-off addresses:
2737+ # https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/one-off-addresses
2738+ with self .assertRaises (errors .HeaderParseError ):
2739+ parser .get_msg_id ("<[abrakadabra@microsoft.com]>" )
2740+
2741+ def test_get_msg_id_ws_only_local (self ):
2742+ msg_id = self ._test_get_x (
2743+ parser .get_msg_id ,
2744+ "< @domain>" ,
2745+ "< @domain>" ,
2746+ "< @domain>" ,
2747+ [errors .ObsoleteHeaderDefect ],
2748+ ""
2749+ )
2750+ self .assertEqual (msg_id .token_type , 'msg-id' )
2751+
27272752
27282753
27292754@parameterize
Original file line number Diff line number Diff line change 1+ Fix IndexError when parse some emails with invalid Message-ID (including
2+ one-off addresses generated by Microsoft Outlook).
You can’t perform that action at this time.
0 commit comments