From: Neil Smith Date: Sun, 27 Mar 2016 14:48:32 +0000 (+0100) Subject: Initial commit X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=66626d16adffb0245d288e94c36638a9eac00055;p=dmarc.git Initial commit --- 66626d16adffb0245d288e94c36638a9eac00055 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7703496 --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +*.py[cod] + +# C extensions +*.so + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 +__pycache__ + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox +nosetests.xml + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# IPython +.ipynb* + +# Sublime text +*.sublime-workspace + +# Logs +*.log + +# Config file +dmarc.ini diff --git a/dmarc.sublime-project b/dmarc.sublime-project new file mode 100644 index 0000000..861201f --- /dev/null +++ b/dmarc.sublime-project @@ -0,0 +1,12 @@ +{ + "folders": + [ + { + "path": "." + } + ], + "settings": + { + "tab_size": 4 + } +} diff --git a/read_report.ipynb b/read_report.ipynb new file mode 100644 index 0000000..1cf8a2a --- /dev/null +++ b/read_report.ipynb @@ -0,0 +1,827 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import configparser\n", + "import imaplib\n", + "# import ssl\n", + "# import base64\n", + "# import email.parser\n", + "import email\n", + "import io\n", + "import zipfile\n", + "import xml.etree.ElementTree" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['dmarc.ini']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "config = configparser.ConfigParser()\n", + "config.read('dmarc.ini')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['server', 'username', 'port', 'password']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[k for k in config['DEFAULT']]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'imap.njae.me.uk'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "config['DEFAULT']['server']" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "mailbox = imaplib.IMAP4(host=config['DEFAULT']['server'], \n", + " port=config['DEFAULT']['port'])" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('OK', [None])" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mailbox.starttls()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('OK', [b'Logged in'])" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mailbox.login(config['DEFAULT']['username'], config['DEFAULT']['password'])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('OK', [b'169'])" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mailbox.select('INBOX', readonly=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('OK',\n", + " [b'1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169'])" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mailbox.search(None, \"ALL\")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('OK', [b'164 165 166 167 168 169'])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "resp, nums = mailbox.search(None, \"SINCE 23-Mar-2016\")\n", + "resp, nums" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[b'164', b'165', b'166', b'167', b'168', b'169']" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nums[0].split()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('OK',\n", + " [(b'169 (RFC822 {4480}',\n", + " b'Return-Path: \\r\\nDelivered-To: dmarc@njae.me.uk\\r\\nReceived: from localhost (localhost [127.0.0.1])\\r\\n\\tby mail.njae.me.uk (Postfix) with ESMTP id 2A065106\\r\\n\\tfor ; Sun, 27 Mar 2016 10:28:09 +0100 (BST)\\r\\nX-Virus-Scanned: Debian amavisd-new at njae.me.uk\\r\\nAuthentication-Results: ogedei.njae.me.uk (amavisd-new);\\r\\n\\tdkim=pass (2048-bit key) header.d=google.com\\r\\nReceived: from mail.njae.me.uk ([127.0.0.1])\\r\\n\\tby localhost (ogedei.njae.me.uk [127.0.0.1]) (amavisd-new, port 10024)\\r\\n\\twith ESMTP id S06rrC9pLQlu for ;\\r\\n\\tSun, 27 Mar 2016 10:28:07 +0100 (BST)\\r\\nReceived-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.223.201; helo=mail-io0-f201.google.com; envelope-from=noreply-dmarc-support@google.com; receiver=dmarc@njae.me.uk \\r\\nAuthentication-Results: mail.njae.me.uk; dmarc=pass header.from=google.com\\r\\nAuthentication-Results: mail.njae.me.uk; dkim=pass\\r\\n\\treason=\"2048-bit key; unprotected key\"\\r\\n\\theader.d=google.com header.i=@google.com header.b=kRG+/uqj;\\r\\n\\tdkim-adsp=pass; dkim-atps=neutral\\r\\nReceived: from mail-io0-f201.google.com (mail-io0-f201.google.com [209.85.223.201])\\r\\n\\tby mail.njae.me.uk (Postfix) with ESMTPS id 36952EB\\r\\n\\tfor ; Sun, 27 Mar 2016 10:28:06 +0100 (BST)\\r\\nReceived: by mail-io0-f201.google.com with SMTP id 124so13927004iov.0\\r\\n for ; Sun, 27 Mar 2016 02:28:06 -0700 (PDT)\\r\\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\\r\\n d=google.com; s=20120113;\\r\\n h=mime-version:message-id:date:subject:from:to:content-disposition\\r\\n :content-transfer-encoding;\\r\\n bh=WebWWyH674VepKwkY7+3OEpaPDkuJsYet/WYzuiqEhc=;\\r\\n b=kRG+/uqjzLNy4IsueOq2bd1CW4i2x4dzf5Dg+soCJzKTycsrUudvIkphybOCPAE4aW\\r\\n 1ffplA6Tt9mxOpAfYppahUPeWFXtCE5AEf3/qorGxcv/yHv8S3TFiUqulTLccOyLbhoG\\r\\n P02OxDg38XWHLob7gOKUsqdCAmPfxqATsvakVN/SJkJswU4Fm8iBBaoca7wgW/A97eJs\\r\\n zKnmyWvpc1juUp5YLYWVGwL9927tbw8bO+0acz53Qgwj+QScqSftMNeLzKS3Ct11RkvX\\r\\n W49XblUJOHS+lbtVF6radeGKbsGp09QClMLAyLKEUeYTTgux/K0CIuB3A+BmQ1O3Souk\\r\\n cN7A==\\r\\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\\r\\n d=1e100.net; s=20130820;\\r\\n h=x-gm-message-state:mime-version:message-id:date:subject:from:to\\r\\n :content-disposition:content-transfer-encoding;\\r\\n bh=WebWWyH674VepKwkY7+3OEpaPDkuJsYet/WYzuiqEhc=;\\r\\n b=iy79Cfu0C9JtwPWMHnqS7hbVnFOcPMPttWMomjdh1ekeq+jxAg9335NteUoNg79PTo\\r\\n QSJbg9YAM4bvlFPOcPrSNQN+Q5fdopi1TuDBgHK7L0Rb9Vv8eKVRSG8pyLAw7Izs+y/H\\r\\n 9Rlh8qfOV3Te/pzQb+4eA+SS39D9O8L1Cmg2p19Y+XmNfX8xd/UhIKzXNNSbQODMOwnL\\r\\n xw0wmbMu/3wMgnUgJVfcp7BkZVhJzO7CqNfkGlv4BSpSGEH2+I0AwZFQgLfytwJ4j3nh\\r\\n oH217zO+us6vAE2gV3zneO4X3Pf88J7ma+I7Et6Bl2cM1TunPpisx6aqnzPdIMhJwMDt\\r\\n GM+w==\\r\\nX-Gm-Message-State: AD7BkJIXsS+d+n0kHSQlvoPQuXFYd9jWCwS846F7EdDD9cR1K1RkBPs0SrrYY9ARYXU/K7Bs7gdjAw==\\r\\nMIME-Version: 1.0\\r\\nX-Received: by 10.157.11.13 with SMTP id a13mr14086672ota.35.1459070885519;\\r\\n Sun, 27 Mar 2016 02:28:05 -0700 (PDT)\\r\\nMessage-ID: <2150510829392606201@google.com>\\r\\nDate: Sun, 27 Mar 2016 09:28:05 +0000\\r\\nSubject: Report domain: njae.me.uk Submitter: google.com Report-ID: 2150510829392606201\\r\\nFrom: noreply-dmarc-support@google.com\\r\\nTo: dmarc@njae.me.uk\\r\\nContent-Type: application/zip; \\r\\n\\tname=\"google.com!njae.me.uk!1458950400!1459036799.zip\"\\r\\nContent-Disposition: attachment; \\r\\n\\tfilename=\"google.com!njae.me.uk!1458950400!1459036799.zip\"\\r\\nContent-Transfer-Encoding: base64\\r\\n\\r\\nUEsDBAoAAAAIADpKe0gTM/X5EAIAAKsGAAAvAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5\\r\\nNTA0MDAhMTQ1OTAzNjc5OS54bWzVVU1vnDAQvedXoL0vBrJQqBynp/6C9oy8ZmDdBduyTZL99zVr\\r\\n85FNKkVVpKqnNW9m3swbP1j8+DL00RNow6V42KVxsotAMNlw0T3sfv74vi930SO5wy1Ac6TsTO6i\\r\\nCGtQUtt6AEsbaumEOVTqrhZ0ANJJ2fUQMzlgtIA+BwbKeyKkY+gv+2agmu3NqCa6b9synxdqXqym\\r\\nNZPCUmZrLlpJTtYq8xWhUBqvpYgiKswzaJQdiiIvE8f1tt4TBxm8IVmaJ3malFl1X2VFUmRJitEa\\r\\n9ulOKtSaii6IcdAROi5IesjLKk8OiWvmkTkOopmiVXJffKkqN4qYydBrtqXbdqdYyZ6zS63GY8/N\\r\\nCZZBpNuOIOIXhXiAeDw7Ng/5OG3OfCAaI38IoFHtFZt+PaTcRQjASIVnMwNmRhSzJJ1kTYfrmO+N\\r\\n5BbJpJ6n0/J50W/kqBnUXJEyi9OkitPyELs9rPicyeQoXC+M/GGGQzt4ov3oFtbMgWkL3ChpuHXG\\r\\nDWNvkU3etIPW2cklLOsIetsQWHaykXjT093QLAzzBoTlLXevzVJ2AtqArlsth1c3s8UD0ZtyTEd7\\r\\nqjWYsbcr48204YpZ71bfy0tj/Juyvfng6omGKGrM5Krrw6Jty4k3qj+LfzUXutU0Jc82+YhjsjSL\\r\\niyrO87jI/oFjvL53HOMD/5Fj/vSd+Ay3/D33h5yC0fq/8xtQSwECCgAKAAAACAA6SntIEzP1+RAC\\r\\nAACrBgAALwAAAAAAAAAAAAAAAAAAAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5NTA0MDAh\\r\\nMTQ1OTAzNjc5OS54bWxQSwUGAAAAAAEAAQBdAAAAXQIAAAAA\\r\\n'),\n", + " b')'])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_resp = mailbox.fetch(nums[0].split()[-1], '(RFC822)')\n", + "all_resp" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Return-Path: \r\n", + "Delivered-To: dmarc@njae.me.uk\r\n", + "Received: from localhost (localhost [127.0.0.1])\r\n", + "\tby mail.njae.me.uk (Postfix) with ESMTP id 2A065106\r\n", + "\tfor ; Sun, 27 Mar 2016 10:28:09 +0100 (BST)\r\n", + "X-Virus-Scanned: Debian amavisd-new at njae.me.uk\r\n", + "Authentication-Results: ogedei.njae.me.uk (amavisd-new);\r\n", + "\tdkim=pass (2048-bit key) header.d=google.com\r\n", + "Received: from mail.njae.me.uk ([127.0.0.1])\r\n", + "\tby localhost (ogedei.njae.me.uk [127.0.0.1]) (amavisd-new, port 10024)\r\n", + "\twith ESMTP id S06rrC9pLQlu for ;\r\n", + "\tSun, 27 Mar 2016 10:28:07 +0100 (BST)\r\n", + "Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.223.201; helo=mail-io0-f201.google.com; envelope-from=noreply-dmarc-support@google.com; receiver=dmarc@njae.me.uk \r\n", + "Authentication-Results: mail.njae.me.uk; dmarc=pass header.from=google.com\r\n", + "Authentication-Results: mail.njae.me.uk; dkim=pass\r\n", + "\treason=\"2048-bit key; unprotected key\"\r\n", + "\theader.d=google.com header.i=@google.com header.b=kRG+/uqj;\r\n", + "\tdkim-adsp=pass; dkim-atps=neutral\r\n", + "Received: from mail-io0-f201.google.com (mail-io0-f201.google.com [209.85.223.201])\r\n", + "\tby mail.njae.me.uk (Postfix) with ESMTPS id 36952EB\r\n", + "\tfor ; Sun, 27 Mar 2016 10:28:06 +0100 (BST)\r\n", + "Received: by mail-io0-f201.google.com with SMTP id 124so13927004iov.0\r\n", + " for ; Sun, 27 Mar 2016 02:28:06 -0700 (PDT)\r\n", + "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n", + " d=google.com; s=20120113;\r\n", + " h=mime-version:message-id:date:subject:from:to:content-disposition\r\n", + " :content-transfer-encoding;\r\n", + " bh=WebWWyH674VepKwkY7+3OEpaPDkuJsYet/WYzuiqEhc=;\r\n", + " b=kRG+/uqjzLNy4IsueOq2bd1CW4i2x4dzf5Dg+soCJzKTycsrUudvIkphybOCPAE4aW\r\n", + " 1ffplA6Tt9mxOpAfYppahUPeWFXtCE5AEf3/qorGxcv/yHv8S3TFiUqulTLccOyLbhoG\r\n", + " P02OxDg38XWHLob7gOKUsqdCAmPfxqATsvakVN/SJkJswU4Fm8iBBaoca7wgW/A97eJs\r\n", + " zKnmyWvpc1juUp5YLYWVGwL9927tbw8bO+0acz53Qgwj+QScqSftMNeLzKS3Ct11RkvX\r\n", + " W49XblUJOHS+lbtVF6radeGKbsGp09QClMLAyLKEUeYTTgux/K0CIuB3A+BmQ1O3Souk\r\n", + " cN7A==\r\n", + "X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n", + " d=1e100.net; s=20130820;\r\n", + " h=x-gm-message-state:mime-version:message-id:date:subject:from:to\r\n", + " :content-disposition:content-transfer-encoding;\r\n", + " bh=WebWWyH674VepKwkY7+3OEpaPDkuJsYet/WYzuiqEhc=;\r\n", + " b=iy79Cfu0C9JtwPWMHnqS7hbVnFOcPMPttWMomjdh1ekeq+jxAg9335NteUoNg79PTo\r\n", + " QSJbg9YAM4bvlFPOcPrSNQN+Q5fdopi1TuDBgHK7L0Rb9Vv8eKVRSG8pyLAw7Izs+y/H\r\n", + " 9Rlh8qfOV3Te/pzQb+4eA+SS39D9O8L1Cmg2p19Y+XmNfX8xd/UhIKzXNNSbQODMOwnL\r\n", + " xw0wmbMu/3wMgnUgJVfcp7BkZVhJzO7CqNfkGlv4BSpSGEH2+I0AwZFQgLfytwJ4j3nh\r\n", + " oH217zO+us6vAE2gV3zneO4X3Pf88J7ma+I7Et6Bl2cM1TunPpisx6aqnzPdIMhJwMDt\r\n", + " GM+w==\r\n", + "X-Gm-Message-State: AD7BkJIXsS+d+n0kHSQlvoPQuXFYd9jWCwS846F7EdDD9cR1K1RkBPs0SrrYY9ARYXU/K7Bs7gdjAw==\r\n", + "MIME-Version: 1.0\r\n", + "X-Received: by 10.157.11.13 with SMTP id a13mr14086672ota.35.1459070885519;\r\n", + " Sun, 27 Mar 2016 02:28:05 -0700 (PDT)\r\n", + "Message-ID: <2150510829392606201@google.com>\r\n", + "Date: Sun, 27 Mar 2016 09:28:05 +0000\r\n", + "Subject: Report domain: njae.me.uk Submitter: google.com Report-ID: 2150510829392606201\r\n", + "From: noreply-dmarc-support@google.com\r\n", + "To: dmarc@njae.me.uk\r\n", + "Content-Type: application/zip; \r\n", + "\tname=\"google.com!njae.me.uk!1458950400!1459036799.zip\"\r\n", + "Content-Disposition: attachment; \r\n", + "\tfilename=\"google.com!njae.me.uk!1458950400!1459036799.zip\"\r\n", + "Content-Transfer-Encoding: base64\r\n", + "\r\n", + "UEsDBAoAAAAIADpKe0gTM/X5EAIAAKsGAAAvAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5\r\n", + "NTA0MDAhMTQ1OTAzNjc5OS54bWzVVU1vnDAQvedXoL0vBrJQqBynp/6C9oy8ZmDdBduyTZL99zVr\r\n", + "85FNKkVVpKqnNW9m3swbP1j8+DL00RNow6V42KVxsotAMNlw0T3sfv74vi930SO5wy1Ac6TsTO6i\r\n", + "CGtQUtt6AEsbaumEOVTqrhZ0ANJJ2fUQMzlgtIA+BwbKeyKkY+gv+2agmu3NqCa6b9synxdqXqym\r\n", + "NZPCUmZrLlpJTtYq8xWhUBqvpYgiKswzaJQdiiIvE8f1tt4TBxm8IVmaJ3malFl1X2VFUmRJitEa\r\n", + "9ulOKtSaii6IcdAROi5IesjLKk8OiWvmkTkOopmiVXJffKkqN4qYydBrtqXbdqdYyZ6zS63GY8/N\r\n", + "CZZBpNuOIOIXhXiAeDw7Ng/5OG3OfCAaI38IoFHtFZt+PaTcRQjASIVnMwNmRhSzJJ1kTYfrmO+N\r\n", + "5BbJpJ6n0/J50W/kqBnUXJEyi9OkitPyELs9rPicyeQoXC+M/GGGQzt4ov3oFtbMgWkL3ChpuHXG\r\n", + "DWNvkU3etIPW2cklLOsIetsQWHaykXjT093QLAzzBoTlLXevzVJ2AtqArlsth1c3s8UD0ZtyTEd7\r\n", + "qjWYsbcr48204YpZ71bfy0tj/Juyvfng6omGKGrM5Krrw6Jty4k3qj+LfzUXutU0Jc82+YhjsjSL\r\n", + "iyrO87jI/oFjvL53HOMD/5Fj/vSd+Ay3/D33h5yC0fq/8xtQSwECCgAKAAAACAA6SntIEzP1+RAC\r\n", + "AACrBgAALwAAAAAAAAAAAAAAAAAAAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5NTA0MDAh\r\n", + "MTQ1OTAzNjc5OS54bWxQSwUGAAAAAAEAAQBdAAAAXQIAAAAA\r\n", + "\n" + ] + } + ], + "source": [ + "print(all_resp[1][0][1].decode('utf-8'))" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('OK',\n", + " [(b'169 (BODY[1] {986}',\n", + " b'UEsDBAoAAAAIADpKe0gTM/X5EAIAAKsGAAAvAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5\\r\\nNTA0MDAhMTQ1OTAzNjc5OS54bWzVVU1vnDAQvedXoL0vBrJQqBynp/6C9oy8ZmDdBduyTZL99zVr\\r\\n85FNKkVVpKqnNW9m3swbP1j8+DL00RNow6V42KVxsotAMNlw0T3sfv74vi930SO5wy1Ac6TsTO6i\\r\\nCGtQUtt6AEsbaumEOVTqrhZ0ANJJ2fUQMzlgtIA+BwbKeyKkY+gv+2agmu3NqCa6b9synxdqXqym\\r\\nNZPCUmZrLlpJTtYq8xWhUBqvpYgiKswzaJQdiiIvE8f1tt4TBxm8IVmaJ3malFl1X2VFUmRJitEa\\r\\n9ulOKtSaii6IcdAROi5IesjLKk8OiWvmkTkOopmiVXJffKkqN4qYydBrtqXbdqdYyZ6zS63GY8/N\\r\\nCZZBpNuOIOIXhXiAeDw7Ng/5OG3OfCAaI38IoFHtFZt+PaTcRQjASIVnMwNmRhSzJJ1kTYfrmO+N\\r\\n5BbJpJ6n0/J50W/kqBnUXJEyi9OkitPyELs9rPicyeQoXC+M/GGGQzt4ov3oFtbMgWkL3ChpuHXG\\r\\nDWNvkU3etIPW2cklLOsIetsQWHaykXjT093QLAzzBoTlLXevzVJ2AtqArlsth1c3s8UD0ZtyTEd7\\r\\nqjWYsbcr48204YpZ71bfy0tj/Juyvfng6omGKGrM5Krrw6Jty4k3qj+LfzUXutU0Jc82+YhjsjSL\\r\\niyrO87jI/oFjvL53HOMD/5Fj/vSd+Ay3/D33h5yC0fq/8xtQSwECCgAKAAAACAA6SntIEzP1+RAC\\r\\nAACrBgAALwAAAAAAAAAAAAAAAAAAAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5NTA0MDAh\\r\\nMTQ1OTAzNjc5OS54bWxQSwUGAAAAAAEAAQBdAAAAXQIAAAAA\\r\\n'),\n", + " b')'])" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_resp = mailbox.fetch(nums[0].split()[-1], '(BODY[1])')\n", + "all_resp" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('OK',\n", + " [b'169 (BODY (\"application\" \"zip\" (\"name\" \"google.com!njae.me.uk!1458950400!1459036799.zip\") NIL NIL \"base64\" 986))'])" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_resp = mailbox.fetch(nums[0].split()[-1], '(BODY)')\n", + "all_resp" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "54" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_resp[1][0][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(all_resp[1][0][1])" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "b'Return-Path: \\r\\nDelivered-To: dmarc@njae.me.uk\\r\\nReceived: from localhost (localhost [127.0.0.1])\\r\\n\\tby mail.njae.me.uk (Postfix) with ESMTP id 2A065106\\r\\n\\tfor ; Sun, 27 Mar 2016 10:28:09 +0100 (BST)\\r\\nX-Virus-Scanned: Debian amavisd-new at njae.me.uk\\r\\nAuthentication-Results: ogedei.njae.me.uk (amavisd-new);\\r\\n\\tdkim=pass (2048-bit key) header.d=google.com\\r\\nReceived: from mail.njae.me.uk ([127.0.0.1])\\r\\n\\tby localhost (ogedei.njae.me.uk [127.0.0.1]) (amavisd-new, port 10024)\\r\\n\\twith ESMTP id S06rrC9pLQlu for ;\\r\\n\\tSun, 27 Mar 2016 10:28:07 +0100 (BST)\\r\\nReceived-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.223.201; helo=mail-io0-f201.google.com; envelope-from=noreply-dmarc-support@google.com; receiver=dmarc@njae.me.uk \\r\\nAuthentication-Results: mail.njae.me.uk; dmarc=pass header.from=google.com\\r\\nAuthentication-Results: mail.njae.me.uk; dkim=pass\\r\\n\\treason=\"2048-bit key; unprotected key\"\\r\\n\\theader.d=google.com header.i=@google.com header.b=kRG+/uqj;\\r\\n\\tdkim-adsp=pass; dkim-atps=neutral\\r\\nReceived: from mail-io0-f201.google.com (mail-io0-f201.google.com [209.85.223.201])\\r\\n\\tby mail.njae.me.uk (Postfix) with ESMTPS id 36952EB\\r\\n\\tfor ; Sun, 27 Mar 2016 10:28:06 +0100 (BST)\\r\\nReceived: by mail-io0-f201.google.com with SMTP id 124so13927004iov.0\\r\\n for ; Sun, 27 Mar 2016 02:28:06 -0700 (PDT)\\r\\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\\r\\n d=google.com; s=20120113;\\r\\n h=mime-version:message-id:date:subject:from:to:content-disposition\\r\\n :content-transfer-encoding;\\r\\n bh=WebWWyH674VepKwkY7+3OEpaPDkuJsYet/WYzuiqEhc=;\\r\\n b=kRG+/uqjzLNy4IsueOq2bd1CW4i2x4dzf5Dg+soCJzKTycsrUudvIkphybOCPAE4aW\\r\\n 1ffplA6Tt9mxOpAfYppahUPeWFXtCE5AEf3/qorGxcv/yHv8S3TFiUqulTLccOyLbhoG\\r\\n P02OxDg38XWHLob7gOKUsqdCAmPfxqATsvakVN/SJkJswU4Fm8iBBaoca7wgW/A97eJs\\r\\n zKnmyWvpc1juUp5YLYWVGwL9927tbw8bO+0acz53Qgwj+QScqSftMNeLzKS3Ct11RkvX\\r\\n W49XblUJOHS+lbtVF6radeGKbsGp09QClMLAyLKEUeYTTgux/K0CIuB3A+BmQ1O3Souk\\r\\n cN7A==\\r\\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\\r\\n d=1e100.net; s=20130820;\\r\\n h=x-gm-message-state:mime-version:message-id:date:subject:from:to\\r\\n :content-disposition:content-transfer-encoding;\\r\\n bh=WebWWyH674VepKwkY7+3OEpaPDkuJsYet/WYzuiqEhc=;\\r\\n b=iy79Cfu0C9JtwPWMHnqS7hbVnFOcPMPttWMomjdh1ekeq+jxAg9335NteUoNg79PTo\\r\\n QSJbg9YAM4bvlFPOcPrSNQN+Q5fdopi1TuDBgHK7L0Rb9Vv8eKVRSG8pyLAw7Izs+y/H\\r\\n 9Rlh8qfOV3Te/pzQb+4eA+SS39D9O8L1Cmg2p19Y+XmNfX8xd/UhIKzXNNSbQODMOwnL\\r\\n xw0wmbMu/3wMgnUgJVfcp7BkZVhJzO7CqNfkGlv4BSpSGEH2+I0AwZFQgLfytwJ4j3nh\\r\\n oH217zO+us6vAE2gV3zneO4X3Pf88J7ma+I7Et6Bl2cM1TunPpisx6aqnzPdIMhJwMDt\\r\\n GM+w==\\r\\nX-Gm-Message-State: AD7BkJIXsS+d+n0kHSQlvoPQuXFYd9jWCwS846F7EdDD9cR1K1RkBPs0SrrYY9ARYXU/K7Bs7gdjAw==\\r\\nMIME-Version: 1.0\\r\\nX-Received: by 10.157.11.13 with SMTP id a13mr14086672ota.35.1459070885519;\\r\\n Sun, 27 Mar 2016 02:28:05 -0700 (PDT)\\r\\nMessage-ID: <2150510829392606201@google.com>\\r\\nDate: Sun, 27 Mar 2016 09:28:05 +0000\\r\\nSubject: Report domain: njae.me.uk Submitter: google.com Report-ID: 2150510829392606201\\r\\nFrom: noreply-dmarc-support@google.com\\r\\nTo: dmarc@njae.me.uk\\r\\nContent-Type: application/zip; \\r\\n\\tname=\"google.com!njae.me.uk!1458950400!1459036799.zip\"\\r\\nContent-Disposition: attachment; \\r\\n\\tfilename=\"google.com!njae.me.uk!1458950400!1459036799.zip\"\\r\\nContent-Transfer-Encoding: base64\\r\\n\\r\\nUEsDBAoAAAAIADpKe0gTM/X5EAIAAKsGAAAvAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5\\r\\nNTA0MDAhMTQ1OTAzNjc5OS54bWzVVU1vnDAQvedXoL0vBrJQqBynp/6C9oy8ZmDdBduyTZL99zVr\\r\\n85FNKkVVpKqnNW9m3swbP1j8+DL00RNow6V42KVxsotAMNlw0T3sfv74vi930SO5wy1Ac6TsTO6i\\r\\nCGtQUtt6AEsbaumEOVTqrhZ0ANJJ2fUQMzlgtIA+BwbKeyKkY+gv+2agmu3NqCa6b9synxdqXqym\\r\\nNZPCUmZrLlpJTtYq8xWhUBqvpYgiKswzaJQdiiIvE8f1tt4TBxm8IVmaJ3malFl1X2VFUmRJitEa\\r\\n9ulOKtSaii6IcdAROi5IesjLKk8OiWvmkTkOopmiVXJffKkqN4qYydBrtqXbdqdYyZ6zS63GY8/N\\r\\nCZZBpNuOIOIXhXiAeDw7Ng/5OG3OfCAaI38IoFHtFZt+PaTcRQjASIVnMwNmRhSzJJ1kTYfrmO+N\\r\\n5BbJpJ6n0/J50W/kqBnUXJEyi9OkitPyELs9rPicyeQoXC+M/GGGQzt4ov3oFtbMgWkL3ChpuHXG\\r\\nDWNvkU3etIPW2cklLOsIetsQWHaykXjT093QLAzzBoTlLXevzVJ2AtqArlsth1c3s8UD0ZtyTEd7\\r\\nqjWYsbcr48204YpZ71bfy0tj/Juyvfng6omGKGrM5Krrw6Jty4k3qj+LfzUXutU0Jc82+YhjsjSL\\r\\niyrO87jI/oFjvL53HOMD/5Fj/vSd+Ay3/D33h5yC0fq/8xtQSwECCgAKAAAACAA6SntIEzP1+RAC\\r\\nAACrBgAALwAAAAAAAAAAAAAAAAAAAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5NTA0MDAh\\r\\nMTQ1OTAzNjc5OS54bWxQSwUGAAAAAAEAAQBdAAAAXQIAAAAA\\r\\n'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "msg = mailbox.fetch(nums[0].split()[-1], '(RFC822)')[1][0][1]\n", + "msg" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pmsg = email.parser.BytesParser()\n", + "pmsg.parsebytes(msg)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pmsg = email.message_from_bytes(msg)\n", + "pmsg" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'application/zip'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pmsg.get_content_type()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'UEsDBAoAAAAIADpKe0gTM/X5EAIAAKsGAAAvAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5\\r\\nNTA0MDAhMTQ1OTAzNjc5OS54bWzVVU1vnDAQvedXoL0vBrJQqBynp/6C9oy8ZmDdBduyTZL99zVr\\r\\n85FNKkVVpKqnNW9m3swbP1j8+DL00RNow6V42KVxsotAMNlw0T3sfv74vi930SO5wy1Ac6TsTO6i\\r\\nCGtQUtt6AEsbaumEOVTqrhZ0ANJJ2fUQMzlgtIA+BwbKeyKkY+gv+2agmu3NqCa6b9synxdqXqym\\r\\nNZPCUmZrLlpJTtYq8xWhUBqvpYgiKswzaJQdiiIvE8f1tt4TBxm8IVmaJ3malFl1X2VFUmRJitEa\\r\\n9ulOKtSaii6IcdAROi5IesjLKk8OiWvmkTkOopmiVXJffKkqN4qYydBrtqXbdqdYyZ6zS63GY8/N\\r\\nCZZBpNuOIOIXhXiAeDw7Ng/5OG3OfCAaI38IoFHtFZt+PaTcRQjASIVnMwNmRhSzJJ1kTYfrmO+N\\r\\n5BbJpJ6n0/J50W/kqBnUXJEyi9OkitPyELs9rPicyeQoXC+M/GGGQzt4ov3oFtbMgWkL3ChpuHXG\\r\\nDWNvkU3etIPW2cklLOsIetsQWHaykXjT093QLAzzBoTlLXevzVJ2AtqArlsth1c3s8UD0ZtyTEd7\\r\\nqjWYsbcr48204YpZ71bfy0tj/Juyvfng6omGKGrM5Krrw6Jty4k3qj+LfzUXutU0Jc82+YhjsjSL\\r\\niyrO87jI/oFjvL53HOMD/5Fj/vSd+Ay3/D33h5yC0fq/8xtQSwECCgAKAAAACAA6SntIEzP1+RAC\\r\\nAACrBgAALwAAAAAAAAAAAAAAAAAAAAAAZ29vZ2xlLmNvbSFuamFlLm1lLnVrITE0NTg5NTA0MDAh\\r\\nMTQ1OTAzNjc5OS54bWxQSwUGAAAAAAEAAQBdAAAAXQIAAAAA\\r\\n'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pmsg.get_payload()" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "b'PK\\x03\\x04\\n\\x00\\x00\\x00\\x08\\x00:J{H\\x133\\xf5\\xf9\\x10\\x02\\x00\\x00\\xab\\x06\\x00\\x00/\\x00\\x00\\x00google.com!njae.me.uk!1458950400!1459036799.xml\\xd5UMo\\x9c0\\x10\\xbd\\xe7W\\xa0\\xbd/\\x06\\xb2P\\xa8\\x1c\\xa7\\xa7\\xfe\\x82\\xf6\\x8c\\xbcf`\\xdd\\x05\\xdb\\xb2M\\x92\\xfd\\xf75k\\xf3\\x91M*EU\\xa4\\xaa\\xa75of\\xde\\xcc\\x1b?X\\xfc\\xf82\\xf4\\xd1\\x13h\\xc3\\xa5x\\xd8\\xa5q\\xb2\\x8b@0\\xd9p\\xd1=\\xec~\\xfe\\xf8\\xbe/w\\xd1#\\xb9\\xc3-@s\\xa4\\xecL\\xee\\xa2\\x08kPR\\xdbz\\x00K\\x1bj\\xe9\\x849T\\xea\\xae\\x16t\\x00\\xd2I\\xd9\\xf5\\x1039`\\xb4\\x80>\\x07\\x06\\xca{\"\\xa4c\\xe8/\\xfbf\\xa0\\x9a\\xed\\xcd\\xa8&\\xbao\\xdb2\\x9f\\x17j^\\xac\\xa65\\x93\\xc2Rfk.ZIN\\xd6*\\xf3\\x15\\xa1P\\x1a\\xaf\\xa5\\x88\"*\\xcc3h\\x94\\x1d\\x8a\"/\\x13\\xc7\\xf5\\xb6\\xde\\x13\\x07\\x19\\xbc!Y\\x9a\\'y\\x9a\\x94Yu_eERdI\\x8a\\xd1\\x1a\\xf6\\xe9N*\\xd4\\x9a\\x8a.\\x88q\\xd0\\x11:.Hz\\xc8\\xcb*O\\x0e\\x89k\\xe6\\x919\\x0e\\xa2\\x99\\xa2Ur_|\\xa9*7\\x8a\\x98\\xc9\\xd0k\\xb6\\xa5\\xdbv\\xa7X\\xc9\\x9e\\xb3K\\xad\\xc6c\\xcf\\xcd\\t\\x96A\\xa4\\xdb\\x8e \\xe2\\x17\\x85x\\x80x<;6\\x0f\\xf98m\\xce| \\x1a#\\x7f\\x08\\xa0Q\\xed\\x15\\x9b~=\\xa4\\xdcE\\x08\\xc0H\\x85g3\\x03fF\\x14\\xb3$\\x9ddM\\x87\\xeb\\x98\\xef\\x8d\\xe4\\x16\\xc9\\xa4\\x9e\\xa7\\xd3\\xf2y\\xd1o\\xe4\\xa8\\x19\\xd4\\\\\\x912\\x8b\\xd3\\xa4\\x8a\\xd3\\xf2\\x10\\xbb=\\xac\\xf8\\x9c\\xc9\\xe4(\\\\/\\x8c\\xfca\\x86C;x\\xa2\\xfd\\xe8\\x16\\xd6\\xcc\\x81i\\x0b\\xdc(i\\xb8u\\xc6\\rco\\x91M\\xde\\xb4\\x83\\xd6\\xd9\\xc9%,\\xeb\\x08z\\xdb\\x10Xv\\xb2\\x91x\\xd3\\xd3\\xdd\\xd0,\\x0c\\xf3\\x06\\x84\\xe5-w\\xaf\\xcdRv\\x02\\xda\\x80\\xae[-\\x87W7\\xb3\\xc5\\x03\\xd1\\x9brLG{\\xaa5\\x98\\xb1\\xb7+\\xe3\\xcd\\xb4\\xe1\\x8aY\\xefV\\xdf\\xcbKc\\xfc\\x9b\\xb2\\xbd\\xf9\\xe0\\xea\\x89\\x86(j\\xcc\\xe4\\xaa\\xeb\\xc3\\xa2m\\xcb\\x897\\xaa?\\x8b\\x7f5\\x17\\xba\\xd54%\\xcf6\\xf9\\x88c\\xb24\\x8b\\x8b*\\xce\\xf3\\xb8\\xc8\\xfe\\x81c\\xbc\\xbew\\x1c\\xe3\\x03\\xff\\x91c\\xfe\\xf4\\x9d\\xf8\\x0c\\xb7\\xfc=\\xf7\\x87\\x9c\\x82\\xd1\\xfa\\xbf\\xf3\\x1bPK\\x01\\x02\\n\\x00\\n\\x00\\x00\\x00\\x08\\x00:J{H\\x133\\xf5\\xf9\\x10\\x02\\x00\\x00\\xab\\x06\\x00\\x00/\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00google.com!njae.me.uk!1458950400!1459036799.xmlPK\\x05\\x06\\x00\\x00\\x00\\x00\\x01\\x00\\x01\\x00]\\x00\\x00\\x00]\\x02\\x00\\x00\\x00\\x00'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pmsg.get_payload(decode=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# io.BytesIO(pmsg.get_payload(decode=True))\n", + "zfp = zipfile.ZipFile(io.BytesIO(pmsg.get_payload(decode=True)))" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'google.com!njae.me.uk!1458950400!1459036799.xml'" + ] + }, + "execution_count": 136, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "zfp.infolist()[0].filename" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def walk(node, indent=0):\n", + " for child in node:\n", + " print(' '*indent, child.tag, ':', child.text)\n", + " walk(child, indent+2)" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "zfp.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " report_metadata : \n", + " \n", + " org_name : google.com\n", + " email : noreply-dmarc-support@google.com\n", + " extra_contact_info : https://support.google.com/a/answer/2466580\n", + " report_id : 2150510829392606201\n", + " date_range : \n", + " \n", + " begin : 1458950400\n", + " end : 1459036799\n", + " policy_published : \n", + " \n", + " domain : njae.me.uk\n", + " adkim : r\n", + " aspf : r\n", + " p : none\n", + " sp : none\n", + " pct : 100\n", + " record : \n", + " \n", + " row : \n", + " \n", + " source_ip : 82.109.184.9\n", + " count : 1\n", + " policy_evaluated : \n", + " \n", + " disposition : none\n", + " dkim : fail\n", + " spf : fail\n", + " identifiers : \n", + " \n", + " header_from : njae.me.uk\n", + " auth_results : \n", + " \n", + " dkim : \n", + " \n", + " domain : clublloyds.com\n", + " result : pass\n", + " spf : \n", + " \n", + " domain : clublloyds.com\n", + " result : pass\n", + " record : \n", + " \n", + " row : \n", + " \n", + " source_ip : 212.69.55.62\n", + " count : 1\n", + " policy_evaluated : \n", + " \n", + " disposition : none\n", + " dkim : pass\n", + " spf : pass\n", + " identifiers : \n", + " \n", + " header_from : njae.me.uk\n", + " auth_results : \n", + " \n", + " dkim : \n", + " \n", + " domain : njae.me.uk\n", + " result : pass\n", + " spf : \n", + " \n", + " domain : njae.me.uk\n", + " result : pass\n" + ] + } + ], + "source": [ + "with zipfile.ZipFile(io.BytesIO(pmsg.get_payload(decode=True))) as zf:\n", + " fn = zf.infolist()[0].filename\n", + " contents = zf.read(fn).decode('utf-8')\n", + " root = xml.etree.ElementTree.fromstring(contents)\n", + " walk(root)" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "RuntimeError", + "evalue": "No active exception to reraise", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mRuntimeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mraise\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mRuntimeError\u001b[0m: No active exception to reraise" + ] + } + ], + "source": [ + "raise" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('OK', [b'Close completed.'])" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mailbox.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('BYE', [b'Logging out'])" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mailbox.logout()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.4.3+" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}