Browse files

message MDL-26185 fixed the logic around email addy in user profile V…

…s in messaging preferences
  • Loading branch information...
1 parent 6b14adf commit d3a8184239d351db05e07c22c237698c34308b04 @andyjdavis andyjdavis committed Apr 7, 2011
Showing with 11 additions and 13 deletions.
  1. +11 −13 message/output/email/message_output_email.php
View
24 message/output/email/message_output_email.php
@@ -46,21 +46,19 @@ function send_message($eventdata) {
return true;
}
- //hold onto email preference because /admin/cron.php sends a lot of messages at once
- static $useremailaddresses = array();
+ //the user the email is going to
+ $recipient = null;
- //check user preference for where user wants email sent
- if (!array_key_exists($eventdata->userto->id, $useremailaddresses)) {
- $useremailaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_email_email', $eventdata->userto->email, $eventdata->userto->id);
+ //check if the recipient has a different email address specified in their messaging preferences Vs their user profile
+ $emailmessagingpreference = get_user_preferences('message_processor_email_email', null, $eventdata->userto);
+ if (!empty($emailmessagingpreference)) {
+ //clone to avoid altering the actual user object
+ $recipient = clone($eventdata->userto);
+ $recipient->email = $emailmessagingpreference;
+ } else {
+ $recipient = $eventdata->userto;
}
- $usertoemailaddress = $useremailaddresses[$eventdata->userto->id];
-
- if ( !empty($usertoemailaddress)) {
- $userto->email = $usertoemailaddress;
- }
-
- $result = email_to_user($eventdata->userto, $eventdata->userfrom,
- $eventdata->subject, $eventdata->fullmessage, $eventdata->fullmessagehtml);
+ $result = email_to_user($recipient, $eventdata->userfrom, $eventdata->subject, $eventdata->fullmessage, $eventdata->fullmessagehtml);
return $result;
}

0 comments on commit d3a8184

Please sign in to comment.