diff -urN mharc-0.7.3/bin/filter-maildir maildir/mharc-0.7.3/bin/filter-maildir --- mharc-0.7.3/bin/filter-maildir 1969-12-31 16:00:00.000000000 -0800 +++ maildir/mharc-0.7.3/bin/filter-maildir 2006-04-18 00:14:13.000000000 -0700 @@ -0,0 +1,318 @@ +#!/usr/bin/perl +##--------------------------------------------------------------------------## +## File: +## $Id: filter-spool,v 1.11 2002/09/27 05:01:07 ehood Exp $ +## Description: +## Script to grab maildir and filter mail to raw mbox archives. +##--------------------------------------------------------------------------## +## Copyright (C) 2002 Earl Hood +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +## 02111-1307, USA +##--------------------------------------------------------------------------## + +package MHArc::filter_maildir; + +##--------------------------------------------------------------------------## +# +BEGIN { die qq/CGI use FORBIDDEN!\n/ if (defined($ENV{'GATEWAY_INTERFACE'})); } +my $Dir; BEGIN { $Dir = `dirname $0`; chomp $Dir; } +use lib "$Dir/../lib"; # Add relative lib to search path +# +##--------------------------------------------------------------------------## +# +use MHArc::Config; +my $config = MHArc::Config->load("$Dir/../lib/config.sh"); +# +##--------------------------------------------------------------------------## + + +use Getopt::Long; +use MHArc::Util qw( cmd run_prg usage ); + +my @_term_sigs = qw( + ABRT ALRM BUS FPE HUP ILL INT IOT PIPE POLL PROF QUIT SEGV + TERM TRAP USR1 USR2 VTALRM XCPU XFSZ +); + +my $Procmail = $config->{'PROCMAIL'} || 'procmail'; +my $Lockfile = $config->{'LOCKFILE'} || 'lockfile'; +my $Formail = $config->{'FORMAIL'} || 'formail'; + +my $TmpSpool = '.newmail'; +my $TmpSpoolLock = $TmpSpool.'.lock'; + +MAIN: { + # Make sure umask is set to make things readable by default + umask 022; + + # Grap command-line options + my %opt = ( ); + my $clstatus = GetOptions(\%opt, + 'verbose!', + 'home=s', + 'html-dir=s', + 'is-spool!', + 'log-dir=s', + 'lock-timeout=i', + 'mail=s', + 'mbox-dir=s', + 'procmailrc=s', + 'procmailvars=s', + + 'help', + 'man', + ); + usage(0) unless $clstatus; + usage(1) if $opt{'help'}; + usage(2) if $opt{'man'}; + + my $verbose = $opt{'verbose'}; + if ($verbose) { + $MHArc::Util::ECHO_CMDS = 1; + } + + my $home = $opt{'home'} || + $config->{'SW_ROOT'} || + "$Dir/.."; + my $html_dir = $opt{'html-dir'} || + $config->{'HTML_DIR'} || + join('/', $home, 'html'); + my $log_dir = $opt{'log-dir'} || + $config->{'LOG_DIR'} || + join('/', $home, 'log'); + my $mbox_dir = $opt{'mbox-dir'} || + $config->{'MBOX_DIR'} || + join('/', $home, 'mbox'); + my $procmailrc = $opt{'procmailrc'} || + $config->{'PROCMAILRC'} || + join('/', $home, 'procmailrc.mharc'); + my $procmailvars = $opt{'procmailvars'} || + $config->{'PROCMAILVARS'} || + ""; + my $mail = $opt{'mail'} || + $config->{'ORGMAIL'} || + join('/', '/var/mail', $ENV{'LOGNAME'}); + my $lock_to = $opt{'lock-timeout'} || + $config->{'ORGMAIL_LOCK_TIMEOUT'} || + 3600; + + die qq/ERROR: "$home" not a directory/ + if (! -d $home); + die qq/ERROR: Unable to change directory to "$home": $!/ + unless chdir($home); + + # Make sure certain directories exist + cmd('mkdir', '-p', $log_dir, $mbox_dir, $html_dir); + + # Check that we have data to process + die qq/ERROR: "$mail" not a directory/ + if (! -d $mail); + my $have_new = 0; + opendir(DIR,$mail) or die qq/ERROR: "Couldn't opendir $mail: $!"\n/; + while (defined($file = readdir(DIR))) + { + if(-f "$mail/$file") + { + $have_new = 1; + last; + } + } + closedir(DIR); + + if($have_new == 0) + { + print qq/"$mail" has nothing\n/ if $verbose; + exit 1; + } + + if (cmd("$Lockfile -r5 -l$lock_to $TmpSpoolLock 2>/dev/null") != 0) + { + print qq/Unable to obtain lock, exiting/ if $verbose; + exit 1; + } + + eval + { + local @SIG{@_term_sigs} = (\&clean_lock) x scalar(@_term_sigs); + if ($have_new) + { + run_prg($Lockfile, "-l$lock_to", "$mail.lock"); + + # now that we're not going to be stomping on ourselves..... + if(!opendir(DIR,$mail)) + { + warn qq/Warning: Couldn't opendir "$mail": "$!"\n/; + } + else + { + while (defined(my $file = readdir(DIR))) + { + if(-f "$mail/$file") + { + if(cmd("$Formail -s $Procmail $procmailrc $procmailvars < '$mail/$file'") == 0) + { + unlink("$mail/$file"); + } + } + } + closedir(DIR); + + # now that we've done our work, unlock + unlink("$mail.lock") || + warn qq/Warning: Unable to remove "$mail.lock": $!\n/; + } + } + }; + clean_lock(); + if ($@) { + die $@, "\n"; + } + +} # End: MAIN + +##---------------------------------------------------------------------------## + +sub clean_lock { + unlink($TmpSpoolLock); +} + +##---------------------------------------------------------------------------## +__END__ + +=head1 NAME + +filter-maildir - Filter incoming mail from a maildir into raw archives + +=head1 SYNOPSIS + + filter-maildir + filter-maildir [options] + +=head1 DESCRIPTION + +This program is part of mharc and has the responsibility of filtering +incoming mail from a maildir into the raw message archives. This +script is called by the L script before +L is invoked. + +=head1 OPTIONS + +This program is generally called without any command-line options +since it will read Cmharc-rootE/lib/config.sh> for all configurable +options. However, the following command-line options are +available: + +=over + +=item C<-help> + +Print out usage information. + +=item C<-home> I + +Root pathname of archiving software and data. If not specified, +C variable in C is used, else the parent directory +that contains this program is used. + +=item C<-html-dir> I + +Root pathname containing HTML archives. If not specified, +C variable in C is used, else C/html> +is used. + +B This program does not do any processing of the HTML archives. +This option is used to insure that the HTML archive root directory +exists for subsequent processing by other mharc scripts. + +=item C<-lock-timeout> I + +The age of a lock before it is forceably removed. This is used +to help deal with stale locks. + +If this option is not specified, C variable in +C is used, else C<3600> is used. + +=item C<-log-dir> I + +Root pathname to place log files. If not specified, +C variable in C is used, else C/log> +is used. + +=item C<-mail> I + +Pathname to incoming mailbox file. +If not specified, C variable in C is used, +else C is used, where C<$LOGNAME> represents the +value of the C environment variable. + +=item C<-man> + +Print out entire manpage. + +=item C<-mbox-dir> I + +Root pathname containing raw mailbox archives. If not specified, +C variable in C is used, else C/mbox> +is used. + +=item C<-procmailrc> I + +Pathname to procmailrc file to use when filtering mail. +If not specified, C variable in C is used, +else C/procmailrc.mharc> is used. + +=item C<-procmailvars> I + +Additional variables to pass into C. +If not specified, C variable in C is used. + +=item C<-verbose> + +Print out status messages. + +=back + +=head1 EXIT VALUES + +If there was mail to process, and no errors occurred during processing, +a zero exit status will be returned. Otherwise, a non-zero exit status +will be returned. + +=head1 FILES + +=over + +=item Cmharc-rootE/lib/config.sh> + +Main configuration file for mharc. + +=back + +=head1 VERSION + +$Id: filter-spool,v 1.11 2002/09/27 05:01:07 ehood Exp $ + +=head1 AUTHOR + +Earl Hood, earl@earlhood.com + +This program is part of the mharc archiving system and comes with +ABSOLUTELY NO WARRANTY and may be copied only under the terms of +the GNU General Public License, which may be found in the mharc +distribution. + +=cut + diff -urN mharc-0.7.3/bin/read-maildir maildir/mharc-0.7.3/bin/read-maildir --- mharc-0.7.3/bin/read-maildir 1969-12-31 16:00:00.000000000 -0800 +++ maildir/mharc-0.7.3/bin/read-maildir 2006-04-18 00:06:27.000000000 -0700 @@ -0,0 +1,166 @@ +#!/usr/bin/perl +##--------------------------------------------------------------------------## +## File: +## $Id: read-mail,v 1.10 2002/09/15 03:33:08 ehood Exp $ +## Description: +## Read maildir and archive messages. +##--------------------------------------------------------------------------## +## Copyright (C) 2001 Earl Hood +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +## 02111-1307, USA +##--------------------------------------------------------------------------## + +package MHArc::read_maildir; + +##--------------------------------------------------------------------------## +# +BEGIN { die qq/CGI use FORBIDDEN!\n/ if (defined($ENV{'GATEWAY_INTERFACE'})); } +my $Dir; BEGIN { $Dir = `dirname $0`; chomp $Dir; } +use lib "$Dir/../lib"; # Add relative lib to search path +# +##--------------------------------------------------------------------------## +# +use MHArc::Config; +my $config = MHArc::Config->load("$Dir/../lib/config.sh"); +# +##--------------------------------------------------------------------------## + + +use Getopt::Long; +use MHArc::Util qw( ch_dir cmd usage ); + +MAIN: { + # Grap command-line options + my %opt = ( ); + my $clstatus = GetOptions(\%opt, + 'force!', + 'home=s', + 'verbose!', + + 'help', + 'man', + ); + usage(0) unless $clstatus; + usage(1) if $opt{'help'}; + usage(2) if $opt{'man'}; + + my $verbose = $opt{'verbose'}; + if ($verbose) { + $MHArc::Util::ECHO_CMDS = 1; + } + + my $home = $opt{'home'} || + $config->{'SW_ROOT'} || + "$Dir/.."; + my $force = $opt{'force'}; + + ch_dir($home) || + die qq/ERROR: Unable to change directory to "$home": $!\n/; + + if (-e '.noarchive') { + print "Archiving is currently disabled\n" if $verbose; + if (!$force) { + exit 0; + } + print "However, -force specified, so continuing...\n" if $verbose; + } + + my @cmd_args = (); + push(@cmd_args, '-verbose') if $verbose; + if (cmd('./bin/filter-maildir', @cmd_args) == 0) { + cmd('./bin/web-archive', @cmd_args); + } +} + +##---------------------------------------------------------------------------## +__END__ + +=head1 NAME + +read-maildir - Archive incoming mail + +=head1 SYNOPSIS + + read-maildir + read-maildir [options] + +=head1 DESCRIPTION + +This program is part of mharc and is the main program for archiving +mail. It is generally called via cron. + +This program does very little itself, but it invokes other mharc +scripts to do all the work. + +If the file C<.noarchive> exists in mharc root directory, then this +program will do nothing and exit (unless the C<-force> option is +specified). This is to allow one to disable incoming mail processing +while performing administrative tasks. + +=head1 OPTIONS + +This program is generally called without any command-line options +since it will read Cmharc-rootE/lib/config.sh> for any configurable +options. Regardless, the following command-line options are +available: + +=over + +=item C<-help> + +Print out usage information. + +=item C<-home> I + +Root pathname of archiving software and data. If not specified, +C variable in C is used, else the parent directory +that contains this program is used. + +=item C<-man> + +Print out entire manpage. + +=item C<-verbose> + +Print out status messages. + +=back + +=head1 FILES + +=over + +=item C/lib/config.sh> + +Main configuration file for mharc. + +=back + +=head1 VERSION + +$Id: read-mail,v 1.10 2002/09/15 03:33:08 ehood Exp $ + +=head1 AUTHOR + +Earl Hood, earl@earlhood.com + +This program is part of the mharc archiving system and comes with +ABSOLUTELY NO WARRANTY and may be copied only under the terms of +the GNU General Public License, which may be found in the mharc +distribution. + +=cut + diff -urN mharc-0.7.3/etc/crontab.in.dist maildir/mharc-0.7.3/etc/crontab.in.dist --- mharc-0.7.3/etc/crontab.in.dist 2003-08-09 11:02:42.000000000 -0700 +++ maildir/mharc-0.7.3/etc/crontab.in.dist 2006-04-19 23:21:14.000000000 -0700 @@ -3,8 +3,17 @@ # an hourly basis. However, for one day of the week new message # processing is not done to allow for cleanup. # -57 * * * 1-6 @@SW_ROOT@@/bin/logcmd -log @@SW_ROOT@@/log/cron.log -- @@SW_ROOT@@/bin/read-mail -57 0,4-23 * * 0 @@SW_ROOT@@/bin/logcmd -log @@SW_ROOT@@/log/cron.log -- @@SW_ROOT@@/bin/read-mail +# Note that there are two sets of mail reading jobs, one for +# mbox and one for maildir. You only want to enable one set. +# +# Use the following two lines if your MTA spools to mbox +#57 * * * 1-6 @@SW_ROOT@@/bin/logcmd -log @@SW_ROOT@@/log/cron.log -- @@SW_ROOT@@/bin/read-mail +#57 0,4-23 * * 0 @@SW_ROOT@@/bin/logcmd -log @@SW_ROOT@@/log/cron.log -- @@SW_ROOT@@/bin/read-mail +# +# Use the following two lines if your MTA spools to maildir +#57 * * * 1-6 @@SW_ROOT@@/bin/logcmd -log @@SW_ROOT@@/log/cron.log -- @@SW_ROOT@@/bin/read-maildir +#57 0,4-23 * * 0 @@SW_ROOT@@/bin/logcmd -log @@SW_ROOT@@/log/cron.log -- @@SW_ROOT@@/bin/read-maildir +# 57 1 * * 0 @@SW_ROOT@@/bin/logcmd -log @@SW_ROOT@@/log/cron.log -- @@SW_ROOT@@/bin/gc-search-indexes 57 3 * * 0 @@SW_ROOT@@/bin/logcmd -log @@SW_ROOT@@/log/cron.log -- @@SW_ROOT@@/bin/compress-mboxes # diff -urN mharc-0.7.3/install.pl maildir/mharc-0.7.3/install.pl --- mharc-0.7.3/install.pl 2003-08-09 10:48:34.000000000 -0700 +++ maildir/mharc-0.7.3/install.pl 2006-04-17 23:56:09.000000000 -0700 @@ -63,12 +63,14 @@ bin/compress-mboxes bin/config-check bin/extract-mesg-date + bin/filter-maildir bin/filter-spool bin/gc-search-indexes bin/mbox-month-pack bin/mh-month-pack bin/mhonarc-check bin/mk-procmailrc + bin/read-maildir bin/read-mail bin/web-archive ));