Email Attachments

UCLA Mathematics Consulting Group


Extracting attachments from UNIX email.

Extracting attachments from UNIX email.

For some time now, Mac and PC users have merrily been attaching files and documents to their outgoing E-Mail. While this can be a convenient way to exchange information, it presents a problem for UNIX users. Many times, the file attachments show up as "garbage" under UNIX.

The crux of the problem is that newer PC/Mac mail programs incorporate a Standard called MIME (Multi-purpose Internet Mail Extensions). MIME lets people send files, pictures, sounds and data to others via E-Mail. When a person attaches something to an E-Mail message in MIME format, the program converts the file/document to ASCII, and then attaches it to the outgoing E-Mail. When the E-Mail is read at the destination (using a MIME reader), the attachment will be transferred too.

If you read your mail under UNIX, and you see in a mail message lines that Look like this:

    --Boundary_[ID_Zfq4R6Qp1pYJ4D+aegsXwg]
    Content-id: <Pine.PMDF.3.95.980528115230.539056915C@ONLINE.EMICH.EDU>
    Content-type: TEXT/PLAIN; CHARSET=ISO-8859-1
    Content-transfer-encoding: QUOTED-PRINTABLE
then the message has a MIME attachment.

Reading these attachments can be a little tricky sometimes, but the general procedure is as follows:

  1. Extract the message to a file
  2. Unpack the MIME attachment
  3. Transfer the attachment to a PC/Mac to use it
Here's a little more detail:
  1. If you read your mail with the standard UNIX 'mail' command, you can usually save your message to a file by typing the command:
    s filename
    In elm, the similar command is:
    s ~/filename
    In pine, the command would be:
    E filename
  2. To unpack the data (if you can), all you need to do is quit your mail program and type the following at the shell prompt:
    munpack filename
    Usually, the munpack command will return the name of the file which was extracted, like "file.doc", "picture.gif", or "info.txt". There may be more than one file extracted. Be sure and note the names.

    Sometimes, an incoming message is mangled a bit because it was forwarded or mishandled somewhere in the delivery path. If you run into a message like this, you can try to fix it yourself, or you can get someone at the Consulting Desk to help you.

    If you do opt to try to fix it yourself, here are a couple tips:
    • The most common problem is prepended text. To fix it, edit the message and remove the characters "> " from the start of each line. Then run munpack again.
    • Occasionally, there will be several levels of tabs, ">" characters, and spaces. If this is the case, you'll probably need to use the regular expressions features in your editor. This is as much art as science.

  3. Once you've extracted the MIME file(s), you'll want to upload them to an NT system. You can use a standard FTP session to do this. Be sure to specify the "bin" option before running a "put" or "get" command so that the binary format of the file will be preserved. Once you've transferred the file, you should be able just to double click on it to fire it up.