SF.net SVN: postfixadmin:[619] trunk/ADDITIONS/fetchmail.pl
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2009-04-09 20:06:01
|
Revision: 619 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=619&view=rev Author: christian_boltz Date: 2009-04-09 20:05:45 +0000 (Thu, 09 Apr 2009) Log Message: ----------- fetchmail.pl: - added support for PgSQL - based on patch from johker, https://sourceforge.net/tracker/?func=detail&atid=937966&aid=2747526&group_id=191583 - rename config variables to use names known from vacation.pl - add support for external config file /etc/mail/postfixadmin/fetchmail.conf Modified Paths: -------------- trunk/ADDITIONS/fetchmail.pl Modified: trunk/ADDITIONS/fetchmail.pl =================================================================== --- trunk/ADDITIONS/fetchmail.pl 2009-04-08 20:17:24 UTC (rev 618) +++ trunk/ADDITIONS/fetchmail.pl 2009-04-09 20:05:45 UTC (rev 619) @@ -8,6 +8,35 @@ # require liblockfile-simple-perl use LockFile::Simple qw(lock trylock unlock); +###################################################################### +########## Change the following variables to fit your needs ########## + +# database settings + +# database backend - uncomment one of these +our $db_type = 'Pg'; +#my $db_type = 'mysql'; + +# host name +our $db_host="127.0.0.1"; +# database name +our $db_name="postfix"; +# database username +our $db_username="mail"; +# database password +our $db_password="CHANGE_ME!"; + +# instead of changing this script, you can put your settings to /etc/mail/postfixadmin/fetchmail.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/fetchmail.conf") { + require "/etc/mail/postfixadmin/fetchmail.conf"; +} + + +#################### Don't change anything below! #################### +###################################################################### + openlog("fetchmail-all", "pid", "mail"); sub log_and_die { @@ -30,11 +59,6 @@ } } -# mysql settings -$database="mailadmin"; -$hostname="127.0.0.1"; -$user="mail"; - $run_dir="/var/run/fetchmail"; # use specified config file @@ -42,26 +66,37 @@ do $configfile; } -$dsn = "DBI:mysql:database=$database;host=$hostname"; +if($db_type eq "Pg" || $db_type eq "mysql") { + $dsn = "DBI:$db_type:database=$db_name;host=$db_host"; +} else { + log_and_die "unsupported db_type $db_type"; +} + $lock_file=$run_dir . "/fetchmail-all.lock"; $lockmgr = LockFile::Simple->make(-autoclean => 1, -max => 1); $lockmgr->lock($lock_file) || log_and_die "can't lock ${lock_file}"; -#mysql connect -$dbh = DBI->connect($dsn, $user, $password) || log_and_die "cannot connect the database"; +# database connect +$dbh = DBI->connect($dsn, $db_username, $db_password) || log_and_die "cannot connect the database"; -$sql=<<SQL; -SELECT id,mailbox,src_server,src_auth,src_user,src_password,src_folder,fetchall,keep,protocol,mda,extra_options,usessl -FROM fetchmail -WHERE unix_timestamp(now())-unix_timestamp(date) > poll_time*60 -SQL +if($db_type eq "Pg") { + $sql_cond = "date_part('epoch',now())-date_part('epoch',date)"; +} elsif($db_type eq "mysql") { + $sql_cond = "unix_timestamp(now())-unix_timestamp(date)"; +} +$sql = " + SELECT id,mailbox,src_server,src_auth,src_user,src_password,src_folder,fetchall,keep,protocol,mda,extra_options,usessl + FROM fetchmail + WHERE $sql_cond > poll_time*60 + "; + my (%config); map{ my ($id,$mailbox,$src_server,$src_auth,$src_user,$src_password,$src_folder,$fetchall,$keep,$protocol,$mda,$extra_options,$usessl)=@$_; - syslog("info","fetch ${src_user}@${src_server} for ${mailbox}"); + syslog("info","fetch ${src_user}@${src_server} for ${mailbox}"); $cmd="user '${src_user}' there with password '".decode_base64($src_password)."'"; $cmd.=" folder '${src_folder}'" if ($src_folder); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |