[imapfilter-devel] interest in filter mailing lists on unknown names

Lefteris Chatzibarbas lefcha at hellug.gr
Tue May 11 12:57:46 EEST 2004


On Tue, May 11, 2004 at 02:41:54PM +1000, Gautam Gopalakrishnan wrote:
> Hey,
> 
> I've always wanted to do this with procmail on my POP mail, didn't
> know how to. Anyway, here's some code I wrote. It almost works.
> Anybody with more skill in Lua could maybe help out here. The
> filter runs for only half of my messages. Looks like something to do
> with table.foreachi, but I can't figure it out.
> 
> As usual, no guarantees. To be safe, you could change move() to copy().
> Also, if you want to filter based on the subject having [listname],
> it's trivial to change the regex in function and the fetchheader line
> 
> Any feedback is welcome.
>
> [...]
>
> function filter_listid(k, v) 
> 	hdr = fetchheaders(acc1, 'INBOX', {'List-Id'}, {v})
> 	if hdr[v] == nil then return nil end
> 	hdr[v] = string.gsub(hdr[v], "[\n\r]", "")
> 	if hdr[v] == "" then return nil end
> 	z, z, listname = string.find(hdr[v], "<([a-zA-Z0-9_.-]-)>", 1)
> 	if listname == nil then return nil end
> 	move(acc1, 'INBOX', acc1, listname, {v})
> 	return nil
> end
> 
> f_all  = {}
> 
> results = match(acc1, 'INBOX', f_all)
> if results ~= nil
> then
> 	table.foreachi(results, filter_listid)
> end

Here is another way to do this:

	results = match(acc1, 'INBOX', {})
	hdrs = fetchheaders(acc1, 'INBOX', { 'List-Id' }, results)

	for msgid, msghdr in pairs(hdrs) do
		_, _, listname = string.find(msghdr, "<([%w_.-]+)>")
		if listname ~= nil then
			print(msgid, listname)
	--		move(acc1, 'INBOX', acc1, listname, { msgid })
		end
	end

Of course, if all goes well, comment print() and uncomment move().




More information about the Imapfilter-devel mailing list