1 :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 **Source code:** :source:`Lib/quopri.py` 8 9 .. index:: 10 pair: quoted-printable; encoding 11 single: MIME; quoted-printable encoding 12 13 -------------- 14 15 This module performs quoted-printable transport encoding and decoding, as 16 defined in :rfc:`1521`: "MIME (Multipurpose Internet Mail Extensions) Part One: 17 Mechanisms for Specifying and Describing the Format of Internet Message Bodies". 18 The quoted-printable encoding is designed for data where there are relatively 19 few nonprintable characters; the base64 encoding scheme available via the 20 :mod:`base64` module is more compact if there are many such characters, as when 21 sending a graphics file. 22 23 .. function:: decode(input, output, header=False) 24 25 Decode the contents of the *input* file and write the resulting decoded binary 26 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 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". 31 32 33 .. function:: encode(input, output, quotetabs, header=False) 34 35 Encode the contents of the *input* file and write the resulting quoted-printable 36 data to the *output* file. *input* and *output* must be 37 :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`. 43 44 45 .. function:: decodestring(s, header=False) 46 47 Like :func:`decode`, except that it accepts a source :class:`bytes` and 48 returns the corresponding decoded :class:`bytes`. 49 50 51 .. function:: encodestring(s, quotetabs=False, header=False) 52 53 Like :func:`encode`, except that it accepts a source :class:`bytes` and 54 returns the corresponding encoded :class:`bytes`. By default, it sends a 55 ``False`` value to *quotetabs* parameter of the :func:`encode` function. 56 57 58 59 .. seealso:: 60 61 Module :mod:`base64` 62 Encode and decode MIME base64 data 63