Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/phpmailer/moodle_phpmailer.php
Go to the documentation of this file.
00001 <?php
00002 
00029 // PLEASE NOTE: we use the phpmailer class _unmodified_
00030 // through the joys of OO. Distros are free to use their stock
00031 // version of this file.
00032 require_once($CFG->libdir.'/phpmailer/class.phpmailer.php');
00033 
00045 class moodle_phpmailer extends PHPMailer {
00046 
00051     public function __construct(){
00052         global $CFG;
00053         $this->Version   = 'Moodle '.$CFG->version;         // mailer version
00054         $this->PluginDir = $CFG->libdir.'/phpmailer/';      // plugin directory (eg smtp plugin)
00055         $this->CharSet   = 'UTF-8';
00056     }
00057 
00063     public function AddCustomHeader($custom_header) {
00064         if(preg_match('/message-id:(.*)/i', $custom_header, $matches)){
00065             $this->MessageID = $matches[1];
00066             return true;
00067         }else{
00068             return parent::AddCustomHeader($custom_header);
00069         }
00070     }
00071 
00076     public function EncodeHeader ($str, $position = 'text') {
00077         $textlib = textlib_get_instance();
00078         $encoded = $textlib->encode_mimeheader($str, $this->CharSet);
00079         if ($encoded !== false) {
00080             $encoded = str_replace("\n", $this->LE, $encoded);
00081             if ($position == 'phrase') {
00082                 return ("\"$encoded\"");
00083             }
00084             return $encoded;
00085         }
00086 
00087         return parent::EncodeHeader($str, $position);
00088     }
00089 
00094     public static function RFCDate() {
00095         $tz = date('Z');
00096         $tzs = ($tz < 0) ? '-' : '+';
00097         $tz = abs($tz);
00098         $tz = (($tz - ($tz%3600) )/3600)*100 + ($tz%3600)/60; // fixed tz bug
00099         $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
00100 
00101         return $result;
00102     }
00103 
00110     public function EncodeQP($string, $line_max = 76, $space_conv = false) {
00111         //if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
00112         //    return quoted_printable_encode($string);
00113         //}
00114         $filters = stream_get_filters();
00115         if (!in_array('convert.*', $filters)) { //Got convert stream filter?
00116             return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation
00117         }
00118         $fp = fopen('php://temp/', 'r+');
00119         $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks
00120         $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
00121         $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
00122         fputs($fp, $string);
00123         rewind($fp);
00124         $out = stream_get_contents($fp);
00125         stream_filter_remove($s);
00126         $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange
00127         fclose($fp);
00128         return $out;
00129     }
00130 }
 All Data Structures Namespaces Files Functions Variables Enumerations