19.9. quopri --- MIME quoted-printable 形式データのエンコードおよびデコード

ソースコード: Lib/quopri.py


このモジュールは RFC 1521: "MIME (Multipurpose Internet Mail Extensions) Part One: Mechanisms for Specifying and Describing the Format of Internet Message Bodies" で定義されている quoted-printable による伝送のエンコードおよびデコードを行います。 quoted-printable エンコーディングは比較的印字不可能な文字の少ないデータのために設計されています; 画像ファイルを送るときのように印字不可能な文字がたくさんある場合には、 base64 モジュールで利用できる base64 エンコーディングのほうがよりコンパクトになります。

quopri.decode(input, output, header=False)

ファイル input の内容をデコードして、デコードされたバイナリデータをファイル output に書き出します。 input および outputバイナリファイルオブジェクト でなければなりません。オプション引数 header が存在し、かつその値が真である場合、アンダースコアは空白文字にデコードされます。これは RFC 1522: "MIME (Multipurpose Internet Mail Extensions) Part Two: Message Header Extensions for Non-ASCII Text" で記述されているところの "Q"-エンコードされたヘッダをデコードするのに使われます。

quopri.encode(input, output, quotetabs, header=False)

Encode the contents of the input file and write the resulting quoted-printable data to the output file. input and output must be binary file objects. quotetabs, a flag which controls whether to encode embedded spaces and tabs must be provideda and when true it encodes such embedded whitespace, and when false it leaves them unencoded. Note that spaces and tabs appearing at the end of lines are always encoded, as per RFC 1521. header is a flag which controls if spaces are encoded as underscores as per RFC 1522.

quopri.decodestring(s, header=False)

decode() に似ていますが、ソース bytes を受け取り、対応するデコードされた bytes を返します。

quopri.encodestring(s, quotetabs=False, header=False)

encode() に似ていますが、ソース bytes を受け取り、対応するエンコードされた bytes を返します。 デフォルトでは、 encode() 関数の quotetabs パラメータに False を渡します。

参考

base64 モジュール
MIME base64 形式データのエンコードおよびデコード