*/
namespace Friendica\Util;
-use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
-use Friendica\Core\PConfig;
+use Friendica\DI;
use Friendica\Protocol\Email;
/**
- * @brief class to handle emailing
+ * class to handle emailing
*/
class Emailer
{
* additionalMailHeader additions to the SMTP mail header
* optional uid user id of the destination user
*
- * @return object
+ * @return bool
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function send($params)
+ public static function send(array $params)
{
+ $params['sent'] = false;
+
Hook::callAll('emailer_send_prepare', $params);
+ if ($params['sent']) {
+ return true;
+ }
+
$email_textonly = false;
if (!empty($params['uid'])) {
- $email_textonly = PConfig::get($params['uid'], "system", "email_textonly");
+ $email_textonly = DI::pConfig()->get($params['uid'], "system", "email_textonly");
}
$fromName = Email::encodeHeader(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
.rand(10000, 99999);
// generate a multipart/alternative message header
- $messageHeader = defaults($params, 'additionalMailHeader', '') .
+ $messageHeader = ($params['additionalMailHeader'] ?? '') .
"From: $fromName <{$params['fromEmail']}>\n" .
"Reply-To: $fromName <{$params['replyTo']}>\n" .
"MIME-Version: 1.0\n" .
$multipartMessageBody .=
"--" . $mimeBoundary . "--\n"; // message ending
- if (Config::get("system", "sendmail_params", true)) {
+ if (DI::config()->get("system", "sendmail_params", true)) {
$sendmail_params = '-f ' . $params['fromEmail'];
} else {
$sendmail_params = null;
'subject' => $messageSubject,
'body' => $multipartMessageBody,
'headers' => $messageHeader,
- 'parameters' => $sendmail_params
+ 'parameters' => $sendmail_params,
+ 'sent' => false,
];
Hook::callAll("emailer_send", $hookdata);
+ if ($hookdata['sent']) {
+ return true;
+ }
+
$res = mail(
$hookdata['to'],
$hookdata['subject'],