[dev] Questions about parsing an email message using Horde_Mime and friends

Michael M Slusarz slusarz at horde.org
Sat Mar 17 02:33:28 UTC 2012


Quoting Michael J Rubinsky <mrubinsk at horde.org>:

> I spent more than the better part of 2 days trying to figure out  
> what I am doing wrong here. ANY help would be greatly appreciated.
>
> When sending a message via ActiveSync, the device sends an RFC 822  
> stream to the server. When the ActiveSync code receives this, it is  
> parsed and sent out using Horde_Mime_Mail.  I have it basically  
> working, but am having trouble when the recipient's address in  
> quoted-printable, AND the message is multipart. In these cases, when  
> Horde_Mime_Mail attempts to send the message, the address parsing  
> fails. Some examples:
>
> A working, simple example:
> <code>
> $text = 'Date: Fri, 16 Mar 2012 17:58:35 +0100
> Subject: Test
> Message-ID: <pb6yut241ybk25xh5ype5fgv.1331917115106 at email.android.com>
> From: mike at theupstairsroom.com
> To: =?ISO-8859-1?Q?Mich=F1el_Rubinsky?= <mrubinsk at horde.org>
> MIME-Version: 1.0
> Content-Type: text/plain; charset=utf-8
> Content-Transfer-Encoding: base64
>
> VGVzdA==';
>
> $headers = Horde_Mime_Headers::parseHeaders($text);
> $message = Horde_Mime_Part::parseMessage($text);
> $mail = new Horde_Mime_Mail();
> if (preg_match('/multipart/i', $headers->getValue('Content-Type'))) {
>    $mail->setBasePart($message);
> } else {
>    $body_id = $message->findBody();
>    if ($body_id) {
>      $part = $message->getPart($body_id);
>      $body = $part->getContents();
>      $mail->setBody($body);
>    } else {
>      $mail->setBody('No body?');
>    }
> }
> $mail->addHeaders($headers->toArray());
> $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
> </code>
>
>
> If I send an image attachment (using the same PHP code above, with  
> the following message data) it fails in  
> Horde_Mime_Rfc822::parseAddressList() after Horde_Mime_Mail::send()  
> is called.
>
> http://pastebin.com/4shm4Nej
>
>
> But, if the To: header is changed to a simple, non quoted-printable  
> address, it works.
>
> Am I doing something obviously wrong? I've tried numerous ways of  
> populating the $mail object's mime parts, tried converting charsets,  
> all to no avail. I'm sure it's something really silly that I am  
> doing or overlooking...
>
> Thanks for any help you can provide.

Are you using develop?  My guess is that Horde_Mime_Mail is not yet  
fully converted to use the new Horde_Mime and Horde_Mail frameworks.

I try my best to keep it updated, and I ensure it passes all unit  
tests, but I don't actively use Horde_Mime_Mail ever so I won't  
personally catch any issues.  My advice would be to try to isolate the  
issue in a unit test and I could more easily debug.

michael

___________________________________
Michael Slusarz [slusarz at horde.org]



More information about the dev mailing list