# Organizing Messages with Folders

When you first start xmh, you will have folders named inbox and drafts. Folders are like the folders you'd find in an office file cabinet: they group related messages. If you don't have many messages, you may not want new folders. People who get a lot of mail, though, will. Here's how to make new folders and move or copy messages into them.

## Making a New Folder

The `Create Folder` command on the `Folder` menu will make a small window and prompt you for a folder name. After you type in the name, the folder and a new folder button will be created.

The folder name should be all one word -- don't use spaces. You can use a character like an underscore (`_`) to join two words into one. Long names are okay, but remember that they make the buttons bigger than short names. This is demonstrated in the Figure below. (Note that if you have a lot of buttons, or buttons with long names, you can always shorten the folder buttonbox so that it has a scrollbar -- and scroll through the folder buttons.)

Figure: Folder buttonbox with some long folder names

xmh Release 6 supports a single level of subfolders. (The Section Folders and Subfolders has more information.) Make a subfolder like a top-level folder -- but put a slash (`/`) and the subfolder name after the top-level folder name. For example, to make a cheese subfolder in the existing project folder, type `project/cheese` in the `Create Folder` box.

## Folders and Subfolders

xmh Release 4 introduced limited support for MH subfolders. A subfolder is a folder within a folder, as the Figure below shows.

Figure: A folder with one subfolder

MH can have folders inside subfolders, many levels deep. xmh supports just one level -- but that's plenty for most users. (You can create a subfolder more than one level deep from within xmh. It will appear in the menu under the folder button. After you quit and restart xmh, though, the sub-subfolder won't appear on the folder menu anymore.)

If a folder has a subfolder, a list box will drop down when you select the button. The first entry in the list is always for the top-level folder. The other entries are for its subfolders. The next Figure shows how to select the system_b subfolder of the syserrs folder.

All xmh operations work as well on subfolders as they do on top-level folders.

## Using Another Folder

To see another folder, you have two choices: either change the folder you're viewing now in the main window or open a new main window for the folder.

- To change the folder you're viewing in a main window, select the new folder by clicking the button named for the folder. Then use `Open Folder` on the `Folder` menu. The Table of Contents will display the first few messages in the folder -- if there are more messages, there'll be a scrollbar. Select, view, or delete messages the same way you did for inbox.

  The accelerator for opening a new folder is handy and fast. Click on the folder button with your second mouse button. That selects and opens the folder in one step.

  If a folder has a subfolder, slide down the subfolder list to the folder you want, as the Figure below shows.

  Figure: A folder with four subfolders

- One advantage of xmh over standard (uncustomized) MH is that you can have windows open onto several different folders -- xmh won't get confused. To open a separate folder window, use your first mouse button to select the button named for the folder you want. Then, select `Open Folder in New Window` from the `Folder` menu. A new main window will open with a view of that folder.

  Notice that the first main window is still displaying the original folder. That's possible because xmh keeps the selected folder separate from the viewed folder. You can select a different folder by clicking its folder button, but xmh does not view that folder until you have selected `Open Folder` or `Open Folder in New Window`.

  Once you have the new window open, you can compose new messages from each window, move messages to other folders, and so on.

  If you move messages between two open main folder windows, the Tables of Contents will change automatically.

  If you try to view the same folder from two windows, things can get confusing. It's probably best to stick with one window per folder.

> NOTE: If you make a new folder and you don't move or copy any messages into it -- then, when you open it for the first time, you'll get an error message like `scan: no messages in folderpath`.

> This isn't really an error -- it's just the MH scan command telling you that the folder is empty. If you move or link a message into the folder before you open it for the first time, you won't see the error.

## Moving Messages Between Folders

Here are the steps for moving messages to another folder, with and without an accelerator. First, make sure that the Table of Contents shows the folder you want to take messages from (the folder you want to move messages out of):

