diff -x CVS -urN /home/flatcap/scouts/notify-cvs/notify.inc ./notify.inc --- /home/flatcap/scouts/notify-cvs/notify.inc 2006-06-26 21:51:14.000000000 +0100 +++ ./notify.inc 2006-06-27 00:31:04.000000000 +0100 @@ -163,9 +163,14 @@ function _notify_send() { $period = variable_get('notify_send_last', time() - variable_get('notify_send', 86400)); - $separator = '------------------------------------------------------------------------------'; - $mini_separator = '---'; - + + $templates = notify_email_variables(); + + $substitute = array( + '%sitemail' => variable_get('site_mail', ini_get('sendmail_from')), + '%sitename' => mime_header_encode(variable_get('site_name', 'drupal')), + ); + $ret = array('sent' => 0, 'failed' => 0); _notify_switch_user(); // Store current user @@ -197,14 +202,14 @@ } // Set up initial values for e-mail - $from = variable_get('site_mail', ini_get('sendmail_from')); - $from_name = mime_header_encode(variable_get('site_name', 'drupal')); - $subject = t('%sitename new content notification for %username', array('%username' => $user->name, '%sitename' => variable_get('site_name', 'drupal'))); $node_body = ''; $comment_body = ''; // Write new node content to e-mail if user has permissions and nodes are ready to be sent if ($user->node && user_access('access content') && count($nodes)) { + + $substitute['%user'] = $user->name; + $substitute['%notify_url'] = url("user/$user->uid/notify", NULL, NULL, TRUE); $node_count = 0; foreach ($nodes as $node) { @@ -215,30 +220,33 @@ // TODO: Add functionality to hook into new 4.7 moderation modules if ($node->moderate) { - $status = t('Queued'); + $substitute['%status'] = t('Queued'); } elseif ($node->status == 1) { - $status = t('Published'); + $substitute['%status'] = t('Published'); } elseif ($node->status == 0) { - $status = t('Unpublished'); + $substitute['%status'] = t('Unpublished'); } if ($node_count > 0) { - $node_body .= $mini_separator . "\n\n"; + $node_body .= strtr($templates['notify_email_separator'], $substitute); } - $node_body .= ++$node_count.'. '.t('%title', array('%title' => $node->title)) ."\n"; - $node_body .= t('%status %type by %author', array('%status' => $status, '%type' => _node_names('name', $node), '%author' => ($node->name ? $node->name : variable_get('anonymous', 'Anonymous')))) ."\n"; - $node_body .= '[ '. url('node/'.$node->nid, NULL, NULL, TRUE) ." ]\n\n"; - $node_body .= _notify_content($node, $user). "\n"; + + $node_count++; + $substitute['%number'] = $node_count; + $substitute['%type'] = _node_names('name', $node); + $substitute['%title'] = $node->title; + $substitute['%url'] = url('node/'.$node->nid, NULL, NULL, TRUE); + $substitute["%author"] = ($node->name ? $node->name : variable_get('anonymous', 'Anonymous')); + + $user->teasers = 1; + $substitute["%teaser"] = _notify_content($node, $user); + $user->teasers = 2; + $substitute["%body"] = _notify_content($node, $user); + + $node_body .= strtr($templates['notify_email_entry'], $substitute); } - - //Prepend node e-mail header as long as user could access at least one node - if ($node_count > 0) { - $node_body = $separator . "\n" - . t('Recent content - %count', array('%count' => format_plural(count($nodes), '1 new node', '%count new nodes'))) ."\n" - . $separator . "\n\n" . $node_body; - } } // Write new comments to e-mail if user has permissions and there are comments to be sent @@ -280,16 +288,20 @@ } $body = $node_body . $comment_body; + $substitute['%count'] = $node_count; // If there was anything new, send mail if ($body) { - $body = t('Greetings %user,', array("%user" => $user->name))."\n\n$body"; + $from = strtr($templates['notify_email_from'], $substitute); + $headers = strtr($templates['notify_email_headers'], $substitute); + $subject = strtr($templates['notify_email_subject'], $substitute); + $prefix = strtr($templates['notify_email_prefix'], $substitute); + $suffix = strtr($templates['notify_email_suffix'], $substitute); - $body .= "\n-- \n"; - $body .= t('This is an automatic e-mail from %sitename.', array('%sitename' => variable_get('site_name', 'drupal')))."\n"; - $body .= t('To stop receiving these e-mails, change your notification preferences at %notify-url', array('%notify-url' => url("user/$user->uid/notify" , NULL, NULL, TRUE)))."\n"; + $from = mime_header_encode($from); + $body = $prefix . $body . $suffix; - if (!user_mail($user->mail, $subject, wordwrap($body, 72), "From: $from_name <$from>\nReply-to: $from_name <$from>\nReturn-path: $from_name <$from>\nX-Mailer: Drupal\nErrors-to: $from\n")) { + if (!user_mail($user->mail, $subject, wordwrap($body, 72), "From: $from\n$headers")) { $ret['failed']++; db_query('UPDATE {notify} SET attempts = attempts + 1 WHERE uid = %d', $user->uid); watchdog('error', t('Notify: User %name (%mail) could not be notified. Mail error.', array('%name' => ''. $user->name .'', '%mail' => $user->mail))); @@ -382,3 +394,17 @@ } } +function notify_email_variables() { + $vars = array(); + + $vars["notify_email_from"] = variable_get("notify_email_from", t("%sitename <%sitemail>")); + $vars["notify_email_subject"] = variable_get("notify_email_subject", t("%sitename new content notification for %user")); + $vars["notify_email_headers"] = variable_get("notify_email_headers", t("Reply-to: %sitename <%sitemail>\nReturn-path: %sitename <%sitemail>\nX-Mailer: Drupal\nErrors-to: %sitemail")); + $vars["notify_email_prefix"] = variable_get("notify_email_prefix", t("Greetings %user,\n\n------------------------------------------------------------------------------\nRecent content - %count new nodes\n------------------------------------------------------------------------------\n\n")); + $vars["notify_email_entry"] = variable_get("notify_email_entry", t("%number. %title\n%status %type by %author\n[ %url ]\n\n\n")); + $vars["notify_email_separator"] = variable_get("notify_email_separator", t("---\n\n")); + $vars["notify_email_suffix"] = variable_get("notify_email_suffix", t("\n-- \nThis is an automatic e-mail from %sitename.\nTo stop receiving these e-mails, change your notification preferences at %notify_url\n")); + + return $vars; +} + diff -x CVS -urN /home/flatcap/scouts/notify-cvs/notify.module ./notify.module --- /home/flatcap/scouts/notify-cvs/notify.module 2006-04-21 10:01:37.000000000 +0100 +++ ./notify.module 2006-06-27 00:39:26.000000000 +0100 @@ -59,6 +59,90 @@ '#options' => array(t('Disabled'), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20) ); + include_once drupal_get_path('module', 'notify') . '/notify.inc'; + $vars = notify_email_variables(); + + /* E-mail headers */ + $form['notify_email_headers'] = array( + '#type' => 'fieldset', + '#title' => t('E-mail headers'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => t('Alter the appearance of the e-mail headers.'), + ); + + $form['notify_email_headers']['notify_email_from'] = array( + '#type' => 'textfield', + '#title' => t('From'), + '#default_value' => $vars['notify_email_from'], + '#size' => 50, + '#maxlength' => 128, + '#description' => t('The e-mail will appear to be from this person.') + ); + + $form['notify_email_headers']['notify_email_subject'] = array( + '#type' => 'textfield', + '#title' => t('Subject'), + '#default_value' => $vars['notify_email_subject'], + '#size' => 50, + '#maxlength' => 128, + '#description' => t('The subject line for the e-mail.') + ); + + $form['notify_email_headers']['notify_email_headers'] = array( + '#type' => 'textarea', + '#title' => t('Extra headers'), + '#default_value' => $vars['notify_email_headers'], + '#rows' => 4, + '#maxlength' => 1024, + '#description' => t('Add extra headers to the e-mail.') + ); + + /* E-mail contents */ + $form['notify_email_contents'] = array( + '#type' => 'fieldset', + '#title' => t('E-mail contents'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => t('These settings affect the content of the email.'), + ); + + $form['notify_email_contents']['notify_email_prefix'] = array( + '#type' => 'textarea', + '#title' => t('E-mail prefix'), + '#default_value' => $vars['notify_email_prefix'], + '#rows' => 4, + '#maxlength' => 1024, + '#description' => t('Each e-mail will start with this text.') + ); + + $form['notify_email_contents']['notify_email_entry'] = array( + '#type' => 'textarea', + '#title' => t('E-mail entry'), + '#default_value' => $vars['notify_email_entry'], + '#rows' => 4, + '#maxlength' => 1024, + '#description' => t('A template for each node or comment.') + ); + + $form['notify_email_contents']['notify_email_separator'] = array( + '#type' => 'textarea', + '#title' => t('Entry separator'), + '#default_value' => $vars['notify_email_separator'], + '#rows' => 2, + '#maxlength' => 1024, + '#description' => t('Node entries will be separated by this text.') + ); + + $form['notify_email_contents']['notify_email_suffix'] = array( + '#type' => 'textarea', + '#title' => t('E-mail suffix'), + '#default_value' => $vars['notify_email_suffix'], + '#rows' => 4, + '#maxlength' => 1024, + '#description' => t('This text will be added to the bottom of each e-mail.') + ); + return $form; }