[PATCH 10/10] timegm: add portable implementation (Solaris support)

2012-11-03 Thread Blake Jones
The timegm(3) function is a non-standard extension to libc which is
available in GNU libc and on some BSDs.  Although SunOS had this
function in its libc, Solaris (unfortunately) removed it.  This patch
implements a very simple version of timegm() which is good enough for
parse-time-string.c.

Although notmuch's idiom for portability is to test for native
availability and put alternate versions in compat/, that approach led to
a compilation problem in this case.  libnotmuch.a includes a call to
parse_time_string() from parse-time-vrp.o, and parse_time_string() in
libparse-time-string.a needs to call timegm().  An attempt to create
compat/timegm.c caused the link to fail, because libparse-time-string.a
acquired a dependency on the new timegm.o in libnotmuch.a, and the
linker only does a single pass on each ".a" looking for dependencies.
This seems to be the case both for the GNU linker and the Solaris
linker.  A different possible workaround would have been to include
libnotmuch.a multiple times on the link line, but that seemed like a
brittle way to track this dependency.
---
 parse-time-string/parse-time-string.c |   37 -
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/parse-time-string/parse-time-string.c 
b/parse-time-string/parse-time-string.c
index 584067d..28901af 100644
--- a/parse-time-string/parse-time-string.c
+++ b/parse-time-string/parse-time-string.c
@@ -1315,6 +1315,41 @@ fixup_ampm (struct state *state)
 return 0;
 }

