From patchwork Wed Jan 26 12:57:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Wallenstein X-Patchwork-Id: 80503 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 B79051007D4 for ; Wed, 26 Jan 2011 23:57:30 +1100 (EST) Received: from mailout12.t-online.de (mailout12.t-online.de [194.25.134.22]) by ozlabs.org (Postfix) with ESMTP id 8CFA5B70F9 for ; Wed, 26 Jan 2011 23:57:28 +1100 (EST) Received: from fwd02.aul.t-online.de (fwd02.aul.t-online.de ) by mailout12.t-online.de with smtp id 1Pi4w9-0007PX-0Z; Wed, 26 Jan 2011 13:57:25 +0100 Received: from localhost.localdomain (EIv-t2ZEYhhHkrSOYXOnZfIVdhLbzbc6wCroVAY-5-rW6NNU0zH1Yl54gm3fhPmQnX@[84.139.31.230]) by fwd02.t-online.de with esmtp id 1Pi4w1-1vsUuu0; Wed, 26 Jan 2011 13:57:17 +0100 From: Dirk Wallenstein To: patchwork@lists.ozlabs.org Subject: [PATCH] Recognize mail headers for delegate and state Date: Wed, 26 Jan 2011 13:57:05 +0100 Message-Id: <1296046625-25263-1-git-send-email-halsmit@t-online.de> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <20110125210647.06A9CBB0B9@gemini.denx.de> References: <20110125210647.06A9CBB0B9@gemini.denx.de> X-ID: EIv-t2ZEYhhHkrSOYXOnZfIVdhLbzbc6wCroVAY-5-rW6NNU0zH1Yl54gm3fhPmQnX X-TOI-MSGID: 64901e0c-c980-45ef-b30b-421da69f12a3 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 --- apps/patchwork/bin/parsemail.py | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-) diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py index 1b73169..dbd4c3c 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.strip()) + 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.strip()) + except User.DoesNotExist: + pass + return None + def parse_mail(mail): # some basic sanity checks @@ -381,6 +401,8 @@ def parse_mail(mail): patch.submitter = author patch.msgid = msgid patch.project = project + patch.state = get_state(mail.get('X-Patchwork-State')) + patch.delegate = get_delegate(mail.get('X-Patchwork-Delegate')) try: patch.save() except Exception, ex: