After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 787542 - Fix search for exact phrase in body of mail on Gmail
Fix search for exact phrase in body of mail on Gmail
Status: RESOLVED FIXED
Product: evolution-data-server
Classification: Platform
Component: Mailer
3.22.x (obsolete)
Other Linux
: Normal minor
: ---
Assigned To: evolution-mail-maintainers
Evolution QA team
Depends on:
Blocks:
 
 
Reported: 2017-09-11 11:31 UTC by Andrea Vai
Modified: 2017-09-18 07:50 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Andrea Vai 2017-09-11 11:31:40 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
Comment 1 Milan Crha 2017-09-15 12:12:27 UTC
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
Comment 2 Andrea Vai 2017-09-15 13:03:35 UTC
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)
Comment 3 Milan Crha 2017-09-18 07:17:43 UTC
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.
Comment 4 Milan Crha 2017-09-18 07:50:05 UTC
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+)