/** * @test */ public function it_gets_all_messages_after_the_given_date_and_sets_them_as_read() { $imap = $this->getImap(); /** @noinspection PhpUndefinedMethodInspection */ $imap->shouldReceive('sort')->with('SINCE "11-Jan-2016"', SORTDATE, true, 0)->andReturn([1, 2]); $mailboxManager = new ImapMailboxService($imap); $this->assertEquals([1, 2], $mailboxManager->getMessagesAfter('2016-01-11', SORTDATE, true, false)); }
//$messageNumbers = $mailboxService->getMessagesBetween('2016-01-17','2016-01-18'); $folders = ImapFolderCollectionFactory::create($mailboxService->getAllFolders()); // 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; } } // Show all messages for the trash folder, as these are usually auto deleted at specified time periods. So there shouldn't be too many! if ($isTrash) { $messageNumbers = $mailboxService->getAllMessages(); } else { $messageNumbers = $mailboxService->getMessagesAfter(time()); } $messages = ImapMessageCollectionFactory::create($messageNumbers, $imap); ?> <html> <head> <title>Emails</title> <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
set_time_limit(0); require_once '../../vendor/autoload.php'; use Humps\ImapCacheManager\Memcache\MemcacheMessageCache; use Humps\ImapCacheManager\Memcache\MemcacheServer; use Humps\ImapCacheManager\ImapMessageCache; use Humps\MailManager\Factories\ImapFactory; use Humps\MailManager\ImapMailboxService; // The number of days the message should remain cached for (Max: 30). Use 0 for never expires const CACHE_DURATION = 28; // The memcache server host const HOST = 'localhost'; // The memcache server port const PORT = 11211; // Pass the cacheBody parameter as false if you do not want to cache the message body. $cacheBody = isset($_REQUEST['cacheBody']) ? $_REQUEST['cacheBody'] : true; $folder = isset($_REQUEST['folder']) ? $_REQUEST['folder'] : 'INBOX'; // Create the MailboxService so we can access our mailbox $imap = ImapFactory::create($folder, '../imap_config/config.php'); $mailboxService = new ImapMailboxService($imap); // Create the cache service $cacheServer = MemcacheServer::connect(HOST, PORT); $cache = new MemcacheMessageCache($cacheServer); $messageCache = new ImapMessageCache($cache, $imap); // Get messages after the last time a message was cached (this is a timestamp, which ImapMailboxService will handle) $lastCached = $cacheServer->getLastCached() ? $cacheServer->getLastCached() : time() - 60 * 60 * 24; echo $lastCached; $messages = $mailboxService->getMessagesAfter($lastCached); // Convert the CACHE_DURATION to seconds. $expires = 60 * 60 * 24 * CACHE_DURATION; // Now cache the messages $messageCache->cacheMessages($messages, true, $expires);