Decoding of payload of attachment
See original GitHub issueHello,
I am have following code in my project:
decoder_map = {'base64': lambda payload: base64.b64decode(payload),
'': lambda payload: payload.encode('utf-8'),
'7bit': lambda payload: payload.encode('utf-8'),
'quoted-printable': lambda payload: quopri.decodestring(payload)}
for msg_id in data[0].decode('utf-8').split():
result_fetch, data = client.fetch(msg_id, "(RFC822)")
if result_fetch != 'OK':
raise Exception("Fetch failed!")
raw_mail = data[0][1]
mail = mailparser.parse_from_bytes(raw_mail)
for attachment in mail.attachments:
if attachment['content_transfer_encoding'] not in decoder_map:
msg = "Unsupported Content-Transfer Encoding ({}) in msg {}.".format(attachment['content_transfer_encoding'], msg_id)
raise RuntimeError(msg)
decoder = decoder_map[attachment['content_transfer_encoding']]
try:
fp, fname = find_filename(attachment['filename'], args.attachment_dir)
fp.write(decoder(attachment['payload']))
except binascii.Error as e:
print("Unable to parse attachment '{}'".format(attachment['filename']))
finally:
fp.close()
I think that this is not a fully-handled case of use. I had to introduce quite a lot of logic to save attachments that can be coded in a variety of ways.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Parsing or decoding .pluginPayloadAttachment files?
pluginPayloadAttachment " extension. I have no idea how to parse these. Running them through xxd reveals some indecipherable binary/hex, except ...
Read more >Decryption of Business Chat Attach…
Here an example how you can access the encoded attachment data by calling the /preDownload endpoint, decode the attachment payload and process it....
Read more >JSON Payload-Attachment as Byte format-How to Scan
Hi, If we have scenario where the attachment is sent as byte format inside JSON Payload and need to scan for content inside...
Read more >Decoding from base64 an xml attachment from a multipart ...
This article explains how the decoding from base64 should be done for an xml attachment received in a multipart response (from a SOAP...
Read more >python - Need help decoding a WAV file email attachment
I tried to decode using 'base64' or the "encoding property in the payload" but I keep getting this error: "UnicodeDecodeError: 'utf8' codec ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I added the
store attachments
function inmail-parser
command line:Hi @ad-m,
in
mail-parser
results there is abinary
flag. If it’strue
the sample is a binary, else it’sfalse
is not binary. If you read this part of code you can see:mail-parser
gives you the correct payload, so you should do:That’s it