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

Implement automatic conversion of embed image as base64 #1512

Merged
merged 7 commits into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/bundles/EmailBundle/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
'mailer_from_email' => 'email@yoursite.com',
'mailer_return_path' => null,
'mailer_transport' => 'mail',
'mailer_convert_embed_images' => false,
'mailer_host' => '',
'mailer_port' => null,
'mailer_user' => null,
Expand Down
2 changes: 1 addition & 1 deletion app/bundles/EmailBundle/Event/EmailSendEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function getContent($replaceTokens = false)
public function setContent($content)
{
if ($this->helper !== null) {
$this->helper->setBody($content, 'text/html', null, true);
$this->helper->setBody($content, 'text/html', null, true, true);
} else {
$this->content = $content;
}
Expand Down
16 changes: 16 additions & 0 deletions app/bundles/EmailBundle/Form/Type/ConfigType.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ public function buildForm(FormBuilderInterface $builder, array $options)
)
);

$builder->add(
'mailer_convert_embed_images',
'yesno_button_group',
array(
'label' => 'mautic.email.config.mailer.convert.embed.images',
'label_attr' => array('class' => 'control-label'),
'attr' => array(
'class' => 'form-control',
'tooltip' => 'mautic.email.config.mailer.convert.embed.images.tooltip',

),
'data' => empty($options['data']['mailer_convert_embed_images']) ? false : true,
'required' => false
)
);

$smtpServiceShowConditions = '{"config_emailconfig_mailer_transport":["smtp"]}';
$amazonRegionShowConditions = '{"config_emailconfig_mailer_transport":["mautic.transport.amazon"]}';

Expand Down
16 changes: 15 additions & 1 deletion app/bundles/EmailBundle/Helper/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,23 @@ protected function setMessagePlainText()
* @param string $contentType
* @param null $charset
* @param bool $ignoreTrackingPixel
* @param bool $ignoreEmbedImageConversion
*/
public function setBody($content, $contentType = 'text/html', $charset = null, $ignoreTrackingPixel = false)
public function setBody($content, $contentType = 'text/html', $charset = null, $ignoreTrackingPixel = false, $ignoreEmbedImageConversion = false)
{
if (!$ignoreEmbedImageConversion && $this->factory->getParameter('mailer_convert_embed_images')) {
$matches = array();
if (preg_match_all('/<img.+?src=[\"\'](.+?)[\"\'].*?>/i', $content, $matches)) {
$replaces = array();
foreach($matches[1] AS $match) {
if (strpos($match, 'cid:') === false) {
$replaces[$match] = $this->message->embed(\Swift_Image::fromPath($match));
}
}
$content = strtr($content, $replaces);
}
}

if (!$ignoreTrackingPixel) {
// Append tracking pixel
$trackingImg = '<img style="display: none;" height="1" width="1" src="{tracking_pixel}" alt="Mautic is open source marketing automation" />';
Expand Down
2 changes: 2 additions & 0 deletions app/bundles/EmailBundle/Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ mautic.email.variant.graph.all="All"
mautic.email.variant.graph.variant="Variant"
mautic.email.webhook.event.open="Email Open Event"
mautic.email.webview.text="<a href='%link%'>Having trouble reading this email? Click here.</a>"
mautic.email.config.mailer.convert.embed.images="Convert embed images to Base64"
mautic.email.config.mailer.convert.embed.images.tooltip="Enable automatic conversion of embed images to Base64"
mautic.email.dashboard.widgets="Email Widgets"
mautic.widget.emails.in.time="Emails in time"
mautic.widget.ignored.vs.read.emails="Ignored vs read"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,8 @@
<div class="row">
<?php echo $view['form']->rowIfExists($fields, 'default_signature_text', $template); ?>
</div>
<div class="row">
<?php echo $view['form']->rowIfExists($fields, 'mailer_convert_embed_images', $template); ?>
</div>
</div>
</div>