Postingan lainnya
Bagaimana mengatasi base64 yang gagal decode di imap php?
Bagaimana mengatasi content email yang gagal decode di imap php?
Beberapa berhasil decode, tapi beberapa ada yang gagal.
Berikut potongan program yang saya buat :
//controller
$conn = imap_open($host, $user, $password);
if (!$conn) {
$v['connInfo'] = '<strong>Unable to connect : </strong> '.imap_last_error();
imap_close($conn);
} else {
$v['connInfo'] = '';
$header = imap_headerinfo($conn, $email_id);
$overview = imap_fetch_overview($conn, $email_id, 0);
$structure = imap_fetchstructure($conn, $email_id);
$message = imap_fetchbody($conn, $email_id, 1);
$message = imap_binary($message);
if(isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) {
$part = $structure->parts[1];
print_r($part->encoding);
switch ($part->encoding) {
# 7BIT
case 0: $message = imap_qprint($message);
# 8BIT
case 1: $message = quoted_printable_decode(imap_8bit($message));
# BINARY
case 2: $message = imap_binary($message);
# BASE64
case 3: $message = imap_base64($message); //$message = base64_decode($message);
# QUOTED-PRINTABLE
case 4: $message = quoted_printable_decode($message);
# OTHER
case 5: $message = $message;
# UNKNOWN
default: $message = $message;
}
}
$v['message'] = $message;
imap_close($conn);
}
//view
<div class="panel-body">
<?php
if (base64_decode($message, true)) {
$message = base64_decode($message);
echo nl2br($message);
} else {
echo nl2br($message);
}
?>
</div>
Contoh content email yang gagal decode :
1. Contoh 1
imap01.PNG
2. Contoh 2
imap02.PNG
3. Contoh 3
imap03.PNG
Ketiga contoh email tersebut berasal dari email yang berbeda.
Terimakasih
1 Jawaban:
<div>kenapa $message harus di-convert dl ke base64 ya via imap_binary($message)?<br><br>decryption imap setelah imap_fetchbody langsung masuk ke switch aja:<br><br><br></div><pre>switch ($part->encoding) { # 8BIT case 1: $message = quoted_printable_decode(imap_8bit($message)); break; # BINARY case 2: $message = imap_binary($message); # BASE64 break; case 3: $message = imap_base64($message); break; # QUOTED-PRINTABLE case 4: $message = quoted_printable_decode($message); break; # Skip 7BIT, OTHER & UNKNOWN }</pre>
Tanggapan
cara ini sudah saya coba ga work jg, kalau convert ke binary dulu beberapa berhasil convert tapi tidak semua