diff -ruN qmail-1.03/Makefile qmail-mysql/Makefile
--- qmail-1.03/Makefile	Mon Jun 15 19:53:16 1998
+++ qmail-mysql/Makefile	Fri Nov 12 17:54:59 1999
@@ -1,9 +1,17 @@
 # Don't edit Makefile! Use conf-* for configuration.
 
 SHELL=/bin/sh
+MYSQL_INCLUDE=-I/usr/local/include
+# for linux libc5
+# MYSQL_LIBS=/usr/local/lib/mysql/libmysqlclient.a -lm -lz -ldl
+# for Linux libc6
+MYSQL_LIBS=/usr/lib/mysql/libmysqlclient.a -lm -lz -lcrypt -lnsl -ldl
 
 default: it
 
+auto_du.c: conf-du
+	sh auto_du.sh
+
 addresses.0: \
 addresses.5
 	nroff -man addresses.5 > addresses.0
@@ -741,16 +749,16 @@
 
 install: \
 load install.o fifo.o hier.o auto_qmail.o auto_split.o auto_uids.o \
-strerr.a substdio.a open.a error.a str.a fs.a
+strerr.a substdio.a open.a error.a str.a fs.a stralloc.a alloc.a
 	./load install fifo.o hier.o auto_qmail.o auto_split.o \
-	auto_uids.o strerr.a substdio.a open.a error.a str.a fs.a 
+	auto_uids.o strerr.a substdio.a open.a error.a str.a fs.a  stralloc.a alloc.a
 
 install-big: \
 load install-big.o fifo.o install.o auto_qmail.o auto_split.o \
-auto_uids.o strerr.a substdio.a open.a error.a str.a fs.a
+auto_uids.o strerr.a substdio.a open.a error.a str.a fs.a stralloc.a alloc.a
 	./load install-big fifo.o install.o auto_qmail.o \
 	auto_split.o auto_uids.o strerr.a substdio.a open.a error.a \
-	str.a fs.a 
+	str.a fs.a stralloc.a alloc.a
 
 install-big.o: \
 compile install-big.c auto_qmail.h auto_split.h auto_uids.h fmt.h \
@@ -764,9 +772,9 @@
 
 instcheck: \
 load instcheck.o fifo.o hier.o auto_qmail.o auto_split.o auto_uids.o \
-strerr.a substdio.a error.a str.a fs.a
+strerr.a substdio.a error.a str.a fs.a stralloc.a alloc.a
 	./load instcheck fifo.o hier.o auto_qmail.o auto_split.o \
-	auto_uids.o strerr.a substdio.a error.a str.a fs.a 
+	auto_uids.o strerr.a substdio.a error.a str.a fs.a stralloc.a alloc.a
 
 instcheck.o: \
 compile instcheck.c strerr.h error.h readwrite.h exit.h
@@ -945,6 +953,9 @@
 compile myctime.c datetime.h fmt.h myctime.h
 	./compile myctime.c
 
+mysql.o: compile mysql.c auto_qmail.h
+	./compile mysql.c $(MYSQL_INCLUDE)
+
 ndelay.a: \
 makelib ndelay.o ndelay_off.o
 	./makelib ndelay.a ndelay.o ndelay_off.o
@@ -1109,9 +1120,12 @@
 
 qmail-getpw: \
 load qmail-getpw.o case.a substdio.a error.a str.a fs.a auto_break.o \
-auto_usera.o
+auto_usera.o stralloc.a alloc.a mysql.o
 	./load qmail-getpw case.a substdio.a error.a str.a fs.a \
-	auto_break.o auto_usera.o 
+	auto_break.o auto_usera.o \
+	stralloc.a alloc.a \
+	auto_qmail.o auto_uids.o \
+	mysql.o $(MYSQL_LIBS)
 
 qmail-getpw.0: \
 qmail-getpw.8
@@ -1129,7 +1143,7 @@
 compile qmail-getpw.c readwrite.h substdio.h subfd.h substdio.h \
 error.h exit.h byte.h str.h case.h fmt.h auto_usera.h auto_break.h \
 qlx.h
-	./compile qmail-getpw.c
+	./compile qmail-getpw.c $(MYSQL_INCLUDE)
 
 qmail-header.0: \
 qmail-header.5
@@ -1190,7 +1204,7 @@
 open.h wait.h lock.h seek.h substdio.h getln.h strerr.h subfd.h \
 substdio.h sgetopt.h subgetopt.h alloc.h error.h stralloc.h \
 gen_alloc.h fmt.h str.h now.h datetime.h case.h quote.h qmail.h \
-substdio.h slurpclose.h myctime.h gfrom.h auto_patrn.h
+substdio.h slurpclose.h myctime.h gfrom.h auto_patrn.h auto_du.c
 	./compile qmail-local.c
 
 qmail-log.0: \
@@ -1200,11 +1214,11 @@
 qmail-lspawn: \
 load qmail-lspawn.o spawn.o prot.o slurpclose.o coe.o sig.a wait.a \
 case.a cdb.a fd.a open.a stralloc.a alloc.a substdio.a error.a str.a \
-fs.a auto_qmail.o auto_uids.o auto_spawn.o
+fs.a auto_qmail.o auto_uids.o auto_spawn.o env.a str_diffn.o str_cpy.o
 	./load qmail-lspawn spawn.o prot.o slurpclose.o coe.o \
 	sig.a wait.a case.a cdb.a fd.a open.a stralloc.a alloc.a \
 	substdio.a error.a str.a fs.a auto_qmail.o auto_uids.o \
-	auto_spawn.o 
+	auto_spawn.o env.a str_diffn.o str_cpy.o
 
 qmail-lspawn.0: \
 qmail-lspawn.8
@@ -1288,11 +1302,11 @@
 
 qmail-popup: \
 load qmail-popup.o commands.o timeoutread.o timeoutwrite.o now.o \
-case.a fd.a sig.a wait.a stralloc.a alloc.a substdio.a error.a str.a \
+case.a fd.a sig.a wait.a stralloc.a alloc.a env.a substdio.a error.a str.a \
 fs.a socket.lib
 	./load qmail-popup commands.o timeoutread.o timeoutwrite.o \
 	now.o case.a fd.a sig.a wait.a stralloc.a alloc.a \
-	substdio.a error.a str.a fs.a  `cat socket.lib`
+	env.a substdio.a error.a str.a fs.a  `cat socket.lib`
 
 qmail-popup.0: \
 qmail-popup.8
