/** * Use internal moodles own core_text to encode mimeheaders. * Fall back to phpmailers inbuilt functions if not */ public function encodeHeader($str, $position = 'text') { $encoded = core_text::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); }
/** * Use internal moodles own core_text to encode mimeheaders. * Fall back to phpmailers inbuilt functions if not */ public function encodeHeader($str, $position = 'text') { $encoded = core_text::encode_mimeheader($str, $this->CharSet); if ($encoded !== false) { if ($position === 'phrase') { // Escape special symbols in each line in the encoded string, join back together and enclose in quotes. $chunks = preg_split("/\\n/", $encoded); $chunks = array_map(function ($chunk) { return addcslashes($chunk, "..\\\""); }, $chunks); return '"' . join($this->LE, $chunks) . '"'; } return str_replace("\n", $this->LE, $encoded); } return parent::encodeHeader($str, $position); }