c79c3cd
From 964b72f05f056a6a494e8650c37f7172320fb9cd Mon Sep 17 00:00:00 2001
99ab4c8
From: Jeffrey C. Ollie <jcollie@pc21224.campus.dmacc.edu>
99ab4c8
Date: Thu, 8 Nov 2007 15:47:38 -0600
99ab4c8
Subject: [PATCH] Patch so that system IMAP library can be used.
99ab4c8
99ab4c8
---
99ab4c8
 apps/app_voicemail.c |   10 ++++++++++
99ab4c8
 configure            |   37 ++++++++++++++++++++++++++++---------
99ab4c8
 configure.ac         |   36 +++++++++++++++++++++++++++---------
99ab4c8
 doc/imapstorage.txt  |   34 ++++++++++++++++------------------
99ab4c8
 4 files changed, 81 insertions(+), 36 deletions(-)
99ab4c8
99ab4c8
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
c79c3cd
index fec54fc..d455a0f 100644
99ab4c8
--- a/apps/app_voicemail.c
99ab4c8
+++ b/apps/app_voicemail.c
99ab4c8
@@ -70,10 +70,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
99ab4c8
 #include <ctype.h>
99ab4c8
 #include <signal.h>
99ab4c8
 #include <pwd.h>
99ab4c8
+#ifdef USE_SYSTEM_IMAP
99ab4c8
+#include <imap/c-client.h>
99ab4c8
+#include <imap/imap4r1.h>
99ab4c8
+#include <imap/linkage.h>
99ab4c8
+#else
99ab4c8
 #include "c-client.h"
99ab4c8
 #include "imap4r1.h"
99ab4c8
 #include "linkage.h"
99ab4c8
 #endif
99ab4c8
+#endif
99ab4c8
 #include "asterisk/lock.h"
99ab4c8
 #include "asterisk/file.h"
99ab4c8
 #include "asterisk/logger.h"
c79c3cd
@@ -4708,7 +4714,11 @@ static int init_mailstream(struct vm_state *vms, int box)
99ab4c8
 
