Commit graph

5316 commits

Author SHA1 Message Date
Carl Worth
defd216487 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".
2009-10-21 15:56:33 -07:00
Carl Worth
0bbfa57014 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.
2009-10-21 15:51:13 -07:00
Carl Worth
a6b3f341dc 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.)
2009-10-21 15:46:46 -07:00
Carl Worth
0383ae2a07 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.
2009-10-21 15:45:34 -07:00
Carl Worth
2afd95bfc2 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.
2009-10-21 15:42:54 -07:00
Carl Worth
6c5054ebee 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.
2009-10-21 15:40:20 -07:00
Carl Worth
8ad4350fef 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.
2009-10-21 15:23:08 -07:00
Carl Worth
d008389a4a Add wrappers for regcomp and regexec to xutil.c.
These will be handy for some parsing.
2009-10-21 15:07:20 -07:00
Carl Worth
22b2265cac Rename NOTMUCH_MAX_TERM to NOTMUCH_TERM_MAX
Just better consistency with our naming schemes.
2009-10-21 14:10:00 -07:00
Carl Worth
6142216132 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).
2009-10-21 14:07:40 -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
17b3c214ea Convert notmuch_database_t to start using talloc.
This will be handy as we can hang future talloc allocations off
of the datbase now.
2009-10-21 14:00:37 -07:00
Carl Worth
9ec5189a56 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).
2009-10-21 13:57:02 -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
d29a6ec791 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.
2009-10-21 10:07:34 -07:00
Carl Worth
65baa4f4e7 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).
2009-10-21 00:35:56 -07:00
Carl Worth
6a3b68edef 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.
2009-10-21 00:34:36 -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
266c612a50 .gitignore: Ignore generated file Makefile.dep
Forgot to add this when I first add dependency checking to the
Makefile.
2009-10-20 23:13:28 -07:00
Carl Worth
50144fb354 database: Remove two little bits of dead code. 2009-10-20 23:12:53 -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
4ca1492f1b 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.
2009-10-20 22:24:59 -07:00
Carl Worth
f6c7810945 Rename our talloc destructor functions to _destructor.
I want to reserve the _destroy names for some public functions
I'm about to add.
2009-10-20 22:10:07 -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
cd4a8734d3 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.
2009-10-20 15:09:51 -07:00
Carl Worth
00af443b8e Makefile: Add automatic dependency tracking to the Makefile.
With this, I really don't miss anything from automake.
2009-10-20 15:09:18 -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
7f254fb603 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.)
2009-10-20 13:07:19 -07:00
Carl Worth
5a84df0f15 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.
2009-10-20 13:05:45 -07:00
Carl Worth
e6236b88fd database.cc: Document better pieces of glib that we're using. 2009-10-20 12:49:32 -07:00
Carl Worth
25aef82877 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.
2009-10-20 12:48:14 -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
968feafbad 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.
2009-10-20 10:14:00 -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
ed6ee7330d 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).
2009-10-20 09:52:01 -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
b6dd413903 Protect definition of _GNU_SOURCE.
I was getting a duplicate definition of this from somewhere, so
getting compiler warnings without this protection.
2009-10-19 22:34:59 -07:00
Carl Worth
fedef062ce 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.
2009-10-19 22:24:28 -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
371091139a Rework message parsing to use getline rather than mmap.
The line-based parsing can be a bit awkward when wanting to peek
ahead, (say, for folded header values), but it's so convenient
to be able to trust that a string terminator exists on every
line so it cleans up the code considerably.
2009-10-19 16:38:44 -07:00
Carl Worth
45f0d7bcab Don't hash headers we won't end up using.
Just saving a little work here.
2009-10-19 13:48:13 -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
fa562fa22b Hook up our fancy new notmuch_parse_date function.
With all the de-glib-ification out of the way, we can now use it
to allow for date-based sorting of Xapian search results.
2009-10-19 13:35:29 -07:00
Carl Worth
401c6cc579 notmuch_parse_date: Handle a NULL date string gracefully.
The obvious thing to do is to treat a missing date as the beginning
of time. Also, remove a useless cast from another return of 0.
2009-10-19 13:24:12 -07:00
Carl Worth
8e4e0559e7 date.c: Rename function to notmuch_parse_date
Now completing the process of making this function "our own".

The documentation is deleted here, because we already have
the documentation we want in notmuch-private.h.
2009-10-19 13:24:07 -07:00
Carl Worth
747f610901 date.c: Add hard-coded definition of HAVE_TIMEZONE
The original code expected this to be set by running configure.
We'll just manually set it here for now. This isn't as portable
as if we were doing some compile-time examination of the current
system, but I don't need portability now.

When someone comes along that wants to port notmuch to another
system, they will already have all the #ifdefs in place and
will simply need to add the appropriate machinery to set the
defines.
2009-10-19 13:19:37 -07:00
Carl Worth
c2c50d50c5 date.c: Don't use glib's slice allocator.
This change is gratuitous. For now, notmuch is still linking
against glib, so I don't have any requirement to remove this,
(unlike the last few changes where good taste really did
require the changes).

The motivation here is two-fold:

1. I'm considering switching away from all glib-based allocation
soon so that I can more easily verify that the memory management
is solid. I want valgrind to say "no leaks are possible" not
"there is tons of memory still allocated, but probably reachable
so who knows if there are leaks or not?". And glib seems to make
that impossible.

2. I don't think there's anything performance-sensitive about the
allocation here. (In fact, if there is, then the right answer
would be to do this parsing without any allocation whatsoever.)
2009-10-19 13:14:37 -07:00