Repository: allura
Updated Branches:
  refs/heads/master 247bb35bf -> 8e9eb0e51


[#8185] Allow additional domain patterns for inbound email


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/8e9eb0e5
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/8e9eb0e5
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/8e9eb0e5

Branch: refs/heads/master
Commit: 8e9eb0e512caa5fce56845bb61bfe5ca1c4941ae
Parents: 247bb35
Author: Dave Brondsema <d...@brondsema.net>
Authored: Fri Feb 16 15:58:25 2018 -0500
Committer: Dave Brondsema <d...@brondsema.net>
Committed: Fri Feb 16 15:59:24 2018 -0500

----------------------------------------------------------------------
 Allura/allura/lib/mail_util.py        | 11 ++++++++---
 Allura/allura/tests/test_mail_util.py |  7 +++++++
 2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/8e9eb0e5/Allura/allura/lib/mail_util.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/mail_util.py b/Allura/allura/lib/mail_util.py
index 211d4e6..bb768a1 100644
--- a/Allura/allura/lib/mail_util.py
+++ b/Allura/allura/lib/mail_util.py
@@ -38,7 +38,9 @@ log = logging.getLogger(__name__)
 RE_MESSAGE_ID = re.compile(r'<(?:[^>]*/)?([^>]*)>')
 config = ConfigProxy(
     common_suffix='forgemail.domain',
-    return_path='forgemail.return_path')
+    common_suffix_alt='forgemail.domain.alternates',
+    return_path='forgemail.return_path',
+)
 EMAIL_VALIDATOR = fev.Email(not_empty=True)
 
 
@@ -100,9 +102,12 @@ def is_autoreply(msg):
 def parse_address(addr):
     userpart, domain = addr.split('@')
     # remove common domain suffix
-    if not domain.endswith(config.common_suffix):
+    for suffix in [config.common_suffix] + aslist(config.common_suffix_alt):
+        if domain.endswith(suffix):
+            domain = domain[:-len(suffix)]
+            break
+    else:
         raise exc.AddressException, 'Unknown domain: ' + domain
-    domain = domain[:-len(config.common_suffix)]
     path = '/'.join(reversed(domain.split('.')))
     project, mount_point = h.find_project('/' + path)
     if project is None:

http://git-wip-us.apache.org/repos/asf/allura/blob/8e9eb0e5/Allura/allura/tests/test_mail_util.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_mail_util.py 
b/Allura/allura/tests/test_mail_util.py
index e8d5e12..13b5b42 100644
--- a/Allura/allura/tests/test_mail_util.py
+++ b/Allura/allura/tests/test_mail_util.py
@@ -24,6 +24,7 @@ from email.MIMEText import MIMEText
 import mock
 from nose.tools import raises, assert_equal, assert_false, assert_true
 from ming.orm import ThreadLocalORMSession
+from tg import config as tg_config
 
 from alluratest.controller import setup_basic_test, setup_global_objects
 from allura.lib.utils import ConfigProxy
@@ -56,6 +57,12 @@ class TestReactor(unittest.TestCase):
     def test_parse_address_bad_domain(self):
         parse_address('f...@bar.com')
 
+    @td.with_wiki
+    @mock.patch.dict(tg_config, {'forgemail.domain.alternates': 
'.secondary.com .tertiary.com'})
+    def test_parse_address_alternate_domain(self):
+        parse_address('f...@wiki.test.p.secondary.com')
+        parse_address('f...@wiki.test.p.tertiary.com')
+
     @raises(AddressException)
     def test_parse_address_bad_project(self):
         parse_address('foo@wiki.unicorns.p' + config.common_suffix)

Reply via email to