new notification module working for "email message received"

This commit is contained in:
friendica 2011-12-25 23:00:19 -08:00
parent 205dcd8f5b
commit bb40e54dec
3 changed files with 66 additions and 128 deletions

View file

@ -5,7 +5,7 @@
/* /*
$notif_params = array( $notif_params = array(
'type' => NOTIFY_MAIL, 'type' => NOTIFY_MAIL,
'notify_flags' => $importer['notify_flags'], 'notify_flags' => $importer['notify-flags'],
'language' => $importer['language'], 'language' => $importer['language'],
'to_name' => $importer['username'], 'to_name' => $importer['username'],
'to_email' => $importer['email'], 'to_email' => $importer['email'],
@ -20,6 +20,8 @@
function notification($params) { function notification($params) {
logger('notification: entry');
$a = get_app(); $a = get_app();
$banner = t('Friendica Notification'); $banner = t('Friendica Notification');
$product = FRIENDICA_PLATFORM; $product = FRIENDICA_PLATFORM;
@ -36,78 +38,84 @@ function notification($params) {
if($params['type'] == NOTIFY_MAIL) { if($params['type'] == NOTIFY_MAIL) {
logger('notification: email');
$subject = sprintf( t('New mail received at %s'),$sitename); $subject = sprintf( t('New mail received at %s'),$sitename);
$preamble = sprintf( t('%s sent you a new private message at %s.'),$params['source_name'],$sitename); $preamble = sprintf( t('%s sent you a new private message at %s.'),$params['source_name'],$sitename);
$sitelink = t('Please visit %s to view and/or reply to your private messages.');
$tsitelink = sprintf( $email_visit, $siteurl . '/message' );
$hsitelink = sprintf( $email_visit, '<a href="' . $siteurl . '/message">' . $sitename . '</a>');
$sitelink = t('Please visit %s to view and/or reply to your private messages.');
$tsitelink = sprintf( $sitelink, $siteurl . '/message' );
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/message">' . $sitename . '</a>');
} }
// send email notification if notification preferences permit // send email notification if notification preferences permit
require_once('bbcode.php'); require_once('bbcode.php');
if(intval($params['notify-flags']) & intval($params['type'])) { if(intval($params['notify_flags']) & intval($params['type'])) {
logger('notification: sending email');
push_lang($params['language']); push_lang($params['language']);
$msg = array(); $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
$msg['fromname'] = $sender_name; $body))),ENT_QUOTES,'UTF-8'));
$msg['fromemail'] = $sender_email; $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
"<br />\n",$body))));
$msg['textversion'] = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
$body))),ENT_QUOTES,'UTF-8'));
$msg['htmlversion'] = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
"<br />\n",$body))));
// load the template for private message notifications // load the template for private message notifications
$tpl = get_view_template('email_notify_html.tpl'); $tpl = get_markup_template('email_notify_html.tpl');
$email_html_body_tpl = replace_macros($tpl,array( $email_html_body = replace_macros($tpl,array(
'$banner' => $banner, '$banner' => $banner,
'$product' => $product, '$product' => $product,
'$preamble' => $preamble, '$preamble' => $preamble,
'$source_name' => $parama['source_name'], '$sitename' => $sitename,
'$source_link' => $params['source_link'], '$siteurl' => $siteurl,
'$source_name' => $parama['source_name'],
'$source_link' => $params['source_link'],
'$source_photo' => $params['source_photo'], '$source_photo' => $params['source_photo'],
'$username' => $params['to_name'], '$username' => $params['to_name'],
'$hsitelink' => $hsitelink, '$hsitelink' => $hsitelink,
'$thanks' => $thanks, '$thanks' => $thanks,
'$site_admin' => $site_admin, '$site_admin' => $site_admin,
'$title' => stripslashes($msg['title']), // subject of the message '$title' => stripslashes($title),
'$htmlversion' => $msg['htmlversion'], // html version of the message '$htmlversion' => $htmlversion,
)); ));
// load the template for private message notifications // load the template for private message notifications
$tpl = get_intltext_template('mail_received_text_body_eml.tpl'); $tpl = get_markup_template('email_notify_text.tpl');
$email_text_body_tpl = replace_macros($tpl,array( $email_text_body = replace_macros($tpl,array(
'$username' => $importer['username'], '$banner' => $banner,
'$siteName' => $a->config['sitename'], // name of this site '$product' => $product,
'$siteurl' => $a->get_baseurl(), // descriptive url of this site '$preamble' => $preamble,
'$thumb' => $importer['thumb'], // thumbnail url for sender icon '$sitename' => $sitename,
'$email' => $importer['email'], // email address to send to '$siteurl' => $siteurl,
'$url' => $importer['url'], // full url for the site '$source_name' => $parama['source_name'],
'$from' => $msg['from-name'], // name of the person sending the message '$source_link' => $params['source_link'],
'$title' => stripslashes($msg['title']), // subject of the message '$source_photo' => $params['source_photo'],
'$textversion' => $msg['textversion'], // text version of the message '$username' => $params['to_name'],
'$mimeboundary' => $msg['mimeboundary'], // mime message divider '$tsitelink' => $tsitelink,
'$hostname' => $a->get_hostname() // name of this host '$thanks' => $thanks,
'$site_admin' => $site_admin,
'$title' => stripslashes($title),
'$textversion' => $textversion,
)); ));
logger('text: ' . $email_text_body);
// use the EmailNotification library to send the message // use the EmailNotification library to send the message
require_once("include/EmailNotification.php");
EmailNotification::sendTextHtmlEmail( enotify::send(array(
$msg['notificationfromname'], 'fromName' => $sender_name,
$msg['notificationfromemail'], 'fromEmail' => $sender_email,
$msg['notificationfromemail'], 'replyTo' => $sender_email,
$importer['email'], 'toEmail' => $params['to_email'],
$subject, 'messageSubject' => $subject,
$email_html_body_tpl, 'htmlVersion' => $email_html_body,
$email_text_body_tpl 'textVersion' => $email_text_body
); ));
pop_lang(); pop_lang();
} }
} }
@ -126,6 +134,8 @@ class enotify {
* @param textVersion text only version of the message * @param textVersion text only version of the message
*/ */
static public function send($params) { static public function send($params) {
logger('enotify: send: ' . print_r($params,true));
$fromName = email_header_encode($params['fromName'],'UTF-8'); $fromName = email_header_encode($params['fromName'],'UTF-8');
$messageSubject = email_header_encode($params['messageSubject'],'UTF-8'); $messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
@ -159,8 +169,8 @@ class enotify {
// send the message // send the message
$res = mail( $res = mail(
$toEmail, // send to address $params['toEmail'], // send to address
$messageSubject, // subject $params['messageSubject'], // subject
$multipartMessageBody, // message body $multipartMessageBody, // message body
$messageHeader // message headers $messageHeader // message headers
); );

View file

@ -1822,11 +1822,13 @@ function local_delivery($importer,$data) {
$r = dbq("INSERT INTO `mail` (`" . implode("`, `", array_keys($msg)) $r = dbq("INSERT INTO `mail` (`" . implode("`, `", array_keys($msg))
. "`) VALUES ('" . implode("', '", array_values($msg)) . "')" ); . "`) VALUES ('" . implode("', '", array_values($msg)) . "')" );
// send email notification if requested. // send notifications.
require_once('include/enotify.php');
$notif_params = array( $notif_params = array(
'type' => NOTIFY_MAIL, 'type' => NOTIFY_MAIL,
'notify_flags' => $importer['notify_flags'], 'notify_flags' => $importer['notify-flags'],
'language' => $importer['language'], 'language' => $importer['language'],
'to_name' => $importer['username'], 'to_name' => $importer['username'],
'to_email' => $importer['email'], 'to_email' => $importer['email'],
@ -1836,84 +1838,9 @@ function local_delivery($importer,$data) {
'source_photo' => $importer['thumb'], 'source_photo' => $importer['thumb'],
); );
//notification($notif_params); notification($notif_params);
require_once('bbcode.php');
if($importer['notify-flags'] & NOTIFY_MAIL) {
push_lang($importer['language']);
// name of the automated email sender
$msg['notificationfromname'] = t('Administrator');
// noreply address to send from
$msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
// text version
// process the message body to display properly in text mode
// 1) substitute a \n character for the "\" then "n", so it behaves properly (it doesn't come in as a \n character)
// 2) remove escape slashes
// 3) decode any bbcode from the message editor
// 4) decode any encoded html tags
// 5) remove html tags
$msg['textversion']
= strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",$msg['body']))),ENT_QUOTES,'UTF-8'));
// html version
// process the message body to display properly in text mode
// 1) substitute a <br /> tag for the "\" then "n", so it behaves properly (it doesn't come in as a \n character)
// 2) remove escape slashes
// 3) decode any bbcode from the message editor
// 4) decode any encoded html tags
$msg['htmlversion']
= html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$msg['body']))));
// load the template for private message notifications
$tpl = get_intltext_template('mail_received_html_body_eml.tpl');
$email_html_body_tpl = replace_macros($tpl,array(
'$username' => $importer['username'],
'$siteName' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site
'$thumb' => $importer['thumb'], // thumbnail url for sender icon
'$email' => $importer['email'], // email address to send to
'$url' => $importer['url'], // full url for the site
'$from' => $msg['from-name'], // name of the person sending the message
'$title' => stripslashes($msg['title']), // subject of the message
'$htmlversion' => $msg['htmlversion'], // html version of the message
'$mimeboundary' => $msg['mimeboundary'], // mime message divider
'$hostname' => $a->get_hostname() // name of this host
));
// load the template for private message notifications
$tpl = get_intltext_template('mail_received_text_body_eml.tpl');
$email_text_body_tpl = replace_macros($tpl,array(
'$username' => $importer['username'],
'$siteName' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site
'$thumb' => $importer['thumb'], // thumbnail url for sender icon
'$email' => $importer['email'], // email address to send to
'$url' => $importer['url'], // full url for the site
'$from' => $msg['from-name'], // name of the person sending the message
'$title' => stripslashes($msg['title']), // subject of the message
'$textversion' => $msg['textversion'], // text version of the message
'$mimeboundary' => $msg['mimeboundary'], // mime message divider
'$hostname' => $a->get_hostname() // name of this host
));
// use the EmailNotification library to send the message
require_once("include/EmailNotification.php");
EmailNotification::sendTextHtmlEmail(
$msg['notificationfromname'],
$msg['notificationfromemail'],
$msg['notificationfromemail'],
$importer['email'],
t('New mail received at ') . $a->config['sitename'],
$email_html_body_tpl,
$email_text_body_tpl
);
pop_lang();
}
return 0; return 0;
// NOTREACHED // NOTREACHED
} }

View file

@ -1,3 +1,4 @@
$preamble $preamble
$title $title