process ( -- )


Vocabulary
smtp.server

Inputs
None

Outputs
None

Definition


: process ( -- )
read-crlf {
{ [ dup not ] [ f ] }
{
[ dup [ "HELO" head? ] [ "EHLO" head? ] bi or ]
[ "220 and..?\r\n" write flush t ]
}
{
[ dup "STARTTLS" = ]
[
"220 2.0.0 Ready to start TLS\r\n" write
flush accept-secure-handshake t
]
}
{ [ dup "QUIT" = ] [ "220 bye\r\n" write flush f ] }
{
[ dup "MAIL FROM:" head? ]
[ "220 OK\r\n" write flush t ]
}
{
[ dup "RCPT TO:" head? ]
[ "220 OK\r\n" write flush t ]
}
{
[ dup "DATA" = ]
[
data-mode on
"354 Enter message, ending with \".\" on a line by itself\r\n"
write flush t
]
}
{
[ dup "." = data-mode get and ]
[ data-mode off "220 OK\r\n" write flush t ]
}
{ [ data-mode get ] [ dup [ print ] with-global t ] }
[ "500 ERROR\r\n" write flush t ]
} cond nip [ process ] when ;