From 380701202f59ca003bd7afa2b08b7f31d836acc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 4 Oct 2020 07:09:19 +0200 Subject: [PATCH 01/12] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8c9e45b..2b1fef4 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,9 @@ "minimum-stability": "stable", "require": { "php": ">=5.5.0", - "nette/mail": "^2.3", + "nette/mail": "^2.3 || ^3.0", "tracy/tracy": "^2.3", - "nette/di": "^2.3", + "nette/di": "^2.3 || ^3.0", "guzzlehttp/guzzle": "^6.3" }, "require-dev": { From ea6a7320bddad34f08925b5eb1c9196a4858f697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 4 Oct 2020 10:01:43 +0200 Subject: [PATCH 02/12] Update AdtMailerExtension.php --- src/DI/AdtMailerExtension.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/DI/AdtMailerExtension.php b/src/DI/AdtMailerExtension.php index 45f838c..7f11c75 100644 --- a/src/DI/AdtMailerExtension.php +++ b/src/DI/AdtMailerExtension.php @@ -44,7 +44,7 @@ public function loadConfiguration() { ->setAutowired($config['autowireMailer']); } - public function validateConfig(array $expected, array $config = NULL, $name = NULL) { + public function validateConfig(array $expected, array $config = NULL, $name = NULL) : array { $config = parent::validateConfig($expected, $config, $name); if (empty($config['remote']['api'])) { @@ -72,5 +72,4 @@ public function validateConfig(array $expected, array $config = NULL, $name = NU return $config; } - } From af6779ff1a585656e67b44c7142495f4bddbb674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 4 Oct 2020 10:02:02 +0200 Subject: [PATCH 03/12] Update Mailer.php --- src/Services/Mailer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/Mailer.php b/src/Services/Mailer.php index c7696e3..c2d0459 100644 --- a/src/Services/Mailer.php +++ b/src/Services/Mailer.php @@ -13,8 +13,8 @@ public function __construct(Api $api) { $this->apiService = $api; } - function send(Message $mail) { + function send(Message $mail): void { $this->apiService->send($mail); } -} \ No newline at end of file +} From 73522061b6fb9995c47f48a6ff3d0988a427c8a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Lohnisk=C3=BD?= Date: Fri, 13 Nov 2020 23:54:04 +0100 Subject: [PATCH 04/12] remote.key can be method --- README.md | 5 +++ src/DI/AdtMailerExtension.php | 4 +- src/Services/Api.php | 71 +++++++++++++++++++---------------- 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 82f8da7..3504e69 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,18 @@ extensions: adtMailer: remote: api: yourAdtMailApiInstance.com:1234 + + # can be either static string or method, required key: yourPrivateKey + error: # mode: silent => log and continue # mode: exception => throw mode: silent + # all undelivered messages are stored here (applies to mode: silent) logDir: %logDir%/adt_mailer + # if recipient is suppressed, this address receives notification and delist link # can be either static string or method, required suppressionControlAddress: @App\Model\SuppressionControl::decide diff --git a/src/DI/AdtMailerExtension.php b/src/DI/AdtMailerExtension.php index 9d6193a..49a7745 100644 --- a/src/DI/AdtMailerExtension.php +++ b/src/DI/AdtMailerExtension.php @@ -51,8 +51,8 @@ public function validateConfig(array $expected, array $config = NULL, $name = NU throw new \Nette\UnexpectedValueException('Specify remote API endpoint.'); } - if (empty($config['remote']['key'])) { - throw new \Nette\UnexpectedValueException('Specify authentication key.'); + if (empty($config['remote']['key']) || !(is_string($config['remote']['key']) || is_callable($config['remote']['key']))) { + throw new \Nette\UnexpectedValueException('Specify authentication key as string or method (e.g. @ServiceClass::method).'); } if (!in_array($config['error']['mode'], static::errorModes(), TRUE)) { diff --git a/src/Services/Api.php b/src/Services/Api.php index 174cb14..215fc4b 100644 --- a/src/Services/Api.php +++ b/src/Services/Api.php @@ -18,6 +18,44 @@ class Api { public function __construct(array $config, \Tracy\ILogger $logger) { $this->logger = $logger; $this->config = $config; + } + + protected function getSuppressionControlAddress(\Nette\Mail\Message $mail) { + return $this->processCallableOption($this->config['suppressionControlAddress'], $mail); + } + + protected function getRemoteKey(\Nette\Mail\Message $mail) { + return $this->processCallableOption($this->config['ip_pool'], $mail); + } + + protected function processCallableOption($value, \Nette\Mail\Message $mail) { + if (is_callable($value, FALSE)) { + return $value($mail); + } else { + return $value; + } + } + + /** + * @param \Nette\Mail\Message $mail + * @return array + */ + protected function serializeMessage(\Nette\Mail\Message $mail) { + $result = [ + 'from' => $mail->getFrom(), + 'subject' => $mail->getSubject(), + 'message' => $mail->generateMessage(), + 'suppressionControlAddress' => $this->getSuppressionControlAddress($mail), + ]; + + foreach ([ 'to', 'cc', 'bcc' ] as $header) { + $result[$header] = $mail->getHeader(ucfirst($header)); + } + + return $result; + } + + public function send(\Nette\Mail\Message $mail) { $this->curl = curl_init(); // set remote URL @@ -25,7 +63,7 @@ public function __construct(array $config, \Tracy\ILogger $logger) { curl_setopt( $this->curl, CURLOPT_URL, - $endPoint . '/mail/send?key=' . $this->config['remote']['key'] + $endPoint . '/mail/send?key=' . $this->getRemoteKey() ); // do not wait more than 3s @@ -51,38 +89,7 @@ public function __construct(array $config, \Tracy\ILogger $logger) { // do not display result curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE); - } - - protected function getSuppressionControlAddress(\Nette\Mail\Message $mail) { - $address = $this->config['suppressionControlAddress']; - if (is_callable($address, FALSE)) { - return $address($mail); - } else { - return $address; - } - } - - /** - * @param \Nette\Mail\Message $mail - * @return array - */ - protected function serializeMessage(\Nette\Mail\Message $mail) { - $result = [ - 'from' => $mail->getFrom(), - 'subject' => $mail->getSubject(), - 'message' => $mail->generateMessage(), - 'suppressionControlAddress' => $this->getSuppressionControlAddress($mail), - ]; - - foreach ([ 'to', 'cc', 'bcc' ] as $header) { - $result[$header] = $mail->getHeader(ucfirst($header)); - } - - return $result; - } - - public function send(\Nette\Mail\Message $mail) { $postData = \Nette\Utils\Json::encode($this->serializeMessage($mail)); // set message From bef28ba9cd960b74b2dd73f8589c7c51279002e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Lohnisk=C3=BD?= Date: Tue, 17 Nov 2020 02:27:47 +0100 Subject: [PATCH 05/12] remote.key can be method typos --- src/Services/Api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/Api.php b/src/Services/Api.php index 215fc4b..68689ac 100644 --- a/src/Services/Api.php +++ b/src/Services/Api.php @@ -25,7 +25,7 @@ protected function getSuppressionControlAddress(\Nette\Mail\Message $mail) { } protected function getRemoteKey(\Nette\Mail\Message $mail) { - return $this->processCallableOption($this->config['ip_pool'], $mail); + return $this->processCallableOption($this->config['remote']['key'], $mail); } protected function processCallableOption($value, \Nette\Mail\Message $mail) { @@ -63,7 +63,7 @@ public function send(\Nette\Mail\Message $mail) { curl_setopt( $this->curl, CURLOPT_URL, - $endPoint . '/mail/send?key=' . $this->getRemoteKey() + $endPoint . '/mail/send?key=' . $this->getRemoteKey($mail) ); // do not wait more than 3s From 885f544936e994cdec8423d9cba7a8372e93efae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Fri, 26 Mar 2021 09:36:11 +0100 Subject: [PATCH 06/12] Update AdtMailerExtension.php --- src/DI/AdtMailerExtension.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/DI/AdtMailerExtension.php b/src/DI/AdtMailerExtension.php index c313d18..a2324e0 100644 --- a/src/DI/AdtMailerExtension.php +++ b/src/DI/AdtMailerExtension.php @@ -65,10 +65,6 @@ public function validateConfig(array $expected, array $config = NULL, $name = NU throw new \Nette\UnexpectedValueException('Specify mail log directory.'); } - if (empty($config['suppressionControlAddress']) || !(is_string($config['suppressionControlAddress']) || is_callable(array_map(function($value) { return ltrim($value, '@'); }, $config['suppressionControlAddress'])))) { - throw new \Nette\UnexpectedValueException('Specify suppression control address as string or method (e.g. @ServiceClass::method).'); - } - return $config; } From 95dd2832bdf2fb7e7d0a456f1f2e4d1b05c540ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Fri, 26 Mar 2021 09:56:58 +0100 Subject: [PATCH 07/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3504e69..c9e63b5 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ adtMailer: logDir: %logDir%/adt_mailer # if recipient is suppressed, this address receives notification and delist link - # can be either static string or method, required + # can be either an email address, url or a callback returning an email address or url suppressionControlAddress: @App\Model\SuppressionControl::decide ``` From 4acdc1fc2619d9313c534faa0b677c2e746bfcba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Lohnisk=C3=BD?= Date: Fri, 26 Mar 2021 14:56:23 +0100 Subject: [PATCH 08/12] Update AdtMailerExtension.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit V této chvíli je to ještě pole 2 stringů, ale callable to ještě není. --- src/DI/AdtMailerExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DI/AdtMailerExtension.php b/src/DI/AdtMailerExtension.php index a2324e0..0f1bee0 100644 --- a/src/DI/AdtMailerExtension.php +++ b/src/DI/AdtMailerExtension.php @@ -51,8 +51,8 @@ public function validateConfig(array $expected, array $config = NULL, $name = NU throw new \Nette\UnexpectedValueException('Specify remote API endpoint.'); } - if (empty($config['remote']['key']) || !(is_string($config['remote']['key']) || is_callable($config['remote']['key']))) { - throw new \Nette\UnexpectedValueException('Specify authentication key as string or method (e.g. @ServiceClass::method).'); + if (empty($config['remote']['key']) || !(is_string($config['remote']['key']) || is_array($config['remote']['key']))) { + throw new \Nette\UnexpectedValueException('Specify authentication key as string or method (e.g. [@ServiceClass, method]).'); } if (!in_array($config['error']['mode'], static::errorModes(), TRUE)) { From d40dc0d7c971173a1e6bdb70ccecc9172ac936de Mon Sep 17 00:00:00 2001 From: Marek Valuch Date: Mon, 28 Feb 2022 15:22:39 +0100 Subject: [PATCH 09/12] Guzzle ^7.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 937eeb7..6667240 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "nette/mail": "^2.3 || ^3.0", "tracy/tracy": "^2.3", "nette/di": "^2.3 || ^3.0", - "guzzlehttp/guzzle": "^6.3" + "guzzlehttp/guzzle": "^6.3|^7.0" }, "require-dev": { }, From e86df41126094f6fbfe56d208255d1811ca86d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1?= Date: Thu, 5 Jan 2023 11:36:03 +0100 Subject: [PATCH 10/12] Support header Reply-To --- src/Services/Api.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Services/Api.php b/src/Services/Api.php index bc1569e..ce748de 100644 --- a/src/Services/Api.php +++ b/src/Services/Api.php @@ -50,6 +50,10 @@ protected function serializeMessage(\Nette\Mail\Message $mail) { $result[$header] = $mail->getHeader(ucfirst($header)); } + if ($mail->getHeader('Reply-To') !== null) { + $result['reply-to'] = $mail->getHeader('Reply-To'); + } + return $result; } @@ -106,4 +110,4 @@ public function send(\Nette\Mail\Message $mail) { } class ApiException extends \Nette\IOException { -} \ No newline at end of file +} From 3cd183cac585c40fc53107999e9c54e22c92ef46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 28 May 2023 07:54:23 +0200 Subject: [PATCH 11/12] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 6667240..8219025 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "minimum-stability": "stable", "require": { - "php": ">=7.1", - "nette/mail": "^2.3 || ^3.0", + "php": ">=7.4", + "nette/mail": "^2.3 | ^3.0 | ^4.0", "tracy/tracy": "^2.3", "nette/di": "^2.3 || ^3.0", "guzzlehttp/guzzle": "^6.3|^7.0" From 40dccd0fb51f790b15a0c73eed95f741ded794f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 26 Jan 2025 13:22:47 +0100 Subject: [PATCH 12/12] Update AdtMailerExtension.php --- src/DI/AdtMailerExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DI/AdtMailerExtension.php b/src/DI/AdtMailerExtension.php index 0f1bee0..d9d3af7 100644 --- a/src/DI/AdtMailerExtension.php +++ b/src/DI/AdtMailerExtension.php @@ -44,7 +44,7 @@ public function loadConfiguration() { ->setAutowired($config['autowireMailer']); } - public function validateConfig(array $expected, array $config = NULL, $name = NULL): array { + public function validateConfig(array $expected, ?array $config = NULL, $name = NULL): array { $config = parent::validateConfig($expected, $config, $name); if (empty($config['remote']['api'])) {