mhonarc-users

Re: Mhonarcing individual maildir files

2005-07-14 13:09:23
[We have been experiencing mail delivery problems to list subscribers.
 I just noticed your message when scanning the list archives.]

On July 5, 2005 at 21:19, East Coast Coder wrote:

Is there a simple way to tell Mhonarc to only process particular
maildir files?  Ideally, I'd like to say: only process files written
in the past x minutes.

Is the time based upon the modtime of the file, or by some date
within the message data in the file?  If the latter, you could
use MSGEXCFILTER resource to do whatever custom exclusion you
want.  It does have the drawback where each file in the maildir
is opened.

If based on the modtime, you'll need to write a preprocessor.
The preproc could do stats on the files, and if in the time period you
want, create a mbox stream to stdout which can be fed into mhonarc.
For example:

  maildir-preproc | mhonarc -add [other-options-here] -- -

If '-' is specified as an input mail folder, mhonarc will read
mbox style input from standard input.  The '--' is needed to
terminate normal command-line option parsing.

It appears that "maildir-preproc" can be done with a simple
Perl script:

  my $time_threshold = 60 * $min;   # Need to define $min
  my $maildir        = shift @ARGV; # or set via some other way
  my $cur_time       = time;

  opendir(DIR, $maildir) ||
      die qq{Error: Unable to open "$maildir": $!};

  foreach my $f (readdir(DIR)) {
    # ... include filename check here if needed ...

    $modtime = (stat($f))[9];
    next  unless -f _;   # only process plain files

    if ($cur_time - $modtime < $time_threshold) {
      open(F, join('/', $maildir, $f)) ||
          die qq{Error: Unable to open "$maildir/$f": $!};

      # remove generation of "From " separator if file already contains
      # "From " line at the beginning.
      print STDOUT 'From - ', gmtime($modtime), "\n";

      # dump file to stdout
      while (<F>) {
        print STDOUT $_;
      }
      close(F);
  }
  closedir(DIR);


--ewh

<Prev in Thread] Current Thread [Next in Thread>