inboxfer

inboxfer is a Perl script that was used in Chapter 9 to move messages from a Berkeley format inbox (e.g., /var/mail/johndoe) into a Cyrus inbox. The script (shown in Example A-3) assumes that the Cyrus mailbox already exists and that formail   is available on the machine where the script runs.[87] inboxfer takes the name of the file containing usernames, one per line, as input.

Example A-3. inboxfer

#!/usr/local/bin/perl

## Purpose: Extract messages from /var/mail mailbox 
##          and populate the Cyrus INBOX.

$scripts   = "/home/cyrus/bin";       # Location of this script
$mailstore = "/var/spool/imap/user";  # Cyrus mailstore
$oldspool  = "/var/oldmail";          # Old mail spool

$cmd       = "/usr/local/bin/formail -n 20 -s $scripts/cpmsg";

$users = "$ARGV[0]";
if (!$users) { die "Usage: $0 $users\\n"; }

open(USERS,"$users") || die "can't open $users";

while (<USERS>) {
    chop;
    $inbox = "$oldspool/$_";
    system("/usr/bin/cat $inbox | $cmd $mailstore/$_");
}

The system call pipes the contents of the incoming mail folder into a formail command. The formail command splits the folder up into separate mail messages and, in turn, pipes each mail message into another Perl script, cpmsg, for processing. cpmsg is the script that actually copies the message into the Cyrus mailbox. cpmsg is shown in Example A-4 .

formail increments an environment variable, FILENO, each time it finds a new message in the Berkeley folder. cpmsg takes advantage of the FILENO variable to come up with a unique numbering scheme ...

Get Managing IMAP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.