Skip to content

Commit 6a948ca

Browse files
committed
Strip comments from trailers for stg mail --auto
Commits in the Linux kernel repo include 'Cc: ' trailers that contain comments starting with '#'. When these commented trailers are incorporated directly into email headers, the email will be rejected due to the invalid syntax of the comments in the context of an email address. Repairs #91
1 parent 7e972a6 commit 6a948ca

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

stgit/commands/mail.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,19 @@ def __get_signers_list(msg):
510510
'suggested-by',
511511
'reported-and-tested-by',
512512
)
513-
regex = r'^(%s):\s+(.+)$' % tags
513+
514+
# N.B. This regex treats '#' as the start of a comment and thus discards everything
515+
# after the '#'. This does not allow for valid email addresses that contain '#' in
516+
# the local-part (i.e. the part before the '@') as is allowed by RFC2822. Such email
517+
# addresses containing '#' in their local-part are thus not supported by this
518+
# function.
519+
regex = r'^(%s):\s+([^#]+).*$' % tags
514520

515521
r = re.compile(regex, re.I)
516522
for line in msg.split('\n'):
517523
m = r.match(line)
518524
if m:
519-
addr_list.append(m.expand(r'\g<2>'))
525+
addr_list.append(m.group(2))
520526

521527
return addr_list
522528

t/t1900-mail.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,42 @@ test_expect_success 'Check the e-mail address duplicates' '
7575
test "$(cat mbox | grep -e "^Bcc:")" = "Bcc: d@d"
7676
'
7777

78+
test_expect_success 'Check --auto with commented Cc: realname and addr' '
79+
stg edit -m "Patch 5
80+
81+
Cc: Some Body <[email protected]> # v3.2.1
82+
" &&
83+
stg mail --auto $(stg top) -m > mbox &&
84+
test "$(cat mbox | grep -e "^Cc:" | head -n 1)" = "Cc: Some Body <[email protected]>"
85+
'
86+
87+
test_expect_success 'Check --auto with commented Cc: addr only' '
88+
stg edit -m "Patch 5
89+
90+
Cc: [email protected] # v3.2.1
91+
" &&
92+
stg mail --auto $(stg top) -m > mbox &&
93+
test "$(cat mbox | grep -e "^Cc:" | head -n 1)" = "Cc: [email protected]"
94+
'
95+
96+
test_expect_success 'Check --auto with no-space commented Cc: realname and addr' '
97+
stg edit -m "Patch 5
98+
99+
Cc: Some Body <[email protected]>#v3.2.1
100+
" &&
101+
stg mail --auto $(stg top) -m > mbox &&
102+
test "$(cat mbox | grep -e "^Cc:" | head -n 1)" = "Cc: Some Body <[email protected]>"
103+
'
104+
105+
test_expect_success 'Check --auto with no-space commented Cc: addr only' '
106+
stg edit -m "Patch 5
107+
108+
109+
" &&
110+
stg mail --auto $(stg top) -m > mbox &&
111+
test "$(cat mbox | grep -e "^Cc:" | head -n 1)" = "Cc: [email protected]"
112+
'
113+
78114
test_expect_success 'Test no patches' '
79115
command_error stg mail
80116
'

0 commit comments

Comments
 (0)