Mi sono documentato un po'.
In pratica non esiste nessuna via semplice per prendere gli allegati dalle e-mail via php, ma ho trovato questa cosa che ti potrebbe tornare utile:
Codice PHP:
$attachments = array();
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) {
if(strtolower($object->attribute) == 'name') {
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['name'] = $object->value;
}
}
}
if($attachments[$i]['is_attachment']) {
$attachments[$i]['attachment'] = imap_fetchbody($connection, $message_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
$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
}
}
}
}
In pratica questo codice genererà un array di questo tipo:
codice:
Array
(
[0] => Array
(
[is_attachment] =>
[filename] =>
[name] =>
[attachment] =>
)
[1] => Array
(
[is_attachment] => 1
[filename] => Analytics_www.electrictoolbox.com_20090108-20090207.tsv
[name] => Analytics_www.electrictoolbox.com_20090108-20090207.tsv
[attachment] => ...
)
)
Avendo questo devi utilizzare un foreach nell'array $attachments che controlla se is_attachment è 1 (potrebbe capitare che è un allegato fasullo), e poi fai quello che vuoi con il [filename], il [name] e [attachment]. I primi due ti servono per il nome, il terzo invece è proprio l'allegato come stringa.
Spero ti sia stato d'aiuto,