-
Notifications
You must be signed in to change notification settings - Fork 142
Imap
Mark Sch edited this page Jan 17, 2018
·
6 revisions
3.x: todo (same class name, though)
2.x: A small example script to read mails via IMAP/POP:
App::uses('ImapLib', 'Tools.Lib');
$Imap = new ImapLib();
$Imap->set(ImapLib::S_SERVICE, 'imap'); // For IMAP instead of POP
$Imap->set(ImapLib::S_NORSH, true);
$res = $Imap->connect($account['address'], $account['password'], $account['host']);
if (!$res) {
throw new InternalErrorException('Error connecting: '.$account['address'].' - '.$account['host'].' ('.$account['password'].')');
}
//$count = $Imap->msgCount(); // If you just need to know how many there are
$messages = $Imap->msgList();
if ($delete) {
$messageNumbers = Set::extract('/Msgno', $messages);
$res = $Imap->delete($messageNumbers, true); // Omit true for soft-delete
}
$Imap->close();
// $messages will contain all messages including the attachments