]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-client-transaction - Handle recipient failure callback in a separate...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 9 Feb 2019 11:22:40 +0000 (12:22 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 19 Feb 2019 22:32:58 +0000 (23:32 +0100)
src/lib-smtp/smtp-client-transaction.c

index 211d49f7738f256ab2edbba678d27f6b581a184a..7188f19c97c2a48f93ddd1e53839733d4b0877ee 100644 (file)
@@ -292,6 +292,30 @@ void smtp_client_transaction_rcpt_abort(
        smtp_client_transaction_rcpt_free(_rcpt);
 }
 
+static void
+smtp_client_transaction_rcpt_fail_reply(
+       struct smtp_client_transaction_rcpt *rcpt,
+       const struct smtp_reply *reply)
+{
+       smtp_client_command_callback_t *callback;
+       void *context;
+
+       if (rcpt->queued) {
+               callback = rcpt->rcpt_callback;
+               context = rcpt->context;
+       } else {
+               callback = rcpt->data_callback;
+               context = rcpt->data_context;
+       }
+       rcpt->rcpt_callback = NULL;
+       rcpt->data_callback = NULL;
+
+       rcpt->failed = TRUE;
+
+       if (callback != NULL)
+               callback(reply, context);
+}
+
 static void
 smtp_client_transaction_rcpt_finished(struct smtp_client_transaction_rcpt *rcpt,
                                      const struct smtp_reply *reply)
@@ -580,16 +604,10 @@ void smtp_client_transaction_fail_reply(struct smtp_client_transaction *trans,
                rcpt_next = rcpt->next;
 
                rcpt->cmd_rcpt_to = NULL;
-               rcpt->failed = TRUE;
-
-               if (cmd != NULL) {
+               if (cmd != NULL)
                        smtp_client_command_fail_reply(&cmd, reply);
-               } else {
-                       if (rcpt->rcpt_callback != NULL) {
-                               rcpt->rcpt_callback(reply, rcpt->context);
-                       }
-                       rcpt->rcpt_callback = NULL;
-               }
+               else
+                       smtp_client_transaction_rcpt_fail_reply(rcpt, reply);
 
                rcpt = rcpt_next;
        }
@@ -614,10 +632,7 @@ void smtp_client_transaction_fail_reply(struct smtp_client_transaction *trans,
                   for the recipients that were previously accepted. */
                for (rcpt = trans->rcpts_data; rcpt != NULL;
                     rcpt = rcpt->next) {
-                       if (rcpt->data_callback != NULL) {
-                               rcpt->data_callback(reply, rcpt->data_context);
-                       }
-                       rcpt->data_callback = NULL;
+                       smtp_client_transaction_rcpt_fail_reply(rcpt, reply);
                }
                if (trans->data_callback != NULL)
                        trans->data_callback(reply, trans->data_context);