]> git.notmuchmail.org Git - notmuch/log
notmuch
14 years agoFix bit-twiddling brain damage in notmuch_query_search
Carl Worth [Sun, 25 Oct 2009 05:20:13 +0000 (22:20 -0700)]
Fix bit-twiddling brain damage in notmuch_query_search

Here's the big bug that was preventing any searches from working at
all like desired. I did the work to carefully pick out exactly the
flags that I wanted, and then I threw it away by trying to combine
them with & instead of | (so just passing 0 for flags instead).

Much better now.

14 years agoAdd debugging code for examining query strings.
Carl Worth [Sun, 25 Oct 2009 05:18:20 +0000 (22:18 -0700)]
Add debugging code for examining query strings.

It's nice that Xapian provides a little function to print a textual
representation of the entire query tree. So now, if you compile
like so:

make CFLAGS=-DDEBUG_QUERY

then you get a nice output of the query string received by the query
module, and the final query actually being sent to Xapian.

14 years agoAdd a preliminary "notmuch search" command.
Carl Worth [Sun, 25 Oct 2009 05:16:10 +0000 (22:16 -0700)]
Add a preliminary "notmuch search" command.

This isn't behaving at all like it's documented yet, (for example,
it's returning message IDs not thread IDs[*]). In fact, the output
code is just a copy of the body of "notmuch dump", so all you
get for now is message ID and tags.

But this should at least be enough to start exercising the query
functionality, (which is currently very buggy).

[*] I'll want to convert the databse to store thread documents
before fixing that.

14 years agonotmuch_database_create: Document idea to (optionally) return a status
Carl Worth [Sun, 25 Oct 2009 05:14:31 +0000 (22:14 -0700)]
notmuch_database_create: Document idea to (optionally) return a status

The current problem is that when this function fails the caller
doesn't get any information about what the particular failure
was, (something in the filesystem? or in Xapian?). We should fix
that.

14 years agonotmuch setup/new: Propagate failure from notmuch_database_set_timestamp
Carl Worth [Sun, 25 Oct 2009 05:11:38 +0000 (22:11 -0700)]
notmuch setup/new: Propagate failure from notmuch_database_set_timestamp

With some recent testing, the timestamp was failing, (overflowing
the term limit), and reporting an error, but the top-level notmuch
command was still returning a success return value.

I think it's high time to add a test suite, (and the code base is
small enough that if we add it now it shouldn't be *too* hard to
shoot for a very high coverage percentage).

14 years agoFix timestamp generation to avoid overflowing the term limit
Carl Worth [Sun, 25 Oct 2009 05:10:03 +0000 (22:10 -0700)]
Fix timestamp generation to avoid overflowing the term limit

The previous code was only correct as long as the timestamp prefix
was only a single character. But with the recent change to a
multi-character prefix, this broke. So fix it now.

14 years agoTrim down prefix list to things we are actually using.
Carl Worth [Sun, 25 Oct 2009 05:04:59 +0000 (22:04 -0700)]
Trim down prefix list to things we are actually using.

I've decided not to try for sup compatibility at the leve of the
xapian datbase. There's just too much about sup's usage of the
database that I don't like, (beyond the embedded ruby data structures
there is redundant storage of message IDs, thread IDs, and dates (in
both terms and values)).

I'm going to fix that up in the database of notmuch, with some other
changes as well. (I plan to drop "reference" terms once linkage to a
thread ID through the reference is established.  I also plan to add
actual documents to represent threads.)

So with all that incompatibility, I might as well make my own prefix
values. And while doing that, I should try to be as compatible as
possible with the conventions described here:

http://xapian.org/docs/omega/termprefixes.html

14 years agoMove the prefix-string arrays back into database.cc from message.cc
Carl Worth [Sun, 25 Oct 2009 04:52:48 +0000 (21:52 -0700)]
Move the prefix-string arrays back into database.cc from message.cc

Yes, I'm being wishy-washy here, moving code back and forth. But
this is where these really do belong.

14 years agoRevert "Remove some unneeded initializers."
Carl Worth [Sat, 24 Oct 2009 15:06:23 +0000 (08:06 -0700)]
Revert "Remove some unneeded initializers."

This reverts commit fb1bae07002d45138832eacb280419dbd7a19774.

These initializers were totally necessary. I clearly wasn't
thinking straight when I removed them.

14 years agoCut the enthusiasm a bit.
Carl Worth [Sat, 24 Oct 2009 00:25:23 +0000 (17:25 -0700)]
Cut the enthusiasm a bit.

It gets annoying pretty quick.

14 years agoMake "notmuch new" ignore directories that are read-only.
Carl Worth [Sat, 24 Oct 2009 00:20:43 +0000 (17:20 -0700)]
Make "notmuch new" ignore directories that are read-only.

With this, "notmuch new" is now plenty fast even with large archives
spanning many sub-directories. Document this both in "notmuch help"
and also in the output of notmuch setup.

14 years agoadd_files: Pull one stat out of the recrusive function.
Carl Worth [Fri, 23 Oct 2009 23:19:35 +0000 (16:19 -0700)]
add_files: Pull one stat out of the recrusive function.

