Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1 | |
| 2 | :mod:`mimify` --- MIME processing of mail messages |
| 3 | ================================================== |
| 4 | |
| 5 | .. module:: mimify |
| 6 | :synopsis: Mimification and unmimification of mail messages. |
| 7 | |
| 8 | |
| 9 | .. deprecated:: 2.3 |
| 10 | The :mod:`email` package should be used in preference to the :mod:`mimify` |
| 11 | module. This module is present only to maintain backward compatibility. |
| 12 | |
| 13 | The :mod:`mimify` module defines two functions to convert mail messages to and |
| 14 | from MIME format. The mail message can be either a simple message or a |
| 15 | so-called multipart message. Each part is treated separately. Mimifying (a part |
| 16 | of) a message entails encoding the message as quoted-printable if it contains |
| 17 | any characters that cannot be represented using 7-bit ASCII. Unmimifying (a |
| 18 | part of) a message entails undoing the quoted-printable encoding. Mimify and |
| 19 | unmimify are especially useful when a message has to be edited before being |
| 20 | sent. Typical use would be:: |
| 21 | |
| 22 | unmimify message |
| 23 | edit message |
| 24 | mimify message |
| 25 | send message |
| 26 | |
| 27 | The modules defines the following user-callable functions and user-settable |
| 28 | variables: |
| 29 | |
| 30 | |
| 31 | .. function:: mimify(infile, outfile) |
| 32 | |
| 33 | Copy the message in *infile* to *outfile*, converting parts to quoted-printable |
| 34 | and adding MIME mail headers when necessary. *infile* and *outfile* can be file |
| 35 | objects (actually, any object that has a :meth:`readline` method (for *infile*) |
| 36 | or a :meth:`write` method (for *outfile*)) or strings naming the files. If |
| 37 | *infile* and *outfile* are both strings, they may have the same value. |
| 38 | |
| 39 | |
| 40 | .. function:: unmimify(infile, outfile[, decode_base64]) |
| 41 | |
| 42 | Copy the message in *infile* to *outfile*, decoding all quoted-printable parts. |
| 43 | *infile* and *outfile* can be file objects (actually, any object that has a |
| 44 | :meth:`readline` method (for *infile*) or a :meth:`write` method (for |
| 45 | *outfile*)) or strings naming the files. If *infile* and *outfile* are both |
| 46 | strings, they may have the same value. If the *decode_base64* argument is |
| 47 | provided and tests true, any parts that are coded in the base64 encoding are |
| 48 | decoded as well. |
| 49 | |
| 50 | |
| 51 | .. function:: mime_decode_header(line) |
| 52 | |
| 53 | Return a decoded version of the encoded header line in *line*. This only |
| 54 | supports the ISO 8859-1 charset (Latin-1). |
| 55 | |
| 56 | |
| 57 | .. function:: mime_encode_header(line) |
| 58 | |
| 59 | Return a MIME-encoded version of the header line in *line*. |
| 60 | |
| 61 | |
| 62 | .. data:: MAXLEN |
| 63 | |
| 64 | By default, a part will be encoded as quoted-printable when it contains any |
| 65 | non-ASCII characters (characters with the 8th bit set), or if there are any |
| 66 | lines longer than :const:`MAXLEN` characters (default value 200). |
| 67 | |
| 68 | |
| 69 | .. data:: CHARSET |
| 70 | |
| 71 | When not specified in the mail headers, a character set must be filled in. The |
| 72 | string used is stored in :const:`CHARSET`, and the default value is ISO-8859-1 |
| 73 | (also known as Latin1 (latin-one)). |
| 74 | |
| 75 | This module can also be used from the command line. Usage is as follows:: |
| 76 | |
| 77 | mimify.py -e [-l length] [infile [outfile]] |
| 78 | mimify.py -d [-b] [infile [outfile]] |
| 79 | |
| 80 | to encode (mimify) and decode (unmimify) respectively. *infile* defaults to |
| 81 | standard input, *outfile* defaults to standard output. The same file can be |
| 82 | specified for input and output. |
| 83 | |
| 84 | If the **-l** option is given when encoding, if there are any lines longer than |
| 85 | the specified *length*, the containing part will be encoded. |
| 86 | |
| 87 | If the **-b** option is given when decoding, any base64 parts will be decoded as |
| 88 | well. |
| 89 | |
| 90 | |
| 91 | .. seealso:: |
| 92 | |
| 93 | Module :mod:`quopri` |
| 94 | Encode and decode MIME quoted-printable files. |
| 95 | |