+static int
+leapyear (int year)
+{
+return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
+}
+
+/*
+ * This is a simple implementation of timegm() which does what is needed
+ * by create_output() -- just turns the "struct tm" into a GMT time_t.
+ * It does not normalize any of the fields of the "struct tm", nor does
+ * it set tm_wday or tm_yday.
+ */
+static time_t
+local_timegm (struct tm *tm)
+{
+intmonthlen[2][12] = {
+   { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+   { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+};
+intyear, month, days;
+
+days = 365 * (tm->tm_year - 70);
+for (year = 70; year < tm->tm_year; year++) {
+   if (leapyear(1900 + year)) {
+   days++;
+   }
+}
+for (month = 0; month < tm->tm_mon; month++) {
+   days += monthlen[leapyear(1900 + year)][month];
+}
+days += tm->tm_mday - 1;
+
+return days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec);
+}
+
 /* Combine absolute and relative fields, and round. */
 static int
 create_output (struct state *state, time_t *t_out, const time_t *ref,
@@ -1465,7 +1500,7 @@ create_output (struct state *state, time_t *t_out, const 
time_t *ref,
 if (is_field_set (state, TM_TZ)) {
/* tm is in specified TZ, convert to UTC for timegm(3). */
tm.tm_min -= get_field (state, TM_TZ);
-   t = timegm ();
+   t = local_timegm ();
 } else {
/* tm is in local time. */
t = mktime ();
-- 
1.7.9.2



[PATCH 09/10] debugger.c: correct return type from getppid() (Solaris support)

2012-11-03 Thread Blake Jones
Cast the return value of getppid() to "int" from "pid_t" in debugger.c,
since it is being passed to sprintf("%d"), which wants an "int"
argument.  On Solaris, "pid_t" is a "long" for 32-bit programs.
---
 debugger.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/debugger.c b/debugger.c
index e8b9378..8ff13d6 100644
--- a/debugger.c
+++ b/debugger.c
@@ -36,7 +36,7 @@ debugger_is_active (void)
 if (RUNNING_ON_VALGRIND)
return TRUE;

-sprintf (buf, "/proc/%d/exe", getppid ());
+sprintf (buf, "/proc/%d/exe", (int) getppid ());
 if (readlink (buf, buf, sizeof (buf)) != -1 &&
strncmp (basename (buf), "gdb", 3) == 0)
 {
-- 
1.7.9.2



[PATCH 08/10] notmuch-config: header for index() prototype (Solaris support)

2012-11-03 Thread Blake Jones
Linux, FreeBSD, and Solaris all expect to find the prototype for
"index()" in .  On some operating systems, including
 is sufficient to get the prototype, but that's not the case
on Solaris.  This patch just modifies notmuch-config.c to include
 to get the prototype.
---
 notmuch-config.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/notmuch-config.c b/notmuch-config.c
index 3e37a2d..2537a65 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 

 static const char toplevel_config_comment[] =
 " .notmuch-config - Configuration file for the notmuch mail system\n"
-- 
1.7.9.2



[PATCH 07/10] gen-version-script: parse Solaris "nm" output (Solaris support)

2012-11-03 Thread Blake Jones
The output of "nm" on Solaris is substantially different from that on
Linux, and the current version of gen-version-script is tied to the
Linux "nm" output.  This patch separates the parts of "nm" processing
which are dependent on the output format into a couple shell functions,
and makes another shell function to use the appropriate version of
"c++filt" to demangle symbols.  It also modifies lib/Makefile.local
to pass the generated symbol table correctly to the Solaris linker.
---
 lib/Makefile.local|4 
 lib/gen-version-script.sh |   50 -
 2 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/lib/Makefile.local b/lib/Makefile.local
index 0c6b258..2068e4a 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -30,7 +30,11 @@ LIBRARY_SUFFIX = so
 LINKER_NAME = libnotmuch.$(LIBRARY_SUFFIX)
 SONAME = $(LINKER_NAME).$(LIBNOTMUCH_VERSION_MAJOR)
 LIBNAME = $(SONAME).$(LIBNOTMUCH_VERSION_MINOR).$(LIBNOTMUCH_VERSION_RELEASE)
+ifeq ($(PLATFORM),SOLARIS)
+LIBRARY_LINK_FLAG = -shared -Wl,-M notmuch.sym -Wl,-soname=$(SONAME) 
-Wl,--no-undefined -lc
+else
 LIBRARY_LINK_FLAG = -shared -Wl,--version-script=notmuch.sym,-soname=$(SONAME) 
-Wl,--no-undefined
+endif
 ifeq ($(PLATFORM),OPENBSD)
 LIBRARY_LINK_FLAG += -lc
 endif
diff --git a/lib/gen-version-script.sh b/lib/gen-version-script.sh
index 76670d5..d7d96da 100644
--- a/lib/gen-version-script.sh
+++ b/lib/gen-version-script.sh
@@ -1,3 +1,4 @@
+#!/bin/sh

 # we go through a bit of work to get the unmangled names of the
 # typeinfo symbols because of
@@ -11,10 +12,44 @@ fi
 HEADER=$1
 shift

+if [ `uname -s` == SunOS ] ; then
+#
+# Using Solaris "nm", a defined symbol looks like this:
+#
+# [Index]ValueSize Type  Bind  Other Shndx   Name
+# [15]|128| 16|FUNC |GLOB |0|1  |notmuch_tags_get
+#
+# and an undefined symbol looks like this:
+#
+# [Index]ValueSize Type  Bind  Other Shndx   Name
+# [35]|  0|  0|NOTY |GLOB |0|UNDEF  |notmuch_tags_get
+#
+find_xapian_error() {
+   nawk -F'\|' '$7 !~ "UNDEF" && $8 ~ "Xapian.*Error" { print $8 }'
+}
+find_compat_syms() {
+   nawk -F'\|' '$7 !~ "UNDEF" && $8 ~ "get(line|delim)" { print $8 ";" }'
+}
+demangle() {
+   gc++filt "$@"
+}
+else
+find_xapian_error() {
+   awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $3 ~ "Xapian.*Error" {print 
$3}'
+}
+find_compat_syms() {
+   awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $2 == "T" && $3 ~ 
"^get(line|delim)$" {print $3 ";"}'
+}
+demangle() {
+   c++filt "$@"
+}
+fi
+
 printf '{\nglobal:\n'
-nm  $* | awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $3 ~ "Xapian.*Error" {print 
$3}' | sort | uniq | \
-while read sym; do
-demangled=$(c++filt $sym)
+
+# Find the typeinfo for "Xapian::*Error"s.
+nm $* | find_xapian_error | sort | uniq | while read sym; do
+demangled=$(demangle $sym)
 case $demangled in
typeinfo*) 
printf "\t$sym;\n"
@@ -23,6 +58,11 @@ while read sym; do
;;
 esac
 done
-nm $* | awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $2 == "T" && $3 ~ 
"^get(line|delim)$" {print $3 ";"}'
-sed  -n 's/^[[:space:]]*\(notmuch_[a-z_]*\)[[:space:]]*(.*/ \1;/p' $HEADER
+
+# Find the "compat" syms that we need to export.
+nm $* | find_compat_syms
+
+# Finally, get the real notmuch symbols.
+sed -n 's/^[   ]*\(notmuch_[a-z_]*\)[  ]*(.*/ \1;/p' $HEADER
+
 printf "local: *;\n};\n"
-- 
1.7.9.2



[PATCH 06/10] strsep: check for availability (Solaris support)

2012-11-03 Thread Blake Jones
Solaris does not ship a version of the strsep() function.  This change
adds a check to "configure" to see whether notmuch needs to provide its
own implementation, and if so, it uses the new version in
"compat/strsep.c" (which was copied from Mutt, and apparently before
that from glibc).
---
 compat/Makefile.local |4 +++
 compat/compat.h   |4 +++
 compat/have_strsep.c  |   10 
 compat/strsep.c   |   65 +
 configure |   17 +
 5 files changed, 100 insertions(+)
 create mode 100644 compat/have_strsep.c
 create mode 100644 compat/strsep.c

diff --git a/compat/Makefile.local b/compat/Makefile.local
index 13f16cd..2c4f65f 100644
--- a/compat/Makefile.local
+++ b/compat/Makefile.local
@@ -13,4 +13,8 @@ ifneq ($(HAVE_STRCASESTR),1)
 notmuch_compat_srcs += $(dir)/strcasestr.c
 endif

+ifneq ($(HAVE_STRSEP),1)
+notmuch_compat_srcs += $(dir)/strsep.c
+endif
+
 SRCS := $(SRCS) $(notmuch_compat_srcs)
diff --git a/compat/compat.h b/compat/compat.h
index b750501..1fd2723 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -46,6 +46,10 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE 
*fp);
 char* strcasestr(const char *haystack, const char *needle);
 #endif /* !HAVE_STRCASESTR */

+#if !HAVE_STRSEP
+char *strsep(char **stringp, const char *delim);
+#endif /* !HAVE_STRSEP */
+
 /* Silence gcc warnings about unused results.  These warnings exist
  * for a reason; any use of this needs to be justified. */
 #ifdef __GNUC__
diff --git a/compat/have_strsep.c b/compat/have_strsep.c
new file mode 100644
index 000..5bd396c
--- /dev/null
+++ b/compat/have_strsep.c
@@ -0,0 +1,10 @@
+#define _GNU_SOURCE
+#include 
+
+int main()
+{
+char *found;
+char **stringp, const char *delim;
+
+found = strsep(stringp, delim);
+}
diff --git a/compat/strsep.c b/compat/strsep.c
new file mode 100644
index 000..78ab9e7
--- /dev/null
+++ b/compat/strsep.c
@@ -0,0 +1,65 @@
+/* Copyright (C) 1992, 93, 96, 97, 98, 99, 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include 
+
+/* Taken from glibc 2.6.1 */
+
+char *strsep (char **stringp, const char *delim)
+{
+  char *begin, *end;
+
+  begin = *stringp;
+  if (begin == NULL)
+return NULL;
+
+  /* A frequent case is when the delimiter string contains only one
+ character.  Here we don't need to call the expensive `strpbrk'
+ function and instead work using `strchr'.  */
+  if (delim[0] == '\0' || delim[1] == '\0')
+{
+  char ch = delim[0];
+
+  if (ch == '\0')
+   end = NULL;
+  else
+   {
+ if (*begin == ch)
+   end = begin;
+ else if (*begin == '\0')
+   end = NULL;
+ else
+   end = strchr (begin + 1, ch);
+   }
+}
+  else
+/* Find the end of the token.  */
+end = strpbrk (begin, delim);
+
+  if (end)
+{
+  /* Terminate the token and set *STRINGP past NUL character.  */
+  *end++ = '\0';
+  *stringp = end;
+}
+  else
+/* No more delimiters; this is the last token.  */
+*stringp = NULL;
+
+  return begin;
+}
diff --git a/configure b/configure
index dae837e..e519abc 100755
--- a/configure
+++ b/configure
@@ -512,6 +512,17 @@ else
 fi
 rm -f compat/have_strcasestr

+printf "Checking for strsep... "
+if ${CC} -o compat/have_strsep "$srcdir"/compat/have_strsep.c > /dev/null 2>&1
+then
+printf "Yes.\n"
+have_strsep="1"
+else
+printf "No (will use our own instead).\n"
+have_strsep="0"
+fi
+rm -f compat/have_strsep
+
 printf "Checking for standard version of getpwuid_r... "
 if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > 
/dev/null 2>&1
 then
@@ -723,6 +734,10 @@ HAVE_GETLINE = ${have_getline}
 # build its own version)
 HAVE_STRCASESTR = ${have_strcasestr}

+# Whether the strsep function is available (if not, then notmuch will
+# build its own version)
+HAVE_STRSEP = ${have_strsep}
+
 # Whether the getpwuid_r function is standards-compliant
 # (if not, then notmuch will compile with -D_POSIX_PTHREAD_SEMANTICS
 # to enable the standards-compliant version -- needed for Solaris)
@@ -782,12 +797,14 @@ CONFIGURE_CFLAGS = 

[PATCH 05/10] install: check for non-SysV version (Solaris support)

2012-11-03 Thread Blake Jones
Solaris ships a program called "install" in /usr/sbin, which performs a
task that's fairly similar to the GNU and BSD "install" programs but
which uses very different command line arguments.  In particular, if it
is invoked without "-c", "-f", or "-n", it will search the target
directory for a file with the same name as the one being installed, and
it will only install the file if it finds a matching name.  More
excitingly, if it doesn't find a match, it will look in /bin, /usr/bin,
/etc, /lib, and /usr/lib and try to do the same there.

The standard workaround for this is to use GNU install.
It is available via the standard Solaris packaging system (in
"file/gnu-coreutils"), and installs itself as /usr/bin/ginstall.

This patch adds a check to "configure" to see if "install" behaves in a
way that's compatible with GNU and BSD install, and if not, it uses a
program called "ginstall" instead.  It also modifies "configure" to set
the $(INSTALL) variable, and changes various Makefiles to use it.
---
 Makefile.local|2 +-
 completion/Makefile.local |4 ++--
 configure |   19 +++
 emacs/Makefile.local  |6 +++---
 lib/Makefile.local|4 ++--
 man/Makefile.local|6 +++---
 vim/Makefile  |6 ++
 7 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/Makefile.local b/Makefile.local
index 2b91946..7ccb1cd 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -286,7 +286,7 @@ notmuch-shared: $(notmuch_client_modules) lib/$(LINKER_NAME)
 .PHONY: install
 install: all install-man
mkdir -p "$(DESTDIR)$(prefix)/bin/"
-   install notmuch-shared "$(DESTDIR)$(prefix)/bin/notmuch"
+   $(INSTALL) notmuch-shared "$(DESTDIR)$(prefix)/bin/notmuch"
 ifeq ($(MAKECMDGOALS), install)
@echo ""
@echo "Notmuch is now installed to $(DESTDIR)$(prefix)"
diff --git a/completion/Makefile.local b/completion/Makefile.local
index dfc1271..a648a78 100644
--- a/completion/Makefile.local
+++ b/completion/Makefile.local
@@ -14,9 +14,9 @@ install-$(dir):
@echo $@
 ifeq ($(WITH_BASH),1)
mkdir -p "$(DESTDIR)$(bash_completion_dir)"
-   install -m0644 $(bash_script) "$(DESTDIR)$(bash_completion_dir)/notmuch"
+   $(INSTALL) -m0644 $(bash_script) 
"$(DESTDIR)$(bash_completion_dir)/notmuch"
 endif
 ifeq ($(WITH_ZSH),1)
mkdir -p "$(DESTDIR)$(zsh_completion_dir)"
-   install -m0644 $(zsh_script) "$(DESTDIR)$(zsh_completion_dir)/_notmuch"
+   $(INSTALL) -m0644 $(zsh_script) 
"$(DESTDIR)$(zsh_completion_dir)/_notmuch"
 endif
diff --git a/configure b/configure
index 5c5139f..dae837e 100755
--- a/configure
+++ b/configure
@@ -591,6 +591,21 @@ for flag in -Wmissing-declarations; do
 done
 printf "\n\t${WARN_CFLAGS}\n"

+INSTALL="install"
+printf "Checking for working \"install\" program... "
+mkdir _tmp_
+cd _tmp_
+echo 1 > 1
+mkdir dest
+if install 1 dest > /dev/null 2>&1 ; then
+  printf "\"install\" works fine.\n"
+else
+  INSTALL="ginstall"
+  printf "using \"ginstall\".\n"
+fi
+cd ..
+rm -rf _tmp_
+
 rm -f minimal minimal.c

 cat <

[PATCH 04/10] configure: check for -Wl,-rpath (Solaris support)

2012-11-03 Thread Blake Jones
Add a check to "configure" to see whether -Wl,-rpath can be used without
--enable-new-dtags.  Solaris needs the former and doesn't know about the
latter.
---
 configure |4 
 1 file changed, 4 insertions(+)

diff --git a/configure b/configure
index 28d4110..5c5139f 100755
--- a/configure
+++ b/configure
@@ -552,6 +552,10 @@ if ${CC} -Wl,--enable-new-dtags -Wl,-rpath,/tmp/ -o 
minimal minimal.c >/dev/null
 then
 printf "Yes.\n"
 rpath_ldflags="-Wl,--enable-new-dtags -Wl,-rpath,\$(libdir)"
+elif ${CC} -Wl,-rpath,/tmp/ -o minimal minimal.c >/dev/null 2>&1
+then
+printf "Yes.\n"
+rpath_ldflags="-Wl,-rpath,\$(libdir)"
 else
 printf "No (nothing to worry about).\n"
 rpath_ldflags=""
-- 
1.7.9.2



[PATCH 03/10] gethostbyname: check for libnsl (Solaris support)

2012-11-03 Thread Blake Jones
Add a check to "configure" to see whether -lnsl is needed for programs
that are using gethostbyname().  This change also adds the file
"compat/check_ghbn.c", which configure uses to perform its check.
---
 compat/check_ghbn.c |8 
 configure   |   17 -
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 compat/check_ghbn.c

diff --git a/compat/check_ghbn.c b/compat/check_ghbn.c
new file mode 100644
index 000..ec5f227
--- /dev/null
+++ b/compat/check_ghbn.c
@@ -0,0 +1,8 @@
+#include 
+
+int main()
+{
+(void) gethostbyname(NULL);
+
+return (0);
+}
diff --git a/configure b/configure
index 047c011..28d4110 100755
--- a/configure
+++ b/configure
@@ -534,6 +534,17 @@ else
 fi
 rm -f compat/check_asctime

+printf "Checking whether libnsl is needed for gethostbyname... "
+if ${CC} -o compat/check_ghbn "$srcdir"/compat/check_ghbn.c > /dev/null 2>&1
+then
+printf "No.\n"
+libnsl_ldflags=""
+else
+printf "Yes.\n"
+libnsl_ldflags="-lnsl"
+fi
+rm -f compat/check_ghbn
+
 printf "int main(void){return 0;}\n" > minimal.c

 printf "Checking for rpath support... "
@@ -723,6 +734,9 @@ GMIME_LDFLAGS = ${gmime_ldflags}
 TALLOC_CFLAGS = ${talloc_cflags}
 TALLOC_LDFLAGS = ${talloc_ldflags}

+# Flags needed to get gethostbyname() at link time
+LIBNSL_LDFLAGS = ${libnsl_ldflags}
+
 # Flags needed to have linker set rpath attribute
 RPATH_LDFLAGS = ${rpath_ldflags}

@@ -757,5 +771,6 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) 
\$(GMIME_CFLAGS)\\
 -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)   \\
 -DSTD_GETPWUID=\$(STD_GETPWUID) \\
 -DSTD_ASCTIME=\$(STD_ASCTIME)
-CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
+CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS) \\
+\$(LIBNSL_LDFLAGS)
 EOF
