Thread: SF.net SVN: postfixadmin:[427] trunk/VIRTUAL_VACATION/vacation.pl
Brought to you by:
christian_boltz,
gingerdog
From: <Gin...@us...> - 2008-07-29 19:52:58
|
Revision: 427 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=427&view=rev Author: GingerDog Date: 2008-07-29 19:53:08 +0000 (Tue, 29 Jul 2008) Log Message: ----------- vacation.pl: applying patch from luxten - see https://sourceforge.net/tracker/index.php?func=detail&aid=2031659&group_id=191583&atid=937966 - thanks! Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-07-29 19:32:32 UTC (rev 426) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-07-29 19:53:08 UTC (rev 427) @@ -164,7 +164,7 @@ # Violation of a primay key constraint may happen here, and that's # fine. All other error conditions are not fine, however. - if ($e !~ /_pkey/) { + if ($e !~ /(?:_pkey|^Duplicate entry)/) { do_log('',$to,$from,'',"Unexpected error: '$e' from query '$query'"); # Let's play safe and notify anyway This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2008-07-29 20:33:23
|
Revision: 428 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=428&view=rev Author: GingerDog Date: 2008-07-29 20:33:30 +0000 (Tue, 29 Jul 2008) Log Message: ----------- vacation.pl: add patch from Luxten - enable re-notification after definable timeout - see : https://sourceforge.net/tracker/index.php?func=detail&aid=2031631&group_id=191583&atid=937966 Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-07-29 19:53:08 UTC (rev 427) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-07-29 20:33:30 UTC (rev 428) @@ -40,6 +40,9 @@ # Properly handle failed queries to vacation_notification. # Fixed log reporting. # +# 2008-07-29 Patch from Luxten to add repeat notification after timeout. See: +# https://sourceforge.net/tracker/index.php?func=detail&aid=2031631&group_id=191583&atid=937966 +# # Requirements: # You need to have the DBD::Pg or DBD::mysql perl-module installed. # You need to have the Mail::Sendmail module installed. @@ -98,6 +101,10 @@ my $debugfile=''; #my $debugfile = "/var/log/vacation/vacation.debug"; +# notification interval, in seconds +# set to 0 to notify only once +my $interval = 60*60*24; + # =========== end configuration =========== use DBI; @@ -170,7 +177,32 @@ # Let's play safe and notify anyway return 0; } - return 1; + if ($interval) { + $query = qq{SELECT NOW()-notified_at FROM vacation_notification WHERE on_vacation=? AND notified=?}; + $stm = $dbh->prepare($query) or panic_prepare($query); + $stm->execute($to,$from) or panic_execute($query,"on_vacation='$to', notified='$from'"); + my @row = $stm->fetchrow_array; + my $int = $row[0]; + if ($int > $interval) { + do_debug ("[Interval elapsed, sending the message]: ", $from, $to); + $query = qq{UPDATE vacation_notification SET notified_at=NOW() WHERE on_vacation=? AND notified=?}; + $stm = $dbh->prepare($query); + if (!$stm) { + do_log('',$to,$from,'',"Could not prepare query $query"); + return 0; + } + if (!$stm->execute($to,$from)) { + $e=$dbh->errstr; + do_log('',$to,$from,'',"Unexpected error: '$e' from query '$query'"); + } + return 0; + } else { + do_debug ("[Interval not elapsed, not sending the message]: ", $from, $to); + return 1; + } + } else { + return 1; + } } return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2008-07-30 06:48:27
|
Revision: 431 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=431&view=rev Author: GingerDog Date: 2008-07-30 06:48:37 +0000 (Wed, 30 Jul 2008) Log Message: ----------- vacation.pl: disable automaticnotification stuff Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-07-29 23:32:23 UTC (rev 430) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-07-30 06:48:37 UTC (rev 431) @@ -103,7 +103,10 @@ # notification interval, in seconds # set to 0 to notify only once -my $interval = 60*60*24; +# e.g. 1 day ... +#my $interval = 60*60*24; +# disabled by default +my $interval = 0; # =========== end configuration =========== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2008-08-03 10:09:20
|
Revision: 433 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=433&view=rev Author: GingerDog Date: 2008-08-03 10:09:29 +0000 (Sun, 03 Aug 2008) Log Message: ----------- vacation.pl: initial merge of smtp rcpt/to checking stuff as per https://sourceforge.net/forum/forum.php?thread_id=2099851&forum_id=676076 ; Thank you! Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-08-01 20:47:07 UTC (rev 432) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-08-03 10:09:29 UTC (rev 433) @@ -43,12 +43,20 @@ # 2008-07-29 Patch from Luxten to add repeat notification after timeout. See: # https://sourceforge.net/tracker/index.php?func=detail&aid=2031631&group_id=191583&atid=937966 # +# 2008-08-01 Luigi Iotti <luigi at iotti dot biz> +# Use envelope sender/recipient instead of using +# From: and To: header fields; +# Support to good vacation behavior as in +# http://www.irbs.net/internet/postfix/0707/0954.html +# (needs to be tested); +# # Requirements: # You need to have the DBD::Pg or DBD::mysql perl-module installed. # You need to have the Mail::Sendmail module installed. # You need to have the Email::Valid module installed. # You need to have the MIME::Charset module installed. # You need to have the MIME::EncWords module installed. +# You need to have the GetOpt::Std module installed. # # On Debian based systems : # libmail-sendmail-perl @@ -116,6 +124,7 @@ use Email::Valid; use strict; use Mail::Sendmail; +use Getopt::Std; binmode (STDIN,':utf8'); @@ -131,12 +140,12 @@ exit(0); } -my $db_true; # MySQL and PgSQL use different values for TRUE +my $db_true; # MySQL and PgSQL use different values for TRUE, and unicode support... if ($db_type eq "mysql") { $dbh->do("SET CHARACTER SET utf8;"); $db_true = '1'; } else { # Pg - # TODO: SET CHARACTER SET is mysql only, needs FIX for ALL databases + $dbh->do("SET CLIENT ENCODING 'UTF8'"); $db_true = 'True'; } @@ -355,9 +364,15 @@ } +sub strip_address { + my $arg = shift; + $arg =~ /([\w\-.%]+\@[\w.-]+)/; + return lc($1); +} + ########################### main ################################# -my ($from, $to, $cc, $subject, $messageid, $lastheader); +my ($from, $to, $cc, ,$bcc , $subject, $messageid, $lastheader, $sender, $recipient, %opts, $sndrhdr); $subject=''; $spam = 0; @@ -366,55 +381,59 @@ while (<STDIN>) { last if (/^$/); if (/^\s+(.*)/ and $lastheader) { $$lastheader .= " $1"; } + elsif (/^Return-Path:\s+(.*)\n$/i) { $sender = $1; $lastheader = \$sender; } + elsif (/^Delivered-To:\s+(.*)\n$/i) { $recipient = $1; $lastheader = \$recipient; } elsif (/^from:\s+(.*)\n$/i) { $from = $1; $lastheader = \$from; } elsif (/^to:\s+(.*)\n$/i) { $to = $1; $lastheader = \$to; } elsif (/^cc:\s+(.*)\n$/i) { $cc = $1; $lastheader = \$cc; } + elsif (/^bcc:\s+(.*)\n$/i) { $bcc = $1; $lastheader = \$bcc; } elsif (/^subject:\s+(.*)\n$/i) { $subject = $1; $lastheader = \$subject; } elsif (/^message-id:\s+(.*)\n$/i) { $messageid = $1; $lastheader = \$messageid; } - elsif (/^x-spam-(flag|status):\s+yes/i) { exit (0); } - elsif (/^precedence:\s+(bulk|list|junk)/i) { exit (0); } - elsif (/^x-loop:\s+postfix\ admin\ virtual\ vacation/i) { exit (0); } + elsif (/^x-spam-(flag|status):\s+yes/i) { do_debug("x-spam-$1: yes found"); exit (0); } + elsif (/^precedence:\s+(bulk|list|junk)/i) { do_debug("precedence: $1 found"); exit (0); } + elsif (/^x-loop:\s+postfix\ admin\ virtual\ vacation/i) { do_debug("x-loop: postfix admin virtual vacation found"); exit (0); } + elsif (/^Auto-Submitted:\s+no/i) { next; } + elsif (/^Auto-Submitted:/i) { do_debug("Auto-Submitted: something found"); exit (0); } + elsif (/^List-(Id|Post):/i) { do_debug("List-$1: found"); exit (0); } + elsif (/^Sender:\s+(.*)/i) { $sndrhdr = $1; $lastheader = \$sndrhdr; } else {$lastheader = "" ; } } +getopts('f:', \%opts) or die "Usage: $0 [-f sender] [-- [recipient]]"; +$opts{f} and $sender = $opts{f}; +$recipient = shift || $recipient || $ENV{"USER"} || ""; + # If either From: or To: are not set, exit -if (!$from || !$to || !$messageid) { exit (0); } +if (!$from || !$to || !$messageid || !$sender || !$recipient) { do_debug("One of from=$from, to=$to, $messageid=$messageid, sender=$sender, recipient=$recipient is empty"); exit (0); } +if ( $sender =~ /^(mailer-daemon|listserv|majordomo|owner-|request-|bounces-)/i) { do_debug("sender $sender contains $1"); exit (0); } +if ( $sender =~ /-(owner|request|bounces)\@/i) { do_debug("sender $sender contains $1"); exit (0); } +my $ss = strip_address($sender); +my $sr = strip_address($recipient); +my $ssh = strip_address($sndrhdr); +if ($ss eq $sr) { do_debug("sender $ss and recipient $sr are the same"); exit(0); } +my $recipfound = 0; +for (split(/,\s*/, lc($to)), split(/,\s*/, lc($cc)), split(/,\s*/, lc($bcc))) { + my $destinatario = strip_address($_); + if ($ssh eq $destinatario) { do_debug("sender header $sender contains recipient $destinatario"); exit(0); } + if ($sr eq $destinatario) { $recipfound++; } +} +if (!$recipfound) { do_debug("envelope recipient $sr not found in the header recipients"); exit (0); } $from = lc ($from); if (!Email::Valid->address($from,-mxcheck => 1)) { do_debug("Invalid from email address: $from; exiting."); exit(0); } +if (!Email::Valid->address($ss,-mxcheck => 1)) { do_debug("Invalid sender email address: $ss; exiting."); exit(0); } # Check if it's an obvious sender, exit if ($from =~ /([\w\-.%]+\@[\w.-]+)/) { $from = $1; } -if ($from eq "" || $from =~ /^owner-|-(request|owner)\@|^(mailer-daemon|postmaster)\@/i) { exit (0); } +if ($from eq "" || $from =~ /^(owner-|-(?:request|owner)\@|^(?:mailer-daemon|postmaster)\@)/i) { do_debug("from $from contains $1"); exit (0); } -# Strip To: and Cc: and push them in array -my @strip_cc_array; -my @strip_to_array = split(/, */, lc ($to) ); -if (defined $cc) { @strip_cc_array = split(/, */, lc ($cc) ); } -push (@strip_to_array, @strip_cc_array); - -my @search_array; - -# Strip email address from headers -for (@strip_to_array) { - if ($_ =~ /([\w\-.%]+\@[\w.-]+)/) { - push (@search_array, $1); - do_debug ("[STRIP RECIPIENTS]: ", $messageid, $1); - } +my ($rv, $email) = find_real_address ($sr); +if ($rv == 1) { + do_debug ("[FOUND VACATION]: ", $messageid, $sender, $recipient, $email); + send_vacation_email( $email, $sender, $recipient, $messageid); } -# Search for email address which has vacation -for (@search_array) { - /([\w\-.%]+\@[\w.-]+)/ or next; - my $addr = $1; - my ($rv, $email) = find_real_address ($addr); - if ($rv == 1) { - do_debug ("[FOUND VACATION]: ", $messageid, $from, $to, $email); - send_vacation_email( $email, $from, $to, $messageid); - } -} - 0; #/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2008-08-03 10:12:27
|
Revision: 434 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=434&view=rev Author: GingerDog Date: 2008-08-03 10:12:35 +0000 (Sun, 03 Aug 2008) Log Message: ----------- fix compile error Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-08-03 10:09:29 UTC (rev 433) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-08-03 10:12:35 UTC (rev 434) @@ -372,10 +372,9 @@ ########################### main ################################# -my ($from, $to, $cc, ,$bcc , $subject, $messageid, $lastheader, $sender, $recipient, %opts, $sndrhdr); +my ($from, $to, $cc, ,$bcc , $subject, $messageid, $lastheader, $sender, $recipient, %opts, $sndrhdr, $spam); $subject=''; -$spam = 0; # Take headers apart while (<STDIN>) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2008-08-05 20:57:37
|
Revision: 441 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=441&view=rev Author: GingerDog Date: 2008-08-05 20:57:45 +0000 (Tue, 05 Aug 2008) Log Message: ----------- vacation.pl: remove my super secret connection details Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-08-05 20:54:47 UTC (rev 440) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-08-05 20:57:45 UTC (rev 441) @@ -99,13 +99,14 @@ my $db_host = ''; # connection details -my $db_username = 'dg'; -my $db_password = 'gingerdog'; +my $db_username = 'your_username'; +my $db_password = 'your_password'; my $db_name = 'postfix'; # smtp server used to send vacation e-mails -my $smtp_server = '192.168.1.4'; +my $smtp_server = 'localhost'; +# Set to 1 to enable logging to syslog. my $syslog = 0; # path to logfile, when empty logging is supressed This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2008-08-06 14:45:07
|
Revision: 442 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=442&view=rev Author: GingerDog Date: 2008-08-06 14:45:17 +0000 (Wed, 06 Aug 2008) Log Message: ----------- vacation.pl: fix for https://sourceforge.net/tracker/?func=detail&atid=937964&aid=2040288&group_id=191583 Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-08-05 20:57:45 UTC (rev 441) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-08-06 14:45:17 UTC (rev 442) @@ -167,7 +167,7 @@ filename => $logfile, mode => 'append'); - my $logger = get_logger(); + $logger = get_logger(); $appender->layout($log_layout); $logger->add_appender($appender); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2008-09-03 08:44:31
|
Revision: 457 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=457&view=rev Author: GingerDog Date: 2008-09-03 08:44:36 +0000 (Wed, 03 Sep 2008) Log Message: ----------- 1- fix smtp_recipient (i.e un-vacationise-it), 2- remove the needless \s* stuff - these will get removed by the strip_address() routine anyway Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-09-03 08:32:25 UTC (rev 456) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-09-03 08:44:36 UTC (rev 457) @@ -103,6 +103,8 @@ my $db_password = 'gingerdog'; my $db_name = 'postfix'; +my $vacation_domain = 'autoreply.example.org'; + # smtp server used to send vacation e-mails my $smtp_server = 'localhost'; @@ -452,24 +454,34 @@ while (<STDIN>) { last if (/^$/); if (/^\s+(.*)/ and $lastheader) { $$lastheader .= " $1"; next; } - elsif (/^from:\s*(.*)\b\s*\n$/i) { $from = $1; $lastheader = \$from; } - elsif (/^to:\s*(.*)\s*\n$/i) { $to = $1; $lastheader = \$to; } - elsif (/^cc:\s*(.*)\s*\n$/i) { $cc = $1; $lastheader = \$cc; } + elsif (/^from:\s*(.*)\n$/i) { $from = $1; $lastheader = \$from; } + elsif (/^to:\s*(.*)\n$/i) { $to = $1; $lastheader = \$to; } + elsif (/^cc:\s*(.*)\n$/i) { $cc = $1; $lastheader = \$cc; } elsif (/^Reply-to:\s*(.*)\s*\n$/i) { $replyto = $1; $lastheader = \$replyto; } - elsif (/^subject:\s*(.*)\s*\n$/i) { $subject = $1; $lastheader = \$subject; } + elsif (/^subject:\s*(.*)\n$/i) { $subject = $1; $lastheader = \$subject; } elsif (/^message-id:\s*(.*)\s*\n$/i) { $messageid = $1; $lastheader = \$messageid; } elsif (/^x-spam-(flag|status):\s+yes/i) { $logger->debug("x-spam-$1: yes found; exiting"); exit (0); } elsif (/^x-facebook-notify:/i) { $logger->debug('Mail from facebook, ignoring'); exit(0); } elsif (/^precedence:\s+(bulk|list|junk)/i) { $logger->debug("precedence: $1 found; exiting"); exit (0); } elsif (/^x-loop:\s+postfix\ admin\ virtual\ vacation/i) { $logger->debug("x-loop: postfix admin virtual vacation found; exiting"); exit (0); } - elsif (/^Auto-Submitted:\s*no\b*/i) { next; } + elsif (/^Auto-Submitted:\s*no/i) { next; } elsif (/^Auto-Submitted:/i) { $logger->debug("Auto-Submitted: something found; exiting"); exit (0); } elsif (/^List-(Id|Post):/i) { $logger->debug("List-$1: found; exiting"); exit (0); } else {$lastheader = "" ; } } +if($smtp_recipient =~ /\@$vacation_domain/) { + # the regexp used here could probably be improved somewhat, for now hope that people won't use # as a valid mailbox character. + my $tmp = $smtp_recipient; + $tmp =~ s/\@$vacation_domain//; + $tmp =~ s/#/\@/; + $logger->debug("Converted autoreply mailbox back to normal style - from $smtp_recipient to $tmp"); + $smtp_recipient = $tmp; + undef $tmp; +} + # If either From: or To: are not set, exit if(!$from || !$to || !$messageid || !$smtp_sender || !$smtp_recipient) { $logger->info("One of from=$from, to=$to, messageid=$messageid, smtp sender=$smtp_sender, smtp recipient=$smtp_recipient empty"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2008-09-03 09:18:56
|
Revision: 456 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=456&view=rev Author: GingerDog Date: 2008-09-03 08:32:25 +0000 (Wed, 03 Sep 2008) Log Message: ----------- force requirement for command line parameters to script; regexp changes - thanks Luxten (https://sourceforge.net/forum/forum.php?thread_id=2099851&forum_id=676076) Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-09-01 19:20:23 UTC (rev 455) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-09-03 08:32:25 UTC (rev 456) @@ -146,10 +146,10 @@ # Setup a logger... # getopts('f:t:', \%opts) or die "Usage: $0 [-t yes] -f sender -- recipient\n -t for testing only\n"; -$opts{f} and $smtp_sender = $opts{f}; +$opts{f} and $smtp_sender = $opts{f} or die "-f sender not present on command line"; $test_mode = 0; $opts{t} and $test_mode = 1; -$smtp_recipient = shift || $smtp_recipient || $ENV{"USER"} || ""; +$smtp_recipient = shift or die "recipient not given on command line"; my $log_layout = Log::Log4perl::Layout::PatternLayout->new("%d %p> %F:%L %M - %m%n"); @@ -452,7 +452,7 @@ while (<STDIN>) { last if (/^$/); if (/^\s+(.*)/ and $lastheader) { $$lastheader .= " $1"; next; } - elsif (/^from:\s*(.*)\s*\n$/i) { $from = $1; $lastheader = \$from; } + elsif (/^from:\s*(.*)\b\s*\n$/i) { $from = $1; $lastheader = \$from; } elsif (/^to:\s*(.*)\s*\n$/i) { $to = $1; $lastheader = \$to; } elsif (/^cc:\s*(.*)\s*\n$/i) { $cc = $1; $lastheader = \$cc; } elsif (/^Reply-to:\s*(.*)\s*\n$/i) { $replyto = $1; $lastheader = \$replyto; } @@ -462,7 +462,7 @@ elsif (/^x-facebook-notify:/i) { $logger->debug('Mail from facebook, ignoring'); exit(0); } elsif (/^precedence:\s+(bulk|list|junk)/i) { $logger->debug("precedence: $1 found; exiting"); exit (0); } elsif (/^x-loop:\s+postfix\ admin\ virtual\ vacation/i) { $logger->debug("x-loop: postfix admin virtual vacation found; exiting"); exit (0); } - elsif (/^Auto-Submitted:\s*no\s*/i) { next; } + elsif (/^Auto-Submitted:\s*no\b*/i) { next; } elsif (/^Auto-Submitted:/i) { $logger->debug("Auto-Submitted: something found; exiting"); exit (0); } elsif (/^List-(Id|Post):/i) { $logger->debug("List-$1: found; exiting"); exit (0); } else {$lastheader = "" ; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2008-10-21 11:08:32
|
Revision: 468 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=468&view=rev Author: GingerDog Date: 2008-10-21 11:08:19 +0000 (Tue, 21 Oct 2008) Log Message: ----------- vacation.pl: bump version number as it has not changed in years Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-10-19 18:27:14 UTC (rev 467) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-10-21 11:08:19 UTC (rev 468) @@ -1,7 +1,8 @@ #!/usr/bin/perl -w # -# Virtual Vacation 3.1 -# by Mischa Peters <mischa at high5 dot net> +# Virtual Vacation 4.0 +# Originally by Mischa Peters <mischa at high5 dot net> +# # Copyright (c) 2002 - 2005 High5! # Licensed under GPL for more info check GPL-LICENSE.TXT # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2008-10-31 13:37:57
|
Revision: 470 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=470&view=rev Author: christian_boltz Date: 2008-10-31 13:37:49 +0000 (Fri, 31 Oct 2008) Log Message: ----------- vacation.pl: - allow to enter the configuration in /etc/mail/postfixadmin/vacation.conf instead of editing vacation.pl directly Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2008-10-31 10:24:23 UTC (rev 469) +++ trunk/VIRTUAL_VACATION/vacation.pl 2008-10-31 13:37:49 UTC (rev 470) @@ -93,31 +93,31 @@ # can read it. # db_type - uncomment one of these -my $db_type = 'Pg'; +our $db_type = 'Pg'; #my $db_type = 'mysql'; # leave empty for connection via UNIX socket -my $db_host = ''; +our $db_host = ''; # connection details -my $db_username = 'dg'; -my $db_password = 'gingerdog'; -my $db_name = 'postfix'; +our $db_username = 'dg'; +our $db_password = 'gingerdog'; +our $db_name = 'postfix'; -my $vacation_domain = 'autoreply.example.org'; +our $vacation_domain = 'autoreply.example.org'; # smtp server used to send vacation e-mails -my $smtp_server = 'localhost'; +our $smtp_server = 'localhost'; # Set to 1 to enable logging to syslog. -my $syslog = 0; +our $syslog = 0; # path to logfile, when empty logging is supressed # change to e.g. /dev/null if you want nothing logged. # if we can't write to this, we try /tmp/vacation.log instead -my $logfile='/var/spool/vacation/vacation.log'; +our $logfile='/var/spool/vacation/vacation.log'; # 2 = debug + info, 1 = info only, 0 = error only -my $log_level = 2; +our $log_level = 2; # notification interval, in seconds @@ -125,8 +125,15 @@ # e.g. 1 day ... #my $interval = 60*60*24; # disabled by default -my $interval = 0; +our $interval = 0; +# instead of changing this script, you can put your settings to /etc/mail/postfixadmin/vacation.conf +# just use perl syntax there to fill the variables listed above (without the "our" keyword). Example: +# $db_username = 'mail'; +if (-f "/etc/mail/postfixadmin/vacation.conf") { + require "/etc/mail/postfixadmin/vacation.conf"; +} + # =========== end configuration =========== if ( ! -w $logfile ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2009-01-13 14:22:12
|
Revision: 513 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=513&view=rev Author: GingerDog Date: 2009-01-13 14:22:00 +0000 (Tue, 13 Jan 2009) Log Message: ----------- wiza thinks this is hte correct behaviour (i.e return true not false Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-01-12 21:14:08 UTC (rev 512) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-01-13 14:22:00 UTC (rev 513) @@ -247,7 +247,7 @@ if ($e !~ /(?:_pkey|^Duplicate entry)/) { $logger->error("Failed to insert into vacation_notification table (to:$to from:$from error:'$e' query:'$query')"); # Let's play safe and notify anyway - return 0; + return 1; } if ($interval) { $query = qq{SELECT NOW()-notified_at FROM vacation_notification WHERE on_vacation=? AND notified=?}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2009-01-20 13:22:30
|
Revision: 532 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=532&view=rev Author: GingerDog Date: 2009-01-20 11:53:54 +0000 (Tue, 20 Jan 2009) Log Message: ----------- vacation.pl: make it strip/discover addresses better, slightly better logging, stop it requiring a messageid Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-01-20 11:49:03 UTC (rev 531) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-01-20 11:53:54 UTC (rev 532) @@ -152,6 +152,7 @@ my ($from, $to, $cc, $replyto , $subject, $messageid, $lastheader, $smtp_sender, $smtp_recipient, %opts, $spam, $test_mode, $logger); $subject=''; +$messageid='unknown'; # Setup a logger... # @@ -391,7 +392,7 @@ 'Message' => encode_base64($body) ); if($test_mode == 1) { - $logger->info("** TEST MODE ** : Vacation response sent to $to from $from subject $subject - NOT sent\n"); + $logger->info("** TEST MODE ** : Vacation response sent to $to from $from subject $subject (not) sent\n"); $logger->info(%mail); return 0; } @@ -410,13 +411,28 @@ } my @ok; $logger = get_logger(); - for (split(/,\s*/, lc($arg))) { - my $temp = Email::Valid->address($_); + my @list; + @list = $arg =~ m/([\w\.\-\']+\@[\w\.\-]+\w+)/g; + foreach(@list) { + #$logger->debug("Checking: $_"); + my $temp = Email::Valid->address( -address => $_, -mxcheck => 0); if($temp) { push(@ok, $temp); } + else { + $logger->debug("Email not valid : $Email::Valid::Details"); + } } - my $result = join(", ", @ok); + # remove duplicates + my %seen = (); + my @uniq; + my $item; + foreach $item (@ok) { + push(@uniq, $item) unless $seen{$item}++ + } + + my $result = join(", ", @uniq); + #$logger->debug("Result: $result"); return $result; } @@ -459,6 +475,7 @@ $cc = ''; $replyto = ''; +$logger->debug("Script argument SMTP recipient is : '$smtp_recipient' and smtp_sender : '$smtp_sender'"); while (<STDIN>) { last if (/^$/); if (/^\s+(.*)/ and $lastheader) { $$lastheader .= " $1"; next; } @@ -495,7 +512,7 @@ $logger->info("One of from=$from, to=$to, messageid=$messageid, smtp sender=$smtp_sender, smtp recipient=$smtp_recipient empty"); exit(0); } - +$logger->debug("Email headers have to: '$to' and From: '$from'"); $to = strip_address($to); $from = lc ($from); $from = check_and_clean_from_address($from); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2009-06-29 07:58:54
|
Revision: 677 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=677&view=rev Author: GingerDog Date: 2009-06-29 07:58:50 +0000 (Mon, 29 Jun 2009) Log Message: ----------- vacation.pl: fix https://sourceforge.net/tracker/?func=detail&aid=2796067&group_id=191583&atid=937964 - remove usage of file in /tmp; abort if logfile is not writeable, or we cannot create it Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-06-11 13:56:29 UTC (rev 676) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-06-29 07:58:50 UTC (rev 677) @@ -87,6 +87,16 @@ # http://dag.wieers.com/home-made/apt/packages.php # +use DBI; +use MIME::Base64; +use MIME::EncWords qw(:all); +use Email::Valid; +use strict; +use Mail::Sendmail; +use Getopt::Std; +use Log::Log4perl qw(get_logger :levels); +use File::Basename; + # ========== begin configuration ========== # IMPORTANT: If you put passwords into this script, then remember @@ -101,8 +111,8 @@ our $db_host = ''; # connection details -our $db_username = 'dg'; -our $db_password = 'gingerdog'; +our $db_username = 'user'; +our $db_password = 'password'; our $db_name = 'postfix'; our $vacation_domain = 'autoreply.example.org'; @@ -115,12 +125,13 @@ # path to logfile, when empty logging is supressed # change to e.g. /dev/null if you want nothing logged. -# if we can't write to this, we try /tmp/vacation.log instead -our $logfile='/var/spool/vacation/vacation.log'; +# if we can't write to this, and $log_to_file is 1 (below) the script will abort. +our $logfile='/var/log/vacation.log'; # 2 = debug + info, 1 = info only, 0 = error only our $log_level = 2; +# Whether to log to file or not, 0 = do not write to a log file +our $log_to_file = 1; - # notification interval, in seconds # set to 0 to notify only once # e.g. 1 day ... @@ -137,18 +148,13 @@ # =========== end configuration =========== -if ( ! -w $logfile ) { - $logfile = "/tmp/vacation.log"; +if($log_to_file == 1) { + if (( ! -w $logfile ) && (! -w dirname($logfile))) { + # Cannot log; no where to write to. + die("Cannot create logfile : $logfile"); + } } -use DBI; -use MIME::Base64; -use MIME::EncWords qw(:all); -use Email::Valid; -use strict; -use Mail::Sendmail; -use Getopt::Std; -use Log::Log4perl qw(get_logger :levels); my ($from, $to, $cc, $replyto , $subject, $messageid, $lastheader, $smtp_sender, $smtp_recipient, %opts, $spam, $test_mode, $logger); @@ -175,16 +181,18 @@ $logger->debug("Test mode enabled"); } else { - # log to file. - my $appender = Log::Log4perl::Appender->new( - 'Log::Dispatch::File', - filename => $logfile, - mode => 'append'); - $logger = get_logger(); - $appender->layout($log_layout); - $logger->add_appender($appender); + if($log_to_file == 1) { + # log to file. + my $appender = Log::Log4perl::Appender->new( + 'Log::Dispatch::File', + filename => $logfile, + mode => 'append'); + $appender->layout($log_layout); + $logger->add_appender($appender); + } + if($syslog == 1) { my $syslog_appender = Log::Log4perl::Appender->new( 'Log::Dispatch::Syslog', This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2009-06-29 08:26:44
|
Revision: 678 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=678&view=rev Author: GingerDog Date: 2009-06-29 08:26:35 +0000 (Mon, 29 Jun 2009) Log Message: ----------- vacation.pl: add patch from Steve - https://sourceforge.net/tracker/?func=detail&aid=2813178&group_id=191583&atid=937967 Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-06-29 07:58:50 UTC (rev 677) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-06-29 08:26:35 UTC (rev 678) @@ -56,15 +56,18 @@ # Use Log4Perl # Added better testing (and -t option) # +# 2009-06-29 Steve (sbajic/sf.net) +# Add Mail::Sender for SMTP auth + more flexibility +# # Requirements - the following perl modules are required: # DBD::Pg or DBD::mysql -# Mail::Sendmail, Email::Valid MIME::Charset, Log::Log4perl, Log::Dispatch, MIME::EncWords and GetOpt::Std +# Mail::Sender, Email::Valid MIME::Charset, Log::Log4perl, Log::Dispatch, MIME::EncWords and GetOpt::Std # # You may install these via CPAN, or through your package tool. # CPAN: 'perl -MCPAN -e shell', then 'install Module::Whatever' # # On Debian based systems : -# libmail-sendmail-perl +# libmail-sender-perl # libdbd-pg-perl # libemail-valid-perl # libmime-perl @@ -92,7 +95,7 @@ use MIME::EncWords qw(:all); use Email::Valid; use strict; -use Mail::Sendmail; +use Mail::Sender; use Getopt::Std; use Log::Log4perl qw(get_logger :levels); use File::Basename; @@ -119,7 +122,17 @@ # smtp server used to send vacation e-mails our $smtp_server = 'localhost'; +our $smtp_server_port = 25; +# SMTP authentication protocol used for sending. +# Can be 'PLAIN', 'LOGIN', 'CRAM-MD5' or 'NTLM' +# Leave it blank if you don't use authentification +our $smtp_auth = undef; +# username used to login to the server +our $smtp_authid = 'someuser'; +# password used to login to the server +our $smtp_authpwd = 'somepass'; + # Set to 1 to enable logging to syslog. our $syslog = 0; @@ -130,7 +143,7 @@ # 2 = debug + info, 1 = info only, 0 = error only our $log_level = 2; # Whether to log to file or not, 0 = do not write to a log file -our $log_to_file = 1; +our $log_to_file = 0; # notification interval, in seconds # set to 0 to notify only once @@ -386,27 +399,38 @@ my $body = $row[1]; my $from = $email; my $to = $orig_from; - my $vacation_subject = encode_mimewords($subject, 'Encoding'=> 'q', 'Charset'=>'utf-8', 'Field'=>'Subject'); + my %smtp_connection; + %smtp_connection = ( + 'smtp' => $smtp_server, + 'port' => $smtp_server_port, + 'auth' => $smtp_auth, + 'authid' => $smtp_authid, + 'authpwd' => $smtp_authpwd, + 'skip_bad_recipients' => 'true', + 'encoding' => 'Base64', + 'ctype' => 'text/plain; charset=UTF-8', + 'headers' => 'Precedence: junk', + 'headers' => 'X-Loop: Postfix Admin Virtual Vacation', + ); my %mail; + # I believe Mail::Sender qp encodes the subject, so we no longer need to. %mail = ( - 'smtp' => $smtp_server, - 'Subject' => $vacation_subject, - 'From' => $from, - 'To' => $to, - 'MIME-Version' => '1.0', - 'Content-Type' => 'text/plain; charset=UTF-8', - 'Content-Transfer-Encoding' => 'base64', - 'Precedence' => 'junk', - 'X-Loop' => 'Postfix Admin Virtual Vacation', - 'Message' => encode_base64($body) + 'subject' => $subject, + 'from' => $from, + 'to' => $to, + 'msg' => encode_base64($body) ); if($test_mode == 1) { $logger->info("** TEST MODE ** : Vacation response sent to $to from $from subject $subject (not) sent\n"); $logger->info(%mail); return 0; } - sendmail(%mail) or $logger->error("Failed to send vacation response: " . $Mail::Sendmail::error); - $logger->debug("Vacation response sent, Mail::Sendmail said : " . $Mail::Sendmail::log); + $Mail::Sender::NO_X_MAILER = 1; + my $sender = new Mail::Sender({%smtp_connection}); + $sender->Open({%mail}); + $sender->SentLineEnc($body); + $sender->Close() or $logger->error("Failed to send vacation response: " . $sender->{'error_msg'}); + $logger->debug("Vacation response sent to $to, from $from"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2009-07-10 21:12:48
|
Revision: 684 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=684&view=rev Author: GingerDog Date: 2009-07-10 21:12:44 +0000 (Fri, 10 Jul 2009) Log Message: ----------- patch from Steve ... see https://sourceforge.net/tracker/index.php?func=detail&aid=2818228&group_id=191583&atid=937964 - once again, thank you Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-07-10 21:05:16 UTC (rev 683) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-07-10 21:12:44 UTC (rev 684) @@ -56,9 +56,13 @@ # Use Log4Perl # Added better testing (and -t option) # -# 2009-06-29 Steve (sbajic/sf.net) +# 2009-06-29 Stevan Bajic <st...@ba...> # Add Mail::Sender for SMTP auth + more flexibility # +# 2009-07-07 Stevan Bajic <st...@ba...> +# Add better alias lookups +# Check for more heades from Anti-Virus/Anti-Spam solutions +# # Requirements - the following perl modules are required: # DBD::Pg or DBD::mysql # Mail::Sender, Email::Valid MIME::Charset, Log::Log4perl, Log::Dispatch, MIME::EncWords and GetOpt::Std @@ -108,7 +112,7 @@ # db_type - uncomment one of these our $db_type = 'Pg'; -#my $db_type = 'mysql'; +#our $db_type = 'mysql'; # leave empty for connection via UNIX socket our $db_host = ''; @@ -153,10 +157,13 @@ our $interval = 0; # instead of changing this script, you can put your settings to /etc/mail/postfixadmin/vacation.conf -# just use perl syntax there to fill the variables listed above (without the "our" keyword). Example: +# or /etc/postfixadmin/vacation.conf just use Perl syntax there to fill the variables listed above +# (without the "our" keyword). Example: # $db_username = 'mail'; if (-f "/etc/mail/postfixadmin/vacation.conf") { - require "/etc/mail/postfixadmin/vacation.conf"; + require "/etc/mail/postfixadmin/vacation.conf"; +} elsif (-f "/etc/postfixadmin/vacation.conf") { + require "/etc/postfixadmin/vacation.conf"; } # =========== end configuration =========== @@ -168,7 +175,6 @@ } } - my ($from, $to, $cc, $replyto , $subject, $messageid, $lastheader, $smtp_sender, $smtp_recipient, %opts, $spam, $test_mode, $logger); $subject=''; @@ -176,13 +182,12 @@ # Setup a logger... # -getopts('f:t:', \%opts) or die "Usage: $0 [-t yes] -f sender -- recipient\n -t for testing only\n"; +getopts('f:t:', \%opts) or die "Usage: $0 [-t yes] -f sender -- recipient\n\t-t for testing only\n"; $opts{f} and $smtp_sender = $opts{f} or die "-f sender not present on command line"; $test_mode = 0; $opts{t} and $test_mode = 1; $smtp_recipient = shift or die "recipient not given on command line"; - my $log_layout = Log::Log4perl::Layout::PatternLayout->new("%d %p> %F:%L %M - %m%n"); if($test_mode == 1) { @@ -192,11 +197,10 @@ $appender->layout($log_layout); $logger->add_appender($appender); $logger->debug("Test mode enabled"); -} -else { +} else { $logger = get_logger(); if($log_to_file == 1) { - # log to file. + # log to file my $appender = Log::Log4perl::Appender->new( 'Log::Dispatch::File', filename => $logfile, @@ -224,7 +228,6 @@ $logger->level($DEBUG); } - binmode (STDIN,':utf8'); my $dbh; @@ -302,9 +305,6 @@ return 0; } - - - # try and determine if email address has vacation turned on; we # have to do alias searching, and domain aliasing resolution for this. # If found, return ($num_matches, $real_email); @@ -316,7 +316,7 @@ exit(1); } my $realemail = ''; - my $query = qq{SELECT email FROM vacation WHERE email=? and active=$db_true}; + my $query = qq{SELECT email FROM vacation WHERE email=? AND active=$db_true}; my $stm = $dbh->prepare($query) or panic_prepare($query); $stm->execute($email) or panic_execute($query,"email='$email'"); my $rv = $stm->rows; @@ -324,54 +324,83 @@ # Recipient has vacation if ($rv == 1) { $realemail = $email; - $logger->debug("Found $email has vacation active"); + $logger->debug("Found '\$email'\ has vacation active"); } else { - # XXX why aren't we doing a join here? - $logger->debug("Looking for alias records that $email resolves to with vacation turned on"); - $query = qq{SELECT goto FROM alias WHERE address=?}; + $logger->debug("Looking for alias records that \'$email\' resolves to with vacation turned on"); + $query = qq{SELECT goto FROM alias WHERE address=? AND (goto LIKE ?,% OR goto LIKE %,? OR goto LIKE %,?,%)}; $stm = $dbh->prepare($query) or panic_prepare($query); - $stm->execute($email) or panic_execute($query,"address='$email'"); + $stm->execute($email,$email,$email,$email) or panic_execute($query,"address='$email'"); $rv = $stm->rows; # Recipient is an alias, check if mailbox has vacation if ($rv == 1) { my @row = $stm->fetchrow_array; my $alias = $row[0]; - $query = qq{SELECT email FROM vacation WHERE email=? and active=$db_true}; - $stm = $dbh->prepare($query) or panic_prepare($query); - $stm->execute($alias) or panic_prepare($query,"email='$alias'"); - $rv = $stm->rows; - + if ($alias =~ /,/) { + for (split(/\s*,\s*/, lc($alias))) { + my $singlealias = $_; + $logger->debug("Found alias \'$singlealias\' for email \'$email\'. Looking if vacation is on for alias."); + $query = qq{SELECT email FROM vacation WHERE email=? AND active=$db_true}; + $stm = $dbh->prepare($query) or panic_prepare($query); + $stm->execute($singlealias) or panic_execute($query,"email='$singlealias'"); + $rv = $stm->rows; # Alias has vacation - if ($rv == 1) { - $realemail = $alias; + if ($rv == 1) { + $realemail = $singlealias; + last; + } + } + } else { + $query = qq{SELECT email FROM vacation WHERE email=? AND active=$db_true}; + $stm = $dbh->prepare($query) or panic_prepare($query); + $stm->execute($alias) or panic_prepare($query,"email='$alias'"); + $rv = $stm->rows; +# Alias has vacation + if ($rv == 1) { + $realemail = $alias; + } } -# We still have to look for domain level aliases... - } else { +# We have to look for alias domain (domain1 -> domain2) + } else { my ($user, $domain) = split(/@/, $email); - $query = qq{SELECT goto FROM alias WHERE address=?}; + $logger->debug("Looking for alias domain for $domain / $email / $user"); + $query = qq{SELECT target_domain FROM alias_domain WHERE alias_domain=?}; $stm = $dbh->prepare($query) or panic_prepare($query); - $stm->execute("\@$domain") or panic_execute($query,"address='\@$domain'"); + $stm->execute($domain) or panic_execute($query,"alias_domain='$domain'"); $rv = $stm->rows; - $logger->debug("Looking for domain level aliases for $domain / $email / $user"); -# The receipient has a domain level alias - if ($rv == 1) { + +# The domain has a alias domain level alias + if ($rv == 1) { my @row = $stm->fetchrow_array; - my $wildcard_dest = $row[0]; - my ($wilduser, $wilddomain) = split(/@/, $wildcard_dest); + my $alias_domain_dest = $row[0]; + ($rv, $realemail) = find_real_address ("$user\@$alias_domain_dest"); +# We still have to look for domain level aliases... + } else { + my ($user, $domain) = split(/@/, $email); + $logger->debug("Looking for domain level aliases for $domain / $email / $user"); + $query = qq{SELECT goto FROM alias WHERE address=?}; + $stm = $dbh->prepare($query) or panic_prepare($query); + $stm->execute("\@$domain") or panic_execute($query,"address='\@$domain'"); + $rv = $stm->rows; + +# The receipient has a domain level alias + if ($rv == 1) { + my @row = $stm->fetchrow_array; + my $wildcard_dest = $row[0]; + my ($wilduser, $wilddomain) = split(/@/, $wildcard_dest); + # Check domain alias - if ($wilduser) { - ($rv, $realemail) = find_real_address ($wildcard_dest); + if ($wilduser) { + ($rv, $realemail) = find_real_address ($wildcard_dest); + } else { + ($rv, $realemail) = find_real_address ("$user\@$wilddomain"); + } } else { - my $new_email = $user . '@' . $wilddomain; - ($rv, $realemail) = find_real_address ($new_email); + $logger->debug("No domain level alias present for $domain / $email / $user"); } } - else { - $logger->debug("No domain level alias present for $domain / $email / $user"); - } } } return ($rv, $realemail); @@ -428,15 +457,17 @@ $Mail::Sender::NO_X_MAILER = 1; my $sender = new Mail::Sender({%smtp_connection}); $sender->Open({%mail}); - $sender->SentLineEnc($body); + $sender->SendLineEnc($body); $sender->Close() or $logger->error("Failed to send vacation response: " . $sender->{'error_msg'}); $logger->debug("Vacation response sent to $to, from $from"); } } -# Remove textual stuff from a (list of) email address(es) -# e.g. convert: "aardvark" <a@b.com>, "Danger Mouse" <c@d.com>, e@f.com to -# a@b.com, c@d.com, e@f.com +# Convert a (list of) email address(es) from RFC 822 style addressing to +# RFC 821 style addressing. e.g. convert: +# "John Jones" <JJ...@ac...>, "Jane Doe/Sales/ACME" <JD...@ac...> +# to: +# jj...@ac..., jd...@ac... sub strip_address { my ($arg) = @_; if(!$arg) { @@ -445,14 +476,13 @@ my @ok; $logger = get_logger(); my @list; - @list = $arg =~ m/([\w\.\-\']+\@[\w\.\-]+\w+)/g; + @list = $arg =~ m/([\w\.\-\+\'\=_\^\|\$\/\{\}~\?\*\\&\!`\%]+\@[\w\.\-]+\w+)/g; foreach(@list) { #$logger->debug("Checking: $_"); my $temp = Email::Valid->address( -address => $_, -mxcheck => 0); if($temp) { push(@ok, $temp); - } - else { + } else { $logger->debug("Email not valid : $Email::Valid::Details"); } } @@ -464,7 +494,7 @@ push(@uniq, $item) unless $seen{$item}++ } - my $result = join(", ", @uniq); + my $result = lc(join(", ", @uniq)); #$logger->debug("Result: $result"); return $result; } @@ -489,8 +519,8 @@ my ($address) = @_; my $logger = get_logger(); - if($address =~ /^(noreply|postmaster|mailer-daemon|listserv|majordomo|owner-|request-|bounces-)/i || - $address =~ /-(owner|request|bounces)\@/i ) { + if($address =~ /^(noreply|postmaster|mailer\-daemon|listserv|majordomo|owner\-|request\-|bounces\-)/i || + $address =~ /\-(owner|request|bounces)\@/i ) { $logger->debug("sender $address contains $1 - will not send vacation message"); exit(0); } @@ -515,20 +545,24 @@ elsif (/^from:\s*(.*)\n$/i) { $from = $1; $lastheader = \$from; } elsif (/^to:\s*(.*)\n$/i) { $to = $1; $lastheader = \$to; } elsif (/^cc:\s*(.*)\n$/i) { $cc = $1; $lastheader = \$cc; } - elsif (/^Reply-to:\s*(.*)\s*\n$/i) { $replyto = $1; $lastheader = \$replyto; } + elsif (/^Reply\-to:\s*(.*)\s*\n$/i) { $replyto = $1; $lastheader = \$replyto; } elsif (/^subject:\s*(.*)\n$/i) { $subject = $1; $lastheader = \$subject; } - elsif (/^message-id:\s*(.*)\s*\n$/i) { $messageid = $1; $lastheader = \$messageid; } - elsif (/^x-spam-(flag|status):\s+yes/i) { $logger->debug("x-spam-$1: yes found; exiting"); exit (0); } - elsif (/^x-facebook-notify:/i) { $logger->debug('Mail from facebook, ignoring'); exit(0); } + elsif (/^message\-id:\s*(.*)\s*\n$/i) { $messageid = $1; $lastheader = \$messageid; } + elsif (/^x\-spam\-(flag|status):\s+yes/i) { $logger->debug("x-spam-$1: yes found; exiting"); exit (0); } + elsif (/^x\-facebook\-notify:/i) { $logger->debug('Mail from facebook, ignoring'); exit(0); } elsif (/^precedence:\s+(bulk|list|junk)/i) { $logger->debug("precedence: $1 found; exiting"); exit (0); } - elsif (/^x-loop:\s+postfix\ admin\ virtual\ vacation/i) { $logger->debug("x-loop: postfix admin virtual vacation found; exiting"); exit (0); } - elsif (/^Auto-Submitted:\s*no/i) { next; } - elsif (/^Auto-Submitted:/i) { $logger->debug("Auto-Submitted: something found; exiting"); exit (0); } - elsif (/^List-(Id|Post):/i) { $logger->debug("List-$1: found; exiting"); exit (0); } + elsif (/^x\-loop:\s+postfix\ admin\ virtual\ vacation/i) { $logger->debug("x-loop: postfix admin virtual vacation found; exiting"); exit (0); } + elsif (/^Auto\-Submitted:\s*no/i) { next; } + elsif (/^Auto\-Submitted:/i) { $logger->debug("Auto-Submitted: something found; exiting"); exit (0); } + elsif (/^List\-(Id|Post):/i) { $logger->debug("List-$1: found; exiting"); exit (0); } + elsif (/^(x\-(barracuda\-)?spam\-status):\s+(yes)/i) { $logger->debug("$1: $3 found; exiting"); exit (0); } + elsif (/^(x\-dspam\-result):\s+(spam|bl[ao]cklisted)/i) { $logger->debug("$1: $2 found; exiting"); exit (0); } + elsif (/^(x\-(anti|avas\-)?virus\-status):\s+(infected)/i) { $logger->debug("$1: $3 found; exiting"); exit (0); } + elsif (/^(x\-(avas\-spam|spamtest|crm114|razor|pyzor)\-status):\s+(spam)/i) { $logger->debug("$1: $3 found; exiting"); exit (0); } + elsif (/^(x\-osbf\-lua\-score):\s+[0-9\/\.\-\+]+\s+\[([-S])\]/i) { $logger->debug("$1: $2 found; exiting"); exit (0); } else {$lastheader = "" ; } } - if($smtp_recipient =~ /\@$vacation_domain/) { # the regexp used here could probably be improved somewhat, for now hope that people won't use # as a valid mailbox character. my $tmp = $smtp_recipient; @@ -539,7 +573,6 @@ undef $tmp; } - # If either From: or To: are not set, exit if(!$from || !$to || !$messageid || !$smtp_sender || !$smtp_recipient) { $logger->info("One of from=$from, to=$to, messageid=$messageid, smtp sender=$smtp_sender, smtp recipient=$smtp_recipient empty"); @@ -547,7 +580,7 @@ } $logger->debug("Email headers have to: '$to' and From: '$from'"); $to = strip_address($to); -$from = lc ($from); +$cc = strip_address($cc); $from = check_and_clean_from_address($from); if($replyto ne "") { # if reply-to is invalid, or looks like a mailing list, then we probably don't want to send a reply. @@ -556,37 +589,29 @@ $smtp_sender = check_and_clean_from_address($smtp_sender); $smtp_recipient = check_and_clean_from_address($smtp_recipient); - if ($smtp_sender eq $smtp_recipient) { $logger->debug("smtp sender $smtp_sender and recipient $smtp_recipient are the same; aborting"); exit(0); } -my $recipfound = 0; for (split(/,\s*/, lc($to)), split(/,\s*/, lc($cc))) { - my $destinatario = strip_address($_); - if ($smtp_sender eq $destinatario) { - $logger->debug("sender header $smtp_sender contains recipient $destinatario (mailing myself?)"); + my $header_recipient = strip_address($_); + if ($smtp_sender eq $header_recipient) { + $logger->debug("sender header $smtp_sender contains recipient $header_recipient (mailing myself?)"); exit(0); } - if ($smtp_recipient eq $destinatario) { $recipfound++; } } -if (!$recipfound) { - $logger->debug("smtp envelope recipient $smtp_recipient not found in the header recipients ($to & $cc) (therefore they were bcc'ed, so won't send vacation message)"); - exit (0); -} - - my ($rv, $email) = find_real_address($smtp_recipient); if ($rv == 1) { $logger->debug("Attempting to send vacation response for: $messageid to: $smtp_sender, $smtp_recipient, $email (test_mode = $test_mode)"); send_vacation_email($email, $smtp_sender, $smtp_recipient, $messageid, $test_mode); -} -else { +} else { $logger->debug("SMTP recipient $smtp_recipient which resolves to $email does not have an active vacation (rv: $rv, email: $email)"); } 0; #/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2009-08-12 06:24:02
|
Revision: 703 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=703&view=rev Author: GingerDog Date: 2009-08-12 06:23:51 +0000 (Wed, 12 Aug 2009) Log Message: ----------- VIRTUAL_VACATION/vacation.pl: fix sql query - see https://sourceforge.net/tracker/index.php?func=detail&aid=2835877&group_id=191583&atid=937964 Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-08-10 13:40:32 UTC (rev 702) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-08-12 06:23:51 UTC (rev 703) @@ -327,9 +327,9 @@ $logger->debug("Found '\$email'\ has vacation active"); } else { $logger->debug("Looking for alias records that \'$email\' resolves to with vacation turned on"); - $query = qq{SELECT goto FROM alias WHERE address=? AND (goto LIKE ?,% OR goto LIKE %,? OR goto LIKE %,?,%)}; + $query = qq{SELECT goto FROM alias WHERE address=? AND (goto LIKE ? OR goto LIKE % OR goto LIKE ?)}; $stm = $dbh->prepare($query) or panic_prepare($query); - $stm->execute($email,$email,$email,$email) or panic_execute($query,"address='$email'"); + $stm->execute($email,"$email,%","%,$email","%,$email,%") or panic_execute($query,"address='$email'"); $rv = $stm->rows; # Recipient is an alias, check if mailbox has vacation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2009-08-18 20:52:47
|
Revision: 706 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=706&view=rev Author: christian_boltz Date: 2009-08-18 20:52:37 +0000 (Tue, 18 Aug 2009) Log Message: ----------- vacation.pl: - fix typo (?) in query: "goto like %" should most probably be "goto like ?" (placeholder) (if this was not a typo, the whole "AND ..." would be superfluous) Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-08-17 17:36:04 UTC (rev 705) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-08-18 20:52:37 UTC (rev 706) @@ -327,7 +327,7 @@ $logger->debug("Found '\$email'\ has vacation active"); } else { $logger->debug("Looking for alias records that \'$email\' resolves to with vacation turned on"); - $query = qq{SELECT goto FROM alias WHERE address=? AND (goto LIKE ? OR goto LIKE % OR goto LIKE ?)}; + $query = qq{SELECT goto FROM alias WHERE address=? AND (goto LIKE ? OR goto LIKE ? OR goto LIKE ?)}; $stm = $dbh->prepare($query) or panic_prepare($query); $stm->execute($email,"$email,%","%,$email","%,$email,%") or panic_execute($query,"address='$email'"); $rv = $stm->rows; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2009-09-26 08:17:13
|
Revision: 721 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=721&view=rev Author: GingerDog Date: 2009-09-26 08:17:03 +0000 (Sat, 26 Sep 2009) Log Message: ----------- vacation.pl: change syslog facility Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-09-16 21:37:06 UTC (rev 720) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-09-26 08:17:03 UTC (rev 721) @@ -213,7 +213,7 @@ if($syslog == 1) { my $syslog_appender = Log::Log4perl::Appender->new( 'Log::Dispatch::Syslog', - Facility => 'user', + Facility => 'mail', ); $logger->add_appender($syslog_appender); } @@ -282,7 +282,7 @@ my @row = $stm->fetchrow_array; my $int = $row[0]; if ($int > $interval) { - $logger->debug("[Interval elapsed, sending the message]: From: $from To:$to"); + $logger->info("[Interval elapsed, sending the message]: From: $from To:$to"); $query = qq{UPDATE vacation_notification SET notified_at=NOW() WHERE on_vacation=? AND notified=?}; $stm = $dbh->prepare($query); if (!$stm) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2009-10-21 08:00:17
|
Revision: 734 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=734&view=rev Author: GingerDog Date: 2009-10-21 08:00:07 +0000 (Wed, 21 Oct 2009) Log Message: ----------- vacation.pl: see email conversation with st...@ba... and #2835877 (https://sourceforge.net/tracker/?func=detail&aid=2835877&group_id=191583&atid=937964); thanks to stevan for taking the time to explain why he was right :) - this change makes the vacation script look for user#do...@va...main in the alias table, rather than user@domain, which is a better check (as it implies they also have vacation turned on) Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2009-10-20 19:25:20 UTC (rev 733) +++ trunk/VIRTUAL_VACATION/vacation.pl 2009-10-21 08:00:07 UTC (rev 734) @@ -17,7 +17,7 @@ # Slightly better logging which includes messageid # Avoid infinite loops with domain aliases # -# 2005-01-19 Troels Arvin <tr...@ar...> +# 2005-01-19 Troels Arvin <troels at arvin.dk> # PostgreSQL-version. # Normalized DB schema from one vacation table ("vacation") # to two ("vacation", "vacation_notification"). Uses @@ -27,18 +27,18 @@ # to try to avoid SQL injection. # International characters are now handled well. # -# 2005-01-21 Troels Arvin <tr...@ar...> +# 2005-01-21 Troels Arvin <troels at arvin.dk> # Uses the Email::Valid package to avoid sending notices # to obviously invalid addresses. # -# 2007-08-15 David Goodwin <da...@pa...> +# 2007-08-15 David Goodwin <david at palepurple.co.uk> # Use the Perl Mail::Sendmail module for sending mail # Check for headers that start with blank lines (patch from forum) # -# 2007-08-20 Martin Ambroz <am...@tr...> +# 2007-08-20 Martin Ambroz <amsys at trustica.cz> # Added initial Unicode support # -# 2008-05-09 Fabio Bonelli <fab...@li...> +# 2008-05-09 Fabio Bonelli <fabiobonelli at libero.it> # Properly handle failed queries to vacation_notification. # Fixed log reporting. # @@ -326,10 +326,13 @@ $realemail = $email; $logger->debug("Found '\$email'\ has vacation active"); } else { + my $vemail = $email; + $vemail =~ s/\@/#/g; + $vemail = $vemail . "\@" . $vacation_domain; $logger->debug("Looking for alias records that \'$email\' resolves to with vacation turned on"); - $query = qq{SELECT goto FROM alias WHERE address=? AND (goto LIKE ? OR goto LIKE ? OR goto LIKE ?)}; + $query = qq{SELECT goto FROM alias WHERE address=? AND (goto LIKE ? OR goto LIKE ? OR goto LIKE ? OR goto = ?)}; $stm = $dbh->prepare($query) or panic_prepare($query); - $stm->execute($email,"$email,%","%,$email","%,$email,%") or panic_execute($query,"address='$email'"); + $stm->execute($email,"$vemail,%","%,$vemail","%,$vemail,%", "$vemail") or panic_execute($query,"address='$email'"); $rv = $stm->rows; # Recipient is an alias, check if mailbox has vacation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Gin...@us...> - 2012-05-24 11:15:09
|
Revision: 1389 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1389&view=rev Author: GingerDog Date: 2012-05-24 11:14:58 +0000 (Thu, 24 May 2012) Log Message: ----------- add a friendly from address to vacation messages; probably needs more work to beautify it though...; change error handling if we cannot send the reply to be hopefully more robust Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2012-05-13 21:09:03 UTC (rev 1388) +++ trunk/VIRTUAL_VACATION/vacation.pl 2012-05-24 11:14:58 UTC (rev 1389) @@ -487,6 +487,7 @@ my $from = $email; my $to = $orig_from; my %smtp_connection; + my $friendly_from = "Vacation Service"; %smtp_connection = ( 'smtp' => $smtp_server, 'port' => $smtp_server_port, @@ -499,12 +500,14 @@ 'ctype' => 'text/plain; charset=UTF-8', 'headers' => 'Precedence: junk', 'headers' => 'X-Loop: Postfix Admin Virtual Vacation', + 'on_errors' => 'die', # raise exception on error ); my %mail; # I believe Mail::Sender qp encodes the subject, so we no longer need to. %mail = ( 'subject' => $subject, 'from' => $from, + 'fake_from' => $friendly_from . " <$from>", 'to' => $to, 'msg' => encode_base64($body) ); @@ -513,12 +516,17 @@ $logger->info(%mail); return 0; } - $Mail::Sender::NO_X_MAILER = 1; - my $sender = new Mail::Sender({%smtp_connection}); - $sender->Open({%mail}); - $sender->SendLineEnc($body); - $sender->Close() or $logger->error('Failed to send vacation response: ' . $sender->{'error_msg'}); - $logger->debug("Vacation response sent to $to, from $from"); + eval { + $Mail::Sender::NO_X_MAILER = 1; + my $sender = new Mail::Sender({%smtp_connection}); + $sender->Open({%mail}); + $sender->SendLineEnc($body); + $sender->Close(); + $logger->debug("Vacation response sent to $to, from $from"); + }; + if ($@) { + $logger->error("Failed to send vacation response: $@ / " . $Mail::Sender::Error); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <va...@us...> - 2013-03-12 19:33:56
|
Revision: 1442 http://sourceforge.net/p/postfixadmin/code/1442 Author: valkum Date: 2013-03-12 19:33:54 +0000 (Tue, 12 Mar 2013) Log Message: ----------- added custom noreply detection Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2013-03-03 01:23:50 UTC (rev 1441) +++ trunk/VIRTUAL_VACATION/vacation.pl 2013-03-12 19:33:54 UTC (rev 1442) @@ -174,6 +174,15 @@ # disabled by default our $interval = 0; +# Send vacation mails to do-not-reply email adresses. +# By default vacation email adresses will be sent. +# For now emails from bounce|do-not-reply|facebook|linkedin|list-|myspace|twitter won't +# be answered when $custom_noreply_pattern is set to 1. +# default = 0 +our $custom_noreply_pattern = 0; +our $noreply_pattern = 'bounce|do-not-reply|facebook|linkedin|list-|myspace|twitter'; + + # instead of changing this script, you can put your settings to /etc/mail/postfixadmin/vacation.conf # or /etc/postfixadmin/vacation.conf just use Perl syntax there to fill the variables listed above # (without the "our" keyword). Example: @@ -586,7 +595,8 @@ my $logger = get_logger(); if($address =~ /^(noreply|postmaster|mailer\-daemon|listserv|majordomo|owner\-|request\-|bounces\-)/i || - $address =~ /\-(owner|request|bounces)\@/i ) { + $address =~ /\-(owner|request|bounces)\@/i || + ($custom_noreply_pattern == 1 && $adress =~ /^.*($noreply_pattern).*/i) ) { $logger->debug("sender $address contains $1 - will not send vacation message"); exit(0); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2013-03-14 23:18:00
|
Revision: 1444 http://sourceforge.net/p/postfixadmin/code/1444 Author: christian_boltz Date: 2013-03-14 23:17:57 +0000 (Thu, 14 Mar 2013) Log Message: ----------- vacation.pl: - fix typo in variable name Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2013-03-12 20:08:57 UTC (rev 1443) +++ trunk/VIRTUAL_VACATION/vacation.pl 2013-03-14 23:17:57 UTC (rev 1444) @@ -596,7 +596,7 @@ if($address =~ /^(noreply|postmaster|mailer\-daemon|listserv|majordomo|owner\-|request\-|bounces\-)/i || $address =~ /\-(owner|request|bounces)\@/i || - ($custom_noreply_pattern == 1 && $adress =~ /^.*($noreply_pattern).*/i) ) { + ($custom_noreply_pattern == 1 && $address =~ /^.*($noreply_pattern).*/i) ) { $logger->debug("sender $address contains $1 - will not send vacation message"); exit(0); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2010-10-13 23:51:19
|
Revision: 875 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=875&view=rev Author: christian_boltz Date: 2010-10-13 23:51:12 +0000 (Wed, 13 Oct 2010) Log Message: ----------- vacation.pl: - drop unneeded backslashes. The first one caused logging of "$email" instead of the variable content, the others are just cosmetical. Reported by Johan Meiring (jmeiring) https://sourceforge.net/tracker/?func=detail&atid=937964&aid=3086899&group_id=191583 Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2010-10-12 20:45:24 UTC (rev 874) +++ trunk/VIRTUAL_VACATION/vacation.pl 2010-10-13 23:51:12 UTC (rev 875) @@ -327,12 +327,12 @@ # Recipient has vacation if ($rv == 1) { $realemail = $email; - $logger->debug("Found '\$email'\ has vacation active"); + $logger->debug("Found '$email' has vacation active"); } else { my $vemail = $email; $vemail =~ s/\@/#/g; $vemail = $vemail . "\@" . $vacation_domain; - $logger->debug("Looking for alias records that \'$email\' resolves to with vacation turned on"); + $logger->debug("Looking for alias records that '$email' resolves to with vacation turned on"); $query = qq{SELECT goto FROM alias WHERE address=? AND (goto LIKE ? OR goto LIKE ? OR goto LIKE ? OR goto = ?)}; $stm = $dbh->prepare($query) or panic_prepare($query); $stm->execute($email,"$vemail,%","%,$vemail","%,$vemail,%", "$vemail") or panic_execute($query,"address='$email'"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2010-11-01 15:46:24
|
Revision: 881 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=881&view=rev Author: christian_boltz Date: 2010-11-01 15:46:16 +0000 (Mon, 01 Nov 2010) Log Message: ----------- vacation.pl: some changes after using perlcritic.org - in detail: - removed unused variable $spam - use ':encoding(UTF-8)' instead of ':utf8' to validate input against invalid utf8 sequences - foreach creates its own instance of $item - marking it with "my $item" - replaced lots of "..." with '...' BTW: Thanks to the nice guy who recommended perlcritic.org at the openSUSE conference! Modified Paths: -------------- trunk/VIRTUAL_VACATION/vacation.pl Modified: trunk/VIRTUAL_VACATION/vacation.pl =================================================================== --- trunk/VIRTUAL_VACATION/vacation.pl 2010-10-17 12:17:48 UTC (rev 880) +++ trunk/VIRTUAL_VACATION/vacation.pl 2010-11-01 15:46:16 UTC (rev 881) @@ -163,10 +163,10 @@ # or /etc/postfixadmin/vacation.conf just use Perl syntax there to fill the variables listed above # (without the "our" keyword). Example: # $db_username = 'mail'; -if (-f "/etc/mail/postfixadmin/vacation.conf") { - require "/etc/mail/postfixadmin/vacation.conf"; -} elsif (-f "/etc/postfixadmin/vacation.conf") { - require "/etc/postfixadmin/vacation.conf"; +if (-f '/etc/mail/postfixadmin/vacation.conf') { + require '/etc/mail/postfixadmin/vacation.conf'; +} elsif (-f '/etc/postfixadmin/vacation.conf') { + require '/etc/postfixadmin/vacation.conf'; } # =========== end configuration =========== @@ -178,7 +178,7 @@ } } -my ($from, $to, $cc, $replyto , $subject, $messageid, $lastheader, $smtp_sender, $smtp_recipient, %opts, $spam, $test_mode, $logger); +my ($from, $to, $cc, $replyto , $subject, $messageid, $lastheader, $smtp_sender, $smtp_recipient, %opts, $test_mode, $logger); $subject=''; $messageid='unknown'; @@ -186,12 +186,12 @@ # Setup a logger... # getopts('f:t:', \%opts) or die "Usage: $0 [-t yes] -f sender -- recipient\n\t-t for testing only\n"; -$opts{f} and $smtp_sender = $opts{f} or die "-f sender not present on command line"; +$opts{f} and $smtp_sender = $opts{f} or die '-f sender not present on command line'; $test_mode = 0; $opts{t} and $test_mode = 1; -$smtp_recipient = shift or die "recipient not given on command line"; +$smtp_recipient = shift or die 'recipient not given on command line'; -my $log_layout = Log::Log4perl::Layout::PatternLayout->new("%d %p> %F:%L %M - %m%n"); +my $log_layout = Log::Log4perl::Layout::PatternLayout->new('%d %p> %F:%L %M - %m%n'); if($test_mode == 1) { $logger = get_logger(); @@ -199,7 +199,7 @@ my $appender = Log::Log4perl::Appender->new('Log::Dispatch::Screen'); $appender->layout($log_layout); $logger->add_appender($appender); - $logger->debug("Test mode enabled"); + $logger->debug('Test mode enabled'); } else { $logger = get_logger(); if($log_to_file == 1) { @@ -231,7 +231,7 @@ $logger->level($DEBUG); } -binmode (STDIN,':utf8'); +binmode (STDIN,':encoding(UTF-8)'); my $dbh; if ($db_host) { @@ -241,13 +241,13 @@ } if (!$dbh) { - $logger->error("Could not connect to database"); # eval { } etc better here? + $logger->error('Could not connect to database'); # eval { } etc better here? exit(0); } my $db_true; # MySQL and PgSQL use different values for TRUE, and unicode support... -if ($db_type eq "mysql") { - $dbh->do("SET CHARACTER SET utf8;"); +if ($db_type eq 'mysql') { + $dbh->do('SET CHARACTER SET utf8;'); $db_true = '1'; } else { # Pg $dbh->do("SET CLIENT_ENCODING TO 'UTF8'"); @@ -465,7 +465,7 @@ my $sender = new Mail::Sender({%smtp_connection}); $sender->Open({%mail}); $sender->SendLineEnc($body); - $sender->Close() or $logger->error("Failed to send vacation response: " . $sender->{'error_msg'}); + $sender->Close() or $logger->error('Failed to send vacation response: ' . $sender->{'error_msg'}); $logger->debug("Vacation response sent to $to, from $from"); } } @@ -496,12 +496,11 @@ # remove duplicates my %seen = (); my @uniq; - my $item; - foreach $item (@ok) { + foreach my $item (@ok) { push(@uniq, $item) unless $seen{$item}++ } - my $result = lc(join(", ", @uniq)); + my $result = lc(join(', ', @uniq)); #$logger->debug("Result: $result"); return $result; } @@ -532,7 +531,7 @@ exit(0); } $address = strip_address($address); - if($address eq "") { + if($address eq '') { $logger->error("Address $address is not valid; exiting"); exit(0); } @@ -558,16 +557,16 @@ elsif (/^x\-spam\-(flag|status):\s+yes/i) { $logger->debug("x-spam-$1: yes found; exiting"); exit (0); } elsif (/^x\-facebook\-notify:/i) { $logger->debug('Mail from facebook, ignoring'); exit(0); } elsif (/^precedence:\s+(bulk|list|junk)/i) { $logger->debug("precedence: $1 found; exiting"); exit (0); } - elsif (/^x\-loop:\s+postfix\ admin\ virtual\ vacation/i) { $logger->debug("x-loop: postfix admin virtual vacation found; exiting"); exit (0); } + elsif (/^x\-loop:\s+postfix\ admin\ virtual\ vacation/i) { $logger->debug('x-loop: postfix admin virtual vacation found; exiting'); exit (0); } elsif (/^Auto\-Submitted:\s*no/i) { next; } - elsif (/^Auto\-Submitted:/i) { $logger->debug("Auto-Submitted: something found; exiting"); exit (0); } + elsif (/^Auto\-Submitted:/i) { $logger->debug('Auto-Submitted: something found; exiting'); exit (0); } elsif (/^List\-(Id|Post):/i) { $logger->debug("List-$1: found; exiting"); exit (0); } elsif (/^(x\-(barracuda\-)?spam\-status):\s+(yes)/i) { $logger->debug("$1: $3 found; exiting"); exit (0); } elsif (/^(x\-dspam\-result):\s+(spam|bl[ao]cklisted)/i) { $logger->debug("$1: $2 found; exiting"); exit (0); } elsif (/^(x\-(anti|avas\-)?virus\-status):\s+(infected)/i) { $logger->debug("$1: $3 found; exiting"); exit (0); } elsif (/^(x\-(avas\-spam|spamtest|crm114|razor|pyzor)\-status):\s+(spam)/i) { $logger->debug("$1: $3 found; exiting"); exit (0); } elsif (/^(x\-osbf\-lua\-score):\s+[0-9\/\.\-\+]+\s+\[([-S])\]/i) { $logger->debug("$1: $2 found; exiting"); exit (0); } - else {$lastheader = "" ; } + else {$lastheader = '' ; } } if($smtp_recipient =~ /\@$vacation_domain/) { @@ -589,7 +588,7 @@ $to = strip_address($to); $cc = strip_address($cc); $from = check_and_clean_from_address($from); -if($replyto ne "") { +if($replyto ne '') { # if reply-to is invalid, or looks like a mailing list, then we probably don't want to send a reply. $replyto = check_and_clean_from_address($replyto); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |