lua-users home
lua-l archive

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


OK, I've put the code up at http://www.tombob.com/limap.c . Don't have
time to do a luaforge or makefile or ... for this now, so it's just the code.

Hope this can get you started.  I link everything statically on my
setup, so I don't know off the top of my head how you would DLL or SO
this.

You can get the UW IMAP library at http://www.washington.edu/imap/ . I
build this library on Windows XP using the supplied makefile.w2k . The
c-client API is mostly documented in docs/internal.txt

The open function is
int luaopen_limap(lua_State *L);

The wrapper exposes the following functions:

> mbox = imap.mailbox {
       full_mailbox_name = "{smtp.gmail.com/imap/ssl}Lua", -- see
docs/naming.txt
       user = "[email protected]",
       password = "not telling",
}
>
> print(mbox)
MAILSTREAM (imap mailbox:
{gmail-imap.l.google.com:993/imap/notls/ssl/user="[email protected]"}Lua,
1162 messages)
>
> =mbox:ping()  -- Are we still connected?
true
>
> =mbox:num_messages()
1162
>
> =mbox:mailbox()
{gmail-imap.l.google.com:993/imap/notls/ssl/user="[email protected]"}Lua
>
> =mbox:raw_header(1162)
Delivered-To: [email protected]
   [.... lots of header ...]
Message-ID: <[email protected]>
To: Lua list <[email protected]>
Subject: Re[2]: LuaSocket SMTP receive

>
> =mbox:raw_body(1162)
- Show quoted text -
Hi Robert!

Thanks for your offer, I would like to receive code and take a look at
it.

Can you please post it there or email me directly to dp at xeepe.com ?

Thanks!
Dennis

> I've got a wrapper around the UW IMAP c-client library. It's not
> packaged nicely, but if anyone's interested I can send you the raw
> code. The UW IMAP lib is kind of like the reference implementation of
> IMAP, but it also includes POP3, mbox, ... and can deal with TLS and
> the like. I've also started a wrapper around the SMTP bit of this lib,
> but that's not quite there yet.

> The stuff in LuaSocket is brilliant, but once you get into using
> different mail stores and TLS territory things become way more
> difficult to deal with. So this wraps things up quite nicely for
> email.

> Robby


--=20
Best regards,
 Dennis                            mailto:[email protected]

>
> S = mbox:structure(1162)
> =stringify(S)
{
 env = {
   sender = {
     [1] = {
       host = "bazar2.conectiva.com.br",
       mailbox = "lua-bounces",
     },
   },
   to = {
     [1] = {
       personal = "Lua list",
       host = "bazar2.conectiva.com.br",
       mailbox = "lua",
     },
   },
   references = "<[email protected]>
<[email protected]>
<[email protected]>",
   date = "Fri, 17 Oct 2008 13:45:59 +0300",
   ["in-reply-to"] =
"<[email protected]>",
   from = {
     [1] = {
       personal = "Dennis Povshedny",
       host = "xeepe.com",
       mailbox = "dp",
     },
   },
   ["reply-to"] = {
     [1] = {
       personal = "Lua list",
       host = "bazar2.conectiva.com.br",
       mailbox = "lua",
     },
   },
   ["message-id"] = "<[email protected]>",
   subject = "Re[2]: LuaSocket SMTP receive",
 },
 body = {
   bytes = 887,
   encoding = "QUOTED-PRINTABLE",
   subtype = "PLAIN",
   type_parameter = {
     [1] = {
       attribute = "CHARSET",
       value = "utf-8",
     },
   },
   lines = 29,
   type = "TEXT",
 },
}
>
> =mbox:part(1162, "1") -- The second param is a dotted part number for multipart emails.
Hi Robert!

Thanks for your offer, I would like to receive code and take a look at
it.
   [.... etc. ... ]
>

Also have:

mbox:delete(msgno)
mbox:mark_read(msgno)
mbox:find_unseen()


And to aid with character sets and encodings:

imap.decode_base64(s)
imap.encode_base64(s)
imap.decode_quotedprintable(s)
imap.encode_quotedprintable(s)

imap.utf8_from_charset(s, [charset])  -- tries to guess if no charset is given
imap.utf8_to_charset(s, charset, [err_char])  -- replaces
untranslatable chars with '_' if no err_char is given
imap.utf8_from_mime2(s)  -- translates from those weird encoded
subject, to and from strings
imap.utf8_charset(s)  -- checks if s is a recognised charset, lists
all charsets if called without an argument
imap.utf8_textwidth(s)  -- attempts to tell you how many letters in
the utf8 string


That's all.  Oh, the code contains a currently not quite working stab
at getting the smtp part working as well. Ignore that or fix it.

Robby