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