From 6226cc30fb688a271cb7479b897f01353623da1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Mon, 23 Sep 2013 10:11:27 +0200 Subject: [PATCH] MDL-37324 fix phpmailer method case names and standardise phpmailer init --- lib/moodlelib.php | 48 +++++++++++------------------- lib/phpmailer/moodle_phpmailer.php | 7 +++++ 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 92091ea16dfc2..f9296c9f30893 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5421,6 +5421,7 @@ function moodle_process_email($modargs, $body) { function get_mailer($action='get') { global $CFG; + /** @var moodle_phpmailer $mailer */ static $mailer = null; static $counter = 0; @@ -5432,7 +5433,7 @@ function get_mailer($action='get') { $prevkeepalive = false; if (isset($mailer) and $mailer->Mailer == 'smtp') { - if ($counter < $CFG->smtpmaxbulk and !$mailer->IsError()) { + if ($counter < $CFG->smtpmaxbulk and !$mailer->isError()) { $counter++; // Reset the mailer. $mailer->Priority = 3; @@ -5447,10 +5448,10 @@ function get_mailer($action='get') { $mailer->AltBody = ""; $mailer->ConfirmReadingTo = ""; - $mailer->ClearAllRecipients(); - $mailer->ClearReplyTos(); - $mailer->ClearAttachments(); - $mailer->ClearCustomHeaders(); + $mailer->clearAllRecipients(); + $mailer->clearReplyTos(); + $mailer->clearAttachments(); + $mailer->clearCustomHeaders(); return $mailer; } @@ -5458,35 +5459,22 @@ function get_mailer($action='get') { get_mailer('flush'); } - include_once($CFG->libdir.'/phpmailer/moodle_phpmailer.php'); + require_once($CFG->libdir.'/phpmailer/moodle_phpmailer.php'); $mailer = new moodle_phpmailer(); $counter = 1; - // Mailer version. - $mailer->Version = 'Moodle '.$CFG->version; - // Plugin directory (eg smtp plugin). - $mailer->PluginDir = $CFG->libdir.'/phpmailer/'; - $mailer->CharSet = 'UTF-8'; - - // Some MTAs may do double conversion of LF if CRLF used, CRLF is required line ending in RFC 822bis. - if (isset($CFG->mailnewline) and $CFG->mailnewline == 'CRLF') { - $mailer->LE = "\r\n"; - } else { - $mailer->LE = "\n"; - } - if ($CFG->smtphosts == 'qmail') { // Use Qmail system. - $mailer->IsQmail(); + $mailer->isQmail(); } else if (empty($CFG->smtphosts)) { // Use PHP mail() = sendmail. - $mailer->IsMail(); + $mailer->isMail(); } else { // Use SMTP directly. - $mailer->IsSMTP(); + $mailer->isSMTP(); if (!empty($CFG->debugsmtp)) { $mailer->SMTPDebug = true; } @@ -5692,10 +5680,10 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '', // Add custom headers. if (is_array($from->customheaders)) { foreach ($from->customheaders as $customheader) { - $mail->AddCustomHeader($customheader); + $mail->addCustomHeader($customheader); } } else { - $mail->AddCustomHeader($from->customheaders); + $mail->addCustomHeader($from->customheaders); } } @@ -5705,7 +5693,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '', if ($messagehtml && !empty($user->mailformat) && $user->mailformat == 1) { // Don't ever send HTML to users who don't want it. - $mail->IsHTML(true); + $mail->isHTML(true); $mail->Encoding = 'quoted-printable'; $mail->Body = $messagehtml; $mail->AltBody = "\n$messagetext\n"; @@ -5718,11 +5706,11 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '', if (preg_match( "~\\.\\.~" , $attachment )) { // Security check for ".." in dir path. $temprecipients[] = array($supportuser->email, fullname($supportuser, true)); - $mail->AddStringAttachment('Error in attachment. User attempted to attach a filename with a unsafe name.', 'error.txt', '8bit', 'text/plain'); + $mail->addStringAttachment('Error in attachment. User attempted to attach a filename with a unsafe name.', 'error.txt', '8bit', 'text/plain'); } else { require_once($CFG->libdir.'/filelib.php'); $mimetype = mimeinfo('type', $attachname); - $mail->AddAttachment($CFG->dataroot .'/'. $attachment, $attachname, 'base64', $mimetype); + $mail->addAttachment($CFG->dataroot .'/'. $attachment, $attachname, 'base64', $mimetype); } } @@ -5757,13 +5745,13 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '', } foreach ($temprecipients as $values) { - $mail->AddAddress($values[0], $values[1]); + $mail->addAddress($values[0], $values[1]); } foreach ($tempreplyto as $values) { - $mail->AddReplyTo($values[0], $values[1]); + $mail->addReplyTo($values[0], $values[1]); } - if ($mail->Send()) { + if ($mail->send()) { set_send_count($user); if (!empty($mail->SMTPDebug)) { echo ''; diff --git a/lib/phpmailer/moodle_phpmailer.php b/lib/phpmailer/moodle_phpmailer.php index 9bff57ca731e1..3e0e258912a96 100644 --- a/lib/phpmailer/moodle_phpmailer.php +++ b/lib/phpmailer/moodle_phpmailer.php @@ -52,6 +52,13 @@ public function __construct(){ global $CFG; $this->Version = 'Moodle '.$CFG->version; // mailer version $this->CharSet = 'UTF-8'; + + // Some MTAs may do double conversion of LF if CRLF used, CRLF is required line ending in RFC 822bis. + if (isset($CFG->mailnewline) and $CFG->mailnewline == 'CRLF') { + $this->LE = "\r\n"; + } else { + $this->LE = "\n"; + } } /**