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

[Documents] Newsletter: add option to maintain a manual edited plain-text version #4794

Merged
merged 11 commits into from Aug 2, 2019
Expand Up @@ -192,6 +192,12 @@ protected function setValuesToDocument(Request $request, Document $page)
$this->addSettingsToDocument($request, $page);
$this->addDataToDocument($request, $page);
$this->addPropertiesToDocument($request, $page);

// plaintext
if ($request->get('plaintext')) {
$plaintext = $this->decodeJson($request->get('plaintext'));
$page->setValues($plaintext);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions bundles/AdminBundle/Resources/public/css/icons.css
Expand Up @@ -1821,6 +1821,10 @@
background: url(/bundles/pimcoreadmin/img/material-icons/outline-settings-24px.svg) center center no-repeat;
}

.pimcore_material_icon_text {
background: url(/bundles/pimcoreadmin/img/flat-white-icons/text.svg) center center no-repeat;
}

.pimcore_material_icon_workflow {
background: url(/bundles/pimcoreadmin/img/material-icons/outline-directions-24px.svg) center center no-repeat;
}
Expand Down
Expand Up @@ -56,6 +56,7 @@ pimcore.document.newsletter = Class.create(pimcore.document.page_snippet, {

this.sendingPanel = new pimcore.document.newsletters.sendingPanel(this);
// this.reports = new pimcore.report.panel("document_snippet", this);
this.plaintextPanel = new pimcore.document.newsletters.plaintextPanel(this);

this.tagAssignment = new pimcore.element.tag.assignment(this, "document");
this.workflows = new pimcore.element.workflows(this, "document");
Expand All @@ -67,6 +68,7 @@ pimcore.document.newsletter = Class.create(pimcore.document.page_snippet, {
var items = [];

items.push(this.edit.getLayout());
items.push(this.plaintextPanel.getLayout());
items.push(this.preview.getLayout());
if (this.isAllowed("settings")) {
items.push(this.settings.getLayout());
Expand Down Expand Up @@ -162,6 +164,14 @@ pimcore.document.newsletter = Class.create(pimcore.document.page_snippet, {
}

}

// plaintext
try {
parameters.plaintext = Ext.encode(this.plaintextPanel.getValues());
}
catch (e4) {
//console.log(e4);
}

// data
try {
Expand Down
@@ -0,0 +1,78 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/

pimcore.registerNS("pimcore.document.newsletters.plaintextPanel");
pimcore.document.newsletters.plaintextPanel = Class.create({

initialize: function(document) {
this.document = document;
},

getLayout: function () {

if (this.layout == null) {

this.layout = new Ext.FormPanel({
title: t('plain_text'),
border: false,
autoScroll: true,
bodyStyle:'padding:0 10px 0 10px;',
iconCls: "pimcore_material_icon_text pimcore_material_icon",
items: [
{
xtype:'fieldset',
title: t('plain_text_email_part'),
itemId: "plaintextPanel",
collapsible: true,
autoHeight:true,
defaults: {
labelWidth: 200
},
defaultType: 'textarea',
items :[
{
fieldLabel: t('plain_text') + " (" + this.document.data.plaintext.length + ")",
maxLength: 4000,
height: 700,
width: 1400,
name: 'plaintext',
itemId: 'plaintext',
value: this.document.data.plaintext,
enableKeyEvents: true,
listeners: {
"keyup": function (el) {
el.labelEl.update(t("plain_text") + " (" + el.getValue().length + "):");
}
}
}
]
}
]
});
}

return this.layout;
},

getValues: function () {

if (!this.layout.rendered) {
throw "plaintext not available";
}

// get values
var plaintext = this.getLayout().getForm().getFieldValues();
return plaintext;
}

});
Expand Up @@ -379,6 +379,7 @@
"pimcore/document/emails/settings.js",
"pimcore/document/newsletters/settings.js",
"pimcore/document/newsletters/sendingPanel.js",
"pimcore/document/newsletters/plaintextPanel.js",
"pimcore/document/newsletters/addressSourceAdapters/default.js",
"pimcore/document/newsletters/addressSourceAdapters/csvList.js",
"pimcore/document/newsletters/addressSourceAdapters/report.js",
Expand Down
2 changes: 1 addition & 1 deletion bundles/CoreBundle/Resources/translations/de.json
Expand Up @@ -899,4 +899,4 @@
"metainfo_copy_id": "Copy ID to clipboard",
"metainfo_copy_fullpath": "Copy full path to clipboard",
"metainfo_copy_deeplink": "Copy deeplink to clipboard"
}
}
2 changes: 2 additions & 0 deletions bundles/CoreBundle/Resources/translations/en.json
Expand Up @@ -74,6 +74,8 @@
"send_newsletter": "Send Newsletter Now",
"object_filter": "Object Filter",
"add_newsletter": "Add Newsletter",
"plain_text": "Plain Text",
"plain_text_email_part": "Email Plain Text Part",
"newsletter": "Newsletter",
"crm": "CRM",
"notes_events": "Notes & Events",
Expand Down
8 changes: 6 additions & 2 deletions lib/Tool/Newsletter.php
Expand Up @@ -69,6 +69,10 @@ public static function prepareMail(
if ($sendingContainer && $sendingContainer->getParams()) {
$mail->setParams($sendingContainer->getParams());
}

if(strlen(trim($newsletterDocument->getPlaintext())) > 0) {
$mail->setBodyText(trim($newsletterDocument->getPlaintext()));
}

$contentHTML = $mail->getBodyHtmlRendered();
$contentText = $mail->getBodyTextRendered();
Expand Down Expand Up @@ -115,6 +119,8 @@ public static function prepareMail(

$mail->setBodyHtml($contentHTML);
$mail->setBodyText($contentText);
// Adds the plain text part to the message, that it becomes a multipart email
$mail->addPart($contentText, 'text/plain');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? See:

$this->addPart($bodyTextRendered, 'text/plain');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 567 is part of the send function, the newsletter is send via sendWithoutRendering function:

Pimcore::getEventDispatcher()->dispatch(DocumentEvents::NEWSLETTER_PRE_SEND, $event);
$mail->sendWithoutRendering($mailer);
Pimcore::getEventDispatcher()->dispatch(DocumentEvents::NEWSLETTER_POST_SEND, $event);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 👍😊

$mail->setSubject($mail->getSubjectRendered());

return $mail;
Expand All @@ -137,8 +143,6 @@ public static function sendNewsletterDocumentBasedMail(Mail $mail, SendingParamC

if (!empty($mailAddress)) {
$mail->setTo($mailAddress);
// Getting bounces
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary, as the SMTP Server will set it automatically set the return path when finally sending the email.

https://www.postmastery.com/about-the-return-path-header/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added this in #4349 ... can't hurt to leave it as it is, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it was me. :-)
But on what I read in the meantime, I would recommend to leave it out, because some mailserver seems to reject or identify the email as spam, when return path is wrongly set. At the end if we leave it in, it won't hurt the sending process, !maybe! some emails won't receive the customer.

$mail->setReturnPath(key($mail->getFrom()));

$mailer = null;
// check if newsletter specific mailer is needed
Expand Down
33 changes: 32 additions & 1 deletion models/Document/Newsletter.php
Expand Up @@ -37,7 +37,14 @@ class Newsletter extends Model\Document\PageSnippet
* @var string
*/
protected $subject = '';


/**
* Contains the plain text part of the email
*
* @var string
*/
protected $plaintext = '';

/**
* Contains the from email address
*
Expand Down Expand Up @@ -109,6 +116,30 @@ public function setFrom($from)

return $this;
}

/**
* Contains the email plain text part
*
* @param string $plaintext
*
* @return $this
*/
public function setPlaintext($plaintext)
{
$this->plaintext = $plaintext;

return $this;
}

/**
* Returns the email plain text part
*
* @return string
*/
public function getPlaintext()
{
return $this->plaintext;
}

/**
* Returns the "from" email address
Expand Down