diff -urN ../exim-4.94.orig/src/daemon.c ./src/daemon.c --- ../exim-4.94.orig/src/daemon.c 2020-05-30 23:35:38.000000000 +0300 +++ ./src/daemon.c 2020-06-07 12:12:49.042131000 +0300 @@ -599,9 +599,42 @@ whether we have received too many messages in this session for immediate delivery. */ + +#define DEFAULT_ACCEPT_QUEUE_PER_CONNECTION 10 +int accept_queue_per_connection = -1; +if (smtp_accept_queue_per_connection != NULL) + { + uschar *expanded = expand_string(smtp_accept_queue_per_connection); + if (expanded == NULL) + { + if (!f.expand_string_forcedfail) + log_write(0, LOG_MAIN|LOG_PANIC, "expansion of smtp_accept_queue_per_connection " + "failed for message from %s: %s; fallback to default value %d", sender_fullhost, expand_string_message, DEFAULT_ACCEPT_QUEUE_PER_CONNECTION); + } + /* For speed, interpret a decimal number inline here */ + else + { + accept_queue_per_connection = 0; + uschar *s = expanded; + while (isdigit(*s)) + accept_queue_per_connection = accept_queue_per_connection * 10 + *s++ - '0'; + if (*s != 0) + { + log_write(0, LOG_MAIN|LOG_PANIC, "expansion of smtp_accept_queue_per_connection " + "for message from %s contains non-digit: %s; fallback to default value %d", sender_fullhost, expanded, DEFAULT_ACCEPT_QUEUE_PER_CONNECTION); + accept_queue_per_connection = DEFAULT_ACCEPT_QUEUE_PER_CONNECTION; + } + } + } +if (accept_queue_per_connection == -1) accept_queue_per_connection = DEFAULT_ACCEPT_QUEUE_PER_CONNECTION; + + +// if (!session_local_queue_only && +// smtp_accept_queue_per_connection > 0 && +// receive_messagecount > smtp_accept_queue_per_connection) if (!session_local_queue_only && - smtp_accept_queue_per_connection > 0 && - receive_messagecount > smtp_accept_queue_per_connection) + accept_queue_per_connection > 0 && + receive_messagecount > accept_queue_per_connection) { session_local_queue_only = TRUE; queue_only_reason = 2; @@ -637,9 +670,12 @@ "(%d, max %d)", smtp_accept_count, smtp_accept_queue); break; +// case 2: log_write(L_delay_delivery, +// LOG_MAIN, "no immediate delivery: more than %d messages " +// "received in one connection", smtp_accept_queue_per_connection); case 2: log_write(L_delay_delivery, LOG_MAIN, "no immediate delivery: more than %d messages " - "received in one connection", smtp_accept_queue_per_connection); + "received in one connection", accept_queue_per_connection); break; case 3: log_write(L_delay_delivery, diff -urN ../exim-4.94.orig/src/exim.c ./src/exim.c --- ../exim-4.94.orig/src/exim.c 2020-05-30 23:35:38.000000000 +0300 +++ ./src/exim.c 2020-06-07 12:12:49.043223000 +0300 @@ -5631,9 +5631,42 @@ will be TRUE. If it is not, check on the number of messages received in this connection. */ + +#define DEFAULT_ACCEPT_QUEUE_PER_CONNECTION 10 +int accept_queue_per_connection = -1; +if (smtp_accept_queue_per_connection != NULL) + { + uschar *expanded = expand_string(smtp_accept_queue_per_connection); + if (expanded == NULL) + { + if (!f.expand_string_forcedfail) + log_write(0, LOG_MAIN|LOG_PANIC, "expansion of smtp_accept_queue_per_connection " + "failed for message from %s: %s; fallback to default value %d", sender_fullhost, expand_string_message, DEFAULT_ACCEPT_QUEUE_PER_CONNECTION); + } + /* For speed, interpret a decimal number inline here */ + else + { + accept_queue_per_connection = 0; + uschar *s = expanded; + while (isdigit(*s)) + accept_queue_per_connection = accept_queue_per_connection * 10 + *s++ - '0'; + if (*s != 0) + { + log_write(0, LOG_MAIN|LOG_PANIC, "expansion of smtp_accept_queue_per_connection " + "for message from %s contains non-digit: %s; fallback to default value %d", sender_fullhost, expanded, DEFAULT_ACCEPT_QUEUE_PER_CONNECTION); + accept_queue_per_connection = DEFAULT_ACCEPT_QUEUE_PER_CONNECTION; + } + } + } +if (accept_queue_per_connection == -1) accept_queue_per_connection = DEFAULT_ACCEPT_QUEUE_PER_CONNECTION; + + +// if ( !session_local_queue_only +// && smtp_accept_queue_per_connection > 0 +// && receive_messagecount > smtp_accept_queue_per_connection) if ( !session_local_queue_only - && smtp_accept_queue_per_connection > 0 - && receive_messagecount > smtp_accept_queue_per_connection) + && accept_queue_per_connection > 0 + && receive_messagecount > accept_queue_per_connection) { session_local_queue_only = TRUE; queue_only_reason = 2; @@ -5672,9 +5705,12 @@ switch(queue_only_reason) { case 2: +// log_write(L_delay_delivery, +// LOG_MAIN, "no immediate delivery: more than %d messages " +// "received in one connection", smtp_accept_queue_per_connection); log_write(L_delay_delivery, LOG_MAIN, "no immediate delivery: more than %d messages " - "received in one connection", smtp_accept_queue_per_connection); + "received in one connection", accept_queue_per_connection); break; case 3: diff -urN ../exim-4.94.orig/src/globals.c ./src/globals.c --- ../exim-4.94.orig/src/globals.c 2020-05-30 23:35:38.000000000 +0300 +++ ./src/globals.c 2020-06-07 12:12:49.043626000 +0300 @@ -1439,10 +1439,12 @@ int smtp_accept_max = 20; int smtp_accept_max_nonmail= 10; uschar *smtp_accept_max_nonmail_hosts = US"*"; -int smtp_accept_max_per_connection = 1000; +//int smtp_accept_max_per_connection = 1000; +uschar *smtp_accept_max_per_connection = NULL; uschar *smtp_accept_max_per_host = NULL; int smtp_accept_queue = 0; -int smtp_accept_queue_per_connection = 10; +//int smtp_accept_queue_per_connection = 10; +uschar *smtp_accept_queue_per_connection = NULL; int smtp_accept_reserve = 0; uschar *smtp_active_hostname = NULL; uschar *smtp_banner = US"$smtp_active_hostname ESMTP " diff -urN ../exim-4.94.orig/src/globals.h ./src/globals.h --- ../exim-4.94.orig/src/globals.h 2020-05-30 23:35:38.000000000 +0300 +++ ./src/globals.h 2020-06-07 12:12:49.044009000 +0300 @@ -919,10 +919,12 @@ extern int smtp_accept_max; /* Max SMTP connections */ extern int smtp_accept_max_nonmail;/* Max non-mail commands in one con */ extern uschar *smtp_accept_max_nonmail_hosts; /* Limit non-mail cmds from these hosts */ -extern int smtp_accept_max_per_connection; /* Max msgs per connection */ +//extern int smtp_accept_max_per_connection; /* Max msgs per connection */ +extern uschar *smtp_accept_max_per_connection; /* Max msgs per connection */ extern uschar *smtp_accept_max_per_host; /* Max SMTP cons from one IP addr */ extern int smtp_accept_queue; /* Queue after so many connections */ -extern int smtp_accept_queue_per_connection; /* Queue after so many msgs */ +//extern int smtp_accept_queue_per_connection; /* Queue after so many msgs */ +extern uschar *smtp_accept_queue_per_connection; /* Queue after so many msgs */ extern int smtp_accept_reserve; /* Reserve these SMTP connections */ extern uschar *smtp_active_hostname; /* Hostname for this message */ extern uschar *smtp_banner; /* Banner string (to be expanded) */ diff -urN ../exim-4.94.orig/src/readconf.c ./src/readconf.c --- ../exim-4.94.orig/src/readconf.c 2020-05-30 23:35:38.000000000 +0300 +++ ./src/readconf.c 2020-06-07 12:12:49.044805000 +0300 @@ -297,10 +297,10 @@ { "smtp_accept_max", opt_int, {&smtp_accept_max} }, { "smtp_accept_max_nonmail", opt_int, {&smtp_accept_max_nonmail} }, { "smtp_accept_max_nonmail_hosts", opt_stringptr, {&smtp_accept_max_nonmail_hosts} }, - { "smtp_accept_max_per_connection", opt_int, {&smtp_accept_max_per_connection} }, + { "smtp_accept_max_per_connection", opt_stringptr, {&smtp_accept_max_per_connection} }, { "smtp_accept_max_per_host", opt_stringptr, {&smtp_accept_max_per_host} }, { "smtp_accept_queue", opt_int, {&smtp_accept_queue} }, - { "smtp_accept_queue_per_connection", opt_int, {&smtp_accept_queue_per_connection} }, + { "smtp_accept_queue_per_connection", opt_stringptr, {&smtp_accept_queue_per_connection} }, { "smtp_accept_reserve", opt_int, {&smtp_accept_reserve} }, { "smtp_active_hostname", opt_stringptr, {&raw_active_hostname} }, { "smtp_banner", opt_stringptr, {&smtp_banner} }, diff -urN ../exim-4.94.orig/src/smtp_in.c ./src/smtp_in.c --- ../exim-4.94.orig/src/smtp_in.c 2020-05-30 23:35:38.000000000 +0300 +++ ./src/smtp_in.c 2020-06-07 12:12:49.045797000 +0300 @@ -4580,8 +4580,40 @@ /* Check to see if the limit for messages per connection would be exceeded by accepting further messages. */ - if (smtp_accept_max_per_connection > 0 && - smtp_mailcmd_count > smtp_accept_max_per_connection) + +#define DEFAULT_ACCEPT_MAX_PER_CONNECTION 1000 +int accept_max_per_connection = -1; +if (smtp_accept_max_per_connection != NULL) + { + uschar *expanded = expand_string(smtp_accept_max_per_connection); + if (expanded == NULL) + { + if (!f.expand_string_forcedfail) + log_write(0, LOG_MAIN|LOG_PANIC, "expansion of smtp_accept_max_per_connection " + "failed for message from %s: %s; fallback to default value %d", host_and_ident(FALSE), expand_string_message, DEFAULT_ACCEPT_MAX_PER_CONNECTION); + } + /* For speed, interpret a decimal number inline here */ + else + { + accept_max_per_connection = 0; + uschar *s = expanded; + while (isdigit(*s)) + accept_max_per_connection = accept_max_per_connection * 10 + *s++ - '0'; + if (*s != 0) + { + log_write(0, LOG_MAIN|LOG_PANIC, "expansion of smtp_accept_max_per_connection " + "for message from %s contains non-digit: %s; fallback to default value %d", host_and_ident(FALSE), expanded, DEFAULT_ACCEPT_MAX_PER_CONNECTION); + accept_max_per_connection = DEFAULT_ACCEPT_MAX_PER_CONNECTION; + } + } + } +if (accept_max_per_connection == -1) accept_max_per_connection = DEFAULT_ACCEPT_MAX_PER_CONNECTION; + + +// if (smtp_accept_max_per_connection > 0 && +// smtp_mailcmd_count > smtp_accept_max_per_connection) + if (accept_max_per_connection > 0 && + smtp_mailcmd_count > accept_max_per_connection) { smtp_printf("421 too many messages in this connection\r\n", FALSE); log_write(0, LOG_MAIN|LOG_REJECT, "rejected MAIL command %s: too many "