Commit graph

147 commits

Author SHA1 Message Date
Carl Worth
3dce200788 tags: Re-implement tags iterator to avoid having C++ in the interface
We want to be able to iterate over tags stored in various ways, so
the previous TermIterator-based tags object just wasn't general
enough. The new interface is nice and simple, and involves only
C datatypes.
2009-10-26 14:02:51 -07:00
Carl Worth
46ba33b115 notmuch restore: Fix leak of FILE* object.
Apparently, I didn't copy enough of the "notmuch dump" implementation
since it didn't have a similar leak.
2009-10-26 13:36:40 -07:00
Carl Worth
1ba3d46fab Add an initial implementation of a notmuch_thread_t object.
We've now got a new notmuch_query_search_threads and a
notmuch_threads_result_t iterator. The thread object itself
doesn't do much yet, (just allows one to get the thread_id),
but that's at least enough to see that "notmuch search" is
actually doing something now, (since it has been converted
to print thread IDs instead of message IDs).

And maybe that's all we need. Getting the messages belonging
to a thread is as simple as a notmuch_query_search_messages
with a string of "thread:<thread-id>".

Though it would be convenient to add notmuch_thread_get_messages
which could use the existing notmuch_message_results_t iterator.

Now we just need an implementation of "notmuch show" and we'll
have something somewhat usable.
2009-10-25 23:12:20 -07:00
Carl Worth
cd467cafb5 Rename notmuch_query_search to notmuch_query_search_messages
Along with renaming notmuch_results_t to notmuch_message_results_t.
The new type is quite a mouthful, but I don't expect it to be
used much other than the for-loop idiom in the documentation,
(which does at least fit nicely within 80 columns).

This is all in preparation for the addition of a new
notmuch_query_search_threads of course.
2009-10-25 22:22:07 -07:00
Carl Worth
3bd4a2eaaa Add -Wswitch-enum and fix warnings.
Having to enumerate all the enum values at every switch is annoying,
but this warning actually found a bug, (missing support for
NOTMUCH_STATUS_OUT_OF_MEMORY in notmuch_status_to_string).
2009-10-25 16:03:45 -07:00
Carl Worth
c7482b4dce Add -Wmising-declarations and fix warnings.
Wow, lots of missing 'static' on internal functions.
2009-10-25 15:58:05 -07:00
Carl Worth
884ac59256 Re-enable the warning for unused parameters.
It's easy enough to squelch the warning with an __attribute__ ((unused))
and it might just catch something for us in the future.
2009-10-25 15:53:27 -07:00
Carl Worth
cc48812cb5 Add -Wextra and fix warnings.
When adding -Wextra we also add -Wno-ununsed-parameters since that
function means well enough, but is really annoying in practice.

So the warnings we fix here are basically all comparsions between
signed and unsigned values.
2009-10-25 15:52:14 -07:00
Carl Worth
7b227a6bf7 Add an INTERNAL_ERROR macro and use it for all internal errors.
We were previously just doing fprintf;exit at each point, but I
wanted to add file and line-number details to all messages, so it
makes sense to use a single macro for that.
2009-10-25 10:54:49 -07:00
Carl Worth
9f673f3cf8 notmuch dump: Eliminate extra space in error message.
Little details can make big impressions.
2009-10-25 09:20:13 -07:00
Carl Worth
a8ae2cd214 Move read-only-archive hint from "notmuch setup" to "notmuch new"
The "notmuch setup" output was getting overwhelmingly verbose.

Also, some people might not have a lot of mail, so might never need
this optimization. It's much better to move the hint to the time
when the user could actually benefit from it, (it's easy to detect
that "notmuch new" took more than 1 second, and we know if there
are any read-only directories there or not).
2009-10-25 09:14:16 -07:00
Carl Worth
144b2cbc55 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.
2009-10-24 22:16:10 -07:00
Carl Worth
309c0e1cc5 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).
2009-10-24 22:11:38 -07:00
Carl Worth
e1e1f0cb3b Revert "Remove some unneeded initializers."
This reverts commit fb1bae0700.

