The current IDs we generate are not unique - the same Message-ID will get used for every distinct email going out for a particular post (i.e. if it’s sent to 10 users, that Message-ID gets repeated 10 times):
if post.post_number == 1
"<topic/#{topic_id}@#{host}>"
else
"<topic/#{topic_id}/#{post.id}@#{host}>"
end
Message-ID: <topic/3981/53574@meta.discourse.org>
We should append some randomness onto the Message ID (which we can obviously remove when parsing incoming email).
I suspect it may be causing problems but am not entirely sure it is. 99.9% of the time things will be fine, but I know it would have caused problems at companies I’ve worked at previously (e.g. email scanning gateways may reject duplicate Message-IDs with different content).
Note the differing content comes from the post getting emailed to different people.
It really doesn’t need to make sense - “random string” is VERY typical.
If you want it to, I would do both - add the target user.id as well as random data (who knows - perhaps it’s possible now or in the future for the same user to be emailed about a post twice).
I am not exactly sure what’s up with the secondary emails feature, but if all of them are used to notify the user your approach may cause issues. If a user has multiple email addresses then it is going to receive multiple emails with the same Message-ID.