1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 04:42:40 +01:00

Backport fix from php-mime-mail-parser to fix attachment parsing

Summary:
- Allow proper parsing of attachments with missing Content-Disposition
  header

Test Plan:
- Create application email for Maniphest.
- Send example broken email from Outlook 2007 to that address {F1842816}

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D16584
This commit is contained in:
Brendan Zerr 2016-09-21 15:02:45 -07:00 committed by epriestley
parent f8c2225268
commit af218564e5

View file

@ -251,20 +251,42 @@ class MimeMailParser {
return $headers;
}
/**
* Returns the attachments contents in order of appearance
* @return Array
* @param $type Object[optional]
*/
public function getAttachments() {
// NOTE: This has been modified for Phabricator. Some mail clients do not
// send attachments with "Content-Disposition" headers.
$attachments = array();
$dispositions = array("attachment","inline");
$non_attachment_types = array("text/plain", "text/html");
$nonameIter = 0;
foreach ($this->parts as $part) {
$disposition = $this->getPartContentDisposition($part);
if (in_array($disposition, $dispositions)) {
$filename = 'noname';
if (isset($part['disposition-filename'])) {
$filename = $part['disposition-filename'];
} elseif (isset($part['content-name'])) {
// if we have no disposition but we have a content-name, it's a valid attachment.
// we simulate the presence of an attachment disposition with a disposition filename
$filename = $part['content-name'];
$disposition = 'attachment';
} elseif (!in_array($part['content-type'], $non_attachment_types, true)
&& substr($part['content-type'], 0, 10) !== 'multipart/'
) {
// if we cannot get it with getMessageBody, we assume it is an attachment
$disposition = 'attachment';
}
if (in_array($disposition, $dispositions) && isset($filename) === true) {
if ($filename == 'noname') {
$nonameIter++;
$filename = 'noname'.$nonameIter;
}
$attachments[] = new MimeMailParser_attachment(
$part['disposition-filename'],
$filename,
$this->getPartContentType($part),
$this->getAttachmentStream($part),
$disposition,