+ if ($sender->id == $user->id) {
+ return;
+ }
+
+ if (!$sender->hasRight(Right::EMAILONREPLY)) {
+ return;
+ }
+
+ $bestname = $sender->getBestName();
+
+ 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 = '';
+ }
+
+ // TRANS: E-mail subject for notice notification.
+ // TRANS: %1$s is the sending user's long name, %2$s is the adding user's nickname.
+ $subject = sprintf(_('%1$s (@%2$s) sent a notice to your attention'), $bestname, $sender->nickname);
+
+ // TRANS: Body of @-reply notification e-mail.
+ // TRANS: %1$s is the sending user's long name, $2$s is the StatusNet sitename,
+ // TRANS: %3$s is a URL to the notice, %4$s is the notice text,
+ // TRANS: %5$s is a URL to the full conversion if it exists (otherwise empty),
+ // TRANS: %6$s is a URL to reply to the notice, %7$s is a URL to all @-replied for the addressed user,
+ // TRANS: %8$s is a URL to the addressed user's e-mail settings, %9$s is the sender's nickname.
+ $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" .
+ "%5\$s" .
+ "You can reply back here:\n\n".
+ "\t%6\$s\n\n" .
+ "The list of all @-replies for you here:\n\n" .
+ "%7\$s\n\n" .
+ "Faithfully yours,\n" .
+ "%2\$s\n\n" .
+ "P.S. You can turn off these email notifications here: %8\$s\n"),
+ $bestname,//%1
+ common_config('site', 'name'),//%2
+ common_local_url('shownotice',
+ array('notice' => $notice->id)),//%3
+ $notice->content,//%4
+ $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
+
+ $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;