Hey guys,
Posted this elsewhere also, but looking for a resolution to my problem as quickly as I can.
I've been developing a bespoke "helpdesk" system for work and, while it works well on the whole, I am having major problems with base64 encoded email bodies.
Admittedly, this might be due to my misunderstanding of imap body parts. It seems in my current setup, the system thinks that all mails are either "type" 0 or 4. As a result, base64 emails don't get decoded and display as an unreadable long string.
Here is what my code for the body decoding looks like just now - can provide more on request.
Initially, I have the following four statements
$overview=imap_fetch_overview($map,$mailno, 0);
$body=imap_fetchbody($map,$mailno,1);
$header=imap_header($map,$mailno);
$structure=imap_fetchstructure($map, $mailno);
Here is I try to work with different encodings - unsuccessfully.
if($structure->encoding == 0){
$arr1=array("=A3", "=80");
$arr2=array("£", "€");
$newcontent=$explodeunder[0];
define("CHARSET", "ISO-8859-1");
$dbcontenta=str_replace($arr1, $arr2, $newcontent);
$r=mb_detect_encoding($dbcontenta);
if($r=="UTF-8"){
$dbcontents=mb_convert_encoding($dbcontenta, "ISO-8859-1", "UTF-8");
$dbcontent1=addslashes($dbcontents);
$dbcontent2=strip_tags($dbcontent1);
}
elseif($r=="ASCII"){
$dbcontentb=mb_convert_encoding($dbcontenta, "UTF-8", "ASCII");
$dbcontents=mb_convert_encoding($dbcontentb, "ISO-8859-1", "UTF-8");
$dbcontent1=addslashes($dbcontents);
$dbcontentf=strip_tags($dbcontent1);
$dbcontent2=quoted_printable_decode($dbcontentf);
}
} elseif($structure->encoding == 4) {
$dbcontent=$explodeunder[0];
$dbcontentf=quoted_printable_decode($dbcontent);
$dbcontent2=mb_convert_encoding($dbcontentf, "ISO-8859-1", "UTF-8");
}
elseif($structure->encoding == 3) {
$dbcontent2=imap_base64($explodeunder[0]);
} elseif($structure->encoding == 1){
$dbcontent3=imap_8bit($explodeunder[0]);
$dbcontent2=quoted_printable_decode($dbcontent3);
}
Any help on this would be massively appreciated, as it's causing me all sorts of headaches!
Many Thanks