From: Tim Düsterhus Date: Mon, 15 Jun 2015 15:03:25 +0000 (+0200) Subject: Move header encoding from Mailbox into a generic function X-Git-Tag: 3.0.0_Beta_1~2249^2~2^2~10 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f70ac99f4945ae3224cfbf88e18a10f6516baa2c;p=GitHub%2FWoltLab%2FWCF.git Move header encoding from Mailbox into a generic function --- diff --git a/wcfsetup/install/files/lib/system/email/EmailGrammar.class.php b/wcfsetup/install/files/lib/system/email/EmailGrammar.class.php index 049153de38..b185df430b 100644 --- a/wcfsetup/install/files/lib/system/email/EmailGrammar.class.php +++ b/wcfsetup/install/files/lib/system/email/EmailGrammar.class.php @@ -83,9 +83,30 @@ final class EmailGrammar { * @param string $header Header to encode * @return string Encoded header */ - public static function encodeMimeHeader($header) { + public static function encodeQuotedPrintableHeader($header) { return mb_encode_mimeheader($header, "UTF-8", "Q", "\r\n"); } + /** + * Return text either unmodified, if it matches the 'atom' grammar, + * in double quotes or encoded in quoted printable. Depending on which + * encoding is necessary. + * + * @param string $header Header to encode + * @return string Encoded header + */ + public static function encodeHeader($header) { + if (!preg_match('(^'.self::getGrammar('atom').'$)', $header)) { + if (($encoded = self::encodeQuotedPrintableHeader($header)) === $header) { + $header = '"'.addcslashes($header, '\\"').'"'; + } + else { + $header = $encoded; + } + } + + return $header; + } + private function __construct() { } } diff --git a/wcfsetup/install/files/lib/system/email/Mailbox.class.php b/wcfsetup/install/files/lib/system/email/Mailbox.class.php index 8205c1e041..f94858e4e5 100644 --- a/wcfsetup/install/files/lib/system/email/Mailbox.class.php +++ b/wcfsetup/install/files/lib/system/email/Mailbox.class.php @@ -68,16 +68,7 @@ class Mailbox { return $this->address; } - $name = $this->name; - if (!preg_match('(^'.EmailGrammar::getGrammar('atom').'$)', $name)) { - if (($encoded = EmailGrammar::encodeMimeHeader($name)) === $name) { - $name = '"'.addcslashes($name, '\\"').'"'; - } - else { - $name = $encoded; - } - } - + $name = EmailGrammar::encodeHeader($this->name); return $name.' <'.$this->address.'>'; } }