| 1 |
joko |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
# ========================================================================== |
| 4 |
joko |
1.2 |
# |
| 5 |
|
|
# recieveMail v0.02 |
| 6 |
|
|
# |
| 7 |
|
|
# 2001-12-05, joko@netfrag.org |
| 8 |
|
|
# a simple mail filter done in perl with CPAN-module "Mail::Audit" |
| 9 |
|
|
# more to come ... |
| 10 |
|
|
# 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 |
joko |
1.1 |
# ========================================================================== |
| 19 |
|
|
|
| 20 |
|
|
use strict; |
| 21 |
|
|
|
| 22 |
|
|
# ---------------------------------------------------------- |
| 23 |
|
|
# declare and initialize some variables |
| 24 |
|
|
# these are mostly directories for routing our mail to |
| 25 |
joko |
1.2 |
my $HOME = "/home/joko/virtual/home/joko_mail/"; |
| 26 |
joko |
1.1 |
my $MAILDIR = "$HOME/Mail"; |
| 27 |
|
|
my $LOGFILE = "$MAILDIR/procmail.log"; |
| 28 |
|
|
my $LOCKFILE = "$HOME/.procmail.lockfile"; |
| 29 |
joko |
1.2 |
my $DEFAULT = "$MAILDIR/SORTED/misc/Inbox"; |
| 30 |
joko |
1.1 |
|
| 31 |
|
|
|
| 32 |
|
|
# ---------------------------------------------------------- |
| 33 |
|
|
# main |
| 34 |
|
|
# ---------------------------------------------------------- |
| 35 |
|
|
|
| 36 |
|
|
# cry for our "Auditor" |
| 37 |
|
|
use Mail::Audit; |
| 38 |
|
|
|
| 39 |
|
|
# "jump" into processing of new incoming mail and get a "handler" to this mail |
| 40 |
|
|
my $incoming = Mail::Audit->new; |
| 41 |
|
|
|
| 42 |
|
|
# - - - - - - - - - - - - - - - - - - - - |
| 43 |
|
|
# process mail |
| 44 |
|
|
# - - - - - - - - - - - - - - - - - - - - |
| 45 |
joko |
1.2 |
|
| 46 |
|
|
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 |
joko |
1.1 |
} |
| 87 |
joko |
1.2 |
|
| 88 |
|
|
if ($incoming->to =~ /web\.de/i) { |
| 89 |
joko |
1.1 |
$incoming->accept("$MAILDIR/SORTED/web.de/Current/Inbox"); |
| 90 |
|
|
} |
| 91 |
joko |
1.2 |
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 |
joko |
1.1 |
# - - - - - - - - - - - - - - - - - - - - |
| 99 |
|
|
|
| 100 |
|
|
# the default-handler: simply accept all mails and route them to "/var/spool/mail" |
| 101 |
|
|
# $incoming->accept(); |
| 102 |
|
|
|
| 103 |
|
|
# if you want to reject all mails coming through to here, do a ... |
| 104 |
|
|
# $incoming->reject; |
| 105 |
|
|
|
| 106 |
|
|
# catch all mails and route them to a "DEFAULT"-inbox |
| 107 |
|
|
$incoming->accept($DEFAULT); |