Sets the lookup table that determines how characters are encoded.
The lookup table that determines how characters are encoded.
The encode map serves as a lookup table for the encoder,
determining how characters (that is, bytes or 8-bit characters) are
encoded. Two encode maps, LowRiskEncodeMap
and HighRiskEncodeMap, are provided as class
fields. By setting a user-defined encode map, you can precisely
specify the characters that the encoder will encode using the hex
encoding.
The default is LowRiskEncodeMap.
An encode map must be a byte array of at least 256 bytes. Each
of the first 256 bytes in the array must have a value of
Safe, Unsafe, or Special. If a byte is set to
Unsafe, then the corresponding character will be encoded
using the hex encoding. If a byte is set to Safe, then the
corresponding character will not be encoded. The value
Special may be used only for CR or LF.
The following code example shows how to create and set an encode map that encodes all characters except CR, LF, the digits, and the letters:
byte[] myEncodeMap = new byte[256];
// First, set all entries to Unsafe
int i;
for (i = 0; i < 256; ++i) {
myEncodeMap[i] = QuotedPrintableEncoder.Unsafe;
}
// Set CR and LF to Special
myEncodeMap[10] = QuotedPrintableEncoder.Special;
myEncodeMap[13] = QuotedPrintableEncoder.Special;
// Set all digits to Safe
for (i = 48; i < 58; ++i) {
myEncodeMap[i] = QuotedPrintableEncoder.Safe;
}
// Set upper-case letters to Safe
for (i = 65; i < 91; ++i) {
myEncodeMap[i] = QuotedPrintableEncoder.Safe;
}
// Set lower-case letters to Safe
for (i = 97; i < 123; ++i) {
myEncodeMap[i] = QuotedPrintableEncoder.Safe;
}
encoder.EncodeMap = myEncodeMap;
One possibility that is allowed by setting a user-defined encode map is that you can encode arbitrary binary data. Normally, the quoted-printable encoding is not a good choice for encoding binary data, because the CR LF sequence (or sometimes just LF) is treated as a hard-line break. (This is bad because most binary file formats -- image or sound files, for instance -- don't have line breaks.) Therefore, you can cause the encoder to encode CR and LF using the hex encoding. You do this by setting a user-defined encode map that has the entries for CR (13) and LF (10) set to Unsafe.
QuotedPrintableEncoder Class | Hunny.Mime Namespace