Add explicit parameters to Sender::send() method signature
This commit is contained in:
parent
ea9d3b7438
commit
915abe8a33
|
@ -512,19 +512,19 @@ function notification($params)
|
||||||
Logger::log('sending notification email');
|
Logger::log('sending notification email');
|
||||||
|
|
||||||
if (isset($params['parent']) && (intval($params['parent']) != 0)) {
|
if (isset($params['parent']) && (intval($params['parent']) != 0)) {
|
||||||
$id_for_parent = $params['parent']."@".$hostname;
|
$id_for_parent = $params['parent'] . "@" . $hostname;
|
||||||
|
|
||||||
// Is this the first email notification for this parent item and user?
|
// Is this the first email notification for this parent item and user?
|
||||||
if (!DBA::exists('notify-threads', ['master-parent-item' => $params['parent'], 'receiver-uid' => $params['uid']])) {
|
if (!DBA::exists('notify-threads', ['master-parent-item' => $params['parent'], 'receiver-uid' => $params['uid']])) {
|
||||||
Logger::log("notify_id:".intval($notify_id).", parent: ".intval($params['parent'])."uid: ".intval($params['uid']), Logger::DEBUG);
|
Logger::log("notify_id:" . intval($notify_id) . ", parent: " . intval($params['parent']) . "uid: " . intval($params['uid']), Logger::DEBUG);
|
||||||
|
|
||||||
$fields = ['notify-id' => $notify_id, 'master-parent-item' => $params['parent'],
|
$fields = ['notify-id' => $notify_id, 'master-parent-item' => $params['parent'],
|
||||||
'receiver-uid' => $params['uid'], 'parent-item' => 0];
|
'receiver-uid' => $params['uid'], 'parent-item' => 0];
|
||||||
DBA::insert('notify-threads', $fields);
|
DBA::insert('notify-threads', $fields);
|
||||||
|
|
||||||
$additional_mail_header .= "Message-ID: <${id_for_parent}>\n";
|
$additional_mail_header .= "Message-ID: <${id_for_parent}>\n";
|
||||||
$log_msg = "include/enotify: No previous notification found for this parent:\n".
|
$log_msg = "include/enotify: No previous notification found for this parent:\n" .
|
||||||
" parent: ${params['parent']}\n"." uid : ${params['uid']}\n";
|
" parent: ${params['parent']}\n" . " uid : ${params['uid']}\n";
|
||||||
Logger::log($log_msg, Logger::DEBUG);
|
Logger::log($log_msg, Logger::DEBUG);
|
||||||
} else {
|
} else {
|
||||||
// If not, just "follow" the thread.
|
// If not, just "follow" the thread.
|
||||||
|
@ -536,30 +536,30 @@ function notification($params)
|
||||||
$textversion = BBCode::toPlaintext($body);
|
$textversion = BBCode::toPlaintext($body);
|
||||||
$htmlversion = BBCode::convert($body);
|
$htmlversion = BBCode::convert($body);
|
||||||
|
|
||||||
$datarray = [];
|
$datarray = [];
|
||||||
$datarray['banner'] = $banner;
|
$datarray['banner'] = $banner;
|
||||||
$datarray['product'] = $product;
|
$datarray['product'] = $product;
|
||||||
$datarray['preamble'] = $preamble;
|
$datarray['preamble'] = $preamble;
|
||||||
$datarray['sitename'] = $sitename;
|
$datarray['sitename'] = $sitename;
|
||||||
$datarray['siteurl'] = $siteurl;
|
$datarray['siteurl'] = $siteurl;
|
||||||
$datarray['type'] = $params['type'];
|
$datarray['type'] = $params['type'];
|
||||||
$datarray['parent'] = $parent_id;
|
$datarray['parent'] = $parent_id;
|
||||||
$datarray['source_name'] = $params['source_name'] ?? '';
|
$datarray['source_name'] = $params['source_name'] ?? '';
|
||||||
$datarray['source_link'] = $params['source_link'] ?? '';
|
$datarray['source_link'] = $params['source_link'] ?? '';
|
||||||
$datarray['source_photo'] = $params['source_photo'] ?? '';
|
$datarray['source_photo'] = $params['source_photo'] ?? '';
|
||||||
$datarray['uid'] = $params['uid'];
|
$datarray['uid'] = $params['uid'];
|
||||||
$datarray['username'] = $params['to_name'] ?? '';
|
$datarray['username'] = $params['to_name'] ?? '';
|
||||||
$datarray['hsitelink'] = $hsitelink;
|
$datarray['hsitelink'] = $hsitelink;
|
||||||
$datarray['tsitelink'] = $tsitelink;
|
$datarray['tsitelink'] = $tsitelink;
|
||||||
$datarray['hitemlink'] = '<a href="'.$itemlink.'">'.$itemlink.'</a>';
|
$datarray['hitemlink'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
|
||||||
$datarray['titemlink'] = $itemlink;
|
$datarray['titemlink'] = $itemlink;
|
||||||
$datarray['thanks'] = $thanks;
|
$datarray['thanks'] = $thanks;
|
||||||
$datarray['site_admin'] = $site_admin;
|
$datarray['site_admin'] = $site_admin;
|
||||||
$datarray['title'] = stripslashes($title);
|
$datarray['title'] = stripslashes($title);
|
||||||
$datarray['htmlversion'] = $htmlversion;
|
$datarray['htmlversion'] = $htmlversion;
|
||||||
$datarray['textversion'] = $textversion;
|
$datarray['textversion'] = $textversion;
|
||||||
$datarray['subject'] = $subject;
|
$datarray['subject'] = $subject;
|
||||||
$datarray['headers'] = $additional_mail_header;
|
$datarray['headers'] = $additional_mail_header;
|
||||||
|
|
||||||
Hook::callAll('enotify_mail', $datarray);
|
Hook::callAll('enotify_mail', $datarray);
|
||||||
|
|
||||||
|
@ -568,59 +568,52 @@ function notification($params)
|
||||||
$content_allowed = ((!DI::config()->get('system', 'enotify_no_content')) || ($params['type'] == SYSTEM_EMAIL));
|
$content_allowed = ((!DI::config()->get('system', 'enotify_no_content')) || ($params['type'] == SYSTEM_EMAIL));
|
||||||
|
|
||||||
// load the template for private message notifications
|
// load the template for private message notifications
|
||||||
$tpl = Renderer::getMarkupTemplate('email_notify_html.tpl');
|
$tpl = Renderer::getMarkupTemplate('email_notify_html.tpl');
|
||||||
$email_html_body = Renderer::replaceMacros($tpl, [
|
$email_html_body = Renderer::replaceMacros($tpl, [
|
||||||
'$banner' => $datarray['banner'],
|
'$banner' => $datarray['banner'],
|
||||||
'$product' => $datarray['product'],
|
'$product' => $datarray['product'],
|
||||||
'$preamble' => str_replace("\n", "<br>\n", $datarray['preamble']),
|
'$preamble' => str_replace("\n", "<br>\n", $datarray['preamble']),
|
||||||
'$sitename' => $datarray['sitename'],
|
'$sitename' => $datarray['sitename'],
|
||||||
'$siteurl' => $datarray['siteurl'],
|
'$siteurl' => $datarray['siteurl'],
|
||||||
'$source_name' => $datarray['source_name'],
|
'$source_name' => $datarray['source_name'],
|
||||||
'$source_link' => $datarray['source_link'],
|
'$source_link' => $datarray['source_link'],
|
||||||
'$source_photo' => $datarray['source_photo'],
|
'$source_photo' => $datarray['source_photo'],
|
||||||
'$username' => $datarray['username'],
|
'$username' => $datarray['username'],
|
||||||
'$hsitelink' => $datarray['hsitelink'],
|
'$hsitelink' => $datarray['hsitelink'],
|
||||||
'$hitemlink' => $datarray['hitemlink'],
|
'$hitemlink' => $datarray['hitemlink'],
|
||||||
'$thanks' => $datarray['thanks'],
|
'$thanks' => $datarray['thanks'],
|
||||||
'$site_admin' => $datarray['site_admin'],
|
'$site_admin' => $datarray['site_admin'],
|
||||||
'$title' => $datarray['title'],
|
'$title' => $datarray['title'],
|
||||||
'$htmlversion' => $datarray['htmlversion'],
|
'$htmlversion' => $datarray['htmlversion'],
|
||||||
'$content_allowed' => $content_allowed,
|
'$content_allowed' => $content_allowed,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// load the template for private message notifications
|
// load the template for private message notifications
|
||||||
$tpl = Renderer::getMarkupTemplate('email_notify_text.tpl');
|
$tpl = Renderer::getMarkupTemplate('email_notify_text.tpl');
|
||||||
$email_text_body = Renderer::replaceMacros($tpl, [
|
$email_text_body = Renderer::replaceMacros($tpl, [
|
||||||
'$banner' => $datarray['banner'],
|
'$banner' => $datarray['banner'],
|
||||||
'$product' => $datarray['product'],
|
'$product' => $datarray['product'],
|
||||||
'$preamble' => $datarray['preamble'],
|
'$preamble' => $datarray['preamble'],
|
||||||
'$sitename' => $datarray['sitename'],
|
'$sitename' => $datarray['sitename'],
|
||||||
'$siteurl' => $datarray['siteurl'],
|
'$siteurl' => $datarray['siteurl'],
|
||||||
'$source_name' => $datarray['source_name'],
|
'$source_name' => $datarray['source_name'],
|
||||||
'$source_link' => $datarray['source_link'],
|
'$source_link' => $datarray['source_link'],
|
||||||
'$source_photo' => $datarray['source_photo'],
|
'$source_photo' => $datarray['source_photo'],
|
||||||
'$username' => $datarray['username'],
|
'$username' => $datarray['username'],
|
||||||
'$tsitelink' => $datarray['tsitelink'],
|
'$tsitelink' => $datarray['tsitelink'],
|
||||||
'$titemlink' => $datarray['titemlink'],
|
'$titemlink' => $datarray['titemlink'],
|
||||||
'$thanks' => $datarray['thanks'],
|
'$thanks' => $datarray['thanks'],
|
||||||
'$site_admin' => $datarray['site_admin'],
|
'$site_admin' => $datarray['site_admin'],
|
||||||
'$title' => $datarray['title'],
|
'$title' => $datarray['title'],
|
||||||
'$textversion' => $datarray['textversion'],
|
'$textversion' => $datarray['textversion'],
|
||||||
'$content_allowed' => $content_allowed,
|
'$content_allowed' => $content_allowed,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// use the Emailer class to send the message
|
// use the Emailer class to send the message
|
||||||
return DI::emailer()->send([
|
return DI::emailer()->send($sender_name, $sender_email, $sender_email, $params['to_email'],
|
||||||
'uid' => $params['uid'],
|
$datarray['subject'], $email_html_body, $email_text_body,
|
||||||
'fromName' => $sender_name,
|
$datarray['headers'], $params['uid']
|
||||||
'fromEmail' => $sender_email,
|
);
|
||||||
'replyTo' => $sender_email,
|
|
||||||
'toEmail' => $params['to_email'],
|
|
||||||
'messageSubject' => $datarray['subject'],
|
|
||||||
'htmlVersion' => $email_html_body,
|
|
||||||
'textVersion' => $email_text_body,
|
|
||||||
'additionalMailHeader' => $datarray['headers']
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
21
mod/item.php
21
mod/item.php
|
@ -796,27 +796,20 @@ function item_post(App $a) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$disclaimer = '<hr />' . DI::l10n()->t('This message was sent to you by %s, a member of the Friendica social network.', $a->user['username'])
|
$disclaimer = '<hr />' . DI::l10n()->t('This message was sent to you by %s, a member of the Friendica social network.', $a->user['username'])
|
||||||
. '<br />';
|
. '<br />';
|
||||||
$disclaimer .= DI::l10n()->t('You may visit them online at %s', DI::baseUrl() . '/profile/' . $a->user['nickname']) . EOL;
|
$disclaimer .= DI::l10n()->t('You may visit them online at %s', DI::baseUrl() . '/profile/' . $a->user['nickname']) . EOL;
|
||||||
$disclaimer .= DI::l10n()->t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
|
$disclaimer .= DI::l10n()->t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
|
||||||
if (!$datarray['title']=='') {
|
if (!$datarray['title'] == '') {
|
||||||
$subject = Email::encodeHeader($datarray['title'], 'UTF-8');
|
$subject = Email::encodeHeader($datarray['title'], 'UTF-8');
|
||||||
} else {
|
} else {
|
||||||
$subject = Email::encodeHeader('[Friendica]' . ' ' . DI::l10n()->t('%s posted an update.', $a->user['username']), 'UTF-8');
|
$subject = Email::encodeHeader('[Friendica]' . ' ' . DI::l10n()->t('%s posted an update.', $a->user['username']), 'UTF-8');
|
||||||
}
|
}
|
||||||
$link = '<a href="' . DI::baseUrl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
|
$link = '<a href="' . DI::baseUrl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
|
||||||
$html = Item::prepareBody($datarray);
|
$html = Item::prepareBody($datarray);
|
||||||
$message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
|
$message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';;
|
||||||
$params = [
|
DI::emailer()->send($a->user['username'], $a->user['email'], $a->user['email'], $addr,
|
||||||
'fromName' => $a->user['username'],
|
$subject, $message, HTML::toPlaintext($html . $disclaimer)
|
||||||
'fromEmail' => $a->user['email'],
|
);
|
||||||
'toEmail' => $addr,
|
|
||||||
'replyTo' => $a->user['email'],
|
|
||||||
'messageSubject' => $subject,
|
|
||||||
'htmlVersion' => $message,
|
|
||||||
'textVersion' => HTML::toPlaintext($html.$disclaimer)
|
|
||||||
];
|
|
||||||
DI::emailer()->send($params);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,9 @@ class Emailer
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function send(array $params)
|
public function send(string $fromName, string $fromEmail, string $replyTo, string $toEmail,
|
||||||
|
string $subject, string $msgHtml, string $msgText,
|
||||||
|
string $additionalMailHeader = '', int $uid = null)
|
||||||
{
|
{
|
||||||
$params['sent'] = false;
|
$params['sent'] = false;
|
||||||
|
|
||||||
|
@ -42,12 +44,12 @@ class Emailer
|
||||||
}
|
}
|
||||||
|
|
||||||
$email_textonly = false;
|
$email_textonly = false;
|
||||||
if (!empty($params['uid'])) {
|
if (!empty($uid)) {
|
||||||
$email_textonly = DI::pConfig()->get($params['uid'], "system", "email_textonly");
|
$email_textonly = DI::pConfig()->get($uid, "system", "email_textonly");
|
||||||
}
|
}
|
||||||
|
|
||||||
$fromName = Email::encodeHeader(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
|
$fromName = Email::encodeHeader(html_entity_decode($fromName, ENT_QUOTES, 'UTF-8'), 'UTF-8');
|
||||||
$messageSubject = Email::encodeHeader(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
|
$messageSubject = Email::encodeHeader(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'), 'UTF-8');
|
||||||
|
|
||||||
// generate a mime boundary
|
// generate a mime boundary
|
||||||
$mimeBoundary =rand(0, 9)."-"
|
$mimeBoundary =rand(0, 9)."-"
|
||||||
|
@ -56,21 +58,21 @@ class Emailer
|
||||||
.rand(10000, 99999);
|
.rand(10000, 99999);
|
||||||
|
|
||||||
// generate a multipart/alternative message header
|
// generate a multipart/alternative message header
|
||||||
$messageHeader = ($params['additionalMailHeader'] ?? '') .
|
$messageHeader = $additionalMailHeader .
|
||||||
"From: $fromName <{$params['fromEmail']}>\n" .
|
"From: $fromName <{$fromEmail}>\n" .
|
||||||
"Reply-To: $fromName <{$params['replyTo']}>\n" .
|
"Reply-To: $fromName <{$replyTo}>\n" .
|
||||||
"MIME-Version: 1.0\n" .
|
"MIME-Version: 1.0\n" .
|
||||||
"Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
|
"Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
|
||||||
|
|
||||||
// assemble the final multipart message body with the text and html types included
|
// assemble the final multipart message body with the text and html types included
|
||||||
$textBody = chunk_split(base64_encode($params['textVersion']));
|
$textBody = chunk_split(base64_encode($msgText));
|
||||||
$htmlBody = chunk_split(base64_encode($params['htmlVersion']));
|
$htmlBody = chunk_split(base64_encode($msgHtml));
|
||||||
$multipartMessageBody = "--" . $mimeBoundary . "\n" . // plain text section
|
$multipartMessageBody = "--" . $mimeBoundary . "\n" . // plain text section
|
||||||
"Content-Type: text/plain; charset=UTF-8\n" .
|
"Content-Type: text/plain; charset=UTF-8\n" .
|
||||||
"Content-Transfer-Encoding: base64\n\n" .
|
"Content-Transfer-Encoding: base64\n\n" .
|
||||||
$textBody . "\n";
|
$textBody . "\n";
|
||||||
|
|
||||||
if (!$email_textonly && !is_null($params['htmlVersion'])) {
|
if (!$email_textonly && !is_null($msgHtml)) {
|
||||||
$multipartMessageBody .=
|
$multipartMessageBody .=
|
||||||
"--" . $mimeBoundary . "\n" . // text/html section
|
"--" . $mimeBoundary . "\n" . // text/html section
|
||||||
"Content-Type: text/html; charset=UTF-8\n" .
|
"Content-Type: text/html; charset=UTF-8\n" .
|
||||||
|
@ -81,14 +83,14 @@ class Emailer
|
||||||
"--" . $mimeBoundary . "--\n"; // message ending
|
"--" . $mimeBoundary . "--\n"; // message ending
|
||||||
|
|
||||||
if (DI::config()->get("system", "sendmail_params", true)) {
|
if (DI::config()->get("system", "sendmail_params", true)) {
|
||||||
$sendmail_params = '-f ' . $params['fromEmail'];
|
$sendmail_params = '-f ' . $fromEmail;
|
||||||
} else {
|
} else {
|
||||||
$sendmail_params = null;
|
$sendmail_params = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send the message
|
// send the message
|
||||||
$hookdata = [
|
$hookdata = [
|
||||||
'to' => $params['toEmail'],
|
'to' => $toEmail,
|
||||||
'subject' => $messageSubject,
|
'subject' => $messageSubject,
|
||||||
'body' => $multipartMessageBody,
|
'body' => $multipartMessageBody,
|
||||||
'headers' => $messageHeader,
|
'headers' => $messageHeader,
|
||||||
|
@ -109,7 +111,7 @@ class Emailer
|
||||||
$hookdata['headers'],
|
$hookdata['headers'],
|
||||||
$hookdata['parameters']
|
$hookdata['parameters']
|
||||||
);
|
);
|
||||||
Logger::log("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, Logger::DEBUG);
|
Logger::log("header " . 'To: ' . $toEmail . "\n" . $messageHeader, Logger::DEBUG);
|
||||||
Logger::log("return value " . (($res)?"true":"false"), Logger::DEBUG);
|
Logger::log("return value " . (($res)?"true":"false"), Logger::DEBUG);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue