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." <[email protected]>
To: Mike Young <[email protected]>
Message-ID: <[email protected]>
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, 2012 at 20:47
  • Updated the question with the email. Mar 6, 2012 at 20:52
  • It decodes fine for me. Run file x.pdf and see what it says the file is.
    – Kevin
    Mar 6, 2012 at 21:01
  • Seems to be a valid PDF file, but I can't seem to view it with anything. Mar 6, 2012 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, 2012 at 4:32

1 Answer 1


munpack seems like the tool you want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .