--- qmail-smtpd.c.orig	Fri Apr 12 15:28:45 2002
+++ qmail-smtpd.c	Fri Apr 12 16:53:01 2002
@@ -91,6 +91,24 @@
   fakehelo = case_diffs(remotehost,helohost.s) ? helohost.s : 0;
 }
 
+/*
+ * Send the value of ETRN to stderr.
+ * James Raftery <james@now.ie>, 12 April 2002.
+ * Code from http://www.lamer.de/maex/creative/software/qmail/oldpatches/qmail-smtpd-loggin.diff
+ */
+char sserrbuf[512];
+substdio sserr = SUBSTDIO_FDBUF(write,2,sserrbuf,sizeof(sserrbuf));
+void logerr(s) char *s; { if(substdio_puts(&sserr,s) == -1) _exit(1); }
+void logerrf(s) char *s; { if(substdio_puts(&sserr,s) == -1) _exit(1); if(substdio_flush(&sserr) == -1) _exit(1); }
+
+stralloc etrnhost = {0};
+
+void doetrn(arg) char *arg; {
+  if (!stralloc_copys(&etrnhost,arg)) die_nomem(); 
+  if (!stralloc_0(&etrnhost)) die_nomem(); 
+  logerr("qmail-smtpd: ETRN: "); logerr(etrnhost.s); logerrf("\n");
+}
+
 int liphostok = 0;
 stralloc liphost = {0};
 int bmfok = 0;
@@ -227,9 +245,14 @@
   smtp_greet("250 "); out("\r\n");
   seenmail = 0; dohelo(arg);
 }
+
+/*
+ * Advertise ETRN capability(!) in response to EHLO.
+ * James Raftery <james@now.ie>, 12 April 2002.
+ */
 void smtp_ehlo(arg) char *arg;
 {
-  smtp_greet("250-"); out("\r\n250-PIPELINING\r\n250 8BITMIME\r\n");
+  smtp_greet("250-"); out("\r\n250-PIPELINING\r\n250-8BITMIME\r\n250 ETRN\r\n");
   seenmail = 0; dohelo(arg);
 }
 void smtp_rset()
@@ -237,6 +260,17 @@
   seenmail = 0;
   out("250 flushed\r\n");
 }
+
+/*
+ * React to ETRN command.
+ * James Raftery <james@now.ie>, 12 April 2002.
+ */
+void smtp_etrn(arg) char *arg;
+{
+  out("250 request noted, i'll try my best\r\n");
+  seenmail = 0; doetrn(arg);
+}
+
 void smtp_mail(arg) char *arg;
 {
   if (!addrparse(arg)) { err_syntax(); return; }
@@ -401,6 +435,7 @@
 , { "quit", smtp_quit, flush }
 , { "helo", smtp_helo, flush }
 , { "ehlo", smtp_ehlo, flush }
+, { "etrn", smtp_etrn, flush }
 , { "rset", smtp_rset, 0 }
 , { "help", smtp_help, flush }
 , { "noop", err_noop, flush }

