d0d307
#!/usr/bin/perl
d0d307
#
d0d307
# Usage:	cat mailbox.txt | formail -s cpmsg 
d0d307
#
d0d307
#		where 'cpmsg' is the name of this script
d0d307
#
d0d307
# Purpose:	Called by formail once for each mail message in a Berkeley-
d0d307
#		format mailbox
d0d307
#
d0d307
#$Id: cpmsg,v 1.1 2004/02/04 12:59:42 karsten Exp $
d0d307
d0d307
$maildir  = "$ARGV[0]";
d0d307
if (!$maildir) { die "Usage: $0 $maildir"; }
d0d307
d0d307
# Formail increments this number for each message. The 
d0d307
# leading "0"'s must be removed (e.g. 001 becomes 1)
d0d307
d0d307
$filenum  = ($ENV{FILENO} - 0) + 1;
d0d307
d0d307
open (OUTFILE,">$maildir/$filenum.");
d0d307
while (<stdin>) {
d0d307
    chop;
d0d307
    print OUTFILE "$_\015\012";  # Add CRLF to each line!
d0d307
}
d0d307
close OUTFILE;
d0d307