This may be a fairly uncommon situation, but have you ever needed to recover
an attachment from a deleted email? I had accidentally deleted an email
containing an excel spreadsheet that I still needed. For reasons I won’t go
into here, the only copy of the email I had was a ‘raw’ text file of the
email. rather than mess around with trying to get Mail.app to recognize it as
an email, I decided to try and recover the base64-encoded excel file from the
email.
First off, copy the base64-encoded version of the spreadsheet to a seperate
file. It will be very long and look something like this:
Next open up a pry (or irb) console in the directory holding the file you
just created.
We’ll be using Ruby’s Base64 utility, so
Then we want to open the file we created:
And write the unencoded version of it to a new file (the ‘w’ is for write mode, ‘b’ is for binary):
and voila! you know have an open-able excel file! 1
I had to open the file with OpenOffice, Excel complained that the file was un-openable. ↩