Emails are not threaded in Outlook 2013

in-reply-to is set to this value

In-Reply-To: <topic/>

Thus, all replies should thread to this topic, if what you say is true. Is it?

No. You may talk about these headers:

In-Reply-To: <topic/>
References: <topic/>

It has been explained here why it is wrong:

In-Reply-To and References must point to a unique message id. <topic/> is not a unique message id thus mail clients cannot do threading. It works when I replace these headers with its correct message ids manually on the imap server.

I had a look on a github email. They do it this way:

Message-ID: <discourse/onebox/pull/257/>
In-Reply-To: <discourse/onebox/pull/>
References: <discourse/onebox/pull/>

Maybe fixing the Message-ID in discourse mails suffices. Dicourse does it this way (wrong!):

Message-ID: <5475a885c34fd_2fd5036a24480ae@archvm.mail>
In-Reply-To: <topic/>
References: <topic/>

Hmmm… How about this?

Message-ID: <topic/16501/>
In-Reply-To: <topic/16501/>
References: <topic/16501/> <topic/16501/>

What you describe is impossible – I don’t know how to get, in Ruby code, the message ID header that the mail server appends to emails at the time it sends them, before dispatching the email. That ID doesn’t even exist until the message is being transmitted.

Those ids are created at the time the message is sent by the mail server as far as I know, and they are internal to the mail server software.

Also, the “in reply to” should always be in reply to the original topic creation, the first post of the topic, which you may never have even received an notification about. So there is no “message id” to work with in that case…

As far as I know it is created by the first SMTP server when it is missing. Maybe this could help; it should be possible with action mailer.

That is not that bad. I just tried it on a mailman mailinglist in my inbox. I deleted the parent message and the threading did not break because the References headers are fine. Maybe also this commit description here could help a bit:

see here:

   Note: Some implementations parse the "References:" field to display
   the "thread of the discussion".  These implementations assume that
   each new message is a reply to a single parent and hence that they
   can walk backwards through the "References:" field to find the parent
   of each message listed there.

As @codinghorror mentioned in-reply-to must be the first email. So it should be sth. like this, should’t it?

Message-ID: <topic/16501/>
In-Reply-To: <topic/16501/>
References: <topic/16501/> <topic/16501/>

Which is fine, but let’s say this happens:

  1. You read a topic.
  2. You reply to post #25 in that topic as post #27.
  3. You go offline for hours.
  4. Post #28 arrives and mentions your name (it is not a reply)

So there are three numbers in play here:

  1. the topic (post #1)
  2. Your post (post #27)
  3. The post which mentions you (post #28)

Note that this post is a reply to the topic. That’s the typical case, we want email to thread based on the TOPIC. We have no idea if you have an email about the first post, though.

So when you get an email notification about the mention (post #28), that email should contain:

Message-ID: <topic/16501/>
In-Reply-To: <topic/>
References: <topic/> 

I guess “References” is the key here? All the posts in a topic should “reference” the first post, even though you may not have that email message.

Right now it says

Message-ID: <54752ba335286_633fee205cc454883a2@tiefighter6-virtual_host.mail>
In-Reply-To: <topic/>
References: <topic/>

So the only thing missing is the Message-ID header. All replies are in reply to the first post of the topic, though…

OK I just checked this in

topic_identifier = "<topic/#{topic_id}@#{host}>"
post_identifier = "<topic/#{topic_id}/#{post_id}@#{host}>"
@message.header['Message-ID'] = post_identifier
@message.header['In-Reply-To'] = topic_identifier
@message.header['References'] = topic_identifier

Let’s see if that helps? no idea, but I can check headers…


Also here’s what a random GitHub reply has in it

Message-ID: <discourse/discourse/pull/3006/>
In-Reply-To: <discourse/discourse/pull/>
References: <discourse/discourse/pull/>

so this might be the missing header we needed, if it works.

1 Like

OK I can confirm this works. In a reply I just got via email here I see

Message-ID: <topic/22572/>
In-Reply-To: <topic/>
References: <topic/>

So it corresponds pretty exactly with what GitHub sends in their email notifications. Thanks for the nudge @rumpelsepp hopefully this helps.

1 Like

You’re welcome. :blush:
It looks fine now but I don’t know if there are any issues left. I will just test it a few days. In case of issues I will ping you back. Anyway, thanks for the fix!

1 Like

Threads now well in KMail, K9 and Thunderbird! But only Roundcube has still problems with this. Maybe this is now a roundcube upstream issue rather than a discourse one, isn’t it?