I have an email stored in plaintext (yes, headers, messages, attachments, everything in one plaintext file) and I'd like to extract a PDF document from it. I've copied the base64-encoded text, then ran it through base64 -d and catted it to a file. I then tried opening it up, which didn't work, and it doesn't appear like a PDF file.

Is there something I'm doing wrong here? I'm fairly certain that it is, indeed, encoded in base64 and that it's a PDF file.

Here is the email:

---------- MESSAGE FOLLOWS ----------
Date: Tue, 6 Mar 2012 12:24:24 -0800 (PST)
From: "Outer, Inc." <admin@outer.com>
To: Mike Young <inner@outer.org>
Message-ID: <169371530.01331065464959.JavaMail.admin@outer.com>
Subject: Your results are in, Mike!
MIME-Version: 1.0
Content-Type: multipart/mixed; 

Content-Type: multipart/alternative; 

Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Great job, Mike on your baby!
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

        <h3>Great job, Mike on your baby!</h3>

Content-Type: application/pdf; name="Baby Results.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Baby Results.pdf"

  • 1
    Does it look like plain text? What does file say about it?
    – Kevin
    Mar 6 '12 at 20:47
  • Updated the question with the email. Mar 6 '12 at 20:52
  • It decodes fine for me. Run file x.pdf and see what it says the file is.
    – Kevin
    Mar 6 '12 at 21:01
  • Seems to be a valid PDF file, but I can't seem to view it with anything. Mar 6 '12 at 21:26
  • 1
    If i decode the beginning of your base64 encoded attachment, I get: %PDF-1.4......, so that looks like a legit PDF file. In the other hand, if I decode the end, I don't see '%%EOF' which would mark the end of a legit PDF file. It seems that your attachment is truncated Mar 8 '12 at 4:32

munpack seems like the tool you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.