diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-04-11 17:35:46 +0300 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2017-04-11 17:35:46 +0300 |
commit | 3600dd4f5295b67eaad3cbd503675e9bd9c679aa (patch) | |
tree | 56b33722ac6ae7cdb9b56d053633884c9e49739d /lib/public/Mail | |
parent | bd6273ee1c803b8a129fb76135ca23377805da9e (diff) |
Add IEMailTemplate to public OCP API
Also adds `\OCP\Mail\IMailer::createEMailTemplate` as helper so the functionality can easily be used within apps.
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/public/Mail')
-rw-r--r-- | lib/public/Mail/IEMailTemplate.php | 128 | ||||
-rw-r--r-- | lib/public/Mail/IMailer.php | 8 |
2 files changed, 136 insertions, 0 deletions
diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php new file mode 100644 index 00000000000..1a940348b1d --- /dev/null +++ b/lib/public/Mail/IEMailTemplate.php @@ -0,0 +1,128 @@ +<?php +/** + * @copyright 2017, Morris Jobke <hey@morrisjobke.de> + * + * @author Morris Jobke <hey@morrisjobke.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Mail; + +/** + * Interface IEMailTemplate + * + * Interface to a class that allows to build HTML emails + * + * Example: + * + * <?php + * + * $emailTemplate = new EMailTemplate($this->defaults, $this->urlGenerator, $this->l10n); + * + * $emailTemplate->addHeader(); + * $emailTemplate->addHeading('Welcome aboard'); + * $emailTemplate->addBodyText('You have now an Nextcloud account, you can add, protect, and share your data.'); + * + * $emailTemplate->addBodyButtonGroup( + * 'Set your password', 'https://example.org/resetPassword/q1234567890qwertz', + * 'Install Client', 'https://nextcloud.com/install/#install-clients' + * ); + * + * $emailTemplate->addFooter('Optional footer text'); + * + * $htmlContent = $emailTemplate->renderHTML(); + * $plainContent = $emailTemplate->renderText(); + * + * @since 12.0.0 + */ +interface IEMailTemplate { + /** + * @param \OCP\Defaults $themingDefaults + * @param \OCP\IURLGenerator $urlGenerator + * @param \OCP\IL10N $l10n + * + * @since 12.0.0 + */ + public function __construct(\OCP\Defaults $themingDefaults, + \OCP\IURLGenerator $urlGenerator, + \OCP\IL10N $l10n); + + /** + * Adds a header to the email + * + * @since 12.0.0 + */ + public function addHeader(); + + /** + * Adds a heading to the email + * + * @param string $title + * + * @since 12.0.0 + */ + public function addHeading($title); + + /** + * Adds a paragraph to the body of the email + * + * @param string $text + * + * @since 12.0.0 + */ + public function addBodyText($text); + + /** + * Adds a button group of two buttons to the body of the email + * + * @param string $textLeft Text of left button + * @param string $urlLeft URL of left button + * @param string $textRight Text of right button + * @param string $urlRight URL of right button + * + * @since 12.0.0 + */ + public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight); + + /** + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email + * + * @param string $text + * + * @since 12.0.0 + */ + public function addFooter($text = ''); + + /** + * Returns the rendered HTML email as string + * + * @return string + * + * @since 12.0.0 + */ + public function renderHTML(); + + /** + * Returns the rendered plain text email as string + * + * @return string + * + * @since 12.0.0 + */ + public function renderText(); +} diff --git a/lib/public/Mail/IMailer.php b/lib/public/Mail/IMailer.php index 9ecebd2ee40..af16a8a239a 100644 --- a/lib/public/Mail/IMailer.php +++ b/lib/public/Mail/IMailer.php @@ -55,6 +55,14 @@ interface IMailer { public function createMessage(); /** + * Creates a new email template object + * + * @return IEMailTemplate + * @since 12.0.0 + */ + public function createEMailTemplate(); + + /** * Send the specified message. Also sets the from address to the value defined in config.php * if no-one has been passed. * |