pop3(3tcl)
๐ pop3 โ the Tcl POP3 Client Library (aka pop3(3tcl) bestie edition) ๐
okay so you want to talk to a POP3 email server from Tcl? say less. this is the whole pop3 manual page and i'm gonna walk you through it like we're texting. every flag, every default, every little detail โ it's all here, no cap. ๐
โจ NAME โจ
pop3 โ Tcl client for POP3 email protocol
like. that's the whole vibe. it's a client. for POP3. written in Tcl. iconic.
๐ธ SYNOPSIS ๐ธ
package require Tcl 8.5 9
package require pop3 ?1.11?
::pop3::open ?-msex 0|1? ?-retr-mode retr|list|slow? ?-socketcmd
cmdprefix? ?-stls 0|1? ?-tls-callback stls-callback-command? host
username password ?port?
::pop3::config chan
::pop3::status chan
::pop3::last chan
::pop3::retrieve chan startIndex ?endIndex?
::pop3::delete chan startIndex ?endIndex?
::pop3::list chan ?msg?
::pop3::top chan msg n
::pop3::uidl chan ?msg?
::pop3::capa chan
::pop3::close chan
that's the whole cast of characters bestie. they all take a chan (that channel handle ::pop3::open hands you back) and they all do their little thing. ๐ซถ
๐ DESCRIPTION ๐
the pop3 package is a simple, Tcl-only client library for the POP3 email protocol โ the one spec'd out in RFC 1939 [http://www.rfc-editor.org/rfc/rfc1939.txt]. ๐
how does it work? so simple. it opens the standard POP3 socket on the server, transmits the username and password, and then hands you a Tcl API to poke at the POP3 protocol commands. that's it. that's the whole magic trick.
ok important thing: all server errors are returned as Tcl errors (thrown) and you must catch them with the Tcl catch command. no silent failures here, she will let you know. ๐ญ
๐ TLS SECURITY CONSIDERATIONS ๐
this package uses the TLS package to handle the security for https urls and other socket connections. slay.
but listen โ policy decisions like which protocols to support and what ciphers to use? those are not the responsibility of TLS, and definitely not of this package either. nope. those decisions belong to whichever application is using the package, and they're probably gonna be influenced by the set of servers that app is gonna talk to. it's giving "know your audience." ๐
for example โ in light of the recent POODLE attack [http://googleonlinesecurity.blogspot.co.uk/2014/10/this-poodle-bites-exploiting-ssl-30.html] discovered by Google, many servers will disable support for the SSLv3 protocol. to handle this change, the applications using TLS must be patched โ not this package, and not TLS itself. such a patch may be as simple as generally activating tls1 support, as shown in the example below. ๐ฆ
package require tls
tls::init -tls1 1 ;# forcibly activate support for the TLS1 protocol
... your own application code ...
๐ API ๐
๐ซ ::pop3::open ?-msex 0|1? ?-retr-mode retr|list|slow? ?-socketcmd cmdprefix? ?-stls 0|1? ?-tls-callback stls-callback-command? host username password ?port?
open a socket connection to the server specified by host, and transmit the username and password as login info to the server. ๐ซถ
the default port number is 110, which you can override with the optional port argument. the return value is a channel, and every single other ::pop3 function uses that channel. she's the main character and everyone else is just supporting cast. ๐
the command recognizes three options:
-msexboolean โ setting this option tells the package that the server we're talking to is an MS Exchange server (which has some oddities we have to work around ๐). the default is False.-retr-moderetr|list|slow โ the retrieval mode determines how exactly messages are read from the server. allowed values areretr,listandslow. the default isretr. see::pop3::retrievefor more info. ๐-socketcmdcmdprefix โ this option lets you override the use of the builtinsocketcommand with any API-compatible command. the envisioned main use is securing the new connection via SSL, through specifying the commandtls::socket. this command is specially recognized as well, changing the default port of the connection to 995. ๐-stlsboolean โ setting this option tells the package to secure the connection using SSL or TLS. it performs STARTTLS as described in IETF RFC 2595 โ first it opens a normal, unencrypted connection, and then it negotiates a SSLv3 or TLSv1 connection. if the connection cannot be secured, the connection will be closed and an error will be returned. no half-secured situations, periodt. ๐-tls-callbackstls-callback-command โ this option lets you override thetls::callbackused during the-stlsSSL/TLS handshake. see the TLS manual for details on how to implement this callback. ๐
๐ซ ::pop3::config chan
returns the configuration of the pop3 connection identified by the channel handle chan as a serialized array. it's like a little snapshot of the whole setup. ๐ธ
๐ซ ::pop3::status chan
query the server for the status of the mail spool. the status is returned as a list containing two elements:
- the number of email messages on the server ๐
- the size (in octets, 8 bit blocks) of the entire mail spool
๐ซ ::pop3::last chan
query the server for the last email message read from the spool. this value includes all messages read from all clients connecting to the login account. ๐ณ
heads up bestie: this command may not be supported by the email server, in which case the server may return 0 or an error. not every server is emotionally available like that. ๐
๐ซ ::pop3::retrieve chan startIndex ?endIndex?
retrieve a range of messages from the server. if endIndex is not specified, only one message will be retrieved. the return value is a list containing each message as a separate element. see the startIndex and endIndex descriptions below. ๐
the retrieval mode determines how exactly messages are read from the server:
- mode
retrassumes that the RETR command delivers the size of the message as part of the command status and uses this to read the message efficiently. โจ - mode
listโ RETR does not deliver the size, but the LIST command does, and we use this to retrieve the message size before the actual retrieval, which can then be done efficiently. ๐ฆ - the last mode,
slowโ the system is unable to obtain the size of the message to retrieve in any manner and falls back to reading the message from the server line by line. it's giving snail mail but we love her anyway. ๐
it should also be noted that the system checks upon the configured mode and falls back to the slower modes if the above assumptions are not true. she adapts. she's resilient. ๐
๐ซ ::pop3::delete chan startIndex ?endIndex?
delete a range of messages from the server. if endIndex is not specified, only one message will be deleted. ๐
ngl important: the indices are not reordered on the server, so if you delete message1, then the first message in the queue is message2(message index1is no longer valid). the numbering does NOT shift up to fill the gap, bestie. remember that.
see the startIndex and endIndex descriptions below. ๐
startIndex
the startIndex may be an index of a specific message starting with the index 1, or it may have any of the following values:
startโ this is a logical value for the first message in the spool, equivalent to the value1. ๐ฅnextโ the message immediately following the last message read, see::pop3::last. โญ๏ธendโ the most recent message in the spool (the end of the spool). this is useful to retrieve only the most recent message. ๐
endIndex
the endIndex is an optional parameter and defaults to the value "-1", which indicates to only retrieve the one message specified by startIndex. if specified, it may be an index of a specific message starting with the index "1", or it may have any of the following values:
lastโ the message is the last message read by a POP3 client, see::pop3::last. โฎ๏ธendโ the most recent message in the spool (the end of the spool). ๐
๐ซ ::pop3::list chan ?msg?
returns the scan listing of the mailbox. if the parameter msg is given, then the listing only for that message is returned. targeted. specific. we love a queen who knows what she wants. ๐
๐ซ ::pop3::top chan msg n
optional POP3 command โ not all servers may support this. ๐ญ
::pop3::top retrieves headers of a message, specified by the parameter msg, and number of n lines from the message body.
๐ซ ::pop3::uidl chan ?msg?
optional POP3 command โ not all servers may support this. ๐ญ
::pop3::uidl returns the uid listing of the mailbox. if the parameter msg is specified, then the listing only for that message is returned.
๐ซ ::pop3::capa chan
optional POP3 command โ not all servers may support this. ๐ญ
::pop3::capa returns a list of the capabilities of the server. TOP, SASL, UIDL, LOGIN-DELAY and STLS are typical capabilities. see IETF RFC 2449. ๐
๐ซ ::pop3::close chan
gracefully close the connection after sending a POP3 QUIT command down the socket. so polite. so classy. say bye with your chest. ๐
๐ SECURE MAIL TRANSFER ๐
a pop3 connection can be secured with SSL/TLS by requiring the package TLS and then using either the option -socketcmd or the option -stls of the command pop3::open. two paths, same destination. choose your fighter. โจ
method one โ the -socketcmd way ๐ธ
the first method, option -socketcmd, will force the use of the tls::socket command when opening the connection. this is suitable for POP3 servers which expect SSL connections only. these will generally be listening on port 995. ๐
package require tls
tls::init -cafile /path/to/ca/cert -keyfile ...
# Create secured pop3 channel
pop3::open -socketcmd tls::socket \
$thehost $theuser $thepassword
...
method two โ the -stls way ๐ฆ
the second method, option -stls, will connect to the standard POP3 port and then perform an STARTTLS handshake. this will only work for POP3 servers which have this capability. the package will confirm that the server supports STARTTLS and the handshake was performed correctly before proceeding with authentication. she checks her work, bestie. ๐
package require tls
tls::init -cafile /path/to/ca/cert -keyfile ...
# Create secured pop3 channel
pop3::open -stls 1 \
$thehost $theuser $thepassword
...
to be continued... ๐ (more parts incoming, don't go anywhere bestie) ๐ซถ
๐ BUGS, IDEAS, FEEDBACK ๐
okay bestie, real talk ๐ โ this doc? and the whole package it's describing? yeah, they will undoubtedly have bugs and other problems. not being dramatic, that's just literally what the page says. nothing is perfect, not even your fave.
so if you spot something cursed, please report it under the category pop3 in the Tcllib Trackers:
http://core.tcl.tk/tcllib/reportlist
and if you've got big brain ideas for enhancements โ for the package, for the docs, for literally either one โ send those in too. we want them ๐ซถ
๐ one (1) thing about code changes
when you're proposing code changes, please bring unified diffs, i.e. the output of:
diff -u
no vibes-based handwaving, give us the diff โจ
๐ and about patches, bestie
attachments are strongly preferred over inlined patches. like, strongly. not a drill.
how do you attach one? it's a whole little side quest but it's easy:
- go to the Edit form of the ticket โ immediately after its creation, don't wander off
- then use the left-most button in the secondary navigation bar
and that's it, you're an icon ๐
๐ KEYWORDS ๐
email, mail, pop, pop3, rfc 1939, secure, ssl, tls
iykyk ๐ธ
๐ CATEGORY ๐
Networking ๐
and that's the whole page, bestie!! ๐ this was the pop3(3tcl) manpage from tcllib 1.11 โ go forth and fetch your mail securely, mwah ๐โจ๐ฆ
๐ฆ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 ยท Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 ยท Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 ยท Tcl
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms