--- nfo/perl/scripts/dispatchmail/recieveMail 2002/10/21 12:16:31 1.2 +++ nfo/perl/scripts/dispatchmail/recieveMail 2002/10/21 12:22:55 1.3 @@ -2,32 +2,52 @@ # ========================================================================== # -# recieveMail v0.02 +# recieveMail v0.03 +# a simple mail filter done in perl with CPAN-module "Mail::Audit" +# # +# 2002-10-14, joko@netfrag.org +# + $LOGFILE is used now (recievemail.log) +# + tracing (uses $LOGFILE) +# + checks delivery path for existance, +# changes $LOGFILE if needed +# +# 2002-07-17, joko@netfrag.org +# + added filtering by target (destination-routing) +# (looks in "to", "cc" and "bcc") +# # 2001-12-05, joko@netfrag.org -# a simple mail filter done in perl with CPAN-module "Mail::Audit" -# more to come ... +# + initial internal release # TODO: # - more sophisticated filtering # - configuration-comfort (use arrays and hashes, no "matching-code-worm") -# - Html-Gui +# - Html-Gui to define rules +# - rule base located in LDAP (local delivery routing) # -# 2002-07-17, joko@netfrag.org -# + added filtering by target (looks in "to", "cc" and "bcc") -# # ========================================================================== use strict; +# don't use warnings; # ---------------------------------------------------------- # declare and initialize some variables # these are mostly directories for routing our mail to -my $HOME = "/home/joko/virtual/home/joko_mail/"; +my $HOME = "/home/joko/virtual/joko_mail"; my $MAILDIR = "$HOME/Mail"; -my $LOGFILE = "$MAILDIR/procmail.log"; +my $LOGFILE = "$MAILDIR/recievemail.log"; my $LOCKFILE = "$HOME/.procmail.lockfile"; my $DEFAULT = "$MAILDIR/SORTED/misc/Inbox"; +my $DEBUG = 0; +my $TRACE = 1; +if (! -e $HOME) { + $LOGFILE = "log/recievemail-emerg.log"; + my $msg = "delivery failed, base directory $HOME does not exist"; + open(FH, '>>' . $LOGFILE); + print FH $msg, "\n"; + close(FH); + die($msg); +} # ---------------------------------------------------------- # main @@ -39,8 +59,30 @@ # "jump" into processing of new incoming mail and get a "handler" to this mail my $incoming = Mail::Audit->new; + my $from = $incoming->from; + my $to = $incoming->to; + my $subject = $incoming->subject; + + chomp($from); + chomp($to); + chomp($subject); + + # - - - - - - - - - - - - - - - - - - - - + # tracing mail + # - - - - - - - - - - - - - - - - - - - - + sub s2f { + my $str = shift; + open(FH, '>>' . $LOGFILE); + print FH $str, "\n"; + close(FH); + } + if ($TRACE) { + s2f("Mail from $from to $to"); + s2f("Subject: $subject"); + } + # - - - - - - - - - - - - - - - - - - - - - # process mail + # processing mail # - - - - - - - - - - - - - - - - - - - - sub compareTarget { @@ -52,26 +94,35 @@ return $ok; } + sub jaccept { + my $deliver_to = shift; + # TODO: tracing, debugging + if ($TRACE) { + s2f("deliver to: $deliver_to"); + } + $incoming->accept($deliver_to); + } + # ----- # source-routing #if ($incoming->from =~ /root\@smtp\.f7x\.net/i) { # $incoming->accept("$MAILDIR/SORTED/netfrag.org/Current/status-ns1.f7x.net"); #} if ($incoming->from =~ /(root|admin)\@cashew\.netfrag\.org/i) { - $incoming->accept("$MAILDIR/SORTED/netfrag.org/Status/cashew.netfrag.org"); + jaccept("$MAILDIR/SORTED/netfrag.org/Status/cashew.netfrag.org"); } if ($incoming->from =~ /(root|admin)\@quepasa\.netfrag\.org/i) { - $incoming->accept("$MAILDIR/SORTED/netfrag.org/Status/quepasa.netfrag.org"); + jaccept("$MAILDIR/SORTED/netfrag.org/Status/quepasa.netfrag.org"); } if ($incoming->from =~ /(root|service|netsaint)\@h1\.service\.netfrag\.org/i) { - $incoming->accept("$MAILDIR/SORTED/netfrag.org/Status/h1.service.netfrag.org"); + jaccept("$MAILDIR/SORTED/netfrag.org/Status/h1.service.netfrag.org"); } # ----- # source && destination - routing if ($incoming->from =~ /andreas\.motl\@ilo\.de/ && compareTarget('joko\@netfrag\.org')) { - $incoming->accept("$MAILDIR/SORTED/netfrag.org/Info"); + jaccept("$MAILDIR/SORTED/netfrag.org/Info"); } @@ -82,17 +133,17 @@ my $bool_from_kolumnen_de = ($incoming->to =~ m/kolumnen\.de/i); my $bool_from_strixner = ($incoming->to =~ m/strixner\@web\.de/i); if ($bool_ilo || $bool_ilo_news1 || $bool_from_kolumnen_de || $bool_from_strixner) { - $incoming->accept("$MAILDIR/SORTED/ilo.de/Inbox"); + jaccept("$MAILDIR/SORTED/ilo.de/Inbox"); } if ($incoming->to =~ /web\.de/i) { - $incoming->accept("$MAILDIR/SORTED/web.de/Current/Inbox"); + jaccept("$MAILDIR/SORTED/web.de/Current/Inbox"); } if ($incoming->to =~ /wor\.net/i) { - $incoming->accept("$MAILDIR/SORTED/wor.net/Current/Inbox"); + jaccept("$MAILDIR/SORTED/wor.net/Current/Inbox"); } if ($incoming->to =~ /netfrag\.org/i || $incoming->to =~ /archivists-talk\@yahoogroups\.com/) { - $incoming->accept("$MAILDIR/SORTED/netfrag.org/Inbox"); + jaccept("$MAILDIR/SORTED/netfrag.org/Inbox"); } # - - - - - - - - - - - - - - - - - - - - @@ -104,4 +155,5 @@ # $incoming->reject; # catch all mails and route them to a "DEFAULT"-inbox -$incoming->accept($DEFAULT); +jaccept($DEFAULT); +