*** 1328,1349 ****
$attachment->filereference = $folderid . ":" . $id . ":" . $i;
$attachment->method = 1; //Normal attachment
$attachment->contentid = isset($part->headers['content-id']) ? str_replace("<", "", str_replace(">", "", $part->headers['content-id'])) : "";
-
if (isset($part->disposition) && $part->disposition == "inline") {
$attachment->isinline = 1;
// We try to fix the name for the inline file.
// FIXME: This is a dirty hack as the used in the Zarafa backend, if you have a better method let me know!
! // KD 2015-06-16 If we got a filename use it, otherwise guess
! if (!isset($part->filename)) {
! if (isset($part->ctype_primary) && isset($part->ctype_secondary)) {
! ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - Guessing extension for inline attachment [primary_type %s secondary_type %s]", $part->ctype_primary, $part->ctype_secondary));
! if (isset(BackendIMAP::$mimeTypes[$part->ctype_primary.'/'.$part->ctype_secondary])) {
! ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - primary_type %s secondary_type %s", $part->ctype_primary, $part->ctype_secondary));
! $attachment->displayname = "inline_".$i.".".BackendIMAP::$mimeTypes[$part->ctype_primary.'/'.$part->ctype_secondary];
! }
! else {
! ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - no extension found in /etc/mime.types'!!"));
! }
}
}
else {
--- 1327,1344 ----
$attachment->filereference = $folderid . ":" . $id . ":" . $i;
$attachment->method = 1; //Normal attachment
$attachment->contentid = isset($part->headers['content-id']) ? str_replace("<", "", str_replace(">", "", $part->headers['content-id'])) : "";
if (isset($part->disposition) && $part->disposition == "inline") {
$attachment->isinline = 1;
// We try to fix the name for the inline file.
// FIXME: This is a dirty hack as the used in the Zarafa backend, if you have a better method let me know!
! if (isset($part->ctype_primary) && isset($part->ctype_secondary)) {
! ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - Guessing extension for inline attachment [primary_type %s secondary_type %s]", $part->ctype_primary, $part->ctype_secondary));
! if (isset(BackendIMAP::$mimeTypes[$part->ctype_primary.'/'.$part->ctype_secondary])) {
! ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - primary_type %s secondary_type %s", $part->ctype_primary, $part->ctype_secondary));
! $attachment->displayname = "inline_".$i.".".BackendIMAP::$mimeTypes[$part->ctype_primary.'/'.$part->ctype_secondary];
! }
! else {
! ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - no extension found in /etc/mime.types'!!"));
}
}
else {
And in support of this we have to get the filename when the mime part is decoded; that is done in include/mimeDecode.php:
*** mimeDecode.php Mon Jun 15 10:00:00 2015
--- /usr/share/z-push/include/mimeDecode.php Tue Jun 16 14:27:02 2015
***************
*** 290,298 ****
case 'content-type':
$content_type = $this->_parseHeaderValue($headers[$key]['value']);
! if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) {
$return->ctype_primary = $regs[1];
$return->ctype_secondary = $regs[2];
}
if (isset($content_type['other'])) {
--- 290,305 ----
case 'content-type':
$content_type = $this->_parseHeaderValue($headers[$key]['value']);
! if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)\; name=\"([0-9a-z+.-]+)/i', $headers[$key]['value'], $regs)) {
$return->ctype_primary = $regs[1];
$return->ctype_secondary = $regs[2];
+ $return->filename = $regs[3];
+ }
+ else {
+ if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) {
+ $return->ctype_primary = $regs[1];
+ $return->ctype_secondary = $regs[2];
+ }
}
if (isset($content_type['other'])) {
Now if there is a filename specified in the MIME header it is returned in the structure and the imap.php code uses it for the attachment. If it's missing then a "best guess" using mime.types is made as before.
Diff for imap.c:
And in support of this we have to get the filename when the mime part is decoded; that is done in include/mimeDecode.php:
Now if there is a filename specified in the MIME header it is returned in the structure and the imap.php code uses it for the attachment. If it's missing then a "best guess" using mime.types is made as before.