# Emails are not threaded in Outlook 2013

**URL:** <https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501>\
**Category:** Bug\
**Created:** [2014年六月13日 04:36 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501 "2014-06-13T04:36:40Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2014年十一月26日 12:21 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/25 "2014-11-26T12:21:47Z")

</div>

`in-reply-to` is set to this value

`In-Reply-To: <topic/16501@meta.discourse.org>`

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

---

<div class="post-metadata">

**Author:** ![rumpelsepp](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rumpelsepp](https://meta.discourse.org/u/rumpelsepp)\
**Post date:** [2014年十一月26日 12:33 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/26 "2014-11-26T12:33:40Z")

</div>

No. You may talk about these headers:

```plaintext
In-Reply-To: <topic/16501@meta.discourse.org>
References: <topic/16501@meta.discourse.org>

```

It has been explained here why it is wrong:

> [@peternlewis](#):
>
> References: lists the parent’s References header followed by the parent’s message ID.
> 
> If you look at ours currently, it looks like this:
> 
> Message-ID: \<539a986f8300\_5a3fae28acd8c8201e9@forum.mail\>  
> In-Reply-To: \<topic/96@forum.keyboardmaestro.com\>  
> References: \<topic/96@forum.keyboardmaestro.com\>
> 
> and
> 
> Message-ID: \<539a9904d40bd\_5a3fae28d5b8242036d@forum.mail\>  
> In-Reply-To: \<topic/96@forum.keyboardmaestro.com\>  
> References: \<topic/96@forum.keyboardmaestro.com\>
> 
> which is clearly wrong. The first one was the original PM, so should not have an In-Reply-To or References header, and the second one (the reply, should look like this:
> 
> Message-ID: \<539a9904d40bd\_5a3fae28d5b8242036d@forum.mail\>  
> In-Reply-To: \<539a9904d40bd\_5a3fae28d5b8242036d@forum.mail\>  
> References: \<539a986f8300\_5a3fae28acd8c8201e9@forum.mail\>
> 
> And a reply to that reply should look like this:
> 
> Message-ID: \<adsassadfdfsdfs\_sddfsdfsaererfgdsf@forum.mail\>  
> In-Reply-To: \<539a986f8300\_5a3fae28acd8c8201e9@forum.mail\>  
> References: \<539a986f8300\_5a3fae28acd8c8201e9@forum.mail\> \<539a9904d40bd\_5a3fae28d5b8242036d@forum.mail\>

`In-Reply-To` and `References` must point to a unique message id. `<topic/16501@meta.discourse.org>` 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.

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

```plaintext
Message-ID: <discourse/onebox/pull/257/r20941543@github.com>
In-Reply-To: <discourse/onebox/pull/257@github.com>
References: <discourse/onebox/pull/257@github.com>

```

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

```plaintext
Message-ID: <5475a885c34fd_2fd5036a24480ae@archvm.mail>
In-Reply-To: <topic/753@discourse.sevenbyte.org>
References: <topic/753@discourse.sevenbyte.org>

```

---

<div class="post-metadata">

**Author:** ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
**Post date:** [2014年十一月26日 21:30 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/27 "2014-11-26T21:30:33Z")

</div>

> [@rumpelsepp](#):
>
> References: lists the parent’s References header followed by the parent’s message ID.

Hmmm… How about this?

```
Message-ID: <topic/16501/27@meta.discourse.org>
In-Reply-To: <topic/16501/26@meta.discourse.org>
References: <topic/16501/25@meta.discourse.org> <topic/16501/26@meta.discourse.org>

```

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2014年十一月26日 22:30 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/28 "2014-11-26T22:30:41Z")

</div>

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..

---

<div class="post-metadata">

**Author:** ![rumpelsepp](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rumpelsepp](https://meta.discourse.org/u/rumpelsepp)\
**Post date:** [2014年十一月26日 23:23 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/29 "2014-11-26T23:23:28Z")

</div>

> [@codinghorror](#):
>
> 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.

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.

- [http://stackoverflow.com/a/6602846](http://stackoverflow.com/a/6602846)
- [http://blog.mailgun.com/tips-tricks-avoiding-gmail-spam-filtering-when-using-ruby-on-rails-action-mailer/](http://blog.mailgun.com/tips-tricks-avoiding-gmail-spam-filtering-when-using-ruby-on-rails-action-mailer/)

> [@codinghorror](#):
>
> 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..

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: [https://projects.archlinux.org/aur.git/commit/?id=8658bf22aac73ed8d32d3f998c3c13528f415ffe](https://projects.archlinux.org/aur.git/commit/?id=8658bf22aac73ed8d32d3f998c3c13528f415ffe)

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.

```

---

<div class="post-metadata">

**Author:** ![rumpelsepp](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rumpelsepp](https://meta.discourse.org/u/rumpelsepp)\
**Post date:** [2014年十一月26日 23:27 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/30 "2014-11-26T23:27:11Z")

</div>

> [@riking](#):
>
> Hmmm… How about this?
> 
> Message-ID: \<topic/16501/27@meta.discourse.org\>  
> In-Reply-To: \<topic/16501/26@meta.discourse.org\>  
> References: \<topic/16501/25@meta.discourse.org\> \<topic/16501/26@meta.discourse.org\>

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

```plaintext
Message-ID: <topic/16501/27@meta.discourse.org>
In-Reply-To: <topic/16501/1@meta.discourse.org>
References: <topic/16501/25@meta.discourse.org> <topic/16501/26@meta.discourse.org>

```

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2014年十一月27日 00:25 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/31 "2014-11-27T00:25:11Z")

</div>

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/28@meta.discourse.org>
In-Reply-To: <topic/16501@meta.discourse.org>
References: <topic/16501@meta.discourse.org> 

```

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/91@talk.thumbtack.io>
References: <topic/91@talk.thumbtack.io>

```

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

```plaintext
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..

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2014年十一月27日 00:39 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/32 "2014-11-27T00:39:33Z")

</div>

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

```
Message-ID: <discourse/discourse/pull/3006/c64666078@github.com>
In-Reply-To: <discourse/discourse/pull/3006@github.com>
References: <discourse/discourse/pull/3006@github.com>

```

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

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2014年十一月27日 02:31 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/33 "2014-11-27T02:31:49Z")

</div>

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

```
Message-ID: <topic/22572/86235@meta.discourse.org>
In-Reply-To: <topic/22572@meta.discourse.org>
References: <topic/22572@meta.discourse.org>

```

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

---

<div class="post-metadata">

**Author:** ![rumpelsepp](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rumpelsepp](https://meta.discourse.org/u/rumpelsepp)\
**Post date:** [2014年十一月27日 07:02 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/34 "2014-11-27T07:02:11Z")

</div>

> [@codinghorror](#):
>
> Thanks for the nudge @rumpelsepp hopefully this helps.

You’re welcome. 😊  
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!

---

<div class="post-metadata">

**Author:** ![rumpelsepp](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rumpelsepp](https://meta.discourse.org/u/rumpelsepp)\
**Post date:** [2014年十二月11日 00:34 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/35 "2014-12-11T00:34:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2015年一月9日 06:30 UTC](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501/36 "2015-01-09T06:30:57Z")

</div>



[上一頁](https://meta.discourse.org/t/emails-are-not-threaded-in-outlook-2013/16501.md?page=1)
