]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lda: Added mail_deliver_get_log_var_expand_table().
authorTimo Sirainen <tss@iki.fi>
Fri, 23 Apr 2010 07:38:30 +0000 (10:38 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 23 Apr 2010 07:38:30 +0000 (10:38 +0300)
--HG--
branch : HEAD

src/lda/main.c
src/lib-lda/mail-deliver.c
src/lib-lda/mail-deliver.h

index 056ce3e391caa20f0b367ba21018ec5c222a65bb..288cf5e273607692fd996c7bff76daa4c1794b66 100644 (file)
@@ -437,7 +437,8 @@ int main(int argc, char *argv[])
        mail_set_seq(ctx.src_mail, 1);
 
        if (ctx.dest_addr == NULL) {
-               ctx.dest_addr = mail_deliver_get_address(&ctx, "Envelope-To");
+               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);
index 0f02553cf05da7aea07c43b4a32c42cdabad1ba2..3f9f127b87d4094a84fb7da700254e6813b12147 100644 (file)
 
 deliver_mail_func_t *deliver_mail = NULL;
 
-const char *mail_deliver_get_address(struct mail_deliver_context *ctx,
-                                    const char *header)
+const char *mail_deliver_get_address(struct mail *mail, const char *header)
 {
        struct message_address *addr;
        const char *str;
 
-       if (mail_get_first_header(ctx->src_mail, header, &str) <= 0)
+       if (mail_get_first_header(mail, header, &str) <= 0)
                return NULL;
        addr = message_address_parse(pool_datastack_create(),
                                     (const unsigned char *)str,
@@ -32,8 +31,8 @@ const char *mail_deliver_get_address(struct mail_deliver_context *ctx,
                NULL : t_strconcat(addr->mailbox, "@", addr->domain, NULL);
 }
 
-static const struct var_expand_table *
-get_log_var_expand_table(struct mail_deliver_context *ctx, const char *message)
+const struct var_expand_table *
+mail_deliver_get_log_var_expand_table(struct mail *mail, const char *message)
 {
        static struct var_expand_table static_tab[] = {
                { '$', NULL, NULL },
@@ -51,17 +50,17 @@ get_log_var_expand_table(struct mail_deliver_context *ctx, const char *message)
        memcpy(tab, static_tab, sizeof(static_tab));
 
        tab[0].value = message;
-       (void)mail_get_first_header(ctx->src_mail, "Message-ID", &tab[1].value);
-       tab[1].value = str_sanitize(tab[1].value, 200);
+       (void)mail_get_first_header(mail, "Message-ID", &tab[1].value);
+       tab[1].value = tab[1].value == NULL ? "unspecified" :
+               str_sanitize(tab[1].value, 200);
 
-       (void)mail_get_first_header_utf8(ctx->src_mail, "Subject", &tab[2].value);
+       (void)mail_get_first_header_utf8(mail, "Subject", &tab[2].value);
        tab[2].value = str_sanitize(tab[2].value, 80);
+       tab[3].value = str_sanitize(mail_deliver_get_address(mail, "From"), 80);
 
-       tab[3].value = str_sanitize(mail_deliver_get_address(ctx, "From"), 80);
-
-       if (mail_get_physical_size(ctx->src_mail, &size) == 0)
+       if (mail_get_physical_size(mail, &size) == 0)
                tab[4].value = dec2str(size);
-       if (mail_get_virtual_size(ctx->src_mail, &size) == 0)
+       if (mail_get_virtual_size(mail, &size) == 0)
                tab[5].value = dec2str(size);
        return tab;
 }
@@ -79,7 +78,7 @@ void mail_deliver_log(struct mail_deliver_context *ctx, const char *fmt, ...)
        if (ctx->session_id != NULL)
                str_printfa(str, "%s: ", ctx->session_id);
        var_expand(str, ctx->set->deliver_log_format,
-                  get_log_var_expand_table(ctx, msg));
+                  mail_deliver_get_log_var_expand_table(ctx->src_mail, msg));
        i_info("%s", str_c(str));
        va_end(args);
 }
@@ -251,7 +250,7 @@ const char *mail_deliver_get_return_address(struct mail_deliver_context *ctx)
        if (ctx->src_envelope_sender != NULL)
                return ctx->src_envelope_sender;
 
-       return mail_deliver_get_address(ctx, "Return-Path");
+       return mail_deliver_get_address(ctx->src_mail, "Return-Path");
 }
 
 const char *mail_deliver_get_new_message_id(struct mail_deliver_context *ctx)
index bbedb2e7b02db19708b1b031895b02d929c2b7fb..307106e9a0ceb0fceda143c61dd0a782e39454d8 100644 (file)
@@ -40,11 +40,12 @@ typedef int deliver_mail_func_t(struct mail_deliver_context *ctx,
 
 extern deliver_mail_func_t *deliver_mail;
 
+const struct var_expand_table *
+mail_deliver_get_log_var_expand_table(struct mail *mail, const char *message);
 void mail_deliver_log(struct mail_deliver_context *ctx, const char *fmt, ...)
        ATTR_FORMAT(2, 3);
 
-const char *mail_deliver_get_address(struct mail_deliver_context *ctx,
-                                    const char *header);
+const char *mail_deliver_get_address(struct mail *mail, const char *header);
 const char *mail_deliver_get_return_address(struct mail_deliver_context *ctx);
 const char *mail_deliver_get_new_message_id(struct mail_deliver_context *ctx);