-
Notifications
You must be signed in to change notification settings - Fork 233
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
🐛 N°7916 SF#2274 EmailLaminas.php: Keep charset with part header in multipart email #672
Conversation
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.
What do you think of these suggestions? I think they will be clearer for the future..
} | ||
|
||
public function AddAttachment($data, $sFileName, $sMimeType) | ||
{ | ||
$oBody = $this->m_oMessage->getBody(); |
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.
I would leave this line together with my following suggestion..
// setBody called only to refresh Content-Type to multipart/mixed | ||
$this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewAttachment)); |
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.
// setBody called only to refresh Content-Type to multipart/mixed | |
$this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewAttachment)); | |
$oBody->addPart($oNewAttachment); | |
$this->m_oMessage->setBody($oBody); |
// setBody called only to refresh Content-Type to multipart/mixed | ||
$this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewPart)); |
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.
Similar as previous suggestion:
// setBody called only to refresh Content-Type to multipart/mixed | |
$this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewPart)); | |
$oBody->$this->m_oMessage->getBody() | |
$oBody->addPart($oNewPart) | |
$this->m_oMessage->setBody($oBody); |
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.
- First added line should be
$oBody = $this->m_oMessage->getBody();
. - Second added line is missing a
;
. - First two lines can be combined to
$oBody = $this->m_oMessage->getBody()->addPart($oNewPart);
. The method returns the object. They call it "fluent interface". It is up to you, if you want 1, 2, or 3 lines. I am fine with either. - I would keep the comment about why
setBody
is called at all. It is not obvious, because the previousaddPart
already modifies the messages body. What is being done is essentially$this->m_oMessage->setBody($this->m_oMessage->getBody());
. The call is only necessary if the body was single-part previously. This ensures that the mainContent-Type
header gets updated accordingly (here). IMHO, this is a workaround in the library's deficiency.
Everything said applies to the first suggestion as well.
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.
I would keep the comment about why
setBody
is called at all. It is not obvious, because the previousaddPart
already modifies the messages body.
That's exactly why I suggested to break that apart to make it more clear 😉
I was indeed a bit too quick, here's a better suggestion:
// setBody called only to refresh Content-Type to multipart/mixed | |
$this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewPart)); | |
$oBody = $this->m_oMessage->getBody(); | |
$oBody->addPart($oNewPart); | |
$this->m_oMessage->setBody($oBody); |
Could also be
// setBody called only to refresh Content-Type to multipart/mixed | |
$this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewPart)); | |
$oBody = $this->m_oMessage->getBody()->addPart($oNewPart); | |
$this->m_oMessage->setBody($oBody); |
I thought the idea was clear enough without being lexically/syntaxically correct.
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.
Which one do you prefer?
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.
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.
I have no preferences on this matter, I'll let others answer 😅
PR looks great, but it would be nice to have a test case for that in the existing unit tests, or to give 2 eml files (actual / expected) so Combodo can help / make the test. |
Thanks for your contribution! I've logged your bug in our internal bug tracker under ref N°7916 |
Not sure where to start with the unit tests but I think I can at least provide the before/after |
bugSF2274-singlepart-3.1.1-1.txt The files have been anonymized a little. The relevant (without changes in timestamps and random strings) output from 16,17c16
< Content-Type: text/plain;
< boundary="=_ad74c45415ef3ef6f6975298450e56ec"
---
> Content-Type: text/plain; charset=UTF-8 |
Hey, I added a unit test, I will bring these bugs to the QA team when I have some time. |
@steffunky If everyone is OK with it, can you please merge the request as it is? Personally I slightly prefer it over the suggestions. |
Base information
Symptom
Since upgrading to iTop 3.1 (after switching to Laminas-mail, N°4307), we have been experiencing issues with character encoding with emails that contain attachments. More information is in the above-linked SourceForge issue.
Reproduction procedure
emailtest.php
in your iTop root directory:AddAttachment
.Cause
Multipart content type is necessary to include attachments. The iTop code interacting with the Laminas-mail library does some unnecessary and counterproductive steps when trying to convert an email to a multipart one.
Proposed solution
Let the library handle conversion to multipart content type by removing blocks that test for
$oBody->isMultiPart()
.Checklist before requesting a review
Checklist of things to do before PR is ready to merge