From: Stephan Bosch Date: Mon, 3 Dec 2018 17:45:42 +0000 (+0100) Subject: lib-smtp: client: Allow deferring sending the XCLIENT command until authentication... X-Git-Tag: 2.3.5~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c02fdbb83483930fd0c48b5cf42463ff1325bfec;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: client: Allow deferring sending the XCLIENT command until authentication or first mail transaction. This allows updating the proxy data until the XCLIENT command actually needs to be sent. For submission, this means that later EHLO domain changes can still be accounted for. This change makes the simplifications in subsequent changes easier. --- diff --git a/src/lib-smtp/smtp-client-command.c b/src/lib-smtp/smtp-client-command.c index 82208a0856..185904dca4 100644 --- a/src/lib-smtp/smtp-client-command.c +++ b/src/lib-smtp/smtp-client-command.c @@ -981,6 +981,8 @@ smtp_client_command_mail_submit( { struct smtp_client_command *cmd; + smtp_client_connection_send_xclient(conn); + cmd = smtp_client_command_new(conn, flags | SMTP_CLIENT_COMMAND_FLAG_PIPELINE, callback, context); diff --git a/src/lib-smtp/smtp-client-connection.c b/src/lib-smtp/smtp-client-connection.c index c0f6c6d2d1..0c2d217463 100644 --- a/src/lib-smtp/smtp-client-connection.c +++ b/src/lib-smtp/smtp-client-connection.c @@ -747,6 +747,14 @@ smtp_client_connection_authenticate(struct smtp_client_connection *conn) string_t *sasl_output_base64; const char *init_resp, *error; + if (set->username == NULL && set->sasl_mech == NULL) { + if (!conn->initial_xclient_sent && !conn->set.xclient_defer) { + conn->initial_xclient_sent = TRUE; + smtp_client_connection_send_xclient(conn); + } + return (conn->xclient_replies_expected == 0); + } + if (!conn->initial_xclient_sent) { conn->initial_xclient_sent = TRUE; smtp_client_connection_send_xclient(conn); @@ -756,8 +764,6 @@ smtp_client_connection_authenticate(struct smtp_client_connection *conn) if (conn->authenticated) return TRUE; - if (set->username == NULL && set->sasl_mech == NULL) - return TRUE; if ((conn->caps.standard & SMTP_CAPABILITY_AUTH) == 0) { smtp_client_connection_fail(conn, @@ -1878,6 +1884,7 @@ smtp_client_connection_do_create(struct smtp_client *client, const char *name, smtp_proxy_data_merge(conn->pool, &conn->set.proxy_data, &set->proxy_data); + conn->set.xclient_defer = set->xclient_defer; conn->set.peer_trusted = set->peer_trusted; } diff --git a/src/lib-smtp/smtp-client.h b/src/lib-smtp/smtp-client.h index fe8fd55f22..bf16ec28ab 100644 --- a/src/lib-smtp/smtp-client.h +++ b/src/lib-smtp/smtp-client.h @@ -93,6 +93,9 @@ struct smtp_client_settings { bool debug; /* peer is trusted, so e.g. attempt sending XCLIENT data */ bool peer_trusted; + /* defer sending XCLIENT command until authentication or first mail + transaction. */ + bool xclient_defer; /* don't clear password after first successful authentication */ bool remember_password; };