Skip to content

Commit

Permalink
message MDL-23101 made email notifications of forum posts work
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Davis committed Jul 6, 2010
1 parent ac90abb commit 6d2e693
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
9 changes: 7 additions & 2 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4520,16 +4520,19 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
static $mnetjumps = array();

if (empty($user) || empty($user->email)) {
mtrace('Error: lib/moodlelib.php email_to_user(): User is null or has no email');
return false;
}

if (!empty($user->deleted)) {
// do not mail delted users
mtrace('Error: lib/moodlelib.php email_to_user(): User is deleted');
return false;
}

if (!empty($CFG->noemailever)) {
// hidden setting for development sites, set in config.php if needed
mtrace('Error: lib/moodlelib.php email_to_user(): Not sending email due to noemailever config setting');
return true;
}

Expand All @@ -4549,7 +4552,9 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
}

if (over_bounce_threshold($user)) {
error_log("User $user->id (".fullname($user).") is over bounce threshold! Not sending.");
$bouncemsg = "User $user->id (".fullname($user).") is over bounce threshold! Not sending.";
error_log($bouncemsg);
mtrace('Error: lib/moodlelib.php email_to_user(): '.$bouncemsg);
return false;
}

Expand Down Expand Up @@ -4626,7 +4631,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
$mail->Priority = $from->priority;
}

if ($messagehtml && $user->mailformat == 1) { // Don't ever send HTML to users who don't want it
if ($messagehtml && !empty($user->mailformat) && $user->mailformat == 1) { // Don't ever send HTML to users who don't want it
$mail->IsHTML(true);
$mail->Encoding = 'quoted-printable'; // Encoding to use
$mail->Body = $messagehtml;
Expand Down
19 changes: 9 additions & 10 deletions message/output/email/message_output_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ class message_output_email extends message_output {
function send_message($message) {
global $DB;

//send an email
//if fails saved as read message
$userto = $DB->get_record('user', array('id' => $message->useridto));
$userfrom = $DB->get_record('user', array('id' => $message->useridfrom));

//check user preference for where user wants email sent
$usertoemailaddress = get_user_preferences('message_processor_email_email', '', $message->useridto);

//first try to get preference
$usertoemail = get_user_preferences( 'message_processor_email_email', '', $message->useridto);
//if fails use user profile default
if ( $usertoemail == NULL){
$userto = $DB->get_record('user', array('id' => $message->useridto));
$usertoemail = $userto->email;
if ( !empty($usertoemailaddress)) {
$userto->email = $usertoemailaddress;
}
$userfrom = $DB->get_record('user', array('id' => $message->useridfrom));
$result = email_to_user($usertoemail, $userfrom->email,

$result = email_to_user($userto, $userfrom,
$message->subject, $message->fullmessage,
$message->fullmessagehtml);

Expand Down
2 changes: 1 addition & 1 deletion mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ function forum_cron() {
}
$posthtml .= '</body>';

if ($userto->mailformat != 1) {
if (empty($userto->mailformat) || $userto->mailformat != 1) {
// This user DOESN'T want to receive HTML
$posthtml = '';
}
Expand Down

0 comments on commit 6d2e693

Please sign in to comment.