-- 
1.7.9.2



[PATCH 02/10] asctime: check for standards compliance (Solaris support)

2012-11-03 Thread Blake Jones
Add checks to "configure" to see whether _POSIX_PTHREAD_SEMANTICS needs
to be defined to get the right number of arguments in the prototypes for
asctime_r().  Solaris' default implementation conforms to POSIX.1c
Draft 6, rather than the final POSIX.1c spec.  The standards-compliant
version can be used by defining _POSIX_PTHREAD_SEMANTICS.

This change also adds the file "compat/check_asctime.c", which
configure uses to perform its check, and modifies compat/compat.h to
define _POSIX_PTHREAD_SEMANTICS if configure detected it was needed.
---
 compat/check_asctime.c |   17 +
 compat/compat.h|3 +++
 configure  |   22 --
 3 files changed, 40 insertions(+), 2 deletions(-)
 create mode 100644 compat/check_asctime.c

diff --git a/compat/check_asctime.c b/compat/check_asctime.c
new file mode 100644
index 000..a595110
--- /dev/null
+++ b/compat/check_asctime.c
@@ -0,0 +1,17 @@
+/*
+ * This compatibility check actually succeeds (on Solaris) if
+ * _POSIX_PTHREAD_SEMANTICS is not defined.  But we need to define that to get
+ * the right version of getpwuid_r(), so we define it here to ensure that the
+ * compatibility check ends up doing the same thing as the rest of the code.
+ */
+#define_POSIX_PTHREAD_SEMANTICS
+#include 
+
+int main()
+{
+struct tm tm;
+
+(void) asctime_r (, NULL, 0);
+
+return (0);
+}
diff --git a/compat/compat.h b/compat/compat.h
index 8374d2f..b750501 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -57,6 +57,9 @@ char* strcasestr(const char *haystack, const char *needle);
 #if !STD_GETPWUID
 #define _POSIX_PTHREAD_SEMANTICS
 #endif
