Updated 2016-01-17 11:34:36 by HolgerJ

Internet Mail Access Protocol

Often referred to as IMAP4.

IMAP (and POP) are protocols used for remote email access. IMAP is a remote protocol, which means that the messages live on the server until deleted, although your mail client will usually cache a local copy of messages. This is unlike POP, where messages are downloaded and deleted from the server immediately, and all email is kept and stored locally by your mail client. The IMAP protocol is specifically designed to support mailbox access by multiple clients simultaneously.

The current version of the IMAP protocol is "4rev1", defined in RFC 3501 [1].

A list of RFC specifications for the core protocol and extensions is maintained by the original author of the IMAP protocol at http://panda.com/imap/rfcs/ .

A list of RFC specifications supported by the Cyrus IMAP server can be found at http://cyrusimap.web.cmu.edu/docs/cyrus-imapd/2.4.16/specs.php .

[ http://phaseit.net/claird/comp.mail.imap/IMAP.html ]

tkbiff knows some IMAP.

Maybe you just want to learn how to go about checking your IMAP mail with Expect.

nsmail has useful code.

SS http://www.hping.org/tclsbignum/imap4.tcl has experimental pure Tcl client-side IMAP implementation. Please test it against your account and report bugs to [email protected]

schlenk The imap code from SS was imported into tcllib cvs (modules/imap4), but isn't a proper tcllib module yet. If someone feels like writing docs, a testsuite or just patches to add the missing functionality, feel free to do so. (Be sure to get the above file from the tcllib repository: there have been changes.)

Gerhard Reithofer 2010-06-30: After some investigation I found out that the module which I reworked is exactly that file above.
More information can be found in imap4, I'm currently discussing with AK about future of the module.


[ CL thinks he's seen code for a prototype client Tcl library. Where did it go? Scott Beasley?]

Mark Roseman I may be mistaken, but I seem to recall a Tcl wrapper around the "c-client" library (part of UWashington's pine) that does IMAP. But this would have been years and years ago when I was working for a place doing a commercial IMAP client (back in 1994?) - EMJ (20-Mar-2008) this might perhaps have been http://www.island-resort.com/tcl-sift.htm .

Or were you looking for iMap: an indexed map viewer?

[Explain the new client tcllib provides as of summer 2004.]

RFox - 2012-07-17 12:21:48

One source of docs: http://docs.activestate.com/activetcl/8.5/tcllib/imap4/imap4.html

HolgerJ Unfortunately, as of today (2016-01-15), the imap4 module of Tcllib doesn't support appending do a mailbox. My application is putting new draft messages into the 'Drafts' folder of an IMAP account.

Appending a new message to a folder works by sending tag APPEND Entw&APw-rfe {[string length $mail]}\r\n to the open channel. If it's ok, the server will reply a string beginning with '+ '. Then send the mail content of length [string length $mail], the server will reply a string beginning with 'tag OK'. The 'tag' itself can by any short alphanumeric string and should be different for each command, like 'A001', 'A002' and so on.

Sometimes, the 'Drafts' folder gets renamed to a folder with a local name like 'Entwürfe' in German, which is beyond the ASCII range. There is a solution for this described in section 5.1.3 of RFC 3501. This is a procedure converting a mailbox named to the needed format, which is called 'modified utf-7':
proc imapMailboxName {s} {
  set status ASCII
  set utf7String ""

  set retval ""
  foreach ch [split $s ""] {
    if {$ch < " " || $ch > "\u007f"} {    ;# special handling for chars below 32 and above 127
      switch -- $status {
        ASCII {                           ;# beginning a new utf7String
          set status UTF7
          set utf7String "\u0000$ch"
        UTF7 {
          append utf7String "\u0000$ch"   ;# appending to an existing utf7String
    } else {
      if {$utf7String != ""} {            ;# a utf7String has to be converted
        append retval "&[string trimright [binary encode base64 "$utf7String"] =]-"
        set status ASCII
        set utf7String ""
      } ;# if
      append retval $ch    
  } ;# foreach

  if {$utf7String != ""} {            ;# a utf7String has to be converted
    append retval "&[string trimright [binary encode base64 "$utf7String"] =]-"
    set status ASCII
    set utf7String ""
  } ;# if
  return $retval
} ;# proc imapMailboxName

In order to create a mailbox, the returning string can be used. In Thunderbird, you can examine the real name of folders by right-clicking on one and look at the properties.