diff --git Makefile Makefile
index a865774..a21d7eb 100644
--- Makefile
+++ Makefile
@@ -1,7 +1,6 @@
 # $NetBSD: Makefile,v 1.68 2008/02/21 15:50:29 jlam Exp $
 
-DISTNAME=	courier-imap-4.3.0
-PKGREVISION=	1
+DISTNAME=	courier-imap-4.7.0
 CATEGORIES=	mail
 MASTER_SITES=	${MASTER_SITE_SOURCEFORGE:=courier/}
 EXTRACT_SUFX=	.tar.bz2
@@ -10,8 +9,8 @@ MAINTAINER=	jlam@pkgsrc.org
 COMMENT=	IMAP server for access to maildir-style mailboxes
 HOMEPAGE=	http://www.courier-mta.org/imap/
 
-DEPENDS+=	courier-maildir>=0.58.0:../../mail/courier-maildir
-DEPENDS+=	couriertcpd>=0.58.0:../../net/couriertcpd
+DEPENDS+=	courier-maildir>=${COURIER_VERSION}:../../mail/courier-maildir
+DEPENDS+=	couriertcpd>=${COURIER_VERSION}:../../net/couriertcpd
 
 PKG_DESTDIR_SUPPORT=	user-destdir
 
diff --git PLIST PLIST
index ded8fda..265037a 100644
--- PLIST
+++ PLIST
@@ -7,18 +7,18 @@ man/man8/courierimapd.8
 man/man8/courierpop3d.8
 man/man8/mkimapdcert.8
 man/man8/mkpop3dcert.8
-sbin/imapd
-sbin/imapd-ssl
+sbin/imapd.rc
+sbin/imapd-ssl.rc
 sbin/mkimapdcert
 sbin/mkpop3dcert
-sbin/pop3d
-sbin/pop3d-ssl
-share/courier/imapd
-share/courier/imapd-ssl
+sbin/pop3d.rc
+sbin/pop3d-ssl.rc
+share/courier/imapd.rc
+share/courier/imapd-ssl.rc
 share/courier/mkimapdcert
 share/courier/mkpop3dcert
-share/courier/pop3d
-share/courier/pop3d-ssl
+share/courier/pop3d.rc
+share/courier/pop3d-ssl.rc
 share/doc/courier/courierpop3d.html
 share/doc/courier/imap/BUGS.html
 share/doc/courier/imap/README.html
diff --git distinfo distinfo
index 4d25f65..d728f6b 100644
--- distinfo
+++ distinfo
@@ -1,14 +1,13 @@
 $NetBSD: distinfo,v 1.23 2008/02/19 18:45:14 jlam Exp $
 
-SHA1 (courier-imap-4.3.0.tar.bz2) = b7c091f2bfdd22308ac26724e88b50e7a4f68cb2
-RMD160 (courier-imap-4.3.0.tar.bz2) = 8865d4b139af5f85a08ce5f1b6e1e453d3827120
-Size (courier-imap-4.3.0.tar.bz2) = 3342522 bytes
-SHA1 (patch-aa) = 9b60c07f2a8c4c3fea3fac8c22a8386de3f7d53b
-SHA1 (patch-ad) = 8a80f42a179e34a838317a0aac2d0a811fd47071
-SHA1 (patch-ae) = 9d925f4639086af9f6faecd6a2fab2a9ecab670c
-SHA1 (patch-af) = 37c54ed8aca2f86ac142f8fa920c217058c5fc29
-SHA1 (patch-ag) = 6ddd8b3f6a2cfbab4d814b51552dbf364384cf57
-SHA1 (patch-ah) = 1870daea8320cc9748961fc7e37237bd5cde1b3c
-SHA1 (patch-ak) = 057df5c41382768a0f221107137412c46200c035
-SHA1 (patch-an) = da8ce37a8a4ff57a25325153f1d68b7df865faee
-SHA1 (patch-ao) = f576d11ee217000a7760f153b131ed7a445d48f6
+SHA1 (courier-imap-4.7.0.tar.bz2) = 9729f3add8692563865da5167cfe88f2227c3968
+RMD160 (courier-imap-4.7.0.tar.bz2) = 2ab1768fb7714cfe291edcc00c96cc276af12782
+Size (courier-imap-4.7.0.tar.bz2) = 3414328 bytes
+SHA1 (patch-aa) = d83a04bd9118fbe57d83b6022ace922e84f93af0
+SHA1 (patch-ad) = 49ed00bf47af7f9a3370c2e68e03ee1a766473e2
+SHA1 (patch-ae) = e61fe4e93f466e1a90981f0c466567417f67d2fb
+SHA1 (patch-af) = ca556cf1b0cfdbbe9dbfea563fb403878feff1bd
+SHA1 (patch-ag) = 12635085d8f00de5c527f8a23e6c73d28dfe706c
+SHA1 (patch-ah) = b9769225547ad0415a7f338e43cce3f8fd7538b7
+SHA1 (patch-ak) = 6102d5bc275cdffdb6385bba634f4310c99617f7
+SHA1 (patch-ao) = 1769d6a526e00ece65f5c0194f201addcb6501f5
diff --git patches/patch-aa patches/patch-aa
index ec9ee85..d9dfa97 100644
--- patches/patch-aa
+++ patches/patch-aa
@@ -1,8 +1,10 @@
 $NetBSD: patch-aa,v 1.14 2007/10/15 15:37:21 jlam Exp $
 
