Page MenuHomePhabricator
Paste P629

Masterwork From Distant Lands
ActivePublic

Authored by epriestley on Dec 20 2012, 12:37 AM.
Tags
None
Referenced Files
F28024: Masterwork_From_Distant_Lands
Feb 24 2016, 1:31 AM
Subscribers
None
commit b13bd2db29ec40532887fdaf037668e84976831d
Author: epriestley <git@epriestley.com>
Date: Wed Dec 19 16:39:17 2012 -0800
Fix EncodeQ implementation in PHPMailer
Summary: See https://github.com/facebook/phabricator/commit/f5c2a2ab4bbe6317993fbcb406a86993e6ab75e0#commitcomment-2333247
Copy of working implementation from PHPMailerLite.
Test Plan:
Reviewers:
CC:
Maniphest Tasks:
diff --git a/externals/phpmailer/class.phpmailer.php b/externals/phpmailer/class.phpmailer.php
index 56007cd..0c62ddb 100644
--- a/externals/phpmailer/class.phpmailer.php
+++ b/externals/phpmailer/class.phpmailer.php
@@ -1711,6 +1711,13 @@ class PHPMailer {
}
/**
+ * NOTE: Phabricator patch to remove use of "/e". See D2147.
+ */
+ private function encodeQCallback(array $matches) {
+ return '='.sprintf('%02X', ord($matches[1]));
+ }
+
+ /**
* Encode string to q encoding.
* @link http://tools.ietf.org/html/rfc2047
* @param string $str the text to encode
@@ -1719,21 +1726,32 @@ class PHPMailer {
* @return string
*/
public function EncodeQ ($str, $position = 'text') {
+
+ // NOTE: Phabricator patch to remove use of "/e". See D2147.
+
// There should not be any EOL in the string
$encoded = preg_replace('/[\r\n]*/', '', $str);
switch (strtolower($position)) {
case 'phrase':
- $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/", "'='.sprintf('%02X', ord('\\1'))", $encoded);
+ $encoded = preg_replace_callback(
+ "/([^A-Za-z0-9!*+\/ -])/",
+ array($this, 'encodeQCallback'),
+ $encoded);
break;
case 'comment':
- $encoded = preg_replace("/([\(\)\"])/", "'='.sprintf('%02X', ord('\\1'))", $encoded);
+ $encoded = preg_replace_callback(
+ "/([\(\)\"])/",
+ array($this, 'encodeQCallback'),
+ $encoded);
+ break;
case 'text':
default:
// Replace every high ascii, control =, ? and _ characters
- //TODO using /e (equivalent to eval()) is probably not a good idea
- $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/',
- "'='.sprintf('%02X', ord('\\1'))", $encoded);
+ $encoded = preg_replace_callback(
+ '/([\000-\011\013\014\016-\037\075\077\137\177-\377])/',
+ array($this, 'encodeQCallback'),
+ $encoded);
break;
}

Event Timeline