diff options
Diffstat (limited to 'service')
| -rw-r--r-- | service/pixelated/adapter/model/mail.py | 5 | ||||
| -rw-r--r-- | service/test/unit/adapter/test_mail.py | 17 | ||||
| -rw-r--r-- | service/test/unit/fixtures/bounced_mail_hdoc.json | 218 | 
3 files changed, 240 insertions, 0 deletions
| diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py index 3522f695..b3d2e3a5 100644 --- a/service/pixelated/adapter/model/mail.py +++ b/service/pixelated/adapter/model/mail.py @@ -380,6 +380,11 @@ class PixelatedMail(Mail):          return self.hdoc.content["headers"].get("OpenPGP", None) is not None or \              self.hdoc.content["headers"].get("X-Pixelated-encryption-status", "false") == "true" +    @property +    def bounced(self): +        content_type =  self.hdoc.content["headers"].get("Content-Type", '') +        return re.compile('delivery-status').search(content_type) +      def as_dict(self):          dict_mail = {'header': {k.lower(): v for k, v in self.headers.items()},                       'ident': self.ident, diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py index be7b731d..72bb6d6d 100644 --- a/service/test/unit/adapter/test_mail.py +++ b/service/test/unit/adapter/test_mail.py @@ -23,6 +23,8 @@ import dateutil.parser as dateparser  import base64  from leap.mail.imap.fields import fields  from datetime import datetime +import os +import json  class TestPixelatedMail(unittest.TestCase): @@ -209,6 +211,21 @@ class TestPixelatedMail(unittest.TestCase):          self.assertEquals(body, mail.text_plain_body) +    def test_bounced_mails_are_recognized(self): +        bounced_mail_hdoc = os.path.join(os.path.dirname(__file__), '..', 'fixtures', 'bounced_mail_hdoc.json') +        with open(bounced_mail_hdoc) as f: +            hdoc = json.loads(f.read()) + +        bounced_leap_mail = test_helper.leap_mail() +        bounced_leap_mail[1].content = hdoc +        bounced_mail = PixelatedMail.from_soledad(*bounced_leap_mail, soledad_querier=self.querier) + +        not_bounced_leap_mail = test_helper.leap_mail() +        not_bounced_mail = PixelatedMail.from_soledad(*not_bounced_leap_mail, soledad_querier=self.querier) + +        self.assertTrue(bounced_mail.bounced) +        self.assertFalse(not_bounced_mail.bounced) +      def _create_bdoc(self, raw):          class FakeBDoc:              def __init__(self, raw): diff --git a/service/test/unit/fixtures/bounced_mail_hdoc.json b/service/test/unit/fixtures/bounced_mail_hdoc.json new file mode 100644 index 00000000..5a0f9700 --- /dev/null +++ b/service/test/unit/fixtures/bounced_mail_hdoc.json @@ -0,0 +1,218 @@ +{ +    "body": "3583150D422268B15A27553279767CD26D7AC20937E8BDA8DC55BA53CFF0E9B2", +    "chash": "E374570706F4263C533103893344FD6CBE62B9807ECCC082C159FECF60277656", +    "date": "Wed, 11 Feb 2015 20:49:14 +0100 (CET)", +    "headers": { +        "Auto-Submitted": "auto-replied", +        "Content-Type": "multipart/report; report-type=delivery-status;\n boundary=\"499F57FF7C.1423684154/domain.org\"", +        "Date": "Wed, 11 Feb 2015 20:49:14 +0100 (CET)", +        "Delivered-To": "412cab846cd0d6327f4505e9c4112c64@domain.org", +        "From": "MAILER-DAEMON@domain.org (Mail Delivery System)", +        "MIME-Version": "1.0", +        "Message-Id": "<20150211194914.12CB3804C7@domain.org>", +        "Received": "by domain.org (Postfix)\n id 12CB3804C7; Wed, 11 Feb 2015 20:49:14 +0100 (CET)", +        "Return-Path": "<>", +        "Subject": "Undelivered Mail Returned to Sender", +        "To": "cuzcuz2@domain.org", +        "X-Leap-Provenance": "Wed, 11 Feb 2015 19:49:14 -0000; pubkey=\"E2F104EE8B01F675\"", +        "X-Leap-Signature": "could not verify", +        "X-Original-To": "cuzcuz2@domain.org" +    }, +    "msgid": null, +    "multi": true, +    "part_map": { +        "1": { +            "ctype": "text/plain", +            "headers": [ +                [ +                    "Content-Description", +                    "Notification" +                ], +                [ +                    "Content-Type", +                    "text/plain; charset=us-ascii" +                ] +            ], +            "multi": false, +            "parts": 1, +            "phash": "3583150D422268B15A27553279767CD26D7AC20937E8BDA8DC55BA53CFF0E9B2", +            "size": 896 +        }, +        "2": { +            "ctype": "message/delivery-status", +            "headers": [ +                [ +                    "Content-Description", +                    "Delivery report" +                ], +                [ +                    "Content-Type", +                    "message/delivery-status" +                ] +            ], +            "multi": true, +            "parts": 2, +            "phash": null, +            "size": 772 +        }, +        "3": { +            "ctype": "text/plain", +            "headers": [ +                [ +                    "Reporting-MTA", +                    "dns; domain.org" +                ], +                [ +                    "X-Postfix-Queue-ID", +                    "499F57FF7C" +                ], +                [ +                    "X-Postfix-Sender", +                    "rfc822; cuzcuz2@domain.org" +                ], +                [ +                    "Arrival-Date", +                    "Wed, 11 Feb 2015 20:49:10 +0100 (CET)" +                ] +            ], +            "multi": false, +            "part_map": { +                "0": { +                    "ctype": "text/plain", +                    "headers": [ +                        [ +                            "Final-Recipient", +                            "rfc822; inexistentaccount@domain.com" +                        ], +                        [ +                            "Original-Recipient", +                            "rfc822;inexistentaccount@domain.com" +                        ], +                        [ +                            "Action", +                            "failed" +                        ], +                        [ +                            "Status", +                            "5.1.1" +                        ], +                        [ +                            "Remote-MTA", +                            "dns; ASPMX.L.DOMAIN.com" +                        ], +                        [ +                            "Diagnostic-Code", +                            "smtp; 550-5.1.1 The email account that you tried to reach does\n not exist. Please try 550-5.1.1 double-checking the\n recipient's email\n address for typos or 550-5.1.1 unnecessary spaces." +                        ] +                    ], +                    "multi": false, +                    "parts": 1, +                    "phash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", +                    "size": 497 +                }, +                "1": { +                    "ctype": "message/rfc822", +                    "headers": [ +                        [ +                            "Content-Description", +                            "Undelivered Message" +                        ], +                        [ +                            "Content-Type", +                            "message/rfc822" +                        ] +                    ], +                    "multi": true, +                    "parts": 1, +                    "phash": null, +                    "size": 2397 +                }, +                "2": { +                    "headers": { +                        "Content-Type": "multipart/signed; protocol=\"application/pgp-signature\";\n micalg=\"pgp-sha512\"; boundary=\"===============5178971458699783746==\"", +                        "Date": "2015-02-11T16:48:54.245828-03:00", +                        "From": "cuzcuz2@domain.org", +                        "MIME-Version": "1.0", +                        "Message-Id": "<20150211194857.19888.1605637474.0@host>", +                        "OpenPGP": "id=E2F104EE8B01F675;\n url=\"https://domain.org/key/cuzcuz2\"; preference=\"signencrypt\"", +                        "Received": "from 0.3.9-1-gc1f9c92 (unknown [127.0.0.1])\n (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))\n (Client CN \"UNLIMITEDdbe63unx9tfxa286ol3che4vx\",\n Issuer \"LEAP_Example Root CA (client certificates only!)\" (verified OK))\n by domain.org (Postfix) with ESMTPS id 499F57FF7C\n for <inexistentaccount@domain.com>; Wed, 11 Feb 2015 20:49:10 +0100 (CET)", +                        "Return-Path": "<cuzcuz2@domain.org>", +                        "Subject": "volte", +                        "To": "inexistentaccount@domain.com" +                    }, +                    "multi": true, +                    "part_map": { +                        "1": { +                            "ctype": "multipart/mixed", +                            "headers": [ +                                [ +                                    "Received", +                                    "by bitmask.local from 127.0.0.1 with ESMTP ;\n Wed, 11 Feb 2015 16:48:55 -0300" +                                ], +                                [ +                                    "Content-Type", +                                    "multipart/mixed; boundary=\"===============4044974129166450777==\"" +                                ], +                                [ +                                    "MIME-Version", +                                    "1.0" +                                ] +                            ], +                            "multi": true, +                            "parts": 1, +                            "phash": null, +                            "size": 370 +                        }, +                        "2": { +                            "ctype": "text/plain", +                            "headers": [ +                                [ +                                    "Content-Type", +                                    "text/plain; charset=\"utf-8\"" +                                ], +                                [ +                                    "MIME-Version", +                                    "1.0" +                                ], +                                [ +                                    "Content-Transfer-Encoding", +                                    "base64" +                                ] +                            ], +                            "multi": false, +                            "parts": 1, +                            "phash": "231B2728DE0EF4968B1183F0DD7FA9C963A90996E64B9B7A9AB6936F0B1EADB7", +                            "size": 100 +                        } +                    } +                }, +                "3": { +                    "ctype": "application/pgp-signature", +                    "headers": [ +                        [ +                            "Content-Type", +                            "application/pgp-signature; name=\"signature.asc\"" +                        ], +                        [ +                            "MIME-Version", +                            "1.0" +                        ], +                        [ +                            "Content-Description", +                            "OpenPGP Digital Signature" +                        ] +                    ], +                    "multi": false, +                    "parts": 1, +                    "phash": "90A694453A671BA3144BA9147ACA4C4B41DF7E714377C584E802ED5469AB5365", +                    "size": 929 +                } +            }, +            "parts": 1, +            "phash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", +            "size": 200 +        } +    }, +    "subject": "Undelivered Mail Returned to Sender", +    "type": "head" +} | 
