From e4093a150222b3145605b6b4da3ca9ea6785f957 Mon Sep 17 00:00:00 2001
From: Brendan Cully <brendan@kublai.com>
Date: Thu, 5 Apr 2007 19:22:00 -0700
Subject: [PATCH] Fix up QDBM autoconf test for arguments and includes in
 subdirectories

---
 ChangeLog    | 12 +++++++++++-
 configure.ac | 40 +++++++++++++++++++++++-----------------
 hcache.c     |  7 ++++++-
 3 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5a27e34d..67ec8a5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,14 @@
-2007-04-05 17:07 -0700  Brendan Cully  <brendan@kublai.com>  (26b19fc9b78c)
+2007-04-05 18:52 -0700  Brendan Cully  <brendan@kublai.com>  (94d3441e86d0)
+
+	* imap/message.c: Fix logic error introduced in [efbcef81ac49]
+
+	* hcache.c: Fix typo in 26b19fc9b78c
+
+	* imap/imap_private.h, imap/message.c, imap/util.c: IMAP header cache
+	API improvements.
+
+	* imap/imap.c, imap/imap_private.h, imap/message.c, imap/util.c:
+	Keep hcache pointer in idata, open and close with mailbox
 
 	* hcache.c: Do not cache some unsafe header fields.
 
diff --git a/configure.ac b/configure.ac
index 7e59d4a8..60481547 100644
--- a/configure.ac
+++ b/configure.ac
@@ -831,20 +831,28 @@ AC_ARG_ENABLE(hcache, AC_HELP_STRING([--enable-hcache], [Enable header caching])
 
     need_md5="yes"
 
-    ac_prefer_qdbm=yes
-    AC_ARG_WITH(qdbm, AC_HELP_STRING([--without-qdbm], [Don't use qdbm even if it is available]),
-        ac_prefer_qdbm=$withval)
-    if test x$ac_prefer_qdbm != xno; then
-        CPPFLAGS="$OLDCPPFLAGS"
-        LIBS="$OLDLIBS -lqdbm";
-        AC_CACHE_CHECK(for vlopen, ac_cv_vlopen,[
-            ac_cv_vlopen=no
-            AC_TRY_LINK([#include <villa.h>],[vlopen(0,0,0);],[ac_cv_vlopen=yes])
-        ])
+    use_qdbm=no
+    AC_ARG_WITH(qdbm, AC_HELP_STRING([--without-qdbm], [Don't use qdbm even if it is available]))
+    if test "$with_qdbm" != "no"
+    then
+      if test -n "$with_qdbm" -a "$with_qdbm" != "yes"
+      then
+        CPPFLAGS="$CPPFLAGS -I$with_qdbm/include"
+        LDFLAGS="$LDFLAGS -L$with_qdbm/lib"
+      fi
+
+      saved_LIBS="$LIBS"
+      AC_CHECK_HEADERS(villa.h qdbm/villa.h)
+      AC_CHECK_LIB(qdbm, vlopen, [MUTTLIBS="$MUTTLIBS -lqdbm"; use_qdbm=yes])
+      LIBS="$saved_LIBS"
+      if test -n "$with_qdbm" -a "$use_qdbm" != yes
+      then
+        AC_MSG_ERROR([QDBM could not be used. Check config.log for details.])
+      fi
     fi
 
     AC_ARG_WITH(gdbm, AC_HELP_STRING([--without-gdbm], [Don't use gdbm even if it is available]))
-    if test x$with_gdbm != xno -a x$ac_cv_vlopen != xyes; then
+    if test x$with_gdbm != xno -a $use_qdbm != yes; then
         if test "$with_gdbm" != "yes"
         then
           CPPFLAGS="$CPPFLAGS -I$with_gdbm/include"
@@ -861,7 +869,7 @@ AC_ARG_ENABLE(hcache, AC_HELP_STRING([--enable-hcache], [Enable header caching])
     ac_bdb_prefix=yes
     AC_ARG_WITH(bdb, AC_HELP_STRING([--with-bdb[=DIR]], [Use BerkeleyDB4 if gdbm is not available]),
         ac_bdb_prefix=$withval)
-    if test x$ac_bdb_prefix != xno -a x$ac_cv_gdbmopen != xyes -a x$ac_cv_vlopen != xyes; then
+    if test x$ac_bdb_prefix != xno -a x$ac_cv_gdbmopen != xyes -a $use_qdbm != yes; then
         test x$ac_bdb_prefix = xyes && ac_bdb_prefix="$mutt_cv_prefix /opt/csw/bdb4 /opt /usr/local /usr"
         for d in $ac_bdb_prefix; do
             bdbpfx="$bdbpfx $d"
@@ -909,9 +917,7 @@ AC_ARG_ENABLE(hcache, AC_HELP_STRING([--enable-hcache], [Enable header caching])
         fi
     fi
 
-    if test x$ac_cv_vlopen = xyes; then
-        CPPFLAGS="$OLDCPPFLAGS"
-        LIBS="$OLDLIBS -lqdbm";
+    if test "$use_qdbm" = yes; then
         AC_DEFINE(HAVE_QDBM, 1, [QDBM Support])
     elif test x$ac_cv_gdbmopen = xyes; then
         CPPFLAGS="$OLDCPPFLAGS"
@@ -920,9 +926,9 @@ AC_ARG_ENABLE(hcache, AC_HELP_STRING([--enable-hcache], [Enable header caching])
     elif test x$ac_cv_dbcreate = xyes; then
         CPPFLAGS="$OLDCPPFLAGS -I$BDB_INCLUDE_DIR"
         LIBS="$OLDLIBS -L$BDB_LIB_DIR -l$BDB_LIB"
-        AC_DEFINE(HAVE_DB4, 1, [Sleepycat DB4 Support])
+        AC_DEFINE(HAVE_DB4, 1, [Berkeley DB4 Support])
     else
-        AC_MSG_ERROR([You need QDBM, GDBM or Sleepycat DB4 for hcache])
+        AC_MSG_ERROR([You need QDBM, GDBM or Berkeley DB4 for hcache])
     fi
 fi])
 dnl -- end cache --
diff --git a/hcache.c b/hcache.c
index 7d1ffe4e..0ee890ad 100644
--- a/hcache.c
+++ b/hcache.c
@@ -22,10 +22,15 @@
 #include "config.h"
 #endif				/* HAVE_CONFIG_H */
 
-#if HAVE_QDBM
+#if HAVE_VILLA_H
 #include <depot.h>
 #include <cabin.h>
 #include <villa.h>
+#elif HAVE_QDBM_VILLA_H
+#include <qdbm/depot.h>
+#include <qdbm/cabin.h>
+#include <qdbm/villa.h>
+#endif
 #elif HAVE_GDBM
 #include <gdbm.h>
 #elif HAVE_DB4
-- 
2.40.0