]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: lmtp-local - Perform actual (default) delivery in a separate function.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 15 Apr 2020 18:47:11 +0000 (20:47 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 4 May 2020 13:11:49 +0000 (13:11 +0000)
src/lmtp/lmtp-local.c

index 5cc29b40215f47e956e6213fb6a0441758d5de13..cea2c06fc0d792e443bd002a3e0b456c001d69b8 100644 (file)
@@ -533,6 +533,47 @@ lmtp_local_deliver(struct lmtp_local *local,
        return ret;
 }
 
+static int
+lmtp_local_default_do_deliver(struct lmtp_local *local,
+                             struct lmtp_local_recipient *llrcpt,
+                             struct lmtp_local_deliver_context *lldctx,
+                             struct mail_deliver_context *dctx)
+{
+       struct smtp_server_recipient *rcpt = llrcpt->rcpt->rcpt;
+       struct mail_storage *storage;
+       enum mail_error mail_error;
+       const char *error;
+
+       if (mail_deliver(dctx, &storage) == 0) {
+               if (dctx->dest_mail != NULL) {
+                       i_assert(local->first_saved_mail == NULL);
+                       local->first_saved_mail = dctx->dest_mail;
+               }
+               smtp_server_recipient_reply(rcpt, 250, "2.0.0", "%s Saved",
+                                           lldctx->session_id);
+               return 0;
+       }
+
+       if (dctx->tempfail_error != NULL) {
+               smtp_server_recipient_reply(rcpt, 451, "4.2.0", "%s",
+                                           dctx->tempfail_error);
+       } else if (storage != NULL) {
+               error = mail_storage_get_last_error(storage, &mail_error);
+               if (mail_error == MAIL_ERROR_NOQUOTA) {
+                       lmtp_local_rcpt_reply_overquota(llrcpt, error);
+               } else {
+                       smtp_server_recipient_reply(rcpt, 451, "4.2.0", "%s",
+                                                   error);
+               }
+       } else {
+               /* This shouldn't happen */
+               e_error(rcpt->event, "BUG: Saving failed to unknown storage");
+               smtp_server_recipient_reply(rcpt, 451, "4.3.0",
+                                           "Temporary internal error");
+       }
+       return -1;
+}
+
 int lmtp_local_default_deliver(struct client *client,
                               struct lmtp_recipient *lrcpt,
                               struct smtp_server_cmd_ctx *cmd ATTR_UNUSED,
@@ -545,10 +586,7 @@ int lmtp_local_default_deliver(struct client *client,
        struct smtp_address *rcpt_to = rcpt->path;
        struct mail_deliver_input dinput;
        struct mail_deliver_context dctx;
-       struct mail_storage *storage;
        struct event *event;
-       enum mail_error mail_error;
-       const char *error;
        int ret;
 
        event = event_create(rcpt->event);
@@ -590,34 +628,7 @@ int lmtp_local_default_deliver(struct client *client,
        dinput.delivery_time_started = lldctx->delivery_time_started;
 
        mail_deliver_init(&dctx, &dinput);
-       if (mail_deliver(&dctx, &storage) == 0) {
-               if (dctx.dest_mail != NULL) {
-                       i_assert(local->first_saved_mail == NULL);
-                       local->first_saved_mail = dctx.dest_mail;
-               }
-               smtp_server_recipient_reply(rcpt, 250, "2.0.0", "%s Saved",
-                                           lldctx->session_id);
-               ret = 0;
-       } else if (dctx.tempfail_error != NULL) {
-               smtp_server_recipient_reply(rcpt, 451, "4.2.0", "%s",
-                                           dctx.tempfail_error);
-               ret = -1;
-       } else if (storage != NULL) {
-               error = mail_storage_get_last_error(storage, &mail_error);
-               if (mail_error == MAIL_ERROR_NOQUOTA) {
-                       lmtp_local_rcpt_reply_overquota(llrcpt, error);
-               } else {
-                       smtp_server_recipient_reply(rcpt, 451, "4.2.0", "%s",
-                                                   error);
-               }
-               ret = -1;
-       } else {
-               /* This shouldn't happen */
-               e_error(rcpt->event, "BUG: Saving failed to unknown storage");
-               smtp_server_recipient_reply(rcpt, 451, "4.3.0",
-                                           "Temporary internal error");
-               ret = -1;
-       }
+       ret = lmtp_local_default_do_deliver(local, llrcpt, lldctx, &dctx);
        mail_deliver_deinit(&dctx);
        event_unref(&event);