Binary files and Email

While certain mail programs have methods of "attaching" "binary" files, the Internet's underlying mail software isn't designed to handle anything but plain text. That means you often have to take special steps to send anything other than simple text. This help page explains what programs can be used to "encode" and files, or "decode" files that were sent to you, and gives examples of use with various mail software and encoding software.

Binary files in email: Subtopics

Introduction: Why is it so complicated

The software that transports email is only designed to handle readable text, or "ASCII." Internet messages can contain only alphabetic characters, numbers, and punctuation. And the alphabet is limited to the U.S. alphabet. Files created by the most programs, even word processors, contain non-ASCII data, and require special handling to be mailed. For example, image files, database files, and executable files can not be sent directly through email. So, to send these files and preserve their native format, the sender converts the file to an all-ASCII representation, and the recipient uses corresponding "decoding" software to translate that ASCII representation back to the orignal file. Generally speaking, it is easy to encode and mail such files, but more difficult to decode them when you receive them in email.

Most word processors allow you to export to a "generic text" or "ASCII" format, and this remains the "normal" way to send messages you prepare with a word processor. If you're willing to convert the file to ASCII, you don't have to worry about any of the issues here, and neither does the recipient of your mail. However, you do lose bolding, tables, footnotes, etc. if you take this tack.

Overview: What are binary files? What is encoding?

What are binary files?

Short answer: A "binary" file is anything that isn't an ASCII file, and an ASCII file is a file with nothing but letters, numbers, punctuation, etc. (No font specifications, bolding, or other attributes). Spreadsheet files, database files, images, and, perhaps not so intuitively, word processor files (or documents), are all binary files. In fact, unless you're a programmer, probably every file you deal with on your computer is a binary file. Non-binary files are created by programs known as "text editors"; the "edit" program that comes with DOS is a good example.

Longer Answer: "Binary" is a misleading term. All computer files are composed of binary data -- as everyone's grandmother knows, computers store information as ones and zeros -- and that must be the etymology of "binary". In a computer, ones and zeros are organized into groups (usually of 8) called "bytes" (each 1 or 0 is a "bit"). There is a standard, called ASCII, which defines a correspondence between, on the one hand, certain patterns of ones zeros and, on the other hand, alphanumeric characters and miscellaneous symbols conveniently recognizable by humans. One ASCII-defined pattern corresponds to a capital "C", another to the character "=", etc. Those patterns which correspond to the characters you can type on a keyboard and see appear on your screen are called the ASCII character set (actually, there are a few other characters in ASCII, but they don't concern us.) Certain applications, including many Internet mail programs, restrict the data they use to characters in this set of 100 or so patterns. ASCII is the lingua franca of modern computers: anyone you want to send mail to, and anyone who wants to send mail to you, can probably read and write ASCII letters.

So-called "binary" files, on the other hand, are composed of any bytes the programmer finds convenient. There are 256 possible arrangements of ones and zeros in an eight bit byte; the ASCII set uses only half of them.) Non-ascii characters can be used to create certain formatting (tables, footnotes, special fonts or faces), or to store numeric data in spreadsheets, or to represent colors and coordinates in a picture, etc. Even the text in a word processing document need not be stored in ASCII format, though as it happens, it usually is. But if a program decides that the byte that corresponds to "I" in ASCII should mean "Coordinates of circle follow", the computer doesn't care. As long as a program that understands the data reads the files the program writes, all will be fine.

It's the convention, stupid -Mayor Daley, 1968

ASCII itself is just one such arbitrary relation between bytes and meanings; it happens to be a very widely used and very simple arbitrary relation, one that just about all mail programs on the 'net understand and display without complication.

What is encoding?

So you want to send a "binary" file. There are several programs which can encode any file into an all-ASCII representation. The recipient will have to run the encoded file through a corresponding decoding program when she receives it, and which software she has available what determines which method you use encode the file.

"Encoding" files to mail them has no relation to enoding data for security reasons.

MIME and uuencode are the two most common of the various encoding schemes. binhex is a similar standard, primarily used in the Macintosh community. btoa is yet another standard; it is very rare and not documented in our Help system, see:

	world% man btoa

MIME is the emerging standard. Pine and Elm, and most Windows mail programs, understand MIME. binhex is mostly associated with the Macintosh freeware Eudora version. uuencode is widely available on UNIX computers, so students will normally have access to that.

How to mail a binary file

If you use mail software installed on The World, the very first step is to upload the file to World. How to do so is described in a separate help file, which you can see by clicking or hitting <enter> here.

Instructions for mailing binary files, by software

