diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 79e1a76..f9f4b6e 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4061,8 +4061,8 @@ function &get_mailer($action='get') { get_mailer('flush'); } - include_once($CFG->libdir.'/phpmailer/class.phpmailer.php'); - $mailer = new phpmailer(); + include_once($CFG->libdir.'/phpmailer/moodle_phpmailer.php'); + $mailer = new moodle_phpmailer(); $counter = 1; diff --git a/lib/phpmailer/moodle_phpmailer.php b/lib/phpmailer/moodle_phpmailer.php new file mode 100644 index 0000000..3617bb2 --- /dev/null +++ b/lib/phpmailer/moodle_phpmailer.php @@ -0,0 +1,61 @@ +libdir.'/phpmailer/class.phpmailer.php'); + +class moodle_phpmailer extends PHPMailer { + + /** + * Set Moodle Defaults + */ + public function __construct(){ + global $CFG; + $this->Version = 'Moodle '.$CFG->version; // mailer version + $this->PluginDir = $CFG->libdir.'/phpmailer/'; // plugin directory (eg smtp plugin) + $this->CharSet = 'UTF-8'; + } + + /** + * Extended AddCustomHeader function in order to stop duplicate + * message-ids + * http://tracker.moodle.org/browse/MDL-3681 + */ + public function AddCustomHeader($custom_header) { + if(preg_match('/message-id:(.*)/i', $custom_header, $matches)){ + $this->MessageID = $matches[1]; + return true; + }else{ + return parent::AddCustomHeader($custom_header); + } + } + + /** + * Use internal moodles own textlib to encode mimeheaders + */ + public function EncodeHeader ($str, $position = 'text') { + $textlib = textlib_get_instance(); + $encoded = $textlib->encode_mimeheader($str, $this->CharSet); + if ($encoded !== false) { + $encoded = str_replace("\n", $this->LE, $encoded); + if ($position == 'phrase') { + return ("\"$encoded\""); + } + return $encoded; + } + + return parent::EncodeHeader($str, $position); + } + + /** + * Replaced function to fix tz bug: + * http://tracker.moodle.org/browse/MDL-12596 + */ + private static function RFCDate() { + $tz = date('Z'); + $tzs = ($tz < 0) ? '-' : '+'; + $tz = abs($tz); + $tz = (($tz - ($tz%3600) )/3600)*100 + ($tz%3600)/60; // fixed tz bug + $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); + + return $result; + } +}