These initializers were totally necessary. I clearly wasn't
thinking straight when I removed them.
2009-10-24 08:06:23 -07:00
Carl Worth
1f193675c4 Cut the enthusiasm a bit.
It gets annoying pretty quick.
2009-10-23 17:25:23 -07:00
Carl Worth
c037dc5e53 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.
2009-10-23 17:25:03 -07:00
Carl Worth
ef944693c3 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.
2009-10-23 16:23:18 -07:00
Carl Worth
e58d85dd75 More fixing of plurals.
It definitely doesn't help that we have the same messages in both
"setup" and "new". Should combine those really.
2009-10-23 16:00:24 -07:00
Carl Worth
6cccc10bf0 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).
2009-10-23 15:57:39 -07:00
Carl Worth
cbb2675ec5 Print a better message than "0s" for zero seconds.
It's nice to have a tool that at least construct actual sentences.
2009-10-23 15:55:36 -07:00
Carl Worth
491ece966f 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.
2009-10-23 15:48:05 -07:00
Carl Worth
9577e8a105 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.
2009-10-23 15:39:11 -07:00
Carl Worth
a7a897b883 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.
2009-10-23 15:29:06 -07:00
Carl Worth
fb1bae0700 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.
2009-10-23 14:55:50 -07:00
Carl Worth
336deb279e 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.
2009-10-23 14:55:02 -07:00
Carl Worth
68a10091d6 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.
2009-10-23 14:31:01 -07:00
Carl Worth
c9fbe6b58b 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.
2009-10-23 06:08:22 -07:00
Carl Worth
302d54834d Add notmuch_status_to_string function.
Be kind and let the user print error messages, not just error
codes.
2009-10-21 16:12:53 -07:00
Carl Worth
f232f0a797 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.
2009-10-21 16:03:03 -07:00
Carl Worth
f96f4fe427 Pull out a chomp_newline function from "notmuch setup"
We'll want this same thing with "notmuch restore", (and really
anything using getline).
2009-10-21 15:59:11 -07:00
Carl Worth
baf1867cc4 notmuch dump: Fix to print spaces between tags.
Simple little bug here made all the tags run together.
2009-10-21 14:02:51 -07:00
Carl Worth
0e914d9e96 notmuch dump: Fix buffer overrun in error message.
Just a little bug I noticed while editing nearby code.
2009-10-21 10:12:11 -07:00
Carl Worth
af65f52acf 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.
2009-10-21 00:32:30 -07:00
Carl Worth
6519aff957 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.
2009-10-20 22:40:37 -07:00
Carl Worth
aad13c3ac9 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.
2009-10-20 22:27:56 -07:00
Carl Worth
466a7bbf62 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").
2009-10-20 21:21:39 -07:00
Carl Worth
28fa0bc2d6 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.
2009-10-20 13:17:56 -07:00
Carl Worth
00b65cad98 notmuch: Use GNU libc getline() instead of glib GIOChannel
Less reliance on glib is always nice for our memory-leak testing
efforts.
2009-10-20 12:47:23 -07:00
Carl Worth
67a0ee2ebb 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.
2009-10-20 10:09:17 -07:00
Carl Worth
55c8ee9a86 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
2009-10-20 09:58:40 -07:00
Carl Worth
5f8d44fa5b 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.
2009-10-19 23:41:31 -07:00
Carl Worth
ad784f38ce 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).
2009-10-19 23:16:05 -07:00
Carl Worth
2269106466 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).
2009-10-19 18:30:48 -07:00
Carl Worth
c5eea2b77e Document which pieces of glib we're still using.
Looks like we can copy in a hash-table implementation, (from cairo,
say), and then a few _ascii_ functions from glib, (we'll need to
switch a few current uses if things like isspace, etc. to locale-
independent versions as well). So not too hard to free ourselves
of glib for now, (until we add GMime back in later, of course).
2009-10-19 13:40:56 -07:00
Carl Worth
9bc4253fa8 notmuch: Ignore .notmuch when counting files.
We were correctly ignoring this when adding files, but not when
doing the initial count. Clearly we need better code sharing
here.
2009-10-19 12:52:46 -07:00
Carl Worth
10c176ba0e notmuch: Start actually adding messages to the index.
This is the beginning of the notmuch library as well, with its
interface in notmuch.h. So far we've got create, open, close, and
add_message (all with a notmuch_database prefix).

The current add_message function has already been whittled down from
what we have in notmuch-index-message to add only references,
message-id, and thread-id to the index, (that is---just enough to do
thread-linkage but nothing for full-text searching).

The concept here is to do something quickly so that the user can get
some data into notmuch and start using it. (The most interesting stuff
is then thread-linkage and labels like inbox and unread.)  We can
defer the full-text indexing of the body of the messages for later,
(such as in the background while the user is reading mail).

The initial thread-stitching step is still slower than I would like.
We may have to stop using libgmime for this step as its overhead is
not worth it for the simple case of just parsing the message-id,
references, and in-reply-to headers.
2009-10-18 20:56:30 -07:00
Carl Worth
36640b303e Start a new top-level executable: notmuch.
Of course, there's not much that this program does yet. It's got
some structure for some sub-commands that don't do anything. And
it has a main command that prints some explanatory text and then
counts all the regular files in your mail archive.
2009-10-17 08:26:58 -07:00