I have been trying to find information on how to retrieve attachments from a gmail account in either python or PHP, I\'m hoping that someone here can be of some help, thanks.
I found some code that works! this will download any attachments to a selected folder
parts;
foreach ($parts as $part) {
if ($part->parameters[0]->attribute == "NAME") {
//Generate a filename with format DATE_RANDOM#_ATTACHMENTNAME.EXT
$savefilename = date("m-d-Y") . '_' . mt_rand(rand(), 6) . '_' . $part->parameters[0]->value;
save_attachment(imap_fetchbody($imap,$result,2),$savefilename,$savefilepath,$savethumbpath);
imap_fetchbody($imap,$result,2); //This marks message as read
}
}
}
}
imap_close($imap);
function save_attachment( $content , $filename , $localfilepath, $thumbfilepath ) {
if (imap_base64($content) != FALSE) {
$file = fopen($localfilepath.$filename, 'w');
fwrite($file, imap_base64($content));
fclose($file);
}
}
?>