blob: a3f94a0ad0668ac3f25914d2dea8044c51b3e572 [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
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04007**Source code:** :source:`Lib/quopri.py`
Georg Brandl116aa622007-08-15 14:28:22 +00008
9.. index::
10 pair: quoted-printable; encoding
11 single: MIME; quoted-printable encoding
12
Raymond Hettinger05ce0792011-01-10 21:16:07 +000013--------------
14
Georg Brandl116aa622007-08-15 14:28:22 +000015This module performs quoted-printable transport encoding and decoding, as
16defined in :rfc:`1521`: "MIME (Multipurpose Internet Mail Extensions) Part One:
17Mechanisms for Specifying and Describing the Format of Internet Message Bodies".
18The quoted-printable encoding is designed for data where there are relatively
19few nonprintable characters; the base64 encoding scheme available via the
20:mod:`base64` module is more compact if there are many such characters, as when
21sending a graphics file.
22
Georg Brandl18244152009-09-02 20:34:52 +000023.. function:: decode(input, output, header=False)
Georg Brandl116aa622007-08-15 14:28:22 +000024
25 Decode the contents of the *input* file and write the resulting decoded binary
Senthil Kumaran99597c42014-06-25 01:12:03 -070026 data to the *output* file. *input* and *output* must be :term:`binary file objects
27 <file object>`. If the optional argument *header* is present and true, underscore
Antoine Pitrou11cb9612010-09-15 11:11:28 +000028 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
Georg Brandl18244152009-09-02 20:34:52 +000033.. function:: encode(input, output, quotetabs, header=False)
Georg Brandl116aa622007-08-15 14:28:22 +000034
Martin Panter8f137832017-01-14 08:24:20 +000035 Encode the contents of the *input* file and write the resulting quoted-printable
36 data to the *output* file. *input* and *output* must be
Senthil Kumaran99597c42014-06-25 01:12:03 -070037 :term:`binary file objects <file object>`. *quotetabs*, a flag which controls
38 whether to encode embedded spaces and tabs must be provideda and when true it
39 encodes such embedded whitespace, and when false it leaves them unencoded.
40 Note that spaces and tabs appearing at the end of lines are always encoded,
41 as per :rfc:`1521`. *header* is a flag which controls if spaces are encoded
42 as underscores as per :rfc:`1522`.
Georg Brandl116aa622007-08-15 14:28:22 +000043
44
Georg Brandl18244152009-09-02 20:34:52 +000045.. function:: decodestring(s, header=False)
Georg Brandl116aa622007-08-15 14:28:22 +000046
Senthil Kumaran99597c42014-06-25 01:12:03 -070047 Like :func:`decode`, except that it accepts a source :class:`bytes` and
48 returns the corresponding decoded :class:`bytes`.
Georg Brandl116aa622007-08-15 14:28:22 +000049
50
Georg Brandl18244152009-09-02 20:34:52 +000051.. function:: encodestring(s, quotetabs=False, header=False)
Georg Brandl116aa622007-08-15 14:28:22 +000052
Senthil Kumaran99597c42014-06-25 01:12:03 -070053 Like :func:`encode`, except that it accepts a source :class:`bytes` and
54 returns the corresponding encoded :class:`bytes`. By default, it sends a
Serhiy Storchaka4adf01c2016-10-19 18:30:05 +030055 ``False`` value to *quotetabs* parameter of the :func:`encode` function.
Senthil Kumaran99597c42014-06-25 01:12:03 -070056
Georg Brandl116aa622007-08-15 14:28:22 +000057
58
59.. seealso::
60
61 Module :mod:`base64`
62 Encode and decode MIME base64 data