+#if !STD_ASCTIME
+#define _POSIX_PTHREAD_SEMANTICS
+#endif

 #ifdef __cplusplus
 }
diff --git a/configure b/configure
index 3c18a45..047c011 100755
--- a/configure
+++ b/configure
@@ -523,6 +523,17 @@ else
 fi
 rm -f compat/check_getpwuid

+printf "Checking for standard version of asctime_r... "
+if ${CC} -o compat/check_asctime "$srcdir"/compat/check_asctime.c > /dev/null 
2>&1
+then
+printf "Yes.\n"
+std_asctime=1
+else
+printf "No (will define _POSIX_PTHREAD_SEMANTICS to get it).\n"
+std_asctime=0
+fi
+rm -f compat/check_asctime
+
 printf "int main(void){return 0;}\n" > minimal.c

 printf "Checking for rpath support... "
@@ -687,6 +698,11 @@ HAVE_STRCASESTR = ${have_strcasestr}
 # to enable the standards-compliant version -- needed for Solaris)
 STD_GETPWUID = ${std_getpwuid}

+# Whether the asctime_r function is standards-compliant
+# (if not, then notmuch will compile with -D_POSIX_PTHREAD_SEMANTICS
+# to enable the standards-compliant version -- needed for Solaris)
+STD_ASCTIME = ${std_asctime}
+
 # Supported platforms (so far) are: LINUX, MACOSX, SOLARIS, FREEBSD, OPENBSD
 PLATFORM = ${platform}

