patch b0cebeb0d05720d8b145fc479b09238a463a26cf
Author: Enrique D. Bosch <presidev@AT@gmail.com>
Date: Sat Jun 4 17:05:02 CEST 2016
* Improve capabilities parse routine
diff -rN -u old-idlebiff/idlebiff new-idlebiff/idlebiff
--- old-idlebiff/idlebiff 2024-11-22 16:31:20.199825087 +0100
+++ new-idlebiff/idlebiff 2024-11-22 16:31:20.199825087 +0100
@@ -31,9 +31,12 @@
namespace eval shared \
{
variable idle 0
- variable idlecap 0
- variable logindiscap 0
- variable esearchcap 0
+ array set cap \
+ {
+ idle 0
+ logindisabled 0
+ esearch 0
+ }
variable msgs 0
variable sock
variable conf
@@ -248,9 +251,9 @@
proc login { con retr } \
{
variable ::shared::conf
- variable ::shared::logindiscap
+ variable ::shared::cap
- if $logindiscap { error logindisabled }
+ if $cap(logindisabled) { error logindisabled }
if $retr { unset conf(pass) }
if ![ info exists conf(pass) ] { set conf(pass) [ get_password $retr ] }
@@ -301,31 +304,21 @@
proc ask_unseen { con } \
{
- variable ::shared::esearchcap
+ variable ::shared::cap
- if $esearchcap { imap_command_tagged $con "SEARCH RETURN (COUNT) UNSEEN" } \
- else { imap_command_tagged $con "SEARCH UNSEEN" }
+ if $cap(esearch) { imap_command_tagged $con "SEARCH RETURN (COUNT) UNSEEN" } \
+ else { imap_command_tagged $con "SEARCH UNSEEN" }
}
-proc check_cap_logindis { linea } \
+proc check_cap { linea capname } \
{
- variable ::shared::logindiscap
-
- if !$logindiscap { set logindiscap [ regexp -nocase -lineanchor {.*capability .*logindisabled(?: .*|].*|$)} $linea ] }
-}
+ variable ::shared::cap
-proc check_cap_idle { linea } \
-{
- variable ::shared::idlecap
-
- if !$idlecap { set idlecap [ regexp -nocase -lineanchor {.*capability .*idle(?: .*|].*|$)} $linea ] }
-}
-
-proc check_cap_esearch { linea } \
-{
- variable ::shared::esearchcap
-
- if !$esearchcap { set esearchcap [ regexp -nocase -lineanchor {.*capability .*esearch(?: .*|].*|$)} $linea ] }
+ if !$cap($capname) \
+ {
+ set rexp ".*capability .*${capname}(?: .*|].*|$)"
+ set cap($capname) [ regexp -nocase -lineanchor $rexp $linea ]
+ }
}
proc idle_cycle { con check } \
@@ -357,15 +350,14 @@
proc parse_greeting { con } \
{
set linea [ read_line $con ]
- check_cap_logindis $linea
+ check_cap $linea logindisabled
if [ ok_untagged $linea ] { fileevent $con readable { parse_noop $con } }
}
proc parse_noop { con } \
{
-
set linea [ read_line $con ]
- check_cap_logindis $linea
+ check_cap $linea logindisabled
if [ ok_tagged $linea ] \
{
fileevent $con readable { parse_login $con }
@@ -375,14 +367,14 @@
proc parse_login { con } \
{
- variable ::shared::idlecap
+ variable ::shared::cap
set linea [ read_line $con ]
- check_cap_idle $linea
- check_cap_esearch $linea
+ check_cap $linea idle
+ check_cap $linea esearch
if [ ok_tagged $linea ] \
{
- if $idlecap { init_idle $con } \
+ if $cap(idle) { init_idle $con } \
else \
{
fileevent $con readable { parse_cap $con }
@@ -394,14 +386,14 @@
proc parse_cap { con } \
{
- variable ::shared::idlecap
+ variable ::shared::cap
set linea [ read_line $con ]
- check_cap_idle $linea
- check_cap_esearch $linea
+ check_cap $linea idle
+ check_cap $linea esearch
if [ ok_tagged $linea ] \
{
- if $idlecap { init_idle $con } \
+ if $cap(idle) { init_idle $con } \
else { error no idle capability } \
}
}
@@ -423,13 +415,13 @@
variable ::shared::img_up
variable ::shared::img_down
variable ::shared::new_messages
- variable ::shared::esearchcap
+ variable ::shared::cap
- if $esearchcap { set rexpr {^\*\s+esearch\s+\(tag\s*[^)]*\)\s+count\s+(.*)$} } \
- else { set rexpr {^\*\s+search\s+(.*)$} }
+ 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 !$esearchcap { set res [ llength $res ] }
+ if !$cap(esearch) { set res [ llength $res ] }
set new_messages $res
if { $new_messages > 0 } \
{ set current $img_up } \