There's no need to stat each directory both before and after each
recursive call.

14 years agoMore fixing of plurals.
Carl Worth [Fri, 23 Oct 2009 23:00:24 +0000 (16:00 -0700)]
More fixing of plurals.

It definitely doesn't help that we have the same messages in both
"setup" and "new". Should combine those really.

14 years agoMore care in final status reporting.
Carl Worth [Fri, 23 Oct 2009 22:57:39 +0000 (15:57 -0700)]
More care in final status reporting.

Printing "Added 1 new messages" just looks like lack of attention
to detail, (but yes plurals can be annoying this way).

14 years agoPrint a better message than "0s" for zero seconds.
Carl Worth [Fri, 23 Oct 2009 22:50:48 +0000 (15:50 -0700)]
Print a better message than "0s" for zero seconds.

It's nice to have a tool that at least construct actual sentences.

14 years agoAdd new "notmuch new" command.
Carl Worth [Fri, 23 Oct 2009 22:48:05 +0000 (15:48 -0700)]
Add new "notmuch new" command.

Finally, I can get new messages into my notmuch database without
having to run a complete "notmuch setup" again. This takes
advantage of the recent timestamp capabilities in the database
to avoid looking into directories that haven't changed since the
last time "notmuch new" was run.

14 years agoadd_files: Change to return a status value instead of void
Carl Worth [Fri, 23 Oct 2009 22:39:11 +0000 (15:39 -0700)]
add_files: Change to return a status value instead of void

Also change to use goto rather than early returns. And once again,
there were lots of bugs in the error cases previously.

14 years agonotmuch setup: Clean up the progress printing a bit.
Carl Worth [Fri, 23 Oct 2009 22:22:14 +0000 (15:22 -0700)]
notmuch setup: Clean up the progress printing a bit.

Get rid of a useless leading 0 on the seconds value, and make a
distinction between "files" and "messages", (we process many
files, but not all of them are recongized as messages). Finally,
add a summary line at the end saying how many unique messages
were added to the database. Since this comes right after the
total number of files, it gives the user at least a hint as
to how many messages were encountered with duplicate message IDs.

14 years agoRe-order documentation a bit.
Carl Worth [Fri, 23 Oct 2009 22:17:16 +0000 (15:17 -0700)]
Re-order documentation a bit.

The notmuch_database_get_default_path function is unique in not
accepting a notmuch_database_t* (nor creating one). So list it
outside the other notmuch_database functions.

14 years agonotmuch_message_get_filename: Improve documentation.
Carl Worth [Fri, 23 Oct 2009 22:12:03 +0000 (15:12 -0700)]
notmuch_message_get_filename: Improve documentation.

Fix a typo, and add clarifications about the lifetime and readonly
nature of the return value.

14 years agoRemove some unneeded initializers.
Carl Worth [Fri, 23 Oct 2009 21:55:50 +0000 (14:55 -0700)]
Remove some unneeded initializers.

Some people might argue for more initializers to be "safer",
but I actually prefer to leave things this way. It saves
typing, but the real benefit is that the things that do
require initialization stand out so we know to watch them
carefully. And with valgrind, we actually get to catch
errors earlier if we *don't* initialize them. So that can
be "safer" ironically enough.

14 years agonotmuch setup: Fix a couple of error paths.
Carl Worth [Fri, 23 Oct 2009 21:55:02 +0000 (14:55 -0700)]
notmuch setup: Fix a couple of error paths.

We had early returns instead of goto statments, and sure enough,
they were leaking. Much cleaner this way.

14 years ago_find_prefix: Exit when given an invalid prefix name.
Carl Worth [Fri, 23 Oct 2009 21:45:33 +0000 (14:45 -0700)]
_find_prefix: Exit when given an invalid prefix name.

This will be a nice safety check for internal sanity.

14 years agoAdd NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID
Carl Worth [Fri, 23 Oct 2009 21:40:33 +0000 (14:40 -0700)]
Add NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID

And document that notmuch_database_add_message can return this
value. This pushes the hard decision of what to do with duplicate
messages out to the user, but that's OK. (We weren't really doing
anything with these ourselves, and this way the user is at least
informed of the issue, rather than it just getting papered over
internally.)

14 years agoClean up comments to not include spaces before tabs.
Carl Worth [Fri, 23 Oct 2009 21:37:09 +0000 (14:37 -0700)]
Clean up comments to not include spaces before tabs.

This were just unclean, (an invisble sort of uncleanliness, but still
there are liable to make for ugly diffs). Oh, wait, like this one!
But at least it's not sprinkled among code changes.

14 years agoClarify documentation and error string for NOTMUCH_STATUS_TAG_TOO_LONG
Carl Worth [Fri, 23 Oct 2009 21:34:21 +0000 (14:34 -0700)]
Clarify documentation and error string for NOTMUCH_STATUS_TAG_TOO_LONG

It's helpful to point out NOTMUCH_STATUS_TAG_MAX for users.

14 years agoAdd notmuch_database_set_timestamp and notmuch_database_get_timestamp
Carl Worth [Fri, 23 Oct 2009 21:31:01 +0000 (14:31 -0700)]
Add notmuch_database_set_timestamp and notmuch_database_get_timestamp

