--- ../qmail-1.03-zftoaster.14g/qmail-smtpd.c	2004-03-09 16:50:04.000000000 +0100
+++ qmail-smtpd.c	2004-03-11 10:34:46.000000000 +0100
@@ -166,6 +166,9 @@
 int tarpitdelay = 5;
 int sigsok = 0;
 stralloc sigs = {0};
+unsigned int tagauthinfo = 0;
+char *extauthinfo;
+void authinfo();
 
 void setup()
 {
@@ -195,6 +198,11 @@
   x = env_get("MFCHECK");
   if (x) { scan_ulong(x,&u); mfchk = u; }
 
+  if (control_readint(&tagauthinfo,"control/tagauthinfo") == -1) die_control();
+  x = env_get("TAGAUTHINFO");
+  if (x) { scan_ulong(x,&u); tagauthinfo = u; }
+  extauthinfo = env_get("AUTHINFO");
+
   bmfok = control_readfile(&bmf,"control/badmailfrom",0);
   if (bmfok == -1) die_control();
   if (!constmap_init(&mapbmf,bmf.s,bmf.len,0)) die_nomem();
@@ -956,6 +964,7 @@
   out("354 go ahead\r\n");
  
   received(&qqt,protocol,local,remoteip,remotehost,remoteinfo,fakehelo);
+  if (tagauthinfo) { authinfo(&qqt); }
   blast(&hops);
   hops = (hops >= MAXHOPS);
   if (hops) qmail_fail(&qqt);
@@ -1193,6 +1202,22 @@
   }
 }
 
+void authinfo(qqt)
+struct qmail *qqt;
+{
+  if (flagauth) {          /* authenticated user */
+    qmail_puts(qqt,"X-Authinfo: SMTP authenticated <");
+    qmail_puts(qqt,user.s);
+    qmail_puts(qqt,">\n");
+  } else if (extauthinfo) {    /* authentication by external source (SMTP-after-POP3) */
+    qmail_puts(qqt,"X-Authinfo: externally authenticated <");
+    qmail_puts(qqt,extauthinfo);
+    qmail_puts(qqt,">\n");
+  } else {                     /* no authentication info */
+    qmail_puts(qqt,"X-Authinfo: none\n");
+  }
+}
+
 #ifdef TLS
 stralloc proto = {0};
 int ssl_verified = 0;
