aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Net/IMAP
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Net/IMAP')
-rw-r--r--lib/Net/IMAP/Sync.pm40
1 files changed, 25 insertions, 15 deletions
diff --git a/lib/Net/IMAP/Sync.pm b/lib/Net/IMAP/Sync.pm
index b952546..0b95276 100644
--- a/lib/Net/IMAP/Sync.pm
+++ b/lib/Net/IMAP/Sync.pm
@@ -321,7 +321,7 @@ sub new($%) {
$self->fail("Logins are disabled.") if grep {$_ eq 'LOGINDISABLED'} @caps;
my @mechs = grep defined, map { /^AUTH=(.+)/ ? $1 : undef } @caps;
- my $mech = (grep defined, map {my $m = $_; grep {$m eq $_} @mechs ? $m : undef}
+ my $mech = (grep defined, map {my $m = $_; (grep {$m eq $_} @mechs) ? $m : undef}
split(/ /, $self->{auth}))[0];
$self->fail("Failed to choose an authentication mechanism") unless defined $mech;
@@ -571,19 +571,22 @@ sub remove($@) {
my %vanished = map {$_ => 1} @{$self->{_VANISHED}};
- my @failed;
+ my (@failed, @expunged);
foreach my $uid (@set) {
if (exists $vanished{$uid}) {
- # ignore succesfully EXPUNGEd messages
- delete $vanished{$uid};
- delete $self->{_MODIFIED}->{$uid};
+ push @expunged, $uid
} else {
push @failed, $uid;
}
}
+
+ # ignore succesfully EXPUNGEd messages
+ delete @vanished{@expunged};
+ delete @{$self->{_MODIFIED}}{@expunged};
$self->{_VANISHED} = [ keys %vanished ];
- $self->warn("Could not EXPUNGE UID(s) ".compact_set(@failed)) if @failed;
+ $self->log("Removed UID ".compact_set(@expunged)) if @expunged and !$self->{quiet};
+ $self->warn("Could not UID EXPUNGE ".compact_set(@failed)) if @failed;
return @failed;
}
@@ -656,6 +659,8 @@ sub append($$$@) {
$cache->{UIDNEXT} = $UIDNEXT if ($cache->{UIDNEXT} // 0) < $UIDNEXT;
}
+ $self->log("Added ".($#appends+1)." message(s) to $mailbox, got new UID ".compact_set(@uids))
+ unless $self->{quiet};
return @uids;
}
@@ -844,12 +849,12 @@ sub pull_updates($) {
$self->_send("UID FETCH ".compact_set(@missing)." (MODSEQ FLAGS)") if @missing;
@missing = ();
}
-
+
# do that afterwards since the UID FETCH command above can produce VANISHED responses
my %vanished = map {$_ => 1} @{$self->{_VANISHED}};
- my @vanished = keys %vanished;
+ @vanished = keys %vanished;
$self->{_VANISHED} = [];
-
+
# ignore FLAG updates on VANISHED messages
delete @modified{@vanished};
}
@@ -947,6 +952,7 @@ sub push_flag_updates($$@) {
}
}
+ my @ok;
foreach my $uid (@set) {
if ($failed{$uid}) {
# $uid was listed in the MODIFIED response code
@@ -968,8 +974,15 @@ sub push_flag_updates($$@) {
# got multiple FETCH responses for $uid, the last one with $flags
delete $self->{_MODIFIED}->{$uid};
}
+ push @ok, $uid;
}
}
+
+ unless ($self->{quiet}) {
+ $self->log("Updated flags ($flags) for UID ".compact_set(@ok));
+ $self->log("Couldn't update flags ($flags) for UID ".compact_set(keys %failed).', '.
+ "trying again later") if %failed;
+ }
return keys %failed;
}
@@ -1169,7 +1182,7 @@ sub _select_or_examine($$$) {
$command .= " (QRESYNC ($pcache->{UIDVALIDITY} $pcache->{HIGHESTMODSEQ} "
."1:".($pcache->{UIDNEXT}-1)."))"
if $self->_enabled('QRESYNC') and
- ($pcache->{HIGHESTMODSEQ} // 0) > 0 and ($pcache->{UIDNEXT} // 0) > 0;
+ ($pcache->{HIGHESTMODSEQ} // 0) > 0 and ($pcache->{UIDNEXT} // 0) > 1;
if ($self->{_STATE} eq 'SELECTED' and ($self->_capable('CONDSTORE') or $self->_capable('QRESYNC'))) {
# A mailbox is currently selected and the server advertizes
@@ -1185,11 +1198,8 @@ sub _select_or_examine($$$) {
}
$self->{_STATE} = 'AUTH';
- if ($self->_send($command) eq 'OK') {
- $self->{_STATE} = 'SELECTED';
- } else {
- delete $self->{_SELECTED};
- }
+ $self->_send($command);
+ $self->{_STATE} = 'SELECTED';
}