These will be very helpful to implement an efficient "notmuch new"
command which imports new mail messages that have appeared.

14 years agodatabase: Add private find_unique_doc_id and find_unique_document functions
Carl Worth [Fri, 23 Oct 2009 21:24:07 +0000 (14:24 -0700)]
database: Add private find_unique_doc_id and find_unique_document functions

These are a generalization of the unique-ness testing of
notmuch_database_find_message. More preparation for
firectory timestamps.

14 years agodatabase: Similarly rename find_message_by_docid to find_document_for_doc_id
Carl Worth [Fri, 23 Oct 2009 21:12:06 +0000 (14:12 -0700)]
database: Similarly rename find_message_by_docid to find_document_for_doc_id

Again preferring notmuch_database_t* over Xapian::Database*.

Also, we're standardizing on "doc_id" rather than "docid" locally, (as
an analoge to "message_id"), in spite of the "Xapian::docid" name,
(which, fortunately, we can ignore and just us "unsigned int" instead).

14 years agodatabase: Rename internal find_messages_by_term to find_doc_ids
Carl Worth [Fri, 23 Oct 2009 21:06:24 +0000 (14:06 -0700)]
database: Rename internal find_messages_by_term to find_doc_ids

This name is a more accurate description of what it does, and
the more general naming will make sense as we start storing
non-message documents in the database (such as directory
timestamps).

Also, don't pass around a Xapian::Database where it's more our
style to pass a notmuch_database_t*.

14 years agosha1: Add new notmuch_sha1_of_string function
Carl Worth [Fri, 23 Oct 2009 20:54:53 +0000 (13:54 -0700)]
sha1: Add new notmuch_sha1_of_string function

We'll be using this for storing really long terms in the database
and when we just need to look them up, (and never read back the
original data directly from the database). For example, storing
arbitrarily long directory paths in the database along with
mtime timestamps.

Note that if we did want to store arbitrarily long terms and also
be able to read them back, the Xapian folks recommending splitting
the term off with multiple prefixes. See the note near the end
of this page:

http://trac.xapian.org/wiki/FAQ/UniqueIds

14 years agonotmuch restore: Print names of tags that cannot be applied
Carl Worth [Fri, 23 Oct 2009 13:08:22 +0000 (06:08 -0700)]
notmuch restore: Print names of tags that cannot be applied

This helps the user gauge the severity of the error.

For example, when restoring my sup tags I see a bunch of tags missing
for message IDs of the form "sup-faked-...". That's not surprising
since I know that sup generates these with the md5sum of the message
header while notmuch uses the sha-1 of the entire message. But how
much will this hurt?

Well, now that I can see that most of the missing tags are just
"attachment", then I'm not concerned, (I'll be automatically creating
that tag in the future based on the message contents). But if a
missing tag is "inbox" then that's more concerning because that's data
that I can't easily regenerate outside of sup.

14 years agonotmuch_tags_has_more: Fix to use string.empty rather than string.size
Carl Worth [Fri, 23 Oct 2009 13:06:20 +0000 (06:06 -0700)]
notmuch_tags_has_more: Fix to use string.empty rather than string.size

I'm really interested in the length of the data here, not the size
of the storage.

14 years agoFix notmuch_message_get_message_id to never return NULL.
Carl Worth [Fri, 23 Oct 2009 13:04:57 +0000 (06:04 -0700)]
Fix notmuch_message_get_message_id to never return NULL.

With the recent improvements to the handling of message IDs we
"know" that a NULL message ID is impossible, (so we simply
abort if the impossible happens).

14 years agoadd_message: Fix to not add multiple documents with the same message ID
Carl Worth [Fri, 23 Oct 2009 13:00:10 +0000 (06:00 -0700)]
add_message: Fix to not add multiple documents with the same message ID

Here's the second big fix to message-ID handling, (the first was to
generate message IDs when an email contained none). Now, with no
document missing a message ID, and no two documents having the same
message ID, we have a nice consistent database where the message ID
can be used as a unique key.

14 years agoAdd _notmuch_message_create_for_message_id
Carl Worth [Fri, 23 Oct 2009 12:53:52 +0000 (05:53 -0700)]
Add _notmuch_message_create_for_message_id

This is the last piece needed for add_message to be able to properly
support a message with a duplicate message ID.  This function creates
a new notmuch_message_t object but one that may reference an existing
document in the database.

14 years agoFix _notmuch_message_create to catch Xapian DocNotFoundError.
Carl Worth [Fri, 23 Oct 2009 12:45:29 +0000 (05:45 -0700)]
Fix _notmuch_message_create to catch Xapian DocNotFoundError.

This function is only supposed to be called with a doc_id that
was queried from the database already. So there's an internal
error if no document with that doc_id can be found in the database.

In that case, return NULL.

14 years agoAdd internal functions for manipulating a new notmuch_message_t
Carl Worth [Fri, 23 Oct 2009 12:41:17 +0000 (05:41 -0700)]
Add internal functions for manipulating a new notmuch_message_t

