An MH Primer
Prev |  | Next

# 3 Folders and Mail Searching

Anybody who gets lots of email definitely wants to be able to prioritize, stamp, brief, de-brief, and number their emails in a variety of different ways. MH can do this better than just about anything. One thing that we have not really talked about is the concept of folders. You have undoubtedly come across the folders concept using other email programs. MH has folders too. MH can even do sub-folders of a folder. One thing you should keep in mind with MH is that when you ran `inc` for the first time and it asked you if it could create a `Mail` directory it began storing everything in that directory. If you look at that directory you will find a directory named `inbox`. The `inbox` directory houses all of your incoming mail that has not been thrown anywhere else.

Whenever you create a new folder a new directory is going to be created underneath your MH `Mail` directory, and messages in that folder are going to be stored in that directory. When a new email message comes, it is thrown into your `inbox` directory with a file name that is equivalent to the message number. So even if you did not have any of the MH tools to read your email you could still use standard UNIX® commands to munge around in those directories and just more your files. It is this simplicity that really gives you a lot of power with what you can do with your email.

Just as you can use message lists like `23 16 42` with most MH commands there is a folder option you can specify with just about every MH command. If you do a `scan +freebsd` it will scan your `freebsd` folder, and your current folder will be changed to `freebsd`. If you do a `show +freebsd 23 16 42`, `show` is going to switch to your `freebsd` folder and display messages 23, 16 and 42. So remember that `+`folder`` syntax. You will need to make sure you use it to make commands process different folders. Remember you default folder for mail is `inbox` so doing a `folder +inbox` should always get you back to your mail. Of course, in MH's infinite flexibility this can be changed but most places have probably left it as `inbox`.

## 3.1 `pick`--search email that matches certain criteria

`pick` is one of the more complex commands in the MH system. So you might want to read the pick(1) man page for a more thorough understanding. At its simplest level you can do something like

    % pick -search pci
    15
    42
    55
    56
    57

This will tell `pick` to look through every single line in every message in your current folder and tell you which message numbers it found the word `pci` in. You can then `show` those messages and read them if you wish or `rmm` them. You would have to specify something like `show 15 42 55-57` to display them though. A slightly more useful thing to do is this:

    % pick -search pci -seq pick
    5 hits
    % show pick

This will show you the same messages you just did not have to work as hard to do it. The `-seq` option is really an abbreviation of `-sequence` and `pick` is just a sequence which contains the message numbers that matched. You can use sequences with just about any MH command. So you could have done an `rmm pick` and all those messages would be removed instead. You sequence can be named anything. If you run pick again it will overwrite the old sequence if you use the same name.

Doing a `pick -search` can be a bit more time consuming than just searching for message from someone, or to someone. So `pick` allows you to use the following predefined search criteria:

`-to`

  search based upon who the message is to

`-cc`

  search based on who is in the `Cc:` list

`-from`

  search for who sent the message

`-subject`

  search for emails with this subject

`-date`

  find emails with a matching date

`--`component``

  search for any other component in the header. (i.e. `--reply-to` to find all emails with a certain reply-to in the header)

This allows you to do things like

    % pick -to freebsd-hackers@FreeBSD.org -seq hackers

to get a list of all the email send to the FreeBSD hackers mailing list. `pick` also allows you to group these criteria in different ways using the following options:

- ... `-and` ...

- ... `-or` ...

- `-not` ...

- `-lbrace` ... `-rbrace`

These commands allow you to do things like

    % pick -to freebsd-hackers -or -cc freebsd-hackers

That will grab all the email in your `inbox` that was sent to freebsd-hackers or cc'd to that list. The brace options allow you to group search criteria together. This is sometimes very necessary as in the following example

    % pick -lbrace -to freebsd-hackers -and
      -not -cc freebsd-questions -rbrace -and -subject pci

Basically this says “pick (to freebsd-hackers and not cc'd on freebsd-questions) and the subject is pci”. It should look through your folder and find all messages sent to the freebsd-hackers list that are not cc'd to the freebsd-questions list and contain “pci” in the subject line. Ordinarily you might have to worry about something called operator precedence. Remember in math how you evaluate from left to right and you do multiplication and division first and addition and subtraction second? MH has the same type of rules for `pick`. It is fairly complex so you might want to study the manual page. This document is just to help you get acquainted with MH.

## 3.2 `folder`, `folders`, `refile`--three useful programs for folder maintenance

There are three programs which are primarily just for manipulating your folders. The `folder` program is used to switch between folders, pack them, and list them. At its simplest level you can do a `folder +`newfolder`` and you will be switched into `newfolder`. From there on out all your MH commands like `comp`, `repl`, `scan`, and `show` will act on that `newfolder` folder.

Sometimes when you are reading and deleting messages you will develop “holes” in your folders. If you do a `scan` you might just see messages 34, 35, 36, 43, 55, 56, 57, 80. If you do a `folder -pack` this will renumber all your messages so that there are no holes. It does not actually delete any messages though. So you may need to periodically go through and physically delete `rmm`'d messages.

If you need statistics on your folders you can do a `folders` or `folder -all` to list all your folders, how many messages they have, what the current message is in each one and so on. This line of stats it displays for all your folders is the same one you get when you change to a folder with `folder +foldername`. A `folders` command looks like this:

                    Folder      # of messages (  range  ); cur  msg  (other files)
                  announce  has    1 message  (   1-   1).
                    drafts  has   no messages.
                 f-hackers  has   43 messages (   1-  43).
               f-questions  has   16 messages (   1-  16).
                     inbox+ has   35 messages (   1-  38); cur=  37.
                     lists  has    8 messages (   1-   8).
                 netfuture  has    1 message  (   1-   1).
                       out  has   31 messages (   1-  31).
                  personal  has    6 messages (   1-   6).
                      todo  has   58 messages (   1-  58); cur=   1.

                         TOTAL=  199 messages in 13 folders.

The `refile` command is what you use to move messages between folders. When you do something like `refile 23 +netfuture` message number 23 is moved into the `netfuture` folder. You could also do something like `refile 23 +netfuture/latest` which would put message number 23 in a subfolder called `latest` under the `netfuture` folder. If you want to keep a message in the current folder and link it you can do a `refile -link 23 +netfuture` which would keep 23 in your current `inbox` but also list in your `netfuture` folder. You are probably beginning to realize some of the really powerful things you can do with MH.

Prev | Home | Next
Reading Mail |  | Sending Mail

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.