function notifyBackupFile($user, $fileName)
 {
     $fileUrl = File::url($fileName);
     $body = sprintf(_m("The backup file you requested is ready for download.\n\n" . "%s\n" . "Thanks for your time,\n", "%s\n"), $fileUrl, common_config('site', 'name'));
     $headers = _mail_prepare_headers('offlinebackup', $user->nickname, $user->nickname);
     mail_to_user($user, _('Backup file ready for download'), $body, $headers);
 }
Esempio n. 2
0
 function recoverPassword()
 {
     $nore = $this->trimmed('nicknameoremail');
     if (!$nore) {
         // TRANS: Form instructions for password recovery form.
         $this->showForm(_('Enter a nickname or email address.'));
         return;
     }
     $user = User::staticGet('email', common_canonical_email($nore));
     if (!$user) {
         try {
             $user = User::staticGet('nickname', common_canonical_nickname($nore));
         } catch (NicknameException $e) {
             // invalid
         }
     }
     # See if it's an unconfirmed email address
     if (!$user) {
         // Warning: it may actually be legit to have multiple folks
         // who have claimed, but not yet confirmed, the same address.
         // We'll only send to the first one that comes up.
         $confirm_email = new Confirm_address();
         $confirm_email->address = common_canonical_email($nore);
         $confirm_email->address_type = 'email';
         $confirm_email->find();
         if ($confirm_email->fetch()) {
             $user = User::staticGet($confirm_email->user_id);
         } else {
             $confirm_email = null;
         }
     } else {
         $confirm_email = null;
     }
     if (!$user) {
         // TRANS: Information on password recovery form if no known username or e-mail address was specified.
         $this->showForm(_('No user with that email address or username.'));
         return;
     }
     # Try to get an unconfirmed email address if they used a user name
     if (!$user->email && !$confirm_email) {
         $confirm_email = new Confirm_address();
         $confirm_email->user_id = $user->id;
         $confirm_email->address_type = 'email';
         $confirm_email->find();
         if (!$confirm_email->fetch()) {
             $confirm_email = null;
         }
     }
     if (!$user->email && !$confirm_email) {
         // TRANS: Client error displayed on password recovery form if a user does not have a registered e-mail address.
         $this->clientError(_('No registered email address for that user.'));
         return;
     }
     # Success! We have a valid user and a confirmed or unconfirmed email address
     $confirm = new Confirm_address();
     $confirm->code = common_confirmation_code(128);
     $confirm->address_type = 'recover';
     $confirm->user_id = $user->id;
     $confirm->address = !empty($user->email) ? $user->email : $confirm_email->address;
     if (!$confirm->insert()) {
         common_log_db_error($confirm, 'INSERT', __FILE__);
         // TRANS: Server error displayed if e-mail address confirmation fails in the database on the password recovery form.
         $this->serverError(_('Error saving address confirmation.'));
         return;
     }
     // @todo FIXME: needs i18n.
     $body = "Hey, {$user->nickname}.";
     $body .= "\n\n";
     $body .= 'Someone just asked for a new password ' . 'for this account on ' . common_config('site', 'name') . '.';
     $body .= "\n\n";
     $body .= 'If it was you, and you want to confirm, use the URL below:';
     $body .= "\n\n";
     $body .= "\t" . common_local_url('recoverpassword', array('code' => $confirm->code));
     $body .= "\n\n";
     $body .= 'If not, just ignore this message.';
     $body .= "\n\n";
     $body .= 'Thanks for your time, ';
     $body .= "\n";
     $body .= common_config('site', 'name');
     $body .= "\n";
     $headers = _mail_prepare_headers('recoverpassword', $user->nickname, $user->nickname);
     // TRANS: Subject for password recovery e-mail.
     mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address);
     $this->mode = 'sent';
     // TRANS: User notification after an e-mail with instructions was sent from the password recovery form.
     $this->msg = _('Instructions for recovering your password ' . 'have been sent to the email address registered to your ' . 'account.');
     $this->success = true;
     $this->showPage();
 }