Mailing a binary file with pine
Pine has direct support for sending MIME files, using the attachment feature. All attachments are MIME encoded. If it's easier for your recipient, you can also send uuencoded files by encoding them with the program uuencode and inserting the uuencoded data into your message.
Using pine to send MIME-encoded messages
Sending uuencoded messages with pine
Mailing a binary file with Eudora

Different versions of Eudora use different encoding methods. Eudora can not read external files, so you're stuck with what your version supports.

Freeware Macintosh Eudora

The current freeware version supports three types of encoding; Binhex, Apple I, and Apple II. Apple II, apparently a MIME variant, is the best attachment method to use if you're sending to someone who doesn't have a mac; Eudora's manual says that binhex is the best to use if your recipient does have a mac. If this is a feature you need often, consider converting to the commercial version

  1. Begin a new message as usual
  2. Under the "Message" menu, choose "Attach document"
  3. Use the familiar disk navigation tool to find your file; when it is selected, hit open.
  4. You may attach multiple files but there is no "Shift-Select", you must go through the steps above for each of them.
Commercial Windows Version

This version allows you to choose between binhex, MIME, and uuencode. Find out from your recipient which she prefers..

Sending uuencoded mail from the UNIX shell

You can also just dump the uuencoded file into mail, with no text in the message. This might sound rude, but if you first send a regular message saying something like: "I'm about to send you quarter3.wks, uuencoded", it might in fact be the most convenient way for them to deal with it. Here's the command to mail "quarter3.wks" to firstlady@whitehouse.gov:
world% uuencode quarter3.wks quarter3.wks | mail firstlady@whitehouse.gov

The first "quarter3.wks" is the name of the binary file that you want to deliver. The second name is the name of the binary file to be created when the person uudecodes it on the other end. These two names are normally the same. But if the second name is different, that's the file name your recipient will end up with she decodes it.

How to decode a binary file you receive

Some mail software can recognize and decode certain of encoded files. pine and elm can recognize and decode MIME files; Eudora for the macintosh can recognize and decode binhexed files sent from Eudora.

Generally, though, you have to save the message you have received out of the mail software and then decode it with program specifically designed to decode such files.

Decoding binary mail: Key points

Software for decoding files on World

Exporting and Decoding Uuenncoded/binhexed mail you receive in pine

In pine, when you realize you've received a binary file, you have to quit pine to create a temporary directory, since pine (by default) doesn't allow you to suspend it or invoke shell commands. Tell it *not* to save read messages, that will make it leave the read messages in your inbox (you "read" the message, in pine's view, by looking at it and seeing it contained encoded data).

At the world% prompt:

	world%  mkdir  /tmp/myname

substituting your login name for "myname".

Then, if the message contains uuencoded data, or some other format like binhex which Pine does not recognize as an attachment, export the message (by highlighting it in the index), and hit "e" for export. If the messages contains an "attachment" which pine recognizes, ignore these instructions, and see below, Saving attachments in pine). Pine will ask which file "in home directory" you want to export the message to. Give it the name:

	/tmp/myname/decodeme
