From 840af79b7d2c41ed0dfd70b496b6b5f3ffefc510 Mon Sep 17 00:00:00 2001 From: schlatterbeck Date: Wed, 24 Aug 2011 14:43:52 +0000 Subject: [PATCH] Fix matching of incoming email addresses to the alternate_addresses field of a user -- this would match substrings, e.g. if the user has discuss-support@example.com as an alternate email and an incoming mail is addressed to support@example.com this would (wrongly) match. Note: I *think* I've seen this discussed somewhere but couldn't find it, neither in the tracker nor in recent discussions on the mailinglists. So if someone remembers an issue which now should be closed, please tell me :-) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4644 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 9 ++++++--- roundup/mailgw.py | 12 +++++++++++- test/test_mailgw.py | 6 ++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 185d132..2aac40e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,12 +8,15 @@ Entries without name were done by Richard Jones. Features: Fixed: -issue2550715: IndexError when requesting non-existing file via http. +- issue2550715: IndexError when requesting non-existing file via http. Reported and fixed by Cédric Krier. (Bernhard) - -issue2550695: 'No sort or group' settings not retained when editing queries. +- issue2550695: 'No sort or group' settings not retained when editing queries. Reported and fixed by John Kristensen. Tested by Satchidanand Haridas. (Bernhard) +- Fix matching of incoming email addresses to the alternate_addresses + field of a user -- this would match substrings, e.g. if the user has + discuss-support@example.com as an alternate email and an incoming mail + is addressed to support@example.com this would (wrongly) match. (Ralf) 2011-07-15 1.4.19 (r4638) diff --git a/roundup/mailgw.py b/roundup/mailgw.py index 2da86bb..7a71d6a 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -1666,7 +1666,17 @@ def uidFromAddress(db, address, create=1, **user_props): props = db.user.getprops() if props.has_key('alternate_addresses'): users = db.user.filter(None, {'alternate_addresses': address}) - user = extractUserFromList(db.user, users) + # We want an exact match of the email, not just a substring + # match. Otherwise e.g. support@example.com would match + # discuss-support@example.com which is not what we want. + found_users = [] + for u in users: + alt = db.user.get(u, 'alternate_addresses').split('\n') + for a in alt: + if a.strip().lower() == address.lower(): + found_users.append(u) + break + user = extractUserFromList(db.user, found_users) if user is not None: return user diff --git a/test/test_mailgw.py b/test/test_mailgw.py index 0cd78d4..6b64a30 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -2205,6 +2205,12 @@ This is a followup self.assertEqual(uidFromAddress(self.db, ('', 'user1@bar.com'), 0), i) self.assertEqual(uidFromAddress(self.db, ('', 'USER1@bar.com'), 0), i) + def testUserAlternateSubstringNomatch(self): + i = self.db.user.create(username='user1', address='user1@foo.com', + alternate_addresses='x-user1@bar.com') + self.assertEqual(uidFromAddress(self.db, ('', 'user1@bar.com'), 0), 0) + self.assertEqual(uidFromAddress(self.db, ('', 'USER1@bar.com'), 0), 0) + def testUserCreate(self): i = uidFromAddress(self.db, ('', 'user@foo.com'), 1) self.assertNotEqual(uidFromAddress(self.db, ('', 'user@bar.com'), 1), i) -- 2.30.2