1
0
Fork 0
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:
epriestley 2011-06-12 21:09:55 -07:00
parent 93773495d1
commit 8ca5581a9c
2 changed files with 61 additions and 32 deletions

View file

@ -181,6 +181,13 @@ class MimeMailParser {
* @param $type Object[optional]
*/
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;
$mime_types = array(
'text'=> 'text/plain',
@ -188,10 +195,23 @@ class MimeMailParser {
);
if (in_array($type, array_keys($mime_types))) {
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]) {
$headers = $this->getPartHeaders($part);
$body = $this->decode($this->getPartBody($part), array_key_exists('content-transfer-encoding', $headers) ?
$headers['content-transfer-encoding'] : '');
$headers = $this->getPartHeaders($part);
// Concatenate all the matching parts into the body text. For example,
// 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 {

View file

@ -45,6 +45,15 @@ $received->setBodies(array(
$attachments = array();
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(
$attachment->getContent(),
array(