From: David Bremner Date: Tue, 4 Jul 2017 00:35:05 +0000 (-0300) Subject: Merge branch 'release' X-Git-Tag: 0.25_rc0~44 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=0aba694c11846f76cfa64470d10a50cec8e43bd5;hp=1970981bf1b6b27a4c9b120f65d960053c15198e Merge branch 'release' --- diff --git a/.gitignore b/.gitignore index 296030c7..7b283fb3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ tags *cscope* .deps /notmuch -notmuch.sym notmuch-shared libnotmuch.so* libnotmuch*.dylib diff --git a/Makefile b/Makefile index 0ef57fa9..d2010fe4 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,35 @@ include Makefile.config global_deps = Makefile Makefile.config Makefile.local \ $(subdirs:%=%/Makefile) $(subdirs:%=%/Makefile.local) +INCLUDE_MORE := yes +ifneq ($(filter clean distclean dataclean, $(word 1, $(MAKECMDGOALS))),) +CLEAN_GOAL := $(word 1, $(MAKECMDGOALS)) + +# If there are more goals following CLEAN_GOAL, run $(MAKE)s in parts. +ifneq ($(word 2, $(MAKECMDGOALS)),) +INCLUDE_MORE := no +FOLLOWING_GOALS := $(wordlist 2, 99, $(MAKECMDGOALS)) + +.PHONY: $(FOLLOWING_GOALS) make_in_parts +$(FOLLOWING_GOALS): + @true +$(CLEAN_GOAL): make_in_parts +make_in_parts: + $(MAKE) $(CLEAN_GOAL) + $(MAKE) $(FOLLOWING_GOALS) configure_options="$(configure_options)" +endif + +else +CLEAN_GOAL := +endif + +# Potentially speedup make clean, distclean and dataclean ; avoid +# re-creating Makefile.config if it exists but configure is newer. +ifneq ($(CLEAN_GOAL),) +Makefile.config: | $(srcdir)/configure +else Makefile.config: $(srcdir)/configure +endif ifeq ($(configure_options),) @echo "" @echo "Note: Calling ./configure with no command-line arguments. This is often fine," @@ -33,9 +61,11 @@ ifeq ($(configure_options),) endif $(srcdir)/configure $(configure_options) +ifeq ($(INCLUDE_MORE),yes) # runtime variable definitions available in all subdirs include $(srcdir)/Makefile.global # Finally, include all of the Makefile.local fragments where all the # real work is done. include $(subdirs:%=%/Makefile.local) Makefile.local +endif diff --git a/Makefile.global b/Makefile.global index 7a78e9b5..cae4c7d1 100644 --- a/Makefile.global +++ b/Makefile.global @@ -52,7 +52,7 @@ PV_FILE=bindings/python/notmuch/version.py STD_CFLAGS := -std=gnu99 FINAL_CFLAGS = -DNOTMUCH_VERSION=$(VERSION) $(CPPFLAGS) $(STD_CFLAGS) $(CFLAGS) $(WARN_CFLAGS) $(extra_cflags) $(CONFIGURE_CFLAGS) FINAL_CXXFLAGS = $(CPPFLAGS) $(CXXFLAGS) $(WARN_CXXFLAGS) $(extra_cflags) $(extra_cxxflags) $(CONFIGURE_CXXFLAGS) -FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch +FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lnotmuch_util -Llib -lnotmuch ifeq ($(LIBDIR_IN_LDCONFIG),0) FINAL_NOTMUCH_LDFLAGS += $(RPATH_LDFLAGS) endif diff --git a/Makefile.local b/Makefile.local index e75b6eae..6bc78ef8 100644 --- a/Makefile.local +++ b/Makefile.local @@ -31,7 +31,9 @@ $(TAR_FILE): fi ; \ git archive --format=tar --prefix=$(PACKAGE)-$(VERSION)/ $$ref > $(TAR_FILE).tmp echo $(VERSION) > version.tmp - tar --append -f $(TAR_FILE).tmp --transform s_^_$(PACKAGE)-$(VERSION)/_ --transform 's_.tmp$$__' version.tmp + tar --owner root --group root --append -f $(TAR_FILE).tmp \ + --transform s_^_$(PACKAGE)-$(VERSION)/_ \ + --transform 's_.tmp$$__' version.tmp rm version.tmp gzip < $(TAR_FILE).tmp > $(TAR_FILE) @echo "Source is ready for release in $(TAR_FILE)" @@ -210,6 +212,7 @@ dataclean: distclean rm -rf $(DATACLEAN) notmuch_client_srcs = \ + $(notmuch_compat_srcs) \ command-line-arguments.c\ debugger.c \ status.c \ @@ -241,7 +244,7 @@ notmuch_client_modules = $(notmuch_client_srcs:.c=.o) notmuch.o: version.stamp -notmuch: $(notmuch_client_modules) lib/libnotmuch.a util/libutil.a parse-time-string/libparse-time-string.a +notmuch: $(notmuch_client_modules) lib/libnotmuch.a util/libnotmuch_util.a parse-time-string/libparse-time-string.a $(call quiet,CXX $(CFLAGS)) $^ $(FINAL_LIBNOTMUCH_LDFLAGS) -o $@ notmuch-shared: $(notmuch_client_modules) lib/$(LINKER_NAME) diff --git a/bindings/Makefile.local b/bindings/Makefile.local index 11d11d4b..17b561ca 100644 --- a/bindings/Makefile.local +++ b/bindings/Makefile.local @@ -8,6 +8,7 @@ ifeq ($(HAVE_RUBY_DEV),1) cd $(dir)/ruby && \ EXTRA_LDFLAGS="$(NO_UNDEFINED_LDFLAGS)" \ LIBNOTMUCH="../../lib/$(LINKER_NAME)" \ + NOTMUCH_SRCDIR='$(NOTMUCH_SRCDIR)' \ ruby extconf.rb --vendor $(MAKE) -C $(dir)/ruby endif diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py index 67fb1c41..8f918069 100644 --- a/bindings/python/notmuch/database.py +++ b/bindings/python/notmuch/database.py @@ -86,6 +86,11 @@ class Database(object): _get_version.argtypes = [NotmuchDatabaseP] _get_version.restype = c_uint + """notmuch_database_get_revision""" + _get_revision = nmlib.notmuch_database_get_revision + _get_revision.argtypes = [NotmuchDatabaseP, POINTER(c_char_p)] + _get_revision.restype = c_uint + """notmuch_database_open""" _open = nmlib.notmuch_database_open _open.argtypes = [c_char_p, c_uint, POINTER(NotmuchDatabaseP)] @@ -261,6 +266,17 @@ class Database(object): self._assert_db_is_initialized() return Database._get_version(self._db) + def get_revision (self): + """Returns the committed database revison and UUID + + :returns: (revison, uuid) The database revision as a positive integer + and the UUID of the database. + """ + self._assert_db_is_initialized() + uuid = c_char_p () + revision = Database._get_revision(self._db, byref (uuid)) + return (revision, uuid.value.decode ('utf-8')) + _needs_upgrade = nmlib.notmuch_database_needs_upgrade _needs_upgrade.argtypes = [NotmuchDatabaseP] _needs_upgrade.restype = bool diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py index a0f4f64b..06c7b11b 100644 --- a/bindings/python/notmuch/query.py +++ b/bindings/python/notmuch/query.py @@ -134,10 +134,10 @@ class Query(object): self._assert_query_is_initialized() self._exclude_tag(self._query, _str(tagname)) - """notmuch_query_search_threads_st""" - _search_threads_st = nmlib.notmuch_query_search_threads_st - _search_threads_st.argtypes = [NotmuchQueryP, POINTER(NotmuchThreadsP)] - _search_threads_st.restype = c_uint + """notmuch_query_search_threads""" + _search_threads = nmlib.notmuch_query_search_threads + _search_threads.argtypes = [NotmuchQueryP, POINTER(NotmuchThreadsP)] + _search_threads.restype = c_uint def search_threads(self): """Execute a query for threads @@ -155,7 +155,7 @@ class Query(object): """ self._assert_query_is_initialized() threads_p = NotmuchThreadsP() # == NULL - status = Query._search_threads_st(self._query, byref(threads_p)) + status = Query._search_threads(self._query, byref(threads_p)) if status != 0: raise NotmuchError(status) @@ -164,9 +164,9 @@ class Query(object): return Threads(threads_p, self) """notmuch_query_search_messages_st""" - _search_messages_st = nmlib.notmuch_query_search_messages_st - _search_messages_st.argtypes = [NotmuchQueryP, POINTER(NotmuchMessagesP)] - _search_messages_st.restype = c_uint + _search_messages = nmlib.notmuch_query_search_messages + _search_messages.argtypes = [NotmuchQueryP, POINTER(NotmuchMessagesP)] + _search_messages.restype = c_uint def search_messages(self): """Filter messages according to the query and return @@ -177,7 +177,7 @@ class Query(object): """ self._assert_query_is_initialized() msgs_p = NotmuchMessagesP() # == NULL - status = Query._search_messages_st(self._query, byref(msgs_p)) + status = Query._search_messages(self._query, byref(msgs_p)) if status != 0: raise NotmuchError(status) @@ -185,7 +185,7 @@ class Query(object): raise NullPointerError return Messages(msgs_p, self) - _count_messages = nmlib.notmuch_query_count_messages_st + _count_messages = nmlib.notmuch_query_count_messages _count_messages.argtypes = [NotmuchQueryP, POINTER(c_uint)] _count_messages.restype = c_uint @@ -204,7 +204,7 @@ class Query(object): raise NotmuchError(status) return count.value - _count_threads = nmlib.notmuch_query_count_threads_st + _count_threads = nmlib.notmuch_query_count_threads _count_threads.argtypes = [NotmuchQueryP, POINTER(c_uint)] _count_threads.restype = c_uint diff --git a/bindings/python/notmuch/version.py b/bindings/python/notmuch/version.py index 49bca347..6101902b 100644 --- a/bindings/python/notmuch/version.py +++ b/bindings/python/notmuch/version.py @@ -1,3 +1,3 @@ # this file should be kept in sync with ../../../version __VERSION__ = '0.24.2' -SOVERSION = '4' +SOVERSION = '5' diff --git a/bindings/ruby/extconf.rb b/bindings/ruby/extconf.rb index ddaa6841..161de5a2 100644 --- a/bindings/ruby/extconf.rb +++ b/bindings/ruby/extconf.rb @@ -5,7 +5,7 @@ require 'mkmf' -dir = File.join('..', '..', 'lib') +dir = File.join(ENV['NOTMUCH_SRCDIR'], 'lib') # includes $INCFLAGS = "-I#{dir} #{$INCFLAGS}" diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c index ce66926c..8b46d700 100644 --- a/bindings/ruby/query.c +++ b/bindings/ruby/query.c @@ -138,7 +138,7 @@ notmuch_rb_query_search_threads (VALUE self) Data_Get_Notmuch_Query (self, query); - status = notmuch_query_search_threads_st (query, &threads); + status = notmuch_query_search_threads (query, &threads); if (status) notmuch_rb_status_raise (status); @@ -159,7 +159,7 @@ notmuch_rb_query_search_messages (VALUE self) Data_Get_Notmuch_Query (self, query); - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (status) notmuch_rb_status_raise (status); @@ -180,7 +180,7 @@ notmuch_rb_query_count_messages (VALUE self) Data_Get_Notmuch_Query (self, query); - status = notmuch_query_count_messages_st (query, &count); + status = notmuch_query_count_messages (query, &count); if (status) notmuch_rb_status_raise (status); @@ -201,7 +201,7 @@ notmuch_rb_query_count_threads (VALUE self) Data_Get_Notmuch_Query (self, query); - status = notmuch_query_count_threads_st (query, &count); + status = notmuch_query_count_threads (query, &count); if (status) notmuch_rb_status_raise (status); diff --git a/compat/have_timegm.c b/compat/have_timegm.c index b62b7937..483fc3b6 100644 --- a/compat/have_timegm.c +++ b/compat/have_timegm.c @@ -1,5 +1,4 @@ #include -#include "compat.h" int main() { diff --git a/configure b/configure index fa77eb8f..c5e2ffed 100755 --- a/configure +++ b/configure @@ -19,7 +19,12 @@ To work around this problem you may try to execute: # Store original IFS value so it can be changed (and restored) in many places. readonly DEFAULT_IFS="$IFS" +# The top-level directory for the source. This ./configure and all Makefiles +# are good with ${srcdir} usually being relative. Some components (e.g. tests) +# are executed in subdirectories and for those it is simpler to use +# ${NOTMUCH_SRCDIR} which holds absolute path to the source. srcdir=$(dirname "$0") +NOTMUCH_SRCDIR=$(cd "$srcdir" && pwd) subdirs="util compat lib parse-time-string completion doc emacs" subdirs="${subdirs} performance-test test test/test-databases" @@ -42,6 +47,12 @@ if [ "$srcdir" != "." ]; then # Emacs only likes to generate compiled files next to the .el files # by default so copy these as well (which is not ideal). cp -a "$srcdir"/emacs/*.el emacs + + # We were not able to create fully working Makefile using ruby mkmf.rb + # so ruby bindings source files are copied as well (ditto -- not ideal). + mkdir bindings/ruby + cp -a "$srcdir"/bindings/ruby/*.[ch] bindings/ruby + cp -a "$srcdir"/bindings/ruby/extconf.rb bindings/ruby fi # Set several defaults (optionally specified by the user in @@ -132,7 +143,7 @@ Fine tuning of some installation directories is available: --sysconfdir=DIR Read-only single-machine data [PREFIX/etc] --emacslispdir=DIR Emacs code [PREFIX/share/emacs/site-lisp] --emacsetcdir=DIR Emacs miscellaneous files [PREFIX/share/emacs/site-lisp] - --bashcompletiondir=DIR Bash completions files [SYSCONFDIR/bash_completion.d] + --bashcompletiondir=DIR Bash completions files [PREFIX/share/bash-completion/completions] --zshcompletiondir=DIR Zsh completions files [PREFIX/share/zsh/functions/Completion/Unix] Some features can be disabled (--with-feature=no is equivalent to @@ -311,22 +322,29 @@ 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 +test_cmdline="${CC} ${CFLAGS} ${CPPFLAGS} minimal.c ${LDFLAGS} -o minimal" +if ${test_cmdline} > /dev/null 2>&1 then printf "OK.\n" else printf "Fail.\n" errors=$((errors + 1)) + printf Executed:; printf ' %s' ${test_cmdline}; echo + ${test_cmdline} fi printf "Sanity checking C++ compilation environment... " -if ${CXX} ${CXXFLAGS_for_sh} ${CPPFLAGS} minimal.c ${LDFLAGS} -o minimal > /dev/null 2>&1 +test_cmdline="${CXX} ${CXXFLAGS_for_sh} ${CPPFLAGS} minimal.c ${LDFLAGS} -o minimal" +if ${test_cmdline} > /dev/null 2>&1 then printf "OK.\n" else printf "Fail.\n" errors=$((errors + 1)) + printf Executed:; printf ' %s' ${test_cmdline}; echo + ${test_cmdline} fi +unset test_cmdline if [ $errors -gt 0 ]; then cat < /dev/null 2>&1 && \ - ./_libversion > _libversion.sh && . ./_libversion.sh +if ${CC} ${CFLAGS} -I"$srcdir" _libversion.c -o _libversion > /dev/null 2>&1 \ + && ./_libversion > _libversion.sh && . ./_libversion.sh then printf "OK.\n" else @@ -466,11 +484,18 @@ fi GMIME_MINVER=2.6.7 printf "Checking for GMime development files... " -if pkg-config --exists "gmime-2.6 >= $GMIME_MINVER"; then - printf "Yes.\n" +if pkg-config --exists "gmime-3.0"; then + printf "Yes (3.0).\n" + have_gmime=1 + gmime_cflags=$(pkg-config --cflags gmime-3.0) + gmime_ldflags=$(pkg-config --libs gmime-3.0) + gmime_major=3 +elif pkg-config --exists "gmime-2.6 >= $GMIME_MINVER"; then + printf "Yes (2.6).\n" have_gmime=1 gmime_cflags=$(pkg-config --cflags gmime-2.6) gmime_ldflags=$(pkg-config --libs gmime-2.6) + gmime_major=2 else have_gmime=0 printf "No.\n" @@ -493,8 +518,7 @@ else fi if ! pkg-config --exists zlib; then - ${CC} ${zlib_cflags} -o compat/gen_zlib_pc \ - "$srcdir"/compat/gen_zlib_pc.c ${zlib_ldflags} > /dev/null 2>&1 && + ${CC} -o compat/gen_zlib_pc "$srcdir"/compat/gen_zlib_pc.c >/dev/null 2>&1 && compat/gen_zlib_pc > compat/zlib.pc && PKG_CONFIG_PATH="$PKG_CONFIG_PATH":compat && export PKG_CONFIG_PATH @@ -914,6 +938,7 @@ cat > Makefile.config < sh.config < Sun, 05 Mar 2017 19:32:08 -0400 +notmuch (0.23.7-3) unstable; urgency=medium + + * Cherry pick fixes to dump header from 0.24.1 + + -- David Bremner Sat, 01 Apr 2017 21:09:36 -0300 + notmuch (0.23.7-2) unstable; urgency=medium * Cherry pick 06adc276, fix use after free in libnotmuch4 diff --git a/debian/control b/debian/control index e71a6716..3811d825 100644 --- a/debian/control +++ b/debian/control @@ -34,7 +34,7 @@ Vcs-Browser: https://git.notmuchmail.org/git/notmuch Package: notmuch Architecture: any -Depends: libnotmuch4 (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Depends: libnotmuch5 (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} Recommends: notmuch-emacs | notmuch-vim | notmuch-mutt | alot, gnupg-agent, gpgsm Description: thread-based email index, search and tagging Notmuch is a system for indexing, searching, reading, and tagging @@ -44,7 +44,7 @@ Description: thread-based email index, search and tagging . This package contains the notmuch command-line interface -Package: libnotmuch4 +Package: libnotmuch5 Section: libs Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} @@ -61,7 +61,7 @@ Description: thread-based email index, search and tagging (runtime) Package: libnotmuch-dev Section: libdevel Architecture: any -Depends: ${misc:Depends}, libnotmuch4 (= ${binary:Version}) +Depends: ${misc:Depends}, libnotmuch5 (= ${binary:Version}) Description: thread-based email index, search and tagging (development) Notmuch is a system for indexing, searching, reading, and tagging large collections of email messages in maildir or mh format. It uses @@ -74,7 +74,7 @@ Description: thread-based email index, search and tagging (development) Package: python-notmuch Architecture: all Section: python -Depends: ${misc:Depends}, ${python:Depends}, libnotmuch4 (>= ${source:Version}) +Depends: ${misc:Depends}, ${python:Depends}, libnotmuch5 (>= ${source:Version}) Description: python interface to the notmuch mail search and index library Notmuch is a system for indexing, searching, reading, and tagging large collections of email messages in maildir or mh format. It uses @@ -87,7 +87,7 @@ Description: python interface to the notmuch mail search and index library Package: python3-notmuch Architecture: all Section: python -Depends: ${misc:Depends}, ${python3:Depends}, libnotmuch4 (>= ${source:Version}) +Depends: ${misc:Depends}, ${python3:Depends}, libnotmuch5 (>= ${source:Version}) Description: Python 3 interface to the notmuch mail search and index library Notmuch is a system for indexing, searching, reading, and tagging large collections of email messages in maildir or mh format. It uses @@ -167,7 +167,7 @@ Package: notmuch-dbg Architecture: any Section: debug Priority: extra -Depends: ${shlibs:Depends}, ${misc:Depends}, libnotmuch4 (= ${binary:Version}) +Depends: ${shlibs:Depends}, ${misc:Depends}, libnotmuch5 (= ${binary:Version}) Description: thread-based email index, search and tagging - debugging symbols Notmuch is a system for indexing, searching, reading, and tagging large collections of email messages in maildir or mh format. It uses diff --git a/debian/libnotmuch4.install b/debian/libnotmuch4.install deleted file mode 100644 index a513b475..00000000 --- a/debian/libnotmuch4.install +++ /dev/null @@ -1 +0,0 @@ -usr/lib/*/libnotmuch.so.* diff --git a/debian/libnotmuch4.symbols b/debian/libnotmuch4.symbols deleted file mode 100644 index 9bfec1a1..00000000 --- a/debian/libnotmuch4.symbols +++ /dev/null @@ -1,126 +0,0 @@ -libnotmuch.so.4 libnotmuch4 #MINVER# - notmuch_built_with@Base 0.23~rc0 - notmuch_config_list_destroy@Base 0.23~rc0 - notmuch_config_list_key@Base 0.23~rc0 - notmuch_config_list_move_to_next@Base 0.23~rc0 - notmuch_config_list_valid@Base 0.23~rc0 - notmuch_config_list_value@Base 0.23~rc0 - notmuch_database_add_message@Base 0.3 - notmuch_database_begin_atomic@Base 0.9~rc1 - notmuch_database_close@Base 0.13~rc1 - notmuch_database_compact@Base 0.17~rc1 - notmuch_database_create@Base 0.3 - notmuch_database_create_verbose@Base 0.20~rc1 - notmuch_database_destroy@Base 0.13~rc1 - notmuch_database_end_atomic@Base 0.9~rc1 - notmuch_database_find_message@Base 0.9~rc2 - notmuch_database_find_message_by_filename@Base 0.9~rc2 - notmuch_database_get_all_tags@Base 0.3 - notmuch_database_get_config@Base 0.23~rc0 - notmuch_database_get_config_list@Base 0.23~rc0 - notmuch_database_get_directory@Base 0.3 - notmuch_database_get_path@Base 0.3 - notmuch_database_get_revision@Base 0.21~rc1 - notmuch_database_get_version@Base 0.3 - notmuch_database_needs_upgrade@Base 0.3 - notmuch_database_open@Base 0.3 - notmuch_database_open_verbose@Base 0.20~rc1 - notmuch_database_remove_message@Base 0.3 - notmuch_database_set_config@Base 0.23~rc0 - notmuch_database_status_string@Base 0.20~rc1 - notmuch_database_upgrade@Base 0.3 - notmuch_directory_delete@Base 0.21~rc1 - notmuch_directory_destroy@Base 0.3 - notmuch_directory_get_child_directories@Base 0.3 - notmuch_directory_get_child_files@Base 0.3 - notmuch_directory_get_mtime@Base 0.3 - notmuch_directory_set_mtime@Base 0.3 - notmuch_filenames_destroy@Base 0.3 - notmuch_filenames_get@Base 0.3 - notmuch_filenames_move_to_next@Base 0.3 - notmuch_filenames_valid@Base 0.3 - notmuch_message_add_property@Base 0.23~rc0 - notmuch_message_add_tag@Base 0.3 - notmuch_message_destroy@Base 0.3 - notmuch_message_freeze@Base 0.3 - notmuch_message_get_date@Base 0.3 - notmuch_message_get_filename@Base 0.3 - notmuch_message_get_filenames@Base 0.5 - notmuch_message_get_flag@Base 0.3 - notmuch_message_get_header@Base 0.3 - notmuch_message_get_message_id@Base 0.3 - notmuch_message_get_properties@Base 0.23~rc0 - notmuch_message_get_property@Base 0.23~rc0 - notmuch_message_get_replies@Base 0.3 - notmuch_message_get_tags@Base 0.3 - notmuch_message_get_thread_id@Base 0.3 - notmuch_message_maildir_flags_to_tags@Base 0.5 - notmuch_message_properties_destroy@Base 0.23~rc0 - notmuch_message_properties_key@Base 0.23~rc0 - notmuch_message_properties_move_to_next@Base 0.23~rc0 - notmuch_message_properties_valid@Base 0.23~rc0 - notmuch_message_properties_value@Base 0.23~rc0 - notmuch_message_remove_all_properties@Base 0.23~rc0 - notmuch_message_remove_all_tags@Base 0.3 - notmuch_message_remove_property@Base 0.23~rc0 - notmuch_message_remove_tag@Base 0.3 - notmuch_message_set_flag@Base 0.3 - notmuch_message_tags_to_maildir_flags@Base 0.5 - notmuch_message_thaw@Base 0.3 - notmuch_messages_collect_tags@Base 0.3 - notmuch_messages_destroy@Base 0.3 - notmuch_messages_get@Base 0.3 - notmuch_messages_move_to_next@Base 0.3 - notmuch_messages_valid@Base 0.3 - notmuch_query_add_tag_exclude@Base 0.12~rc1 - notmuch_query_count_messages@Base 0.3 - notmuch_query_count_messages_st@Base 0.21~rc1 - notmuch_query_count_threads@Base 0.10~rc1 - notmuch_query_count_threads_st@Base 0.21~rc1 - notmuch_query_create@Base 0.3 - notmuch_query_destroy@Base 0.3 - notmuch_query_get_database@Base 0.21~rc1 - notmuch_query_get_query_string@Base 0.4 - notmuch_query_get_sort@Base 0.4 - notmuch_query_search_messages@Base 0.3 - notmuch_query_search_messages_st@Base 0.20~rc1 - notmuch_query_search_threads@Base 0.3 - notmuch_query_search_threads_st@Base 0.20~rc1 - notmuch_query_set_omit_excluded@Base 0.13~rc1 - notmuch_query_set_sort@Base 0.3 - notmuch_status_to_string@Base 0.3 - notmuch_tags_destroy@Base 0.3 - notmuch_tags_get@Base 0.3 - notmuch_tags_move_to_next@Base 0.3 - notmuch_tags_valid@Base 0.3 - notmuch_thread_destroy@Base 0.3 - notmuch_thread_get_authors@Base 0.3 - notmuch_thread_get_matched_messages@Base 0.3 - notmuch_thread_get_messages@Base 0.16 - notmuch_thread_get_newest_date@Base 0.3 - notmuch_thread_get_oldest_date@Base 0.3 - notmuch_thread_get_subject@Base 0.3 - notmuch_thread_get_tags@Base 0.3 - notmuch_thread_get_thread_id@Base 0.3 - notmuch_thread_get_toplevel_messages@Base 0.3 - notmuch_thread_get_total_messages@Base 0.3 - notmuch_threads_destroy@Base 0.3 - notmuch_threads_get@Base 0.3 - notmuch_threads_move_to_next@Base 0.3 - notmuch_threads_valid@Base 0.3 - (c++)"typeinfo for Xapian::LogicError@Base" 0.6.1 - (c++)"typeinfo for Xapian::RuntimeError@Base" 0.6.1 - (c++)"typeinfo for Xapian::DocNotFoundError@Base" 0.6.1 - (c++)"typeinfo for Xapian::InvalidArgumentError@Base" 0.6.1 - (c++)"typeinfo for Xapian::Error@Base" 0.6.1 - (c++)"typeinfo for Xapian::DatabaseError@Base" 0.24~rc0 - (c++)"typeinfo for Xapian::DatabaseModifiedError@Base" 0.24~rc0 - (c++|optional=present with Xapian 1.4)"typeinfo for Xapian::QueryParserError@Base" 0.23~rc0 - (c++)"typeinfo name for Xapian::LogicError@Base" 0.6.1 - (c++)"typeinfo name for Xapian::RuntimeError@Base" 0.6.1 - (c++)"typeinfo name for Xapian::DocNotFoundError@Base" 0.6.1 - (c++)"typeinfo name for Xapian::InvalidArgumentError@Base" 0.6.1 - (c++)"typeinfo name for Xapian::Error@Base" 0.6.1 - (c++)"typeinfo name for Xapian::DatabaseError@Base" 0.24~rc0 - (c++)"typeinfo name for Xapian::DatabaseModifiedError@Base" 0.24~rc0 - (c++|optional=present with Xapian 1.4)"typeinfo name for Xapian::QueryParserError@Base" 0.23~rc0 diff --git a/debian/libnotmuch5.install b/debian/libnotmuch5.install new file mode 100644 index 00000000..a513b475 --- /dev/null +++ b/debian/libnotmuch5.install @@ -0,0 +1 @@ +usr/lib/*/libnotmuch.so.* diff --git a/debian/libnotmuch5.symbols b/debian/libnotmuch5.symbols new file mode 100644 index 00000000..9f3323ff --- /dev/null +++ b/debian/libnotmuch5.symbols @@ -0,0 +1,126 @@ +libnotmuch.so.5 libnotmuch5 #MINVER# + notmuch_built_with@Base 0.23~rc0 + notmuch_config_list_destroy@Base 0.23~rc0 + notmuch_config_list_key@Base 0.23~rc0 + notmuch_config_list_move_to_next@Base 0.23~rc0 + notmuch_config_list_valid@Base 0.23~rc0 + notmuch_config_list_value@Base 0.23~rc0 + notmuch_database_add_message@Base 0.3 + notmuch_database_begin_atomic@Base 0.9~rc1 + notmuch_database_close@Base 0.13~rc1 + notmuch_database_compact@Base 0.17~rc1 + notmuch_database_create@Base 0.3 + notmuch_database_create_verbose@Base 0.20~rc1 + notmuch_database_destroy@Base 0.13~rc1 + notmuch_database_end_atomic@Base 0.9~rc1 + notmuch_database_find_message@Base 0.9~rc2 + notmuch_database_find_message_by_filename@Base 0.9~rc2 + notmuch_database_get_all_tags@Base 0.3 + notmuch_database_get_config@Base 0.23~rc0 + notmuch_database_get_config_list@Base 0.23~rc0 + notmuch_database_get_directory@Base 0.3 + notmuch_database_get_path@Base 0.3 + notmuch_database_get_revision@Base 0.21~rc1 + notmuch_database_get_version@Base 0.3 + notmuch_database_needs_upgrade@Base 0.3 + notmuch_database_open@Base 0.3 + notmuch_database_open_verbose@Base 0.20~rc1 + notmuch_database_remove_message@Base 0.3 + notmuch_database_set_config@Base 0.23~rc0 + notmuch_database_status_string@Base 0.20~rc1 + notmuch_database_upgrade@Base 0.3 + notmuch_directory_delete@Base 0.21~rc1 + notmuch_directory_destroy@Base 0.3 + notmuch_directory_get_child_directories@Base 0.3 + notmuch_directory_get_child_files@Base 0.3 + notmuch_directory_get_mtime@Base 0.3 + notmuch_directory_set_mtime@Base 0.3 + notmuch_filenames_destroy@Base 0.3 + notmuch_filenames_get@Base 0.3 + notmuch_filenames_move_to_next@Base 0.3 + notmuch_filenames_valid@Base 0.3 + notmuch_message_add_property@Base 0.23~rc0 + notmuch_message_add_tag@Base 0.3 + notmuch_message_destroy@Base 0.3 + notmuch_message_freeze@Base 0.3 + notmuch_message_get_date@Base 0.3 + notmuch_message_get_filename@Base 0.3 + notmuch_message_get_filenames@Base 0.5 + notmuch_message_get_flag@Base 0.3 + notmuch_message_get_header@Base 0.3 + notmuch_message_get_message_id@Base 0.3 + notmuch_message_get_properties@Base 0.23~rc0 + notmuch_message_get_property@Base 0.23~rc0 + notmuch_message_get_replies@Base 0.3 + notmuch_message_get_tags@Base 0.3 + notmuch_message_get_thread_id@Base 0.3 + notmuch_message_maildir_flags_to_tags@Base 0.5 + notmuch_message_properties_destroy@Base 0.23~rc0 + notmuch_message_properties_key@Base 0.23~rc0 + notmuch_message_properties_move_to_next@Base 0.23~rc0 + notmuch_message_properties_valid@Base 0.23~rc0 + notmuch_message_properties_value@Base 0.23~rc0 + notmuch_message_remove_all_properties@Base 0.23~rc0 + notmuch_message_remove_all_tags@Base 0.3 + notmuch_message_remove_property@Base 0.23~rc0 + notmuch_message_remove_tag@Base 0.3 + notmuch_message_set_flag@Base 0.3 + notmuch_message_tags_to_maildir_flags@Base 0.5 + notmuch_message_thaw@Base 0.3 + notmuch_messages_collect_tags@Base 0.3 + notmuch_messages_destroy@Base 0.3 + notmuch_messages_get@Base 0.3 + notmuch_messages_move_to_next@Base 0.3 + notmuch_messages_valid@Base 0.3 + notmuch_query_add_tag_exclude@Base 0.12~rc1 + notmuch_query_count_messages@Base 0.3 + notmuch_query_count_messages_st@Base 0.21~rc1 + notmuch_query_count_threads@Base 0.10~rc1 + notmuch_query_count_threads_st@Base 0.21~rc1 + notmuch_query_create@Base 0.3 + notmuch_query_destroy@Base 0.3 + notmuch_query_get_database@Base 0.21~rc1 + notmuch_query_get_query_string@Base 0.4 + notmuch_query_get_sort@Base 0.4 + notmuch_query_search_messages@Base 0.3 + notmuch_query_search_messages_st@Base 0.20~rc1 + notmuch_query_search_threads@Base 0.3 + notmuch_query_search_threads_st@Base 0.20~rc1 + notmuch_query_set_omit_excluded@Base 0.13~rc1 + notmuch_query_set_sort@Base 0.3 + notmuch_status_to_string@Base 0.3 + notmuch_tags_destroy@Base 0.3 + notmuch_tags_get@Base 0.3 + notmuch_tags_move_to_next@Base 0.3 + notmuch_tags_valid@Base 0.3 + notmuch_thread_destroy@Base 0.3 + notmuch_thread_get_authors@Base 0.3 + notmuch_thread_get_matched_messages@Base 0.3 + notmuch_thread_get_messages@Base 0.16 + notmuch_thread_get_newest_date@Base 0.3 + notmuch_thread_get_oldest_date@Base 0.3 + notmuch_thread_get_subject@Base 0.3 + notmuch_thread_get_tags@Base 0.3 + notmuch_thread_get_thread_id@Base 0.3 + notmuch_thread_get_toplevel_messages@Base 0.3 + notmuch_thread_get_total_messages@Base 0.3 + notmuch_threads_destroy@Base 0.3 + notmuch_threads_get@Base 0.3 + notmuch_threads_move_to_next@Base 0.3 + notmuch_threads_valid@Base 0.3 + (c++)"typeinfo for Xapian::LogicError@Base" 0.6.1 + (c++)"typeinfo for Xapian::RuntimeError@Base" 0.6.1 + (c++)"typeinfo for Xapian::DocNotFoundError@Base" 0.6.1 + (c++)"typeinfo for Xapian::InvalidArgumentError@Base" 0.6.1 + (c++)"typeinfo for Xapian::Error@Base" 0.6.1 + (c++)"typeinfo for Xapian::DatabaseError@Base" 0.24~rc0 + (c++)"typeinfo for Xapian::DatabaseModifiedError@Base" 0.24~rc0 + (c++|optional=present with Xapian 1.4)"typeinfo for Xapian::QueryParserError@Base" 0.23~rc0 + (c++)"typeinfo name for Xapian::LogicError@Base" 0.6.1 + (c++)"typeinfo name for Xapian::RuntimeError@Base" 0.6.1 + (c++)"typeinfo name for Xapian::DocNotFoundError@Base" 0.6.1 + (c++)"typeinfo name for Xapian::InvalidArgumentError@Base" 0.6.1 + (c++)"typeinfo name for Xapian::Error@Base" 0.6.1 + (c++)"typeinfo name for Xapian::DatabaseError@Base" 0.24~rc0 + (c++)"typeinfo name for Xapian::DatabaseModifiedError@Base" 0.24~rc0 + (c++|optional=present with Xapian 1.4)"typeinfo name for Xapian::QueryParserError@Base" 0.23~rc0 diff --git a/debian/notmuch.install b/debian/notmuch.install index 86e891d4..31b9a37e 100644 --- a/debian/notmuch.install +++ b/debian/notmuch.install @@ -1,3 +1,3 @@ usr/bin usr/share/man -etc/bash_completion.d +usr/share/bash-completion diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el index 68a7e9f3..0af727ef 100644 --- a/emacs/notmuch-crypto.el +++ b/emacs/notmuch-crypto.el @@ -21,6 +21,7 @@ ;;; Code: +(require 'epg) (require 'notmuch-lib) (defcustom notmuch-crypto-process-mime nil @@ -140,7 +141,7 @@ mode." (with-selected-window window (with-current-buffer buffer (goto-char (point-max)) - (call-process "gpg" nil t t "--list-keys" fingerprint)) + (call-process epg-gpg-program nil t t "--list-keys" fingerprint)) (recenter -1)))) (defun notmuch-crypto-sigstatus-error-callback (button) @@ -151,9 +152,9 @@ mode." (with-selected-window window (with-current-buffer buffer (goto-char (point-max)) - (call-process "gpg" nil t t "--recv-keys" keyid) + (call-process epg-gpg-program nil t t "--recv-keys" keyid) (insert "\n") - (call-process "gpg" nil t t "--list-keys" keyid)) + (call-process epg-gpg-program nil t t "--list-keys" keyid)) (recenter -1)) (notmuch-show-refresh-view))) diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el index 777658cc..1551e8b6 100644 --- a/emacs/notmuch-maildir-fcc.el +++ b/emacs/notmuch-maildir-fcc.el @@ -250,7 +250,7 @@ If CREATE is non-nil then create the folder if necessary." ;; how to deal with it. (error (let ((response (notmuch-read-char-choice - "Insert failed: (r)etry, (c)reate folder, (i)gnore, or (e)dit the header? " + "Insert failed: (r)etry, (c)reate folder, (i)gnore, or (e)dit the header? " '(?r ?c ?i ?e)))) (case response (?r (notmuch-maildir-fcc-with-notmuch-insert fcc-header)) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index c670160d..aafdd3d7 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -247,6 +247,19 @@ every user interaction with notmuch." :type 'function :group 'notmuch-show) +(defcustom notmuch-show-imenu-indent nil + "Should Imenu display messages indented. + +By default, Imenu (see Info node `(emacs) Imenu') in a +notmuch-show buffer displays all messages straight. This is +because the default Emacs frontend for Imenu makes it difficult +to select an Imenu entry with spaces in front. Other imenu +frontends such as counsel-imenu does not have this limitation. +In these cases, Imenu entries can be indented to reflect the +position of the message in the thread." + :type 'boolean + :group 'notmuch-show) + (defmacro with-current-notmuch-show-message (&rest body) "Evaluate body with current buffer set to the text of current message" `(save-excursion @@ -330,7 +343,7 @@ operation on the contents of the current buffer." (with-temp-buffer (insert all) (if indenting - (indent-rigidly (point-min) (point-max) (- depth))) + (indent-rigidly (point-min) (point-max) (- (* notmuch-show-indent-messages-width depth)))) ;; Remove the original header. (goto-char (point-min)) (re-search-forward "^$" (point-max) nil) @@ -909,7 +922,7 @@ will return nil if the CID is unknown or cannot be retrieved." (narrow-to-region part-beg part-end) (delete-region part-beg part-end) (apply #'notmuch-show-insert-bodypart-internal part-args) - (indent-rigidly part-beg part-end depth)) + (indent-rigidly part-beg part-end (* notmuch-show-indent-messages-width depth))) (goto-char part-end) (delete-char 1) (notmuch-show-record-part-information (second part-args) @@ -1516,7 +1529,11 @@ All currently available key bindings: \\{notmuch-show-mode-map}" (setq notmuch-buffer-refresh-function #'notmuch-show-refresh-view) (setq buffer-read-only t - truncate-lines t)) + truncate-lines t) + (setq imenu-prev-index-position-function + #'notmuch-show-imenu-prev-index-position-function) + (setq imenu-extract-index-name-function + #'notmuch-show-imenu-extract-index-name-function)) (defun notmuch-tree-from-show-current-query () "Call notmuch tree with the current query" @@ -1674,6 +1691,9 @@ current thread." (defun notmuch-show-get-date () (notmuch-show-get-header :Date)) +(defun notmuch-show-get-timestamp () + (notmuch-show-get-prop :timestamp)) + (defun notmuch-show-get-from () (notmuch-show-get-header :From)) @@ -2239,10 +2259,17 @@ thread from search." (interactive) (notmuch-common-do-stash (notmuch-show-get-cc))) -(defun notmuch-show-stash-date () - "Copy date of current message to kill-ring." - (interactive) - (notmuch-common-do-stash (notmuch-show-get-date))) +(put 'notmuch-show-stash-date 'notmuch-prefix-doc + "Copy timestamp of current message to kill-ring.") +(defun notmuch-show-stash-date (&optional stash-timestamp) + "Copy date of current message to kill-ring. + +If invoked with a prefix argument, copy timestamp of current +message to kill-ring." + (interactive "P") + (if stash-timestamp + (notmuch-common-do-stash (format "%d" (notmuch-show-get-timestamp))) + (notmuch-common-do-stash (notmuch-show-get-date)))) (defun notmuch-show-stash-filename () "Copy filename of current message to kill-ring." @@ -2455,6 +2482,26 @@ the new buffer." (mailcap-mime-types) nil nil nil nil "text/plain"))) (notmuch-show-apply-to-current-part-handle #'notmuch-show--mm-display-part mime-type)) +(defun notmuch-show-imenu-prev-index-position-function () + "Move point to previous message in notmuch-show buffer. +This function is used as a value for +`imenu-prev-index-position-function'." + (if (bobp) + nil + (notmuch-show-previous-message) + t)) + +(defun notmuch-show-imenu-extract-index-name-function () + "Return imenu name for line at point. +This function is used as a value for +`imenu-extract-index-name-function'. Point should be at the +beginning of the line." + (back-to-indentation) + (buffer-substring-no-properties (if notmuch-show-imenu-indent + (line-beginning-position) + (point)) + (line-end-position))) + (provide 'notmuch-show) ;;; notmuch-show.el ends here diff --git a/emacs/notmuch.el b/emacs/notmuch.el index d8d3afeb..90af68e3 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -374,7 +374,11 @@ Complete list of currently available key bindings: (set (make-local-variable 'scroll-preserve-screen-position) t) (add-to-invisibility-spec (cons 'ellipsis t)) (setq truncate-lines t) - (setq buffer-read-only t)) + (setq buffer-read-only t) + (setq imenu-prev-index-position-function + #'notmuch-search-imenu-prev-index-position-function) + (setq imenu-extract-index-name-function + #'notmuch-search-imenu-extract-index-name-function)) (defun notmuch-search-get-result (&optional pos) "Return the result object for the thread at POS (or point). @@ -402,17 +406,17 @@ returns nil" (next-single-property-change (or pos (point)) 'notmuch-search-result nil (point-max)))) -(defun notmuch-search-foreach-result (beg end function) - "Invoke FUNCTION for each result between BEG and END. +(defun notmuch-search-foreach-result (beg end fn) + "Invoke FN for each result between BEG and END. -FUNCTION should take one argument. It will be applied to the +FN should take one argument. It will be applied to the character position of the beginning of each result that overlaps the region between points BEG and END. As a special case, if (= -BEG END), FUNCTION will be applied to the result containing point +BEG END), FN will be applied to the result containing point BEG." (lexical-let ((pos (notmuch-search-result-beginning beg)) - ;; End must be a marker in case function changes the + ;; End must be a marker in case fn changes the ;; text. (end (copy-marker end)) ;; Make sure we examine at least one result, even if @@ -423,7 +427,7 @@ BEG." ;; pos. (while (and pos (or (< pos end) first)) (when (notmuch-search-get-result pos) - (funcall function pos)) + (funcall fn pos)) (setq pos (notmuch-search-result-end pos) first nil)))) ;; Unindent the function argument of notmuch-search-foreach-result so @@ -1094,8 +1098,8 @@ notmuch buffers exist, run `notmuch'." ;; Find the first notmuch buffer. (setq first (loop for buffer in (buffer-list) - if (notmuch-interesting-buffer buffer) - return buffer)) + if (notmuch-interesting-buffer buffer) + return buffer)) (if first ;; If the first one we found is any other than the starting @@ -1104,6 +1108,23 @@ notmuch buffers exist, run `notmuch'." (switch-to-buffer first)) (notmuch)))) +;;;; Imenu Support + +(defun notmuch-search-imenu-prev-index-position-function () + "Move point to previous message in notmuch-search buffer. +This function is used as a value for +`imenu-prev-index-position-function'." + (notmuch-search-previous-thread)) + +(defun notmuch-search-imenu-extract-index-name-function () + "Return imenu name for line at point. +This function is used as a value for +`imenu-extract-index-name-function'. Point should be at the +beginning of the line." + (let ((subject (notmuch-search-find-subject)) + (author (notmuch-search-find-authors))) + (format "%s (%s)" subject author))) + (setq mail-user-agent 'notmuch-user-agent) (provide 'notmuch) diff --git a/lib/Makefile.local b/lib/Makefile.local index cd92fc79..bf6e0649 100644 --- a/lib/Makefile.local +++ b/lib/Makefile.local @@ -1,5 +1,12 @@ # -*- makefile -*- +dir := lib + +# The (often-reused) $dir works fine within targets/prerequisites, +# but cannot be used reliably within commands, so copy its value to a +# variable that is not reused. +lib := $(dir) + ifeq ($(PLATFORM),MACOSX) LIBRARY_SUFFIX = dylib # On OS X, library version numbers go before suffix. @@ -12,7 +19,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) $(NO_UNDEFINED_LDFLAGS) +LIBRARY_LINK_FLAG = -shared -Wl,--version-script=$(lib)/notmuch.sym,-soname=$(SONAME) $(NO_UNDEFINED_LDFLAGS) ifeq ($(PLATFORM),OPENBSD) LIBRARY_LINK_FLAG += -lc endif @@ -23,13 +30,8 @@ endif endif endif -dir := lib -extra_cflags += -I$(srcdir)/$(dir) -fPIC - -# The (often-reused) $dir works fine within targets/prerequisites, -# but cannot be used reliably within commands, so copy its value to a -# variable that is not reused. -lib := $(dir) +extra_cflags += -I$(srcdir)/$(dir) -fPIC -fvisibility=hidden +extra_cxxflags += -fvisibility-inlines-hidden libnotmuch_c_srcs = \ $(notmuch_compat_srcs) \ @@ -60,11 +62,8 @@ libnotmuch_modules := $(libnotmuch_c_srcs:.c=.o) $(libnotmuch_cxx_srcs:.cc=.o) $(dir)/libnotmuch.a: $(libnotmuch_modules) $(call quiet,AR) rcs $@ $^ -$(dir)/$(LIBNAME): $(libnotmuch_modules) notmuch.sym util/libutil.a parse-time-string/libparse-time-string.a - $(call quiet,CXX $(CXXFLAGS)) $(libnotmuch_modules) $(FINAL_LIBNOTMUCH_LDFLAGS) $(LIBRARY_LINK_FLAG) -o $@ util/libutil.a parse-time-string/libparse-time-string.a - -notmuch.sym: $(srcdir)/$(dir)/notmuch.h $(libnotmuch_modules) - sh $(srcdir)/$(lib)/gen-version-script.sh $< $(libnotmuch_modules) > $@ +$(dir)/$(LIBNAME): $(libnotmuch_modules) util/libnotmuch_util.a parse-time-string/libparse-time-string.a + $(call quiet,CXX $(CXXFLAGS)) $(libnotmuch_modules) $(FINAL_LIBNOTMUCH_LDFLAGS) $(LIBRARY_LINK_FLAG) -o $@ util/libnotmuch_util.a parse-time-string/libparse-time-string.a $(dir)/$(SONAME): $(dir)/$(LIBNAME) ln -sf $(LIBNAME) $@ @@ -85,5 +84,5 @@ install-$(dir): $(dir)/$(LIBNAME) SRCS := $(SRCS) $(libnotmuch_c_srcs) $(libnotmuch_cxx_srcs) CLEAN += $(libnotmuch_modules) $(dir)/$(SONAME) $(dir)/$(LINKER_NAME) -CLEAN += $(dir)/$(LIBNAME) $(dir)/libnotmuch.a notmuch.sym +CLEAN += $(dir)/$(LIBNAME) $(dir)/libnotmuch.a CLEAN += $(dir)/notmuch.h.gch diff --git a/lib/database-private.h b/lib/database-private.h index ab3d9691..727b1d61 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -38,8 +38,6 @@ #include -#pragma GCC visibility push(hidden) - /* Bit masks for _notmuch_database::features. Features are named, * independent aspects of the database schema. * @@ -248,6 +246,4 @@ _notmuch_database_get_terms_with_prefix (void *ctx, Xapian::TermIterator &i, Xapian::TermIterator &end, const char *prefix); -#pragma GCC visibility pop - #endif diff --git a/lib/database.cc b/lib/database.cc index b7fc53ee..5b13f541 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -259,11 +259,15 @@ prefix_t prefix_table[] = { { "file-direntry", "XFDIRENTRY", NOTMUCH_FIELD_NO_FLAGS }, { "directory-direntry", "XDDIRENTRY", NOTMUCH_FIELD_NO_FLAGS }, { "thread", "G", NOTMUCH_FIELD_EXTERNAL }, - { "tag", "K", NOTMUCH_FIELD_EXTERNAL }, - { "is", "K", NOTMUCH_FIELD_EXTERNAL }, + { "tag", "K", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROCESSOR }, + { "is", "K", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROCESSOR }, { "id", "Q", NOTMUCH_FIELD_EXTERNAL }, - { "mid", "Q", NOTMUCH_FIELD_EXTERNAL }, - { "path", "P", NOTMUCH_FIELD_EXTERNAL }, + { "mid", "Q", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROCESSOR }, + { "path", "P", NOTMUCH_FIELD_EXTERNAL| + NOTMUCH_FIELD_PROCESSOR }, { "property", "XPROPERTY", NOTMUCH_FIELD_EXTERNAL }, /* * Unconditionally add ':' to reduce potential ambiguity with @@ -271,7 +275,8 @@ prefix_t prefix_table[] = { * letters. See Xapian document termprefixes.html for related * discussion. */ - { "folder", "XFOLDER:", NOTMUCH_FIELD_EXTERNAL }, + { "folder", "XFOLDER:", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROCESSOR }, #if HAVE_XAPIAN_FIELD_PROCESSOR { "date", NULL, NOTMUCH_FIELD_EXTERNAL | NOTMUCH_FIELD_PROCESSOR }, @@ -313,7 +318,8 @@ _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) else if (STRNCMP_LITERAL(prefix->name, "query") == 0) fp = (new QueryFieldProcessor (*notmuch->query_parser, notmuch))->release (); else - fp = (new RegexpFieldProcessor (prefix->name, *notmuch->query_parser, notmuch))->release (); + fp = (new RegexpFieldProcessor (prefix->name, prefix->flags, + *notmuch->query_parser, notmuch))->release (); /* we treat all field-processor fields as boolean in order to get the raw input */ notmuch->query_parser->add_boolean_prefix (prefix->name, fp); @@ -1493,7 +1499,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, query = notmuch_query_create (notmuch, ""); unsigned msg_count; - status = notmuch_query_count_messages_st (query, &msg_count); + status = notmuch_query_count_messages (query, &msg_count); if (status) goto DONE; @@ -1531,7 +1537,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, query = notmuch_query_create (notmuch, ""); - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (status) goto DONE; for (; @@ -2493,53 +2499,53 @@ notmuch_database_add_message (notmuch_database_t *notmuch, if (ret) goto DONE; - try { - /* Before we do any real work, (especially before doing a - * potential SHA-1 computation on the entire file's contents), - * let's make sure that what we're looking at looks like an - * actual email message. - */ - from = _notmuch_message_file_get_header (message_file, "from"); - subject = _notmuch_message_file_get_header (message_file, "subject"); - to = _notmuch_message_file_get_header (message_file, "to"); + /* Before we do any real work, (especially before doing a + * potential SHA-1 computation on the entire file's contents), + * let's make sure that what we're looking at looks like an + * actual email message. + */ + from = _notmuch_message_file_get_header (message_file, "from"); + subject = _notmuch_message_file_get_header (message_file, "subject"); + to = _notmuch_message_file_get_header (message_file, "to"); + + if ((from == NULL || *from == '\0') && + (subject == NULL || *subject == '\0') && + (to == NULL || *to == '\0')) { + ret = NOTMUCH_STATUS_FILE_NOT_EMAIL; + goto DONE; + } - if ((from == NULL || *from == '\0') && - (subject == NULL || *subject == '\0') && - (to == NULL || *to == '\0')) - { - ret = NOTMUCH_STATUS_FILE_NOT_EMAIL; - goto DONE; - } + /* Now that we're sure it's mail, the first order of business + * is to find a message ID (or else create one ourselves). + */ + header = _notmuch_message_file_get_header (message_file, "message-id"); + if (header && *header != '\0') { + message_id = _parse_message_id (message_file, header, NULL); - /* Now that we're sure it's mail, the first order of business - * is to find a message ID (or else create one ourselves). */ + /* So the header value isn't RFC-compliant, but it's + * better than no message-id at all. + */ + if (message_id == NULL) + message_id = talloc_strdup (message_file, header); + } - header = _notmuch_message_file_get_header (message_file, "message-id"); - if (header && *header != '\0') { - message_id = _parse_message_id (message_file, header, NULL); + if (message_id == NULL ) { + /* No message-id at all, let's generate one by taking a + * hash over the file's contents. + */ + char *sha1 = _notmuch_sha1_of_file (filename); - /* So the header value isn't RFC-compliant, but it's - * better than no message-id at all. */ - if (message_id == NULL) - message_id = talloc_strdup (message_file, header); + /* If that failed too, something is really wrong. Give up. */ + if (sha1 == NULL) { + ret = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; } - if (message_id == NULL ) { - /* No message-id at all, let's generate one by taking a - * hash over the file's contents. */ - char *sha1 = _notmuch_sha1_of_file (filename); - - /* If that failed too, something is really wrong. Give up. */ - if (sha1 == NULL) { - ret = NOTMUCH_STATUS_FILE_ERROR; - goto DONE; - } - - message_id = talloc_asprintf (message_file, - "notmuch-sha1-%s", sha1); - free (sha1); - } + message_id = talloc_asprintf (message_file, "notmuch-sha1-%s", sha1); + free (sha1); + } + try { /* Now that we have a message ID, we get a message object, * (which may or may not reference an existing document in the * database). */ diff --git a/lib/gen-version-script.sh b/lib/gen-version-script.sh deleted file mode 100644 index 5621f2a9..00000000 --- a/lib/gen-version-script.sh +++ /dev/null @@ -1,29 +0,0 @@ -set -eu - -# we go through a bit of work to get the unmangled names of the -# typeinfo symbols because of -# https://sourceware.org/bugzilla/show_bug.cgi?id=10326 - -if [ $# -lt 2 ]; then - echo Usage: $0 header obj1 obj2 obj3 - exit 1; -fi - -HEADER=$1 -shift - -printf '{\nglobal:\n' -nm $* | awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $3 ~ "Xapian.*Error" {print $3}' | sort | uniq | \ -while read sym; do - demangled=$(c++filt $sym) - case $demangled in - typeinfo*) - printf "\t$sym;\n" - ;; - *) - ;; - esac -done -nm $* | awk '$1 ~ "^[0-9a-fA-F][0-9a-fA-F]*$" && $2 == "T" && $3 ~ "^(getline|getdelim|canonicalize_file_name)$" {print $3 ";"}' -sed -n 's/^[[:space:]]*\(notmuch_[a-z_]*\)[[:space:]]*(.*/ \1;/p' $HEADER -printf "local: *;\n};\n" diff --git a/lib/index.cc b/lib/index.cc index 8c145540..0c4e2329 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -24,13 +24,74 @@ #include + +typedef struct { + int state; + int a; + int b; + int next_if_match; + int next_if_not_match; +} scanner_state_t; + +/* Simple, linear state-transition diagram for the uuencode filter. + * + * If the character being processed is within the range of [a, b] + * for the current state then we transition next_if_match + * state. If not, we transition to the next_if_not_match state. + * + * The final two states are special in that they are the states in + * which we discard data. */ +static const int first_uuencode_skipping_state = 11; +static const scanner_state_t uuencode_states[] = { + {0, 'b', 'b', 1, 0}, + {1, 'e', 'e', 2, 0}, + {2, 'g', 'g', 3, 0}, + {3, 'i', 'i', 4, 0}, + {4, 'n', 'n', 5, 0}, + {5, ' ', ' ', 6, 0}, + {6, '0', '7', 7, 0}, + {7, '0', '7', 8, 0}, + {8, '0', '7', 9, 0}, + {9, ' ', ' ', 10, 0}, + {10, '\n', '\n', 11, 10}, + {11, 'M', 'M', 12, 0}, + {12, ' ', '`', 12, 11} +}; + +/* The following table is intended to implement this DFA (in 'dot' + format). Note that 2 and 3 are "hidden" states used to step through + the possible out edges of state 1. + +digraph html_filter { + 0 -> 1 [label="<"]; + 0 -> 0; + 1 -> 4 [label="'"]; + 1 -> 5 [label="\""]; + 1 -> 0 [label=">"]; + 1 -> 1; + 4 -> 1 [label="'"]; + 4 -> 4; + 5 -> 1 [label="\""]; + 5 -> 5; +} +*/ +static const int first_html_skipping_state = 1; +static const scanner_state_t html_states[] = { + {0, '<', '<', 1, 0}, + {1, '\'', '\'', 4, 2}, /* scanning for quote or > */ + {1, '"', '"', 5, 3}, + {1, '>', '>', 0, 1}, + {4, '\'', '\'', 1, 4}, /* inside single quotes */ + {5, '"', '"', 1, 5}, /* inside double quotes */ +}; + /* Oh, how I wish that gobject didn't require so much noisy boilerplate! * (Though I have at least eliminated some of the stock set...) */ -typedef struct _NotmuchFilterDiscardUuencode NotmuchFilterDiscardUuencode; -typedef struct _NotmuchFilterDiscardUuencodeClass NotmuchFilterDiscardUuencodeClass; +typedef struct _NotmuchFilterDiscardNonTerm NotmuchFilterDiscardNonTerm; +typedef struct _NotmuchFilterDiscardNonTermClass NotmuchFilterDiscardNonTermClass; /** - * NotmuchFilterDiscardUuencode: + * NotmuchFilterDiscardNonTerm: * * @parent_object: parent #GMimeFilter * @encode: encoding vs decoding @@ -54,18 +115,21 @@ typedef struct _NotmuchFilterDiscardUuencodeClass NotmuchFilterDiscardUuencodeCl * final line of encoded data (the line not starting with M) will be * indexed. **/ -struct _NotmuchFilterDiscardUuencode { +struct _NotmuchFilterDiscardNonTerm { GMimeFilter parent_object; + GMimeContentType *content_type; int state; + int first_skipping_state; + const scanner_state_t *states; }; -struct _NotmuchFilterDiscardUuencodeClass { +struct _NotmuchFilterDiscardNonTermClass { GMimeFilterClass parent_class; }; -static GMimeFilter *notmuch_filter_discard_uuencode_new (void); +static GMimeFilter *notmuch_filter_discard_non_term_new (GMimeContentType *content); -static void notmuch_filter_discard_uuencode_finalize (GObject *object); +static void notmuch_filter_discard_non_term_finalize (GObject *object); static GMimeFilter *filter_copy (GMimeFilter *filter); static void filter_filter (GMimeFilter *filter, char *in, size_t len, size_t prespace, @@ -78,14 +142,14 @@ static void filter_reset (GMimeFilter *filter); static GMimeFilterClass *parent_class = NULL; static void -notmuch_filter_discard_uuencode_class_init (NotmuchFilterDiscardUuencodeClass *klass) +notmuch_filter_discard_non_term_class_init (NotmuchFilterDiscardNonTermClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GMimeFilterClass *filter_class = GMIME_FILTER_CLASS (klass); parent_class = (GMimeFilterClass *) g_type_class_ref (GMIME_TYPE_FILTER); - object_class->finalize = notmuch_filter_discard_uuencode_finalize; + object_class->finalize = notmuch_filter_discard_non_term_finalize; filter_class->copy = filter_copy; filter_class->filter = filter_filter; @@ -94,7 +158,7 @@ notmuch_filter_discard_uuencode_class_init (NotmuchFilterDiscardUuencodeClass *k } static void -notmuch_filter_discard_uuencode_finalize (GObject *object) +notmuch_filter_discard_non_term_finalize (GObject *object) { G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -102,67 +166,46 @@ notmuch_filter_discard_uuencode_finalize (GObject *object) static GMimeFilter * filter_copy (GMimeFilter *gmime_filter) { - (void) gmime_filter; - return notmuch_filter_discard_uuencode_new (); + NotmuchFilterDiscardNonTerm *filter = (NotmuchFilterDiscardNonTerm *) gmime_filter; + return notmuch_filter_discard_non_term_new (filter->content_type); } static void filter_filter (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace, char **outbuf, size_t *outlen, size_t *outprespace) { - NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter; + NotmuchFilterDiscardNonTerm *filter = (NotmuchFilterDiscardNonTerm *) gmime_filter; + const scanner_state_t *states = filter->states; register const char *inptr = inbuf; const char *inend = inbuf + inlen; char *outptr; (void) prespace; - /* Simple, linear state-transition diagram for our filter. - * - * If the character being processed is within the range of [a, b] - * for the current state then we transition next_if_match - * state. If not, we transition to the next_if_not_match state. - * - * The final two states are special in that they are the states in - * which we discard data. */ - static const struct { - int state; - int a; - int b; - int next_if_match; - int next_if_not_match; - } states[] = { - {0, 'b', 'b', 1, 0}, - {1, 'e', 'e', 2, 0}, - {2, 'g', 'g', 3, 0}, - {3, 'i', 'i', 4, 0}, - {4, 'n', 'n', 5, 0}, - {5, ' ', ' ', 6, 0}, - {6, '0', '7', 7, 0}, - {7, '0', '7', 8, 0}, - {8, '0', '7', 9, 0}, - {9, ' ', ' ', 10, 0}, - {10, '\n', '\n', 11, 10}, - {11, 'M', 'M', 12, 0}, - {12, ' ', '`', 12, 11} - }; int next; g_mime_filter_set_size (gmime_filter, inlen, FALSE); outptr = gmime_filter->outbuf; + next = filter->state; while (inptr < inend) { - if (*inptr >= states[filter->state].a && - *inptr <= states[filter->state].b) - { - next = states[filter->state].next_if_match; - } - else - { - next = states[filter->state].next_if_not_match; - } + /* Each state is defined by a contiguous set of rows of the + * state table marked by a common value for '.state'. The + * state numbers must be equal to the index of the first row + * in a given state; thus the loop condition here looks for a + * jump to a first row of a state, which is a real transition + * in the underlying DFA. + */ + do { + if (*inptr >= states[next].a && *inptr <= states[next].b) { + next = states[next].next_if_match; + } else { + next = states[next].next_if_not_match; + } - if (filter->state < 11) + } while (next != states[next].state); + + if (filter->state < filter->first_skipping_state) *outptr++ = *inptr; filter->state = next; @@ -185,41 +228,49 @@ filter_complete (GMimeFilter *filter, char *inbuf, size_t inlen, size_t prespace static void filter_reset (GMimeFilter *gmime_filter) { - NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter; + NotmuchFilterDiscardNonTerm *filter = (NotmuchFilterDiscardNonTerm *) gmime_filter; filter->state = 0; } /** - * notmuch_filter_discard_uuencode_new: + * notmuch_filter_discard_non_term_new: * - * Returns: a new #NotmuchFilterDiscardUuencode filter. + * Returns: a new #NotmuchFilterDiscardNonTerm filter. **/ static GMimeFilter * -notmuch_filter_discard_uuencode_new (void) +notmuch_filter_discard_non_term_new (GMimeContentType *content_type) { static GType type = 0; - NotmuchFilterDiscardUuencode *filter; + NotmuchFilterDiscardNonTerm *filter; if (!type) { static const GTypeInfo info = { - sizeof (NotmuchFilterDiscardUuencodeClass), + sizeof (NotmuchFilterDiscardNonTermClass), NULL, /* base_class_init */ NULL, /* base_class_finalize */ - (GClassInitFunc) notmuch_filter_discard_uuencode_class_init, + (GClassInitFunc) notmuch_filter_discard_non_term_class_init, NULL, /* class_finalize */ NULL, /* class_data */ - sizeof (NotmuchFilterDiscardUuencode), + sizeof (NotmuchFilterDiscardNonTerm), 0, /* n_preallocs */ NULL, /* instance_init */ NULL /* value_table */ }; - type = g_type_register_static (GMIME_TYPE_FILTER, "NotmuchFilterDiscardUuencode", &info, (GTypeFlags) 0); + type = g_type_register_static (GMIME_TYPE_FILTER, "NotmuchFilterDiscardNonTerm", &info, (GTypeFlags) 0); } - filter = (NotmuchFilterDiscardUuencode *) g_object_newv (type, 0, NULL); + filter = (NotmuchFilterDiscardNonTerm *) g_object_newv (type, 0, NULL); + filter->content_type = content_type; filter->state = 0; + if (g_mime_content_type_is_type (content_type, "text", "html")) { + filter->states = html_states; + filter->first_skipping_state = first_html_skipping_state; + } else { + filter->states = uuencode_states; + filter->first_skipping_state = first_uuencode_skipping_state; + } return (GMimeFilter *) filter; } @@ -306,7 +357,7 @@ _index_mime_part (notmuch_message_t *message, GMimeObject *part) { GMimeStream *stream, *filter; - GMimeFilter *discard_uuencode_filter; + GMimeFilter *discard_non_term_filter; GMimeDataWrapper *wrapper; GByteArray *byte_array; GMimeContentDisposition *disposition; @@ -396,10 +447,10 @@ _index_mime_part (notmuch_message_t *message, g_mime_stream_mem_set_owner (GMIME_STREAM_MEM (stream), FALSE); filter = g_mime_stream_filter_new (stream); - discard_uuencode_filter = notmuch_filter_discard_uuencode_new (); + discard_non_term_filter = notmuch_filter_discard_non_term_new (content_type); g_mime_stream_filter_add (GMIME_STREAM_FILTER (filter), - discard_uuencode_filter); + discard_non_term_filter); charset = g_mime_object_get_content_type_parameter (part, "charset"); if (charset) { @@ -421,7 +472,7 @@ _index_mime_part (notmuch_message_t *message, g_object_unref (stream); g_object_unref (filter); - g_object_unref (discard_uuencode_filter); + g_object_unref (discard_non_term_filter); g_byte_array_append (byte_array, (guint8 *) "\0", 1); body = (char *) g_byte_array_free (byte_array, FALSE); diff --git a/lib/message-property.cc b/lib/message-property.cc index 0b13cac3..f32d5550 100644 --- a/lib/message-property.cc +++ b/lib/message-property.cc @@ -51,7 +51,7 @@ _notmuch_message_modify_property (notmuch_message_t *message, const char *key, c if (key == NULL || value == NULL) return NOTMUCH_STATUS_NULL_POINTER; - if (index (key, '=')) + if (strchr (key, '=')) return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; term = talloc_asprintf (message, "%s=%s", key, value); diff --git a/lib/message.cc b/lib/message.cc index 36a07a88..b330dcce 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -26,7 +26,7 @@ #include -struct visible _notmuch_message { +struct _notmuch_message { notmuch_database_t *notmuch; Xapian::docid doc_id; int frozen; @@ -1034,10 +1034,16 @@ _notmuch_message_set_header_values (notmuch_message_t *message, /* GMime really doesn't want to see a NULL date, so protect its * sensibilities. */ - if (date == NULL || *date == '\0') + if (date == NULL || *date == '\0') { time_value = 0; - else + } else { time_value = g_mime_utils_header_decode_date (date, NULL); + /* + * Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=779923 + */ + if (time_value < 0) + time_value = 0; + } message->doc.add_value (NOTMUCH_VALUE_TIMESTAMP, Xapian::sortable_serialise (time_value)); @@ -1123,7 +1129,7 @@ _notmuch_message_delete (notmuch_message_t *message) query = notmuch_query_create (notmuch, query_string); if (query == NULL) return NOTMUCH_STATUS_OUT_OF_MEMORY; - status = notmuch_query_count_messages_st (query, &count); + status = notmuch_query_count_messages (query, &count); if (status) { notmuch_query_destroy (query); return status; @@ -1837,7 +1843,7 @@ _notmuch_message_ensure_property_map (notmuch_message_t *message) const char *key; char *value; - value = index(node->string, '='); + value = strchr(node->string, '='); if (!value) INTERNAL_ERROR ("malformed property term"); diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 8587e86c..ac315e4c 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -52,8 +52,6 @@ NOTMUCH_BEGIN_DECLS #include "error_util.h" #include "string-util.h" -#pragma GCC visibility push(hidden) - #ifdef DEBUG # define DEBUG_DATABASE_SANITY 1 # define DEBUG_QUERY 1 @@ -76,12 +74,6 @@ NOTMUCH_BEGIN_DECLS #define unused(x) x __attribute__ ((unused)) -#ifdef __cplusplus -# define visible __attribute__((visibility("default"))) -#else -# define visible -#endif - /* Thanks to Andrew Tridgell's (SAMBA's) talloc for this definition of * unlikely. The talloc source code comes to us via the GNU LGPL v. 3. */ @@ -455,7 +447,7 @@ typedef struct _notmuch_message_list { * somewhere with some nasty C++ objects in it. We'll try to maintain * ignorance of that here. (See notmuch_mset_messages_t in query.cc) */ -struct visible _notmuch_messages { +struct _notmuch_messages { notmuch_bool_t is_of_list_type; notmuch_doc_id_set_t *excluded_doc_ids; notmuch_message_node_t *iterator; @@ -524,7 +516,7 @@ typedef struct _notmuch_string_node { struct _notmuch_string_node *next; } notmuch_string_node_t; -typedef struct visible _notmuch_string_list { +typedef struct _notmuch_string_list { int length; notmuch_string_node_t *head; notmuch_string_node_t **tail; @@ -621,6 +613,4 @@ _notmuch_talloc_steal (const void *new_ctx, const T *ptr) #endif #endif -#pragma GCC visibility pop - #endif diff --git a/lib/notmuch.h b/lib/notmuch.h index 16da8be9..e1745444 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -43,6 +43,8 @@ NOTMUCH_BEGIN_DECLS #include +#pragma GCC visibility push(default) + #ifndef FALSE #define FALSE 0 #endif @@ -55,8 +57,8 @@ NOTMUCH_BEGIN_DECLS * The library version number. This must agree with the soname * version in Makefile.local. */ -#define LIBNOTMUCH_MAJOR_VERSION 4 -#define LIBNOTMUCH_MINOR_VERSION 4 +#define LIBNOTMUCH_MAJOR_VERSION 5 +#define LIBNOTMUCH_MINOR_VERSION 0 #define LIBNOTMUCH_MICRO_VERSION 0 @@ -179,6 +181,11 @@ typedef enum _notmuch_status { * passed to a function expecting an absolute path. */ NOTMUCH_STATUS_PATH_ERROR, + /** + * The requested operation was ignored. Depending on the function, + * this may not be an actual error. + */ + NOTMUCH_STATUS_IGNORED, /** * One of the arguments violates the preconditions for the * function, in a way not covered by a more specific argument. @@ -812,10 +819,20 @@ notmuch_query_get_sort (const notmuch_query_t *query); /** * Add a tag that will be excluded from the query results by default. - * This exclusion will be overridden if this tag appears explicitly in + * This exclusion will be ignored if this tag appears explicitly in * the query. + * + * @returns + * + * NOTMUCH_STATUS_SUCCESS: excluded was added successfully. + * + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. + * Most likely a problem lazily parsing the query string. + * + * NOTMUCH_STATUS_IGNORED: tag is explicitely present in the query, so + * not excluded. */ -void +notmuch_status_t notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag); /** @@ -855,24 +872,22 @@ 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). * - * @since libnotmuch 4.2 (notmuch 0.20) + * @since libnotmuch 5.0 (notmuch 0.25) */ notmuch_status_t -notmuch_query_search_threads_st (notmuch_query_t *query, - notmuch_threads_t **out); +notmuch_query_search_threads (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 alias for notmuch_query_search_threads. * - * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please - * use notmuch_query_search_threads_st instead. + * @deprecated Deprecated as of libnotmuch 5 (notmuch 0.25). Please + * use notmuch_query_search_threads instead. * */ -NOTMUCH_DEPRECATED(4,3) -notmuch_threads_t * -notmuch_query_search_threads (notmuch_query_t *query); +NOTMUCH_DEPRECATED(5,0) +notmuch_status_t +notmuch_query_search_threads_st (notmuch_query_t *query, notmuch_threads_t **out); /** * Execute a query for messages, returning a notmuch_messages_t object @@ -913,23 +928,23 @@ notmuch_query_search_threads (notmuch_query_t *query); * * If a Xapian exception occurs this function will return NULL. * - * @since libnotmuch 4.2 (notmuch 0.20) + * @since libnotmuch 5 (notmuch 0.25) */ notmuch_status_t -notmuch_query_search_messages_st (notmuch_query_t *query, - notmuch_messages_t **out); +notmuch_query_search_messages (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 alias for notmuch_query_search_messages * - * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please use - * notmuch_query_search_messages_st instead. + * @deprecated Deprecated as of libnotmuch 5 (notmuch 0.25). Please use + * notmuch_query_search_messages instead. * */ -NOTMUCH_DEPRECATED(4,3) -notmuch_messages_t * -notmuch_query_search_messages (notmuch_query_t *query); + +NOTMUCH_DEPRECATED(5,0) +notmuch_status_t +notmuch_query_search_messages_st (notmuch_query_t *query, + notmuch_messages_t **out); /** * Destroy a notmuch_query_t along with any associated resources. @@ -1010,22 +1025,21 @@ notmuch_threads_destroy (notmuch_threads_t *threads); * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The * value of *count is not defined. * - * @since libnotmuch 4.3 (notmuch 0.21) + * @since libnotmuch 5 (notmuch 0.25) */ notmuch_status_t -notmuch_query_count_messages_st (notmuch_query_t *query, unsigned int *count); +notmuch_query_count_messages (notmuch_query_t *query, unsigned int *count); /** - * like notmuch_query_count_messages_st, but without a status return. + * Deprecated alias for notmuch_query_count_messages * - * May return 0 in the case of errors. * - * @deprecated Deprecated since libnotmuch 4.3 (notmuch 0.21). Please - * use notmuch_query_count_messages_st instead. + * @deprecated Deprecated since libnotmuch 5.0 (notmuch 0.25). Please + * use notmuch_query_count_messages instead. */ -NOTMUCH_DEPRECATED(4,3) -unsigned int -notmuch_query_count_messages (notmuch_query_t *query); +NOTMUCH_DEPRECATED(5,0) +notmuch_status_t +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned int *count); /** * Return the number of threads matching a search. @@ -1047,22 +1061,20 @@ notmuch_query_count_messages (notmuch_query_t *query); * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The * value of *count is not defined. * - * @since libnotmuch 4.3 (notmuch 0.21) + * @since libnotmuch 5 (notmuch 0.25) */ notmuch_status_t -notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count); +notmuch_query_count_threads (notmuch_query_t *query, unsigned *count); /** - * like notmuch_query_count_threads, but without a status return. - * - * May return 0 in case of errors. + * Deprecated alias for notmuch_query_count_threads * - * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please + * @deprecated Deprecated as of libnotmuch 5.0 (notmuch 0.25). Please * use notmuch_query_count_threads_st instead. */ -NOTMUCH_DEPRECATED(4,3) -unsigned int -notmuch_query_count_threads (notmuch_query_t *query); +NOTMUCH_DEPRECATED(5,0) +notmuch_status_t +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count); /** * Get the thread ID of 'thread'. @@ -2110,6 +2122,8 @@ notmuch_bool_t notmuch_built_with (const char *name); /* @} */ +#pragma GCC visibility pop + NOTMUCH_END_DECLS #endif diff --git a/lib/notmuch.sym b/lib/notmuch.sym new file mode 100644 index 00000000..7d0c0af4 --- /dev/null +++ b/lib/notmuch.sym @@ -0,0 +1,7 @@ +{ +global: + _ZTI*; + _ZTS*; + notmuch_*; +local: *; +}; diff --git a/lib/query.cc b/lib/query.cc index 59e9141a..9c6ecc8d 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -49,7 +49,7 @@ struct _notmuch_doc_id_set { #define DOCIDSET_WORD(bit) ((bit) / CHAR_BIT) #define DOCIDSET_BIT(bit) ((bit) % CHAR_BIT) -struct visible _notmuch_threads { +struct _notmuch_threads { notmuch_query_t *query; /* The ordered list of doc ids matched by the query. */ @@ -177,29 +177,22 @@ notmuch_query_get_sort (const notmuch_query_t *query) return query->sort; } -void +notmuch_status_t notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag) { notmuch_status_t status; char *term; status = _notmuch_query_ensure_parsed (query); - /* The following is not ideal error handling, but to avoid - * breaking the ABI, we can live with it for now. In particular at - * least in the notmuch CLI, any syntax error in the query is - * caught in a later call to _notmuch_query_ensure_parsed with a - * better error path. - * - * TODO: add status return to this function. - */ if (status) - return; + return status; term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag); if (query->terms.count(term) != 0) - return; /* XXX report ignoring exclude? */ + return NOTMUCH_STATUS_IGNORED; _notmuch_string_list_append (query->exclude_terms, term); + return NOTMUCH_STATUS_SUCCESS; } /* We end up having to call the destructors explicitly because we had @@ -233,20 +226,16 @@ _notmuch_exclude_tags (notmuch_query_t *query) return exclude_query; } -notmuch_messages_t * -notmuch_query_search_messages (notmuch_query_t *query) + +notmuch_status_t +notmuch_query_search_messages_st (notmuch_query_t *query, + notmuch_messages_t **out) { - notmuch_status_t status; - notmuch_messages_t *messages; - status = notmuch_query_search_messages_st (query, &messages); - if (status) - return NULL; - else - return messages; + return notmuch_query_search_messages (query, out); } notmuch_status_t -notmuch_query_search_messages_st (notmuch_query_t *query, +notmuch_query_search_messages (notmuch_query_t *query, notmuch_messages_t **out) { return _notmuch_query_search_documents (query, "mail", out); @@ -497,22 +486,15 @@ _notmuch_threads_destructor (notmuch_threads_t *threads) return 0; } - -notmuch_threads_t * -notmuch_query_search_threads (notmuch_query_t *query) +notmuch_status_t +notmuch_query_search_threads_st (notmuch_query_t *query, notmuch_threads_t **out) { - notmuch_status_t status; - notmuch_threads_t *threads; - status = notmuch_query_search_threads_st (query, &threads); - if (status) - return NULL; - else - return threads; + return notmuch_query_search_threads(query, out); } notmuch_status_t -notmuch_query_search_threads_st (notmuch_query_t *query, - notmuch_threads_t **out) +notmuch_query_search_threads (notmuch_query_t *query, + notmuch_threads_t **out) { notmuch_threads_t *threads; notmuch_messages_t *messages; @@ -526,7 +508,7 @@ notmuch_query_search_threads_st (notmuch_query_t *query, threads->query = query; - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (status) { talloc_free (threads); return status; @@ -609,18 +591,14 @@ notmuch_threads_destroy (notmuch_threads_t *threads) talloc_free (threads); } -unsigned int -notmuch_query_count_messages (notmuch_query_t *query) +notmuch_status_t +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out) { - notmuch_status_t status; - unsigned int count; - - status = notmuch_query_count_messages_st (query, &count); - return status ? 0 : count; + return notmuch_query_count_messages (query, count_out); } notmuch_status_t -notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out) +notmuch_query_count_messages (notmuch_query_t *query, unsigned *count_out) { return _notmuch_query_count_documents (query, "mail", count_out); } @@ -695,18 +673,14 @@ _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsign return NOTMUCH_STATUS_SUCCESS; } -unsigned -notmuch_query_count_threads (notmuch_query_t *query) +notmuch_status_t +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count) { - notmuch_status_t status; - unsigned int count; - - status = notmuch_query_count_threads_st (query, &count); - return status ? 0 : count; + return notmuch_query_count_threads (query, count); } notmuch_status_t -notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count) +notmuch_query_count_threads (notmuch_query_t *query, unsigned *count) { notmuch_messages_t *messages; GHashTable *hash; @@ -715,7 +689,7 @@ notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count) sort = query->sort; query->sort = NOTMUCH_SORT_UNSORTED; - ret = notmuch_query_search_messages_st (query, &messages); + ret = notmuch_query_search_messages (query, &messages); if (ret) return ret; query->sort = sort; diff --git a/lib/regexp-fields.cc b/lib/regexp-fields.cc index 1651677c..084bc8c0 100644 --- a/lib/regexp-fields.cc +++ b/lib/regexp-fields.cc @@ -135,42 +135,76 @@ static inline Xapian::valueno _find_slot (std::string prefix) return NOTMUCH_VALUE_FROM; else if (prefix == "subject") return NOTMUCH_VALUE_SUBJECT; + else if (prefix == "mid") + return NOTMUCH_VALUE_MESSAGE_ID; else - throw Xapian::QueryParserError ("unsupported regexp field '" + prefix + "'"); + return Xapian::BAD_VALUENO; } -RegexpFieldProcessor::RegexpFieldProcessor (std::string prefix, Xapian::QueryParser &parser_, notmuch_database_t *notmuch_) - : slot (_find_slot (prefix)), term_prefix (_find_prefix (prefix.c_str ())), - parser (parser_), notmuch (notmuch_) +RegexpFieldProcessor::RegexpFieldProcessor (std::string prefix, + notmuch_field_flag_t options_, + Xapian::QueryParser &parser_, + notmuch_database_t *notmuch_) + : slot (_find_slot (prefix)), + term_prefix (_find_prefix (prefix.c_str ())), + options (options_), + parser (parser_), + notmuch (notmuch_) { }; Xapian::Query RegexpFieldProcessor::operator() (const std::string & str) { - if (str.size () == 0) - return Xapian::Query(Xapian::Query::OP_AND_NOT, + if (str.empty ()) { + if (options & NOTMUCH_FIELD_PROBABILISTIC) { + return Xapian::Query(Xapian::Query::OP_AND_NOT, Xapian::Query::MatchAll, Xapian::Query (Xapian::Query::OP_WILDCARD, term_prefix)); + } else { + return Xapian::Query (term_prefix); + } + } if (str.at (0) == '/') { - if (str.at (str.size () - 1) == '/'){ - RegexpPostingSource *postings = new RegexpPostingSource (slot, str.substr(1,str.size () - 2)); - return Xapian::Query (postings->release ()); + if (str.length() > 1 && str.at (str.size () - 1) == '/'){ + std::string regexp_str = str.substr(1,str.size () - 2); + if (slot != Xapian::BAD_VALUENO) { + RegexpPostingSource *postings = new RegexpPostingSource (slot, regexp_str); + return Xapian::Query (postings->release ()); + } else { + std::vector terms; + regex_t regexp; + + compile_regex(regexp, regexp_str.c_str ()); + for (Xapian::TermIterator it = notmuch->xapian_db->allterms_begin (term_prefix); + it != notmuch->xapian_db->allterms_end (); ++it) { + if (regexec (®exp, (*it).c_str () + term_prefix.size(), + 0, NULL, 0) == 0) + terms.push_back(*it); + } + return Xapian::Query (Xapian::Query::OP_OR, terms.begin(), terms.end()); + } } else { throw Xapian::QueryParserError ("unmatched regex delimiter in '" + str + "'"); } } else { - /* TODO replace this with a nicer API level triggering of - * phrase parsing, when possible */ - std::string query_str; + if (options & NOTMUCH_FIELD_PROBABILISTIC) { + /* TODO replace this with a nicer API level triggering of + * phrase parsing, when possible */ + std::string query_str; - if (str.find (' ') != std::string::npos) - query_str = '"' + str + '"'; - else - query_str = str; + if (str.find (' ') != std::string::npos) + query_str = '"' + str + '"'; + else + query_str = str; - return parser.parse_query (query_str, NOTMUCH_QUERY_PARSER_FLAGS, term_prefix); + return parser.parse_query (query_str, NOTMUCH_QUERY_PARSER_FLAGS, term_prefix); + } else { + /* Boolean prefix */ + std::string term = term_prefix + str; + return Xapian::Query (term); + } } } #endif diff --git a/lib/regexp-fields.h b/lib/regexp-fields.h index a4ba7ad8..d5f93445 100644 --- a/lib/regexp-fields.h +++ b/lib/regexp-fields.h @@ -65,11 +65,13 @@ class RegexpFieldProcessor : public Xapian::FieldProcessor { protected: Xapian::valueno slot; std::string term_prefix; + notmuch_field_flag_t options; Xapian::QueryParser &parser; notmuch_database_t *notmuch; public: - RegexpFieldProcessor (std::string prefix, Xapian::QueryParser &parser_, notmuch_database_t *notmuch_); + RegexpFieldProcessor (std::string prefix, notmuch_field_flag_t options, + Xapian::QueryParser &parser_, notmuch_database_t *notmuch_); ~RegexpFieldProcessor () { }; diff --git a/lib/thread.cc b/lib/thread.cc index 84ee5298..1a1ecfa5 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -26,7 +26,7 @@ #define EMPTY_STRING(s) ((s)[0] == '\0') -struct visible _notmuch_thread { +struct _notmuch_thread { notmuch_database_t *notmuch; char *thread_id; char *subject; @@ -505,7 +505,7 @@ _notmuch_thread_create (void *ctx, * oldest or newest subject is desired. */ notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_OLDEST_FIRST); - status = notmuch_query_search_messages_st (thread_id_query, &messages); + status = notmuch_query_search_messages (thread_id_query, &messages); if (status) goto DONE; diff --git a/mime-node.c b/mime-node.c index c9b82330..f719422e 100644 --- a/mime-node.c +++ b/mime-node.c @@ -322,20 +322,21 @@ mime_node_child (mime_node_t *parent, int child) static mime_node_t * _mime_node_seek_dfs_walk (mime_node_t *node, int *n) { - mime_node_t *ret = NULL; int i; if (*n == 0) return node; *n -= 1; - for (i = 0; i < node->nchildren && !ret; i++) { + for (i = 0; i < node->nchildren; i++) { mime_node_t *child = mime_node_child (node, i); - ret = _mime_node_seek_dfs_walk (child, n); - if (!ret) - talloc_free (child); + mime_node_t *ret = _mime_node_seek_dfs_walk (child, n); + if (ret) + return ret; + + talloc_free (child); } - return ret; + return NULL; } mime_node_t * diff --git a/notmuch-client.h b/notmuch-client.h index e8f17250..62d4bcec 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -29,7 +29,7 @@ #include "compat.h" -#include +#include "gmime-extra.h" typedef GMimeCryptoContext notmuch_crypto_context_t; /* This is automatically included only since gmime 2.6.10 */ @@ -83,10 +83,10 @@ typedef struct notmuch_show_params { notmuch_bool_t entire_thread; notmuch_bool_t omit_excluded; notmuch_bool_t output_body; - notmuch_bool_t raw; int part; notmuch_crypto_t crypto; notmuch_bool_t include_html; + GMimeStream *out_stream; } notmuch_show_params_t; /* There's no point in continuing when we've detected that we've done diff --git a/notmuch-count.c b/notmuch-count.c index 35a2aa70..50b0c193 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -43,7 +43,7 @@ count_files (notmuch_query_t *query) notmuch_status_t status; int count = 0; - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (print_status_query ("notmuch count", query, status)) return -1; @@ -87,18 +87,23 @@ print_count (notmuch_database_t *notmuch, const char *query_str, return -1; } - for (i = 0; i < exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, exclude_tags[i]); + for (i = 0; i < exclude_tags_length; i++) { + status = notmuch_query_add_tag_exclude (query, exclude_tags[i]); + if (status && status != NOTMUCH_STATUS_IGNORED) { + print_status_query ("notmuch count", query, status); + return -1; + } + } switch (output) { case OUTPUT_MESSAGES: - status = notmuch_query_count_messages_st (query, &ucount); + status = notmuch_query_count_messages (query, &ucount); if (print_status_query ("notmuch count", query, status)) return -1; printf ("%u", ucount); break; case OUTPUT_THREADS: - status = notmuch_query_count_threads_st (query, &ucount); + status = notmuch_query_count_threads (query, &ucount); if (print_status_query ("notmuch count", query, status)) return -1; printf ("%u", ucount); @@ -106,7 +111,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str, case OUTPUT_FILES: count = count_files (query); if (count >= 0) { - printf ("%u", count); + printf ("%d", count); } else { ret = -1; goto DONE; diff --git a/notmuch-dump.c b/notmuch-dump.c index f0ac1932..5cc3b2f6 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -240,7 +240,7 @@ database_dump_file (notmuch_database_t *notmuch, gzFile output, */ notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED); - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (print_status_query ("notmuch dump", query, status)) return EXIT_FAILURE; diff --git a/notmuch-new.c b/notmuch-new.c index 13212639..3a60f7ca 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -131,10 +131,10 @@ generic_print_progress (const char *action, const char *object, elapsed_overall = notmuch_time_elapsed (tv_start, tv_now); rate_overall = processed / elapsed_overall; - printf ("%s %d ", action, processed); + printf ("%s %u ", action, processed); if (total) { - printf ("of %d %s", total, object); + printf ("of %u %s", total, object); if (processed > 0 && elapsed_overall > 0.5) { double time_remaining = ((total - processed) / rate_overall); printf (" ("); @@ -850,7 +850,7 @@ _remove_directory (void *ctx, const char *path, add_files_state_t *add_files_state) { - notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; + notmuch_status_t status; notmuch_directory_t *directory; notmuch_filenames_t *files, *subdirs; char *absolute; @@ -905,10 +905,9 @@ print_results (const add_files_state_t *state) state->processed_files == 1 ? "file" : "total files"); notmuch_time_print_formatted_seconds (elapsed); if (elapsed > 1) - printf (" (%d files/sec.).\033[K\n", + printf (" (%d files/sec.)", (int) (state->processed_files / elapsed)); - else - printf (".\033[K\n"); + printf (".%s\n", (state->output_is_a_tty) ? "\033[K" : ""); } if (state->added_messages) diff --git a/notmuch-reply.c b/notmuch-reply.c index 8c894974..e6c16641 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -25,47 +25,44 @@ #include "sprinter.h" static void -show_reply_headers (GMimeMessage *message) +show_reply_headers (GMimeStream *stream, GMimeMessage *message) { - GMimeStream *stream_stdout = NULL; - - stream_stdout = g_mime_stream_file_new (stdout); - if (stream_stdout) { - g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE); - /* Output RFC 2822 formatted (and RFC 2047 encoded) headers. */ - g_mime_object_write_to_stream (GMIME_OBJECT(message), stream_stdout); - g_object_unref(stream_stdout); + /* Output RFC 2822 formatted (and RFC 2047 encoded) headers. */ + if (g_mime_object_write_to_stream (GMIME_OBJECT(message), stream) < 0) { + INTERNAL_ERROR("failed to write headers to stdout\n"); } } static void -format_part_reply (mime_node_t *node) +format_part_reply (GMimeStream *stream, mime_node_t *node) { int i; if (node->envelope_file) { - printf ("On %s, %s wrote:\n", - notmuch_message_get_header (node->envelope_file, "date"), - notmuch_message_get_header (node->envelope_file, "from")); + g_mime_stream_printf (stream, "On %s, %s wrote:\n", + notmuch_message_get_header (node->envelope_file, "date"), + notmuch_message_get_header (node->envelope_file, "from")); } else if (GMIME_IS_MESSAGE (node->part)) { GMimeMessage *message = GMIME_MESSAGE (node->part); InternetAddressList *recipients; - const char *recipients_string; + char *recipients_string; - printf ("> From: %s\n", g_mime_message_get_sender (message)); + g_mime_stream_printf (stream, "> From: %s\n", g_mime_message_get_sender (message)); recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO); recipients_string = internet_address_list_to_string (recipients, 0); if (recipients_string) - printf ("> To: %s\n", - recipients_string); + g_mime_stream_printf (stream, "> To: %s\n", + recipients_string); + g_free (recipients_string); recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC); recipients_string = internet_address_list_to_string (recipients, 0); if (recipients_string) - printf ("> Cc: %s\n", - recipients_string); - printf ("> Subject: %s\n", g_mime_message_get_subject (message)); - printf ("> Date: %s\n", g_mime_message_get_date_as_string (message)); - printf (">\n"); + g_mime_stream_printf (stream, "> Cc: %s\n", + recipients_string); + g_free (recipients_string); + g_mime_stream_printf (stream, "> Subject: %s\n", g_mime_message_get_subject (message)); + g_mime_stream_printf (stream, "> Date: %s\n", g_mime_message_get_date_as_string (message)); + g_mime_stream_printf (stream, ">\n"); } else if (GMIME_IS_PART (node->part)) { GMimeContentType *content_type = g_mime_object_get_content_type (node->part); GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (node->part); @@ -75,24 +72,21 @@ format_part_reply (mime_node_t *node) /* Ignore PGP/MIME cruft parts */ } else if (g_mime_content_type_is_type (content_type, "text", "*") && !g_mime_content_type_is_type (content_type, "text", "html")) { - GMimeStream *stream_stdout = g_mime_stream_file_new (stdout); - g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE); - show_text_part_content (node->part, stream_stdout, NOTMUCH_SHOW_TEXT_PART_REPLY); - g_object_unref(stream_stdout); + show_text_part_content (node->part, stream, NOTMUCH_SHOW_TEXT_PART_REPLY); } else if (disposition && strcasecmp (g_mime_content_disposition_get_disposition (disposition), GMIME_DISPOSITION_ATTACHMENT) == 0) { const char *filename = g_mime_part_get_filename (GMIME_PART (node->part)); - printf ("Attachment: %s (%s)\n", filename, - g_mime_content_type_to_string (content_type)); + g_mime_stream_printf (stream, "Attachment: %s (%s)\n", filename, + g_mime_content_type_to_string (content_type)); } else { - printf ("Non-text part: %s\n", - g_mime_content_type_to_string (content_type)); + g_mime_stream_printf (stream, "Non-text part: %s\n", + g_mime_content_type_to_string (content_type)); } } for (i = 0; i < node->nchildren; i++) - format_part_reply (mime_node_child (node, i)); + format_part_reply (stream, mime_node_child (node, i)); } typedef enum { @@ -337,6 +331,12 @@ add_recipients_from_message (GMimeMessage *reply, GMimeMessage *message, notmuch_bool_t reply_all) { + + /* There is a memory leak here with gmime-2.6 because get_sender + * returns a newly allocated list, while the others return + * references to libgmime owned data. This leak will be fixed with + * the transition to gmime-3.0. + */ struct { InternetAddressList * (*get_header)(GMimeMessage *message); GMimeRecipientType recipient_type; @@ -630,12 +630,12 @@ static int do_reply(notmuch_config_t *config, if (format == FORMAT_JSON || format == FORMAT_SEXP) { unsigned count; - status = notmuch_query_count_messages_st (query, &count); + status = notmuch_query_count_messages (query, &count); if (print_status_query ("notmuch reply", query, status)) return 1; if (count != 1) { - fprintf (stderr, "Error: search term did not match precisely one message (matched %d messages).\n", count); + fprintf (stderr, "Error: search term did not match precisely one message (matched %u messages).\n", count); return 1; } @@ -645,7 +645,7 @@ static int do_reply(notmuch_config_t *config, sp = sprinter_sexp_create (config, stdout); } - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (print_status_query ("notmuch reply", query, status)) return 1; @@ -678,9 +678,14 @@ static int do_reply(notmuch_config_t *config, /* End */ sp->end (sp); } else { - show_reply_headers (reply); - if (format == FORMAT_DEFAULT) - format_part_reply (node); + GMimeStream *stream_stdout = stream_stdout = g_mime_stream_stdout_new (); + if (stream_stdout) { + show_reply_headers (stream_stdout, reply); + if (format == FORMAT_DEFAULT) + format_part_reply (stream_stdout, node); + } + g_mime_stream_flush (stream_stdout); + g_object_unref(stream_stdout); } g_object_unref (G_OBJECT (reply)); @@ -701,11 +706,6 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]) int opt_index; notmuch_show_params_t params = { .part = -1, - .crypto = { - .verify = FALSE, - .decrypt = FALSE, - .gpgpath = NULL - } }; int format = FORMAT_DEFAULT; int reply_all = TRUE; diff --git a/notmuch-search.c b/notmuch-search.c index 8c65d5ad..019e14ee 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -123,7 +123,7 @@ do_search_threads (search_context_t *ctx) if (ctx->offset < 0) { unsigned count; notmuch_status_t status; - status = notmuch_query_count_threads_st (ctx->query, &count); + status = notmuch_query_count_threads (ctx->query, &count); if (print_status_query ("notmuch search", ctx->query, status)) return 1; @@ -132,7 +132,7 @@ do_search_threads (search_context_t *ctx) ctx->offset = 0; } - status = notmuch_query_search_threads_st (ctx->query, &threads); + status = notmuch_query_search_threads (ctx->query, &threads); if (print_status_query("notmuch search", ctx->query, status)) return 1; @@ -529,7 +529,7 @@ do_search_messages (search_context_t *ctx) if (ctx->offset < 0) { unsigned count; notmuch_status_t status; - status = notmuch_query_count_messages_st (ctx->query, &count); + status = notmuch_query_count_messages (ctx->query, &count); if (print_status_query ("notmuch search", ctx->query, status)) return 1; @@ -538,7 +538,7 @@ do_search_messages (search_context_t *ctx) ctx->offset = 0; } - status = notmuch_query_search_messages_st (ctx->query, &messages); + status = notmuch_query_search_messages (ctx->query, &messages); if (print_status_query ("notmuch search", ctx->query, status)) return 1; @@ -629,7 +629,7 @@ do_search_tags (const search_context_t *ctx) tags = notmuch_database_get_all_tags (notmuch); } else { notmuch_status_t status; - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (print_status_query ("notmuch search", query, status)) return 1; @@ -735,11 +735,19 @@ _notmuch_search_prepare (search_context_t *ctx, notmuch_config_t *config, int ar if (ctx->exclude != NOTMUCH_EXCLUDE_FALSE) { const char **search_exclude_tags; size_t search_exclude_tags_length; + notmuch_status_t status; search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_length); - for (i = 0; i < search_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (ctx->query, search_exclude_tags[i]); + + for (i = 0; i < search_exclude_tags_length; i++) { + status = notmuch_query_add_tag_exclude (ctx->query, search_exclude_tags[i]); + if (status && status != NOTMUCH_STATUS_IGNORED) { + print_status_query ("notmuch search", ctx->query, status); + return EXIT_FAILURE; + } + } + notmuch_query_set_omit_excluded (ctx->query, ctx->exclude); } diff --git a/notmuch-show.c b/notmuch-show.c index 1954096d..3ce4b63c 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -22,48 +22,6 @@ #include "gmime-filter-reply.h" #include "sprinter.h" -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); - -static const notmuch_show_format_t format_text = { - .new_sprinter = sprinter_text_create, - .part = format_part_text, -}; - -static notmuch_status_t -format_part_sprinter_entry (const void *ctx, sprinter_t *sp, mime_node_t *node, - int indent, const notmuch_show_params_t *params); - -static const notmuch_show_format_t format_json = { - .new_sprinter = sprinter_json_create, - .part = format_part_sprinter_entry, -}; - -static const notmuch_show_format_t format_sexp = { - .new_sprinter = sprinter_sexp_create, - .part = format_part_sprinter_entry, -}; - -static notmuch_status_t -format_part_mbox (const void *ctx, sprinter_t *sp, mime_node_t *node, - int indent, const notmuch_show_params_t *params); - -static const notmuch_show_format_t format_mbox = { - .new_sprinter = sprinter_text_create, - .part = format_part_mbox, -}; - -static notmuch_status_t -format_part_raw (unused (const void *ctx), sprinter_t *sp, mime_node_t *node, - unused (int indent), - unused (const notmuch_show_params_t *params)); - -static const notmuch_show_format_t format_raw = { - .new_sprinter = sprinter_text_create, - .part = format_part_raw, -}; - static const char * _get_tags_as_string (const void *ctx, notmuch_message_t *message) { @@ -468,6 +426,7 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, GMIME_OBJECT (node->envelope_part) : node->part; GMimeContentType *content_type = g_mime_object_get_content_type (meta); const notmuch_bool_t leaf = GMIME_IS_PART (node->part); + GMimeStream *stream = params->out_stream; const char *part_type; int i; @@ -475,13 +434,13 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, notmuch_message_t *message = node->envelope_file; part_type = "message"; - printf ("\f%s{ id:%s depth:%d match:%d excluded:%d filename:%s\n", - part_type, - notmuch_message_get_message_id (message), - indent, - notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? 1 : 0, - notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0, - notmuch_message_get_filename (message)); + g_mime_stream_printf (stream, "\f%s{ id:%s depth:%d match:%d excluded:%d filename:%s\n", + part_type, + notmuch_message_get_message_id (message), + indent, + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? 1 : 0, + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0, + notmuch_message_get_filename (message)); } else { char *content_string; const char *disposition = _get_disposition (meta); @@ -495,14 +454,14 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, else part_type = "part"; - printf ("\f%s{ ID: %d", part_type, node->part_num); + g_mime_stream_printf (stream, "\f%s{ ID: %d", part_type, node->part_num); if (filename) - printf (", Filename: %s", filename); + g_mime_stream_printf (stream, ", Filename: %s", filename); if (cid) - printf (", Content-id: %s", cid); + g_mime_stream_printf (stream, ", Content-id: %s", cid); content_string = g_mime_content_type_to_string (content_type); - printf (", Content-type: %s\n", content_string); + g_mime_stream_printf (stream, ", Content-type: %s\n", content_string); g_free (content_string); } @@ -512,40 +471,37 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, char *recipients_string; char *date_string; - printf ("\fheader{\n"); + g_mime_stream_printf (stream, "\fheader{\n"); if (node->envelope_file) - printf ("%s\n", _get_one_line_summary (ctx, node->envelope_file)); - printf ("Subject: %s\n", g_mime_message_get_subject (message)); - printf ("From: %s\n", g_mime_message_get_sender (message)); + g_mime_stream_printf (stream, "%s\n", _get_one_line_summary (ctx, node->envelope_file)); + g_mime_stream_printf (stream, "Subject: %s\n", g_mime_message_get_subject (message)); + g_mime_stream_printf (stream, "From: %s\n", g_mime_message_get_sender (message)); recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO); recipients_string = internet_address_list_to_string (recipients, 0); if (recipients_string) - printf ("To: %s\n", recipients_string); + g_mime_stream_printf (stream, "To: %s\n", recipients_string); g_free (recipients_string); recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC); recipients_string = internet_address_list_to_string (recipients, 0); if (recipients_string) - printf ("Cc: %s\n", recipients_string); + g_mime_stream_printf (stream, "Cc: %s\n", recipients_string); g_free (recipients_string); date_string = g_mime_message_get_date_as_string (message); - printf ("Date: %s\n", date_string); + g_mime_stream_printf (stream, "Date: %s\n", date_string); g_free (date_string); - printf ("\fheader}\n"); + g_mime_stream_printf (stream, "\fheader}\n"); - printf ("\fbody{\n"); + g_mime_stream_printf (stream, "\fbody{\n"); } if (leaf) { if (g_mime_content_type_is_type (content_type, "text", "*") && !g_mime_content_type_is_type (content_type, "text", "html")) { - GMimeStream *stream_stdout = g_mime_stream_file_new (stdout); - g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE); - show_text_part_content (node->part, stream_stdout, 0); - g_object_unref(stream_stdout); + show_text_part_content (node->part, stream, 0); } else { char *content_string = g_mime_content_type_to_string (content_type); - printf ("Non-text part: %s\n", content_string); + g_mime_stream_printf (stream, "Non-text part: %s\n", content_string); g_free (content_string); } } @@ -554,9 +510,9 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, format_part_text (ctx, sp, mime_node_child (node, i), indent, params); if (GMIME_IS_MESSAGE (node->part)) - printf ("\fbody}\n"); + g_mime_stream_printf (stream, "\fbody}\n"); - printf ("\f%s}\n", part_type); + g_mime_stream_printf (stream, "\f%s}\n", part_type); return NOTMUCH_STATUS_SUCCESS; } @@ -783,7 +739,7 @@ format_part_mbox (const void *ctx, unused (sprinter_t *sp), mime_node_t *node, static notmuch_status_t format_part_raw (unused (const void *ctx), unused (sprinter_t *sp), mime_node_t *node, unused (int indent), - unused (const notmuch_show_params_t *params)) + const notmuch_show_params_t *params) { if (node->envelope_file) { /* Special case the entire message to avoid MIME parsing. */ @@ -823,13 +779,7 @@ format_part_raw (unused (const void *ctx), unused (sprinter_t *sp), return NOTMUCH_STATUS_SUCCESS; } - GMimeStream *stream_stdout; - GMimeStream *stream_filter = NULL; - - stream_stdout = g_mime_stream_file_new (stdout); - g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE); - - stream_filter = g_mime_stream_filter_new (stream_stdout); + GMimeStream *stream_filter = g_mime_stream_filter_new (params->out_stream); if (GMIME_IS_PART (node->part)) { /* For leaf parts, we emit only the transfer-decoded @@ -852,9 +802,6 @@ format_part_raw (unused (const void *ctx), unused (sprinter_t *sp), if (stream_filter) g_object_unref (stream_filter); - if (stream_stdout) - g_object_unref(stream_stdout); - return NOTMUCH_STATUS_SUCCESS; } @@ -950,16 +897,16 @@ do_show_single (void *ctx, notmuch_status_t status; unsigned int count; - status = notmuch_query_count_messages_st (query, &count); + status = notmuch_query_count_messages (query, &count); if (print_status_query ("notmuch show", query, status)) return 1; if (count != 1) { - fprintf (stderr, "Error: search term did not match precisely one message (matched %d messages).\n", count); + fprintf (stderr, "Error: search term did not match precisely one message (matched %u messages).\n", count); return 1; } - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (print_status_query ("notmuch show", query, status)) return 1; @@ -989,7 +936,7 @@ do_show (void *ctx, notmuch_messages_t *messages; notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS; - status= notmuch_query_search_threads_st (query, &threads); + status= notmuch_query_search_threads (query, &threads); if (print_status_query ("notmuch show", query, status)) return 1; @@ -1029,10 +976,43 @@ enum { NOTMUCH_FORMAT_RAW }; +static const notmuch_show_format_t format_json = { + .new_sprinter = sprinter_json_create, + .part = format_part_sprinter_entry, +}; + +static const notmuch_show_format_t format_sexp = { + .new_sprinter = sprinter_sexp_create, + .part = format_part_sprinter_entry, +}; + +static const notmuch_show_format_t format_text = { + .new_sprinter = sprinter_text_create, + .part = format_part_text, +}; + +static const notmuch_show_format_t format_mbox = { + .new_sprinter = sprinter_text_create, + .part = format_part_mbox, +}; + +static const notmuch_show_format_t format_raw = { + .new_sprinter = sprinter_text_create, + .part = format_part_raw, +}; + +static const notmuch_show_format_t *formatters[] = { + [NOTMUCH_FORMAT_JSON] = &format_json, + [NOTMUCH_FORMAT_SEXP] = &format_sexp, + [NOTMUCH_FORMAT_TEXT] = &format_text, + [NOTMUCH_FORMAT_MBOX] = &format_mbox, + [NOTMUCH_FORMAT_RAW] = &format_raw, +}; + enum { - ENTIRE_THREAD_DEFAULT, - ENTIRE_THREAD_TRUE, - ENTIRE_THREAD_FALSE, + ENTIRE_THREAD_DEFAULT = -1, + ENTIRE_THREAD_FALSE = FALSE, + ENTIRE_THREAD_TRUE = TRUE, }; /* The following is to allow future options to be added more easily */ @@ -1048,25 +1028,20 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) notmuch_query_t *query; char *query_string; int opt_index, ret; - const notmuch_show_format_t *format = &format_text; + const notmuch_show_format_t *formatter; sprinter_t *sprinter; notmuch_show_params_t params = { .part = -1, .omit_excluded = TRUE, .output_body = TRUE, - .crypto = { - .verify = FALSE, - .decrypt = FALSE, - .gpgpath = NULL - }, - .include_html = FALSE }; - int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED; + int format = NOTMUCH_FORMAT_NOT_SPECIFIED; int exclude = EXCLUDE_TRUE; int entire_thread = ENTIRE_THREAD_DEFAULT; + notmuch_bool_t single_message; notmuch_opt_desc_t options[] = { - { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f', + { NOTMUCH_OPT_KEYWORD, &format, "format", 'f', (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON }, { "text", NOTMUCH_FORMAT_TEXT }, { "sexp", NOTMUCH_FORMAT_SEXP }, @@ -1102,40 +1077,25 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) if (params.crypto.decrypt) params.crypto.verify = TRUE; - if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) { + /* specifying a part implies single message display */ + single_message = params.part >= 0; + + if (format == NOTMUCH_FORMAT_NOT_SPECIFIED) { /* if part was requested and format was not specified, use format=raw */ if (params.part >= 0) - format_sel = NOTMUCH_FORMAT_RAW; + format = NOTMUCH_FORMAT_RAW; else - format_sel = NOTMUCH_FORMAT_TEXT; + format = NOTMUCH_FORMAT_TEXT; } - switch (format_sel) { - case NOTMUCH_FORMAT_JSON: - format = &format_json; - break; - case NOTMUCH_FORMAT_TEXT: - format = &format_text; - break; - case NOTMUCH_FORMAT_SEXP: - format = &format_sexp; - break; - case NOTMUCH_FORMAT_MBOX: + if (format == NOTMUCH_FORMAT_MBOX) { if (params.part > 0) { fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n"); return EXIT_FAILURE; } - - format = &format_mbox; - break; - case NOTMUCH_FORMAT_RAW: - format = &format_raw; - /* If --format=raw specified without specifying part, we can only - * output single message, so set part=0 */ - if (params.part < 0) - params.part = 0; - params.raw = TRUE; - break; + } else if (format == NOTMUCH_FORMAT_RAW) { + /* raw format only supports single message display */ + single_message = TRUE; } notmuch_exit_if_unsupported_format (); @@ -1143,10 +1103,12 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) /* Default is entire-thread = FALSE except for format=json and * format=sexp. */ if (entire_thread == ENTIRE_THREAD_DEFAULT) { - if (format == &format_json || format == &format_sexp) - entire_thread = ENTIRE_THREAD_TRUE; + if (format == NOTMUCH_FORMAT_JSON || format == NOTMUCH_FORMAT_SEXP) + params.entire_thread = TRUE; else - entire_thread = ENTIRE_THREAD_FALSE; + params.entire_thread = FALSE; + } else { + params.entire_thread = entire_thread; } if (!params.output_body) { @@ -1154,22 +1116,17 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) fprintf (stderr, "Warning: --body=false is incompatible with --part > 0. Disabling.\n"); params.output_body = TRUE; } else { - if (format != &format_json && format != &format_sexp) + if (format != NOTMUCH_FORMAT_JSON && format != NOTMUCH_FORMAT_SEXP) fprintf (stderr, "Warning: --body=false only implemented for format=json and format=sexp\n"); } } if (params.include_html && - (format_sel != NOTMUCH_FORMAT_JSON && format_sel != NOTMUCH_FORMAT_SEXP)) { + (format != NOTMUCH_FORMAT_JSON && format != NOTMUCH_FORMAT_SEXP)) { fprintf (stderr, "Warning: --include-html only implemented for format=json and format=sexp\n"); } - if (entire_thread == ENTIRE_THREAD_TRUE) - params.entire_thread = TRUE; - else - params.entire_thread = FALSE; - query_string = query_string_from_args (config, argc-opt_index, argv+opt_index); if (query_string == NULL) { fprintf (stderr, "Out of memory\n"); @@ -1196,32 +1153,47 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) } /* Create structure printer. */ - sprinter = format->new_sprinter(config, stdout); + formatter = formatters[format]; + sprinter = formatter->new_sprinter(config, stdout); + + params.out_stream = g_mime_stream_stdout_new (); /* If a single message is requested we do not use search_excludes. */ - if (params.part >= 0) - ret = do_show_single (config, query, format, sprinter, ¶ms); - else { + if (single_message) { + ret = do_show_single (config, query, formatter, sprinter, ¶ms); + } else { /* We always apply set the exclude flag. The * exclude=true|false option controls whether or not we return * threads that only match in an excluded message */ const char **search_exclude_tags; size_t search_exclude_tags_length; unsigned int i; + notmuch_status_t status; search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_length); - for (i = 0; i < search_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); + + for (i = 0; i < search_exclude_tags_length; i++) { + status = notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); + if (status && status != NOTMUCH_STATUS_IGNORED) { + print_status_query ("notmuch show", query, status); + ret = -1; + goto DONE; + } + } if (exclude == EXCLUDE_FALSE) { notmuch_query_set_omit_excluded (query, FALSE); params.omit_excluded = FALSE; } - ret = do_show (config, query, format, sprinter, ¶ms); + ret = do_show (config, query, formatter, sprinter, ¶ms); } + DONE: + g_mime_stream_flush (params.out_stream); + g_object_unref (params.out_stream); + notmuch_crypto_cleanup (¶ms.crypto); notmuch_query_destroy (query); notmuch_database_destroy (notmuch); diff --git a/notmuch-tag.c b/notmuch-tag.c index 18d78ddd..9c03754d 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -121,7 +121,7 @@ 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); - status = notmuch_query_search_messages_st (query, &messages); + status = notmuch_query_search_messages (query, &messages); if (print_status_query ("notmuch tag", query, status)) return status; diff --git a/performance-test/M02-show.sh b/performance-test/M02-show.sh new file mode 100755 index 00000000..d73035ea --- /dev/null +++ b/performance-test/M02-show.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +test_description='show' + +. ./perf-test-lib.sh || exit 1 + +memory_start + +memory_run 'show *' "notmuch show '*' 1>/dev/null" +memory_run 'show --format=json *' "notmuch show --format=json '*' 1>/dev/null" +memory_run 'show --format=sexp *' "notmuch show --format=sexp '*' 1>/dev/null" + +memory_done diff --git a/performance-test/M03-search.sh b/performance-test/M03-search.sh new file mode 100755 index 00000000..8d026eee --- /dev/null +++ b/performance-test/M03-search.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +test_description='search' + +. ./perf-test-lib.sh || exit 1 + +memory_start + +memory_run 'search *' "notmuch search '*' 1>/dev/null" +memory_run 'search --format=json *' "notmuch search --format=json '*' 1>/dev/null" +memory_run 'search --format=sexp *' "notmuch search --format=sexp '*' 1>/dev/null" + +memory_done diff --git a/performance-test/M04-reply.sh b/performance-test/M04-reply.sh new file mode 100755 index 00000000..0e1ce087 --- /dev/null +++ b/performance-test/M04-reply.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +test_description='search' + +. ./perf-test-lib.sh || exit 1 + +memory_start + +for id in $(notmuch search --output=messages '*' | shuf -n 5); do + memory_run "reply $id" "notmuch reply \"$id\" 1>/dev/null" + memory_run "reply --format=json $id" "notmuch reply --format=json \"$id\" 1>/dev/null" + memory_run "reply --format=sexp $id" "notmuch reply --format=sexp \"$id\" 1>/dev/null" +done + +memory_done diff --git a/performance-test/perf-test-lib.sh b/performance-test/perf-test-lib.sh index 00d2f1c6..c89d5aab 100644 --- a/performance-test/perf-test-lib.sh +++ b/performance-test/perf-test-lib.sh @@ -149,7 +149,7 @@ memory_run () printf "[ %d ]\t%s\n" $test_count "$1" - NOTMUCH_TALLOC_REPORT="$talloc_log" valgrind --leak-check=full --log-file="$log_file" $2 + NOTMUCH_TALLOC_REPORT="$talloc_log" eval "valgrind --leak-check=full --log-file='$log_file' $2" awk '/LEAK SUMMARY/,/suppressed/ { sub(/^==[0-9]*==/," "); print }' "$log_file" echo diff --git a/tag-util.c b/tag-util.c index 343c161f..d9fca7b8 100644 --- a/tag-util.c +++ b/tag-util.c @@ -28,13 +28,15 @@ line_error (tag_parse_status_t status, fprintf (stderr, status < 0 ? "Error: " : "Warning: "); vfprintf (stderr, format, va_args); fprintf (stderr, " [%s]\n", line); + + va_end (va_args); + return status; } const char * illegal_tag (const char *tag, notmuch_bool_t remove) { - if (*tag == '\0' && ! remove) return "empty tag forbidden"; @@ -155,7 +157,6 @@ tag_parse_status_t parse_tag_command_line (void *ctx, int argc, char **argv, char **query_str, tag_op_list_t *tag_ops) { - int i; for (i = 0; i < argc; i++) { @@ -202,6 +203,8 @@ message_error (notmuch_message_t *message, vfprintf (stderr, format, va_args); fprintf (stderr, "Message-ID: %s\n", notmuch_message_get_message_id (message)); fprintf (stderr, "Status: %s\n", notmuch_status_to_string (status)); + + va_end (va_args); } static int @@ -209,14 +212,12 @@ makes_changes (notmuch_message_t *message, tag_op_list_t *list, tag_op_flag_t flags) { - size_t i; notmuch_tags_t *tags; notmuch_bool_t changes = FALSE; /* First, do we delete an existing tag? */ - changes = FALSE; for (tags = notmuch_message_get_tags (message); ! changes && notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) { diff --git a/test/Makefile.local b/test/Makefile.local index f8cf90d0..0df72c92 100644 --- a/test/Makefile.local +++ b/test/Makefile.local @@ -12,15 +12,15 @@ smtp_dummy_srcs = \ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o) -$(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a +$(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libnotmuch_util.a $(call quiet,CC) $^ -o $@ $(LDFLAGS) -$(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a +$(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libnotmuch_util.a $(call quiet,CC) $^ -o $@ $(LDFLAGS) $(TALLOC_LDFLAGS) random_corpus_deps = $(dir)/random-corpus.o $(dir)/database-test.o \ notmuch-config.o status.o command-line-arguments.o \ - lib/libnotmuch.a util/libutil.a \ + lib/libnotmuch.a util/libnotmuch_util.a \ parse-time-string/libparse-time-string.a $(dir)/random-corpus: $(random_corpus_deps) @@ -61,7 +61,7 @@ test-binaries: $(TEST_BINARIES) test: all test-binaries ifeq ($V,) - @echo 'Use "$(MAKE) V=1" to print test headings and PASSing results.' + @echo 'Use "$(MAKE) V=1" to see the details for passing and known broken tests.' @env NOTMUCH_TEST_QUIET=1 ${test_src_dir}/notmuch-test $(OPTIONS) else # The user has explicitly enabled quiet execution. diff --git a/test/README b/test/README index 104a120e..f2499bce 100644 --- a/test/README +++ b/test/README @@ -33,6 +33,17 @@ chosen directory to your PATH before running the tests. e.g. env PATH=/opt/gnu/bin:$PATH make test +For FreeBSD you need to install latest gdb from ports or packages and +provide path to it in TEST_GDB environment variable before executing +the tests, native FreeBSD gdb does not not work. If you install +coreutils, which provides GNU versions of basic utils like 'date' and +'base64' on FreeBSD, the test suite will use these instead of the +native ones. This provides robustness against portability issues with +these system tools. Most often the tests are written, reviewed and +tested on Linux system so such portability issues arise from time to +time. + + Running Tests ------------- The easiest way to run tests is to say "make test", (or simply run the @@ -189,16 +200,21 @@ Test harness library There are a handful helper functions defined in the test harness library for your script to use. - test_expect_success