aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2015-08-09 20:41:59 +0200
committerGuilhem Moulin <guilhem@fripost.org>2015-08-09 20:41:59 +0200
commitc1549a74c99904fb2648240cab239d61ab0c9522 (patch)
tree37c574fb46e5c924c5059d49570987f635e7b060 /lib
parent8f56dacdbc3459959b3200e776387d34f91e968c (diff)
parentb1985240f59a22b27824c9fdcb79998a1c7c0396 (diff)
Merge branch 'master' into debian
Diffstat (limited to 'lib')
-rw-r--r--lib/Net/IMAP/Sync.pm22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/Net/IMAP/Sync.pm b/lib/Net/IMAP/Sync.pm
index 47c6258..85ca487 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);
@@ -343,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");
@@ -392,7 +400,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 +408,11 @@ 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) {
+ 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';
$self->{'logger-fd'}->say($prefix, ': ', @_);