-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple calls to ActionMailer::Base#mail produces multiple Mail::Fields in the headers #162
base: main
Are you sure you want to change the base?
Changes from 1 commit
d1fa5c4
e25d90f
b70f698
4ede654
9f97605
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ def template_mail(template_id, options) | |
|
||
message.personalisation = options[:personalisation] || {} | ||
|
||
headers = options.except([:personalisation, :reply_to_id, :reference]) | ||
headers = options.except(:personalisation, :reply_to_id, :reference) | ||
|
||
headers[:subject] = "Subject managed in Notify" unless options[:subject] | ||
|
||
|
@@ -74,12 +74,19 @@ def view_mail(template_id, options) | |
message.reference = options[:reference] | ||
|
||
subject = options[:subject] | ||
headers = options.except([:personalisation, :reply_to_id, :reference]) | ||
headers = options.except(:personalisation, :reply_to_id, :reference) | ||
|
||
# we have to render the view for the message and grab the raw source, then we set that as the | ||
# body in the personalisation for sending to the Notify API. | ||
# Calling the #mail method is not idempotent. It modifies state by setting instance variables on the message. Specifically it sets @_message. | ||
# mail generates message headers for the options passed in. | ||
# each time it is called with the same headers it adds another header field. | ||
# | ||
# original_message = message.dup | ||
body = mail(headers).body.raw_source | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just not pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Digging into it more, I can't see why we are handling headers other than I would be interested to know what headers are being duplicated for you and are showing up in your tests. I've refactored the two methods to only use to and subject on the end of #165. |
||
|
||
# @_message = original_message | ||
|
||
# The 'view mail' works by sending a subject and body as personalisation options, these are | ||
# then used in the Notify template to provide content. | ||
message.personalisation = {subject: subject, body: body} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is spot on and your tests demonstrate it nicely! 👌