summaryrefslogtreecommitdiff
path: root/src/Mail/Transport/Transport.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-26 21:28:49 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-26 21:31:18 +0200
commit6187eed3bb08f200050a3078bd762b5731dfbe78 (patch)
tree06e0b08294c66449ed5f9f046a3bfe2097c7b4ad /src/Mail/Transport/Transport.php
parentbc5764b33ffc8a92dfa1d788ba2a204dd991c3d9 (diff)
parentd36de2d26f5af76d5d4f34f8620694c6d0368983 (diff)
Merge remote-tracking branch 'MyIgel/mailing'
Diffstat (limited to 'src/Mail/Transport/Transport.php')
-rw-r--r--src/Mail/Transport/Transport.php103
1 files changed, 103 insertions, 0 deletions
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 @@
+<?php
+
+namespace Engelsystem\Mail\Transport;
+
+use Swift_Events_EventListener;
+use Swift_Mime_SimpleMessage as SimpleMessage;
+use Swift_Transport as SwiftTransport;
+
+abstract class Transport implements SwiftTransport
+{
+ /**
+ * Test if this Transport mechanism has started.
+ *
+ * @return bool
+ */
+ public function isStarted(): bool
+ {
+ return true;
+ }
+
+ /**
+ * Start this Transport mechanism.
+ */
+ public function start() { }
+
+ /**
+ * Stop this Transport mechanism.
+ */
+ public function stop() { }
+
+ /**
+ * Check if this Transport mechanism is alive.
+ *
+ * If a Transport mechanism session is no longer functional, the method
+ * returns FALSE. It is the responsibility of the developer to handle this
+ * case and restart the Transport mechanism manually.
+ *
+ * @example
+ *
+ * if (!$transport->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);
+ }
+}