Once upon a time I wrote a mail-client, which worked in the console directly via Maildir manipulation.
My mail client was written in C++, and used Lua for scripting unlike clients such as mutt, alpine, and similar alternatives which don't have complete scripting support.
I've pondered several times whether to restart this project, but I think it is the right thing to do.
The original lumail client has a rich API, but it is very ad-hoc and random. Functions were added where they seemed like a good idea, but with no real planning, and although there are grouped functions that operate similarly there isn't a lot of consistency. The implementation is clean in places, elegant in others, and horrid in yet more parts.
This time round everything is an object, accessible to Lua, with Lua, and for Lua. This time round all the drawing-magic is will be written in Lua.
So to display a list of Maildirs I create a bunch of objects, one for each Maildir, and then the Lua function Maildir.to_string is called. That function looks like this:
-- -- This method returns the text which is displayed when a maildir is -- to be show in maildir-mode. -- function Maildir.to_string(self) local total = self:total_messages() local unread = self:unread_messages() local path = self:path() local output = string.format( "[%05d / %05d] - %s", unread, total, path ); if ( unread > 0 ) then output = "$[RED]" .. output end if ( string.find( output, "Automated." ) ) then output = strip_colour( output ) output = "$[YELLOW]" .. output end return output end
The end result is something that looks like this:
[00001 / 00010 ] - Amazon.de
[00000 / 00023 ] - Automated.root
The formatting can thus be adjusted clearly, easily, and without hacking the core of the client. Providing I implement the apporpriate methods to the Maildir object.
It's still work in progress. You can view maildirs, view indexes, and view messages. You cannot reply, forward, or scroll properly. That said the hard part is done now, and I'm reasonably happy with it.
The sample configuration file is a bit verbose, but a good demonstration regardless.
See the code, if you wish, online here:
Tags: lua, lumail, lumail2 2 comments