The Internet is, at heart, a UNIX network. It and its many services were closely tied to UNIX at the start, and that relationship continues to this day. Most UNIX implementations come with, or allow easy addition of, a whole suite of utilities for Internet connectivity. UNIX machines tend to be networked, and there is a good chance that your Internet access comes either directly or indirectly through some box running UNIX.
Many UNIX e-mail packages have primitive user interfaces, but that is changing. On the other hand, UNIX e-mail packages tend to be extremely powerful and flexible. Microcomputer-based e-mail, discussed in the next chapter, tends to be strong on user interfaces and less powerful.
In the last chapter, we looked at the lower levels of e-mail. This chapter is concerned with User Agents for UNIXthe e-mail programs themselves. These programs are supposed to take care of all the hassles involved with retrieving and sending mail. You'll find that they vary widely in capability.
To access e-mail on UNIX, you don't actually have to run any sort of e-mail program. When your mail host receives a message for you, it places the message in your incoming mail spool file, usually /var/spool/mail/yourid, /usr/mail/yourid, or /usr/spool/mail/yourid.
All new messages are lumped together in the same file, divided by some separator your e-mail program should recognize. The most common separator is the characters From at the start of a line. Another separator, used in the MMDF format, is four Ctrl+A (ASCII 001) characters.
Most UNIX systems come with a basic program named, simply, mail. The Sun manual pages for mail claim that it is "a comfortable, flexible, interactive program for composing, sending, and receiving electronic messages." Flexible and interactive, yes; comfortable, no. But mail or a variation of it is on most systems. The mail version reviewed here is the common Sun mail program, but there are clones all over the place.
In its simplest use, mail can be an easy mail-sending device. Just use the following line:
mail -s "subject" recipient < message
On some systems, you may have to use the mailx command instead of mail. You can't place headers in the message text. Or rather, you can, but the headers are treated as part of the message bodymail wants to control all the headers.
The < message part isn't required. If you don't give it, mail prompts you for the message text. If you do give it, it is a pre-prepared file that contains the message.
The -s "subject" part is optional, but if you don't include it, your e-mail won't have a subject when it is received. If you didn't include the < message part and are entering the message by hand, mail prompts you for the subject.
You can specify multiple recipients, separated by spaces.
You can enter e-mail by hand as opposed to sending a prepared message. Just type mail recipient.
You are prompted to enter a subject. After entering the subject, you can type your message in a line mode (that provides very limited editing capability using tilde escape commands). If you enter the message in line mode, press Ctrl+D to send the mail when you are finished typing the message.
You can use a number of tilde escape commands to control various mail functions. These commands are indicated by a tilde (~) as the first character of a line, followed by the escape command. If you really want to have a tilde as the first character of a line of your message, enter it twice (~~).
NOTE In normal use, I recommend the use of only one tilde escape command: ~v. The ~v command puts you in the editor defined by the UNIX environment variable VISUAL. By default, this is usually the vi editor, which is not the best editor for entering e-mail but does work. (Other editors such as emacs are also available.) If you ever need other tilde commands, type ~?.
If you start mail without any arguments (that is, if you just type mail), the program looks in your incoming mailbox for new e-mail. If it finds any, it places you into command mode. The first thing mail does is show you the e-mail waiting for you:
Mail version SMI 4.0 Wed Mar22 10:38:28 PDT 1995 Type ? for help. "/var/spool/mail/rdippold": 2 messages 2 new >N 1 jeff@goo.goo.com Sat Mar 4 23:18 20/1045 Voting N 2 rdippold Sun Mar 5 01:19 13/347 This is a test
This message shows that I have two new e-mail messages waiting. One is from jeff@goo.goo.com, sent Saturday, March 4, at 11:18 p.m. It is 20 lines long and 1,045 characters (including the header). The subject of the message is Voting. The second message is one I sent to myself.
The > in the left column of the first message indicates that it is the current messageif I don't specify a message number, any command I give acts on this message. The Ns next to messages 1 and 2 indicate that they are new messages. The & is mail's prompt.
Note that there are many mailboxes, in the sense of files containing mail messages. There are two defaults, plus any you create yourself. The first standard mailbox is the incoming mailbox referred to earlier, usually stored at /usr/spool/mail/yourid, /usr/mail/yourid, or /var/spool/mail/yourid. This is your "system" mailbox. The second standard mailbox contains all your old, previously read messages (unless you've deleted them). This is a file called mbox in your home directory. You can also define as many mailboxes, or folders, as you want. Any file with saved messages is technically a mailbox, so simply executing a save or copy command on a message to another file creates another mailbox, which you can switch to later.
The general procedure for reading new e-mail is to press[]to view each message; press r to reply to a message; press d to delete it (if you don't want it saved in mbox). You can follow any of these commands by a number (for example, you can read the fifth message by typing[]5 or delete the tenth message by typing d 10.
As with most UNIX e-mail programs, messages are not deleted until you exit the mail program. Until then, you can type undelete # where the pound sign is the message number you want to undelete (the message you previously marked to be deleted).
Mail supports folders. You can see your available folders by using the folders command. You can switch to a particular folder by using the file folder command (replace folder with the folder name).
You can move messages into folders with the command copy message folder. The message parameter is the message number to be moved. The folder parameter is the name of the folder to which you want to move the message.
Mail has several variables that affect its behavior. These variables act as a way to customize mail to your preferences. These variables are lost when you exit mail, so you should place any variable settings you want to use all the time in your .mailrc file (see "The .mailrc File," below).
You use the set command to change the value of these variables. For example, type set VISUAL=emacs to set the full-screen editor to the emacs editor. Type set by itself to see all the current variables.
To change the location of where mail thinks your folders are, use the set folder=directory command. By default, when replying, mail puts a tab in front of the other person's text. You can change this default with set indentprefix=prefix where prefix is the prefix character you want to use. The most common use of this command is set indentprefix=>.
The set replyall command configures mail so that whenever you reply, the message goes to all the people on the Cc line as well as those on the From line.
It would be a real pain in the neck to have to configure mail each time for the way you like to work. Instead, you can use the source command to read in a file as a series of mail commands. By using the source command, you can have a file that sets up your mail configuration the way you like it. But you still have to type source myconfig every time you run mail, and this method doesn't work if you type mail henry and never see a command line.
The solution is the .mailrc file. This file lives in your home directory and is automatically executed every time you start mail, just as if you had typed source .mailrc. Usually, the .mailrc file contains mail variables, but you can include other mail commands as well. The following sample .mailrc file uses many variables and commands not discussed in this chapter, but it will give you an idea of some of the other options available in mail:
# Example .mailrc file for Ron Dippold echo Running Ron's .mailrc file # # The next lines set up aliases for sending mail alias bill williamf@wubba.com alias me rdippold@tofu.com alias mit mail-server@rtfm.mit.edu # # These are some alternate addresses which I go by alternates rdippold voting ronnied # # Discard "Received:" headers, which we don't care about discard received # # Now set some variables set alwaysignored set autoprint set crt=20 set editheaders set folder=/usr/rdippold/mailboxes set indentprefix=" > " set keep set metoo set prompt="mail> " set quiet set screen=20 set sign=" Ron Dippold" set Sign="Ron Dippold - rdippold@tofu.com - (619) 555-1212" set VISUAL=emacs # # This next bit is kind of neat - if I'm using a terminal, even my regular editor # should be emacs. Why would I want to use a line editor? If for some reason # I'm not using a terminal, then I'll grudgingly use ex, a line editor. if t set EDITOR=emacs else set EDITOR=ex endif echo Done processing Ron's .mailrc file. You may cheer.
TIP To leave mail, just type quit. There are many mail commands not described in this chapter. You can discover them by looking at the mail manual page (type man mail) or by typing help within mail.
The basic mail program is fairly flexible and powerful. The user interface is enough to send most people crying home to their parent or legal guardian, so there have been no shortage of replacement mail programs. In fact, you probably won't use mail. I spent the time explaining it because the same basic principles apply to the rest of the mail programs out there.
Elm is_impressive. It's written to be an easy-to-use, full-screen UNIX e-mail system, but it actually comes with an impressive amount of configurability and power. Elm comes with more than 100 pages of PostScript-formatted documentation.
Elm includes support for AT&T Mail forms, which makes it easy to fill out a standardized form and mail it off. Elm has some MIME support, but for real MIME support, you need the metamail package (available by anonymous FTP from thumper.bellcore.com).
As of the time of this writing, Elm was at version 2.4.
NOTE You can use anonymous FTP to get Elm from
ftp://ftp.uu.net/networking/mail/elm or from
ftp://wuarchive.wustl.edu/mirrors/elm.
The packed source-code file (which you need to build Elm) is about 1M, and the packed documentation is about 250K. Elm is not for those whose disk space is scarce. However, if you're looking for a friendly and fairly powerful mail program, it may be worth getting some guru with disk space to burn to get Elm running for youElm doesn't require a huge amount of space when it's running.
You start Elm by typing elm.
Elm places an .elm directory in your home directory to contain configuration items (such as the elmrc configuration file). It also makes a Mail directory for your mail folders (unless you change that setting).
Elm itself is actually fairly simple. The messages are presented as header summaries (see Figure 13.1). You scroll a selection bar up and down the list of messages and press a key to perform an action on the message. The basic list of keys you need to know is reasonably small and usually appears at the bottom of the screen, but there are many esoteric functions assigned to esoteric keys. Almost every key has a function.
FIGURE 13.1. The main Elm screen. I have eight messages in my mailbox; four are new. Message 7 is selected.
Elm has respectable online help. Type ? to get help; type ?? to get a list of all valid keys.
After you select a message, press Enter or the spacebar to view it. You will be in a simple full-screen e-mail lister. Most of the keys that affect e-mail also work from this screen.
To send a message in Elm, use the m command. Entering messages in Elm is easy. Just enter the name of the recipient and the subject, and Elm sends you into the editor. When you exit the editor, you have several options:
Option |
Description |
|
e |
Edit the message again. |
|
! |
Exit to a command shell. Type exit to get back to Elm. |
|
h |
Edit the message headers (see Figure 13.2). |
|
c |
Save a copy of the message. |
|
i |
Spell-check the message. |
|
s |
Send the message. |
|
f |
Forget about itdon't send the message. |
FIGURE 13.2. Editing the message headers is easier than it soundsElm comes with an option screen for this task.
Pick the appropriate command. If you pick s, your message goes to the recipient.
If you press o from the main menu, you see the Elm options screen. The options shown in Figure 13.3 are explained in Table 13.1.
FIGURE 13.3. An example option screen.
Option |
Description |
|
D |
Your message display program. By default, Elm uses its own built-in message displayer (builtin+). Change this value to more if you like the UNIX pager. |
|
E |
The editor used for outbound messages. Elm comes with a built-in editor, which is rather puny. If you regularly use a good full-screen editor, the outbound editor should be the same as your visual editor (see the entry for the V option). |
|
F |
The directory in which your e-mail folders are kept. By default, Elm uses the Mail directory under your root directory. |
|
S |
Specification of how folders are sorted. Most options you would want to use (and some you wouldn't) are allowed for. I normally use Mailbox Order, which is effectively unsorted. When you select this option, it goes through the list of valid options. |
|
O |
You can specify a folder in which all the e-mail you send is kept. By default, this is =sent, which means the folder sent stored in the file sent in your Elm Mail directory. |
|
P |
This is the command used to print your e-mail. Place the characters %s in the command to specify where Elm can put the name of the file to print to the programs you invoke. For example, you can use /bin/lp %s to invoke the printer on some System V systems. |
|
Y |
Your full name is the equivalent of the personal name in other e-mail programs. The text you specify here is sent in the From field as a comment: ab3443@bravenew.world.com (Your Full Name). |
|
V |
Visual editor is a strange way of saying full-screen editor. This is usually emacs, vi, or pico; specify your favorite. |
|
A |
If the Arrow Cursor setting is off, an inverse highlight bar is used to choose messages. If you're on a very slow link, that method may be too slow; it may also be that you cannot see inverse highlights on your old clunker terminal. In both cases, you can set this option on to get a -> to the left of the screen to select messages. |
|
M |
Normally, Elm gives a short menu of the most important keys at the bottom of the screen. Although this menu is nice, it takes up room where you could show message headers (after a while, you learn what the keys are). Turn off this option to free that screen space. |
|
U |
The User Level option isn't well defined, but there are three levels: beginner, intermediate, and advanced. Beginners won't have some commands available (there's no need to scare them). |
|
N |
Normally, Elm shows only the name of the sender when you reply to a message. If you turn off the Names Only option, both the name and the address are shown. |
Don't forget to press > to save your options when you're done!
Even if you don't want to change any of the options shown in the Elm options screen, you should press > from the options screen. Doing so creates the file .elm/elmrc in your home directory. You can edit this file to set all sorts of nifty options, most of which can't be configured from inside Elm.
TIP The .elm/elmrc file can be somewhat deceiving if you forget that all lines starting with # are comments. You can change values until you're blue in the face, but unless you get rid of those #s, Elm uses its default values.
You can find help for all the settings in the Ref.guide, which comes with Elm. Therefore, this chapter does not detail all the Elm settings.
Reading messages in Elm is simple. Use the arrow keys to highlight the message you want to read and then press Enter or Return. Elm displays the selected message.
Continue pressing Enter to see the various pages of the message. When you want to go back to the message list, press i (Index).
To reply to a message, highlight the message and press r. The rest of the reply function works like the send function.
Highlight a message and press d to delete the message. If you change your mind, notice that once a message is deleted, the cursor skips over that message when you press the arrow keys. However, you can type the message number by itself to go directly to the deleted message. Once the message is highlighted, you can press u to undelete.
Folders are one of Elm's strengths. If you want to see what folders you currently have, the command depends on your version of Elm. With version 2.4 (and probably future versions), press c (for change folder) and then press =*. For earlier versions, press c and then press ?.
To switch to a folder, use the c command. Then Elm prompts you for the folder name. Enter the name of the folder preceded by an equal sign. For example, to switch to the fun folder, type =fun.
To save a message into a particular folder, highlight the message and use the s command. The default folder name that appears is the userid of the person who sent you the mail. If you do not want the default, type = and the name of the folder to which you want to save the message.
Elm handles the same command-line arguments as mail (and more), so you can use Elm instead of mail to send an automatic command-line message. The following line works just fine:
elm -s "subject" recipient < messagefile
If you don't give the < messagefile information, Elm prompts you, just like mail does.
Elm is actually much more powerful than it appears at first glance. In addition to Elm itself, a host of associated programs are available. Read the documentation for a full description of how to use each program. These associated programs serve a variety of purposes such as telling people you are on vacation, telling you immediately when new mail arrives, and so on.
There are also several programs (chkalias, elmalias, and so on) that help manage Elm's aliases feature, which is fairly robust. Aliases enable you to define user nicknames and group of names so that you can specify just joeb rather than his full address of joe_buttafucco@incredibly_long_name.fisher.edu.
Elm comes with much documentation and includes specific guides for aliases, the filter program, and mail forms. Be sure to browse Users.guide and Ref.guide for hints.
NOTE If you think you are going to be a serious Elm user, the Usenet group comp.mail.elm carries a discussion on it. The Elm Frequently Asked Questions list (FAQ) is available at
ftp://ghost.dsi.unimi.it/pub/Elm/Elm-FAQ.Z. It's also posted to the Usenet group news.answers once a month.
In its simplest configuration, Elm is easier to use than mail. Elm also comes with quite a few useful additional programs, if you don't mind the complexity of the add-ins. But what if Elm is still too complex for you?
PINE, in a vein similar to Elm, is a product from the University of Washington that's designed to act on simple one-key menu operations. PINE originally stood for "PINE Is Not Elm," but recently has been changed to mean "Program for Internet News and E-mail." PINE supports MIME. MS-DOS and UNIX versions of PINE are available. PINE uses a message editor, pico, which can also be used as a stand-alone program. PINE handles multiple folders or incoming mailboxes quite well. PINE can read Usenet news, although it currently does not offer all the features of a full-featured news reader.
NOTE To get PINE, anonymously FTP to
ftp://ftp.cac.washington.edu/mail.
At the time of this writing, the latest version of PINE was version 3.91. The compressed distribution code, pine.tar.Z, was 2M in size. As a nice touch, precompiled versions for AIX3.2, HP/UX 9.01, Linux, NeXTstep, Solaris 2.X (SPARC), and SunOS 4.1.3 (SPARC) systems are available in the UNIX-BINARIES subdirectory. Most of these files are around 2M in size (the AIX executable file weighs in at 4M).
If you already have a version of PINE, you should know that some versions of PINE let you fetch the latest version of itself from the PINE Update Server.
You can totally configure PINE 3.9x from within the program itself. If you have an older version of PINE, you must edit a file called .pinerc (not covered here). The PINE configuration screen can be reached by pressing S and then C from the main menu.
If you installed PINE yourself, make sure that you set personal-name (your own name, for example, John Smith), smtp-server (if you're using SMTPyou probably should ask your system administrator for this value if PINE cannot send a message successfully), and inbox-path (very important, usually /var/spool/mail/yourid). The rest is gravy. The sort-key setting is nice if you like to be organized. The image-viewer setting is a necessity if you want to view GIF or JPEG files that arrive in MIME messages. However, if you are a PINE user and not the system administrator, you will probably find PINE preconfigured for your system and do not need to make any changes unless you want to.
PINE is designed to be easy to use (see Figure 13.4). Most functions are keyed off of "hotkeys." These hotkeys change from screen to screen, but an effort was made to keep them consistent where possible. The bottom of the screen lists some of the currently acceptable commands.
Press ? on most screens to get help; on screens where text entry is called for, press Ctrl+G to get help. The Ctrl+G combination isn't very intuitive, but PINE always reminds you of it. (Any "normal" key may be something you want to enter as part of the text, so something strange has to be used to access help.) The help is fairly detailed (see Figure 13.5).
FIGURE 13.5. This is a PINE help screen for the Address Book.
When hotkeys aren't practical (such as when you're selecting one mail message out of dozens), a selection bar is used. You can move it with the arrow keys and press a hotkey to take appropriate action against the selected message.
Finally, there are a few places where you just must actually type something, such as when you enter message text. If this bugs you, be cheered by the fact that voice recognition systems are improving rapidly.
PINE makes good use of the concept of multiple folders. By default, PINE creates three folders: INBOX (your incoming e-mail), sent-mail (e-mail you've sent), and saved-messages (a generic place for you to save messages). You can define folders of your own for storing e-mail that should be grouped with other mail. Switching to another folder is as simple as pressing L (for List Folders) from almost any menu. By default, all folders except INBOX are created in a mail directory under your home directory; INBOX is wherever your system places your new e-mail. To create a new folder, press L to get the folder list, press A (for Add), and type the name of the new folder.
When you open a folder, you see an overview of all the messages in the folder (see Figure 13.6). Use your cursor to select a message to read, press Return, and you are in a full-screen message viewer.
The PINE Address Book is useful (access the Address Book screen by pressing A from the main menu). The basic concept is the same as the nicknames, or aliases, of mail and Elm: you want to create fast names you can use to refer to nasty long addresses or lists of addresses (see Figure 13.7).
Instead of sending e-mail to wakko@watertower.warner.com, I can define that address to be associated with a nickname wakko. When I compose a message and enter wakko as the recipient, PINE replaces that alias with the full address. You can also create list aliases, which send e-mail to several addresses. For example, I can define the alias warners to send mail to wakko, yakko, and dot. PINE takes care of expanding the alias name into addresses for me.
You can create an alias when you are reading a message or looking at an index of messages. The Takeaddr command searches the current message for the From field, shows it to you, and asks you for a nickname for this address. Using this feature, you can define nicknames on the fly.
Compose is PINE's equivalent of other programs' send command. Compose enables you to specify who you want to send the message to and then enter your message text. You can start a composition by pressing C from most menus. The editor is easy to use, and even includes a primitive spell checker (see Figure 13.8).
There's one item in the editor screen that may be puzzling: Attchmnt (it stands for Attachment and refers to an attached file). Use this field to specify the name of a file you want to send with the message using MIME format. If the receiver has a MIME-capable e-mail reader, the receiver should be able to "detach" the file and use it for whatever nefarious purpose you intended. When you're viewing a message, PINE enables you to view or save an attached MIME file by pressing the V key.
One of the advanced features of PINE is its capability to stop a composition in the middle and continue it at a later date. The function is known as Postpone and can be accessed by pressing Ctrl+O. Thereafter, every time you enter Compose mode (in a few minutes, hours, days, or years), you are prompted whether you want to continue the postponed composition.
Reading messages in PINE is almost identical to reading them in Elm. You highlight what you want with the arrow keys and press Enter or Return. After reading the message, press I (for Index) to go back to the messages screen.
Press D to delete a message; press U to undelete a message (PINE does not skip undeleted messages like Elm does). Finally, you can reply to a message by pressing R.
PINE is easy to use, is fairly powerful, does MIME, and has good help. If you can live with a large mail program and if menu-driven programs don't drive you crazy, it's certainly worth looking at.
This chapter has described several e-mail programs, from the most primitive to the most user friendly. Is this all of them? Not by any means! I'll list a few more here.
NOTE For a complete list of e-mail programs, find the "UNIX E-Mail Software Survey FAQ," which is posted once a month to the Usenet group news.answers. By reading the comp.mail.misc group, you should learn about any exciting new products.
Program |
Description |
|
mailx |
This is AT&T's version of mail. You wouldn't want to use this any more than you would want to use mail, but it's fairly common and should be mentioned. |
|
metamail |
The metamail program isn't really a normal User Mail Agent. Rather, regular e-mail programs can take MIME messages they don't know how to handle and pass them on to metamail, which may be able to do something with them. You can anonymously FTP to thumper.bellcore.com and look in pub/nsb for the source code. |
|
MH |
Mail Handler (MH). MH is different in that each command is a different program. Why use a separate user interface when you can do everything from the UNIX shell? This program is obviously not for novices, but it may be your cup of tea. MH has MIME support and is standard with some UNIX systems. You can find it at ftp://ftp.uci.edu/pub/mh/mh-6.8.tar.Z if you are interested (this is the latest version as of this writing). The Usenet group comp.mail.mh is for discussions of MH. There's also an emacs interface for MH called MH-E. |
|
mush |
Mail User's Shell (mush). This program stands out because it enables you to configure everything, even its internal workings, with a UNIX shell-type scripting language. You can build a totally custom mail environment for yourself. The mush program has evolved into a commercial product, Z-Mail, which is very advanced. For information on either product, mail info@z-code.com. The Usenet group comp.mail.mush is for mush discussion. |
|
ECSMail |
ECSMail is a relatively new, but nice graphical interface to UNIX e-mail. See ftp://isagate.isac.ca/ecsmail/. |
There are other programs (including several for other platforms as discussed in the next chapter), but if none of those listed or discussed fits your needs, read the comp.mail.misc Usenet group to see what else may be out there.
Chapter 12 introduced the concept of a mail filter. Now let's take a look at the packages available on UNIX for filtering messages.
Procmail is designed to "do" things to your e-mail before you see it. It can sort your e-mail into separate folders (useful if you subscribe to different mailing lists) or get a substantial amount of e-mail that can be split off separately so that you can forward the messages to another address. Procmail lets you preprocess your e-mail; for example, you can pass it through a formatter. You can have Procmail generate automatic replies, or have it execute programs when certain types of mail are received. You can even run mail servers and mailing lists with it (more on these entities in later chapters). Procmail has been extensively tested, is fast, and has scads of error checking built in. You can pick up the latest version at ftp://ftp.informatik. rwth-aachen.de/pub/unix/Procmail.tar.Z.
Although Procmail is the king-of-the-hill for mail filter programs, I personally like Deliver. With Deliver, you write shell scripts to handle all incoming messages. Although this usually requires more work on your part than filtering with Procmail, Deliver is very clean, is almost infinitely flexible, and set limits on what you can do with your e-mail based only on how well you can program scripts. The speed shouldn't be too much of a concern on that fast machine of yours. Deliver can be found at ftp://oak.oakland.edu/pub2/unix-c/mail/deliver.tar.Z.
I can't personally recommend or say bad things about the Mailagent program because I'm not very familiar with it, but it's another well-known e-mail filter. This one is written in the perl language, which means you can do almost anything with your e-mail. Mailagent comes with many built-in features. I suggest you look at this one if you know perl; it can be found at ftp://isfs.kuis.kyoto-u.ac.jp/utils/perl-archive/perl-mailagent.tar.Z.
The simple Elm Filter filtering program comes with Elm. It is a nice program to use if your filtering needs are minimal or you are just getting started and want something simple to use. If you want something really powerful, use one of the other programs described here.
The following sections describe how to use uuencode and split. Uuencode converts a binary file to text; split splits a large file into multiple pieces. For general information on these topics, refer to Chapter 12, "Internet E-Mail: An Overview."
Here's a simple example of how uuencode works. The file test1 contains the text This is a test. To run the file through uuencode and place the result in test1.uue, you use the following command:
uuencode test1 test1 > test1.uue
This is the standard uuencode command format: first the name of the file you want to encode, then the name you want the file to have when it is unpacked on the other end, then the > symbol and the name of the encoded file. Normally, you want the file to have the same name when it is unpacked as it does now, so both names (test1 and test1 in this example) usually are the same in any uuencode you do. When you cat test1.uue, you get the following result:
begin 660 test1
.5&AI<R!I<R!A('1E<W1!
end
The first line contains uuencode's begin signal, the UNIX file permissions for the file, and the name to which the file should be unpacked. The second line contains the encoded data, which can consist of only printable characters. Then there's a blank line, followed by end to end the file. You can freely send the uuencoded file through almost any mail system.
You can even send the uuencoded data directly to someone else without an intermediate file:
uuencode ttt.exe ttt.exe | mail -s "Tic Tac Toe" mybuddy
When you receive an e-mail message that has been uuencoded, you have to decode it. For that you use uudecode. First, save the uuencoded e-mail message to a file. Then decode it with the following command:
uudecode test1.uue
Simple as that. Well, not quite. A lot of other crud such as message headers winds up in the test1.uue file. Sometimes, the sender adds some commentary before the data. Uudecode is supposed to find the beginning of the actual uuencoded data in the file, but sometimes it gets confused. You may have to use your editor to trim off everything before the begin line and after the end line.
Now look at the resulting file with cat test1:
This is a test
It worked! Of course, you could have just sent this sentence through the mail without encoding and decoding it. If you want to send programs through the mail, you should encode and decode themand the process should work the same way as described here. It's tough to show the contents of program files in printexcept as a hex dump, which would probably send weaker readers screaming. Therefore, I used just the simple sentence in this example.
But wait! All is not paradise. The test1 file was short; had it been a long file (generally, greater than 100K), we may have had problems sending it to certain networks with UUCP. In Chapter 12, we talked about splitting a mail message. Now we will cover the commands you use to do it.
Although you can split a file manually, there's a UNIX program that does the job for you: split. Just tell split the number of lines you want in each piece of the split file, and split goes snicker-snack, sending that big file galumphing back. The number of lines you specify doesn't tell you the size, exactly, but you can experiment. I find that using 800 lines per piece gives you nice safe 50,000-byte chunks. Here's how it works:
uuencode bigfile bigfile > bigfile.uue split -800 bigfile.uue splits mail -s "Bigfile.uue 1/3" mybuddy < splitsaa mail -s "Bigfile.uue 2/3" mybuddy < splitsab mail -s "Bigfile.uue 3/3" mybuddy < splitsac rm bigfile.uue splits??
The hidden piece of the puzzle is that the split command needs the number of lines, the name of the file to be split, and a base name for the output files. In this case, the base name for the output files is splits. The split program then names the resulting files splitsaa, splitsab, splitsac, and if necessary, all the way up to splitszz. Split can divide a large file into as many as 676 pieces. If that's not enough, seriously consider using other methods to send data.
In the example, the subject lines (-s) use the convention 1/3, 2/3, and 3/3 to let the receiver know how many total pieces there are and which piece of the whole each message is.
The receiver has to save all the messages into a big file, edit out everything except the uuencoded stuff, and then run uudecode on the resulting file. Although it's a cumbersome process, it works. If you do this a lot, look into programs that automate the uuencode splitting and mailing and the recombining plus uudecoding. There's a program for everything.