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

CakePHP Mailer does not allow multiple headers of the same name #12523

Closed
1 of 3 tasks
burzum opened this issue Aug 31, 2018 · 10 comments
Closed
1 of 3 tasks

CakePHP Mailer does not allow multiple headers of the same name #12523

burzum opened this issue Aug 31, 2018 · 10 comments

Comments

@burzum
Copy link
Contributor

burzum commented Aug 31, 2018

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.6.x

What you did

->addHeaders(['o:tag' => $newsletter->get('id')])
->addHeaders(['o:tag' => 'swissmailer'])

What happened

Ending up with just o:tag: swissmailer

Duplicate headers are allowed for specific types and third party headers. See https://stackoverflow.com/questions/18039142/email-legitimate-duplicate-email-header-keys-with-mutually-exclusive-values

What you expected to happen

Getting all the headers in the email.

@ADmad ADmad added this to the 3.6.11 milestone Aug 31, 2018
@markstory markstory self-assigned this Sep 2, 2018
@markstory markstory modified the milestones: 3.6.11, 3.6.12 Sep 3, 2018
@markstory
Copy link
Member

Changing the existing behavior of addHeaders() could break existing applications that rely on the overwrite as a 'feature'. We would be better off adding a new method. For responses we have withHeader() and withAddedHeader(). Does anyone have a suggestion for a new method name on Email?

@markstory markstory modified the milestones: 3.6.12, 3.7.0 Sep 7, 2018
@ravage84
Copy link
Member

How about withAdditionalHeader() (preferred) or withAnotherHeader()?

@garas
Copy link
Member

garas commented Sep 11, 2018

Email is mutable object, and with*() method would suggest instance is immutable and returns another instance like Response.

I would prefer add parameter $replace = true similarly to PHP header()

@markstory
Copy link
Member

@garas Modal flags on methods are not an API pattern I'm a huge fan of. It requires memorizing the API or looking at the documentation to understand what the flag does.

@josegonzalez
Copy link
Member

Break it for 4.x?

@markstory markstory added mailer and removed defect labels Sep 15, 2018
@markstory markstory removed their assignment Sep 22, 2018
@JoshuaLuckers
Copy link
Contributor

addHeadersAndMergeRecursive()

@dereuromark
Copy link
Member

2nd param as BC flag for 3.x sounds reasonable if we can then fix it for 4.x using merge default true. Separate methods could work for both major versions, though.

@markstory
Copy link
Member

Adding a new method for the append operation is my preference as it requires the least churn overall.

@markstory markstory modified the milestones: 3.7.0, Future Dec 9, 2018
@ADmad
Copy link
Member

ADmad commented Mar 12, 2019

One way to solve this without any API changes would be allow providing the value as array:

->addHeaders(['o:tag' => [$newsletter->get('id')]])

The, subsequent call like

->addHeaders(['o:tag' => ['swissmailer'])

would merge the values for that particular header.

addHeaders() method would be updated to use Hash::merge() instead of array_merge() and AbstractTransport::_headersToString() updated to account for values being an array.

@markstory
Copy link
Member

@ADmad I like that approach over breaking the existing behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants