Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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; 
    boundary="----=_Part_0_1998493940.1331065464916"
X-Peer: 127.0.0.1

------=_Part_0_1998493940.1331065464916
Content-Type: multipart/alternative; 
    boundary="----=_Part_1_1254200493.1331065464936"

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

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

<html>
    <body>
        <h3>Great job, Mike on your baby!</h3>
    </body>
</html>
------=_Part_1_1254200493.1331065464936--

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

JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9UeXBlL1hPYmplY3QvQ29sb3JTcGFjZS9EZXZpY2VH
cmF5L1N1YnR5cGUvSW1hZ2UvQml0c1BlckNvbXBvbmVudCA4L1dpZHRoIDI1My9MZW5ndGggMTYx
...
HR5P9F0eg4+P8tWzo2bPl6eGcNwyLqqW+chQi7Fo/CTWPUI7Kud1ZYgpcnSg7do4SKpTy10jyggP
1dVbvqS63pYxNl1JGGcvD1P+VFdN2b7O3YBqXTuiRteun3nmUdcoObmr5qduv09
share|improve this question
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. –  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
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 –  Frederik Deweerdt Mar 8 '12 at 4:32
show 4 more comments

1 Answer 1

up vote 1 down vote accepted

munpack seems like the tool you want.

share|improve this answer
add comment

Your Answer

 
discard

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.