From 71564d36ea3aba6dd6a0d2560da46ffda733b679 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 14 Sep 2010 13:45:57 +0100 Subject: [PATCH] Added lda_original_recipient_header setting. Removed non-standard use of Envelope-To: header. --- doc/example-config/conf.d/15-lda.conf | 7 ++++++- src/lda/main.c | 13 +++++++------ src/lib-lda/lda-settings.c | 2 ++ src/lib-lda/lda-settings.h | 1 + src/lmtp/commands.c | 7 ++++++- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/doc/example-config/conf.d/15-lda.conf b/doc/example-config/conf.d/15-lda.conf index ad7db56b1b..c8dcd2e889 100644 --- a/doc/example-config/conf.d/15-lda.conf +++ b/doc/example-config/conf.d/15-lda.conf @@ -1,5 +1,5 @@ ## -## LDA specific settings +## LDA specific settings (also used by LMTP) ## # Address to use when sending rejection mails. @@ -28,6 +28,11 @@ # Delimiter character between local-part and detail in email address. #recipient_delimiter = + +# Header where the original recipient address (SMTP's RCPT TO: address) is taken +# from if not available elsewhere. With dovecot-lda -a parameter overrides this. +# A commonly used header for this is X-Original-To. +#lda_original_recipient_header = + # Should saving a mail to a nonexistent mailbox automatically create it? #lda_mailbox_autocreate = no diff --git a/src/lda/main.c b/src/lda/main.c index 9cacbde204..865f767ff3 100644 --- a/src/lda/main.c +++ b/src/lda/main.c @@ -405,13 +405,14 @@ int main(int argc, char *argv[]) mailbox_header_lookup_unref(&headers_ctx); mail_set_seq(ctx.src_mail, 1); - if (ctx.dest_addr == NULL) { + if (ctx.dest_addr == NULL && + *ctx.set->lda_original_recipient_header != '\0') { ctx.dest_addr = mail_deliver_get_address(ctx.src_mail, - "Envelope-To"); - if (ctx.dest_addr == NULL) { - ctx.dest_addr = strchr(user, '@') != NULL ? user : - t_strconcat(user, "@", ctx.set->hostname, NULL); - } + ctx.set->lda_original_recipient_header); + } + if (ctx.dest_addr == NULL) { + ctx.dest_addr = strchr(user, '@') != NULL ? user : + t_strconcat(user, "@", ctx.set->hostname, NULL); } if (ctx.final_dest_addr == NULL) ctx.final_dest_addr = ctx.dest_addr; diff --git a/src/lib-lda/lda-settings.c b/src/lib-lda/lda-settings.c index 366560a905..828c42d48c 100644 --- a/src/lib-lda/lda-settings.c +++ b/src/lib-lda/lda-settings.c @@ -25,6 +25,7 @@ static const struct setting_define lda_setting_defines[] = { DEF(SET_STR, rejection_reason), DEF(SET_STR, deliver_log_format), DEF(SET_STR, recipient_delimiter), + DEF(SET_STR, lda_original_recipient_header), DEF(SET_BOOL, quota_full_tempfail), DEF(SET_BOOL, lda_mailbox_autocreate), DEF(SET_BOOL, lda_mailbox_autosubscribe), @@ -41,6 +42,7 @@ static const struct lda_settings lda_default_settings = { "Your message to <%t> was automatically rejected:%n%r", .deliver_log_format = "msgid=%m: %$", .recipient_delimiter = "+", + .lda_original_recipient_header = "", .quota_full_tempfail = FALSE, .lda_mailbox_autocreate = FALSE, .lda_mailbox_autosubscribe = FALSE diff --git a/src/lib-lda/lda-settings.h b/src/lib-lda/lda-settings.h index d0f92b5af4..60d23aba44 100644 --- a/src/lib-lda/lda-settings.h +++ b/src/lib-lda/lda-settings.h @@ -11,6 +11,7 @@ struct lda_settings { const char *rejection_reason; const char *deliver_log_format; const char *recipient_delimiter; + const char *lda_original_recipient_header; bool quota_full_tempfail; bool lda_mailbox_autocreate; bool lda_mailbox_autosubscribe; diff --git a/src/lmtp/commands.c b/src/lmtp/commands.c index cf34a6b578..67bcfb5e23 100644 --- a/src/lmtp/commands.c +++ b/src/lmtp/commands.c @@ -462,7 +462,12 @@ client_deliver(struct client *client, const struct mail_recipient *rcpt, dctx.src_mail = src_mail; dctx.src_envelope_sender = client->state.mail_from; dctx.dest_user = client->state.dest_user; - dctx.dest_addr = rcpt->address; + if (*dctx.set->lda_original_recipient_header != '\0') { + dctx.dest_addr = mail_deliver_get_address(src_mail, + dctx.set->lda_original_recipient_header); + } + if (dctx.dest_addr == NULL) + dctx.dest_addr = rcpt->address; dctx.final_dest_addr = rcpt->address; dctx.dest_mailbox_name = *rcpt->detail == '\0' ? "INBOX" : rcpt->detail; dctx.save_dest_mail = array_count(&client->state.rcpt_to) > 1 && -- 2.47.3