mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 04:42:40 +01:00
Skip attaching 'inline' text attachments
Summary: Mail clients can send messages where the body is represented as 'inline' attachments. Don't treat any such text attachments as actual attachments. Test Plan: toulouse, can you verify this fixes the issue? Reviewed By: toulouse Reviewers: toulouse CC: aran, toulouse, epriestley Differential Revision: 441
This commit is contained in:
parent
93773495d1
commit
8ca5581a9c
2 changed files with 61 additions and 32 deletions
|
@ -181,6 +181,13 @@ class MimeMailParser {
|
||||||
* @param $type Object[optional]
|
* @param $type Object[optional]
|
||||||
*/
|
*/
|
||||||
public function getMessageBody($type = 'text') {
|
public function getMessageBody($type = 'text') {
|
||||||
|
|
||||||
|
// NOTE: This function has been modified for Phabricator. The default
|
||||||
|
// implementation returns the last matching part, which throws away text
|
||||||
|
// for many emails. Instead, we concatenate all matching parts. See
|
||||||
|
// issue 22 for discussion:
|
||||||
|
// http://code.google.com/p/php-mime-mail-parser/issues/detail?id=22
|
||||||
|
|
||||||
$body = false;
|
$body = false;
|
||||||
$mime_types = array(
|
$mime_types = array(
|
||||||
'text'=> 'text/plain',
|
'text'=> 'text/plain',
|
||||||
|
@ -188,10 +195,23 @@ class MimeMailParser {
|
||||||
);
|
);
|
||||||
if (in_array($type, array_keys($mime_types))) {
|
if (in_array($type, array_keys($mime_types))) {
|
||||||
foreach($this->parts as $part) {
|
foreach($this->parts as $part) {
|
||||||
|
$disposition = $this->getPartContentDisposition($part);
|
||||||
|
if ($disposition == 'attachment') {
|
||||||
|
// text/plain parts with "Content-Disposition: attachment" are
|
||||||
|
// attachments, not part of the text body.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($this->getPartContentType($part) == $mime_types[$type]) {
|
if ($this->getPartContentType($part) == $mime_types[$type]) {
|
||||||
$headers = $this->getPartHeaders($part);
|
$headers = $this->getPartHeaders($part);
|
||||||
$body = $this->decode($this->getPartBody($part), array_key_exists('content-transfer-encoding', $headers) ?
|
// Concatenate all the matching parts into the body text. For example,
|
||||||
$headers['content-transfer-encoding'] : '');
|
// if a user sends a message with some text, then an image, and then
|
||||||
|
// some more text, the text body of the email gets split over several
|
||||||
|
// attachments.
|
||||||
|
$body .= $this->decode(
|
||||||
|
$this->getPartBody($part),
|
||||||
|
array_key_exists('content-transfer-encoding', $headers)
|
||||||
|
? $headers['content-transfer-encoding']
|
||||||
|
: '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -45,6 +45,15 @@ $received->setBodies(array(
|
||||||
|
|
||||||
$attachments = array();
|
$attachments = array();
|
||||||
foreach ($parser->getAttachments() as $attachment) {
|
foreach ($parser->getAttachments() as $attachment) {
|
||||||
|
if (preg_match('@text/(plain|html)@', $attachment->getContentType()) &&
|
||||||
|
$attachment->getContentDisposition() == 'inline') {
|
||||||
|
// If this is an "inline" attachment with some sort of text content-type,
|
||||||
|
// do not treat it as a file for attachment. MimeMailParser already picked
|
||||||
|
// it up in the getMessageBody() call above. We still want to treat 'inline'
|
||||||
|
// attachments with other content types (e.g., images) as attachments.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$file = PhabricatorFile::newFromFileData(
|
$file = PhabricatorFile::newFromFileData(
|
||||||
$attachment->getContent(),
|
$attachment->getContent(),
|
||||||
array(
|
array(
|
||||||
|
|
Loading…
Reference in a new issue