(substituting your login name for "myname"; explicitly supplying a name that begins with "/" overrides pine's normal behavior of saving the message in your home directory.)

Quit pine. Again, leave "read" messages in your mail spool by telling pine not to save read messages in read-messages. Once everything is decoded and downloaded, you probably want to delete the message, rather than save it, but don't delete it yet, in case anything goes wrong.

Now, change to your temporary directory and decode the file. For a uuencoded file, the commands would be:

	world%  cd  /tmp/myname
	world%  uuconvert  decodeme
and for a binhexed file, the commands would be
	world%  cd  /tmp/myname
	world%  mcvert  decodeme

Then you can download the message; if all is well, you can delete it from pine's inbox.

Saving MIME attachments in pine

MIME encoding is the emerging standard which will someday make emailing binary files transparent. MIME can tell a program which application an encoded data file is associated with, so someday, you'll be able to read mail on your own computer, click on an attached spreadsheet, and have your mail program launch 1-2-3, with the spreadsheet you just received loaded for you. Over a dial-in connection, it's not so slick; there's just a different way of decoding files, which saves one step.

You'll still have to make a temporary directory as described above.

Then, in pine, when you look at the message, you'll see:

[Can not display this part. Use the "V" command to save in a file]

Hit "V", and pine will ask:

Save or View attachment 1 ? (s/v) [s]
(The number may be "2" if there is a textual part of the message.) Pine will suggest a name, delete that, because you don't want it in your home directory, and give the name /tmp/myname/filename. Now, there won't be any decoding to do, so you don't choose "filename", instead you give it the name you want the file to have.

Then quit pine, answering "no" to the question about saving read messages, and change to your temporary directory, and download the file.

Exporting/decoding mail you receive in 'mail'

In "mail", you can create a temporary directory from the ampersand prompt:

	& mkdir  /tmp/myname
And save the message with:
	& s  ##  /tmp/myname/decodeme
(substituting your login name for "myname", and the number of the message for ##.) mail will, in that case, mark the message "read", you can "unread" it with:
	&  U ##
again, substituting the number of the message you just saved for ##. Then quit mail. (As with pine, you'll probably want to delete the message in a subsequent session, but leave it in the inbox for now in case anything goes wrong.)

Now, change to the directory and decode the message. munpack or mmencode handle MIME, uuconvert is for uuencoded messages, and mcvert is for binhexed files.

For a MIME encoded file, there are two commands you can use, munpack and mmencode. munpack normally works and is the easier to use:

	world%  cd  /tmp/myname
	world%  munpack  decodeme
If successful, it will create a new file, announcing that it is doing so. Again, you can see the file with:
	world%  ls
and download it as usual. Then remove the files, and delete the still unread message from your mail spool next time you read mail. munpack will announce if it cannot decode the file. If that happens, sometimes the program mmencode can handle the file. (I'm told, I haven't actually encountered this situation.) First, try:
	world%  mmencode -u  decodeme -o newfile
That will create a file called "newfile"; the "-u" tells mmencode that it is decoding, if you forget it, mmencode will re-encode the file. Do:
	world%  ls  -l
which will tell you the files in the directory and their sizes, if "newfile" is of reasonable size, you can presume it worked. If it looks too small, see "common problems" at the end of this help topic.

For a uuencoded file.

	world%  cd  /tmp/myname
	world%  uuconvert  decodeme
and for a binhexed file, the commands would be
	world%  cd  /tmp/myname
	world%  mcvert  decodeme

Software for decoding files on your home computer

These are files to download with utility software for various microcomputer platforms.

Quick And Concise Instructions

To send a file called "myfile" using MIME:

	world% mpack  filename   user@host

To send a file called "myfile" using uuencode

	world%  uuencode  myfile myfile | user@address
Sending MIME mail:
	pine: specify file in attachment header.  Optionally turn off FCC 
	      with ^R while in headers
	Unix "mail" command and similar: convert with mpack, include in message
	mpack can also send MIME-encoded mail with no other mail software
Sending UUencoded mail
	munpack can also handle uuencoded files, uuconvert is superior but
          if you're using a PC or mac with munpack installed that might
          be worth knowing.
Sending Binhexed mail
	there is no program on the World to create binhex files.

Reading an encoded file into a message:
	Pine: hit ^R while in the text area of the message.
	mail: ~r filename
	emacs mail programs: C-x i
	Eudora for Windows can not read in files.  Use MIME attachment
          feature, or use windows clipboard.

Decoding MIME messages
  	Pine and elm will recognize them and instructions are on screen
	Else export to file and run:
		world%  munpack  filename
	If munpack fails, 

	1.  Create a temporary directory where quota doesn't
	    apply.  This reduces clutter and avoids quota
	    problems.
	2.  Save the mail message to a file in the directory
	    you just created.  Use a name unrelated to the name
	    you expect the decoded file to have: I generally
	    choose a name like "decodeme".
	3.  Quit the mail program, change to the temporary
	    directory, and run the appropriate file conversion
	    program.  If you called the file "decodeme" and it
	    is:

		uuencoded:
		world%  uuconvert  decodeme

		MIME encoded:
		world%  munpack  decodeme
		*or*
		world%  mmencode -u  decodeme -o outputname
		
		binhexed:
		world%  mcvert  binhex

	All of these methods create a *new* file, they do not
	actually change "decodeme".
		
	For MIME, munpack handles most files, but if it doesn't
	work, try mmencode.

Common Problems

Related topics

Encoding/decoding program documentation
uuencode and uuconvert mpack, for MIME; mcvert, for binhex
MIME
A quick definition of the Multipurpose Internet Mail Extension.
Temporary disk space
You can write out files that you don't have quota for, and keep down clutter in your home directory.

HOME Top of Help Desk Eye On The World  The World Kiosk


             For further assistance, please send an email 
                       request to support@world.std.com

        Copyright 1995 Software Tool & Die, Inc.  All Rights Reserved.

   Software Tool & Die, Inc., 1330 Beacon St. Suite 215 Brookline, MA 02146