function _support_get_attachments in Support Ticketing System 6
Same name and namespace in other branches
- 7 support.module \_support_get_attachments()
Find all attachments in the current message.
1 call to _support_get_attachments()
- support_client_fetch in ./
support.module - Fetch mail for a specific client.
File
- ./
support.module, line 1520 - support.module
Code
function _support_get_attachments($stream, $message, $structure, $parts, $prefix = FALSE) {
$attachments = array();
for ($part = 2; $part <= $parts; $part++) {
if ($prefix == FALSE) {
$prefix = $part;
}
$attachment = imap_fetchbody($stream, $message, $prefix);
$details = imap_bodystruct($stream, $message, $prefix);
if (empty($details)) {
continue;
}
// Extract all the parts in a multipart message.
if ($details->type == TYPEMULTIPART) {
if ($prefix) {
$prefix = $prefix . '.';
}
$structure = imap_fetchstructure($stream, $message);
while (list($index, $substructure) = each($structure->parts)) {
$parts = count($substructure->parts);
$attachments += _support_get_attachments($stream, $message, $substructure, $parts, $prefix . ($index + 1));
}
if (!empty($structure)) {
foreach ($structure->parameters as $parameter) {
if (strtoupper($parameter->attribute) == 'CHARSET') {
$encoding = mb_decode_mimeheader($parameter->value);
break;
}
if ($data) {
return $data;
}
}
}
}
// Decode as necessary
if ($details->encoding == ENCBASE64) {
$attachment = imap_base64($attachment);
}
else {
if ($details->encoding == ENCQUOTEDPRINTABLE) {
$attachment = quoted_printable_decode($attachment);
}
else {
if ($details->type == TYPETEXT) {
$attachment = imap_utf8($attachment);
}
}
}
$details->filemime = _support_get_filemime($details);
if (!empty($attachment)) {
$details->attachment = $attachment;
$attachments[] = $details;
}
if (!empty($prefix)) {
$pieces = explode('.', $prefix);
$piece = count($pieces) - 1;
$pieces[$piece]++;
$prefix = implode('.', $pieces);
}
}
return $attachments;
}