99ab4c8
 	if (delimiter == '\0') {		/* did not probe the server yet */
99ab4c8
 		char *cp;
99ab4c8
+#if USE_SYSTEM_IMAP
99ab4c8
+#include <imap/linkage.c>
99ab4c8
+#else
99ab4c8
 #include "linkage.c"
99ab4c8
+#endif
99ab4c8
 		/* Connect to INBOX first to get folders delimiter */
99ab4c8
 		imap_mailbox_name(tmp, sizeof(tmp), vms, 0, 1);
99ab4c8
 		stream = mail_open (stream, tmp, debug ? OP_DEBUG : NIL);
99ab4c8
diff --git a/configure b/configure
c79c3cd
index f296f05..fb3bdbf 100755
99ab4c8
--- a/configure
99ab4c8
+++ b/configure
c79c3cd
@@ -18652,7 +18652,10 @@ fi
99ab4c8
 fi
99ab4c8
 
99ab4c8
 if test "${USE_IMAP_TK}" != "no"; then
99ab4c8
-   if test "${IMAP_TK_DIR}" = ""; then
99ab4c8
+   if test "${IMAP_TK_DIR}" = "system" ; then
99ab4c8
+      { echo "$as_me:$LINENO: Checking for system c-client library..." >&5
99ab4c8
+echo "$as_me: Checking for system c-client library..." >&6;}
99ab4c8
+   elif test "${IMAP_TK_DIR}" = ""; then
99ab4c8
       IMAP_TK_DIR=`pwd`"/../imap-2004g"
99ab4c8
       if test  -n "${IMAP_TK_MANDATORY}"; then
99ab4c8
 	 { echo "$as_me:$LINENO: The --with-imap option does not search your system for installed" >&5
c79c3cd
@@ -18665,22 +18668,34 @@ echo "$as_me: the configure script will assume you have placed built the c-clien
99ab4c8
 echo "$as_me: files at ${IMAP_TK_DIR}, as outlined in the doc/imapstorage.txt file." >&6;}
99ab4c8
       fi
99ab4c8
    fi
99ab4c8
-   { echo "$as_me:$LINENO: checking for UW IMAP Toolkit c-client library" >&5
99ab4c8
+   if test "${IMAP_TK_DIR}" != "system" ; then
99ab4c8
+      { echo "$as_me:$LINENO: checking for UW IMAP Toolkit c-client library" >&5
99ab4c8
 echo $ECHO_N "checking for UW IMAP Toolkit c-client library... $ECHO_C" >&6; }
99ab4c8
+   fi
99ab4c8
    saved_cppflags="${CPPFLAGS}"
99ab4c8
    saved_libs="${LIBS}"
99ab4c8
-   if test -f ${IMAP_TK_DIR}/c-client/LDFLAGS ; then
99ab4c8
+   if test "${IMAP_TK_DIR}" = "system" ; then
99ab4c8
+      imap_ldflags=""
99ab4c8
+      imap_libs="-lc-client"
99ab4c8
+      imap_include="-DUSE_SYSTEM_IMAP"
99ab4c8
+   elif test -f ${IMAP_TK_DIR}/c-client/LDFLAGS ; then
99ab4c8
       imap_ldflags=`cat ${IMAP_TK_DIR}/c-client/LDFLAGS`
99ab4c8
+      imap_libs="${IMAP_TK_DIR}/c-client/c-client.a"
99ab4c8
+      imap_include="-I${IMAP_TK_DIR}/c-client"
99ab4c8
    fi
99ab4c8
-   CPPFLAGS="${CPPFLAGS} -I${IMAP_TK_DIR}/c-client"
99ab4c8
-   LIBS="${LIBS} ${IMAP_TK_DIR}/c-client/c-client.a "`echo ${imap_ldflags}`
99ab4c8
+   CPPFLAGS="${CPPFLAGS} ${imap_include}"
99ab4c8
+   LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
99ab4c8
    cat >conftest.$ac_ext <<_ACEOF
99ab4c8
 /* confdefs.h.  */
99ab4c8
 _ACEOF
99ab4c8
 cat confdefs.h >>conftest.$ac_ext
99ab4c8
 cat >>conftest.$ac_ext <<_ACEOF
99ab4c8
 /* end confdefs.h.  */
99ab4c8
-#include "c-client.h"
99ab4c8
+#ifdef USE_SYSTEM_IMAP
99ab4c8
+		#include <imap/c-client.h>
99ab4c8
+		#else
99ab4c8
+		#include "c-client.h"
99ab4c8
+		#endif
99ab4c8
 		void mm_searched (MAILSTREAM *stream,unsigned long number)
99ab4c8
 		{
99ab4c8
 		}
c79c3cd
@@ -18773,7 +18788,11 @@ _ACEOF
99ab4c8
 cat confdefs.h >>conftest.$ac_ext
99ab4c8
 cat >>conftest.$ac_ext <<_ACEOF
99ab4c8
 /* end confdefs.h.  */
99ab4c8
-#include "c-client.h"
99ab4c8
+#ifdef USE_SYSTEM_IMAP
99ab4c8
+	 #include <imap/c-client.h>
99ab4c8
+	 #else
99ab4c8
+	 #include "c-client.h"
99ab4c8
+	 #endif
99ab4c8
          void mm_searched (MAILSTREAM *stream,unsigned long number)
99ab4c8
          {
99ab4c8
          }
c79c3cd
@@ -18865,8 +18884,8 @@ rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
99ab4c8
    if test "${ac_cv_imap_tk}" = "yes"; then
99ab4c8
       { echo "$as_me:$LINENO: result: yes" >&5
99ab4c8
 echo "${ECHO_T}yes" >&6; }
99ab4c8
-      IMAP_TK_LIB="${IMAP_TK_DIR}/c-client/c-client.a "`echo ${imap_ldflags}`
99ab4c8
-      IMAP_TK_INCLUDE="-I${IMAP_TK_DIR}/c-client"
99ab4c8
+      IMAP_TK_LIB="${imap_libs}"`echo ${imap_ldflags}`
99ab4c8
+      IMAP_TK_INCLUDE="${imap_include}"
99ab4c8
       PBX_IMAP_TK=1
99ab4c8
 
99ab4c8
 cat >>confdefs.h <<\_ACEOF
99ab4c8
diff --git a/configure.ac b/configure.ac
c79c3cd
index 8f1d95c..4b074ba 100644
99ab4c8
--- a/configure.ac
99ab4c8
+++ b/configure.ac
c79c3cd
@@ -467,7 +467,9 @@ if test "${PBX_IKSEMEL}" = 1; then
99ab4c8
 fi
99ab4c8
 
99ab4c8
 if test "${USE_IMAP_TK}" != "no"; then
99ab4c8
-   if test "${IMAP_TK_DIR}" = ""; then
99ab4c8
+   if test "${IMAP_TK_DIR}" = "system" ; then
99ab4c8
+      AC_MSG_NOTICE([Checking for system c-client library...])
99ab4c8
+   elif test "${IMAP_TK_DIR}" = ""; then
99ab4c8
       IMAP_TK_DIR=`pwd`"/../imap-2004g"
99ab4c8
       if test  -n "${IMAP_TK_MANDATORY}"; then
99ab4c8
 	 AC_MSG_NOTICE([The --with-imap option does not search your system for installed])
c79c3cd
@@ -476,17 +478,29 @@ if test "${USE_IMAP_TK}" != "no"; then
99ab4c8
 	 AC_MSG_NOTICE([files at ${IMAP_TK_DIR}, as outlined in the doc/imapstorage.txt file.])
99ab4c8
       fi
99ab4c8
    fi
99ab4c8
-   AC_MSG_CHECKING(for UW IMAP Toolkit c-client library)
99ab4c8
+   if test "${IMAP_TK_DIR}" != "system" ; then
99ab4c8
+      AC_MSG_CHECKING(for UW IMAP Toolkit c-client library)
99ab4c8
+   fi
99ab4c8
    saved_cppflags="${CPPFLAGS}"
99ab4c8
    saved_libs="${LIBS}"
99ab4c8
-   if test -f ${IMAP_TK_DIR}/c-client/LDFLAGS ; then
99ab4c8
+   if test "${IMAP_TK_DIR}" = "system" ; then
99ab4c8
+      imap_ldflags=""
99ab4c8
+      imap_libs="-lc-client"
99ab4c8
+      imap_include="-DUSE_SYSTEM_IMAP"
99ab4c8
+   elif test -f ${IMAP_TK_DIR}/c-client/LDFLAGS ; then
99ab4c8
       imap_ldflags=`cat ${IMAP_TK_DIR}/c-client/LDFLAGS`
99ab4c8
+      imap_libs="${IMAP_TK_DIR}/c-client/c-client.a"
99ab4c8
+      imap_include="-I${IMAP_TK_DIR}/c-client"
99ab4c8
    fi
99ab4c8
-   CPPFLAGS="${CPPFLAGS} -I${IMAP_TK_DIR}/c-client"
99ab4c8
-   LIBS="${LIBS} ${IMAP_TK_DIR}/c-client/c-client.a "`echo ${imap_ldflags}`
99ab4c8
+   CPPFLAGS="${CPPFLAGS} ${imap_include}"
99ab4c8
+   LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
99ab4c8
    AC_LINK_IFELSE(
99ab4c8
 	AC_LANG_PROGRAM(
99ab4c8
-		[#include "c-client.h"
99ab4c8
+		[#ifdef USE_SYSTEM_IMAP
99ab4c8
+		#include <imap/c-client.h>
99ab4c8
+		#else
99ab4c8
+		#include "c-client.h"
99ab4c8
+		#endif
99ab4c8
 		void mm_searched (MAILSTREAM *stream,unsigned long number)
99ab4c8
 		{
99ab4c8
 		}
c79c3cd
@@ -542,7 +556,11 @@ if test "${USE_IMAP_TK}" != "no"; then
99ab4c8
    if test "${ac_cv_imap_tk}" = "yes"; then
99ab4c8
    AC_LINK_IFELSE(
99ab4c8
       AC_LANG_PROGRAM(
99ab4c8
-         [#include "c-client.h"
99ab4c8
+         [#ifdef USE_SYSTEM_IMAP
99ab4c8
+	 #include <imap/c-client.h>
99ab4c8
+	 #else
99ab4c8
+	 #include "c-client.h"
99ab4c8
+	 #endif
99ab4c8
          void mm_searched (MAILSTREAM *stream,unsigned long number)
99ab4c8
          {
99ab4c8
          }
c79c3cd
@@ -600,8 +618,8 @@ if test "${USE_IMAP_TK}" != "no"; then
99ab4c8
    LIBS="${saved_libs}"
99ab4c8
    if test "${ac_cv_imap_tk}" = "yes"; then
99ab4c8
       AC_MSG_RESULT(yes) 
99ab4c8
-      IMAP_TK_LIB="${IMAP_TK_DIR}/c-client/c-client.a "`echo ${imap_ldflags}`
99ab4c8
-      IMAP_TK_INCLUDE="-I${IMAP_TK_DIR}/c-client"
99ab4c8
+      IMAP_TK_LIB="${imap_libs}"`echo ${imap_ldflags}`
99ab4c8
+      IMAP_TK_INCLUDE="${imap_include}"
99ab4c8
       PBX_IMAP_TK=1
99ab4c8
       AC_DEFINE([HAVE_IMAP_TK], 1, [Define if your system has the UW IMAP Toolkit c-client library.])
99ab4c8
       if test "${ac_cv_imap_tk2006}" = "yes"; then
99ab4c8
diff --git a/doc/imapstorage.txt b/doc/imapstorage.txt
99ab4c8
index 1e5484b..d292b5d 100644
99ab4c8
--- a/doc/imapstorage.txt
99ab4c8
+++ b/doc/imapstorage.txt
99ab4c8
@@ -38,10 +38,11 @@ Installation Notes
99ab4c8
 --------------------------------------
99ab4c8
 University of Washington IMAP C-Client
99ab4c8
 --------------------------------------
99ab4c8
-You will need a source distribution of University of Washington's IMAP
99ab4c8
-c-client (http://www.washington.edu/imap/).  Asterisk supports both the
99ab4c8
-2004 and 2006 versions of c-client, however mail_expunge_full is enabled
99ab4c8
-in the 2006 version.
99ab4c8
+If you do not have the University of Washington's IMAP c-client
99ab4c8
+installed on your system, you will need to download the c-client
99ab4c8
+source distribution (http://www.washington.edu/imap/) and compile it.
99ab4c8
+Asterisk supports both the 2004 and 2006 versions of c-client, however
99ab4c8
+mail_expunge_full is enabled in the 2006 version.
99ab4c8
 
99ab4c8
 Note that Asterisk only uses the 'client' portion of the UW IMAP toolkit,
99ab4c8
 but building it also builds an IMAP server and various other utilities.
99ab4c8
@@ -68,20 +69,17 @@ need to run 'make install'.
99ab4c8
 ------------------
99ab4c8
 Compiling Asterisk 
99ab4c8
 ------------------
99ab4c8
-
99ab4c8
-Configure with ./configure --with-imap=/usr/src/imap
99ab4c8
-or where ever you built thfe UWashington IMAP Toolkit. When you run
99ab4c8
-'make menuselect', choose 'Voicemail Build Options' and the
99ab4c8
-IMAP_STORAGE option should be available for selection.
99ab4c8
-
99ab4c8
-Note that the --with-imap option will NOT search your system for an
99ab4c8
-installed copy of the IMAP Toolkit c-client library; the Asterisk
99ab4c8
-Makefiles and configure script are designed to build against an
99ab4c8
-unpacked and compiled source tree of the IMAP Toolkit, not a binary
99ab4c8
-distribution.
99ab4c8
-
99ab4c8
-After selecting it, use the 'x' key to exit menuselect and save
99ab4c8
-your changes, and the build/install Asterisk normally.
99ab4c8
+To use the system c-client library, configure Asterisk with
99ab4c8
+./configure --with-imap=system. If you downloaded the c-client source
99ab4c8
+and compiled it according to the above instructions, configure
99ab4c8
+Asterisk with with ./configure --with-imap=/usr/src/imap or where ever
99ab4c8
+you built the UWashington IMAP Toolkit. When you run 'make
99ab4c8
+menuselect', choose 'Voicemail Build Options' and the IMAP_STORAGE
99ab4c8
+option should be available for selection.
99ab4c8
+
99ab4c8
+After selecting the IMAP_STORAGE option, use the 'x' key to exit
99ab4c8
+menuselect and save your changes, and the build/install Asterisk
99ab4c8
+normally.
99ab4c8
 
99ab4c8
 ---------------------
99ab4c8
 Modify voicemail.conf
99ab4c8
-- 
c79c3cd
1.5.3.6
99ab4c8