# HG changeset patch # User heiko # Date 1216588898 0 # Node ID 2638ae65724069bf9dc3d7b22fa3e9712d6cb604 # Parent 68aafeeb1559896af767aec00b0b2e21366cbd97 - now working with config file diff -r 68aafeeb1559 -r 2638ae657240 Makefile --- a/Makefile Sun Jul 20 20:58:37 2008 +0000 +++ b/Makefile Sun Jul 20 21:21:38 2008 +0000 @@ -7,14 +7,14 @@ .PHONY: all clean install -all: .ok.mailscan +all: .ok.mail2db install: all install -d -m 0755 ${DESTDIR}${sbindir}/ install -d -m 0755 ${DESTDIR}${man8dir}/ - install -m 0755 mailscan ${DESTDIR}${sbindir}/ + install -m 0755 mail2db ${DESTDIR}${sbindir}/ umask 022; \ - pod2man --section 8 mailscan | gzip >${DESTDIR}${man8dir}/mailscan.8.gz + pod2man --section 8 mail2db | gzip >${DESTDIR}${man8dir}/mail2db.8.gz clean: -rm -f .ok.* diff -r 68aafeeb1559 -r 2638ae657240 mail2db --- a/mail2db Sun Jul 20 20:58:37 2008 +0000 +++ b/mail2db Sun Jul 20 21:21:38 2008 +0000 @@ -24,11 +24,11 @@ my $opt_help = 0; my $opt_man = 0; my $opt_dry = 0; +my $opt_dsn = ""; +my $opt_dbuser = ""; +my $opt_dbpass = ""; -my $DBH = - DBI->connect($DSN, @CREDENTIALS, - { RaiseError => 1, FetchHashKeyName => "NAME_lc", AutoCommit => 0 }) - or die; +my $DBH; # read the message into tmpfile (passed as arg) and return "Message" object sub get_message(); @@ -37,7 +37,15 @@ MAIN: { openlog("mail2db", LOG_PID | (-t STDERR ? LOG_PERROR : 0), LOG_MAIL); + + if (-f ($_ = "/etc/mail2db.conf")) { + open(X, $_) or die "Can't open $_: $!\n"; + unshift @ARGV, map { chomp; $_ } ; + } GetOptions( + "dsn=s" => \$opt_dsn, + "dbuser=s" => \$opt_dbuser, + "dbpass=s" => \$opt_dbpass, "h|help" => \$opt_help, "m|man" => \$opt_man, "n|dry" => \$opt_dry, @@ -46,6 +54,10 @@ pod2usage(-verbose => 1, -exitval => 0) if $opt_help; pod2usage(-verbose => 2, -exitval => 0) if $opt_man; + $DBH = DBI->connect($opt_dsn, $opt_dbuser, $opt_dbpass, + { RaiseError => 1, FetchHashKeyName => "NAME_lc", AutoCommit => 0 }) + or die; + my ($tmpfile, $message) = get_message(); decode_headers($message, $OUTPUT_CHARSET); @@ -197,20 +209,30 @@ =head1 SYNOPSIS - mail2db [-n|--dry] +mail2db [--dsn=I] [--dbuser=I] [--dbpass=I] [-n|--dry] - mail2db [-h|--help] - mail2db [-m|--man] +mail2db [-h|--help] +mail2db [-m|--man] =head1 DESCRIPTION B reads a RFC822 message from stdin and saves it into a database. -For more information please the the source code itself. +For more information please see the source code itself. =head1 OPTIONS =over 4 +=item B<--dsn> + +The data source name. Something like "DBI:mysql:mail:hostname=schnuffi". [default: ""] + +=item B<--dbuser> + +=item B<--dbpass> + +The credentials to access the database. [default: ""] + =item B<-n>|B<--dry> Do not modify the database, just start a transaction but do not commit it. @@ -257,6 +279,10 @@ JOIN header_field ON header_field.id = message_header.header_field_id ORDER BY message_header.message_id, header_field.name, message_header.idx; +=head1 FILES + +Some configuration can be put to F. + =head1 AUTHOR Heiko Schlittermann L