@@ -733,11 +749,13 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) 
\$(GMIME_CFLAGS)  \\
   \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\
   \$(VALGRIND_CFLAGS)   \\
   -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
-  -DSTD_GETPWUID=\$(STD_GETPWUID)
+  -DSTD_GETPWUID=\$(STD_GETPWUID)   \\
+  -DSTD_ASCTIME=\$(STD_ASCTIME)
 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)\\
 \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
 \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
 -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)   \\
--DSTD_GETPWUID=\$(STD_GETPWUID)
+-DSTD_GETPWUID=\$(STD_GETPWUID) \\
+-DSTD_ASCTIME=\$(STD_ASCTIME)
 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
 EOF
-- 
1.7.9.2



[PATCH 01/10] getpwuid: check for standards compliance (Solaris support)

2012-11-03 Thread Blake Jones
Add checks to "configure" to see whether _POSIX_PTHREAD_SEMANTICS needs
to be defined to get the right number of arguments in the prototypes for
getpwuid_r().  Solaris' default implementation conforms to POSIX.1c
Draft 6, rather than the final POSIX.1c spec.  The standards-compliant
version can be used by defining _POSIX_PTHREAD_SEMANTICS.

This change also adds the file "compat/check_getpwuid.c", which
configure uses to perform its check, and modifies compat/compat.h to
define _POSIX_PTHREAD_SEMANTICS if configure detected it was needed.
---
 compat/check_getpwuid.c |   10 ++
 compat/compat.h |4 
 configure   |   23 +--
 3 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 compat/check_getpwuid.c

