summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-03-17 11:15:39 +0100
committerLukas Reschke <lukas@owncloud.com>2015-03-17 11:15:39 +0100
commitb1c19f74a1d245bd8a4a807e73bbe58860d55314 (patch)
tree250b6b85573a01ee5677b1c99d73d0e2d13d32bd /lib/public
parent65259114391eaeab1f6ceb44e52e2c0a5efa9027 (diff)
parent7a70fffa6cd1597e588111cd39054b80adf296c0 (diff)
downloadnextcloud-server-b1c19f74a1d245bd8a4a807e73bbe58860d55314.tar.gz
nextcloud-server-b1c19f74a1d245bd8a4a807e73bbe58860d55314.zip
Merge pull request #12085 from owncloud/add-swift-mailer
Migrate OC_Mail to SwiftMailer
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/iservercontainer.php8
-rw-r--r--lib/public/mail/imailer.php57
-rw-r--r--lib/public/util.php39
3 files changed, 98 insertions, 6 deletions
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index ec23cc52345..20345e61212 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -318,9 +318,15 @@ interface IServerContainer {
* @return \bantu\IniGetWrapper\IniGetWrapper
*/
function getIniWrapper();
-
/**
* @return \OCP\Command\IBus
*/
function getCommandBus();
+
+ /**
+ * Creates a new mailer
+ *
+ * @return \OCP\Mail\IMailer
+ */
+ function getMailer();
}
diff --git a/lib/public/mail/imailer.php b/lib/public/mail/imailer.php
new file mode 100644
index 00000000000..dc6fe5ba869
--- /dev/null
+++ b/lib/public/mail/imailer.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Mail;
+use OC\Mail\Message;
+
+/**
+ * Class IMailer provides some basic functions to create a mail message that can be used in combination with
+ * \OC\Mail\Message.
+ *
+ * Example usage:
+ *
+ * $mailer = \OC::$server->getMailer();
+ * $message = $mailer->createMessage();
+ * $message->setSubject('Your Subject');
+ * $message->setFrom(array('cloud@domain.org' => 'ownCloud Notifier');
+ * $message->setTo(array('recipient@domain.org' => 'Recipient');
+ * $message->setBody('The message text');
+ * $mailer->send($message);
+ *
+ * This message can then be passed to send() of \OC\Mail\Mailer
+ *
+ * @package OCP\Mail
+ */
+interface IMailer {
+ /**
+ * Creates a new message object that can be passed to send()
+ *
+ * @return Message
+ */
+ public function createMessage();
+
+ /**
+ * 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
+ * @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);
+
+ /**
+ * Checks if an e-mail address is valid
+ *
+ * @param string $email Email address to be validated
+ * @return bool True if the mail address is valid, false otherwise
+ */
+ public function validateMailAddress($email);
+}
diff --git a/lib/public/util.php b/lib/public/util.php
index aa6cd5ba012..5efdcc55de4 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -63,12 +63,40 @@ class Util {
* @param string $ccaddress
* @param string $ccname
* @param string $bcc
+ * @deprecated Use \OCP\Mail\IMailer instead
*/
- public static function sendMail( $toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname,
+ public static function sendMail($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname,
$html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '') {
- // call the internal mail class
- \OC_MAIL::send($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname,
- $html, $altbody, $ccaddress, $ccname, $bcc);
+ $mailer = \OC::$server->getMailer();
+ $message = $mailer->createMessage();
+ $message->setTo([$toaddress => $toname]);
+ $message->setSubject($subject);
+ $message->setPlainBody($mailtext);
+ $message->setFrom([$fromaddress => $fromname]);
+ if($html === 1) {
+ $message->setHTMLBody($altbody);
+ }
+
+ if($altbody === '') {
+ $message->setHTMLBody($mailtext);
+ $message->setPlainBody('');
+ } else {
+ $message->setHtmlBody($mailtext);
+ $message->setPlainBody($altbody);
+ }
+
+ if(!empty($ccaddress)) {
+ if(!empty($ccname)) {
+ $message->setCc([$ccaddress => $ccname]);
+ } else {
+ $message->setCc([$ccaddress]);
+ }
+ }
+ if(!empty($bcc)) {
+ $message->setBcc([$bcc]);
+ }
+
+ $mailer->send($message);
}
/**
@@ -275,7 +303,8 @@ class Util {
$host_name = \OC_Config::getValue('mail_domain', $host_name);
$defaultEmailAddress = $user_part.'@'.$host_name;
- if (\OC_Mail::validateAddress($defaultEmailAddress)) {
+ $mailer = \OC::$server->getMailer();
+ if ($mailer->validateMailAddress($defaultEmailAddress)) {
return $defaultEmailAddress;
}