X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/d12746bc15d83ab821be36975da0179672708bc1..b4a37a77271a8f6efc887d68265eb7867eff6170:/src/src/deliver.c diff --git a/src/src/deliver.c b/src/src/deliver.c index 0b403bad2..d4ed8af08 100644 --- a/src/src/deliver.c +++ b/src/src/deliver.c @@ -5378,7 +5378,7 @@ static void print_address_error(address_item *addr, FILE *f, uschar *t) { int count = Ustrlen(t); -uschar *s = testflag(addr, af_pass_message)? addr->message : NULL; +uschar *s = testflag(addr, af_pass_message) ? addr->message : NULL; if (!s && !(s = addr->user_message)) return; @@ -5507,6 +5507,25 @@ while ((addr = *anchor)) +/************************************************/ + +static void +print_dsn_addr_action(FILE * f, address_item * addr, + uschar * action, uschar * status) +{ +address_item * pa; + +if (addr->dsn_orcpt) + fprintf(f,"Original-Recipient: %s\n", addr->dsn_orcpt); + +for (pa = addr; pa->parent; ) pa = pa->parent; +fprintf(f, "Action: %s\n" + "Final-Recipient: rfc822;%s\n" + "Status: %s\n", + action, pa->address, status); +} + + /************************************************* * Deliver one message * *************************************************/ @@ -5885,9 +5904,7 @@ else if (system_filter && process_recipients != RECIP_FAIL_TIMEOUT) ugid.uid_set = ugid.gid_set = TRUE; } else - { ugid.uid_set = ugid.gid_set = FALSE; - } return_path = sender_address; f.enable_dollar_recipients = TRUE; /* Permit $recipients in system filter */ @@ -6610,13 +6627,21 @@ while (addr_new) /* Loop until all addresses dealt with */ if ( domain_retry_record && now - domain_retry_record->time_stamp > retry_data_expire ) + { + DEBUG(D_deliver|D_retry) + debug_printf("domain retry record present but expired\n"); domain_retry_record = NULL; /* Ignore if too old */ + } address_retry_record = dbfn_read(dbm_file, addr->address_retry_key); if ( address_retry_record && now - address_retry_record->time_stamp > retry_data_expire ) + { + DEBUG(D_deliver|D_retry) + debug_printf("address retry record present but expired\n"); address_retry_record = NULL; /* Ignore if too old */ + } if (!address_retry_record) { @@ -6625,7 +6650,11 @@ while (addr_new) /* Loop until all addresses dealt with */ address_retry_record = dbfn_read(dbm_file, altkey); if ( address_retry_record && now - address_retry_record->time_stamp > retry_data_expire) + { + DEBUG(D_deliver|D_retry) + debug_printf("address retry record present but expired\n"); address_retry_record = NULL; /* Ignore if too old */ + } } } else @@ -6634,9 +6663,18 @@ while (addr_new) /* Loop until all addresses dealt with */ DEBUG(D_deliver|D_retry) { if (!domain_retry_record) - debug_printf("no domain retry record\n"); + debug_printf("no domain retry record\n"); + else + debug_printf("have domain retry record; next_try = now%+d\n", + f.running_in_test_harness ? 0 : + (int)(domain_retry_record->next_try - now)); + if (!address_retry_record) - debug_printf("no address retry record\n"); + debug_printf("no address retry record\n"); + else + debug_printf("have address retry record; next_try = now%+d\n", + f.running_in_test_harness ? 0 : + (int)(address_retry_record->next_try - now)); } /* If we are sending a message down an existing SMTP connection, we must @@ -6658,6 +6696,9 @@ while (addr_new) /* Loop until all addresses dealt with */ addr->message = US"reusing SMTP connection skips previous routing defer"; addr->basic_errno = ERRNO_RRETRY; (void)post_process_one(addr, DEFER, LOG_MAIN, EXIM_DTYPE_ROUTER, 0); + + addr->message = domain_retry_record->text; + setflag(addr, af_pass_message); } /* If we are in a queue run, defer routing unless there is no retry data or @@ -6711,6 +6752,16 @@ while (addr_new) /* Loop until all addresses dealt with */ addr->message = US"retry time not reached"; addr->basic_errno = ERRNO_RRETRY; (void)post_process_one(addr, DEFER, LOG_MAIN, EXIM_DTYPE_ROUTER, 0); + + /* For remote-retry errors (here and just above) that we've not yet + hit the rery time, use the error recorded in the retry database + as info in the warning message. This lets us send a message even + when we're not failing on a fresh attempt. We assume that this + info is not sensitive. */ + + addr->message = domain_retry_record + ? domain_retry_record->text : address_retry_record->text; + setflag(addr, af_pass_message); } /* The domain is OK for routing. Remember if retry data exists so it @@ -7041,7 +7092,7 @@ if ( f.header_rewritten } -/* If there are any deliveries to be and we do not already have the journal +/* If there are any deliveries to do and we do not already have the journal file, create it. This is used to record successful deliveries as soon as possible after each delivery is known to be complete. A file opened with O_APPEND is used so that several processes can run simultaneously. @@ -7333,8 +7384,8 @@ if (addr_senddsn) if (errors_reply_to) fprintf(f, "Reply-To: %s\n", errors_reply_to); + moan_write_from(f); fprintf(f, "Auto-Submitted: auto-generated\n" - "From: Mail Delivery System \n" "To: %s\n" "Subject: Delivery Status Notification\n" "Content-Type: multipart/report; report-type=delivery-status; boundary=%s\n" @@ -7345,7 +7396,7 @@ if (addr_senddsn) "This message was created automatically by mail delivery software.\n" " ----- The following addresses had successful delivery notifications -----\n", - qualify_domain_sender, sender_address, bound, bound); + sender_address, bound, bound); for (addr_dsntmp = addr_senddsn; addr_dsntmp; addr_dsntmp = addr_dsntmp->next) @@ -7378,10 +7429,7 @@ if (addr_senddsn) if (addr_dsntmp->dsn_orcpt) fprintf(f,"Original-Recipient: %s\n", addr_dsntmp->dsn_orcpt); - fprintf(f, "Action: delivered\n" - "Final-Recipient: rfc822;%s\n" - "Status: 2.0.0\n", - addr_dsntmp->address); + print_dsn_addr_action(f, addr_dsntmp, US"delivered", US"2.0.0"); if (addr_dsntmp->host_used && addr_dsntmp->host_used->name) fprintf(f, "Remote-MTA: dns; %s\nDiagnostic-Code: smtp; 250 Ok\n\n", @@ -7401,7 +7449,7 @@ if (addr_senddsn) tctx.u.fd = fd; tctx.options = topt_add_return_path | topt_no_body; - /*XXX hmm, retval ignored. + /*XXX hmm, FALSE(fail) retval ignored. Could error for any number of reasons, and they are not handled. */ transport_write_message(&tctx, 0); fflush(f); @@ -7471,7 +7519,8 @@ while (addr_failed) mark the recipient done. */ if ( addr_failed->prop.ignore_error - || addr_failed->dsn_flags & (rf_dsnflags & ~rf_notify_failure) + || addr_failed->dsn_flags & rf_dsnflags + && !(addr_failed->dsn_flags & rf_notify_failure) ) { addr = addr_failed; @@ -7766,10 +7815,9 @@ wording. */ for (addr = handled_addr; addr; addr = addr->next) { host_item * hu; - fprintf(fp, "Action: failed\n" - "Final-Recipient: rfc822;%s\n" - "Status: 5.0.0\n", - addr->address); + + print_dsn_addr_action(fp, addr, US"failed", US"5.0.0"); + if ((hu = addr->host_used) && hu->name) { fprintf(fp, "Remote-MTA: dns; %s\n", hu->name); @@ -8012,6 +8060,8 @@ the parent's domain. If all the deferred addresses have an error number that indicates "retry time not reached", skip sending the warning message, because it won't contain the reason for the delay. It will get sent at the next real delivery attempt. + Exception: for retries caused by a remote peer we use the error message + store in the retry DB as the reason. However, if at least one address has tried, we'd better include all of them in the message. @@ -8031,7 +8081,7 @@ else if (addr_defer != (address_item *)(+1)) { address_item *addr; uschar *recipients = US""; - BOOL delivery_attempted = FALSE; + BOOL want_warning_msg = FALSE; deliver_domain = testflag(addr_defer, af_pfr) ? addr_defer->parent->domain : addr_defer->domain; @@ -8040,7 +8090,7 @@ else if (addr_defer != (address_item *)(+1)) { address_item *otaddr; - if (addr->basic_errno > ERRNO_RETRY_BASE) delivery_attempted = TRUE; + if (addr->basic_errno > ERRNO_WARN_BASE) want_warning_msg = TRUE; if (deliver_domain) { @@ -8112,7 +8162,7 @@ else if (addr_defer != (address_item *)(+1)) it also defers). */ if ( !f.queue_2stage - && delivery_attempted + && want_warning_msg && ( !(addr_defer->dsn_flags & rf_dsnflags) || addr_defer->dsn_flags & rf_notify_delay ) @@ -8163,7 +8213,7 @@ else if (addr_defer != (address_item *)(+1)) DEBUG(D_deliver) { - debug_printf("time on queue = %s\n", readconf_printtime(queue_time)); + debug_printf("time on queue = %s id %s addr %s\n", readconf_printtime(queue_time), message_id, addr_defer->address); debug_printf("warning counts: required %d done %d\n", count, warning_count); } @@ -8309,13 +8359,9 @@ else if (addr_defer != (address_item *)(+1)) for ( ; addr_dsndefer; addr_dsndefer = addr_dsndefer->next) { - if (addr_dsndefer->dsn_orcpt) - fprintf(f, "Original-Recipient: %s\n", addr_dsndefer->dsn_orcpt); - fprintf(f, "Action: delayed\n" - "Final-Recipient: rfc822;%s\n" - "Status: 4.0.0\n", - addr_dsndefer->address); + print_dsn_addr_action(f, addr_dsndefer, US"delayed", US"4.0.0"); + if (addr_dsndefer->host_used && addr_dsndefer->host_used->name) { fprintf(f, "Remote-MTA: dns; %s\n",