18.9. mimify — MIME processing of mail messages - Python 2.7.18 documentation 编辑

Deprecated since version 2.3: The email package should be used in preference to the mimify module. This module is present only to maintain backward compatibility.

The mimify module defines two functions to convert mail messages to and from MIME format. The mail message can be either a simple message or a so-called multipart message. Each part is treated separately. Mimifying (a part of) a message entails encoding the message as quoted-printable if it contains any characters that cannot be represented using 7-bit ASCII. Unmimifying (a part of) a message entails undoing the quoted-printable encoding. Mimify and unmimify are especially useful when a message has to be edited before being sent. Typical use would be:

unmimify message
edit message
mimify message
send message

The modules defines the following user-callable functions and user-settable variables:

mimify.mimify(infile, outfile)

Copy the message in infile to outfile, converting parts to quoted-printable and adding MIME mail headers when necessary. infile and outfile can be file objects (actually, any object that has a readline() method (for infile) or a write() method (for outfile)) or strings naming the files. If infile and outfile are both strings, they may have the same value.

mimify.unmimify(infile, outfile[, decode_base64])

Copy the message in infile to outfile, decoding all quoted-printable parts. infile and outfile can be file objects (actually, any object that has a readline() method (for infile) or a write() method (for outfile)) or strings naming the files. If infile and outfile are both strings, they may have the same value. If the decode_base64 argument is provided and tests true, any parts that are coded in the base64 encoding are decoded as well.

mimify.mime_decode_header(line)

Return a decoded version of the encoded header line in line. This only supports the ISO 8859-1 charset (Latin-1).

mimify.mime_encode_header(line)

Return a MIME-encoded version of the header line in line.

mimify.MAXLEN

By default, a part will be encoded as quoted-printable when it contains any non-ASCII characters (characters with the 8th bit set), or if there are any lines longer than MAXLEN characters (default value 200).

mimify.CHARSET

When not specified in the mail headers, a character set must be filled in. The string used is stored in CHARSET, and the default value is ISO-8859-1 (also known as Latin1 (latin-one)).

This module can also be used from the command line. Usage is as follows:

mimify.py -e [-l length] [infile [outfile]]
mimify.py -d [-b] [infile [outfile]]

to encode (mimify) and decode (unmimify) respectively. infile defaults to standard input, outfile defaults to standard output. The same file can be specified for input and output.

If the -l option is given when encoding, if there are any lines longer than the specified length, the containing part will be encoded.

If the -b option is given when decoding, any base64 parts will be decoded as well.

See also

Module quopri

Encode and decode MIME quoted-printable files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:38 次

字数:4206

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文