diff mbox

Guessing project based on email address

Message ID 1300316025.2866.89.camel@feioso
State RFC
Headers show

Commit Message

Guilherme Salgado March 16, 2011, 10:53 p.m. UTC
On Wed, 2011-03-09 at 08:11 -0300, Guilherme Salgado wrote:
[...]
> > 
> > Also, if this was configurable (PATCHWORK_FALLBACK_TO_LISTEMAIL perhaps?), I'd 
> > be much happier :)

I've just changed it to only fallback to list email when the setting
above is True (the default value is False).  The patch for that is
attached.

Comments

Jeremy Kerr April 14, 2011, 4:26 a.m. UTC | #1
Hi Guilherme,

> I've just changed it to only fallback to list email when the setting
> above is True (the default value is False).  The patch for that is
> attached.

OK, looks good. Could you combine with the base patch and add your
signed-off-by to that?

Cheers,


Jeremy
diff mbox

Patch

diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index a29c32f..10b7e9f 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -24,6 +24,7 @@  import re
 import datetime
 import time
 import operator
+import settings
 from email import message_from_file
 try:
     from email.header import Header, decode_header
@@ -105,7 +106,7 @@  def find_project_by_list_address(mail):
 
 def find_project(mail):
     project = find_project_by_listid(mail)
-    if project is None:
+    if project is None and settings.PATCHWORK_FALLBACK_TO_LISTEMAIL:
         project = find_project_by_list_address(mail)
     return project
 
diff --git a/apps/patchwork/tests/patchparser.py b/apps/patchwork/tests/patchparser.py
index d2eabb9..d141412 100644
--- a/apps/patchwork/tests/patchparser.py
+++ b/apps/patchwork/tests/patchparser.py
@@ -20,6 +20,7 @@ 
 import unittest
 import os
 from email import message_from_string
+import settings
 from patchwork.models import Project, Person, Patch, Comment
 from patchwork.tests.utils import read_patch, read_mail, create_email, defaults
 
@@ -303,6 +304,9 @@  class MultipleProjectPatchCommentTest(MultipleProjectPatchTest):
 class EmailProjectGuessing(unittest.TestCase):
     """Projects are guessed based on List-Id headers or recipient addresses"""
     def setUp(self):
+        self.orig_fallback_to_listemail = \
+            settings.PATCHWORK_FALLBACK_TO_LISTEMAIL
+        settings.PATCHWORK_FALLBACK_TO_LISTEMAIL = False
         self.project = Project(linkname = 'test-project-1', name = 'Project 1',
                 listid = '1.example.com', listemail='1@example.com')
         self.project.save()
@@ -320,18 +324,27 @@  class EmailProjectGuessing(unittest.TestCase):
              'bar-foo@bar.foo.example.com'],
             emails)
 
+    def testDoNotFallbackToEmailAddressWhenNotConfiguredTo(self):
+        self.assertFalse(settings.PATCHWORK_FALLBACK_TO_LISTEMAIL)
+        email = MIMEText('')
+        email['To'] = '"First dev list" <1@example.com>'
+        project = find_project(email)
+        self.assertEquals(None, project)
+
     def testNoListId(self):
         email = MIMEText('')
         project = find_project(email)
         self.assertEquals(project, None)
 
     def testNoListIdWithListEmailAsRecipient(self):
+        settings.PATCHWORK_FALLBACK_TO_LISTEMAIL = True
         email = MIMEText('')
         email['To'] = '"First dev list" <1@example.com>'
         project = find_project(email)
         self.assertEquals(self.project, project)
 
     def testNoListIdWithListEmailAsCC(self):
+        settings.PATCHWORK_FALLBACK_TO_LISTEMAIL = True
         email = MIMEText('')
         email['CC'] = ('"First maintainer <maintainer@example.com>, '
                        '"First dev list" <1@example.com>')
@@ -371,6 +384,8 @@  class EmailProjectGuessing(unittest.TestCase):
         self.assertEquals(project, self.project)
 
     def tearDown(self):
+        settings.PATCHWORK_FALLBACK_TO_LISTEMAIL = \
+            self.orig_fallback_to_listemail
         self.project.delete()
 
 
diff --git a/apps/settings.py b/apps/settings.py
index 84a262c..29e3351 100644
--- a/apps/settings.py
+++ b/apps/settings.py
@@ -101,6 +101,9 @@  INSTALLED_APPS = (
 
 DEFAULT_PATCHES_PER_PAGE = 100
 DEFAULT_FROM_EMAIL = 'Patchwork <patchwork@patchwork.example.com>'
+# If set to True, this will cause the parsemail script to lookup projects
+# by email address when one cannot be found by list ID.
+PATCHWORK_FALLBACK_TO_LISTEMAIL = False
 
 ACCOUNT_ACTIVATION_DAYS = 7