# 如何在邮件中稳健地确定论坛 URL？

**URL:** <https://meta.discourse.org/t/robust-way-to-determine-forum-url-in-a-mail/113996>\
**Category:** Development\
**Created:** [2019 年4 月 10 日 15: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:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![distfp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/distfp/32/134853_2.png) [@distfp](https://meta.discourse.org/u/distfp)\
发布日期： [2019 年4 月 10 日 15: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.

---

_[View the full topic](https://meta.discourse.org/t/robust-way-to-determine-forum-url-in-a-mail/113996)._
