--- vacation.pl.original 2009-03-15 16:42:57.000000000 -0600 +++ vacation.pl 2009-03-26 18:29:48.000000000 -0600 @@ -40,6 +40,9 @@ # Properly handle failed queries to vacation_notification. # Fixed log reporting. # +# 2009-01-10 Gary V - mr88talent at yahoo dot com +# Patched to allow the use of sendmail binary instead of Mail::Sendmail +# # Requirements: # You need to have the DBD::Pg or DBD::mysql perl-module installed. # You need to have the Mail::Sendmail module installed. @@ -87,7 +90,11 @@ my $db_name = 'postfix'; # smtp server used to send vacation e-mails +# You can use smtp ($use_smtp = 1;) which uses Mail::Sendmail +# or instead use the sendmail binary ($use_smtp = 0;) my $smtp_server = 'localhost'; +my $sendmail = "/usr/sbin/sendmail"; +my $use_smtp = 0; my $syslog = 1; @@ -164,7 +171,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 @@ -222,6 +229,21 @@ do_debug('Mail::Sendmail said :' . $Mail::Sendmail::log); } +sub do_mail_sendmail { + my ($from, $to, $subject, $body, $orig_msgID) = @_; + open (MAIL, "| $sendmail -t -f \"<>\"") or die ("Unable to open sendmail"); + print MAIL "From: $from\n"; + print MAIL "To: $to\n"; + print MAIL "Subject: $subject\n"; + if ( $orig_msgID ) { + print MAIL "References: $orig_msgID\n"; + print MAIL "In-Reply-To: $orig_msgID\n"; + } + print MAIL "X-Loop: Postfix Admin Virtual Vacation\n\n"; + print MAIL "$body"; + close (MAIL) or die ("Unable to close sendmail"); +} + sub panic { my ($arg) = @_; do_log('','','','',"$arg"); @@ -313,8 +335,12 @@ if (already_notified($email, $orig_from)) { return; } do_debug ("[SEND RESPONSE] for $orig_messageid:\n", "FROM: $email (orig_to: $orig_to)\n", "TO: $orig_from\n", "VACATION SUBJECT: $row[0]\n", "VACATION BODY: $row[1]\n"); - # do_mail(from, to, subject, body); - do_mail ($email, $orig_from, $row[0], $row[1]); + # do_mail(from, to, subject, body); or do_mail_sendmail(from, to, subject, body, original message ID); + if ($use_smtp) { + do_mail ($email, $orig_from, $row[0], $row[1]); + } else { + do_mail_sendmail ($email, $orig_from, $row[0], $row[1], $orig_messageid); + } do_log ($orig_messageid, $orig_to, $orig_from, ''); }