aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2019-11-07 03:53:33 +0100
committerGuilhem Moulin <guilhem@fripost.org>2019-11-07 18:52:51 +0100
commitbf9272b19724c351cd211067afb177c37c87f210 (patch)
tree34bcde54708edc67cd4598167729cd3c9400c953
parentab2774a3039efc0efe0a4bc840675bf6d36435d7 (diff)
wibble
-rwxr-xr-xinterimap17
-rw-r--r--lib/Net/IMAP/InterIMAP.pm1
2 files changed, 10 insertions, 8 deletions
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 = ();
diff --git a/lib/Net/IMAP/InterIMAP.pm b/lib/Net/IMAP/InterIMAP.pm
index ff10854..dd4134d 100644
--- a/lib/Net/IMAP/InterIMAP.pm
+++ b/lib/Net/IMAP/InterIMAP.pm
@@ -520,6 +520,7 @@ sub stats($) {
# Destroy a Net::IMAP::InterIMAP object.
sub DESTROY($) {
+ local($., $@, $!, $^E, $?);
my $self = shift;
$self->{_STATE} = 'LOGOUT';