Commit graph

7410 commits

Author SHA1 Message Date
David Bremner
808fd6f258 test: add known broken test for message-id with embedded spaces.
According to my reading of RFC5322, there is an obsolete syntax for
Message-Id which permits folding whitespace (i.e. to be removed /
ignored by parsers). In [1] Paul Wise observed that notmuch removed
whitespace on indexing, but does not do any corresponding
normalization of queries. Mark the latter as a bug by adding a failing
test.

[1]: id:20230409044143.4041560-1-pabs3@bonedaddy.net
2023-07-09 11:59:43 -03:00
Michael J Gruber
3771832b01 python: adjust legacy bindings to py 3.12
Py 3.12 finally pulled the plug on the `SafeConfigParser` class which
has been deprecated since py 3.2.

We use it in the legacy bindings only, so take the easy route of
importing `ConfigParser` as `SafeConfigParser` and monkey-patching so
that the class has the expected interface.
2023-07-09 11:43:21 -03:00
Felipe Contreras
95a4bf3817 ruby: db: reorganize initializer
In order to make it more extensible.

No functional changes.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-05-29 07:51:02 -03:00
Paul Wise
239fdbbbf0 notmuch-mutt: check that the search cache Maildir is not a real Maildir
This prevents data loss when users configure the search cache Maildir to be a
real Maildir containing their real mail data, since the search cache Maildir
is expected to contain only symlinks to the real mail data.

Prevents: <ZCsQBNmbzwkvbpHA@localhost.localdomain>
2023-05-28 15:34:42 -03:00
Paul Wise
18e35950da notmuch-mutt: do not clear search cache Maildir when nothing is found
The previous results might be useful to the user but
an empty directory definitely isn't useful.
2023-05-28 15:33:11 -03:00
Paul Wise
85916d8a96 notmuch-mutt: clarify the empty Maildir function operates on search caches
Rename the function and adjust the documentation comment.
2023-05-28 15:32:11 -03:00
Paul Wise
93d936c5ae notmuch-mutt: replace extra command with notmuch thread search feature
This should be be slightly faster since it avoids forking a shell
and is less code in and less dependencies for the script.

Since String::ShellQuote isn't used elsewhere, drop mention of it.
2023-05-27 14:26:43 -03:00
Paul Wise
6d383d4049 notmuch-mutt: fix Xapian query construction
Spaces need to be stripped when querying the Message-Id,
because notmuch stores them in Xapian with spaces stripped.

All double-quote characters need to be doubled to escape them,
otherwise they will be added as extra query terms outside the id.
2023-05-27 14:24:40 -03:00
Paul Wise
d155f29eca notmuch-mutt: convert ISO-8859-15 copyright statement to UTF-8
Suggested-by: isutf8 & check-all-the-things
2023-05-25 08:43:14 -03:00
Felipe Contreras
afa45bd6b8 ruby: query: fix get sort
The order was wrong, right now `query.sort` doesn't return a number.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-05-25 07:02:59 -03:00
John Gliksberg
74c2c86769 vim: doc: minor spelling fix
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-05-07 14:27:33 -06:00
Felipe Contreras
3f4c61592f vim: doc: small fixes
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-05-07 14:27:10 -06:00
Jakub Wilk
1b878877d9 doc: fix typos 2023-04-13 11:14:58 -03:00
Felipe Contreras
e4d75fcc83 ruby: remove FileNames object
Not used anymore now that we return an array of strings directly.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-04-12 07:30:01 -03:00
Felipe Contreras
837426d7be ruby: filenames: return string array directly
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-04-12 07:29:48 -03:00
Felipe Contreras
777b02a7d7 ruby: add filenames helper
Right now it doesn't do much, but it will help for further
reorganization.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-04-12 07:05:23 -03:00
David Bremner
a554690d6a lib: index attachments with mime types matching index.as_text
Instead of skipping indexing all attachments, we check of a (user
configured) mime type that is indexable as text.
2023-04-02 19:24:43 -03:00
David Bremner
3f5809bf28 lib: parse index.as_text
We pre-parse into a list of compiled regular expressions to avoid
calling regexc on the hot (indexing) path.  As explained in the code
comment, this cannot be done lazily with reasonable error reporting,
at least not without touching a lot of the code in index.cc.
2023-04-02 19:22:36 -03:00
David Bremner
c6733a45c8 lib: add config key INDEX_AS_TEXT
Higher level processing as a list of regular expressions and
documentation will follow.
2023-04-02 19:21:37 -03:00
Felipe Contreras
44924a6a09 ruby: remove Tags object
Not used anymore now that we return an array of strings directly.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-04-02 19:11:10 -03:00
Felipe Contreras
3a52290609 ruby: tags: return string array directly
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-04-02 19:10:55 -03:00
Felipe Contreras
ae1336dea5 ruby: add tags helper
Right now it doesn't do much, but it will help for further
reorganization.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-04-02 19:00:49 -03:00
Kevin Boulain
6273966d0b lib: replace some uses of Query::MatchAll with a thread-safe alternative
This replaces two instances of Xapian::Query::MatchAll with the
equivalent but thread-safe alternative Xapian::Query(std::string()).
Xapian::Query::MatchAll maintains an internal pointer to a refcounted
Xapian::Internal::QueryTerm.

