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')) ?
54 common_config('mail', 'params') :
56 if (PEAR::isError($backend)) {
57 common_server_error($backend->getMessage(), 500);
64 * send an email to one or more recipients
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
70 * @return boolean success flag
72 function mail_send($recipients, $headers, $body)
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';
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());
89 * returns the configured mail domain
91 * Defaults to the server name.
93 * @return string mail domain, suitable for making email addresses.
95 function mail_domain()
97 $maildomain = common_config('mail', 'domain');
99 $maildomain = common_config('site', 'server');
105 * returns a good address for sending email from this server
107 * Uses either the configured value or a faked-up value made
108 * from the mail domain.
110 * @return string notify from address
112 function mail_notify_from()
114 $notifyfrom = common_config('mail', 'notifyfrom');
118 $domain = mail_domain();
120 $notifyfrom = '"'. str_replace('"', '\\"', common_config('site', 'name')) .'" <noreply@'.$domain.'>';
127 * sends email to a user
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
135 * @return boolean success flag
137 function mail_to_user(&$user, $subject, $body, $headers=array(), $address=null)
140 $address = $user->email;
143 $recipients = $address;
144 $profile = $user->getProfile();
146 $headers['From'] = mail_notify_from();
147 $headers['To'] = $profile->getBestName() . ' <' . $address . '>';
148 $headers['Subject'] = $subject;
150 return mail_send($recipients, $headers, $body);
154 * Send an email to confirm a user's control of an email address
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
161 * @see common_confirmation_code()
163 * @return success flag
165 function mail_confirm_address($user, $code, $nickname, $address, $url=null)
168 $url = common_local_url('confirmaddress', array('code' => $code));
171 // TRANS: Subject for address confirmation email.
172 $subject = _('Email address confirmation');
174 // TRANS: Body for address confirmation email.
175 // TRANS: %1$s is the addressed user's nickname, %2$s is the StatusNet sitename,
176 // TRANS: %3$s is the URL to confirm at.
177 $body = sprintf(_("Hey, %1\$s.\n\n".
178 "Someone just entered this email address on %2\$s.\n\n" .
179 "If it was you, and you want to confirm your entry, ".
180 "use the URL below:\n\n\t%3\$s\n\n" .
181 "If not, just ignore this message.\n\n".
182 "Thanks for your time, \n%2\$s\n"),
184 common_config('site', 'name'),
189 return mail_to_user($user, $subject, $body, $headers, $address);
193 * notify a user of subscription by another user
195 * This is just a wrapper around the profile-based version.
197 * @param User $listenee user who is being subscribed to
198 * @param User $listener user who is subscribing
200 * @see mail_subscribe_notify_profile()
204 function mail_subscribe_notify($listenee, $listener)
206 $other = $listener->getProfile();
207 mail_subscribe_notify_profile($listenee, $other);
211 * notify a user of subscription by a profile (remote or local)
213 * This function checks to see if the listenee has an email
214 * address and wants subscription notices.
216 * @param User $listenee user who's being subscribed to
217 * @param Profile $other profile of person who's listening
221 function mail_subscribe_notify_profile($listenee, $other)
223 if ($other->hasRight(Right::EMAILONSUBSCRIBE) &&
224 $listenee->email && $listenee->emailnotifysub) {
226 $profile = $listenee->getProfile();
228 $name = $profile->getBestName();
230 $long_name = ($other->fullname) ?
231 ($other->fullname . ' (' . $other->nickname . ')') : $other->nickname;
233 $recipients = $listenee->email;
235 // use the recipient's localization
236 common_switch_locale($listenee->language);
238 $headers = _mail_prepare_headers('subscribe', $listenee->nickname, $other->nickname);
239 $headers['From'] = mail_notify_from();
240 $headers['To'] = $name . ' <' . $listenee->email . '>';
241 // TRANS: Subject of new-subscriber notification e-mail.
242 // TRANS: %1$s is the subscribing user's nickname, %2$s is the StatusNet sitename.
243 $headers['Subject'] = sprintf(_('%1$s is now listening to '.
244 'your notices on %2$s.'),
245 $other->getBestName(),
246 common_config('site', 'name'));
248 // TRANS: Main body of new-subscriber notification e-mail.
249 // TRANS: %1$s is the subscriber's long name, %2$s is the StatusNet sitename.
250 $body = sprintf(_('%1$s is now listening to your notices on %2$s.'),
252 common_config('site', 'name')) .
253 mail_profile_block($other) .
256 // reset localization
257 common_switch_locale();
258 mail_send($recipients, $headers, $body);
262 function mail_subscribe_pending_notify_profile($listenee, $other)
264 if ($other->hasRight(Right::EMAILONSUBSCRIBE) &&
265 $listenee->email && $listenee->emailnotifysub) {
267 $profile = $listenee->getProfile();
269 $name = $profile->getBestName();
271 $long_name = ($other->fullname) ?
272 ($other->fullname . ' (' . $other->nickname . ')') : $other->nickname;
274 $recipients = $listenee->email;
276 // use the recipient's localization
277 common_switch_locale($listenee->language);
279 $headers = _mail_prepare_headers('subscribe', $listenee->nickname, $other->nickname);
280 $headers['From'] = mail_notify_from();
281 $headers['To'] = $name . ' <' . $listenee->email . '>';
282 // TRANS: Subject of pending new-subscriber notification e-mail.
283 // TRANS: %1$s is the subscribing user's nickname, %2$s is the StatusNet sitename.
284 $headers['Subject'] = sprintf(_('%1$s would like to listen to '.
285 'your notices on %2$s.'),
286 $other->getBestName(),
287 common_config('site', 'name'));
289 // TRANS: Main body of pending new-subscriber notification e-mail.
290 // TRANS: %1$s is the subscriber's long name, %2$s is the StatusNet sitename.
291 $body = sprintf(_('%1$s would like to listen to your notices on %2$s. ' .
292 'You may approve or reject their subscription at %3$s'),
294 common_config('site', 'name'),
295 common_local_url('subqueue', array('nickname' => $listenee->nickname))) .
296 mail_profile_block($other) .
299 // reset localization
300 common_switch_locale();
301 mail_send($recipients, $headers, $body);
305 function mail_footer_block()
307 // TRANS: Common footer block for StatusNet notification emails.
308 // TRANS: %1$s is the StatusNet sitename,
309 // TRANS: %2$s is a link to the addressed user's e-mail settings.
310 return "\n\n" . sprintf(_('Faithfully yours,'.
313 "Change your email address or ".
314 "notification options at ".'%2$s'),
315 common_config('site', 'name'),
316 common_local_url('emailsettings')) . "\n";
320 * Format a block of profile info for a plaintext notification email.
322 * @param Profile $profile
325 function mail_profile_block($profile)
328 // TRANS: %1$s is the subscriber's profile URL, %2$s is the subscriber's location (or empty)
329 // TRANS: %3$s is the subscriber's homepage URL (or empty), %4%s is the subscriber's bio (or empty)
333 // TRANS: Profile info line in notification e-mail.
334 // TRANS: %s is a URL.
335 $out[] = sprintf(_("Profile: %s"), $profile->profileurl);
336 if ($profile->location) {
337 // TRANS: Profile info line in notification e-mail.
338 // TRANS: %s is a location.
339 $out[] = sprintf(_("Location: %s"), $profile->location);
341 if ($profile->homepage) {
342 // TRANS: Profile info line in notification e-mail.
343 // TRANS: %s is a homepage.
344 $out[] = sprintf(_("Homepage: %s"), $profile->homepage);
347 // TRANS: Profile info line in notification e-mail.
348 // TRANS: %s is biographical information.
349 $out[] = sprintf(_("Bio: %s"), $profile->bio);
352 $blocklink = common_local_url('block', array('profileid' => $profile->id));
353 // This'll let ModPlus add the remote profile info so it's possible
354 // to block remote users directly...
355 Event::handle('MailProfileInfoBlockLink', array($profile, &$blocklink));
357 // TRANS: This is a paragraph in a new-subscriber e-mail.
358 // TRANS: %s is a URL where the subscriber can be reported as abusive.
359 $out[] = sprintf(_('If you believe this account is being used abusively, ' .
360 'you can block them from your subscribers list and ' .
361 'report as spam to site administrators at %s.'),
365 return implode("\n", $out);
369 * notify a user of their new incoming email address
371 * User's email and incoming fields should already be updated.
373 * @param User $user user with the new address
377 function mail_new_incoming_notify($user)
379 $profile = $user->getProfile();
381 $name = $profile->getBestName();
383 $headers['From'] = $user->incomingemail;
384 $headers['To'] = $name . ' <' . $user->email . '>';
385 // TRANS: Subject of notification mail for new posting email address.
386 // TRANS: %s is the StatusNet sitename.
387 $headers['Subject'] = sprintf(_('New email address for posting to %s'),
388 common_config('site', 'name'));
390 // TRANS: Body of notification mail for new posting email address.
391 // TRANS: %1$s is the StatusNet sitename, %2$s is the e-mail address to send
392 // TRANS: to to post by e-mail, %3$s is a URL to more instructions.
393 $body = sprintf(_("You have a new posting address on %1\$s.\n\n".
394 "Send email to %2\$s to post new messages.\n\n".
395 "More email instructions at %3\$s."),
396 common_config('site', 'name'),
397 $user->incomingemail,
398 common_local_url('doc', array('title' => 'email'))) .
401 mail_send($user->email, $headers, $body);
405 * generate a new address for incoming messages
407 * @todo check the database for uniqueness
409 * @return string new email address for incoming messages
411 function mail_new_incoming_address()
413 $prefix = common_confirmation_code(64);
414 $suffix = mail_domain();
415 return $prefix . '@' . $suffix;
419 * broadcast a notice to all subscribers with SMS notification on
421 * This function sends SMS messages to all users who have sms addresses;
422 * have sms notification on; and have sms enabled for this particular
425 * @param Notice $notice The notice to broadcast
427 * @return success flag
429 function mail_broadcast_notice_sms($notice)
431 // Now, get users subscribed to this profile
435 $UT = common_config('db','type')=='pgsql'?'"user"':'user';
436 $user->query('SELECT nickname, smsemail, incomingemail ' .
437 "FROM $UT JOIN subscription " .
438 "ON $UT.id = subscription.subscriber " .
439 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' .
440 'AND subscription.subscribed != subscription.subscriber ' .
441 "AND $UT.smsemail IS NOT null " .
442 "AND $UT.smsnotify = 1 " .
443 'AND subscription.sms = 1 ');
445 while ($user->fetch()) {
447 'Sending notice ' . $notice->id . ' to ' . $user->smsemail,
449 $success = mail_send_sms_notice_address($notice,
451 $user->incomingemail);
453 // XXX: Not sure, but I think that's the right thing to do
454 common_log(LOG_WARNING,
455 'Sending notice ' . $notice->id . ' to ' .
456 $user->smsemail . ' FAILED, cancelling.',
469 * send a notice to a user via SMS
471 * A convenience wrapper around mail_send_sms_notice_address()
473 * @param Notice $notice notice to send
474 * @param User $user user to receive notice
476 * @see mail_send_sms_notice_address()
478 * @return boolean success flag
480 function mail_send_sms_notice($notice, $user)
482 return mail_send_sms_notice_address($notice,
484 $user->incomingemail);
488 * send a notice to an SMS email address from a given address
490 * We use the user's incoming email address as the "From" address to make
491 * replying to notices easier.
493 * @param Notice $notice notice to send
494 * @param string $smsemail email address to send to
495 * @param string $incomingemail email address to set as 'from'
497 * @return boolean success flag
499 function mail_send_sms_notice_address($notice, $smsemail, $incomingemail)
501 $to = $nickname . ' <' . $smsemail . '>';
503 $other = $notice->getProfile();
505 common_log(LOG_INFO, 'Sending notice ' . $notice->id .
506 ' to ' . $smsemail, __FILE__);
510 $headers['From'] = ($incomingemail) ? $incomingemail : mail_notify_from();
511 $headers['To'] = $to;
512 // TRANS: Subject line for SMS-by-email notification messages.
513 // TRANS: %s is the posting user's nickname.
514 $headers['Subject'] = sprintf(_('%s status'),
515 $other->getBestName());
517 $body = $notice->content;
519 return mail_send($smsemail, $headers, $body);
523 * send a message to confirm a claim for an SMS number
525 * @param string $code confirmation code
526 * @param string $nickname nickname of user claiming number
527 * @param string $address email address to send the confirmation to
529 * @see common_confirmation_code()
533 function mail_confirm_sms($code, $nickname, $address)
535 $recipients = $address;
537 $headers['From'] = mail_notify_from();
538 $headers['To'] = $nickname . ' <' . $address . '>';
539 // TRANS: Subject line for SMS-by-email address confirmation message.
540 $headers['Subject'] = _('SMS confirmation');
542 // TRANS: Main body heading for SMS-by-email address confirmation message.
543 // TRANS: %s is the addressed user's nickname.
544 $body = sprintf(_('%s: confirm you own this phone number with this code:'), $nickname);
549 mail_send($recipients, $headers, $body);
553 * send a mail message to notify a user of a 'nudge'
555 * @param User $from user nudging
556 * @param User $to user being nudged
558 * @return boolean success flag
560 function mail_notify_nudge($from, $to)
562 common_switch_locale($to->language);
563 // TRANS: Subject for 'nudge' notification email.
564 // TRANS: %s is the nudging user.
565 $subject = sprintf(_('You have been nudged by %s'), $from->nickname);
567 $from_profile = $from->getProfile();
569 // TRANS: Body for 'nudge' notification email.
570 // TRANS: %1$s is the nuding user's long name, $2$s is the nudging user's nickname,
571 // TRANS: %3$s is a URL to post notices at.
572 $body = sprintf(_("%1\$s (%2\$s) is wondering what you are up to ".
573 "these days and is inviting you to post some news.\n\n".
574 "So let's hear from you :)\n\n".
576 "Don't reply to this email; it won't get to them."),
577 $from_profile->getBestName(),
579 common_local_url('all', array('nickname' => $to->nickname))) .
581 common_switch_locale();
583 $headers = _mail_prepare_headers('nudge', $to->nickname, $from->nickname);
585 return mail_to_user($to, $subject, $body, $headers);
589 * send a message to notify a user of a direct message (DM)
591 * This function checks to see if the recipient wants notification
592 * of DMs and has a configured email address.
594 * @param Message $message message to notify about
595 * @param User $from user sending message; default to sender
596 * @param User $to user receiving message; default to recipient
598 * @return boolean success code
600 function mail_notify_message($message, $from=null, $to=null)
602 if (is_null($from)) {
603 $from = User::staticGet('id', $message->from_profile);
607 $to = User::staticGet('id', $message->to_profile);
610 if (is_null($to->email) || !$to->emailnotifymsg) {
614 common_switch_locale($to->language);
615 // TRANS: Subject for direct-message notification email.
616 // TRANS: %s is the sending user's nickname.
617 $subject = sprintf(_('New private message from %s'), $from->nickname);
619 $from_profile = $from->getProfile();
621 // TRANS: Body for direct-message notification email.
622 // TRANS: %1$s is the sending user's long name, %2$s is the sending user's nickname,
623 // TRANS: %3$s is the message content, %4$s a URL to the message,
624 $body = sprintf(_("%1\$s (%2\$s) sent you a private message:\n\n".
625 "------------------------------------------------------\n".
627 "------------------------------------------------------\n\n".
628 "You can reply to their message here:\n\n".
630 "Don't reply to this email; it won't get to them."),
631 $from_profile->getBestName(),
634 common_local_url('newmessage', array('to' => $from->id))) .
637 $headers = _mail_prepare_headers('message', $to->nickname, $from->nickname);
639 common_switch_locale();
640 return mail_to_user($to, $subject, $body, $headers);
644 * Notify a user that one of their notices has been chosen as a 'fave'
646 * Doesn't check that the user has an email address nor if they
647 * want to receive notification of faves. Maybe this happens higher
650 * @param User $other The user whose notice was faved
651 * @param User $user The user who faved the notice
652 * @param Notice $notice The notice that was faved
656 function mail_notify_fave($other, $user, $notice)
658 if (!$user->hasRight(Right::EMAILONFAVE)) {
662 $profile = $user->getProfile();
663 if ($other->hasBlocked($profile)) {
664 // If the author has blocked us, don't spam them with a notification.
668 $bestname = $profile->getBestName();
670 common_switch_locale($other->language);
672 // TRANS: Subject for favorite notification e-mail.
673 // TRANS: %1$s is the adding user's long name, %2$s is the adding user's nickname.
674 $subject = sprintf(_('%1$s (@%2$s) added your notice as a favorite'), $bestname, $user->nickname);
676 // TRANS: Body for favorite notification e-mail.
677 // TRANS: %1$s is the adding user's long name, $2$s is the date the notice was created,
678 // TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text,
679 // TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename,
680 // TRANS: %7$s is the adding user's nickname.
681 $body = sprintf(_("%1\$s (@%7\$s) just added your notice from %2\$s".
682 " as one of their favorites.\n\n" .
683 "The URL of your notice is:\n\n" .
685 "The text of your notice is:\n\n" .
687 "You can see the list of %1\$s's favorites here:\n\n" .
690 common_exact_date($notice->created),
691 common_local_url('shownotice',
692 array('notice' => $notice->id)),
694 common_local_url('showfavorites',
695 array('nickname' => $user->nickname)),
696 common_config('site', 'name'),
700 $headers = _mail_prepare_headers('fave', $other->nickname, $user->nickname);
702 common_switch_locale();
703 mail_to_user($other, $subject, $body, $headers);
707 * Notify a user that they have received an "attn:" message AKA "@-reply"
709 * @param User $user The user who recevied the notice
710 * @param Notice $notice The notice that was sent
714 function mail_notify_attn($user, $notice)
716 if (!$user->email || !$user->emailnotifyattn) {
720 $sender = $notice->getProfile();
722 if ($sender->id == $user->id) {
726 if (!$sender->hasRight(Right::EMAILONREPLY)) {
730 $bestname = $sender->getBestName();
732 common_switch_locale($user->language);
734 if ($notice->hasConversation()) {
735 $conversationUrl = common_local_url('conversation',
736 array('id' => $notice->conversation)).'#notice-'.$notice->id;
737 // TRANS: Line in @-reply notification e-mail. %s is conversation URL.
738 $conversationEmailText = sprintf(_("The full conversation can be read here:\n\n".
739 "\t%s"), $conversationUrl) . "\n\n";
741 $conversationEmailText = '';
744 // TRANS: E-mail subject for notice notification.
745 // TRANS: %1$s is the sending user's long name, %2$s is the adding user's nickname.
746 $subject = sprintf(_('%1$s (@%2$s) sent a notice to your attention'), $bestname, $sender->nickname);
748 // TRANS: Body of @-reply notification e-mail.
749 // TRANS: %1$s is the sending user's name, $2$s is the StatusNet sitename,
750 // TRANS: %3$s is a URL to the notice, %4$s is the notice text,
751 // TRANS: %5$s is a URL to the full conversion if it exists (otherwise empty),
752 // TRANS: %6$s is a URL to reply to the notice, %7$s is a URL to all @-replies for the addressed user,
753 $body = sprintf(_("%1\$s just sent a notice to your attention (an '@-reply') on %2\$s.\n\n".
754 "The notice is here:\n\n".
759 "You can reply back here:\n\n".
761 "The list of all @-replies for you here:\n\n" .
763 $sender->getFancyName(),//%1
764 common_config('site', 'name'),//%2
765 common_local_url('shownotice',
766 array('notice' => $notice->id)),//%3
767 $notice->content,//%4
768 $conversationEmailText,//%5
769 common_local_url('newnotice',
770 array('replyto' => $sender->nickname, 'inreplyto' => $notice->id)),//%6
771 common_local_url('replies',
772 array('nickname' => $user->nickname))) . //%7
774 $headers = _mail_prepare_headers('mention', $user->nickname, $sender->nickname);
776 common_switch_locale();
777 mail_to_user($user, $subject, $body, $headers);
781 * Prepare the common mail headers used in notification emails
783 * @param string $msg_type type of message being sent to the user
784 * @param string $to nickname of the receipient
785 * @param string $from nickname of the user triggering the notification
787 * @return array list of mail headers to include in the message
789 function _mail_prepare_headers($msg_type, $to, $from)
792 'X-StatusNet-MessageType' => $msg_type,
793 'X-StatusNet-TargetUser' => $to,
794 'X-StatusNet-SourceUser' => $from,
795 'X-StatusNet-Domain' => common_config('site', 'server')
802 * Send notification emails to group administrator.
804 * @param User_group $group
805 * @param Profile $joiner
807 function mail_notify_group_join($group, $joiner)
809 // This returns a Profile query...
810 $admin = $group->getAdmins();
811 while ($admin->fetch()) {
812 // We need a local user for email notifications...
813 $adminUser = User::staticGet('id', $admin->id);
814 // @fixme check for email preference?
815 if ($adminUser && $adminUser->email) {
816 // use the recipient's localization
817 common_switch_locale($adminUser->language);
819 $headers = _mail_prepare_headers('join', $admin->nickname, $joiner->nickname);
820 $headers['From'] = mail_notify_from();
821 $headers['To'] = $admin->getBestName() . ' <' . $adminUser->email . '>';
822 // TRANS: Subject of group join notification e-mail.
823 // TRANS: %1$s is the joining user's nickname, %2$s is the group name, and %3$s is the StatusNet sitename.
824 $headers['Subject'] = sprintf(_('%1$s has joined '.
825 'your group %2$s on %3$s.'),
826 $joiner->getBestName(),
827 $group->getBestName(),
828 common_config('site', 'name'));
830 // TRANS: Main body of group join notification e-mail.
831 // TRANS: %1$s is the subscriber's long name, %2$s is the group name, and %3$s is the StatusNet sitename,
832 // TRANS: %4$s is a block of profile info about the subscriber.
833 // TRANS: %5$s is a link to the addressed user's e-mail settings.
834 $body = sprintf(_('%1$s has joined your group %2$s on %3$s.'),
835 $joiner->getFancyName(),
836 $group->getFancyName(),
837 common_config('site', 'name')) .
838 mail_profile_block($joiner) .
841 // reset localization
842 common_switch_locale();
843 mail_send($adminUser->email, $headers, $body);
850 * Send notification emails to group administrator.
852 * @param User_group $group
853 * @param Profile $joiner
855 function mail_notify_group_join_pending($group, $joiner)
857 $admin = $group->getAdmins();
858 while ($admin->fetch()) {
859 // We need a local user for email notifications...
860 $adminUser = User::staticGet('id', $admin->id);
861 // @fixme check for email preference?
862 if ($adminUser && $adminUser->email) {
863 // use the recipient's localization
864 common_switch_locale($adminUser->language);
866 $headers = _mail_prepare_headers('join', $admin->nickname, $joiner->nickname);
867 $headers['From'] = mail_notify_from();
868 $headers['To'] = $admin->getBestName() . ' <' . $adminUser->email . '>';
869 // TRANS: Subject of pending group join request notification e-mail.
870 // TRANS: %1$s is the joining user's nickname, %2$s is the group name, and %3$s is the StatusNet sitename.
871 $headers['Subject'] = sprintf(_('%1$s wants to join your group %2$s on %3$s.'),
872 $joiner->getBestName(),
873 $group->getBestName(),
874 common_config('site', 'name'));
876 // TRANS: Main body of pending group join request notification e-mail.
877 // TRANS: %1$s is the subscriber's long name, %2$s is the group name, and %3$s is the StatusNet sitename,
878 // TRANS: %4$s is the URL to the moderation queue page.
879 $body = sprintf(_('%1$s would like to join your group %2$s on %3$s. ' .
880 'You may approve or reject their group membership at %4$s'),
881 $joiner->getFancyName(),
882 $group->getFancyName(),
883 common_config('site', 'name'),
884 common_local_url('groupqueue', array('nickname' => $group->nickname))) .
885 mail_profile_block($joiner) .
888 // reset localization
889 common_switch_locale();
890 mail_send($adminUser->email, $headers, $body);