/[cvs]/nfo/perl/scripts/dispatchmail/recieveMail
ViewVC logotype

Diff of /nfo/perl/scripts/dispatchmail/recieveMail

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by joko, Mon Oct 21 12:16:31 2002 UTC revision 1.3 by joko, Mon Oct 21 12:22:55 2002 UTC
# Line 2  Line 2 
2    
3  # ==========================================================================  # ==========================================================================
4  #  #
5  # recieveMail v0.02  # recieveMail v0.03
6    #   a simple mail filter done in perl with CPAN-module "Mail::Audit"
7    #
8  #  #
9    # 2002-10-14, joko@netfrag.org
10    #   + $LOGFILE is used now (recievemail.log)
11    #   + tracing (uses $LOGFILE)
12    #   + checks delivery path for existance,
13    #     changes $LOGFILE if needed
14    #  
15    # 2002-07-17, joko@netfrag.org
16    #   + added filtering by target (destination-routing)
17    #     (looks in "to", "cc" and "bcc")
18    #  
19  # 2001-12-05, joko@netfrag.org  # 2001-12-05, joko@netfrag.org
20  #   a simple mail filter done in perl with CPAN-module "Mail::Audit"  #   + initial internal release
 #   more to come ...  
21  #   TODO:  #   TODO:
22  #   - more sophisticated filtering  #   - more sophisticated filtering
23  #   - configuration-comfort (use arrays and hashes, no "matching-code-worm")  #   - configuration-comfort (use arrays and hashes, no "matching-code-worm")
24  #   - Html-Gui  #   - Html-Gui to define rules
25    #   - rule base located in LDAP (local delivery routing)
26  #  #
 # 2002-07-17, joko@netfrag.org  
 #   + added filtering by target (looks in "to", "cc" and "bcc")  
 #    
