From bf9272b19724c351cd211067afb177c37c87f210 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 7 Nov 2019 03:53:33 +0100 Subject: wibble --- interimap | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'interimap') diff --git a/interimap b/interimap index 207d389..afe18e9 100755 --- a/interimap +++ b/interimap @@ -88,17 +88,17 @@ my $CONF = do { my ($DBFILE, $LOGGER_FD, %LIST); { - $DBFILE = $CONF->{_}->{database} if defined $CONF->{_}; + $CONF->{_} //= {}; + $DBFILE = $CONF->{_}->{database}; $DBFILE //= $CONF->{remote}->{host}.'.db' if defined $CONF->{remote}; $DBFILE //= $CONF->{local}->{host}. '.db' if defined $CONF->{local}; die "Missing option database" unless defined $DBFILE; $DBFILE = xdg_basedir( XDG_DATA_HOME => ".local/share", $NAME, $DBFILE ); - if (defined $CONF->{_} and defined $CONF->{_}->{logfile}) { + if (defined (my $l = $CONF->{_}->{logfile})) { require 'POSIX.pm'; require 'Time/HiRes.pm'; - open $LOGGER_FD, '>>', $CONF->{_}->{logfile} - or die "Can't open $CONF->{_}->{logfile}: $!\n"; + open $LOGGER_FD, '>>', $l or die "Can't open $l: $!\n"; $LOGGER_FD->autoflush(1); my $flags = fcntl($LOGGER_FD, F_GETFD, 0) or die "fcntl F_GETFD: $!"; fcntl($LOGGER_FD, F_SETFD, $flags | FD_CLOEXEC) or die "fcntl F_SETFD: $!"; @@ -149,7 +149,8 @@ my ($IMAP, $lIMAP, $rIMAP); sub cleanup() { undef $_ foreach grep defined, ($IMAP, $lIMAP, $rIMAP); logger(undef, "Cleaning up...") if $CONFIG{debug}; - close $LOGGER_FD if defined $LOGGER_FD; + $LOGGER_FD->close() if defined $LOGGER_FD and defined $LOGGER_FD->fileno + and $LOGGER_FD->fileno != fileno STDERR; $DBH->disconnect() if defined $DBH; } $SIG{INT} = sub { msg(undef, $!); cleanup(); exit 1; }; @@ -219,8 +220,8 @@ foreach my $name (qw/local remote/) { $config{'compress'} //= ($name eq 'local' ? 0 : 1); $config{keepalive} = 1 if $CONFIG{watch} and $config{type} ne 'tunnel'; - $IMAP->{$name} = { client => Net::IMAP::InterIMAP::->new(%config) }; - my $client = $IMAP->{$name}->{client}; + my $client = Net::IMAP::InterIMAP::->new(%config); + $IMAP->{$name} = { client => $client }; die "Non $_-capable IMAP server.\n" foreach $client->incapable(qw/LIST-EXTENDED UIDPLUS/); die "Non LIST-STATUS-capable IMAP server.\n" if !$CONFIG{notify} and $client->incapable('LIST-STATUS'); @@ -1161,7 +1162,7 @@ sub callback_new_message($$$$;$$$) { } else { # use MULTIAPPEND (RFC 3502) - # proceed by batches of 1MB to save roundtrips without blowing up the memory + # proceed by 1MiB batches to save roundtrips without blowing up the memory if (@$buff and $$bufflen + $length > 1048576) { @UIDs = callback_new_message_flush($idx, $mailbox, $name, @$buff); @$buff = (); -- cgit v1.2.3