aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debian/patches/0001-Ignore-custom-lib-PATH.patch24
-rw-r--r--debian/patches/series1
-rwxr-xr-ximapsync22
-rw-r--r--lib/Net/IMAP/Sync.pm40
4 files changed, 68 insertions, 19 deletions
diff --git a/debian/patches/0001-Ignore-custom-lib-PATH.patch b/debian/patches/0001-Ignore-custom-lib-PATH.patch
new file mode 100644
index 0000000..0786ffa
--- /dev/null
+++ b/debian/patches/0001-Ignore-custom-lib-PATH.patch
@@ -0,0 +1,24 @@
+From 5c814e42f3eb9d638c6cb6fd4bc8a7d0ed020cfc Mon Sep 17 00:00:00 2001
+From: Guilhem Moulin <guilhem@fripost.org>
+Date: Thu, 23 Jul 2015 19:19:25 +0200
+Subject: [PATCH] Ignore custom lib PATH.
+
+---
+ imapsync | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/imapsync b/imapsync
+index 4ef47b3..f932686 100755
+--- a/imapsync
++++ b/imapsync
+@@ -30,7 +30,6 @@ use List::Util 'first';
+ use DBI ();
+ use POSIX 'strftime';
+
+-use lib 'lib';
+ use Net::IMAP::Sync qw/read_config compact_set $IMAP_text $IMAP_cond/;
+
+ # Clean up PATH
+--
+2.4.6
+
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..ba71084
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+0001-Ignore-custom-lib-PATH.patch
diff --git a/imapsync b/imapsync
index eb8f652..4ef47b3 100755
--- a/imapsync
+++ b/imapsync
@@ -444,6 +444,20 @@ my @SUBSCRIPTIONS;
push @{$IMAP->{$unsubscribed}->{mailboxes}->{$mbx}}, '\Subscribed';
}
}
+ else {
+ $sth_search->execute($mbx);
+ my $row = $sth_search->fetch();
+ die if defined $sth_search->fetch(); # sanity check
+
+ if (defined $row) {
+ my ($idx,$status) = @$row;
+ unless (defined $status and $status != 0) {
+ my $subscribed = subscribed_mbx('local',$mbx) ? 1 : 0;
+ $sth_subscribe->execute($subscribed, $idx);
+ $DBH->commit();
+ }
+ }
+ }
push @SUBSCRIPTIONS, $mbx if subscribed_mbx('local', $mbx) and
subscribed_mbx('remote',$mbx);
}
@@ -713,7 +727,7 @@ sub sync_messages($$) {
# new mailbox
if (!defined $$idx) {
- my $subscribed = grep { $_ eq $mailbox} @SUBSCRIPTIONS ? 1 : 0;
+ my $subscribed = (grep { $_ eq $mailbox} @SUBSCRIPTIONS) ? 1 : 0;
$STH_NEWMAILBOX->execute($mailbox, $subscribed);
$STH_GET_INDEX->execute($mailbox);
($$idx) = $STH_GET_INDEX->fetchrow_array();
@@ -738,9 +752,8 @@ sub sync_messages($$) {
}
-
-# Wait for notifications on either IMAP server, up to $timout. Then
-# issue a NOOP so the connection doesn't terminate for inactivity.
+# Wait up to $timout seconds for notifications on either IMAP server.
+# Then issue a NOOP so the connection doesn't terminate for inactivity.
sub wait_notifications(;$) {
my $timeout = shift // 300;
@@ -753,6 +766,7 @@ sub wait_notifications(;$) {
if (--$timeout == 0) {
$lIMAP->noop();
$rIMAP->noop();
+ # might have got updates so exit the loop
}
}
}
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';
}