GNOME Bugzilla – Bug 787542
Fix search for exact phrase in body of mail on Gmail
Last modified: 2017-09-18 07:50:05 UTC
As pointed out in the evolution mailing list [1], when I need to find an exact phrase (i.e. I put it in double quotes, "my search strings") in the search box, evo shows messages containing all the strings, but does not restrict the results to the exact phrase. It happens searching for text in message body, but it works as expected if I search in the subject. The problem affects (only?) gmail IMAP accounts (see the thread starting at [1] for details). [1]: https://mail.gnome.org/archives/evolution-list/2016-November/msg00052.html
Thanks for a bug report. I finally looked at this, but I didn't find anything useful. There is X-GM-RAW search extension [1], which sounds promising, but it doesn't work either, or I do not know how to write the search term in a way which the Gmail will understand as "one word", not as multiple words. I even tried to use a '+' or '&' instead of the space, but neither helped, the server returned to me two messages, where one had that exact phrase, but the other one only those words "far from each other". I can add a special case, when the search term will start with "X-GM-RAW", then interpret it as such and pass it to the server in some way, instead of the BODY search, but that doesn't sound a) user friendly, b) users might not know. Another option is to verify that the UID set returned from the server is actually the one requested by the user, but it has the downside which the server-side search tries to avoid, which is to not download each message to run the search. [1] https://developers.google.com/gmail/imap/imap-extensions#extension_of_the_search_command_x-gm-raw
I am not sure I am even understanding the basics, but: from [1] above I read "Arguments passed along with the X-GM-RAW attribute when executing the SEARCH or UID SEARCH commands will be interpreted in the same manner as in the Gmail web interface.". To get an exact phrase in the Gmail web interface, I put "exact phrase" (with double quotes) in the text box. So, could it be that double quotes " " need to be passed surronding the phrase? (maybe escaped as \" ?) Sorry if it's a silly guess, or if you already tried it. (See also something similar at https://stackoverflow.com/questions/13403790/python-imap-search-for-partial-subject)
As it currently works with the IMAP body search, Camel's IMAPx divides the search term by words (which understands double quotes), thus when you type into the Search field in Evolution something like: 'two words' (single quotes for clarity only), then it issues: UID SEARCH BODY two BODY words but if you type something like: '"two words"', then it issues: UID SEARCH BODY "two words" Gmail doesn't do any difference in the two term and returns the same set of UIDs, while other servers properly search for both words in the first case and for an exact phase in the second case. I tried to replace BODY with X-GM-RAW and issued UID SEARCH X-GM-RAW "two words" which didn't change anything. I also did think of some escaping of the double quotes, but it didn't work for some reason. I might do it wrong, as I tried to pass those quotes from the UI, without modifying the code. I re-tried with changed code and the command: UID SEARCH X-GM-RAW "\"two words\"" and this time it seems to do what it is supposed to do. I did read that stackoverflow question, that's how I found the X-GM-RAW extension. (In reply to Milan Crha from comment #1) > I can add a special case, when the search term will start with "X-GM-RAW", > then interpret it as such and pass it to the server in some way, instead of > the BODY search, but that doesn't sound a) user friendly, b) users might not > know. Okay, this is nonsense, it'll be better when users will not know about this. As I know what to do now I'll write the change in Camel. Thanks for pushing me the right way.
The below change changes the BODY search to X-GM-RAW when the word is a multiword token and the server is a Gmail server. Created commit c24c113db in eds master (3.27.1+) Created commit 7be9c717e in eds gnome-3-26 (3.26.1+)