Example #1
0
 public function clientRemove(Client $client)
 {
     $this->log->debug('client remove: ' . $client->getId());
     $client->shutdown();
     $clientsId = $client->getId();
     unset($this->clients[$clientsId]);
 }
Example #2
0
 public function testMsgHandleMail()
 {
     $server = new Server('', 0);
     $server->setLog(new Logger('test_application'));
     $server->init();
     $client = new Client();
     $client->setServer($server);
     $client->setId(1);
     $msg = $client->msgHandle('MAIL FROM:<*****@*****.**>');
     $this->assertEquals('500 Syntax error, command unrecognized' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('HELO localhost.localdomain');
     $this->assertEquals('250 localhost.localdomain' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('MAIL');
     $this->assertEquals('501 Syntax error in parameters or arguments' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('MAIL FROM:<*****@*****.**>');
     $this->assertEquals('250 OK' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('RCPT');
     $this->assertEquals('501 Syntax error in parameters or arguments' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('RCPT TO:<*****@*****.**>');
     $this->assertEquals('250 OK' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('RCPT TO:<*****@*****.**>');
     $this->assertEquals('250 OK' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('DATA');
     $this->assertEquals('354 Start mail input; end with <CRLF>.<CRLF>' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('From: TheFox <*****@*****.**>');
     $this->assertEquals('', $msg);
     $msg = $client->msgHandle('To: TheFox <*****@*****.**>');
     $this->assertEquals('', $msg);
     $msg = $client->msgHandle('Subject: Test');
     $this->assertEquals('', $msg);
     $msg = $client->msgHandle('');
     $this->assertEquals('', $msg);
     $msg = $client->msgHandle('Body');
     $this->assertEquals('', $msg);
     $msg = $client->msgHandle('.');
     $this->assertEquals('250 OK' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('QUIT');
     $this->assertEquals('221 localhost.localdomain Service closing transmission channel' . Client::MSG_SEPARATOR, $msg);
 }
Example #3
0
 public function testMsgHandleStartTls()
 {
     $server = new Server('', 0);
     $server->setLog(new Logger('test_application'));
     $server->init();
     $socket = $this->getMock('TheFox\\Network\\StreamSocket', array('enableEncryption'));
     $socket->expects($this->at(0))->method('enableEncryption')->will($this->throwException(new RuntimeException()));
     $socket->expects($this->at(1))->method('enableEncryption')->will($this->returnValue(true));
     $client = new Client();
     $client->setServer($server);
     $client->setId(1);
     $client->setSocket($socket);
     $msg = $client->msgHandle('EHLO localhost.localdomain');
     $expect = '250-localhost.localdomain' . Client::MSG_SEPARATOR;
     $expect .= '250-AUTH PLAIN LOGIN' . Client::MSG_SEPARATOR;
     $expect .= '250-STARTTLS' . Client::MSG_SEPARATOR;
     $expect .= '250 HELP' . Client::MSG_SEPARATOR;
     $this->assertEquals($expect, $msg);
     $msg = $client->msgHandle('STARTTLS PARAMETER');
     $this->assertEquals('501 Syntax error in parameters or arguments' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('STARTTLS');
     $this->assertEquals('454 TLS not available due to temporary reason' . Client::MSG_SEPARATOR, $msg);
     $msg = $client->msgHandle('STARTTLS');
     $this->assertTrue($msg);
 }