None of this is thread-safe but that wouldn't be an issue if
Xapian::Query::MatchAll wasn't static. Because it's static, the
refcounting goes awry when Notmuch is called from multiple threads.
This is actually documented by Xapian:
4715de3a9f/xapian-core/include/xapian/query.h (L65)

While static, Xapian::Query::MatchNothing is safe because it doesn't
maintain an internal object and as such, doesn't use references.

Two best-effort tests making use of TSan were added to showcase the
issue (I couldn't figure out a way to deterministically reproduce it
without making an unmaintainable mess).

First, when two databases are created in parallel, a query that uses
Xapian::Query::MatchAll is made (lib/query.cc), resulting in the
following backtrace on a segfault:
  #0  0x00007ffff76822af in Xapian::Query::get_terms_begin (this=0x7fffe80137f0) at api/query.cc:141
  #1  0x00007ffff7f933f5 in _notmuch_query_cache_terms (query=0x7fffe80137c0) at lib/query.cc:176
  #2  0x00007ffff7f93784 in _notmuch_query_ensure_parsed_xapian (query=0x7fffe80137c0) at lib/query.cc:225
  #3  0x00007ffff7f9381a in _notmuch_query_ensure_parsed (query=0x7fffe80137c0) at lib/query.cc:260
  #4  0x00007ffff7f93bfe in _notmuch_query_search_documents (query=0x7fffe80137c0, type=0x7ffff7fa9b1e "mail", out=0x7ffff666da18) at lib/query.cc:361
  #5  0x00007ffff7f93ba4 in notmuch_query_search_messages (query=0x7fffe80137c0, out=0x7ffff666da18) at lib/query.cc:349
  #6  0x00007ffff7f83d98 in notmuch_database_upgrade (notmuch=0x7fffe8000bd0, progress_notify=0x0, closure=0x0) at lib/database.cc:934
  #7  0x00007ffff7fa110f in notmuch_database_create_with_config (database_path=0x7ffff666dcb0 "/tmp/notmuch.MZ2AGr", config_path=0x7ffff7faab3c "", profile=0x0, database=0x0, status_string=0x7ffff666dc90) at lib/open.cc:754
  #8  0x00007ffff7fa0d6f in notmuch_database_create_verbose (path=0x7ffff666dcb0 "/tmp/notmuch.MZ2AGr", database=0x0, status_string=0x7ffff666dc90) at lib/open.cc:653
  #9  0x00007ffff7fa0ceb in notmuch_database_create (path=0x7ffff666dcb0 "/tmp/notmuch.MZ2AGr", database=0x0) at lib/open.cc:637
  ...

