From 13bd9d5313bb54c9a8ed06a81264b91c1b719b92 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 1 Apr 2014 20:55:17 -0500 Subject: [PATCH] Support inline images without a filename Such images are attached to emails by Lotus Notes. Technically, these images are valid attachments, although historically osTicket would reject them --- include/class.mailfetch.php | 11 +++++++++-- include/class.mailparse.php | 11 ++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index f1ea77d74..beb427300 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -19,7 +19,6 @@ require_once(INCLUDE_DIR.'class.ticket.php'); require_once(INCLUDE_DIR.'class.dept.php'); require_once(INCLUDE_DIR.'class.email.php'); require_once(INCLUDE_DIR.'class.filter.php'); -require_once(INCLUDE_DIR.'html2text.php'); require_once(INCLUDE_DIR.'tnef_decoder.php'); class MailFetcher { @@ -441,7 +440,8 @@ class MailFetcher { array('attachment', 'inline'))) { $filename = $this->findFilename($part->dparameters); } - // Inline attachments without disposition. + // Inline attachments without disposition. NOTE that elseif is + // not utilized here b/c ::findFilename may return null if (!$filename && $part->ifparameters && $part->parameters && $part->type > 0) { $filename = $this->findFilename($part->parameters); @@ -450,6 +450,13 @@ class MailFetcher { $content_id = ($part->ifid) ? rtrim(ltrim($part->id, '<'), '>') : false; + // Some mail clients / servers (like Lotus Notes / Domino) will + // send images without a filename. For such a case, generate a + // random filename for the image + if (!$filename && $content_id && $part->type == 5) { + $filename = 'image-'.Misc::randCode(4).'.'.strtolower($part->subtype); + } + if($filename) { return array( array( diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 0ec0b4f19..2b05900a8 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -366,10 +366,19 @@ class Mail_Parse { // Support attachments that do not specify a content-disposition // but do specify a "name" parameter in the content-type header. elseif (isset($part->ctype_parameters['name'])) - $filename=$part->ctype_parameters['name']; + $filename = $part->ctype_parameters['name']; elseif (isset($part->ctype_parameters['name*'])) $filename = Format::decodeRfc5987( $part->ctype_parameters['name*']); + + // Some mail clients / servers (like Lotus Notes / Domino) will + // send images without a filename. For such a case, generate a + // random filename for the image + elseif (isset($part->headers['content-id']) + && $part->headers['content-id'] + && 0 === strcasecmp($part->ctype_primary, 'image')) + $filename = 'image-'.Misc::randCode(4).'.' + .strtolower($part->ctype_secondary); else // Not an attachment? return false; -- GitLab