diff -ru courier-imap-3.0.8/authlib/checkpassword.c courier-imap-3.0.8-apop/authlib/checkpassword.c
--- courier-imap-3.0.8/authlib/checkpassword.c	2004-06-09 07:44:18.000000000 +0900
+++ courier-imap-3.0.8-apop/authlib/checkpassword.c	2004-09-19 20:49:52.000000000 +0900
@@ -37,6 +37,7 @@
 #if	HAVE_MD5LIB
 	if (strncmp(encrypted_password, "$1$", 3) == 0
 		|| strncasecmp(encrypted_password, "{MD5}", 5) == 0
+		|| strncasecmp(encrypted_password, "{APOP}", 6) == 0
 		)
 		return (authcheckpasswordmd5(password, encrypted_password));
 #endif
diff -ru courier-imap-3.0.8/authlib/checkpasswordmd5.c courier-imap-3.0.8-apop/authlib/checkpasswordmd5.c
--- courier-imap-3.0.8/authlib/checkpasswordmd5.c	2002-12-12 13:23:58.000000000 +0900
+++ courier-imap-3.0.8-apop/authlib/checkpasswordmd5.c	2004-09-19 20:49:52.000000000 +0900
@@ -2,6 +2,8 @@
 ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
 ** distribution information.
 */
+#include <stdio.h>
+#include <stdlib.h>
 
 #if	HAVE_CONFIG_H
 #include	"config.h"
@@ -27,5 +29,33 @@
 	{
                return (strcmp(encrypted_password+5, md5_hash_courier(password)));
 	}
+
+	if (strncasecmp(encrypted_password, "{APOP}", 6) == 0)
+	{
+		char *opass, *cpass, *okpass, *p, okmesg[BUFSIZ];
+		int j;
+		MD5_DIGEST digest;
+		if((opass=malloc(strlen(password)+1)) == 0)
+		{
+			perror("malloc");
+			authexit(1);
+		}
+		strcpy(opass, password);
+		cpass=strtok(opass, " ");
+		p=strtok(0, "\t\r");
+		if((okpass = malloc(strlen(p)+strlen(encrypted_password)+3)) == 0)
+		{
+			perror("malloc");
+			authexit(1);
+		}
+		strcat(strcpy(okpass, p), encrypted_password+6);
+		md5_digest(okpass, strlen(okpass), digest);
+		for(j=0; j<sizeof(digest); j++)
+			sprintf(&okmesg[j*2], "%02x", digest[j]);
+		free(okpass);
+		j=strcmp(cpass, okmesg);
+		free(opass);
+		return (j);
+	}
 	return (-1);
 }
diff -ru courier-imap-3.0.8/imap/pop3d.dist.in courier-imap-3.0.8-apop/imap/pop3d.dist.in
--- courier-imap-3.0.8/imap/pop3d.dist.in	2004-06-09 07:44:21.000000000 +0900
+++ courier-imap-3.0.8-apop/imap/pop3d.dist.in	2004-09-19 20:49:52.000000000 +0900
@@ -152,3 +152,9 @@
 # MAILDIRPATH - directory name of the maildir directory.
 #
 MAILDIRPATH=Maildir
+
+##NAME: POP3DHOSTNAME:0
+#
+# POP3DHOSTNAME - APOP time-stamp hostname.
+#
+POP3DHOSTNAME=localhost.localdomain
diff -ru courier-imap-3.0.8/imap/pop3login.c courier-imap-3.0.8-apop/imap/pop3login.c
--- courier-imap-3.0.8/imap/pop3login.c	2004-09-13 08:25:56.000000000 +0900
+++ courier-imap-3.0.8-apop/imap/pop3login.c	2004-09-19 20:49:52.000000000 +0900
@@ -14,6 +14,7 @@
 #include	<signal.h>
 #include	<ctype.h>
 #include	<fcntl.h>
+#include	<time.h>
 #if	HAVE_UNISTD_H
 #include	<unistd.h>
 #endif
@@ -22,6 +23,7 @@
 #include	"authlib/authsasl.h"
 #include	"tcpd/spipe.h"
 #include	"authlib/debug.h"
+#include	"md5/md5.h"
 
 static const char rcsid[]="$Id: courier-imap-3.0.8-apop.patch 2 2005-12-30 14:34:29Z setoppu $";
 
@@ -128,12 +130,15 @@
 int main(int argc, char **argv)
 {
 char	*user=0;
-char	*p;
+char	*p,*r;
 char	buf[BUFSIZ];
-int	c;
+int	c,j;
 const	char *ip=getenv("TCPREMOTEIP");
-char authservice[40];
-char *q ;
+char 	authservice[40];
+char 	*q;
+time_t	now;
+char	*okmesg=0;
+char	*hostname=getenv("POP3DHOSTNAME");
 
 	if (!ip || !*ip)
 	{
@@ -142,12 +147,29 @@
 		exit(1);
 	}
 
+	if(hostname == NULL || *hostname == '\0')
+	{
+		fprintf(stderr, "INFO: Hostname is not setup, A default Hostname is used,\n");
+		fflush(stderr);
+		hostname="localhost.localdomain";
+	}
+
 	auth_debug_login_init();
 
 	if (authmoduser(argc, argv, 60, 5))
 	{
+		time(&now);
 		fprintf(stderr, "DEBUG: Connection, ip=[%s]\n", ip);
-		printf("+OK Hello there.\r\n");
+		j=strlen(hostname)+26;
+		if ((okmesg=malloc(j)) == 0)
+		{
+			printf("-ERR Server out of memory, aborting connection.\r\n");
+			fflush(stdout);
+			perror("malloc");
+			exit(1);
+		}
+		snprintf(okmesg, j, "<%lu.%lu@%s>", (unsigned long)(getpid() & 0xffffffff), (unsigned long)(now & 0xffffffff), hostname);
+		printf("+OK Hello there. %s\r\n", okmesg);
 	}
 	else
 	{
@@ -282,11 +304,44 @@
 					q="pop3";
 
 				authmod_login(argc-1, argv+1, q, user, p);
+			} else if (strcmp(p, "APOP") == 0)
+			{
+				p=strtok(0, " \t\r");
+				if (p)
+				{
+					if (user) free(user);
+					if ((user=malloc(strlen(p)+1)) == 0)
+					{
+						printf("-ERR Server out of memory, aborting connection.\r\n");
+						fflush(stdout);
+						perror("malloc");
+						exit(1);
+					}
+					strcpy(user, p);
+				}
+				p=strtok(0, "\t\r");
+				if (p == 0)
+				{
+					printf("-ERR PASS required.\r\n");
+					fflush(stdout);
+					continue;
+				}
+				if ((r=malloc(strlen(p)+strlen(okmesg)+3)) == 0)
+				{
+					printf("-ERR Server out of memory, aborting connection.\r\n");
+					fflush(stdout);
+					perror("malloc");
+					exit(1);
+				}
+				strcat(strcat(strcat(strcpy(r, p), " "), okmesg), "\n");
+				authmod_login(argc-1, argv+1, "apop", user, r);
+				free(r);
 			}
 		}
 		printf("-ERR Invalid command.\r\n");
 		fflush(stdout);
 	}
+	free(okmesg);
 	exit(0);
 	return (0);
 }
