Commit dbe6b979d7e07b47aa4cab5c7ccf54d3ba24f319
- Diff rendering mode:
- inline
- side by side
lib/mail.php
(50 / 16)
|   | |||
| 133 | 133 | * @param User &$user user to send email to | |
| 134 | 134 | * @param string $subject subject of the email | |
| 135 | 135 | * @param string $body body of the email | |
| 136 | * @param array $headers optional list of email headers | ||
| 136 | 137 | * @param string $address optional specification of email address | |
| 137 | 138 | * | |
| 138 | 139 | * @return boolean success flag | |
| 139 | 140 | */ | |
| 140 | 141 | ||
| 141 | function mail_to_user(&$user, $subject, $body, $address=null) | ||
| 142 | function mail_to_user(&$user, $subject, $body, $headers=array(), $address=null) | ||
| 142 | 143 | { | |
| 143 | 144 | if (!$address) { | |
| 144 | 145 | $address = $user->email; | |
| … | … | ||
| 181 | 181 | $nickname, common_config('site', 'name'), | |
| 182 | 182 | common_local_url('confirmaddress', array('code' => $code)), | |
| 183 | 183 | common_config('site', 'name')); | |
| 184 | return mail_to_user($user, $subject, $body, $address); | ||
| 184 | $headers = array(); | ||
| 185 | |||
| 186 | return mail_to_user($user, $subject, $body, $headers, $address); | ||
| 185 | 187 | } | |
| 186 | 188 | ||
| 187 | 189 | /** | |
| … | … | ||
| 234 | 234 | ||
| 235 | 235 | $recipients = $listenee->email; | |
| 236 | 236 | ||
| 237 | $headers = _mail_prepare_headers('subscribe', $listenee->nickname, $other->nickname); | ||
| 237 | 238 | $headers['From'] = mail_notify_from(); | |
| 238 | 239 | $headers['To'] = $name . ' <' . $listenee->email . '>'; | |
| 239 | 240 | $headers['Subject'] = sprintf(_('%1$s is now listening to '. | |
| … | … | ||
| 480 | 480 | common_local_url('all', array('nickname' => $to->nickname)), | |
| 481 | 481 | common_config('site', 'name')); | |
| 482 | 482 | common_init_locale(); | |
| 483 | return mail_to_user($to, $subject, $body); | ||
| 483 | |||
| 484 | $headers = _mail_prepare_headers('nudge', $to->nickname, $from->nickname); | ||
| 485 | |||
| 486 | return mail_to_user($to, $subject, $body, $headers); | ||
| 484 | 487 | } | |
| 485 | 488 | ||
| 486 | 489 | /** | |
| … | … | ||
| 533 | 533 | common_local_url('newmessage', array('to' => $from->id)), | |
| 534 | 534 | common_config('site', 'name')); | |
| 535 | 535 | ||
| 536 | $headers = _mail_prepare_headers('message', $to->nickname, $from->nickname); | ||
| 537 | |||
| 536 | 538 | common_init_locale(); | |
| 537 | return mail_to_user($to, $subject, $body); | ||
| 539 | return mail_to_user($to, $subject, $body, $headers); | ||
| 538 | 540 | } | |
| 539 | 541 | ||
| 540 | 542 | /** | |
| … | … | ||
| 587 | 587 | common_config('site', 'name'), | |
| 588 | 588 | $user->nickname); | |
| 589 | 589 | ||
| 590 | $headers = _mail_prepare_headers('fave', $other->nickname, $user->nickname); | ||
| 591 | |||
| 590 | 592 | common_init_locale(); | |
| 591 | mail_to_user($other, $subject, $body); | ||
| 593 | mail_to_user($other, $subject, $body, $headers); | ||
| 592 | 594 | } | |
| 593 | 595 | ||
| 594 | 596 | /** | |
| … | … | ||
| 622 | 622 | ||
| 623 | 623 | common_init_locale($user->language); | |
| 624 | 624 | ||
| 625 | if ($notice->conversation != $notice->id) { | ||
| 626 | $conversationEmailText = "The full conversation can be read here:\n\n". | ||
| 627 | "\t%5\$s\n\n "; | ||
| 628 | $conversationUrl = common_local_url('conversation', | ||
| 625 | if ($notice->conversation != $notice->id) { | ||
| 626 | $conversationEmailText = "The full conversation can be read here:\n\n". | ||
| 627 | "\t%5\$s\n\n "; | ||
| 628 | $conversationUrl = common_local_url('conversation', | ||
| 629 | 629 | array('id' => $notice->conversation)).'#notice-'.$notice->id; | |
| 630 | } else { | ||
| 631 | $conversationEmailText = "%5\$s"; | ||
| 632 | $conversationUrl = null; | ||
| 633 | } | ||
| 630 | } else { | ||
| 631 | $conversationEmailText = "%5\$s"; | ||
| 632 | $conversationUrl = null; | ||
| 633 | } | ||
| 634 | 634 | ||
| 635 | 635 | $subject = sprintf(_('%s (@%s) sent a notice to your attention'), $bestname, $sender->nickname); | |
| 636 | 636 | ||
| 637 | $body = sprintf(_("%1\$s (@%9\$s) just sent a notice to your attention (an '@-reply') on %2\$s.\n\n". | ||
| 637 | $body = sprintf(_("%1\$s (@%9\$s) just sent a notice to your attention (an '@-reply') on %2\$s.\n\n". | ||
| 638 | 638 | "The notice is here:\n\n". | |
| 639 | 639 | "\t%3\$s\n\n" . | |
| 640 | 640 | "It reads:\n\n". | |
| … | … | ||
| 652 | 652 | common_local_url('shownotice', | |
| 653 | 653 | array('notice' => $notice->id)),//%3 | |
| 654 | 654 | $notice->content,//%4 | |
| 655 | $conversationUrl,//%5 | ||
| 655 | $conversationUrl,//%5 | ||
| 656 | 656 | common_local_url('newnotice', | |
| 657 | 657 | array('replyto' => $sender->nickname, 'inreplyto' => $notice->id)),//%6 | |
| 658 | 658 | common_local_url('replies', | |
| … | … | ||
| 660 | 660 | common_local_url('emailsettings'), //%8 | |
| 661 | 661 | $sender->nickname); //%9 | |
| 662 | 662 | ||
| 663 | $headers = _mail_prepare_headers('mention', $user->nickname, $sender->nickname); | ||
| 664 | |||
| 663 | 665 | common_init_locale(); | |
| 664 | mail_to_user($user, $subject, $body); | ||
| 666 | mail_to_user($user, $subject, $body, $headers); | ||
| 667 | } | ||
| 668 | |||
| 669 | /** | ||
| 670 | * Prepare the common mail headers used in notification emails | ||
| 671 | * | ||
| 672 | * @param string $msg_type type of message being sent to the user | ||
| 673 | * @param string $to nickname of the receipient | ||
| 674 | * @param string $from nickname of the user triggering the notification | ||
| 675 | * | ||
| 676 | * @return array list of mail headers to include in the message | ||
| 677 | */ | ||
| 678 | function _mail_prepare_headers($msg_type, $to, $from) | ||
| 679 | { | ||
| 680 | $headers = array( | ||
| 681 | 'X-StatusNet-MessageType' => $msg_type, | ||
| 682 | 'X-StatusNet-TargetUser' => $to, | ||
| 683 | 'X-StatusNet-SourceUser' => $from, | ||
| 684 | 'X-StatusNet-Domain' => common_config('site', 'server') | ||
| 685 | ); | ||
| 686 | |||
| 687 | return $headers; | ||
| 665 | 688 | } |

