[dev] Questions about parsing an email message using Horde_Mime and friends
Michael J Rubinsky
mrubinsk at horde.org
Sat Mar 17 01:56:08 UTC 2012
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.
--
mike
The Horde Project (www.horde.org)
mrubinsk at horde.org
More information about the dev
mailing list