]> git.notmuchmail.org Git - notmuch/commitdiff
Merge branch 'release'
authorDavid Bremner <david@tethera.net>
Sat, 26 Sep 2015 13:31:50 +0000 (10:31 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 26 Sep 2015 13:31:50 +0000 (10:31 -0300)
bring debian specific changes into master

130 files changed:
INSTALL
Makefile.local
NEWS
bindings/Makefile [new file with mode: 0644]
bindings/Makefile.local [new file with mode: 0644]
bindings/ruby/README [new file with mode: 0644]
bindings/ruby/extconf.rb
configure
crypto.c
debian/rules
devel/STYLE
devel/gen-testdb.sh
devel/release-checks.sh
doc/Makefile.local
doc/doxygen.cfg
doc/man1/notmuch-address.rst
doc/man1/notmuch-count.rst
doc/man1/notmuch.rst
doc/man7/notmuch-search-terms.rst
emacs/notmuch-hello.el
emacs/notmuch-lib.el
emacs/notmuch-maildir-fcc.el
emacs/notmuch-mua.el
emacs/notmuch-show.el
emacs/notmuch-tag.el
emacs/notmuch.el
lib/Makefile.local
lib/database-private.h
lib/database.cc
lib/gen-version-script.sh
lib/message-file.c
lib/message.cc
lib/notmuch-private.h
lib/notmuch.h
lib/parse-time-vrp.cc
lib/query.cc
lib/thread.cc
mime-node.c
notmuch-client.h
notmuch-compact.c
notmuch-config.c
notmuch-count.c
notmuch-dump.c
notmuch-insert.c
notmuch-new.c
notmuch-reply.c
notmuch-restore.c
notmuch-search.c
notmuch-setup.c
notmuch-show.c
notmuch-tag.c
notmuch.c
performance-test/M00-new.sh
performance-test/M01-dump-restore.sh
performance-test/T00-new.sh
performance-test/T01-dump-restore.sh
performance-test/T02-tag.sh
performance-test/perf-test-lib.sh
status.c [new file with mode: 0644]
test/Makefile.local
test/README
test/T000-basic.sh
test/T010-help-test.sh
test/T020-compact.sh
test/T030-config.sh
test/T040-setup.sh
test/T050-new.sh
test/T060-count.sh
test/T070-insert.sh
test/T080-search.sh
test/T090-search-output.sh
test/T095-address.sh
test/T100-search-by-folder.sh
test/T110-search-position-overlap-bug.sh
test/T120-search-insufficient-from-quoting.sh
test/T130-search-limiting.sh
test/T140-excludes.sh
test/T150-tagging.sh
test/T160-json.sh
test/T170-sexp.sh
test/T180-text.sh
test/T190-multipart.sh
test/T200-thread-naming.sh
test/T205-author-naming.sh
test/T210-raw.sh
test/T220-reply.sh
test/T230-reply-to-sender.sh
test/T240-dump-restore.sh
test/T250-uuencode.sh
test/T260-thread-order.sh
test/T270-author-order.sh
test/T280-from-guessing.sh
test/T290-long-id.sh
test/T300-encoding.sh
test/T310-emacs.sh
test/T320-emacs-large-search-buffer.sh
test/T330-emacs-subject-to-filename.sh
test/T340-maildir-sync.sh
test/T350-crypto.sh
test/T360-symbol-hiding.sh
test/T370-search-folder-coherence.sh
test/T380-atomicity.sh
test/T390-python.sh
test/T395-ruby.sh [new file with mode: 0755]
test/T400-hooks.sh
test/T410-argument-parsing.sh
test/T420-emacs-test-functions.sh
test/T430-emacs-address-cleaning.sh
test/T440-emacs-hello.sh
test/T450-emacs-show.sh
test/T455-emacs-charsets.sh
test/T460-emacs-tree.sh
test/T470-missing-headers.sh
test/T480-hex-escaping.sh
test/T490-parse-time-string.sh
test/T500-search-date.sh
test/T510-thread-replies.sh
test/T520-show.sh
test/T530-upgrade.sh
test/T550-db-features.sh
test/T560-lib-error.sh
test/T570-revision-tracking.sh [new file with mode: 0755]
test/aggregate-results.sh
test/random-corpus.c
test/symbol-test.cc
test/test-lib-common.sh
test/test-lib.sh
test/test-verbose
util/string-util.c
util/string-util.h

diff --git a/INSTALL b/INSTALL
index eaccd93d276c458cf4c954d88257e40bb2596ce7..b1b9cd55af4380ab525701d39ed7ece8b5c8ef9a 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -20,7 +20,7 @@ configure stage.
 
 Dependencies
 ------------
-Notmuch depends on four libraries: Xapian, GMime 2.4 or 2.6,
+Notmuch depends on four libraries: Xapian, GMime 2.6,
 Talloc, and zlib which are each described below:
 
        Xapian
@@ -39,8 +39,8 @@ Talloc, and zlib which are each described below:
        reading mail while notmuch would wait for Xapian when removing
        the "inbox" and "unread" tags from messages in a thread.
 
-       GMime 2.4 or 2.6
-       ----------------
+       GMime  2.6
+       ----------
        GMime provides decoding of MIME email messages for Notmuch.
 
        Without GMime, Notmuch would not be able to extract and index
index 6d54742334a238cb2fb08e65e9ff0ed09416fe13..d58cea04746a498efe0b2016822b6671822f631c 100644 (file)
@@ -59,7 +59,7 @@ endif
 FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(CONFIGURE_LDFLAGS)
 
 .PHONY: all
-all: notmuch notmuch-shared build-man
+all: notmuch notmuch-shared build-man ruby-bindings
 ifeq ($(MAKECMDGOALS),)
 ifeq ($(shell cat .first-build-message 2>/dev/null),)
        @NOTMUCH_FIRST_BUILD=1 $(MAKE) --no-print-directory all
@@ -271,6 +271,7 @@ dataclean: distclean
 notmuch_client_srcs =          \
        command-line-arguments.c\
        debugger.c              \
+       status.c                \
        gmime-filter-reply.c    \
        hooks.c                 \
        notmuch.c               \
diff --git a/NEWS b/NEWS
index cc8d7edf2432dc804e06dd3c69669e2acfea8acc..3593ded71bd7fdac4d912ec4561fcb73a3ac094b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,32 @@
+Notmuch 0.21 (UNRELEASED)
+=========================
+
+General
+-------
+
+Notmuch now requires gmime >= 2.6.7. The gmime 2.4 series is no longer
+supported.
+
+Emacs Interface
+---------------
+
+`notmuch-emacs-version` is used in `User-Agent` header
+
+  The value of recently introduced variable `notmuch-emacs-version` is
+  now used as a part of `User-Agent` header when sending emails.
+
+Removed `notmuch-version` function by renaming it to `notmuch-cli-version`
+
+  With existing variable `notmuch-emacs-version` the accompanied
+  function which retrieves the version of `notmuch-command` is
+  better named as `notmuch-cli-version`.
+
+Library
+-------
+
+The use of absolute paths is now enforced when calling
+`notmuch_database_{open, create}`.
+
 Notmuch 0.20.2 (2015-06-27)
 ===========================
 
@@ -12,7 +41,7 @@ Notmuch 0.20.1 (2015-06-01)
 Test Suite
 ----------
 
-Work around apparent gdb bug on arm64
+Work around apparent gdb bug on arm64.
 
 Notmuch 0.20 (2015-05-31)
 =========================
@@ -2767,7 +2796,7 @@ New 'G' key binding to trigger mail refresh (G == "Get new mail")
 
   The 'G' key works wherever '=' works. Before refreshing the screen
   it calls an external program that can be used to poll email servers,
-  run notmuch new and setup specific tags for the new emails. The
+  run notmuch new and set up specific tags for the new emails. The
   script to be called should be configured with the "Notmuch Poll
   Script" setting in the customize interface. This script will
   typically invoke "notmuch new" and then perhaps several "notmuch
diff --git a/bindings/Makefile b/bindings/Makefile
new file mode 100644 (file)
index 0000000..de492a7
--- /dev/null
@@ -0,0 +1,7 @@
+# See Makefile.local for the list of files to be compiled in this
+# directory.
+all:
+       $(MAKE) -C .. all
+
+.DEFAULT:
+       $(MAKE) -C .. $@
diff --git a/bindings/Makefile.local b/bindings/Makefile.local
new file mode 100644 (file)
index 0000000..4ecf839
--- /dev/null
@@ -0,0 +1,21 @@
+# -*- makefile -*-
+
+dir := bindings
+
+# force the shared library to be built
+ruby-bindings: lib/$(LINKER_NAME)
+ifeq ($(HAVE_RUBY_DEV),1)
+       cd $(dir)/ruby && \
+               EXTRA_LDFLAGS="$(NO_UNDEFINED_LDFLAGS)" \
+               LIBNOTMUCH="../../lib/$(LINKER_NAME)" \
+               ruby extconf.rb --vendor
+       $(MAKE) -C $(dir)/ruby
+else
+       @echo Missing dependency, skipping ruby bindings
+endif
+
+CLEAN += $(patsubst %,$(dir)/ruby/%, \
+       .RUBYARCHDIR.time \
+       Makefile database.o directory.o filenames.o\
+       init.o message.o messages.o mkmf.log notmuch.so query.o \
+       status.o tags.o thread.o threads.o)
diff --git a/bindings/ruby/README b/bindings/ruby/README
new file mode 100644 (file)
index 0000000..a2946b6
--- /dev/null
@@ -0,0 +1,7 @@
+To build the the notmuch ruby extension, run the following commands
+from the *top level* notmuch source directory:
+
+% ./configure
+% make ruby-bindings
+
+The generic documentation about building notmuch also applies.
index 6160db26e2ea10286fb16065c2c030ea90a0c07e..ddaa6841e5ff2d507c65501f6d81dd00f9e942fe 100644 (file)
@@ -10,22 +10,16 @@ dir = File.join('..', '..', 'lib')
 # includes
 $INCFLAGS = "-I#{dir} #{$INCFLAGS}"
 
-# make sure there are no undefined symbols
-$LDFLAGS += ' -Wl,--no-undefined'
-
-def have_local_library(lib, path, func, headers = nil)
-  checking_for checking_message(func, lib) do
-    lib = File.join(path, lib)
-    if try_func(func, lib, headers)
-      $LOCAL_LIBS += lib
-    end
-  end
+if ENV['EXTRA_LDFLAGS']
+  $LDFLAGS += " " + ENV['EXTRA_LDFLAGS']
 end
 
-if not have_local_library('libnotmuch.so', dir, 'notmuch_database_create', 'notmuch.h')
+if not ENV['LIBNOTMUCH']
   exit 1
 end
 
+$LOCAL_LIBS += ENV['LIBNOTMUCH']
+
 # Create Makefile
 dir_config('notmuch')
 create_makefile('notmuch')
index 4af7ba94f7bd344cba6fb9e355e10ae5034717a4..440d678c7eb3828041a24577cf7f1e37bf36c2ab 100755 (executable)
--- a/configure
+++ b/configure
@@ -21,6 +21,7 @@ srcdir=$(dirname "$0")
 
 subdirs="util compat lib parse-time-string completion doc emacs"
 subdirs="${subdirs} performance-test test test/test-databases"
+subdirs="${subdirs} bindings"
 
 # For a non-srcdir configure invocation (such as ../configure), create
 # the directory structure and copy Makefiles.
@@ -37,7 +38,7 @@ if [ "$srcdir" != "." ]; then
     cp -a "$srcdir"/test/* test
 
     # Emacs only likes to generate compiled files next to the .el files
-    # by default so copy these as well (which is not ideal0.
+    # by default so copy these as well (which is not ideal).
     cp -a "$srcdir"/emacs/*.el emacs
 fi
 
@@ -47,9 +48,11 @@ CC=${CC:-cc}
 CXX=${CXX:-c++}
 CFLAGS=${CFLAGS:--g -O2}
 CPPFLAGS=${CPPFLAGS:-}
+CXXFLAGS_for_sh=${CXXFLAGS:-${CFLAGS}}
 CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}
 LDFLAGS=${LDFLAGS:-}
 XAPIAN_CONFIG=${XAPIAN_CONFIG:-xapian-config}
+PYTHON=${PYTHON:-}
 
 # We don't allow the EMACS or GZIP Makefile variables inherit values
 # from the environment as we do with CC and CXX above. The reason is
@@ -62,20 +65,12 @@ XAPIAN_CONFIG=${XAPIAN_CONFIG:-xapian-config}
 # options.
 PREFIX=/usr/local
 LIBDIR=
+WITH_DOCS=1
 WITH_EMACS=1
 WITH_BASH=1
+WITH_RUBY=1
 WITH_ZSH=1
 
-# Compatible GMime versions (with constraints).
-# If using GMime 2.6, we need to have a version >= 2.6.5 to avoid a
-# crypto bug. We need 2.6.7 for permissive "From " header handling.
-GMIME_24_VERSION_CTR=''
-GMIME_24_VERSION="gmime-2.4 $GMIME_24_VERSION_CTR"
-GMIME_26_VERSION_CTR='>= 2.6.7'
-GMIME_26_VERSION="gmime-2.6 $GMIME_26_VERSION_CTR"
-
-WITH_GMIME_VERSIONS="$GMIME_26_VERSION;$GMIME_24_VERSION"
-
 usage ()
 {
     cat <<EOF
@@ -95,7 +90,7 @@ First, some common variables can specified via environment variables:
 
        CC              The C compiler to use
        CFLAGS          Flags to pass to the C compiler
-        CPPFLAGS       Flags to pass to the C preprocessor
+       CPPFLAGS        Flags to pass to the C preprocessor
        CXX             The C++ compiler to use
        CXXFLAGS        Flags to pass to the C compiler
        LDFLAGS         Flags to pass when linking
@@ -109,6 +104,8 @@ Other environment variables can be used to control configure itself,
        XAPIAN_CONFIG   The program to use to determine flags for
                        compiling and linking against the Xapian
                        library. [$XAPIAN_CONFIG]
+       PYTHON          Name of python command to use in
+                       configure and the test suite.
 
 Additionally, various options can be specified on the configure
 command line.
@@ -133,15 +130,13 @@ Fine tuning of some installation directories is available:
        --bashcompletiondir=DIR Bash completions files [SYSCONFDIR/bash_completion.d]
        --zshcompletiondir=DIR  Zsh completions files [PREFIX/share/zsh/functions/Completion/Unix]
 
-Some specific library versions can be specified (auto-detected otherwise):
-
-        --with-gmime-version=VERS       Specify GMIME version (2.4 or 2.6)
-
 Some features can be disabled (--with-feature=no is equivalent to
 --without-feature) :
 
-       --without-emacs                 Do not install lisp file
        --without-bash-completion       Do not install bash completions files
+       --without-docs                  Do not install documentation and man pages
+       --without-emacs                 Do not install lisp file
+       --without-ruby                  Do not install ruby bindings
        --without-zsh-completion        Do not install zsh completions files
 
 Additional options are accepted for compatibility with other
@@ -182,6 +177,14 @@ for option; do
        BASHCOMPLETIONDIR="${option#*=}"
     elif [ "${option%%=*}" = '--zshcompletiondir' ] ; then
        ZSHCOMLETIONDIR="${option#*=}"
+    elif [ "${option%%=*}" = '--with-docs' ]; then
+       if [ "${option#*=}" = 'no' ]; then
+           WITH_DOCS=0
+       else
+           WITH_DOCS=1
+       fi
+    elif [ "${option}" = '--without-docs' ] ; then
+       WITH_DOCS=0
     elif [ "${option%%=*}" = '--with-emacs' ]; then
        if [ "${option#*=}" = 'no' ]; then
            WITH_EMACS=0
@@ -198,6 +201,14 @@ for option; do
        fi
     elif [ "${option}" = '--without-bash-completion' ] ; then
        WITH_BASH=0
+    elif [ "${option%%=*}" = '--with-ruby' ]; then
+       if [ "${option#*=}" = 'no' ]; then
+           WITH_RUBY=0
+       else
+           WITH_RUBY=1
+       fi
+    elif [ "${option}" = '--without-ruby' ] ; then
+       WITH_RUBY=0
     elif [ "${option%%=*}" = '--with-zsh-completion' ]; then
        if [ "${option#*=}" = 'no' ]; then
            WITH_ZSH=0
@@ -206,12 +217,6 @@ for option; do
        fi
     elif [ "${option}" = '--without-zsh-completion' ] ; then
        WITH_ZSH=0
-    elif [ "${option%%=*}" = '--with-gmime-version' ] ; then
-       if [ "${option#*=}" = '2.4' ]; then
-            WITH_GMIME_VERSIONS=$GMIME_24_VERSION
-        elif [ "${option#*=}" = '2.6' ]; then
-            WITH_GMIME_VERSIONS=$GMIME_26_VERSION
-       fi
     elif [ "${option%%=*}" = '--build' ] ; then
        true
     elif [ "${option%%=*}" = '--host' ] ; then
@@ -269,6 +274,64 @@ dependencies are available:
 EOF
 
 errors=0
+printf "int main(void){return 0;}\n" > minimal.c
+
+printf "Sanity checking C compilation environment... "
+if ${CC} ${CFLAGS} ${CPPFLAGS} minimal.c ${LDFLAGS} -o minimal > /dev/null 2>&1
+then
+    printf "OK.\n"
+else
+    printf "Fail.\n"
+    errors=$((errors + 1))
+fi
+
+printf "Sanity checking C++ compilation environment... "
+if ${CXX} ${CXXFLAGS_for_sh} ${CPPFLAGS} minimal.c ${LDFLAGS} -o minimal > /dev/null 2>&1
+then
+    printf "OK.\n"
+else
+    printf "Fail.\n"
+    errors=$((errors + 1))
+fi
+
+if [ $errors -gt 0 ]; then
+    cat <<EOF
+*** Error: Initial sanity checking of environment failed.  Please try
+running configure in a clean environment, and if the problem persists,
+report a bug.
+EOF
+    rm -f minimal minimal.c
+    exit 1
+fi
+
+printf "Reading libnotmuch version from source... "
+cat > _libversion.c <<EOF
+#include <stdio.h>
+#include "lib/notmuch.h"
+int main(void) {
+    printf("libnotmuch_version_major=%d\n",
+               LIBNOTMUCH_MAJOR_VERSION);
+    printf("libnotmuch_version_minor=%d\n",
+               LIBNOTMUCH_MINOR_VERSION);
+    printf("libnotmuch_version_release=%d\n",
+               LIBNOTMUCH_MICRO_VERSION);
+    return 0;
+}
+EOF
+if ${CC} ${CFLAGS} _libversion.c -o _libversion > /dev/null 2>&1 && \
+       ./_libversion > _libversion.sh && . ./_libversion.sh
+then
+    printf "OK.\n"
+else
+    cat <<EOF
+
+*** Error: Reading lib/notmuch.h failed.
+Please try running configure again in a clean environment, and if the
+problem persists, report a bug.
+EOF
+    rm -f _libversion _libversion.c _libversion.sh
+    exit 1
+fi
 
 if pkg-config --version > /dev/null 2>&1; then
     have_pkg_config=1
@@ -298,30 +361,29 @@ have_xapian_compact=0
 if [ ${have_xapian} = "1" ]; then
     printf "Checking for Xapian compaction support... "
     case "${xapian_version}" in
-        0.*|1.[01].*|1.2.[0-5])
-            printf "No (only available with Xapian > 1.2.6).\n" ;;
-        [1-9]*.[0-9]*.[0-9]*)
-            have_xapian_compact=1
-            printf "Yes.\n" ;;
-        *)
-            printf "Unknown version.\n" ;;
+       0.*|1.[01].*|1.2.[0-5])
+           printf "No (only available with Xapian > 1.2.6).\n" ;;
+       [1-9]*.[0-9]*.[0-9]*)
+           have_xapian_compact=1
+           printf "Yes.\n" ;;
+       *)
+           printf "Unknown version.\n" ;;
     esac
 fi
 
+
+# we need to have a version >= 2.6.5 to avoid a crypto bug. We need
+# 2.6.7 for permissive "From " header handling.
+GMIME_MINVER=2.6.7
+
 printf "Checking for GMime development files... "
-have_gmime=0
-IFS=';'
-for gmimepc in $WITH_GMIME_VERSIONS; do
-    if pkg-config --exists $gmimepc; then
-       printf "Yes ($gmimepc).\n"
-       have_gmime=1
-       gmime_cflags=$(pkg-config --cflags $gmimepc)
-       gmime_ldflags=$(pkg-config --libs $gmimepc)
-       break
-    fi
-done
-IFS=$DEFAULT_IFS
-if [ "$have_gmime" = "0" ]; then
+if pkg-config --exists "gmime-2.6 >= $GMIME_MINVER"; then
+    printf "Yes.\n"
+    have_gmime=1
+    gmime_cflags=$(pkg-config --cflags gmime-2.6)
+    gmime_ldflags=$(pkg-config --libs gmime-2.6)
+else
+    have_gmime=0
     printf "No.\n"
     errors=$((errors + 1))
 fi
@@ -377,7 +439,7 @@ fi
 printf "Checking for python... "
 have_python=0
 
-for name in python python2 python3; do
+for name in ${PYTHON} python python2 python3; do
     if command -v $name > /dev/null; then
        have_python=1
        python=$name
@@ -434,22 +496,37 @@ else
     have_emacs=0
 fi
 
-printf "Checking if doxygen is available... "
-if command -v doxygen > /dev/null; then
-    printf "Yes.\n"
-    have_doxygen=1
-else
-    printf "No (so will not install api docs)\n"
-    have_doxygen=0
+have_doxygen=0
+if [ $WITH_DOCS = "1" ] ; then
+    printf "Checking if doxygen is available... "
+    if command -v doxygen > /dev/null; then
+       printf "Yes.\n"
+       have_doxygen=1
+    else
+       printf "No (so will not install api docs)\n"
+    fi
 fi
 
-printf "Checking if sphinx is available and supports nroff output... "
-if command -v sphinx-build > /dev/null && ${python} -m sphinx.writers.manpage > /dev/null 2>&1 ; then
-    printf "Yes.\n"
-    have_sphinx=1
-else
-    printf "No (so will not install man pages).\n"
-    have_sphinx=0
+have_ruby_dev=0
+if [ $WITH_RUBY = "1" ] ; then
+    printf "Checking for ruby development files... "
+    if ruby -e "require 'mkmf'"> /dev/null 2>&1; then
+       printf "Yes.\n"
+       have_ruby_dev=1
+    else
+       printf "No (skipping ruby bindings)\n"
+    fi
+fi
+
+have_sphinx=0
+if [ $WITH_DOCS = "1" ] ; then
+    printf "Checking if sphinx is available and supports nroff output... "
+    if command -v sphinx-build > /dev/null && ${python} -m sphinx.writers.manpage > /dev/null 2>&1 ; then
+       printf "Yes.\n"
+       have_sphinx=1
+    else
+       printf "No (so will not install man pages).\n"
+    fi
 fi
 
 libdir_in_ldconfig=0
@@ -542,7 +619,7 @@ EOF
        echo
     fi
     if [ $have_gmime -eq 0 ]; then
-       echo "  Either GMime 2.4 library" $GMIME_24_VERSION_CTR "or GMime 2.6 library" $GMIME_26_VERSION_CTR
+       echo "  GMime 2.6 library >= $GMIME_MINVER"
        echo "  (including development files such as headers)"
        echo "  http://spruce.sourceforge.net/gmime/"
        echo
@@ -690,8 +767,6 @@ else
 fi
 rm -f compat/check_asctime
 
-printf "int main(void){return 0;}\n" > minimal.c
-
 printf "Checking for rpath support... "
 if ${CC} -Wl,--enable-new-dtags -Wl,-rpath,/tmp/ -o minimal minimal.c >/dev/null 2>&1
 then
@@ -712,6 +787,16 @@ else
     as_needed_ldflags=""
 fi
 
+printf "Checking for -Wl,--no-undefined... "
+if ${CC} -Wl,--no-undefined -o minimal minimal.c >/dev/null 2>&1
+then
+    printf "Yes.\n"
+    no_undefined_ldflags="-Wl,--no-undefined"
+else
+    printf "No (nothing to worry about).\n"
+    no_undefined_ldflags=""
+fi
+
 WARN_CXXFLAGS=""
 printf "Checking for available C++ compiler warning flags... "
 for flag in -Wall -Wextra -Wwrite-strings; do
@@ -732,7 +817,7 @@ for flag in -Wmissing-declarations; do
 done
 printf "\n\t${WARN_CFLAGS}\n"
 
-rm -f minimal minimal.c
+rm -f minimal minimal.c _libversion.c _libversion _libversion.sh
 
 # construct the Makefile.config
 cat > Makefile.config <<EOF
@@ -770,6 +855,28 @@ vpath Makefile.% \$(srcdir)
 vpath %.py \$(srcdir)
 vpath %.rst \$(srcdir)
 
+# Library versions (used to make SONAME)
+# The major version of the library interface. This will control the soname.
+# As such, this number must be incremented for any incompatible change to
+# the library interface, (such as the deletion of an API or a major
+# semantic change that breaks formerly functioning code).
+#
+LIBNOTMUCH_VERSION_MAJOR = ${libnotmuch_version_major}
+
+# The minor version of the library interface. This should be incremented at
+# the time of release for any additions to the library interface,
+# (and when it is incremented, the release version of the library should
+#  be reset to 0).
+LIBNOTMUCH_VERSION_MINOR = ${libnotmuch_version_minor}
+
+# The release version the library interface. This should be incremented at
+# the time of release if there have been no changes to the interface, (but
+# simply compatible changes to the implementation).
+LIBNOTMUCH_VERSION_RELEASE = ${libnotmuch_version_release}
+
+# These are derived from the VERSION macros in lib/notmuch.h so
+# if you have to change them, something is wrong.
+
 # The C compiler to use
 CC = ${CC}
 
@@ -858,6 +965,10 @@ HAVE_CANONICALIZE_FILE_NAME = ${have_canonicalize_file_name}
 # build its own version)
 HAVE_GETLINE = ${have_getline}
 
+# Are the ruby development files (and ruby) available? If not skip
+# building/testing ruby bindings.
+HAVE_RUBY_DEV = ${have_ruby_dev}
+
 # Whether the strcasestr function is available (if not, then notmuch will
 # build its own version)
 HAVE_STRCASESTR = ${have_strcasestr}
@@ -894,7 +1005,7 @@ LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}
 XAPIAN_CXXFLAGS = ${xapian_cxxflags}
 XAPIAN_LDFLAGS = ${xapian_ldflags}
 
-# Flags needed to compile and link against GMime-2.4
+# Flags needed to compile and link against GMime
 GMIME_CFLAGS = ${gmime_cflags}
 GMIME_LDFLAGS = ${gmime_ldflags}
 
@@ -912,6 +1023,9 @@ RPATH_LDFLAGS = ${rpath_ldflags}
 # Flags needed to have linker link only to necessary libraries
 AS_NEEDED_LDFLAGS = ${as_needed_ldflags}
 
+# Flags to have the linker flag undefined symbols in object files
+NO_UNDEFINED_LDFLAGS = ${no_undefined_ldflags}
+
 # Whether valgrind header files are available
 HAVE_VALGRIND = ${have_valgrind}
 
@@ -970,6 +1084,10 @@ NOTMUCH_HAVE_MAN=$((have_sphinx))
 
 # Name of python interpreter
 NOTMUCH_PYTHON=${python}
+
+# Are the ruby development files (and ruby) available? If not skip
+# building/testing ruby bindings.
+NOTMUCH_HAVE_RUBY_DEV=${have_ruby_dev}
 EOF
 
 # Finally, after everything configured, inform the user how to continue.
index 026640fee8b2cd5006becda9f0ff76ce801f4847..a6eb27db7f630c131149377f7e51a190df86f613 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -20,8 +20,6 @@
 
 #include "notmuch-client.h"
 
-#ifdef GMIME_ATLEAST_26
-
 /* Create a GPG context (GMime 2.6) */
 static notmuch_crypto_context_t *
 create_gpg_context (const char *gpgpath)
@@ -39,29 +37,6 @@ create_gpg_context (const char *gpgpath)
     return gpgctx;
 }
 
