Server does not find a message with a subject divided in two lines.
NilsHoyer opened this issue · 3 comments
I have a mail on my IMAP server, I've downloaded with Thunderbird into a file. I start with the following lines:
From:
Date: Sun, 25 Aug 2024 12:13:18 +0200
Subject: [Test] Advertise
(WindowsC02HFGPPDV13S-1-5-21-106835334-3766545784-1673647939-1000)
Message-Id: <6C1FGVPFXNU4.OT5FN99GEAZ5@macbookpro>
MIME-Version: 1.0
Now, I try to find it with following code:
var searchQuery = SearchQuery.SubjectContains("Advertise (");
var uniqueIds = _mailFolder.SearchAsync(searchQuery, Context.CancellationToken).Result;
The message will not be found. But Thunderbird displays the subject as well.
I wonder about the Subject
is divided into two lines, but I'm not a Mail professional.
Inside the log, I found this line:
C: A00000008 UID SEARCH SUBJECT "Advertise ("
Am I right, you believe, this is a server bug?
Can I specify another search string, which finds this message?
I've sent this message with MailKit.
Yea, this is a server bug.
The Subject header that is split across 2 lines is perfectly legal, so there's nothing wrong with the message itself, but the server is clearly not unfolding the Subject value before doing a string match against it.
You might be able to work around this by doing:
var searchQuery = SearchQuery.SubjectContains("Advertise\r\n (");
But I wouldn't hold out hope.
Maybe your suggestion works, but I believe a better solution is to use less matching definition for the SearchQuery and use a regular expression after fetching the mail.
If I'm right, IMAP does not offer regular expressions or joker characters for the SEARCH command?
Unfortunately, IMAP does not support regular expressions or wildcard matching in the SEARCH command.
As you said, the best way might be to do client side matching.