27  # ==========================================================================  # ==========================================================================
28    
29  use strict;  use strict;
30    # don't use warnings;
31    
32  # ----------------------------------------------------------  # ----------------------------------------------------------
33  # declare and initialize some variables  # declare and initialize some variables
34  # these are mostly directories for routing our mail to  # these are mostly directories for routing our mail to
35  my $HOME = "/home/joko/virtual/home/joko_mail/";  my $HOME = "/home/joko/virtual/joko_mail";
36  my $MAILDIR = "$HOME/Mail";  my $MAILDIR = "$HOME/Mail";
37  my $LOGFILE = "$MAILDIR/procmail.log";  my $LOGFILE = "$MAILDIR/recievemail.log";
38  my $LOCKFILE = "$HOME/.procmail.lockfile";  my $LOCKFILE = "$HOME/.procmail.lockfile";
39  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbox";  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbox";
40    my $DEBUG = 0;
41    my $TRACE = 1;
42    
43    if (! -e $HOME) {
44      $LOGFILE = "log/recievemail-emerg.log";
45      my $msg = "delivery failed, base directory $HOME does not exist";
46      open(FH, '>>' . $LOGFILE);
47      print FH $msg, "\n";
48      close(FH);
49      die($msg);
50    }
51    
52  # ----------------------------------------------------------  # ----------------------------------------------------------
53  #                       main  #                       main
# Line 39  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbo Line 59  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbo
59    # "jump" into processing of new incoming mail and get a "handler" to this mail    # "jump" into processing of new incoming mail and get a "handler" to this mail
60    my $incoming = Mail::Audit->new;    my $incoming = Mail::Audit->new;
61    
62      my $from    = $incoming->from;
63      my $to      = $incoming->to;
64      my $subject = $incoming->subject;
65    
66      chomp($from);
67      chomp($to);
68      chomp($subject);
69    
70      # - - - - - - - - - - - - - - - - - - - -
71      #             tracing mail
72      # - - - - - - - - - - - - - - - - - - - -
73      sub s2f {
74        my $str = shift;
75        open(FH, '>>' . $LOGFILE);
76        print FH $str, "\n";
77        close(FH);
78      }
79      if ($TRACE) {
80        s2f("Mail from $from to $to");
81        s2f("Subject: $subject");
82      }
83    
84    # - - - - - - - - - - - - - - - - - - - -    # - - - - - - - - - - - - - - - - - - - -
85    #             process mail    #             processing mail
86    # - - - - - - - - - - - - - - - - - - - -    # - - - - - - - - - - - - - - - - - - - -
87    
88    sub compareTarget {    sub compareTarget {
# Line 52  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbo Line 94  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbo
94      return $ok;      return $ok;
95    }    }
96    
97      sub jaccept {
98        my $deliver_to = shift;
99        # TODO: tracing, debugging
100        if ($TRACE) {
101          s2f("deliver to: $deliver_to");
102        }
103        $incoming->accept($deliver_to);
104      }
105    
106    # -----    # -----
107    # source-routing    # source-routing
108    #if ($incoming->from =~ /root\@smtp\.f7x\.net/i) {    #if ($incoming->from =~ /root\@smtp\.f7x\.net/i) {
109    #  $incoming->accept("$MAILDIR/SORTED/netfrag.org/Current/status-ns1.f7x.net");    #  $incoming->accept("$MAILDIR/SORTED/netfrag.org/Current/status-ns1.f7x.net");
110    #}    #}
111    if ($incoming->from =~ /(root|admin)\@cashew\.netfrag\.org/i) {    if ($incoming->from =~ /(root|admin)\@cashew\.netfrag\.org/i) {
112      $incoming->accept("$MAILDIR/SORTED/netfrag.org/Status/cashew.netfrag.org");      jaccept("$MAILDIR/SORTED/netfrag.org/Status/cashew.netfrag.org");
113    }    }
114    if ($incoming->from =~ /(root|admin)\@quepasa\.netfrag\.org/i) {    if ($incoming->from =~ /(root|admin)\@quepasa\.netfrag\.org/i) {
115      $incoming->accept("$MAILDIR/SORTED/netfrag.org/Status/quepasa.netfrag.org");      jaccept("$MAILDIR/SORTED/netfrag.org/Status/quepasa.netfrag.org");
116    }    }
117    if ($incoming->from =~ /(root|service|netsaint)\@h1\.service\.netfrag\.org/i) {    if ($incoming->from =~ /(root|service|netsaint)\@h1\.service\.netfrag\.org/i) {
118      $incoming->accept("$MAILDIR/SORTED/netfrag.org/Status/h1.service.netfrag.org");      jaccept("$MAILDIR/SORTED/netfrag.org/Status/h1.service.netfrag.org");
119    }    }
120    
121    
122    # -----    # -----
123    # source && destination - routing    # source && destination - routing
124    if ($incoming->from =~ /andreas\.motl\@ilo\.de/ && compareTarget('joko\@netfrag\.org')) {    if ($incoming->from =~ /andreas\.motl\@ilo\.de/ && compareTarget('joko\@netfrag\.org')) {
125      $incoming->accept("$MAILDIR/SORTED/netfrag.org/Info");      jaccept("$MAILDIR/SORTED/netfrag.org/Info");
126    }    }
127    
128    
# Line 82  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbo Line 133  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbo
133    my $bool_from_kolumnen_de = ($incoming->to =~ m/kolumnen\.de/i);    my $bool_from_kolumnen_de = ($incoming->to =~ m/kolumnen\.de/i);
134    my $bool_from_strixner = ($incoming->to =~ m/strixner\@web\.de/i);    my $bool_from_strixner = ($incoming->to =~ m/strixner\@web\.de/i);
135    if ($bool_ilo || $bool_ilo_news1 || $bool_from_kolumnen_de || $bool_from_strixner) {    if ($bool_ilo || $bool_ilo_news1 || $bool_from_kolumnen_de || $bool_from_strixner) {
136      $incoming->accept("$MAILDIR/SORTED/ilo.de/Inbox");      jaccept("$MAILDIR/SORTED/ilo.de/Inbox");
137    }    }
138    
139    if ($incoming->to =~ /web\.de/i) {    if ($incoming->to =~ /web\.de/i) {
140      $incoming->accept("$MAILDIR/SORTED/web.de/Current/Inbox");      jaccept("$MAILDIR/SORTED/web.de/Current/Inbox");
141    }    }
142    if ($incoming->to =~ /wor\.net/i) {    if ($incoming->to =~ /wor\.net/i) {
143      $incoming->accept("$MAILDIR/SORTED/wor.net/Current/Inbox");      jaccept("$MAILDIR/SORTED/wor.net/Current/Inbox");
144    }    }
145    if ($incoming->to =~ /netfrag\.org/i || $incoming->to =~ /archivists-talk\@yahoogroups\.com/) {    if ($incoming->to =~ /netfrag\.org/i || $incoming->to =~ /archivists-talk\@yahoogroups\.com/) {
146      $incoming->accept("$MAILDIR/SORTED/netfrag.org/Inbox");      jaccept("$MAILDIR/SORTED/netfrag.org/Inbox");
147    }    }
148    
149    # - - - - - - - - - - - - - - - - - - - -    # - - - - - - - - - - - - - - - - - - - -
# Line 104  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbo Line 155  my $DEFAULT = "$MAILDIR/SORTED/misc/Inbo
155  # $incoming->reject;  # $incoming->reject;
156    
157  # catch all mails and route them to a "DEFAULT"-inbox  # catch all mails and route them to a "DEFAULT"-inbox
158  $incoming->accept($DEFAULT);  jaccept($DEFAULT);
159    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed