]> git.mjollnir.org Git - moodle.git/commitdiff
First cut of email working with any encoding. Works practically ok but
authorstronk7 <stronk7>
Sat, 18 Mar 2006 17:48:52 +0000 (17:48 +0000)
committerstronk7 <stronk7>
Sat, 18 Mar 2006 17:48:52 +0000 (17:48 +0000)
I've to check something that seems to be a bug in the build of the
subject. Sendind it to CVS to check the code under Win32 and Linux.

lib/moodlelib.php

index 5a6b476f188e6029f004a7bcaed92364f47b15b6..0042e3bf30021b23286b37d0e237d42b91ed8d6e 100644 (file)
@@ -3732,6 +3732,9 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
 
     include_once($CFG->libdir .'/phpmailer/class.phpmailer.php');
 
+/// We are going to use textlib services here
+    $textlib = textlib_get_instance();
+
     if (empty($user)) {
         return false;
     }
@@ -3843,6 +3846,37 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
         }
     }
 
+
+
+/// If we are running under Unicode and sitemailcharset or allowusermailcharset are set, convert the email
+/// encoding to the specified one
+    if ($CFG->unicodedb && (!empty($CFG->sitemailcharset) || !empty($CFG->allowusermailcharset))) {
+    /// Set it to site mail charset
+        $charset = $CFG->sitemailcharset;
+    /// Overwrite it with the user mail charset
+        if (!empty($CFG->allowusermailcharset)) {
+            if ($useremailcharset = get_user_preferences('mailcharset', '0', $user->id)) {
+                $charset = $useremailcharset;
+            }
+        }
+    /// If it has changed, convert all the necessary strings
+        if ($mail->CharSet != $charset) {
+        /// Save the new mail charset
+            $mail->CharSet = $charset;
+        /// And convert some strings
+            $mail->FromName = $textlib->convert($mail->FromName, 'utf-8', $mail->CharSet); //From Name
+            foreach ($mail->ReplyTo as $key => $rt) {                                      //ReplyTo Names
+                $mail->ReplyTo[$key][1] = $textlib->convert($rt, 'utf-8', $mail->CharSet);
+            }
+            $mail->Subject = $textlib->convert($mail->Subject, 'utf-8', $mail->CharSet);   //Subject
+            foreach ($mail->to as $key => $to) {
+                $mail->to[$key][1] = $textlib->convert($to, 'utf-8', $mail->CharSet);      //To Names
+            }
+            $mail->Body = $textlib->convert($mail->Body, 'utf-8', $mail->CharSet);         //Body
+            $mail->AltBody = $textlib->convert($mail->AltBody, 'utf-8', $mail->CharSet);   //Subject
+        }
+    }
+
     if ($mail->Send()) {
         set_send_count($user);
         return true;