]> source.dussan.org Git - nextcloud-server.git/commitdiff
New layout for welcome email
authorMorris Jobke <hey@morrisjobke.de>
Thu, 6 Apr 2017 18:20:47 +0000 (13:20 -0500)
committerMorris Jobke <hey@morrisjobke.de>
Fri, 7 Apr 2017 17:03:32 +0000 (12:03 -0500)
* thanks to @espina2 for make this nice design
* the button says "Set password" if the admin didn't specified a password

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
lib/private/Mail/EMailTemplate.php [new file with mode: 0644]
lib/private/Mail/IEMailTemplate.php [new file with mode: 0644]
settings/Controller/UsersController.php
settings/templates/email.new_user.php [deleted file]
settings/templates/email.new_user_plain_text.php [deleted file]
tests/Settings/Controller/UsersControllerTest.php
tests/data/emails/new-account-email.html [new file with mode: 0644]
tests/data/emails/new-account-email.txt [new file with mode: 0644]
tests/lib/Mail/EMailTemplateTest.php [new file with mode: 0644]

diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php
new file mode 100644 (file)
index 0000000..7a884dd
--- /dev/null
@@ -0,0 +1,392 @@
+<?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 OC\Mail;
+
+
+/**
+ * Class EMailTemplate
+ *
+ * addBodyText and addBodyButtonGroup automatically opens the body
+ * addFooter, renderHTML, renderText automatically closes the body and the HTML if opened
+ *
+ * @package OC\Mail
+ */
+class EMailTemplate implements IEMailTemplate {
+
+       /** @var \OC_Defaults */
+       protected $defaults;
+
+       /** @var string */
+       protected $htmlBody = '';
+       /** @var string */
+       protected $plainBody = '';
+       /** @var bool indicated if the footer is added */
+       protected $headerAdded = false;
+       /** @var bool indicated if the body is already opened */
+       protected $bodyOpened = false;
+       /** @var bool indicated if the footer is added */
+       protected $footerAdded = false;
+
+       protected $head = <<<EOF
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important">
+<head>
+       <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+       <meta name="viewport" content="width=device-width">
+       <title></title>
+       <style type="text/css">@media only screen{html{min-height:100%;background:#F5F5F5}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
+</head>
+<body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;Margin:0;background:#f3f3f3!important;box-sizing:border-box;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
+       <span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
+       </span>
+       <table class="body" style="-webkit-font-smoothing:antialiased;Margin:0;background:#f3f3f3!important;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;height:100%;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
+               <tr style="padding:0;text-align:left;vertical-align:top">
+                       <td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                               <center data-parsed="" style="min-width:580px;width:100%">
+EOF;
+
+       protected $tail = <<<EOF
+                                       </center>
+                               </td>
+                       </tr>
+               </table>
+               <!-- prevent Gmail on iOS font size manipulation -->
+               <div style="display:none;white-space:nowrap;font:15px courier;line-height:0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
+       </body>
+</html>
+EOF;
+
+       protected $header = <<<EOF
+<table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:%s;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word">
+                       <table align="center" class="container" style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
+                               <tbody>
+                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                       <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                               <table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%">
+                                                       <tbody>
+                                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                                               <center data-parsed="" style="min-width:580px;width:100%%"><!-- TODO -->
+                                                                       <img class="logo float-center" src="%s" alt="logo" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;max-height:100%%;max-width:100px;outline:0;text-align:center;text-decoration:none;width:auto">
+                                                               </center>
+                                                       </tr>
+                                                       </tbody>
+                                               </table>
+                                       </td>
+                               </tr>
+                               </tbody>
+                       </table>
+               </td>
+       </tr>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td height="80px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+       </tr>
+       </tbody>
+</table>
+EOF;
+
+       protected $heading = <<<EOF
+<table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                       <h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center;word-wrap:normal">%s</h1>
+               </td>
+       </tr>
+       </tbody>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td height="40px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:40px;font-weight:400;hyphens:auto;line-height:40px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+       </tr>
+       </tbody>
+</table>
+EOF;
+
+       protected $bodyBegin = <<<EOF
+<table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                       <table align="center" class="container has-shadow" style="Margin:0 auto;background:#fefefe;border-collapse:collapse;border-spacing:0;box-shadow:0 1px 2px 0 rgba(0,0,0,.2),0 1px 3px 0 rgba(0,0,0,.1);margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
+                               <tbody>
+                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                       <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                               <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+                                                       <tbody>
+                                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                                               <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+                                                       </tr>
+                                                       </tbody>
+                                               </table>
+EOF;
+
+       protected $bodyText = <<<EOF
+<table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+                       <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
+                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                       <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+                                               <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:left">%s</p>
+                                       </th>
+                                       <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+                               </tr>
+                       </table>
+               </th>
+       </tr>
+       </tbody>
+</table>
+EOF;
+
+       protected $buttonGroup = <<<EOF
+<table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:50px;font-weight:400;hyphens:auto;line-height:50px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+       </tr>
+       </tbody>
+</table>
+<table align="center" class="row btn-group" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+                       <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
+                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                       <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+                                               <center data-parsed="" style="min-width:490px;width:100%%">
+                                                       <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
+                                                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                                                       <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                                                               <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
+                                                                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                                                                               <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:%s;border:0 solid %s;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                                                                                       <a href="%s" style="Margin:0;border:0 solid %s;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%s</a>
+                                                                                               </td>
+                                                                                       </tr>
+                                                                               </table>
+                                                                       </td>
+                                                               </tr>
+                                                       </table>
+                                                       <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
+                                                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                                                       <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                                                               <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
+                                                                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                                                                               <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                                                                                       <a href="%s" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #CBCBCB;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%s</a>
+                                                                                               </td>
+                                                                                       </tr>
+                                                                               </table>
+                                                                       </td>
+                                                               </tr>
+                                                       </table>
+                                               </center>
+                                       </th>
+                                       <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+                               </tr>
+                       </table>
+               </th>
+       </tr>
+       </tbody>
+</table>
+EOF;
+
+       protected $bodyEnd = <<<EOF
+
+                                       </td>
+                               </tr>
+                               </tbody>
+                       </table>
+               </td>
+       </tr>
+</table>
+EOF;
+
+       protected $footer = <<<EOF
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+       </tr>
+       </tbody>
+</table>
+<table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                       <center data-parsed="" style="min-width:580px;width:100%%"><!-- TODO -->
+                               <img class="logo float-center" src="%s" alt="logo" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;max-height:100%%;max-width:75px;outline:0;text-align:center;text-decoration:none;width:auto">
+                               <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
+                                       <tbody>
+                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                               <td height="15px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+                                       </tr>
+                                       </tbody>
+                               </table>
+                               <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">%s</p>
+                       </center>
+               </td>
+       </tr>
+</table>
+EOF;
+
+
+       public function __construct(\OC_Defaults $defaults) {
+               $this->defaults = $defaults;
+
+               $this->htmlBody .= $this->head;
+       }
+
+       /**
+        * Adds a header to the email
+        *
+        * @param string $logoUrl
+        */
+       public function addHeader($logoUrl) {
+               if ($this->headerAdded) {
+                       return;
+               }
+               $this->headerAdded = true;
+
+               $this->htmlBody .= vsprintf($this->header, [$this->defaults->getColorPrimary(), $logoUrl]);
+       }
+
+       /**
+        * Adds a heading to the email
+        *
+        * @param string $title
+        */
+       public function addHeading($title) {
+               if ($this->footerAdded) {
+                       return;
+               }
+
+               $this->htmlBody .= vsprintf($this->heading, [$title]);
+               $this->plainBody .= $title . PHP_EOL . PHP_EOL;
+       }
+
+       /**
+        * Adds a paragraph to the body of the email
+        *
+        * @param string $text
+        */
+       public function addBodyText($text) {
+               if ($this->footerAdded) {
+                       return;
+               }
+
+               if (!$this->bodyOpened) {
+                       $this->htmlBody .= $this->bodyBegin;
+                       $this->bodyOpened = true;
+               }
+
+               $this->htmlBody .= vsprintf($this->bodyText, [$text]);
+               $this->plainBody .= $text . PHP_EOL . PHP_EOL;
+       }
+
+       /**
+        * 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
+        */
+       public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight) {
+               if ($this->footerAdded) {
+                       return;
+               }
+
+               if (!$this->bodyOpened) {
+                       $this->htmlBody .= $this->bodyBegin;
+                       $this->bodyOpened = true;
+               }
+
+               $color = $this->defaults->getColorPrimary();
+               $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textLeft, $urlRight, $textRight]);
+               $this->plainBody .= $textLeft . ': ' . $urlLeft . PHP_EOL;
+               $this->plainBody .= $textRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
+
+       }
+
+       /**
+        * 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 $logoUrl
+        * @param string $text
+        */
+       public function addFooter($logoUrl, $text) {
+               if ($this->footerAdded) {
+                       return;
+               }
+               $this->footerAdded = true;
+
+               if ($this->bodyOpened) {
+                       $this->htmlBody .= $this->bodyEnd;
+                       $this->bodyOpened = false;
+               }
+               $this->htmlBody .= vsprintf($this->footer, [$logoUrl, $text]);
+               $this->htmlBody .= $this->tail;
+               $this->plainBody .= '--' . PHP_EOL;
+               $this->plainBody .= str_replace('<br>', PHP_EOL, $text);
+       }
+
+       /**
+        * Returns the rendered HTML email as string
+        *
+        * @return string
+        */
+       public function renderHTML() {
+               if (!$this->footerAdded) {
+                       $this->footerAdded = true;
+                       if ($this->bodyOpened) {
+                               $this->htmlBody .= $this->bodyEnd;
+                       }
+                       $this->htmlBody .= $this->tail;
+               }
+               return $this->htmlBody;
+       }
+
+       /**
+        * Returns the rendered plain text email as string
+        *
+        * @return string
+        */
+       public function renderText() {
+               if (!$this->footerAdded) {
+                       $this->footerAdded = true;
+                       if ($this->bodyOpened) {
+                               $this->htmlBody .= $this->bodyEnd;
+                       }
+                       $this->htmlBody .= $this->tail;
+               }
+               return $this->plainBody;
+       }
+}
+
diff --git a/lib/private/Mail/IEMailTemplate.php b/lib/private/Mail/IEMailTemplate.php
new file mode 100644 (file)
index 0000000..5bf2b8e
--- /dev/null
@@ -0,0 +1,107 @@
+<?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 OC\Mail;
+
+/**
+ * Interface IEMailTemplate
+ *
+ * Interface to a class that allows to build HTML emails
+ *
+ * Example:
+ *
+ * <?php
+ *
+ * $emailTemplate = new EMailTemplate($this->defaults);
+ *
+ * $emailTemplate->addHeader('https://example.org/img/logo-mail-header.png');
+ * $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(
+ *     'https://example.org/img/logo-mail-footer.png',
+ *     'Nextcloud - a safe home for your data <br>This is an automatically generated email, please do not reply.'
+ * );
+ *
+ * $htmlContent = $emailTemplate->renderHTML();
+ * $plainContent = $emailTemplate->renderText();
+ */
+interface IEMailTemplate {
+       /**
+        * Adds a header to the email
+        *
+        * @param string $logoUrl
+        */
+       public function addHeader($logoUrl);
+
+       /**
+        * Adds a heading to the email
+        *
+        * @param string $title
+        */
+       public function addHeading($title);
+
+       /**
+        * Adds a paragraph to the body of the email
+        *
+        * @param string $text
+        */
+       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
+        */
+       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 $logoUrl
+        * @param string $text
+        */
+       public function addFooter($logoUrl, $text);
+
+       /**
+        * Returns the rendered HTML email as string
+        *
+        * @return string
+        */
+       public function renderHTML();
+
+       /**
+        * Returns the rendered plain text email as string
+        *
+        * @return string
+        */
+       public function renderText();
+}
\ No newline at end of file
index 19c5b0681673c0db0491803c3e4fd8df0297a706..3688cb7b7e2567aa1080ec19cc32820b891e7d6f 100644 (file)
@@ -33,6 +33,7 @@ namespace OC\Settings\Controller;
 use OC\Accounts\AccountManager;
 use OC\AppFramework\Http;
 use OC\ForbiddenException;
