From: Stephan Bosch Date: Sun, 17 Sep 2017 08:52:43 +0000 (+0200) Subject: lmtp: Moved client_deliver_to_rcpts() from commands.c to lmtp-local.c. X-Git-Tag: 2.3.0.rc1~232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb2e20a30de93e83bbfe407f8231181f69ae684f;p=thirdparty%2Fdovecot%2Fcore.git lmtp: Moved client_deliver_to_rcpts() from commands.c to lmtp-local.c. --- diff --git a/src/lmtp/commands.c b/src/lmtp/commands.c index f3afe340c4..e0cd50722b 100644 --- a/src/lmtp/commands.c +++ b/src/lmtp/commands.c @@ -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; diff --git a/src/lmtp/lmtp-local.c b/src/lmtp/lmtp-local.c index c51b8cb3f5..97462e2912 100644 --- a/src/lmtp/lmtp-local.c +++ b/src/lmtp/lmtp-local.c @@ -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; +} diff --git a/src/lmtp/lmtp-local.h b/src/lmtp/lmtp-local.h index eacfe56014..b4752497db 100644 --- a/src/lmtp/lmtp-local.h +++ b/src/lmtp/lmtp-local.h @@ -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