[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: imap client
- From: Choonster TheMage <choonster.2010@...>
- Date: Mon, 5 Aug 2013 00:27:00 +1000
On 4 August 2013 23: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:
>
> #!/usr/bin/lua
>
> local imap = require "imap"
> local gmail = imap.connect("imap.gmail.com", 993, true)
> gmail:capability()
> gmail:login("myuser@gmail.com", "my.password")
> -- gmail:select "CustomFilter" -- open a folder
> local message = gmail:fetch "593 BODY[TEXT]"
>
>
> # 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]: ?
>
> Can someone explain what the above error means and what is causing it?
This means that the ssl.wrap function called on line 25 of imap.lua
returned nil instead of the wrapped socket object the IMAP code was
expecting; which means that it encountered an error of some sort while
trying to wrap the socket. If you wrap an assert call around the
ssl.wrap call (shown below), it should throw an error with a
description of what went wrong.
Line 25 changes from this:
conn = ssl.wrap(conn, params)
To this:
conn = assert(ssl.wrap(conn, params))
> Another question, where do the capability() and select() functions come from
> (I don't see them in the imap code)?
When you try to look up a key that doesn't exist in a table, Lua calls
that table's __index metamethod (if it has one) and that function's
return value is the result of the expression. In this case when you
call a method on the IMAP connection object, the __index metamethod
returns a function that calls the IMAP_META:command method with the
method name as the first argument, followed by any arguments you
passed to the method.
The IMAP_META:command method just sends this command with its
arguments over the IMAP connection and returns the response from the
server.
>
> Thanks!
> Chris
>