X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplmailer.php;h=317dd64f05749e93ccf3561b8c0926ef123bdc5a;hb=36f58fcfd9fa0f3660a727effcdc47a6ff4eebf6;hp=58e6997c2c89c4d0cc02d5f1e781a1958bf6b597;hpb=5bc6e9e64bbc884c4878b56d3e5cb7b514e66920;p=platal.git diff --git a/classes/plmailer.php b/classes/plmailer.php index 58e6997..317dd64 100644 --- a/classes/plmailer.php +++ b/classes/plmailer.php @@ -1,6 +1,6 @@ tpl = $tpl; - $this->mailer =& $mailer; $this->caching = false; $this->compile_check = true; $this->template_dir = $globals->spoolroot . "/templates/"; - $this->compile_dir = $globals->spoolroot . "/spool/templates_c/"; + $this->compile_dir = $globals->spoolroot . "/spool/mails_c/"; $this->config_dir = $globals->spoolroot . "/configs/"; + $this->register_outputfilter(Array($this, 'mail_format')); $this->register_function('from', Array($this, 'setFrom')); @@ -51,10 +49,21 @@ class PlMail extends Smarty $this->register_function('add_header', Array($this, 'addHeader')); } + public static function &get(&$mailer, $tpl) + { + static $plmail; + if (!isset($plmail) || $plmail->tpl != $tpl) { + $plmail = new PlMail($tpl); + } + $plmail->mailer =& $mailer; + return $plmail; + } + public function run($html) { $this->assign('html_version', $html); - return $this->fetch($this->tpl); + $text = $this->fetch($this->tpl); + return $text; } /** used to remove the empty lines due to {from ...}, {to ...} ... functions */ @@ -139,13 +148,13 @@ class PlMailer extends Mail_Mime { private $page = null; private $charset; - function __construct($tpl = null, $charset = "ISO-8859-15") + function __construct($tpl = null, $charset = "UTF-8") { $this->charset = $charset; $this->Mail_Mime("\n"); - $this->mail = @Mail::factory('sendmail', Array('sendmail_args' => '-oi')); + $this->mail = Mail::factory('sendmail', Array('sendmail_args' => '-oi')); if (!is_null($tpl)) { - $this->page = new PlMail($this, $tpl); + $this->page =& PlMail::get($this, $tpl); } } @@ -154,7 +163,7 @@ class PlMailer extends Mail_Mime { */ private function correct_emails($email) { - return preg_replace('!(^|, *)([^<"]+?) *(<[^>]*>)!', '\1"\2" \3', $email); + return preg_replace('!(^|, *)([^<"]+?) *(<[^>]*>)!u', '\1"\2" \3', $email); } public function addTo($email) @@ -239,6 +248,7 @@ class PlMailer extends Mail_Mime { private function processPage($with_html = true) { + $level = error_reporting(0); if (!is_null($this->page)) { $this->setTxtBody($this->page->run(false)); if ($with_html) { @@ -248,19 +258,24 @@ class PlMailer extends Mail_Mime { } } } + error_reporting($level); } public function send($with_html = true) { $this->processPage($with_html); if (S::v('forlife')) { - $this->addHeader('X-Org-Mail', S::v('forlife') . '@polytechnique.org'); + global $globals; + $this->addHeader('X-Org-Mail', S::v('forlife') . '@' . $globals->mail->domain); } $addrs = Array(); foreach(Array('To', 'Cc', 'Bcc') as $hdr) { if(isset($this->_headers[$hdr])) { require_once 'Mail/RFC822.php'; - $addrs = array_merge($addrs, @Mail_RFC822::parseAddressList($this->_headers[$hdr])); + $parsed = @Mail_RFC822::parseAddressList($this->_headers[$hdr]); + if (is_array($parsed)) { + $addrs = array_merge($addrs, $parsed); + } } } if(empty($addrs)) { @@ -285,4 +300,5 @@ class PlMailer extends Mail_Mime { } } +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>