* @param User &$user user to send email to
* @param string $subject subject of the email
* @param string $body body of the email
+ * @param array $headers optional list of email headers
* @param string $address optional specification of email address
*
* @return boolean success flag
*/
-function mail_to_user(&$user, $subject, $body, $address=null)
+function mail_to_user(&$user, $subject, $body, $headers=array(), $address=null)
{
if (!$address) {
$address = $user->email;
function mail_confirm_address($user, $code, $nickname, $address)
{
+ // TRANS: Subject for address confirmation email
$subject = _('Email address confirmation');
+ // TRANS: Body for address confirmation email.
$body = sprintf(_("Hey, %s.\n\n".
"Someone just entered this email address on %s.\n\n" .
"If it was you, and you want to confirm your entry, ".
$nickname, common_config('site', 'name'),
common_local_url('confirmaddress', array('code' => $code)),
common_config('site', 'name'));
- return mail_to_user($user, $subject, $body, $address);
+ $headers = array();
+
+ return mail_to_user($user, $subject, $body, $headers, $address);
}
/**
function mail_subscribe_notify_profile($listenee, $other)
{
- if ($listenee->email && $listenee->emailnotifysub) {
-
- // use the recipient's localization
- common_init_locale($listenee->language);
+ if ($other->hasRight(Right::EMAILONSUBSCRIBE) &&
+ $listenee->email && $listenee->emailnotifysub) {
$profile = $listenee->getProfile();
$recipients = $listenee->email;
+ // use the recipient's localization
+ common_switch_locale($listenee->language);
+
+ $headers = _mail_prepare_headers('subscribe', $listenee->nickname, $other->nickname);
$headers['From'] = mail_notify_from();
$headers['To'] = $name . ' <' . $listenee->email . '>';
+ // TRANS: Subject of new-subscriber notification e-mail
$headers['Subject'] = sprintf(_('%1$s is now listening to '.
'your notices on %2$s.'),
$other->getBestName(),
common_config('site', 'name'));
+ $blocklink = sprintf(_("If you believe this account is being used abusively, " .
+ "you can block them from your subscribers list and " .
+ "report as spam to site administrators at %s"),
+ common_local_url('block', array('profileid' => $other->id)));
+
+ // TRANS: Main body of new-subscriber notification e-mail
$body = sprintf(_('%1$s is now listening to your notices on %2$s.'."\n\n".
"\t".'%3$s'."\n\n".
'%4$s'.
common_config('site', 'name'),
$other->profileurl,
($other->location) ?
- sprintf(_("Location: %s\n"), $other->location) : '',
+ // TRANS: Profile info line in new-subscriber notification e-mail
+ sprintf(_("Location: %s"), $other->location) . "\n" : '',
($other->homepage) ?
- sprintf(_("Homepage: %s\n"), $other->homepage) : '',
- ($other->bio) ?
- sprintf(_("Bio: %s\n\n"), $other->bio) : '',
+ // TRANS: Profile info line in new-subscriber notification e-mail
+ sprintf(_("Homepage: %s"), $other->homepage) . "\n" : '',
+ (($other->bio) ?
+ // TRANS: Profile info line in new-subscriber notification e-mail
+ sprintf(_("Bio: %s"), $other->bio) . "\n" : '') .
+ "\n\n" . $blocklink . "\n",
common_config('site', 'name'),
common_local_url('emailsettings'));
// reset localization
- common_init_locale();
+ common_switch_locale();
mail_send($recipients, $headers, $body);
}
}
$headers['From'] = $user->incomingemail;
$headers['To'] = $name . ' <' . $user->email . '>';
+ // TRANS: Subject of notification mail for new posting email address
$headers['Subject'] = sprintf(_('New email address for posting to %s'),
common_config('site', 'name'));
+ // TRANS: Body of notification mail for new posting email address
$body = sprintf(_("You have a new posting address on %1\$s.\n\n".
"Send email to %2\$s to post new messages.\n\n".
"More email instructions at %3\$s.\n\n".
$headers['From'] = ($incomingemail) ? $incomingemail : mail_notify_from();
$headers['To'] = $to;
+ // TRANS: Subject line for SMS-by-email notification messages
$headers['Subject'] = sprintf(_('%s status'),
$other->getBestName());
$headers['From'] = mail_notify_from();
$headers['To'] = $nickname . ' <' . $address . '>';
+ // TRANS: Subject line for SMS-by-email address confirmation message
$headers['Subject'] = _('SMS confirmation');
- // FIXME: I18N
-
- $body = "$nickname: confirm you own this phone number with this code:";
+ // TRANS: Main body heading for SMS-by-email address confirmation message
+ $body = sprintf(_("%s: confirm you own this phone number with this code:"), $nickname);
$body .= "\n\n";
$body .= $code;
$body .= "\n\n";
function mail_notify_nudge($from, $to)
{
- common_init_locale($to->language);
+ common_switch_locale($to->language);
+ // TRANS: Subject for 'nudge' notification email
$subject = sprintf(_('You\'ve been nudged by %s'), $from->nickname);
$from_profile = $from->getProfile();
+ // TRANS: Body for 'nudge' notification email
$body = sprintf(_("%1\$s (%2\$s) is wondering what you are up to ".
"these days and is inviting you to post some news.\n\n".
"So let's hear from you :)\n\n".
"%3\$s\n\n".
- "Do not reply to this email. It will not get to them.\n\n".
+ "Don't reply to this email; it won't get to them.\n\n".
"With kind regards,\n".
"%4\$s\n"),
$from_profile->getBestName(),
$from->nickname,
common_local_url('all', array('nickname' => $to->nickname)),
common_config('site', 'name'));
- common_init_locale();
- return mail_to_user($to, $subject, $body);
+ common_switch_locale();
+
+ $headers = _mail_prepare_headers('nudge', $to->nickname, $from->nickname);
+
+ return mail_to_user($to, $subject, $body, $headers);
}
/**
return true;
}
- common_init_locale($to->language);
+ common_switch_locale($to->language);
+ // TRANS: Subject for direct-message notification email
$subject = sprintf(_('New private message from %s'), $from->nickname);
$from_profile = $from->getProfile();
+ // TRANS: Body for direct-message notification email
$body = sprintf(_("%1\$s (%2\$s) sent you a private message:\n\n".
"------------------------------------------------------\n".
"%3\$s\n".
"------------------------------------------------------\n\n".
"You can reply to their message here:\n\n".
"%4\$s\n\n".
- "Do not reply to this email. It will not get to them.\n\n".
+ "Don't reply to this email; it won't get to them.\n\n".
"With kind regards,\n".
"%5\$s\n"),
$from_profile->getBestName(),
common_local_url('newmessage', array('to' => $from->id)),
common_config('site', 'name'));
- common_init_locale();
- return mail_to_user($to, $subject, $body);
+ $headers = _mail_prepare_headers('message', $to->nickname, $from->nickname);
+
+ common_switch_locale();
+ return mail_to_user($to, $subject, $body, $headers);
}
/**
* notify a user that one of their notices has been chosen as a 'fave'
*
- * Does not check that the user has an email address nor if they
+ * Doesn't check that the user has an email address nor if they
* want to receive notification of faves. Maybe this happens higher
* up the stack...?
*
function mail_notify_fave($other, $user, $notice)
{
+ if (!$user->hasRight(Right::EMAILONFAVE)) {
+ return;
+ }
+
$profile = $user->getProfile();
$bestname = $profile->getBestName();
- common_init_locale($other->language);
+ common_switch_locale($other->language);
+ // TRANS: Subject for favorite notification email
$subject = sprintf(_('%s (@%s) added your notice as a favorite'), $bestname, $user->nickname);
+ // TRANS: Body for favorite notification email
$body = sprintf(_("%1\$s (@%7\$s) just added your notice from %2\$s".
" as one of their favorites.\n\n" .
"The URL of your notice is:\n\n" .
common_config('site', 'name'),
$user->nickname);
- common_init_locale();
- mail_to_user($other, $subject, $body);
+ $headers = _mail_prepare_headers('fave', $other->nickname, $user->nickname);
+
+ common_switch_locale();
+ mail_to_user($other, $subject, $body, $headers);
}
/**
$sender = $notice->getProfile();
+ if ($sender->id == $user->id) {
+ return;
+ }
+
+ if (!$sender->hasRight(Right::EMAILONREPLY)) {
+ return;
+ }
+
$bestname = $sender->getBestName();
- common_init_locale($user->language);
-
- if ($notice->conversation != $notice->id) {
- $conversationEmailText = "The full conversation can be read here:\n\n".
- "\t%5\$s\n\n ";
- $conversationUrl = common_local_url('conversation',
- array('id' => $notice->conversation)).'#notice-'.$notice->id;
- } else {
- $conversationEmailText = "%5\$s";
- $conversationUrl = null;
- }
-
+ common_switch_locale($user->language);
+
+ if ($notice->hasConversation()) {
+ $conversationUrl = common_local_url('conversation',
+ array('id' => $notice->conversation)).'#notice-'.$notice->id;
+ // TRANS: Line in @-reply notification e-mail. %s is conversation URL.
+ $conversationEmailText = sprintf(_("The full conversation can be read here:\n\n".
+ "\t%s"), $conversationUrl) . "\n\n";
+ } else {
+ $conversationEmailText = '';
+ }
+
$subject = sprintf(_('%s (@%s) sent a notice to your attention'), $bestname, $sender->nickname);
-
- $body = sprintf(_("%1\$s (@%9\$s) just sent a notice to your attention (an '@-reply') on %2\$s.\n\n".
+
+ // TRANS: Body of @-reply notification e-mail.
+ $body = sprintf(_("%1\$s (@%9\$s) just sent a notice to your attention (an '@-reply') on %2\$s.\n\n".
"The notice is here:\n\n".
"\t%3\$s\n\n" .
"It reads:\n\n".
"\t%4\$s\n\n" .
- $conversationEmailText .
+ "%5\$s" .
"You can reply back here:\n\n".
"\t%6\$s\n\n" .
"The list of all @-replies for you here:\n\n" .
common_local_url('shownotice',
array('notice' => $notice->id)),//%3
$notice->content,//%4
- $conversationUrl,//%5
+ $conversationEmailText,//%5
common_local_url('newnotice',
array('replyto' => $sender->nickname, 'inreplyto' => $notice->id)),//%6
common_local_url('replies',
array('nickname' => $user->nickname)),//%7
common_local_url('emailsettings'), //%8
$sender->nickname); //%9
-
- common_init_locale();
- mail_to_user($user, $subject, $body);
+
+ $headers = _mail_prepare_headers('mention', $user->nickname, $sender->nickname);
+
+ common_switch_locale();
+ mail_to_user($user, $subject, $body, $headers);
+}
+
+/**
+ * Prepare the common mail headers used in notification emails
+ *
+ * @param string $msg_type type of message being sent to the user
+ * @param string $to nickname of the receipient
+ * @param string $from nickname of the user triggering the notification
+ *
+ * @return array list of mail headers to include in the message
+ */
+function _mail_prepare_headers($msg_type, $to, $from)
+{
+ $headers = array(
+ 'X-StatusNet-MessageType' => $msg_type,
+ 'X-StatusNet-TargetUser' => $to,
+ 'X-StatusNet-SourceUser' => $from,
+ 'X-StatusNet-Domain' => common_config('site', 'server')
+ );
+
+ return $headers;
}