This will support the add_message function in incrementally creating
state in a new notmuch_message_t. The new functions are

      _notmuch_message_set_filename
      _notmuch_message_add_thread_id
      _notmuch_message_ensure_thread_id
      _notmuch_message_set_date
      _notmuch_message_sync

14 years agoAdd notmuch_message_get_filename
Carl Worth [Fri, 23 Oct 2009 12:38:13 +0000 (05:38 -0700)]
Add notmuch_message_get_filename

This is a new public function to find the filename of the original
email message for a message-object that was found in the database.

We may change this function in the future to support returning a
list of filenames, (for messages with duplicate message IDs).

14 years agoadd_message: Re-order the code a bit (find message-id first).
Carl Worth [Fri, 23 Oct 2009 12:30:37 +0000 (05:30 -0700)]
add_message: Re-order the code a bit (find message-id first).

We're preparing for being able to deal with files with duplicate
message IDs here. The plan is to create a notmuch_message_t object in
add_message that may or may not reference a document that exists in
the database. So to do this, we have to find the message ID before we
do any manipulation of the doc.

14 years agoMove thread_id generation code from database.cc to message.cc
Carl Worth [Fri, 23 Oct 2009 12:25:58 +0000 (05:25 -0700)]
Move thread_id generation code from database.cc to message.cc

It's really up to the message to decide how to generate these.

14 years agoMove the _notmuch_message_sync from private to public interfaces
Carl Worth [Fri, 23 Oct 2009 12:18:35 +0000 (05:18 -0700)]
Move the _notmuch_message_sync from private to public interfaces

The idea here is to allow internal users to see a non-synced message
object, (for example, while parsing a message file and incrementally
adding terms, etc.). We're willing to take the care to get the
improved performance.

But for the public interface, keeping everything synced will be much
less confusing, (reference lots of sup bugs that happen due to
message state being altered by the user but not synced to the database).

14 years agoadd_message: Rename message to message_file
Carl Worth [Fri, 23 Oct 2009 12:13:42 +0000 (05:13 -0700)]
add_message: Rename message to message_file

I still don't like the name message_file at all, but we're about
to start using a notmuch_message_t in this function so we need
to do something to keep the identifiers separate for now.

Eventually, it probably makes sense to push the message-parsing
code from database.cc to message.cc.

14 years agoPrevent that last bug from reoccurring.
Carl Worth [Thu, 22 Oct 2009 22:46:22 +0000 (15:46 -0700)]
Prevent that last bug from reoccurring.

It's even enough to check if a "missing" header was accidentally
left off the list in the call to restrict_headers. (And it's
cheap since we only check in case no such header was found in the
message.)

14 years agoDon't forget the "to" header when restrict parsing to certain headers
Carl Worth [Thu, 22 Oct 2009 22:34:47 +0000 (15:34 -0700)]
Don't forget the "to" header when restrict parsing to certain headers

We recently started discarding files as "not email" if they have none
of Subject, From, nor To. Apaprently, my mail collection contains a
number of messages that I sent, that are saved without Subject and
From, (perhaps these were drafts?).

Anyway, it's fortunate I had those since they alerted me to this bug,
where we were not parsing the "To" header in some cases.

14 years agoFix missing error check.
Carl Worth [Thu, 22 Oct 2009 22:33:56 +0000 (15:33 -0700)]
Fix missing error check.

The notmuch_message_file_open function is perfectly capable of
returning NULL. So check for it.

14 years agoGenerate message ID (using SHA1) when a mail message contains none.
Carl Worth [Thu, 22 Oct 2009 22:31:56 +0000 (15:31 -0700)]
Generate message ID (using SHA1) when a mail message contains none.

This is important as we're using the message ID as the unique key
in our database. So previously, all messages with no message ID
would be treated as the same message---not good at all.

14 years agoRename sha1.c to libsha1.c
Carl Worth [Thu, 22 Oct 2009 06:25:58 +0000 (23:25 -0700)]
Rename sha1.c to libsha1.c

This way both the .c and .h files have the same name, and all of the
code imported from the "libsha1" implementation is in filenames
matching libsha1.*.

This also gives me room to make my own notmuch_sha1 wrapper functions
in sha1.c.

14 years agoMerge branch from fixing up bugs after bisecting.
Carl Worth [Thu, 22 Oct 2009 06:23:32 +0000 (23:23 -0700)]
Merge branch from fixing up bugs after bisecting.

I'm glad that when I implemented "notmuch restore" I went through the
extra effort to take the code I had written in one sitting into over a
dozen commits. Sure enough, I hadn't tested well enough and had
totally broken "notmuch setup", (segfaults and bogus thread_id
values).

With the little commits I had made, git bisect saved the day, and I
went back to make the fixes right on top of the commits that
introduced the bugs. So now we octopus merge those in.

14 years agoBring back the insert_thread_id function.
Carl Worth [Thu, 22 Oct 2009 06:10:19 +0000 (23:10 -0700)]
Bring back the insert_thread_id function.

We deleted this in favor of our fancy new thread_ids iterator
from the message object. But one of the previous callers of
insert_thread_id isn't using notmuch_message_t yet. I made
the mistake of thinking I could just call g_hash_table_insert
directly, but the problem was that nobody was splitting
up the thread_id string at its commas.