+use OC\Mail\EMailTemplate;
 use OC\User\User;
 use OCP\App\IAppManager;
 use OCP\AppFramework\Controller;
@@ -443,17 +444,39 @@ class UsersController extends Controller {
                                        $link = $this->urlGenerator->getAbsoluteURL('/');
                                }
 
-                               // data for the mail template
-                               $mailData = array(
-                                       'username' => $username,
-                                       'url' => $link
+
+
+                               $emailTemplate = new EMailTemplate($this->defaults);
+
+                               $emailTemplate->addHeader($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('', 'logo-mail-header.png')));
+
+                               $displayname = $user->getDisplayName();
+                               if ($displayname === $username) {
+                                       $emailTemplate->addHeading($this->l10n->t('Welcome aboard'));
+                               } else {
+                                       $emailTemplate->addHeading($this->l10n->t('Welcome aboard %s', $displayname));
+                               }
+                               $emailTemplate->addBodyText($this->l10n->t('You have now an Nextcloud account, you can add, protect, and share your data.'));
+                               $emailTemplate->addBodyText($this->l10n->t('Your username is: %s', [$username]));
+
+                               if ($generatedPassword) {
+                                       $leftButtonText = $this->l10n->t('Set your password');
+                               } else {
+                                       $leftButtonText = $this->l10n->t('Go to %s', [$this->defaults->getName()]);
+                               }
+
+                               $emailTemplate->addBodyButtonGroup(
+                                       $leftButtonText, $link,
+                                       $this->l10n->t('Install Client'), 'https://nextcloud.com/install/#install-clients'
                                );
 