Second, some queries would make use of Xapian::Query::MatchAll
(lib/regexp-fields.cc), resulting in the following backtrace on a
segfault:
  #0  0x00007f629828b690 in Xapian::Internal::QueryBranch::gather_terms (this=0x7f628800def0, void_terms=0x7f629726d5a0) at api/queryinternal.cc:1245
  #1  0x00007f629828c260 in Xapian::Internal::QueryScaleWeight::gather_terms (this=0x7f628800df70, void_terms=0x7f629726d5a0) at api/queryinternal.cc:1434
  #2  0x00007f629828b69f in Xapian::Internal::QueryBranch::gather_terms (this=0x7f628800dd90, void_terms=0x7f629726d5a0) at api/queryinternal.cc:1245
  #3  0x00007f6298282571 in Xapian::Query::get_unique_terms_begin (this=0x7f628800dcd8) at api/query.cc:166
  #4  0x00007f629841a59b in Xapian::Weight::Internal::accumulate_stats (this=0x7f628800dca0, subdb=..., rset=...) at weight/weightinternal.cc:86
  #5  0x00007f62983c15ba in LocalSubMatch::prepare_match (this=0x7f628800df20, nowait=true, total_stats=...) at matcher/localsubmatch.cc:172
  #6  0x00007f62983c8fcc in prepare_sub_matches (leaves=std::vector of length 1, capacity 1 = {...}, stats=...) at matcher/multimatch.cc:237
  #7  0x00007f62983c98a3 in MultiMatch::MultiMatch (this=0x7f629726d9a0, db_=..., query_=..., qlen=3, omrset=0x0, collapse_max_=0, collapse_key_=4294967295, percent_cutoff_=0, weight_cutoff_=0, order_=Xapian::Enquire::ASCENDING, sort_key_=0, sort_by_=Xapian::Enquire::Internal::VAL, sort_value_forward_=true, time_limit_=0, stats=..., weight_=0x7f6288008d50, matchspies_=std::vector of length 0, capacity 0, have_sorter=false, have_mdecider=false) at matcher/multimatch.cc:353
  #8  0x00007f629826fcba in Xapian::Enquire::Internal::get_mset (this=0x7f628800e0b0, first=0, maxitems=0, check_at_least=0, rset=0x0, mdecider=0x0) at api/omenquire.cc:569
  #9  0x00007f629827181c in Xapian::Enquire::get_mset (this=0x7f629726db80, first=0, maxitems=0, check_at_least=0, rset=0x0, mdecider=0x0) at api/omenquire.cc:937
  #10 0x00007f6298be529a in _notmuch_query_search_documents (query=0x7f6288009750, type=0x7f6298bfaafe "mail", out=0x7f629726dcc0) at lib/query.cc:447
  #11 0x00007f6298be4ae8 in notmuch_query_search_messages (query=0x7f6288009750, out=0x7f629726dcc0) at lib/query.cc:349
  ...

Printing Xapian::Query::MatchAll->internal.px->_refs in these
circumstances can help quickly identifying this scenario.

