private bool Dispatch(NetworkStream ns, StreamReader r, string s)
{
Trace("command", s);
if (s.Length < 4)
{
WriteNS(ns, "502 Unrecognized\r\n");
return false;
}
bool retval = true;
switch (s.Substring(0, 4))
{
case "HELO":
break;
case "EHLO":
WriteNS(ns, "250-localhost Hello" + s.Substring(5, s.Length - 5) + "\r\n");
WriteNS(ns, "250-AUTH PLAIN\r\n");
break;
case "QUIT":
WriteNS(ns, "221 Quit\r\n");
return false;
case "MAIL":
_mailfrom = s.Substring(10);
break;
case "RCPT":
_mailto = s.Substring(8);
break;
case "DATA":
WriteNS(ns, "354 Continue\r\n");
while ((s = r.ReadLine()) != null)
{
if (s == ".")
break;
if (s.StartsWith("Subject:"))
{
_subject = s.Substring(9, s.Length - 9);
}
else if (s == "" && _body == null)
{
_body = r.ReadLine();
}
}
Trace("end of data", s);
retval = (s != null);
break;
default:
WriteNS(ns, "502 Unrecognized\r\n");
return true;
}
WriteNS(ns, "250 OK\r\n");
return retval;
}