diff options
author | Dirk Wallenstein <halsmit@t-online.de> | 2011-01-26 05:12:29 +0000 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2011-02-28 09:54:05 +0800 |
commit | fec4267113abb18890ddf04b744122892af63383 (patch) | |
tree | 771f7f4ee434c68f2920777a63c932a58358c16d | |
parent | 6e8cc100dc722b153d611c85c43dd22041516da8 (diff) | |
download | patchwork-fec4267113abb18890ddf04b744122892af63383.tar.bz2 patchwork-fec4267113abb18890ddf04b744122892af63383.tar.xz |
parser: Recognize mail headers for delegate and state
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@project.tld
Signed-off-by: Dirk Wallenstein <halsmit@t-online.de>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rwxr-xr-x | 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: |