This is motivated by some test frameworks (like Rust's Cargo) that
runs unit tests in parallel and would easily encounter this issue,
unless client code gates every call to Notmuch behind a lock.

This is what can be expected from the tests when they fail:
   == stderr ==
  +==================
  +WARNING: ThreadSanitizer: data race (pid=207931)
  +  Read of size 1 at 0x7b10000001a0 by thread T2:
  +    #0 memcpy <null> (libtsan.so.2+0x62506)
  +    #1 void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) [clone .isra.0] <null> (libxapian.so.30+0x872b3)
  +
  +  Previous write of size 8 at 0x7b10000001a0 by thread T1:
  +    #0 operator new(unsigned long) <null> (libtsan.so.2+0x8ba83)
  +    #1 Xapian::Query::Query(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int) <null> (libxapian.so.30+0x855cd)
  ...
2023-03-31 08:11:39 -03:00
Felipe Contreras
4152e1bc20 ruby: database: make path arg optional
It can be automatically loaded from the configuration now.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-03-31 07:56:03 -03:00
Felipe Contreras
83ea220178 ruby: use database_open_with_config
Fixes warning:

  warning: ‘notmuch_database_open’ is deprecated: function deprecated as of libnotmuch 5.4

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2023-03-31 07:53:00 -03:00
Kevin Boulain
a95959c491 test: add test for notmuch_message_remove_all_properties_with_prefix
It wasn't covered, though it shares most of its implementation with
notmuch_message_remove_all_properties.
2023-03-30 08:07:57 -03:00
Kevin Boulain
fb55ff28a2 lib/message-property: sync removed properties to the database
_notmuch_message_remove_all_properties wasn't syncing the message back
to the database but was still invalidating the metadata, giving the
impression the properties had actually been removed.

Also move the metadata invalidation to _notmuch_message_remove_terms
to be closer to what's done in _notmuch_message_modify_property and
_notmuch_message_remove_term.
2023-03-30 08:01:09 -03:00
David Bremner
3363349967 test: reveal notmuch_message_remove_all_properties as broken
Close and re-open the database to show that the removal is not
committed to the database.
2023-03-30 07:56:17 -03:00
Kevin Boulain
e191d3c574 test: reorganize tests and mark a few of them as broken
notmuch_message_remove_all_properties should have removed the
  testkey1 = testvalue1
property but hasn't. Delay the execution of the corresponding test
to avoid updating a few tests that actually relied on the broken
behavior.
2023-03-30 07:49:07 -03:00
Kevin Boulain
552d9ec9f7 test: remove unnecessary sorting
The other tests rely on a stable output.
2023-03-30 07:48:27 -03:00
Kevin Boulain
ce59df5296 test: display key name in property tests
To make the tests a bit easier to understand.
2023-03-30 07:48:19 -03:00
Kevin Boulain
568f6bc3c2 lib/message-property: catch xapian exceptions
Since libnotmuch exposes a C interface there's no way for clients to
catch this.
Inspired by what's done for tags (see notmuch_message_remove_tag).
2023-03-30 07:08:47 -03:00
Kevin Boulain
c810312e24 test: uncaught exception when editing properties of a removed message
These two functions don't fail gracefully when editing a removed
message:
 BROKEN edit property on removed message without uncaught exception
        --- T610-message-property.20.EXPECTED   2023-02-27 11:33:25.792764376 +0000
        +++ T610-message-property.20.OUTPUT     2023-02-27 11:33:25.793764381 +0000
        @@ -1,2 +1,3 @@
         == stdout ==
         == stderr ==
        +terminate called after throwing an instance of 'Xapian::DocNotFoundError'

The other functions appear to be safe.
2023-03-30 07:06:48 -03:00
Kevin Boulain
d86e03c786 lib/notmuch: update example
Likely missed in 86cbd215e, when notmuch_query_search_messages_st was
renamed to notmuch_query_search_messages.
2023-02-27 08:34:38 -04:00
David Bremner
48d774bbf4 emacs/tree: use two argument form of setq-local
Apparently the macro setq-local only takes two arguments in Emacs 26.1
2023-02-21 10:55:42 -04:00
David Bremner
09f2ad8e85 lib: add better diagnostics for over long filenames.
Previously we just crashed with an internal error. With this change,
the caller can handle it better. Update notmuch-new so that it doesn't
crash with "unknown error code" because of this change.
2023-02-20 09:22:32 -04:00
David Bremner
4e6c6c8aac test: add known broken test for diagnostics from over long filenames.
Previously we tested over long directory names, add similar testing
for over long filenames.
2023-02-20 09:22:07 -04:00
jao
f63d14a8c1 emacs: notmuch-tree-outline-mode
With this mode, one can fold trees in the notmuch-tree buffer as if
they were outlines, using all the commands provided by
outline-minor-mode.  We also define a couple of movement commands
that, optional, will ensure that only the thread around point is
unfolded.

The implementation is based on registering a :level property in the
messages p-list, that is then used by outline-minor-mode to to
recognise headers.

Amended by db: Copy docstring to manual and edit for presentation. Add
two tests. Fix typo "wether".
2023-02-20 08:58:32 -04:00
Daniel Kahn Gillmor
db4b48f6cc configure: use pkg-config for gpgme
GnuPG upstream has supported pkg-config since gpgme version 1.13 and
gpg-error 1.33, and now prefers the use of pkg-config by default,
instead of relying on gpg-error-config and gpgme-config.

As of libgpg-error 1.46, upstream deliberately does not ship
gpg-error-config by default.  As of gpgme 1.18.0, upstream does not
ship gpgme-config if gpg-error-config is also not present.

Both of these versions of upstream libraries are in debian unstable
now.  To the extent that notmuch is dependent on GnuPG, it should
follow GnuPG upstream's lead.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2023-01-10 08:29:23 -04:00
David Bremner
f4dc32e71b test: mark some tests as broken when run as root.
File permission errors e.g., are hard to trigger as root.
2023-01-05 20:14:37 -04:00
David Bremner
1d5d0ae686 lib/message: move xapian call inside try/catch block in _n_m_delete
The call to delete_document can throw exceptions (and can happen in
practice [1]), so catch the exception and extract the error
message. As a side effect, also move the call to _n_m_has_term inside
the try/catch. This should not change anything as that function
already traps any Xapian exceptions.

[1]: id:wwuk039sk2p.fsf@chaotikum.eu
2022-12-27 11:59:46 -04:00
David Bremner
966f40086f test: add known broken test for exception handling in _n_m_delete
In [1], Thomas Schneider reported an uncaught Xapian exception when
running out of disk space. We generate the same exception via database
corruption.

[1]: id:wwuk039sk2p.fsf@chaotikum.eu
2022-12-27 11:59:38 -04:00
David Bremner
16d92abf9f lib/database: propagate status code from _notmuch_message_delete
_notmuch_message_delete can return (at least)
NOTMUCH_STATUS_XAPIAN_EXCEPTION, which we should not ignore.
2022-12-27 11:59:29 -04:00
David Bremner
891af1d457 CLI/git: use --exclude=false when calling notmuch-search
We use notmuch search in two places in notmuch-git.py: to find which
tags have a given prefix, and to see if message with given id exists
locally. In both cases we do not want the presence of exclude tags
(e.g. deleted) to change the results.
2022-12-27 11:54:57 -04:00
Michael J Gruber
a5f7efd722 doc: mark --output=summary as default
`notmuch search` behaves differently depending on the output option: It
either outputs information pertaining to all threads with matching
messages (summary, threads) or to all matching messages (messages,
files, tags). The man page refres solely to the former in the main
description.

Help the user by clearly marking `summary` as the default output option.

Signed-off-by: Michael J Gruber <git@grubix.eu>
2022-12-03 09:32:48 -04:00
David Bremner
5ba7684445 emacs/show: use n-s-i-headerline to update tags
Although this has more steps than the previous regular expression
search and replace, it should be more robust against changes in the
headerline format, such as the inclusion of duplicate numbers (which
broke the previous version).
2022-11-15 07:34:25 -04:00
David Bremner
056249627a emacs/show: add optional orig-tags argument to n-s-i-headerline
This will support use of this function in notmuch-show-update-tags.
2022-11-15 07:28:29 -04:00
David Bremner
2b842a1d8c emacs/show: use plist to pass message info to n-s-insert-headerline
This should allow calling notmuch-show-insert-headerline from other
places without duplicating the set of plist accesses.
2022-11-15 07:28:02 -04:00
Russell Sim
82aa1acc0c emacs: move From header addition to after header intern
OTHER-HEADERS are expected to be passed as strings, to match the
implementation of `compose-mail'.  But the "From" header is currently
expected to be passed as a symbol.  Instead the "From" header can be
safely added after converting all the headers to symbols.
2022-11-05 13:30:50 -04:00
Robin Jarry
793f298091 cli: add options --offset and --limit to notmuch show
notmuch search does not output header values. However, when browsing
through a large email corpus, it can be time saving to be able to
paginate without running notmuch show for each message/thread.

Add --offset and --limit options to notmuch show. This is inspired from
commit 796b629c3b ("cli: add options --offset and --limit to notmuch
search").

Update man page, shell completion and add a test case to ensure it works
as expected.

Cc: Tim Culverhouse <tim@timculverhouse.com>
Cc: Tomi Ollila <tomi.ollila@iki.fi>
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-11-05 13:18:15 -04:00