addr2->transport_return = addr->transport_return;
addr2->basic_errno = addr->basic_errno;
addr2->more_errno = addr->more_errno;
- addr2->delivery_usec = addr->delivery_usec;
+ addr2->delivery_time = addr->delivery_time;
addr2->special_action = addr->special_action;
addr2->message = addr->message;
addr2->user_message = addr->user_message;
string_timesince(&received_time));
if (LOGGING(deliver_time))
- {
- struct timeval diff = {.tv_sec = addr->more_errno, .tv_usec = addr->delivery_usec};
- g = string_append(g, 2, US" DT=", string_timediff(&diff));
- }
+ g = string_append(g, 2, US" DT=", string_timediff(&addr->delivery_time));
/* string_cat() always leaves room for the terminator. Release the
store we used to build the line after writing it. */
}
}
+if (LOGGING(deliver_time))
+ g = string_append(g, 2, US" DT=", string_timediff(&addr->delivery_time));
+
if (addr->message)
g = string_append(g, 2, US": ", addr->message);
if (addr->message)
g = string_append(g, 2, US": ", addr->message);
+if (LOGGING(deliver_time))
+ g = string_append(g, 2, US" DT=", string_timediff(&addr->delivery_time));
+
(void) string_from_gstring(g);
/* Do the logging. For the message log, "routing failed" for those cases,
|| (ret = write(pfd[pipe_write], &addr2->flags, sizeof(addr2->flags))) != sizeof(addr2->flags)
|| (ret = write(pfd[pipe_write], &addr2->basic_errno, sizeof(int))) != sizeof(int)
|| (ret = write(pfd[pipe_write], &addr2->more_errno, sizeof(int))) != sizeof(int)
- || (ret = write(pfd[pipe_write], &addr2->delivery_usec, sizeof(int))) != sizeof(int)
+ || (ret = write(pfd[pipe_write], &addr2->delivery_time, sizeof(struct timeval))) != sizeof(struct timeval)
|| (ret = write(pfd[pipe_write], &addr2->special_action, sizeof(int))) != sizeof(int)
|| (ret = write(pfd[pipe_write], &addr2->transport,
sizeof(transport_instance *))) != sizeof(transport_instance *)
len = read(pfd[pipe_read], &addr2->flags, sizeof(addr2->flags));
len = read(pfd[pipe_read], &addr2->basic_errno, sizeof(int));
len = read(pfd[pipe_read], &addr2->more_errno, sizeof(int));
- len = read(pfd[pipe_read], &addr2->delivery_usec, sizeof(int));
+ len = read(pfd[pipe_read], &addr2->delivery_time, sizeof(struct timeval));
len = read(pfd[pipe_read], &addr2->special_action, sizeof(int));
len = read(pfd[pipe_read], &addr2->transport,
sizeof(transport_instance *));
/* Done with this address */
- if (result == OK)
- {
- addr2->more_errno = deliver_time.tv_sec;
- addr2->delivery_usec = deliver_time.tv_usec;
- }
+ addr2->delivery_time = deliver_time;
post_process_one(addr2, result, logflags, EXIM_DTYPE_TRANSPORT, logchar);
/* If a pipe delivery generated text to be sent back, the result may be
ptr += sizeof(addr->basic_errno);
memcpy(&addr->more_errno, ptr, sizeof(addr->more_errno));
ptr += sizeof(addr->more_errno);
- memcpy(&addr->delivery_usec, ptr, sizeof(addr->delivery_usec));
- ptr += sizeof(addr->delivery_usec);
+ memcpy(&addr->delivery_time, ptr, sizeof(addr->delivery_time));
+ ptr += sizeof(addr->delivery_time);
memcpy(&addr->flags, ptr, sizeof(addr->flags));
ptr += sizeof(addr->flags);
addr->message = *ptr ? string_copy(ptr) : NULL;
ptr += sizeof(addr->basic_errno);
memcpy(ptr, &addr->more_errno, sizeof(addr->more_errno));
ptr += sizeof(addr->more_errno);
- memcpy(ptr, &addr->delivery_usec, sizeof(addr->delivery_usec));
- ptr += sizeof(addr->delivery_usec);
+ memcpy(ptr, &addr->delivery_time, sizeof(addr->delivery_time));
+ ptr += sizeof(addr->delivery_time);
memcpy(ptr, &addr->flags, sizeof(addr->flags));
ptr += sizeof(addr->flags);
host if set, mark addrs as having used this host
smtp_greeting from peer
helo_response from peer
+ start points to timestamp of delivery start
If errno_value has the special value ERRNO_CONNECTTIMEOUT, ETIMEDOUT is put in
the errno field, and RTEF_CTOUT is ORed into the more_errno field, to indicate
static void
set_errno(address_item *addrlist, int errno_value, uschar *msg, int rc,
- BOOL pass_message, host_item * host
+ BOOL pass_message, host_item * host,
#ifdef EXPERIMENTAL_DSN_INFO
- , const uschar * smtp_greeting, const uschar * helo_response
+ const uschar * smtp_greeting, const uschar * helo_response,
#endif
+ struct timeval * start
)
{
int orvalue = 0;
+struct timeval deliver_time;
+
if (errno_value == ERRNO_CONNECTTIMEOUT)
{
errno_value = ETIMEDOUT;
orvalue = RTEF_CTOUT;
}
+timesince(&deliver_time, start);
+
for (address_item * addr = addrlist; addr; addr = addr->next)
if (addr->transport_return >= PENDING)
{
addr->basic_errno = errno_value;
addr->more_errno |= orvalue;
+ addr->delivery_time = deliver_time;
if (msg)
{
addr->message = msg;
}
static void
-set_errno_nohost(address_item *addrlist, int errno_value, uschar *msg, int rc,
- BOOL pass_message)
+set_errno_nohost(address_item * addrlist, int errno_value, uschar * msg, int rc,
+ BOOL pass_message, struct timeval * start)
{
-set_errno(addrlist, errno_value, msg, rc, pass_message, NULL
+set_errno(addrlist, errno_value, msg, rc, pass_message, NULL,
#ifdef EXPERIMENTAL_DSN_INFO
- , NULL, NULL
+ NULL, NULL,
#endif
- );
+ start);
}
{
uschar *message = string_sprintf("SMTP timeout after RCPT TO:<%s>",
transport_rcpt_address(addr, sx->conn_args.tblock->rcpt_include_affixes));
- set_errno_nohost(sx->first_addr, ETIMEDOUT, message, DEFER, FALSE);
+ set_errno_nohost(sx->first_addr, ETIMEDOUT, message, DEFER, FALSE, &sx->delivery_start);
retry_add_item(addr, addr->address_retry_key, 0);
update_waiting = FALSE;
return -1;
case ERROR:
set_errno_nohost(sx->addrlist, ERRNO_AUTHPROB, string_copy(sx->buffer),
- DEFER, FALSE);
+ DEFER, FALSE, &sx->delivery_start);
return ERROR;
}
return OK;
{
set_errno_nohost(sx->addrlist, ERRNO_AUTHFAIL,
string_sprintf("authentication required but %s", fail_reason), DEFER,
- FALSE);
+ FALSE, &sx->delivery_start);
return DEFER;
}
/* Construct AUTH appendix string for MAIL TO */
/*
Arguments
- buffer to build string
+ sx context for smtp connection
+ p point in sx->buffer to build string
addrlist chain of potential addresses to deliver
- ob transport options
Globals f.smtp_authenticated
client_authenticated_sender
*/
static BOOL
-smtp_mail_auth_str(uschar *buffer, unsigned bufsize, address_item *addrlist,
- smtp_transport_options_block *ob)
+smtp_mail_auth_str(smtp_context * sx, uschar * p, address_item * addrlist)
{
+smtp_transport_options_block * ob = sx->conn_args.ob;
uschar * local_authenticated_sender = authenticated_sender;
#ifdef notdef
- debug_printf("smtp_mail_auth_str: as<%s> os<%s> SA<%s>\n", authenticated_sender, ob->authenticated_sender, f.smtp_authenticated?"Y":"N");
+ debug_printf("smtp_mail_auth_str: as<%s> os<%s> SA<%s>\n",
+ authenticated_sender, ob->authenticated_sender, f.smtp_authenticated?"Y":"N");
#endif
if (ob->authenticated_sender)
{
- uschar *new = expand_string(ob->authenticated_sender);
+ uschar * new = expand_string(ob->authenticated_sender);
if (!new)
{
if (!f.expand_string_forcedfail)
{
uschar *message = string_sprintf("failed to expand "
"authenticated_sender: %s", expand_string_message);
- set_errno_nohost(addrlist, ERRNO_EXPANDFAIL, message, DEFER, FALSE);
+ set_errno_nohost(addrlist, ERRNO_EXPANDFAIL, message, DEFER, FALSE, &sx->delivery_start);
return TRUE;
}
}
- else if (*new) local_authenticated_sender = new;
+ else if (*new)
+ local_authenticated_sender = new;
}
/* Add the authenticated sender address if present */
if ( (f.smtp_authenticated || ob->authenticated_sender_force)
&& local_authenticated_sender)
{
- string_format_nt(buffer, bufsize, " AUTH=%s",
+ string_format_nt(p, sizeof(sx->buffer) - (p-sx->buffer), " AUTH=%s",
auth_xtextencode(local_authenticated_sender,
Ustrlen(local_authenticated_sender)));
client_authenticated_sender = string_copy(local_authenticated_sender);
}
else
- *buffer= 0;
+ *p = 0;
return FALSE;
}
if (sx->smtps)
{
set_errno_nohost(sx->addrlist, ERRNO_TLSFAILURE, US"TLS support not available",
- DEFER, FALSE);
+ DEFER, FALSE, &sx->delivery_start);
return ERROR;
}
#endif
default: set_errno_nohost(sx->addrlist, ERRNO_DNSDEFER,
string_sprintf("DANE error: tlsa lookup %s",
rc_to_string(rc)),
- rc, FALSE);
+ rc, FALSE, &sx->delivery_start);
# ifndef DISABLE_EVENT
(void) event_raise(sx->conn_args.tblock->event_action,
US"dane:fail", sx->dane_required
{
set_errno_nohost(sx->addrlist, ERRNO_DNSDEFER,
string_sprintf("DANE error: %s lookup not DNSSEC", sx->conn_args.host->name),
- FAIL, FALSE);
+ FAIL, FALSE, &sx->delivery_start);
# ifndef DISABLE_EVENT
(void) event_raise(sx->conn_args.tblock->event_action,
US"dane:fail", US"dane-required");
set_errno_nohost(sx->addrlist,
errno == ETIMEDOUT ? ERRNO_CONNECTTIMEOUT : errno,
sx->verify ? US strerror(errno) : NULL,
- DEFER, FALSE);
+ DEFER, FALSE, &sx->delivery_start);
sx->send_quit = FALSE;
return DEFER;
}
{
set_errno_nohost(sx->addrlist, ERRNO_EXPANDFAIL,
string_sprintf("deferred by smtp:connect event expansion: %s", s),
- DEFER, FALSE);
+ DEFER, FALSE, &sx->delivery_start);
yield = DEFER;
goto SEND_QUIT;
}
{
message = string_sprintf("failed to expand helo_data: %s",
expand_string_message);
- set_errno_nohost(sx->addrlist, ERRNO_EXPANDFAIL, message, DEFER, FALSE);
+ set_errno_nohost(sx->addrlist, ERRNO_EXPANDFAIL, message, DEFER, FALSE, &sx->delivery_start);
yield = DEFER;
goto SEND_QUIT;
}
{
uschar *message = string_sprintf("failed to expand helo_data: %s",
expand_string_message);
- set_errno_nohost(sx->addrlist, ERRNO_EXPANDFAIL, message, DEFER, FALSE);
+ set_errno_nohost(sx->addrlist, ERRNO_EXPANDFAIL, message, DEFER, FALSE, &sx->delivery_start);
yield = DEFER;
goto SEND_QUIT;
}
{
message = string_sprintf("failed to expand utf8_downconvert: %s",
expand_string_message);
- set_errno_nohost(sx->addrlist, ERRNO_EXPANDFAIL, message, DEFER, FALSE);
+ set_errno_nohost(sx->addrlist, ERRNO_EXPANDFAIL, message, DEFER, FALSE, &sx->delivery_start);
yield = DEFER;
goto SEND_QUIT;
}
set_errno_nohost(sx->addrlist,
errno == ETIMEDOUT ? ERRNO_CONNECTTIMEOUT : errno,
sx->verify ? US strerror(errno) : NULL,
- DEFER, FALSE);
+ DEFER, FALSE, &sx->delivery_start);
sx->send_quit = FALSE;
return DEFER;
}
#endif
? FAIL : DEFER,
pass_message,
- errno == ECONNREFUSED ? NULL : sx->conn_args.host
+ errno == ECONNREFUSED ? NULL : sx->conn_args.host,
#ifdef EXPERIMENTAL_DSN_INFO
- , sx->smtp_greeting, sx->helo_response
+ sx->smtp_greeting, sx->helo_response,
#endif
- );
+ &sx->delivery_start);
}
otherwise no check - this feature is expected to be used with LMTP and other
cases where non-standard addresses (e.g. without domains) might be required. */
-if (smtp_mail_auth_str(p, sizeof(sx->buffer) - (p-sx->buffer), addrlist, sx->conn_args.ob))
- return ERROR;
-
-return OK;
+return smtp_mail_auth_str(sx, p, addrlist) ? ERROR : OK;
}
{
if (s = string_address_utf8_to_alabel(s, &errstr), errstr)
{
- set_errno_nohost(sx->addrlist, ERRNO_EXPANDFAIL, errstr, DEFER, FALSE);
+ set_errno_nohost(sx->addrlist, ERRNO_EXPANDFAIL, errstr, DEFER, FALSE, &sx->delivery_start);
*yield = ERROR;
return -4;
}
and there was a problem setting it up; OR helo_data
or add_headers or authenticated_sender is specified
for this transport, and the string failed to expand
+
+ For all non-OK returns the first addr of the list carries the
+ time taken for the attempt.
*/
static int
int yield = OK;
int save_errno;
int rc;
-struct timeval start_delivery_time;
BOOL pass_message = FALSE;
uschar *message = NULL;
uschar new_message_id[MESSAGE_ID_LENGTH + 1];
smtp_context * sx = store_get(sizeof(*sx), TRUE); /* tainted, for the data buffers */
-gettimeofday(&start_delivery_time, NULL);
suppress_tls = suppress_tls; /* stop compiler warning when no TLS support */
*message_defer = FALSE;
sx->helo_data = NULL;
sx->conn_args.tblock = tblock;
/* sx->verify = FALSE; */
+gettimeofday(&sx->delivery_start, NULL);
sx->sync_addr = sx->first_addr = addrlist;
/* Get the channel set up ready for a message (MAIL FROM being the next
SMTP command to send */
if ((rc = smtp_setup_conn(sx, suppress_tls)) != OK)
+ {
+ timesince(&addrlist->delivery_time, &sx->delivery_start);
return rc;
+ }
/* If there is a filter command specified for this transport, we can now
set it up. This cannot be done until the identify of the host is known. */
string_sprintf("%.50s transport", tblock->name), NULL))
{
set_errno_nohost(addrlist->next, addrlist->basic_errno, addrlist->message, DEFER,
- FALSE);
+ FALSE, &sx->delivery_start);
yield = ERROR;
goto SEND_QUIT;
}
{
/*XXX could we find a better errno than 0 here? */
set_errno_nohost(addrlist, 0, a->message, FAIL,
- testflag(a, af_pass_message));
+ testflag(a, af_pass_message), &sx->delivery_start);
sx->ok = FALSE;
break;
}
int len;
uschar * conf = NULL;
- timesince(&delivery_time, &start_delivery_time);
+ timesince(&delivery_time, &sx->delivery_start);
sx->send_rset = FALSE;
pipelining_active = FALSE;
actual host that was used. */
addr->transport_return = OK;
- addr->more_errno = delivery_time.tv_sec;
- addr->delivery_usec = delivery_time.tv_usec;
addr->host_used = host;
+ addr->delivery_time = delivery_time;
addr->special_action = flag;
addr->message = conf;
}
}
- set_errno(addrlist, save_errno, set_message, set_rc, pass_message, host
+ set_errno(addrlist, save_errno, set_message, set_rc, pass_message, host,
#ifdef EXPERIMENTAL_DSN_INFO
- , sx->smtp_greeting, sx->helo_response
+ sx->smtp_greeting, sx->helo_response,
#endif
- );
+ &sx->delivery_start);
}
/* If all has gone well, send_quit will be set TRUE, implying we can end the
socket_fd = pfd[1];
else
set_errno(sx->first_addr, errno, US"internal allocation problem",
- DEFER, FALSE, host
+ DEFER, FALSE, host,
# ifdef EXPERIMENTAL_DSN_INFO
- , sx->smtp_greeting, sx->helo_response
+ sx->smtp_greeting, sx->helo_response,
# endif
- );
+ &sx->delivery_start);
}
else
#endif
/* If RSET failed and there are addresses left, they get deferred. */
else
- set_errno(sx->first_addr, errno, msg, DEFER, FALSE, host
+ set_errno(sx->first_addr, errno, msg, DEFER, FALSE, host,
#ifdef EXPERIMENTAL_DSN_INFO
- , sx->smtp_greeting, sx->helo_response
+ sx->smtp_greeting, sx->helo_response,
#endif
- );
+ &sx->delivery_start);
}
}
if (f.dont_deliver)
{
- set_errno_nohost(addrlist, 0, NULL, OK, FALSE);
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ set_errno_nohost(addrlist, 0, NULL, OK, FALSE, &now);
for (address_item * addr = addrlist; addr; addr = addr->next)
{
addr->host_used = host;