From 52fa8113d87c56a8260aa6f27b87340ccc5834ed Mon Sep 17 00:00:00 2001 From: Ameir Abdeldayem Date: Fri, 13 Nov 2015 18:57:08 -0500 Subject: [PATCH 1/6] Support returning IMAP delimiter. --- src/Storage/Imap.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Storage/Imap.php b/src/Storage/Imap.php index 240c3692..c6ed8b55 100644 --- a/src/Storage/Imap.php +++ b/src/Storage/Imap.php @@ -29,6 +29,12 @@ class Imap extends AbstractStorage implements Folder\FolderInterface, Writable\W */ protected $currentFolder = ''; + /** + * IMAP folder delimiter character + * @var string + */ + protected $delimiter; + /** * IMAP flags to constants translation * @var array @@ -331,6 +337,7 @@ public function getFolders($rootFolder = null) $parentFolder->$localName = $folder; array_push($folderStack, $parentFolder); $parentFolder = $folder; + $this->delimiter = $data['delim']; break; } elseif ($stack) { $parent = array_pop($stack); @@ -504,4 +511,17 @@ public function setFlags($id, $flags) throw new Exception\RuntimeException('cannot set flags, have you tried to set the recent flag or special chars?'); } } + + /** + * get IMAP delimiter + * + * @return string|null + */ + public function delimiter() + { + if (!isset($this->delimiter)) { + $this->getFolders(); + } + return $this->delimiter; + } } From 1863c83b592cbc7937d2cdc7e71f2e74888b504e Mon Sep 17 00:00:00 2001 From: Ameir Abdeldayem Date: Sun, 10 Apr 2016 14:13:10 -0400 Subject: [PATCH 2/6] Add test for IMAP delimiter. --- test/Storage/ImapTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/Storage/ImapTest.php b/test/Storage/ImapTest.php index d30becf9..9111b82f 100644 --- a/test/Storage/ImapTest.php +++ b/test/Storage/ImapTest.php @@ -697,4 +697,11 @@ public function testCountFlags() $this->assertEquals($mail->countMessages([Storage::FLAG_SEEN, Storage::FLAG_FLAGGED]), 0); $this->assertEquals($mail->countMessages(Storage::FLAG_FLAGGED), 0); } + + public function testDelimiter() + { + $mail = new Storage\Imap($this->params); + $delimiter = $mail->delimiter(); + $this->assertEquals(strlen($delimiter), 1); + } } From 46d52dbd5ff581605bee5da9239d7cc5977245d0 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Apr 2016 14:10:46 -0500 Subject: [PATCH 3/6] Incorporated feedback - `$delimiter` can be either a string OR null. --- src/Storage/Imap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Imap.php b/src/Storage/Imap.php index 6504d89a..334910ee 100644 --- a/src/Storage/Imap.php +++ b/src/Storage/Imap.php @@ -31,7 +31,7 @@ class Imap extends AbstractStorage implements Folder\FolderInterface, Writable\W /** * IMAP folder delimiter character - * @var string + * @var null|string */ protected $delimiter; From 4fbf655f1b3a785e86cdadacac95a5fc62ddf817 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Apr 2016 14:11:36 -0500 Subject: [PATCH 4/6] Added CHANGELOG for #41 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c2d4866..15947151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ All notable changes to this project will be documented in this file, in reverse ### Added -- Nothing. +- [#41](https://github.com/zendframework/zend-mail/pull/41) adds support for + IMAP delimiters in the IMAP storage adapter. ### Deprecated From 76885ce0f0daab1761f0d337fe46648f747cb1ba Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Apr 2016 15:21:00 -0500 Subject: [PATCH 5/6] Prepare standalone package Adds: - `Zend\Mail\Protocol\SmtpPluginManagerFactory`, for creating and returning an `SmtpPluginManagerFactory` instance. - `Zend\Mail\ConfigProvider`, which maps the `SmtpPluginManager` service to the above factory. - `Zend\Mail\Module`, which does the same, for a zend-mvc context. --- composer.json | 4 + src/ConfigProvider.php | 37 ++++++++++ src/Module.php | 24 ++++++ src/Protocol/SmtpPluginManager.php | 2 +- src/Protocol/SmtpPluginManagerFactory.php | 53 ++++++++++++++ .../Protocol/SmtpPluginManagerFactoryTest.php | 73 +++++++++++++++++++ 6 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 src/ConfigProvider.php create mode 100644 src/Module.php create mode 100644 src/Protocol/SmtpPluginManagerFactory.php create mode 100644 test/Protocol/SmtpPluginManagerFactoryTest.php diff --git a/composer.json b/composer.json index 4275fdfd..47b2f9c4 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,10 @@ "branch-alias": { "dev-master": "2.6-dev", "dev-develop": "2.7-dev" + }, + "zf": { + "component": "Zend\\Mail", + "config-provider": "Zend\\Mail\\ConfigProvider" } }, "autoload-dev": { diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php new file mode 100644 index 00000000..06d3b6f0 --- /dev/null +++ b/src/ConfigProvider.php @@ -0,0 +1,37 @@ + $this->getDependencyConfig(), + ]; + } + + /** + * Retrieve dependency settings for zend-mail package. + * + * @return array + */ + public function getDependencyConfig() + { + return [ + 'factories' => [ + Protocol\SmtpPluginManager::class => Protocol\SmtpPluginManagerFactory::class, + ], + ]; + } +} diff --git a/src/Module.php b/src/Module.php new file mode 100644 index 00000000..2ad6674d --- /dev/null +++ b/src/Module.php @@ -0,0 +1,24 @@ + $provider->getDependencyConfig(), + ]; + } +} diff --git a/src/Protocol/SmtpPluginManager.php b/src/Protocol/SmtpPluginManager.php index a03ec7c9..c0160361 100644 --- a/src/Protocol/SmtpPluginManager.php +++ b/src/Protocol/SmtpPluginManager.php @@ -55,7 +55,7 @@ class SmtpPluginManager extends AbstractPluginManager 'zendmailprotocolsmtpauthcrammd5' => InvokableFactory::class, 'zendmailprotocolsmtpauthlogin' => InvokableFactory::class, 'zendmailprotocolsmtpauthplain' => InvokableFactory::class, - 'zendmailprotocolsmtp' => InvokableFactory::class, + 'zendmailprotocolsmtp' => InvokableFactory::class, ]; /** diff --git a/src/Protocol/SmtpPluginManagerFactory.php b/src/Protocol/SmtpPluginManagerFactory.php new file mode 100644 index 00000000..be10a96a --- /dev/null +++ b/src/Protocol/SmtpPluginManagerFactory.php @@ -0,0 +1,53 @@ +creationOptions); + } + + /** + * zend-servicemanager v2 support for invocation options. + * + * @param array $options + * @return void + */ + public function setCreationOptions(array $options) + { + $this->creationOptions = $options; + } +} diff --git a/test/Protocol/SmtpPluginManagerFactoryTest.php b/test/Protocol/SmtpPluginManagerFactoryTest.php new file mode 100644 index 00000000..145bd52f --- /dev/null +++ b/test/Protocol/SmtpPluginManagerFactoryTest.php @@ -0,0 +1,73 @@ +prophesize(ContainerInterface::class)->reveal(); + $factory = new SmtpPluginManagerFactory(); + + $plugins = $factory($container, SmtpPluginManager::class); + $this->assertInstanceOf(SmtpPluginManager::class, $plugins); + + if (method_exists($plugins, 'configure')) { + // zend-servicemanager v3 + $this->assertAttributeSame($container, 'creationContext', $plugins); + } else { + // zend-servicemanager v2 + $this->assertSame($container, $plugins->getServiceLocator()); + } + } + + /** + * @depends testFactoryReturnsPluginManager + */ + public function testFactoryConfiguresPluginManagerUnderContainerInterop() + { + $container = $this->prophesize(ContainerInterface::class)->reveal(); + $smtp = $this->prophesize(Smtp::class)->reveal(); + + $factory = new SmtpPluginManagerFactory(); + $plugins = $factory($container, SmtpPluginManager::class, [ + 'services' => [ + 'test' => $smtp, + ], + ]); + $this->assertSame($smtp, $plugins->get('test')); + } + + /** + * @depends testFactoryReturnsPluginManager + */ + public function testFactoryConfiguresPluginManagerUnderServiceManagerV2() + { + $container = $this->prophesize(ServiceLocatorInterface::class); + $container->willImplement(ContainerInterface::class); + + $smtp = $this->prophesize(Smtp::class)->reveal(); + + $factory = new SmtpPluginManagerFactory(); + $factory->setCreationOptions([ + 'services' => [ + 'test' => $smtp, + ], + ]); + + $plugins = $factory->createService($container->reveal()); + $this->assertSame($smtp, $plugins->get('test')); + } +} From cd2c323afe0d97d5171befbaba985f1da973ec2e Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Apr 2016 15:31:13 -0500 Subject: [PATCH 6/6] Added CHANGELOG for #80 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 765c4746..74cd8c01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file, in reverse - [#41](https://github.com/zendframework/zend-mail/pull/41) adds support for IMAP delimiters in the IMAP storage adapter. +- [#80](https://github.com/zendframework/zend-mail/pull/80) adds: + - `Zend\Mail\Protocol\SmtpPluginManagerFactory`, for creating and returning an + `SmtpPluginManagerFactory` instance. + - `Zend\Mail\ConfigProvider`, which maps the `SmtpPluginManager` to the above + factory. + - `Zend\Mail\Module`, which does the same, for zend-mvc contexts. ### Deprecated