16

How can I extract attachments from an email when they arrive encoded in the body of the email like this:

------ =_NEXTPART_FORMSCAPE_MAIL_message101122101615
Content-Type: application/octet-stream; name="MyFile_hasalongish
     filename_22-NOV-2010.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="MyFile_hasalongishfilename_22-NOV-2010.pdf"
Content-Description: MyFile_hasalongishfilename_22-NOV-2010.pdf

JVBEDi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0
ZFRGVSdsfSDF43N0cmVhbQp4nJ0b23IVN/LdXzG1D7vnbOUMo9tISiWpBduAN2CMbZJN
[...]
OUIwOEYxRDcyRjkwRDAxRUU1QzBDMjhEM0Y+XQo+PgpzdGFydHhyZWYKMTMwNDQKJSVF
T0YK
------ =_NEXTPART_FORMSCAPE_MAIL_message101122101615--
DrStalker
  • 391
  • 3
  • 4
  • 12

3 Answers3

21

Copy only the base64 encoded text into a new text file foo.txt.

base64 --decode foo.txt > bar.pdf

I just decoded a base64 stream that had an extra bit on the end that I had to remove. It looked like this: --=_59494bda030d4629113a60ff13935d81--. Before I removed it I got the error: Invalid character in input stream. After I deleted it, no decoding errors and it opened just fine.

Simon Woodside
  • 451
  • 4
  • 11
4

Save the email to a text file with the extension .uue and extract the attachment with a de-archiver.

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
Rob Kam
  • 1,856
  • 2
  • 20
  • 29
1

I was able to recover the file using a base64 decoder and copying only the actual text that was the encoded attachment, not any of the surrounding header/footer stuff.

DrStalker
  • 391
  • 3
  • 4
  • 12