aboutsummaryrefslogtreecommitdiffstats
path: root/pullimap
diff options
context:
space:
mode:
Diffstat (limited to 'pullimap')
-rwxr-xr-xpullimap18
1 files changed, 14 insertions, 4 deletions
diff --git a/pullimap b/pullimap
index dca8c49..736bbff 100755
--- a/pullimap
+++ b/pullimap
@@ -249,10 +249,20 @@ sub purge() {
my @now = gmtime($now - $days*86400);
my @m = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; # RFC 3501's date-month
my $date = sprintf("%02d-%s-%04d", $now[3], $m[$now[4]], $now[5]+1900);
- my @uid = $IMAP->search("UID $set BEFORE $date");
-
- $set = @uid ? compact_set(@uid) : undef;
- $IMAP->log("Removing ".($#uid+1)." UID(s) $set") if defined $set and !$CONFIG{quiet};
+ my $ext = $IMAP->incapable('ESEARCH') ? undef : [qw/COUNT ALL/];
+ my @uid = $IMAP->search((defined $ext ? "RETURN (".join(' ', @$ext).') ' : '')
+ ."UID $set BEFORE $date");
+ my $count;
+ if (defined $ext) {
+ my ($uid_indicator, %resp) = @uid;
+ $IMAP->panic() unless defined $uid_indicator and $uid_indicator = 'UID';
+ $count = $resp{COUNT} // $IMAP->panic();
+ $set = $resp{ALL}; # MUST NOT be present if there are no matches
+ } else {
+ $count = $#uid+1;
+ $set = $count == 0 ? undef : compact_set(@uid);
+ }
+ $IMAP->log("Removing $count UID(s) $set") if $count > 0 and !$CONFIG{quiet};
}
if (defined $set) {