質問

このコードがあります。 Zend Readingメールの例からです。

$message = $mail->getMessage(1);

// output first text/plain part
$foundPart = null;
foreach (new RecursiveIteratorIterator($mail->getMessage(1)) as $part) {
    try {
        if (strtok($part->contentType, ';') == 'text/plain') {
            $foundPart = $part;
            break;
        }
    } catch (Zend_Mail_Exception $e) {
        // ignore
    }
}
if (!$foundPart) {
    echo 'no plain text part found';
} else {
    echo $foundPart->getContent();
}

私が得ることができるのはメッセージです。しかし、メッセージを読み取り可能なものにデコードしようとしても機能しません。 Zend_Mime、imap_mime、iconvを試してみましたが、うまくいきませんでした。

これは $ foundPart-> getContent();

で得られるものの例です
  

Hall = F3 heim = FAr

"ホールó heimú r"

私が望むのは、「ボタンを押してベーコンを受け取る」ことができるライブラリだけです。実際には。つまり、ライブラリにPOP3メールボックスを指定し、(エンコードの問題なしで)読み取り可能な形式のメールと添付ファイルを取得するだけです。

imap_mime_header_decode()同じデータの配列を提供します。
iconv_ mime_ decode()同じことをします

誰がこれが起こっているのか、これを単に抽象化できるライブラリ(PHP / PythonまたはPerl)を知っていますか

役に立ちましたか?

解決

これは、base64エンコーディングが原因である可能性があります。 Zend_Mailのドキュメントには(「エンコード」の下)とあります:

  

...他のすべての添付ファイルはエンコードされます   他のエンコーディングがない場合、base64経由   addAttachment()呼び出しで指定されるか、   MIMEパーツオブジェクトに割り当てられます   後で。

次のようなものを試してください:

echo base64_decode($foundPart->getContent());

また、読む: http://framework.zend.com/manual/en/zend。 mail.encoding.html

何らかの形で助けてくれたことを願っています。

他のヒント

Zend_Mailを使用してメールを読む方法を学習しているときに、同様の問題に遭遇しました。エンコードされたメールのデコードや文字セットの変換など、Zend_Mailが実装していないロジックを追加する必要があります。プレーンテキスト部分を見つけた後、私がやっていることは次のとおりです。

$content = $foundPart->getContent();

switch ($foundPart->contentTransferEncoding) {
    case 'base64':
        $content = base64_decode($content);
        break;
    case 'quoted-printable':
        $content = quoted_printable_decode($content);
        break;
}

//find the charset
preg_match('/charset="(.+)"$/', $foundPart->contentType, $matches);
$charset = $matches[1];

if ($charset == 'iso-8859-1') {
    $content = utf8_encode($content); //convert to utf8
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top