1
내 웹 응용 프로그램 용 메일 모듈을 만들고 있습니다. 내 현재 시점에서 메일 본문을 가져오고 올바르게 디코딩하려고합니다. 그러나 메일에서 국제 문자를 발견하면 올바르게 디코딩하지 않습니다.php imap 메일 본문 인코딩
ex.
--001a11c126f6bd3aa804f575bd85 Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable ss -- s Niels S=F8nderb=E6k --001a11c126f6bd3aa804f575bd85
Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
ss
-- s
Ni= els S=F8nderb=E6k
--001a11c126f6bd3aa804f575bd85--
이 디코딩 후 결과는 다음과 같습니다 :
ss
-- s
Niels S�nderb�k
Niels S�nderb�k
는 Niels Sønderbæk
해야 내가 원시 이메일 본문이있다. 국제 문자를 다룰 때는이 문제 만 보았습니다. 아무도 그것을 고칠 줄 알아? 아래에 내 디코딩 코드가 포함되었습니다. 그것은 http://www.sitepoint.com/exploring-phps-imap-library-1/에서 가져 왔습니다.
<?php
$imap = imap_open(...);
$uid = ...
function getBody($uid, $imap) {
$body = get_part($imap, $uid, "TEXT/HTML");
// if HTML body is empty, try getting text body
if ($body == "") {
$body = get_part($imap, $uid, "TEXT/PLAIN");
}
return $body;
}
function get_part($imap, $uid, $mimetype, $structure = false, $partNumber = false) {
if (!$structure) {
$structure = imap_fetchstructure($imap, $uid, FT_UID);
}
if ($structure) {
if ($mimetype == get_mime_type($structure)) {
if (!$partNumber) {
$partNumber = 1;
}
$text = imap_fetchbody($imap, $uid, $partNumber, FT_UID);
switch ($structure->encoding) {
case 3: return imap_base64($text);
case 4: return imap_qprint($text);
default: return imap_utf8($text);
}
}
// multipart
if ($structure->type == 1) {
foreach ($structure->parts as $index => $subStruct) {
$prefix = "";
if ($partNumber) {
$prefix = $partNumber . ".";
}
$data = get_part($imap, $uid, $mimetype, $subStruct, $prefix . ($index + 1));
if ($data) {
return $data;
}
}
}
}
return false;
}
function get_mime_type($structure) {
$primaryMimetype = array("TEXT", "MULTIPART", "MESSAGE", "APPLICATION", "AUDIO", "IMAGE", "VIDEO", "OTHER");
if ($structure->subtype) {
return $primaryMimetype[(int)$structure->type] . "/" . $structure->subtype;
}
return "TEXT/PLAIN";
}
echo getBody($uid,$imap);
?>
어떻게하면됩니까? –