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(
'type' => NOTIFY_MAIL,
'notify_flags' => $importer['notify_flags'],
'notify_flags' => $importer['notify-flags'],
'language' => $importer['language'],
'to_name' => $importer['username'],
'to_email' => $importer['email'],
@ -20,6 +20,8 @@
function notification($params) {
logger('notification: entry');
$a = get_app();
$banner = t('Friendica Notification');
$product = FRIENDICA_PLATFORM;
@ -36,38 +38,40 @@ function notification($params) {
if($params['type'] == NOTIFY_MAIL) {
logger('notification: email');
$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);
$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
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']);
$msg = array();
$msg['fromname'] = $sender_name;
$msg['fromemail'] = $sender_email;
$msg['textversion'] = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
$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"),
$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
$tpl = get_view_template('email_notify_html.tpl');
$email_html_body_tpl = replace_macros($tpl,array(
$tpl = get_markup_template('email_notify_html.tpl');
$email_html_body = replace_macros($tpl,array(
'$banner' => $banner,
'$product' => $product,
'$preamble' => $preamble,
'$sitename' => $sitename,
'$siteurl' => $siteurl,
'$source_name' => $parama['source_name'],
'$source_link' => $params['source_link'],
'$source_photo' => $params['source_photo'],
@ -75,38 +79,42 @@ function notification($params) {
'$hsitelink' => $hsitelink,
'$thanks' => $thanks,
'$site_admin' => $site_admin,
'$title' => stripslashes($msg['title']), // subject of the message
'$htmlversion' => $msg['htmlversion'], // html version of the message
'$title' => stripslashes($title),
'$htmlversion' => $htmlversion,
));
// 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
$tpl = get_markup_template('email_notify_text.tpl');
$email_text_body = replace_macros($tpl,array(
'$banner' => $banner,
'$product' => $product,
'$preamble' => $preamble,
'$sitename' => $sitename,
'$siteurl' => $siteurl,
'$source_name' => $parama['source_name'],
'$source_link' => $params['source_link'],
'$source_photo' => $params['source_photo'],
'$username' => $params['to_name'],
'$tsitelink' => $tsitelink,
'$thanks' => $thanks,
'$site_admin' => $site_admin,
'$title' => stripslashes($title),
'$textversion' => $textversion,
));
logger('text: ' . $email_text_body);
// use the EmailNotification library to send the message
require_once("include/EmailNotification.php");
EmailNotification::sendTextHtmlEmail(
$msg['notificationfromname'],
$msg['notificationfromemail'],
$msg['notificationfromemail'],
$importer['email'],
$subject,
$email_html_body_tpl,
$email_text_body_tpl
);
enotify::send(array(
'fromName' => $sender_name,
'fromEmail' => $sender_email,
'replyTo' => $sender_email,
'toEmail' => $params['to_email'],
'messageSubject' => $subject,
'htmlVersion' => $email_html_body,
'textVersion' => $email_text_body
));
pop_lang();
}
}
@ -126,6 +134,8 @@ class enotify {
* @param textVersion text only version of the message
*/
static public function send($params) {
logger('enotify: send: ' . print_r($params,true));
$fromName = email_header_encode($params['fromName'],'UTF-8');
$messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
@ -159,8 +169,8 @@ class enotify {
// send the message
$res = mail(
$toEmail, // send to address
$messageSubject, // subject
$params['toEmail'], // send to address
$params['messageSubject'], // subject
$multipartMessageBody, // message body
$messageHeader // message headers
);

View File

@ -1822,11 +1822,13 @@ function local_delivery($importer,$data) {
$r = dbq("INSERT INTO `mail` (`" . implode("`, `", array_keys($msg))
. "`) VALUES ('" . implode("', '", array_values($msg)) . "')" );
// send email notification if requested.
// send notifications.
require_once('include/enotify.php');
$notif_params = array(
'type' => NOTIFY_MAIL,
'notify_flags' => $importer['notify_flags'],
'notify_flags' => $importer['notify-flags'],
'language' => $importer['language'],
'to_name' => $importer['username'],
'to_email' => $importer['email'],
@ -1836,84 +1838,9 @@ function local_delivery($importer,$data) {
'source_photo' => $importer['thumb'],
);
//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();
}
notification($notif_params);
return 0;
// NOTREACHED
}

View File

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