- $recipients = $address;
- $profile = $user->getProfile();
-
- $headers['From'] = mail_notify_from();
- $headers['To'] = $profile->getBestName() . ' <' . $address . '>';
- $headers['Subject'] = $subject;
-
- return mail_send($recipients, $headers, $body);
-}
-
-# For confirming a Jabber address
-# XXX: change to use mail_to_user() above
-
-function mail_confirm_address($code, $nickname, $address) {
- $recipients = $address;
- $headers['From'] = mail_notify_from();
- $headers['To'] = $nickname . ' <' . $address . '>';
- $headers['Subject'] = _('Email address confirmation');
-
- $body = "Hey, $nickname.";
- $body .= "\n\n";
- $body .= 'Someone just entered this email address on ' . common_config('site', 'name') . '.';
- $body .= "\n\n";
- $body .= 'If it was you, and you want to confirm your entry, use the URL below:';
- $body .= "\n\n";
- $body .= "\t".common_local_url('confirmaddress',
- array('code' => $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";
-
- mail_send($recipients, $headers, $body);
-}
-
-function mail_subscribe_notify($listenee, $listener) {
- if ($listenee->email && $listenee->emailnotifysub) {
- $profile = $listenee->getProfile();
- $other = $listener->getProfile();
- $name = $profile->getBestName();
- $long_name = ($other->fullname) ? ($other->fullname . ' (' . $other->nickname . ')') : $other->nickname;
- $recipients = $listenee->email;
- $headers['From'] = mail_notify_from();
- $headers['To'] = $name . ' <' . $listenee->email . '>';
- $headers['Subject'] = sprintf(_('%1$s is now listening to your notices on %2$s.'), $other->getBestName(),
- common_config('site', 'name'));
- $body = sprintf(_('%1$s is now listening to your notices on %2$s.'."\n\n".
- "\t".'%3$s'."\n\n".
- 'Faithfully yours,'."\n".'%4$s.'."\n"),
- $long_name,
- common_config('site', 'name'),
- $other->profileurl,
- common_config('site', 'name'));
- mail_send($recipients, $headers, $body);
- }
-}
-
-function mail_new_incoming_notify($user) {
-
- $profile = $user->getProfile();
- $name = $profile->getBestName();
-
- $headers['From'] = $user->incomingemail;
- $headers['To'] = $name . ' <' . $user->email . '>';
- $headers['Subject'] = sprintf(_('New email address for posting to %s'),
- common_config('site', 'name'));
-
- $body = sprintf(_("You have a new posting address on %1\$s.\n\n".
- "Send email to %2\$s to post new messages.\n\n".
- "More email instructions at %3\$s.\n\n".
- "Faithfully yours,\n%4\$s"),
- common_config('site', 'name'),
- $user->incomingemail,
- common_local_url('doc', array('title' => 'email')),
- common_config('site', 'name'));
-
- mail_send($user->email, $headers, $body);
-}
-
-function mail_new_incoming_address() {
- $prefix = common_good_rand(8);
- $suffix = mail_domain();
- return $prefix . '@' . $suffix;
-}
-
-function mail_broadcast_notice_sms($notice) {
-
- $user = new User();
-
- $user->smsnotify = 1;
- $user->whereAdd('EXISTS (select subscriber from subscriptions where ' .
- ' subscriber = user.id and subscribed = ' . $notice->profile_id);
- $user->whereAdd('sms is not null');
-
- $cnt = $user->find();
-
- while ($user->fetch()) {
- $success = mail_send_sms_notice($notice, $user);
- if (!$success) {
- common_log(LOG_ERR, 'Could not send SMS message to user', __FILE__);
- return false;
- }
- }
-
- return true;
-}
-
-function mail_send_sms_notice($notice, $user) {
- $profile = $user->getProfile();
- $name = $profile->getBestName();
- $to = $name . ' <' . $user->smsemail . '>';
- $other = $notice->getProfile();
-
- $headers = array();
- $headers['From'] = $user->incomingemail;
- $headers['To'] = $to;
- $headers['Subject'] = sprintf(_('%s status'),
- $other->getBestName());
- $body = $notice->content;
-
- return mail_send($user->smsemail, $headers, $body);
-}
-
-function mail_confirm_sms($code, $nickname, $address) {
-
- $recipients = $address;
-
- $headers['From'] = mail_notify_from();
- $headers['To'] = $nickname . ' <' . $address . '>';
- $headers['Subject'] = _('SMS confirmation');
+function mail_new_incoming_notify($user)
+{
+ $profile = $user->getProfile();
+
+ $name = $profile->getBestName();
+
+ $headers['From'] = $user->incomingemail;
+ $headers['To'] = $name . ' <' . $user->email . '>';
+ $headers['Subject'] = sprintf(_('New email address for posting to %s'),
+ common_config('site', 'name'));
+
+ $body = sprintf(_("You have a new posting address on %1\$s.\n\n".
+ "Send email to %2\$s to post new messages.\n\n".
+ "More email instructions at %3\$s.\n\n".
+ "Faithfully yours,\n%4\$s"),
+ common_config('site', 'name'),
+ $user->incomingemail,
+ common_local_url('doc', array('title' => 'email')),
+ common_config('site', 'name'));
+
+ mail_send($user->email, $headers, $body);
+}
+
+/**
+ * generate a new address for incoming messages
+ *
+ * @todo check the database for uniqueness
+ *
+ * @return string new email address for incoming messages
+ */
+
+function mail_new_incoming_address()
+{
+ $prefix = common_confirmation_code(64);
+ $suffix = mail_domain();
+ return $prefix . '@' . $suffix;
+}
+
+/**
+ * broadcast a notice to all subscribers with SMS notification on
+ *
+ * This function sends SMS messages to all users who have sms addresses;
+ * have sms notification on; and have sms enabled for this particular
+ * subscription.
+ *
+ * @param Notice $notice The notice to broadcast
+ *
+ * @return success flag
+ */
+
+function mail_broadcast_notice_sms($notice)
+{
+ // Now, get users subscribed to this profile
+
+ $user = new User();
+
+ $user->query('SELECT nickname, smsemail, incomingemail ' .
+ 'FROM user JOIN subscription ' .
+ 'ON user.id = subscription.subscriber ' .
+ 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' .
+ 'AND user.smsemail IS NOT null ' .
+ 'AND user.smsnotify = 1 ' .
+ 'AND subscription.sms = 1 ');
+
+ while ($user->fetch()) {
+ common_log(LOG_INFO,
+ 'Sending notice ' . $notice->id . ' to ' . $user->smsemail,
+ __FILE__);
+ $success = mail_send_sms_notice_address($notice,
+ $user->smsemail,
+ $user->incomingemail);
+ if (!$success) {
+ // XXX: Not sure, but I think that's the right thing to do
+ common_log(LOG_WARNING,
+ 'Sending notice ' . $notice->id . ' to ' .
+ $user->smsemail . ' FAILED, cancelling.',
+ __FILE__);
+ return false;
+ }
+ }
+
+ $user->free();
+ unset($user);
+
+ return true;
+}
+
+/**
+ * send a notice to a user via SMS
+ *
+ * A convenience wrapper around mail_send_sms_notice_address()
+ *
+ * @param Notice $notice notice to send
+ * @param User $user user to receive notice
+ *
+ * @see mail_send_sms_notice_address()
+ *
+ * @return boolean success flag
+ */
+
+function mail_send_sms_notice($notice, $user)
+{
+ return mail_send_sms_notice_address($notice,
+ $user->smsemail,
+ $user->incomingemail);
+}
+
+/**
+ * send a notice to an SMS email address from a given address
+ *
+ * We use the user's incoming email address as the "From" address to make
+ * replying to notices easier.
+ *
+ * @param Notice $notice notice to send
+ * @param string $smsemail email address to send to
+ * @param string $incomingemail email address to set as 'from'
+ *
+ * @return boolean success flag
+ */
+
+function mail_send_sms_notice_address($notice, $smsemail, $incomingemail)
+{
+ $to = $nickname . ' <' . $smsemail . '>';
+
+ $other = $notice->getProfile();
+
+ common_log(LOG_INFO, 'Sending notice ' . $notice->id .
+ ' to ' . $smsemail, __FILE__);
+
+ $headers = array();
+
+ $headers['From'] = ($incomingemail) ? $incomingemail : mail_notify_from();
+ $headers['To'] = $to;
+ $headers['Subject'] = sprintf(_('%s status'),
+ $other->getBestName());
+
+ $body = $notice->content;
+
+ return mail_send($smsemail, $headers, $body);
+}
+
+/**
+ * send a message to confirm a claim for an SMS number
+ *
+ * @param string $code confirmation code
+ * @param string $nickname nickname of user claiming number
+ * @param string $address email address to send the confirmation to
+ *
+ * @see common_confirmation_code()
+ *
+ * @return void
+ */
+
+function mail_confirm_sms($code, $nickname, $address)
+{
+ $recipients = $address;
+
+ $headers['From'] = mail_notify_from();
+ $headers['To'] = $nickname . ' <' . $address . '>';
+ $headers['Subject'] = _('SMS confirmation');
+
+ // FIXME: I18N
+
+ $body = "$nickname: confirm you own this phone number with this code:";
+ $body .= "\n\n";
+ $body .= $code;
+ $body .= "\n\n";
+
+ mail_send($recipients, $headers, $body);
+}
+
+/**
+ * send a mail message to notify a user of a 'nudge'
+ *
+ * @param User $from user nudging
+ * @param User $to user being nudged
+ *
+ * @return boolean success flag
+ */
+
+function mail_notify_nudge($from, $to)
+{
+ common_init_locale($to->language);
+ $subject = sprintf(_('You\'ve been nudged by %s'), $from->nickname);
+
+ $from_profile = $from->getProfile();
+
+ $body = sprintf(_("%1\$s (%2\$s) is wondering what you are up to ".
+ "these days and is inviting you to post some news.\n\n".
+ "So let's hear from you :)\n\n".
+ "%3\$s\n\n".
+ "Don't reply to this email; it won't get to them.\n\n".
+ "With kind regards,\n".
+ "%4\$s\n"),
+ $from_profile->getBestName(),
+ $from->nickname,
+ common_local_url('all', array('nickname' => $to->nickname)),
+ common_config('site', 'name'));
+ common_init_locale();
+ return mail_to_user($to, $subject, $body);
+}
+
+/**
+ * send a message to notify a user of a direct message (DM)
+ *
+ * This function checks to see if the recipient wants notification
+ * of DMs and has a configured email address.
+ *
+ * @param Message $message message to notify about
+ * @param User $from user sending message; default to sender
+ * @param User $to user receiving message; default to recipient
+ *
+ * @return boolean success code
+ */
+
+function mail_notify_message($message, $from=null, $to=null)
+{
+ if (is_null($from)) {
+ $from = User::staticGet('id', $message->from_profile);
+ }
+
+ if (is_null($to)) {
+ $to = User::staticGet('id', $message->to_profile);
+ }
+
+ if (is_null($to->email) || !$to->emailnotifymsg) {
+ return true;
+ }
+
+ common_init_locale($to->language);
+ $subject = sprintf(_('New private message from %s'), $from->nickname);
+
+ $from_profile = $from->getProfile();
+
+ $body = sprintf(_("%1\$s (%2\$s) sent you a private message:\n\n".
+ "------------------------------------------------------\n".
+ "%3\$s\n".
+ "------------------------------------------------------\n\n".
+ "You can reply to their message here:\n\n".
+ "%4\$s\n\n".
+ "Don't reply to this email; it won't get to them.\n\n".
+ "With kind regards,\n".
+ "%5\$s\n"),
+ $from_profile->getBestName(),
+ $from->nickname,
+ $message->content,
+ common_local_url('newmessage', array('to' => $from->id)),
+ common_config('site', 'name'));
+
+ common_init_locale();
+ return mail_to_user($to, $subject, $body);
+}
+
+/**
+ * notify a user that one of their notices has been chosen as a 'fave'
+ *
+ * Doesn't check that the user has an email address nor if they
+ * want to receive notification of faves. Maybe this happens higher
+ * up the stack...?
+ *
+ * @param User $other The user whose notice was faved
+ * @param User $user The user who faved the notice
+ * @param Notice $notice The notice that was faved
+ *
+ * @return void
+ */