如何使用Zend_Mail_Storage_Imap读取重音符号

时间:2012-03-24 10:36:16

标签: zend-framework email smtp

我正在尝试使用Zend_Mail_Storage_Imap阅读邮件。这是我的代码的一部分:

$mail = new Zend_Mail_Storage_Imap(
        array(  'host' =>'imap.gmail.com',
                'ssl' =>true,
                'port'=>993,
                'folder'=>'inbox',
                'user' => '***',
                'password' => '***' 
            )
        );


    foreach ($mail as $k => $message) {
             $msg = $mail->getMessage( $k );
             echo $msg->getContent();
    }

除了重音格式外,还有很好的工作。我有这样的事情:

int = C3 =整合的A9gration

对于sàrl,

S = C3 = A0rl *

有人能帮助我吗?

3 个答案:

答案 0 :(得分:2)

utf8_decode( quoted_printable_decode( $part->getContent() ))

答案 1 :(得分:1)

在这里查看“getText()”方法: http://wiip.fr/content/zend-mail-storage-imap

该文本是法语,但不要打扰并只将您需要的内容添加到此getText方法中。基本上你需要确定电子邮件的编码和解码它。

您还可以查看:Email decoding doesn't work in zend mail

答案 2 :(得分:0)

如果你使用utf-8内部编码,这是一个可能的解决方案。

/**
 * retrieves message content
 * @param Zend_Mail_Message|Zend_Mail_Part $oMessage
 * @return string returns message content as utf-8 string from message object
 */
public static function contentDecoder ($oMessage, $bVerbose = false) {
    mb_internal_encoding("UTF-8");
    echo ($bVerbose)?("\tultimateContentDecode {\n"):('');      
    if($oMessage->headerExists('content-type')) {
        echo ($bVerbose)?("\t\t" . $oMessage->contentType . "\n"):('');
        preg_match('/^([a-z\/]+)(?:;\s+format=[a-zA-Z0-9-]+)?(?:;\s+charset=([a-zA-Z0-9-]+))?/i', 
            str_replace('"', '', $oMessage->contentType), $matches);
        list(,$sMimeType,$sEncoding) = $matches;
        echo ($bVerbose)?("\t\tType of this part is {$sMimeType}, {$sEncoding}\n"):('');
    } else {
        $sContent = $oMessage->getContent();
        $sMimeType = 'text/plain';
        $sEncoding = mb_detect_encoding($sContent, self::$_sEncDetectOrder);
        echo ($bVerbose)?("\t\tUnknow content type. text/plain; charset={$sEncoding}\n"):('');
    }
    $sEncoding = strtoupper($sEncoding);
    if($oMessage->headerExists('content-transfer-encoding')) {
        $sQuoting = $oMessage->contentTransferEncoding;
        echo ($bVerbose)?("\t\tContent-Transfer-Encoding: " . $oMessage->contentTransferEncoding . "\n"):('');
    } else {
        $sQuoting = '';
    }
    $sContent = $oMessage->getContent();
    switch ($sQuoting) {
        case 'quoted-printable':
        case '7bit':
            $sContent = quoted_printable_decode($sContent);
            break;
        case 'base64':
            $sContent = base64_decode($sContent);
            break;
    }
    if ($sEncoding != 'UTF-8') {
        echo ($bVerbose)?("\t\tConvert encoding: {$sEncoding} -> UTF-8 \n"):('');
        $sContent = mb_convert_encoding($sContent, 'UTF-8', $sEncoding);
    }
    $sContent = trim(preg_replace(
            array('/^\s+/m', '/\s+$/m', '/[ \t]+/'),
            array('', '', ' '), $sContent));
    echo ($bVerbose)?("--\n{$sContent}\n--"):('');
    echo ($bVerbose)?("\t}\n"):('');
    return $sContent;
}