encodeText method
Encodes the specified text in quoted printable format.
text
specifies the text to be encoded.
codec
the optional codec, which defaults to utf8.
Set wrap
to false in case you do not want to wrap lines.
Implementation
@override
String encodeText(final String text,
{Codec codec = MailCodec.encodingUtf8, bool wrap = true}) {
final buffer = StringBuffer();
final runes = List.from(text.runes);
final runeCount = runes.length;
var lineCharacterCount = 0;
for (var i = 0; i < runeCount; i++) {
var rune = runes[i];
if ((rune >= 32 && rune <= 60) ||
(rune >= 62 && rune <= 126) ||
rune == 9) {
buffer.writeCharCode(rune);
lineCharacterCount++;
} else {
if (i < runeCount - 1 &&
rune == AsciiRunes.runeCarriageReturn &&
runes[i + 1] == AsciiRunes.runeLineFeed) {
buffer.write('\r\n');
i++;
lineCharacterCount = 0;
} else if (rune == AsciiRunes.runeLineFeed) {
buffer.write('\r\n');
lineCharacterCount = 0;
} else {
//TODO some characters consist of more than a single rune
lineCharacterCount += _writeQuotedPrintable(rune, buffer, codec);
}
}
if (wrap && lineCharacterCount >= MailConventions.textLineMaxLength - 1) {
buffer.write('=\r\n'); // soft line break
lineCharacterCount = 0;
}
}
return buffer.toString();
}