2016-12-07 2 views
0

다음 코드를 PHP IMAP decoding messages에서 복사했지만 아직 구현에 어려움이 있습니다. 이것은 내가 이것을 구현하는 방법입니다 다음 getEncodingType 호출이 항상 텍스트를 표시 할 때 문제가 발생하고 쓰레기를 보여줍니다 7 비트 같은 형식을 반환 어떤 이유로PHP Imap Body 디코드 문제

public function readMessage($imap,$email_number){ 

    $message['header'] = imap_headerinfo($imap,$email_number,0); 
    $message['overview'] = imap_fetch_overview($imap,$email_number,0); 
    //$message['body'] = imap_fetchbody($imap,$email_number,2); 

    // Get the message body. 
    $body = imap_fetchbody($imap, $email_number, 1.2); 
    if (!strlen($body) > 0) { 
     $body = imap_fetchbody($imap, $email_number, 1); 
    } 

    // Get the message body encoding. 
    $encoding = $this->getEncodingType($imap,$email_number); 

    // Decode body into plaintext (8bit, 7bit, and binary are exempt). 
    if ($encoding == 'BASE64') { 
     $message['body'] = $this->decodeBase64($body); 
    } 
    elseif ($encoding == 'QUOTED-PRINTABLE') { 
     $message['body'] = $this->decodeQuotedPrintable($body); 
    } 
    elseif ($encoding == '8BIT') { 
     $message['body'] = $this->decode8Bit($body); 
    } 
    elseif ($encoding == '7BIT') { 
     $message['body'] = $this->decode7Bit($body); 
    } 

    return $message; 
} 

.

public function getEncodingType($imap, $messageId, $numeric = false) { 
    // See imap_fetchstructure() documentation for explanation. 
    $encodings = array(
     0 => '7BIT', 
     1 => '8BIT', 
     2 => 'BINARY', 
     3 => 'BASE64', 
     4 => 'QUOTED-PRINTABLE', 
     5 => 'OTHER', 
    ); 
    // Get the structure of the message. 
    $structure = $this->getStructure($imap, $messageId); 
    // Return a number or a string, depending on the $numeric value. 
    if ($numeric) { 
     return $structure->encoding; 
    } else { 
     return $encodings[$structure->encoding]; 
    } 
} 

당신은 아마도 내가 잘못하고 있어요 몇 가지를 지적 할 수 다음은 그 기능은 무엇입니까?

+0

죄송합니다. 내 대답을 업데이트했습니다. 다시 한번 확인해보십시오. – mertyildiran

답변

0

사용 imap_qprint : 내 고등학교 년에서였다 바보 변수 이름에 대한

<?php 

$header = imap_header($imap, $email_number); 
$from = $header->from; 
$print_sender = $from[0]->personal; 
$print_check = $print_sender[0]->charset; 

$bodymsg = imap_qprint(imap_fetchbody($imap, $email_number, 1.2)); 

if (empty($bodymsg)) { 
    $bodymsg = imap_qprint(imap_fetchbody($imap, $email_number, 1)); 
} 

if($print_check == "ISO-8859-9") { 
    $print_sender = mb_convert_encoding($print_sender, "UTF-8", "ISO-8859-9");//Encoding process 
    $bodymsg = mb_convert_encoding($bodymsg, "UTF-8", "ISO-8859-9");//Encoding process 
} 

echo $print_sender; 
echo $bodymsg; 

?> 
+0

고맙습니다. 코드가 내용을 변환하지만 서식을 유지하지 않습니다. 텍스트로만 변환됩니다. – LeRoux

+0

아마도 부분적으로 1.2가 아닙니다 :) – Max

+0

@LeRoux'mb_convert_encoding' 부분을 포함하지 않으시겠습니까? – mertyildiran