From 0b151d0aa91bda0a1498dd78a23f8302588baa8d Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 31 Jul 2015 17:17:29 +0200 Subject: typo --- imapsync.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imapsync.1 b/imapsync.1 index d794d1a..fdbf2fe 100644 --- a/imapsync.1 +++ b/imapsync.1 @@ -185,7 +185,7 @@ Relative paths start from \fI$XDG_DATA_HOME/imapsync\fR, or is unset. This option is only available in the default section. (Default: \(lq\fIhost\fR.db\)\(rq, where \fIhost\fR is taken from the -\(lq[remote]\(rq or \(lq[local]\(rq sections, in that order. +\(lq[remote]\(rq or \(lq[local]\(rq sections, in that order.) .TP .I list-mailbox -- cgit v1.2.3 From 74ef024258870c9f767688f9305c1fab3e4ce393 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 31 Jul 2015 17:20:44 +0200 Subject: Add a note regrading the default database with type=tunnel. --- imapsync.1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imapsync.1 b/imapsync.1 index fdbf2fe..b9ec795 100644 --- a/imapsync.1 +++ b/imapsync.1 @@ -235,6 +235,8 @@ One of \(lqimap\(rq, \(lqimaps\(rq or \(lqtunnel\(rq. IMAP over SSL/TLS connections over a INET socket. \fItype\fR=tunnel causes \fBimapsync\fR to open a pipe to a \fIcommand\fR instead of a raw socket. +Note that specifying \fItype\fR=tunnel in the \(lq[remote]\(rq section +makes the default \fIdatabase\fR to be \(lqlocalhost.db\(rq. (Default: \(lqimaps\(rq.) .TP -- cgit v1.2.3 From 69502140d2e229a314bb1eb192d31b9a2c14f981 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 31 Jul 2015 22:40:28 +0200 Subject: Log debug messages to STDERR unless 'logfile' is set. However don't include timestamps to STDERR, that's the job of the syslog. --- imapsync | 10 ++++++++-- lib/Net/IMAP/Sync.pm | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/imapsync b/imapsync index b0226c3..30982af 100755 --- a/imapsync +++ b/imapsync @@ -96,6 +96,9 @@ my ($DBFILE, $LOCKFILE, $LOGGER_FD); or die "Can't open $CONF->{_}->{logfile}: $!\n"; $LOGGER_FD->autoflush(1); } + elsif ($CONFIG{debug}) { + $LOGGER_FD = \*STDERR; + } } my $DBH; @@ -196,14 +199,17 @@ $DBH->do('PRAGMA foreign_keys = ON'); sub msg($@) { my $name = shift; return unless @_; - logger($name, @_) if defined $LOGGER_FD and $LOGGER_FD ne \*STDERR; + logger($name, @_) if defined $LOGGER_FD and $LOGGER_FD->fileno != fileno STDERR; my $prefix = defined $name ? "$name: " : ''; print STDERR $prefix, @_, "\n"; } sub logger($@) { my $name = shift; return unless @_ and defined $LOGGER_FD; - my $prefix = strftime "%b %e %H:%M:%S ", localtime; + my $prefix = ''; + if ($LOGGER_FD->fileno != fileno STDERR) { + $prefix = strftime "%b %e %H:%M:%S ", localtime; + } $prefix .= "$name: " if defined $name; $LOGGER_FD->say($prefix, @_); } diff --git a/lib/Net/IMAP/Sync.pm b/lib/Net/IMAP/Sync.pm index 47c6258..b44f0a6 100644 --- a/lib/Net/IMAP/Sync.pm +++ b/lib/Net/IMAP/Sync.pm @@ -392,7 +392,7 @@ sub DESTROY($) { sub log($@) { my $self = shift; return unless @_; - $self->logger(@_) if defined $self->{'logger-fd'} and $self->{'logger-fd'} ne \*STDERR; + $self->logger(@_) if defined $self->{'logger-fd'} and $self->{'logger-fd'}->fileno != fileno STDERR; my $prefix = defined $self->{name} ? $self->{name} : ''; $prefix .= "($self->{_SELECTED})" if $self->{_STATE} eq 'SELECTED'; print STDERR $prefix, ': ', @_, "\n"; @@ -400,7 +400,10 @@ sub log($@) { sub logger($@) { my $self = shift; return unless @_ and defined $self->{'logger-fd'}; - my $prefix = strftime "%b %e %H:%M:%S ", localtime; + my $prefix = ''; + if ($self->{'logger-fd'}->fileno != fileno STDERR) { + $prefix = strftime "%b %e %H:%M:%S ", localtime; + } $prefix .= defined "$self->{name}" ? $self->{name} : ''; $prefix .= "($self->{_SELECTED})" if $self->{_STATE} eq 'SELECTED'; $self->{'logger-fd'}->say($prefix, ': ', @_); -- cgit v1.2.3 From a9071cd1c10bcf3a2203a28cdbdf0a26b4db8641 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 31 Jul 2015 22:41:24 +0200 Subject: Log high precision timestamps in the logfile. Also, don't try to import POSIX or Time::HiRes unless the logfile is configured. --- imapsync | 6 ++++-- lib/Net/IMAP/Sync.pm | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/imapsync b/imapsync index 30982af..a007089 100755 --- a/imapsync +++ b/imapsync @@ -27,7 +27,6 @@ use Getopt::Long qw/:config posix_default no_ignore_case gnu_compat bundling auto_version/; use DBI (); use List::Util 'first'; -use POSIX 'strftime'; use lib 'lib'; use Net::IMAP::Sync qw/read_config compact_set $IMAP_text $IMAP_cond/; @@ -92,6 +91,8 @@ my ($DBFILE, $LOCKFILE, $LOGGER_FD); $LOCKFILE = $DBFILE =~ s/([^\/]+)\z/.$1.lck/r; if (defined $CONF->{_} and defined $CONF->{_}->{logfile}) { + require 'POSIX.pm'; + require 'Time/HiRes.pm'; open $LOGGER_FD, '>>', $CONF->{_}->{logfile} or die "Can't open $CONF->{_}->{logfile}: $!\n"; $LOGGER_FD->autoflush(1); @@ -208,7 +209,8 @@ sub logger($@) { return unless @_ and defined $LOGGER_FD; my $prefix = ''; if ($LOGGER_FD->fileno != fileno STDERR) { - $prefix = strftime "%b %e %H:%M:%S ", localtime; + my ($s, $us) = Time::HiRes::gettimeofday(); + $prefix = POSIX::strftime("%b %e %H:%M:%S", localtime($s)).".$us "; } $prefix .= "$name: " if defined $name; $LOGGER_FD->say($prefix, @_); diff --git a/lib/Net/IMAP/Sync.pm b/lib/Net/IMAP/Sync.pm index b44f0a6..4a9d431 100644 --- a/lib/Net/IMAP/Sync.pm +++ b/lib/Net/IMAP/Sync.pm @@ -23,7 +23,6 @@ use strict; use Config::Tiny (); use IO::Select (); use List::Util 'first'; -use POSIX 'strftime'; use Socket 'SO_KEEPALIVE'; use Exporter 'import'; @@ -288,6 +287,11 @@ sub new($%) { # are considered. $self->{_MODIFIED} = {}; + if (defined $self->{'logger-fd'} and $self->{'logger-fd'}->fileno != fileno STDERR) { + require 'POSIX.pm'; + require 'Time/HiRes.pm'; + } + # wait for the greeting my $x = $self->_getline(); $x =~ s/\A\* (OK|PREAUTH) // or $self->panic($x); @@ -402,7 +406,8 @@ sub logger($@) { return unless @_ and defined $self->{'logger-fd'}; my $prefix = ''; if ($self->{'logger-fd'}->fileno != fileno STDERR) { - $prefix = strftime "%b %e %H:%M:%S ", localtime; + my ($s, $us) = Time::HiRes::gettimeofday(); + $prefix = POSIX::strftime("%b %e %H:%M:%S", localtime($s)).".$us "; } $prefix .= defined "$self->{name}" ? $self->{name} : ''; $prefix .= "($self->{_SELECTED})" if $self->{_STATE} eq 'SELECTED'; -- cgit v1.2.3 From b1985240f59a22b27824c9fdcb79998a1c7c0396 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sun, 9 Aug 2015 20:38:30 +0200 Subject: Add support for SASL-IR (RFC 4959) to save a round-trip in AUTHENTICATE commands. --- lib/Net/IMAP/Sync.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Net/IMAP/Sync.pm b/lib/Net/IMAP/Sync.pm index 4a9d431..85ca487 100644 --- a/lib/Net/IMAP/Sync.pm +++ b/lib/Net/IMAP/Sync.pm @@ -347,9 +347,13 @@ sub new($%) { elsif ($mech eq 'PLAIN') { require 'MIME/Base64.pm'; $self->fail("Missing option $_") foreach grep {!defined $self->{$_}} qw/username password/; - $command = "AUTHENTICATE $mech"; my $credentials = MIME::Base64::encode_base64("\x00".$username."\x00".$password, ''); - $callback = sub($) {return $credentials}; + $command = "AUTHENTICATE $mech"; + if ($self->_capable('SASL-IR')) { # RFC 4959 SASL-IR + $command .= " $credentials"; + } else { + $callback = sub($) {return $credentials}; + } } else { $self->fail("Unsupported authentication mechanism: $mech"); -- cgit v1.2.3