---- Makefile.in.orig	Sat Sep 29 14:48:20 2007
-+++ Makefile.in
-@@ -250,9 +250,10 @@ DIST_SUBDIRS = numlib md5 sha1 bdbobj gd
+--- Makefile.in.orig	2009-12-25 22:08:26.000000000 +0000
++++ Makefile.in	2010-03-15 16:10:48.000000000 +0000
+@@ -286,17 +286,18 @@
+ 	rfc1035 rfc2045 liblock maildir makedat libhmac \
+ 	waitlib tcpd rootcerts imap
  
 -sbin_SCRIPTS = sharedindexinstall sharedindexsplit
 +sbin_SCRIPTS = 
@@ -18,12 +20,16 @@ $NetBSD: patch-aa,v 1.14 2007/10/15 15:37:21 jlam Exp $
 +sbinPROGRAMS = 
 +libexecPROGRAMS = imaplogin courierpop3login courierpop3d
  bin_PROGRAMS = @binPROGRAMS_exec@
-@@ -260,3 +261,3 @@ sbin_PROGRAMS = @sbinPROGRAMS_exec@
+ sbin_PROGRAMS = @sbinPROGRAMS_exec@
  libexec_PROGRAMS = @libexecPROGRAMS_exec@
 -man_MANS = couriertcpd.1 deliverquota.8 maildirmake.1 maildiracl.1 imapd.8 mkimapdcert.8 mkpop3dcert.8 maildirkw.1
 +man_MANS = courierimapd.8 courierpop3d.8 mkimapdcert.8 mkpop3dcert.8
  
-@@ -271,5 +272,5 @@ EXTRA_DIST = 00README.NOW.OR.SUFFER READ
+ # Added by sysconftoolize: $Id: Makefile.am,v 1.124 2009/12/25 22:08:20 mrsam Exp $
+ 
+@@ -307,9 +308,9 @@
+ EXTRA_DIST = 00README.NOW.OR.SUFFER README README.cygwin COPYING.GPL \
+ 	NEWS.html $(TEMPLFILES) pgpkeys.txt sysconftool
  sysconf_DATA = imapd.dist imapd-ssl.dist pop3d.dist pop3d-ssl.dist \
 -	imapd.cnf pop3d.cnf quotawarnmsg.example
 +	imapd.cnf pop3d.cnf
@@ -31,7 +37,11 @@ $NetBSD: patch-aa,v 1.14 2007/10/15 15:37:21 jlam Exp $
 -libexec_SCRIPTS = imapd.rc imapd-ssl.rc pop3d.rc pop3d-ssl.rc
 +libexec_SCRIPTS = 
  HTML2TXT = links -dump -no-numbering -no-references
-@@ -1045,7 +1046,7 @@ sharedindexsplit: maildir/sharedindexspl
+ 
+ # NOTE: when using a complex directory hierarchy it is only necessary to
+@@ -1223,11 +1224,11 @@
+ sharedindexsplit: maildir/sharedindexsplit
+ 	cp maildir/sharedindexsplit .
  
 -pop3login$(EXEEXT): imap/pop3login$(EXEEXT)
 -	cp imap/pop3login$(EXEEXT) .
@@ -43,7 +53,11 @@ $NetBSD: patch-aa,v 1.14 2007/10/15 15:37:21 jlam Exp $
 +courierpop3d$(EXEEXT): imap/pop3d$(EXEEXT)
 +	cp imap/pop3d$(EXEEXT) ./$@
  
-@@ -1093,4 +1094,7 @@ maildirkw.1: maildir/maildirkw.1
+ makedatprog$(EXEEXT): makedat/makedatprog$(EXEEXT)
+ 	cp makedat/makedatprog$(EXEEXT) .
+@@ -1271,8 +1272,11 @@
+ maildirkw.1: maildir/maildirkw.1
+ 	cp $(srcdir)/maildir/maildirkw.1 .
  
 -imapd.8: imap/imapd.8
 -	cp imap/imapd.8 .
@@ -53,15 +67,21 @@ $NetBSD: patch-aa,v 1.14 2007/10/15 15:37:21 jlam Exp $
 +courierpop3d.8: imap/courierpop3d.8
 +	cp imap/courierpop3d.8 .
  
-@@ -1120,6 +1124,4 @@ install-exec-local:
+ mkimapdcert: imap/mkimapdcert
+ 	cp imap/mkimapdcert .
+@@ -1298,37 +1302,21 @@
+ install-exec-local:
+ 	$(mkinstalldirs) $(DESTDIR)$(databindir)
  	$(mkinstalldirs) $(DESTDIR)$(bindir)
 -	test ! -x tcpd/couriertls || $(INSTALL_PROGRAM) $(INSTALL_STRIP_FLAG) \
 -		tcpd/couriertls $(DESTDIR)$(bindir)/couriertls
  	$(mkinstalldirs) $(DESTDIR)$(sbindir)
 -	for f in mkimapdcert mkpop3dcert ; \
-+	for f in imapd-ssl imapd mkimapdcert mkpop3dcert pop3d pop3d-ssl ; \
++	for f in imapd-ssl.rc imapd.rc mkimapdcert mkpop3dcert pop3d.rc pop3d-ssl.rc ; \
  		do rm -f $(DESTDIR)$(sbindir)/$$f ; \
-@@ -1129,17 +1131,4 @@ install-exec-local:
+ 		$(LN_S) $(databindir)/$$f $(DESTDIR)$(sbindir)/$$f ; done
+ 	$(mkinstalldirs) $(DESTDIR)$(localstatedir)
+ 
  install-exec-hook:
 -	chmod 444 $(DESTDIR)$(sysconfdir)/quotawarnmsg.example
 -	mkdir -p $(DESTDIR)$(sysconfdir)/shared
