From d78386584f0d40b272501165245f9837cdcceba2 Mon Sep 17 00:00:00 2001 From: Bryan Cuccioli Date: Wed, 5 Jun 2013 05:39:08 -0700 Subject: [PATCH] Globally limit the size of generated emails. Summary: At the global level, truncate emails at a user-configured size. Test Plan: Untested, as I could not get PHP to send emails on my box, but if you can this should be very easy to test. Just set the max size to something like .001 kilobytes and make sure it does the right thing. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, AnhNhan Maniphest Tasks: T1392 Differential Revision: https://secure.phabricator.com/D6118 --- conf/default.conf.php | 4 ++++ .../config/option/PhabricatorMetaMTAConfigOptions.php | 11 +++++++++++ .../metamta/storage/PhabricatorMetaMTAMail.php | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/conf/default.conf.php b/conf/default.conf.php index 00e0ca3b80..6b8b3b2476 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -285,6 +285,10 @@ return array( // mostly never arrive. 'metamta.can-send-as-user' => false, + // Limit the maximum size of the body of an email generated for a diff + // (in bytes). + 'metamta.email-body-limit' => 524288, + // 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 diff --git a/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php b/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php index 452f1ed32f..8adf8610d1 100644 --- a/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php +++ b/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php @@ -338,6 +338,17 @@ EODOC ->addExample( 'gwashington (George Washington) ', 'full'), + $this->newOption('metamta.email-body-limit', 'int', 524288) + ->setDescription( + pht( + 'You can set a limit for the maximum byte size of outbound mail. '. + 'Mail which is larger than this limit will be truncated before '. + 'being sent. This can be useful if your MTA rejects mail which '. + 'exceeds some limit (this is reasonably common). Specify a value '. + 'in bytes.')) + ->setSummary(pht('Global cap for size of generated emails (bytes).')) + ->addExample(524288, pht('Truncate at 512KB')) + ->addExample(1048576, pht('Truncate at 1MB')) ); } diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index e0c0dd3d0e..1a606a09a1 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -445,6 +445,12 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { } break; case 'body': + $max = PhabricatorEnv::getEnvConfig('metamta.email-body-limit'); + if (strlen($value) > $max) { + $value = phutil_utf8_shorten($value, $max); + $value .= "\n"; + $value .= pht('(This email was truncated at %d bytes.)', $max); + } $mailer->setBody($value); break; case 'subject':