From 30fba4d490f5966a8ddb1375ec307be03dc4c3a3 Mon Sep 17 00:00:00 2001 From: Aleksey Khudyakov Date: Mon, 10 Sep 2012 03:12:18 +1100 Subject: [PATCH 1/6] make Mail\Message::fromString() method static --- src/Message.php | 12 ++++++++---- test/MessageTest.php | 4 +--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Message.php b/src/Message.php index f8421e1a..2d53f10f 100644 --- a/src/Message.php +++ b/src/Message.php @@ -542,13 +542,17 @@ public function toString() * @param string $rawMessage * @return Message */ - public function fromString($rawMessage) + public static function fromString($rawMessage) { + $message = new static(); $headers = null; $content = null; Mime\Decode::splitMessage($rawMessage, $headers, $content); - $this->setHeaders($headers); - $this->setBody($content); - return $this; + if ($headers->has('mime-version')) { + // @todo restore body to mime\message + } + $message->setHeaders($headers); + $message->setBody($content); + return $message; } } diff --git a/test/MessageTest.php b/test/MessageTest.php index bb295a85..6d33d76b 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -655,10 +655,8 @@ public function testRestoreFromSerializedString() $this->message->addCc('zf-contributors@lists.zend.com', 'ZF Contributors List'); $this->message->setSubject('This is a subject'); $this->message->setBody('foo'); - $serialized = $this->message->toString(); - $restoredMessage = new Message(); - $restoredMessage->fromString($serialized); + $restoredMessage = Message::fromString($serialized); $this->assertEquals($serialized, $restoredMessage->toString()); } } From f80689050bb185aa2fe8fcfc39d286ec66f7a579 Mon Sep 17 00:00:00 2001 From: Aleksey Khudyakov Date: Tue, 11 Sep 2012 08:32:46 +1100 Subject: [PATCH 2/6] update emails used in tests to @example.com --- src/Message.php | 2 +- test/MessageTest.php | 188 +++++++++++++++++++++---------------------- 2 files changed, 95 insertions(+), 95 deletions(-) diff --git a/src/Message.php b/src/Message.php index 2d53f10f..37f3866f 100644 --- a/src/Message.php +++ b/src/Message.php @@ -537,7 +537,7 @@ public function toString() } /** - * Set from serialized string + * Instantiate from raw message string * * @param string $rawMessage * @return Message diff --git a/test/MessageTest.php b/test/MessageTest.php index 6d33d76b..4ee224a2 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -56,7 +56,7 @@ public function testSetsOrigDateHeaderByDefault() public function testAddingFromAddressMarksAsValid() { - $this->message->addFrom('zf-devteam@zend.com'); + $this->message->addFrom('zf-devteam@example.com'); $this->assertTrue($this->message->isValid()); } @@ -68,14 +68,14 @@ public function testHeadersMethodReturnsHeadersObject() public function testToMethodReturnsAddressListObject() { - $this->message->addTo('zf-devteam@zend.com'); + $this->message->addTo('zf-devteam@example.com'); $to = $this->message->getTo(); $this->assertInstanceOf('Zend\Mail\AddressList', $to); } public function testToAddressListLivesInHeaders() { - $this->message->addTo('zf-devteam@zend.com'); + $this->message->addTo('zf-devteam@example.com'); $to = $this->message->getTo(); $headers = $this->message->getHeaders(); $this->assertInstanceOf('Zend\Mail\Headers', $headers); @@ -86,14 +86,14 @@ public function testToAddressListLivesInHeaders() public function testFromMethodReturnsAddressListObject() { - $this->message->addFrom('zf-devteam@zend.com'); + $this->message->addFrom('zf-devteam@example.com'); $from = $this->message->getFrom(); $this->assertInstanceOf('Zend\Mail\AddressList', $from); } public function testFromAddressListLivesInHeaders() { - $this->message->addFrom('zf-devteam@zend.com'); + $this->message->addFrom('zf-devteam@example.com'); $from = $this->message->getFrom(); $headers = $this->message->getHeaders(); $this->assertInstanceOf('Zend\Mail\Headers', $headers); @@ -104,14 +104,14 @@ public function testFromAddressListLivesInHeaders() public function testCcMethodReturnsAddressListObject() { - $this->message->addCc('zf-devteam@zend.com'); + $this->message->addCc('zf-devteam@example.com'); $cc = $this->message->getCc(); $this->assertInstanceOf('Zend\Mail\AddressList', $cc); } public function testCcAddressListLivesInHeaders() { - $this->message->addCc('zf-devteam@zend.com'); + $this->message->addCc('zf-devteam@example.com'); $cc = $this->message->getCc(); $headers = $this->message->getHeaders(); $this->assertInstanceOf('Zend\Mail\Headers', $headers); @@ -122,14 +122,14 @@ public function testCcAddressListLivesInHeaders() public function testBccMethodReturnsAddressListObject() { - $this->message->addBcc('zf-devteam@zend.com'); + $this->message->addBcc('zf-devteam@example.com'); $bcc = $this->message->getBcc(); $this->assertInstanceOf('Zend\Mail\AddressList', $bcc); } public function testBccAddressListLivesInHeaders() { - $this->message->addBcc('zf-devteam@zend.com'); + $this->message->addBcc('zf-devteam@example.com'); $bcc = $this->message->getBcc(); $headers = $this->message->getHeaders(); $this->assertInstanceOf('Zend\Mail\Headers', $headers); @@ -140,14 +140,14 @@ public function testBccAddressListLivesInHeaders() public function testReplyToMethodReturnsAddressListObject() { - $this->message->addReplyTo('zf-devteam@zend.com'); + $this->message->addReplyTo('zf-devteam@example.com'); $replyTo = $this->message->getReplyTo(); $this->assertInstanceOf('Zend\Mail\AddressList', $replyTo); } public function testReplyToAddressListLivesInHeaders() { - $this->message->addReplyTo('zf-devteam@zend.com'); + $this->message->addReplyTo('zf-devteam@example.com'); $replyTo = $this->message->getReplyTo(); $headers = $this->message->getHeaders(); $this->assertInstanceOf('Zend\Mail\Headers', $headers); @@ -163,14 +163,14 @@ public function testSenderIsNullByDefault() public function testSettingSenderCreatesAddressObject() { - $this->message->setSender('zf-devteam@zend.com'); + $this->message->setSender('zf-devteam@example.com'); $sender = $this->message->getSender(); $this->assertInstanceOf('Zend\Mail\Address', $sender); } public function testCanSpecifyNameWhenSettingSender() { - $this->message->setSender('zf-devteam@zend.com', 'ZF DevTeam'); + $this->message->setSender('zf-devteam@example.com', 'ZF DevTeam'); $sender = $this->message->getSender(); $this->assertInstanceOf('Zend\Mail\Address', $sender); $this->assertEquals('ZF DevTeam', $sender->getName()); @@ -178,7 +178,7 @@ public function testCanSpecifyNameWhenSettingSender() public function testCanProvideAddressObjectWhenSettingSender() { - $sender = new Address('zf-devteam@zend.com'); + $sender = new Address('zf-devteam@example.com'); $this->message->setSender($sender); $test = $this->message->getSender(); $this->assertSame($sender, $test); @@ -188,24 +188,24 @@ public function testSenderAccessorsProxyToSenderHeader() { $header = new Header\Sender(); $this->message->getHeaders()->addHeader($header); - $address = new Address('zf-devteam@zend.com', 'ZF DevTeam'); + $address = new Address('zf-devteam@example.com', 'ZF DevTeam'); $this->message->setSender($address); $this->assertSame($address, $header->getAddress()); } public function testCanAddFromAddressUsingName() { - $this->message->addFrom('zf-devteam@zend.com', 'ZF DevTeam'); + $this->message->addFrom('zf-devteam@example.com', 'ZF DevTeam'); $addresses = $this->message->getFrom(); $this->assertEquals(1, count($addresses)); $address = $addresses->current(); - $this->assertEquals('zf-devteam@zend.com', $address->getEmail()); + $this->assertEquals('zf-devteam@example.com', $address->getEmail()); $this->assertEquals('ZF DevTeam', $address->getName()); } public function testCanAddFromAddressUsingAddressObject() { - $address = new Address('zf-devteam@zend.com', 'ZF DevTeam'); + $address = new Address('zf-devteam@example.com', 'ZF DevTeam'); $this->message->addFrom($address); $addresses = $this->message->getFrom(); @@ -217,59 +217,59 @@ public function testCanAddFromAddressUsingAddressObject() public function testCanAddManyFromAddressesUsingArray() { $addresses = array( - 'zf-devteam@zend.com', - 'zf-contributors@lists.zend.com' => 'ZF Contributors List', - new Address('fw-announce@lists.zend.com', 'ZF Announce List'), + 'zf-devteam@example.com', + 'zf-contributors@example.com' => 'ZF Contributors List', + new Address('fw-announce@example.com', 'ZF Announce List'), ); $this->message->addFrom($addresses); $from = $this->message->getFrom(); $this->assertEquals(3, count($from)); - $this->assertTrue($from->has('zf-devteam@zend.com')); - $this->assertTrue($from->has('zf-contributors@lists.zend.com')); - $this->assertTrue($from->has('fw-announce@lists.zend.com')); + $this->assertTrue($from->has('zf-devteam@example.com')); + $this->assertTrue($from->has('zf-contributors@example.com')); + $this->assertTrue($from->has('fw-announce@example.com')); } public function testCanAddManyFromAddressesUsingAddressListObject() { $list = new AddressList(); - $list->add('zf-devteam@zend.com'); + $list->add('zf-devteam@example.com'); - $this->message->addFrom('fw-announce@lists.zend.com'); + $this->message->addFrom('fw-announce@example.com'); $this->message->addFrom($list); $from = $this->message->getFrom(); $this->assertEquals(2, count($from)); - $this->assertTrue($from->has('fw-announce@lists.zend.com')); - $this->assertTrue($from->has('zf-devteam@zend.com')); + $this->assertTrue($from->has('fw-announce@example.com')); + $this->assertTrue($from->has('zf-devteam@example.com')); } public function testCanSetFromListFromAddressList() { $list = new AddressList(); - $list->add('zf-devteam@zend.com'); + $list->add('zf-devteam@example.com'); - $this->message->addFrom('fw-announce@lists.zend.com'); + $this->message->addFrom('fw-announce@example.com'); $this->message->setFrom($list); $from = $this->message->getFrom(); $this->assertEquals(1, count($from)); - $this->assertFalse($from->has('fw-announce@lists.zend.com')); - $this->assertTrue($from->has('zf-devteam@zend.com')); + $this->assertFalse($from->has('fw-announce@example.com')); + $this->assertTrue($from->has('zf-devteam@example.com')); } public function testCanAddCcAddressUsingName() { - $this->message->addCc('zf-devteam@zend.com', 'ZF DevTeam'); + $this->message->addCc('zf-devteam@example.com', 'ZF DevTeam'); $addresses = $this->message->getCc(); $this->assertEquals(1, count($addresses)); $address = $addresses->current(); - $this->assertEquals('zf-devteam@zend.com', $address->getEmail()); + $this->assertEquals('zf-devteam@example.com', $address->getEmail()); $this->assertEquals('ZF DevTeam', $address->getName()); } public function testCanAddCcAddressUsingAddressObject() { - $address = new Address('zf-devteam@zend.com', 'ZF DevTeam'); + $address = new Address('zf-devteam@example.com', 'ZF DevTeam'); $this->message->addCc($address); $addresses = $this->message->getCc(); @@ -281,59 +281,59 @@ public function testCanAddCcAddressUsingAddressObject() public function testCanAddManyCcAddressesUsingArray() { $addresses = array( - 'zf-devteam@zend.com', - 'zf-contributors@lists.zend.com' => 'ZF Contributors List', - new Address('fw-announce@lists.zend.com', 'ZF Announce List'), + 'zf-devteam@example.com', + 'zf-contributors@example.com' => 'ZF Contributors List', + new Address('fw-announce@example.com', 'ZF Announce List'), ); $this->message->addCc($addresses); $cc = $this->message->getCc(); $this->assertEquals(3, count($cc)); - $this->assertTrue($cc->has('zf-devteam@zend.com')); - $this->assertTrue($cc->has('zf-contributors@lists.zend.com')); - $this->assertTrue($cc->has('fw-announce@lists.zend.com')); + $this->assertTrue($cc->has('zf-devteam@example.com')); + $this->assertTrue($cc->has('zf-contributors@example.com')); + $this->assertTrue($cc->has('fw-announce@example.com')); } public function testCanAddManyCcAddressesUsingAddressListObject() { $list = new AddressList(); - $list->add('zf-devteam@zend.com'); + $list->add('zf-devteam@example.com'); - $this->message->addCc('fw-announce@lists.zend.com'); + $this->message->addCc('fw-announce@example.com'); $this->message->addCc($list); $cc = $this->message->getCc(); $this->assertEquals(2, count($cc)); - $this->assertTrue($cc->has('fw-announce@lists.zend.com')); - $this->assertTrue($cc->has('zf-devteam@zend.com')); + $this->assertTrue($cc->has('fw-announce@example.com')); + $this->assertTrue($cc->has('zf-devteam@example.com')); } public function testCanSetCcListFromAddressList() { $list = new AddressList(); - $list->add('zf-devteam@zend.com'); + $list->add('zf-devteam@example.com'); - $this->message->addCc('fw-announce@lists.zend.com'); + $this->message->addCc('fw-announce@example.com'); $this->message->setCc($list); $cc = $this->message->getCc(); $this->assertEquals(1, count($cc)); - $this->assertFalse($cc->has('fw-announce@lists.zend.com')); - $this->assertTrue($cc->has('zf-devteam@zend.com')); + $this->assertFalse($cc->has('fw-announce@example.com')); + $this->assertTrue($cc->has('zf-devteam@example.com')); } public function testCanAddBccAddressUsingName() { - $this->message->addBcc('zf-devteam@zend.com', 'ZF DevTeam'); + $this->message->addBcc('zf-devteam@example.com', 'ZF DevTeam'); $addresses = $this->message->getBcc(); $this->assertEquals(1, count($addresses)); $address = $addresses->current(); - $this->assertEquals('zf-devteam@zend.com', $address->getEmail()); + $this->assertEquals('zf-devteam@example.com', $address->getEmail()); $this->assertEquals('ZF DevTeam', $address->getName()); } public function testCanAddBccAddressUsingAddressObject() { - $address = new Address('zf-devteam@zend.com', 'ZF DevTeam'); + $address = new Address('zf-devteam@example.com', 'ZF DevTeam'); $this->message->addBcc($address); $addresses = $this->message->getBcc(); @@ -345,59 +345,59 @@ public function testCanAddBccAddressUsingAddressObject() public function testCanAddManyBccAddressesUsingArray() { $addresses = array( - 'zf-devteam@zend.com', - 'zf-contributors@lists.zend.com' => 'ZF Contributors List', - new Address('fw-announce@lists.zend.com', 'ZF Announce List'), + 'zf-devteam@example.com', + 'zf-contributors@example.com' => 'ZF Contributors List', + new Address('fw-announce@example.com', 'ZF Announce List'), ); $this->message->addBcc($addresses); $bcc = $this->message->getBcc(); $this->assertEquals(3, count($bcc)); - $this->assertTrue($bcc->has('zf-devteam@zend.com')); - $this->assertTrue($bcc->has('zf-contributors@lists.zend.com')); - $this->assertTrue($bcc->has('fw-announce@lists.zend.com')); + $this->assertTrue($bcc->has('zf-devteam@example.com')); + $this->assertTrue($bcc->has('zf-contributors@example.com')); + $this->assertTrue($bcc->has('fw-announce@example.com')); } public function testCanAddManyBccAddressesUsingAddressListObject() { $list = new AddressList(); - $list->add('zf-devteam@zend.com'); + $list->add('zf-devteam@example.com'); - $this->message->addBcc('fw-announce@lists.zend.com'); + $this->message->addBcc('fw-announce@example.com'); $this->message->addBcc($list); $bcc = $this->message->getBcc(); $this->assertEquals(2, count($bcc)); - $this->assertTrue($bcc->has('fw-announce@lists.zend.com')); - $this->assertTrue($bcc->has('zf-devteam@zend.com')); + $this->assertTrue($bcc->has('fw-announce@example.com')); + $this->assertTrue($bcc->has('zf-devteam@example.com')); } public function testCanSetBccListFromAddressList() { $list = new AddressList(); - $list->add('zf-devteam@zend.com'); + $list->add('zf-devteam@example.com'); - $this->message->addBcc('fw-announce@lists.zend.com'); + $this->message->addBcc('fw-announce@example.com'); $this->message->setBcc($list); $bcc = $this->message->getBcc(); $this->assertEquals(1, count($bcc)); - $this->assertFalse($bcc->has('fw-announce@lists.zend.com')); - $this->assertTrue($bcc->has('zf-devteam@zend.com')); + $this->assertFalse($bcc->has('fw-announce@example.com')); + $this->assertTrue($bcc->has('zf-devteam@example.com')); } public function testCanAddReplyToAddressUsingName() { - $this->message->addReplyTo('zf-devteam@zend.com', 'ZF DevTeam'); + $this->message->addReplyTo('zf-devteam@example.com', 'ZF DevTeam'); $addresses = $this->message->getReplyTo(); $this->assertEquals(1, count($addresses)); $address = $addresses->current(); - $this->assertEquals('zf-devteam@zend.com', $address->getEmail()); + $this->assertEquals('zf-devteam@example.com', $address->getEmail()); $this->assertEquals('ZF DevTeam', $address->getName()); } public function testCanAddReplyToAddressUsingAddressObject() { - $address = new Address('zf-devteam@zend.com', 'ZF DevTeam'); + $address = new Address('zf-devteam@example.com', 'ZF DevTeam'); $this->message->addReplyTo($address); $addresses = $this->message->getReplyTo(); @@ -409,44 +409,44 @@ public function testCanAddReplyToAddressUsingAddressObject() public function testCanAddManyReplyToAddressesUsingArray() { $addresses = array( - 'zf-devteam@zend.com', - 'zf-contributors@lists.zend.com' => 'ZF Contributors List', - new Address('fw-announce@lists.zend.com', 'ZF Announce List'), + 'zf-devteam@example.com', + 'zf-contributors@example.com' => 'ZF Contributors List', + new Address('fw-announce@example.com', 'ZF Announce List'), ); $this->message->addReplyTo($addresses); $replyTo = $this->message->getReplyTo(); $this->assertEquals(3, count($replyTo)); - $this->assertTrue($replyTo->has('zf-devteam@zend.com')); - $this->assertTrue($replyTo->has('zf-contributors@lists.zend.com')); - $this->assertTrue($replyTo->has('fw-announce@lists.zend.com')); + $this->assertTrue($replyTo->has('zf-devteam@example.com')); + $this->assertTrue($replyTo->has('zf-contributors@example.com')); + $this->assertTrue($replyTo->has('fw-announce@example.com')); } public function testCanAddManyReplyToAddressesUsingAddressListObject() { $list = new AddressList(); - $list->add('zf-devteam@zend.com'); + $list->add('zf-devteam@example.com'); - $this->message->addReplyTo('fw-announce@lists.zend.com'); + $this->message->addReplyTo('fw-announce@example.com'); $this->message->addReplyTo($list); $replyTo = $this->message->getReplyTo(); $this->assertEquals(2, count($replyTo)); - $this->assertTrue($replyTo->has('fw-announce@lists.zend.com')); - $this->assertTrue($replyTo->has('zf-devteam@zend.com')); + $this->assertTrue($replyTo->has('fw-announce@example.com')); + $this->assertTrue($replyTo->has('zf-devteam@example.com')); } public function testCanSetReplyToListFromAddressList() { $list = new AddressList(); - $list->add('zf-devteam@zend.com'); + $list->add('zf-devteam@example.com'); - $this->message->addReplyTo('fw-announce@lists.zend.com'); + $this->message->addReplyTo('fw-announce@example.com'); $this->message->setReplyTo($list); $replyTo = $this->message->getReplyTo(); $this->assertEquals(1, count($replyTo)); - $this->assertFalse($replyTo->has('fw-announce@lists.zend.com')); - $this->assertTrue($replyTo->has('zf-devteam@zend.com')); + $this->assertFalse($replyTo->has('fw-announce@example.com')); + $this->assertTrue($replyTo->has('zf-devteam@example.com')); } public function testSubjectIsEmptyByDefault() @@ -604,10 +604,10 @@ public function testEncodingIsMutable() public function testSettingNonAsciiEncodingForcesMimeEncodingOfSomeHeaders() { - $this->message->addTo('zf-devteam@zend.com', 'ZF DevTeam'); - $this->message->addFrom('matthew@zend.com', "Matthew Weier O'Phinney"); - $this->message->addCc('zf-contributors@lists.zend.com', 'ZF Contributors List'); - $this->message->addBcc('zf-crteam@lists.zend.com', 'ZF CR Team'); + $this->message->addTo('zf-devteam@example.com', 'ZF DevTeam'); + $this->message->addFrom('matthew@example.com', "Matthew Weier O'Phinney"); + $this->message->addCc('zf-contributors@example.com', 'ZF Contributors List'); + $this->message->addBcc('zf-crteam@example.com', 'ZF CR Team'); $this->message->setSubject('This is a subject'); $this->message->setEncoding('UTF-8'); @@ -615,19 +615,19 @@ public function testSettingNonAsciiEncodingForcesMimeEncodingOfSomeHeaders() $expected = '=?UTF-8?Q?ZF=20DevTeam?='; $this->assertContains($expected, $test); - $this->assertContains('', $test); + $this->assertContains('', $test); $expected = "=?UTF-8?Q?Matthew=20Weier=20O'Phinney?="; $this->assertContains($expected, $test, $test); - $this->assertContains('', $test); + $this->assertContains('', $test); $expected = '=?UTF-8?Q?ZF=20Contributors=20List?='; $this->assertContains($expected, $test); - $this->assertContains('', $test); + $this->assertContains('', $test); $expected = '=?UTF-8?Q?ZF=20CR=20Team?='; $this->assertContains($expected, $test); - $this->assertContains('', $test); + $this->assertContains('', $test); $expected = 'Subject: =?UTF-8?Q?This=20is=20a=20subject?='; $this->assertContains($expected, $test); @@ -650,9 +650,9 @@ public function testDefaultDateHeaderEncodingIsAlwaysAscii() public function testRestoreFromSerializedString() { - $this->message->addTo('zf-devteam@zend.com', 'ZF DevTeam'); - $this->message->addFrom('matthew@zend.com', "Matthew Weier O'Phinney"); - $this->message->addCc('zf-contributors@lists.zend.com', 'ZF Contributors List'); + $this->message->addTo('zf-devteam@example.com', 'ZF DevTeam'); + $this->message->addFrom('matthew@example.com', "Matthew Weier O'Phinney"); + $this->message->addCc('zf-contributors@example.com', 'ZF Contributors List'); $this->message->setSubject('This is a subject'); $this->message->setBody('foo'); $serialized = $this->message->toString(); From 80f12670d179c666a20dab8a91c58bf93db60d8a Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 13 Sep 2012 13:46:03 -0500 Subject: [PATCH 3/6] [zendframework/zf2#2333] Add todo annotation - Added @todo annotation so it's discoverable via API docs --- src/Message.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Message.php b/src/Message.php index 37f3866f..48137841 100644 --- a/src/Message.php +++ b/src/Message.php @@ -539,6 +539,7 @@ public function toString() /** * Instantiate from raw message string * + * @todo Restore body to Mime\Message * @param string $rawMessage * @return Message */ @@ -549,7 +550,7 @@ public static function fromString($rawMessage) $content = null; Mime\Decode::splitMessage($rawMessage, $headers, $content); if ($headers->has('mime-version')) { - // @todo restore body to mime\message + // todo - restore body to mime\message } $message->setHeaders($headers); $message->setBody($content); From fdd2938fd4349a8068c9502daf7c5fb327caaba1 Mon Sep 17 00:00:00 2001 From: Fernando Andre Date: Mon, 12 Nov 2012 00:31:45 -0200 Subject: [PATCH 4/6] rewrite connection code for a simpler view --- src/Protocol/Imap.php | 27 ++++++++++++++++++--------- src/Protocol/Pop3.php | 27 ++++++++++++++++++--------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php index a8527981..89819750 100644 --- a/src/Protocol/Imap.php +++ b/src/Protocol/Imap.php @@ -70,16 +70,25 @@ public function __destruct() */ public function connect($host, $port = null, $ssl = false) { - if ($ssl !== false) { - $ssl = strtoupper( $ssl ); - } + $isTls = false; - if ($ssl == 'SSL') { - $host = 'ssl://' . $host; + if ( $ssl !== false ) { + $ssl = strtolower($ssl); } - if ($port === null) { - $port = $ssl === 'SSL' ? 993 : 143; + switch ($ssl) { + case 'ssl': + $host = 'ssl://' . $host; + if (!$port) { + $port = 993; + } + break; + case 'tls': + $isTls = true; + default: + if ( !$port ) { + $port = 143; + } } ErrorHandler::start(); @@ -87,7 +96,7 @@ public function connect($host, $port = null, $ssl = false) $error = ErrorHandler::stop(); if (!$this->socket) { throw new Exception\RuntimeException(sprintf( - 'cannot connect to host%s', + 'cannot connect to host %s', ($error ? sprintf('; error = %s (errno = %d )', $error->getMessage(), $error->getCode()) : '') ), 0, $error); } @@ -96,7 +105,7 @@ public function connect($host, $port = null, $ssl = false) throw new Exception\RuntimeException('host doesn\'t allow connection'); } - if ($ssl === 'TLS') { + if ($isTls) { $result = $this->requestAndResponse('STARTTLS'); $result = $result && stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); if (!$result) { diff --git a/src/Protocol/Pop3.php b/src/Protocol/Pop3.php index 7c5ffdd5..ec2cc47c 100644 --- a/src/Protocol/Pop3.php +++ b/src/Protocol/Pop3.php @@ -78,16 +78,25 @@ public function __destruct() */ public function connect($host, $port = null, $ssl = false) { - if ($ssl !== false) { - $ssl = strtoupper($ssl); - } + $isTls = false; - if ($ssl == 'SSL') { - $host = 'ssl://' . $host; + if ($ssl !== false) { + $ssl = strtolower($ssl); } - if ($port === null) { - $port = $ssl == 'SSL' ? 995 : 110; + switch( $ssl ) { + case 'ssl': + $host = 'ssl://' . $host; + if ( !$port ) { + $port = 995; + } + break; + case 'tls': + $isTls = true; + default: + if ( !$port ) { + $port = 110; + } } ErrorHandler::start(); @@ -95,7 +104,7 @@ public function connect($host, $port = null, $ssl = false) $error = ErrorHandler::stop(); if (!$this->socket) { throw new Exception\RuntimeException(sprintf( - 'cannot connect to host%s', + 'cannot connect to host %s', ($error ? sprintf('; error = %s (errno = %d )', $error->getMessage(), $error->getCode()) : '') ), 0, $error); } @@ -110,7 +119,7 @@ public function connect($host, $port = null, $ssl = false) $this->timestamp = '<' . $this->timestamp . '>'; } - if ($ssl === 'TLS') { + if ($isTls === true) { $this->request('STLS'); $result = stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); if (!$result) { From b375918a9e08ca46d20a4ca240e612652863557a Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 12 Nov 2012 09:07:23 +0100 Subject: [PATCH 5/6] [zendframework/zf2#2936] Add comment about removed break --- src/Protocol/Imap.php | 5 +++-- src/Protocol/Pop3.php | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php index 89819750..65bd1b0f 100644 --- a/src/Protocol/Imap.php +++ b/src/Protocol/Imap.php @@ -72,7 +72,7 @@ public function connect($host, $port = null, $ssl = false) { $isTls = false; - if ( $ssl !== false ) { + if ($ssl) { $ssl = strtolower($ssl); } @@ -85,8 +85,9 @@ public function connect($host, $port = null, $ssl = false) break; case 'tls': $isTls = true; + // break intentionally omitted default: - if ( !$port ) { + if (!$port) { $port = 143; } } diff --git a/src/Protocol/Pop3.php b/src/Protocol/Pop3.php index ec2cc47c..220fe758 100644 --- a/src/Protocol/Pop3.php +++ b/src/Protocol/Pop3.php @@ -80,21 +80,22 @@ public function connect($host, $port = null, $ssl = false) { $isTls = false; - if ($ssl !== false) { + if ($ssl) { $ssl = strtolower($ssl); } - switch( $ssl ) { + switch ($ssl) { case 'ssl': $host = 'ssl://' . $host; - if ( !$port ) { + if (!$port) { $port = 995; } break; case 'tls': $isTls = true; + // break intentionally omitted default: - if ( !$port ) { + if (!$port) { $port = 110; } } @@ -119,7 +120,7 @@ public function connect($host, $port = null, $ssl = false) $this->timestamp = '<' . $this->timestamp . '>'; } - if ($isTls === true) { + if ($isTls) { $this->request('STLS'); $result = stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); if (!$result) { From 910a43ab6fd9e434cdc288bec506c57bf4810808 Mon Sep 17 00:00:00 2001 From: Jurgen Van de Moere Date: Thu, 3 Jan 2013 21:28:28 +0100 Subject: [PATCH 6/6] Revert "Added protected contentTypes array and requestHasContentType function" This reverts commit 9dfdefbf4c9d695bc0d2125c30571ae37ff95a89. --- test/_files/mail.txt | 54 +++---- test/_files/test.mbox/INBOX | 226 +++++++++++++-------------- test/_files/test.mbox/subfolder/test | 26 +-- 3 files changed, 153 insertions(+), 153 deletions(-) diff --git a/test/_files/mail.txt b/test/_files/mail.txt index 13ae2b3b..52587bac 100644 --- a/test/_files/mail.txt +++ b/test/_files/mail.txt @@ -1,27 +1,27 @@ -To: foo@example.com -Subject: multipart -Date: Sun, 01 Jan 2000 00:00:00 +0000 -From: =?UTF-8?Q?"Peter M=C3=BCller"?= -ContENT-type: multipart/alternative; boUNDary="crazy-multipart" -Message-ID: -MIME-version: 1.0 - -multipart message ---crazy-multipart -Content-type: text/plain - -The first part -is horizontal - ---crazy-multipart -Content-type: text/x-vertical - -T s p i v -h e a s e -e c r r - o t t - n i - d c - a - l ---crazy-multipart-- +To: foo@example.com +Subject: multipart +Date: Sun, 01 Jan 2000 00:00:00 +0000 +From: =?UTF-8?Q?"Peter M=C3=BCller"?= +ContENT-type: multipart/alternative; boUNDary="crazy-multipart" +Message-ID: +MIME-version: 1.0 + +multipart message +--crazy-multipart +Content-type: text/plain + +The first part +is horizontal + +--crazy-multipart +Content-type: text/x-vertical + +T s p i v +h e a s e +e c r r + o t t + n i + d c + a + l +--crazy-multipart-- diff --git a/test/_files/test.mbox/INBOX b/test/_files/test.mbox/INBOX index 151f6001..8499be13 100644 --- a/test/_files/test.mbox/INBOX +++ b/test/_files/test.mbox/INBOX @@ -1,114 +1,114 @@ -From next-message@example.com Mon Jan 00 00:00:00 0000 -Return-Path: -Delivered-To: to@example.com -Received: by example.com - id 1; Sun, 30 Apr 2006 19:00:00 +0200 (CEST) -Received: by localhost - id 1; Sun, 30 Apr 2006 19:10:00 +0200 (CEST) -To: to@example.com -Subject: Simple Message -Message-Id: <20060430185000.1@example.com> -Date: Sun, 30 Apr 2006 18:50:00 +0200 (CEST) -From: from@example.com - -This is a simple test message -From next-message@example.com Mon Jan 00 00:00:00 0000 -To: bar@example.com -Subject: A Really Simple Message -From: foo@example.com - -Message - -From next-message@example.com Mon Jan 00 00:00:00 0000 -To: river@example.com -Subject: To the River -Date: Sun, 01 Jan 1829 00:00:00 +0000 -From: poe@example.com -Message-Id: <18290101000000.0000@example.com> -Content-type: text/plain -MIME-version: 1.0 -X-Twin: the good -X-Twin: the evil - -Fair river! in thy bright, clear flow -Of crystal, wandering water, -Thou art an emblem of the glow -Of beautythe unhidden heart -The playful maziness of art -In old Alberto's daughter; - -But when within thy wave she looks -Which glistens then, and trembles -Why, then, the prettiest of brooks -Her worshipper resembles; -For in his heart, as in thy stream, -Her image deeply lies -His heart which trembles at the beam -Of her soul-searching eyes. - -From next-message@example.com Mon Jan 00 00:00:00 0000 -To: foo@example.com -Subject: multipart -Date: Sun, 01 Jan 2000 00:00:00 +0000 -From: crazy@example.com -Content-type: multipart/alternative; boundary="crazy-multipart" -MIME-version: 1.0 - -multipart message ---crazy-multipart -Content-type: text/plain - -The first part -is horizontal - ---crazy-multipart -Content-type: text/x-vertical - -T s p i v -h e a s e -e c r r - o t t - n i - d c - a - l ---crazy-multipart-- - -From next-message@example.com Mon Jan 00 00:00:00 0000 -To: foo@example.com -Subject: multipart -Date: Sun, 01 Jan 2000 01:00:00 +0000 -From: normal@example.com -Content-type: multipart/alternative; boundary="normal-multipart" -MIME-version: 1.0 - -multipart message ---normal-multipart -Content-type: text/html - - - -Again a simple message - ---normal-multipart -Content-type: text/plain - -Again a simple message ---normal-multipart-- -From next-message@example.com Mon Jan 00 00:00:00 0000 -To: foo@example.com -Subject: no body -Date: Sun, 01 Jan 2000 01:00:00 +0000 -From: short@example.com -From next-message@example.com Mon Jan 00 00:00:00 0000 -To: to@example.com -Subject: Dot Test -Date: Sun, 01 Jan 2000 01:00:00 +0000 -From: from@example.com - -Before the dot -. +From next-message@example.com Mon Jan 00 00:00:00 0000 +Return-Path: +Delivered-To: to@example.com +Received: by example.com + id 1; Sun, 30 Apr 2006 19:00:00 +0200 (CEST) +Received: by localhost + id 1; Sun, 30 Apr 2006 19:10:00 +0200 (CEST) +To: to@example.com +Subject: Simple Message +Message-Id: <20060430185000.1@example.com> +Date: Sun, 30 Apr 2006 18:50:00 +0200 (CEST) +From: from@example.com + +This is a simple test message +From next-message@example.com Mon Jan 00 00:00:00 0000 +To: bar@example.com +Subject: A Really Simple Message +From: foo@example.com + +Message + +From next-message@example.com Mon Jan 00 00:00:00 0000 +To: river@example.com +Subject: To the River +Date: Sun, 01 Jan 1829 00:00:00 +0000 +From: poe@example.com +Message-Id: <18290101000000.0000@example.com> +Content-type: text/plain +MIME-version: 1.0 +X-Twin: the good +X-Twin: the evil + +Fair river! in thy bright, clear flow +Of crystal, wandering water, +Thou art an emblem of the glow +Of beautythe unhidden heart +The playful maziness of art +In old Alberto's daughter; + +But when within thy wave she looks +Which glistens then, and trembles +Why, then, the prettiest of brooks +Her worshipper resembles; +For in his heart, as in thy stream, +Her image deeply lies +His heart which trembles at the beam +Of her soul-searching eyes. + +From next-message@example.com Mon Jan 00 00:00:00 0000 +To: foo@example.com +Subject: multipart +Date: Sun, 01 Jan 2000 00:00:00 +0000 +From: crazy@example.com +Content-type: multipart/alternative; boundary="crazy-multipart" +MIME-version: 1.0 + +multipart message +--crazy-multipart +Content-type: text/plain + +The first part +is horizontal + +--crazy-multipart +Content-type: text/x-vertical + +T s p i v +h e a s e +e c r r + o t t + n i + d c + a + l +--crazy-multipart-- + +From next-message@example.com Mon Jan 00 00:00:00 0000 +To: foo@example.com +Subject: multipart +Date: Sun, 01 Jan 2000 01:00:00 +0000 +From: normal@example.com +Content-type: multipart/alternative; boundary="normal-multipart" +MIME-version: 1.0 + +multipart message +--normal-multipart +Content-type: text/html + + + +Again a simple message + +--normal-multipart +Content-type: text/plain + +Again a simple message +--normal-multipart-- +From next-message@example.com Mon Jan 00 00:00:00 0000 +To: foo@example.com +Subject: no body +Date: Sun, 01 Jan 2000 01:00:00 +0000 +From: short@example.com +From next-message@example.com Mon Jan 00 00:00:00 0000 +To: to@example.com +Subject: Dot Test +Date: Sun, 01 Jan 2000 01:00:00 +0000 +From: from@example.com + +Before the dot +. is after the dot \ No newline at end of file diff --git a/test/_files/test.mbox/subfolder/test b/test/_files/test.mbox/subfolder/test index d9340968..c59490e4 100644 --- a/test/_files/test.mbox/subfolder/test +++ b/test/_files/test.mbox/subfolder/test @@ -1,14 +1,14 @@ -From next-message@example.com Mon Jan 00 00:00:00 0000 -Return-Path: -Delivered-To: to@example.com -Received: by example.com - id 1; Sun, 30 May 2006 19:00:00 +0200 (CEST) -Received: by localhost - id 1; Sun, 30 May 2006 19:10:00 +0200 (CEST) -To: to@example.com -Subject: Message in subfolder -Message-Id: <20060530185000.1@example.com> -Date: Sun, 30 May 2006 18:50:00 +0200 (CEST) -From: from@example.com - +From next-message@example.com Mon Jan 00 00:00:00 0000 +Return-Path: +Delivered-To: to@example.com +Received: by example.com + id 1; Sun, 30 May 2006 19:00:00 +0200 (CEST) +Received: by localhost + id 1; Sun, 30 May 2006 19:10:00 +0200 (CEST) +To: to@example.com +Subject: Message in subfolder +Message-Id: <20060530185000.1@example.com> +Date: Sun, 30 May 2006 18:50:00 +0200 (CEST) +From: from@example.com + This is the message in the subfolder \ No newline at end of file