diff --git a/compat/check_getpwuid.c b/compat/check_getpwuid.c
new file mode 100644
index 000..5da2590
--- /dev/null
+++ b/compat/check_getpwuid.c
@@ -0,0 +1,10 @@
+#include 
+
+int main()
+{
+struct passwd passwd, *ignored;
+
+(void) getpwuid_r (0, , NULL, 0, );
+
+return (0);
+}
diff --git a/compat/compat.h b/compat/compat.h
index b2e2736..8374d2f 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -54,6 +54,10 @@ char* strcasestr(const char *haystack, const char *needle);
 #define IGNORE_RESULT(x) x
 #endif /* __GNUC__ */

+#if !STD_GETPWUID
+#define _POSIX_PTHREAD_SEMANTICS
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/configure b/configure
index ea8a1ad..3c18a45 100755
--- a/configure
+++ b/configure
@@ -512,6 +512,17 @@ else
 fi
 rm -f compat/have_strcasestr

+printf "Checking for standard version of getpwuid_r... "
+if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > 
/dev/null 2>&1
+then
+printf "Yes.\n"
+std_getpwuid=1
+else
+printf "No (will define _POSIX_PTHREAD_SEMANTICS to get it).\n"
+std_getpwuid=0
+fi
+rm -f compat/check_getpwuid
+
 printf "int main(void){return 0;}\n" > minimal.c

 printf "Checking for rpath support... "
@@ -671,6 +682,11 @@ HAVE_GETLINE = ${have_getline}
 # build its own version)
 HAVE_STRCASESTR = ${have_strcasestr}

+# Whether the getpwuid_r function is standards-compliant
+# (if not, then notmuch will compile with -D_POSIX_PTHREAD_SEMANTICS
+# to enable the standards-compliant version -- needed for Solaris)
+STD_GETPWUID = ${std_getpwuid}
+
 # Supported platforms (so far) are: LINUX, MACOSX, SOLARIS, FREEBSD, OPENBSD
 PLATFORM = ${platform}

@@ -715,10 +731,13 @@ WITH_ZSH = ${WITH_ZSH}
 # Combined flags for compiling and linking against all of the above
 CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)  \\
   \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\
-  \$(VALGRIND_CFLAGS) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)
+  \$(VALGRIND_CFLAGS)   \\
+  -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
+  -DSTD_GETPWUID=\$(STD_GETPWUID)
 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)\\
 \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
 \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
- -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)
+-DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)   \\
+-DSTD_GETPWUID=\$(STD_GETPWUID)
 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
 EOF
-- 
1.7.9.2



[PATCH 00/10] Solaris support

2012-11-03 Thread Blake Jones
Hi all,

This patch series fixes several issues which are needed to allow notmuch
to build on Solaris 11.  I've been "testing" it for a month or so by
using Karel Zak's fork of mutt along with a copy of notmuch-0.13.2 that
I got to compile.  After a friend asked for a copy of my setup, I
decided to try to get my patches cleaned up enough to submit, so that he
wouldn't need to deal with them if he wanted to hack on it.

I don't have access to any machines running a modern version of Linux
(much less *BSD), so I haven't been able to check whether these changes
have broken any other platforms.  I've tried to follow the prevailing
idiom of compatibility checks and conditionally-set variables, to
minimize the impact on other platforms, but it's possible that I
overlooked something.

I'm really pleased with my experience using notmuch; using it along with
the fork of mutt has given me real control of my email for the first
time in many years.  So I'm happy to offer these changes up in the hopes
that they can be useful to others.

I'm not subscribed to the mailing list, so please CC me on any comments.
I'll also try to watch the web archives of the list just in case.

