/// <summary>
/// Does period handling.
/// </summary>
/// <param name="strm">Input stream.</param>
/// <param name="add_Remove">If true add periods, else removes periods.</param>
/// <param name="setStrmPosTo0">If true sets stream position to 0.</param>
/// <returns></returns>
public static MemoryStream DoPeriodHandling(Stream strm, bool add_Remove, bool setStrmPosTo0)
{
MemoryStream replyData = new MemoryStream();
byte[] crlf = new byte[] { (byte)'\r', (byte)'\n' };
if (setStrmPosTo0)
{
strm.Position = 0;
}
StreamLineReader r = new StreamLineReader(strm);
byte[] line = r.ReadLine();
// Loop through all lines
while (line != null)
{
if (line.Length > 0)
{
if (line[0] == (byte)'.')
{
/* Add period Rfc 2821 4.5.2
* - Before sending a line of mail text, the SMTP client checks the
* first character of the line. If it is a period, one additional
* period is inserted at the beginning of the line.
*/
if (add_Remove)
{
replyData.WriteByte((byte)'.');
replyData.Write(line, 0, line.Length);
}
/* Remove period Rfc 2821 4.5.2
* If the first character is a period , the first characteris deleted.
*/
else
{
replyData.Write(line, 1, line.Length - 1);
}
}
else
{
replyData.Write(line, 0, line.Length);
}
}
replyData.Write(crlf, 0, crlf.Length);
// Read next line
line = r.ReadLine();
}
replyData.Position = 0;
return(replyData);
}