From patchwork Wed Jan 26 15:12:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Wallenstein X-Patchwork-Id: 80515 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 996C3B710E for ; Thu, 27 Jan 2011 02:12:51 +1100 (EST) Received: from mailout00.t-online.de (mailout00.t-online.de [194.25.134.16]) by ozlabs.org (Postfix) with ESMTP id F188FB7106 for ; Thu, 27 Jan 2011 02:12:48 +1100 (EST) Received: from fwd01.aul.t-online.de (fwd01.aul.t-online.de ) by mailout00.t-online.de with smtp id 1Pi737-0004O6-B4; Wed, 26 Jan 2011 16:12:45 +0100 Received: from localhost.localdomain (TQ6JVYZfrh1F0itPzFTQ08cHrk8RSoxN66fwB1h4MtGHogDeJuT7BnHAG7CG+fiQ6C@[84.139.31.230]) by fwd01.t-online.de with esmtp id 1Pi72z-1MO5Ym0; Wed, 26 Jan 2011 16:12:37 +0100 From: Dirk Wallenstein To: patchwork@lists.ozlabs.org Subject: [PATCH v2] Recognize mail headers for delegate and state Date: Wed, 26 Jan 2011 16:12:29 +0100 Message-Id: <1296054749-13453-1-git-send-email-halsmit@t-online.de> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1296046625-25263-1-git-send-email-halsmit@t-online.de> References: <1296046625-25263-1-git-send-email-halsmit@t-online.de> X-ID: TQ6JVYZfrh1F0itPzFTQ08cHrk8RSoxN66fwB1h4MtGHogDeJuT7BnHAG7CG+fiQ6C X-TOI-MSGID: c01f0bdc-a2ab-4b38-84a0-bb7680cbe30f X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org 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 --- 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: