pepoluan
pepoluan

Reputation: 6780

When to send SMTP Status "500 Line too long" during DATA phase?

I'm currently writing an SMTP Server.

One of the SMTP Status Codes defined in RFC5321 § 4.5.3.1.9 is 500 Line too long. This status code must be returned whenever line-length limits are violated.

As with other SMTP Status Codes, this one must be returned to the client "before client sends the next command". It's easy to do this for stateless commands such as MAIL FROM and RCPT TO ...

... but when DATA has been sent by the client, the SMTP Server transitions into the "Receiving DATA" phase ... when is the right moment to return the 500 Line too long status code?

A) Immediately upon receipt of the too-long line?
This leads to

A1) Continue accepting lines until <CR><LF>.<CR><LF>, or
A2) Immediately exit the DATA phase and return to "Receiving Command" state

or

B) After the DATA phase have been terminated with <CR><LF>.<CR><LF>

I have searched high & low for weeks for an answer, searching even for "SMTP Server State Machine", but I cannot find any explicit instruction on whether (A) or (B) is the right answer. And if (A), whether to do (A1) or (A2)

Upvotes: 1

Views: 1477

Answers (1)

tripleee
tripleee

Reputation: 189387

My reading is that you have to wait for the <CRLF>.<CRLF> terminator before you send back any status code. See in particular section 4.2.5. which sort of implies this (but does not really spell it out).

What you do on the server side is up to you, but what would make sense is to discard any further input from the client and just wait for the terminator so you can tell them whatever they were trying to send was not accepted.

Upvotes: 4

Related Questions