1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Fix EncodeQ implementation in PHPMailer, and provide SSL/TLS options

Summary:
See f5c2a2ab4b (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
This commit is contained in:
epriestley 2012-12-20 11:11:15 -08:00
parent 53115007ff
commit eeb97db283
3 changed files with 39 additions and 11 deletions

View file

@ -291,13 +291,12 @@ return array(
// mostly never arrive. // mostly never arrive.
'metamta.can-send-as-user' => false, 'metamta.can-send-as-user' => false,
// Adapter class to use to transmit mail to the MTA. The default uses // Adapter class to use to transmit mail to the MTA. The default uses
// PHPMailerLite, which will invoke "sendmail". This is appropriate // PHPMailerLite, which will invoke "sendmail". This is appropriate
// if sendmail actually works on your host, but if you haven't configured mail // if sendmail actually works on your host, but if you haven't configured mail
// it may not be so great. You can also use Amazon SES, by changing this to // it may not be so great. A number of other mailers are available (e.g., SES,
// 'PhabricatorMailImplementationAmazonSESAdapter', signing up for SES, and // SendGrid, SMTP, custom mailers), consult "Configuring Outbound Email" in
// filling in your 'amazon-ses.access-key' and 'amazon-ses.secret-key' below. // the documentation for details.
'metamta.mail-adapter' => 'metamta.mail-adapter' =>
'PhabricatorMailImplementationPHPMailerLiteAdapter', 'PhabricatorMailImplementationPHPMailerLiteAdapter',
@ -317,12 +316,18 @@ return array(
'metamta.user-address-format' => 'full', 'metamta.user-address-format' => 'full',
// If you're using PHPMailer to send email, provide the mailer and options // If you're using PHPMailer to send email, provide the mailer and options
// here. PHPMailer is a superior to PHPMailerLite and provides more mailers. // here. PHPMailer is much more enormous than PHPMailerLite, and provides more
// You need it when you want to use SMTP instead of sendmail as the mailer. // mailers and greater enormity. You need it when you want to use SMTP
// instead of sendmail as the mailer.
'phpmailer.mailer' => 'smtp', 'phpmailer.mailer' => 'smtp',
'phpmailer.smtp-host' => '', 'phpmailer.smtp-host' => '',
'phpmailer.smtp-port' => 25, 'phpmailer.smtp-port' => 25,
// When using PHPMailer with SMTP, you can set this to one of "tls" or "ssl"
// to use TLS or SSL. Leave it blank for vanilla SMTP. If you're sending
// via Gmail, set it to "ssl".
'phpmailer.smtp-protocol' => '',
// Set following if your smtp server requires authentication. // Set following if your smtp server requires authentication.
'phpmailer.smtp-user' => null, 'phpmailer.smtp-user' => null,
'phpmailer.smtp-password' => null, 'phpmailer.smtp-password' => null,

View file

@ -1710,6 +1710,13 @@ class PHPMailer {
return $out; return $out;
} }
/**
* 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. * Encode string to q encoding.
* @link http://tools.ietf.org/html/rfc2047 * @link http://tools.ietf.org/html/rfc2047
@ -1719,21 +1726,32 @@ class PHPMailer {
* @return string * @return string
*/ */
public function EncodeQ ($str, $position = 'text') { 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 // There should not be any EOL in the string
$encoded = preg_replace('/[\r\n]*/', '', $str); $encoded = preg_replace('/[\r\n]*/', '', $str);
switch (strtolower($position)) { switch (strtolower($position)) {
case 'phrase': 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; break;
case 'comment': case 'comment':
$encoded = preg_replace("/([\(\)\"])/", "'='.sprintf('%02X', ord('\\1'))", $encoded); $encoded = preg_replace_callback(
"/([\(\)\"])/",
array($this, 'encodeQCallback'),
$encoded);
break;
case 'text': case 'text':
default: default:
// Replace every high ascii, control =, ? and _ characters // Replace every high ascii, control =, ? and _ characters
//TODO using /e (equivalent to eval()) is probably not a good idea $encoded = preg_replace_callback(
$encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/', '/([\000-\011\013\014\016-\037\075\077\137\177-\377])/',
"'='.sprintf('%02X', ord('\\1'))", $encoded); array($this, 'encodeQCallback'),
$encoded);
break; break;
} }

View file

@ -30,6 +30,11 @@ final class PhabricatorMailImplementationPHPMailerAdapter
$this->mailer->Password = $this->mailer->Password =
PhabricatorEnv::getEnvConfig('phpmailer.smtp-password'); PhabricatorEnv::getEnvConfig('phpmailer.smtp-password');
} }
$protocol = PhabricatorEnv::getEnvConfig('phpmailer.smtp-protocol');
if ($protocol) {
$this->mailer->SMTPSecure = $protocol;
}
} else if ($mailer == 'sendmail') { } else if ($mailer == 'sendmail') {
$this->mailer->IsSendmail(); $this->mailer->IsSendmail();
} else { } else {