[commits] [Wiki] created: Doc/Dev/Imap_Client

Wiki Guest wikiguest at horde.org
Tue Jan 3 15:11:55 UTC 2012


guest [75.147.94.99]  Tue, 03 Jan 2012 15:11:55 +0000

Created page: http://wiki.horde.org/Doc/Dev/Imap_Client

++Using the Horde/Imap_Client Library

These are some basic examples. All examples assume you have a fully  
configured IMP, and can get the client object from the IMP API:
<code type="php">
$imap = $registry->mail->imapOb();
</code>

+++Basics

++++Get a list of all messages in the INBOX:
<code type="php">
$query = new Horde_Imap_Client_Fetch_Query();
$mbox = new Horde_Imap_Client_Mailbox('INBOX');

// $list is a Horde_Imap_Client_Data_Fetch object.
$list = $imap->fetch($mbox, $query);
</code>


++++Get a list of messages in INBOX, since a certain date:
<code type="php">
$query = new Horde_Imap_Client_Search_Query();
$query->dateSearch(
     new Horde_Date($date_string),
     Horde_Imap_Client_Search_Query::DATE_SINCE
);
$mbox = new Horde_Imap_Client_Mailbox('INBOX');

// $list is a Horde_Imap_Client_Data_Search object.
$results = $imap->search($mbox, $query);

// The list of message uids.
var_dump($results['match']);
</code>

++++Using the above message ids, fetch the plaintext body of the first email:
<code type="php">
$mbox = new Horde_Imap_Client_Mailbox('INBOX');
$query = new Horde_Imap_Client_Fetch_Query();
$query->structure();

$list = $imap->fetch($mbox, $query, array('ids' => $results['match']));
$message = array_pop($list);
$uid = $message->getUid();
$part = $message->getStructure();
$id = $part->findBody();
$body = $part->getPart($id);

$query2 = new Horde_Imap_Client_Fetch_Query();
$query2->bodyPart($id, array(
     'peek' => true,
     'decode' => true
));
$results = $imap->fetch($mbox, $query2, array('ids' => new  
Horde_Imap_Client_Ids(array($uid))));
$message2 = array_pop($results);
$text = $message2->getBodyPart($id);
if (!$message2->getBodyPartDecode($id)) {
     // Quick way to transfer decode contents
     $body->setContents($message2->getBodyPart($id));
     $text = $body->getContents();
}

echo $text;
</code>





More information about the commits mailing list