Skip to content

Commit 4879884

Browse files
committed
issue2551262 - make mail gateway subject prefix parsing accept spaces
Allow spaces before/after prefix. Also allow spaces between classname and id number in prefix designator. So "[ issue 23 ] subject" is parsed like "[issue23] subject".
1 parent 0e73004 commit 4879884

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ Features:
110110
- issue2551253 - new password hash PBDKF2-SHA512 added. Not available
111111
by default. See issue ticket for details.
112112
- roundup-admin migrate command reports the schema version.
113+
- issue2551262 - the mail gateway subject prefix now allows spaces
114+
before/after prefix. Also allow spaces between classname and id
115+
number in prefix designator. So "[ issue 23 ] subject" is parsed
116+
like "[issue23] subject".
113117

114118
2022-07-13 2.2.0
115119

doc/user_guide.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,11 @@ If a one-time key is found, we're processing an in-progress
454454
registration confirmation.
455455

456456
If the subject line contains a prefix in ``[square brackets]`` then
457-
we're looking at case 3 or 4 above. Any "re:" or "fwd:" prefixes are
458-
stripped off the subject line before we start looking for real
459-
information.
457+
we're looking at case 3 or 4 above. Spaces are allowed inside the
458+
brackets and after the class item name. So ``[issue2]`` and
459+
``[ issue 2 ]`` are treted the same where any whitespace is optional.
460+
Any "re:" or "fwd:" prefixes are stripped off the subject line before
461+
we start looking for real information.
460462

461463
If an item designator (class name and id number, for example
462464
``issue123``) is found there, a new "msg" item is added to the
@@ -492,15 +494,15 @@ For example,
492494

493495
- adding yourself to a nosy list::
494496

495-
Subject: Re: [issue2] we're out of widgets [nosy=+richard]
497+
Subject: Re: [ issue2 ] we're out of widgets [nosy=+richard]
496498

497499
- setting the nosy list to just you and cliff::
498500

499-
Subject: Re: [issue2] we're out of widgets [nosy=richard,cliff]
501+
Subject: Re: [issue 2] we're out of widgets [nosy=richard,cliff]
500502

501503
- removing yourself from a nosy list and setting the priority::
502504

503-
Subject: Re: [issue2] we're out of widgets [nosy=-richard;priority=bug]
505+
Subject: Re: [ issue 2 ] we're out of widgets [nosy=-richard;priority=bug]
504506

505507
In all cases, the message relates to issue 2. The ``Re:`` prefix is
506508
stripped off.

roundup/mailgw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,12 @@ def parse_subject(self):
636636
tmpsubject = tmpsubject[len(self.matches['quote']):]
637637

638638
# Check if the subject includes a prefix
639-
self.has_prefix = re.search(r'^%s(\w+)%s' % (delim_open,
639+
self.has_prefix = re.search(r'^%s\s*(\w+)\s*%s' % (delim_open,
640640
delim_close),
641641
tmpsubject.strip())
642642

643643
# Match the classname if specified
644-
class_re = r'%s(?P<classname>(%s))(?P<nodeid>\d+)?%s' % \
644+
class_re = r'%s\s*(?P<classname>(%s))\s*(?P<nodeid>\d+)?\s*%s' % \
645645
(delim_open, "|".join(self.db.getclasses()),
646646
delim_close)
647647
# Note: re.search, not re.match as there might be garbage

test/test_mailgw.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,6 +4290,21 @@ def testMaillistSubject(self):
42904290
assert not os.path.exists(SENDMAILDEBUG)
42914291
self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar')
42924292

4293+
def testSpacedPrefixSubject(self):
4294+
self.db.keyword.create(name='Foo')
4295+
self._handle_mail('''Content-Type: text/plain;
4296+
charset="iso-8859-1"
4297+
From: Chef <[email protected]>
4298+
4299+
Subject: VeryStrangeRe: [ keyword 1 ] Testing.. [name=Bar]
4300+
4301+
4302+
Message-Id: <dummy_test_message_id>
4303+
4304+
''')
4305+
assert not os.path.exists(SENDMAILDEBUG)
4306+
self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar')
4307+
42934308
def testUnknownPrefixSubject(self):
42944309
self.db.keyword.create(name='Foo')
42954310
self._handle_mail('''Content-Type: text/plain;

0 commit comments

Comments
 (0)