lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 4 August 2013 15:52, Josh Amishav-Zlatin <jamuse@gmail.com> wrote:
Excuse my newb question, using Michal's example code from https://gist.github.com/mkottman/6108316 I used the following code which produced the error below:

# lua5.1 test.lua 
Connected to    74.125.136.109  993
lua5.1: ./imap.lua:26: attempt to index local 'conn' (a nil value)
stack traceback:
        ./imap.lua:26: in function 'connect'
        test.lua:4: in main chunk
        [C]: ?

The error was because I forgot to add the certificates file against which the GMail certificate is checked (I forget to test things locally before I upload, must change that...). I updated the gist with a list of trusted root certificates from Mozilla and a simple test which will load the headers and body of the first message in your inbox.

Can someone explain what the above error means and what is causing it? Another question, where do the capability() and select() functions come from (I don't see them in the imap code)?

The library is a very thin binding over the IMAP protocol, and all magic happens in IMAP_META:command() and IMAP_META.__index. IMAP_META:command(cmd, ...)  will format the IMAP command with the arguments, like adding a sequence number, converting the command to uppercase and concatenating all arguments with spaces. It will then send the command and collect all results into a table, which it returns.

IMAP_META.__index then provides a simple interface over IMAP_META:command(cmd) - instead of writing imap:command("select", ...), you can just do imap:select(...).

There are no "nice" commands to get a message, list folder contents or parsing the MIME formatted messages, you have to parse the responses yourself, maybe with the help of MIME library such as [1]. Keep an IMAP tutorial handy, such as [2], [3], and the reference [4].

[1] http://w3.impa.br/~diego/software/luasocket/mime.html
[2] http://www.skytale.net/blog/archives/23-Manual-IMAP.html
[3] http://donsutherland.org/crib/imap
[4] http://tools.ietf.org/html/rfc3501