Here is a code which downloads attachment files from the an imap server. Almost all file types (pdf, doc, xls, etc) are being downloaded correctly, where as some zip files g
The culprit was imap_base64. It was not decoding the data correctly. I replaced it with base64_decode as follows and the code worked fine.
$body = base64_encode($data);