diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2018-05-10 17:56:45 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2018-05-10 18:07:25 +0200 |
commit | 15cd4f6ea5074ffb33de8670bd1877603e504289 (patch) | |
tree | 237b90088d6f8fb244d5912b707e4782aca847bb /pullimap | |
parent | 567fc180a3e76716816ea9af5a066bad2ea8c01a (diff) |
pullimap: use extended SEARCH (RFC 4731) when available
Diffstat (limited to 'pullimap')
-rwxr-xr-x | pullimap | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -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) { |