Fast registration of maildir -- script inside
Matthias Andree
matthias.andree at gmx.de
Mon Feb 10 03:34:15 CET 2003
Hi,
I've written a small Perl script that prints a whole maildir to stdout,
so you can easily register your whole maildir; this example assumes you
have a "spam" subfolder (Courier-IMAP/Sqwebmail style):
perl printmaildir.pl ~/Maildir/ | bogofilter -n
perl printmaildir.pl ~/Maildir/.spam | bogofilter -s
printmaildir.pl prints all mails from the cur and new directories,
adding From_ lines when missing and escaping existing From_ lines when
found in the body, so that the message count is correct.
This script has been committed to the CVS contrib/ section, a copy of it
is below.
Hope that helps somebody.
---------------------------------------------------------
#! /usr/bin/perl -w
# printmaildir.pl -- (C) 2003 by Matthias Andree
# This program reads a Maildir and prints in in UNIX mbox format on
# stdout. It is redistributable in accordance to the terms of the
# GNU GENERAL PUBLIC LICENSE V2
use strict;
use POSIX;
sub read_dir($ ) {
my $dir = shift;
my @list = ();
my $d;
foreach $d (qw/cur new/) {
opendir(DIR, $dir . "/$d") || die "can't opendir $dir/$d: $!";
push @list, grep { ! /^\./ && $_ =~ s|^|$dir/$d/|; } readdir(DIR);
closedir DIR;
}
foreach (@list) {
if (open F, $_) {
my $head = <F>;
my $last = $head;
if ($head !~ /^From /) {
print "From unknown\@example.invalid ", POSIX::ctime(time);
}
print $head;
while(<F>) {
$last = $_;
if (/^From /){
print ">$_";
} else {
print $_;
}
}
if ($last !~ /\n$/) {
print "\n";
}
close F;
} else { # open failed
warn "can't open $_: $!";
}
}
}
if (!@ARGV) { unshift @ARGV, "."; }
foreach(@ARGV) {
read_dir $_;
}
---------------------------------------------------------
--
Matthias Andree
More information about the Bogofilter
mailing list