Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode an email attachment received as a Base64 text

I have an email backup file which is purely text. How can I retrieve the document (PDF, images, word files) attached to it as a normal file?

like image 367
13thOlympian Avatar asked Oct 13 '14 10:10

13thOlympian


People also ask

How do I decode a file with Base64?

To decode a file with contents that are base64 encoded, you simply provide the path of the file with the --decode flag. As with encoding files, the output will be a very long string of the original file. You may want to output stdout directly to a file.

How do I decode an email attachment?

First, save the whole message as a text file onto your desktop. Then open the text file with a decompression utility like WinZip or Stuffit. Sometimes the utility will recognize the file as a compressed file, and decode the file for you into the original attachment.

Can Base64 encoding be decoded?

In JavaScript there are two functions respectively for decoding and encoding Base64 strings: btoa() : creates a Base64-encoded ASCII string from a "string" of binary data ("btoa" should be read as "binary to ASCII"). atob() : decodes a Base64-encoded string ("atob" should be read as "ASCII to binary").


1 Answers

  1. Select the long string of text which appears in your email. That is probably one of the attachments, it usually starts like this:

    --bcaec554d754b0f76a04d9fda578--
    --bcaec554d754b0f77204d9fda57a
    Content-Type: application/pdf; name="test.pdf"
    Content-Disposition: attachment; filename="Otest.pdf"
    Content-Transfer-Encoding: base64
    X-Attachment-Id: 9ba6310dffca527f_0.1
    
  2. Copy this long string and paste it in the Base64 decoder found here.

  3. Download the output and rename it by adding the appropriate extension to it. For example testfile.pdf or filename.docx.

There you go. You just recreated your lost attachment using Base64 decoding.

like image 80
13thOlympian Avatar answered Nov 08 '22 16:11

13thOlympian