My solution (works with all types and charset) :
function format_html($str) {
// Convertit tous les caractères éligibles en entités HTML en convertissant les codes ASCII 10 en $lf
$str = htmlentities($str, ENT_COMPAT, "UTF-8");
$str = str_replace(chr(10), "<br>", $str);
return $str;
}
// Start
$obj_structure = imap_fetchstructure($imapLink, $obj_mail->msgno);
// Recherche de la section contenant le corps du message et extraction du contenu
$obj_section = $obj_structure;
$section = "1";
for ($i = 0 ; $i < 10 ; $i++) {
if ($obj_section->type == 0) {
break;
} else {
$obj_section = $obj_section->parts[0];
$section.= ($i > 0 ? ".1" : "");
}
}
$text = imap_fetchbody($imapLink, $obj_mail->msgno, $section);
// Décodage éventuel
if ($obj_section->encoding == 3) {
$text = imap_base64($text);
} else if ($obj_section->encoding == 4) {
$text = imap_qprint($text);
}
// Encodage éventuel
foreach ($obj_section->parameters as $obj_param) {
if (($obj_param->attribute == "charset") && (mb_strtoupper($obj_param->value) != "UTF-8")) {
$text = utf8_encode($text);
break;
}
}
// End
print format_html($text);