| 1 | #!/usr/bin/perl | #!/usr/bin/perl | 
| 2 |  |  | 
| 3 | # ========================================================================== | # ========================================================================== | 
| 4 | # a simple mail filter done in perl with CPAN-module "Mail::Audit" | # | 
| 5 | # more to come ... | # recieveMail v0.02 | 
| 6 | # TODO: | # | 
| 7 | # - more sophisticated filtering | # 2001-12-05, joko@netfrag.org | 
| 8 | # - configuration-comfort (use arrays and hashes, no "matching-code-worm") | #   a simple mail filter done in perl with CPAN-module "Mail::Audit" | 
| 9 | # - Html-Gui | #   more to come ... | 
| 10 | # 2001-12-05, amo@netfrag.org | #   TODO: | 
| 11 |  | #   - more sophisticated filtering | 
| 12 |  | #   - configuration-comfort (use arrays and hashes, no "matching-code-worm") | 
| 13 |  | #   - Html-Gui | 
| 14 |  | # | 
| 15 |  | # 2002-07-17, joko@netfrag.org | 
| 16 |  | #   + added filtering by target (looks in "to", "cc" and "bcc") | 
| 17 |  | # | 
| 18 | # ========================================================================== | # ========================================================================== | 
| 19 |  |  | 
|  |  |  | 
|  | # variables have to be declared! |  | 
| 20 | use strict; | use strict; | 
| 21 |  |  | 
| 22 | # ---------------------------------------------------------- | # ---------------------------------------------------------- | 
| 23 | # declare and initialize some variables | # declare and initialize some variables | 
| 24 | # these are mostly directories for routing our mail to | # these are mostly directories for routing our mail to | 
| 25 | my $HOME = "/home/amo/virtual/home/amo_mail/"; | my $HOME = "/home/joko/virtual/home/joko_mail/"; | 
| 26 | my $MAILDIR = "$HOME/Mail"; | my $MAILDIR = "$HOME/Mail"; | 
| 27 | my $LOGFILE = "$MAILDIR/procmail.log"; | my $LOGFILE = "$MAILDIR/procmail.log"; | 
| 28 | my $LOCKFILE = "$HOME/.procmail.lockfile"; | my $LOCKFILE = "$HOME/.procmail.lockfile"; | 
| 29 | my $DEFAULT = "$MAILDIR/UNSORTED/Current/Inbox"; | my $DEFAULT = "$MAILDIR/SORTED/misc/Inbox"; | 
| 30 |  |  | 
| 31 |  |  | 
| 32 | # ---------------------------------------------------------- | # ---------------------------------------------------------- | 
| 42 | # - - - - - - - - - - - - - - - - - - - - | # - - - - - - - - - - - - - - - - - - - - | 
| 43 | #             process mail | #             process mail | 
| 44 | # - - - - - - - - - - - - - - - - - - - - | # - - - - - - - - - - - - - - - - - - - - | 
| 45 | if ($incoming->to =~ /ilo\.de/) { |  | 
| 46 | $incoming->accept("$MAILDIR/SORTED/ilo.de/Current/Inbox"); | sub compareTarget { | 
| 47 |  | my $pattern = shift; | 
| 48 |  | my $ok = 0; | 
| 49 |  | $ok = 1 if ($incoming->to =~ m/$pattern/); | 
| 50 |  | $ok = 1 if ($incoming->cc =~ m/$pattern/); | 
| 51 |  | $ok = 1 if ($incoming->bcc =~ m/$pattern/); | 
| 52 |  | return $ok; | 
| 53 |  | } | 
| 54 |  |  | 
| 55 |  | # ----- | 
| 56 |  | # source-routing | 
| 57 |  | #if ($incoming->from =~ /root\@smtp\.f7x\.net/i) { | 
| 58 |  | #  $incoming->accept("$MAILDIR/SORTED/netfrag.org/Current/status-ns1.f7x.net"); | 
| 59 |  | #} | 
| 60 |  | if ($incoming->from =~ /(root|admin)\@cashew\.netfrag\.org/i) { | 
| 61 |  | $incoming->accept("$MAILDIR/SORTED/netfrag.org/Status/cashew.netfrag.org"); | 
| 62 |  | } | 
| 63 |  | if ($incoming->from =~ /(root|admin)\@quepasa\.netfrag\.org/i) { | 
| 64 |  | $incoming->accept("$MAILDIR/SORTED/netfrag.org/Status/quepasa.netfrag.org"); | 
| 65 |  | } | 
| 66 |  | if ($incoming->from =~ /(root|service|netsaint)\@h1\.service\.netfrag\.org/i) { | 
| 67 |  | $incoming->accept("$MAILDIR/SORTED/netfrag.org/Status/h1.service.netfrag.org"); | 
| 68 |  | } | 
| 69 |  |  | 
| 70 |  |  | 
| 71 |  | # ----- | 
| 72 |  | # source && destination - routing | 
| 73 |  | if ($incoming->from =~ /andreas\.motl\@ilo\.de/ && compareTarget('joko\@netfrag\.org')) { | 
| 74 |  | $incoming->accept("$MAILDIR/SORTED/netfrag.org/Info"); | 
| 75 |  | } | 
| 76 |  |  | 
| 77 |  |  | 
| 78 |  | # ----- | 
| 79 |  | # destination-routing | 
| 80 |  | my $bool_ilo = ($incoming->to =~ m/ilo\.de/i); | 
| 81 |  | my $bool_ilo_news1 = ($incoming->to =~ m/kritletter\@kbx\.de/i); | 
| 82 |  | my $bool_from_kolumnen_de = ($incoming->to =~ m/kolumnen\.de/i); | 
| 83 |  | my $bool_from_strixner = ($incoming->to =~ m/strixner\@web\.de/i); | 
| 84 |  | if ($bool_ilo || $bool_ilo_news1 || $bool_from_kolumnen_de || $bool_from_strixner) { | 
| 85 |  | $incoming->accept("$MAILDIR/SORTED/ilo.de/Inbox"); | 
| 86 | } | } | 
| 87 | if ($incoming->to =~ /web\.de/) { |  | 
| 88 |  | if ($incoming->to =~ /web\.de/i) { | 
| 89 | $incoming->accept("$MAILDIR/SORTED/web.de/Current/Inbox"); | $incoming->accept("$MAILDIR/SORTED/web.de/Current/Inbox"); | 
| 90 | } | } | 
| 91 |  | if ($incoming->to =~ /wor\.net/i) { | 
| 92 |  | $incoming->accept("$MAILDIR/SORTED/wor.net/Current/Inbox"); | 
| 93 |  | } | 
| 94 |  | if ($incoming->to =~ /netfrag\.org/i || $incoming->to =~ /archivists-talk\@yahoogroups\.com/) { | 
| 95 |  | $incoming->accept("$MAILDIR/SORTED/netfrag.org/Inbox"); | 
| 96 |  | } | 
| 97 |  |  | 
| 98 | # - - - - - - - - - - - - - - - - - - - - | # - - - - - - - - - - - - - - - - - - - - | 
| 99 |  |  | 
| 100 | # the default-handler: simply accept all mails and route them to "/var/spool/mail" | # the default-handler: simply accept all mails and route them to "/var/spool/mail" |