IMAP - how to search all messages in a conversation thread?

I am working on an IMAP client and want to be able to find a list of all the messages that are referenced in the conversation thread.

I know that the β€œLinks” heading contains a list of messages that are referred to in the conversation, so I tried to search for it like this:

TAG1 UID SEARCH all HEADER References "< CAOZnC-Nr+Q+bS_Nn5XiZ6A-kw=ZRBYrNbdoRfgZ65OjGA4_BKg@mail.gmail.c om>" 

But he does not return anything. I successfully searched for a single message using the "Message-ID" header, for example:

 TAG2 UID SEARCH all HEADER Message-ID "< 918171f1-8822-4869-afb4-de76b05b850b@xtnvmta101.xt.local >" 

How to do this using IMAP 4?

NOTE. I know that search queries only work with one mailbox at a time, but at least half of these messages are in the destination folder for my searches, and they do not appear in my search results.

+6
source share
1 answer

Your search query is incorrect - you must remove the ALL token from there - what you are sending is not syntactically valid. The correct form is, for example:

 1 UID SEARCH HEADER references "< CAOZnC-Nr+Q+bS_Nn5XiZ6A-kw=ZRBYrNbdoRfgZ65OjGA4_BKg@mail.gmail.c om>" 

This will help you.

However, remember that the References header of the attached message may not contain everything that the message will contain earlier in the stream - the restrictions on the total length of the string apply, which means that the total size of the header is limited, and some of the "middle" elements can be deleted .

There are methods to overcome this limitation, for example, the INTHREAD operator defined in the experimental extension supported by Dovecot (and no other IMAP, AFAIK servers). Using this, you can simply request all the UIDs in the stream where a particular message is present, for example:

 1 UID SEARCH INTHREAD REFS HEADER Message-Id "something" 

I really tested this with Dovecot and it works (and has worked for many years). Please keep in mind that Dovecot does not support the search key MESSAGEID , and that the syntax for INTHREAD REFS is different from what the draft standard says. However, the command above works.

If you need to work without any extensions, then it looks like you have no other chance but to:

  • Extract HEADER.FIELDS[Message-Id References In-Reply-To] immediately and analyze the client messages,
  • Whenever your SEARCH HEADER References returns a new UID, select HEADER.FIELDS[References In-Reply-To] , extract the "new" message identifiers from it, add them at the end of the queue and continue.

Finally, you can also rely on GMail X-GM-THRID if you mainly target Gmail users, but please advise that their implementation is quite limited, including a hard limit of not more than 100 messages per stream, non-standard stream correlation, etc. d. etc..

Ok, take your poison.

+7
source

Source: https://habr.com/ru/post/946094/


All Articles