Solaris Advanced User's Guide

Saving and Retrieving Messages

In addition to sending and receiving messages, you might also save and retrieve them for later use. In mailx you can save messages by appending them to regular text files. You can also append messages to special files called folders. Both methods are discussed subsequently.

mailx makes a distinction between saving messages and copying them. Saving removes a message from the mailbox and appends it to a file or folder. Copying leaves a message in the mailbox and appends a copy to a file or folder.

Saving and Copying Messages in Files

To save a message into a file, use the following command form at the mailx prompt.

s number filename

where number is the number of the message to be saved and filename is the file where you want to save the message. For example, to save message 3 into a file called ~/notes/finance, you would type:

& s 3 ~/notes/finance

Remember that in a path name, the ~ represents your home directory.

You can also save several messages at once to the same file. For example, to save messages 3, 5, 6, 7, and 8 to ~/notes/finance, type the following command.

& s 3 5-8 ~/notes/finance

If the file you specify does not exist, mailx creates it. If the file does exist, mailx appends the message you are saving to the end of the file.

Saving a file removes it from your mailbox. mailx displays an asterisk (*) next to the header of any message than has been saved.

To leave the message in your mailbox while appending it to another file, use the copy command, as follows:

& c 3 ~/notes/finance

Saving and Copying Messages in Folders

You can avoid typing full path names to files if you save or copy messages to mail folders. Folders are special files that are stored in a folder directory.

The advantage of saving or copying messages to folders is that your messages are automatically stored in the same directory, where they are easily accessible without typing long path names.

Setting the Folder Directory

To use folders, you must first set up a folder directory. Follow these steps to set up a folder directory.

  1. Create a directory by using the mkdir command.

    For example, if you wanted your folder directory to be called Messages, you would first create the directory:

    $ mkdir Messages
  2. Edit the .mailrc file in your home directory (which contains mailx options) to set the folder directory path.

    Edit the folder variable to include the full path name of your newly created folder directory. For example:

    set folder=/home/austin/rose/Messages

    Or use the C shell shortcut ~ to specify your home directory.

    set folder=~/Messages

Now your folder directory is set to receive messages that are saved in folders. The change to the .mailrc file becomes effective the next time you start mailx.

Designating Folders

You use the same commands to save or copy messages into folders as into files, except that the folder name is preceded by a plus sign (+) instead of a path name. The + tells mailx that the folder is to be kept in the folder directory (Messages).

For example, to save message 3 to a folder called projects, type:

& s 3 +projects

mailx interprets this command as “save message 3 into ~/Messages/projects.” If the folder doesn't already exist, mailx creates it.

Copy the message into a folder by typing:

& c 3 +projects

Sending a Message Directly to a File or Folder

You can send copies of your messages directly to one of your files or folders. To send a copy to a folder, simply type the folder name in either the Cc: or the Bcc: field. Sending a copy to a file is similar, but you must include the full path name.

Reading Messages in Files and Folders

To read messages that are saved in a file, use the command form:

mailx -f filename

In the previous example, you would read the file ~/memos/finance by typing:

$ mailx -f ~/memos/finance

You can read messages that are saved in a folder with a similar command—just use the + instead of a path name. For example, to read the messages in the folder projects, you would type:

$ mailx -f +projects

This command starts mailx in the file or folder that you have designated. Only headers for the messages in the file or folder are displayed. Select a message to read by typing its number at the mailx prompt, and then press Return.

You can also work on mail folders within the mailx program. To see a list of your folders, type this command at a mailx prompt:

& folders

To switch from your mailbox to a folder, use the command form:

& folder +foldername

To return to your mailbox, type this command at a mailx prompt:

& %

To return to the previous folder, type:

& #