Documentation can be found at http://tcllib.sourceforge.net/doc/pop3.html .
if 0 { package require pop3 ;# http://tcllib.sourceforge.net/ set popsock [pop3::open $_theHost $_theUser $_thePassword] foreach {msgcount size} [pop3::status $popsock] {} set message [pop3::retrieve $popsock $_index] set messages [pop3::retrieve $popsock $_first $_last] pop3::delete $popsock $_index pop3::delete $popsock $_first $_last pop3::close $popsock }
[Add commentary to above. Explain foreach idiom. Mention exceptions.]
VL 21 may 2003: -ERR autorization fist, if you recieve this error during pop3::open a likely explanation is that the email-server does not accept connections through telent, only through SSH, I'm working on a general fix that can be used with tcllib::pop3 and a locally installed SSH-client.
escargo 21 May 2003 - I put if 0 { around the code so that this page becomes reapable; the check mail code should then just work if collected by wish-reaper and friends.
[Explain performance considerations, version compatibility, head use, exception-handling, ... Warn about deletes. Point to pertinent RFC for index base and other definitions.]
A little pop3 client demo, using the tcllib: Steve Offutt, 5/25/01 mailto:[email protected] Thanks to Cameron for help getting started.
escargo 21 May 2003 - If you push the "Disconnect" button to disconnect, and then push it again, an error results. The close_it proc does not check to see if the popsock value is empty before trying to close it.
# Check Mail - a lightweight pop3 client - Thursday May 31, 2001 package require pop3 #create a user interface proc make_gui { } { label .lhost -text "Hostname" label .luser -text "Username" label .lpass -text "Password" entry .eh -textvariable "_theHost" entry .eu -textvariable "_theUser" entry .ep -textvariable "_thePassword" bind .ep <Return> {open_channel} button .b -text "Connect" -command {open_channel} button .b2 -text "Disconnect" -command {close_it} set popsock "" label .lsock -text "Socket:" label .lsock2 -relief groove -bd 2 grid .lhost .eh -sticky ew grid .luser .eu -sticky ew grid .lpass .ep -sticky ew grid .lsock .lsock2 -row 3 -sticky ew grid .b -row 4 -columnspan 2 -sticky ew grid .b2 -row 5 -columnspan 2 -sticky ew .ep configure -show * } make_gui #globals global new_messages set new_messages 0 global popsock set popsock "" #procedures follow proc open_channel { } { global _theHost _theUser _thePassword popsock set popsock [pop3::open $_theHost $_theUser $_thePassword] .lsock2 configure -text $popsock get_status return $popsock } proc close_it { } { global popsock close $popsock set popsock "" .lsock2 configure -text "" return $popsock } proc get_status { } { global popsock set my_stat [pop3::status $popsock] set new_messages [lindex $my_stat 0] show_it $new_messages return $new_messages } proc show_it { var } { tk_messageBox -icon info -title "Messages" \ -parent . -type ok -message "You have $var new messages." #xception-handling, ... Warn about deletes. Point to pertinent RFC for index base and other definitions.] } proc tkerror { errmsg } { global errorCode set msg [format "Error: %s\nResult: %s." $errmsg $errorCode] tk_messageBox -parent . -title Error -type ok\ -icon error -message $msg bell } wm protocol . WM_DELETE_WINDOW "clean_up" proc clean_up { } { global popsock if {$popsock != ""} { close_it } exit } wm title . "Check Mail" wm deiconify . focus .eh
NOTE: Most pop3 servers only allow one client to connect at a time. That's what RFC 1939 [L1 ] requires.
AK: Actually the note above is too restrictive. The RFC says that a server should allow only one client/connection per maildrop. In other words, a pop3 server managing N different maildrops can have N connections from N clients, if these connections all talk to a different maildrop.
NOTE: RFC 1939 [L2 ] (which is a standard) is updated by RFC 1957 [L3 ] (informational), and RFC 2449 [L4 ] (standards track). -EE
(My information comes from http://www.rfc-editor.org/ , which is pretty much the canonical source of RFC information.)
Only marginally on topic, we also have RFC 2384 [L5 ].
Remember, one doesn't do a package require of tcllib itself, but of the modules INSIDE tcllib...
If you had only an old, socket-less Tcl at hand, but also Expect, you could exploit the Unix telnet binary, as Glenn Jackman's checkpopmail [L6 ] exemplifies.
Or maybe, you just copy Glenn Jackman's script once you realize that you want to check your IMAP mail account -- see Checking your IMAP Mail with Expect.
Category Package, subset tcllib