From a7c681b54997b849c46054571fa2d0071c97fa32 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 15 Jun 2018 12:03:28 -0700 Subject: [PATCH] Don't set mail HTML bodies if there's no actual HTML body Summary: See . Some mailers get upset if we `setHTMLBody(...)` with an empty string. There's some possible argument they should be more graceful about this, but it's reasonably pretty ambiguous. Only try to set the HTML body if we actually have a nonempty HTML body. Test Plan: - Configured an "smtp" mailer. - Ran `echo hi | ./bin/mail send-test --to someone@somewhere.com --subject test`. - Before: error about empty message body. - After: no more message body error. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D19494 --- .../metamta/storage/PhabricatorMetaMTAMail.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index c2435499af..cca3dfa335 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -917,13 +917,14 @@ final class PhabricatorMetaMTAMail if ($send_html) { $html_body = idx($params, 'html-body'); - - // NOTE: We just drop the entire HTML body if it won't fit. Safely - // truncating HTML is hard, and we already have the text body to fall - // back to. - if (strlen($html_body) <= $body_limit) { - $mailer->setHTMLBody($html_body); - $body_limit -= strlen($html_body); + if (strlen($html_body)) { + // NOTE: We just drop the entire HTML body if it won't fit. Safely + // truncating HTML is hard, and we already have the text body to fall + // back to. + if (strlen($html_body) <= $body_limit) { + $mailer->setHTMLBody($html_body); + $body_limit -= strlen($html_body); + } } }