-                               $mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
-                               $mailContent = $mail->render();
+                               $emailTemplate->addFooter(
+                                       $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('', 'logo-mail-footer.png')),
+                                       $this->defaults->getName() . ' - ' . $this->defaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.')
+                               );
 
-                               $mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
-                               $plainTextMailContent = $mail->render();
+                               $mailContent = $emailTemplate->renderHTML();
+                               $plainTextMailContent = $emailTemplate->renderText();
 
                                $subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]);
 
diff --git a/settings/templates/email.new_user.php b/settings/templates/email.new_user.php
deleted file mode 100644 (file)
index 9418c21..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-<table cellspacing="0" cellpadding="0" border="0" width="100%">
-       <tr><td>
-                       <table cellspacing="0" cellpadding="0" border="0" width="600px">
-                               <tr>
-                                       <td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>" bordercolor="<?php p($theme->getColorPrimary());?>" border>
-                                               <img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/>
-                                       </td>
-                               </tr>
-                               <tr><td colspan="2">&nbsp;</td></tr>
-                               <tr>
-                                       <td width="20px">&nbsp;</td>
-                                       <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">
-                                               <?php
-                                               print_unescaped($l->t('Hey there,<br><br>just letting you know that you now have a %s account.<br><br>Your username: <strong>%s</strong><br>Access it: <strong><a href="%s">%s</a></strong><br><br>', array($theme->getName(), $_['username'], $_['url'], $_['url'])));
-
-                                               // TRANSLATORS term at the end of a mail
-                                               p($l->t('Cheers!'));
-                                               ?>
-                                       </td>
-                               </tr>
-                               <tr><td colspan="2">&nbsp;</td></tr>
-                               <tr>
-                                       <td width="20px">&nbsp;</td>
-                                       <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br>
-                                               <?php p($theme->getName()); ?> -
-                                               <?php p($theme->getSlogan()); ?>
-                                               <br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl());?></a>
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td colspan="2">&nbsp;</td>
-                               </tr>
-                       </table>
-               </td></tr>
-</table>
diff --git a/settings/templates/email.new_user_plain_text.php b/settings/templates/email.new_user_plain_text.php
deleted file mode 100644 (file)
index 2cc70dd..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-print_unescaped($l->t("Hey there,\n\njust letting you know that you now have a %s account.\n\nYour username: %s\nAccess it: %s\n\n", array($theme->getName(), $_['username'], $_['url'])));
-
-// TRANSLATORS term at the end of a mail
-p($l->t("Cheers!"));
-?>
-
-       --
-<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?>
-<?php print_unescaped("\n".$theme->getBaseUrl());
index 3cdde1b2d276809e8d414bde7e64e14526622f79..2ed298df2dcc1a3b124d9938d2f04a9a62d77f02 100644 (file)
@@ -12,6 +12,7 @@ namespace Tests\Settings\Controller;
 
 use OC\Accounts\AccountManager;
 use OC\Group\Manager;
