Aquí tienen la solución para obtener los adjuntos de un email.
Código PHP:
Ver original<?php
#
$hostname = '{mail.cocacola.cl:993/imap/ssl/novalidate-cert}INBOX';
$password = 'suclavedelcorreo';
$bandeja_entrada="xml/";
/* try to connect */
/* grab emails */
/* if emails are returned, cycle through each... */
if($emails) {
/* begin output var */
$output = '';
/* put the newest emails on top */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetc_overview($inbox,$email_number,0);
$message = imap_fetcbody($inbox,$email_number,2);
$structure = imap_fethstructure($inbox,$email_number);
//pre($overview);
if(isset($structure->parts) && count($structure->parts)) { for($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false,
'filename' => '',
'name' => '',
'attachment' => '');
if($structure->parts[$i]->ifdparameters) {
foreach($structure->parts[$i]->dparameters as $object) {
if(strtolower($object->attribute) == 'filename') { $attachments[$i]['is_attachment'] = true;
$attachments[$i]['filename'] = $object->value;
}
}
}
if($structure->parts[$i]->ifparameters) {
foreach($structure->parts[$i]->parameters as $object) {
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['name'] = $object->value;
}
}
}
if($attachments[$i]['is_attachment']) {
$attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1); if($structure->parts[$i]->encoding == 3) { // 3 = BASE64
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); }
elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
}
}
} // for($i = 0; $i < count($structure->parts); $i++)
} // if(isset($structure->parts) && count($structure->parts))
if(count($atachments)!=0){
foreach($attachments as $at){
if($at[is_attachment]==1){
#-------------------------------------------------------------------------- guardar adjuntos
}
}
}
}
// echo $output;
}
/* close the connection */
?>