[dev] Questions about using Horde_Imap_Client

Michael J Rubinsky mrubinsk at horde.org
Thu Dec 29 18:14:11 UTC 2011


Sending to the list, but this question is mostly directed towards Michael:

I'm in the process of adding email support to our ActiveSync library.  
The EAS 2.5 protocol does not provide support for HTML email, only  
plaintext. You MUST only send plaintext message body to the client, it  
will always just display the text as received.

Anyway, I have tried to get only the plaintext body from the email  
message like so (simplified from my code):

<code>
$q = new Horde_Imap_Fetch_Query();
$q->envelope();
$q->structure();
$q->fullText(array('peek' => true));

// Obviously $mbox is a Horde_Imap_Client_Mailbox object
// and $ids is a Horde_Imap_Client_Ids object.
$list = $client->fetch($mbox, $q, array('ids' => $ids));

$email = array_pop($list);
$part = $email->getStructure();
$id = $part->findBody();
$body = $part->getPart($id);
echo $body->getContents(); // <--- Always returns an empty string.
</code>

The only way I've been able to do what I want is to parse the entire  
message text with Horde_Mime_Part::parseMessage();

<code>
  $msg = Horde_Mime_Part::parseMessage($data->getFullMsg());
  $id = $msg->findBody();
  $body = $msg->getPart($id);
  echo $body->getContents(); // <--- Shows plaintext message body.
</code>

..am I missing something, or do I completely misunderstand what I'm doing?


Also, a sort-of related question:

The EAS client may request to truncate the email body. Is it possible  
to use the imap library's ability to only return the truncated body  
data while still being able to parse out only the plaintext portion of  
the body? i.e., If the IMAP client only returns a portion of the body,  
I am assuming that it would be impossible to properly parse the body  
for the different parts, right?  Currently, since I'm parsing the  
fullMsg anyway, I truncate in the ActiveSync code if needed.

Thanks for any input you can provide.
-- 
mike

The Horde Project (www.horde.org)
mrubinsk at horde.org



More information about the dev mailing list