+use OC\Mail\EMailTemplate;
 use OC\Settings\Controller\UsersController;
 use OCP\App\IAppManager;
 use OCP\AppFramework\Http;
@@ -1427,32 +1428,33 @@ class UsersControllerTest extends \Test\TestCase {
                        ->expects($this->at(1))
                        ->method('setSubject')
                        ->with('Your  account was created');
-               $htmlBody = new Http\TemplateResponse(
-                       'settings',
-                       'email.new_user',
-                       [
-                               'username' => 'foo',
-                               'url' => '',
-                       ],
-                       'blank'
+
+               $emailTemplate = new EMailTemplate($this->defaults);
+
+               $emailTemplate->addHeader('https://example.org/img/logo-mail-header.png');
+
+               $emailTemplate->addHeading('Welcome aboard');
+               $emailTemplate->addBodyText('You have now an Nextcloud account, you can add, protect, and share your data.');
+               $emailTemplate->addBodyText('Your username is: foo');
+
+
+               $emailTemplate->addBodyButtonGroup(
+                       'Go to Nextcloud', 'https://example.org/resetPassword/123',
+                       'Install Client', 'https://nextcloud.com/install/#install-clients'
+               );
+
+               $emailTemplate->addFooter(
+                       'https://example.org/img/logo-mail-footer.png',
+                       'TestCloud - A safe home for your data<br>This is an automatically generated email, please do not reply.'
                );
                $message
                        ->expects($this->at(2))
                        ->method('setHtmlBody')
-                       ->with($htmlBody->render());
-               $plainBody = new Http\TemplateResponse(
-                       'settings',
-                       'email.new_user_plain_text',
-                       [
-                               'username' => 'foo',
-                               'url' => '',
-                       ],
-                       'blank'
-               );
+                       ->with($emailTemplate->renderHTML());
                $message
                        ->expects($this->at(3))
                        ->method('setPlainBody')
-                       ->with($plainBody->render());
+                       ->with($emailTemplate->renderText());
                $message
                        ->expects($this->at(4))
                        ->method('setFrom')
@@ -2325,32 +2327,33 @@ class UsersControllerTest extends \Test\TestCase {
                        ->expects($this->at(1))
                        ->method('setSubject')
                        ->with('Your  account was created');
-               $htmlBody = new Http\TemplateResponse(
-                       'settings',
-                       'email.new_user',
-                       [
-                               'username' => 'foo',
-                               'url' => 'link-with-my-token',
-                       ],
-                       'blank'
+
+               $emailTemplate = new EMailTemplate($this->defaults);
+
+               $emailTemplate->addHeader('https://example.org/img/logo-mail-header.png');
+
+               $emailTemplate->addHeading('Welcome aboard');
+               $emailTemplate->addBodyText('You have now an Nextcloud account, you can add, protect, and share your data.');
+               $emailTemplate->addBodyText('Your username is: foo');
+
+
+               $emailTemplate->addBodyButtonGroup(
+                       'Go to Nextcloud', 'https://example.org/resetPassword/123',
+                       'Install Client', 'https://nextcloud.com/install/#install-clients'
+               );
+
+               $emailTemplate->addFooter(
+                       'https://example.org/img/logo-mail-footer.png',
+                       'TestCloud - A safe home for your data<br>This is an automatically generated email, please do not reply.'
                );
                $message
                        ->expects($this->at(2))
                        ->method('setHtmlBody')
-                       ->with($htmlBody->render());
-               $plainBody = new Http\TemplateResponse(
-                       'settings',
-                       'email.new_user_plain_text',
-                       [
-                               'username' => 'foo',
-                               'url' => 'link-with-my-token',
-                       ],
-                       'blank'
-               );
+                       ->with($emailTemplate->renderHTML());
                $message
                        ->expects($this->at(3))
                        ->method('setPlainBody')
-                       ->with($plainBody->render());
+                       ->with($emailTemplate->renderText());
                $message
                        ->expects($this->at(4))
                        ->method('setFrom')
diff --git a/tests/data/emails/new-account-email.html b/tests/data/emails/new-account-email.html
new file mode 100644 (file)
index 0000000..9b9155f
--- /dev/null
@@ -0,0 +1,188 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important">
+<head>
+       <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+       <meta name="viewport" content="width=device-width">
+       <title></title>
+       <style type="text/css">@media only screen{html{min-height:100%;background:#F5F5F5}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
+</head>
+<body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;Margin:0;background:#f3f3f3!important;box-sizing:border-box;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
+       <span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
+       </span>
+       <table class="body" style="-webkit-font-smoothing:antialiased;Margin:0;background:#f3f3f3!important;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;height:100%;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
+               <tr style="padding:0;text-align:left;vertical-align:top">
+                       <td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                               <center data-parsed="" style="min-width:580px;width:100%"><table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:#0082c9;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word">
+                       <table align="center" class="container" style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
+                               <tbody>
+                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                       <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                               <table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+                                                       <tbody>
+                                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                                               <center data-parsed="" style="min-width:580px;width:100%"><!-- TODO -->
+                                                                       <img class="logo float-center" src="https://example.org/img/logo-mail-header.png" alt="logo" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;max-height:100%;max-width:100px;outline:0;text-align:center;text-decoration:none;width:auto">
+                                                               </center>
+                                                       </tr>
+                                                       </tbody>
+                                               </table>
+                                       </td>
+                               </tr>
+                               </tbody>
+                       </table>
+               </td>
+       </tr>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td height="80px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+       </tr>
+       </tbody>
+</table><table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                       <h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center;word-wrap:normal">Welcome aboard</h1>
+               </td>
+       </tr>
+       </tbody>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td height="40px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:40px;font-weight:400;hyphens:auto;line-height:40px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+       </tr>
+       </tbody>
+</table><table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                       <table align="center" class="container has-shadow" style="Margin:0 auto;background:#fefefe;border-collapse:collapse;border-spacing:0;box-shadow:0 1px 2px 0 rgba(0,0,0,.2),0 1px 3px 0 rgba(0,0,0,.1);margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
+                               <tbody>
+                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                       <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                               <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+                                                       <tbody>
+                                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                                               <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+                                                       </tr>
+                                                       </tbody>
+                                               </table><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+                       <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                       <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+                                               <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:left">You have now an Nextcloud account, you can add, protect, and share your data.</p>
+                                       </th>
+                                       <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+                               </tr>
+                       </table>
+               </th>
+       </tr>
+       </tbody>
+</table><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+                       <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                       <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+                                               <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:left">Your username is: abc</p>
+                                       </th>
+                                       <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+                               </tr>
+                       </table>
+               </th>
+       </tr>
+       </tbody>
+</table><table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:50px;font-weight:400;hyphens:auto;line-height:50px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+       </tr>
+       </tbody>
+</table>
+<table align="center" class="row btn-group" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+                       <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                       <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+                                               <center data-parsed="" style="min-width:490px;width:100%">
+                                                       <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
+                                                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                                                       <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                                                               <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+                                                                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                                                                               <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#0082c9;border:0 solid #0082c9;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                                                                                       <a href="https://example.org/resetPassword/123" style="Margin:0;border:0 solid #0082c9;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Set your password</a>
+                                                                                               </td>
+                                                                                       </tr>
+                                                                               </table>
+                                                                       </td>
+                                                               </tr>
+                                                       </table>
+                                                       <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
+                                                               <tr style="padding:0;text-align:left;vertical-align:top">
+                                                                       <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                                                               <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+                                                                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                                                                               <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                                                                                                       <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #CBCBCB;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Install Client</a>
+                                                                                               </td>
+                                                                                       </tr>
+                                                                               </table>
+                                                                       </td>
+                                                               </tr>
+                                                       </table>
+                                               </center>
+                                       </th>
+                                       <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+                               </tr>
+                       </table>
+               </th>
+       </tr>
+       </tbody>
+</table>
+                                       </td>
+                               </tr>
+                               </tbody>
+                       </table>
+               </td>
+       </tr>
+</table><table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+       <tbody>
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+       </tr>
+       </tbody>
+</table>
+<table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+       <tr style="padding:0;text-align:left;vertical-align:top">
+               <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+                       <center data-parsed="" style="min-width:580px;width:100%"><!-- TODO -->
+                               <img class="logo float-center" src="https://example.org/img/logo-mail-footer.png" alt="logo" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;max-height:100%;max-width:75px;outline:0;text-align:center;text-decoration:none;width:auto">
+                               <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+                                       <tbody>
+                                       <tr style="padding:0;text-align:left;vertical-align:top">
+                                               <td height="15px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+                                       </tr>
+                                       </tbody>
+                               </table>
+                               <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">TestCloud - A safe home for your data<br>This is an automatically generated email, please do not reply.</p>
+                       </center>
+               </td>
+       </tr>
+</table>                                       </center>
+                               </td>
+                       </tr>
+               </table>
+               <!-- prevent Gmail on iOS font size manipulation -->
+               <div style="display:none;white-space:nowrap;font:15px courier;line-height:0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
+       </body>
+</html>
\ No newline at end of file
diff --git a/tests/data/emails/new-account-email.txt b/tests/data/emails/new-account-email.txt
new file mode 100644 (file)
index 0000000..6732d80
--- /dev/null
@@ -0,0 +1,12 @@
+Welcome aboard
+
+You have now an Nextcloud account, you can add, protect, and share your data.
+
+Your username is: abc
+
+Set your password: https://example.org/resetPassword/123
+Install Client: https://nextcloud.com/install/#install-clients
+
+--
+TestCloud - A safe home for your data
+This is an automatically generated email, please do not reply.
\ No newline at end of file
diff --git a/tests/lib/Mail/EMailTemplateTest.php b/tests/lib/Mail/EMailTemplateTest.php
new file mode 100644 (file)
index 0000000..3acb742
--- /dev/null
@@ -0,0 +1,75 @@
+<?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 Test\Mail;
+
+use OC\Mail\EMailTemplate;
+use OC_Defaults;
+use Test\TestCase;
+
+class EMailTemplateTest extends TestCase {
+       /** @var OC_Defaults */
+       private $defaults;
+
+       function setUp() {
+               parent::setUp();
+
+               $this->defaults = $this->getMockBuilder('\OC_Defaults')
+                       ->disableOriginalConstructor()->getMock();
+
+               $this->defaults
+                       ->expects($this->any())
+                       ->method('getColorPrimary')
+                       ->willReturn('#0082c9');
+       }
+
+       public function testEMailTemplate() {
+               $emailTemplate = new EMailTemplate($this->defaults);
+
+               $emailTemplate->addHeader('https://example.org/img/logo-mail-header.png');
+
+               $emailTemplate->addHeading('Welcome aboard');
+               $emailTemplate->addBodyText('You have now an Nextcloud account, you can add, protect, and share your data.');
+               $emailTemplate->addBodyText('Your username is: abc');
+
+
+               $emailTemplate->addBodyButtonGroup(
+                       'Set your password', 'https://example.org/resetPassword/123',
+                       'Install Client', 'https://nextcloud.com/install/#install-clients'
+               );
+
+               $emailTemplate->addFooter(
+                       'https://example.org/img/logo-mail-footer.png',
+                       'TestCloud - A safe home for your data<br>This is an automatically generated email, please do not reply.'
+               );
+
+               $expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email.html');
+               $this->assertSame($expectedHTML, $emailTemplate->renderHTML());
+
+
+               $expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email.txt');
+               $this->assertSame($expectedTXT, $emailTemplate->renderText());
+       }
+
+
+}