# メール内でフォーラムのURLを確実に特定する堅牢な方法は？

**URL:** https://meta.discourse.org/t/robust-way-to-determine-forum-url-in-a-mail/113996
**Category:** Development
**Created:** [2019 年 4 月 10 日午後 3:46 UTC](https://meta.discourse.org/t/robust-way-to-determine-forum-url-in-a-mail/113996 "2019-04-10T15:46:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![distfp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/distfp/32/134853_2.png) [@distfp](https://meta.discourse.org/u/distfp)
#### Post date: [2019 年 4 月 10 日午後 3:46 UTC](https://meta.discourse.org/t/robust-way-to-determine-forum-url-in-a-mail/113996/1 "2019-04-10T15:46:55Z")

</div>

Hello,

(Sorry if this isn’t the right category, as this is about client-side dev rather than Discourse dev proper, but it looked like the closest fitting category.)

I’m writing a Discourse mail “treatment” for Emacs’ Gnus and among other things, this treatment adds links on user names of the form `@<user>` leading to the user’s profile at `https://<forum-url>/u/<user>`.

To construct this user profile URL, I extract `<forum-url>` from the mail header’s `Message-ID:` field which seems of the form `<...@forum-url>` (based on the couple of forums I’ve tested this on).[1]

Can I count on `Message-ID` being of this form for all Discourse forums?

If not, would you consider adding a custom mail header, say `Discourse-Forum: <forum-url>`? It would be useful for the purpose described above and also (and more importantly) to determine in a robust way whether an e-mail comes from a Discourse forum or not (and thus whether to apply the treatment).[2]

[1] I had a previous implementation that extracted the forum URL from the unsubscription link at the end of the e-mail, but I felt it was too brittle.

[2] The current implementation has a user-customizable list of regexps that match against the value of the `From:` field, which is not very user-friendly and not very robust.

---

<div class="post-metadata">

### Author: ![distfp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/distfp/32/134853_2.png) [@distfp](https://meta.discourse.org/u/distfp)
#### Post date: [2019 年 4 月 20 日午後 2:30 UTC](https://meta.discourse.org/t/robust-way-to-determine-forum-url-in-a-mail/113996/2 "2019-04-20T14:30:03Z")

</div>

Hi Discourse devs,

Any thoughts on this? In particular about adding a custom `Discourse-Forum:` mail header? Thanks.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2019 年 4 月 25 日午後 1:37 UTC](https://meta.discourse.org/t/robust-way-to-determine-forum-url-in-a-mail/113996/3 "2019-04-25T13:37:42Z")

</div>

Have you tried looking at the `List-ID:` header?

It should look like this

```
List-ID: Discourse Meta <meta.discourse.org>

```

---

<div class="post-metadata">

### Author: ![distfp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/distfp/32/134853_2.png) [@distfp](https://meta.discourse.org/u/distfp)
#### Post date: [2019 年 4 月 25 日午後 3:11 UTC](https://meta.discourse.org/t/robust-way-to-determine-forum-url-in-a-mail/113996/4 "2019-04-25T15:11:59Z")

</div>

Thanks for your reply.

Unfortunately, the value of the `List-ID` header is not a reliable way  
to determine that an e-mail originates from a Discourse-powered forum:

- The CommonMark forums ([http://talk.commonmark.org](http://talk.commonmark.org)) have List-ID:  
\<[extensions.talk.commonmark.org](http://extensions.talk.commonmark.org)\>

- The Swift forums ([https://forums.swift.org](https://forums.swift.org)) don’t have a List-ID  
header (not in their “activity summary” e-mails, at least)

I can’t even do search for occurrences of the “discourse” string in the  
headers (which wouldn’t be pretty), since it may not appear at all, as  
is the case for the CommonMark forums.
