Reputation: 3320
I use imapfilter that uses a Lua script as config. I am trying to match emails subjects containing [sometext] at any position.
So I tried:
results = account1.INBOX:contain_subject('[sometext]')
This performs a search on the server side. It generates the following IMAP command:
UID SEARCH CHARSET "ISO-8859-15" ALL SUBJECT "[sometext]"
But it matches sometext
even without the brackets.
Same thing happens for:
results = account1.INBOX:match_subject('%[sometext%]')
This performs a local search so it first downloads all the Subject headers and then it matches them against the regular expression. But, it does not match anything.
What would be the correct way to match the [sometext]
string in my subjects?
UPDATE
I gave up on trying to find how to make an exact search on an IMAP server. I tried using other clients than Imapfilter and even telnet directly into the IMAP server to verify the results of a SEARCH command, and they all behaved in the same way, returning wrong results. So the sloppy search issue is on the IMAP server side.
So what I ended up doing is a two pass operation. First I send the SEARCH, then I filter the search results on the client side to eliminate the wrong ones. Not ideal but I have no more time to waste on this.
I'll let the question open in case someone finds a solution.
Upvotes: 0
Views: 122
Reputation: 9685
IMAP text search is inclusive, not exact. The specification says (I'm paraphrasing here, not being exact) that the server should include this and and that in the result, without saying that it should exclude anything. This gives servers scope to include borderline cases, or to simplify their code by disregarding non-letters, or, or, or.
The above implies that can assume that what you want will be in the server's result, but if you need an exact search, you have to check again on the client. The server will give you all the matches you want and maybe a few spurious extras.
(A common example of this is that if you search for "answers", the server may include a message that mentions "answer", because its search engine works on word stems rather than exactly.)
Upvotes: 1