]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: Moved client_deliver_to_rcpts() from commands.c to lmtp-local.c.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 17 Sep 2017 08:52:43 +0000 (10:52 +0200)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Thu, 7 Dec 2017 23:08:14 +0000 (00:08 +0100)
src/lmtp/commands.c
src/lmtp/lmtp-local.c
src/lmtp/lmtp-local.h

index f3afe340c41c313108854f2d02d143b93ed282fc..e0cd50722b6aab095d05b30d4976f13f4e3f305d 100644 (file)
@@ -5,13 +5,11 @@
 #include "array.h"
 #include "str.h"
 #include "strescape.h"
-#include "hostpid.h"
 #include "istream.h"
 #include "istream-concat.h"
 #include "ostream.h"
 #include "istream-dot.h"
 #include "safe-mkstemp.h"
-#include "hex-dec.h"
 #include "restrict-access.h"
 #include "anvil-client.h"
 #include "master-service.h"
@@ -19,7 +17,6 @@
 #include "iostream-ssl.h"
 #include "rfc822-parser.h"
 #include "message-date.h"
-#include "message-address.h"
 #include "auth-master.h"
 #include "mail-storage-service.h"
 #include "index/raw/raw-storage.h"
@@ -548,54 +545,6 @@ int cmd_noop(struct client *client, const char *args ATTR_UNUSED)
        return 0;
 }
 
-static bool client_rcpt_to_is_last(struct client *client)
-{
-       return client->state.rcpt_idx >= array_count(&client->state.rcpt_to);
-}
-
-static uid_t client_deliver_to_rcpts(struct client *client,
-                                   struct mail_deliver_session *session)
-{
-       uid_t first_uid = (uid_t)-1;
-       struct mail *src_mail;
-
-       struct mail_recipient *const *rcpts;
-       unsigned int count;
-       int ret;
-       src_mail = client->state.raw_mail;
-
-       rcpts = array_get(&client->state.rcpt_to, &count);
-       while (client->state.rcpt_idx < count) {
-               ret = client_deliver(client, rcpts[client->state.rcpt_idx],
-                                    src_mail, session);
-               client_state_set(client, "DATA", "");
-               i_set_failure_prefix("lmtp(%s): ", my_pid);
-
-               client->state.rcpt_idx++;
-
-               /* succeeded and mail_user is not saved in first_saved_mail */
-               if ((ret == 0 &&
-                    (client->state.first_saved_mail == NULL ||
-                     client->state.first_saved_mail == src_mail)) ||
-                   /* failed. try the next one. */
-                   (ret != 0 && client->state.dest_user != NULL)) {
-                       if (client_rcpt_to_is_last(client))
-                               mail_user_autoexpunge(client->state.dest_user);
-                       mail_user_unref(&client->state.dest_user);
-               } else if (ret == 0) {
-                       /* use the first saved message to save it elsewhere too.
-                          this might allow hard linking the files.
-                          mail_user is saved in first_saved_mail,
-                          will be unreferenced later on */
-                       client->state.dest_user = NULL;
-                       src_mail = client->state.first_saved_mail;
-                       first_uid = geteuid();
-                       i_assert(first_uid != 0);
-               }
-       }
-       return first_uid;
-}
-
 static void client_rcpt_fail_all(struct client *client)
 {
        struct mail_recipient *const *rcptp;
index c51b8cb3f5a7bd4595092a47cae2d25381ef5f04..97462e2912c0aad7f120ea354cdd949d7134a8d8 100644 (file)
@@ -12,6 +12,7 @@
 #include "mail-storage-service.h"
 #include "mail-namespace.h"
 #include "mail-deliver.h"
+#include "mail-autoexpunge.h"
 #include "master-service.h"
 #include "smtp-address.h"
 #include "smtp-submit-settings.h"
@@ -151,7 +152,8 @@ void rcpt_anvil_lookup_callback(const char *reply, void *context)
        client_input_handle(client);
 }
 
-int client_deliver(struct client *client, const struct mail_recipient *rcpt,
+static int
+client_deliver(struct client *client, const struct mail_recipient *rcpt,
               struct mail *src_mail, struct mail_deliver_session *session)
 {
        struct mail_deliver_context dctx;
@@ -311,3 +313,51 @@ int 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);
+}
+
+uid_t client_deliver_to_rcpts(struct client *client,
+                             struct mail_deliver_session *session)
+{
+       uid_t first_uid = (uid_t)-1;
+       struct mail *src_mail;
+
+       struct mail_recipient *const *rcpts;
+       unsigned int count;
+       int ret;
+       src_mail = client->state.raw_mail;
+
+       rcpts = array_get(&client->state.rcpt_to, &count);
+       while (client->state.rcpt_idx < count) {
+               ret = client_deliver(client, rcpts[client->state.rcpt_idx],
+                                    src_mail, session);
+               client_state_set(client, "DATA", "");
+               i_set_failure_prefix("lmtp(%s): ", my_pid);
+
+               client->state.rcpt_idx++;
+
+               /* succeeded and mail_user is not saved in first_saved_mail */
+               if ((ret == 0 &&
+                    (client->state.first_saved_mail == NULL ||
+                     client->state.first_saved_mail == src_mail)) ||
+                   /* failed. try the next one. */
+                   (ret != 0 && client->state.dest_user != NULL)) {
+                       if (client_rcpt_to_is_last(client))
+                               mail_user_autoexpunge(client->state.dest_user);
+                       mail_user_unref(&client->state.dest_user);
+               } else if (ret == 0) {
+                       /* use the first saved message to save it elsewhere too.
+                          this might allow hard linking the files.
+                          mail_user is saved in first_saved_mail,
+                          will be unreferenced later on */
+                       client->state.dest_user = NULL;
+                       src_mail = client->state.first_saved_mail;
+                       first_uid = geteuid();
+                       i_assert(first_uid != 0);
+               }
+       }
+       return first_uid;
+}
index eacfe560140b43f6e3df4a5bb57bf9e31ebe92e8..b4752497db11f2c00d66209d3bb8e6a370eadc75 100644 (file)
@@ -11,7 +11,7 @@ bool cmd_rcpt_finish(struct client *client, struct mail_recipient *rcpt);
 
 void rcpt_anvil_lookup_callback(const char *reply, void *context);
 
-int client_deliver(struct client *client, const struct mail_recipient *rcpt,
-              struct mail *src_mail, struct mail_deliver_session *session);
+uid_t client_deliver_to_rcpts(struct client *client,
+                                   struct mail_deliver_session *session);
 
 #endif