[imapfilter-devel] Filter empty bodies

Lefteris Chatzibarbas lefcha at hellug.gr
Tue Jul 27 11:13:40 EEST 2004


On Fri, Jul 23, 2004 at 07:30:43AM -0700, Ezsra McDonald wrote:
> I get a lot of messages with empty bodies. I want to
> delete/move these messages. Can this be done with
> imapfilter?

Basically the only way I can thing of to do this, is to fetch the body
parts of the messages and see if they are empty.  But as I was looking
on this I found a bug... I attach a patch that corrects this problem.

So maybe you could do something like:

	results = match(myaccount, 'INBOX', { 'smaller 5000' })
	body = fetchbody(myaccount, 'INBOX', results)

	sentenced = {}
	for msgid, msgbody in pairs(body) do
		if msgbody == '' then
			print(msgid)
			table.insert(sentenced, msgid)
		end
	end

	delete(myaccount, 'INBOX', sentenced)

-------------- next part --------------
diff -ruN imapfilter-1.0.orig/interface.lua imapfilter-1.0/interface.lua
--- imapfilter-1.0.orig/interface.lua	Sun May 23 02:30:23 2004
+++ imapfilter-1.0/interface.lua	Mon Jul 26 23:00:05 2004
@@ -308,9 +308,9 @@
 	local results = {}
 	for i, v in ipairs(messages) do
 		local _, fetch = ifcore.fetch(account, tostring(v), 'BODY.PEEK[HEADER]')
-		local _, _, header = string.find(fetch, '{%d+}\r\n(.*)%)\r\n')
+		local _, _, header = string.find(fetch, '%(BODY%[HEADER%] {%d+}\r\n(.*)%)\r\n')
 		if (header ~= nil) then
-			results[v] = header
+			results[tonumber(v)] = header
 		end
 	end
 
@@ -345,9 +345,12 @@
 	local results = {}
 	for i, v in ipairs(messages) do
 		local _, fetch = ifcore.fetch(account, tostring(v), 'BODY.PEEK[TEXT]')
-		local _, _, body = string.find(fetch, '{%d+}\r\n(.*)%)\r\n')
+		local _, _, body = string.find(fetch, '%(BODY%[TEXT%] {%d+}\r\n(.*)%)\r\n')
+		if (body == nil) then
+			_, _, body = string.find(fetch, '%(BODY%[TEXT%] "(.*)"%)\r\n')
+		end
 		if (body ~= nil) then
-			results[v] = body
+			results[tonumber(v)] = body
 		end
 	end
 
@@ -382,11 +385,14 @@
 	local results = {}
 	for i, v in ipairs(messages) do
 		local _, fetch = ifcore.fetch(account, tostring(v), 'BODY.PEEK[HEADER]')
-		local _, _, header = string.find(fetch, '{%d+}\r\n(.*)%)\r\n')
+		local _, _, header = string.find(fetch, '%(BODY%[HEADER%] {%d+}\r\n(.*)%)\r\n')
 		local _, fetch = ifcore.fetch(account, tostring(v), 'BODY.PEEK[TEXT]')
-		local _, _, body = string.find(fetch, '{%d+}\r\n(.*)%)\r\n')
+		local _, _, body = string.find(fetch, '%(BODY%[TEXT%] {%d+}\r\n(.*)%)\r\n')
+		if (body == nil) then
+			_, _, body = string.find(fetch, '%(BODY%[TEXT%] "(.*)"%)\r\n')
+		end
 		if (header ~= nil and body ~= nil) then
-			results[v] = header .. body
+			results[tonumber(v)] = header .. body
 		end
 	end
 
@@ -429,10 +435,10 @@
 			for s in string.gfind(flags, '%w+') do
 				table.insert(f, s)
 			end
-			results[v] = {}
-			results[v]['flags'] = f
-			results[v]['date'] = date
-			results[v]['size'] = size
+			results[tonumber(v)] = {}
+			results[tonumber(v)]['flags'] = f
+			results[tonumber(v)]['date'] = date
+			results[tonumber(v)]['size'] = size
 		end
 	end
 
@@ -469,9 +475,10 @@
 	for i, v in ipairs(messages) do
 		local _, fetch = ifcore.fetch(account, tostring(v), 'BODY.PEEK[HEADER.FIELDS (' ..
 		    table.concat(headers, ' ') .. ')]')
-		local _, _, hdrs = string.find(fetch, '{%d+}\r\n(.*)%)\r\n')
+		local _, _, hdrs = string.find(fetch, 'BODY%[HEADER.FIELDS %(.*%)%] {%d+}\r\n(.*)%)\r\n')
+		print(hdrs)
 		if (hdrs ~= nil) then
-			results[v] = hdrs
+			results[tonumber(v)] = hdrs
 		end
 	end
 


More information about the Imapfilter-devel mailing list