Allow to custom content type when setting mailer body#27227
Allow to custom content type when setting mailer body#27227rafaelfranca merged 5 commits intorails:masterfrom
Conversation
|
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
270ecea to
c4639b7
Compare
|
Thank you for the pull request. Can you add documentation and a changelog entry? |
ad3ecfa to
97bd115
Compare
97bd115 to
2263769
Compare
|
@sgrif thank for your feedback, I added changelog and release note. |
| assert_equal("multipart/mixed", email.mime_type) | ||
| end | ||
|
|
||
| test "set mime type to text/html when attachment is inclued and body is set" do |
|
I would document it on the |
0311620 to
40b1f64
Compare
|
@sgrif thank for your feedback, I just add documentation for |
| def collect_responses_from_text(headers) | ||
| [{ | ||
| body: headers.delete(:body), | ||
| content_type: headers[:content_type] || self.class.default[:content_type] || "text/plain" |
There was a problem hiding this comment.
@sgrif should we consider to use different name here like body_type instead of content_type, because there are some cases mailer will have many parts like mailer content_type, body content_type
|
@sgrif i wonder is there anything lefts should i do? |
| def collect_responses_from_text(headers) | ||
| [{ | ||
| body: headers.delete(:body), | ||
| content_type: headers[:content_type] || self.class.default[:content_type] || "text/plain" |
There was a problem hiding this comment.
I think that at this point headers[:content_type] already has the value of self.class.default[:content_type].
There was a problem hiding this comment.
From what I try and debug, they are different value, because they comes from mail method and class default
There was a problem hiding this comment.
This method is only called after the apply_defaults method is called and the headers passed to this method as argument is the result of apply_defaults, so unless apply_defaults is broken. self.class.default[:content_type] should be already applied on headers[:content_type].
There was a problem hiding this comment.
I think apply_defaults only applies key into headers when headers doesn't have that key. In this case, we want to use the value from headers in mail method instead default from self.class.default[:content_type] 🤔
There was a problem hiding this comment.
If :content_type is passed to mail, apply_defaults will not copy the default value to the headers and headers[:content_type] will be the same as the :content_type passed to mail.
If :content_type is not passed to mail, apply_defaults will copy the default value to the headers and headers[:content_type] will be the same as the self.class.default[:content_type.
So at this point headers[:content_type] behaves exactly as we want.
There was a problem hiding this comment.
headers[:content_type]will be the same as the:content_typepassed to
but self.class.default[:content_type] will get value from default method in actionmailer
There was a problem hiding this comment.
Is there another case different of those two?
If :content_type is passed to mail, headers[:content_type] will be the value passed to mail. In this case no matter what self.class.default[:content_type] is.
In the case you show the conditional:
headers[:content_type] || self.class.default[:content_type] || "text/plain"
will return the value of :content_type passed to mail, that is the same as headers[:content_type], unless I'm missing something.
There was a problem hiding this comment.
hum, so in this case the condition is just headers[:content_type] || "text/plain" because headers[:content_type] always contains the value of self.class.default[:content_type], right? 😄
There was a problem hiding this comment.
will refactor it, thank you so much 🙇
|
@rafaelfranca thank for your suggestion 🙇, please let's me know if is there anything else need to be improved :D |
…-body Allow to custom content type when setting mailer body
Summary
Allow to custom
content-typein case of settingheaders[:body]andattachments