Multipart mail's MIME headers changed/discarded

ISPTraderChris - October 22, 2009 - 00:33
Project:SMTP Authentication Support
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:franz
Status:postponed (maintainer needs more info)
Description

I'm currently using a small bit of code that leverages the PEAR Mail_Mime library to assemble Multipart MIME messages. The problem seems to be that this module is re-writing key MIME headers before sending it on its way. Is there any simple way to avoid this?

My message body looks like this before hitting drupal_mail_send:

--=_b18fcc6c17d665be4fa89cffe58ec6ac
Content-Type: multipart/alternative;
boundary="=_7153493ae5c61f2ac61194b4f7f2f8ad"

--=_7153493ae5c61f2ac61194b4f7f2f8ad
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="ISO-8859-1"

...

--=_7153493ae5c61f2ac61194b4f7f2f8ad
Content-Transfer-Encoding: 7bit
Content-Type: text/html; charset="ISO-8859-1"

...

--=_7153493ae5c61f2ac61194b4f7f2f8ad--

--=_b18fcc6c17d665be4fa89cffe58ec6ac
Content-Transfer-Encoding: base64
Content-Type: text/html;
name="test-file.html";
Content-Disposition: attachment;
filename="test-file.html";

...

--=_b18fcc6c17d665be4fa89cffe58ec6ac--

This is how it is supposed to look. However, after passing through drupal_mail_send, this is what I get on the other end:

--b1_9f19e17f9b44cab31b39ac27f0925ad1
Content-Type: text/plain; charset = "iso-8859-1"
Content-Transfer-Encoding: 8Bit

...

--b1_9f19e17f9b44cab31b39ac27f0925ad1
Content-Type: text/html; charset = "iso-8859-1"
Content-Transfer-Encoding: 8Bit

name="test-file.html";
Content-Disposition: attachment;
filename="test-file.html";

...

--b1_9f19e17f9b44cab31b39ac27f0925ad1--

Note that some headers have been disregarded completely, while others have been modified with different encodings, and/or modified in ways such that the e-mail client is not able to properly recognize and process them. I would like to still be able to take advantage of this module's SMTP authentication and sending capabilities without allowing it to try and reformat my message -- is this possible?

#1

franz - November 5, 2009 - 17:04

#2

franz - November 6, 2009 - 10:33
Assigned to:Anonymous» franz
Status:active» needs work

#3

franz - November 6, 2009 - 10:34
Title:Module Re-Writes my MIME-formatted E-mails» Multipart mail's MIME headers changed/discarded

Are you using any other module (like Mimemail) to create those headers?

#4

franz - November 6, 2009 - 11:54
Status:needs work» postponed (maintainer needs more info)

I'm not very good with MIME headers, but shouldn't there be a multipart/mixed header encapsulating the multipart/alternative and the attachment?

Anyways, SMTP module is limited to 1 text part and 1 html part when it comes to multipart/alternative.

Can you test with multipart/mixed ?

#5

ISPTraderChris - November 6, 2009 - 13:16

I'm not sure at what point in the process I posted this, but now that I have my MIME messages working without SMTP Auth, let me repost the proper headers. These headers represent a message sent only in Plain Text and include a File Attachment. I also have the options to send message with Plain Text with Alternative HTML also with File Attachments. If it would be helpful, I can post these headers as well (which would involve Multipart/Alternative).

Here is the primary (MIME portion) message header:

MIME-Version: 1.0
Content-Type: multipart/mixed;boundary="=_e3f9c985e6b51624e6cfad1c9bc375b3"
Content-Transfer-Encoding: 8Bit

Then, within the message body, there are the following MIME message headers:

--=_e3f9c985e6b51624e6cfad1c9bc375b3
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="ISO-8859-1"
...
--=_e3f9c985e6b51624e6cfad1c9bc375b3
Content-Transfer-Encoding: base64
Content-Type: text/html;
  name="Attachment.html";
Content-Disposition: attachment;
  filename="Attachment.html";
...
--=_e3f9c985e6b51624e6cfad1c9bc375b3--

I've briefly looked through the code for this module, and I can see very clearly that it is attempting to locate and modify MIME headers, thought I'm not sure why these simply can't be passed through "as-is". See below for the code that is generating and sending my MIME formatted messages just so you have an idea of how this is being accomplished.

This is executed via the hook_mail() API

<?php
     
// Include MIME library
     
include_once('Mail/mime.php');
   
     
// Configure new MIME object
     
$mime = new Mail_mime("\n");
     
$mime_params['html_encoding'] = '7bit';

     
// Pass message contents into MIME object
     
switch ($params['send_option']) {
        case
'sendlink':
         
$mime->setTXTBody($sendlink_plain);
         
$mime->setHTMLBody($sendlink_html);
        break;
        case
'inline-attachment':
         
$mime->setHTMLBody($params['body']);
        case
'plain-attachment':
         
$mime->setTXTBody($params['message']);
         
$mime->addAttachment($params['body'],'text/html','Attachment.html',false);
        break;
      }

     
// Store MIME message output in message array
     
$message['body'] = $mime->get($mime_params);
     
$message['headers'] = $mime->headers($message['headers']);

     
// Strip special characters from Content-Type header
      // Required to prevent mime_header_encode() from disrupting Content-Type header
     
$message['headers']['Content-Type'] = preg_replace('/[^\x20-\x7E]/','', $message['headers']['Content-Type']);
?>

I took a look at the issue you posted above, and do not believe it is related to this issue.

 
 

Drupal is a registered trademark of Dries Buytaert.