Handle_mail support for Postmark webhook

AI-generated summary

A user, mcaruanagalizia, seeks guidance on integrating Postmark’s webhook with Discourse’s handle_mail feature. Postmark sends a JSON payload with a RawEmail field, but Discourse expects email. The user proposes two solutions: modifying handle_mail to rename the field or creating a new endpoint to process parsed emails. mcaruanagalizia also asks if Discourse plans to adopt Rails 6’s ActionMailbox, which supports Postmark natively. sam responds that there are no current plans, but a proof-of-concept PR would be welcome for review.

First time Discourse user, impressed at how well made but at the same hackable the app is! In order to avoid running a mail server I want to get Postmark working with Discourse. They have a webhook for inbound mail, that sends a JSON payload containing the parsed email. For example, it parses the From field into several attributes, same for the CC field, et c.

Optionally, you can tell Postmark to include the raw email in a RawEmail attribute. Unfortunately the name of the attribute cannot be changed to email, which is what Discourse’s handle_mail endpoint expects.

There are two options I can think of:

  1. add a one line bodge to handle_mail to rename the RawEmail attribute to email if present
  2. create a new endpoint that will add the ready parsed email to the job queue, then add a new method to the receiver to handle ready-parsed email objects

Any preference for a PR/way forward?

@codinghorror are there any plans to replace existing handlers with Rails 6’s ActionMailbox in Discourse? It has ingresses for different services, including Postmark, built in.

No there are no current plans to swap in action mailbox, but I would be open to review a PR that swaps it in if you want to do a proof-of-concept.