SF.net SVN: postfixadmin:[428] trunk/VIRTUAL_VACATION/vacation.pl
Brought to you by:
christian_boltz,
gingerdog
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. |