Improve capabilities parsing, remove initial noop by default
patch 2b11c67e9dd039c4f3bce6bf120363cfc66bd5d4
Author: Enrique D. Bosch <presidev@AT@gmail.com>
Date: Tue Jan 3 20:44:31 CET 2017
* Improve capabilities parsing, remove initial noop by default
hunk ./.idlebiffrc 13
+initial_noop=0
hunk ./idlebiff 44
- idle 0
hunk ./idlebiff 45
+ logindisabled_chk 0
+ chk 0
+ idle 0
hunk ./idlebiff 51
+ variable rexp_chk
hunk ./idlebiff 183
+ variable ::shared::rexp_chk
hunk ./idlebiff 187
+ set rexp_chk {(?: |\[)capability }
hunk ./idlebiff 271
-proc imap_command_tagged { con com } \
+proc imap_command_tagged { con prefix com } \
hunk ./idlebiff 275
- if { $tag == 10000 } { set tag 1 } [_$_]
- append tcom A [ format %04d $tag ] " " $com
+ if { $tag == 10000 } { set tag 1 }
+ append tcom $prefix [ format %04d $tag ] " " $com
hunk ./idlebiff 281
-proc ok_tagged linea \
+proc ok_tagged { linea prefix } \
hunk ./idlebiff 283
- return [ regexp -lineanchor -nocase {^A\d+ ok.*$} $linea ]
+ append rexp {^} $prefix {\d+ ok.*$}
+ return [ regexp -lineanchor -nocase $rexp $linea ]
hunk ./idlebiff 307
- imap_command_tagged $con "LOGIN $conf(user) $conf(pass)"
+ imap_command_tagged $con A "LOGIN $conf(user) $conf(pass)"
hunk ./idlebiff 312
- imap_command_tagged $con LOGOUT
+ imap_command_tagged $con A LOGOUT
hunk ./idlebiff 331
- imap_command_tagged $con IDLE [_$_]
+ imap_command_tagged $con A IDLE
hunk ./idlebiff 343
- imap_command_tagged $con "EXAMINE $conf(mailbox)"
+ imap_command_tagged $con A "EXAMINE $conf(mailbox)"
hunk ./idlebiff 348
- imap_command_tagged $con CLOSE
+ imap_command_tagged $con A CLOSE
hunk ./idlebiff 355
- imap_command_tagged $con $search
+ imap_command_tagged $con A $search
hunk ./idlebiff 358
-proc check_cap { linea capname } \
+proc check_cap { linea args } \
hunk ./idlebiff 361
-
- if !$cap($capname) \
+ variable ::shared::rexp_chk
+
+ if [ regexp -nocase -lineanchor $rexp_chk $linea ] \
hunk ./idlebiff 365
- set rexp ".*capability .*${capname}(?: .*|].*|$)"
- set cap($capname) [ regexp -nocase -lineanchor $rexp $linea ]
+ if { $args eq "logindisabled" } { set cap(logindisabled_chk) 1 } \
+ else { set cap(chk) 1 }
+ foreach capname $args \
+ {
+ if !$cap($capname) \
+ {
+ set rexp_cap " ${capname}(?: |]|$)"
+ set cap($capname) [ regexp -nocase -lineanchor $rexp_cap $linea ]
+ }
+ }
hunk ./idlebiff 396
-
+ variable ::shared::cap
+
+ if !$cap(idle) { error noidle }
hunk ./idlebiff 408
+ variable ::shared::cap
+
hunk ./idlebiff 412
- if [ ok_untagged $linea ] { fileevent $con readable { parse_noop $con } }
+ if [ ok_untagged $linea ] \
+ {
+ if $cap(logindisabled_chk) \
+ {
+ fileevent $con readable { parse_login $con }
+ login $con 0
+ } \
+ else \
+ {
+ fileevent $con readable { parse_logindisabled $con }
+ imap_command_tagged $con A CAPABILITY
+ }
+ }
hunk ./idlebiff 427
-proc parse_noop con \
+proc parse_logindisabled con \
hunk ./idlebiff 429
+ variable ::shared::cap
+
hunk ./idlebiff 433
- if [ ok_tagged $linea ] \
+ if [ ok_tagged $linea A ] \
hunk ./idlebiff 435
- fileevent $con readable { parse_login $con }
- login $con 0
+ if $cap(logindisabled_chk) \
+ {
+ fileevent $con readable { parse_login $con }
+ login $con 0
+ }
hunk ./idlebiff 448
- check_cap $linea idle
- check_cap $linea esearch
- if [ ok_tagged $linea ] \
+ check_cap $linea idle esearch
+ if [ ok_tagged $linea A ] \
hunk ./idlebiff 451
- if $cap(idle) { init_idle $con } \
+ if $cap(chk) { init_idle $con } \
hunk ./idlebiff 455
- imap_command_tagged $con CAPABILITY
+ imap_command_tagged $con A CAPABILITY
hunk ./idlebiff 463
- variable ::shared::cap
-
hunk ./idlebiff 464
- check_cap $linea idle
- check_cap $linea esearch
- if [ ok_tagged $linea ] \
- {
- if $cap(idle) { init_idle $con } \
- else { error no idle capability } \
- } [_$_]
+ check_cap $linea idle esearch
+ if [ ok_tagged $linea A ] { init_idle $con }
hunk ./idlebiff 495
- if { $search_resp && [ ok_tagged $linea ] } \
+ if { $search_resp && [ ok_tagged $linea A ] } \
hunk ./idlebiff 593
- imap_command_tagged $con NOOP
+ if $conf(initial_noop) { imap_command_tagged $con N NOOP }