1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 03:20:59 +01:00

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
This commit is contained in:
epriestley 2015-04-21 09:49:40 -07:00
parent d8ab5f594c
commit 80b23b21f3

View file

@ -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);