So with this, we were inserting bogus comma-separated IDs
into the hash table, so thread_id values were ballooning
out of control. Should be much better now.

14 years agoFix lifetime-maintenance bug with std::string and c_str()
Carl Worth [Thu, 22 Oct 2009 06:01:17 +0000 (23:01 -0700)]
Fix lifetime-maintenance bug with std::string and c_str()

Here's more evidence that C++ is a nightmare to program---or that
I'm smart enough to realize that C++ is more clever than I will
ever be.

Most of my issues with C++ have to do with it hiding things from
me that I'd really like to and expect to be aware of as a C
programmer.

For example, the specific problem here is that there's a
short-lived std::string, from which I just want to copy
the C string. I try to do that on the next line, but before
I can, C++ has already called the destructor on the std::string.

Now, C++ isn't alone in doing garbage collecting like this.
But in a *real* garbage-collecting system, everything would
work that way. For example, here, I'm still holding a pointer
to the C string contents, so if the garbage collector were
aware of that reference, then it might clean up the std::string
container and leave the data I'm still using.

But that's not what we get with C++. Instead, some things are
reference counted and collected, (like the std::string), and
some things just aren't (like the C string it contains). The
end result is that it's very fragile. It forces me to be aware
of the timing of hidden functions. In a "real" system I wouldn't
have to be aware of that timing, and in C the function just
wouldn't be hidden.

14 years agoList a few more co-conspirators.
Carl Worth [Thu, 22 Oct 2009 04:29:18 +0000 (21:29 -0700)]
List a few more co-conspirators.

Keith's name already shows up in the git log, so it would be
wrong to not mention him. And Martin and Jamey have been
helpful in discussions about what an ideal mail system
would look like.

14 years agoAdd an AUTHORS file.
Carl Worth [Thu, 22 Oct 2009 04:26:01 +0000 (21:26 -0700)]
Add an AUTHORS file.

Now that I've copied in another source file from someone else, I
want to be sure I'm keeping a good list of everyone who has helped.

14 years agoAdd sha1.c and libsha1.h for doing SHA-1-based message-ID generation.
Mikhail Gusarov [Thu, 22 Oct 2009 04:07:43 +0000 (21:07 -0700)]
Add sha1.c and libsha1.h for doing SHA-1-based message-ID generation.

This code comes courtesy of Brian Gladman and Mikhail Gusarov.

Both files are available under the GPL and were downloaded as
version 0.2 of libsha1 from git://github.com/dottedmag/libsha1.git
with the following commit:

commit d0f0e7e0dc5ce2d58972cb5a492183c0d4e58433
Author: Mikhail Gusarov <dottedmag@dottedmag.net>
Date:   Mon Oct 20 22:38:47 2008 +0700

    Version bump.

Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
14 years agoAdd copy of GNU General Public License (version 3).
Carl Worth [Wed, 21 Oct 2009 23:25:08 +0000 (16:25 -0700)]
Add copy of GNU General Public License (version 3).

All the files were already advertising the license, but we didn't
actually have a copy of the license in the repository until now.

14 years agoAdd notmuch_status_to_string function.
Carl Worth [Wed, 21 Oct 2009 23:12:53 +0000 (16:12 -0700)]
Add notmuch_status_to_string function.

Be kind and let the user print error messages, not just error
codes.

14 years agoImplement "notmuch restore".
Carl Worth [Wed, 21 Oct 2009 23:03:03 +0000 (16:03 -0700)]
Implement "notmuch restore".

It's pretty easy to do with all the right infrastructure in place.
Now that I can get my tags from sup to notmuch, maybe I'll be able
to start reading mail again.

14 years agoPull out a chomp_newline function from "notmuch setup"
Carl Worth [Wed, 21 Oct 2009 22:59:11 +0000 (15:59 -0700)]
Pull out a chomp_newline function from "notmuch setup"

We'll want this same thing with "notmuch restore", (and really
anything using getline).

14 years agoAdd notmuch_message_add_tag and notmuch_message_remove_tag
Carl Worth [Wed, 21 Oct 2009 22:53:38 +0000 (15:53 -0700)]
Add notmuch_message_add_tag and notmuch_message_remove_tag

With these two added, we now have enough functionality in the
library to implement "notmuch restore".

14 years agonotmuch-private.h: Move NOTMUCH_BEGIN_DECLS earlier
Carl Worth [Wed, 21 Oct 2009 22:51:13 +0000 (15:51 -0700)]
notmuch-private.h: Move NOTMUCH_BEGIN_DECLS earlier

We actually need this before the include of xutil.h, but
it was previously stuck randomly among various system
includes. Instead, put it at the top, right after include
the notmuch.h header that defines it.

14 years agonotmuch_query_search: Clarify the documentation.
Carl Worth [Wed, 21 Oct 2009 22:46:46 +0000 (15:46 -0700)]
notmuch_query_search: Clarify the documentation.

