Decode email

In pine email, when you receive an email with an attachment, the content of the attachment is incoded (content-transfer-encoding: base64). I am trying to write a shell script that will read the mail file, and it will save the attachment of an email to a directory.

I want to do this by reading mail file, save the content of the attachment into a variable, and saving that content in a directory with the same file name that it had, which is also specified in the mail file. I'm trying to figure out how I can decode the attachment in my shell script so that I can save the unencoded content of the file, rather than the hex code that is shown in the mail spool file.

Any ideas? Thanks for the help.

pulled out incorrect information

uudecode isn't going to decode MIME base64 encoded attachments.

Do a google search for base64. There are a bazillion utilities that will decode MIME attachments.

Thomas

It's not that simple. uuencode is different than base64. This would be very rough from a shell script because shell scripts can't write binary data very easily. I wrote a binary file to base64 encoder in ksh once but it ran too slow. This will really need a external c program to handle the base 64 stuff.

Agreed. A c program is really the only way to do the decoding. There are base64 encoder and decoders available freely and, at least the one that I used many years ago, can find where the encoding begins and begin the decoding process regardless of any message text preceeding the attachment.

Thomas

Thanks for the info. I will continue to look for a base64 decoder. I found one, but when I try to run the windows version of it, I just get a blank command prompt. When I try to configure the unix version in my unix account at school, I get a message saying permission denied, so I will need to find out how I can get the permissions to run the file that configures the decoding system. :confused:

Thanks for the pointers.

I found a perfect solution, just in case anyone needs it in the future. It is a free program called UUDeview. There is both a windows version and a Unix version available for download at UUDeview Home Page (I hope I'm allowed to post a link on here, if not....forgive me). It gives you exact instructions on how to install it into Unix. To decode attachments of an email, you simply type the command and the file to be decoded (i.e. the mail spool file). The program will extract and decode all of the attachments, and save them to your directory with the same name as they were sent, Works like a charm!

Not only does it encode files encoded in base64, but it also decodes files encoded in BinHex, uuencoding, and xxencoding. The only setback is that when you send an attachment from yahoo, hotmail, etc, if the attachment is a regular text file or .cpp file, .java, etc, the files are not encoded, so the program does not extract these files because they are not encoded, but I will get around this by simply writing a script to extract the text files myself, and let the program do the rest.

Just figured I would put this info here just in case someone needs it in the future, which is probably very unlikely! :cool:

1 Like