blob: a64337ef7c06d8b220d40bca04c485d0642fe1b7 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2:mod:`quopri` --- Encode and decode MIME quoted-printable data
3==============================================================
4
5.. module:: quopri
6 :synopsis: Encode and decode files using the MIME quoted-printable encoding.
7
8
9.. index::
10 pair: quoted-printable; encoding
11 single: MIME; quoted-printable encoding
12
13This module performs quoted-printable transport encoding and decoding, as
14defined in :rfc:`1521`: "MIME (Multipurpose Internet Mail Extensions) Part One:
15Mechanisms for Specifying and Describing the Format of Internet Message Bodies".
16The quoted-printable encoding is designed for data where there are relatively
17few nonprintable characters; the base64 encoding scheme available via the
18:mod:`base64` module is more compact if there are many such characters, as when
19sending a graphics file.
20
21
22.. function:: decode(input, output[,header])
23
24 Decode the contents of the *input* file and write the resulting decoded binary
Antoine Pitrou25d535e2010-09-15 11:25:11 +000025 data to the *output* file. *input* and *output* must be :term:`file objects
26 <file object>`. *input* will be read until ``input.readline()`` returns an
27 empty string. If the optional argument *header* is present and true, underscore
28 will be decoded as space. This is used to decode "Q"-encoded headers as
29 described in :rfc:`1522`: "MIME (Multipurpose Internet Mail Extensions)
30 Part Two: Message Header Extensions for Non-ASCII Text".
Georg Brandl116aa622007-08-15 14:28:22 +000031
32
33.. function:: encode(input, output, quotetabs)
34
35 Encode the contents of the *input* file and write the resulting quoted-printable
Antoine Pitrou25d535e2010-09-15 11:25:11 +000036 data to the *output* file. *input* and *output* must be :term:`file objects
37 <file object>`. *input* will be read until ``input.readline()`` returns an
38 empty string. *quotetabs* is a flag which controls whether to encode embedded
39 spaces and tabs; when true it encodes such embedded whitespace, and when
40 false it leaves them unencoded. Note that spaces and tabs appearing at the
41 end of lines are always encoded, as per :rfc:`1521`.
Georg Brandl116aa622007-08-15 14:28:22 +000042
43
44.. function:: decodestring(s[,header])
45
46 Like :func:`decode`, except that it accepts a source string and returns the
47 corresponding decoded string.
48
49
50.. function:: encodestring(s[, quotetabs])
51
52 Like :func:`encode`, except that it accepts a source string and returns the
53 corresponding encoded string. *quotetabs* is optional (defaulting to 0), and is
54 passed straight through to :func:`encode`.
55
56
57.. seealso::
58
59 Module :mod:`base64`
60 Encode and decode MIME base64 data
61