7 unshift(@INC, $ENV{'DELIVERPATH'});
8 require 'audit.pl' || die "$program: cannot include audit.pl: $@";
9 require 'mh.pl' || die "$program: cannot include mh.pl: $@";
17 '-log +folder', # defaults to +log
22 '-src +folder', # defaults to current folder
31 defined($SW{'help'}) && do {
32 print "syntax: $program [msgs] [switches]\n";
38 @args = (defined(@MSGS) ? @MSGS : @ARGV);
41 $logdir = $SW{'log'} || $MH{'logdir'} || "+log";
42 ($logdir = '+' . $logdir) if ($logdir !~ /\+/);
43 $folder = `mhpath cur`; chop $folder; $folder =~ s|/\d+$||;
44 $folder = $SW{'src'} if defined($SW{'src'});
45 ($folder = '+' . $folder) if ($folder !~ /\+/);
48 $SW{'file'} = "$MH{'path'}/draft" if defined($SW{'draft'});
49 if (defined($SW{'file'})) {
52 @paths = `mhpath $folder @args`; chop @paths;
57 for ('link', 'nolink', 'preserve', 'nopreserve') {
58 push(@refileargs, "-$_") if defined($SW{$_});
60 push(@refileargs, "-rmmproc", $SW{'rmmproc'}) if defined($SW{'rmmproc'});
63 foreach $msg (@paths) {
64 open(MESSAGE, "< $msg") || next;
66 &local_parse_message(MESSAGE);
69 # if -from was specified use the From line; if -to is specified use
72 $header = $headers{'from'} if ($program eq "refilefrom");
73 $header = $headers{'to'} if ($program eq "refileto");
74 $header = $header . ',' . $headers{'cc'} if
75 (($program eq "refileto") && defined($headers{'cc'}));
78 foreach $addr (split(',', $header)) {
79 ($friendly, $address, $name, $org) = &parse_email_address($addr);
80 $org = "local" if ($org eq "unknown");
81 push(@nfolders, "$logdir/$org/$name");
85 foreach $folder (@nfolders) {
86 $fpath = `mhpath $folder`; chop $fpath;
87 if (-d $fpath || ! &make_mhpath($fpath)) {
88 push(@mfolders, $folder);
90 warn "cannot make directory $fpath: $!\n";
94 print "refile @refileargs -file $msg @mfolders\n" if
95 (@mfolders && defined($SW{'verbose'}));
96 system "refile -file $msg @mfolders" if
97 (@mfolders && !defined($SW{'debug'}));
104 # Subroutine local_parse_message
105 # A simplified version of parse_message that does
106 # not care about the body of the message
108 sub local_parse_message {
110 local($header, $body, $mheader);
112 $/ = ''; # read input in paragraph mode
121 # fill out the headers associative array with fields from the mail
126 @lines = split('\n');
128 /^(\w*):\s*(.*)/ && do {
130 $mheader =~ tr/A-Z/a-z/;
131 if (($mheader eq "cc" || $mheader eq "to") && $headers{$mheader}) {
132 $headers{$mheader} .= ", $2";
134 $headers{$mheader} = $2;