@@ -68,22 +68,48 @@ def read_mail(filename, project=None):
6868 return mail
6969
7070
71- def _create_email (msg , msgid = None , sender = None , listid = None , in_reply_to = None ):
71+ def _create_email (
72+ msg ,
73+ msgid = None ,
74+ subject = None ,
75+ sender = None ,
76+ listid = None ,
77+ in_reply_to = None ,
78+ references = None ,
79+ ):
7280 msg ['Message-Id' ] = msgid or make_msgid ()
7381 msg ['Subject' ] = 'Test subject'
7482 msg ['From' ] = sender or 'Test Author <test-author@example.com>'
7583 msg ['List-Id' ] = listid or 'test.example.com'
7684 if in_reply_to :
7785 msg ['In-Reply-To' ] = in_reply_to
7886
87+ if references :
88+ msg ['References' ] = references
89+
7990 return msg
8091
8192
82- def create_email (content , msgid = None , sender = None , listid = None ,
83- in_reply_to = None ):
93+ def create_email (
94+ content ,
95+ msgid = None ,
96+ subject = None ,
97+ sender = None ,
98+ listid = None ,
99+ in_reply_to = None ,
100+ references = None ,
101+ ):
84102 msg = MIMEText (content , _charset = 'us-ascii' )
85103
86- return _create_email (msg , msgid , sender , listid , in_reply_to )
104+ return _create_email (
105+ msg ,
106+ msgid ,
107+ subject ,
108+ sender ,
109+ listid ,
110+ in_reply_to ,
111+ references ,
112+ )
87113
88114
89115def parse_mail (* args , ** kwargs ):
@@ -1146,26 +1172,34 @@ def log_query_errors(execute, sql, params, many, context):
11461172
11471173 def test_duplicate_patch (self ):
11481174 diff = read_patch ('0001-add-line.patch' )
1149- m = create_email (diff , listid = self .listid , msgid = '1@example.com' )
1175+ m = create_email (diff , listid = self .listid , msgid = '< 1@example.com> ' )
11501176
11511177 self ._test_duplicate_mail (m )
11521178
11531179 self .assertEqual (Patch .objects .count (), 1 )
11541180
11551181 def test_duplicate_comment (self ):
11561182 diff = read_patch ('0001-add-line.patch' )
1157- m1 = create_email (diff , listid = self .listid , msgid = '1@example.com' )
1183+ m1 = create_email (
1184+ diff ,
1185+ listid = self .listid ,
1186+ msgid = '<1@example.com>' ,
1187+ )
11581188 _parse_mail (m1 )
11591189
1160- m2 = create_email ('test' , listid = self .listid , msgid = '2@example.com' ,
1161- in_reply_to = '1@example.com' )
1190+ m2 = create_email (
1191+ 'test' ,
1192+ listid = self .listid ,
1193+ msgid = '<2@example.com>' ,
1194+ in_reply_to = '<1@example.com>' ,
1195+ )
11621196 self ._test_duplicate_mail (m2 )
11631197
11641198 self .assertEqual (Patch .objects .count (), 1 )
11651199 self .assertEqual (PatchComment .objects .count (), 1 )
11661200
11671201 def test_duplicate_coverletter (self ):
1168- m = create_email ('test' , listid = self .listid , msgid = '1@example.com' )
1202+ m = create_email ('test' , listid = self .listid , msgid = '< 1@example.com> ' )
11691203 del m ['Subject' ]
11701204 m ['Subject' ] = '[PATCH 0/1] test cover letter'
11711205
@@ -1174,6 +1208,52 @@ def test_duplicate_coverletter(self):
11741208 self .assertEqual (Cover .objects .count (), 1 )
11751209
11761210
1211+ class TestFindReferences (TestCase ):
1212+ def test_find_references__header_with_comments (self ):
1213+ """Test that we strip comments from References, In-Reply-To fields."""
1214+ in_reply_to = (
1215+ '<4574b99b-edac-d8dc-9141-79c3109d2fcc@huawei.com> (message from\n '
1216+ ' liqingqing on Thu, 1 Apr 2021 16:51:45 +0800)'
1217+ )
1218+ email = create_email ('test' , in_reply_to = in_reply_to )
1219+
1220+ expected = ['<4574b99b-edac-d8dc-9141-79c3109d2fcc@huawei.com>' ]
1221+ actual = parser .find_references (email )
1222+
1223+ self .assertEqual (expected , actual )
1224+
1225+ def test_find_references__duplicate_references (self ):
1226+ """Test that we ignore duplicate message IDs in 'References'."""
1227+ message_id = '<20130510114450.7104c5d2@nehalam.linuxnetplumber.net>'
1228+ in_reply_to = (
1229+ '<525534677.5312512.1368202896189.JavaMail.root@vmware.com>'
1230+ )
1231+ references = (
1232+ '<AFCFCEB8EB0E24448E4EB95988BA1E531FA2EA0D@xmb-aln-x05.cisco.com>\n ' # noqa: E501
1233+ ' <CAE68AUOr7B5a2QvduJhH0kEHPi+sR9X3qfrtumgLxT1BK4VS+Q@mail.gmail.com>\n ' # noqa: E501
1234+ ' <1676591087.5291867.1368201908283.JavaMail.root@vmware.com>\n '
1235+ ' <20130510091549.3c064df6@nehalam.linuxnetplumber.net>\n '
1236+ ' <525534677.5312512.1368202896189.JavaMail.root@vmware.com>'
1237+ )
1238+ email = create_email (
1239+ 'test' ,
1240+ msgid = message_id ,
1241+ in_reply_to = in_reply_to ,
1242+ references = references ,
1243+ )
1244+
1245+ expected = [
1246+ '<525534677.5312512.1368202896189.JavaMail.root@vmware.com>' ,
1247+ '<20130510091549.3c064df6@nehalam.linuxnetplumber.net>' ,
1248+ '<1676591087.5291867.1368201908283.JavaMail.root@vmware.com>' ,
1249+ '<CAE68AUOr7B5a2QvduJhH0kEHPi+sR9X3qfrtumgLxT1BK4VS+Q@mail.gmail.com>' , # noqa: E501
1250+ '<AFCFCEB8EB0E24448E4EB95988BA1E531FA2EA0D@xmb-aln-x05.cisco.com>' ,
1251+ ]
1252+ actual = parser .find_references (email )
1253+
1254+ self .assertEqual (expected , actual )
1255+
1256+
11771257class TestCommentCorrelation (TestCase ):
11781258
11791259 def test_find_patch_for_comment__no_reply (self ):
0 commit comments