From b212c114cea735ca6a6b8f2a6caf29927c858bcd Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sat, 18 Mar 2006 17:48:52 +0000 Subject: [PATCH] First cut of email working with any encoding. Works practically ok but 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 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 5a6b476f18..0042e3bf30 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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; -- 2.39.5