Example #1
0
use Humps\MailManager\ImapMailboxService;
require_once '../vendor/autoload.php';
$cacheServer = MemcacheServer::connect('localhost', 11211);
$messageCache = new MemcacheMessageCache($cacheServer);
$folderCache = new MemcacheFolderCache($cacheServer);
$folder = isset($_REQUEST['folder']) ? $_REQUEST['folder'] : 'INBOX';
try {
    $imap = ImapFactory::create($folder);
} catch (Exception $e) {
    die('Unable to connect to mail server');
}
$mailboxService = new ImapMailboxService($imap);
$folders = $folderCache->getAllCached();
Sorter::sort($folders, 'name');
// Uses getMailbox() method from the ImapConnection helper trait, or you can do: $imap->getConnection()->getMailbox()->getFolder();
$currentFolder = $mailboxService->getMailbox()->getFolder();
$aliases = $mailboxService->getAliases();
$isTrash = false;
if (isset($aliases['trash'])) {
    if ($aliases['trash'] == $currentFolder) {
        $isTrash = true;
    }
}
$cacheManager = new ImapMessageCache($messageCache, $imap);
$messages = $cacheManager->getAllCachedMessages();
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
$recordsPerPage = 25;
$messages = $messages->toArray();
if (Sorter::sortMessagesByDate($messages)) {
    $messages = array_slice($messages, $recordsPerPage * ($page - 1), $recordsPerPage);
} else {