patch c10ef6fde35c32a02b4d6ceb7731589dd6e207a0 Author: Enrique D. Bosch Date: Fri Aug 31 21:32:14 CEST 2018 * Simplify interface for imap_command_tagged function diff -rN -u old-idlebiff/idlebiff new-idlebiff/idlebiff --- old-idlebiff/idlebiff 2024-11-22 21:31:16.507297596 +0100 +++ new-idlebiff/idlebiff 2024-11-22 21:31:16.515297583 +0100 @@ -30,6 +30,11 @@ proc or args { foreach x $args { if { $x } { return 1 } }; return 0 } proc and args { foreach x $args { if { $x } continue { return 0 } }; return 1 } +proc ifempty { str alt } \ +{ + return [ expr { [ eq $str {} ] ? $alt : $str } ] +} + proc check_conf_and_set_default { opt default } \ { variable ::shared::conf @@ -286,19 +291,19 @@ set_timeout } -proc imap_command_tagged { con prefix com } \ +proc imap_command_tagged { con com args } \ { variable ::static::tag if {[ == $tag 10000 ]} { set tag 1 } - append tcom $prefix [ format %04d $tag ] { } $com + append tcom [ ifempty $args A ] [ format %04d $tag ] { } $com imap_command $con $tcom incr tag } -proc ok_tagged { linea prefix } \ +proc ok_tagged linea \ { - append rexp {^} $prefix {\d+ ok.*$} + append rexp {^} A {\d+ ok.*$} return [ regexp -lineanchor -nocase $rexp $linea ] } @@ -322,12 +327,12 @@ if { $retr } { unset conf(pass) } if { ![ info exists conf(pass) ] } { set conf(pass) [ get_password $retr ] } - imap_command_tagged $con A "LOGIN $conf(user) $conf(pass)" + imap_command_tagged $con "LOGIN $conf(user) $conf(pass)" } proc logout con \ { - imap_command_tagged $con A LOGOUT + imap_command_tagged $con LOGOUT close $con } @@ -346,7 +351,7 @@ proc enter_idle con \ { - imap_command_tagged $con A IDLE + imap_command_tagged $con IDLE } proc exit_idle con \ @@ -358,19 +363,19 @@ { variable ::shared::conf - imap_command_tagged $con A "EXAMINE $conf(mailbox)" + imap_command_tagged $con "EXAMINE $conf(mailbox)" } proc exit_mailbox con \ { - imap_command_tagged $con A CLOSE + imap_command_tagged $con CLOSE } proc do_search con \ { variable ::shared::search - imap_command_tagged $con A $search + imap_command_tagged $con $search } proc check_cap { linea args } \ @@ -437,7 +442,7 @@ else \ { fileevent $con readable { parse_logindisabled $con } - imap_command_tagged $con A CAPABILITY + imap_command_tagged $con CAPABILITY } } } @@ -448,7 +453,7 @@ set linea [ read_line $con ] check_cap $linea logindisabled - if {[ ok_tagged $linea A ]} \ + if {[ ok_tagged $linea ]} \ { if { $cap(logindisabled_chk) } \ { @@ -464,13 +469,13 @@ set linea [ read_line $con ] check_cap $linea idle esearch - if {[ ok_tagged $linea A ]} \ + if {[ ok_tagged $linea ]} \ { if { $cap(chk) } { init_idle $con } \ else \ { fileevent $con readable { parse_cap $con } - imap_command_tagged $con A CAPABILITY + imap_command_tagged $con CAPABILITY } } \ elseif {[ no_tagged $linea ]} { login $con 1 } @@ -480,7 +485,7 @@ { set linea [ read_line $con ] check_cap $linea idle esearch - if {[ ok_tagged $linea A ]} { init_idle $con } + if {[ ok_tagged $linea ]} { init_idle $con } } proc parse_idle_check con \ @@ -510,7 +515,7 @@ if { $cap(esearch) } { set pmsgs $res } else { incr pmsgs [ llength $res ] } set search_resp 1 } - if {[ and $search_resp [ ok_tagged $linea A ] ]} \ + if {[ and $search_resp [ ok_tagged $linea ] ]} \ { enter_idle $con set new_messages $pmsgs @@ -617,7 +622,7 @@ set con [ exec_terse $sock -async $conf(host) $conf(port) ] fconfigure $con -blocking 0 -buffering line -translation {crlf crlf} fileevent $con readable { parse_greeting $con } - if { $conf(initial_noop) } { imap_command_tagged $con N NOOP } + if { $conf(initial_noop) } { imap_command_tagged $con NOOP N } } read_conf