Esempio n. 3
0
/**
 * Notify a user that one of their notices has been chosen as a 'fave'
 *
 * @param User    $rcpt   The user whose notice was faved
 * @param Profile $sender The user who faved the notice
 * @param Notice  $notice The notice that was faved
 *
 * @return void
 */
function mail_notify_fave(User $rcpt, Profile $sender, Notice $notice)
{
    if (!$rcpt->receivesEmailNotifications() || !$rcpt->getConfigPref('email', 'notify_fave')) {
        return;
    }
    // This test is actually "if the sender is sandboxed"
    if (!$sender->hasRight(Right::EMAILONFAVE)) {
        return;
    }
    if ($rcpt->hasBlocked($sender)) {
        // If the author has blocked us, don't spam them with a notification.
        return;
    }
    // We need the global mail.php for various mail related functions below.
    require_once INSTALLDIR . '/lib/mail.php';
    $bestname = $sender->getBestName();
    common_switch_locale($rcpt->language);
    // TRANS: Subject for favorite notification e-mail.
    // TRANS: %1$s is the adding user's long name, %2$s is the adding user's nickname.
    $subject = sprintf(_('%1$s (@%2$s) added your notice as a favorite'), $bestname, $sender->getNickname());
    // TRANS: Body for favorite notification e-mail.
    // TRANS: %1$s is the adding user's long name, $2$s is the date the notice was created,
    // TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text,
    // TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename,
    // TRANS: %7$s is the adding user's nickname.
    $body = sprintf(_("%1\$s (@%7\$s) just added your notice from %2\$s" . " as one of their favorites.\n\n" . "The URL of your notice is:\n\n" . "%3\$s\n\n" . "The text of your notice is:\n\n" . "%4\$s\n\n" . "You can see the list of %1\$s's favorites here:\n\n" . "%5\$s"), $bestname, common_exact_date($notice->created), common_local_url('shownotice', array('notice' => $notice->id)), $notice->content, common_local_url('showfavorites', array('nickname' => $sender->getNickname())), common_config('site', 'name'), $sender->getNickname()) . mail_footer_block();
    $headers = _mail_prepare_headers('fave', $rcpt->getNickname(), $sender->getNickname());
    common_switch_locale();
    mail_to_user($rcpt, $subject, $body, $headers);
}
Esempio n. 4
0
/**
 * notify a user that they have received an "attn:" message AKA "@-reply"
 *
 * @param User   $user   The user who recevied the notice
 * @param Notice $notice The notice that was sent
 *
 * @return void
 */
