From b1f15bf3228b00ce76ba2ade26fac30a2e3676eb Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 13 Nov 2003 03:41:38 +0000 Subject: [PATCH] Resent-From: header git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1983 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 1 + roundup/mailgw.py | 18 ++++++++++++------ test/test_mailgw.py | 44 ++++++++++++++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 361eddd..c26a27c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -11,6 +11,7 @@ Feature: since) - all RDBMS backends now have indexes on several columns - Change nosymessage and send_message to accept msgid=None (RFE #707235). +- Handle Resent-From: headers (sf bug 841151) Fixed: - mysql documentation fixed to note requirement of 4.0+ and InnoDB diff --git a/roundup/mailgw.py b/roundup/mailgw.py index a45f9e9..50a3c54 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -73,7 +73,7 @@ are calling the create() method to create a new node). If an auditor raises an exception, the original message is bounced back to the sender with the explanatory message given in the exception. -$Id: mailgw.py,v 1.137 2003-11-11 00:35:13 richard Exp $ +$Id: mailgw.py,v 1.138 2003-11-13 03:41:38 richard Exp $ """ import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri @@ -297,7 +297,9 @@ class MailGW: """ # in some rare cases, a particularly stuffed-up e-mail will make # its way into here... try to handle it gracefully - sendto = message.getaddrlist('from') + sendto = message.getaddrlist('resent-from') + if not sendto: + sendto = message.getaddrlist('from') if sendto: if not self.trapExceptions: return self.handle_message(message) @@ -414,6 +416,11 @@ class MailGW: # nodeid = issue.group('nodeid') # break + # determine the sender's address + from_list = message.getaddrlist('resent-from') + if not from_list: + from_list = message.getaddrlist('from') + # handle the subject line subject = message.getheader('subject', '') @@ -440,7 +447,7 @@ Emails to Roundup trackers must include a Subject: line! self.db.confirm_registration(otk.group('otk')) subject = 'Your registration to %s is complete' % \ self.instance.config.TRACKER_NAME - sendto = [message.getheader('from')] + sendto = [from_list[0][1]] self.mailer.standard_message(sendto, subject, '') return elif hasattr(self.instance.config, 'MAIL_DEFAULT_CLASS') and \ @@ -574,8 +581,7 @@ The mail gateway is not properly set up. Please contact # ok, now figure out who the author is - create a new user if the # "create" flag is true - author = uidFromAddress(self.db, message.getaddrlist('from')[0], - create=create) + author = uidFromAddress(self.db, from_list[0], create=create) # if we're not recognised, and we don't get added as a user, then we # must be anonymous @@ -590,7 +596,7 @@ The mail gateway is not properly set up. Please contact You are not a registered user. Unknown address: %s -'''%message.getaddrlist('from')[0][1] +'''%from_list[0][1] else: # we're registered and we're _still_ not allowed access raise Unauthorized, 'You are not permitted to access '\ diff --git a/test/test_mailgw.py b/test/test_mailgw.py index 211b4c4..5ffc55e 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -8,7 +8,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_mailgw.py,v 1.61 2003-11-11 00:35:14 richard Exp $ +# $Id: test_mailgw.py,v 1.62 2003-11-13 03:41:38 richard Exp $ import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822 @@ -99,13 +99,13 @@ class MailgwTestCase(unittest.TestCase, DiffHelper): # and open the database self.db = self.instance.open('admin') - self.db.user.create(username='Chef', address='chef@bork.bork.bork', - realname='Bork, Chef', roles='User') - self.db.user.create(username='richard', address='richard@test', - roles='User') - self.db.user.create(username='mary', address='mary@test', + self.chef_id = self.db.user.create(username='Chef', + address='chef@bork.bork.bork', realname='Bork, Chef', roles='User') + self.richard_id = self.db.user.create(username='richard', + address='richard@test', roles='User') + self.mary_id = self.db.user.create(username='mary', address='mary@test', roles='User', realname='Contrary, Mary') - self.db.user.create(username='john', address='john@test', + self.john_id = self.db.user.create(username='john', address='john@test', alternate_addresses='jondoe@test\njohn.doe@test', roles='User', realname='John Doe') @@ -157,7 +157,7 @@ This is a test submission of a new issue. assert not os.path.exists(SENDMAILDEBUG) l = self.db.issue.get(nodeid, 'nosy') l.sort() - self.assertEqual(l, ['3', '4']) + self.assertEqual(l, [self.chef_id, self.richard_id]) return nodeid def testNewIssue(self): @@ -178,7 +178,7 @@ This is a test submission of a new issue. assert not os.path.exists(SENDMAILDEBUG) l = self.db.issue.get(nodeid, 'nosy') l.sort() - self.assertEqual(l, ['3', '4']) + self.assertEqual(l, [self.chef_id, self.richard_id]) def testAlternateAddress(self): self._send_mail('''Content-Type: text/plain; @@ -315,7 +315,8 @@ This is a followup ''') l = self.db.issue.get('1', 'nosy') l.sort() - self.assertEqual(l, ['3', '4', '5', '6']) + self.assertEqual(l, [self.chef_id, self.richard_id, self.mary_id, + self.john_id]) self.compareMessages(self._get_mail(), '''FROM: roundup-admin@your.tracker.email.domain.example @@ -620,7 +621,8 @@ Subject: [issue1] Testing... [assignedto=mary; nosy=+john] ''') l = self.db.issue.get('1', 'nosy') l.sort() - self.assertEqual(l, ['3', '4', '5', '6']) + self.assertEqual(l, [self.chef_id, self.richard_id, self.mary_id, + self.john_id]) # should be no file created (ie. no message) assert not os.path.exists(SENDMAILDEBUG) @@ -639,7 +641,7 @@ Subject: [issue1] Testing... [nosy=-richard] ''') l = self.db.issue.get('1', 'nosy') l.sort() - self.assertEqual(l, ['3']) + self.assertEqual(l, [self.chef_id]) # NO NOSY MESSAGE SHOULD BE SENT! assert not os.path.exists(SENDMAILDEBUG) @@ -941,6 +943,24 @@ Subject: [keyword1] Testing... [name=Bar] ''') self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar') + + def testResentFrom(self): + nodeid = self._send_mail('''Content-Type: text/plain; + charset="iso-8859-1" +From: Chef +Resent-From: mary +To: issue_tracker@your.tracker.email.domain.example +Cc: richard@test +Message-Id: +Subject: [issue] Testing... + +This is a test submission of a new issue. +''') + assert not os.path.exists(SENDMAILDEBUG) + l = self.db.issue.get(nodeid, 'nosy') + l.sort() + self.assertEqual(l, [self.richard_id, self.mary_id]) + return nodeid def test_suite(): suite = unittest.TestSuite() -- 2.30.2