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