Robust way to determine forum URL in a mail?

AI-generated summary

Robust way to determine forum URL in a mail

The discussion revolves around finding a reliable way to determine the forum URL from a Discourse email. distfp is writing an Emacs mail treatment for Discourse and extracts the forum URL from the Message-ID field. However, this method may not be robust for all Discourse forums.

distfp proposes adding a custom Discourse-Forum mail header to provide a reliable way to determine the forum URL and whether an email comes from a Discourse forum.

zogstrip suggests using the List-ID header, but distfp finds that this method is not reliable as the List-ID header may not be present or may not contain the forum URL.

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.

Hi Discourse devs,

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

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

It should look like this

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

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:

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.