-
Notifications
You must be signed in to change notification settings - Fork 238
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
Merged
+44
−43
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,7 +7,6 @@ | |||||||||
*/ | ||||||||||
|
||||||||||
use Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory; | ||||||||||
use Laminas\Mail\Header\ContentType; | ||||||||||
use Laminas\Mail\Message; | ||||||||||
use Laminas\Mail\Protocol\Smtp\Auth\Oauth; | ||||||||||
use Laminas\Mail\Transport\File; | ||||||||||
|
@@ -398,19 +397,6 @@ public function SetBody($sBody, $sMimeType = Mime::TYPE_HTML, $sCustomStyles = n | |||||||||
$oBody->addPart($oAdditionalPart); | ||||||||||
} | ||||||||||
|
||||||||||
if ($oBody->isMultiPart()) { | ||||||||||
$oContentTypeHeader = $this->m_oMessage->getHeaders(); | ||||||||||
foreach ($oContentTypeHeader as $oHeader) { | ||||||||||
if (!$oHeader instanceof ContentType) { | ||||||||||
continue; | ||||||||||
} | ||||||||||
|
||||||||||
$oHeader->setType(Mime::MULTIPART_MIXED); | ||||||||||
$oHeader->addParameter('boundary', $oBody->getMime()->boundary()); | ||||||||||
break; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
$this->m_oMessage->setBody($oBody); | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -431,22 +417,13 @@ public function AddPart($sText, $sMimeType = Mime::TYPE_HTML) | |||||||||
$oNewPart = new Part($sText); | ||||||||||
$oNewPart->encoding = Mime::ENCODING_8BIT; | ||||||||||
$oNewPart->type = $sMimeType; | ||||||||||
$this->m_oMessage->getBody()->addPart($oNewPart); | ||||||||||
|
||||||||||
// setBody called only to refresh Content-Type to multipart/mixed | ||||||||||
$this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewPart)); | ||||||||||
} | ||||||||||
|
||||||||||
public function AddAttachment($data, $sFileName, $sMimeType) | ||||||||||
{ | ||||||||||
$oBody = $this->m_oMessage->getBody(); | ||||||||||
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 would leave this line together with my following suggestion.. |
||||||||||
|
||||||||||
if (!$oBody->isMultiPart()) { | ||||||||||
$multipart_content = new Part($oBody->generateMessage()); | ||||||||||
$multipart_content->setType($oBody->getParts()[0]->getType()); | ||||||||||
$multipart_content->setBoundary($oBody->getMime()->boundary()); | ||||||||||
|
||||||||||
$oBody = new Laminas\Mime\Message(); | ||||||||||
$oBody->addPart($multipart_content); | ||||||||||
} | ||||||||||
|
||||||||||
if (!array_key_exists('attachments', $this->m_aData)) { | ||||||||||
$this->m_aData['attachments'] = array(); | ||||||||||
} | ||||||||||
|
@@ -457,23 +434,8 @@ public function AddAttachment($data, $sFileName, $sMimeType) | |||||||||
$oNewAttachment->disposition = Mime::DISPOSITION_ATTACHMENT; | ||||||||||
$oNewAttachment->encoding = Mime::ENCODING_BASE64; | ||||||||||
|
||||||||||
|
||||||||||
$oBody->addPart($oNewAttachment); | ||||||||||
|
||||||||||
if ($oBody->isMultiPart()) { | ||||||||||
$oContentTypeHeader = $this->m_oMessage->getHeaders(); | ||||||||||
foreach ($oContentTypeHeader as $oHeader) { | ||||||||||
if (!$oHeader instanceof ContentType) { | ||||||||||
continue; | ||||||||||
} | ||||||||||
|
||||||||||
$oHeader->setType(Mime::MULTIPART_MIXED); | ||||||||||
$oHeader->addParameter('boundary', $oBody->getMime()->boundary()); | ||||||||||
break; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
$this->m_oMessage->setBody($oBody); | ||||||||||
// setBody called only to refresh Content-Type to multipart/mixed | ||||||||||
$this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewAttachment)); | ||||||||||
Comment on lines
+443
to
+444
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.
Suggested change
|
||||||||||
} | ||||||||||
|
||||||||||
public function SetSubject($sSubject) | ||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.
$oBody = $this->m_oMessage->getBody();
.;
.$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.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.
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:
Could also be
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.
It's up to @Combodo team to decide, I was just suggesting. I'm a person from the community just like you.
PS: You can join us on Slack if you like.
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 😅