blob: 3a74cf8511b796dae55907328485e52fa868a453 [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
Raymond Hettinger05ce0792011-01-10 21:16:07 +000012**Source code:** :source:`Lib/quopri.py`
13
14--------------
15
Georg Brandl116aa622007-08-15 14:28:22 +000016This module performs quoted-printable transport encoding and decoding, as
17defined in :rfc:`1521`: "MIME (Multipurpose Internet Mail Extensions) Part One:
18Mechanisms for Specifying and Describing the Format of Internet Message Bodies".
19The quoted-printable encoding is designed for data where there are relatively
20few nonprintable characters; the base64 encoding scheme available via the
21:mod:`base64` module is more compact if there are many such characters, as when
22sending a graphics file.
23
Georg Brandl18244152009-09-02 20:34:52 +000024.. function:: decode(input, output, header=False)
Georg Brandl116aa622007-08-15 14:28:22 +000025
26 Decode the contents of the *input* file and write the resulting decoded binary
Senthil Kumaran99597c42014-06-25 01:12:03 -070027 data to the *output* file. *input* and *output* must be :term:`binary file objects
28 <file object>`. If the optional argument *header* is present and true, underscore
Antoine Pitrou11cb9612010-09-15 11:11:28 +000029 will be decoded as space. This is used to decode "Q"-encoded headers as
30 described in :rfc:`1522`: "MIME (Multipurpose Internet Mail Extensions)
31 Part Two: Message Header Extensions for Non-ASCII Text".
Georg Brandl116aa622007-08-15 14:28:22 +000032
33
Georg Brandl18244152009-09-02 20:34:52 +000034.. function:: encode(input, output, quotetabs, header=False)
Georg Brandl116aa622007-08-15 14:28:22 +000035
Senthil Kumaran99597c42014-06-25 01:12:03 -070036 Encode the contents of the *input* file and write the resulting quoted-
37 printable data to the *output* file. *input* and *output* must be
38 :term:`binary file objects <file object>`. *quotetabs*, a flag which controls
39 whether to encode embedded spaces and tabs must be provideda and when true it
40 encodes such embedded whitespace, and when false it leaves them unencoded.
41 Note that spaces and tabs appearing at the end of lines are always encoded,
42 as per :rfc:`1521`. *header* is a flag which controls if spaces are encoded
43 as underscores as per :rfc:`1522`.
Georg Brandl116aa622007-08-15 14:28:22 +000044
45
Georg Brandl18244152009-09-02 20:34:52 +000046.. function:: decodestring(s, header=False)
Georg Brandl116aa622007-08-15 14:28:22 +000047
Senthil Kumaran99597c42014-06-25 01:12:03 -070048 Like :func:`decode`, except that it accepts a source :class:`bytes` and
49 returns the corresponding decoded :class:`bytes`.
Georg Brandl116aa622007-08-15 14:28:22 +000050
51
Georg Brandl18244152009-09-02 20:34:52 +000052.. function:: encodestring(s, quotetabs=False, header=False)
Georg Brandl116aa622007-08-15 14:28:22 +000053
Senthil Kumaran99597c42014-06-25 01:12:03 -070054 Like :func:`encode`, except that it accepts a source :class:`bytes` and
55 returns the corresponding encoded :class:`bytes`. By default, it sends a
56 False value to *quotetabs* parameter of the :func:`encode` function.
57
Georg Brandl116aa622007-08-15 14:28:22 +000058
59
60.. seealso::
61
62 Module :mod:`base64`
63 Encode and decode MIME base64 data