#!/usr/bin/expect -f #log_user 0 ;# hide interaction, i.e. do not display to stdout set timeout 10 match_max 100000 set server my.server.com set port 143 set user {dude} set pass {32k$12!_a} spawn telnet $server $port expect { timeout {puts stdout "timeout while connecting to $server"; exit 1} "* OK" } send "a001 login $user $pass\r" expect { timeout {puts stdout "timed out after login"; exit 1} "a001 NO" {puts stdout "bad login"; exit 1} "a001 OK" } send "a002 examine inbox\r" expect { timeout {puts stdout "timed out after examining inbox"; exit 1} "a002 NO" {puts stdout "could not examine inbox"; exit 1} "a002 OK" } #parray expect_out set buffer_to_parse $expect_out(buffer) regexp {([0-9]+) RECENT} $buffer_to_parse -> new_msgs puts "new: $new_msgs" send "a003 logout\r" expect { timeout {puts stdout "timed out after logout"; exit 1} "a003 NO" {puts stdout "could not logout"; exit 1} "a003 OK" } exit
CL, intent on demonstrating that many people who think they need Expect do not need Expect, feels motivation to code a pure-Tcl example that almost as easily achieves the same effect--but not enough motivation yet to turn away from other projects.
schlenk It is quite simply to do it with the rudimentary IMAP4 client inside the Tcllib CVS tree.
DL Yes, CL and schlenk are correct but not all is lost. Drop an 'interact' in the middle of the script and it becomes a cute script for experimenting with an IMAP server interactively. I do that a lot! As far as solving the original problem (automating checking of mail account), I use tkbiff.