summaryrefslogtreecommitdiffstats
path: root/lib/private/Mail
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-09-15 10:55:27 +0200
committerJoas Schilling <coding@schilljs.com>2017-10-18 15:12:03 +0200
commitc9af36a9ab05e808df526a2054c30364ee02241c (patch)
tree39c49dd14c53467c64685e6a154971997afa1d20 /lib/private/Mail
parent8b37fe7f6534ad16bd9a357036e95e748e2068e3 (diff)
downloadnextcloud-server-c9af36a9ab05e808df526a2054c30364ee02241c.tar.gz
nextcloud-server-c9af36a9ab05e808df526a2054c30364ee02241c.zip
Introduce a public interface for Message
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Mail')
-rw-r--r--lib/private/Mail/Mailer.php7
-rw-r--r--lib/private/Mail/Message.php15
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php
index 45405157d26..43fdb07b810 100644
--- a/lib/private/Mail/Mailer.php
+++ b/lib/private/Mail/Mailer.php
@@ -29,6 +29,7 @@ use OCP\IURLGenerator;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\ILogger;
+use OCP\Mail\IMessage;
/**
* Class Mailer provides some basic functions to create a mail message that can be used in combination with
@@ -84,7 +85,7 @@ class Mailer implements IMailer {
/**
* Creates a new message object that can be passed to send()
*
- * @return Message
+ * @return IMessage
*/
public function createMessage() {
return new Message(new \Swift_Message());
@@ -124,13 +125,13 @@ class Mailer implements IMailer {
* Send the specified message. Also sets the from address to the value defined in config.php
* if no-one has been passed.
*
- * @param Message $message Message to send
+ * @param IMessage|Message $message Message to send
* @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and
* therefore should be considered
* @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address
* has been supplied.)
*/
- public function send(Message $message) {
+ public function send(IMessage $message) {
$debugMode = $this->config->getSystemValue('mail_smtpdebug', false);
if (empty($message->getFrom())) {
diff --git a/lib/private/Mail/Message.php b/lib/private/Mail/Message.php
index 2d3c49d0ce1..b4d1e4dbe7a 100644
--- a/lib/private/Mail/Message.php
+++ b/lib/private/Mail/Message.php
@@ -23,6 +23,8 @@
namespace OC\Mail;
+use OCP\Mail\IEMailTemplate;
+use OCP\Mail\IMessage;
use Swift_Message;
/**
@@ -30,7 +32,7 @@ use Swift_Message;
*
* @package OC\Mail
*/
-class Message {
+class Message implements IMessage {
/** @var Swift_Message */
private $swiftMessage;
@@ -250,4 +252,15 @@ class Message {
$this->swiftMessage->setBody($body, $contentType);
return $this;
}
+
+ /**
+ * @param IEMailTemplate $emailTemplate
+ * @return $this
+ */
+ public function useTemplate(IEMailTemplate $emailTemplate) {
+ $this->setSubject($emailTemplate->renderSubject());
+ $this->setPlainBody($emailTemplate->renderText());
+ $this->setHtmlBody($emailTemplate->renderHtml());
+ return $this;
+ }
}