3 * StatusNet, the distributed open-source microblogging tool
5 * utilities for sending email
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.
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.
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/>.
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/
33 if (!defined('STATUSNET') && !defined('LACONICA')) {
37 require_once 'Mail.php';
40 * return the configured mail backend
42 * Uses the $config array to make a mail backend. Cached so it is safe to call
45 * @return Mail backend
47 function mail_backend()
49 static $backend = null;
52 $backend = Mail::factory(common_config('mail', 'backend'),
53 common_config('mail', 'params') ?: array());
54 if (PEAR::isError($backend)) {
55 common_server_error($backend->getMessage(), 500);
62 * send an email to one or more recipients
64 * @param array $recipients array of strings with email addresses of recipients
65 * @param array $headers array mapping strings to strings for email headers
66 * @param string $body body of the email
68 * @return boolean success flag
70 function mail_send($recipients, $headers, $body)
73 // XXX: use Mail_Queue... maybe
74 $backend = mail_backend();
76 if (!isset($headers['Content-Type'])) {
77 $headers['Content-Type'] = 'text/plain; charset=UTF-8';
80 assert($backend); // throws an error if it's bad
81 $sent = $backend->send($recipients, $headers, $body);
83 } catch (PEAR_Exception $e) {
86 "Unable to send email - '{$e->getMessage()}'. "
87 . 'Is your mail subsystem set up correctly?'
94 * returns the configured mail domain
96 * Defaults to the server name.
98 * @return string mail domain, suitable for making email addresses.
100 function mail_domain()
102 $maildomain = common_config('mail', 'domain');
104 $maildomain = common_config('site', 'server');
110 * returns a good address for sending email from this server
112 * Uses either the configured value or a faked-up value made
113 * from the mail domain.
115 * @return string notify from address
117 function mail_notify_from()
119 $notifyfrom = common_config('mail', 'notifyfrom');
123 $domain = mail_domain();
125 $notifyfrom = '"'. str_replace('"', '\\"', common_config('site', 'name')) .'" <noreply@'.$domain.'>';
132 * sends email to a user
134 * @param User &$user user to send email to
135 * @param string $subject subject of the email
136 * @param string $body body of the email
137 * @param array $headers optional list of email headers
138 * @param string $address optional specification of email address
140 * @return boolean success flag
142 function mail_to_user(&$user, $subject, $body, $headers=array(), $address=null)
145 $address = $user->email;
148 $recipients = $address;
149 $profile = $user->getProfile();
151 $headers['From'] = mail_notify_from();
152 $headers['To'] = $profile->getBestName() . ' <' . $address . '>';
153 $headers['Subject'] = $subject;
155 return mail_send($recipients, $headers, $body);
159 * Send an email to confirm a user's control of an email address
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
166 * @see common_confirmation_code()
168 * @return success flag
170 function mail_confirm_address($user, $code, $nickname, $address, $url=null)
173 $url = common_local_url('confirmaddress', array('code' => $code));
176 // TRANS: Subject for address confirmation email.
177 $subject = _('Email address confirmation');
179 // TRANS: Body for address confirmation email.
180 // TRANS: %1$s is the addressed user's nickname, %2$s is the StatusNet sitename,
181 // TRANS: %3$s is the URL to confirm at.
182 $body = sprintf(_("Hey, %1\$s.\n\n".
183 "Someone just entered this email address on %2\$s.\n\n" .
184 "If it was you, and you want to confirm your entry, ".
185 "use the URL below:\n\n\t%3\$s\n\n" .
186 "If not, just ignore this message.\n\n".
187 "Thanks for your time, \n%2\$s\n"),
189 common_config('site', 'name'),
194 return mail_to_user($user, $subject, $body, $headers, $address);
198 * notify a user of subscription by another user
200 * This is just a wrapper around the profile-based version.
202 * @param User $listenee user who is being subscribed to
203 * @param User $listener user who is subscribing
205 * @see mail_subscribe_notify_profile()
209 function mail_subscribe_notify($listenee, $listener)
211 $other = $listener->getProfile();
212 mail_subscribe_notify_profile($listenee, $other);
216 * notify a user of subscription by a profile (remote or local)
218 * This function checks to see if the listenee has an email
219 * address and wants subscription notices.
221 * @param User $listenee user who's being subscribed to
222 * @param Profile $other profile of person who's listening
226 function mail_subscribe_notify_profile($listenee, $other)
228 if ($other->hasRight(Right::EMAILONSUBSCRIBE) &&
229 $listenee->email && $listenee->emailnotifysub) {
231 $profile = $listenee->getProfile();
233 $name = $profile->getBestName();
235 $long_name = ($other->fullname) ?
236 ($other->fullname . ' (' . $other->nickname . ')') : $other->nickname;
238 $recipients = $listenee->email;
240 // use the recipient's localization
241 common_switch_locale($listenee->language);
243 $headers = _mail_prepare_headers('subscribe', $listenee->nickname, $other->nickname);
244 $headers['From'] = mail_notify_from();
245 $headers['To'] = $name . ' <' . $listenee->email . '>';
246 // TRANS: Subject of new-subscriber notification e-mail.
247 // TRANS: %1$s is the subscribing user's nickname, %2$s is the StatusNet sitename.
248 $headers['Subject'] = sprintf(_('%1$s is now following you on %2$s.'),
249 $other->getBestName(),
250 common_config('site', 'name'));
252 // TRANS: Main body of new-subscriber notification e-mail.
253 // TRANS: %1$s is the subscriber's long name, %2$s is the StatusNet sitename.
254 $body = sprintf(_('%1$s is now following you on %2$s.'),
256 common_config('site', 'name')) .
257 mail_profile_block($other) .
260 // reset localization
261 common_switch_locale();
262 mail_send($recipients, $headers, $body);
266 function mail_subscribe_pending_notify_profile($listenee, $other)
268 if ($other->hasRight(Right::EMAILONSUBSCRIBE) &&
269 $listenee->email && $listenee->emailnotifysub) {
271 $profile = $listenee->getProfile();
273 $name = $profile->getBestName();
275 $long_name = ($other->fullname) ?
276 ($other->fullname . ' (' . $other->nickname . ')') : $other->nickname;
278 $recipients = $listenee->email;
280 // use the recipient's localization
281 common_switch_locale($listenee->language);
283 $headers = _mail_prepare_headers('subscribe', $listenee->nickname, $other->nickname);
284 $headers['From'] = mail_notify_from();
285 $headers['To'] = $name . ' <' . $listenee->email . '>';
286 // TRANS: Subject of pending new-subscriber notification e-mail.
287 // TRANS: %1$s is the subscribing user's nickname, %2$s is the StatusNet sitename.
288 $headers['Subject'] = sprintf(_('%1$s would like to listen to '.
289 'your notices on %2$s.'),
290 $other->getBestName(),
291 common_config('site', 'name'));
293 // TRANS: Main body of pending new-subscriber notification e-mail.
294 // TRANS: %1$s is the subscriber's long name, %2$s is the StatusNet sitename.
295 $body = sprintf(_('%1$s would like to listen to your notices on %2$s. ' .
296 'You may approve or reject their subscription at %3$s'),
298 common_config('site', 'name'),
299 common_local_url('subqueue', array('nickname' => $listenee->nickname))) .
300 mail_profile_block($other) .
303 // reset localization
304 common_switch_locale();
305 mail_send($recipients, $headers, $body);
309 function mail_footer_block()
311 // TRANS: Common footer block for StatusNet notification emails.
312 // TRANS: %1$s is the StatusNet sitename,
313 // TRANS: %2$s is a link to the addressed user's e-mail settings.
314 return "\n\n" . sprintf(_('Faithfully yours,'.
317 "Change your email address or ".
318 "notification options at ".'%2$s'),
319 common_config('site', 'name'),
320 common_local_url('emailsettings')) . "\n";
324 * Format a block of profile info for a plaintext notification email.
326 * @param Profile $profile
329 function mail_profile_block($profile)
332 // TRANS: %1$s is the subscriber's profile URL, %2$s is the subscriber's location (or empty)
333 // TRANS: %3$s is the subscriber's homepage URL (or empty), %4%s is the subscriber's bio (or empty)
337 // TRANS: Profile info line in notification e-mail.
338 // TRANS: %s is a URL.
339 $out[] = sprintf(_("Profile: %s"), $profile->profileurl);
340 if ($profile->location) {
341 // TRANS: Profile info line in notification e-mail.
342 // TRANS: %s is a location.
343 $out[] = sprintf(_("Location: %s"), $profile->location);
345 if ($profile->homepage) {
346 // TRANS: Profile info line in notification e-mail.
347 // TRANS: %s is a homepage.
348 $out[] = sprintf(_("Homepage: %s"), $profile->homepage);
351 // TRANS: Profile info line in notification e-mail.
352 // TRANS: %s is biographical information.
353 $out[] = sprintf(_("Bio: %s"), $profile->bio);
356 $blocklink = common_local_url('block', array('profileid' => $profile->id));
357 // This'll let ModPlus add the remote profile info so it's possible
358 // to block remote users directly...
359 Event::handle('MailProfileInfoBlockLink', array($profile, &$blocklink));
361 // TRANS: This is a paragraph in a new-subscriber e-mail.
362 // TRANS: %s is a URL where the subscriber can be reported as abusive.
363 $out[] = sprintf(_('If you believe this account is being used abusively, ' .
364 'you can block them from your subscribers list and ' .
365 'report as spam to site administrators at %s.'),
369 return implode("\n", $out);
373 * notify a user of their new incoming email address
375 * User's email and incoming fields should already be updated.
377 * @param User $user user with the new address
381 function mail_new_incoming_notify($user)
383 $profile = $user->getProfile();
385 $name = $profile->getBestName();
387 $headers['From'] = $user->incomingemail;
388 $headers['To'] = $name . ' <' . $user->email . '>';
389 // TRANS: Subject of notification mail for new posting email address.
390 // TRANS: %s is the StatusNet sitename.
391 $headers['Subject'] = sprintf(_('New email address for posting to %s'),
392 common_config('site', 'name'));
394 // TRANS: Body of notification mail for new posting email address.
395 // TRANS: %1$s is the StatusNet sitename, %2$s is the e-mail address to send
396 // TRANS: to to post by e-mail, %3$s is a URL to more instructions.
397 $body = sprintf(_("You have a new posting address on %1\$s.\n\n".
398 "Send email to %2\$s to post new messages.\n\n".
399 "More email instructions at %3\$s."),
400 common_config('site', 'name'),
401 $user->incomingemail,
402 common_local_url('doc', array('title' => 'email'))) .
405 mail_send($user->email, $headers, $body);
409 * generate a new address for incoming messages
411 * @todo check the database for uniqueness
413 * @return string new email address for incoming messages
415 function mail_new_incoming_address()
417 $prefix = common_confirmation_code(64);
418 $suffix = mail_domain();
419 return $prefix . '@' . $suffix;
423 * broadcast a notice to all subscribers with SMS notification on
425 * This function sends SMS messages to all users who have sms addresses;
426 * have sms notification on; and have sms enabled for this particular
429 * @param Notice $notice The notice to broadcast
431 * @return success flag
433 function mail_broadcast_notice_sms($notice)
435 // Now, get users subscribed to this profile
439 $UT = common_config('db','type')=='pgsql'?'"user"':'user';
440 $user->query('SELECT nickname, smsemail, incomingemail ' .
441 "FROM $UT JOIN subscription " .
442 "ON $UT.id = subscription.subscriber " .
443 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' .
444 'AND subscription.subscribed != subscription.subscriber ' .
445 "AND $UT.smsemail IS NOT null " .
446 "AND $UT.smsnotify = 1 " .
447 'AND subscription.sms = 1 ');
449 while ($user->fetch()) {
451 'Sending notice ' . $notice->id . ' to ' . $user->smsemail,
453 $success = mail_send_sms_notice_address($notice,
455 $user->incomingemail,
458 // XXX: Not sure, but I think that's the right thing to do
459 common_log(LOG_WARNING,
460 'Sending notice ' . $notice->id . ' to ' .
461 $user->smsemail . ' FAILED, cancelling.',
474 * send a notice to a user via SMS
476 * A convenience wrapper around mail_send_sms_notice_address()
478 * @param Notice $notice notice to send
479 * @param User $user user to receive notice
481 * @see mail_send_sms_notice_address()
483 * @return boolean success flag
485 function mail_send_sms_notice($notice, $user)
487 return mail_send_sms_notice_address($notice,
489 $user->incomingemail,
494 * send a notice to an SMS email address from a given address
496 * We use the user's incoming email address as the "From" address to make
497 * replying to notices easier.
499 * @param Notice $notice notice to send
500 * @param string $smsemail email address to send to
501 * @param string $incomingemail email address to set as 'from'
502 * @param string $nickname nickname to add to beginning
504 * @return boolean success flag
506 function mail_send_sms_notice_address($notice, $smsemail, $incomingemail, $nickname)
508 $to = $nickname . ' <' . $smsemail . '>';
510 $other = $notice->getProfile();
512 common_log(LOG_INFO, 'Sending notice ' . $notice->id .
513 ' to ' . $smsemail, __FILE__);
517 $headers['From'] = ($incomingemail) ? $incomingemail : mail_notify_from();
518 $headers['To'] = $to;
519 // TRANS: Subject line for SMS-by-email notification messages.
520 // TRANS: %s is the posting user's nickname.
521 $headers['Subject'] = sprintf(_('%s status'),
522 $other->getBestName());
524 $body = $notice->content;
526 return mail_send($smsemail, $headers, $body);
530 * send a message to confirm a claim for an SMS number
532 * @param string $code confirmation code
533 * @param string $nickname nickname of user claiming number
534 * @param string $address email address to send the confirmation to
536 * @see common_confirmation_code()
540 function mail_confirm_sms($code, $nickname, $address)
542 $recipients = $address;
544 $headers['From'] = mail_notify_from();
545 $headers['To'] = $nickname . ' <' . $address . '>';
546 // TRANS: Subject line for SMS-by-email address confirmation message.
547 $headers['Subject'] = _('SMS confirmation');
549 // TRANS: Main body heading for SMS-by-email address confirmation message.
550 // TRANS: %s is the addressed user's nickname.
551 $body = sprintf(_('%s: confirm you own this phone number with this code:'), $nickname);
556 mail_send($recipients, $headers, $body);
560 * send a mail message to notify a user of a 'nudge'
562 * @param User $from user nudging
563 * @param User $to user being nudged
565 * @return boolean success flag
567 function mail_notify_nudge($from, $to)
569 common_switch_locale($to->language);
570 // TRANS: Subject for 'nudge' notification email.
571 // TRANS: %s is the nudging user.
572 $subject = sprintf(_('You have been nudged by %s'), $from->nickname);
574 $from_profile = $from->getProfile();
576 // TRANS: Body for 'nudge' notification email.
577 // TRANS: %1$s is the nuding user's long name, $2$s is the nudging user's nickname,
578 // TRANS: %3$s is a URL to post notices at.
579 $body = sprintf(_("%1\$s (%2\$s) is wondering what you are up to ".
580 "these days and is inviting you to post some news.\n\n".
581 "So let's hear from you :)\n\n".
583 "Don't reply to this email; it won't get to them."),
584 $from_profile->getBestName(),
586 common_local_url('all', array('nickname' => $to->nickname))) .
588 common_switch_locale();
590 $headers = _mail_prepare_headers('nudge', $to->nickname, $from->nickname);
592 return mail_to_user($to, $subject, $body, $headers);
596 * send a message to notify a user of a direct message (DM)
598 * This function checks to see if the recipient wants notification
599 * of DMs and has a configured email address.
601 * @param Message $message message to notify about
602 * @param User $from user sending message; default to sender
603 * @param User $to user receiving message; default to recipient
605 * @return boolean success code
607 function mail_notify_message($message, $from=null, $to=null)
609 if (is_null($from)) {
610 $from = User::getKV('id', $message->from_profile);
614 $to = User::getKV('id', $message->to_profile);
617 if (is_null($to->email) || !$to->emailnotifymsg) {
621 common_switch_locale($to->language);
622 // TRANS: Subject for direct-message notification email.
623 // TRANS: %s is the sending user's nickname.
624 $subject = sprintf(_('New private message from %s'), $from->nickname);
626 $from_profile = $from->getProfile();
628 // TRANS: Body for direct-message notification email.
629 // TRANS: %1$s is the sending user's long name, %2$s is the sending user's nickname,
630 // TRANS: %3$s is the message content, %4$s a URL to the message,
631 $body = sprintf(_("%1\$s (%2\$s) sent you a private message:\n\n".
632 "------------------------------------------------------\n".
634 "------------------------------------------------------\n\n".
635 "You can reply to their message here:\n\n".
637 "Don't reply to this email; it won't get to them."),
638 $from_profile->getBestName(),
641 common_local_url('newmessage', array('to' => $from->id))) .
644 $headers = _mail_prepare_headers('message', $to->nickname, $from->nickname);
646 common_switch_locale();
647 return mail_to_user($to, $subject, $body, $headers);
651 * Notify a user that one of their notices has been chosen as a 'fave'
653 * Doesn't check that the user has an email address nor if they
654 * want to receive notification of faves. Maybe this happens higher
657 * @param User $other The user whose notice was faved
658 * @param User $user The user who faved the notice
659 * @param Notice $notice The notice that was faved
663 function mail_notify_fave($other, $user, $notice)
665 if (!$user->hasRight(Right::EMAILONFAVE)) {
669 $profile = $user->getProfile();
670 if ($other->hasBlocked($profile)) {
671 // If the author has blocked us, don't spam them with a notification.
675 $bestname = $profile->getBestName();
677 common_switch_locale($other->language);
679 // TRANS: Subject for favorite notification e-mail.
680 // TRANS: %1$s is the adding user's long name, %2$s is the adding user's nickname.
681 $subject = sprintf(_('%1$s (@%2$s) added your notice as a favorite'), $bestname, $user->nickname);
683 // TRANS: Body for favorite notification e-mail.
684 // TRANS: %1$s is the adding user's long name, $2$s is the date the notice was created,
685 // TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text,
686 // TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename,
687 // TRANS: %7$s is the adding user's nickname.
688 $body = sprintf(_("%1\$s (@%7\$s) just added your notice from %2\$s".
689 " as one of their favorites.\n\n" .
690 "The URL of your notice is:\n\n" .
692 "The text of your notice is:\n\n" .
694 "You can see the list of %1\$s's favorites here:\n\n" .
697 common_exact_date($notice->created),
698 common_local_url('shownotice',
699 array('notice' => $notice->id)),
701 common_local_url('showfavorites',
702 array('nickname' => $user->nickname)),
703 common_config('site', 'name'),
707 $headers = _mail_prepare_headers('fave', $other->nickname, $user->nickname);
709 common_switch_locale();
710 mail_to_user($other, $subject, $body, $headers);
714 * Notify a user that they have received an "attn:" message AKA "@-reply"
716 * @param User $user The user who recevied the notice
717 * @param Notice $notice The notice that was sent
721 function mail_notify_attn($user, $notice)
723 if (!$user->email || !$user->emailnotifyattn) {
727 $sender = $notice->getProfile();
729 if ($sender->id == $user->id) {
733 if (!$sender->hasRight(Right::EMAILONREPLY)) {
737 if ($user->hasBlocked($sender)) {
738 // If the author has blocked us, don't spam them with a notification.
742 $bestname = $sender->getBestName();
744 common_switch_locale($user->language);
746 if ($notice->hasConversation()) {
747 $conversationUrl = common_local_url('conversation',
748 array('id' => $notice->conversation)).'#notice-'.$notice->id;
749 // TRANS: Line in @-reply notification e-mail. %s is conversation URL.
750 $conversationEmailText = sprintf(_("The full conversation can be read here:\n\n".
751 "\t%s"), $conversationUrl) . "\n\n";
753 $conversationEmailText = '';
756 // TRANS: E-mail subject for notice notification.
757 // TRANS: %1$s is the sending user's long name, %2$s is the adding user's nickname.
758 $subject = sprintf(_('%1$s (@%2$s) sent a notice to your attention'), $bestname, $sender->nickname);
760 // TRANS: Body of @-reply notification e-mail.
761 // TRANS: %1$s is the sending user's name, $2$s is the StatusNet sitename,
762 // TRANS: %3$s is a URL to the notice, %4$s is the notice text,
763 // TRANS: %5$s is the text "The full conversation can be read here:" and a URL to the full conversion if it exists (otherwise empty),
764 // TRANS: %6$s is a URL to reply to the notice, %7$s is a URL to all @-replies for the addressed user,
765 $body = sprintf(_("%1\$s just sent a notice to your attention (an '@-reply') on %2\$s.\n\n".
766 "The notice is here:\n\n".
771 "You can reply back here:\n\n".
773 "The list of all @-replies for you here:\n\n" .
775 $sender->getFancyName(),//%1
776 common_config('site', 'name'),//%2
777 common_local_url('shownotice',
778 array('notice' => $notice->id)),//%3
779 $notice->content,//%4
780 $conversationEmailText,//%5
781 common_local_url('newnotice',
782 array('replyto' => $sender->nickname, 'inreplyto' => $notice->id)),//%6
783 common_local_url('replies',
784 array('nickname' => $user->nickname))) . //%7
786 $headers = _mail_prepare_headers('mention', $user->nickname, $sender->nickname);
788 common_switch_locale();
789 mail_to_user($user, $subject, $body, $headers);
793 * Prepare the common mail headers used in notification emails
795 * @param string $msg_type type of message being sent to the user
796 * @param string $to nickname of the receipient
797 * @param string $from nickname of the user triggering the notification
799 * @return array list of mail headers to include in the message
801 function _mail_prepare_headers($msg_type, $to, $from)
804 'X-StatusNet-MessageType' => $msg_type,
805 'X-StatusNet-TargetUser' => $to,
806 'X-StatusNet-SourceUser' => $from,
807 'X-StatusNet-Domain' => common_config('site', 'server')
814 * Send notification emails to group administrator.
816 * @param User_group $group
817 * @param Profile $joiner
819 function mail_notify_group_join($group, $joiner)
821 // This returns a Profile query...
822 $admin = $group->getAdmins();
823 while ($admin->fetch()) {
824 // We need a local user for email notifications...
825 $adminUser = User::getKV('id', $admin->id);
826 // @fixme check for email preference?
827 if ($adminUser && $adminUser->email) {
828 // use the recipient's localization
829 common_switch_locale($adminUser->language);
831 $headers = _mail_prepare_headers('join', $admin->nickname, $joiner->nickname);
832 $headers['From'] = mail_notify_from();
833 $headers['To'] = $admin->getBestName() . ' <' . $adminUser->email . '>';
834 // TRANS: Subject of group join notification e-mail.
835 // TRANS: %1$s is the joining user's nickname, %2$s is the group name, and %3$s is the StatusNet sitename.
836 $headers['Subject'] = sprintf(_('%1$s has joined '.
837 'your group %2$s on %3$s'),
838 $joiner->getBestName(),
839 $group->getBestName(),
840 common_config('site', 'name'));
842 // TRANS: Main body of group join notification e-mail.
843 // TRANS: %1$s is the subscriber's long name, %2$s is the group name, and %3$s is the StatusNet sitename,
844 // TRANS: %4$s is a block of profile info about the subscriber.
845 // TRANS: %5$s is a link to the addressed user's e-mail settings.
846 $body = sprintf(_('%1$s has joined your group %2$s on %3$s.'),
847 $joiner->getFancyName(),
848 $group->getFancyName(),
849 common_config('site', 'name')) .
850 mail_profile_block($joiner) .
853 // reset localization
854 common_switch_locale();
855 mail_send($adminUser->email, $headers, $body);
862 * Send notification emails to group administrator.
864 * @param User_group $group
865 * @param Profile $joiner
867 function mail_notify_group_join_pending($group, $joiner)
869 $admin = $group->getAdmins();
870 while ($admin->fetch()) {
871 // We need a local user for email notifications...
872 $adminUser = User::getKV('id', $admin->id);
873 // @fixme check for email preference?
874 if ($adminUser && $adminUser->email) {
875 // use the recipient's localization
876 common_switch_locale($adminUser->language);
878 $headers = _mail_prepare_headers('join', $admin->nickname, $joiner->nickname);
879 $headers['From'] = mail_notify_from();
880 $headers['To'] = $admin->getBestName() . ' <' . $adminUser->email . '>';
881 // TRANS: Subject of pending group join request notification e-mail.
882 // TRANS: %1$s is the joining user's nickname, %2$s is the group name, and %3$s is the StatusNet sitename.
883 $headers['Subject'] = sprintf(_('%1$s wants to join your group %2$s on %3$s.'),
884 $joiner->getBestName(),
885 $group->getBestName(),
886 common_config('site', 'name'));
888 // TRANS: Main body of pending group join request notification e-mail.
889 // TRANS: %1$s is the subscriber's long name, %2$s is the group name, and %3$s is the StatusNet sitename,
890 // TRANS: %4$s is the URL to the moderation queue page.
891 $body = sprintf(_('%1$s would like to join your group %2$s on %3$s. ' .
892 'You may approve or reject their group membership at %4$s'),
893 $joiner->getFancyName(),
894 $group->getFancyName(),
895 common_config('site', 'name'),
896 common_local_url('groupqueue', array('nickname' => $group->nickname))) .
897 mail_profile_block($joiner) .
900 // reset localization
901 common_switch_locale();
902 mail_send($adminUser->email, $headers, $body);