aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2012-08-06 18:10:31 +0200
committerAnton Khirnov <anton@khirnov.net>2012-08-06 18:10:31 +0200
commit7192d0221a361d3d9cfd6626058e4a1c86ea7b44 (patch)
tree11d3db0604f47498e16b50ef7f559e138bfe4482
parent6bc2f5a999d9ff77779d98b7cc688a4350ea65d9 (diff)
parent6b820673fc9c2483572af5ec7ea91e4d7d7258c9 (diff)
Merge remote-tracking branch 'origin/master' into vim
-rw-r--r--.dir-locals.el6
-rw-r--r--.gitignore1
-rw-r--r--INSTALL14
-rw-r--r--Makefile.local37
-rw-r--r--NEWS847
-rw-r--r--bindings/go/Makefile70
-rw-r--r--bindings/go/cmds/Makefile11
-rw-r--r--bindings/go/pkg/Makefile17
-rw-r--r--bindings/go/src/notmuch-addrlookup/addrlookup.go (renamed from bindings/go/cmds/notmuch-addrlookup.go)90
-rw-r--r--bindings/go/src/notmuch/notmuch.go (renamed from bindings/go/pkg/notmuch.go)142
-rw-r--r--bindings/python/docs/source/conf.py22
-rw-r--r--bindings/python/docs/source/database.rst50
-rw-r--r--bindings/python/docs/source/filesystem.rst28
-rw-r--r--bindings/python/docs/source/index.rst284
-rw-r--r--bindings/python/docs/source/message.rst50
-rw-r--r--bindings/python/docs/source/messages.rst15
-rw-r--r--bindings/python/docs/source/notes.rst6
-rw-r--r--bindings/python/docs/source/notmuch.rst68
-rw-r--r--bindings/python/docs/source/query.rst41
-rw-r--r--bindings/python/docs/source/quickstart.rst19
-rw-r--r--bindings/python/docs/source/status_and_errors.rst6
-rw-r--r--bindings/python/docs/source/tags.rst17
-rw-r--r--bindings/python/docs/source/thread.rst26
-rw-r--r--bindings/python/docs/source/threads.rst10
-rwxr-xr-xbindings/python/notmuch.py651
-rw-r--r--bindings/python/notmuch/__init__.py19
-rw-r--r--bindings/python/notmuch/compat.py67
-rw-r--r--bindings/python/notmuch/database.py638
-rw-r--r--bindings/python/notmuch/directory.py185
-rw-r--r--bindings/python/notmuch/errors.py183
-rw-r--r--bindings/python/notmuch/filename.py121
-rw-r--r--bindings/python/notmuch/filenames.py150
-rw-r--r--bindings/python/notmuch/globals.py189
-rw-r--r--bindings/python/notmuch/message.py566
-rw-r--r--bindings/python/notmuch/messages.py282
-rw-r--r--bindings/python/notmuch/query.py207
-rw-r--r--bindings/python/notmuch/tag.py52
-rw-r--r--bindings/python/notmuch/thread.py252
-rw-r--r--bindings/python/notmuch/threads.py177
-rw-r--r--bindings/python/notmuch/version.py2
-rw-r--r--bindings/python/setup.py61
-rw-r--r--bindings/ruby/database.c25
-rw-r--r--bindings/ruby/defs.h61
-rw-r--r--bindings/ruby/extconf.rb2
-rw-r--r--bindings/ruby/init.c37
-rw-r--r--bindings/ruby/query.c57
-rw-r--r--command-line-arguments.c49
-rw-r--r--compat/Makefile.local2
-rw-r--r--compat/compat.h8
-rwxr-xr-xconfigure102
-rwxr-xr-xcontrib/nmbug/nmbug (renamed from contrib/nmbug)37
-rwxr-xr-xcontrib/nmbug/nmbug-status149
-rw-r--r--contrib/nmbug/status-config.json65
-rw-r--r--contrib/notmuch-deliver/src/main.c12
-rw-r--r--contrib/notmuch-mutt/.gitignore2
-rw-r--r--contrib/notmuch-mutt/Makefile12
-rw-r--r--contrib/notmuch-mutt/README59
-rwxr-xr-xcontrib/notmuch-mutt/notmuch-mutt297
-rw-r--r--contrib/notmuch-mutt/notmuch-mutt.rc9
-rw-r--r--crypto.c71
-rw-r--r--debian/.gitignore7
-rw-r--r--debian/NEWS.Debian14
-rw-r--r--debian/changelog81
-rw-r--r--debian/control37
-rw-r--r--debian/libnotmuch3.install (renamed from debian/libnotmuch2.install)0
-rw-r--r--debian/libnotmuch3.symbols (renamed from debian/libnotmuch2.symbols)7
-rw-r--r--debian/notmuch-mutt.docs1
-rw-r--r--debian/notmuch-mutt.install2
-rw-r--r--debian/notmuch-mutt.manpages1
-rwxr-xr-xdebian/rules2
-rw-r--r--devel/RELEASING (renamed from RELEASING)0
-rw-r--r--devel/STYLE88
-rw-r--r--devel/TODO (renamed from TODO)10
-rw-r--r--devel/schemata155
-rw-r--r--devel/uncrustify.cfg117
-rw-r--r--emacs/Makefile.local4
-rw-r--r--emacs/notmuch-address.el9
-rw-r--r--emacs/notmuch-crypto.el28
-rw-r--r--emacs/notmuch-hello.el728
-rw-r--r--emacs/notmuch-lib.el376
-rw-r--r--emacs/notmuch-maildir-fcc.el13
-rw-r--r--emacs/notmuch-message.el5
-rw-r--r--emacs/notmuch-mua.el227
-rw-r--r--emacs/notmuch-print.el92
-rw-r--r--emacs/notmuch-show.el966
-rw-r--r--emacs/notmuch-tag.el145
-rw-r--r--emacs/notmuch-wash.el107
-rw-r--r--emacs/notmuch.el804
-rw-r--r--lib/Makefile.local2
-rw-r--r--lib/database.cc147
-rw-r--r--lib/directory.cc41
-rw-r--r--lib/index.cc15
-rw-r--r--lib/message.cc117
-rw-r--r--lib/notmuch-private.h43
-rw-r--r--lib/notmuch.h122
-rw-r--r--lib/query.cc127
-rw-r--r--lib/thread.cc18
-rw-r--r--man/.gitignore2
-rw-r--r--man/man1/notmuch-config.1150
-rw-r--r--man/man1/notmuch-count.120
-rw-r--r--man/man1/notmuch-dump.117
-rw-r--r--man/man1/notmuch-new.117
-rw-r--r--man/man1/notmuch-reply.160
-rw-r--r--man/man1/notmuch-restore.120
-rw-r--r--man/man1/notmuch-search.125
-rw-r--r--man/man1/notmuch-show.183
-rw-r--r--man/man1/notmuch-tag.118
-rw-r--r--man/man1/notmuch.19
-rw-r--r--man/man5/notmuch-hooks.510
-rw-r--r--man/man7/notmuch-search-terms.79
-rw-r--r--mime-node.c124
-rw-r--r--notmuch-client.h134
-rw-r--r--notmuch-config.c226
-rw-r--r--notmuch-count.c29
-rw-r--r--notmuch-dump.c10
-rw-r--r--notmuch-new.c324
-rw-r--r--notmuch-reply.c600
-rw-r--r--notmuch-restore.c157
-rw-r--r--notmuch-search.c344
-rw-r--r--notmuch-setup.c73
-rw-r--r--notmuch-show.c1306
-rw-r--r--notmuch-tag.c189
-rw-r--r--show-message.c102
-rw-r--r--sprinter-json.c199
-rw-r--r--sprinter-text.c133
-rw-r--r--sprinter.h71
-rw-r--r--test/Makefile.local4
-rw-r--r--test/README21
-rwxr-xr-xtest/config60
-rwxr-xr-xtest/crypto55
-rwxr-xr-xtest/dump-restore28
-rwxr-xr-xtest/emacs320
-rwxr-xr-xtest/emacs-address-cleaning15
-rw-r--r--test/emacs-address-cleaning.el39
-rwxr-xr-xtest/emacs-hello69
-rwxr-xr-xtest/emacs-large-search-buffer12
-rwxr-xr-xtest/emacs-show39
-rwxr-xr-xtest/emacs-test-functions9
-rw-r--r--test/emacs.expected-output/notmuch-hello9
-rw-r--r--test/emacs.expected-output/notmuch-hello-empty-custom-queries-section3
-rw-r--r--test/emacs.expected-output/notmuch-hello-empty-custom-tags-section5
-rw-r--r--test/emacs.expected-output/notmuch-hello-long-names18
-rw-r--r--test/emacs.expected-output/notmuch-hello-new-section4
-rw-r--r--test/emacs.expected-output/notmuch-hello-no-saved-searches7
-rw-r--r--test/emacs.expected-output/notmuch-hello-section-counts5
-rw-r--r--test/emacs.expected-output/notmuch-hello-section-hidden-tag4
-rw-r--r--test/emacs.expected-output/notmuch-hello-section-with-empty4
-rw-r--r--test/emacs.expected-output/notmuch-hello-with-empty9
-rwxr-xr-xtest/encoding14
-rwxr-xr-xtest/excludes423
-rwxr-xr-xtest/from-guessing126
-rwxr-xr-xtest/json49
-rwxr-xr-xtest/maildir-sync28
-rwxr-xr-xtest/multipart205
-rwxr-xr-xtest/new37
-rwxr-xr-xtest/notmuch-test8
-rwxr-xr-xtest/python8
-rwxr-xr-xtest/raw7
-rwxr-xr-xtest/reply129
-rwxr-xr-xtest/reply-to-sender209
-rwxr-xr-xtest/search-folder-coherence2
-rwxr-xr-xtest/search-output2
-rwxr-xr-xtest/search-position-overlap-bug4
-rwxr-xr-xtest/symbol-hiding2
-rw-r--r--test/symbol-test.cc3
-rwxr-xr-xtest/tagging8
-rw-r--r--test/test-lib.el61
-rw-r--r--test/test-lib.sh87
-rwxr-xr-xtest/text55
-rwxr-xr-xtest/thread-naming62
-rw-r--r--util/Makefile.local1
-rw-r--r--version2
-rw-r--r--vim/Makefile19
-rw-r--r--vim/plugin/notmuch.vim5
174 files changed, 11822 insertions, 6327 deletions
diff --git a/.dir-locals.el b/.dir-locals.el
index 044c214..fc75ae6 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -1,6 +1,6 @@
-; emacs local configuration settings for notmuch source
-; surmised by dkg on 2010-11-23 13:43:18-0500
-; amended by amdragon on 2011-06-06
+;; emacs local configuration settings for notmuch source
+;; surmised by dkg on 2010-11-23 13:43:18-0500
+;; amended by amdragon on 2011-06-06
((c-mode
(indent-tabs-mode . t)
diff --git a/.gitignore b/.gitignore
index d64ec9f..d428290 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,7 +7,6 @@ tags
/notmuch
notmuch.sym
notmuch-shared
-notmuch.1.gz
libnotmuch.so*
libnotmuch*.dylib
*.[ao]
diff --git a/INSTALL b/INSTALL
index e51b397..fce9352 100644
--- a/INSTALL
+++ b/INSTALL
@@ -20,8 +20,8 @@ configure stage.
Dependencies
------------
-Notmuch depends on three libraries: Xapian, GMime 2.4, and Talloc
-which are each described below:
+Notmuch depends on three libraries: Xapian, GMime 2.4 or 2.6, and
+Talloc which are each described below:
Xapian
------
@@ -39,14 +39,14 @@ which are each described below:
reading mail while notmuch would wait for Xapian when removing
the "inbox" and "unread" tags from messages in a thread.
- GMime 2.4
- ---------
- GMime 2.4 provides decoding of MIME email messages for Notmuch.
+ GMime 2.4 or 2.6
+ ----------------
+ GMime provides decoding of MIME email messages for Notmuch.
Without GMime, Notmuch would not be able to extract and index
the actual text from email message encoded as BASE64, etc.
- GMime 2.4 is available from http://spruce.sourceforge.net/gmime/
+ GMime is available from http://spruce.sourceforge.net/gmime/
Talloc
------
@@ -65,7 +65,7 @@ dependencies with a simple simple command line. For example:
For Debian and similar:
- sudo apt-get install libxapian-dev libgmime-2.4-dev libtalloc-dev
+ sudo apt-get install libxapian-dev libgmime-2.6-dev libtalloc-dev
For Fedora and similar:
diff --git a/Makefile.local b/Makefile.local
index d3bf947..b3b960c 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -256,35 +256,20 @@ endif
quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))
%.o: %.cc $(global_deps)
- $(call quiet,CXX $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@
+ @mkdir -p .deps/$(@D)
+ $(call quiet,CXX $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d
%.o: %.c $(global_deps)
- $(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@
-
-.deps/%.d: %.c $(global_deps)
- @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
- $(CC) -M $(CPPFLAGS) $(FINAL_CFLAGS) $< > $@.$$$$ 2>/dev/null ; \
- sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \
- rm -f $@.$$$$
-
-.deps/%.d: %.cc $(global_deps)
- @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
- $(CXX) -M $(CPPFLAGS) $(FINAL_CXXFLAGS) $< > $@.$$$$ 2>/dev/null ; \
- sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \
- rm -f $@.$$$$
-
-DEPS := $(SRCS:%.c=.deps/%.d)
-DEPS := $(DEPS:%.cc=.deps/%.d)
--include $(DEPS)
+ @mkdir -p .deps/$(@D)
+ $(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d
.PHONY : clean
clean:
- rm -f $(CLEAN); rm -rf .deps
+ rm -rf $(CLEAN); rm -rf .deps
-# We don't (yet) have any distributed files not in the upstream repository.
-# So distclean is currently identical to clean.
.PHONY: distclean
distclean: clean
+ rm -rf $(DISTCLEAN)
notmuch_client_srcs = \
command-line-arguments.c\
@@ -304,9 +289,11 @@ notmuch_client_srcs = \
notmuch-show.c \
notmuch-tag.c \
notmuch-time.c \
+ sprinter-json.c \
+ sprinter-text.c \
query-string.c \
- show-message.c \
mime-node.c \
+ crypto.c \
json.c
notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
@@ -350,3 +337,9 @@ install-desktop:
SRCS := $(SRCS) $(notmuch_client_srcs)
CLEAN := $(CLEAN) notmuch notmuch-shared $(notmuch_client_modules) notmuch.elc
+
+DISTCLEAN := $(DISTCLEAN) .first-build-message Makefile.config
+
+DEPS := $(SRCS:%.c=.deps/%.d)
+DEPS := $(DEPS:%.cc=.deps/%.d)
+-include $(DEPS)
diff --git a/NEWS b/NEWS
index bf21e64..761b2c1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,386 @@
+Notmuch 0.14 (xxxx-xx-xx)
+=========================
+
+General bug fixes
+-----------------
+
+Maildir tag synchronization
+
+ Maildir flag-to-tag synchronization now applies only to messages in
+ maildir-like directory structures. Previously, it applied to any
+ message that had a maildir "info" part, which meant it could
+ incorrectly synchronize tags for non-maildir messages, while at the
+ same time failing to synchronize tags for newly received maildir
+ messages (typically causing new messages to not receive the "unread"
+ tag).
+
+Command-Line Interface
+----------------------
+
+ The deprecated positional output file argument to `notmuch dump` has
+ been replaced with an `--output` option. The input file positional
+ argument to `notmuch restore` has been replaced with an `--input`
+ option for consistency with dump. These changes simplify the syntax
+ of dump/restore options and make them more consistent with other
+ notmuch commands.
+
+Emacs Interface
+---------------
+
+Search results now get re-colored when tags are updated
+
+The formatting of tags in search results can now be customized
+
+ Previously, attempting to change the format of tags in
+ `notmuch-search-result-format` would usually break tagging from
+ search-mode. We no longer make assumptions about the format.
+
+Experimental support for multi-line search result formats
+
+ It is now possible to embed newlines in
+ `notmuch-search-result-format` to make individual search results
+ span multiple lines.
+
+Search now uses the JSON format internally
+
+ This should address problems with unusual characters in authors and
+ subject lines that could confuse the old text-based search parser.
+
+The date shown in search results is no longer padded before applying
+user-specified formatting
+
+ Previously, the date in the search results was padded to fixed width
+ before being formatted with `notmuch-search-result-format`. It is
+ no longer padded. The default format has been updated, but if
+ you've customized this variable, you may have to change your date
+ format from `"%s "` to `"%12s "`.
+
+Notmuch 0.13.2 (2012-06-02)
+===========================
+
+Bug-fix release
+---------------
+
+Update contrib/notmuch-deliver for API changes in 0.13. This fixes a
+compilation error for this contrib package.
+
+Notmuch 0.13.1 (2012-05-29)
+===========================
+
+Bug-fix release
+---------------
+
+Fix inserting of UTF-8 characters from *text/plain* parts in reply
+
+ While notmuch gained ability to insert content from other than *text/plain*
+ parts of email whenever *text/plain* parts are not available (notably
+ HTML-only emails), replying to mails that do have *text/plain* the
+ non-ASCII characters were incorrectly decoded. This is now fixed.
+
+`notmuch_database_get_directory` and
+`notmuch_database_find_message_by_filename` now work on read-only
+databases
+
+ Previously, these functions attempted to create directory documents
+ that didn't exist and would return an error or abort when given a
+ read-only database. Now they no longer create directory documents
+ and simply return a `NULL` object if the directory does not exist,
+ as documented.
+
+Fix compilation of ruby bindings.
+
+ Revert to dynamic linking, since the statically linked bindings did
+ not work well.
+
+Notmuch 0.13 (2012-05-15)
+=========================
+
+Command-Line Interface
+----------------------
+
+JSON reply format
+
+ `notmuch reply` can now produce JSON output that contains the headers
+ for a reply message and full information about the original message
+ begin replied to. This allows MUAs to create replies intelligently.
+ For example, an MUA that can parse HTML might quote HTML parts.
+
+ Calling notmuch reply with `--format=json` imposes the restriction that
+ only a single message is returned by the search, as replying to
+ multiple messages does not have a well-defined behavior. The default
+ retains its current behavior for multiple message replies.
+
+Tag exclusion
+
+ Tags can be automatically excluded from search results by adding them
+ to the new `search.exclude_tags` option in the Notmuch config file.
+
+ This behaviour can be overridden by explicitly including an excluded
+ tag in your query, for example:
+
+ notmuch search $your_query and tag:$excluded_tag
+
+ Existing users will probably want to run `notmuch setup` again to add
+ the new well-commented [search] section to the configuration file.
+
+ For new configurations, accepting the default setting will cause the
+ tags "deleted" and "spam" to be excluded, equivalent to running:
+
+ notmuch config set search.exclude_tags deleted spam
+
+Raw show format changes
+
+ The output of show `--format=raw` has changed for multipart and
+ message parts. Previously, the output was a mash of somewhat-parsed
+ headers and transfer-decoded bodies. Now, such parts are reproduced
+ faithfully from the original source. Message parts (which includes
+ part 0) output the full message, including the message headers (but
+ not the transfer headers). Multipart parts output the part as
+ encoded in the original message, including the part's headers. Leaf
+ parts, as before, output the part's transfer-decoded body.
+
+Listing configuration items
+
+ The new `config list` command prints out all configuration items and
+ their values.
+
+Emacs Interface
+---------------
+
+Changes to tagging interface
+
+ The user-facing tagging functions in the Emacs interface have been
+ normalized across all notmuch modes. The tagging functions are now
+ notmuch-search-tag in search-mode, and notmuch-show-tag in
+ show-mode. They accept a string representing a single tag change,
+ or a list of tag changes. See 'M-x describe-function notmuch-tag'
+ for more information.
+
+ NOTE: This breaks compatibility with old tagging functions, so user
+ may need to update in custom configurations.
+
+Reply improvement using the JSON format
+
+ Emacs now uses the JSON reply format to create replies. It obeys
+ the customization variables message-citation-line-format and
+ message-citation-line-function when creating the first line of the
+ reply body, and it will quote HTML parts if no text/plain parts are
+ available.
+
+New add-on tool: notmuch-mutt
+-----------------------------
+
+The new contrib/ tool `notmuch-mutt` provides Notmuch integration for
+the Mutt mail user agent. Using it, Mutt users can perform mail
+search, thread reconstruction, and mail tagging/untagging without
+leaving Mutt. notmuch-mutt, formerly distributed under the name
+`mutt-notmuch` by Stefano Zacchiroli, will be maintained as a notmuch
+contrib/ from now on.
+
+Library changes
+---------------
+
+The API changes detailed below break binary and source compatibility,
+so libnotmuch has been bumped to version 3.0.0.
+
+The function `notmuch_database_close` has been split into
+`notmuch_database_close` and `notmuch_database_destroy`
+
+ This makes it possible for long running programs to close the xapian
+ database and thus release the lock associated with it without
+ destroying the data structures obtained from it.
+
+`notmuch_database_open`, `notmuch_database_create`, and
+`notmuch_database_get_directory` now return errors
+
+ The type signatures of these functions have changed so that the
+ functions now return a `notmuch_status_t` and take an out-argument for
+ returning the new database object or directory object.
+
+Go bindings changes
+-------------------
+
+Go 1 compatibility
+
+ The go bindings and the `notmuch-addrlookup` utility are now
+ compatible with go 1.
+
+Notmuch 0.12 (2012-03-20)
+=========================
+
+Command-Line Interface
+----------------------
+
+Reply to sender
+
+ `notmuch reply` has gained the ability to create a reply template
+ for replying just to the sender of the message, in addition to reply
+ to all. The feature is available through the new command line option
+ `--reply-to=(all|sender)`.
+
+Mail store folder/file ignore
+
+ A new configuration option, `new.ignore`, lets users specify a
+ ;-separated list of file and directory names that will not be
+ searched for messages by `notmuch new`.
+
+ NOTE: *Every* file/directory that goes by one of those names will
+ be ignored, independent of its depth/location in the mail store.
+
+Unified help and manual pages
+
+ The notmuch help command now runs man for the appropriate page. If
+ you install notmuch somewhere "unusual", you may need to update
+ MANPATH.
+
+Manual page for notmuch configuration options
+
+ The notmuch CLI configuration file options are now documented in the
+ notmuch-config(1) manual page in addition to the configuration file
+ itself.
+
+Emacs Interface
+---------------
+
+Reply to sender
+
+ The Emacs interface has, with the new CLI support, gained the
+ ability to reply to sender in addition to reply to all. In both show
+ and search modes, 'r' has been bound to reply to sender, replacing
+ reply to all, which now has key binding 'R'.
+
+More flexible and consistent tagging operations
+
+ All tagging operations ('+', '-', '*') now accept multiple tags with
+ '+' or '-' prefix, like '*' operation in notmuch-search view before.
+
+ '*' operation (`notmuch-show-tag-all`) is now available in
+ notmuch-show view.
+
+ `notmuch-show-{add,remove}-tag` functions no longer accept tag
+ argument, `notmuch-show-tag-message` should be used instead. Custom
+ bindings using these functions should be updated, e.g.:
+
+ (notmuch-show-remove-tag "unread")
+
+ should be changed to:
+
+ (notmuch-show-tag-message "-unread")
+
+Refreshing the show view ('=' by default) no longer opens or closes messages
+
+ To get the old behavior of putting messages back in their initial
+ opened/closed state, use a prefix argument, e.g., 'C-u ='.
+
+Attachment buttons can be used to view or save attachments.
+
+ When the cursor is on an attachment button the key 's' can be used
+ to save the attachment, the key 'v' to view the attachment in the
+ default mailcap application, and the key 'o' prompts the user for an
+ application to use to open the attachment. By default Enter or mouse
+ button 1 saves the attachment but this is customisable (option
+ Notmuch Show Part Button Default Action).
+
+New functions
+
+ `notmuch-show-stash-mlarchive-link{,-and-go}` allow stashing and
+ optionally visiting a URI to the current message at one of a number
+ of Mailing List Archives.
+
+Fix MML tag quoting in replies
+
+ The MML tag quoting fix of 0.11.1 unintentionally quoted tags
+ inserted in `message-setup-hook`. Quoting is now limited to the
+ cited message.
+
+Show view archiving key binding changes
+
+ The show view archiving key bindings 'a' and 'x' now remove the
+ "inbox" tag from the current message only (instead of thread), and
+ move to the next message. At the last message, 'a' proceeds to the
+ next thread in search results, and 'x' returns to search
+ results. The thread archiving functions are now available in 'A' and
+ 'X'.
+
+Support text/calendar MIME type
+
+ The text/calendar MIME type is now supported in addition to
+ text/x-vcalendar.
+
+Generate inline patch fake attachment file names from message subject
+
+ Use the message subject to generate file names for the inline patch
+ fake attachments. The names are now similar to the ones generated by
+ 'git format-patch' instead of just "inline patch". See "Notmuch Show
+ Insert Text/Plain Hook" in the notmuch customize interface.
+
+Enable `notmuch-search-line-faces` by default
+
+ Make the `notmuch-search-line-faces` functionality more discoverable
+ for new users by showing "unread" messages bold and "flagged"
+ messages blue by default in the search view.
+
+Printing Support
+
+ notmuch-show mode now has simple printing support, bound to '#' by
+ default. You can customize the variable notmuch-print-mechanism.
+
+Library changes
+---------------
+
+New functions
+
+ `notmuch_query_add_tag_exclude` supports the new tag exclusion
+ feature.
+
+Python bindings changes
+-----------------------
+
+Python 3.2 compatibility
+
+ The python bindings are now compatible with both python 2.5+ and 3.2.
+
+Added missing unicode conversions
+
+ Python strings have to be encoded to and decoded from utf-8 when
+ calling libnotmuch functions. Porting the bindings to python 3.2
+ revealed a few function calls that were missing these conversions.
+
+Build fixes
+-----------
+
+Compatibility with GMime 2.6
+
+ It is now possible to build notmuch against both GMime 2.4 and 2.6.
+ However, a bug in GMime 2.6 before 2.6.5 causes notmuch not to
+ report signatures where the signer key is unavailable (GNOME bug
+ 668085). For compatibility with GMime 2.4's tolerance of "From "
+ headers we require GMime 2.6 >= 2.6.7.
+
+Notmuch 0.11.1 (2012-02-03)
+===========================
+
+Bug-fix release
+---------------
+
+Fix error handling in python bindings
+
+ The python bindings in 0.11 failed to detect NULL pointers being
+ returned from libnotmuch functions and thus failed to raise
+ exceptions to indicate the error condition. Any subsequent calls
+ into libnotmuch caused segmentation faults.
+
+Quote MML tags in replies
+
+ MML tags are text codes that Emacs uses to indicate attachments
+ (among other things) in messages being composed. The Emacs
+ interface did not quote MML tags in the quoted text of a reply.
+ User could be tricked into replying to a maliciously formatted
+ message and not editing out the MML tags from the quoted text. This
+ could lead to files from the user's machine being attached to the
+ outgoing message. The Emacs interface now quotes these tags in
+ reply text, so that they do not effect outgoing messages.
+
Notmuch 0.11 (2012-01-13)
=========================
@@ -7,13 +390,13 @@ Command-Line Interface
Hooks
Hooks have been introduced to notmuch. Hooks are scripts that notmuch
- invokes before and after certain actions. Initially, "notmuch new"
- supports "pre-new" and "post-new" hooks that are run before and after
+ invokes before and after certain actions. Initially, `notmuch new`
+ supports `pre-new` and `post-new` hooks that are run before and after
importing new messages into the database.
-notmuch reply --decrypt bugfix
+`notmuch reply --decrypt bugfix`
- The "notmuch reply" command with --decrypt argument had a rarely
+ The `notmuch reply` command with `--decrypt` argument had a rarely
occurring bug that caused an encrypted message not to be decrypted
sometimes. This is now fixed.
@@ -22,7 +405,7 @@ Performance
Automatic tag query optimization
- "notmuch tag" now automatically optimizes the user's query to
+ `notmuch tag` now automatically optimizes the user's query to
exclude messages whose tags won't change. In the past, we've
suggested that people do this by hand; this is no longer necessary.
@@ -30,7 +413,7 @@ Don't sort messages when creating a dump file
This speeds up tag dumps considerably, without any loss of
information. To replicate the old behavior of sorted output (for
- example to compare two dump files), one can use e.g. sort(1).
+ example to compare two dump files), one can use e.g. `sort(1)`.
Memory Management
-----------------
@@ -50,11 +433,11 @@ Bug fixes
should have scrolled down to show more of the current message instead.
This is now fixed.
-Support "notmuch new" as a notmuch-poll-script
+Support `notmuch new` as a notmuch-poll-script
- It's now possible to use "notmuch new" as a notmuch-poll-script
+ It's now possible to use `notmuch new` as a notmuch-poll-script
directly. This is also the new default. This allows taking better
- advantage of the "notmuch new" hooks from emacs without intermediate
+ advantage of the `notmuch new` hooks from emacs without intermediate
scripts.
Improvements in saved search management
@@ -83,7 +466,7 @@ Use space as default thousands separator
changed by customizing "notmuch-hello-thousands-separator".
Call notmuch-show instead of notmuch-search when clicking on
-buttonized id: links.
+buttonized id: links
New function notmuch-show-advance
@@ -91,39 +474,39 @@ New function notmuch-show-advance
less invasive than notmuch-show-advance-and-archive. It can easily
be bound to SPC with:
- (define-key notmuch-show-mode-map " " 'notmuch-show-advance)
+ (define-key notmuch-show-mode-map " " 'notmuch-show-advance)
-Various performance improvements.
+Various performance improvements
New add-on tool
---------------
-The tool contrib/notmuch-deliver helps with initial delivery and
-tagging of mail (replacing running notmuch new).
+The tool `contrib/notmuch-deliver` helps with initial delivery and
+tagging of mail (replacing running `notmuch new`).
Notmuch 0.10.2 (2011-12-04)
===========================
-Bug-fix release.
-----------------
+Bug-fix release
+---------------
-Fix crash in python bindings.
+Fix crash in python bindings
- The python bindings did not call g_type_init, which caused crashes
- for some, but not all users.
+ The python bindings did not call `g_type_init`, which caused crashes
+ for some, but not all users.
Notmuch 0.10.1 (2011-11-25)
===========================
-Bug-fix release.
-----------------
+Bug-fix release
+---------------
-Fix --help argument
+Fix `--help` argument
- Argument processing changes in 0.10 introduced a bug where "notmuch
- --help" crashed while "notmuch help" worked fine. This is fixed in
- 0.10.1.
+ Argument processing changes in 0.10 introduced a bug where
+ `notmuch --help` crashed while `notmuch help` worked fine.
+ This is fixed in 0.10.1.
Notmuch 0.10 (2011-11-23)
=========================
@@ -131,7 +514,7 @@ Notmuch 0.10 (2011-11-23)
New build and testing features
------------------------------
-Emacs tests are now done in dtach. This means that dtach is now
+Emacs tests are now done in `dtach`. This means that dtach is now
needed to run the notmuch test suite, at least until the checking for
prerequisites is improved.
@@ -140,32 +523,33 @@ Full test coverage of the stashing feature in Emacs.
New command-line features
-------------------------
-Add "notmuch restore --accumulate" option
+Add `notmuch restore --accumulate` option
- The --accumulate switch causes the union of the existing and new tags to be
- applied, instead of replacing each message's tags as they are read in from
- the dump file.
+ The `--accumulate` switch causes the union of the existing and new tags to
+ be applied, instead of replacing each message's tags as they are read in
+ from the dump file.
-Add search terms to "notmuch dump"
+Add search terms to `notmuch dump`
The dump command now takes an optional search term much like notmuch
search/show/tag. The output file argument of dump is deprecated in
favour of using stdout.
-Add "notmuch search" --offset and --limit options
+Add `notmuch search` `--offset` and `--limit` options
- The search command now takes options --offset=[-]N and --limit=N to limit
- the number of results shown.
+ The search command now takes options `--offset=[-]N` and `--limit=N` to
+ limit the number of results shown.
-Add "notmuch count --output" option
+Add `notmuch count --output` option
The count command is now capable of counting threads in addition to
- messages. This is selected using the new --output=(threads|messages) option.
+ messages. This is selected using the new `--output=(threads|messages)`
+ option.
New emacs UI features
---------------------
-Add tab-completion for notmuch-search and notmuch-search-filter
+Add tab-completion for `notmuch-search` and `notmuch-search-filter`
These functions now support completion tags for query parts
starting with "tag:".
@@ -179,10 +563,10 @@ Add keybinding ('c I') for stashing Message-ID's without an id: prefix
Reduces manual labour when stashing them for use outside notmuch.
-Do not query on notmuch-search exit
+Do not query on `notmuch-search` exit
- It is harmless to kill the external notmuch process, so the user
- is no longer interrogated when they interrupt a search.
+ It is harmless to kill the external notmuch process, so the user
+ is no longer interrogated when they interrupt a search.
Performance
-----------
@@ -196,10 +580,10 @@ Search avoids opening and parsing message files
improve search speed by as much as 10X, but taking advantage of this
requires a database rebuild:
- notmuch dump > notmuch.dump
- # Backup, then remove notmuch database ($MAIL/.notmuch)
- notmuch new
- notmuch restore notmuch.dump
+ notmuch dump > notmuch.dump
+ # Backup, then remove notmuch database ($MAIL/.notmuch)
+ notmuch new
+ notmuch restore notmuch.dump
New collection of add-on tools
------------------------------
@@ -211,9 +595,9 @@ mailing list.
nmbug - share tags with a given prefix
- nmbug helps maintain a git repo containing all tags with a given
- prefix (by default "notmuch::"). Tags can be shared by commiting
- them to git in one location and restoring in another.
+ nmbug helps maintain a git repo containing all tags with a given
+ prefix (by default "notmuch::"). Tags can be shared by commiting
+ them to git in one location and restoring in another.
Notmuch 0.9 (2011-10-01)
========================
@@ -221,9 +605,9 @@ Notmuch 0.9 (2011-10-01)
New, general features
---------------------
-Correct handling of interruptions during "notmuch new"
+Correct handling of interruptions during `notmuch new`
- "notmuch new" now operates as a series of small, self-consistent
+ `notmuch new` now operates as a series of small, self-consistent
transactions, so it can correctly resume after an interruption or
crash. Previously, interruption could lose existing tags, fail to
detect messages on resume, or leave the database in a state
@@ -234,14 +618,14 @@ Library changes
New functions
- notmuch_database_begin_atomic and notmuch_database_end_atomic allow
- multiple database operations to be performed atomically.
+ `notmuch_database_begin_atomic` and `notmuch_database_end_atomic`
+ allow multiple database operations to be performed atomically.
- notmuch_database_find_message_by_filename does exactly what it says.
+ `notmuch_database_find_message_by_filename` does exactly what it says.
API changes
- notmuch_database_find_message (and n_d_f_m_by_filename) now return
+ `notmuch_database_find_message` (and `n_d_f_m_by_filename`) now return
a status indicator and uses an output parameter for the
message. This change required changing the SONAME of libnotmuch to
libnotmuch.so.2
@@ -251,33 +635,33 @@ Python bindings changes
- Re-encode python unicode objects to utf-8 before passing back to
libnotmuch.
- - Support Database().begin_atomic()/end_atomic()
- - Support Database().find_message_by_filename()
+ - Support `Database().begin_atomic()/end_atomic()`
+ - Support `Database().find_message_by_filename()`
NB! This needs a db opened in READ-WRITE mode currently, or it will crash
the python process. The is a limitation (=bug) of the underlying libnotmuch.
- Fixes where we would not throw NotmuchErrors when we should (Justus Winter)
- - Update for n_d_find_message* API changes (see above).
+ - Update for `n_d_find_message*` API changes (see above).
Ruby bindings changes
---------------------
- - Wrap new library functions notmuch_database_{begin,end}_atomic.
- - Add new exception Notmuch::UnbalancedAtomicError.
- - Rename destroy to destroy! according to Ruby naming conventions.
- - Update for n_d_find_message* API changes (see above).
+ - Wrap new library functions `notmuch_database_{begin,end}_atomic.`
+ - Add new exception `Notmuch::UnbalancedAtomicError.`
+ - Rename destroy to destroy! according to Ruby naming conventions.
+ - Update for `n_d_find_message*` API changes (see above).
Emacs improvements
------------------
* Add gpg callback to crypto sigstatus buttons to retrieve/refresh
signing key.
- * Add notmuch-show-refresh-view function (and corresponding binding)
+ * Add `notmuch-show-refresh-view` function (and corresponding binding)
to refresh the view of a notmuch-show buffer.
Reply formatting cleanup
------------------------
- "notmuch reply" no longer includes notification that non-leafnode
+ `notmuch reply` no longer includes notification that non-leafnode
MIME parts are being suppressed.
Notmuch 0.8 (2011-09-10)
@@ -304,7 +688,7 @@ Documentation update for Ruby bindings
Unicode, iterator, PEP8 changes for python bindings
- PEP8 (code formatting) changes for python files.
- - Remove Tags.__len__ ; see 0.6 release notes for motivation.
+ - Remove `Tags.__len__` ; see 0.6 release notes for motivation.
- Decode headers as UTF8, encode (unicode) database paths as UTF8.
Notmuch 0.7 (2011-08-01)
@@ -335,7 +719,7 @@ Sebastian Spaeth contributed two changes related to unicode and UTF8:
* query string is encoded as a UTF8 byte string
Build-System improvements
-------------------------
+-------------------------
Generate notmuch.sym after the relevant object files
@@ -345,31 +729,33 @@ Generate notmuch.sym after the relevant object files
Notmuch 0.6.1 (2011-07-17)
==========================
-Bug-fix release.
-----------------
+Bug-fix release
+---------------
-Re-export Xapian exception typeinfo symbols.
+Re-export Xapian exception typeinfo symbols
It turned out our aggressive symbol hiding caused problems for
people running gcc 4.4.5.
Notmuch 0.6 (2011-07-01)
=======================
+
New, general features
---------------------
+
Folder-based searching
Notmuch queries can now include a search term to match the
directories in which mail files are stored (within the mail
storage). The syntax is as follows:
- folder:<path>
+ folder:<path>
For example, one might use things such as:
- folder:spam
- folder:2011-*
- folder:work/todo
+ folder:spam
+ folder:2011-*
+ folder:work/todo
to match any path containing a directory "spam", "work/todo", or
containing a directory starting with "2011-", respectively.
@@ -384,14 +770,14 @@ Folder-based searching
this feature for all mail, the entire notmuch index will need to be
rebuilt as follows:
- notmuch dump > notmuch.dump
- # Backup, then remove notmuch database ($MAIL/.notmuch)
- notmuch new
- notmuch restore notmuch.dump
+ notmuch dump > notmuch.dump
+ # Backup, then remove notmuch database ($MAIL/.notmuch)
+ notmuch new
+ notmuch restore notmuch.dump
Support for PGP/MIME
- Both the command line interface and the emacs-interface have new
+ Both the command-line interface and the emacs-interface have new
support for PGP/MIME, detailed below. Thanks to Daniel Kahn Gillmor
and Jameson Graef Rollins for making this happen.
@@ -405,6 +791,7 @@ New, automatic tags: "signed" and "encrypted"
New command-line features
-------------------------
+
Add new "notmuch show --verify" option for signature verification
This option instruct notmuch to verify the signature of
@@ -432,7 +819,7 @@ Add new "notmuch show --part" option
part, (such as --format=json for extracting a message part with JSON
formatting).
-Deprecate "notmuch search-tags", (in favor of "notmuch search --output=tags *")
+Deprecate "notmuch search-tags" (in favor of "notmuch search --output=tags *")
The "notmuch search-tags" sub-command has been redundant since the
addition of the --output=tags option to "notmuch search". We now
@@ -442,6 +829,7 @@ Deprecate "notmuch search-tags", (in favor of "notmuch search --output=tags *")
Performance improvements
------------------------
+
Faster searches (by doing fewer searches to construct threads)
Whenever a user asks for search results as threads, notmuch first
@@ -484,7 +872,7 @@ Support for PGP/MIME (GnuPG)
messages. Automatically display decrypted content for
multipart/encrypted messages. See the emacs variable
notmuch-crypto-process-mime for more information. Note that this
- needs gpg-agent and a pinentry tool just as the command line tools.
+ needs gpg-agent and a pinentry tool just as the command-line tools.
Also note there is no support SMIME yet.
Output of pipe command is now displayed if pipe command fails
@@ -519,7 +907,7 @@ Automatic detection and hiding of original message in top-posted message
When a message contains a line looking something like:
- ----- Original Message -----
+ ----- Original Message -----
emacs hides this and all subsequent lines as an "original message",
(allowing the user to click or press enter on the "original message"
@@ -534,8 +922,8 @@ New hooks for running code when tags are modified
tool. To facilitate this, two new hooks are added which can be
modified in the following settings of the notmuch customize group:
- Notmuch Before Tag Hook
- Notmuch After Tag Hook
+ Notmuch Before Tag Hook
+ Notmuch After Tag Hook
New optional support for hiding some multipart/alternative parts
@@ -543,7 +931,7 @@ New optional support for hiding some multipart/alternative parts
multipart/alternative group (such as a text/plain part as well as a
text/html part). Users can configure the setting:
- Notmuch Show All Multipart/Alternative Parts
+ Notmuch Show All Multipart/Alternative Parts
to "off" in the notmuch customize group to have the interface
automatically hide some part alternatives (such as text/html
@@ -560,11 +948,14 @@ Avoid getting confused by Subject and Author fields with newline characters
Replacing all characters with ASCII code less than 32 with a question mark.
-Cleaner display of From line in email messages (remove double quotes,
-and drop "name" if it's actually just a repeat of the email address).
+Cleaner display of From line in email messages
+
+ Remove double quotes, and drop "name" if it's actually just a repeat of
+ the email address.
Vim interface improvements
--------------------------
+
Felipe Contreras provided a number of updates for the vim interface:
* Using sendmail directly rather than mailx,
@@ -575,47 +966,54 @@ Felipe Contreras provided a number of updates for the vim interface:
Bindings improvements
---------------------
+
Ruby bindings are now much more complete
- Including QUERY.sort, QUERY.to_s, MESSAGE.maildir_flags_to_tags,
- MESSAGE.tags_to_maildir_flags, and MESSAGE.get_filenames
+ Including `QUERY.sort`, `QUERY.to_s`, `MESSAGE.maildir_flags_to_tags`,
+ `MESSAGE.tags_to_maildir_flags`, and `MESSAGE.get_filenames`
+
+Python bindings have been updated and extended
-* Python bindings have been updated and extended
(docs online at http://packages.python.org/notmuch/)
New bindings:
- - Message().get_filenames(),
- - Message().tags_to_maildir_flags(),Message().maildir_flags_to_tags()
- - list(Threads()) and list(Messages) works now
- - Message().__cmp__() and __hash__()
+ - `Message().get_filenames()`, `Message().tags_to_maildir_flags()`,
+ `Message().maildir_flags_to_tags()`, `list(Threads())` and
+ `list(Messages)` works now
+ - `Message().__cmp__()` and `__hash__()`
+
These allow, for example:
- if msg1 == msg2: ...
- As well as set arithmetic on Messages():
+ if msg1 == msg2: ...
+
+ As well as set arithmetic on `Messages()`:
+
+ s1, s2 = set(msgs1), set(msgs2)
+ s1.union(s2)
+ s2 -= s1
- s1, s2= set(msgs1), set(msgs2)
- s1.union(s2)
- s2 -= s1
+ Removed:
- Removed:
- - len(Messages()) as it exhausted the iterator.
- Use len(list(Messages())) or
- Query.count_messages() to get the length.
+ - `len(Messages())` as it exhausted the iterator
+
+ Use `len(list(Messages()))` or `Query.count_messages()`
+ to get the length.
Added initial Go bindings in bindings/go
New build-system features
-------------------------
+
Added support for building in a directory other than the source directory
This can be used with the widely-supported idiom of simply running
the configure script from some other directory:
- mkdir build
- cd build
- ../configure
- make
+ mkdir build
+ cd build
+ ../configure
+ make
Fix to save configure options for future, implicit runs of configure
@@ -627,7 +1025,8 @@ Fix to save configure options for future, implicit runs of configure
New test-suite feature
----------------------
-Binary for bash for running test suite now located via PATH.
+
+Binary for bash for running test suite now located via PATH
The notmuch test suite requires a fairly recent version of bash (>=
bash 4). As some systems supply an older version of bash at
@@ -636,12 +1035,12 @@ Binary for bash for running test suite now located via PATH.
simply install bash >= 4 somewhere on $PATH before /bin and then use
the test suite.
-Support for testing output with a trailing newline.
+Support for testing output with a trailing newline
Previously, some tests would fail to notice a difference in the
presence/absence of a trailing newline in a program output, (which
has led to bugs in the past). Now, carefully-written tests (using
- test_expect_equal_file rather than test_expect_equal) will detect
+ `test_expect_equal_file` rather than `test_expect_equal`) will detect
any change in the presence/absence of a trailing newline. Many tests
are updated to take advantage of this.
@@ -655,6 +1054,7 @@ Avoiding accessing user's $HOME while running test suite
General bug fixes
-----------------
+
Output *all* files for "notmuch search --output=files"
For the cases where multiple files have the same Message ID,
@@ -665,11 +1065,11 @@ Fixed spurious search results from "overlapped" indexing of addresses
This fixed a bug where a search for:
- to:user@elsewhere.com
+ to:user@elsewhere.com
would incorrectly match a message sent:
- To: user@example,com, someone@elsewhere.com
+ To: user@example,com, someone@elsewhere.com
Fix --output=json when search has no results
@@ -678,15 +1078,15 @@ Fix --output=json when search has no results
return a valid json object representing an empty array "[]" as
expected.
-fix the automatic detection of the From address for "notmuch reply"
-from the Received headers in some cases.
+Fix the automatic detection of the From address for "notmuch reply"
+from the Received headers in some cases
Fix core dump on DragonFlyBSD due to -1 return value from
-sysconf(_SC_GETPW_R_SIZE_MAX).
+`sysconf(_SC_GETPW_R_SIZE_MAX)`
Cleaned up several memory leaks
-Eliminated a few, rare segmentation faults and a double-free.
+Eliminated a few, rare segmentation faults and a double-free
Fix libnotmuch library to only export notmuch API functions
@@ -696,6 +1096,7 @@ Fix libnotmuch library to only export notmuch API functions
Emacs-interface bug fixes
-------------------------
+
Display any unexpected output or errors from "notmuch search" invocations
Previously any misformatted output or trailing error messages were
@@ -723,21 +1124,23 @@ Fix hiding of a message when a previously-hidden citation is visible
Notmuch 0.5 (2010-11-11)
========================
+
New, general features
---------------------
+
Maildir-flag synchronization
Notmuch now knows how to synchronize flags in maildir filenames with
tags in the notmuch database. The following flag/tag mappings are
supported:
- Flag <-> Tag
- ---- -----
- 'D' draft
- 'F' flagged
- 'P' passed
- 'R' replied
- 'S' unread (added when 'S' flag is not present)
+ Flag <-> Tag
+ ---- -----
+ 'D' draft
+ 'F' flagged
+ 'P' passed
+ 'R' replied
+ 'S' unread (added when 'S' flag is not present)
The synchronization occurs in both directions, (for example, adding
the 'S' flag to a file will cause the "unread" tag to be added, and
@@ -747,10 +1150,10 @@ Maildir-flag synchronization
This synchronization is enabled by default for users of the
command-line interface, (though only files in directories named
"cur" or "new" will be renamed). It can be disabled by setting the
- new maildir.synchronize_flags option in the configuration file. For
+ new `maildir.synchronize_flags` option in the configuration file. For
example:
- notmuch config set maildir.synchronize_flags false
+ notmuch config set maildir.synchronize_flags false
Users upgrading may also want to run "notmuch setup" once (just
accept the existing configuration) to get a new, nicely-commented
@@ -759,8 +1162,8 @@ Maildir-flag synchronization
For users of the notmuch library, the new synchronization
functionality is available with the following two new functions:
- notmuch_message_maildir_flags_to_tags
- notmuch_message_tags_to_maildir_flags
+ notmuch_message_maildir_flags_to_tags
+ notmuch_message_tags_to_maildir_flags
It is anticipated that future improvements to this support will
allow for safe synchronization of the 'T' flag with the "deleted"
@@ -768,24 +1171,26 @@ Maildir-flag synchronization
New library features
--------------------
+
Support for querying multiple filenames for a single message
It is common for the mailstore to contain multiple files with the
same message ID. Previously, notmuch would always hide these
duplicate files, (returning a single, arbitrary filename with
- notmuch_message_get_filename).
+ `notmuch_message_get_filename`).
With this release, library users can access all filenames for a
message with the new function:
- notmuch_message_get_filenames
+ notmuch_message_get_filenames
- Together with notmuch_filenames_valid, notmuch_filenames_get, and
- notmuch_filenames_move_to_next it is now possible to iterate over
- all available filenames for a given message.
+ Together with `notmuch_filenames_valid`, `notmuch_filenames_get`,
+ and `notmuch_filenames_move_to_next` it is now possible to iterate
+ over all available filenames for a given message.
New command-line features
-------------------------
+
New "notmuch show --format=raw" for getting at original email contents
This new feature allows for a fully-functional email client to be
@@ -797,7 +1202,7 @@ New "notmuch show --format=raw" for getting at original email contents
do this, simply set the notmuch-command variable in emacs to the
name of a script containing:
- ssh user@host notmuch "$@"
+ ssh user@host notmuch "$@"
If the ssh client has enabled connection sharing (ControlMaster
option in OpenSSH), the emacs interface can be quite responsive this
@@ -805,11 +1210,12 @@ New "notmuch show --format=raw" for getting at original email contents
General bug fixes
-----------------
+
Fix "notmuch search" to print nothing when nothing matches
The 0.4 release had a bug in which:
- notmuch search <expression-with-no-matches>
+ notmuch search <expression-with-no-matches>
would produce a single blank line of output, (where previous
versions would produce no output. This fix also causes a change in
@@ -818,17 +1224,18 @@ Fix "notmuch search" to print nothing when nothing matches
Emacs interface improvements
----------------------------
+
Fix to allow pipe ('|') command to work when using notmuch over ssh
-Fix count of lines in hidden signatures.
+Fix count of lines in hidden signatures
-Omit repeated subject lines in (collapsed) thread display.
+Omit repeated subject lines in (collapsed) thread display
-Display current thread subject in a header line.
+Display current thread subject in a header line
-Provide a "c i" binding to copy a thread ID from the search view.
+Provide a "c i" binding to copy a thread ID from the search view
-Allow for notmuch-fcc-dirs to have a value of nil.
+Allow for notmuch-fcc-dirs to have a value of nil
Also, the more complex form of notmuch-fcc-dirs now has a slightly
different format. It no longer has a special first-element, fallback
@@ -840,7 +1247,8 @@ Allow for notmuch-fcc-dirs to have a value of nil.
Vim interface improvements
--------------------------
-Felipe Contreras provided a number of updates for the vim interface.
+
+Felipe Contreras provided a number of updates for the vim interface
These include optimizations, support for newer versions of vim, fixed
support for sending mail on modern systems, new commands, and
@@ -848,13 +1256,16 @@ Felipe Contreras provided a number of updates for the vim interface.
New bindings
------------
+
Added initial ruby bindings in bindings/ruby
Notmuch 0.4 (2010-11-01)
========================
+
New command-line features
-------------------------
-notmuch search --output=(summary|threads|messages|tags|files)
+
+`notmuch search --output=(summary|threads|messages|tags|files)`
This new option allows for particular items to be returned from
notmuch searches. The "summary" option is the default and behaves
@@ -865,11 +1276,11 @@ notmuch search --output=(summary|threads|messages|tags|files)
expected that this new option will be very useful in shell
scripts. For example:
- for file in $(notmuch search --output=files <search-terms>); do
- <operations-on> "$file"
- done
+ for file in $(notmuch search --output=files <search-terms>); do
+ <operations-on> "$file"
+ done
-notmuch show --format=mbox <search-specification>
+`notmuch show --format=mbox <search-specification>`
This new option allows for the messages matching a search
specification to be presented as an mbox. Specifically the "mboxrd"
@@ -878,7 +1289,7 @@ notmuch show --format=mbox <search-specification>
beginning of all lines beginning with one or more '>' characters
followed by the 5 characters "From ".
-notmuch config [get|set] <section>.<item> [value ...]
+`notmuch config [get|set] <section>.<item> [value ...]`
The new top-level "config" command allows for any value in the
notmuch configuration file to be queried or set to a new value. Both
@@ -894,13 +1305,15 @@ Avoid setting Bcc header in "notmuch reply"
New library features
--------------------
-Add notmuch_query_get_query_string and notmuch_query_get_sort
+
+Add `notmuch_query_get_query_string` and `notmuch_query_get_sort`
These are simply functions for querying properties of a
- notmuch_query_t object.
+ `notmuch_query_t` object.
New emacs features
------------------
+
Enable Fcc of all sent messages by default (to "sent" directory)
All messages sent from the emacs interface will now be saved to the
@@ -941,7 +1354,7 @@ Allow search-result color specifications to overlay each other
case in previous releases). See "Notmuch Search Line Faces" in the
notmuch customize interface.
-Make hidden author names still available for incremental search.
+Make hidden author names still available for incremental search
When there is insufficient space to display all authors of a thread
in search results, the names of hidden authors are now still made
@@ -958,6 +1371,7 @@ New binding of Control-TAB (works like TAB in reverse)
New build-system features
-------------------------
+
Various portability fixes have been applied
These include fixes for build failures on at least Solaris, FreeBSD,
@@ -970,18 +1384,18 @@ Arrange for libnotmuch to be found automatically after make install
errors of the form "libnotmuch.so could not be found" immediately
after installing. This support takes two forms:
- 1. If the library is installed to a system directory,
- (configured in /etc/ld.so.conf), then "make install" will
- automatically run ldconfig.
+ 1. If the library is installed to a system directory,
+ (configured in /etc/ld.so.conf), then "make install" will
+ automatically run ldconfig.
- 2. If the library is installed to a non-system directory, the
- build system adds a DR_RUNPATH entry to the final binary
- pointing to the directory to which the library is installed.
+ 2. If the library is installed to a non-system directory, the
+ build system adds a `DR_RUNPATH` entry to the final binary
+ pointing to the directory to which the library is installed.
When this support works, the user should be able to run notmuch
immediately after "make install", without any errors trying to find
the notmuch library, and without having to manually set environment
- variables such as LD_LIBRARY_PATH.
+ variables such as `LD_LIBRARY_PATH`.
Check compiler/linker options before using them
@@ -992,7 +1406,8 @@ Check compiler/linker options before using them
New test-suite features
-----------------------
-New modularization of test suite.
+
+New modularization of test suite
Thanks to a gracious relicensing of the test-suite infrastructure
from the git project, notmuch now has a modular test suite. This
@@ -1003,7 +1418,7 @@ New modularization of test suite.
it easy to run the test suite within valgrind (pass --valgrind to
notmuch-test or to any sub-script) which has been very useful.
-New testing of emacs interface.
+New testing of emacs interface
The test suite has been augmented to allow automated testing of the
emacs interfaces. So far, this includes basic searches, display of
@@ -1014,18 +1429,19 @@ New testing of emacs interface.
General bug fixes
-----------------
-Fix potential corruption of database when "notmuch new " is interrupted.
+
+Fix potential corruption of database when "notmuch new" is interrupted
Previously, an interruption of "notmuch new" would (rarely) result
in a corrupt database. The corruption would manifest itself by a
persistent error of the form:
- document ID of 1234 has no thread ID
+ document ID of 1234 has no thread ID
The message-adding code has been carefully audited and reworked to
avoid this sort of corruption regardless of when it is interrupted.
-Fix failure with extremely long message ID headers.
+Fix failure with extremely long message ID headers
Previously, a message with an extremely long message ID, (say, more
than 300 characters), would fail to be added to notmuch, (triggering
@@ -1037,9 +1453,10 @@ Fix for messages with "charset=unknown-8bit"
GMime warning, (which would then trip up emacs or other interfaces
parsing the notmuch results).
-Fix notmuch_query_search_threads function to return NULL on any exception
+Fix `notmuch_query_search_threads` function to return NULL on any exception
-Fix "notmuch search" to return non-zero if notmuch_query_search_threads fails
+Fix "notmuch search" to return non-zero if `notmuch_query_search_threads`
+fails
Previously, this command could confusingly report a Xapian
exception, yet still return an error code of 0. It now correctly
@@ -1047,6 +1464,7 @@ Fix "notmuch search" to return non-zero if notmuch_query_search_threads fails
Emacs bug fixes
---------------
+
Fix to handle a message with a subject containing, for example "[1234]"
Previously, a message subject containing a sequence of digits within
@@ -1063,11 +1481,13 @@ Fix to correctly handle message IDs containing ".."
Python-binding fixes
--------------------
+
The python bindings for notmuch have been updated to work with python3.
Debian-specific fixes
---------------------
-Fix emacs initialization so "M-x notmuch" works for users by default.
+
+Fix emacs initialization so "M-x notmuch" works for users by default
Now, a new Debian user can immediately run "emacs -f notmuch" after
"apt-get install notmuch". Previously, the user would have had to
@@ -1076,8 +1496,10 @@ Fix emacs initialization so "M-x notmuch" works for users by default.
Notmuch 0.3.1 (2010-04-27)
==========================
+
General bug fixes
-----------------
+
Fix an infinite loop in "notmuch reply"
This bug could be triggered by replying to a message where the
@@ -1093,22 +1515,26 @@ Fix a potential SEGV in "notmuch search"
Emacs bug fixes
---------------
-Fix calculations for line wrapping in the primary "notmuch" view.
+
+Fix calculations for line wrapping in the primary "notmuch" view
Fix Fcc support to prompt to create a directory if the specified Fcc
-directory does not exist.
+directory does not exist
Build fix
---------
-Fix build on OpenSolaris (at least) due to missing 'extern "C"' block.
+
+Fix build on OpenSolaris (at least) due to missing 'extern "C"' block
Without this, the C++ sources could not find strcasestr and the
final linking of notmuch would fail.
Notmuch 0.3 (2010-04-27)
========================
+
New command-line features
-------------------------
+
User-configurable tags for new messages
A new "new.tags" option is available in the configuration file to
@@ -1147,6 +1573,7 @@ Indication of author names that match a search
New: Python bindings
--------------------
+
Sebastian Spaeth has contributed his python bindings for the notmuch
library to the central repository. These bindings were previously
known as "cnotmuch" within python but have now been renamed to be
@@ -1163,6 +1590,7 @@ package-building scripts. Improvements are welcome.
Emacs interface improvements
----------------------------
+
An entirely new initial view for notmuch, (friendly yet powerful)
Some of us call the new view "notmuch hello" but you can get at it
@@ -1179,16 +1607,16 @@ An entirely new initial view for notmuch, (friendly yet powerful)
search of messages with that tag that's simply a click (or keypress)
away.
- Note: For users that liked the original mode of "emacs -f notmuch"
- immediately displaying a particular search result, we
- recommend instead running something like:
+ NOTE: For users that liked the original mode of "emacs -f notmuch"
+ immediately displaying a particular search result, we recommend
+ instead running something like:
- emacs --eval '(notmuch search "tag:inbox" t)'
+ emacs --eval '(notmuch search "tag:inbox" t)'
- The "t" means to sort the messages in an "oldest first" order,
- (as notmuch would do previously by default). You can also
- leave that off to have your search results in "newest first"
- order.
+ The "t" means to sort the messages in an "oldest first" order,
+ (as notmuch would do previously by default). You can also
+ leave that off to have your search results in "newest first"
+ order.
Full-featured "customize" support for configuring notmuch
@@ -1219,7 +1647,7 @@ Support for doing tab-completion of email addresses
One such program (implemented in python with the python bindings to
notmuch) is available via:
- git clone http://jkr.acm.jhu.edu/git/notmuch_addresses.git
+ git clone http://jkr.acm.jhu.edu/git/notmuch_addresses.git
Install that program as notmuch-addresses on your PATH, and then
hitting TAB on a partial email address or name within the To: or Cc:
@@ -1242,7 +1670,7 @@ New 'G' key binding to trigger mail refresh (G == "Get new mail")
typically invoke "notmuch new" and then perhaps several "notmuch
tag" commands.
-Implement emacs message display with the JSON output from notmuch.
+Implement emacs message display with the JSON output from notmuch
This is much more robust than the previous implementation, (where
some HTML mails and mail quoting the notmuch code with the delimiter
@@ -1304,15 +1732,16 @@ Customizable formatting of search results
the various fields in a "notmuch search" buffer. See the "Notmuch
Search Result Format" section of the customize interface.
-Generate nicer names for search buffers when using a saved search.
+Generate nicer names for search buffers when using a saved search
-Add a notmuch User-Agent header when sending mail from notmuch/emacs.
+Add a notmuch User-Agent header when sending mail from notmuch/emacs
-New keybinding (M-Ret) to open all collapsed messages in a thread.
+New keybinding (M-Ret) to open all collapsed messages in a thread
New library feature
-------------------
-Provide a new NOTMUCH_SORT_UNSORTED value for queries
+
+Provide a new `NOTMUCH_SORT_UNSORTED` value for queries
This can be somewhat faster when sorting simply isn't desired. For
example when collecting a set of messages that will all be
@@ -1322,27 +1751,30 @@ Provide a new NOTMUCH_SORT_UNSORTED value for queries
Build fixes
-----------
+
Fix to compile against GMime 2.6
Previously notmuch insisted on being able to find GMime 2.4, (even
though GMime 2.6 would have worked all along).
-Fix configure script to accept (and ignore) various standard options.
+Fix configure script to accept (and ignore) various standard options
For example, those that the Gentoo build scripts expect configure to
accept are now all accepted.
Test suite
----------
-A large number of new tests for the many new features.
-Better display of output from failed tests.
+A large number of new tests for the many new features
+
+Better display of output from failed tests
Now shows failures with diff rather than forcing the user to gaze at
complete actual and expected output looking for deviation.
Notmuch 0.2 (2010-04-16)
========================
+
This is the second release of the notmuch mail system, with actual
detailed release notes this time!
@@ -1358,7 +1790,8 @@ notmuch in subsequent releases.
General features
----------------
-Better guessing of From: header.
+
+Better guessing of From: header
Notmuch now tries harder to guess which configured address should be
used as the From: line in a "notmuch reply". It will examine the
@@ -1372,7 +1805,7 @@ Make "notmuch count" with no arguments count all messages
Previously, it was hard to construct a search term that was
guaranteed to match all messages.
-Provide a new special-case search term of "*" to match all messages.
+Provide a new special-case search term of "*" to match all messages
This can be used in any command accepting a search term, such as
"notmuch search '*'". Note that you'll want to take care that the
@@ -1382,7 +1815,7 @@ Provide a new special-case search term of "*" to match all messages.
other search terms.
Automatically detect thread connections even when a parent message is
-missing.
+missing
Previously, if two or more message were received with a common
parent, but that parent was not received, then these messages would
@@ -1391,6 +1824,7 @@ missing.
General bug fixes
-----------------
+
Fix potential data loss in "notmuch new" with SIGINT
One code path in "notmuch new" was not properly handling
@@ -1398,7 +1832,7 @@ Fix potential data loss in "notmuch new" with SIGINT
the database (and their tags being lost) if the user pressed
Control-C while "notmuch new" was working.
-Fix segfault when a message includes a MIME part that is empty.
+Fix segfault when a message includes a MIME part that is empty
Fix handling of non-ASCII characters with --format=json
@@ -1410,11 +1844,11 @@ Fix headers to be properly decoded in "notmuch reply"
Previously, the user might see:
- Subject: Re: =?iso-8859-2?q?Rozlu=E8ka?=
+ Subject: Re: =?iso-8859-2?q?Rozlu=E8ka?=
rather than:
- Subject: Re: Rozlučka
+ Subject: Re: Rozlučka
The former text is properly encoded to be RFC-compliant SMTP, will
be sent correctly, and will be properly decoded by the
@@ -1423,7 +1857,8 @@ Fix headers to be properly decoded in "notmuch reply"
Emacs client features
---------------------
-Show the last few lines of citations as well as the first few lines.
+
+Show the last few lines of citations as well as the first few lines
It's often the case that the last sentence of a citation is what is
being replied to directly, so the last few lines are often much more
@@ -1432,20 +1867,20 @@ Show the last few lines of citations as well as the first few lines.
notmuch-show-citation-lines-suffix).
The '+' and '-' commands in the search view can now add and remove
-tags by region.
+tags by region
Selective bulk tagging is now possible by selecting a region of
threads and then using either the '+' or '-' keybindings. Bulk
tagging is still available for all threads matching the current
search with the '*' binding.
-More meaningful buffer names for thread-view buffers.
+More meaningful buffer names for thread-view buffers
Notmuch now uses the Subject of the thread as the buffer
name. Previously it was using the thread ID, which is a meaningless
number to the user.
-Provide for customized colors of threads in search view based on tags.
+Provide for customized colors of threads in search view based on tags
See the documentation of notmuch-search-line-faces, (or us "M-x
customize" and browse to the "notmuch" group within "Applications"
@@ -1453,33 +1888,35 @@ Provide for customized colors of threads in search view based on tags.
Build-system features
---------------------
-Add support to properly build libnotmuch on Darwin systems (OS X).
-Add support to configure for many standard options.
+Add support to properly build libnotmuch on Darwin systems (OS X)
+
+Add support to configure for many standard options
We include actual support for:
- --includedir --mandir --sysconfdir
+ --includedir --mandir --sysconfdir
And accept and silently ignore several more:
- --build --infodir --libexecdir --localstatedir
- --disable-maintainer-mode --disable-dependency-tracking
+ --build --infodir --libexecdir --localstatedir
+ --disable-maintainer-mode --disable-dependency-tracking
Install emacs client in "make install" rather than requiring a
-separate "make install-emacs".
+separate "make install-emacs"
-Automatically compute versions numbers between releases.
+Automatically compute versions numbers between releases
This support uses the git-describe notation, so a version such as
0.1-144-g43cbbfc indicates a version that is 144 commits since the
0.1 release and is available as git commit "43cbbfc".
-Add a new "make test" target to run the test suite and actually verify
-its results.
+Add a new "make test" target to run the test suite and actually
+verify its results
Notmuch 0.1 (2010-04-05)
========================
+
This is the first release of the notmuch mail system.
It includes the libnotmuch library, the notmuch command-line
@@ -1491,3 +1928,13 @@ a performance bug that made notmuch very slow when modifying
tags. This would cause distracting pauses when reading mail while
notmuch would wait for Xapian when removing the "inbox" and "unread"
tags from messages in a thread.
+
+
+<!--
+ Local variables:
+ mode: text
+ tab-width: 8
+ indent-tabs-mode: nil
+ End:
+ vi: sw=8 ts=8 et
+-->
diff --git a/bindings/go/Makefile b/bindings/go/Makefile
index aba2d59..c38f234 100644
--- a/bindings/go/Makefile
+++ b/bindings/go/Makefile
@@ -1,30 +1,40 @@
-# Copyright 2009 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include ${GOROOT}/src/Make.inc
-
-all: install
-
-DIRS=\
- pkg\
- cmds\
-
-
-clean.dirs: $(addsuffix .clean, $(DIRS))
-install.dirs: $(addsuffix .install, $(DIRS))
-nuke.dirs: $(addsuffix .nuke, $(DIRS))
-test.dirs: $(addsuffix .test, $(TEST))
-bench.dirs: $(addsuffix .bench, $(BENCH))
-
-%.clean:
- +cd $* && $(QUOTED_GOBIN)/gomake clean
-
-%.install:
- +cd $* && $(QUOTED_GOBIN)/gomake install
-
-clean: clean.dirs
-
-install: install.dirs
-
-#-include ${GOROOT}/src/Make.deps
+# Makefile for the go bindings of notmuch
+
+export GOPATH ?= $(shell pwd)
+export CGO_CFLAGS ?= -I../../../../lib
+export CGO_LDFLAGS ?= -L../../../../lib
+
+GO ?= go
+GOFMT ?= gofmt
+
+all: notmuch notmuch-addrlookup
+
+.PHONY: notmuch
+notmuch:
+ $(GO) install notmuch
+
+.PHONY: goconfig
+goconfig:
+ if [ ! -d src/github.com/kless/goconfig/config ]; then \
+ $(GO) get github.com/kless/goconfig/config; \
+ fi
+
+.PHONY: notmuch-addrlookup
+notmuch-addrlookup: notmuch goconfig
+ $(GO) install notmuch-addrlookup
+
+.PHONY: format
+format:
+ $(GOFMT) -w=true $(GOFMT_OPTS) src/notmuch
+ $(GOFMT) -w=true $(GOFMT_OPTS) src/notmuch-addrlookup
+
+.PHONY: check-format
+check-format:
+ $(GOFMT) -d=true $(GOFMT_OPTS) src/notmuch
+ $(GOFMT) -d=true $(GOFMT_OPTS) src/notmuch-addrlookup
+
+.PHONY: clean
+clean:
+ $(GO) clean notmuch
+ $(GO) clean notmuch-addrlookup
+ rm -rf pkg bin
diff --git a/bindings/go/cmds/Makefile b/bindings/go/cmds/Makefile
deleted file mode 100644
index afbc6d2..0000000
--- a/bindings/go/cmds/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2009 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include ${GOROOT}/src/Make.inc
-
-TARG=notmuch-addrlookup
-GOFILES=\
- notmuch-addrlookup.go
-
-include ${GOROOT}/src/Make.cmd
diff --git a/bindings/go/pkg/Makefile b/bindings/go/pkg/Makefile
deleted file mode 100644
index de89dbc..0000000
--- a/bindings/go/pkg/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright 2009 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include $(GOROOT)/src/Make.inc
-
-TARG=notmuch
-CGOFILES=notmuch.go
-CGO_LDFLAGS=-lnotmuch
-
-CLEANFILES+=notmuch_test
-
-include $(GOROOT)/src/Make.pkg
-
-%: install %.go
- $(GC) $*.go
- $(LD) -o $@ $*.$O
diff --git a/bindings/go/cmds/notmuch-addrlookup.go b/bindings/go/src/notmuch-addrlookup/addrlookup.go
index 16958e5..59283f8 100644
--- a/bindings/go/cmds/notmuch-addrlookup.go
+++ b/bindings/go/src/notmuch-addrlookup/addrlookup.go
@@ -22,18 +22,18 @@ type frequencies map[string]uint
/* Used to sort the email addresses from most to least used */
func sort_by_freq(m1, m2 *mail_addr_freq) int {
- if (m1.count[0] == m2.count[0] &&
+ if m1.count[0] == m2.count[0] &&
m1.count[1] == m2.count[1] &&
- m1.count[2] == m2.count[2]) {
+ m1.count[2] == m2.count[2] {
return 0
}
- if (m1.count[0] > m2.count[0] ||
+ if m1.count[0] > m2.count[0] ||
m1.count[0] == m2.count[0] &&
- m1.count[1] > m2.count[1] ||
+ m1.count[1] > m2.count[1] ||
m1.count[0] == m2.count[0] &&
- m1.count[1] == m2.count[1] &&
- m1.count[2] > m2.count[2]) {
+ m1.count[1] == m2.count[1] &&
+ m1.count[2] > m2.count[2] {
return -1
}
@@ -46,17 +46,17 @@ func (self *maddresses) Len() int {
return len(*self)
}
-func (self *maddresses) Less(i,j int) bool {
+func (self *maddresses) Less(i, j int) bool {
m1 := (*self)[i]
m2 := (*self)[j]
- v := sort_by_freq(m1, m2)
- if v<=0 {
+ v := sort_by_freq(m1, m2)
+ if v <= 0 {
return true
}
return false
}
-func (self *maddresses) Swap(i,j int) {
+func (self *maddresses) Swap(i, j int) {
(*self)[i], (*self)[j] = (*self)[j], (*self)[i]
}
@@ -66,7 +66,7 @@ func frequent_fullname(freqs frequencies) string {
fullname := ""
freqs_sz := len(freqs)
- for mail,freq := range freqs {
+ for mail, freq := range freqs {
if (freq > maxfreq && mail != "") || freqs_sz == 1 {
// only use the entry if it has a real name
// or if this is the only entry
@@ -86,33 +86,33 @@ func addresses_by_frequency(msgs *notmuch.Messages, name string, pass uint, addr
// "<?(?P<mail>\\b\\w+([-+.]\\w+)*\\@\\w+[-\\.\\w]*\\.([-\\.\\w]+)*\\w\\b)>?)"
pattern = `.*` + strings.ToLower(name) + `.*`
var re *regexp.Regexp = nil
- var err os.Error = nil
- if re,err = regexp.Compile(pattern); err != nil {
+ var err error = nil
+ if re, err = regexp.Compile(pattern); err != nil {
log.Printf("error: %v\n", err)
return &freqs
}
-
+
headers := []string{"from"}
if pass == 1 {
headers = append(headers, "to", "cc", "bcc")
}
- for ;msgs.Valid();msgs.MoveToNext() {
+ for ; msgs.Valid(); msgs.MoveToNext() {
msg := msgs.Get()
//println("==> msg [", msg.GetMessageId(), "]")
- for _,header := range headers {
+ for _, header := range headers {
froms := strings.ToLower(msg.GetHeader(header))
//println(" froms: ["+froms+"]")
- for _,from := range strings.Split(froms, ",", -1) {
+ for _, from := range strings.Split(froms, ",") {
from = strings.Trim(from, " ")
match := re.FindString(from)
//println(" -> match: ["+match+"]")
- occ,ok := freqs[match]
+ occ, ok := freqs[match]
if !ok {
freqs[match] = 0
occ = 0
}
- freqs[match] = occ+1
+ freqs[match] = occ + 1
}
}
}
@@ -125,7 +125,7 @@ func search_address_passes(queries [3]*notmuch.Query, name string) []string {
addr_to_realname := make(map[string]*frequencies)
var pass uint = 0 // 0-based
- for _,query := range queries {
+ for _, query := range queries {
if query == nil {
//println("**warning: idx [",idx,"] contains a nil query")
continue
@@ -133,9 +133,9 @@ func search_address_passes(queries [3]*notmuch.Query, name string) []string {
msgs := query.SearchMessages()
ht := addresses_by_frequency(msgs, name, pass, &addr_to_realname)
for addr, count := range *ht {
- freq,ok := addr_freq[addr]
+ freq, ok := addr_freq[addr]
if !ok {
- freq = &mail_addr_freq{addr:addr, count:[3]uint{0,0,0}}
+ freq = &mail_addr_freq{addr: addr, count: [3]uint{0, 0, 0}}
}
freq.count[pass] = count
addr_freq[addr] = freq
@@ -154,8 +154,8 @@ func search_address_passes(queries [3]*notmuch.Query, name string) []string {
}
sort.Sort(&addrs)
- for _,addr := range addrs {
- freqs,ok := addr_to_realname[addr.addr]
+ for _, addr := range addrs {
+ freqs, ok := addr_to_realname[addr.addr]
if ok {
val = append(val, frequent_fullname(*freqs))
} else {
@@ -179,7 +179,7 @@ type address_matcher struct {
func new_address_matcher() *address_matcher {
var cfg *config.Config
- var err os.Error
+ var err error
// honor NOTMUCH_CONFIG
home := os.Getenv("NOTMUCH_CONFIG")
@@ -187,30 +187,34 @@ func new_address_matcher() *address_matcher {
home = os.Getenv("HOME")
}
- if cfg,err = config.ReadDefault(path.Join(home, ".notmuch-config")); err != nil {
- log.Fatalf("error loading config file:",err)
+ if cfg, err = config.ReadDefault(path.Join(home, ".notmuch-config")); err != nil {
+ log.Fatalf("error loading config file:", err)
}
- db_path,_ := cfg.String("database", "path")
- primary_email,_ := cfg.String("user", "primary_email")
- addrbook_tag,err := cfg.String("user", "addrbook_tag")
+ db_path, _ := cfg.String("database", "path")
+ primary_email, _ := cfg.String("user", "primary_email")
+ addrbook_tag, err := cfg.String("user", "addrbook_tag")
if err != nil {
addrbook_tag = "addressbook"
}
- self := &address_matcher{db:nil,
- user_db_path:db_path,
- user_primary_email:primary_email,
- user_addrbook_tag:addrbook_tag}
+ self := &address_matcher{db: nil,
+ user_db_path: db_path,
+ user_primary_email: primary_email,
+ user_addrbook_tag: addrbook_tag}
return self
}
func (self *address_matcher) run(name string) {
queries := [3]*notmuch.Query{}
-
+
// open the database
- self.db = notmuch.OpenDatabase(self.user_db_path,
- notmuch.DATABASE_MODE_READ_ONLY)
+ if db, status := notmuch.OpenDatabase(self.user_db_path,
+ notmuch.DATABASE_MODE_READ_ONLY); status == notmuch.STATUS_SUCCESS {
+ self.db = db
+ } else {
+ log.Fatalf("Failed to open the database: %v\n", status)
+ }
// pass 1: look at all from: addresses with the address book tag
query := "tag:" + self.user_addrbook_tag
@@ -222,7 +226,7 @@ func (self *address_matcher) run(name string) {
// pass 2: look at all to: addresses sent from our primary mail
query = ""
if name != "" {
- query = "to:"+name+"*"
+ query = "to:" + name + "*"
}
if self.user_primary_email != "" {
query = query + " from:" + self.user_primary_email
@@ -230,17 +234,17 @@ func (self *address_matcher) run(name string) {
queries[1] = self.db.CreateQuery(query)
// if that leads only to a few hits, we check every from too
- if queries[0].CountMessages() + queries[1].CountMessages() < 10 {
+ if queries[0].CountMessages()+queries[1].CountMessages() < 10 {
query = ""
if name != "" {
- query = "from:"+name+"*"
+ query = "from:" + name + "*"
}
queries[2] = self.db.CreateQuery(query)
}
-
+
// actually retrieve and sort addresses
results := search_address_passes(queries, name)
- for _,v := range results {
+ for _, v := range results {
if v != "" && v != "\n" {
fmt.Println(v)
}
@@ -256,4 +260,4 @@ func main() {
name = os.Args[1]
}
app.run(name)
-} \ No newline at end of file
+}
diff --git a/bindings/go/pkg/notmuch.go b/bindings/go/src/notmuch/notmuch.go
index c6844ef..00bd53a 100644
--- a/bindings/go/pkg/notmuch.go
+++ b/bindings/go/src/notmuch/notmuch.go
@@ -3,6 +3,8 @@
package notmuch
/*
+#cgo LDFLAGS: -lnotmuch
+
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -13,24 +15,26 @@ import "unsafe"
// Status codes used for the return values of most functions
type Status C.notmuch_status_t
+
const (
- STATUS_SUCCESS Status = 0
+ STATUS_SUCCESS Status = iota
STATUS_OUT_OF_MEMORY
- STATUS_READ_ONLY_DATABASE
- STATUS_XAPIAN_EXCEPTION
- STATUS_FILE_ERROR
- STATUS_FILE_NOT_EMAIL
- STATUS_DUPLICATE_MESSAGE_ID
- STATUS_NULL_POINTER
- STATUS_TAG_TOO_LONG
- STATUS_UNBALANCED_FREEZE_THAW
-
- STATUS_LAST_STATUS
+ STATUS_READ_ONLY_DATABASE
+ STATUS_XAPIAN_EXCEPTION
+ STATUS_FILE_ERROR
+ STATUS_FILE_NOT_EMAIL
+ STATUS_DUPLICATE_MESSAGE_ID
+ STATUS_NULL_POINTER
+ STATUS_TAG_TOO_LONG
+ STATUS_UNBALANCED_FREEZE_THAW
+ STATUS_UNBALANCED_ATOMIC
+
+ STATUS_LAST_STATUS
)
func (self Status) String() string {
var p *C.char
-
+
// p is read-only
p = C.notmuch_status_to_string(C.notmuch_status_t(self))
if p != nil {
@@ -80,27 +84,28 @@ type Filenames struct {
}
type DatabaseMode C.notmuch_database_mode_t
+
const (
- DATABASE_MODE_READ_ONLY DatabaseMode = 0
- DATABASE_MODE_READ_WRITE
+ DATABASE_MODE_READ_ONLY DatabaseMode = 0
+ DATABASE_MODE_READ_WRITE
)
// Create a new, empty notmuch database located at 'path'
-func NewDatabase(path string) *Database {
+func NewDatabase(path string) (*Database, Status) {
var c_path *C.char = C.CString(path)
defer C.free(unsafe.Pointer(c_path))
if c_path == nil {
- return nil
+ return nil, STATUS_OUT_OF_MEMORY
}
- self := &Database{db:nil}
- self.db = C.notmuch_database_create(c_path)
- if self.db == nil {
- return nil
+ self := &Database{db: nil}
+ st := Status(C.notmuch_database_create(c_path, &self.db))
+ if st != STATUS_SUCCESS {
+ return nil, st
}
- return self
+ return self, st
}
/* Open an existing notmuch database located at 'path'.
@@ -114,41 +119,41 @@ func NewDatabase(path string) *Database {
* An existing notmuch database can be identified by the presence of a
* directory named ".notmuch" below 'path'.
*
- * The caller should call notmuch_database_close when finished with
+ * The caller should call notmuch_database_destroy when finished with
* this database.
*
* In case of any failure, this function returns NULL, (after printing
* an error message on stderr).
*/
-func OpenDatabase(path string, mode DatabaseMode) *Database {
+func OpenDatabase(path string, mode DatabaseMode) (*Database, Status) {
var c_path *C.char = C.CString(path)
defer C.free(unsafe.Pointer(c_path))
if c_path == nil {
- return nil
+ return nil, STATUS_OUT_OF_MEMORY
}
- self := &Database{db:nil}
- self.db = C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode))
- if self.db == nil {
- return nil
+ self := &Database{db: nil}
+ st := Status(C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode), &self.db))
+ if st != STATUS_SUCCESS {
+ return nil, st
}
- return self
+ return self, st
}
/* Close the given notmuch database, freeing all associated
* resources. See notmuch_database_open. */
func (self *Database) Close() {
- C.notmuch_database_close(self.db)
+ C.notmuch_database_destroy(self.db)
}
/* Return the database path of the given database.
*/
func (self *Database) GetPath() string {
-
- /* The return value is a string owned by notmuch so should not be
- * modified nor freed by the caller. */
+
+ /* The return value is a string owned by notmuch so should not be
+ * modified nor freed by the caller. */
var p *C.char = C.notmuch_database_get_path(self.db)
if p != nil {
s := C.GoString(p)
@@ -178,7 +183,6 @@ func (self *Database) NeedsUpgrade() bool {
// TODO: notmuch_database_upgrade
-
/* Retrieve a directory object from the database for 'path'.
*
* Here, 'path' should be a path relative to the path of 'database'
@@ -187,19 +191,20 @@ func (self *Database) NeedsUpgrade() bool {
*
* Can return NULL if a Xapian exception occurs.
*/
-func (self *Database) GetDirectory(path string) *Directory {
+func (self *Database) GetDirectory(path string) (*Directory, Status) {
var c_path *C.char = C.CString(path)
defer C.free(unsafe.Pointer(c_path))
if c_path == nil {
- return nil
+ return nil, STATUS_OUT_OF_MEMORY
}
- c_dir := C.notmuch_database_get_directory(self.db, c_path)
- if c_dir == nil {
- return nil
+ var c_dir *C.notmuch_directory_t
+ st := Status(C.notmuch_database_get_directory(self.db, c_path, &c_dir))
+ if st != STATUS_SUCCESS || c_dir == nil {
+ return nil, st
}
- return &Directory{dir:c_dir}
+ return &Directory{dir: c_dir}, st
}
/* Add a new message to the given notmuch database.
@@ -242,8 +247,7 @@ func (self *Database) GetDirectory(path string) *Directory {
* NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
* mode so no message can be added.
*/
-func
-(self *Database) AddMessage(fname string) (*Message, Status) {
+func (self *Database) AddMessage(fname string) (*Message, Status) {
var c_fname *C.char = C.CString(fname)
defer C.free(unsafe.Pointer(c_fname))
@@ -254,7 +258,7 @@ func
var c_msg *C.notmuch_message_t = new(C.notmuch_message_t)
st := Status(C.notmuch_database_add_message(self.db, c_fname, &c_msg))
- return &Message{message:c_msg}, st
+ return &Message{message: c_msg}, st
}
/* Remove a message from the given notmuch database.
@@ -282,7 +286,7 @@ func
* mode so no message can be removed.
*/
func (self *Database) RemoveMessage(fname string) Status {
-
+
var c_fname *C.char = C.CString(fname)
defer C.free(unsafe.Pointer(c_fname))
@@ -306,20 +310,21 @@ func (self *Database) RemoveMessage(fname string) Status {
* * An out-of-memory situation occurs
* * A Xapian exception occurs
*/
-func (self *Database) FindMessage(message_id string) *Message {
-
+func (self *Database) FindMessage(message_id string) (*Message, Status) {
+
var c_msg_id *C.char = C.CString(message_id)
defer C.free(unsafe.Pointer(c_msg_id))
if c_msg_id == nil {
- return nil
+ return nil, STATUS_OUT_OF_MEMORY
}
- msg := C.notmuch_database_find_message(self.db, c_msg_id)
- if msg == nil {
- return nil
+ msg := &Message{message: nil}
+ st := Status(C.notmuch_database_find_message(self.db, c_msg_id, &msg.message))
+ if st != STATUS_SUCCESS {
+ return nil, st
}
- return &Message{message:msg}
+ return msg, st
}
/* Return a list of all tags found in the database.
@@ -334,7 +339,7 @@ func (self *Database) GetAllTags() *Tags {
if tags == nil {
return nil
}
- return &Tags{tags:tags}
+ return &Tags{tags: tags}
}
/* Create a new query for 'database'.
@@ -362,7 +367,7 @@ func (self *Database) GetAllTags() *Tags {
* Will return NULL if insufficient memory is available.
*/
func (self *Database) CreateQuery(query string) *Query {
-
+
var c_query *C.char = C.CString(query)
defer C.free(unsafe.Pointer(c_query))
@@ -374,11 +379,12 @@ func (self *Database) CreateQuery(query string) *Query {
if q == nil {
return nil
}
- return &Query{query:q}
+ return &Query{query: q}
}
/* Sort values for notmuch_query_set_sort */
type Sort C.notmuch_sort_t
+
const (
SORT_OLDEST_FIRST Sort = 0
SORT_NEWEST_FIRST
@@ -391,7 +397,7 @@ func (self *Query) String() string {
// FIXME: do we own 'q' or not ?
q := C.notmuch_query_get_query_string(self.query)
//defer C.free(unsafe.Pointer(q))
-
+
if q != nil {
s := C.GoString(q)
return s
@@ -453,7 +459,7 @@ func (self *Query) SearchThreads() *Threads {
if threads == nil {
return nil
}
- return &Threads{threads:threads}
+ return &Threads{threads: threads}
}
/* Execute a query for messages, returning a notmuch_messages_t object
@@ -499,7 +505,7 @@ func (self *Query) SearchMessages() *Messages {
if msgs == nil {
return nil
}
- return &Messages{messages:msgs}
+ return &Messages{messages: msgs}
}
/* Destroy a notmuch_query_t along with any associated resources.
@@ -601,7 +607,7 @@ func (self *Messages) Get() *Message {
if msg == nil {
return nil
}
- return &Message{message:msg}
+ return &Message{message: msg}
}
/* Move the 'messages' iterator to the next message.
@@ -653,7 +659,7 @@ func (self *Messages) CollectTags() *Tags {
if tags == nil {
return nil
}
- return &Tags{tags:tags}
+ return &Tags{tags: tags}
}
/* Get the message ID of 'message'.
@@ -693,14 +699,14 @@ func (self *Message) GetMessageId() string {
* message belongs to a single thread.
*/
func (self *Message) GetThreadId() string {
-
+
if self.message == nil {
return ""
}
id := C.notmuch_message_get_thread_id(self.message)
// we dont own id
// defer C.free(unsafe.Pointer(id))
-
+
if id == nil {
return ""
}
@@ -733,7 +739,7 @@ func (self *Message) GetReplies() *Messages {
if msgs == nil {
return nil
}
- return &Messages{messages:msgs}
+ return &Messages{messages: msgs}
}
/* Get a filename for the email corresponding to 'message'.
@@ -757,7 +763,7 @@ func (self *Message) GetFileName() string {
fname := C.notmuch_message_get_filename(self.message)
// we dont own fname
// defer C.free(unsafe.Pointer(fname))
-
+
if fname == nil {
return ""
}
@@ -766,6 +772,7 @@ func (self *Message) GetFileName() string {
}
type Flag C.notmuch_message_flag_t
+
const (
MESSAGE_FLAG_MATCH Flag = 0
)
@@ -812,16 +819,16 @@ func (self *Message) GetHeader(header string) string {
if self.message == nil {
return ""
}
-
+
var c_header *C.char = C.CString(header)
defer C.free(unsafe.Pointer(c_header))
-
+
/* we dont own value */
value := C.notmuch_message_get_header(self.message, c_header)
if value == nil {
return ""
}
-
+
return C.GoString(value)
}
@@ -863,7 +870,7 @@ func (self *Message) GetTags() *Tags {
if tags == nil {
return nil
}
- return &Tags{tags:tags}
+ return &Tags{tags: tags}
}
/* The longest possible tag value. */
@@ -1120,4 +1127,5 @@ func (self *Filenames) Destroy() {
}
C.notmuch_filenames_destroy(self.fnames)
}
+
/* EOF */
diff --git a/bindings/python/docs/source/conf.py b/bindings/python/docs/source/conf.py
index e0ee39c..9db377f 100644
--- a/bindings/python/docs/source/conf.py
+++ b/bindings/python/docs/source/conf.py
@@ -18,6 +18,24 @@ import sys, os
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0,os.path.abspath('../..'))
+class Mock(object):
+ def __init__(self, *args, **kwargs):
+ pass
+
+ def __call__(self, *args, **kwargs):
+ return Mock()
+
+ @classmethod
+ def __getattr__(self, name):
+ return Mock() if name not in ('__file__', '__path__') else '/dev/null'
+
+MOCK_MODULES = [
+ 'ctypes',
+]
+for mod_name in MOCK_MODULES:
+ sys.modules[mod_name] = Mock()
+
+
from notmuch import __VERSION__,__AUTHOR__
# -- General configuration -----------------------------------------------------
@@ -39,8 +57,8 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
-project = u'cnotmuch'
-copyright = u'2010, ' + __AUTHOR__
+project = u'notmuch'
+copyright = u'2010-2012, ' + __AUTHOR__
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
diff --git a/bindings/python/docs/source/database.rst b/bindings/python/docs/source/database.rst
new file mode 100644
index 0000000..2464bff
--- /dev/null
+++ b/bindings/python/docs/source/database.rst
@@ -0,0 +1,50 @@
+:class:`Database` -- The underlying notmuch database
+====================================================
+
+.. currentmodule:: notmuch
+
+.. autoclass:: Database([path=None[, create=False[, mode=MODE.READ_ONLY]]])
+
+ .. automethod:: create
+
+ .. automethod:: open(path, status=MODE.READ_ONLY)
+
+ .. automethod:: close
+
+ .. automethod:: get_path
+
+ .. automethod:: get_version
+
+ .. automethod:: needs_upgrade
+
+ .. automethod:: upgrade
+
+ .. automethod:: begin_atomic
+
+ .. automethod:: end_atomic
+
+ .. automethod:: get_directory
+
+ .. automethod:: add_message
+
+ .. automethod:: remove_message
+
+ .. automethod:: find_message
+
+ .. automethod:: find_message_by_filename
+
+ .. automethod:: get_all_tags
+
+ .. automethod:: create_query
+
+ .. attribute:: Database.MODE
+
+ Defines constants that are used as the mode in which to open a database.
+
+ MODE.READ_ONLY
+ Open the database in read-only mode
+
+ MODE.READ_WRITE
+ Open the database in read-write mode
+
+ .. autoattribute:: db_p
diff --git a/bindings/python/docs/source/filesystem.rst b/bindings/python/docs/source/filesystem.rst
new file mode 100644
index 0000000..4eb7810
--- /dev/null
+++ b/bindings/python/docs/source/filesystem.rst
@@ -0,0 +1,28 @@
+Files and directories
+=====================
+
+.. currentmodule:: notmuch
+
+:class:`Filenames` -- An iterator over filenames
+------------------------------------------------
+
+.. autoclass:: Filenames
+
+ .. automethod:: Filenames.__len__
+
+:class:`Directoy` -- A directory entry in the database
+------------------------------------------------------
+
+.. autoclass:: Directory
+
+ .. automethod:: Directory.get_child_files
+
+ .. automethod:: Directory.get_child_directories
+
+ .. automethod:: Directory.get_mtime
+
+ .. automethod:: Directory.set_mtime
+
+ .. autoattribute:: Directory.mtime
+
+ .. autoattribute:: Directory.path
diff --git a/bindings/python/docs/source/index.rst b/bindings/python/docs/source/index.rst
index f7d3d60..1cece5f 100644
--- a/bindings/python/docs/source/index.rst
+++ b/bindings/python/docs/source/index.rst
@@ -1,284 +1,36 @@
-.. notmuch documentation master file, created by
- sphinx-quickstart on Tue Feb 2 10:00:47 2010.
+Welcome to :mod:`notmuch`'s documentation
+=========================================
.. currentmodule:: notmuch
-Welcome to :mod:`notmuch`'s documentation
-===========================================
-
-The :mod:`notmuch` module provides an interface to the `notmuch <http://notmuchmail.org>`_ functionality, directly interfacing to a shared notmuch library.
-Within :mod:`notmuch`, the classes :class:`Database`, :class:`Query` provide most of the core functionality, returning :class:`Threads`, :class:`Messages` and :class:`Tags`.
+The :mod:`notmuch` module provides an interface to the `notmuch
+<http://notmuchmail.org>`_ functionality, directly interfacing to a
+shared notmuch library. Within :mod:`notmuch`, the classes
+:class:`Database`, :class:`Query` provide most of the core
+functionality, returning :class:`Threads`, :class:`Messages` and
+:class:`Tags`.
.. moduleauthor:: Sebastian Spaeth <Sebastian@SSpaeth.de>
:License: This module is covered under the GNU GPL v3 (or later).
-This page contains the main API overview of notmuch |release|.
-
-Notmuch can be imported as::
-
- import notmuch
-
-or::
-
- from notmuch import Query, Database
-
- db = Database('path',create=True)
- msgs = Query(db,'from:myself').search_messages()
-
- for msg in msgs:
- print (msg)
-
-More information on specific topics can be found on the following pages:
-
.. toctree::
:maxdepth: 1
+ quickstart
+ notes
status_and_errors
- notmuch
-
-:mod:`notmuch` -- The Notmuch interface
-=================================================
-
-.. automodule:: notmuch
-
-:class:`notmuch.Database` -- The underlying notmuch database
----------------------------------------------------------------------
-
-.. autoclass:: notmuch.Database([path=None[, create=False[, mode=MODE.READ_ONLY]]])
-
- .. automethod:: create
-
- .. automethod:: open(path, status=MODE.READ_ONLY)
-
- .. automethod:: get_path
-
- .. automethod:: get_version
-
- .. automethod:: needs_upgrade
-
- .. automethod:: upgrade
-
- .. automethod:: begin_atomic
-
- .. automethod:: end_atomic
-
- .. automethod:: get_directory
-
- .. automethod:: add_message
-
- .. automethod:: remove_message
-
- .. automethod:: find_message
-
- .. automethod:: find_message_by_filename
-
- .. automethod:: get_all_tags
-
- .. automethod:: create_query
-
- .. attribute:: Database.MODE
-
- Defines constants that are used as the mode in which to open a database.
-
- MODE.READ_ONLY
- Open the database in read-only mode
-
- MODE.READ_WRITE
- Open the database in read-write mode
-
- .. autoattribute:: db_p
-
-
-:class:`notmuch.Query` -- A search query
--------------------------------------------------
-
-.. autoclass:: notmuch.Query
-
- .. automethod:: create
-
- .. attribute:: Query.SORT
-
- Defines constants that are used as the mode in which to open a database.
-
- SORT.OLDEST_FIRST
- Sort by message date, oldest first.
-
- SORT.NEWEST_FIRST
- Sort by message date, newest first.
-
- SORT.MESSAGE_ID
- Sort by email message ID.
-
- SORT.UNSORTED
- Do not apply a special sort order (returns results in document id
- order).
-
- .. automethod:: set_sort
-
- .. attribute:: sort
-
- Instance attribute :attr:`sort` contains the sort order (see
- :attr:`Query.SORT`) if explicitely specified via
- :meth:`set_sort`. By default it is set to `None`.
-
- .. automethod:: search_threads
-
- .. automethod:: search_messages
-
- .. automethod:: count_messages
-
-
-:class:`Messages` -- A bunch of messages
-----------------------------------------
-
-.. autoclass:: Messages
-
- .. automethod:: collect_tags
-
- .. method:: __len__()
-
- .. warning::
-
- :meth:`__len__` was removed in version 0.6 as it exhausted the iterator and broke
- list(Messages()). Use the :meth:`Query.count_messages` function or use `len(list(msgs))`.
-
-:class:`Message` -- A single message
-----------------------------------------
-
-.. autoclass:: Message
-
- .. automethod:: get_message_id
-
- .. automethod:: get_thread_id
-
- .. automethod:: get_replies
-
- .. automethod:: get_filename
-
- .. automethod:: get_filenames
-
- .. attribute:: FLAG
-
- FLAG.MATCH
- This flag is automatically set by a
- Query.search_threads on those messages that match the
- query. This allows us to distinguish matches from the rest
- of the messages in that thread.
-
- .. automethod:: get_flag
-
- .. automethod:: set_flag
-
- .. automethod:: get_date
-
- .. automethod:: get_header
-
- .. automethod:: get_tags
-
- .. automethod:: maildir_flags_to_tags
-
- .. automethod:: tags_to_maildir_flags
-
- .. automethod:: remove_tag
-
- .. automethod:: add_tag
-
- .. automethod:: remove_all_tags
-
- .. automethod:: freeze
-
- .. automethod:: thaw
-
- .. automethod:: format_message_as_json
-
- .. automethod:: format_message_as_text
-
- .. automethod:: __str__
-
-
-:class:`Tags` -- Notmuch tags
------------------------------
-
-.. autoclass:: Tags
- :members:
-
- .. method:: __len__
-
- .. warning::
-
- :meth:`__len__` was removed in version 0.6 as it exhausted the iterator and broke
- list(Tags()). Use :meth:`len(list(msgs))` instead if you need to know the number of
- tags.
-
- .. automethod:: __str__
-
-
-:class:`notmuch.Threads` -- Threads iterator
------------------------------------------------------
-
-.. autoclass:: notmuch.Threads
-
- .. automethod:: __len__
-
- .. automethod:: __str__
-
-:class:`Thread` -- A single thread
-------------------------------------
-
-.. autoclass:: Thread
-
- .. automethod:: get_thread_id
-
- .. automethod:: get_total_messages
-
- .. automethod:: get_toplevel_messages
-
- .. automethod:: get_matched_messages
-
- .. automethod:: get_authors
-
- .. automethod:: get_subject
-
- .. automethod:: get_oldest_date
-
- .. automethod:: get_newest_date
-
- .. automethod:: get_tags
-
- .. automethod:: __str__
-
-
-:class:`Filenames` -- An iterator over filenames
-------------------------------------------------
-
-.. autoclass:: notmuch.database.Filenames
-
- .. automethod:: notmuch.database.Filenames.__len__
-
-:class:`notmuch.database.Directoy` -- A directory entry in the database
-------------------------------------------------------------------------
-
-.. autoclass:: notmuch.database.Directory
-
- .. automethod:: notmuch.database.Directory.get_child_files
-
- .. automethod:: notmuch.database.Directory.get_child_directories
-
- .. automethod:: notmuch.database.Directory.get_mtime
-
- .. automethod:: notmuch.database.Directory.set_mtime
-
- .. autoattribute:: notmuch.database.Directory.mtime
-
- .. autoattribute:: notmuch.database.Directory.path
-
-
-The `next page <status_and_errors.html>`_ contains information on possible Status and Error values.
+ database
+ query
+ messages
+ message
+ tags
+ threads
+ thread
+ filesystem
Indices and tables
==================
* :ref:`genindex`
* :ref:`search`
-
diff --git a/bindings/python/docs/source/message.rst b/bindings/python/docs/source/message.rst
new file mode 100644
index 0000000..1a6cc3d
--- /dev/null
+++ b/bindings/python/docs/source/message.rst
@@ -0,0 +1,50 @@
+:class:`Message` -- A single message
+====================================
+
+.. currentmodule:: notmuch
+
+.. autoclass:: Message
+
+ .. automethod:: get_message_id
+
+ .. automethod:: get_thread_id
+
+ .. automethod:: get_replies
+
+ .. automethod:: get_filename
+
+ .. automethod:: get_filenames
+
+ .. attribute:: FLAG
+
+ FLAG.MATCH
+ This flag is automatically set by a
+ Query.search_threads on those messages that match the
+ query. This allows us to distinguish matches from the rest
+ of the messages in that thread.
+
+ .. automethod:: get_flag
+
+ .. automethod:: set_flag
+
+ .. automethod:: get_date
+
+ .. automethod:: get_header
+
+ .. automethod:: get_tags
+
+ .. automethod:: maildir_flags_to_tags
+
+ .. automethod:: tags_to_maildir_flags
+
+ .. automethod:: remove_tag
+
+ .. automethod:: add_tag
+
+ .. automethod:: remove_all_tags
+
+ .. automethod:: freeze
+
+ .. automethod:: thaw
+
+ .. automethod:: __str__
diff --git a/bindings/python/docs/source/messages.rst b/bindings/python/docs/source/messages.rst
new file mode 100644
index 0000000..3ccf505
--- /dev/null
+++ b/bindings/python/docs/source/messages.rst
@@ -0,0 +1,15 @@
+:class:`Messages` -- A bunch of messages
+========================================
+
+.. currentmodule:: notmuch
+
+.. autoclass:: Messages
+
+ .. automethod:: collect_tags
+
+ .. method:: __len__()
+
+ .. warning::
+
+ :meth:`__len__` was removed in version 0.6 as it exhausted the iterator and broke
+ list(Messages()). Use the :meth:`Query.count_messages` function or use `len(list(msgs))`.
diff --git a/bindings/python/docs/source/notes.rst b/bindings/python/docs/source/notes.rst
new file mode 100644
index 0000000..a792748
--- /dev/null
+++ b/bindings/python/docs/source/notes.rst
@@ -0,0 +1,6 @@
+Interfacing with notmuch
+========================
+
+.. todo:: move the note about talloc out of the code
+
+.. automodule:: notmuch
diff --git a/bindings/python/docs/source/notmuch.rst b/bindings/python/docs/source/notmuch.rst
deleted file mode 100644
index 32e1783..0000000
--- a/bindings/python/docs/source/notmuch.rst
+++ /dev/null
@@ -1,68 +0,0 @@
-The notmuch 'binary'
-====================
-
-The cnotmuch module provides *notmuch*, a python reimplementation of the standard notmuch binary for two purposes: first, to allow running the standard notmuch testsuite over the cnotmuch bindings (for correctness and performance testing) and second, to give some examples as to how to use cnotmuch. 'Notmuch' provides a command line interface to your mail database.
-
-A standard install via `easy_install cnotmuch` will not install the notmuch binary, however it is available in the `cnotmuch source code repository <http://bitbucket.org/spaetz/cnotmuch/src/>`_.
-
-
-It is invoked with the following pattern: `notmuch <command> [args...]`.
-
-Where <command> and [args...] are as follows:
-
- **setup** Interactively setup notmuch for first use.
- This has not yet been implemented, and will probably not be
- implemented unless someone puts in the effort.
-
- **new** [--verbose]
- Find and import new messages to the notmuch database.
-
- This has not been implemented yet. We cheat by calling
- the regular "notmuch" binary (which must be in your path
- somewhere).
-
- **search** [options...] <search-terms> [...] Search for messages matching the given search terms.
-
- This has been implemented but for the `--format` and
- `--sort` options.
-
- **show** <search-terms> [...]
- Show all messages matching the search terms.
-
- This has been partially implemented, we show a stub for each
- found message, but do not output the full message body yet.
-
- **count** <search-terms> [...]
- Count messages matching the search terms.
-
- This has been fully implemented.
-
- **reply** [options...] <search-terms> [...]
- Construct a reply template for a set of messages.
-
- This has not been implemented yet.
-
- **tag** +<tag>|-<tag> [...] [--] <search-terms> [...]
- Add/remove tags for all messages matching the search terms.
-
- This has been fully implemented.
-
- **dump** [<filename>]
- Create a plain-text dump of the tags for each message.
-
- This has been fully implemented.
- **restore** <filename>
- Restore the tags from the given dump file (see 'dump').
-
- This has been fully implemented.
-
- **search-tags** [<search-terms> [...] ]
- List all tags found in the database or matching messages.
-
- This has been fully implemented.
-
- **help** [<command>]
- This message, or more detailed help for the named command.
-
- The 'help' page has been implemented, help for single
- commands are missing though. Patches are welcome.
diff --git a/bindings/python/docs/source/query.rst b/bindings/python/docs/source/query.rst
new file mode 100644
index 0000000..ddfc348
--- /dev/null
+++ b/bindings/python/docs/source/query.rst
@@ -0,0 +1,41 @@
+:class:`Query` -- A search query
+================================
+
+.. currentmodule:: notmuch
+
+.. autoclass:: Query
+
+ .. automethod:: create
+
+ .. attribute:: Query.SORT
+
+ Defines constants that are used as the mode in which to open a database.
+
+ SORT.OLDEST_FIRST
+ Sort by message date, oldest first.
+
+ SORT.NEWEST_FIRST
+ Sort by message date, newest first.
+
+ SORT.MESSAGE_ID
+ Sort by email message ID.
+
+ SORT.UNSORTED
+ Do not apply a special sort order (returns results in document id
+ order).
+
+ .. automethod:: set_sort
+
+ .. attribute:: sort
+
+ Instance attribute :attr:`sort` contains the sort order (see
+ :attr:`Query.SORT`) if explicitely specified via
+ :meth:`set_sort`. By default it is set to `None`.
+
+ .. automethod:: search_threads
+
+ .. automethod:: search_messages
+
+ .. automethod:: count_messages
+
+ .. automethod:: count_threads
diff --git a/bindings/python/docs/source/quickstart.rst b/bindings/python/docs/source/quickstart.rst
new file mode 100644
index 0000000..609f42e
--- /dev/null
+++ b/bindings/python/docs/source/quickstart.rst
@@ -0,0 +1,19 @@
+Quickstart and examples
+=======================
+
+.. todo:: write a nice introduction
+.. todo:: improve the examples
+
+Notmuch can be imported as::
+
+ import notmuch
+
+or::
+
+ from notmuch import Query, Database
+
+ db = Database('path', create=True)
+ msgs = Query(db, 'from:myself').search_messages()
+
+ for msg in msgs:
+ print(msg)
diff --git a/bindings/python/docs/source/status_and_errors.rst b/bindings/python/docs/source/status_and_errors.rst
index bc0d0d2..dd6e31f 100644
--- a/bindings/python/docs/source/status_and_errors.rst
+++ b/bindings/python/docs/source/status_and_errors.rst
@@ -5,6 +5,12 @@ Status and Errors
Some methods return a status, indicating if an operation was successful and what the error was. Most of these status codes are expressed as a specific value, the :class:`notmuch.STATUS`.
+.. note::
+
+ Prior to version 0.12 the exception classes and the enumeration
+ :class:`notmuch.STATUS` were defined in `notmuch.globals`. They
+ have since then been moved into `notmuch.errors`.
+
:class:`STATUS` -- Notmuch operation return value
--------------------------------------------------
diff --git a/bindings/python/docs/source/tags.rst b/bindings/python/docs/source/tags.rst
new file mode 100644
index 0000000..31527d4
--- /dev/null
+++ b/bindings/python/docs/source/tags.rst
@@ -0,0 +1,17 @@
+:class:`Tags` -- Notmuch tags
+-----------------------------
+
+.. currentmodule:: notmuch
+
+.. autoclass:: Tags
+ :members:
+
+ .. method:: __len__
+
+ .. warning::
+
+ :meth:`__len__` was removed in version 0.6 as it exhausted the iterator and broke
+ list(Tags()). Use :meth:`len(list(msgs))` instead if you need to know the number of
+ tags.
+
+ .. automethod:: __str__
diff --git a/bindings/python/docs/source/thread.rst b/bindings/python/docs/source/thread.rst
new file mode 100644
index 0000000..4067872
--- /dev/null
+++ b/bindings/python/docs/source/thread.rst
@@ -0,0 +1,26 @@
+:class:`Thread` -- A single thread
+==================================
+
+.. currentmodule:: notmuch
+
+.. autoclass:: Thread
+
+ .. automethod:: get_thread_id
+
+ .. automethod:: get_total_messages
+
+ .. automethod:: get_toplevel_messages
+
+ .. automethod:: get_matched_messages
+
+ .. automethod:: get_authors
+
+ .. automethod:: get_subject
+
+ .. automethod:: get_oldest_date
+
+ .. automethod:: get_newest_date
+
+ .. automethod:: get_tags
+
+ .. automethod:: __str__
diff --git a/bindings/python/docs/source/threads.rst b/bindings/python/docs/source/threads.rst
new file mode 100644
index 0000000..e5a8c8a
--- /dev/null
+++ b/bindings/python/docs/source/threads.rst
@@ -0,0 +1,10 @@
+:class:`Threads` -- Threads iterator
+====================================
+
+.. currentmodule:: notmuch
+
+.. autoclass:: Threads
+
+ .. automethod:: __len__
+
+ .. automethod:: __str__
diff --git a/bindings/python/notmuch.py b/bindings/python/notmuch.py
deleted file mode 100755
index 3ff53ec..0000000
--- a/bindings/python/notmuch.py
+++ /dev/null
@@ -1,651 +0,0 @@
-#!/usr/bin/env python
-"""This is a notmuch implementation in python.
-It's goal is to allow running the test suite on the cnotmuch python bindings.
-
-This "binary" honors the NOTMUCH_CONFIG environmen variable for reading a user's
-notmuch configuration (e.g. the database path).
-
- (c) 2010 by Sebastian Spaeth <Sebastian@SSpaeth.de>
- Jesse Rosenthal <jrosenthal@jhu.edu>
- This code is licensed under the GNU GPL v3+.
-"""
-import sys
-import os
-
-import re
-import stat
-import email
-
-from notmuch import Database, Query, NotmuchError, STATUS
-try:
- # python3.x
- from configparser import SafeConfigParser
-except ImportError:
- # python2.x
- from ConfigParser import SafeConfigParser
-from cStringIO import StringIO
-
-PREFIX = re.compile('(\w+):(.*$)')
-
-HELPTEXT = """The notmuch mail system.
-Usage: notmuch <command> [args...]
-
-Where <command> and [args...] are as follows:
- setup Interactively setup notmuch for first use.
- new [--verbose]
- Find and import new messages to the notmuch database.
- search [options...] <search-terms> [...]
- Search for messages matching the given search terms.
- show <search-terms> [...]
- Show all messages matching the search terms.
- count <search-terms> [...]
- Count messages matching the search terms.
- reply [options...] <search-terms> [...]
- Construct a reply template for a set of messages.
- tag +<tag>|-<tag> [...] [--] <search-terms> [...]
- Add/remove tags for all messages matching the search terms.
- dump [<filename>]
- Create a plain-text dump of the tags for each message.
- restore <filename>
- Restore the tags from the given dump file (see 'dump').
- search-tags [<search-terms> [...] ]
- List all tags found in the database or matching messages.
- help [<command>]
- This message, or more detailed help for the named command.
-
-Use "notmuch help <command>" for more details on each command.
-And "notmuch help search-terms" for the common search-terms syntax.
-"""
-
-USAGE = """Notmuch is configured and appears to have a database. Excellent!
-
-At this point you can start exploring the functionality of notmuch by
-using commands such as:
- notmuch search tag:inbox
- notmuch search to:"%(fullname)s"
- notmuch search from:"%(mailaddress)s"
- notmuch search subject:"my favorite things"
-
-See "notmuch help search" for more details.
-
-You can also use "notmuch show" with any of the thread IDs resulting
-from a search. Finally, you may want to explore using a more sophisticated
-interface to notmuch such as the emacs interface implemented in notmuch.el
-or any other interface described at http://notmuchmail.org
-
-And don't forget to run "notmuch new" whenever new mail arrives.
-
-Have fun, and may your inbox never have much mail.
-"""
-
-#-------------------------------------------------------------------------
-def quote_query_line(argv):
- # mangle arguments wrapping terms with spaces in quotes
- for (num, item) in enumerate(argv):
- if item.find(' ') >= 0:
- # if we use prefix:termWithSpaces, put quotes around term
- match = PREFIX.match(item)
- if match:
- argv[num] = '%s:"%s"' %(match.group(1), match.group(2))
- else:
- argv[num] = '"%s"' % item
- return ' '.join(argv)
-
-#-------------------------------------------------------------------------
-
-
-class Notmuch(object):
-
- def __init__(self, configpath="~/.notmuch-config)"):
- self._config = None
- self._configpath = os.getenv('NOTMUCH_CONFIG',
- os.path.expanduser(configpath))
-
- def cmd_usage(self):
- """Print the usage text and exits"""
- data={}
- names = self.get_user_email_addresses()
- data['fullname'] = names[0] if names[0] else 'My Name'
- data['mailaddress'] = names[1] if names[1] else 'My@email.address'
- print USAGE % data
-
- def cmd_new(self):
- """Run 'notmuch new'"""
- #get the database directory
- db = Database(mode=Database.MODE.READ_WRITE)
- path = db.get_path()
- print self._add_new_files_recursively(path, db)
-
- def cmd_help(self, subcmd=None):
- """Print help text for 'notmuch help'"""
- if len(subcmd) > 1:
- print "Help for specific commands not implemented"
- return
- print HELPTEXT
-
- def _get_user_notmuch_config(self):
- """Returns the ConfigParser of the user's notmuch-config"""
- # return the cached config parser if we read it already
- if self._config:
- return self._config
-
- config = SafeConfigParser()
- config.read(self._configpath)
- self._config = config
- return config
-
- def _add_new_files_recursively(self, path, db):
- """:returns: (added, moved, removed)"""
- print "Enter add new files with path %s" % path
-
- try:
- #get the Directory() object for this path
- db_dir = db.get_directory(path)
- added = moved = removed = 0
- except NotmuchError:
- # Occurs if we have wrong absolute paths in the db, for example
- return (0,0,0)
-
-
- # for folder in subdirs:
-
- # TODO, retrieve dir mtime here and store it later
- # as long as Filenames() does not allow multiple iteration, we need to
- # use this kludgy way to get a sorted list of filenames
- # db_files is a list of subdirectories and filenames in this folder
- db_files = set()
- db_folders = set()
- for subdir in db_dir.get_child_directories():
- db_folders.add(subdir)
-# file is a keyword (remove this ;))
- for mail in db_dir.get_child_files():
- db_files.add(mail)
-
- fs_files = set(os.listdir(db_dir.path))
-
- # list of files (and folders) on the fs, but not the db
- for fs_file in ((fs_files - db_files) - db_folders):
- absfile = os.path.normpath(os.path.join(db_dir.path, fs_file))
- statinfo = os.stat(absfile)
-
- if stat.S_ISDIR(statinfo.st_mode):
- # This is a directory
- if fs_file in ['.notmuch','tmp','.']:
- continue
- print "%s %s" % (fs_file, db_folders)
- print "Directory not in db yet. Descending into %s" % absfile
- new = self._add_new_files_recursively(absfile, db)
- added += new[0]
- moved += new[1]
- removed += new[2]
-
- elif stat.S_ISLNK(statinfo.st_mode):
- print ("%s is a symbolic link (%d). FIXME!!!" %
- (absfile, statinfo.st_mode))
- exit(1)
-
- else:
- # This is a regular file, not in the db yet. Add it.
- print "This file needs to be added %s" % (absfile)
- (msg, status) = db.add_message(absfile)
- # We increases 'added', even on dupe messages. If it is a moved
- # message, we will deduct it later and increase 'moved' instead
- added += 1
-
- if status == STATUS.DUPLICATE_MESSAGE_ID:
- print "Added msg was in the db"
- else:
- print "New message."
-
- # Finally a list of files (not folders) in the database,
- # but not the filesystem
- for db_file in (db_files - fs_files):
- absfile = os.path.normpath(os.path.join(db_dir.path, db_file))
-
- # remove a mail message from the db
- print ("%s is not on the fs anymore. Delete" % absfile)
- status = db.remove_message(absfile)
-
- if status == STATUS.SUCCESS:
- # we just deleted the last reference, so this was a remove
- removed += 1
- sys.stderr.write("SUCCESS %d %s %s.\n" %
- (status, STATUS.status2str(status), absfile))
- elif status == STATUS.DUPLICATE_MESSAGE_ID:
- # The filename exists already somewhere else, so this is a move
- moved += 1
- added -= 1
- sys.stderr.write("DUPE %d %s %s.\n" %
- (status, STATUS.status2str(status), absfile))
- else:
- # This should not occur
- sys.stderr.write("This should not occur %d %s %s.\n" %
- (status, STATUS.status2str(status), absfile))
-
- # list of folders in the filesystem. Just descend into dirs
- for fs_file in fs_files:
- absfile = os.path.normpath(os.path.join(db_dir.path, fs_file))
- if os.path.isdir(absfile):
- # This is a directory. Remove it from the db_folder list.
- # All remaining db_folders at the end will be not present
- # on the file system.
- db_folders.remove(fs_file)
- if fs_file in ['.notmuch','tmp','.']:
- continue
- new = self._add_new_files_recursively(absfile, db)
- added += new[0]
- moved += new[0]
- removed += new[0]
-
- # we are not interested in anything but directories here
- #TODO: All remaining elements of db_folders are not in the filesystem
- #delete those
-
- return added, moved, removed
- #Read the mtime of a directory from the filesystem
- #
- #* Call :meth:`Database.add_message` for all mail files in
- # the directory
-
- #* Call notmuch_directory_set_mtime with the mtime read from the
- # filesystem. Then, when wanting to check for updates to the
- # directory in the future, the client can call :meth:`get_mtime`
- # and know that it only needs to add files if the mtime of the
- # directory and files are newer than the stored timestamp.
-
- def get_user_email_addresses(self):
- """ Reads a user's notmuch config and returns his email addresses as
- list (name, primary_address, other_address1,...)"""
-
- #read the config file
- config = self._get_user_notmuch_config()
-
- conf = {'name': '', 'primary_email': ''}
- for entry in conf:
- if config.has_option('user', entry):
- conf[entry] = config.get('user', entry)
-
- if config.has_option('user','other_email'):
- other = config.get('user','other_email')
- other = [mail.strip() for mail in other.split(';') if mail]
- else:
- other = []
- # for being compatible. It would be nicer to return a dict.
- return conf.keys() + other
-
- def quote_msg_body(self, oldbody ,date, from_address):
- """Transform a mail body into a quoted text,
- starting with On foo, bar wrote:
-
- :param body: a str with a mail body
- :returns: The new payload of the email.message()
- """
-
- # we get handed a string, wrap it in a file-like object
- oldbody = StringIO(oldbody)
- newbody = StringIO()
-
- newbody.write("On %s, %s wrote:\n" % (date, from_address))
-
- for line in oldbody:
- newbody.write("> " + line)
-
- return newbody.getvalue()
-
- def format_reply(self, msgs):
- """Gets handed Messages() and displays the reply to them
-
- This is pretty ugly and hacky. It tries to mimic the "real"
- notmuch output as much as it can to pass the test suite. It
- could deserve a healthy bit of love. It is also buggy because
- it returns after the first message it has handled."""
-
- for msg in msgs:
- f = open(msg.get_filename(), "r")
- reply = email.message_from_file(f)
-
- # handle the easy non-multipart case:
- if not reply.is_multipart():
- reply.set_payload(self.quote_msg_body(reply.get_payload(),
- reply['date'], reply['from']))
- else:
- # handle the tricky multipart case
- deleted = ""
- """A string describing which nontext attachements
- that have been deleted"""
- delpayloads = []
- """A list of payload indices to be deleted"""
- payloads = reply.get_payload()
-
- for (num, part) in enumerate(payloads):
- mime_main = part.get_content_maintype()
- if mime_main not in ['multipart', 'message', 'text']:
- deleted += "Non-text part: %s\n" % (part.get_content_type())
- payloads[num].set_payload("Non-text part: %s" %
- (part.get_content_type()))
- payloads[num].set_type('text/plain')
- delpayloads.append(num)
- elif mime_main == 'text':
- payloads[num].set_payload(self.quote_msg_body(
- payloads[num].get_payload(),
- reply['date'], reply['from']))
- else:
- # TODO handle deeply nested multipart messages
- sys.stderr.write ("FIXME: Ignoring multipart part. Handle me\n")
- # Delete those payloads that we don't need anymore
- for item in reversed(sorted(delpayloads)):
- del payloads[item]
-
- # Back to single- and multipart handling
- my_addresses = self.get_user_email_addresses()
- used_address = None
- # filter our email addresses from all to: cc: and bcc: fields
- # if we find one of "my" addresses being used,
- # it is stored in used_address
- for header in ['To', 'CC', 'Bcc']:
- if not header in reply:
- #only handle fields that exist
- continue
- addresses = email.utils.getaddresses(reply.get_all(header, []))
- purged_addr = []
- for (name, mail) in addresses:
- if mail in my_addresses[1:]:
- used_address = email.utils.formataddr(
- (my_addresses[0], mail))
- else:
- purged_addr.append(email.utils.formataddr((name, mail)))
-
- if purged_addr:
- reply.replace_header(header, ", ".join(purged_addr))
- else:
- # we deleted all addresses, delete the header
- del reply[header]
-
- # Use our primary email address to the From
- # (save original from line, we still need it)
- new_to = reply['From']
- if used_address:
- reply['From'] = used_address
- else:
- email.utils.formataddr((my_addresses[0], my_addresses[1]))
-
- reply['Subject'] = 'Re: ' + reply['Subject']
-
- # Calculate our new To: field
- # add all remaining original 'To' addresses
- if 'To' in reply:
- new_to += ", " + reply['To']
- reply.add_header('To', new_to)
-
- # Add our primary email address to the BCC
- new_bcc = my_addresses[1]
- if 'Bcc' in reply:
- new_bcc += ', ' + reply['Bcc']
- reply['Bcc'] = new_bcc
-
- # Set replies 'In-Reply-To' header to original's Message-ID
- if 'Message-ID' in reply:
- reply['In-Reply-To'] = reply['Message-ID']
-
- #Add original's Message-ID to replies 'References' header.
- if 'References' in reply:
- reply['References'] = ' '.join([reply['References'], reply['Message-ID']])
- else:
- reply['References'] = reply['Message-ID']
-
- # Delete the original Message-ID.
- del(reply['Message-ID'])
-
- # filter all existing headers but a few and delete them from 'reply'
- delheaders = filter(lambda x: x not in ['From', 'To', 'Subject', 'CC',
- 'Bcc', 'In-Reply-To',
- 'References', 'Content-Type'],
- reply.keys())
- map(reply.__delitem__, delheaders)
-
- # TODO: OUCH, we return after the first msg we have handled rather than
- # handle all of them
- # return resulting message without Unixfrom
- return reply.as_string(False)
-
-
-def main():
- # Handle command line options
- #------------------------------------
- # No option given, print USAGE and exit
- if len(sys.argv) == 1:
- Notmuch().cmd_usage()
- #------------------------------------
- elif sys.argv[1] == 'setup':
- """Interactively setup notmuch for first use."""
- exit("Not implemented.")
- #-------------------------------------
- elif sys.argv[1] == 'new':
- """Check for new and removed messages."""
- Notmuch().cmd_new()
- #-------------------------------------
- elif sys.argv[1] == 'help':
- """Print the help text"""
- Notmuch().cmd_help(sys.argv[1:])
- #-------------------------------------
- elif sys.argv[1] == 'part':
- part()
- #-------------------------------------
- elif sys.argv[1] == 'search':
- search()
- #-------------------------------------
- elif sys.argv[1] == 'show':
- show()
- #-------------------------------------
- elif sys.argv[1] == 'reply':
- db = Database()
- if len(sys.argv) == 2:
- # no search term. abort
- exit("Error: notmuch reply requires at least one search term.")
- # mangle arguments wrapping terms with spaces in quotes
- querystr = quote_query_line(sys.argv[2:])
- msgs = Query(db, querystr).search_messages()
- print Notmuch().format_reply(msgs)
- #-------------------------------------
- elif sys.argv[1] == 'count':
- if len(sys.argv) == 2:
- # no further search term, count all
- querystr = ''
- else:
- # mangle arguments wrapping terms with spaces in quotes
- querystr = quote_query_line(sys.argv[2:])
- print Database().create_query(querystr).count_messages()
- #-------------------------------------
- elif sys.argv[1] == 'tag':
- # build lists of tags to be added and removed
- add = []
- remove = []
- while not sys.argv[2] == '--' and \
- (sys.argv[2].startswith('+') or sys.argv[2].startswith('-')):
- if sys.argv[2].startswith('+'):
- # append to add list without initial +
- add.append(sys.argv.pop(2)[1:])
- else:
- # append to remove list without initial -
- remove.append(sys.argv.pop(2)[1:])
- # skip eventual '--'
- if sys.argv[2] == '--': sys.argv.pop(2)
- # the rest is search terms
- querystr = quote_query_line(sys.argv[2:])
- db = Database(mode=Database.MODE.READ_WRITE)
- msgs = Query(db, querystr).search_messages()
- for msg in msgs:
- # actually add and remove all tags
- map(msg.add_tag, add)
- map(msg.remove_tag, remove)
- #-------------------------------------
- elif sys.argv[1] == 'search-tags':
- if len(sys.argv) == 2:
- # no further search term
- print "\n".join(Database().get_all_tags())
- else:
- # mangle arguments wrapping terms with spaces in quotes
- querystr = quote_query_line(sys.argv[2:])
- db = Database()
- msgs = Query(db, querystr).search_messages()
- print "\n".join([t for t in msgs.collect_tags()])
- #-------------------------------------
- elif sys.argv[1] == 'dump':
- if len(sys.argv) == 2:
- f = sys.stdout
- else:
- f = open(sys.argv[2], "w")
- db = Database()
- query = Query(db, '')
- query.set_sort(Query.SORT.MESSAGE_ID)
- msgs = query.search_messages()
- for msg in msgs:
- f.write("%s (%s)\n" % (msg.get_message_id(), msg.get_tags()))
- #-------------------------------------
- elif sys.argv[1] == 'restore':
- if len(sys.argv) == 2:
- print("No filename given. Reading dump from stdin.")
- f = sys.stdin
- else:
- f = open(sys.argv[2], "r")
-
- # split the msg id and the tags
- MSGID_TAGS = re.compile("(\S+)\s\((.*)\)$")
- db = Database(mode=Database.MODE.READ_WRITE)
-
- #read each line of the dump file
- for line in f:
- msgs = MSGID_TAGS.match(line)
- if not msgs:
- sys.stderr.write("Warning: Ignoring invalid input line: %s" %
- line)
- continue
- # split line in components and fetch message
- msg_id = msgs.group(1)
- new_tags = set(msgs.group(2).split())
- msg = db.find_message(msg_id)
-
- if msg == None:
- sys.stderr.write(
- "Warning: Cannot apply tags to missing message: %s\n" % msg_id)
- continue
-
- # do nothing if the old set of tags is the same as the new one
- old_tags = set(msg.get_tags())
- if old_tags == new_tags: continue
-
- # set the new tags
- msg.freeze()
- # only remove tags if the new ones are not a superset anyway
- if not (new_tags > old_tags): msg.remove_all_tags()
- for tag in new_tags: msg.add_tag(tag)
- msg.thaw()
- #-------------------------------------
- else:
- # unknown command
- exit("Error: Unknown command '%s' (see \"notmuch help\")" % sys.argv[1])
-
-def part():
- db = Database()
- query_string = ''
- part_num = 0
- first_search_term = 0
- for (num, arg) in enumerate(sys.argv[1:]):
- if arg.startswith('--part='):
- part_num_str = arg.split("=")[1]
- try:
- part_num = int(part_num_str)
- except ValueError:
- # just emulating behavior
- exit(1)
- elif not arg.startswith('--'):
- # save the position of the first sys.argv
- # that is a search term
- first_search_term = num + 1
- if first_search_term:
- # mangle arguments wrapping terms with spaces in quotes
- querystr = quote_query_line(sys.argv[first_search_term:])
- qry = Query(db,querystr)
- msgs = [msg for msg in qry.search_messages()]
-
- if not msgs:
- sys.exit(1)
- elif len(msgs) > 1:
- raise Exception("search term did not match precisely one message")
- else:
- msg = msgs[0]
- print msg.get_part(part_num)
-
-def search():
- db = Database()
- query_string = ''
- sort_order = "newest-first"
- first_search_term = 0
- for (num, arg) in enumerate(sys.argv[1:]):
- if arg.startswith('--sort='):
- sort_order=arg.split("=")[1]
- if not sort_order in ("oldest-first", "newest-first"):
- raise Exception("unknown sort order")
- elif not arg.startswith('--'):
- # save the position of the first sys.argv that is a search term
- first_search_term = num + 1
-
- if first_search_term:
- # mangle arguments wrapping terms with spaces in quotes
- querystr = quote_query_line(sys.argv[first_search_term:])
-
- qry = Query(db, querystr)
- if sort_order == "oldest-first":
- qry.set_sort(Query.SORT.OLDEST_FIRST)
- else:
- qry.set_sort(Query.SORT.NEWEST_FIRST)
- threads = qry.search_threads()
-
- for thread in threads:
- print thread
-
-def show():
- entire_thread = False
- db = Database()
- out_format = "text"
- querystr = ''
- first_search_term = None
-
- # ugly homegrown option parsing
- # TODO: use OptionParser
- for (num, arg) in enumerate(sys.argv[1:]):
- if arg == '--entire-thread':
- entire_thread = True
- elif arg.startswith("--format="):
- out_format = arg.split("=")[1]
- if out_format == 'json':
- # for compatibility use --entire-thread for json
- entire_thread = True
- if not out_format in ("json", "text"):
- raise Exception("unknown format")
- elif not arg.startswith('--'):
- # save the position of the first sys.argv that is a search term
- first_search_term = num + 1
-
- if first_search_term:
- # mangle arguments wrapping terms with spaces in quotes
- querystr = quote_query_line(sys.argv[first_search_term:])
-
- threads = Query(db, querystr).search_threads()
- first_toplevel = True
- if out_format == "json":
- sys.stdout.write("[")
- for thread in threads:
- msgs = thread.get_toplevel_messages()
- if not first_toplevel:
- if out_format == "json":
- sys.stdout.write(", ")
- first_toplevel = False
- msgs.print_messages(out_format, 0, entire_thread)
-
- if out_format == "json":
- sys.stdout.write("]")
- sys.stdout.write("\n")
-
-if __name__ == '__main__':
- main()
diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py
index f3ff987..5561624 100644
--- a/bindings/python/notmuch/__init__.py
+++ b/bindings/python/notmuch/__init__.py
@@ -51,12 +51,17 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>.
Copyright 2010-2011 Sebastian Spaeth <Sebastian@SSpaeth.de>
"""
-from notmuch.database import Database, Query
-from notmuch.message import Messages, Message
-from notmuch.thread import Threads, Thread
-from notmuch.tag import Tags
-from notmuch.globals import (
- nmlib,
+from .database import Database
+from .directory import Directory
+from .filenames import Filenames
+from .message import Message
+from .messages import Messages
+from .query import Query
+from .tag import Tags
+from .thread import Thread
+from .threads import Threads
+from .globals import nmlib
+from .errors import (
STATUS,
NotmuchError,
OutOfMemoryError,
@@ -71,6 +76,6 @@ from notmuch.globals import (
UnbalancedAtomicError,
NotInitializedError,
)
-from notmuch.version import __VERSION__
+from .version import __VERSION__
__LICENSE__ = "GPL v3+"
__AUTHOR__ = 'Sebastian Spaeth <Sebastian@SSpaeth.de>'
diff --git a/bindings/python/notmuch/compat.py b/bindings/python/notmuch/compat.py
new file mode 100644
index 0000000..adc8d24
--- /dev/null
+++ b/bindings/python/notmuch/compat.py
@@ -0,0 +1,67 @@
+'''
+This file is part of notmuch.
+
+This module handles differences between python2.x and python3.x and
+allows the notmuch bindings to support both version families with one
+source tree.
+
+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 <http://www.gnu.org/licenses/>.
+
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
+Copyright 2012 Justus Winter <4winter@informatik.uni-hamburg.de>
+'''
+
+import sys
+
+if sys.version_info[0] == 2:
+ from ConfigParser import SafeConfigParser
+
+ class Python3StringMixIn(object):
+ def __str__(self):
+ return unicode(self).encode('utf-8')
+
+ def encode_utf8(value):
+ '''
+ Ensure a nicely utf-8 encoded string to pass to wrapped
+ libnotmuch functions.
+
+ C++ code expects strings to be well formatted and unicode
+ strings to have no null bytes.
+ '''
+ if not isinstance(value, basestring):
+ raise TypeError('Expected str or unicode, got %s' % type(value))
+
+ if isinstance(value, unicode):
+ return value.encode('utf-8', 'replace')
+
+ return value
+else:
+ from configparser import SafeConfigParser
+
+ class Python3StringMixIn(object):
+ def __str__(self):
+ return self.__unicode__()
+
+ def encode_utf8(value):
+ '''
+ Ensure a nicely utf-8 encoded string to pass to wrapped
+ libnotmuch functions.
+
+ C++ code expects strings to be well formatted and unicode
+ strings to have no null bytes.
+ '''
+ if not isinstance(value, str):
+ raise TypeError('Expected str, got %s' % type(value))
+
+ return value.encode('utf-8', 'replace')
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 24da8e9..5931f41 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -14,19 +14,34 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see <http://www.gnu.org/licenses/>.
-Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
"""
import os
-from ctypes import c_char_p, c_void_p, c_uint, c_long, byref, POINTER
-from notmuch.globals import (nmlib, STATUS, NotmuchError, NotInitializedError,
- NullPointerError, Enum, _str,
- NotmuchDatabaseP, NotmuchDirectoryP, NotmuchMessageP, NotmuchTagsP,
- NotmuchQueryP, NotmuchMessagesP, NotmuchThreadsP, NotmuchFilenamesP)
-from notmuch.thread import Threads
-from notmuch.message import Messages, Message
-from notmuch.tag import Tags
-
+import codecs
+from ctypes import c_char_p, c_void_p, c_uint, byref, POINTER
+from .compat import SafeConfigParser
+from .globals import (
+ nmlib,
+ Enum,
+ _str,
+ NotmuchDatabaseP,
+ NotmuchDirectoryP,
+ NotmuchMessageP,
+ NotmuchTagsP,
+)
+from .errors import (
+ STATUS,
+ FileError,
+ NotmuchError,
+ NullPointerError,
+ NotInitializedError,
+ ReadOnlyDatabaseError,
+)
+from .message import Message
+from .tag import Tags
+from .query import Query
+from .directory import Directory
class Database(object):
"""The :class:`Database` is the highest-level object that notmuch
@@ -40,19 +55,16 @@ class Database(object):
:exc:`XapianError` as the underlying database has been
modified. Close and reopen the database to continue working with it.
+ :class:`Database` objects implement the context manager protocol
+ so you can use the :keyword:`with` statement to ensure that the
+ database is properly closed. See :meth:`close` for more
+ information.
+
.. note::
Any function in this class can and will throw an
:exc:`NotInitializedError` if the database was not intitialized
properly.
-
- .. note::
-
- Do remember that as soon as we tear down (e.g. via `del db`) this
- object, all underlying derived objects such as queries, threads,
- messages, tags etc will be freed by the underlying library as well.
- Accessing these objects will lead to segfaults and other unexpected
- behavior. See above for more details.
"""
_std_db_path = None
"""Class attribute to cache user's default database"""
@@ -62,8 +74,8 @@ class Database(object):
"""notmuch_database_get_directory"""
_get_directory = nmlib.notmuch_database_get_directory
- _get_directory.argtypes = [NotmuchDatabaseP, c_char_p]
- _get_directory.restype = NotmuchDirectoryP
+ _get_directory.argtypes = [NotmuchDatabaseP, c_char_p, POINTER(NotmuchDirectoryP)]
+ _get_directory.restype = c_uint
"""notmuch_database_get_path"""
_get_path = nmlib.notmuch_database_get_path
@@ -77,8 +89,8 @@ class Database(object):
"""notmuch_database_open"""
_open = nmlib.notmuch_database_open
- _open.argtypes = [c_char_p, c_uint]
- _open.restype = NotmuchDatabaseP
+ _open.argtypes = [c_char_p, c_uint, POINTER(NotmuchDatabaseP)]
+ _open.restype = c_uint
"""notmuch_database_upgrade"""
_upgrade = nmlib.notmuch_database_upgrade
@@ -104,10 +116,11 @@ class Database(object):
"""notmuch_database_create"""
_create = nmlib.notmuch_database_create
- _create.argtypes = [c_char_p]
- _create.restype = NotmuchDatabaseP
+ _create.argtypes = [c_char_p, POINTER(NotmuchDatabaseP)]
+ _create.restype = c_uint
- def __init__(self, path=None, create=False, mode=0):
+ def __init__(self, path = None, create = False,
+ mode = MODE.READ_ONLY):
"""If *path* is `None`, we will try to read a users notmuch
configuration and use his configured database. The location of the
configuration file can be specified through the environment variable
@@ -125,10 +138,11 @@ class Database(object):
:param mode: Mode to open a database in. Is always
:attr:`MODE`.READ_WRITE when creating a new one.
:type mode: :attr:`MODE`
- :exception: :exc:`NotmuchError` or derived exception in case of
+ :raises: :exc:`NotmuchError` or derived exception in case of
failure.
"""
self._db = None
+ self.mode = mode
if path is None:
# no path specified. use a user's default database
if Database._std_db_path is None:
@@ -141,9 +155,17 @@ class Database(object):
else:
self.create(path)
+ _destroy = nmlib.notmuch_database_destroy
+ _destroy.argtypes = [NotmuchDatabaseP]
+ _destroy.restype = None
+
+ def __del__(self):
+ if self._db:
+ self._destroy(self._db)
+
def _assert_db_is_initialized(self):
"""Raises :exc:`NotInitializedError` if self._db is `None`"""
- if self._db is None:
+ if not self._db:
raise NotInitializedError()
def create(self, path):
@@ -158,20 +180,20 @@ class Database(object):
:param path: A directory in which we should create the database.
:type path: str
- :returns: Nothing
- :exception: :exc:`NotmuchError` in case of any failure
+ :raises: :exc:`NotmuchError` in case of any failure
(possibly after printing an error message on stderr).
"""
- if self._db is not None:
+ if self._db:
raise NotmuchError(message="Cannot create db, this Database() "
"already has an open one.")
- res = Database._create(_str(path), Database.MODE.READ_WRITE)
+ db = NotmuchDatabaseP()
+ status = Database._create(_str(path), Database.MODE.READ_WRITE, byref(db))
- if res is None:
- raise NotmuchError(
- message="Could not create the specified database")
- self._db = res
+ if status != STATUS.SUCCESS:
+ raise NotmuchError(status)
+ self._db = db
+ return status
def open(self, path, mode=0):
"""Opens an existing database
@@ -182,15 +204,46 @@ class Database(object):
:param status: Open the database in read-only or read-write mode
:type status: :attr:`MODE`
- :returns: Nothing
- :exception: Raises :exc:`NotmuchError` in case of any failure
+ :raises: Raises :exc:`NotmuchError` in case of any failure
(possibly after printing an error message on stderr).
"""
- res = Database._open(_str(path), mode)
+ db = NotmuchDatabaseP()
+ status = Database._open(_str(path), mode, byref(db))
- if res is None:
- raise NotmuchError(message="Could not open the specified database")
- self._db = res
+ if status != STATUS.SUCCESS:
+ raise NotmuchError(status)
+ self._db = db
+ return status
+
+ _close = nmlib.notmuch_database_close
+ _close.argtypes = [NotmuchDatabaseP]
+ _close.restype = None
+
+ def close(self):
+ '''
+ Closes the notmuch database.
+
+ .. warning::
+
+ This function closes the notmuch database. From that point
+ on every method invoked on any object ever derived from
+ the closed database may cease to function and raise a
+ NotmuchError.
+ '''
+ if self._db:
+ self._close(self._db)
+
+ def __enter__(self):
+ '''
+ Implements the context manager protocol.
+ '''
+ return self
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ '''
+ Implements the context manager protocol.
+ '''
+ self.close()
def get_path(self):
"""Returns the file path of an open database"""
@@ -256,7 +309,7 @@ class Database(object):
neither begin nor end necessarily flush modifications to disk.
:returns: :attr:`STATUS`.SUCCESS or raises
- :exception: :exc:`NotmuchError`: :attr:`STATUS`.XAPIAN_EXCEPTION
+ :raises: :exc:`NotmuchError`: :attr:`STATUS`.XAPIAN_EXCEPTION
Xapian exception occurred; atomic section not entered.
*Added in notmuch 0.9*"""
@@ -277,7 +330,7 @@ class Database(object):
:returns: :attr:`STATUS`.SUCCESS or raises
- :exception:
+ :raises:
:exc:`NotmuchError`:
:attr:`STATUS`.XAPIAN_EXCEPTION
A Xapian exception occurred; atomic section not
@@ -294,41 +347,38 @@ class Database(object):
def get_directory(self, path):
"""Returns a :class:`Directory` of path,
- (creating it if it does not exist(?))
-
- .. warning::
-
- This call needs a writeable database in
- :attr:`Database.MODE`.READ_WRITE mode. The underlying library will
- exit the program if this method is used on a read-only database!
:param path: An unicode string containing the path relative to the path
of database (see :meth:`get_path`), or else should be an absolute
path with initial components that match the path of 'database'.
:returns: :class:`Directory` or raises an exception.
- :exception:
- :exc:`NotmuchError` with :attr:`STATUS`.FILE_ERROR
- If path is not relative database or absolute with initial
- components same as database.
+ :raises: :exc:`FileError` if path is not relative database or absolute
+ with initial components same as database.
"""
self._assert_db_is_initialized()
+
# sanity checking if path is valid, and make path absolute
- if path[0] == os.sep:
+ if path and path[0] == os.sep:
# we got an absolute path
if not path.startswith(self.get_path()):
# but its initial components are not equal to the db path
- raise NotmuchError(STATUS.FILE_ERROR,
- message="Database().get_directory() called "
- "with a wrong absolute path.")
+ raise FileError('Database().get_directory() called '
+ 'with a wrong absolute path')
abs_dirpath = path
else:
#we got a relative path, make it absolute
abs_dirpath = os.path.abspath(os.path.join(self.get_path(), path))
- dir_p = Database._get_directory(self._db, _str(path))
+ dir_p = NotmuchDirectoryP()
+ status = Database._get_directory(self._db, _str(path), byref(dir_p))
+
+ if status != STATUS.SUCCESS:
+ raise NotmuchError(status)
+ if not dir_p:
+ return None
# return the Directory, init it with the absolute path
- return Directory(_str(abs_dirpath), dir_p, self)
+ return Directory(abs_dirpath, dir_p, self)
_add_message = nmlib.notmuch_database_add_message
_add_message.argtypes = [NotmuchDatabaseP, c_char_p,
@@ -371,7 +421,7 @@ class Database(object):
:rtype: 2-tuple(:class:`Message`, :attr:`STATUS`)
- :exception: Raises a :exc:`NotmuchError` with the following meaning.
+ :raises: Raises a :exc:`NotmuchError` with the following meaning.
If such an exception occurs, nothing was added to the database.
:attr:`STATUS`.FILE_ERROR
@@ -421,7 +471,7 @@ class Database(object):
This filename was removed but the message persists in the
database with at least one other filename.
- :exception: Raises a :exc:`NotmuchError` with the following meaning.
+ :raises: Raises a :exc:`NotmuchError` with the following meaning.
If such an exception occurs, nothing was removed from the
database.
@@ -440,7 +490,7 @@ class Database(object):
:param msgid: The message ID
:type msgid: unicode or str
:returns: :class:`Message` or `None` if no message is found.
- :exception:
+ :raises:
:exc:`OutOfMemoryError`
If an Out-of-memory occured while constructing the message.
:exc:`XapianError`
@@ -462,31 +512,25 @@ class Database(object):
def find_message_by_filename(self, filename):
"""Find a message with the given filename
- .. warning::
-
- This call needs a writeable database in
- :attr:`Database.MODE`.READ_WRITE mode. The underlying library will
- exit the program if this method is used on a read-only database!
-
:returns: If the database contains a message with the given
filename, then a class:`Message:` is returned. This
function returns None if no message is found with the given
filename.
- :exception:
- :exc:`OutOfMemoryError`
- If an Out-of-memory occured while constructing the message.
- :exc:`XapianError`
- In case of a Xapian Exception. These exceptions
- include "Database modified" situations, e.g. when the
- notmuch database has been modified by another program
- in the meantime. In this case, you should close and
- reopen the database and retry.
- :exc:`NotInitializedError` if
- the database was not intitialized.
+ :raises: :exc:`OutOfMemoryError` if an Out-of-memory occured while
+ constructing the message.
+ :raises: :exc:`XapianError` in case of a Xapian Exception.
+ These exceptions include "Database modified"
+ situations, e.g. when the notmuch database has been
+ modified by another program in the meantime. In this
+ case, you should close and reopen the database and
+ retry.
+ :raises: :exc:`NotInitializedError` if the database was not
+ intitialized.
*Added in notmuch 0.9*"""
self._assert_db_is_initialized()
+
msg_p = NotmuchMessageP()
status = Database._find_message_by_filename(self._db, _str(filename),
byref(msg_p))
@@ -503,8 +547,8 @@ class Database(object):
"""
self._assert_db_is_initialized()
tags_p = Database._get_all_tags(self._db)
- if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ if not tags_p:
+ raise NullPointerError()
return Tags(tags_p, self)
def create_query(self, querystring):
@@ -530,444 +574,26 @@ class Database(object):
def __repr__(self):
return "'Notmuch DB " + self.get_path() + "'"
- _close = nmlib.notmuch_database_close
- _close.argtypes = [NotmuchDatabaseP]
- _close.restype = None
-
- def __del__(self):
- """Close and free the notmuch database if needed"""
- if self._db is not None:
- self._close(self._db)
-
def _get_user_default_db(self):
""" Reads a user's notmuch config and returns his db location
Throws a NotmuchError if it cannot find it"""
- try:
- # python3.x
- from configparser import SafeConfigParser
- except ImportError:
- # python2.x
- from ConfigParser import SafeConfigParser
-
config = SafeConfigParser()
conf_f = os.getenv('NOTMUCH_CONFIG',
os.path.expanduser('~/.notmuch-config'))
- config.read(conf_f)
+ config.readfp(codecs.open(conf_f, 'r', 'utf-8'))
if not config.has_option('database', 'path'):
raise NotmuchError(message="No DB path specified"
" and no user default found")
- return config.get('database', 'path').decode('utf-8')
+ return config.get('database', 'path')
@property
def db_p(self):
"""Property returning a pointer to `notmuch_database_t` or `None`
- This should normally not be needed by a user (and is not yet
- guaranteed to remain stable in future versions).
+ .. deprecated:: 0.14
+ If you really need a pointer to the notmuch
+ database object use the `_pointer` field. This
+ alias will be removed in notmuch 0.15.
"""
return self._db
-
-
-class Query(object):
- """Represents a search query on an opened :class:`Database`.
-
- A query selects and filters a subset of messages from the notmuch
- database we derive from.
-
- :class:`Query` provides an instance attribute :attr:`sort`, which
- contains the sort order (if specified via :meth:`set_sort`) or
- `None`.
-
- Any function in this class may throw an :exc:`NotInitializedError`
- in case the underlying query object was not set up correctly.
-
- .. note:: Do remember that as soon as we tear down this object,
- all underlying derived objects such as threads,
- messages, tags etc will be freed by the underlying library
- as well. Accessing these objects will lead to segfaults and
- other unexpected behavior. See above for more details.
- """
- # constants
- SORT = Enum(['OLDEST_FIRST', 'NEWEST_FIRST', 'MESSAGE_ID', 'UNSORTED'])
- """Constants: Sort order in which to return results"""
-
- """notmuch_query_create"""
- _create = nmlib.notmuch_query_create
- _create.argtypes = [NotmuchDatabaseP, c_char_p]
- _create.restype = NotmuchQueryP
-
- """notmuch_query_search_threads"""
- _search_threads = nmlib.notmuch_query_search_threads
- _search_threads.argtypes = [NotmuchQueryP]
- _search_threads.restype = NotmuchThreadsP
-
- """notmuch_query_search_messages"""
- _search_messages = nmlib.notmuch_query_search_messages
- _search_messages.argtypes = [NotmuchQueryP]
- _search_messages.restype = NotmuchMessagesP
-
- """notmuch_query_count_messages"""
- _count_messages = nmlib.notmuch_query_count_messages
- _count_messages.argtypes = [NotmuchQueryP]
- _count_messages.restype = c_uint
-
- def __init__(self, db, querystr):
- """
- :param db: An open database which we derive the Query from.
- :type db: :class:`Database`
- :param querystr: The query string for the message.
- :type querystr: utf-8 encoded str or unicode
- """
- self._db = None
- self._query = None
- self.sort = None
- self.create(db, querystr)
-
- def _assert_query_is_initialized(self):
- """Raises :exc:`NotInitializedError` if self._query is `None`"""
- if self._query is None:
- raise NotInitializedError()
-
- def create(self, db, querystr):
- """Creates a new query derived from a Database
-
- This function is utilized by __init__() and usually does not need to
- be called directly.
-
- :param db: Database to create the query from.
- :type db: :class:`Database`
- :param querystr: The query string
- :type querystr: utf-8 encoded str or unicode
- :returns: Nothing
- :exception:
- :exc:`NullPointerError` if the query creation failed
- (e.g. too little memory).
- :exc:`NotInitializedError` if the underlying db was not
- intitialized.
- """
- db._assert_db_is_initialized()
- # create reference to parent db to keep it alive
- self._db = db
- # create query, return None if too little mem available
- query_p = Query._create(db.db_p, _str(querystr))
- if query_p is None:
- raise NullPointerError
- self._query = query_p
-
- _set_sort = nmlib.notmuch_query_set_sort
- _set_sort.argtypes = [NotmuchQueryP, c_uint]
- _set_sort.argtypes = None
-
- def set_sort(self, sort):
- """Set the sort order future results will be delivered in
-
- :param sort: Sort order (see :attr:`Query.SORT`)
- """
- self._assert_query_is_initialized()
- self.sort = sort
- self._set_sort(self._query, sort)
-
- def search_threads(self):
- """Execute a query for threads
-
- Execute a query for threads, returning a :class:`Threads` iterator.
- The returned threads are owned by the query and as such, will only be
- valid until the Query is deleted.
-
- The method sets :attr:`Message.FLAG`\.MATCH for those messages that
- match the query. The method :meth:`Message.get_flag` allows us
- to get the value of this flag.
-
- :returns: :class:`Threads`
- :exception: :exc:`NullPointerError` if search_threads failed
- """
- self._assert_query_is_initialized()
- threads_p = Query._search_threads(self._query)
-
- if threads_p is None:
- raise NullPointerError
- return Threads(threads_p, self)
-
- def search_messages(self):
- """Filter messages according to the query and return
- :class:`Messages` in the defined sort order
-
- :returns: :class:`Messages`
- :exception: :exc:`NullPointerError` if search_messages failed
- """
- self._assert_query_is_initialized()
- msgs_p = Query._search_messages(self._query)
-
- if msgs_p is None:
- raise NullPointerError
- return Messages(msgs_p, self)
-
- def count_messages(self):
- """Estimate the number of messages matching the query
-
- This function performs a search and returns Xapian's best
- guess as to the number of matching messages. It is much faster
- than performing :meth:`search_messages` and counting the
- result with `len()` (although it always returned the same
- result in my tests). Technically, it wraps the underlying
- *notmuch_query_count_messages* function.
-
- :returns: :class:`Messages`
- """
- self._assert_query_is_initialized()
- return Query._count_messages(self._query)
-
- _destroy = nmlib.notmuch_query_destroy
- _destroy.argtypes = [NotmuchQueryP]
- _destroy.restype = None
-
- def __del__(self):
- """Close and free the Query"""
- if self._query is not None:
- self._destroy(self._query)
-
-
-class Directory(object):
- """Represents a directory entry in the notmuch directory
-
- Modifying attributes of this object will modify the
- database, not the real directory attributes.
-
- The Directory object is usually derived from another object
- e.g. via :meth:`Database.get_directory`, and will automatically be
- become invalid whenever that parent is deleted. You should
- therefore initialized this object handing it a reference to the
- parent, preventing the parent from automatically being garbage
- collected.
- """
-
- """notmuch_directory_get_mtime"""
- _get_mtime = nmlib.notmuch_directory_get_mtime
- _get_mtime.argtypes = [NotmuchDirectoryP]
- _get_mtime.restype = c_long
-
- """notmuch_directory_set_mtime"""
- _set_mtime = nmlib.notmuch_directory_set_mtime
- _set_mtime.argtypes = [NotmuchDirectoryP, c_long]
- _set_mtime.restype = c_uint
-
- """notmuch_directory_get_child_files"""
- _get_child_files = nmlib.notmuch_directory_get_child_files
- _get_child_files.argtypes = [NotmuchDirectoryP]
- _get_child_files.restype = NotmuchFilenamesP
-
- """notmuch_directory_get_child_directories"""
- _get_child_directories = nmlib.notmuch_directory_get_child_directories
- _get_child_directories.argtypes = [NotmuchDirectoryP]
- _get_child_directories.restype = NotmuchFilenamesP
-
- def _assert_dir_is_initialized(self):
- """Raises a NotmuchError(:attr:`STATUS`.NOT_INITIALIZED)
- if dir_p is None"""
- if self._dir_p is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
-
- def __init__(self, path, dir_p, parent):
- """
- :param path: The absolute path of the directory object as unicode.
- :param dir_p: The pointer to an internal notmuch_directory_t object.
- :param parent: The object this Directory is derived from
- (usually a :class:`Database`). We do not directly use
- this, but store a reference to it as long as
- this Directory object lives. This keeps the
- parent object alive.
- """
- assert isinstance(path, unicode), "Path needs to be an UNICODE object"
- self._path = path
- self._dir_p = dir_p
- self._parent = parent
-
- def set_mtime(self, mtime):
- """Sets the mtime value of this directory in the database
-
- The intention is for the caller to use the mtime to allow efficient
- identification of new messages to be added to the database. The
- recommended usage is as follows:
-
- * Read the mtime of a directory from the filesystem
-
- * Call :meth:`Database.add_message` for all mail files in
- the directory
-
- * Call notmuch_directory_set_mtime with the mtime read from the
- filesystem. Then, when wanting to check for updates to the
- directory in the future, the client can call :meth:`get_mtime`
- and know that it only needs to add files if the mtime of the
- directory and files are newer than the stored timestamp.
-
- .. note::
-
- :meth:`get_mtime` function does not allow the caller to
- distinguish a timestamp of 0 from a non-existent timestamp. So
- don't store a timestamp of 0 unless you are comfortable with
- that.
-
- :param mtime: A (time_t) timestamp
- :returns: Nothing on success, raising an exception on failure.
- :exception: :exc:`NotmuchError`:
-
- :attr:`STATUS`.XAPIAN_EXCEPTION
- A Xapian exception occurred, mtime not stored.
- :attr:`STATUS`.READ_ONLY_DATABASE
- Database was opened in read-only mode so directory
- mtime cannot be modified.
- :attr:`STATUS`.NOT_INITIALIZED
- The directory has not been initialized
- """
- self._assert_dir_is_initialized()
- #TODO: make sure, we convert the mtime parameter to a 'c_long'
- status = Directory._set_mtime(self._dir_p, mtime)
-
- #return on success
- if status == STATUS.SUCCESS:
- return
- #fail with Exception otherwise
- raise NotmuchError(status)
-
- def get_mtime(self):
- """Gets the mtime value of this directory in the database
-
- Retrieves a previously stored mtime for this directory.
-
- :param mtime: A (time_t) timestamp
- :returns: Nothing on success, raising an exception on failure.
- :exception: :exc:`NotmuchError`:
-
- :attr:`STATUS`.NOT_INITIALIZED
- The directory has not been initialized
- """
- self._assert_dir_is_initialized()
- return Directory._get_mtime(self._dir_p)
-
- # Make mtime attribute a property of Directory()
- mtime = property(get_mtime, set_mtime, doc="""Property that allows getting
- and setting of the Directory *mtime* (read-write)
-
- See :meth:`get_mtime` and :meth:`set_mtime` for usage and
- possible exceptions.""")
-
- def get_child_files(self):
- """Gets a Filenames iterator listing all the filenames of
- messages in the database within the given directory.
-
- The returned filenames will be the basename-entries only (not
- complete paths.
- """
- self._assert_dir_is_initialized()
- files_p = Directory._get_child_files(self._dir_p)
- return Filenames(files_p, self)
-
- def get_child_directories(self):
- """Gets a :class:`Filenames` iterator listing all the filenames of
- sub-directories in the database within the given directory
-
- The returned filenames will be the basename-entries only (not
- complete paths.
- """
- self._assert_dir_is_initialized()
- files_p = Directory._get_child_directories(self._dir_p)
- return Filenames(files_p, self)
-
- @property
- def path(self):
- """Returns the absolute path of this Directory (read-only)"""
- return self._path
-
- def __repr__(self):
- """Object representation"""
- return "<notmuch Directory object '%s'>" % self._path
-
- _destroy = nmlib.notmuch_directory_destroy
- _destroy.argtypes = [NotmuchDirectoryP]
- _destroy.argtypes = None
-
- def __del__(self):
- """Close and free the Directory"""
- if self._dir_p is not None:
- self._destroy(self._dir_p)
-
-
-class Filenames(object):
- """An iterator over File- or Directory names stored in the database"""
-
- #notmuch_filenames_get
- _get = nmlib.notmuch_filenames_get
- _get.argtypes = [NotmuchFilenamesP]
- _get.restype = c_char_p
-
- def __init__(self, files_p, parent):
- """
- :param files_p: The pointer to an internal notmuch_filenames_t object.
- :param parent: The object this Directory is derived from
- (usually a Directory()). We do not directly use
- this, but store a reference to it as long as
- this Directory object lives. This keeps the
- parent object alive.
- """
- self._files_p = files_p
- self._parent = parent
-
- def __iter__(self):
- """ Make Filenames an iterator """
- return self
-
- _valid = nmlib.notmuch_filenames_valid
- _valid.argtypes = [NotmuchFilenamesP]
- _valid.restype = bool
-
- _move_to_next = nmlib.notmuch_filenames_move_to_next
- _move_to_next.argtypes = [NotmuchFilenamesP]
- _move_to_next.restype = None
-
- def __next__(self):
- if self._files_p is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
-
- if not self._valid(self._files_p):
- self._files_p = None
- raise StopIteration
-
- file_ = Filenames._get(self._files_p)
- self._move_to_next(self._files_p)
- return file_.decode('utf-8', 'ignore')
- next = __next__ # python2.x iterator protocol compatibility
-
- def __len__(self):
- """len(:class:`Filenames`) returns the number of contained files
-
- .. note::
-
- As this iterates over the files, we will not be able to
- iterate over them again! So this will fail::
-
- #THIS FAILS
- files = Database().get_directory('').get_child_files()
- if len(files) > 0: # this 'exhausts' msgs
- # next line raises
- # NotmuchError(:attr:`STATUS`.NOT_INITIALIZED)
- for file in files: print file
- """
- if self._files_p is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
-
- i = 0
- while self._valid(self._files_p):
- self._move_to_next(self._files_p)
- i += 1
- self._files_p = None
- return i
-
- _destroy = nmlib.notmuch_filenames_destroy
- _destroy.argtypes = [NotmuchFilenamesP]
- _destroy.restype = None
-
- def __del__(self):
- """Close and free Filenames"""
- if self._files_p is not None:
- self._destroy(self._files_p)
diff --git a/bindings/python/notmuch/directory.py b/bindings/python/notmuch/directory.py
new file mode 100644
index 0000000..3b0a525
--- /dev/null
+++ b/bindings/python/notmuch/directory.py
@@ -0,0 +1,185 @@
+"""
+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 <http://www.gnu.org/licenses/>.
+
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
+"""
+
+from ctypes import c_uint, c_long
+from .globals import (
+ nmlib,
+ NotmuchDirectoryP,
+ NotmuchFilenamesP
+)
+from .errors import (
+ STATUS,
+ NotmuchError,
+ NotInitializedError,
+)
+from .filenames import Filenames
+
+class Directory(object):
+ """Represents a directory entry in the notmuch directory
+
+ Modifying attributes of this object will modify the
+ database, not the real directory attributes.
+
+ The Directory object is usually derived from another object
+ e.g. via :meth:`Database.get_directory`, and will automatically be
+ become invalid whenever that parent is deleted. You should
+ therefore initialized this object handing it a reference to the
+ parent, preventing the parent from automatically being garbage
+ collected.
+ """
+
+ """notmuch_directory_get_mtime"""
+ _get_mtime = nmlib.notmuch_directory_get_mtime
+ _get_mtime.argtypes = [NotmuchDirectoryP]
+ _get_mtime.restype = c_long
+
+ """notmuch_directory_set_mtime"""
+ _set_mtime = nmlib.notmuch_directory_set_mtime
+ _set_mtime.argtypes = [NotmuchDirectoryP, c_long]
+ _set_mtime.restype = c_uint
+
+ """notmuch_directory_get_child_files"""
+ _get_child_files = nmlib.notmuch_directory_get_child_files
+ _get_child_files.argtypes = [NotmuchDirectoryP]
+ _get_child_files.restype = NotmuchFilenamesP
+
+ """notmuch_directory_get_child_directories"""
+ _get_child_directories = nmlib.notmuch_directory_get_child_directories
+ _get_child_directories.argtypes = [NotmuchDirectoryP]
+ _get_child_directories.restype = NotmuchFilenamesP
+
+ def _assert_dir_is_initialized(self):
+ """Raises a NotmuchError(:attr:`STATUS`.NOT_INITIALIZED)
+ if dir_p is None"""
+ if not self._dir_p:
+ raise NotInitializedError()
+
+ def __init__(self, path, dir_p, parent):
+ """
+ :param path: The absolute path of the directory object.
+ :param dir_p: The pointer to an internal notmuch_directory_t object.
+ :param parent: The object this Directory is derived from
+ (usually a :class:`Database`). We do not directly use
+ this, but store a reference to it as long as
+ this Directory object lives. This keeps the
+ parent object alive.
+ """
+ self._path = path
+ self._dir_p = dir_p
+ self._parent = parent
+
+ def set_mtime(self, mtime):
+ """Sets the mtime value of this directory in the database
+
+ The intention is for the caller to use the mtime to allow efficient
+ identification of new messages to be added to the database. The
+ recommended usage is as follows:
+
+ * Read the mtime of a directory from the filesystem
+
+ * Call :meth:`Database.add_message` for all mail files in
+ the directory
+
+ * Call notmuch_directory_set_mtime with the mtime read from the
+ filesystem. Then, when wanting to check for updates to the
+ directory in the future, the client can call :meth:`get_mtime`
+ and know that it only needs to add files if the mtime of the
+ directory and files are newer than the stored timestamp.
+
+ .. note::
+
+ :meth:`get_mtime` function does not allow the caller to
+ distinguish a timestamp of 0 from a non-existent timestamp. So
+ don't store a timestamp of 0 unless you are comfortable with
+ that.
+
+ :param mtime: A (time_t) timestamp
+ :raises: :exc:`XapianError` a Xapian exception occurred, mtime
+ not stored
+ :raises: :exc:`ReadOnlyDatabaseError` the database was opened
+ in read-only mode so directory mtime cannot be modified
+ :raises: :exc:`NotInitializedError` the directory object has not
+ been initialized
+ """
+ self._assert_dir_is_initialized()
+ status = Directory._set_mtime(self._dir_p, mtime)
+
+ if status != STATUS.SUCCESS:
+ raise NotmuchError(status)
+
+ def get_mtime(self):
+ """Gets the mtime value of this directory in the database
+
+ Retrieves a previously stored mtime for this directory.
+
+ :param mtime: A (time_t) timestamp
+ :raises: :exc:`NotmuchError`:
+
+ :attr:`STATUS`.NOT_INITIALIZED
+ The directory has not been initialized
+ """
+ self._assert_dir_is_initialized()
+ return Directory._get_mtime(self._dir_p)
+
+ # Make mtime attribute a property of Directory()
+ mtime = property(get_mtime, set_mtime, doc="""Property that allows getting
+ and setting of the Directory *mtime* (read-write)
+
+ See :meth:`get_mtime` and :meth:`set_mtime` for usage and
+ possible exceptions.""")
+
+ def get_child_files(self):
+ """Gets a Filenames iterator listing all the filenames of
+ messages in the database within the given directory.
+
+ The returned filenames will be the basename-entries only (not
+ complete paths.
+ """
+ self._assert_dir_is_initialized()
+ files_p = Directory._get_child_files(self._dir_p)
+ return Filenames(files_p, self)
+
+ def get_child_directories(self):
+ """Gets a :class:`Filenames` iterator listing all the filenames of
+ sub-directories in the database within the given directory
+
+ The returned filenames will be the basename-entries only (not
+ complete paths.
+ """
+ self._assert_dir_is_initialized()
+ files_p = Directory._get_child_directories(self._dir_p)
+ return Filenames(files_p, self)
+
+ @property
+ def path(self):
+ """Returns the absolute path of this Directory (read-only)"""
+ return self._path
+
+ def __repr__(self):
+ """Object representation"""
+ return "<notmuch Directory object '%s'>" % self._path
+
+ _destroy = nmlib.notmuch_directory_destroy
+ _destroy.argtypes = [NotmuchDirectoryP]
+ _destroy.restype = None
+
+ def __del__(self):
+ """Close and free the Directory"""
+ if self._dir_p:
+ self._destroy(self._dir_p)
diff --git a/bindings/python/notmuch/errors.py b/bindings/python/notmuch/errors.py
new file mode 100644
index 0000000..f153a9c
--- /dev/null
+++ b/bindings/python/notmuch/errors.py
@@ -0,0 +1,183 @@
+"""
+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 <http://www.gnu.org/licenses/>.
+
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
+"""
+
+from ctypes import c_char_p, c_int
+
+from .globals import (
+ nmlib,
+ Enum,
+ Python3StringMixIn,
+)
+
+class Status(Enum):
+ """Enum with a string representation of a notmuch_status_t value."""
+ _status2str = nmlib.notmuch_status_to_string
+ _status2str.restype = c_char_p
+ _status2str.argtypes = [c_int]
+
+ def __init__(self, statuslist):
+ """It is initialized with a list of strings that are available as
+ Status().string1 - Status().stringn attributes.
+ """
+ super(Status, self).__init__(statuslist)
+
+ @classmethod
+ def status2str(self, status):
+ """Get a (unicode) string representation of a notmuch_status_t value."""
+ # define strings for custom error messages
+ if status == STATUS.NOT_INITIALIZED:
+ return "Operation on uninitialized object impossible."
+ return unicode(Status._status2str(status))
+
+STATUS = Status(['SUCCESS',
+ 'OUT_OF_MEMORY',
+ 'READ_ONLY_DATABASE',
+ 'XAPIAN_EXCEPTION',
+ 'FILE_ERROR',
+ 'FILE_NOT_EMAIL',
+ 'DUPLICATE_MESSAGE_ID',
+ 'NULL_POINTER',
+ 'TAG_TOO_LONG',
+ 'UNBALANCED_FREEZE_THAW',
+ 'UNBALANCED_ATOMIC',
+ 'NOT_INITIALIZED'])
+"""STATUS is a class, whose attributes provide constants that serve as return
+indicators for notmuch functions. Currently the following ones are defined. For
+possible return values and specific meaning for each method, see the method
+description.
+
+ * SUCCESS
+ * OUT_OF_MEMORY
+ * READ_ONLY_DATABASE
+ * XAPIAN_EXCEPTION
+ * FILE_ERROR
+ * FILE_NOT_EMAIL
+ * DUPLICATE_MESSAGE_ID
+ * NULL_POINTER
+ * TAG_TOO_LONG
+ * UNBALANCED_FREEZE_THAW
+ * UNBALANCED_ATOMIC
+ * NOT_INITIALIZED
+
+Invoke the class method `notmuch.STATUS.status2str` with a status value as
+argument to receive a human readable string"""
+STATUS.__name__ = 'STATUS'
+
+
+class NotmuchError(Exception, Python3StringMixIn):
+ """Is initiated with a (notmuch.STATUS[, message=None]). It will not
+ return an instance of the class NotmuchError, but a derived instance
+ of a more specific Error Message, e.g. OutOfMemoryError. Each status
+ but SUCCESS has a corresponding subclassed Exception."""
+
+ @classmethod
+ def get_exc_subclass(cls, status):
+ """Returns a fine grained Exception() type,
+ detailing the error status"""
+ subclasses = {
+ STATUS.OUT_OF_MEMORY: OutOfMemoryError,
+ STATUS.READ_ONLY_DATABASE: ReadOnlyDatabaseError,
+ STATUS.XAPIAN_EXCEPTION: XapianError,
+ STATUS.FILE_ERROR: FileError,
+ STATUS.FILE_NOT_EMAIL: FileNotEmailError,
+ STATUS.DUPLICATE_MESSAGE_ID: DuplicateMessageIdError,
+ STATUS.NULL_POINTER: NullPointerError,
+ STATUS.TAG_TOO_LONG: TagTooLongError,
+ STATUS.UNBALANCED_FREEZE_THAW: UnbalancedFreezeThawError,
+ STATUS.UNBALANCED_ATOMIC: UnbalancedAtomicError,
+ STATUS.NOT_INITIALIZED: NotInitializedError,
+ }
+ assert 0 < status <= len(subclasses)
+ return subclasses[status]
+
+ def __new__(cls, *args, **kwargs):
+ """Return a correct subclass of NotmuchError if needed
+
+ We return a NotmuchError instance if status is None (or 0) and a
+ subclass that inherits from NotmuchError depending on the
+ 'status' parameter otherwise."""
+ # get 'status'. Passed in as arg or kwarg?
+ status = args[0] if len(args) else kwargs.get('status', None)
+ # no 'status' or cls is subclass already, return 'cls' instance
+ if not status or cls != NotmuchError:
+ return super(NotmuchError, cls).__new__(cls)
+ subclass = cls.get_exc_subclass(status) # which class to use?
+ return subclass.__new__(subclass, *args, **kwargs)
+
+ def __init__(self, status=None, message=None):
+ self.status = status
+ self.message = message
+
+ def __unicode__(self):
+ if self.message is not None:
+ return self.message
+ elif self.status is not None:
+ return STATUS.status2str(self.status)
+ else:
+ return 'Unknown error'
+
+
+# List of Subclassed exceptions that correspond to STATUS values and are
+# subclasses of NotmuchError.
+class OutOfMemoryError(NotmuchError):
+ status = STATUS.OUT_OF_MEMORY
+
+
+class ReadOnlyDatabaseError(NotmuchError):
+ status = STATUS.READ_ONLY_DATABASE
+
+
+class XapianError(NotmuchError):
+ status = STATUS.XAPIAN_EXCEPTION
+
+
+class FileError(NotmuchError):
+ status = STATUS.FILE_ERROR
+
+
+class FileNotEmailError(NotmuchError):
+ status = STATUS.FILE_NOT_EMAIL
+
+
+class DuplicateMessageIdError(NotmuchError):
+ status = STATUS.DUPLICATE_MESSAGE_ID
+
+
+class NullPointerError(NotmuchError):
+ status = STATUS.NULL_POINTER
+
+
+class TagTooLongError(NotmuchError):
+ status = STATUS.TAG_TOO_LONG
+
+
+class UnbalancedFreezeThawError(NotmuchError):
+ status = STATUS.UNBALANCED_FREEZE_THAW
+
+
+class UnbalancedAtomicError(NotmuchError):
+ status = STATUS.UNBALANCED_ATOMIC
+
+
+class NotInitializedError(NotmuchError):
+ """Derived from NotmuchError, this occurs if the underlying data
+ structure (e.g. database is not initialized (yet) or an iterator has
+ been exhausted. You can test for NotmuchError with .status =
+ STATUS.NOT_INITIALIZED"""
+ status = STATUS.NOT_INITIALIZED
diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py
deleted file mode 100644
index 51dae20..0000000
--- a/bindings/python/notmuch/filename.py
+++ /dev/null
@@ -1,121 +0,0 @@
-"""
-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 <http://www.gnu.org/licenses/>.
-
-Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
-"""
-from ctypes import c_char_p
-from notmuch.globals import (nmlib, STATUS, NotmuchError,
- NotmuchFilenamesP, NotmuchMessageP, _str, Python3StringMixIn)
-
-
-class Filenames(Python3StringMixIn):
- """Represents a list of filenames as returned by notmuch
-
- This object contains the Filenames iterator. The main function is
- as_generator() which will return a generator so we can do a Filenamesth an
- iterator over a list of notmuch filenames. Do note that the underlying
- library only provides a one-time iterator (it cannot reset the iterator to
- the start). Thus iterating over the function will "exhaust" the list of
- tags, and a subsequent iteration attempt will raise a :exc:`NotmuchError`
- STATUS.NOT_INITIALIZED. Also note, that any function that uses iteration
- (nearly all) will also exhaust the tags. So both::
-
- for name in filenames: print name
-
- as well as::
-
- number_of_names = len(names)
-
- and even a simple::
-
- #str() iterates over all tags to construct a space separated list
- print(str(filenames))
-
- will "exhaust" the Filenames. However, you can use
- :meth:`Message.get_filenames` repeatedly to get fresh Filenames
- objects to perform various actions on filenames.
- """
-
- #notmuch_filenames_get
- _get = nmlib.notmuch_filenames_get
- _get.argtypes = [NotmuchFilenamesP]
- _get.restype = c_char_p
-
- def __init__(self, files_p, parent):
- """
- :param files_p: A pointer to an underlying *notmuch_tags_t*
- structure. These are not publically exposed, so a user
- will almost never instantiate a :class:`Tags` object
- herself. They are usually handed back as a result,
- e.g. in :meth:`Database.get_all_tags`. *tags_p* must be
- valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
- :type files_p: :class:`ctypes.c_void_p`
- :param parent: The parent object (ie :class:`Message` these
- filenames are derived from, and saves a
- reference to it, so we can automatically delete the db object
- once all derived objects are dead.
- """
- if files_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
-
- self._files = files_p
- #save reference to parent object so we keep it alive
- self._parent = parent
-
- _valid = nmlib.notmuch_filenames_valid
- _valid.argtypes = [NotmuchFilenamesP]
- _valid.restype = bool
-
- _move_to_next = nmlib.notmuch_filenames_move_to_next
- _move_to_next.argtypes = [NotmuchFilenamesP]
- _move_to_next.restype = None
-
- def as_generator(self):
- """Return generator of Filenames
-
- This is the main function that will usually be used by the
- user."""
- if self._files is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
-
- while self._valid(self._files):
- yield Filenames._get(self._files).decode('utf-8', 'ignore')
- self._move_to_next(self._files)
-
- self._files = None
-
- def __unicode__(self):
- """Represent Filenames() as newline-separated list of full paths
-
- .. note:: As this iterates over the filenames, we will not be
- able to iterate over them again (as in retrieve them)! If
- the tags have been exhausted already, this will raise a
- :exc:`NotmuchError` STATUS.NOT_INITIALIZED on subsequent
- attempts. However, you can use
- :meth:`Message.get_filenames` repeatedly to perform
- various actions on filenames.
- """
- return "\n".join(self)
-
- _destroy = nmlib.notmuch_filenames_destroy
- _destroy.argtypes = [NotmuchMessageP]
- _destroy.restype = None
-
- def __del__(self):
- """Close and free the notmuch filenames"""
- if self._files is not None:
- self._destroy(self._files)
diff --git a/bindings/python/notmuch/filenames.py b/bindings/python/notmuch/filenames.py
new file mode 100644
index 0000000..229f414
--- /dev/null
+++ b/bindings/python/notmuch/filenames.py
@@ -0,0 +1,150 @@
+"""
+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 <http://www.gnu.org/licenses/>.
+
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
+"""
+from ctypes import c_char_p
+from .globals import (
+ nmlib,
+ NotmuchMessageP,
+ NotmuchFilenamesP,
+ Python3StringMixIn,
+)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
+
+
+class Filenames(Python3StringMixIn):
+ """Represents a list of filenames as returned by notmuch
+
+ Objects of this class implement the iterator protocol.
+
+ .. note::
+
+ The underlying library only provides a one-time iterator (it
+ cannot reset the iterator to the start). Thus iterating over
+ the function will "exhaust" the list of tags, and a subsequent
+ iteration attempt will raise a
+ :exc:`NotInitializedError`. Also note, that any function that
+ uses iteration (nearly all) will also exhaust the tags. So
+ both::
+
+ for name in filenames: print name
+
+ as well as::
+
+ number_of_names = len(names)
+
+ and even a simple::
+
+ #str() iterates over all tags to construct a space separated list
+ print(str(filenames))
+
+ will "exhaust" the Filenames. However, you can use
+ :meth:`Message.get_filenames` repeatedly to get fresh
+ Filenames objects to perform various actions on filenames.
+ """
+
+ #notmuch_filenames_get
+ _get = nmlib.notmuch_filenames_get
+ _get.argtypes = [NotmuchFilenamesP]
+ _get.restype = c_char_p
+
+ def __init__(self, files_p, parent):
+ """
+ :param files_p: A pointer to an underlying *notmuch_tags_t*
+ structure. These are not publically exposed, so a user
+ will almost never instantiate a :class:`Tags` object
+ herself. They are usually handed back as a result,
+ e.g. in :meth:`Database.get_all_tags`. *tags_p* must be
+ valid, we will raise an :exc:`NullPointerError`
+ if it is `None`.
+ :type files_p: :class:`ctypes.c_void_p`
+ :param parent: The parent object (ie :class:`Message` these
+ filenames are derived from, and saves a
+ reference to it, so we can automatically delete the db object
+ once all derived objects are dead.
+ """
+ if not files_p:
+ raise NullPointerError()
+
+ self._files_p = files_p
+ #save reference to parent object so we keep it alive
+ self._parent = parent
+
+ def __iter__(self):
+ """ Make Filenames an iterator """
+ return self
+
+ _valid = nmlib.notmuch_filenames_valid
+ _valid.argtypes = [NotmuchFilenamesP]
+ _valid.restype = bool
+
+ _move_to_next = nmlib.notmuch_filenames_move_to_next
+ _move_to_next.argtypes = [NotmuchFilenamesP]
+ _move_to_next.restype = None
+
+ def __next__(self):
+ if not self._files_p:
+ raise NotInitializedError()
+
+ if not self._valid(self._files_p):
+ self._files_p = None
+ raise StopIteration
+
+ file_ = Filenames._get(self._files_p)
+ self._move_to_next(self._files_p)
+ return file_.decode('utf-8', 'ignore')
+ next = __next__ # python2.x iterator protocol compatibility
+
+ def __unicode__(self):
+ """Represent Filenames() as newline-separated list of full paths
+
+ .. note::
+
+ This method exhausts the iterator object, so you will not be able to
+ iterate over them again.
+ """
+ return "\n".join(self)
+
+ _destroy = nmlib.notmuch_filenames_destroy
+ _destroy.argtypes = [NotmuchMessageP]
+ _destroy.restype = None
+
+ def __del__(self):
+ """Close and free the notmuch filenames"""
+ if self._files_p:
+ self._destroy(self._files_p)
+
+ def __len__(self):
+ """len(:class:`Filenames`) returns the number of contained files
+
+ .. note::
+
+ This method exhausts the iterator object, so you will not be able to
+ iterate over them again.
+ """
+ if not self._files_p:
+ raise NotInitializedError()
+
+ i = 0
+ while self._valid(self._files_p):
+ self._move_to_next(self._files_p)
+ i += 1
+ self._files_p = None
+ return i
diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
index 32ed9ae..c7632c3 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -14,28 +14,19 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see <http://www.gnu.org/licenses/>.
-Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
"""
-import sys
-from ctypes import CDLL, c_char_p, c_int, Structure, POINTER
+
+from ctypes import CDLL, Structure, POINTER
#-----------------------------------------------------------------------------
#package-global instance of the notmuch library
try:
- nmlib = CDLL("libnotmuch.so.2")
+ nmlib = CDLL("libnotmuch.so.3")
except:
raise ImportError("Could not find shared 'notmuch' library.")
-
-if sys.version_info[0] == 2:
- class Python3StringMixIn(object):
- def __str__(self):
- return unicode(self).encode('utf-8')
-else:
- class Python3StringMixIn(object):
- def __str__(self):
- return self.__unicode__()
-
+from .compat import Python3StringMixIn, encode_utf8 as _str
class Enum(object):
"""Provides ENUMS as "code=Enum(['a','b','c'])" where code.a=0 etc..."""
@@ -44,176 +35,6 @@ class Enum(object):
setattr(self, name, number)
-class Status(Enum):
- """Enum with a string representation of a notmuch_status_t value."""
- _status2str = nmlib.notmuch_status_to_string
- _status2str.restype = c_char_p
- _status2str.argtypes = [c_int]
-
- def __init__(self, statuslist):
- """It is initialized with a list of strings that are available as
- Status().string1 - Status().stringn attributes.
- """
- super(Status, self).__init__(statuslist)
-
- @classmethod
- def status2str(self, status):
- """Get a (unicode) string representation of a notmuch_status_t value."""
- # define strings for custom error messages
- if status == STATUS.NOT_INITIALIZED:
- return "Operation on uninitialized object impossible."
- return unicode(Status._status2str(status))
-
-STATUS = Status(['SUCCESS',
- 'OUT_OF_MEMORY',
- 'READ_ONLY_DATABASE',
- 'XAPIAN_EXCEPTION',
- 'FILE_ERROR',
- 'FILE_NOT_EMAIL',
- 'DUPLICATE_MESSAGE_ID',
- 'NULL_POINTER',
- 'TAG_TOO_LONG',
- 'UNBALANCED_FREEZE_THAW',
- 'UNBALANCED_ATOMIC',
- 'NOT_INITIALIZED'])
-"""STATUS is a class, whose attributes provide constants that serve as return
-indicators for notmuch functions. Currently the following ones are defined. For
-possible return values and specific meaning for each method, see the method
-description.
-
- * SUCCESS
- * OUT_OF_MEMORY
- * READ_ONLY_DATABASE
- * XAPIAN_EXCEPTION
- * FILE_ERROR
- * FILE_NOT_EMAIL
- * DUPLICATE_MESSAGE_ID
- * NULL_POINTER
- * TAG_TOO_LONG
- * UNBALANCED_FREEZE_THAW
- * UNBALANCED_ATOMIC
- * NOT_INITIALIZED
-
-Invoke the class method `notmuch.STATUS.status2str` with a status value as
-argument to receive a human readable string"""
-STATUS.__name__ = 'STATUS'
-
-
-class NotmuchError(Exception, Python3StringMixIn):
- """Is initiated with a (notmuch.STATUS[, message=None]). It will not
- return an instance of the class NotmuchError, but a derived instance
- of a more specific Error Message, e.g. OutOfMemoryError. Each status
- but SUCCESS has a corresponding subclassed Exception."""
-
- @classmethod
- def get_exc_subclass(cls, status):
- """Returns a fine grained Exception() type,
- detailing the error status"""
- subclasses = {
- STATUS.OUT_OF_MEMORY: OutOfMemoryError,
- STATUS.READ_ONLY_DATABASE: ReadOnlyDatabaseError,
- STATUS.XAPIAN_EXCEPTION: XapianError,
- STATUS.FILE_ERROR: FileError,
- STATUS.FILE_NOT_EMAIL: FileNotEmailError,
- STATUS.DUPLICATE_MESSAGE_ID: DuplicateMessageIdError,
- STATUS.NULL_POINTER: NullPointerError,
- STATUS.TAG_TOO_LONG: TagTooLongError,
- STATUS.UNBALANCED_FREEZE_THAW: UnbalancedFreezeThawError,
- STATUS.UNBALANCED_ATOMIC: UnbalancedAtomicError,
- STATUS.NOT_INITIALIZED: NotInitializedError,
- }
- assert 0 < status <= len(subclasses)
- return subclasses[status]
-
- def __new__(cls, *args, **kwargs):
- """Return a correct subclass of NotmuchError if needed
-
- We return a NotmuchError instance if status is None (or 0) and a
- subclass that inherits from NotmuchError depending on the
- 'status' parameter otherwise."""
- # get 'status'. Passed in as arg or kwarg?
- status = args[0] if len(args) else kwargs.get('status', None)
- # no 'status' or cls is subclass already, return 'cls' instance
- if not status or cls != NotmuchError:
- return super(NotmuchError, cls).__new__(cls)
- subclass = cls.get_exc_subclass(status) # which class to use?
- return subclass.__new__(subclass, *args, **kwargs)
-
- def __init__(self, status=None, message=None):
- self.status = status
- self.message = message
-
- def __unicode__(self):
- if self.message is not None:
- return self.message
- elif self.status is not None:
- return STATUS.status2str(self.status)
- else:
- return 'Unknown error'
-
-
-# List of Subclassed exceptions that correspond to STATUS values and are
-# subclasses of NotmuchError.
-class OutOfMemoryError(NotmuchError):
- status = STATUS.OUT_OF_MEMORY
-
-
-class ReadOnlyDatabaseError(NotmuchError):
- status = STATUS.READ_ONLY_DATABASE
-
-
-class XapianError(NotmuchError):
- status = STATUS.XAPIAN_EXCEPTION
-
-
-class FileError(NotmuchError):
- status = STATUS.FILE_ERROR
-
-
-class FileNotEmailError(NotmuchError):
- status = STATUS.FILE_NOT_EMAIL
-
-
-class DuplicateMessageIdError(NotmuchError):
- status = STATUS.DUPLICATE_MESSAGE_ID
-
-
-class NullPointerError(NotmuchError):
- status = STATUS.NULL_POINTER
-
-
-class TagTooLongError(NotmuchError):
- status = STATUS.TAG_TOO_LONG
-
-
-class UnbalancedFreezeThawError(NotmuchError):
- status = STATUS.UNBALANCED_FREEZE_THAW
-
-
-class UnbalancedAtomicError(NotmuchError):
- status = STATUS.UNBALANCED_ATOMIC
-
-
-class NotInitializedError(NotmuchError):
- """Derived from NotmuchError, this occurs if the underlying data
- structure (e.g. database is not initialized (yet) or an iterator has
- been exhausted. You can test for NotmuchError with .status =
- STATUS.NOT_INITIALIZED"""
- status = STATUS.NOT_INITIALIZED
-
-
-def _str(value):
- """Ensure a nicely utf-8 encoded string to pass to libnotmuch
-
- C++ code expects strings to be well formatted and
- unicode strings to have no null bytes."""
- if not isinstance(value, basestring):
- raise TypeError("Expected str or unicode, got %s" % str(type(value)))
- if isinstance(value, unicode):
- return value.encode('UTF-8')
- return value
-
-
class NotmuchDatabaseS(Structure):
pass
NotmuchDatabaseP = POINTER(NotmuchDatabaseS)
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index d40a575..d1c1b58 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -14,256 +14,33 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see <http://www.gnu.org/licenses/>.
-Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
Jesse Rosenthal <jrosenthal@jhu.edu>
"""
from ctypes import c_char_p, c_long, c_uint, c_int
from datetime import date
-from notmuch.globals import (
- nmlib, STATUS, NotmuchError, Enum, _str, Python3StringMixIn,
- NotmuchTagsP, NotmuchMessagesP, NotmuchMessageP, NotmuchFilenamesP)
-from notmuch.tag import Tags
-from notmuch.filename import Filenames
-import sys
-import email
-try:
- import simplejson as json
-except ImportError:
- import json
-
-
-class Messages(object):
- """Represents a list of notmuch messages
-
- This object provides an iterator over a list of notmuch messages
- (Technically, it provides a wrapper for the underlying
- *notmuch_messages_t* structure). Do note that the underlying library
- only provides a one-time iterator (it cannot reset the iterator to
- the start). Thus iterating over the function will "exhaust" the list
- of messages, and a subsequent iteration attempt will raise a
- :exc:`NotmuchError` STATUS.NOT_INITIALIZED. If you need to
- re-iterate over a list of messages you will need to retrieve a new
- :class:`Messages` object or cache your :class:`Message`\s in a list
- via::
-
- msglist = list(msgs)
-
- You can store and reuse the single :class:`Message` objects as often
- as you want as long as you keep the parent :class:`Messages` object
- around. (Due to hierarchical memory allocation, all derived
- :class:`Message` objects will be invalid when we delete the parent
- :class:`Messages` object, even if it was already exhausted.) So
- this works::
-
- db = Database()
- msgs = Query(db,'').search_messages() #get a Messages() object
- msglist = list(msgs)
-
- # msgs is "exhausted" now and msgs.next() will raise an exception.
- # However it will be kept alive until all retrieved Message()
- # objects are also deleted. If you do e.g. an explicit del(msgs)
- # here, the following lines would fail.
-
- # You can reiterate over *msglist* however as often as you want.
- # It is simply a list with :class:`Message`s.
-
- print (msglist[0].get_filename())
- print (msglist[1].get_filename())
- print (msglist[0].get_message_id())
-
-
- As :class:`Message` implements both __hash__() and __cmp__(), it is
- possible to make sets out of :class:`Messages` and use set
- arithmetic (this happens in python and will of course be *much*
- slower than redoing a proper query with the appropriate filters::
-
- s1, s2 = set(msgs1), set(msgs2)
- s.union(s2)
- s1 -= s2
- ...
-
- Be careful when using set arithmetic between message sets derived
- from different Databases (ie the same database reopened after
- messages have changed). If messages have added or removed associated
- files in the meantime, it is possible that the same message would be
- considered as a different object (as it points to a different file).
- """
-
- #notmuch_messages_get
- _get = nmlib.notmuch_messages_get
- _get.argtypes = [NotmuchMessagesP]
- _get.restype = NotmuchMessageP
-
- _collect_tags = nmlib.notmuch_messages_collect_tags
- _collect_tags.argtypes = [NotmuchMessagesP]
- _collect_tags.restype = NotmuchTagsP
-
- def __init__(self, msgs_p, parent=None):
- """
- :param msgs_p: A pointer to an underlying *notmuch_messages_t*
- structure. These are not publically exposed, so a user
- will almost never instantiate a :class:`Messages` object
- herself. They are usually handed back as a result,
- e.g. in :meth:`Query.search_messages`. *msgs_p* must be
- valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
- :type msgs_p: :class:`ctypes.c_void_p`
- :param parent: The parent object
- (ie :class:`Query`) these tags are derived from. It saves
- a reference to it, so we can automatically delete the db
- object once all derived objects are dead.
- :TODO: Make the iterator work more than once and cache the tags in
- the Python object.(?)
- """
- if msgs_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
-
- self._msgs = msgs_p
- #store parent, so we keep them alive as long as self is alive
- self._parent = parent
-
- def collect_tags(self):
- """Return the unique :class:`Tags` in the contained messages
-
- :returns: :class:`Tags`
- :exceptions: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if not init'ed
-
- .. note::
-
- :meth:`collect_tags` will iterate over the messages and therefore
- will not allow further iterations.
- """
- if self._msgs is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
-
- # collect all tags (returns NULL on error)
- tags_p = Messages._collect_tags(self._msgs)
- #reset _msgs as we iterated over it and can do so only once
- self._msgs = None
-
- if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
- return Tags(tags_p, self)
-
- def __iter__(self):
- """ Make Messages an iterator """
- return self
-
- _valid = nmlib.notmuch_messages_valid
- _valid.argtypes = [NotmuchMessagesP]
- _valid.restype = bool
-
- _move_to_next = nmlib.notmuch_messages_move_to_next
- _move_to_next.argtypes = [NotmuchMessagesP]
- _move_to_next.restype = None
-
- def __next__(self):
- if self._msgs is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
-
- if not self._valid(self._msgs):
- self._msgs = None
- raise StopIteration
+from .globals import (
+ nmlib,
+ Enum,
+ _str,
+ Python3StringMixIn,
+ NotmuchTagsP,
+ NotmuchMessageP,
+ NotmuchMessagesP,
+ NotmuchFilenamesP,
+)
+from .errors import (
+ STATUS,
+ NotmuchError,
+ NullPointerError,
+ NotInitializedError,
+)
+from .tag import Tags
+from .filenames import Filenames
- msg = Message(Messages._get(self._msgs), self)
- self._move_to_next(self._msgs)
- return msg
- next = __next__ # python2.x iterator protocol compatibility
-
- def __nonzero__(self):
- """
- :return: True if there is at least one more thread in the
- Iterator, False if not."""
- return self._msgs is not None and \
- self._valid(self._msgs) > 0
-
- _destroy = nmlib.notmuch_messages_destroy
- _destroy.argtypes = [NotmuchMessagesP]
- _destroy.restype = None
-
- def __del__(self):
- """Close and free the notmuch Messages"""
- if self._msgs is not None:
- self._destroy(self._msgs)
-
- def format_messages(self, format, indent=0, entire_thread=False):
- """Formats messages as needed for 'notmuch show'.
-
- :param format: A string of either 'text' or 'json'.
- :param indent: A number indicating the reply depth of these messages.
- :param entire_thread: A bool, indicating whether we want to output
- whole threads or only the matching messages.
- :return: a list of lines
- """
- result = list()
-
- if format.lower() == "text":
- set_start = ""
- set_end = ""
- set_sep = ""
- elif format.lower() == "json":
- set_start = "["
- set_end = "]"
- set_sep = ", "
- else:
- raise TypeError("format must be either 'text' or 'json'")
-
- first_set = True
-
- result.append(set_start)
-
- # iterate through all toplevel messages in this thread
- for msg in self:
- # if not msg:
- # break
- if not first_set:
- result.append(set_sep)
- first_set = False
-
- result.append(set_start)
- match = msg.is_match()
- next_indent = indent
-
- if (match or entire_thread):
- if format.lower() == "text":
- result.append(msg.format_message_as_text(indent))
- else:
- result.append(msg.format_message_as_json(indent))
- next_indent = indent + 1
-
- # get replies and print them also out (if there are any)
- replies = msg.get_replies().format_messages(format, next_indent, entire_thread)
- if replies:
- result.append(set_sep)
- result.extend(replies)
-
- result.append(set_end)
- result.append(set_end)
-
- return result
-
- def print_messages(self, format, indent=0, entire_thread=False, handle=sys.stdout):
- """Outputs messages as needed for 'notmuch show' to a file like object.
-
- :param format: A string of either 'text' or 'json'.
- :param handle: A file like object to print to (default is sys.stdout).
- :param indent: A number indicating the reply depth of these messages.
- :param entire_thread: A bool, indicating whether we want to output
- whole threads or only the matching messages.
- """
- handle.write(''.join(self.format_messages(format, indent, entire_thread)))
-
-
-class EmptyMessagesResult(Messages):
- def __init__(self, parent):
- self._msgs = None
- self._parent = parent
-
- def __next__(self):
- raise StopIteration()
- next = __next__
+import email
class Message(Python3StringMixIn):
@@ -341,16 +118,16 @@ class Message(Python3StringMixIn):
def __init__(self, msg_p, parent=None):
"""
:param msg_p: A pointer to an internal notmuch_message_t
- Structure. If it is `None`, we will raise an :exc:`NotmuchError`
- STATUS.NULL_POINTER.
+ Structure. If it is `None`, we will raise an
+ :exc:`NullPointerError`.
:param parent: A 'parent' object is passed which this message is
derived from. We save a reference to it, so we can
automatically delete the parent object once all derived
objects are dead.
"""
- if msg_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ if not msg_p:
+ raise NullPointerError()
self._msg = msg_p
#keep reference to parent, so we keep it alive
self._parent = parent
@@ -359,11 +136,11 @@ class Message(Python3StringMixIn):
"""Returns the message ID
:returns: String with a message ID
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
return Message._get_message_id(self._msg).decode('utf-8', 'ignore')
def get_thread_id(self):
@@ -376,11 +153,11 @@ class Message(Python3StringMixIn):
message belongs to a single thread.
:returns: String with a thread ID
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
return Message._get_thread_id(self._msg).decode('utf-8', 'ignore')
@@ -399,15 +176,17 @@ class Message(Python3StringMixIn):
an empty Messages iterator.
:returns: :class:`Messages`.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
msgs_p = Message._get_replies(self._msg)
- if msgs_p is None:
+ from .messages import Messages, EmptyMessagesResult
+
+ if not msgs_p:
return EmptyMessagesResult(self)
return Messages(msgs_p, self)
@@ -421,11 +200,11 @@ class Message(Python3StringMixIn):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
return Message._get_date(self._msg)
def get_header(self, header):
@@ -441,30 +220,28 @@ class Message(Python3StringMixIn):
It is not case-sensitive.
:type header: str
:returns: The header value as string
- :exception: :exc:`NotmuchError`
-
- * STATUS.NOT_INITIALIZED if the message
- is not initialized.
- * STATUS.NULL_POINTER if any error occured.
+ :raises: :exc:`NotInitializedError` if the message is not
+ initialized
+ :raises: :exc:`NullPointerError` if any error occured
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
#Returns NULL if any error occurs.
header = Message._get_header(self._msg, _str(header))
if header == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
return header.decode('UTF-8', 'ignore')
def get_filename(self):
"""Returns the file path of the message file
:returns: Absolute file path & name of the message file
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
return Message._get_filename(self._msg).decode('utf-8', 'ignore')
def get_filenames(self):
@@ -473,12 +250,12 @@ class Message(Python3StringMixIn):
Returns a Filenames() generator with all absolute filepaths for
messages recorded to have the same Message-ID. These files must
not necessarily have identical content."""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
files_p = Message._get_filenames(self._msg)
- return Filenames(files_p, self).as_generator()
+ return Filenames(files_p, self)
def get_flag(self, flag):
"""Checks whether a specific flag is set for this message
@@ -490,11 +267,11 @@ class Message(Python3StringMixIn):
:param flag: One of the :attr:`Message.FLAG` values (currently only
*Message.FLAG.MATCH*
:returns: An unsigned int (0/1), indicating whether the flag is set.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
return Message._get_flag(self._msg, flag)
def set_flag(self, flag, value):
@@ -504,30 +281,27 @@ class Message(Python3StringMixIn):
*Message.FLAG.MATCH*
:param value: A bool indicating whether to set or unset the flag.
- :returns: Nothing
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
self._set_flag(self._msg, flag, value)
def get_tags(self):
"""Returns the message tags
:returns: A :class:`Tags` iterator.
- :exception: :exc:`NotmuchError`
-
- * STATUS.NOT_INITIALIZED if the message
- is not initialized.
- * STATUS.NULL_POINTER, on error
+ :raises: :exc:`NotInitializedError` if the message is not
+ initialized
+ :raises: :exc:`NullPointerError` if any error occured
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
tags_p = Message._get_tags(self._msg)
- if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ if not tags_p:
+ raise NullPointerError()
return Tags(tags_p, self)
_add_tag = nmlib.notmuch_message_add_tag
@@ -552,21 +326,16 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the tag was successfully added.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.NULL_POINTER
- The 'tag' argument is NULL
- STATUS.TAG_TOO_LONG
- The length of 'tag' is too long
- (exceeds Message.NOTMUCH_TAG_MAX)
- STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot be
- modified.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
- """
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ :raises: :exc:`NullPointerError` if the `tag` argument is NULL
+ :raises: :exc:`TagTooLongError` if the length of `tag` exceeds
+ Message.NOTMUCH_TAG_MAX)
+ :raises: :exc:`ReadOnlyDatabaseError` if the database was opened
+ in read-only mode so message cannot be modified
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
+ """
+ if not self._msg:
+ raise NotInitializedError()
status = self._add_tag(self._msg, _str(tag))
@@ -600,21 +369,16 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the tag was successfully removed or if
the message had no such tag.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.NULL_POINTER
- The 'tag' argument is NULL
- STATUS.TAG_TOO_LONG
- The length of 'tag' is too long
- (exceeds NOTMUCH_TAG_MAX)
- STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot
- be modified.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
+ :raises: :exc:`NullPointerError` if the `tag` argument is NULL
+ :raises: :exc:`TagTooLongError` if the length of `tag` exceeds
+ Message.NOTMUCH_TAG_MAX)
+ :raises: :exc:`ReadOnlyDatabaseError` if the database was opened
+ in read-only mode so message cannot be modified
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
status = self._remove_tag(self._msg, _str(tag))
# bail out on error
@@ -646,16 +410,13 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the tags were successfully removed.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot
- be modified.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
+ :raises: :exc:`ReadOnlyDatabaseError` if the database was opened
+ in read-only mode so message cannot be modified
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
status = self._remove_all_tags(self._msg)
@@ -704,16 +465,13 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the message was successfully frozen.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot
- be modified.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
+ :raises: :exc:`ReadOnlyDatabaseError` if the database was opened
+ in read-only mode so message cannot be modified
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
status = self._freeze(self._msg)
@@ -742,17 +500,15 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the message was successfully frozen.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.UNBALANCED_FREEZE_THAW
- An attempt was made to thaw an unfrozen message.
- That is, there have been an unbalanced number of calls
- to :meth:`freeze` and :meth:`thaw`.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
+ :raises: :exc:`UnbalancedFreezeThawError` if an attempt was made
+ to thaw an unfrozen message. That is, there have been
+ an unbalanced number of calls to :meth:`freeze` and
+ :meth:`thaw`.
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
"""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
status = self._thaw(self._msg)
@@ -787,8 +543,8 @@ class Message(Python3StringMixIn):
:returns: a :class:`STATUS` value. In short, you want to see
notmuch.STATUS.SUCCESS here. See there for details."""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
return Message._tags_to_maildir_flags(self._msg)
def maildir_flags_to_tags(self):
@@ -814,8 +570,8 @@ class Message(Python3StringMixIn):
:returns: a :class:`STATUS`. In short, you want to see
notmuch.STATUS.SUCCESS here. See there for details."""
- if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._msg:
+ raise NotInitializedError()
return Message._tags_to_maildir_flags(self._msg)
def __repr__(self):
@@ -850,114 +606,10 @@ class Message(Python3StringMixIn):
out_part = parts[(num - 1)]
return out_part.get_payload(decode=True)
- def format_message_internal(self):
- """Create an internal representation of the message parts,
- which can easily be output to json, text, or another output
- format. The argument match tells whether this matched a
- query."""
- output = {}
- output["id"] = self.get_message_id()
- output["match"] = self.is_match()
- output["filename"] = self.get_filename()
- output["tags"] = list(self.get_tags())
-
- headers = {}
- for h in ["Subject", "From", "To", "Cc", "Bcc", "Date"]:
- headers[h] = self.get_header(h)
- output["headers"] = headers
-
- body = []
- parts = self.get_message_parts()
- for i in xrange(len(parts)):
- msg = parts[i]
- part_dict = {}
- part_dict["id"] = i + 1
- # We'll be using this is a lot, so let's just get it once.
- cont_type = msg.get_content_type()
- part_dict["content-type"] = cont_type
- # NOTE:
- # Now we emulate the current behaviour, where it ignores
- # the html if there's a text representation.
- #
- # This is being worked on, but it will be easier to fix
- # here in the future than to end up with another
- # incompatible solution.
- disposition = msg["Content-Disposition"]
- if disposition and disposition.lower().startswith("attachment"):
- part_dict["filename"] = msg.get_filename()
- else:
- if cont_type.lower() == "text/plain":
- part_dict["content"] = msg.get_payload()
- elif (cont_type.lower() == "text/html" and
- i == 0):
- part_dict["content"] = msg.get_payload()
- body.append(part_dict)
-
- output["body"] = body
-
- return output
-
- def format_message_as_json(self, indent=0):
- """Outputs the message as json. This is essentially the same
- as python's dict format, but we run it through, just so we
- don't have to worry about the details."""
- return json.dumps(self.format_message_internal())
-
- def format_message_as_text(self, indent=0):
- """Outputs it in the old-fashioned notmuch text form. Will be
- easy to change to a new format when the format changes."""
-
- format = self.format_message_internal()
- output = "\fmessage{ id:%s depth:%d match:%d filename:%s" \
- % (format['id'], indent, format['match'], format['filename'])
- output += "\n\fheader{"
-
- #Todo: this date is supposed to be prettified, as in the index.
- output += "\n%s (%s) (" % (format["headers"]["From"],
- format["headers"]["Date"])
- output += ", ".join(format["tags"])
- output += ")"
-
- output += "\nSubject: %s" % format["headers"]["Subject"]
- output += "\nFrom: %s" % format["headers"]["From"]
- output += "\nTo: %s" % format["headers"]["To"]
- if format["headers"]["Cc"]:
- output += "\nCc: %s" % format["headers"]["Cc"]
- if format["headers"]["Bcc"]:
- output += "\nBcc: %s" % format["headers"]["Bcc"]
- output += "\nDate: %s" % format["headers"]["Date"]
- output += "\n\fheader}"
-
- output += "\n\fbody{"
-
- parts = format["body"]
- parts.sort(key=lambda x: x['id'])
- for p in parts:
- if not "filename" in p:
- output += "\n\fpart{ "
- output += "ID: %d, Content-type: %s\n" % (p["id"],
- p["content-type"])
- if "content" in p:
- output += "\n%s\n" % p["content"]
- else:
- output += "Non-text part: %s\n" % p["content-type"]
- output += "\n\fpart}"
- else:
- output += "\n\fattachment{ "
- output += "ID: %d, Content-type:%s\n" % (p["id"],
- p["content-type"])
- output += "Attachment: %s\n" % p["filename"]
- output += "\n\fattachment}\n"
-
- output += "\n\fbody}\n"
- output += "\n\fmessage}"
-
- return output
-
def __hash__(self):
"""Implement hash(), so we can use Message() sets"""
file = self.get_filename()
- if file is None:
+ if not file:
return None
return hash(file)
@@ -981,5 +633,5 @@ class Message(Python3StringMixIn):
def __del__(self):
"""Close and free the notmuch Message"""
- if self._msg is not None:
+ if self._msg:
self._destroy(self._msg)
diff --git a/bindings/python/notmuch/messages.py b/bindings/python/notmuch/messages.py
new file mode 100644
index 0000000..e83455b
--- /dev/null
+++ b/bindings/python/notmuch/messages.py
@@ -0,0 +1,282 @@
+"""
+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 <http://www.gnu.org/licenses/>.
+
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
+ Jesse Rosenthal <jrosenthal@jhu.edu>
+"""
+
+from .globals import (
+ nmlib,
+ NotmuchTagsP,
+ NotmuchMessageP,
+ NotmuchMessagesP,
+)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
+from .tag import Tags
+from .message import Message
+
+import sys
+
+class Messages(object):
+ """Represents a list of notmuch messages
+
+ This object provides an iterator over a list of notmuch messages
+ (Technically, it provides a wrapper for the underlying
+ *notmuch_messages_t* structure). Do note that the underlying library
+ only provides a one-time iterator (it cannot reset the iterator to
+ the start). Thus iterating over the function will "exhaust" the list
+ of messages, and a subsequent iteration attempt will raise a
+ :exc:`NotInitializedError`. If you need to
+ re-iterate over a list of messages you will need to retrieve a new
+ :class:`Messages` object or cache your :class:`Message`\s in a list
+ via::
+
+ msglist = list(msgs)
+
+ You can store and reuse the single :class:`Message` objects as often
+ as you want as long as you keep the parent :class:`Messages` object
+ around. (Due to hierarchical memory allocation, all derived
+ :class:`Message` objects will be invalid when we delete the parent
+ :class:`Messages` object, even if it was already exhausted.) So
+ this works::
+
+ db = Database()
+ msgs = Query(db,'').search_messages() #get a Messages() object
+ msglist = list(msgs)
+
+ # msgs is "exhausted" now and msgs.next() will raise an exception.
+ # However it will be kept alive until all retrieved Message()
+ # objects are also deleted. If you do e.g. an explicit del(msgs)
+ # here, the following lines would fail.
+
+ # You can reiterate over *msglist* however as often as you want.
+ # It is simply a list with :class:`Message`s.
+
+ print (msglist[0].get_filename())
+ print (msglist[1].get_filename())
+ print (msglist[0].get_message_id())
+
+
+ As :class:`Message` implements both __hash__() and __cmp__(), it is
+ possible to make sets out of :class:`Messages` and use set
+ arithmetic (this happens in python and will of course be *much*
+ slower than redoing a proper query with the appropriate filters::
+
+ s1, s2 = set(msgs1), set(msgs2)
+ s.union(s2)
+ s1 -= s2
+ ...
+
+ Be careful when using set arithmetic between message sets derived
+ from different Databases (ie the same database reopened after
+ messages have changed). If messages have added or removed associated
+ files in the meantime, it is possible that the same message would be
+ considered as a different object (as it points to a different file).
+ """
+
+ #notmuch_messages_get
+ _get = nmlib.notmuch_messages_get
+ _get.argtypes = [NotmuchMessagesP]
+ _get.restype = NotmuchMessageP
+
+ _collect_tags = nmlib.notmuch_messages_collect_tags
+ _collect_tags.argtypes = [NotmuchMessagesP]
+ _collect_tags.restype = NotmuchTagsP
+
+ def __init__(self, msgs_p, parent=None):
+ """
+ :param msgs_p: A pointer to an underlying *notmuch_messages_t*
+ structure. These are not publically exposed, so a user
+ will almost never instantiate a :class:`Messages` object
+ herself. They are usually handed back as a result,
+ e.g. in :meth:`Query.search_messages`. *msgs_p* must be
+ valid, we will raise an :exc:`NullPointerError` if it is
+ `None`.
+ :type msgs_p: :class:`ctypes.c_void_p`
+ :param parent: The parent object
+ (ie :class:`Query`) these tags are derived from. It saves
+ a reference to it, so we can automatically delete the db
+ object once all derived objects are dead.
+ :TODO: Make the iterator work more than once and cache the tags in
+ the Python object.(?)
+ """
+ if not msgs_p:
+ raise NullPointerError()
+
+ self._msgs = msgs_p
+ #store parent, so we keep them alive as long as self is alive
+ self._parent = parent
+
+ def collect_tags(self):
+ """Return the unique :class:`Tags` in the contained messages
+
+ :returns: :class:`Tags`
+ :exceptions: :exc:`NotInitializedError` if not init'ed
+
+ .. note::
+
+ :meth:`collect_tags` will iterate over the messages and therefore
+ will not allow further iterations.
+ """
+ if not self._msgs:
+ raise NotInitializedError()
+
+ # collect all tags (returns NULL on error)
+ tags_p = Messages._collect_tags(self._msgs)
+ #reset _msgs as we iterated over it and can do so only once
+ self._msgs = None
+
+ if not tags_p:
+ raise NullPointerError()
+ return Tags(tags_p, self)
+
+ def __iter__(self):
+ """ Make Messages an iterator """
+ return self
+
+ _valid = nmlib.notmuch_messages_valid
+ _valid.argtypes = [NotmuchMessagesP]
+ _valid.restype = bool
+
+ _move_to_next = nmlib.notmuch_messages_move_to_next
+ _move_to_next.argtypes = [NotmuchMessagesP]
+ _move_to_next.restype = None
+
+ def __next__(self):
+ if not self._msgs:
+ raise NotInitializedError()
+
+ if not self._valid(self._msgs):
+ self._msgs = None
+ raise StopIteration
+
+ msg = Message(Messages._get(self._msgs), self)
+ self._move_to_next(self._msgs)
+ return msg
+ next = __next__ # python2.x iterator protocol compatibility
+
+ def __nonzero__(self):
+ '''
+ Implement truth value testing. If __nonzero__ is not
+ implemented, the python runtime would fall back to `len(..) >
+ 0` thus exhausting the iterator.
+
+ :returns: True if the wrapped iterator has at least one more object
+ left.
+ '''
+ return self._msgs and self._valid(self._msgs)
+
+ _destroy = nmlib.notmuch_messages_destroy
+ _destroy.argtypes = [NotmuchMessagesP]
+ _destroy.restype = None
+
+ def __del__(self):
+ """Close and free the notmuch Messages"""
+ if self._msgs:
+ self._destroy(self._msgs)
+
+ def format_messages(self, format, indent=0, entire_thread=False):
+ """Formats messages as needed for 'notmuch show'.
+
+ :param format: A string of either 'text' or 'json'.
+ :param indent: A number indicating the reply depth of these messages.
+ :param entire_thread: A bool, indicating whether we want to output
+ whole threads or only the matching messages.
+ :return: a list of lines
+
+ .. deprecated:: 0.14
+ This code adds functionality at the python
+ level that is unlikely to be useful for
+ anyone. Furthermore the python bindings strive
+ to be a thin wrapper around libnotmuch, so
+ this code will be removed in notmuch 0.15.
+ """
+ result = list()
+
+ if format.lower() == "text":
+ set_start = ""
+ set_end = ""
+ set_sep = ""
+ elif format.lower() == "json":
+ set_start = "["
+ set_end = "]"
+ set_sep = ", "
+ else:
+ raise TypeError("format must be either 'text' or 'json'")
+
+ first_set = True
+
+ result.append(set_start)
+
+ # iterate through all toplevel messages in this thread
+ for msg in self:
+ # if not msg:
+ # break
+ if not first_set:
+ result.append(set_sep)
+ first_set = False
+
+ result.append(set_start)
+ match = msg.is_match()
+ next_indent = indent
+
+ if (match or entire_thread):
+ if format.lower() == "text":
+ result.append(msg.format_message_as_text(indent))
+ else:
+ result.append(msg.format_message_as_json(indent))
+ next_indent = indent + 1
+
+ # get replies and print them also out (if there are any)
+ replies = msg.get_replies().format_messages(format, next_indent, entire_thread)
+ if replies:
+ result.append(set_sep)
+ result.extend(replies)
+
+ result.append(set_end)
+ result.append(set_end)
+
+ return result
+
+ def print_messages(self, format, indent=0, entire_thread=False, handle=sys.stdout):
+ """Outputs messages as needed for 'notmuch show' to a file like object.
+
+ :param format: A string of either 'text' or 'json'.
+ :param handle: A file like object to print to (default is sys.stdout).
+ :param indent: A number indicating the reply depth of these messages.
+ :param entire_thread: A bool, indicating whether we want to output
+ whole threads or only the matching messages.
+
+ .. deprecated:: 0.14
+ This code adds functionality at the python
+ level that is unlikely to be useful for
+ anyone. Furthermore the python bindings strive
+ to be a thin wrapper around libnotmuch, so
+ this code will be removed in notmuch 0.15.
+ """
+ handle.write(''.join(self.format_messages(format, indent, entire_thread)))
+
+class EmptyMessagesResult(Messages):
+ def __init__(self, parent):
+ self._msgs = None
+ self._parent = parent
+
+ def __next__(self):
+ raise StopIteration()
+ next = __next__
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
new file mode 100644
index 0000000..4abba5b
--- /dev/null
+++ b/bindings/python/notmuch/query.py
@@ -0,0 +1,207 @@
+"""
+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 <http://www.gnu.org/licenses/>.
+
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
+"""
+
+from ctypes import c_char_p, c_uint
+from .globals import (
+ nmlib,
+ Enum,
+ _str,
+ NotmuchQueryP,
+ NotmuchThreadsP,
+ NotmuchDatabaseP,
+ NotmuchMessagesP,
+)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
+from .threads import Threads
+from .messages import Messages
+
+
+class Query(object):
+ """Represents a search query on an opened :class:`Database`.
+
+ A query selects and filters a subset of messages from the notmuch
+ database we derive from.
+
+ :class:`Query` provides an instance attribute :attr:`sort`, which
+ contains the sort order (if specified via :meth:`set_sort`) or
+ `None`.
+
+ Any function in this class may throw an :exc:`NotInitializedError`
+ in case the underlying query object was not set up correctly.
+
+ .. note:: Do remember that as soon as we tear down this object,
+ all underlying derived objects such as threads,
+ messages, tags etc will be freed by the underlying library
+ as well. Accessing these objects will lead to segfaults and
+ other unexpected behavior. See above for more details.
+ """
+ # constants
+ SORT = Enum(['OLDEST_FIRST', 'NEWEST_FIRST', 'MESSAGE_ID', 'UNSORTED'])
+ """Constants: Sort order in which to return results"""
+
+ def __init__(self, db, querystr):
+ """
+ :param db: An open database which we derive the Query from.
+ :type db: :class:`Database`
+ :param querystr: The query string for the message.
+ :type querystr: utf-8 encoded str or unicode
+ """
+ self._db = None
+ self._query = None
+ self.sort = None
+ self.create(db, querystr)
+
+ def _assert_query_is_initialized(self):
+ """Raises :exc:`NotInitializedError` if self._query is `None`"""
+ if not self._query:
+ raise NotInitializedError()
+
+ """notmuch_query_create"""
+ _create = nmlib.notmuch_query_create
+ _create.argtypes = [NotmuchDatabaseP, c_char_p]
+ _create.restype = NotmuchQueryP
+
+ def create(self, db, querystr):
+ """Creates a new query derived from a Database
+
+ This function is utilized by __init__() and usually does not need to
+ be called directly.
+
+ :param db: Database to create the query from.
+ :type db: :class:`Database`
+ :param querystr: The query string
+ :type querystr: utf-8 encoded str or unicode
+ :raises:
+ :exc:`NullPointerError` if the query creation failed
+ (e.g. too little memory).
+ :exc:`NotInitializedError` if the underlying db was not
+ intitialized.
+ """
+ db._assert_db_is_initialized()
+ # create reference to parent db to keep it alive
+ self._db = db
+ # create query, return None if too little mem available
+ query_p = Query._create(db.db_p, _str(querystr))
+ if not query_p:
+ raise NullPointerError
+ self._query = query_p
+
+ _set_sort = nmlib.notmuch_query_set_sort
+ _set_sort.argtypes = [NotmuchQueryP, c_uint]
+ _set_sort.argtypes = None
+
+ def set_sort(self, sort):
+ """Set the sort order future results will be delivered in
+
+ :param sort: Sort order (see :attr:`Query.SORT`)
+ """
+ self._assert_query_is_initialized()
+ self.sort = sort
+ self._set_sort(self._query, sort)
+
+ """notmuch_query_search_threads"""
+ _search_threads = nmlib.notmuch_query_search_threads
+ _search_threads.argtypes = [NotmuchQueryP]
+ _search_threads.restype = NotmuchThreadsP
+
+ def search_threads(self):
+ """Execute a query for threads
+
+ Execute a query for threads, returning a :class:`Threads` iterator.
+ The returned threads are owned by the query and as such, will only be
+ valid until the Query is deleted.
+
+ The method sets :attr:`Message.FLAG`\.MATCH for those messages that
+ match the query. The method :meth:`Message.get_flag` allows us
+ to get the value of this flag.
+
+ :returns: :class:`Threads`
+ :raises: :exc:`NullPointerError` if search_threads failed
+ """
+ self._assert_query_is_initialized()
+ threads_p = Query._search_threads(self._query)
+
+ if not threads_p:
+ raise NullPointerError
+ return Threads(threads_p, self)
+
+ """notmuch_query_search_messages"""
+ _search_messages = nmlib.notmuch_query_search_messages
+ _search_messages.argtypes = [NotmuchQueryP]
+ _search_messages.restype = NotmuchMessagesP
+
+ def search_messages(self):
+ """Filter messages according to the query and return
+ :class:`Messages` in the defined sort order
+
+ :returns: :class:`Messages`
+ :raises: :exc:`NullPointerError` if search_messages failed
+ """
+ self._assert_query_is_initialized()
+ msgs_p = Query._search_messages(self._query)
+
+ if not msgs_p:
+ raise NullPointerError
+ return Messages(msgs_p, self)
+
+ _count_messages = nmlib.notmuch_query_count_messages
+ _count_messages.argtypes = [NotmuchQueryP]
+ _count_messages.restype = c_uint
+
+ def count_messages(self):
+ '''
+ This function performs a search and returns Xapian's best
+ guess as to the number of matching messages.
+
+ :returns: the estimated number of messages matching this query
+ :rtype: int
+ '''
+ self._assert_query_is_initialized()
+ return Query._count_messages(self._query)
+
+ _count_threads = nmlib.notmuch_query_count_threads
+ _count_threads.argtypes = [NotmuchQueryP]
+ _count_threads.restype = c_uint
+
+ def count_threads(self):
+ '''
+ This function performs a search and returns the number of
+ unique thread IDs in the matching messages. This is the same
+ as number of threads matching a search.
+
+ Note that this is a significantly heavier operation than
+ meth:`Query.count_messages`.
+
+ :returns: the number of threads returned by this query
+ :rtype: int
+ '''
+ self._assert_query_is_initialized()
+ return Query._count_threads(self._query)
+
+ _destroy = nmlib.notmuch_query_destroy
+ _destroy.argtypes = [NotmuchQueryP]
+ _destroy.restype = None
+
+ def __del__(self):
+ """Close and free the Query"""
+ if self._query:
+ self._destroy(self._query)
diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
index ceb7244..1d52345 100644
--- a/bindings/python/notmuch/tag.py
+++ b/bindings/python/notmuch/tag.py
@@ -14,10 +14,18 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see <http://www.gnu.org/licenses/>.
-Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
"""
from ctypes import c_char_p
-from notmuch.globals import nmlib, STATUS, NotmuchError, NotmuchTagsP, _str, Python3StringMixIn
+from .globals import (
+ nmlib,
+ Python3StringMixIn,
+ NotmuchTagsP,
+)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
class Tags(Python3StringMixIn):
@@ -29,9 +37,9 @@ class Tags(Python3StringMixIn):
Do note that the underlying library only provides a one-time
iterator (it cannot reset the iterator to the start). Thus iterating
over the function will "exhaust" the list of tags, and a subsequent
- iteration attempt will raise a :exc:`NotmuchError`
- STATUS.NOT_INITIALIZED. Also note, that any function that uses
- iteration (nearly all) will also exhaust the tags. So both::
+ iteration attempt will raise a :exc:`NotInitializedError`.
+ Also note, that any function that uses iteration (nearly all) will
+ also exhaust the tags. So both::
for tag in tags: print tag
@@ -60,8 +68,8 @@ class Tags(Python3StringMixIn):
will almost never instantiate a :class:`Tags` object
herself. They are usually handed back as a result,
e.g. in :meth:`Database.get_all_tags`. *tags_p* must be
- valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
+ valid, we will raise an :exc:`NullPointerError` if it is
+ `None`.
:type tags_p: :class:`ctypes.c_void_p`
:param parent: The parent object (ie :class:`Database` or
:class:`Message` these tags are derived from, and saves a
@@ -70,8 +78,8 @@ class Tags(Python3StringMixIn):
:TODO: Make the iterator optionally work more than once by
cache the tags in the Python object(?)
"""
- if tags_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ if not tags_p:
+ raise NullPointerError()
self._tags = tags_p
#save reference to parent object so we keep it alive
@@ -90,8 +98,8 @@ class Tags(Python3StringMixIn):
_move_to_next.restype = None
def __next__(self):
- if self._tags is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._tags:
+ raise NotInitializedError()
if not self._valid(self._tags):
self._tags = None
raise StopIteration
@@ -101,15 +109,15 @@ class Tags(Python3StringMixIn):
next = __next__ # python2.x iterator protocol compatibility
def __nonzero__(self):
- """Implement bool(Tags) check that can be repeatedly used
+ '''
+ Implement truth value testing. If __nonzero__ is not
+ implemented, the python runtime would fall back to `len(..) >
+ 0` thus exhausting the iterator.
- If __nonzero__ is not implemented, "if Tags()"
- will implicitly call __len__, using up our iterator, so it is
- important that this function is defined.
-
- :returns: True if the Tags() iterator has at least one more Tag
- left."""
- return self._valid(self._tags) > 0
+ :returns: True if the wrapped iterator has at least one more object
+ left.
+ '''
+ return self._tags and self._valid(self._tags)
def __unicode__(self):
"""string representation of :class:`Tags`: a space separated list of tags
@@ -118,8 +126,8 @@ class Tags(Python3StringMixIn):
As this iterates over the tags, we will not be able to iterate over
them again (as in retrieve them)! If the tags have been exhausted
- already, this will raise a :exc:`NotmuchError`
- STATUS.NOT_INITIALIZED on subsequent attempts.
+ already, this will raise a :exc:`NotInitializedError`on subsequent
+ attempts.
"""
return " ".join(self)
@@ -129,5 +137,5 @@ class Tags(Python3StringMixIn):
def __del__(self):
"""Close and free the notmuch tags"""
- if self._tags is not None:
+ if self._tags:
self._destroy(self._tags)
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index e81ff1b..009cb2b 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -14,169 +14,24 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see <http://www.gnu.org/licenses/>.
-Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
"""
from ctypes import c_char_p, c_long, c_int
-from notmuch.globals import (nmlib, STATUS,
- NotmuchError, NotmuchThreadP, NotmuchThreadsP, NotmuchMessagesP,
- NotmuchTagsP, Python3StringMixIn)
-from notmuch.message import Messages
-from notmuch.tag import Tags
+from .globals import (
+ nmlib,
+ NotmuchThreadP,
+ NotmuchMessagesP,
+ NotmuchTagsP,
+)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
+from .messages import Messages
+from .tag import Tags
from datetime import date
-
-class Threads(Python3StringMixIn):
- """Represents a list of notmuch threads
-
- This object provides an iterator over a list of notmuch threads
- (Technically, it provides a wrapper for the underlying
- *notmuch_threads_t* structure). Do note that the underlying
- library only provides a one-time iterator (it cannot reset the
- iterator to the start). Thus iterating over the function will
- "exhaust" the list of threads, and a subsequent iteration attempt
- will raise a :exc:`NotmuchError` STATUS.NOT_INITIALIZED. Also
- note, that any function that uses iteration will also
- exhaust the messages. So both::
-
- for thread in threads: print thread
-
- as well as::
-
- number_of_msgs = len(threads)
-
- will "exhaust" the threads. If you need to re-iterate over a list of
- messages you will need to retrieve a new :class:`Threads` object.
-
- Things are not as bad as it seems though, you can store and reuse
- the single Thread objects as often as you want as long as you
- keep the parent Threads object around. (Recall that due to
- hierarchical memory allocation, all derived Threads objects will
- be invalid when we delete the parent Threads() object, even if it
- was already "exhausted".) So this works::
-
- db = Database()
- threads = Query(db,'').search_threads() #get a Threads() object
- threadlist = []
- for thread in threads:
- threadlist.append(thread)
-
- # threads is "exhausted" now and even len(threads) will raise an
- # exception.
- # However it will be kept around until all retrieved Thread() objects are
- # also deleted. If you did e.g. an explicit del(threads) here, the
- # following lines would fail.
-
- # You can reiterate over *threadlist* however as often as you want.
- # It is simply a list with Thread objects.
-
- print (threadlist[0].get_thread_id())
- print (threadlist[1].get_thread_id())
- print (threadlist[0].get_total_messages())
- """
-
- #notmuch_threads_get
- _get = nmlib.notmuch_threads_get
- _get.argtypes = [NotmuchThreadsP]
- _get.restype = NotmuchThreadP
-
- def __init__(self, threads_p, parent=None):
- """
- :param threads_p: A pointer to an underlying *notmuch_threads_t*
- structure. These are not publically exposed, so a user
- will almost never instantiate a :class:`Threads` object
- herself. They are usually handed back as a result,
- e.g. in :meth:`Query.search_threads`. *threads_p* must be
- valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
- :type threads_p: :class:`ctypes.c_void_p`
- :param parent: The parent object
- (ie :class:`Query`) these tags are derived from. It saves
- a reference to it, so we can automatically delete the db
- object once all derived objects are dead.
- :TODO: Make the iterator work more than once and cache the tags in
- the Python object.(?)
- """
- if threads_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
-
- self._threads = threads_p
- #store parent, so we keep them alive as long as self is alive
- self._parent = parent
-
- def __iter__(self):
- """ Make Threads an iterator """
- return self
-
- _valid = nmlib.notmuch_threads_valid
- _valid.argtypes = [NotmuchThreadsP]
- _valid.restype = bool
-
- _move_to_next = nmlib.notmuch_threads_move_to_next
- _move_to_next.argtypes = [NotmuchThreadsP]
- _move_to_next.restype = None
-
- def __next__(self):
- if self._threads is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
-
- if not self._valid(self._threads):
- self._threads = None
- raise StopIteration
-
- thread = Thread(Threads._get(self._threads), self)
- self._move_to_next(self._threads)
- return thread
- next = __next__ # python2.x iterator protocol compatibility
-
- def __len__(self):
- """len(:class:`Threads`) returns the number of contained Threads
-
- .. note:: As this iterates over the threads, we will not be able to
- iterate over them again! So this will fail::
-
- #THIS FAILS
- threads = Database().create_query('').search_threads()
- if len(threads) > 0: #this 'exhausts' threads
- # next line raises NotmuchError(STATUS.NOT_INITIALIZED)!!!
- for thread in threads: print thread
- """
- if self._threads is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
-
- i = 0
- # returns 'bool'. On out-of-memory it returns None
- while self._valid(self._threads):
- self._move_to_next(self._threads)
- i += 1
- # reset self._threads to mark as "exhausted"
- self._threads = None
- return i
-
- def __nonzero__(self):
- """Check if :class:`Threads` contains at least one more valid thread
-
- The existence of this function makes 'if Threads: foo' work, as
- that will implicitely call len() exhausting the iterator if
- __nonzero__ does not exist. This function makes `bool(Threads())`
- work repeatedly.
-
- :return: True if there is at least one more thread in the
- Iterator, False if not. None on a "Out-of-memory" error.
- """
- return self._threads is not None and \
- self._valid(self._threads) > 0
-
- _destroy = nmlib.notmuch_threads_destroy
- _destroy.argtypes = [NotmuchThreadsP]
- _destroy.argtypes = None
-
- def __del__(self):
- """Close and free the notmuch Threads"""
- if self._threads is not None:
- self._destroy(self._threads)
-
-
class Thread(object):
"""Represents a single message thread."""
@@ -220,16 +75,16 @@ class Thread(object):
will almost never instantiate a :class:`Thread` object
herself. They are usually handed back as a result,
e.g. when iterating through :class:`Threads`. *thread_p*
- must be valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
+ must be valid, we will raise an :exc:`NullPointerError`
+ if it is `None`.
:param parent: A 'parent' object is passed which this message is
derived from. We save a reference to it, so we can
automatically delete the parent object once all derived
objects are dead.
"""
- if thread_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ if not thread_p:
+ raise NullPointerError()
self._thread = thread_p
#keep reference to parent, so we keep it alive
self._parent = parent
@@ -241,11 +96,11 @@ class Thread(object):
for as long as the thread is valid.
:returns: String with a message ID
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
+ :raises: :exc:`NotInitializedError` if the thread
is not initialized.
"""
- if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._thread:
+ raise NotInitializedError()
return Thread._get_thread_id(self._thread).decode('utf-8', 'ignore')
_get_total_messages = nmlib.notmuch_thread_get_total_messages
@@ -258,11 +113,11 @@ class Thread(object):
:returns: The number of all messages in the database
belonging to this thread. Contrast with
:meth:`get_matched_messages`.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
+ :raises: :exc:`NotInitializedError` if the thread
is not initialized.
"""
- if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._thread:
+ raise NotInitializedError()
return self._get_total_messages(self._thread)
def get_toplevel_messages(self):
@@ -279,18 +134,16 @@ class Thread(object):
messages, etc.).
:returns: :class:`Messages`
- :exception: :exc:`NotmuchError`
-
- * STATUS.NOT_INITIALIZED if query is not inited
- * STATUS.NULL_POINTER if search_messages failed
+ :raises: :exc:`NotInitializedError` if query is not initialized
+ :raises: :exc:`NullPointerError` if search_messages failed
"""
- if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._thread:
+ raise NotInitializedError()
msgs_p = Thread._get_toplevel_messages(self._thread)
- if msgs_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ if not msgs_p:
+ raise NullPointerError()
return Messages(msgs_p, self)
@@ -304,11 +157,11 @@ class Thread(object):
:returns: The number of all messages belonging to this thread that
matched the :class:`Query`from which this thread was created.
Contrast with :meth:`get_total_messages`.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
+ :raises: :exc:`NotInitializedError` if the thread
is not initialized.
"""
- if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._thread:
+ raise NotInitializedError()
return self._get_matched_messages(self._thread)
def get_authors(self):
@@ -321,10 +174,10 @@ class Thread(object):
The returned string belongs to 'thread' and will only be valid for
as long as this Thread() is not deleted.
"""
- if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._thread:
+ raise NotInitializedError()
authors = Thread._get_authors(self._thread)
- if authors is None:
+ if not authors:
return None
return authors.decode('UTF-8', 'ignore')
@@ -334,10 +187,10 @@ class Thread(object):
The returned string belongs to 'thread' and will only be valid for
as long as this Thread() is not deleted.
"""
- if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._thread:
+ raise NotInitializedError()
subject = Thread._get_subject(self._thread)
- if subject is None:
+ if not subject:
return None
return subject.decode('UTF-8', 'ignore')
@@ -346,11 +199,11 @@ class Thread(object):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
- if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._thread:
+ raise NotInitializedError()
return Thread._get_newest_date(self._thread)
def get_oldest_date(self):
@@ -358,11 +211,11 @@ class Thread(object):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
- if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._thread:
+ raise NotInitializedError()
return Thread._get_oldest_date(self._thread)
def get_tags(self):
@@ -378,18 +231,15 @@ class Thread(object):
query from which it derived is explicitely deleted).
:returns: A :class:`Tags` iterator.
- :exception: :exc:`NotmuchError`
-
- * STATUS.NOT_INITIALIZED if the thread
- is not initialized.
- * STATUS.NULL_POINTER, on error
+ :raises: :exc:`NotInitializedError` if query is not initialized
+ :raises: :exc:`NullPointerError` if search_messages failed
"""
- if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ if not self._thread:
+ raise NotInitializedError()
tags_p = Thread._get_tags(self._thread)
- if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ if not tags_p:
+ raise NullPointerError()
return Tags(tags_p, self)
def __unicode__(self):
@@ -410,5 +260,5 @@ class Thread(object):
def __del__(self):
"""Close and free the notmuch Thread"""
- if self._thread is not None:
+ if self._thread:
self._destroy(self._thread)
diff --git a/bindings/python/notmuch/threads.py b/bindings/python/notmuch/threads.py
new file mode 100644
index 0000000..f8ca34a
--- /dev/null
+++ b/bindings/python/notmuch/threads.py
@@ -0,0 +1,177 @@
+"""
+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 <http://www.gnu.org/licenses/>.
+
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
+"""
+
+from .globals import (
+ nmlib,
+ Python3StringMixIn,
+ NotmuchThreadP,
+ NotmuchThreadsP,
+)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
+from .thread import Thread
+
+class Threads(Python3StringMixIn):
+ """Represents a list of notmuch threads
+
+ This object provides an iterator over a list of notmuch threads
+ (Technically, it provides a wrapper for the underlying
+ *notmuch_threads_t* structure). Do note that the underlying
+ library only provides a one-time iterator (it cannot reset the
+ iterator to the start). Thus iterating over the function will
+ "exhaust" the list of threads, and a subsequent iteration attempt
+ will raise a :exc:`NotInitializedError`. Also
+ note, that any function that uses iteration will also
+ exhaust the messages. So both::
+
+ for thread in threads: print thread
+
+ as well as::
+
+ number_of_msgs = len(threads)
+
+ will "exhaust" the threads. If you need to re-iterate over a list of
+ messages you will need to retrieve a new :class:`Threads` object.
+
+ Things are not as bad as it seems though, you can store and reuse
+ the single Thread objects as often as you want as long as you
+ keep the parent Threads object around. (Recall that due to
+ hierarchical memory allocation, all derived Threads objects will
+ be invalid when we delete the parent Threads() object, even if it
+ was already "exhausted".) So this works::
+
+ db = Database()
+ threads = Query(db,'').search_threads() #get a Threads() object
+ threadlist = []
+ for thread in threads:
+ threadlist.append(thread)
+
+ # threads is "exhausted" now and even len(threads) will raise an
+ # exception.
+ # However it will be kept around until all retrieved Thread() objects are
+ # also deleted. If you did e.g. an explicit del(threads) here, the
+ # following lines would fail.
+
+ # You can reiterate over *threadlist* however as often as you want.
+ # It is simply a list with Thread objects.
+
+ print (threadlist[0].get_thread_id())
+ print (threadlist[1].get_thread_id())
+ print (threadlist[0].get_total_messages())
+ """
+
+ #notmuch_threads_get
+ _get = nmlib.notmuch_threads_get
+ _get.argtypes = [NotmuchThreadsP]
+ _get.restype = NotmuchThreadP
+
+ def __init__(self, threads_p, parent=None):
+ """
+ :param threads_p: A pointer to an underlying *notmuch_threads_t*
+ structure. These are not publically exposed, so a user
+ will almost never instantiate a :class:`Threads` object
+ herself. They are usually handed back as a result,
+ e.g. in :meth:`Query.search_threads`. *threads_p* must be
+ valid, we will raise an :exc:`NullPointerError` if it is
+ `None`.
+ :type threads_p: :class:`ctypes.c_void_p`
+ :param parent: The parent object
+ (ie :class:`Query`) these tags are derived from. It saves
+ a reference to it, so we can automatically delete the db
+ object once all derived objects are dead.
+ :TODO: Make the iterator work more than once and cache the tags in
+ the Python object.(?)
+ """
+ if not threads_p:
+ raise NullPointerError()
+
+ self._threads = threads_p
+ #store parent, so we keep them alive as long as self is alive
+ self._parent = parent
+
+ def __iter__(self):
+ """ Make Threads an iterator """
+ return self
+
+ _valid = nmlib.notmuch_threads_valid
+ _valid.argtypes = [NotmuchThreadsP]
+ _valid.restype = bool
+
+ _move_to_next = nmlib.notmuch_threads_move_to_next
+ _move_to_next.argtypes = [NotmuchThreadsP]
+ _move_to_next.restype = None
+
+ def __next__(self):
+ if not self._threads:
+ raise NotInitializedError()
+
+ if not self._valid(self._threads):
+ self._threads = None
+ raise StopIteration
+
+ thread = Thread(Threads._get(self._threads), self)
+ self._move_to_next(self._threads)
+ return thread
+ next = __next__ # python2.x iterator protocol compatibility
+
+ def __len__(self):
+ """len(:class:`Threads`) returns the number of contained Threads
+
+ .. note:: As this iterates over the threads, we will not be able to
+ iterate over them again! So this will fail::
+
+ #THIS FAILS
+ threads = Database().create_query('').search_threads()
+ if len(threads) > 0: #this 'exhausts' threads
+ # next line raises :exc:`NotInitializedError`!!!
+ for thread in threads: print thread
+ """
+ if not self._threads:
+ raise NotInitializedError()
+
+ i = 0
+ # returns 'bool'. On out-of-memory it returns None
+ while self._valid(self._threads):
+ self._move_to_next(self._threads)
+ i += 1
+ # reset self._threads to mark as "exhausted"
+ self._threads = None
+ return i
+
+ def __nonzero__(self):
+ '''
+ Implement truth value testing. If __nonzero__ is not
+ implemented, the python runtime would fall back to `len(..) >
+ 0` thus exhausting the iterator.
+
+ :returns: True if the wrapped iterator has at least one more object
+ left.
+ '''
+ return self._threads and self._valid(self._threads)
+
+ _destroy = nmlib.notmuch_threads_destroy
+ _destroy.argtypes = [NotmuchThreadsP]
+ _destroy.restype = None
+
+ def __del__(self):
+ """Close and free the notmuch Threads"""
+ if self._threads:
+ self._destroy(self._threads)
diff --git a/bindings/python/notmuch/version.py b/bindings/python/notmuch/version.py
index 59c396f..90bcadb 100644
--- a/bindings/python/notmuch/version.py
+++ b/bindings/python/notmuch/version.py
@@ -1,2 +1,2 @@
# this file should be kept in sync with ../../../version
-__VERSION__ = '0.11'
+__VERSION__ = '0.13.2'
diff --git a/bindings/python/setup.py b/bindings/python/setup.py
index 2e58dab..f4c338e 100644
--- a/bindings/python/setup.py
+++ b/bindings/python/setup.py
@@ -1,14 +1,33 @@
#!/usr/bin/env python
+"""
+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 <http://www.gnu.org/licenses/>.
+
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
+"""
+
import os
-import re
from distutils.core import setup
# get the notmuch version number without importing the notmuch module
-version_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+version_file = os.path.join(os.path.dirname(__file__),
'notmuch', 'version.py')
exec(compile(open(version_file).read(), version_file, 'exec'))
-assert __VERSION__, 'Failed to read the notmuch binding version number'
+assert '__VERSION__' in globals(), \
+ 'Failed to read the notmuch binding version number'
setup(name='notmuch',
version=__VERSION__,
@@ -16,32 +35,20 @@ setup(name='notmuch',
author='Sebastian Spaeth',
author_email='Sebastian@SSpaeth.de',
url='http://notmuchmail.org/',
- download_url='http://notmuchmail.org/releases/notmuch-'+__VERSION__+'.tar.gz',
+ download_url='http://notmuchmail.org/releases/notmuch-%s.tar.gz' % __VERSION__,
packages=['notmuch'],
- keywords = ["library", "email"],
- long_description="""Overview
-==============
-
-The notmuch module provides an interface to the `notmuch <http://notmuchmail.org>`_ functionality, directly interfacing with a shared notmuch library. Notmuch provides a maildatabase that allows for extremely quick searching and filtering of your email according to various criteria.
-
-The documentation for the latest cnotmuch release can be `viewed online <http://packages.python.org/notmuch>`_.
-
-The classes notmuch.Database, notmuch.Query provide most of the core functionality, returning notmuch.Messages and notmuch.Tags.
-
-Installation and Deinstallation
--------------------------------
-
-notmuch is included in the upstream notmuch source repository and it is
-packaged on http://pypi.python.org. This means you can do "easy_install
-notmuch" (or using pip) on your linux box and it will get installed
-into:
+ keywords=['library', 'email'],
+ long_description='''Overview
+========
-/usr/local/lib/python2.x/dist-packages/
+The notmuch module provides an interface to the `notmuch
+<http://notmuchmail.org>`_ functionality, directly interfacing with a
+shared notmuch library. Notmuch provides a maildatabase that allows
+for extremely quick searching and filtering of your email according to
+various criteria.
-For uninstalling, you will need to remove the "notmuch-0.x-py2.x.egg"
-directory and delete one entry refering to cnotmuch in the
-"easy-install.pth" file in that directory. There should be no trace
-left of cnotmuch then.
+The documentation for the latest notmuch release can be `viewed
+online <http://notmuch.readthedocs.org/>`_.
Requirements
------------
@@ -49,7 +56,7 @@ Requirements
You need to have notmuch installed (or rather libnotmuch.so.1). Also,
notmuch makes use of the ctypes library, and has only been tested with
python >= 2.5. It will not work on earlier python versions.
-""",
+''',
classifiers=['Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License (GPL)',
diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index 982fd59..e84f726 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -42,6 +42,8 @@ notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE self)
int create, mode;
VALUE pathv, hashv;
VALUE modev;
+ notmuch_database_t *database;
+ notmuch_status_t ret;
/* Check arguments */
rb_scan_args (argc, argv, "11", &pathv, &hashv);
@@ -73,9 +75,13 @@ notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE self)
}
Check_Type (self, T_DATA);
- DATA_PTR (self) = create ? notmuch_database_create (path) : notmuch_database_open (path, mode);
- if (!DATA_PTR (self))
- rb_raise (notmuch_rb_eDatabaseError, "Failed to open database");
+ if (create)
+ ret = notmuch_database_create (path, &database);
+ else
+ ret = notmuch_database_open (path, mode, &database);
+ notmuch_rb_status_raise (ret);
+
+ DATA_PTR (self) = database;
return self;
}
@@ -110,7 +116,7 @@ notmuch_rb_database_close (VALUE self)
notmuch_database_t *db;
Data_Get_Notmuch_Database (self, db);
- notmuch_database_close (db);
+ notmuch_database_destroy (db);
DATA_PTR (self) = NULL;
return Qnil;
@@ -246,6 +252,7 @@ VALUE
notmuch_rb_database_get_directory (VALUE self, VALUE pathv)
{
const char *path;
+ notmuch_status_t ret;
notmuch_directory_t *dir;
notmuch_database_t *db;
@@ -254,11 +261,11 @@ notmuch_rb_database_get_directory (VALUE self, VALUE pathv)
SafeStringValue (pathv);
path = RSTRING_PTR (pathv);
- dir = notmuch_database_get_directory (db, path);
- if (!dir)
- rb_raise (notmuch_rb_eXapianError, "Xapian exception");
-
- return Data_Wrap_Struct (notmuch_rb_cDirectory, NULL, NULL, dir);
+ ret = notmuch_database_get_directory (db, path, &dir);
+ notmuch_rb_status_raise (ret);
+ if (dir)
+ return Data_Wrap_Struct (notmuch_rb_cDirectory, NULL, NULL, dir);
+ return Qnil;
}
/*
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 81f652f..fe81b3f 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -1,6 +1,6 @@
/* The Ruby interface to the notmuch mail library
*
- * Copyright © 2010, 2011 Ali Polatel
+ * Copyright © 2010, 2011, 2012 Ali Polatel
*
* 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
@@ -24,31 +24,31 @@
#include <notmuch.h>
#include <ruby.h>
-VALUE notmuch_rb_cDatabase;
-VALUE notmuch_rb_cDirectory;
-VALUE notmuch_rb_cFileNames;
-VALUE notmuch_rb_cQuery;
-VALUE notmuch_rb_cThreads;
-VALUE notmuch_rb_cThread;
-VALUE notmuch_rb_cMessages;
-VALUE notmuch_rb_cMessage;
-VALUE notmuch_rb_cTags;
-
-VALUE notmuch_rb_eBaseError;
-VALUE notmuch_rb_eDatabaseError;
-VALUE notmuch_rb_eMemoryError;
-VALUE notmuch_rb_eReadOnlyError;
-VALUE notmuch_rb_eXapianError;
-VALUE notmuch_rb_eFileError;
-VALUE notmuch_rb_eFileNotEmailError;
-VALUE notmuch_rb_eNullPointerError;
-VALUE notmuch_rb_eTagTooLongError;
-VALUE notmuch_rb_eUnbalancedFreezeThawError;
-VALUE notmuch_rb_eUnbalancedAtomicError;
-
-ID ID_call;
-ID ID_db_create;
-ID ID_db_mode;
+extern VALUE notmuch_rb_cDatabase;
+extern VALUE notmuch_rb_cDirectory;
+extern VALUE notmuch_rb_cFileNames;
+extern VALUE notmuch_rb_cQuery;
+extern VALUE notmuch_rb_cThreads;
+extern VALUE notmuch_rb_cThread;
+extern VALUE notmuch_rb_cMessages;
+extern VALUE notmuch_rb_cMessage;
+extern VALUE notmuch_rb_cTags;
+
+extern VALUE notmuch_rb_eBaseError;
+extern VALUE notmuch_rb_eDatabaseError;
+extern VALUE notmuch_rb_eMemoryError;
+extern VALUE notmuch_rb_eReadOnlyError;
+extern VALUE notmuch_rb_eXapianError;
+extern VALUE notmuch_rb_eFileError;
+extern VALUE notmuch_rb_eFileNotEmailError;
+extern VALUE notmuch_rb_eNullPointerError;
+extern VALUE notmuch_rb_eTagTooLongError;
+extern VALUE notmuch_rb_eUnbalancedFreezeThawError;
+extern VALUE notmuch_rb_eUnbalancedAtomicError;
+
+extern ID ID_call;
+extern ID ID_db_create;
+extern ID ID_db_mode;
/* RSTRING_PTR() is new in ruby-1.9 */
#if !defined(RSTRING_PTR)
@@ -217,11 +217,20 @@ VALUE
notmuch_rb_query_get_string (VALUE self);
VALUE
+notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv);
+
+VALUE
+notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv);
+
+VALUE
notmuch_rb_query_search_threads (VALUE self);
VALUE
notmuch_rb_query_search_messages (VALUE self);
+VALUE
+notmuch_rb_query_count_messages (VALUE self);
+
/* threads.c */
VALUE
notmuch_rb_threads_destroy (VALUE self);
diff --git a/bindings/ruby/extconf.rb b/bindings/ruby/extconf.rb
index ccac609..7b9750f 100644
--- a/bindings/ruby/extconf.rb
+++ b/bindings/ruby/extconf.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
# coding: utf-8
-# Copyright 2010, 2011 Ali Polatel <alip@exherbo.org>
+# Copyright 2010, 2011, 2012 Ali Polatel <alip@exherbo.org>
# Distributed under the terms of the GNU General Public License v3
require 'mkmf'
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 4405f19..f4931d3 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -1,6 +1,6 @@
/* The Ruby interface to the notmuch mail library
*
- * Copyright © 2010, 2011 Ali Polatel
+ * Copyright © 2010, 2011, 2012 Ali Polatel
*
* 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
@@ -20,6 +20,32 @@
#include "defs.h"
+VALUE notmuch_rb_cDatabase;
+VALUE notmuch_rb_cDirectory;
+VALUE notmuch_rb_cFileNames;
+VALUE notmuch_rb_cQuery;
+VALUE notmuch_rb_cThreads;
+VALUE notmuch_rb_cThread;
+VALUE notmuch_rb_cMessages;
+VALUE notmuch_rb_cMessage;
+VALUE notmuch_rb_cTags;
+
+VALUE notmuch_rb_eBaseError;
+VALUE notmuch_rb_eDatabaseError;
+VALUE notmuch_rb_eMemoryError;
+VALUE notmuch_rb_eReadOnlyError;
+VALUE notmuch_rb_eXapianError;
+VALUE notmuch_rb_eFileError;
+VALUE notmuch_rb_eFileNotEmailError;
+VALUE notmuch_rb_eNullPointerError;
+VALUE notmuch_rb_eTagTooLongError;
+VALUE notmuch_rb_eUnbalancedFreezeThawError;
+VALUE notmuch_rb_eUnbalancedAtomicError;
+
+ID ID_call;
+ID ID_db_create;
+ID ID_db_mode;
+
/*
* Document-module: Notmuch
*
@@ -96,6 +122,12 @@ Init_notmuch (void)
*/
rb_define_const (mod, "MESSAGE_FLAG_MATCH", INT2FIX (NOTMUCH_MESSAGE_FLAG_MATCH));
/*
+ * Document-const: Notmuch::MESSAGE_FLAG_EXCLUDED
+ *
+ * Message flag "excluded"
+ */
+ rb_define_const (mod, "MESSAGE_FLAG_EXCLUDED", INT2FIX (NOTMUCH_MESSAGE_FLAG_EXCLUDED));
+ /*
* Document-const: Notmuch::TAG_MAX
*
* Maximum allowed length of a tag
@@ -234,8 +266,11 @@ Init_notmuch (void)
rb_define_method (notmuch_rb_cQuery, "sort", notmuch_rb_query_get_sort, 0); /* in query.c */
rb_define_method (notmuch_rb_cQuery, "sort=", notmuch_rb_query_set_sort, 1); /* in query.c */
rb_define_method (notmuch_rb_cQuery, "to_s", notmuch_rb_query_get_string, 0); /* in query.c */
+ rb_define_method (notmuch_rb_cQuery, "add_tag_exclude", notmuch_rb_query_add_tag_exclude, 1); /* in query.c */
+ rb_define_method (notmuch_rb_cQuery, "omit_excluded=", notmuch_rb_query_set_omit_excluded, 1); /* in query.c */
rb_define_method (notmuch_rb_cQuery, "search_threads", notmuch_rb_query_search_threads, 0); /* in query.c */
rb_define_method (notmuch_rb_cQuery, "search_messages", notmuch_rb_query_search_messages, 0); /* in query.c */
+ rb_define_method (notmuch_rb_cQuery, "count_messages", notmuch_rb_query_count_messages, 0); /* in query.c */
/*
* Document-class: Notmuch::Threads
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 74fd585..e5ba1b7 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -1,6 +1,6 @@
/* The Ruby interface to the notmuch mail library
*
- * Copyright © 2010, 2011 Ali Polatel
+ * Copyright © 2010, 2011, 2012 Ali Polatel
*
* 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
@@ -89,6 +89,42 @@ notmuch_rb_query_get_string (VALUE self)
}
/*
+ * call-seq: QUERY.add_tag_exclude(tag) => nil
+ *
+ * Add a tag that will be excluded from the query results by default.
+ */
+VALUE
+notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv)
+{
+ notmuch_query_t *query;
+ const char *tag;
+
+ Data_Get_Notmuch_Query (self, query);
+ tag = RSTRING_PTR(tagv);
+
+ notmuch_query_add_tag_exclude(query, tag);
+ return Qnil;
+}
+
+/*
+ * call-seq: QUERY.omit_excluded=(boolean) => nil
+ *
+ * Specify whether to omit excluded results or simply flag them.
+ * By default, this is set to +true+.
+ */
+VALUE
+notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv)
+{
+ notmuch_query_t *query;
+
+ Data_Get_Notmuch_Query (self, query);
+
+ notmuch_query_set_omit_excluded (query, RTEST (omitv));
+
+ return Qnil;
+}
+
+/*
* call-seq: QUERY.search_threads => THREADS
*
* Search for threads
@@ -127,3 +163,22 @@ notmuch_rb_query_search_messages (VALUE self)
return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
}
+
+/*
+ * call-seq: QUERY.count_messages => Fixnum
+ *
+ * Return an estimate of the number of messages matching a search
+ */
+VALUE
+notmuch_rb_query_count_messages (VALUE self)
+{
+ notmuch_query_t *query;
+
+ Data_Get_Notmuch_Query (self, query);
+
+ /* Xapian exceptions are not handled properly.
+ * (function may return 0 after printing a message)
+ * Thus there is nothing we can do here...
+ */
+ return UINT2FIX(notmuch_query_count_messages(query));
+}
diff --git a/command-line-arguments.c b/command-line-arguments.c
index e711414..b0a0dab 100644
--- a/command-line-arguments.c
+++ b/command-line-arguments.c
@@ -11,10 +11,15 @@
*/
static notmuch_bool_t
-_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {
+_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
const notmuch_keyword_t *keywords = arg_desc->keywords;
+ if (next == 0) {
+ /* No keyword given */
+ arg_str = "";
+ }
+
while (keywords->name) {
if (strcmp (arg_str, keywords->name) == 0) {
if (arg_desc->output_var) {
@@ -24,7 +29,28 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {
}
keywords++;
}
- fprintf (stderr, "unknown keyword: %s\n", arg_str);
+ if (next != 0)
+ fprintf (stderr, "unknown keyword: %s\n", arg_str);
+ else
+ fprintf (stderr, "option %s needs a keyword\n", arg_desc->name);
+ return FALSE;
+}
+
+static notmuch_bool_t
+_process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
+
+ if (next == 0) {
+ *((notmuch_bool_t *)arg_desc->output_var) = TRUE;
+ return TRUE;
+ }
+ if (strcmp (arg_str, "false") == 0) {
+ *((notmuch_bool_t *)arg_desc->output_var) = FALSE;
+ return TRUE;
+ }
+ if (strcmp (arg_str, "true") == 0) {
+ *((notmuch_bool_t *)arg_desc->output_var) = TRUE;
+ return TRUE;
+ }
return FALSE;
}
@@ -76,14 +102,16 @@ parse_option (const char *arg,
char *endptr;
/* Everything but boolean arguments (switches) needs a
- * delimiter, and a non-zero length value
+ * delimiter, and a non-zero length value. Boolean
+ * arguments may take an optional =true or =false value.
*/
-
- if (try->opt_type != NOTMUCH_OPT_BOOLEAN) {
- if (next != '=' && next != ':') return FALSE;
- if (value[0] == 0) return FALSE;
+ if (next != '=' && next != ':' && next != 0) return FALSE;
+ if (next == 0) {
+ if (try->opt_type != NOTMUCH_OPT_BOOLEAN &&
+ try->opt_type != NOTMUCH_OPT_KEYWORD)
+ return FALSE;
} else {
- if (next != 0) return FALSE;
+ if (value[0] == 0) return FALSE;
}
if (try->output_var == NULL)
@@ -91,11 +119,10 @@ parse_option (const char *arg,
switch (try->opt_type) {
case NOTMUCH_OPT_KEYWORD:
- return _process_keyword_arg (try, value);
+ return _process_keyword_arg (try, next, value);
break;
case NOTMUCH_OPT_BOOLEAN:
- *((notmuch_bool_t *)try->output_var) = TRUE;
- return TRUE;
+ return _process_boolean_arg (try, next, value);
break;
case NOTMUCH_OPT_INT:
*((int *)try->output_var) = strtol (value, &endptr, 10);
diff --git a/compat/Makefile.local b/compat/Makefile.local
index 504eb71..13f16cd 100644
--- a/compat/Makefile.local
+++ b/compat/Makefile.local
@@ -12,3 +12,5 @@ endif
ifneq ($(HAVE_STRCASESTR),1)
notmuch_compat_srcs += $(dir)/strcasestr.c
endif
+
+SRCS := $(SRCS) $(notmuch_compat_srcs)
diff --git a/compat/compat.h b/compat/compat.h
index 7767fe8..b2e2736 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -46,6 +46,14 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp);
char* strcasestr(const char *haystack, const char *needle);
#endif /* !HAVE_STRCASESTR */
+/* Silence gcc warnings about unused results. These warnings exist
+ * for a reason; any use of this needs to be justified. */
+#ifdef __GNUC__
+#define IGNORE_RESULT(x) ({ __typeof__(x) __z = (x); (void)(__z = __z); })
+#else /* !__GNUC__ */
+#define IGNORE_RESULT(x) x
+#endif /* __GNUC__ */
+
#ifdef __cplusplus
}
#endif
diff --git a/configure b/configure
index e90b76f..dc0dba4 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,22 @@
#! /bin/sh
+# Test whether this shell is capable of parameter substring processing.
+( option='a/b'; : ${option#*/} ) 2>/dev/null || {
+ echo "
+The shell interpreting '$0' is lacking some required features.
+
+To work around this problem you may try to execute:
+
+ ksh $0 $*
+ or
+ bash $0 $*
+"
+ exit 1
+}
+
+# Store original IFS value so it can be changed (and restored) in many places.
+readonly DEFAULT_IFS="$IFS"
+
srcdir=$(dirname "$0")
# For a non-srcdir configure invocation (such as ../configure), create
@@ -45,6 +62,16 @@ WITH_EMACS=1
WITH_BASH=1
WITH_ZSH=1
+# Compatible GMime versions (with constraints).
+# If using GMime 2.6, we need to have a version >= 2.6.5 to avoid a
+# crypto bug. We need 2.6.7 for permissive "From " header handling.
+GMIME_24_VERSION_CTR=''
+GMIME_24_VERSION="gmime-2.4 $GMIME_24_VERSION_CTR"
+GMIME_26_VERSION_CTR='>= 2.6.7'
+GMIME_26_VERSION="gmime-2.6 $GMIME_26_VERSION_CTR"
+
+WITH_GMIME_VERSIONS="$GMIME_26_VERSION;$GMIME_24_VERSION"
+
usage ()
{
cat <<EOF
@@ -101,6 +128,10 @@ Fine tuning of some installation directories is available:
--bashcompletiondir=DIR Bash completions files [SYSCONFDIR/bash_completion.d]
--zshcompletiondir=DIR Zsh completions files [PREFIX/share/zsh/functions/Completion/Unix]
+Some specific library versions can be specified (auto-detected otherwise):
+
+ --with-gmime-version=VERS Specify GMIME version (2.4 or 2.6)
+
Some features can be disabled (--with-feature=no is equivalent to
--without-feature) :
@@ -170,38 +201,16 @@ for option; do
fi
elif [ "${option}" = '--without-zsh-completion' ] ; then
WITH_ZSH=0
+ elif [ "${option%%=*}" = '--with-gmime-version' ] ; then
+ if [ "${option#*=}" = '2.4' ]; then
+ WITH_GMIME_VERSIONS=$GMIME_24_VERSION
+ elif [ "${option#*=}" = '2.6' ]; then
+ WITH_GMIME_VERSIONS=$GMIME_26_VERSION
+ fi
elif [ "${option%%=*}" = '--build' ] ; then
- build_option="${option#*=}"
- case ${build_option} in
- *-*-*) ;;
- *)
- echo "Unrecognized value for --build option: ${build_option}"
- echo "Should be: <cpu>-<vendor>-<os>"
- echo "See:"
- echo " $0 --help"
- echo ""
- exit 1
- esac
- build_cpu=${build_option%%-*}
- build_option=${build_option#*-}
- build_vendor=${build_option%%-*}
- build_os=${build_option#*-}
+ true
elif [ "${option%%=*}" = '--host' ] ; then
- host_option="${option#*=}"
- case ${host_option} in
- *-*-*) ;;
- *)
- echo "Unrecognized value for --host option: ${host_option}"
- echo "Should be: <cpu>-<vendor>-<os>"
- echo "See:"
- echo " $0 --help"
- echo ""
- exit 1
- esac
- host_cpu=${host_option%%-*}
- host_option=${host_option#*-}
- host_vendor=${host_option%%-*}
- host_os=${host_option#*-}
+ true
elif [ "${option%%=*}" = '--infodir' ] ; then
true
elif [ "${option%%=*}" = '--datadir' ] ; then
@@ -275,24 +284,27 @@ fi
printf "Checking for GMime development files... "
have_gmime=0
-for gmimepc in gmime-2.6 gmime-2.4; do
+IFS=';'
+for gmimepc in $WITH_GMIME_VERSIONS; do
if pkg-config --exists $gmimepc; then
printf "Yes ($gmimepc).\n"
have_gmime=1
gmime_cflags=$(pkg-config --cflags $gmimepc)
gmime_ldflags=$(pkg-config --libs $gmimepc)
+ break
fi
done
+IFS=$DEFAULT_IFS
if [ "$have_gmime" = "0" ]; then
printf "No.\n"
errors=$((errors + 1))
fi
# GMime already depends on Glib >= 2.12, but we use at least one Glib
-# function that only exists as of 2.14, (g_hash_table_get_keys)
-printf "Checking for Glib development files (>= 2.14)... "
+# function that only exists as of 2.22, (g_array_unref)
+printf "Checking for Glib development files (>= 2.22)... "
have_glib=0
-if pkg-config --exists 'glib-2.0 >= 2.14'; then
+if pkg-config --exists 'glib-2.0 >= 2.22'; then
printf "Yes.\n"
have_glib=1
glib_cflags=$(pkg-config --cflags glib-2.0)
@@ -362,9 +374,9 @@ elif [ $uname = "SunOS" ] ; then
printf "Solaris.\n"
platform=SOLARIS
linker_resolves_library_dependencies=0
-elif [ $uname = "Linux" ] ; then
- printf "Linux\n"
- platform=LINUX
+elif [ $uname = "Linux" ] || [ $uname = "GNU" ] ; then
+ printf "$uname\n"
+ platform="$uname"
linker_resolves_library_dependencies=1
printf "Checking for $libdir_expanded in ldconfig... "
@@ -376,7 +388,6 @@ elif [ $uname = "Linux" ] ; then
# IFS=$(printf '\n')
#
# because the shell's command substitution deletes any trailing newlines.
- OLD_IFS=$IFS
IFS="
"
for path in $ldconfig_paths; do
@@ -384,7 +395,7 @@ elif [ $uname = "Linux" ] ; then
libdir_in_ldconfig=1
fi
done
- IFS=$OLD_IFS
+ IFS=$DEFAULT_IFS
if [ "$libdir_in_ldconfig" = '0' ]; then
printf "No (will set RPATH)\n"
else
@@ -412,26 +423,29 @@ EOF
echo " http://xapian.org/"
fi
if [ $have_gmime -eq 0 ]; then
- echo " GMime 2.4 library (including development files such as headers)"
+ echo " Either GMime 2.4 library" $GMIME_24_VERSION_CTR "or GMime 2.6 library" $GMIME_26_VERSION_CTR
+ echo " (including development files such as headers)"
echo " http://spruce.sourceforge.net/gmime/"
+ echo
fi
if [ $have_glib -eq 0 ]; then
- echo " Glib library >= 2.14 (including development files such as headers)"
+ echo " Glib library >= 2.22 (including development files such as headers)"
echo " http://ftp.gnome.org/pub/gnome/sources/glib/"
+ echo
fi
if [ $have_talloc -eq 0 ]; then
echo " The talloc library (including development files such as headers)"
echo " http://talloc.samba.org/"
+ echo
fi
cat <<EOF
-
With any luck, you're using a modern, package-based operating system
that has all of these packages available in the distribution. In that
case a simple command will install everything you need. For example:
On Debian and similar systems:
- sudo apt-get install libxapian-dev libgmime-2.4-dev libtalloc-dev
+ sudo apt-get install libxapian-dev libgmime-2.6-dev libtalloc-dev
Or on Fedora and similar systems:
@@ -533,7 +547,7 @@ done
printf "\n\t${WARN_CFLAGS}\n"
rm -f minimal minimal.c
-
+
cat <<EOF
All required packages were found. You may now run the following
diff --git a/contrib/nmbug b/contrib/nmbug/nmbug
index bb0739f..f003ef9 100755
--- a/contrib/nmbug
+++ b/contrib/nmbug/nmbug
@@ -60,6 +60,9 @@ sub git_pipe {
sub git {
my $fh = git_pipe (@_);
my $str = join ('', <$fh>);
+ unless (close $fh) {
+ die "'git @_' exited with nonzero value\n";
+ }
chomp($str);
return $str;
}
@@ -84,7 +87,7 @@ sub spawn {
foreach my $line (@{$ioref}) {
print $fh $line, "\n";
}
- exit 0;
+ exit ! close $fh;
} else {
if ($dir ne '|-') {
open STDIN, '<', '/dev/null' or die "reopening stdin: $!"
@@ -106,6 +109,9 @@ sub get_tags {
chomp ();
push @tags, $_ if (m/^$prefix/);
}
+ unless (close $fh) {
+ die "'notmuch search --output=tags *' exited with nonzero value\n";
+ }
return @tags;
}
@@ -173,6 +179,10 @@ sub update_index {
foreach my $pair (@{$status->{added}}) {
index_tags_for_msg ($git, $pair->{id}, 'A', $pair->{tag});
}
+ unless (close $git) {
+ die "'git update-index --index-info' exited with nonzero value\n";
+ }
+
}
@@ -211,8 +221,12 @@ sub index_tags {
my @tags = grep { s/^$TAGPREFIX//; } split (' ', $rest);
index_tags_for_msg ($git,$id, 'A', @tags);
}
-
- close $git;
+ unless (close $git) {
+ die "'git update-index --index-info' exited with nonzero value\n";
+ }
+ unless (close $fh) {
+ die "'notmuch dump -- $query' exited with nonzero value\n";
+ }
return $index;
}
@@ -395,6 +409,9 @@ sub compute_status {
} else {
push @deleted, $pair;
}
+ unless (close $fh) {
+ die "'notmuch search --output=files id:$id' exited with nonzero value\n";
+ }
}
@@ -414,7 +431,12 @@ sub diff_index {
qw/diff-index --cached/,
"--diff-filter=$filter", qw/--name-only HEAD/ );
- return unpack_diff_lines ($fh);
+ my @lines = unpack_diff_lines ($fh);
+ unless (close $fh) {
+ die "'git diff-index --cached --diff-filter=$filter --name-only HEAD' ",
+ "exited with nonzero value\n";
+ }
+ return @lines;
}
@@ -426,7 +448,12 @@ sub diff_refs {
my $fh= git_pipe ( 'diff', "--diff-filter=$filter", '--name-only',
$ref1, $ref2);
- return unpack_diff_lines ($fh);
+ my @lines = unpack_diff_lines ($fh);
+ unless (close $fh) {
+ die "'git diff --diff-filter=$filter --name-only $ref1 $ref2' ",
+ "exited with nonzero value\n";
+ }
+ return @lines;
}
diff --git a/contrib/nmbug/nmbug-status b/contrib/nmbug/nmbug-status
new file mode 100755
index 0000000..f37ee84
--- /dev/null
+++ b/contrib/nmbug/nmbug-status
@@ -0,0 +1,149 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2011-2012 David Bremner <david@tethera.net>
+# License: Same as notmuch
+# dependencies
+# - python 2.6 for json
+# - argparse; either python 2.7, or install separately
+
+import datetime
+import notmuch
+import rfc822
+import urllib
+import json
+import argparse
+import os
+import subprocess
+
+# parse command line arguments
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--text', help='output plain text format',
+ action='store_true')
+
+parser.add_argument('--config', help='load config from given file')
+
+
+args = parser.parse_args()
+
+# read config from json file
+
+if args.config != None:
+ fp = open(args.config)
+else:
+ nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug'))
+
+ # read only the first line from the pipe
+ sha1 = subprocess.Popen(['git', '--git-dir', nmbhome,
+ 'show-ref', '-s', 'config'],
+ stdout=subprocess.PIPE).stdout.readline()
+
+ sha1 = sha1.rstrip()
+
+ fp = subprocess.Popen(['git', '--git-dir', nmbhome,
+ 'cat-file', 'blob', sha1+':status-config.json'],
+ stdout=subprocess.PIPE).stdout
+
+config = json.load(fp)
+
+if args.text:
+ output_format = 'text'
+else:
+ output_format = 'html'
+
+headers = ['date', 'from', 'subject']
+last = {}
+
+def clear_last():
+ for header in headers:
+ last[header] = ''
+
+def print_view(title, query, comment):
+
+ query_string = ' and '.join(query)
+ q_new = notmuch.Query(db, query_string)
+ q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
+
+ last['thread_id'] = ''
+
+ if output_format == 'html':
+ print '<h3>%s</h3>' % title
+ print comment
+ print 'The view is generated from the following query:'
+ print '<blockquote>'
+ print query_string
+ print '</blockquote>'
+ print '<table>\n'
+
+ for m in q_new.search_messages():
+
+ out = {}
+
+ thread_id = m.get_thread_id()
+ if thread_id != last['thread_id']:
+ clear_last()
+
+ for header in headers:
+ val = m.get_header(header)
+
+ if header == 'date':
+ val = str.join(' ', val.split(None)[1:4])
+ val = str(datetime.datetime.strptime(val, '%d %b %Y').date())
+ elif header == 'from':
+ val = rfc822.parseaddr(val)[0]
+
+ if last[header] == val:
+ out[header] = ''
+ else:
+ out[header] = val.encode('utf-8')
+ last[header] = val
+
+ mid = m.get_message_id()
+ out['id'] = 'id:"%s"' % mid
+
+ if output_format == 'html':
+ # XXX using <br /> is a hack, but ... // 20111216 too
+ if thread_id != last['thread_id']:
+ br = '<br />'
+ else:
+ br = ''
+
+ out['subject'] = '<a href="http://mid.gmane.org/%s">%s</a>' \
+ % (urllib.quote(mid), out['subject'])
+
+ print ' <tr><td>%s %s' % (br, out['date'])
+ print '</td><td>%s %s' % (br, out['id'])
+ print '</td></tr>'
+ print ' <tr><td>%s' % out['from']
+ print '</td><td>%s' % out['subject']
+ print '</td></tr>\n'
+ else:
+ print '%(date)-10.10s %(from)-20.20s %(subject)-40.40s\n%(id)72s\n' % out
+
+ last['thread_id'] = thread_id
+
+ if output_format == 'html':
+ print '</table>'
+
+# main program
+
+db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
+
+if output_format == 'html':
+ print '''<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>Notmuch Patches</title>
+</head>
+<body>'''
+ print '<h2>Notmuch Patches</h2>'
+ print 'Generated: %s<br />' % datetime.datetime.utcnow().date()
+ print 'For more infomation see <a href="http://notmuchmail.org/nmbug">nmbug</a>'
+
+for view in config['views']:
+ print_view(**view)
+
+if output_format == 'html':
+ print '</body>\n</html>'
diff --git a/contrib/nmbug/status-config.json b/contrib/nmbug/status-config.json
new file mode 100644
index 0000000..6b4934f
--- /dev/null
+++ b/contrib/nmbug/status-config.json
@@ -0,0 +1,65 @@
+{
+ "views": [
+ {
+ "comment": "Unresolved bugs (or just need tag updating).",
+ "query": [
+ "tag:notmuch::bug",
+ "not tag:notmuch::fixed",
+ "not tag:notmuch::wontfix"
+ ],
+ "title": "Bugs"
+ },
+ {
+ "comment": "These patches are under consideration for pushing.",
+ "query": [
+ "tag:notmuch::patch and not tag:notmuch::pushed",
+ "not tag:notmuch::obsolete and not tag:notmuch::wip",
+ "not tag:notmuch::stale and not tag:notmuch::contrib",
+ "not tag:notmuch::moreinfo",
+ "not tag:notmuch::python",
+ "not tag:notmuch::vim",
+ "not tag:notmuch::wontfix",
+ "not tag:notmuch::needs-review"
+ ],
+ "title": "Maybe Ready (Core and Emacs)"
+ },
+ {
+ "comment": "These python related patches might be ready to push, or they might just need updated tags.",
+ "query": [
+ "tag:notmuch::patch and not tag:notmuch::pushed",
+ "not tag:notmuch::obsolete and not tag:notmuch::wip",
+ "not tag:notmuch::stale and not tag:notmuch::contrib",
+ "not tag:notmuch::moreinfo",
+ "not tag:notmuch::wontfix",
+ " tag:notmuch::python",
+ "not tag:notmuch::needs-review"
+ ],
+ "title": "Maybe Ready (Python)"
+ },
+ {
+ "comment": "These vim related patches might be ready to push, or they might just need updated tags.",
+ "query": [
+ "tag:notmuch::patch and not tag:notmuch::pushed",
+ "not tag:notmuch::obsolete and not tag:notmuch::wip",
+ "not tag:notmuch::stale and not tag:notmuch::contrib",
+ "not tag:notmuch::moreinfo",
+ "not tag:notmuch::wontfix",
+ "tag:notmuch::vim",
+ "not tag:notmuch::needs-review"
+ ],
+ "title": "Maybe Ready (vim)"
+ },
+ {
+ "comment": "These patches are under review, or waiting for feedback.",
+ "query": [
+ "tag:notmuch::patch",
+ "not tag:notmuch::pushed",
+ "not tag:notmuch::obsolete",
+ "not tag:notmuch::stale",
+ "not tag:notmuch::wontfix",
+ "(tag:notmuch::moreinfo or tag:notmuch::needs-review)"
+ ],
+ "title": "Review"
+ }
+ ]
+}
diff --git a/contrib/notmuch-deliver/src/main.c b/contrib/notmuch-deliver/src/main.c
index 6f32f73..032b9d6 100644
--- a/contrib/notmuch-deliver/src/main.c
+++ b/contrib/notmuch-deliver/src/main.c
@@ -359,6 +359,7 @@ main(int argc, char **argv)
GOptionContext *ctx;
GError *error = NULL;
notmuch_database_t *db;
+ notmuch_status_t status;
ctx = g_option_context_new("[FOLDER]");
g_option_context_add_main_entries(ctx, options, PACKAGE);
@@ -429,7 +430,14 @@ main(int argc, char **argv)
maildir = g_strdup(db_path);
g_debug("Opening notmuch database `%s'", db_path);
- db = notmuch_database_open(db_path, NOTMUCH_DATABASE_MODE_READ_WRITE);
+ status = notmuch_database_open(db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,
+ &db);
+ if (status) {
+ g_critical("Failed to open database `%s': %s",
+ db_path, notmuch_status_to_string(status));
+ g_free(maildir);
+ return EX_SOFTWARE;
+ }
g_free(db_path);
if (db == NULL)
return EX_SOFTWARE;
@@ -455,7 +463,7 @@ main(int argc, char **argv)
g_strfreev(opt_rtags);
g_free(mail);
- notmuch_database_close(db);
+ notmuch_database_destroy(db);
return 0;
}
diff --git a/contrib/notmuch-mutt/.gitignore b/contrib/notmuch-mutt/.gitignore
new file mode 100644
index 0000000..682a577
--- /dev/null
+++ b/contrib/notmuch-mutt/.gitignore
@@ -0,0 +1,2 @@
+notmuch-mutt.1
+README.html
diff --git a/contrib/notmuch-mutt/Makefile b/contrib/notmuch-mutt/Makefile
new file mode 100644
index 0000000..87f9031
--- /dev/null
+++ b/contrib/notmuch-mutt/Makefile
@@ -0,0 +1,12 @@
+NAME = notmuch-mutt
+
+all: $(NAME) $(NAME).1
+
+$(NAME).1: $(NAME)
+ pod2man $< > $@
+
+README.html: README
+ markdown $< > $@
+
+clean:
+ rm -f notmuch-mutt.1 README.html
diff --git a/contrib/notmuch-mutt/README b/contrib/notmuch-mutt/README
new file mode 100644
index 0000000..382ac91
--- /dev/null
+++ b/contrib/notmuch-mutt/README
@@ -0,0 +1,59 @@
+notmuch-mutt: Notmuch (of a) helper for Mutt
+============================================
+
+notmuch-mutt provide integration among the [Mutt] [1] mail user agent and the
+[Notmuch] [2] mail indexer.
+
+notmuch-mutt offer two main integration features. The first one is the ability
+of stating a **search query interactively** and then jump to a fresh Maildir
+containing its search results only. The second one is the ability to
+**reconstruct threads on the fly** starting from the currently highlighted
+mail, which comes handy when a thread has been split across different maildirs,
+archived, or the like.
+
+notmuch-mutt enables to trigger mail searches via a Mutt macro (usually F8) and
+reconstruct threads via another (usually F9). Check the manpage for the 2-liner
+configuration snippet for your Mutt configuration files (~/.muttrc,
+/etc/Muttrc, or a /etc/Muttrc.d snippet).
+
+A [blog style introduction] [3] to notmuch-mutt is available and includes some
+more rationale for its existence.
+
+Arguably, some of the logics of notmuch-mutt could disappear by adding support
+for a --output=symlinks flag to notmuch.
+
+
+[1]: http://www.mutt.org/
+[2]: http://notmuchmail.org/
+[3]: http://upsilon.cc/~zack/blog/posts/2011/01/how_to_use_Notmuch_with_Mutt/
+
+
+Requirements
+------------
+
+To *run* notmuch-mutt you will need Perl with the following libraries:
+
+- Mail::Box <http://search.cpan.org/~markov/Mail-Box/>
+ (Debian package: libmail-box-perl)
+- Mail::Internet <http://search.cpan.org/~markov/MailTools/>
+ (Debian package: libmailtools-perl)
+- String::ShellQuote <http://search.cpan.org/~rosch/String-ShellQuote/ShellQuote.pm>
+ (Debian package: libstring-shellquote-perl)
+- Term::ReadLine <http://search.cpan.org/~hayashi/Term-ReadLine-Gnu/>
+ (Debian package: libterm-readline-gnu-perl)
+
+To *build* notmuch-mutt documentation you will need:
+
+- pod2man (coming with Perl) to generate the manpage
+- markdown to generate README.html out of this file
+
+
+License
+-------
+
+notmuch-mutt is copyright (C) 2011-2012 Stefano Zacchiroli <zack@upsilon.cc>.
+
+notmuch-mutt is released under the terms of the GNU General Public License
+(GPL), version 3 or above. A copy of the license is available online at
+<http://www.gnu.org/licenses/>.
+
diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt
new file mode 100755
index 0000000..d14709d
--- /dev/null
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -0,0 +1,297 @@
+#!/usr/bin/perl -w
+#
+# notmuch-mutt - notmuch (of a) helper for Mutt
+#
+# Copyright: 2011-2012 Stefano Zacchiroli <zack@upsilon.cc>
+# License: GNU General Public License (GPL), version 3 or above
+#
+# See the bottom of this file for more documentation.
+# A manpage can be obtained by running "pod2man notmuch-mutt > notmuch-mutt.1"
+
+use strict;
+use warnings;
+
+use File::Path;
+use Getopt::Long qw(:config no_getopt_compat);
+use Mail::Internet;
+use Mail::Box::Maildir;
+use Pod::Usage;
+use String::ShellQuote;
+use Term::ReadLine;
+use Digest::SHA;
+use File::Which;
+
+
+my $xdg_cache_dir = "$ENV{HOME}/.cache";
+$xdg_cache_dir = $ENV{XDG_CACHE_HOME} if $ENV{XDG_CACHE_HOME};
+my $cache_dir = "$xdg_cache_dir/notmuch/mutt";
+
+
+# create an empty maildir (if missing) or empty an existing maildir"
+sub empty_maildir($) {
+ my ($maildir) = (@_);
+ rmtree($maildir) if (-d $maildir);
+ my $folder = new Mail::Box::Maildir(folder => $maildir,
+ create => 1);
+ $folder->close();
+}
+
+# Match files by size and SHA-256; then delete duplicates
+sub builtin_remove_dups($) {
+ my ($maildir) = @_;
+ my (%size_to_files, %sha_to_files);
+
+ # Group files by matching sizes
+ foreach my $file (glob("$maildir/cur/*")) {
+ my $size = -s $file;
+ push(@{$size_to_files{$size}}, $file) if $size;
+ }
+
+ foreach my $same_size_files (values %size_to_files) {
+ # Don't run sha unless there is another file of the same size
+ next if scalar(@$same_size_files) < 2;
+ %sha_to_files = ();
+
+ # Group files with matching sizes by SHA-256
+ foreach my $file (@$same_size_files) {
+ open(my $fh, '<', $file) or next;
+ binmode($fh);
+ my $sha256hash = Digest::SHA->new(256)->addfile($fh)->hexdigest;
+ close($fh);
+
+ push(@{$sha_to_files{$sha256hash}}, $file);
+ }
+
+ # Remove duplicates
+ foreach my $same_sha_files (values %sha_to_files) {
+ next if scalar(@$same_sha_files) < 2;
+ unlink(@{$same_sha_files}[1..$#$same_sha_files]);
+ }
+ }
+}
+
+# Use either fdupes or the built-in scanner to detect and remove duplicate
+# search results in the maildir
+sub remove_duplicates($) {
+ my ($maildir) = @_;
+
+ my $fdupes = which("fdupes");
+ if ($fdupes) {
+ system("$fdupes --hardlinks --symlinks --delete --noprompt"
+ . " --quiet $maildir/cur/ > /dev/null");
+ } else {
+ builtin_remove_dups($maildir);
+ }
+}
+
+# search($maildir, $remove_dups, $query)
+# search mails according to $query with notmuch; store results in $maildir
+sub search($$$) {
+ my ($maildir, $remove_dups, $query) = @_;
+ $query = shell_quote($query);
+
+ empty_maildir($maildir);
+ system("notmuch search --output=files $query"
+ . " | sed -e 's: :\\\\ :g'"
+ . " | xargs --no-run-if-empty ln -s -t $maildir/cur/");
+ remove_duplicates($maildir) if ($remove_dups);
+}
+
+sub prompt($$) {
+ my ($text, $default) = @_;
+ my $query = "";
+ my $term = Term::ReadLine->new( "notmuch-mutt" );
+ my $histfile = "$cache_dir/history";
+
+ $term->ornaments( 0 );
+ $term->unbind_key( ord( "\t" ) );
+ $term->MinLine( 3 );
+ $histfile = $ENV{MUTT_NOTMUCH_HISTFILE} if $ENV{MUTT_NOTMUCH_HISTFILE};
+ $term->ReadHistory($histfile) if (-r $histfile);
+ while (1) {
+ chomp($query = $term->readline($text, $default));
+ if ($query eq "?") {
+ system("man", "notmuch-search-terms");
+ } else {
+ $term->WriteHistory($histfile);
+ return $query;
+ }
+ }
+}
+
+sub get_message_id() {
+ my $mail = Mail::Internet->new(\*STDIN);
+ $mail->head->get("message-id") =~ /^<(.*)>$/; # get message-id
+ return $1;
+}
+
+sub search_action($$$@) {
+ my ($interactive, $results_dir, $remove_dups, @params) = @_;
+
+ if (! $interactive) {
+ search($results_dir, $remove_dups, join(' ', @params));
+ } else {
+ my $query = prompt("search ('?' for man): ", join(' ', @params));
+ if ($query ne "") {
+ search($results_dir, $remove_dups, $query);
+ }
+ }
+}
+
+sub thread_action($$@) {
+ my ($results_dir, $remove_dups, @params) = @_;
+
+ my $mid = get_message_id();
+ my $search_cmd = 'notmuch search --output=threads ' . shell_quote("id:$mid");
+ my $tid = `$search_cmd`; # get thread id
+ chomp($tid);
+
+ search($results_dir, $remove_dups, $tid);
+}
+
+sub tag_action(@) {
+ my $mid = get_message_id();
+
+ system("notmuch tag "
+ . shell_quote(join(' ', @_))
+ . " id:$mid");
+}
+
+sub die_usage() {
+ my %podflags = ( "verbose" => 1,
+ "exitval" => 2 );
+ pod2usage(%podflags);
+}
+
+sub main() {
+ mkpath($cache_dir) unless (-d $cache_dir);
+
+ my $results_dir = "$cache_dir/results";
+ my $interactive = 0;
+ my $help_needed = 0;
+ my $remove_dups = 0;
+
+ my $getopt = GetOptions(
+ "h|help" => \$help_needed,
+ "o|output-dir=s" => \$results_dir,
+ "p|prompt" => \$interactive,
+ "r|remove-dups" => \$remove_dups);
+ if (! $getopt || $#ARGV < 0) { die_usage() };
+ my ($action, @params) = ($ARGV[0], @ARGV[1..$#ARGV]);
+
+ foreach my $param (@params) {
+ $param =~ s/folder:=/folder:/g;
+ }
+
+ if ($help_needed) {
+ die_usage();
+ } elsif ($action eq "search" && $#ARGV == 0 && ! $interactive) {
+ print STDERR "Error: no search term provided\n\n";
+ die_usage();
+ } elsif ($action eq "search") {
+ search_action($interactive, $results_dir, $remove_dups, @params);
+ } elsif ($action eq "thread") {
+ thread_action($results_dir, $remove_dups, @params);
+ } elsif ($action eq "tag") {
+ tag_action(@params);
+ } else {
+ die_usage();
+ }
+}
+
+main();
+
+__END__
+
+=head1 NAME
+
+notmuch-mutt - notmuch (of a) helper for Mutt
+
+=head1 SYNOPSIS
+
+=over
+
+=item B<notmuch-mutt> [I<OPTION>]... search [I<SEARCH-TERM>]...
+
+=item B<notmuch-mutt> [I<OPTION>]... thread < I<MAIL>
+
+=item B<notmuch-mutt> [I<OPTION>]... tag [I<TAGS>]... < I<MAIL>
+
+=back
+
+=head1 DESCRIPTION
+
+notmuch-mutt is a frontend to the notmuch mail indexer capable of populating
+a maildir with search results.
+
+=head1 OPTIONS
+
+=over 4
+
+=item -o DIR
+
+=item --output-dir DIR
+
+Store search results as (symlink) messages under maildir DIR. Beware: DIR will
+be overwritten. (Default: F<~/.cache/notmuch/mutt/results/>)
+
+=item -p
+
+=item --prompt
+
+Instead of using command line search terms, prompt the user for them (only for
+"search").
+
+=item -r
+
+=item --remove-dups
+
+Remove duplicates from search results.
+
+=item -h
+
+=item --help
+
+Show usage information and exit.
+
+=back
+
+=head1 INTEGRATION WITH MUTT
+
+notmuch-mutt can be used to integrate notmuch with the Mutt mail user agent
+(unsurprisingly, given the name). To that end, you should define macros like
+the following in your Mutt configuration (usually one of: F<~/.muttrc>,
+F</etc/Muttrc>, or a configuration snippet under F</etc/Muttrc.d/>):
+
+ macro index <F8> \
+ "<enter-command>unset wait_key<enter><shell-escape>notmuch-mutt -r --prompt search<enter><change-folder-readonly>~/.cache/notmuch/mutt/results<enter>" \
+ "notmuch: search mail"
+ macro index <F9> \
+ "<enter-command>unset wait_key<enter><pipe-message>notmuch-mutt -r thread<enter><change-folder-readonly>~/.cache/notmuch/mutt/results<enter><enter-command>set wait_key<enter>" \
+ "notmuch: reconstruct thread"
+ macro index <F6> \
+ "<enter-command>unset wait_key<enter><pipe-message>notmuch-mutt tag -- -inbox<enter>" \
+ "notmuch: remove message from inbox"
+
+The first macro (activated by <F8>) prompts the user for notmuch search terms
+and then jump to a temporary maildir showing search results. The second macro
+(activated by <F9>) reconstructs the thread corresponding to the current mail
+and show it as search results. The third macro (activated by <F6>) removes the
+tag C<inbox> from the current message; by changing C<-inbox> this macro may be
+customised to add or remove tags appropriate to the users notmuch work-flow.
+
+To keep notmuch index current you should then periodically run C<notmuch
+new>. Depending on your local mail setup, you might want to do that via cron,
+as a hook triggered by mail retrieval, etc.
+
+=head1 SEE ALSO
+
+mutt(1), notmuch(1)
+
+=head1 AUTHOR
+
+Copyright: (C) 2011-2012 Stefano Zacchiroli <zack@upsilon.cc>
+
+License: GNU General Public License (GPL), version 3 or higher
+
+=cut
diff --git a/contrib/notmuch-mutt/notmuch-mutt.rc b/contrib/notmuch-mutt/notmuch-mutt.rc
new file mode 100644
index 0000000..ddc4b48
--- /dev/null
+++ b/contrib/notmuch-mutt/notmuch-mutt.rc
@@ -0,0 +1,9 @@
+macro index <F8> \
+ "<enter-command>unset wait_key<enter><shell-escape>notmuch-mutt -r --prompt search<enter><change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>" \
+ "notmuch: search mail"
+macro index <F9> \
+ "<enter-command>unset wait_key<enter><pipe-message>notmuch-mutt -r thread<enter><change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter><enter-command>set wait_key<enter>" \
+ "notmuch: reconstruct thread"
+macro index <F6> \
+ "<enter-command>unset wait_key<enter><pipe-message>notmuch-mutt tag -- -inbox<enter>" \
+ "notmuch: remove message from inbox"
diff --git a/crypto.c b/crypto.c
new file mode 100644
index 0000000..fbe5aeb
--- /dev/null
+++ b/crypto.c
@@ -0,0 +1,71 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright © 2012 Jameson Rollins
+ *
+ * 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 http://www.gnu.org/licenses/ .
+ *
+ * Authors: Jameson Rollins <jrollins@finestructure.net>
+ */
+
+#include "notmuch-client.h"
+
+/* for the specified protocol return the context pointer (initializing
+ * if needed) */
+notmuch_crypto_context_t *
+notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)
+{
+ notmuch_crypto_context_t *cryptoctx = NULL;
+
+ /* As per RFC 1847 section 2.1: "the [protocol] value token is
+ * comprised of the type and sub-type tokens of the Content-Type".
+ * As per RFC 1521 section 2: "Content-Type values, subtypes, and
+ * parameter names as defined in this document are
+ * case-insensitive." Thus, we use strcasecmp for the protocol.
+ */
+ if ((strcasecmp (protocol, "application/pgp-signature") == 0)
+ || (strcasecmp (protocol, "application/pgp-encrypted") == 0)) {
+ if (!crypto->gpgctx) {
+#ifdef GMIME_ATLEAST_26
+ /* TODO: GMimePasswordRequestFunc */
+ crypto->gpgctx = g_mime_gpg_context_new (NULL, "gpg");
+#else
+ GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
+ crypto->gpgctx = g_mime_gpg_context_new (session, "gpg");
+ g_object_unref (session);
+#endif
+ if (crypto->gpgctx) {
+ g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto->gpgctx, FALSE);
+ } else {
+ fprintf (stderr, "Failed to construct gpg context.\n");
+ }
+ }
+ cryptoctx = crypto->gpgctx;
+
+ } else {
+ fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");
+ }
+
+ return cryptoctx;
+}
+
+int
+notmuch_crypto_cleanup (notmuch_crypto_t *crypto)
+{
+ if (crypto->gpgctx) {
+ g_object_unref (crypto->gpgctx);
+ crypto->gpgctx = NULL;
+ }
+
+ return 0;
+}
diff --git a/debian/.gitignore b/debian/.gitignore
index 801ca02..9f09f22 100644
--- a/debian/.gitignore
+++ b/debian/.gitignore
@@ -1,3 +1,10 @@
+tmp/
+libnotmuch-dev/
+libnotmuch2/
+notmuch-emacs/
+notmuch-vim/
+notmuch/
+python-notmuch/
*.debhelper
*.debhelper.log
*.substvars
diff --git a/debian/NEWS.Debian b/debian/NEWS.Debian
index 6947754..bf95738 100644
--- a/debian/NEWS.Debian
+++ b/debian/NEWS.Debian
@@ -1,3 +1,17 @@
+notmuch (0.14-1) unstable; urgency=low
+
+ There is an incompatible change in option syntax for dump and restore
+ in this release. Please update your scripts.
+
+ From upstream NEWS:
+
+ The deprecated positional output file argument to notmuch dump has
+ been replaced with an --output option. The input file positional
+ argument for restore has been replaced with an --input option for
+ consistency with dump.
+
+ -- David Bremner <bremner@debian.org> Sun, 05 Aug 2012 11:52:49 -0300
+
notmuch (0.6~238) unstable; urgency=low
The emacs user interface to notmuch is now contained in a seperate
diff --git a/debian/changelog b/debian/changelog
index 26fff87..36f06af 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,84 @@
+notmuch (0.14-1) unstable; urgency=low
+
+ [ Stefano Zacchiroli ]
+ * notmuch-mutt: fix tag action invocation (Closes: #678012)
+ * Use notmuch-search-terms manpage in notmuch-mutt (Closes: #675073).
+
+ [ David Bremner ]
+ * Do a better job of cleaning up after configuration and testing
+ (Closes: #683505)
+ * Alternately depend on emacs24 instead of emacs23 (Closes: #677900).
+
+ -- David Bremner <bremner@debian.org> Thu, 02 Aug 2012 21:32:31 -0300
+
+notmuch (0.13.2-1) unstable; urgency=low
+
+ * Upstream bugfix release. No changes to binary packages.
+
+ -- David Bremner <bremner@debian.org> Sat, 02 Jun 2012 18:16:01 -0300
+
+notmuch (0.13.1-1) unstable; urgency=low
+
+ * Upstream bugfix release.
+ - fix for encoding problems with reply in emacs
+ - notmuch_database_(get_directory|find_message_by_filename) now
+ work for read-only databases.
+
+ -- David Bremner <bremner@debian.org> Fri, 25 May 2012 21:19:06 -0300
+
+notmuch (0.13-1) unstable; urgency=low
+
+ * New upstream release. See /usr/share/doc/notmuch/NEWS.gz for changes.
+
+ [ Stefano Zacchiroli ]
+ * Recommend all notmuch UI (including notmuch-mutt) as alternatives,
+ to avoid unneeded vim/emacs installation. Thanks Matteo F. Vescovi
+ for the patch. (Closes: #673011)
+
+ -- David Bremner <bremner@debian.org> Tue, 15 May 2012 18:19:32 -0300
+
+notmuch (0.13~rc1-2) experimental; urgency=low
+
+ * New upstream pre-release
+ * new binary package "notmuch-mutt" for Mutt integration
+ * Bump libnotmuch SONAME because of API changes
+
+ -- David Bremner <bremner@debian.org> Sat, 05 May 2012 10:26:47 -0300
+
+notmuch (0.12-1) unstable; urgency=low
+
+ * New upstream release
+ - Python 3.2 support
+ - GMime 2.6 support
+ - Many updates to emacs interface (see /usr/share/doc/notmuch/NEWS)
+ - Optionally ignore some files/directories within mail hierarchy
+
+ -- David Bremner <bremner@debian.org> Tue, 20 Mar 2012 18:45:22 -0300
+
+notmuch (0.12~rc2-1) experimental; urgency=low
+
+ * Upstream pre-release
+ * New bug fixes since ~rc1
+ - fix for uninitialized variable
+ - fix for python bindings type signatures
+
+ -- David Bremner <bremner@debian.org> Sun, 18 Mar 2012 08:10:35 -0300
+
+notmuch (0.12~rc1-1) experimental; urgency=low
+
+ * Upstream pre-release.
+ * Bump standards version to 3.9.3; no changes.
+
+ -- David Bremner <bremner@debian.org> Thu, 01 Mar 2012 07:51:45 -0400
+
+notmuch (0.11.1-1) unstable; urgency=low
+
+ * Upstream bugfix release
+ - Fix error handling bug in python bindings
+ - Fix vulnerability in emacs reply handling
+
+ -- David Bremner <bremner@debian.org> Fri, 03 Feb 2012 08:35:41 -0400
+
notmuch (0.11-1) unstable; urgency=low
* New upstream release.
diff --git a/debian/control b/debian/control
index f6f415e..f725276 100644
--- a/debian/control
+++ b/debian/control
@@ -10,14 +10,15 @@ Build-Depends:
debhelper (>= 7.0.50~),
pkg-config,
libxapian-dev,
- libgmime-2.4-dev,
+ libgmime-2.6-dev (>= 2.6.7~) | libgmime-2.4-dev,
libtalloc-dev,
libz-dev,
python-all (>= 2.6.6-3~),
- emacs23-nox | emacs23 (>=23~) | emacs23-lucid (>=23~),
+ emacs23-nox | emacs23 (>=23~) | emacs23-lucid (>=23~) |
+ emacs24-nox | emacs24 (>=24~) | emacs24-lucid (>=24~),
gdb,
dtach (>= 0.8)
-Standards-Version: 3.9.2
+Standards-Version: 3.9.3
Homepage: http://notmuchmail.org/
Vcs-Git: git://notmuchmail.org/git/notmuch
Vcs-Browser: http://git.notmuchmail.org/git/notmuch
@@ -25,8 +26,8 @@ Dm-Upload-Allowed: yes
Package: notmuch
Architecture: any
-Depends: libnotmuch2 (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends}
-Recommends: notmuch-emacs | notmuch-vim
+Depends: libnotmuch3 (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends}
+Recommends: notmuch-emacs | notmuch-vim | notmuch-mutt, gnupg-agent
Description: thread-based email index, search and tagging
Notmuch is a system for indexing, searching, reading, and tagging
large collections of email messages in maildir or mh format. It uses
@@ -35,7 +36,7 @@ Description: thread-based email index, search and tagging
.
This package contains the notmuch command-line interface
-Package: libnotmuch2
+Package: libnotmuch3
Section: libs
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
@@ -51,7 +52,7 @@ Description: thread-based email index, search and tagging (runtime)
Package: libnotmuch-dev
Section: libdevel
Architecture: any
-Depends: ${misc:Depends}, libnotmuch2 (= ${binary:Version})
+Depends: ${misc:Depends}, libnotmuch3 (= ${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
@@ -64,7 +65,7 @@ Description: thread-based email index, search and tagging (development)
Package: python-notmuch
Architecture: all
Section: python
-Depends: ${misc:Depends}, ${python:Depends}, libnotmuch2
+Depends: ${misc:Depends}, ${python:Depends}, libnotmuch3
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
@@ -80,7 +81,8 @@ Section: mail
Breaks: notmuch (<<0.6~254~)
Replaces: notmuch (<<0.6~254~)
Depends: ${misc:Depends}, notmuch (>= ${source:Version}),
- emacs23 (>= 23~) | emacs23-nox (>=23~) | emacs23-lucid (>=23~)
+ emacs23 (>= 23~) | emacs23-nox (>=23~) | emacs23-lucid (>=23~) |
+ emacs24 (>= 24~) | emacs24-nox (>=24~) | emacs24-lucid (>=24~)
Description: thread-based email index, search and tagging (emacs interface)
Notmuch is a system for indexing, searching, reading, and tagging
large collections of email messages in maildir or mh format. It uses
@@ -105,3 +107,20 @@ Description: thread-based email index, search and tagging (vim interface)
This package provides a vim based mail user agent based on
notmuch.
+Package: notmuch-mutt
+Architecture: all
+Depends: notmuch, libmail-box-perl, libmailtools-perl,
+ libstring-shellquote-perl, libterm-readline-gnu-perl,
+ libfile-which-perl,
+ ${misc:Depends}
+Recommends: mutt, fdupes
+Enhances: notmuch, mutt
+Description: thread-based email index, search and tagging (Mutt interface)
+ notmuch-mutt provides integration among the Mutt mail user agent and
+ the Notmuch mail indexer.
+ .
+ notmuch-mutt offer two main integration features. The first one is
+ the ability of stating a search query interactively and then jump to
+ a fresh Maildir containing its search results only. The second one is
+ the ability to reconstruct threads on the fly starting from the
+ current highlighted mail.
diff --git a/debian/libnotmuch2.install b/debian/libnotmuch3.install
index da4fc25..da4fc25 100644
--- a/debian/libnotmuch2.install
+++ b/debian/libnotmuch3.install
diff --git a/debian/libnotmuch2.symbols b/debian/libnotmuch3.symbols
index 507600c..140cae9 100644
--- a/debian/libnotmuch2.symbols
+++ b/debian/libnotmuch3.symbols
@@ -1,8 +1,9 @@
-libnotmuch.so.2 libnotmuch2 #MINVER#
+libnotmuch.so.3 libnotmuch3 #MINVER#
notmuch_database_add_message@Base 0.3
notmuch_database_begin_atomic@Base 0.9~rc1
- notmuch_database_close@Base 0.3
+ notmuch_database_close@Base 0.13~rc1
notmuch_database_create@Base 0.3
+ 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
@@ -46,6 +47,7 @@ libnotmuch.so.2 libnotmuch2 #MINVER#
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_threads@Base 0.10~rc1
notmuch_query_create@Base 0.3
@@ -54,6 +56,7 @@ libnotmuch.so.2 libnotmuch2 #MINVER#
notmuch_query_get_sort@Base 0.4
notmuch_query_search_messages@Base 0.3
notmuch_query_search_threads@Base 0.3
+ 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
diff --git a/debian/notmuch-mutt.docs b/debian/notmuch-mutt.docs
new file mode 100644
index 0000000..f3d25cd
--- /dev/null
+++ b/debian/notmuch-mutt.docs
@@ -0,0 +1 @@
+contrib/notmuch-mutt/README
diff --git a/debian/notmuch-mutt.install b/debian/notmuch-mutt.install
new file mode 100644
index 0000000..9141c26
--- /dev/null
+++ b/debian/notmuch-mutt.install
@@ -0,0 +1,2 @@
+contrib/notmuch-mutt/notmuch-mutt usr/bin
+contrib/notmuch-mutt/notmuch-mutt.rc etc/Muttrc.d
diff --git a/debian/notmuch-mutt.manpages b/debian/notmuch-mutt.manpages
new file mode 100644
index 0000000..3f6b8ab
--- /dev/null
+++ b/debian/notmuch-mutt.manpages
@@ -0,0 +1 @@
+contrib/notmuch-mutt/notmuch-mutt.1
diff --git a/debian/rules b/debian/rules
index 956f3f2..603b3ab 100755
--- a/debian/rules
+++ b/debian/rules
@@ -9,10 +9,12 @@ override_dh_auto_configure:
override_dh_auto_build:
dh_auto_build
dh_auto_build --sourcedirectory bindings/python
+ $(MAKE) -C contrib/notmuch-mutt
override_dh_auto_clean:
dh_auto_clean
dh_auto_clean --sourcedirectory bindings/python
+ $(MAKE) -C contrib/notmuch-mutt clean
override_dh_auto_install:
dh_auto_install
diff --git a/RELEASING b/devel/RELEASING
index 88dab04..88dab04 100644
--- a/RELEASING
+++ b/devel/RELEASING
diff --git a/devel/STYLE b/devel/STYLE
new file mode 100644
index 0000000..094f71d
--- /dev/null
+++ b/devel/STYLE
@@ -0,0 +1,88 @@
+C/C++ coding style
+==================
+
+Tools
+-----
+
+There is a file uncrustify.cfg in this directory that can be used to
+approximate the prevailing code style. You can run it with e.g.
+
+ uncrustify --replace -c devel/uncrustify.cfg foo.c
+
+You still have to use your judgement about accepting or rejecting the
+changes uncrustify makes. With a nice git frontend, you can add the
+lines you agree with and reject the rest.
+
+For Emacs users, the file .dir-locals.el in the top level source
+directory will configure c-mode to automatically meet most of the
+basic layout rules. I
+
+Indentation, Whitespace, and Layout
+-----------------------------------
+
+The following nonsense code demonstrates many aspects of the style:
+
+static some_type
+function (param_type param, param_type param)
+{
+ int i;
+
+ for (i = 0; i < 10; i++) {
+ int j;
+
+ j = i + 10;
+
+ some_other_func (j, i);
+ }
+}
+
+* Indent is 4 spaces with mixed tab/spaces and a tab width of 8.
+ (Specifically, a line should begin with zero or more tabs followed
+ by fewer than eight spaces.)
+
+* Use copious whitespace. In particular
+ - there is a space between the function name and the open paren in a call.
+ - likewise, there is a space following keywords such as if and while
+ - every binary operator should have space on either side.
+
+* No trailing whitespace. Please enable the standard pre-commit hook
+ in git (or an equivalent hook).
+
+* The name in a function prototype should start at the beginning of a line.
+
+* Opening braces "cuddle" (they are on the same line as the
+ if/for/while test) and are preceded by a space. The opening brace of
+ functions is the exception, and starts on a new line.
+
+* Comments are always C-style /* */ block comments. They should start
+ with a capital letter and generally be written in complete
+ sentences. Public library functions are documented immediately
+ before their prototype in lib/notmuch.h. Internal functions are
+ typically documented immediately before their definition.
+
+* Code lines should be less than 80 columns and comments should be
+ wrapped at 70 columns.
+
+Naming
+------
+
+* Use lowercase_with_underscores for function, variable, and type
+ names.
+
+* All structs should be typedef'd to a name ending with _t. If the
+ struct has a tag, it should be the same as the typedef name, minus
+ the trailing _t.
+
+libnotmuch conventions
+----------------------------------
+
+* Functions starting with notmuch_ in lib/notmuch.h are public and are
+ automatically exported from the shared library. Private library
+ functions should generally either be static or, if they are shared
+ between compilation units, start with _notmuch.
+
+* Functions in libnotmuch must not access user configuration files
+ (i.e. .notmuch-config)
+
+* Code which needs to be accessed from both the CLI and from
+ libnotmuch should be factored out into libutil (under util/).
diff --git a/TODO b/devel/TODO
index 4dda6f4..eb757af 100644
--- a/TODO
+++ b/devel/TODO
@@ -92,8 +92,6 @@ and email address in the From: line. We could also then easily support
"notmuch compose --from <something>" to support getting at alternate
email addresses.
-Fix the --format=json option to not imply --entire-thread.
-
Implement "notmuch search --exclude-threads=<search-terms>" to allow
for excluding muted threads, (and any other negative, thread-based
filtering that the user wants to do).
@@ -141,6 +139,14 @@ Simplify notmuch-reply to simply print the headers (we have the
original values) rather than calling GMime (which encodes) and adding
the confusing gmime-filter-headers.c code (which decodes).
+Properly handle replying to multiple messages. Currently, the JSON
+reply format only supports a single message, but the default reply
+format accepts searches returning multiple messages. The expected
+behavior of replying to multiple messages is not obvious, and there
+are multiple ideas that might make sense. Some consensus needs to be
+reached on this issue, and then both reply formats should be updated
+to be consistent.
+
notmuch library
---------------
Add support for custom flag<->tag mappings. In the notmuch
diff --git a/devel/schemata b/devel/schemata
new file mode 100644
index 0000000..9cb25f5
--- /dev/null
+++ b/devel/schemata
@@ -0,0 +1,155 @@
+This file describes the schemata used for notmuch's structured output
+format (currently JSON).
+
+[]'s indicate lists. List items can be marked with a '?', meaning
+they are optional; or a '*', meaning there can be zero or more of that
+item. {}'s indicate an object that maps from field identifiers to
+values. An object field marked '?' is optional. |'s indicate
+alternates (e.g., int|string means something can be an int or a
+string).
+
+Common non-terminals
+--------------------
+
+# Number of seconds since the Epoch
+unix_time = int
+
+# Thread ID, sans "thread:"
+threadid = string
+
+# Message ID, sans "id:"
+messageid = string
+
+notmuch show schema
+-------------------
+
+# A top-level set of threads (do_show)
+# Returned by notmuch show without a --part argument
+thread_set = [thread*]
+
+# Top-level messages in a thread (show_messages)
+thread = [thread_node*]
+
+# A message and its replies (show_messages)
+thread_node = [
+ message|null, # null if not matched and not --entire-thread
+ [thread_node*] # children of message
+]
+
+# A message (format_part_json)
+message = {
+ # (format_message_json)
+ id: messageid,
+ match: bool,
+ filename: string,
+ timestamp: unix_time, # date header as unix time
+ date_relative: string, # user-friendly timestamp
+ tags: [string*],
+
+ headers: headers,
+ body?: [part] # omitted if --body=false
+}
+
+# A MIME part (format_part_json)
+part = {
+ id: int|string, # part id (currently DFS part number)
+
+ encstatus?: encstatus,
+ sigstatus?: sigstatus,
+
+ content-type: string,
+ content-id?: string,
+ # if content-type starts with "multipart/":
+ content: [part*],
+ # if content-type is "message/rfc822":
+ content: [{headers: headers, body: [part]}],
+ # otherwise (leaf parts):
+ filename?: string,
+ content-charset?: string,
+ # A leaf part's body content is optional, but may be included if
+ # it can be correctly encoded as a string. Consumers should use
+ # this in preference to fetching the part content separately.
+ content?: string
+}
+
+# The headers of a message or part (format_headers_json with reply = FALSE)
+headers = {
+ Subject: string,
+ From: string,
+ To?: string,
+ Cc?: string,
+ Bcc?: string,
+ Date: string
+}
+
+# Encryption status (format_part_json)
+encstatus = [{status: "good"|"bad"}]
+
+# Signature status (format_part_sigstatus_json)
+sigstatus = [signature*]
+
+signature = {
+ # (signature_status_to_string)
+ status: "none"|"good"|"bad"|"error"|"unknown",
+ # if status is "good":
+ fingerprint?: string,
+ created?: unix_time,
+ expires?: unix_time,
+ userid?: string
+ # if status is not "good":
+ keyid?: string
+ # if the signature has errors:
+ errors?: int
+}
+
+notmuch search schema
+---------------------
+
+# --output=summary
+summary = [thread*]
+
+# --output=threads
+threads = [threadid*]
+
+# --output=messages
+messages = [messageid*]
+
+# --output=files
+files = [string*]
+
+# --output=tags
+tags = [string*]
+
+thread = {
+ thread: threadid,
+ timestamp: unix_time,
+ date_relative: string, # user-friendly timestamp
+ matched: int, # number of matched messages
+ total: int, # total messages in thread
+ authors: string, # comma-separated names with | between
+ # matched and unmatched
+ subject: string,
+ tags: [string*]
+}
+
+notmuch reply schema
+--------------------
+
+reply = {
+ # The headers of the constructed reply
+ reply-headers: reply_headers,
+
+ # As in the show format (format_part_json)
+ original: message
+}
+
+# Reply headers (format_headers_json with reply = TRUE)
+reply_headers = {
+ Subject: string,
+ From: string,
+ To?: string,
+ Cc?: string,
+ Bcc?: string,
+ In-reply-to: string,
+ References: string
+}
diff --git a/devel/uncrustify.cfg b/devel/uncrustify.cfg
new file mode 100644
index 0000000..d24cf6e
--- /dev/null
+++ b/devel/uncrustify.cfg
@@ -0,0 +1,117 @@
+#
+# Uncrustify config file for notmuch.
+# Based on uncrustify config file for the linux kernel
+#
+# $Id: linux-indent.cfg 488 2006-09-09 12:44:38Z bengardner $
+# Taken from the uncrustify distribution under license (GPL2+)
+#
+# Sample usage:
+# uncrustify --replace -c uncrustify.cfg foo.c
+#
+
+indent_with_tabs = 2 # 1=indent to level only, 2=indent with tabs
+align_with_tabs = TRUE # use tabs to align
+align_on_tabstop = TRUE # align on tabstops
+input_tab_size = 8 # original tab size
+output_tab_size = 8 # new tab size
+indent_columns = 4
+
+indent_label = -2 # pos: absolute col, neg: relative column
+
+indent_cmt_with_tabs = false # true would align to tabstop always...
+
+#
+# inter-symbol newlines
+#
+
+nl_enum_brace = remove # "enum {" vs "enum \n {"
+nl_union_brace = remove # "union {" vs "union \n {"
+nl_struct_brace = remove # "struct {" vs "struct \n {"
+nl_do_brace = remove # "do {" vs "do \n {"
+nl_if_brace = remove # "if () {" vs "if () \n {"
+nl_for_brace = remove # "for () {" vs "for () \n {"
+nl_else_brace = remove # "else {" vs "else \n {"
+nl_while_brace = remove # "while () {" vs "while () \n {"
+nl_switch_brace = remove # "switch () {" vs "switch () \n {"
+nl_brace_while = remove # "} while" vs "} \n while" - cuddle while
+nl_brace_else = remove # "} else" vs "} \n else" - cuddle else
+nl_func_var_def_blk = 1
+nl_fcall_brace = remove # "list_for_each() {" vs "list_for_each()\n{"
+nl_fdef_brace = force # "int foo() {" vs "int foo()\n{"
+# nl_after_return = TRUE;
+# nl_before_case = 1
+
+# Add or remove newline between return type and function name in definition
+nl_func_type_name = force
+nl_enum_leave_one_liners = True
+nl_enum_brace = Remove
+nl_after_struct = 0
+#
+# Source code modifications
+#
+
+# mod_paren_on_return = remove # "return 1;" vs "return (1);"
+# mod_full_brace_if = remove # "if (a) a--;" vs "if (a) { a--; }"
+# mod_full_brace_for = remove # "for () a--;" vs "for () { a--; }"
+# mod_full_brace_do = remove # "do a--; while ();" vs "do { a--; } while ();"
+# mod_full_brace_while = remove # "while (a) a--;" vs "while (a) { a--; }"
+
+
+# In case some custom types aren't detected properly by uncrustify
+# add those to this section below. For example there are cases where
+# uncrustify doesn't know whether a 'token' is part of pointer type
+# or left operand of a binary multiplication operation.
+
+type GMimeObject GMimeCryptoContext GMimeCipherContext
+type mime_node_t notmuch_message_t
+
+#
+# inter-character spacing options
+#
+
+sp_before_ptr_star = force
+sp_between_ptr_star = remove
+sp_after_ptr_star = remove
+sp_not = force
+sp_pp_concat = ignore # XXX 'remove' drops leading space also
+sp_pp_stringify = remove
+
+# sp _return_paren = force # "return (1);" vs "return(1);"
+sp_sizeof_paren = force # "sizeof (int)" vs "sizeof(int)"
+sp_before_sparen = force # "if (" vs "if("
+sp_after_sparen = force # "if () {" vs "if (){"
+sp_sparen_brace = force
+sp_after_cast = force # "(int) a" vs "(int)a"
+sp_inside_braces = add # "{ 1 }" vs "{1}"
+sp_inside_braces_struct = add # "{ 1 }" vs "{1}"
+sp_inside_braces_enum = add # "{ 1 }" vs "{1}"
+sp_assign = force
+sp_arith = force
+sp_bool = add
+sp_compare = add
+sp_assign = add
+sp_after_comma = add
+sp_func_def_paren = force # "int foo (){" vs "int foo(){"
+sp_func_call_paren = force # "foo (" vs "foo("
+sp_func_proto_paren = force # "int foo ();" vs "int foo();"
+sp_brace_else = force # "} else" vs "}else"
+sp_else_brace = force # "else {" vs "else{"
+#
+# Aligning stuff
+#
+
+align_enum_equ_span = 4 # '=' in enum definition
+# align_nl_cont = TRUE
+# align_var_def_span = 2
+# align_var_def_inline = TRUE
+# align_var_def_star = FALSE
+# align_var_def_colon = TRUE
+# align_assign_span = 1
+align_struct_init_span = 0 # align stuff in a structure init '= { }'
+align_right_cmt_span = 8 # align comments span this much in func
+# align_pp_define_span = 8;
+# align_pp_define_gap = 4;
+
+cmt_star_cont = true
+
+# indent_brace = 0
diff --git a/emacs/Makefile.local b/emacs/Makefile.local
index 0c58b82..fb82247 100644
--- a/emacs/Makefile.local
+++ b/emacs/Makefile.local
@@ -13,7 +13,9 @@ emacs_sources := \
$(dir)/notmuch-maildir-fcc.el \
$(dir)/notmuch-message.el \
$(dir)/notmuch-crypto.el \
- $(dir)/coolj.el
+ $(dir)/notmuch-tag.el \
+ $(dir)/coolj.el \
+ $(dir)/notmuch-print.el
emacs_images := \
$(srcdir)/$(dir)/notmuch-logo.png
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 8eba7a0..2bf762b 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -28,7 +28,8 @@
single argument and output a list of possible matches, one per
line."
:type 'string
- :group 'notmuch)
+ :group 'notmuch-send
+ :group 'notmuch-external)
(defvar notmuch-address-message-alist-member
'("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
@@ -37,9 +38,9 @@ line."
(defvar notmuch-address-history nil)
(defun notmuch-address-message-insinuate ()
- (if (not (memq notmuch-address-message-alist-member message-completion-alist))
- (setq message-completion-alist
- (push notmuch-address-message-alist-member message-completion-alist))))
+ (unless (memq notmuch-address-message-alist-member message-completion-alist)
+ (setq message-completion-alist
+ (push notmuch-address-message-alist-member message-completion-alist))))
(defun notmuch-address-options (original)
(process-lines notmuch-address-command original))
diff --git a/emacs/notmuch-crypto.el b/emacs/notmuch-crypto.el
index ac30098..83e5d37 100644
--- a/emacs/notmuch-crypto.el
+++ b/emacs/notmuch-crypto.el
@@ -34,38 +34,44 @@ The effect of setting this variable can be seen temporarily by
providing a prefix when viewing a signed or encrypted message, or
by providing a prefix when reloading the message in notmuch-show
mode."
- :group 'notmuch
- :type 'boolean)
+ :type 'boolean
+ :group 'notmuch-crypto)
(defface notmuch-crypto-part-header
'((t (:foreground "blue")))
"Face used for crypto parts headers."
- :group 'notmuch)
+ :group 'notmuch-crypto
+ :group 'notmuch-faces)
(defface notmuch-crypto-signature-good
'((t (:background "green" :foreground "black")))
"Face used for good signatures."
- :group 'notmuch)
+ :group 'notmuch-crypto
+ :group 'notmuch-faces)
(defface notmuch-crypto-signature-good-key
'((t (:background "orange" :foreground "black")))
"Face used for good signatures."
- :group 'notmuch)
+ :group 'notmuch-crypto
+ :group 'notmuch-faces)
(defface notmuch-crypto-signature-bad
'((t (:background "red" :foreground "black")))
"Face used for bad signatures."
- :group 'notmuch)
+ :group 'notmuch-crypto
+ :group 'notmuch-faces)
(defface notmuch-crypto-signature-unknown
'((t (:background "red" :foreground "black")))
"Face used for signatures of unknown status."
- :group 'notmuch)
+ :group 'notmuch-crypto
+ :group 'notmuch-faces)
(defface notmuch-crypto-decryption
'((t (:background "purple" :foreground "black")))
"Face used for encryption/decryption status messages."
- :group 'notmuch)
+ :group 'notmuch-crypto
+ :group 'notmuch-faces)
(define-button-type 'notmuch-crypto-status-button-type
'action (lambda (button) (message (button-get button 'help-echo)))
@@ -95,7 +101,7 @@ mode."
(let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
(setq label (concat "Unknown key ID " keyid " or unsupported algorithm"))
(setq button-action 'notmuch-crypto-sigstatus-error-callback)
- (setq help-msg (concat "Click to retreive key ID " keyid " from keyserver and redisplay."))))
+ (setq help-msg (concat "Click to retrieve key ID " keyid " from keyserver and redisplay."))))
((string= status "bad")
(let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
(setq label (concat "Bad signature (claimed key ID " keyid ")"))
@@ -114,7 +120,7 @@ mode."
:notmuch-from from)
(insert "\n")))
-(declare-function notmuch-show-refresh-view "notmuch-show" (&optional crypto-switch))
+(declare-function notmuch-show-refresh-view "notmuch-show" (&optional reset-state))
(defun notmuch-crypto-sigstatus-good-callback (button)
(let* ((sigstatus (button-get button :notmuch-sigstatus))
@@ -123,6 +129,7 @@ mode."
(window (display-buffer buffer t nil)))
(with-selected-window window
(with-current-buffer buffer
+ (goto-char (point-max))
(call-process "gpg" nil t t "--list-keys" fingerprint))
(recenter -1))))
@@ -133,6 +140,7 @@ mode."
(window (display-buffer buffer t nil)))
(with-selected-window window
(with-current-buffer buffer
+ (goto-char (point-max))
(call-process "gpg" nil t t "--recv-keys" keyid)
(insert "\n")
(call-process "gpg" nil t t "--list-keys" keyid))
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 02017ce..684bedc 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -29,22 +29,19 @@
(declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))
(declare-function notmuch-poll "notmuch" ())
-(defvar notmuch-hello-search-bar-marker nil
- "The position of the search bar within the notmuch-hello buffer.")
-
-(defcustom notmuch-recent-searches-max 10
- "The number of recent searches to store and display."
+(defcustom notmuch-hello-recent-searches-max 10
+ "The number of recent searches to display."
:type 'integer
- :group 'notmuch)
+ :group 'notmuch-hello)
(defcustom notmuch-show-empty-saved-searches nil
"Should saved searches with no messages be listed?"
:type 'boolean
- :group 'notmuch)
+ :group 'notmuch-hello)
(defun notmuch-sort-saved-searches (alist)
"Generate an alphabetically sorted saved searches alist."
- (sort alist (lambda (a b) (string< (car a) (car b)))))
+ (sort (copy-sequence alist) (lambda (a b) (string< (car a) (car b)))))
(defcustom notmuch-saved-search-sort-function nil
"Function used to sort the saved searches for the notmuch-hello view.
@@ -60,7 +57,7 @@ alist to be used."
(const :tag "Sort alphabetically" notmuch-sort-saved-searches)
(function :tag "Custom sort function"
:value notmuch-sort-saved-searches))
- :group 'notmuch)
+ :group 'notmuch-hello)
(defvar notmuch-hello-indent 4
"How much to indent non-headers.")
@@ -68,12 +65,12 @@ alist to be used."
(defcustom notmuch-show-logo t
"Should the notmuch logo be shown?"
:type 'boolean
- :group 'notmuch)
+ :group 'notmuch-hello)
(defcustom notmuch-show-all-tags-list nil
"Should all tags be shown in the notmuch-hello view?"
:type 'boolean
- :group 'notmuch)
+ :group 'notmuch-hello)
(defcustom notmuch-hello-tag-list-make-query nil
"Function or string to generate queries for the all tags list.
@@ -89,12 +86,12 @@ should return a filter for that tag, or nil to hide the tag."
(string :tag "Custom filter"
:value "tag:unread")
(function :tag "Custom filter function"))
- :group 'notmuch)
+ :group 'notmuch-hello)
(defcustom notmuch-hello-hide-tags nil
"List of tags to be hidden in the \"all tags\"-section."
:type '(repeat string)
- :group 'notmuch)
+ :group 'notmuch-hello)
(defface notmuch-hello-logo-background
'((((class color)
@@ -104,7 +101,8 @@ should return a filter for that tag, or nil to hide the tag."
(background light))
(:background "white")))
"Background colour for the notmuch logo."
- :group 'notmuch)
+ :group 'notmuch-hello
+ :group 'notmuch-faces)
(defcustom notmuch-column-control t
"Controls the number of columns for saved searches/tags in notmuch view.
@@ -126,11 +124,11 @@ So:
30.
- if you don't want to worry about all of this nonsense, leave
this set to `t'."
- :group 'notmuch
:type '(choice
(const :tag "Automatically calculated" t)
(integer :tag "Number of characters")
- (float :tag "Fraction of window")))
+ (float :tag "Fraction of window"))
+ :group 'notmuch-hello)
(defcustom notmuch-hello-thousands-separator " "
"The string used as a thousands separator.
@@ -138,31 +136,125 @@ So:
Typically \",\" in the US and UK and \".\" or \" \" in Europe.
The latter is recommended in the SI/ISO 31-0 standard and by the
International Bureau of Weights and Measures."
- :group 'notmuch
- :type 'string)
+ :type 'string
+ :group 'notmuch-hello)
(defcustom notmuch-hello-mode-hook nil
"Functions called after entering `notmuch-hello-mode'."
- :group 'notmuch
- :type 'hook)
+ :type 'hook
+ :group 'notmuch-hello
+ :group 'notmuch-hooks)
(defcustom notmuch-hello-refresh-hook nil
"Functions called after updating a `notmuch-hello' buffer."
:type 'hook
- :group 'notmuch)
+ :group 'notmuch-hello
+ :group 'notmuch-hooks)
(defvar notmuch-hello-url "http://notmuchmail.org"
"The `notmuch' web site.")
-(defvar notmuch-hello-recent-searches nil)
-
-(defun notmuch-hello-remember-search (search)
- (setq notmuch-hello-recent-searches
- (delete search notmuch-hello-recent-searches))
- (push search notmuch-hello-recent-searches)
- (if (> (length notmuch-hello-recent-searches)
- notmuch-recent-searches-max)
- (setq notmuch-hello-recent-searches (butlast notmuch-hello-recent-searches))))
+(defvar notmuch-hello-search-pos nil
+ "Position of search widget, if any.
+
+This should only be set by `notmuch-hello-insert-search'.")
+
+(defvar notmuch-hello-custom-section-options
+ '((:filter (string :tag "Filter for each tag"))
+ (:filter-count (string :tag "Different filter to generate message counts"))
+ (:initially-hidden (const :tag "Hide this section on startup" t))
+ (:show-empty-searches (const :tag "Show queries with no matching messages" t))
+ (:hide-if-empty (const :tag "Hide this section if all queries are empty
+\(and not shown by show-empty-searches)" t)))
+ "Various customization-options for notmuch-hello-tags/query-section.")
+
+(define-widget 'notmuch-hello-tags-section 'lazy
+ "Customize-type for notmuch-hello tag-list sections."
+ :tag "Customized tag-list section (see docstring for details)"
+ :type
+ `(list :tag ""
+ (const :tag "" notmuch-hello-insert-tags-section)
+ (string :tag "Title for this section")
+ (plist
+ :inline t
+ :options
+ ,(append notmuch-hello-custom-section-options
+ '((:hide-tags (repeat :tag "Tags that will be hidden"
+ string)))))))
+
+(define-widget 'notmuch-hello-query-section 'lazy
+ "Customize-type for custom saved-search-like sections"
+ :tag "Customized queries section (see docstring for details)"
+ :type
+ `(list :tag ""
+ (const :tag "" notmuch-hello-insert-searches)
+ (string :tag "Title for this section")
+ (repeat :tag "Queries"
+ (cons (string :tag "Name") (string :tag "Query")))
+ (plist :inline t :options ,notmuch-hello-custom-section-options)))
+
+(defcustom notmuch-hello-sections
+ (list #'notmuch-hello-insert-header
+ #'notmuch-hello-insert-saved-searches
+ #'notmuch-hello-insert-search
+ #'notmuch-hello-insert-recent-searches
+ #'notmuch-hello-insert-alltags
+ #'notmuch-hello-insert-footer)
+ "Sections for notmuch-hello.
+
+The list contains functions which are used to construct sections in
+notmuch-hello buffer. When notmuch-hello buffer is constructed,
+these functions are run in the order they appear in this list. Each
+function produces a section simply by adding content to the current
+buffer. A section should not end with an empty line, because a
+newline will be inserted after each section by `notmuch-hello'.
+
+Each function should take no arguments. If the produced section
+includes `notmuch-hello-target' (i.e. cursor should be positioned
+inside this section), the function should return this element's
+position.
+Otherwise, it should return nil.
+
+For convenience an element can also be a list of the form (FUNC ARG1
+ARG2 .. ARGN) in which case FUNC will be applied to the rest of the
+list.
+
+A \"Customized tag-list section\" item in the customize-interface
+displays a list of all tags, optionally hiding some of them. It
+is also possible to filter the list of messages matching each tag
+by an additional filter query. Similarly, the count of messages
+displayed next to the buttons can be generated by applying a
+different filter to the tag query. These filters are also
+supported for \"Customized queries section\" items."
+ :group 'notmuch-hello
+ :type
+ '(repeat
+ (choice (function-item notmuch-hello-insert-header)
+ (function-item notmuch-hello-insert-saved-searches)
+ (function-item notmuch-hello-insert-search)
+ (function-item notmuch-hello-insert-recent-searches)
+ (function-item notmuch-hello-insert-alltags)
+ (function-item notmuch-hello-insert-footer)
+ (function-item notmuch-hello-insert-inbox)
+ notmuch-hello-tags-section
+ notmuch-hello-query-section
+ (function :tag "Custom section"))))
+
+(defvar notmuch-hello-target nil
+ "Button text at position of point before rebuilding the notmuch-buffer.
+
+This variable contains the text of the button, if any, the
+point was positioned at before the notmuch-hello buffer was
+rebuilt. This should never actually be global and is defined as a
+defvar only for documentation purposes and to avoid a compiler
+warning about it occurring as a free variable.")
+
+(defvar notmuch-hello-hidden-sections nil
+ "List of sections titles whose contents are hidden")
+
+(defvar notmuch-hello-first-run t
+ "True if `notmuch-hello' is run for the first time, set to nil
+afterwards.")
(defun notmuch-hello-nice-number (n)
(let (result)
@@ -182,10 +274,14 @@ International Bureau of Weights and Measures."
(match-string 1 search)
search))
-(defun notmuch-hello-search (search)
- (let ((search (notmuch-hello-trim search)))
- (notmuch-hello-remember-search search)
- (notmuch-search search notmuch-search-oldest-first nil nil #'notmuch-hello-search-continuation)))
+(defun notmuch-hello-search (&optional search)
+ (interactive)
+ (unless (null search)
+ (setq search (notmuch-hello-trim search))
+ (let ((history-delete-duplicates t))
+ (add-to-history 'notmuch-search-history search)))
+ (notmuch-search search notmuch-search-oldest-first nil nil
+ #'notmuch-hello-search-continuation))
(defun notmuch-hello-add-saved-search (widget)
(interactive)
@@ -207,8 +303,8 @@ International Bureau of Weights and Measures."
(message "Saved '%s' as '%s'." search name)
(notmuch-hello-update)))
-(defun notmuch-hello-longest-label (tag-alist)
- (or (loop for elem in tag-alist
+(defun notmuch-hello-longest-label (searches-alist)
+ (or (loop for elem in searches-alist
maximize (length (car elem)))
0))
@@ -272,12 +368,71 @@ should be. Returns a cons cell `(tags-per-line width)'."
(* tags-per-line (+ 9 1))))
tags-per-line))))
-(defun notmuch-hello-insert-tags (tag-alist widest target)
- (let* ((tags-and-width (notmuch-hello-tags-per-line widest))
+(defun notmuch-hello-filtered-query (query filter)
+ "Constructs a query to search all messages matching QUERY and FILTER.
+
+If FILTER is a string, it is directly used in the returned query.
+
+If FILTER is a function, it is called with QUERY as a parameter and
+the string it returns is used as the query. If nil is returned,
+the entry is hidden.
+
+Otherwise, FILTER is ignored.
+"
+ (cond
+ ((functionp filter) (funcall filter query))
+ ((stringp filter)
+ (concat "(" query ") and (" filter ")"))
+ (t query)))
+
+(defun notmuch-hello-query-counts (query-alist &rest options)
+ "Compute list of counts of matched messages from QUERY-ALIST.
+
+QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)
+or (NAME QUERY COUNT-QUERY). If the latter form is used,
+COUNT-QUERY specifies an alternate query to be used to generate
+the count for the associated query.
+
+The result is the list of elements of the form (NAME QUERY COUNT).
+
+The values :show-empty-searches, :filter and :filter-count from
+options will be handled as specified for
+`notmuch-hello-insert-searches'."
+ (notmuch-remove-if-not
+ #'identity
+ (mapcar
+ (lambda (elem)
+ (let* ((name (car elem))
+ (query-and-count (if (consp (cdr elem))
+ ;; do we have a different query for the message count?
+ (cons (second elem) (third elem))
+ (cons (cdr elem) (cdr elem))))
+ (message-count
+ (string-to-number
+ (notmuch-saved-search-count
+ (notmuch-hello-filtered-query (cdr query-and-count)
+ (or (plist-get options :filter-count)
+ (plist-get options :filter)))))))
+ (and (or (plist-get options :show-empty-searches) (> message-count 0))
+ (list name (notmuch-hello-filtered-query
+ (car query-and-count) (plist-get options :filter))
+ message-count))))
+ query-alist)))
+
+(defun notmuch-hello-insert-buttons (searches)
+ "Insert buttons for SEARCHES.
+
+SEARCHES must be a list containing lists of the form (NAME QUERY COUNT), where
+QUERY is the query to start when the button for the corresponding entry is
+activated. COUNT should be the number of messages matching the query.
+Such a list can be computed with `notmuch-hello-query-counts'."
+ (let* ((widest (notmuch-hello-longest-label searches))
+ (tags-and-width (notmuch-hello-tags-per-line widest))
(tags-per-line (car tags-and-width))
- (widest (cdr tags-and-width))
+ (column-width (cdr tags-and-width))
+ (column-indent 0)
(count 0)
- (reordered-list (notmuch-hello-reflect tag-alist tags-per-line))
+ (reordered-list (notmuch-hello-reflect searches tags-per-line))
;; Hack the display of the buttons used.
(widget-push-button-prefix "")
(widget-push-button-suffix "")
@@ -287,45 +442,33 @@ should be. Returns a cons cell `(tags-per-line width)'."
(mapc (lambda (elem)
;; (not elem) indicates an empty slot in the matrix.
(when elem
- (let* ((name (car elem))
- (query (cdr elem))
- (formatted-name (format "%s " name)))
+ (if (> column-indent 0)
+ (widget-insert (make-string column-indent ? )))
+ (let* ((name (first elem))
+ (query (second elem))
+ (msg-count (third elem)))
(widget-insert (format "%8s "
- (notmuch-hello-nice-number
- (string-to-number (notmuch-saved-search-count query)))))
- (if (string= formatted-name target)
+ (notmuch-hello-nice-number msg-count)))
+ (if (string= name notmuch-hello-target)
(setq found-target-pos (point-marker)))
(widget-create 'push-button
:notify #'notmuch-hello-widget-search
:notmuch-search-terms query
- formatted-name)
- (unless (eq (% count tags-per-line) (1- tags-per-line))
- ;; If this is not the last tag on the line, insert
- ;; enough space to consume the rest of the column.
- ;; Because the button for the name is `(1+ (length
- ;; name))' long (due to the trailing space) we can
- ;; just insert `(- widest (length name))' spaces - the
- ;; column separator is included in the button if
- ;; `(equal widest (length name)'.
- (widget-insert (make-string (max 1
- (- widest (length name)))
- ? )))))
+ name)
+ (setq column-indent
+ (1+ (max 0 (- column-width (length name)))))))
(setq count (1+ count))
- (if (eq (% count tags-per-line) 0)
- (widget-insert "\n")))
+ (when (eq (% count tags-per-line) 0)
+ (setq column-indent 0)
+ (widget-insert "\n")))
reordered-list)
;; If the last line was not full (and hence did not include a
;; carriage return), insert one now.
- (if (not (eq (% count tags-per-line) 0))
- (widget-insert "\n"))
+ (unless (eq (% count tags-per-line) 0)
+ (widget-insert "\n"))
found-target-pos))
-(defun notmuch-hello-goto-search ()
- "Put point inside the `search' widget."
- (interactive)
- (goto-char notmuch-hello-search-bar-marker))
-
(defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png")))
(defun notmuch-hello-search-continuation()
@@ -355,7 +498,7 @@ should be. Returns a cons cell `(tags-per-line width)'."
(define-key map "G" 'notmuch-hello-poll-and-update)
(define-key map (kbd "<C-tab>") 'widget-backward)
(define-key map "m" 'notmuch-mua-new-mail)
- (define-key map "s" 'notmuch-hello-goto-search)
+ (define-key map "s" 'notmuch-hello-search)
map)
"Keymap for \"notmuch hello\" buffers.")
(fset 'notmuch-hello-mode-map notmuch-hello-mode-map)
@@ -370,51 +513,263 @@ Complete list of currently available key bindings:
(kill-all-local-variables)
(use-local-map notmuch-hello-mode-map)
(setq major-mode 'notmuch-hello-mode
- mode-name "notmuch-hello")
+ mode-name "notmuch-hello")
(run-mode-hooks 'notmuch-hello-mode-hook)
;;(setq buffer-read-only t)
)
-(defun notmuch-hello-generate-tag-alist ()
+(defun notmuch-hello-generate-tag-alist (&optional hide-tags)
"Return an alist from tags to queries to display in the all-tags section."
- (notmuch-remove-if-not
- #'cdr
- (mapcar (lambda (tag)
- (cons tag
- (cond
- ((functionp notmuch-hello-tag-list-make-query)
- (concat "tag:" tag " and ("
- (funcall notmuch-hello-tag-list-make-query tag) ")"))
- ((stringp notmuch-hello-tag-list-make-query)
- (concat "tag:" tag " and ("
- notmuch-hello-tag-list-make-query ")"))
- (t (concat "tag:" tag)))))
- (notmuch-remove-if-not
- (lambda (tag)
- (not (member tag notmuch-hello-hide-tags)))
- (process-lines notmuch-command "search-tags")))))
+ (mapcar (lambda (tag)
+ (cons tag (format "tag:%s" tag)))
+ (notmuch-remove-if-not
+ (lambda (tag)
+ (not (member tag hide-tags)))
+ (process-lines notmuch-command "search-tags"))))
+
+(defun notmuch-hello-insert-header ()
+ "Insert the default notmuch-hello header."
+ (when notmuch-show-logo
+ (let ((image notmuch-hello-logo))
+ ;; The notmuch logo uses transparency. That can display poorly
+ ;; when inserting the image into an emacs buffer (black logo on
+ ;; a black background), so force the background colour of the
+ ;; image. We use a face to represent the colour so that
+ ;; `defface' can be used to declare the different possible
+ ;; colours, which depend on whether the frame has a light or
+ ;; dark background.
+ (setq image (cons 'image
+ (append (cdr image)
+ (list :background (face-background 'notmuch-hello-logo-background)))))
+ (insert-image image))
+ (widget-insert " "))
+
+ (widget-insert "Welcome to ")
+ ;; Hack the display of the links used.
+ (let ((widget-link-prefix "")
+ (widget-link-suffix ""))
+ (widget-create 'link
+ :notify (lambda (&rest ignore)
+ (browse-url notmuch-hello-url))
+ :help-echo "Visit the notmuch website."
+ "notmuch")
+ (widget-insert ". ")
+ (widget-insert "You have ")
+ (widget-create 'link
+ :notify (lambda (&rest ignore)
+ (notmuch-hello-update))
+ :help-echo "Refresh"
+ (notmuch-hello-nice-number
+ (string-to-number (car (process-lines notmuch-command "count")))))
+ (widget-insert " messages.\n")))
+
+
+(defun notmuch-hello-insert-saved-searches ()
+ "Insert the saved-searches section."
+ (let ((searches (notmuch-hello-query-counts
+ (if notmuch-saved-search-sort-function
+ (funcall notmuch-saved-search-sort-function
+ notmuch-saved-searches)
+ notmuch-saved-searches)
+ :show-empty-searches notmuch-show-empty-saved-searches))
+ found-target-pos)
+ (when searches
+ (widget-insert "Saved searches: ")
+ (widget-create 'push-button
+ :notify (lambda (&rest ignore)
+ (customize-variable 'notmuch-saved-searches))
+ "edit")
+ (widget-insert "\n\n")
+ (let ((start (point)))
+ (setq found-target-pos
+ (notmuch-hello-insert-buttons searches))
+ (indent-rigidly start (point) notmuch-hello-indent)
+ found-target-pos))))
+
+(defun notmuch-hello-insert-search ()
+ "Insert a search widget."
+ (widget-insert "Search: ")
+ (setq notmuch-hello-search-pos (point-marker))
+ (widget-create 'editable-field
+ ;; Leave some space at the start and end of the
+ ;; search boxes.
+ :size (max 8 (- (window-width) notmuch-hello-indent
+ (length "Search: ")))
+ :action (lambda (widget &rest ignore)
+ (notmuch-hello-search (widget-value widget))))
+ ;; Add an invisible dot to make `widget-end-of-line' ignore
+ ;; trailing spaces in the search widget field. A dot is used
+ ;; instead of a space to make `show-trailing-whitespace'
+ ;; happy, i.e. avoid it marking the whole line as trailing
+ ;; spaces.
+ (widget-insert ".")
+ (put-text-property (1- (point)) (point) 'invisible t)
+ (widget-insert "\n"))
+
+(defun notmuch-hello-insert-recent-searches ()
+ "Insert recent searches."
+ (when notmuch-search-history
+ (widget-insert "Recent searches: ")
+ (widget-create 'push-button
+ :notify (lambda (&rest ignore)
+ (setq notmuch-search-history nil)
+ (notmuch-hello-update))
+ "clear")
+ (widget-insert "\n\n")
+ (let ((start (point)))
+ (loop for i from 1 to notmuch-hello-recent-searches-max
+ for search in notmuch-search-history do
+ (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))
+ (set widget-symbol
+ (widget-create 'editable-field
+ ;; Don't let the search boxes be
+ ;; less than 8 characters wide.
+ :size (max 8
+ (- (window-width)
+ ;; Leave some space
+ ;; at the start and
+ ;; end of the
+ ;; boxes.
+ (* 2 notmuch-hello-indent)
+ ;; 1 for the space
+ ;; before the
+ ;; `[save]' button. 6
+ ;; for the `[save]'
+ ;; button.
+ 1 6))
+ :action (lambda (widget &rest ignore)
+ (notmuch-hello-search (widget-value widget)))
+ search))
+ (widget-insert " ")
+ (widget-create 'push-button
+ :notify (lambda (widget &rest ignore)
+ (notmuch-hello-add-saved-search widget))
+ :notmuch-saved-search-widget widget-symbol
+ "save"))
+ (widget-insert "\n"))
+ (indent-rigidly start (point) notmuch-hello-indent))
+ nil))
+
+(defun notmuch-hello-insert-searches (title query-alist &rest options)
+ "Insert a section with TITLE showing a list of buttons made from QUERY-ALIST.
+
+QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)
+or (NAME QUERY COUNT-QUERY). If the latter form is used,
+COUNT-QUERY specifies an alternate query to be used to generate
+the count for the associated item.
+
+Supports the following entries in OPTIONS as a plist:
+:initially-hidden - if non-nil, section will be hidden on startup
+:show-empty-searches - show buttons with no matching messages
+:hide-if-empty - hide if no buttons would be shown
+ (only makes sense without :show-empty-searches)
+:filter - This can be a function that takes the search query as its argument and
+ returns a filter to be used in conjuction with the query for that search or nil
+ to hide the element. This can also be a string that is used as a combined with
+ each query using \"and\".
+:filter-count - Separate filter to generate the count displayed each search. Accepts
+ the same values as :filter. If :filter and :filter-count are specified, this
+ will be used instead of :filter, not in conjunction with it."
+ (widget-insert title ": ")
+ (if (and notmuch-hello-first-run (plist-get options :initially-hidden))
+ (add-to-list 'notmuch-hello-hidden-sections title))
+ (let ((is-hidden (member title notmuch-hello-hidden-sections))
+ (start (point)))
+ (if is-hidden
+ (widget-create 'push-button
+ :notify `(lambda (widget &rest ignore)
+ (setq notmuch-hello-hidden-sections
+ (delete ,title notmuch-hello-hidden-sections))
+ (notmuch-hello-update))
+ "show")
+ (widget-create 'push-button
+ :notify `(lambda (widget &rest ignore)
+ (add-to-list 'notmuch-hello-hidden-sections
+ ,title)
+ (notmuch-hello-update))
+ "hide"))
+ (widget-insert "\n")
+ (let (target-pos)
+ (when (not is-hidden)
+ (let ((searches (apply 'notmuch-hello-query-counts query-alist options)))
+ (when (or (not (plist-get options :hide-if-empty))
+ searches)
+ (widget-insert "\n")
+ (setq target-pos
+ (notmuch-hello-insert-buttons searches))
+ (indent-rigidly start (point) notmuch-hello-indent))))
+ target-pos)))
+
+(defun notmuch-hello-insert-tags-section (&optional title &rest options)
+ "Insert a section displaying all tags with message counts.
+
+TITLE defaults to \"All tags\".
+Allowed options are those accepted by `notmuch-hello-insert-searches' and the
+following:
+
+:hide-tags - List of tags that should be excluded."
+ (apply 'notmuch-hello-insert-searches
+ (or title "All tags")
+ (notmuch-hello-generate-tag-alist (plist-get options :hide-tags))
+ options))
+
+(defun notmuch-hello-insert-inbox ()
+ "Show an entry for each saved search and inboxed messages for each tag"
+ (notmuch-hello-insert-searches "What's in your inbox"
+ (append
+ (notmuch-saved-searches)
+ (notmuch-hello-generate-tag-alist))
+ :filter "tag:inbox"))
+
+(defun notmuch-hello-insert-alltags ()
+ "Insert a section displaying all tags and associated message counts"
+ (notmuch-hello-insert-tags-section
+ nil
+ :initially-hidden (not notmuch-show-all-tags-list)
+ :hide-tags notmuch-hello-hide-tags
+ :filter notmuch-hello-tag-list-make-query))
+
+(defun notmuch-hello-insert-footer ()
+ "Insert the notmuch-hello footer."
+ (let ((start (point)))
+ (widget-insert "Type a search query and hit RET to view matching threads.\n")
+ (when notmuch-search-history
+ (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")
+ (widget-insert "Save recent searches with the `save' button.\n"))
+ (when notmuch-saved-searches
+ (widget-insert "Edit saved searches with the `edit' button.\n"))
+ (widget-insert "Hit RET or click on a saved search or tag name to view matching threads.\n")
+ (widget-insert "`=' to refresh this screen. `s' to search messages. `q' to quit.\n")
+ (widget-create 'link
+ :notify (lambda (&rest ignore)
+ (customize-variable 'notmuch-hello-sections))
+ :button-prefix "" :button-suffix ""
+ "Customize")
+ (widget-insert " this page.")
+ (let ((fill-column (- (window-width) notmuch-hello-indent)))
+ (center-region start (point)))))
;;;###autoload
(defun notmuch-hello (&optional no-display)
"Run notmuch and display saved searches, known tags, etc."
(interactive)
- ; Jump through a hoop to get this value from the deprecated variable
- ; name (`notmuch-folders') or from the default value.
- (if (not notmuch-saved-searches)
+ ;; Jump through a hoop to get this value from the deprecated variable
+ ;; name (`notmuch-folders') or from the default value.
+ (unless notmuch-saved-searches
(setq notmuch-saved-searches (notmuch-saved-searches)))
(if no-display
(set-buffer "*notmuch-hello*")
(switch-to-buffer "*notmuch-hello*"))
- (let ((target (if (widget-at)
- (widget-value (widget-at))
- (condition-case nil
- (progn
- (widget-forward 1)
- (widget-value (widget-at)))
- (error nil))))
+ (let ((notmuch-hello-target (if (widget-at)
+ (widget-value (widget-at))
+ (condition-case nil
+ (progn
+ (widget-forward 1)
+ (widget-value (widget-at)))
+ (error nil))))
(inhibit-read-only t))
;; Delete all editable widget fields. Editable widget fields are
@@ -433,166 +788,20 @@ Complete list of currently available key bindings:
(mapc 'delete-overlay (car all))
(mapc 'delete-overlay (cdr all)))
- (when notmuch-show-logo
- (let ((image notmuch-hello-logo))
- ;; The notmuch logo uses transparency. That can display poorly
- ;; when inserting the image into an emacs buffer (black logo on
- ;; a black background), so force the background colour of the
- ;; image. We use a face to represent the colour so that
- ;; `defface' can be used to declare the different possible
- ;; colours, which depend on whether the frame has a light or
- ;; dark background.
- (setq image (cons 'image
- (append (cdr image)
- (list :background (face-background 'notmuch-hello-logo-background)))))
- (insert-image image))
- (widget-insert " "))
-
- (widget-insert "Welcome to ")
- ;; Hack the display of the links used.
- (let ((widget-link-prefix "")
- (widget-link-suffix ""))
- (widget-create 'link
- :notify (lambda (&rest ignore)
- (browse-url notmuch-hello-url))
- :help-echo "Visit the notmuch website."
- "notmuch")
- (widget-insert ". ")
- (widget-insert "You have ")
- (widget-create 'link
- :notify (lambda (&rest ignore)
- (notmuch-hello-update))
- :help-echo "Refresh"
- (notmuch-hello-nice-number
- (string-to-number (car (process-lines notmuch-command "count")))))
- (widget-insert " messages.\n"))
-
- (let ((found-target-pos nil)
- (final-target-pos nil))
- (let* ((saved-alist
- ;; Filter out empty saved searches if required.
- (if notmuch-show-empty-saved-searches
- notmuch-saved-searches
- (loop for elem in notmuch-saved-searches
- if (> (string-to-number (notmuch-saved-search-count (cdr elem))) 0)
- collect elem)))
- (saved-widest (notmuch-hello-longest-label saved-alist))
- (alltags-alist (if notmuch-show-all-tags-list (notmuch-hello-generate-tag-alist)))
- (alltags-widest (notmuch-hello-longest-label alltags-alist))
- (widest (max saved-widest alltags-widest)))
-
- (when saved-alist
- ;; Sort saved searches if required.
- (when notmuch-saved-search-sort-function
- (setq saved-alist
- (funcall notmuch-saved-search-sort-function saved-alist)))
- (widget-insert "\nSaved searches: ")
- (widget-create 'push-button
- :notify (lambda (&rest ignore)
- (customize-variable 'notmuch-saved-searches))
- "edit")
- (widget-insert "\n\n")
- (setq final-target-pos (point-marker))
- (let ((start (point)))
- (setq found-target-pos (notmuch-hello-insert-tags saved-alist widest target))
- (if found-target-pos
- (setq final-target-pos found-target-pos))
- (indent-rigidly start (point) notmuch-hello-indent)))
-
- (widget-insert "\nSearch: ")
- (setq notmuch-hello-search-bar-marker (point-marker))
- (widget-create 'editable-field
- ;; Leave some space at the start and end of the
- ;; search boxes.
- :size (max 8 (- (window-width) notmuch-hello-indent
- (length "Search: ")))
- :action (lambda (widget &rest ignore)
- (notmuch-hello-search (widget-value widget))))
- ;; add an invisible space to make `widget-end-of-line' ignore
- ;; trailine spaces in the search widget field
- (widget-insert " ")
- (put-text-property (1- (point)) (point) 'invisible t)
- (widget-insert "\n")
-
- (when notmuch-hello-recent-searches
- (widget-insert "\nRecent searches: ")
- (widget-create 'push-button
- :notify (lambda (&rest ignore)
- (setq notmuch-hello-recent-searches nil)
- (notmuch-hello-update))
- "clear")
- (widget-insert "\n\n")
- (let ((start (point))
- (nth 0))
- (mapc (lambda (search)
- (let ((widget-symbol (intern (format "notmuch-hello-search-%d" nth))))
- (set widget-symbol
- (widget-create 'editable-field
- ;; Don't let the search boxes be
- ;; less than 8 characters wide.
- :size (max 8
- (- (window-width)
- ;; Leave some space
- ;; at the start and
- ;; end of the
- ;; boxes.
- (* 2 notmuch-hello-indent)
- ;; 1 for the space
- ;; before the
- ;; `[save]' button. 6
- ;; for the `[save]'
- ;; button.
- 1 6))
- :action (lambda (widget &rest ignore)
- (notmuch-hello-search (widget-value widget)))
- search))
- (widget-insert " ")
- (widget-create 'push-button
- :notify (lambda (widget &rest ignore)
- (notmuch-hello-add-saved-search widget))
- :notmuch-saved-search-widget widget-symbol
- "save"))
- (widget-insert "\n")
- (setq nth (1+ nth)))
- notmuch-hello-recent-searches)
- (indent-rigidly start (point) notmuch-hello-indent)))
-
- (when alltags-alist
- (widget-insert "\nAll tags: ")
- (widget-create 'push-button
- :notify (lambda (widget &rest ignore)
- (setq notmuch-show-all-tags-list nil)
- (notmuch-hello-update))
- "hide")
- (widget-insert "\n\n")
- (let ((start (point)))
- (setq found-target-pos (notmuch-hello-insert-tags alltags-alist widest target))
- (if (not final-target-pos)
- (setq final-target-pos found-target-pos))
- (indent-rigidly start (point) notmuch-hello-indent)))
-
- (widget-insert "\n")
-
- (if (not notmuch-show-all-tags-list)
- (widget-create 'push-button
- :notify (lambda (widget &rest ignore)
- (setq notmuch-show-all-tags-list t)
- (notmuch-hello-update))
- "Show all tags")))
-
- (let ((start (point)))
- (widget-insert "\n\n")
- (widget-insert "Type a search query and hit RET to view matching threads.\n")
- (when notmuch-hello-recent-searches
- (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")
- (widget-insert "Save recent searches with the `save' button.\n"))
- (when notmuch-saved-searches
- (widget-insert "Edit saved searches with the `edit' button.\n"))
- (widget-insert "Hit RET or click on a saved search or tag name to view matching threads.\n")
- (widget-insert "`=' refreshes this screen. `s' jumps to the search box. `q' to quit.\n")
- (let ((fill-column (- (window-width) notmuch-hello-indent)))
- (center-region start (point))))
-
+ (let (final-target-pos)
+ (mapc
+ (lambda (section)
+ (let ((point-before (point))
+ (result (if (functionp section)
+ (funcall section)
+ (apply (car section) (cdr section)))))
+ (if (and (not final-target-pos) (integer-or-marker-p result))
+ (setq final-target-pos result))
+ ;; don't insert a newline when the previous section didn't show
+ ;; anything.
+ (unless (eq (point) point-before)
+ (widget-insert "\n"))))
+ notmuch-hello-sections)
(widget-setup)
(when final-target-pos
@@ -601,9 +810,10 @@ Complete list of currently available key bindings:
(widget-forward 1)))
(unless (widget-at)
- (notmuch-hello-goto-search))))
-
- (run-hooks 'notmuch-hello-refresh-hook))
+ (when notmuch-hello-search-pos
+ (goto-char notmuch-hello-search-pos)))))
+ (run-hooks 'notmuch-hello-refresh-hook)
+ (setq notmuch-hello-first-run nil))
(defun notmuch-folder ()
"Deprecated function for invoking notmuch---calling `notmuch' is preferred now."
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 0f856bf..30db58f 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -21,6 +21,11 @@
;; This is an part of an emacs-based interface to the notmuch mail system.
+(require 'mm-view)
+(require 'mm-decode)
+(require 'json)
+(eval-when-compile (require 'cl))
+
(defvar notmuch-command "notmuch"
"Command to run the notmuch binary.")
@@ -28,17 +33,54 @@
"Notmuch mail reader for Emacs."
:group 'mail)
+(defgroup notmuch-hello nil
+ "Overview of saved searches, tags, etc."
+ :group 'notmuch)
+
+(defgroup notmuch-search nil
+ "Searching and sorting mail."
+ :group 'notmuch)
+
+(defgroup notmuch-show nil
+ "Showing messages and threads."
+ :group 'notmuch)
+
+(defgroup notmuch-send nil
+ "Sending messages from Notmuch."
+ :group 'notmuch)
+
+(custom-add-to-group 'notmuch-send 'message 'custom-group)
+
+(defgroup notmuch-crypto nil
+ "Processing and display of cryptographic MIME parts."
+ :group 'notmuch)
+
+(defgroup notmuch-hooks nil
+ "Running custom code on well-defined occasions."
+ :group 'notmuch)
+
+(defgroup notmuch-external nil
+ "Running external commands from within Notmuch."
+ :group 'notmuch)
+
+(defgroup notmuch-faces nil
+ "Graphical attributes for displaying text"
+ :group 'notmuch)
+
(defcustom notmuch-search-oldest-first t
"Show the oldest mail first when searching."
:type 'boolean
- :group 'notmuch)
+ :group 'notmuch-search)
;;
+(defvar notmuch-search-history nil
+ "Variable to store notmuch searches history.")
+
(defcustom notmuch-saved-searches nil
"A list of saved searches to display."
:type '(alist :key-type string :value-type string)
- :group 'notmuch)
+ :group 'notmuch-hello)
(defvar notmuch-folders nil
"Deprecated name for what is now known as `notmuch-saved-searches'.")
@@ -96,6 +138,19 @@ the user hasn't set this variable with the old or new value."
(interactive)
(kill-buffer (current-buffer)))
+(defun notmuch-prettify-subject (subject)
+ ;; This function is used by `notmuch-search-process-filter' which
+ ;; requires that we not disrupt its' matching state.
+ (save-match-data
+ (if (and subject
+ (string-match "^[ \t]*$" subject))
+ "[No Subject]"
+ subject)))
+
+(defun notmuch-id-to-query (id)
+ "Return a query that matches the message with id ID."
+ (concat "id:\"" (replace-regexp-in-string "\"" "\"\"" id t t) "\""))
+
;;
(defun notmuch-common-do-stash (text)
@@ -114,19 +169,121 @@ the user hasn't set this variable with the old or new value."
(setq list (cdr list)))
(nreverse out)))
-; This lets us avoid compiling these replacement functions when emacs
-; is sufficiently new enough to supply them alone. We do the macro
-; treatment rather than just wrapping our defun calls in a when form
-; specifically so that the compiler never sees the code on new emacs,
-; (since the code is triggering warnings that we don't know how to get
-; rid of.
-;
-; A more clever macro here would accept a condition and a list of forms.
+;; This lets us avoid compiling these replacement functions when emacs
+;; is sufficiently new enough to supply them alone. We do the macro
+;; treatment rather than just wrapping our defun calls in a when form
+;; specifically so that the compiler never sees the code on new emacs,
+;; (since the code is triggering warnings that we don't know how to get
+;; rid of.
+;;
+;; A more clever macro here would accept a condition and a list of forms.
(defmacro compile-on-emacs-prior-to-23 (form)
"Conditionally evaluate form only on emacs < emacs-23."
(list 'when (< emacs-major-version 23)
form))
+(defun notmuch-split-content-type (content-type)
+ "Split content/type into 'content' and 'type'"
+ (split-string content-type "/"))
+
+(defun notmuch-match-content-type (t1 t2)
+ "Return t if t1 and t2 are matching content types, taking wildcards into account"
+ (let ((st1 (notmuch-split-content-type t1))
+ (st2 (notmuch-split-content-type t2)))
+ (if (or (string= (cadr st1) "*")
+ (string= (cadr st2) "*"))
+ ;; Comparison of content types should be case insensitive.
+ (string= (downcase (car st1)) (downcase (car st2)))
+ (string= (downcase t1) (downcase t2)))))
+
+(defvar notmuch-multipart/alternative-discouraged
+ '(
+ ;; Avoid HTML parts.
+ "text/html"
+ ;; multipart/related usually contain a text/html part and some associated graphics.
+ "multipart/related"
+ ))
+
+(defun notmuch-multipart/alternative-choose (types)
+ "Return a list of preferred types from the given list of types"
+ ;; Based on `mm-preferred-alternative-precedence'.
+ (let ((seq types))
+ (dolist (pref (reverse notmuch-multipart/alternative-discouraged))
+ (dolist (elem (copy-sequence seq))
+ (when (string-match pref elem)
+ (setq seq (nconc (delete elem seq) (list elem))))))
+ seq))
+
+(defun notmuch-parts-filter-by-type (parts type)
+ "Given a list of message parts, return a list containing the ones matching
+the given type."
+ (remove-if-not
+ (lambda (part) (notmuch-match-content-type (plist-get part :content-type) type))
+ parts))
+
+;; Helper for parts which are generally not included in the default
+;; JSON output.
+(defun notmuch-get-bodypart-internal (query part-number process-crypto)
+ (let ((args '("show" "--format=raw"))
+ (part-arg (format "--part=%s" part-number)))
+ (setq args (append args (list part-arg)))
+ (if process-crypto
+ (setq args (append args '("--decrypt"))))
+ (setq args (append args (list query)))
+ (with-temp-buffer
+ (let ((coding-system-for-read 'no-conversion))
+ (progn
+ (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args))
+ (buffer-string))))))
+
+(defun notmuch-get-bodypart-content (msg part nth process-crypto)
+ (or (plist-get part :content)
+ (notmuch-get-bodypart-internal (notmuch-id-to-query (plist-get msg :id)) nth process-crypto)))
+
+(defun notmuch-mm-display-part-inline (msg part nth content-type process-crypto)
+ "Use the mm-decode/mm-view functions to display a part in the
+current buffer, if possible."
+ (let ((display-buffer (current-buffer)))
+ (with-temp-buffer
+ ;; In case there is :content, the content string is already converted
+ ;; into emacs internal format. `gnus-decoded' is a fake charset,
+ ;; which means no further decoding (to be done by mm- functions).
+ (let* ((charset (if (plist-member part :content)
+ 'gnus-decoded
+ (plist-get part :content-charset)))
+ (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))
+ ;; If the user wants the part inlined, insert the content and
+ ;; test whether we are able to inline it (which includes both
+ ;; capability and suitability tests).
+ (when (mm-inlined-p handle)
+ (insert (notmuch-get-bodypart-content msg part nth process-crypto))
+ (when (mm-inlinable-p handle)
+ (set-buffer display-buffer)
+ (mm-display-part handle)
+ t))))))
+
+;; Converts a plist of headers to an alist of headers. The input plist should
+;; have symbols of the form :Header as keys, and the resulting alist will have
+;; symbols of the form 'Header as keys.
+(defun notmuch-headers-plist-to-alist (plist)
+ (loop for (key value . rest) on plist by #'cddr
+ collect (cons (intern (substring (symbol-name key) 1)) value)))
+
+(defun notmuch-combine-face-text-property (start end face)
+ "Combine FACE into the 'face text property between START and END.
+
+This function combines FACE with any existing faces between START
+and END. Attributes specified by FACE take precedence over
+existing attributes. FACE must be a face name (a symbol or
+string), a property list of face attributes, or a list of these."
+
+ (let ((pos start))
+ (while (< pos end)
+ (let ((cur (get-text-property pos 'face))
+ (next (next-single-property-change pos 'face nil end)))
+ (put-text-property pos next 'face (cons face cur))
+ (setq pos next)))))
+
;; Compatibility functions for versions of emacs before emacs 23.
;;
;; Both functions here were copied from emacs 23 with the following copyright:
@@ -155,5 +312,204 @@ was called."
(defvar notmuch-show-process-crypto nil)
(make-variable-buffer-local 'notmuch-show-process-crypto)
+;; Incremental JSON parsing
+
+(defun notmuch-json-create-parser (buffer)
+ "Return a streaming JSON parser that consumes input from BUFFER.
+
+This parser is designed to read streaming JSON whose structure is
+known to the caller. Like a typical JSON parsing interface, it
+provides a function to read a complete JSON value from the input.
+However, it extends this with an additional function that
+requires the next value in the input to be a compound value and
+descends into it, allowing its elements to be read one at a time
+or further descended into. Both functions can return 'retry to
+indicate that not enough input is available.
+
+The parser always consumes input from BUFFER's point. Hence, the
+caller is allowed to delete and data before point and may
+resynchronize after an error by moving point."
+
+ (list buffer
+ ;; Terminator stack: a stack of characters that indicate the
+ ;; end of the compound values enclosing point
+ '()
+ ;; Next: One of
+ ;; * 'expect-value if the next token must be a value, but a
+ ;; value has not yet been reached
+ ;; * 'value if point is at the beginning of a value
+ ;; * 'expect-comma if the next token must be a comma
+ 'expect-value
+ ;; Allow terminator: non-nil if the next token may be a
+ ;; terminator
+ nil
+ ;; Partial parse position: If state is 'value, a marker for
+ ;; the position of the partial parser or nil if no partial
+ ;; parsing has happened yet
+ nil
+ ;; Partial parse state: If state is 'value, the current
+ ;; `parse-partial-sexp' state
+ nil))
+
+(defmacro notmuch-json-buffer (jp) `(first ,jp))
+(defmacro notmuch-json-term-stack (jp) `(second ,jp))
+(defmacro notmuch-json-next (jp) `(third ,jp))
+(defmacro notmuch-json-allow-term (jp) `(fourth ,jp))
+(defmacro notmuch-json-partial-pos (jp) `(fifth ,jp))
+(defmacro notmuch-json-partial-state (jp) `(sixth ,jp))
+
+(defvar notmuch-json-syntax-table
+ (let ((table (make-syntax-table)))
+ ;; The standard syntax table is what we need except that "." needs
+ ;; to have word syntax instead of punctuation syntax.
+ (modify-syntax-entry ?. "w" table)
+ table)
+ "Syntax table used for incremental JSON parsing.")
+
+(defun notmuch-json-scan-to-value (jp)
+ ;; Helper function that consumes separators, terminators, and
+ ;; whitespace from point. Returns nil if it successfully reached
+ ;; the beginning of a value, 'end if it consumed a terminator, or
+ ;; 'retry if not enough input was available to reach a value. Upon
+ ;; nil return, (notmuch-json-next jp) is always 'value.
+
+ (if (eq (notmuch-json-next jp) 'value)
+ ;; We're already at a value
+ nil
+ ;; Drive the state toward 'expect-value
+ (skip-chars-forward " \t\r\n")
+ (or (when (eobp) 'retry)
+ ;; Test for the terminator for the current compound
+ (when (and (notmuch-json-allow-term jp)
+ (eq (char-after) (car (notmuch-json-term-stack jp))))
+ ;; Consume it and expect a comma or terminator next
+ (forward-char)
+ (setf (notmuch-json-term-stack jp) (cdr (notmuch-json-term-stack jp))
+ (notmuch-json-next jp) 'expect-comma
+ (notmuch-json-allow-term jp) t)
+ 'end)
+ ;; Test for a separator
+ (when (eq (notmuch-json-next jp) 'expect-comma)
+ (when (/= (char-after) ?,)
+ (signal 'json-readtable-error (list "expected ','")))
+ ;; Consume it, switch to 'expect-value, and disallow a
+ ;; terminator
+ (forward-char)
+ (skip-chars-forward " \t\r\n")
+ (setf (notmuch-json-next jp) 'expect-value
+ (notmuch-json-allow-term jp) nil)
+ ;; We moved point, so test for eobp again and fall through
+ ;; to the next test if there's more input
+ (when (eobp) 'retry))
+ ;; Next must be 'expect-value and we know this isn't
+ ;; whitespace, EOB, or a terminator, so point must be on a
+ ;; value
+ (progn
+ (assert (eq (notmuch-json-next jp) 'expect-value))
+ (setf (notmuch-json-next jp) 'value)
+ nil))))
+
+(defun notmuch-json-begin-compound (jp)
+ "Parse the beginning of a compound value and traverse inside it.
+
+Returns 'retry if there is insufficient input to parse the
+beginning of the compound. If this is able to parse the
+beginning of a compound, it moves point past the token that opens
+the compound and returns t. Later calls to `notmuch-json-read'
+will return the compound's elements.
+
+Entering JSON objects is currently unimplemented."
+
+ (with-current-buffer (notmuch-json-buffer jp)
+ ;; Disallow terminators
+ (setf (notmuch-json-allow-term jp) nil)
+ (or (notmuch-json-scan-to-value jp)
+ (if (/= (char-after) ?\[)
+ (signal 'json-readtable-error (list "expected '['"))
+ (forward-char)
+ (push ?\] (notmuch-json-term-stack jp))
+ ;; Expect a value or terminator next
+ (setf (notmuch-json-next jp) 'expect-value
+ (notmuch-json-allow-term jp) t)
+ t))))
+
+(defun notmuch-json-read (jp)
+ "Parse the value at point in JP's buffer.
+
+Returns 'retry if there is insufficient input to parse a complete
+JSON value (though it may still move point over separators or
+whitespace). If the parser is currently inside a compound value
+and the next token ends the list or object, this moves point just
+past the terminator and returns 'end. Otherwise, this moves
+point to just past the end of the value and returns the value."
+
+ (with-current-buffer (notmuch-json-buffer jp)
+ (or
+ ;; Get to a value state
+ (notmuch-json-scan-to-value jp)
+
+ ;; Can we parse a complete value?
+ (let ((complete
+ (if (looking-at "[-+0-9tfn]")
+ ;; This is a number or a keyword, so the partial
+ ;; parser isn't going to help us because a truncated
+ ;; number or keyword looks like a complete symbol to
+ ;; it. Look for something that clearly ends it.
+ (save-excursion
+ (skip-chars-forward "^]},: \t\r\n")
+ (not (eobp)))
+
+ ;; We're looking at a string, object, or array, which we
+ ;; can partial parse. If we just reached the value, set
+ ;; up the partial parser.
+ (when (null (notmuch-json-partial-state jp))
+ (setf (notmuch-json-partial-pos jp) (point-marker)))
+
+ ;; Extend the partial parse until we either reach EOB or
+ ;; get the whole value
+ (save-excursion
+ (let ((pstate
+ (with-syntax-table notmuch-json-syntax-table
+ (parse-partial-sexp
+ (notmuch-json-partial-pos jp) (point-max) 0 nil
+ (notmuch-json-partial-state jp)))))
+ ;; A complete value is available if we've reached
+ ;; depth 0 or less and encountered a complete
+ ;; subexpression.
+ (if (and (<= (first pstate) 0) (third pstate))
+ t
+ ;; Not complete. Update the partial parser state
+ (setf (notmuch-json-partial-pos jp) (point-marker)
+ (notmuch-json-partial-state jp) pstate)
+ nil))))))
+
+ (if (not complete)
+ 'retry
+ ;; We have a value. Reset the partial parse state and expect
+ ;; a comma or terminator after the value.
+ (setf (notmuch-json-next jp) 'expect-comma
+ (notmuch-json-allow-term jp) t
+ (notmuch-json-partial-pos jp) nil
+ (notmuch-json-partial-state jp) nil)
+ ;; Parse the value
+ (let ((json-object-type 'plist)
+ (json-array-type 'list)
+ (json-false nil))
+ (json-read)))))))
+
+(defun notmuch-json-eof (jp)
+ "Signal a json-error if there is more data in JP's buffer.
+
+Moves point to the beginning of any trailing data or to the end
+of the buffer if there is only trailing whitespace."
+
+ (with-current-buffer (notmuch-json-buffer jp)
+ (skip-chars-forward " \t\r\n")
+ (unless (eobp)
+ (signal 'json-error (list "Trailing garbage following JSON data")))))
+
(provide 'notmuch-lib)
+;; Local Variables:
+;; byte-compile-warnings: (not cl-functions)
+;; End:
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 6fbf82d..07eedba 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -51,13 +51,13 @@ the database.path option in the notmuch configuration file).
You will be prompted to create the directory if it does not exist
yet when sending a mail."
- :require 'notmuch-fcc-initialization
- :group 'notmuch
:type '(choice
(const :tag "No FCC header" nil)
(string :tag "A single folder")
(repeat :tag "A folder based on the From header"
- (cons regexp (string :tag "Folder")))))
+ (cons regexp (string :tag "Folder"))))
+ :require 'notmuch-fcc-initialization
+ :group 'notmuch-send)
(defun notmuch-fcc-initialization ()
"If notmuch-fcc-directories is set,
@@ -140,13 +140,12 @@ will NOT be removed or replaced."
t))
(defun notmuch-maildir-fcc-make-uniq-maildir-id ()
- (let* ((ct (current-time))
- (timeid (+ (* (car ct) 65536) (cadr ct)))
- (microseconds (car (cdr (cdr ct))))
+ (let* ((ftime (float-time))
+ (microseconds (mod (* 1000000 ftime) 1000000))
(hostname (notmuch-maildir-fcc-host-fixer system-name)))
(setq notmuch-maildir-fcc-count (+ notmuch-maildir-fcc-count 1))
(format "%d.%d_%d_%d.%s"
- timeid
+ ftime
(emacs-pid)
microseconds
notmuch-maildir-fcc-count
diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 08e5b17..d3738bf 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -20,6 +20,7 @@
;; Authors: Jesse Rosenthal <jrosenthal@jhu.edu>
(require 'message)
+(require 'notmuch-tag)
(require 'notmuch-mua)
(defcustom notmuch-message-replied-tags '("replied")
@@ -31,7 +32,7 @@ For example, if you wanted to add a \"replied\" tag and remove
the \"inbox\" and \"todo\", you would set
(\"replied\" \"-inbox\" \"-todo\"\)"
:type 'list
- :group 'notmuch)
+ :group 'notmuch-send)
(defun notmuch-message-mark-replied ()
;; get the in-reply-to header and parse it for the message id.
@@ -44,7 +45,7 @@ the \"inbox\" and \"todo\", you would set
(concat "+" str)
str))
notmuch-message-replied-tags)))
- (apply 'notmuch-tag (concat "id:" (car (car rep))) tags)))))
+ (funcall 'notmuch-tag (notmuch-id-to-query (car (car rep))) tags)))))
(add-hook 'message-send-hook 'notmuch-message-mark-replied)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 32e2e30..408b49e 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -19,37 +19,80 @@
;;
;; Authors: David Edmondson <dme@dme.org>
+(require 'json)
(require 'message)
+(require 'mm-view)
+(require 'format-spec)
(require 'notmuch-lib)
(require 'notmuch-address)
+(eval-when-compile (require 'cl))
+
;;
(defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
"Hook run before sending messages."
- :group 'notmuch
- :type 'hook)
+ :type 'hook
+ :group 'notmuch-send
+ :group 'notmuch-hooks)
+
+(defcustom notmuch-mua-compose-in 'current-window
+ (concat
+ "Where to create the mail buffer used to compose a new message.
+Possible values are `current-window' (default), `new-window' and
+`new-frame'. If set to `current-window', the mail buffer will be
+displayed in the current window, so the old buffer will be
+restored when the mail buffer is killed. If set to `new-window'
+or `new-frame', the mail buffer will be displayed in a new
+window/frame that will be destroyed when the buffer is killed.
+You may want to customize `message-kill-buffer-on-exit'
+accordingly."
+ (when (< emacs-major-version 24)
+ " Due to a known bug in Emacs 23, you should not set
+this to `new-window' if `message-kill-buffer-on-exit' is
+disabled: this would result in an incorrect behavior."))
+ :group 'notmuch-send
+ :type '(choice (const :tag "Compose in the current window" current-window)
+ (const :tag "Compose mail in a new window" new-window)
+ (const :tag "Compose mail in a new frame" new-frame)))
(defcustom notmuch-mua-user-agent-function 'notmuch-mua-user-agent-full
"Function used to generate a `User-Agent:' string. If this is
`nil' then no `User-Agent:' will be generated."
- :group 'notmuch
:type '(choice (const :tag "No user agent string" nil)
(const :tag "Full" notmuch-mua-user-agent-full)
(const :tag "Notmuch" notmuch-mua-user-agent-notmuch)
(const :tag "Emacs" notmuch-mua-user-agent-emacs)
(function :tag "Custom user agent function"
- :value notmuch-mua-user-agent-full)))
+ :value notmuch-mua-user-agent-full))
+ :group 'notmuch-send)
(defcustom notmuch-mua-hidden-headers '("^User-Agent:")
"Headers that are added to the `message-mode' hidden headers
list."
- :group 'notmuch
- :type '(repeat string))
+ :type '(repeat string)
+ :group 'notmuch-send)
;;
+(defun notmuch-mua-get-switch-function ()
+ "Get a switch function according to `notmuch-mua-compose-in'."
+ (cond ((eq notmuch-mua-compose-in 'current-window)
+ 'switch-to-buffer)
+ ((eq notmuch-mua-compose-in 'new-window)
+ 'switch-to-buffer-other-window)
+ ((eq notmuch-mua-compose-in 'new-frame)
+ 'switch-to-buffer-other-frame)
+ (t (error "Invalid value for `notmuch-mua-compose-in'"))))
+
+(defun notmuch-mua-maybe-set-window-dedicated ()
+ "Set the selected window as dedicated according to
+`notmuch-mua-compose-in'."
+ (when (or (eq notmuch-mua-compose-in 'new-frame)
+ (eq notmuch-mua-compose-in 'new-window))
+ (set-window-dedicated-p (selected-window) t)))
+
(defun notmuch-mua-user-agent-full ()
"Generate a `User-Agent:' string suitable for notmuch."
(concat (notmuch-mua-user-agent-notmuch)
@@ -71,50 +114,122 @@ list."
(push header message-hidden-headers)))
notmuch-mua-hidden-headers))
-(defun notmuch-mua-reply (query-string &optional sender)
- (let (headers
- body
- (args '("reply")))
- (if notmuch-show-process-crypto
- (setq args (append args '("--decrypt"))))
+(defun notmuch-mua-get-quotable-parts (parts)
+ (loop for part in parts
+ if (notmuch-match-content-type (plist-get part :content-type) "multipart/alternative")
+ collect (let* ((subparts (plist-get part :content))
+ (types (mapcar (lambda (part) (plist-get part :content-type)) subparts))
+ (chosen-type (car (notmuch-multipart/alternative-choose types))))
+ (loop for part in (reverse subparts)
+ if (notmuch-match-content-type (plist-get part :content-type) chosen-type)
+ return part))
+ else if (notmuch-match-content-type (plist-get part :content-type) "multipart/*")
+ append (notmuch-mua-get-quotable-parts (plist-get part :content))
+ else if (notmuch-match-content-type (plist-get part :content-type) "text/*")
+ collect part))
+
+(defun notmuch-mua-insert-quotable-part (message part)
+ (save-restriction
+ (narrow-to-region (point) (point))
+ (notmuch-mm-display-part-inline message part (plist-get part :id)
+ (plist-get part :content-type)
+ notmuch-show-process-crypto)
+ (goto-char (point-max))))
+
+;; There is a bug in emacs 23's message.el that results in a newline
+;; not being inserted after the References header, so the next header
+;; is concatenated to the end of it. This function fixes the problem,
+;; while guarding against the possibility that some current or future
+;; version of emacs has the bug fixed.
+(defun notmuch-mua-insert-references (original-func header references)
+ (funcall original-func header references)
+ (unless (bolp) (insert "\n")))
+
+(defun notmuch-mua-reply (query-string &optional sender reply-all)
+ (let ((args '("reply" "--format=json"))
+ reply
+ original)
+ (when notmuch-show-process-crypto
+ (setq args (append args '("--decrypt"))))
+
+ (if reply-all
+ (setq args (append args '("--reply-to=all")))
+ (setq args (append args '("--reply-to=sender"))))
(setq args (append args (list query-string)))
- ;; This make assumptions about the output of `notmuch reply', but
- ;; really only that the headers come first followed by a blank
- ;; line and then the body.
+
+ ;; Get the reply object as JSON, and parse it into an elisp object.
(with-temp-buffer
- (apply 'call-process (append (list notmuch-command nil (list t t) nil) args))
+ (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args))
(goto-char (point-min))
- (if (re-search-forward "^$" nil t)
- (save-excursion
- (save-restriction
- (narrow-to-region (point-min) (point))
- (goto-char (point-min))
- (setq headers (mail-header-extract)))))
- (forward-line 1)
- (setq body (buffer-substring (point) (point-max))))
- ;; If sender is non-nil, set the From: header to its value.
- (when sender
- (mail-header-set 'from sender headers))
- (let
- ;; Overlay the composition window on that being used to read
- ;; the original message.
- ((same-window-regexps '("\\*mail .*")))
- (notmuch-mua-mail (mail-header 'to headers)
- (mail-header 'subject headers)
- (message-headers-to-generate headers t '(to subject))))
- ;; insert the message body - but put it in front of the signature
- ;; if one is present
- (goto-char (point-max))
- (if (re-search-backward message-signature-separator nil t)
+ (let ((json-object-type 'plist)
+ (json-array-type 'list)
+ (json-false 'nil))
+ (setq reply (json-read))))
+
+ ;; Extract the original message to simplify the following code.
+ (setq original (plist-get reply :original))
+
+ ;; Extract the headers of both the reply and the original message.
+ (let* ((original-headers (plist-get original :headers))
+ (reply-headers (plist-get reply :reply-headers)))
+
+ ;; If sender is non-nil, set the From: header to its value.
+ (when sender
+ (plist-put reply-headers :From sender))
+ (let
+ ;; Overlay the composition window on that being used to read
+ ;; the original message.
+ ((same-window-regexps '("\\*mail .*")))
+
+ ;; We modify message-header-format-alist to get around a bug in message.el.
+ ;; See the comment above on notmuch-mua-insert-references.
+ (let ((message-header-format-alist
+ (loop for pair in message-header-format-alist
+ if (eq (car pair) 'References)
+ collect (cons 'References
+ (apply-partially
+ 'notmuch-mua-insert-references
+ (cdr pair)))
+ else
+ collect pair)))
+ (notmuch-mua-mail (plist-get reply-headers :To)
+ (plist-get reply-headers :Subject)
+ (notmuch-headers-plist-to-alist reply-headers)
+ nil (notmuch-mua-get-switch-function))))
+
+ ;; Insert the message body - but put it in front of the signature
+ ;; if one is present
+ (goto-char (point-max))
+ (if (re-search-backward message-signature-separator nil t)
(forward-line -1)
- (goto-char (point-max)))
- (insert body)
- (push-mark))
- (set-buffer-modified-p nil)
+ (goto-char (point-max)))
+
+ (let ((from (plist-get original-headers :From))
+ (date (plist-get original-headers :Date))
+ (start (point)))
+
+ ;; message-cite-original constructs a citation line based on the From and Date
+ ;; headers of the original message, which are assumed to be in the buffer.
+ (insert "From: " from "\n")
+ (insert "Date: " date "\n\n")
+
+ ;; Get the parts of the original message that should be quoted; this includes
+ ;; all the text parts, except the non-preferred ones in a multipart/alternative.
+ (let ((quotable-parts (notmuch-mua-get-quotable-parts (plist-get original :body))))
+ (mapc (apply-partially 'notmuch-mua-insert-quotable-part original) quotable-parts))
+
+ (set-mark (point))
+ (goto-char start)
+ ;; Quote the original message according to the user's configured style.
+ (message-cite-original))))
- (message-goto-body))
+ (goto-char (point-max))
+ (push-mark)
+ (message-goto-body)
+ (set-buffer-modified-p nil))
(defun notmuch-mua-forward-message ()
+ (funcall (notmuch-mua-get-switch-function) (current-buffer))
(message-forward)
(when notmuch-mua-user-agent-function
@@ -124,6 +239,7 @@ list."
(message-sort-headers)
(message-hide-headers)
(set-buffer-modified-p nil)
+ (notmuch-mua-maybe-set-window-dedicated)
(message-goto-to))
@@ -136,16 +252,17 @@ OTHER-ARGS are passed through to `message-mail'."
(when notmuch-mua-user-agent-function
(let ((user-agent (funcall notmuch-mua-user-agent-function)))
(when (not (string= "" user-agent))
- (push (cons "User-Agent" user-agent) other-headers))))
+ (push (cons 'User-Agent user-agent) other-headers))))
- (unless (mail-header 'from other-headers)
- (push (cons "From" (concat
- (notmuch-user-name) " <" (notmuch-user-primary-email) ">")) other-headers))
+ (unless (assq 'From other-headers)
+ (push (cons 'From (concat
+ (notmuch-user-name) " <" (notmuch-user-primary-email) ">")) other-headers))
(apply #'message-mail to subject other-headers other-args)
(message-sort-headers)
(message-hide-headers)
(set-buffer-modified-p nil)
+ (notmuch-mua-maybe-set-window-dedicated)
(message-goto-to))
@@ -154,16 +271,16 @@ OTHER-ARGS are passed through to `message-mail'."
If this variable is left unset, then a list will be constructed from the
name and addresses configured in the notmuch configuration file."
- :group 'notmuch
- :type '(repeat string))
+ :type '(repeat string)
+ :group 'notmuch-send)
(defcustom notmuch-always-prompt-for-sender nil
"Always prompt for the From: address when composing or forwarding a message.
This is not taken into account when replying to a message, because in that case
the From: header is already filled in by notmuch."
- :group 'notmuch
- :type 'boolean)
+ :type 'boolean
+ :group 'notmuch-send)
(defvar notmuch-mua-sender-history nil)
@@ -201,8 +318,8 @@ the From: address first."
(interactive "P")
(let ((other-headers
(when (or prompt-for-sender notmuch-always-prompt-for-sender)
- (list (cons 'from (notmuch-mua-prompt-for-sender))))))
- (notmuch-mua-mail nil nil other-headers)))
+ (list (cons 'From (notmuch-mua-prompt-for-sender))))))
+ (notmuch-mua-mail nil nil other-headers nil (notmuch-mua-get-switch-function))))
(defun notmuch-mua-new-forward-message (&optional prompt-for-sender)
"Invoke the notmuch message forwarding window.
@@ -218,13 +335,13 @@ the From: address first."
(notmuch-mua-forward-message))
(notmuch-mua-forward-message)))
-(defun notmuch-mua-new-reply (query-string &optional prompt-for-sender)
+(defun notmuch-mua-new-reply (query-string &optional prompt-for-sender reply-all)
"Invoke the notmuch reply window."
(interactive "P")
(let ((sender
(when prompt-for-sender
(notmuch-mua-prompt-for-sender))))
- (notmuch-mua-reply query-string sender)))
+ (notmuch-mua-reply query-string sender reply-all)))
(defun notmuch-mua-send-and-exit (&optional arg)
(interactive "P")
diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el
new file mode 100644
index 0000000..8c18f4b
--- /dev/null
+++ b/emacs/notmuch-print.el
@@ -0,0 +1,92 @@
+;; notmuch-print.el --- printing messages from notmuch.
+;;
+;; Copyright © David Edmondson
+;;
+;; 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 <http://www.gnu.org/licenses/>.
+;;
+;; Authors: David Edmondson <dme@dme.org>
+
+(require 'notmuch-lib)
+
+(declare-function notmuch-show-get-prop "notmuch-show" (prop &optional props))
+
+(defcustom notmuch-print-mechanism 'notmuch-print-lpr
+ "How should printing be done?"
+ :group 'notmuch-show
+ :type '(choice
+ (function :tag "Use lpr" notmuch-print-lpr)
+ (function :tag "Use ps-print" notmuch-print-ps-print)
+ (function :tag "Use ps-print then evince" notmuch-print-ps-print/evince)
+ (function :tag "Use muttprint" notmuch-print-muttprint)
+ (function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)
+ (function :tag "Using a custom function")))
+
+;; Utility functions:
+
+(defun notmuch-print-run-evince (file)
+ "View FILE using 'evince'."
+ (start-process "evince" nil "evince" file))
+
+(defun notmuch-print-run-muttprint (&optional output)
+ "Pass the contents of the current buffer to 'muttprint'.
+
+Optional OUTPUT allows passing a list of flags to muttprint."
+ (apply #'call-process-region (point-min) (point-max)
+ ;; Reads from stdin.
+ "muttprint"
+ nil nil nil
+ ;; Show the tags.
+ "--printed-headers" "Date_To_From_CC_Newsgroups_*Subject*_/Tags/"
+ output))
+
+;; User-visible functions:
+
+(defun notmuch-print-lpr (msg)
+ "Print a message buffer using lpr."
+ (lpr-buffer))
+
+(defun notmuch-print-ps-print (msg)
+ "Print a message buffer using the ps-print package."
+ (let ((subject (notmuch-prettify-subject
+ (plist-get (notmuch-show-get-prop :headers msg) :Subject))))
+ (rename-buffer subject t)
+ (ps-print-buffer)))
+
+(defun notmuch-print-ps-print/evince (msg)
+ "Preview a message buffer using ps-print and evince."
+ (let ((ps-file (make-temp-file "notmuch"))
+ (subject (notmuch-prettify-subject
+ (plist-get (notmuch-show-get-prop :headers msg) :Subject))))
+ (rename-buffer subject t)
+ (ps-print-buffer ps-file)
+ (notmuch-print-run-evince ps-file)))
+
+(defun notmuch-print-muttprint (msg)
+ "Print a message using muttprint."
+ (notmuch-print-run-muttprint))
+
+(defun notmuch-print-muttprint/evince (msg)
+ "Preview a message buffer using muttprint and evince."
+ (let ((ps-file (make-temp-file "notmuch")))
+ (notmuch-print-run-muttprint (list "--printer" (concat "TO_FILE:" ps-file)))
+ (notmuch-print-run-evince ps-file)))
+
+(defun notmuch-print-message (msg)
+ "Print a message using the user-selected mechanism."
+ (set-buffer-modified-p nil)
+ (funcall notmuch-print-mechanism msg))
+
+(provide 'notmuch-print)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 034db87..dcfc190 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -30,14 +30,16 @@
(require 'goto-addr)
(require 'notmuch-lib)
+(require 'notmuch-tag)
(require 'notmuch-query)
(require 'notmuch-wash)
(require 'notmuch-mua)
(require 'notmuch-crypto)
+(require 'notmuch-print)
(declare-function notmuch-call-notmuch-process "notmuch" (&rest args))
(declare-function notmuch-fontify-headers "notmuch" nil)
-(declare-function notmuch-select-tag-with-completion "notmuch" (prompt &rest search-terms))
+(declare-function notmuch-search-next-thread "notmuch" nil)
(declare-function notmuch-search-show-thread "notmuch" nil)
(defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
@@ -47,8 +49,8 @@ For an open message, all of these headers will be made visible
according to `notmuch-message-headers-visible' or can be toggled
with `notmuch-show-toggle-headers'. For a closed message, only
the first header in the list will be visible."
- :group 'notmuch
- :type '(repeat string))
+ :type '(repeat string)
+ :group 'notmuch-show)
(defcustom notmuch-message-headers-visible t
"Should the headers be visible by default?
@@ -58,41 +60,44 @@ If this value is non-nil, then all of the headers defined in
of each message. Otherwise, these headers will be hidden and
`notmuch-show-toggle-headers' can be used to make the visible for
any given message."
- :group 'notmuch
- :type 'boolean)
+ :type 'boolean
+ :group 'notmuch-show)
(defcustom notmuch-show-relative-dates t
"Display relative dates in the message summary line."
- :group 'notmuch
- :type 'boolean)
+ :type 'boolean
+ :group 'notmuch-show)
(defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers)
"A list of functions called to decorate the headers listed in
`notmuch-message-headers'.")
-(defcustom notmuch-show-hook nil
+(defcustom notmuch-show-hook '(notmuch-show-turn-on-visual-line-mode)
"Functions called after populating a `notmuch-show' buffer."
- :group 'notmuch
- :type 'hook)
+ :type 'hook
+ :options '(notmuch-show-turn-on-visual-line-mode)
+ :group 'notmuch-show
+ :group 'notmuch-hooks)
(defcustom notmuch-show-insert-text/plain-hook '(notmuch-wash-wrap-long-lines
notmuch-wash-tidy-citations
notmuch-wash-elide-blank-lines
notmuch-wash-excerpt-citations)
"Functions used to improve the display of text/plain parts."
- :group 'notmuch
:type 'hook
:options '(notmuch-wash-convert-inline-patch-to-part
notmuch-wash-wrap-long-lines
notmuch-wash-tidy-citations
notmuch-wash-elide-blank-lines
- notmuch-wash-excerpt-citations))
+ notmuch-wash-excerpt-citations)
+ :group 'notmuch-show
+ :group 'notmuch-hooks)
;; Mostly useful for debugging.
(defcustom notmuch-show-all-multipart/alternative-parts t
"Should all parts of multipart/alternative parts be shown?"
- :group 'notmuch
- :type 'boolean)
+ :type 'boolean
+ :group 'notmuch-show)
(defcustom notmuch-show-indent-messages-width 1
"Width of message indentation in threads.
@@ -101,14 +106,82 @@ Messages are shown indented according to their depth in a thread.
This variable determines the width of this indentation measured
in number of blanks. Defaults to `1', choose `0' to disable
indentation."
- :group 'notmuch
- :type 'integer)
+ :type 'integer
+ :group 'notmuch-show)
(defcustom notmuch-show-indent-multipart nil
"Should the sub-parts of a multipart/* part be indented?"
;; dme: Not sure which is a good default.
- :group 'notmuch
- :type 'boolean)
+ :type 'boolean
+ :group 'notmuch-show)
+
+(defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part
+ "Default part header button action (on ENTER or mouse click)."
+ :group 'notmuch-show
+ :type '(choice (const :tag "Save part"
+ notmuch-show-save-part)
+ (const :tag "View part"
+ notmuch-show-view-part)
+ (const :tag "View interactively"
+ notmuch-show-interactively-view-part)))
+
+(defcustom notmuch-show-only-matching-messages nil
+ "Only matching messages are shown by default."
+ :type 'boolean
+ :group 'notmuch-show)
+
+(defvar notmuch-show-thread-id nil)
+(make-variable-buffer-local 'notmuch-show-thread-id)
+(put 'notmuch-show-thread-id 'permanent-local t)
+
+(defvar notmuch-show-parent-buffer nil)
+(make-variable-buffer-local 'notmuch-show-parent-buffer)
+(put 'notmuch-show-parent-buffer 'permanent-local t)
+
+(defvar notmuch-show-query-context nil)
+(make-variable-buffer-local 'notmuch-show-query-context)
+(put 'notmuch-show-query-context 'permanent-local t)
+
+(defvar notmuch-show-process-crypto nil)
+(make-variable-buffer-local 'notmuch-show-process-crypto)
+(put 'notmuch-show-process-crypto 'permanent-local t)
+
+(defvar notmuch-show-elide-non-matching-messages nil)
+(make-variable-buffer-local 'notmuch-show-elide-non-matching-messages)
+(put 'notmuch-show-elide-non-matching-messages 'permanent-local t)
+
+(defvar notmuch-show-indent-content t)
+(make-variable-buffer-local 'notmuch-show-indent-content)
+(put 'notmuch-show-indent-content 'permanent-local t)
+
+(defcustom notmuch-show-stash-mlarchive-link-alist
+ '(("Gmane" . "http://mid.gmane.org/")
+ ("MARC" . "http://marc.info/?i=")
+ ("Mail Archive, The" . "http://mail-archive.com/search?l=mid&q=")
+ ;; FIXME: can these services be searched by `Message-Id' ?
+ ;; ("MarkMail" . "http://markmail.org/")
+ ;; ("Nabble" . "http://nabble.com/")
+ ;; ("opensubscriber" . "http://opensubscriber.com/")
+ )
+ "List of Mailing List Archives to use when stashing links.
+
+These URIs are concatenated with the current message's
+Message-Id in `notmuch-show-stash-mlarchive-link'."
+ :type '(alist :key-type (string :tag "Name")
+ :value-type (string :tag "URL"))
+ :group 'notmuch-show)
+
+(defcustom notmuch-show-stash-mlarchive-link-default "Gmane"
+ "Default Mailing List Archive to use when stashing links.
+
+This is used when `notmuch-show-stash-mlarchive-link' isn't
+provided with an MLA argument nor `completing-read' input."
+ :type `(choice
+ ,@(mapcar
+ (lambda (mla)
+ (list 'const :tag (car mla) :value (car mla)))
+ notmuch-show-stash-mlarchive-link-alist))
+ :group 'notmuch-show)
(defmacro with-current-notmuch-show-message (&rest body)
"Evaluate body with current buffer set to the text of current message"
@@ -120,18 +193,22 @@ indentation."
,@body)
(kill-buffer buf)))))
+(defun notmuch-show-turn-on-visual-line-mode ()
+ "Enable Visual Line mode."
+ (visual-line-mode t))
+
(defun notmuch-show-view-all-mime-parts ()
"Use external viewers to view all attachments from the current message."
(interactive)
(with-current-notmuch-show-message
- ; We override the mm-inline-media-tests to indicate which message
- ; parts are already sufficiently handled by the original
- ; presentation of the message in notmuch-show mode. These parts
- ; will be inserted directly into the temporary buffer of
- ; with-current-notmuch-show-message and silently discarded.
- ;
- ; Any MIME part not explicitly mentioned here will be handled by an
- ; external viewer as configured in the various mailcap files.
+ ;; We override the mm-inline-media-tests to indicate which message
+ ;; parts are already sufficiently handled by the original
+ ;; presentation of the message in notmuch-show mode. These parts
+ ;; will be inserted directly into the temporary buffer of
+ ;; with-current-notmuch-show-message and silently discarded.
+ ;;
+ ;; Any MIME part not explicitly mentioned here will be handled by an
+ ;; external viewer as configured in the various mailcap files.
(let ((mm-inline-media-tests '(
("text/.*" ignore identity)
("application/pgp-signature" ignore identity)
@@ -186,6 +263,54 @@ indentation."
mm-handle (> (notmuch-count-attachments mm-handle) 1))))
(message "Done"))
+(defun notmuch-show-with-message-as-text (fn)
+ "Apply FN to a text representation of the current message.
+
+FN is called with one argument, the message properties. It should
+operation on the contents of the current buffer."
+
+ ;; Remake the header to ensure that all information is available.
+ (let* ((to (notmuch-show-get-to))
+ (cc (notmuch-show-get-cc))
+ (from (notmuch-show-get-from))
+ (subject (notmuch-show-get-subject))
+ (date (notmuch-show-get-date))
+ (tags (notmuch-show-get-tags))
+ (depth (notmuch-show-get-depth))
+
+ (header (concat
+ "Subject: " subject "\n"
+ "To: " to "\n"
+ (if (not (string= cc ""))
+ (concat "Cc: " cc "\n")
+ "")
+ "From: " from "\n"
+ "Date: " date "\n"
+ (if tags
+ (concat "Tags: "
+ (mapconcat #'identity tags ", ") "\n")
+ "")))
+ (all (buffer-substring (notmuch-show-message-top)
+ (notmuch-show-message-bottom)))
+
+ (props (notmuch-show-get-message-properties))
+ (indenting notmuch-show-indent-content))
+ (with-temp-buffer
+ (insert all)
+ (if indenting
+ (indent-rigidly (point-min) (point-max) (- depth)))
+ ;; Remove the original header.
+ (goto-char (point-min))
+ (re-search-forward "^$" (point-max) nil)
+ (delete-region (point-min) (point))
+ (insert header)
+ (funcall fn props))))
+
+(defun notmuch-show-print-message ()
+ "Print the current message."
+ (interactive)
+ (notmuch-show-with-message-as-text 'notmuch-print-message))
+
(defun notmuch-show-fontify-header ()
(let ((face (cond
((looking-at "[Tt]o:")
@@ -230,21 +355,57 @@ indentation."
"Try to clean a single email ADDRESS for display. Return
unchanged ADDRESS if parsing fails."
(condition-case nil
- (let* ((parsed (mail-header-parse-address address))
- (address (car parsed))
- (name (cdr parsed)))
- ;; Remove double quotes. They might be required during transport,
- ;; but we don't need to see them.
- (when name
- (setq name (replace-regexp-in-string "\"" "" name)))
+ (let (p-name p-address)
+ ;; It would be convenient to use `mail-header-parse-address',
+ ;; but that expects un-decoded mailbox parts, whereas our
+ ;; mailbox parts are already decoded (and hence may contain
+ ;; UTF-8). Given that notmuch should handle most of the awkward
+ ;; cases, some simple string deconstruction should be sufficient
+ ;; here.
+ (cond
+ ;; "User <user@dom.ain>" style.
+ ((string-match "\\(.*\\) <\\(.*\\)>" address)
+ (setq p-name (match-string 1 address)
+ p-address (match-string 2 address)))
+
+ ;; "<user@dom.ain>" style.
+ ((string-match "<\\(.*\\)>" address)
+ (setq p-address (match-string 1 address)))
+
+ ;; Everything else.
+ (t
+ (setq p-address address)))
+
+ (when p-name
+ ;; Remove elements of the mailbox part that are not relevant for
+ ;; display, even if they are required during transport:
+ ;;
+ ;; Backslashes.
+ (setq p-name (replace-regexp-in-string "\\\\" "" p-name))
+
+ ;; Outer single and double quotes, which might be nested.
+ (loop
+ with start-of-loop
+ do (setq start-of-loop p-name)
+
+ when (string-match "^\"\\(.*\\)\"$" p-name)
+ do (setq p-name (match-string 1 p-name))
+
+ when (string-match "^'\\(.*\\)'$" p-name)
+ do (setq p-name (match-string 1 p-name))
+
+ until (string= start-of-loop p-name)))
+
;; If the address is 'foo@bar.com <foo@bar.com>' then show just
;; 'foo@bar.com'.
- (when (string= name address)
- (setq name nil))
-
- (if (not name)
- address
- (concat name " <" address ">")))
+ (when (string= p-name p-address)
+ (setq p-name nil))
+
+ ;; If no name results, return just the address.
+ (if (not p-name)
+ p-address
+ ;; Otherwise format the name and address together.
+ (concat p-name " <" p-address ">")))
(error address)))
(defun notmuch-show-insert-headerline (headers date tags depth)
@@ -281,10 +442,22 @@ message at DEPTH in the current thread."
(run-hooks 'notmuch-show-markup-headers-hook)))))
(define-button-type 'notmuch-show-part-button-type
- 'action 'notmuch-show-part-button-action
+ 'action 'notmuch-show-part-button-default
+ 'keymap 'notmuch-show-part-button-map
'follow-link t
'face 'message-mml)
+(defvar notmuch-show-part-button-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map button-map)
+ (define-key map "s" 'notmuch-show-part-button-save)
+ (define-key map "v" 'notmuch-show-part-button-view)
+ (define-key map "o" 'notmuch-show-part-button-interactively-view)
+ (define-key map "|" 'notmuch-show-part-button-pipe)
+ map)
+ "Submap for button commands")
+(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)
+
(defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)
(let ((button))
(setq button
@@ -299,70 +472,71 @@ message at DEPTH in the current thread."
" ]")
:type 'notmuch-show-part-button-type
:notmuch-part nth
- :notmuch-filename name))
+ :notmuch-filename name
+ :notmuch-content-type content-type))
(insert "\n")
;; return button
button))
;; Functions handling particular MIME parts.
-(defun notmuch-show-save-part (message-id nth &optional filename)
- (let ((process-crypto notmuch-show-process-crypto))
- (with-temp-buffer
- (setq notmuch-show-process-crypto process-crypto)
- ;; Always acquires the part via `notmuch part', even if it is
- ;; available in the JSON output.
- (insert (notmuch-show-get-bodypart-internal message-id nth))
- (let ((file (read-file-name
- "Filename to save as: "
- (or mailcap-download-directory "~/")
- nil nil
- filename)))
- ;; Don't re-compress .gz & al. Arguably we should make
- ;; `file-name-handler-alist' nil, but that would chop
- ;; ange-ftp, which is reasonable to use here.
- (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))
-
-(defun notmuch-show-mm-display-part-inline (msg part nth content-type)
- "Use the mm-decode/mm-view functions to display a part in the
-current buffer, if possible."
- (let ((display-buffer (current-buffer)))
- (with-temp-buffer
- (let* ((charset (plist-get part :content-charset))
- (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))
- (if (and (mm-inlinable-p handle)
- (mm-inlined-p handle))
- (let ((content (notmuch-show-get-bodypart-content msg part nth)))
- (insert content)
- (set-buffer display-buffer)
- (mm-display-part handle)
- t)
- nil)))))
-
-(defvar notmuch-show-multipart/alternative-discouraged
- '(
- ;; Avoid HTML parts.
- "text/html"
- ;; multipart/related usually contain a text/html part and some associated graphics.
- "multipart/related"
- ))
+(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)
+ (declare (indent 2))
+ (let ((process-crypto (make-symbol "process-crypto")))
+ `(let ((,process-crypto notmuch-show-process-crypto))
+ (with-temp-buffer
+ (setq notmuch-show-process-crypto ,process-crypto)
+ ;; Always acquires the part via `notmuch part', even if it is
+ ;; available in the JSON output.
+ (insert (notmuch-get-bodypart-internal ,message-id ,nth notmuch-show-process-crypto))
+ ,@body))))
+
+(defun notmuch-show-save-part (message-id nth &optional filename content-type)
+ (notmuch-with-temp-part-buffer message-id nth
+ (let ((file (read-file-name
+ "Filename to save as: "
+ (or mailcap-download-directory "~/")
+ nil nil
+ filename)))
+ ;; Don't re-compress .gz & al. Arguably we should make
+ ;; `file-name-handler-alist' nil, but that would chop
+ ;; ange-ftp, which is reasonable to use here.
+ (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t))))
+
+(defun notmuch-show-view-part (message-id nth &optional filename content-type )
+ (notmuch-with-temp-part-buffer message-id nth
+ ;; set mm-inlined-types to nil to force an external viewer
+ (let ((handle (mm-make-handle (current-buffer) (list content-type)))
+ (mm-inlined-types nil))
+ ;; We override mm-save-part as notmuch-show-save-part is better
+ ;; since it offers the filename. We need to lexically bind
+ ;; everything we need for notmuch-show-save-part to prevent
+ ;; potential dynamic shadowing.
+ (lexical-let ((message-id message-id)
+ (nth nth)
+ (filename filename)
+ (content-type content-type))
+ (flet ((mm-save-part (&rest args) (notmuch-show-save-part
+ message-id nth filename content-type)))
+ (mm-display-part handle))))))
+
+(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)
+ (notmuch-with-temp-part-buffer message-id nth
+ (let ((handle (mm-make-handle (current-buffer) (list content-type))))
+ (mm-interactively-view-part handle))))
+
+(defun notmuch-show-pipe-part (message-id nth &optional filename content-type)
+ (notmuch-with-temp-part-buffer message-id nth
+ (let ((handle (mm-make-handle (current-buffer) (list content-type))))
+ (mm-pipe-part handle))))
(defun notmuch-show-multipart/*-to-list (part)
(mapcar (lambda (inner-part) (plist-get inner-part :content-type))
(plist-get part :content)))
-(defun notmuch-show-multipart/alternative-choose (types)
- ;; Based on `mm-preferred-alternative-precedence'.
- (let ((seq types))
- (dolist (pref (reverse notmuch-show-multipart/alternative-discouraged))
- (dolist (elem (copy-sequence seq))
- (when (string-match pref elem)
- (setq seq (nconc (delete elem seq) (list elem))))))
- seq))
-
(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)
(notmuch-show-insert-part-header nth declared-type content-type nil)
- (let ((chosen-type (car (notmuch-show-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
+ (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
(inner-parts (plist-get part :content))
(start (point)))
;; This inserts all parts of the chosen type rather than just one,
@@ -427,8 +601,8 @@ current buffer, if possible."
;; times (hundreds!), which results in many calls to
;; `notmuch part'.
(unless content
- (setq content (notmuch-show-get-bodypart-internal (concat "id:" message-id)
- part-number))
+ (setq content (notmuch-get-bodypart-internal (notmuch-id-to-query message-id)
+ part-number notmuch-show-process-crypto))
(with-current-buffer w3m-current-buffer
(notmuch-show-w3m-cid-store-internal url
message-id
@@ -468,7 +642,7 @@ current buffer, if possible."
(sigstatus (car (plist-get part :sigstatus))))
(notmuch-crypto-insert-sigstatus-button sigstatus from))
;; if we're not adding sigstatus, tell the user how they can get it
- (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))
+ (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))
(let ((inner-parts (plist-get part :content))
(start (point)))
@@ -494,7 +668,7 @@ current buffer, if possible."
(sigstatus (car (plist-get part :sigstatus))))
(notmuch-crypto-insert-sigstatus-button sigstatus from))))
;; if we're not adding encstatus, tell the user how they can get it
- (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))
+ (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))
(let ((inner-parts (plist-get part :content))
(start (point)))
@@ -548,17 +722,17 @@ current buffer, if possible."
;; insert a header to make this clear.
(if (> nth 1)
(notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename)))
- (insert (notmuch-show-get-bodypart-content msg part nth))
+ (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))
(save-excursion
(save-restriction
(narrow-to-region start (point-max))
(run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))
t)
-(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type)
+(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth declared-type)
(notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))
(insert (with-temp-buffer
- (insert (notmuch-show-get-bodypart-content msg part nth))
+ (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))
(goto-char (point-min))
(let ((file (make-temp-file "notmuch-ical"))
result)
@@ -573,6 +747,10 @@ current buffer, if possible."
result)))
t)
+;; For backwards compatibility.
+(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type)
+ (notmuch-show-insert-part-text/calendar msg part content-type nth depth declared-type))
+
(defun notmuch-show-insert-part-application/octet-stream (msg part content-type nth depth declared-type)
;; If we can deduce a MIME type from the filename of the attachment,
;; do so and pass it on to the handler for that type.
@@ -596,14 +774,11 @@ current buffer, if possible."
(defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)
;; This handler _must_ succeed - it is the handler of last resort.
(notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))
- (notmuch-show-mm-display-part-inline msg part nth content-type)
+ (notmuch-mm-display-part-inline msg part nth content-type notmuch-show-process-crypto)
t)
;; Functions for determining how to handle MIME parts.
-(defun notmuch-show-split-content-type (content-type)
- (split-string content-type "/"))
-
(defun notmuch-show-handlers-for (content-type)
"Return a list of content handlers for a part of type CONTENT-TYPE."
(let (result)
@@ -614,32 +789,11 @@ current buffer, if possible."
(list (intern (concat "notmuch-show-insert-part-*/*"))
(intern (concat
"notmuch-show-insert-part-"
- (car (notmuch-show-split-content-type content-type))
+ (car (notmuch-split-content-type content-type))
"/*"))
(intern (concat "notmuch-show-insert-part-" content-type))))
result))
-;; Helper for parts which are generally not included in the default
-;; JSON output.
-;; Uses the buffer-local variable notmuch-show-process-crypto to
-;; determine if parts should be decrypted first.
-(defun notmuch-show-get-bodypart-internal (message-id part-number)
- (let ((args '("show" "--format=raw"))
- (part-arg (format "--part=%s" part-number)))
- (setq args (append args (list part-arg)))
- (if notmuch-show-process-crypto
- (setq args (append args '("--decrypt"))))
- (setq args (append args (list message-id)))
- (with-temp-buffer
- (let ((coding-system-for-read 'no-conversion))
- (progn
- (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args))
- (buffer-string))))))
-
-(defun notmuch-show-get-bodypart-content (msg part nth)
- (or (plist-get part :content)
- (notmuch-show-get-bodypart-internal (concat "id:" (plist-get msg :id)) nth)))
-
;;
(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth declared-type)
@@ -660,8 +814,8 @@ current buffer, if possible."
;; part, so we make sure that we're down at the end.
(goto-char (point-max))
;; Ensure that the part ends with a carriage return.
- (if (not (bolp))
- (insert "\n")))
+ (unless (bolp)
+ (insert "\n")))
(defun notmuch-show-insert-body (msg body depth)
"Insert the body BODY at depth DEPTH in the current thread."
@@ -671,7 +825,7 @@ current buffer, if possible."
(make-symbol (concat "notmuch-show-" type)))
(defun notmuch-show-strip-re (string)
- (replace-regexp-in-string "\\([Rr]e: *\\)+" "" string))
+ (replace-regexp-in-string "^\\([Rr]e: *\\)+" "" string))
(defvar notmuch-show-previous-subject "")
(make-variable-buffer-local 'notmuch-show-previous-subject)
@@ -723,8 +877,6 @@ current buffer, if possible."
;; compatible with the existing implementation. This just sets it
;; to after the first header.
(notmuch-show-insert-headers headers)
- ;; Headers should include a blank line (backwards compatibility).
- (insert "\n")
(save-excursion
(goto-char content-start)
;; If the subject of this message is the same as that of the
@@ -739,15 +891,19 @@ current buffer, if possible."
(setq notmuch-show-previous-subject bare-subject)
(setq body-start (point-marker))
- (notmuch-show-insert-body msg (plist-get msg :body) depth)
+ ;; A blank line between the headers and the body.
+ (insert "\n")
+ (notmuch-show-insert-body msg (plist-get msg :body)
+ (if notmuch-show-indent-content depth 0))
;; Ensure that the body ends with a newline.
- (if (not (bolp))
- (insert "\n"))
+ (unless (bolp)
+ (insert "\n"))
(setq body-end (point-marker))
(setq content-end (point-marker))
;; Indent according to the depth in the thread.
- (indent-rigidly content-start content-end (* notmuch-show-indent-messages-width depth))
+ (if notmuch-show-indent-content
+ (indent-rigidly content-start content-end (* notmuch-show-indent-messages-width depth)))
(setq message-end (point-max-marker))
@@ -761,6 +917,8 @@ current buffer, if possible."
(overlay-put headers-overlay 'priority 10))
(overlay-put (make-overlay body-start body-end) 'invisible message-invis-spec)
+ (plist-put msg :depth depth)
+
;; Save the properties for this message. Currently this saves the
;; entire message (augmented it with other stuff), which seems
;; like overkill. We might save a reduced subset (for example, not
@@ -772,13 +930,43 @@ current buffer, if possible."
;; Message visibility depends on whether it matched the search
;; criteria.
- (notmuch-show-message-visible msg (plist-get msg :match))))
+ (notmuch-show-message-visible msg (and (plist-get msg :match)
+ (not (plist-get msg :excluded))))))
+
+(defun notmuch-show-toggle-process-crypto ()
+ "Toggle the processing of cryptographic MIME parts."
+ (interactive)
+ (setq notmuch-show-process-crypto (not notmuch-show-process-crypto))
+ (message (if notmuch-show-process-crypto
+ "Processing cryptographic MIME parts."
+ "Not processing cryptographic MIME parts."))
+ (notmuch-show-refresh-view))
+
+(defun notmuch-show-toggle-elide-non-matching ()
+ "Toggle the display of non-matching messages."
+ (interactive)
+ (setq notmuch-show-elide-non-matching-messages (not notmuch-show-elide-non-matching-messages))
+ (message (if notmuch-show-elide-non-matching-messages
+ "Showing matching messages only."
+ "Showing all messages."))
+ (notmuch-show-refresh-view))
+
+(defun notmuch-show-toggle-thread-indentation ()
+ "Toggle the indentation of threads."
+ (interactive)
+ (setq notmuch-show-indent-content (not notmuch-show-indent-content))
+ (message (if notmuch-show-indent-content
+ "Content is indented."
+ "Content is not indented."))
+ (notmuch-show-refresh-view))
(defun notmuch-show-insert-tree (tree depth)
"Insert the message tree TREE at depth DEPTH in the current thread."
(let ((msg (car tree))
(replies (cadr tree)))
- (notmuch-show-insert-msg msg depth)
+ ;; We test whether there is a message or just some replies.
+ (when msg
+ (notmuch-show-insert-msg msg depth))
(notmuch-show-insert-thread replies (1+ depth))))
(defun notmuch-show-insert-thread (thread depth)
@@ -789,15 +977,6 @@ current buffer, if possible."
"Insert the forest of threads FOREST."
(mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
-(defvar notmuch-show-thread-id nil)
-(make-variable-buffer-local 'notmuch-show-thread-id)
-(defvar notmuch-show-parent-buffer nil)
-(make-variable-buffer-local 'notmuch-show-parent-buffer)
-(defvar notmuch-show-query-context nil)
-(make-variable-buffer-local 'notmuch-show-query-context)
-(defvar notmuch-show-buffer-name nil)
-(make-variable-buffer-local 'notmuch-show-buffer-name)
-
(defun notmuch-show-buttonise-links (start end)
"Buttonise URLs and mail addresses between START and END.
@@ -817,7 +996,7 @@ a corresponding notmuch search."
'face goto-address-mail-face))))
;;;###autoload
-(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name crypto-switch)
+(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name)
"Run \"notmuch show\" with the given thread ID and display results.
The optional PARENT-BUFFER is the notmuch-search buffer from
@@ -832,80 +1011,113 @@ non-nil.
The optional BUFFER-NAME provides the name of the buffer in
which the message thread is shown. If it is nil (which occurs
when the command is called interactively) the argument to the
-function is used.
-
-The optional CRYPTO-SWITCH toggles the value of the
-notmuch-crypto-process-mime customization variable for this show
-buffer."
+function is used."
(interactive "sNotmuch show: ")
- (let* ((process-crypto (if crypto-switch
- (not notmuch-crypto-process-mime)
- notmuch-crypto-process-mime)))
- (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))
-
-(defun notmuch-show-worker (thread-id parent-buffer query-context buffer-name process-crypto)
- (let* ((buffer-name (generate-new-buffer-name
- (or buffer-name
- (concat "*notmuch-" thread-id "*"))))
- (buffer (get-buffer-create buffer-name))
- (inhibit-read-only t))
- (switch-to-buffer buffer)
+ (let ((buffer-name (generate-new-buffer-name
+ (or buffer-name
+ (concat "*notmuch-" thread-id "*")))))
+ (switch-to-buffer (get-buffer-create buffer-name))
+ ;; Set the default value for `notmuch-show-process-crypto' in this
+ ;; buffer.
+ (setq notmuch-show-process-crypto notmuch-crypto-process-mime)
+ ;; Set the default value for
+ ;; `notmuch-show-elide-non-matching-messages' in this buffer. If
+ ;; there is a prefix argument, invert the default.
+ (setq notmuch-show-elide-non-matching-messages notmuch-show-only-matching-messages)
+ (if current-prefix-arg
+ (setq notmuch-show-elide-non-matching-messages (not notmuch-show-elide-non-matching-messages)))
+
+ (setq notmuch-show-thread-id thread-id
+ notmuch-show-parent-buffer parent-buffer
+ notmuch-show-query-context query-context)
+ (notmuch-show-build-buffer)
+ (notmuch-show-goto-first-wanted-message)))
+
+(defun notmuch-show-build-buffer ()
+ (let ((inhibit-read-only t))
+
(notmuch-show-mode)
;; Don't track undo information for this buffer
(set 'buffer-undo-list t)
- (setq notmuch-show-thread-id thread-id)
- (setq notmuch-show-parent-buffer parent-buffer)
- (setq notmuch-show-query-context query-context)
- (setq notmuch-show-buffer-name buffer-name)
- (setq notmuch-show-process-crypto process-crypto)
-
(erase-buffer)
(goto-char (point-min))
(save-excursion
- (let* ((basic-args (list thread-id))
- (args (if query-context
- (append (list "\'") basic-args (list "and (" query-context ")\'"))
- (append (list "\'") basic-args (list "\'")))))
- (notmuch-show-insert-forest (notmuch-query-get-threads args))
+ (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"
+ (when notmuch-show-elide-non-matching-messages
+ (list "--entire-thread=false")))))
+
+ (notmuch-show-insert-forest (notmuch-query-get-threads (append cli-args args)))
;; If the query context reduced the results to nothing, run
;; the basic query.
(when (and (eq (buffer-size) 0)
- query-context)
+ notmuch-show-query-context)
(notmuch-show-insert-forest
- (notmuch-query-get-threads basic-args))))
+ (notmuch-query-get-threads (append cli-args basic-args)))))
(jit-lock-register #'notmuch-show-buttonise-links)
- ;; Act on visual lines rather than logical lines.
- (visual-line-mode t)
-
(run-hooks 'notmuch-show-hook))
- ;; Move straight to the first open message
- (if (not (notmuch-show-message-visible-p))
- (notmuch-show-next-open-message))
+ ;; Set the header line to the subject of the first message.
+ (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-subject)))))
- ;; Set the header line to the subject of the first open message.
- (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-subject)))
+(defun notmuch-show-capture-state ()
+ "Capture the state of the current buffer.
- (notmuch-show-mark-read)))
+This includes:
+ - the list of open messages,
+ - the current message."
+ (list (notmuch-show-get-message-id) (notmuch-show-get-message-ids-for-open-messages)))
-(defun notmuch-show-refresh-view (&optional crypto-switch)
- "Refresh the current view (with crypto switch if prefix given).
+(defun notmuch-show-apply-state (state)
+ "Apply STATE to the current buffer.
-Kills the current buffer and reruns notmuch show with the same
-thread id. If a prefix is given, crypto processing is toggled."
+This includes:
+ - opening the messages previously opened,
+ - closing all other messages,
+ - moving to the correct current message."
+ (let ((current (car state))
+ (open (cadr state)))
+
+ ;; Open those that were open.
+ (goto-char (point-min))
+ (loop do (notmuch-show-message-visible (notmuch-show-get-message-properties)
+ (member (notmuch-show-get-message-id) open))
+ until (not (notmuch-show-goto-message-next)))
+
+ ;; Go to the previously open message.
+ (goto-char (point-min))
+ (unless (loop if (string= current (notmuch-show-get-message-id))
+ return t
+ until (not (notmuch-show-goto-message-next)))
+ (goto-char (point-min))
+ (message "Previously current message not found."))
+ (notmuch-show-message-adjust)))
+
+(defun notmuch-show-refresh-view (&optional reset-state)
+ "Refresh the current view.
+
+Refreshes the current view, observing changes in display
+preferences. If invoked with a prefix argument (or RESET-STATE is
+non-nil) then the state of the buffer (open/closed messages) is
+reset based on the original query."
(interactive "P")
- (let ((thread-id notmuch-show-thread-id)
- (parent-buffer notmuch-show-parent-buffer)
- (query-context notmuch-show-query-context)
- (buffer-name notmuch-show-buffer-name)
- (process-crypto (if crypto-switch
- (not notmuch-show-process-crypto)
- notmuch-show-process-crypto)))
- (notmuch-kill-this-buffer)
- (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))
+ (let ((inhibit-read-only t)
+ (state (unless reset-state
+ (notmuch-show-capture-state))))
+ (erase-buffer)
+ (notmuch-show-build-buffer)
+ (if state
+ (notmuch-show-apply-state state)
+ ;; We're resetting state, so navigate to the first open message
+ ;; and mark it read, just like opening a new show buffer.
+ (notmuch-show-goto-first-wanted-message))))
(defvar notmuch-show-stash-map
(let ((map (make-sparse-keymap)))
@@ -918,6 +1130,8 @@ thread id. If a prefix is given, crypto processing is toggled."
(define-key map "s" 'notmuch-show-stash-subject)
(define-key map "T" 'notmuch-show-stash-tags)
(define-key map "t" 'notmuch-show-stash-to)
+ (define-key map "l" 'notmuch-show-stash-mlarchive-link)
+ (define-key map "L" 'notmuch-show-stash-mlarchive-link-and-go)
map)
"Submap for stash commands")
(fset 'notmuch-show-stash-map notmuch-show-stash-map)
@@ -933,7 +1147,8 @@ thread id. If a prefix is given, crypto processing is toggled."
(define-key map "s" 'notmuch-search)
(define-key map "m" 'notmuch-mua-new-mail)
(define-key map "f" 'notmuch-show-forward-message)
- (define-key map "r" 'notmuch-show-reply)
+ (define-key map "r" 'notmuch-show-reply-sender)
+ (define-key map "R" 'notmuch-show-reply)
(define-key map "|" 'notmuch-show-pipe-message)
(define-key map "w" 'notmuch-show-save-attachments)
(define-key map "V" 'notmuch-show-view-raw-message)
@@ -941,10 +1156,13 @@ thread id. If a prefix is given, crypto processing is toggled."
(define-key map "c" 'notmuch-show-stash-map)
(define-key map "=" 'notmuch-show-refresh-view)
(define-key map "h" 'notmuch-show-toggle-headers)
+ (define-key map "*" 'notmuch-show-tag-all)
(define-key map "-" 'notmuch-show-remove-tag)
(define-key map "+" 'notmuch-show-add-tag)
- (define-key map "x" 'notmuch-show-archive-thread-then-exit)
- (define-key map "a" 'notmuch-show-archive-thread)
+ (define-key map "X" 'notmuch-show-archive-thread-then-exit)
+ (define-key map "x" 'notmuch-show-archive-message-then-next-or-exit)
+ (define-key map "A" 'notmuch-show-archive-thread-then-next)
+ (define-key map "a" 'notmuch-show-archive-message-then-next-or-next-thread)
(define-key map "N" 'notmuch-show-next-message)
(define-key map "P" 'notmuch-show-previous-message)
(define-key map "n" 'notmuch-show-next-open-message)
@@ -953,6 +1171,11 @@ thread id. If a prefix is given, crypto processing is toggled."
(define-key map " " 'notmuch-show-advance-and-archive)
(define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)
(define-key map (kbd "RET") 'notmuch-show-toggle-message)
+ (define-key map "#" 'notmuch-show-print-message)
+ (define-key map "!" 'notmuch-show-toggle-elide-non-matching)
+ (define-key map "$" 'notmuch-show-toggle-process-crypto)
+ (define-key map "<" 'notmuch-show-toggle-thread-indentation)
+ (define-key map "t" 'toggle-truncate-lines)
map)
"Keymap for \"notmuch show\" buffers.")
(fset 'notmuch-show-mode-map notmuch-show-mode-map)
@@ -990,7 +1213,8 @@ All currently available key bindings:
(use-local-map notmuch-show-mode-map)
(setq major-mode 'notmuch-show-mode
mode-name "notmuch-show")
- (setq buffer-read-only t))
+ (setq buffer-read-only t
+ truncate-lines t))
(defun notmuch-show-move-to-message-top ()
(goto-char (notmuch-show-message-top)))
@@ -1035,6 +1259,15 @@ All currently available key bindings:
(notmuch-show-move-to-message-top)
t))
+(defun notmuch-show-mapc (function)
+ "Iterate through all messages in the current thread with
+`notmuch-show-goto-message-next' and call FUNCTION for side
+effects."
+ (save-excursion
+ (goto-char (point-min))
+ (loop do (funcall function)
+ while (notmuch-show-goto-message-next))))
+
;; Functions relating to the visibility of messages and their
;; components.
@@ -1083,9 +1316,26 @@ Some useful entries are:
(notmuch-show-get-message-properties))))
(plist-get props prop)))
-(defun notmuch-show-get-message-id ()
- "Return the message id of the current message."
- (concat "id:\"" (notmuch-show-get-prop :id) "\""))
+(defun notmuch-show-get-message-id (&optional bare)
+ "Return an id: query for the Message-Id of the current message.
+
+If optional argument BARE is non-nil, return
+the Message-Id without id: prefix and escaping."
+ (if bare
+ (notmuch-show-get-prop :id)
+ (notmuch-id-to-query (notmuch-show-get-prop :id))))
+
+(defun notmuch-show-get-messages-ids ()
+ "Return all id: queries of messages in the current thread."
+ (let ((message-ids))
+ (notmuch-show-mapc
+ (lambda () (push (notmuch-show-get-message-id) message-ids)))
+ message-ids))
+
+(defun notmuch-show-get-messages-ids-search ()
+ "Return a search string for all message ids of messages in the
+current thread."
+ (mapconcat 'identity (notmuch-show-get-messages-ids) " or "))
;; dme: Would it make sense to use a macro for many of these?
@@ -1112,6 +1362,9 @@ Some useful entries are:
(defun notmuch-show-get-to ()
(notmuch-show-get-header :To))
+(defun notmuch-show-get-depth ()
+ (notmuch-show-get-prop :depth))
+
(defun notmuch-show-set-tags (tags)
"Set the tags of the current message."
(notmuch-show-set-prop :tags tags)
@@ -1131,13 +1384,13 @@ Some useful entries are:
(defun notmuch-show-mark-read ()
"Mark the current message as read."
- (notmuch-show-remove-tag "unread"))
+ (notmuch-show-tag-message "-unread"))
;; Functions for getting attributes of several messages in the current
;; thread.
(defun notmuch-show-get-message-ids-for-open-messages ()
- "Return a list of all message IDs for open messages in the current thread."
+ "Return a list of all id: queries for open messages in the current thread."
(save-excursion
(let (message-ids done)
(goto-char (point-min))
@@ -1181,6 +1434,11 @@ current window), advance to the next open message."
;; This is not the last message - move to the next visible one.
(notmuch-show-next-open-message))
+ ((not (= (point) (point-max)))
+ ;; This is the last message, but the cursor is not at the end of
+ ;; the buffer. Move it there.
+ (goto-char (point-max)))
+
(t
;; This is the last message - change the return value
(setq ret t)))
@@ -1199,7 +1457,7 @@ thread from the search from which this thread was originally
shown."
(interactive)
(if (notmuch-show-advance)
- (notmuch-show-archive-thread)))
+ (notmuch-show-archive-thread-then-next)))
(defun notmuch-show-rewind ()
"Backup through the thread, (reverse scrolling compared to \\[notmuch-show-advance-and-archive]).
@@ -1226,11 +1484,10 @@ any effects from previous calls to
;; If a small number of lines from the previous message are
;; visible, realign so that the top of the current message is at
;; the top of the screen.
- (if (<= (count-screen-lines (window-start) start-of-message)
- next-screen-context-lines)
- (progn
- (goto-char (notmuch-show-message-top))
- (notmuch-show-message-adjust)))
+ (when (<= (count-screen-lines (window-start) start-of-message)
+ next-screen-context-lines)
+ (goto-char (notmuch-show-message-top))
+ (notmuch-show-message-adjust))
;; Move to the top left of the window.
(goto-char (window-start)))
(t
@@ -1238,9 +1495,14 @@ any effects from previous calls to
(notmuch-show-previous-message)))))
(defun notmuch-show-reply (&optional prompt-for-sender)
- "Reply to the current message."
+ "Reply to the sender and all recipients of the current message."
(interactive "P")
- (notmuch-mua-new-reply (notmuch-show-get-message-id) prompt-for-sender))
+ (notmuch-mua-new-reply (notmuch-show-get-message-id) prompt-for-sender t))
+
+(defun notmuch-show-reply-sender (&optional prompt-for-sender)
+ "Reply to the sender of the current message."
+ (interactive "P")
+ (notmuch-mua-new-reply (notmuch-show-get-message-id) prompt-for-sender nil))
(defun notmuch-show-forward-message (&optional prompt-for-sender)
"Forward the current message."
@@ -1248,14 +1510,19 @@ any effects from previous calls to
(with-current-notmuch-show-message
(notmuch-mua-new-forward-message prompt-for-sender)))
-(defun notmuch-show-next-message ()
- "Show the next message."
- (interactive)
+(defun notmuch-show-next-message (&optional pop-at-end)
+ "Show the next message.
+
+If a prefix argument is given and this is the last message in the
+thread, navigate to the next thread in the parent search buffer."
+ (interactive "P")
(if (notmuch-show-goto-message-next)
(progn
(notmuch-show-mark-read)
(notmuch-show-message-adjust))
- (goto-char (point-max))))
+ (if pop-at-end
+ (notmuch-show-next-thread)
+ (goto-char (point-max)))))
(defun notmuch-show-previous-message ()
"Show the previous message."
@@ -1264,9 +1531,14 @@ any effects from previous calls to
(notmuch-show-mark-read)
(notmuch-show-message-adjust))
-(defun notmuch-show-next-open-message ()
- "Show the next message."
- (interactive)
+(defun notmuch-show-next-open-message (&optional pop-at-end)
+ "Show the next open message.
+
+If a prefix argument is given and this is the last open message
+in the thread, navigate to the next thread in the parent search
+buffer. Return t if there was a next open message in the thread
+to show, nil otherwise."
+ (interactive "P")
(let (r)
(while (and (setq r (notmuch-show-goto-message-next))
(not (notmuch-show-message-visible-p))))
@@ -1274,10 +1546,46 @@ any effects from previous calls to
(progn
(notmuch-show-mark-read)
(notmuch-show-message-adjust))
+ (if pop-at-end
+ (notmuch-show-next-thread)
+ (goto-char (point-max))))
+ r))
+
+(defun notmuch-show-next-matching-message ()
+ "Show the next matching message."
+ (interactive)
+ (let (r)
+ (while (and (setq r (notmuch-show-goto-message-next))
+ (not (notmuch-show-get-prop :match))))
+ (if r
+ (progn
+ (notmuch-show-mark-read)
+ (notmuch-show-message-adjust))
(goto-char (point-max)))))
+(defun notmuch-show-open-if-matched ()
+ "Open a message if it is matched (whether or not excluded)."
+ (let ((props (notmuch-show-get-message-properties)))
+ (notmuch-show-message-visible props (plist-get props :match))))
+
+(defun notmuch-show-goto-first-wanted-message ()
+ "Move to the first open message and mark it read"
+ (goto-char (point-min))
+ (if (notmuch-show-message-visible-p)
+ (notmuch-show-mark-read)
+ (notmuch-show-next-open-message))
+ (when (eobp)
+ ;; There are no matched non-excluded messages so open all matched
+ ;; (necessarily excluded) messages and go to the first.
+ (notmuch-show-mapc 'notmuch-show-open-if-matched)
+ (force-window-update)
+ (goto-char (point-min))
+ (if (notmuch-show-message-visible-p)
+ (notmuch-show-mark-read)
+ (notmuch-show-next-open-message))))
+
(defun notmuch-show-previous-open-message ()
- "Show the previous message."
+ "Show the previous open message."
(interactive)
(while (and (notmuch-show-goto-message-previous)
(not (notmuch-show-message-visible-p))))
@@ -1308,8 +1616,8 @@ than only the current message."
(interactive "P\nsPipe message to command: ")
(let (shell-command)
(if entire-thread
- (setq shell-command
- (concat notmuch-command " show --format=mbox "
+ (setq shell-command
+ (concat notmuch-command " show --format=mbox --exclude=false "
(shell-quote-argument
(mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR "))
" | " command))
@@ -1329,52 +1637,50 @@ than only the current message."
(message (format "Command '%s' exited abnormally with code %d"
shell-command exit-code))))))))
-(defun notmuch-show-add-tags-worker (current-tags add-tags)
- "Add to `current-tags' with any tags from `add-tags' not
-currently present and return the result."
- (let ((result-tags (copy-sequence current-tags)))
- (mapc (lambda (add-tag)
- (unless (member add-tag current-tags)
- (setq result-tags (push add-tag result-tags))))
- add-tags)
- (sort result-tags 'string<)))
-
-(defun notmuch-show-del-tags-worker (current-tags del-tags)
- "Remove any tags in `del-tags' from `current-tags' and return
-the result."
- (let ((result-tags (copy-sequence current-tags)))
- (mapc (lambda (del-tag)
- (setq result-tags (delete del-tag result-tags)))
- del-tags)
- result-tags))
-
-(defun notmuch-show-add-tag (&rest toadd)
- "Add a tag to the current message."
- (interactive
- (list (notmuch-select-tag-with-completion "Tag to add: ")))
+(defun notmuch-show-tag-message (&rest tag-changes)
+ "Change tags for the current message.
+TAG-CHANGES is a list of tag operations for `notmuch-tag'."
(let* ((current-tags (notmuch-show-get-tags))
- (new-tags (notmuch-show-add-tags-worker current-tags toadd)))
-
+ (new-tags (notmuch-update-tags current-tags tag-changes)))
(unless (equal current-tags new-tags)
- (apply 'notmuch-tag (notmuch-show-get-message-id)
- (mapcar (lambda (s) (concat "+" s)) toadd))
+ (funcall 'notmuch-tag (notmuch-show-get-message-id) tag-changes)
(notmuch-show-set-tags new-tags))))
-(defun notmuch-show-remove-tag (&rest toremove)
- "Remove a tag from the current message."
- (interactive
- (list (notmuch-select-tag-with-completion
- "Tag to remove: " (notmuch-show-get-message-id))))
+(defun notmuch-show-tag (&optional tag-changes)
+ "Change tags for the current message.
+See `notmuch-tag' for information on the format of TAG-CHANGES."
+ (interactive)
+ (setq tag-changes (funcall 'notmuch-tag (notmuch-show-get-message-id) tag-changes))
(let* ((current-tags (notmuch-show-get-tags))
- (new-tags (notmuch-show-del-tags-worker current-tags toremove)))
-
+ (new-tags (notmuch-update-tags current-tags tag-changes)))
(unless (equal current-tags new-tags)
- (apply 'notmuch-tag (notmuch-show-get-message-id)
- (mapcar (lambda (s) (concat "-" s)) toremove))
(notmuch-show-set-tags new-tags))))
+(defun notmuch-show-tag-all (&optional tag-changes)
+ "Change tags for all messages in the current show buffer.
+
+See `notmuch-tag' for information on the format of TAG-CHANGES."
+ (interactive)
+ (setq tag-changes (funcall 'notmuch-tag (notmuch-show-get-messages-ids-search) tag-changes))
+ (notmuch-show-mapc
+ (lambda ()
+ (let* ((current-tags (notmuch-show-get-tags))
+ (new-tags (notmuch-update-tags current-tags tag-changes)))
+ (unless (equal current-tags new-tags)
+ (notmuch-show-set-tags new-tags))))))
+
+(defun notmuch-show-add-tag ()
+ "Same as `notmuch-show-tag' but sets initial input to '+'."
+ (interactive)
+ (notmuch-show-tag "+"))
+
+(defun notmuch-show-remove-tag ()
+ "Same as `notmuch-show-tag' but sets initial input to '-'."
+ (interactive)
+ (notmuch-show-tag "-"))
+
(defun notmuch-show-toggle-headers ()
"Toggle the visibility of the current message headers."
(interactive)
@@ -1415,39 +1721,73 @@ argument, hide all of the messages."
(interactive)
(backward-button 1))
-(defun notmuch-show-archive-thread-internal (show-next)
- ;; Remove the tag from the current set of messages.
- (goto-char (point-min))
- (loop do (notmuch-show-remove-tag "inbox")
- until (not (notmuch-show-goto-message-next)))
- ;; Move to the next item in the search results, if any.
+(defun notmuch-show-next-thread (&optional show-next)
+ "Move to the next item in the search results, if any."
+ (interactive "P")
(let ((parent-buffer notmuch-show-parent-buffer))
(notmuch-kill-this-buffer)
- (if parent-buffer
- (progn
- (switch-to-buffer parent-buffer)
- (forward-line)
- (if show-next
- (notmuch-search-show-thread))))))
+ (when (buffer-live-p parent-buffer)
+ (switch-to-buffer parent-buffer)
+ (notmuch-search-next-thread)
+ (if show-next
+ (notmuch-search-show-thread)))))
-(defun notmuch-show-archive-thread ()
- "Archive each message in thread, then show next thread from search.
+(defun notmuch-show-archive-thread (&optional unarchive)
+ "Archive each message in thread.
Archive each message currently shown by removing the \"inbox\"
-tag from each. Then kill this buffer and show the next thread
-from the search from which this thread was originally shown.
+tag from each. If a prefix argument is given, the messages will
+be \"unarchived\" (ie. the \"inbox\" tag will be added instead of
+removed).
Note: This command is safe from any race condition of new messages
being delivered to the same thread. It does not archive the
entire thread, but only the messages shown in the current
buffer."
+ (interactive "P")
+ (let ((op (if unarchive "+" "-")))
+ (notmuch-show-tag-all (concat op "inbox"))))
+
+(defun notmuch-show-archive-thread-then-next ()
+ "Archive all messages in the current buffer, then show next thread from search."
(interactive)
- (notmuch-show-archive-thread-internal t))
+ (notmuch-show-archive-thread)
+ (notmuch-show-next-thread t))
(defun notmuch-show-archive-thread-then-exit ()
- "Archive each message in thread, then exit back to search results."
+ "Archive all messages in the current buffer, then exit back to search results."
+ (interactive)
+ (notmuch-show-archive-thread)
+ (notmuch-show-next-thread))
+
+(defun notmuch-show-archive-message (&optional unarchive)
+ "Archive the current message (remove \"inbox\" tag).
+
+If a prefix argument is given, the message will be
+\"unarchived\" (ie. the \"inbox\" tag will be added instead of
+removed)."
+ (interactive "P")
+ (let ((op (if unarchive "+" "-")))
+ (notmuch-show-tag-message (concat op "inbox"))))
+
+(defun notmuch-show-archive-message-then-next-or-exit ()
+ "Archive the current message, then show the next open message in the current thread.
+
+If at the last open message in the current thread, then exit back
+to search results."
(interactive)
- (notmuch-show-archive-thread-internal nil))
+ (notmuch-show-archive-message)
+ (notmuch-show-next-open-message t))
+
+(defun notmuch-show-archive-message-then-next-or-next-thread ()
+ "Archive the current message, then show the next open message in the current thread.
+
+If at the last open message in the current thread, then show next
+thread from search."
+ (interactive)
+ (notmuch-show-archive-message)
+ (unless (notmuch-show-next-open-message)
+ (notmuch-show-next-thread t)))
(defun notmuch-show-stash-cc ()
"Copy CC field of current message to kill-ring."
@@ -1470,14 +1810,14 @@ buffer."
(notmuch-common-do-stash (notmuch-show-get-from)))
(defun notmuch-show-stash-message-id ()
- "Copy message ID of current message to kill-ring."
+ "Copy id: query matching the current message to kill-ring."
(interactive)
(notmuch-common-do-stash (notmuch-show-get-message-id)))
(defun notmuch-show-stash-message-id-stripped ()
"Copy message ID of current message (sans `id:' prefix) to kill-ring."
(interactive)
- (notmuch-common-do-stash (substring (notmuch-show-get-message-id) 4 -1)))
+ (notmuch-common-do-stash (notmuch-show-get-message-id t)))
(defun notmuch-show-stash-subject ()
"Copy Subject field of current message to kill-ring."
@@ -1494,14 +1834,66 @@ buffer."
(interactive)
(notmuch-common-do-stash (notmuch-show-get-to)))
+(defun notmuch-show-stash-mlarchive-link (&optional mla)
+ "Copy an ML Archive URI for the current message to the kill-ring.
+
+This presumes that the message is available at the selected Mailing List Archive.
+
+If optional argument MLA is non-nil, use the provided key instead of prompting
+the user (see `notmuch-show-stash-mlarchive-link-alist')."
+ (interactive)
+ (notmuch-common-do-stash
+ (concat (cdr (assoc
+ (or mla
+ (let ((completion-ignore-case t))
+ (completing-read
+ "Mailing List Archive: "
+ notmuch-show-stash-mlarchive-link-alist
+ nil t nil nil notmuch-show-stash-mlarchive-link-default)))
+ notmuch-show-stash-mlarchive-link-alist))
+ (notmuch-show-get-message-id t))))
+
+(defun notmuch-show-stash-mlarchive-link-and-go (&optional mla)
+ "Copy an ML Archive URI for the current message to the kill-ring and visit it.
+
+This presumes that the message is available at the selected Mailing List Archive.
+
+If optional argument MLA is non-nil, use the provided key instead of prompting
+the user (see `notmuch-show-stash-mlarchive-link-alist')."
+ (interactive)
+ (notmuch-show-stash-mlarchive-link mla)
+ (browse-url (current-kill 0 t)))
+
;; Commands typically bound to buttons.
-(defun notmuch-show-part-button-action (button)
- (let ((nth (button-get button :notmuch-part)))
- (if nth
- (notmuch-show-save-part (notmuch-show-get-message-id) nth
- (button-get button :notmuch-filename))
- (message "Not a valid part (is it a fake part?)."))))
+(defun notmuch-show-part-button-default (&optional button)
+ (interactive)
+ (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))
+
+(defun notmuch-show-part-button-save (&optional button)
+ (interactive)
+ (notmuch-show-part-button-internal button #'notmuch-show-save-part))
+
+(defun notmuch-show-part-button-view (&optional button)
+ (interactive)
+ (notmuch-show-part-button-internal button #'notmuch-show-view-part))
+
+(defun notmuch-show-part-button-interactively-view (&optional button)
+ (interactive)
+ (notmuch-show-part-button-internal button #'notmuch-show-interactively-view-part))
+
+(defun notmuch-show-part-button-pipe (&optional button)
+ (interactive)
+ (notmuch-show-part-button-internal button #'notmuch-show-pipe-part))
+
+(defun notmuch-show-part-button-internal (button handler)
+ (let ((button (or button (button-at (point)))))
+ (if button
+ (let ((nth (button-get button :notmuch-part)))
+ (if nth
+ (funcall handler (notmuch-show-get-message-id) nth
+ (button-get button :notmuch-filename)
+ (button-get button :notmuch-content-type)))))))
;;
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
new file mode 100644
index 0000000..0c0fc87
--- /dev/null
+++ b/emacs/notmuch-tag.el
@@ -0,0 +1,145 @@
+;; notmuch-tag.el --- tag messages within emacs
+;;
+;; Copyright © Carl Worth
+;;
+;; 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 <http://www.gnu.org/licenses/>.
+;;
+;; Authors: Carl Worth <cworth@cworth.org>
+
+(eval-when-compile (require 'cl))
+(require 'crm)
+(require 'notmuch-lib)
+
+(defcustom notmuch-before-tag-hook nil
+ "Hooks that are run before tags of a message are modified.
+
+'tags' will contain the tags that are about to be added or removed as
+a list of strings of the form \"+TAG\" or \"-TAG\".
+'query' will be a string containing the search query that determines
+the messages that are about to be tagged"
+
+ :type 'hook
+ :options '(notmuch-hl-line-mode)
+ :group 'notmuch-hooks)
+
+(defcustom notmuch-after-tag-hook nil
+ "Hooks that are run after tags of a message are modified.
+
+'tags' will contain the tags that were added or removed as
+a list of strings of the form \"+TAG\" or \"-TAG\".
+'query' will be a string containing the search query that determines
+the messages that were tagged"
+ :type 'hook
+ :options '(notmuch-hl-line-mode)
+ :group 'notmuch-hooks)
+
+(defvar notmuch-select-tag-history nil
+ "Variable to store minibuffer history for
+`notmuch-select-tag-with-completion' function.")
+
+(defvar notmuch-read-tag-changes-history nil
+ "Variable to store minibuffer history for
+`notmuch-read-tag-changes' function.")
+
+(defun notmuch-tag-completions (&optional search-terms)
+ (if (null search-terms)
+ (setq search-terms (list "*")))
+ (split-string
+ (with-output-to-string
+ (with-current-buffer standard-output
+ (apply 'call-process notmuch-command nil t
+ nil "search" "--output=tags" "--exclude=false" search-terms)))
+ "\n+" t))
+
+(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
+ (let ((tag-list (notmuch-tag-completions search-terms)))
+ (completing-read prompt tag-list nil nil nil 'notmuch-select-tag-history)))
+
+(defun notmuch-read-tag-changes (&optional initial-input &rest search-terms)
+ (let* ((all-tag-list (notmuch-tag-completions))
+ (add-tag-list (mapcar (apply-partially 'concat "+") all-tag-list))
+ (remove-tag-list (mapcar (apply-partially 'concat "-")
+ (if (null search-terms)
+ all-tag-list
+ (notmuch-tag-completions search-terms))))
+ (tag-list (append add-tag-list remove-tag-list))
+ (crm-separator " ")
+ ;; By default, space is bound to "complete word" function.
+ ;; Re-bind it to insert a space instead. Note that <tab>
+ ;; still does the completion.
+ (crm-local-completion-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map crm-local-completion-map)
+ (define-key map " " 'self-insert-command)
+ map)))
+ (delete "" (completing-read-multiple "Tags (+add -drop): "
+ tag-list nil nil initial-input
+ 'notmuch-read-tag-changes-history))))
+
+(defun notmuch-update-tags (tags tag-changes)
+ "Return a copy of TAGS with additions and removals from TAG-CHANGES.
+
+TAG-CHANGES must be a list of tags names, each prefixed with
+either a \"+\" to indicate the tag should be added to TAGS if not
+present or a \"-\" to indicate that the tag should be removed
+from TAGS if present."
+ (let ((result-tags (copy-sequence tags)))
+ (dolist (tag-change tag-changes)
+ (let ((op (string-to-char tag-change))
+ (tag (unless (string= tag-change "") (substring tag-change 1))))
+ (case op
+ (?+ (unless (member tag result-tags)
+ (push tag result-tags)))
+ (?- (setq result-tags (delete tag result-tags)))
+ (otherwise
+ (error "Changed tag must be of the form `+this_tag' or `-that_tag'")))))
+ (sort result-tags 'string<)))
+
+(defun notmuch-tag (query &optional tag-changes)
+ "Add/remove tags in TAG-CHANGES to messages matching QUERY.
+
+QUERY should be a string containing the search-terms.
+TAG-CHANGES can take multiple forms. If TAG-CHANGES is a list of
+strings of the form \"+tag\" or \"-tag\" then those are the tag
+changes applied. If TAG-CHANGES is a string then it is
+interpreted as a single tag change. If TAG-CHANGES is the string
+\"-\" or \"+\", or null, then the user is prompted to enter the
+tag changes.
+
+Note: Other code should always use this function alter tags of
+messages instead of running (notmuch-call-notmuch-process \"tag\" ..)
+directly, so that hooks specified in notmuch-before-tag-hook and
+notmuch-after-tag-hook will be run."
+ ;; Perform some validation
+ (if (string-or-null-p tag-changes)
+ (if (or (string= tag-changes "-") (string= tag-changes "+") (null tag-changes))
+ (setq tag-changes (notmuch-read-tag-changes tag-changes query))
+ (setq tag-changes (list tag-changes))))
+ (mapc (lambda (tag-change)
+ (unless (string-match-p "^[-+]\\S-+$" tag-change)
+ (error "Tag must be of the form `+this_tag' or `-that_tag'")))
+ tag-changes)
+ (unless (null tag-changes)
+ (run-hooks 'notmuch-before-tag-hook)
+ (apply 'notmuch-call-notmuch-process "tag"
+ (append tag-changes (list "--" query)))
+ (run-hooks 'notmuch-after-tag-hook))
+ ;; in all cases we return tag-changes as a list
+ tag-changes)
+
+;;
+
+(provide 'notmuch-tag)
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 5c1e830..7d003a2 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -87,6 +87,14 @@ If there is one more line than the sum of
`notmuch-wash-citation-lines-suffix', show that, otherwise
collapse the remaining lines into a button.")
+(defvar notmuch-wash-wrap-lines-length nil
+ "Wrap line after at most this many characters.
+
+If this is nil, lines in messages will be wrapped to fit in the
+current window. If this is a number, lines will be wrapped after
+this many characters or at the window width (whichever one is
+lower).")
+
(defun notmuch-wash-toggle-invisible-action (cite-button)
(let ((invis-spec (button-get cite-button 'invisibility-spec)))
(if (invisible-p invis-spec)
@@ -136,12 +144,13 @@ collapse the remaining lines into a button.")
(lines-count (count-lines (overlay-start overlay) (overlay-end overlay))))
(format label-format lines-count)))
-(defun notmuch-wash-region-to-button (msg beg end type prefix)
+(defun notmuch-wash-region-to-button (msg beg end type &optional prefix)
"Auxiliary function to do the actual making of overlays and buttons
BEG and END are buffer locations. TYPE should a string, either
-\"citation\" or \"signature\". PREFIX is some arbitrary text to
-insert before the button, probably for indentation."
+\"citation\" or \"signature\". Optional PREFIX is some arbitrary
+text to insert before the button, probably for indentation. Note
+that PREFIX should not include a newline."
;; This uses some slightly tricky conversions between strings and
;; symbols because of the way the button code works. Note that
@@ -160,12 +169,15 @@ insert before the button, probably for indentation."
(overlay-put overlay 'type type)
(goto-char (1+ end))
(save-excursion
- (goto-char (1- beg))
- (insert prefix)
- (insert-button (notmuch-wash-button-label overlay)
+ (goto-char beg)
+ (if prefix
+ (insert-before-markers prefix))
+ (let ((button-beg (point)))
+ (insert-before-markers (notmuch-wash-button-label overlay) "\n")
+ (make-button button-beg (1- (point))
'invisibility-spec invis-spec
'overlay overlay
- :type button-type))))
+ :type button-type)))))
(defun notmuch-wash-excerpt-citations (msg depth)
"Excerpt citations and up to one signature."
@@ -177,7 +189,7 @@ insert before the button, probably for indentation."
(msg-end (point-max))
(msg-lines (count-lines msg-start msg-end)))
(notmuch-wash-region-to-button
- msg msg-start msg-end "original" "\n")))
+ msg msg-start msg-end "original")))
(while (and (< (point) (point-max))
(re-search-forward notmuch-wash-citation-regexp nil t))
(let* ((cite-start (match-beginning 0))
@@ -194,7 +206,7 @@ insert before the button, probably for indentation."
(forward-line (- notmuch-wash-citation-lines-suffix))
(notmuch-wash-region-to-button
msg hidden-start (point-marker)
- "citation" "\n")))))
+ "citation")))))
(if (and (not (eobp))
(re-search-forward notmuch-wash-signature-regexp nil t))
(let* ((sig-start (match-beginning 0))
@@ -208,7 +220,7 @@ insert before the button, probably for indentation."
(overlay-put (make-overlay sig-start-marker sig-end-marker) 'face 'message-cited-text)
(notmuch-wash-region-to-button
msg sig-start-marker sig-end-marker
- "signature" "\n"))))))
+ "signature"))))))
;;
@@ -272,16 +284,24 @@ Perform several transformations on the message body:
;;
(defun notmuch-wash-wrap-long-lines (msg depth)
- "Wrap any long lines in the message to the width of the window.
-
-When doing so, maintaining citation leaders in the wrapped text."
-
- (let ((coolj-wrap-follows-window-size nil)
- (fill-column (- (window-width)
- depth
- ;; 2 to avoid poor interaction with
- ;; `word-wrap'.
- 2)))
+ "Wrap long lines in the message.
+
+If `notmuch-wash-wrap-lines-length' is a number, this will wrap
+the message lines to the minimum of the width of the window or
+its value. Otherwise, this function will wrap long lines in the
+message at the window width. When doing so, citation leaders in
+the wrapped text are maintained."
+
+ (let* ((coolj-wrap-follows-window-size nil)
+ (limit (if (numberp notmuch-wash-wrap-lines-length)
+ (min notmuch-wash-wrap-lines-length
+ (window-width))
+ (window-width)))
+ (fill-column (- limit
+ depth
+ ;; 2 to avoid poor interaction with
+ ;; `word-wrap'.
+ 2)))
(coolj-wrap-region (point-min) (point-max))))
;;
@@ -336,30 +356,29 @@ patch and then guesses the extent of the patch, there is scope
for error."
(goto-char (point-min))
- (if (re-search-forward diff-file-header-re nil t)
- (progn
- (beginning-of-line -1)
- (let ((patch-start (point))
- (patch-end (point-max))
- part)
- (goto-char patch-start)
- (if (or
- ;; Patch ends with signature.
- (re-search-forward notmuch-wash-signature-regexp nil t)
- ;; Patch ends with bugtraq comment.
- (re-search-forward "^\\*\\*\\* " nil t))
- (setq patch-end (match-beginning 0)))
- (save-restriction
- (narrow-to-region patch-start patch-end)
- (setq part (plist-put part :content-type "inline-patch-fake-part"))
- (setq part (plist-put part :content (buffer-string)))
- (setq part (plist-put part :id -1))
- (setq part (plist-put part :filename
- (notmuch-wash-subject-to-patch-filename
- (plist-get
- (plist-get msg :headers) :Subject))))
- (delete-region (point-min) (point-max))
- (notmuch-show-insert-bodypart nil part depth))))))
+ (when (re-search-forward diff-file-header-re nil t)
+ (beginning-of-line -1)
+ (let ((patch-start (point))
+ (patch-end (point-max))
+ part)
+ (goto-char patch-start)
+ (if (or
+ ;; Patch ends with signature.
+ (re-search-forward notmuch-wash-signature-regexp nil t)
+ ;; Patch ends with bugtraq comment.
+ (re-search-forward "^\\*\\*\\* " nil t))
+ (setq patch-end (match-beginning 0)))
+ (save-restriction
+ (narrow-to-region patch-start patch-end)
+ (setq part (plist-put part :content-type "inline-patch-fake-part"))
+ (setq part (plist-put part :content (buffer-string)))
+ (setq part (plist-put part :id -1))
+ (setq part (plist-put part :filename
+ (notmuch-wash-subject-to-patch-filename
+ (plist-get
+ (plist-get msg :headers) :Subject))))
+ (delete-region (point-min) (point-max))
+ (notmuch-show-insert-bodypart nil part depth)))))
;;
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 1e61775..d2d82a9 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -1,57 +1,58 @@
-; notmuch.el --- run notmuch within emacs
-;
-; Copyright © Carl Worth
-;
-; 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 <http://www.gnu.org/licenses/>.
-;
-; Authors: Carl Worth <cworth@cworth.org>
-
-; This is an emacs-based interface to the notmuch mail system.
-;
-; You will first need to have the notmuch program installed and have a
-; notmuch database built in order to use this. See
-; http://notmuchmail.org for details.
-;
-; To install this software, copy it to a directory that is on the
-; `load-path' variable within emacs (a good candidate is
-; /usr/local/share/emacs/site-lisp). If you are viewing this from the
-; notmuch source distribution then you can simply run:
-;
-; sudo make install-emacs
-;
-; to install it.
-;
-; Then, to actually run it, add:
-;
-; (require 'notmuch)
-;
-; to your ~/.emacs file, and then run "M-x notmuch" from within emacs,
-; or run:
-;
-; emacs -f notmuch
-;
-; Have fun, and let us know if you have any comment, questions, or
-; kudos: Notmuch list <notmuch@notmuchmail.org> (subscription is not
-; required, but is available from http://notmuchmail.org).
+;; notmuch.el --- run notmuch within emacs
+;;
+;; Copyright © Carl Worth
+;;
+;; 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 <http://www.gnu.org/licenses/>.
+;;
+;; Authors: Carl Worth <cworth@cworth.org>
+
+;; This is an emacs-based interface to the notmuch mail system.
+;;
+;; You will first need to have the notmuch program installed and have a
+;; notmuch database built in order to use this. See
+;; http://notmuchmail.org for details.
+;;
+;; To install this software, copy it to a directory that is on the
+;; `load-path' variable within emacs (a good candidate is
+;; /usr/local/share/emacs/site-lisp). If you are viewing this from the
+;; notmuch source distribution then you can simply run:
+;;
+;; sudo make install-emacs
+;;
+;; to install it.
+;;
+;; Then, to actually run it, add:
+;;
+;; (require 'notmuch)
+;;
+;; to your ~/.emacs file, and then run "M-x notmuch" from within emacs,
+;; or run:
+;;
+;; emacs -f notmuch
+;;
+;; Have fun, and let us know if you have any comment, questions, or
+;; kudos: Notmuch list <notmuch@notmuchmail.org> (subscription is not
+;; required, but is available from http://notmuchmail.org).
(eval-when-compile (require 'cl))
(require 'mm-view)
(require 'message)
(require 'notmuch-lib)
+(require 'notmuch-tag)
(require 'notmuch-show)
(require 'notmuch-mua)
(require 'notmuch-hello)
@@ -59,7 +60,7 @@
(require 'notmuch-message)
(defcustom notmuch-search-result-format
- `(("date" . "%s ")
+ `(("date" . "%12s ")
("count" . "%-7s ")
("authors" . "%-20s ")
("subject" . "%s ")
@@ -68,20 +69,19 @@
date, count, authors, subject, tags
For example:
(setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)
- \(\"subject\" . \"%s\"\)\)\)"
+ \(\"subject\" . \"%s\"\)\)\)
+Line breaks are permitted in format strings (though this is
+currently experimental). Note that a line break at the end of an
+\"authors\" field will get elided if the authors list is long;
+place it instead at the beginning of the following field. To
+enter a line break when setting this variable with setq, use \\n.
+To enter a line break in customize, press \\[quoted-insert] C-j."
:type '(alist :key-type (string) :value-type (string))
- :group 'notmuch)
+ :group 'notmuch-search)
(defvar notmuch-query-history nil
"Variable to store minibuffer history for notmuch queries")
-(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
- (let ((tag-list
- (with-output-to-string
- (with-current-buffer standard-output
- (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))))
- (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))
-
(defun notmuch-foreach-mime-part (function mm-handle)
(cond ((stringp (car mm-handle))
(dolist (part (cdr mm-handle))
@@ -139,10 +139,10 @@ This is basically just `format-kbd-macro' but we also convert ESC to M-."
"M-"
(concat desc " "))))
-; I would think that emacs would have code handy for walking a keymap
-; and generating strings for each key, and I would prefer to just call
-; that. But I couldn't find any (could be all implemented in C I
-; suppose), so I wrote my own here.
+;; I would think that emacs would have code handy for walking a keymap
+;; and generating strings for each key, and I would prefer to just call
+;; that. But I couldn't find any (could be all implemented in C I
+;; suppose), so I wrote my own here.
(defun notmuch-substitute-one-command-key-with-prefix (prefix binding)
"For a key binding, return a string showing a human-readable
representation of the prefixed key as well as the first line of
@@ -195,11 +195,19 @@ For a mouse binding, return nil."
(set-buffer-modified-p nil)
(view-buffer (current-buffer) 'kill-buffer-if-not-modified))))
-(defcustom notmuch-search-hook '(hl-line-mode)
+(require 'hl-line)
+
+(defun notmuch-hl-line-mode ()
+ (prog1 (hl-line-mode)
+ (when hl-line-overlay
+ (overlay-put hl-line-overlay 'priority 1))))
+
+(defcustom notmuch-search-hook '(notmuch-hl-line-mode)
"List of functions to call when notmuch displays the search results."
:type 'hook
- :options '(hl-line-mode)
- :group 'notmuch)
+ :options '(notmuch-hl-line-mode)
+ :group 'notmuch-search
+ :group 'notmuch-hooks)
(defvar notmuch-search-mode-map
(let ((map (make-sparse-keymap)))
@@ -213,7 +221,8 @@ For a mouse binding, return nil."
(define-key map ">" 'notmuch-search-last-thread)
(define-key map "p" 'notmuch-search-previous-thread)
(define-key map "n" 'notmuch-search-next-thread)
- (define-key map "r" 'notmuch-search-reply-to-thread)
+ (define-key map "r" 'notmuch-search-reply-to-thread-sender)
+ (define-key map "R" 'notmuch-search-reply-to-thread)
(define-key map "m" 'notmuch-mua-new-mail)
(define-key map "s" 'notmuch-search)
(define-key map "o" 'notmuch-search-toggle-order)
@@ -223,7 +232,7 @@ For a mouse binding, return nil."
(define-key map "t" 'notmuch-search-filter-by-tag)
(define-key map "f" 'notmuch-search-filter)
(define-key map [mouse-1] 'notmuch-search-show-thread)
- (define-key map "*" 'notmuch-search-operate-all)
+ (define-key map "*" 'notmuch-search-tag-all)
(define-key map "a" 'notmuch-search-archive-thread)
(define-key map "-" 'notmuch-search-remove-tag)
(define-key map "+" 'notmuch-search-add-tag)
@@ -269,14 +278,14 @@ For a mouse binding, return nil."
(defun notmuch-search-scroll-down ()
"Move backward through the search results by one window's worth."
(interactive)
- ; I don't know why scroll-down doesn't signal beginning-of-buffer
- ; the way that scroll-up signals end-of-buffer, but c'est la vie.
- ;
- ; So instead of trapping a signal we instead check whether the
- ; window begins on the first line of the buffer and if so, move
- ; directly to that position. (We have to count lines since the
- ; window-start position is not the same as point-min due to the
- ; invisible thread-ID characters on the first line.
+ ;; I don't know why scroll-down doesn't signal beginning-of-buffer
+ ;; the way that scroll-up signals end-of-buffer, but c'est la vie.
+ ;;
+ ;; So instead of trapping a signal we instead check whether the
+ ;; window begins on the first line of the buffer and if so, move
+ ;; directly to that position. (We have to count lines since the
+ ;; window-start position is not the same as point-min due to the
+ ;; invisible thread-ID characters on the first line.
(if (equal (count-lines (point-min) (window-start)) 0)
(goto-char (point-min))
(scroll-down nil)))
@@ -284,18 +293,25 @@ For a mouse binding, return nil."
(defun notmuch-search-next-thread ()
"Select the next thread in the search results."
(interactive)
- (forward-line 1))
+ (when (notmuch-search-get-result)
+ (goto-char (notmuch-search-result-end))))
(defun notmuch-search-previous-thread ()
"Select the previous thread in the search results."
(interactive)
- (forward-line -1))
+ (if (notmuch-search-get-result)
+ (unless (bobp)
+ (goto-char (notmuch-search-result-beginning (- (point) 1))))
+ ;; We must be past the end; jump to the last result
+ (notmuch-search-last-thread)))
(defun notmuch-search-last-thread ()
"Select the last thread in the search results."
(interactive)
(goto-char (point-max))
- (forward-line -2))
+ (forward-line -2)
+ (let ((beg (notmuch-search-result-beginning)))
+ (when beg (goto-char beg))))
(defun notmuch-search-first-thread ()
"Select the first thread in the search results."
@@ -306,27 +322,32 @@ For a mouse binding, return nil."
'((((class color) (background light)) (:background "#f0f0f0"))
(((class color) (background dark)) (:background "#303030")))
"Face for the single-line message summary in notmuch-show-mode."
- :group 'notmuch)
+ :group 'notmuch-show
+ :group 'notmuch-faces)
(defface notmuch-search-date
'((t :inherit default))
"Face used in search mode for dates."
- :group 'notmuch)
+ :group 'notmuch-search
+ :group 'notmuch-faces)
(defface notmuch-search-count
'((t :inherit default))
"Face used in search mode for the count matching the query."
- :group 'notmuch)
+ :group 'notmuch-search
+ :group 'notmuch-faces)
(defface notmuch-search-subject
'((t :inherit default))
"Face used in search mode for subjects."
- :group 'notmuch)
+ :group 'notmuch-search
+ :group 'notmuch-faces)
(defface notmuch-search-matching-authors
'((t :inherit default))
"Face used in search mode for authors matching the query."
- :group 'notmuch)
+ :group 'notmuch-search
+ :group 'notmuch-faces)
(defface notmuch-search-non-matching-authors
'((((class color)
@@ -338,7 +359,8 @@ For a mouse binding, return nil."
(t
(:italic t)))
"Face used in search mode for authors not matching the query."
- :group 'notmuch)
+ :group 'notmuch-search
+ :group 'notmuch-faces)
(defface notmuch-tag-face
'((((class color)
@@ -350,7 +372,8 @@ For a mouse binding, return nil."
(t
(:bold t)))
"Face used in search mode face for tags."
- :group 'notmuch)
+ :group 'notmuch-search
+ :group 'notmuch-faces)
(defun notmuch-search-mode ()
"Major mode displaying results of a notmuch search.
@@ -365,7 +388,7 @@ any tags).
Pressing \\[notmuch-search-show-thread] on any line displays that thread. The '\\[notmuch-search-add-tag]' and '\\[notmuch-search-remove-tag]'
keys can be used to add or remove tags from a thread. The '\\[notmuch-search-archive-thread]' key
is a convenience for archiving a thread (removing the \"inbox\"
-tag). The '\\[notmuch-search-operate-all]' key can be used to add or remove a tag from all
+tag). The '\\[notmuch-search-tag-all]' key can be used to add or remove a tag from all
threads in the current buffer.
Other useful commands are '\\[notmuch-search-filter]' for filtering the current search
@@ -391,67 +414,121 @@ Complete list of currently available key bindings:
mode-name "notmuch-search")
(setq buffer-read-only t))
+(defun notmuch-search-get-result (&optional pos)
+ "Return the result object for the thread at POS (or point).
+
+If there is no thread at POS (or point), returns nil."
+ (get-text-property (or pos (point)) 'notmuch-search-result))
+
+(defun notmuch-search-result-beginning (&optional pos)
+ "Return the point at the beginning of the thread at POS (or point).
+
+If there is no thread at POS (or point), returns nil."
+ (when (notmuch-search-get-result pos)
+ ;; We pass 1+point because previous-single-property-change starts
+ ;; searching one before the position we give it.
+ (previous-single-property-change (1+ (or pos (point)))
+ 'notmuch-search-result nil (point-min))))
+
+(defun notmuch-search-result-end (&optional pos)
+ "Return the point at the end of the thread at POS (or point).
+
+The returned point will be just after the newline character that
+ends the result line. If there is no thread at POS (or point),
+returns nil"
+ (when (notmuch-search-get-result pos)
+ (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.
+
+FUNCTION 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."
+
+ (lexical-let ((pos (notmuch-search-result-beginning beg))
+ ;; End must be a marker in case function changes the
+ ;; text.
+ (end (copy-marker end))
+ ;; Make sure we examine at least one result, even if
+ ;; (= beg end).
+ (first t))
+ ;; We have to be careful if the region extends beyond the results.
+ ;; In this case, pos could be null or there could be no result at
+ ;; pos.
+ (while (and pos (or (< pos end) first))
+ (when (notmuch-search-get-result pos)
+ (funcall function pos))
+ (setq pos (notmuch-search-result-end pos)
+ first nil))))
+;; Unindent the function argument of notmuch-search-foreach-result so
+;; the indentation of callers doesn't get out of hand.
+(put 'notmuch-search-foreach-result 'lisp-indent-function 2)
+
(defun notmuch-search-properties-in-region (property beg end)
- (save-excursion
- (let ((output nil)
- (last-line (line-number-at-pos end))
- (max-line (- (line-number-at-pos (point-max)) 2)))
- (goto-char beg)
- (beginning-of-line)
- (while (<= (line-number-at-pos) (min last-line max-line))
- (setq output (cons (get-text-property (point) property) output))
- (forward-line 1))
- output)))
+ (let (output)
+ (notmuch-search-foreach-result beg end
+ (lambda (pos)
+ (push (plist-get (notmuch-search-get-result pos) property) output)))
+ output))
(defun notmuch-search-find-thread-id ()
"Return the thread for the current thread"
- (get-text-property (point) 'notmuch-search-thread-id))
+ (let ((thread (plist-get (notmuch-search-get-result) :thread)))
+ (when thread (concat "thread:" thread))))
(defun notmuch-search-find-thread-id-region (beg end)
"Return a list of threads for the current region"
- (notmuch-search-properties-in-region 'notmuch-search-thread-id beg end))
+ (mapcar (lambda (thread) (concat "thread:" thread))
+ (notmuch-search-properties-in-region :thread beg end)))
+
+(defun notmuch-search-find-thread-id-region-search (beg end)
+ "Return a search string for threads for the current region"
+ (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))
(defun notmuch-search-find-authors ()
"Return the authors for the current thread"
- (get-text-property (point) 'notmuch-search-authors))
+ (plist-get (notmuch-search-get-result) :authors))
(defun notmuch-search-find-authors-region (beg end)
"Return a list of authors for the current region"
- (notmuch-search-properties-in-region 'notmuch-search-authors beg end))
+ (notmuch-search-properties-in-region :authors beg end))
(defun notmuch-search-find-subject ()
"Return the subject for the current thread"
- (get-text-property (point) 'notmuch-search-subject))
+ (plist-get (notmuch-search-get-result) :subject))
(defun notmuch-search-find-subject-region (beg end)
"Return a list of authors for the current region"
- (notmuch-search-properties-in-region 'notmuch-search-subject beg end))
+ (notmuch-search-properties-in-region :subject beg end))
-(defun notmuch-search-show-thread (&optional crypto-switch)
+(defun notmuch-search-show-thread ()
"Display the currently selected thread."
- (interactive "P")
+ (interactive)
(let ((thread-id (notmuch-search-find-thread-id))
(subject (notmuch-search-find-subject)))
(if (> (length thread-id) 0)
(notmuch-show thread-id
(current-buffer)
notmuch-search-query-string
- ;; name the buffer based on notmuch-search-find-subject
- (if (string-match "^[ \t]*$" subject)
- "[No Subject]"
- (truncate-string-to-width
- (concat "*"
- (truncate-string-to-width subject 32 nil nil t)
- "*")
- 32 nil nil t))
- crypto-switch)
+ ;; Name the buffer based on the subject.
+ (concat "*" (truncate-string-to-width subject 30 nil nil t) "*"))
(message "End of search results."))))
(defun notmuch-search-reply-to-thread (&optional prompt-for-sender)
+ "Begin composing a reply-all to the entire current thread in a new buffer."
+ (interactive "P")
+ (let ((message-id (notmuch-search-find-thread-id)))
+ (notmuch-mua-new-reply message-id prompt-for-sender t)))
+
+(defun notmuch-search-reply-to-thread-sender (&optional prompt-for-sender)
"Begin composing a reply to the entire current thread in a new buffer."
(interactive "P")
(let ((message-id (notmuch-search-find-thread-id)))
- (notmuch-mua-new-reply message-id prompt-for-sender)))
+ (notmuch-mua-new-reply message-id prompt-for-sender nil)))
(defun notmuch-call-notmuch-process (&rest args)
"Synchronously invoke \"notmuch\" with the given list of arguments.
@@ -470,151 +547,84 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
(error (buffer-substring beg end))
))))))
-(defun notmuch-tag (query &rest tags)
- "Add/remove tags in TAGS to messages matching QUERY.
-
-TAGS should be a list of strings of the form \"+TAG\" or \"-TAG\" and
-QUERY should be a string containing the search-query.
+(defun notmuch-search-set-tags (tags &optional pos)
+ (let ((new-result (plist-put (notmuch-search-get-result pos) :tags tags)))
+ (notmuch-search-update-result new-result pos)))
-Note: Other code should always use this function alter tags of
-messages instead of running (notmuch-call-notmuch-process \"tag\" ..)
-directly, so that hooks specified in notmuch-before-tag-hook and
-notmuch-after-tag-hook will be run."
- (run-hooks 'notmuch-before-tag-hook)
- (apply 'notmuch-call-notmuch-process
- (append (list "tag") tags (list "--" query)))
- (run-hooks 'notmuch-after-tag-hook))
-
-(defcustom notmuch-before-tag-hook nil
- "Hooks that are run before tags of a message are modified.
-
-'tags' will contain the tags that are about to be added or removed as
-a list of strings of the form \"+TAG\" or \"-TAG\".
-'query' will be a string containing the search query that determines
-the messages that are about to be tagged"
-
- :type 'hook
- :options '(hl-line-mode)
- :group 'notmuch)
-
-(defcustom notmuch-after-tag-hook nil
- "Hooks that are run after tags of a message are modified.
-
-'tags' will contain the tags that were added or removed as
-a list of strings of the form \"+TAG\" or \"-TAG\".
-'query' will be a string containing the search query that determines
-the messages that were tagged"
- :type 'hook
- :options '(hl-line-mode)
- :group 'notmuch)
-
-(defun notmuch-search-set-tags (tags)
- (save-excursion
- (end-of-line)
- (re-search-backward "(")
- (forward-char)
- (let ((beg (point))
- (inhibit-read-only t))
- (re-search-forward ")")
- (backward-char)
- (let ((end (point)))
- (delete-region beg end)
- (insert (propertize (mapconcat 'identity tags " ")
- 'face 'notmuch-tag-face))))))
-
-(defun notmuch-search-get-tags ()
- (save-excursion
- (end-of-line)
- (re-search-backward "(")
- (let ((beg (+ (point) 1)))
- (re-search-forward ")")
- (let ((end (- (point) 1)))
- (split-string (buffer-substring beg end))))))
+(defun notmuch-search-get-tags (&optional pos)
+ (plist-get (notmuch-search-get-result pos) :tags))
(defun notmuch-search-get-tags-region (beg end)
- (save-excursion
- (let ((output nil)
- (last-line (line-number-at-pos end))
- (max-line (- (line-number-at-pos (point-max)) 2)))
- (goto-char beg)
- (while (<= (line-number-at-pos) (min last-line max-line))
- (setq output (append output (notmuch-search-get-tags)))
- (forward-line 1))
- output)))
-
-(defun notmuch-search-add-tag-thread (tag)
- (notmuch-search-add-tag-region tag (point) (point)))
-
-(defun notmuch-search-add-tag-region (tag beg end)
- (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
- (notmuch-tag search-id-string (concat "+" tag))
- (save-excursion
- (let ((last-line (line-number-at-pos end))
- (max-line (- (line-number-at-pos (point-max)) 2)))
- (goto-char beg)
- (while (<= (line-number-at-pos) (min last-line max-line))
- (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<)))
- (forward-line))))))
-
-(defun notmuch-search-remove-tag-thread (tag)
- (notmuch-search-remove-tag-region tag (point) (point)))
-
-(defun notmuch-search-remove-tag-region (tag beg end)
- (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
- (notmuch-tag search-id-string (concat "-" tag))
- (save-excursion
- (let ((last-line (line-number-at-pos end))
- (max-line (- (line-number-at-pos (point-max)) 2)))
- (goto-char beg)
- (while (<= (line-number-at-pos) (min last-line max-line))
- (notmuch-search-set-tags (delete tag (notmuch-search-get-tags)))
- (forward-line))))))
-
-(defun notmuch-search-add-tag (tag)
- "Add a tag to the currently selected thread or region.
-
-The tag is added to all messages in the currently selected thread
-or threads in the current region."
- (interactive
- (list (notmuch-select-tag-with-completion "Tag to add: ")))
- (save-excursion
- (if (region-active-p)
- (let* ((beg (region-beginning))
- (end (region-end)))
- (notmuch-search-add-tag-region tag beg end))
- (notmuch-search-add-tag-thread tag))))
+ (let (output)
+ (notmuch-search-foreach-result beg end
+ (lambda (pos)
+ (setq output (append output (notmuch-search-get-tags pos)))))
+ output))
+
+(defun notmuch-search-tag-region (beg end &optional tag-changes)
+ "Change tags for threads in the given region."
+ (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))
+ (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))
+ (notmuch-search-foreach-result beg end
+ (lambda (pos)
+ (notmuch-search-set-tags
+ (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)
+ pos)))))
+
+(defun notmuch-search-tag (&optional tag-changes)
+ "Change tags for the currently selected thread or region.
+
+See `notmuch-tag' for information on the format of TAG-CHANGES."
+ (interactive)
+ (let* ((beg (if (region-active-p) (region-beginning) (point)))
+ (end (if (region-active-p) (region-end) (point))))
+ (funcall 'notmuch-search-tag-region beg end tag-changes)))
-(defun notmuch-search-remove-tag (tag)
- "Remove a tag from the currently selected thread or region.
+(defun notmuch-search-add-tag ()
+ "Same as `notmuch-search-tag' but sets initial input to '+'."
+ (interactive)
+ (notmuch-search-tag "+"))
-The tag is removed from all messages in the currently selected
-thread or threads in the current region."
- (interactive
- (list (notmuch-select-tag-with-completion
- "Tag to remove: "
- (if (region-active-p)
- (mapconcat 'identity
- (notmuch-search-find-thread-id-region (region-beginning) (region-end))
- " ")
- (notmuch-search-find-thread-id)))))
- (save-excursion
- (if (region-active-p)
- (let* ((beg (region-beginning))
- (end (region-end)))
- (notmuch-search-remove-tag-region tag beg end))
- (notmuch-search-remove-tag-thread tag))))
+(defun notmuch-search-remove-tag ()
+ "Same as `notmuch-search-tag' but sets initial input to '-'."
+ (interactive)
+ (notmuch-search-tag "-"))
(defun notmuch-search-archive-thread ()
"Archive the currently selected thread (remove its \"inbox\" tag).
This function advances the next thread when finished."
(interactive)
- (notmuch-search-remove-tag-thread "inbox")
- (forward-line))
-
-(defvar notmuch-search-process-filter-data nil
- "Data that has not yet been processed.")
-(make-variable-buffer-local 'notmuch-search-process-filter-data)
+ (notmuch-search-tag '("-inbox"))
+ (notmuch-search-next-thread))
+
+(defun notmuch-search-update-result (result &optional pos)
+ "Replace the result object of the thread at POS (or point) by
+RESULT and redraw it.
+
+This will keep point in a reasonable location. However, if there
+are enclosing save-excursions and the saved point is in the
+result being updated, the point will be restored to the beginning
+of the result."
+ (let ((start (notmuch-search-result-beginning pos))
+ (end (notmuch-search-result-end pos))
+ (init-point (point))
+ (inhibit-read-only t))
+ ;; Delete the current thread
+ (delete-region start end)
+ ;; Insert the updated thread
+ (notmuch-search-show-result result start)
+ ;; If point was inside the old result, make an educated guess
+ ;; about where to place it now. Unfortunately, this won't work
+ ;; with save-excursion (or any other markers that would be nice to
+ ;; preserve, such as the window start), but there's nothing we can
+ ;; do about that without a way to retrieve markers in a region.
+ (when (and (>= init-point start) (<= init-point end))
+ (let* ((new-end (notmuch-search-result-end start))
+ (new-point (if (= init-point end)
+ new-end
+ (min init-point (- new-end 1)))))
+ (goto-char new-point)))))
(defun notmuch-search-process-sentinel (proc msg)
"Add a message to let user know when \"notmuch search\" exits"
@@ -622,7 +632,8 @@ This function advances the next thread when finished."
(status (process-status proc))
(exit-status (process-exit-status proc))
(never-found-target-thread nil))
- (if (memq status '(exit signal))
+ (when (memq status '(exit signal))
+ (kill-buffer (process-get proc 'parse-buf))
(if (buffer-live-p buffer)
(with-current-buffer buffer
(save-excursion
@@ -631,55 +642,47 @@ This function advances the next thread when finished."
(goto-char (point-max))
(if (eq status 'signal)
(insert "Incomplete search results (search process was killed).\n"))
- (if (eq status 'exit)
- (progn
- (if notmuch-search-process-filter-data
- (insert (concat "Error: Unexpected output from notmuch search:\n" notmuch-search-process-filter-data)))
- (insert "End of search results.")
- (if (not (= exit-status 0))
- (insert (format " (process returned %d)" exit-status)))
- (insert "\n")
- (if (and atbob
- (not (string= notmuch-search-target-thread "found")))
- (set 'never-found-target-thread t))))))
+ (when (eq status 'exit)
+ (insert "End of search results.")
+ (unless (= exit-status 0)
+ (insert (format " (process returned %d)" exit-status)))
+ (insert "\n")
+ (if (and atbob
+ (not (string= notmuch-search-target-thread "found")))
+ (set 'never-found-target-thread t)))))
(when (and never-found-target-thread
notmuch-search-target-line)
(goto-char (point-min))
(forward-line (1- notmuch-search-target-line))))))))
-(defcustom notmuch-search-line-faces nil
+(defcustom notmuch-search-line-faces '(("unread" :weight bold)
+ ("flagged" :foreground "blue"))
"Tag/face mapping for line highlighting in notmuch-search.
Here is an example of how to color search results based on tags.
(the following text would be placed in your ~/.emacs file):
- (setq notmuch-search-line-faces '((\"delete\" . (:foreground \"red\"
+ (setq notmuch-search-line-faces '((\"deleted\" . (:foreground \"red\"
:background \"blue\"))
(\"unread\" . (:foreground \"green\"))))
The attributes defined for matching tags are merged, with later
-attributes overriding earlier. A message having both \"delete\"
+attributes overriding earlier. A message having both \"deleted\"
and \"unread\" tags with the above settings would have a green
foreground and blue background."
:type '(alist :key-type (string) :value-type (custom-face-edit))
- :group 'notmuch)
+ :group 'notmuch-search
+ :group 'notmuch-faces)
(defun notmuch-search-color-line (start end line-tag-list)
"Colorize lines in `notmuch-show' based on tags."
- ;; Create the overlay only if the message has tags which match one
- ;; of those specified in `notmuch-search-line-faces'.
- (let (overlay)
- (mapc (lambda (elem)
- (let ((tag (car elem))
- (attributes (cdr elem)))
- (when (member tag line-tag-list)
- (when (not overlay)
- (setq overlay (make-overlay start end)))
- ;; Merge the specified properties with any already
- ;; applied from an earlier match.
- (overlay-put overlay 'face
- (append (overlay-get overlay 'face) attributes)))))
- notmuch-search-line-faces)))
+ (mapc (lambda (elem)
+ (let ((tag (car elem))
+ (attributes (cdr elem)))
+ (when (member tag line-tag-list)
+ (notmuch-combine-face-text-property start end attributes))))
+ ;; Reverse the list so earlier entries take precedence
+ (reverse notmuch-search-line-faces)))
(defun notmuch-search-author-propertize (authors)
"Split `authors' into matching and non-matching authors and
@@ -761,99 +764,111 @@ non-authors is found, assume that all of the authors match."
(overlay-put overlay 'isearch-open-invisible #'delete-overlay)))
(insert padding))))
-(defun notmuch-search-insert-field (field date count authors subject tags)
+(defun notmuch-search-insert-field (field format-string result)
(cond
((string-equal field "date")
- (insert (propertize (format (cdr (assoc field notmuch-search-result-format)) date)
+ (insert (propertize (format format-string (plist-get result :date_relative))
'face 'notmuch-search-date)))
((string-equal field "count")
- (insert (propertize (format (cdr (assoc field notmuch-search-result-format)) count)
+ (insert (propertize (format format-string
+ (format "[%s/%s]" (plist-get result :matched)
+ (plist-get result :total)))
'face 'notmuch-search-count)))
((string-equal field "subject")
- (insert (propertize (format (cdr (assoc field notmuch-search-result-format)) subject)
+ (insert (propertize (format format-string (plist-get result :subject))
'face 'notmuch-search-subject)))
((string-equal field "authors")
- (notmuch-search-insert-authors (cdr (assoc field notmuch-search-result-format)) authors))
+ (notmuch-search-insert-authors format-string (plist-get result :authors)))
((string-equal field "tags")
- (insert (concat "(" (propertize tags 'font-lock-face 'notmuch-tag-face) ")")))))
+ (let ((tags-str (mapconcat 'identity (plist-get result :tags) " ")))
+ (insert (propertize (format format-string tags-str)
+ 'face 'notmuch-tag-face))))))
+
+(defun notmuch-search-show-result (result &optional pos)
+ "Insert RESULT at POS or the end of the buffer if POS is null."
+ ;; Ignore excluded matches
+ (unless (= (plist-get result :matched) 0)
+ (let ((beg (or pos (point-max))))
+ (save-excursion
+ (goto-char beg)
+ (dolist (spec notmuch-search-result-format)
+ (notmuch-search-insert-field (car spec) (cdr spec) result))
+ (insert "\n")
+ (notmuch-search-color-line beg (point) (plist-get result :tags))
+ (put-text-property beg (point) 'notmuch-search-result result))
+ (when (string= (plist-get result :thread) notmuch-search-target-thread)
+ (setq notmuch-search-target-thread "found")
+ (goto-char beg)))))
+
+(defun notmuch-search-show-error (string &rest objects)
+ (save-excursion
+ (goto-char (point-max))
+ (insert "Error: Unexpected output from notmuch search:\n")
+ (insert (apply #'format string objects))
+ (insert "\n")))
+
+(defvar notmuch-search-process-state nil
+ "Parsing state of the search process filter.")
-(defun notmuch-search-show-result (date count authors subject tags)
- (let ((fields) (field))
- (setq fields (mapcar 'car notmuch-search-result-format))
- (loop for field in fields
- do (notmuch-search-insert-field field date count authors subject tags)))
- (insert "\n"))
+(defvar notmuch-search-json-parser nil
+ "Incremental JSON parser for the search process filter.")
(defun notmuch-search-process-filter (proc string)
"Process and filter the output of \"notmuch search\""
- (let ((buffer (process-buffer proc))
- (found-target nil))
- (if (buffer-live-p buffer)
- (with-current-buffer buffer
- (save-excursion
- (let ((line 0)
- (more t)
- (inhibit-read-only t)
- (string (concat notmuch-search-process-filter-data string)))
- (setq notmuch-search-process-filter-data nil)
- (while more
- (while (and (< line (length string)) (= (elt string line) ?\n))
- (setq line (1+ line)))
- (if (string-match "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" string line)
- (let* ((thread-id (match-string 1 string))
- (date (match-string 2 string))
- (count (match-string 3 string))
- (authors (match-string 4 string))
- (subject (match-string 5 string))
- (tags (match-string 6 string))
- (tag-list (if tags (save-match-data (split-string tags)))))
- (goto-char (point-max))
- (if (/= (match-beginning 1) line)
- (insert (concat "Error: Unexpected output from notmuch search:\n" (substring string line (match-beginning 1)) "\n")))
- (let ((beg (point)))
- (notmuch-search-show-result date count authors subject tags)
- (notmuch-search-color-line beg (point) tag-list)
- (put-text-property beg (point) 'notmuch-search-thread-id thread-id)
- (put-text-property beg (point) 'notmuch-search-authors authors)
- (put-text-property beg (point) 'notmuch-search-subject subject)
- (if (string= thread-id notmuch-search-target-thread)
- (progn
- (set 'found-target beg)
- (set 'notmuch-search-target-thread "found"))))
- (set 'line (match-end 0)))
- (set 'more nil)
- (while (and (< line (length string)) (= (elt string line) ?\n))
- (setq line (1+ line)))
- (if (< line (length string))
- (setq notmuch-search-process-filter-data (substring string line)))
- ))))
- (if found-target
- (goto-char found-target)))
- (delete-process proc))))
-
-(defun notmuch-search-operate-all (action)
- "Add/remove tags from all matching messages.
-
-This command adds or removes tags from all messages matching the
-current search terms. When called interactively, this command
-will prompt for tags to be added or removed. Tags prefixed with
-'+' will be added and tags prefixed with '-' will be removed.
-
-Each character of the tag name may consist of alphanumeric
-characters as well as `_.+-'.
-"
- (interactive "sOperation (+add -drop): notmuch tag ")
- (let ((action-split (split-string action " +")))
- ;; Perform some validation
- (let ((words action-split))
- (when (null words) (error "No operation given"))
- (while words
- (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
- (error "Action must be of the form `+thistag -that_tag'"))
- (setq words (cdr words))))
- (apply 'notmuch-tag notmuch-search-query-string action-split)))
+ (let ((results-buf (process-buffer proc))
+ (parse-buf (process-get proc 'parse-buf))
+ (inhibit-read-only t)
+ done)
+ (if (not (buffer-live-p results-buf))
+ (delete-process proc)
+ (with-current-buffer parse-buf
+ ;; Insert new data
+ (save-excursion
+ (goto-char (point-max))
+ (insert string)))
+ (with-current-buffer results-buf
+ (while (not done)
+ (condition-case nil
+ (case notmuch-search-process-state
+ ((begin)
+ ;; Enter the results list
+ (if (eq (notmuch-json-begin-compound
+ notmuch-search-json-parser) 'retry)
+ (setq done t)
+ (setq notmuch-search-process-state 'result)))
+ ((result)
+ ;; Parse a result
+ (let ((result (notmuch-json-read notmuch-search-json-parser)))
+ (case result
+ ((retry) (setq done t))
+ ((end) (setq notmuch-search-process-state 'end))
+ (otherwise (notmuch-search-show-result result)))))
+ ((end)
+ ;; Any trailing data is unexpected
+ (notmuch-json-eof notmuch-search-json-parser)
+ (setq done t)))
+ (json-error
+ ;; Do our best to resynchronize and ensure forward
+ ;; progress
+ (notmuch-search-show-error
+ "%s"
+ (with-current-buffer parse-buf
+ (let ((bad (buffer-substring (line-beginning-position)
+ (line-end-position))))
+ (forward-line)
+ bad))))))
+ ;; Clear out what we've parsed
+ (with-current-buffer parse-buf
+ (delete-region (point-min) (point)))))))
+
+(defun notmuch-search-tag-all (&optional tag-changes)
+ "Add/remove tags from all messages in current search buffer.
+
+See `notmuch-tag' for information on the format of TAG-CHANGES."
+ (interactive)
+ (apply 'notmuch-tag notmuch-search-query-string tag-changes))
(defun notmuch-search-buffer-title (query)
"Returns the title for a buffer with notmuch search results."
@@ -908,22 +923,26 @@ PROMPT is the string to prompt with."
completions)))
(t (list string)))))))
;; this was simpler than convincing completing-read to accept spaces:
- (define-key keymap (kbd "<tab>") 'minibuffer-complete)
- (read-from-minibuffer prompt nil keymap nil
- 'notmuch-query-history nil nil))))
+ (define-key keymap (kbd "TAB") 'minibuffer-complete)
+ (let ((history-delete-duplicates t))
+ (read-from-minibuffer prompt nil keymap nil
+ 'notmuch-search-history nil nil)))))
;;;###autoload
-(defun notmuch-search (query &optional oldest-first target-thread target-line continuation)
- "Run \"notmuch search\" with the given query string and display results.
+(defun notmuch-search (&optional query oldest-first target-thread target-line continuation)
+ "Run \"notmuch search\" with the given `query' and display results.
-The optional parameters are used as follows:
+If `query' is nil, it is read interactively from the minibuffer.
+Other optional parameters are used as follows:
oldest-first: A Boolean controlling the sort order of returned threads
target-thread: A thread ID (with the thread: prefix) that will be made
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."
- (interactive (list (notmuch-read-query "Notmuch search: ")))
+ (interactive)
+ (if (null query)
+ (setq query (notmuch-read-query "Notmuch search: ")))
(let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))
(switch-to-buffer buffer)
(notmuch-search-mode)
@@ -945,10 +964,19 @@ The optional parameters are used as follows:
(let ((proc (start-process
"notmuch-search" buffer
notmuch-command "search"
+ "--format=json"
(if oldest-first
"--sort=oldest-first"
"--sort=newest-first")
- query)))
+ query))
+ ;; Use a scratch buffer to accumulate partial output.
+ ;; This buffer will be killed by the sentinel, which
+ ;; should be called no matter how the process dies.
+ (parse-buf (generate-new-buffer " *notmuch search parse*")))
+ (set (make-local-variable 'notmuch-search-process-state) 'begin)
+ (set (make-local-variable 'notmuch-search-json-parser)
+ (notmuch-json-create-parser parse-buf))
+ (process-put proc 'parse-buf parse-buf)
(set-process-sentinel proc 'notmuch-search-process-sentinel)
(set-process-filter proc 'notmuch-search-process-filter)
(set-process-query-on-exit-flag proc nil))))
@@ -997,7 +1025,7 @@ Note that the recommended way of achieving the same is using
:type '(choice (const :tag "notmuch new" nil)
(const :tag "Disabled" "")
(string :tag "Custom script"))
- :group 'notmuch)
+ :group 'notmuch-external)
(defun notmuch-poll ()
"Run \"notmuch new\" or an external script to import mail.
@@ -1006,8 +1034,8 @@ Invokes `notmuch-poll-script', \"notmuch new\", or does nothing
depending on the value of `notmuch-poll-script'."
(interactive)
(if (stringp notmuch-poll-script)
- (if (not (string= notmuch-poll-script ""))
- (call-process notmuch-poll-script nil nil))
+ (unless (string= notmuch-poll-script "")
+ (call-process notmuch-poll-script nil nil))
(call-process notmuch-command nil nil nil "new")))
(defun notmuch-search-poll-and-refresh-view ()
@@ -1062,21 +1090,39 @@ current search results AND that are tagged with the given tag."
(interactive)
(notmuch-hello))
+(defun notmuch-interesting-buffer (b)
+ "Is the current buffer of interest to a notmuch user?"
+ (with-current-buffer b
+ (memq major-mode '(notmuch-show-mode
+ notmuch-search-mode
+ notmuch-hello-mode
+ message-mode))))
+
;;;###autoload
-(defun notmuch-jump-to-recent-buffer ()
- "Jump to the most recent notmuch buffer (search, show or hello).
+(defun notmuch-cycle-notmuch-buffers ()
+ "Cycle through any existing notmuch buffers (search, show or hello).
-If no recent buffer is found, run `notmuch'."
+If the current buffer is the only notmuch buffer, bury it. If no
+notmuch buffers exist, run `notmuch'."
(interactive)
- (let ((last
- (loop for buffer in (buffer-list)
- if (with-current-buffer buffer
- (memq major-mode '(notmuch-show-mode
- notmuch-search-mode
- notmuch-hello-mode)))
- return buffer)))
- (if last
- (switch-to-buffer last)
+
+ (let (start first)
+ ;; If the current buffer is a notmuch buffer, remember it and then
+ ;; bury it.
+ (when (notmuch-interesting-buffer (current-buffer))
+ (setq start (current-buffer))
+ (bury-buffer))
+
+ ;; Find the first notmuch buffer.
+ (setq first (loop for buffer in (buffer-list)
+ if (notmuch-interesting-buffer buffer)
+ return buffer))
+
+ (if first
+ ;; If the first one we found is any other than the starting
+ ;; buffer, switch to it.
+ (unless (eq first start)
+ (switch-to-buffer first))
(notmuch))))
(setq mail-user-agent 'notmuch-user-agent)
diff --git a/lib/Makefile.local b/lib/Makefile.local
index 54c4dea..8a9aa28 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -5,7 +5,7 @@
# the library interface, (such as the deletion of an API or a major
# semantic change that breaks formerly functioning code).
#
-LIBNOTMUCH_VERSION_MAJOR = 2
+LIBNOTMUCH_VERSION_MAJOR = 3
# The minor version of the library interface. This should be incremented at
# the time of release for any additions to the library interface,
diff --git a/lib/database.cc b/lib/database.cc
index 8103bd9..761dc1a 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -520,9 +520,10 @@ parse_references (void *ctx,
}
}
-notmuch_database_t *
-notmuch_database_create (const char *path)
+notmuch_status_t
+notmuch_database_create (const char *path, notmuch_database_t **database)
{
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
notmuch_database_t *notmuch = NULL;
char *notmuch_path = NULL;
struct stat st;
@@ -530,6 +531,7 @@ notmuch_database_create (const char *path)
if (path == NULL) {
fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");
+ status = NOTMUCH_STATUS_NULL_POINTER;
goto DONE;
}
@@ -537,12 +539,14 @@ notmuch_database_create (const char *path)
if (err) {
fprintf (stderr, "Error: Cannot create database at %s: %s.\n",
path, strerror (errno));
+ status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
if (! S_ISDIR (st.st_mode)) {
fprintf (stderr, "Error: Cannot create database at %s: Not a directory.\n",
path);
+ status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
@@ -553,18 +557,30 @@ notmuch_database_create (const char *path)
if (err) {
fprintf (stderr, "Error: Cannot create directory %s: %s.\n",
notmuch_path, strerror (errno));
+ status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
- notmuch = notmuch_database_open (path,
- NOTMUCH_DATABASE_MODE_READ_WRITE);
- notmuch_database_upgrade (notmuch, NULL, NULL);
+ status = notmuch_database_open (path,
+ NOTMUCH_DATABASE_MODE_READ_WRITE,
+ &notmuch);
+ if (status)
+ goto DONE;
+ status = notmuch_database_upgrade (notmuch, NULL, NULL);
+ if (status) {
+ notmuch_database_close(notmuch);
+ notmuch = NULL;
+ }
DONE:
if (notmuch_path)
talloc_free (notmuch_path);
- return notmuch;
+ if (database)
+ *database = notmuch;
+ else
+ talloc_free (notmuch);
+ return status;
}
notmuch_status_t
@@ -578,20 +594,29 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
return NOTMUCH_STATUS_SUCCESS;
}
-notmuch_database_t *
+notmuch_status_t
notmuch_database_open (const char *path,
- notmuch_database_mode_t mode)
+ notmuch_database_mode_t mode,
+ notmuch_database_t **database)
{
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
+ void *local = talloc_new (NULL);
notmuch_database_t *notmuch = NULL;
- char *notmuch_path = NULL, *xapian_path = NULL;
+ char *notmuch_path, *xapian_path;
struct stat st;
int err;
unsigned int i, version;
static int initialized = 0;
- if (asprintf (&notmuch_path, "%s/%s", path, ".notmuch") == -1) {
- notmuch_path = NULL;
+ if (path == NULL) {
+ fprintf (stderr, "Error: Cannot open a database for a NULL path.\n");
+ status = NOTMUCH_STATUS_NULL_POINTER;
+ goto DONE;
+ }
+
+ if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {
fprintf (stderr, "Out of memory\n");
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;
}
@@ -599,12 +624,13 @@ notmuch_database_open (const char *path,
if (err) {
fprintf (stderr, "Error opening database at %s: %s\n",
notmuch_path, strerror (errno));
+ status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
- if (asprintf (&xapian_path, "%s/%s", notmuch_path, "xapian") == -1) {
- xapian_path = NULL;
+ if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {
fprintf (stderr, "Out of memory\n");
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;
}
@@ -617,7 +643,7 @@ notmuch_database_open (const char *path,
initialized = 1;
}
- notmuch = talloc (NULL, notmuch_database_t);
+ notmuch = talloc_zero (NULL, notmuch_database_t);
notmuch->exception_reported = FALSE;
notmuch->path = talloc_strdup (notmuch, path);
@@ -643,8 +669,9 @@ notmuch_database_open (const char *path,
" read-write mode.\n",
notmuch_path, version, NOTMUCH_DATABASE_VERSION);
notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
- notmuch_database_close (notmuch);
+ notmuch_database_destroy (notmuch);
notmuch = NULL;
+ status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
@@ -703,23 +730,27 @@ notmuch_database_open (const char *path,
} catch (const Xapian::Error &error) {
fprintf (stderr, "A Xapian exception occurred opening database: %s\n",
error.get_msg().c_str());
+ notmuch_database_destroy (notmuch);
notmuch = NULL;
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
DONE:
- if (notmuch_path)
- free (notmuch_path);
- if (xapian_path)
- free (xapian_path);
+ talloc_free (local);
- return notmuch;
+ if (database)
+ *database = notmuch;
+ else
+ talloc_free (notmuch);
+ return status;
}
void
notmuch_database_close (notmuch_database_t *notmuch)
{
try {
- if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
+ if (notmuch->xapian_db != NULL &&
+ notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();
} catch (const Xapian::Error &error) {
if (! notmuch->exception_reported) {
@@ -728,10 +759,31 @@ notmuch_database_close (notmuch_database_t *notmuch)
}
}
+ /* Many Xapian objects (and thus notmuch objects) hold references to
+ * the database, so merely deleting the database may not suffice to
+ * close it. Thus, we explicitly close it here. */
+ if (notmuch->xapian_db != NULL) {
+ try {
+ notmuch->xapian_db->close();
+ } catch (const Xapian::Error &error) {
+ /* do nothing */
+ }
+ }
+
delete notmuch->term_gen;
+ notmuch->term_gen = NULL;
delete notmuch->query_parser;
+ notmuch->query_parser = NULL;
delete notmuch->xapian_db;
+ notmuch->xapian_db = NULL;
delete notmuch->value_range_processor;
+ notmuch->value_range_processor = NULL;
+}
+
+void
+notmuch_database_destroy (notmuch_database_t *notmuch)
+{
+ notmuch_database_close (notmuch);
talloc_free (notmuch);
}
@@ -903,8 +955,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
mtime = Xapian::sortable_unserialise (
document.get_value (NOTMUCH_VALUE_TIMESTAMP));
- directory = notmuch_database_get_directory (notmuch,
- term.c_str() + 10);
+ directory = _notmuch_directory_create (notmuch, term.c_str() + 10,
+ NOTMUCH_FIND_CREATE, &status);
notmuch_directory_set_mtime (directory, mtime);
notmuch_directory_destroy (directory);
}
@@ -1145,9 +1197,17 @@ _notmuch_database_split_path (void *ctx,
return NOTMUCH_STATUS_SUCCESS;
}
+/* Find the document ID of the specified directory.
+ *
+ * If (flags & NOTMUCH_FIND_CREATE), a new directory document will be
+ * created if one does not exist for 'path'. Otherwise, if the
+ * directory document does not exist, this sets *directory_id to
+ * ((unsigned int)-1) and returns NOTMUCH_STATUS_SUCCESS.
+ */
notmuch_status_t
_notmuch_database_find_directory_id (notmuch_database_t *notmuch,
const char *path,
+ notmuch_find_flags_t flags,
unsigned int *directory_id)
{
notmuch_directory_t *directory;
@@ -1158,8 +1218,8 @@ _notmuch_database_find_directory_id (notmuch_database_t *notmuch,
return NOTMUCH_STATUS_SUCCESS;
}
- directory = _notmuch_directory_create (notmuch, path, &status);
- if (status) {
+ directory = _notmuch_directory_create (notmuch, path, flags, &status);
+ if (status || !directory) {
*directory_id = -1;
return status;
}
@@ -1188,13 +1248,16 @@ _notmuch_database_get_directory_path (void *ctx,
* database path), return a new string (with 'ctx' as the talloc
* owner) suitable for use as a direntry term value.
*
- * The necessary directory documents will be created in the database
- * as needed.
+ * If (flags & NOTMUCH_FIND_CREATE), the necessary directory documents
+ * will be created in the database as needed. Otherwise, if the
+ * necessary directory documents do not exist, this sets
+ * *direntry to NULL and returns NOTMUCH_STATUS_SUCCESS.
*/
notmuch_status_t
_notmuch_database_filename_to_direntry (void *ctx,
notmuch_database_t *notmuch,
const char *filename,
+ notmuch_find_flags_t flags,
char **direntry)
{
const char *relative, *directory, *basename;
@@ -1208,10 +1271,12 @@ _notmuch_database_filename_to_direntry (void *ctx,
if (status)
return status;
- status = _notmuch_database_find_directory_id (notmuch, directory,
+ status = _notmuch_database_find_directory_id (notmuch, directory, flags,
&directory_id);
- if (status)
+ if (status || directory_id == (unsigned int)-1) {
+ *direntry = NULL;
return status;
+ }
*direntry = talloc_asprintf (ctx, "%u:%s", directory_id, basename);
@@ -1252,20 +1317,27 @@ _notmuch_database_relative_path (notmuch_database_t *notmuch,
return relative;
}
-notmuch_directory_t *
+notmuch_status_t
notmuch_database_get_directory (notmuch_database_t *notmuch,
- const char *path)
+ const char *path,
+ notmuch_directory_t **directory)
{
notmuch_status_t status;
+ if (directory == NULL)
+ return NOTMUCH_STATUS_NULL_POINTER;
+ *directory = NULL;
+
try {
- return _notmuch_directory_create (notmuch, path, &status);
+ *directory = _notmuch_directory_create (notmuch, path,
+ NOTMUCH_FIND_LOOKUP, &status);
} catch (const Xapian::Error &error) {
fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
- return NULL;
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
+ return status;
}
/* Allocate a document ID that satisfies the following criteria:
@@ -1816,12 +1888,15 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
if (message_ret == NULL)
return NOTMUCH_STATUS_NULL_POINTER;
+ /* return NULL on any failure */
+ *message_ret = NULL;
+
local = talloc_new (notmuch);
try {
- status = _notmuch_database_filename_to_direntry (local, notmuch,
- filename, &direntry);
- if (status)
+ status = _notmuch_database_filename_to_direntry (
+ local, notmuch, filename, NOTMUCH_FIND_LOOKUP, &direntry);
+ if (status || !direntry)
goto DONE;
term = talloc_asprintf (local, "%s%s", prefix, direntry);
diff --git a/lib/directory.cc b/lib/directory.cc
index 70e1693..6a3ffed 100644
--- a/lib/directory.cc
+++ b/lib/directory.cc
@@ -82,28 +82,41 @@ find_directory_document (notmuch_database_t *notmuch,
return NOTMUCH_PRIVATE_STATUS_SUCCESS;
}
+/* Find or create a directory document.
+ *
+ * 'path' should be a path relative to the path of 'database', or else
+ * should be an absolute path with initial components that match the
+ * path of 'database'.
+ *
+ * If (flags & NOTMUCH_FIND_CREATE), then the directory document will
+ * be created if it does not exist. Otherwise, if the directory
+ * document does not exist, *status_ret is set to
+ * NOTMUCH_STATUS_SUCCESS and this returns NULL.
+ */
notmuch_directory_t *
_notmuch_directory_create (notmuch_database_t *notmuch,
const char *path,
+ notmuch_find_flags_t flags,
notmuch_status_t *status_ret)
{
Xapian::WritableDatabase *db;
notmuch_directory_t *directory;
notmuch_private_status_t private_status;
const char *db_path;
+ notmuch_bool_t create = (flags & NOTMUCH_FIND_CREATE);
*status_ret = NOTMUCH_STATUS_SUCCESS;
path = _notmuch_database_relative_path (notmuch, path);
- if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
+ if (create && notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
INTERNAL_ERROR ("Failure to ensure database is writable");
- db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
-
directory = talloc (notmuch, notmuch_directory_t);
- if (unlikely (directory == NULL))
+ if (unlikely (directory == NULL)) {
+ *status_ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
return NULL;
+ }
directory->notmuch = notmuch;
@@ -122,6 +135,13 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
directory->document_id = directory->doc.get_docid ();
if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
+ if (!create) {
+ notmuch_directory_destroy (directory);
+ directory = NULL;
+ *status_ret = NOTMUCH_STATUS_SUCCESS;
+ goto DONE;
+ }
+
void *local = talloc_new (directory);
const char *parent, *basename;
Xapian::docid parent_id;
@@ -133,7 +153,13 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
_notmuch_database_split_path (local, path, &parent, &basename);
- _notmuch_database_find_directory_id (notmuch, parent, &parent_id);
+ *status_ret = _notmuch_database_find_directory_id (
+ notmuch, parent, NOTMUCH_FIND_CREATE, &parent_id);
+ if (*status_ret) {
+ notmuch_directory_destroy (directory);
+ directory = NULL;
+ goto DONE;
+ }
if (basename) {
term = talloc_asprintf (local, "%s%u:%s",
@@ -145,6 +171,8 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
directory->doc.add_value (NOTMUCH_VALUE_TIMESTAMP,
Xapian::sortable_serialise (0));
+ db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
+
directory->document_id = _notmuch_database_generate_doc_id (notmuch);
db->replace_document (directory->document_id, directory->doc);
talloc_free (local);
@@ -158,10 +186,11 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
notmuch_directory_destroy (directory);
+ directory = NULL;
*status_ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
- return NULL;
}
+ DONE:
if (db_path != path)
free ((char *) db_path);
diff --git a/lib/index.cc b/lib/index.cc
index d8f8b2b..e377732 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -315,6 +315,7 @@ _index_mime_part (notmuch_message_t *message,
GByteArray *byte_array;
GMimeContentDisposition *disposition;
char *body;
+ const char *charset;
if (! part) {
fprintf (stderr, "Warning: Not indexing empty mime part.\n");
@@ -390,6 +391,20 @@ _index_mime_part (notmuch_message_t *message,
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filter),
discard_uuencode_filter);
+ charset = g_mime_object_get_content_type_parameter (part, "charset");
+ if (charset) {
+ GMimeFilter *charset_filter;
+ charset_filter = g_mime_filter_charset_new (charset, "UTF-8");
+ /* This result can be NULL for things like "unknown-8bit".
+ * Don't set a NULL filter as that makes GMime print
+ * annoying assertion-failure messages on stderr. */
+ if (charset_filter) {
+ g_mime_stream_filter_add (GMIME_STREAM_FILTER (filter),
+ charset_filter);
+ g_object_unref (charset_filter);
+ }
+ }
+
wrapper = g_mime_part_get_content_object (GMIME_PART (part));
if (wrapper)
g_mime_data_wrapper_write_to_stream (wrapper, filter);
diff --git a/lib/message.cc b/lib/message.cc
index 0075425..978de06 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -495,9 +495,8 @@ _notmuch_message_add_filename (notmuch_message_t *message,
if (status)
return status;
- status = _notmuch_database_filename_to_direntry (local,
- message->notmuch,
- filename, &direntry);
+ status = _notmuch_database_filename_to_direntry (
+ local, message->notmuch, filename, NOTMUCH_FIND_CREATE, &direntry);
if (status)
return status;
@@ -541,9 +540,9 @@ _notmuch_message_remove_filename (notmuch_message_t *message,
notmuch_status_t status;
Xapian::TermIterator i, last;
- status = _notmuch_database_filename_to_direntry (local, message->notmuch,
- filename, &direntry);
- if (status)
+ status = _notmuch_database_filename_to_direntry (
+ local, message->notmuch, filename, NOTMUCH_FIND_LOOKUP, &direntry);
+ if (status || !direntry)
return status;
/* Unlink this file from its parent directory. */
@@ -1028,13 +1027,54 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag)
return NOTMUCH_STATUS_SUCCESS;
}
+/* Is the given filename within a maildir directory?
+ *
+ * Specifically, is the final directory component of 'filename' either
+ * "cur" or "new". If so, return a pointer to that final directory
+ * component within 'filename'. If not, return NULL.
+ *
+ * A non-NULL return value is guaranteed to be a valid string pointer
+ * pointing to the characters "new/" or "cur/", (but not
+ * NUL-terminated).
+ */
+static const char *
+_filename_is_in_maildir (const char *filename)
+{
+ const char *slash, *dir = NULL;
+
+ /* Find the last '/' separating directory from filename. */
+ slash = strrchr (filename, '/');
+ if (slash == NULL)
+ return NULL;
+
+ /* Jump back 4 characters to where the previous '/' will be if the
+ * directory is named "cur" or "new". */
+ if (slash - filename < 4)
+ return NULL;
+
+ slash -= 4;
+
+ if (*slash != '/')
+ return NULL;
+
+ dir = slash + 1;
+
+ if (STRNCMP_LITERAL (dir, "cur/") == 0 ||
+ STRNCMP_LITERAL (dir, "new/") == 0)
+ {
+ return dir;
+ }
+
+ return NULL;
+}
+
notmuch_status_t
notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
{
const char *flags;
notmuch_status_t status;
notmuch_filenames_t *filenames;
- const char *filename;
+ const char *filename, *dir;
char *combined_flags = talloc_strdup (message, "");
unsigned i;
int seen_maildir_info = 0;
@@ -1044,15 +1084,25 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
notmuch_filenames_move_to_next (filenames))
{
filename = notmuch_filenames_get (filenames);
+ dir = _filename_is_in_maildir (filename);
- flags = strstr (filename, ":2,");
- if (! flags)
+ if (! dir)
continue;
- seen_maildir_info = 1;
- flags += 3;
-
- combined_flags = talloc_strdup_append (combined_flags, flags);
+ flags = strstr (filename, ":2,");
+ if (flags) {
+ seen_maildir_info = 1;
+ flags += 3;
+ combined_flags = talloc_strdup_append (combined_flags, flags);
+ } else if (STRNCMP_LITERAL (dir, "new/") == 0) {
+ /* Messages are delivered to new/ with no "info" part, but
+ * they effectively have default maildir flags. According
+ * to the spec, we should ignore the info part for
+ * messages in new/, but some MUAs (mutt) can set maildir
+ * flags on messages in new/, so we're liberal in what we
+ * accept. */
+ seen_maildir_info = 1;
+ }
}
/* If none of the filenames have any maildir info field (not even
@@ -1084,47 +1134,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
return status;
}
-/* Is the given filename within a maildir directory?
- *
- * Specifically, is the final directory component of 'filename' either
- * "cur" or "new". If so, return a pointer to that final directory
- * component within 'filename'. If not, return NULL.
- *
- * A non-NULL return value is guaranteed to be a valid string pointer
- * pointing to the characters "new/" or "cur/", (but not
- * NUL-terminated).
- */
-static const char *
-_filename_is_in_maildir (const char *filename)
-{
- const char *slash, *dir = NULL;
-
- /* Find the last '/' separating directory from filename. */
- slash = strrchr (filename, '/');
- if (slash == NULL)
- return NULL;
-
- /* Jump back 4 characters to where the previous '/' will be if the
- * directory is named "cur" or "new". */
- if (slash - filename < 4)
- return NULL;
-
- slash -= 4;
-
- if (*slash != '/')
- return NULL;
-
- dir = slash + 1;
-
- if (STRNCMP_LITERAL (dir, "cur/") == 0 ||
- STRNCMP_LITERAL (dir, "new/") == 0)
- {
- return dir;
- }
-
- return NULL;
-}
-
/* From the set of tags on 'message' and the flag2tag table, compute a
* set of maildir-flag actions to be taken, (flags that should be
* either set or cleared).
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 60a932f..bfb4111 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -146,8 +146,20 @@ typedef enum _notmuch_private_status {
: \
(notmuch_status_t) private_status)
+/* Flags shared by various lookup functions. */
+typedef enum _notmuch_find_flags {
+ /* Lookup without creating any documents. This is the default
+ * behavior. */
+ NOTMUCH_FIND_LOOKUP = 0,
+ /* If set, create the necessary document (or documents) if they
+ * are missing. Requires a read/write database. */
+ NOTMUCH_FIND_CREATE = 1<<0,
+} notmuch_find_flags_t;
+
typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;
+typedef struct _notmuch_string_list notmuch_string_list_t;
+
/* database.cc */
/* Lookup a prefix value by name.
@@ -186,6 +198,7 @@ _notmuch_database_find_unique_doc_id (notmuch_database_t *notmuch,
notmuch_status_t
_notmuch_database_find_directory_id (notmuch_database_t *database,
const char *path,
+ notmuch_find_flags_t flags,
unsigned int *directory_id);
const char *
@@ -197,6 +210,7 @@ notmuch_status_t
_notmuch_database_filename_to_direntry (void *ctx,
notmuch_database_t *notmuch,
const char *filename,
+ notmuch_find_flags_t flags,
char **direntry);
/* directory.cc */
@@ -204,6 +218,7 @@ _notmuch_database_filename_to_direntry (void *ctx,
notmuch_directory_t *
_notmuch_directory_create (notmuch_database_t *notmuch,
const char *path,
+ notmuch_find_flags_t flags,
notmuch_status_t *status_ret);
unsigned int
@@ -216,6 +231,7 @@ _notmuch_thread_create (void *ctx,
notmuch_database_t *notmuch,
unsigned int seed_doc_id,
notmuch_doc_id_set_t *match_set,
+ notmuch_string_list_t *excluded_terms,
notmuch_sort_t sort);
/* message.cc */
@@ -401,6 +417,7 @@ typedef struct _notmuch_message_list {
*/
struct visible _notmuch_messages {
notmuch_bool_t is_of_list_type;
+ notmuch_doc_id_set_t *excluded_doc_ids;
notmuch_message_node_t *iterator;
};
@@ -458,11 +475,11 @@ typedef struct _notmuch_string_node {
struct _notmuch_string_node *next;
} notmuch_string_node_t;
-typedef struct _notmuch_string_list {
+struct visible _notmuch_string_list {
int length;
notmuch_string_node_t *head;
notmuch_string_node_t **tail;
-} notmuch_string_list_t;
+};
notmuch_string_list_t *
_notmuch_string_list_create (const void *ctx);
@@ -491,8 +508,26 @@ notmuch_filenames_t *
_notmuch_filenames_create (const void *ctx,
notmuch_string_list_t *list);
-#pragma GCC visibility pop
-
NOTMUCH_END_DECLS
+#ifdef __cplusplus
+/* Implicit typecast from 'void *' to 'T *' is okay in C, but not in
+ * C++. In talloc_steal, an explicit cast is provided for type safety
+ * in some GCC versions. Otherwise, a cast is required. Provide a
+ * template function for this to maintain type safety, and redefine
+ * talloc_steal to use it.
+ */
+#if !(__GNUC__ >= 3)
+template <class T> T *
+_notmuch_talloc_steal (const void *new_ctx, const T *ptr)
+{
+ return static_cast<T *> (talloc_steal (new_ctx, ptr));
+}
+#undef talloc_steal
+#define talloc_steal _notmuch_talloc_steal
+#endif
+#endif
+
+#pragma GCC visibility pop
+
#endif
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 9f23a10..3633bed 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -133,27 +133,38 @@ typedef struct _notmuch_filenames notmuch_filenames_t;
*
* After a successful call to notmuch_database_create, the returned
* database will be open so the caller should call
- * notmuch_database_close when finished with it.
+ * notmuch_database_destroy when finished with it.
*
* The database will not yet have any data in it
* (notmuch_database_create itself is a very cheap function). Messages
* contained within 'path' can be added to the database by calling
* notmuch_database_add_message.
*
- * In case of any failure, this function returns NULL, (after printing
- * an error message on stderr).
+ * In case of any failure, this function returns an error status and
+ * sets *database to NULL (after printing an error message on stderr).
+ *
+ * Return value:
+ *
+ * NOTMUCH_STATUS_SUCCESS: Successfully created the database.
+ *
+ * NOTMUCH_STATUS_NULL_POINTER: The given 'path' argument is NULL.
+ *
+ * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
+ *
+ * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to create the
+ * database file (such as permission denied, or file not found,
+ * etc.), or the database already exists.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
*/
-notmuch_database_t *
-notmuch_database_create (const char *path);
+notmuch_status_t
+notmuch_database_create (const char *path, notmuch_database_t **database);
typedef enum {
NOTMUCH_DATABASE_MODE_READ_ONLY = 0,
NOTMUCH_DATABASE_MODE_READ_WRITE
} notmuch_database_mode_t;
-/* XXX: I think I'd like this to take an extra argument of
- * notmuch_status_t* for returning a status value on failure. */
-
/* Open an existing notmuch database located at 'path'.
*
* The database should have been created at some time in the past,
@@ -165,21 +176,50 @@ typedef enum {
* An existing notmuch database can be identified by the presence of a
* directory named ".notmuch" below 'path'.
*
- * The caller should call notmuch_database_close when finished with
+ * The caller should call notmuch_database_destroy when finished with
* this database.
*
- * In case of any failure, this function returns NULL, (after printing
- * an error message on stderr).
+ * In case of any failure, this function returns an error status and
+ * sets *database to NULL (after printing an error message on stderr).
+ *
+ * Return value:
+ *
+ * NOTMUCH_STATUS_SUCCESS: Successfully opened the database.
+ *
+ * NOTMUCH_STATUS_NULL_POINTER: The given 'path' argument is NULL.
+ *
+ * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
+ *
+ * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the
+ * database file (such as permission denied, or file not found,
+ * etc.), or the database version is unknown.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
*/
-notmuch_database_t *
+notmuch_status_t
notmuch_database_open (const char *path,
- notmuch_database_mode_t mode);
+ notmuch_database_mode_t mode,
+ notmuch_database_t **database);
-/* Close the given notmuch database, freeing all associated
- * resources. See notmuch_database_open. */
+/* Close the given notmuch database.
+ *
+ * After notmuch_database_close has been called, calls to other
+ * functions on objects derived from this database may either behave
+ * as if the database had not been closed (e.g., if the required data
+ * has been cached) or may fail with a
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION.
+ *
+ * notmuch_database_close can be called multiple times. Later calls
+ * have no effect.
+ */
void
notmuch_database_close (notmuch_database_t *database);
+/* Destroy the notmuch database, closing it if necessary and freeing
+* all associated resources. */
+void
+notmuch_database_destroy (notmuch_database_t *database);
+
/* Return the database path of the given database.
*
* The return value is a string owned by notmuch so should not be
@@ -260,11 +300,22 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch);
* (see notmuch_database_get_path), or else should be an absolute path
* with initial components that match the path of 'database'.
*
- * Can return NULL if a Xapian exception occurs.
+ * If this directory object does not exist in the database, this
+ * returns NOTMUCH_STATUS_SUCCESS and sets *directory to NULL.
+ *
+ * Return value:
+ *
+ * NOTMUCH_STATUS_SUCCESS: Successfully retrieved directory.
+ *
+ * NOTMUCH_STATUS_NULL_POINTER: The given 'directory' argument is NULL.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
+ * directory not retrieved.
*/
-notmuch_directory_t *
+notmuch_status_t
notmuch_database_get_directory (notmuch_database_t *database,
- const char *path);
+ const char *path,
+ notmuch_directory_t **directory);
/* Add a new message to the given notmuch database or associate an
* additional filename with an existing message.
@@ -449,6 +500,26 @@ typedef enum {
const char *
notmuch_query_get_query_string (notmuch_query_t *query);
+/* Specify whether to omit excluded results or simply flag them. By
+ * default, this is set to TRUE.
+ *
+ * If this is TRUE, notmuch_query_search_messages will omit excluded
+ * messages from the results. notmuch_query_search_threads will omit
+ * threads that match only in excluded messages, but will include all
+ * messages in threads that match in at least one non-excluded
+ * message.
+ *
+ * The performance difference when calling
+ * notmuch_query_search_messages should be relatively small (and both
+ * should be very fast). However, in some cases,
+ * notmuch_query_search_threads is very much faster when omitting
+ * excluded messages as it does not need to construct the threads that
+ * only match in excluded messages.
+ */
+
+void
+notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded);
+
/* Specify the sorting desired for this query. */
void
notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
@@ -457,6 +528,12 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
notmuch_sort_t
notmuch_query_get_sort (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
+ * the query. */
+void
+notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);
+
/* Execute a query for threads, returning a notmuch_threads_t object
* which can be used to iterate over the results. The returned threads
* object is owned by the query and as such, will only be valid until
@@ -659,8 +736,10 @@ notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread);
/* Get the number of messages in 'thread' that matched the search.
*
* This count includes only the messages in this thread that were
- * matched by the search from which the thread was created. Contrast
- * with notmuch_thread_get_total_messages() .
+ * matched by the search from which the thread was created and were
+ * not excluded by any exclude tags passed in with the query (see
+ * notmuch_query_add_tag_exclude). Contrast with
+ * notmuch_thread_get_total_messages() .
*/
int
notmuch_thread_get_matched_messages (notmuch_thread_t *thread);
@@ -889,7 +968,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);
/* Message flags */
typedef enum _notmuch_message_flag {
- NOTMUCH_MESSAGE_FLAG_MATCH
+ NOTMUCH_MESSAGE_FLAG_MATCH,
+ NOTMUCH_MESSAGE_FLAG_EXCLUDED
} notmuch_message_flag_t;
/* Get a value of a flag for the email corresponding to 'message'. */
diff --git a/lib/query.cc b/lib/query.cc
index b6c0f12..e9c1a2d 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -27,6 +27,8 @@ struct _notmuch_query {
notmuch_database_t *notmuch;
const char *query_string;
notmuch_sort_t sort;
+ notmuch_string_list_t *exclude_terms;
+ notmuch_bool_t omit_excluded;
};
typedef struct _notmuch_mset_messages {
@@ -56,15 +58,27 @@ struct visible _notmuch_threads {
notmuch_doc_id_set_t match_set;
};
+/* We need this in the message functions so forward declare. */
+static notmuch_bool_t
+_notmuch_doc_id_set_init (void *ctx,
+ notmuch_doc_id_set_t *doc_ids,
+ GArray *arr);
+
+static notmuch_bool_t
+_debug_query (void)
+{
+ char *env = getenv ("NOTMUCH_DEBUG_QUERY");
+ return (env && strcmp (env, "") != 0);
+}
+
notmuch_query_t *
notmuch_query_create (notmuch_database_t *notmuch,
const char *query_string)
{
notmuch_query_t *query;
-#ifdef DEBUG_QUERY
- fprintf (stderr, "Query string is:\n%s\n", query_string);
-#endif
+ if (_debug_query ())
+ fprintf (stderr, "Query string is:\n%s\n", query_string);
query = talloc (NULL, notmuch_query_t);
if (unlikely (query == NULL))
@@ -76,6 +90,10 @@ notmuch_query_create (notmuch_database_t *notmuch,
query->sort = NOTMUCH_SORT_NEWEST_FIRST;
+ query->exclude_terms = _notmuch_string_list_create (query);
+
+ query->omit_excluded = TRUE;
+
return query;
}
@@ -86,6 +104,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)
}
void
+notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded)
+{
+ query->omit_excluded = omit_excluded;
+}
+
+void
notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)
{
query->sort = sort;
@@ -97,6 +121,13 @@ notmuch_query_get_sort (notmuch_query_t *query)
return query->sort;
}
+void
+notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag)
+{
+ char *term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag);
+ _notmuch_string_list_append (query->exclude_terms, term);
+}
+
/* We end up having to call the destructors explicitly because we had
* to use "placement new" in order to initialize C++ objects within a
* block that we allocated with talloc. So C++ is making talloc
@@ -112,6 +143,33 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)
return 0;
}
+/* 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
+ * query appropriately.*/
+static Xapian::Query
+_notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)
+{
+ 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, "");
+ }
+ return exclude_query;
+}
+
notmuch_messages_t *
notmuch_query_search_messages (notmuch_query_t *query)
{
@@ -137,8 +195,9 @@ notmuch_query_search_messages (notmuch_query_t *query)
Xapian::Query mail_query (talloc_asprintf (query, "%s%s",
_find_prefix ("type"),
"mail"));
- Xapian::Query string_query, final_query;
+ Xapian::Query string_query, final_query, exclude_query;
Xapian::MSet mset;
+ Xapian::MSetIterator iterator;
unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
Xapian::QueryParser::FLAG_PHRASE |
Xapian::QueryParser::FLAG_LOVEHATE |
@@ -156,6 +215,36 @@ notmuch_query_search_messages (notmuch_query_t *query)
final_query = Xapian::Query (Xapian::Query::OP_AND,
mail_query, string_query);
}
+ messages->base.excluded_doc_ids = NULL;
+
+ if (query->exclude_terms) {
+ exclude_query = _notmuch_exclude_tags (query, final_query);
+
+ if (query->omit_excluded)
+ final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,
+ final_query, exclude_query);
+ else {
+ exclude_query = Xapian::Query (Xapian::Query::OP_AND,
+ exclude_query, final_query);
+
+ enquire.set_weighting_scheme (Xapian::BoolWeight());
+ enquire.set_query (exclude_query);
+
+ mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());
+
+ GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));
+
+ for (iterator = mset.begin (); iterator != mset.end (); iterator++) {
+ unsigned int doc_id = *iterator;
+ g_array_append_val (excluded_doc_ids, doc_id);
+ }
+ messages->base.excluded_doc_ids = talloc (messages, _notmuch_doc_id_set);
+ _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,
+ excluded_doc_ids);
+ g_array_unref (excluded_doc_ids);
+ }
+ }
+
enquire.set_weighting_scheme (Xapian::BoolWeight());
@@ -173,9 +262,12 @@ notmuch_query_search_messages (notmuch_query_t *query)
break;
}
-#if DEBUG_QUERY
- fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str());
-#endif
+ if (_debug_query ()) {
+ fprintf (stderr, "Exclude query is:\n%s\n",
+ exclude_query.get_description ().c_str ());
+ fprintf (stderr, "Final query is:\n%s\n",
+ final_query.get_description ().c_str ());
+ }
enquire.set_query (final_query);
@@ -244,6 +336,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)
INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");
}
+ if (messages->excluded_doc_ids &&
+ _notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id))
+ notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);
+
return message;
}
@@ -389,6 +485,7 @@ notmuch_threads_get (notmuch_threads_t *threads)
threads->query->notmuch,
doc_id,
&threads->match_set,
+ threads->query->exclude_terms,
threads->query->sort);
}
@@ -416,7 +513,7 @@ notmuch_query_count_messages (notmuch_query_t *query)
Xapian::Query mail_query (talloc_asprintf (query, "%s%s",
_find_prefix ("type"),
"mail"));
- Xapian::Query string_query, final_query;
+ Xapian::Query string_query, final_query, exclude_query;
Xapian::MSet mset;
unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
Xapian::QueryParser::FLAG_PHRASE |
@@ -436,12 +533,20 @@ notmuch_query_count_messages (notmuch_query_t *query)
mail_query, string_query);
}
+ exclude_query = _notmuch_exclude_tags (query, final_query);
+
+ final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,
+ final_query, exclude_query);
+
enquire.set_weighting_scheme(Xapian::BoolWeight());
enquire.set_docid_order(Xapian::Enquire::ASCENDING);
-#if DEBUG_QUERY
- fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str());
-#endif
+ if (_debug_query ()) {
+ fprintf (stderr, "Exclude query is:\n%s\n",
+ exclude_query.get_description ().c_str ());
+ fprintf (stderr, "Final query is:\n%s\n",
+ final_query.get_description ().c_str ());
+ }
enquire.set_query (final_query);
diff --git a/lib/thread.cc b/lib/thread.cc
index 0435ee6..e976d64 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -214,7 +214,8 @@ _thread_cleanup_author (notmuch_thread_t *thread,
*/
static void
_thread_add_message (notmuch_thread_t *thread,
- notmuch_message_t *message)
+ notmuch_message_t *message,
+ notmuch_string_list_t *exclude_terms)
{
notmuch_tags_t *tags;
const char *tag;
@@ -262,6 +263,15 @@ _thread_add_message (notmuch_thread_t *thread,
notmuch_tags_move_to_next (tags))
{
tag = notmuch_tags_get (tags);
+ /* Mark excluded messages. */
+ for (notmuch_string_node_t *term = exclude_terms->head; term;
+ term = term->next) {
+ /* We ignore initial 'K'. */
+ if (strcmp(tag, (term->string + 1)) == 0) {
+ notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);
+ break;
+ }
+ }
g_hash_table_insert (thread->tags, xstrdup (tag), NULL);
}
}
@@ -321,7 +331,8 @@ _thread_add_matched_message (notmuch_thread_t *thread,
_thread_set_subject_from_message (thread, message);
}
- thread->matched_messages++;
+ if (!notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED))
+ thread->matched_messages++;
if (g_hash_table_lookup_extended (thread->message_hash,
notmuch_message_get_message_id (message), NULL,
@@ -392,6 +403,7 @@ _notmuch_thread_create (void *ctx,
notmuch_database_t *notmuch,
unsigned int seed_doc_id,
notmuch_doc_id_set_t *match_set,
+ notmuch_string_list_t *exclude_terms,
notmuch_sort_t sort)
{
notmuch_thread_t *thread;
@@ -467,7 +479,7 @@ _notmuch_thread_create (void *ctx,
if (doc_id == seed_doc_id)
message = seed_message;
- _thread_add_message (thread, message);
+ _thread_add_message (thread, message, exclude_terms);
if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {
_notmuch_doc_id_set_remove (match_set, doc_id);
diff --git a/man/.gitignore b/man/.gitignore
new file mode 100644
index 0000000..26ead20
--- /dev/null
+++ b/man/.gitignore
@@ -0,0 +1,2 @@
+# ignore gzipped man pages
+*.[0-9].gz
diff --git a/man/man1/notmuch-config.1 b/man/man1/notmuch-config.1
index cb3234f..2ee555d 100644
--- a/man/man1/notmuch-config.1
+++ b/man/man1/notmuch-config.1
@@ -1,13 +1,15 @@
-.TH NOTMUCH-CONFIG 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-CONFIG 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-config \- Output a single part of a multipart MIME message.
+notmuch-config \- access notmuch configuration file
.SH SYNOPSIS
.B notmuch config get
-.RI "<" section "> . <" item ">"
+.RI "<" section ">.<" item ">"
.B notmuch config set
-.RI "<" section "> . <" item "> [" value "]"
+.RI "<" section ">.<" item "> [" value " ...]"
+
+.B notmuch config list
.SH DESCRIPTION
@@ -16,39 +18,141 @@ The
command can be used to get or set settings in the notmuch
configuration file.
-.SS GET
-
+.RS 4
+.TP 4
+.B get
The value of the specified configuration item is printed to stdout. If
-the item has multiple values, each value is separated by a newline
-character.
+the item has multiple values (it is a list), each value is separated
+by a newline character.
+.RE
-Available configuration items include at least
+.RS 4
+.TP 4
+.B set
+The specified configuration item is set to the given value. To specify
+a multiple-value item (a list), provide each value as a separate
+command-line argument.
- database.path
+If no values are provided, the specified configuration item will be
+removed from the configuration file.
+.RE
- user.name
+.RS 4
+.TP 4
+.B list
+Every configuration item is printed to stdout, each on a separate line
+of the form:
- user.primary_email
+.RI "" section "." item "=" value
- user.other_email
+No additional whitespace surrounds the dot or equals sign characters. In a
+multiple-value item (a list), the values are separated by semicolon characters.
+.RE
- new.tags
+The available configuration items are described below.
-.SS SET
+.RS 4
+.TP 4
+.B database.path
+The top-level directory where your mail currently exists and to where
+mail will be delivered in the future. Files should be individual email
+messages. Notmuch will store its database within a sub-directory of
+the path configured here named
+.BR ".notmuch".
+.RE
-The specified configuration item is set to the given value. To
-specify a multiple-value item, provide each value as a separate
-command-line argument.
+.RS 4
+.TP 4
+.B user.name
+Your full name.
+.RE
-If no values are provided, the specified configuration item will be
-removed from the configuration file.
+.RS 4
+.TP 4
+.B user.primary_email
+Your primary email address.
.RE
+.RS 4
+.TP 4
+.B user.other_email
+A list of other email addresses at which you receive email.
+.RE
+
+.RS 4
+.TP 4
+.B new.tags
+A list of tags that will be added to all messages incorporated by
+.BR "notmuch new".
+.RE
+
+.RS 4
+.TP 4
+.B new.ignore
+A list of file and directory names, without path, that will not be
+searched for messages by
+.BR "notmuch new".
+All the files and directories matching any of the names specified here
+will be ignored, regardless of the location in the mail store
+directory hierarchy.
+.RE
+
+.RS 4
+.TP 4
+.B search.exclude_tags
+A list of tags that will be excluded from search results by
+default. Using an excluded tag in a query will override that
+exclusion.
+.RE
+
+.RS 4
+.TP 4
+.B maildir.synchronize_flags
+If true, then the following maildir flags (in message filenames) will
+be synchronized with the corresponding notmuch tags:
+
+ Flag Tag
+ ---- -------
+ D draft
+ F flagged
+ P passed
+ R replied
+ S unread (added when 'S' flag is not present)
+
+The
+.B notmuch new
+command will notice flag changes in filenames and update tags, while
+the
+.B notmuch tag
+and
+.B notmuch restore
+commands will notice tag changes and update flags in filenames.
+
+If there have been any changes in the maildir (new messages added, old
+ones removed or renamed, maildir flags changed, etc.), it is advisable
+to run
+.B notmuch new
+before
+.B notmuch tag
+or
+.B notmuch restore
+commands to ensure the tag changes are properly synchronized to the
+maildir flags, as the commands expect the database and maildir to be
+in sync.
+.RE
+
+.RE
+.SH ENVIRONMENT
+The following environment variables can be used to control the
+behavior of notmuch.
+.TP
+.B NOTMUCH_CONFIG
+Specifies the location of the notmuch configuration file. Notmuch will
+use ${HOME}/.notmuch\-config if this variable is not set.
.SH SEE ALSO
-\fBnotmuch\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
-\fBnotmuch-part\fR(1), \fBnotmuch-reply\fR(1),
+\fBnotmuch\fR(1), \fBnotmuch-count\fR(1), \fBnotmuch-dump\fR(1),
+\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-reply\fR(1),
\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-count.1 b/man/man1/notmuch-count.1
index 25fe329..8551ab2 100644
--- a/man/man1/notmuch-count.1
+++ b/man/man1/notmuch-count.1
@@ -1,6 +1,6 @@
-.TH NOTMUCH-COUNT 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-COUNT 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-count \- Count messages matching the given search terms.
+notmuch-count \- count messages matching the given search terms
.SH SYNOPSIS
.B notmuch count
@@ -38,13 +38,21 @@ Output the number of matching messages. This is the default.
Output the number of matching threads.
.RE
.RE
+
+.RS 4
+.TP 4
+.BR \-\-exclude=(true|false)
+
+Specify whether to omit messages matching search.tag_exclude from the
+count (the default) or not.
+.RE
.RE
.RE
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-dump\fR(1),
-\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-reply\fR(1),
+\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-dump.1 b/man/man1/notmuch-dump.1
index 9ccf35d..5d1e197 100644
--- a/man/man1/notmuch-dump.1
+++ b/man/man1/notmuch-dump.1
@@ -1,19 +1,18 @@
-.TH NOTMUCH-DUMP 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-DUMP 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-dump \- Creates a plain-text dump of the tags of each message.
+notmuch-dump \- creates a plain-text dump of the tags of each message
.SH SYNOPSIS
.B "notmuch dump"
-.RI "[ <" filename "> ] [--]"
+.RI "[ --output=<" filename "> ] [--]"
.RI "[ <" search-term ">...]"
.SH DESCRIPTION
Dump tags for messages matching the given search terms.
-Output is to the given filename, if any, or to stdout. Note that
-using the filename argument is deprecated.
+Output is to the given filename, if any, or to stdout.
These tags are the only data in the notmuch database that can't be
recreated from the messages themselves. The output of notmuch dump is
@@ -31,7 +30,7 @@ for details of the supported syntax for <search-terms>.
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-reply\fR(1),
+\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-new.1 b/man/man1/notmuch-new.1
index 77d4776..e01f2eb 100644
--- a/man/man1/notmuch-new.1
+++ b/man/man1/notmuch-new.1
@@ -1,6 +1,6 @@
-.TH NOTMUCH-NEW 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-NEW 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-new \- Incorporate new mail into the notmuch database.
+notmuch-new \- incorporate new mail into the notmuch database
.SH SYNOPSIS
.B notmuch new
@@ -40,6 +40,11 @@ has previously been completed, but
.B "notmuch new"
has not previously been run.
+.B "notmuch new"
+updates tags according to maildir flag changes if the
+.B "maildir.synchronize_flags"
+configuration option is enabled. See \fBnotmuch-config\fR(1) for
+details.
The
.B new
@@ -59,7 +64,7 @@ Prevents hooks from being run.
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(5), \fBnotmuch-hooks\fR(5), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-reply\fR(1),
+\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-reply.1 b/man/man1/notmuch-reply.1
index db464d8..5aa86c0 100644
--- a/man/man1/notmuch-reply.1
+++ b/man/man1/notmuch-reply.1
@@ -1,6 +1,6 @@
-.TH NOTMUCH-REPLY 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-REPLY 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-reply \- Constructs a reply template for a set of messages.
+notmuch-reply \- constructs a reply template for a set of messages
.SH SYNOPSIS
@@ -14,11 +14,13 @@ Constructs a reply template for a set of messages.
To make replying to email easier,
.B notmuch reply
takes an existing set of messages and constructs a suitable mail
-template. The Reply-to header (if any, otherwise From:) is used for
-the To: address. Vales from the To: and Cc: headers are copied, but
-not including any of the current user's email addresses (as configured
-in primary_mail or other_email in the .notmuch\-config file) in the
-recipient list
+template. The Reply-to: header (if any, otherwise From:) is used for
+the To: address. Unless
+.BR \-\-reply-to=sender
+is specified, values from the To: and Cc: headers are copied, but not
+including any of the current user's email addresses (as configured in
+primary_mail or other_email in the .notmuch\-config file) in the
+recipient list.
It also builds a suitable new subject, including Re: at the front (if
not already present), and adding the message IDs of the messages being
@@ -35,16 +37,47 @@ Supported options for
include
.RS
.TP 4
-.BR \-\-format= ( default | headers\-only )
+.BR \-\-format= ( default | json | headers\-only )
.RS
.TP 4
.BR default
Includes subject and quoted message body.
.TP
+.BR json
+Produces JSON output containing headers for a reply message and the
+contents of the original message. This output can be used by a client
+to create a reply message intelligently.
+.TP
.BR headers\-only
Only produces In\-Reply\-To, References, To, Cc, and Bcc headers.
.RE
.RE
+.RS
+.TP 4
+.BR \-\-reply\-to= ( all | sender )
+.RS
+.TP 4
+.BR all " (default)"
+Replies to all addresses.
+.TP 4
+.BR sender
+Replies only to the sender. If replying to user's own message
+(Reply-to: or From: header is one of the user's configured email
+addresses), try To:, Cc:, and Bcc: headers in this order, and copy
+values from the first that contains something other than only the
+user's addresses.
+.RE
+.RE
+.RS
+.TP 4
+.B \-\-decrypt
+
+Decrypt any MIME encrypted parts found in the selected content
+(ie. "multipart/encrypted" parts). Status of the decryption will be
+reported (currently only supported with --format=json) and the
+multipart/encrypted part will be replaced by the decrypted
+content.
+.RE
See \fBnotmuch-search-terms\fR(7)
for details of the supported syntax for <search-terms>.
@@ -55,14 +88,15 @@ with a search string matching a single message, (such as
id:<message-id>), but it can be useful to reply to several messages at
once. For example, when a series of patches are sent in a single
thread, replying to the entire thread allows for the reply to comment
-on issue found in multiple patches.
+on issues found in multiple patches. The default format supports
+replying to multiple messages at once, but the JSON format does not.
.RE
.RE
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(5), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
-\fBnotmuch-part\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
+\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-restore.1 b/man/man1/notmuch-restore.1
index 2191df0..d0d50dd 100644
--- a/man/man1/notmuch-restore.1
+++ b/man/man1/notmuch-restore.1
@@ -1,12 +1,12 @@
-.TH NOTMUCH-RESTORE 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-RESTORE 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-restore \- Restores the tags from the given file (see notmuch dump).
+notmuch-restore \- restores the tags from the given file (see notmuch dump)
.SH SYNOPSIS
.B "notmuch restore"
.RB [ "--accumulate" ]
-.RI "[ <" filename "> ]"
+.RI "[ --input=<" filename "> ]"
.SH DESCRIPTION
@@ -29,11 +29,17 @@ dump file.
See \fBnotmuch-search-terms\fR(7)
for details of the supported syntax for <search-terms>.
+.B "notmuch restore"
+updates the maildir flags according to tag changes if the
+.B "maildir.synchronize_flags"
+configuration option is enabled. See \fBnotmuch-config\fR(1) for
+details.
+
.RE
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-dump\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
+\fBnotmuch-reply\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1
index 0bc3f40..b42eb2c 100644
--- a/man/man1/notmuch-search.1
+++ b/man/man1/notmuch-search.1
@@ -1,6 +1,6 @@
-.TH NOTMUCH-SEARCH 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-SEARCH 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-search \- Search for messages matching the given search terms.
+notmuch-search \- search for messages matching the given search terms
.SH SYNOPSIS
.B notmuch search
@@ -112,10 +112,23 @@ result from the end.
Limit the number of displayed results to N.
.RE
+.RS 4
+.TP 4
+.BR \-\-exclude=(true|false|flag)
+
+Specify whether to omit messages matching search.tag_exclude from the
+search results (the default) or not. The extra option
+.B flag
+only has an effect when
+.B --output=summary
+In this case all matching threads are returned but the "match count"
+is the number of matching non-excluded messages in the thread.
+.RE
+
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(5), \fBnotmuch-hooks\fR(5), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-reply\fR(1),
-\fBnotmuch-restore\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
+\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-show.1 b/man/man1/notmuch-show.1
index b2301d8..765b22c 100644
--- a/man/man1/notmuch-show.1
+++ b/man/man1/notmuch-show.1
@@ -1,6 +1,6 @@
-.TH NOTMUCH-SHOW 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-SHOW 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-show \- Show messages matching the given search terms.
+notmuch-show \- show messages matching the given search terms
.SH SYNOPSIS
.B notmuch show
@@ -24,11 +24,14 @@ Supported options for
include
.RS 4
.TP 4
-.B \-\-entire\-thread
+.B \-\-entire\-thread=(true|false)
-By default only those messages that match the search terms will be
-displayed. With this option, all messages in the same thread as any
-matched message will be displayed.
+If true,
+.B notmuch show
+outputs all messages in the thread of any message matching the search
+terms; if false, it outputs only the matching messages. For
+.B --format=json
+this defaults to true. For other formats, this defaults to false.
.RE
.RS 4
@@ -55,11 +58,13 @@ be nested.
The output is formatted with Javascript Object Notation (JSON). This
format is more robust than the text format for automated
processing. The nested structure of multipart MIME messages is
-reflected in nested JSON output. JSON output always includes all
-messages in a matching thread; in effect
+reflected in nested JSON output. By default JSON output includes all
+messages in a matching thread; that is, by default,
.B \-\-format=json
-implies
-.B \-\-entire\-thread
+sets
+.B "\-\-entire\-thread"
+The caller can disable this behaviour by setting
+.B \-\-entire\-thread=false
.RE
.RS 4
@@ -84,12 +89,17 @@ http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/mail-mbox-formats.html
.TP 4
.BR raw " (default for a single part, see \-\-part)"
-For a message, the original, raw content of the email message is
-output. Consumers of this format should expect to implement MIME
-decoding and similar functions.
+For a message or an attached message part, the original, raw content
+of the email message is output. Consumers of this format should expect
+to implement MIME decoding and similar functions.
For a single part (\-\-part) the raw part content is output after
-performing any necessary MIME decoding.
+performing any necessary MIME decoding. Note that messages with a
+simple body still have two parts: part 0 is the whole message and part
+1 is the body.
+
+For a multipart part, the part headers and body (including all child
+parts) is output.
The raw format must only be used with search terms matching single
message.
@@ -125,7 +135,42 @@ Decrypt any MIME encrypted parts found in the selected content
(ie. "multipart/encrypted" parts). Status of the decryption will be
reported (currently only supported with --format=json) and the
multipart/encrypted part will be replaced by the decrypted
-content.
+content. Implies --verify.
+.RE
+
+.RS 4
+.TP 4
+.BR \-\-exclude=(true|false)
+
+Specify whether to omit threads only matching search.tag_exclude from
+the search results (the default) or not. In either case the excluded
+message will be marked with the exclude flag (except when output=mbox
+when there is nowhere to put the flag).
+
+If --entire-thread is specified then complete threads are returned
+regardless (with the excluded flag being set when appropriate) but
+threads that only match in an excluded message are not returned when
+.B --exclude=true.
+
+The default is
+.B --exclude=true.
+
+.RE
+
+.RS 4
+.TP 4
+.B \-\-body=(true|false)
+
+If true (the default)
+.B notmuch show
+includes the bodies of the messages in the output; if false,
+bodies are omitted.
+.B --body=false
+is only implemented for the json format and it is incompatible with
+.B --part > 0.
+
+This is useful if the caller only needs the headers as body-less
+output is much faster and substantially smaller.
.RE
A common use of
@@ -139,7 +184,7 @@ command.
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(5), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
-\fBnotmuch-part\fR(1), \fBnotmuch-reply\fR(1),
-\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
-\fBnotmuch-search-terms\fR(7), \fBnotmuch-tag\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
+\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
+\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-tag.1 b/man/man1/notmuch-tag.1
index 993911b..d810e1b 100644
--- a/man/man1/notmuch-tag.1
+++ b/man/man1/notmuch-tag.1
@@ -1,6 +1,6 @@
-.TH NOTMUCH-TAG 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-TAG 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-tag \- Add/remove tags for all messages matching the search terms.
+notmuch-tag \- add/remove tags for all messages matching the search terms
.SH SYNOPSIS
.B notmuch tag
@@ -23,10 +23,16 @@ an initial search term beginning with '+' or '\-' is provided
by allowing the user to specify a "\-\-" argument to separate
the tags from the search terms.
+.B "notmuch tag"
+updates the maildir flags according to tag changes if the
+.B "maildir.synchronize_flags"
+configuration option is enabled. See \fBnotmuch-config\fR(1) for
+details.
+
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(5), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
-\fBnotmuch-part\fR(1), \fBnotmuch-reply\fR(1),
-\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
-\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
+\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
+\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
+\fBnotmuch-show\fR(1),
diff --git a/man/man1/notmuch.1 b/man/man1/notmuch.1
index 424ca36..ebea4aa 100644
--- a/man/man1/notmuch.1
+++ b/man/man1/notmuch.1
@@ -16,7 +16,7 @@
.\" along with this program. If not, see http://www.gnu.org/licenses/ .
.\"
.\" Author: Carl Worth <cworth@cworth.org>
-.TH NOTMUCH 1 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH 1 2012-06-01 "Notmuch 0.13.2"
.SH NAME
notmuch \- thread-based email index, search, and tagging
.SH SYNOPSIS
@@ -131,10 +131,9 @@ use ${HOME}/.notmuch\-config if this variable is not set.
\fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
-\fBnotmuch-part\fR(1), \fBnotmuch-reply\fR(1),
-\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
-\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
-\fBnotmuch-tag\fR(1)
+\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
+\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
+\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
The notmuch website:
diff --git a/man/man5/notmuch-hooks.5 b/man/man5/notmuch-hooks.5
index 2c4e552..b914a29 100644
--- a/man/man5/notmuch-hooks.5
+++ b/man/man5/notmuch-hooks.5
@@ -1,4 +1,4 @@
-.TH NOTMUCH-HOOKS 5 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-HOOKS 5 2012-06-01 "Notmuch 0.13.2"
.SH NAME
notmuch-hooks \- hooks for notmuch
@@ -42,7 +42,7 @@ imported messages.
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-new\fR(1), \fBnotmuch-reply\fR(1),
+\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man7/notmuch-search-terms.7 b/man/man7/notmuch-search-terms.7
index a53565b..b8ab52d 100644
--- a/man/man7/notmuch-search-terms.7
+++ b/man/man7/notmuch-search-terms.7
@@ -1,7 +1,7 @@
-.TH NOTMUCH-SEARCH-TERMS 7 2011-12-04 "Notmuch 0.10.2"
+.TH NOTMUCH-SEARCH-TERMS 7 2012-06-01 "Notmuch 0.13.2"
.SH NAME
-notmuch-search-terms \- Syntax for notmuch queries
+notmuch-search-terms \- syntax for notmuch queries
.SH SYNOPSIS
@@ -135,7 +135,6 @@ current time:
.SH SEE ALSO
\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(5), \fBnotmuch-hooks\fR(5), \fBnotmuch-part\fR(1),
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search\fR(1),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-search\fR(1), \fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
diff --git a/mime-node.c b/mime-node.c
index d26bb44..97e8b48 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -33,8 +33,7 @@ typedef struct mime_node_context {
GMimeMessage *mime_message;
/* Context provided by the caller. */
- GMimeCipherContext *cryptoctx;
- notmuch_bool_t decrypt;
+ notmuch_crypto_t *crypto;
} mime_node_context_t;
static int
@@ -57,8 +56,7 @@ _mime_node_context_free (mime_node_context_t *res)
notmuch_status_t
mime_node_open (const void *ctx, notmuch_message_t *message,
- GMimeCipherContext *cryptoctx, notmuch_bool_t decrypt,
- mime_node_t **root_out)
+ notmuch_crypto_t *crypto, mime_node_t **root_out)
{
const char *filename = notmuch_message_get_filename (message);
mime_node_context_t *mctx;
@@ -89,14 +87,28 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
}
mctx->stream = g_mime_stream_file_new (mctx->file);
+ if (!mctx->stream) {
+ fprintf (stderr, "Out of memory.\n");
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;
+ goto DONE;
+ }
g_mime_stream_file_set_owner (GMIME_STREAM_FILE (mctx->stream), FALSE);
mctx->parser = g_mime_parser_new_with_stream (mctx->stream);
+ if (!mctx->parser) {
+ fprintf (stderr, "Out of memory.\n");
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;
+ goto DONE;
+ }
mctx->mime_message = g_mime_parser_construct_message (mctx->parser);
+ if (!mctx->mime_message) {
+ fprintf (stderr, "Failed to parse %s\n", filename);
+ status = NOTMUCH_STATUS_FILE_ERROR;
+ goto DONE;
+ }
- mctx->cryptoctx = cryptoctx;
- mctx->decrypt = decrypt;
+ mctx->crypto = crypto;
/* Create the root node */
root->part = GMIME_OBJECT (mctx->mime_message);
@@ -104,6 +116,11 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
root->nchildren = 1;
root->ctx = mctx;
+ root->parent = NULL;
+ root->part_num = 0;
+ root->next_child = 0;
+ root->next_part_num = 1;
+
*root_out = root;
return NOTMUCH_STATUS_SUCCESS;
@@ -112,18 +129,28 @@ DONE:
return status;
}
+#ifdef GMIME_ATLEAST_26
+static int
+_signature_list_free (GMimeSignatureList **proxy)
+{
+ g_object_unref (*proxy);
+ return 0;
+}
+#else
static int
_signature_validity_free (GMimeSignatureValidity **proxy)
{
g_mime_signature_validity_free (*proxy);
return 0;
}
+#endif
static mime_node_t *
-_mime_node_create (const mime_node_t *parent, GMimeObject *part)
+_mime_node_create (mime_node_t *parent, GMimeObject *part)
{
mime_node_t *node = talloc_zero (parent, mime_node_t);
GError *err = NULL;
+ notmuch_crypto_context_t *cryptoctx = NULL;
/* Set basic node properties */
node->part = part;
@@ -133,6 +160,9 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
talloc_free (node);
return NULL;
}
+ node->parent = parent;
+ node->part_num = node->next_part_num = -1;
+ node->next_child = 0;
/* Deal with the different types of parts */
if (GMIME_IS_PART (part)) {
@@ -153,9 +183,15 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
return NULL;
}
+ if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt)
+ || (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {
+ GMimeContentType *content_type = g_mime_object_get_content_type (part);
+ const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");
+ cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);
+ }
+
/* Handle PGP/MIME parts */
- if (GMIME_IS_MULTIPART_ENCRYPTED (part)
- && node->ctx->cryptoctx && node->ctx->decrypt) {
+ if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt && cryptoctx) {
if (node->nchildren != 2) {
/* this violates RFC 3156 section 4, so we won't bother with it. */
fprintf (stderr, "Error: %d part(s) for a multipart/encrypted "
@@ -165,23 +201,46 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
GMimeMultipartEncrypted *encrypteddata =
GMIME_MULTIPART_ENCRYPTED (part);
node->decrypt_attempted = TRUE;
+#ifdef GMIME_ATLEAST_26
+ GMimeDecryptResult *decrypt_result = NULL;
node->decrypted_child = g_mime_multipart_encrypted_decrypt
- (encrypteddata, node->ctx->cryptoctx, &err);
+ (encrypteddata, cryptoctx, &decrypt_result, &err);
+#else
+ node->decrypted_child = g_mime_multipart_encrypted_decrypt
+ (encrypteddata, cryptoctx, &err);
+#endif
if (node->decrypted_child) {
node->decrypt_success = node->verify_attempted = TRUE;
+#ifdef GMIME_ATLEAST_26
+ /* This may be NULL if the part is not signed. */
+ node->sig_list = g_mime_decrypt_result_get_signatures (decrypt_result);
+ if (node->sig_list)
+ g_object_ref (node->sig_list);
+ g_object_unref (decrypt_result);
+#else
node->sig_validity = g_mime_multipart_encrypted_get_signature_validity (encrypteddata);
+#endif
} else {
fprintf (stderr, "Failed to decrypt part: %s\n",
(err ? err->message : "no error explanation given"));
}
}
- } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->cryptoctx) {
+ } else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify && cryptoctx) {
if (node->nchildren != 2) {
/* this violates RFC 3156 section 5, so we won't bother with it. */
fprintf (stderr, "Error: %d part(s) for a multipart/signed message "
"(must be exactly 2)\n",
node->nchildren);
} else {
+#ifdef GMIME_ATLEAST_26
+ node->sig_list = g_mime_multipart_signed_verify
+ (GMIME_MULTIPART_SIGNED (part), cryptoctx, &err);
+ node->verify_attempted = TRUE;
+
+ if (!node->sig_list)
+ fprintf (stderr, "Failed to verify signed part: %s\n",
+ (err ? err->message : "no error explanation given"));
+#else
/* For some reason the GMimeSignatureValidity returned
* here is not a const (inconsistent with that
* returned by
@@ -191,7 +250,7 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
* In GMime 2.6, they're both non-const, so we'll be able
* to clean up this asymmetry. */
GMimeSignatureValidity *sig_validity = g_mime_multipart_signed_verify
- (GMIME_MULTIPART_SIGNED (part), node->ctx->cryptoctx, &err);
+ (GMIME_MULTIPART_SIGNED (part), cryptoctx, &err);
node->verify_attempted = TRUE;
node->sig_validity = sig_validity;
if (sig_validity) {
@@ -200,12 +259,25 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
*proxy = sig_validity;
talloc_set_destructor (proxy, _signature_validity_free);
}
+#endif
}
}
+#ifdef GMIME_ATLEAST_26
+ /* sig_list may be created in both above cases, so we need to
+ * cleanly handle it here. */
+ if (node->sig_list) {
+ GMimeSignatureList **proxy = talloc (node, GMimeSignatureList *);
+ *proxy = node->sig_list;
+ talloc_set_destructor (proxy, _signature_list_free);
+ }
+#endif
+
+#ifndef GMIME_ATLEAST_26
if (node->verify_attempted && !node->sig_validity)
fprintf (stderr, "Failed to verify signed part: %s\n",
(err ? err->message : "no error explanation given"));
+#endif
if (err)
g_error_free (err);
@@ -214,9 +286,10 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
}
mime_node_t *
-mime_node_child (const mime_node_t *parent, int child)
+mime_node_child (mime_node_t *parent, int child)
{
GMimeObject *sub;
+ mime_node_t *node;
if (!parent || child < 0 || child >= parent->nchildren)
return NULL;
@@ -234,7 +307,30 @@ mime_node_child (const mime_node_t *parent, int child)
INTERNAL_ERROR ("Unexpected GMimeObject type: %s",
g_type_name (G_OBJECT_TYPE (parent->part)));
}
- return _mime_node_create (parent, sub);
+ node = _mime_node_create (parent, sub);
+
+ if (child == parent->next_child && parent->next_part_num != -1) {
+ /* We're traversing in depth-first order. Record the child's
+ * depth-first numbering. */
+ node->part_num = parent->next_part_num;
+ node->next_part_num = node->part_num + 1;
+
+ /* Prepare the parent for its next depth-first child. */
+ parent->next_child++;
+ parent->next_part_num = -1;
+
+ if (node->nchildren == 0) {
+ /* We've reached a leaf, so find the parent that has more
+ * children and set it up to number its next child. */
+ mime_node_t *iter = node->parent;
+ while (iter && iter->next_child == iter->nchildren)
+ iter = iter->parent;
+ if (iter)
+ iter->next_part_num = node->part_num + 1;
+ }
+ }
+
+ return node;
}
static mime_node_t *
diff --git a/notmuch-client.h b/notmuch-client.h
index 517c010..ae9344b 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -30,6 +30,17 @@
#include <gmime/gmime.h>
+/* GMIME_CHECK_VERSION in gmime 2.4 is not usable from the
+ * preprocessor (it calls a runtime function). But since
+ * GMIME_MAJOR_VERSION and friends were added in gmime 2.6, we can use
+ * these to check the version number. */
+#ifdef GMIME_MAJOR_VERSION
+#define GMIME_ATLEAST_26
+typedef GMimeCryptoContext notmuch_crypto_context_t;
+#else
+typedef GMimeCipherContext notmuch_crypto_context_t;
+#endif
+
#include "notmuch.h"
/* This is separate from notmuch-private.h because we're trying to
@@ -54,37 +65,30 @@
#define STRINGIFY(s) STRINGIFY_(s)
#define STRINGIFY_(s) #s
+typedef struct mime_node mime_node_t;
+struct sprinter;
+struct notmuch_show_params;
+
typedef struct notmuch_show_format {
- const char *message_set_start;
- const char *message_start;
- void (*message) (const void *ctx,
- notmuch_message_t *message,
- int indent);
- const char *header_start;
- void (*header) (const void *ctx,
- notmuch_message_t *message);
- void (*header_message_part) (GMimeMessage *message);
- const char *header_end;
- const char *body_start;
- void (*part_start) (GMimeObject *part,
- int *part_count);
- void (*part_encstatus) (int status);
- void (*part_sigstatus) (const GMimeSignatureValidity* validity);
- void (*part_content) (GMimeObject *part);
- void (*part_end) (GMimeObject *part);
- const char *part_sep;
- const char *body_end;
- const char *message_end;
- const char *message_set_sep;
- const char *message_set_end;
+ struct sprinter *(*new_sprinter) (const void *ctx, FILE *stream);
+ notmuch_status_t (*part) (const void *ctx, struct sprinter *sprinter,
+ struct mime_node *node, int indent,
+ const struct notmuch_show_params *params);
} notmuch_show_format_t;
+typedef struct notmuch_crypto {
+ notmuch_crypto_context_t* gpgctx;
+ notmuch_bool_t verify;
+ notmuch_bool_t decrypt;
+} notmuch_crypto_t;
+
typedef struct notmuch_show_params {
- int entire_thread;
- int raw;
+ notmuch_bool_t entire_thread;
+ notmuch_bool_t omit_excluded;
+ notmuch_bool_t output_body;
+ notmuch_bool_t raw;
int part;
- GMimeCipherContext* cryptoctx;
- int decrypt;
+ notmuch_crypto_t crypto;
} notmuch_show_params_t;
/* There's no point in continuing when we've detected that we've done
@@ -113,6 +117,12 @@ chomp_newline (char *str)
str[strlen(str)-1] = '\0';
}
+notmuch_crypto_context_t *
+notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);
+
+int
+notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
+
int
notmuch_count_command (void *ctx, int argc, char *argv[]);
@@ -162,13 +172,24 @@ char *
query_string_from_args (void *ctx, int argc, char *argv[]);
notmuch_status_t
-show_message_body (notmuch_message_t *message,
- const notmuch_show_format_t *format,
- notmuch_show_params_t *params);
-
-notmuch_status_t
show_one_part (const char *filename, int part);
+void
+format_part_json (const void *ctx, struct sprinter *sp, mime_node_t *node,
+ notmuch_bool_t first, notmuch_bool_t output_body);
+
+void
+format_headers_json (struct sprinter *sp, GMimeMessage *message,
+ notmuch_bool_t reply);
+
+typedef enum {
+ NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,
+} notmuch_show_text_part_flags;
+
+void
+show_text_part_content (GMimeObject *part, GMimeStream *stream_out,
+ notmuch_show_text_part_flags flags);
+
char *
json_quote_chararray (const void *ctx, const char *str, const size_t len);
@@ -228,6 +249,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
const char *new_tags[],
size_t length);
+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config,
+ size_t *length);
+
+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+ const char *new_ignore[],
+ size_t length);
+
notmuch_bool_t
notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);
@@ -235,6 +265,14 @@ void
notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,
notmuch_bool_t synchronize_flags);
+const char **
+notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length);
+
+void
+notmuch_config_set_search_exclude_tags (notmuch_config_t *config,
+ const char *list[],
+ size_t length);
+
int
notmuch_run_hook (const char *db_path, const char *hook);
@@ -249,7 +287,7 @@ debugger_is_active (void);
* parts. Message-type parts have one child, multipart-type parts
* have multiple children, and leaf parts have zero children.
*/
-typedef struct mime_node {
+struct mime_node {
/* The MIME object of this part. This will be a GMimeMessage,
* GMimePart, GMimeMultipart, or a subclass of one of these.
*
@@ -273,6 +311,13 @@ typedef struct mime_node {
/* The number of children of this part. */
int nchildren;
+ /* The parent of this node or NULL if this is the root node. */
+ struct mime_node *parent;
+
+ /* The depth-first part number of this child if the MIME tree is
+ * being traversed in depth-first order, or -1 otherwise. */
+ int part_num;
+
/* True if decryption of this part was attempted. */
notmuch_bool_t decrypt_attempted;
/* True if decryption of this part's child succeeded. In this
@@ -282,11 +327,17 @@ typedef struct mime_node {
/* True if signature verification on this part was attempted. */
notmuch_bool_t verify_attempted;
+#ifdef GMIME_ATLEAST_26
+ /* The list of signatures for signed or encrypted containers. If
+ * there are no signatures, this will be NULL. */
+ GMimeSignatureList* sig_list;
+#else
/* For signed or encrypted containers, the validity of the
* signature. May be NULL if signature verification failed. If
* there are simply no signatures, this will be non-NULL with an
* empty signers list. */
const GMimeSignatureValidity *sig_validity;
+#endif
/* Internal: Context inherited from the root iterator. */
struct mime_node_context *ctx;
@@ -294,12 +345,18 @@ typedef struct mime_node {
/* Internal: For successfully decrypted multipart parts, the
* decrypted part to substitute for the second child. */
GMimeObject *decrypted_child;
-} mime_node_t;
+
+ /* Internal: The next child for depth-first traversal and the part
+ * number to assign it (or -1 if unknown). */
+ int next_child;
+ int next_part_num;
+};
/* Construct a new MIME node pointing to the root message part of
- * message. If cryptoctx is non-NULL, it will be used to verify
- * signatures on any child parts. If decrypt is true, then cryptoctx
- * will additionally be used to decrypt any encrypted child parts.
+ * message. If crypto->verify is true, signed child parts will be
+ * verified. If crypto->decrypt is true, encrypted child parts will be
+ * decrypted. If crypto->gpgctx is NULL, it will be lazily
+ * initialized.
*
* Return value:
*
@@ -311,8 +368,7 @@ typedef struct mime_node {
*/
notmuch_status_t
mime_node_open (const void *ctx, notmuch_message_t *message,
- GMimeCipherContext *cryptoctx, notmuch_bool_t decrypt,
- mime_node_t **node_out);
+ notmuch_crypto_t *crypto, mime_node_t **node_out);
/* Return a new MIME node for the requested child part of parent.
* parent will be used as the talloc context for the returned child
@@ -322,7 +378,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
* an error message on stderr).
*/
mime_node_t *
-mime_node_child (const mime_node_t *parent, int child);
+mime_node_child (mime_node_t *parent, int child);
/* Return the nth child of node in a depth-first traversal. If n is
* 0, returns node itself. Returns NULL if there is no such part. */
diff --git a/notmuch-config.c b/notmuch-config.c
index d697138..3e37a2d 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -44,7 +44,13 @@ static const char new_config_comment[] =
" The following options are supported here:\n"
"\n"
"\ttags A list (separated by ';') of the tags that will be\n"
- "\t added to all messages incorporated by \"notmuch new\".\n";
+ "\t added to all messages incorporated by \"notmuch new\".\n"
+ "\n"
+ "\tignore A list (separated by ';') of file and directory names\n"
+ "\t that will not be searched for messages by \"notmuch new\".\n"
+ "\n"
+ "\t NOTE: *Every* file/directory that goes by one of those names will\n"
+ "\t be ignored, independent of its depth/location in the mail store.\n";
static const char user_config_comment[] =
" User configuration\n"
@@ -84,6 +90,16 @@ static const char maildir_config_comment[] =
"\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n"
"\tcommands will notice tag changes and update flags in filenames\n";
+static const char search_config_comment[] =
+ " Search configuration\n"
+ "\n"
+ " The following option is supported here:\n"
+ "\n"
+ "\texclude_tags\n"
+ "\t\tA ;-separated list of tags that will be excluded from\n"
+ "\t\tsearch results by default. Using an excluded tag in a\n"
+ "\t\tquery will override that exclusion.\n";
+
struct _notmuch_config {
char *filename;
GKeyFile *key_file;
@@ -95,7 +111,11 @@ struct _notmuch_config {
size_t user_other_email_length;
const char **new_tags;
size_t new_tags_length;
+ const char **new_ignore;
+ size_t new_ignore_length;
notmuch_bool_t maildir_synchronize_flags;
+ const char **search_exclude_tags;
+ size_t search_exclude_tags_length;
};
static int
@@ -221,6 +241,7 @@ notmuch_config_open (void *ctx,
int file_had_new_group;
int file_had_user_group;
int file_had_maildir_group;
+ int file_had_search_group;
if (is_new_ret)
*is_new_ret = 0;
@@ -251,7 +272,11 @@ notmuch_config_open (void *ctx,
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;
if (! g_key_file_load_from_file (config->key_file,
config->filename,
@@ -295,6 +320,7 @@ notmuch_config_open (void *ctx,
file_had_new_group = g_key_file_has_group (config->key_file, "new");
file_had_user_group = g_key_file_has_group (config->key_file, "user");
file_had_maildir_group = g_key_file_has_group (config->key_file, "maildir");
+ file_had_search_group = g_key_file_has_group (config->key_file, "search");
if (notmuch_config_get_database_path (config) == NULL) {
@@ -345,6 +371,19 @@ notmuch_config_open (void *ctx,
notmuch_config_set_new_tags (config, tags, 2);
}
+ if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {
+ notmuch_config_set_new_ignore (config, NULL, 0);
+ }
+
+ if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
+ if (is_new) {
+ const char *tags[] = { "deleted", "spam" };
+ notmuch_config_set_search_exclude_tags (config, tags, 2);
+ } else {
+ notmuch_config_set_search_exclude_tags (config, NULL, 0);
+ }
+ }
+
error = NULL;
config->maildir_synchronize_flags =
g_key_file_get_boolean (config->key_file,
@@ -387,6 +426,11 @@ notmuch_config_open (void *ctx,
maildir_config_comment, NULL);
}
+ if (! file_had_search_group) {
+ g_key_file_set_comment (config->key_file, "search", NULL,
+ search_config_comment, NULL);
+ }
+
if (is_new_ret)
*is_new_ret = is_new;
@@ -437,6 +481,48 @@ notmuch_config_save (notmuch_config_t *config)
return 0;
}
+static const char **
+_config_get_list (notmuch_config_t *config,
+ const char *section, const char *key,
+ const char ***outlist, size_t *list_length, size_t *ret_length)
+{
+ assert(outlist);
+
+ if (*outlist == NULL) {
+
+ char **inlist = g_key_file_get_string_list (config->key_file,
+ section, key, list_length, NULL);
+ if (inlist) {
+ unsigned int i;
+
+ *outlist = talloc_size (config, sizeof (char *) * (*list_length + 1));
+
+ for (i = 0; i < *list_length; i++)
+ (*outlist)[i] = talloc_strdup (*outlist, inlist[i]);
+
+ (*outlist)[i] = NULL;
+
+ g_strfreev (inlist);
+ }
+ }
+
+ if (ret_length)
+ *ret_length = *list_length;
+
+ return *outlist;
+}
+
+static void
+_config_set_list (notmuch_config_t *config,
+ const char *group, const char *name,
+ const char *list[],
+ size_t length, const char ***config_var )
+{
+ g_key_file_set_string_list (config->key_file, group, name, list, length);
+ talloc_free (*config_var);
+ *config_var = NULL;
+}
+
const char *
notmuch_config_get_database_path (notmuch_config_t *config)
{
@@ -521,37 +607,6 @@ notmuch_config_set_user_primary_email (notmuch_config_t *config,
config->user_primary_email = NULL;
}
-static const char **
-_config_get_list (notmuch_config_t *config,
- const char *section, const char *key,
- const char ***outlist, size_t *list_length, size_t *ret_length)
-{
- assert(outlist);
-
- if (*outlist == NULL) {
-
- char **inlist = g_key_file_get_string_list (config->key_file,
- section, key, list_length, NULL);
- if (inlist) {
- unsigned int i;
-
- *outlist = talloc_size (config, sizeof (char *) * (*list_length + 1));
-
- for (i = 0; i < *list_length; i++)
- (*outlist)[i] = talloc_strdup (*outlist, inlist[i]);
-
- (*outlist)[i] = NULL;
-
- g_strfreev (inlist);
- }
- }
-
- if (ret_length)
- *ret_length = *list_length;
-
- return *outlist;
-}
-
const char **
notmuch_config_get_user_other_email (notmuch_config_t *config, size_t *length)
{
@@ -568,15 +623,12 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
&(config->new_tags_length), length);
}
-static void
-_config_set_list (notmuch_config_t *config,
- const char *group, const char *name,
- const char *list[],
- size_t length, const char ***config_var )
+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
{
- g_key_file_set_string_list (config->key_file, group, name, list, length);
- talloc_free (*config_var);
- *config_var = NULL;
+ return _config_get_list (config, "new", "ignore",
+ &(config->new_ignore),
+ &(config->new_ignore_length), length);
}
void
@@ -597,6 +649,32 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
&(config->new_tags));
}
+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+ const char *list[],
+ size_t length)
+{
+ _config_set_list (config, "new", "ignore", list, length,
+ &(config->new_ignore));
+}
+
+const char **
+notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
+{
+ return _config_get_list (config, "search", "exclude_tags",
+ &(config->search_exclude_tags),
+ &(config->search_exclude_tags_length), length);
+}
+
+void
+notmuch_config_set_search_exclude_tags (notmuch_config_t *config,
+ const char *list[],
+ size_t length)
+{
+ _config_set_list (config, "search", "exclude_tags", list, length,
+ &(config->search_exclude_tags));
+}
+
/* Given a configuration item of the form <group>.<key> return the
* component group and key. If any error occurs, print a message on
* stderr and return 1. Otherwise, return 0.
@@ -673,7 +751,7 @@ notmuch_config_command_get (void *ctx, char *item)
for (i = 0; i < length; i++)
printf ("%s\n", value[i]);
- free (value);
+ g_strfreev (value);
}
notmuch_config_close (config);
@@ -721,20 +799,78 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])
return ret;
}
+static int
+notmuch_config_command_list (void *ctx)
+{
+ notmuch_config_t *config;
+ char **groups;
+ size_t g, groups_length;
+
+ config = notmuch_config_open (ctx, NULL, NULL);
+ if (config == NULL)
+ return 1;
+
+ groups = g_key_file_get_groups (config->key_file, &groups_length);
+ if (groups == NULL)
+ return 1;
+
+ for (g = 0; g < groups_length; g++) {
+ char **keys;
+ size_t k, keys_length;
+
+ keys = g_key_file_get_keys (config->key_file,
+ groups[g], &keys_length, NULL);
+ if (keys == NULL)
+ continue;
+
+ for (k = 0; k < keys_length; k++) {
+ char *value;
+
+ value = g_key_file_get_string (config->key_file,
+ groups[g], keys[k], NULL);
+ if (value != NULL) {
+ printf ("%s.%s=%s\n", groups[g], keys[k], value);
+ free (value);
+ }
+ }
+
+ g_strfreev (keys);
+ }
+
+ g_strfreev (groups);
+
+ notmuch_config_close (config);
+
+ return 0;
+}
+
int
notmuch_config_command (void *ctx, int argc, char *argv[])
{
argc--; argv++; /* skip subcommand argument */
- if (argc < 2) {
- fprintf (stderr, "Error: notmuch config requires at least two arguments.\n");
+ if (argc < 1) {
+ fprintf (stderr, "Error: notmuch config requires at least one argument.\n");
return 1;
}
- if (strcmp (argv[0], "get") == 0)
+ if (strcmp (argv[0], "get") == 0) {
+ if (argc != 2) {
+ fprintf (stderr, "Error: notmuch config get requires exactly "
+ "one argument.\n");
+ return 1;
+ }
return notmuch_config_command_get (ctx, argv[1]);
- else if (strcmp (argv[0], "set") == 0)
+ } else if (strcmp (argv[0], "set") == 0) {
+ if (argc < 2) {
+ fprintf (stderr, "Error: notmuch config set requires at least "
+ "one argument.\n");
+ return 1;
+ }
return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2);
+ } else if (strcmp (argv[0], "list") == 0) {
+ return notmuch_config_command_list (ctx);
+ }
fprintf (stderr, "Unrecognized argument for notmuch config: %s\n",
argv[0]);
diff --git a/notmuch-count.c b/notmuch-count.c
index 0982f99..2f98128 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -26,6 +26,12 @@ enum {
OUTPUT_MESSAGES,
};
+/* The following is to allow future options to be added more easily */
+enum {
+ EXCLUDE_TRUE,
+ EXCLUDE_FALSE,
+};
+
int
notmuch_count_command (void *ctx, int argc, char *argv[])
{
@@ -35,12 +41,18 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
char *query_str;
int opt_index;
int output = OUTPUT_MESSAGES;
+ int exclude = EXCLUDE_TRUE;
+ unsigned int i;
notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
(notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },
{ "messages", OUTPUT_MESSAGES },
{ 0, 0 } } },
+ { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
+ (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
+ { "false", EXCLUDE_FALSE },
+ { 0, 0 } } },
{ 0, 0, 0, 0, 0 }
};
@@ -54,9 +66,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
- if (notmuch == NULL)
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
return 1;
query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
@@ -75,6 +86,16 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
return 1;
}
+ if (exclude == EXCLUDE_TRUE) {
+ const char **search_exclude_tags;
+ size_t search_exclude_tags_length;
+
+ 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]);
+ }
+
switch (output) {
case OUTPUT_MESSAGES:
printf ("%u\n", notmuch_query_count_messages (query));
@@ -85,7 +106,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
}
notmuch_query_destroy (query);
- notmuch_database_close (notmuch);
+ notmuch_database_destroy (notmuch);
return 0;
}
diff --git a/notmuch-dump.c b/notmuch-dump.c
index a735875..d8186fb 100644
--- a/notmuch-dump.c
+++ b/notmuch-dump.c
@@ -36,16 +36,15 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
- if (notmuch == NULL)
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
return 1;
char *output_file_name = NULL;
int opt_index;
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_POSITION, &output_file_name, 0, 0, 0 },
+ { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
{ 0, 0, 0, 0, 0 }
};
@@ -57,7 +56,6 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
}
if (output_file_name) {
- fprintf (stderr, "Warning: the output file argument of dump is deprecated.\n");
output = fopen (output_file_name, "w");
if (output == NULL) {
fprintf (stderr, "Error opening %s for writing: %s\n",
@@ -116,7 +114,7 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
fclose (output);
notmuch_query_destroy (query);
- notmuch_database_close (notmuch);
+ notmuch_database_destroy (notmuch);
return 0;
}
diff --git a/notmuch-new.c b/notmuch-new.c
index 3512de7..938ae29 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -39,6 +39,8 @@ typedef struct {
int verbose;
const char **new_tags;
size_t new_tags_length;
+ const char **new_ignore;
+ size_t new_ignore_length;
int total_files;
int processed_files;
@@ -67,7 +69,11 @@ handle_sigint (unused (int sig))
{
static char msg[] = "Stopping... \n";
- (void) write(2, msg, sizeof(msg)-1);
+ /* This write is "opportunistic", so it's okay to ignore the
+ * result. It is not required for correctness, and if it does
+ * fail or produce a short write, we want to get out of the signal
+ * handler as quickly as possible, not retry it. */
+ IGNORE_RESULT (write (2, msg, sizeof(msg)-1));
interrupted = 1;
}
@@ -148,6 +154,48 @@ dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b)
return strcmp ((*a)->d_name, (*b)->d_name);
}
+/* Return the type of a directory entry relative to path as a stat(2)
+ * mode. Like stat, this follows symlinks. Returns -1 and sets errno
+ * if the file's type cannot be determined (which includes dangling
+ * symlinks).
+ */
+static int
+dirent_type (const char *path, const struct dirent *entry)
+{
+ struct stat statbuf;
+ char *abspath;
+ int err, saved_errno;
+
+#ifdef _DIRENT_HAVE_D_TYPE
+ /* Mapping from d_type to stat mode_t. We omit DT_LNK so that
+ * we'll fall through to stat and get the real file type. */
+ static const mode_t modes[] = {
+ [DT_BLK] = S_IFBLK,
+ [DT_CHR] = S_IFCHR,
+ [DT_DIR] = S_IFDIR,
+ [DT_FIFO] = S_IFIFO,
+ [DT_REG] = S_IFREG,
+ [DT_SOCK] = S_IFSOCK
+ };
+ if (entry->d_type < ARRAY_SIZE(modes) && modes[entry->d_type])
+ return modes[entry->d_type];
+#endif
+
+ abspath = talloc_asprintf (NULL, "%s/%s", path, entry->d_name);
+ if (!abspath) {
+ errno = ENOMEM;
+ return -1;
+ }
+ err = stat(abspath, &statbuf);
+ saved_errno = errno;
+ talloc_free (abspath);
+ if (err < 0) {
+ errno = saved_errno;
+ return -1;
+ }
+ return statbuf.st_mode & S_IFMT;
+}
+
/* Test if the directory looks like a Maildir directory.
*
* Search through the array of directory entries to see if we can find all
@@ -156,12 +204,12 @@ dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b)
* Return 1 if the directory looks like a Maildir and 0 otherwise.
*/
static int
-_entries_resemble_maildir (struct dirent **entries, int count)
+_entries_resemble_maildir (const char *path, struct dirent **entries, int count)
{
int i, found = 0;
for (i = 0; i < count; i++) {
- if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)
+ if (dirent_type (path, entries[i]) != S_IFDIR)
continue;
if (strcmp(entries[i]->d_name, "new") == 0 ||
@@ -177,6 +225,20 @@ _entries_resemble_maildir (struct dirent **entries, int count)
return 0;
}
+/* Test if the file/directory is to be ignored.
+ */
+static notmuch_bool_t
+_entry_in_ignore_list (const char *entry, add_files_state_t *state)
+{
+ size_t i;
+
+ for (i = 0; i < state->new_ignore_length; i++)
+ if (strcmp (entry, state->new_ignore[i]) == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
/* Examine 'path' recursively as follows:
*
* o Ask the filesystem for the mtime of 'path' (fs_mtime)
@@ -219,9 +281,9 @@ _entries_resemble_maildir (struct dirent **entries, int count)
* if fs_mtime isn't the current wall-clock time.
*/
static notmuch_status_t
-add_files_recursive (notmuch_database_t *notmuch,
- const char *path,
- add_files_state_t *state)
+add_files (notmuch_database_t *notmuch,
+ const char *path,
+ add_files_state_t *state)
{
DIR *dir = NULL;
struct dirent *entry = NULL;
@@ -230,13 +292,13 @@ add_files_recursive (notmuch_database_t *notmuch,
notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
notmuch_message_t *message = NULL;
struct dirent **fs_entries = NULL;
- int i, num_fs_entries;
+ int i, num_fs_entries = 0, entry_type;
notmuch_directory_t *directory;
notmuch_filenames_t *db_files = NULL;
notmuch_filenames_t *db_subdirs = NULL;
time_t stat_time;
struct stat st;
- notmuch_bool_t is_maildir, new_directory;
+ notmuch_bool_t is_maildir;
const char **tag;
if (stat (path, &st)) {
@@ -246,54 +308,40 @@ add_files_recursive (notmuch_database_t *notmuch,
}
stat_time = time (NULL);
- /* This is not an error since we may have recursed based on a
- * symlink to a regular file, not a directory, and we don't know
- * that until this stat. */
- if (! S_ISDIR (st.st_mode))
- return NOTMUCH_STATUS_SUCCESS;
+ if (! S_ISDIR (st.st_mode)) {
+ fprintf (stderr, "Error: %s is not a directory.\n", path);
+ return NOTMUCH_STATUS_FILE_ERROR;
+ }
fs_mtime = st.st_mtime;
- directory = notmuch_database_get_directory (notmuch, path);
- db_mtime = notmuch_directory_get_mtime (directory);
-
- new_directory = db_mtime ? FALSE : TRUE;
-
- /* XXX This is a temporary workaround. If we don't update the
- * database mtime until after processing messages in this
- * directory, then a 0 mtime is *not* sufficient to indicate that
- * this directory has no messages or subdirs in the database (for
- * example, if an earlier run skipped the mtime update because
- * fs_mtime == stat_time, or was interrupted before updating the
- * mtime at the end). To address this, we record a (bogus)
- * non-zero value before processing any child messages so that a
- * later run won't mistake this for a new directory (and, for
- * example, fail to detect removed files and subdirs).
- *
- * A better solution would be for notmuch_database_get_directory
- * to indicate if it really created a new directory or not, either
- * by a new out-argument, or by recording this information and
- * providing an accessor.
- */
- if (new_directory)
- notmuch_directory_set_mtime (directory, -1);
+ status = notmuch_database_get_directory (notmuch, path, &directory);
+ if (status) {
+ ret = status;
+ goto DONE;
+ }
+ db_mtime = directory ? notmuch_directory_get_mtime (directory) : 0;
/* If the database knows about this directory, then we sort based
* on strcmp to match the database sorting. Otherwise, we can do
* inode-based sorting for faster filesystem operation. */
num_fs_entries = scandir (path, &fs_entries, 0,
- new_directory ?
- dirent_sort_inode : dirent_sort_strcmp_name);
+ directory ?
+ dirent_sort_strcmp_name : dirent_sort_inode);
if (num_fs_entries == -1) {
fprintf (stderr, "Error opening directory %s: %s\n",
path, strerror (errno));
+ /* We consider this a fatal error because, if a user moved a
+ * message from another directory that we were able to scan
+ * into this directory, skipping this directory will cause
+ * that message to be lost. */
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
/* Pass 1: Recurse into all sub-directories. */
- is_maildir = _entries_resemble_maildir (fs_entries, num_fs_entries);
+ is_maildir = _entries_resemble_maildir (path, fs_entries, num_fs_entries);
for (i = 0; i < num_fs_entries; i++) {
if (interrupted)
@@ -301,38 +349,39 @@ add_files_recursive (notmuch_database_t *notmuch,
entry = fs_entries[i];
- /* We only want to descend into directories.
- * But symlinks can be to directories too, of course.
- *
- * And if the filesystem doesn't tell us the file type in the
- * scandir results, then it might be a directory (and if not,
- * then we'll stat and return immediately in the next level of
- * recursion). */
- if (entry->d_type != DT_DIR &&
- entry->d_type != DT_LNK &&
- entry->d_type != DT_UNKNOWN)
- {
+ /* We only want to descend into directories (and symlinks to
+ * directories). */
+ entry_type = dirent_type (path, entry);
+ if (entry_type == -1) {
+ /* Be pessimistic, e.g. so we don't lose lots of mail just
+ * because a user broke a symlink. */
+ fprintf (stderr, "Error reading file %s/%s: %s\n",
+ path, entry->d_name, strerror (errno));
+ return NOTMUCH_STATUS_FILE_ERROR;
+ } else if (entry_type != S_IFDIR) {
continue;
}
/* Ignore special directories to avoid infinite recursion.
- * Also ignore the .notmuch directory and any "tmp" directory
- * that appears within a maildir.
+ * Also ignore the .notmuch directory, any "tmp" directory
+ * that appears within a maildir and files/directories
+ * the user has configured to be ignored.
*/
- /* XXX: Eventually we'll want more sophistication to let the
- * user specify files to be ignored. */
if (strcmp (entry->d_name, ".") == 0 ||
strcmp (entry->d_name, "..") == 0 ||
(is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
- strcmp (entry->d_name, ".notmuch") ==0)
+ strcmp (entry->d_name, ".notmuch") == 0 ||
+ _entry_in_ignore_list (entry->d_name, state))
{
continue;
}
next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
- status = add_files_recursive (notmuch, next, state);
- if (status && ret == NOTMUCH_STATUS_SUCCESS)
+ status = add_files (notmuch, next, state);
+ if (status) {
ret = status;
+ goto DONE;
+ }
talloc_free (next);
next = NULL;
}
@@ -346,13 +395,12 @@ add_files_recursive (notmuch_database_t *notmuch,
* being discovered until the clock catches up and the directory
* is modified again).
*/
- if (fs_mtime == db_mtime)
+ if (directory && fs_mtime == db_mtime)
goto DONE;
- /* new_directory means a directory that the database has never
- * seen before. In that case, we can simply leave db_files and
- * db_subdirs NULL. */
- if (!new_directory) {
+ /* If the database has never seen this directory before, we can
+ * simply leave db_files and db_subdirs NULL. */
+ if (directory) {
db_files = notmuch_directory_get_child_files (directory);
db_subdirs = notmuch_directory_get_child_directories (directory);
}
@@ -365,6 +413,10 @@ add_files_recursive (notmuch_database_t *notmuch,
entry = fs_entries[i];
+ /* Ignore files & directories user has configured to be ignored */
+ if (_entry_in_ignore_list (entry->d_name, state))
+ continue;
+
/* Check if we've walked past any names in db_files or
* db_subdirs. If so, these have been deleted. */
while (notmuch_filenames_valid (db_files) &&
@@ -395,31 +447,13 @@ add_files_recursive (notmuch_database_t *notmuch,
notmuch_filenames_move_to_next (db_subdirs);
}
- /* If we're looking at a symlink, we only want to add it if it
- * links to a regular file, (and not to a directory, say).
- *
- * Similarly, if the file is of unknown type (due to filesystem
- * limitations), then we also need to look closer.
- *
- * In either case, a stat does the trick.
- */
- if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {
- int err;
-
- next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
- err = stat (next, &st);
- talloc_free (next);
- next = NULL;
-
- /* Don't emit an error for a link pointing nowhere, since
- * the directory-traversal pass will have already done
- * that. */
- if (err)
- continue;
-
- if (! S_ISREG (st.st_mode))
- continue;
- } else if (entry->d_type != DT_REG) {
+ /* Only add regular files (and symlinks to regular files). */
+ entry_type = dirent_type (path, entry);
+ if (entry_type == -1) {
+ fprintf (stderr, "Error reading file %s/%s: %s\n",
+ path, entry->d_name, strerror (errno));
+ return NOTMUCH_STATUS_FILE_ERROR;
+ } else if (entry_type != S_IFREG) {
continue;
}
@@ -555,12 +589,14 @@ add_files_recursive (notmuch_database_t *notmuch,
DONE:
if (next)
talloc_free (next);
- if (entry)
- free (entry);
if (dir)
closedir (dir);
- if (fs_entries)
+ if (fs_entries) {
+ for (i = 0; i < num_fs_entries; i++)
+ free (fs_entries[i]);
+
free (fs_entries);
+ }
if (db_subdirs)
notmuch_filenames_destroy (db_subdirs);
if (db_files)
@@ -611,32 +647,6 @@ stop_progress_printing_timer (void)
}
-/* This is the top-level entry point for add_files. It does a couple
- * of error checks and then calls into the recursive function. */
-static notmuch_status_t
-add_files (notmuch_database_t *notmuch,
- const char *path,
- add_files_state_t *state)
-{
- notmuch_status_t status;
- struct stat st;
-
- if (stat (path, &st)) {
- fprintf (stderr, "Error reading directory %s: %s\n",
- path, strerror (errno));
- return NOTMUCH_STATUS_FILE_ERROR;
- }
-
- if (! S_ISDIR (st.st_mode)) {
- fprintf (stderr, "Error: %s is not a directory.\n", path);
- return NOTMUCH_STATUS_FILE_ERROR;
- }
-
- status = add_files_recursive (notmuch, path, state);
-
- return status;
-}
-
/* XXX: This should be merged with the add_files function since it
* shares a lot of logic with it. */
/* Recursively count all regular files in path and all sub-directories
@@ -644,7 +654,7 @@ add_files (notmuch_database_t *notmuch,
* initialized to zero by the top-level caller before calling
* count_files). */
static void
-count_files (const char *path, int *count)
+count_files (const char *path, int *count, add_files_state_t *state)
{
struct dirent *entry = NULL;
char *next;
@@ -666,13 +676,13 @@ count_files (const char *path, int *count)
entry = fs_entries[i++];
/* Ignore special directories to avoid infinite recursion.
- * Also ignore the .notmuch directory.
+ * Also ignore the .notmuch directory and files/directories
+ * the user has configured to be ignored.
*/
- /* XXX: Eventually we'll want more sophistication to let the
- * user specify files to be ignored. */
if (strcmp (entry->d_name, ".") == 0 ||
strcmp (entry->d_name, "..") == 0 ||
- strcmp (entry->d_name, ".notmuch") == 0)
+ strcmp (entry->d_name, ".notmuch") == 0 ||
+ _entry_in_ignore_list (entry->d_name, state))
{
continue;
}
@@ -693,17 +703,19 @@ count_files (const char *path, int *count)
fflush (stdout);
}
} else if (S_ISDIR (st.st_mode)) {
- count_files (next, count);
+ count_files (next, count, state);
}
free (next);
}
DONE:
- if (entry)
- free (entry);
- if (fs_entries)
+ if (fs_entries) {
+ for (i = 0; i < num_fs_entries; i++)
+ free (fs_entries[i]);
+
free (fs_entries);
+ }
}
static void
@@ -745,32 +757,40 @@ remove_filename (notmuch_database_t *notmuch,
return status;
status = notmuch_database_find_message_by_filename (notmuch, path, &message);
if (status || message == NULL)
- return status;
+ goto DONE;
+
status = notmuch_database_remove_message (notmuch, path);
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
add_files_state->renamed_messages++;
if (add_files_state->synchronize_flags == TRUE)
notmuch_message_maildir_flags_to_tags (message);
- } else
+ status = NOTMUCH_STATUS_SUCCESS;
+ } else if (status == NOTMUCH_STATUS_SUCCESS) {
add_files_state->removed_messages++;
+ }
notmuch_message_destroy (message);
+
+ DONE:
notmuch_database_end_atomic (notmuch);
return status;
}
/* Recursively remove all filenames from the database referring to
* 'path' (or to any of its children). */
-static void
+static notmuch_status_t
_remove_directory (void *ctx,
notmuch_database_t *notmuch,
const char *path,
add_files_state_t *add_files_state)
{
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
notmuch_directory_t *directory;
notmuch_filenames_t *files, *subdirs;
char *absolute;
- directory = notmuch_database_get_directory (notmuch, path);
+ status = notmuch_database_get_directory (notmuch, path, &directory);
+ if (status || !directory)
+ return status;
for (files = notmuch_directory_get_child_files (directory);
notmuch_filenames_valid (files);
@@ -778,8 +798,10 @@ _remove_directory (void *ctx,
{
absolute = talloc_asprintf (ctx, "%s/%s", path,
notmuch_filenames_get (files));
- remove_filename (notmuch, absolute, add_files_state);
+ status = remove_filename (notmuch, absolute, add_files_state);
talloc_free (absolute);
+ if (status)
+ goto DONE;
}
for (subdirs = notmuch_directory_get_child_directories (directory);
@@ -788,11 +810,15 @@ _remove_directory (void *ctx,
{
absolute = talloc_asprintf (ctx, "%s/%s", path,
notmuch_filenames_get (subdirs));
- _remove_directory (ctx, notmuch, absolute, add_files_state);
+ status = _remove_directory (ctx, notmuch, absolute, add_files_state);
talloc_free (absolute);
+ if (status)
+ goto DONE;
}
+ DONE:
notmuch_directory_destroy (directory);
+ return status;
}
int
@@ -833,6 +859,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
return 1;
add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
+ add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
db_path = notmuch_config_get_database_path (config);
@@ -848,17 +875,17 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
int count;
count = 0;
- count_files (db_path, &count);
+ count_files (db_path, &count, &add_files_state);
if (interrupted)
return 1;
printf ("Found %d total files (that's not much mail).\n", count);
- notmuch = notmuch_database_create (db_path);
+ if (notmuch_database_create (db_path, &notmuch))
+ return 1;
add_files_state.total_files = count;
} else {
- notmuch = notmuch_database_open (db_path,
- NOTMUCH_DATABASE_MODE_READ_WRITE);
- if (notmuch == NULL)
+ if (notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,
+ &notmuch))
return 1;
if (notmuch_database_needs_upgrade (notmuch)) {
@@ -904,10 +931,14 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
}
ret = add_files (notmuch, db_path, &add_files_state);
+ if (ret)
+ goto DONE;
gettimeofday (&tv_start, NULL);
for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) {
- remove_filename (notmuch, f->filename, &add_files_state);
+ ret = remove_filename (notmuch, f->filename, &add_files_state);
+ if (ret)
+ goto DONE;
if (do_print_progress) {
do_print_progress = 0;
generic_print_progress ("Cleaned up", "messages",
@@ -918,7 +949,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
gettimeofday (&tv_start, NULL);
for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {
- _remove_directory (ctx, notmuch, f->filename, &add_files_state);
+ ret = _remove_directory (ctx, notmuch, f->filename, &add_files_state);
+ if (ret)
+ goto DONE;
if (do_print_progress) {
do_print_progress = 0;
generic_print_progress ("Cleaned up", "directories",
@@ -928,14 +961,16 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
}
for (f = add_files_state.directory_mtimes->head; f && !interrupted; f = f->next) {
+ notmuch_status_t status;
notmuch_directory_t *directory;
- directory = notmuch_database_get_directory (notmuch, f->filename);
- if (directory) {
+ status = notmuch_database_get_directory (notmuch, f->filename, &directory);
+ if (status == NOTMUCH_STATUS_SUCCESS && directory) {
notmuch_directory_set_mtime (directory, f->mtime);
notmuch_directory_destroy (directory);
}
}
+ DONE:
talloc_free (add_files_state.removed_files);
talloc_free (add_files_state.removed_directories);
talloc_free (add_files_state.directory_mtimes);
@@ -983,12 +1018,11 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
printf ("\n");
- if (ret) {
- printf ("\nNote: At least one error was encountered: %s\n",
- notmuch_status_to_string (ret));
- }
+ if (ret)
+ fprintf (stderr, "Note: A fatal error was encountered: %s\n",
+ notmuch_status_to_string (ret));
- notmuch_database_close (notmuch);
+ notmuch_database_destroy (notmuch);
if (run_hooks && !ret && !interrupted)
ret = notmuch_run_hook (db_path, "post-new");
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 000f6da..fa6665f 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -21,30 +21,8 @@
*/
#include "notmuch-client.h"
-#include "gmime-filter-reply.h"
#include "gmime-filter-headers.h"
-
-static void
-reply_headers_message_part (GMimeMessage *message);
-
-static void
-reply_part_content (GMimeObject *part);
-
-static const notmuch_show_format_t format_reply = {
- "",
- "", NULL,
- "", NULL, reply_headers_message_part, ">\n",
- "",
- NULL,
- NULL,
- NULL,
- reply_part_content,
- NULL,
- "",
- "",
- "", "",
- ""
-};
+#include "sprinter.h"
static void
show_reply_headers (GMimeMessage *message)
@@ -66,124 +44,157 @@ show_reply_headers (GMimeMessage *message)
}
static void
-reply_headers_message_part (GMimeMessage *message)
-{
- InternetAddressList *recipients;
- const char *recipients_string;
-
- printf ("> 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);
- 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));
-}
-
-
-static void
-reply_part_content (GMimeObject *part)
+format_part_reply (mime_node_t *node)
{
- GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
- GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part);
-
- if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
- g_mime_content_type_is_type (content_type, "message", "rfc822"))
- {
- /* Output nothing, since multipart subparts will be handled individually. */
- }
- else if (g_mime_content_type_is_type (content_type, "application", "pgp-encrypted") ||
- g_mime_content_type_is_type (content_type, "application", "pgp-signature"))
- {
- /* 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 = NULL, *stream_filter = NULL;
- GMimeDataWrapper *wrapper;
- const char *charset;
+ int i;
- charset = g_mime_object_get_content_type_parameter (part, "charset");
- stream_stdout = g_mime_stream_file_new (stdout);
- if (stream_stdout) {
+ 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"));
+ } else if (GMIME_IS_MESSAGE (node->part)) {
+ GMimeMessage *message = GMIME_MESSAGE (node->part);
+ InternetAddressList *recipients;
+ const char *recipients_string;
+
+ printf ("> 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);
+ 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");
+ } 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);
+
+ if (g_mime_content_type_is_type (content_type, "application", "pgp-encrypted") ||
+ g_mime_content_type_is_type (content_type, "application", "pgp-signature")) {
+ /* 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);
- stream_filter = g_mime_stream_filter_new(stream_stdout);
- if (charset) {
- g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream_filter),
- g_mime_filter_charset_new(charset, "UTF-8"));
- }
- }
- g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream_filter),
- g_mime_filter_reply_new(TRUE));
- wrapper = g_mime_part_get_content_object (GMIME_PART (part));
- if (wrapper && stream_filter)
- g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
- if (stream_filter)
- g_object_unref(stream_filter);
- if (stream_stdout)
+ show_text_part_content (node->part, stream_stdout, NOTMUCH_SHOW_TEXT_PART_REPLY);
g_object_unref(stream_stdout);
- }
- else
- {
- if (disposition &&
- strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
- {
- const char *filename = g_mime_part_get_filename (GMIME_PART (part));
+ } else if (disposition &&
+ strcmp (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));
- }
- else
- {
+ } else {
printf ("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));
}
-/* Is the given address configured as one of the user's "personal" or
- * "other" addresses. */
-static int
-address_is_users (const char *address, notmuch_config_t *config)
+typedef enum {
+ USER_ADDRESS_IN_STRING,
+ STRING_IN_USER_ADDRESS,
+ STRING_IS_USER_ADDRESS,
+} address_match_t;
+
+/* Match given string against given address according to mode. */
+static notmuch_bool_t
+match_address (const char *str, const char *address, address_match_t mode)
+{
+ switch (mode) {
+ case USER_ADDRESS_IN_STRING:
+ return strcasestr (str, address) != NULL;
+ case STRING_IN_USER_ADDRESS:
+ return strcasestr (address, str) != NULL;
+ case STRING_IS_USER_ADDRESS:
+ return strcasecmp (address, str) == 0;
+ }
+
+ return FALSE;
+}
+
+/* Match given string against user's configured "primary" and "other"
+ * addresses according to mode. */
+static const char *
+address_match (const char *str, notmuch_config_t *config, address_match_t mode)
{
const char *primary;
const char **other;
size_t i, other_len;
+ if (!str || *str == '\0')
+ return NULL;
+
primary = notmuch_config_get_user_primary_email (config);
- if (strcasecmp (primary, address) == 0)
- return 1;
+ if (match_address (str, primary, mode))
+ return primary;
other = notmuch_config_get_user_other_email (config, &other_len);
- for (i = 0; i < other_len; i++)
- if (strcasecmp (other[i], address) == 0)
- return 1;
+ for (i = 0; i < other_len; i++) {
+ if (match_address (str, other[i], mode))
+ return other[i];
+ }
- return 0;
+ return NULL;
+}
+
+/* Does the given string contain an address configured as one of the
+ * user's "primary" or "other" addresses. If so, return the matching
+ * address, NULL otherwise. */
+static const char *
+user_address_in_string (const char *str, notmuch_config_t *config)
+{
+ return address_match (str, config, USER_ADDRESS_IN_STRING);
+}
+
+/* Do any of the addresses configured as one of the user's "primary"
+ * or "other" addresses contain the given string. If so, return the
+ * matching address, NULL otherwise. */
+static const char *
+string_in_user_address (const char *str, notmuch_config_t *config)
+{
+ return address_match (str, config, STRING_IN_USER_ADDRESS);
+}
+
+/* Is the given address configured as one of the user's "primary" or
+ * "other" addresses. */
+static notmuch_bool_t
+address_is_users (const char *address, notmuch_config_t *config)
+{
+ return address_match (address, config, STRING_IS_USER_ADDRESS) != NULL;
}
-/* For each address in 'list' that is not configured as one of the
- * user's addresses in 'config', add that address to 'message' as an
- * address of 'type'.
+/* Scan addresses in 'list'.
+ *
+ * If 'message' is non-NULL, then for each address in 'list' that is
+ * not configured as one of the user's addresses in 'config', add that
+ * address to 'message' as an address of 'type'.
+ *
+ * If 'user_from' is non-NULL and *user_from is NULL, *user_from will
+ * be set to the first address encountered in 'list' that is the
+ * user's address.
*
- * The first address encountered that *is* the user's address will be
- * returned, (otherwise NULL is returned).
+ * Return the number of addresses added to 'message'. (If 'message' is
+ * NULL, the function returns 0 by definition.)
*/
-static const char *
-add_recipients_for_address_list (GMimeMessage *message,
- notmuch_config_t *config,
- GMimeRecipientType type,
- InternetAddressList *list)
+static unsigned int
+scan_address_list (InternetAddressList *list,
+ notmuch_config_t *config,
+ GMimeMessage *message,
+ GMimeRecipientType type,
+ const char **user_from)
{
InternetAddress *address;
int i;
- const char *ret = NULL;
+ unsigned int n = 0;
for (i = 0; i < internet_address_list_length (list); i++) {
address = internet_address_list_get_address (list, i);
@@ -196,8 +207,7 @@ add_recipients_for_address_list (GMimeMessage *message,
if (group_list == NULL)
continue;
- add_recipients_for_address_list (message, config,
- type, group_list);
+ n += scan_address_list (group_list, config, message, type, user_from);
} else {
InternetAddressMailbox *mailbox;
const char *name;
@@ -209,40 +219,41 @@ add_recipients_for_address_list (GMimeMessage *message,
addr = internet_address_mailbox_get_addr (mailbox);
if (address_is_users (addr, config)) {
- if (ret == NULL)
- ret = addr;
- } else {
+ if (user_from && *user_from == NULL)
+ *user_from = addr;
+ } else if (message) {
g_mime_message_add_recipient (message, type, name, addr);
+ n++;
}
}
}
- return ret;
+ return n;
}
-/* For each address in 'recipients' that is not configured as one of
- * the user's addresses in 'config', add that address to 'message' as
- * an address of 'type'.
+/* Scan addresses in 'recipients'.
*
- * The first address encountered that *is* the user's address will be
- * returned, (otherwise NULL is returned).
+ * See the documentation of scan_address_list() above. This function
+ * does exactly the same, but converts 'recipients' to an
+ * InternetAddressList first.
*/
-static const char *
-add_recipients_for_string (GMimeMessage *message,
- notmuch_config_t *config,
- GMimeRecipientType type,
- const char *recipients)
+static unsigned int
+scan_address_string (const char *recipients,
+ notmuch_config_t *config,
+ GMimeMessage *message,
+ GMimeRecipientType type,
+ const char **user_from)
{
InternetAddressList *list;
if (recipients == NULL)
- return NULL;
+ return 0;
list = internet_address_list_parse_string (recipients);
if (list == NULL)
- return NULL;
+ return 0;
- return add_recipients_for_address_list (message, config, type, list);
+ return scan_address_list (list, config, message, type, user_from);
}
/* Does the address in the Reply-To header of 'message' already appear
@@ -284,15 +295,23 @@ reply_to_header_is_redundant (notmuch_message_t *message)
return 0;
}
-/* Augments the recipients of reply from the headers of message.
+/* Augment the recipients of 'reply' from the "Reply-to:", "From:",
+ * "To:", "Cc:", and "Bcc:" headers of 'message'.
+ *
+ * If 'reply_all' is true, use sender and all recipients, otherwise
+ * scan the headers for the first that contains something other than
+ * the user's addresses and add the recipients from this header
+ * (typically this would be reply-to-sender, but also handles reply to
+ * user's own message in a sensible way).
*
- * If any of the user's addresses were found in these headers, the first
- * of these returned, otherwise NULL is returned.
+ * If any of the user's addresses were found in these headers, the
+ * first of these returned, otherwise NULL is returned.
*/
static const char *
add_recipients_from_message (GMimeMessage *reply,
notmuch_config_t *config,
- notmuch_message_t *message)
+ notmuch_message_t *message,
+ notmuch_bool_t reply_all)
{
struct {
const char *header;
@@ -306,6 +325,7 @@ add_recipients_from_message (GMimeMessage *reply,
};
const char *from_addr = NULL;
unsigned int i;
+ unsigned int n = 0;
/* Some mailing lists munge the Reply-To header despite it being A Bad
* Thing, see http://www.unicom.com/pw/reply-to-harmful.html
@@ -324,7 +344,7 @@ add_recipients_from_message (GMimeMessage *reply,
}
for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
- const char *addr, *recipients;
+ const char *recipients;
recipients = notmuch_message_get_header (message,
reply_to_map[i].header);
@@ -332,11 +352,24 @@ add_recipients_from_message (GMimeMessage *reply,
recipients = notmuch_message_get_header (message,
reply_to_map[i].fallback);
- addr = add_recipients_for_string (reply, config,
- reply_to_map[i].recipient_type,
- recipients);
- if (from_addr == NULL)
- from_addr = addr;
+ n += scan_address_string (recipients, config, reply,
+ reply_to_map[i].recipient_type, &from_addr);
+
+ if (!reply_all && n) {
+ /* Stop adding new recipients in reply-to-sender mode if
+ * we have added some recipient(s) above.
+ *
+ * This also handles the case of user replying to his own
+ * message, where reply-to/from is not a recipient. In
+ * this case there may be more than one recipient even if
+ * not replying to all.
+ */
+ reply = NULL;
+
+ /* From address and some recipients are enough, bail out. */
+ if (from_addr)
+ break;
+ }
}
return from_addr;
@@ -345,19 +378,18 @@ add_recipients_from_message (GMimeMessage *reply,
static const char *
guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message)
{
- const char *received,*primary,*by;
- const char **other;
- char *tohdr;
+ const char *addr, *received, *by;
char *mta,*ptr,*token;
char *domain=NULL;
char *tld=NULL;
const char *delim=". \t";
- size_t i,j,other_len;
-
- const char *to_headers[] = {"Envelope-to", "X-Original-To"};
+ size_t i;
- primary = notmuch_config_get_user_primary_email (config);
- other = notmuch_config_get_user_other_email (config, &other_len);
+ const char *to_headers[] = {
+ "Envelope-to",
+ "X-Original-To",
+ "Delivered-To",
+ };
/* sadly, there is no standard way to find out to which email
* address a mail was delivered - what is in the headers depends
@@ -368,28 +400,19 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
* the To: or Cc: header. From here we try the following in order:
* 1) check for an Envelope-to: header
* 2) check for an X-Original-To: header
- * 3) check for a (for <email@add.res>) clause in Received: headers
- * 4) check for the domain part of known email addresses in the
+ * 3) check for a Delivered-To: header
+ * 4) check for a (for <email@add.res>) clause in Received: headers
+ * 5) check for the domain part of known email addresses in the
* 'by' part of Received headers
* If none of these work, we give up and return NULL
*/
- for (i = 0; i < sizeof(to_headers)/sizeof(*to_headers); i++) {
- tohdr = xstrdup(notmuch_message_get_header (message, to_headers[i]));
- if (tohdr && *tohdr) {
- /* tohdr is potentialy a list of email addresses, so here we
- * check if one of the email addresses is a substring of tohdr
- */
- if (strcasestr(tohdr, primary)) {
- free(tohdr);
- return primary;
- }
- for (j = 0; j < other_len; j++)
- if (strcasestr (tohdr, other[j])) {
- free(tohdr);
- return other[j];
- }
- free(tohdr);
- }
+ for (i = 0; i < ARRAY_SIZE (to_headers); i++) {
+ const char *tohdr = notmuch_message_get_header (message, to_headers[i]);
+
+ /* Note: tohdr potentially contains a list of email addresses. */
+ addr = user_address_in_string (tohdr, config);
+ if (addr)
+ return addr;
}
/* We get the concatenated Received: headers and search from the
@@ -407,19 +430,12 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
* header
*/
ptr = strstr (received, " for ");
- if (ptr) {
- /* the text following is potentialy a list of email addresses,
- * so again we check if one of the email addresses is a
- * substring of ptr
- */
- if (strcasestr(ptr, primary)) {
- return primary;
- }
- for (i = 0; i < other_len; i++)
- if (strcasestr (ptr, other[i])) {
- return other[i];
- }
- }
+
+ /* Note: ptr potentially contains a list of email addresses. */
+ addr = user_address_in_string (ptr, config);
+ if (addr)
+ return addr;
+
/* Finally, we parse all the " by MTA ..." headers to guess the
* email address that this was originally delivered to.
* We extract just the MTA here by removing leading whitespace and
@@ -460,15 +476,11 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
*/
*(tld-1) = '.';
- if (strcasestr(primary, domain)) {
- free(mta);
- return primary;
+ addr = string_in_user_address (domain, config);
+ if (addr) {
+ free (mta);
+ return addr;
}
- for (i = 0; i < other_len; i++)
- if (strcasestr (other[i],domain)) {
- free(mta);
- return other[i];
- }
}
free (mta);
}
@@ -476,18 +488,72 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message
return NULL;
}
+static GMimeMessage *
+create_reply_message(void *ctx,
+ notmuch_config_t *config,
+ notmuch_message_t *message,
+ notmuch_bool_t reply_all)
+{
+ const char *subject, *from_addr = NULL;
+ const char *in_reply_to, *orig_references, *references;
+
+ /* The 1 means we want headers in a "pretty" order. */
+ GMimeMessage *reply = g_mime_message_new (1);
+ if (reply == NULL) {
+ fprintf (stderr, "Out of memory\n");
+ return NULL;
+ }
+
+ subject = notmuch_message_get_header (message, "subject");
+ if (subject) {
+ if (strncasecmp (subject, "Re:", 3))
+ subject = talloc_asprintf (ctx, "Re: %s", subject);
+ g_mime_message_set_subject (reply, subject);
+ }
+
+ from_addr = add_recipients_from_message (reply, config,
+ message, reply_all);
+
+ if (from_addr == NULL)
+ from_addr = guess_from_received_header (config, message);
+
+ if (from_addr == NULL)
+ from_addr = notmuch_config_get_user_primary_email (config);
+
+ from_addr = talloc_asprintf (ctx, "%s <%s>",
+ notmuch_config_get_user_name (config),
+ from_addr);
+ g_mime_object_set_header (GMIME_OBJECT (reply),
+ "From", from_addr);
+
+ in_reply_to = talloc_asprintf (ctx, "<%s>",
+ notmuch_message_get_message_id (message));
+
+ g_mime_object_set_header (GMIME_OBJECT (reply),
+ "In-Reply-To", in_reply_to);
+
+ orig_references = notmuch_message_get_header (message, "references");
+ references = talloc_asprintf (ctx, "%s%s%s",
+ orig_references ? orig_references : "",
+ orig_references ? " " : "",
+ in_reply_to);
+ g_mime_object_set_header (GMIME_OBJECT (reply),
+ "References", references);
+
+ return reply;
+}
+
static int
notmuch_reply_format_default(void *ctx,
notmuch_config_t *config,
notmuch_query_t *query,
- notmuch_show_params_t *params)
+ notmuch_show_params_t *params,
+ notmuch_bool_t reply_all)
{
GMimeMessage *reply;
notmuch_messages_t *messages;
notmuch_message_t *message;
- const char *subject, *from_addr = NULL;
- const char *in_reply_to, *orig_references, *references;
- const notmuch_show_format_t *format = &format_reply;
+ mime_node_t *root;
for (messages = notmuch_query_search_messages (query);
notmuch_messages_valid (messages);
@@ -495,61 +561,75 @@ notmuch_reply_format_default(void *ctx,
{
message = notmuch_messages_get (messages);
- /* The 1 means we want headers in a "pretty" order. */
- reply = g_mime_message_new (1);
- if (reply == NULL) {
- fprintf (stderr, "Out of memory\n");
+ reply = create_reply_message (ctx, config, message, reply_all);
+
+ /* If reply creation failed, we're out of memory, so don't
+ * bother trying any more messages.
+ */
+ if (!reply) {
+ notmuch_message_destroy (message);
return 1;
}
- subject = notmuch_message_get_header (message, "subject");
- if (subject) {
- if (strncasecmp (subject, "Re:", 3))
- subject = talloc_asprintf (ctx, "Re: %s", subject);
- g_mime_message_set_subject (reply, subject);
- }
+ show_reply_headers (reply);
- from_addr = add_recipients_from_message (reply, config, message);
+ g_object_unref (G_OBJECT (reply));
+ reply = NULL;
- if (from_addr == NULL)
- from_addr = guess_from_received_header (config, message);
+ if (mime_node_open (ctx, message, &(params->crypto), &root) == NOTMUCH_STATUS_SUCCESS) {
+ format_part_reply (root);
+ talloc_free (root);
+ }
- if (from_addr == NULL)
- from_addr = notmuch_config_get_user_primary_email (config);
+ notmuch_message_destroy (message);
+ }
+ return 0;
+}
- from_addr = talloc_asprintf (ctx, "%s <%s>",
- notmuch_config_get_user_name (config),
- from_addr);
- g_mime_object_set_header (GMIME_OBJECT (reply),
- "From", from_addr);
+static int
+notmuch_reply_format_json(void *ctx,
+ notmuch_config_t *config,
+ notmuch_query_t *query,
+ notmuch_show_params_t *params,
+ notmuch_bool_t reply_all)
+{
+ GMimeMessage *reply;
+ notmuch_messages_t *messages;
+ notmuch_message_t *message;
+ mime_node_t *node;
+ sprinter_t *sp;
- in_reply_to = talloc_asprintf (ctx, "<%s>",
- notmuch_message_get_message_id (message));
+ if (notmuch_query_count_messages (query) != 1) {
+ fprintf (stderr, "Error: search term did not match precisely one message.\n");
+ return 1;
+ }
- g_mime_object_set_header (GMIME_OBJECT (reply),
- "In-Reply-To", in_reply_to);
+ messages = notmuch_query_search_messages (query);
+ message = notmuch_messages_get (messages);
+ if (mime_node_open (ctx, message, &(params->crypto), &node) != NOTMUCH_STATUS_SUCCESS)
+ return 1;
- orig_references = notmuch_message_get_header (message, "references");
- references = talloc_asprintf (ctx, "%s%s%s",
- orig_references ? orig_references : "",
- orig_references ? " " : "",
- in_reply_to);
- g_mime_object_set_header (GMIME_OBJECT (reply),
- "References", references);
+ reply = create_reply_message (ctx, config, message, reply_all);
+ if (!reply)
+ return 1;
- show_reply_headers (reply);
+ sp = sprinter_json_create (ctx, stdout);
- g_object_unref (G_OBJECT (reply));
- reply = NULL;
+ /* The headers of the reply message we've created */
+ printf ("{\"reply-headers\": ");
+ format_headers_json (sp, reply, TRUE);
+ g_object_unref (G_OBJECT (reply));
+ reply = NULL;
- printf ("On %s, %s wrote:\n",
- notmuch_message_get_header (message, "date"),
- notmuch_message_get_header (message, "from"));
+ /* Start the original */
+ printf (", \"original\": ");
- show_message_body (message, format, params);
+ format_part_json (ctx, sp, node, TRUE, TRUE);
+
+ /* End */
+ printf ("}\n");
+ notmuch_message_destroy (message);
- notmuch_message_destroy (message);
- }
return 0;
}
@@ -558,7 +638,8 @@ static int
notmuch_reply_format_headers_only(void *ctx,
notmuch_config_t *config,
notmuch_query_t *query,
- unused (notmuch_show_params_t *params))
+ unused (notmuch_show_params_t *params),
+ notmuch_bool_t reply_all)
{
GMimeMessage *reply;
notmuch_messages_t *messages;
@@ -598,7 +679,7 @@ notmuch_reply_format_headers_only(void *ctx,
g_mime_object_set_header (GMIME_OBJECT (reply),
"References", references);
- (void)add_recipients_from_message (reply, config, message);
+ (void)add_recipients_from_message (reply, config, message, reply_all);
reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));
printf ("%s", reply_headers);
@@ -614,6 +695,7 @@ notmuch_reply_format_headers_only(void *ctx,
enum {
FORMAT_DEFAULT,
+ FORMAT_JSON,
FORMAT_HEADERS_ONLY,
};
@@ -625,17 +707,28 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
notmuch_query_t *query;
char *query_string;
int opt_index, ret = 0;
- int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);
- notmuch_show_params_t params = { .part = -1 };
+ int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);
+ notmuch_show_params_t params = {
+ .part = -1,
+ .crypto = {
+ .verify = FALSE,
+ .decrypt = FALSE
+ }
+ };
int format = FORMAT_DEFAULT;
- notmuch_bool_t decrypt = FALSE;
+ int reply_all = TRUE;
notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
(notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },
+ { "json", FORMAT_JSON },
{ "headers-only", FORMAT_HEADERS_ONLY },
{ 0, 0 } } },
- { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },
+ { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',
+ (notmuch_keyword_t []){ { "all", TRUE },
+ { "sender", FALSE },
+ { 0, 0 } } },
+ { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },
{ 0, 0, 0, 0, 0 }
};
@@ -647,21 +740,11 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
if (format == FORMAT_HEADERS_ONLY)
reply_format_func = notmuch_reply_format_headers_only;
+ else if (format == FORMAT_JSON)
+ reply_format_func = notmuch_reply_format_json;
else
reply_format_func = notmuch_reply_format_default;
- if (decrypt) {
- GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
- params.cryptoctx = g_mime_gpg_context_new (session, "gpg");
- if (params.cryptoctx) {
- g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);
- params.decrypt = TRUE;
- } else {
- fprintf (stderr, "Failed to construct gpg context.\n");
- }
- g_object_unref (session);
- }
-
config = notmuch_config_open (ctx, NULL, NULL);
if (config == NULL)
return 1;
@@ -677,9 +760,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
return 1;
}
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
- if (notmuch == NULL)
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
return 1;
query = notmuch_query_create (notmuch, query_string);
@@ -688,14 +770,12 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
return 1;
}
- if (reply_format_func (ctx, config, query, &params) != 0)
+ if (reply_format_func (ctx, config, query, &params, reply_all) != 0)
return 1;
+ notmuch_crypto_cleanup (&params.crypto);
notmuch_query_destroy (query);
- notmuch_database_close (notmuch);
-
- if (params.cryptoctx)
- g_object_unref(params.cryptoctx);
+ notmuch_database_destroy (notmuch);
return ret;
}
diff --git a/notmuch-restore.c b/notmuch-restore.c
index 87d9772..08d5adc 100644
--- a/notmuch-restore.c
+++ b/notmuch-restore.c
@@ -20,6 +20,81 @@
#include "notmuch-client.h"
+static int
+tag_message (notmuch_database_t *notmuch, const char *message_id,
+ char *file_tags, notmuch_bool_t remove_all,
+ notmuch_bool_t synchronize_flags)
+{
+ notmuch_status_t status;
+ notmuch_tags_t *db_tags;
+ char *db_tags_str;
+ notmuch_message_t *message = NULL;
+ const char *tag;
+ char *next;
+ int ret = 0;
+
+ status = notmuch_database_find_message (notmuch, message_id, &message);
+ if (status || message == NULL) {
+ fprintf (stderr, "Warning: Cannot apply tags to %smessage: %s\n",
+ message ? "" : "missing ", message_id);
+ if (status)
+ fprintf (stderr, "%s\n", notmuch_status_to_string(status));
+ return 1;
+ }
+
+ /* In order to detect missing messages, this check/optimization is
+ * intentionally done *after* first finding the message. */
+ if (!remove_all && (file_tags == NULL || *file_tags == '\0'))
+ goto DONE;
+
+ db_tags_str = NULL;
+ for (db_tags = notmuch_message_get_tags (message);
+ notmuch_tags_valid (db_tags);
+ notmuch_tags_move_to_next (db_tags)) {
+ tag = notmuch_tags_get (db_tags);
+
+ if (db_tags_str)
+ db_tags_str = talloc_asprintf_append (db_tags_str, " %s", tag);
+ else
+ db_tags_str = talloc_strdup (message, tag);
+ }
+
+ if (((file_tags == NULL || *file_tags == '\0') &&
+ (db_tags_str == NULL || *db_tags_str == '\0')) ||
+ (file_tags && db_tags_str && strcmp (file_tags, db_tags_str) == 0))
+ goto DONE;
+
+ notmuch_message_freeze (message);
+
+ if (remove_all)
+ notmuch_message_remove_all_tags (message);
+
+ next = file_tags;
+ while (next) {
+ tag = strsep (&next, " ");
+ if (*tag == '\0')
+ continue;
+ status = notmuch_message_add_tag (message, tag);
+ if (status) {
+ fprintf (stderr, "Error applying tag %s to message %s:\n",
+ tag, message_id);
+ fprintf (stderr, "%s\n", notmuch_status_to_string (status));
+ ret = 1;
+ }
+ }
+
+ notmuch_message_thaw (message);
+
+ if (synchronize_flags)
+ notmuch_message_tags_to_maildir_flags (message);
+
+DONE:
+ if (message)
+ notmuch_message_destroy (message);
+
+ return ret;
+}
+
int
notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
{
@@ -40,15 +115,14 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_WRITE);
- if (notmuch == NULL)
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
return 1;
synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_POSITION, &input_file_name, 0, 0, 0 },
+ { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
{ NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },
{ 0, 0, 0, 0, 0 }
};
@@ -88,11 +162,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
while ((line_len = getline (&line, &line_size, input)) != -1) {
regmatch_t match[3];
- char *message_id, *file_tags, *tag, *next;
- notmuch_message_t *message = NULL;
- notmuch_status_t status;
- notmuch_tags_t *db_tags;
- char *db_tags_str;
+ char *message_id, *file_tags;
chomp_newline (line);
@@ -109,72 +179,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
file_tags = xstrndup (line + match[2].rm_so,
match[2].rm_eo - match[2].rm_so);
- status = notmuch_database_find_message (notmuch, message_id, &message);
- if (status || message == NULL) {
- fprintf (stderr, "Warning: Cannot apply tags to %smessage: %s\n",
- message ? "" : "missing ", message_id);
- if (status)
- fprintf (stderr, "%s\n",
- notmuch_status_to_string(status));
- goto NEXT_LINE;
- }
-
- /* In order to detect missing messages, this check/optimization is
- * intentionally done *after* first finding the message. */
- if (accumulate && (file_tags == NULL || *file_tags == '\0'))
- {
- goto NEXT_LINE;
- }
-
- db_tags_str = NULL;
- for (db_tags = notmuch_message_get_tags (message);
- notmuch_tags_valid (db_tags);
- notmuch_tags_move_to_next (db_tags))
- {
- const char *tag = notmuch_tags_get (db_tags);
-
- if (db_tags_str)
- db_tags_str = talloc_asprintf_append (db_tags_str, " %s", tag);
- else
- db_tags_str = talloc_strdup (message, tag);
- }
-
- if (((file_tags == NULL || *file_tags == '\0') &&
- (db_tags_str == NULL || *db_tags_str == '\0')) ||
- (file_tags && db_tags_str && strcmp (file_tags, db_tags_str) == 0))
- {
- goto NEXT_LINE;
- }
-
- notmuch_message_freeze (message);
-
- if (!accumulate)
- notmuch_message_remove_all_tags (message);
-
- next = file_tags;
- while (next) {
- tag = strsep (&next, " ");
- if (*tag == '\0')
- continue;
- status = notmuch_message_add_tag (message, tag);
- if (status) {
- fprintf (stderr,
- "Error applying tag %s to message %s:\n",
- tag, message_id);
- fprintf (stderr, "%s\n",
- notmuch_status_to_string (status));
- }
- }
-
- notmuch_message_thaw (message);
-
- if (synchronize_flags)
- notmuch_message_tags_to_maildir_flags (message);
+ tag_message (notmuch, message_id, file_tags, !accumulate,
+ synchronize_flags);
- NEXT_LINE:
- if (message)
- notmuch_message_destroy (message);
- message = NULL;
free (message_id);
free (file_tags);
}
@@ -184,7 +191,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
if (line)
free (line);
- notmuch_database_close (notmuch);
+ notmuch_database_destroy (notmuch);
if (input != stdin)
fclose (input);
diff --git a/notmuch-search.c b/notmuch-search.c
index 4baab56..830c4e4 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -19,6 +19,7 @@
*/
#include "notmuch-client.h"
+#include "sprinter.h"
typedef enum {
OUTPUT_SUMMARY,
@@ -28,89 +29,6 @@ typedef enum {
OUTPUT_TAGS
} output_t;
-typedef struct search_format {
- const char *results_start;
- const char *item_start;
- void (*item_id) (const void *ctx,
- const char *item_type,
- const char *item_id);
- void (*thread_summary) (const void *ctx,
- const char *thread_id,
- const time_t date,
- const int matched,
- const int total,
- const char *authors,
- const char *subject);
- const char *tag_start;
- const char *tag;
- const char *tag_sep;
- const char *tag_end;
- const char *item_sep;
- const char *item_end;
- const char *results_end;
- const char *results_null;
-} search_format_t;
-
-static void
-format_item_id_text (const void *ctx,
- const char *item_type,
- const char *item_id);
-
-static void
-format_thread_text (const void *ctx,
- const char *thread_id,
- const time_t date,
- const int matched,
- const int total,
- const char *authors,
- const char *subject);
-static const search_format_t format_text = {
- "",
- "",
- format_item_id_text,
- format_thread_text,
- " (",
- "%s", " ",
- ")", "\n",
- "",
- "\n",
- "",
-};
-
-static void
-format_item_id_json (const void *ctx,
- const char *item_type,
- const char *item_id);
-
-static void
-format_thread_json (const void *ctx,
- const char *thread_id,
- const time_t date,
- const int matched,
- const int total,
- const char *authors,
- const char *subject);
-static const search_format_t format_json = {
- "[",
- "{",
- format_item_id_json,
- format_thread_json,
- "\"tags\": [",
- "\"%s\"", ", ",
- "]", ",\n",
- "}",
- "]\n",
- "]\n",
-};
-
-static void
-format_item_id_text (unused (const void *ctx),
- const char *item_type,
- const char *item_id)
-{
- printf ("%s%s", item_type, item_id);
-}
-
static char *
sanitize_string (const void *ctx, const char *str)
{
@@ -128,72 +46,8 @@ sanitize_string (const void *ctx, const char *str)
return out;
}
-static void
-format_thread_text (const void *ctx,
- const char *thread_id,
- const time_t date,
- const int matched,
- const int total,
- const char *authors,
- const char *subject)
-{
- void *ctx_quote = talloc_new (ctx);
-
- printf ("thread:%s %12s [%d/%d] %s; %s",
- thread_id,
- notmuch_time_relative_date (ctx, date),
- matched,
- total,
- sanitize_string (ctx_quote, authors),
- sanitize_string (ctx_quote, subject));
-
- talloc_free (ctx_quote);
-}
-
-static void
-format_item_id_json (const void *ctx,
- unused (const char *item_type),
- const char *item_id)
-{
- void *ctx_quote = talloc_new (ctx);
-
- printf ("%s", json_quote_str (ctx_quote, item_id));
-
- talloc_free (ctx_quote);
-
-}
-
-static void
-format_thread_json (const void *ctx,
- const char *thread_id,
- const time_t date,
- const int matched,
- const int total,
- const char *authors,
- const char *subject)
-{
- void *ctx_quote = talloc_new (ctx);
-
- printf ("\"thread\": %s,\n"
- "\"timestamp\": %ld,\n"
- "\"date_relative\": \"%s\",\n"
- "\"matched\": %d,\n"
- "\"total\": %d,\n"
- "\"authors\": %s,\n"
- "\"subject\": %s,\n",
- json_quote_str (ctx_quote, thread_id),
- date,
- notmuch_time_relative_date (ctx, date),
- matched,
- total,
- json_quote_str (ctx_quote, authors),
- json_quote_str (ctx_quote, subject));
-
- talloc_free (ctx_quote);
-}
-
static int
-do_search_threads (const search_format_t *format,
+do_search_threads (sprinter_t *format,
notmuch_query_t *query,
notmuch_sort_t sort,
output_t output,
@@ -204,7 +58,6 @@ do_search_threads (const search_format_t *format,
notmuch_threads_t *threads;
notmuch_tags_t *tags;
time_t date;
- int first_thread = 1;
int i;
if (offset < 0) {
@@ -217,14 +70,12 @@ do_search_threads (const search_format_t *format,
if (threads == NULL)
return 1;
- fputs (format->results_start, stdout);
+ format->begin_list (format);
for (i = 0;
notmuch_threads_valid (threads) && (limit < 0 || i < offset + limit);
notmuch_threads_move_to_next (threads), i++)
{
- int first_tag = 1;
-
thread = notmuch_threads_get (threads);
if (i < offset) {
@@ -232,60 +83,97 @@ do_search_threads (const search_format_t *format,
continue;
}
- if (! first_thread)
- fputs (format->item_sep, stdout);
-
if (output == OUTPUT_THREADS) {
- format->item_id (thread, "thread:",
- notmuch_thread_get_thread_id (thread));
+ format->set_prefix (format, "thread");
+ format->string (format,
+ notmuch_thread_get_thread_id (thread));
+ format->separator (format);
} else { /* output == OUTPUT_SUMMARY */
- fputs (format->item_start, stdout);
+ void *ctx_quote = talloc_new (thread);
+ const char *authors = notmuch_thread_get_authors (thread);
+ const char *subject = notmuch_thread_get_subject (thread);
+ const char *thread_id = notmuch_thread_get_thread_id (thread);
+ int matched = notmuch_thread_get_matched_messages (thread);
+ int total = notmuch_thread_get_total_messages (thread);
+ const char *relative_date = NULL;
+ notmuch_bool_t first_tag = TRUE;
+
+ format->begin_map (format);
if (sort == NOTMUCH_SORT_OLDEST_FIRST)
date = notmuch_thread_get_oldest_date (thread);
else
date = notmuch_thread_get_newest_date (thread);
- format->thread_summary (thread,
- notmuch_thread_get_thread_id (thread),
- date,
- notmuch_thread_get_matched_messages (thread),
- notmuch_thread_get_total_messages (thread),
- notmuch_thread_get_authors (thread),
- notmuch_thread_get_subject (thread));
+ relative_date = notmuch_time_relative_date (ctx_quote, date);
+
+ if (format->is_text_printer) {
+ /* Special case for the text formatter */
+ printf ("thread:%s %12s [%d/%d] %s; %s (",
+ thread_id,
+ relative_date,
+ matched,
+ total,
+ sanitize_string (ctx_quote, authors),
+ sanitize_string (ctx_quote, subject));
+ } else { /* Structured Output */
+ format->map_key (format, "thread");
+ format->string (format, thread_id);
+ format->map_key (format, "timestamp");
+ format->integer (format, date);
+ format->map_key (format, "date_relative");
+ format->string (format, relative_date);
+ format->map_key (format, "matched");
+ format->integer (format, matched);
+ format->map_key (format, "total");
+ format->integer (format, total);
+ format->map_key (format, "authors");
+ format->string (format, authors);
+ format->map_key (format, "subject");
+ format->string (format, subject);
+ }
+
+ talloc_free (ctx_quote);
- fputs (format->tag_start, stdout);
+ format->map_key (format, "tags");
+ format->begin_list (format);
for (tags = notmuch_thread_get_tags (thread);
notmuch_tags_valid (tags);
notmuch_tags_move_to_next (tags))
{
- if (! first_tag)
- fputs (format->tag_sep, stdout);
- printf (format->tag, notmuch_tags_get (tags));
- first_tag = 0;
+ const char *tag = notmuch_tags_get (tags);
+
+ if (format->is_text_printer) {
+ /* Special case for the text formatter */
+ if (first_tag)
+ first_tag = FALSE;
+ else
+ fputc (' ', stdout);
+ fputs (tag, stdout);
+ } else { /* Structured Output */
+ format->string (format, tag);
+ }
}
- fputs (format->tag_end, stdout);
+ if (format->is_text_printer)
+ printf (")");
- fputs (format->item_end, stdout);
+ format->end (format);
+ format->end (format);
+ format->separator (format);
}
- first_thread = 0;
-
notmuch_thread_destroy (thread);
}
- if (first_thread)
- fputs (format->results_null, stdout);
- else
- fputs (format->results_end, stdout);
+ format->end (format);
return 0;
}
static int
-do_search_messages (const search_format_t *format,
+do_search_messages (sprinter_t *format,
notmuch_query_t *query,
output_t output,
int offset,
@@ -294,7 +182,6 @@ do_search_messages (const search_format_t *format,
notmuch_message_t *message;
notmuch_messages_t *messages;
notmuch_filenames_t *filenames;
- int first_message = 1;
int i;
if (offset < 0) {
@@ -307,7 +194,7 @@ do_search_messages (const search_format_t *format,
if (messages == NULL)
return 1;
- fputs (format->results_start, stdout);
+ format->begin_list (format);
for (i = 0;
notmuch_messages_valid (messages) && (limit < 0 || i < offset + limit);
@@ -325,24 +212,17 @@ do_search_messages (const search_format_t *format,
notmuch_filenames_valid (filenames);
notmuch_filenames_move_to_next (filenames))
{
- if (! first_message)
- fputs (format->item_sep, stdout);
-
- format->item_id (message, "",
- notmuch_filenames_get (filenames));
-
- first_message = 0;
+ format->string (format, notmuch_filenames_get (filenames));
+ format->separator (format);
}
notmuch_filenames_destroy( filenames );
} else { /* output == OUTPUT_MESSAGES */
- if (! first_message)
- fputs (format->item_sep, stdout);
-
- format->item_id (message, "id:",
- notmuch_message_get_message_id (message));
- first_message = 0;
+ format->set_prefix (format, "id");
+ format->string (format,
+ notmuch_message_get_message_id (message));
+ format->separator (format);
}
notmuch_message_destroy (message);
@@ -350,23 +230,22 @@ do_search_messages (const search_format_t *format,
notmuch_messages_destroy (messages);
- if (first_message)
- fputs (format->results_null, stdout);
- else
- fputs (format->results_end, stdout);
+ format->end (format);
return 0;
}
static int
do_search_tags (notmuch_database_t *notmuch,
- const search_format_t *format,
+ sprinter_t *format,
notmuch_query_t *query)
{
notmuch_messages_t *messages = NULL;
notmuch_tags_t *tags;
const char *tag;
- int first_tag = 1;
+
+ /* should the following only special case if no excluded terms
+ * specified? */
/* Special-case query of "*" for better performance. */
if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {
@@ -381,7 +260,7 @@ do_search_tags (notmuch_database_t *notmuch,
if (tags == NULL)
return 1;
- fputs (format->results_start, stdout);
+ format->begin_list (format);
for (;
notmuch_tags_valid (tags);
@@ -389,12 +268,9 @@ do_search_tags (notmuch_database_t *notmuch,
{
tag = notmuch_tags_get (tags);
- if (! first_tag)
- fputs (format->item_sep, stdout);
+ format->string (format, tag);
+ format->separator (format);
- format->item_id (tags, "", tag);
-
- first_tag = 0;
}
notmuch_tags_destroy (tags);
@@ -402,14 +278,17 @@ do_search_tags (notmuch_database_t *notmuch,
if (messages)
notmuch_messages_destroy (messages);
- if (first_tag)
- fputs (format->results_null, stdout);
- else
- fputs (format->results_end, stdout);
+ format->end (format);
return 0;
}
+enum {
+ EXCLUDE_TRUE,
+ EXCLUDE_FALSE,
+ EXCLUDE_FLAG,
+};
+
int
notmuch_search_command (void *ctx, int argc, char *argv[])
{
@@ -418,11 +297,13 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
notmuch_query_t *query;
char *query_str;
notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
- const search_format_t *format = &format_text;
+ sprinter_t *format = NULL;
int opt_index, ret;
output_t output = OUTPUT_SUMMARY;
int offset = 0;
int limit = -1; /* unlimited */
+ int exclude = EXCLUDE_TRUE;
+ unsigned int i;
enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }
format_sel = NOTMUCH_FORMAT_TEXT;
@@ -443,6 +324,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
{ "files", OUTPUT_FILES },
{ "tags", OUTPUT_TAGS },
{ 0, 0 } } },
+ { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
+ (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
+ { "false", EXCLUDE_FALSE },
+ { "flag", EXCLUDE_FLAG },
+ { 0, 0 } } },
{ NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },
{ NOTMUCH_OPT_INT, &limit, "limit", 'L', 0 },
{ 0, 0, 0, 0, 0 }
@@ -456,20 +342,22 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
switch (format_sel) {
case NOTMUCH_FORMAT_TEXT:
- format = &format_text;
+ format = sprinter_text_create (ctx, stdout);
break;
case NOTMUCH_FORMAT_JSON:
- format = &format_json;
+ format = sprinter_json_create (ctx, stdout);
break;
+ default:
+ /* this should never happen */
+ INTERNAL_ERROR("no output format selected");
}
config = notmuch_config_open (ctx, NULL, NULL);
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
- if (notmuch == NULL)
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
return 1;
query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);
@@ -490,6 +378,26 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
notmuch_query_set_sort (query, sort);
+ if (exclude == EXCLUDE_FLAG && output != OUTPUT_SUMMARY) {
+ /* If we are not doing summary output there is nowhere to
+ * print the excluded flag so fall back on including the
+ * excluded messages. */
+ fprintf (stderr, "Warning: this output format cannot flag excluded messages.\n");
+ exclude = EXCLUDE_FALSE;
+ }
+
+ if (exclude == EXCLUDE_TRUE || exclude == EXCLUDE_FLAG) {
+ const char **search_exclude_tags;
+ size_t search_exclude_tags_length;
+
+ 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]);
+ if (exclude == EXCLUDE_FLAG)
+ notmuch_query_set_omit_excluded (query, FALSE);
+ }
+
switch (output) {
default:
case OUTPUT_SUMMARY:
@@ -506,7 +414,9 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
}
notmuch_query_destroy (query);
- notmuch_database_close (notmuch);
+ notmuch_database_destroy (notmuch);
+
+ talloc_free (format);
return ret;
}
diff --git a/notmuch-setup.c b/notmuch-setup.c
index c3ea937..94d0aa7 100644
--- a/notmuch-setup.c
+++ b/notmuch-setup.c
@@ -87,6 +87,38 @@ welcome_message_post_setup (void)
"have sufficient storage space available now.\n\n");
}
+static void
+print_tag_list (const char **tags, size_t tags_len)
+{
+ unsigned int i;
+ for (i = 0; i < tags_len; i++) {
+ if (i != 0)
+ printf (" ");
+ printf ("%s", tags[i]);
+ }
+}
+
+static GPtrArray *
+parse_tag_list (void *ctx, char *response)
+{
+ GPtrArray *tags = g_ptr_array_new ();
+ char *tag = response;
+ char *space;
+
+ while (tag && *tag) {
+ space = strchr (tag, ' ');
+ if (space)
+ g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));
+ else
+ g_ptr_array_add (tags, talloc_strdup (ctx, tag));
+ tag = space;
+ while (tag && *tag == ' ')
+ tag++;
+ }
+
+ return tags;
+}
+
int
notmuch_setup_command (unused (void *ctx),
unused (int argc), unused (char *argv[]))
@@ -101,6 +133,8 @@ notmuch_setup_command (unused (void *ctx),
int is_new;
const char **new_tags;
size_t new_tags_len;
+ const char **search_exclude_tags;
+ size_t search_exclude_tags_len;
#define prompt(format, ...) \
do { \
@@ -164,37 +198,36 @@ notmuch_setup_command (unused (void *ctx),
new_tags = notmuch_config_get_new_tags (config, &new_tags_len);
printf ("Tags to apply to all new messages (separated by spaces) [");
+ print_tag_list (new_tags, new_tags_len);
+ prompt ("]: ");
- for (i = 0; i < new_tags_len; i++) {
- if (i != 0)
- printf (" ");
- printf ("%s", new_tags[i]);
+ if (strlen (response)) {
+ GPtrArray *tags = parse_tag_list (ctx, response);
+
+ notmuch_config_set_new_tags (config, (const char **) tags->pdata,
+ tags->len);
+
+ g_ptr_array_free (tags, TRUE);
}
+
+ search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_len);
+
+ printf ("Tags to exclude when searching messages (separated by spaces) [");
+ print_tag_list (search_exclude_tags, search_exclude_tags_len);
prompt ("]: ");
if (strlen (response)) {
- GPtrArray *tags = g_ptr_array_new ();
- char *tag = response;
- char *space;
-
- while (tag && *tag) {
- space = strchr (tag, ' ');
- if (space)
- g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));
- else
- g_ptr_array_add (tags, talloc_strdup (ctx, tag));
- tag = space;
- while (tag && *tag == ' ')
- tag++;
- }
+ GPtrArray *tags = parse_tag_list (ctx, response);
- notmuch_config_set_new_tags (config, (const char **) tags->pdata,
- tags->len);
+ notmuch_config_set_search_exclude_tags (config,
+ (const char **) tags->pdata,
+ tags->len);
g_ptr_array_free (tags, TRUE);
}
+
if (! notmuch_config_save (config)) {
if (is_new)
welcome_message_post_setup ();
diff --git a/notmuch-show.c b/notmuch-show.c
index 87a1c90..3556293 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -19,125 +19,44 @@
*/
#include "notmuch-client.h"
+#include "gmime-filter-reply.h"
+#include "sprinter.h"
-static void
-format_message_text (unused (const void *ctx),
- notmuch_message_t *message,
- int indent);
-static void
-format_headers_text (const void *ctx,
- notmuch_message_t *message);
-
-static void
-format_headers_message_part_text (GMimeMessage *message);
-
-static void
-format_part_start_text (GMimeObject *part,
- int *part_count);
-
-static void
-format_part_content_text (GMimeObject *part);
-
-static void
-format_part_end_text (GMimeObject *part);
+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 = {
- "",
- "\fmessage{ ", format_message_text,
- "\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n",
- "\fbody{\n",
- format_part_start_text,
- NULL,
- NULL,
- format_part_content_text,
- format_part_end_text,
- "",
- "\fbody}\n",
- "\fmessage}\n", "",
- ""
+ .new_sprinter = sprinter_text_create,
+ .part = format_part_text,
};
-static void
-format_message_json (const void *ctx,
- notmuch_message_t *message,
- unused (int indent));
-static void
-format_headers_json (const void *ctx,
- notmuch_message_t *message);
-
-static void
-format_headers_message_part_json (GMimeMessage *message);
-
-static void
-format_part_start_json (unused (GMimeObject *part),
- int *part_count);
-
-static void
-format_part_encstatus_json (int status);
-
-static void
-format_part_sigstatus_json (const GMimeSignatureValidity* validity);
-
-static void
-format_part_content_json (GMimeObject *part);
-
-static void
-format_part_end_json (GMimeObject *part);
+static notmuch_status_t
+format_part_json_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 = {
- "[",
- "{", format_message_json,
- "\"headers\": {", format_headers_json, format_headers_message_part_json, "}",
- ", \"body\": [",
- format_part_start_json,
- format_part_encstatus_json,
- format_part_sigstatus_json,
- format_part_content_json,
- format_part_end_json,
- ", ",
- "]",
- "}", ", ",
- "]"
+ .new_sprinter = sprinter_json_create,
+ .part = format_part_json_entry,
};
-static void
-format_message_mbox (const void *ctx,
- notmuch_message_t *message,
- unused (int indent));
+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 = {
- "",
- "", format_message_mbox,
- "", NULL, NULL, "",
- "",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- "",
- "",
- "", "",
- ""
+ .new_sprinter = sprinter_text_create,
+ .part = format_part_mbox,
};
-static void
-format_part_content_raw (GMimeObject *part);
+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 = {
- "",
- "", NULL,
- "", NULL, format_headers_message_part_text, "\n",
- "",
- NULL,
- NULL,
- NULL,
- format_part_content_raw,
- NULL,
- "",
- "",
- "", "",
- ""
+ .new_sprinter = sprinter_text_create,
+ .part = format_part_raw,
};
static const char *
@@ -186,44 +105,45 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)
from, relative_date, tags);
}
+/* Emit a sequence of key/value pairs for the metadata of message.
+ * The caller should begin a map before calling this. */
static void
-format_message_text (unused (const void *ctx), notmuch_message_t *message, int indent)
-{
- printf ("id:%s depth:%d match:%d filename:%s\n",
- notmuch_message_get_message_id (message),
- indent,
- notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH),
- notmuch_message_get_filename (message));
-}
-
-static void
-format_message_json (const void *ctx, notmuch_message_t *message, unused (int indent))
+format_message_json (sprinter_t *sp, notmuch_message_t *message)
{
+ void *local = talloc_new (NULL);
notmuch_tags_t *tags;
- int first = 1;
- void *ctx_quote = talloc_new (ctx);
time_t date;
const char *relative_date;
+ sp->map_key (sp, "id");
+ sp->string (sp, notmuch_message_get_message_id (message));
+
+ sp->map_key (sp, "match");
+ sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH));
+
+ sp->map_key (sp, "excluded");
+ 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));
+
+ sp->map_key (sp, "timestamp");
date = notmuch_message_get_date (message);
- relative_date = notmuch_time_relative_date (ctx, date);
+ sp->integer (sp, date);
- printf ("\"id\": %s, \"match\": %s, \"filename\": %s, \"timestamp\": %ld, \"date_relative\": \"%s\", \"tags\": [",
- json_quote_str (ctx_quote, notmuch_message_get_message_id (message)),
- notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? "true" : "false",
- json_quote_str (ctx_quote, notmuch_message_get_filename (message)),
- date, relative_date);
+ sp->map_key (sp, "date_relative");
+ relative_date = notmuch_time_relative_date (local, date);
+ sp->string (sp, relative_date);
+ sp->map_key (sp, "tags");
+ sp->begin_list (sp);
for (tags = notmuch_message_get_tags (message);
notmuch_tags_valid (tags);
notmuch_tags_move_to_next (tags))
- {
- printf("%s%s", first ? "" : ",",
- json_quote_str (ctx_quote, notmuch_tags_get (tags)));
- first = 0;
- }
- printf("], ");
- talloc_free (ctx_quote);
+ sp->string (sp, notmuch_tags_get (tags));
+ sp->end (sp);
+
+ talloc_free (local);
}
/* Extract just the email address from the contents of a From:
@@ -284,169 +204,62 @@ _is_from_line (const char *line)
return 0;
}
-/* Print a message in "mboxrd" format as documented, for example,
- * here:
- *
- * http://qmail.org/qmail-manual-html/man5/mbox.html
- */
-static void
-format_message_mbox (const void *ctx,
- notmuch_message_t *message,
- unused (int indent))
+void
+format_headers_json (sprinter_t *sp, GMimeMessage *message,
+ notmuch_bool_t reply)
{
- const char *filename;
- FILE *file;
- const char *from;
-
- time_t date;
- struct tm date_gmtime;
- char date_asctime[26];
-
- char *line = NULL;
- size_t line_size;
- ssize_t line_len;
-
- filename = notmuch_message_get_filename (message);
- file = fopen (filename, "r");
- if (file == NULL) {
- fprintf (stderr, "Failed to open %s: %s\n",
- filename, strerror (errno));
- return;
- }
-
- from = notmuch_message_get_header (message, "from");
- from = _extract_email_address (ctx, from);
-
- date = notmuch_message_get_date (message);
- gmtime_r (&date, &date_gmtime);
- asctime_r (&date_gmtime, date_asctime);
-
- printf ("From %s %s", from, date_asctime);
-
- while ((line_len = getline (&line, &line_size, file)) != -1 ) {
- if (_is_from_line (line))
- putchar ('>');
- printf ("%s", line);
- }
-
- printf ("\n");
-
- fclose (file);
-}
-
-
-static void
-format_headers_text (const void *ctx, notmuch_message_t *message)
-{
- const char *headers[] = {
- "Subject", "From", "To", "Cc", "Bcc", "Date"
- };
- const char *name, *value;
- unsigned int i;
+ InternetAddressList *recipients;
+ const char *recipients_string;
- printf ("%s\n", _get_one_line_summary (ctx, message));
+ sp->begin_map (sp);
- for (i = 0; i < ARRAY_SIZE (headers); i++) {
- name = headers[i];
- value = notmuch_message_get_header (message, name);
- if (value && strlen (value))
- printf ("%s: %s\n", name, value);
- }
-}
+ sp->map_key (sp, "Subject");
+ sp->string (sp, g_mime_message_get_subject (message));
-static void
-format_headers_message_part_text (GMimeMessage *message)
-{
- InternetAddressList *recipients;
- const char *recipients_string;
+ sp->map_key (sp, "From");
+ sp->string (sp, g_mime_message_get_sender (message));
- printf ("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);
+ if (recipients_string) {
+ sp->map_key (sp, "To");
+ sp->string (sp, 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));
-}
-
-static void
-format_headers_json (const void *ctx, notmuch_message_t *message)
-{
- const char *headers[] = {
- "Subject", "From", "To", "Cc", "Bcc", "Date"
- };
- const char *name, *value;
- unsigned int i;
- int first_header = 1;
- void *ctx_quote = talloc_new (ctx);
-
- for (i = 0; i < ARRAY_SIZE (headers); i++) {
- name = headers[i];
- value = notmuch_message_get_header (message, name);
- if (value)
- {
- if (!first_header)
- fputs (", ", stdout);
- first_header = 0;
-
- printf ("%s: %s",
- json_quote_str (ctx_quote, name),
- json_quote_str (ctx_quote, value));
- }
+ if (recipients_string) {
+ sp->map_key (sp, "Cc");
+ sp->string (sp, recipients_string);
}
- talloc_free (ctx_quote);
-}
+ if (reply) {
+ sp->map_key (sp, "In-reply-to");
+ sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to"));
-static void
-format_headers_message_part_json (GMimeMessage *message)
-{
- void *ctx = talloc_new (NULL);
- void *ctx_quote = talloc_new (ctx);
- InternetAddressList *recipients;
- const char *recipients_string;
+ sp->map_key (sp, "References");
+ 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));
+ }
- printf ("%s: %s",
- json_quote_str (ctx_quote, "From"),
- json_quote_str (ctx_quote, 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 (", %s: %s",
- json_quote_str (ctx_quote, "To"),
- json_quote_str (ctx_quote, 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 (", %s: %s",
- json_quote_str (ctx_quote, "Cc"),
- json_quote_str (ctx_quote, recipients_string));
- printf (", %s: %s",
- json_quote_str (ctx_quote, "Subject"),
- json_quote_str (ctx_quote, g_mime_message_get_subject (message)));
- printf (", %s: %s",
- json_quote_str (ctx_quote, "Date"),
- json_quote_str (ctx_quote, g_mime_message_get_date_as_string (message)));
-
- talloc_free (ctx_quote);
- talloc_free (ctx);
+ sp->end (sp);
}
/* Write a MIME text part out to the given stream.
*
+ * If (flags & NOTMUCH_SHOW_TEXT_PART_REPLY), this prepends "> " to
+ * each output line.
+ *
* Both line-ending conversion (CRLF->LF) and charset conversion ( ->
* UTF-8) will be performed, so it is inappropriate to call this
* function with a non-text part. Doing so will trigger an internal
* error.
*/
-static void
-show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
+void
+show_text_part_content (GMimeObject *part, GMimeStream *stream_out,
+ notmuch_show_text_part_flags flags)
{
GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
GMimeStream *stream_filter = NULL;
@@ -479,6 +292,16 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
}
+ if (flags & NOTMUCH_SHOW_TEXT_PART_REPLY) {
+ GMimeFilter *reply_filter;
+ reply_filter = g_mime_filter_reply_new (TRUE);
+ if (reply_filter) {
+ g_mime_stream_filter_add (GMIME_STREAM_FILTER (stream_filter),
+ reply_filter);
+ g_object_unref (reply_filter);
+ }
+ }
+
wrapper = g_mime_part_get_content_object (GMIME_PART (part));
if (wrapper && stream_filter)
g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
@@ -486,6 +309,21 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
g_object_unref(stream_filter);
}
+#ifdef GMIME_ATLEAST_26
+static const char*
+signature_status_to_string (GMimeSignatureStatus x)
+{
+ switch (x) {
+ case GMIME_SIGNATURE_STATUS_GOOD:
+ return "good";
+ case GMIME_SIGNATURE_STATUS_BAD:
+ return "bad";
+ case GMIME_SIGNATURE_STATUS_ERROR:
+ return "error";
+ }
+ return "unknown";
+}
+#else
static const char*
signer_status_to_string (GMimeSignerStatus x)
{
@@ -501,183 +339,308 @@ signer_status_to_string (GMimeSignerStatus x)
}
return "unknown";
}
+#endif
+#ifdef GMIME_ATLEAST_26
static void
-format_part_start_text (GMimeObject *part, int *part_count)
+format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
{
- GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part);
+ GMimeSignatureList *siglist = node->sig_list;
- if (disposition &&
- strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
- {
- printf ("\fattachment{ ID: %d", *part_count);
+ sp->begin_list (sp);
- } else {
-
- printf ("\fpart{ ID: %d", *part_count);
- }
-}
-
-static void
-format_part_content_text (GMimeObject *part)
-{
- const char *cid = g_mime_object_get_content_id (part);
- GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
-
- if (GMIME_IS_PART (part))
- {
- const char *filename = g_mime_part_get_filename (GMIME_PART (part));
- if (filename)
- printf (", Filename: %s", filename);
+ if (!siglist) {
+ sp->end (sp);
+ return;
}
- if (cid)
- printf (", Content-id: %s", cid);
+ int i;
+ for (i = 0; i < g_mime_signature_list_length (siglist); i++) {
+ GMimeSignature *signature = g_mime_signature_list_get_signature (siglist, i);
- printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
+ sp->begin_map (sp);
- 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 (part, stream_stdout);
- g_object_unref(stream_stdout);
- }
- else if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
- g_mime_content_type_is_type (content_type, "message", "rfc822"))
- {
- /* Do nothing for multipart since its content will be printed
- * when recursing. */
- }
- else
- {
- printf ("Non-text part: %s\n",
- g_mime_content_type_to_string (content_type));
- }
-}
+ /* status */
+ GMimeSignatureStatus status = g_mime_signature_get_status (signature);
+ sp->map_key (sp, "status");
+ sp->string (sp, signature_status_to_string (status));
+
+ GMimeCertificate *certificate = g_mime_signature_get_certificate (signature);
+ if (status == GMIME_SIGNATURE_STATUS_GOOD) {
+ if (certificate) {
+ sp->map_key (sp, "fingerprint");
+ sp->string (sp, g_mime_certificate_get_fingerprint (certificate));
+ }
+ /* these dates are seconds since the epoch; should we
+ * provide a more human-readable format string? */
+ time_t created = g_mime_signature_get_created (signature);
+ if (created != -1) {
+ sp->map_key (sp, "created");
+ sp->integer (sp, created);
+ }
+ time_t expires = g_mime_signature_get_expires (signature);
+ if (expires > 0) {
+ sp->map_key (sp, "expires");
+ sp->integer (sp, expires);
+ }
+ /* output user id only if validity is FULL or ULTIMATE. */
+ /* note that gmime is using the term "trust" here, which
+ * is WRONG. It's actually user id "validity". */
+ if (certificate) {
+ const char *name = g_mime_certificate_get_name (certificate);
+ GMimeCertificateTrust trust = g_mime_certificate_get_trust (certificate);
+ if (name && (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE)) {
+ sp->map_key (sp, "userid");
+ sp->string (sp, name);
+ }
+ }
+ } else if (certificate) {
+ const char *key_id = g_mime_certificate_get_key_id (certificate);
+ if (key_id) {
+ sp->map_key (sp, "keyid");
+ sp->string (sp, key_id);
+ }
+ }
-static void
-format_part_end_text (GMimeObject *part)
-{
- GMimeContentDisposition *disposition;
+ GMimeSignatureError errors = g_mime_signature_get_errors (signature);
+ if (errors != GMIME_SIGNATURE_ERROR_NONE) {
+ sp->map_key (sp, "errors");
+ sp->integer (sp, errors);
+ }
- disposition = g_mime_object_get_content_disposition (part);
- if (disposition &&
- strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
- {
- printf ("\fattachment}\n");
- }
- else
- {
- printf ("\fpart}\n");
- }
-}
+ sp->end (sp);
+ }
-static void
-format_part_start_json (unused (GMimeObject *part), int *part_count)
-{
- printf ("{\"id\": %d", *part_count);
+ sp->end (sp);
}
-
+#else
static void
-format_part_encstatus_json (int status)
+format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
{
- printf (", \"encstatus\": [{\"status\": ");
- if (status) {
- printf ("\"good\"");
- } else {
- printf ("\"bad\"");
- }
- printf ("}]");
-}
+ const GMimeSignatureValidity* validity = node->sig_validity;
-static void
-format_part_sigstatus_json (const GMimeSignatureValidity* validity)
-{
- printf (", \"sigstatus\": [");
+ sp->begin_list (sp);
if (!validity) {
- printf ("]");
+ sp->end (sp);
return;
}
const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity);
- int first = 1;
- void *ctx_quote = talloc_new (NULL);
-
while (signer) {
- if (first)
- first = 0;
- else
- printf (", ");
-
- printf ("{");
+ sp->begin_map (sp);
/* status */
- printf ("\"status\": %s",
- json_quote_str (ctx_quote,
- signer_status_to_string (signer->status)));
+ sp->map_key (sp, "status");
+ sp->string (sp, signer_status_to_string (signer->status));
if (signer->status == GMIME_SIGNER_STATUS_GOOD)
{
- if (signer->fingerprint)
- printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, signer->fingerprint));
+ if (signer->fingerprint) {
+ sp->map_key (sp, "fingerprint");
+ sp->string (sp, signer->fingerprint);
+ }
/* these dates are seconds since the epoch; should we
* provide a more human-readable format string? */
- if (signer->created)
- printf (", \"created\": %d", (int) signer->created);
- if (signer->expires)
- printf (", \"expires\": %d", (int) signer->expires);
+ if (signer->created) {
+ sp->map_key (sp, "created");
+ sp->integer (sp, signer->created);
+ }
+ if (signer->expires) {
+ sp->map_key (sp, "expires");
+ sp->integer (sp, signer->expires);
+ }
/* output user id only if validity is FULL or ULTIMATE. */
/* note that gmime is using the term "trust" here, which
* is WRONG. It's actually user id "validity". */
if ((signer->name) && (signer->trust)) {
- if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE))
- printf (", \"userid\": %s", json_quote_str (ctx_quote, signer->name));
+ if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE)) {
+ sp->map_key (sp, "userid");
+ sp->string (sp, signer->name);
+ }
}
} else {
- if (signer->keyid)
- printf (", \"keyid\": %s", json_quote_str (ctx_quote, signer->keyid));
+ if (signer->keyid) {
+ sp->map_key (sp, "keyid");
+ sp->string (sp, signer->keyid);
+ }
}
if (signer->errors != GMIME_SIGNER_ERROR_NONE) {
- printf (", \"errors\": %x", signer->errors);
+ sp->map_key (sp, "errors");
+ sp->integer (sp, signer->errors);
}
- printf ("}");
+ sp->end (sp);
signer = signer->next;
}
- printf ("]");
+ sp->end (sp);
+}
+#endif
+
+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)
+{
+ /* The disposition and content-type metadata are associated with
+ * the envelope for message parts */
+ GMimeObject *meta = node->envelope_part ?
+ 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);
+ const char *part_type;
+ int i;
+
+ if (node->envelope_file) {
+ 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));
+ } else {
+ GMimeContentDisposition *disposition = g_mime_object_get_content_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 &&
+ strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
+ part_type = "attachment";
+ else
+ part_type = "part";
+
+ printf ("\f%s{ ID: %d", part_type, node->part_num);
+ if (filename)
+ printf (", Filename: %s", filename);
+ if (cid)
+ printf (", Content-id: %s", cid);
+ printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
+ }
+
+ if (GMIME_IS_MESSAGE (node->part)) {
+ GMimeMessage *message = GMIME_MESSAGE (node->part);
+ InternetAddressList *recipients;
+ const char *recipients_string;
+
+ printf ("\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));
+ 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);
+ 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");
+ }
- talloc_free (ctx_quote);
+ 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);
+ } else {
+ printf ("Non-text part: %s\n",
+ g_mime_content_type_to_string (content_type));
+ }
+ }
+
+ for (i = 0; i < node->nchildren; i++)
+ format_part_text (ctx, sp, mime_node_child (node, i), indent, params);
+
+ if (GMIME_IS_MESSAGE (node->part))
+ printf ("\fbody}\n");
+
+ printf ("\f%s}\n", part_type);
+
+ return NOTMUCH_STATUS_SUCCESS;
}
-static void
-format_part_content_json (GMimeObject *part)
+void
+format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
+ notmuch_bool_t first, notmuch_bool_t output_body)
{
- GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
- GMimeStream *stream_memory = g_mime_stream_mem_new ();
- const char *cid = g_mime_object_get_content_id (part);
- void *ctx = talloc_new (NULL);
- GByteArray *part_content;
+ /* Any changes to the JSON format should be reflected in the file
+ * devel/schemata. */
- printf (", \"content-type\": %s",
- json_quote_str (ctx, g_mime_content_type_to_string (content_type)));
+ if (node->envelope_file) {
+ sp->begin_map (sp);
+ format_message_json (sp, node->envelope_file);
- if (cid != NULL)
- printf(", \"content-id\": %s", json_quote_str (ctx, cid));
+ sp->map_key (sp, "headers");
+ format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);
- if (GMIME_IS_PART (part))
- {
- const char *filename = g_mime_part_get_filename (GMIME_PART (part));
- if (filename)
- printf (", \"filename\": %s", json_quote_str (ctx, filename));
+ if (output_body) {
+ sp->map_key (sp, "body");
+ sp->begin_list (sp);
+ format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE);
+ sp->end (sp);
+ }
+ sp->end (sp);
+ return;
}
- if (g_mime_content_type_is_type (content_type, "text", "*"))
- {
- /* For non-HTML text/* parts, we include the content in the
+ /* The disposition and content-type metadata are associated with
+ * the envelope for message parts */
+ GMimeObject *meta = node->envelope_part ?
+ GMIME_OBJECT (node->envelope_part) : node->part;
+ GMimeContentType *content_type = g_mime_object_get_content_type (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;
+ int nclose = 0;
+ int i;
+
+ sp->begin_map (sp);
+
+ sp->map_key (sp, "id");
+ sp->integer (sp, node->part_num);
+
+ if (node->decrypt_attempted) {
+ sp->map_key (sp, "encstatus");
+ sp->begin_list (sp);
+ sp->begin_map (sp);
+ sp->map_key (sp, "status");
+ sp->string (sp, node->decrypt_success ? "good" : "bad");
+ sp->end (sp);
+ sp->end (sp);
+ }
+
+ if (node->verify_attempted) {
+ sp->map_key (sp, "sigstatus");
+ format_part_sigstatus_json (sp, node);
+ }
+
+ sp->map_key (sp, "content-type");
+ sp->string (sp, g_mime_content_type_to_string (content_type));
+
+ if (cid) {
+ sp->map_key (sp, "content-id");
+ sp->string (sp, cid);
+ }
+
+ if (filename) {
+ sp->map_key (sp, "filename");
+ sp->string (sp, filename);
+ }
+
+ if (GMIME_IS_PART (node->part)) {
+ /* For non-HTML text parts, we include the content in the
* JSON. Since JSON must be Unicode, we handle charset
* decoding here and do not report a charset to the caller.
* For text/html parts, we do not include the content. If a
@@ -686,154 +649,271 @@ format_part_content_json (GMimeObject *part)
* makes charset decoding the responsibility on the caller, we
* report the charset for text/html parts.
*/
- if (g_mime_content_type_is_type (content_type, "text", "html"))
- {
- const char *content_charset = g_mime_object_get_content_type_parameter (GMIME_OBJECT (part), "charset");
+ if (g_mime_content_type_is_type (content_type, "text", "html")) {
+ const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset");
- if (content_charset != NULL)
- printf (", \"content-charset\": %s", json_quote_str (ctx, content_charset));
- }
- else
- {
- show_text_part_content (part, stream_memory);
+ if (content_charset != NULL) {
+ sp->map_key (sp, "content-charset");
+ sp->string (sp, content_charset);
+ }
+ } else if (g_mime_content_type_is_type (content_type, "text", "*")) {
+ GMimeStream *stream_memory = g_mime_stream_mem_new ();
+ GByteArray *part_content;
+ show_text_part_content (node->part, stream_memory, 0);
part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));
-
- printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));
+ sp->map_key (sp, "content");
+ sp->string_len (sp, (char *) part_content->data, part_content->len);
+ g_object_unref (stream_memory);
}
- }
- else if (g_mime_content_type_is_type (content_type, "multipart", "*"))
- {
- printf (", \"content\": [");
- }
- else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))
- {
- printf (", \"content\": [{");
+ } else if (GMIME_IS_MULTIPART (node->part)) {
+ sp->map_key (sp, "content");
+ sp->begin_list (sp);
+ nclose = 1;
+ } else if (GMIME_IS_MESSAGE (node->part)) {
+ sp->map_key (sp, "content");
+ sp->begin_list (sp);
+ sp->begin_map (sp);
+
+ sp->map_key (sp, "headers");
+ format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);
+
+ sp->map_key (sp, "body");
+ sp->begin_list (sp);
+ nclose = 3;
}
- talloc_free (ctx);
- if (stream_memory)
- g_object_unref (stream_memory);
+ for (i = 0; i < node->nchildren; i++)
+ format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE);
+
+ /* Close content structures */
+ for (i = 0; i < nclose; i++)
+ sp->end (sp);
+ /* Close part map */
+ sp->end (sp);
}
-static void
-format_part_end_json (GMimeObject *part)
+static notmuch_status_t
+format_part_json_entry (const void *ctx, sprinter_t *sp,
+ mime_node_t *node, unused (int indent),
+ const notmuch_show_params_t *params)
{
- GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
+ format_part_json (ctx, sp, node, TRUE, params->output_body);
- if (g_mime_content_type_is_type (content_type, "multipart", "*"))
- printf ("]");
- else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))
- printf ("}]");
+ return NOTMUCH_STATUS_SUCCESS;
+}
- printf ("}");
+/* Print a message in "mboxrd" format as documented, for example,
+ * here:
+ *
+ * http://qmail.org/qmail-manual-html/man5/mbox.html
+ */
+static notmuch_status_t
+format_part_mbox (const void *ctx, unused (sprinter_t *sp), mime_node_t *node,
+ unused (int indent),
+ unused (const notmuch_show_params_t *params))
+{
+ notmuch_message_t *message = node->envelope_file;
+
+ const char *filename;
+ FILE *file;
+ const char *from;
+
+ time_t date;
+ struct tm date_gmtime;
+ char date_asctime[26];
+
+ char *line = NULL;
+ size_t line_size;
+ ssize_t line_len;
+
+ if (!message)
+ INTERNAL_ERROR ("format_part_mbox requires a root part");
+
+ filename = notmuch_message_get_filename (message);
+ file = fopen (filename, "r");
+ if (file == NULL) {
+ fprintf (stderr, "Failed to open %s: %s\n",
+ filename, strerror (errno));
+ return NOTMUCH_STATUS_FILE_ERROR;
+ }
+
+ from = notmuch_message_get_header (message, "from");
+ from = _extract_email_address (ctx, from);
+
+ date = notmuch_message_get_date (message);
+ gmtime_r (&date, &date_gmtime);
+ asctime_r (&date_gmtime, date_asctime);
+
+ printf ("From %s %s", from, date_asctime);
+
+ while ((line_len = getline (&line, &line_size, file)) != -1 ) {
+ if (_is_from_line (line))
+ putchar ('>');
+ printf ("%s", line);
+ }
+
+ printf ("\n");
+
+ fclose (file);
+
+ return NOTMUCH_STATUS_SUCCESS;
}
-static void
-format_part_content_raw (GMimeObject *part)
+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))
{
- if (! GMIME_IS_PART (part))
- return;
+ if (node->envelope_file) {
+ /* Special case the entire message to avoid MIME parsing. */
+ const char *filename;
+ FILE *file;
+ size_t size;
+ char buf[4096];
+
+ filename = notmuch_message_get_filename (node->envelope_file);
+ if (filename == NULL) {
+ fprintf (stderr, "Error: Cannot get message filename.\n");
+ return NOTMUCH_STATUS_FILE_ERROR;
+ }
+
+ file = fopen (filename, "r");
+ if (file == NULL) {
+ fprintf (stderr, "Error: Cannot open file %s: %s\n", filename, strerror (errno));
+ return NOTMUCH_STATUS_FILE_ERROR;
+ }
+
+ while (!feof (file)) {
+ size = fread (buf, 1, sizeof (buf), file);
+ if (ferror (file)) {
+ fprintf (stderr, "Error: Read failed from %s\n", filename);
+ fclose (file);
+ return NOTMUCH_STATUS_FILE_ERROR;
+ }
+
+ if (fwrite (buf, size, 1, stdout) != 1) {
+ fprintf (stderr, "Error: Write failed\n");
+ fclose (file);
+ return NOTMUCH_STATUS_FILE_ERROR;
+ }
+ }
+
+ fclose (file);
+ return NOTMUCH_STATUS_SUCCESS;
+ }
GMimeStream *stream_stdout;
GMimeStream *stream_filter = NULL;
- GMimeDataWrapper *wrapper;
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);
- wrapper = g_mime_part_get_content_object (GMIME_PART (part));
+ if (GMIME_IS_PART (node->part)) {
+ /* For leaf parts, we emit only the transfer-decoded
+ * body. */
+ GMimeDataWrapper *wrapper;
+ wrapper = g_mime_part_get_content_object (GMIME_PART (node->part));
- if (wrapper && stream_filter)
- g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
+ if (wrapper && stream_filter)
+ g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
+ } else {
+ /* Write out the whole part. For message parts (the root
+ * part and embedded message parts), this will be the
+ * message including its headers (but not the
+ * encapsulating part's headers). For multipart parts,
+ * this will include the headers. */
+ if (stream_filter)
+ g_mime_object_write_to_stream (node->part, stream_filter);
+ }
if (stream_filter)
g_object_unref (stream_filter);
if (stream_stdout)
g_object_unref(stream_stdout);
+
+ return NOTMUCH_STATUS_SUCCESS;
}
-static void
+static notmuch_status_t
show_message (void *ctx,
const notmuch_show_format_t *format,
+ sprinter_t *sp,
notmuch_message_t *message,
int indent,
notmuch_show_params_t *params)
{
- if (params->part <= 0) {
- fputs (format->message_start, stdout);
- if (format->message)
- format->message(ctx, message, indent);
-
- fputs (format->header_start, stdout);
- if (format->header)
- format->header(ctx, message);
- fputs (format->header_end, stdout);
-
- fputs (format->body_start, stdout);
- }
+ void *local = talloc_new (ctx);
+ mime_node_t *root, *part;
+ notmuch_status_t status;
- if (format->part_content)
- show_message_body (message, format, params);
-
- if (params->part <= 0) {
- fputs (format->body_end, stdout);
-
- fputs (format->message_end, stdout);
- }
+ status = mime_node_open (local, message, &(params->crypto), &root);
+ if (status)
+ goto DONE;
+ part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));
+ if (part)
+ status = format->part (local, sp, part, indent, params);
+ DONE:
+ talloc_free (local);
+ return status;
}
-static void
+static notmuch_status_t
show_messages (void *ctx,
const notmuch_show_format_t *format,
+ sprinter_t *sp,
notmuch_messages_t *messages,
int indent,
notmuch_show_params_t *params)
{
notmuch_message_t *message;
notmuch_bool_t match;
- int first_set = 1;
+ notmuch_bool_t excluded;
int next_indent;
+ notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
- fputs (format->message_set_start, stdout);
+ sp->begin_list (sp);
for (;
notmuch_messages_valid (messages);
notmuch_messages_move_to_next (messages))
{
- if (!first_set)
- fputs (format->message_set_sep, stdout);
- first_set = 0;
-
- fputs (format->message_set_start, stdout);
+ sp->begin_list (sp);
message = notmuch_messages_get (messages);
match = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH);
+ excluded = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED);
next_indent = indent;
- if (match || params->entire_thread) {
- show_message (ctx, format, message, indent, params);
+ if ((match && (!excluded || !params->omit_excluded)) || params->entire_thread) {
+ status = show_message (ctx, format, sp, message, indent, params);
+ if (status && !res)
+ res = status;
next_indent = indent + 1;
-
- fputs (format->message_set_sep, stdout);
+ } else {
+ sp->null (sp);
}
- show_messages (ctx,
- format,
- notmuch_message_get_replies (message),
- next_indent,
- params);
+ status = show_messages (ctx,
+ format, sp,
+ notmuch_message_get_replies (message),
+ next_indent,
+ params);
+ if (status && !res)
+ res = status;
notmuch_message_destroy (message);
- fputs (format->message_set_end, stdout);
+ sp->end (sp);
}
- fputs (format->message_set_end, stdout);
+ sp->end (sp);
+
+ return res;
}
/* Formatted output of single message */
@@ -841,6 +921,7 @@ static int
do_show_single (void *ctx,
notmuch_query_t *query,
const notmuch_show_format_t *format,
+ sprinter_t *sp,
notmuch_show_params_t *params)
{
notmuch_messages_t *messages;
@@ -861,40 +942,8 @@ do_show_single (void *ctx,
notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH, 1);
- /* Special case for --format=raw of full single message, just cat out file */
- if (params->raw && 0 == params->part) {
-
- const char *filename;
- FILE *file;
- size_t size;
- char buf[4096];
-
- filename = notmuch_message_get_filename (message);
- if (filename == NULL) {
- fprintf (stderr, "Error: Cannot message filename.\n");
- return 1;
- }
-
- file = fopen (filename, "r");
- if (file == NULL) {
- fprintf (stderr, "Error: Cannot open file %s: %s\n", filename, strerror (errno));
- return 1;
- }
-
- while (!feof (file)) {
- size = fread (buf, 1, sizeof (buf), file);
- (void) fwrite (buf, size, 1, stdout);
- }
-
- fclose (file);
-
- } else {
-
- show_message (ctx, format, message, 0, params);
-
- }
-
- return 0;
+ return show_message (ctx, format, sp, message, 0, params)
+ != NOTMUCH_STATUS_SUCCESS;
}
/* Formatted output of threads */
@@ -902,14 +951,15 @@ static int
do_show (void *ctx,
notmuch_query_t *query,
const notmuch_show_format_t *format,
+ sprinter_t *sp,
notmuch_show_params_t *params)
{
notmuch_threads_t *threads;
notmuch_thread_t *thread;
notmuch_messages_t *messages;
- int first_toplevel = 1;
+ notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
- fputs (format->message_set_start, stdout);
+ sp->begin_list (sp);
for (threads = notmuch_query_search_threads (query);
notmuch_threads_valid (threads);
@@ -923,21 +973,39 @@ do_show (void *ctx,
INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",
notmuch_thread_get_thread_id (thread));
- if (!first_toplevel)
- fputs (format->message_set_sep, stdout);
- first_toplevel = 0;
-
- show_messages (ctx, format, messages, 0, params);
+ status = show_messages (ctx, format, sp, messages, 0, params);
+ if (status && !res)
+ res = status;
notmuch_thread_destroy (thread);
}
- fputs (format->message_set_end, stdout);
+ sp->end (sp);
- return 0;
+ return res != NOTMUCH_STATUS_SUCCESS;
}
+enum {
+ NOTMUCH_FORMAT_NOT_SPECIFIED,
+ NOTMUCH_FORMAT_JSON,
+ NOTMUCH_FORMAT_TEXT,
+ NOTMUCH_FORMAT_MBOX,
+ NOTMUCH_FORMAT_RAW
+};
+
+enum {
+ ENTIRE_THREAD_DEFAULT,
+ ENTIRE_THREAD_TRUE,
+ ENTIRE_THREAD_FALSE,
+};
+
+/* The following is to allow future options to be added more easily */
+enum {
+ EXCLUDE_TRUE,
+ EXCLUDE_FALSE,
+};
+
int
notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
{
@@ -945,93 +1013,128 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
notmuch_database_t *notmuch;
notmuch_query_t *query;
char *query_string;
- char *opt;
+ int opt_index, ret;
const notmuch_show_format_t *format = &format_text;
- notmuch_show_params_t params;
- int mbox = 0;
- int format_specified = 0;
- int i;
+ sprinter_t *sprinter;
+ notmuch_show_params_t params = {
+ .part = -1,
+ .omit_excluded = TRUE,
+ .output_body = TRUE,
+ .crypto = {
+ .verify = FALSE,
+ .decrypt = FALSE
+ }
+ };
+ int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
+ int exclude = EXCLUDE_TRUE;
+ int entire_thread = ENTIRE_THREAD_DEFAULT;
+
+ notmuch_opt_desc_t options[] = {
+ { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
+ (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
+ { "text", NOTMUCH_FORMAT_TEXT },
+ { "mbox", NOTMUCH_FORMAT_MBOX },
+ { "raw", NOTMUCH_FORMAT_RAW },
+ { 0, 0 } } },
+ { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
+ (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
+ { "false", EXCLUDE_FALSE },
+ { 0, 0 } } },
+ { NOTMUCH_OPT_KEYWORD, &entire_thread, "entire-thread", 't',
+ (notmuch_keyword_t []){ { "true", ENTIRE_THREAD_TRUE },
+ { "false", ENTIRE_THREAD_FALSE },
+ { "", ENTIRE_THREAD_TRUE },
+ { 0, 0 } } },
+ { NOTMUCH_OPT_INT, &params.part, "part", 'p', 0 },
+ { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },
+ { NOTMUCH_OPT_BOOLEAN, &params.crypto.verify, "verify", 'v', 0 },
+ { NOTMUCH_OPT_BOOLEAN, &params.output_body, "body", 'b', 0 },
+ { 0, 0, 0, 0, 0 }
+ };
+
+ opt_index = parse_arguments (argc, argv, options, 1);
+ if (opt_index < 0) {
+ /* diagnostics already printed */
+ return 1;
+ }
- params.entire_thread = 0;
- params.raw = 0;
- params.part = -1;
- params.cryptoctx = NULL;
- params.decrypt = 0;
+ /* decryption implies verification */
+ if (params.crypto.decrypt)
+ params.crypto.verify = TRUE;
- argc--; argv++; /* skip subcommand argument */
+ if (format_sel == 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;
+ else
+ format_sel = NOTMUCH_FORMAT_TEXT;
+ }
- for (i = 0; i < argc && argv[i][0] == '-'; i++) {
- if (strcmp (argv[i], "--") == 0) {
- i++;
- break;
+ switch (format_sel) {
+ case NOTMUCH_FORMAT_JSON:
+ format = &format_json;
+ break;
+ case NOTMUCH_FORMAT_TEXT:
+ format = &format_text;
+ break;
+ case NOTMUCH_FORMAT_MBOX:
+ if (params.part > 0) {
+ fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n");
+ return 1;
}
- if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
- opt = argv[i] + sizeof ("--format=") - 1;
- if (strcmp (opt, "text") == 0) {
- format = &format_text;
- } else if (strcmp (opt, "json") == 0) {
- format = &format_json;
- params.entire_thread = 1;
- } else if (strcmp (opt, "mbox") == 0) {
- format = &format_mbox;
- mbox = 1;
- } else if (strcmp (opt, "raw") == 0) {
- format = &format_raw;
- params.raw = 1;
- } else {
- fprintf (stderr, "Invalid value for --format: %s\n", opt);
- return 1;
- }
- format_specified = 1;
- } else if (STRNCMP_LITERAL (argv[i], "--part=") == 0) {
- params.part = atoi(argv[i] + sizeof ("--part=") - 1);
- } else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {
- params.entire_thread = 1;
- } else if ((STRNCMP_LITERAL (argv[i], "--verify") == 0) ||
- (STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {
- if (params.cryptoctx == NULL) {
- GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);
- if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg")))
- fprintf (stderr, "Failed to construct gpg context.\n");
- else
- g_mime_gpg_context_set_always_trust((GMimeGpgContext*)params.cryptoctx, FALSE);
- g_object_unref (session);
- session = NULL;
- }
- if (STRNCMP_LITERAL (argv[i], "--decrypt") == 0)
- params.decrypt = 1;
+
+ 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;
+ }
+
+ /* Default is entire-thread = FALSE except for format=json. */
+ if (entire_thread == ENTIRE_THREAD_DEFAULT) {
+ if (format == &format_json)
+ entire_thread = ENTIRE_THREAD_TRUE;
+ else
+ entire_thread = ENTIRE_THREAD_FALSE;
+ }
+
+ if (!params.output_body) {
+ if (params.part > 0) {
+ fprintf (stderr, "Warning: --body=false is incompatible with --part > 0. Disabling.\n");
+ params.output_body = TRUE;
} else {
- fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
- return 1;
+ if (format != &format_json)
+ fprintf (stderr, "Warning: --body=false only implemented for format=json\n");
}
}
- argc -= i;
- argv += i;
+ if (entire_thread == ENTIRE_THREAD_TRUE)
+ params.entire_thread = TRUE;
+ else
+ params.entire_thread = FALSE;
config = notmuch_config_open (ctx, NULL, NULL);
if (config == NULL)
return 1;
- query_string = query_string_from_args (ctx, argc, argv);
+ query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
return 1;
}
- if (mbox && params.part > 0) {
- fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n");
- return 1;
- }
-
if (*query_string == '\0') {
fprintf (stderr, "Error: notmuch show requires at least one search term.\n");
return 1;
}
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY);
- if (notmuch == NULL)
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
return 1;
query = notmuch_query_create (notmuch, query_string);
@@ -1040,25 +1143,36 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
return 1;
}
- /* if part was requested and format was not specified, use format=raw */
- if (params.part >= 0 && !format_specified)
- format = &format_raw;
-
- /* If --format=raw specified without specifying part, we can only
- * output single message, so set part=0 */
- if (params.raw && params.part < 0)
- params.part = 0;
+ /* Create structure printer. */
+ sprinter = format->new_sprinter(ctx, stdout);
+ /* If a single message is requested we do not use search_excludes. */
if (params.part >= 0)
- return do_show_single (ctx, query, format, &params);
- else
- return do_show (ctx, query, format, &params);
+ ret = do_show_single (ctx, query, format, sprinter, &params);
+ 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;
+
+ 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]);
+
+ if (exclude == EXCLUDE_FALSE) {
+ notmuch_query_set_omit_excluded (query, FALSE);
+ params.omit_excluded = FALSE;
+ }
- notmuch_query_destroy (query);
- notmuch_database_close (notmuch);
+ ret = do_show (ctx, query, format, sprinter, &params);
+ }
- if (params.cryptoctx)
- g_object_unref(params.cryptoctx);
+ notmuch_crypto_cleanup (&params.crypto);
+ notmuch_query_destroy (query);
+ notmuch_database_destroy (notmuch);
- return 0;
+ return ret;
}
diff --git a/notmuch-tag.c b/notmuch-tag.c
index 292c5da..7d18639 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -26,7 +26,12 @@ static void
handle_sigint (unused (int sig))
{
static char msg[] = "Stopping... \n";
- (void) write(2, msg, sizeof(msg)-1);
+
+ /* This write is "opportunistic", so it's okay to ignore the
+ * result. It is not required for correctness, and if it does
+ * fail or produce a short write, we want to get out of the signal
+ * handler as quickly as possible, not retry it. */
+ IGNORE_RESULT (write (2, msg, sizeof(msg)-1));
interrupted = 1;
}
@@ -48,10 +53,14 @@ _escape_tag (char *buf, const char *tag)
return buf;
}
+typedef struct {
+ const char *tag;
+ notmuch_bool_t remove;
+} tag_operation_t;
+
static char *
-_optimize_tag_query (void *ctx, const char *orig_query_string, char *argv[],
- int *add_tags, int add_tags_count,
- int *remove_tags, int remove_tags_count)
+_optimize_tag_query (void *ctx, const char *orig_query_string,
+ const tag_operation_t *tag_ops)
{
/* This is subtler than it looks. Xapian ignores the '-' operator
* at the beginning both queries and parenthesized groups and,
@@ -66,15 +75,16 @@ _optimize_tag_query (void *ctx, const char *orig_query_string, char *argv[],
int i;
unsigned int max_tag_len = 0;
+ /* Don't optimize if there are no tag changes. */
+ if (tag_ops[0].tag == NULL)
+ return talloc_strdup (ctx, orig_query_string);
+
/* Allocate a buffer for escaping tags. This is large enough to
* hold a fully escaped tag with every character doubled plus
* enclosing quotes and a NUL. */
- for (i = 0; i < add_tags_count; i++)
- if (strlen (argv[add_tags[i]] + 1) > max_tag_len)
- max_tag_len = strlen (argv[add_tags[i]] + 1);
- for (i = 0; i < remove_tags_count; i++)
- if (strlen (argv[remove_tags[i]] + 1) > max_tag_len)
- max_tag_len = strlen (argv[remove_tags[i]] + 1);
+ for (i = 0; tag_ops[i].tag; i++)
+ if (strlen (tag_ops[i].tag) > max_tag_len)
+ max_tag_len = strlen (tag_ops[i].tag);
escaped = talloc_array(ctx, char, max_tag_len * 2 + 3);
if (!escaped)
return NULL;
@@ -85,16 +95,11 @@ _optimize_tag_query (void *ctx, const char *orig_query_string, char *argv[],
else
query_string = talloc_asprintf (ctx, "( %s ) and (", orig_query_string);
- for (i = 0; i < add_tags_count && query_string; i++) {
- query_string = talloc_asprintf_append_buffer (
- query_string, "%snot tag:%s", join,
- _escape_tag (escaped, argv[add_tags[i]] + 1));
- join = " or ";
- }
- for (i = 0; i < remove_tags_count && query_string; i++) {
+ for (i = 0; tag_ops[i].tag && query_string; i++) {
query_string = talloc_asprintf_append_buffer (
- query_string, "%stag:%s", join,
- _escape_tag (escaped, argv[remove_tags[i]] + 1));
+ query_string, "%s%stag:%s", join,
+ tag_ops[i].remove ? "" : "not ",
+ _escape_tag (escaped, tag_ops[i].tag));
join = " or ";
}
@@ -105,21 +110,75 @@ _optimize_tag_query (void *ctx, const char *orig_query_string, char *argv[],
return query_string;
}
+/* Tag messages matching 'query_string' according to 'tag_ops', which
+ * must be an array of tagging operations terminated with an empty
+ * element. */
+static int
+tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
+ tag_operation_t *tag_ops, notmuch_bool_t synchronize_flags)
+{
+ notmuch_query_t *query;
+ notmuch_messages_t *messages;
+ notmuch_message_t *message;
+ int i;
+
+ /* Optimize the query so it excludes messages that already have
+ * the specified set of tags. */
+ query_string = _optimize_tag_query (ctx, query_string, tag_ops);
+ if (query_string == NULL) {
+ fprintf (stderr, "Out of memory.\n");
+ return 1;
+ }
+
+ query = notmuch_query_create (notmuch, query_string);
+ if (query == NULL) {
+ fprintf (stderr, "Out of memory.\n");
+ return 1;
+ }
+
+ /* tagging is not interested in any special sort order */
+ notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
+
+ for (messages = notmuch_query_search_messages (query);
+ notmuch_messages_valid (messages) && !interrupted;
+ notmuch_messages_move_to_next (messages))
+ {
+ message = notmuch_messages_get (messages);
+
+ notmuch_message_freeze (message);
+
+ for (i = 0; tag_ops[i].tag; i++) {
+ if (tag_ops[i].remove)
+ notmuch_message_remove_tag (message, tag_ops[i].tag);
+ else
+ notmuch_message_add_tag (message, tag_ops[i].tag);
+ }
+
+ notmuch_message_thaw (message);
+
+ if (synchronize_flags)
+ notmuch_message_tags_to_maildir_flags (message);
+
+ notmuch_message_destroy (message);
+ }
+
+ notmuch_query_destroy (query);
+
+ return interrupted;
+}
+
int
-notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
+notmuch_tag_command (void *ctx, int argc, char *argv[])
{
- int *add_tags, *remove_tags;
- int add_tags_count = 0;
- int remove_tags_count = 0;
+ tag_operation_t *tag_ops;
+ int tag_ops_count = 0;
char *query_string;
notmuch_config_t *config;
notmuch_database_t *notmuch;
- notmuch_query_t *query;
- notmuch_messages_t *messages;
- notmuch_message_t *message;
struct sigaction action;
notmuch_bool_t synchronize_flags;
int i;
+ int ret;
/* Setup our handler for SIGINT */
memset (&action, 0, sizeof (struct sigaction));
@@ -128,35 +187,33 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
action.sa_flags = SA_RESTART;
sigaction (SIGINT, &action, NULL);
- add_tags = talloc_size (ctx, argc * sizeof (int));
- if (add_tags == NULL) {
- fprintf (stderr, "Out of memory.\n");
- return 1;
- }
+ argc--; argv++; /* skip subcommand argument */
- remove_tags = talloc_size (ctx, argc * sizeof (int));
- if (remove_tags == NULL) {
+ /* Array of tagging operations (add or remove), terminated with an
+ * empty element. */
+ tag_ops = talloc_array (ctx, tag_operation_t, argc + 1);
+ if (tag_ops == NULL) {
fprintf (stderr, "Out of memory.\n");
return 1;
}
- argc--; argv++; /* skip subcommand argument */
-
for (i = 0; i < argc; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
break;
}
- if (argv[i][0] == '+') {
- add_tags[add_tags_count++] = i;
- } else if (argv[i][0] == '-') {
- remove_tags[remove_tags_count++] = i;
+ if (argv[i][0] == '+' || argv[i][0] == '-') {
+ tag_ops[tag_ops_count].tag = argv[i] + 1;
+ tag_ops[tag_ops_count].remove = (argv[i][0] == '-');
+ tag_ops_count++;
} else {
break;
}
}
- if (add_tags_count == 0 && remove_tags_count == 0) {
+ tag_ops[tag_ops_count].tag = NULL;
+
+ if (tag_ops_count == 0) {
fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");
return 1;
}
@@ -168,61 +225,19 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
return 1;
}
- /* Optimize the query so it excludes messages that already have
- * the specified set of tags. */
- query_string = _optimize_tag_query (ctx, query_string, argv,
- add_tags, add_tags_count,
- remove_tags, remove_tags_count);
- if (query_string == NULL) {
- fprintf (stderr, "Out of memory.\n");
- return 1;
- }
-
config = notmuch_config_open (ctx, NULL, NULL);
if (config == NULL)
return 1;
- notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_WRITE);
- if (notmuch == NULL)
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
return 1;
synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
- query = notmuch_query_create (notmuch, query_string);
- if (query == NULL) {
- fprintf (stderr, "Out of memory.\n");
- return 1;
- }
-
- /* tagging is not interested in any special sort order */
- notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
-
- for (messages = notmuch_query_search_messages (query);
- notmuch_messages_valid (messages) && !interrupted;
- notmuch_messages_move_to_next (messages))
- {
- message = notmuch_messages_get (messages);
-
- notmuch_message_freeze (message);
-
- for (i = 0; i < remove_tags_count; i++)
- notmuch_message_remove_tag (message,
- argv[remove_tags[i]] + 1);
-
- for (i = 0; i < add_tags_count; i++)
- notmuch_message_add_tag (message, argv[add_tags[i]] + 1);
-
- notmuch_message_thaw (message);
-
- if (synchronize_flags)
- notmuch_message_tags_to_maildir_flags (message);
-
- notmuch_message_destroy (message);
- }
+ ret = tag_query (ctx, notmuch, query_string, tag_ops, synchronize_flags);
- notmuch_query_destroy (query);
- notmuch_database_close (notmuch);
+ notmuch_database_destroy (notmuch);
- return interrupted;
+ return ret;
}
diff --git a/show-message.c b/show-message.c
deleted file mode 100644
index 8768889..0000000
--- a/show-message.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/* notmuch - Not much of an email program, (just index and search)
- *
- * Copyright © 2009 Carl Worth
- * Copyright © 2009 Keith Packard
- *
- * 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 http://www.gnu.org/licenses/ .
- *
- * Authors: Carl Worth <cworth@cworth.org>
- * Keith Packard <keithp@keithp.com>
- */
-
-#include "notmuch-client.h"
-
-typedef struct show_message_state {
- int part_count;
-} show_message_state_t;
-
-static void
-show_message_part (mime_node_t *node,
- show_message_state_t *state,
- const notmuch_show_format_t *format,
- int first)
-{
- /* Formatters expect the envelope for embedded message parts */
- GMimeObject *part = node->envelope_part ?
- GMIME_OBJECT (node->envelope_part) : node->part;
- int i;
-
- if (!first)
- fputs (format->part_sep, stdout);
-
- /* Format this part */
- if (format->part_start)
- format->part_start (part, &(state->part_count));
-
- if (node->decrypt_attempted && format->part_encstatus)
- format->part_encstatus (node->decrypt_success);
-
- if (node->verify_attempted && format->part_sigstatus)
- format->part_sigstatus (node->sig_validity);
-
- format->part_content (part);
-
- if (node->envelope_part) {
- fputs (format->header_start, stdout);
- if (format->header_message_part)
- format->header_message_part (GMIME_MESSAGE (node->part));
- fputs (format->header_end, stdout);
-
- fputs (format->body_start, stdout);
- }
-
- /* Recurse over the children */
- state->part_count += 1;
- for (i = 0; i < node->nchildren; i++)
- show_message_part (mime_node_child (node, i), state, format, i == 0);
-
- /* Finish this part */
- if (node->envelope_part)
- fputs (format->body_end, stdout);
-
- if (format->part_end)
- format->part_end (part);
-}
-
-notmuch_status_t
-show_message_body (notmuch_message_t *message,
- const notmuch_show_format_t *format,
- notmuch_show_params_t *params)
-{
- notmuch_status_t ret;
- show_message_state_t state;
- mime_node_t *root, *part;
-
- ret = mime_node_open (NULL, message, params->cryptoctx, params->decrypt,
- &root);
- if (ret)
- return ret;
-
- /* The caller of show_message_body has already handled the
- * outermost envelope, so skip it. */
- state.part_count = MAX (params->part, 1);
-
- part = mime_node_seek_dfs (root, state.part_count);
- if (part)
- show_message_part (part, &state, format, TRUE);
-
- talloc_free (root);
-
- return NOTMUCH_STATUS_SUCCESS;
-}
diff --git a/sprinter-json.c b/sprinter-json.c
new file mode 100644
index 0000000..c9b6835
--- /dev/null
+++ b/sprinter-json.c
@@ -0,0 +1,199 @@
+#include <stdbool.h>
+#include <stdio.h>
+#include <talloc.h>
+#include "sprinter.h"
+
+struct sprinter_json {
+ struct sprinter vtable;
+ FILE *stream;
+ /* Top of the state stack, or NULL if the printer is not currently
+ * inside any aggregate types. */
+ struct json_state *state;
+
+ /* A flag to signify that a separator should be inserted in the
+ * output as soon as possible.
+ */
+ notmuch_bool_t insert_separator;
+};
+
+struct json_state {
+ struct json_state *parent;
+ /* True if nothing has been printed in this aggregate yet.
+ * Suppresses the comma before a value. */
+ notmuch_bool_t first;
+ /* The character that closes the current aggregate. */
+ char close;
+};
+
+/* Helper function to set up the stream to print a value. If this
+ * value follows another value, prints a comma. */
+static struct sprinter_json *
+json_begin_value (struct sprinter *sp)
+{
+ struct sprinter_json *spj = (struct sprinter_json *) sp;
+
+ if (spj->state) {
+ if (! spj->state->first) {
+ fputc (',', spj->stream);
+ if (spj->insert_separator) {
+ fputc ('\n', spj->stream);
+ spj->insert_separator = FALSE;
+ } else {
+ fputc (' ', spj->stream);
+ }
+ } else {
+ spj->state->first = FALSE;
+ }
+ }
+ return spj;
+}
+
+/* Helper function to begin an aggregate type. Prints the open
+ * character and pushes a new state frame. */
+static void
+json_begin_aggregate (struct sprinter *sp, char open, char close)
+{
+ struct sprinter_json *spj = json_begin_value (sp);
+ struct json_state *state = talloc (spj, struct json_state);
+
+ fputc (open, spj->stream);
+ state->parent = spj->state;
+ state->first = TRUE;
+ state->close = close;
+ spj->state = state;
+}
+
+static void
+json_begin_map (struct sprinter *sp)
+{
+ json_begin_aggregate (sp, '{', '}');
+}
+
+static void
+json_begin_list (struct sprinter *sp)
+{
+ json_begin_aggregate (sp, '[', ']');
+}
+
+static void
+json_end (struct sprinter *sp)
+{
+ struct sprinter_json *spj = (struct sprinter_json *) sp;
+ struct json_state *state = spj->state;
+
+ fputc (spj->state->close, spj->stream);
+ spj->state = state->parent;
+ talloc_free (state);
+ if (spj->state == NULL)
+ fputc ('\n', spj->stream);
+}
+
+/* This implementation supports embedded NULs as allowed by the JSON
+ * specification and Unicode. Support for *parsing* embedded NULs
+ * varies, but is generally not a problem outside of C-based parsers
+ * (Python's json module and Emacs' json.el take embedded NULs in
+ * stride). */
+static void
+json_string_len (struct sprinter *sp, const char *val, size_t len)
+{
+ static const char *const escapes[] = {
+ ['\"'] = "\\\"", ['\\'] = "\\\\", ['\b'] = "\\b",
+ ['\f'] = "\\f", ['\n'] = "\\n", ['\t'] = "\\t"
+ };
+ struct sprinter_json *spj = json_begin_value (sp);
+
+ fputc ('"', spj->stream);
+ for (; len; ++val, --len) {
+ unsigned char ch = *val;
+ if (ch < ARRAY_SIZE (escapes) && escapes[ch])
+ fputs (escapes[ch], spj->stream);
+ else if (ch >= 32)
+ fputc (ch, spj->stream);
+ else
+ fprintf (spj->stream, "\\u%04x", ch);
+ }
+ fputc ('"', spj->stream);
+}
+
+static void
+json_string (struct sprinter *sp, const char *val)
+{
+ json_string_len (sp, val, strlen (val));
+}
+
+static void
+json_integer (struct sprinter *sp, int val)
+{
+ struct sprinter_json *spj = json_begin_value (sp);
+
+ fprintf (spj->stream, "%d", val);
+}
+
+static void
+json_boolean (struct sprinter *sp, notmuch_bool_t val)
+{
+ struct sprinter_json *spj = json_begin_value (sp);
+
+ fputs (val ? "true" : "false", spj->stream);
+}
+
+static void
+json_null (struct sprinter *sp)
+{
+ struct sprinter_json *spj = json_begin_value (sp);
+
+ fputs ("null", spj->stream);
+}
+
+static void
+json_map_key (struct sprinter *sp, const char *key)
+{
+ struct sprinter_json *spj = (struct sprinter_json *) sp;
+
+ json_string (sp, key);
+ fputs (": ", spj->stream);
+ spj->state->first = TRUE;
+}
+
+static void
+json_set_prefix (unused (struct sprinter *sp), unused (const char *name))
+{
+}
+
+static void
+json_separator (struct sprinter *sp)
+{
+ struct sprinter_json *spj = (struct sprinter_json *) sp;
+
+ spj->insert_separator = TRUE;
+}
+
+struct sprinter *
+sprinter_json_create (const void *ctx, FILE *stream)
+{
+ static const struct sprinter_json template = {
+ .vtable = {
+ .begin_map = json_begin_map,
+ .begin_list = json_begin_list,
+ .end = json_end,
+ .string = json_string,
+ .string_len = json_string_len,
+ .integer = json_integer,
+ .boolean = json_boolean,
+ .null = json_null,
+ .map_key = json_map_key,
+ .separator = json_separator,
+ .set_prefix = json_set_prefix,
+ .is_text_printer = FALSE,
+ }
+ };
+ struct sprinter_json *res;
+
+ res = talloc (ctx, struct sprinter_json);
+ if (! res)
+ return NULL;
+
+ *res = template;
+ res->stream = stream;
+ return &res->vtable;
+}
diff --git a/sprinter-text.c b/sprinter-text.c
new file mode 100644
index 0000000..dfa54b5
--- /dev/null
+++ b/sprinter-text.c
@@ -0,0 +1,133 @@
+#include <stdbool.h>
+#include <stdio.h>
+#include <talloc.h>
+#include "sprinter.h"
+
+/* "Structured printer" interface for unstructured text printing.
+ * Note that --output=summary is dispatched and formatted in
+ * notmuch-search.c, the code in this file is only used for all other
+ * output types.
+ */
+
+struct sprinter_text {
+ struct sprinter vtable;
+ FILE *stream;
+
+ /* The current prefix to be printed with string/integer/boolean
+ * data.
+ */
+ const char *current_prefix;
+
+ /* A flag to indicate if this is the first tag. Used in list of tags
+ * for summary.
+ */
+ notmuch_bool_t first_tag;
+};
+
+static void
+text_string_len (struct sprinter *sp, const char *val, size_t len)
+{
+ struct sprinter_text *sptxt = (struct sprinter_text *) sp;
+
+ if (sptxt->current_prefix != NULL)
+ fprintf (sptxt->stream, "%s:", sptxt->current_prefix);
+
+ fwrite (val, len, 1, sptxt->stream);
+}
+
+static void
+text_string (struct sprinter *sp, const char *val)
+{
+ text_string_len (sp, val, strlen (val));
+}
+
+static void
+text_integer (struct sprinter *sp, int val)
+{
+ struct sprinter_text *sptxt = (struct sprinter_text *) sp;
+
+ fprintf (sptxt->stream, "%d", val);
+}
+
+static void
+text_boolean (struct sprinter *sp, notmuch_bool_t val)
+{
+ struct sprinter_text *sptxt = (struct sprinter_text *) sp;
+
+ fputs (val ? "true" : "false", sptxt->stream);
+}
+
+static void
+text_separator (struct sprinter *sp)
+{
+ struct sprinter_text *sptxt = (struct sprinter_text *) sp;
+
+ fputc ('\n', sptxt->stream);
+}
+
+static void
+text_set_prefix (struct sprinter *sp, const char *prefix)
+{
+ struct sprinter_text *sptxt = (struct sprinter_text *) sp;
+
+ sptxt->current_prefix = prefix;
+}
+
+/* The structure functions begin_map, begin_list, end and map_key
+ * don't do anything in the text formatter.
+ */
+
+static void
+text_begin_map (unused (struct sprinter *sp))
+{
+}
+
+static void
+text_begin_list (unused (struct sprinter *sp))
+{
+}
+
+static void
+text_end (unused (struct sprinter *sp))
+{
+}
+
+static void
+text_null (unused (struct sprinter *sp))
+{
+}
+
+static void
+text_map_key (unused (struct sprinter *sp), unused (const char *key))
+{
+}
+
+struct sprinter *
+sprinter_text_create (const void *ctx, FILE *stream)
+{
+ static const struct sprinter_text template = {
+ .vtable = {
+ .begin_map = text_begin_map,
+ .begin_list = text_begin_list,
+ .end = text_end,
+ .string = text_string,
+ .string_len = text_string_len,
+ .integer = text_integer,
+ .boolean = text_boolean,
+ .null = text_null,
+ .map_key = text_map_key,
+ .separator = text_separator,
+ .set_prefix = text_set_prefix,
+ .is_text_printer = TRUE,
+ },
+ };
+ struct sprinter_text *res;
+
+ res = talloc (ctx, struct sprinter_text);
+ if (! res)
+ return NULL;
+
+ *res = template;
+ res->stream = stream;
+ return &res->vtable;
+}
diff --git a/sprinter.h b/sprinter.h
new file mode 100644
index 0000000..5f43175
--- /dev/null
+++ b/sprinter.h
@@ -0,0 +1,71 @@
+#ifndef NOTMUCH_SPRINTER_H
+#define NOTMUCH_SPRINTER_H
+
+/* Necessary for notmuch_bool_t */
+#include "notmuch-client.h"
+
+/* Structure printer interface. This is used to create output
+ * structured as maps (with key/value pairs), lists and primitives
+ * (strings, integers and booleans).
+ */
+typedef struct sprinter {
+ /* Start a new map/dictionary structure. This should be followed by
+ * a sequence of alternating calls to map_key and one of the
+ * value-printing functions until the map is ended by end.
+ */
+ void (*begin_map) (struct sprinter *);
+
+ /* Start a new list/array structure.
+ */
+ void (*begin_list) (struct sprinter *);
+
+ /* End the last opened list or map structure.
+ */
+ void (*end) (struct sprinter *);
+
+ /* Print one string/integer/boolean/null element (possibly inside
+ * a list or map, followed or preceded by separators). For string
+ * and string_len, the char * must be UTF-8 encoded. string_len
+ * allows non-terminated strings and strings with embedded NULs
+ * (though the handling of the latter is format-dependent).
+ */
+ void (*string) (struct sprinter *, const char *);
+ void (*string_len) (struct sprinter *, const char *, size_t);
+ void (*integer) (struct sprinter *, int);
+ void (*boolean) (struct sprinter *, notmuch_bool_t);
+ void (*null) (struct sprinter *);
+
+ /* Print the key of a map's key/value pair. The char * must be UTF-8
+ * encoded.
+ */
+ void (*map_key) (struct sprinter *, const char *);
+
+ /* Insert a separator (usually extra whitespace) for improved
+ * readability without affecting the abstract syntax of the
+ * structure being printed.
+ * For JSON, this could simply be a line break.
+ */
+ void (*separator) (struct sprinter *);
+
+ /* Set the current string prefix. This only affects the text
+ * printer, which will print this string, followed by a colon,
+ * before any string. For other printers, this does nothing.
+ */
+ void (*set_prefix) (struct sprinter *, const char *);
+
+ /* True if this is the special-cased plain text printer.
+ */
+ notmuch_bool_t is_text_printer;
+} sprinter_t;
+
+
+/* Create a new unstructured printer that emits the default text format
+ * for "notmuch search". */
+struct sprinter *
+sprinter_text_create (const void *ctx, FILE *stream);
+
+/* Create a new structure printer that emits JSON. */
+struct sprinter *
+sprinter_json_create (const void *ctx, FILE *stream);
+
+#endif // NOTMUCH_SPRINTER_H
diff --git a/test/Makefile.local b/test/Makefile.local
index fa2df73..c7f1435 100644
--- a/test/Makefile.local
+++ b/test/Makefile.local
@@ -28,6 +28,8 @@ test: all test-binaries
check: test
+SRCS := $(SRCS) $(smtp_dummy_srcs)
CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
$(dir)/symbol-test $(dir)/symbol-test.o \
- $(dir)/arg-test $(dir)/arg-test.o
+ $(dir)/arg-test $(dir)/arg-test.o \
+ $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*
diff --git a/test/README b/test/README
index bde6db0..43656a3 100644
--- a/test/README
+++ b/test/README
@@ -6,6 +6,19 @@ When fixing bugs or enhancing notmuch, you are strongly encouraged to
add tests in this directory to cover what you are trying to fix or
enhance.
+Prerequisites
+-------------
+Some tests require external dependencies to run. Without them, they
+will be skipped, or (rarely) marked failed. Please install these, so
+that you know if you break anything.
+
+ - dtach(1)
+ - emacs(1)
+ - emacsclient(1)
+ - gdb(1)
+ - gpg(1)
+ - python(1)
+
Running Tests
-------------
The easiest way to run tests is to say "make test", (or simply run the
@@ -189,6 +202,14 @@ library for your script to use.
tests that may run in the same Emacs instance. Use `let' instead
so the scope of the changed variables is limited to a single test.
+ test_emacs_expect_t <emacs-lisp-expressions>
+
+ This function executes the provided emacs lisp script within
+ emacs in a manner similar to 'test_emacs'. The expressions should
+ return the value `t' to indicate that the test has passed. If the
+ test does not return `t' then it is considered failed and all data
+ returned by the test is reported to the tester.
+
test_done
Your test script must have test_done at the end. Its purpose
diff --git a/test/config b/test/config
new file mode 100755
index 0000000..93ecb13
--- /dev/null
+++ b/test/config
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+
+test_description='"notmuch config"'
+. test-lib.sh
+
+test_begin_subtest "Get string value"
+test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"
+
+test_begin_subtest "Get list value"
+test_expect_equal "$(notmuch config get new.tags)" "\
+unread
+inbox"
+
+test_begin_subtest "Set string value"
+notmuch config set foo.string "this is a string value"
+test_expect_equal "$(notmuch config get foo.string)" "this is a string value"
+
+test_begin_subtest "Set string value again"
+notmuch config set foo.string "this is another string value"
+test_expect_equal "$(notmuch config get foo.string)" "this is another string value"
+
+test_begin_subtest "Set list value"
+notmuch config set foo.list this "is a" "list value"
+test_expect_equal "$(notmuch config get foo.list)" "\
+this
+is a
+list value"
+
+test_begin_subtest "Set list value again"
+notmuch config set foo.list this "is another" "list value"
+test_expect_equal "$(notmuch config get foo.list)" "\
+this
+is another
+list value"
+
+test_begin_subtest "Remove key"
+notmuch config set foo.remove baz
+notmuch config set foo.remove
+test_expect_equal "$(notmuch config get foo.remove)" ""
+
+test_begin_subtest "Remove non-existent key"
+notmuch config set foo.nonexistent
+test_expect_equal "$(notmuch config get foo.nonexistent)" ""
+
+test_begin_subtest "List all items"
+notmuch config set database.path "/canonical/path"
+output=$(notmuch config list)
+test_expect_equal "$output" "\
+database.path=/canonical/path
+user.name=Notmuch Test Suite
+user.primary_email=test_suite@notmuchmail.org
+user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
+new.tags=unread;inbox;
+new.ignore=
+search.exclude_tags=
+maildir.synchronize_flags=true
+foo.string=this is another string value
+foo.list=this;is another;list value;"
+
+test_done
diff --git a/test/crypto b/test/crypto
index 0af4aa8..5dd14c4 100755
--- a/test/crypto
+++ b/test/crypto
@@ -43,6 +43,7 @@ output=$(notmuch show --format=json --verify subject:"test signed message 001" \
| sed -e 's|"created": [1234567890]*|"created": 946728000|')
expected='[[[{"id": "XXXXX",
"match": true,
+ "excluded": false,
"filename": "YYYYY",
"timestamp": 946728000,
"date_relative": "2000-01-01",
@@ -50,9 +51,7 @@ expected='[[[{"id": "XXXXX",
"headers": {"Subject": "test signed message 001",
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
"To": "test_suite@notmuchmail.org",
- "Cc": "",
- "Bcc": "",
- "Date": "01 Jan 2000 12:00:00 -0000"},
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
"body": [{"id": 1,
"sigstatus": [{"status": "good",
"fingerprint": "'$FINGERPRINT'",
@@ -64,7 +63,7 @@ expected='[[[{"id": "XXXXX",
{"id": 3,
"content-type": "application/pgp-signature"}]}]},
[]]]]'
-test_expect_equal \
+test_expect_equal_json \
"$output" \
"$expected"
@@ -77,6 +76,7 @@ output=$(notmuch show --format=json --verify subject:"test signed message 001" \
| sed -e 's|"created": [1234567890]*|"created": 946728000|')
expected='[[[{"id": "XXXXX",
"match": true,
+ "excluded": false,
"filename": "YYYYY",
"timestamp": 946728000,
"date_relative": "2000-01-01",
@@ -84,9 +84,7 @@ expected='[[[{"id": "XXXXX",
"headers": {"Subject": "test signed message 001",
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
"To": "test_suite@notmuchmail.org",
- "Cc": "",
- "Bcc": "",
- "Date": "01 Jan 2000 12:00:00 -0000"},
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
"body": [{"id": 1,
"sigstatus": [{"status": "good",
"fingerprint": "'$FINGERPRINT'",
@@ -99,7 +97,7 @@ expected='[[[{"id": "XXXXX",
{"id": 3,
"content-type": "application/pgp-signature"}]}]},
[]]]]'
-test_expect_equal \
+test_expect_equal_json \
"$output" \
"$expected"
@@ -111,6 +109,7 @@ output=$(notmuch show --format=json --verify subject:"test signed message 001" \
| sed -e 's|"created": [1234567890]*|"created": 946728000|')
expected='[[[{"id": "XXXXX",
"match": true,
+ "excluded": false,
"filename": "YYYYY",
"timestamp": 946728000,
"date_relative": "2000-01-01",
@@ -118,9 +117,7 @@ expected='[[[{"id": "XXXXX",
"headers": {"Subject": "test signed message 001",
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
"To": "test_suite@notmuchmail.org",
- "Cc": "",
- "Bcc": "",
- "Date": "01 Jan 2000 12:00:00 -0000"},
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
"body": [{"id": 1,
"sigstatus": [{"status": "error",
"keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
@@ -132,7 +129,7 @@ expected='[[[{"id": "XXXXX",
{"id": 3,
"content-type": "application/pgp-signature"}]}]},
[]]]]'
-test_expect_equal \
+test_expect_equal_json \
"$output" \
"$expected"
mv "${GNUPGHOME}"{.bak,}
@@ -151,13 +148,13 @@ test_begin_subtest "decryption, --format=text"
output=$(notmuch show --format=text --decrypt subject:"test encrypted message 001" \
| notmuch_show_sanitize_all \
| sed -e 's|"created": [1234567890]*|"created": 946728000|')
-expected=' message{ id:XXXXX depth:0 match:1 filename:XXXXX
+expected=' message{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
Subject: test encrypted message 001
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: test_suite@notmuchmail.org
-Date: 01 Jan 2000 12:00:00 -0000
+Date: Sat, 01 Jan 2000 12:00:00 +0000
header}
body{
part{ ID: 1, Content-type: multipart/encrypted
@@ -185,6 +182,7 @@ output=$(notmuch show --format=json --decrypt subject:"test encrypted message 00
| sed -e 's|"created": [1234567890]*|"created": 946728000|')
expected='[[[{"id": "XXXXX",
"match": true,
+ "excluded": false,
"filename": "YYYYY",
"timestamp": 946728000,
"date_relative": "2000-01-01",
@@ -192,9 +190,7 @@ expected='[[[{"id": "XXXXX",
"headers": {"Subject": "test encrypted message 001",
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
"To": "test_suite@notmuchmail.org",
- "Cc": "",
- "Bcc": "",
- "Date": "01 Jan 2000 12:00:00 -0000"},
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
"body": [{"id": 1,
"encstatus": [{"status": "good"}],
"sigstatus": [],
@@ -210,7 +206,7 @@ expected='[[[{"id": "XXXXX",
"content-type": "application/octet-stream",
"filename": "TESTATTACHMENT"}]}]}]},
[]]]]'
-test_expect_equal \
+test_expect_equal_json \
"$output" \
"$expected"
@@ -221,7 +217,7 @@ output=$(notmuch show --format=json --part=4 --decrypt subject:"test encrypted m
expected='{"id": 4,
"content-type": "text/plain",
"content": "This is a test encrypted message.\n"}'
-test_expect_equal \
+test_expect_equal_json \
"$output" \
"$expected"
@@ -240,6 +236,7 @@ output=$(notmuch show --format=json --decrypt subject:"test encrypted message 00
| sed -e 's|"created": [1234567890]*|"created": 946728000|')
expected='[[[{"id": "XXXXX",
"match": true,
+ "excluded": false,
"filename": "YYYYY",
"timestamp": 946728000,
"date_relative": "2000-01-01",
@@ -247,9 +244,7 @@ expected='[[[{"id": "XXXXX",
"headers": {"Subject": "test encrypted message 001",
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
"To": "test_suite@notmuchmail.org",
- "Cc": "",
- "Bcc": "",
- "Date": "01 Jan 2000 12:00:00 -0000"},
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
"body": [{"id": 1,
"encstatus": [{"status": "bad"}],
"content-type": "multipart/encrypted",
@@ -258,7 +253,7 @@ expected='[[[{"id": "XXXXX",
{"id": 3,
"content-type": "application/octet-stream"}]}]},
[]]]]'
-test_expect_equal \
+test_expect_equal_json \
"$output" \
"$expected"
mv "${GNUPGHOME}"{.bak,}
@@ -275,6 +270,7 @@ output=$(notmuch show --format=json --decrypt subject:"test encrypted message 00
| sed -e 's|"created": [1234567890]*|"created": 946728000|')
expected='[[[{"id": "XXXXX",
"match": true,
+ "excluded": false,
"filename": "YYYYY",
"timestamp": 946728000,
"date_relative": "2000-01-01",
@@ -282,9 +278,7 @@ expected='[[[{"id": "XXXXX",
"headers": {"Subject": "test encrypted message 002",
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
"To": "test_suite@notmuchmail.org",
- "Cc": "",
- "Bcc": "",
- "Date": "01 Jan 2000 12:00:00 -0000"},
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
"body": [{"id": 1,
"encstatus": [{"status": "good"}],
"sigstatus": [{"status": "good",
@@ -298,7 +292,7 @@ expected='[[[{"id": "XXXXX",
"content-type": "text/plain",
"content": "This is another test encrypted message.\n"}]}]},
[]]]]'
-test_expect_equal \
+test_expect_equal_json \
"$output" \
"$expected"
@@ -330,6 +324,7 @@ output=$(notmuch show --format=json --verify subject:"test signed message 001" \
| sed -e 's|"created": [1234567890]*|"created": 946728000|')
expected='[[[{"id": "XXXXX",
"match": true,
+ "excluded": false,
"filename": "YYYYY",
"timestamp": 946728000,
"date_relative": "2000-01-01",
@@ -337,9 +332,7 @@ expected='[[[{"id": "XXXXX",
"headers": {"Subject": "test signed message 001",
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
"To": "test_suite@notmuchmail.org",
- "Cc": "",
- "Bcc": "",
- "Date": "01 Jan 2000 12:00:00 -0000"},
+ "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
"body": [{"id": 1,
"sigstatus": [{"status": "error",
"keyid": "6D92612D94E46381",
@@ -351,7 +344,7 @@ expected='[[[{"id": "XXXXX",
{"id": 3,
"content-type": "application/pgp-signature"}]}]},
[]]]]'
-test_expect_equal \
+test_expect_equal_json \
"$output" \
"$expected"
diff --git a/test/dump-restore b/test/dump-restore
index 439e998..f25f7cf 100755
--- a/test/dump-restore
+++ b/test/dump-restore
@@ -19,7 +19,7 @@ test_expect_success 'Dumping all tags II' \
test_expect_success 'Clearing all tags' \
'sed -e "s/(\([^(]*\))$/()/" < dump.expected > clear.expected &&
- notmuch restore clear.expected &&
+ notmuch restore --input=clear.expected &&
notmuch dump > clear.actual &&
test_cmp clear.expected clear.actual'
@@ -30,7 +30,7 @@ test_expect_success 'Accumulate original tags' \
test_cmp dump-ABC_DEF.expected dump.actual'
test_expect_success 'Restoring original tags' \
- 'notmuch restore dump.expected &&
+ 'notmuch restore --input=dump.expected &&
notmuch dump > dump.actual &&
test_cmp dump.expected dump.actual'
@@ -40,7 +40,7 @@ test_expect_success 'Restore with nothing to do' \
test_cmp dump.expected dump.actual'
test_expect_success 'Restore with nothing to do, II' \
- 'notmuch restore --accumulate dump.expected &&
+ 'notmuch restore --accumulate --input=dump.expected &&
notmuch dump > dump.actual &&
test_cmp dump.expected dump.actual'
@@ -51,18 +51,14 @@ test_expect_success 'Restore with nothing to do, III' \
# notmuch restore currently only considers the first argument.
test_expect_success 'Invalid restore invocation' \
- 'test_must_fail notmuch restore dump.expected another_one'
+ 'test_must_fail notmuch restore --input=dump.expected another_one'
-test_begin_subtest "dump outfile"
-notmuch dump dump-outfile.actual
+test_begin_subtest "dump --output=outfile"
+notmuch dump --output=dump-outfile.actual
test_expect_equal_file dump.expected dump-outfile.actual
-test_begin_subtest "dump outfile # deprecated"
-test_expect_equal "Warning: the output file argument of dump is deprecated."\
- "$(notmuch dump /dev/null 2>&1)"
-
-test_begin_subtest "dump outfile --"
-notmuch dump dump-1-arg-dash.actual --
+test_begin_subtest "dump --output=outfile --"
+notmuch dump --output=dump-1-arg-dash.actual --
test_expect_equal_file dump.expected dump-1-arg-dash.actual
# Note, we assume all messages from cworth have a message-id
@@ -74,12 +70,12 @@ test_begin_subtest "dump -- from:cworth"
notmuch dump -- from:cworth > dump-dash-cworth.actual
test_expect_equal_file dump-cworth.expected dump-dash-cworth.actual
-test_begin_subtest "dump outfile from:cworth"
-notmuch dump dump-outfile-cworth.actual from:cworth
+test_begin_subtest "dump --output=outfile from:cworth"
+notmuch dump --output=dump-outfile-cworth.actual from:cworth
test_expect_equal_file dump-cworth.expected dump-outfile-cworth.actual
-test_begin_subtest "dump outfile -- from:cworth"
-notmuch dump dump-outfile-dash-inbox.actual -- from:cworth
+test_begin_subtest "dump --output=outfile -- from:cworth"
+notmuch dump --output=dump-outfile-dash-inbox.actual -- from:cworth
test_expect_equal_file dump-cworth.expected dump-outfile-dash-inbox.actual
test_done
diff --git a/test/emacs b/test/emacs
index ac47b16..afe35ba 100755
--- a/test/emacs
+++ b/test/emacs
@@ -35,11 +35,21 @@ test_emacs '(notmuch-search "tag:inbox")
(test-output)'
test_expect_equal_file OUTPUT $EXPECTED/notmuch-search-tag-inbox
+test_begin_subtest "Incremental parsing of search results"
+test_emacs "(ad-enable-advice 'notmuch-search-process-filter 'around 'pessimal)
+ (ad-activate 'notmuch-search-process-filter)
+ (notmuch-search \"tag:inbox\")
+ (notmuch-test-wait)
+ (ad-disable-advice 'notmuch-search-process-filter 'around 'pessimal)
+ (ad-activate 'notmuch-search-process-filter)
+ (test-output)"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-search-tag-inbox
+
test_begin_subtest "Navigation of notmuch-hello to search results"
test_emacs '(notmuch-hello)
(goto-char (point-min))
(re-search-forward "inbox")
- (widget-button-press (point))
+ (widget-button-press (1- (point)))
(notmuch-test-wait)
(test-output)'
test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-view-inbox
@@ -78,7 +88,7 @@ thread=$(notmuch search --output=threads subject:message-with-invalid-from)
test_emacs "(notmuch-show \"$thread\")
(test-output)"
cat <<EOF >EXPECTED
-"Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)
+"Invalid " (2001-01-05) (inbox)
Subject: message-with-invalid-from
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Date: Fri, 05 Jan 2001 15:43:57 +0000
@@ -101,26 +111,26 @@ test_begin_subtest "Add tag from search view"
os_x_darwin_thread=$(notmuch search --output=threads id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com)
test_emacs "(notmuch-search \"$os_x_darwin_thread\")
(notmuch-test-wait)
- (notmuch-search-add-tag \"tag-from-search-view\")"
+ (execute-kbd-macro \"+tag-from-search-view\")"
output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-search-view unread)"
test_begin_subtest "Remove tag from search view"
test_emacs "(notmuch-search \"$os_x_darwin_thread\")
(notmuch-test-wait)
- (notmuch-search-remove-tag \"tag-from-search-view\")"
+ (execute-kbd-macro \"-tag-from-search-view\")"
output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
test_begin_subtest "Add tag from notmuch-show view"
test_emacs "(notmuch-show \"$os_x_darwin_thread\")
- (notmuch-show-add-tag \"tag-from-show-view\")"
+ (execute-kbd-macro \"+tag-from-show-view\")"
output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-show-view unread)"
test_begin_subtest "Remove tag from notmuch-show view"
test_emacs "(notmuch-show \"$os_x_darwin_thread\")
- (notmuch-show-remove-tag \"tag-from-show-view\")"
+ (execute-kbd-macro \"-tag-from-show-view\")"
output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
@@ -128,17 +138,28 @@ test_begin_subtest "Message with .. in Message-Id:"
add_message [id]=123..456@example '[subject]="Message with .. in Message-Id"'
test_emacs '(notmuch-search "id:\"123..456@example\"")
(notmuch-test-wait)
- (notmuch-search-add-tag "search-add")
- (notmuch-search-add-tag "search-remove")
- (notmuch-search-remove-tag "search-remove")
+ (execute-kbd-macro "+search-add")
+ (execute-kbd-macro "+search-remove")
+ (execute-kbd-macro "-search-remove")
(notmuch-show "id:\"123..456@example\"")
(notmuch-test-wait)
- (notmuch-show-add-tag "show-add")
- (notmuch-show-add-tag "show-remove")
- (notmuch-show-remove-tag "show-remove")'
+ (execute-kbd-macro "+show-add")
+ (execute-kbd-macro "+show-remove")
+ (execute-kbd-macro "-show-remove")'
output=$(notmuch search 'id:"123..456@example"' | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Message with .. in Message-Id (inbox search-add show-add)"
+test_begin_subtest "Message with quote in Message-Id:"
+add_message '[id]="\"quote\"@example"' '[subject]="Message with quote in Message-Id"'
+test_emacs '(notmuch-search "subject:\"Message with quote\"")
+ (notmuch-test-wait)
+ (execute-kbd-macro "+search-add")
+ (notmuch-search-show-thread)
+ (notmuch-test-wait)
+ (execute-kbd-macro "+show-add")'
+output=$(notmuch search 'id:"""quote""@example"' | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Message with quote in Message-Id (inbox search-add show-add)"
+
test_begin_subtest "Sending a message via (fake) SMTP"
emacs_deliver_message \
'Testing message sent via SMTP' \
@@ -225,7 +246,7 @@ test_expect_equal_file OUTPUT EXPECTED
mkdir -p mail/sent-list-catch-all/cur
mkdir -p mail/sent-list-catch-all/new
mkdir -p mail/sent-list-catch-all/tmp
-
+
test_begin_subtest "notmuch-fcc-dirs set to a list (catch-all)"
test_emacs "(let ((notmuch-fcc-dirs
'((\"example.com\" . \"failure\")
@@ -256,23 +277,231 @@ EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Reply within emacs"
-test_emacs '(notmuch-search "subject:\"testing message sent via SMTP\"")
+test_emacs '(let ((message-hidden-headers ''()))
+ (notmuch-search "subject:\"testing message sent via SMTP\"")
(notmuch-test-wait)
(notmuch-search-reply-to-thread)
- (test-output)'
+ (test-output))'
sed -i -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' OUTPUT
+sed -i -e 's/^References: <.*>$/References: <XXX>/' OUTPUT
+sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
cat <<EOF >EXPECTED
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: user@example.com
Subject: Re: Testing message sent via SMTP
In-Reply-To: <XXX>
-Fcc: $(pwd)/mail/sent
+Fcc: ${MAIL_DIR}/sent
+References: <XXX>
+User-Agent: Notmuch/XXX Emacs/XXX
--text follows this line--
-On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
+Notmuch Test Suite <test_suite@notmuchmail.org> writes:
+
> This is a test that messages are sent via SMTP
EOF
test_expect_equal_file OUTPUT EXPECTED
+test_begin_subtest "Reply from alternate address within emacs"
+add_message '[from]="Sender <sender@example.com>"' \
+ [to]=test_suite_other@notmuchmail.org
+
+test_emacs "(let ((message-hidden-headers '()))
+ (notmuch-search \"id:\\\"${gen_msg_id}\\\"\")
+ (notmuch-test-wait)
+ (notmuch-search-reply-to-thread)
+ (test-output))"
+sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
+cat <<EOF >EXPECTED
+From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
+To: Sender <sender@example.com>
+Subject: Re: ${test_subtest_name}
+In-Reply-To: <${gen_msg_id}>
+Fcc: ${MAIL_DIR}/sent
+References: <${gen_msg_id}>
+User-Agent: Notmuch/XXX Emacs/XXX
+--text follows this line--
+Sender <sender@example.com> writes:
+
+> This is just a test message (#${gen_msg_cnt})
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "Reply from address in named group list within emacs"
+add_message '[from]="Sender <sender@example.com>"' \
+ '[to]=group:test_suite@notmuchmail.org,someone@example.com\;' \
+ [cc]=test_suite_other@notmuchmail.org
+
+test_emacs "(let ((message-hidden-headers '()))
+ (notmuch-search \"id:\\\"${gen_msg_id}\\\"\")
+ (notmuch-test-wait)
+ (notmuch-search-reply-to-thread)
+ (test-output))"
+sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
+cat <<EOF >EXPECTED
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Sender <sender@example.com>, someone@example.com
+Subject: Re: ${test_subtest_name}
+In-Reply-To: <${gen_msg_id}>
+Fcc: ${MAIL_DIR}/sent
+References: <${gen_msg_id}>
+User-Agent: Notmuch/XXX Emacs/XXX
+--text follows this line--
+Sender <sender@example.com> writes:
+
+> This is just a test message (#${gen_msg_cnt})
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "Reply within emacs to a multipart/mixed message"
+test_emacs '(let ((message-hidden-headers ''()))
+ (notmuch-show "id:20091118002059.067214ed@hikari")
+ (notmuch-show-reply)
+ (test-output))'
+sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
+cat <<EOF >EXPECTED
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Adrian Perez de Castro <aperez@igalia.com>, notmuch@notmuchmail.org
+Subject: Re: [notmuch] Introducing myself
+In-Reply-To: <20091118002059.067214ed@hikari>
+Fcc: ${MAIL_DIR}/sent
+References: <20091118002059.067214ed@hikari>
+User-Agent: Notmuch/XXX Emacs/XXX
+--text follows this line--
+Adrian Perez de Castro <aperez@igalia.com> writes:
+
+> Hello to all,
+>
+> I have just heard about Not Much today in some random Linux-related news
+> site (LWN?), my name is Adrian Perez and I work as systems administrator
+> (although I can do some code as well :P). I have always thought that the
+> ideas behind Sup were great, but after some time using it, I got tired of
+> the oddities that it has. I also do not like doing things like having to
+> install Ruby just for reading and sorting mails. Some time ago I thought
+> about doing something like Not Much and in fact I played a bit with the
+> Python+Xapian and the Python+Whoosh combinations, because I find relaxing
+> to code things in Python when I am not working and also it is installed
+> by default on most distribution. I got to have some mailboxes indexed and
+> basic searching working a couple of months ago. Lately I have been very
+> busy and had no time for coding, and them... boom! Not Much appears -- and
+> it is almost exactly what I was trying to do, but faster. I have been
+> playing a bit with Not Much today, and I think it has potential.
+>
+> Also, I would like to share one idea I had in mind, that you might find
+> interesting: One thing I have found very annoying is having to re-tag my
+> mail when the indexes get b0rked (it happened a couple of times to me while
+> using Sup), so I was planning to mails as read/unread and adding the tags
+> not just to the index, but to the mail text itself, e.g. by adding a
+> "X-Tags" header field or by reusing the "Keywords" one. This way, the index
+> could be totally recreated by re-reading the mail directories, and this
+> would also allow to a tools like OfflineIMAP [1] to get the mails into a
+> local maildir, tagging and indexing the mails with the e-mail reader and
+> then syncing back the messages with the "X-Tags" header to the IMAP server.
+> This would allow to use the mail reader from a different computer and still
+> have everything tagged finely.
+>
+> Best regards,
+>
+>
+> ---
+> [1] http://software.complete.org/software/projects/show/offlineimap
+>
+> --
+> Adrian Perez de Castro <aperez@igalia.com>
+> Igalia - Free Software Engineering
+> _______________________________________________
+> notmuch mailing list
+> notmuch@notmuchmail.org
+> http://notmuchmail.org/mailman/listinfo/notmuch
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "Reply within emacs to a multipart/alternative message"
+test_emacs '(let ((message-hidden-headers ''()))
+ (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
+ (notmuch-show-reply)
+ (test-output))'
+sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
+cat <<EOF >EXPECTED
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Alex Botero-Lowry <alex.boterolowry@gmail.com>, notmuch@notmuchmail.org
+Subject: Re: [notmuch] preliminary FreeBSD support
+In-Reply-To: <cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com>
+Fcc: ${MAIL_DIR}/sent
+References: <cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com>
+User-Agent: Notmuch/XXX Emacs/XXX
+--text follows this line--
+Alex Botero-Lowry <alex.boterolowry@gmail.com> writes:
+
+> I saw the announcement this morning, and was very excited, as I had been
+> hoping sup would be turned into a library,
+> since I like the concept more than the UI (I'd rather an emacs interface).
+>
+> I did a preliminary compile which worked out fine, but
+> sysconf(_SC_SC_GETPW_R_SIZE_MAX) returns -1 on
+> FreeBSD, so notmuch_config_open segfaulted.
+>
+> Attached is a patch that supplies a default buffer size of 64 in cases where
+> -1 is returned.
+>
+> http://www.opengroup.org/austin/docs/austin_328.txt - seems to indicate this
+> is acceptable behavior,
+> and http://mail-index.netbsd.org/pkgsrc-bugs/2006/06/07/msg016808.htmlspecifically
+> uses 64 as the
+> buffer size.
+> _______________________________________________
+> notmuch mailing list
+> notmuch@notmuchmail.org
+> http://notmuchmail.org/mailman/listinfo/notmuch
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "Reply within emacs to an html-only message"
+add_message '[content-type]="text/html"' \
+ '[body]="Hi,<br />This is an <b>HTML</b> test message.<br /><br />OK?"'
+test_emacs "(let ((message-hidden-headers '()) (mm-text-html-renderer 'html2text))
+ (notmuch-show \"id:${gen_msg_id}\")
+ (notmuch-show-reply)
+ (test-output))"
+sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
+cat <<EOF >EXPECTED
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To:
+Subject: Re: Reply within emacs to an html-only message
+In-Reply-To: <${gen_msg_id}>
+Fcc: ${MAIL_DIR}/sent
+References: <${gen_msg_id}>
+User-Agent: Notmuch/XXX Emacs/XXX
+--text follows this line--
+Notmuch Test Suite <test_suite@notmuchmail.org> writes:
+
+> Hi,This is an HTML test message.OK?
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "Quote MML tags in reply"
+message_id='test-emacs-mml-quoting@message.id'
+add_message [id]="$message_id" \
+ "[subject]='$test_subtest_name'" \
+ '[body]="<#part disposition=inline>"'
+test_emacs "(let ((message-hidden-headers '()))
+ (notmuch-show \"id:$message_id\")
+ (notmuch-show-reply)
+ (test-output))"
+sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
+cat <<EOF >EXPECTED
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To:
+Subject: Re: Quote MML tags in reply
+In-Reply-To: <test-emacs-mml-quoting@message.id>
+Fcc: ${MAIL_DIR}/sent
+References: <test-emacs-mml-quoting@message.id>
+User-Agent: Notmuch/XXX Emacs/XXX
+--text follows this line--
+Notmuch Test Suite <test_suite@notmuchmail.org> writes:
+
+> <#!part disposition=inline>
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"
# save as archive to test that Emacs does not re-compress .gz
test_emacs '(let ((standard-input "\"attachment1.gz\""))
@@ -373,25 +602,28 @@ add_message '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
'[body]="Unable to stash body. Where did you get it in the first place?!?"'
notmuch tag +stashtest id:${gen_msg_id}
test_emacs '(notmuch-show "id:\"bought\"")
- (notmuch-show-stash-date)
- (notmuch-show-stash-from)
- (notmuch-show-stash-to)
- (notmuch-show-stash-cc)
- (notmuch-show-stash-subject)
- (notmuch-show-stash-message-id)
- (notmuch-show-stash-message-id-stripped)
- (notmuch-show-stash-tags)
- (notmuch-show-stash-filename)
- (switch-to-buffer
- (generate-new-buffer "*test-stashing*"))
- (dotimes (i 9)
- (yank)
- (insert "\n")
- (rotate-yank-pointer 1))
- (reverse-region (point-min) (point-max))
+ (notmuch-show-stash-date)
+ (notmuch-show-stash-from)
+ (notmuch-show-stash-to)
+ (notmuch-show-stash-cc)
+ (notmuch-show-stash-subject)
+ (notmuch-show-stash-message-id)
+ (notmuch-show-stash-message-id-stripped)
+ (notmuch-show-stash-tags)
+ (notmuch-show-stash-filename)
+ (notmuch-show-stash-mlarchive-link "Gmane")
+ (notmuch-show-stash-mlarchive-link "MARC")
+ (notmuch-show-stash-mlarchive-link "Mail Archive, The")
+ (switch-to-buffer
+ (generate-new-buffer "*test-stashing*"))
+ (dotimes (i 12)
+ (yank)
+ (insert "\n")
+ (rotate-yank-pointer 1))
+ (reverse-region (point-min) (point-max))
(test-output)'
cat <<EOF >EXPECTED
-Sat, 01 Jan 2000 12:00:00 -0000
+Sat, 01 Jan 2000 12:00:00 +0000
Some One <someone@somewhere.org>
Some One Else <notsomeone@somewhere.org>
Notmuch <notmuch@notmuchmail.org>
@@ -400,16 +632,19 @@ id:"bought"
bought
inbox,stashtest
${gen_msg_filename}
+http://mid.gmane.org/bought
+http://marc.info/?i=bought
+http://mail-archive.com/search?l=mid&q=bought
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Stashing in notmuch-search"
test_emacs '(notmuch-search "id:\"bought\"")
- (notmuch-test-wait)
- (notmuch-search-stash-thread-id)
- (switch-to-buffer
- (generate-new-buffer "*test-stashing*"))
- (yank)
+ (notmuch-test-wait)
+ (notmuch-search-stash-thread-id)
+ (switch-to-buffer
+ (generate-new-buffer "*test-stashing*"))
+ (yank)
(test-output)'
sed -i -e 's/^thread:.*$/thread:XXX/' OUTPUT
test_expect_equal "$(cat OUTPUT)" "thread:XXX"
@@ -436,11 +671,10 @@ test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Refresh modified show buffer"
-test_subtest_known_broken
test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
- (notmuch-show-toggle-message)
- (notmuch-show-next-message)
- (notmuch-show-toggle-message)
+ (notmuch-show-toggle-message)
+ (notmuch-show-next-message)
+ (notmuch-show-toggle-message)
(test-visible-output "EXPECTED")
(notmuch-show-refresh-view)
(test-visible-output)'
diff --git a/test/emacs-address-cleaning b/test/emacs-address-cleaning
new file mode 100755
index 0000000..6ddde5c
--- /dev/null
+++ b/test/emacs-address-cleaning
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+test_description="emacs address cleaning"
+. test-lib.sh
+
+test_begin_subtest "notmuch-test-address-clean part 1"
+test_emacs_expect_t '(notmuch-test-address-cleaning-1)'
+
+test_begin_subtest "notmuch-test-address-clean part 2"
+test_emacs_expect_t '(notmuch-test-address-cleaning-2)'
+
+test_begin_subtest "notmuch-test-address-clean part 3"
+test_emacs_expect_t '(notmuch-test-address-cleaning-3)'
+
+test_done
diff --git a/test/emacs-address-cleaning.el b/test/emacs-address-cleaning.el
new file mode 100644
index 0000000..8423245
--- /dev/null
+++ b/test/emacs-address-cleaning.el
@@ -0,0 +1,39 @@
+(defun notmuch-test-address-cleaning-1 ()
+ (notmuch-test-expect-equal (notmuch-show-clean-address "dme@dme.org")
+ "dme@dme.org"))
+
+(defun notmuch-test-address-cleaning-2 ()
+ (let* ((input '("foo@bar.com"
+ "<foo@bar.com>"
+ "Foo Bar <foo@bar.com>"
+ "foo@bar.com <foo@bar.com>"
+ "\"Foo Bar\" <foo@bar.com>"))
+ (expected '("foo@bar.com"
+ "foo@bar.com"
+ "Foo Bar <foo@bar.com>"
+ "foo@bar.com"
+ "Foo Bar <foo@bar.com>"))
+ (output (mapcar #'notmuch-show-clean-address input)))
+ (notmuch-test-expect-equal output expected)))
+
+(defun notmuch-test-address-cleaning-3 ()
+ (let* ((input '("ДБ <db-uknot@stop.me.uk>"
+ "foo (at home) <foo@bar.com>"
+ "foo [at home] <foo@bar.com>"
+ "Foo Bar"
+ "'Foo Bar' <foo@bar.com>"
+ "\"'Foo Bar'\" <foo@bar.com>"
+ "'\"Foo Bar\"' <foo@bar.com>"
+ "'\"'Foo Bar'\"' <foo@bar.com>"
+ "Fred Dibna \\[extraordinaire\\] <fred@dibna.com>"))
+ (expected '("ДБ <db-uknot@stop.me.uk>"
+ "foo (at home) <foo@bar.com>"
+ "foo [at home] <foo@bar.com>"
+ "Foo Bar"
+ "Foo Bar <foo@bar.com>"
+ "Foo Bar <foo@bar.com>"
+ "Foo Bar <foo@bar.com>"
+ "Foo Bar <foo@bar.com>"
+ "Fred Dibna [extraordinaire] <fred@dibna.com>"))
+ (output (mapcar #'notmuch-show-clean-address input)))
+ (notmuch-test-expect-equal output expected)))
diff --git a/test/emacs-hello b/test/emacs-hello
new file mode 100755
index 0000000..48d1420
--- /dev/null
+++ b/test/emacs-hello
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+
+test_description="emacs notmuch-hello view"
+. test-lib.sh
+
+EXPECTED=$TEST_DIRECTORY/emacs.expected-output
+
+add_email_corpus
+
+test_begin_subtest "User-defined section with inbox tag"
+test_emacs "(let ((notmuch-hello-sections
+ (list (lambda () (notmuch-hello-insert-searches
+ \"Test\" '((\"inbox\" . \"tag:inbox\")))))))
+ (notmuch-hello)
+ (test-output))"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-new-section
+
+test_begin_subtest "User-defined section with empty, hidden entry"
+test_emacs "(let ((notmuch-hello-sections
+ (list (lambda () (notmuch-hello-insert-searches
+ \"Test-with-empty\"
+ '((\"inbox\" . \"tag:inbox\")
+ (\"doesnotexist\" . \"tag:doesnotexist\"))
+ :hide-empty-searches t)))))
+ (notmuch-hello)
+ (test-output))"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-section-with-empty
+
+test_begin_subtest "User-defined section, unread tag filtered out"
+test_emacs "(let ((notmuch-hello-sections
+ (list (lambda () (notmuch-hello-insert-tags-section
+ \"Test-with-filtered\"
+ :hide-tags '(\"unread\"))))))
+ (notmuch-hello)
+ (test-output))"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-section-hidden-tag
+
+test_begin_subtest "User-defined section, different query for counts"
+test_emacs "(let ((notmuch-hello-sections
+ (list (lambda () (notmuch-hello-insert-tags-section
+ \"Test-with-counts\"
+ :filter-count \"tag:signed\")))))
+ (notmuch-hello)
+ (test-output))"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-section-counts
+
+test_begin_subtest "Empty custom tags section"
+test_emacs "(let* ((widget (widget-create 'notmuch-hello-tags-section))
+ (notmuch-hello-sections (list (widget-value widget))))
+ (notmuch-hello)
+ (test-output))"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-empty-custom-tags-section
+
+test_begin_subtest "Empty custom queries section"
+test_emacs "(let* ((widget (widget-create 'notmuch-hello-query-section))
+ (notmuch-hello-sections (list (widget-value widget))))
+ (notmuch-hello)
+ (test-output))"
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-empty-custom-queries-section
+
+test_begin_subtest "Column alignment for tag/queries with long names"
+tag=a-very-long-tag # length carefully calculated for 80 characters window width
+notmuch tag +$tag '*'
+test_emacs '(notmuch-hello)
+ (test-output)'
+notmuch tag -$tag '*'
+test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-long-names
+
+test_done
diff --git a/test/emacs-large-search-buffer b/test/emacs-large-search-buffer
index 6095e9d..4351e33 100755
--- a/test/emacs-large-search-buffer
+++ b/test/emacs-large-search-buffer
@@ -19,25 +19,25 @@ done
notmuch new > /dev/null
test_begin_subtest "Ensure that emacs doesn't drop results"
-notmuch search '*' > EXPEXTED
-sed -i -e 's/^thread:[0-9a-f]* //' -e 's/;//' -e 's/xx*/[BLOB]/' EXPEXTED
-echo 'End of search results.' >> EXPEXTED
+notmuch search '*' > EXPECTED
+sed -i -e 's/^thread:[0-9a-f]* //' -e 's/;//' -e 's/xx*/[BLOB]/' EXPECTED
+echo 'End of search results.' >> EXPECTED
test_emacs '(notmuch-search "*")
(notmuch-test-wait)
(test-output)'
sed -i -e s', *, ,g' -e 's/xxx*/[BLOB]/g' OUTPUT
-test_expect_equal_file OUTPUT EXPEXTED
+test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Ensure that emacs doesn't drop error messages"
test_emacs '(notmuch-search "--this-option-does-not-exist")
(notmuch-test-wait)
(test-output)'
-cat <<EOF >EXPEXTED
+cat <<EOF >EXPECTED
Error: Unexpected output from notmuch search:
Unrecognized option: --this-option-does-not-exist
End of search results. (process returned 1)
EOF
-test_expect_equal_file OUTPUT EXPEXTED
+test_expect_equal_file OUTPUT EXPECTED
test_done
diff --git a/test/emacs-show b/test/emacs-show
new file mode 100755
index 0000000..e9a714f
--- /dev/null
+++ b/test/emacs-show
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+test_description="emacs notmuch-show view"
+. test-lib.sh
+
+test_begin_subtest "Hiding Original Message region at beginning of a message"
+message_id='OriginalMessageHiding.1@notmuchmail.org'
+add_message \
+ [id]="$message_id" \
+ '[subject]="Hiding Original Message region at beginning of a message"' \
+ '[body]="-----Original Message-----
+Text here."'
+
+cat <<EOF >EXPECTED
+Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
+Subject: Hiding Original Message region at beginning of a message
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Fri, 05 Jan 2001 15:43:57 +0000
+
+[ 2-line hidden original message. Click/Enter to show. ]
+EOF
+
+test_emacs "(notmuch-show \"id:$message_id\")
+ (test-visible-output)"
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "Bare subject #1"
+output=$(test_emacs '(notmuch-show-strip-re "Re: subject")')
+test_expect_equal "$output" '"subject"'
+
+test_begin_subtest "Bare subject #2"
+output=$(test_emacs '(notmuch-show-strip-re "re:Re: re: Re: re:subject")')
+test_expect_equal "$output" '"subject"'
+
+test_begin_subtest "Bare subject #3"
+output=$(test_emacs '(notmuch-show-strip-re "the cure: fix the regexp")')
+test_expect_equal "$output" '"the cure: fix the regexp"'
+
+test_done
diff --git a/test/emacs-test-functions b/test/emacs-test-functions
new file mode 100755
index 0000000..0e1f9fc
--- /dev/null
+++ b/test/emacs-test-functions
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+test_description="emacs test function sanity"
+. test-lib.sh
+
+test_begin_subtest "emacs test function sanity"
+test_emacs_expect_t 't'
+
+test_done
diff --git a/test/emacs.expected-output/notmuch-hello b/test/emacs.expected-output/notmuch-hello
index de57de2..2d69891 100644
--- a/test/emacs.expected-output/notmuch-hello
+++ b/test/emacs.expected-output/notmuch-hello
@@ -2,13 +2,14 @@
Saved searches: [edit]
- 52 inbox 52 unread
+ 52 inbox 52 unread
-Search:
+Search: .
-[Show all tags]
+All tags: [show]
Type a search query and hit RET to view matching threads.
Edit saved searches with the `edit' button.
Hit RET or click on a saved search or tag name to view matching threads.
- `=' refreshes this screen. `s' jumps to the search box. `q' to quit.
+ `=' to refresh this screen. `s' to search messages. `q' to quit.
+ Customize this page.
diff --git a/test/emacs.expected-output/notmuch-hello-empty-custom-queries-section b/test/emacs.expected-output/notmuch-hello-empty-custom-queries-section
new file mode 100644
index 0000000..cd0fdf0
--- /dev/null
+++ b/test/emacs.expected-output/notmuch-hello-empty-custom-queries-section
@@ -0,0 +1,3 @@
+: [hide]
+
+
diff --git a/test/emacs.expected-output/notmuch-hello-empty-custom-tags-section b/test/emacs.expected-output/notmuch-hello-empty-custom-tags-section
new file mode 100644
index 0000000..b56fd67
--- /dev/null
+++ b/test/emacs.expected-output/notmuch-hello-empty-custom-tags-section
@@ -0,0 +1,5 @@
+: [hide]
+
+ 4 attachment 7 signed
+ 52 inbox 52 unread
+
diff --git a/test/emacs.expected-output/notmuch-hello-long-names b/test/emacs.expected-output/notmuch-hello-long-names
new file mode 100644
index 0000000..486d0d9
--- /dev/null
+++ b/test/emacs.expected-output/notmuch-hello-long-names
@@ -0,0 +1,18 @@
+ Welcome to notmuch. You have 52 messages.
+
+Saved searches: [edit]
+
+ 52 inbox 52 unread
+
+Search: .
+
+All tags: [hide]
+
+ 52 a-very-long-tag 52 inbox 52 unread
+ 4 attachment 7 signed
+
+ Type a search query and hit RET to view matching threads.
+ Edit saved searches with the `edit' button.
+ Hit RET or click on a saved search or tag name to view matching threads.
+ `=' to refresh this screen. `s' to search messages. `q' to quit.
+ Customize this page.
diff --git a/test/emacs.expected-output/notmuch-hello-new-section b/test/emacs.expected-output/notmuch-hello-new-section
new file mode 100644
index 0000000..67fdef2
--- /dev/null
+++ b/test/emacs.expected-output/notmuch-hello-new-section
@@ -0,0 +1,4 @@
+Test: [hide]
+
+ 52 inbox
+
diff --git a/test/emacs.expected-output/notmuch-hello-no-saved-searches b/test/emacs.expected-output/notmuch-hello-no-saved-searches
index f1fc4d6..05475b1 100644
--- a/test/emacs.expected-output/notmuch-hello-no-saved-searches
+++ b/test/emacs.expected-output/notmuch-hello-no-saved-searches
@@ -1,10 +1,11 @@
Welcome to notmuch. You have 52 messages.
-Search:
+Search: .
-[Show all tags]
+All tags: [show]
Type a search query and hit RET to view matching threads.
Edit saved searches with the `edit' button.
Hit RET or click on a saved search or tag name to view matching threads.
- `=' refreshes this screen. `s' jumps to the search box. `q' to quit.
+ `=' to refresh this screen. `s' to search messages. `q' to quit.
+ Customize this page.
diff --git a/test/emacs.expected-output/notmuch-hello-section-counts b/test/emacs.expected-output/notmuch-hello-section-counts
new file mode 100644
index 0000000..7a9827c
--- /dev/null
+++ b/test/emacs.expected-output/notmuch-hello-section-counts
@@ -0,0 +1,5 @@
+Test-with-counts: [hide]
+
+ 2 attachment 7 signed
+ 7 inbox 7 unread
+
diff --git a/test/emacs.expected-output/notmuch-hello-section-hidden-tag b/test/emacs.expected-output/notmuch-hello-section-hidden-tag
new file mode 100644
index 0000000..809a114
--- /dev/null
+++ b/test/emacs.expected-output/notmuch-hello-section-hidden-tag
@@ -0,0 +1,4 @@
+Test-with-filtered: [hide]
+
+ 4 attachment 52 inbox 7 signed
+
diff --git a/test/emacs.expected-output/notmuch-hello-section-with-empty b/test/emacs.expected-output/notmuch-hello-section-with-empty
new file mode 100644
index 0000000..5c67317
--- /dev/null
+++ b/test/emacs.expected-output/notmuch-hello-section-with-empty
@@ -0,0 +1,4 @@
+Test-with-empty: [hide]
+
+ 52 inbox
+
diff --git a/test/emacs.expected-output/notmuch-hello-with-empty b/test/emacs.expected-output/notmuch-hello-with-empty
index dd8728b..854e0c2 100644
--- a/test/emacs.expected-output/notmuch-hello-with-empty
+++ b/test/emacs.expected-output/notmuch-hello-with-empty
@@ -2,13 +2,14 @@
Saved searches: [edit]
- 52 inbox 52 unread 0 empty
+ 52 inbox 52 unread 0 empty
-Search:
+Search: .
-[Show all tags]
+All tags: [show]
Type a search query and hit RET to view matching threads.
Edit saved searches with the `edit' button.
Hit RET or click on a saved search or tag name to view matching threads.
- `=' refreshes this screen. `s' jumps to the search box. `q' to quit.
+ `=' to refresh this screen. `s' to search messages. `q' to quit.
+ Customize this page.
diff --git a/test/encoding b/test/encoding
index e875c8b..2e1326e 100755
--- a/test/encoding
+++ b/test/encoding
@@ -4,12 +4,12 @@ test_description="encoding issues"
test_begin_subtest "Message with text of unknown charset"
add_message '[content-type]="text/plain; charset=unknown-8bit"' \
- "[body]=irrelevant"
+ "[body]=irrelevant"
output=$(notmuch show id:${gen_msg_id} 2>&1 | notmuch_show_sanitize)
-test_expect_equal "$output" " message{ id:msg-001@notmuch-test-suite depth:0 match:1 filename:/XXX/mail/msg-001
+test_expect_equal "$output" " message{ id:msg-001@notmuch-test-suite depth:0 match:1 excluded:0 filename:/XXX/mail/msg-001
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox unread)
-Subject: Test message #1
+Subject: Message with text of unknown charset
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
Date: Fri, 05 Jan 2001 15:43:57 +0000
@@ -21,4 +21,12 @@ irrelevant
body}
message}"
+test_begin_subtest "Search for ISO-8859-2 encoded message"
+add_message '[content-type]="text/plain; charset=iso-8859-2"' \
+ '[content-transfer-encoding]=8bit' \
+ '[subject]="ISO-8859-2 encoded message"' \
+ "[body]=$'Czech word tu\350\362\341\350\350\355 means pinguin\'s.'" # ISO-8859-2 characters are generated by shell's escape sequences
+output=$(notmuch search tučňáččí 2>&1 | notmuch_show_sanitize)
+test_expect_equal "$output" "thread:0000000000000002 2001-01-05 [1/1] Notmuch Test Suite; ISO-8859-2 encoded message (inbox unread)"
+
test_done
diff --git a/test/excludes b/test/excludes
new file mode 100755
index 0000000..24d653e
--- /dev/null
+++ b/test/excludes
@@ -0,0 +1,423 @@
+#!/usr/bin/env bash
+test_description='"notmuch search, count and show" with excludes in several variations'
+. ./test-lib.sh
+
+# Generates a thread consisting of a top level message and 'length'
+# replies. The subject of the top message 'subject: top message"
+# and the subject of the nth reply in the thread is "subject: reply n"
+generate_thread ()
+{
+ local subject="$1"
+ local length="$2"
+ generate_message '[subject]="'"${subject}: top message"'"' '[body]="'"body of top message"'"'
+ parent_id=$gen_msg_id
+ gen_thread_msg_id[0]=$gen_msg_id
+ for i in `seq 1 $length`
+ do
+ generate_message '[subject]="'"${subject}: reply $i"'"' \
+ "[in-reply-to]=\<$parent_id\>" \
+ '[body]="'"body of reply $i"'"'
+ gen_thread_msg_id[$i]=$gen_msg_id
+ parent_id=$gen_msg_id
+ done
+ notmuch new > /dev/null
+ # We cannot retrieve the thread_id until after we have run notmuch new.
+ gen_thread_id=`notmuch search --output=threads id:${gen_thread_msg_id[0]}`
+}
+
+#############################################
+# These are the original search exclude tests.
+
+test_begin_subtest "Search, exclude \"deleted\" messages from search"
+notmuch config set search.exclude_tags deleted
+generate_message '[subject]="Not deleted"'
+not_deleted_id=$gen_msg_id
+generate_message '[subject]="Deleted"'
+notmuch new > /dev/null
+notmuch tag +deleted id:$gen_msg_id
+deleted_id=$gen_msg_id
+output=$(notmuch search subject:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)"
+
+test_begin_subtest "Search, exclude \"deleted\" messages from message search"
+output=$(notmuch search --output=messages subject:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "id:$not_deleted_id"
+
+test_begin_subtest "Search, exclude \"deleted\" messages from message search --exclude=false"
+output=$(notmuch search --exclude=false --output=messages subject:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "id:$not_deleted_id
+id:$deleted_id"
+
+test_begin_subtest "Search, exclude \"deleted\" messages from message search (non-existent exclude-tag)"
+notmuch config set search.exclude_tags deleted non_existent_tag
+output=$(notmuch search --output=messages subject:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "id:$not_deleted_id"
+notmuch config set search.exclude_tags deleted
+
+test_begin_subtest "Search, exclude \"deleted\" messages from search, overridden"
+output=$(notmuch search subject:deleted and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Deleted (deleted inbox unread)"
+
+test_begin_subtest "Search, exclude \"deleted\" messages from threads"
+add_message '[subject]="Not deleted reply"' '[in-reply-to]="<$gen_msg_id>"'
+output=$(notmuch search subject:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
+thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)"
+
+test_begin_subtest "Search, don't exclude \"deleted\" messages when --exclude=flag specified"
+output=$(notmuch search --exclude=flag subject:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
+thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)"
+
+test_begin_subtest "Search, don't exclude \"deleted\" messages from search if not configured"
+notmuch config set search.exclude_tags
+output=$(notmuch search subject:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
+thread:XXX 2001-01-05 [2/2] Notmuch Test Suite; Deleted (deleted inbox unread)"
+
+
+########################################################
+# We construct some threads for the tests. We use the tag "test" to
+# indicate which messages we will search for.
+
+# A thread of deleted messages; test matches one of them.
+generate_thread "All messages excluded: single match" 5
+notmuch tag +deleted $gen_thread_id
+notmuch tag +test id:${gen_thread_msg_id[2]}
+
+# A thread of deleted messages; test matches two of them.
+generate_thread "All messages excluded: double match" 5
+notmuch tag +deleted $gen_thread_id
+notmuch tag +test id:${gen_thread_msg_id[2]}
+notmuch tag +test id:${gen_thread_msg_id[4]}
+
+# A thread some messages deleted; test only matches a deleted message.
+generate_thread "Some messages excluded: single excluded match" 5
+notmuch tag +deleted +test id:${gen_thread_msg_id[3]}
+
+# A thread some messages deleted; test only matches a non-deleted message.
+generate_thread "Some messages excluded: single non-excluded match" 5
+notmuch tag +deleted id:${gen_thread_msg_id[2]}
+notmuch tag +test id:${gen_thread_msg_id[4]}
+
+# A thread no messages deleted; test matches a message.
+generate_thread "No messages excluded: single match" 5
+notmuch tag +test id:${gen_thread_msg_id[3]}
+
+# Temporarily remove excludes to get list of matching messages
+notmuch config set search.exclude_tags
+matching_message_ids=( `notmuch search --output=messages tag:test` )
+notmuch config set search.exclude_tags deleted
+
+#########################################
+# Notmuch search tests
+
+test_begin_subtest "Search, default exclusion (thread summary)"
+output=$(notmuch search tag:test | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; Some messages excluded: single non-excluded match: reply 4 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; No messages excluded: single match: reply 3 (inbox test unread)"
+
+test_begin_subtest "Search, default exclusion (messages)"
+output=$(notmuch search --output=messages tag:test | notmuch_search_sanitize)
+test_expect_equal "$output" "${matching_message_ids[4]}
+${matching_message_ids[5]}"
+
+test_begin_subtest "Search, exclude=true (thread summary)"
+output=$(notmuch search --exclude=true tag:test | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; Some messages excluded: single non-excluded match: reply 4 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; No messages excluded: single match: reply 3 (inbox test unread)"
+
+test_begin_subtest "Search, exclude=true (messages)"
+output=$(notmuch search --exclude=true --output=messages tag:test | notmuch_search_sanitize)
+test_expect_equal "$output" "${matching_message_ids[4]}
+${matching_message_ids[5]}"
+
+test_begin_subtest "Search, exclude=false (thread summary)"
+output=$(notmuch search --exclude=false tag:test | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; All messages excluded: single match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [2/6] Notmuch Test Suite; All messages excluded: double match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; Some messages excluded: single excluded match: reply 3 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; Some messages excluded: single non-excluded match: reply 4 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; No messages excluded: single match: reply 3 (inbox test unread)"
+
+test_begin_subtest "Search, exclude=false (messages)"
+output=$(notmuch search --exclude=false --output=messages tag:test | notmuch_search_sanitize)
+test_expect_equal "$output" "${matching_message_ids[0]}
+${matching_message_ids[1]}
+${matching_message_ids[2]}
+${matching_message_ids[3]}
+${matching_message_ids[4]}
+${matching_message_ids[5]}"
+
+test_begin_subtest "Search, exclude=flag (thread summary)"
+output=$(notmuch search --exclude=flag tag:test | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [0/6] Notmuch Test Suite; All messages excluded: single match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [0/6] Notmuch Test Suite; All messages excluded: double match: reply 4 (deleted inbox test unread)
+thread:XXX 2001-01-05 [0/6] Notmuch Test Suite; Some messages excluded: single excluded match: reply 3 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; Some messages excluded: single non-excluded match: reply 4 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; No messages excluded: single match: reply 3 (inbox test unread)"
+
+test_begin_subtest "Search, exclude=flag (messages)"
+output=$(notmuch search --exclude=flag --output=messages tag:test | notmuch_search_sanitize)
+test_expect_equal "$output" "${matching_message_ids[0]}
+${matching_message_ids[1]}
+${matching_message_ids[2]}
+${matching_message_ids[3]}
+${matching_message_ids[4]}
+${matching_message_ids[5]}"
+
+test_begin_subtest "Search, default exclusion: tag in query (thread summary)"
+output=$(notmuch search tag:test and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; All messages excluded: single match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [2/6] Notmuch Test Suite; All messages excluded: double match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; Some messages excluded: single excluded match: reply 3 (deleted inbox test unread)"
+
+test_begin_subtest "Search, default exclusion: tag in query (messages)"
+output=$(notmuch search --output=messages tag:test and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "${matching_message_ids[0]}
+${matching_message_ids[1]}
+${matching_message_ids[2]}
+${matching_message_ids[3]}"
+
+test_begin_subtest "Search, exclude=true: tag in query (thread summary)"
+output=$(notmuch search --exclude=true tag:test and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; All messages excluded: single match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [2/6] Notmuch Test Suite; All messages excluded: double match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; Some messages excluded: single excluded match: reply 3 (deleted inbox test unread)"
+
+test_begin_subtest "Search, exclude=true: tag in query (messages)"
+output=$(notmuch search --exclude=true --output=messages tag:test and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "${matching_message_ids[0]}
+${matching_message_ids[1]}
+${matching_message_ids[2]}
+${matching_message_ids[3]}"
+
+test_begin_subtest "Search, exclude=false: tag in query (thread summary)"
+output=$(notmuch search --exclude=false tag:test and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; All messages excluded: single match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [2/6] Notmuch Test Suite; All messages excluded: double match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; Some messages excluded: single excluded match: reply 3 (deleted inbox test unread)"
+
+test_begin_subtest "Search, exclude=false: tag in query (messages)"
+output=$(notmuch search --exclude=false --output=messages tag:test and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "${matching_message_ids[0]}
+${matching_message_ids[1]}
+${matching_message_ids[2]}
+${matching_message_ids[3]}"
+
+test_begin_subtest "Search, exclude=flag: tag in query (thread summary)"
+output=$(notmuch search --exclude=flag tag:test and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; All messages excluded: single match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [2/6] Notmuch Test Suite; All messages excluded: double match: reply 2 (deleted inbox test unread)
+thread:XXX 2001-01-05 [1/6] Notmuch Test Suite; Some messages excluded: single excluded match: reply 3 (deleted inbox test unread)"
+
+test_begin_subtest "Search, exclude=flag: tag in query (messages)"
+output=$(notmuch search --exclude=flag --output=messages tag:test and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "${matching_message_ids[0]}
+${matching_message_ids[1]}
+${matching_message_ids[2]}
+${matching_message_ids[3]}"
+
+
+#########################################################
+# Notmuch count tests
+
+test_begin_subtest "Count, default exclusion (messages)"
+output=$(notmuch count tag:test)
+test_expect_equal "$output" "2"
+
+test_begin_subtest "Count, default exclusion (threads)"
+output=$(notmuch count --output=threads tag:test)
+test_expect_equal "$output" "2"
+
+test_begin_subtest "Count, exclude=true (messages)"
+output=$(notmuch count --exclude=true tag:test)
+test_expect_equal "$output" "2"
+
+test_begin_subtest "Count, exclude=true (threads)"
+output=$(notmuch count --output=threads --exclude=true tag:test)
+test_expect_equal "$output" "2"
+
+test_begin_subtest "Count, exclude=false (messages)"
+output=$(notmuch count --exclude=false tag:test)
+test_expect_equal "$output" "6"
+
+test_begin_subtest "Count, exclude=false (threads)"
+output=$(notmuch count --output=threads --exclude=false tag:test)
+test_expect_equal "$output" "5"
+
+test_begin_subtest "Count, default exclusion: tag in query (messages)"
+output=$(notmuch count tag:test and tag:deleted)
+test_expect_equal "$output" "4"
+
+test_begin_subtest "Count, default exclusion: tag in query (threads)"
+output=$(notmuch count --output=threads tag:test and tag:deleted)
+test_expect_equal "$output" "3"
+
+test_begin_subtest "Count, exclude=true: tag in query (messages)"
+output=$(notmuch count --exclude=true tag:test and tag:deleted)
+test_expect_equal "$output" "4"
+
+test_begin_subtest "Count, exclude=true: tag in query (threads)"
+output=$(notmuch count --output=threads --exclude=true tag:test and tag:deleted)
+test_expect_equal "$output" "3"
+
+test_begin_subtest "Count, exclude=false: tag in query (messages)"
+output=$(notmuch count --exclude=false tag:test and tag:deleted)
+test_expect_equal "$output" "4"
+
+test_begin_subtest "Count, exclude=false: tag in query (threads)"
+output=$(notmuch count --output=threads --exclude=false tag:test and tag:deleted)
+test_expect_equal "$output" "3"
+
+#############################################################
+# Show tests
+
+test_begin_subtest "Show, default exclusion"
+output=$(notmuch show tag:test | notmuch_show_sanitize_all | egrep "Subject:|message{")
+test_expect_equal "$output" " message{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 4
+ message{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 3"
+
+test_begin_subtest "Show, default exclusion (entire-thread)"
+output=$(notmuch show --entire-thread tag:test | notmuch_show_sanitize_all | egrep "Subject:|message{")
+test_expect_equal "$output" " message{ id:XXXXX depth:0 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: top message
+ message{ id:XXXXX depth:1 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 1
+ message{ id:XXXXX depth:2 match:0 excluded:1 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 2
+ message{ id:XXXXX depth:3 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 3
+ message{ id:XXXXX depth:4 match:1 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 4
+ message{ id:XXXXX depth:5 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 5
+ message{ id:XXXXX depth:0 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: top message
+ message{ id:XXXXX depth:1 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 1
+ message{ id:XXXXX depth:2 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 2
+ message{ id:XXXXX depth:3 match:1 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 3
+ message{ id:XXXXX depth:4 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 4
+ message{ id:XXXXX depth:5 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 5"
+
+test_begin_subtest "Show, exclude=true"
+output=$(notmuch show --exclude=true tag:test | notmuch_show_sanitize_all | egrep "Subject:|message{")
+test_expect_equal "$output" " message{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 4
+ message{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 3"
+
+test_begin_subtest "Show, exclude=true (entire-thread)"
+output=$(notmuch show --entire-thread --exclude=true tag:test | notmuch_show_sanitize_all | egrep "Subject:|message{")
+test_expect_equal "$output" " message{ id:XXXXX depth:0 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: top message
+ message{ id:XXXXX depth:1 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 1
+ message{ id:XXXXX depth:2 match:0 excluded:1 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 2
+ message{ id:XXXXX depth:3 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 3
+ message{ id:XXXXX depth:4 match:1 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 4
+ message{ id:XXXXX depth:5 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 5
+ message{ id:XXXXX depth:0 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: top message
+ message{ id:XXXXX depth:1 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 1
+ message{ id:XXXXX depth:2 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 2
+ message{ id:XXXXX depth:3 match:1 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 3
+ message{ id:XXXXX depth:4 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 4
+ message{ id:XXXXX depth:5 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 5"
+
+test_begin_subtest "Show, exclude=false"
+output=$(notmuch show --exclude=false tag:test | notmuch_show_sanitize_all | egrep "Subject:|message{")
+test_expect_equal "$output" " message{ id:XXXXX depth:0 match:1 excluded:1 filename:XXXXX
+Subject: All messages excluded: single match: reply 2
+ message{ id:XXXXX depth:0 match:1 excluded:1 filename:XXXXX
+Subject: All messages excluded: double match: reply 2
+ message{ id:XXXXX depth:1 match:1 excluded:1 filename:XXXXX
+Subject: All messages excluded: double match: reply 4
+ message{ id:XXXXX depth:0 match:1 excluded:1 filename:XXXXX
+Subject: Some messages excluded: single excluded match: reply 3
+ message{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 4
+ message{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 3"
+
+test_begin_subtest "Show, exclude=false (entire-thread)"
+output=$(notmuch show --entire-thread --exclude=false tag:test | notmuch_show_sanitize_all | egrep "Subject:|message{")
+test_expect_equal "$output" " message{ id:XXXXX depth:0 match:0 excluded:1 filename:XXXXX
+Subject: All messages excluded: single match: top message
+ message{ id:XXXXX depth:1 match:0 excluded:1 filename:XXXXX
+Subject: All messages excluded: single match: reply 1
+ message{ id:XXXXX depth:2 match:1 excluded:1 filename:XXXXX
+Subject: All messages excluded: single match: reply 2
+ message{ id:XXXXX depth:3 match:0 excluded:1 filename:XXXXX
+Subject: All messages excluded: single match: reply 3
+ message{ id:XXXXX depth:4 match:0 excluded:1 filename:XXXXX
+Subject: All messages excluded: single match: reply 4
+ message{ id:XXXXX depth:5 match:0 excluded:1 filename:XXXXX
+Subject: All messages excluded: single match: reply 5
+ message{ id:XXXXX depth:0 match:0 excluded:1 filename:XXXXX
+Subject: All messages excluded: double match: top message
+ message{ id:XXXXX depth:1 match:0 excluded:1 filename:XXXXX
+Subject: All messages excluded: double match: reply 1
+ message{ id:XXXXX depth:2 match:1 excluded:1 filename:XXXXX
+Subject: All messages excluded: double match: reply 2
+ message{ id:XXXXX depth:3 match:0 excluded:1 filename:XXXXX
+Subject: All messages excluded: double match: reply 3
+ message{ id:XXXXX depth:4 match:1 excluded:1 filename:XXXXX
+Subject: All messages excluded: double match: reply 4
+ message{ id:XXXXX depth:5 match:0 excluded:1 filename:XXXXX
+Subject: All messages excluded: double match: reply 5
+ message{ id:XXXXX depth:0 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single excluded match: top message
+ message{ id:XXXXX depth:1 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single excluded match: reply 1
+ message{ id:XXXXX depth:2 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single excluded match: reply 2
+ message{ id:XXXXX depth:3 match:1 excluded:1 filename:XXXXX
+Subject: Some messages excluded: single excluded match: reply 3
+ message{ id:XXXXX depth:4 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single excluded match: reply 4
+ message{ id:XXXXX depth:5 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single excluded match: reply 5
+ message{ id:XXXXX depth:0 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: top message
+ message{ id:XXXXX depth:1 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 1
+ message{ id:XXXXX depth:2 match:0 excluded:1 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 2
+ message{ id:XXXXX depth:3 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 3
+ message{ id:XXXXX depth:4 match:1 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 4
+ message{ id:XXXXX depth:5 match:0 excluded:0 filename:XXXXX
+Subject: Some messages excluded: single non-excluded match: reply 5
+ message{ id:XXXXX depth:0 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: top message
+ message{ id:XXXXX depth:1 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 1
+ message{ id:XXXXX depth:2 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 2
+ message{ id:XXXXX depth:3 match:1 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 3
+ message{ id:XXXXX depth:4 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 4
+ message{ id:XXXXX depth:5 match:0 excluded:0 filename:XXXXX
+Subject: No messages excluded: single match: reply 5"
+
+
+test_done
diff --git a/test/from-guessing b/test/from-guessing
index 8b69cf6..6dfaa40 100755
--- a/test/from-guessing
+++ b/test/from-guessing
@@ -4,10 +4,10 @@ test_description="From line heuristics (with multiple configured addresses)"
test_begin_subtest "Magic from guessing (nothing to go on)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -21,11 +21,11 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Magic from guessing (Envelope-to:)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- '[header]="Envelope-To: test_suite_other@notmuchmail.org"' \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[header]="Envelope-To: test_suite_other@notmuchmail.org"' \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
@@ -39,11 +39,11 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Magic from guessing (X-Original-To:)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- '[header]="X-Original-To: test_suite_other@notmuchmail.org"' \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[header]="X-Original-To: test_suite_other@notmuchmail.org"' \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
@@ -57,13 +57,13 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Magic from guessing (Received: .. for ..)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
- by mail.notmuchmail.org (some MTA) with ESMTP id 12345678
- for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
+ by mail.notmuchmail.org (some MTA) with ESMTP id 12345678
+ for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
@@ -77,13 +77,13 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Magic from guessing (Received: domain)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
- by mail.otherdomain.org (some MTA) with ESMTP id 12345678
- Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
+ by mail.otherdomain.org (some MTA) with ESMTP id 12345678
+ Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@otherdomain.org>
@@ -97,15 +97,15 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Magic from guessing (multiple Received: headers)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- "[header]=\"Received: from extraneous.example.com (extraneous.example.com [1.1.1.1])
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ "[header]=\"Received: from extraneous.example.com (extraneous.example.com [1.1.1.1])
Received: from mail.example.com (mail.example.com [1.1.1.1])
- by mail.otherdomain.org (some MTA) with ESMTP id 12345678
- for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)
+ by mail.otherdomain.org (some MTA) with ESMTP id 12345678
+ for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)
Received: from extraneous.example.com (extraneous.example.com [1.1.1.1])\"" \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output="$(notmuch reply id:${gen_msg_id})"
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
@@ -123,10 +123,10 @@ test_expect_equal '' ''
test_begin_subtest "Magic from guessing (nothing to go on)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -140,11 +140,11 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Magic from guessing (Envelope-to:)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- '[header]="Envelope-To: test_suite_other@notmuchmail.org"' \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[header]="Envelope-To: test_suite_other@notmuchmail.org"' \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -158,11 +158,11 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Magic from guessing (X-Original-To:)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- '[header]="X-Original-To: test_suite_other@notmuchmail.org"' \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[header]="X-Original-To: test_suite_other@notmuchmail.org"' \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -176,13 +176,13 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Magic from guessing (Received: .. for ..)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
- by mail.notmuchmail.org (some MTA) with ESMTP id 12345678
- for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
+ by mail.notmuchmail.org (some MTA) with ESMTP id 12345678
+ for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -196,13 +196,13 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Magic from guessing (Received: domain)"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=mailinglist@notmuchmail.org \
- [subject]=notmuch-reply-test \
- "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
- by mail.otherdomain.org (some MTA) with ESMTP id 12345678
- Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="from guessing test"'
+ [to]=mailinglist@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ "[header]=\"Received: from mail.example.com (mail.example.com [1.1.1.1])
+ by mail.otherdomain.org (some MTA) with ESMTP id 12345678
+ Sat, 10 Apr 2010 07:54:51 -0400 (EDT)\"" \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="from guessing test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
diff --git a/test/json b/test/json
index 7df4380..ac8fa8e 100755
--- a/test/json
+++ b/test/json
@@ -5,24 +5,34 @@ test_description="--format=json output"
test_begin_subtest "Show message: json"
add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-show-message\""
output=$(notmuch show --format=json "json-show-message")
-test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Cc\": \"\", \"Bcc\": \"\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 -0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
+test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"excluded\": false, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
+
+# This should be the same output as above.
+test_begin_subtest "Show message: json --body=true"
+output=$(notmuch show --format=json --body=true "json-show-message")
+test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"excluded\": false, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
+
+test_begin_subtest "Show message: json --body=false"
+output=$(notmuch show --format=json --body=false "json-show-message")
+test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"excluded\": false, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}}, []]]]"
test_begin_subtest "Search message: json"
add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-search-message\""
output=$(notmuch search --format=json "json-search-message" | notmuch_search_sanitize)
-test_expect_equal "$output" "[{\"thread\": \"XXX\",
-\"timestamp\": 946728000,
-\"date_relative\": \"2000-01-01\",
-\"matched\": 1,
-\"total\": 1,
-\"authors\": \"Notmuch Test Suite\",
-\"subject\": \"json-search-subject\",
-\"tags\": [\"inbox\", \"unread\"]}]"
+test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
+ \"timestamp\": 946728000,
+ \"date_relative\": \"2000-01-01\",
+ \"matched\": 1,
+ \"total\": 1,
+ \"authors\": \"Notmuch Test Suite\",
+ \"subject\": \"json-search-subject\",
+ \"tags\": [\"inbox\",
+ \"unread\"]}]"
test_begin_subtest "Show message: json, utf-8"
add_message "[subject]=\"json-show-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-show-méssage\""
output=$(notmuch show --format=json "jsön-show-méssage")
-test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-utf8-body-sübjéct\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Cc\": \"\", \"Bcc\": \"\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 -0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"jsön-show-méssage\n\"}]}, []]]]"
+test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"excluded\": false, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-utf8-body-sübjéct\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"jsön-show-méssage\n\"}]}, []]]]"
test_begin_subtest "Show message: json, inline attachment filename"
subject='json-show-inline-attachment-filename'
@@ -35,18 +45,19 @@ emacs_deliver_message \
(insert \"Message-ID: <$id>\n\")"
output=$(notmuch show --format=json "id:$id")
filename=$(notmuch search --output=files "id:$id")
-test_expect_equal "$output" "[[[{\"id\": \"$id\", \"match\": true, \"filename\": \"$filename\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\"], \"headers\": {\"Subject\": \"$subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"test_suite@notmuchmail.org\", \"Cc\": \"\", \"Bcc\": \"\", \"Date\": \"01 Jan 2000 12:00:00 -0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"multipart/mixed\", \"content\": [{\"id\": 2, \"content-type\": \"text/plain\", \"content\": \"This is a test message with inline attachment with a filename\"}, {\"id\": 3, \"content-type\": \"application/octet-stream\", \"filename\": \"README\"}]}]}, []]]]"
+test_expect_equal_json "$output" "[[[{\"id\": \"$id\", \"match\": true, \"excluded\": false, \"filename\": \"$filename\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\"], \"headers\": {\"Subject\": \"$subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"test_suite@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"multipart/mixed\", \"content\": [{\"id\": 2, \"content-type\": \"text/plain\", \"content\": \"This is a test message with inline attachment with a filename\"}, {\"id\": 3, \"content-type\": \"application/octet-stream\", \"filename\": \"README\"}]}]}, []]]]"
test_begin_subtest "Search message: json, utf-8"
add_message "[subject]=\"json-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\""
output=$(notmuch search --format=json "jsön-search-méssage" | notmuch_search_sanitize)
-test_expect_equal "$output" "[{\"thread\": \"XXX\",
-\"timestamp\": 946728000,
-\"date_relative\": \"2000-01-01\",
-\"matched\": 1,
-\"total\": 1,
-\"authors\": \"Notmuch Test Suite\",
-\"subject\": \"json-search-utf8-body-sübjéct\",
-\"tags\": [\"inbox\", \"unread\"]}]"
+test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
+ \"timestamp\": 946728000,
+ \"date_relative\": \"2000-01-01\",
+ \"matched\": 1,
+ \"total\": 1,
+ \"authors\": \"Notmuch Test Suite\",
+ \"subject\": \"json-search-utf8-body-sübjéct\",
+ \"tags\": [\"inbox\",
+ \"unread\"]}]"
test_done
diff --git a/test/maildir-sync b/test/maildir-sync
index d5872a5..0fc742a 100755
--- a/test/maildir-sync
+++ b/test/maildir-sync
@@ -4,12 +4,9 @@ test_description="maildir synchronization"
. ./test-lib.sh
-# Much easier to examine differences if the "notmuch show
-# --format=json" output includes some newlines. Also, need to avoid
-# including the local value of MAIL_DIR in the result.
+# Avoid including the local value of MAIL_DIR in the result.
filter_show_json() {
- sed -e 's/, /,\n/g' | sed -e "s|${MAIL_DIR}/|MAIL_DIR/|"
- echo
+ sed -e "s|${MAIL_DIR}/|MAIL_DIR/|"
}
# Create the expected maildir structure
@@ -44,8 +41,9 @@ test_expect_equal "$output" "adding-replied-tag:2,RS"
test_begin_subtest "notmuch show works with renamed file (without notmuch new)"
output=$(notmuch show --format=json id:${gen_msg_id} | filter_show_json)
-test_expect_equal "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite",
+test_expect_equal_json "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite",
"match": true,
+"excluded": false,
"filename": "MAIL_DIR/cur/adding-replied-tag:2,RS",
"timestamp": 978709437,
"date_relative": "2001-01-05",
@@ -53,10 +51,7 @@ test_expect_equal "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite",
"headers": {"Subject": "Adding replied tag",
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
"To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
-"Cc": "",
-"Bcc": "",
-"Date": "Fri,
-05 Jan 2001 15:43:57 +0000"},
+"Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
"body": [{"id": 1,
"content-type": "text/plain",
"content": "This is just a test message (#3)\n"}]},
@@ -129,9 +124,9 @@ mv $MAIL_DIR/cur/adding-replied-tag:2,RS $MAIL_DIR/cur/adding-replied-tag:2,S
mv $MAIL_DIR/cur/adding-s-flag:2,S $MAIL_DIR/cur/adding-s-flag:2,
mv $MAIL_DIR/cur/adding-with-s-flag:2,S $MAIL_DIR/cur/adding-with-s-flag:2,RS
mv $MAIL_DIR/cur/message-to-move-to-cur:2,S $MAIL_DIR/cur/message-to-move-to-cur:2,DS
-notmuch dump dump.txt
+notmuch dump --output=dump.txt
NOTMUCH_NEW >/dev/null
-notmuch restore dump.txt
+notmuch restore --input=dump.txt
output=$(ls $MAIL_DIR/cur)
test_expect_equal "$output" "$expected"
@@ -167,4 +162,13 @@ add_message [subject]='"Non-compliant maildir info"' [dir]=cur [filename]='non-c
notmuch tag +unread +draft -flagged subject:"Non-compliant maildir info"
test_expect_equal "$(cd $MAIL_DIR/cur/; ls non-compliant*)" "non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch"
+test_begin_subtest "Files in new/ get default synchronized tags"
+OLDCONFIG=$(notmuch config get new.tags)
+notmuch config set new.tags test
+add_message [subject]='"File in new/"' [dir]=new [filename]='file-in-new'
+notmuch config set new.tags $OLDCONFIG
+notmuch search 'subject:"File in new"' | notmuch_search_sanitize > output
+test_expect_equal "$(< output)" \
+"thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; File in new/ (test unread)"
+
test_done
diff --git a/test/multipart b/test/multipart
index f83526b..0527f84 100755
--- a/test/multipart
+++ b/test/multipart
@@ -46,6 +46,7 @@ Content-Disposition: inline
EOF
cat embedded_message >> ${MAIL_DIR}/multipart
cat <<EOF >> ${MAIL_DIR}/multipart
+
--=-=-=
Content-Disposition: attachment; filename=attachment
@@ -108,7 +109,7 @@ notmuch new > /dev/null
test_begin_subtest "--format=text --part=0, full message"
notmuch show --format=text --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
- message{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 filename:${MAIL_DIR}/multipart
+ message{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 excluded:0 filename:${MAIL_DIR}/multipart
header{
Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed unread)
Subject: Multipart message
@@ -121,9 +122,9 @@ Date: Fri, 05 Jan 2001 15:43:57 +0000
part{ ID: 2, Content-type: multipart/mixed
part{ ID: 3, Content-type: message/rfc822
header{
+Subject: html message
From: Carl Worth <cworth@cworth.org>
To: cworth@cworth.org
-Subject: html message
Date: Fri, 05 Jan 2001 15:42:57 +0000
header}
body{
@@ -162,9 +163,9 @@ cat <<EOF >EXPECTED
part{ ID: 2, Content-type: multipart/mixed
part{ ID: 3, Content-type: message/rfc822
header{
+Subject: html message
From: Carl Worth <cworth@cworth.org>
To: cworth@cworth.org
-Subject: html message
Date: Fri, 05 Jan 2001 15:42:57 +0000
header}
body{
@@ -200,9 +201,9 @@ cat <<EOF >EXPECTED
part{ ID: 2, Content-type: multipart/mixed
part{ ID: 3, Content-type: message/rfc822
header{
+Subject: html message
From: Carl Worth <cworth@cworth.org>
To: cworth@cworth.org
-Subject: html message
Date: Fri, 05 Jan 2001 15:42:57 +0000
header}
body{
@@ -233,9 +234,9 @@ notmuch show --format=text --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OU
cat <<EOF >EXPECTED
part{ ID: 3, Content-type: message/rfc822
header{
+Subject: html message
From: Carl Worth <cworth@cworth.org>
To: cworth@cworth.org
-Subject: html message
Date: Fri, 05 Jan 2001 15:42:57 +0000
header}
body{
@@ -318,14 +319,12 @@ test_expect_success \
"notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
test_begin_subtest "--format=json --part=0, full message"
-notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
-{"id": "87liy5ap00.fsf@yoom.home.cworth.org", "match": true, "filename": "${MAIL_DIR}/multipart", "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Cc": "", "Bcc": "", "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [
+{"id": "87liy5ap00.fsf@yoom.home.cworth.org", "match": true, "excluded": false, "filename": "${MAIL_DIR}/multipart", "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [
{"id": 1, "content-type": "multipart/signed", "content": [
{"id": 2, "content-type": "multipart/mixed", "content": [
-{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Subject": "html message", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
+{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
{"id": 4, "content-type": "multipart/alternative", "content": [
{"id": 5, "content-type": "text/html"},
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
@@ -333,16 +332,14 @@ cat <<EOF >EXPECTED
{"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]},
{"id": 9, "content-type": "application/pgp-signature"}]}]}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=1, message body"
-notmuch show --format=json --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
{"id": 1, "content-type": "multipart/signed", "content": [
{"id": 2, "content-type": "multipart/mixed", "content": [
-{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Subject": "html message", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
+{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
{"id": 4, "content-type": "multipart/alternative", "content": [
{"id": 5, "content-type": "text/html"},
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
@@ -350,90 +347,74 @@ cat <<EOF >EXPECTED
{"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]},
{"id": 9, "content-type": "application/pgp-signature"}]}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=2, multipart/mixed"
-notmuch show --format=json --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
{"id": 2, "content-type": "multipart/mixed", "content": [
-{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Subject": "html message", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
+{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
{"id": 4, "content-type": "multipart/alternative", "content": [
{"id": 5, "content-type": "text/html"},
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
{"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"},
{"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=3, rfc822 part"
-notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
-{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Subject": "html message", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
+{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
{"id": 4, "content-type": "multipart/alternative", "content": [
{"id": 5, "content-type": "text/html"},
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=4, rfc822's multipart/alternative"
-notmuch show --format=json --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
{"id": 4, "content-type": "multipart/alternative", "content": [
{"id": 5, "content-type": "text/html"},
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=5, rfc822's html part"
-notmuch show --format=json --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
{"id": 5, "content-type": "text/html"}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=6, rfc822's text part"
-notmuch show --format=json --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=7, inline attachment"
-notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
{"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=8, plain text part"
-notmuch show --format=json --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
{"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=9, pgp signature (unverified)"
-notmuch show --format=json --part=9 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
-echo >>OUTPUT # expect *no* newline at end of output
+notmuch show --format=json --part=9 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
-
{"id": 9, "content-type": "application/pgp-signature"}
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_expect_success \
"--format=json --part=10, no part, expect error" \
@@ -449,58 +430,80 @@ test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
test_begin_subtest "--format=raw --part=1, message body"
notmuch show --format=raw --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
-# output should *not* include newline
-echo >>OUTPUT
-cat <<EOF >EXPECTED
-From: Carl Worth <cworth@cworth.org>
-To: cworth@cworth.org
-Subject: html message
-Date: Fri, 05 Jan 2001 15:42:57 +0000
-
-<p>This is an embedded message, with a multipart/alternative part.</p>
-This is an embedded message, with a multipart/alternative part.
-This is a text attachment.
-And this message is signed.
-
--Carl
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.11 (GNU/Linux)
-
-iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
-W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
-=zkga
------END PGP SIGNATURE-----
-EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
test_begin_subtest "--format=raw --part=2, multipart/mixed"
notmuch show --format=raw --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
+Content-Type: multipart/mixed; boundary="=-=-="
+
+--=-=-=
+Content-Type: message/rfc822
+Content-Disposition: inline
+
From: Carl Worth <cworth@cworth.org>
To: cworth@cworth.org
Subject: html message
Date: Fri, 05 Jan 2001 15:42:57 +0000
+User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
+Message-ID: <87liy5ap01.fsf@yoom.home.cworth.org>
+MIME-Version: 1.0
+Content-Type: multipart/alternative; boundary="==-=-=="
+
+--==-=-==
+Content-Type: text/html
<p>This is an embedded message, with a multipart/alternative part.</p>
+
+--==-=-==
+Content-Type: text/plain
+
This is an embedded message, with a multipart/alternative part.
+
+--==-=-==--
+
+--=-=-=
+Content-Disposition: attachment; filename=attachment
+
This is a text attachment.
+
+--=-=-=
+
And this message is signed.
-Carl
+
+--=-=-=--
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "--format=raw --part=3, rfc822 part"
-test_subtest_known_broken
-
notmuch show --format=raw --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
test_expect_equal_file OUTPUT embedded_message
-test_begin_subtest "--format=raw --part=4, rfc822's html part"
+test_begin_subtest "--format=raw --part=4, rfc822's multipart"
notmuch show --format=raw --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
+From: Carl Worth <cworth@cworth.org>
+To: cworth@cworth.org
+Subject: html message
+Date: Fri, 05 Jan 2001 15:42:57 +0000
+User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
+Message-ID: <87liy5ap01.fsf@yoom.home.cworth.org>
+MIME-Version: 1.0
+Content-Type: multipart/alternative; boundary="==-=-=="
+
+--==-=-==
+Content-Type: text/html
+
<p>This is an embedded message, with a multipart/alternative part.</p>
+
+--==-=-==
+Content-Type: text/plain
+
This is an embedded message, with a multipart/alternative part.
+
+--==-=-==--
EOF
test_expect_equal_file OUTPUT EXPECTED
@@ -589,9 +592,57 @@ Non-text part: text/html
EOF
test_expect_equal_file OUTPUT EXPECTED
+test_begin_subtest "'notmuch reply' to a multipart message with json format"
+notmuch reply --format=json 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT
+cat <<EOF >EXPECTED
+{"reply-headers": {"Subject": "Re: Multipart message",
+ "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
+ "To": "Carl Worth <cworth@cworth.org>, cworth@cworth.org",
+ "In-reply-to": "<87liy5ap00.fsf@yoom.home.cworth.org>",
+ "References": " <87liy5ap00.fsf@yoom.home.cworth.org>"},
+ "original": {"id": "XXXXX",
+ "match": false,
+ "excluded": false,
+ "filename": "YYYYY",
+ "timestamp": 978709437,
+ "date_relative": "2001-01-05",
+ "tags": ["attachment","inbox","signed","unread"],
+ "headers": {"Subject": "Multipart message",
+ "From": "Carl Worth <cworth@cworth.org>",
+ "To": "cworth@cworth.org",
+ "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
+ "body": [{"id": 1,
+ "content-type": "multipart/signed",
+ "content": [{"id": 2,
+ "content-type": "multipart/mixed",
+ "content": [{"id": 3,
+ "content-type": "message/rfc822",
+ "content": [{"headers": {"Subject": "html message",
+ "From": "Carl Worth <cworth@cworth.org>",
+ "To": "cworth@cworth.org",
+ "Date": "Fri, 05 Jan 2001 15:42:57 +0000"},
+ "body": [{"id": 4,
+ "content-type": "multipart/alternative",
+ "content": [{"id": 5,
+ "content-type": "text/html"},
+ {"id": 6,
+ "content-type": "text/plain",
+ "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
+ {"id": 7,
+ "content-type": "text/plain",
+ "filename": "YYYYY",
+ "content": "This is a text attachment.\n"},
+ {"id": 8,
+ "content-type": "text/plain",
+ "content": "And this message is signed.\n\n-Carl\n"}]},
+ {"id": 9,
+ "content-type": "application/pgp-signature"}]}]}}
+EOF
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
+
test_begin_subtest "'notmuch show --part' does not corrupt a part with CRLF pair"
notmuch show --format=raw --part=3 id:base64-part-with-crlf > crlf.out
echo -n -e "\xEF\x0D\x0A" > crlf.expected
test_expect_equal_file crlf.out crlf.expected
-test_done
+test_done \ No newline at end of file
diff --git a/test/new b/test/new
index 49f390d..cab7c01 100755
--- a/test/new
+++ b/test/new
@@ -117,10 +117,10 @@ test_expect_equal "$output" "No new mail. Removed 3 messages."
test_begin_subtest "New symlink to directory"
rm -rf "${MAIL_DIR}"/.notmuch
-mv "${MAIL_DIR}" "$PWD"/actual_maildir
+mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
mkdir "${MAIL_DIR}"
-ln -s "$PWD"/actual_maildir "${MAIL_DIR}"/symlink
+ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
output=$(NOTMUCH_NEW)
test_expect_equal "$output" "Added 1 new message to the database."
@@ -128,7 +128,7 @@ test_expect_equal "$output" "Added 1 new message to the database."
test_begin_subtest "New symlink to a file"
generate_message
-external_msg_filename="$PWD"/external/"$(basename "$gen_msg_filename")"
+external_msg_filename="${TMP_DIRECTORY}"/external/"$(basename "$gen_msg_filename")"
mkdir -p "$(dirname "$external_msg_filename")"
mv "$gen_msg_filename" "$external_msg_filename"
ln -s "$external_msg_filename" "$gen_msg_filename"
@@ -136,6 +136,16 @@ output=$(NOTMUCH_NEW)
test_expect_equal "$output" "Added 1 new message to the database."
+test_begin_subtest "Broken symlink aborts"
+ln -s does-not-exist "${MAIL_DIR}/broken"
+output=$(NOTMUCH_NEW 2>&1)
+test_expect_equal "$output" \
+"Error reading file ${MAIL_DIR}/broken: No such file or directory
+Note: A fatal error was encountered: Something went wrong trying to read or write a file
+No new mail."
+rm "${MAIL_DIR}/broken"
+
+
test_begin_subtest "New two-level directory"
generate_message [dir]=two/levels
@@ -153,4 +163,25 @@ rm -rf "${MAIL_DIR}"/two
output=$(NOTMUCH_NEW)
test_expect_equal "$output" "No new mail. Removed 3 messages."
+# This test requires that notmuch new has been run at least once.
+test_begin_subtest "Skip and report non-mail files"
+generate_message
+mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
+touch "${MAIL_DIR}"/ignored_file
+touch "${MAIL_DIR}"/.ignored_hidden_file
+output=$(NOTMUCH_NEW 2>&1)
+test_expect_equal "$output" \
+"Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
+Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
+Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
+Added 1 new message to the database."
+
+test_begin_subtest "Ignore files and directories specified in new.ignore"
+generate_message
+notmuch config set new.ignore .git ignored_file .ignored_hidden_file
+touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
+output=$(NOTMUCH_NEW 2>&1)
+test_expect_equal "$output" "Added 1 new message to the database."
+
+
test_done
diff --git a/test/notmuch-test b/test/notmuch-test
index e40ef86..ea39dfc 100755
--- a/test/notmuch-test
+++ b/test/notmuch-test
@@ -19,6 +19,7 @@ cd $(dirname "$0")
TESTS="
basic
help-test
+ config
new
count
search
@@ -27,12 +28,15 @@ TESTS="
search-position-overlap-bug
search-insufficient-from-quoting
search-limiting
+ excludes
tagging
json
+ text
multipart
thread-naming
raw
reply
+ reply-to-sender
dump-restore
uuencode
thread-order
@@ -51,6 +55,10 @@ TESTS="
python
hooks
argument-parsing
+ emacs-test-functions
+ emacs-address-cleaning
+ emacs-hello
+ emacs-show
"
TESTS=${NOTMUCH_TESTS:=$TESTS}
diff --git a/test/python b/test/python
index 6018c2d..3f03a2e 100755
--- a/test/python
+++ b/test/python
@@ -28,4 +28,12 @@ EOF
notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED
test_expect_equal_file OUTPUT EXPECTED
+test_begin_subtest "get non-existent file"
+test_python <<EOF
+import notmuch
+db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
+print db.find_message_by_filename("i-dont-exist")
+EOF
+test_expect_equal "$(cat OUTPUT)" "None"
+
test_done
diff --git a/test/raw b/test/raw
index 0171e64..de0b867 100755
--- a/test/raw
+++ b/test/raw
@@ -3,11 +3,8 @@
test_description='notmuch show --format=raw'
. ./test-lib.sh
-test_begin_subtest "Generate some messages"
-generate_message
-generate_message
-output=$(NOTMUCH_NEW)
-test_expect_equal "$output" "Added 2 new messages to the database."
+add_message
+add_message
test_begin_subtest "Attempt to show multiple raw messages"
output=$(notmuch show --format=raw "*" 2>&1)
diff --git a/test/reply b/test/reply
index c0b8e26..ee5d361 100755
--- a/test/reply
+++ b/test/reply
@@ -4,10 +4,10 @@ test_description="\"notmuch reply\" in several variations"
test_begin_subtest "Basic reply"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=test_suite@notmuchmail.org \
- [subject]=notmuch-reply-test \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="basic reply test"'
+ [to]=test_suite@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="basic reply test"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -21,10 +21,10 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Multiple recipients"
add_message '[from]="Sender <sender@example.com>"' \
- '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
- [subject]=notmuch-reply-test \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="Multiple recipients"'
+ '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="Multiple recipients"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -38,11 +38,11 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Reply with CC"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=test_suite@notmuchmail.org \
- '[cc]="Other Parties <cc@example.com>"' \
- [subject]=notmuch-reply-test \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="reply with CC"'
+ [to]=test_suite@notmuchmail.org \
+ '[cc]="Other Parties <cc@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="reply with CC"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -57,10 +57,10 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Reply from alternate address"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=test_suite_other@notmuchmail.org \
- [subject]=notmuch-reply-test \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="reply from alternate address"'
+ [to]=test_suite_other@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="reply from alternate address"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
@@ -72,13 +72,31 @@ References: <${gen_msg_id}>
On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
> reply from alternate address"
-test_begin_subtest "Support for Reply-To"
+test_begin_subtest "Reply from address in named group list"
add_message '[from]="Sender <sender@example.com>"' \
- [to]=test_suite@notmuchmail.org \
+ '[to]=group:test_suite@notmuchmail.org,someone@example.com\;' \
+ [cc]=test_suite_other@notmuchmail.org \
[subject]=notmuch-reply-test \
'[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="support for reply-to"' \
- '[reply-to]="Sender <elsewhere@example.com>"'
+ '[body]="Reply from address in named group list"'
+
+output=$(notmuch reply id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Sender <sender@example.com>, someone@example.com
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> Reply from address in named group list"
+
+test_begin_subtest "Support for Reply-To"
+add_message '[from]="Sender <sender@example.com>"' \
+ [to]=test_suite@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="support for reply-to"' \
+ '[reply-to]="Sender <elsewhere@example.com>"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -92,11 +110,11 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Un-munging Reply-To"
add_message '[from]="Sender <sender@example.com>"' \
- '[to]="Some List <list@example.com>"' \
- [subject]=notmuch-reply-test \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="Un-munging Reply-To"' \
- '[reply-to]="Evil Munging List <list@example.com>"'
+ '[to]="Some List <list@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="Un-munging Reply-To"' \
+ '[reply-to]="Evil Munging List <list@example.com>"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -110,8 +128,8 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
test_begin_subtest "Message with header of exactly 200 bytes"
add_message '[subject]="This subject is exactly 200 bytes in length. Other than its length there is not much of note here. Note that the length of 200 bytes includes the Subject: and Re: prefixes with two spaces"' \
- '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
- '[body]="200-byte header"'
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="200-byte header"'
output=$(notmuch reply id:${gen_msg_id})
test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
Subject: Re: This subject is exactly 200 bytes in length. Other than its length there is not much of note here. Note that the length of 200 bytes includes the Subject: and Re: prefixes with two spaces
@@ -120,4 +138,59 @@ References: <${gen_msg_id}>
On Tue, 05 Jan 2010 15:43:56 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
> 200-byte header"
+
+test_begin_subtest "From guessing: Envelope-To"
+add_message '[from]="Sender <sender@example.com>"' \
+ '[to]="Recipient <recipient@example.com>"' \
+ '[subject]="From guessing"' \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="From guessing"' \
+ '[header]="Envelope-To: test_suite_other@notmuchmail.org"'
+
+output=$(notmuch reply id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
+Subject: Re: From guessing
+To: Sender <sender@example.com>, Recipient <recipient@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> From guessing"
+
+test_begin_subtest "From guessing: X-Original-To"
+add_message '[from]="Sender <sender@example.com>"' \
+ '[to]="Recipient <recipient@example.com>"' \
+ '[subject]="From guessing"' \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="From guessing"' \
+ '[header]="X-Original-To: test_suite@otherdomain.org"'
+
+output=$(notmuch reply id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@otherdomain.org>
+Subject: Re: From guessing
+To: Sender <sender@example.com>, Recipient <recipient@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> From guessing"
+
+test_begin_subtest "From guessing: Delivered-To"
+add_message '[from]="Sender <sender@example.com>"' \
+ '[to]="Recipient <recipient@example.com>"' \
+ '[subject]="From guessing"' \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="From guessing"' \
+ '[header]="Delivered-To: test_suite_other@notmuchmail.org"'
+
+output=$(notmuch reply id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
+Subject: Re: From guessing
+To: Sender <sender@example.com>, Recipient <recipient@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> From guessing"
+
test_done
diff --git a/test/reply-to-sender b/test/reply-to-sender
new file mode 100755
index 0000000..c7d15bb
--- /dev/null
+++ b/test/reply-to-sender
@@ -0,0 +1,209 @@
+#!/usr/bin/env bash
+test_description="\"notmuch reply --reply-to=sender\" in several variations"
+. ./test-lib.sh
+
+test_begin_subtest "Basic reply-to-sender"
+add_message '[from]="Sender <sender@example.com>"' \
+ [to]=test_suite@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="basic reply-to-sender test"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Sender <sender@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> basic reply-to-sender test"
+
+test_begin_subtest "From Us, Basic reply to message"
+add_message '[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"' \
+ '[to]="Recipient <recipient@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="basic reply-to-from-us test"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Recipient <recipient@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
+> basic reply-to-from-us test"
+
+test_begin_subtest "Multiple recipients"
+add_message '[from]="Sender <sender@example.com>"' \
+ '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="Multiple recipients"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Sender <sender@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> Multiple recipients"
+
+test_begin_subtest "From Us, Multiple TO recipients"
+add_message '[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"' \
+ '[to]="Recipient <recipient@example.com>, Someone Else <someone@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="From Us, Multiple TO recipients"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Recipient <recipient@example.com>, Someone Else <someone@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
+> From Us, Multiple TO recipients"
+
+test_begin_subtest "Reply with CC"
+add_message '[from]="Sender <sender@example.com>"' \
+ [to]=test_suite@notmuchmail.org \
+ '[cc]="Other Parties <cc@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="reply with CC"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Sender <sender@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> reply with CC"
+
+test_begin_subtest "From Us, Reply with CC"
+add_message '[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"' \
+ '[to]="Recipient <recipient@example.com>"' \
+ '[cc]="Other Parties <cc@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="reply with CC"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Recipient <recipient@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
+> reply with CC"
+
+test_begin_subtest "From Us, Reply no TO but with CC"
+add_message '[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"' \
+ '[cc]="Other Parties <cc@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="reply with CC"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+Cc: Other Parties <cc@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
+> reply with CC"
+
+test_begin_subtest "Reply from alternate address"
+add_message '[from]="Sender <sender@example.com>"' \
+ [to]=test_suite_other@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="reply from alternate address"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Sender <sender@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> reply from alternate address"
+
+test_begin_subtest "Support for Reply-To"
+add_message '[from]="Sender <sender@example.com>"' \
+ [to]=test_suite@notmuchmail.org \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="support for reply-to"' \
+ '[reply-to]="Sender <elsewhere@example.com>"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Sender <elsewhere@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> support for reply-to"
+
+test_begin_subtest "Support for Reply-To with multiple recipients"
+add_message '[from]="Sender <sender@example.com>"' \
+ '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="support for reply-to with multiple recipients"' \
+ '[reply-to]="Sender <elsewhere@example.com>"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Sender <elsewhere@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> support for reply-to with multiple recipients"
+
+test_begin_subtest "Un-munging Reply-To"
+add_message '[from]="Sender <sender@example.com>"' \
+ '[to]="Some List <list@example.com>"' \
+ [subject]=notmuch-reply-test \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="Un-munging Reply-To"' \
+ '[reply-to]="Evil Munging List <list@example.com>"'
+
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: notmuch-reply-test
+To: Sender <sender@example.com>
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
+> Un-munging Reply-To"
+
+test_begin_subtest "Message with header of exactly 200 bytes"
+add_message '[subject]="This subject is exactly 200 bytes in length. Other than its length there is not much of note here. Note that the length of 200 bytes includes the Subject: and Re: prefixes with two spaces"' \
+ '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
+ '[body]="200-byte header"'
+output=$(notmuch reply --reply-to=sender id:${gen_msg_id})
+test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
+Subject: Re: This subject is exactly 200 bytes in length. Other than its length there is not much of note here. Note that the length of 200 bytes includes the Subject: and Re: prefixes with two spaces
+In-Reply-To: <${gen_msg_id}>
+References: <${gen_msg_id}>
+
+On Tue, 05 Jan 2010 15:43:56 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
+> 200-byte header"
+test_done
diff --git a/test/search-folder-coherence b/test/search-folder-coherence
index f8119cb..3f6ec76 100755
--- a/test/search-folder-coherence
+++ b/test/search-folder-coherence
@@ -32,7 +32,7 @@ test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Test matches folder:spam"
output=$(notmuch search folder:spam)
-test_expect_equal "$output" "thread:0000000000000001 2001-01-05 [1/1] Notmuch Test Suite; Test message #1 (inbox unread)"
+test_expect_equal "$output" "thread:0000000000000001 2001-01-05 [1/1] Notmuch Test Suite; Single new message (inbox unread)"
test_begin_subtest "Remove folder:spam copy of email"
rm $dir/spam/$(basename $file_x)
diff --git a/test/search-output b/test/search-output
index 8b57a43..c2a87eb 100755
--- a/test/search-output
+++ b/test/search-output
@@ -62,7 +62,7 @@ cat <<EOF >EXPECTED
"THREADID",
"THREADID"]
EOF
-test_expect_equal_file OUTPUT EXPECTED
+test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--output=messages"
notmuch search --output=messages '*' >OUTPUT
diff --git a/test/search-position-overlap-bug b/test/search-position-overlap-bug
index 414b8d5..5da6ad6 100755
--- a/test/search-position-overlap-bug
+++ b/test/search-position-overlap-bug
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Test to demonstrate a position overlap bug.
-#
+#
# At one point, notmuch would index terms incorrectly in the case of
# calling index_terms multiple times for a single field. The term
# generator was being reset to position 0 each time. This means that
@@ -12,7 +12,7 @@
# one could get a bogus match by searching for:
#
# To: a@y.c
-#
+#
# Thanks to Mark Anderson for reporting the bug, (and providing a nice,
# minimal test case that inspired what is used here), in
# id:3wd4o8wa7fx.fsf@testarossa.amd.com
diff --git a/test/symbol-hiding b/test/symbol-hiding
index 7fa7b2a..636ec91 100755
--- a/test/symbol-hiding
+++ b/test/symbol-hiding
@@ -23,7 +23,7 @@ mkdir -p fakedb/.notmuch
test_expect_success 'running test' run_test
test_begin_subtest 'checking output'
-test_expect_equal "$result" "$output"
+test_expect_equal "$result" "$output"
test_begin_subtest 'comparing existing to exported symbols'
objdump -t $TEST_DIRECTORY/../lib/*.o | awk '$4 == ".text" && $6 ~ "^notmuch" {print $6}' | sort | uniq > ACTUAL
diff --git a/test/symbol-test.cc b/test/symbol-test.cc
index 1548ca4..3e96c03 100644
--- a/test/symbol-test.cc
+++ b/test/symbol-test.cc
@@ -4,7 +4,8 @@
int main() {
- (void) notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY);
+ notmuch_database_t *notmuch;
+ notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch);
try {
(void) new Xapian::WritableDatabase("./nonexistant", Xapian::DB_OPEN);
diff --git a/test/tagging b/test/tagging
index 77202bf..e4782ed 100755
--- a/test/tagging
+++ b/test/tagging
@@ -38,4 +38,12 @@ test_expect_equal "$output" "\
thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; One (:\" inbox tag1 unread)
thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 unread)"
+test_begin_subtest "Tagging order"
+notmuch tag +tag4 -tag4 One
+notmuch tag -tag4 +tag4 Two
+output=$(notmuch search \* | notmuch_search_sanitize)
+test_expect_equal "$output" "\
+thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; One (:\" inbox tag1 unread)
+thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag4 unread)"
+
test_done
diff --git a/test/test-lib.el b/test/test-lib.el
index 3b817c3..5dd6271 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -20,12 +20,21 @@
;;
;; Authors: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
+(require 'cl) ;; This code is generally used uncompiled.
+
;; `read-file-name' by default uses `completing-read' function to read
;; user input. It does not respect `standard-input' variable which we
;; use in tests to provide user input. So replace it with a plain
;; `read' call.
(setq read-file-name-function (lambda (&rest _) (read)))
+;; Work around a bug in emacs 23.1 and emacs 23.2 which prevents
+;; noninteractive (kill-emacs) from emacsclient.
+(if (and (= emacs-major-version 23) (< emacs-minor-version 3))
+ (defadvice kill-emacs (before disable-yes-or-no-p activate)
+ "Disable yes-or-no-p before executing kill-emacs"
+ (defun yes-or-no-p (prompt) t)))
+
(defun notmuch-test-wait ()
"Wait for process completion."
(while (get-buffer-process (current-buffer))
@@ -42,16 +51,19 @@ FILENAME is OUTPUT."
(with-temp-file (or filename "OUTPUT") (insert text))))
(defun visible-buffer-string ()
- "Same as `buffer-string', but excludes invisible text."
+ "Same as `buffer-string', but excludes invisible text and
+removes any text properties."
(visible-buffer-substring (point-min) (point-max)))
(defun visible-buffer-substring (start end)
- "Same as `buffer-substring', but excludes invisible text."
+ "Same as `buffer-substring-no-properties', but excludes
+invisible text."
(let (str)
(while (< start end)
(let ((next-pos (next-char-property-change start end)))
(when (not (invisible-p start))
- (setq str (concat str (buffer-substring start next-pos))))
+ (setq str (concat str (buffer-substring-no-properties
+ start next-pos))))
(setq start next-pos)))
str))
@@ -76,3 +88,46 @@ nothing."
(add-hook-counter 'notmuch-hello-mode-hook)
(add-hook-counter 'notmuch-hello-refresh-hook)
+
+(defadvice notmuch-search-process-filter (around pessimal activate disable)
+ "Feed notmuch-search-process-filter one character at a time."
+ (let ((string (ad-get-arg 1)))
+ (loop for char across string
+ do (progn
+ (ad-set-arg 1 (char-to-string char))
+ ad-do-it))))
+
+(defmacro notmuch-test-run (&rest body)
+ "Evaluate a BODY of test expressions and output the result."
+ `(with-temp-buffer
+ (let ((buffer (current-buffer))
+ (result (progn ,@body)))
+ (switch-to-buffer buffer)
+ (insert (if (stringp result)
+ result
+ (prin1-to-string result)))
+ (test-output))))
+
+(defun notmuch-test-report-unexpected (output expected)
+ "Report that the OUTPUT does not match the EXPECTED result."
+ (concat "Expect:\t" (prin1-to-string expected) "\n"
+ "Output:\t" (prin1-to-string output) "\n"))
+
+(defun notmuch-test-expect-equal (output expected)
+ "Compare OUTPUT with EXPECTED. Report any discrepencies."
+ (if (equal output expected)
+ t
+ (cond
+ ((and (listp output)
+ (listp expected))
+ ;; Reporting the difference between two lists is done by
+ ;; reporting differing elements of OUTPUT and EXPECTED
+ ;; pairwise. This is expected to make analysis of failures
+ ;; simpler.
+ (apply #'concat (loop for o in output
+ for e in expected
+ if (not (equal o e))
+ collect (notmuch-test-report-unexpected o e))))
+
+ (t
+ (notmuch-test-report-unexpected output expected)))))
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 82767c0..791d2dc 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -140,7 +140,7 @@ if test -n "$color"; then
esac
shift
printf " "
- printf "$@"
+ printf "$@"
tput sgr0
print_subtest
)
@@ -150,7 +150,7 @@ else
test -z "$1" && test -n "$quiet" && return
shift
printf " "
- printf "$@"
+ printf "$@"
print_subtest
}
fi
@@ -249,7 +249,7 @@ remove_cr () {
# Store the message in file 'name'. The default is to store it
# in 'msg-<count>', where <count> is three-digit number of the
# message.
-#
+#
# [body]=text
#
# Text to use as the body of the email message
@@ -318,7 +318,11 @@ generate_message ()
fi
if [ -z "${template[subject]}" ]; then
- template[subject]="Test message #${gen_msg_cnt}"
+ if [ -n "$test_subtest_name" ]; then
+ template[subject]="$test_subtest_name"
+ else
+ template[subject]="Test message #${gen_msg_cnt}"
+ fi
fi
if [ -z "${template[date]}" ]; then
@@ -356,6 +360,11 @@ ${additional_headers}"
${additional_headers}"
fi
+ if [ ! -z "${template[content-transfer-encoding]}" ]; then
+ additional_headers="Content-Transfer-Encoding: ${template[content-transfer-encoding]}
+${additional_headers}"
+ fi
+
# Note that in the way we're setting it above and using it below,
# `additional_headers' will also serve as the header / body separator
# (empty line in between).
@@ -503,6 +512,45 @@ test_expect_equal_file ()
fi
}
+# Like test_expect_equal, but arguments are JSON expressions to be
+# canonicalized before diff'ing. If an argument cannot be parsed, it
+# is used unchanged so that there's something to diff against.
+test_expect_equal_json () {
+ output=$(echo "$1" | python -mjson.tool || echo "$1")
+ expected=$(echo "$2" | python -mjson.tool || echo "$2")
+ shift 2
+ test_expect_equal "$output" "$expected" "$@"
+}
+
+test_emacs_expect_t () {
+ test "$#" = 2 && { prereq=$1; shift; } || prereq=
+ test "$#" = 1 ||
+ error "bug in the test script: not 1 or 2 parameters to test_emacs_expect_t"
+
+ # Run the test.
+ if ! test_skip "$test_subtest_name"
+ then
+ test_emacs "(notmuch-test-run $1)" >/dev/null
+
+ # Restore state after the test.
+ exec 1>&6 2>&7 # Restore stdout and stderr
+ inside_subtest=
+
+ # Report success/failure.
+ result=$(cat OUTPUT)
+ if [ "$result" = t ]
+ then
+ test_ok_ "$test_subtest_name"
+ else
+ test_failure_ "$test_subtest_name" "${result}"
+ fi
+ else
+ # Restore state after the (non) test.
+ exec 1>&6 2>&7 # Restore stdout and stderr
+ inside_subtest=
+ fi
+}
+
NOTMUCH_NEW ()
{
notmuch new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
@@ -527,10 +575,9 @@ notmuch_show_sanitize_all ()
notmuch_json_show_sanitize ()
{
- sed -e 's|, |,\n |g' | \
- sed \
- -e 's|"id": "[^"]*",|"id": "XXXXX",|' \
- -e 's|"filename": "[^"]*",|"filename": "YYYYY",|'
+ sed \
+ -e 's|"id": "[^"]*",|"id": "XXXXX",|g' \
+ -e 's|"filename": "[^"]*",|"filename": "YYYYY",|g'
}
# End of notmuch helper functions
@@ -673,8 +720,8 @@ test_skip () {
test_check_missing_external_prereqs_ () {
if test -n "$test_subtest_missing_external_prereqs_"; then
- say_color skip >&3 "missing prerequisites:"
- echo "$test_subtest_missing_external_prereqs_" >&3
+ say_color skip >&1 "missing prerequisites:"
+ echo "$test_subtest_missing_external_prereqs_" >&1
test_report_skip_ "$@"
else
false
@@ -869,7 +916,7 @@ test_done () {
[ -n "$EMACS_SERVER" ] && test_emacs '(kill-emacs)'
if [ "$test_failure" = "0" ]; then
- if [ "$test_broken" = "0" ]; then
+ if [ "$test_broken" = "0" ]; then
rm -rf "$remove_tmp"
fi
exit 0
@@ -881,7 +928,7 @@ test_done () {
emacs_generate_script () {
# Construct a little test script here for the benefit of the user,
# (who can easily run "run_emacs" to get the same emacs environment
- # for investigating any failures).
+ # for investigating any failures).
cat <<EOF >"$TMP_DIRECTORY/run_emacs"
#!/bin/sh
export PATH=$PATH
@@ -907,10 +954,19 @@ EOF
test_emacs () {
# test dependencies beforehand to avoid the waiting loop below
- test_require_external_prereq emacs || return
- test_require_external_prereq emacsclient || return
+ missing_dependencies=
+ test_require_external_prereq dtach || missing_dependencies=1
+ test_require_external_prereq emacs || missing_dependencies=1
+ test_require_external_prereq emacsclient || missing_dependencies=1
+ test -z "$missing_dependencies" || return
if [ -z "$EMACS_SERVER" ]; then
+ emacs_tests="$(basename $0).el"
+ if [ -f "$TEST_DIRECTORY/$emacs_tests" ]; then
+ load_emacs_tests="--eval '(load \"$emacs_tests\")'"
+ else
+ load_emacs_tests=
+ fi
server_name="notmuch-test-suite-$$"
# start a detached session with an emacs server
# user's TERM is given to dtach which assumes a minimally
@@ -918,12 +974,13 @@ test_emacs () {
TERM=$ORIGINAL_TERM dtach -n "$TEST_TMPDIR/emacs-dtach-socket.$$" \
sh -c "stty rows 24 cols 80; exec '$TMP_DIRECTORY/run_emacs' \
--no-window-system \
+ $load_emacs_tests \
--eval '(setq server-name \"$server_name\")' \
--eval '(server-start)' \
--eval '(orphan-watchdog $$)'" || return
EMACS_SERVER="$server_name"
# wait until the emacs server is up
- until test_emacs '()' 2>/dev/null; do
+ until test_emacs '()' >/dev/null 2>/dev/null; do
sleep 1
done
fi
diff --git a/test/text b/test/text
new file mode 100755
index 0000000..428c89b
--- /dev/null
+++ b/test/text
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+test_description="--format=text output"
+. ./test-lib.sh
+
+test_begin_subtest "Show message: text"
+add_message "[subject]=\"text-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"text-show-message\""
+output=$(notmuch show --format=text "text-show-message" | notmuch_show_sanitize_all)
+test_expect_equal "$output" "\
+ message{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
+ header{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (inbox unread)
+Subject: text-show-subject
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Sat, 01 Jan 2000 12:00:00 +0000
+ header}
+ body{
+ part{ ID: 1, Content-type: text/plain
+text-show-message
+ part}
+ body}
+ message}"
+
+test_begin_subtest "Search message: text"
+add_message "[subject]=\"text-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"text-search-message\""
+output=$(notmuch search --format=text "text-search-message" | notmuch_search_sanitize)
+test_expect_equal "$output" \
+"thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; text-search-subject (inbox unread)"
+
+test_begin_subtest "Show message: text, utf-8"
+add_message "[subject]=\"text-show-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"tëxt-show-méssage\""
+output=$(notmuch show --format=text "tëxt-show-méssage" | notmuch_show_sanitize_all)
+test_expect_equal "$output" "\
+ message{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
+ header{
+Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (inbox unread)
+Subject: text-show-utf8-body-sübjéct
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Sat, 01 Jan 2000 12:00:00 +0000
+ header}
+ body{
+ part{ ID: 1, Content-type: text/plain
+tëxt-show-méssage
+ part}
+ body}
+ message}"
+
+test_begin_subtest "Search message: text, utf-8"
+add_message "[subject]=\"text-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"tëxt-search-méssage\""
+output=$(notmuch search --format=text "tëxt-search-méssage" | notmuch_search_sanitize)
+test_expect_equal "$output" \
+"thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; text-search-utf8-body-sübjéct (inbox unread)"
+
+test_done
diff --git a/test/thread-naming b/test/thread-naming
index 41b97d9..1a1a48f 100755
--- a/test/thread-naming
+++ b/test/thread-naming
@@ -4,18 +4,18 @@ test_description="naming of threads with changing subject"
test_begin_subtest "Initial thread name (oldest-first search)"
add_message '[subject]="thread-naming: Initial thread subject"' \
- '[date]="Fri, 05 Jan 2001 15:43:56 -0000"'
+ '[date]="Fri, 05 Jan 2001 15:43:56 -0000"'
first=${gen_msg_cnt}
parent=${gen_msg_id}
add_message '[subject]="thread-naming: Older changed subject"' \
- '[date]="Sat, 06 Jan 2001 15:43:56 -0000"' \
- "[in-reply-to]=\<$parent\>"
+ '[date]="Sat, 06 Jan 2001 15:43:56 -0000"' \
+ "[in-reply-to]=\<$parent\>"
add_message '[subject]="thread-naming: Newer changed subject"' \
- '[date]="Sun, 07 Jan 2001 15:43:56 -0000"' \
- "[in-reply-to]=\<$parent\>"
+ '[date]="Sun, 07 Jan 2001 15:43:56 -0000"' \
+ "[in-reply-to]=\<$parent\>"
add_message '[subject]="thread-naming: Final thread subject"' \
- '[date]="Mon, 08 Jan 2001 15:43:56 -0000"' \
- "[in-reply-to]=\<$parent\>"
+ '[date]="Mon, 08 Jan 2001 15:43:56 -0000"' \
+ "[in-reply-to]=\<$parent\>"
final=${gen_msg_id}
output=$(notmuch search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2001-01-05 [4/4] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
@@ -37,41 +37,41 @@ test_expect_equal "$output" "thread:XXX 2001-01-07 [2/4] Notmuch Test Suite; t
test_begin_subtest "Ignore added reply prefix (Re:)"
add_message '[subject]="Re: thread-naming: Initial thread subject"' \
- '[date]="Tue, 09 Jan 2001 15:43:45 -0000"' \
- "[in-reply-to]=\<$parent\>"
+ '[date]="Tue, 09 Jan 2001 15:43:45 -0000"' \
+ "[in-reply-to]=\<$parent\>"
output=$(notmuch search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2001-01-09 [3/5] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
test_begin_subtest "Ignore added reply prefix (Aw:)"
add_message '[subject]="Aw: thread-naming: Initial thread subject"' \
- '[date]="Wed, 10 Jan 2001 15:43:45 -0000"' \
- "[in-reply-to]=\<$parent\>"
+ '[date]="Wed, 10 Jan 2001 15:43:45 -0000"' \
+ "[in-reply-to]=\<$parent\>"
output=$(notmuch search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2001-01-10 [4/6] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
test_begin_subtest "Ignore added reply prefix (Vs:)"
add_message '[subject]="Vs: thread-naming: Initial thread subject"' \
- '[date]="Thu, 11 Jan 2001 15:43:45 -0000"' \
- "[in-reply-to]=\<$parent\>"
+ '[date]="Thu, 11 Jan 2001 15:43:45 -0000"' \
+ "[in-reply-to]=\<$parent\>"
output=$(notmuch search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2001-01-11 [5/7] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
test_begin_subtest "Ignore added reply prefix (Sv:)"
add_message '[subject]="Sv: thread-naming: Initial thread subject"' \
- '[date]="Fri, 12 Jan 2001 15:43:45 -0000"' \
- "[in-reply-to]=\<$parent\>"
+ '[date]="Fri, 12 Jan 2001 15:43:45 -0000"' \
+ "[in-reply-to]=\<$parent\>"
output=$(notmuch search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2001-01-12 [6/8] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
test_begin_subtest 'Test order of messages in "notmuch show"'
output=$(notmuch show thread-naming | notmuch_show_sanitize)
-test_expect_equal "$output" " message{ id:msg-$(printf "%03d" $first)@notmuch-test-suite depth:0 match:1 filename:/XXX/mail/msg-$(printf "%03d" $first)
+test_expect_equal "$output" " message{ id:msg-$(printf "%03d" $first)@notmuch-test-suite depth:0 match:1 excluded:0 filename:/XXX/mail/msg-$(printf "%03d" $first)
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (unread)
Subject: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Fri, 05 Jan 2001 15:43:56 -0000
+Date: Fri, 05 Jan 2001 15:43:56 +0000
header}
body{
part{ ID: 1, Content-type: text/plain
@@ -79,13 +79,13 @@ This is just a test message (#$first)
part}
body}
message}
- message{ id:msg-$(printf "%03d" $((first + 1)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 1)))
+ message{ id:msg-$(printf "%03d" $((first + 1)))@notmuch-test-suite depth:1 match:1 excluded:0 filename:/XXX/mail/msg-$(printf "%03d" $((first + 1)))
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-06) (inbox unread)
Subject: thread-naming: Older changed subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Sat, 06 Jan 2001 15:43:56 -0000
+Date: Sat, 06 Jan 2001 15:43:56 +0000
header}
body{
part{ ID: 1, Content-type: text/plain
@@ -93,13 +93,13 @@ This is just a test message (#$((first + 1)))
part}
body}
message}
- message{ id:msg-$(printf "%03d" $((first + 2)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 2)))
+ message{ id:msg-$(printf "%03d" $((first + 2)))@notmuch-test-suite depth:1 match:1 excluded:0 filename:/XXX/mail/msg-$(printf "%03d" $((first + 2)))
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-07) (inbox unread)
Subject: thread-naming: Newer changed subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Sun, 07 Jan 2001 15:43:56 -0000
+Date: Sun, 07 Jan 2001 15:43:56 +0000
header}
body{
part{ ID: 1, Content-type: text/plain
@@ -107,13 +107,13 @@ This is just a test message (#$((first + 2)))
part}
body}
message}
- message{ id:msg-$(printf "%03d" $((first + 3)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 3)))
+ message{ id:msg-$(printf "%03d" $((first + 3)))@notmuch-test-suite depth:1 match:1 excluded:0 filename:/XXX/mail/msg-$(printf "%03d" $((first + 3)))
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-08) (unread)
Subject: thread-naming: Final thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Mon, 08 Jan 2001 15:43:56 -0000
+Date: Mon, 08 Jan 2001 15:43:56 +0000
header}
body{
part{ ID: 1, Content-type: text/plain
@@ -121,13 +121,13 @@ This is just a test message (#$((first + 3)))
part}
body}
message}
- message{ id:msg-$(printf "%03d" $((first + 4)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 4)))
+ message{ id:msg-$(printf "%03d" $((first + 4)))@notmuch-test-suite depth:1 match:1 excluded:0 filename:/XXX/mail/msg-$(printf "%03d" $((first + 4)))
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-09) (inbox unread)
Subject: Re: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Tue, 09 Jan 2001 15:43:45 -0000
+Date: Tue, 09 Jan 2001 15:43:45 +0000
header}
body{
part{ ID: 1, Content-type: text/plain
@@ -135,13 +135,13 @@ This is just a test message (#$((first + 4)))
part}
body}
message}
- message{ id:msg-$(printf "%03d" $((first + 5)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 5)))
+ message{ id:msg-$(printf "%03d" $((first + 5)))@notmuch-test-suite depth:1 match:1 excluded:0 filename:/XXX/mail/msg-$(printf "%03d" $((first + 5)))
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-10) (inbox unread)
Subject: Aw: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Wed, 10 Jan 2001 15:43:45 -0000
+Date: Wed, 10 Jan 2001 15:43:45 +0000
header}
body{
part{ ID: 1, Content-type: text/plain
@@ -149,13 +149,13 @@ This is just a test message (#$((first + 5)))
part}
body}
message}
- message{ id:msg-$(printf "%03d" $((first + 6)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 6)))
+ message{ id:msg-$(printf "%03d" $((first + 6)))@notmuch-test-suite depth:1 match:1 excluded:0 filename:/XXX/mail/msg-$(printf "%03d" $((first + 6)))
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-11) (inbox unread)
Subject: Vs: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Thu, 11 Jan 2001 15:43:45 -0000
+Date: Thu, 11 Jan 2001 15:43:45 +0000
header}
body{
part{ ID: 1, Content-type: text/plain
@@ -163,13 +163,13 @@ This is just a test message (#$((first + 6)))
part}
body}
message}
- message{ id:msg-$(printf "%03d" $((first + 7)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 7)))
+ message{ id:msg-$(printf "%03d" $((first + 7)))@notmuch-test-suite depth:1 match:1 excluded:0 filename:/XXX/mail/msg-$(printf "%03d" $((first + 7)))
header{
Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-12) (inbox unread)
Subject: Sv: thread-naming: Initial thread subject
From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: Notmuch Test Suite <test_suite@notmuchmail.org>
-Date: Fri, 12 Jan 2001 15:43:45 -0000
+Date: Fri, 12 Jan 2001 15:43:45 +0000
header}
body{
part{ ID: 1, Content-type: text/plain
diff --git a/util/Makefile.local b/util/Makefile.local
index 26e4c3f..c7cae61 100644
--- a/util/Makefile.local
+++ b/util/Makefile.local
@@ -10,4 +10,5 @@ libutil_modules := $(libutil_c_srcs:.c=.o)
$(dir)/libutil.a: $(libutil_modules)
$(call quiet,AR) rcs $@ $^
+SRCS := $(SRCS) $(libutil_c_srcs)
CLEAN := $(CLEAN) $(libutil_modules) $(dir)/libutil.a
diff --git a/version b/version
index 51176c7..9beb74d 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-0.11
+0.13.2
diff --git a/vim/Makefile b/vim/Makefile
index 89e18be..f17bebf 100644
--- a/vim/Makefile
+++ b/vim/Makefile
@@ -1,11 +1,11 @@
.PHONY: all help install link symlink
-FILES = plugin/notmuch.vim \
- $(wildcard syntax/notmuch-*.vim)
+files = plugin/notmuch.vim \
+ $(wildcard syntax/notmuch-*.vim)
+prefix = $(HOME)/.vim
+destdir = $(prefix)/plugin
-PREFIX = $(shell ls -d ~/.vim/)
-
-OUT_FILES = $(FILES:%=${PREFIX}/%)
+INSTALL = install -D -m644
all: help
@@ -16,9 +16,8 @@ help:
@echo " make install - copy plugin scripts and syntax files to ~/.vim"
@echo " make symlink - create symlinks in ~/.vim (useful for development)"
-install: ${OUT_FILES}
-link symlink:
- ${MAKE} SYMLINK=1 install
+install:
+ @for x in $(files); do $(INSTALL) $(CURDIR)/$$x $(prefix)/$$x; done
-${OUT_FILES}: ${PREFIX}/%: %
- $(if ${SYMLINK},ln -fs,cp) `pwd`/$< $@
+link symlink: INSTALL = ln -fs
+link symlink: install
diff --git a/vim/plugin/notmuch.vim b/vim/plugin/notmuch.vim
index 21985c7..8f27fb9 100644
--- a/vim/plugin/notmuch.vim
+++ b/vim/plugin/notmuch.vim
@@ -48,7 +48,7 @@ let s:notmuch_defaults = {
\ 'g:notmuch_show_part_end_regexp': ' part}' ,
\ 'g:notmuch_show_marker_regexp': ' \\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$',
\
- \ 'g:notmuch_show_message_parse_regexp': '\(id:[^ ]*\) depth:\([0-9]*\) match:\([0-9]*\) filename:\(.*\)$',
+ \ 'g:notmuch_show_message_parse_regexp': '\(id:[^ ]*\) depth:\([0-9]*\) match:\([0-9]*\) excluded:\([0-9]*\) filename:\(.*\)$',
\ 'g:notmuch_show_tags_regexp': '(\([^)]*\))$' ,
\
\ 'g:notmuch_show_signature_regexp': '^\(-- \?\|_\+\)$' ,
@@ -870,7 +870,8 @@ function! s:NM_cmd_show_parse(inlines)
let msg['id'] = m[1]
let msg['depth'] = m[2]
let msg['match'] = m[3]
- let msg['filename'] = m[4]
+ let msg['excluded'] = m[4]
+ let msg['filename'] = m[5]
endif
let in_message = 1