Sibling tracker to MDLSITE-6059. I originally though this was more of an AWS setup bug just with how moodle.org's email mta is setup, which overwrites the message id's created by moodle which breaks the threading. But then I realized that this can be gracefully worked around in a generic way in core.
The problem is the first email in a thread would be like:
And then second email reply reference it:
But AWS overwrites all message id's so the first email looks like:
But we don't actually need the message Id's to match, if we simply add the References to the initial email then most email clients will thread the anyway because they are designed to thread even with a partial subset of the emails.