patch 7eb7e2ff46a284866aa04fa8679ec731279c63c7
Author: Enrique D. Bosch <presidev@AT@gmail.com>
Date: Sun Sep 2 21:20:08 CEST 2018
* Implement correctly LOGOUT command according to RFC 3501, add logout_timeout config option
diff -rN -u old-idlebiff/.idlebiffrc new-idlebiff/.idlebiffrc
--- old-idlebiff/.idlebiffrc 2024-11-22 15:55:23.043302882 +0100
+++ new-idlebiff/.idlebiffrc 2024-11-22 15:55:23.043302882 +0100
@@ -13,6 +13,7 @@
initial_noop=0
keepalive=1500
timeout=20
+timeout_logout=2
png_up=up.png
png_down=down.png
png_chk=check.png
diff -rN -u old-idlebiff/idlebiff new-idlebiff/idlebiff
--- old-idlebiff/idlebiff 2024-11-22 15:55:23.043302882 +0100
+++ new-idlebiff/idlebiff 2024-11-22 15:55:23.043302882 +0100
@@ -30,6 +30,7 @@
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 setappend { var args } { upvar 1 $var v; set v [ join $args {} ] }
proc check_conf_and_set_default { opt default } \
{
@@ -40,7 +41,7 @@
namespace eval static \
{
- variable tag 1
+ variable ntag 1
variable ccsp 0
variable pmsgs 0
variable search_resp 0
@@ -73,6 +74,7 @@
variable img_down
variable img_chk
variable new_messages 0
+ variable tag
}
proc define_pixmaps {} \
@@ -279,7 +281,9 @@
if { $conf(imap_trace) } \
{ if {[ regexp {.*LOGIN.*} $com ]} { puts "C: [string range $com 0 10]" } else { puts "C: $com" } }
- if {[ catch { puts $con $com } ]} \
+ set r [ catch { puts $con $com } ]
+ if {[ eq $com LOGOUT ]} return
+ if { $r } \
{
recon $con
return
@@ -289,17 +293,19 @@
proc imap_command_tagged { con com { prefix A } } \
{
- variable ::static::tag
+ variable ::static::ntag
+ variable ::shared::tag
- if {[ == $tag 10000 ]} { set tag 1 }
- append tcom $prefix [ format %04d $tag ] { } $com
+ if {[ == $ntag 10000 ]} { set ntag 1 }
+ setappend tag $prefix [ format %04d $ntag ]
+ append tcom $tag { } $com
imap_command $con $tcom
- incr tag
+ incr ntag
}
-proc ok_tagged linea \
+proc ok_tagged { linea { tag {A\d+} } } \
{
- append rexp {^} A {\d+ ok.*$}
+ append rexp {^} $tag { ok.*$}
return [ regexp -lineanchor -nocase $rexp $linea ]
}
@@ -328,14 +334,25 @@
proc logout con \
{
+ variable ::shared::ka
+ variable ::shared::idle
+ variable ::shared::conf
+
+ after cancel $ka
+ set idle 0
+ exit_idle $con
+ fileevent $con readable { parse_logout $con }
+ after ${conf(timeout_logout)}000 \
+ {
+ close $con
+ exit 0
+ }
imap_command_tagged $con LOGOUT
- close $con
}
proc cleanup con \
{
logout $con
- exit 0
}
proc force_down {} \
@@ -525,6 +542,20 @@
if {[ no_tagged $linea ]} { emit_error search }
}
+proc parse_logout con \
+{
+ variable ::shared::conf
+ variable ::shared::tag
+
+ if {[ catch { gets $con linea } ]} return
+ if { $conf(imap_trace) } { puts "S: $linea" }
+ if {[ ok_tagged $linea $tag ]} \
+ {
+ close $con
+ exit 0
+ }
+}
+
proc read_line con \
{
variable ::shared::conf