Support extension to SEARCH (RFC-4731) when available (via ESEARCH capability) to make UNSEEN queries more efficient
patch e5c973637923fda8b5c042f0135d08965c6ac2de
Author: Enrique D. Bosch <presidev@AT@gmail.com>
Date: Tue May 31 17:06:39 CEST 2016
* Support extension to SEARCH (RFC-4731) when available (via ESEARCH capability) to make UNSEEN queries more efficient
diff -rN -u old-idlebiff/idlebiff new-idlebiff/idlebiff
--- old-idlebiff/idlebiff 2024-05-06 11:18:18.123939613 +0200
+++ new-idlebiff/idlebiff 2024-05-06 11:18:18.123939613 +0200
@@ -33,6 +33,7 @@
variable idle 0
variable idlecap 0
variable logindiscap 0
+ variable esearchcap 0
variable msgs 0
variable sock
variable conf
@@ -300,7 +301,10 @@
proc ask_unseen { con } \
{
- imap_command_tagged $con "SEARCH UNSEEN"
+ variable ::shared::esearchcap
+
+ if $esearchcap { imap_command_tagged $con "SEARCH RETURN (COUNT) UNSEEN" } \
+ else { imap_command_tagged $con "SEARCH UNSEEN" }
}
proc check_cap_logindis { linea } \
@@ -317,6 +321,13 @@
if !$idlecap { set idlecap [ regexp -nocase {.*capability .* idle .*} $linea ] }
}
+proc check_cap_esearch { linea } \
+{
+ variable ::shared::esearchcap
+
+ if !$esearchcap { set esearchcap [ regexp -nocase {.*capability .* esearch .*} $linea ] }
+}
+
proc idle_cycle { con check } \
{
variable ::shared::idle
@@ -368,6 +379,7 @@
set linea [ read_line $con ]
check_cap_idle $linea
+ check_cap_esearch $linea
if [ ok_tagged $linea ] \
{
if $idlecap { init_idle $con } \
@@ -386,6 +398,7 @@
set linea [ read_line $con ]
check_cap_idle $linea
+ check_cap_esearch $linea
if [ ok_tagged $linea ] \
{
if $idlecap { init_idle $con } \
@@ -410,10 +423,14 @@
variable ::shared::img_up
variable ::shared::img_down
variable ::shared::new_messages
+ variable ::shared::esearchcap
- if [ regexp -lineanchor -nocase {^\*\s+search\s+(.*)$} $linea -> msg_list ] \
+ if $esearchcap { set rexpr {^\*\s+esearch\s+\(tag\s*[^)]*\)\s+count\s+(.*)$} } \
+ else { set rexpr {^\*\s+search\s+(.*)$} }
+ if [ regexp -lineanchor -nocase $rexpr $linea -> res ] \
{
- set new_messages [ llength $msg_list ]
+ if !$esearchcap { set res [ llength $res ] }
+ set new_messages $res
if { $new_messages > 0 } \
{ set current $img_up } \
else { set current $img_down }