From 80b23b21f396d80bcdfabcdfaa3c825c7144234f Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 21 Apr 2015 09:49:40 -0700 Subject: [PATCH] Work around mailparse bug (?) with messages that have no terminal newline Summary: Under some unusual circumstances, mailparse appears to incorrectly discard the last line of some mail messages. Test Plan: - Constructed a raw mail with no terminal newline. - Piped it into `mail_receiver.php`. - Saw the last line vanish into the aether. - Applied patch; repeated; last line survived. Reviewers: btrahan, chad Reviewed By: chad Subscribers: chad, epriestley Differential Revision: https://secure.phabricator.com/D12494 --- externals/mimemailparser/MimeMailParser.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/externals/mimemailparser/MimeMailParser.class.php b/externals/mimemailparser/MimeMailParser.class.php index 3ce0ee49c7..a192f2b266 100644 --- a/externals/mimemailparser/MimeMailParser.class.php +++ b/externals/mimemailparser/MimeMailParser.class.php @@ -111,6 +111,14 @@ class MimeMailParser { * @param $data String */ public function setText($data) { + // NOTE: This has been modified for Phabricator. If the input data does not + // end in a newline, Mailparse fails to include the last line in the mail + // body. This happens somewhere deep, deep inside the mailparse extension, + // so adding a newline here seems like the most straightforward fix. + if (!preg_match('/\n\z/', $data)) { + $data = $data."\n"; + } + $this->resource = mailparse_msg_create(); // does not parse incrementally, fast memory hog might explode mailparse_msg_parse($this->resource, $data);