<?php /** * This script can be used either via an ajax call to update cached folders and/or as a cron * job or scheduled task. It simply caches all folders returned from the server. */ use Humps\ImapCacheManager\Memcache\MemcacheFolderCache; use Humps\ImapCacheManager\Memcache\MemcacheServer; use Humps\MailManager\Factories\ImapFactory; use Humps\MailManager\Factories\ImapFolderCollectionFactory; use Humps\MailManager\ImapMailboxService; set_time_limit(0); require_once '../../vendor/autoload.php'; // The memcache server host const HOST = 'localhost'; // The memcache server port const PORT = 11211; $cacheServer = MemcacheServer::connect(HOST, PORT); $cache = new MemcacheFolderCache($cacheServer); // Create the MailboxService so we can access our mailbox $imap = ImapFactory::create('INBOX', '../imap_config/config.php'); $mailboxService = new ImapMailboxService($imap); $folders = ImapFolderCollectionFactory::create($mailboxService->getAllFolders()); $cache->cacheFolders($folders);
/** * @test */ public function it_should_get_all_the_folders_in_the_current_mailbox() { $imap = $this->getImap(false); /** @noinspection PhpUndefinedMethodInspection */ $this->mailbox->shouldReceive('getMailboxName')->with(true)->andReturn('{imap.example.com:993/imap/ssl}'); /** @noinspection PhpUndefinedMethodInspection */ $imap->shouldReceive('getFolders')->with('{imap.example.com:993/imap/ssl}', '*'); $mailboxManager = new ImapMailboxService($imap); $mailboxManager->getAllFolders(); }