- Here's how to move messages without an accelerator:
  1. Select the message(s) you want to move by highlighting the message line(s) in the Table of Contents: use the first mouse button, as you did before.
  2. Next, select the destination folder (this is called the selected folder). To do this, just click the first mouse button on the destination folder-name button in the folder-name buttonbox. Do not use the `Open Folder` command, though!

     The viewed folder (in the Table of Contents) won't change. (If it does change, you probably used the second mouse button accidentally.)

  3. Pull down the `Message` menu and choose `Move`. This doesn't actually move the messages; it just marks them for moving. The scan lines of the messages to be moved will get a caret (`^`) next to the message numbers. (If the viewed and destination folders are the same, xmh will just ring the bell.)
  4. Repeat the steps above to mark more messages, if you want to. It's okay to have different destination folders for different messages. After you highlight the message(s), you can choose any destination folder.
  5. You can use `UnMark` on the `Message` menu to clear the mark from a selected message. When you're done, you can scroll the Table of Contents up and down to be sure that the messages you want to move are marked.
  6. When you use the `Commit Changes` command, the messages will move to their destination folders. The accelerator for `Commit Changes` is META-SHIFT-C.
- Here's how to move messages with an accelerator. Using accelerators saves you time and steps:
  1. In the Table of Contents, use the first mouse button to select the message(s) you want to move.
  2. To unmark message(s) so they won't be moved, select the messages (put in reverse video) with the first mouse button. Then, press META-U.
  3. To move the marked messages, select the destination folder with the third mouse button.

Here are some miscellaneous facts about moving messages:

- If you are viewing one of the messages before you move it, then you will see `-> foldername` in the titlebar, as shown in the Figure below. In fact, if you changed destination folders while you were marking, this is a good way to find out where a message is going.
- The messages you move will be renumbered starting after the last message in the destination folder.
- Accelerators for viewing the next and previous message (META-N and META-P, respectively) will skip over messages that have been marked for moving, copying, or deleting -- that's the default. To change it, you can set the SkipMoved, SkipDeleted, and SkipCopied resources to `false`.

Figure: Two messages marked for moving

## Linking (not Copying) Messages Between Folders

xmh Release 4 had a `Copy` command (on the `Message` menu) for "copying" messages between folders. This isn't really what xmh does with the messages -- instead, it links the messages to the new folder. In xmh Release 5, the command name was changed to `Copy as Link` -- but it does the same thing it did before. For more details about what linking means, see the Sections Using Links and Links. Basically, linking saves disk space.

> CAUTION: If you edit one of the "copied" (linked) messages by displaying it in the view window and choosing `Edit Message`, all the "copies" of the messages in all folders will show the same edit!

> A link isn't a true copy. In this book I'll call it a link, not a copy.

Linking a message to another folder takes the same steps as moving. The difference is that when the message is marked for copying, xmh puts a `C` in the Table of Contents next to the message number and `-> foldername (Copy)` in the titlebar above the message view. Be sure to use `Commit Changes` when you're ready.

The accelerator for marking to copy is META-C. The accelerator for committing the changes is META-SHIFT-C.

## Deleting (and Restoring) Messages

To delete messages, use the steps in the Section Moving Messages Between Folders for selecting the messages, but use the `Delete` command on the `Message` menu. The accelerator for marking to delete is META-D. The accelerator for committing the changes is META-SHIFT-C.

If you accidentally delete a message, you can probably get it back (though you may have to exit xmh). See the Section Removing and Recovering Messages.

Also see the rmmer shell script, which makes it easy to recover your deleted messages. If you install rmmer on your account, you still use the `Delete` and `Commit Changes` commands (or the accelerators), as always. But rmmer puts your deleted messages into a subfolder named DELETE where it's easy to recover them if you need to. (A system program removes the "deleted" messages later.)

