Skip to content

Commit

Permalink
Work around mailparse bug (?) with messages that have no terminal new…
Browse files Browse the repository at this point in the history
…line

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
  • Loading branch information
epriestley committed Apr 21, 2015
1 parent d8ab5f5 commit 80b23b2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions externals/mimemailparser/MimeMailParser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ public function setStream($stream) {
* @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);
Expand Down

0 comments on commit 80b23b2

Please sign in to comment.