Skip to content

Commit 80b23b2

Browse files
author
epriestley
committedApr 21, 2015
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
1 parent d8ab5f5 commit 80b23b2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎externals/mimemailparser/MimeMailParser.class.php

+8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ public function setStream($stream) {
111111
* @param $data String
112112
*/
113113
public function setText($data) {
114+
// NOTE: This has been modified for Phabricator. If the input data does not
115+
// end in a newline, Mailparse fails to include the last line in the mail
116+
// body. This happens somewhere deep, deep inside the mailparse extension,
117+
// so adding a newline here seems like the most straightforward fix.
118+
if (!preg_match('/\n\z/', $data)) {
119+
$data = $data."\n";
120+
}
121+
114122
$this->resource = mailparse_msg_create();
115123
// does not parse incrementally, fast memory hog might explode
116124
mailparse_msg_parse($this->resource, $data);

0 commit comments

Comments
 (0)
Failed to load comments.