This is where we wanted to put the note to recommend the user
call notmuch_message_destroy if the lifetime of the message
is much shorter than the lifetime of the query. (Somehow this
had ended up in the documentation of notmuch_message_get_tags
before.)

14 years agonotmuch.h: Fix some copy-paste errors in the documentaton.
Carl Worth [Wed, 21 Oct 2009 22:45:34 +0000 (15:45 -0700)]
notmuch.h: Fix some copy-paste errors in the documentaton.

In several places we had "results" where "tags" was intended.
It actually read fine in some cases, but this is still better.

14 years agonotmuch_message_get_message_id: Fix to cache result
Carl Worth [Wed, 21 Oct 2009 22:42:54 +0000 (15:42 -0700)]
notmuch_message_get_message_id: Fix to cache result

Previously, this would allocate new memory with every call. That
was with talloc, of course, so there wasn't any leaking (eventually).
But since we're now calling this internally we want to be a little
less wasteful. It's easy enough to just stash the result into the
message on the first call, and then just return that on subsequent
calls.

14 years agodatabase: Add new notmuch_database_find_message
Carl Worth [Wed, 21 Oct 2009 22:37:51 +0000 (15:37 -0700)]
database: Add new notmuch_database_find_message

With this function, and the recently added support for
notmuch_message_get_thread_ids, we now recode the find_thread_ids
function to work just the way we expect a user of the public
notmuch API to work. Not too bad really.

14 years agoAdd notmuch_message_get_thread_ids function
Carl Worth [Wed, 21 Oct 2009 22:23:08 +0000 (15:23 -0700)]
Add notmuch_message_get_thread_ids function

Along with all of the notmuch_thread_ids_t iterator functions.
Using a consistent idiom seems better here rather than returning
a comma-separated string and forcing the user to parse it.

14 years agoAdd wrappers for regcomp and regexec to xutil.c.
Carl Worth [Wed, 21 Oct 2009 22:06:52 +0000 (15:06 -0700)]
Add wrappers for regcomp and regexec to xutil.c.

These will be handy for some parsing.

14 years agoRename NOTMUCH_MAX_TERM to NOTMUCH_TERM_MAX
Carl Worth [Wed, 21 Oct 2009 21:10:00 +0000 (14:10 -0700)]
Rename NOTMUCH_MAX_TERM to NOTMUCH_TERM_MAX

Just better consistency with our naming schemes.

14 years agoMove find_prefix function from database.cc to message.cc
Carl Worth [Wed, 21 Oct 2009 21:07:40 +0000 (14:07 -0700)]
Move find_prefix function from database.cc to message.cc

It's definitely a better fit there for now, (and can likely
eventually be made static as add_term moves from database
to message as well).

14 years agonotmuch dump: Fix to print spaces between tags.
Carl Worth [Wed, 21 Oct 2009 21:02:51 +0000 (14:02 -0700)]
notmuch dump: Fix to print spaces between tags.

Simple little bug here made all the tags run together.

14 years agoConvert notmuch_database_t to start using talloc.
Carl Worth [Wed, 21 Oct 2009 21:00:37 +0000 (14:00 -0700)]
Convert notmuch_database_t to start using talloc.

This will be handy as we can hang future talloc allocations off
of the datbase now.

14 years agoMove declarations for xutil.c from notmuch-private to new xutil.h.
Carl Worth [Wed, 21 Oct 2009 20:57:02 +0000 (13:57 -0700)]
Move declarations for xutil.c from notmuch-private to new xutil.h.

The motivation here is that our top-level notmuch.c main program
wants to start using these, but we don't want it to see into
notmuch-private.h, (since our main program is a test vehicle
for the "public" notmuch interface in notmuch.h).

14 years agonotmuch dump: Fix buffer overrun in error message.
Carl Worth [Wed, 21 Oct 2009 17:12:11 +0000 (10:12 -0700)]
notmuch dump: Fix buffer overrun in error message.

Just a little bug I noticed while editing nearby code.

14 years agonotmuch setup: Collapse internal whitespace within message-id
Carl Worth [Wed, 21 Oct 2009 17:07:34 +0000 (10:07 -0700)]
notmuch setup: Collapse internal whitespace within message-id

I'm too lazy to see what the RFC says, but I know that having
whitespace inside a message-ID is sure to confuse things. And
besides, this makes things more compatible with sup so that
I have some hope of importing sup labels.

14 years agonotmuch dump: Fix the sorting of results.
Carl Worth [Wed, 21 Oct 2009 07:35:56 +0000 (00:35 -0700)]
notmuch dump: Fix the sorting of results.

To properly support sorting in notmuch_query we know use an
Enquire object. We also throw in a QueryParser too, so we're
really close to being able to support arbitrary full-text
searches.

I took a look at the supported QueryParser syntax and chose
a set of flags for everything I like, (such as supporting
Boolean operators in either case ("AND" or "and"), supporting
phrase searching, supporting + and - to include/preclude terms,
and supporting a trailing * on any term as a wildcard).

14 years agoadd_message: Add a type:mail ("Kmail") term to all documents.
Carl Worth [Wed, 21 Oct 2009 07:34:36 +0000 (00:34 -0700)]
add_message: Add a type:mail ("Kmail") term to all documents.

