[imapfilter-devel] append message to mailbox

Daniel-Constantin Mierla miconda at gmail.com
Wed Sep 1 18:24:36 EEST 2010


  Hello,

I was searching documentation and API for a function that allows to 
upload an email message to imap server. Also, sometime I need to mangle 
headers (eg, some mailing lists don't have any prefix in subject and I 
want to add one), but I couldn't find existing API, hope I haven't 
missed something obvious.

Not a heavy lua developer here, but I started to use it more lately for 
other purposes so I coded some extensions for imapfilter. If you find 
them useful, would be great to integrate in next version (improvements 
are welcome!).

1) http://bit.ly/azDCcT - here is a patch that adds new function to 
mailbox.lua:
    - append_plain_message(self, mplain, mflags, mdate) - upload a plain 
text formatted email message to imap server with respective flags and 
date - inspired from message copy/move to another imap server

2) http://bit.ly/cVSrIs - rawmessage.lua - new class to mangle plain 
text formatted email message (ie, add header, set header, prefix header, 
...)

Short sample of usage:

require "rawmessage"
...
all = accounta["unsorted"]:select_all()
for tmp, mesg in ipairs(all) do
     mbox, uid = unpack(mesg)
     text = mbox[uid]:fetch_message()
     rawm = RawMessage(text)
     hdr = "X-My-Hdr: okey"
     rawm:add_header(hdr)
     rawm:prefix_header("X-My-Hdr", "-[prefix]-")
     accounta["sorted"]:append_plain_message(rawm:get_message(),
              table.concat(mbox[uid]:fetch_flags(), " "), 
mbox[uid]:fetch_date())
     -- you may want to delete it from "unsorted" now
     ...
end

Thanks,
Daniel

-- 
Daniel-Constantin Mierla
http://www.asipto.com/



More information about the Imapfilter-devel mailing list