From 01e9c22695a3e495f07ab445750221af72e09fe4 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 5 Sep 2018 13:40:03 +0200 Subject: Implemented mailing abstraction Closes #434 --- src/Mail/Transport/Transport.php | 103 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/Mail/Transport/Transport.php (limited to 'src/Mail/Transport/Transport.php') diff --git a/src/Mail/Transport/Transport.php b/src/Mail/Transport/Transport.php new file mode 100644 index 00000000..691faf60 --- /dev/null +++ b/src/Mail/Transport/Transport.php @@ -0,0 +1,103 @@ +ping()) { + * $transport->stop(); + * $transport->start(); + * } + * + * The Transport mechanism will be started, if it is not already. + * + * It is undefined if the Transport mechanism attempts to restart as long as + * the return value reflects whether the mechanism is now functional. + * + * @return bool TRUE if the transport is alive + */ + public function ping(): bool + { + return true; + } + + /** + * Register a plugin in the Transport. + * + * @param Swift_Events_EventListener $plugin + */ + public function registerPlugin(Swift_Events_EventListener $plugin) { } + + /** + * Returns a unified list of all recipients + * + * @param SimpleMessage $message + * @return array + */ + protected function allRecipients(SimpleMessage $message): array + { + return array_merge( + (array)$message->getTo(), + (array)$message->getCc(), + (array)$message->getBcc() + ); + } + + /** + * Returns a concatenated list of mail recipients + * + * @param SimpleMessage $message + * @return string + */ + protected function getTo(SimpleMessage $message): string + { + return $this->formatTo($this->allRecipients($message)); + } + + /** + * @param array $recipients + * @return string + */ + protected function formatTo(array $recipients) + { + $list = []; + foreach ($recipients as $address => $name) { + $list[] = $name ? sprintf('%s <%s>', $name, $address) : $address; + } + + return implode(',', $list); + } +} -- cgit v1.2.3-54-g00ecf