Blake


Automatic suppression of non-duplicate messages

2012-11-03 Thread Eirik Byrkjeflot Anonsen
As has been mentioned a few times before, notmuch chooses to silently
drop any message that has the same message-id as an already-seen
message.

In another thread, Austin Clements said:

> notmuch tracks all copies of a message, but its output generally shows
> messages, rather than files, so you see a message only once regardless
> of how many copies there are in the file system.

That's not what I see.  If I search for a term that only appears in one
of the "copies", none of the copies are included in the search result.

This is with:
$ dpkg -l | grep notmuch | 
ii  libnotmuch30.13.2-1
ii  notmuch0.13.2-1
ii  notmuch-emacs  0.13.2-1


However, I still find it a much bigger problem that notmuch will
silently and automatically discard new mail without letting me know that
they exist, let alone allow me to read them.  (I.e. when receiving a new
mail that happens to have the same message-id as a previously received
mail.)

Personally, I find almost no cost in seeing all near-duplicates of the
same message (a cost that could be further mitigated by clever
presentation).  Conversely, I find a huge cost in never seeing some
messages at all.

This is currently the main issue that keeps me from switching to
notmuch.  (Importing my mail into notmuch dropped roughly 6800 mails.
I'm sure most of these mails are near-duplicates, but I've found 34
mails so far that are emphatically not.)

I think it is a nice and useful design to use the message-id as the
unique id to refer to a specific message.  Most of the time, this will
work just fine.  However, it is less useful to blindly trust that this
will always work correctly.

eirik


Automatic suppression of non-duplicate messages

2012-11-03 Thread Eirik Byrkjeflot Anonsen
As has been mentioned a few times before, notmuch chooses to silently
drop any message that has the same message-id as an already-seen
message.

In another thread, Austin Clements said:

 notmuch tracks all copies of a message, but its output generally shows
 messages, rather than files, so you see a message only once regardless
 of how many copies there are in the file system.

That's not what I see.  If I search for a term that only appears in one
of the copies, none of the copies are included in the search result.

This is with:
$ dpkg -l | grep notmuch | remove uninteresting stuff
ii  libnotmuch30.13.2-1
ii  notmuch0.13.2-1
ii  notmuch-emacs  0.13.2-1


However, I still find it a much bigger problem that notmuch will
silently and automatically discard new mail without letting me know that
they exist, let alone allow me to read them.  (I.e. when receiving a new
mail that happens to have the same message-id as a previously received
mail.)

Personally, I find almost no cost in seeing all near-duplicates of the
same message (a cost that could be further mitigated by clever
presentation).  Conversely, I find a huge cost in never seeing some
messages at all.

This is currently the main issue that keeps me from switching to
notmuch.  (Importing my mail into notmuch dropped roughly 6800 mails.
I'm sure most of these mails are near-duplicates, but I've found 34
mails so far that are emphatically not.)

I think it is a nice and useful design to use the message-id as the
unique id to refer to a specific message.  Most of the time, this will
work just fine.  However, it is less useful to blindly trust that this
will always work correctly.

eirik
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: Automatic suppression of non-duplicate messages

2012-11-03 Thread David Bremner
Eirik Byrkjeflot Anonsen ei...@eirikba.org writes:

 That's not what I see.  If I search for a term that only appears in
 one of the copies, none of the copies are included in the search
 result.

The offending code is at line 1813 of lib/database.cc; the message is
only indexed if the message-id is new.

It might be sensible to move _notmuch_message_index_file into the other
branch of the if, but even if that works fine, something more
sophisticated is needed for the call to
__notmuch_message_set_header_values; the invariant that each message has
a single subject seems reasonable.

Offhand I'm not sure of a good method of automatically deciding what is
the same message (with e.g. headers and footer text added by a mailing
list).



___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v2] contrib: notmuch-pick: add tests

2012-11-03 Thread Tomi Ollila
On Thu, Nov 01 2012, Mark Walters markwalters1...@gmail.com wrote:

 The test should be run using the wrapper run-tests.sh.  This links
 the tests into the normal notmuch TEST_DIRECTORY and runs them from
 there. After the test is complete then the links are removed.
 ---

2 things:

