From: David Bremner Date: Sun, 2 Jul 2017 13:50:17 +0000 (-0300) Subject: Merge branch 'debian' X-Git-Tag: 0.25_rc0~45 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=ab022657776af0bb47e72caf2517464ca59e7d48;hp=68173a1dc5b1f6408525996467f7dd3025e3f0c6 Merge branch 'debian' merge in changes from 0.23.7-3 debian upload --- 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 4c0e8c62..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,7 +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 new file mode 100644 index 00000000..cae4c7d1 --- /dev/null +++ b/Makefile.global @@ -0,0 +1,65 @@ +# Here's the (hopefully simple) versioning scheme. +# +# Releases of notmuch have a two-digit version (0.1, 0.2, etc.). We +# increment the second digit for each release and increment the first +# digit when we reach particularly major milestones of usability. +# +# Between releases, (such as when compiling notmuch from the git +# repository), we let git append identification of the actual commit. +PACKAGE=notmuch + +IS_GIT:=$(if $(wildcard ${srcdir}/.git),yes,no) + +ifeq ($(IS_GIT),yes) +DATE:=$(shell git --git-dir=${srcdir}/.git log --date=short -1 --pretty=format:%cd) +else +DATE:=$(shell date +%F) +endif + +VERSION:=$(shell cat ${srcdir}/version) +ELPA_VERSION:=$(subst ~,_,$(VERSION)) +ifeq ($(filter release release-message pre-release update-versions,$(MAKECMDGOALS)),) +ifeq ($(IS_GIT),yes) +VERSION:=$(shell git --git-dir=${srcdir}/.git describe --abbrev=7 --match '[0-9.]*'|sed -e s/_/~/ -e s/-/+/ -e s/-/~/) +# drop the ~g$sha1 part +ELPA_VERSION:=$(word 1,$(subst ~, ,$(VERSION))) +# convert git version to package.el friendly form +ELPA_VERSION:=$(subst +,snapshot,$(ELPA_VERSION)) + +# Write the file 'version.stamp' in case its contents differ from $(VERSION) +FILE_VERSION:=$(shell test -f version.stamp && read vs < version.stamp || vs=; echo $$vs) +ifneq ($(FILE_VERSION),$(VERSION)) + $(shell echo "$(VERSION)" > version.stamp) +endif +endif +endif + +UPSTREAM_TAG=$(subst ~,_,$(VERSION)) +DEB_TAG=debian/$(UPSTREAM_TAG)-1 + +RELEASE_HOST=notmuchmail.org +RELEASE_DIR=/srv/notmuchmail.org/www/releases +RELEASE_URL=https://notmuchmail.org/releases +TAR_FILE=$(PACKAGE)-$(VERSION).tar.gz +ELPA_FILE:=$(PACKAGE)-emacs-$(ELPA_VERSION).tar +DEB_TAR_FILE=$(PACKAGE)_$(VERSION).orig.tar.gz +SHA256_FILE=$(TAR_FILE).sha256 +GPG_FILE=$(SHA256_FILE).asc + +PV_FILE=bindings/python/notmuch/version.py + +# Smash together user's values with our extra values +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 -lnotmuch_util -Llib -lnotmuch +ifeq ($(LIBDIR_IN_LDCONFIG),0) +FINAL_NOTMUCH_LDFLAGS += $(RPATH_LDFLAGS) +endif +FINAL_NOTMUCH_LDFLAGS += $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS) $(ZLIB_LDFLAGS) +FINAL_NOTMUCH_LINKER = CC +ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1) +FINAL_NOTMUCH_LDFLAGS += $(CONFIGURE_LDFLAGS) +FINAL_NOTMUCH_LINKER = CXX +endif +FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(CONFIGURE_LDFLAGS) diff --git a/Makefile.local b/Makefile.local index 0a122ab0..6bc78ef8 100644 --- a/Makefile.local +++ b/Makefile.local @@ -1,67 +1,5 @@ # -*- makefile -*- -# Here's the (hopefully simple) versioning scheme. -# -# Releases of notmuch have a two-digit version (0.1, 0.2, etc.). We -# increment the second digit for each release and increment the first -# digit when we reach particularly major milestones of usability. -# -# Between releases, (such as when compiling notmuch from the git -# repository), we let git append identification of the actual commit. -PACKAGE=notmuch - -IS_GIT:=$(if $(wildcard ${srcdir}/.git),yes,no) - -ifeq ($(IS_GIT),yes) -DATE:=$(shell git --git-dir=${srcdir}/.git log --date=short -1 --pretty=format:%cd) -else -DATE:=$(shell date +%F) -endif - -VERSION:=$(shell cat ${srcdir}/version) -ELPA_VERSION:=$(subst ~,_,$(VERSION)) -ifeq ($(filter release release-message pre-release update-versions,$(MAKECMDGOALS)),) -ifeq ($(IS_GIT),yes) -VERSION:=$(shell git --git-dir=${srcdir}/.git describe --abbrev=7 --match '[0-9.]*'|sed -e s/_/~/ -e s/-/+/ -e s/-/~/) -# drop the ~g$sha1 part -ELPA_VERSION:=$(word 1,$(subst ~, ,$(VERSION))) -# Write the file 'version.stamp' in case its contents differ from $(VERSION) -FILE_VERSION:=$(shell test -f version.stamp && read vs < version.stamp || vs=; echo $$vs) -ifneq ($(FILE_VERSION),$(VERSION)) - $(shell echo "$(VERSION)" > version.stamp) -endif -endif -endif - -UPSTREAM_TAG=$(subst ~,_,$(VERSION)) -DEB_TAG=debian/$(UPSTREAM_TAG)-1 - -RELEASE_HOST=notmuchmail.org -RELEASE_DIR=/srv/notmuchmail.org/www/releases -RELEASE_URL=https://notmuchmail.org/releases -TAR_FILE=$(PACKAGE)-$(VERSION).tar.gz -DEB_TAR_FILE=$(PACKAGE)_$(VERSION).orig.tar.gz -SHA1_FILE=$(TAR_FILE).sha1 -GPG_FILE=$(SHA1_FILE).asc - -PV_FILE=bindings/python/notmuch/version.py - -# Smash together user's values with our extra values -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 -ifeq ($(LIBDIR_IN_LDCONFIG),0) -FINAL_NOTMUCH_LDFLAGS += $(RPATH_LDFLAGS) -endif -FINAL_NOTMUCH_LDFLAGS += $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS) $(ZLIB_LDFLAGS) -FINAL_NOTMUCH_LINKER = CC -ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1) -FINAL_NOTMUCH_LDFLAGS += $(CONFIGURE_LDFLAGS) -FINAL_NOTMUCH_LINKER = CXX -endif -FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(CONFIGURE_LDFLAGS) - .PHONY: all all: notmuch notmuch-shared build-man ruby-bindings ifeq ($(MAKECMDGOALS),) @@ -93,17 +31,18 @@ $(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)" -$(SHA1_FILE): $(TAR_FILE) - sha1sum $^ > $@ +$(SHA256_FILE): $(TAR_FILE) + sha256sum $^ > $@ -$(GPG_FILE): $(SHA1_FILE) - @echo "Please enter your GPG password to sign the checksum." - gpg --armor --sign $^ +$(GPG_FILE): $(SHA256_FILE) + gpg --armor --sign $^ .PHONY: dist dist: $(TAR_FILE) @@ -133,11 +72,11 @@ release: verify-source-tree-and-version pristine-tar commit $(DEB_TAR_FILE) $(UPSTREAM_TAG) git tag -s -m "$(PACKAGE) Debian $(VERSION)-1 upload (same as $(VERSION))" $(DEB_TAG) mkdir -p releases - mv $(TAR_FILE) $(SHA1_FILE) $(GPG_FILE) releases + mv $(TAR_FILE) $(SHA256_FILE) $(GPG_FILE) releases $(MAKE) VERSION=$(VERSION) release-message > $(PACKAGE)-$(VERSION).announce ifeq ($(REALLY_UPLOAD),yes) git push origin $(VERSION) - cd releases && scp $(TAR_FILE) $(SHA1_FILE) $(GPG_FILE) $(RELEASE_HOST):$(RELEASE_DIR) + cd releases && scp $(TAR_FILE) $(SHA256_FILE) $(GPG_FILE) $(RELEASE_HOST):$(RELEASE_DIR) ssh $(RELEASE_HOST) "rm -f $(RELEASE_DIR)/LATEST-$(PACKAGE)-* ; ln -s $(TAR_FILE) $(RELEASE_DIR)/LATEST-$(TAR_FILE)" endif @echo "Please send a release announcement using $(PACKAGE)-$(VERSION).announce as a template." @@ -177,9 +116,9 @@ release-message: @echo "" @echo "Which can be verified with:" @echo "" - @echo " $(RELEASE_URL)/$(SHA1_FILE)" + @echo " $(RELEASE_URL)/$(SHA256_FILE)" @echo -n " " - @cat releases/$(SHA1_FILE) + @cat releases/$(SHA256_FILE) @echo "" @echo " $(RELEASE_URL)/$(GPG_FILE)" @echo " (signed by `getent passwd "$$USER" | cut -d: -f 5 | cut -d, -f 1`)" @@ -273,6 +212,7 @@ dataclean: distclean rm -rf $(DATACLEAN) notmuch_client_srcs = \ + $(notmuch_compat_srcs) \ command-line-arguments.c\ debugger.c \ status.c \ @@ -304,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) @@ -336,11 +276,6 @@ ifeq ($(WITH_EMACS), 1) endif endif -.PHONY: install-desktop -install-desktop: - mkdir -p "$(DESTDIR)$(desktop_dir)" - desktop-file-install --mode 0644 --dir "$(DESTDIR)$(desktop_dir)" notmuch.desktop - SRCS := $(SRCS) $(notmuch_client_srcs) CLEAN := $(CLEAN) notmuch notmuch-shared $(notmuch_client_modules) CLEAN := $(CLEAN) version.stamp notmuch-*.tar.gz.tmp diff --git a/NEWS b/NEWS index 7f25ca79..70bce788 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,166 @@ +Notmuch 0.24.2 (2017-06-01) +=========================== + +Command Line Interface +---------------------- + +Fix output from `notmuch dump --include=properties` to not include tags. + +Emacs +----- + +Fix filename stashing in tree view. + +Notmuch 0.24.1 (2017-04-01) +=========================== + +General +------- + +Fix regressions in non-regexp search for `from:` and `subject:`. + + The regexp search code in 0.24 introduced a regression in the + handling of empty queries and wildcards. These are both corrected in + this release. + +Command Line Interface +---------------------- + +Fix several memory leaks in `notmuch show`. + +Update NEWS for 0.24 to mention schema changes. + +Fix bug in dump header. + + The previous version of the dump header failed to mention the + inclusion of tags. This fix bumps the version number of the dump + format to 3. There are no other changes to the format. + +Library Changes +--------------- + +Fix a read-after-free in the library. + +Notmuch 0.24 (2017-03-12) +========================= + +General +------- + +Regular expression searches supported for `from:` and `subject:`. + + This requires recent Xapian (1.4+) See notmuch-search-terms(7) for + details. + +Command Line Interface +---------------------- + +Run external `notmuch-` prefixed commands as subcommands + + You can now add your own `notmuch-` prefixed commands in PATH, and + have notmuch run them as if they were notmuch commands. See the + `notmuch(1)` man page for details + +New default output format to 3 + + See devel/schemata for details. Users of the structured output + format are reminded of the `--format-version` argument to `notmuch + show` and `notmuch search` which can prevent breakage when the + default format changes. + +Emacs +----- + +Postpone and resume messages in `notmuch-message-mode` (composition) + + Notmuch now has built in support for postponing, saving and resuming + messages. The default bindings are C-x C-s to save a draft, C-c C-p + to postpone a draft (save and exit compose buffer), and "e" in show + or tree view to resume. + + Draft messages are tagged with `notmuch-draft-tags` (draft by + default) so you may wish to add that to the excluded tags list. When + saving a previously saved draft message the earlier draft gets + tagged deleted. + + Note that attachments added before postponing will be included as + they were when you postponed in the final message. + +Address Completion + + It is now possible to save the list of address completions for + notmuch's internal completion between runs of emacs. This makes the + first calls to address completion much better and faster. For + privacy reasons it is disabled by default, to enable set or + customize `notmuch-address-save-filename`. + +Tag jump menu + + It is now possible to configure tagging shortcuts (with an interface + like notmuch jump). For example (by default) k u will remove the + unread tag, and k s will add a tag "spam" and remove the inbox + tag. Pressing k twice will do the reverse operation so, for example, + k k s removes the spam tag and adds the inbox tag. See the customize + variable `notmuch-tagging-keys` for more information. + +Refresh all buffers + + It is now possible to refresh all notmuch buffers to reflect the + current state of the database with a single command, `M-=`. + +Stop display of application/* parts + + By default gnus displays all application/* parts such as + application/zip in the message buffer. This has several undesirable + effects for notmuch (security, triggering errors etc). Notmuch now + overrides this and does not display them by default. If you have + customized `mm-inline-override-types` then we assume you know what + you want and do not interfere; if you do want to stop the display of + application/* add application/* to your customization. If you want + to allow application/* then set `mm-inline-override-types` to + "non/existent". + +Small change in the api for notmuch-search-tag + + When `notmuch-search-tag` is called non-interactively and the region + is set, then it only tags the threads in the region. (Previously it + only tagged the current thread.) + +Bugfix for sending messages with very long headers. + + Previously emacs didn't fold very long headers when sending which + could cause the MTA to refuse to send the message. This makes sure + it does fold any long headers so the message is RFC compliant. + +`notmuch emacs-mua` command installed with the Emacs interface + + We've carried a `notmuch-emacs-mua` script in the source tree for + quite some time. It can be used to launch the Notmuch Emacs + interface from the command line in many different ways. Starting + with this release, it will be installed with the Emacs + interface. With the new external subcommand support, the script + transparently becomes a new notmuch command. See the + `notmuch-emacs-mua(1)` man page for details. + +Notmuch Emacs desktop integration + + The desktop integration file will now be installed with the Notmuch + Emacs interface, adding a Notmuch menu item and configuration to + allow the user to set up Notmuch Emacs as the `mailto:` URL handler. + +Library changes +--------------- + +`notmuch_query_count_messages` is now non-destructive. + + Internally the implementation of excludes has changed to make this + possible. + +Improved handling of DatabaseModifiedError + + Previously uncaught exceptions reading message metadata are now + handled. + Notmuch 0.23.7 (2017-02-28) =========================== 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 e1a49522..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.23.7' -SOVERSION = '4' +__VERSION__ = '0.24.2' +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/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index 78047b5f..e4e4b36b 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -58,6 +58,34 @@ _notmuch_email() sed 's/[^<]*<\([^>]*\)>/\1/' | tr "[:upper:]" "[:lower:]" | sort -u } +_notmuch_mimetype() +{ + # use mime types from mime-support package if available, and fall + # back to a handful of common ones otherwise + if [ -r "/etc/mime.types" ]; then + sed -n '/^[[:alpha:]]/{s/[[:space:]].*//;p;}' /etc/mime.types + else + cat < 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 @@ -456,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" @@ -483,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 @@ -602,6 +636,16 @@ if [ $WITH_DOCS = "1" ] ; then fi fi +if [ $WITH_DESKTOP = "1" ]; then + printf "Checking if desktop-file-install is available... " + if command -v desktop-file-install > /dev/null; then + printf "Yes.\n" + else + printf "No (so will not install .desktop file).\n" + WITH_DESKTOP=0 + fi +fi + libdir_in_ldconfig=0 printf "Checking which platform we are on... " @@ -660,19 +704,6 @@ else EOF fi -printf "Checking byte order... " -cat> _byteorder.c < -#include -uint32_t test = 0x34333231; -int main() { printf("%.4s\n", (const char*)&test); return 0; } -EOF -${CC} ${CFLAGS} _byteorder.c -o _byteorder > /dev/null 2>&1 -util_byte_order=$(./_byteorder) -echo $util_byte_order - -rm -f _byteorder _byteorder.c - if [ $errors -gt 0 ]; then cat < Makefile.config < sh.config < Thu, 01 Jun 2017 07:24:55 -0300 + +notmuch (0.24.1-1) experimental; urgency=medium + + * Restore Xapian wildcard queries to from: and subject: + * Handle empty queries for from: and subject: + * Memory leaks in notmuch show fixed + * Fix bug notmuch dump header generation + + -- David Bremner Sat, 01 Apr 2017 09:17:47 -0300 + +notmuch (0.24-1) experimental; urgency=medium + + * New upstream release + - regexp search for from: and subject: + - Emacs interface improvements: + - draft handling + - don't automatically expand application/* + - jump (shortcut) menu for tagging. + - fold long headers when sending + - library improvements + - catch some stray DatabaseModifiedErrors + - make exclude handling non-destructive. + + -- David Bremner Sun, 12 Mar 2017 22:14:25 -0300 + +notmuch (0.24~rc1-1) experimental; urgency=medium + + * New upstream release candidate + * upstream release notes + * One library internals fix/optimization for regexp processing. + + -- David Bremner Wed, 08 Mar 2017 08:08:34 -0400 + +notmuch (0.24~rc0-1) experimental; urgency=medium + + * New upstream feature release (candidate). + + -- David Bremner 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 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 c8a94ba6..00000000 --- a/debian/libnotmuch4.symbols +++ /dev/null @@ -1,122 +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++|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++|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/devel/emacs-keybindings.org b/devel/emacs-keybindings.org new file mode 100644 index 00000000..464b9467 --- /dev/null +++ b/devel/emacs-keybindings.org @@ -0,0 +1,58 @@ +|-----------+----------------------------------------+-------------------------------------------------------+-----------------------------------------| +| Key | Search Mode | Show Mode | Tree Mode | +|-----------+----------------------------------------+-------------------------------------------------------+-----------------------------------------| +| a | notmuch-search-archive-thread | notmuch-show-archive-message-then-next-or-next-thread | notmuch-tree-archive-message-then-next | +| b | notmuch-search-scroll-down | notmuch-show-resend-message | notmuch-show-resend-message | +| c | notmuch-search-stash-map | notmuch-show-stash-map | notmuch-show-stash-map | +| d | | | | +| e | | | (notmuch-tree-button-activate) | +| f | | notmuch-show-forward-message | notmuch-show-forward-message | +| g | | | | +| h | | notmuch-show-toggle-visibility-headers | | +| i | | | | +| j | notmuch-jump-search | notmuch-jump-search | notmuch-jump-search | +| k | notmuch-tag-jump | notmuch-tag-jump | notmuch-tag-jump | +| l | notmuch-search-filter | notmuch-show-filter-thread | | +| m | notmuch-mua-new-mail | notmuch-mua-new-mail | notmuch-mua-new-mail | +| n | notmuch-search-next-thread | notmuch-show-next-open-message | notmuch-tree-next-matching-message | +| o | notmuch-search-toggle-order | | | +| p | notmuch-search-previous-thread | notmuch-show-previous-open-message | notmuch-tree-prev-matching-message | +| q | notmuch-bury-or-kill-this-buffer | notmuch-bury-or-kill-this-buffer | notmuch-bury-or-kill-this-buffer | +| r | notmuch-search-reply-to-thread-sender | notmuch-show-reply-sender | notmuch-show-reply-sender | +| s | notmuch-search | notmuch-search | notmuch-search | +| t | notmuch-search-filter-by-tag | toggle-truncate-lines | | +| u | | | | +| v | | | notmuch-show-view-all-mime-parts | +| w | | notmuch-show-save-attachments | notmuch-show-save-attachments | +| x | notmuch-bury-or-kill-this-buffer | notmuch-show-archive-message-then-next-or-exit | notmuch-tree-quit | +| y | | | | +| z | notmuch-tree | notmuch-tree | notmuch-tree-to-tree | +| A | | notmuch-show-archive-thread-then-next | notmuch-tree-archive-thread | +| F | | notmuch-show-forward-open-messages | | +| G | notmuch-poll-and-refresh-this-buffer | notmuch-poll-and-refresh-this-buffer | notmuch-poll-and-refresh-this-buffer | +| N | | notmuch-show-next-message | notmuch-tree-next-message | +| O | | | | +| P | | notmuch-show-previous-message | notmuch-tree-prev-message | +| R | notmuch-search-reply-to-thread | notmuch-show-reply | notmuch-show-reply | +| S | | | notmuch-search-from-tree-current-query | +| V | | notmuch-show-view-raw-message | notmuch-show-view-raw-message | +| X | | notmuch-show-archive-thread-then-exit | | +| Z | notmuch-tree-from-search-current-query | notmuch-tree-from-show-current-query | | +| =!= | | notmuch-show-toggle-elide-non-matching | | +| =#= | | notmuch-show-print-message | | +| =$= | | notmuch-show-toggle-process-crypto | | +| =*= | notmuch-search-tag-all | notmuch-show-tag-all | notmuch-tree-tag-thread | +| + | notmuch-search-add-tag | notmuch-show-add-tag | notmuch-tree-add-tag | +| - | notmuch-search-remove-tag | notmuch-show-remove-tag | notmuch-tree-remove-tag | +| . | | notmuch-show-part-map | | +| < | notmuch-search-first-thread | notmuch-show-toggle-thread-indentation | | +| | notmuch-search-scroll-down | notmuch-show-rewind | notmuch-tree-scroll-message-window-back | +| | notmuch-search-show-thread | notmuch-show-toggle-message | notmuch-tree-show-message | +| | notmuch-search-scroll-up | notmuch-show-advance | notmuch-tree-scroll-or-next | +| | | notmuch-show-next-button | notmuch-show-next-button | +| | | notmuch-show-previous-button | notmuch-show-previous-button | +| = | notmuch-refresh-this-buffer | notmuch-refresh-this-buffer | notmuch-tree-refresh-view | +| > | notmuch-search-last-thread | | | +| ? | notmuch-help | notmuch-help | notmuch-help | +| \vert | | notmuch-show-pipe-message | notmuch-show-pipe-message | +|-----------+----------------------------------------+-------------------------------------------------------+-----------------------------------------| diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug index 1dd5f14f..6febf16f 100755 --- a/devel/nmbug/nmbug +++ b/devel/nmbug/nmbug @@ -475,7 +475,7 @@ def log(args=()): 'nmbug log HEAD..@{upstream}'. """ # we don't want output trapping here, because we want the pager. - args = ['log', '--name-status'] + list(args) + args = ['log', '--name-status', '--no-renames'] + list(args) with _git(args=args, expect=(0, 1, -13)) as p: p.wait() diff --git a/devel/schemata b/devel/schemata index 41dc4a60..00ebb7a6 100644 --- a/devel/schemata +++ b/devel/schemata @@ -26,6 +26,10 @@ v1 v2 - Added the thread_summary.query field. +v3 +- Replaced message.filename string with a list of filenames. +- Added part.content-disposition field. + Common non-terminals -------------------- @@ -59,7 +63,7 @@ message = { # (format_message_sprinter) id: messageid, match: bool, - filename: string, + filename: [string*], timestamp: unix_time, # date header as unix time date_relative: string, # user-friendly timestamp tags: [string*], @@ -76,6 +80,7 @@ part = { sigstatus?: sigstatus, content-type: string, + content-disposition?: string, content-id?: string, # if content-type starts with "multipart/": content: [part*], diff --git a/doc/.gitignore b/doc/.gitignore index d0da78e5..9fa35d08 100644 --- a/doc/.gitignore +++ b/doc/.gitignore @@ -1,4 +1,3 @@ *.pyc -docdeps.mk _build config.dox diff --git a/doc/Makefile.local b/doc/Makefile.local index 8633cfcd..c6f05ca8 100644 --- a/doc/Makefile.local +++ b/doc/Makefile.local @@ -7,13 +7,23 @@ SPHINXOPTS := -q SPHINXBUILD = sphinx-build DOCBUILDDIR := $(dir)/_build -mkdocdeps := $(PYTHON) $(srcdir)/$(dir)/mkdocdeps.py - # Internal variables. ALLSPHINXOPTS := -d $(DOCBUILDDIR)/doctrees $(SPHINXOPTS) $(srcdir)/$(dir) APIMAN := $(DOCBUILDDIR)/man/man3/notmuch.3 DOXYFILE := $(srcdir)/$(dir)/doxygen.cfg +MAN1_RST := $(wildcard $(srcdir)/doc/man1/*.rst) +MAN5_RST := $(wildcard $(srcdir)/doc/man5/*.rst) +MAN7_RST := $(wildcard $(srcdir)/doc/man7/*.rst) +MAN_RST_FILES := $(MAN1_RST) $(MAN5_RST) $(MAN7_RST) + +MAN1_ROFF := $(patsubst $(srcdir)/doc/%,$(DOCBUILDDIR)/man/%,$(MAN1_RST:.rst=.1)) +MAN5_ROFF := $(patsubst $(srcdir)/doc/%,$(DOCBUILDDIR)/man/%,$(MAN5_RST:.rst=.5)) +MAN7_ROFF := $(patsubst $(srcdir)/doc/%,$(DOCBUILDDIR)/man/%,$(MAN7_RST:.rst=.7)) +MAN_ROFF_FILES := $(MAN1_ROFF) $(MAN5_ROFF) $(MAN7_ROFF) + +MAN_GZIP_FILES := $(addsuffix .gz,${MAN_ROFF_FILES}) + .PHONY: sphinx-html sphinx-texinfo sphinx-info .PHONY: install-man build-man apidocs install-apidocs @@ -30,10 +40,6 @@ sphinx-texinfo: sphinx-info: sphinx-texinfo make -C $(DOCBUILDDIR)/texinfo info --include $(dir)/docdeps.mk - -MAN_GZIP_FILES := $(addsuffix .gz,${MAN_ROFF_FILES}) - # Use the man page converter that is available. We should never depend # on MAN_ROFF_FILES if a converter is not available. ${MAN_ROFF_FILES}: $(DOCBUILDDIR)/.roff.stamp @@ -53,7 +59,7 @@ else @echo "Fatal: build dependency fail." @false endif - touch ${MAN_ROFF_FILES} $@ + touch $@ install-man: install-apidocs @@ -62,7 +68,7 @@ MAN_GZIP_FILES += ${APIMAN}.gz apidocs: $(APIMAN) install-apidocs: ${APIMAN}.gz mkdir -p "$(DESTDIR)$(mandir)/man3" - install -m0644 $(DOCBUILDDIR)/man/man3/*.3.gz $(DESTDIR)/$(mandir)/man3 + install -m0644 $(filter %.3.gz,$(MAN_GZIP_FILES)) $(DESTDIR)/$(mandir)/man3 $(APIMAN): $(dir)/config.dox $(srcdir)/$(dir)/doxygen.cfg $(srcdir)/lib/notmuch.h mkdir -p $(DOCBUILDDIR)/man/man3 @@ -86,9 +92,9 @@ install-man: ${MAN_GZIP_FILES} mkdir -p "$(DESTDIR)$(mandir)/man1" mkdir -p "$(DESTDIR)$(mandir)/man5" mkdir -p "$(DESTDIR)$(mandir)/man7" - install -m0644 $(DOCBUILDDIR)/man/man1/*.1.gz $(DESTDIR)/$(mandir)/man1 - install -m0644 $(DOCBUILDDIR)/man/man5/*.5.gz $(DESTDIR)/$(mandir)/man5 - install -m0644 $(DOCBUILDDIR)/man/man7/*.7.gz $(DESTDIR)/$(mandir)/man7 + install -m0644 $(filter %.1.gz,$(MAN_GZIP_FILES)) $(DESTDIR)/$(mandir)/man1 + install -m0644 $(filter %.5.gz,$(MAN_GZIP_FILES)) $(DESTDIR)/$(mandir)/man5 + install -m0644 $(filter %.7.gz,$(MAN_GZIP_FILES)) $(DESTDIR)/$(mandir)/man7 cd $(DESTDIR)/$(mandir)/man1 && ln -sf notmuch.1.gz notmuch-setup.1.gz endif @@ -96,8 +102,5 @@ $(dir)/config.dox: version.stamp echo "PROJECT_NAME = \"Notmuch $(VERSION)\"" > $@ echo "INPUT=${srcdir}/lib/notmuch.h" >> $@ -$(dir)/docdeps.mk: $(dir)/conf.py $(dir)/mkdocdeps.py - $(mkdocdeps) $(srcdir)/doc $(DOCBUILDDIR) $@ - -CLEAN := $(CLEAN) $(DOCBUILDDIR) $(dir)/docdeps.mk $(DOCBUILDDIR)/.roff.stamp +CLEAN := $(CLEAN) $(DOCBUILDDIR) $(DOCBUILDDIR)/.roff.stamp CLEAN := $(CLEAN) $(MAN_GZIP_FILES) $(MAN_ROFF_FILES) $(dir)/conf.pyc $(dir)/config.dox diff --git a/doc/conf.py b/doc/conf.py index 356a2b2b..a3d82696 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -52,74 +52,74 @@ htmlhelp_basename = 'notmuchdoc' # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - -('man1/notmuch','notmuch', - u'thread-based email index, search, and tagging', - [u'Carl Worth and many others'], 1), - -('man1/notmuch-address','notmuch-address', - u'output addresses from matching messages', - [u'Carl Worth and many others'], 1), +notmuch_authors = u'Carl Worth and many others' -('man1/notmuch-compact','notmuch-compact', - u'compact the notmuch database', - [u'Carl Worth and many others'], 1), +man_pages = [ + ('man1/notmuch', 'notmuch', + u'thread-based email index, search, and tagging', + [notmuch_authors], 1), -('man1/notmuch-config','notmuch-config', - u'access notmuch configuration file', - [u'Carl Worth and many others'], 1), + ('man1/notmuch-address', 'notmuch-address', + u'output addresses from matching messages', + [notmuch_authors], 1), -('man1/notmuch-count','notmuch-count', - u'count messages matching the given search terms', - [u'Carl Worth and many others'], 1), + ('man1/notmuch-compact', 'notmuch-compact', + u'compact the notmuch database', + [notmuch_authors], 1), -('man1/notmuch-dump','notmuch-dump', - u'creates a plain-text dump of the tags of each message', - [u'Carl Worth and many others'], 1), + ('man1/notmuch-config', 'notmuch-config', + u'access notmuch configuration file', + [notmuch_authors], 1), -('man1/notmuch-emacs-mua','notmuch-emacs-mua', - u'send mail with notmuch and emacs', - [u'Carl Worth and many others'], 1), + ('man1/notmuch-count', 'notmuch-count', + u'count messages matching the given search terms', + [notmuch_authors], 1), -('man5/notmuch-hooks','notmuch-hooks', - u'hooks for notmuch', - [u'Carl Worth and many others'], 5), + ('man1/notmuch-dump', 'notmuch-dump', + u'creates a plain-text dump of the tags of each message', + [notmuch_authors], 1), -('man1/notmuch-insert','notmuch-insert', - u'add a message to the maildir and notmuch database', - [u'Carl Worth and many others'], 1), + ('man1/notmuch-emacs-mua', 'notmuch-emacs-mua', + u'send mail with notmuch and emacs', + [notmuch_authors], 1), -('man1/notmuch-new','notmuch-new', - u'incorporate new mail into the notmuch database', - [u'Carl Worth and many others'], 1), + ('man5/notmuch-hooks', 'notmuch-hooks', + u'hooks for notmuch', + [notmuch_authors], 5), -('man1/notmuch-reply','notmuch-reply', - u'constructs a reply template for a set of messages', - [u'Carl Worth and many others'], 1), + ('man1/notmuch-insert', 'notmuch-insert', + u'add a message to the maildir and notmuch database', + [notmuch_authors], 1), -('man1/notmuch-restore','notmuch-restore', - u'restores the tags from the given file (see notmuch dump)', - [u'Carl Worth and many others'], 1), + ('man1/notmuch-new', 'notmuch-new', + u'incorporate new mail into the notmuch database', + [notmuch_authors], 1), -('man1/notmuch-search','notmuch-search', - u'search for messages matching the given search terms', - [u'Carl Worth and many others'], 1), + ('man1/notmuch-reply', 'notmuch-reply', + u'constructs a reply template for a set of messages', + [notmuch_authors], 1), -('man7/notmuch-search-terms','notmuch-search-terms', - u'syntax for notmuch queries', - [u'Carl Worth and many others'], 7), + ('man1/notmuch-restore', 'notmuch-restore', + u'restores the tags from the given file (see notmuch dump)', + [notmuch_authors], 1), -('man1/notmuch-show','notmuch-show', - u'show messages matching the given search terms', - [u'Carl Worth and many others'], 1), + ('man1/notmuch-search', 'notmuch-search', + u'search for messages matching the given search terms', + [notmuch_authors], 1), -('man1/notmuch-tag','notmuch-tag', - u'add/remove tags for all messages matching the search terms', - [u'Carl Worth and many others'], 1), + ('man7/notmuch-search-terms', 'notmuch-search-terms', + u'syntax for notmuch queries', + [notmuch_authors], 7), + ('man1/notmuch-show', 'notmuch-show', + u'show messages matching the given search terms', + [notmuch_authors], 1), + ('man1/notmuch-tag', 'notmuch-tag', + u'add/remove tags for all messages matching the search terms', + [notmuch_authors], 1), ] + # If true, show URL addresses after external links. #man_show_urls = False @@ -132,52 +132,19 @@ man_pages = [ texinfo_no_detailmenu = True texinfo_documents = [ - ('notmuch-emacs', 'notmuch-emacs', u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-emacs', - 'emacs based front-end for notmuch', 'Miscellaneous'), -('man1/notmuch','notmuch',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch', - 'thread-based email index, search, and tagging','Miscellaneous'), -('man1/notmuch-address','notmuch-address',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-address', - 'output addresses from matching messages','Miscellaneous'), -('man1/notmuch-compact','notmuch-compact',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-compact', - 'compact the notmuch database','Miscellaneous'), -('man1/notmuch-config','notmuch-config',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-config', - 'access notmuch configuration file','Miscellaneous'), -('man1/notmuch-count','notmuch-count',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-count', - 'count messages matching the given search terms','Miscellaneous'), -('man1/notmuch-dump','notmuch-dump',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-dump', - 'creates a plain-text dump of the tags of each message','Miscellaneous'), -('man5/notmuch-hooks','notmuch-hooks',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-hooks', - 'hooks for notmuch','Miscellaneous'), -('man1/notmuch-insert','notmuch-insert',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-insert', - 'add a message to the maildir and notmuch database','Miscellaneous'), -('man1/notmuch-new','notmuch-new',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-new', - 'incorporate new mail into the notmuch database','Miscellaneous'), -('man1/notmuch-reply','notmuch-reply',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-reply', - 'constructs a reply template for a set of messages','Miscellaneous'), -('man1/notmuch-restore','notmuch-restore',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-restore', - 'restores the tags from the given file (see notmuch dump)','Miscellaneous'), -('man1/notmuch-search','notmuch-search',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-search', - 'search for messages matching the given search terms','Miscellaneous'), -('man7/notmuch-search-terms','notmuch-search-terms',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-search-terms', - 'syntax for notmuch queries','Miscellaneous'), -('man1/notmuch-show','notmuch-show',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-show', - 'show messages matching the given search terms','Miscellaneous'), -('man1/notmuch-tag','notmuch-tag',u'notmuch Documentation', - u'Carl Worth and many others', 'notmuch-tag', - 'add/remove tags for all messages matching the search terms','Miscellaneous'), + ('notmuch-emacs', 'notmuch-emacs', u'notmuch-emacs documentation', + notmuch_authors, 'notmuch-emacs', + 'emacs based front-end for notmuch', 'Miscellaneous'), ] + +# generate texinfo list from man page list +texinfo_documents += [ + ( + x[0], # source start file + x[1], # target name + x[1] + u' documentation', # title + x[3][0], # author + x[1], # dir menu entry + x[2], # description + 'Miscellaneous' # category + ) for x in man_pages] diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst index 7f7214b3..446cefbd 100644 --- a/doc/man1/notmuch-address.rst +++ b/doc/man1/notmuch-address.rst @@ -64,11 +64,11 @@ Supported options for **address** include messages. This is not applicable with --output=count. **mailbox** - Deduplicate addresses based on the full, case sensitive - name and email address, or mailbox. This is effectively - the same as piping the --deduplicate=no output to **sort | - uniq**, except for the order of results. This is the - default. + Deduplicate addresses based on the full, case sensitive + name and email address, or mailbox. This is effectively + the same as piping the --deduplicate=no output to **sort | + uniq**, except for the order of results. This is the + default. **address** Deduplicate addresses based on the case insensitive diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst index 5a517ebd..7483b75f 100644 --- a/doc/man1/notmuch-config.rst +++ b/doc/man1/notmuch-config.rst @@ -129,14 +129,14 @@ The available configuration items are described below. Name (or full path) of gpg binary to use in verification and decryption of PGP/MIME messages. - + Default: ``gpg``. **built_with.** - Compile time feature . Current possibilities include - "compact" (see **notmuch-compact(1)**) - and "field_processor" (see **notmuch-search-terms(7)**). + Compile time feature . Current possibilities include + "compact" (see **notmuch-compact(1)**) + and "field_processor" (see **notmuch-search-terms(7)**). **query.** diff --git a/doc/man1/notmuch-count.rst b/doc/man1/notmuch-count.rst index 99de13a9..90d852ae 100644 --- a/doc/man1/notmuch-count.rst +++ b/doc/man1/notmuch-count.rst @@ -48,9 +48,9 @@ Supported options for **count** include compatible with specifying search terms on the command line. ``--lastmod`` - Append lastmod (counter for number of database updates) and UUID - to the output. lastmod values are only comparable between databases - with the same UUID. + Append lastmod (counter for number of database updates) and UUID + to the output. lastmod values are only comparable between databases + with the same UUID. ``--input=``\ Read input from given file, instead of from stdin. Implies diff --git a/doc/man1/notmuch-dump.rst b/doc/man1/notmuch-dump.rst index 738ba4a3..f3f2b394 100644 --- a/doc/man1/notmuch-dump.rst +++ b/doc/man1/notmuch-dump.rst @@ -77,21 +77,21 @@ Supported options for **dump** include **config** - Output configuration data stored in the database. Each line - starts with "#@ ", followed by a space separated key-value - pair. Both key and value are hex encoded if needed. + Output configuration data stored in the database. Each line + starts with "#@ ", followed by a space separated key-value + pair. Both key and value are hex encoded if needed. **properties** - Output per-message (key,value) metadata. Each line starts - with "#= ", followed by a message id, and a space separated - list of key=value pairs. pair. Ids, keys and values are hex - encoded if needed. + Output per-message (key,value) metadata. Each line starts + with "#= ", followed by a message id, and a space separated + list of key=value pairs. pair. Ids, keys and values are hex + encoded if needed. **tags** - Output per-message boolean metadata, namely tags. See *format* above - for description of the output. + Output per-message boolean metadata, namely tags. See *format* above + for description of the output. The default is to include all available types of data. The option can be specified multiple times to select some subset. As diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.rst index 7c572904..87787e20 100644 --- a/doc/man1/notmuch-emacs-mua.rst +++ b/doc/man1/notmuch-emacs-mua.rst @@ -5,15 +5,15 @@ notmuch-emacs-mua SYNOPSIS ======== -**notmuch-emacs-mua** [options ...] [ ...] +**notmuch** **emacs-mua** [options ...] [ ... | ] DESCRIPTION =========== Start composing an email in the Notmuch Emacs UI with the specified -subject, recipients, and message body. +subject, recipients, and message body, or mailto: URL. -Supported options for **notmuch-emacs-mua** include +Supported options for **emacs-mua** include ``-h, --help`` Display help. @@ -33,6 +33,10 @@ Supported options for **notmuch-emacs-mua** include ``-i, --body=``\ Specify a file to include into the body of the message. + ``--hello`` + Go to the Notmuch hello screen instead of the message composition + window if no message composition parameters are given. + ``--no-window-system`` Even if a window system is available, use the current terminal. @@ -56,7 +60,9 @@ Supported options for **notmuch-emacs-mua** include Output the resulting elisp to stdout instead of evaluating it. The supported positional parameters and short options are a compatible -subset of the **mutt** MUA command-line options. +subset of the **mutt** MUA command-line options. The options and +positional parameters modifying the message can't be combined with the +mailto: URL. Options may be specified multiple times. diff --git a/doc/man1/notmuch-restore.rst b/doc/man1/notmuch-restore.rst index c681fa2d..cb68bc8a 100644 --- a/doc/man1/notmuch-restore.rst +++ b/doc/man1/notmuch-restore.rst @@ -54,23 +54,23 @@ Supported options for **restore** include Control what kind of metadata is restored. - **config** + **config** - Restore configuration data to the database. Each configuration line starts - with "#@ ", followed by a space separated key-value pair. - Both key and value are hex encoded if needed. + Restore configuration data to the database. Each configuration line starts + with "#@ ", followed by a space separated key-value pair. + Both key and value are hex encoded if needed. - **properties** + **properties** - Output per-message (key,value) metadata. Each line starts - with "#= ", followed by a message id, and a space separated - list of key=value pairs. pair. Ids, keys and values are - hex encoded if needed. + Output per-message (key,value) metadata. Each line starts + with "#= ", followed by a message id, and a space separated + list of key=value pairs. pair. Ids, keys and values are + hex encoded if needed. - **tags** + **tags** - Output per-message metadata, namely tags. See *format* above - for more details. + Output per-message metadata, namely tags. See *format* above + for more details. The default is to restore all available types of data. The option can be specified multiple times to select some subset. diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst index 7429f517..fbd7f381 100644 --- a/doc/man1/notmuch.rst +++ b/doc/man1/notmuch.rst @@ -116,6 +116,15 @@ dump of email tags for backup purposes, and to restore from that dump. The **config** command can be used to get or set settings in the notmuch configuration file. +CUSTOM COMMANDS +--------------- + +If the given command is not known to notmuch, notmuch tries to execute +the external **notmuch-** in ${PATH} instead. This allows +users to have their own notmuch related tools to be run via the +notmuch command. By design, this does not allow notmuch's own commands +to be overriden using external commands. + ENVIRONMENT =========== diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst index de93d733..47cab48d 100644 --- a/doc/man7/notmuch-search-terms.rst +++ b/doc/man7/notmuch-search-terms.rst @@ -34,10 +34,14 @@ indicate user-supplied values): - from: +- from:// + - to: - subject: +- subject:// + - attachment: - mimetype: @@ -71,6 +75,15 @@ subject of an email. Searching for a phrase in the subject is supported by including quotation marks around the phrase, immediately following **subject:**. +If notmuch is built with **Xapian Field Processors** (see below) the +**from:** and **subject** prefix can be also used to restrict the +results to those whose from/subject value matches a regular expression +(see **regex(7)**) delimited with //. + +:: + + notmuch search 'from:/bob@.*[.]example[.]com/' + The **attachment:** prefix can be used to search for specific filenames (or extensions) of attachments to email messages. @@ -220,13 +233,18 @@ Boolean and Probabilistic Prefixes ---------------------------------- Xapian (and hence notmuch) prefixes are either **boolean**, supporting -exact matches like "tag:inbox" or **probabilistic**, supporting a more flexible **term** based searching. The prefixes currently supported by notmuch are as follows. - +exact matches like "tag:inbox" or **probabilistic**, supporting a more +flexible **term** based searching. Certain **special** prefixes are +processed by notmuch in a way not stricly fitting either of Xapian's +built in styles. The prefixes currently supported by notmuch are as +follows. Boolean **tag:**, **id:**, **thread:**, **folder:**, **path:**, **property:** Probabilistic - **from:**, **to:**, **subject:**, **attachment:**, **mimetype:** + **to:**, **attachment:**, **mimetype:** +Special + **from:**, **query:**, **subject:** Terms and phrases ----------------- @@ -396,6 +414,7 @@ Currently the following features require field processor support: - non-range date queries, e.g. "date:today" - named queries e.g. "query:my_special_query" +- regular expression searches, e.g. "subject:/^\\[SPAM\\]/" SEE ALSO ======== diff --git a/doc/mkdocdeps.py b/doc/mkdocdeps.py deleted file mode 100644 index b87fe3e8..00000000 --- a/doc/mkdocdeps.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -srcdir = sys.argv[1] -builddir = sys.argv[2] -outfile = sys.argv[3] - -sys.path.insert(0, srcdir) -import conf - -roff_files = [] -rst_files = [] -for page in conf.man_pages: - rst_files = rst_files + ["{0:s}/{1:s}.rst".format(srcdir,page[0])] - roff_files = roff_files + ["{0:s}/man/{1:s}.{2:d}".format(builddir,page[0],page[4])] - -with open(outfile, 'w') as out: - out.write('MAN_ROFF_FILES := ' + ' \\\n\t'.join(roff_files) + '\n') - out.write('MAN_RST_FILES := ' + ' \\\n\t'.join(rst_files) + '\n') diff --git a/doc/notmuch-emacs.rst b/doc/notmuch-emacs.rst index d68542d3..5e25996f 100644 --- a/doc/notmuch-emacs.rst +++ b/doc/notmuch-emacs.rst @@ -189,10 +189,12 @@ following key bindings: ``j`` Jump to saved searches using :ref:`notmuch-jump`. +.. _notmuch-jump: + notmuch-jump ------------ -Saved searches configured through :ref:`notmuch-saved-searches` can +Saved searches configured through :ref:`saved-searches` can include a "shortcut key" that's accessible through notmuch-jump. Pressing ``j`` anywhere in notmuch followed by the configured shortcut key of a saved search will immediately jump to that saved search. For diff --git a/emacs/Makefile.local b/emacs/Makefile.local index dfa7c1f1..040e64d4 100644 --- a/emacs/Makefile.local +++ b/emacs/Makefile.local @@ -21,7 +21,10 @@ emacs_sources := \ $(dir)/notmuch-print.el \ $(dir)/notmuch-version.el \ $(dir)/notmuch-jump.el \ - $(dir)/notmuch-company.el + $(dir)/notmuch-company.el \ + $(dir)/notmuch-draft.el + +elpa_sources := ${emacs_sources} $(dir)/notmuch-pkg.el $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl @@ -35,6 +38,9 @@ $(dir)/notmuch-pkg.el: $(srcdir)/$(dir)/notmuch-pkg.el.tmpl all: $(dir)/notmuch-pkg.el install-emacs: $(dir)/notmuch-pkg.el +emacs_mua := $(dir)/notmuch-emacs-mua +emacs_mua_desktop := $(dir)/notmuch-emacs-mua.desktop + emacs_images := \ $(srcdir)/$(dir)/notmuch-logo.png @@ -72,6 +78,14 @@ ifeq ($(HAVE_EMACS),1) $(call quiet,EMACS) --directory emacs -batch -f batch-byte-compile $< endif +elpa: $(ELPA_FILE) + +notmuch-emacs-%.tar: ${elpa_sources} + mkdir -p .elpa-build/notmuch-${ELPA_VERSION} + cp ${elpa_sources} .elpa-build/notmuch-${ELPA_VERSION} + tar -C .elpa-build -cf $@ notmuch-${ELPA_VERSION} + rm -r .elpa-build + ifeq ($(WITH_EMACS),1) ifeq ($(HAVE_EMACS),1) all: $(emacs_bytecode) @@ -90,5 +104,12 @@ ifeq ($(HAVE_EMACS),1) endif mkdir -p "$(DESTDIR)$(emacsetcdir)" install -m0644 $(emacs_images) "$(DESTDIR)$(emacsetcdir)" + mkdir -p "$(DESTDIR)$(prefix)/bin/" + install $(emacs_mua) "$(DESTDIR)$(prefix)/bin" +ifeq ($(WITH_DESKTOP),1) + mkdir -p "$(DESTDIR)$(desktop_dir)" + desktop-file-install --mode 0644 --dir "$(DESTDIR)$(desktop_dir)" $(emacs_mua_desktop) + -update-desktop-database "$(DESTDIR)$(desktop_dir)" +endif CLEAN := $(CLEAN) $(emacs_bytecode) $(dir)/notmuch-version.el $(dir)/notmuch-pkg.el diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el index 34793dbe..d504ff2d 100644 --- a/emacs/notmuch-address.el +++ b/emacs/notmuch-address.el @@ -37,7 +37,15 @@ (defvar notmuch-address-full-harvest-finished nil "t indicates that full completion address harvesting has been -finished") +finished. Use notmuch-address--harvest-ready to access as that +will load a saved hash if necessary (and available).") + +(defun notmuch-address--harvest-ready () + "Return t if there is a full address hash available. + +If the hash is not present it attempts to load a saved hash." + (or notmuch-address-full-harvest-finished + (notmuch-address--load-address-hash))) (defcustom notmuch-address-command 'internal "Determines how address completion candidates are generated. @@ -58,6 +66,7 @@ disabled." (const :tag "Disable address completion" nil) (string :tag "Use external completion command")) :group 'notmuch-send + :group 'notmuch-address :group 'notmuch-external) (defcustom notmuch-address-internal-completion '(sent nil) @@ -85,6 +94,19 @@ This should be a list of the form '(DIRECTION FILTER), where (setq notmuch-address-completions (clrhash notmuch-address-completions)) (setq notmuch-address-full-harvest-finished nil)) :group 'notmuch-send + :group 'notmuch-address + :group 'notmuch-external) + +(defcustom notmuch-address-save-filename nil + "Filename to save the cached completion addresses. + +All the addresses notmuch uses for address completion will be +cached in this file. This has obvious privacy implications so you +should make sure it is not somewhere publicly readable." + :type '(choice (const :tag "Off" nil) + (file :tag "Filename")) + :group 'notmuch-send + :group 'notmuch-address :group 'notmuch-external) (defcustom notmuch-address-selection-function 'notmuch-address-selection-function @@ -96,8 +118,20 @@ See documentation of function `notmuch-address-selection-function' to know how address selection is made by default." :type 'function :group 'notmuch-send + :group 'notmuch-address :group 'notmuch-external) +(defcustom notmuch-address-post-completion-functions nil + "Functions called after completing address. + +The completed address is passed as an argument to each function. +Note that this hook will be invoked for completion in headers +matching `notmuch-address-completion-headers-regexp'. +" + :type 'hook + :group 'notmuch-address + :group 'notmuch-hooks) + (defun notmuch-address-selection-function (prompt collection initial-input) "Call (`completing-read' PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)" @@ -115,7 +149,8 @@ to know how address selection is made by default." (defcustom notmuch-address-use-company t "If available, use company mode for address completion" :type 'boolean - :group 'notmuch-send) + :group 'notmuch-send + :group 'notmuch-address) (defun notmuch-address-setup () (let* ((setup-company (and notmuch-address-use-company @@ -159,7 +194,7 @@ elisp-based implementation or older implementation requiring external commands." (cond ((eq notmuch-address-command 'internal) - (when (not notmuch-address-full-harvest-finished) + (unless (notmuch-address--harvest-ready) ;; First, run quick synchronous harvest based on what the user ;; entered so far (notmuch-address-harvest original t)) @@ -194,12 +229,20 @@ external commands." (t (funcall notmuch-address-selection-function (format "Address (%s matches): " num-options) - (cdr options) (car options)))))) + ;; We put the first match as the initial + ;; input; we put all the matches as + ;; possible completions, moving the + ;; first match to the end of the list + ;; makes cursor up/down in the list work + ;; better. + (append (cdr options) (list (car options))) + (car options)))))) (if chosen (progn (push chosen notmuch-address-history) (delete-region beg end) - (insert chosen)) + (insert chosen) + (run-hook-with-args 'notmuch-address-post-completion-functions chosen)) (message "No matches.") (ding)))) (t nil))) @@ -304,6 +347,64 @@ execution, CALLBACK is called when harvesting finishes." ;; return value nil) +(defvar notmuch-address--save-hash-version 1 + "Version format of the save hash.") + +(defun notmuch-address--get-address-hash () + "Returns the saved address hash as a plist. + +Returns nil if the save file does not exist, or it does not seem +to be a saved address hash." + (when notmuch-address-save-filename + (condition-case nil + (with-temp-buffer + (insert-file-contents notmuch-address-save-filename) + (let ((name (read (current-buffer))) + (plist (read (current-buffer)))) + ;; We do two simple sanity checks on the loaded file. We just + ;; check a version is specified, not that it is the current + ;; version, as we are allowed to over-write and a save-file with + ;; an older version. + (when (and (string= name "notmuch-address-hash") + (plist-get plist :version)) + plist))) + ;; The error case catches any of the reads failing. + (error nil)))) + +(defun notmuch-address--load-address-hash () + "Read the saved address hash and set the corresponding variables." + (let ((load-plist (notmuch-address--get-address-hash))) + (when (and load-plist + ;; If the user's setting have changed, or the version + ;; has changed, return nil to make sure the new settings + ;; take effect. + (equal (plist-get load-plist :completion-settings) + notmuch-address-internal-completion) + (equal (plist-get load-plist :version) + notmuch-address--save-hash-version)) + (setq notmuch-address-last-harvest (plist-get load-plist :last-harvest) + notmuch-address-completions (plist-get load-plist :completions) + notmuch-address-full-harvest-finished t) + ;; Return t to say load was successful. + t))) + +(defun notmuch-address--save-address-hash () + (when notmuch-address-save-filename + (if (or (not (file-exists-p notmuch-address-save-filename)) + ;; The file exists, check it is a file we saved + (notmuch-address--get-address-hash)) + (with-temp-file notmuch-address-save-filename + (let ((save-plist (list :version notmuch-address--save-hash-version + :completion-settings notmuch-address-internal-completion + :last-harvest notmuch-address-last-harvest + :completions notmuch-address-completions))) + (print "notmuch-address-hash" (current-buffer)) + (print save-plist (current-buffer)))) + (message "\ +Warning: notmuch-address-save-filename %s exists but doesn't +appear to be an address savefile. Not overwriting." + notmuch-address-save-filename)))) + (defun notmuch-address-harvest-trigger () (let ((now (float-time))) (when (> (- now notmuch-address-last-harvest) 86400) @@ -314,7 +415,9 @@ execution, CALLBACK is called when harvesting finishes." ;; again when the trigger is next ;; called (if (string= event "finished\n") - (setq notmuch-address-full-harvest-finished t) + (progn + (notmuch-address--save-address-hash) + (setq notmuch-address-full-harvest-finished t)) (setq notmuch-address-last-harvest 0))))))) ;; diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el index 5d75c145..3e12e7a9 100644 --- a/emacs/notmuch-company.el +++ b/emacs/notmuch-company.el @@ -37,12 +37,14 @@ (declare-function company-mode "company") (declare-function company-manual-begin "company") (defvar company-backends) +(defvar company-idle-delay) (declare-function notmuch-address-harvest "notmuch-address") (declare-function notmuch-address-harvest-trigger "notmuch-address") (declare-function notmuch-address-matching "notmuch-address") -(defvar notmuch-address-full-harvest-finished) +(declare-function notmuch-address--harvest-ready "notmuch-address") (defvar notmuch-address-completion-headers-regexp) +(defvar notmuch-address-command) ;;;###autoload (defun notmuch-company-setup () @@ -70,7 +72,7 @@ (line-beginning-position)) (setq notmuch-company-last-prefix (company-grab "[:,][ \t]*\\(.*\\)" 1 (point-at-bol))))) (candidates (cond - (notmuch-address-full-harvest-finished + ((notmuch-address--harvest-ready) ;; Update harvested addressed from time to time (notmuch-address-harvest-trigger) (notmuch-address-matching arg)) @@ -87,6 +89,7 @@ (match (if (string-match notmuch-company-last-prefix arg) (match-end 0) 0)) + (post-completion (run-hook-with-args 'notmuch-address-post-completion-functions arg)) (no-cache t)))) diff --git a/emacs/notmuch-compat.el b/emacs/notmuch-compat.el index c3d827af..2cedd39d 100644 --- a/emacs/notmuch-compat.el +++ b/emacs/notmuch-compat.el @@ -1,8 +1,28 @@ -;; Compatibility functions for emacs 23 and 24 pre 24.4 +;; Compatibility functions for earlier versions of emacs -;; The functions in this file are copied from eamcs 24.4 and are -;; Copyright (C) 1985-1986, 1992, 1994-1995, 1999-2014 Free Software -;; Foundation, Inc. +;; The functions in this file are copied from more modern versions of +;; emacs and are Copyright (C) 1985-1986, 1992, 1994-1995, 1999-2017 +;; Free Software Foundation, Inc. + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; emacs master has a bugfix for folding long headers when sending +;; messages. Include the fix for earlier versions of emacs. To avoid +;; interfering with gnus we only run the hook when called from +;; notmuch-message-mode. + +(declare-function mail-header-fold-field "mail-parse" nil) + +(defun notmuch-message--fold-long-headers () + (when (eq major-mode 'notmuch-message-mode) + (goto-char (point-min)) + (while (not (eobp)) + (when (and (looking-at "[^:]+:") + (> (- (line-end-position) (point)) 998)) + (mail-header-fold-field)) + (forward-line 1)))) + +(unless (fboundp 'message--fold-long-headers) + (add-hook 'message-header-hook 'notmuch-message--fold-long-headers)) (if (fboundp 'setq-local) (defalias 'notmuch-setq-local 'setq-local) diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el index e376aa80..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 @@ -42,7 +43,12 @@ mode." :group 'notmuch-crypto) (defface notmuch-crypto-part-header - '((t (:foreground "blue"))) + '((((class color) + (background dark)) + (:foreground "LightBlue1")) + (((class color) + (background light)) + (:foreground "blue"))) "Face used for crypto parts headers." :group 'notmuch-crypto :group 'notmuch-faces) @@ -135,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) @@ -146,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-draft.el b/emacs/notmuch-draft.el new file mode 100644 index 00000000..fb7f4f55 --- /dev/null +++ b/emacs/notmuch-draft.el @@ -0,0 +1,267 @@ +;;; notmuch-draft.el --- functions for postponing and editing drafts +;; +;; Copyright © Mark Walters +;; Copyright © David Bremner +;; +;; This file is part of Notmuch. +;; +;; Notmuch is free software: you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; Notmuch is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with Notmuch. If not, see . +;; +;; Authors: Mark Walters +;; David Bremner + +;;; Code: + +(require 'notmuch-maildir-fcc) +(require 'notmuch-tag) + +(declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare)) +(declare-function notmuch-message-mode "notmuch-mua") + +(defgroup notmuch-draft nil + "Saving and editing drafts in Notmuch." + :group 'notmuch) + +(defcustom notmuch-draft-tags '("+draft") + "List of tags changes to apply to a draft message when it is saved in the database. + +Tags starting with \"+\" (or not starting with either \"+\" or +\"-\") in the list will be added, and tags starting with \"-\" +will be removed from the message being stored. + +For example, if you wanted to give the message a \"draft\" tag +but not the (normally added by default) \"inbox\" tag, you would +set: + (\"+draft\" \"-inbox\")" + :type '(repeat string) + :group 'notmuch-draft) + +(defcustom notmuch-draft-folder "drafts" + "Folder to save draft messages in. + +This should be specified relative to the root of the notmuch +database. It will be created if necessary." + :type 'string + :group 'notmuch-draft) + +(defcustom notmuch-draft-quoted-tags '() + "Mml tags to quote. + +This should be a list of mml tags to quote before saving. You do +not need to include \"secure\" as that is handled separately. + +If you include \"part\" then attachments will not be saved with +the draft -- if not then they will be saved with the draft. The +former means the attachments may not still exist when you resume +the message, the latter means that the attachments as they were +when you postponed will be sent with the resumed message. + +Note you may get strange results if you change this between +postponing and resuming a message." + :type '(repeat string) + :group 'notmuch-send) + +(defcustom notmuch-draft-save-plaintext 'ask + "Should notmuch save/postpone in plaintext messages that seem + like they are intended to be sent encrypted +(i.e with an mml encryption tag in it)." + :type '(radio + (const :tag "Never" nil) + (const :tag "Ask every time" ask) + (const :tag "Always" t)) + :group 'notmuch-draft + :group 'notmuch-crypto) + +(defvar notmuch-draft-encryption-tag-regex + "<#\\(part encrypt\\|secure.*mode=.*encrypt>\\)" + "Regular expression matching mml tags indicating encryption of part or message") + +(defvar notmuch-draft-id nil + "Message-id of the most recent saved draft of this message") +(make-variable-buffer-local 'notmuch-draft-id) + +(defun notmuch-draft--mark-deleted () + "Tag the last saved draft deleted. + +Used when a new version is saved, or the message is sent." + (when notmuch-draft-id + (notmuch-tag notmuch-draft-id '("+deleted")))) + +(defun notmuch-draft-quote-some-mml () + "Quote the mml tags in `notmuch-draft-quoted-tags`." + (save-excursion + ;; First we deal with any secure tag separately. + (message-goto-body) + (when (looking-at "<#secure[^\n]*>\n") + (let ((secure-tag (match-string 0))) + (delete-region (match-beginning 0) (match-end 0)) + (message-add-header (concat "X-Notmuch-Emacs-Secure: " secure-tag)))) + ;; This is copied from mml-quote-region but only quotes the + ;; specified tags. + (when notmuch-draft-quoted-tags + (let ((re (concat "<#!*/?\\(" + (mapconcat 'regexp-quote notmuch-draft-quoted-tags "\\|") + "\\)"))) + (message-goto-body) + (while (re-search-forward re nil t) + ;; Insert ! after the #. + (goto-char (+ (match-beginning 0) 2)) + (insert "!")))))) + +(defun notmuch-draft-unquote-some-mml () + "Unquote the mml tags in `notmuch-draft-quoted-tags`." + (save-excursion + (when notmuch-draft-quoted-tags + (let ((re (concat "<#!+/?\\(" + (mapconcat 'regexp-quote notmuch-draft-quoted-tags "\\|") + "\\)"))) + (message-goto-body) + (while (re-search-forward re nil t) + ;; Remove one ! from after the #. + (goto-char (+ (match-beginning 0) 2)) + (delete-char 1)))) + (let (secure-tag) + (save-restriction + (message-narrow-to-headers) + (setq secure-tag (message-fetch-field "X-Notmuch-Emacs-Secure" 't)) + (message-remove-header "X-Notmuch-Emacs-Secure")) + (message-goto-body) + (when secure-tag + (insert secure-tag "\n"))))) + +(defun notmuch-draft--has-encryption-tag () + "Returns t if there is an mml secure tag." + (save-excursion + (message-goto-body) + (re-search-forward notmuch-draft-encryption-tag-regex nil 't))) + +(defun notmuch-draft--query-encryption () + "Checks if we should save a message that should be encrypted. + +`notmuch-draft-save-plaintext' controls the behaviour." + (case notmuch-draft-save-plaintext + ((ask) + (unless (yes-or-no-p "(Customize `notmuch-draft-save-plaintext' to avoid this warning) +This message contains mml tags that suggest it is intended to be encrypted. +Really save and index an unencrypted copy? ") + (error "Save aborted"))) + ((nil) + (error "Refusing to save draft with encryption tags (see `notmuch-draft-save-plaintext')")) + ((t) + (ignore)))) + +(defun notmuch-draft--make-message-id () + ;; message-make-message-id gives the id inside a "<" ">" pair, + ;; but notmuch doesn't want that form, so remove them. + (concat "draft-" (substring (message-make-message-id) 1 -1))) + +(defun notmuch-draft-save () + "Save the current draft message in the notmuch database. + +This saves the current message in the database with tags +`notmuch-draft-tags` (in addition to any default tags +applied to newly inserted messages)." + (interactive) + (when (notmuch-draft--has-encryption-tag) + (notmuch-draft--query-encryption)) + (let ((id (notmuch-draft--make-message-id))) + (with-temporary-notmuch-message-buffer + ;; We insert a Date header and a Message-ID header, the former + ;; so that it is easier to search for the message, and the + ;; latter so we have a way of accessing the saved message (for + ;; example to delete it at a later time). We check that the + ;; user has these in `message-deletable-headers` (the default) + ;; as otherwise they are doing something strange and we + ;; shouldn't interfere. Note, since we are doing this in a new + ;; buffer we don't change the version in the compose buffer. + (cond + ((member 'Message-ID message-deletable-headers) + (message-remove-header "Message-ID") + (message-add-header (concat "Message-ID: <" id ">"))) + (t + (message "You have customized emacs so Message-ID is not a deletable header, so not changing it") + (setq id nil))) + (cond + ((member 'Date message-deletable-headers) + (message-remove-header "Date") + (message-add-header (concat "Date: " (message-make-date)))) + (t + (message "You have customized emacs so Date is not a deletable header, so not changing it"))) + (message-add-header "X-Notmuch-Emacs-Draft: True") + (notmuch-draft-quote-some-mml) + (notmuch-maildir-setup-message-for-saving) + (notmuch-maildir-notmuch-insert-current-buffer + notmuch-draft-folder 't notmuch-draft-tags)) + ;; We are now back in the original compose buffer. Note the + ;; function notmuch-call-notmuch-process (called by + ;; notmuch-maildir-notmuch-insert-current-buffer) signals an error + ;; on failure, so to get to this point it must have + ;; succeeded. Also, notmuch-draft-id is still the id of the + ;; previous draft, so it is safe to mark it deleted. + (notmuch-draft--mark-deleted) + (setq notmuch-draft-id (concat "id:" id)) + (set-buffer-modified-p nil))) + +(defun notmuch-draft-postpone () + "Save the draft message in the notmuch database and exit buffer." + (interactive) + (notmuch-draft-save) + (kill-buffer)) + +(defun notmuch-draft-resume (id) + "Resume editing of message with id ID." + (let* ((tags (process-lines notmuch-command "search" "--output=tags" + "--exclude=false" id)) + (draft (equal tags (notmuch-update-tags tags notmuch-draft-tags)))) + (when (or draft + (yes-or-no-p "Message does not appear to be a draft: really resume? ")) + (switch-to-buffer (get-buffer-create (concat "*notmuch-draft-" id "*"))) + (setq buffer-read-only nil) + (erase-buffer) + (let ((coding-system-for-read 'no-conversion)) + (call-process notmuch-command nil t nil "show" "--format=raw" id)) + (mime-to-mml) + (goto-char (point-min)) + (when (re-search-forward "^$" nil t) + (replace-match mail-header-separator t t)) + ;; Remove the Date and Message-ID headers (unless the user has + ;; explicitly customized emacs to tell us not to) as they will + ;; be replaced when the message is sent. + (save-restriction + (message-narrow-to-headers) + (when (member 'Message-ID message-deletable-headers) + (message-remove-header "Message-ID")) + (when (member 'Date message-deletable-headers) + (message-remove-header "Date")) + ;; The X-Notmuch-Emacs-Draft header is a more reliable + ;; indication of whether the message really is a draft. + (setq draft (> (message-remove-header "X-Notmuch-Emacs-Draft") 0))) + ;; If the message is not a draft we should not unquote any mml. + (when draft + (notmuch-draft-unquote-some-mml)) + (notmuch-message-mode) + (message-goto-body) + (set-buffer-modified-p nil) + ;; If the resumed message was a draft then set the draft + ;; message-id so that we can delete the current saved draft if the + ;; message is resaved or sent. + (setq notmuch-draft-id (when draft id))))) + + +(add-hook 'message-send-hook 'notmuch-draft--mark-deleted) + + +(provide 'notmuch-draft) + +;;; notmuch-draft.el ends here diff --git a/emacs/notmuch-emacs-mua b/emacs/notmuch-emacs-mua new file mode 100755 index 00000000..a5214977 --- /dev/null +++ b/emacs/notmuch-emacs-mua @@ -0,0 +1,179 @@ +#!/usr/bin/env bash +# +# notmuch-emacs-mua - start composing a mail on the command line +# +# Copyright © 2014 Jani Nikula +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see https://www.gnu.org/licenses/ . +# +# Authors: Jani Nikula +# + +set -eu + +# escape: "expand" '\' as '\\' and '"' as '\"' +# calling convention: escape -v var "$arg" (like in bash printf). +escape () +{ + local __escape_arg__=${3//\\/\\\\} + printf -v $2 '%s' "${__escape_arg__//\"/\\\"}" +} + +EMACS=${EMACS:-emacs} +EMACSCLIENT=${EMACSCLIENT:-emacsclient} + +PRINT_ONLY= +NO_WINDOW= +USE_EMACSCLIENT= +AUTO_DAEMON= +CREATE_FRAME= +ELISP= +MAILTO= +HELLO= + +# Short options compatible with mutt(1). +while getopts :s:c:b:i:h opt; do + # Handle errors and long options. + case "${opt}" in + :) + echo "$0: short option -${OPTARG} requires an argument." >&2 + exit 1 + ;; + \?) + opt=$1 + if [ "${OPTARG}" != "-" ]; then + echo "$0: unknown short option -${OPTARG}." >&2 + exit 1 + fi + + case "${opt}" in + # Long options with arguments. + --subject=*|--to=*|--cc=*|--bcc=*|--body=*) + OPTARG=${opt#--*=} + opt=${opt%%=*} + ;; + # Long options without arguments. + --help|--print|--no-window-system|--client|--auto-daemon|--create-frame|--hello) + ;; + *) + echo "$0: unknown long option ${opt}, or argument mismatch." >&2 + exit 1 + ;; + esac + # getopts does not do this for what it considers errors. + OPTIND=$((OPTIND + 1)) + ;; + esac + + escape -v OPTARG "${OPTARG-none}" + + case "${opt}" in + --help|h) + exec man notmuch-emacs-mua + ;; + --subject|s) + ELISP="${ELISP} (message-goto-subject) (insert \"${OPTARG}\")" + ;; + --to) + ELISP="${ELISP} (message-goto-to) (insert \"${OPTARG}, \")" + ;; + --cc|c) + ELISP="${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")" + ;; + --bcc|b) + ELISP="${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")" + ;; + --body|i) + ELISP="${ELISP} (message-goto-body) (insert-file \"${OPTARG}\")" + ;; + --print) + PRINT_ONLY=1 + ;; + --no-window-system) + NO_WINDOW="-nw" + ;; + --client) + USE_EMACSCLIENT="yes" + ;; + --auto-daemon) + AUTO_DAEMON="--alternate-editor=" + CREATE_FRAME="-c" + ;; + --create-frame) + CREATE_FRAME="-c" + ;; + --hello) + HELLO=1 + ;; + *) + # We should never end up here. + echo "$0: internal error (option ${opt})." >&2 + exit 1 + ;; + esac + + shift $((OPTIND - 1)) + OPTIND=1 +done + +# Positional parameters. +for arg; do + escape -v arg "${arg}" + case $arg in + mailto:*) + if [ -n "${MAILTO}" ]; then + echo "$0: more than one mailto: argument." >&2 + exit 1 + fi + MAILTO="${arg}" + ;; + *) + ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")" + ;; + esac +done + +if [ -n "${MAILTO}" ]; then + if [ -n "${ELISP}" ]; then + echo "$0: mailto: is not compatible with other message parameters." >&2 + exit 1 + fi + ELISP="(browse-url-mail \"${MAILTO}\")" +elif [ -z "${ELISP}" -a -n "${HELLO}" ]; then + ELISP="(notmuch)" +else + ELISP="(notmuch-mua-new-mail) ${ELISP}" +fi + +# Kill the terminal/frame if we're creating one. +if [ -z "$USE_EMACSCLIENT" -o -n "$CREATE_FRAME" -o -n "$NO_WINDOW" ]; then + ELISP="${ELISP} (message-add-action #'save-buffers-kill-terminal 'exit)" +fi + +escape -v pwd "$PWD" + +# The crux of it all: construct an elisp progn and eval it. +ELISP="(prog1 'done (require 'notmuch) (cd \"$pwd\") ${ELISP})" + +if [ -n "$PRINT_ONLY" ]; then + echo ${ELISP} + exit 0 +fi + +if [ -n "$USE_EMACSCLIENT" ]; then + # Evaluate the progn. + exec ${EMACSCLIENT} ${NO_WINDOW} ${CREATE_FRAME} ${AUTO_DAEMON} --eval "${ELISP}" +else + exec ${EMACS} ${NO_WINDOW} --eval "${ELISP}" +fi diff --git a/emacs/notmuch-emacs-mua.desktop b/emacs/notmuch-emacs-mua.desktop new file mode 100644 index 00000000..0d9af2a4 --- /dev/null +++ b/emacs/notmuch-emacs-mua.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Notmuch (emacs interface) +GenericName=Email Client +Comment=Emacs based email client +Exec=notmuch-emacs-mua --hello %u +MimeType=x-scheme-handler/mailto; +Icon=emblem-mail +Terminal=false +Type=Application +Categories=Network;Email; diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index d582bff7..c858a20b 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -604,10 +604,11 @@ with `notmuch-hello-query-counts'." (defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png"))) -(defun notmuch-hello-update (&optional no-display) - "Update the current notmuch view." +(defun notmuch-hello-update () + "Update the notmuch-hello buffer." ;; Lazy - rebuild everything. - (notmuch-hello no-display)) + (interactive) + (notmuch-hello t)) (defun notmuch-hello-window-configuration-change () "Hook function to update the hello buffer when it is switched to." diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el index 963253c9..3e20b8c7 100644 --- a/emacs/notmuch-jump.el +++ b/emacs/notmuch-jump.el @@ -104,7 +104,7 @@ not appear in the pop-up buffer. (copy-sequence minibuffer-prompt-properties) 'face)) ;; Build the keymap with our bindings - (minibuffer-map (notmuch-jump--make-keymap action-map)) + (minibuffer-map (notmuch-jump--make-keymap action-map prompt)) ;; The bindings save the the action in notmuch-jump--action (notmuch-jump--action nil)) ;; Read the action @@ -161,18 +161,47 @@ buffer." (set-keymap-parent map minibuffer-local-map) ;; Make this like a special-mode keymap, with no self-insert-command (suppress-keymap map) + (define-key map (kbd "DEL") 'exit-minibuffer) map) "Base keymap for notmuch-jump's minibuffer keymap.") -(defun notmuch-jump--make-keymap (action-map) +(defun notmuch-jump--make-keymap (action-map prompt) "Translate ACTION-MAP into a minibuffer keymap." (let ((map (make-sparse-keymap))) (set-keymap-parent map notmuch-jump-minibuffer-map) (dolist (action action-map) - (define-key map (first action) - `(lambda () (interactive) - (setq notmuch-jump--action ',(third action)) - (exit-minibuffer)))) + (if (= (length (first action)) 1) + (define-key map (first action) + `(lambda () (interactive) + (setq notmuch-jump--action ',(third action)) + (exit-minibuffer))))) + ;; By doing this in two passes (and checking if we already have a + ;; binding) we avoid problems if the user specifies a binding which + ;; is a prefix of another binding. + (dolist (action action-map) + (if (> (length (first action)) 1) + (let* ((key (elt (first action) 0)) + (keystr (string key)) + (new-prompt (concat prompt (format-kbd-macro keystr) " ")) + (action-submap nil)) + (unless (lookup-key map keystr) + (dolist (act action-map) + (when (= key (elt (first act) 0)) + (push (list (substring (first act) 1) + (second act) + (third act)) + action-submap))) + ;; We deal with backspace specially + (push (list (kbd "DEL") + "Backup" + (apply-partially #'notmuch-jump action-map prompt)) + action-submap) + (setq action-submap (nreverse action-submap)) + (define-key map keystr + `(lambda () (interactive) + (setq notmuch-jump--action + ',(apply-partially #'notmuch-jump action-submap new-prompt)) + (exit-minibuffer))))))) map)) ;; diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 23bd81c1..337b20ac 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -58,6 +58,10 @@ (custom-add-to-group 'notmuch-send 'message 'custom-group) +(defgroup notmuch-tag nil + "Tags and tagging in Notmuch." + :group 'notmuch) + (defgroup notmuch-crypto nil "Processing and display of cryptographic MIME parts." :group 'notmuch) @@ -70,6 +74,10 @@ "Running external commands from within Notmuch." :group 'notmuch) +(defgroup notmuch-address nil + "Address completion." + :group 'notmuch) + (defgroup notmuch-faces nil "Graphical attributes for displaying text" :group 'notmuch) @@ -148,6 +156,7 @@ For example, if you wanted to remove an \"inbox\" tag and add an (define-key map "z" 'notmuch-tree) (define-key map "m" 'notmuch-mua-new-mail) (define-key map "=" 'notmuch-refresh-this-buffer) + (define-key map (kbd "M-=") 'notmuch-refresh-all-buffers) (define-key map "G" 'notmuch-poll-and-refresh-this-buffer) (define-key map "j" 'notmuch-jump-search) map) @@ -414,10 +423,8 @@ of its command symbol." "Refresh the current buffer." (interactive) (when notmuch-buffer-refresh-function - (if (commandp notmuch-buffer-refresh-function) - ;; Pass prefix argument, etc. - (call-interactively notmuch-buffer-refresh-function) - (funcall notmuch-buffer-refresh-function)))) + ;; Pass prefix argument, etc. + (call-interactively notmuch-buffer-refresh-function))) (defun notmuch-poll-and-refresh-this-buffer () "Invoke `notmuch-poll' to import mail, then refresh the current buffer." @@ -425,6 +432,21 @@ of its command symbol." (notmuch-poll) (notmuch-refresh-this-buffer)) +(defun notmuch-refresh-all-buffers () + "Invoke `notmuch-refresh-this-buffer' on all notmuch major-mode buffers. + +The buffers are silently refreshed, i.e. they are not forced to +be displayed." + (interactive) + (dolist (buffer (buffer-list)) + (let ((buffer-mode (buffer-local-value 'major-mode buffer))) + (when (memq buffer-mode '(notmuch-show-mode + notmuch-tree-mode + notmuch-search-mode + notmuch-hello-mode)) + (with-current-buffer buffer + (notmuch-refresh-this-buffer)))))) + (defun notmuch-prettify-subject (subject) ;; This function is used by `notmuch-search-process-filter' which ;; requires that we not disrupt its' matching state. diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el index a754b60c..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)) @@ -276,7 +276,7 @@ If CREATE is non-nil then create the folder if necessary." (defun notmuch-maildir-fcc-make-uniq-maildir-id () (let* ((ftime (float-time)) (microseconds (mod (* 1000000 ftime) 1000000)) - (hostname (notmuch-maildir-fcc-host-fixer system-name))) + (hostname (notmuch-maildir-fcc-host-fixer (system-name)))) (setq notmuch-maildir-fcc-count (+ notmuch-maildir-fcc-count 1)) (format "%d.%d_%d_%d.%s" ftime diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index 55bc2672..93747b1c 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -27,12 +27,15 @@ (require 'notmuch-lib) (require 'notmuch-address) +(require 'notmuch-draft) (eval-when-compile (require 'cl)) (declare-function notmuch-show-insert-body "notmuch-show" (msg body depth)) (declare-function notmuch-fcc-header-setup "notmuch-maildir-fcc" ()) (declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ()) +(declare-function notmuch-draft-postpone "notmuch-draft" ()) +(declare-function notmuch-draft-save "notmuch-draft" ()) ;; @@ -251,6 +254,10 @@ mutiple parts get a header." (notmuch-show-max-text-part-size 0) ;; Insert headers for parts as appropriate for replying. (notmuch-show-insert-header-p-function notmuch-mua-reply-insert-header-p-function) + ;; Ensure that any encrypted parts are + ;; decrypted during the generation of the reply + ;; text. + (notmuch-show-process-crypto process-crypto) ;; Don't indent multipart sub-parts. (notmuch-show-indent-multipart nil)) ;; We don't want sigstatus buttons (an information leak and usually wrong anyway). @@ -285,6 +292,8 @@ mutiple parts get a header." (define-key notmuch-message-mode-map (kbd "C-c C-c") #'notmuch-mua-send-and-exit) (define-key notmuch-message-mode-map (kbd "C-c C-s") #'notmuch-mua-send) +(define-key notmuch-message-mode-map (kbd "C-c C-p") #'notmuch-draft-postpone) +(define-key notmuch-message-mode-map (kbd "C-x C-s") #'notmuch-draft-save) (defun notmuch-mua-pop-to-buffer (name switch-function) "Pop to buffer NAME, and warn if it already exists and is @@ -490,15 +499,64 @@ will be addressed to all recipients of the source message." (notmuch-mua-reply query-string sender reply-all) (deactivate-mark))) +(defun notmuch-mua-check-no-misplaced-secure-tag () + "Query user if there is a misplaced secure mml tag. + +Emacs message-send will (probably) ignore a secure mml tag unless +it is at the start of the body. Returns t if there is no such +tag, or the user confirms they mean it." + (save-excursion + (let ((body-start (progn (message-goto-body) (point)))) + (goto-char (point-max)) + (or + ;; We are always fine if there is no secure tag. + (not (search-backward "<#secure" nil 't)) + ;; There is a secure tag, so it must be at the start of the + ;; body, with no secure tag earlier (i.e., in the headers). + (and (= (point) body-start) + (not (search-backward "<#secure" nil 't))) + ;; The user confirms they means it. + (yes-or-no-p "\ +There is a <#secure> tag not at the start of the body. It is +likely that the message will be sent unsigned and unencrypted. +Really send? "))))) + +(defun notmuch-mua-check-secure-tag-has-newline () + "Query if the secure mml tag has a newline following it. + +Emacs message-send will (probably) ignore a correctly placed +secure mml tag unless it is followed by a newline. Returns t if +any secure tag is followed by a newline, or the user confirms +they mean it." + (save-excursion + (message-goto-body) + (or + ;; There is no (correctly placed) secure tag. + (not (looking-at "<#secure")) + ;; The secure tag is followed by a newline. + (looking-at "<#secure[^\n>]*>\n") + ;; The user confirms they means it. + (yes-or-no-p "\ +The <#secure> tag at the start of the body is not followed by a +newline. It is likely that the message will be sent unsigned and +unencrypted. Really send? ")))) + +(defun notmuch-mua-send-common (arg &optional exit) + (interactive "P") + (when (and (notmuch-mua-check-no-misplaced-secure-tag) + (notmuch-mua-check-secure-tag-has-newline)) + (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc)) + (if exit + (message-send-and-exit arg) + (message-send arg))))) + (defun notmuch-mua-send-and-exit (&optional arg) (interactive "P") - (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc)) - (message-send-and-exit arg))) + (notmuch-mua-send-common arg 't)) (defun notmuch-mua-send (&optional arg) (interactive "P") - (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc)) - (message-send arg))) + (notmuch-mua-send-common arg)) (defun notmuch-mua-kill-buffer () (interactive) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index e7d16f81..aafdd3d7 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -38,6 +38,7 @@ (require 'notmuch-mua) (require 'notmuch-crypto) (require 'notmuch-print) +(require 'notmuch-draft) (declare-function notmuch-call-notmuch-process "notmuch" (&rest args)) (declare-function notmuch-search-next-thread "notmuch" nil) @@ -50,6 +51,7 @@ (&optional query query-context target buffer-name open-target)) (declare-function notmuch-tree-get-message-properties "notmuch-tree" nil) (declare-function notmuch-read-query "notmuch" (prompt)) +(declare-function notmuch-draft-resume "notmuch-draft" (id)) (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date") "Headers that should be shown in a message, in this order. @@ -245,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 @@ -328,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) @@ -907,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) @@ -1225,7 +1240,15 @@ matched." (interactive "sNotmuch show: \nP") (let ((buffer-name (generate-new-buffer-name (or buffer-name - (concat "*notmuch-" thread-id "*"))))) + (concat "*notmuch-" thread-id "*")))) + ;; We override mm-inline-override-types to stop application/* + ;; parts from being displayed unless the user has customized + ;; it themselves. + (mm-inline-override-types + (if (equal mm-inline-override-types + (eval (car (get 'mm-inline-override-types 'standard-value)))) + (cons "application/*" mm-inline-override-types) + mm-inline-override-types))) (switch-to-buffer (get-buffer-create buffer-name)) ;; No need to track undo information for this buffer. (setq buffer-undo-list t) @@ -1263,6 +1286,18 @@ matched." (message "No messages matched the query!") nil)))) +(defun notmuch-show--build-queries (thread context) + "Return a list of queries to try for this search. + +THREAD and CONTEXT are both strings, though CONTEXT may be nil. +When CONTEXT is not nil, the first query is the conjunction of it +and THREAD. The next query is THREAD alone, and serves as a +fallback if the prior matches no messages." + (let (queries) + (push (list thread) queries) + (if context (push (list thread "and (" context ")") queries)) + queries)) + (defun notmuch-show--build-buffer (&optional state) "Display messages matching the current buffer context. @@ -1270,25 +1305,20 @@ Apply the previously saved STATE if supplied, otherwise show the first relevant message. If no messages match the query return NIL." - (let* ((basic-args (list notmuch-show-thread-id)) - (args (if notmuch-show-query-context - (append (list "\'") basic-args - (list "and (" notmuch-show-query-context ")\'")) - (append (list "\'") basic-args (list "\'")))) - (cli-args (cons "--exclude=false" + (let* ((cli-args (cons "--exclude=false" (when notmuch-show-elide-non-matching-messages (list "--entire-thread=false")))) - - (forest (or (notmuch-query-get-threads (append cli-args args)) - ;; If a query context reduced the number of - ;; results to zero, try again without it. - (and notmuch-show-query-context - (notmuch-query-get-threads (append cli-args basic-args))))) - + (queries (notmuch-show--build-queries + notmuch-show-thread-id notmuch-show-query-context)) + (forest nil) ;; Must be reset every time we are going to start inserting ;; messages into the buffer. (notmuch-show-previous-subject "")) - + ;; Use results from the first query that returns some. + (while (and (not forest) queries) + (setq forest (notmuch-query-get-threads + (append cli-args (list "'") (car queries) (list "'")))) + (setq queries (cdr queries))) (when forest (notmuch-show-insert-forest forest) @@ -1319,8 +1349,13 @@ If no messages match the query return NIL." This includes: - the list of open messages, - - the current message." - (list (notmuch-show-get-message-id) (notmuch-show-get-message-ids-for-open-messages))) + - the combination of current message id with/for each visible window." + (let* ((win-list (get-buffer-window-list (current-buffer) nil t)) + (win-id-combo (mapcar (lambda (win) + (with-selected-window win + (list win (notmuch-show-get-message-id)))) + win-list))) + (list win-id-combo (notmuch-show-get-message-ids-for-open-messages)))) (defun notmuch-show-get-query () "Return the current query in this show buffer" @@ -1347,8 +1382,8 @@ This includes: This includes: - opening the messages previously opened, - closing all other messages, - - moving to the correct current message." - (let ((current (car state)) + - moving to the correct current message in every displayed window." + (let ((win-msg-alist (car state)) (open (cadr state))) ;; Open those that were open. @@ -1357,8 +1392,10 @@ This includes: (member (notmuch-show-get-message-id) open)) until (not (notmuch-show-goto-message-next))) - ;; Go to the previously open message. - (notmuch-show-goto-message current))) + (dolist (win-msg-pair win-msg-alist) + (with-selected-window (car win-msg-pair) + ;; Go to the previously open message in this window + (notmuch-show-goto-message (cadr win-msg-pair)))))) (defun notmuch-show-refresh-view (&optional reset-state) "Refresh the current view. @@ -1431,8 +1468,10 @@ reset based on the original query." (define-key map "|" 'notmuch-show-pipe-message) (define-key map "w" 'notmuch-show-save-attachments) (define-key map "V" 'notmuch-show-view-raw-message) + (define-key map "e" 'notmuch-show-resume-message) (define-key map "c" 'notmuch-show-stash-map) (define-key map "h" 'notmuch-show-toggle-visibility-headers) + (define-key map "k" 'notmuch-tag-jump) (define-key map "*" 'notmuch-show-tag-all) (define-key map "-" 'notmuch-show-remove-tag) (define-key map "+" 'notmuch-show-add-tag) @@ -1490,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" @@ -1648,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)) @@ -1967,6 +2013,11 @@ to show, nil otherwise." (setq buffer-read-only t) (view-buffer buf 'kill-buffer-if-not-modified))) +(defun notmuch-show-resume-message () + "Resume EDITING the current draft message." + (interactive) + (notmuch-draft-resume (notmuch-show-get-message-id))) + (put 'notmuch-show-pipe-message 'notmuch-doc "Pipe the contents of the current message to a command.") (put 'notmuch-show-pipe-message 'notmuch-prefix-doc @@ -2208,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." @@ -2424,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-tag.el b/emacs/notmuch-tag.el index 6c8b6a75..09d182df 100644 --- a/emacs/notmuch-tag.el +++ b/emacs/notmuch-tag.el @@ -28,6 +28,57 @@ (require 'crm) (require 'notmuch-lib) +(declare-function notmuch-search-tag "notmuch" tag-changes) +(declare-function notmuch-show-tag "notmuch-show" tag-changes) +(declare-function notmuch-tree-tag "notmuch-tree" tag-changes) + +(autoload 'notmuch-jump "notmuch-jump") + +(define-widget 'notmuch-tag-key-type 'list + "A single key tagging binding." + :format "%v" + :args '((list :inline t + :format "%v" + (key-sequence :tag "Key") + (radio :tag "Tag operations" (repeat :tag "Tag list" (string :format "%v" :tag "change")) + (variable :tag "Tag variable")) + (string :tag "Name")))) + +(defcustom notmuch-tagging-keys + `((,(kbd "a") notmuch-archive-tags "Archive") + (,(kbd "u") notmuch-show-mark-read-tags "Mark read") + (,(kbd "f") ("+flagged") "Flag") + (,(kbd "s") ("+spam" "-inbox") "Mark as spam") + (,(kbd "d") ("+deleted" "-inbox") "Delete")) + "A list of keys and corresponding tagging operations. + +For each key (or key sequence) you can specify a sequence of +tagging operations to apply, or a variable which contains a list +of tagging operations such as `notmuch-archive-tags'. The final +element is a name for this tagging operation. If the name is +omitted or empty then the list of tag changes, or the variable +name is used as the name. + +The key `notmuch-tag-jump-reverse-key' (k by default) should not +be used (either as a key, or as the start of a key sequence) as +it is already bound: it switches the menu to a menu of the +reverse tagging operations. The reverse of a tagging operation is +the same list of individual tag-ops but with `+tag` replaced by +`-tag` and vice versa. + +If setting this variable outside of customize then it should be a +list of triples (lists of three elements). Each triple should be +of the form (key-binding tagging-operations name). KEY-BINDING +can be a single character or a key sequence; TAGGING-OPERATIONS +should either be a list of individual tag operations each of the +form `+tag` or `-tag`, or the variable name of a variable that is +a list of tagging operations; NAME should be a name for the +tagging operation, if omitted or empty than then name is taken +from TAGGING-OPERATIONS." + :tag "List of tagging bindings" + :type '(repeat notmuch-tag-key-type) + :group 'notmuch-tag) + (define-widget 'notmuch-tag-format-type 'lazy "Customize widget for notmuch-tag-format and friends" :type '(alist :key-type (regexp :tag "Tag") @@ -64,7 +115,12 @@ Used in the default value of `notmuch-tag-formats`." :group 'notmuch-faces) (defface notmuch-tag-flagged - '((t :foreground "blue")) + '((((class color) + (background dark)) + (:foreground "LightBlue1")) + (((class color) + (background light)) + (:foreground "blue"))) "Face used for the flagged tag. Used in the default value of `notmuch-tag-formats`." @@ -437,6 +493,55 @@ begin with a \"+\" or a \"-\". If REVERSE is non-nil, replace all s))) tags)) +(defvar notmuch-tag-jump-reverse-key "k" + "The key in tag-jump to switch to the reverse tag changes.") + +(defun notmuch-tag-jump (reverse) + "Create a jump menu for tagging operations. + +Creates and displays a jump menu for the tagging operations +specified in `notmuch-tagging-keys'. If REVERSE is set then it +offers a menu of the reverses of the operations specified in +`notmuch-tagging-keys'; i.e. each `+tag` is replaced by `-tag` +and vice versa." + ;; In principle this function is simple, but it has to deal with + ;; lots of cases: different modes (search/show/tree), whether a name + ;; is specified, whether the tagging operations is a list of + ;; tag-ops, or a symbol that evaluates to such a list, and whether + ;; REVERSE is specified. + (interactive "P") + (let (action-map) + (dolist (binding notmuch-tagging-keys) + (let* ((tag-function (case major-mode + (notmuch-search-mode #'notmuch-search-tag) + (notmuch-show-mode #'notmuch-show-tag) + (notmuch-tree-mode #'notmuch-tree-tag))) + (key (first binding)) + (forward-tag-change (if (symbolp (second binding)) + (symbol-value (second binding)) + (second binding))) + (tag-change (if reverse + (notmuch-tag-change-list forward-tag-change 't) + forward-tag-change)) + (name (or (and (not (string= (third binding) "")) + (third binding)) + (and (symbolp (second binding)) + (symbol-name (second binding))))) + (name-string (if name + (if reverse (concat "Reverse " name) + name) + (mapconcat #'identity tag-change " ")))) + (push (list key name-string + `(lambda () (,tag-function ',tag-change))) + action-map))) + (push (list notmuch-tag-jump-reverse-key + (if reverse + "Forward tag changes " + "Reverse tag changes") + (apply-partially 'notmuch-tag-jump (not reverse))) + action-map) + (setq action-map (nreverse action-map)) + (notmuch-jump action-map "Tag: "))) ;; diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index 658c4f90..d4d40761 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -209,6 +209,13 @@ open (if the message pane is closed it does nothing)." (with-selected-window notmuch-tree-message-window (call-interactively #',func))))) +(defun notmuch-tree-inherit-from-message-pane (sym) + "Return value of SYM in message-pane if open, or tree-pane if not" + (if (window-live-p notmuch-tree-message-window) + (with-selected-window notmuch-tree-message-window + (symbol-value sym)) + (symbol-value sym))) + (defun notmuch-tree-button-activate (&optional button) "Activate BUTTON or button at point @@ -226,8 +233,10 @@ FUNC." `(lambda () ,(concat "(Close message pane and) " (documentation func t)) (interactive) - (notmuch-tree-close-message-window) - (call-interactively #',func))) + (let ((notmuch-show-process-crypto + (notmuch-tree-inherit-from-message-pane 'notmuch-show-process-crypto))) + (notmuch-tree-close-message-window) + (call-interactively #',func)))) (defvar notmuch-tree-mode-map (let ((map (make-sparse-keymap))) @@ -257,7 +266,7 @@ FUNC." (define-key map (kbd "M-TAB") (notmuch-tree-to-message-pane #'notmuch-show-previous-button)) (define-key map (kbd "") (notmuch-tree-to-message-pane #'notmuch-show-previous-button)) (define-key map (kbd "TAB") (notmuch-tree-to-message-pane #'notmuch-show-next-button)) - (define-key map "e" (notmuch-tree-to-message-pane #'notmuch-tree-button-activate)) + (define-key map "$" (notmuch-tree-to-message-pane #'notmuch-show-toggle-process-crypto)) ;; bindings from show (or elsewhere) but we close the message pane first. (define-key map "f" (notmuch-tree-close-message-pane-and #'notmuch-show-forward-message)) @@ -271,7 +280,6 @@ FUNC." (define-key map "x" 'notmuch-tree-quit) (define-key map "A" 'notmuch-tree-archive-thread) (define-key map "a" 'notmuch-tree-archive-message-then-next) - (define-key map "=" 'notmuch-tree-refresh-view) (define-key map "z" 'notmuch-tree-to-tree) (define-key map "n" 'notmuch-tree-next-matching-message) (define-key map "p" 'notmuch-tree-prev-matching-message) @@ -279,11 +287,13 @@ FUNC." (define-key map "P" 'notmuch-tree-prev-message) (define-key map (kbd "M-p") 'notmuch-tree-prev-thread) (define-key map (kbd "M-n") 'notmuch-tree-next-thread) + (define-key map "k" 'notmuch-tag-jump) (define-key map "-" 'notmuch-tree-remove-tag) (define-key map "+" 'notmuch-tree-add-tag) (define-key map "*" 'notmuch-tree-tag-thread) (define-key map " " 'notmuch-tree-scroll-or-next) (define-key map (kbd "DEL") 'notmuch-tree-scroll-message-window-back) + (define-key map "e" 'notmuch-tree-resume-message) map)) (fset 'notmuch-tree-mode-map notmuch-tree-mode-map) @@ -364,12 +374,18 @@ updated." (defun notmuch-tree-tag-update-display (&optional tag-changes) "Update display for TAG-CHANGES to current message. -Does NOT change the database." +Updates the message in the message pane if appropriate, but does +NOT change the database." (let* ((current-tags (notmuch-tree-get-tags)) - (new-tags (notmuch-update-tags current-tags tag-changes))) + (new-tags (notmuch-update-tags current-tags tag-changes)) + (tree-msg-id (notmuch-tree-get-message-id))) (unless (equal current-tags new-tags) (notmuch-tree-set-tags new-tags) - (notmuch-tree-refresh-result)))) + (notmuch-tree-refresh-result) + (when (window-live-p notmuch-tree-message-window) + (with-selected-window notmuch-tree-message-window + (when (string= tree-msg-id (notmuch-show-get-message-id)) + (notmuch-show-update-tags new-tags))))))) (defun notmuch-tree-tag (tag-changes) "Change tags for the current message" @@ -390,6 +406,15 @@ Does NOT change the database." (list (notmuch-read-tag-changes (notmuch-tree-get-tags) "Tag message" "-"))) (notmuch-tree-tag tag-changes)) +(defun notmuch-tree-resume-message () + "Resume EDITING the current draft message." + (interactive) + (notmuch-tree-close-message-window) + (let ((id (notmuch-tree-get-message-id))) + (if id + (notmuch-draft-resume id) + (message "No message to resume!")))) + ;; The next two functions close the message window before calling ;; notmuch-search or notmuch-tree but they do so after the user has ;; entered the query (in case the user was basing the query on @@ -892,7 +917,7 @@ the same as for the function notmuch-tree." (notmuch-tag-clear-cache) (let ((proc (notmuch-start-notmuch "notmuch-tree" (current-buffer) #'notmuch-tree-process-sentinel - "show" "--body=false" "--format=sexp" + "show" "--body=false" "--format=sexp" "--format-version=2" message-arg search-args)) ;; Use a scratch buffer to accumulate partial output. ;; This buffer will be killed by the sentinel, which diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 46f14fea..90af68e3 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -169,6 +169,7 @@ there will be called at other points of notmuch execution." (define-key map "t" 'notmuch-search-filter-by-tag) (define-key map "l" 'notmuch-search-filter) (define-key map [mouse-1] 'notmuch-search-show-thread) + (define-key map "k" 'notmuch-tag-jump) (define-key map "*" 'notmuch-search-tag-all) (define-key map "a" 'notmuch-search-archive-thread) (define-key map "-" 'notmuch-search-remove-tag) @@ -312,7 +313,11 @@ there will be called at other points of notmuch execution." :group 'notmuch-faces) (defface notmuch-search-flagged-face - '((t + '((((class color) + (background dark)) + (:foreground "LightBlue1")) + (((class color) + (background light)) (:foreground "blue"))) "Face used in search mode face for flagged threads. @@ -369,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). @@ -397,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 @@ -418,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 @@ -561,12 +570,15 @@ Returns (TAG-CHANGES REGION-BEGIN REGION-END)." See `notmuch-tag' for information on the format of TAG-CHANGES. When called interactively, this uses the region if the region is active. When called directly, BEG and END provide the region. -If these are nil or not provided, this applies to the thread at -point. +If these are nil or not provided, then, if the region is active +this applied to all threads meeting the region, and if the region +is inactive this applies to the thread at point. If ONLY-MATCHED is non-nil, only tag matched messages." (interactive (notmuch-search-interactive-tag-changes)) - (unless (and beg end) (setq beg (point) end (point))) + (unless (and beg end) + (setq beg (car (notmuch-search-interactive-region)) + end (cadr (notmuch-search-interactive-region)))) (let ((search-string (notmuch-search-find-stable-query-region beg end only-matched))) (notmuch-tag search-string tag-changes) @@ -900,9 +912,10 @@ PROMPT is the string to prompt with." (process-lines notmuch-command "search" "--output=tags" "*"))) (completions (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:" - "subject:" "attachment:" "mimetype:") + "subject:" "attachment:") (mapcar (lambda (tag) (concat "tag:" tag)) all-tags) - (mapcar (lambda (tag) (concat "is:" tag)) all-tags)))) + (mapcar (lambda (tag) (concat "is:" tag)) all-tags) + (mapcar (lambda (mimetype) (concat "mimetype:" mimetype)) (mailcap-mime-types))))) (let ((keymap (copy-keymap minibuffer-local-map)) (current-query (case major-mode (notmuch-search-mode (notmuch-search-get-query)) @@ -933,7 +946,7 @@ PROMPT is the string to prompt with." (put 'notmuch-search 'notmuch-doc "Search for messages.") ;;;###autoload -(defun notmuch-search (&optional query oldest-first target-thread target-line) +(defun notmuch-search (&optional query oldest-first target-thread target-line no-display) "Display threads matching QUERY in a notmuch-search buffer. If QUERY is nil, it is read interactively from the minibuffer. @@ -944,6 +957,9 @@ Other optional parameters are used as follows: current if it appears in the search results. TARGET-LINE: The line number to move to if the target thread does not appear in the search results. + NO-DISPLAY: Do not try to foreground the search results buffer. If it is + already foregrounded i.e. displayed in a window, this has no + effect, meaning the buffer will remain visible. When called interactively, this will prompt for a query and use the configured default sort order." @@ -957,7 +973,9 @@ the configured default sort order." (let* ((query (or query (notmuch-read-query "Notmuch search: "))) (buffer (get-buffer-create (notmuch-search-buffer-title query)))) - (switch-to-buffer buffer) + (if no-display + (set-buffer buffer) + (switch-to-buffer buffer)) (notmuch-search-mode) ;; Don't track undo information for this buffer (set 'buffer-undo-list t) @@ -993,17 +1011,18 @@ the configured default sort order." (defun notmuch-search-refresh-view () "Refresh the current view. -Kills the current buffer and runs a new search with the same +Erases the current buffer and runs a new search with the same query string as the current search. If the current thread is in the new search results, then point will be placed on the same thread. Otherwise, point will be moved to attempt to be in the same relative position within the new buffer." + (interactive) (let ((target-line (line-number-at-pos)) (oldest-first notmuch-search-oldest-first) (target-thread (notmuch-search-find-thread-id 'bare)) (query notmuch-search-query-string)) - (notmuch-bury-or-kill-this-buffer) - (notmuch-search query oldest-first target-thread target-line) + ;; notmuch-search erases the current buffer. + (notmuch-search query oldest-first target-thread target-line t) (goto-char (point-min)))) (defun notmuch-search-toggle-order () @@ -1079,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 @@ -1089,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 3d1030a5..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,19 +30,13 @@ 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) \ $(dir)/filenames.c \ $(dir)/string-list.c \ - $(dir)/libsha1.c \ $(dir)/message-file.c \ $(dir)/messages.c \ $(dir)/sha1.c \ @@ -53,6 +54,7 @@ libnotmuch_cxx_srcs = \ $(dir)/query.cc \ $(dir)/query-fp.cc \ $(dir)/config.cc \ + $(dir)/regexp-fields.cc \ $(dir)/thread.cc libnotmuch_modules := $(libnotmuch_c_srcs:.c=.o) $(libnotmuch_cxx_srcs:.cc=.o) @@ -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 ca71a92f..727b1d61 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -32,9 +32,11 @@ #include "notmuch-private.h" -#include +#ifdef SILENCE_XAPIAN_DEPRECATION_WARNINGS +#define XAPIAN_DEPRECATED(D) D +#endif -#pragma GCC visibility push(hidden) +#include /* Bit masks for _notmuch_database::features. Features are named, * independent aspects of the database schema. @@ -144,6 +146,31 @@ operator&=(_notmuch_features &a, _notmuch_features b) return a; } +/* + * Configuration options for xapian database fields */ +typedef enum notmuch_field_flags { + NOTMUCH_FIELD_NO_FLAGS = 0, + NOTMUCH_FIELD_EXTERNAL = 1 << 0, + NOTMUCH_FIELD_PROBABILISTIC = 1 << 1, + NOTMUCH_FIELD_PROCESSOR = 1 << 2, +} notmuch_field_flag_t; + +/* + * define bitwise operators to hide casts */ +inline notmuch_field_flag_t +operator|(notmuch_field_flag_t a, notmuch_field_flag_t b) +{ + return static_cast( + static_cast(a) | static_cast(b)); +} + +inline notmuch_field_flag_t +operator&(notmuch_field_flag_t a, notmuch_field_flag_t b) +{ + return static_cast( + static_cast(a) & static_cast(b)); +} + #define NOTMUCH_QUERY_PARSER_FLAGS (Xapian::QueryParser::FLAG_BOOLEAN | \ Xapian::QueryParser::FLAG_PHRASE | \ Xapian::QueryParser::FLAG_LOVEHATE | \ @@ -179,14 +206,14 @@ struct _notmuch_database { unsigned long revision; const char *uuid; + /* Keep track of the number of times the database has been re-opened + * (or other global invalidations of notmuch's caching) + */ + unsigned long view; Xapian::QueryParser *query_parser; Xapian::TermGenerator *term_gen; Xapian::ValueRangeProcessor *value_range_processor; Xapian::ValueRangeProcessor *date_range_processor; -#if HAVE_XAPIAN_FIELD_PROCESSOR - Xapian::FieldProcessor *date_field_processor; - Xapian::FieldProcessor *query_field_processor; -#endif Xapian::ValueRangeProcessor *last_mod_range_processor; }; @@ -219,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 eddb780c..5b13f541 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -21,6 +21,7 @@ #include "database-private.h" #include "parse-time-vrp.h" #include "query-fp.h" +#include "regexp-fields.h" #include "string-util.h" #include @@ -42,6 +43,7 @@ using namespace std; typedef struct { const char *name; const char *prefix; + notmuch_field_flag_t flags; } prefix_t; #define NOTMUCH_DATABASE_VERSION 3 @@ -247,57 +249,100 @@ typedef struct { * nearly universal to all mail messages). */ -static prefix_t BOOLEAN_PREFIX_INTERNAL[] = { - { "type", "T" }, - { "reference", "XREFERENCE" }, - { "replyto", "XREPLYTO" }, - { "directory", "XDIRECTORY" }, - { "file-direntry", "XFDIRENTRY" }, - { "directory-direntry", "XDDIRENTRY" }, -}; - -static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = { - { "thread", "G" }, - { "tag", "K" }, - { "is", "K" }, - { "id", "Q" }, - { "path", "P" }, - { "property", "XPROPERTY" }, +static const +prefix_t prefix_table[] = { + /* name term prefix flags */ + { "type", "T", NOTMUCH_FIELD_NO_FLAGS }, + { "reference", "XREFERENCE", NOTMUCH_FIELD_NO_FLAGS }, + { "replyto", "XREPLYTO", NOTMUCH_FIELD_NO_FLAGS }, + { "directory", "XDIRECTORY", NOTMUCH_FIELD_NO_FLAGS }, + { "file-direntry", "XFDIRENTRY", NOTMUCH_FIELD_NO_FLAGS }, + { "directory-direntry", "XDDIRENTRY", NOTMUCH_FIELD_NO_FLAGS }, + { "thread", "G", 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 | + NOTMUCH_FIELD_PROCESSOR }, + { "path", "P", NOTMUCH_FIELD_EXTERNAL| + NOTMUCH_FIELD_PROCESSOR }, + { "property", "XPROPERTY", NOTMUCH_FIELD_EXTERNAL }, /* * Unconditionally add ':' to reduce potential ambiguity with * overlapping prefixes and/or terms that start with capital * letters. See Xapian document termprefixes.html for related * discussion. */ - { "folder", "XFOLDER:" }, + { "folder", "XFOLDER:", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROCESSOR }, +#if HAVE_XAPIAN_FIELD_PROCESSOR + { "date", NULL, NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROCESSOR }, + { "query", NULL, NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROCESSOR }, +#endif + { "from", "XFROM", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROBABILISTIC | + NOTMUCH_FIELD_PROCESSOR }, + { "to", "XTO", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROBABILISTIC }, + { "attachment", "XATTACHMENT", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROBABILISTIC }, + { "mimetype", "XMIMETYPE", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROBABILISTIC }, + { "subject", "XSUBJECT", NOTMUCH_FIELD_EXTERNAL | + NOTMUCH_FIELD_PROBABILISTIC | + NOTMUCH_FIELD_PROCESSOR}, }; -static prefix_t PROBABILISTIC_PREFIX[]= { - { "from", "XFROM" }, - { "to", "XTO" }, - { "attachment", "XATTACHMENT" }, - { "mimetype", "XMIMETYPE"}, - { "subject", "XSUBJECT"}, -}; +static void +_setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch) +{ + if (prefix->flags & NOTMUCH_FIELD_PROBABILISTIC) + notmuch->query_parser->add_prefix (prefix->name, prefix->prefix); + else + notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix); +} -const char * -_find_prefix (const char *name) +#if HAVE_XAPIAN_FIELD_PROCESSOR +static void +_setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) { - unsigned int i; + if (prefix->flags & NOTMUCH_FIELD_PROCESSOR) { + Xapian::FieldProcessor *fp; - for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_INTERNAL); i++) { - if (strcmp (name, BOOLEAN_PREFIX_INTERNAL[i].name) == 0) - return BOOLEAN_PREFIX_INTERNAL[i].prefix; - } + if (STRNCMP_LITERAL (prefix->name, "date") == 0) + fp = (new DateFieldProcessor())->release (); + else if (STRNCMP_LITERAL(prefix->name, "query") == 0) + fp = (new QueryFieldProcessor (*notmuch->query_parser, notmuch))->release (); + else + fp = (new RegexpFieldProcessor (prefix->name, prefix->flags, + *notmuch->query_parser, notmuch))->release (); - for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) { - if (strcmp (name, BOOLEAN_PREFIX_EXTERNAL[i].name) == 0) - return BOOLEAN_PREFIX_EXTERNAL[i].prefix; + /* we treat all field-processor fields as boolean in order to get the raw input */ + notmuch->query_parser->add_boolean_prefix (prefix->name, fp); + } else { + _setup_query_field_default (prefix, notmuch); } +} +#else +static inline void +_setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) +{ + _setup_query_field_default (prefix, notmuch); +} +#endif + +const char * +_find_prefix (const char *name) +{ + unsigned int i; - for (i = 0; i < ARRAY_SIZE (PROBABILISTIC_PREFIX); i++) { - if (strcmp (name, PROBABILISTIC_PREFIX[i].name) == 0) - return PROBABILISTIC_PREFIX[i].prefix; + for (i = 0; i < ARRAY_SIZE (prefix_table); i++) { + if (strcmp (name, prefix_table[i].name) == 0) + return prefix_table[i].prefix; } INTERNAL_ERROR ("No prefix exists for '%s'\n", name); @@ -959,6 +1004,7 @@ notmuch_database_open_verbose (const char *path, notmuch->mode = mode; notmuch->atomic_nesting = 0; + notmuch->view = 1; try { string last_thread_id; string last_mod; @@ -1035,14 +1081,6 @@ notmuch_database_open_verbose (const char *path, notmuch->term_gen->set_stemmer (Xapian::Stem ("english")); notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); -#if HAVE_XAPIAN_FIELD_PROCESSOR - /* This currently relies on the query parser to pass anything - * with a .. to the range processor */ - notmuch->date_field_processor = new DateFieldProcessor(); - notmuch->query_parser->add_boolean_prefix("date", notmuch->date_field_processor); - notmuch->query_field_processor = new QueryFieldProcessor (*notmuch->query_parser, notmuch); - notmuch->query_parser->add_boolean_prefix("query", notmuch->query_field_processor); -#endif notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:"); notmuch->query_parser->set_default_op (Xapian::Query::OP_AND); @@ -1053,15 +1091,11 @@ notmuch_database_open_verbose (const char *path, notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor); notmuch->query_parser->add_valuerangeprocessor (notmuch->last_mod_range_processor); - for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) { - prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i]; - notmuch->query_parser->add_boolean_prefix (prefix->name, - prefix->prefix); - } - - for (i = 0; i < ARRAY_SIZE (PROBABILISTIC_PREFIX); i++) { - prefix_t *prefix = &PROBABILISTIC_PREFIX[i]; - notmuch->query_parser->add_prefix (prefix->name, prefix->prefix); + for (i = 0; i < ARRAY_SIZE (prefix_table); i++) { + const prefix_t *prefix = &prefix_table[i]; + if (prefix->flags & NOTMUCH_FIELD_EXTERNAL) { + _setup_query_field (prefix, notmuch); + } } } catch (const Xapian::Error &error) { IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n", @@ -1133,16 +1167,31 @@ notmuch_database_close (notmuch_database_t *notmuch) delete notmuch->last_mod_range_processor; notmuch->last_mod_range_processor = NULL; -#if HAVE_XAPIAN_FIELD_PROCESSOR - delete notmuch->date_field_processor; - notmuch->date_field_processor = NULL; - delete notmuch->query_field_processor; - notmuch->query_field_processor = NULL; -#endif - return status; } +notmuch_status_t +_notmuch_database_reopen (notmuch_database_t *notmuch) +{ + if (notmuch->mode != NOTMUCH_DATABASE_MODE_READ_ONLY) + return NOTMUCH_STATUS_UNSUPPORTED_OPERATION; + + try { + notmuch->xapian_db->reopen (); + } catch (const Xapian::Error &error) { + if (! notmuch->exception_reported) { + _notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n", + error.get_msg ().c_str ()); + notmuch->exception_reported = TRUE; + } + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } + + notmuch->view++; + + return NOTMUCH_STATUS_SUCCESS; +} + static int unlink_cb (const char *path, unused (const struct stat *sb), @@ -1450,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; @@ -1488,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 (; @@ -1711,7 +1760,7 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch) * However, we rely on flushing to test atomicity. */ const char *thresh = getenv ("XAPIAN_FLUSH_THRESHOLD"); if (thresh && atoi (thresh) == 1) - db->flush (); + db->commit (); } catch (const Xapian::Error &error) { _notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n", error.get_msg().c_str()); @@ -2450,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/libsha1.c b/lib/libsha1.c deleted file mode 100644 index aaaa4eb2..00000000 --- a/lib/libsha1.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - --------------------------------------------------------------------------- - Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - ALTERNATIVELY, provided that this notice is retained in full, this product - may be distributed under the terms of the GNU General Public License (GPL), - in which case the provisions of the GPL apply INSTEAD OF those given above. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and/or fitness for purpose. - --------------------------------------------------------------------------- - Issue Date: 01/08/2005 - - This is a byte oriented version of SHA1 that operates on arrays of bytes - stored in memory. -*/ - -#include /* for memcpy() etc. */ -#include "endian-util.h" -#include "libsha1.h" - -#if defined(__cplusplus) -extern "C" -{ -#endif - -#define SHA1_BLOCK_SIZE 64 - -#define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) -#define rotr32(x,n) (((x) >> n) | ((x) << (32 - n))) - -#define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00)) - -#if (UTIL_BYTE_ORDER == UTIL_ORDER_LITTLE_ENDIAN) -# define bsw_32(p,n) \ - { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); } -#elif (UTIL_BYTE_ORDER == UTIL_ORDER_BIG_ENDIAN) -# define bsw_32(p,n) -#else -# error "Unsupported byte order" -#endif - -#define SHA1_MASK (SHA1_BLOCK_SIZE - 1) - -#if 0 - -#define ch(x,y,z) (((x) & (y)) ^ (~(x) & (z))) -#define parity(x,y,z) ((x) ^ (y) ^ (z)) -#define maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) - -#else /* Discovered by Rich Schroeppel and Colin Plumb */ - -#define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) -#define parity(x,y,z) ((x) ^ (y) ^ (z)) -#define maj(x,y,z) (((x) & (y)) | ((z) & ((x) ^ (y)))) - -#endif - -/* Compile 64 bytes of hash data into SHA1 context. Note */ -/* that this routine assumes that the byte order in the */ -/* ctx->wbuf[] at this point is in such an order that low */ -/* address bytes in the ORIGINAL byte stream will go in */ -/* this buffer to the high end of 32-bit words on BOTH big */ -/* and little endian systems */ - -#ifdef ARRAY -#define q(v,n) v[n] -#else -#define q(v,n) v##n -#endif - -#define one_cycle(v,a,b,c,d,e,f,k,h) \ - q(v,e) += rotr32(q(v,a),27) + \ - f(q(v,b),q(v,c),q(v,d)) + k + h; \ - q(v,b) = rotr32(q(v,b), 2) - -#define five_cycle(v,f,k,i) \ - one_cycle(v, 0,1,2,3,4, f,k,hf(i )); \ - one_cycle(v, 4,0,1,2,3, f,k,hf(i+1)); \ - one_cycle(v, 3,4,0,1,2, f,k,hf(i+2)); \ - one_cycle(v, 2,3,4,0,1, f,k,hf(i+3)); \ - one_cycle(v, 1,2,3,4,0, f,k,hf(i+4)) - -static void sha1_compile(sha1_ctx ctx[1]) -{ uint32_t *w = ctx->wbuf; - -#ifdef ARRAY - uint32_t v[5]; - memcpy(v, ctx->hash, 5 * sizeof(uint32_t)); -#else - uint32_t v0, v1, v2, v3, v4; - v0 = ctx->hash[0]; v1 = ctx->hash[1]; - v2 = ctx->hash[2]; v3 = ctx->hash[3]; - v4 = ctx->hash[4]; -#endif - -#define hf(i) w[i] - - five_cycle(v, ch, 0x5a827999, 0); - five_cycle(v, ch, 0x5a827999, 5); - five_cycle(v, ch, 0x5a827999, 10); - one_cycle(v,0,1,2,3,4, ch, 0x5a827999, hf(15)); \ - -#undef hf -#define hf(i) (w[(i) & 15] = rotl32( \ - w[((i) + 13) & 15] ^ w[((i) + 8) & 15] \ - ^ w[((i) + 2) & 15] ^ w[(i) & 15], 1)) - - one_cycle(v,4,0,1,2,3, ch, 0x5a827999, hf(16)); - one_cycle(v,3,4,0,1,2, ch, 0x5a827999, hf(17)); - one_cycle(v,2,3,4,0,1, ch, 0x5a827999, hf(18)); - one_cycle(v,1,2,3,4,0, ch, 0x5a827999, hf(19)); - - five_cycle(v, parity, 0x6ed9eba1, 20); - five_cycle(v, parity, 0x6ed9eba1, 25); - five_cycle(v, parity, 0x6ed9eba1, 30); - five_cycle(v, parity, 0x6ed9eba1, 35); - - five_cycle(v, maj, 0x8f1bbcdc, 40); - five_cycle(v, maj, 0x8f1bbcdc, 45); - five_cycle(v, maj, 0x8f1bbcdc, 50); - five_cycle(v, maj, 0x8f1bbcdc, 55); - - five_cycle(v, parity, 0xca62c1d6, 60); - five_cycle(v, parity, 0xca62c1d6, 65); - five_cycle(v, parity, 0xca62c1d6, 70); - five_cycle(v, parity, 0xca62c1d6, 75); - -#ifdef ARRAY - ctx->hash[0] += v[0]; ctx->hash[1] += v[1]; - ctx->hash[2] += v[2]; ctx->hash[3] += v[3]; - ctx->hash[4] += v[4]; -#else - ctx->hash[0] += v0; ctx->hash[1] += v1; - ctx->hash[2] += v2; ctx->hash[3] += v3; - ctx->hash[4] += v4; -#endif -} - -void sha1_begin(sha1_ctx ctx[1]) -{ - ctx->count[0] = ctx->count[1] = 0; - ctx->hash[0] = 0x67452301; - ctx->hash[1] = 0xefcdab89; - ctx->hash[2] = 0x98badcfe; - ctx->hash[3] = 0x10325476; - ctx->hash[4] = 0xc3d2e1f0; -} - -/* SHA1 hash data in an array of bytes into hash buffer and */ -/* call the hash_compile function as required. */ - -void sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]) -{ uint32_t pos = (uint32_t)(ctx->count[0] & SHA1_MASK), - space = SHA1_BLOCK_SIZE - pos; - const unsigned char *sp = data; - - if((ctx->count[0] += len) < len) - ++(ctx->count[1]); - - while(len >= space) /* transfer whole blocks if possible */ - { - memcpy(((unsigned char*)ctx->wbuf) + pos, sp, space); - sp += space; len -= space; space = SHA1_BLOCK_SIZE; pos = 0; - bsw_32(ctx->wbuf, SHA1_BLOCK_SIZE >> 2); - sha1_compile(ctx); - } - - memcpy(((unsigned char*)ctx->wbuf) + pos, sp, len); -} - -/* SHA1 final padding and digest calculation */ - -void sha1_end(unsigned char hval[], sha1_ctx ctx[1]) -{ uint32_t i = (uint32_t)(ctx->count[0] & SHA1_MASK); - - /* put bytes in the buffer in an order in which references to */ - /* 32-bit words will put bytes with lower addresses into the */ - /* top of 32 bit words on BOTH big and little endian machines */ - bsw_32(ctx->wbuf, (i + 3) >> 2); - - /* we now need to mask valid bytes and add the padding which is */ - /* a single 1 bit and as many zero bits as necessary. Note that */ - /* we can always add the first padding byte here because the */ - /* buffer always has at least one empty slot */ - ctx->wbuf[i >> 2] &= 0xffffff80 << 8 * (~i & 3); - ctx->wbuf[i >> 2] |= 0x00000080 << 8 * (~i & 3); - - /* we need 9 or more empty positions, one for the padding byte */ - /* (above) and eight for the length count. If there is not */ - /* enough space, pad and empty the buffer */ - if(i > SHA1_BLOCK_SIZE - 9) - { - if(i < 60) ctx->wbuf[15] = 0; - sha1_compile(ctx); - i = 0; - } - else /* compute a word index for the empty buffer positions */ - i = (i >> 2) + 1; - - while(i < 14) /* and zero pad all but last two positions */ - ctx->wbuf[i++] = 0; - - /* the following 32-bit length fields are assembled in the */ - /* wrong byte order on little endian machines but this is */ - /* corrected later since they are only ever used as 32-bit */ - /* word values. */ - ctx->wbuf[14] = (ctx->count[1] << 3) | (ctx->count[0] >> 29); - ctx->wbuf[15] = ctx->count[0] << 3; - sha1_compile(ctx); - - /* extract the hash value as bytes in case the hash buffer is */ - /* misaligned for 32-bit words */ - for(i = 0; i < SHA1_DIGEST_SIZE; ++i) - hval[i] = (unsigned char)(ctx->hash[i >> 2] >> (8 * (~i & 3))); -} - -void sha1(unsigned char hval[], const unsigned char data[], unsigned long len) -{ sha1_ctx cx[1]; - - sha1_begin(cx); sha1_hash(data, len, cx); sha1_end(hval, cx); -} - -#if defined(__cplusplus) -} -#endif diff --git a/lib/libsha1.h b/lib/libsha1.h deleted file mode 100644 index 56f445a9..00000000 --- a/lib/libsha1.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - --------------------------------------------------------------------------- - Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - ALTERNATIVELY, provided that this notice is retained in full, this product - may be distributed under the terms of the GNU General Public License (GPL), - in which case the provisions of the GPL apply INSTEAD OF those given above. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and/or fitness for purpose. - --------------------------------------------------------------------------- - Issue Date: 01/08/2005 -*/ - -#ifndef _SHA1_H -#define _SHA1_H - -#if defined(__cplusplus) -extern "C" -{ -#endif -#if 0 -} /* Appeasing Emacs */ -#endif - -#include - -#pragma GCC visibility push(hidden) - -/* Size of SHA1 digest */ - -#define SHA1_DIGEST_SIZE 20 - -/* type to hold the SHA1 context */ - -typedef struct -{ uint32_t count[2]; - uint32_t hash[5]; - uint32_t wbuf[16]; -} sha1_ctx; - -void sha1_begin(sha1_ctx ctx[1]); -void sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]); -void sha1_end(unsigned char hval[], sha1_ctx ctx[1]); -void sha1(unsigned char hval[], const unsigned char data[], unsigned long len); - -#pragma GCC visibility pop - -#if defined(__cplusplus) -} -#endif - -#endif 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 a91e69e0..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; @@ -49,6 +49,9 @@ struct visible _notmuch_message { /* Message document modified since last sync */ notmuch_bool_t modified; + /* last view of database the struct is synced with */ + unsigned long last_view; + Xapian::Document doc; Xapian::termcount termpos; }; @@ -110,6 +113,9 @@ _notmuch_message_create_for_document (const void *talloc_owner, message->flags = 0; message->lazy_flags = 0; + /* the message is initially not synchronized with Xapian */ + message->last_view = 0; + /* Each of these will be lazily created as needed. */ message->message_id = NULL; message->thread_id = NULL; @@ -310,10 +316,14 @@ _notmuch_message_get_term (notmuch_message_t *message, return value; } -void -_notmuch_message_ensure_metadata (notmuch_message_t *message) +static void +_notmuch_message_ensure_metadata (notmuch_message_t *message, void *field) { Xapian::TermIterator i, end; + + if (field && (message->last_view >= message->notmuch->view)) + return; + const char *thread_prefix = _find_prefix ("thread"), *tag_prefix = _find_prefix ("tag"), *id_prefix = _find_prefix ("id"), @@ -327,73 +337,88 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message) * slightly more costly than looking up individual fields if only * one field of the message object is actually used, it's a huge * win as more fields are used. */ + for (int count=0; count < 3; count++) { + try { + i = message->doc.termlist_begin (); + end = message->doc.termlist_end (); + + /* Get thread */ + if (!message->thread_id) + message->thread_id = + _notmuch_message_get_term (message, i, end, thread_prefix); + + /* Get tags */ + assert (strcmp (thread_prefix, tag_prefix) < 0); + if (!message->tag_list) { + message->tag_list = + _notmuch_database_get_terms_with_prefix (message, i, end, + tag_prefix); + _notmuch_string_list_sort (message->tag_list); + } - i = message->doc.termlist_begin (); - end = message->doc.termlist_end (); + /* Get id */ + assert (strcmp (tag_prefix, id_prefix) < 0); + if (!message->message_id) + message->message_id = + _notmuch_message_get_term (message, i, end, id_prefix); + + /* Get document type */ + assert (strcmp (id_prefix, type_prefix) < 0); + if (! NOTMUCH_TEST_BIT (message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST)) { + i.skip_to (type_prefix); + /* "T" is the prefix "type" fields. See + * BOOLEAN_PREFIX_INTERNAL. */ + if (*i == "Tmail") + NOTMUCH_CLEAR_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); + else if (*i == "Tghost") + NOTMUCH_SET_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); + else + INTERNAL_ERROR ("Message without type term"); + NOTMUCH_SET_BIT (&message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST); + } - /* Get thread */ - if (!message->thread_id) - message->thread_id = - _notmuch_message_get_term (message, i, end, thread_prefix); - - /* Get tags */ - assert (strcmp (thread_prefix, tag_prefix) < 0); - if (!message->tag_list) { - message->tag_list = - _notmuch_database_get_terms_with_prefix (message, i, end, - tag_prefix); - _notmuch_string_list_sort (message->tag_list); - } + /* Get filename list. Here we get only the terms. We lazily + * expand them to full file names when needed in + * _notmuch_message_ensure_filename_list. */ + assert (strcmp (type_prefix, filename_prefix) < 0); + if (!message->filename_term_list && !message->filename_list) + message->filename_term_list = + _notmuch_database_get_terms_with_prefix (message, i, end, + filename_prefix); + + + /* Get property terms. Mimic the setup with filenames above */ + assert (strcmp (filename_prefix, property_prefix) < 0); + if (!message->property_map && !message->property_term_list) + message->property_term_list = + _notmuch_database_get_terms_with_prefix (message, i, end, + property_prefix); + + /* Get reply to */ + assert (strcmp (property_prefix, replyto_prefix) < 0); + if (!message->in_reply_to) + message->in_reply_to = + _notmuch_message_get_term (message, i, end, replyto_prefix); - /* Get id */ - assert (strcmp (tag_prefix, id_prefix) < 0); - if (!message->message_id) - message->message_id = - _notmuch_message_get_term (message, i, end, id_prefix); - - /* Get document type */ - assert (strcmp (id_prefix, type_prefix) < 0); - if (! NOTMUCH_TEST_BIT (message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST)) { - i.skip_to (type_prefix); - /* "T" is the prefix "type" fields. See - * BOOLEAN_PREFIX_INTERNAL. */ - if (*i == "Tmail") - NOTMUCH_CLEAR_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); - else if (*i == "Tghost") - NOTMUCH_SET_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); - else - INTERNAL_ERROR ("Message without type term"); - NOTMUCH_SET_BIT (&message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST); - } - /* Get filename list. Here we get only the terms. We lazily - * expand them to full file names when needed in - * _notmuch_message_ensure_filename_list. */ - assert (strcmp (type_prefix, filename_prefix) < 0); - if (!message->filename_term_list && !message->filename_list) - message->filename_term_list = - _notmuch_database_get_terms_with_prefix (message, i, end, - filename_prefix); - - - /* Get property terms. Mimic the setup with filenames above */ - assert (strcmp (filename_prefix, property_prefix) < 0); - if (!message->property_map && !message->property_term_list) - message->property_term_list = - _notmuch_database_get_terms_with_prefix (message, i, end, - property_prefix); - - /* Get reply to */ - assert (strcmp (property_prefix, replyto_prefix) < 0); - if (!message->in_reply_to) - message->in_reply_to = - _notmuch_message_get_term (message, i, end, replyto_prefix); - - - /* It's perfectly valid for a message to have no In-Reply-To - * header. For these cases, we return an empty string. */ - if (!message->in_reply_to) - message->in_reply_to = talloc_strdup (message, ""); + /* It's perfectly valid for a message to have no In-Reply-To + * header. For these cases, we return an empty string. */ + if (!message->in_reply_to) + message->in_reply_to = talloc_strdup (message, ""); + + /* all the way without an exception */ + break; + } catch (const Xapian::DatabaseModifiedError &error) { + notmuch_status_t status = _notmuch_database_reopen (message->notmuch); + if (status != NOTMUCH_STATUS_SUCCESS) + INTERNAL_ERROR ("unhandled error from notmuch_database_reopen: %s\n", + notmuch_status_to_string (status)); + } catch (const Xapian::Error &error) { + INTERNAL_ERROR ("A Xapian exception occurred fetching message metadata: %s\n", + error.get_msg().c_str()); + } + } + message->last_view = message->notmuch->view; } void @@ -448,8 +473,7 @@ _notmuch_message_get_doc_id (notmuch_message_t *message) const char * notmuch_message_get_message_id (notmuch_message_t *message) { - if (!message->message_id) - _notmuch_message_ensure_metadata (message); + _notmuch_message_ensure_metadata (message, message->message_id); if (!message->message_id) INTERNAL_ERROR ("Message with document ID of %u has no message ID.\n", message->doc_id); @@ -524,16 +548,14 @@ notmuch_message_get_header (notmuch_message_t *message, const char *header) const char * _notmuch_message_get_in_reply_to (notmuch_message_t *message) { - if (!message->in_reply_to) - _notmuch_message_ensure_metadata (message); + _notmuch_message_ensure_metadata (message, message->in_reply_to); return message->in_reply_to; } const char * notmuch_message_get_thread_id (notmuch_message_t *message) { - if (!message->thread_id) - _notmuch_message_ensure_metadata (message); + _notmuch_message_ensure_metadata (message, message->thread_id); if (!message->thread_id) INTERNAL_ERROR ("Message with document ID of %u has no thread ID.\n", message->doc_id); @@ -836,8 +858,7 @@ _notmuch_message_ensure_filename_list (notmuch_message_t *message) if (message->filename_list) return; - if (!message->filename_term_list) - _notmuch_message_ensure_metadata (message); + _notmuch_message_ensure_metadata (message, message->filename_term_list); message->filename_list = _notmuch_string_list_create (message); node = message->filename_term_list->head; @@ -931,7 +952,7 @@ notmuch_message_get_flag (notmuch_message_t *message, { if (flag == NOTMUCH_MESSAGE_FLAG_GHOST && ! NOTMUCH_TEST_BIT (message->lazy_flags, flag)) - _notmuch_message_ensure_metadata (message); + _notmuch_message_ensure_metadata (message, NULL); return NOTMUCH_TEST_BIT (message->flags, flag); } @@ -972,8 +993,7 @@ notmuch_message_get_tags (notmuch_message_t *message) { notmuch_tags_t *tags; - if (!message->tag_list) - _notmuch_message_ensure_metadata (message); + _notmuch_message_ensure_metadata (message, message->tag_list); tags = _notmuch_tags_create (message, message->tag_list); /* _notmuch_tags_create steals the reference to the tag_list, but @@ -1014,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)); @@ -1103,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; @@ -1801,7 +1827,7 @@ _notmuch_message_database (notmuch_message_t *message) return message->notmuch; } -void +static void _notmuch_message_ensure_property_map (notmuch_message_t *message) { notmuch_string_node_t *node; @@ -1809,8 +1835,7 @@ _notmuch_message_ensure_property_map (notmuch_message_t *message) if (message->property_map) return; - if (!message->property_term_list) - _notmuch_message_ensure_metadata (message); + _notmuch_message_ensure_metadata (message, message->property_term_list); message->property_map = _notmuch_string_map_create (message); @@ -1818,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 7b35fc5b..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. */ @@ -192,6 +184,9 @@ _notmuch_message_id_compressed (void *ctx, const char *message_id); notmuch_status_t _notmuch_database_ensure_writable (notmuch_database_t *notmuch); +notmuch_status_t +_notmuch_database_reopen (notmuch_database_t *notmuch); + void _notmuch_database_log (notmuch_database_t *notmuch, const char *format, ...); @@ -452,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; @@ -521,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; @@ -618,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 18678c0a..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 @@ -126,15 +128,15 @@ typedef enum _notmuch_status { NOTMUCH_STATUS_READ_ONLY_DATABASE, /** * A Xapian exception occurred. + * + * @todo We don't really want to expose this lame XAPIAN_EXCEPTION + * value. Instead we should map to things like DATABASE_LOCKED or + * whatever. */ NOTMUCH_STATUS_XAPIAN_EXCEPTION, /** * An error occurred trying to read or write to a file (this could * be file not found, permission denied, etc.) - * - * @todo We don't really want to expose this lame XAPIAN_EXCEPTION - * value. Instead we should map to things like DATABASE_LOCKED or - * whatever. */ NOTMUCH_STATUS_FILE_ERROR, /** @@ -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'. @@ -1811,7 +1823,7 @@ const char * notmuch_message_properties_key (notmuch_message_properties_t *properties); /** - * Return the key from the current (key,value) pair. + * Return the value from the current (key,value) pair. * * This could be useful if iterating for a prefix. * @@ -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 53efd4e1..9c6ecc8d 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -29,6 +29,9 @@ struct _notmuch_query { notmuch_sort_t sort; notmuch_string_list_t *exclude_terms; notmuch_exclude_t omit_excluded; + notmuch_bool_t parsed; + Xapian::Query xapian_query; + std::set terms; }; typedef struct _notmuch_mset_messages { @@ -46,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. */ @@ -71,6 +74,14 @@ _debug_query (void) return (env && strcmp (env, "") != 0); } +/* Explicit destructor call for placement new */ +static int +_notmuch_query_destructor (notmuch_query_t *query) { + query->xapian_query.~Query(); + query->terms.~set(); + return 0; +} + notmuch_query_t * notmuch_query_create (notmuch_database_t *notmuch, const char *query_string) @@ -84,6 +95,12 @@ notmuch_query_create (notmuch_database_t *notmuch, if (unlikely (query == NULL)) return NULL; + new (&query->xapian_query) Xapian::Query (); + new (&query->terms) std::set (); + query->parsed = FALSE; + + talloc_set_destructor (query, _notmuch_query_destructor); + query->notmuch = notmuch; query->query_string = talloc_strdup (query, query_string); @@ -97,6 +114,44 @@ notmuch_query_create (notmuch_database_t *notmuch, return query; } +static notmuch_status_t +_notmuch_query_ensure_parsed (notmuch_query_t *query) +{ + if (query->parsed) + return NOTMUCH_STATUS_SUCCESS; + + try { + query->xapian_query = + query->notmuch->query_parser-> + parse_query (query->query_string, NOTMUCH_QUERY_PARSER_FLAGS); + + /* Xapian doesn't support skip_to on terms from a query since + * they are unordered, so cache a copy of all terms in + * something searchable. + */ + + for (Xapian::TermIterator t = query->xapian_query.get_terms_begin (); + t != query->xapian_query.get_terms_end (); ++t) + query->terms.insert (*t); + + query->parsed = TRUE; + + } catch (const Xapian::Error &error) { + if (!query->notmuch->exception_reported) { + _notmuch_database_log (query->notmuch, + "A Xapian exception occurred parsing query: %s\n", + error.get_msg ().c_str ()); + _notmuch_database_log_append (query->notmuch, + "Query string was: %s\n", + query->query_string); + query->notmuch->exception_reported = TRUE; + } + + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } + return NOTMUCH_STATUS_SUCCESS; +} + const char * notmuch_query_get_query_string (const notmuch_query_t *query) { @@ -122,11 +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) { - char *term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag); + notmuch_status_t status; + char *term; + + status = _notmuch_query_ensure_parsed (query); + if (status) + return status; + + term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag); + if (query->terms.count(term) != 0) + 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 @@ -145,46 +211,31 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages) } /* Return a query that matches messages with the excluded tags - * registered with query. Any tags that explicitly appear in xquery - * will not be excluded, and will be removed from the list of exclude - * tags. The caller of this function has to combine the returned + * registered with query. The caller of this function has to combine the returned * query appropriately.*/ static Xapian::Query -_notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery) +_notmuch_exclude_tags (notmuch_query_t *query) { Xapian::Query exclude_query = Xapian::Query::MatchNothing; for (notmuch_string_node_t *term = query->exclude_terms->head; term; term = term->next) { - Xapian::TermIterator it = xquery.get_terms_begin (); - Xapian::TermIterator end = xquery.get_terms_end (); - for (; it != end; it++) { - if ((*it).compare (term->string) == 0) - break; - } - if (it == end) - exclude_query = Xapian::Query (Xapian::Query::OP_OR, - exclude_query, Xapian::Query (term->string)); - else - term->string = talloc_strdup (query, ""); + exclude_query = Xapian::Query (Xapian::Query::OP_OR, + exclude_query, Xapian::Query (term->string)); } 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); @@ -198,6 +249,11 @@ _notmuch_query_search_documents (notmuch_query_t *query, notmuch_database_t *notmuch = query->notmuch; const char *query_string = query->query_string; notmuch_mset_messages_t *messages; + notmuch_status_t status; + + status = _notmuch_query_ensure_parsed (query); + if (status) + return status; messages = talloc (query, notmuch_mset_messages_t); if (unlikely (messages == NULL)) @@ -217,7 +273,7 @@ _notmuch_query_search_documents (notmuch_query_t *query, Xapian::Query mail_query (talloc_asprintf (query, "%s%s", _find_prefix ("type"), type)); - Xapian::Query string_query, final_query, exclude_query; + Xapian::Query final_query, exclude_query; Xapian::MSet mset; Xapian::MSetIterator iterator; @@ -226,15 +282,13 @@ _notmuch_query_search_documents (notmuch_query_t *query, { final_query = mail_query; } else { - string_query = notmuch->query_parser-> - parse_query (query_string, NOTMUCH_QUERY_PARSER_FLAGS); final_query = Xapian::Query (Xapian::Query::OP_AND, - mail_query, string_query); + mail_query, query->xapian_query); } messages->base.excluded_doc_ids = NULL; if ((query->omit_excluded != NOTMUCH_EXCLUDE_FALSE) && (query->exclude_terms)) { - exclude_query = _notmuch_exclude_tags (query, final_query); + exclude_query = _notmuch_exclude_tags (query); if (query->omit_excluded == NOTMUCH_EXCLUDE_TRUE || query->omit_excluded == NOTMUCH_EXCLUDE_ALL) @@ -432,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; @@ -461,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; @@ -544,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); } @@ -566,13 +609,18 @@ _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsign notmuch_database_t *notmuch = query->notmuch; const char *query_string = query->query_string; Xapian::doccount count = 0; + notmuch_status_t status; + + status = _notmuch_query_ensure_parsed (query); + if (status) + return status; try { Xapian::Enquire enquire (*notmuch->xapian_db); Xapian::Query mail_query (talloc_asprintf (query, "%s%s", _find_prefix ("type"), type)); - Xapian::Query string_query, final_query, exclude_query; + Xapian::Query final_query, exclude_query; Xapian::MSet mset; if (strcmp (query_string, "") == 0 || @@ -580,13 +628,11 @@ _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsign { final_query = mail_query; } else { - string_query = notmuch->query_parser-> - parse_query (query_string, NOTMUCH_QUERY_PARSER_FLAGS); final_query = Xapian::Query (Xapian::Query::OP_AND, - mail_query, string_query); + mail_query, query->xapian_query); } - exclude_query = _notmuch_exclude_tags (query, final_query); + exclude_query = _notmuch_exclude_tags (query); final_query = Xapian::Query (Xapian::Query::OP_AND_NOT, final_query, exclude_query); @@ -606,8 +652,9 @@ _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsign /* * Set the checkatleast parameter to the number of documents * in the database to make get_matches_estimated() exact. + * Set the max parameter to 0 to avoid fetching documents we will discard. */ - mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount (), + mset = enquire.get_mset (0, 0, notmuch->xapian_db->get_doccount ()); count = mset.get_matches_estimated(); @@ -626,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; @@ -646,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 new file mode 100644 index 00000000..084bc8c0 --- /dev/null +++ b/lib/regexp-fields.cc @@ -0,0 +1,210 @@ +/* regexp-fields.cc - field processor glue for regex supporting fields + * + * This file is part of notmuch. + * + * Copyright © 2015 Austin Clements + * Copyright © 2016 David Bremner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see https://www.gnu.org/licenses/ . + * + * Author: Austin Clements + * David Bremner + */ + +#include "regexp-fields.h" +#include "notmuch-private.h" +#include "database-private.h" + +#if HAVE_XAPIAN_FIELD_PROCESSOR +static void +compile_regex (regex_t ®exp, const char *str) +{ + int err = regcomp (®exp, str, REG_EXTENDED | REG_NOSUB); + + if (err != 0) { + size_t len = regerror (err, ®exp, NULL, 0); + char *buffer = new char[len]; + std::string msg; + (void) regerror (err, ®exp, buffer, len); + msg.assign (buffer, len); + delete[] buffer; + + throw Xapian::QueryParserError (msg); + } +} + +RegexpPostingSource::RegexpPostingSource (Xapian::valueno slot, const std::string ®exp) + : slot_ (slot) +{ + compile_regex (regexp_, regexp.c_str ()); +} + +RegexpPostingSource::~RegexpPostingSource () +{ + regfree (®exp_); +} + +void +RegexpPostingSource::init (const Xapian::Database &db) +{ + db_ = db; + it_ = db_.valuestream_begin (slot_); + end_ = db.valuestream_end (slot_); + started_ = false; +} + +Xapian::doccount +RegexpPostingSource::get_termfreq_min () const +{ + return 0; +} + +Xapian::doccount +RegexpPostingSource::get_termfreq_est () const +{ + return get_termfreq_max () / 2; +} + +Xapian::doccount +RegexpPostingSource::get_termfreq_max () const +{ + return db_.get_value_freq (slot_); +} + +Xapian::docid +RegexpPostingSource::get_docid () const +{ + return it_.get_docid (); +} + +bool +RegexpPostingSource::at_end () const +{ + return it_ == end_; +} + +void +RegexpPostingSource::next (unused (double min_wt)) +{ + if (started_ && ! at_end ()) + ++it_; + started_ = true; + + for (; ! at_end (); ++it_) { + std::string value = *it_; + if (regexec (®exp_, value.c_str (), 0, NULL, 0) == 0) + break; + } +} + +void +RegexpPostingSource::skip_to (Xapian::docid did, unused (double min_wt)) +{ + started_ = true; + it_.skip_to (did); + for (; ! at_end (); ++it_) { + std::string value = *it_; + if (regexec (®exp_, value.c_str (), 0, NULL, 0) == 0) + break; + } +} + +bool +RegexpPostingSource::check (Xapian::docid did, unused (double min_wt)) +{ + started_ = true; + if (!it_.check (did) || at_end ()) + return false; + return (regexec (®exp_, (*it_).c_str (), 0, NULL, 0) == 0); +} + +static inline Xapian::valueno _find_slot (std::string prefix) +{ + if (prefix == "from") + return NOTMUCH_VALUE_FROM; + else if (prefix == "subject") + return NOTMUCH_VALUE_SUBJECT; + else if (prefix == "mid") + return NOTMUCH_VALUE_MESSAGE_ID; + else + return Xapian::BAD_VALUENO; +} + +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.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.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 { + 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; + + 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 new file mode 100644 index 00000000..d5f93445 --- /dev/null +++ b/lib/regexp-fields.h @@ -0,0 +1,81 @@ +/* regex-fields.h - xapian glue for semi-bruteforce regexp search + * + * This file is part of notmuch. + * + * Copyright © 2015 Austin Clements + * Copyright © 2016 David Bremner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see https://www.gnu.org/licenses/ . + * + * Author: Austin Clements + * David Bremner + */ + +#ifndef NOTMUCH_REGEXP_FIELDS_H +#define NOTMUCH_REGEXP_FIELDS_H +#if HAVE_XAPIAN_FIELD_PROCESSOR +#include +#include +#include "database-private.h" +#include "notmuch-private.h" + +/* A posting source that returns documents where a value matches a + * regexp. + */ +class RegexpPostingSource : public Xapian::PostingSource +{ + protected: + const Xapian::valueno slot_; + regex_t regexp_; + Xapian::Database db_; + bool started_; + Xapian::ValueIterator it_, end_; + +/* No copying */ + RegexpPostingSource (const RegexpPostingSource &); + RegexpPostingSource &operator= (const RegexpPostingSource &); + + public: + RegexpPostingSource (Xapian::valueno slot, const std::string ®exp); + ~RegexpPostingSource (); + void init (const Xapian::Database &db); + Xapian::doccount get_termfreq_min () const; + Xapian::doccount get_termfreq_est () const; + Xapian::doccount get_termfreq_max () const; + Xapian::docid get_docid () const; + bool at_end () const; + void next (unused (double min_wt)); + void skip_to (Xapian::docid did, unused (double min_wt)); + bool check (Xapian::docid did, unused (double min_wt)); +}; + + +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, notmuch_field_flag_t options, + Xapian::QueryParser &parser_, notmuch_database_t *notmuch_); + + ~RegexpFieldProcessor () { }; + + Xapian::Query operator()(const std::string & str); +}; +#endif +#endif /* NOTMUCH_REGEXP_FIELDS_H */ diff --git a/lib/sha1.c b/lib/sha1.c index b7dea1c2..cb55b49a 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -20,28 +20,7 @@ #include "notmuch-private.h" -#include "libsha1.h" - -/* Just some simple interfaces on top of libsha1 so that we can leave - * libsha1 as untouched as possible. */ - -static char * -_hex_of_sha1_digest (const unsigned char digest[SHA1_DIGEST_SIZE]) -{ - char *result, *r; - int i; - - result = xcalloc (SHA1_DIGEST_SIZE * 2 + 1, 1); - - for (r = result, i = 0; - i < SHA1_DIGEST_SIZE; - r += 2, i++) - { - sprintf (r, "%02x", digest[i]); - } - - return result; -} +#include /* Create a hexadecimal string version of the SHA-1 digest of 'str' * (including its null terminating character). @@ -52,16 +31,15 @@ _hex_of_sha1_digest (const unsigned char digest[SHA1_DIGEST_SIZE]) char * _notmuch_sha1_of_string (const char *str) { - sha1_ctx sha1; - unsigned char digest[SHA1_DIGEST_SIZE]; - - sha1_begin (&sha1); + GChecksum *sha1; + char *digest; - sha1_hash ((unsigned char *) str, strlen (str) + 1, &sha1); + sha1 = g_checksum_new (G_CHECKSUM_SHA1); + g_checksum_update (sha1, (const guchar *) str, strlen (str) + 1); + digest = xstrdup (g_checksum_get_string (sha1)); + g_checksum_free (sha1); - sha1_end (digest, &sha1); - - return _hex_of_sha1_digest (digest); + return digest; } /* Create a hexadecimal string version of the SHA-1 digest of the @@ -80,35 +58,36 @@ _notmuch_sha1_of_file (const char *filename) #define BLOCK_SIZE 4096 unsigned char block[BLOCK_SIZE]; size_t bytes_read; - sha1_ctx sha1; - unsigned char digest[SHA1_DIGEST_SIZE]; - char *result; + GChecksum *sha1; + char *digest = NULL; file = fopen (filename, "r"); if (file == NULL) return NULL; - sha1_begin (&sha1); + sha1 = g_checksum_new (G_CHECKSUM_SHA1); + if (sha1 == NULL) + goto DONE; while (1) { bytes_read = fread (block, 1, 4096, file); if (bytes_read == 0) { - if (feof (file)) { + if (feof (file)) break; - } else if (ferror (file)) { - fclose (file); - return NULL; - } + else if (ferror (file)) + goto DONE; } else { - sha1_hash (block, bytes_read, &sha1); + g_checksum_update (sha1, block, bytes_read); } } - sha1_end (digest, &sha1); - - result = _hex_of_sha1_digest (digest); + digest = xstrdup (g_checksum_get_string (sha1)); - fclose (file); + DONE: + if (sha1) + g_checksum_free (sha1); + if (file) + fclose (file); - return result; + return digest; } 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 dc640326..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 @@ -145,7 +145,7 @@ chomp_newline (char *str) * this. New (required) map fields can be added without increasing * this. */ -#define NOTMUCH_FORMAT_CUR 2 +#define NOTMUCH_FORMAT_CUR 3 /* The minimum supported structured output format version. Requests * for format versions below this will return an error. */ #define NOTMUCH_FORMAT_MIN 1 @@ -263,10 +263,15 @@ json_quote_str (const void *ctx, const char *str); /* notmuch-config.c */ +typedef enum { + NOTMUCH_CONFIG_OPEN = 1 << 0, + NOTMUCH_CONFIG_CREATE = 1 << 1, +} notmuch_config_mode_t; + notmuch_config_t * notmuch_config_open (void *ctx, const char *filename, - notmuch_bool_t create_new); + notmuch_config_mode_t config_mode); void notmuch_config_close (notmuch_config_t *config); diff --git a/notmuch-config.c b/notmuch-config.c index e5d42a0c..e4aaef61 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -202,6 +202,84 @@ get_username_from_passwd_file (void *ctx) return name; } +static notmuch_bool_t +get_config_from_file (notmuch_config_t *config, notmuch_bool_t create_new) +{ + #define BUF_SIZE 4096 + char *config_str = NULL; + int config_len = 0; + int config_bufsize = BUF_SIZE; + size_t len; + GError *error = NULL; + notmuch_bool_t ret = FALSE; + + FILE *fp = fopen(config->filename, "r"); + if (fp == NULL) { + if (errno == ENOENT) { + /* If create_new is true, then the caller is prepared for a + * default configuration file in the case of FILE NOT FOUND. + */ + if (create_new) { + config->is_new = TRUE; + ret = TRUE; + } else { + fprintf (stderr, "Configuration file %s not found.\n" + "Try running 'notmuch setup' to create a configuration.\n", + config->filename); + } + } else { + fprintf (stderr, "Error opening config file '%s': %s\n", + config->filename, strerror(errno)); + } + goto out; + } + + config_str = talloc_zero_array (config, char, config_bufsize); + if (config_str == NULL) { + fprintf (stderr, "Error reading '%s': Out of memory\n", config->filename); + goto out; + } + + while ((len = fread (config_str + config_len, 1, + config_bufsize - config_len, fp)) > 0) { + config_len += len; + if (config_len == config_bufsize) { + config_bufsize += BUF_SIZE; + config_str = talloc_realloc (config, config_str, char, config_bufsize); + if (config_str == NULL) { + fprintf (stderr, "Error reading '%s': Failed to reallocate memory\n", + config->filename); + goto out; + } + } + } + + if (ferror (fp)) { + fprintf (stderr, "Error reading '%s': I/O error\n", config->filename); + goto out; + } + + if (g_key_file_load_from_data (config->key_file, config_str, config_len, + G_KEY_FILE_KEEP_COMMENTS, &error)) { + ret = TRUE; + goto out; + } + + fprintf (stderr, "Error parsing config file '%s': %s\n", + config->filename, error->message); + + g_error_free (error); + +out: + if (fp) + fclose(fp); + + if (config_str) + talloc_free(config_str); + + return ret; +} + /* Open the named notmuch configuration file. If the filename is NULL, * the value of the environment variable $NOTMUCH_CONFIG will be used. * If $NOTMUCH_CONFIG is unset, the default configuration file @@ -243,7 +321,7 @@ get_username_from_passwd_file (void *ctx) notmuch_config_t * notmuch_config_open (void *ctx, const char *filename, - notmuch_bool_t create_new) + notmuch_config_mode_t config_mode) { GError *error = NULL; size_t tmp; @@ -255,7 +333,7 @@ notmuch_config_open (void *ctx, int file_had_search_group; int file_had_crypto_group; - notmuch_config_t *config = talloc (ctx, notmuch_config_t); + notmuch_config_t *config = talloc_zero (ctx, notmuch_config_t); if (config == NULL) { fprintf (stderr, "Out of memory.\n"); return NULL; @@ -263,6 +341,9 @@ notmuch_config_open (void *ctx, talloc_set_destructor (config, notmuch_config_destructor); + /* non-zero defaults */ + config->maildir_synchronize_flags = TRUE; + if (filename) { config->filename = talloc_strdup (config, filename); } else if ((notmuch_config_env = getenv ("NOTMUCH_CONFIG"))) { @@ -274,49 +355,11 @@ notmuch_config_open (void *ctx, config->key_file = g_key_file_new (); - config->is_new = FALSE; - config->database_path = NULL; - config->user_name = NULL; - config->user_primary_email = NULL; - config->user_other_email = NULL; - config->user_other_email_length = 0; - config->new_tags = NULL; - config->new_tags_length = 0; - config->new_ignore = NULL; - config->new_ignore_length = 0; - config->maildir_synchronize_flags = TRUE; - config->search_exclude_tags = NULL; - config->search_exclude_tags_length = 0; - config->crypto_gpg_path = NULL; - - if (! g_key_file_load_from_file (config->key_file, - config->filename, - G_KEY_FILE_KEEP_COMMENTS, - &error)) - { - if (error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT) { - /* If create_new is true, then the caller is prepared for a - * default configuration file in the case of FILE NOT - * FOUND. - */ - if (create_new) { - g_error_free (error); - config->is_new = TRUE; - } else { - fprintf (stderr, "Configuration file %s not found.\n" - "Try running 'notmuch setup' to create a configuration.\n", - config->filename); - talloc_free (config); - g_error_free (error); - return NULL; - } - } - else - { - fprintf (stderr, "Error reading configuration file %s: %s\n", - config->filename, error->message); + if (config_mode & NOTMUCH_CONFIG_OPEN) { + notmuch_bool_t create_new = (config_mode & NOTMUCH_CONFIG_CREATE) != 0; + + if (! get_config_from_file (config, create_new)) { talloc_free (config); - g_error_free (error); return NULL; } } @@ -591,11 +634,11 @@ _config_get_list (notmuch_config_t *config, static void _config_set_list (notmuch_config_t *config, - const char *group, const char *name, + const char *group, const char *key, const char *list[], size_t length, const char ***config_var ) { - g_key_file_set_string_list (config->key_file, group, name, list, length); + g_key_file_set_string_list (config->key_file, group, key, list, length); /* drop the cached value */ talloc_free (*config_var); 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 0bb946f8..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; @@ -250,7 +250,8 @@ database_dump_file (notmuch_database_t *notmuch, gzFile output, message = notmuch_messages_get (messages); - if (dump_tags_message (notmuch, message, output_format, output, + if ((include & DUMP_INCLUDE_TAGS) && + dump_tags_message (notmuch, message, output_format, output, &buffer, &buffer_size)) return EXIT_FAILURE; diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua deleted file mode 100755 index f9d83713..00000000 --- a/notmuch-emacs-mua +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env bash -# -# notmuch-emacs-mua - start composing a mail on the command line -# -# Copyright © 2014 Jani Nikula -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see https://www.gnu.org/licenses/ . -# -# Authors: Jani Nikula -# - -set -eu - -# escape: "expand" '\' as '\\' and '"' as '\"' -# calling convention: escape -v var "$arg" (like in bash printf). -escape () -{ - local __escape_arg__=${3//\\/\\\\} - printf -v $2 '%s' "${__escape_arg__//\"/\\\"}" -} - -EMACS=${EMACS:-emacs} -EMACSCLIENT=${EMACSCLIENT:-emacsclient} - -PRINT_ONLY= -NO_WINDOW= -USE_EMACSCLIENT= -AUTO_DAEMON= -CREATE_FRAME= - -escape -v pwd "$PWD" - -# The crux of it all: construct an elisp progn and eval it. -ELISP="(prog1 'done (require 'notmuch) (cd \"$pwd\") (notmuch-mua-new-mail)" - -# Short options compatible with mutt(1). -while getopts :s:c:b:i:h opt; do - # Handle errors and long options. - case "${opt}" in - :) - echo "$0: short option -${OPTARG} requires an argument." >&2 - exit 1 - ;; - \?) - opt=$1 - if [ "${OPTARG}" != "-" ]; then - echo "$0: unknown short option -${OPTARG}." >&2 - exit 1 - fi - - case "${opt}" in - # Long options with arguments. - --subject=*|--to=*|--cc=*|--bcc=*|--body=*) - OPTARG=${opt#--*=} - opt=${opt%%=*} - ;; - # Long options without arguments. - --help|--print|--no-window-system|--client|--auto-daemon|--create-frame) - ;; - *) - echo "$0: unknown long option ${opt}, or argument mismatch." >&2 - exit 1 - ;; - esac - # getopts does not do this for what it considers errors. - OPTIND=$((OPTIND + 1)) - ;; - esac - - escape -v OPTARG "${OPTARG-none}" - - case "${opt}" in - --help|h) - exec man notmuch-emacs-mua - ;; - --subject|s) - ELISP="${ELISP} (message-goto-subject) (insert \"${OPTARG}\")" - ;; - --to) - ELISP="${ELISP} (message-goto-to) (insert \"${OPTARG}, \")" - ;; - --cc|c) - ELISP="${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")" - ;; - --bcc|b) - ELISP="${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")" - ;; - --body|i) - ELISP="${ELISP} (message-goto-body) (insert-file \"${OPTARG}\")" - ;; - --print) - PRINT_ONLY=1 - ;; - --no-window-system) - NO_WINDOW="-nw" - ;; - --client) - USE_EMACSCLIENT="yes" - ;; - --auto-daemon) - AUTO_DAEMON="--alternate-editor=" - CREATE_FRAME="-c" - ;; - --create-frame) - CREATE_FRAME="-c" - ;; - *) - # We should never end up here. - echo "$0: internal error (option ${opt})." >&2 - exit 1 - ;; - esac - - shift $((OPTIND - 1)) - OPTIND=1 -done - -# Positional parameters. -for arg; do - escape -v arg "${arg}" - ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")" -done - -# Kill the terminal/frame if we're creating one. -if [ -z "$USE_EMACSCLIENT" -o -n "$CREATE_FRAME" -o -n "$NO_WINDOW" ]; then - ELISP="${ELISP} (message-add-action #'save-buffers-kill-terminal 'exit)" -fi - -# End progn. -ELISP="${ELISP})" - -if [ -n "$PRINT_ONLY" ]; then - echo ${ELISP} - exit 0 -fi - -if [ -n "$USE_EMACSCLIENT" ]; then - # Evaluate the progn. - exec ${EMACSCLIENT} ${NO_WINDOW} ${CREATE_FRAME} ${AUTO_DAEMON} --eval "${ELISP}" -else - exec ${EMACS} ${NO_WINDOW} --eval "${ELISP}" -fi diff --git a/notmuch-new.c b/notmuch-new.c index cc680b41..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 (" ("); @@ -738,18 +738,20 @@ count_files (const char *path, int *count, add_files_state_t *state) entry = fs_entries[i]; /* Ignore special directories to avoid infinite recursion. - * Also ignore the .notmuch directory and files/directories - * the user has configured to be ignored. + * Also ignore the .notmuch directory. */ if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0 || - strcmp (entry->d_name, ".notmuch") == 0 || - _entry_in_ignore_list (entry->d_name, state)) - { - if (state->debug && _entry_in_ignore_list (entry->d_name, state)) + strcmp (entry->d_name, ".notmuch") == 0) + continue; + + /* Ignore any files/directories the user has configured to be + * ignored + */ + if (_entry_in_ignore_list (entry->d_name, state)) { + if (state->debug) printf ("(D) count_files: explicitly ignoring %s/%s\n", - path, - entry->d_name); + path, entry->d_name); continue; } @@ -848,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; @@ -903,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 22fa655a..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) { @@ -110,6 +68,17 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message) from, relative_date, tags); } +static const char *_get_disposition(GMimeObject *meta) +{ + GMimeContentDisposition *disposition; + + disposition = g_mime_object_get_content_disposition (meta); + if (!disposition) + return NULL; + + return g_mime_content_disposition_get_disposition (disposition); +} + /* Emit a sequence of key/value pairs for the metadata of message. * The caller should begin a map before calling this. */ static void @@ -133,7 +102,20 @@ format_message_sprinter (sprinter_t *sp, notmuch_message_t *message) sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED)); sp->map_key (sp, "filename"); - sp->string (sp, notmuch_message_get_filename (message)); + if (notmuch_format_version >= 3) { + notmuch_filenames_t *filenames; + + sp->begin_list (sp); + for (filenames = notmuch_message_get_filenames (message); + notmuch_filenames_valid (filenames); + notmuch_filenames_move_to_next (filenames)) { + sp->string (sp, notmuch_filenames_get (filenames)); + } + notmuch_filenames_destroy (filenames); + sp->end (sp); + } else { + sp->string (sp, notmuch_message_get_filename (message)); + } sp->map_key (sp, "timestamp"); date = notmuch_message_get_date (message); @@ -220,8 +202,9 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, * reflected in the file devel/schemata. */ InternetAddressList *recipients; - const char *recipients_string; + char *recipients_string; const char *reply_to_string; + char *date_string; sp->begin_map (sp); @@ -236,6 +219,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, if (recipients_string) { sp->map_key (sp, "To"); sp->string (sp, recipients_string); + g_free (recipients_string); } recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC); @@ -243,6 +227,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, if (recipients_string) { sp->map_key (sp, "Cc"); sp->string (sp, recipients_string); + g_free (recipients_string); } recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_BCC); @@ -250,6 +235,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, if (recipients_string) { sp->map_key (sp, "Bcc"); sp->string (sp, recipients_string); + g_free (recipients_string); } reply_to_string = g_mime_message_get_reply_to (message); @@ -266,7 +252,9 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "References")); } else { sp->map_key (sp, "Date"); - sp->string (sp, g_mime_message_get_date_as_string (message)); + date_string = g_mime_message_get_date_as_string (message); + sp->string (sp, date_string); + g_free (date_string); } sp->end (sp); @@ -288,6 +276,7 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out, { GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part)); GMimeStream *stream_filter = NULL; + GMimeFilter *crlf_filter = NULL; GMimeDataWrapper *wrapper; const char *charset; @@ -299,8 +288,10 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out, return; stream_filter = g_mime_stream_filter_new (stream_out); + crlf_filter = g_mime_filter_crlf_new (FALSE, FALSE); g_mime_stream_filter_add(GMIME_STREAM_FILTER (stream_filter), - g_mime_filter_crlf_new (FALSE, FALSE)); + crlf_filter); + g_object_unref (crlf_filter); charset = g_mime_object_get_content_type_parameter (part, "charset"); if (charset) { @@ -435,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; @@ -442,69 +434,75 @@ 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 { - GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta); + char *content_string; + const char *disposition = _get_disposition (meta); const char *cid = g_mime_object_get_content_id (meta); const char *filename = leaf ? g_mime_part_get_filename (GMIME_PART (node->part)) : NULL; if (disposition && - strcasecmp (g_mime_content_disposition_get_disposition (disposition), - GMIME_DISPOSITION_ATTACHMENT) == 0) + strcasecmp (disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) part_type = "attachment"; 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); - printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type)); + g_mime_stream_printf (stream, ", Content-id: %s", cid); + + content_string = g_mime_content_type_to_string (content_type); + g_mime_stream_printf (stream, ", Content-type: %s\n", content_string); + g_free (content_string); } if (GMIME_IS_MESSAGE (node->part)) { GMimeMessage *message = GMIME_MESSAGE (node->part); InternetAddressList *recipients; - const char *recipients_string; + 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); - printf ("Date: %s\n", g_mime_message_get_date_as_string (message)); - printf ("\fheader}\n"); - - printf ("\fbody{\n"); + g_mime_stream_printf (stream, "Cc: %s\n", recipients_string); + g_free (recipients_string); + date_string = g_mime_message_get_date_as_string (message); + g_mime_stream_printf (stream, "Date: %s\n", date_string); + g_free (date_string); + g_mime_stream_printf (stream, "\fheader}\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 { - printf ("Non-text part: %s\n", - g_mime_content_type_to_string (content_type)); + char *content_string = g_mime_content_type_to_string (content_type); + g_mime_stream_printf (stream, "Non-text part: %s\n", content_string); + g_free (content_string); } } @@ -512,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; } @@ -572,6 +570,8 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node, GMimeObject *meta = node->envelope_part ? GMIME_OBJECT (node->envelope_part) : node->part; GMimeContentType *content_type = g_mime_object_get_content_type (meta); + char *content_string; + const char *disposition = _get_disposition (meta); const char *cid = g_mime_object_get_content_id (meta); const char *filename = GMIME_IS_PART (node->part) ? g_mime_part_get_filename (GMIME_PART (node->part)) : NULL; @@ -599,7 +599,14 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node, } sp->map_key (sp, "content-type"); - sp->string (sp, g_mime_content_type_to_string (content_type)); + content_string = g_mime_content_type_to_string (content_type); + sp->string (sp, content_string); + g_free (content_string); + + if (disposition) { + sp->map_key (sp, "content-disposition"); + sp->string (sp, disposition); + } if (cid) { sp->map_key (sp, "content-id"); @@ -732,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. */ @@ -772,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 @@ -801,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; } @@ -899,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; @@ -938,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; @@ -978,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 */ @@ -997,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 }, @@ -1051,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 (); @@ -1092,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) { @@ -1103,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"); @@ -1145,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/notmuch.c b/notmuch.c index 38b73c1d..8e332ce6 100644 --- a/notmuch.c +++ b/notmuch.c @@ -33,7 +33,7 @@ typedef int (*command_function_t) (notmuch_config_t *config, int argc, char *arg typedef struct command { const char *name; command_function_t function; - notmuch_bool_t create_config; + notmuch_config_mode_t config_mode; const char *summary; } command_t; @@ -97,35 +97,35 @@ int notmuch_minimal_options (const char *subcommand_name, } static command_t commands[] = { - { NULL, notmuch_command, TRUE, + { NULL, notmuch_command, NOTMUCH_CONFIG_OPEN | NOTMUCH_CONFIG_CREATE, "Notmuch main command." }, - { "setup", notmuch_setup_command, TRUE, + { "setup", notmuch_setup_command, NOTMUCH_CONFIG_OPEN | NOTMUCH_CONFIG_CREATE, "Interactively set up notmuch for first use." }, - { "new", notmuch_new_command, FALSE, + { "new", notmuch_new_command, NOTMUCH_CONFIG_OPEN, "Find and import new messages to the notmuch database." }, - { "insert", notmuch_insert_command, FALSE, + { "insert", notmuch_insert_command, NOTMUCH_CONFIG_OPEN, "Add a new message into the maildir and notmuch database." }, - { "search", notmuch_search_command, FALSE, + { "search", notmuch_search_command, NOTMUCH_CONFIG_OPEN, "Search for messages matching the given search terms." }, - { "address", notmuch_address_command, FALSE, + { "address", notmuch_address_command, NOTMUCH_CONFIG_OPEN, "Get addresses from messages matching the given search terms." }, - { "show", notmuch_show_command, FALSE, + { "show", notmuch_show_command, NOTMUCH_CONFIG_OPEN, "Show all messages matching the search terms." }, - { "count", notmuch_count_command, FALSE, + { "count", notmuch_count_command, NOTMUCH_CONFIG_OPEN, "Count messages matching the search terms." }, - { "reply", notmuch_reply_command, FALSE, + { "reply", notmuch_reply_command, NOTMUCH_CONFIG_OPEN, "Construct a reply template for a set of messages." }, - { "tag", notmuch_tag_command, FALSE, + { "tag", notmuch_tag_command, NOTMUCH_CONFIG_OPEN, "Add/remove tags for all messages matching the search terms." }, - { "dump", notmuch_dump_command, FALSE, + { "dump", notmuch_dump_command, NOTMUCH_CONFIG_OPEN, "Create a plain-text dump of the tags for each message." }, - { "restore", notmuch_restore_command, FALSE, + { "restore", notmuch_restore_command, NOTMUCH_CONFIG_OPEN, "Restore the tags from the given dump file (see 'dump')." }, - { "compact", notmuch_compact_command, FALSE, + { "compact", notmuch_compact_command, NOTMUCH_CONFIG_OPEN, "Compact the notmuch database." }, - { "config", notmuch_config_command, FALSE, + { "config", notmuch_config_command, NOTMUCH_CONFIG_OPEN, "Get or set settings in the notmuch configuration file." }, - { "help", notmuch_help_command, TRUE, /* create but don't save config */ + { "help", notmuch_help_command, NOTMUCH_CONFIG_CREATE, /* create but don't save config */ "This message, or more detailed help for the named command." } }; @@ -363,6 +363,39 @@ notmuch_command (notmuch_config_t *config, return EXIT_SUCCESS; } +/* + * Try to run subcommand in argv[0] as notmuch- prefixed external + * command. argv must be NULL terminated (argv passed to main always + * is). + * + * Does not return if the external command is found and + * executed. Return TRUE if external command is not found. Return + * FALSE on errors. + */ +static notmuch_bool_t try_external_command(char *argv[]) +{ + char *old_argv0 = argv[0]; + notmuch_bool_t ret = TRUE; + + argv[0] = talloc_asprintf (NULL, "notmuch-%s", old_argv0); + + /* + * This will only return on errors. Not finding an external + * command (ENOENT) is not an error from our perspective. + */ + execvp (argv[0], argv); + if (errno != ENOENT) { + fprintf (stderr, "Error: Running external command '%s' failed: %s\n", + argv[0], strerror(errno)); + ret = FALSE; + } + + talloc_free (argv[0]); + argv[0] = old_argv0; + + return ret; +} + int main (int argc, char *argv[]) { @@ -406,13 +439,15 @@ main (int argc, char *argv[]) command = find_command (command_name); if (!command) { - fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n", - command_name); + /* This won't return if the external command is found. */ + if (try_external_command(argv + opt_index)) + fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n", + command_name); ret = EXIT_FAILURE; goto DONE; } - config = notmuch_config_open (local, config_file_name, command->create_config); + config = notmuch_config_open (local, config_file_name, command->config_mode); if (!config) { ret = EXIT_FAILURE; goto DONE; diff --git a/notmuch.desktop b/notmuch.desktop deleted file mode 100644 index f1600473..00000000 --- a/notmuch.desktop +++ /dev/null @@ -1,7 +0,0 @@ -[Desktop Entry] -Name=Notmuch (emacs interface) -Exec=emacs -f notmuch -Icon=emblem-mail -Terminal=false -Type=Application -Categories=Network;Email; 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 91b36936..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. @@ -77,4 +77,4 @@ check: test SRCS := $(SRCS) $(test_srcs) CLEAN += $(TEST_BINARIES) $(addsuffix .o,$(TEST_BINARIES)) \ $(dir)/database-test.o \ - $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.* + $(dir)/corpora.mail $(dir)/test-results $(dir)/tmp.* 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