This gives us an easy way to specify "all mail messages" in a search
query. We simply look for this term.

14 years agonotmuch setup: Print a few protecting spaces after progress reports.
Carl Worth [Wed, 21 Oct 2009 07:32:30 +0000 (00:32 -0700)]
notmuch setup: Print a few protecting spaces after progress reports.

This is to help keep the report looking clean when a new report
is shorter than a previous reports, (say, when crossing the
boundary from over one minute remaining to less than one minute
remaining).

This used to be here, but I must have accidentally dropped it
when reformatting the progress report recently.

14 years ago.gitignore: Ignore generated file Makefile.dep
Carl Worth [Wed, 21 Oct 2009 06:13:28 +0000 (23:13 -0700)]
.gitignore: Ignore generated file Makefile.dep

Forgot to add this when I first add dependency checking to the
Makefile.

14 years agodatabase: Remove two little bits of dead code.
Carl Worth [Wed, 21 Oct 2009 06:12:53 +0000 (23:12 -0700)]
database: Remove two little bits of dead code.

14 years agoquery: Remove the magic NOTMUCH_QUERY_ALL
Carl Worth [Wed, 21 Oct 2009 05:40:37 +0000 (22:40 -0700)]
query: Remove the magic NOTMUCH_QUERY_ALL

Using the address of a static char* was clever, but really
unnecessary. An empty string is much less magic, and even
easier to understand as the way to query everything from
the database.

14 years agonotmuch dump: Free each message as it's used.
Carl Worth [Wed, 21 Oct 2009 05:27:56 +0000 (22:27 -0700)]
notmuch dump: Free each message as it's used.

Previously we were leaking[*] memory in that the memory footprint of
a "notmuch dump" run would continue to grow until the output was
complete, and then finally all the memory would be freed.

Now, the memory footprint is small and constant, O(1) rather than
O(n) in the number of messages.

[*] Not leaking in a valgrind sense---every byte was still carefully
being accounted for and freed eventually.

14 years agoAdd destroy functions for results, message, and tags.
Carl Worth [Wed, 21 Oct 2009 05:24:59 +0000 (22:24 -0700)]
Add destroy functions for results, message, and tags.

None of these are strictly necessary, (everything was leak-free
without them), but notmuch_message_destroy can actually be useful
for when one query has many message results, but only one is needed
to be live at a time.

The destroy functions for results and tags are fairly gratuitous, as
there's unlikely to be any benefit from calling them. But they're all
easy to add, (all of these functions are just wrappers for talloc_free),
and we do so for consistency and completeness.

14 years agoRename our talloc destructor functions to _destructor.
Carl Worth [Wed, 21 Oct 2009 05:08:31 +0000 (22:08 -0700)]
Rename our talloc destructor functions to _destructor.

I want to reserve the _destroy names for some public functions
I'm about to add.

14 years agoImplement 'notmuch dump'.
Carl Worth [Wed, 21 Oct 2009 04:03:30 +0000 (21:03 -0700)]
Implement 'notmuch dump'.

This is a fairly big milestone for notmuch. It's our first command
to do anything besides building the index, so it proves we can
actually read valid results out from the index.

It also puts in place almost all of the API and infrastructure we
will need to allow searching of the database.