The PICK_DIR variable needs export in run-tests.sh, otherwise it is
not (always??!!) available for test scripts (all tests failed
for me until I added that export (fatal).

git am informs  test/pick.expected-output/notmuch-pick-show-window 
has trailing whitespace when applied. Could you arrange your test
to use other message there (wish).


Tomi



 This is version 2 of the patches to add some tests for notmuch pick. 

 The main change is that I have added Tomi's suggested wrapper script
 (id:m2ip9srpd6@guru.guru-group.fi) which is much more robust and
 generally better than the one I had.

 The other changes are to split out the tests for the default async
 parser from those for the sync parser. My guess is that the sync
 parser should be removed but it can be useful for debugging so is
 probably worth keeping until pick is closer to being ready for proper
 mainline.

 Best wishes

 Mark




  contrib/notmuch-pick/README|5 ++
  contrib/notmuch-pick/run-tests.sh  |   46 
  contrib/notmuch-pick/test/emacs-pick   |   76 
 
  contrib/notmuch-pick/test/emacs-pick-sync  |   64 
  .../pick.expected-output/notmuch-pick-show-window  |   32 
  .../notmuch-pick-single-thread |6 ++
  .../pick.expected-output/notmuch-pick-tag-inbox|   53 ++
  7 files changed, 282 insertions(+), 0 deletions(-)
  create mode 100755 contrib/notmuch-pick/run-tests.sh
  create mode 100755 contrib/notmuch-pick/test/emacs-pick
  create mode 100755 contrib/notmuch-pick/test/emacs-pick-sync
  create mode 100644 
 contrib/notmuch-pick/test/pick.expected-output/notmuch-pick-show-window
  create mode 100644 
 contrib/notmuch-pick/test/pick.expected-output/notmuch-pick-single-thread
  create mode 100644 
 contrib/notmuch-pick/test/pick.expected-output/notmuch-pick-tag-inbox

 diff --git a/contrib/notmuch-pick/README b/contrib/notmuch-pick/README
 index 8eed974..4200824 100644
 --- a/contrib/notmuch-pick/README
 +++ b/contrib/notmuch-pick/README
 @@ -15,6 +15,11 @@ Then after the (require 'notmuch) line in your .emacs 
 file add
  the line (require 'notmuch-pick nil t). This will load notmuch-pick on
  your next emacs start.
  
 +TEST
 +
 +Just execute run-tests.sh and it should all work (it does require that
 +notmuch has already been built).
 +
  USING PICK
  
  The main key entries to notmuch pick are
 diff --git a/contrib/notmuch-pick/run-tests.sh 
 b/contrib/notmuch-pick/run-tests.sh
 new file mode 100755
 index 000..97cc9e8
 --- /dev/null
 +++ b/contrib/notmuch-pick/run-tests.sh
 @@ -0,0 +1,46 @@
 +#!/usr/bin/env bash
 +
 +set -eu
 +
 +fail() {
 +echo ERROR $1
 +exit 1
 +}
 +
 +TESTS=emacs-pick emacs-pick-sync
 +TESTFILES=$TESTS pick.expected-output
 +
 +PICK_DIR=`cd \`dirname $0\`  pwd`
 +PICK_TEST_DIR=$PICK_DIR/test
 +
 +
 +for f in $TESTFILES
 +do
 +test -f $PICK_TEST_DIR/$f || test -d $PICK_TEST_DIR/$f || fail 
 $PICK_TEST_DIR/$f does not exist
 +done
 +
 +cd $PICK_DIR/../../test
 +
 +test -x ../notmuch || fail `cd ..  pwd`/notmuch has not been built
 +
 +for f in $TESTFILES
 +do
 +if test -f $f
 +then
 + fail $f exists
 +fi
 +done
 +
 +trap rm -f $TESTFILES 0
 +
 +for f in $TESTFILES
 +do
 +ln -s $PICK_TEST_DIR/$f .
 +done
 +
 +#don't exec -- traps would not run.
 +for f in $TESTS
 +do
 +echo $f
 +./$f
 +done
 diff --git a/contrib/notmuch-pick/test/emacs-pick 
 b/contrib/notmuch-pick/test/emacs-pick
 new file mode 100755
 index 000..9db4b34
 --- /dev/null
 +++ b/contrib/notmuch-pick/test/emacs-pick
 @@ -0,0 +1,76 @@
 +#!/usr/bin/env bash
 +
 +test_description=emacs pick interface
 +. test-lib.sh
 +
 +EXPECTED=$TEST_DIRECTORY/pick.expected-output
 +
 +add_email_corpus
 +test_begin_subtest Do we have emacs
 +test_emacs '(insert hello\n)
 + (test-output)'
 +cat EOF EXPECTED
 +hello
 +EOF
 +test_expect_equal_file OUTPUT EXPECTED
 +
 +test_begin_subtest Basic notmuch-pick view in emacs
 +test_emacs '(add-to-list (quote load-path) '$PICK_DIR')
 + (require (quote notmuch-pick))
 + (notmuch-pick tag:inbox)
 + (notmuch-test-wait)
 + (test-output)
 + (delete-other-windows)'
 +test_expect_equal_file OUTPUT $EXPECTED/notmuch-pick-tag-inbox
 +
 +test_begin_subtest Navigation of notmuch-hello to search results
 +test_emacs '(notmuch-hello)
 + (goto-char (point-min))
 + (re-search-forward inbox)
 + (widget-button-press (1- (point)))
 + (notmuch-test-wait)
 + (notmuch-pick-from-search-current-query)
 + (notmuch-test-wait)
 + (test-output)
 +