Skip to content
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

Fix: Header handling #165

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Fix: Header handling #165

wants to merge 3 commits into from

Conversation

mec
Copy link
Member

@mec mec commented Oct 18, 2024

This work sets out to resolve the two issues reported in #162 by @inulty-dfe.

We fix the first issue on the call to Hash.except.

We then stop the potential for duplicate headers ending up in the Mail::Message, by only sending the headers once to mail in view_mail.

After some thought, I wondered why we support headers other than to and subject as they will never get used as we cannot pass them on to Notify to be actually sent - dfb2447 is a refactor that sidesteps both issues by only setting a to and subject header, which do not appear to be duplicated no matter how many times mail is called.

This work will form the basis of v2.0.1

@coveralls
Copy link

coveralls commented Oct 18, 2024

Pull Request Test Coverage Report for Build 11403145272

Details

  • 25 of 25 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 11402636625: 0.0%
Covered Lines: 415
Relevant Lines: 415

💛 - Coveralls

@coveralls
Copy link

coveralls commented Oct 18, 2024

Pull Request Test Coverage Report for Build 11405877090

Details

  • 30 of 30 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 11402636625: 0.0%
Covered Lines: 419
Relevant Lines: 419

💛 - Coveralls

The call to `except` here should not be an array as there is no array of
these symbol to exclude from the hash.

This issue was kindly identified by @inulty-dfe in #162.
With a view mail we have to call `mail` twice, once to get the body of
the email from the view and once again to override the format contents.

We were passing in any custom headers for both calls which was resulting
in duplicate headers in the message.

By calling `mail` without the headers, we can get the body and not
modify the headers, leaving that for the second call.

Interestingly adding custom headers is pointless, as they will never end
up in the email from Notify - we may want to stop messing with the
headers at all - I think it is a hangover from the v1 implementation.

This was kindly identified by @inulty-dfe in #162 who are testing the
header Mail::Fields that are potentially duplicated.
We only keep a Mail::Message for use in previews, it is never actually
sent, email sending is handled by Notify, not the host application.

The Notify API does not accept additional custom headers, so passing
custom headers to the message via the call to `mail` serves no purpose
as those headers will never be used (other than in the previews, where
they get shown).

This work refactors the two mailer methods so that only the `to` and
`subject` headers are set on the Mail::Message returned.
@mec mec marked this pull request as ready for review October 18, 2024 14:51
@mec mec marked this pull request as draft October 19, 2024 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants