# HG changeset patch # User heiko # Date 1216644851 0 # Node ID 7917e610abcd090012b4b1991c9f774e1dacbaf9 # Parent d14cfa1c1298fcf9646ee6c5f3cde55310dd48c0 - perltidy diff -r d14cfa1c1298 -r 7917e610abcd mail2db --- a/mail2db Mon Jul 21 12:30:37 2008 +0000 +++ b/mail2db Mon Jul 21 12:54:11 2008 +0000 @@ -16,7 +16,7 @@ use Time::HiRes qw(gettimeofday tv_interval); use if $ENV{DEBUG} => "Data::Dumper"; -my $T0 = [gettimeofday()]; +my $T0 = [ gettimeofday() ]; my $OUTPUT_CHARSET = "UTF8"; my $DEFAULT_INPUT_CHARSET = "ASCII"; @@ -36,12 +36,11 @@ sub get_headers($); sub decode_headers($$); - - MAIN: { openlog( "mail2db", LOG_PID | ( -t STDIN ? LOG_PERROR: 0 ), LOG_MAIL ); - $SIG{__DIE__} = sub { die $@ if $^S; syslog(LOG_ERR, "ERROR: %s", join "", @_); exit 2 }; - $SIG{__WARN__} = sub { syslog(LOG_WARNING, "%s", join "", @_) }; + $SIG{__DIE__} = + sub { die $@ if $^S; syslog( LOG_ERR, "ERROR: %s", join "", @_ ); exit 2 }; + $SIG{__WARN__} = sub { syslog( LOG_WARNING, "%s", join "", @_ ) }; if ( -f ( $_ = "/etc/mail2db.conf" ) ) { open( X, $_ ) or die "Can't open $_: $!\n"; @@ -54,7 +53,7 @@ "h|help" => \$opt_help, "m|man" => \$opt_man, "n|dry" => \$opt_dry, - "debug!" => \$opt_debug, + "debug!" => \$opt_debug, ) or pod2usage(); pod2usage( -verbose => 1, -exitval => 0 ) if $opt_help; @@ -65,9 +64,9 @@ { RaiseError => 1, FetchHashKeyName => "NAME_lc", AutoCommit => 0 } ) or die; - # The $message contains the in-core representation, the MIME parser - # works on it. The $tmpfile (handle) will be used for access to the - # original unmodified message. + # The $message contains the in-core representation, the MIME parser + # works on it. The $tmpfile (handle) will be used for access to the + # original unmodified message. my ( $tmpfile, $message ) = get_message(); decode_headers( $message, $OUTPUT_CHARSET ); @@ -102,7 +101,7 @@ my $msg_id; { local $/ = undef; - seek($tmpfile, 0, 0); + seek( $tmpfile, 0, 0 ); $insert_message->execute(<$tmpfile>); $msg_id = $DBH->last_insert_id( undef, undef, message => "id" ); syslog( LOG_DEBUG, "message id: $msg_id" ) if $opt_debug; @@ -135,7 +134,7 @@ } $DBH->commit if not $opt_dry; - syslog(LOG_NOTICE, "inserted message $msg_id (%.1fs)", tv_interval($T0)); + syslog( LOG_NOTICE, "inserted message $msg_id (%.1fs)", tv_interval($T0) ); } @@ -146,17 +145,17 @@ # unfortunely the MIME::Parser may temporary files too my $tmpfile = new File::Temp( TEMPLATE => "/tmp/mail2db-XXXXXX" ); local $_ = <>; - die "No input" if not defined; + die "No input" if not defined; if ( !/^From\s/ ) { my $nl = /\r?\n$/; print {$tmpfile} "From - @{[scalar localtime]}$nl", $_; } - { - local $/ = undef; - print {$tmpfile} $_, <>; - } + { + local $/ = undef; + print {$tmpfile} $_, <>; + } $tmpfile->autoflush(1); seek( $tmpfile, 0, 0 );