[erlang-questions] EPmail-0.2 released
Andrew Thompson
andrew@REDACTED
Sat Feb 19 03:27:53 CET 2011
On Thu, Feb 17, 2011 at 10:41:25PM -0800, shk wrote:
> Yeasterday i released EPmail-0.2 mail system written in Erlang.
First of all, congratulations on making so much progress.
>
> Changes of new version:
>
> * Pop3 server compliant with rfc 1939
>
> * Smtp server, a minimal implementation of rfc 5321
>
> * Pop3 and Smtp servers remake with gen_fsm
>
Your FSMs aren't really very complete, since all you have is
'autorization' (which should probably be 'authorization') and
'transaction'. If you're going to use a FSM you should implement
each SMTP/POP verb as a state. So for SMTP, you'd do something like this:
State Next Available States
Start EHLO, HELO, QUIT
EHLO AUTH, STARTTLS, MAIL FROM, QUIT
MAIL FROM MAIL FROM, RCPT TO, QUIT, RSET
RCPT TO RCPT TO, DATA, RSET, QUIT
and so on. Obviously you can't go from EHLO to RCPT TO, or MAIL FROM to
DATA, so those should be disallowed. You should capture this in the
representation of the FSM, not in a bunch of try/catches.
In gen_smtp I don't use a FSM (maybe I should have) to represent the
state of a connection, I do it manually via pattern matching on the
state (do we have a from address in the envelope when we get a RCPT TO,
etc).
Also, implementing the SMTP client for relaying on to a smarthost inline
like that is kinda... ugly. Your handling of the message body also looks
like its not ideal, especially if the message is large. You can't be
sure that gen_tcp:recv(State#state.socket, 0) is going to give you
everything you need, you need to check for /r/n./r/n at the end.
I'd also suggest writing a lot of unit tests to make sure the code
behaves as you expect.
Finally, if you're interested, I'd like to invite you to use gen_smtp
for your SMTP stack. That way you don't have to *write* a SMTP stack and
I get another user for mine to yell at me for bugs or other issues; we
both win. Although, if you're writing this just as a learning
experience, then I can understand the desire to reimplement the wheel
(although, having written a whole SMTP/MIME stack, I would call it one
of the more painful wheels to reinvent).
Andrew
More information about the erlang-questions
mailing list