Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: batching commands #203

Open
emersion opened this issue Oct 21, 2022 · 1 comment
Open

client: batching commands #203

emersion opened this issue Oct 21, 2022 · 1 comment

Comments

@emersion
Copy link
Owner

Right now clients always wait for the server reply for a command before sending the next one. This causes some unnecessary latency due to roundtrips.

Possible extended API to allow clients to send command batches:

type ClientBatch struct {}

func (*Client) Batch() *ClientBatch

func (*ClientBatch) Mail(from string) *ClientBatch
func (*ClientBatch) Rcpt(to string) *ClientBatch
func (*ClientBatch) Data() io.WriteCloser
func (*ClientBatch) Wait() error
@imirkin
Copy link

imirkin commented Dec 31, 2022

It's not generally legal to do this, but the PIPELINING extension (RFC 2920) allows it for certain commands, when advertised by the server. Specifically from section 3.1:

In particular, the commands RSET, MAIL FROM,
SEND FROM, SOML FROM, SAML FROM, and RCPT TO can all appear anywhere
in a pipelined command group. The EHLO, DATA, VRFY, EXPN, TURN,
QUIT, and NOOP commands can only appear as the last command in a
group since their success or failure produces a change of state which
the client SMTP must accommodate. (NOOP is included in this group so
it can be used as a synchronization point.)

Note that you have to wait for the response from DATA, which may be an error or a success, and even if an earlier command returned failure, DATA may return success, at which point you have to provide it with valid data.

I guess Data() should return a writer + error though, in addition to the explicit Wait() (which would not be necessary to call under usual circumstances). Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants