Skip to content

Commit 1238b12

Browse files
author
Richard Jones
committed
Resent-From: header
1 parent 3bceac8 commit 1238b12

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Feature:
1111
since)
1212
- all RDBMS backends now have indexes on several columns
1313
- Change nosymessage and send_message to accept msgid=None (RFE #707235).
14+
- Handle Resent-From: headers (sf bug 841151)
1415

1516
Fixed:
1617
- mysql documentation fixed to note requirement of 4.0+ and InnoDB

roundup/mailgw.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.137 2003-11-11 00:35:13 richard Exp $
76+
$Id: mailgw.py,v 1.138 2003-11-13 03:41:38 richard Exp $
7777
"""
7878

7979
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -297,7 +297,9 @@ def handle_Message(self, message):
297297
"""
298298
# in some rare cases, a particularly stuffed-up e-mail will make
299299
# its way into here... try to handle it gracefully
300-
sendto = message.getaddrlist('from')
300+
sendto = message.getaddrlist('resent-from')
301+
if not sendto:
302+
sendto = message.getaddrlist('from')
301303
if sendto:
302304
if not self.trapExceptions:
303305
return self.handle_message(message)
@@ -414,6 +416,11 @@ def handle_message(self, message):
414416
# nodeid = issue.group('nodeid')
415417
# break
416418

419+
# determine the sender's address
420+
from_list = message.getaddrlist('resent-from')
421+
if not from_list:
422+
from_list = message.getaddrlist('from')
423+
417424
# handle the subject line
418425
subject = message.getheader('subject', '')
419426

@@ -440,7 +447,7 @@ def handle_message(self, message):
440447
self.db.confirm_registration(otk.group('otk'))
441448
subject = 'Your registration to %s is complete' % \
442449
self.instance.config.TRACKER_NAME
443-
sendto = [message.getheader('from')]
450+
sendto = [from_list[0][1]]
444451
self.mailer.standard_message(sendto, subject, '')
445452
return
446453
elif hasattr(self.instance.config, 'MAIL_DEFAULT_CLASS') and \
@@ -574,8 +581,7 @@ def handle_message(self, message):
574581

575582
# ok, now figure out who the author is - create a new user if the
576583
# "create" flag is true
577-
author = uidFromAddress(self.db, message.getaddrlist('from')[0],
578-
create=create)
584+
author = uidFromAddress(self.db, from_list[0], create=create)
579585

580586
# if we're not recognised, and we don't get added as a user, then we
581587
# must be anonymous
@@ -590,7 +596,7 @@ def handle_message(self, message):
590596
You are not a registered user.
591597
592598
Unknown address: %s
593-
'''%message.getaddrlist('from')[0][1]
599+
'''%from_list[0][1]
594600
else:
595601
# we're registered and we're _still_ not allowed access
596602
raise Unauthorized, 'You are not permitted to access '\

test/test_mailgw.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_mailgw.py,v 1.61 2003-11-11 00:35:14 richard Exp $
11+
# $Id: test_mailgw.py,v 1.62 2003-11-13 03:41:38 richard Exp $
1212

1313
import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822
1414

@@ -99,13 +99,13 @@ def setUp(self):
9999

100100
# and open the database
101101
self.db = self.instance.open('admin')
102-
self.db.user.create(username='Chef', address='[email protected]',
103-
realname='Bork, Chef', roles='User')
104-
self.db.user.create(username='richard', address='richard@test',
105-
roles='User')
106-
self.db.user.create(username='mary', address='mary@test',
102+
self.chef_id = self.db.user.create(username='Chef',
103+
address='[email protected]', realname='Bork, Chef', roles='User')
104+
self.richard_id = self.db.user.create(username='richard',
105+
address='richard@test', roles='User')
106+
self.mary_id = self.db.user.create(username='mary', address='mary@test',
107107
roles='User', realname='Contrary, Mary')
108-
self.db.user.create(username='john', address='john@test',
108+
self.john_id = self.db.user.create(username='john', address='john@test',
109109
alternate_addresses='jondoe@test\njohn.doe@test', roles='User',
110110
realname='John Doe')
111111

@@ -157,7 +157,7 @@ def doNewIssue(self):
157157
assert not os.path.exists(SENDMAILDEBUG)
158158
l = self.db.issue.get(nodeid, 'nosy')
159159
l.sort()
160-
self.assertEqual(l, ['3', '4'])
160+
self.assertEqual(l, [self.chef_id, self.richard_id])
161161
return nodeid
162162

163163
def testNewIssue(self):
@@ -178,7 +178,7 @@ def testNewIssueNosy(self):
178178
assert not os.path.exists(SENDMAILDEBUG)
179179
l = self.db.issue.get(nodeid, 'nosy')
180180
l.sort()
181-
self.assertEqual(l, ['3', '4'])
181+
self.assertEqual(l, [self.chef_id, self.richard_id])
182182

183183
def testAlternateAddress(self):
184184
self._send_mail('''Content-Type: text/plain;
@@ -315,7 +315,8 @@ def testFollowup(self):
315315
''')
316316
l = self.db.issue.get('1', 'nosy')
317317
l.sort()
318-
self.assertEqual(l, ['3', '4', '5', '6'])
318+
self.assertEqual(l, [self.chef_id, self.richard_id, self.mary_id,
319+
self.john_id])
319320

320321
self.compareMessages(self._get_mail(),
321322
@@ -620,7 +621,8 @@ def testFollowupEmptyMessage(self):
620621
''')
621622
l = self.db.issue.get('1', 'nosy')
622623
l.sort()
623-
self.assertEqual(l, ['3', '4', '5', '6'])
624+
self.assertEqual(l, [self.chef_id, self.richard_id, self.mary_id,
625+
self.john_id])
624626

625627
# should be no file created (ie. no message)
626628
assert not os.path.exists(SENDMAILDEBUG)
@@ -639,7 +641,7 @@ def testNosyRemove(self):
639641
''')
640642
l = self.db.issue.get('1', 'nosy')
641643
l.sort()
642-
self.assertEqual(l, ['3'])
644+
self.assertEqual(l, [self.chef_id])
643645

644646
# NO NOSY MESSAGE SHOULD BE SENT!
645647
assert not os.path.exists(SENDMAILDEBUG)
@@ -941,6 +943,24 @@ def testFollowupOnNonIssue(self):
941943
942944
''')
943945
self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar')
946+
947+
def testResentFrom(self):
948+
nodeid = self._send_mail('''Content-Type: text/plain;
949+
charset="iso-8859-1"
950+
From: Chef <[email protected]>
951+
Resent-From: mary <mary@test>
952+
953+
Cc: richard@test
954+
Message-Id: <dummy_test_message_id>
955+
Subject: [issue] Testing...
956+
957+
This is a test submission of a new issue.
958+
''')
959+
assert not os.path.exists(SENDMAILDEBUG)
960+
l = self.db.issue.get(nodeid, 'nosy')
961+
l.sort()
962+
self.assertEqual(l, [self.richard_id, self.mary_id])
963+
return nodeid
944964

945965
def test_suite():
946966
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)