Messaging: Message default email settings patch

Messaging: Message default email settings patch

by Michael Penney -
Number of replies: 5

Problem:

Message defaults are drawn from mdl_user_preferences, however they don't exist there until a user saves changes. Messages are supposed to be emailed by default when users are offline, however the code actually looks for the setting in mdl_usr_preferences, and then defaults to not sending messages until this preference is created.

Also, messaging creates an entry for the users email address in the mdl_user_preferences table, and only after the settings are saved. This creates the situation where users may have one email in mdl_user and another in mdl_user_preferences.

This is a significant problem as users expect messages to be emailed by default, as that is what the default settings in the settings form are set to do (email by default and to the users's email address as set in mdl_user), however these settings don't actually get created and used until the user clicks 'save changes' in the message settings form.

We attached a patch for lib.php fixes the problem by default to sending messages, and using the email settings in mdl_user to initial bug report for message email problems: .

I asked Mark Nielson to fix this, see below.

I put a patch in the bug tracker for bug 4639. This fixes the problem with messages not being emailed by default, and gets the email address from mdl_user.

Around line 990:
    // Bug 4639 Fix Here
    if (!isset($preference->message_emailmessages) or $preference->message_emailmessages) {  // Receiver wants mail forwarding
        // Bug 4639 Fix Here
        if (!isset($preference->message_emailtimenosee)) {
            $preference->message_emailtimenosee = 10;
        }
        if ((time() - $userto->lastaccess) > ((int)$preference->message_emailtimenosee * 60)) { // Long enough

            $message = stripslashes_safe($message);
            $tagline = get_string('emailtagline', 'message', $SITE->shortname);
           
            $messagesubject = message_shorten_message(strip_tags($message), 30).'...';

            $messagetext = format_text_email($message, $format).
                           "\n\n--\n".$tagline."\n"."$CFG->wwwroot/message/index.php?popup=1";

            if (isset($preference->message_emailformat) and $preference->message_emailformat == FORMAT_HTML) {
                $messagehtml  = format_text($message, $format);
                $messagehtml .= '<hr /><p><a href="'.$CFG->wwwroot.'/message/index.php?popup=1">'.$tagline.'</a></p>';
            } else {
                $messagehtml = NULL;
            }
           
            // Bug 4639 Fix Here
            if (!empty($preference->message_emailaddress)) {
                $userto->email = $preference->message_emailaddress;   // Use custom messaging address
            }
            email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml);
        }
    }

Average of ratings: -
In reply to Michael Penney

Re: Messaging: Message default email settings patch

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Good catch, thanks!   Fixed in CVS and next releases.
In reply to Martin Dougiamas

Message system does not get email from user profile in 1.6 ?

by Stephen Digby -

This bug doesn't seem to have been fixed in 1.6 ....

unless the message hack (white/ grey/ black lists) has the bug within it ??

Shall I apply the hack above to message "white/ grey/ black lists" hack ?

 

In reply to Stephen Digby

Re: Message system does not get email from user profile in 1.6 ?

by David Brighton -
This bug still seems to be included in version 1.6.1 (without message hack), certainly allows a user to have a different email address in the user preferences table to the user table record. Did this really make it into the release or is this a new incarnation of the bug?
In reply to David Brighton

Re: Message system does not get email from user profile in 1.6 ?

by David Jackson -
1.7+ also allows a different email address to be stored in user_preferences
In reply to Michael Penney

Re: Messaging: Message default email settings patch

by Ray Fallon -

As a new Moodle adopter(effective 9/1/08),(our site: moodle.ramapo.edu) , I believe we are using Moodle 1.9 and it appears as though we are experiencing this as a problem.  As admininstrator, I am looking for a setting to change to allow the forwarding (to our e-mail system) of a Moodle message to a user who is offline.  And then this creates the assumption that if a user is online when a message is sent, it will only appear in the Moodle message.

I am hoping that it is not as complicated as changing  the coding as described in this solution

Thanks

Ray Fallon