General help

 
 
Picture of Michael Penney
Messaging: Message default email settings patch
Group Developers

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: -
Martin in black and white
Re: Messaging: Message default email settings patch
Group DevelopersGroup Documentation writersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers
Good catch, thanks!   Fixed in CVS and next releases.
 
Average of ratings: -
Picture of Stephen Digby
Message system does not get email from user profile in 1.6 ?
 

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 ?

 

 
Average of ratings: -
Picture of David Brighton
Re: Message system does not get email from user profile in 1.6 ?
 
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?
 
Average of ratings: -
Garrrr
Re: Message system does not get email from user profile in 1.6 ?
 
1.7+ also allows a different email address to be stored in user_preferences
 
Average of ratings: -
Picture of Ray Fallon
Re: Messaging: Message default email settings patch
 

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

 
Average of ratings: -