Adam Baranyai
Adam Baranyai

Reputation: 3867

HORDE Imap PHP client - how to fetch messages

Okay, had no luck with the ZETA email client, so now I tried installing the Horde IMAP Client library. I've managed to login to my account, and make a search for e-mails, also got back the results, but I don't know how to fetch the email data, and the documentation is not really helping:|

I presume that I would have to use the Horde_Imap_Client_Base::fetch() method to get some e-mails, which accepts two parameters, a mailbox name, and a Horde_Imap_Client_Fetch_Query object, but I don't know how to get this second object:|

Should this object be returned by one of the Base functions, or should I build this object with the query parameters I want? If the second, how should I rebuild my search query in the fetch query object from the below example?

Here's how I am searching my INBOX, for mails from a specific contact on a specific day:

 $client = new Horde_Imap_Client_Socket(array(
    'username' => '[email protected]',
    'password' => 'xxxxxxxxxx',
    'hostspec' => 'my.mail.server',
    'port' => '143',
    'debug' => '/tmp/foo',
));
$query = new Horde_Imap_Client_Fetch_Query();
$query->dateSearch(new Date(), Horde_Imap_Client_Search_Query::DATE_ON);
$query->headerText("from","[email protected]");
$results = $client->search('INBOX', $query);

The Horde_Imap_Client_Base::search() returns an array, which contains the search results(the message id's of the searched emails), and some additional data.

Upvotes: 2

Views: 1853

Answers (2)

William Entriken
William Entriken

Reputation: 39263

Not completely answering your questions. This is how I search for messages which are not deleted.

  $client = new Horde_Imap_Client_Socket(array(
      'username' => $user,
      'password' => $pass,
      'hostspec' => $server,
      'secure' => 'ssl'
  ));

  $query = new Horde_Imap_Client_Search_Query();
  $query->flag(Horde_Imap_Client::FLAG_DELETED, false);
  $results = $client->search('INBOX', $query);

  foreach($results['match'] as $match) {
    $muid = new Horde_Imap_Client_Ids($match);
    $fetchQuery = new Horde_Imap_Client_Fetch_Query();
    $fetchQuery->imapDate();
    $list = $client->fetch('INBOX', $fetchQuery, array(
        'ids' => $muid
    ));
    var_dump($list);
  }

Upvotes: 2

Alexander Scherer
Alexander Scherer

Reputation: 39

$results = $client->search($mailbox, $searchquery, array('sort' => array($sSortDir, $sSort)));
$uids = $results['match'];
for ($i = $i_start; $i < $i_to; $i++) 
{
    $muid = new Horde_Imap_Client_Ids($uids->ids[$i]);

    $list = $client->fetch($mailbox, $query, array(
        'ids' => $muid
    ));
    $flags = $list->first()->getFlags();
    $part = $list->first()->getStructure();
    $map = $part->ContentTypeMap();
    $envelope = $list->first()->getEnvelope();
}

Upvotes: 1

Related Questions