From nobody Tue Apr 30 01:53:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524587103521503.3025244980481; Tue, 24 Apr 2018 09:25:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89AD07F776; Tue, 24 Apr 2018 16:25:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F76C7E567; Tue, 24 Apr 2018 16:25:02 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2E25C18033EB; Tue, 24 Apr 2018 16:25:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3OGP0Pg012591 for ; Tue, 24 Apr 2018 12:25:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id E550A80948; Tue, 24 Apr 2018 16:24:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 816867E682 for ; Tue, 24 Apr 2018 16:24:21 +0000 (UTC) Received: from mail-pg0-f44.google.com (mail-pg0-f44.google.com [74.125.83.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0ADC53003F29 for ; Tue, 24 Apr 2018 16:04:28 +0000 (UTC) Received: by mail-pg0-f44.google.com with SMTP id e12so11196375pgn.9 for ; Tue, 24 Apr 2018 09:04:27 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.55]) by smtp.gmail.com with ESMTPSA id z27sm1209793pfi.33.2018.04.24.09.04.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 09:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=HwbUkIPt2ENfOybAE2AYz77j/1Dt6FXqbEpuorVJq0c=; b=A1xMmjX5sc2mklZoucmjofiMCU0jXuAyrYkQoKM6avqMSNWG7PE/EXiSIdRlGAcIKe +81it+yeLCYOn6Z4qoKbfRSLV8uxLjfo6oHfXiniN/UPUJpSarEThhOzF+PqXTU/HGZa hCm8DJQYLmL4uTN6rq7JSRwwzAgmbz8olEwRl6C3E5WDzjbM5c47NUp1ghebpBypwFAu 46Wlxr80BxVwFdDZU+teLJsm/1Ma77w1AKWdrsNS6gDNMEZBzbWQ+f6fk+Gp9dnsN/o8 lkfRhjYoAIygzahYStUjyh0yaIsP3/cDZt37BWMc2YSyiazcYm/BYzu4Eu3/UZ77+5P+ BCWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HwbUkIPt2ENfOybAE2AYz77j/1Dt6FXqbEpuorVJq0c=; b=EYRhwF2H9s756pNgFxhJ9LD0nW33WwHLUhURSzwcLnX4+o7D3Ysh1wXJetuVUqTrGK My69PlOgPK+a0ob4D9s1wkDyusRSbQU0LCkswBr1WnNk+dnsK2eipGmHfFsXD/3g+AHK hmigO6Rgg0dazvgA7soYhgm6CkhpnR6vjKGixpxTmtDZqZ1HIEdxSqpb/KnAAVifkqJp zjT6YlJXa7JeZyZGqjlywmRSvwpIyVjtVjqkBk0JHcGb7s7vK9kF4cQJkIx1C3UvZ1xw 6KS6qtwXfyJ8ei8iQajG033WyWdl21OgM+OTa1gq7vRgcx4sBJNmNsIeF2Ml/M24NbOa 2Xzg== X-Gm-Message-State: ALQs6tC6Ql1lE0gKE1fXK8O9H3JWLWc95Mk3Vu7s+/prGZCwg5cTPW7M w3o2NvrxxvB6Lxde6Wtq32JaQdhr X-Google-Smtp-Source: AIpwx48U3uzGwbW26RJbkYaAs1NIh4jGPKilNkwaZZsgY3SqF9H8pwkqi34uOth+yEdLTTcZNZE0Bw== X-Received: by 2002:a17:902:290a:: with SMTP id g10-v6mr25510482plb.155.1524585866764; Tue, 24 Apr 2018 09:04:26 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Tue, 24 Apr 2018 21:34:00 +0530 Message-Id: <20180424160400.29938-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 24 Apr 2018 16:04:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 24 Apr 2018 16:04:28 +0000 (UTC) for IP:'74.125.83.44' DOMAIN:'mail-pg0-f44.google.com' HELO:'mail-pg0-f44.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.551 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 74.125.83.44 mail-pg0-f44.google.com 74.125.83.44 mail-pg0-f44.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH] Text to json convertor for mbox X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 24 Apr 2018 16:25:02 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Mbox would now return a dictionary object which would help REST API deseria= lize easily into model object. [WIP] POST endpoint for messages. It's a work in progress for creating new message which is improvement of le= gacy endpoint: "import" --- api/rest.py | 19 ++++++++++++++++++- mbox.py | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/api/rest.py b/api/rest.py index 6aa744d..ee814e8 100644 --- a/api/rest.py +++ b/api/rest.py @@ -303,8 +303,25 @@ class StaticTextRenderer(renderers.BaseRenderer): return data =20 class MessagesViewSet(ProjectMessagesViewSetMixin, - BaseMessageViewSet): + BaseMessageViewSet, mixins.CreateModelMixin): serializer_class =3D MessageSerializer + =20 + def create(self, request, *args, **kwargs): + def find_message_projects(m): + return [p for p in Project.objects.all() if p.recognizes(m)] + =20 + msg =3D MboxMessage(request.data) + project =3D find_message_projects(msg) + msg.project =3D project + serializer =3D self.get_serializer(data=3Dmsg.get_json()) + serializer.is_valid(raise_exception=3DTrue) + self.perform_create(serializer) + headers =3D self.get_success_headers(serializer.data) + return Response(serializer.data, status=3Dstatus.HTTP_201_CREATED,= headers=3Dheaders) + + + def perform_create(self, serializer): + serializer.save() =20 @detail_route(renderer_classes=3D[StaticTextRenderer]) def mbox(self, request, *args, **kwargs): diff --git a/mbox.py b/mbox.py index 3692cc6..6b42e8f 100644 --- a/mbox.py +++ b/mbox.py @@ -13,6 +13,7 @@ import email.utils import email.header import datetime import re +import json =20 def _parse_header(header): r =3D '' @@ -267,3 +268,23 @@ class MboxMessage(object): if c =3D=3D 0: return True return False + + def get_json(self): + """ + """ + msg =3D {} + msg['message_id'] =3D self.get_message_id() + msg['in_reply_to'] =3D self.get_in_reply_to() or "" + msg['date'] =3D self.get_date() + msg['subject'] =3D self.get_subject() + msg['stripped_subject'] =3D self.get_subject(strip_tags=3DTrue) + msg['version'] =3D self.get_version() + msg['sender'] =3D json.dumps(self.get_from()) + msg['recipients'] =3D json.dumps(self.get_to() + self.get_cc()) + msg['prefixes']=3Djson.dumps(self.get_prefixes()) + msg['is_series_head'] =3D self.is_series_head() + msg['is_patch'] =3D self.is_patch() + msg['patch_num'] =3D self.get_num()[0] + msg['project'] =3D self.project=20 + msg['mbox'] =3D self._mbox + return msg --=20 2.14.3 (Apple Git-98) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel