Commit graph

89 commits

Author SHA1 Message Date
Jameson Graef Rollins
6c2417cabc add part_sep formatter to replace "first" argument to part format functions
A new field "part_sep" is added to the notmuch_show_format structure,
to be used for part separation.  This is cleaner than the "first"
argument that was being passed around to the part arguments, and
allows the function that handles overall part output formatting
(show_message_part) to directly handle when outputting the separator.
2011-05-23 14:55:27 -07:00
Jameson Graef Rollins
d2177d0b22 create notmuch_show_params_t structure for holding parameters passed to show functions.
This simplifies the passing of arguments to the show functions.  This
will be very useful as we accumulate more parameters that will need to
be passed.  Currently only the entire_thread parameter is passed this
way.
2011-05-23 14:55:27 -07:00
Jameson Graef Rollins
dcdb843094 pass entire format structure to various show_message functions
Various show_message* functions require formatting functions, which
were previously being passed individually as arguments.  Since we will
need to be needing to passing in more formatting function in the
future (ie. for crypto support), we here modify things so that we just
pass in the entire format structure.  This will make things much
simpler down the line as we need to pass in new format functions.

We move the show_format structure into notmuch-client.c as
notmuch_show_format.  This also affects notmuch-reply.c, so we create
a mostly-empty format_reply to pass the reply_part function to
show_message_body.
2011-05-20 12:27:35 -07:00
David Edmondson
97bc272b9c notmuch: Add the content-id of a part to the JSON output if it is known.
It's simply one more property of a MIME part that might be useful, and
json makes it so easy to add additional properties.

Signed-off-by: Jameson Rollins <jrollins@finestructure.net>
2011-05-18 15:51:46 -07:00
Carl Worth
362ab047c2 notmuch show: Properly nest MIME parts within mulipart parts
Previously, notmuch show flattened all output, losing information
about the nesting of the MIME hierarchy. Now, the output is properly
nested, (both in the --format=text and --format=json output), so that
clients can analyze the original MIME structure.

Internally, this required splitting the final closing delimiter out of
the various show_part functions and putting it into a new
show_part_end function instead. Also, the show_part function now
accepts a new "first" argument that is set not only for the first MIME
part of a message, but also for each first MIME part within a series
of multipart parts. This "first" argument controls the omission of a
preceding comma when printing a part (for json).

Many thanks to David Edmondson <dme@dme.org> for originally
identifying the lack of nesting in the json output and submitting an
early implementation of this feature. Thanks as well to Jameson Graef
Rollins <jrollins@finestructure.net> for carefully shepherding David's
patches through a remarkably long review process, patiently explaining
them, and providing a cleaned up series that led to this final
implementation. Jameson also provided the new emacs code here.
2011-05-17 15:58:57 -07:00
Carl Worth
c51d5b3cdb notmuch show: Include output for the enclosing multipart part of a MIME mail
Previously, the outer multipart part of any multipart/mixed,
multipart/signed, etc. MIME message was silently omitted from the
"notmuch show" output. This prevented any client from correctly
determining to which parts a signature applies, for example.

Now, we actually emit these parts as their own parts. The output is
still flattened---the contained parts are not yet included "within"
the multipart part---so it's still not possible to determine to which
parts a signature applies, but this is one step along the path.

The test suite is updated to reflect this change, (though we'll
eventually want to fix the emacs interface to not display buttons for
the multipart enclosure parts as there's nothing useful for the user
to actually do with them).
2011-05-17 14:51:06 -07:00
Carl Worth
81d3bd3670 Rename "notmuch cat" to "notmuch show --format=raw"
This is part of an effort to avoid proliferation of excessive
top-level notmuch commands. Also, "raw" better captures the
functionality here, (as opposed to "cat" which is a fairly oblique
reference to a bad Unix abbreviation whose metaphor doesn't work here
since "notmuch cat" operates only on a single message and hence cannot
"con'cat'enate" anything).
2010-11-06 12:03:51 -07:00
Michal Sojka
d39d0e55f0 Add 'cat' subcommand
This command outputs a raw message matched by search term to the
standard output. It allows MUAs to access the messages for piping,
attachment manipulation, etc. by running notmuch cat rather then
directly access the file. This will simplify the MUAs when they need
to operate on a remote database.

