Skip to content
Permalink
Browse files

MailExtension: added support for Signer

  • Loading branch information...
dg committed Jun 3, 2019
1 parent 34ae057 commit 65b6e63a0b60445945f679adefa5c2b9eb143609
Showing with 51 additions and 0 deletions.
  1. +22 −0 src/Bridges/MailDI/MailExtension.php
  2. +14 −0 tests/Mail.DI/Mail.extension.phpt
  3. +15 −0 tests/Mail.DI/fixtures/private.key
@@ -31,6 +31,16 @@ public function getConfigSchema(): Nette\Schema\Schema
'context' => Expect::arrayOf('array')->dynamic(),
'clientHost' => Expect::string()->dynamic(),
'persistent' => Expect::bool(false)->dynamic(),
'dkim' => Expect::anyOf(
Expect::null(),
Expect::structure([
'domain' => Expect::string()->dynamic(),
'selector' => Expect::string()->dynamic(),
'privateKey' => Expect::string()->dynamic()->required(),
'passPhrase' => Expect::string()->dynamic(),
'testMode' => Expect::bool(false)->dynamic(),
])->castTo('array')
),
])->castTo('array');
}
@@ -42,6 +52,18 @@ public function loadConfiguration()
$mailer = $builder->addDefinition($this->prefix('mailer'))
->setType(Nette\Mail\Mailer::class);
if ($this->config['dkim']) {
$dkim = $this->config['dkim'];
$dkim['privateKey'] = file_get_contents($dkim['privateKey']);
unset($this->config['dkim']);
$signer = $builder->addDefinition($this->prefix('signer'))
->setType(Nette\Mail\Signer::class)
->setFactory(Nette\Mail\DkimSigner::class, [$dkim]);
$mailer->addSetup('setSigner', [$signer]);
}
if ($this->config['smtp']) {
$mailer->setFactory(Nette\Mail\SmtpMailer::class, [$this->config]);
} else {
@@ -23,6 +23,7 @@ test:
smtp: false
');
Assert::type(Nette\Mail\SendmailMailer::class, $container1->getService('test.mailer'));
Assert::false($container1->hasService('test.signer'));
Assert::false($container1->hasService('nette.mailer'));
@@ -34,3 +35,16 @@ mail:
');
Assert::type(Nette\Mail\SmtpMailer::class, $container2->getService('mail.mailer'));
Assert::type($container2->getService('mail.mailer'), $container2->getService('nette.mailer'));
Assert::false($container2->hasService('mail.signer'));
$compiler = new DI\Compiler;
$compiler->addExtension('mail', new MailExtension);
$container3 = createContainer($compiler, '
mail:
smtp: true
dkim:
privateKey: fixtures/private.key
');
Assert::type(Nette\Mail\DkimSigner::class, $container3->getService('mail.signer'));
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCxDQWcHZB2hO5GNSaj7CUVbCw+wkRBZ9xtNCHqrWwqaUozqWkw
50XEe5gtnvjPix3zmOKJQVY15bYIrgRsnHsbMA2TUSZZyYgCpeypSq7Mvp79H1ZF
dHlVRUbjzgLzOAko7Yg3F7vwMS2SWAwZxRttCkDmQyMO0tn2kRE5ZJhFTQIDAQAB
AoGBAJ3mTyp782rAAwD6RgvLfwcsAgm2l8j9J8j8xYLWR7FLVbHdVMMYf1BMKdwF
+0CdgYjOwLpIWuqWg1IaYDe9FswcvAVLvFmbkmbt40oWD0v67SVxITXjjKmaA6yL
TF0QqVp7Wo2Rppi4K0A5JaK9FnsbWygGwdtNmz518Pc5JngBAkEA1xEqnzjAXFB5
4egCaKj3uGpVfGelUFvIlFrxoLSrvZ4NSp0XdrR/lzBB/TsMi/WkZpPeeQUTy+bq
GcIdXYc9IQJBANK/kjfXtg3tK0dNW/9GXcZA2Nb40475rnCruXy8nhv+S8KkccdY
IDnSvSs1ALy3X3Ew+aAGtIeWJAHttihvNq0CQQCTrQTwSd7ERLo8Zbxps0ROTC2g
++Zm1G9Zd00dRZH75PBJgK7g4rYN0aQuRwKphCW8DeMghF0AkPHEeCcD1t4hAkBM
75y8gCY5HU0AYbBlF9YiCwheKkZpWqMhBL/ZVq5Nv97+drQGtxhEo7dlb5sOSc8w
7lUi42/CU8BfZ91pE3idAkB4CvSZyTfH5MTM+ta7oQGq/HGMCB+nIOdy6OZ28nGA
FAXmcXdM0CjhOg4Xnf07+X5iKyXZQ17ErPJgh/L1Ih/O
-----END RSA PRIVATE KEY-----

0 comments on commit 65b6e63

Please sign in to comment.
You can’t perform that action at this time.