MAILSORT(1)

NAME
mailsort - sort mbox mail folders by date

SYNOPSIS
mailsort [ -hLrv ] [ folder ... ]

README
Sort mbox format mail folders by dates in the `From ' lines that separate messages.

DESCRIPTION
mailsort sorts "mbox" format mail folders by the dates in the `From ' lines that separate mail messages in each folder. Normally these lines specify the local time of arrival of each message. Folders are reordered in increasing date order (with the oldest message first), and any leading non-mailbox items are left in place. Files containing no mail headers are not considered mail folders, and are left unchanged. Folders which are already sorted are also left unchanged. The -r option reverses the sorting order.

If no arguments are specified, or if - is an argument, mailsort acts as a filter, reading a mail folder from standard input and writing the sorted folder on standard output, in addition to rewriting any folders passed as arguments.

Normally, mailsort is silent. Warnings are printed in case of problems encountered during processing. In verbose mode, an indication of processing is printed for each folder.

If a folder needs sorting, a temporary file containing the sorted folder is created; mailsort will try to create this file first in the directory where the folder resides, then (if the folder is a symbolic link) in the directory containing the symbolic link, and then in the fall-back temporary directory. The temporary file then replaces the original, if possible by renaming, otherwise by copying the temporary file over the original and deleting the temporary file.

"mbox" format files consist of possibly non-message material at the start of the file, and then at least one message that begins with a "From" line. This consists of the word `From', a space, followed by a return address, followed by anything, followed by a date in the format returned by the ctime(3) library routine, optionally with a three-letter time zone indicator between the time and the year. To cater for the version of mailx which ships with Solaris 2.x, the seconds field of the time may be omitted. Here is an example of a valid "From" line:

    From person@example.org Wed Dec 16 12:01:45 GMT 1998

OPTIONS

-d Display additional information for debugging purposes.
-h Display a brief help message.
-L Show the software license.
-r Reverse the order of sorting: the newest message in each folder will be placed first; the oldest, last.
-v Verbose mode.  Show the progress of the program.

PREREQUISITES
Now needs at least perl 5, since versions from 1.25 use Getopt::Std instead of getopts.pl.

/bin/cp is used if rename() is not successful.

EXAMPLES
    mailsort -v myfolder
    mailsort Mail/work inbox Mail/people/*
    cat /var/spool/mail/* | mailsort > allmail

ENVIRONMENT
TMPDIR    The last-resort location for the temporary file, if
the preferred directories are not writable. If not defined, /tmp is used instead.

FILES
A temporary file for every folder which needs sorting.

CAVEATS
Performance across NFS-mounted partitions is unknown, feedback would be welcome. People have not reported any NFS-related problems, so I expect no problems.

Only tested on Unix-like systems, but the only OS dependency should be that /bin/cp is used if rename() is not successful.

mailsort is intended to be fast and robust, but I cannot make any guarantees about its correctness. If you absolutely can't afford a mail folder being corrupted, make a copy of it before sorting it.

BUGS
The time zone is ignored during sorting. There is some controversy whether it should be used, since the "From" line is rumoured to supposedly contain a localized form of the time of arrival of the message. Timezone names are also nonstandard.

A system() call to "cp" is used to copy the temporary file across when rename() is not sufficient. This would perhaps be more elegantly done inside mailsort, though performance might suffer. (And what about interrupts?).

SEE ALSO
Mail(1), mailx(1), mail(1), ctime(3), mutt(1), elm(1), pine(1), perl(1), gawk(1).

AUTHOR
Copyright 1994-2004 Andras Salamon "<andras@dns.net>".

HISTORY
The inspiration for mailsort came from the gawk-ish script mboxsort, by Roman Czyborra, who also provided useful feedback on two early versions of mailsort.

When originally writing this program I was aware of one other script to sort mailboxes: sortmail (posted by Christopher Thomas to "alt.sources" on 26 June 1993).

During 1998, Daniel E. Singer wrote an article for "USENIX ;login:" magazine which covered archiving and sorting mail. This is available from: http://www.usenix.org/publications/login/1998-8/toolman.html

AVAILABILITY
The latest version of mailsort is available from http://www.dns.net/dist/mailsort/ and also from CPAN, at http://www.cpan.org/authors/id/A/AZ/AZS/mailsort/ and in http://www.cpan.org/scripts/Mail/ .

SCRIPT CATEGORIES
Mail