flanker
flanker copied to clipboard
Attachments from AppleMail client have no bodies
Flanker parses attachment's body from email as None:
In [19]: mail = open("/tmp/1.txt", "rb").read()
In [20]: mail
Out[20]: 'Delivered-To: [email protected]\nReceived: by 10.27.184.6 with SMTP id i6csp81852wlf;\n Wed, 9 Sep 2015 01:42:19 -0700 (PDT)\nX-Received: by 10.180.75.176 with SMTP id d16mr54538910wiw.75.1441788139160;\n Wed, 09 Sep 2015 01:42:19 -0700 (PDT)\nReturn-Path: <[email protected]>\nReceived: from mail-wi0-f180.google.com (mail-wi0-f180.google.com. [209.85.212.180])\n by mx.google.com with ESMTPS id kf6si11215377wjb.11.2015.09.09.01.42.19\n for <[email protected]>\n (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n Wed, 09 Sep 2015 01:42:19 -0700 (PDT)\nReceived-SPF: softfail (google.com: domain of transitioning [email protected] does not designate 209.85.212.180 as permitted sender) client-ip=209.85.212.180;\nAuthentication-Results: mx.google.com;\n spf=softfail (google.com: domain of transitioning [email protected] does not designate 209.85.212.180 as permitted sender) [email protected]\nReceived: by wiclk2 with SMTP id lk2so12858549wic.1\n for <[email protected]>; Wed, 09 Sep 2015 01:42:19 -0700 (PDT)\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20130820;\n h=x-gm-message-state:from:content-type:subject:message-id:date:to\n :mime-version;\n bh=iADgoaV1xyNMOvT6xlZQjOp+2r7wUfsTdfZA3wUI/eg=;\n b=H6GiBZGlEfhUxlw6ytg1vbcHiqXd69rOWl0z09HqH6ywhG8dSDXlFFVfe0rYKVZAjc\n bD0YAjmEAw1BjgRJUXMsVa4zS48+iRLSqRboeWBjnbxJAseUHesxCKzCOd0FTITxHAA6\n S9E3MwSqUv+zwK6ES7DV90X0hWvxVUyzzVSDtemBnV/rkWr7jlZ9uyAvnaK7dztiTZos\n lKwuz4+H0OvDw0LV1d1y/23rr0R6TMGqd8QmGnlVqyCTI8E6LQjoeHWaQ3b7tLJxHMtM\n d5NIhqkRAl58aVSSTSAbKOEiAUqgBq98ZJpz4q5Nw3stPdu1btF/uDxyLUyaQmoTU8nr\n vIUA==\nX-Gm-Message-State: ALoCoQmaqZjZegl0KF6Y/see4tzw8O/hXN1+vW7W0waIfhTff9DYQa3y+iMBYjCE6XlOJAsq2d1U\nX-Received: by 10.180.230.197 with SMTP id ta5mr31843529wic.26.1441788138945;\n Wed, 09 Sep 2015 01:42:18 -0700 (PDT)\nReturn-Path: <[email protected]>\nReceived: from [192.168.1.9] (215-81-133-95.pool.ukrtel.net. [95.133.81.215])\n by smtp.gmail.com with ESMTPSA id fn8sm2658059wib.2.2015.09.09.01.42.18\n for <[email protected]>\n (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);\n Wed, 09 Sep 2015 01:42:18 -0700 (PDT)\nFrom: Michael Korbakov <[email protected]>\nContent-Type: multipart/mixed; boundary="Apple-Mail=_C9C2B061-E965-4274-A8D2-0CAAB92A2F17"\nSubject: =?utf-8?Q?Fwd=3A_=D1=82=D0=B5=D1=81=D1=82_ApplMail?=\nMessage-Id: <[email protected]>\nDate: Wed, 9 Sep 2015 11:42:16 +0300\nTo: Anton Koval <[email protected]>\nMime-Version: 1.0 (Mac OS X Mail 8.2 \\(2104\\))\nX-Mailer: Apple Mail (2.2104)\n\n\n--Apple-Mail=_C9C2B061-E965-4274-A8D2-0CAAB92A2F17\nContent-Transfer-Encoding: base64\nContent-Type: text/plain;\n\tcharset=utf-8\n\n0KLQtdGB0YINCg==\n--Apple-Mail=_C9C2B061-E965-4274-A8D2-0CAAB92A2F17\nContent-Disposition: attachment;\n\tfilename*=utf-8\'\'%D1%82%D0%B5%D1%81%D1%82%20ApplMail.eml\nContent-Type: message/rfc822;\n\tx-mac-hide-extension=yes;\n\tname="=?utf-8?Q?=D1=82=D0=B5=D1=81=D1=82_ApplMail=2Eeml?="\nContent-Transfer-Encoding: 7bit\n\nDelivered-To: [email protected]\nReceived: by 10.27.173.129 with SMTP id w123csp81617wle;\n Wed, 9 Sep 2015 01:38:33 -0700 (PDT)\nX-Received: by 10.180.101.164 with SMTP id fh4mr54549269wib.25.1441787913118;\n Wed, 09 Sep 2015 01:38:33 -0700 (PDT)\nReturn-Path: <[email protected]>\nReceived: from mail-wi0-f172.google.com (mail-wi0-f172.google.com. [209.85.212.172])\n by mx.google.com with ESMTPS id l20si11145816wjw.125.2015.09.09.01.38.33\n for <[email protected]>\n (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n Wed, 09 Sep 2015 01:38:33 -0700 (PDT)\nReceived-SPF: softfail (google.com: domain of transitioning [email protected] does not designate 209.85.212.172 as permitted sender) client-ip=209.85.212.172;\nAuthentication-Results: mx.google.com;\n spf=softfail (google.com: domain of transitioning [email protected] does not designate 209.85.212.172 as permitted sender) [email protected]\nReceived: by wicfx3 with SMTP id fx3so12722933wic.0\n for <[email protected]>; Wed, 09 Sep 2015 01:38:33 -0700 (PDT)\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20130820;\n h=x-gm-message-state:mime-version:date:message-id:subject:from:to\n :content-type;\n bh=yCsUOUoICXWy85xw3Vv9Q1aD4vzogMR3DYZ0+y+X65w=;\n b=jIoY2gfVjfrjya69jmfc3W/2p108e3c1+3TDCbKQNAgT2B1BQfEtvZqWXHXcij4NbK\n YCyiva/EJ3CBFQ9C0B4j+fiKUCi5DLTkUXF6E9W6INNM5HFdQJiIpWqi/kHdI7gtBN2G\n 6WlrcVm1NHvAvESVh7j65iDcmdimNDC/zjrUFb0nCkpvmldmhP0dJGTJ0K8t1Ho/3RhH\n 6P2idxr+HpR1RbEaV5+0ehUmiEiVZinaEyGUuT8fcLnsz/ztCy6LueNIyT+jmNbvz1HH\n /R5/lIykXTI40Q5FUz5vuLxx09u1s4f7JPvAWISnzmQTm51NIesZQ65F94twSce8wLtC\n A7sA==\nX-Gm-Message-State: ALoCoQmKzyo22NkyAdTk4HymZiAf2dqGE2bdsk3Drc+uloOqVIX4tuICf8KIgMN5JuNsFIQbZlFn\nMIME-Version: 1.0\nX-Received: by 10.194.201.71 with SMTP id jy7mr56686474wjc.93.1441787912788;\n Wed, 09 Sep 2015 01:38:32 -0700 (PDT)\nReceived: by 10.27.176.135 with HTTP; Wed, 9 Sep 2015 01:38:32 -0700 (PDT)\nDate: Wed, 9 Sep 2015 11:38:32 +0300\nMessage-ID: <CABxjYs9Kk=4OnT6uYrR5=kiQ3H+yGw9XNcu_JaJvwRDU_U5GSA@mail.gmail.com>\nSubject: =?UTF-8?B?0YLQtdGB0YIgQXBwbE1haWw=?=\nFrom: Anton Koval <[email protected]>\nTo: Michael Korbakov <[email protected]>\nContent-Type: multipart/alternative; boundary=047d7bae4944623830051f4c6811\n\n--047d7bae4944623830051f4c6811\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: base64\n\n0JAg0YHQtNC10LvQsNC5INGA0LXQv9C70LDQuSDQvdCwINGN0YLQviDQv9C40YHRjNC80L4g0YfQ\ntdGA0LXQtyDRjdC/0L/Qu9C+INC60LvQuNC10L3Rgi4NCg==\n--047d7bae4944623830051f4c6811\nContent-Type: text/html; charset=UTF-8\nContent-Transfer-Encoding: base64\n\nPGRpdiBkaXI9Imx0ciI+0JAg0YHQtNC10LvQsNC5INGA0LXQv9C70LDQuSDQvdCwINGN0YLQviDQ\nv9C40YHRjNC80L4g0YfQtdGA0LXQtyDRjdC/0L/Qu9C+INC60LvQuNC10L3Rgi48YnI+PC9kaXY+\nDQo=\n--047d7bae4944623830051f4c6811--\n\n--Apple-Mail=_C9C2B061-E965-4274-A8D2-0CAAB92A2F17--'
In [21]: msg = mime.from_string(mail)
In [23]: parts = [p for p in msg.walk(with_self=True)]
In [24]: parts
Out[24]:
[<flanker.mime.message.part.MimePart at 0x10bfa7d50>,
<flanker.mime.message.part.MimePart at 0x10bfa7ad0>,
<flanker.mime.message.part.MimePart at 0x10bfa7cd0>,
<flanker.mime.message.part.MimePart at 0x10bfa7c50>,
<flanker.mime.message.part.MimePart at 0x10bfa7b50>,
<flanker.mime.message.part.MimePart at 0x10bfa7bd0>]
In [25]: [(p.is_attachment(), p) for p in parts]
Out[25]:
[(False, <flanker.mime.message.part.MimePart at 0x10bfa7d50>),
(False, <flanker.mime.message.part.MimePart at 0x10bfa7ad0>),
(True, <flanker.mime.message.part.MimePart at 0x10bfa7cd0>),
(False, <flanker.mime.message.part.MimePart at 0x10bfa7c50>),
(False, <flanker.mime.message.part.MimePart at 0x10bfa7b50>),
(False, <flanker.mime.message.part.MimePart at 0x10bfa7bd0>)]
In [26]: attach = parts[2]
In [27]: attach.dete
attach.detected_content_type attach.detected_file_name attach.detected_format attach.detected_subtype
In [27]: attach.detected_file_name
Out[27]: u'\u0442\u0435\u0441\u0442 ApplMail.eml'
In [28]: attach.body is None
Out[28]: True
However:
In [29]: p_attach = attach.to_python_message()
In [32]: p_attach.get_payload()[0].as_string()
Out[32]: 'Delivered-To: [email protected]\nReceived: by 10.27.173.129 with SMTP id w123csp81617wle;\n Wed, 9 Sep 2015 01:38:33 -0700 (PDT)\nX-Received: by 10.180.101.164 with SMTP id fh4mr54549269wib.25.1441787913118; \n Wed, 09 Sep 2015 01:38:33 -0700 (PDT)\nReturn-Path: <[email protected]>\nReceived: from mail-wi0-f172.google.com (mail-wi0-f172.google.com.\n [209.85.212.172])\n by mx.google.com with ESMTPS id l20si11145816wjw.125.2015.09.09.01.38.33\n for <[email protected]>\n (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n Wed, 09 Sep 2015 01:38:33 -0700 (PDT)\nReceived-SPF: softfail (google.com: domain of transitioning [email protected]\n does not designate 209.85.212.172 as permitted sender)\n client-ip=209.85.212.172; \nAuthentication-Results: mx.google.com;\n spf=softfail (google.com: domain of transitioning [email protected] does not\n designate 209.85.212.172 as permitted sender) [email protected]\nReceived: by wicfx3 with SMTP id fx3so12722933wic.0\n for <[email protected]>; Wed, 09 Sep 2015 01:38:33 -0700 (PDT)\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20130820;\n h=x-gm-message-state:mime-version:date:message-id:subject:from:to\n :content-type;\n bh=yCsUOUoICXWy85xw3Vv9Q1aD4vzogMR3DYZ0+y+X65w=;\n b=jIoY2gfVjfrjya69jmfc3W/2p108e3c1+3TDCbKQNAgT2B1BQfEtvZqWXHXcij4NbK\n YCyiva/EJ3CBFQ9C0B4j+fiKUCi5DLTkUXF6E9W6INNM5HFdQJiIpWqi/kHdI7gtBN2G\n 6WlrcVm1NHvAvESVh7j65iDcmdimNDC/zjrUFb0nCkpvmldmhP0dJGTJ0K8t1Ho/3RhH\n 6P2idxr+HpR1RbEaV5+0ehUmiEiVZinaEyGUuT8fcLnsz/ztCy6LueNIyT+jmNbvz1HH\n /R5/lIykXTI40Q5FUz5vuLxx09u1s4f7JPvAWISnzmQTm51NIesZQ65F94twSce8wLtC\n A7sA==\nX-Gm-Message-State: ALoCoQmKzyo22NkyAdTk4HymZiAf2dqGE2bdsk3Drc+uloOqVIX4tuICf8KIgMN5JuNsFIQbZlFn\nMIME-Version: 1.0\nX-Received: by 10.194.201.71 with SMTP id jy7mr56686474wjc.93.1441787912788;\n Wed, 09 Sep 2015 01:38:32 -0700 (PDT)\nReceived: by 10.27.176.135 with HTTP; Wed, 9 Sep 2015 01:38:32 -0700 (PDT)\nDate: Wed, 9 Sep 2015 11:38:32 +0300\nMessage-ID: <CABxjYs9Kk=4OnT6uYrR5=kiQ3H+yGw9XNcu_JaJvwRDU_U5GSA@mail.gmail.com>\nSubject: =?UTF-8?B?0YLQtdGB0YIgQXBwbE1haWw=?=\nFrom: Anton Koval <[email protected]>\nTo: Michael Korbakov <[email protected]>\nContent-Type: multipart/alternative; boundary=047d7bae4944623830051f4c6811\n\n--047d7bae4944623830051f4c6811\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: base64\n\n0JAg0YHQtNC10LvQsNC5INGA0LXQv9C70LDQuSDQvdCwINGN0YLQviDQv9C40YHRjNC80L4g0YfQ\ntdGA0LXQtyDRjdC/0L/Qu9C+INC60LvQuNC10L3Rgi4NCg==\n--047d7bae4944623830051f4c6811\nContent-Type: text/html; charset=UTF-8\nContent-Transfer-Encoding: base64\n\nPGRpdiBkaXI9Imx0ciI+0JAg0YHQtNC10LvQsNC5INGA0LXQv9C70LDQuSDQvdCwINGN0YLQviDQ\nv9C40YHRjNC80L4g0YfQtdGA0LXQtyDRjdC/0L/Qu9C+INC60LvQuNC10L3Rgi48YnI+PC9kaXY+\nDQo=\n--047d7bae4944623830051f4c6811--\n'
Maybe I'm trying to get attachment's body in a wrong way?