From 227a7a2d8729153f3303c608302b3ca6bc074b05 Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Sat, 25 Jun 2011 12:51:16 -0400
Subject: [PATCH] Fix parsing of content-type header in SmtpMailSystem::mail() function.

---
 smtp.mail.inc |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/smtp.mail.inc b/smtp.mail.inc
index 4aa423a8e561306a10e43ac179ac538715dd1559..2d397cfadf637b6215671508815029e5c3434c84 100644
--- a/smtp.mail.inc
+++ b/smtp.mail.inc
@@ -152,19 +152,18 @@ class SmtpMailSystem implements MailSystemInterface {
         case 'content-type':
           // Parse several values on the Content-type header, storing them in an array like
           // key=value -> $vars['key']='value'
-          $vars = explode('; ', $value);
+          $vars = explode(';', $value);
           foreach ($vars as $i => $var) {
             if ($cut = strpos($var, '=')) {
-              $new_var = drupal_strtolower(drupal_substr($var, $cut + 1));
-              $new_key = drupal_substr($var, 0, $cut);
+              $new_var = trim(drupal_strtolower(drupal_substr($var, $cut + 1)));
+              $new_key = trim(drupal_substr($var, 0, $cut));
               unset($vars[$i]);
               $vars[$new_key] = $new_var;
             }
           }
           // Set the charset based on the provided value, if there is one.
-          $charset = $vars['charset'];
-          if ($charset) {
-            $mailer->CharSet = $charset;
+          if (!empty($vars['charset'])) {
+            $mailer->CharSet = $vars['charset'];
           }
           switch ($vars[0]) {
             case 'text/plain':
@@ -200,8 +199,8 @@ class SmtpMailSystem implements MailSystemInterface {
             break;
             default:
               // Everything else is unsuppored by PHPMailer.
-              drupal_set_message(t('The Content-Type of your message is not supported by PHPMailer and will be sent as text/plain instead.'), 'error');
-              watchdog('smtp', 'The Content-Type of your message is not supported by PHPMailer and will be sent as text/plain instead.', array(), WATCHDOG_ERROR);
+              drupal_set_message(t('The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: $value")), 'error');
+              watchdog('smtp', 'The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: $value"), WATCHDOG_ERROR);
 
               // Force the Content-Type to be text/plain.
               $mailer->IsHTML(FALSE);
-- 
1.7.4.1

