Skip to content

Commit d783865

Browse files
Bryan Cuccioliepriestley
Bryan Cuccioli
authored and
epriestley
committedJun 5, 2013
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
1 parent 758586a commit d783865

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
 

‎conf/default.conf.php

+4
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@
285285
// mostly never arrive.
286286
'metamta.can-send-as-user' => false,
287287

288+
// Limit the maximum size of the body of an email generated for a diff
289+
// (in bytes).
290+
'metamta.email-body-limit' => 524288,
291+
288292
// Adapter class to use to transmit mail to the MTA. The default uses
289293
// PHPMailerLite, which will invoke "sendmail". This is appropriate
290294
// if sendmail actually works on your host, but if you haven't configured mail

‎src/applications/config/option/PhabricatorMetaMTAConfigOptions.php

+11
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,17 @@ public function getOptions() {
338338
->addExample(
339339
'gwashington (George Washington) <gwashington@example.com>',
340340
'full'),
341+
$this->newOption('metamta.email-body-limit', 'int', 524288)
342+
->setDescription(
343+
pht(
344+
'You can set a limit for the maximum byte size of outbound mail. '.
345+
'Mail which is larger than this limit will be truncated before '.
346+
'being sent. This can be useful if your MTA rejects mail which '.
347+
'exceeds some limit (this is reasonably common). Specify a value '.
348+
'in bytes.'))
349+
->setSummary(pht('Global cap for size of generated emails (bytes).'))
350+
->addExample(524288, pht('Truncate at 512KB'))
351+
->addExample(1048576, pht('Truncate at 1MB'))
341352
);
342353
}
343354

‎src/applications/metamta/storage/PhabricatorMetaMTAMail.php

+6
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ public function sendNow(
445445
}
446446
break;
447447
case 'body':
448+
$max = PhabricatorEnv::getEnvConfig('metamta.email-body-limit');
449+
if (strlen($value) > $max) {
450+
$value = phutil_utf8_shorten($value, $max);
451+
$value .= "\n";
452+
$value .= pht('(This email was truncated at %d bytes.)', $max);
453+
}
448454
$mailer->setBody($value);
449455
break;
450456
case 'subject':

0 commit comments

Comments
 (0)
Failed to load comments.