This is a real win for xmh users because you don't have to open an xterm window or use MH commands to recover deleted messages anymore. (Remember that because xmh can't deal with sub-subfolders, you'll need to use MH commands to recover messages you delete from subfolders -- see the Section Recovering a Removed Message for help. If you have to recover a deleted message with MH, you should use the xmh `Rescan Folder` command so xmh will update its folder list. This is a good thing to do any time after you use an MH command. Or use the rmmer_1.noask script instead -- it puts all deleted messages in one top-level folder (not a subfolder) named DELETE.)

The first time you delete a message in a folder, rmmer will create the DELETE subfolder for you. But the new subfolder won't appear on a menu until the next time you start xmh.

To recover a deleted message, go to the folder where it was deleted. Then go to the DELETE subfolder (see the Figure below) and move the message to its parent folder. (You can actually move the message to any folder, not just its parent.)

Figure: Recovering a message deleted by rmmer

## Rescan Folder

Unlike MH, where you can always find out what's in your folder with scan, xmh only rescans your folder every so often (depending on the CheckFrequency setting -- see the resource summary in the Table xmh Resources).

If you think xmh doesn't have the latest view of the folder, use the `Rescan Folder` command on the `Table of Contents` menu. (The accelerator is META-SHIFT-R.) This is good to do after you've used some MH commands from, say, an xterm window.

## Viewed Message vs. Viewed Folder

The viewed message area of the main window will hold a view of one message. It can even be a message from a different folder than the viewed folder. The Figure below is viewing a message from the drafts folder, but with a different folder and sequence selected in the Table of Contents. You might want to do this if your screen is already full of windows and you don't want to open a separate window on a separate folder.

Figure: Message and Table of Contents from different folders

## Packing a Folder

If you use the `Pack Folder` command on the `Table of Contents` menu, messages in the folder will be renumbered as 1, 2, 3, and so on. This closes gaps caused by removing messages (if you don't pack the folder, the messages aren't renumbered). MH and xmh don't care much what numbers your messages have, although xmh isn't happy with message numbers larger than 9999. Packing a folder also avoids errors in the sequence file if the folder gets too fragmented; the NOTE in the Section Previous-Sequence, Sequence-Negation explains what to do if this happens to you.

## Sorting a Folder

To sort the messages by date from oldest to newest use the `Sort Folder` command. (Depending on the version of MH you're running, this may also renumber the messages starting from 1 (like packing the folder). Check your online sortm(1) manual page.)

The first Figure below is an example of a folder before sorting. The next Figure below shows the same folder after sorting.

Figure: Folder before sorting

Figure: Folder after sorting

Notice that one of the messages has an asterisk (`*`) by the number. This means that there's no acceptable `Date:` field in the header -- so xmh shows the date that the message file itself was modified. The message from the MH sortm command pops up in a dialog box.

After sorting, the messages don't seem to be in date order (message 3 was sent on November 23, but message 4 was sent on February 9?). But the dates are in order -- the date sort pays attention to the year. For instance, message 3 was sent in 1989. If a message doesn't have an acceptable date, the sort tries to keep the message in about the same relative position it was before -- but, as you can see, this doesn't always work.

If you have the MH 6.7 or later version of sortm, you can change it to sort by other fields. For instance, it can sort by subject. The Section Sorting Messages: sortm explains sorting switches.

You can set default sortm switches in your MH profile, so you always get one kind of sort. You can also set up xmh buttons that run the edprofile shell script -- to change the sorting order at any time while you're running xmh.

## Deleting a Folder

The `Delete Folder` command on the `Folder` menu deletes the selected folder and all messages in it. Before it deletes the folder, xmh will list it in the Table of Contents. Then, it will will ask for confirmation in a dialog box.

> NOTE: `Delete Folder` deletes the selected folder, not the viewed folder.

Even though the dialog box is up, you should be able to browse through the Table of Contents, view messages, and so on. When you're sure, click `Yes`.

> CAUTION: When you delete a folder, there's no going back. Be careful...