Internet Protocols Module User’s Guide : PART II Packages of the Internet Protocols Module : Chapter 10 MIME Package Advanced Topics : Transfer Encodings
Transfer Encodings
The Content-Transfer-Encoding of a MIME part describes how the data within the part body has been processed for transport (see “The Content-Transfer-Encoding Header”). This section describes each encoding in detail.
Identity Encodings
The 7bit, 8bit, and binary encoding values state that the body of the message hasn’t been encoded. In principle, there’s no need to process unencoded data at all. For convenience, the encode() and decode() functions of RWMimeUtils accept the values "7bit", "8bit", and "binary" as encoding types. When any of these three values is provided as an encoding type, both functions simply return the original string.
 
RWCString text = "Unencoded text”;
 
RWCString encoded = RWMimeUtils::encode(text,
RWMimeUtils::SevenBit);
 
assert(encoded == text); // Always true
Because unencoded values do not change the string provided, programs can safely call encode() and decode() with any MIME C-ontent‑Transfer‑Encoding value and receive the correct data.
Base 64 Encoding
Base 64 encoding, described in detail in RFC 2045, provides a simple way to translate binary data into an ASCII format suitable for use with the SMTP protocol. The encoding process generates four characters of encoded data for each three bytes of original data.
A base 64 encoder reads the byte sequence of the original data six bits at a time. Each six-bit value is encoded as one of 64 printable characters. After encoding, the encoder arranges the printable output in lines of 72 characters each. The result is a message that any RFC 822-compliant mail system can process without loss of data.
RWMimeUtils provides static utility functions, including a base 64 encoder. To encode data in base 64 format, use the encode() function with RWMimeUtils::Base64 as the second argument, for example:
 
RWCString binaryData;
 
// ... fill the RWCString with binary data
 
RWCString encoded = RWMimeUtils::encode(binaryData,
RWMimeUtils::Base64);
Likewise, to decode base 64 encoded data, use the decode() function from RWMimeUtils, as shown:
 
RWCString encoded;
 
// ... fill the RWCString with base 64 encoded data
 
RWCString binaryData = RWMimeUtils::decode(encoded,
RWMimeUtils::Base64);
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);