Handle multiline SEARCH responses (according to http://imapwiki.org/ClientImplementation/Search)
patch 6dd64c777afb2deec0c3dcfacbba3552e409ead6
Author: Enrique D. Bosch <presidev@AT@gmail.com>
Date: Tue Nov 22 23:26:40 CET 2016
* Handle multiline SEARCH responses (according to http://imapwiki.org/ClientImplementation/Search)
diff -rN -u old-idlebiff/idlebiff new-idlebiff/idlebiff
--- old-idlebiff/idlebiff 2024-11-22 15:58:27.211006646 +0100
+++ new-idlebiff/idlebiff 2024-11-22 15:58:27.211006646 +0100
@@ -31,6 +31,8 @@
{
variable tag 1
variable ccsp 0
+ variable pmsgs 0
+ variable search_resp 0
array set ccsu {}
}
@@ -43,6 +45,8 @@
logindisabled 0
esearch 0
}
+ variable search
+ variable rexpsearch
variable criteria
variable msgs 0
variable sock
@@ -179,6 +183,25 @@
else { set criteria UNSEEN }
}
+proc set_search_params { } \
+{
+ variable ::shared::cap
+ variable ::shared::search
+ variable ::shared::rexpsearch
+ variable ::shared::criteria
+
+ if $cap(esearch) \
+ {
+ set search "SEARCH RETURN (COUNT) $criteria"
+ set rexpsearch {^\*\s+esearch\s+\(tag\s*[^)]*\)\s+count\s+(.*)$}
+ } \
+ else \
+ {
+ set search "SEARCH $criteria"
+ set rexpsearch {^\*\s+search\s+(.*)$}
+ }
+}
+
proc set_timeout { } \
{
variable ::shared::conf
@@ -322,11 +345,9 @@
proc do_search con \
{
- variable ::shared::cap
- variable ::shared::criteria
+ variable ::shared::search
- if $cap(esearch) { imap_command_tagged $con "SEARCH RETURN (COUNT) $criteria" } \
- else { imap_command_tagged $con "SEARCH $criteria" }
+ imap_command_tagged $con $search
}
proc check_cap { linea capname } \
@@ -361,6 +382,7 @@
fileevent $con readable { parse_idle_check $con }
enter_mailbox $con
+ set_search_params
do_search $con
set ka [ after ${conf(keepalive)}000 { idle_cycle $con 0 } ]
}
@@ -434,19 +456,27 @@
variable ::shared::img_down
variable ::shared::new_messages
variable ::shared::cap
+ variable ::shared::rexpsearch
+ variable ::static::pmsgs
+ variable ::static::search_resp
- if $cap(esearch) { set rexpr {^\*\s+esearch\s+\(tag\s*[^)]*\)\s+count\s+(.*)$} } \
- else { set rexpr {^\*\s+search\s+(.*)$} }
- if [ regexp -lineanchor -nocase $rexpr $linea -> res ] \
+ if [ regexp -lineanchor -nocase $rexpsearch $linea -> res ] \
+ {
+ if $cap(esearch) { set pmsgs $res } else { incr pmsgs [ llength $res ] }
+ set search_resp 1
+ }
+ if { $search_resp && [ ok_tagged $linea ] } \
{
enter_idle $con
- if !$cap(esearch) { set res [ llength $res ] }
- set new_messages $res
+ set new_messages $pmsgs
+ set pmsgs 0
+ set search_resp 0
if { $new_messages > 0 } \
{ set current $img_up } \
else { set current $img_down }
update_img $current
- }
+ }
+ if [ no_tagged $linea ] { error search }
}
proc read_line con \