3 # Move old mail messages between queues by calling re-mqueue.pl.
5 # movemail.pl [config-script]
7 # Default config script is /usr/local/etc/movemail.conf.
9 # Graeme Hewson <graeme.hewson@oracle.com>, June 2000
14 # Load external program as subroutine to avoid
15 # compilation overhead on each call
19 or die "Filename not specified";
20 my $len = (stat($fn))[7]
21 or die "Can't stat $fn: $!";
23 or die "Can't open $fn: $!";
25 read PROG, $prog, $len
26 or die "Can't read $fn: $!";
29 'return sub { my @ARGV = @_; $0 = $fn; no strict;',
39 # Load and eval config script
41 my $conffile = shift || "/usr/local/etc/movemail.conf";
42 my $len = (stat($conffile))[7]
43 or die "Can't stat $conffile: $!";
44 open CONF, "< $conffile"
45 or die "Can't open $conffile: $!";
47 read CONF, $conf, $len
48 or die "Can't read $conffile: $!";
50 use vars qw(@queues $subqbase @ages $remqueue $lockfile);
54 print "$progname: there must be at least two queues\n";
58 if ($#ages != ($#queues - 1)) {
59 print "$progname: wrong number of ages (should be one less than number of queues)\n";
63 # Get lock or exit quietly. Useful when running from cron.
66 open LOCK, ">>$lockfile"
67 or die "Can't open lock file: $!";
68 unless (flock LOCK, $LOCK_EX|$LOCK_NB) {
74 my $remsub = loadsub($remqueue);
76 # Go through directories in reverse order so as to check spool files only once
78 for (my $n = $#queues - 1; $n >= 0; $n--) {
79 unless ($ages[$n] =~ /^\d+$/) {
80 print "$progname: invalid number $ages[$n] in ages array\n";
83 unless ($lastage < 0 || $ages[$n] < $lastage) {
84 print "$progname: age $lastage is not > previous value $ages[$n]\n";
90 opendir(DIR, $queues[$n])
91 or die "Can't open $queues[$n]: $!";
92 foreach $subdir ( grep { /^$subqbase/ } readdir DIR) {
93 &$remsub("$queues[$n]/$subdir", "$queues[$n+1]/$subdir",
98 # Not using subdirectories
99 &$remsub($queues[$n], $queues[$n+1], $ages[$n]);