5

テキスト メール メッセージの本文が base64 でエンコードされているかどうかを判断するのに苦労しています。その場合は、このコード行を使用します。jython 2.2.1を利用する

dirty=base64.decodebytes(dirty)

それ以外は通常どおり続行します。

これは私が持っているコードです。電子メールからこれを抽出できるコード行は次のとおりです。

「コンテンツ転送エンコーディング: base64」

import email, email.Message
import base64

def _get_email_body(self):
    try:
        parts=self._email.get_payload()
        check=parts[0].get_content_type()
        if check=="text/plain":
            part=parts[0].get_payload()
            enc = part[0]['Content-Transfer-Encoding']
            if enc == "base64":
                dirty=base64.decodebytes(dirty)
        elif check=="multipart/alternative":
            part=parts[0].get_payload()
            enc = part[0]['Content-Transfer-Encoding']
            if part[0].get_content_type()=="text/plain":
                dirty=part[0].get_payload()
                if enc == "base64":
                    dirty=base64.decodebytes(dirty)
            else:
                return "cannot obtain the body of the email"
        else:
            return "cannot obtain the body of the email"
        return dirty
    except:
        raise

OKAY このコードは今すぐ動作します! 皆さんありがとう

4

2 に答える 2

6

試す:

enc = msg['Content-Transfer-Encoding']

これはヘッダーなので、本文を見てもわかりません。対象を見つけたのと同じ場所にたどり着けるはずです。

于 2008-11-28T02:44:04.760 に答える