Edited-by: Carl Worth <cworth@cworth.org>: Remove trailing whitespace,
add missing "test_done" to new test script to avoid "Unexpected exit"
error.
2010-11-05 17:51:18 -07:00
Carl Worth
33cd247dc1 notmuch show: Add a --format=mbox option
We don't love the mbox format, but it's still sometimes the most
practical way to share a collection of messages as a single file.

Here we implement the "mboxrd" variant of the mbox file format. This
variant applies reversible escaping by prefixing a '>' character to
all lines in the email messages matching the regular expression:

	"^>*From "

This allows the escaping to be reliably removed. A reader should remove
a '>' from any line matching the regular expression:

	"^>>*From "

More details on the mboxrd formats (and others as well) can be found
here:

http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/mail-mbox-formats.html
2010-06-08 19:45:54 -07:00
Carl Worth
2ead072e85 Fix minor style issues in show_part_content function.
I was recently editing the code in this function and decided to clean
it up a bit.
2010-06-05 08:47:13 -07:00
Carl Worth
9c7668bdb5 Avoid giving GMime a NULL MIME-stream filter.
Micah Anderson reported an issue where a message failed to display in
the emacs interface, (it instead gave an error, "json-read-string: Bad
string format").

Micah tracked this down to the json output from "notmuch show" being
interrupted by a GMime error message:

	gmime-CRITICAL **: g_mime_stream_filter_add: assertion
	`GMIME_IS_FILTER (filter)

I tracked this down further to notmuch passing a NULL value to
g_mime_stream_filter_add. And this was due to calling
g_mime_filter_charset_new with a value of "unknown-8bit".

So we add a test message withe a Conten-Type of "text/plain;
charset=unknown-8bit" from Micah's message. Then we fix "notmuch show"
to test for NULL before calling g_mime_stream_filter_add. Bug fixed.
2010-06-05 08:40:26 -07:00
David Edmondson
afb8c9ca62 json: Replace date_unix' with timestamp' in show output
Search output was already using `timestamp' for a very similar field,
so follow that.
2010-04-22 14:52:32 -07:00
David Edmondson
9eb3603299 notmuch: Correctly terminate text/* parts in JSON output
Text parts returned by `g_mime_stream_mem_get_byte_array()' are not
NULL terminated strings - add `json_quote_chararray()' to handle them
correctly.
2010-04-05 10:57:23 -07:00
David Edmondson
2e9c7aba99 notmuch: Add a 'part' subcommand
A new 'part' subcommand allows the user to extract a single part from
a MIME message. Usage:
  notmuch part --part=<n> <search terms>
The search terms must match only a single message
(e.g. id:foo@bar.com). The part number specified refers to the part
identifiers output by `notmuch show'. The content of the part is
written the stdout with no formatting or identification marks. It is
not JSON formatted.
2010-04-02 09:43:03 +01:00
David Edmondson
930a47935f notmuch-show: Add unix and relative dates to the JSON output
Include a 'date_unix' and 'date_relative' field in the JSON output for
each message. 'date_relative' can be used by a UI implementation,
whereas 'date_unix' is useful when scripting.
2010-04-02 09:25:38 +01:00
nstraz@redhat.com
685cfcc9e8 Setup the GMimeStream only when needed
I ran into this while looking at the vim plugin.  Vim's system() call
redirects output to a file and it was missing many of the part{ lines.

If stream_stdout is setup too early, it will overwrite the part start
when notmuch is redirected to a file.

Reviewed-by Carl Worth <cworth@cworth.org>: GMime is calling fseek
before every write to reset the FILE* to the position it believes is
correct based on the writes it has seen. Our code was getting
incorrect results because our GMime writes were interleaved with
non-GMime writes via printf.

The bug appears when writing to a file because it's seekable, but not
when writing to a pipe which is not.
2010-04-01 14:27:01 -07:00
Sebastian Spaeth
d30049d2b9 notmuch-show: add tags to json output
The previous json patches forgot to add the notmuch tags to the json
output. This is inconsistent to the text output so here they are. We
just output a 'tags' field that sends notmuch tags as a json array.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2010-03-11 04:30:46 -08:00
Carl Worth
2303d9366e notmuch show: Don't show empty headers.
This is a fairly old regression. There has always been code to avoid
printing empty headers (such as Cc or Bcc with no values), but it has
been broken since notmuch_message_get_header was changed to return
an empty string rather than a NULL pointer for these fields.
2010-03-09 10:12:58 -08:00
Carl Worth
4e5d2f22db lib: Rename iterator functions to prepare for reverse iteration.
We rename 'has_more' to 'valid' so that it can function whether
iterating in a forward or reverse direction. We also rename
'advance' to 'move_to_next' to setup parallel naming with
the proposed functions 'move_to_first', 'move_to_last', and
'move_to_previous'.
2010-03-09 09:22:29 -08:00
Scott Robinson
6ce2bf68f5 Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.
In the case of notmuch-show, "--format=json" also implies
"--entire-thread" as the thread structure is implicit in the emitted
document tree.

As a coincidence to the implementation, multipart message ID numbers are
now incremented with each part printed. This changes the previous
semantics, which were unclear and not necessary related to the actual
ordering of the message parts.
2010-02-23 12:01:12 -08:00
Carl Worth
115b7c15b8 notmuch show: Preserve thread-ordering and nesting without --entire-thread
When "notmuch show" was recently modified to not show an entire thread
by default, it also lost all capability to properly order the messages
in a thread and to print their proper depth. For example, the command:

	notmuch show thread:6d5e3e276461188c5778c9f219f63782

had dramatically different output than:

	notmuch show --entire-thread thread:6d5e3e276461188c5778c9f219f63782

even though both commands were selecting and displaying the same set
of messages. The first command would diplay them "flat", (all with
depth:0), and in strict date order; while the second command would
display them "nested" (with depth based on threading), and in thread
order.

We now fix "notmuch show" without the --entire-thread option to also
display nested and thread-ordered messages.

If some messages in the thread are not included in the displayed
results, then they are not counted when computing depth values.
2009-12-02 16:14:41 -08:00
Bart Trojanowski
d50c67d53b notmuch show: limit display to only matching messages
This patch changes the default behaviour of notmuch show to display only
messages that match the search expression.  However, --entire-thread
option is provided to display all messages in threads that matched the
search expression.

It is deemed that will be more useful for human users on the command line.
Scripts can be modified to include the --entire-thread option so that they
can display all messages once more.

Example:

$ notmuch search subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b
thread:23d99d0f364f93e90e15df8b42eddb5b      July 31 [4/12] Johan Herland; [RFCv2 00/12] Foreign VCS helper program for CVS repositories (inbox unread)

Note that in this thread 4 out of 12 messages matched.  The default show
behaviour is to show only those messages that match:

$ notmuch show subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b | grep 'message{' | wc -l
4

With the --entire-thread option the output will contain all dozen
messages:

$ notmuch show --entire-thread subject:git AND thread:23d99d0f364f93e90e15df8b42eddb5b | grep 'message{' | wc -l
12

Signed-off-by: Bart Trojanowski <bart@jukie.net>
2009-12-02 14:32:14 -08:00
Bart Trojanowski
6da6566576 correct message flag enum value so that it matches the type
As per Carl's request, this patch corrects the only value defined under
the notmuch_message_flag_t enum typedef to match the name of the type.

Signed-off-by: Bart Trojanowski <bart@jukie.net>
2009-11-27 20:50:59 -08:00
Bart Trojanowski
c984fc43cc notmuch-show: identify which messages printed matched the query string
The show command outputs all messages in the threads that match the
search-terms.  This patch introduces a 'match:[01]' entry to the 'message{'
line output by the show command.  Value of 1 indicates that the message is
matching the search expression.

Signed-off-by: Bart Trojanowski <bart@jukie.net>
2009-11-27 17:07:18 -08:00
Carl Worth
1fd8b7866f notmuch search: Remove the chunked-searching hack.
This was a poor workaround around the fact that the existing
notmuch_threads_t object is implemented poorly. It's got a fine
iterartor-based interface, but the implementation does all of the
work up-front in _create rather than doing the work incrementally
while iterating.

So to start fixing this, first get rid of all the hacks we had working
around this. This drops the --first and --max-threads options from the
search command, (but hopefully nobody was using them
anyway---notmuch.el certainly wasn't).
2009-11-23 20:17:37 -08:00
Kan-Ru Chen
a15f174437 notmuch-show: Show message part using UTF-8.
Pass the message through the charset filter so that we can view
messages wrote in different charset encoding.

Signed-off-by: Kan-Ru Chen <kanru@kanru.info>
2009-11-22 13:31:34 +01:00
Carl Worth
637f99d8f3 Rename NOTMUCH_DATABASE_MODE_WRITABLE to NOTMUCH_DATABASE_MODE_READ_WRITE
And correspondingly, READONLY to READ_ONLY.
2009-11-21 22:10:18 +01:00
Chris Wilson
f379aa5284 Permit opening the notmuch database in read-only mode.
We only rarely need to actually open the database for writing, but we
always create a Xapian::WritableDatabase. This has the effect of
preventing searches and like whilst updating the index.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Carl Worth <cworth@cworth.org>
2009-11-21 22:04:49 +01:00
Carl Worth
268da2cf19 notmuch show: Don't hide text parts, even with disposition attachment.
If it's text, (such as a patch), then I want to see it.
2009-11-21 01:10:25 +01:00
Keith Packard
394cb1c46d Make reply/show/tag all require at least one search term
In particular, notmuch tag -inbox "" tended to take a long time to
run, happened if you hit 'a' on a blank line in the search view and
probably didn't have the desired effect.

Signed-off-by: Keith Packard <keithp@keithp.com>
2009-11-18 23:37:35 +01:00
Keith Packard
469d786c25 Filter out carriage-returns in show and reply output.
Thanks, windows mail clients.

Signed-off-by: Keith Packard <keithp@keithp.com>
2009-11-18 23:34:43 +01:00
Carl Worth
58b659f893 notmuch show: Detect an internal error if a thread has no messages.
This really should be impossible---if there are no messages, then what
was the thread object created from? During recent debugging, it was
useful to have this error detected and reported.
2009-11-17 17:55:45 -08:00
Carl Worth
933caf814f notmuch show: Implement proper thread ordering/nesting of messages.
We now properly analyze the in-reply-to headers to create a proper
tree representing the actual thread and present the messages in this
correct thread order. Also, there's a new "depth:" value added to the
"message{" header so that clients can format the thread as desired,
(such as by indenting replies).
2009-11-15 20:41:45 -08:00
Carl Worth
819f964d9a Minor whitespace touchup.
It's funny that I picked up the habit of always including a space
before a left parenthesis from Keith, and now he's in the habit of
contributing code without it.
2009-11-15 20:38:16 -08:00
Carl Worth
93dcc3b695 libnotmuch: Underlying support for doing partial-results searches.
The library interface now allows the caller to do incremental searches,
(such as one page of results at a time). Next we'll just need to hook
this up to "notmuch search" and the emacs interface.
2009-11-12 16:47:27 -08:00
Carl Worth
bb7ed1f153 notmuch show: Display "Subject: " before the subject.
I think I was being uselessly terse when I dropped that. Put it back.
2009-11-12 10:22:55 -08:00
Carl Worth
13569ad6c9 Unbreak several notmuch commands after the addition of configuration.
All of the following commands:

	notmuch dump
	notmuch reply
	notmuch restore
	notmuch search
	notmuch show
	notmuch tag

were calling notmuch_database_open with an argument of NULL. This was
a legitimate call until the recent addition of configuration, after
which it is expected that all commands will lookup the correct path in
the configuration file. So fix all these commands to do that.

Also, while touching all of these commands, we fix them to use the
talloc context that is passed in rather than creating a local talloc
context. We also switch from using goto for return values, to doing
direct returns as soon as an error is detected, (which can be leak
free thanks to talloc).
2009-11-11 20:29:30 -08:00
Keith Packard
357aba3ec8 notmuch reply: Add (incomplete) reply command
Reviewed-by: Carl Worth <cworth@cworth.org>

Keith wrote all the code here against notmuch before notmuch.c was
split up into multiple files. So I've pushed the code around in
various ways to match the new code structure, but have generally tried
to avoid making any changes to the behavior of the code.

I did fix one bug---a missing call to g_mime_stream_file_set_owner in
show_part which would cause "notmuch show" to go off into the weeds
when trying to show multiple messages, (since the first stream would
fclose stdout).
2009-11-10 13:32:02 -08:00
Carl Worth
50144f95ca notmuch: Break notmuch.c up into several smaller files.
Now that the client sources are alone here in their own directory,
(with all the library sources down inside the lib directory), we can
break the client up into multiple files without mixing the files up.
The hope is that these smaller files will be easier to manage and
maintain.
2009-11-10 12:03:05 -08:00