I'm writing a fetcher of emails from IMAP. I've written my code so that it will look for BOTH attachments and inline images.
Everything works great, but I'm having trouble with the file_put_contents
part where the content of the attachment is saved.
I've just put $object['attachment']
as kind of a best guess around what it should be, because I don't know how to obtain this from the array/s.
$inbox = imap_open($hostname,$username,$password);
$emails = imap_search($inbox,'ALL');
if ($emails) {
rsort($emails);
foreach($emails as $n) {
$structure = imap_fetchstructure($inbox,$n);
foreach($structure->parts AS $object) {
if (strtolower($object->disposition) == "attachment") {
foreach ($object->dparameters AS $object2) {
if(strtolower($object2->attribute) == "filename")
$filename = $object2->value;
}
//file_put_contents($filename, base64_decode($object['attachment']));
}
foreach($object->parts AS $object2) {
if (strtolower($object2->disposition) == "inline") {
foreach ($object2->dparameters AS $object3) {
if(strtolower($object3->attribute) == "filename")
$filename = $object3->value;
}
//file_put_contents($filename, base64_decode($object['attachment']));
}
}
}
}
}