Skip to content

Commit eeb97db

Browse files
author
epriestley
committed
Fix EncodeQ implementation in PHPMailer, and provide SSL/TLS options
Summary: See phacility@f5c2a2a#commitcomment-2333247 Copy of working implementation from PHPMailerLite. Also expose the SSL/TLS options. Test Plan: Switched to this mailer, configured Gmail SMTP, sent email. Verified email arrived intact. Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran, mbeck Differential Revision: https://secure.phabricator.com/D4239
1 parent 5311500 commit eeb97db

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

conf/default.conf.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,12 @@
291291
// mostly never arrive.
292292
'metamta.can-send-as-user' => false,
293293

294-
295294
// Adapter class to use to transmit mail to the MTA. The default uses
296295
// PHPMailerLite, which will invoke "sendmail". This is appropriate
297296
// if sendmail actually works on your host, but if you haven't configured mail
298-
// it may not be so great. You can also use Amazon SES, by changing this to
299-
// 'PhabricatorMailImplementationAmazonSESAdapter', signing up for SES, and
300-
// filling in your 'amazon-ses.access-key' and 'amazon-ses.secret-key' below.
297+
// it may not be so great. A number of other mailers are available (e.g., SES,
298+
// SendGrid, SMTP, custom mailers), consult "Configuring Outbound Email" in
299+
// the documentation for details.
301300
'metamta.mail-adapter' =>
302301
'PhabricatorMailImplementationPHPMailerLiteAdapter',
303302

@@ -317,12 +316,18 @@
317316
'metamta.user-address-format' => 'full',
318317

319318
// If you're using PHPMailer to send email, provide the mailer and options
320-
// here. PHPMailer is a superior to PHPMailerLite and provides more mailers.
321-
// You need it when you want to use SMTP instead of sendmail as the mailer.
319+
// here. PHPMailer is much more enormous than PHPMailerLite, and provides more
320+
// mailers and greater enormity. You need it when you want to use SMTP
321+
// instead of sendmail as the mailer.
322322
'phpmailer.mailer' => 'smtp',
323323
'phpmailer.smtp-host' => '',
324324
'phpmailer.smtp-port' => 25,
325325

326+
// When using PHPMailer with SMTP, you can set this to one of "tls" or "ssl"
327+
// to use TLS or SSL. Leave it blank for vanilla SMTP. If you're sending
328+
// via Gmail, set it to "ssl".
329+
'phpmailer.smtp-protocol' => '',
330+
326331
// Set following if your smtp server requires authentication.
327332
'phpmailer.smtp-user' => null,
328333
'phpmailer.smtp-password' => null,

externals/phpmailer/class.phpmailer.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,13 @@ public function EncodeQP($string, $line_max = 76, $space_conv = false) {
17101710
return $out;
17111711
}
17121712

1713+
/**
1714+
* NOTE: Phabricator patch to remove use of "/e". See D2147.
1715+
*/
1716+
private function encodeQCallback(array $matches) {
1717+
return '='.sprintf('%02X', ord($matches[1]));
1718+
}
1719+
17131720
/**
17141721
* Encode string to q encoding.
17151722
* @link http://tools.ietf.org/html/rfc2047
@@ -1719,21 +1726,32 @@ public function EncodeQP($string, $line_max = 76, $space_conv = false) {
17191726
* @return string
17201727
*/
17211728
public function EncodeQ ($str, $position = 'text') {
1729+
1730+
// NOTE: Phabricator patch to remove use of "/e". See D2147.
1731+
17221732
// There should not be any EOL in the string
17231733
$encoded = preg_replace('/[\r\n]*/', '', $str);
17241734

17251735
switch (strtolower($position)) {
17261736
case 'phrase':
1727-
$encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1737+
$encoded = preg_replace_callback(
1738+
"/([^A-Za-z0-9!*+\/ -])/",
1739+
array($this, 'encodeQCallback'),
1740+
$encoded);
17281741
break;
17291742
case 'comment':
1730-
$encoded = preg_replace("/([\(\)\"])/", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1743+
$encoded = preg_replace_callback(
1744+
"/([\(\)\"])/",
1745+
array($this, 'encodeQCallback'),
1746+
$encoded);
1747+
break;
17311748
case 'text':
17321749
default:
17331750
// Replace every high ascii, control =, ? and _ characters
1734-
//TODO using /e (equivalent to eval()) is probably not a good idea
1735-
$encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/',
1736-
"'='.sprintf('%02X', ord('\\1'))", $encoded);
1751+
$encoded = preg_replace_callback(
1752+
'/([\000-\011\013\014\016-\037\075\077\137\177-\377])/',
1753+
array($this, 'encodeQCallback'),
1754+
$encoded);
17371755
break;
17381756
}
17391757

src/applications/metamta/adapter/PhabricatorMailImplementationPHPMailerAdapter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public function __construct() {
3030
$this->mailer->Password =
3131
PhabricatorEnv::getEnvConfig('phpmailer.smtp-password');
3232
}
33+
34+
$protocol = PhabricatorEnv::getEnvConfig('phpmailer.smtp-protocol');
35+
if ($protocol) {
36+
$this->mailer->SMTPSecure = $protocol;
37+
}
3338
} else if ($mailer == 'sendmail') {
3439
$this->mailer->IsSendmail();
3540
} else {

0 commit comments

Comments
 (0)