--- ../netqmail-1.05-smtp-auth/qmail-smtpd.c	2004-03-11 11:15:53.000000000 +0100
+++ qmail-smtpd.c	2004-03-11 11:18:28.000000000 +0100
@@ -110,6 +110,9 @@
 int bmfok = 0;
 stralloc bmf = {0};
 struct constmap mapbmf;
+unsigned int tagauthinfo = 0;
+char *extauthinfo;
+void authinfo();
 
 void setup()
 {
@@ -126,6 +129,11 @@
 
   if (rcpthosts_init() == -1) die_control();
 
+  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 (bmfok)
@@ -399,6 +407,7 @@
   out("354 go ahead\r\n");
  
   received(&qqt,"SMTP",local,remoteip,remotehost,remoteinfo,fakehelo);
+  if (tagauthinfo) { authinfo(&qqt); }
   blast(&hops);
   hops = (hops >= MAXHOPS);
   if (hops) qmail_fail(&qqt);
@@ -639,6 +648,22 @@
 
 /* this file is too long --------------------------------------------- GO ON */
 
+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");
+  }
+}
+
 struct commands smtpcommands[] = {
   { "rcpt", smtp_rcpt, 0 }
 , { "mail", smtp_mail, 0 }