-#else /* GMIME_ATLEAST_26 */
-
-/* Create a GPG context (GMime 2.4) */
-static notmuch_crypto_context_t *
-create_gpg_context (const char* gpgpath)
-{
-    GMimeSession *session;
-    notmuch_crypto_context_t *gpgctx;
-
-    session = g_object_new (g_mime_session_get_type (), NULL);
-    gpgctx = g_mime_gpg_context_new (session, gpgpath ? gpgpath : "gpg");
-    g_object_unref (session);
-
-    if (! gpgctx)
-       return NULL;
-
-    g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);
-
-    return gpgctx;
-}
-
-#endif /* GMIME_ATLEAST_26 */
-
 /* for the specified protocol return the context pointer (initializing
  * if needed) */
 notmuch_crypto_context_t *
index 56378ecd66827c6c1391c7e9011319153352c341..04f0062a53ab992eb8f0f927a7644ab1a48d128a 100755 (executable)
@@ -19,7 +19,6 @@ override_dh_auto_build:
        dh_auto_build -- V=1
        dh_auto_build --sourcedirectory bindings/python
        cd bindings/python && $(python3_all) setup.py build
-       cd bindings/ruby && ruby extconf.rb --vendor && make
        $(MAKE) -C contrib/notmuch-mutt
 
 override_dh_auto_clean:
index 92de42ccc9ba1847234532a88b58840ab5b0151a..24bd5482a4899b185f923302bb4801177dc6b3ea 100644 (file)
@@ -93,3 +93,13 @@ libnotmuch conventions
 
 * Code which needs to be accessed from both the CLI and from
   libnotmuch should be factored out into libutil (under util/).
+
+* Deprecated functions should be marked with the NOTMUCH_DEPRECATED
+  macro which generates run time warnings with gcc and clang. In order
+  not to confuse doxygen this should go at the beginning of the
+  declaration like:
+
+  NOTMUCH_DEPRECATED(major,minor) notmuch_status_t notmuch_dwim(void *arg);
+
+  The @deprecated doxygen command can be used to generate markup in
+  the API docs.
index 621b31e67fc22a402795e2a6c3c9b3c72054fb0f..61ae48a316ad6d52755eb578a3db32230638ddf2 100755 (executable)
@@ -79,7 +79,7 @@ while getopts v:c:s: opt; do
 done
 shift `expr $OPTIND - 1`
 
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 SHORT_CORPUS=$(basename ${CORPUS:-database})
 DBNAME=${SHORT_CORPUS}${SUFFIX}
index ae02f557af23bda8488035367d2ae8eae5f95bb6..8604a9f7d10bb3e62a620de25ae02d7031bf8c42 100755 (executable)
@@ -59,6 +59,17 @@ readonly VERSION
 
 # In the rest of this file, tests collect list of errors to be fixed
 
+echo -n "Checking that git working directory is clean... "
+git_status=`git status --porcelain`
+if [ "$git_status" = '' ]
+then
+       echo Yes.
+else
+       echo No.
+       append_emsg "Git working directory is not clean (git status --porcelain)."
+fi
+unset git_status
+
 verfail ()
 {
        echo No.
@@ -77,38 +88,6 @@ case $VERSION in
        *)      verfail "'$VERSION' is a single number" ;;
 esac
 
-echo -n "Checking that LIBNOTMUCH version macros & variables match ... "
-# lib/notmuch.h
-LIBNOTMUCH_MAJOR_VERSION=broken
-LIBNOTMUCH_MINOR_VERSION=broken
-LIBNOTMUCH_MICRO_VERSION=broken
-# lib/Makefile.local
-LIBNOTMUCH_VERSION_MAJOR=borken
-LIBNOTMUCH_VERSION_MINOR=borken
-LIBNOTMUCH_VERSION_RELEASE=borken
-
-eval `awk 'NF == 3 && $1 == "#define" && $2 ~ /^LIBNOTMUCH_[A-Z]+_VERSION$/ \
-       && $3 ~ /^[0-9]+$/ { print $2 "=" $3 }' lib/notmuch.h`
-
-eval `awk 'NF == 3 && $1 ~ /^LIBNOTMUCH_VERSION_[A-Z]+$/ && $2 == "=" \
-       && $3 ~ /^[0-9]+$/ { print $1 "=" $3 }' lib/Makefile.local`
-
-
-check_version_component ()
-{
-       eval local v1=\$LIBNOTMUCH_$1_VERSION
-       eval local v2=\$LIBNOTMUCH_VERSION_$2
-       if [ $v1 != $v2 ]
-       then    append_emsg "LIBNOTMUCH_$1_VERSION ($v1) does not equal LIBNOTMUCH_VERSION_$2 ($v2)"
-       fi
-}
-
-old_emsg_count=$emsg_count
-check_version_component MAJOR MAJOR
-check_version_component MINOR MINOR
-check_version_component MICRO RELEASE
-[ $old_emsg_count = $emsg_count ] && echo Yes. || echo No.
-
 echo -n "Checking that this is Debian package for notmuch... "
 read deb_notmuch deb_version rest < debian/changelog
 if [ "$deb_notmuch" = 'notmuch' ]
@@ -130,7 +109,7 @@ else
 fi
 
 echo -n "Checking that python bindings version is $VERSION... "
-py_version=`python -c "with open('$PV_FILE') as vf: exec(vf.read()); print __VERSION__"`
+py_version=`python -c "with open('$PV_FILE') as vf: exec(vf.read()); print(__VERSION__)"`
 if [ "$py_version" = "$VERSION" ]
 then
        echo Yes.
index e209749176243adf0142a8fa8ca27849838958d6..8633cfcd3b51e24b5df686f576271e63dbc69b4f 100644 (file)
@@ -7,7 +7,7 @@ SPHINXOPTS    := -q
 SPHINXBUILD   = sphinx-build
 DOCBUILDDIR      := $(dir)/_build
 
-mkdocdeps := python $(srcdir)/$(dir)/mkdocdeps.py
+mkdocdeps := $(PYTHON) $(srcdir)/$(dir)/mkdocdeps.py
 
 # Internal variables.
 ALLSPHINXOPTS   := -d $(DOCBUILDDIR)/doctrees $(SPHINXOPTS) $(srcdir)/$(dir)
index 42b633948113beb2ccae9368293054fb6c600385..c033f344d3c3780dc0a50a1fc3036f06c354c1ec 100644 (file)
@@ -74,7 +74,7 @@ STRICT_PROTO_MATCHING  = NO
 GENERATE_TODOLIST      = NO
 GENERATE_TESTLIST      = NO
 GENERATE_BUGLIST       = NO
-GENERATE_DEPRECATEDLIST= NO
+GENERATE_DEPRECATEDLIST= YES
 ENABLED_SECTIONS       =
 MAX_INITIALIZER_LINES  = 30
 SHOW_USED_FILES        = NO
index 9570095b23c8437965e88831e2247fa03dcaaea1..7f7214b32fb3e25a91c0bb6bc5464d94b13c6254 100644 (file)
@@ -55,6 +55,28 @@ Supported options for **address** include
             Note: With this option, addresses are printed only after
             the whole search is finished. This may take long time.
 
+    ``--deduplicate=(no|mailbox|address)``
+
+        Control the deduplication of results.
+
+        **no**
+            Output all occurences of addresses in the matching
+            messages. This is not applicable with --output=count.
+
+        **mailbox**
+           Deduplicate addresses based on the full, case sensitive
+           name and email address, or mailbox. This is effectively
+           the same as piping the --deduplicate=no output to **sort |
+           uniq**, except for the order of results. This is the
+           default.
+
+        **address**
+            Deduplicate addresses based on the case insensitive
+            address part of the mailbox. Of all the variants (with
+            different name or case), print the one occurring most
+            frequently among the matching messages. If --output=count
+            is specified, include all variants in the count.
+
     ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
         This option can be used to present results in either
         chronological order (**oldest-first**) or reverse chronological
@@ -63,7 +85,9 @@ Supported options for **address** include
         By default, results will be displayed in reverse chronological
         order, (that is, the newest results will be displayed first).
 
-        This option is not supported with --output=count.
+        However, if either --output=count or --deduplicate=address is
+        specified, this option is ignored and the order of the results
+        is unspecified.
 
     ``--exclude=(true|false)``
         A message is called "excluded" if it matches at least one tag in
index ca78c18b20555c80a87b720fb3bfe5900d2db05d..99de13a9871245af98f1ca55e8570179e116883e 100644 (file)
@@ -47,6 +47,11 @@ Supported options for **count** include
         (or threads) in the database will be output. This option is not
         compatible with specifying search terms on the command line.
 
+    ``--lastmod``
+       Append lastmod (counter for number of database updates) and UUID
+       to the output. lastmod values are only comparable between databases
+       with the same UUID.
+
     ``--input=``\ <filename>
         Read input from given file, instead of from stdin. Implies
         ``--batch``.
index b33738ed33166699fb3872610634aa2f984e7c74..3acfbdb436db953f3889e98e75f913135ae06858 100644 (file)
@@ -39,15 +39,28 @@ OPTIONS
 
 Supported global options for ``notmuch`` include
 
-    ``--help``
-        Print a synopsis of available commands and exit.
+    ``--help`` [command-name]
+       Print a synopsis of available commands and exit.
+       With an optional command name, show the man page
+       for that subcommand.
 
     ``--version``
-        Print the installed version of notmuch, and exit.
+       Print the installed version of notmuch, and exit.
 
     ``--config=FILE``
-        Specify the configuration file to use. This overrides any
-        configuration file specified by ${NOTMUCH\_CONFIG}.
+       Specify the configuration file to use. This overrides any
+       configuration file specified by ${NOTMUCH\_CONFIG}.
+
+    ``--uuid=HEX``
+       Enforce that the database UUID (a unique identifier which
+       persists until e.g. the database is compacted)
+       is HEX; exit with an error if it is not. This is useful to
+       detect rollover in modification counts on messages. You can
+       find this UUID using e.g. ``notmuch count --lastmod``
+
+All global options except ``--config`` can also be specified after the
+command. For example, ``notmuch subcommand --uuid=HEX`` is
+equivalent to ``notmuch --uuid=HEX subcommand``.
 
 COMMANDS
 ========
index 1d27ac1e6de5ac931c6a349e1355fee57322f7be..11a3da3de135ea96a4e8d6a583476c1601cf1800 100644 (file)
@@ -54,6 +54,8 @@ indicate user-supplied values):
 
 -  date:<since>..<until>
 
+-  lastmod:<since>..<until>
+
 The **from:** prefix is used to match the name or address of the sender
 of an email message.
 
@@ -124,6 +126,12 @@ The time range can also be specified using timestamps with a syntax of:
 Each timestamp is a number representing the number of seconds since
 1970-01-01 00:00:00 UTC.
 
+The **lastmod:** prefix can be used to restrict the result by the
+database revision number of when messages were last modified (tags
+were added/removed or filenames changed).  This is usually used in
+conjunction with the **--uuid** argument to **notmuch search**
+to find messages that have changed since an earlier query.
+
 Operators
 ---------
 
@@ -270,6 +278,13 @@ In this case, <since> is taken as the earliest time it could describe
 could describe (the end of yesterday). Similarly, date:january..february
 matches from the beginning of January to the end of February.
 
+date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The
+expansion takes place before interpretation, and thus, for example,
+date:monday..! matches from the beginning of Monday until the end of
+Monday. (Note that entering date:<expr> without "..", for example
+date:yesterday, won't work, as it's not interpreted as a range
+expression at all. Again, use date:yesterday..!)
+
 Currently, we do not support spaces in range expressions. You can
 replace the spaces with '\_', or (in most cases) '-', or (in some cases)
 leave the spaces out altogether. Examples in this man page use spaces
@@ -280,11 +295,6 @@ to specify date:..<until> or date:<since>.. to not limit the start or
 end time, respectively. Pre-1.2.1 Xapian does not report an error on
 open ended ranges, but it does not work as expected either.
 
-Entering date:expr without ".." (for example date:yesterday) won't work,
-as it's not interpreted as a range expression at all. You can achieve
-the expected result by duplicating the expr both sides of ".." (for
-example date:yesterday..yesterday).
-
 Relative date and time
 ----------------------
 
index 65d062760a71a5f00a940ec945886a87be73c388..7bfa752d2a04d3d3cc0244aac63299979fb9a88e 100644 (file)
@@ -628,7 +628,7 @@ with `notmuch-hello-query-counts'."
 (defun notmuch-hello-versions ()
   "Display the notmuch version(s)"
   (interactive)
-  (let ((notmuch-cli-version (notmuch-version)))
+  (let ((notmuch-cli-version (notmuch-cli-version)))
     (message "notmuch version %s"
             (if (string= notmuch-emacs-version notmuch-cli-version)
                 notmuch-cli-version
index f8e516583dfec6da1ae5fd9fbfa6d6a82377b0af..201d7ec8593f376c1ae9f20a3671eff52535e4bc 100644 (file)
 (require 'mm-decode)
 (require 'cl)
 
+(unless (require 'notmuch-version nil t)
+  (defconst notmuch-emacs-version "unknown"
+    "Placeholder variable when notmuch-version.el[c] is not available."))
+
 (autoload 'notmuch-jump-search "notmuch-jump"
   "Jump to a saved search by shortcut key." t)
 
@@ -192,8 +196,8 @@ Otherwise the output will be returned"
 "Perhaps you haven't run \"notmuch setup\" yet? Try running this
 on the command line, and then retry your notmuch command")))
 
-(defun notmuch-version ()
-  "Return a string with the notmuch version number."
+(defun notmuch-cli-version ()
+  "Return a string with the notmuch cli command version number."
   (let ((long-string
         ;; Trim off the trailing newline.
         (substring (notmuch-command-to-string "--version") 0 -1)))
index 07eedba22a33a28ae802f260781c3fbfdeeca582..c2f2f4cb127db3d9f2c786b8c8236cffe558193e 100644 (file)
@@ -59,23 +59,19 @@ yet when sending a mail."
  :require 'notmuch-fcc-initialization
  :group 'notmuch-send)
 
-(defun notmuch-fcc-initialization ()
-  "If notmuch-fcc-directories is set,
-   hook them into the message-fcc-handler-function"
-    ;; Set up the message-fcc-handler to move mails to the maildir in Fcc
-    ;; The parameter is set to mark messages as "seen"
-    (setq message-fcc-handler-function
-          (lambda (destdir)
-           (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)))
-    ;; add a hook to actually insert the Fcc header when sending
-    (add-hook 'message-header-setup-hook 'notmuch-fcc-header-setup))
+(defun notmuch-fcc-handler (destdir)
+  "Write buffer to `destdir', marking it as sent
+
+Intended to be dynamically bound to `message-fcc-handler-function'"
+    (notmuch-maildir-fcc-write-buffer-to-maildir destdir t))
 
 (defun notmuch-fcc-header-setup ()
   "Add an Fcc header to the current message buffer.
 
-Can be added to `message-send-hook' and will set the Fcc header
-based on the values of `notmuch-fcc-dirs'. An existing Fcc header
-will NOT be removed or replaced."
+Sets the Fcc header based on the values of `notmuch-fcc-dirs'.
+
+Originally intended to be use a hook function, but now called directly
+by notmuch-mua-mail"
 
   (let ((subdir
         (cond
@@ -213,6 +209,5 @@ return t if successful, and nil otherwise."
          (delete-file (concat destdir "/tmp/" msg-id))))
       t)))
 