diff -ruN qmail-1.03/README.mysql.en qmail-mysql/README.mysql.en
--- qmail-1.03/README.mysql.en	Thu Jan  1 09:00:00 1970
+++ qmail-mysql/README.mysql.en	Fri Mar 31 18:22:07 2000
@@ -0,0 +1,626 @@
+qmail + MYSQL
+
+http://www.softagency.co.jp/mysql/
+
+*****************
+What is this?
+*****************
+This patch provide next fuction to qmail-1.03
+
+ * Authentication by using MySQL
+ * Virtual Domain by using MySQL
+ * APOP (for checkpassword+mysql )
+ * Maildir size limitation by using MySQL
+
+
+*****************
+Changes
+*****************
+ver.0.6.6	2000-03-31	takeshi@softagency.co.jp 
+
+ * add: default_domain
+   Thanks TiTaNiC!
+
+--------------------
+ver.0.6.5	2000-01-29	takeshi@softagency.co.jp 
+
+ * fix: Segmentation Fault when (uid|gid)==NULL
+ * Note: change : if uid==0, invokes error.
+
+--------------------
+ver.0.6.4	2000-01-28	takeshi@softagency.co.jp 
+
+ * fix pass, user
+
+--------------------
+ver.0.6.3	2000-01-27	takeshi@softagency.co.jp 
+
+ * return error mail immediatly if Maildir is full.
+ * add ignore_validity
+
+--------------------
+ver.0.6.2	1999-12-02	takeshi@softagency.co.jp 
+
+ * FIX: Maildir quota
+
+--------------------
+ver.0.6.1	1999-11-12	takeshi@softagency.co.jp 
+
+ * add Maildir quota
+
+--------------------
+ver.0.6.0	1999-11-09	takeshi@softagency.co.jp
+
+ * add AUTH environment to qmail-popup.
+   this for checkpassword-mysql-0.6 APOP
+
+-------------------- 
+ver.0.4.1	1999-07-30	takeshi@softagency.co.jp
+
+ * disconnect MySQL session every each time.
+ * you can also set mbox_host to ''.
+
+-------------------- 
+ver.0.4.0	1999-06-17	takeshi@softagency.co.jp
+
+ * fix mysql.c :
+   1. sorry, i miss patch ver.0.3.2:
+       mysql_use, check_host keyword were dropped. this fixed.
+   2. for mysql-3.22.x C API
+   3. add `active' , `start_date', `expire_date' fields!
+       this is not compat old version!!   
+
+--------------------
+ver.0.3.2	1998.10.15	takeshi@softagency.co.jp
+
+ * fix mysql.c
+
+--------------------
+ver.0.3.1	1998.09.27	takeshi@softagency.co.jp
+
+ * fix mysql.c
+
+--------------------
+ver.0.3.0	1998.09.26	takeshi@softagency.co.jp
+
+ * Many Changes!
+   not user FAKEUSER (ver.0.1x, 0.2x)
+     -> remove 'conf-fake' file.
+        require 'uid, gid, home, shell field' on MySQL table!
+
+   many change  : mysql.c, qmail-getpw.c
+
+
+--------------------
+ver.0.2.1	1998.07.14	takeshi@softagency.co.jp
+
+ * fix bugs: cant send to root
+
+--------------------
+ver.0.2.0	1998.07.12	takeshi@softagency.co.jp
+
+ * Add function 'check host name'
+
+   This function check 'To:' fields first.
+
+   Example:
+     Mail header set 'To: user@host', then
+    the program  query 'user' and 'host' to MySQL.
+     if not,  qmail reject the mail.
+
+   Must add field 'mbox_host' to sql table.
+   Add keyword 'check_host' to /var/qmail/control/sqlserver
+
+
+--------------------
+ver.0.1.2	1998.06.21	takeshi@softagency.co.jp
+
+ * If the program found user directory,
+   qmail send the mail to this directory always,
+   though qmail not found user name not in mysql.
+
+--------------------
+ver.0.1.1	1998.05.24	takeshi@softagency.co.jp
+
+ * fix to qmail-1.02
+
+--------------------
+ver.0.1		1998.04.17	takeshi@softagency.co.jp
+
+ * initial release. (for qmail-1.01)
+
+
+
+*****************
+1.OverView
+*****************
+ Please patch to qmail-1.03
+
+ This patch change 'qmail-lspawn.c', 'qmail-getpw.c', 'Makefile', 'qmail-popup.c', 'qmail-local.c'
+
+
+Not only /etc/passwd but also a registered user on MySQL database is refered,
+when a mail is recieved on host and user read mail by using pop3.
+
+When a mail is recieved on host, qmail check /etc/passwd at first.
+If no user on /etc/passwd, qmail search MySQL database for user name.
+If qmail find the username on MySQL, it send the mail to under the directory [dir/username] that you specified when you compile programs. 
+
+              qmail
+                |
+                V
+           /etc/passwd -> ~user/Maildir/
+                |
+                V
+              MySQL
+                |
+                v
+          /userdir/Maildir/
+
+When a user read a mail by pop client, qmail-pop3d(checkpassword) check /etc/passwd at first.
+If no user on /etc/passwd, 'checkpassword' program refer to MySQL.
+
+
+and more function:
+ you can set effective flag to user account.
+ you can set start - end day to a account.
+
+
+*****************
+2.NO WARRANTY
+*****************
+
+There is NO WARRANTY for this patch.
+We don't have any responsibility for this patch.
+USE IT AT YOUR OWN RISK
+If you have any suggestions, modifications, addition, reports and bugs, please mail me.
+
+primary site:
+http://www.softagency.co.jp/mysql/
+
+takeshi@SoftAgency.co.jp
+
+
+
+**************************
+3.How to use MySQL-QMAIL
+**************************
+
+----------------------------------
+3-1. /var/qmail/control/sqlserver
+----------------------------------
+
+Create a file /var/qmail/control/sqlserver as bellow: 
+
+Example:
+  mysql_use     yes
+  server        localhost
+  login         askonly
+  password      oshienai
+  db            db1
+  table         table1
+  check_host    yes
+  quota         yes
+  ignore_validity yes
+
+Description:
+ mysql_use     if yes is set, qmail refer userid on MySQL database. 
+ server        Servername of MySQL
+ login         Username of MySQL database(need to register on mysql in advance)
+ password      Password of MySQL database
+ db            Name of database.
+ table         Name of table.
+
+ check_host    yes : you can manage Virtual Domain by using MySQL.
+                      if a mail have 'To: user1@domain1' line,
+                      qmail-mysql search `user1' & `domain1' on `id' & `mbox_host' fields.
+                no: qmail-mysql seach ONLY `id' field. don't check domain .
+                default is no.
+
+ default_domain  this keyword used when check_host is yes.
+                 you can skip this.
+                 if you set this, when qmail recieve `To: user',
+                  MySQL check "mbox_host='' OR mbox_host=default_domain"
+
+ port          MySQL sever port number
+                default 3306. you can skip this
+
+ socket        MySQL server socket file
+                default /tmp/mysql.sock . you can skip this
+
+ quota         yes: you can set Maildir quota for users who are entried into MySQL database.
+                no: no limit.
+                default: no
+
+ ignore_validity    yes: ignore start_date , expire_date.
+                     default is no.
+
+----------------------------------
+3-2. Create table
+----------------------------------
+
+Make sure to make these fields on table.
+
+  id , uid, gid, home, shell, mbox_host, active, start_date, expire_date, quota_size
+
+  id :		username to refer.
+  uid :		user id. (int)
+  gid :		group id. (int)
+  home :	user's home directory path.(Full path.  char)
+  shell :	user's shell. (char)
+
+  mbox_host :	When `check_host' keyword is set to `yes', qmail-mysql use this field.
+		if reciver of mail is `user1@domain1' , mysql check 
+		  id = 'user1' AND mbox_host = 'domain1' .
+
+		if a mail have ONLY 'To: user1' , qmail-mysql check
+		  id = 'user1' AND (mbox_host IS NULL OR mbox_host='') .
+
+		if you don't use this function,
+		qmail-mysql check only user-name on `id' field .
+		In this case, if you have duplicate user-name on `id' field,
+		qmail-mysql return first user's attributes. please attention.
+
+  active:	set active flag.
+
+  start_date:
+  expire_date:	start_date <= account effective <expire_date
+
+  quota_size :	quota_size (Kbytes).
+		this field are only referd
+		when you set 'quota_check' keyword in sqlserver file.
+                this values MUST >= 0 , INTEGER.
+                if this value is 0, then no limit.
+
+example:
+
+CREATE TABLE users (
+  id char(32) DEFAULT '' NOT NULL,
+  crypt char(32) binary DEFAULT '' NOT NULL,
+  passwd char(32) binary DEFAULT '' NOT NULL,
+  uid int(10) unsigned DEFAULT '65534' NOT NULL,
+  gid int(10) unsigned DEFAULT '65534' NOT NULL,
+  shell char(100) binary DEFAULT '' NOT NULL,
+  home char(100) binary DEFAULT '' NOT NULL,
+  mbox_host char(64) NOT NULL,
+  start_date date DEFAULT '0000-00-00' NOT NULL,
+  expire_date date DEFAULT '2030-01-01' NOT NULL,
+  active enum('Y','N') DEFAULT 'Y' NOT NULL,
+  quota_size int unsigned DEFAULT '0' NOT NULL,
+  KEY id (id(10)),
+  KEY shell (shell(10)),
+  KEY home (home(20)),
+  KEY start_date (start_date),
+  KEY expire_date (expire_date),
+  KEY active (active)
+);
+
+
+
+----------------------------------
+3-3. Create User's home directory
+----------------------------------
+
+Make a user directory of a user on MySQL.
+
+You must set 'chown' same uid,gid fields.
+
+For example:
+ MySQL table
+    id     |  uid  | gid  |  home               | shell
+  ---------+-------+------+---------------------+-----------
+  username |  1234 | 5678 | /somewhere/username | /bin/false
+
+
+ Operation
+    mkdir /somewhere/username
+    maildirmake  /somewhere/username/Maildir
+    chown -R 1234 /somewhere/username/
+    chgrp -R 5678 /somewhere/username/
+
+Note
+
+   * user's home directory permission MUST be readable by qmail.
+     in many case, this will be drwxr-xr-x.
+   * you can set same uid,gid to all users who are entried into MySQL.
+     but in this case, you should pay attention.
+
+Example:
+
+ls -la
+drwxr-xr-x    3 1234    5678      1024 Jan  8 16:21 ./
+drwxr-xr-x    6 root    root      1024 Sep  2 20:49 ../
+drwx------    5 1234    5678      1024 Jul 11  1998 Maildir/
+
+this `ls -la' done at user's home directory.
+where `1234' is a user's uid. `5678' is a user's gid.
+
+
+
+*****************
+4.To compile
+*****************
+
+GNU gzip, tar, patch needed.
+
+1. get qmail-mysql-patch & qmail
+
+2. gunzip qmail-mysql-patch.gz
+
+3. extract qmail-1.03.tar.gz
+
+4. cd qmail-1.03
+
+5. patch -p1 < /path/to/qmail-mysql-patch
+
+6. edit Makefile
+   MYSQL_INCLUDE=-I/usr/local/include
+   MYSQL_LIBS=-L/usr/local/lib/mysql -lmysqlclient -lm -lz -ldl
+
+  MYSQL_INCLUDE : mysql include directory.
+  MYSQL_LIBS : mysql libraries.
+               this is not same on all platforms.
+               if you don't know what libraries need, then
+                  see mysql-x.x.x/Makefile , mysql-x.x.x/config.log
+                  ldd /path/to/mysql
+
+7. edit conf-*
+   `conf-du' file is used for `quota_check'
+
+8. please read INSTALL.ids
+   if you don't have qmail's uid, gid, then add
+
+9. make
+
+
+*************
+Debugging....
+*************
+for debugging, `mysqld --log' and mail log file are useful.
+almost reason of errors:
+
+  1. incorrect user's home directory permission. this is top.
+     user's home directory permission MUST be readable by qmail. but
+     unwritable by others. in many case, this will be drwxr-xr-x.
+  2. incorrect MySQL & /var/qmail/control/sqlserver file setting.
+  3. incorrect /var/qmail/control/* file setting.
+
+Example of home directory permission:
+
+ls -la
+drwxr-xr-x    3 1234    5678      1024 Jan  8 16:21 ./
+drwxr-xr-x    6 root    root      1024 Sep  2 20:49 ../
+drwx------    5 1234    5678      1024 Jul 11  1998 Maildir/
+
+this `ls -la' done at user's home directory.
+where `1234' is a user's uid. `5678' is a user's gid.
+
+when you get error, you MUST see MySQL log file and mail log file!
+MySQL log say `SELECT' line?
+The `SELECT' return right result, even if you exec by manual (ex. using
+mysql command.)?
+What mail log file say?
+qmail error provide error number such like (#5.1.1)
+
+It is NOT useful that you say ONLY platform(Distribution name) to me.
+ex. `I use LetHot5.x. do you know why?'
+i don't know.
+needed things are:
+
+  1. what MySQL log file say
+  2. what mail log file say
+  3. /var/qmail/control/sqlserver file
+  4. mysqlbug scripts report
+  5. compile flags for qmail+MySQL
+  6. result of ldd /usr/local/bin/mysql
+  7. library version. ( `ls ..../libc*` ; ex. libc.so.5.4.46 )
+  8. your OS name ( do `uname -a`)
+
+distribution name and kernel version are NOT useful for debugging!
+because, this is application that have nothing to do with inside Kernel.
+and, I use Debian/GNU Linux distribution (sometimes i use Solaris, freebsd),
+so, other distribution name have nothing hint.
+
+
+*****************
+5. check
+*****************
+you can check mysql version qmail-getpw by following:
+ example:
+   shell #  ./qmail-getpw user1 somewhere.com
+   user1123465534/somewhere/username
+
+ this command return id,uid,gid,home
+
+ if it can't find a user, this return `qmail alias'.
+   example:
+     shell # ./qmail-getpw u1 a
+     alias7065534/var/qmail/alias-u1
+
+if you start mysqld with --log option,
+please see mysql log.
+
+
+
+***************************
+6. limit Mailbox file size
+***************************
+this patch check user's mail files size.
+but this doesn't use OS's quota system.
+this patch check user's mail by using UNIX `du' command!!!!
+
+----------------------
+6-1. setup(how to use)
+----------------------
+
+If you limit usrs's mail file size,
+you can this by following step:
+
+ 0. edit conf-du and rebuild.
+
+ 1. create `quota_size' field into your MySQL Table.
+    this field MUST be:
+        unsigned DEFAULT 0 NOT NULL
+
+ 2. write next line into /var/qmail/control/sqlserver file
+       quota  yes
+
+ 3. set quota_size for user.
+    this is Kilo Bytes!!!
+    quota_size = 0 means NO LIMIT.
+
+
+conf-du
+ this patch except `du -ks` result in next format:
+
+  12345678  Maildir
+
+ in regex format
+
+  [^\s*[:digit:]+\s+]
+
+ if your `du -ks` return other format, please write other program(scripts) by yourself.
+
+
+
+------------------------------
+6-2. if a user's dir is full?
+------------------------------
+If a user's dir is full, then a mail to the user are defered to send to.
+This means that, this mail is queued into qmail's spool directory!
+qmail try to send the mail after.
+qmail spools deferred mail during 7 days by default.
+If you want to short this queue time, please edit
+/var/qmail/control/queuelifetime file.
+ex. if you want to set 1 day:
+86400
+
+note:
+ver.0.6.3 return error mail immediatly.
+
+
+------------------------------
+6-3. inside this quota
+------------------------------
+this patch work:
+
+1. qmail-lspawn invoke qmail-getpw
+
+2. qmail-getpw get quota_size from MySQL
+3. qmail-getpw write this quota_size to FD 3
+
+4. qmail-lspawn read quota_size from FD 3
+5. qmail-lspawn set `MAIL_QUOTA_SIZE' environment to this quota_size.
+
+6. qmail-lspawn invokes qmail-local
+
+7. qmail-local get quota_size from `MAIL_QUOTA_SIZE' environment
+8. if quota_size > 0, qmail-local invokes 'du -ks ./Maildir/'
+
+
+
+**************************************
+7. checking mbox_host (Virtual Domain)
+**************************************
+if you want to check host_part of mail recpt,
+please write
+
+check_host yes
+
+into /var/qmail/control/sqlserver file.
+
+in this case, MySQL table must have mbox_host field.
+
+if a mail's rcpt is username only (not has host part),
+MySQL check mbox_host='' record.
+
+----------
+if you already use checkpassword-mysql ,
+and if you want to use 'check_host yes' for checkpassword ONLY,
+don't want to use 'check_host yes' for qmail,
+please change
+
+mysql.c :
+static char *config_key =.....
+                         ...  "check_host"
+
+my checkpassword-mysql & qmail-mysql see same `sqlserver' file
+and same keywords, so, please change keyword.
+
+
+
+************************************
+8. APOP
+************************************
+this patch add AUTH environment into qmail-popup.c .
+
+when user send server `APOP',
+
++OK
+APOP username 64738962846
+
+qmail-popup set "apop" to AUTH environment.
+
+checkpassword-mysql-0.6(and later) and chekpwd(this from qmail.org)
+see this `AUTH' environment.
+
+
+APOP work with MySQL-3.23.2 higher.
+
+
+*****************
+8.Note
+*****************
+If you set mysql+qmail to follows, please pay attention to qmail+mysql settings.
+
+Conditions:
+  1. you write /var/qmail/control/virtualdomains
+ AND
+  2. you set virtualdomains prepend  to mysql accounted owner.
+ AND
+  3. you set 'check_host  yes' on /var/qmail/control/sqlserver.
+
+
+******************
+Maildir??
+******************
+qmail send local user's mail to user's Maildir directory.
+
+if you use Maildir directory,
+  qmail-start ./Maildir/
+
+this line is written in /var/qmail/bin/rc or your system start up file.
+
+How to make Maildir?
+  /var/qmail/bin/maildirmake ~user/Maildir
+
+
+
+******************
+QMAIL Flow
+******************
+
+ver. 0.6.1
+                         qmail-inject      qmail-smtpd
+                                \             /
+                                 \           /
+                                  qmail-queue  ... [qmail-clean]
+                                       |
+                                       |
+                                 [qmail-send]
+                                 /           \
+                                /             \
+MySQL ... qmail-getpw ... [qmail-lspawn]  [qmail-rspawn]
+                               ||             ||
+                               ||             ||
+                   du ... qmail-local     qmail-remote
+
+RED : qmail-mysql patch
+in version 0.1.x, i modifed only qmail-getpw . this was simple. (i like
+simple.)
+ver. 0.2 - 0.4, i modified qmail-lspawn to checking host_part (virtual
+domain).
+in 0.6, i also modified qmail-local , qmail-popup (for APOP, limit size)
+.... hummm....
+
+**************** END ***************
diff -ruN qmail-1.03/TARGETS qmail-mysql/TARGETS
--- qmail-1.03/TARGETS	Mon Jun 15 19:53:16 1998
+++ qmail-mysql/TARGETS	Fri Nov 12 18:44:37 1999
@@ -1,3 +1,5 @@
+mysql.o
+auto_du.c
 auto-ccld.sh
 make-load
 find-systype
diff -ruN qmail-1.03/auto_du.sh qmail-mysql/auto_du.sh
--- qmail-1.03/auto_du.sh	Thu Jan  1 09:00:00 1970
+++ qmail-mysql/auto_du.sh	Fri Nov 12 17:53:42 1999
@@ -0,0 +1,5 @@
+#!/bin/sh
+A=`head -1 conf-du`
+cat <<EOF > auto_du.c
+static char DUCOM[]="$A";
+EOF
diff -ruN qmail-1.03/conf-du qmail-mysql/conf-du
--- qmail-1.03/conf-du	Thu Jan  1 09:00:00 1970
+++ qmail-mysql/conf-du	Fri Nov 12 18:21:20 1999
@@ -0,0 +1,22 @@
+du -ks
+
+Please write disk check command in 1st line!
+This command MUST return Kilobytes and SUM!
+I assume that this command return next format(GNU fileutility's du)
+
+shell# du -ks Maildir
+12345   Maildir
+
+If your `du' command doesn't return in this format,
+please make wrapper scripts and specify them in file.
+
+ex.:
+write du.sh
+------
+#!/bin/sh
+du -..... $1 | awk....|sed....
+-----
+and, write into line1
+-----
+/full/path/du.sh
+-----
diff -ruN qmail-1.03/mysql.c qmail-mysql/mysql.c
--- qmail-1.03/mysql.c	Thu Jan  1 09:00:00 1970
+++ qmail-mysql/mysql.c	Fri Mar 31 18:06:05 2000
@@ -0,0 +1,362 @@
+/*
+ 1999-06-17
+  change select ....
+   append active, start_date, expire_date field.
+  fix up to 3.22.x
+   mysql_real_connect
+   need port, socket, parameters...
+
+ 1999-07-22
+  change : close connection each times. -> keepalive flag ignored.
+
+ 1999-11-09
+  add sleep()
+  add quota keyword. but not work yet.
+
+ 1999-12-02
+  fix & chenge : qmail-local.c quota functions.
+
+ 2000-01-27
+  return error mail if Maildir is full
+  add ignore_validity
+ 2000-01-28
+  fix Cuser, Cpass
+
+ 2000-02-28
+  fix Segmentation Fault when (uid|gid)==NULL
+  invokes error when uid==0
+
+ 2000-03-21
+  added default_domain and sep_char option into config file, this two option
+  enables you to specify the default domain if any user log in without domain
+  specification, and  enables to specify the username - domain separate
+  characters (TiTaNiC)
+ */
+
+#include <stdio.h>
+#include <mysql/mysql.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "stralloc.h" 
+#include "auto_qmail.h"
+
+#define LEN_SERV   60
+#define LEN_LOGIN  16
+#define LEN_TABLE  64
+char   *SVname, *Cuser, *Cpass, *Dname, *TBname, *DefDom;
+int Port_num=0;
+char *Socket_file=NULL;
+
+#define LEN_BUFFER LEN_TABLE+20
+
+int    mysql_keepopen=1;
+int    mysql_acct_keepopen;
+int    mysql_use=1;
+int	check_host=0;
+int    check_quota=0;
+
+int    myAUTH_ignore_validity=0;
+
+MYSQL  real_mysql, *mysql = NULL;
+MYSQL_RES      *result;
+
+#define TRY_N 10
+
+static char *config_key[] = {
+  "server", "login", "password", "db", "table",
+  "keepon","mysql_use","check_host",
+  "port", "socket",
+  "quota",
+  "ignore_validity",
+  "default_domain",
+  NULL };
+
+int Get_cfg_pair (char *s, char **val);
+
+extern stralloc tmpname;
+extern stralloc tmphome;
+extern stralloc tmpshell;
+extern unsigned long tmpquota;
+
+/*****************************************************/
+void set_flags_yes(char *value, int *flags, int num)
+{
+  if (strncasecmp(value, "yes", 3) == 0)
+  { *flags = 1;
+    /* log_err("mysql init : %s = yes\n",config_key[num]); */
+  }
+  else { *flags = 0; }
+}
+
+char *set_flags_str(char *value, char *flags, int num)
+{
+  char *new=NULL;
+  if (flags != NULL) { free(flags); }
+  new = (char *)malloc( sizeof(char)*(strlen(value)+1) );
+  if (new != NULL) strcpy(new,value);
+  /* log_err("mysql init : %s = %s\n",config_key[num],new); */
+  return new;
+}
+
+/*****************************************************/
+int
+Mysql_Init()
+{
+  FILE    *sqlfd;
+  char    buffer[128], sqlfile[128], value[LEN_TABLE+2], *dummy;
+
+  SVname = (char *)malloc(2);  strcpy(SVname,"");
+  Cuser  = (char *)malloc(2);  strcpy(Cuser, "");
+  Cpass  = (char *)malloc(2);  strcpy(Cpass, "");
+  Dname  = (char *)malloc(10); strcpy(Dname, "dbname");
+  TBname = (char *)malloc(12); strcpy(TBname,"usertable");
+  DefDom = (char *)malloc(2); strcpy(DefDom,"");
+
+  mysql_use = 1;
+
+  /******** read %s/control/sqlserver file *****/
+  sprintf(sqlfile, "%s/control/sqlserver", auto_qmail);
+  if((sqlfd = fopen(sqlfile, "r")) == (FILE *)NULL) {
+    mysql_use = 0;
+    return(mysql_use);
+  }
+
+  while(fgets(buffer, sizeof(buffer), sqlfd) != (char *)NULL) {
+
+    if(buffer[0] == '#' || buffer[0] == '\0' || buffer[0] == '\n') {
+      continue;
+    }
+
+    dummy = &value[0];
+    switch (Get_cfg_pair(buffer, &dummy))
+      {
+      case 0:
+	SVname = set_flags_str(value, SVname, 0);	break;
+      case 1:
+	Cuser = set_flags_str(value, Cuser, 1);	break;
+      case 2:
+	Cpass = set_flags_str(value, Cpass, 2);	break;
+      case 3:
+	Dname = set_flags_str(value, Dname, 3);	break;
+      case 4:
+	TBname = set_flags_str(value, TBname, 4);	break;
+
+      case 5:
+	set_flags_yes(value, &mysql_keepopen, 5);	break;
+      case 6:
+	set_flags_yes(value, &mysql_use, 6);	break;
+      case 7:
+	set_flags_yes(value, &check_host, 7);	break;
+
+      case 8:
+	Port_num = atoi(value);	break;
+
+      case 9:
+	Socket_file = set_flags_str(value, Socket_file, 9);	break;
+
+      case 10:
+	set_flags_yes(value, &check_quota, 10);	break;
+
+      case 11:
+	set_flags_yes(value, &myAUTH_ignore_validity, 11);	break;
+
+      case 12:
+        DefDom = set_flags_str(value, DefDom, 13);	break;
+      
+      default:
+	break;
+      }
+  }
+  fclose(sqlfd);
+
+  if (mysql_use==0) { check_host=0; check_quota=0; myAUTH_ignore_validity=1; }
+
+  return(0);
+}
+
+int
+Get_cfg_pair(char *s, char **val)
+{
+  int i, n, ret;
+  char dum[LEN_TABLE+1];
+
+  n = sizeof(config_key) / sizeof(char *);
+
+  while (*s == ' ' || *s == '\t' || *s == '\n') {s++;}
+  i=0;
+  while (*(s+i) != ' ' && *(s+i) != '\t' && *(s+i) != '\0' && i< sizeof(dum)) { i++;}
+  strncpy(dum, s, i); dum[i]='\0';
+  s=s+i;
+
+  i=0;
+  while (i<n && config_key[i] != NULL && strcmp(dum,config_key[i]) != 0 ) { i++; }
+  if (i>=n) return(-1);
+  ret = i;
+
+  while ( *s==' ' || *s=='\t' || *s=='\n') {s++;}
+  i=0;
+  while ( *(s+i)!=' ' && *(s+i)!='\t' && *(s+i)!='\n' && *(s+i)!='\0'  && i< sizeof(dum)) {i++;}
+  strncpy(dum, s, i); dum[i]='\0';
+  sprintf(*val, "%s", dum);
+
+  if (strlen(*val)<1) {
+    return -1;
+  }
+  if ( ret == n-1) { return -1; }
+  return ret;
+}
+
+
+/**********************************************/
+/**********************************************/
+/**********************************************/
+int
+Mysql_Reconnect()
+{
+  int i ;
+
+  i = 0; 
+  while(i<TRY_N) { /* Try it 10 Times  */
+    mysql_init(&real_mysql);
+       if (!(mysql=mysql_real_connect(&real_mysql, SVname, Cuser, Cpass
+				,NULL, Port_num, Socket_file, 0))) {
+	 mysql = NULL;
+       } else {
+	 mysql = &real_mysql;
+	 break;
+       }
+       i++;
+       sleep(3);
+  }
+
+  if (mysql != NULL) {
+     i = 0; 
+     while(i<TRY_N) { /* Try it 10 Times */
+        if  (mysql_select_db(mysql, Dname)) {
+	} else {
+	  return(0);
+	}
+       i++;
+       sleep(3);
+     }
+  }
+
+  return(-1);
+}
+
+
+/*******************************/
+void
+My_Mysql_Close(int keepopen_flag)
+{
+  if(keepopen_flag == 0) { 
+    /* Close the connection after each record */
+    if (mysql != NULL) {
+      mysql_close(mysql);
+    }
+    mysql = NULL;
+  }
+}
+
+
+/**************************************/
+int
+Check_User_Mysql(char *username, char *aaa, int L, int *uid, int *gid)
+{
+  char            buf[1024];
+  int             err, num, len;
+  MYSQL_ROW row;
+
+  if (mysql_use == 0) return(0);
+
+  /*=======================*/
+  if (mysql == NULL)
+  {
+    err = Mysql_Reconnect();
+    if (err == -1) { return(0); }
+  }
+
+  /*=======================*/
+  strcpy(buf, "SELECT id,uid,gid,home,shell");
+
+  if (check_quota == 1) { strcat(buf,",quota_size"); }
+
+  if (check_host==1)
+  {
+    if (L>0) {
+      sprintf(buf, "%s FROM %s WHERE id='%s' AND mbox_host='%s'", buf,
+	      TBname, username, aaa);
+    }
+    else {
+      sprintf(buf, "%s FROM %s WHERE id='%s' AND (mbox_host IS NULL OR mbox_host=''"
+	      ,buf, TBname, username);
+
+      if (strlen(DefDom)>0) {
+	strcat(buf, " OR mbox_host='");
+	strcat(buf,DefDom);
+	strcat(buf, "'");
+      }
+
+      strcat(buf,")");
+    }
+  }
+  else {
+    sprintf(buf, "%s FROM %s WHERE id='%s'", buf, TBname, username);
+  }
+
+  strcat(buf, " AND active=1");
+  if (myAUTH_ignore_validity != 1) {
+    strcat(buf, " AND start_date<=curdate() AND expire_date>curdate()");
+  }
+
+  if ( mysql_query(mysql, buf) < 0 || !(result=mysql_store_result(mysql)) )
+  {
+    return(0);
+  }
+
+  num = mysql_num_rows(result);
+
+  if (num != 1)
+    {
+      mysql_free_result(result);
+      My_Mysql_Close(0);
+      return(0);
+    }
+
+  row=mysql_fetch_row(result);
+
+  if (row[0] == NULL) { goto error_exit; }
+  if (row[1] == NULL) { goto error_exit; }
+  if (row[2] == NULL) { goto error_exit; }
+  if (row[3] == NULL) { goto error_exit; }
+  if (row[4] == NULL) { goto error_exit; }
+
+  stralloc_copys(&tmpname, row[0]);
+  stralloc_0(&tmpname); 
+
+  stralloc_copys(&tmphome, row[3]);
+  stralloc_0(&tmphome);
+
+  stralloc_copys(&tmpshell, row[4]);
+  stralloc_0(&tmpshell);
+
+  *uid = atoi(row[1]);
+  *gid = atoi(row[2]);
+  if (*uid == 0) { return (0); }
+
+  if (check_quota == 1) {
+    if (row[5] == NULL) { tmpquota=0; }
+    else if ( atol(row[5]) > 0 ) { tmpquota=atol(row[5]); }
+  }
+
+  mysql_free_result(result);
+  My_Mysql_Close(0);
+  return(num);
+
+ error_exit:
+      mysql_free_result(result);
+      My_Mysql_Close(0);
+      return(0);
+}
diff -ruN qmail-1.03/qmail-getpw.c qmail-mysql/qmail-getpw.c
--- qmail-1.03/qmail-getpw.c	Mon Jun 15 19:53:16 1998
+++ qmail-mysql/qmail-getpw.c	Tue Nov  9 17:38:44 1999
@@ -14,6 +14,14 @@
 #include "auto_break.h"
 #include "qlx.h"
 
+/************************************/
+#include "stralloc.h"
+#include "auto_uids.h"
+#include "auto_qmail.h"
+#include <mysql/mysql.h>
+
+/************************************/
+
 #define GETPW_USERLEN 32
 
 char *local;
@@ -21,10 +29,29 @@
 char *dash;
 char *extension;
 
+/************************************/
+stralloc mbox_host={0};
+
+extern int mysql_use , mysql_keepopen;
+int ncount=0;
+
+int Check_User_Mysql (char *username, char *aaa, int L, int *UID, int *GID);
+void My_Mysql_Close(int keepopen_flag);
+int Mysql_Init();
+
+struct passwd pwtmp;
+/*char *tmpname, *tmphome, *tmpshell;*/
+stralloc tmpname={0};
+stralloc tmphome={0};
+stralloc tmpshell={0};
+unsigned long tmpquota=0;
+
+/************************************/
 int userext()
 {
   char username[GETPW_USERLEN];
   struct stat st;
+  int uid, gid;
 
   extension = local + str_len(local);
   for (;;) {
@@ -36,32 +63,59 @@
 	errno = 0;
 	pw = getpwnam(username);
 	if (errno == error_txtbsy) _exit(QLX_SYS);
-	if (pw)
-	  if (pw->pw_uid)
-	    if (stat(pw->pw_dir,&st) == 0) {
-	      if (st.st_uid == pw->pw_uid) {
-		dash = "";
-		if (*extension) { ++extension; dash = "-"; }
-		return 1;
-	      }
+
+	if (!(pw) && mysql_use==1)
+	{
+	  ncount = Check_User_Mysql(username, mbox_host.s, mbox_host.len, &uid, &gid);
+	  if (ncount > 0)
+	  {
+	      pwtmp.pw_name = tmpname.s;
+	      pwtmp.pw_uid = uid; pwtmp.pw_gid = gid;
+	      pwtmp.pw_dir = tmphome.s;
+	      pwtmp.pw_shell = tmpshell.s;
+	      pw = &pwtmp;
+	  }
+	  My_Mysql_Close(0);
+	}
+
+        if (pw) {
+          if (pw->pw_uid) {
+            if (stat(pw->pw_dir,&st) == 0) {
+              if (st.st_uid == pw->pw_uid) {
+                dash = "";
+                if (*extension) { ++extension; dash = "-"; }
+                return 1;
+              }
+            }
+            else {
+              if (error_temp(errno)) _exit(QLX_NFS);
 	    }
-	    else
-	      if (error_temp(errno)) _exit(QLX_NFS);
+	  } /* if (pw->pw_uid) */
+	} /* if (pw) */
       }
     if (extension == local) return 0;
     --extension;
   }
 }
 
+
 char num[FMT_ULONG];
 
 void main(argc,argv)
 int argc;
 char **argv;
 {
+  int i;
   local = argv[1];
   if (!local) _exit(100);
 
+  if (argc>2) {
+    stralloc_copys(&mbox_host, argv[2]);
+    stralloc_0(&mbox_host);
+  }
+
+  Mysql_Init();
+
   if (!userext()) {
     extension = local;
     dash = "-";
@@ -82,6 +136,10 @@
   substdio_put(subfdoutsmall,"",1);
   substdio_puts(subfdoutsmall,extension);
   substdio_put(subfdoutsmall,"",1);
+
+  substdio_put(subfdoutsmall,num,fmt_ulong(num,(long) tmpquota) );
+  substdio_put(subfdoutsmall,"",1);
+
   substdio_flush(subfdoutsmall);
 
   _exit(0);
diff -ruN qmail-1.03/qmail-local.c qmail-mysql/qmail-local.c
--- qmail-1.03/qmail-local.c	Mon Jun 15 19:53:16 1998
+++ qmail-mysql/qmail-local.c	Thu Jan 27 13:15:12 2000
@@ -1,3 +1,5 @@
+#include <stdio.h>
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include "readwrite.h"
@@ -74,6 +76,42 @@
 void tryunlinktmp() { unlink(fntmptph); }
 void sigalrm() { tryunlinktmp(); _exit(3); }
 
+#include "auto_du.c"
+unsigned long quota_size=0;
+
+int Check_quota(dir)
+     char *dir;
+{
+ int loop;
+ FILE *fp, *fp1;
+ stralloc ducomm={0};
+ char bbb[21], *bt;
+
+ if (quota_size >0)
+ {
+   stralloc_copys(&ducomm,DUCOM);
+   stralloc_cats(&ducomm, " ");
+   stralloc_cats(&ducomm, dir);
+   stralloc_0(&ducomm);
+
+   fp = popen(ducomm.s,"r");
+   if (fp == NULL) { return 6; }
+   bt = bbb;
+   if (fgets(bbb, 20, fp) != NULL)
+   {
+     while (*bt==' '||*bt=='\t') {bt++;}
+     if (bt - bbb > 20) { return 6; }
+     while (*bt!=' ' && *bt!='\t' && *bt!='\0') {bt++;}
+     if (bt - bbb > 20) { return 6; }
+     *bt = '\0';
+
+     if (quota_size < atol(bbb)) { return 5; }
+   }
+   else { return 6; }
+ }
+ return 0;
+}
+
 void maildir_child(dir)
 char *dir;
 {
@@ -86,6 +124,7 @@
  int fd;
  substdio ss;
  substdio ssout;
+ int eee;
 
  sig_alarmcatch(sigalrm);
  if (chdir(dir) == -1) { if (error_temp(errno)) _exit(1); _exit(2); }
@@ -107,6 +146,7 @@
   }
  str_copy(fnnewtph,fntmptph);
  byte_copy(fnnewtph,3,"new");
+ /* s = Maildir/tmp/xxxxxx.xx done. */
 
  alarm(86400);
  fd = open_excl(fntmptph);
@@ -117,6 +157,7 @@
  if (substdio_put(&ssout,rpline.s,rpline.len) == -1) goto fail;
  if (substdio_put(&ssout,dtline.s,dtline.len) == -1) goto fail;
 
+ /* read message & write.. */
  switch(substdio_copy(&ssout,&ss))
   {
    case -2: tryunlinktmp(); _exit(4);
@@ -126,12 +167,15 @@
  if (substdio_flush(&ssout) == -1) goto fail;
  if (fsync(fd) == -1) goto fail;
  if (close(fd) == -1) goto fail; /* NFS dorks */
+ if ((eee=Check_quota("."))!=0) goto limiterror;
 
  if (link(fntmptph,fnnewtph) == -1) goto fail;
    /* if it was error_exist, almost certainly successful; i hate NFS */
  tryunlinktmp(); _exit(0);
 
  fail: tryunlinktmp(); _exit(1);
+ limiterror: tryunlinktmp(); _exit(eee);
+
 }
 
 /* end child process */
@@ -162,6 +206,8 @@
    case 2: strerr_die1x(111,"Unable to chdir to maildir. (#4.2.1)");
    case 3: strerr_die1x(111,"Timeout on maildir delivery. (#4.3.0)");
    case 4: strerr_die1x(111,"Unable to read message. (#4.3.0)");
+   case 5: strerr_die1x(100,"Mailbox is FULL.");
+   case 6: strerr_die1x(100,"Unknown error occured while checking file size.");
    default: strerr_die1x(111,"Temporary error on maildir delivery. (#4.3.0)");
   }
 }
@@ -175,6 +221,7 @@
  int match;
  seek_pos pos;
  int flaglocked;
+ int eee;
 
  if (seek_begin(0) == -1) temp_rewind();
 
@@ -217,6 +264,7 @@
  if (substdio_bputs(&ssout,"\n")) goto writeerrs;
  if (substdio_flush(&ssout)) goto writeerrs;
  if (fsync(fd) == -1) goto writeerrs;
+ if ((eee=Check_quota(fn))!=0) goto limiterror;
  close(fd);
  return;
 
@@ -225,6 +273,28 @@
  if (flaglocked) seek_trunc(fd,pos);
  close(fd);
  _exit(111);
+
+ limiterror:
+ switch(eee)
+ {
+   case 5:
+     if (flaglocked) seek_trunc(fd,pos);
+     close(fd);
+     strerr_die1x(100,"Mailbox is FULL.");
+     break;
+   case 6:
+     if (flaglocked) seek_trunc(fd,pos);
+     close(fd);
+     strerr_die1x(100,"Unknown error occured while checking file size.");
+     break;
+   default:
+     strerr_warn5("Unable to write ",fn,": ",error_str(errno),". (#4.3.0)",0);
+     break;
+ }
+ if (flaglocked) seek_trunc(fd,pos);
+ close(fd);
+ _exit(111);
+
 }
 
 void mailprogram(prog)
@@ -458,6 +528,10 @@
  datetime_sec starttime;
  int flagforwardonly;
  char *x;
+ char *q;
+
+ if ((q=env_get("MAIL_QUOTA_SIZE")) > 0) quota_size = (unsigned long)atol(q);  
+ else quota_size = 0;  
 
  umask(077);
  sig_pipeignore();
diff -ruN qmail-1.03/qmail-lspawn.c qmail-mysql/qmail-lspawn.c
--- qmail-1.03/qmail-lspawn.c	Mon Jun 15 19:53:16 1998
+++ qmail-mysql/qmail-lspawn.c	Thu Nov 11 22:28:52 1999
@@ -13,6 +13,7 @@
 #include "auto_qmail.h"
 #include "auto_uids.h"
 #include "qlx.h"
+#include "env.h"
 
 char *aliasempty;
 
@@ -61,6 +62,8 @@
      substdio_put(ss,"Z",1); break;
    case 0:
      substdio_put(ss,"K",1); break;
+   case 200:
+     substdio_puts(ss,"ZUnable to run qmail-local because quota error.\n"); return;
    case 100:
    default:
      substdio_put(ss,"D",1); break;
@@ -73,11 +76,12 @@
 stralloc lower = {0};
 stralloc nughde = {0};
 stralloc wildchars = {0};
+stralloc mbox_host = {0};
 
 void nughde_get(local)
 char *local;
 {
- char *(args[3]);
+ char *(args[4]);
  int pi[2];
  int gpwpid;
  int gpwstat;
@@ -141,7 +145,9 @@
  if (pipe(pi) == -1) _exit(QLX_SYS);
  args[0] = "bin/qmail-getpw";
  args[1] = local;
- args[2] = 0;
+ args[2] = mbox_host.s;
+ args[3] = 0;
+
  switch(gpwpid = vfork())
   {
    case -1:
@@ -180,10 +186,14 @@
    int gid;
    char *x;
    unsigned int xlen;
-   
+
+   if (!stralloc_copys(&mbox_host, r+at+1)) _exit(QLX_NOMEM);
+   if (!stralloc_0(&mbox_host)) _exit(QLX_NOMEM);
+
    r[at] = 0;
    if (!r[0]) _exit(0); /* <> */
 
+
    if (chdir(auto_qmail) == -1) _exit(QLX_USAGE);
 
    nughde_get(r);
@@ -213,6 +223,8 @@
 
    args[6] = x;
    n = byte_chr(x,xlen,0); if (n++ == xlen) _exit(QLX_USAGE); x += n; xlen -= n;
+
+   if (!env_put2("MAIL_QUOTA_SIZE",x)) {;}
 
    args[7] = r + at + 1;
    args[8] = s;
diff -ruN qmail-1.03/qmail-popup.c qmail-mysql/qmail-popup.c
--- qmail-1.03/qmail-popup.c	Mon Jun 15 19:53:16 1998
+++ qmail-mysql/qmail-popup.c	Tue Nov  9 09:45:56 1999
@@ -13,6 +13,7 @@
 #include "readwrite.h"
 #include "timeoutread.h"
 #include "timeoutwrite.h"
+#include "env.h"
 
 void die() { _exit(1); }
 
@@ -145,6 +146,7 @@
 {
   if (!seenuser) { err_wantuser(); return; }
   if (!*arg) { err_syntax(); return; }
+  if (!env_put("AUTH=pop")) die_nomem();
   doanddie(username.s,username.len,arg);
 }
 void pop3_apop(arg) char *arg;
@@ -153,6 +155,7 @@
   space = arg + str_chr(arg,' ');
   if (!*space) { err_syntax(); return; }
   *space++ = 0;
+  if (!env_put("AUTH=apop")) die_nomem();
   doanddie(arg,space - arg,space);
 }
 
