From: Timo Sirainen Date: Tue, 28 Feb 2012 03:27:03 +0000 (+0200) Subject: lib-lda: Fixed mai forward/reject to work with the new smtp_client_open() API. X-Git-Tag: 2.2.alpha1~537 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa01a43b5e4d352a5d5ed0056a2e7f4cbda7c596;p=thirdparty%2Fdovecot%2Fcore.git lib-lda: Fixed mai forward/reject to work with the new smtp_client_open() API. --- diff --git a/src/lib-lda/mail-send.c b/src/lib-lda/mail-send.c index 5841503221..a00ceb5da7 100644 --- a/src/lib-lda/mail-send.c +++ b/src/lib-lda/mail-send.c @@ -4,6 +4,7 @@ #include "ioloop.h" #include "hostpid.h" #include "istream.h" +#include "ostream.h" #include "str.h" #include "str-sanitize.h" #include "var-expand.h" @@ -55,12 +56,10 @@ int mail_send_rejection(struct mail_deliver_context *ctx, const char *recipient, struct mail *mail = ctx->src_mail; struct istream *input; struct smtp_client *smtp_client; - FILE *f; + struct ostream *output; const char *return_addr, *hdr; - const unsigned char *data; const char *value, *msgid, *orig_msgid, *boundary; string_t *str; - size_t size; int ret; if (mail_get_first_header(mail, "Message-ID", &orig_msgid) < 0) @@ -87,76 +86,75 @@ int mail_send_rejection(struct mail_deliver_context *ctx, const char *recipient, str_sanitize(reason, 512)); } - smtp_client = smtp_client_open(ctx->set, return_addr, NULL, &f); + smtp_client = smtp_client_open(ctx->set, return_addr, NULL, &output); msgid = mail_deliver_get_new_message_id(ctx); boundary = t_strdup_printf("%s/%s", my_pid, ctx->set->hostname); - fprintf(f, "Message-ID: %s\r\n", msgid); - fprintf(f, "Date: %s\r\n", message_date_create(ioloop_time)); - fprintf(f, "From: Mail Delivery Subsystem <%s>\r\n", - ctx->set->postmaster_address); - fprintf(f, "To: <%s>\r\n", return_addr); - fprintf(f, "MIME-Version: 1.0\r\n"); - fprintf(f, "Content-Type: " - "multipart/report; report-type=%s;\r\n" - "\tboundary=\"%s\"\r\n", - ctx->dsn ? "delivery-status" : "disposition-notification", - boundary); - - str = t_str_new(256); + str = t_str_new(512); + str_printfa(str, "Message-ID: %s\r\n", msgid); + str_printfa(str, "Date: %s\r\n", message_date_create(ioloop_time)); + str_printfa(str, "From: Mail Delivery Subsystem <%s>\r\n", + ctx->set->postmaster_address); + str_printfa(str, "To: <%s>\r\n", return_addr); + str_append(str, "MIME-Version: 1.0\r\n"); + str_printfa(str, "Content-Type: " + "multipart/report; report-type=%s;\r\n" + "\tboundary=\"%s\"\r\n", + ctx->dsn ? "delivery-status" : "disposition-notification", + boundary); + str_append(str, "Subject: "); var_expand(str, ctx->set->rejection_subject, get_var_expand_table(mail, reason, recipient)); - fprintf(f, "Subject: %s\r\n", str_c(str)); + str_append(str, "\r\n"); - fprintf(f, "Auto-Submitted: auto-replied (rejected)\r\n"); - fprintf(f, "Precedence: bulk\r\n"); - fprintf(f, "\r\nThis is a MIME-encapsulated message\r\n\r\n"); + str_append(str, "Auto-Submitted: auto-replied (rejected)\r\n"); + str_append(str, "Precedence: bulk\r\n"); + str_append(str, "\r\nThis is a MIME-encapsulated message\r\n\r\n"); /* human readable status report */ - fprintf(f, "--%s\r\n", boundary); - fprintf(f, "Content-Type: text/plain; charset=utf-8\r\n"); - fprintf(f, "Content-Disposition: inline\r\n"); - fprintf(f, "Content-Transfer-Encoding: 8bit\r\n\r\n"); + str_printfa(str, "--%s\r\n", boundary); + str_append(str, "Content-Type: text/plain; charset=utf-8\r\n"); + str_append(str, "Content-Disposition: inline\r\n"); + str_append(str, "Content-Transfer-Encoding: 8bit\r\n\r\n"); - str_truncate(str, 0); var_expand(str, ctx->set->rejection_reason, get_var_expand_table(mail, reason, recipient)); - fprintf(f, "%s\r\n", str_c(str)); + str_append(str, "\r\n"); if (ctx->dsn) { /* DSN status report: For LDA rejects. currently only used when user is out of quota */ - fprintf(f, "--%s\r\n" - "Content-Type: message/delivery-status\r\n\r\n", - boundary); - fprintf(f, "Reporting-MTA: dns; %s\r\n", - ctx->set->hostname); + str_printfa(str, "--%s\r\n" + "Content-Type: message/delivery-status\r\n\r\n", + boundary); + str_printfa(str, "Reporting-MTA: dns; %s\r\n", ctx->set->hostname); if (mail_get_first_header(mail, "Original-Recipient", &hdr) > 0) - fprintf(f, "Original-Recipient: rfc822; %s\r\n", hdr); - fprintf(f, "Final-Recipient: rfc822; %s\r\n", recipient); - fprintf(f, "Action: failed\r\n"); - fprintf(f, "Status: %s\r\n", ctx->mailbox_full ? "5.2.2" : "5.2.0"); + str_printfa(str, "Original-Recipient: rfc822; %s\r\n", hdr); + str_printfa(str, "Final-Recipient: rfc822; %s\r\n", recipient); + str_append(str, "Action: failed\r\n"); + str_printfa(str, "Status: %s\r\n", ctx->mailbox_full ? "5.2.2" : "5.2.0"); } else { /* MDN status report: For Sieve "reject" */ - fprintf(f, "--%s\r\n" - "Content-Type: message/disposition-notification\r\n\r\n", - boundary); - fprintf(f, "Reporting-UA: %s; Dovecot Mail Delivery Agent\r\n", - ctx->set->hostname); + str_printfa(str, "--%s\r\n" + "Content-Type: message/disposition-notification\r\n\r\n", + boundary); + str_printfa(str, "Reporting-UA: %s; Dovecot Mail Delivery Agent\r\n", + ctx->set->hostname); if (mail_get_first_header(mail, "Original-Recipient", &hdr) > 0) - fprintf(f, "Original-Recipient: rfc822; %s\r\n", hdr); - fprintf(f, "Final-Recipient: rfc822; %s\r\n", recipient); + str_printfa(str, "Original-Recipient: rfc822; %s\r\n", hdr); + str_printfa(str, "Final-Recipient: rfc822; %s\r\n", recipient); if (orig_msgid != NULL) - fprintf(f, "Original-Message-ID: %s\r\n", orig_msgid); - fprintf(f, "Disposition: " - "automatic-action/MDN-sent-automatically; deleted\r\n"); + str_printfa(str, "Original-Message-ID: %s\r\n", orig_msgid); + str_append(str, "Disposition: " + "automatic-action/MDN-sent-automatically; deleted\r\n"); } - fprintf(f, "\r\n"); + str_append(str, "\r\n"); /* original message's headers */ - fprintf(f, "--%s\r\nContent-Type: message/rfc822\r\n\r\n", boundary); + str_printfa(str, "--%s\r\nContent-Type: message/rfc822\r\n\r\n", boundary); + o_stream_send(output, str_data(str), str_len(str)); if (mail_get_hdr_stream(mail, NULL, &input) == 0) { /* Note: If you add more headers, they need to be sorted. @@ -173,17 +171,15 @@ int mail_send_rejection(struct mail_deliver_context *ctx, const char *recipient, N_ELEMENTS(exclude_headers), null_header_filter_callback, NULL); - while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) { - if (fwrite(data, size, 1, f) == 0) - break; - i_stream_skip(input, size); - } + ret = o_stream_send_istream(output, input); i_stream_unref(&input); i_assert(ret != 0); } - fprintf(f, "\r\n\r\n--%s--\r\n", boundary); + str_truncate(str, 0); + str_printfa(str, "\r\n\r\n--%s--\r\n", boundary); + o_stream_send(output, str_data(str), str_len(str)); return smtp_client_close(smtp_client); } @@ -193,11 +189,9 @@ int mail_send_forward(struct mail_deliver_context *ctx, const char *forwardto) "Return-Path" }; struct istream *input; + struct ostream *output; struct smtp_client *smtp_client; - FILE *f; - const unsigned char *data; const char *return_path; - size_t size; if (mail_get_stream(ctx->src_mail, NULL, NULL, &input) < 0) return -1; @@ -208,18 +202,14 @@ int mail_send_forward(struct mail_deliver_context *ctx, const char *forwardto) forwardto, return_path); } - smtp_client = smtp_client_open(ctx->set, forwardto, return_path, &f); + smtp_client = smtp_client_open(ctx->set, forwardto, return_path, &output); input = i_stream_create_header_filter(input, HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR, hide_headers, N_ELEMENTS(hide_headers), null_header_filter_callback, NULL); - while (i_stream_read_data(input, &data, &size, 0) > 0) { - if (fwrite(data, size, 1, f) == 0) - break; - i_stream_skip(input, size); - } + o_stream_send_istream(output, input); i_stream_unref(&input); return smtp_client_close(smtp_client);