function mail_notify_attn($user, $notice)
{
    if (!$user->email || !$user->emailnotifyattn) {
        return;
    }
    $sender = $notice->getProfile();
    if ($sender->id == $user->id) {
        return;
    }
    if (!$sender->hasRight(Right::EMAILONREPLY)) {
        return;
    }
    $bestname = $sender->getBestName();
    common_switch_locale($user->language);
    if ($notice->hasConversation()) {
        $conversationUrl = common_local_url('conversation', array('id' => $notice->conversation)) . '#notice-' . $notice->id;
        // TRANS: Line in @-reply notification e-mail. %s is conversation URL.
        $conversationEmailText = sprintf(_("The full conversation can be read here:\n\n" . "\t%s"), $conversationUrl) . "\n\n";
    } else {
        $conversationEmailText = '';
    }
    // TRANS: E-mail subject for notice notification.
    // TRANS: %1$s is the sending user's long name, %2$s is the adding user's nickname.
    $subject = sprintf(_('%1$s (@%2$s) sent a notice to your attention'), $bestname, $sender->nickname);
    // TRANS: Body of @-reply notification e-mail.
    // TRANS: %1$s is the sending user's long name, $2$s is the StatusNet sitename,
    // TRANS: %3$s is a URL to the notice, %4$s is the notice text,
    // TRANS: %5$s is a URL to the full conversion if it exists (otherwise empty),
    // TRANS: %6$s is a URL to reply to the notice, %7$s is a URL to all @-replied for the addressed user,
    // TRANS: %8$s is a URL to the addressed user's e-mail settings, %9$s is the sender's nickname.
    $body = sprintf(_("%1\$s (@%9\$s) just sent a notice to your attention (an '@-reply') on %2\$s.\n\n" . "The notice is here:\n\n" . "\t%3\$s\n\n" . "It reads:\n\n" . "\t%4\$s\n\n" . "%5\$s" . "You can reply back here:\n\n" . "\t%6\$s\n\n" . "The list of all @-replies for you here:\n\n" . "%7\$s\n\n" . "Faithfully yours,\n" . "%2\$s\n\n" . "P.S. You can turn off these email notifications here: %8\$s\n"), $bestname, common_config('site', 'name'), common_local_url('shownotice', array('notice' => $notice->id)), $notice->content, $conversationEmailText, common_local_url('newnotice', array('replyto' => $sender->nickname, 'inreplyto' => $notice->id)), common_local_url('replies', array('nickname' => $user->nickname)), common_local_url('emailsettings'), $sender->nickname);
    //%9
    $headers = _mail_prepare_headers('mention', $user->nickname, $sender->nickname);
    common_switch_locale();
    mail_to_user($user, $subject, $body, $headers);
}
Esempio n. 5
0
/**
 * Send notification emails to group administrator.
 *
 * @param User_group $group
 * @param Profile $joiner
 */
