diff options
| author | David Bremner <bremner@debian.org> | 2012-04-04 23:27:01 -0300 |
|---|---|---|
| committer | David Bremner <bremner@debian.org> | 2012-04-04 23:27:01 -0300 |
| commit | 4adefd4c497a1977db36317ed34c406565fb201d (patch) | |
| tree | 1d1d7c6cea688d8ef71f70a9a022165f60be3140 | |
| parent | 954cf155718a5a7576a7a578d836b76e15d312a4 (diff) | |
| parent | 331f0cac61802606e0103c35453656d2299cbfe3 (diff) | |
Merge tag 'debian/0.12-1' into squeeze-backports
notmuch Debian 0.12-1 upload (same as 0.12 + debian changelog fix)
Conflicts:
debian/changelog
134 files changed, 7116 insertions, 4227 deletions
diff --git a/.dir-locals.el b/.dir-locals.el index aea630bd..fc75ae61 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) @@ -20,4 +20,6 @@ (tab-width . 8) (sh-basic-offset . 4) (sh-indentation . 4)) + (nil + (fill-column . 70)) ) @@ -7,7 +7,6 @@ tags /notmuch notmuch.sym notmuch-shared -notmuch.1.gz libnotmuch.so* libnotmuch*.dylib *.[ao] @@ -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 ------ @@ -3,7 +3,7 @@ all: # List all subdirectories here. Each contains its own Makefile.local -subdirs = compat completion emacs lib util test +subdirs = compat completion emacs lib man util test # We make all targets depend on the Makefiles themselves. global_deps = Makefile Makefile.config Makefile.local \ diff --git a/Makefile.local b/Makefile.local index 97f397ff..1131dea8 100644 --- a/Makefile.local +++ b/Makefile.local @@ -53,7 +53,7 @@ endif FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(CONFIGURE_LDFLAGS) .PHONY: all -all: notmuch notmuch-shared notmuch.1.gz +all: notmuch notmuch-shared ifeq ($(MAKECMDGOALS),) ifeq ($(shell cat .first-build-message 2>/dev/null),) @NOTMUCH_FIRST_BUILD=1 $(MAKE) --no-print-directory all @@ -95,8 +95,7 @@ dist: $(TAR_FILE) .PHONY: update-versions -update-versions: - sed -i "s/^.TH NOTMUCH 1.*$$/.TH NOTMUCH 1 ${DATE} \"Notmuch ${VERSION}\"/" notmuch.1 +update-versions: update-man-versions sed -i "s/^__VERSION__[[:blank:]]*=.*$$/__VERSION__ = \'${VERSION}\'/" $(PV_FILE) # We invoke make recursively only to force ordering of our phony @@ -221,14 +220,6 @@ verify-version-python: verify-version-components echo "Please edit version and $(PV_FILE) to have consistent versions." && false) @echo "Good." -.PHONY: verify-version-manpage -verify-version-manpage: verify-version-components - @echo -n "Checking that manual page version is $(VERSION)..." - @[ "$(VERSION)" = $$(sed -n '/^[.]TH NOTMUCH 1/{s/.*"Notmuch //;s/".*//p;}' notmuch.1) ] || \ - (echo "No." && \ - echo "Please edit version and notmuch.1 to have consistent versions." && false) - @echo "Good." - .PHONY: verify-version-components verify-version-components: @echo -n "Checking that $(VERSION) consists only of digits and periods..." @@ -282,10 +273,6 @@ quiet ?= $($(shell echo $1 | sed -e s'/ .*//')) sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ -DEPS := $(SRCS:%.c=.deps/%.d) -DEPS := $(DEPS:%.cc=.deps/%.d) --include $(DEPS) - .PHONY : clean clean: rm -f $(CLEAN); rm -rf .deps @@ -315,6 +302,7 @@ notmuch_client_srcs = \ notmuch-time.c \ query-string.c \ show-message.c \ + mime-node.c \ json.c notmuch_client_modules = $(notmuch_client_srcs:.c=.o) @@ -325,13 +313,8 @@ notmuch: $(notmuch_client_modules) lib/libnotmuch.a util/libutil.a notmuch-shared: $(notmuch_client_modules) lib/$(LINKER_NAME) $(call quiet,$(FINAL_NOTMUCH_LINKER) $(CFLAGS)) $(notmuch_client_modules) $(FINAL_NOTMUCH_LDFLAGS) -o $@ -notmuch.1.gz: notmuch.1 - gzip --stdout $^ > $@ - .PHONY: install -install: all notmuch.1.gz - mkdir -p "$(DESTDIR)$(mandir)/man1" - install -m0644 notmuch.1.gz "$(DESTDIR)$(mandir)/man1/" +install: all install-man mkdir -p "$(DESTDIR)$(prefix)/bin/" install notmuch-shared "$(DESTDIR)$(prefix)/bin/notmuch" ifeq ($(MAKECMDGOALS), install) @@ -362,4 +345,8 @@ install-desktop: desktop-file-install --mode 0644 --dir "$(DESTDIR)$(desktop_dir)" notmuch.desktop SRCS := $(SRCS) $(notmuch_client_srcs) -CLEAN := $(CLEAN) notmuch notmuch-shared $(notmuch_client_modules) notmuch.elc notmuch.1.gz +CLEAN := $(CLEAN) notmuch notmuch-shared $(notmuch_client_modules) notmuch.elc + +DEPS := $(SRCS:%.c=.deps/%.d) +DEPS := $(DEPS:%.cc=.deps/%.d) +-include $(DEPS) @@ -1,3 +1,155 @@ +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) =========================== @@ -22,7 +174,6 @@ Quote MML tags in replies 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) ========================= @@ -135,8 +286,8 @@ Bug-fix release. 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) =========================== @@ -206,8 +357,8 @@ Add keybinding ('c I') for stashing Message-ID's without an id: prefix 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 ----------- @@ -236,9 +387,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) ======================== @@ -623,7 +774,7 @@ Ruby bindings are now much more complete 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. diff --git a/bindings/python/docs/source/conf.py b/bindings/python/docs/source/conf.py index e0ee39cd..9db377f7 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 00000000..ee71085f --- /dev/null +++ b/bindings/python/docs/source/database.rst @@ -0,0 +1,48 @@ +: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:: 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 00000000..685dc4d3 --- /dev/null +++ b/bindings/python/docs/source/filesystem.rst @@ -0,0 +1,30 @@ +Files and directories +===================== + +.. currentmodule:: notmuch + +:class:`Filenames` -- An iterator over filenames +------------------------------------------------ + +.. autoclass:: Filenames + + .. automethod:: Filenames.__len__ + + .. automethod:: Filenames.as_generator + +: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 f7d3d605..9ad5fa97 100644 --- a/bindings/python/docs/source/index.rst +++ b/bindings/python/docs/source/index.rst @@ -1,284 +1,37 @@ -.. 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 + notmuch 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 00000000..2ae280e3 --- /dev/null +++ b/bindings/python/docs/source/message.rst @@ -0,0 +1,54 @@ +: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:: format_message_as_json + + .. automethod:: format_message_as_text + + .. automethod:: __str__ diff --git a/bindings/python/docs/source/messages.rst b/bindings/python/docs/source/messages.rst new file mode 100644 index 00000000..3ccf505c --- /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 00000000..a7927485 --- /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 index 32e17833..bf68f337 100644 --- a/bindings/python/docs/source/notmuch.rst +++ b/bindings/python/docs/source/notmuch.rst @@ -29,7 +29,7 @@ Where <command> and [args...] are as follows: **show** <search-terms> [...] Show all messages matching the search terms. - This has been partially implemented, we show a stub for each + 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> [...] diff --git a/bindings/python/docs/source/query.rst b/bindings/python/docs/source/query.rst new file mode 100644 index 00000000..ddfc3485 --- /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 00000000..609f42e1 --- /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 bc0d0d23..dd6e31f8 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 00000000..31527d4b --- /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 00000000..40678725 --- /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 00000000..e5a8c8a9 --- /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 index 8d118595..3ff53ec8 100755 --- a/bindings/python/notmuch.py +++ b/bindings/python/notmuch.py @@ -17,7 +17,12 @@ import stat import email from notmuch import Database, Query, NotmuchError, STATUS -from ConfigParser import SafeConfigParser +try: + # python3.x + from configparser import SafeConfigParser +except ImportError: + # python2.x + from ConfigParser import SafeConfigParser from cStringIO import StringIO PREFIX = re.compile('(\w+):(.*$)') diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py index f3ff9874..5561624e 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/database.py b/bindings/python/notmuch/database.py index 0074ba36..44d40fdb 100644 --- a/bindings/python/notmuch/database.py +++ b/bindings/python/notmuch/database.py @@ -18,15 +18,29 @@ 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 +import codecs +from ctypes import c_char_p, c_void_p, c_uint, byref, POINTER +from notmuch.globals import ( + nmlib, + Enum, + _str, + NotmuchDatabaseP, + NotmuchDirectoryP, + NotmuchMessageP, + NotmuchTagsP, +) +from .errors import ( + STATUS, + FileError, + NotmuchError, + NullPointerError, + NotInitializedError, + ReadOnlyDatabaseError, +) +from notmuch.message import Message from notmuch.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,6 +54,10 @@ 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. + .. note:: Any function in this class can and will throw an @@ -107,7 +125,8 @@ class Database(object): _create.argtypes = [c_char_p] _create.restype = NotmuchDatabaseP - 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 +144,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 +161,12 @@ class Database(object): else: self.create(path) + def __del__(self): + self.close() + 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,8 +181,7 @@ 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: @@ -182,8 +204,7 @@ 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) @@ -192,6 +213,28 @@ class Database(object): raise NotmuchError(message="Could not open the specified database") self._db = res + _close = nmlib.notmuch_database_close + _close.argtypes = [NotmuchDatabaseP] + _close.restype = None + + def close(self): + """Close and free the notmuch database if needed""" + if self._db is not None: + self._close(self._db) + self._db = None + + 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""" self._assert_db_is_initialized() @@ -256,7 +299,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 +320,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 @@ -296,30 +339,31 @@ class Database(object): """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. + :raises: :exc:`ReadOnlyDatabaseError` if the database has not been + opened in read-write mode """ self._assert_db_is_initialized() + + # work around libnotmuch calling exit(3), see + # id:20120221002921.8534.57091@thinkbox.jade-hamburg.de + # TODO: remove once this issue is resolved + if self.mode != Database.MODE.READ_WRITE: + raise ReadOnlyDatabaseError('The database has to be opened in ' + 'read-write mode for get_directory') + # 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 @@ -328,7 +372,7 @@ class Database(object): dir_p = Database._get_directory(self._db, _str(path)) # 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 +415,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 +465,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. @@ -430,7 +474,7 @@ class Database(object): removed. """ self._assert_db_is_initialized() - return self._remove_message(self._db, filename) + return self._remove_message(self._db, _str(filename)) def find_message(self, msgid): """Returns a :class:`Message` as identified by its message ID @@ -440,7 +484,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 +506,34 @@ 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. + :raises: :exc:`ReadOnlyDatabaseError` if the database has not been + opened in read-write mode *Added in notmuch 0.9*""" self._assert_db_is_initialized() + + # work around libnotmuch calling exit(3), see + # id:20120221002921.8534.57091@thinkbox.jade-hamburg.de + # TODO: remove once this issue is resolved + if self.mode != Database.MODE.READ_WRITE: + raise ReadOnlyDatabaseError('The database has to be opened in ' + 'read-write mode for get_directory') + msg_p = NotmuchMessageP() status = Database._find_message_by_filename(self._db, _str(filename), byref(msg_p)) @@ -504,7 +551,7 @@ 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) + raise NullPointerError() return Tags(tags_p, self) def create_query(self, querystring): @@ -530,28 +577,25 @@ 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""" - from ConfigParser import SafeConfigParser + 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): @@ -561,406 +605,3 @@ class Database(object): guaranteed to remain stable in future versions). """ 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 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) - - 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 not threads_p: - 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 not msgs_p: - 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 not self._dir_p: - 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 not self._files_p: - 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 - - 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 not self._files_p: - 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 00000000..284cbdce --- /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 notmuch.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 is not None: + self._destroy(self._dir_p) diff --git a/bindings/python/notmuch/errors.py b/bindings/python/notmuch/errors.py new file mode 100644 index 00000000..f153a9c5 --- /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/filenames.py index f7313ec5..12050df9 100644 --- a/bindings/python/notmuch/filename.py +++ b/bindings/python/notmuch/filenames.py @@ -17,11 +17,19 @@ 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) +from notmuch.globals import ( + nmlib, + NotmuchMessageP, + NotmuchFilenamesP, + Python3StringMixIn, +) +from .errors import ( + NullPointerError, + NotInitializedError, +) -class Filenames(object): +class Filenames(Python3StringMixIn): """Represents a list of filenames as returned by notmuch This object contains the Filenames iterator. The main function is @@ -29,9 +37,9 @@ class Filenames(object): 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:: + 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 @@ -61,8 +69,8 @@ class Filenames(object): 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 files_p: :class:`ctypes.c_void_p` :param parent: The parent object (ie :class:`Message` these filenames are derived from, and saves a @@ -70,12 +78,16 @@ class Filenames(object): once all derived objects are dead. """ if not files_p: - raise NotmuchError(STATUS.NULL_POINTER) + raise NullPointerError() - self._files = files_p + 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 @@ -84,22 +96,30 @@ class Filenames(object): _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 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) + user. - while self._valid(self._files): - yield Filenames._get(self._files) - self._move_to_next(self._files) - - self._files = None - - def __str__(self): - return unicode(self).encode('utf-8') + .. deprecated:: 0.12 + :class:`Filenames` objects implement the + iterator protocol. + """ + return self def __unicode__(self): """Represent Filenames() as newline-separated list of full paths @@ -107,7 +127,7 @@ class Filenames(object): .. 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 + :exc:`NotInitializedError` on subsequent attempts. However, you can use :meth:`Message.get_filenames` repeatedly to perform various actions on filenames. @@ -120,5 +140,30 @@ class Filenames(object): def __del__(self): """Close and free the notmuch filenames""" - if self._files is not None: - self._destroy(self._files) + if self._files_p is not None: + self._destroy(self._files_p) + + 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 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 54a49b2d..442f3e35 100644 --- a/bindings/python/notmuch/globals.py +++ b/bindings/python/notmuch/globals.py @@ -16,8 +16,8 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>. Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>' """ - -from ctypes import CDLL, c_char_p, c_int, Structure, POINTER +import sys +from ctypes import CDLL, Structure, POINTER #----------------------------------------------------------------------------- #package-global instance of the notmuch library @@ -27,184 +27,43 @@ except: raise ImportError("Could not find shared 'notmuch' library.") -class Enum(object): - """Provides ENUMS as "code=Enum(['a','b','c'])" where code.a=0 etc...""" - def __init__(self, names): - for number, name in enumerate(names): - 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 u"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): - """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 __str__(self): - return unicode(self).encode('utf-8') - - 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 u'Unknown error' - - -# List of Subclassed exceptions that correspond to STATUS values and are -# subclasses of NotmuchError. -class OutOfMemoryError(NotmuchError): - status = STATUS.OUT_OF_MEMORY +if sys.version_info[0] == 2: + class Python3StringMixIn(object): + def __str__(self): + return unicode(self).encode('utf-8') -class ReadOnlyDatabaseError(NotmuchError): - status = STATUS.READ_ONLY_DATABASE + 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" % type(value)) + if isinstance(value, unicode): + return value.encode('UTF-8') + return value +else: + class Python3StringMixIn(object): + def __str__(self): + return self.__unicode__() -class XapianError(NotmuchError): - status = STATUS.XAPIAN_EXCEPTION + def _str(value): + """Ensure a nicely utf-8 encoded string to pass to libnotmuch -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 - + 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') -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 Enum(object): + """Provides ENUMS as "code=Enum(['a','b','c'])" where code.a=0 etc...""" + def __init__(self, names): + for number, name in enumerate(names): + setattr(self, name, number) class NotmuchDatabaseS(Structure): diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py index 5540df3e..9eb4feef 100644 --- a/bindings/python/notmuch/message.py +++ b/bindings/python/notmuch/message.py @@ -21,11 +21,25 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>' 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, - NotmuchTagsP, NotmuchMessagesP, NotmuchMessageP, NotmuchFilenamesP) -from notmuch.tag import Tags -from notmuch.filename import Filenames -import sys +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 + import email try: import simplejson as json @@ -33,212 +47,7 @@ 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 not msgs_p: - 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 - - msg = Message(Messages._get(self._msgs), self) - self._move_to_next(self._msgs) - return msg - - 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 print_messages(self, format, indent=0, entire_thread=False): - """Outputs messages as needed for 'notmuch show' to sys.stdout - - :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. - """ - 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 - - sys.stdout.write(set_start) - - # iterate through all toplevel messages in this thread - for msg in self: - # if not msg: - # break - if not first_set: - sys.stdout.write(set_sep) - first_set = False - - sys.stdout.write(set_start) - match = msg.is_match() - next_indent = indent - - if (match or entire_thread): - if format.lower() == "text": - sys.stdout.write(msg.format_message_as_text(indent)) - else: - sys.stdout.write(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() - if not replies is None: - sys.stdout.write(set_sep) - replies.print_messages(format, next_indent, entire_thread) - - sys.stdout.write(set_end) - sys.stdout.write(set_end) - - -class Message(object): +class Message(Python3StringMixIn): """Represents a single Email message Technically, this wraps the underlying *notmuch_message_t* @@ -313,8 +122,8 @@ class Message(object): 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 @@ -322,7 +131,7 @@ class Message(object): objects are dead. """ if not msg_p: - raise NotmuchError(STATUS.NULL_POINTER) + raise NullPointerError() self._msg = msg_p #keep reference to parent, so we keep it alive self._parent = parent @@ -331,12 +140,12 @@ class Message(object): """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) - return Message._get_message_id(self._msg) + if not self._msg: + raise NotInitializedError() + return Message._get_message_id(self._msg).decode('utf-8', 'ignore') def get_thread_id(self): """Returns the thread ID @@ -348,13 +157,13 @@ class Message(object): 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) + return Message._get_thread_id(self._msg).decode('utf-8', 'ignore') def get_replies(self): """Gets all direct replies to this message as :class:`Messages` @@ -368,20 +177,21 @@ class Message(object): number of subsequent calls to :meth:`get_replies`). If this message was obtained through some non-thread means, (such as by a call to :meth:`Query.search_messages`), then this function will return - `None`. + an empty Messages iterator. - :returns: :class:`Messages` or `None` if there are no replies to - this message. - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message + :returns: :class:`Messages`. + :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) + from .messages import Messages, EmptyMessagesResult + if not msgs_p: - return None + return EmptyMessagesResult(self) return Messages(msgs_p, self) @@ -394,11 +204,11 @@ class Message(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._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): @@ -414,31 +224,29 @@ class Message(object): 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, header) + header = Message._get_header(self._msg, _str(header)) if header == None: - raise NotmuchError(STATUS.NULL_POINTER) - return header.decode('UTF-8', errors='ignore') + 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) - return Message._get_filename(self._msg) + if not self._msg: + raise NotInitializedError() + return Message._get_filename(self._msg).decode('utf-8', 'ignore') def get_filenames(self): """Get all filenames for the email corresponding to 'message' @@ -446,8 +254,8 @@ class Message(object): 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) @@ -463,11 +271,11 @@ class Message(object): :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): @@ -477,30 +285,27 @@ class Message(object): *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) + raise NullPointerError() return Tags(tags_p, self) _add_tag = nmlib.notmuch_message_add_tag @@ -525,21 +330,16 @@ class Message(object): :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)) @@ -573,21 +373,16 @@ class Message(object): :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 @@ -619,16 +414,13 @@ class Message(object): :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) @@ -677,16 +469,13 @@ class Message(object): :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) @@ -715,17 +504,15 @@ class Message(object): :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) @@ -760,8 +547,8 @@ class Message(object): :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): @@ -787,17 +574,14 @@ class Message(object): :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): """Represent a Message() object by str()""" return self.__str__() - def __str__(self): - return unicode(self).encode('utf-8') - def __unicode__(self): format = "%s (%s) (%s)" return format % (self.get_header('from'), @@ -933,7 +717,7 @@ class Message(object): 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) diff --git a/bindings/python/notmuch/messages.py b/bindings/python/notmuch/messages.py new file mode 100644 index 00000000..d94f91b4 --- /dev/null +++ b/bindings/python/notmuch/messages.py @@ -0,0 +1,264 @@ +""" +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 tags_p == None: + 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): + """ + :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__ diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py new file mode 100644 index 00000000..ddaf8e08 --- /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 notmuch.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 is not None: + self._destroy(self._query) diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py index 4881db9f..711bf533 100644 --- a/bindings/python/notmuch/tag.py +++ b/bindings/python/notmuch/tag.py @@ -17,10 +17,18 @@ 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, NotmuchTagsP +from notmuch.globals import ( + nmlib, + Python3StringMixIn, + NotmuchTagsP, +) +from .errors import ( + NullPointerError, + NotInitializedError, +) -class Tags(object): +class Tags(Python3StringMixIn): """Represents a list of notmuch tags This object provides an iterator over a list of notmuch tags (which @@ -29,9 +37,9 @@ class Tags(object): 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(object): 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 @@ -71,7 +79,7 @@ class Tags(object): cache the tags in the Python object(?) """ if not tags_p: - raise NotmuchError(STATUS.NULL_POINTER) + raise NullPointerError() self._tags = tags_p #save reference to parent object so we keep it alive @@ -89,15 +97,16 @@ class Tags(object): _move_to_next.argtypes = [NotmuchTagsP] _move_to_next.restype = None - def next(self): - if self._tags is None: - raise NotmuchError(STATUS.NOT_INITIALIZED) + def __next__(self): + if not self._tags: + raise NotInitializedError() if not self._valid(self._tags): self._tags = None raise StopIteration tag = Tags._get(self._tags).decode('UTF-8') self._move_to_next(self._tags) return tag + next = __next__ # python2.x iterator protocol compatibility def __nonzero__(self): """Implement bool(Tags) check that can be repeatedly used @@ -110,9 +119,6 @@ class Tags(object): left.""" return self._valid(self._tags) > 0 - def __str__(self): - return unicode(self).encode('utf-8') - def __unicode__(self): """string representation of :class:`Tags`: a space separated list of tags @@ -120,8 +126,8 @@ class Tags(object): 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) diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py index 594fa522..a759c909 100644 --- a/bindings/python/notmuch/thread.py +++ b/bindings/python/notmuch/thread.py @@ -18,164 +18,20 @@ 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,) -from notmuch.message import Messages +from notmuch.globals import ( + nmlib, + NotmuchThreadP, + NotmuchMessagesP, + NotmuchTagsP, +) +from .errors import ( + NullPointerError, + NotInitializedError, +) +from .messages import Messages from notmuch.tag import Tags from datetime import date - -class Threads(object): - """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 not threads_p: - 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 - - 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.""" @@ -219,8 +75,8 @@ 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 @@ -228,7 +84,7 @@ class Thread(object): objects are dead. """ if not thread_p: - raise NotmuchError(STATUS.NULL_POINTER) + raise NullPointerError() self._thread = thread_p #keep reference to parent, so we keep it alive self._parent = parent @@ -240,12 +96,12 @@ 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) - return Thread._get_thread_id(self._thread) + 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 _get_total_messages.argtypes = [NotmuchThreadP] @@ -257,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): @@ -278,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 not msgs_p: - raise NotmuchError(STATUS.NULL_POINTER) + raise NullPointerError() return Messages(msgs_p, self) @@ -303,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): @@ -320,12 +174,12 @@ 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', errors='ignore') + return authors.decode('UTF-8', 'ignore') def get_subject(self): """Returns the Subject of 'thread' @@ -333,23 +187,23 @@ 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', errors='ignore') + return subject.decode('UTF-8', 'ignore') def get_newest_date(self): """Returns time_t of the newest message date :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): @@ -357,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): @@ -377,23 +231,17 @@ 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) + raise NullPointerError() return Tags(tags_p, self) - def __str__(self): - return unicode(self).encode('utf-8') - def __unicode__(self): frm = "thread:%s %12s [%d/%d] %s; %s (%s)" diff --git a/bindings/python/notmuch/threads.py b/bindings/python/notmuch/threads.py new file mode 100644 index 00000000..225f5246 --- /dev/null +++ b/bindings/python/notmuch/threads.py @@ -0,0 +1,180 @@ +""" +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 notmuch.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): + """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.restype = None + + def __del__(self): + """Close and free the notmuch Threads""" + if self._threads is not None: + self._destroy(self._threads) diff --git a/bindings/python/notmuch/version.py b/bindings/python/notmuch/version.py index ed40e7f8..24e1d4c9 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.1' +__VERSION__ = '0.12' diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 286fd196..2e58dab1 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -7,7 +7,7 @@ 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__)), 'notmuch', 'version.py') -execfile(version_file) +exec(compile(open(version_file).read(), version_file, 'exec')) assert __VERSION__, 'Failed to read the notmuch binding version number' setup(name='notmuch', diff --git a/compat/Makefile.local b/compat/Makefile.local index 504eb715..13f16cd3 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 7767fe84..b2e27368 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 @@ -273,14 +273,17 @@ if [ ${have_xapian} = "0" ]; then errors=$((errors + 1)) fi +# 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. printf "Checking for GMime development files... " have_gmime=0 -for gmimepc in gmime-2.6 gmime-2.4; do +for gmimepc in 'gmime-2.6 >= 2.6.7' gmime-2.4; 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 if [ "$have_gmime" = "0" ]; then @@ -289,10 +292,10 @@ if [ "$have_gmime" = "0" ]; then 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) @@ -416,7 +419,7 @@ EOF echo " http://spruce.sourceforge.net/gmime/" 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/" fi if [ $have_talloc -eq 0 ]; then diff --git a/debian/.gitignore b/debian/.gitignore index 801ca02d..9f09f22d 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/changelog b/debian/changelog index 3cb2ad5a..026871dd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,29 @@ +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~bpo60+1) squeeze-backports; urgency=low * Rebuild for squeeze-backports. diff --git a/debian/control b/debian/control index f6f415ed..ed27c587 100644 --- a/debian/control +++ b/debian/control @@ -10,14 +10,14 @@ 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~), 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 diff --git a/debian/libnotmuch2.symbols b/debian/libnotmuch2.symbols index 507600c8..272467a3 100644 --- a/debian/libnotmuch2.symbols +++ b/debian/libnotmuch2.symbols @@ -46,6 +46,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 diff --git a/debian/notmuch.install b/debian/notmuch.install index fff498d2..86e891d4 100644 --- a/debian/notmuch.install +++ b/debian/notmuch.install @@ -1,3 +1,3 @@ usr/bin -usr/share/man/man1 +usr/share/man etc/bash_completion.d diff --git a/RELEASING b/devel/RELEASING index 88dab04e..88dab04e 100644 --- a/RELEASING +++ b/devel/RELEASING diff --git a/devel/STYLE b/devel/STYLE new file mode 100644 index 00000000..094f71d1 --- /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/devel/schemata b/devel/schemata new file mode 100644 index 00000000..24ad7757 --- /dev/null +++ b/devel/schemata @@ -0,0 +1,138 @@ +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?, # present if --entire-thread or matched + [thread_node*] # children of message +] + +# A message (show_message) +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] +} + +# A MIME part (show_message_body) +part = { + # format_part_start_json + id: int|string, # part id (currently DFS part number) + + # format_part_encstatus_json + encstatus?: encstatus, + + # format_part_sigstatus_json + sigstatus?: sigstatus, + + # format_part_content_json + 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 (format_headers_json with raw headers) or +# a part (format_headers_message_part_json with pretty-printed headers) +headers = { + Subject: string, + From: string, + To?: string, + Cc?: string, + Bcc?: string, + Date: string +} + +# Encryption status (format_part_encstatus_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 +} diff --git a/devel/uncrustify.cfg b/devel/uncrustify.cfg new file mode 100644 index 00000000..d8075ba1 --- /dev/null +++ b/devel/uncrustify.cfg @@ -0,0 +1,112 @@ +# +# 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 + +# +# 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--; }" + +# +# Extra types used in notmuch source. +# (add more on demand) + +type GMimeObject mime_node_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 = FALSE + +# indent_brace = 0 diff --git a/emacs/Makefile.local b/emacs/Makefile.local index 0c58b824..4fee0e89 100644 --- a/emacs/Makefile.local +++ b/emacs/Makefile.local @@ -13,7 +13,8 @@ emacs_sources := \ $(dir)/notmuch-maildir-fcc.el \ $(dir)/notmuch-message.el \ $(dir)/notmuch-crypto.el \ - $(dir)/coolj.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 8eba7a0b..2bf762ba 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 ac300987..83e5d37a 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 333d4c1e..d17a30f9 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -29,18 +29,15 @@ (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." @@ -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,32 +136,24 @@ 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)))) - (defun notmuch-hello-nice-number (n) (let (result) (while (> n 0) @@ -182,10 +172,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) @@ -299,15 +293,17 @@ should be. Returns a cons cell `(tags-per-line width)'." :notify #'notmuch-hello-widget-search :notmuch-search-terms query formatted-name) - ;; 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))) - ? )))) + (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))) + ? ))))) (setq count (1+ count)) (if (eq (% count tags-per-line) 0) (widget-insert "\n"))) @@ -315,15 +311,10 @@ should be. Returns a cons cell `(tags-per-line width)'." ;; 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() @@ -353,7 +344,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) @@ -397,9 +388,9 @@ Complete list of currently available key bindings: "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 @@ -466,7 +457,8 @@ Complete list of currently available key bindings: (widget-insert " messages.\n")) (let ((found-target-pos nil) - (final-target-pos nil)) + (final-target-pos nil) + (default-pos)) (let* ((saved-alist ;; Filter out empty saved searches if required. (if notmuch-show-empty-saved-searches @@ -498,7 +490,7 @@ Complete list of currently available key bindings: (indent-rigidly start (point) notmuch-hello-indent))) (widget-insert "\nSearch: ") - (setq notmuch-hello-search-bar-marker (point-marker)) + (setq default-pos (point-marker)) (widget-create 'editable-field ;; Leave some space at the start and end of the ;; search boxes. @@ -506,24 +498,27 @@ Complete list of currently available key bindings: (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 " ") + ;; 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") - (when notmuch-hello-recent-searches + (when notmuch-search-history (widget-insert "\nRecent searches: ") (widget-create 'push-button :notify (lambda (&rest ignore) - (setq notmuch-hello-recent-searches nil) + (setq notmuch-search-history 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)))) + (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 @@ -550,9 +545,7 @@ Complete list of currently available key bindings: (notmuch-hello-add-saved-search widget)) :notmuch-saved-search-widget widget-symbol "save")) - (widget-insert "\n") - (setq nth (1+ nth))) - notmuch-hello-recent-searches) + (widget-insert "\n")) (indent-rigidly start (point) notmuch-hello-indent))) (when alltags-alist @@ -565,29 +558,29 @@ Complete list of currently available key bindings: (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)) + (unless 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"))) + (unless 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 + (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 "`=' refreshes this screen. `s' jumps to the search box. `q' to quit.\n") + (widget-insert "`=' to refresh this screen. `s' to search messages. `q' to quit.\n") (let ((fill-column (- (window-width) notmuch-hello-indent))) (center-region start (point)))) @@ -599,7 +592,7 @@ Complete list of currently available key bindings: (widget-forward 1))) (unless (widget-at) - (notmuch-hello-goto-search)))) + (goto-char default-pos)))) (run-hooks 'notmuch-hello-refresh-hook)) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 0f856bf0..d315f765 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -28,17 +28,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 +133,15 @@ 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-common-do-stash (text) @@ -114,14 +160,14 @@ 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) diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el index 6fbf82d2..dcfbc4b3 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, diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el index 08e5b174..264a5b9b 100644 --- a/emacs/notmuch-message.el +++ b/emacs/notmuch-message.el @@ -31,7 +31,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. diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index 3e93d7c8..13244eb8 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -28,25 +28,26 @@ (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-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) ;; @@ -71,12 +72,15 @@ list." (push header message-hidden-headers))) notmuch-mua-hidden-headers)) -(defun notmuch-mua-reply (query-string &optional sender) +(defun notmuch-mua-reply (query-string &optional sender reply-all) (let (headers body (args '("reply"))) (if 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 @@ -91,6 +95,9 @@ list." (goto-char (point-min)) (setq headers (mail-header-extract))))) (forward-line 1) + ;; Original message may contain (malicious) MML tags. We must + ;; properly quote them in the reply. + (mml-quote-region (point) (point-max)) (setq body (buffer-substring (point) (point-max)))) ;; If sender is non-nil, set the From: header to its value. (when sender @@ -108,15 +115,11 @@ list." (if (re-search-backward message-signature-separator nil t) (forward-line -1) (goto-char (point-max))) - (insert body)) + (insert body) + (push-mark)) (set-buffer-modified-p nil) - (message-goto-body) - ;; Original message may contain (malicious) MML tags. We must - ;; properly quote them in the reply. Note that using `point-max' - ;; instead of `mark' here is wrong. The buffer may include user's - ;; signature which should not be MML-quoted. - (mml-quote-region (point) (point-max))) + (message-goto-body)) (defun notmuch-mua-forward-message () (message-forward) @@ -158,16 +161,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) @@ -222,13 +225,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 00000000..6653d977 --- /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 + :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 82d11c92..7c4c0bea 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -34,11 +34,14 @@ (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-read-tag-changes "notmuch" (&optional initial-input &rest search-terms)) +(declare-function notmuch-search-next-thread "notmuch" nil) (declare-function notmuch-search-show-thread "notmuch" nil) +(declare-function notmuch-update-tags "notmuch" (current-tags tag-changes)) (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date") "Headers that should be shown in a message, in this order. @@ -47,8 +50,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,38 +61,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-excerpt-citations) +(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. @@ -98,14 +107,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" @@ -117,18 +194,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) @@ -183,6 +264,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:") @@ -227,21 +356,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)) + (when (string= p-name p-address) + (setq p-name nil)) - (if (not name) - address - (concat name " <" address ">"))) + ;; 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) @@ -278,10 +443,21 @@ 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) + 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 @@ -296,44 +472,75 @@ 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))))) +(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-show-get-bodypart-internal ,message-id ,nth)) + ,@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-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 ((handle (mm-make-handle (current-buffer) (list content-type)))) - (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))))) + (let* ((charset (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-show-get-bodypart-content msg part nth)) + (when (mm-inlinable-p handle) + (set-buffer display-buffer) + (mm-display-part handle) + t)))))) (defvar notmuch-show-multipart/alternative-discouraged '( @@ -464,7 +671,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))) @@ -490,7 +697,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))) @@ -551,7 +758,7 @@ current buffer, if possible." (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)) @@ -569,6 +776,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. @@ -585,6 +796,10 @@ current buffer, if possible." nil)) nil)))) +;; Handler for wash generated inline patch fake parts. +(defun notmuch-show-insert-part-inline-patch-fake-part (msg part content-type nth depth declared-type) + (notmuch-show-insert-part-*/* msg part "text/x-diff" nth depth "inline patch")) + (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)) @@ -613,8 +828,6 @@ current buffer, if possible." ;; 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))) @@ -652,8 +865,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." @@ -715,8 +928,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 @@ -731,15 +942,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)) @@ -753,6 +968,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 @@ -766,11 +983,40 @@ current buffer, if possible." ;; criteria. (notmuch-show-message-visible msg (plist-get msg :match)))) +(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) + (if (or (not notmuch-show-elide-non-matching-messages) + (plist-get msg :match)) + (notmuch-show-insert-msg msg depth)) (notmuch-show-insert-thread replies (1+ depth)))) (defun notmuch-show-insert-thread (thread depth) @@ -781,15 +1027,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. @@ -809,7 +1046,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 @@ -824,80 +1061,115 @@ 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))) + (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) + + ;; Move to the first open message and mark it read + (if (notmuch-show-message-visible-p) + (notmuch-show-mark-read) + (notmuch-show-next-open-message)))) + +(defun notmuch-show-build-buffer () + (let ((inhibit-read-only t)) -(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) (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 ")\'")) + (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 "\'"))))) (notmuch-show-insert-forest (notmuch-query-get-threads 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)))) (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-pretty-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. + (if (notmuch-show-message-visible-p) + (notmuch-show-mark-read) + (notmuch-show-next-open-message))))) (defvar notmuch-show-stash-map (let ((map (make-sparse-keymap))) @@ -910,6 +1182,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) @@ -925,7 +1199,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) @@ -933,10 +1208,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) @@ -945,6 +1223,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) @@ -982,7 +1265,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))) @@ -1027,6 +1311,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. @@ -1075,9 +1368,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 the Message-Id of the current message. + +If optional argument BARE is non-nil, return +the Message-Id without prefix and quotes." + (if bare + (notmuch-show-get-prop :id) + (concat "id:\"" (notmuch-show-get-prop :id) "\""))) + +(defun notmuch-show-get-messages-ids () + "Return all message ids 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? @@ -1104,6 +1414,12 @@ 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-get-pretty-subject () + (notmuch-prettify-subject (notmuch-show-get-subject))) + (defun notmuch-show-set-tags (tags) "Set the tags of the current message." (notmuch-show-set-prop :tags tags) @@ -1123,7 +1439,7 @@ 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. @@ -1191,7 +1507,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]). @@ -1218,11 +1534,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 @@ -1230,9 +1545,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." @@ -1240,14 +1560,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." @@ -1256,9 +1581,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)))) @@ -1266,10 +1596,13 @@ any effects from previous calls to (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)))) + r)) (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)))) @@ -1300,7 +1633,7 @@ than only the current message." (interactive "P\nsPipe message to command: ") (let (shell-command) (if entire-thread - (setq shell-command + (setq shell-command (concat notmuch-command " show --format=mbox " (shell-quote-argument (mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR ")) @@ -1321,51 +1654,45 @@ 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)) + (apply '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 initial-input) + "Change tags for the current message, read input from the minibuffer." + (interactive) + (let ((tag-changes (notmuch-read-tag-changes + initial-input (notmuch-show-get-message-id)))) + (apply 'notmuch-show-tag-message tag-changes))) - (let* ((current-tags (notmuch-show-get-tags)) - (new-tags (notmuch-show-del-tags-worker current-tags toremove))) +(defun notmuch-show-tag-all (&rest tag-changes) + "Change tags for all messages in the current buffer. - (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)))) +TAG-CHANGES is a list of tag operations for `notmuch-tag'." + (interactive (notmuch-read-tag-changes nil notmuch-show-thread-id)) + (apply '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." @@ -1407,23 +1734,23 @@ 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 (&optional unarchive) + "Archive each message in thread. -(defun notmuch-show-archive-thread () - "Archive each message in thread, then show next thread from search. +If a prefix argument is given, the messages will be +\"unarchived\" (ie. the \"inbox\" tag will be added instead of +removed). Archive each message currently shown by removing the \"inbox\" tag from each. Then kill this buffer and show the next thread @@ -1433,13 +1760,50 @@ 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. + +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-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-thread-internal nil)) + (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." @@ -1469,7 +1833,7 @@ buffer." (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." @@ -1486,14 +1850,62 @@ 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-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-wash.el b/emacs/notmuch-wash.el index 1f420b25..56981d06 100644 --- a/emacs/notmuch-wash.el +++ b/emacs/notmuch-wash.el @@ -136,12 +136,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 +161,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 +181,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 +198,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 +212,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")))))) ;; @@ -290,6 +294,44 @@ When doing so, maintaining citation leaders in the wrapped text." (defvar diff-file-header-re) ; From `diff-mode.el'. +(defun notmuch-wash-subject-to-filename (subject &optional maxlen) + "Convert a mail SUBJECT into a filename. + +The resulting filename is similar to the names generated by \"git +format-patch\", without the leading patch sequence number +\"0001-\" and \".patch\" extension. Any leading \"[PREFIX]\" +style strings are removed prior to conversion. + +Optional argument MAXLEN is the maximum length of the resulting +filename, before trimming any trailing . and - characters." + (let* ((s (replace-regexp-in-string "^ *\\(\\[[^]]*\\] *\\)*" "" subject)) + (s (replace-regexp-in-string "[^A-Za-z0-9._]+" "-" s)) + (s (replace-regexp-in-string "\\.+" "." s)) + (s (if maxlen (substring s 0 (min (length s) maxlen)) s)) + (s (replace-regexp-in-string "[.-]*$" "" s))) + s)) + +(defun notmuch-wash-subject-to-patch-sequence-number (subject) + "Convert a patch mail SUBJECT into a patch sequence number. + +Return the patch sequence number N from the last \"[PATCH N/M]\" +style prefix in SUBJECT, or nil if such a prefix can't be found." + (when (string-match + "^ *\\(\\[[^]]*\\] *\\)*\\[[^]]*?\\([0-9]+\\)/[0-9]+[^]]*\\].*" + subject) + (string-to-number (substring subject (match-beginning 2) (match-end 2))))) + +(defun notmuch-wash-subject-to-patch-filename (subject) + "Convert a patch mail SUBJECT into a filename. + +The resulting filename is similar to the names generated by \"git +format-patch\". If the patch mail was generated and sent using +\"git format-patch/send-email\", this should re-create the +original filename the sender had." + (format "%04d-%s.patch" + (or (notmuch-wash-subject-to-patch-sequence-number subject) 1) + (notmuch-wash-subject-to-filename subject 52))) + (defun notmuch-wash-convert-inline-patch-to-part (msg depth) "Convert an inline patch into a fake 'text/x-diff' attachment. @@ -298,27 +340,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 "text/x-diff")) - (setq part (plist-put part :content (buffer-string))) - (setq part (plist-put part :id -1)) - (setq part (plist-put part :filename "inline patch")) - (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 fde23779..f851c6f7 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -1,53 +1,54 @@ -; 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> +;; 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). +;; 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 'crm) (require 'mm-view) (require 'message) @@ -70,17 +71,70 @@ For example: (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\) \(\"subject\" . \"%s\"\)\)\)" :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") +(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) + (split-string + (with-output-to-string + (with-current-buffer standard-output + (apply 'call-process notmuch-command nil t + nil "search-tags" search-terms))) + "\n+" t)) + (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))) + (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-foreach-mime-part (function mm-handle) (cond ((stringp (car mm-handle)) @@ -139,10 +193,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 @@ -164,16 +218,23 @@ For a mouse binding, return nil." "\t" (notmuch-documentation-first-line action)))))) -(defalias 'notmuch-substitute-one-command-key - (apply-partially 'notmuch-substitute-one-command-key-with-prefix nil)) +(defun notmuch-substitute-command-keys-one (key) + ;; A `keymap' key indicates inheritance from a parent keymap - the + ;; inherited mappings follow, so there is nothing to print for + ;; `keymap' itself. + (when (not (eq key 'keymap)) + (notmuch-substitute-one-command-key-with-prefix nil key))) (defun notmuch-substitute-command-keys (doc) "Like `substitute-command-keys' but with documentation, not function names." (let ((beg 0)) (while (string-match "\\\\{\\([^}[:space:]]*\\)}" doc beg) - (let ((map (substring doc (match-beginning 1) (match-end 1)))) - (setq doc (replace-match (mapconcat 'notmuch-substitute-one-command-key - (cdr (symbol-value (intern map))) "\n") 1 1 doc))) + (let* ((keymap-name (substring doc (match-beginning 1) (match-end 1))) + (keymap (symbol-value (intern keymap-name)))) + (setq doc (replace-match + (mapconcat #'notmuch-substitute-command-keys-one + (cdr keymap) "\n") + 1 1 doc))) (setq beg (match-end 0))) doc)) @@ -188,11 +249,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))) @@ -206,7 +275,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) @@ -216,7 +286,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) @@ -262,14 +332,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))) @@ -299,27 +369,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) @@ -331,7 +406,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) @@ -343,7 +419,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. @@ -358,7 +435,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 @@ -404,6 +481,10 @@ Complete list of currently available key bindings: "Return a list of threads for the current region" (notmuch-search-properties-in-region 'notmuch-search-thread-id 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)) @@ -420,31 +501,30 @@ Complete list of currently available key bindings: "Return a list of authors for the current region" (notmuch-search-properties-in-region 'notmuch-search-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))) + (subject (notmuch-prettify-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) - (error "End of search results")))) + ;; 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. @@ -463,20 +543,27 @@ 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. +(defun notmuch-tag (query &rest tag-changes) + "Add/remove tags in TAG-CHANGES 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. +TAG-CHANGES should be a list of strings of the form \"+tag\" or +\"-tag\" and QUERY should be a string containing the +search-query. 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)) + ;; Perform some validation + (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))) (defcustom notmuch-before-tag-hook nil "Hooks that are run before tags of a message are modified. @@ -487,8 +574,8 @@ a list of strings of the form \"+TAG\" or \"-TAG\". the messages that are about to be tagged" :type 'hook - :options '(hl-line-mode) - :group 'notmuch) + :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. @@ -498,8 +585,8 @@ 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) + :options '(notmuch-hl-line-mode) + :group 'notmuch-hooks) (defun notmuch-search-set-tags (tags) (save-excursion @@ -522,7 +609,7 @@ the messages that were tagged" (let ((beg (+ (point) 1))) (re-search-forward ")") (let ((end (- (point) 1))) - (split-string (buffer-substring beg end)))))) + (split-string (buffer-substring-no-properties beg end)))))) (defun notmuch-search-get-tags-region (beg end) (save-excursion @@ -535,75 +622,54 @@ the messages that were tagged" (forward-line 1)) output))) -(defun notmuch-search-add-tag-thread (tag) - (notmuch-search-add-tag-region tag (point) (point))) +(defun notmuch-search-tag-thread (&rest tag-changes) + "Change tags for the currently selected thread. -(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)))))) +See `notmuch-search-tag-region' for details." + (apply 'notmuch-search-tag-region (point) (point) tag-changes)) -(defun notmuch-search-remove-tag-thread (tag) - (notmuch-search-remove-tag-region tag (point) (point))) +(defun notmuch-search-tag-region (beg end &rest tag-changes) + "Change tags for threads in the given region. -(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)) +TAGS is a list of tag operations for `notmuch-tag'. The tags are +added or removed for all threads in the region from BEG to END." + (let ((search-string (notmuch-search-find-thread-id-region-search beg end))) + (apply 'notmuch-tag search-string tag-changes) (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))) + (notmuch-search-set-tags + (notmuch-update-tags (notmuch-search-get-tags) tag-changes)) (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)))) +(defun notmuch-search-tag (&optional initial-input) + "Change tags for the currently selected thread or region." + (interactive) + (let* ((beg (if (region-active-p) (region-beginning) (point))) + (end (if (region-active-p) (region-end) (point))) + (search-string (notmuch-search-find-thread-id-region-search beg end)) + (tags (notmuch-read-tag-changes initial-input search-string))) + (apply 'notmuch-search-tag-region beg end tags))) -(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)) + (notmuch-search-tag-thread "-inbox") + (notmuch-search-next-thread)) (defvar notmuch-search-process-filter-data nil "Data that has not yet been processed.") @@ -624,23 +690,23 @@ 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) + (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.") + (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. @@ -655,7 +721,8 @@ attributes overriding earlier. A message having both \"delete\" 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." @@ -806,15 +873,15 @@ non-authors is found, assume that all of the authors match." (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-show-result date count authors + (notmuch-prettify-subject 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")))) + (when (string= thread-id notmuch-search-target-thread) + (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)) @@ -826,7 +893,7 @@ non-authors is found, assume that all of the authors match." (goto-char found-target))) (delete-process proc)))) -(defun notmuch-search-operate-all (action) +(defun notmuch-search-tag-all (&rest tag-changes) "Add/remove tags from all matching messages. This command adds or removes tags from all messages matching the @@ -837,16 +904,8 @@ will prompt for tags to be added or removed. Tags prefixed with 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))) + (interactive (notmuch-read-tag-changes)) + (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." @@ -902,21 +961,25 @@ PROMPT is the string to prompt with." (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)))) + (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) @@ -990,7 +1053,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. @@ -999,8 +1062,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 () @@ -1055,21 +1118,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/database.cc b/lib/database.cc index 8103bd96..16c4354f 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -582,15 +582,15 @@ notmuch_database_t * notmuch_database_open (const char *path, notmuch_database_mode_t mode) { + 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 (¬much_path, "%s/%s", path, ".notmuch") == -1) { - notmuch_path = NULL; + if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) { fprintf (stderr, "Out of memory\n"); goto DONE; } @@ -602,8 +602,7 @@ notmuch_database_open (const char *path, 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"); goto DONE; } @@ -617,7 +616,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); @@ -703,14 +702,12 @@ 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_close (notmuch); notmuch = NULL; } DONE: - if (notmuch_path) - free (notmuch_path); - if (xapian_path) - free (xapian_path); + talloc_free (local); return notmuch; } @@ -719,7 +716,8 @@ 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,6 +726,17 @@ 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; delete notmuch->query_parser; delete notmuch->xapian_db; @@ -1816,6 +1825,9 @@ 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 { diff --git a/lib/index.cc b/lib/index.cc index e8e9922b..e3777322 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"); @@ -339,6 +340,10 @@ _index_mime_part (notmuch_message_t *message, if (i > 1) fprintf (stderr, "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n"); } + if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) { + /* Don't index encrypted parts. */ + continue; + } _index_mime_part (message, g_mime_multipart_get_part (multipart, i)); } @@ -386,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/messages.c b/lib/messages.c index 7bcd1abf..11218648 100644 --- a/lib/messages.c +++ b/lib/messages.c @@ -127,8 +127,10 @@ notmuch_messages_get (notmuch_messages_t *messages) void notmuch_messages_move_to_next (notmuch_messages_t *messages) { - if (! messages->is_of_list_type) - return _notmuch_mset_messages_move_to_next (messages); + if (! messages->is_of_list_type) { + _notmuch_mset_messages_move_to_next (messages); + return; + } if (messages->iterator == NULL) return; diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 60a932fc..7bf153e0 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -458,7 +458,7 @@ typedef struct _notmuch_string_node { struct _notmuch_string_node *next; } notmuch_string_node_t; -typedef struct _notmuch_string_list { +typedef struct visible _notmuch_string_list { int length; notmuch_string_node_t *head; notmuch_string_node_t **tail; diff --git a/lib/notmuch.h b/lib/notmuch.h index 9f23a106..7929fe72 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -457,6 +457,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 diff --git a/lib/query.cc b/lib/query.cc index b6c0f12d..0b366025 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -27,6 +27,7 @@ struct _notmuch_query { notmuch_database_t *notmuch; const char *query_string; notmuch_sort_t sort; + notmuch_string_list_t *exclude_terms; }; typedef struct _notmuch_mset_messages { @@ -76,6 +77,8 @@ notmuch_query_create (notmuch_database_t *notmuch, query->sort = NOTMUCH_SORT_NEWEST_FIRST; + query->exclude_terms = _notmuch_string_list_create (query); + return query; } @@ -97,6 +100,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 +122,27 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages) return 0; } +/* Return a query that does not match messages with the excluded tags + * registered with the query. Any tags that explicitly appear in + * xquery will not be excluded. */ +static Xapian::Query +_notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery) +{ + 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) + xquery = Xapian::Query (Xapian::Query::OP_AND_NOT, + xquery, Xapian::Query (term->string)); + } + return xquery; +} + notmuch_messages_t * notmuch_query_search_messages (notmuch_query_t *query) { @@ -157,6 +188,8 @@ notmuch_query_search_messages (notmuch_query_t *query) mail_query, string_query); } + final_query = _notmuch_exclude_tags (query, final_query); + enquire.set_weighting_scheme (Xapian::BoolWeight()); switch (query->sort) { @@ -436,6 +469,8 @@ notmuch_query_count_messages (notmuch_query_t *query) mail_query, string_query); } + final_query = _notmuch_exclude_tags (query, final_query); + enquire.set_weighting_scheme(Xapian::BoolWeight()); enquire.set_docid_order(Xapian::Enquire::ASCENDING); diff --git a/man/.gitignore b/man/.gitignore new file mode 100644 index 00000000..26ead201 --- /dev/null +++ b/man/.gitignore @@ -0,0 +1,2 @@ +# ignore gzipped man pages +*.[0-9].gz diff --git a/man/Makefile b/man/Makefile new file mode 100644 index 00000000..fa25832e --- /dev/null +++ b/man/Makefile @@ -0,0 +1,5 @@ +all: + $(MAKE) -C .. all + +.DEFAULT: + $(MAKE) -C .. $@ diff --git a/man/Makefile.local b/man/Makefile.local new file mode 100644 index 00000000..d43a949c --- /dev/null +++ b/man/Makefile.local @@ -0,0 +1,60 @@ +# -*- Makefile -*- + +dir := man + +# this variable seems to be needed to prevent lazy evaluation causing +# problems with $(dir) changing values. +MAIN_PAGE := $(dir)/man1/notmuch.1 + +MAN1 := \ + $(MAIN_PAGE) \ + $(dir)/man1/notmuch-config.1 \ + $(dir)/man1/notmuch-count.1 \ + $(dir)/man1/notmuch-dump.1 \ + $(dir)/man1/notmuch-restore.1 \ + $(dir)/man1/notmuch-new.1 \ + $(dir)/man1/notmuch-reply.1 \ + $(dir)/man1/notmuch-search.1 \ + $(dir)/man1/notmuch-show.1 \ + $(dir)/man1/notmuch-tag.1 + +MAN5 := $(dir)/man5/notmuch-hooks.5 +MAN7 := $(dir)/man7/notmuch-search-terms.7 + +MAN1_GZ := $(addsuffix .gz,$(MAN1)) +MAN5_GZ := $(addsuffix .gz,$(MAN5)) +MAN7_GZ := $(addsuffix .gz,$(MAN7)) + +MAN_SOURCE := $(MAN1) $(MAN5) $(MAN7) +MAN_BACKUP := $(addsuffix .bak,$(MAN_SOURCE)) +COMPRESSED_MAN := $(MAN1_GZ) $(MAN5_GZ) $(MAN7_GZ) + +%.gz: % + gzip --stdout $^ > $@ + +.PHONY: install-man update-man-versions verify-version-manpage + +install-man: $(COMPRESSED_MAN) + mkdir -p "$(DESTDIR)$(mandir)/man1" + mkdir -p "$(DESTDIR)$(mandir)/man5" + mkdir -p "$(DESTDIR)$(mandir)/man7" + install -m0644 $(MAN1_GZ) $(DESTDIR)/$(mandir)/man1 + install -m0644 $(MAN5_GZ) $(DESTDIR)/$(mandir)/man5 + install -m0644 $(MAN7_GZ) $(DESTDIR)/$(mandir)/man7 + cd $(DESTDIR)/$(mandir)/man1 && ln -sf notmuch.1.gz notmuch-setup.1.gz + +verify-version-manpage: verify-version-components + @echo -n "Checking that manual page version is $(VERSION)..." + @[ "$(VERSION)" = $$(sed -n '/^[.]TH NOTMUCH 1/{s/.*"Notmuch //;s/".*//p;}' $(MAIN_PAGE)) ] || \ + (echo "No." && \ + echo "Please edit version and notmuch.1 to have consistent versions." && false) + @echo "Good." + +update-man-versions: $(MAN_SOURCE) + for file in $(MAN_SOURCE); do \ + cp $$file $$file.bak ; \ + sed "s/^.TH NOTMUCH\([^[:blank:]]*\) \([1-9]\) .*$$/.TH NOTMUCH\1 \2 ${DATE} \"Notmuch ${VERSION}\"/" \ + < $$file.bak > $$file; \ + done + +CLEAN := $(CLEAN) $(COMPRESSED_MAN) $(MAN_BACKUP) diff --git a/man/man1/notmuch-config.1 b/man/man1/notmuch-config.1 new file mode 100644 index 00000000..a7468950 --- /dev/null +++ b/man/man1/notmuch-config.1 @@ -0,0 +1,136 @@ +.TH NOTMUCH-CONFIG 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch-config \- Access notmuch configuration file. +.SH SYNOPSIS + +.B notmuch config get +.RI "<" section ">.<" item ">" + +.B notmuch config set +.RI "<" section ">.<" item "> [" value " ...]" + +.SH DESCRIPTION + +The +.B config +command can be used to get or set settings in the notmuch +configuration file. + +.RS 4 +.TP 4 +.B get +The value of the specified configuration item is printed to stdout. If +the item has multiple values (it is a list), each value is separated +by a newline character. +.RE + +.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. + +If no values are provided, the specified configuration item will be +removed from the configuration file. +.RE + +The available configuration items are described below. + +.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 + +.RS 4 +.TP 4 +.B user.name +Your full name. +.RE + +.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 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-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 new file mode 100644 index 00000000..8de43453 --- /dev/null +++ b/man/man1/notmuch-count.1 @@ -0,0 +1,50 @@ +.TH NOTMUCH-COUNT 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch-count \- Count messages matching the given search terms. +.SH SYNOPSIS + +.B notmuch count +.RI [ options "... ] <" search-term ">..." + +.SH DESCRIPTION + +Count messages matching the search terms. + +The number of matching messages (or threads) is output to stdout. + +With no search terms, a count of all messages (or threads) in the database will +be displayed. + +See \fBnotmuch-search-terms\fR(7) +for details of the supported syntax for <search-terms>. + +Supported options for +.B count +include +.RS 4 +.TP 4 +.B \-\-output=(messages|threads) + +.RS 4 +.TP 4 +.B messages + +Output the number of matching messages. This is the default. +.RE +.RS 4 +.TP 4 +.B threads + +Output the number of matching threads. +.RE +.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-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 new file mode 100644 index 00000000..f479e8bf --- /dev/null +++ b/man/man1/notmuch-dump.1 @@ -0,0 +1,37 @@ +.TH NOTMUCH-DUMP 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch-dump \- Creates a plain-text dump of the tags of each message. + +.SH SYNOPSIS + +.B "notmuch dump" +.RI "[ <" 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. + +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 +therefore the only critical thing to backup (and much more friendly to +incremental backup than the native database files.) + +With no search terms, a dump of all messages in the database will be +generated. A "--" argument instructs notmuch that the +remaining arguments are search terms. + +See \fBnotmuch-search-terms\fR(7) +for details of the supported syntax for <search-terms>. + +.RE +.SH SEE ALSO + +\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\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 new file mode 100644 index 00000000..613658d2 --- /dev/null +++ b/man/man1/notmuch-new.1 @@ -0,0 +1,70 @@ +.TH NOTMUCH-NEW 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch-new \- Incorporate new mail into the notmuch database. +.SH SYNOPSIS + +.B notmuch new +.RB "[" --no-hooks "]" + +.SH DESCRIPTION + +Find and import any new messages to the database. + +The +.B new +command scans all sub-directories of the database, performing +full-text indexing on new messages that are found. Each new message +will automatically be tagged with both the +.BR inbox " and " unread +tags. + +You should run +.B "notmuch new" +once after first running +.B "notmuch setup" +to create the initial database. The first run may take a long time if +you have a significant amount of mail (several hundred thousand +messages or more). Subsequently, you should run +.B "notmuch new" +whenever new mail is delivered and you wish to incorporate it into the +database. These subsequent runs will be much quicker than the initial +run. + +Invoking +.B notmuch +with no command argument will run +.B new +if +.B "notmuch setup" +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 +command supports hooks. See \fBnotmuch-hooks(5)\fR +for more details on hooks. + +Supported options for +.B new +include +.RS 4 +.TP 4 +.BR \-\-no\-hooks + +Prevents hooks from being run. +.RE +.RE +.SH SEE ALSO + +\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\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 new file mode 100644 index 00000000..bd95b5f8 --- /dev/null +++ b/man/man1/notmuch-reply.1 @@ -0,0 +1,86 @@ +.TH NOTMUCH-REPLY 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch-reply \- Constructs a reply template for a set of messages. + +.SH SYNOPSIS + +.B notmuch reply +.RI "[" options "...] <" search-term ">..." + +.SH DESCRIPTION + +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. 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 +replied to to the References list and setting the In\-Reply\-To: field +correctly. + +Finally, the original contents of the emails are quoted by prefixing +each line with '> ' and included in the body. + +The resulting message template is output to stdout. + +Supported options for +.B reply +include +.RS +.TP 4 +.BR \-\-format= ( default | headers\-only ) +.RS +.TP 4 +.BR default +Includes subject and quoted message body. +.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 + +See \fBnotmuch-search-terms\fR(7) +for details of the supported syntax for <search-terms>. + +Note: It is most common to use +.B "notmuch reply" +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. +.RE +.RE + +.SH SEE ALSO + +\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\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 new file mode 100644 index 00000000..db0b697e --- /dev/null +++ b/man/man1/notmuch-restore.1 @@ -0,0 +1,45 @@ +.TH NOTMUCH-RESTORE 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch-restore \- Restores the tags from the given file (see notmuch dump). + +.SH SYNOPSIS + +.B "notmuch restore" +.RB [ "--accumulate" ] +.RI "[ <" filename "> ]" + +.SH DESCRIPTION + +Restores the tags from the given file (see +.BR "notmuch dump" ")." + +The input is read from the given filename, if any, or from stdin. + +Note: The dump file format is specifically chosen to be +compatible with the format of files produced by sup-dump. +So if you've previously been using sup for mail, then the +.B "notmuch restore" +command provides you a way to import all of your tags (or labels as +sup calls them). + +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. + +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-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 new file mode 100644 index 00000000..bf172207 --- /dev/null +++ b/man/man1/notmuch-search.1 @@ -0,0 +1,121 @@ +.TH NOTMUCH-SEARCH 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch-search \- Search for messages matching the given search terms. +.SH SYNOPSIS + +.B notmuch search +.RI [ options "...] <" search-term ">..." + +.SH DESCRIPTION + +Search for messages matching the given search terms, and display as +results the threads containing the matched messages. + +The output consists of one line per thread, giving a thread ID, the +date of the newest (or oldest, depending on the sort option) matched +message in the thread, the number of matched messages and total +messages in the thread, the names of all participants in the thread, +and the subject of the newest (or oldest) message. + +See \fBnotmuch-search-terms\fR(7) +for details of the supported syntax for <search-terms>. + +Supported options for +.B search +include +.RS 4 +.TP 4 +.BR \-\-format= ( json | text ) + +Presents the results in either JSON or plain-text (default). +.RE + +.RS 4 +.TP 4 +.B \-\-output=(summary|threads|messages|files|tags) + +.RS 4 +.TP 4 +.B summary + +Output a summary of each thread with any message matching the search +terms. The summary includes the thread ID, date, the number of +messages in the thread (both the number matched and the total number), +the authors of the thread and the subject. +.RE +.RS 4 +.TP 4 +.B threads + +Output the thread IDs of all threads with any message matching the +search terms, either one per line (\-\-format=text) or as a JSON array +(\-\-format=json). +.RE +.RS 4 +.TP 4 +.B messages + +Output the message IDs of all messages matching the search terms, +either one per line (\-\-format=text) or as a JSON array +(\-\-format=json). +.RE +.RS 4 +.TP 4 +.B files + +Output the filenames of all messages matching the search terms, either +one per line (\-\-format=text) or as a JSON array (\-\-format=json). +.RE +.RS 4 +.TP 4 +.B tags + +Output all tags that appear on any message matching the search terms, +either one per line (\-\-format=text) or as a JSON array +(\-\-format=json). +.RE +.RE + +.RS 4 +.TP 4 +.BR \-\-sort= ( newest\-first | oldest\-first ) + +This option can be used to present results in either chronological order +.RB ( oldest\-first ) +or reverse chronological order +.RB ( newest\-first ). + +Note: The thread order will be distinct between these two options +(beyond being simply reversed). When sorting by +.B oldest\-first +the threads will be sorted by the oldest message in each thread, but +when sorting by +.B newest\-first +the threads will be sorted by the newest message in each thread. + +By default, results will be displayed in reverse chronological order, +(that is, the newest results will be displayed first). +.RE + +.RS 4 +.TP 4 +.BR \-\-offset=[\-]N + +Skip displaying the first N results. With the leading '\-', start at the Nth +result from the end. +.RE + +.RS 4 +.TP 4 +.BR \-\-limit=N + +Limit the number of displayed results to N. +.RE + +.SH SEE ALSO + +\fBnotmuch\fR(1), \fBnotmuch-config\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-terms\fR(7), \fBnotmuch-show\fR(1), +\fBnotmuch-tag\fR(1) diff --git a/man/man1/notmuch-setup.1 b/man/man1/notmuch-setup.1 new file mode 120000 index 00000000..5c78dc87 --- /dev/null +++ b/man/man1/notmuch-setup.1 @@ -0,0 +1 @@ +notmuch.1
\ No newline at end of file diff --git a/man/man1/notmuch-show.1 b/man/man1/notmuch-show.1 new file mode 100644 index 00000000..d69834a1 --- /dev/null +++ b/man/man1/notmuch-show.1 @@ -0,0 +1,145 @@ +.TH NOTMUCH-SHOW 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch-show \- Show messages matching the given search terms. +.SH SYNOPSIS + +.B notmuch show +.RI "[" options "...] <" search-term ">..." + +.SH DESCRIPTION + +Shows all messages matching the search terms. + +See \fBnotmuch-search-terms\fR(7) +for details of the supported syntax for <search-terms>. + +The messages will be grouped and sorted based on the threading (all +replies to a particular message will appear immediately after that +message in date order). The output is not indented by default, but +depth tags are printed so that proper indentation can be performed by +a post-processor (such as the emacs interface to notmuch). + +Supported options for +.B show +include +.RS 4 +.TP 4 +.B \-\-entire\-thread + +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. +.RE + +.RS 4 +.TP 4 +.B \-\-format=(text|json|mbox|raw) + +.RS 4 +.TP 4 +.BR text " (default for messages)" + +The default plain-text format has all text-content MIME parts +decoded. Various components in the output, +.RB ( message ", " header ", " body ", " attachment ", and MIME " part ), +will be delimited by easily-parsed markers. Each marker consists of a +Control-L character (ASCII decimal 12), the name of the marker, and +then either an opening or closing brace, ('{' or '}'), to either open +or close the component. For a multipart MIME message, these parts will +be nested. +.RE +.RS 4 +.TP 4 +.B json + +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 +.B \-\-format=json +implies +.B \-\-entire\-thread + +.RE +.RS 4 +.TP 4 +.B mbox + +All matching messages are output in the traditional, Unix mbox format +with each message being prefixed by a line beginning with "From " and +a blank line separating each message. Lines in the message content +beginning with "From " (preceded by zero or more '>' characters) have +an additional '>' character added. This reversible escaping +is termed "mboxrd" format and described in detail here: + +.nf +.nh +http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/mail-mbox-formats.html +.hy +.fi +. +.RE +.RS 4 +.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 single part (\-\-part) the raw part content is output after +performing any necessary MIME decoding. + +The raw format must only be used with search terms matching single +message. +.RE +.RE + +.RS 4 +.TP 4 +.B \-\-part=N + +Output the single decoded MIME part N of a single message. The search +terms must match only a single message. Message parts are numbered in +a depth-first walk of the message MIME structure, and are identified +in the 'json' or 'text' output formats. +.RE + +.RS 4 +.TP 4 +.B \-\-verify + +Compute and report the validity of any MIME cryptographic signatures +found in the selected content (ie. "multipart/signed" parts). Status +of the signature will be reported (currently only supported with +--format=json), and the multipart/signed part will be replaced by the +signed data. +.RE + +.RS 4 +.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 + +A common use of +.B notmuch show +is to display a single thread of email messages. For this, use a +search term of "thread:<thread-id>" as can be seen in the first +column of output from the +.B notmuch search +command. + +.SH SEE ALSO + +\fBnotmuch\fR(1), \fBnotmuch-config\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-tag\fR(1) diff --git a/man/man1/notmuch-tag.1 b/man/man1/notmuch-tag.1 new file mode 100644 index 00000000..aa4546e4 --- /dev/null +++ b/man/man1/notmuch-tag.1 @@ -0,0 +1,38 @@ +.TH NOTMUCH-TAG 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch-tag \- Add/remove tags for all messages matching the search terms. + +.SH SYNOPSIS +.B notmuch tag +.RI "+<" tag> "|\-<" tag "> [...] [\-\-] <" search-term ">..." + +.SH DESCRIPTION + +Add/remove tags for all messages matching the search terms. + +See \fBnotmuch-search-terms\fR(7) +for details of the supported syntax for <search-terms>. + +Tags prefixed by '+' are added while those prefixed by '\-' are +removed. For each message, tag removal is performed before tag +addition. + +The beginning of <search-terms> is recognized by the first +argument that begins with neither '+' nor '\-'. Support for +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(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 new file mode 100644 index 00000000..2afcc771 --- /dev/null +++ b/man/man1/notmuch.1 @@ -0,0 +1,147 @@ +.\" notmuch - Not much of an email program, (just index, search and tagging) +.\" +.\" Copyright © 2009 Carl Worth +.\" +.\" 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 this program. If not, see http://www.gnu.org/licenses/ . +.\" +.\" Author: Carl Worth <cworth@cworth.org> +.TH NOTMUCH 1 2012-03-19 "Notmuch 0.12" +.SH NAME +notmuch \- thread-based email index, search, and tagging +.SH SYNOPSIS +.B notmuch +.IR command " [" args " ...]" +.SH DESCRIPTION +Notmuch is a command-line based program for indexing, searching, +reading, and tagging large collections of email messages. + +This page describes how to get started using notmuch from the command +line, and gives a brief overview of the commands available. For more +information on e.g. +.B notmuch show +consult the \fBnotmuch-show\fR(1) man page, also accessible via +.B notmuch help show + +The quickest way to get started with Notmuch is to simply invoke the +.B notmuch +command with no arguments, which will interactively guide you through +the process of indexing your mail. +.SH NOTE +While the command-line program +.B notmuch +provides powerful functionality, it does not provide the most +convenient interface for that functionality. More sophisticated +interfaces are expected to be built on top of either the command-line +interface, or more likely, on top of the notmuch library +interface. See http://notmuchmail.org for more about alternate +interfaces to notmuch. The emacs-based interface to notmuch (available under +.B emacs/ +in the Notmuch source distribution) is probably the most widely used at +this time. + +.SH COMMANDS + + +.SS SETUP + +The +.B notmuch setup +command is used to configure Notmuch for first use, (or to reconfigure +it later). + +The setup command will prompt for your full name, your primary email +address, any alternate email addresses you use, and the directory +containing your email archives. Your answers will be written to a +configuration file in ${NOTMUCH_CONFIG} (if set) or +${HOME}/.notmuch-config . This configuration file will be created with +descriptive comments, making it easy to edit by hand later to change the +configuration. Or you can run +.B "notmuch setup" +again to change the configuration. + +The mail directory you specify can contain any number of +sub-directories and should primarily contain only files with individual +email messages (eg. maildir or mh archives are perfect). If there are +other, non-email files (such as indexes maintained by other email +programs) then notmuch will do its best to detect those and ignore +them. + +Mail storage that uses mbox format, (where one mbox file contains many +messages), will not work with notmuch. If that's how your mail is +currently stored, it is recommended you first convert it to maildir +format with a utility such as mb2md before running +.B "notmuch setup" . + +Invoking +.B notmuch +with no command argument will run +.B setup +if the setup command has not previously been completed. +.RE + +.SS OTHER COMMANDS + +Several of the notmuch commands accept search terms with a common +syntax. See \fNnotmuch-search-terms\fR(7) +for more details on the supported syntax. + +The +.BR search ", " show " and " count +commands are used to query the email database. + +The +.B reply +command is useful for preparing a template for an email reply. + +The +.B tag +command is the only command available for manipulating database +contents. + + +The +.BR dump " and " restore +commands can be used to create a textual dump of email tags for backup +purposes, and to restore from that dump. + +The +.B config +command can be used to get or set settings int the notmuch +configuration file. + +.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-config\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) + + +The notmuch website: +.B http://notmuchmail.org +.SH CONTACT +Feel free to send questions, comments, or kudos to the notmuch mailing +list <notmuch@notmuchmail.org> . Subscription is not required before +posting, but is available from the notmuchmail.org website. + +Real-time interaction with the Notmuch community is available via IRC +(server: irc.freenode.net, channel: #notmuch). diff --git a/man/man5/notmuch-hooks.5 b/man/man5/notmuch-hooks.5 new file mode 100644 index 00000000..9662bdeb --- /dev/null +++ b/man/man5/notmuch-hooks.5 @@ -0,0 +1,48 @@ +.TH NOTMUCH-HOOKS 5 2012-03-19 "Notmuch 0.12" + +.SH NAME +notmuch-hooks \- hooks for notmuch + +.SH SYNOPSIS + $DATABASEDIR/.notmuch/hooks/* + +.SH DESCRIPTION +Hooks are scripts (or arbitrary executables or symlinks to such) that notmuch +invokes before and after certain actions. These scripts reside in +the .notmuch/hooks directory within the database directory and must have +executable permissions. + +The currently available hooks are described below. +.RS 4 +.TP 4 +.B pre\-new +This hook is invoked by the +.B new +command before scanning or importing new messages into the database. If this +hook exits with a non-zero status, notmuch will abort further processing of the +.B new +command. + +Typically this hook is used for fetching or delivering new mail to be imported +into the database. +.RE +.RS 4 +.TP 4 +.B post\-new +This hook is invoked by the +.B new +command after new messages have been imported into the database and initial tags +have been applied. The hook will not be run if there have been any errors during +the scan or import. + +Typically this hook is used to perform additional query\-based tagging on the +imported messages. +.RE + +.SH SEE ALSO + +\fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\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 new file mode 100644 index 00000000..37ba9bb1 --- /dev/null +++ b/man/man7/notmuch-search-terms.7 @@ -0,0 +1,140 @@ +.TH NOTMUCH-SEARCH-TERMS 7 2012-03-19 "Notmuch 0.12" + +.SH NAME +notmuch-search-terms \- Syntax for notmuch queries + +.SH SYNOPSIS + +.B notmuch count +.RI [ options... ] +.RI < search-term ">..." + +.B "notmuch dump" +.RI "[ <" filename "> ] [--]" +.RI "[ <" search-term ">...]" + +.B notmuch search +.RI [ options "...] <" search-term ">..." + +.B notmuch show +.RI "[" options "...] <" search-term ">..." + +.B notmuch tag +.RI "+<" tag> "|\-<" tag "> [...] [\-\-] <" search-term ">..." + + +.SH DESCRIPTION +Several notmuch commands accept a common syntax for search terms. + +The search terms can consist of free-form text (and quoted phrases) +which will match all messages that contain all of the given +terms/phrases in the body, the subject, or any of the sender or +recipient headers. + +As a special case, a search string consisting of exactly a single +asterisk ("*") will match all messages. + +In addition to free text, the following prefixes can be used to force +terms to match against specific portions of an email, (where +<brackets> indicate user-supplied values): + + from:<name-or-address> + + to:<name-or-address> + + subject:<word-or-quoted-phrase> + + attachment:<word> + + tag:<tag> (or is:<tag>) + + id:<message-id> + + thread:<thread-id> + + folder:<directory-path> + +The +.B from: +prefix is used to match the name or address of the sender of an email +message. + +The +.B to: +prefix is used to match the names or addresses of any recipient of an +email message, (whether To, Cc, or Bcc). + +Any term prefixed with +.B subject: +will match only text from the subject of an email. Searching for a +phrase in the subject is supported by including quotation marks around +the phrase, immediately following +.BR subject: . + +The +.B attachment: +prefix can be used to search for specific filenames (or extensions) of +attachments to email messages. + +For +.BR tag: " and " is: +valid tag values include +.BR inbox " and " unread +by default for new messages added by +.B notmuch new +as well as any other tag values added manually with +.BR "notmuch tag" . + +For +.BR id: , +message ID values are the literal contents of the Message\-ID: header +of email messages, but without the '<', '>' delimiters. + +The +.B thread: +prefix can be used with the thread ID values that are generated +internally by notmuch (and do not appear in email messages). These +thread ID values can be seen in the first column of output from +.B "notmuch search" + +The +.B folder: +prefix can be used to search for email message files that are +contained within particular directories within the mail store. Only +the directory components below the top-level mail database path are +available to be searched. + +In addition to individual terms, multiple terms can be +combined with Boolean operators ( +.BR and ", " or ", " not +, etc.). Each term in the query will be implicitly connected by a +logical AND if no explicit operator is provided, (except that terms +with a common prefix will be implicitly combined with OR until we get +Xapian defect #402 fixed). + +Parentheses can also be used to control the combination of the Boolean +operators, but will have to be protected from interpretation by the +shell, (such as by putting quotation marks around any parenthesized +expression). + +Finally, results can be restricted to only messages within a +particular time range, (based on the Date: header) with a syntax of: + + <initial-timestamp>..<final-timestamp> + +Each timestamp is a number representing the number of seconds since +1970\-01\-01 00:00:00 UTC. This is not the most convenient means of +expressing date ranges, but until notmuch is fixed to accept a more +convenient form, one can use the date program to construct +timestamps. For example, with the bash shell the following syntax would +specify a date range to return messages from 2009\-10\-01 until the +current time: + + $(date +%s \-d 2009\-10\-01)..$(date +%s) + +.SH SEE ALSO + +\fBnotmuch\fR(1), \fBnotmuch-config\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-show\fR(1), \fBnotmuch-tag\fR(1) diff --git a/mime-node.c b/mime-node.c new file mode 100644 index 00000000..a95bdabc --- /dev/null +++ b/mime-node.c @@ -0,0 +1,365 @@ +/* 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> + * Austin Clements <aclements@csail.mit.edu> + */ + +#include "notmuch-client.h" + +/* Context that gets inherited from the root node. */ +typedef struct mime_node_context { + /* Per-message resources. These are allocated internally and must + * be destroyed. */ + FILE *file; + GMimeStream *stream; + GMimeParser *parser; + GMimeMessage *mime_message; + + /* Context provided by the caller. */ +#ifdef GMIME_ATLEAST_26 + GMimeCryptoContext *cryptoctx; +#else + GMimeCipherContext *cryptoctx; +#endif + notmuch_bool_t decrypt; +} mime_node_context_t; + +static int +_mime_node_context_free (mime_node_context_t *res) +{ + if (res->mime_message) + g_object_unref (res->mime_message); + + if (res->parser) + g_object_unref (res->parser); + + if (res->stream) + g_object_unref (res->stream); + + if (res->file) + fclose (res->file); + + return 0; +} + +notmuch_status_t +mime_node_open (const void *ctx, notmuch_message_t *message, +#ifdef GMIME_ATLEAST_26 + GMimeCryptoContext *cryptoctx, +#else + GMimeCipherContext *cryptoctx, +#endif + notmuch_bool_t decrypt, mime_node_t **root_out) +{ + const char *filename = notmuch_message_get_filename (message); + mime_node_context_t *mctx; + mime_node_t *root; + notmuch_status_t status; + + root = talloc_zero (ctx, mime_node_t); + if (root == NULL) { + fprintf (stderr, "Out of memory.\n"); + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + + /* Create the tree-wide context */ + mctx = talloc_zero (root, mime_node_context_t); + if (mctx == NULL) { + fprintf (stderr, "Out of memory.\n"); + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + talloc_set_destructor (mctx, _mime_node_context_free); + + mctx->file = fopen (filename, "r"); + if (! mctx->file) { + fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno)); + status = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; + } + + 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; + + /* Create the root node */ + root->part = GMIME_OBJECT (mctx->mime_message); + root->envelope_file = 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; + +DONE: + talloc_free (root); + 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 (mime_node_t *parent, GMimeObject *part) +{ + mime_node_t *node = talloc_zero (parent, mime_node_t); + GError *err = NULL; + + /* Set basic node properties */ + node->part = part; + node->ctx = parent->ctx; + if (!talloc_reference (node, node->ctx)) { + fprintf (stderr, "Out of memory.\n"); + 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)) { + node->nchildren = 0; + } else if (GMIME_IS_MULTIPART (part)) { + node->nchildren = g_mime_multipart_get_count (GMIME_MULTIPART (part)); + } else if (GMIME_IS_MESSAGE_PART (part)) { + /* Promote part to an envelope and open it */ + GMimeMessagePart *message_part = GMIME_MESSAGE_PART (part); + GMimeMessage *message = g_mime_message_part_get_message (message_part); + node->envelope_part = message_part; + node->part = GMIME_OBJECT (message); + node->nchildren = 1; + } else { + fprintf (stderr, "Warning: Unknown mime part type: %s.\n", + g_type_name (G_OBJECT_TYPE (part))); + talloc_free (node); + return NULL; + } + + /* Handle PGP/MIME parts */ + if (GMIME_IS_MULTIPART_ENCRYPTED (part) + && node->ctx->cryptoctx && node->ctx->decrypt) { + 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 " + "message (must be exactly 2)\n", + node->nchildren); + } else { + 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, &decrypt_result, &err); +#else + node->decrypted_child = g_mime_multipart_encrypted_decrypt + (encrypteddata, node->ctx->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) { + 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), node->ctx->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 + * g_mime_multipart_encrypted_get_signature_validity, + * and therefore needs to be properly disposed of. + * + * 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); + node->verify_attempted = TRUE; + node->sig_validity = sig_validity; + if (sig_validity) { + GMimeSignatureValidity **proxy = + talloc (node, GMimeSignatureValidity *); + *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); + + return node; +} + +mime_node_t * +mime_node_child (mime_node_t *parent, int child) +{ + GMimeObject *sub; + mime_node_t *node; + + if (!parent || child < 0 || child >= parent->nchildren) + return NULL; + + if (GMIME_IS_MULTIPART (parent->part)) { + if (child == 1 && parent->decrypted_child) + sub = parent->decrypted_child; + else + sub = g_mime_multipart_get_part + (GMIME_MULTIPART (parent->part), child); + } else if (GMIME_IS_MESSAGE (parent->part)) { + sub = g_mime_message_get_mime_part (GMIME_MESSAGE (parent->part)); + } else { + /* This should have been caught by message_part_create */ + INTERNAL_ERROR ("Unexpected GMimeObject type: %s", + g_type_name (G_OBJECT_TYPE (parent->part))); + } + 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 * +_mime_node_seek_dfs_walk (mime_node_t *node, int *n) +{ + mime_node_t *ret = NULL; + int i; + + if (*n == 0) + return node; + + *n -= 1; + for (i = 0; i < node->nchildren && !ret; i++) { + mime_node_t *child = mime_node_child (node, i); + ret = _mime_node_seek_dfs_walk (child, n); + if (!ret) + talloc_free (child); + } + return ret; +} + +mime_node_t * +mime_node_seek_dfs (mime_node_t *node, int n) +{ + if (n < 0) + return NULL; + return _mime_node_seek_dfs_walk (node, &n); +} diff --git a/notmuch-client.h b/notmuch-client.h index c602e2e0..f4a62ccb 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -30,6 +30,14 @@ #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 +#endif + #include "notmuch.h" /* This is separate from notmuch-private.h because we're trying to @@ -54,8 +62,14 @@ #define STRINGIFY(s) STRINGIFY_(s) #define STRINGIFY_(s) #s +struct mime_node; +struct notmuch_show_params; + typedef struct notmuch_show_format { const char *message_set_start; + void (*part) (const void *ctx, + struct mime_node *node, int indent, + const struct notmuch_show_params *params); const char *message_start; void (*message) (const void *ctx, notmuch_message_t *message, @@ -69,7 +83,11 @@ typedef struct notmuch_show_format { void (*part_start) (GMimeObject *part, int *part_count); void (*part_encstatus) (int status); +#ifdef GMIME_ATLEAST_26 + void (*part_sigstatus) (GMimeSignatureList* siglist); +#else void (*part_sigstatus) (const GMimeSignatureValidity* validity); +#endif void (*part_content) (GMimeObject *part); void (*part_end) (GMimeObject *part); const char *part_sep; @@ -80,11 +98,15 @@ typedef struct notmuch_show_format { } notmuch_show_format_t; typedef struct notmuch_show_params { - int entire_thread; - int raw; + notmuch_bool_t entire_thread; + notmuch_bool_t raw; int part; +#ifdef GMIME_ATLEAST_26 + GMimeCryptoContext* cryptoctx; +#else GMimeCipherContext* cryptoctx; - int decrypt; +#endif + notmuch_bool_t decrypt; } notmuch_show_params_t; /* There's no point in continuing when we've detected that we've done @@ -162,7 +184,7 @@ char * query_string_from_args (void *ctx, int argc, char *argv[]); notmuch_status_t -show_message_body (const char *filename, +show_message_body (notmuch_message_t *message, const notmuch_show_format_t *format, notmuch_show_params_t *params); @@ -228,6 +250,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,11 +266,129 @@ 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); notmuch_bool_t debugger_is_active (void); +/* mime-node.c */ + +/* mime_node_t represents a single node in a MIME tree. A MIME tree + * abstracts the different ways of traversing different types of MIME + * parts, allowing a MIME message to be viewed as a generic tree of + * parts. Message-type parts have one child, multipart-type parts + * have multiple children, and leaf parts have zero children. + */ +typedef struct mime_node { + /* The MIME object of this part. This will be a GMimeMessage, + * GMimePart, GMimeMultipart, or a subclass of one of these. + * + * This will never be a GMimeMessagePart because GMimeMessagePart + * is structurally redundant with GMimeMessage. If this part is a + * message (that is, 'part' is a GMimeMessage), then either + * envelope_file will be set to a notmuch_message_t (for top-level + * messages) or envelope_part will be set to a GMimeMessagePart + * (for embedded message parts). + */ + GMimeObject *part; + + /* If part is a GMimeMessage, these record the envelope of the + * message: either a notmuch_message_t representing a top-level + * message, or a GMimeMessagePart representing a MIME part + * containing a message. + */ + notmuch_message_t *envelope_file; + GMimeMessagePart *envelope_part; + + /* 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 + * case, the decrypted part is substituted for the second child of + * this part (which would usually be the encrypted data). */ + notmuch_bool_t decrypt_success; + + /* 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; + + /* Internal: For successfully decrypted multipart parts, the + * decrypted part to substitute for the second child. */ + GMimeObject *decrypted_child; + + /* 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; +} mime_node_t; + +/* 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. + * + * Return value: + * + * NOTMUCH_STATUS_SUCCESS: Root node is returned in *node_out. + * + * NOTMUCH_STATUS_FILE_ERROR: Failed to open message file. + * + * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory. + */ +notmuch_status_t +mime_node_open (const void *ctx, notmuch_message_t *message, +#ifdef GMIME_ATLEAST_26 + GMimeCryptoContext *cryptoctx, +#else + GMimeCipherContext *cryptoctx, +#endif + notmuch_bool_t decrypt, 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 + * node. + * + * In case of any failure, this function returns NULL, (after printing + * an error message on stderr). + */ +mime_node_t * +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. */ +mime_node_t * +mime_node_seek_dfs (mime_node_t *node, int n); + #include "command-line-arguments.h" #endif diff --git a/notmuch-config.c b/notmuch-config.c index d697138a..61fda3ea 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,18 @@ 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) { + /* We do not set default search_exclude_tags for 0.12 */ + } 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 +425,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 +480,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 +606,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 +622,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 +648,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. diff --git a/notmuch-count.c b/notmuch-count.c index 20ce3342..63459fb6 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -21,6 +21,11 @@ #include "notmuch-client.h" +enum { + OUTPUT_THREADS, + OUTPUT_MESSAGES, +}; + int notmuch_count_command (void *ctx, int argc, char *argv[]) { @@ -28,34 +33,25 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) notmuch_database_t *notmuch; notmuch_query_t *query; char *query_str; - int i; - notmuch_bool_t output_messages = TRUE; + int opt_index; + int output = OUTPUT_MESSAGES; + const char **search_exclude_tags; + size_t search_exclude_tags_length; + unsigned int i; - argc--; argv++; /* skip subcommand argument */ + notmuch_opt_desc_t options[] = { + { NOTMUCH_OPT_KEYWORD, &output, "output", 'o', + (notmuch_keyword_t []){ { "threads", OUTPUT_THREADS }, + { "messages", OUTPUT_MESSAGES }, + { 0, 0 } } }, + { 0, 0, 0, 0, 0 } + }; - for (i = 0; i < argc && argv[i][0] == '-'; i++) { - if (strcmp (argv[i], "--") == 0) { - i++; - break; - } - if (STRNCMP_LITERAL (argv[i], "--output=") == 0) { - const char *opt = argv[i] + sizeof ("--output=") - 1; - if (strcmp (opt, "threads") == 0) { - output_messages = FALSE; - } else if (strcmp (opt, "messages") == 0) { - output_messages = TRUE; - } else { - fprintf (stderr, "Invalid value for --output: %s\n", opt); - return 1; - } - } else { - fprintf (stderr, "Unrecognized option: %s\n", argv[i]); - return 1; - } - } + opt_index = parse_arguments (argc, argv, options, 1); - argc -= i; - argv += i; + if (opt_index < 0) { + return 1; + } config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) @@ -66,7 +62,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) if (notmuch == NULL) return 1; - query_str = query_string_from_args (ctx, argc, argv); + query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index); if (query_str == NULL) { fprintf (stderr, "Out of memory.\n"); return 1; @@ -82,10 +78,19 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) return 1; } - if (output_messages) + 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)); - else + break; + case OUTPUT_THREADS: printf ("%u\n", notmuch_query_count_threads (query)); + break; + } notmuch_query_destroy (query); notmuch_database_close (notmuch); diff --git a/notmuch-new.c b/notmuch-new.c index 3512de72..4f13535c 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; } @@ -177,6 +183,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) @@ -316,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch, } /* 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; } @@ -365,6 +385,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) && @@ -555,12 +579,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) @@ -644,7 +670,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 +692,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 +719,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 @@ -833,6 +861,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,7 +877,7 @@ 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; diff --git a/notmuch-reply.c b/notmuch-reply.c index 7242310a..6b244e6d 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -31,7 +31,7 @@ static void reply_part_content (GMimeObject *part); static const notmuch_show_format_t format_reply = { - "", + "", NULL, "", NULL, "", NULL, reply_headers_message_part, ">\n", "", @@ -168,22 +168,29 @@ address_is_users (const char *address, notmuch_config_t *config) return 0; } -/* 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'. * - * The first address encountered that *is* the user's address will be - * returned, (otherwise NULL is returned). + * 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. + * + * 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 +203,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 +215,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 +291,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 +321,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 +340,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 +348,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; @@ -480,7 +509,8 @@ 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; @@ -509,7 +539,8 @@ notmuch_reply_format_default(void *ctx, g_mime_message_set_subject (reply, subject); } - from_addr = add_recipients_from_message (reply, config, message); + from_addr = add_recipients_from_message (reply, config, message, + reply_all); if (from_addr == NULL) from_addr = guess_from_received_header (config, message); @@ -546,8 +577,7 @@ notmuch_reply_format_default(void *ctx, notmuch_message_get_header (message, "date"), notmuch_message_get_header (message, "from")); - show_message_body (notmuch_message_get_filename (message), - format, params); + show_message_body (message, format, params); notmuch_message_destroy (message); } @@ -559,7 +589,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; @@ -599,7 +630,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); @@ -613,62 +644,72 @@ notmuch_reply_format_headers_only(void *ctx, return 0; } +enum { + FORMAT_DEFAULT, + FORMAT_HEADERS_ONLY, +}; + int notmuch_reply_command (void *ctx, int argc, char *argv[]) { notmuch_config_t *config; notmuch_database_t *notmuch; notmuch_query_t *query; - char *opt, *query_string; - int i, ret = 0; - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params); + 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_bool_t reply_all); notmuch_show_params_t params = { .part = -1 }; + int format = FORMAT_DEFAULT; + int reply_all = TRUE; - reply_format_func = notmuch_reply_format_default; + notmuch_opt_desc_t options[] = { + { NOTMUCH_OPT_KEYWORD, &format, "format", 'f', + (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT }, + { "headers-only", FORMAT_HEADERS_ONLY }, + { 0, 0 } } }, + { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r', + (notmuch_keyword_t []){ { "all", TRUE }, + { "sender", FALSE }, + { 0, 0 } } }, + { NOTMUCH_OPT_BOOLEAN, ¶ms.decrypt, "decrypt", 'd', 0 }, + { 0, 0, 0, 0, 0 } + }; - argc--; argv++; /* skip subcommand argument */ + opt_index = parse_arguments (argc, argv, options, 1); + if (opt_index < 0) { + /* diagnostics already printed */ + return 1; + } - for (i = 0; i < argc && argv[i][0] == '-'; i++) { - if (strcmp (argv[i], "--") == 0) { - i++; - break; - } - if (STRNCMP_LITERAL (argv[i], "--format=") == 0) { - opt = argv[i] + sizeof ("--format=") - 1; - if (strcmp (opt, "default") == 0) { - reply_format_func = notmuch_reply_format_default; - } else if (strcmp (opt, "headers-only") == 0) { - reply_format_func = notmuch_reply_format_headers_only; - } else { - fprintf (stderr, "Invalid value for --format: %s\n", opt); - return 1; - } - } else if ((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 { - params.decrypt = TRUE; - g_mime_gpg_context_set_always_trust((GMimeGpgContext*)params.cryptoctx, FALSE); - } - g_object_unref (session); - session = NULL; - } + if (format == FORMAT_HEADERS_ONLY) + reply_format_func = notmuch_reply_format_headers_only; + else + reply_format_func = notmuch_reply_format_default; + + if (params.decrypt) { +#ifdef GMIME_ATLEAST_26 + /* TODO: GMimePasswordRequestFunc */ + params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg"); +#else + GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL); + params.cryptoctx = g_mime_gpg_context_new (session, "gpg"); +#endif + if (params.cryptoctx) { + g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE); } else { - fprintf (stderr, "Unrecognized option: %s\n", argv[i]); - return 1; + params.decrypt = FALSE; + fprintf (stderr, "Failed to construct gpg context.\n"); } +#ifndef GMIME_ATLEAST_26 + g_object_unref (session); +#endif } - argc -= i; - argv += i; - 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; @@ -690,7 +731,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) return 1; } - if (reply_format_func (ctx, config, query, ¶ms) != 0) + if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0) return 1; notmuch_query_destroy (query); diff --git a/notmuch-search.c b/notmuch-search.c index 4baab561..92ce38a1 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -90,6 +90,9 @@ format_thread_json (const void *ctx, const int total, const char *authors, const char *subject); + +/* Any changes to the JSON format should be reflected in the file + * devel/schemata. */ static const search_format_t format_json = { "[", "{", @@ -423,6 +426,9 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) output_t output = OUTPUT_SUMMARY; int offset = 0; int limit = -1; /* unlimited */ + const char **search_exclude_tags; + size_t search_exclude_tags_length; + unsigned int i; enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT } format_sel = NOTMUCH_FORMAT_TEXT; @@ -490,6 +496,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) notmuch_query_set_sort (query, sort); + 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) { default: case OUTPUT_SUMMARY: diff --git a/notmuch-setup.c b/notmuch-setup.c index c3ea9371..307231d5 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[])) @@ -164,30 +196,11 @@ 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) ["); - - for (i = 0; i < new_tags_len; i++) { - if (i != 0) - printf (" "); - printf ("%s", new_tags[i]); - } - + print_tag_list (new_tags, new_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); @@ -195,6 +208,9 @@ notmuch_setup_command (unused (void *ctx), g_ptr_array_free (tags, TRUE); } + + /* Temporarily remove exclude tag support for 0.12 */ + if (! notmuch_config_save (config)) { if (is_new) welcome_message_post_setup (); diff --git a/notmuch-show.c b/notmuch-show.c index 19fb49f2..93fb16f3 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -21,40 +21,17 @@ #include "notmuch-client.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); +format_part_text (const void *ctx, 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", "", - "" + .message_set_start = "", + .part = format_part_text, + .message_set_sep = "", + .message_set_end = "" }; static void @@ -76,7 +53,11 @@ static void format_part_encstatus_json (int status); static void +#ifdef GMIME_ATLEAST_26 +format_part_sigstatus_json (GMimeSignatureList* siglist); +#else format_part_sigstatus_json (const GMimeSignatureValidity* validity); +#endif static void format_part_content_json (GMimeObject *part); @@ -84,8 +65,10 @@ format_part_content_json (GMimeObject *part); static void format_part_end_json (GMimeObject *part); +/* Any changes to the JSON format should be reflected in the file + * devel/schemata. */ static const notmuch_show_format_t format_json = { - "[", + "[", NULL, "{", format_message_json, "\"headers\": {", format_headers_json, format_headers_message_part_json, "}", ", \"body\": [", @@ -106,7 +89,7 @@ format_message_mbox (const void *ctx, unused (int indent)); static const notmuch_show_format_t format_mbox = { - "", + "", NULL, "", format_message_mbox, "", NULL, NULL, "", "", @@ -125,7 +108,7 @@ static void format_part_content_raw (GMimeObject *part); static const notmuch_show_format_t format_raw = { - "", + "", NULL, "", NULL, "", NULL, format_headers_message_part_text, "\n", "", @@ -187,16 +170,6 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message) } 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)) { notmuch_tags_t *tags; @@ -334,32 +307,13 @@ format_message_mbox (const void *ctx, 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; - - printf ("%s\n", _get_one_line_summary (ctx, message)); - - 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); - } -} - static void format_headers_message_part_text (GMimeMessage *message) { InternetAddressList *recipients; const char *recipients_string; + 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); @@ -371,7 +325,6 @@ format_headers_message_part_text (GMimeMessage *message) 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)); } @@ -486,6 +439,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,97 +469,93 @@ signer_status_to_string (GMimeSignerStatus x) } return "unknown"; } +#endif static void -format_part_start_text (GMimeObject *part, int *part_count) +format_part_start_json (unused (GMimeObject *part), int *part_count) { - GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part); - - if (disposition && - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) - { - printf ("\fattachment{ ID: %d", *part_count); + printf ("{\"id\": %d", *part_count); +} +static void +format_part_encstatus_json (int status) +{ + printf (", \"encstatus\": [{\"status\": "); + if (status) { + printf ("\"good\""); } else { - - printf ("\fpart{ ID: %d", *part_count); + printf ("\"bad\""); } + printf ("}]"); } +#ifdef GMIME_ATLEAST_26 static void -format_part_content_text (GMimeObject *part) +format_part_sigstatus_json (GMimeSignatureList *siglist) { - const char *cid = g_mime_object_get_content_id (part); - GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part)); + printf (", \"sigstatus\": ["); - if (GMIME_IS_PART (part)) - { - const char *filename = g_mime_part_get_filename (GMIME_PART (part)); - if (filename) - printf (", Filename: %s", filename); + if (!siglist) { + printf ("]"); + return; } - if (cid) - printf (", Content-id: %s", cid); + void *ctx_quote = talloc_new (NULL); + 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)); + if (i > 0) + printf (", "); - 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)); - } -} + printf ("{"); -static void -format_part_end_text (GMimeObject *part) -{ - GMimeContentDisposition *disposition; + /* status */ + GMimeSignatureStatus status = g_mime_signature_get_status (signature); + printf ("\"status\": %s", + json_quote_str (ctx_quote, + signature_status_to_string (status))); - disposition = g_mime_object_get_content_disposition (part); - if (disposition && - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) - { - printf ("\fattachment}\n"); - } - else - { - printf ("\fpart}\n"); - } -} + GMimeCertificate *certificate = g_mime_signature_get_certificate (signature); + if (status == GMIME_SIGNATURE_STATUS_GOOD) { + if (certificate) + printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, 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) + printf (", \"created\": %d", (int) created); + time_t expires = g_mime_signature_get_expires (signature); + if (expires > 0) + printf (", \"expires\": %d", (int) 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)) + printf (", \"userid\": %s", json_quote_str (ctx_quote, name)); + } + } else if (certificate) { + const char *key_id = g_mime_certificate_get_key_id (certificate); + if (key_id) + printf (", \"keyid\": %s", json_quote_str (ctx_quote, key_id)); + } -static void -format_part_start_json (unused (GMimeObject *part), int *part_count) -{ - printf ("{\"id\": %d", *part_count); -} + GMimeSignatureError errors = g_mime_signature_get_errors (signature); + if (errors != GMIME_SIGNATURE_ERROR_NONE) { + printf (", \"errors\": %d", errors); + } -static void -format_part_encstatus_json (int status) -{ - printf (", \"encstatus\": [{\"status\": "); - if (status) { - printf ("\"good\""); - } else { - printf ("\"bad\""); - } - printf ("}]"); -} + printf ("}"); + } + + printf ("]"); + talloc_free (ctx_quote); +} +#else static void format_part_sigstatus_json (const GMimeSignatureValidity* validity) { @@ -641,7 +605,7 @@ format_part_sigstatus_json (const GMimeSignatureValidity* validity) printf (", \"keyid\": %s", json_quote_str (ctx_quote, signer->keyid)); } if (signer->errors != GMIME_SIGNER_ERROR_NONE) { - printf (", \"errors\": %x", signer->errors); + printf (", \"errors\": %d", signer->errors); } printf ("}"); @@ -652,6 +616,7 @@ format_part_sigstatus_json (const GMimeSignatureValidity* validity) talloc_free (ctx_quote); } +#endif static void format_part_content_json (GMimeObject *part) @@ -675,13 +640,31 @@ format_part_content_json (GMimeObject *part) printf (", \"filename\": %s", json_quote_str (ctx, filename)); } - if (g_mime_content_type_is_type (content_type, "text", "*") && - !g_mime_content_type_is_type (content_type, "text", "html")) + if (g_mime_content_type_is_type (content_type, "text", "*")) { - show_text_part_content (part, stream_memory); - part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory)); + /* 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 + * caller is interested in text/html parts, it should retrieve + * them separately and they will not be decoded. Since this + * 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 (content_charset != NULL) + printf (", \"content-charset\": %s", json_quote_str (ctx, content_charset)); + } + else + { + show_text_part_content (part, stream_memory); + 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)); + printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len)); + } } else if (g_mime_content_type_is_type (content_type, "multipart", "*")) { @@ -738,12 +721,115 @@ format_part_content_raw (GMimeObject *part) } static void +format_part_text (const void *ctx, 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 filename:%s\n", + part_type, + notmuch_message_get_message_id (message), + indent, + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH), + 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"); + } + + 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); + 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, mime_node_child (node, i), indent, params); + + if (GMIME_IS_MESSAGE (node->part)) + printf ("\fbody}\n"); + + printf ("\f%s}\n", part_type); +} + +static void show_message (void *ctx, const notmuch_show_format_t *format, notmuch_message_t *message, int indent, notmuch_show_params_t *params) { + if (format->part) { + void *local = talloc_new (ctx); + mime_node_t *root, *part; + + if (mime_node_open (local, message, params->cryptoctx, params->decrypt, + &root) == NOTMUCH_STATUS_SUCCESS && + (part = mime_node_seek_dfs (root, (params->part < 0 ? + 0 : params->part)))) + format->part (local, part, indent, params); + talloc_free (local); + return; + } + if (params->part <= 0) { fputs (format->message_start, stdout); if (format->message) @@ -758,8 +844,7 @@ show_message (void *ctx, } if (format->part_content) - show_message_body (notmuch_message_get_filename (message), - format, params); + show_message_body (message, format, params); if (params->part <= 0) { fputs (format->body_end, stdout); @@ -866,7 +951,17 @@ do_show_single (void *ctx, while (!feof (file)) { size = fread (buf, 1, sizeof (buf), file); - (void) fwrite (buf, size, 1, stdout); + if (ferror (file)) { + fprintf (stderr, "Error: Read failed from %s\n", filename); + fclose (file); + return 1; + } + + if (fwrite (buf, size, 1, stdout) != 1) { + fprintf (stderr, "Error: Write failed\n"); + fclose (file); + return 1; + } } fclose (file); @@ -921,6 +1016,14 @@ do_show (void *ctx, return 0; } +enum { + NOTMUCH_FORMAT_NOT_SPECIFIED, + NOTMUCH_FORMAT_JSON, + NOTMUCH_FORMAT_TEXT, + NOTMUCH_FORMAT_MBOX, + NOTMUCH_FORMAT_RAW +}; + int notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) { @@ -928,85 +1031,94 @@ 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; + notmuch_show_params_t params = { .part = -1 }; + int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED; + notmuch_bool_t verify = FALSE; - params.entire_thread = 0; - params.raw = 0; - params.part = -1; - params.cryptoctx = NULL; - params.decrypt = 0; + 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_INT, ¶ms.part, "part", 'p', 0 }, + { NOTMUCH_OPT_BOOLEAN, ¶ms.entire_thread, "entire-thread", 't', 0 }, + { NOTMUCH_OPT_BOOLEAN, ¶ms.decrypt, "decrypt", 'd', 0 }, + { NOTMUCH_OPT_BOOLEAN, &verify, "verify", 'v', 0 }, + { 0, 0, 0, 0, 0 } + }; - argc--; argv++; /* skip subcommand argument */ + opt_index = parse_arguments (argc, argv, options, 1); + if (opt_index < 0) { + /* diagnostics already printed */ + return 1; + } - for (i = 0; i < argc && argv[i][0] == '-'; i++) { - if (strcmp (argv[i], "--") == 0) { - i++; - break; - } - 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; - } else { - fprintf (stderr, "Unrecognized option: %s\n", argv[i]); + 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; + } + + switch (format_sel) { + case NOTMUCH_FORMAT_JSON: + format = &format_json; + params.entire_thread = TRUE; + 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; } + 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; } - argc -= i; - argv += i; + if (params.decrypt || verify) { +#ifdef GMIME_ATLEAST_26 + /* TODO: GMimePasswordRequestFunc */ + params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg"); +#else + GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL); + params.cryptoctx = g_mime_gpg_context_new (session, "gpg"); +#endif + if (params.cryptoctx) { + g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE); + } else { + params.decrypt = FALSE; + fprintf (stderr, "Failed to construct gpg context.\n"); + } +#ifndef GMIME_ATLEAST_26 + g_object_unref (session); +#endif + } 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; @@ -1023,19 +1135,10 @@ 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; - if (params.part >= 0) - return do_show_single (ctx, query, format, ¶ms); + ret = do_show_single (ctx, query, format, ¶ms); else - return do_show (ctx, query, format, ¶ms); + ret = do_show (ctx, query, format, ¶ms); notmuch_query_destroy (query); notmuch_database_close (notmuch); @@ -1043,5 +1146,5 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) if (params.cryptoctx) g_object_unref(params.cryptoctx); - return 0; + return ret; } diff --git a/notmuch-tag.c b/notmuch-tag.c index 292c5da3..36b9b092 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; } @@ -106,7 +111,7 @@ _optimize_tag_query (void *ctx, const char *orig_query_string, char *argv[], } 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; diff --git a/notmuch.1 b/notmuch.1 deleted file mode 100644 index 7ab2947d..00000000 --- a/notmuch.1 +++ /dev/null @@ -1,776 +0,0 @@ -.\" notmuch - Not much of an email program, (just index, search and tagging) -.\" -.\" Copyright © 2009 Carl Worth -.\" -.\" 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 this program. If not, see http://www.gnu.org/licenses/ . -.\" -.\" Author: Carl Worth <cworth@cworth.org> -.TH NOTMUCH 1 2012-02-03 "Notmuch 0.11.1" -.SH NAME -notmuch \- thread-based email index, search, and tagging -.SH SYNOPSIS -.B notmuch -.IR command " [" args " ...]" -.SH DESCRIPTION -Notmuch is a command-line based program for indexing, searching, -reading, and tagging large collections of email messages. - -The quickest way to get started with Notmuch is to simply invoke the -.B notmuch -command with no arguments, which will interactively guide you through -the process of indexing your mail. -.SH NOTE -While the command-line program -.B notmuch -provides powerful functionality, it does not provide the most -convenient interface for that functionality. More sophisticated -interfaces are expected to be built on top of either the command-line -interface, or more likely, on top of the notmuch library -interface. See http://notmuchmail.org for more about alternate -interfaces to notmuch. -.SH COMMANDS -The -.BR setup -command is used to configure Notmuch for first use, (or to reconfigure -it later). -.RS 4 -.TP 4 -.B setup - -Interactively sets up notmuch for first use. - -The setup command will prompt for your full name, your primary email -address, any alternate email addresses you use, and the directory -containing your email archives. Your answers will be written to a -configuration file in ${NOTMUCH_CONFIG} (if set) or -${HOME}/.notmuch-config . This configuration file will be created with -descriptive comments, making it easy to edit by hand later to change the -configuration. Or you can run -.B "notmuch setup" -again to change the configuration. - -The mail directory you specify can contain any number of -sub-directories and should primarily contain only files with individual -email messages (eg. maildir or mh archives are perfect). If there are -other, non-email files (such as indexes maintained by other email -programs) then notmuch will do its best to detect those and ignore -them. - -Mail storage that uses mbox format, (where one mbox file contains many -messages), will not work with notmuch. If that's how your mail is -currently stored, it is recommended you first convert it to maildir -format with a utility such as mb2md before running -.B "notmuch setup" . - -Invoking -.B notmuch -with no command argument will run -.B setup -if the setup command has not previously been completed. -.RE - -The -.B new -command is used to incorporate new mail into the notmuch database. -.RS 4 -.TP 4 -.BR new " [options...]" - -Find and import any new messages to the database. - -The -.B new -command scans all sub-directories of the database, performing -full-text indexing on new messages that are found. Each new message -will automatically be tagged with both the -.BR inbox " and " unread -tags. - -You should run -.B "notmuch new" -once after first running -.B "notmuch setup" -to create the initial database. The first run may take a long time if -you have a significant amount of mail (several hundred thousand -messages or more). Subsequently, you should run -.B "notmuch new" -whenever new mail is delivered and you wish to incorporate it into the -database. These subsequent runs will be much quicker than the initial -run. - -Invoking -.B notmuch -with no command argument will run -.B new -if -.B "notmuch setup" -has previously been completed, but -.B "notmuch new" -has not previously been run. - -The -.B new -command supports hooks. See the -.B "HOOKS" -section below for more details on hooks. - -Supported options for -.B new -include -.RS 4 -.TP 4 -.BR \-\-no\-hooks - -Prevents hooks from being run. -.RE -.RE - -Several of the notmuch commands accept search terms with a common -syntax. See the -.B "SEARCH SYNTAX" -section below for more details on the supported syntax. - -The -.BR search ", " show " and " count -commands are used to query the email database. -.RS 4 -.TP 4 -.BR search " [options...] <search-term>..." - -Search for messages matching the given search terms, and display as -results the threads containing the matched messages. - -The output consists of one line per thread, giving a thread ID, the -date of the newest (or oldest, depending on the sort option) matched -message in the thread, the number of matched messages and total -messages in the thread, the names of all participants in the thread, -and the subject of the newest (or oldest) message. - -Supported options for -.B search -include -.RS 4 -.TP 4 -.BR \-\-format= ( json | text ) - -Presents the results in either JSON or plain-text (default). -.RE - -.RS 4 -.TP 4 -.B \-\-output=(summary|threads|messages|files|tags) - -.RS 4 -.TP 4 -.B summary - -Output a summary of each thread with any message matching the search -terms. The summary includes the thread ID, date, the number of -messages in the thread (both the number matched and the total number), -the authors of the thread and the subject. -.RE -.RS 4 -.TP 4 -.B threads - -Output the thread IDs of all threads with any message matching the -search terms, either one per line (\-\-format=text) or as a JSON array -(\-\-format=json). -.RE -.RS 4 -.TP 4 -.B messages - -Output the message IDs of all messages matching the search terms, -either one per line (\-\-format=text) or as a JSON array -(\-\-format=json). -.RE -.RS 4 -.TP 4 -.B files - -Output the filenames of all messages matching the search terms, either -one per line (\-\-format=text) or as a JSON array (\-\-format=json). -.RE -.RS 4 -.TP 4 -.B tags - -Output all tags that appear on any message matching the search terms, -either one per line (\-\-format=text) or as a JSON array -(\-\-format=json). -.RE -.RE - -.RS 4 -.TP 4 -.BR \-\-sort= ( newest\-first | oldest\-first ) - -This option can be used to present results in either chronological order -.RB ( oldest\-first ) -or reverse chronological order -.RB ( newest\-first ). - -Note: The thread order will be distinct between these two options -(beyond being simply reversed). When sorting by -.B oldest\-first -the threads will be sorted by the oldest message in each thread, but -when sorting by -.B newest\-first -the threads will be sorted by the newest message in each thread. - -By default, results will be displayed in reverse chronological order, -(that is, the newest results will be displayed first). -.RE - -.RS 4 -.TP 4 -.BR \-\-offset=[\-]N - -Skip displaying the first N results. With the leading '\-', start at the Nth -result from the end. -.RE - -.RS 4 -.TP 4 -.BR \-\-limit=N - -Limit the number of displayed results to N. -.RE - -.RS 4 -See the -.B "SEARCH SYNTAX" -section below for details of the supported syntax for <search-terms>. -.RE -.TP -.BR show " [options...] <search-term>..." - -Shows all messages matching the search terms. - -The messages will be grouped and sorted based on the threading (all -replies to a particular message will appear immediately after that -message in date order). The output is not indented by default, but -depth tags are printed so that proper indentation can be performed by -a post-processor (such as the emacs interface to notmuch). - -Supported options for -.B show -include -.RS 4 -.TP 4 -.B \-\-entire\-thread - -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. -.RE - -.RS 4 -.TP 4 -.B \-\-format=(text|json|mbox|raw) - -.RS 4 -.TP 4 -.BR text " (default for messages)" - -The default plain-text format has all text-content MIME parts -decoded. Various components in the output, -.RB ( message ", " header ", " body ", " attachment ", and MIME " part ), -will be delimited by easily-parsed markers. Each marker consists of a -Control-L character (ASCII decimal 12), the name of the marker, and -then either an opening or closing brace, ('{' or '}'), to either open -or close the component. For a multipart MIME message, these parts will -be nested. -.RE -.RS 4 -.TP 4 -.B json - -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 -.B \-\-format=json -implies -.B \-\-entire\-thread - -.RE -.RS 4 -.TP 4 -.B mbox - -All matching messages are output in the traditional, Unix mbox format -with each message being prefixed by a line beginning with "From " and -a blank line separating each message. Lines in the message content -beginning with "From " (preceded by zero or more '>' characters) have -an additional '>' character added. This reversible escaping -is termed "mboxrd" format and described in detail here: - -.nf -.nh -http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/mail-mbox-formats.html -.hy -.fi -. -.RE -.RS 4 -.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 single part (\-\-part) the raw part content is output after -performing any necessary MIME decoding. - -The raw format must only be used with search terms matching single -message. -.RE -.RE - -.RS 4 -.TP 4 -.B \-\-part=N - -Output the single decoded MIME part N of a single message. The search -terms must match only a single message. Message parts are numbered in -a depth-first walk of the message MIME structure, and are identified -in the 'json' or 'text' output formats. -.RE - -.RS 4 -.TP 4 -.B \-\-verify - -Compute and report the validity of any MIME cryptographic signatures -found in the selected content (ie. "multipart/signed" parts). Status -of the signature will be reported (currently only supported with ---format=json), and the multipart/signed part will be replaced by the -signed data. -.RE - -.RS 4 -.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 - -A common use of -.B notmuch show -is to display a single thread of email messages. For this, use a -search term of "thread:<thread-id>" as can be seen in the first -column of output from the -.B notmuch search -command. - -See the -.B "SEARCH SYNTAX" -section below for details of the supported syntax for <search-terms>. -.RE -.RS 4 -.TP 4 -.BR count " [options...] <search-term>..." - -Count messages matching the search terms. - -The number of matching messages (or threads) is output to stdout. - -With no search terms, a count of all messages (or threads) in the database will -be displayed. - -Supported options for -.B count -include -.RS 4 -.TP 4 -.B \-\-output=(messages|threads) - -.RS 4 -.TP 4 -.B messages - -Output the number of matching messages. This is the default. -.RE -.RS 4 -.TP 4 -.B threads - -Output the number of matching threads. -.RE -.RE -.RE -.RE - -The -.B reply -command is useful for preparing a template for an email reply. -.RS 4 -.TP 4 -.BR reply " [options...] <search-term>..." - -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 - -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 -replied to to the References list and setting the In\-Reply\-To: field -correctly. - -Finally, the original contents of the emails are quoted by prefixing -each line with '> ' and included in the body. - -The resulting message template is output to stdout. - -Supported options for -.B reply -include -.RS -.TP 4 -.BR \-\-format= ( default | headers\-only ) -.RS -.TP 4 -.BR default -Includes subject and quoted message body. -.TP -.BR headers\-only -Only produces In\-Reply\-To, References, To, Cc, and Bcc headers. -.RE - -See the -.B "SEARCH SYNTAX" -section below for details of the supported syntax for <search-terms>. - -Note: It is most common to use -.B "notmuch reply" -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. -.RE -.RE - -The -.B tag -command is the only command available for manipulating database -contents. - -.RS 4 -.TP 4 -.BR tag " +<tag>|\-<tag> [...] [\-\-] <search-term>..." - -Add/remove tags for all messages matching the search terms. - -Tags prefixed by '+' are added while those prefixed by '\-' are -removed. For each message, tag removal is performed before tag -addition. - -The beginning of <search-terms> is recognized by the first -argument that begins with neither '+' nor '\-'. Support for -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. - -See the -.B "SEARCH SYNTAX" -section below for details of the supported syntax for <search-terms>. -.RE - -The -.BR dump " and " restore -commands can be used to create a textual dump of email tags for backup -purposes, and to restore from that dump. - -.RS 4 -.TP 4 -.BR dump " [<filename>] [--] [<search-terms>]" - -Creates a plain-text dump of the tags of each message. - -Output is to the given filename, if any, or to stdout. Note that -using the filename argument is deprecated. - -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 -therefore the only critical thing to backup (and much more friendly to -incremental backup than the native database files.) - -With no search terms, a dump of all messages in the database will be -generated. A "--" argument instructs notmuch that the -remaining arguments are search terms. - -See the -.B "SEARCH SYNTAX" -section below for details of the supported syntax for <search-terms>. -.RE - -.TP -.BR restore " [--accumulate] [<filename>]" - -Restores the tags from the given file (see -.BR "notmuch dump" ")." - -The input is read from the given filename, if any, or from stdin. - -Note: The dump file format is specifically chosen to be -compatible with the format of files produced by sup-dump. -So if you've previously been using sup for mail, then the -.B "notmuch restore" -command provides you a way to import all of your tags (or labels as -sup calls them). - -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. -.RE - -The -.B part -command can used to output a single part of a multipart MIME message. - -.RS 4 -.TP 4 -.BR part " \-\-part=<part-number> <search-term>..." - -Output a single MIME part of a message. - -A single decoded MIME part, with no encoding or framing, is output to -stdout. The search terms must match only a single message, otherwise -this command will fail. - -The part number should match the part "id" field output by the -"\-\-format=json" option of "notmuch show". If the message specified by -the search terms does not include a part with the specified "id" there -will be no output. - -See the -.B "SEARCH SYNTAX" -section below for details of the supported syntax for <search-terms>. -.RE - -The -.B config -command can be used to get or set settings int the notmuch -configuration file. - -.RS 4 -.TP 4 -.BR "config get " <section> . <item> - -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. - -Available configuration items include at least - - database.path - - user.name - - user.primary_email - - user.other_email - - new.tags -.RE - -.RS 4 -.TP 4 -.BR "config set " <section> . "<item> [values ...]" - -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. - -If no values are provided, the specified configuration item will be -removed from the configuration file. -.RE - -.SH SEARCH SYNTAX -Several notmuch commands accept a common syntax for search terms. - -The search terms can consist of free-form text (and quoted phrases) -which will match all messages that contain all of the given -terms/phrases in the body, the subject, or any of the sender or -recipient headers. - -As a special case, a search string consisting of exactly a single -asterisk ("*") will match all messages. - -In addition to free text, the following prefixes can be used to force -terms to match against specific portions of an email, (where -<brackets> indicate user-supplied values): - - from:<name-or-address> - - to:<name-or-address> - - subject:<word-or-quoted-phrase> - - attachment:<word> - - tag:<tag> (or is:<tag>) - - id:<message-id> - - thread:<thread-id> - - folder:<directory-path> - -The -.B from: -prefix is used to match the name or address of the sender of an email -message. - -The -.B to: -prefix is used to match the names or addresses of any recipient of an -email message, (whether To, Cc, or Bcc). - -Any term prefixed with -.B subject: -will match only text from the subject of an email. Searching for a -phrase in the subject is supported by including quotation marks around -the phrase, immediately following -.BR subject: . - -The -.B attachment: -prefix can be used to search for specific filenames (or extensions) of -attachments to email messages. - -For -.BR tag: " and " is: -valid tag values include -.BR inbox " and " unread -by default for new messages added by -.B notmuch new -as well as any other tag values added manually with -.BR "notmuch tag" . - -For -.BR id: , -message ID values are the literal contents of the Message\-ID: header -of email messages, but without the '<', '>' delimiters. - -The -.B thread: -prefix can be used with the thread ID values that are generated -internally by notmuch (and do not appear in email messages). These -thread ID values can be seen in the first column of output from -.B "notmuch search" - -The -.B folder: -prefix can be used to search for email message files that are -contained within particular directories within the mail store. Only -the directory components below the top-level mail database path are -available to be searched. - -In addition to individual terms, multiple terms can be -combined with Boolean operators ( -.BR and ", " or ", " not -, etc.). Each term in the query will be implicitly connected by a -logical AND if no explicit operator is provided, (except that terms -with a common prefix will be implicitly combined with OR until we get -Xapian defect #402 fixed). - -Parentheses can also be used to control the combination of the Boolean -operators, but will have to be protected from interpretation by the -shell, (such as by putting quotation marks around any parenthesized -expression). - -Finally, results can be restricted to only messages within a -particular time range, (based on the Date: header) with a syntax of: - - <initial-timestamp>..<final-timestamp> - -Each timestamp is a number representing the number of seconds since -1970\-01\-01 00:00:00 UTC. This is not the most convenient means of -expressing date ranges, but until notmuch is fixed to accept a more -convenient form, one can use the date program to construct -timestamps. For example, with the bash shell the following syntax would -specify a date range to return messages from 2009\-10\-01 until the -current time: - - $(date +%s \-d 2009\-10\-01)..$(date +%s) -.SH HOOKS -Hooks are scripts (or arbitrary executables or symlinks to such) that notmuch -invokes before and after certain actions. These scripts reside in -the .notmuch/hooks directory within the database directory and must have -executable permissions. - -The currently available hooks are described below. -.RS 4 -.TP 4 -.B pre\-new -This hook is invoked by the -.B new -command before scanning or importing new messages into the database. If this -hook exits with a non-zero status, notmuch will abort further processing of the -.B new -command. - -Typically this hook is used for fetching or delivering new mail to be imported -into the database. -.RE -.RS 4 -.TP 4 -.B post\-new -This hook is invoked by the -.B new -command after new messages have been imported into the database and initial tags -have been applied. The hook will not be run if there have been any errors during -the scan or import. - -Typically this hook is used to perform additional query\-based tagging on the -imported messages. -.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 -The emacs-based interface to notmuch (available as -.B notmuch.el -in the Notmuch distribution). - -The notmuch website: -.B http://notmuchmail.org -.SH CONTACT -Feel free to send questions, comments, or kudos to the notmuch mailing -list <notmuch@notmuchmail.org> . Subscription is not required before -posting, but is available from the notmuchmail.org website. - -Real-time interaction with the Notmuch community is available via IRC -(server: irc.freenode.net, channel: #notmuch). @@ -29,7 +29,6 @@ typedef struct command { command_function_t function; const char *arguments; const char *summary; - const char *documentation; } command_t; #define MAX_ALIAS_SUBSTITUTIONS 3 @@ -47,447 +46,40 @@ alias_t aliases[] = { static int notmuch_help_command (void *ctx, int argc, char *argv[]); -static const char search_terms_help[] = - "\tSeveral notmuch commands accept a common syntax for search\n" - "\tterms.\n" - "\n" - "\tThe search terms can consist of free-form text (and quoted\n" - "\tphrases) which will match all messages that contain all of\n" - "\tthe given terms/phrases in the body, the subject, or any of\n" - "\tthe sender or recipient headers.\n" - "\n" - "\tAs a special case, a search string consisting of exactly a\n" - "\tsingle asterisk (\"*\") will match all messages.\n" - "\n" - "\tIn addition to free text, the following prefixes can be used\n" - "\tto force terms to match against specific portions of an email,\n" - "\t(where <brackets> indicate user-supplied values):\n" - "\n" - "\t\tfrom:<name-or-address>\n" - "\t\tto:<name-or-address>\n" - "\t\tsubject:<word-or-quoted-phrase>\n" - "\t\tattachment:<word>\n" - "\t\ttag:<tag> (or is:<tag>)\n" - "\t\tid:<message-id>\n" - "\t\tthread:<thread-id>\n" - "\t\tfolder:<directory-path>\n" - "\n" - "\tThe from: prefix is used to match the name or address of\n" - "\tthe sender of an email message.\n" - "\n" - "\tThe to: prefix is used to match the names or addresses of\n" - "\tany recipient of an email message, (whether To, Cc, or Bcc).\n" - "\n" - "\tAny term prefixed with subject: will match only text from\n" - "\tthe subject of an email. Quoted phrases are supported when\n" - "\tsearching with: subject:\"this is a phrase\".\n" - "\n" - "\tFor tag: and is:, valid tag values include \"inbox\" and \"unread\"\n" - "\tby default for new messages added by \"notmuch new\" as well\n" - "\tas any other tag values added manually with \"notmuch tag\".\n" - "\n" - "\tFor id:, message ID values are the literal contents of the\n" - "\tMessage-ID: header of email messages, but without the '<','>'\n" - "\tdelimiters.\n" - "\n" - "\tThe thread: prefix can be used with the thread ID values that\n" - "\tare generated internally by notmuch (and do not appear in email\n" - "\tmessages). These thread ID values can be seen in the first\n" - "\tcolumn of output from \"notmuch search\".\n" - "\n" - "\tThe folder: prefix can be used to search for email message\n" - "\tfiles that are contained within particular directories within\n" - "\tthe mail store. Only the directory components below the top-level\n" - "\tmail database path are available to be searched.\n" - "\n" - "\tIn addition to individual terms, multiple terms can be\n" - "\tcombined with Boolean operators (\"and\", \"or\", \"not\", etc.).\n" - "\tEach term in the query will be implicitly connected by a\n" - "\tlogical AND if no explicit operator is provided, (except\n" - "\tthat terms with a common prefix will be implicitly combined\n" - "\twith OR until we get Xapian defect #402 fixed).\n" - "\n" - "\tParentheses can also be used to control the combination of\n" - "\tthe Boolean operators, but will have to be protected from\n" - "\tinterpretation by the shell, (such as by putting quotation\n" - "\tmarks around any parenthesized expression).\n" - "\n" - "\tFinally, results can be restricted to only messages within a\n" - "\tparticular time range, (based on the Date: header) with:\n" - "\n" - "\t\t<intial-timestamp>..<final-timestamp>\n" - "\n" - "\tEach timestamp is a number representing the number of seconds\n" - "\tsince 1970-01-01 00:00:00 UTC. This is not the most convenient\n" - "\tmeans of expressing date ranges, but until notmuch is fixed to\n" - "\taccept a more convenient form, one can use the date program to\n" - "\tconstruct timestamps. For example, with the bash shell the\n" - "\tfollowing syntax would specify a date range to return messages\n" - "\tfrom 2009-10-01 until the current time:\n" - "\n" - "\t\t$(date +%%s -d 2009-10-01)..$(date +%%s)\n\n"; - -static const char hooks_help[] = - "\tHooks are scripts (or arbitrary executables or symlinks to such) that\n" - "\tnotmuch invokes before and after certain actions. These scripts reside\n" - "\tin the .notmuch/hooks directory within the database directory and must\n" - "\thave executable permissions.\n" - "\n" - "\tThe currently available hooks are described below.\n" - "\n" - "\tpre-new\n" - "\t\tThis hook is invoked by the new command before scanning or\n" - "\t\timporting new messages into the database. If this hook exits\n" - "\t\twith a non-zero status, notmuch will abort further processing\n" - "\t\tof the new command.\n" - "\n" - "\t\tTypically this hook is used for fetching or delivering new\n" - "\t\tmail to be imported into the database.\n" - "\n" - "\tpost-new\n" - "\t\tThis hook is invoked by the new command after new messages\n" - "\t\thave been imported into the database and initial tags have\n" - "\t\tbeen applied. The hook will not be run if there have been any\n" - "\t\terrors during the scan or import.\n" - "\n" - "\t\tTypically this hook is used to perform additional query-based\n" - "\t\ttagging on the imported messages.\n\n"; - static command_t commands[] = { { "setup", notmuch_setup_command, NULL, - "Interactively setup notmuch for first use.", - "\tThe setup command will prompt for your full name, your primary\n" - "\temail address, any alternate email addresses you use, and the\n" - "\tdirectory containing your email archives. Your answers will be\n" - "\twritten to a configuration file in ${NOTMUCH_CONFIG} (if set)\n" - "\tor ${HOME}/.notmuch-config.\n" - "\n" - "\tThis configuration file will be created with descriptive\n" - "\tcomments, making it easy to edit by hand later to change the\n" - "\tconfiguration. Or you can run \"notmuch setup\" again.\n" - "\n" - "\tInvoking notmuch with no command argument will run setup if\n" - "\tthe setup command has not previously been completed." }, + "Interactively setup notmuch for first use." }, { "new", notmuch_new_command, "[options...]", - "Find and import new messages to the notmuch database.", - "\tScans all sub-directories of the mail directory, performing\n" - "\tfull-text indexing on new messages that are found. Each new\n" - "\tmessage will be tagged as both \"inbox\" and \"unread\".\n" - "\n" - "\tYou should run \"notmuch new\" once after first running\n" - "\t\"notmuch setup\" to create the initial database. The first\n" - "\trun may take a long time if you have a significant amount of\n" - "\tmail (several hundred thousand messages or more).\n" - "\n" - "\tSubsequently, you should run \"notmuch new\" whenever new mail\n" - "\tis delivered and you wish to incorporate it into the database.\n" - "\tThese subsequent runs will be much quicker than the initial run.\n" - "\n" - "\tThe new command supports hooks. See \"notmuch help hooks\" for\n" - "\tmore details on hooks.\n" - "\n" - "\tSupported options for new include:\n" - "\n" - "\t--no-hooks\n" - "\n" - "\t\tPrevent hooks from being run.\n" - "\n" - "\t--verbose\n" - "\n" - "\t\tVerbose operation. Shows paths of message files as\n" - "\t\tthey are being indexed.\n" - "\n" - "\tInvoking notmuch with no command argument will run new if\n" - "\tthe setup command has previously been completed, but new has\n" - "\tnot previously been run." }, + "Find and import new messages to the notmuch database." }, { "search", notmuch_search_command, "[options...] <search-terms> [...]", - "Search for messages matching the given search terms.", - "\tNote that the individual mail messages will be matched\n" - "\tagainst the search terms, but the results will be the\n" - "\tthreads (one per line) containing the matched messages.\n" - "\n" - "\tSupported options for search include:\n" - "\n" - "\t--format=(json|text)\n" - "\n" - "\t\tPresents the results in either JSON or\n" - "\t\tplain-text (default)\n" - "\n" - "\t--output=(summary|threads|messages|files|tags)\n" - "\n" - "\t\tsummary (default)\n" - "\n" - "\t\tOutput a summary of each thread with any message matching the\n" - "\t\tsearch terms. The summary includes the thread ID, date, the\n" - "\t\tnumber of messages in the thread (both the number matched and\n" - "\t\tthe total number), the authors of the thread and the subject.\n" - "\n" - "\t\tthreads\n" - "\n" - "\t\tOutput the thread IDs of all threads with any message matching\n" - "\t\tthe search terms, either one per line (--format=text) or as a\n" - "\t\tJSON array (--format=json).\n" - "\n" - "\t\tmessages\n" - "\n" - "\t\tOutput the message IDs of all messages matching the search\n" - "\t\tterms, either one per line (--format=text) or as a JSON array\n" - "\t\t(--format=json).\n" - "\n" - "\t\tfiles\n" - "\n" - "\t\tOutput the filenames of all messages matching the search\n" - "\t\tterms, either one per line (--format=text) or as a JSON array\n" - "\t\t(--format=json).\n" - "\n" - "\t\ttags\n" - "\n" - "\t\tOutput all tags that appear on any message matching the search\n" - "\t\tterms, either one per line (--format=text) or as a JSON array\n" - "\t\t(--format=json).\n" - "\n" - "\t--sort=(newest-first|oldest-first)\n" - "\n" - "\t\tPresent results in either chronological order\n" - "\t\t(oldest-first) or reverse chronological order\n" - "\t\t(newest-first), which is the default.\n" - "\n" - "\t--offset=[-]N\n" - "\n" - "\t\tSkip displaying the first N results. With the leading '-',\n" - "\t\tstart at the Nth result from the end.\n" - "\n" - "\t--limit=N\n" - "\n" - "\t\tLimit the number of displayed results to N.\n" - "\n" - "\tSee \"notmuch help search-terms\" for details of the search\n" - "\tterms syntax." }, + "Search for messages matching the given search terms." }, { "show", notmuch_show_command, "<search-terms> [...]", - "Show all messages matching the search terms.", - "\tThe messages are grouped and sorted based on the threading\n" - "\t(all replies to a particular message appear immediately\n" - "\tafter that message in date order).\n" - "\n" - "\tSupported options for show include:\n" - "\n" - "\t--entire-thread\n" - "\n" - "\t\tBy default only those messages that match the\n" - "\t\tsearch terms will be displayed. With this option,\n" - "\t\tall messages in the same thread as any matched\n" - "\t\tmessage will be displayed.\n" - "\n" - "\t--format=(text|json|mbox|raw)\n" - "\n" - "\t\ttext (default for messages)\n" - "\n" - "\t\tThe default plain-text format has all text-content MIME parts\n" - "\t\tdecoded. Various components in the output, ('message', 'header',\n" - "\t\t'body', 'attachment', and MIME 'part') are delimited by\n" - "\t\teasily-parsed markers. Each marker consists of a Control-L\n" - "\t\tcharacter (ASCII decimal 12), the name of the marker, and\n" - "\t\tthen either an opening or closing brace, '{' or '}' to\n" - "\t\teither open or close the component. For a multipart MIME\n" - "\t\tmessage, these parts will be nested.\n" - "\n" - "\t\tjson\n" - "\n" - "\t\tThe output is formatted with Javascript Object Notation\n" - "\t\t(JSON). This format is more robust than the text format\n" - "\t\tfor automated processing. The nested structure of multipart\n" - "\t\tMIME messages is reflected in nested JSON output. JSON\n" - "\t\toutput always includes all messages in a matching thread;\n" - "\t\tin effect '--format=json' implies '--entire-thread'\n" - "\n" - "\t\tmbox\n" - "\n" - "\t\tAll matching messages are output in the traditional, Unix\n" - "\t\tmbox format with each message being prefixed by a line\n" - "\t\tbeginning with 'From ' and a blank line separating each\n" - "\t\tmessage. Lines in the message content beginning with 'From '\n" - "\t\t(preceded by zero or more '>' characters) have an additional\n" - "\t\t'>' character added. This reversible escaping is termed\n" - "\t\t\"mboxrd\" format and described in detail here:\n" - "\n" - "\t\thttp://homepage.ntlworld.com/jonathan.deboynepollard/FGA/mail-mbox-formats.html\n" - "\n" - "\t\traw (default for a single part, see --part)\n" - "\n" - "\t\tFor a message, the original, raw content of the email\n" - "\t\tmessage is output. Consumers of this format should\n" - "\t\texpect to implement MIME decoding and similar functions.\n" - "\n" - "\t\tFor a single part (--part) the raw part content is output\n" - "\t\tafter performing any necessary MIME decoding.\n" - "\n" - "\t\tThe raw format must only be used with search terms matching\n" - "\t\tsingle message.\n" - "\n" - "\t--part=N\n" - "\n" - "\t\tOutput the single decoded MIME part N of a single message.\n" - "\t\tThe search terms must match only a single message.\n" - "\t\tMessage parts are numbered in a depth-first walk of the\n" - "\t\tmessage MIME structure, and are identified in the 'json' or\n" - "\t\t'text' output formats.\n" - "\n" - "\t--verify\n" - "\n" - "\t\tCompute and report the validity of any MIME cryptographic\n" - "\t\tsignatures found in the selected content (ie.\n" - "\t\t\"multipart/signed\" parts). Status of the signature will be\n" - "\t\treported (currently only supported with --format=json) and\n" - "\t\tthe multipart/signed part will be replaced by the signed data.\n" - "\n" - "\t--decrypt\n" - "\n" - "\t\tDecrypt any MIME encrypted parts found in the selected content\n" - "\t\t(ie. \"multipart/encrypted\" parts). Status of the decryption\n" - "\t\twill be reported (currently only supported with --format=json)\n" - "\t\tand the multipart/encrypted part will be replaced by the\n" - "\t\tdecrypted content.\n" - "\n" - "\n" - "\tA common use of \"notmuch show\" is to display a single\n" - "\tthread of email messages. For this, use a search term of\n" - "\t\"thread:<thread-id>\" as can be seen in the first column\n" - "\tof output from the \"notmuch search\" command.\n" - "\n" - "\tSee \"notmuch help search-terms\" for details of the search\n" - "\tterms syntax." }, + "Show all messages matching the search terms." }, { "count", notmuch_count_command, "[options...] <search-terms> [...]", - "Count messages matching the search terms.", - "\tThe number of matching messages (or threads) is output to stdout.\n" - "\n" - "\tWith no search terms, a count of all messages (or threads) in\n" - "\tthe database will be displayed.\n" - "\n" - "\tSupported options for count include:\n" - "\n" - "\t--output=(messages|threads)\n" - "\n" - "\t\tmessages (default)\n" - "\n" - "\t\tOutput the number of matching messages.\n" - "\n" - "\t\tthreads\n" - "\n" - "\t\tOutput the number of matching threads.\n" - "\n" - "\tSee \"notmuch help search-terms\" for details of the search\n" - "\tterms syntax." }, + "Count messages matching the search terms." }, { "reply", notmuch_reply_command, "[options...] <search-terms> [...]", - "Construct a reply template for a set of messages.", - "\tConstructs a new message as a reply to a set of existing\n" - "\tmessages. The Reply-To: header (if any, otherwise From:) is\n" - "\tused for the To: address. The To: and Cc: headers are copied,\n" - "\tbut not including any of the user's configured addresses.\n" - "\n" - "\tA suitable subject is constructed. The In-Reply-to: and\n" - "\tReferences: headers are set appropriately, and the content\n" - "\tof the original messages is quoted and included in the body\n" - "\t(unless --format=headers-only is given).\n" - "\n" - "\tThe resulting message template is output to stdout.\n" - "\n" - "\tSupported options for reply include:\n" - "\n" - "\t--format=(default|headers-only)\n" - "\n" - "\t\tdefault:\n" - "\t\t\tIncludes subject and quoted message body.\n" - "\n" - "\t\theaders-only:\n" - "\t\t\tOnly produces In-Reply-To, References, To\n" - "\t\t\tCc, and Bcc headers.\n" - "\n" - "\tSee \"notmuch help search-terms\" for details of the search\n" - "\tterms syntax." }, + "Construct a reply template for a set of messages." }, { "tag", notmuch_tag_command, - "+<tag>|-<tag> [...] [--] <search-terms> [...]", - "Add/remove tags for all messages matching the search terms.", - "\tThe search terms are handled exactly as in 'search' so one\n" - "\tcan use that command first to see what will be modified.\n" - "\n" - "\tTags prefixed by '+' are added while those prefixed by\n" - "\t'-' are removed. For each message, tag removal is performed\n" - "\tbefore tag addition.\n" - "\n" - "\tThe beginning of <search-terms> is recognized by the first\n" - "\targument that begins with neither '+' nor '-'. Support for\n" - "\tan initial search term beginning with '+' or '-' is provided\n" - "\tby allowing the user to specify a \"--\" argument to separate\n" - "\tthe tags from the search terms.\n" - "\n" - "\tSee \"notmuch help search-terms\" for details of the search\n" - "\tterms syntax." }, + "+<tag>|-<tag> [...] [--] <search-terms> [...]" , + "Add/remove tags for all messages matching the search terms." }, { "dump", notmuch_dump_command, "[<filename>] [--] [<search-terms>]", - "Create a plain-text dump of the tags for each message.", - "\tOutput is to the given filename, if any, or to stdout.\n" - "\tNote that using the filename argument is deprecated.\n" - "\n" - "\tThese tags are the only data in the notmuch database\n" - "\tthat can't be recreated from the messages themselves.\n" - "\tThe output of notmuch dump is therefore the only\n" - "\tcritical thing to backup (and much more friendly to\n" - "\tincremental backup than the native database files.)\n" - "\n" - "\tWith no search terms, a dump of all messages in the\n" - "\tdatabase will be generated. A \"--\" argument instructs\n" - "\tnotmuch that the remaining arguments are search terms.\n" - "\n" - "\tSee \"notmuch help search-terms\" for the search-term syntax.\n" - }, + "Create a plain-text dump of the tags for each message." }, { "restore", notmuch_restore_command, "[--accumulate] [<filename>]", - "Restore the tags from the given dump file (see 'dump').", - "\tInput is read from the given filename, if any, or from stdin.\n" - "\tNote: The dump file format is specifically chosen to be\n" - "\tcompatible with the format of files produced by sup-dump.\n" - "\tSo if you've previously been using sup for mail, then the\n" - "\t\"notmuch restore\" command provides you a way to import\n" - "\tall of your tags (or labels as sup calls them).\n" - "\tThe --accumulate switch causes the union of the existing and new\n" - "\ttags to be applied, instead of replacing each message's tags as\n" - "\tthey are read in from the dump file."}, + "Restore the tags from the given dump file (see 'dump')." }, { "config", notmuch_config_command, "[get|set] <section>.<item> [value ...]", - "Get or set settings in the notmuch configuration file.", - " config get <section>.<item>\n" - "\n" - "\tThe value of the specified configuration item is printed\n" - "\tto stdout. If the item has multiple values, each value\n" - "\tis separated by a newline character.\n" - "\n" - "\tAvailable configuration items include at least\n" - "\n" - "\t\tdatabase.path\n" - "\t\tuser.name\n" - "\t\tuser.primary_email\n" - "\t\tuser.other_email\n" - "\t\tnew.tags\n" - "\n" - " config set <section>.<item> [value ...]\n" - "\n" - "\tThe specified configuration item is set to the given value.\n" - "\tTo specify a multiple-value item, provide each value as\n" - "\ta separate command-line argument.\n" - "\n" - "\tIf no values are provided, the specified configuration item\n" - "\twill be removed from the configuration file." }, + "Get or set settings in the notmuch configuration file." }, { "help", notmuch_help_command, "[<command>]", - "This message, or more detailed help for the named command.", - "\tExcept in this case, where there's not much more detailed\n" - "\thelp available." } + "This message, or more detailed help for the named command." } }; static void @@ -517,8 +109,17 @@ usage (FILE *out) "and \"notmuch help search-terms\" for the common search-terms syntax.\n\n"); } +static void +exec_man (const char *page) +{ + if (execlp ("man", "man", page, (char *) NULL)) { + perror ("exec man"); + exit (1); + } +} + static int -notmuch_help_command (unused (void *ctx), int argc, char *argv[]) +notmuch_help_command (void *ctx, int argc, char *argv[]) { command_t *command; unsigned int i; @@ -531,41 +132,28 @@ notmuch_help_command (unused (void *ctx), int argc, char *argv[]) return 0; } + if (strcmp (argv[0], "help") == 0) { + printf ("The notmuch help system.\n\n" + "\tNotmuch uses the man command to display help. In case\n" + "\tof difficulties check that MANPATH includes the pages\n" + "\tinstalled by notmuch.\n\n" + "\tTry \"notmuch help\" for a list of topics.\n"); + return 0; + } + for (i = 0; i < ARRAY_SIZE (commands); i++) { command = &commands[i]; if (strcmp (argv[0], command->name) == 0) { - printf ("Help for \"notmuch %s\":\n\n", argv[0]); - if (command->arguments) - printf ("%s %s\n\n\t%s\n\n%s\n\n", - command->name, command->arguments, - command->summary, command->documentation); - else - printf ("%s\t%s\n\n%s\n\n", command->name, - command->summary, command->documentation); - return 0; + char *page = talloc_asprintf (ctx, "notmuch-%s", command->name); + exec_man (page); } } if (strcmp (argv[0], "search-terms") == 0) { - printf ("Help for <%s>\n\n", argv[0]); - for (i = 0; i < ARRAY_SIZE (commands); i++) { - command = &commands[i]; - - if (command->arguments && - strstr (command->arguments, "search-terms")) - { - printf ("\t%s\t%s\n", - command->name, command->arguments); - } - } - printf ("\n"); - printf (search_terms_help); - return 0; + exec_man ("notmuch-search-terms"); } else if (strcmp (argv[0], "hooks") == 0) { - printf ("Help for <%s>\n\n", argv[0]); - printf (hooks_help); - return 0; + exec_man ("notmuch-hooks"); } fprintf (stderr, diff --git a/show-message.c b/show-message.c index d83f04ec..83ecf813 100644 --- a/show-message.c +++ b/show-message.c @@ -24,203 +24,83 @@ typedef struct show_message_state { int part_count; - int in_zone; } show_message_state_t; static void -show_message_part (GMimeObject *part, +show_message_part (mime_node_t *node, show_message_state_t *state, const notmuch_show_format_t *format, - notmuch_show_params_t *params, int first) { - GMimeObject *decryptedpart = NULL; - int selected; - state->part_count += 1; + /* Formatters expect the envelope for embedded message parts */ + GMimeObject *part = node->envelope_part ? + GMIME_OBJECT (node->envelope_part) : node->part; + int i; - if (! (GMIME_IS_PART (part) || GMIME_IS_MULTIPART (part) || GMIME_IS_MESSAGE_PART (part))) { - fprintf (stderr, "Warning: Not displaying unknown mime part: %s.\n", - g_type_name (G_OBJECT_TYPE (part))); - return; - } + if (!first) + fputs (format->part_sep, stdout); - selected = (params->part <= 0 || state->part_count == params->part); + /* Format this part */ + if (format->part_start) + format->part_start (part, &(state->part_count)); - if (selected || state->in_zone) { - if (!first && (params->part <= 0 || state->in_zone)) - fputs (format->part_sep, stdout); + if (node->decrypt_attempted && format->part_encstatus) + format->part_encstatus (node->decrypt_success); - if (format->part_start) - format->part_start (part, &(state->part_count)); - } + if (node->verify_attempted && format->part_sigstatus) +#ifdef GMIME_ATLEAST_26 + format->part_sigstatus (node->sig_list); +#else + format->part_sigstatus (node->sig_validity); +#endif - /* handle PGP/MIME parts */ - if (GMIME_IS_MULTIPART (part) && params->cryptoctx) { - GMimeMultipart *multipart = GMIME_MULTIPART (part); - GError* err = NULL; + format->part_content (part); - if (GMIME_IS_MULTIPART_ENCRYPTED (part) && params->decrypt) - { - if ( g_mime_multipart_get_count (multipart) != 2 ) { - /* this violates RFC 3156 section 4, so we won't bother with it. */ - fprintf (stderr, - "Error: %d part(s) for a multipart/encrypted message (should be exactly 2)\n", - g_mime_multipart_get_count (multipart)); - } else { - GMimeMultipartEncrypted *encrypteddata = GMIME_MULTIPART_ENCRYPTED (part); - decryptedpart = g_mime_multipart_encrypted_decrypt (encrypteddata, params->cryptoctx, &err); - if (decryptedpart) { - if ((selected || state->in_zone) && format->part_encstatus) - format->part_encstatus (1); - const GMimeSignatureValidity *sigvalidity = g_mime_multipart_encrypted_get_signature_validity (encrypteddata); - if (!sigvalidity) - fprintf (stderr, "Failed to verify signed part: %s\n", (err ? err->message : "no error explanation given")); - if ((selected || state->in_zone) && format->part_sigstatus) - format->part_sigstatus (sigvalidity); - } else { - fprintf (stderr, "Failed to decrypt part: %s\n", (err ? err->message : "no error explanation given")); - if ((selected || state->in_zone) && format->part_encstatus) - format->part_encstatus (0); - } - } - } - else if (GMIME_IS_MULTIPART_SIGNED (part)) - { - if ( g_mime_multipart_get_count (multipart) != 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 (should be exactly 2)\n", - g_mime_multipart_get_count (multipart)); - } else { - /* For some reason the GMimeSignatureValidity returned - * here is not a const (inconsistent with that - * returned by - * g_mime_multipart_encrypted_get_signature_validity, - * and therefore needs to be properly disposed of. - * Hopefully the API will become more consistent. */ - GMimeSignatureValidity *sigvalidity = g_mime_multipart_signed_verify (GMIME_MULTIPART_SIGNED (part), params->cryptoctx, &err); - if (!sigvalidity) { - fprintf (stderr, "Failed to verify signed part: %s\n", (err ? err->message : "no error explanation given")); - } - if ((selected || state->in_zone) && format->part_sigstatus) - format->part_sigstatus (sigvalidity); - if (sigvalidity) - g_mime_signature_validity_free (sigvalidity); - } - } + 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); - if (err) - g_error_free (err); + fputs (format->body_start, stdout); } - /* end handle PGP/MIME parts */ - - if (selected || state->in_zone) - format->part_content (part); - - if (GMIME_IS_MULTIPART (part)) { - GMimeMultipart *multipart = GMIME_MULTIPART (part); - int i; - - if (selected) - state->in_zone = 1; - - if (decryptedpart) { - /* We emit the useless application/pgp-encrypted version - * part here only to keep the emitted output as consistent - * as possible between decrypted output and the - * unprocessed multipart/mime. For some strange reason, - * the actual encrypted data is the second part of the - * multipart. */ - show_message_part (g_mime_multipart_get_part (multipart, 0), state, format, params, TRUE); - show_message_part (decryptedpart, state, format, params, FALSE); - } else { - for (i = 0; i < g_mime_multipart_get_count (multipart); i++) { - show_message_part (g_mime_multipart_get_part (multipart, i), - state, format, params, i == 0); - } - } - - if (selected) - state->in_zone = 0; - - } else if (GMIME_IS_MESSAGE_PART (part)) { - GMimeMessage *mime_message = g_mime_message_part_get_message (GMIME_MESSAGE_PART (part)); - - if (selected) - state->in_zone = 1; - - if (selected || (!selected && state->in_zone)) { - fputs (format->header_start, stdout); - if (format->header_message_part) - format->header_message_part (mime_message); - fputs (format->header_end, stdout); - - fputs (format->body_start, stdout); - } - show_message_part (g_mime_message_get_mime_part (mime_message), - state, format, params, TRUE); - - if (selected || (!selected && state->in_zone)) - fputs (format->body_end, 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); - if (selected) - state->in_zone = 0; - } + /* Finish this part */ + if (node->envelope_part) + fputs (format->body_end, stdout); - if (selected || state->in_zone) { - if (format->part_end) - format->part_end (part); - } + if (format->part_end) + format->part_end (part); } notmuch_status_t -show_message_body (const char *filename, +show_message_body (notmuch_message_t *message, const notmuch_show_format_t *format, notmuch_show_params_t *params) { - GMimeStream *stream = NULL; - GMimeParser *parser = NULL; - GMimeMessage *mime_message = NULL; - notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; - FILE *file = NULL; + notmuch_status_t ret; show_message_state_t state; + mime_node_t *root, *part; - state.part_count = 0; - state.in_zone = 0; - - file = fopen (filename, "r"); - if (! file) { - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno)); - ret = NOTMUCH_STATUS_FILE_ERROR; - goto DONE; - } - - stream = g_mime_stream_file_new (file); - g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream), FALSE); - - parser = g_mime_parser_new_with_stream (stream); - - mime_message = g_mime_parser_construct_message (parser); - - show_message_part (g_mime_message_get_mime_part (mime_message), - &state, - format, - params, - TRUE); - - DONE: - if (mime_message) - g_object_unref (mime_message); + ret = mime_node_open (NULL, message, params->cryptoctx, params->decrypt, + &root); + if (ret) + return ret; - if (parser) - g_object_unref (parser); + /* The caller of show_message_body has already handled the + * outermost envelope, so skip it. */ + state.part_count = MAX (params->part, 1); - if (stream) - g_object_unref (stream); + part = mime_node_seek_dfs (root, state.part_count); + if (part) + show_message_part (part, &state, format, TRUE); - if (file) - fclose (file); + talloc_free (root); - return ret; + return NOTMUCH_STATUS_SUCCESS; } diff --git a/test/Makefile.local b/test/Makefile.local index fa2df734..4a6a4b12 100644 --- a/test/Makefile.local +++ b/test/Makefile.local @@ -28,6 +28,7 @@ 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 diff --git a/test/README b/test/README index 7b2e96d4..43656a35 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 @@ -56,6 +69,13 @@ can be specified as follows: make test OPTIONS="--verbose" +You can choose an emacs binary to run the tests in one of the +following ways. + + TEST_EMACS=my-special-emacs make test + TEST_EMACS=my-special-emacs ./emacs + make test TEST_EMACS=my-special-emacs + Skipping Tests -------------- If, for any reason, you need to skip one or more tests, you can do so @@ -182,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/corpus/cur/52:2, b/test/corpus/cur/52:2, new file mode 100644 index 00000000..60283404 --- /dev/null +++ b/test/corpus/cur/52:2, @@ -0,0 +1,39 @@ +Message-ID: <4EFC743A.3060609@april.org> +Date: Thu, 29 Dec 2010 15:07:54 +0100 +From: "=?ISO-8859-1?Q?Fran=E7ois_Boulogne?=" <boulogne.f@gmail.com> +User-Agent: Mozilla/5.0 (X11; Linux i686; + rv:9.0) Gecko/20111224 Thunderbird/9.0.1 +MIME-Version: 1.0 +To: Allan McRae <allan@archlinux.org>, + "Discussion about the Arch User Repository (AUR)" <aur-general@archlinux.org> +References: <4EFC3931.6030007@april.org> <4EFC3D62.4030202@archlinux.org> +In-Reply-To: <4EFC3D62.4030202@archlinux.org> +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: 8bit +Subject: Re: [aur-general] Guidelines: cp, mkdir vs install + +Le 29/12/2011 11:13, Allan McRae a crit : +> On 29/12/11 19:56, Franois Boulogne wrote: +>> Hi, +>> +>> Looking to improve the quality of my packages, I read again the guidelines. +>> https://wiki.archlinux.org/index.php/Arch_Packaging_Standards +>> +>> However, it don't see anything about the install command like +>> install -d $pkgdir/usr/{bin,share/man/man1,share/locale} +>> +>> Some contributors on AUR use cp or mkdir to install files/dir (when no +>> makefile is provided) and others use install command. +>> +>> What's the opinion of TU on this point? +>> +> +> Use install with -m specifying the correct permissions +> + +Thank you Allan + + +-- +Franois Boulogne. +https://www.sciunto.org diff --git a/test/corpus/cur/53:2, b/test/corpus/cur/53:2, new file mode 100644 index 00000000..7a1e2e58 --- /dev/null +++ b/test/corpus/cur/53:2, @@ -0,0 +1,20 @@ +From: Olivier Berger <olivier.berger@it-sudparis.eu> +To: olivier.berger@it-sudparis.eu +Subject: Essai =?iso-8859-1?Q?accentu=E9?= +User-Agent: Notmuch/0.10.1 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu) +X-Draft-From: ("nnimap+localdovecot:INBOX" 44228) +Date: Fri, 16 Dec 2010 16:49:59 +0100 +Message-ID: <877h1wv7mg.fsf@inf-8657.int-evry.fr> +MIME-Version: 1.0 +Content-Type: text/plain; charset=iso-8859-1 +Content-Transfer-Encoding: quoted-printable + +Du texte accentu=E9 pour =E7a ... + +=E0 la bonne heure ! +--=20 +Olivier BERGER=20 +http://www-public.it-sudparis.eu/~berger_o/ - OpenPGP-Id: 2048R/5819D7E8 +Ingenieur Recherche - Dept INF +Institut TELECOM, SudParis (http://www.it-sudparis.eu/), Evry (France) + diff --git a/test/crypto b/test/crypto index 0af4aa8a..6723ef87 100755 --- a/test/crypto +++ b/test/crypto @@ -157,7 +157,7 @@ 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 @@ -78,10 +78,10 @@ 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 " From <test_suite@notmuchmail.org> (2001-01-05) (inbox) Subject: message-with-invalid-from To: Notmuch Test Suite <test_suite@notmuchmail.org> -Date: Tue, 05 Jan 2001 15:43:57 -0000 +Date: Fri, 05 Jan 2001 15:43:57 +0000 This is just a test message (#1) EOF @@ -101,26 +101,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,14 +128,14 @@ 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)" @@ -225,7 +225,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\") @@ -266,7 +266,7 @@ 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 --text follows this line-- On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote: > This is a test that messages are sent via SMTP @@ -288,7 +288,7 @@ Subject: Re: Quote MML tags in reply In-Reply-To: <test-emacs-mml-quoting@message.id> Fcc: ${MAIL_DIR}/sent --text follows this line-- -On Tue, 05 Jan 2001 15:43:57 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote: +On Fri, 05 Jan 2001 15:43:57 +0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote: > <#!part disposition=inline> EOF test_expect_equal_file OUTPUT EXPECTED @@ -340,7 +340,7 @@ add_message '[from]="Top Poster <top@poster.com>"' \ ----- Original Message ----- From: Notmuch Test Suite <test_suite@notmuchmail.org> To: Notmuch Test Suite <test_suite@notmuchmai.org> -Sent: Tue, 05 Jan 2001 15:43:57 -0000 +Sent: Fri, 05 Jan 2001 15:43:57 +0000 Subject: The problem with top-posting Q: Why is top-posting such a bad thing? @@ -351,7 +351,7 @@ test_emacs "(notmuch-show \"top-posting\") echo "Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox) Subject: The problem with top-posting To: Notmuch Test Suite <test_suite@notmuchmail.org> -Date: Tue, 05 Jan 2001 15:43:57 -0000 +Date: Fri, 05 Jan 2001 15:43:57 +0000 A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? @@ -360,7 +360,7 @@ Q: What is the most annoying thing in e-mail? Top Poster <top@poster.com> (2001-01-05) (inbox unread) Subject: Re: The problem with top-posting To: Notmuch Test Suite <test_suite@notmuchmail.org> -Date: Tue, 05 Jan 2001 15:43:57 -0000 +Date: Fri, 05 Jan 2001 15:43:57 +0000 Thanks for the advice! I will be sure to put it to good use. @@ -393,22 +393,25 @@ 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 @@ -420,16 +423,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" @@ -456,11 +462,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 00000000..6ddde5c6 --- /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 00000000..8423245f --- /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-large-search-buffer b/test/emacs-large-search-buffer index 6095e9da..4351e33e 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 00000000..5700d2e7 --- /dev/null +++ b/test/emacs-show @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +test_description="Testing 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_done diff --git a/test/emacs-subject-to-filename b/test/emacs-subject-to-filename new file mode 100755 index 00000000..176e6859 --- /dev/null +++ b/test/emacs-subject-to-filename @@ -0,0 +1,138 @@ +#!/usr/bin/env bash + +test_description="emacs: mail subject to filename" +. test-lib.sh + +# emacs server can't be started in a child process with $(test_emacs ...) +test_emacs '(ignore)' + +# test notmuch-wash-subject-to-patch-sequence-number (subject) +test_begin_subtest "no patch sequence number" +output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number + "[PATCH] A normal patch subject without numbers")' +) +test_expect_equal "$output" "" + +test_begin_subtest "patch sequence number #1" +output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number + "[PATCH 2/3] A most regular patch subject")' +) +test_expect_equal "$output" 2 + +test_begin_subtest "patch sequence number #2" +output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number + " [dummy list prefix] [RFC PATCH v2 13/42] Special prefixes")' +) +test_expect_equal "$output" 13 + +test_begin_subtest "patch sequence number #3" +output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number + "[PATCH 2/3] [PATCH 032/037] use the last prefix")' +) +test_expect_equal "$output" 32 + +test_begin_subtest "patch sequence number #4" +output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number + "[dummy list prefix] [PATCH 2/3] PATCH 3/3] do not use a broken prefix")' +) +test_expect_equal "$output" 2 + +test_begin_subtest "patch sequence number #5" +output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number + "[RFC][PATCH 3/5][PATCH 4/5][PATCH 5/5] A made up test")' +) +test_expect_equal "$output" 5 + +test_begin_subtest "patch sequence number #6" +output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number + "[PATCH 2/3] this -> [PATCH 3/3] is not a prefix anymore [nor this 4/4]")' +) +test_expect_equal "$output" 2 + +test_begin_subtest "patch sequence number #7" +output=$(test_emacs '(notmuch-wash-subject-to-patch-sequence-number + "[liberally accept crapola right before123/456and after] the numbers")' +) +test_expect_equal "$output" 123 + +# test notmuch-wash-subject-to-filename (subject &optional maxlen) +test_begin_subtest "filename #1" +output=$(test_emacs '(notmuch-wash-subject-to-filename + "just a subject line")' +) +test_expect_equal $output '"just-a-subject-line"' + +test_begin_subtest "filename #2" +output=$(test_emacs '(notmuch-wash-subject-to-filename + " [any] [prefixes are ] [removed!] from the subject")' +) +test_expect_equal $output '"from-the-subject"' + +test_begin_subtest "filename #3" +output=$(test_emacs '(notmuch-wash-subject-to-filename + " leading and trailing space ")' +) +test_expect_equal $output '"leading-and-trailing-space"' + +test_begin_subtest "filename #4" +output=$(test_emacs '(notmuch-wash-subject-to-filename + "!# leading ()// &%, and in between_and_trailing garbage ()(&%%")' +) +test_expect_equal $output '"-leading-and-in-between_and_trailing-garbage"' + +test_begin_subtest "filename #5" +output=$(test_emacs '(notmuch-wash-subject-to-filename + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_01234567890")' +) +test_expect_equal $output '"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_01234567890"' + +test_begin_subtest "filename #6" +output=$(test_emacs '(notmuch-wash-subject-to-filename + "sequences of ... are squashed and trailing are removed ...")' +) +test_expect_equal $output '"sequences-of-.-are-squashed-and-trailing-are-removed"' + +test_begin_subtest "filename #7" +output=$(test_emacs '(notmuch-wash-subject-to-filename + "max length test" 1)' +) +test_expect_equal $output '"m"' + +test_begin_subtest "filename #8" +output=$(test_emacs '(notmuch-wash-subject-to-filename + "max length test /&(/%&/%%&¤%¤" 20)' +) +test_expect_equal $output '"max-length-test"' + +test_begin_subtest "filename #9" +output=$(test_emacs '(notmuch-wash-subject-to-filename + "[a prefix] [is only separated] by [spaces], so \"by\" is not okay!")' +) +test_expect_equal $output '"by-spaces-so-by-is-not-okay"' + +# test notmuch-wash-subject-to-patch-filename (subject) +test_begin_subtest "patch filename #1" +output=$(test_emacs '(notmuch-wash-subject-to-patch-filename + "[RFC][PATCH 099/100] rewrite notmuch")' +) +test_expect_equal "$output" '"0099-rewrite-notmuch.patch"' + +test_begin_subtest "patch filename #2" +output=$(test_emacs '(notmuch-wash-subject-to-patch-filename + "[RFC PATCH v1] has no patch number, default to 1")' +) +test_expect_equal "$output" '"0001-has-no-patch-number-default-to-1.patch"' + +test_begin_subtest "patch filename #3" +output=$(test_emacs '(notmuch-wash-subject-to-patch-filename + "[PATCH 4/5] the maximum length of a patch filename is 52 + patch sequence number + .patch extension")' +) +test_expect_equal "$output" '"0004-the-maximum-length-of-a-patch-filename-is-52-patch-s.patch"' + +test_begin_subtest "patch filename #4" +output=$(test_emacs '(notmuch-wash-subject-to-patch-filename + "[PATCH 4/5] the maximum length of a patch filename is 52 + patchh ! sequence number + .patch extension, *before* trimming trailing - and .")' +) +test_expect_equal "$output" '"0004-the-maximum-length-of-a-patch-filename-is-52-patchh.patch"' + +test_done diff --git a/test/emacs-test-functions b/test/emacs-test-functions new file mode 100755 index 00000000..0e1f9fc7 --- /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 48143bd7..3e59595f 100644 --- a/test/emacs.expected-output/notmuch-hello +++ b/test/emacs.expected-output/notmuch-hello @@ -1,14 +1,14 @@ - Welcome to notmuch. You have 50 messages. + Welcome to notmuch. You have 52 messages. Saved searches: [edit] - 50 inbox 50 unread + 52 inbox 52 unread -Search: +Search: . [Show all tags] 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. diff --git a/test/emacs.expected-output/notmuch-hello-no-saved-searches b/test/emacs.expected-output/notmuch-hello-no-saved-searches index 7c09e40b..ef0e5d05 100644 --- a/test/emacs.expected-output/notmuch-hello-no-saved-searches +++ b/test/emacs.expected-output/notmuch-hello-no-saved-searches @@ -1,10 +1,10 @@ - Welcome to notmuch. You have 50 messages. + Welcome to notmuch. You have 52 messages. -Search: +Search: . [Show all tags] 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. diff --git a/test/emacs.expected-output/notmuch-hello-view-inbox b/test/emacs.expected-output/notmuch-hello-view-inbox index 894ae5fa..1688d674 100644 --- a/test/emacs.expected-output/notmuch-hello-view-inbox +++ b/test/emacs.expected-output/notmuch-hello-view-inbox @@ -20,4 +20,6 @@ 2009-11-18 [1/1] Alexander Botero-Lowry [notmuch] request for pull (inbox unread) 2009-11-18 [2/2] Keith Packard, Alexander Botero-Lowry [notmuch] [PATCH] Create a default notmuch-show-hook that highlights URLs and uses word-wrap (inbox unread) 2009-11-18 [1/1] Chris Wilson [notmuch] [PATCH 1/2] Makefile: evaluate pkg-config once (inbox unread) + 2010-12-16 [1/1] Olivier Berger Essai accentué (inbox unread) + 2010-12-29 [1/1] François Boulogne [aur-general] Guidelines: cp, mkdir vs install (inbox unread) End of search results. diff --git a/test/emacs.expected-output/notmuch-hello-with-empty b/test/emacs.expected-output/notmuch-hello-with-empty index 2a267c92..71edba73 100644 --- a/test/emacs.expected-output/notmuch-hello-with-empty +++ b/test/emacs.expected-output/notmuch-hello-with-empty @@ -1,14 +1,14 @@ - Welcome to notmuch. You have 50 messages. + Welcome to notmuch. You have 52 messages. Saved searches: [edit] - 50 inbox 50 unread 0 empty + 52 inbox 52 unread 0 empty -Search: +Search: . [Show all tags] 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. diff --git a/test/emacs.expected-output/notmuch-search-tag-inbox b/test/emacs.expected-output/notmuch-search-tag-inbox index 9456ccfd..8a53555a 100644 --- a/test/emacs.expected-output/notmuch-search-tag-inbox +++ b/test/emacs.expected-output/notmuch-search-tag-inbox @@ -1,3 +1,5 @@ + 2010-12-29 [1/1] François Boulogne [aur-general] Guidelines: cp, mkdir vs install (inbox unread) + 2010-12-16 [1/1] Olivier Berger Essai accentué (inbox unread) 2009-11-18 [1/1] Chris Wilson [notmuch] [PATCH 1/2] Makefile: evaluate pkg-config once (inbox unread) 2009-11-18 [2/2] Alex Botero-Lowry, Carl Worth [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread) 2009-11-18 [2/2] Ingmar Vanhassel, Carl Worth [notmuch] [PATCH] Typsos (inbox unread) diff --git a/test/emacs.expected-output/notmuch-show-thread-maildir-storage b/test/emacs.expected-output/notmuch-show-thread-maildir-storage index 8ba64b27..cdbfa1d7 100644 --- a/test/emacs.expected-output/notmuch-show-thread-maildir-storage +++ b/test/emacs.expected-output/notmuch-show-thread-maildir-storage @@ -26,12 +26,11 @@ with Maildir) or if something else is going on. Cheers, -[ 5-line signature. Click/Enter to show. ] +[ 4-line signature. Click/Enter to show. ] -- Lars Kellogg-Stedman <lars@seas.harvard.edu> Senior Technologist, Computing and Information Technology Harvard University School of Engineering and Applied Sciences - [ application/pgp-signature ] [ text/plain ] [ 4-line signature. Click/Enter to show. ] @@ -48,12 +47,14 @@ http://notmuchmail.org/mailman/listinfo/notmuch [ multipart/signed ] [ text/plain ] - Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars@seas.harvard.edu did gyre and gimble: + Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars@seas.harvard.edu did + gyre and gimble: LK> Resulted in 4604 lines of errors along the lines of: LK> Error opening - LK> /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: + LK> + /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: LK> Too many open files See the patch just posted here. @@ -88,12 +89,11 @@ http://notmuchmail.org/mailman/listinfo/notmuch -- Lars - [ 5-line signature. Click/Enter to show. ] + [ 4-line signature. Click/Enter to show. ] -- Lars Kellogg-Stedman <lars@seas.harvard.edu> Senior Technologist, Computing and Information Technology Harvard University School of Engineering and Applied Sciences - [ application/pgp-signature ] [ text/plain ] [ 4-line signature. Click/Enter to show. ] @@ -106,8 +106,8 @@ http://notmuchmail.org/mailman/listinfo/notmuch To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 02:50:48 +0600 - - Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu did gyre and gimble: + Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu + did gyre and gimble: LK> Is the list archived anywhere? The obvious archives LK> (http://notmuchmail.org/pipermail/notmuch/) aren't available, and I @@ -127,14 +127,15 @@ http://notmuchmail.org/mailman/listinfo/notmuch Type: application/pgp-signature Size: 834 bytes Desc: not available - URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp> - + URL: + <http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp> Keith Packard <keithp@keithp.com> (2009-11-17) (inbox unread) Subject: [notmuch] Working with Maildir storage? To: notmuch@notmuchmail.org Date: Tue, 17 Nov 2009 13:24:13 -0800 - On Tue, 17 Nov 2009 15:33:01 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote: + On Tue, 17 Nov 2009 15:33:01 -0500, Lars Kellogg-Stedman <lars at + seas.harvard.edu> wrote: > > See the patch just posted here. I've also pushed a slightly more complicated (and complete) fix to my @@ -150,7 +151,6 @@ http://notmuchmail.org/mailman/listinfo/notmuch Thanks to everyone for trying out notmuch! -keith - Lars Kellogg-Stedman <lars@seas.harvard.edu> (2009-11-18) (inbox signed unread) Subject: Re: [notmuch] Working with Maildir storage? To: Keith Packard <keithp@keithp.com> @@ -166,12 +166,11 @@ http://notmuchmail.org/mailman/listinfo/notmuch The version of lib/messages.cc in your repo doesn't build because it's missing "#include <stdint.h>" (for the uint32_t on line 466). - [ 5-line signature. Click/Enter to show. ] + [ 4-line signature. Click/Enter to show. ] -- Lars Kellogg-Stedman <lars@seas.harvard.edu> Senior Technologist, Computing and Information Technology Harvard University School of Engineering and Applied Sciences - [ application/pgp-signature ] [ text/plain ] [ 4-line signature. Click/Enter to show. ] @@ -184,7 +183,8 @@ http://notmuchmail.org/mailman/listinfo/notmuch To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 02:08:10 -0800 - On Tue, 17 Nov 2009 14:00:54 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote: + On Tue, 17 Nov 2009 14:00:54 -0500, Lars Kellogg-Stedman <lars at + seas.harvard.edu> wrote: > I saw the LWN article and decided to take a look at notmuch. I'm > currently using mutt and mairix to index and read a collection of > Maildir mail folders (around 40,000 messages total). @@ -195,7 +195,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch That's very interesting. So, thanks for coming and trying out notmuch. > Error opening - > /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: + > /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: > Too many open files Sadly, the lwn article coincided with me having just introduced this @@ -212,4 +212,3 @@ http://notmuchmail.org/mailman/listinfo/notmuch Happy hacking, -Carl - diff --git a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation index 41e2aaa3..b0bf93ed 100644 --- a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation +++ b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-with-fourfold-indentation @@ -26,12 +26,11 @@ with Maildir) or if something else is going on. Cheers, -[ 5-line signature. Click/Enter to show. ] +[ 4-line signature. Click/Enter to show. ] -- Lars Kellogg-Stedman <lars@seas.harvard.edu> Senior Technologist, Computing and Information Technology Harvard University School of Engineering and Applied Sciences - [ application/pgp-signature ] [ text/plain ] [ 4-line signature. Click/Enter to show. ] @@ -48,12 +47,14 @@ http://notmuchmail.org/mailman/listinfo/notmuch [ multipart/signed ] [ text/plain ] - Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars@seas.harvard.edu did gyre and gimble: + Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars@seas.harvard.edu did + gyre and gimble: LK> Resulted in 4604 lines of errors along the lines of: LK> Error opening - LK> /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: + LK> + /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: LK> Too many open files See the patch just posted here. @@ -88,12 +89,11 @@ http://notmuchmail.org/mailman/listinfo/notmuch -- Lars - [ 5-line signature. Click/Enter to show. ] + [ 4-line signature. Click/Enter to show. ] -- Lars Kellogg-Stedman <lars@seas.harvard.edu> Senior Technologist, Computing and Information Technology Harvard University School of Engineering and Applied Sciences - [ application/pgp-signature ] [ text/plain ] [ 4-line signature. Click/Enter to show. ] @@ -106,8 +106,8 @@ http://notmuchmail.org/mailman/listinfo/notmuch To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 02:50:48 +0600 - - Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu did gyre and gimble: + Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu + did gyre and gimble: LK> Is the list archived anywhere? The obvious archives LK> (http://notmuchmail.org/pipermail/notmuch/) aren't available, and I @@ -127,14 +127,15 @@ http://notmuchmail.org/mailman/listinfo/notmuch Type: application/pgp-signature Size: 834 bytes Desc: not available - URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp> - + URL: + <http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp> Keith Packard <keithp@keithp.com> (2009-11-17) (inbox unread) Subject: [notmuch] Working with Maildir storage? To: notmuch@notmuchmail.org Date: Tue, 17 Nov 2009 13:24:13 -0800 - On Tue, 17 Nov 2009 15:33:01 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote: + On Tue, 17 Nov 2009 15:33:01 -0500, Lars Kellogg-Stedman <lars at + seas.harvard.edu> wrote: > > See the patch just posted here. I've also pushed a slightly more complicated (and complete) fix to my @@ -150,7 +151,6 @@ http://notmuchmail.org/mailman/listinfo/notmuch Thanks to everyone for trying out notmuch! -keith - Lars Kellogg-Stedman <lars@seas.harvard.edu> (2009-11-18) (inbox signed unread) Subject: Re: [notmuch] Working with Maildir storage? To: Keith Packard <keithp@keithp.com> @@ -166,12 +166,11 @@ http://notmuchmail.org/mailman/listinfo/notmuch The version of lib/messages.cc in your repo doesn't build because it's missing "#include <stdint.h>" (for the uint32_t on line 466). - [ 5-line signature. Click/Enter to show. ] + [ 4-line signature. Click/Enter to show. ] -- Lars Kellogg-Stedman <lars@seas.harvard.edu> Senior Technologist, Computing and Information Technology Harvard University School of Engineering and Applied Sciences - [ application/pgp-signature ] [ text/plain ] [ 4-line signature. Click/Enter to show. ] @@ -184,7 +183,8 @@ http://notmuchmail.org/mailman/listinfo/notmuch To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 02:08:10 -0800 - On Tue, 17 Nov 2009 14:00:54 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote: + On Tue, 17 Nov 2009 14:00:54 -0500, Lars Kellogg-Stedman <lars at + seas.harvard.edu> wrote: > I saw the LWN article and decided to take a look at notmuch. I'm > currently using mutt and mairix to index and read a collection of > Maildir mail folders (around 40,000 messages total). @@ -195,7 +195,7 @@ http://notmuchmail.org/mailman/listinfo/notmuch That's very interesting. So, thanks for coming and trying out notmuch. > Error opening - > /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: + > /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: > Too many open files Sadly, the lwn article coincided with me having just introduced this @@ -212,4 +212,3 @@ http://notmuchmail.org/mailman/listinfo/notmuch Happy hacking, -Carl - diff --git a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-without-indentation b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-without-indentation index fa2108ef..08de8b5d 100644 --- a/test/emacs.expected-output/notmuch-show-thread-maildir-storage-without-indentation +++ b/test/emacs.expected-output/notmuch-show-thread-maildir-storage-without-indentation @@ -26,12 +26,11 @@ with Maildir) or if something else is going on. Cheers, -[ 5-line signature. Click/Enter to show. ] +[ 4-line signature. Click/Enter to show. ] -- Lars Kellogg-Stedman <lars@seas.harvard.edu> Senior Technologist, Computing and Information Technology Harvard University School of Engineering and Applied Sciences - [ application/pgp-signature ] [ text/plain ] [ 4-line signature. Click/Enter to show. ] @@ -48,12 +47,14 @@ Date: Wed, 18 Nov 2009 01:02:38 +0600 [ multipart/signed ] [ text/plain ] -Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars@seas.harvard.edu did gyre and gimble: +Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars@seas.harvard.edu did +gyre and gimble: LK> Resulted in 4604 lines of errors along the lines of: LK> Error opening - LK> /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: + LK> +/home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: LK> Too many open files See the patch just posted here. @@ -88,12 +89,11 @@ It doesn't look like the patch is in git yet. -- Lars -[ 5-line signature. Click/Enter to show. ] +[ 4-line signature. Click/Enter to show. ] -- Lars Kellogg-Stedman <lars@seas.harvard.edu> Senior Technologist, Computing and Information Technology Harvard University School of Engineering and Applied Sciences - [ application/pgp-signature ] [ text/plain ] [ 4-line signature. Click/Enter to show. ] @@ -106,8 +106,8 @@ Subject: [notmuch] Working with Maildir storage? To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 02:50:48 +0600 - -Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu did gyre and gimble: +Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu +did gyre and gimble: LK> Is the list archived anywhere? The obvious archives LK> (http://notmuchmail.org/pipermail/notmuch/) aren't available, and I @@ -127,14 +127,15 @@ Name: not available Type: application/pgp-signature Size: 834 bytes Desc: not available -URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp> - +URL: +<http://notmuchmail.org/pipermail/notmuch/attachments/20091118/0e33d964/attachment.pgp> Keith Packard <keithp@keithp.com> (2009-11-17) (inbox unread) Subject: [notmuch] Working with Maildir storage? To: notmuch@notmuchmail.org Date: Tue, 17 Nov 2009 13:24:13 -0800 -On Tue, 17 Nov 2009 15:33:01 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote: +On Tue, 17 Nov 2009 15:33:01 -0500, Lars Kellogg-Stedman <lars at +seas.harvard.edu> wrote: > > See the patch just posted here. I've also pushed a slightly more complicated (and complete) fix to my @@ -150,7 +151,6 @@ Barcelona today and so it won't get fixed for a while. Thanks to everyone for trying out notmuch! -keith - Lars Kellogg-Stedman <lars@seas.harvard.edu> (2009-11-18) (inbox signed unread) Subject: Re: [notmuch] Working with Maildir storage? To: Keith Packard <keithp@keithp.com> @@ -166,12 +166,11 @@ Date: Tue, 17 Nov 2009 19:50:40 -0500 The version of lib/messages.cc in your repo doesn't build because it's missing "#include <stdint.h>" (for the uint32_t on line 466). -[ 5-line signature. Click/Enter to show. ] +[ 4-line signature. Click/Enter to show. ] -- Lars Kellogg-Stedman <lars@seas.harvard.edu> Senior Technologist, Computing and Information Technology Harvard University School of Engineering and Applied Sciences - [ application/pgp-signature ] [ text/plain ] [ 4-line signature. Click/Enter to show. ] @@ -184,7 +183,8 @@ Subject: [notmuch] Working with Maildir storage? To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 02:08:10 -0800 -On Tue, 17 Nov 2009 14:00:54 -0500, Lars Kellogg-Stedman <lars at seas.harvard.edu> wrote: +On Tue, 17 Nov 2009 14:00:54 -0500, Lars Kellogg-Stedman <lars at +seas.harvard.edu> wrote: > I saw the LWN article and decided to take a look at notmuch. I'm > currently using mutt and mairix to index and read a collection of > Maildir mail folders (around 40,000 messages total). @@ -195,7 +195,7 @@ I hadn't even seen that Keith's blog post had been picked up by lwn.net. That's very interesting. So, thanks for coming and trying out notmuch. > Error opening -> /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: +> /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: > Too many open files Sadly, the lwn article coincided with me having just introduced this @@ -212,4 +212,3 @@ likes the best. Happy hacking, -Carl - diff --git a/test/encoding b/test/encoding index 673b0394..f0d073c5 100755 --- a/test/encoding +++ b/test/encoding @@ -4,7 +4,7 @@ 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 header{ @@ -12,7 +12,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox unread) Subject: Test message #1 From: Notmuch Test Suite <test_suite@notmuchmail.org> To: Notmuch Test Suite <test_suite@notmuchmail.org> -Date: Tue, 05 Jan 2001 15:43:57 -0000 +Date: Fri, 05 Jan 2001 15:43:57 +0000 header} body{ part{ ID: 1, Content-type: text/plain @@ -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/from-guessing b/test/from-guessing index 8b69cf6c..6dfaa40a 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/maildir-sync b/test/maildir-sync index a60854f8..d5872a53 100755 --- a/test/maildir-sync +++ b/test/maildir-sync @@ -55,8 +55,8 @@ test_expect_equal "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite", "To": "Notmuch Test Suite <test_suite@notmuchmail.org>", "Cc": "", "Bcc": "", -"Date": "Tue, -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"}]}, diff --git a/test/multipart b/test/multipart index f83526bb..2dd73f59 100755 --- a/test/multipart +++ b/test/multipart @@ -121,9 +121,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 +162,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 +200,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 +233,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{ @@ -452,9 +452,9 @@ notmuch show --format=raw --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUT # output should *not* include newline echo >>OUTPUT cat <<EOF >EXPECTED +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 <p>This is an embedded message, with a multipart/alternative part.</p> @@ -476,9 +476,9 @@ test_expect_equal_file OUTPUT EXPECTED 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 +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 <p>This is an embedded message, with a multipart/alternative part.</p> @@ -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" @@ -153,4 +153,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 ded79e8f..e14d34e4 100755 --- a/test/notmuch-test +++ b/test/notmuch-test @@ -33,6 +33,7 @@ TESTS=" thread-naming raw reply + reply-to-sender dump-restore uuencode thread-order @@ -42,6 +43,7 @@ TESTS=" encoding emacs emacs-large-search-buffer + emacs-subject-to-filename maildir-sync crypto symbol-hiding @@ -50,6 +52,9 @@ TESTS=" python hooks argument-parsing + emacs-test-functions + emacs-address-cleaning + emacs-show " TESTS=${NOTMUCH_TESTS:=$TESTS} diff --git a/test/python b/test/python index c3aa7266..6018c2d0 100755 --- a/test/python +++ b/test/python @@ -7,11 +7,25 @@ add_email_corpus test_begin_subtest "compare thread ids" test_python <<EOF import notmuch -db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE) +db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY) q_new = notmuch.Query(db, 'tag:inbox') +q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST) for t in q_new.search_threads(): print t.get_thread_id() EOF -notmuch search --output=threads tag:inbox | sed s/^thread:// | sort > EXPECTED -test_expect_equal_file <(sort OUTPUT) EXPECTED +notmuch search --sort=oldest-first --output=threads tag:inbox | sed s/^thread:// > EXPECTED +test_expect_equal_file OUTPUT EXPECTED + +test_begin_subtest "compare message ids" +test_python <<EOF +import notmuch +db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY) +q_new = notmuch.Query(db, 'tag:inbox') +q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST) +for m in q_new.search_messages(): + print m.get_message_id() +EOF +notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED +test_expect_equal_file OUTPUT EXPECTED + test_done @@ -19,7 +19,7 @@ test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.or To: Notmuch Test Suite <test_suite@notmuchmail.org> Message-Id: <msg-001@notmuch-test-suite> Subject: Test message #1 -Date: Tue, 05 Jan 2001 15:43:57 -0000 +Date: Fri, 05 Jan 2001 15:43:57 +0000 This is just a test message (#1)" @@ -29,7 +29,7 @@ test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.or To: Notmuch Test Suite <test_suite@notmuchmail.org> Message-Id: <msg-002@notmuch-test-suite> Subject: Test message #2 -Date: Tue, 05 Jan 2001 15:43:57 -0000 +Date: Fri, 05 Jan 2001 15:43:57 +0000 This is just a test message (#2)" @@ -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 diff --git a/test/reply-to-sender b/test/reply-to-sender new file mode 100755 index 00000000..c7d15bbe --- /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 b/test/search index e7c8c54b..414be356 100755 --- a/test/search +++ b/test/search @@ -79,8 +79,11 @@ output=$(notmuch search 'subject:"subject search test (phrase)"' | notmuch_searc test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)" test_begin_subtest 'Search for all messages ("*")' -output=$(notmuch search '*' | notmuch_search_sanitize) -test_expect_equal "$output" "thread:XXX 2009-11-18 [1/1] Chris Wilson; [notmuch] [PATCH 1/2] Makefile: evaluate pkg-config once (inbox unread) +notmuch search '*' | notmuch_search_sanitize > OUTPUT +cat <<EOF >EXPECTED +thread:XXX 2010-12-29 [1/1] François Boulogne; [aur-general] Guidelines: cp, mkdir vs install (inbox unread) +thread:XXX 2010-12-16 [1/1] Olivier Berger; Essai accentué (inbox unread) +thread:XXX 2009-11-18 [1/1] Chris Wilson; [notmuch] [PATCH 1/2] Makefile: evaluate pkg-config once (inbox unread) thread:XXX 2009-11-18 [2/2] Alex Botero-Lowry, Carl Worth; [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread) thread:XXX 2009-11-18 [2/2] Ingmar Vanhassel, Carl Worth; [notmuch] [PATCH] Typsos (inbox unread) thread:XXX 2009-11-18 [3/3] Adrian Perez de Castro, Keith Packard, Carl Worth; [notmuch] Introducing myself (inbox signed unread) @@ -99,7 +102,7 @@ thread:XXX 2009-11-18 [1/1] Jan Janak; [notmuch] [PATCH] notmuch new: Support thread:XXX 2009-11-18 [1/1] Stewart Smith; [notmuch] [PATCH] count_files: sort directory in inode order before statting (inbox unread) thread:XXX 2009-11-18 [1/1] Stewart Smith; [notmuch] [PATCH 2/2] Read mail directory in inode number order (inbox unread) thread:XXX 2009-11-18 [1/1] Stewart Smith; [notmuch] [PATCH] Fix linking with gcc to use g++ to link in C++ libs. (inbox unread) -thread:XXX 2009-11-18 [2/2] Lars Kellogg-Stedman; [notmuch] \"notmuch help\" outputs to stderr? (attachment inbox signed unread) +thread:XXX 2009-11-18 [2/2] Lars Kellogg-Stedman; [notmuch] "notmuch help" outputs to stderr? (attachment inbox signed unread) thread:XXX 2009-11-17 [1/1] Mikhail Gusarov; [notmuch] [PATCH] Handle rename of message file (inbox unread) thread:XXX 2009-11-17 [2/2] Alex Botero-Lowry, Carl Worth; [notmuch] preliminary FreeBSD support (attachment inbox unread) thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread) @@ -117,11 +120,38 @@ thread:XXX 2000-01-01 [1/1] Search By From Name; search by from (name) (inbox thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread) thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread) thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread) -thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread)" +thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread) +EOF +test_expect_equal_file OUTPUT EXPECTED test_begin_subtest "Search body (utf-8):" add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="message body utf8: bödý"' output=$(notmuch search "bödý" | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)" +test_begin_subtest "Exclude \"deleted\" messages from search" +notmuch config set search.exclude_tags = deleted +generate_message '[subject]="Not deleted"' +generate_message '[subject]="Deleted"' +notmuch new > /dev/null +notmuch tag +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 "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 "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 "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)" + test_done diff --git a/test/search-output b/test/search-output index 10291c3b..8b57a432 100755 --- a/test/search-output +++ b/test/search-output @@ -29,6 +29,8 @@ thread:THREADID thread:THREADID thread:THREADID thread:THREADID +thread:THREADID +thread:THREADID EOF test_expect_equal_file OUTPUT EXPECTED @@ -56,6 +58,8 @@ cat <<EOF >EXPECTED "THREADID", "THREADID", "THREADID", +"THREADID", +"THREADID", "THREADID"] EOF test_expect_equal_file OUTPUT EXPECTED @@ -63,6 +67,8 @@ test_expect_equal_file OUTPUT EXPECTED test_begin_subtest "--output=messages" notmuch search --output=messages '*' >OUTPUT cat <<EOF >EXPECTED +id:4EFC743A.3060609@april.org +id:877h1wv7mg.fsf@inf-8657.int-evry.fr id:1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk id:877htoqdbo.fsf@yoom.home.cworth.org id:878we4qdqf.fsf@yoom.home.cworth.org @@ -119,7 +125,9 @@ test_expect_equal_file OUTPUT EXPECTED test_begin_subtest "--output=messages --format=json" notmuch search --format=json --output=messages '*' >OUTPUT cat <<EOF >EXPECTED -["1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk", +["4EFC743A.3060609@april.org", +"877h1wv7mg.fsf@inf-8657.int-evry.fr", +"1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk", "877htoqdbo.fsf@yoom.home.cworth.org", "878we4qdqf.fsf@yoom.home.cworth.org", "87aaykqe24.fsf@yoom.home.cworth.org", @@ -175,6 +183,8 @@ test_expect_equal_file OUTPUT EXPECTED test_begin_subtest "--output=files" notmuch search --output=files '*' | sed -e "s,$MAIL_DIR,MAIL_DIR," >OUTPUT cat <<EOF >EXPECTED +MAIL_DIR/cur/52:2, +MAIL_DIR/cur/53:2, MAIL_DIR/cur/50:2, MAIL_DIR/cur/49:2, MAIL_DIR/cur/48:2, @@ -232,7 +242,9 @@ test_expect_equal_file OUTPUT EXPECTED test_begin_subtest "--output=files --format=json" notmuch search --format=json --output=files '*' | sed -e "s,$MAIL_DIR,MAIL_DIR," >OUTPUT cat <<EOF >EXPECTED -["MAIL_DIR/cur/50:2,", +["MAIL_DIR/cur/52:2,", +"MAIL_DIR/cur/53:2,", +"MAIL_DIR/cur/50:2,", "MAIL_DIR/cur/49:2,", "MAIL_DIR/cur/48:2,", "MAIL_DIR/cur/47:2,", diff --git a/test/search-position-overlap-bug b/test/search-position-overlap-bug index 414b8d52..5da6ad6f 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 68f0d1b1..636ec917 100755 --- a/test/symbol-hiding +++ b/test/symbol-hiding @@ -12,7 +12,7 @@ test_description='exception symbol hiding' . ./test-lib.sh run_test(){ - result=$(LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib $TEST_DIRECTORY/symbol-test 2>&1) + result=$(LD_LIBRARY_PATH="$TEST_DIRECTORY/../lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" $TEST_DIRECTORY/symbol-test 2>&1) } output="A Xapian exception occurred opening database: Couldn't stat 'fakedb/.notmuch/xapian' @@ -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/test-lib.el b/test/test-lib.el index 3b817c37..6271da22 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,38 @@ nothing." (add-hook-counter 'notmuch-hello-mode-hook) (add-hook-counter 'notmuch-hello-refresh-hook) + +(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 b5e346c0..27815067 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -1,4 +1,3 @@ -#!/usr/bin/env bash # # Copyright (c) 2005 Junio C Hamano # @@ -50,6 +49,7 @@ TZ=UTC TERM=dumb export LANG LC_ALL PAGER TERM TZ GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} +TEST_EMACS=${TEST_EMACS:-${EMACS:-emacs}} # Protect ourselves from common misconfiguration to export # CDPATH into the environment @@ -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 @@ -322,7 +322,7 @@ generate_message () fi if [ -z "${template[date]}" ]; then - template[date]="Tue, 05 Jan 2001 15:43:57 -0000" + template[date]="Fri, 05 Jan 2001 15:43:57 +0000" fi additional_headers="" @@ -356,6 +356,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 +508,35 @@ test_expect_equal_file () fi } +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' @@ -673,8 +707,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 +903,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 +915,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 @@ -897,7 +931,7 @@ export NOTMUCH_CONFIG=$NOTMUCH_CONFIG # # --load Force loading of notmuch.el and test-lib.el -exec emacs --no-init-file --no-site-file \ +exec ${TEST_EMACS} --no-init-file --no-site-file \ --directory "$TEST_DIRECTORY/../emacs" --load notmuch.el \ --directory "$TEST_DIRECTORY" --load test-lib.el \ "\$@" @@ -907,10 +941,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 +961,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/thread-naming b/test/thread-naming index 41b97d9c..942e5939 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,29 +37,29 @@ 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)" @@ -71,7 +71,7 @@ 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 @@ -85,7 +85,7 @@ 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 @@ -99,7 +99,7 @@ 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 @@ -113,7 +113,7 @@ 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 @@ -127,7 +127,7 @@ 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 @@ -141,7 +141,7 @@ 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 @@ -155,7 +155,7 @@ 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 @@ -169,7 +169,7 @@ 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 26e4c3f3..c7cae61e 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 @@ -1 +1 @@ -0.11.1 +0.12 |
