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