@@ -79,7 +99,12 @@ $NetBSD: patch-aa,v 1.14 2007/10/15 15:37:21 jlam Exp $
 -		$(INSTALL_DATA) $(srcdir)/imap/pop3d.pam \
 -		$(DESTDIR)/etc/pam.d/pop3 || exit 1
  	for f in $(man_MANS); do chmod a+r $(DESTDIR)$(mandir)/*/$$f; done
-@@ -1150,3 +1139,2 @@ uninstall-local:
+ 	@echo "Do not forget to run make install-configure"
+ 
+ uninstall-local:
+ 	for f in mkimapdcert mkpop3dcert ; \
  		do rm -f $(DESTDIR)$(sbindir)/$$f ; done
 -	rm -f $(DESTDIR)$(bindir)/couriertls
  
+ INSTALL.txt: INSTALL.html
+ 	$(HTML2TXT) INSTALL.html >INSTALL.txt
diff --git patches/patch-ad patches/patch-ad
index 3ac4263..f877213 100644
--- patches/patch-ad
+++ patches/patch-ad
@@ -1,8 +1,8 @@
 $NetBSD: patch-ad,v 1.9 2008/02/19 18:45:14 jlam Exp $
 
---- configure.orig	2007-11-23 22:20:27.000000000 -0500
-+++ configure
-@@ -20576,9 +20576,6 @@ else
+--- configure.orig	2009-12-25 22:08:26.000000000 +0000
++++ configure	2010-03-15 16:10:48.000000000 +0000
+@@ -12377,9 +12377,6 @@
  fi
  
  
diff --git patches/patch-ae patches/patch-ae
index 1bdb713..222239f 100644
--- patches/patch-ae
+++ patches/patch-ae
@@ -1,8 +1,8 @@
 $NetBSD: patch-ae,v 1.8 2005/08/11 00:04:01 jlam Exp $
 
---- imapd-ssl.rc.in.orig	2005-07-01 21:13:56.000000000 -0400
-+++ imapd-ssl.rc.in
-@@ -9,6 +9,7 @@ prefix=@prefix@
+--- imapd-ssl.rc.in.orig	2005-07-02 02:13:56.000000000 +0100
++++ imapd-ssl.rc.in	2010-03-15 16:10:48.000000000 +0000
+@@ -9,6 +9,7 @@
  exec_prefix=@exec_prefix@
  bindir=@bindir@
  libexecdir=@libexecdir@
@@ -10,7 +10,7 @@ $NetBSD: patch-ae,v 1.8 2005/08/11 00:04:01 jlam Exp $
  
  if test ! -f @sysconfdir@/imapd
  then
-@@ -40,6 +41,7 @@ start)
+@@ -40,6 +41,7 @@
  		exec_prefix=@exec_prefix@ ;
  		bindir=@bindir@ ;
  		libexecdir=@libexecdir@ ;
diff --git patches/patch-af patches/patch-af
index bc8923d..deb8991 100644
--- patches/patch-af
+++ patches/patch-af
@@ -1,8 +1,8 @@
 $NetBSD: patch-af,v 1.8 2005/08/11 00:04:01 jlam Exp $
 
---- imapd.rc.in.orig	2005-07-01 21:13:56.000000000 -0400
-+++ imapd.rc.in
-@@ -9,6 +9,7 @@ prefix=@prefix@
+--- imapd.rc.in.orig	2008-05-04 14:12:47.000000000 +0100
++++ imapd.rc.in	2010-03-15 16:13:30.000000000 +0000
+@@ -9,6 +9,7 @@
  exec_prefix=@exec_prefix@
  bindir=@bindir@
  libexecdir=@libexecdir@
@@ -10,11 +10,11 @@ $NetBSD: patch-af,v 1.8 2005/08/11 00:04:01 jlam Exp $
  
  if test ! -f @sysconfdir@/imapd
  then
-@@ -40,6 +41,7 @@ start)
+@@ -40,6 +41,7 @@
  			exec_prefix=@exec_prefix@ ;
  			bindir=@bindir@ ;
  			libexecdir=@libexecdir@ ;
 +			sbindir=@sbindir@ ;
- 				. @sysconfdir@/imapd ; \
  				. @sysconfdir@/imapd-ssl ; \
+ 				. @sysconfdir@/imapd ; \
  		IMAP_STARTTLS=$IMAPDSTARTTLS ; \
diff --git patches/patch-ag patches/patch-ag
index b6853df..6de91d6 100644
--- patches/patch-ag
+++ patches/patch-ag
@@ -1,8 +1,8 @@
 $NetBSD: patch-ag,v 1.8 2005/08/11 00:04:01 jlam Exp $
 
---- pop3d-ssl.rc.in.orig	2005-07-01 21:13:56.000000000 -0400
-+++ pop3d-ssl.rc.in
-@@ -9,6 +9,7 @@ prefix=@prefix@
+--- pop3d-ssl.rc.in.orig	2005-07-02 02:13:56.000000000 +0100
++++ pop3d-ssl.rc.in	2010-03-15 16:10:48.000000000 +0000
+@@ -9,6 +9,7 @@
  exec_prefix=@exec_prefix@
  bindir=@bindir@
  libexecdir=@libexecdir@
@@ -10,7 +10,7 @@ $NetBSD: patch-ag,v 1.8 2005/08/11 00:04:01 jlam Exp $
  
  if test ! -f @sysconfdir@/pop3d
  then
-@@ -33,6 +34,7 @@ start)
+@@ -33,6 +34,7 @@
  		exec_prefix=@exec_prefix@ ;
  		bindir=@bindir@ ;
  		libexecdir=@libexecdir@ ;
diff --git patches/patch-ah patches/patch-ah
index 5add83b..4512ef9 100644
--- patches/patch-ah
+++ patches/patch-ah
@@ -1,8 +1,8 @@
 $NetBSD: patch-ah,v 1.7 2005/08/11 00:04:01 jlam Exp $
 
---- pop3d.rc.in.orig	2005-07-01 21:13:56.000000000 -0400
-+++ pop3d.rc.in
-@@ -9,6 +9,7 @@ prefix=@prefix@
+--- pop3d.rc.in.orig	2008-05-04 14:12:47.000000000 +0100
++++ pop3d.rc.in	2010-03-15 16:13:54.000000000 +0000
+@@ -9,6 +9,7 @@
  exec_prefix=@exec_prefix@
  bindir=@bindir@
  libexecdir=@libexecdir@
@@ -10,11 +10,11 @@ $NetBSD: patch-ah,v 1.7 2005/08/11 00:04:01 jlam Exp $
  
  if test ! -f @sysconfdir@/pop3d
  then
-@@ -32,6 +33,7 @@ start)
+@@ -32,6 +33,7 @@
  		exec_prefix=@exec_prefix@ ;
  		bindir=@bindir@ ;
  		libexecdir=@libexecdir@ ;
 +		sbindir=@sbindir@ ;
- 		. @sysconfdir@/pop3d ; \
  		. @sysconfdir@/pop3d-ssl ; \
+ 		. @sysconfdir@/pop3d ; \
  		PROXY_HOSTNAME=$PROXY_HOSTNAME ; \
diff --git patches/patch-ak patches/patch-ak
index 3c2f627..d622ba2 100644
--- patches/patch-ak
+++ patches/patch-ak
@@ -1,7 +1,7 @@
 $NetBSD: patch-ak,v 1.3 2008/02/19 18:45:14 jlam Exp $
 
---- imap/mkimapdcert.in.orig	2007-11-04 15:50:15.000000000 -0500
-+++ imap/mkimapdcert.in
+--- imap/mkimapdcert.in.orig	2007-11-04 20:49:58.000000000 +0000
++++ imap/mkimapdcert.in	2010-03-15 16:10:48.000000000 +0000
 @@ -9,7 +9,13 @@
  # IMAP over SSL.  Normally this script would get called by an automatic
  # package installation routine.
@@ -17,7 +17,7 @@ $NetBSD: patch-ak,v 1.3 2008/02/19 18:45:14 jlam Exp $
  then
  	test -x @OPENSSL@ || exit 0
  else
-@@ -36,7 +42,7 @@ cleanup() {
+@@ -36,7 +42,7 @@
  
  cd @mydatadir@
  
diff --git patches/patch-an patches/patch-an
deleted file mode 100644
index e868e8c..0000000
--- patches/patch-an
+++ /dev/null
@@ -1,16 +0,0 @@
-$NetBSD: patch-an,v 1.1 2007/10/15 15:37:21 jlam Exp $
-
---- imap/mailboxlist.c.orig	Fri Jul 27 02:41:01 2007
-+++ imap/mailboxlist.c
-@@ -347,9 +347,11 @@ static void folder_entry(char *folder, c
- 	if (!need_add_folders && !need_add_hier)
- 		return; /* Nothing to do */
- 
-+	{
- 	CHECK_RIGHTSM(folder, have_rights, ACL_LOOKUP);
- 	if (!have_rights[0])
- 		return;
-+	}
- 
- 	if (need_add_folders)
- 		(void) add_hier(folders, folder);
diff --git patches/patch-ao patches/patch-ao
index 4eae4c7..2387eb6 100644
--- patches/patch-ao
+++ patches/patch-ao
@@ -1,7 +1,7 @@
 $NetBSD: patch-ao,v 1.1 2008/02/19 18:45:14 jlam Exp $
 
---- imap/mkpop3dcert.in.orig	2007-11-04 15:50:15.000000000 -0500
-+++ imap/mkpop3dcert.in
+--- imap/mkpop3dcert.in.orig	2007-11-04 20:49:58.000000000 +0000
++++ imap/mkpop3dcert.in	2010-03-15 16:10:48.000000000 +0000
 @@ -9,7 +9,13 @@
  # POP3 over SSL.  Normally this script would get called by an automatic
  # package installation routine.
@@ -17,7 +17,7 @@ $NetBSD: patch-ao,v 1.1 2008/02/19 18:45:14 jlam Exp $
  then
  	test -x @OPENSSL@ || exit 0
  else
-@@ -36,7 +42,7 @@ cleanup() {
+@@ -36,7 +42,7 @@
  
  cd @mydatadir@
  
