blob: ae7c0bdc2e6d84fb7a4624b97c1523b570438971 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{mimify} ---
Fred Drake0fbec551999-04-23 16:44:53 +00002 MIME processing of mail messages}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drake0fbec551999-04-23 16:44:53 +00004\declaremodule{standard}{mimify}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Mimification and unmimification of mail messages.}
6
Guido van Rossumfd16ca41997-07-30 22:05:07 +00007
8The mimify module defines two functions to convert mail messages to
9and from MIME format. The mail message can be either a simple message
10or a so-called multipart message. Each part is treated separately.
11Mimifying (a part of) a message entails encoding the message as
12quoted-printable if it contains any characters that cannot be
Fred Drake0fbec551999-04-23 16:44:53 +000013represented using 7-bit \ASCII. Unmimifying (a part of) a message
Guido van Rossumfd16ca41997-07-30 22:05:07 +000014entails undoing the quoted-printable encoding. Mimify and unmimify
15are especially useful when a message has to be edited before being
16sent. Typical use would be:
17
18\begin{verbatim}
19unmimify message
20edit message
21mimify message
22send message
23\end{verbatim}
24
25The modules defines the following user-callable functions and
26user-settable variables:
27
28\begin{funcdesc}{mimify}{infile, outfile}
29Copy the message in \var{infile} to \var{outfile}, converting parts to
30quoted-printable and adding MIME mail headers when necessary.
31\var{infile} and \var{outfile} can be file objects (actually, any
Fred Drake0fbec551999-04-23 16:44:53 +000032object 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 Rossumfd16ca41997-07-30 22:05:07 +000034If \var{infile} and \var{outfile} are both strings, they may have the
35same value.
36\end{funcdesc}
37
Fred Drake0fbec551999-04-23 16:44:53 +000038\begin{funcdesc}{unmimify}{infile, outfile\optional{, decode_base64}}
Guido van Rossumfd16ca41997-07-30 22:05:07 +000039Copy the message in \var{infile} to \var{outfile}, decoding all
40quoted-printable parts. \var{infile} and \var{outfile} can be file
Fred Drake0fbec551999-04-23 16:44:53 +000041objects (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 Rossumfd16ca41997-07-30 22:05:07 +000043naming the files. If \var{infile} and \var{outfile} are both strings,
44they may have the same value.
45If the \var{decode_base64} argument is provided and tests true, any
46parts that are coded in the base64 encoding are decoded as well.
47\end{funcdesc}
48
Guido van Rossumfcaf26e1997-08-14 14:13:01 +000049\begin{funcdesc}{mime_decode_header}{line}
50Return a decoded version of the encoded header line in \var{line}.
Fred Drake69d1fd22002-06-18 18:51:30 +000051This only supports the ISO 8859-1 charset (Latin-1).
Guido van Rossumfcaf26e1997-08-14 14:13:01 +000052\end{funcdesc}
53
54\begin{funcdesc}{mime_encode_header}{line}
55Return a MIME-encoded version of the header line in \var{line}.
56\end{funcdesc}
57
Guido van Rossumfd16ca41997-07-30 22:05:07 +000058\begin{datadesc}{MAXLEN}
59By default, a part will be encoded as quoted-printable when it
Fred Drake91f2f262001-07-06 19:28:48 +000060contains any non-\ASCII{} characters (characters with the 8th bit
Fred Drake0fbec551999-04-23 16:44:53 +000061set), or if there are any lines longer than \constant{MAXLEN} characters
Guido van Rossumfd16ca41997-07-30 22:05:07 +000062(default value 200).
63\end{datadesc}
64
65\begin{datadesc}{CHARSET}
66When not specified in the mail headers, a character set must be filled
Fred Drake0fbec551999-04-23 16:44:53 +000067in. The string used is stored in \constant{CHARSET}, and the default
Guido van Rossumfd16ca41997-07-30 22:05:07 +000068value is ISO-8859-1 (also known as Latin1 (latin-one)).
69\end{datadesc}
70
71This module can also be used from the command line. Usage is as
72follows:
73\begin{verbatim}
74mimify.py -e [-l length] [infile [outfile]]
75mimify.py -d [-b] [infile [outfile]]
76\end{verbatim}
77to encode (mimify) and decode (unmimify) respectively. \var{infile}
78defaults to standard input, \var{outfile} defaults to standard output.
79The same file can be specified for input and output.
80
Fred Drake0fbec551999-04-23 16:44:53 +000081If the \strong{-l} option is given when encoding, if there are any lines
Guido van Rossumfd16ca41997-07-30 22:05:07 +000082longer than the specified \var{length}, the containing part will be
83encoded.
84
Fred Drake0fbec551999-04-23 16:44:53 +000085If the \strong{-b} option is given when decoding, any base64 parts will
Guido van Rossumfd16ca41997-07-30 22:05:07 +000086be decoded as well.
87
Fred Drake005f4942000-04-04 20:42:38 +000088\begin{seealso}
89 \seemodule{quopri}{Encode and decode MIME quoted-printable files.}
90\end{seealso}