-(notmuch-fcc-initialization)
 (provide 'notmuch-maildir-fcc)
 
index 33f139987e659135cb2aeb29767144455a26429e..57465b205a60a7875a66fdbd39874ca56f2e376c 100644 (file)
@@ -50,7 +50,7 @@ window/frame that will be destroyed when the buffer is killed.
 You may want to customize `message-kill-buffer-on-exit'
 accordingly."
    (when (< emacs-major-version 24)
-           " Due to a known bug in Emacs 23, you should not set
+          " Due to a known bug in Emacs 23, you should not set
 this to `new-window' if `message-kill-buffer-on-exit' is
 disabled: this would result in an incorrect behavior."))
   :group 'notmuch-send
@@ -118,7 +118,10 @@ Note that these functions use `mail-citation-hook' if that is non-nil."
 
 (defun notmuch-mua-user-agent-notmuch ()
   "Generate a `User-Agent:' string suitable for notmuch."
-  (concat "Notmuch/" (notmuch-version) " (http://notmuchmail.org)"))
+  (let ((notmuch-version (if (string= notmuch-emacs-version "unknown")
+                            (notmuch-cli-version)
+                          notmuch-emacs-version)))
+    (concat "Notmuch/" notmuch-version " (http://notmuchmail.org)")))
 
 (defun notmuch-mua-user-agent-emacs ()
   "Generate a `User-Agent:' string suitable for notmuch."
@@ -265,6 +268,12 @@ Note that these functions use `mail-citation-hook' if that is non-nil."
   (message-goto-body)
   (set-buffer-modified-p nil))
 
+(define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
+  "Notmuch message composition mode. Mostly like `message-mode'")
+
+(define-key notmuch-message-mode-map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)
+(define-key notmuch-message-mode-map (kbd "C-c C-s") #'notmuch-mua-send)
+
 (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args)
   "Invoke the notmuch mail composition window.
 
@@ -281,6 +290,8 @@ OTHER-ARGS are passed through to `message-mail'."
                       (notmuch-user-name) " <" (notmuch-user-primary-email) ">")) other-headers))
 
   (apply #'message-mail to subject other-headers other-args)
+  (notmuch-message-mode)
+  (notmuch-fcc-header-setup)
   (message-sort-headers)
   (message-hide-headers)
   (set-buffer-modified-p nil)
@@ -394,7 +405,13 @@ will be addressed to all recipients of the source message."
 
 (defun notmuch-mua-send-and-exit (&optional arg)
   (interactive "P")
-  (message-send-and-exit arg))
+  (let ((message-fcc-handler-function #'notmuch-fcc-handler))
+    (message-send-and-exit arg)))
+
+(defun notmuch-mua-send (&optional arg)
+  (interactive "P")
+  (let ((message-fcc-handler-function #'notmuch-fcc-handler))
+    (message-send arg)))
 
 (defun notmuch-mua-kill-buffer ()
   (interactive)
index 2a53461ee64290c2f25f2faee5b4f456003d735e..4dee34bfd9cfb2d6b1ad876884142d48427e1f26 100644 (file)
@@ -47,6 +47,7 @@
 (declare-function notmuch-tree "notmuch-tree"
                  (&optional query query-context target buffer-name open-target))
 (declare-function notmuch-tree-get-message-properties "notmuch-tree" nil)
+(declare-function notmuch-read-query "notmuch" (prompt))
 
 (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
   "Headers that should be shown in a message, in this order.
@@ -1281,6 +1282,16 @@ This includes:
              ")")
     notmuch-show-thread-id))
 
+(defun notmuch-show-goto-message (msg-id)
+  "Go to message with msg-id."
+  (goto-char (point-min))
+  (unless (loop if (string= msg-id (notmuch-show-get-message-id))
+               return t
+               until (not (notmuch-show-goto-message-next)))
+    (goto-char (point-min))
+    (message "Message-id not found."))
+  (notmuch-show-message-adjust))
+
 (defun notmuch-show-apply-state (state)
   "Apply STATE to the current buffer.
 
@@ -1298,13 +1309,7 @@ This includes:
          until (not (notmuch-show-goto-message-next)))
 
     ;; Go to the previously open message.
-    (goto-char (point-min))
-    (unless (loop if (string= current (notmuch-show-get-message-id))
-                 return t
-                 until (not (notmuch-show-goto-message-next)))
-      (goto-char (point-min))
-      (message "Previously current message not found."))
-    (notmuch-show-message-adjust)))
+    (notmuch-show-goto-message current)))
 
 (defun notmuch-show-refresh-view (&optional reset-state)
   "Refresh the current view.
@@ -1368,6 +1373,7 @@ reset based on the original query."
     (define-key map (kbd "<backtab>") 'notmuch-show-previous-button)
     (define-key map (kbd "TAB") 'notmuch-show-next-button)
     (define-key map "f" 'notmuch-show-forward-message)
+    (define-key map "l" 'notmuch-show-filter-thread)
     (define-key map "r" 'notmuch-show-reply-sender)
     (define-key map "R" 'notmuch-show-reply)
     (define-key map "|" 'notmuch-show-pipe-message)
@@ -1656,6 +1662,16 @@ user decision and we should not override it."
     (save-excursion
       (funcall notmuch-show-mark-read-function (window-start) (window-end)))))
 
+(defun notmuch-show-filter-thread (query)
+  "Filter or LIMIT the current thread based on a new query string.
+
+Reshows the current thread with matches defined by the new query-string."
+  (interactive (list (notmuch-read-query "Filter thread: ")))
+  (let ((msg-id (notmuch-show-get-message-id)))
+    (setq notmuch-show-query-context (if (string= query "") nil query))
+    (notmuch-show-refresh-view t)
+    (notmuch-show-goto-message msg-id)))
+
 ;; Functions for getting attributes of several messages in the current
 ;; thread.
 
index f54aa9d69ef8d440a2e81756fd570ab32a96a2d8..c7f62c90974995caf64aea212e0a5eae9fa97b5e 100644 (file)
@@ -265,7 +265,7 @@ changed (the normal case) are shown using formats from
 (defcustom notmuch-before-tag-hook nil
   "Hooks that are run before tags of a message are modified.
 
-'tags' will contain the tags that are about to be added or removed as
+'tag-changes' will contain the tags that are about to be added or removed as
 a list of strings of the form \"+TAG\" or \"-TAG\".
 'query' will be a string containing the search query that determines
 the messages that are about to be tagged"
@@ -277,7 +277,7 @@ the messages that are about to be tagged"
 (defcustom notmuch-after-tag-hook nil
   "Hooks that are run after tags of a message are modified.
 
-'tags' will contain the tags that were added or removed as
+'tag-changes' will contain the tags that were added or removed as
 a list of strings of the form \"+TAG\" or \"-TAG\".
 'query' will be a string containing the search query that determines
 the messages that were tagged"
index ab00454357ef12f26b2f92b9705f30093d753a1f..463b9262212ecad69b7cff10420359b3c071888d 100644 (file)
 (require 'notmuch-message)
 (require 'notmuch-parser)
 
-(unless (require 'notmuch-version nil t)
-  (defconst notmuch-emacs-version "unknown"
-    "Placeholder variable when notmuch-version.el[c] is not available."))
-
 (defcustom notmuch-search-result-format
   `(("date" . "%12s ")
     ("count" . "%-7s ")
@@ -181,6 +177,7 @@ there will be called at other points of notmuch execution."
 (defvar notmuch-search-stash-map
   (let ((map (make-sparse-keymap)))
     (define-key map "i" 'notmuch-search-stash-thread-id)
+    (define-key map "q" 'notmuch-stash-query)
     (define-key map "?" 'notmuch-subkeymap-help)
     map)
   "Submap for stash commands")
@@ -191,6 +188,11 @@ there will be called at other points of notmuch execution."
   (interactive)
   (notmuch-common-do-stash (notmuch-search-find-thread-id)))
 
+(defun notmuch-stash-query ()
+  "Copy current query to kill-ring."
+  (interactive)
+  (notmuch-common-do-stash (notmuch-search-get-query)))
+
 (defvar notmuch-search-query-string)
 (defvar notmuch-search-target-thread)
 (defvar notmuch-search-target-line)
@@ -855,13 +857,15 @@ See `notmuch-tag' for information on the format of TAG-CHANGES."
   "Read a notmuch-query from the minibuffer with completion.
 
 PROMPT is the string to prompt with."
-  (lexical-let
-      ((completions
-       (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
-                     "subject:" "attachment:" "mimetype:")
-               (mapcar (lambda (tag)
-                         (concat "tag:" (notmuch-escape-boolean-term tag)))
-                       (process-lines notmuch-command "search" "--output=tags" "*")))))
+  (lexical-let*
+      ((all-tags
+        (mapcar (lambda (tag) (notmuch-escape-boolean-term tag))
+                (process-lines notmuch-command "search" "--output=tags" "*")))
+       (completions
+        (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
+                      "subject:" "attachment:" "mimetype:")
+                (mapcar (lambda (tag) (concat "tag:" tag)) all-tags)
+                (mapcar (lambda (tag) (concat "is:" tag)) all-tags))))
     (let ((keymap (copy-keymap minibuffer-local-map))
          (current-query (case major-mode
                           (notmuch-search-mode (notmuch-search-get-query))
@@ -974,18 +978,28 @@ default sort order is defined by `notmuch-search-oldest-first'."
   (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first))
   (notmuch-search-refresh-view))
 
+(defun notmuch-group-disjunctive-query-string (query-string)
+  "Group query if it contains a complex expression.
+
+Enclose QUERY-STRING in parentheses if it matches
+`notmuch-search-disjunctive-regexp'."
+  (if (string-match-p notmuch-search-disjunctive-regexp query-string)
+      (concat "( " query-string " )")
+    query-string))
+
 (defun notmuch-search-filter (query)
   "Filter the current search results based on an additional query string.
 
 Runs a new search matching only messages that match both the
 current search results AND the additional query string provided."
   (interactive (list (notmuch-read-query "Filter search: ")))
-  (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query)
-                          (concat "( " query " )")
-                        query)))
-    (notmuch-search (if (string= notmuch-search-query-string "*")
+  (let ((grouped-query (notmuch-group-disjunctive-query-string query))
+       (grouped-original-query (notmuch-group-disjunctive-query-string
+                                notmuch-search-query-string)))
+    (notmuch-search (if (string= grouped-original-query "*")
                        grouped-query
-                     (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first)))
+                     (concat grouped-original-query " and " grouped-query))
+                   notmuch-search-oldest-first)))
 
 (defun notmuch-search-filter-by-tag (tag)
   "Filter the current search results based on a single tag.
index f9ecd50e7366f6afed8e5cd132e4ea83185d33cd..3a070907271eb263627562087acac78f09e173bc 100644 (file)
@@ -1,26 +1,5 @@
 # -*- makefile -*-
 
-# The major version of the library interface. This will control the soname.
-# As such, this number must be incremented for any incompatible change to
-# the library interface, (such as the deletion of an API or a major
-# semantic change that breaks formerly functioning code).
-#
-LIBNOTMUCH_VERSION_MAJOR = 4
-
-# The minor version of the library interface. This should be incremented at
-# the time of release for any additions to the library interface,
-# (and when it is incremented, the release version of the library should
-#  be reset to 0).
-LIBNOTMUCH_VERSION_MINOR = 2
-
-# The release version the library interface. This should be incremented at
-# the time of release if there have been no changes to the interface, (but
-# simply compatible changes to the implementation).
-LIBNOTMUCH_VERSION_RELEASE = 0
-
-# Note: Don't forget to change the VERSION macros in notmuch.h when
-# any of the above change.
-
 ifeq ($(PLATFORM),MACOSX)
 LIBRARY_SUFFIX = dylib
 # On OS X, library version numbers go before suffix.
@@ -33,7 +12,7 @@ LIBRARY_SUFFIX = so
 LINKER_NAME = libnotmuch.$(LIBRARY_SUFFIX)
 SONAME = $(LINKER_NAME).$(LIBNOTMUCH_VERSION_MAJOR)
 LIBNAME = $(SONAME).$(LIBNOTMUCH_VERSION_MINOR).$(LIBNOTMUCH_VERSION_RELEASE)
-LIBRARY_LINK_FLAG = -shared -Wl,--version-script=notmuch.sym,-soname=$(SONAME) -Wl,--no-undefined
+LIBRARY_LINK_FLAG = -shared -Wl,--version-script=notmuch.sym,-soname=$(SONAME) $(NO_UNDEFINED_LDFLAGS)
 ifeq ($(PLATFORM),OPENBSD)
 LIBRARY_LINK_FLAG += -lc
 endif
index 24243db2e4fd38577a3aae8840003cbfef3ec637..3fb10f7a408415fc7b22a1ce7cf34fa72cbba5b7 100644 (file)
@@ -100,6 +100,12 @@ enum _notmuch_features {
      *
      * Introduced: version 3. */
     NOTMUCH_FEATURE_INDEXED_MIMETYPES = 1 << 5,
+
+    /* If set, messages store the revision number of the last
+     * modification in NOTMUCH_VALUE_LAST_MOD.
+     *
+     * Introduced: version 3. */
+    NOTMUCH_FEATURE_LAST_MOD = 1 << 6,
 };
 
 /* In C++, a named enum is its own type, so define bitwise operators
@@ -145,6 +151,8 @@ struct _notmuch_database {
 
     notmuch_database_mode_t mode;
     int atomic_nesting;
+    /* TRUE if changes have been made in this atomic section */
+    notmuch_bool_t atomic_dirty;
     Xapian::Database *xapian_db;
 
     /* Bit mask of features used by this database.  This is a
@@ -158,10 +166,17 @@ struct _notmuch_database {
      * next library call. May be NULL */
     char *status_string;
 
+    /* Highest committed revision number.  Modifications are recorded
+     * under a higher revision number, which can be generated with
+     * notmuch_database_new_revision. */
+    unsigned long revision;
+    const char *uuid;
+
     Xapian::QueryParser *query_parser;
     Xapian::TermGenerator *term_gen;
     Xapian::ValueRangeProcessor *value_range_processor;
     Xapian::ValueRangeProcessor *date_range_processor;
+    Xapian::ValueRangeProcessor *last_mod_range_processor;
 };
 
 /* Prior to database version 3, features were implied by the database
@@ -179,7 +194,8 @@ struct _notmuch_database {
  * will have it). */
 #define NOTMUCH_FEATURES_CURRENT \
     (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_DIRECTORY_DOCS | \
-     NOTMUCH_FEATURE_BOOL_FOLDER | NOTMUCH_FEATURE_GHOSTS)
+     NOTMUCH_FEATURE_BOOL_FOLDER | NOTMUCH_FEATURE_GHOSTS | \
+     NOTMUCH_FEATURE_LAST_MOD)
 
 /* Return the list of terms from the given iterator matching a prefix.
  * The prefix will be stripped from the strings in the returned list.
index cffab62c895b3dd318855ae27445ad55488de97b..6d0e5a63fd81c6b4163860e84b1e6af8258394bb 100644 (file)
@@ -101,6 +101,9 @@ typedef struct {
  *
  *     SUBJECT:        The value of the "Subject" header
  *
+ *     LAST_MOD:       The revision number as of the last tag or
+ *                     filename change.
+ *
  * In addition, terms from the content of the message are added with
  * "from", "to", "attachment", and "subject" prefixes for use by the
  * user in searching. Similarly, terms from the path of the mail
@@ -310,6 +313,8 @@ static const struct {
      * them. */
     { NOTMUCH_FEATURE_INDEXED_MIMETYPES,
       "indexed MIME types", "w"},
+    { NOTMUCH_FEATURE_LAST_MOD,
+      "modification tracking", "w"},
 };
 
 const char *
@@ -342,6 +347,8 @@ notmuch_status_to_string (notmuch_status_t status)
        return "Unsupported operation";
     case NOTMUCH_STATUS_UPGRADE_REQUIRED:
        return "Operation requires a database upgrade";
+    case NOTMUCH_STATUS_PATH_ERROR:
+       return "Path supplied is illegal for this function";
     default:
     case NOTMUCH_STATUS_LAST_STATUS:
        return "Unknown error status value";
@@ -657,6 +664,12 @@ notmuch_database_create_verbose (const char *path,
        goto DONE;
     }
 
+    if (path[0] != '/') {
+       message = strdup ("Error: Database path must be absolute.\n");
+       status = NOTMUCH_STATUS_PATH_ERROR;
+       goto DONE;
+    }
+
     err = stat (path, &st);
     if (err) {
        IGNORE_RESULT (asprintf (&message, "Error: Cannot create database at %s: %s.\n",
@@ -729,6 +742,23 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
     return NOTMUCH_STATUS_SUCCESS;
 }
 
+/* Allocate a revision number for the next change. */
+unsigned long
+_notmuch_database_new_revision (notmuch_database_t *notmuch)
+{
+    unsigned long new_revision = notmuch->revision + 1;
+
+    /* If we're in an atomic section, hold off on updating the
+     * committed revision number until we commit the atomic section.
+     */
+    if (notmuch->atomic_nesting)
+       notmuch->atomic_dirty = TRUE;
+    else
+       notmuch->revision = new_revision;
+
+    return new_revision;
+}
+
 /* Parse a database features string from the given database version.
  * Returns the feature bit set.
  *
@@ -847,6 +877,12 @@ notmuch_database_open_verbose (const char *path,
        goto DONE;
     }
 
+    if (path[0] != '/') {
+       message = strdup ("Error: Database path must be absolute.\n");
+       status = NOTMUCH_STATUS_PATH_ERROR;
+       goto DONE;
+    }
+
     if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {
        message = strdup ("Out of memory\n");
        status = NOTMUCH_STATUS_OUT_OF_MEMORY;
@@ -890,6 +926,7 @@ notmuch_database_open_verbose (const char *path,
     notmuch->atomic_nesting = 0;
     try {
        string last_thread_id;
+       string last_mod;
 
        if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {
            notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,
@@ -948,11 +985,22 @@ notmuch_database_open_verbose (const char *path,
                INTERNAL_ERROR ("Malformed database last_thread_id: %s", str);
        }
 
+       /* Get current highest revision number. */
+       last_mod = notmuch->xapian_db->get_value_upper_bound (
+           NOTMUCH_VALUE_LAST_MOD);
+       if (last_mod.empty ())
+           notmuch->revision = 0;
+       else
+           notmuch->revision = Xapian::sortable_unserialise (last_mod);
+       notmuch->uuid = talloc_strdup (
+           notmuch, notmuch->xapian_db->get_uuid ().c_str ());
+
        notmuch->query_parser = new Xapian::QueryParser;
        notmuch->term_gen = new Xapian::TermGenerator;
        notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));
        notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
        notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
+       notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:");
 
        notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
        notmuch->query_parser->set_database (*notmuch->xapian_db);
@@ -960,6 +1008,7 @@ notmuch_database_open_verbose (const char *path,
        notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);
        notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);
        notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor);
+       notmuch->query_parser->add_valuerangeprocessor (notmuch->last_mod_range_processor);
 
        for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
            prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
@@ -1038,6 +1087,8 @@ notmuch_database_close (notmuch_database_t *notmuch)
     notmuch->value_range_processor = NULL;
     delete notmuch->date_range_processor;
     notmuch->date_range_processor = NULL;
+    delete notmuch->last_mod_range_processor;
+    notmuch->last_mod_range_processor = NULL;
 
     return status;
 }
@@ -1336,7 +1387,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
        return NOTMUCH_STATUS_SUCCESS;
 
     if (progress_notify) {
-       /* Setup our handler for SIGALRM */
+       /* Set up our handler for SIGALRM */
        memset (&action, 0, sizeof (struct sigaction));
        action.sa_handler = handle_sigalrm;
        sigemptyset (&action.sa_mask);
@@ -1355,7 +1406,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
 
     /* Figure out how much total work we need to do. */
     if (new_features &
-       (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {
+       (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
+        NOTMUCH_FEATURE_LAST_MOD)) {
        notmuch_query_t *query = notmuch_query_create (notmuch, "");
        total += notmuch_query_count_messages (query);
        notmuch_query_destroy (query);
@@ -1382,12 +1434,15 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
 
     /* Perform per-message upgrades. */
     if (new_features &
-       (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {
+       (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
+        NOTMUCH_FEATURE_LAST_MOD)) {
        notmuch_query_t *query = notmuch_query_create (notmuch, "");
        notmuch_messages_t *messages;
        notmuch_message_t *message;
        char *filename;
 
+       /* XXX: this should use the _st version, but needs an error
+          path */
        for (messages = notmuch_query_search_messages (query);
             notmuch_messages_valid (messages);
             notmuch_messages_move_to_next (messages))
@@ -1419,6 +1474,14 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
            if (new_features & NOTMUCH_FEATURE_BOOL_FOLDER)
                _notmuch_message_upgrade_folder (message);
 
+           /* Prior to NOTMUCH_FEATURE_LAST_MOD, messages did not
+            * track modification revisions.  Give all messages the
+            * next available revision; since we just started tracking
+            * revisions for this database, that will be 1.
+            */
+           if (new_features & NOTMUCH_FEATURE_LAST_MOD)
+               _notmuch_message_upgrade_last_mod (message);
+
            _notmuch_message_sync (message);
 
            notmuch_message_destroy (message);
@@ -1601,11 +1664,25 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch)
        return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
     }
 
+    if (notmuch->atomic_dirty) {
+       ++notmuch->revision;
+       notmuch->atomic_dirty = FALSE;
+    }
+
 DONE:
     notmuch->atomic_nesting--;
     return NOTMUCH_STATUS_SUCCESS;
 }
 
+unsigned long
+notmuch_database_get_revision (notmuch_database_t *notmuch,
+                               const char **uuid)
+{
+    if (uuid)
+       *uuid = notmuch->uuid;
+    return notmuch->revision;
+}
+
 /* We allow the user to use arbitrarily long paths for directories. But
  * we have a term-length limit. So if we exceed that, we'll use the
  * SHA-1 of the path for the database term.
@@ -2576,7 +2653,7 @@ notmuch_database_get_all_tags (notmuch_database_t *db)
 }
 
 const char *
-notmuch_database_status_string (notmuch_database_t *notmuch)
+notmuch_database_status_string (const notmuch_database_t *notmuch)
 {
     return notmuch->status_string;
 }
index 64a737494e1cae2c3f3da8b7fc29902236e54372..847700114ef8df1f634db307dd22423c655c90e8 100644 (file)
@@ -1,3 +1,4 @@
+set -eu
 
 # we go through a bit of work to get the unmangled names of the
 # typeinfo symbols because of
index 8ac96e8e06a5dd9a132f241469690c773777fdb4..ee305202fffa63f0e1a1d024c738a1d69a39ebb4 100644 (file)
@@ -37,27 +37,6 @@ struct _notmuch_message_file {
     GMimeMessage *message;
 };
 
-static int
-strcase_equal (const void *a, const void *b)
-{
-    return strcasecmp (a, b) == 0;
-}
-
-static unsigned int
-strcase_hash (const void *ptr)
-{
-    const char *s = ptr;
-
-    /* This is the djb2 hash. */
-    unsigned int hash = 5381;
-    while (s && *s) {
-       hash = ((hash << 5) + hash) + tolower (*s);
-       s++;
-    }
-
-    return hash;
-}
-
 static int
 _notmuch_message_file_destructor (notmuch_message_file_t *message)
 {
index 5bc7aff1386a4a7e09a461f98f7e37f86e5a3f58..26b5e76e9636b67e43ca5c42c08210f73c70f0c2 100644 (file)
@@ -43,6 +43,9 @@ struct visible _notmuch_message {
      * if each flag has been initialized. */
     unsigned long lazy_flags;
 
+    /* Message document modified since last sync */
+    notmuch_bool_t modified;
+
     Xapian::Document doc;
     Xapian::termcount termpos;
 };
@@ -539,6 +542,7 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)
 
        try {
            message->doc.remove_term ((*i));
+           message->modified = TRUE;
        } catch (const Xapian::InvalidArgumentError) {
            /* Ignore failure to remove non-existent term. */
        }
@@ -793,6 +797,7 @@ void
 _notmuch_message_clear_data (notmuch_message_t *message)
 {
     message->doc.set_data ("");
+    message->modified = TRUE;
 }
 
 static void
@@ -990,6 +995,17 @@ _notmuch_message_set_header_values (notmuch_message_t *message,
                            Xapian::sortable_serialise (time_value));
     message->doc.add_value (NOTMUCH_VALUE_FROM, from);
     message->doc.add_value (NOTMUCH_VALUE_SUBJECT, subject);
+    message->modified = TRUE;
+}
+
+/* Upgrade a message to support NOTMUCH_FEATURE_LAST_MOD.  The caller
+ * must call _notmuch_message_sync. */
+void
+_notmuch_message_upgrade_last_mod (notmuch_message_t *message)
+{
+    /* _notmuch_message_sync will update the last modification
+     * revision; we just have to ask it to. */
+    message->modified = TRUE;
 }
 
 /* Synchronize changes made to message->doc out into the database. */
@@ -1001,8 +1017,24 @@ _notmuch_message_sync (notmuch_message_t *message)
     if (message->notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
        return;
 
+    if (! message->modified)
+       return;
+
+    /* Update the last modification of this message. */
+    if (message->notmuch->features & NOTMUCH_FEATURE_LAST_MOD)
+       /* sortable_serialise gives a reasonably compact encoding,
+        * which directly translates to reduced IO when scanning the
+        * value stream.  Since it's built for doubles, we only get 53
+        * effective bits, but that's still enough for the database to
+        * last a few centuries at 1 million revisions per second. */
+       message->doc.add_value (NOTMUCH_VALUE_LAST_MOD,
+                               Xapian::sortable_serialise (
+                                   _notmuch_database_new_revision (
+                                       message->notmuch)));
+
     db = static_cast <Xapian::WritableDatabase *> (message->notmuch->xapian_db);
     db->replace_document (message->doc_id, message->doc);
+    message->modified = FALSE;
 }
 
 /* Delete a message document from the database. */
@@ -1077,6 +1109,7 @@ _notmuch_message_add_term (notmuch_message_t *message,
        return NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG;
 
     message->doc.add_term (term, 0);
+    message->modified = TRUE;
 
     talloc_free (term);
 
@@ -1145,6 +1178,7 @@ _notmuch_message_remove_term (notmuch_message_t *message,
 
     try {
        message->doc.remove_term (term);
+       message->modified = TRUE;
     } catch (const Xapian::InvalidArgumentError) {
        /* We'll let the philosopher's try to wrestle with the
         * question of whether failing to remove that which was not
index cc9ce12ce69d664f708e96d93767355ecc1b4ff2..5dd4770e96190276c3e5077d977cb200aa6f6b82 100644 (file)
@@ -50,6 +50,7 @@ NOTMUCH_BEGIN_DECLS
 
 #include "xutil.h"
 #include "error_util.h"
+#include "string-util.h"
 
 #pragma GCC visibility push(hidden)
 
@@ -107,7 +108,8 @@ typedef enum {
     NOTMUCH_VALUE_TIMESTAMP = 0,
     NOTMUCH_VALUE_MESSAGE_ID,
     NOTMUCH_VALUE_FROM,
-    NOTMUCH_VALUE_SUBJECT
+    NOTMUCH_VALUE_SUBJECT,
+    NOTMUCH_VALUE_LAST_MOD,
 } notmuch_value_t;
 
 /* Xapian (with flint backend) complains if we provide a term longer
@@ -194,6 +196,9 @@ void
 _notmuch_database_log (notmuch_database_t *notmuch,
                       const char *format, ...);
 
+unsigned long
+_notmuch_database_new_revision (notmuch_database_t *notmuch);
+
 const char *
 _notmuch_database_relative_path (notmuch_database_t *notmuch,
                                 const char *path);
@@ -305,6 +310,10 @@ _notmuch_message_set_header_values (notmuch_message_t *message,
                                    const char *date,
                                    const char *from,
                                    const char *subject);
+
+void
+_notmuch_message_upgrade_last_mod (notmuch_message_t *message);
+
 void
 _notmuch_message_sync (notmuch_message_t *message);
 
index 20c4e0190c5cdc2f9e5d5464e9ab67192d424534..87756838d0727f77836e419a2e7f9d5384bb1033 100644 (file)
@@ -56,9 +56,11 @@ NOTMUCH_BEGIN_DECLS
  * version in Makefile.local.
  */
 #define LIBNOTMUCH_MAJOR_VERSION       4
-#define LIBNOTMUCH_MINOR_VERSION       2
+#define LIBNOTMUCH_MINOR_VERSION       3
 #define LIBNOTMUCH_MICRO_VERSION       0
 
+#define NOTMUCH_DEPRECATED(major,minor) \
+    __attribute__ ((deprecated ("function deprecated as of libnotmuch " #major "." #minor)))
 #endif /* __DOXYGEN__ */
 
 /**
@@ -163,6 +165,11 @@ typedef enum _notmuch_status {
      * The operation requires a database upgrade.
      */
     NOTMUCH_STATUS_UPGRADE_REQUIRED,
+    /**
+     * There is a problem with the proposed path, e.g. a relative path
+     * passed to a function expecting an absolute path.
+     */
+    NOTMUCH_STATUS_PATH_ERROR,
     /**
      * Not an actual status value. Just a way to find out how many
      * valid status values there are.
@@ -306,7 +313,7 @@ notmuch_database_open_verbose (const char *path,
  *
  */
 const char *
-notmuch_database_status_string (notmuch_database_t *notmuch);
+notmuch_database_status_string (const notmuch_database_t *notmuch);
 
 /**
  * Commit changes and close the given notmuch database.
@@ -460,6 +467,24 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch);
 notmuch_status_t
 notmuch_database_end_atomic (notmuch_database_t *notmuch);
 
+/**
+ * Return the committed database revision and UUID.
+ *
+ * The database revision number increases monotonically with each
+ * commit to the database.  Hence, all messages and message changes
+ * committed to the database (that is, visible to readers) have a last
+ * modification revision <= the committed database revision.  Any
+ * messages committed in the future will be assigned a modification
+ * revision > the committed database revision.
+ *
+ * The UUID is a NUL-terminated opaque string that uniquely identifies
+ * this database.  Two revision numbers are only comparable if they
+ * have the same database UUID.
+ */
+unsigned long
+notmuch_database_get_revision (notmuch_database_t *notmuch,
+                               const char **uuid);
+
 /**
  * Retrieve a directory object from the database for 'path'.
  *
@@ -703,7 +728,13 @@ typedef enum {
  * Return the query_string of this query. See notmuch_query_create.
  */
 const char *
-notmuch_query_get_query_string (notmuch_query_t *query);
+notmuch_query_get_query_string (const notmuch_query_t *query);
+
+/**
+ * Return the notmuch database of this query. See notmuch_query_create.
+ */
+notmuch_database_t *
+notmuch_query_get_database (const notmuch_query_t *query);
 
 /**
  * Exclude values for notmuch_query_set_omit_excluded. The strange
@@ -760,7 +791,7 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
  * notmuch_query_set_sort.
  */
 notmuch_sort_t
-notmuch_query_get_sort (notmuch_query_t *query);
+notmuch_query_get_sort (const notmuch_query_t *query);
 
 /**
  * Add a tag that will be excluded from the query results by default.
@@ -807,19 +838,24 @@ notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);
  * notmuch_threads_destroy function, but there's no good reason
  * to call it if the query is about to be destroyed).
  *
- * If a Xapian exception occurs this function will return NULL.
- * For better error reporting, use the _st variant.
- */
-notmuch_threads_t *
-notmuch_query_search_threads (notmuch_query_t *query);
-
-/**
- * Like notmuch_query_search_threads, but with a status return.
  */
 notmuch_status_t
 notmuch_query_search_threads_st (notmuch_query_t *query,
                                 notmuch_threads_t **out);
 
+/**
+ * Like notmuch_query_search_threads_st, but without a status return.
+ *
+ * If a Xapian exception occurs this function will return NULL.
+ *
+ * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please
+ * use notmuch_query_search_threads_st instead.
+ *
+ */
+NOTMUCH_DEPRECATED(4,3)
+notmuch_threads_t *
+notmuch_query_search_threads (notmuch_query_t *query);
+
 /**
  * Execute a query for messages, returning a notmuch_messages_t object
  * which can be used to iterate over the results. The returned
@@ -858,17 +894,23 @@ notmuch_query_search_threads_st (notmuch_query_t *query,
  * reason to call it if the query is about to be destroyed).
  *
  * If a Xapian exception occurs this function will return NULL.
- * For better error reporting, use the _st variant.
- */
-notmuch_messages_t *
-notmuch_query_search_messages (notmuch_query_t *query);
-
-/**
- * Like notmuch_query_search_messages, but with a status return.
+ *
  */
 notmuch_status_t
 notmuch_query_search_messages_st (notmuch_query_t *query,
                                  notmuch_messages_t **out);
+/**
+ * Like notmuch_query_search_messages, but without a status return.
+ *
+ * If a Xapian exception occurs this function will return NULL.
+ *
+ * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please use
+ * notmuch_query_search_messages_st instead.
+ *
+ */
+NOTMUCH_DEPRECATED(4,3)
+notmuch_messages_t *
+notmuch_query_search_messages (notmuch_query_t *query);
 
 /**
  * Destroy a notmuch_query_t along with any associated resources.
index 33f07db3410e5762dcf9329ff4510a5783a95318..03804cf50fa83e77a816ac040ca15992c1fb5db8 100644 (file)
@@ -31,6 +31,7 @@ Xapian::valueno
 ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)
 {
     time_t t, now;
+    std::string b;
 
     /* Require date: prefix in start of the range... */
     if (STRNCMP_LITERAL (begin.c_str (), PREFIX))
@@ -38,6 +39,7 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)
 
     /* ...and remove it. */
     begin.erase (0, sizeof (PREFIX) - 1);
+    b = begin;
 
     /* Use the same 'now' for begin and end. */
     if (time (&now) == (time_t) -1)
@@ -51,6 +53,9 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)
     }
 
     if (!end.empty ()) {
+       if (end == "!" && ! b.empty ())
+           end = b;
+
        if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))
            return Xapian::BAD_VALUENO;
 
index 9cedb6a8440ae907ac83f9d0b2ac98e8a9f5c9aa..8cf0a077e5e74e54267d0470a25b51fa9e84475d 100644 (file)
@@ -98,7 +98,7 @@ notmuch_query_create (notmuch_database_t *notmuch,
 }
 
 const char *
-notmuch_query_get_query_string (notmuch_query_t *query)
+notmuch_query_get_query_string (const notmuch_query_t *query)
 {
     return query->query_string;
 }
@@ -117,7 +117,7 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)
 }
 
 notmuch_sort_t
-notmuch_query_get_sort (notmuch_query_t *query)
+notmuch_query_get_sort (const notmuch_query_t *query)
 {
     return query->sort;
 }
@@ -618,10 +618,14 @@ notmuch_query_count_threads (notmuch_query_t *query)
     GHashTable *hash;
     unsigned int count;
     notmuch_sort_t sort;
+    notmuch_status_t status;
 
     sort = query->sort;
     query->sort = NOTMUCH_SORT_UNSORTED;
-    messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (status)
+       return 0;
+
     query->sort = sort;
     if (messages == NULL)
        return 0;
@@ -654,3 +658,9 @@ notmuch_query_count_threads (notmuch_query_t *query)
 
     return count;
 }
+
+notmuch_database_t *
+notmuch_query_get_database (const notmuch_query_t *query)
+{
+    return query->notmuch;
+}
index 9847cf8bfc868d6b63e24a8ff56eb2943e997d36..c8e58c336e46e6dcfc45a15bf78b7182643cb421 100644 (file)
@@ -504,6 +504,8 @@ _notmuch_thread_create (void *ctx,
      * oldest or newest subject is desired. */
     notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_OLDEST_FIRST);
 
+    /* XXX: this should use the _st version, but it needs an error path
+     */
     for (messages = notmuch_query_search_messages (thread_id_query);
         notmuch_messages_valid (messages);
         notmuch_messages_move_to_next (messages))
index fd9e4a45e573fa504d331cd7f2636711f8a7d15b..e96e6639716aa017b1b36476900354d51563917b 100644 (file)
@@ -129,8 +129,6 @@ DONE:
     return status;
 }
 
-#ifdef GMIME_ATLEAST_26
-
 /* Signature list destructor (GMime 2.6) */
 static int
 _signature_list_free (GMimeSignatureList **proxy)
@@ -205,87 +203,6 @@ node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
        g_error_free (err);
 }
 
-#else /* GMIME_ATLEAST_26 */
-
-/* Signature validity destructor (GMime 2.4) */
-static int
-_signature_validity_free (GMimeSignatureValidity **proxy)
-{
-    g_mime_signature_validity_free (*proxy);
-    return 0;
-}
-
-/* Set up signature validity destructor (GMime 2.4) */
-static void
-set_signature_validity_destructor (mime_node_t *node,
-                                  GMimeSignatureValidity *sig_validity)
-{
-    GMimeSignatureValidity **proxy = talloc (node, GMimeSignatureValidity *);
-    if (proxy) {
-       *proxy = sig_validity;
-       talloc_set_destructor (proxy, _signature_validity_free);
-    }
-}
-
-/* Verify a signed mime node (GMime 2.4) */
-static void
-node_verify (mime_node_t *node, GMimeObject *part,
-            notmuch_crypto_context_t *cryptoctx)
-{
-    GError *err = NULL;
-    GMimeSignatureValidity *sig_validity;
-
-    node->verify_attempted = TRUE;
-    sig_validity = g_mime_multipart_signed_verify
-       (GMIME_MULTIPART_SIGNED (part), cryptoctx, &err);
-    node->sig_validity = sig_validity;
-    if (sig_validity) {
-       set_signature_validity_destructor (node, sig_validity);
-    } else {
-       fprintf (stderr, "Failed to verify signed part: %s\n",
-                err ? err->message : "no error explanation given");
-    }
-
-    if (err)
-       g_error_free (err);
-}
-
-/* Decrypt and optionally verify an encrypted mime node (GMime 2.4) */
-static void
-node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
-                        notmuch_crypto_context_t *cryptoctx)
-{
-    GError *err = NULL;
-    GMimeMultipartEncrypted *encrypteddata = GMIME_MULTIPART_ENCRYPTED (part);
-
-    node->decrypt_attempted = TRUE;
-    node->decrypted_child = g_mime_multipart_encrypted_decrypt
-       (encrypteddata, cryptoctx, &err);
-    if (! node->decrypted_child) {
-       fprintf (stderr, "Failed to decrypt part: %s\n",
-                err ? err->message : "no error explanation given");
-       goto DONE;
-    }
-
-    node->decrypt_success = TRUE;
-    node->verify_attempted = TRUE;
-
-    /* The GMimeSignatureValidity returned here is a const, unlike the
-     * one returned by g_mime_multipart_signed_verify() in
-     * node_verify() above, so the destructor is not needed.
-     */
-    node->sig_validity = g_mime_multipart_encrypted_get_signature_validity (encrypteddata);
-    if (! node->sig_validity)
-       fprintf (stderr, "Failed to verify encrypted signed part: %s\n",
-                err ? err->message : "no error explanation given");
-
- DONE:
-    if (err)
-       g_error_free (err);
-}
-
-#endif  /* GMIME_ATLEAST_26 */
-
 static mime_node_t *
 _mime_node_create (mime_node_t *parent, GMimeObject *part)
 {
index fb3021cc37c1aec68a9b2b193b1cea9c011cd200..3bd2903ec54aba42ec09a90e3ecc02dbd5648538 100644 (file)
 
 #include <gmime/gmime.h>
 
-/* GMIME_CHECK_VERSION in gmime 2.4 is not usable from the
- * preprocessor (it calls a runtime function). But since
- * GMIME_MAJOR_VERSION and friends were added in gmime 2.6, we can use
- * these to check the version number. */
-#ifdef GMIME_MAJOR_VERSION
-#define GMIME_ATLEAST_26
 typedef GMimeCryptoContext notmuch_crypto_context_t;
-#else
-typedef GMimeCipherContext notmuch_crypto_context_t;
-#endif
 
 #include "notmuch.h"
 
@@ -57,6 +48,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;
 #include <dirent.h>
 #include <errno.h>
 #include <signal.h>
+#include <ctype.h>
 
 #include "talloc-extra.h"
 
@@ -394,17 +386,10 @@ struct mime_node {
 
     /* True if signature verification on this part was attempted. */
     notmuch_bool_t verify_attempted;
-#ifdef GMIME_ATLEAST_26
+
     /* The list of signatures for signed or encrypted containers. If
      * there are no signatures, this will be NULL. */
     GMimeSignatureList* sig_list;
-#else
-    /* For signed or encrypted containers, the validity of the
-     * signature.  May be NULL if signature verification failed.  If
-     * there are simply no signatures, this will be non-NULL with an
-     * empty signers list. */
-    const GMimeSignatureValidity *sig_validity;
-#endif
 
     /* Internal: Context inherited from the root iterator. */
     struct mime_node_context *ctx;
@@ -465,5 +450,22 @@ notmuch_database_dump (notmuch_database_t *notmuch,
                       dump_format_t output_format,
                       notmuch_bool_t gzip_output);
 
+/* If status is non-zero (i.e. error) print appropriate
+   messages to stderr.
+*/
+
+notmuch_status_t
+print_status_query (const char *loc,
+                   const notmuch_query_t *query,
+                   notmuch_status_t status);
+
 #include "command-line-arguments.h"
+
+extern char *notmuch_requested_db_uuid;
+extern const notmuch_opt_desc_t  notmuch_shared_options [];
+void notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch);
+
+void notmuch_process_shared_options (const char* subcommand_name);
+int notmuch_minimal_options (const char* subcommand_name,
+                            int argc, char **argv);
 #endif
index 2fc012a982d7f3b879fc6fe795d01b194b240c31..937372161df1abc95cc569da44a212367fe8a01f 100644 (file)
@@ -38,12 +38,21 @@ notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[])
     notmuch_opt_desc_t options[] = {
        { NOTMUCH_OPT_STRING, &backup_path, "backup", 0, 0 },
        { NOTMUCH_OPT_BOOLEAN,  &quiet, "quiet", 'q', 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
+       { 0, 0, 0, 0, 0}
     };
 
     opt_index = parse_arguments (argc, argv, options, 1);
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    if (notmuch_requested_db_uuid) {
+       fprintf (stderr, "Error: --uuid not implemented for compact\n");
+       return EXIT_FAILURE;
+    }
+
+    notmuch_process_shared_options (argv[0]);
+
     if (! quiet)
        printf ("Compacting database...\n");
     ret = notmuch_database_compact (path, backup_path,
index 2d5c297b7f5f2996b89c6e7c9502df90a06c93d6..d252bb25d4bb565d78c88a14e5719949259a076d 100644 (file)
@@ -872,8 +872,19 @@ int
 notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])
 {
     int ret;
+    int opt_index;
 
-    argc--; argv++; /* skip subcommand argument */
+    opt_index = notmuch_minimal_options ("config", argc, argv);
+    if (opt_index < 0)
+       return EXIT_FAILURE;
+
+    if (notmuch_requested_db_uuid)
+       fprintf (stderr, "Warning: ignoring --uuid=%s\n",
+                notmuch_requested_db_uuid);
+
+    /* skip at least subcommand argument */
+    argc-= opt_index;
+    argv+= opt_index;
 
     if (argc < 1) {
        fprintf (stderr, "Error: notmuch config requires at least one argument.\n");
index 6058f7c9510d6bdbc15a22c4f24a630eadc50666..09613e6ad8d96a6170b2c7ed2337593e4aa802f1 100644 (file)
@@ -33,17 +33,19 @@ enum {
     EXCLUDE_FALSE,
 };
 
-static unsigned int
+/* Return the number of files matching the query, or -1 for an error */
+static int
 count_files (notmuch_query_t *query)
 {
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     notmuch_filenames_t *filenames;
-    unsigned int count = 0;
+    notmuch_status_t status;
+    int count = 0;
 
-    messages = notmuch_query_search_messages (query);
-    if (messages == NULL)
-       return 0;
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch count", query, status))
+       return -1;
 
     for (;
         notmuch_messages_valid (messages);
@@ -67,10 +69,14 @@ count_files (notmuch_query_t *query)
 
 static int
 print_count (notmuch_database_t *notmuch, const char *query_str,
-            const char **exclude_tags, size_t exclude_tags_length, int output)
+            const char **exclude_tags, size_t exclude_tags_length, int output, int print_lastmod)
 {
     notmuch_query_t *query;
     size_t i;
+    int count;
+    unsigned long revision;
+    const char *uuid;
+    int ret = 0;
 
     query = notmuch_query_create (notmuch, query_str);
     if (query == NULL) {
@@ -83,34 +89,48 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
 
     switch (output) {
     case OUTPUT_MESSAGES:
-       printf ("%u\n", notmuch_query_count_messages (query));
+       printf ("%u", notmuch_query_count_messages (query));
        break;
     case OUTPUT_THREADS:
-       printf ("%u\n", notmuch_query_count_threads (query));
+       printf ("%u", notmuch_query_count_threads (query));
        break;
     case OUTPUT_FILES:
-       printf ("%u\n", count_files (query));
+       count = count_files (query);
+       if (count >= 0) {
+           printf ("%u", count);
+       } else {
+           ret = -1;
+           goto DONE;
+       }
        break;
     }
 
+    if (print_lastmod) {
+       revision = notmuch_database_get_revision (notmuch, &uuid);
+       printf ("\t%s\t%lu\n", uuid, revision);
+    } else {
+       fputs ("\n", stdout);
+    }
+
+  DONE:
     notmuch_query_destroy (query);
 
-    return 0;
+    return ret;
 }
 
 static int
 count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,
-           size_t exclude_tags_length, int output)
+           size_t exclude_tags_length, int output, int print_lastmod)
 {
     char *line = NULL;
     ssize_t line_len;
     size_t line_size;
     int ret = 0;
 
-    while (!ret && (line_len = getline (&line, &line_size, input)) != -1) {
+    while (! ret && (line_len = getline (&line, &line_size, input)) != -1) {
        chomp_newline (line);
        ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,
-                          output);
+                          output, print_lastmod);
     }
 
     if (line)
@@ -130,6 +150,7 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
     const char **search_exclude_tags = NULL;
     size_t search_exclude_tags_length = 0;
     notmuch_bool_t batch = FALSE;
+    notmuch_bool_t print_lastmod = FALSE;
     FILE *input = stdin;
     char *input_file_name = NULL;
     int ret;
@@ -144,8 +165,10 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
          (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
                                  { "false", EXCLUDE_FALSE },
                                  { 0, 0 } } },
+       { NOTMUCH_OPT_BOOLEAN, &print_lastmod, "lastmod", 'l', 0 },
        { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
        { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -153,6 +176,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     if (input_file_name) {
        batch = TRUE;
        input = fopen (input_file_name, "r");
@@ -172,7 +197,9 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
                               NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
        return EXIT_FAILURE;
 
-    query_str = query_string_from_args (config, argc-opt_index, argv+opt_index);
+    notmuch_exit_if_unmatched_db_uuid (notmuch);
+
+    query_str = query_string_from_args (config, argc - opt_index, argv + opt_index);
     if (query_str == NULL) {
        fprintf (stderr, "Out of memory.\n");
        return EXIT_FAILURE;
@@ -185,10 +212,10 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
 
     if (batch)
        ret = count_file (notmuch, input, search_exclude_tags,
-                         search_exclude_tags_length, output);
+                         search_exclude_tags_length, output, print_lastmod);
     else
        ret = print_count (notmuch, query_str, search_exclude_tags,
-                          search_exclude_tags_length, output);
+                          search_exclude_tags_length, output, print_lastmod);
 
     notmuch_database_destroy (notmuch);
 
index 9c6ad7f47b0fde514a5e64c96705d598f2eee7ec..829781f8b44feba2f76fb4e39427c5f1029b7fd1 100644 (file)
@@ -48,8 +48,13 @@ database_dump_file (notmuch_database_t *notmuch, gzFile output,
 
     char *buffer = NULL;
     size_t buffer_size = 0;
+    notmuch_status_t status;
 
-    for (messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch dump", query, status))
+       return EXIT_FAILURE;
+
+    for (;
         notmuch_messages_valid (messages);
         notmuch_messages_move_to_next (messages)) {
        int first = 1;
@@ -215,6 +220,8 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
                               NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
        return EXIT_FAILURE;
 
+    notmuch_exit_if_unmatched_db_uuid (notmuch);
+
     char *output_file_name = NULL;
     int opt_index;
 
@@ -228,6 +235,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
                                  { 0, 0 } } },
        { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0  },
        { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -235,6 +243,8 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     if (opt_index < argc) {
        query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
        if (query_str == NULL) {
index 90fe3bad2bfb7291d3d81e6deafb50e6b62d913e..5205c17a290fb6cbea318d9cdfb76458953561c9 100644 (file)
@@ -466,6 +466,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
        { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },
        { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },
        { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { NOTMUCH_OPT_END, 0, 0, 0, 0 }
     };
 
@@ -473,6 +474,8 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     db_path = notmuch_config_get_database_path (config);
     new_tags = notmuch_config_get_new_tags (config, &new_tags_length);
     synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
@@ -521,7 +524,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
            return EXIT_FAILURE;
     }
 
-    /* Setup our handler for SIGINT. We do not set SA_RESTART so that copying
+    /* Set up our handler for SIGINT. We do not set SA_RESTART so that copying
      * from standard input may be interrupted. */
     memset (&action, 0, sizeof (struct sigaction));
     action.sa_handler = handle_sigint;
@@ -533,6 +536,8 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
                               NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
        return EXIT_FAILURE;
 
+    notmuch_exit_if_unmatched_db_uuid (notmuch);
+
     /* Write the message to the Maildir new directory. */
     newpath = maildir_write_new (config, STDIN_FILENO, maildir);
     if (! newpath) {
index e6c283eb7ca123b762f0db4fa69cb33cb17d3e31..33645349cd5fd8abdb5936e185b5f5c70d529c08 100644 (file)
@@ -528,6 +528,10 @@ add_files (notmuch_database_t *notmuch,
                                              "%s/%s", path,
                                              notmuch_filenames_get (db_files));
 
+           if (state->debug)
+               printf ("(D) add_files_recursive, pass 2: queuing passed file %s for deletion from database\n",
+                       absolute);
+
            _filename_list_add (state->removed_files, absolute);
 
            notmuch_filenames_move_to_next (db_files);
@@ -542,6 +546,9 @@ add_files (notmuch_database_t *notmuch,
            {
                char *absolute = talloc_asprintf (state->removed_directories,
                                                  "%s/%s", path, filename);
+               if (state->debug)
+                   printf ("(D) add_files_recursive, pass 2: queuing passed directory %s for deletion from database\n",
+                       absolute);
 
                _filename_list_add (state->removed_directories, absolute);
            }
@@ -610,6 +617,9 @@ add_files (notmuch_database_t *notmuch,
        char *absolute = talloc_asprintf (state->removed_files,
                                          "%s/%s", path,
                                          notmuch_filenames_get (db_files));
+       if (state->debug)
+           printf ("(D) add_files_recursive, pass 3: queuing leftover file %s for deletion from database\n",
+                   absolute);
 
        _filename_list_add (state->removed_files, absolute);
 
@@ -622,6 +632,10 @@ add_files (notmuch_database_t *notmuch,
                                          "%s/%s", path,
                                          notmuch_filenames_get (db_subdirs));
 
+       if (state->debug)
+           printf ("(D) add_files_recursive, pass 3: queuing leftover directory %s for deletion from database\n",
+                   absolute);
+
        _filename_list_add (state->removed_directories, absolute);
 
        notmuch_filenames_move_to_next (db_subdirs);
@@ -662,7 +676,7 @@ setup_progress_printing_timer (void)
     struct sigaction action;
     struct itimerval timerval;
 
-    /* Setup our handler for SIGALRM */
+    /* Set up our handler for SIGALRM */
     memset (&action, 0, sizeof (struct sigaction));
     action.sa_handler = handle_sigalrm;
     sigemptyset (&action.sa_mask);
@@ -864,6 +878,15 @@ _remove_directory (void *ctx,
            goto DONE;
     }
 
+    /*
+     * XXX: The library does not have a function to remove a directory
+     * document for a path. Usually this doesn't matter except for a
+     * slight waste of space. However, if the directory gets added to
+     * the filesystem again, the old directory document is found with
+     * the old mtime. Reset the directory mtime to avoid problems.
+     */
+    notmuch_directory_set_mtime (directory, 0);
+
   DONE:
     notmuch_directory_destroy (directory);
     return status;
@@ -934,6 +957,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
        { NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },
        { NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },
        { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -941,6 +965,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     /* quiet trumps verbose */
     if (quiet)
        add_files_state.verbosity = VERBOSITY_QUIET;
@@ -992,10 +1018,11 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
                fputs (status_string, stderr);
                free (status_string);
            }
-
            return EXIT_FAILURE;
        }
 
+       notmuch_exit_if_unmatched_db_uuid (notmuch);
+
        if (notmuch_database_needs_upgrade (notmuch)) {
            time_t now = time (NULL);
            struct tm *gm_time = gmtime (&now);
@@ -1047,7 +1074,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     if (notmuch == NULL)
        return EXIT_FAILURE;
 
-    /* Setup our handler for SIGINT. We do this after having
+    /* Set up our handler for SIGINT. We do this after having
      * potentially done a database upgrade we this interrupt handler
      * won't support. */
     memset (&action, 0, sizeof (struct sigaction));
index d51fdfc360dd58edc1e5358433663273188aa8a9..fd6a1ec1b11ddb5d9def9ae88f1aa4c59a4ea31a 100644 (file)
@@ -606,8 +606,13 @@ notmuch_reply_format_default(void *ctx,
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     mime_node_t *root;
+    notmuch_status_t status;
 
-    for (messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch reply", query, status))
+       return 1;
+
+    for (;
         notmuch_messages_valid (messages);
         notmuch_messages_move_to_next (messages))
     {
@@ -650,13 +655,17 @@ notmuch_reply_format_sprinter(void *ctx,
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     mime_node_t *node;
+    notmuch_status_t status;
 
     if (notmuch_query_count_messages (query) != 1) {
        fprintf (stderr, "Error: search term did not match precisely one message.\n");
        return 1;
     }
 
-    messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch reply", query, status))
+       return 1;
+
     message = notmuch_messages_get (messages);
     if (mime_node_open (ctx, message, &(params->crypto), &node) != NOTMUCH_STATUS_SUCCESS)
        return 1;
@@ -698,8 +707,13 @@ notmuch_reply_format_headers_only(void *ctx,
     notmuch_message_t *message;
     const char *in_reply_to, *orig_references, *references;
     char *reply_headers;
+    notmuch_status_t status;
 
-    for (messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch reply", query, status))
+       return 1;
+
+    for (;
         notmuch_messages_valid (messages);
         notmuch_messages_move_to_next (messages))
     {
@@ -790,6 +804,7 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
                                  { "sender", FALSE },
                                  { 0, 0 } } },
        { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -797,6 +812,8 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     if (format == FORMAT_HEADERS_ONLY) {
        reply_format_func = notmuch_reply_format_headers_only;
     } else if (format == FORMAT_JSON) {
@@ -828,6 +845,8 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
                               NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
        return EXIT_FAILURE;
 
+    notmuch_exit_if_unmatched_db_uuid (notmuch);
+
     query = notmuch_query_create (notmuch, query_string);
     if (query == NULL) {
        fprintf (stderr, "Out of memory\n");
index 584d9f96ade8dc33a12213b4df6384ed553f9027..9abc64fdd89e6ae7c61e84bc3d3f7f269e72c8de 100644 (file)
@@ -154,6 +154,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
                                  { 0, 0 } } },
        { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
        { NOTMUCH_OPT_BOOLEAN,  &accumulate, "accumulate", 'a', 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -163,6 +164,9 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
        goto DONE;
     }
 
+    notmuch_process_shared_options (argv[0]);
+    notmuch_exit_if_unmatched_db_uuid (notmuch);
+
     name_for_error = input_file_name ? input_file_name : "stdin";
 
     if (! accumulate)
index b81ac0134ef23cbcfec3d37f063a6f758cc99fdf..44e582cbf416acb42f683609fd9f2491c6dca035 100644 (file)
@@ -36,6 +36,12 @@ typedef enum {
     OUTPUT_COUNT       = 1 << 7,
 } output_t;
 
+typedef enum {
+    DEDUP_NONE,
+    DEDUP_MAILBOX,
+    DEDUP_ADDRESS,
+} dedup_t;
+
 typedef enum {
     NOTMUCH_FORMAT_JSON,
     NOTMUCH_FORMAT_TEXT,
@@ -55,6 +61,7 @@ typedef struct {
     int limit;
     int dupe;
     GHashTable *addresses;
+    dedup_t dedup;
 } search_context_t;
 
 typedef struct {
@@ -111,6 +118,7 @@ do_search_threads (search_context_t *ctx)
     sprinter_t *format = ctx->format;
     time_t date;
     int i;
+    notmuch_status_t status;
 
     if (ctx->offset < 0) {
        ctx->offset += notmuch_query_count_threads (ctx->query);
@@ -118,8 +126,8 @@ do_search_threads (search_context_t *ctx)
            ctx->offset = 0;
     }
 
-    threads = notmuch_query_search_threads (ctx->query);
-    if (threads == NULL)
+    status = notmuch_query_search_threads_st (ctx->query, &threads);
+    if (print_status_query("notmuch search", ctx->query, status))
        return 1;
 
     format->begin_list (format);
@@ -243,33 +251,87 @@ do_search_threads (search_context_t *ctx)
     return 0;
 }
 
+static mailbox_t *new_mailbox (void *ctx, const char *name, const char *addr)
+{
+    mailbox_t *mailbox;
+
+    mailbox = talloc (ctx, mailbox_t);
+    if (! mailbox)
+       return NULL;
+
+    mailbox->name = talloc_strdup (mailbox, name);
+    mailbox->addr = talloc_strdup (mailbox, addr);
+    mailbox->count = 1;
+
+    return mailbox;
+}
+
+static int mailbox_compare (const void *v1, const void *v2)
+{
+    const mailbox_t *m1 = v1, *m2 = v2;
+    int ret;
+
+    ret = strcmp_null (m1->name, m2->name);
+    if (! ret)
+       ret = strcmp (m1->addr, m2->addr);
+
+    return ret;
+}
+
 /* Returns TRUE iff name and addr is duplicate. If not, stores the
  * name/addr pair in order to detect subsequent duplicates. */
 static notmuch_bool_t
 is_duplicate (const search_context_t *ctx, const char *name, const char *addr)
 {
-    notmuch_bool_t duplicate;
     char *key;
+    GList *list, *l;
     mailbox_t *mailbox;
 
-    key = talloc_asprintf (ctx->format, "%s <%s>", name, addr);
+    list = g_hash_table_lookup (ctx->addresses, addr);
+    if (list) {
+       mailbox_t find = {
+           .name = name,
+           .addr = addr,
+       };
+
+       l = g_list_find_custom (list, &find, mailbox_compare);
+       if (l) {
+           mailbox = l->data;
+           mailbox->count++;
+           return TRUE;
+       }
+
+       mailbox = new_mailbox (ctx->format, name, addr);
+       if (! mailbox)
+           return FALSE;
+
+       /*
+        * XXX: It would be more efficient to prepend to the list, but
+        * then we'd have to store the changed list head back to the
+        * hash table. This check is here just to avoid the compiler
+        * warning for unused result.
+        */
+       if (list != g_list_append (list, mailbox))
+           INTERNAL_ERROR ("appending to list changed list head\n");
+
+       return FALSE;
+    }
+
+    key = talloc_strdup (ctx->format, addr);
     if (! key)
        return FALSE;
 
-    duplicate = g_hash_table_lookup_extended (ctx->addresses, key, NULL, (gpointer)&mailbox);
+    mailbox = new_mailbox (ctx->format, name, addr);
+    if (! mailbox)
+       return FALSE;
 
-    if (! duplicate) {
-       mailbox = talloc (ctx->format, mailbox_t);
-       mailbox->name = talloc_strdup (mailbox, name);
-       mailbox->addr = talloc_strdup (mailbox, addr);
-       mailbox->count = 1;
-       g_hash_table_insert (ctx->addresses, key, mailbox);
-    } else {
-       mailbox->count++;
-       talloc_free (key);
-    }
+    list = g_list_append (NULL, mailbox);
+    if (! list)
+       return FALSE;
+
+    g_hash_table_insert (ctx->addresses, key, list);
 
-    return duplicate;
+    return FALSE;
 }
 
 static void
@@ -287,7 +349,7 @@ print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox)
     name_addr = internet_address_to_string (ia, FALSE);
 
     if (format->is_text_printer) {
-       if (count > 0) {
+       if (ctx->output & OUTPUT_COUNT) {
            format->integer (format, count);
            format->string (format, "\t");
        }
@@ -301,7 +363,7 @@ print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox)
        format->string (format, addr);
        format->map_key (format, "name-addr");
        format->string (format, name_addr);
-       if (count > 0) {
+       if (ctx->output & OUTPUT_COUNT) {
            format->map_key (format, "count");
            format->integer (format, count);
        }
@@ -338,13 +400,15 @@ process_address_list (const search_context_t *ctx,
            mailbox_t mbx = {
                .name = internet_address_get_name (address),
                .addr = internet_address_mailbox_get_addr (mailbox),
-               .count = 0,
            };
 
-           if (is_duplicate (ctx, mbx.name, mbx.addr))
+           /* OUTPUT_COUNT only works with deduplication */
+           if (ctx->dedup != DEDUP_NONE &&
+               is_duplicate (ctx, mbx.name, mbx.addr))
                continue;
 
-           if (ctx->output & OUTPUT_COUNT)
+           /* OUTPUT_COUNT and DEDUP_ADDRESS require a full pass. */
+           if (ctx->output & OUTPUT_COUNT || ctx->dedup == DEDUP_ADDRESS)
                continue;
 
            print_mailbox (ctx, &mbx);
@@ -378,14 +442,56 @@ _talloc_free_for_g_hash (void *ptr)
 }
 
 static void
-print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)
+_list_free_for_g_hash (void *ptr)
 {
-    const mailbox_t *mailbox = value;
-    search_context_t *ctx = user_data;
+    g_list_free_full (ptr, _talloc_free_for_g_hash);
+}
+
+/* Print the most common variant of a list of unique mailboxes, and
+ * conflate the counts. */
+static void
+print_popular (const search_context_t *ctx, GList *list)
+{
+    GList *l;
+    mailbox_t *mailbox = NULL, *m;
+    int max = 0;
+    int total = 0;
+
+    for (l = list; l; l = l->next) {
+       m = l->data;
+       total += m->count;
+       if (m->count > max) {
+           mailbox = m;
+           max = m->count;
+       }
+    }
+
+    if (! mailbox)
+       INTERNAL_ERROR("Empty list in address hash table\n");
+
+    /* The original count is no longer needed, so overwrite. */
+    mailbox->count = total;
 
     print_mailbox (ctx, mailbox);
 }
 
+static void
+print_list_value (void *mailbox, void *context)
+{
+    print_mailbox (context, mailbox);
+}
+
+static void
+print_hash_value (unused (void *key), void *list, void *context)
+{
+    const search_context_t *ctx = context;
+
+    if (ctx->dedup == DEDUP_ADDRESS)
+       print_popular (ctx, list);
+    else
+       g_list_foreach (list, print_list_value, context);
+}
+
 static int
 _count_filenames (notmuch_message_t *message)
 {
@@ -412,6 +518,7 @@ do_search_messages (search_context_t *ctx)
     notmuch_filenames_t *filenames;
     sprinter_t *format = ctx->format;
     int i;
+    notmuch_status_t status;
 
     if (ctx->offset < 0) {
        ctx->offset += notmuch_query_count_messages (ctx->query);
@@ -419,8 +526,8 @@ do_search_messages (search_context_t *ctx)
            ctx->offset = 0;
     }
 
-    messages = notmuch_query_search_messages (ctx->query);
-    if (messages == NULL)
+    status = notmuch_query_search_messages_st (ctx->query, &messages);
+    if (print_status_query ("notmuch search", ctx->query, status))
        return 1;
 
     format->begin_list (format);
@@ -481,7 +588,8 @@ do_search_messages (search_context_t *ctx)
        notmuch_message_destroy (message);
     }
 
-    if (ctx->addresses && ctx->output & OUTPUT_COUNT)
+    if (ctx->addresses &&
+       (ctx->output & OUTPUT_COUNT || ctx->dedup == DEDUP_ADDRESS))
        g_hash_table_foreach (ctx->addresses, print_hash_value, ctx);
 
     notmuch_messages_destroy (messages);
@@ -508,8 +616,9 @@ do_search_tags (const search_context_t *ctx)
     if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {
        tags = notmuch_database_get_all_tags (notmuch);
     } else {
-       messages = notmuch_query_search_messages (query);
-       if (messages == NULL)
+       notmuch_status_t status;
+       status = notmuch_query_search_messages_st (query, &messages);
+       if (print_status_query ("notmuch search", query, status))
            return 1;
 
        tags = notmuch_messages_collect_tags (messages);
@@ -583,6 +692,8 @@ _notmuch_search_prepare (search_context_t *ctx, notmuch_config_t *config, int ar
        return EXIT_FAILURE;
     }
 
+    notmuch_exit_if_unmatched_db_uuid (ctx->notmuch);
+
     query_str = query_string_from_args (ctx->notmuch, argc, argv);
     if (query_str == NULL) {
        fprintf (stderr, "Out of memory.\n");
@@ -640,6 +751,7 @@ static search_context_t search_context = {
     .offset = 0,
     .limit = -1, /* unlimited */
     .dupe = -1,
+    .dedup = DEDUP_MAILBOX,
 };
 
 static const notmuch_opt_desc_t common_options[] = {
@@ -681,6 +793,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
        { NOTMUCH_OPT_INT, &ctx->limit, "limit", 'L', 0  },
        { NOTMUCH_OPT_INT, &ctx->dupe, "duplicate", 'D', 0  },
        { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -689,6 +802,8 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES &&
        ctx->dupe != -1) {
         fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");
@@ -736,7 +851,13 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])
          (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
                                  { "false", NOTMUCH_EXCLUDE_FALSE },
                                  { 0, 0 } } },
+       { NOTMUCH_OPT_KEYWORD, &ctx->dedup, "deduplicate", 'D',
+         (notmuch_keyword_t []){ { "no", DEDUP_NONE },
+                                 { "mailbox", DEDUP_MAILBOX },
+                                 { "address", DEDUP_ADDRESS },
+                                 { 0, 0 } } },
        { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -744,15 +865,28 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     if (! (ctx->output & (OUTPUT_SENDER | OUTPUT_RECIPIENTS)))
        ctx->output |= OUTPUT_SENDER;
 
+    if (ctx->output & OUTPUT_COUNT && ctx->dedup == DEDUP_NONE) {
+       fprintf (stderr, "--output=count is not applicable with --deduplicate=no\n");
+       return EXIT_FAILURE;
+    }
+
     if (_notmuch_search_prepare (ctx, config,
                                 argc - opt_index, argv + opt_index))
        return EXIT_FAILURE;
 
-    ctx->addresses = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                           _talloc_free_for_g_hash, _talloc_free_for_g_hash);
+    ctx->addresses = g_hash_table_new_full (strcase_hash, strcase_equal,
+                                           _talloc_free_for_g_hash,
+                                           _list_free_for_g_hash);
+
+    /* The order is not guaranteed if a full pass is required, so go
+     * for fastest. */
+    if (ctx->output & OUTPUT_COUNT || ctx->dedup == DEDUP_ADDRESS)
+       notmuch_query_set_sort (ctx->query, NOTMUCH_SORT_UNSORTED);
 
     ret = do_search_messages (ctx);
 
index 36a6171a695b2bde194eab0dab3a577c91e265fe..9aaf9286e8b257bd4946c7f81804b80117d5e3ca 100644 (file)
@@ -145,6 +145,13 @@ notmuch_setup_command (notmuch_config_t *config,
        chomp_newline (response);                               \
     } while (0)
 
+    if (notmuch_minimal_options ("setup", argc, argv) < 0)
+       return EXIT_FAILURE;
+
+    if (notmuch_requested_db_uuid)
+       fprintf (stderr, "Warning: ignoring --uuid=%s\n",
+                notmuch_requested_db_uuid);
+
     if (notmuch_config_is_new (config))
        welcome_message_pre_setup ();
 
index 43bf71c8c8924e80c28f08469d2615642cba44b4..e05480899b33e9cfbc3809f37e9e8c2b6cc8b3de 100644 (file)
@@ -334,8 +334,6 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out,
        g_object_unref(stream_filter);
 }
 
-#ifdef GMIME_ATLEAST_26
-
 /* Get signature status string (GMime 2.6) */
 static const char*
 signature_status_to_string (GMimeSignatureStatus x)
@@ -427,91 +425,6 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
     sp->end (sp);
 }
 
-#else /* GMIME_ATLEAST_26 */
-
-/* Get signature status string (GMime 2.4) */
-static const char*
-signer_status_to_string (GMimeSignerStatus x)
-{
-    switch (x) {
-    case GMIME_SIGNER_STATUS_NONE:
-       return "none";
-    case GMIME_SIGNER_STATUS_GOOD:
-       return "good";
-    case GMIME_SIGNER_STATUS_BAD:
-       return "bad";
-    case GMIME_SIGNER_STATUS_ERROR:
-       return "error";
-    }
-    return "unknown";
-}
-
-/* Signature status sprinter (GMime 2.4) */
-static void
-format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
-{
-    const GMimeSignatureValidity* validity = node->sig_validity;
-
-    sp->begin_list (sp);
-
-    if (!validity) {
-       sp->end (sp);
-       return;
-    }
-
-    const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity);
-    while (signer) {
-       sp->begin_map (sp);
-
-       /* status */
-       sp->map_key (sp, "status");
-       sp->string (sp, signer_status_to_string (signer->status));
-
-       if (signer->status == GMIME_SIGNER_STATUS_GOOD)
-       {
-           if (signer->fingerprint) {
-               sp->map_key (sp, "fingerprint");
-               sp->string (sp, signer->fingerprint);
-           }
-           /* these dates are seconds since the epoch; should we
-            * provide a more human-readable format string? */
-           if (signer->created) {
-               sp->map_key (sp, "created");
-               sp->integer (sp, signer->created);
-           }
-           if (signer->expires) {
-               sp->map_key (sp, "expires");
-               sp->integer (sp, signer->expires);
-           }
-           /* output user id only if validity is FULL or ULTIMATE. */
-           /* note that gmime is using the term "trust" here, which
-            * is WRONG.  It's actually user id "validity". */
-           if ((signer->name) && (signer->trust)) {
-               if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE)) {
-                   sp->map_key (sp, "userid");
-                   sp->string (sp, signer->name);
-               }
-           }
-       } else {
-           if (signer->keyid) {
-              sp->map_key (sp, "keyid");
-              sp->string (sp, signer->keyid);
-          }
-       }
-       if (signer->errors != GMIME_SIGNER_ERROR_NONE) {
-          sp->map_key (sp, "errors");
-          sp->integer (sp, signer->errors);
-       }
-
-       sp->end (sp);
-       signer = signer->next;
-    }
-
-    sp->end (sp);
-}
-
-#endif /* GMIME_ATLEAST_26 */
-
 static notmuch_status_t
 format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
                  int indent, const notmuch_show_params_t *params)
@@ -982,13 +895,17 @@ do_show_single (void *ctx,
 {
     notmuch_messages_t *messages;
     notmuch_message_t *message;
+    notmuch_status_t status;
 
     if (notmuch_query_count_messages (query) != 1) {
        fprintf (stderr, "Error: search term did not match precisely one message.\n");
        return 1;
     }
 
-    messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch show", query, status))
+       return 1;
+
     message = notmuch_messages_get (messages);
 
     if (message == NULL) {
@@ -1015,8 +932,8 @@ do_show (void *ctx,
     notmuch_messages_t *messages;
     notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
 
-    threads = notmuch_query_search_threads (query);
-    if (! threads)
+    status= notmuch_query_search_threads_st (query, &threads);
+    if (print_status_query ("notmuch show", query, status))
        return 1;
 
     sp->begin_list (sp);
@@ -1114,6 +1031,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
        { NOTMUCH_OPT_BOOLEAN, &params.crypto.verify, "verify", 'v', 0 },
        { NOTMUCH_OPT_BOOLEAN, &params.output_body, "body", 'b', 0 },
        { NOTMUCH_OPT_BOOLEAN, &params.include_html, "include-html", 0, 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -1121,6 +1039,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     /* decryption implies verification */
     if (params.crypto.decrypt)
        params.crypto.verify = TRUE;
@@ -1210,6 +1130,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
                               NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
        return EXIT_FAILURE;
 
+    notmuch_exit_if_unmatched_db_uuid (notmuch);
+
     query = notmuch_query_create (notmuch, query_string);
     if (query == NULL) {
        fprintf (stderr, "Out of memory\n");
index 5b2f1e48d6a7ce7d19bae37f9838ad040cbf2642..c020cb6f40b8ad3677aac9fa6104ef3d4aba78b6 100644 (file)
@@ -97,6 +97,8 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
     notmuch_query_t *query;
     notmuch_messages_t *messages;
     notmuch_message_t *message;
+    notmuch_status_t status;
+
     int ret = NOTMUCH_STATUS_SUCCESS;
 
     if (! (flags & TAG_FLAG_REMOVE_ALL)) {
@@ -119,7 +121,11 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
     /* tagging is not interested in any special sort order */
     notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
 
-    for (messages = notmuch_query_search_messages (query);
+    status = notmuch_query_search_messages_st (query, &messages);
+    if (print_status_query ("notmuch tag", query, status))
+       return status;
+
+    for (;
         notmuch_messages_valid (messages) && ! interrupted;
         notmuch_messages_move_to_next (messages)) {
        message = notmuch_messages_get (messages);
@@ -195,7 +201,7 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
     int opt_index;
     int ret;
 
-    /* Setup our handler for SIGINT */
+    /* Set up our handler for SIGINT */
     memset (&action, 0, sizeof (struct sigaction));
     action.sa_handler = handle_sigint;
     sigemptyset (&action.sa_mask);
@@ -206,6 +212,7 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
        { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
        { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
        { NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -213,6 +220,8 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     if (input_file_name) {
        batch = TRUE;
        input = fopen (input_file_name, "r");
@@ -258,6 +267,8 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
                               NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
        return EXIT_FAILURE;
 
+    notmuch_exit_if_unmatched_db_uuid (notmuch);
+
     if (notmuch_config_get_maildir_synchronize_flags (config))
        tag_flags |= TAG_FLAG_MAILDIR_SYNC;
 
index a5b2877aee09243044b960d6b3b1f833fbf091af..ce6c5756c9700af25fa79d3e3f5379b7b9122e2c 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -43,11 +43,64 @@ notmuch_help_command (notmuch_config_t *config, int argc, char *argv[]);
 static int
 notmuch_command (notmuch_config_t *config, int argc, char *argv[]);
 
+static int
+_help_for (const char *topic);
+
+static notmuch_bool_t print_version = FALSE, print_help = FALSE;
+char *notmuch_requested_db_uuid = NULL;
+
+const notmuch_opt_desc_t notmuch_shared_options [] = {
+    { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },
+    { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },
+    { NOTMUCH_OPT_STRING, &notmuch_requested_db_uuid, "uuid", 'u', 0 },
+    {0, 0, 0, 0, 0}
+};
+
+/* any subcommand wanting to support these options should call
+ * inherit notmuch_shared_options and call
+ * notmuch_process_shared_options (subcommand_name);
+ */
+void
+notmuch_process_shared_options (const char *subcommand_name) {
+    if (print_version) {
+       printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n");
+       exit (EXIT_SUCCESS);
+    }
+
+    if (print_help) {
+       int ret = _help_for (subcommand_name);
+       exit (ret);
+    }
+}
+
+/* This is suitable for subcommands that do not actually open the
+ * database.
+ */
+int notmuch_minimal_options (const char *subcommand_name,
+                                 int argc, char **argv)
+{
+    int opt_index;
+
+    notmuch_opt_desc_t options[] = {
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
+       { 0, 0, 0, 0, 0 }
+    };
+
+    opt_index = parse_arguments (argc, argv, options, 1);
+
+    if (opt_index < 0)
+       return -1;
+
+    /* We can't use argv here as it is sometimes NULL */
+    notmuch_process_shared_options (subcommand_name);
+    return opt_index;
+}
+
 static command_t commands[] = {
     { NULL, notmuch_command, TRUE,
       "Notmuch main command." },
     { "setup", notmuch_setup_command, TRUE,
-      "Interactively setup notmuch for first use." },
+      "Interactively set up notmuch for first use." },
     { "new", notmuch_new_command, FALSE,
       "Find and import new messages to the notmuch database." },
     { "insert", notmuch_insert_command, FALSE,
@@ -167,6 +220,22 @@ be supported in the future.\n", notmuch_format_version);
     }
 }
 
+void
+notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch)
+{
+    const char *uuid = NULL;
+
+    if (!notmuch_requested_db_uuid)
+       return;
+    IGNORE_RESULT (notmuch_database_get_revision (notmuch, &uuid));
+
+    if (strcmp (notmuch_requested_db_uuid, uuid) != 0){
+       fprintf (stderr, "Error: requested database revision %s does not match %s\n",
+                notmuch_requested_db_uuid, uuid);
+       exit (1);
+    }
+}
+
 static void
 exec_man (const char *page)
 {
@@ -177,21 +246,19 @@ exec_man (const char *page)
 }
 
 static int
-notmuch_help_command (notmuch_config_t *config, int argc, char *argv[])
+_help_for (const char *topic_name)
 {
     command_t *command;
     help_topic_t *topic;
     unsigned int i;
 
-    argc--; argv++; /* Ignore "help" */
-
-    if (argc == 0) {
+    if (!topic_name) {
        printf ("The notmuch mail system.\n\n");
        usage (stdout);
        return EXIT_SUCCESS;
     }
 
-    if (strcmp (argv[0], "help") == 0) {
+    if (strcmp (topic_name, "help") == 0) {
        printf ("The notmuch help system.\n\n"
                "\tNotmuch uses the man command to display help. In case\n"
                "\tof difficulties check that MANPATH includes the pages\n"
@@ -200,26 +267,46 @@ notmuch_help_command (notmuch_config_t *config, int argc, char *argv[])
        return EXIT_SUCCESS;
     }
 
-    command = find_command (argv[0]);
+    command = find_command (topic_name);
     if (command) {
-       char *page = talloc_asprintf (config, "notmuch-%s", command->name);
+       char *page = talloc_asprintf (NULL, "notmuch-%s", command->name);
        exec_man (page);
     }
 
     for (i = 0; i < ARRAY_SIZE (help_topics); i++) {
        topic = &help_topics[i];
-       if (strcmp (argv[0], topic->name) == 0) {
-           char *page = talloc_asprintf (config, "notmuch-%s", topic->name);
+       if (strcmp (topic_name, topic->name) == 0) {
+           char *page = talloc_asprintf (NULL, "notmuch-%s", topic->name);
            exec_man (page);
        }
     }
 
     fprintf (stderr,
             "\nSorry, %s is not a known command. There's not much I can do to help.\n\n",
-            argv[0]);
+            topic_name);
     return EXIT_FAILURE;
 }
 
+static int
+notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[])
+{
+    int opt_index;
+
+    opt_index = notmuch_minimal_options ("help", argc, argv);
+    if (opt_index < 0)
+       return EXIT_FAILURE;
+
+    /* skip at least subcommand argument */
+    argc-= opt_index;
+    argv+= opt_index;
+
+    if (argc == 0) {
+       return _help_for (NULL);
+    }
+
+    return _help_for (argv[0]);
+}
+
 /* Handle the case of "notmuch" being invoked with no command
  * argument. For now we just call notmuch_setup_command, but we plan
  * to be more clever about this in the future.
@@ -285,14 +372,12 @@ main (int argc, char *argv[])
     command_t *command;
     char *config_file_name = NULL;
     notmuch_config_t *config = NULL;
-    notmuch_bool_t print_help=FALSE, print_version=FALSE;
     int opt_index;
     int ret;
 
     notmuch_opt_desc_t options[] = {
-       { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },
-       { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },
        { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -314,28 +399,11 @@ main (int argc, char *argv[])
        goto DONE;
     }
 
-    /* Handle notmuch --help [command] and notmuch command --help. */
-    if (print_help ||
-       (opt_index + 1 < argc && strcmp (argv[opt_index + 1], "--help") == 0)) {
-       /*
-        * Pass the first positional argument as argv[1] so the help
-        * command can give help for it. The help command ignores the
-        * argv[0] passed to it.
-        */
-       ret = notmuch_help_command (NULL, argc - opt_index + 1,
-                                   argv + opt_index - 1);
-       goto DONE;
-    }
-
-    if (print_version) {
-       printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n");
-       ret = EXIT_SUCCESS;
-       goto DONE;
-    }
-
     if (opt_index < argc)
        command_name = argv[opt_index];
 
+    notmuch_process_shared_options (command_name);
+
     command = find_command (command_name);
     if (!command) {
        fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
index 99c3f52091d659fb9ef710bd1afa856d5fae2ecc..a040a97e043a65e3691361a53556dba6f0f17da5 100755 (executable)
@@ -2,7 +2,7 @@
 
 test_description='notmuch new'
 
-. ./perf-test-lib.sh
+. ./perf-test-lib.sh || exit 1
 
 # ensure initial 'notmuch new' is run by memory_start
 uncache_database
index be5894a65d6049bc9ab9f12a326164bbee280e98..8fea98242d2cb91785ba08fdb5d717ce138532c2 100755 (executable)
@@ -2,7 +2,7 @@
 
 test_description='dump and restore'
 
-. ./perf-test-lib.sh
+. ./perf-test-lib.sh || exit 1
 
 memory_start
 
index 553bb8b66a1f7dc32af48a8528da1fdab8049284..b9f211581f5a20986605dbe0fb54c727e7ddd93d 100755 (executable)
@@ -2,7 +2,7 @@
 
 test_description='notmuch new'
 
-. ./perf-test-lib.sh
+. ./perf-test-lib.sh || exit 1
 
 uncache_database
 
index b2ff94001a3c15b91bfbb5a1e398df8940d72246..9cfd5cd624accdb1e77b6c3a17bc2a79cebbfedc 100755 (executable)
@@ -2,7 +2,7 @@
 
 test_description='dump and restore'
 
-. ./perf-test-lib.sh
+. ./perf-test-lib.sh || exit 1
 
 time_start
 
index 78ceccccbe2813e28001f24bb00d6df17e951ec2..dacb50b8bbf822eb808ae20202b1a0fb2615aa98 100755 (executable)
@@ -2,7 +2,7 @@
 
 test_description='tagging'
 
-. ./perf-test-lib.sh
+. ./perf-test-lib.sh || exit 1
 
 time_start
 
index 75e3d8787ad6db09aeda709707950f5be839468f..00d2f1c6050bb7330bba19e4a17a7bbe097cae42 100644 (file)
@@ -1,4 +1,4 @@
-. ./version.sh
+. ./version.sh || exit 1
 
 corpus_size=large
 
@@ -25,7 +25,7 @@ do
                echo "error: unknown performance test option '$1'" >&2; exit 1 ;;
        esac
 done
-. ../test/test-lib-common.sh
+. ../test/test-lib-common.sh || exit 1
 
 set -e
 
@@ -203,7 +203,7 @@ time_done ()
     fi
 }
 
-cd -P "$test" || error "Cannot setup test environment"
+cd -P "$test" || error "Cannot set up test environment"
 test_failure=0
 test_count=0
 
diff --git a/status.c b/status.c
new file mode 100644 (file)
index 0000000..8fa81cb
--- /dev/null
+++ b/status.c
@@ -0,0 +1,21 @@
+#include "notmuch-client.h"
+
+notmuch_status_t
+print_status_query (const char *loc,
+                   const notmuch_query_t *query,
+                   notmuch_status_t status)
+{
+    if (status) {
+       const char *msg;
+       notmuch_database_t *notmuch;
+
+       fprintf (stderr, "%s: %s\n", loc,
+                notmuch_status_to_string (status));
+
+       notmuch = notmuch_query_get_database (query);
+       msg = notmuch_database_status_string (notmuch);
+       if (msg)
+           fputs (msg, stderr);
+    }
+    return status;
+}
index 2331ceb15e33d2733c79187c413601484c2bbd67..2b18691403aaa101ab81878c22f957eb1a1f034b 100644 (file)
@@ -56,7 +56,17 @@ TEST_BINARIES := $(TEST_BINARIES:.cc=)
 test-binaries: $(TEST_BINARIES)
 
 test:  all test-binaries
+ifeq ($V,)
+       @echo 'Use "$(MAKE) V=1" to print test headings and PASSIng results.'
+       @env NOTMUCH_TEST_QUIET=1 ${test_src_dir}/notmuch-test $(OPTIONS)
+else
+# The user has explicitly enabled quiet execution.
+ifeq ($V,0)
+       @env NOTMUCH_TEST_QUIET=1 ${test_src_dir}/notmuch-test $(OPTIONS)
+else
        @${test_src_dir}/notmuch-test $(OPTIONS)
+endif
+endif
 
 check: test
 
index daf416002ae16274757e06649647563cccd79caf..e54e36b795e852e536dab96256420edbfee84368 100644 (file)
@@ -117,6 +117,13 @@ Note that some tests in the existing test suite rely on previous test
 items, so you cannot arbitrarily skip any test and expect the
 remaining tests to be unaffected.
 
+Currently we do not consider skipped tests as build failures. For
+maximum robustness, when setting up automated build processes, you
+should explicitely skip tests, rather than relying on notmuch's
+detection of missing prerequisites. In the future we may treat tests
+unable to run because of missing prerequisites, but not explicitely
+skipped by the user, as failures.
+
 Writing Tests
 -------------
 The test script is written as a shell script.  It should start with
@@ -138,7 +145,7 @@ Source 'test-lib.sh'
 After assigning test_description, the test script should source
 test-lib.sh like this:
 
-       . ./test-lib.sh
+       . ./test-lib.sh || exit 1
 
 This test harness library does the following things:
 
index ef642457ffafb85fb32940401bc6c3c15e68a43d..d6811bd1075639d71986b283880d6bb40312a3b1 100755 (executable)
@@ -14,7 +14,7 @@ then
        exit 1
 fi
 
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 ################################################################
 # Test harness
index caf8bdb094805f54ccbbe232a78cc26a4a504c5c..c173237631125ebd68894508763f1f61fab94d74 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description="online help"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_expect_success 'notmuch --help' 'notmuch --help'
 test_expect_success 'notmuch help' 'notmuch help'
@@ -12,9 +12,9 @@ if [ $NOTMUCH_HAVE_MAN -eq 1 ]; then
     test_expect_success 'notmuch help tag' 'notmuch help tag'
 else
     test_expect_success 'notmuch --help tag (man pages not available)' \
-       'test_must_fail notmuch --help tag'
+       'test_must_fail notmuch --help tag >/dev/null'
     test_expect_success 'notmuch help tag (man pages not available)' \
-       'test_must_fail notmuch help tag'
+       'test_must_fail notmuch help tag >/dev/null'
 fi
 
 test_done
index 507f769857ddad7ead5912d286008f35c9af979c..8b4dbbc481891e9cec748fa35cf9d5c6a1e0f029 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='"notmuch compact"'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_message '[subject]=One'
 add_message '[subject]=Two'
index 7d14a85f9b4696ccfc88ea584b3f3240341e58e9..f404908a4a1c71f3f65e92c375d988604ffa469c 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description='"notmuch config"'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Get string value"
 test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"
index 0e9f279a6e714c6359261bb6d44d38d6442e68c8..cf0c00bc5c1fcd3900754db00cee34cf8be7c428 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description='"notmuch setup"'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Notmuch new without a config suggests notmuch setup"
 output=$(notmuch --config=new-notmuch-config new 2>&1)
index e6c3291f786553c972e457cf5aeb749c1edca5e5..625739232369bb9783e7aa41cf25417dba6604d0 100755 (executable)
@@ -1,27 +1,27 @@
 #!/usr/bin/env bash
 test_description='"notmuch new" in several variations'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "No new messages"
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "No new mail."
 
 
 test_begin_subtest "Single new message"
 generate_message
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 1 new message to the database."
 
 
 test_begin_subtest "Multiple new messages"
 generate_message
 generate_message
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 2 new messages to the database."
 
 
 test_begin_subtest "No new messages (non-empty DB)"
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "No new mail."
 
 
@@ -31,7 +31,7 @@ mkdir "${MAIL_DIR}"/def
 mkdir "${MAIL_DIR}"/ghi
 generate_message [dir]=def
 
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 1 new message to the database."
 
 
@@ -42,7 +42,7 @@ mv "${MAIL_DIR}"/ghi "${MAIL_DIR}"/abc
 rm "${MAIL_DIR}"/def/*
 generate_message [dir]=abc
 
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 1 new message to the database."
 
 
@@ -54,7 +54,7 @@ mkdir -p "$(dirname "$tmp_msg_filename")"
 mv "$gen_msg_filename" "$tmp_msg_filename"
 notmuch new > /dev/null
 mv "$tmp_msg_filename" "$gen_msg_filename"
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 1 new message to the database."
 
 
@@ -63,15 +63,18 @@ test_begin_subtest "Renamed message"
 generate_message
 notmuch new > /dev/null
 mv "$gen_msg_filename" "${gen_msg_filename}"-renamed
-output=$(NOTMUCH_NEW)
-test_expect_equal "$output" "No new mail. Detected 1 file rename."
+output=$(NOTMUCH_NEW --debug)
+test_expect_equal "$output" "(D) add_files_recursive, pass 2: queuing passed file ${gen_msg_filename} for deletion from database
+No new mail. Detected 1 file rename."
 
 
 test_begin_subtest "Deleted message"
 
 rm "${gen_msg_filename}"-renamed
-output=$(NOTMUCH_NEW)
-test_expect_equal "$output" "No new mail. Removed 1 message."
+output=$(NOTMUCH_NEW --debug)
+test_expect_equal "$output" "(D) add_files_recursive, pass 3: queuing leftover file ${gen_msg_filename}-renamed for deletion from database
+No new mail. Removed 1 message."
+
 
 
 test_begin_subtest "Renamed directory"
@@ -84,34 +87,39 @@ notmuch new > /dev/null
 
 mv "${MAIL_DIR}"/dir "${MAIL_DIR}"/dir-renamed
 
-output=$(NOTMUCH_NEW)
-test_expect_equal "$output" "No new mail. Detected 3 file renames."
+output=$(NOTMUCH_NEW --debug)
+test_expect_equal "$output" "(D) add_files_recursive, pass 2: queuing passed directory ${MAIL_DIR}/dir for deletion from database
+No new mail. Detected 3 file renames."
 
 
 test_begin_subtest "Deleted directory"
-
+test_subtest_known_broken
 rm -rf "${MAIL_DIR}"/dir-renamed
 
-output=$(NOTMUCH_NEW)
-test_expect_equal "$output" "No new mail. Removed 3 messages."
+output=$(NOTMUCH_NEW --debug)
+test_expect_equal "$output" "(D) add_files_recursive, pass 2: queuing passed directory ${MAIL_DIR}/dir-renamed for deletion from database
+No new mail. Removed 3 messages."
 
 
 test_begin_subtest "New directory (at end of list)"
+test_subtest_known_broken
 
 generate_message [dir]=zzz
 generate_message [dir]=zzz
 generate_message [dir]=zzz
 
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 3 new messages to the database."
 
 
 test_begin_subtest "Deleted directory (end of list)"
 
+test_subtest_known_broken
 rm -rf "${MAIL_DIR}"/zzz
 
-output=$(NOTMUCH_NEW)
-test_expect_equal "$output" "No new mail. Removed 3 messages."
+output=$(NOTMUCH_NEW --debug)
+test_expect_equal "$output" "(D) add_files_recursive, pass 3: queuing leftover directory ${MAIL_DIR}/zzz for deletion from database
+No new mail. Removed 3 messages."
 
 
 test_begin_subtest "New symlink to directory"
@@ -122,7 +130,7 @@ mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
 mkdir "${MAIL_DIR}"
 ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
 
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 1 new message to the database."
 
 
@@ -132,13 +140,13 @@ external_msg_filename="${TMP_DIRECTORY}"/external/"$(basename "$gen_msg_filename
 mkdir -p "$(dirname "$external_msg_filename")"
 mv "$gen_msg_filename" "$external_msg_filename"
 ln -s "$external_msg_filename" "$gen_msg_filename"
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 1 new message to the database."
 
 
 test_begin_subtest "Broken symlink aborts"
 ln -s does-not-exist "${MAIL_DIR}/broken"
-output=$(NOTMUCH_NEW 2>&1)
+output=$(NOTMUCH_NEW --debug 2>&1)
 test_expect_equal "$output" \
 "Error reading file ${MAIL_DIR}/broken: No such file or directory
 Note: A fatal error was encountered: Something went wrong trying to read or write a file
@@ -152,7 +160,7 @@ generate_message [dir]=two/levels
 generate_message [dir]=two/levels
 generate_message [dir]=two/levels
 
-output=$(NOTMUCH_NEW)
+output=$(NOTMUCH_NEW --debug)
 test_expect_equal "$output" "Added 3 new messages to the database."
 
 
@@ -160,10 +168,12 @@ test_begin_subtest "Deleted two-level directory"
 
 rm -rf "${MAIL_DIR}"/two
 
-output=$(NOTMUCH_NEW)
-test_expect_equal "$output" "No new mail. Removed 3 messages."
+output=$(NOTMUCH_NEW --debug)
+test_expect_equal "$output" "(D) add_files_recursive, pass 3: queuing leftover directory ${MAIL_DIR}/two for deletion from database
+No new mail. Removed 3 messages."
 
-test_begin_subtest "Support single-message mbox (deprecated)"
+test_begin_subtest "Support single-message mbox"
+test_subtest_known_broken
 cat > "${MAIL_DIR}"/mbox_file1 <<EOF
 From test_suite@notmuchmail.org Fri Jan  5 15:43:57 2001
 From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -172,11 +182,12 @@ Subject: Test mbox message 1
 
 Body.
 EOF
-output=$(NOTMUCH_NEW 2>&1)
+output=$(NOTMUCH_NEW --debug 2>&1)
 test_expect_equal "$output" "Added 1 new message to the database."
 
 # This test requires that notmuch new has been run at least once.
 test_begin_subtest "Skip and report non-mail files"
+test_subtest_known_broken
 generate_message
 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
 touch "${MAIL_DIR}"/ignored_file
@@ -196,7 +207,7 @@ Subject: Test mbox message 2
 
 Body 2.
 EOF
-output=$(NOTMUCH_NEW 2>&1)
+output=$(NOTMUCH_NEW --debug 2>&1)
 test_expect_equal "$output" \
 "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
 Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
@@ -235,6 +246,7 @@ test_expect_equal "$output" \
 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
+(D) add_files_recursive, pass 3: queuing leftover directory ${MAIL_DIR}/two for deletion from database
 No new mail."
 
 
@@ -263,23 +275,23 @@ OLDCONFIG=$(notmuch config get new.tags)
 
 test_begin_subtest "Empty tags in new.tags are forbidden"
 notmuch config set new.tags "foo;;bar"
-output=$(NOTMUCH_NEW 2>&1)
+output=$(NOTMUCH_NEW --debug 2>&1)
 test_expect_equal "$output" "Error: tag '' in new.tags: empty tag forbidden"
 
 test_begin_subtest "Tags starting with '-' in new.tags are forbidden"
 notmuch config set new.tags "-foo;bar"
-output=$(NOTMUCH_NEW 2>&1)
+output=$(NOTMUCH_NEW --debug 2>&1)
 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
 
 test_expect_code 1 "Invalid tags set exit code" \
-    "NOTMUCH_NEW 2>&1"
+    "NOTMUCH_NEW --debug 2>&1"
 
 notmuch config set new.tags $OLDCONFIG
 
 
 test_begin_subtest "Xapian exception: read only files"
 chmod u-w  ${MAIL_DIR}/.notmuch/xapian/*.DB
-output=$(NOTMUCH_NEW 2>&1 | sed 's/: .*$//' )
+output=$(NOTMUCH_NEW --debug 2>&1 | sed 's/: .*$//' )
 chmod u+w  ${MAIL_DIR}/.notmuch/xapian/*.DB
 test_expect_equal "$output" "A Xapian exception occurred opening database"
 
index da86c8cc70cf4a9f32669fd1b3472353f528d295..3fec94e899cc7925563405b724fb79a5620695bb 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='"notmuch count" for messages and threads'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_email_corpus
 
@@ -93,5 +93,35 @@ notmuch count --output=messages >>EXPECTED
 notmuch count --output=messages tag:inbox >>EXPECTED
 test_expect_equal_file EXPECTED OUTPUT
 
+backup_database
+test_begin_subtest "error message for database open"
+dd if=/dev/zero of="${MAIL_DIR}/.notmuch/xapian/postlist.DB" count=3
+notmuch count '*' 2>OUTPUT 1>/dev/null
+output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)
+test_expect_equal "${output}" "A Xapian exception occurred opening database"
+restore_database
+
+cat <<EOF > count-files.gdb
+set breakpoint pending on
+break count_files
+commands
+shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.DB
+continue
+end
+run
+EOF
+
+backup_database
+test_begin_subtest "error message from query_search_messages"
+gdb --batch-silent --return-child-result -x count-files.gdb \
+    --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null
+cat <<EOF > EXPECTED
+notmuch count: A Xapian exception occurred
+A Xapian exception occurred performing query
+Query string was: *
+EOF
+sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
+test_expect_equal_file EXPECTED OUTPUT.clean
+restore_database
 
 test_done
index 74f1955203f0f5cedcf0be633bcef440eeb5aa51..e7ec6a6cc579d7d2b812e7e19dfb5851b3e25ae8 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='"notmuch insert"'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_require_external_prereq gdb
 
@@ -188,7 +188,7 @@ notmuch config set new.tags $OLDCONFIG
 # DUPLICATE_MESSAGE_ID is not tested here, because it should actually pass.
 
 for code in OUT_OF_MEMORY XAPIAN_EXCEPTION FILE_NOT_EMAIL \
-    READ_ONLY_DATABASE UPGRADE_REQUIRED; do
+    READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do
 gen_insert_msg
 cat <<EOF > index-file-$code.gdb
 set breakpoint pending on
index 05027fb0fee0bfbc7b1548421220e860bef1144d..5e8b20ce1657869d6a9d6c1d0039f3764f48d575 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='"notmuch search" in several variations'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_email_corpus
 
index fe2ec9af8c2a0bd062c35bbbad9077a8190d23cd..a28eaf20a5d0f112eaf64d432f1a249a4e861b59 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='various settings for "notmuch search --output="'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_email_corpus
 
index ed0cac7807ffd8d1a7ffa06e0132d3832631ef5b..a194faf3b8425ec5bd8eabcee59b7637cd82e813 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='"notmuch address" in several variants'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_email_corpus
 
@@ -145,4 +145,148 @@ cat <<EOF >EXPECTED
 EOF
 test_expect_equal_file OUTPUT EXPECTED
 
+test_begin_subtest "--deduplicate=no --sort=oldest-first --output=sender"
+notmuch address --deduplicate=no --sort=oldest-first --output=sender '*' >OUTPUT
+cat <<EOF >EXPECTED
+Mikhail Gusarov <dottedmag@dottedmag.net>
+Mikhail Gusarov <dottedmag@dottedmag.net>
+Carl Worth <cworth@cworth.org>
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Mikhail Gusarov <dottedmag@dottedmag.net>
+Alex Botero-Lowry <alex.boterolowry@gmail.com>
+Carl Worth <cworth@cworth.org>
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Mikhail Gusarov <dottedmag@dottedmag.net>
+Mikhail Gusarov <dottedmag@dottedmag.net>
+Keith Packard <keithp@keithp.com>
+Keith Packard <keithp@keithp.com>
+Keith Packard <keithp@keithp.com>
+Jan Janak <jan@ryngle.com>
+Jan Janak <jan@ryngle.com>
+Jan Janak <jan@ryngle.com>
+Israel Herraiz <isra@herraiz.org>
+Adrian Perez de Castro <aperez@igalia.com>
+Aron Griffis <agriffis@n01se.net>
+Ingmar Vanhassel <ingmar@exherbo.org>
+Alex Botero-Lowry <alex.boterolowry@gmail.com>
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Stewart Smith <stewart@flamingspork.com>
+Stewart Smith <stewart@flamingspork.com>
+Keith Packard <keithp@keithp.com>
+Keith Packard <keithp@keithp.com>
+Keith Packard <keithp@keithp.com>
+Stewart Smith <stewart@flamingspork.com>
+Jjgod Jiang <gzjjgod@gmail.com>
+Jan Janak <jan@ryngle.com>
+Rolland Santimano <rollandsantimano@yahoo.com>
+Alexander Botero-Lowry <alex.boterolowry@gmail.com>
+Jjgod Jiang <gzjjgod@gmail.com>
+Alexander Botero-Lowry <alex.boterolowry@gmail.com>
+Alexander Botero-Lowry <alex.boterolowry@gmail.com>
+Keith Packard <keithp@keithp.com>
+Alexander Botero-Lowry <alex.boterolowry@gmail.com>
+Carl Worth <cworth@cworth.org>
+Carl Worth <cworth@cworth.org>
+Carl Worth <cworth@cworth.org>
+Carl Worth <cworth@cworth.org>
+Carl Worth <cworth@cworth.org>
+Carl Worth <cworth@cworth.org>
+Carl Worth <cworth@cworth.org>
+Carl Worth <cworth@cworth.org>
+Carl Worth <cworth@cworth.org>
+Carl Worth <cworth@cworth.org>
+Chris Wilson <chris@chris-wilson.co.uk>
+Olivier Berger <olivier.berger@it-sudparis.eu>
+François Boulogne <boulogne.f@gmail.com>
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "--deduplicate=no --sort=newest-first --output=sender --output=recipients"
+notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo/new >OUTPUT
+cat <<EOF >EXPECTED
+Mikhail Gusarov <dottedmag@dottedmag.net>
+notmuch@notmuchmail.org
+Mikhail Gusarov <dottedmag@dottedmag.net>
+notmuch@notmuchmail.org
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+notmuch@notmuchmail.org
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "--deduplicate=address --output=sender --output=recipients"
+notmuch address --deduplicate=address --output=sender --output=recipients '*' | sort >OUTPUT
+cat <<EOF >EXPECTED
+"Discussion about the Arch User Repository (AUR)" <aur-general@archlinux.org>
+Adrian Perez de Castro <aperez@igalia.com>
+Alexander Botero-Lowry <alex.boterolowry@gmail.com>
+Allan McRae <allan@archlinux.org>
+Aron Griffis <agriffis@n01se.net>
+Carl Worth <cworth@cworth.org>
+Chris Wilson <chris@chris-wilson.co.uk>
+François Boulogne <boulogne.f@gmail.com>
+Ingmar Vanhassel <ingmar@exherbo.org>
+Israel Herraiz <isra@herraiz.org>
+Jan Janak <jan@ryngle.com>
+Jjgod Jiang <gzjjgod@gmail.com>
+Keith Packard <keithp@keithp.com>
+Lars Kellogg-Stedman <lars@seas.harvard.edu>
+Mikhail Gusarov <dottedmag@dottedmag.net>
+Olivier Berger <olivier.berger@it-sudparis.eu>
+Rolland Santimano <rollandsantimano@yahoo.com>
+Stewart Smith <stewart@flamingspork.com>
+notmuch@notmuchmail.org
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+generate_message '[from]="Foo Bar <foo.bar@example.com>"'
+generate_message '[from]="Foo Bar <Foo.Bar@Example.Com>"'
+generate_message '[from]="Foo Bar <foo.bar@example.com>"'
+generate_message '[from]="Bar <Foo.Bar@Example.Com>"'
+generate_message '[from]="Foo <foo.bar@example.com>"'
+generate_message '[from]="<foo.bar@example.com>"'
+generate_message '[from]="foo.bar@example.com"'
+generate_message '[from]="Baz <foo.bar+baz@example.com>"'
+generate_message '[from]="Foo Bar <foo.bar+baz@example.com>"'
+generate_message '[from]="Baz <foo.bar+baz@example.com>"'
+notmuch new > /dev/null
+
+test_begin_subtest "--deduplicate=no --output=sender"
+notmuch address --deduplicate=no --output=sender from:example.com | sort >OUTPUT
+cat <<EOF >EXPECTED
+Bar <Foo.Bar@Example.Com>
+Baz <foo.bar+baz@example.com>
+Baz <foo.bar+baz@example.com>
+Foo <foo.bar@example.com>
+Foo Bar <Foo.Bar@Example.Com>
+Foo Bar <foo.bar+baz@example.com>
+Foo Bar <foo.bar@example.com>
+Foo Bar <foo.bar@example.com>
+foo.bar@example.com
+foo.bar@example.com
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "--deduplicate=mailbox --output=sender --output=count"
+notmuch address --deduplicate=mailbox --output=sender --output=count from:example.com | sort -n >OUTPUT
+cat <<EOF >EXPECTED
+1      Bar <Foo.Bar@Example.Com>
+1      Foo <foo.bar@example.com>
+1      Foo Bar <Foo.Bar@Example.Com>
+1      Foo Bar <foo.bar+baz@example.com>
+2      Baz <foo.bar+baz@example.com>
+2      Foo Bar <foo.bar@example.com>
+2      foo.bar@example.com
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "--deduplicate=address --output=sender --output=count"
+notmuch address --deduplicate=address --output=sender --output=count from:example.com | sort -n >OUTPUT
+cat <<EOF >EXPECTED
+3      Baz <foo.bar+baz@example.com>
+7      Foo Bar <foo.bar@example.com>
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
 test_done
index 583bdf5eb0869a1031fab79649ee20ee356fe645..2844ec61f47fc6f93cde459ac1e4e34c4b7af6f2 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='"notmuch search" by folder: and path: (with variations)'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_message '[dir]=bad' '[subject]="To the bone"'
 add_message '[dir]=.' '[subject]="Top level"'
index 5da6ad6f2ef7ee018e7b605d7442137e68a8f172..2a4238f95fc93ca48830b6d13f113bf6fe7b6268 100755 (executable)
@@ -18,7 +18,7 @@
 # id:3wd4o8wa7fx.fsf@testarossa.amd.com
 
 test_description='that notmuch does not overlap term positions'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_message '[to]="a@b.c, x@y.z"'
 
index e83ea3d190848831d63ae1aef246ed4a7f2c78e3..4862d82644df6979b2e84f98d8006fdadf18c957 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='messages with unquoted . in name'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_message \
   '[from]="Some.Name for Someone <bugs@quoting.com>"' \
index 303762cf7bbab4f843e9a6c85a8555d928b98d05..c8986f4e405795b58cda66553c80e5e9588bcf4a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='"notmuch search" --offset and --limit parameters'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_email_corpus
 
index 8bbbc2dd033700119bc6768264940eab821b0d06..f91d4d7f0cac11bd7282d9b7a8156c1ac6808294 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='"notmuch search, count and show" with excludes in several variations'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 # Generates a thread consisting of a top level message and 'length'
 # replies. The subject of the top message 'subject: top message"
index 4a2673d442b17379f8d18f4950f325a5247c7ea9..821d39334e5c9684551c7dc4f03afa7502618b81 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='"notmuch tag"'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_message '[subject]=One'
 add_message '[subject]=Two'
index c1cf649d6dcad15735767911f414aa58361a4060..b346f37ee4717d43e8229079ec5d0482d84d08fe 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="--format=json output"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Show message: json"
 add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"json-show-message\""
index 667e3195d836906c2d27498ade17a1f6fa7b0611..800ebc6310e7f6cd7e9b5dac50303461e673008e 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="--format=sexp output"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Show message: sexp"
 add_message "[subject]=\"sexp-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"sexp-show-message\""
index b5ccefc9fccd82e7539a46f9379b8db6750e90df..3a265dbd5a73a24ef76354258ede1e689d8d8d26 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="--format=text output"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Show message: text"
 add_message "[subject]=\"text-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"text-show-message\""
index ad8d29eafcc69802f6226fa60be5860da056d887..7c4c9f71913fc695a29a668294d5ece21cf6f0d5 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="output of multipart message"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 cat <<EOF > embedded_message
 From: Carl Worth <cworth@cworth.org>
index dcfc1b3651d90ba9d71804afe3eb6d3157b5f4fe..132c1d77370fcfa62ae4709b4eca33a66b8937cc 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="naming of threads with changing subject"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Initial thread name (oldest-first search)"
 add_message '[subject]="thread-naming: Initial thread subject"' \
index cb678ae83856bacab1c447350952332574a250cb..69d8dc50ff8652f7f40a0d2a591f8f622e77a01d 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="naming of authors with unusual addresses"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Add author with empty quoted real name"
 add_message '[subject]="author-naming: Initial thread subject"' \
index daf5735cd6da3fd8b3ea870e517eee0739d31ca6..dfea2d19caa93fece9fdbd3dc0ba0fbefd94c828 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description='notmuch show --format=raw'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_message
 add_message
index b0d854a1fc000a3a3b85089eb7c4ea5d6ab538cf..30b78f679d97d82aa42d4817d93c654b5177cf7e 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="\"notmuch reply\" in several variations"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Basic reply"
 add_message '[from]="Sender <sender@example.com>"' \
index 30e5e385e0b32ae2cad2d278192226214424328d..608334dc023ecd4bb4d82636bbd60dd8d596b80f 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="\"notmuch reply --reply-to=sender\" in several variations"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Basic reply-to-sender"
 add_message '[from]="Sender <sender@example.com>"' \
index efe463ea03dd104ad06995a877e91e39b455a78f..e6976ff8f2788634d202ed63e0960b0fa0cf6227 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="\"notmuch dump\" and \"notmuch restore\""
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_email_corpus
 
index b3e1ac191bba9c8f6d7e60d85b6dc0b5cc3aa8c0..6f45d3959bf2d6f020d9ab8731331deb106dd0b7 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="handling of uuencoded data"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
 '[body]="This message is used to ensure that notmuch correctly handles a
index 5239bd443512988f9d11f04fa4cba1894db918c1..f720c99817a1561ef8df2c1300644d8a2ee600db 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="threading when messages received out of order"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 # Generate all single-root four message thread structures.  We'll use
 # this for multiple tests below.
index 6ffeffc719476630c21055dc978d7d934df371c8..9124ece6f911a8f9862dfc1d008a45680fab90d0 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="author reordering;"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Adding parent message"
 generate_message [body]=findme [id]=new-parent-id [subject]=author-reorder-threadtest '[from]="User <user@example.com>"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
index 6dfaa40a9478ccdc6bf415ff0fb4fe66d89c88d7..7c562fb9e3537c139f058bd2510b72b02ae988c1 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="From line heuristics (with multiple configured addresses)"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Magic from guessing (nothing to go on)"
 add_message '[from]="Sender <sender@example.com>"' \
index 85e620fadd404f8c3ffaf4e4316f4f469e0fb943..1fb7c037ee52833c23ea7205d15c4222e572d605 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="messages with ridiculously-long message IDs"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Referencing long ID before adding"
 generate_message '[subject]="Reference of ridiculously-long message ID"' \
index b6c86bf02f11616dbf50fc8db2689882244086df..8d201c7e8aa42d94c316c3e21a51658c58843de0 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="encoding issues"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Message with text of unknown charset"
 add_message '[content-type]="text/plain; charset=unknown-8bit"' \
index d72799b4e1fff881e3d258ff81ae7277b16ee94f..61bc369af494208aa919073f244d835a3912ca45 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description="emacs interface"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 EXPECTED=$TEST_DIRECTORY/emacs.expected-output
 
index 8b1251fec1a683c3ff426630de565b826b82fdc9..3fd6958a0441d6a73bc6004b8b242e2537dbd96f 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="Emacs with large search results buffer"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 x=xxxxxxxxxx # 10
 x=$x$x$x$x$x$x$x$x$x$x # 100
index 230c324d2ea4d60aa35bfbd4af30eb73a6c716d1..517fa8398261ad7c3aea91d641685c8bdba9baf8 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description="emacs: mail subject to filename"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 # emacs server can't be started in a child process with $(test_emacs ...)
 test_emacs '(ignore)' > /dev/null
index 3186e70f56e4c03a3eb45dc85d1fd955f8e59a89..efeaa3f60d6e28fa4489a05dad2837ff844dd4fa 100755 (executable)
@@ -2,7 +2,7 @@
 
 test_description="maildir synchronization"
 
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 # Create the expected maildir structure
 mkdir $MAIL_DIR/cur
index 477b397e419e644dbbf48d92b0a7d13b09e373e5..3656cce951ca08263ae6cdfe8c0acf8ceb38f515 100755 (executable)
@@ -5,7 +5,7 @@
 # - verification of signatures from expired/revoked keys
 
 test_description='PGP/MIME signature verification and decryption'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_gnupg_home ()
 {
index d2b5d1f5a90281bbf69f9d2b968ab3ff2cbd8761..4ec0ea65710baba535cc7910fd3e55895f7edce6 100755 (executable)
@@ -9,18 +9,19 @@
 
 test_description='exception symbol hiding'
 
-. ./test-lib.sh
-
-run_test(){
-    result=$(LD_LIBRARY_PATH="$TEST_DIRECTORY/../lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" $TEST_DIRECTORY/symbol-test 2>&1)
-}
-
-output="A Xapian exception occurred opening database: Couldn't stat 'fakedb/.notmuch/xapian'
-caught No chert database found at path \`./nonexistent'"
-
-mkdir -p fakedb/.notmuch
-
-test_expect_success 'running test' run_test
+. ./test-lib.sh || exit 1
+
+test_begin_subtest 'running test' run_test
+mkdir -p ${PWD}/fakedb/.notmuch
+( LD_LIBRARY_PATH="$TEST_DIRECTORY/../lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
+                $TEST_DIRECTORY/symbol-test ${PWD}/fakedb ${PWD}/nonexistent \
+                2>&1 | sed "s,${PWD},CWD,g") > OUTPUT
+
+cat <<EOF > EXPECTED
+A Xapian exception occurred opening database: Couldn't stat 'CWD/fakedb/.notmuch/xapian'
+caught No chert database found at path \`CWD/nonexistent'
+EOF
+test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest 'checking output'
 test_expect_equal "$result" "$output"
index 5e72a6ccfd3a372bad4127c494e7dfe51cd6945d..da4ec2b8c61a15403b14433b0774ca6aaaf7f2b7 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='folder tags removed and added through file renames remain consistent'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "No new messages"
 output=$(NOTMUCH_NEW)
index ee1e2f43d838960a9f8d8173c666bf2ae95834b1..845dfde75fd6e8bae20283da3285d3046b498761 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='atomicity'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 # This script tests the effects of killing and restarting "notmuch
 # new" at arbitrary points.  If notmuch new is properly atomic, the
index 3f03a2e3a966018a273bdb75dece7fcc1b224ddd..4726bc366ecebda8fc48e694ad802403ea4c6807 100755 (executable)
@@ -1,6 +1,8 @@
 #!/usr/bin/env bash
 test_description="python bindings"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
+
+test_require_external_prereq ${NOTMUCH_PYTHON}
 
 add_email_corpus
 
@@ -11,7 +13,7 @@ db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
 q_new = notmuch.Query(db, 'tag:inbox')
 q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
 for t in q_new.search_threads():
-    print t.get_thread_id()
+    print (t.get_thread_id())
 EOF
 notmuch search --sort=oldest-first --output=threads tag:inbox | sed s/^thread:// > EXPECTED
 test_expect_equal_file OUTPUT EXPECTED
@@ -23,7 +25,7 @@ db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
 q_new = notmuch.Query(db, 'tag:inbox')
 q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
 for m in q_new.search_messages():
-    print m.get_message_id()
+    print (m.get_message_id())
 EOF
 notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED
 test_expect_equal_file OUTPUT EXPECTED
@@ -32,7 +34,7 @@ test_begin_subtest "get non-existent file"
 test_python <<EOF
 import notmuch
 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
-print db.find_message_by_filename("i-dont-exist")
+print (db.find_message_by_filename("i-dont-exist"))
 EOF
 test_expect_equal "$(cat OUTPUT)" "None"
 
diff --git a/test/T395-ruby.sh b/test/T395-ruby.sh
new file mode 100755 (executable)
index 0000000..d5cade8
--- /dev/null
@@ -0,0 +1,86 @@
+#!/usr/bin/env bash
+test_description="ruby bindings"
+. ./test-lib.sh || exit 1
+
+if [ "${NOTMUCH_HAVE_RUBY_DEV}" = "0" ]; then
+    test_subtest_missing_external_prereq_["ruby development files"]=t
+fi
+
+add_email_corpus
+
+test_begin_subtest "compare thread ids"
+test_ruby <<"EOF"
+require 'notmuch'
+$maildir = ENV['MAIL_DIR']
+if not $maildir then
+  abort('environment variable MAIL_DIR must be set')
+end
+@db = Notmuch::Database.new($maildir)
+@q = @db.query('tag:inbox')
+@q.sort = Notmuch::SORT_OLDEST_FIRST
+for t in @q.search_threads do
+  print t.thread_id, "\n"
+end
+EOF
+notmuch search --sort=oldest-first --output=threads tag:inbox | sed s/^thread:// > EXPECTED
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "compare message ids"
+test_ruby <<"EOF"
+require 'notmuch'
+$maildir = ENV['MAIL_DIR']
+if not $maildir then
+  abort('environment variable MAIL_DIR must be set')
+end
+@db = Notmuch::Database.new($maildir)
+@q = @db.query('tag:inbox')
+@q.sort = Notmuch::SORT_OLDEST_FIRST
+for m in @q.search_messages do
+  print m.message_id, "\n"
+end
+EOF
+notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "get non-existent file"
+test_ruby <<"EOF"
+require 'notmuch'
+$maildir = ENV['MAIL_DIR']
+if not $maildir then
+  abort('environment variable MAIL_DIR must be set')
+end
+@db = Notmuch::Database.new($maildir)
+result = @db.find_message_by_filename('i-dont-exist')
+print (result == nil)
+EOF
+test_expect_equal "$(cat OUTPUT)" "true"
+
+test_begin_subtest "count messages"
+test_ruby <<"EOF"
+require 'notmuch'
+$maildir = ENV['MAIL_DIR']
+if not $maildir then
+  abort('environment variable MAIL_DIR must be set')
+end
+@db = Notmuch::Database.new($maildir)
+@q = @db.query('tag:inbox')
+print @q.count_messages(),"\n"
+EOF
+notmuch count --output=messages tag:inbox > EXPECTED
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "count threads"
+test_ruby <<"EOF"
+require 'notmuch'
+$maildir = ENV['MAIL_DIR']
+if not $maildir then
+  abort('environment variable MAIL_DIR must be set')
+end
+@db = Notmuch::Database.new($maildir)
+@q = @db.query('tag:inbox')
+print @q.count_threads(),"\n"
+EOF
+notmuch count --output=threads tag:inbox > EXPECTED
+test_expect_equal_file OUTPUT EXPECTED
+
+test_done
index 1adab2f078e51cbe79b9509431e902d5b15a0e69..ed1191319fecbf49f681b0f46ee4a197a45ccdee 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='hooks'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 HOOK_DIR=${MAIL_DIR}/.notmuch/hooks
 
index 2e5d7ae3ab4da7f809d8ce4f6a7a1e7716515d66..f8ff8ff9139dd90edd15eafda6b9a76cb908f56a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="argument parsing"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "sanity check"
 $TEST_DIRECTORY/arg-test  pos1  --keyword=one --string=foo pos2 --int=7 --flag=one --flag=three > OUTPUT
index ca4a7988567452af1f2d3296ba462d275516fb3f..955c5f7ff295beacdf3dc52b61e5a2ef6b2561c0 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description="emacs test function sanity"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "emacs test function sanity"
 test_emacs_expect_t 't'
index 04723467e80814b26f574b8af71284d102250273..664b79d293fb0ead36326ab4c8a7e04af1da0c7f 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description="emacs address cleaning"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "notmuch-test-address-clean part 1"
 test_emacs_expect_t '(notmuch-test-address-cleaning-1)'
index f7296166a7bdd84b8762b7028a27e3bd88ace808..a8ed22824e0c3efce61a86b42a886b59f09ad1ca 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description="emacs notmuch-hello view"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 EXPECTED=$TEST_DIRECTORY/emacs.expected-output
 
index bfcd5efedaf9f409d37aa75c36eaddb668a2cc64..0342a8745b3d136e942809768a1a5ee6b0368419 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description="emacs notmuch-show view"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 EXPECTED=$TEST_DIRECTORY/emacs-show.expected-output
 
index 3078f9c956a0e1a3423b631ef54a9c1a6ad1980e..7624fa4d10a645b8b8c5d636e76370b4a7904030 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description="emacs notmuch-show charset handling"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 
 UTF8_YEN=$'\xef\xbf\xa5'
index 8e9f37cbf9c6926f8de1b6e665d545ce90dae725..b6181b51c2ff741562d3cbe2f73097862c97bbc9 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 test_description="emacs tree view interface"
-. test-lib.sh
+. ./test-lib.sh || exit 1
 
 EXPECTED=$TEST_DIRECTORY/tree.expected-output
 
index cb38301c255a1d0b8dd661636499930862fd5b7f..e256c10ac47a8f370cd42e95eb0bcafbd20b4845 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description='messages with missing headers'
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 # Notmuch requires at least one of from, subject, or to or it will
 # ignore the file.  Generate two messages so that together they cover
index ad50e1bcc0716a5ad587f0deb50b7e1912d8d893..10527b185fce927c8dab732d7b6ce7d816017812 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="hex encoding and decoding"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "round trip"
 find $TEST_DIRECTORY/corpus -type f -print | sort | xargs cat > EXPECTED
index 6aa9d433bfd40da5562aca16cb0ff79943d502d3..ab90fcc5a76d444c831843d681c2499afc936c2e 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="date/time parser module"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 # Sanity/smoke tests for the date/time parser independent of notmuch
 
index 70bcf344b4f76db35d9c1ccc13177018eb6b0287..f5cea421d785d380985eb0d092c0265821d7aab2 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 test_description="date:since..until queries"
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_email_corpus
 
@@ -8,6 +8,10 @@ test_begin_subtest "Absolute date range"
 output=$(notmuch search date:2010-12-16..12/16/2010 | notmuch_search_sanitize)
 test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentué (inbox unread)"
 
+test_begin_subtest "Absolute date range with 'same' operator"
+output=$(notmuch search date:2010-12-16..! | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentué (inbox unread)"
+
 test_begin_subtest "Absolute time range with TZ"
 notmuch search date:18-Nov-2009_02:19:26-0800..2009-11-18_04:49:52-06:00 | notmuch_search_sanitize > OUTPUT
 cat <<EOF >EXPECTED
index 1392fbedd0527b58b861602314b0073515108732..5ab066ac7baab83c3822172993f34fb48161ecf4 100755 (executable)
@@ -9,7 +9,7 @@ test_description='test of proper handling of in-reply-to and references headers'
 # database is constructed properly, even in the presence of
 # non-RFC-compliant headers'
 
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "Use References when In-Reply-To is broken"
 add_message '[id]="foo@one.com"' \
index 0657c9937f02db91d48164c42383a6af83176331..fb232a32510f77eced30311d02da2fc4a757d73e 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 test_description='"notmuch show"'
 
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 add_email_corpus
 
index 6b42a690fa9002573ef9639167d757987223281b..7faf03d335099d92c6a4d4942441904e019ad4b0 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 test_description="database upgrade"
 
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 dbtarball=database-v1.tar.xz
 
index 5569768c1ec682651afddbab37d5fd8f7aa8850a..f94a660d750838b63d6ab263190bbdfef126831d 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 test_description="database version and feature compatibility"
 
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_begin_subtest "future database versions abort open"
 ${TEST_DIRECTORY}/make-db-version ${MAIL_DIR} 9999 ""
index c99b17ed2fee141a43fb9faca006d3318f20d98e..c280939c54fab4cc83e5aa29a09dbaf0342bdc41 100755 (executable)
@@ -1,17 +1,7 @@
 #!/usr/bin/env bash
 test_description="error reporting for library"
 
-. ./test-lib.sh
-
-backup_database () {
-    rm -rf notmuch-dir-backup
-    cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup
-}
-restore_database () {
-    rm -rf ${MAIL_DIR}/.notmuch
-    cp -pR notmuch-dir-backup ${MAIL_DIR}/.notmuch
-}
-
+. ./test-lib.sh || exit 1
 
 add_email_corpus
 
@@ -35,7 +25,7 @@ Error: Cannot open a database for a NULL path.
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
-test_begin_subtest "Open nonexistent database"
+test_begin_subtest "Open relative path"
 test_C <<'EOF'
 #include <stdio.h>
 #include <notmuch.h>
@@ -49,7 +39,43 @@ EOF
 cat <<'EOF' >EXPECTED
 == stdout ==
 == stderr ==
-Error opening database at ./nonexistent/foo/.notmuch: No such file or directory
+Error: Database path must be absolute.
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "Create database in relative path"
+test_C <<'EOF'
+#include <stdio.h>
+#include <notmuch.h>
+int main (int argc, char** argv)
+{
+    notmuch_database_t *db;
+    notmuch_status_t stat;
+    stat = notmuch_database_create ("./nonexistent/foo", &db);
+}
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+== stderr ==
+Error: Database path must be absolute.
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "Open nonexistent database"
+test_C ${PWD}/nonexistent/foo <<'EOF'
+#include <stdio.h>
+#include <notmuch.h>
+int main (int argc, char** argv)
+{
+    notmuch_database_t *db;
+    notmuch_status_t stat;
+    stat = notmuch_database_open (argv[1], 0, 0);
+}
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+== stderr ==
+Error opening database at CWD/nonexistent/foo/.notmuch: No such file or directory
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
@@ -70,21 +96,21 @@ Error: Cannot create a database for a NULL path.
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
-test_begin_subtest "Create database in non-existant directory"
-test_C <<'EOF'
+test_begin_subtest "Create database in nonexistent directory"
+test_C ${PWD}/nonexistent/foo<<'EOF'
 #include <stdio.h>
 #include <notmuch.h>
 int main (int argc, char** argv)
 {
     notmuch_database_t *db;
     notmuch_status_t stat;
-    stat = notmuch_database_create ("./nonexistent/foo", &db);
+    stat = notmuch_database_create (argv[1], &db);
 }
 EOF
 cat <<'EOF' >EXPECTED
 == stdout ==
 == stderr ==
-Error: Cannot create database at ./nonexistent/foo: No such file or directory.
+Error: Cannot create database at CWD/nonexistent/foo: No such file or directory.
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh
new file mode 100755 (executable)
index 0000000..0936011
--- /dev/null
@@ -0,0 +1,93 @@
+#!/usr/bin/env bash
+test_description="database revision tracking"
+
+. ./test-lib.sh || exit 1
+
+add_email_corpus
+
+test_begin_subtest "notmuch_database_get_revision"
+test_C ${MAIL_DIR} <<'EOF'
+#include <stdio.h>
+#include <string.h>
+#include <notmuch.h>
+int main (int argc, char** argv)
+{
+   notmuch_database_t *db;
+   notmuch_status_t stat;
+   unsigned long revision;
+   const char *uuid;
+
+   unsigned long rev;
+
+   stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
+   if (stat)
+       fputs ("open failed\n", stderr);
+   revision = notmuch_database_get_revision (db, &uuid);
+   printf("%s\t%lu\n", uuid, revision);
+}
+EOF
+notmuch_uuid_sanitize < OUTPUT > CLEAN
+cat <<'EOF' >EXPECTED
+== stdout ==
+UUID   53
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED CLEAN
+
+grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
+
+test_begin_subtest "output of count matches test code"
+notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
+test_expect_equal_file INITIAL_OUTPUT OUTPUT
+
+test_begin_subtest "modification count increases"
+before=$(notmuch count --lastmod '*' | cut -f3)
+notmuch tag +a-random-tag-8743632 '*'
+after=$(notmuch count --lastmod '*' | cut -f3)
+result=$(($before < $after))
+test_expect_equal 1 ${result}
+
+notmuch count --lastmod '*' | cut -f2 > UUID
+
+test_expect_success 'search succeeds with correct uuid' \
+                   "notmuch search --uuid=$(cat UUID) '*'"
+
+test_expect_success 'uuid works as global option ' \
+                   "notmuch --uuid=$(cat UUID) search '*'"
+
+test_expect_code 1 'uuid works as global option II' \
+                   "notmuch --uuid=this-is-no-uuid search '*'"
+
+test_expect_code 1 'search fails with incorrect uuid' \
+                "notmuch search --uuid=this-is-no-uuid '*'"
+
+test_expect_success 'show succeeds with correct uuid' \
+                   "notmuch show --uuid=$(cat UUID) '*'"
+
+test_expect_code 1 'show fails with incorrect uuid' \
+                "notmuch show --uuid=this-is-no-uuid '*'"
+
+test_expect_success 'tag succeeds with correct uuid' \
+                   "notmuch tag --uuid=$(cat UUID) +test '*'"
+
+test_expect_code 1 'tag fails with incorrect uuid' \
+                "notmuch tag --uuid=this-is-no-uuid '*' +test2"
+
+test_begin_subtest 'lastmod:0.. matches everything'
+total=$(notmuch count '*')
+modtotal=$(notmuch count lastmod:0..)
+test_expect_equal "$total" "$modtotal"
+
+test_begin_subtest 'lastmod:1000000.. matches nothing'
+modtotal=$(notmuch count lastmod:1000000..)
+test_expect_equal 0 "$modtotal"
+
+test_begin_subtest 'exclude one message using lastmod'
+lastmod=$(notmuch count --lastmod '*' | cut -f3)
+total=$(notmuch count '*')
+notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org
+subtotal=$(notmuch count lastmod:..$lastmod)
+result=$(($subtotal == $total-1))
+test_expect_equal 1 "$result"
+
+test_done
index b016edb9117108523642b17862b20846f4fbc89c..6322854675fdae93cabbf55ac9a7cb531513b00d 100755 (executable)
@@ -82,7 +82,10 @@ if [ "$skipped" != "0" ]; then
     echo "$skipped $tests skipped."
 fi
 
-if [ $success -gt 0 -a $fixed -eq 0 -a $failed -eq 0 -a $skipped -eq 0 ]
+# Note that we currently do not consider skipped tests as failing the
+# build.
+
+if [ $success -gt 0 -a $fixed -eq 0 -a $failed -eq 0 ]
 then
     exit 0
 else
index 790193d2ee3eed2f5b7edbb4b4e7f3637f6f23d4..d74271d932312d77ea66a02131a753ea4b931762 100644 (file)
@@ -114,6 +114,25 @@ random_utf8_string (void *ctx, size_t char_count)
     return buf;
 }
 
+/* stubs since we cannot link with notmuch.o */
+const notmuch_opt_desc_t notmuch_shared_options[] = {
+       { 0, 0, 0, 0, 0 }
+};
+
+char *notmuch_requested_db_uuid = NULL;
+
+void
+notmuch_process_shared_options (unused (const char *dummy))
+{
+}
+
+int
+notmuch_minimal_options (unused (const char *subcommand),
+                        unused (int argc),
+                        unused (char **argv))
+{
+    return 0;
+}
 
 int
 main (int argc, char **argv)
index f17ddc854c720eb79749f8c4d5428fc5a13ce19b..7454838bfd3125e2de08ad9f5fd9977363900e87 100644 (file)
@@ -3,23 +3,28 @@
 #include <xapian.h>
 #include <notmuch.h>
 
+int main (int argc, char** argv)
+{
+    notmuch_database_t *notmuch;
+    char *message = NULL;
 
-int main() {
-  notmuch_database_t *notmuch;
-  char *message = NULL;
+    if (argc != 3)
+       return 1;
 
-  if (notmuch_database_open_verbose  ("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch, &message))
-      if (message) {
-         fputs (message, stderr);
-         free (message);
-      }
+    if (notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY,
+                                      &notmuch, &message)) {
+       if (message) {
+           fputs (message, stderr);
+           free (message);
+       }
+    }
 
-  try {
-    (void) new Xapian::WritableDatabase("./nonexistent", Xapian::DB_OPEN);
-  } catch (const Xapian::Error &error) {
-    printf("caught %s\n", error.get_msg().c_str());
-    return 0;
-  }
+    try {
+       (void) new Xapian::WritableDatabase (argv[2], Xapian::DB_OPEN);
+    } catch (const Xapian::Error &error) {
+       printf("caught %s\n", error.get_msg().c_str());
+       return 0;
+    }
 
-  return 1;
+    return 1;
 }
index f99ed11162ade498eaef756b9a65774a6a29afec..5eb618c1f51aabffb562d4b2ac9dc6e646b668f7 100644 (file)
@@ -34,13 +34,25 @@ find_notmuch_path ()
     done
 }
 
+backup_database () {
+    test_name=$(basename $0 .sh)
+    rm -rf notmuch-dir-backup."$test_name"
+    cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup."${test_name}"
+}
+
+restore_database () {
+    test_name=$(basename $0 .sh)
+    rm -rf ${MAIL_DIR}/.notmuch
+    cp -pR notmuch-dir-backup."${test_name}" ${MAIL_DIR}/.notmuch
+}
+
 # Test the binaries we have just built.  The tests are kept in
 # test/ subdirectory and are run in 'trash directory' subdirectory.
 TEST_DIRECTORY=$(pwd)
 notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"`
 
 # configure output
-. $notmuch_path/sh.config
+. $notmuch_path/sh.config || exit 1
 
 if test -n "$valgrind"
 then
index 486d1c430adbd714f1d08297612c390b4853e3f3..126911fb385aacb7aa087ab9c7c099419c7641fd 100644 (file)
@@ -96,7 +96,8 @@ _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"
 # test_description='Description of this test...
 # This test checks if command xyzzy does the right thing...
 # '
-# . ./test-lib.sh
+# . ./test-lib.sh || exit 1
+
 [ "x$ORIGINAL_TERM" != "xdumb" ] && (
                TERM=$ORIGINAL_TERM &&
                export TERM &&
@@ -487,7 +488,7 @@ emacs_deliver_message ()
           (message-goto-body)
           (insert \"${body}\")
           $@
-          (message-send-and-exit))"
+          (notmuch-mua-send-and-exit))"
 
     # In case message was sent properly, client waits for confirmation
     # before exiting and resuming control here; therefore making sure
@@ -522,7 +523,7 @@ emacs_fcc_message ()
           (message-goto-body)
           (insert \"${body}\")
           $@
-          (message-send-and-exit))" || return 1
+          (notmuch-mua-send-and-exit))" || return 1
     notmuch new >/dev/null
 }
 
@@ -621,9 +622,9 @@ test_expect_equal_json () {
     # The test suite forces LC_ALL=C, but this causes Python 3 to
     # decode stdin as ASCII.  We need to read JSON in UTF-8, so
     # override Python's stdio encoding defaults.
-    output=$(echo "$1" | PYTHONIOENCODING=utf-8 python -mjson.tool \
+    output=$(echo "$1" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -mjson.tool \
         || echo "$1")
-    expected=$(echo "$2" | PYTHONIOENCODING=utf-8 python -mjson.tool \
+    expected=$(echo "$2" | PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -mjson.tool \
         || echo "$2")
     shift 2
     test_expect_equal "$output" "$expected" "$@"
@@ -719,6 +720,11 @@ notmuch_date_sanitize ()
     sed \
        -e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'
 }
+
+notmuch_uuid_sanitize ()
+{
+    sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'
+}
 # End of notmuch helper functions
 
 # Use test_set_prereq to tell that a particular prerequisite is available.
@@ -1153,14 +1159,13 @@ test_python() {
        export LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib
        export PYTHONPATH=$TEST_DIRECTORY/../bindings/python
 
-       # Some distros (e.g. Arch Linux) ship Python 2.* as /usr/bin/python2,
-       # most others as /usr/bin/python. So first try python2, and fallback to
-       # python if python2 doesn't exist.
-       cmd=python2
-       [[ ${test_missing_external_prereq_[python2]} == t ]] && cmd=python
-
        (echo "import sys; _orig_stdout=sys.stdout; sys.stdout=open('OUTPUT', 'w')"; cat) \
-               | $cmd -
+               | $NOTMUCH_PYTHON -
+}
+
+test_ruby() {
+    export LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib
+    MAIL_DIR=$MAIL_DIR ruby -I $TEST_DIRECTORY/../bindings/ruby> OUTPUT
 }
 
 test_C () {
@@ -1224,14 +1229,14 @@ test_init_ () {
 }
 
 
-. ./test-lib-common.sh
+. ./test-lib-common.sh || exit 1
 
 emacs_generate_script
 
 
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
-cd -P "$test" || error "Cannot setup test environment"
+cd -P "$test" || error "Cannot set up test environment"
 
 if test "$verbose" = "t"
 then
@@ -1320,5 +1325,4 @@ test_declare_external_prereq emacs
 test_declare_external_prereq ${TEST_EMACSCLIENT}
 test_declare_external_prereq gdb
 test_declare_external_prereq gpg
-test_declare_external_prereq python
-test_declare_external_prereq python2
+test_declare_external_prereq ${NOTMUCH_PYTHON}
index 4100c05149f1718896b5ec916111d684979358ce..1723ce665caa73287c4ae5dced5099786626c15b 100755 (executable)
@@ -2,7 +2,7 @@
 
 test_description='the verbosity options of the test framework itself.'
 
-. ./test-lib.sh
+. ./test-lib.sh || exit 1
 
 test_expect_success 'print something in test_expect_success and pass' '
   echo "hello stdout" &&
index a90501ee3e70198e652599e6da841ffe95db8f85..92af937f45ec15eab8ae00d27b287bf6a265134a 100644 (file)
@@ -221,3 +221,37 @@ parse_boolean_term (void *ctx, const char *str,
     errno = err;
     return -1;
 }
+
+int
+strcmp_null (const char *s1, const char *s2)
+{
+    if (s1 && s2)
+       return strcmp (s1, s2);
+    else if (! s1 && ! s2)
+       return 0;
+    else if (s1)
+       return 1;       /* s1 (non-NULL) is greater than s2 (NULL) */
+    else
+       return -1;      /* s1 (NULL) is less than s2 (non-NULL) */
+}
+
+int
+strcase_equal (const void *a, const void *b)
+{
+    return strcasecmp (a, b) == 0;
+}
+
+unsigned int
+strcase_hash (const void *ptr)
+{
+    const char *s = ptr;
+
+    /* This is the djb2 hash. */
+    unsigned int hash = 5381;
+    while (s && *s) {
+       hash = ((hash << 5) + hash) + tolower (*s);
+       s++;
+    }
+
+    return hash;
+}
index e409cb3d2ab154664a24873cfe50e3ac34a23513..87917b8fd279de6e07f2fb919429fb50512a85b4 100644 (file)
@@ -64,6 +64,17 @@ int
 parse_boolean_term (void *ctx, const char *str,
                    char **prefix_out, char **term_out);
 
+/* strcmp that handles NULL strings; in strcmp terms a NULL string is
+ * considered to be less than a non-NULL string.
+ */
+int strcmp_null (const char *s1, const char *s2);
+
+/* GLib GEqualFunc compatible strcasecmp wrapper */
+int strcase_equal (const void *a, const void *b);
+
+/* GLib GHashFunc compatible case insensitive hash function */
+unsigned int strcase_hash (const void *ptr);
+
 #ifdef __cplusplus
 }
 #endif