diff -uNr mail/courier-imap.orig/Makefile mail/courier-imap/Makefile
--- mail/courier-imap.orig/Makefile	Fri Nov 19 11:01:28 2004
+++ mail/courier-imap/Makefile	Fri Dec 17 18:12:14 2004
@@ -49,6 +49,7 @@
 # WITH_DRAC:			Build in DRAC support
 # WITH_TRASHQUOTA:		Include deleted mails in the quota
 # WITH_GDBM:			Use gdbm files instead of bdb
+# WITH_APOP:			Build in APOP support
 #
 
 CONFDIR?=	${PREFIX}/etc/${PORTNAME}
@@ -77,7 +78,7 @@
 		--datadir=${DATADIR} \
 		--libexecdir=${LIBEXECDIR} \
 		--enable-workarounds-for-imap-client-bugs \
-		--enable-unicode \
+		--enable-unicode=iso-2022-jp \
 		--disable-root-check \
 		--with-locking-method=fcntl
 
@@ -170,6 +171,10 @@
 .if defined(WITH_DRAC)
 EXTRA_PATCHES=	${FILESDIR}/extra-patch-drac
 BUILD_DEPENDS+=	${LOCALBASE}/lib/libdrac.a:${PORTSDIR}/mail/drac
+.endif
+
+.if defined(WITH_APOP)
+EXTRA_PATCHES=	${FILESDIR}/extra-patch-apop
 .endif
 
 MAN1=		courierlogger.1 couriertcpd.1 maildiracl.1 maildirkw.1 \
diff -uNr mail/courier-imap.orig/files/extra-patch-apop mail/courier-imap/files/extra-patch-apop
--- mail/courier-imap.orig/files/extra-patch-apop	Thu Jan  1 09:00:00 1970
+++ mail/courier-imap/files/extra-patch-apop	Fri Dec 17 18:22:06 2004
@@ -0,0 +1,117 @@
+--- authlib/checkpassword.c.orig	Wed Jun  9 07:44:18 2004
++++ authlib/checkpassword.c	Fri Dec 17 18:07:18 2004
+@@ -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
+--- authlib/checkpasswordmd5.c.orig	Thu Dec 12 13:23:58 2002
++++ authlib/checkpasswordmd5.c	Fri Dec 17 18:07:18 2004
+@@ -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"
+@@ -26,6 +28,25 @@
+ 	if (strncasecmp(encrypted_password, "{MD5}", 5) == 0)
+ 	{
+                return (strcmp(encrypted_password+5, md5_hash_courier(password)));
++	}
++
++	if (strncasecmp(encrypted_password, "{APOP}", 6) == 0)
++	{
++		char *cpass,*okpass,*p,okmesg[BUFSIZ];
++		int j;
++		MD5_DIGEST digest;
++		cpass=strtok(password," ");
++		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]);
++		return (strcmp(cpass, okmesg));
+ 	}
+ 	return (-1);
+ }
+--- imap/pop3login.c.orig	Mon Sep 13 08:25:56 2004
++++ imap/pop3login.c	Fri Dec 17 18:07:18 2004
+@@ -14,6 +14,7 @@
+ #include	<signal.h>
+ #include	<ctype.h>
+ #include	<fcntl.h>
++#include	<sys/param.h>
+ #if	HAVE_UNISTD_H
+ #include	<unistd.h>
+ #endif
+@@ -134,6 +135,9 @@
+ const	char *ip=getenv("TCPREMOTEIP");
+ char authservice[40];
+ char *q ;
++time_t	now;
++char	hostname[MAXHOSTNAMELEN];
++char	okmesg[BUFSIZ];
+ 
+ 	if (!ip || !*ip)
+ 	{
+@@ -147,7 +151,10 @@
+ 	if (authmoduser(argc, argv, 60, 5))
+ 	{
+ 		fprintf(stderr, "DEBUG: Connection, ip=[%s]\n", ip);
+-		printf("+OK Hello there.\r\n");
++		if (gethostname(hostname, sizeof(hostname)))
++                	strncpy(hostname, "localhost.localdomain", sizeof(hostname));
++		snprintf(okmesg, sizeof(okmesg), "<%d.%ld@%s>", (int)getpid(), time(&now), hostname);
++		printf("+OK Hello there. %s\r\n", okmesg);
+ 	}
+ 	else
+ 	{
+@@ -282,6 +289,37 @@
+ 					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 ((q=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(q, p), " "), okmesg), "\n");
++				authmod_login(argc-1, argv+1, "apop", user, q);
+ 			}
+ 		}
+ 		printf("-ERR Invalid command.\r\n");
