/** * @group medium */ public function testMsgHandleUidSearch() { $path1 = './test_data/test_mailbox_' . date('Ymd_His') . '_' . uniqid('', true); $log = new Logger('test_application'); #$log->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG)); $server = new Server('', 0); $server->setLog($log); $server->init(); $storage1 = new DirectoryStorage(); $storage1->setPath($path1); $server->addStorage($storage1); $client = new Client(); $client->setServer($server); $client->setId(1); $msg = $client->msgHandle('17 uid search'); $this->assertEquals('17 NO uid failure' . Client::MSG_SEPARATOR, $msg); $client->setStatus('hasAuth', true); $msg = $client->msgHandle('17 uid search'); $this->assertEquals('17 NO No mailbox selected.' . Client::MSG_SEPARATOR, $msg); $client->msgHandle('6 select INBOX'); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 1'); $message->setBody('my_body'); $server->addMail($message, null, null, false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 2'); $message->setBody('my_body'); $server->addMail($message, null, array(Storage::FLAG_ANSWERED), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->addBcc('*****@*****.**'); $message->setSubject('my_subject 3'); $message->setBody('my_body'); $server->addMail($message, null, null, false); $headers = new Headers(); $headers->addHeader(Date::fromString('Date: ' . date('r', mktime(0, 0, 0, 2, 21, 1987)))); $message = new Message(); $message->setHeaders($headers); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 4'); $message->setBody('my_body'); $server->addMail($message, null, null, false); $message = new Message(); $message->setHeaders($headers); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 5'); $message->setBody('my_body'); $server->addMail($message, null, null, false); $headers = new Headers(); $headers->addHeader(Date::fromString('Date: ' . date('r', mktime(0, 0, 0, 11, 20, 1986)))); $message = new Message(); $message->setHeaders($headers); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 6'); $message->setBody('hello world'); $server->addMail($message, null, null, false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 7'); $message->setBody('my_body'); $server->addMail($message, null, array(Storage::FLAG_DELETED), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 8'); $message->setBody('my_body'); $server->addMail($message, null, array(Storage::FLAG_DRAFT), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 9'); $message->setBody('my_body'); $server->addMail($message, null, array(Storage::FLAG_FLAGGED), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 10'); $message->setBody('my_body'); $server->addMail($message, null, null, false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 11'); $message->setBody('my super fancy long body for testing the size'); $server->addMail($message, null, null, false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 12'); $message->setBody('my_body'); $server->addMail($message, null, array(), true); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 13'); $message->setBody('my_body'); $server->addMail($message, null, array(), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); #$message->setSubject('my_subject 14'); $message->setBody('my_body'); $server->addMail($message, null, array(), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 15'); $message->setBody('this is a test body'); $server->addMail($message, null, array(), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 16'); #$message->setBody('my_body'); $server->addMail($message, null, array(), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 17'); $message->setBody('my_body'); $server->addMail($message, null, array(), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 18'); $message->setBody('my_body'); $server->addMail($message, null, array(), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 19'); $message->setBody('my_body'); $server->addMail($message, null, array(Storage::FLAG_ANSWERED), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 20'); $message->setBody('my_body'); $server->addMail($message, null, array(Storage::FLAG_DELETED), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->setSubject('my_subject 21'); $message->setBody('my_body'); $server->addMail($message, null, array(Storage::FLAG_DRAFT), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->addCc('*****@*****.**'); $message->setSubject('my_subject 22'); $message->setBody('my_body'); $server->addMail($message, null, array(Storage::FLAG_FLAGGED), false); $message = new Message(); $message->addFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $message->addCc('*****@*****.**'); $message->setSubject('my_subject 23'); $message->setBody('my_body'); $server->addMail($message, null, array(Storage::FLAG_SEEN), false); $msg = $client->msgHandle('17 uid SEARCH'); $expect = '17 BAD Arguments invalid.' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH ALL'); $expect = '* SEARCH 100001 100002 100003 100004 100005 100006 100007 100008 100009 100010 '; $expect .= '100011 100012 100013 100014 100015 100016 100017 100018 100019 100020 100021 '; $expect .= '100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH ANSWERED'); $expect = '* SEARCH 100002 100019' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH BCC apple'); $expect = '* SEARCH 100003' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); #$msg = $client->msgHandle('17 uid SEARCH BEFORE 1990'); $expect = '* SEARCH 100004 100005' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; #$this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH BODY world'); $expect = '* SEARCH 100006' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH CC dev3'); $expect = '* SEARCH 100022 100023' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH DELETED'); $expect = '* SEARCH 100007 100020' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH DRAFT'); $expect = '* SEARCH 100008 100021' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH FLAGGED'); $expect = '* SEARCH 100009 100022' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH FROM test@'); $expect = '* SEARCH 100010' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH HEADER Date 1987'); $expect = '* SEARCH 100004 100005' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH HEADER TO fox21'); $expect = '* SEARCH 100001 100002 100003 100004 100005 100006 100007 100008 100009 100010 100011 100012 '; $expect .= '100013 100014 100015 100016 100018 100019 100020 100021 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH LARGER 40'); $expect = '* SEARCH 100011' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH NEW'); $expect = '* SEARCH 100012' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH OLD'); $expect = '* SEARCH 100001 100002 100003 100004 100005 100006 100007 100008 100009 100010 100011 100013'; $expect .= ' 100014 100015 100016 100017 100018 100019 100020 100021 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH ON 1987-02-21'); $expect = '* SEARCH 100004 100005' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH OR 5 6'); $expect = '* SEARCH 100005 100006' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH OR OR 5 6 7'); $expect = '* SEARCH 100005 100006 100007' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH RECENT'); $expect = '* SEARCH 100012' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH SEEN'); $expect = '* SEARCH 100001 100003 100004 100005 100006 100010 100011 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH SENTBEFORE 1990-01-01'); $expect = '* SEARCH 100004 100005 100006' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH SENTON 1987-02-21'); $expect = '* SEARCH 100004 100005' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH SENTSINCE 1987-02-21'); $expect = '* SEARCH 100001 100002 100003 100004 100005 100007 100008 100009 100010 100011 100012 100013'; $expect .= ' 100014 100015 100016 100017 100018 100019 100020 100021 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH SMALLER 30'); $expect = '* SEARCH 100001 100002 100003 100004 100005 100006 100007 100008 100009 100010 100012 100013'; $expect .= ' 100014 100015 100016 100017 100018 100019 100020 100021 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH SUBJECT "t 13"'); $expect = '* SEARCH 100013' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH TEXT test'); $expect = '* SEARCH 100011 100015' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH TO steve'); $expect = '* SEARCH 100017' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH UID 100018'); $expect = '* SEARCH 100018' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH UNANSWERED'); $expect = '* SEARCH 100001 100003 100004 100005 100006 100007 100008 100009 100010 100011 100012 100013'; $expect .= ' 100014 100015 100016 100017 100018 100020 100021 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH UNDELETED'); $expect = '* SEARCH 100001 100002 100003 100004 100005 100006 100008 100009 100010 100011 100012 100013'; $expect .= ' 100014 100015 100016 100017 100018 100019 100021 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH UNDRAFT'); $expect = '* SEARCH 100001 100002 100003 100004 100005 100006 100007 100009 100010 100011 100012 100013'; $expect .= ' 100014 100015 100016 100017 100018 100019 100020 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH UNFLAGGED'); $expect = '* SEARCH 100001 100002 100003 100004 100005 100006 100007 100008 100010 100011 100012 100013'; $expect .= ' 100014 100015 100016 100017 100018 100019 100020 100021 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); #$msg = $client->msgHandle('17 uid SEARCH UNKEYWORD'); $expect = '* SEARCH 123' . Client::MSG_SEPARATOR . '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; #$this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH UNSEEN'); $expect = '* SEARCH 100002 100007 100008 100009 100012 100013 100014 100015 100016 100017 100018'; $expect .= ' 100019 100020 100021 100022' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH OR CC dev3 TO steve'); $expect = '* SEARCH 100017 100022 100023'; $expect .= '' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH OR CC dev3 NOT CC dev2'); $expect = '* SEARCH 100001 100002 100003 100004 100005 100006 100007 100008 100009 100010 100011'; $expect .= ' 100012 100013 100014 100015 100016 100017'; $expect .= ' 100018 100019 100020 100021 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH CC dev3 AND TO dev2'); $expect = ''; $expect .= '* SEARCH 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH CC dev3 AND OR FROM dev1 TO dev2'); $expect = ''; $expect .= '* SEARCH 100022 100023' . Client::MSG_SEPARATOR; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH CC dev3 AND AND FROM dev1 NOT TO dev2'); $expect = ''; $expect .= '17 OK UID SEARCH completed' . Client::MSG_SEPARATOR; $this->assertEquals($expect, $msg); $msg = $client->msgHandle('17 uid SEARCH BEFORE 1985'); $this->assertEquals('17 OK UID SEARCH completed' . Client::MSG_SEPARATOR, $msg); $msg = $client->msgHandle('17 uid SEARCH BODY xyz'); $this->assertEquals('17 OK UID SEARCH completed' . Client::MSG_SEPARATOR, $msg); #$msg = $client->msgHandle('17 uid SEARCH OR (UNDELETED FROM "thefox") ANSWERED AND FROM "21"'); #$msg = $client->msgHandle('17 uid SEARCH UNDELETED HEADER From @fox21.at HEADER Date 2014'); #$msg = $client->msgHandle('17 uid SEARCH NOT 5'); #$msg = $client->msgHandle('17 uid SEARCH NOT UID 100005'); #$this->assertEquals('x17 OK UID SEARCH completed'.Client::MSG_SEPARATOR, $msg); #$msg = $client->msgHandle('17 uid SEARCH NOT UID 100021'); $server->shutdown(); $filesystem = new Filesystem(); $filesystem->remove($path1); }
/** * Access headers collection * * Lazy-loads if not already attached. * * @return Headers */ public function getHeaders() { if (null === $this->headers) { $this->setHeaders(new Headers()); $date = Header\Date::fromString('Date: ' . date('r')); $this->headers->addHeader($date); } return $this->headers; }