Finally, with this change we are now using talloc inside of notmuch
which is truly a delight to use. And now that I figured out how
to use C++ objects with talloc allocation, (it requires grotty
parts of C++ such as "placement new" and "explicit destructors"),
we are valgrind-clean for "notmuch dump", (as in "no leaks are
possible").

14 years agoRename private notmuch_message_t to notmuch_message_file_t
Carl Worth [Tue, 20 Oct 2009 22:09:51 +0000 (15:09 -0700)]
Rename private notmuch_message_t to notmuch_message_file_t

This is in preparation for a new, public notmuch_message_t.

Eventually, the public notmuch_message_t is going to grow enough
features to need to be file-backed and will likely need everything
that's now in message-file.c. So we may fold these back into one
object/implementation in the future.

14 years agoMakefile: Add automatic dependency tracking to the Makefile.
Carl Worth [Tue, 20 Oct 2009 22:08:03 +0000 (15:08 -0700)]
Makefile: Add automatic dependency tracking to the Makefile.

With this, I really don't miss anything from automake.

14 years agonotmuch: Fix setup so that accepting the default mail path works.
Carl Worth [Tue, 20 Oct 2009 20:16:16 +0000 (13:16 -0700)]
notmuch: Fix setup so that accepting the default mail path works.

The recent change from GIOChannel to getline, (with a semantic
change of the newline terminator now being included in the
result that setup_command sees), broke this.

14 years agomessage: Use g_hash_table_destroy instead of g_hash_table_unref
Carl Worth [Tue, 20 Oct 2009 20:07:19 +0000 (13:07 -0700)]
message: Use g_hash_table_destroy instead of g_hash_table_unref

I'm trying to chase down 3 still-reachable pointers to glib hash
tables.

This change didn't help with that, but I think destroy might be a
better semantic match for what I actually want. (It shouldn't matter
though since I never take any additional references.)

14 years agoadd_message: Fix memory leak of thread_ids GPtrArray.
Carl Worth [Tue, 20 Oct 2009 20:05:45 +0000 (13:05 -0700)]
add_message: Fix memory leak of thread_ids GPtrArray.

We were properly feeing this memory when the thread-ids list was not
empty, but leaking it when it was.

Thanks, of course, to valgrind along with the G_SLICE=always-malloc
environment variable which makes leak checking with glib almost
bearable.

14 years agodatabase.cc: Document better pieces of glib that we're using.
Carl Worth [Tue, 20 Oct 2009 19:49:32 +0000 (12:49 -0700)]
database.cc: Document better pieces of glib that we're using.

14 years agomessage.c: Free leaked memory in notmuch_message object
Carl Worth [Tue, 20 Oct 2009 19:48:14 +0000 (12:48 -0700)]
message.c: Free leaked memory in notmuch_message object

We were careful to free this memory when we finished parsing the
headers, but we missed it for the case of closing the message
without ever parsing all of the headers.

14 years agonotmuch: Use GNU libc getline() instead of glib GIOChannel
Carl Worth [Tue, 20 Oct 2009 19:47:23 +0000 (12:47 -0700)]
notmuch: Use GNU libc getline() instead of glib GIOChannel

Less reliance on glib is always nice for our memory-leak testing
efforts.

14 years agonotmuch_database_open: Fix error message for file-not-found.
Carl Worth [Tue, 20 Oct 2009 17:14:00 +0000 (10:14 -0700)]
notmuch_database_open: Fix error message for file-not-found.

I was incorrectly using the return value of stat (-1) instead of
errno (ENOENT) to try to construct the error message here.

Also, while we're here, reword the error message to not have
"stat" in it, which in spite of what a Unix programmer will
tell you, is not actually a word.

14 years agoAdd some explanation about NOTMUCH_BASE to setup_command.
Carl Worth [Tue, 20 Oct 2009 17:07:11 +0000 (10:07 -0700)]
Add some explanation about NOTMUCH_BASE to setup_command.

Since we allow the user to enter a custom directory, we need to
let the user know how to make this persistent. Of course, a better
answer would be to take what the user entered and shove it into
a ~/.notmuch-config file or so, but for now this will have to do.

14 years agonotmuch_database_create/open: Fix to handle NULL as documented.
Carl Worth [Tue, 20 Oct 2009 16:56:25 +0000 (09:56 -0700)]
notmuch_database_create/open: Fix to handle NULL as documented.

When documenting these functions I described support for a
NOTMUCH_BASE environment variable to be consulted in the case
of a NULL path. Only, I had forgotten to actually write the
code.

This code exists now, with a new, exported function:

     notmuch_database_default_path

14 years agonotmuch_message_get_header: Fix bogus return of NULL header.
Carl Worth [Tue, 20 Oct 2009 16:52:01 +0000 (09:52 -0700)]
notmuch_message_get_header: Fix bogus return of NULL header.

A simple bug meant that the correct value was being inserted into
the hash table, but a NULL value would be returned in some cases.
(If the value was already in the hash table at the beginning of
the call the the correct value would be returned, but if the
function had to parse to reach it then it would return NULL.)

This was tripping up the recently-added code to ignore messages
with NULL From:, Subject:, and To: headers, (which is fortunate
since otherwise the broken parsing might have stayed hidden for
longer).

14 years agonotmuch: Revamp help message a bit.
Carl Worth [Tue, 20 Oct 2009 06:41:31 +0000 (23:41 -0700)]
notmuch: Revamp help message a bit.

The big update here is the addition of the dump and restore commands
which are next on my list. Also, I've now come up with a syntax for
documenting the arguments of sub-commands.

14 years agonotmuch: Ignore files that don't look like email messages.
Carl Worth [Tue, 20 Oct 2009 06:08:49 +0000 (23:08 -0700)]
notmuch: Ignore files that don't look like email messages.

This is helpful for things like indexes that other mail programs
may have left around. It also means we can make the initial
instructions much easier, (the user need not worry about moving
away auxiliary files from some other email program).

14 years agoProtect definition of _GNU_SOURCE.
Carl Worth [Tue, 20 Oct 2009 05:34:59 +0000 (22:34 -0700)]
Protect definition of _GNU_SOURCE.

I was getting a duplicate definition of this from somewhere, so
getting compiler warnings without this protection.

14 years agoRemove test programs, xapian-dump and notmuch-index-message
Carl Worth [Tue, 20 Oct 2009 05:24:28 +0000 (22:24 -0700)]
Remove test programs, xapian-dump and notmuch-index-message

These were just little tests while getting comfortable with
GMime and xapian. I'll likely use pieces of these as notmuch
continues, but for now let's not distract anyone looking
at notmuch with these.

And the code will live on in the history if I need to look
at it.

14 years agonotmuch: Reword the progress report slightly.
Carl Worth [Tue, 20 Oct 2009 01:30:48 +0000 (18:30 -0700)]
notmuch: Reword the progress report slightly.

I noticed this style during a recent Debian install and I liked
how much less busy it is compared to what we had before, (while
still telling the user everything she might want).