[imapfilter-devel] Archive mail based on sender or sender domain
Lefteris Chatzibarbas
lefcha at hellug.gr
Sun Jun 13 11:38:58 EEST 2004
On Thu, Jun 10, 2004 at 07:37:09PM -0700, Ezsra McDonald wrote:
> I have been looking over the new IMAPfilter. Its very
> nice.
>
> I am not a programmer so I am not sure how to extend
> it. As you know I asked a while back how I can make
> archive folders based on the sender name or domain.
>
> Do you have any recommendations or examples of how to
> do this?
Here is an example:
results = match(myaccount, 'INBOX', myfilter)
headers = fetchheaders(myaccount, 'INBOX', { 'from' }, results)
for msgid, msghdrs in pairs(headers) do
-- check for "From: foo at bar"
_, _, user, domain = string.find(msghdrs, 'From: ([%w.-]+)@([%w.-]+)')
if (user ~= nil or domain ~= nil) then
print(msgid, user, domain)
-- move(myaccount, 'INBOX', myaccount, user, { msgid })
end
-- check for "From: Foo Bar <foo at bar>"
_, _, user, domain = string.find(msghdrs, 'From: .+<([%w.-]+)@([%w.-]+)>')
if (user ~= nil or domain ~= nil) then
print(msgid, user, domain)
-- move(myaccount, 'INBOX', myaccount, user, { msgid })
end
end
Basically, it fetches the "From" headers of the messages that match the filter,
tries to find the user and domain of the message and then moves the messages to
a mailbox named after the user (actually it just prints the user and domain,
for testing purposes).
More information about the Imapfilter-devel
mailing list