Quoted-Printable Encoding
Quoted-printable encoding, described in detail in RFC 2045, provides a simple way to convert text into a format that is safe for delivery through SMTP applications. The encoding preserves many human readable characters, providing a way to encode messages that are primarily text. A message encoded in quoted-printable encoding consists entirely of 7-bit ASCII characters arranged in lines no more than 76 characters long.
A quoted-printable encoder escapes characters outside of the normal ASCII character set, non-printing characters, and some whitespace characters. Some other characters (notably punctuation marks) may also be escaped to ensure accurate transmission by non-ASCII systems. Line breaks, however, are not encoded. Therefore, quoted-printable encoding is only useful for text. Since the encoding does not protect a message against line-break translation during transmission, quoted‑printable encoding cannot guarantee accurate delivery of binary data.
The format of a quoted-printable message is simple. The encoder converts any character that must be escaped to an equal sign (=) followed by the character’s ASCII value in hexadecimal. For example, a VT character (ASCII value 11) is represented as =0B and a DEL character (ASCII value 127) is represented as =7F. If a TAB or SPACE character falls at the end of a line, a soft line break (=, ASCII 10, ASCII 13) is added after the TAB or SPACE. Once the entire message is escaped, the encoder adds line breaks so that no line of the message is longer than 76 characters. Each line break the encoder adds is preceded by a single = character.
RWMimeUtils provides static utility functions, including a quoted-printable encoder. To encode data in quoted-printable format, use encode() function with RWMimeUtils::QuotedPrintable as the second argument, for example:
RWCString text;
// ... fill the RWCString with text
RWCString encoded = RWMimeUtils::encode(text,
RWMimeUtils::QuotedPrintable);
Likewise, to decode quoted-printable encoded data, use the
decode() function from
RWMimeUtils, as shown:
RWCString encoded;
// ... fill the RWCString with quoted-printable format data
RWCString text = RWMimeUtils::decode(encoded,
RWMimeUtils::QuotedPrintable);