I want to get all the emails under the same thread using IMAP.
I used the following code but It doesn't return any email IDs.
search_criteria = f'HEADER REFERENCES "{message_id}"'
result, data = imap.search(None, search_criteria)
I cannot search like this, as another email can have the same subject name.
mail.search(None, '(SUBJECT "Sending email using SMTP")')
What should the search criteria be for fetching them using references?
Suppose,
Email1 is in the inbox.
And Email2 is replied to Email1. So, Email2 has the message-id of Email1 in the references field of itself.
In the same way Email3 is replied to Email2.
So, Email3 has message-ids of Email1 and Email2 in the references field of itself.
And Email4 has message-ids of Email1, Email2 and Email3 in the references field.
So, I want to get Email2, Email3, Email4 When I search using IMAP.
What should be the search criteria?