Implement correctly LOGOUT command according to RFC 3501, add logout_timeout config option
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
hunk ./.idlebiffrc 16
+timeout_logout=2
hunk ./idlebiff 33
+proc setappend { var args } { upvar 1 $var v; set v [ join $args {} ] }
hunk ./idlebiff 44
- variable tag 1
+ variable ntag 1
hunk ./idlebiff 77
+ variable tag
hunk ./idlebiff 284
- if {[ catch { puts $con $com } ]} \
+ set r [ catch { puts $con $com } ]
+ if {[ eq $com LOGOUT ]} return
+ if { $r } \
hunk ./idlebiff 296
- variable ::static::tag
-
- if {[ == $tag 10000 ]} { set tag 1 }
- append tcom $prefix [ format %04d $tag ] { } $com
+ variable ::static::ntag
+ variable ::shared::tag
+
+ if {[ == $ntag 10000 ]} { set ntag 1 }
+ setappend tag $prefix [ format %04d $ntag ]
+ append tcom $tag { } $com
hunk ./idlebiff 303
- incr tag
+ incr ntag
hunk ./idlebiff 306
-proc ok_tagged linea \
+proc ok_tagged { linea { tag {A\d+} } } \
hunk ./idlebiff 308
- append rexp {^} A {\d+ ok.*$}
+ append rexp {^} $tag { ok.*$}
hunk ./idlebiff 337
+ 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
+ }
hunk ./idlebiff 351
- close $con
hunk ./idlebiff 356
- exit 0
hunk ./idlebiff 543
+}
+
+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
+ }