]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: Trigger autoexpunging only for the last RCPT TO.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 23 Mar 2017 12:19:42 +0000 (14:19 +0200)
committerGitLab <gitlab@git.dovecot.net>
Thu, 23 Mar 2017 17:21:35 +0000 (19:21 +0200)
Otherwise if the autoexpunging takes a long time, the LMTP client could
disconnect due to a timeout. The mails would still eventually get delivered
though, so it would result in duplicate mails being delivered.

An alternative to this would be to keep all the mail_users referenced until
the delivery is finished and then autoexpunge all of them at the end. It
increases memory usage though and complicates the code, so at least for now
it's not implemented.

src/lmtp/commands.c

index 18c97965d6cede475a97bf8a508a932505c898a8..0fdb9d1433ec83a9a0c2868eff9cef12e6b9f587 100644 (file)
@@ -951,6 +951,11 @@ client_deliver(struct client *client, const struct mail_recipient *rcpt,
        return ret;
 }
 
+static bool client_rcpt_to_is_last(struct client *client)
+{
+       return client->state.rcpt_idx >= array_count(&client->state.rcpt_to);
+}
+
 static bool client_deliver_next(struct client *client, struct mail *src_mail,
                                struct mail_deliver_session *session)
 {
@@ -970,7 +975,8 @@ static bool client_deliver_next(struct client *client, struct mail *src_mail,
                        return TRUE;
                /* failed. try the next one. */
                if (client->state.dest_user != NULL) {
-                       mail_user_autoexpunge(client->state.dest_user);
+                       if (client_rcpt_to_is_last(client))
+                               mail_user_autoexpunge(client->state.dest_user);
                        mail_user_unref(&client->state.dest_user);
                }
        }
@@ -1060,7 +1066,8 @@ client_input_data_write_local(struct client *client, struct istream *input)
        while (client_deliver_next(client, src_mail, session)) {
                if (client->state.first_saved_mail == NULL ||
                    client->state.first_saved_mail == src_mail) {
-                       mail_user_autoexpunge(client->state.dest_user);
+                       if (client_rcpt_to_is_last(client))
+                               mail_user_autoexpunge(client->state.dest_user);
                        mail_user_unref(&client->state.dest_user);
                } else {
                        /* use the first saved message to save it elsewhere too.