Ang-st has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use DBI(); $temp=$$ ; $log = "/var/spool/filter/log"; if (-e $log){ open (LOG, ">>$log");} else {open (LOG, ">$log");} @liste = (<>) ; $i = 0 ; #trouve l'expediteur du mail $to = find_exp_to('To:'); $from = find_exp_to('From:'); print LOG "querrying contact:$from for user:$to \n\n"; db_check($to ,$from); if ($trouve <= 0 ) { mail($from) ; after_mail(); } else { after_mail(); } close LOG; sub db_check { $dbh = DBI->connect( "dbi:mysql:email", "user", "pass", {'RaiseError' => 1} ); $select= shift ; $test = shift ; $trouve = 0; $query= qq{select * from contact where user_name='$select' }; $sth = $dbh->prepare($query); $rv= $sth->execute || die $sth->errstr; while ($answer = $sth->fetchrow_arrayref ) { my ($id,$user,$contact) = @$answer; if ($contact=~ /($test)/i){ print LOG "contact => $test exist \n" ; $trouve = 1 ; } } $sth->finish; $dbh->disconnect(); if ($trouve <= 0){print LOG "$test not in db gonna send a mail\n";} } sub find_exp_to { my $find = shift ; $i = 0; while($liste[$i] ) { if ($liste[$i]=~ m/$find*?(.\w+\S)/cg) { #tous les car +acteres sur la lignes contenant From: $liste[$i]=~ s/($find)\s\b//g;#on vire le from $liste[$i]=~ s/\s//g; $data = $liste[$i]; } $i++; } return($data); } #envoi un mail a l'addr pass\uffff en param sub mail { require Mail::Send ; my $sender = shift ; $msg = new Mail::Send ; $msg->to($sender); $msg->subject('Mail register') ; #appelle les header de la classe: $msg->set($header, @values); $fh = $msg->open; print $fh "Bonjour, pour pouvoir envoyer un mail a $to vous de +vez vous enregister http://sever/cgi-bin/register.pl"; $fh->close ; } #reverifie la db ap mailing si pas de reponse avt time out detruit le +mail sub after_mail { $j = 0; open(TEMP, "+>/var/spool/filter/$temp"); print(TEMP "@liste"); @delete = TEMP ; close(TEMP); $trouve = 0 ; $i =0; while ( $i < 10 && $trouve ==0 ) { db_check($to, $from) ; if ($trouve == 0) { print LOG "pas de news ds la base rest ds 10 s +econde\n"; sleep 10; } else { $trouve = 1; } $i++; } if ($trouve == 0) { print LOG "operation time out deleting mail from $from +\n"; unlink @delete ; } else { @arg=("sendmail","-i","$sender","$recipient","<","@lis +te"); system(@arg) == 0 || die "exec a send back error :$?"; unlink @delete; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: postfix filter...
by hsinclai (Deacon) on Feb 06, 2005 at 16:35 UTC | |
|
Re: postfix filter...
by hsinclai (Deacon) on Feb 07, 2005 at 03:27 UTC | |
|
Re: postfix filter...
by fauria (Deacon) on Feb 06, 2005 at 16:51 UTC | |
|
Re: postfix filter...
by grinder (Bishop) on Feb 06, 2005 at 17:53 UTC | |
by hsinclai (Deacon) on Feb 06, 2005 at 18:44 UTC |