[imapfilter-devel] fetchtext... storetext?
Lefteris Chatzibarbas
lefcha at hellug.gr
Mon Jun 14 00:03:39 EEST 2004
On Sun, Jun 13, 2004 at 02:28:02AM -0500, David DeSimone wrote:
> Hello, I am a new imapfilter user.
>
> Currently I am using fetchmail to pull my mail from an IMAP server, run
> it through procmail for filtering, and store it locally. However, I
> would really prefer to leave my mail on the IMAP server instead, and I
> have found imapfilter as an excellent candidate for doing just that.
>
> I have managed to find good substitutes for nearly all of my current
> procmail rules, but I am curious about two things:
>
> 1. I would like to use spamassassin to detect and filter spam messages
> and send them to a folder for storage.
>
> 2. I would like to make some changes to some of the headers of incoming
> messages.
>
> [...]
After you do a fetchtext() you have a copy of the message locally. You can
then edit the message, which is actually a Lua string, in any way you like, and
then store the modified version to the server (don't forget to delete (or
better move to a backup mailbox) the old version).
A store() function doesn't exist right now (I'll probably add one soon),
but here is one that you could use (define this function before using
it):
function store(account, mbox, message, flags, date)
checktype_aux(account, 'table')
checktype_aux(mbox, 'string')
checktype_aux(message, 'string')
checktype_aux(flags, 'table')
checktype_aux(date, 'string')
if (ifcore.login(account) ~= true) then
return
end
for k, v in ipairs(flags) do
if (string.lower(v) == 'recent') then
table.remove(flags, k)
end
end
local f = ''
if (table.getn(flags) ~= 0) then
f = '\\' .. table.concat(flags, ' \\')
end
local r = ifcore.append(account, mbox, message, f, date)
return r
end
And here is an example:
results = match(myaccount, 'INBOX', myfilter)
text = fetchtext(myaccount, 'INBOX', results)
fast = fetchfast(myaccount, 'INBOX', results)
-- here you edit a message, for example message 2 (ie. the text[2]
-- string) and then:
store(myaccount, 'INBOX', text[2], fast[2]['flags'], fast[2]['date'])
Of course, one could write a more (or less) complicated and useful
store() command to do the job.
More information about the Imapfilter-devel
mailing list