/** * Write in $$attachments, array with the information of attachment * @param <type> $structure * @param <type> $attachments * @param <type> $pIndex */ private function _pushAttachmentsInfo(&$structure, &$attachments, $pIndex = '0') { $name = ''; if (isset($structure->d_parameters['filename']) && $structure->d_parameters['filename']) { $name = $structure->d_parameters['filename']; } else { if (isset($structure->ctype_parameters['name']) && $structure->ctype_parameters['name']) { $name = $structure->ctype_parameters['name']; } else { if (strtolower($structure->ctype_primary) == 'text' && strtolower($structure->ctype_secondary) == 'calendar') { $name = 'calendar.ics'; } } } //Attachments com nomes grandes são quebrados em varias partes VER RFC2231 if (!$name && isset($structure->disposition) && (strtolower($structure->disposition) === 'attachment' || strtolower($structure->ctype_primary) == 'image' || strtolower($structure->ctype_primary . '/' . $structure->ctype_secondary) == 'application/octet-stream')) { foreach ($structure->d_parameters as $i => $v) { if (strpos($i, 'filename') !== false) { $name .= urldecode(str_ireplace(array('ISO-8859-1', 'UTF-8', 'US-ASCII'), '', $v)); } } } if (!$name && isset($structure->disposition) && (strtolower($structure->disposition) === 'attachment' || strtolower($structure->ctype_primary) == 'image' || strtolower($structure->ctype_primary . '/' . $structure->ctype_secondary) == 'application/octet-stream')) { foreach ($structure->ctype_parameters as $i => $v) { if (strpos($i, 'name') !== false) { $name .= urldecode(str_ireplace(array('ISO-8859-1', 'UTF-8', 'US-ASCII'), '', $v)); } } } //////////////////////////////////////////////////////////////////////////////////// if ($structure->ctype_primary == 'message') { $attach = new attachment(); $attach->setStructureFromRawMail($structure->body); if (!$name) { $name = isset($attach->structure->headers['subject']) ? $attach->structure->headers['subject'] : 'no title'; } if (!preg_match("/\\.eml\$/", $name)) { $name .= '.eml'; } } if (!$name && strtolower($structure->ctype_primary) == 'image') { if (strlen($structure->ctype_secondary) === 3) { $ext = strtolower($structure->ctype_secondary); } $name = 'Embedded-Image.' . $ext; } if ($name) { $codificao = mb_detect_encoding($name . 'x', 'UTF-8, ISO-8859-1'); if ($codificao == 'UTF-8') { $name = utf8_decode($name); } $definition['pid'] = $pIndex; $definition['name'] = addslashes(mb_convert_encoding($name, "ISO-8859-1")); $definition['encoding'] = $structure->headers['content-transfer-encoding']; $definition['type'] = strtolower($structure->ctype_primary) . '/' . strtolower($structure->ctype_secondary); $definition['fsize'] = mb_strlen($structure->body, $structure->headers['content-transfer-encoding']); array_push($attachments, $definition); } }