php-imap
php-imap copied to clipboard
[Feature Request] Email Threading / Email Conversation
Is there a function to automatically convert a MailObject to an array of messages?
Not presently, although I'd wonder if there's a gmail-specific pattern/api, or if there's a header for threading that's common to multiple email providers?
Threading is more a client specific feature. The client is only checking the Message-IDs in the email headers and depending on the values, it's threading emails or not.
I've built a support ticket tool, where I had the problem, that every sent email was a new email, although all sent emails were for the same support ticket. So I've analyzed those emails and compared emails, which could be threaded.
There is always a reference of the message ID to the before email. I've improved my support ticket tool by adding this reference and since I've this implemented, all the emails from my application, which are sent regarding the same ticket get threaded (grouped) in email clients (Outlook, Google Mail, Thunderbird, Roundcube, ...), which support this. :)
The responsible headers for threading emails are these:
-
References
(contains all unique Message IDs of previous sent emails) -
In-Reply-To
(contains only the unique Message ID to which this single email was replied) -
Message-ID
(the unique Message ID of the current viewed email)
So if this library should support such a feature, we would need to check the above header fields. But I don't believe, that this implementation makes sense since we're not caching anything and due to this, the library would need to check all emails at every execution. This will be very time consuming.
What do you think @bapcltd-marv?
I was typing a bunch of stuff then it occurred to me that if it's sufficiently useful but out-of-scope, there could be a separate utilities package, where stuff like this and #464 could go.
I mention #464 specifically because the pagination implementation I was working on does a search, fetches the uids, then fetches the emails on request rather than at the moment of invocation. A similar approach could be made for retrieving threads, assuming the v2 syntax allows searching via those headers.
Another "utility" as @bapcltd-marv called it: #550