[PATCH v2] Recognize mail headers for delegate and state

Dirk Wallenstein halsmit at t-online.de
Thu Jan 27 02:12:29 EST 2011


Introduce two new Patchwork mail headers that determine the initial
state and delegate of a patch.  They take a state name as displayed in
Patchwork and the email address of the wanted delegate.  An example:

X-Patchwork-State: Changes Requested
X-Patchwork-Delegate: maintainer at project.tld

Signed-off-by: Dirk Wallenstein <halsmit at t-online.de>
---
The call to strip() was at the wrong place previously.

 apps/patchwork/bin/parsemail.py |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index 1b73169..2a4df38 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -34,8 +34,10 @@ except ImportError:
     from email.Utils import parsedate_tz, mktime_tz
 
 from patchwork.parser import parse_patch
-from patchwork.models import Patch, Project, Person, Comment
+from patchwork.models import Patch, Project, Person, Comment, State
+from django.contrib.auth.models import User
 
+default_patch_state = 'New'
 list_id_headers = ['List-ID', 'X-Mailing-List', 'X-list']
 
 whitespace_re = re.compile('\s+')
@@ -346,6 +348,24 @@ def clean_content(str):
     str = sig_re.sub('', str)
     return str.strip()
 
+def get_state(state_name):
+    """ Return the state with the given name or the default State """
+    if state_name:
+        try:
+            return State.objects.get(name__iexact=state_name)
+        except State.DoesNotExist:
+            pass
+    return State.objects.get(name=default_patch_state)
+
+def get_delegate(delegate_email):
+    """ Return the delegate with the given email or None """
+    if delegate_email:
+        try:
+            return User.objects.get(email__iexact=delegate_email)
+        except User.DoesNotExist:
+            pass
+    return None
+
 def parse_mail(mail):
 
     # some basic sanity checks
@@ -381,6 +401,9 @@ def parse_mail(mail):
         patch.submitter = author
         patch.msgid = msgid
         patch.project = project
+        patch.state = get_state(mail.get('X-Patchwork-State', '').strip())
+        patch.delegate = get_delegate(
+                mail.get('X-Patchwork-Delegate', '').strip())
         try:
             patch.save()
         except Exception, ex:
-- 
1.7.3.2



More information about the Patchwork mailing list