Writes a byte to the stream, adding dots where appropriate.
Also fixes any naked CR or LF to the RFC 2821 mandated CFLF
pairing.
switch (b) {
case '.":
if (countLast0A0D == 2) {
// add extra dot (the first of the pair)
out.write('.");
}
countLast0A0D = 0;
break;
case '\r":
if (countLast0A0D == 1) out.write('\n"); // two CR in a row, so insert an LF first
countLast0A0D = 1;
break;
case '\n":
/* RFC 2821 #2.3.7 mandates that line termination is
* CRLF, and that CR and LF must not be transmitted
* except in that pairing. If we get a naked LF,
* convert to CRLF.
*/
if (countLast0A0D != 1) out.write('\r");
countLast0A0D = 2;
break;
default:
// we're no longer at the start of a line
countLast0A0D = 0;
break;
}
out.write(b);