dovecot-2.1: lda: Code cleanups
dovecot at dovecot.org
dovecot at dovecot.org
Sun Oct 2 16:39:22 EEST 2011
details: http://hg.dovecot.org/dovecot-2.1/rev/020d2092f2f7
changeset: 13582:020d2092f2f7
user: Timo Sirainen <tss at iki.fi>
date: Sun Oct 02 16:47:25 2011 +0300
description:
lda: Code cleanups
diffstat:
src/lda/main.c | 139 ++++++++++++++++++++++++++++++++------------------------
1 files changed, 80 insertions(+), 59 deletions(-)
diffs (174 lines):
diff -r ac9fecc9202e -r 020d2092f2f7 src/lda/main.c
--- a/src/lda/main.c Sun Oct 02 16:35:22 2011 +0300
+++ b/src/lda/main.c Sun Oct 02 16:47:25 2011 +0300
@@ -167,6 +167,75 @@
return input;
}
+static struct mail *
+lda_raw_mail_open(struct mail_deliver_context *ctx, const char *path)
+{
+ struct mail_user *raw_mail_user;
+ struct mailbox *box;
+ struct mailbox_transaction_context *t;
+ struct mail *mail;
+ struct mailbox_header_lookup_ctx *headers_ctx;
+ struct istream *input;
+ void **sets;
+ const char *envelope_sender;
+ time_t mtime;
+ int ret;
+
+ sets = master_service_settings_get_others(master_service);
+ raw_mail_user =
+ raw_storage_create_from_set(ctx->dest_user->set_info, sets[0]);
+
+ envelope_sender = ctx->src_envelope_sender != NULL ?
+ ctx->src_envelope_sender : DEFAULT_ENVELOPE_SENDER;
+ if (path == NULL) {
+ input = create_raw_stream(ctx, 0, &mtime);
+ i_stream_set_name(input, "stdin");
+ ret = raw_mailbox_alloc_stream(raw_mail_user, input, mtime,
+ envelope_sender, &box);
+ i_stream_unref(&input);
+ } else {
+ ret = raw_mailbox_alloc_path(raw_mail_user, path, (time_t)-1,
+ envelope_sender, &box);
+ }
+ if (ret < 0) {
+ i_fatal("Can't open delivery mail as raw: %s",
+ mailbox_get_last_error(box, NULL));
+ }
+ mail_user_unref(&raw_mail_user);
+
+ t = mailbox_transaction_begin(box, 0);
+ headers_ctx = mailbox_header_lookup_init(box, wanted_headers);
+ mail = mail_alloc(t, 0, headers_ctx);
+ mailbox_header_lookup_unref(&headers_ctx);
+ mail_set_seq(mail, 1);
+ return mail;
+}
+
+static void
+lda_set_dest_addr(struct mail_deliver_context *ctx, const char *user,
+ const char *destaddr_source)
+{
+ if (ctx->dest_addr == NULL &&
+ *ctx->set->lda_original_recipient_header != '\0') {
+ ctx->dest_addr = mail_deliver_get_address(ctx->src_mail,
+ ctx->set->lda_original_recipient_header);
+ destaddr_source = t_strconcat(
+ ctx->set->lda_original_recipient_header, " header", NULL);
+ }
+ if (ctx->dest_addr == NULL) {
+ ctx->dest_addr = strchr(user, '@') != NULL ? user :
+ t_strconcat(user, "@", ctx->set->hostname, NULL);
+ destaddr_source = "user at hostname";
+ }
+ if (ctx->final_dest_addr == NULL)
+ ctx->final_dest_addr = ctx->dest_addr;
+
+ if (ctx->dest_user->mail_debug) {
+ i_debug("Destination address: %s (source: %s)",
+ ctx->dest_addr, destaddr_source);
+ }
+}
+
static void failure_exit_callback(int *status)
{
/* we want all our exit codes to be sysexits.h compatible.
@@ -211,18 +280,10 @@
struct mail_storage_service_ctx *storage_service;
struct mail_storage_service_user *service_user;
struct mail_storage_service_input service_input;
- struct mail_user *raw_mail_user;
struct mail_storage *storage;
- struct mailbox *box;
- struct istream *input;
- struct mailbox_transaction_context *t;
- struct mailbox_header_lookup_ctx *headers_ctx;
const char *user_source = "", *destaddr_source = "";
- const char *envelope_sender;
- void **sets;
uid_t process_euid;
bool stderr_rejection = FALSE;
- time_t mtime;
int ret, c;
enum mail_error error;
@@ -367,54 +428,8 @@
user_source);
}
- /* create a separate mail user for the internal namespace */
- sets = master_service_settings_get_others(master_service);
- raw_mail_user =
- raw_storage_create_from_set(ctx.dest_user->set_info, sets[0]);
-
- envelope_sender = ctx.src_envelope_sender != NULL ?
- ctx.src_envelope_sender : DEFAULT_ENVELOPE_SENDER;
- if (path == NULL) {
- input = create_raw_stream(&ctx, 0, &mtime);
- i_stream_set_name(input, "stdin");
- ret = raw_mailbox_alloc_stream(raw_mail_user, input, mtime,
- envelope_sender, &box);
- i_stream_unref(&input);
- } else {
- ret = raw_mailbox_alloc_path(raw_mail_user, path, (time_t)-1,
- envelope_sender, &box);
- }
- if (ret < 0) {
- i_fatal("Can't open delivery mail as raw: %s",
- mailbox_get_last_error(box, &error));
- }
- mail_user_unref(&raw_mail_user);
-
- t = mailbox_transaction_begin(box, 0);
- headers_ctx = mailbox_header_lookup_init(box, wanted_headers);
- ctx.src_mail = mail_alloc(t, 0, headers_ctx);
- mailbox_header_lookup_unref(&headers_ctx);
- mail_set_seq(ctx.src_mail, 1);
-
- if (ctx.dest_addr == NULL &&
- *ctx.set->lda_original_recipient_header != '\0') {
- ctx.dest_addr = mail_deliver_get_address(ctx.src_mail,
- ctx.set->lda_original_recipient_header);
- destaddr_source = t_strconcat(
- ctx.set->lda_original_recipient_header, " header", NULL);
- }
- if (ctx.dest_addr == NULL) {
- ctx.dest_addr = strchr(user, '@') != NULL ? user :
- t_strconcat(user, "@", ctx.set->hostname, NULL);
- destaddr_source = "user at hostname";
- }
- if (ctx.final_dest_addr == NULL)
- ctx.final_dest_addr = ctx.dest_addr;
-
- if (ctx.dest_user->mail_debug) {
- i_debug("Destination address: %s (source: %s)",
- ctx.dest_addr, destaddr_source);
- }
+ ctx.src_mail = lda_raw_mail_open(&ctx, path);
+ lda_set_dest_addr(&ctx, user, destaddr_source);
if (mail_deliver(&ctx, &storage) < 0) {
if (storage == NULL) {
@@ -451,9 +466,15 @@
/* ok, rejection sent */
}
- mail_free(&ctx.src_mail);
- mailbox_transaction_rollback(&t);
- mailbox_free(&box);
+ {
+ struct mailbox_transaction_context *t =
+ ctx.src_mail->transaction;
+ struct mailbox *box = ctx.src_mail->box;
+
+ mail_free(&ctx.src_mail);
+ mailbox_transaction_rollback(&t);
+ mailbox_free(&box);
+ }
mail_user_unref(&ctx.dest_user);
mail_deliver_session_deinit(&ctx.session);
More information about the dovecot-cvs
mailing list