Hi,
I am using Mime Mail + Rules and SMTP to send out mail notifications with node body in HTML format. For some nodes received mail has corrupted HTML version (bellow), while for others it's fine. Plain text format always looks fine. So far I haven't been able to isolate this issue or find put steps to reproduce it.
Any ideas where the root cause might be?

Corrupted mail source sample (HTML section):

--b1_5e44b6dfb1e4e8fa8a38df3a6ebbf82b
Content-Type: text/html; charset = "UTF-8"
Content-Transfer-Encoding: 8Bit

PGh0bWw+CiAgPGhlYWQ+CiAgICA8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5cGUiIGNvbnRl
bnQ9InRleHQvaHRtbDsgY2hhcnNldD11dGYtOCIgLz4KICAgICAgPC9oZWFkPgogIDxib2R5IGlk
PSJtaW1lbWFpbC1ib2R5IiBjbGFzcz0icnVsZXMtYWN0aW9uLW1pbWVtYWlsLXJ1bGVzLWJsb2ct
cG9zdC1ub3RpZmljYXRpb24tZm9yLWdyb3VwLWVkaXRlZC0tMTIiPgogICAgPGRpdiBpZD0iY2Vu
dGVyIj4KICAgICAgPGRpdiBpZD0ibWFpbiI+CiAgICAgICAgRGVhciBKb2huIER1a2UsClRoZSBm
b2xsb3dpbmcgYmxvZyBwb3N0IGhhcyBiZWVuIGp1c3QgcHVibGlzaGVkIGludG8geW91ciBncm91

[cut]

--b1_5e44b6dfb1e4e8fa8a38df3a6ebbf82b--

Comments

sgabe’s picture

I think this will be a duplicate of #1044534: Improve support for multipart/mixed messages.

michlis’s picture

I am not sure if this is a duplicate of #1044534. After more debugging I have found out that my problem was caused by

function mimemail_extract_files($html) {
  $pattern = '/(<link[^>]+href=[\'"]?|<object[^>]+codebase=[\'"]?|@import |[\s]src=[\'"]?)([^\'>"]+)([\'"]?)/mis';
  $content = preg_replace_callback($pattern, '_mimemail_replace_files', $html);
  $encoding = '8Bit';
  /* Quick fix
  $body = explode("\n", $content);
  foreach ($body as $line) {
    if (drupal_strlen($line) > 998) {
      $encoding = 'base64';
      break;
    }
  }
  if ($encoding == 'base64') {
    $content = rtrim(chunk_split(base64_encode($content)));
  }
  */
  $document = array(array(
    'Content-Type' => "text/html; charset=utf-8",
    'Content-Transfer-Encoding' => $encoding,
    'content' => $content,
  ));
  $files = _mimemail_file();
  return array_merge($document, $files);
}

located in mimemail.inc.
My test mail indeed had one very long line, but I don't get a point why to convert all content to base64 encoding? With the commented part as above it works fine, but that's just a quick fix. I hope someone can explain it and fix properly.

sgabe’s picture

sgabe’s picture

Project: Mime Mail » SMTP Authentication Support
Version: 7.x-1.0-alpha2 » 7.x-1.x-dev
Component: Miscellaneous » Code
Category: support » bug
Priority: Normal » Major
Status: Active » Closed (duplicate)

Marking as a duplicate. See my previous comment.