From patchwork Fri Apr 6 11:24:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Veronika Kabatova X-Patchwork-Id: 895671 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40Hcn002DHz9s16 for ; Fri, 6 Apr 2018 21:25:08 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40Hcmz5NmZzF1y2 for ; Fri, 6 Apr 2018 21:25:07 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=vkabatov@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40Hcms3YKmzF1w1 for ; Fri, 6 Apr 2018 21:25:01 +1000 (AEST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57CB2406E8A4 for ; Fri, 6 Apr 2018 11:24:58 +0000 (UTC) Received: from vkabatova.usersys.redhat.com (unknown [10.43.17.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id B20FEAFD68; Fri, 6 Apr 2018 11:24:57 +0000 (UTC) From: vkabatov@redhat.com To: patchwork@lists.ozlabs.org Subject: [PATCH] api: Show all headers with the same key Date: Fri, 6 Apr 2018 13:24:49 +0200 Message-Id: <20180406112449.17184-1-vkabatov@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 06 Apr 2018 11:24:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 06 Apr 2018 11:24:58 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkabatov@redhat.com' RCPT:'' X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" From: Veronika Kabatova While the code on our side returns all (key, value) pairs for email headers, Django's REST framework probably uses dictionaries behind the scenes. This means that having multiple headers with same key (eg 'Received', which is totally valid and common situation), only one of these headers is visible in the REST API. Let's hack around this by returning a list of values in case the key is present multiple times. Signed-off-by: Veronika Kabatova Reviewed-by: Stephen Finucane --- patchwork/api/cover.py | 12 +++++++++++- patchwork/api/patch.py | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py index 1064504..dd1db97 100644 --- a/patchwork/api/cover.py +++ b/patchwork/api/cover.py @@ -57,8 +57,18 @@ class CoverLetterDetailSerializer(CoverLetterListSerializer): headers = SerializerMethodField() def get_headers(self, instance): + headers = {} + if instance.headers: - return email.parser.Parser().parsestr(instance.headers, True) + parsed = email.parser.Parser().parsestr(instance.headers, True) + for key in parsed.keys(): + headers[key] = parsed.get_all(key) + # Let's return a single string instead of a list if only one + # header with this key is present + if len(headers[key]) == 1: + headers[key] = headers[key][0] + + return headers class Meta: model = CoverLetter diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py index 115feff..645b0e9 100644 --- a/patchwork/api/patch.py +++ b/patchwork/api/patch.py @@ -123,8 +123,18 @@ class PatchDetailSerializer(PatchListSerializer): prefixes = SerializerMethodField() def get_headers(self, patch): + headers = {} + if patch.headers: - return email.parser.Parser().parsestr(patch.headers, True) + parsed = email.parser.Parser().parsestr(patch.headers, True) + for key in parsed.keys(): + headers[key] = parsed.get_all(key) + # Let's return a single string instead of a list if only one + # header with this key is present + if len(headers[key]) == 1: + headers[key] = headers[key][0] + + return headers def get_prefixes(self, instance): return clean_subject(instance.name)[1]