]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/mail.php
Merge branch 'master' into 0.9.x
[quix0rs-gnu-social.git] / lib / mail.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * utilities for sending email
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Mail
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Zach Copley <zach@status.net>
26  * @author    Robin Millette <millette@status.net>
27  * @author    Sarven Capadisli <csarven@status.net>
28  * @copyright 2008 StatusNet, Inc.
29  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30  * @link      http://status.net/
31  */
32
33 if (!defined('STATUSNET') && !defined('LACONICA')) {
34     exit(1);
35 }
36
37 require_once 'Mail.php';
38
39 /**
40  * return the configured mail backend
41  *
42  * Uses the $config array to make a mail backend. Cached so it is safe to call
43  * more than once.
44  *
45  * @return Mail backend
46  */
47
48 function mail_backend()
49 {
50     static $backend = null;
51
52     if (!$backend) {
53         $backend = Mail::factory(common_config('mail', 'backend'),
54                                  (common_config('mail', 'params')) ?
55                                  common_config('mail', 'params') :
56                                  array());
57         if (PEAR::isError($backend)) {
58             common_server_error($backend->getMessage(), 500);
59         }
60     }
61     return $backend;
62 }
63
64 /**
65  * send an email to one or more recipients
66  *
67  * @param array  $recipients array of strings with email addresses of recipients
68  * @param array  $headers    array mapping strings to strings for email headers
69  * @param string $body       body of the email
70  *
71  * @return boolean success flag
72  */
73
74 function mail_send($recipients, $headers, $body)
75 {
76     // XXX: use Mail_Queue... maybe
77     $backend = mail_backend();
78     if (!isset($headers['Content-Type'])) {
79         $headers['Content-Type'] = 'text/plain; charset=UTF-8';
80     }
81     assert($backend); // throws an error if it's bad
82     $sent = $backend->send($recipients, $headers, $body);
83     if (PEAR::isError($sent)) {
84         common_log(LOG_ERR, 'Email error: ' . $sent->getMessage());
85         return false;
86     }
87     return true;
88 }
89
90 /**
91  * returns the configured mail domain
92  *
93  * Defaults to the server name.
94  *
95  * @return string mail domain, suitable for making email addresses.
96  */
97
98 function mail_domain()
99 {
100     $maildomain = common_config('mail', 'domain');
101     if (!$maildomain) {
102         $maildomain = common_config('site', 'server');
103     }
104     return $maildomain;
105 }
106
107 /**
108  * returns a good address for sending email from this server
109  *
110  * Uses either the configured value or a faked-up value made
111  * from the mail domain.
112  *
113  * @return string notify from address
114  */
115
116 function mail_notify_from()
117 {
118     $notifyfrom = common_config('mail', 'notifyfrom');
119
120     if (!$notifyfrom) {
121
122         $domain = mail_domain();
123
124         $notifyfrom = '"'.common_config('site', 'name') .'" <noreply@'.$domain.'>';
125     }
126
127     return $notifyfrom;
128 }
129
130 /**
131  * sends email to a user
132  *
133  * @param User   &$user   user to send email to
134  * @param string $subject subject of the email
135  * @param string $body    body of the email
136  * @param array  $headers optional list of email headers
137  * @param string $address optional specification of email address
138  *
139  * @return boolean success flag
140  */
141
142 function mail_to_user(&$user, $subject, $body, $headers=array(), $address=null)
143 {
144     if (!$address) {
145         $address = $user->email;
146     }
147
148     $recipients = $address;
149     $profile    = $user->getProfile();
150
151     $headers['From']    = mail_notify_from();
152     $headers['To']      = $profile->getBestName() . ' <' . $address . '>';
153     $headers['Subject'] = $subject;
154
155     return mail_send($recipients, $headers, $body);
156 }
157
158 /**
159  * Send an email to confirm a user's control of an email address
160  *
161  * @param User   $user     User claiming the email address
162  * @param string $code     Confirmation code
163  * @param string $nickname Nickname of user
164  * @param string $address  email address to confirm
165  *
166  * @see common_confirmation_code()
167  *
168  * @return success flag
169  */
170
171 function mail_confirm_address($user, $code, $nickname, $address)
172 {
173     // TRANS: Subject for address confirmation email.
174     $subject = _('Email address confirmation');
175
176     // TRANS: Body for address confirmation email.
177     // TRANS: %1$s is the addressed user's nickname, %2$s is the StatusNet sitename,
178     // TRANS: %3$s is the URL to confirm at.
179     $body = sprintf(_("Hey, %1\$s.\n\n".
180                       "Someone just entered this email address on %2\$s.\n\n" .
181                       "If it was you, and you want to confirm your entry, ".
182                       "use the URL below:\n\n\t%3\$s\n\n" .
183                       "If not, just ignore this message.\n\n".
184                       "Thanks for your time, \n%2\$s\n"),
185                     $nickname,
186                     common_config('site', 'name'),
187                     common_local_url('confirmaddress', array('code' => $code)));
188     $headers = array();
189
190     return mail_to_user($user, $subject, $body, $headers, $address);
191 }
192
193 /**
194  * notify a user of subscription by another user
195  *
196  * This is just a wrapper around the profile-based version.
197  *
198  * @param User $listenee user who is being subscribed to
199  * @param User $listener user who is subscribing
200  *
201  * @see mail_subscribe_notify_profile()
202  *
203  * @return void
204  */
205
206 function mail_subscribe_notify($listenee, $listener)
207 {
208     $other = $listener->getProfile();
209     mail_subscribe_notify_profile($listenee, $other);
210 }
211
212 /**
213  * notify a user of subscription by a profile (remote or local)
214  *
215  * This function checks to see if the listenee has an email
216  * address and wants subscription notices.
217  *
218  * @param User    $listenee user who's being subscribed to
219  * @param Profile $other    profile of person who's listening
220  *
221  * @return void
222  */
223
224 function mail_subscribe_notify_profile($listenee, $other)
225 {
226     if ($other->hasRight(Right::EMAILONSUBSCRIBE) &&
227         $listenee->email && $listenee->emailnotifysub) {
228
229         $profile = $listenee->getProfile();
230
231         $name = $profile->getBestName();
232
233         $long_name = ($other->fullname) ?
234           ($other->fullname . ' (' . $other->nickname . ')') : $other->nickname;
235
236         $recipients = $listenee->email;
237
238         // use the recipient's localization
239         common_switch_locale($listenee->language);
240
241         $headers = _mail_prepare_headers('subscribe', $listenee->nickname, $other->nickname);
242         $headers['From']    = mail_notify_from();
243         $headers['To']      = $name . ' <' . $listenee->email . '>';
244         // TRANS: Subject of new-subscriber notification e-mail.
245         // TRANS: %1$s is the subscribing user's nickname, %2$s is the StatusNet sitename.
246         $headers['Subject'] = sprintf(_('%1$s is now listening to '.
247                                         'your notices on %2$s.'),
248                                       $other->getBestName(),
249                                       common_config('site', 'name'));
250
251         // TRANS: This is a paragraph in a new-subscriber e-mail.
252         // TRANS: %s is a URL where the subscriber can be reported as abusive.
253         $blocklink = sprintf(_("If you believe this account is being used abusively, " .
254                                "you can block them from your subscribers list and " .
255                                "report as spam to site administrators at %s"),
256                              common_local_url('block', array('profileid' => $other->id)));
257
258         // TRANS: Main body of new-subscriber notification e-mail.
259         // TRANS: %1$s is the subscriber's long name, %2$s is the StatusNet sitename,
260         // TRANS: %3$s is the subscriber's profile URL, %4$s is the subscriber's location (or empty)
261         // TRANS: %5$s is the subscriber's homepage URL (or empty), %6%s is the subscriber's bio (or empty)
262         // TRANS: %7$s is a link to the addressed user's e-mail settings.
263         $body = sprintf(_('%1$s is now listening to your notices on %2$s.'."\n\n".
264                           "\t".'%3$s'."\n\n".
265                           '%4$s'.
266                           '%5$s'.
267                           '%6$s'.
268                           "\n".'Faithfully yours,'."\n".'%2$s.'."\n\n".
269                           "----\n".
270                           "Change your email address or ".
271                           "notification options at ".'%7$s' ."\n"),
272                         $long_name,
273                         common_config('site', 'name'),
274                         $other->profileurl,
275                         ($other->location) ?
276                         // TRANS: Profile info line in new-subscriber notification e-mail.
277                         // TRANS: %s is a location.
278                         sprintf(_("Location: %s"), $other->location) . "\n" : '',
279                         ($other->homepage) ?
280                         // TRANS: Profile info line in new-subscriber notification e-mail.
281                         // TRANS: %s is a homepage.
282                         sprintf(_("Homepage: %s"), $other->homepage) . "\n" : '',
283                         (($other->bio) ?
284                             // TRANS: Profile info line in new-subscriber notification e-mail.
285                             // TRANS: %s is biographical information.
286                             sprintf(_("Bio: %s"), $other->bio) . "\n" : '') .
287                             "\n\n" . $blocklink . "\n",
288                         common_local_url('emailsettings'));
289
290         // reset localization
291         common_switch_locale();
292         mail_send($recipients, $headers, $body);
293     }
294 }
295
296 /**
297  * notify a user of their new incoming email address
298  *
299  * User's email and incoming fields should already be updated.
300  *
301  * @param User $user user with the new address
302  *
303  * @return void
304  */
305 function mail_new_incoming_notify($user)
306 {
307     $profile = $user->getProfile();
308
309     $name = $profile->getBestName();
310
311     $headers['From']    = $user->incomingemail;
312     $headers['To']      = $name . ' <' . $user->email . '>';
313     // TRANS: Subject of notification mail for new posting email address.
314     // TRANS: %s is the StatusNet sitename.
315     $headers['Subject'] = sprintf(_('New email address for posting to %s'),
316                                   common_config('site', 'name'));
317
318     // TRANS: Body of notification mail for new posting email address.
319     // TRANS: %1$s is the StatusNet sitename, %2$s is the e-mail address to send
320     // TRANS: to to post by e-mail, %3$s is a URL to more instructions.
321     $body = sprintf(_("You have a new posting address on %1\$s.\n\n".
322                       "Send email to %2\$s to post new messages.\n\n".
323                       "More email instructions at %3\$s.\n\n".
324                       "Faithfully yours,\n%1\$s"),
325                     common_config('site', 'name'),
326                     $user->incomingemail,
327                     common_local_url('doc', array('title' => 'email')));
328
329     mail_send($user->email, $headers, $body);
330 }
331
332 /**
333  * generate a new address for incoming messages
334  *
335  * @todo check the database for uniqueness
336  *
337  * @return string new email address for incoming messages
338  */
339 function mail_new_incoming_address()
340 {
341     $prefix = common_confirmation_code(64);
342     $suffix = mail_domain();
343     return $prefix . '@' . $suffix;
344 }
345
346 /**
347  * broadcast a notice to all subscribers with SMS notification on
348  *
349  * This function sends SMS messages to all users who have sms addresses;
350  * have sms notification on; and have sms enabled for this particular
351  * subscription.
352  *
353  * @param Notice $notice The notice to broadcast
354  *
355  * @return success flag
356  */
357 function mail_broadcast_notice_sms($notice)
358 {
359     // Now, get users subscribed to this profile
360
361     $user = new User();
362
363     $UT = common_config('db','type')=='pgsql'?'"user"':'user';
364     $user->query('SELECT nickname, smsemail, incomingemail ' .
365                  "FROM $UT JOIN subscription " .
366                  "ON $UT.id = subscription.subscriber " .
367                  'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' .
368                  'AND subscription.subscribed != subscription.subscriber ' .
369                  "AND $UT.smsemail IS NOT null " .
370                  "AND $UT.smsnotify = 1 " .
371                  'AND subscription.sms = 1 ');
372
373     while ($user->fetch()) {
374         common_log(LOG_INFO,
375                    'Sending notice ' . $notice->id . ' to ' . $user->smsemail,
376                    __FILE__);
377         $success = mail_send_sms_notice_address($notice,
378                                                 $user->smsemail,
379                                                 $user->incomingemail);
380         if (!$success) {
381             // XXX: Not sure, but I think that's the right thing to do
382             common_log(LOG_WARNING,
383                        'Sending notice ' . $notice->id . ' to ' .
384                        $user->smsemail . ' FAILED, cancelling.',
385                        __FILE__);
386             return false;
387         }
388     }
389
390     $user->free();
391     unset($user);
392
393     return true;
394 }
395
396 /**
397  * send a notice to a user via SMS
398  *
399  * A convenience wrapper around mail_send_sms_notice_address()
400  *
401  * @param Notice $notice notice to send
402  * @param User   $user   user to receive notice
403  *
404  * @see mail_send_sms_notice_address()
405  *
406  * @return boolean success flag
407  */
408 function mail_send_sms_notice($notice, $user)
409 {
410     return mail_send_sms_notice_address($notice,
411                                         $user->smsemail,
412                                         $user->incomingemail);
413 }
414
415 /**
416  * send a notice to an SMS email address from a given address
417  *
418  * We use the user's incoming email address as the "From" address to make
419  * replying to notices easier.
420  *
421  * @param Notice $notice        notice to send
422  * @param string $smsemail      email address to send to
423  * @param string $incomingemail email address to set as 'from'
424  *
425  * @return boolean success flag
426  */
427 function mail_send_sms_notice_address($notice, $smsemail, $incomingemail)
428 {
429     $to = $nickname . ' <' . $smsemail . '>';
430
431     $other = $notice->getProfile();
432
433     common_log(LOG_INFO, 'Sending notice ' . $notice->id .
434                ' to ' . $smsemail, __FILE__);
435
436     $headers = array();
437
438     $headers['From']    = ($incomingemail) ? $incomingemail : mail_notify_from();
439     $headers['To']      = $to;
440     // TRANS: Subject line for SMS-by-email notification messages.
441     // TRANS: %s is the posting user's nickname.
442     $headers['Subject'] = sprintf(_('%s status'),
443                                   $other->getBestName());
444
445     $body = $notice->content;
446
447     return mail_send($smsemail, $headers, $body);
448 }
449
450 /**
451  * send a message to confirm a claim for an SMS number
452  *
453  * @param string $code     confirmation code
454  * @param string $nickname nickname of user claiming number
455  * @param string $address  email address to send the confirmation to
456  *
457  * @see common_confirmation_code()
458  *
459  * @return void
460  */
461 function mail_confirm_sms($code, $nickname, $address)
462 {
463     $recipients = $address;
464
465     $headers['From']    = mail_notify_from();
466     $headers['To']      = $nickname . ' <' . $address . '>';
467     // TRANS: Subject line for SMS-by-email address confirmation message.
468     $headers['Subject'] = _('SMS confirmation');
469
470     // TRANS: Main body heading for SMS-by-email address confirmation message.
471     // TRANS: %s is the addressed user's nickname.
472     $body  = sprintf(_("%s: confirm you own this phone number with this code:"), $nickname);
473     $body .= "\n\n";
474     $body .= $code;
475     $body .= "\n\n";
476
477     mail_send($recipients, $headers, $body);
478 }
479
480 /**
481  * send a mail message to notify a user of a 'nudge'
482  *
483  * @param User $from user nudging
484  * @param User $to   user being nudged
485  *
486  * @return boolean success flag
487  */
488 function mail_notify_nudge($from, $to)
489 {
490     common_switch_locale($to->language);
491     // TRANS: Subject for 'nudge' notification email.
492     // TRANS: %s is the nudging user.
493     $subject = sprintf(_('You\'ve been nudged by %s'), $from->nickname);
494
495     $from_profile = $from->getProfile();
496
497     // TRANS: Body for 'nudge' notification email.
498     // TRANS: %1$s is the nuding user's long name, $2$s is the nudging user's nickname,
499     // TRANS: %3$s is a URL to post notices at, %4$s is the StatusNet sitename.
500     $body = sprintf(_("%1\$s (%2\$s) is wondering what you are up to ".
501                       "these days and is inviting you to post some news.\n\n".
502                       "So let's hear from you :)\n\n".
503                       "%3\$s\n\n".
504                       "Don't reply to this email; it won't get to them.\n\n".
505                       "With kind regards,\n".
506                       "%4\$s\n"),
507                     $from_profile->getBestName(),
508                     $from->nickname,
509                     common_local_url('all', array('nickname' => $to->nickname)),
510                     common_config('site', 'name'));
511     common_switch_locale();
512
513     $headers = _mail_prepare_headers('nudge', $to->nickname, $from->nickname);
514
515     return mail_to_user($to, $subject, $body, $headers);
516 }
517
518 /**
519  * send a message to notify a user of a direct message (DM)
520  *
521  * This function checks to see if the recipient wants notification
522  * of DMs and has a configured email address.
523  *
524  * @param Message $message message to notify about
525  * @param User    $from    user sending message; default to sender
526  * @param User    $to      user receiving message; default to recipient
527  *
528  * @return boolean success code
529  */
530 function mail_notify_message($message, $from=null, $to=null)
531 {
532     if (is_null($from)) {
533         $from = User::staticGet('id', $message->from_profile);
534     }
535
536     if (is_null($to)) {
537         $to = User::staticGet('id', $message->to_profile);
538     }
539
540     if (is_null($to->email) || !$to->emailnotifymsg) {
541         return true;
542     }
543
544     common_switch_locale($to->language);
545     // TRANS: Subject for direct-message notification email.
546     // TRANS: %s is the sending user's nickname.
547     $subject = sprintf(_('New private message from %s'), $from->nickname);
548
549     $from_profile = $from->getProfile();
550
551     // TRANS: Body for direct-message notification email.
552     // TRANS: %1$s is the sending user's long name, %2$s is the sending user's nickname,
553     // TRANS: %3$s is the message content, %4$s a URL to the message,
554     // TRANS: %5$s is the StatusNet sitename.
555     $body = sprintf(_("%1\$s (%2\$s) sent you a private message:\n\n".
556                       "------------------------------------------------------\n".
557                       "%3\$s\n".
558                       "------------------------------------------------------\n\n".
559                       "You can reply to their message here:\n\n".
560                       "%4\$s\n\n".
561                       "Don't reply to this email; it won't get to them.\n\n".
562                       "With kind regards,\n".
563                       "%5\$s\n"),
564                     $from_profile->getBestName(),
565                     $from->nickname,
566                     $message->content,
567                     common_local_url('newmessage', array('to' => $from->id)),
568                     common_config('site', 'name'));
569
570     $headers = _mail_prepare_headers('message', $to->nickname, $from->nickname);
571
572     common_switch_locale();
573     return mail_to_user($to, $subject, $body, $headers);
574 }
575
576 /**
577  * notify a user that one of their notices has been chosen as a 'fave'
578  *
579  * Doesn't check that the user has an email address nor if they
580  * want to receive notification of faves. Maybe this happens higher
581  * up the stack...?
582  *
583  * @param User   $other  The user whose notice was faved
584  * @param User   $user   The user who faved the notice
585  * @param Notice $notice The notice that was faved
586  *
587  * @return void
588  */
589 function mail_notify_fave($other, $user, $notice)
590 {
591     if (!$user->hasRight(Right::EMAILONFAVE)) {
592         return;
593     }
594
595     $profile = $user->getProfile();
596     if ($other->hasBlocked($profile)) {
597         // If the author has blocked us, don't spam them with a notification.
598         return;
599     }
600
601     $bestname = $profile->getBestName();
602
603     common_switch_locale($other->language);
604
605     // TRANS: Subject for favorite notification e-mail.
606     // TRANS: %1$s is the adding user's long name, %2$s is the adding user's nickname.
607     $subject = sprintf(_('%1$s (@%2$s) added your notice as a favorite'), $bestname, $user->nickname);
608
609     // TRANS: Body for favorite notification e-mail.
610     // TRANS: %1$s is the adding user's long name, $2$s is the date the notice was created,
611     // TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text,
612     // TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename,
613     // TRANS: %7$s is the adding user's nickname.
614     $body = sprintf(_("%1\$s (@%7\$s) just added your notice from %2\$s".
615                       " as one of their favorites.\n\n" .
616                       "The URL of your notice is:\n\n" .
617                       "%3\$s\n\n" .
618                       "The text of your notice is:\n\n" .
619                       "%4\$s\n\n" .
620                       "You can see the list of %1\$s's favorites here:\n\n" .
621                       "%5\$s\n\n" .
622                       "Faithfully yours,\n" .
623                       "%6\$s\n"),
624                     $bestname,
625                     common_exact_date($notice->created),
626                     common_local_url('shownotice',
627                                      array('notice' => $notice->id)),
628                     $notice->content,
629                     common_local_url('showfavorites',
630                                      array('nickname' => $user->nickname)),
631                     common_config('site', 'name'),
632                     $user->nickname);
633
634     $headers = _mail_prepare_headers('fave', $other->nickname, $user->nickname);
635
636     common_switch_locale();
637     mail_to_user($other, $subject, $body, $headers);
638 }
639
640 /**
641  * notify a user that they have received an "attn:" message AKA "@-reply"
642  *
643  * @param User   $user   The user who recevied the notice
644  * @param Notice $notice The notice that was sent
645  *
646  * @return void
647  */
648 function mail_notify_attn($user, $notice)
649 {
650     if (!$user->email || !$user->emailnotifyattn) {
651         return;
652     }
653
654     $sender = $notice->getProfile();
655
656     if ($sender->id == $user->id) {
657         return;
658     }
659
660     if (!$sender->hasRight(Right::EMAILONREPLY)) {
661         return;
662     }
663
664     $bestname = $sender->getBestName();
665
666     common_switch_locale($user->language);
667
668     if ($notice->hasConversation()) {
669         $conversationUrl = common_local_url('conversation',
670                          array('id' => $notice->conversation)).'#notice-'.$notice->id;
671         // TRANS: Line in @-reply notification e-mail. %s is conversation URL.
672         $conversationEmailText = sprintf(_("The full conversation can be read here:\n\n".
673                                            "\t%s"), $conversationUrl) . "\n\n";
674     } else {
675         $conversationEmailText = '';
676     }
677
678     // TRANS: E-mail subject for notice notification.
679     // TRANS: %1$s is the sending user's long name, %2$s is the adding user's nickname.
680     $subject = sprintf(_('%1$s (@%2$s) sent a notice to your attention'), $bestname, $sender->nickname);
681
682         // TRANS: Body of @-reply notification e-mail.
683         // TRANS: %1$s is the sending user's long name, $2$s is the StatusNet sitename,
684         // TRANS: %3$s is a URL to the notice, %4$s is the notice text,
685         // TRANS: %5$s is a URL to the full conversion if it exists (otherwise empty),
686         // TRANS: %6$s is a URL to reply to the notice, %7$s is a URL to all @-replied for the addressed user,
687         // TRANS: %8$s is a URL to the addressed user's e-mail settings, %9$s is the sender's nickname.
688         $body = sprintf(_("%1\$s (@%9\$s) just sent a notice to your attention (an '@-reply') on %2\$s.\n\n".
689                       "The notice is here:\n\n".
690                       "\t%3\$s\n\n" .
691                       "It reads:\n\n".
692                       "\t%4\$s\n\n" .
693                       "%5\$s" .
694                       "You can reply back here:\n\n".
695                       "\t%6\$s\n\n" .
696                       "The list of all @-replies for you here:\n\n" .
697                       "%7\$s\n\n" .
698                       "Faithfully yours,\n" .
699                       "%2\$s\n\n" .
700                       "P.S. You can turn off these email notifications here: %8\$s\n"),
701                     $bestname,//%1
702                     common_config('site', 'name'),//%2
703                     common_local_url('shownotice',
704                                      array('notice' => $notice->id)),//%3
705                     $notice->content,//%4
706                     $conversationEmailText,//%5
707                     common_local_url('newnotice',
708                                      array('replyto' => $sender->nickname, 'inreplyto' => $notice->id)),//%6
709                     common_local_url('replies',
710                                      array('nickname' => $user->nickname)),//%7
711                     common_local_url('emailsettings'), //%8
712                     $sender->nickname); //%9
713
714     $headers = _mail_prepare_headers('mention', $user->nickname, $sender->nickname);
715
716     common_switch_locale();
717     mail_to_user($user, $subject, $body, $headers);
718 }
719
720 /**
721  * Prepare the common mail headers used in notification emails
722  *
723  * @param string $msg_type type of message being sent to the user
724  * @param string $to       nickname of the receipient
725  * @param string $from     nickname of the user triggering the notification
726  *
727  * @return array list of mail headers to include in the message
728  */
729 function _mail_prepare_headers($msg_type, $to, $from)
730 {
731     $headers = array(
732         'X-StatusNet-MessageType' => $msg_type,
733         'X-StatusNet-TargetUser'  => $to,
734         'X-StatusNet-SourceUser'  => $from,
735         'X-StatusNet-Domain'      => common_config('site', 'server')
736     );
737
738     return $headers;
739 }