openaustralia/planningalerts

View on GitHub
app/mailers/reply_to_no_reply_mailer.rb

Summary

Maintainability
A
0 mins
Test Coverage
# typed: strict
# frozen_string_literal: true

class ReplyToNoReplyMailer < ApplicationMailer
  extend T::Sig

  sig { params(mail: Mail::Message).returns(T.any(Mail::Message, ActionMailer::MessageDelivery)) }
  def reply(mail)
    # So we don't have to figure out the intricacies of how to set the in-reply-to and references headers
    reply = mail.reply

    # We're pre-populating the user's email address for the contact form
    @email = T.let(reply.to.first, T.nilable(String))

    headers(
      "In-Reply-To" => reply.in_reply_to,
      "References" => reply.references,
      "Auto-Submitted" => "auto-replied",
      "Precedence" => "auto_reply"
    )
    mail(
      from: "PlanningAlerts <no-reply@planningalerts.org.au>",
      to: reply.to,
      subject: reply.subject
    )
  end
end