function mail_notify_group_join_pending($group, $joiner)
{
    $admin = $group->getAdmins();
    while ($admin->fetch()) {
        // We need a local user for email notifications...
        $adminUser = User::staticGet('id', $admin->id);
        // @fixme check for email preference?
        if ($adminUser && $adminUser->email) {
            // use the recipient's localization
            common_switch_locale($adminUser->language);
            $headers = _mail_prepare_headers('join', $admin->nickname, $joiner->nickname);
            $headers['From'] = mail_notify_from();
            $headers['To'] = $admin->getBestName() . ' <' . $adminUser->email . '>';
            // TRANS: Subject of pending group join request notification e-mail.
            // TRANS: %1$s is the joining user's nickname, %2$s is the group name, and %3$s is the StatusNet sitename.
            $headers['Subject'] = sprintf(_('%1$s wants to join your group %2$s on %3$s.'), $joiner->getBestName(), $group->getBestName(), common_config('site', 'name'));
            // TRANS: Main body of pending group join request notification e-mail.
            // TRANS: %1$s is the subscriber's long name, %2$s is the group name, and %3$s is the StatusNet sitename,
            // TRANS: %4$s is the URL to the moderation queue page.
            $body = sprintf(_('%1$s would like to join your group %2$s on %3$s. ' . 'You may approve or reject their group membership at %4$s'), $joiner->getFancyName(), $group->getFancyName(), common_config('site', 'name'), common_local_url('groupqueue', array('nickname' => $group->nickname))) . mail_profile_block($joiner) . mail_footer_block();
            // reset localization
            common_switch_locale();
            mail_send($adminUser->email, $headers, $body);
        }
    }
}
Esempio n. 6
0
 static function recoverPassword($nore)
 {
     $user = User::staticGet('email', common_canonical_email($nore));
     if (!$user) {
         try {
             $user = User::staticGet('nickname', common_canonical_nickname($nore));
         } catch (NicknameException $e) {
             // invalid
         }
     }
     // See if it's an unconfirmed email address
     if (!$user) {
         // Warning: it may actually be legit to have multiple folks
         // who have claimed, but not yet confirmed, the same address.
         // We'll only send to the first one that comes up.
         $confirm_email = new Confirm_address();
         $confirm_email->address = common_canonical_email($nore);
         $confirm_email->address_type = 'email';
         $confirm_email->find();
         if ($confirm_email->fetch()) {
             $user = User::staticGet($confirm_email->user_id);
         } else {
             $confirm_email = null;
         }
     } else {
         $confirm_email = null;
     }
     if (!$user) {
         // TRANS: Information on password recovery form if no known username or e-mail address was specified.
         throw new ClientException(_('No user with that email address or username.'));
         return;
     }
     // Try to get an unconfirmed email address if they used a user name
     if (!$user->email && !$confirm_email) {
         $confirm_email = new Confirm_address();
         $confirm_email->user_id = $user->id;
         $confirm_email->address_type = 'email';
         $confirm_email->find();
         if (!$confirm_email->fetch()) {
             $confirm_email = null;
         }
     }
     if (!$user->email && !$confirm_email) {
         // TRANS: Client error displayed on password recovery form if a user does not have a registered e-mail address.
         throw new ClientException(_('No registered email address for that user.'));
         return;
     }
     // Success! We have a valid user and a confirmed or unconfirmed email address
     $confirm = new Confirm_address();
     $confirm->code = common_confirmation_code(128);
     $confirm->address_type = 'recover';
     $confirm->user_id = $user->id;
     $confirm->address = !empty($user->email) ? $user->email : $confirm_email->address;
     if (!$confirm->insert()) {
         common_log_db_error($confirm, 'INSERT', __FILE__);
         // TRANS: Server error displayed if e-mail address confirmation fails in the database on the password recovery form.
         throw new ServerException(_('Error saving address confirmation.'));
         return;
     }
     // @todo FIXME: needs i18n.
     $body = "Hola, {$user->nickname}.";
     $body .= "\n\n";
     $body .= 'Alguien ha solicitado una nueva contraseña ' . 'para esta cuenta en ' . common_config('site', 'name') . '.';
     $body .= "\n\n";
     $body .= 'Si has sido tú, y quieres modificarla, pulsa en el enlace de abajo:';
     $body .= "\n\n";
     $body .= "\t" . common_local_url('recoverpassword', array('code' => $confirm->code));
     $body .= "\n\n";
     $body .= 'Si no, puedes ignorar y eliminar este mensaje.';
     $body .= "\n\n";
     $body .= 'Gracias por tu tiempo, ';
     $body .= "\n";
     $body .= common_config('site', 'name');
     $body .= "\n";
     $headers = _mail_prepare_headers('recoverpassword', $user->nickname, $user->nickname);
     // TRANS: Subject for password recovery e-mail.
     mail_to_user($user, _('Solicitud de recuperación de contraseña'), $body, $headers, $confirm->address);
 }
 function notifyByMail()
 {
     $to = User::staticGet('id', $this->to_profile);
     if (empty($to) || is_null($to->email) || !$to->emailnotifymsg) {
         return true;
     }
     $gm = Group_message::staticGet('id', $this->group_message_id);
     $from_profile = Profile::staticGet('id', $gm->from_profile);
     $group = $gm->getGroup();
     common_switch_locale($to->language);
     // TRANS: Subject for direct-message notification email.
     // TRANS: %s is the sending user's nickname.
     $subject = sprintf(_('New private message from %s to group %s'), $from_profile->nickname, $group->nickname);
     // TRANS: Body for direct-message notification email.
     // TRANS: %1$s is the sending user's long name, %2$s is the sending user's nickname,
     // TRANS: %3$s is the message content, %4$s a URL to the message,
     // TRANS: %5$s is the StatusNet sitename.
     $body = sprintf(_("%1\$s (%2\$s) sent a private message to group %3\$s:\n\n" . "------------------------------------------------------\n" . "%4\$s\n" . "------------------------------------------------------\n\n" . "You can reply to their message here:\n\n" . "%5\$s\n\n" . "Don't reply to this email; it won't get to them.\n\n" . "With kind regards,\n" . "%6\$s\n"), $from_profile->getBestName(), $from_profile->nickname, $group->nickname, $gm->content, common_local_url('newmessage', array('to' => $from_profile->id)), common_config('site', 'name'));
     $headers = _mail_prepare_headers('message', $to->nickname, $from_profile->nickname);
     common_switch_locale();
     return mail_to_user($to, $subject, $body, $headers);
 }
