/* Decoded by unphp.net */ createEventDispatcher(); $addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); return new Swift_Transport_EsmtpTransport($buf, array(), $dispatcher, "example.org", $addressEncoder); } public function testHostCanBeSetAndFetched() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $smtp->setHost("foo"); $this->assertEquals("foo", $smtp->getHost(), "%s: Host should be returned"); } public function testPortCanBeSetAndFetched() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $smtp->setPort(25); $this->assertEquals(25, $smtp->getPort(), "%s: Port should be returned"); } public function testTimeoutCanBeSetAndFetched() { $buf = $this->getBuffer(); $buf->shouldReceive("setParam")->once()->with("timeout", 10); $smtp = $this->getTransport($buf); $smtp->setTimeout(10); $this->assertEquals(10, $smtp->getTimeout(), "%s: Timeout should be returned"); } public function testEncryptionCanBeSetAndFetched() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $smtp->setEncryption("tls"); $this->assertEquals("tls", $smtp->getEncryption(), "%s: Crypto should be returned"); } public function testStartSendsHeloToInitiate() { $this->addToAssertionCount(1); } public function testStartSendsEhloToInitiate() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh \xa"); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^EHLO .+?\r\n$~D"))->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250 ServerName" . " "); $this->finishBuffer($buf); try { $smtp->start(); } catch (Exception $e) { $this->fail("Starting Esmtp should send EHLO and accept 250 response: " . $e->getMessage()); } } public function testHeloIsUsedAsFallback() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh \xa"); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^EHLO .+?\r\n$~D"))->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("501 WTF" . "\xd\xa"); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^HELO .+?\r\n$~D"))->andReturn(2); $buf->shouldReceive("readLine")->once()->with(2)->andReturn("250 HELO" . " \xa"); $this->finishBuffer($buf); try { $smtp->start(); } catch (Exception $e) { $this->fail("Starting Esmtp should fallback to HELO if needed and accept 250 response"); } } public function testInvalidHeloResponseCausesException() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh "); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^EHLO .+?\r\n$~D"))->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("501 WTF" . " \xa"); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^HELO .+?\r\n$~D"))->andReturn(2); $buf->shouldReceive("readLine")->once()->with(2)->andReturn("504 WTF" . "\xd\xa"); $this->finishBuffer($buf); try { $this->assertFalse($smtp->isStarted(), "%s: SMTP should begin non-started"); $smtp->start(); $this->fail("Non 250 HELO response should raise Exception"); } catch (Exception $e) { $this->assertFalse($smtp->isStarted(), "%s: SMTP start() should have failed"); } } public function testDomainNameIsPlacedInEhlo() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh\xd "); $buf->shouldReceive("write")->once()->with("EHLO mydomain.com ")->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250 ServerName" . " \xa"); $this->finishBuffer($buf); $smtp->setLocalDomain("mydomain.com"); $smtp->start(); } public function testDomainNameIsPlacedInHelo() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh\xd\xa"); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^EHLO .+?\r\n$~D"))->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("501 WTF" . " "); $buf->shouldReceive("write")->once()->with("HELO mydomain.com ")->andReturn(2); $buf->shouldReceive("readLine")->once()->with(2)->andReturn("250 ServerName" . "\xd\xa"); $this->finishBuffer($buf); $smtp->setLocalDomain("mydomain.com"); $smtp->start(); } public function testPipelining() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $this->assertNull($smtp->getPipelining()); $message = $this->createMessage(); $message->shouldReceive("getFrom")->zeroOrMoreTimes()->andReturn(array("me@domain.com" => "Me")); $message->shouldReceive("getTo")->zeroOrMoreTimes()->andReturn(array("foo@bar" => null)); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh "); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^EHLO .+?\r\n$~D"))->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250-ServerName" . " \xa"); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250 PIPELINING" . "\xd\xa"); $buf->shouldReceive("write")->ordered()->once()->with("MAIL FROM:\xd ")->andReturn(1); $buf->shouldReceive("write")->ordered()->once()->with("RCPT TO: \xa")->andReturn(2); $buf->shouldReceive("write")->ordered()->once()->with("DATA \xa")->andReturn(3); $buf->shouldReceive("readLine")->ordered()->once()->with(1)->andReturn("250 OK "); $buf->shouldReceive("readLine")->ordered()->once()->with(2)->andReturn("250 OK "); $buf->shouldReceive("readLine")->ordered()->once()->with(3)->andReturn("354 OK "); $this->finishBuffer($buf); $smtp->start(); $sent = $smtp->send($message, $failedRecipients); $this->assertEquals(1, $sent); $this->assertEmpty($failedRecipients); $this->assertTrue($smtp->getPipelining()); } public function testPipeliningWithRecipientFailure() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $this->assertNull($smtp->getPipelining()); $message = $this->createMessage(); $message->shouldReceive("getFrom")->zeroOrMoreTimes()->andReturn(array("me@domain.com" => "Me")); $message->shouldReceive("getTo")->zeroOrMoreTimes()->andReturn(array("good@foo" => null, "bad@foo" => null, "good@bar" => null)); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh \xa"); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^EHLO .+?\r\n$~D"))->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250-ServerName" . " "); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250 PIPELINING" . "\xd\xa"); $buf->shouldReceive("write")->ordered()->once()->with("MAIL FROM: ")->andReturn(1); $buf->shouldReceive("write")->ordered()->once()->with("RCPT TO: ")->andReturn(2); $buf->shouldReceive("write")->ordered()->once()->with("RCPT TO: \xa")->andReturn(3); $buf->shouldReceive("write")->ordered()->once()->with("RCPT TO: ")->andReturn(4); $buf->shouldReceive("write")->ordered()->once()->with("DATA \xa")->andReturn(5); $buf->shouldReceive("readLine")->ordered()->once()->with(1)->andReturn("250 OK \xa"); $buf->shouldReceive("readLine")->ordered()->once()->with(2)->andReturn("250 OK\xd\xa"); $buf->shouldReceive("readLine")->ordered()->once()->with(3)->andReturn("450 Unknown address bad@foo \xa"); $buf->shouldReceive("readLine")->ordered()->once()->with(4)->andReturn("250 OK "); $buf->shouldReceive("readLine")->ordered()->once()->with(5)->andReturn("354 OK\xd "); $this->finishBuffer($buf); $smtp->start(); $sent = $smtp->send($message, $failedRecipients); $this->assertEquals(2, $sent); $this->assertEquals(array("bad@foo"), $failedRecipients); $this->assertTrue($smtp->getPipelining()); } public function testPipeliningWithSenderFailure() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $this->assertNull($smtp->getPipelining()); $message = $this->createMessage(); $message->shouldReceive("getFrom")->zeroOrMoreTimes()->andReturn(array("me@domain.com" => "Me")); $message->shouldReceive("getTo")->zeroOrMoreTimes()->andReturn(array("foo@bar" => null)); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh \xa"); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^EHLO .+?\r\n$~D"))->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250-ServerName" . " "); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250 PIPELINING" . "\xd\xa"); $buf->shouldReceive("write")->ordered()->once()->with("MAIL FROM: \xa")->andReturn(1); $buf->shouldReceive("write")->ordered()->once()->with("RCPT TO: \xa")->andReturn(2); $buf->shouldReceive("write")->ordered()->once()->with("DATA \xa")->andReturn(3); $buf->shouldReceive("readLine")->ordered()->once()->with(1)->andReturn("550 Unknown address me@domain.com\xd\xa"); $smtp->start(); $this->expectException("Swift_TransportException"); $this->expectExceptionMessage("Expected response code 250 but got code "550""); $smtp->send($message, $failedRecipients); } public function testPipeliningWithDataFailure() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $this->assertNull($smtp->getPipelining()); $message = $this->createMessage(); $message->shouldReceive("getFrom")->zeroOrMoreTimes()->andReturn(array("me@domain.com" => "Me")); $message->shouldReceive("getTo")->zeroOrMoreTimes()->andReturn(array("foo@bar" => null)); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh "); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^EHLO .+?\r\n$~D"))->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250-ServerName" . " \xa"); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250 PIPELINING" . "\xd\xa"); $buf->shouldReceive("write")->ordered()->once()->with("MAIL FROM: \xa")->andReturn(1); $buf->shouldReceive("write")->ordered()->once()->with("RCPT TO:\xd ")->andReturn(2); $buf->shouldReceive("write")->ordered()->once()->with("DATA \xa")->andReturn(3); $buf->shouldReceive("readLine")->ordered()->once()->with(1)->andReturn("250 OK\xd "); $buf->shouldReceive("readLine")->ordered()->once()->with(2)->andReturn("250 OK "); $buf->shouldReceive("readLine")->ordered()->once()->with(3)->andReturn("452 Insufficient system storage \xa"); $smtp->start(); $this->expectException("Swift_TransportException"); $this->expectExceptionMessage("Expected response code 354 but got code "452""); $smtp->send($message, $failedRecipients); } public function providerPipeliningOverride() { return array(array(null, true, true), array(null, false, false), array(true, false, true), array(true, true, true), array(false, false, false), array(false, true, false)); } public function testPipeliningOverride($enabled, bool $supported, bool $expected) { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $this->assertNull($smtp->getPipelining()); $smtp->setPipelining($enabled); $this->assertSame($enabled, $smtp->getPipelining()); $message = $this->createMessage(); $message->shouldReceive("getFrom")->zeroOrMoreTimes()->andReturn(array("me@domain.com" => "Me")); $buf->shouldReceive("initialize")->once(); $buf->shouldReceive("readLine")->once()->with(0)->andReturn("220 some.server.tld bleh "); $buf->shouldReceive("write")->once()->with(Mockery::pattern("~^EHLO .+?\r\n$~D"))->andReturn(1); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250-ServerName" . " \xa"); $buf->shouldReceive("readLine")->once()->with(1)->andReturn("250 " . ($supported ? "PIPELINING" : "FOOBAR") . " "); $this->finishBuffer($buf); $smtp->start(); $smtp->send($message); $this->assertSame($expected, $smtp->getPipelining()); } public function testFluidInterface() { $buf = $this->getBuffer(); $smtp = $this->getTransport($buf); $buf->shouldReceive("setParam")->once()->with("timeout", 30); $ref = $smtp->setHost("foo")->setPort(25)->setEncryption("tls")->setTimeout(30)->setPipelining(false); $this->assertEquals($ref, $smtp); } } ?>