imapfilter icon indicating copy to clipboard operation
imapfilter copied to clipboard

How to detect and move (mailing list) mails that are *NOT* sent to one of my e-mail addresses?

Open rafo opened this issue 2 years ago • 1 comments

Maybe I am blind, but how can I move all e-mails that are not sent to one of my e-mail addresses?

Instead of something like: gmail.INBOX:contain_to("[email protected]")

maybe something like: gmail.INBOX:not_contain_to("[email protected]")

I tried:

-- Move all mails which are not addressed to me 
MoveMailingListMails = (gmail.INBOX:is_unseen() -
                       (gmail.INBOX:contain_to("[email protected]") +
                        gmail.INBOX:contain_to("[email protected]")))
gmail:create_mailbox("MailingList")
MoveMailingListMails:move_messages(gmail['MailingList'])

with no luck.

I tried RegEx with negative look ahead, but had no luck either (and its a ugly solution if you try to test a list of e-mail addresses).

Maybe I need something in LUA to check the incoming mail against a list of e-mail addresses? And if its not in there move it to the mailing list folder?

rafo avatar Jan 24 '23 11:01 rafo

What messages do you get in the MailingList mailbox when you run the above snippet?

I mean for starters, I would verify how many messages each query gets for example:

all = gmail.INBOX:select_all()
print("all", #all)

unseen = gmail.INBOX:is_unseen()
print("unseen", #unseen)

to1 = gmail.INBOX:contain_to("[email protected]")
print("to googlemail", #to1)

to2 = gmail.INBOX:contain_to("[email protected]")
print("to gmail", #to2)

print("mailing lists", #(unseen - (to1 + to2)))

lefcha avatar Feb 08 '23 15:02 lefcha