migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @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;
use OCP\Mail\IAttachment;
use Symfony\Component\Mime\Email;
/**
* Class Attachment
*
* @package OC\Mail
* @since 13.0.0
*/
class Attachment implements IAttachment {
public function __construct(
private ?string $body,
private ?string $name,
private ?string $contentType,
private ?string $path = null
) {
}
/**
* @return $this
* @since 13.0.0
*/
public function setFilename(string $filename): IAttachment {
$this->name = $filename;
return $this;
}
/**
* @return $this
* @since 13.0.0
*/
public function setContentType(string $contentType): IAttachment {
$this->contentType = $contentType;
return $this;
}
/**
* @return $this
* @since 13.0.0
*/
public function setBody(string $body): IAttachment {
$this->body = $body;
return $this;
}
public function attach(Email $symfonyEmail): void {
if ($this->path !== null) {
$symfonyEmail->attachFromPath($this->path, $this->name, $this->contentType);
} else {
$symfonyEmail->attach($this->body, $this->name, $this->contentType);
}
}
}
@@ -0,0 +1,661 @@
<?php
declare(strict_types=1);
/**
* @copyright 2017, Morris Jobke <hey@morrisjobke.de>
* @copyright 2017, Lukas Reschke <lukas@statuscode.ch>
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author brad2014 <brad2014@users.noreply.github.com>
* @author Brad Rubenstein <brad@wbr.tech>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
* @author Joas Schilling <coding@schilljs.com>
* @author Julius Härtl <jus@bitgrid.net>
* @author Liam JACK <liamjack@users.noreply.github.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author medcloud <42641918+medcloud@users.noreply.github.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Tomasz Paluszkiewicz <tomasz.paluszkiewicz@gmail.com>
*
* @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;
use OCP\Defaults;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Mail\IEMailTemplate;
/**
* 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 {
protected string $subject = '';
protected string $htmlBody = '';
protected string $plainBody = '';
/** indicated if the header is added */
protected bool $headerAdded = false;
/** indicated if the body is already opened */
protected bool $bodyOpened = false;
/** indicated if there is a list open in the body */
protected bool $bodyListOpened = false;
/** indicated if the footer is added */
protected bool $footerAdded = false;
protected string $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:#fff!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:#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>
</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:#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">
<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:#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%">
<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:-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">
<center data-parsed="" style="min-width:580px;width:100%">
EOF;
protected string $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 string $header = <<<EOF
<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%%">
<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:-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">
<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">
<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:-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">
<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="background-color:%s;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
<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">
</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="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>
</tr>
</tbody>
</table>
EOF;
protected string $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:-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">
<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>
</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="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>
</tr>
</tbody>
</table>
EOF;
protected string $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:-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">
<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">
<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:-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">
EOF;
protected string $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:-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">
<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:-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">
<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>
</th>
<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>
</tr>
</table>
</th>
</tr>
</tbody>
</table>
EOF;
// note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151)
protected string $listBegin = <<<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:-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">
<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
EOF;
protected string $listItem = <<<EOF
<tr style="padding:0;text-align:left;vertical-align:top">
<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;">
<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>
</td>
<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">
<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>
</td>
<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>
</tr>
EOF;
protected string $listEnd = <<<EOF
</table>
</th>
</tr>
</tbody>
</table>
EOF;
protected string $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:-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>
</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:-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">
<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:-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">
<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:60px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:%1\$s;background-color:%1\$s;color:#fefefe;">
<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:-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">
<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;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">
<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>
</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:300px;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:-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">
<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:-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">
<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>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</th>
<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>
</tr>
</table>
</th>
</tr>
</tbody>
</table>
EOF;
protected string $button = <<<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:-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>
</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:-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">
<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:-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">
<center data-parsed="" style="min-width:490px;width:100%%">
<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;">
<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:-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">
<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;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">
<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>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</th>
<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>
</tr>
</table>
</th>
</tr>
</tbody>
</table>
EOF;
protected string $bodyEnd = <<<EOF
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
EOF;
protected string $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:-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>
</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:-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">
<center data-parsed="" style="min-width:580px;width:100%%">
<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:-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>
</tr>
</tbody>
</table>
<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>
</center>
</td>
</tr>
</table>
EOF;
public function __construct(
protected Defaults $themingDefaults,
protected IURLGenerator $urlGenerator,
protected IFactory $l10nFactory,
protected string $emailId,
protected array $data,
) {
$this->htmlBody .= $this->head;
}
/**
* Sets the subject of the email
*/
public function setSubject(string $subject): void {
$this->subject = $subject;
}
/**
* Adds a header to the email
*/
public function addHeader(): void {
if ($this->headerAdded) {
return;
}
$this->headerAdded = true;
$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
}
/**
* Adds a heading to the email
*
* @param string|bool $plainTitle Title that is used in the plain text email
* if empty the $title is used, if false none will be used
*/
public function addHeading(string $title, $plainTitle = ''): void {
if ($this->footerAdded) {
return;
}
if ($plainTitle === '') {
$plainTitle = $title;
}
$this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
if ($plainTitle !== false) {
$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
}
}
/**
* Open the HTML body when it is not already
*/
protected function ensureBodyIsOpened(): void {
if ($this->bodyOpened) {
return;
}
$this->htmlBody .= $this->bodyBegin;
$this->bodyOpened = true;
}
/**
* Adds a paragraph to the body of the email
*
* @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
* @param string|bool $plainText Text that is used in the plain text email
* if empty the $text is used, if false none will be used
*/
public function addBodyText(string $text, $plainText = ''): void {
if ($this->footerAdded) {
return;
}
if ($plainText === '') {
$plainText = $text;
$text = htmlspecialchars($text);
}
$this->ensureBodyListClosed();
$this->ensureBodyIsOpened();
$this->htmlBody .= vsprintf($this->bodyText, [$text]);
if ($plainText !== false) {
$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
}
}
/**
* Adds a list item to the body of the email
*
* @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
* @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
* @param string $icon Absolute path, must be 16*16 pixels
* @param string|bool $plainText Text that is used in the plain text email
* if empty or true the $text is used, if false none will be used
* @param string|bool $plainMetaInfo Meta info that is used in the plain text email
* if empty or true the $metaInfo is used, if false none will be used
* @param integer $plainIndent plainIndent If > 0, Indent plainText by this amount.
* @since 12.0.0
*/
public function addBodyListItem(
string $text,
string $metaInfo = '',
string $icon = '',
$plainText = '',
$plainMetaInfo = '',
$plainIndent = 0,
): void {
$this->ensureBodyListOpened();
if ($plainText === '' || $plainText === true) {
$plainText = $text;
$text = htmlspecialchars($text);
$text = str_replace("\n", "<br/>", $text); // convert newlines to HTML breaks
}
if ($plainMetaInfo === '' || $plainMetaInfo === true) {
$plainMetaInfo = $metaInfo;
$metaInfo = htmlspecialchars($metaInfo);
}
$htmlText = $text;
if ($metaInfo) {
$htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText;
}
if ($icon !== '') {
$icon = '<img src="' . htmlspecialchars($icon) . '" alt="&bull;">';
} else {
$icon = '&bull;';
}
$this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]);
if ($plainText !== false) {
if ($plainIndent === 0) {
/*
* If plainIndent is not set by caller, this is the old NC17 layout code.
*/
$this->plainBody .= ' * ' . $plainText;
if ($plainMetaInfo !== false) {
$this->plainBody .= ' (' . $plainMetaInfo . ')';
}
$this->plainBody .= PHP_EOL;
} else {
/*
* Caller can set plainIndent > 0 to format plainText in tabular fashion.
* with plainMetaInfo in column 1, and plainText in column 2.
* The plainMetaInfo label is right justified in a field of width
* "plainIndent". Multilines after the first are indented plainIndent+1
* (to account for space after label). Fixes: #12391
*/
/** @var string $label */
$label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
$this->plainBody .= sprintf("%{$plainIndent}s %s\n",
$label,
str_replace("\n", "\n" . str_repeat(' ', $plainIndent + 1), $plainText));
}
}
}
protected function ensureBodyListOpened(): void {
if ($this->bodyListOpened) {
return;
}
$this->ensureBodyIsOpened();
$this->bodyListOpened = true;
$this->htmlBody .= $this->listBegin;
}
protected function ensureBodyListClosed(): void {
if (!$this->bodyListOpened) {
return;
}
$this->bodyListOpened = false;
$this->htmlBody .= $this->listEnd;
}
/**
* Adds a button group of two buttons to the body of the email
*
* @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
* @param string $urlLeft URL of left button
* @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
* @param string $urlRight URL of right button
* @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
* @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
*/
public function addBodyButtonGroup(
string $textLeft,
string $urlLeft,
string $textRight,
string $urlRight,
string $plainTextLeft = '',
string $plainTextRight = '',
): void {
if ($this->footerAdded) {
return;
}
if ($plainTextLeft === '') {
$plainTextLeft = $textLeft;
$textLeft = htmlspecialchars($textLeft);
}
if ($plainTextRight === '') {
$plainTextRight = $textRight;
$textRight = htmlspecialchars($textRight);
}
$this->ensureBodyIsOpened();
$this->ensureBodyListClosed();
$color = $this->themingDefaults->getDefaultColorPrimary();
$textColor = $this->themingDefaults->getTextColorPrimary();
$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]);
$this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
}
/**
* Adds a button to the body of the email
*
* @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
* @param string $url URL of button
* @param string|false $plainText Text of button in plain text version
* if empty the $text is used, if false none will be used
*
* @since 12.0.0
*/
public function addBodyButton(string $text, string $url, $plainText = ''): void {
if ($this->footerAdded) {
return;
}
$this->ensureBodyIsOpened();
$this->ensureBodyListClosed();
if ($plainText === '') {
$plainText = $text;
$text = htmlspecialchars($text);
}
$color = $this->themingDefaults->getDefaultColorPrimary();
$textColor = $this->themingDefaults->getTextColorPrimary();
$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]);
if ($plainText !== false) {
$this->plainBody .= $plainText . ': ';
}
$this->plainBody .= $url . PHP_EOL;
}
/**
* Close the HTML body when it is open
*/
protected function ensureBodyIsClosed(): void {
if (!$this->bodyOpened) {
return;
}
$this->ensureBodyListClosed();
$this->htmlBody .= $this->bodyEnd;
$this->bodyOpened = false;
}
/**
* Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
*
* @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
*/
public function addFooter(string $text = '', ?string $lang = null): void {
if ($text === '') {
$l10n = $this->l10nFactory->get('lib', $lang);
$slogan = $this->themingDefaults->getSlogan($lang);
if ($slogan !== '') {
$slogan = ' - ' . $slogan;
}
$text = $this->themingDefaults->getName() . $slogan . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
}
if ($this->footerAdded) {
return;
}
$this->footerAdded = true;
$this->ensureBodyIsClosed();
$this->htmlBody .= vsprintf($this->footer, [$text]);
$this->htmlBody .= $this->tail;
$this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
}
/**
* Returns the rendered email subject as string
*/
public function renderSubject(): string {
return $this->subject;
}
/**
* Returns the rendered HTML email as string
*/
public function renderHtml(): string {
if (!$this->footerAdded) {
$this->footerAdded = true;
$this->ensureBodyIsClosed();
$this->htmlBody .= $this->tail;
}
return $this->htmlBody;
}
/**
* Returns the rendered plain text email as string
*/
public function renderText(): string {
if (!$this->footerAdded) {
$this->footerAdded = true;
$this->ensureBodyIsClosed();
$this->htmlBody .= $this->tail;
}
return $this->plainBody;
}
}
+340
View File
@@ -0,0 +1,340 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Arne Hamann <kontakt+github@arne.email>
* @author Branko Kokanovic <branko@kokanovic.org>
* @author Carsten Wiedmann <carsten_sttgt@gmx.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Jared Boone <jared.boone@gmail.com>
* @author Joas Schilling <coding@schilljs.com>
* @author Julius Härtl <jus@bitgrid.net>
* @author kevin147147 <kevintamool@gmail.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Tekhnee <info@tekhnee.org>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Mail;
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IBinaryFinder;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Mail\Events\BeforeMessageSent;
use OCP\Mail\IAttachment;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\Mail\IMessage;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\Mailer as SymfonyMailer;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mailer\Transport\SendmailTransport;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Exception\RfcComplianceException;
/**
* Class Mailer provides some basic functions to create a mail message that can be used in combination with
* \OC\Mail\Message.
*
* Example usage:
*
* $mailer = \OC::$server->getMailer();
* $message = $mailer->createMessage();
* $message->setSubject('Your Subject');
* $message->setFrom(array('cloud@domain.org' => 'ownCloud Notifier'));
* $message->setTo(array('recipient@domain.org' => 'Recipient'));
* $message->setBody('The message text', 'text/html');
* $mailer->send($message);
*
* This message can then be passed to send() of \OC\Mail\Mailer
*
* @package OC\Mail
*/
class Mailer implements IMailer {
private ?MailerInterface $instance = null;
public function __construct(
private IConfig $config,
private LoggerInterface $logger,
private Defaults $defaults,
private IURLGenerator $urlGenerator,
private IL10N $l10n,
private IEventDispatcher $dispatcher,
private IFactory $l10nFactory,
) {
}
/**
* Creates a new message object that can be passed to send()
*/
public function createMessage(): Message {
$plainTextOnly = $this->config->getSystemValueBool('mail_send_plaintext_only', false);
return new Message(new Email(), $plainTextOnly);
}
/**
* @param string|null $data
* @param string|null $filename
* @param string|null $contentType
* @since 13.0.0
*/
public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment {
return new Attachment($data, $filename, $contentType);
}
/**
* @param string|null $contentType
* @since 13.0.0
*/
public function createAttachmentFromPath(string $path, $contentType = null): IAttachment {
return new Attachment(null, null, $contentType, $path);
}
/**
* Creates a new email template object
*
* @since 12.0.0
*/
public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate {
$class = $this->config->getSystemValueString('mail_template_class', '');
if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) {
return new $class(
$this->defaults,
$this->urlGenerator,
$this->l10nFactory,
$emailId,
$data
);
}
return new EMailTemplate(
$this->defaults,
$this->urlGenerator,
$this->l10nFactory,
$emailId,
$data
);
}
/**
* Send the specified message. Also sets the from address to the value defined in config.php
* if no-one has been passed.
*
* If sending failed, the recipients that failed will be returned (to, cc and bcc).
* Will output additional debug info if 'mail_smtpdebug' => 'true' is set in config.php
*
* @param IMessage $message Message to send
* @return string[] $failedRecipients
*/
public function send(IMessage $message): array {
$debugMode = $this->config->getSystemValueBool('mail_smtpdebug', false);
if (!($message instanceof Message)) {
throw new \InvalidArgumentException('Object not of type ' . Message::class);
}
if (empty($message->getFrom())) {
$message->setFrom([\OCP\Util::getDefaultEmailAddress('no-reply') => $this->defaults->getName()]);
}
$mailer = $this->getInstance();
$this->dispatcher->dispatchTyped(new BeforeMessageSent($message));
try {
$message->setRecipients();
} catch (\InvalidArgumentException|RfcComplianceException $e) {
$logMessage = sprintf(
'Could not send mail to "%s" with subject "%s" as validation for address failed',
print_r(array_merge($message->getTo(), $message->getCc(), $message->getBcc()), true),
$message->getSubject()
);
$this->logger->debug($logMessage, ['app' => 'core', 'exception' => $e]);
$recipients = array_merge($message->getTo(), $message->getCc(), $message->getBcc());
$failedRecipients = [];
array_walk($recipients, function ($value, $key) use (&$failedRecipients) {
if (is_numeric($key)) {
$failedRecipients[] = $value;
} else {
$failedRecipients[] = $key;
}
});
return $failedRecipients;
}
try {
$mailer->send($message->getSymfonyEmail());
} catch (TransportExceptionInterface $e) {
$logMessage = sprintf('Sending mail to "%s" with subject "%s" failed', print_r($message->getTo(), true), $message->getSubject());
$this->logger->debug($logMessage, ['app' => 'core', 'exception' => $e]);
if ($debugMode) {
$this->logger->debug($e->getDebug(), ['app' => 'core']);
}
$recipients = array_merge($message->getTo(), $message->getCc(), $message->getBcc());
$failedRecipients = [];
array_walk($recipients, function ($value, $key) use (&$failedRecipients) {
if (is_numeric($key)) {
$failedRecipients[] = $value;
} else {
$failedRecipients[] = $key;
}
});
return $failedRecipients;
}
// Debugging logging
$logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject());
$this->logger->debug($logMessage, ['app' => 'core']);
return [];
}
/**
* @deprecated 26.0.0 Implicit validation is done in \OC\Mail\Message::setRecipients
* via \Symfony\Component\Mime\Address::__construct
*
* @param string $email Email address to be validated
* @return bool True if the mail address is valid, false otherwise
*/
public function validateMailAddress(string $email): bool {
if ($email === '') {
// Shortcut: empty addresses are never valid
return false;
}
$validator = new EmailValidator();
$validation = new RFCValidation();
return $validator->isValid($email, $validation);
}
protected function getInstance(): MailerInterface {
if (!is_null($this->instance)) {
return $this->instance;
}
$transport = null;
switch ($this->config->getSystemValueString('mail_smtpmode', 'smtp')) {
case 'sendmail':
$transport = $this->getSendMailInstance();
break;
case 'smtp':
default:
$transport = $this->getSmtpInstance();
break;
}
return new SymfonyMailer($transport);
}
/**
* Returns the SMTP transport
*
* Only supports ssl/tls
* starttls is not enforcable with Symfony Mailer but might be available
* via the automatic config (Symfony Mailer internal)
*
* @return EsmtpTransport
*/
protected function getSmtpInstance(): EsmtpTransport {
// either null or true - if nothing is passed, let the symfony mailer figure out the configuration by itself
$mailSmtpsecure = ($this->config->getSystemValue('mail_smtpsecure', null) === 'ssl') ? true : null;
$transport = new EsmtpTransport(
$this->config->getSystemValueString('mail_smtphost', '127.0.0.1'),
$this->config->getSystemValueInt('mail_smtpport', 25),
$mailSmtpsecure,
null,
$this->logger
);
/** @var SocketStream $stream */
$stream = $transport->getStream();
/** @psalm-suppress InternalMethod */
$stream->setTimeout($this->config->getSystemValueInt('mail_smtptimeout', 10));
if ($this->config->getSystemValueBool('mail_smtpauth', false)) {
$transport->setUsername($this->config->getSystemValueString('mail_smtpname', ''));
$transport->setPassword($this->config->getSystemValueString('mail_smtppassword', ''));
}
$streamingOptions = $this->config->getSystemValue('mail_smtpstreamoptions', []);
if (is_array($streamingOptions) && !empty($streamingOptions)) {
/** @psalm-suppress InternalMethod */
$currentStreamingOptions = $stream->getStreamOptions();
$currentStreamingOptions = array_merge_recursive($currentStreamingOptions, $streamingOptions);
/** @psalm-suppress InternalMethod */
$stream->setStreamOptions($currentStreamingOptions);
}
$overwriteCliUrl = parse_url(
$this->config->getSystemValueString('overwrite.cli.url', ''),
PHP_URL_HOST
);
if (!empty($overwriteCliUrl)) {
$transport->setLocalDomain($overwriteCliUrl);
}
return $transport;
}
/**
* Returns the sendmail transport
*
* @return SendmailTransport
*/
protected function getSendMailInstance(): SendmailTransport {
switch ($this->config->getSystemValueString('mail_smtpmode', 'smtp')) {
case 'qmail':
$binaryPath = '/var/qmail/bin/sendmail';
break;
default:
$sendmail = \OCP\Server::get(IBinaryFinder::class)->findBinaryPath('sendmail');
if ($sendmail === null) {
$sendmail = '/usr/sbin/sendmail';
}
$binaryPath = $sendmail;
break;
}
$binaryParam = match ($this->config->getSystemValueString('mail_sendmailmode', 'smtp')) {
'pipe' => ' -t',
default => ' -bs',
};
return new SendmailTransport($binaryPath . $binaryParam, null, $this->logger);
}
}
+345
View File
@@ -0,0 +1,345 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Arne Hamann <kontakt+github@arne.email>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Jared Boone <jared.boone@gmail.com>
* @author Joas Schilling <coding@schilljs.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Mail;
use OCP\Mail\Headers\AutoSubmitted;
use OCP\Mail\IAttachment;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMessage;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Exception\InvalidArgumentException;
use Symfony\Component\Mime\Exception\RfcComplianceException;
/**
* Class Message provides a wrapper around Symfony\Component\Mime\Email (Used to be around SwiftMail)
*
* @package OC\Mail
*/
class Message implements IMessage {
private array $to = [];
private array $from = [];
private array $replyTo = [];
private array $cc = [];
private array $bcc = [];
public function __construct(
private Email $symfonyEmail,
private bool $plainTextOnly,
) {
}
/**
* @since 13.0.0
* @return $this
*/
public function attach(IAttachment $attachment): IMessage {
/** @var Attachment $attachment */
$attachment->attach($this->symfonyEmail);
return $this;
}
/**
* Can be used to "attach content inline" as message parts with specific MIME type and encoding.
* {@inheritDoc}
* @since 26.0.0
*/
public function attachInline(string $body, string $name, string $contentType = null): IMessage {
# To be sure this works with iCalendar messages, we encode with 8bit instead of
# quoted-printable encoding. We save the current encoder, replace the current
# encoder with an 8bit encoder and after we've finished, we reset the encoder
# to the previous one. Originally intended to be added after the message body,
# as it is curently unknown if all mail clients handle this properly if added
# before.
$this->symfonyEmail->embed($body, $name, $contentType);
return $this;
}
/**
* Converts the [['displayName' => 'email'], ['displayName2' => 'email2']] arrays to valid Adresses
*
* @param array $addresses Array of mail addresses
* @return Address[]
* @throws RfcComplianceException|InvalidArgumentException
*/
protected function convertAddresses(array $addresses): array {
$convertedAddresses = [];
if (empty($addresses)) {
return [];
}
array_walk($addresses, function ($readableName, $email) use (&$convertedAddresses) {
if (is_numeric($email)) {
$convertedAddresses[] = new Address($readableName);
} else {
$convertedAddresses[] = new Address($email, $readableName);
}
});
return $convertedAddresses;
}
/**
* Set the from address of this message.
*
* If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php
*
* @param array $addresses Example: array('sender@domain.org', 'other@domain.org' => 'A name')
* @return $this
*/
public function setFrom(array $addresses): IMessage {
$this->from = $addresses;
return $this;
}
/**
* Get the from address of this message.
*/
public function getFrom(): array {
return $this->from;
}
/**
* Set the Reply-To address of this message
* @return $this
*/
public function setReplyTo(array $addresses): IMessage {
$this->replyTo = $addresses;
return $this;
}
/**
* Returns the Reply-To address of this message
*/
public function getReplyTo(): array {
return $this->replyTo;
}
/**
* Set the to addresses of this message.
*
* @param array $recipients Example: array('recipient@domain.org', 'other@domain.org' => 'A name')
* @return $this
*/
public function setTo(array $recipients): IMessage {
$this->to = $recipients;
return $this;
}
/**
* Get the to address of this message.
*/
public function getTo(): array {
return $this->to;
}
/**
* Set the CC recipients of this message.
*
* @param array $recipients Example: array('recipient@domain.org', 'other@domain.org' => 'A name')
* @return $this
*/
public function setCc(array $recipients): IMessage {
$this->cc = $recipients;
return $this;
}
/**
* Get the cc address of this message.
*/
public function getCc(): array {
return $this->cc;
}
/**
* Set the BCC recipients of this message.
*
* @param array $recipients Example: array('recipient@domain.org', 'other@domain.org' => 'A name')
* @return $this
*/
public function setBcc(array $recipients): IMessage {
$this->bcc = $recipients;
return $this;
}
/**
* Get the Bcc address of this message.
*/
public function getBcc(): array {
return $this->bcc;
}
/**
* @return $this
*/
public function setSubject(string $subject): IMessage {
$this->symfonyEmail->subject($subject);
return $this;
}
/**
* Get the from subject of this message.
*/
public function getSubject(): string {
return $this->symfonyEmail->getSubject() ?? '';
}
/**
* @return $this
*/
public function setPlainBody(string $body): IMessage {
$this->symfonyEmail->text($body);
return $this;
}
/**
* Get the plain body of this message.
*/
public function getPlainBody(): string {
/** @var string $body */
$body = $this->symfonyEmail->getTextBody() ?? '';
return $body;
}
/**
* @return $this
*/
public function setHtmlBody(string $body): IMessage {
if (!$this->plainTextOnly) {
$this->symfonyEmail->html($body);
}
return $this;
}
/**
* Set the underlying Email instance
*/
public function setSymfonyEmail(Email $symfonyEmail): void {
$this->symfonyEmail = $symfonyEmail;
}
/**
* Get the underlying Email instance
*/
public function getSymfonyEmail(): Email {
return $this->symfonyEmail;
}
/**
* @return $this
*/
public function setBody(string $body, string $contentType): IMessage {
if (!$this->plainTextOnly || $contentType !== 'text/html') {
if ($contentType === 'text/html') {
$this->symfonyEmail->html($body);
} else {
$this->symfonyEmail->text($body);
}
}
return $this;
}
/**
* Set the recipients on the symphony email
*
* Since
*
* setTo
* setFrom
* setReplyTo
* setCc
* setBcc
*
* could throw a \Symfony\Component\Mime\Exception\RfcComplianceException
* or a \Symfony\Component\Mime\Exception\InvalidArgumentException
* we wrap the calls here. We then have the validation errors all in one place and can
* throw shortly before \OC\Mail\Mailer::send
*
* @throws InvalidArgumentException|RfcComplianceException
*/
public function setRecipients(): void {
$this->symfonyEmail->to(...$this->convertAddresses($this->getTo()));
$this->symfonyEmail->from(...$this->convertAddresses($this->getFrom()));
$this->symfonyEmail->replyTo(...$this->convertAddresses($this->getReplyTo()));
$this->symfonyEmail->cc(...$this->convertAddresses($this->getCc()));
$this->symfonyEmail->bcc(...$this->convertAddresses($this->getBcc()));
}
/**
* @return $this
*/
public function useTemplate(IEMailTemplate $emailTemplate): IMessage {
$this->setSubject($emailTemplate->renderSubject());
$this->setPlainBody($emailTemplate->renderText());
if (!$this->plainTextOnly) {
$this->setHtmlBody($emailTemplate->renderHtml());
}
return $this;
}
/**
* Add the Auto-Submitted header to the email, preventing most automated
* responses to automated messages.
*
* @param AutoSubmitted::VALUE_* $value (one of AutoSubmitted::VALUE_NO, AutoSubmitted::VALUE_AUTO_GENERATED, AutoSubmitted::VALUE_AUTO_REPLIED)
* @return $this
*/
public function setAutoSubmitted(string $value): IMessage {
$headers = $this->symfonyEmail->getHeaders();
if ($headers->has(AutoSubmitted::HEADER)) {
// if the header already exsists, remove it.
// the value can be modified with some implementations
// of the interface \Swift_Mime_Header, however the
// interface doesn't, and this makes the static-code
// analysis unhappy.
// @todo check if symfony mailer can modify the autosubmitted header
$headers->remove(AutoSubmitted::HEADER);
}
$headers->addTextHeader(AutoSubmitted::HEADER, $value);
return $this;
}
/**
* Get the current value of the Auto-Submitted header. Defaults to "no"
* which is equivalent to the header not existing at all
*/
public function getAutoSubmitted(): string {
$headers = $this->symfonyEmail->getHeaders();
return $headers->has(AutoSubmitted::HEADER) ?
$headers->get(AutoSubmitted::HEADER)->getBodyAsString() : AutoSubmitted::VALUE_NO;
}
}