# More About scan

If you think that scan can't do much, read on. It can show your messages in different formats, scan in reverse order (handy for reviewing your most recent messages first), and scan a file full of messages (like your system mailbox).

## scan Format Files

You can change scan's output with a format file. This is something like an mhl format file. MH comes with a few standard scan format files named scan.default, scan.time, scan.timely, scan.size, and scan.mailx. nmh has added scan.unseen. They're stored in the MH library directory.

The scan.default file is, naturally enough, the default. (Actually, for speed, scan uses a built-in copy of that file.) To use other format files, type the file's name after the -form switch. The Section MH Format Strings explains how to write your own scan format files. You can show any field in the header, change the appearance of the output depending on the message you're scanning, get multiline output, and much more. For now, here are examples of the standard format files:

        % scan 1-4
           1  04/24*mary@hahvahd.edu   rcvtty -- how do I use it?<<I've been
           2  11/23 Al Bok             Query about "repl -query"<<I have a q
           3 -02/09 "Wilbur, Orville"  X Terminal Presentation/Demonstration
           4+ 02/11 To:"Wilbur, Orvil  Re: X Terminal Presentation/Demonstra
        % scan -form scan.time 1-4
           1  04/24 23:12CST*mary@hahvahd.edu   rcvtty -- how do I use it?<<
           2  11/23 05:13GMT Al Bok             Query about "repl -query"<<I
           3 -02/09 10:24EST "Wilbur, Orville"  X Terminal Presentation/Demo
           4+ 02/11 22:03EST To:"Wilbur, Orvil  Re: X Terminal Presentation/
        % scan -form scan.timely 1-4
           1  Apr86*mary@hahvahd.edu   rcvtty -- how do I use it?<<I've been
           2  23Nov Al Bok             Query about "repl -query"<<I have a q
           3 - Fri  "Wilbur, Orville"  X Terminal Presentation/Demonstration
           4+ 22:03 To:"Wilbur, Orvil  Re: X Terminal Presentation/Demonstra
        % scan -form scan.size 1-4
           1  04/24* 1119 mary@hahvahd.edu   rcvtty -- how do I use it?<<I'v
           2  11/23 15326 Al Bok             Query about "repl -query"<<I ha
           3 -02/09   739 "Wilbur, Orville"  X Terminal Presentation/Demonst
           4+ 02/11   530 To:"Wilbur, Orvil  Re: X Terminal Presentation/Dem
        % scan -form scan.mailx 1-4
         N    1 mary@hahvahd.edu  Thu Apr 24 23:12 rcvtty -- how do I use it
         N    2 Al Bok            Thu Nov 23 05:13 Query about "repl -query"
         NR   3 "Wilbur, Orville" Fri Feb 09 10:24 X Terminal Presentation
        >N    4 To:"Wilbur, Orvil Sun Feb 11 22:03 Re: X Terminal Presentati
        % scan -form scan.unseen last:2
         358   09/25 Gigi Anderson      Re: L.UNIX 4ed figures<<Thanks, Rob. Gigi
         360 U 09/25 "O'Reilly Book Su  Re: upt2--cross-reference type color<<As a

Here are some notes about the previous examples:

- Message 1 doesn't have a recognizable `Date:` field in its header. When that happens, the first four forms tell you by putting an asterisk (`*`) next to the date, and scan shows the last-modification time of the file that the message is stored in.
- The dash (`-`) next to message 3 in the first four forms means that it's been replied to with repl -annotate. The last format file, scan.mailx, uses `R` instead.
- The first four forms show a plus sign (`+`) next to the current message number. scan.mailx uses the right angle bracket (`>`).
- The scan.timely format file shows month and year for messages more than 26 weeks old (as in message 1), date and month for messages more than 7 days old (as in message 2), and day name for messages more than 24 hours old (as in message 3); otherwise it shows the time of day it was sent (as in message 4).
- The scan.size format file shows message size in bytes. If the size is over 99999, it starts with a question mark (`?`). For example, 103173 characters would be shown as `?3173`.
- The scan.mailx format file gives a format like the Berkeley UNIX mail(1) command. That program is called mailx(1) on UNIX System V.
- The nmh scan.unseen file marks messages which are in the unseen sequence (messages which haven't been read yet) with a `U`. In the example above, message 360 hasn't been read.

If you want to use one of those format files every time you scan, add an entry such as this to your MH profile:

        scan: -form scan.timely

## Scanning Backward

The -reverse switch scans from the highest message number to the lowest.

> NOTE: In MH Version 6.6 and before, scan -reverse worked only on hosts configured with the MH `[BERK]` option. As of MH 6.7, the -reverse switch works in all MH configurations.

Let's try it on the messages in the folder above:

        % scan -reverse 1-4
           4+ 02/11 To:"Wilbur, Orvil  Re: X Terminal Presentation/Demonstra
           3 -02/09 "Wilbur, Orville"  X Terminal Presentation/Demonstration
           2  11/23 Al Bok             Query about "repl -query"<<I have a q
           1  04/24*mary@hahvahd.edu   rcvtty -- how do I use it?<<I've been

As usual, you can put -reverse in your MH profile if you want it to be the default. It works with scan format files, too.

> NOTE: If you use xmh, don't use -reverse in your MH profile. See this Section for a workaround.

## Scanning a Mailbox File

Version 6.7 of MH scan added a -file switch that lets you scan a mail file in "maildrop format." This is the format of the file where your new mail waits for you -- for instance, the kind of file that inc reads messages from. The MH packf command also makes files in this format.

For example, here's how ehuser could scan her system mailbox:

        % scan -file /usr/spool/mail/ehuser
           1  07/16 To:al@phlabs.ph.co New MH feature<<Al, scan has a new
           2  07/16 Al Bok             Re: New MH feature<<I saw that and

The command version called msgscan makes that command line easier to type.

> NOTE: There's a bug in MH 6.7 through 6.7.2: scan -file looks in your current folder without saying so, and then it scans the file you asked for. This isn't a problem unless your current folder is empty -- if it is, scan will quit with a message `scan: no messages in currentfolder`. If that happens, you can keep scan quiet by giving it the name of any folder that isn't empty, like `+somefolder`.