From d431802e7e080347291b6e49b3cc9a5f7de384e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Tue, 18 Dec 2012 15:45:43 +0100 Subject: [PATCH] [-] Core: The emails can now be sent with amazon SES when logo is in png --- classes/ImageManager.php | 29 +++++++++++++++++++++++++++++ classes/Mail.php | 12 +++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/classes/ImageManager.php b/classes/ImageManager.php index 8ddb8e811..428eaf4f0 100644 --- a/classes/ImageManager.php +++ b/classes/ImageManager.php @@ -410,4 +410,33 @@ class ImageManagerCore @chmod($filename, 0664); return $success; } + + /** + * Return the mime type by the file extension + * + * @param string $file_name + * @return string + */ + public static function getMimeTypeByExtension($file_name) + { + $types = array( + 'image/gif' => array('gif'), + 'image/jpeg' => array('jpg', 'jpeg'), + 'image/png' => array('jpg', 'png') + ); + $extension = substr($file_name, strrpos($file_name, '.') + 1); + + $mime_type = null; + foreach ($types as $mime => $exts) + if (in_array($extension, $exts)) + { + $mime_type = $mime; + break; + } + + if ($mime_type === null) + $mime_type = 'image/jpeg'; + + return $mime_type; + } } diff --git a/classes/Mail.php b/classes/Mail.php index 33797ec3e..e6a7dddae 100644 --- a/classes/Mail.php +++ b/classes/Mail.php @@ -233,12 +233,18 @@ class MailCore $message->headers->setEncoding('Q'); if (Configuration::get('PS_LOGO_MAIL') !== false && file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO_MAIL'))) - $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_.Configuration::get('PS_LOGO_MAIL')))); + $logo = _PS_IMG_DIR_.Configuration::get('PS_LOGO_MAIL'); else - if (file_exists(_PS_IMG_DIR_.'logo.jpg')) - $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_.Configuration::get('PS_LOGO')))); + { + if (file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO'))) + $logo = _PS_IMG_DIR_.Configuration::get('PS_LOGO'); else $template_vars['{shop_logo}'] = ''; + } + + /* don't attach the logo as */ + if (isset($logo)) + $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_EmbeddedFile(new Swift_File($logo), null, ImageManager::getMimeTypeByExtension($logo))); $template_vars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME')); $template_vars['{shop_url}'] = Tools::getShopDomain(true, true).__PS_BASE_URI__.'index.php';