1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +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.
'metamta.can-send-as-user' => false,
// Adapter class to use to transmit mail to the MTA. The default uses
// PHPMailerLite, which will invoke "sendmail". This is appropriate
// 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
// 'PhabricatorMailImplementationAmazonSESAdapter', signing up for SES, and
// filling in your 'amazon-ses.access-key' and 'amazon-ses.secret-key' below.
// it may not be so great. A number of other mailers are available (e.g., SES,
// SendGrid, SMTP, custom mailers), consult "Configuring Outbound Email" in
// the documentation for details.
'metamta.mail-adapter' =>
'PhabricatorMailImplementationPHPMailerLiteAdapter',
@ -317,12 +316,18 @@ return array(
'metamta.user-address-format' => 'full',
// If you're using PHPMailer to send email, provide the mailer and options
// here. PHPMailer is a superior to PHPMailerLite and provides more mailers.
// You need it when you want to use SMTP instead of sendmail as the mailer.
// here. PHPMailer is much more enormous than PHPMailerLite, and provides more
// mailers and greater enormity. You need it when you want to use SMTP
// instead of sendmail as the mailer.
'phpmailer.mailer' => 'smtp',
'phpmailer.smtp-host' => '',
'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.
'phpmailer.smtp-user' => null,
'phpmailer.smtp-password' => null,

View file

@ -1710,6 +1710,13 @@ class PHPMailer {
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.
* @link http://tools.ietf.org/html/rfc2047
@ -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;
}

View file

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