EMailTemplate.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Mail;
  8. use OCP\Defaults;
  9. use OCP\IURLGenerator;
  10. use OCP\L10N\IFactory;
  11. use OCP\Mail\IEMailTemplate;
  12. /**
  13. * Class EMailTemplate
  14. *
  15. * addBodyText and addBodyButtonGroup automatically opens the body
  16. * addFooter, renderHtml, renderText automatically closes the body and the HTML if opened
  17. *
  18. * @package OC\Mail
  19. */
  20. class EMailTemplate implements IEMailTemplate {
  21. protected string $subject = '';
  22. protected string $htmlBody = '';
  23. protected string $plainBody = '';
  24. /** indicated if the header is added */
  25. protected bool $headerAdded = false;
  26. /** indicated if the body is already opened */
  27. protected bool $bodyOpened = false;
  28. /** indicated if there is a list open in the body */
  29. protected bool $bodyListOpened = false;
  30. /** indicated if the footer is added */
  31. protected bool $footerAdded = false;
  32. protected string $head = <<<EOF
  33. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  34. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
  35. <head>
  36. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  37. <meta name="viewport" content="width=device-width">
  38. <title></title>
  39. <style type="text/css">@media only screen{html{min-height:100%;background:#fff}}@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>
  40. </head>
  41. <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:#fff!important;box-sizing:border-box;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  42. <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">
  43. </span>
  44. <table class="body" style="-webkit-font-smoothing:antialiased;margin:0;background:#fff;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
  45. <tr style="padding:0;text-align:left;vertical-align:top">
  46. <td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  47. <center data-parsed="" style="min-width:580px;width:100%">
  48. EOF;
  49. protected string $tail = <<<EOF
  50. </center>
  51. </td>
  52. </tr>
  53. </table>
  54. <!-- prevent Gmail on iOS font size manipulation -->
  55. <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>
  56. </body>
  57. </html>
  58. EOF;
  59. protected string $header = <<<EOF
  60. <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
  61. <tr style="padding:0;text-align:left;vertical-align:top">
  62. <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  63. <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:150px">
  64. <tbody>
  65. <tr style="padding:0;text-align:left;vertical-align:top">
  66. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  67. <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%%">
  68. <tbody>
  69. <tr style="padding:0;text-align:left;vertical-align:top">
  70. <center data-parsed="" style="background-color:%s;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
  71. <img class="logo float-center" src="%s" alt="%s" align="center" style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;height:auto">
  72. </center>
  73. </tr>
  74. </tbody>
  75. </table>
  76. </td>
  77. </tr>
  78. </tbody>
  79. </table>
  80. </td>
  81. </tr>
  82. </table>
  83. <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%%">
  84. <tbody>
  85. <tr style="padding:0;text-align:left;vertical-align:top">
  86. <td height="40px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;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>
  87. </tr>
  88. </tbody>
  89. </table>
  90. EOF;
  91. protected string $heading = <<<EOF
  92. <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">
  93. <tbody>
  94. <tr style="padding:0;text-align:left;vertical-align:top">
  95. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  96. <h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:center;word-wrap:normal">%s</h1>
  97. </td>
  98. </tr>
  99. </tbody>
  100. </table>
  101. <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%%">
  102. <tbody>
  103. <tr style="padding:0;text-align:left;vertical-align:top">
  104. <td height="36px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:36px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
  105. </tr>
  106. </tbody>
  107. </table>
  108. EOF;
  109. protected string $bodyBegin = <<<EOF
  110. <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%">
  111. <tr style="padding:0;text-align:left;vertical-align:top">
  112. <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  113. <table align="center" class="container" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
  114. <tbody>
  115. <tr style="padding:0;text-align:left;vertical-align:top">
  116. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  117. EOF;
  118. protected string $bodyText = <<<EOF
  119. <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%%">
  120. <tbody>
  121. <tr style="padding:0;text-align:left;vertical-align:top">
  122. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  123. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
  124. <tr style="padding:0;text-align:left;vertical-align:top">
  125. <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  126. <p style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center">%s</p>
  127. </th>
  128. <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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>
  129. </tr>
  130. </table>
  131. </th>
  132. </tr>
  133. </tbody>
  134. </table>
  135. EOF;
  136. // note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151)
  137. protected string $listBegin = <<<EOF
  138. <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%">
  139. <tbody>
  140. <tr style="padding:0;text-align:left;vertical-align:top">
  141. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  142. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
  143. EOF;
  144. protected string $listItem = <<<EOF
  145. <tr style="padding:0;text-align:left;vertical-align:top">
  146. <td style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;width:15px;">
  147. <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;padding-left:10px;text-align:left">%s</p>
  148. </td>
  149. <td style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  150. <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#555;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;padding-left:10px;text-align:left">%s</p>
  151. </td>
  152. <td class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></td>
  153. </tr>
  154. EOF;
  155. protected string $listEnd = <<<EOF
  156. </table>
  157. </th>
  158. </tr>
  159. </tbody>
  160. </table>
  161. EOF;
  162. protected string $buttonGroup = <<<EOF
  163. <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
  164. <tbody>
  165. <tr style="padding:0;text-align:left;vertical-align:top">
  166. <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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>
  167. </tr>
  168. </tbody>
  169. </table>
  170. <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%%">
  171. <tbody>
  172. <tr style="padding:0;text-align:left;vertical-align:top">
  173. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  174. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
  175. <tr style="padding:0;text-align:left;vertical-align:top">
  176. <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  177. <center data-parsed="" style="min-width:490px;width:100%%">
  178. <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:60px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:%1\$s;background-color:%1\$s;color:#fefefe;">
  179. <tr style="padding:0;text-align:left;vertical-align:top">
  180. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  181. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
  182. <tr style="padding:0;text-align:left;vertical-align:top">
  183. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid %2\$s;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  184. <a href="%3\$s" style="Margin:0;border:0 solid %4\$s;border-radius:2px;color:%5\$s;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid %6\$s;text-decoration:none">%7\$s</a>
  185. </td>
  186. </tr>
  187. </table>
  188. </td>
  189. </tr>
  190. </table>
  191. <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:300px;padding:0;text-align:center;vertical-align:top;width:auto">
  192. <tr style="padding:0;text-align:left;vertical-align:top">
  193. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  194. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
  195. <tr style="padding:0;text-align:left;vertical-align:top">
  196. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  197. <a href="%8\$s" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">%9\$s</a>
  198. </td>
  199. </tr>
  200. </table>
  201. </td>
  202. </tr>
  203. </table>
  204. </center>
  205. </th>
  206. <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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>
  207. </tr>
  208. </table>
  209. </th>
  210. </tr>
  211. </tbody>
  212. </table>
  213. EOF;
  214. protected string $button = <<<EOF
  215. <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
  216. <tbody>
  217. <tr style="padding:0;text-align:left;vertical-align:top">
  218. <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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>
  219. </tr>
  220. </tbody>
  221. </table>
  222. <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%%">
  223. <tbody>
  224. <tr style="padding:0;text-align:left;vertical-align:top">
  225. <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  226. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
  227. <tr style="padding:0;text-align:left;vertical-align:top">
  228. <th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
  229. <center data-parsed="" style="min-width:490px;width:100%%">
  230. <table class="button btn default primary float-center" style="Margin:0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0;max-height:60px;padding:0;text-align:center;vertical-align:top;width:auto;background:%1\$s;color:#fefefe;background-color:%1\$s;">
  231. <tr style="padding:0;text-align:left;vertical-align:top">
  232. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  233. <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
  234. <tr style="padding:0;text-align:left;vertical-align:top">
  235. <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid %2\$s;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  236. <a href="%3\$s" style="Margin:0;border:0 solid %4\$s;border-radius:2px;color:%5\$s;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid %5\$s;text-decoration:none">%7\$s</a>
  237. </td>
  238. </tr>
  239. </table>
  240. </td>
  241. </tr>
  242. </table>
  243. </center>
  244. </th>
  245. <th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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>
  246. </tr>
  247. </table>
  248. </th>
  249. </tr>
  250. </tbody>
  251. </table>
  252. EOF;
  253. protected string $bodyEnd = <<<EOF
  254. </td>
  255. </tr>
  256. </tbody>
  257. </table>
  258. </td>
  259. </tr>
  260. </table>
  261. EOF;
  262. protected string $footer = <<<EOF
  263. <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%%">
  264. <tbody>
  265. <tr style="padding:0;text-align:left;vertical-align:top">
  266. <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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>
  267. </tr>
  268. </tbody>
  269. </table>
  270. <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%%">
  271. <tr style="padding:0;text-align:left;vertical-align:top">
  272. <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
  273. <center data-parsed="" style="min-width:580px;width:100%%">
  274. <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%%">
  275. <tbody>
  276. <tr style="padding:0;text-align:left;vertical-align:top">
  277. <td height="15px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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>
  278. </tr>
  279. </tbody>
  280. </table>
  281. <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">%s</p>
  282. </center>
  283. </td>
  284. </tr>
  285. </table>
  286. EOF;
  287. public function __construct(
  288. protected Defaults $themingDefaults,
  289. protected IURLGenerator $urlGenerator,
  290. protected IFactory $l10nFactory,
  291. protected string $emailId,
  292. protected array $data,
  293. ) {
  294. $this->htmlBody .= $this->head;
  295. }
  296. /**
  297. * Sets the subject of the email
  298. */
  299. public function setSubject(string $subject): void {
  300. $this->subject = $subject;
  301. }
  302. /**
  303. * Adds a header to the email
  304. */
  305. public function addHeader(): void {
  306. if ($this->headerAdded) {
  307. return;
  308. }
  309. $this->headerAdded = true;
  310. $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
  311. $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
  312. }
  313. /**
  314. * Adds a heading to the email
  315. *
  316. * @param string|bool $plainTitle Title that is used in the plain text email
  317. * if empty the $title is used, if false none will be used
  318. */
  319. public function addHeading(string $title, $plainTitle = ''): void {
  320. if ($this->footerAdded) {
  321. return;
  322. }
  323. if ($plainTitle === '') {
  324. $plainTitle = $title;
  325. }
  326. $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
  327. if ($plainTitle !== false) {
  328. $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
  329. }
  330. }
  331. /**
  332. * Open the HTML body when it is not already
  333. */
  334. protected function ensureBodyIsOpened(): void {
  335. if ($this->bodyOpened) {
  336. return;
  337. }
  338. $this->htmlBody .= $this->bodyBegin;
  339. $this->bodyOpened = true;
  340. }
  341. /**
  342. * Adds a paragraph to the body of the email
  343. *
  344. * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
  345. * @param string|bool $plainText Text that is used in the plain text email
  346. * if empty the $text is used, if false none will be used
  347. */
  348. public function addBodyText(string $text, $plainText = ''): void {
  349. if ($this->footerAdded) {
  350. return;
  351. }
  352. if ($plainText === '') {
  353. $plainText = $text;
  354. $text = htmlspecialchars($text);
  355. }
  356. $this->ensureBodyListClosed();
  357. $this->ensureBodyIsOpened();
  358. $this->htmlBody .= vsprintf($this->bodyText, [$text]);
  359. if ($plainText !== false) {
  360. $this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
  361. }
  362. }
  363. /**
  364. * Adds a list item to the body of the email
  365. *
  366. * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
  367. * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
  368. * @param string $icon Absolute path, must be 16*16 pixels
  369. * @param string|bool $plainText Text that is used in the plain text email
  370. * if empty or true the $text is used, if false none will be used
  371. * @param string|bool $plainMetaInfo Meta info that is used in the plain text email
  372. * if empty or true the $metaInfo is used, if false none will be used
  373. * @param integer $plainIndent plainIndent If > 0, Indent plainText by this amount.
  374. * @since 12.0.0
  375. */
  376. public function addBodyListItem(
  377. string $text,
  378. string $metaInfo = '',
  379. string $icon = '',
  380. $plainText = '',
  381. $plainMetaInfo = '',
  382. $plainIndent = 0,
  383. ): void {
  384. $this->ensureBodyListOpened();
  385. if ($plainText === '' || $plainText === true) {
  386. $plainText = $text;
  387. $text = htmlspecialchars($text);
  388. $text = str_replace("\n", "<br/>", $text); // convert newlines to HTML breaks
  389. }
  390. if ($plainMetaInfo === '' || $plainMetaInfo === true) {
  391. $plainMetaInfo = $metaInfo;
  392. $metaInfo = htmlspecialchars($metaInfo);
  393. }
  394. $htmlText = $text;
  395. if ($metaInfo) {
  396. $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText;
  397. }
  398. if ($icon !== '') {
  399. $icon = '<img src="' . htmlspecialchars($icon) . '" alt="&bull;">';
  400. } else {
  401. $icon = '&bull;';
  402. }
  403. $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]);
  404. if ($plainText !== false) {
  405. if ($plainIndent === 0) {
  406. /*
  407. * If plainIndent is not set by caller, this is the old NC17 layout code.
  408. */
  409. $this->plainBody .= ' * ' . $plainText;
  410. if ($plainMetaInfo !== false) {
  411. $this->plainBody .= ' (' . $plainMetaInfo . ')';
  412. }
  413. $this->plainBody .= PHP_EOL;
  414. } else {
  415. /*
  416. * Caller can set plainIndent > 0 to format plainText in tabular fashion.
  417. * with plainMetaInfo in column 1, and plainText in column 2.
  418. * The plainMetaInfo label is right justified in a field of width
  419. * "plainIndent". Multilines after the first are indented plainIndent+1
  420. * (to account for space after label). Fixes: #12391
  421. */
  422. /** @var string $label */
  423. $label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
  424. $this->plainBody .= sprintf("%{$plainIndent}s %s\n",
  425. $label,
  426. str_replace("\n", "\n" . str_repeat(' ', $plainIndent + 1), $plainText));
  427. }
  428. }
  429. }
  430. protected function ensureBodyListOpened(): void {
  431. if ($this->bodyListOpened) {
  432. return;
  433. }
  434. $this->ensureBodyIsOpened();
  435. $this->bodyListOpened = true;
  436. $this->htmlBody .= $this->listBegin;
  437. }
  438. protected function ensureBodyListClosed(): void {
  439. if (!$this->bodyListOpened) {
  440. return;
  441. }
  442. $this->bodyListOpened = false;
  443. $this->htmlBody .= $this->listEnd;
  444. }
  445. /**
  446. * Adds a button group of two buttons to the body of the email
  447. *
  448. * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
  449. * @param string $urlLeft URL of left button
  450. * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
  451. * @param string $urlRight URL of right button
  452. * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
  453. * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
  454. */
  455. public function addBodyButtonGroup(
  456. string $textLeft,
  457. string $urlLeft,
  458. string $textRight,
  459. string $urlRight,
  460. string $plainTextLeft = '',
  461. string $plainTextRight = '',
  462. ): void {
  463. if ($this->footerAdded) {
  464. return;
  465. }
  466. if ($plainTextLeft === '') {
  467. $plainTextLeft = $textLeft;
  468. $textLeft = htmlspecialchars($textLeft);
  469. }
  470. if ($plainTextRight === '') {
  471. $plainTextRight = $textRight;
  472. $textRight = htmlspecialchars($textRight);
  473. }
  474. $this->ensureBodyIsOpened();
  475. $this->ensureBodyListClosed();
  476. $color = $this->themingDefaults->getDefaultColorPrimary();
  477. $textColor = $this->themingDefaults->getTextColorPrimary();
  478. $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]);
  479. $this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
  480. $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
  481. }
  482. /**
  483. * Adds a button to the body of the email
  484. *
  485. * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
  486. * @param string $url URL of button
  487. * @param string|false $plainText Text of button in plain text version
  488. * if empty the $text is used, if false none will be used
  489. *
  490. * @since 12.0.0
  491. */
  492. public function addBodyButton(string $text, string $url, $plainText = ''): void {
  493. if ($this->footerAdded) {
  494. return;
  495. }
  496. $this->ensureBodyIsOpened();
  497. $this->ensureBodyListClosed();
  498. if ($plainText === '') {
  499. $plainText = $text;
  500. $text = htmlspecialchars($text);
  501. }
  502. $color = $this->themingDefaults->getDefaultColorPrimary();
  503. $textColor = $this->themingDefaults->getTextColorPrimary();
  504. $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]);
  505. if ($plainText !== false) {
  506. $this->plainBody .= $plainText . ': ';
  507. }
  508. $this->plainBody .= $url . PHP_EOL;
  509. }
  510. /**
  511. * Close the HTML body when it is open
  512. */
  513. protected function ensureBodyIsClosed(): void {
  514. if (!$this->bodyOpened) {
  515. return;
  516. }
  517. $this->ensureBodyListClosed();
  518. $this->htmlBody .= $this->bodyEnd;
  519. $this->bodyOpened = false;
  520. }
  521. /**
  522. * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
  523. *
  524. * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
  525. */
  526. public function addFooter(string $text = '', ?string $lang = null): void {
  527. if ($text === '') {
  528. $l10n = $this->l10nFactory->get('lib', $lang);
  529. $slogan = $this->themingDefaults->getSlogan($lang);
  530. if ($slogan !== '') {
  531. $slogan = ' - ' . $slogan;
  532. }
  533. $text = $this->themingDefaults->getName() . $slogan . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
  534. }
  535. if ($this->footerAdded) {
  536. return;
  537. }
  538. $this->footerAdded = true;
  539. $this->ensureBodyIsClosed();
  540. $this->htmlBody .= vsprintf($this->footer, [$text]);
  541. $this->htmlBody .= $this->tail;
  542. $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
  543. $this->plainBody .= str_replace('<br>', PHP_EOL, $text);
  544. }
  545. /**
  546. * Returns the rendered email subject as string
  547. */
  548. public function renderSubject(): string {
  549. return $this->subject;
  550. }
  551. /**
  552. * Returns the rendered HTML email as string
  553. */
  554. public function renderHtml(): string {
  555. if (!$this->footerAdded) {
  556. $this->footerAdded = true;
  557. $this->ensureBodyIsClosed();
  558. $this->htmlBody .= $this->tail;
  559. }
  560. return $this->htmlBody;
  561. }
  562. /**
  563. * Returns the rendered plain text email as string
  564. */
  565. public function renderText(): string {
  566. if (!$this->footerAdded) {
  567. $this->footerAdded = true;
  568. $this->ensureBodyIsClosed();
  569. $this->htmlBody .= $this->tail;
  570. }
  571. return $this->plainBody;
  572. }
  573. }