I\'m looking for a way to download the whole raw email data (including attachment), similar to what you get by clicking \"Show Original\" in Gmail.
Currently, I can get
A common mistake is to use "\n" or PHP_EOL.
According to RFC RFC821, RFC2060, RFC1939 "\r\n" should be used.
While some mailserver auto convert that mistakes, Cyrus does not and throw a nice error.
PHP_EOL is a system depending constant, it's "\n" on Linux, "\r" on Mac and "\r\n" on Windows, for example.
Furthermore imap_fetchheader() contains the trailing "\r\n" as expected. So the correct example would be:
$source = imap_fetchheader($conn, $msg->msgno) . imap_body($conn, $msg->msgno);