Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"

share|improve this question
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. – Naftuli Tzvi Kay 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. – Naftuli Tzvi Kay Mar 6 '12 at 21:26
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 – Frederik Deweerdt Mar 8 '12 at 4:32
up vote 1 down vote accepted

munpack seems like the tool you want.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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