Skip to content

Commit

Permalink
Update fMailbox.php to provide filename for "related" attachments
Browse files Browse the repository at this point in the history
In most circumstances there's little reason to need to know the filename of the related email attachments (those embedded in to the body of the email) since most email clients render HTML now. However, when rendered in plaintext and the related file becomes an attachment, there's no filename that can be provided for the attachment, only the data and the mimetype. I'm not sure if this was simply an oversight or it was purposefully left out. I can't personally think of a reason not to provide the filename *if it's provided*, and if it's not the value will simply be blank as is the case with "inline" or embedded attachment types as well. At least this way a file extension can be provided to associate the file with an application.

This change simply moves the detection of content_id and inline attachments inside the test for **$has_disposition** in the __handleParts()__ method.
  • Loading branch information
BrendonKoz committed Jul 3, 2015
1 parent 06be20f commit 9d29ac0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions fMailbox.php
Expand Up @@ -218,20 +218,6 @@ static private function handlePart($info, $structure)
}
}

// This indicates a content-id which is used for multipart/related
if ($structure['content_id'] && $structure['disposition'] == 'inline') {
if (!isset($info['related'])) {
$info['related'] = array();
}
$cid = $structure['content_id'][0] == '<' ? substr($structure['content_id'], 1, -1) : $structure['content_id'];
$info['related']['cid:' . $cid] = array(
'mimetype' => $structure['type'] . '/' . $structure['subtype'],
'data' => $content
);
return $info;
}


$has_disposition = !empty($structure['disposition']);
$is_text = $structure['type'] == 'text' && $structure['subtype'] == 'plain';
$is_html = $structure['type'] == 'text' && $structure['subtype'] == 'html';
Expand Down Expand Up @@ -262,6 +248,20 @@ static private function handlePart($info, $structure)
}
}

// This indicates a content-id which is used for multipart/related
if ($structure['content_id'] && $structure['disposition'] == 'inline') {
if (!isset($info['related'])) {
$info['related'] = array();
}
$cid = $structure['content_id'][0] == '<' ? substr($structure['content_id'], 1, -1) : $structure['content_id'];
$info['related']['cid:' . $cid] = array(
'filename' => $filename,
'mimetype' => $structure['type'] . '/' . $structure['subtype'],
'data' => $content
);
return $info;
}

// This automatically handles primary content that has a content-disposition header on it
if ($structure['disposition'] == 'inline' && $filename === '') {
if ($is_text && !isset($info['text'])) {
Expand Down

0 comments on commit 9d29ac0

Please sign in to comment.