Esempio n. 8
0
 static function recoverPassword($nore)
 {
     // $confirm_email will be used as a fallback if our user doesn't have a confirmed email
     $confirm_email = null;
     if (common_is_email($nore)) {
         $user = User::getKV('email', common_canonical_email($nore));
         // See if it's an unconfirmed email address
         if (!$user instanceof User) {
             // Warning: it may actually be legit to have multiple folks
             // who have claimed, but not yet confirmed, the same address.
             // We'll only send to the first one that comes up.
             $confirm_email = new Confirm_address();
             $confirm_email->address = common_canonical_email($nore);
             $confirm_email->address_type = 'email';
             if ($confirm_email->find(true)) {
                 $user = User::getKV('id', $confirm_email->user_id);
             }
         }
         // No luck finding anyone by that email address.
         if (!$user instanceof User) {
             if (common_config('site', 'fakeaddressrecovery')) {
                 // Return without actually doing anything! We fake address recovery
                 // to avoid revealing which email addresses are registered with the site.
                 return;
             }
             // TRANS: Information on password recovery form if no known e-mail address was specified.
             throw new ClientException(_('No user with that email address exists here.'));
         }
     } else {
         // This might throw a NicknameException on bad nicknames
         $user = User::getKV('nickname', common_canonical_nickname($nore));
         if (!$user instanceof User) {
             // TRANS: Information on password recovery form if no known username was specified.
             throw new ClientException(_('No user with that nickname exists here.'));
         }
     }
     // Try to get an unconfirmed email address if they used a user name
     if (empty($user->email) && $confirm_email === null) {
         $confirm_email = new Confirm_address();
         $confirm_email->user_id = $user->id;
         $confirm_email->address_type = 'email';
         $confirm_email->find();
         if (!$confirm_email->fetch()) {
             // Nothing found, so let's reset it to null
             $confirm_email = null;
         }
     }
     if (empty($user->email) && !$confirm_email instanceof Confirm_address) {
         // TRANS: Client error displayed on password recovery form if a user does not have a registered e-mail address.
         throw new ClientException(_('No registered email address for that user.'));
     }
     // Success! We have a valid user and a confirmed or unconfirmed email address
     $confirm = new Confirm_address();
     $confirm->code = common_confirmation_code(128);
     $confirm->address_type = 'recover';
     $confirm->user_id = $user->id;
     $confirm->address = $user->email ?: $confirm_email->address;
     if (!$confirm->insert()) {
         common_log_db_error($confirm, 'INSERT', __FILE__);
         // TRANS: Server error displayed if e-mail address confirmation fails in the database on the password recovery form.
         throw new ServerException(_('Error saving address confirmation.'));
     }
     // @todo FIXME: needs i18n.
     $body = "Hey, {$user->nickname}.";
     $body .= "\n\n";
     $body .= 'Someone just asked for a new password ' . 'for this account on ' . common_config('site', 'name') . '.';
     $body .= "\n\n";
     $body .= 'If it was you, and you want to confirm, use the URL below:';
     $body .= "\n\n";
     $body .= "\t" . common_local_url('recoverpassword', array('code' => $confirm->code));
     $body .= "\n\n";
     $body .= 'If not, just ignore this message.';
     $body .= "\n\n";
     $body .= 'Thanks for your time, ';
     $body .= "\n";
     $body .= common_config('site', 'name');
     $body .= "\n";
     $headers = _mail_prepare_headers('recoverpassword', $user->nickname, $user->nickname);
     // TRANS: Subject for password recovery e-mail.
     mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address);
 }