Commit graph

62 commits

Author SHA1 Message Date
Jani Nikula
230c2ed357 cli: fix use of uninitialized variable in "notmuch reply"
notmuch_show_params_t params is only initialized partially in
notmuch_reply_command(). The only field that is used uninitialized is
params.decrypt. It is usually non-zero, making "notmuch reply" on encrypted
messages work by coincidence.

Initialize params properly, and set params.decrypt as needed.

Signed-off-by: Jani Nikula <jani@nikula.org>
2012-01-09 06:44:47 -04:00
Austin Clements
36f7fe5a1c show: Pass notmuch_message_t instead of path to show_message_body.
In addition to simplifying the code, we'll need the notmuch_message_t*
in show_message_body shortly.
2011-12-25 22:17:27 -04:00
David Bremner
61f0a5b8ee cli: change argument parsing convention for subcommands
previously we deleted the subcommand name from argv before passing to
the subcommand. In this version, the deletion is done in the actual
subcommands. Although this causes some duplication of code, it allows
us to be more flexible about how we parse command line arguments in
the subcommand, including possibly using off-the-shelf routines like
getopt_long that expect the name of the command in argv[0].
2011-10-22 19:42:54 -03:00
Jameson Graef Rollins
fbe3c38655 Ignore "application/pgp-*" parts in reply.
The quoted text doesn't need to mention that the message being replied
to had these crufty parts.
2011-10-06 10:13:51 -03:00
Jameson Graef Rollins
c75410fd81 Fix notmuch-reply to not output "Non-text part:" lines for non-leafnode parts.
These lines are just cruft in this case, and can be removed.
2011-10-06 10:12:48 -03:00
Jameson Graef Rollins
12de016686 Improve handling of message/rfc822 parts by adding a new header_message_part function to the formating structure.
This new function takes a GMimeMessage as input, and outputs the
formatted headers.  This allows for message/rfc822 parts to be
formatted on output in a similar way to full messages (see previous
patch that overhauls the multipart test for more info).
2011-09-05 22:58:52 -03:00
Pieter Praet
8bb6f7869c fix sum moar typos [comments in source code]
Various typo fixes in comments within the source code.

Signed-off-by: Pieter Praet <pieter@praet.org>

Edited-by: Carl Worth <cworth@cworth.org> Restricted to just
source-code comments, (and fixed fix of "descriptios" to "descriptors"
rather than "descriptions").
2011-06-23 15:58:39 -07:00
Dmitry Kurochkin
917e87415e Fix indentation in guess_from_received_header(). 2011-06-15 07:08:28 -07:00
Dmitry Kurochkin
eeffa305eb Fix memory leak in guess_from_received_header().
Mta variable was not free()d in one case.
2011-06-15 07:08:25 -07:00
Dmitry Kurochkin
565d87c2aa Fix double free in guess_from_received_header().
Before the change, the last loop in guess_from_received_header()
did not reset domain and tld variables to NULL.  This leads to
double free error in some cases and possibly other bugs.
2011-06-15 07:08:18 -07:00
Daniel Kahn Gillmor
5143e5e840 Use stock GMimeSession by default
Our use of GMimeSession was unneeded boilerplate, and we weren't doing
anything with it.  This simplifies and clarifies that assumption.

If we want to do anything fancier later, the examples in the gmime
source are a reasonable source to work from in defining a new
GMimeSession derivative.

Since GMimeSession is going away in GMime 2.6, though, i don't
recommend using it.
2011-06-03 17:42:54 -07:00
Jameson Graef Rollins
2e653db38f Add decryption of PGP/MIME-encrypted parts with --decrypt.
This adds support for decrypting PGP/MIME-encrypted parts to
notmuch-show and notmuch-reply.  The --decrypt option implies
--verify.  Once decryption (and possibly signature verification) is
done, a new part_encstatus formatter is emitted, the part_sigstatus
formatter is emitted, and the entire multipart/encrypted part is
replaced by the contents of the encrypted part.

At the moment only a json part_encstatus formatting function is
available, even though decryption is done for all formats.  Emacs
support to follow.
2011-05-27 16:22:00 -07:00
Jameson Graef Rollins
8b18efe171 Add signature verification of PGP/MIME-signed parts with --verify.
This is primarily for notmuch-show, although the functionality is
added to show-message.  Once signatures are processed a new
part_sigstatus formatter is emitted, and the entire multipart/signed
part is replaced with the contents of the signed part.

At the moment only a json part_sigstatus formatting function is
available.  Emacs support to follow.

The original work for this patch was done by

  Daniel Kahn Gillmor <dkg@fifthhorseman.net>

whose help with this functionality I greatly appreciate.
2011-05-27 16:22:00 -07:00
Jameson Graef Rollins
d92146d3a6 Break up format->part function into part_start and part_content functions.
Future improvements (eg. crypto support) will require adding new part
header.  By breaking up the output of part headers from the output of
part content, we can easily out new part headers with new formatting
functions.
2011-05-27 16:18:57 -07:00
Jameson Graef Rollins
757e06f74b Use empty strings instead of NULL in format_reply structure.
This keeps things consistent with notmuch-show, and prevents having to
check for the existence of the field pointer for simple string output
formats.
2011-05-27 16:18:57 -07:00
Jameson Graef Rollins
5659d42231 Integrate reply_part_content function into reply_part function.
After the last patch to eliminate some redundant code paths in
reply_part, the reply_part_content function was only being called
once.  Disolving the function and integrating its contents into the
reply_part function makes things a little simpler, and frees up some
name space that will be needed in the next patch.
2011-05-27 16:18:57 -07:00
Jameson Graef Rollins
03ac922c4b Simplify reply_part function to eliminate redundant code paths.
This is the same logic but with less code.
2011-05-27 16:18:57 -07:00
Jameson Graef Rollins
2f8871df6e New part output handling as option to notmuch-show.
Outputting of single MIME parts is moved to an option of notmuch show,
instead of being handled in it's own sub-command.  The recent rework
of multipart mime allowed for this change but consolidating part
handling into a single recursive function (show_message_part) that
includes formatting.  This allows for far simpler handling single
output of a single part, including formatting.
2011-05-23 15:31:32 -07:00
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
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
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
c6e70e15ea notmuch: Eliminate some const-correctness warnings.
These were introduced as a side-effect of commit
b9eac48c22 (shame on me for doing
side-effect commits like that!).

For me, at least, compilation is now warning-free.
2010-10-27 18:07:37 -07:00
Jameson Rollins
399031c2e3 Remove bcc header from notmuch reply.
Notmuch reply should not be Bcc'ing the sender by default.  This is
not the appropriate way to save copies of sent mail (which should
probably be handled by an Fcc header[*]) and it doesn't give the user the
option to not be bcc'd.  This is really something that should be
handled by the reader UI.  For instance, emacs message-mode can easily
be configured to add Bcc's if the user wishes.

[*] Carl Worth: The FCC header is now in place by default in the emacs
user-interface (and tested in the test suite) so the Bcc is ready to
be eliminated.
2010-10-27 17:15:42 -07:00
Aneesh Kumar K.V
107f58d517 Rename already used counter var i
i is already used in a for loop at this point, so using i here again
broke notmuch-reply (it would just hang). Use j instead of i here.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2010-04-27 08:09:38 -07:00
Dirk Hohndel
932e1c165c Rearchitect From: header guessing code for replies
We want to be able to correctly guess the best From: header to use when
replying to emails. This is what we are looking at now:
 1 is one of the users' mail addresses in the To: or Cc: header
 2 check for an Envelope-to: header
 3 check for an X-Original-To: header
 4 check for a (for <email@add.res>) clause in Received: headers
 5 check for the domain part of known email addresses in the
      'by' part of Received headers
 6 fall back to the primary email address

This patch changes the algorithm for steps 2-5 of this process. Prior to
this patch we had a first attempt to implement only step 5 - but this
broke in many email setups where mail delivery to the local machine added
additional Received: lines.
Steps 2-4 are new, step 5 now analyzes the concatenated Received: header
(this was in the previous patch) to do this analysis.

Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
2010-04-26 14:44:13 -07:00
Carl Worth
d06a34ad5d notmuch reply: Handle notmuch_message_get_header returning NULL.
This seems a rather unlikely case, (replying to a message that
disappears out from under us half way through the reply), but
notmuch_message_get_header is documented to return NULL in error
cases, so we might as well deal sanely with that (rather than just
crashing).
2010-04-24 06:33:32 -07:00
Michal Sojka
452fbedcd5 Decode headers in reply
When headers contain non-ASCII characters, they are encoded according
to rfc2047. Nomtuch reply command emits the headers in the encoded
form, which makes them hard to read by humans who compose the reply.

For example instead of "Subject: Re: Rozlučka" one currently sees
"Subject: Re: =?iso-8859-2?q?Rozlu=E8ka?=".

This patch adds a new GMime filter which is used to decode headers to
UTF-8 and uses this filter when notmuch reply outputs headers.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
2010-04-13 09:23:54 -07:00
Dirk Hohndel
569ecf8c16 Fix code extracting the MTA from Received: headers
The previous code made too many assumptions about the (sadly not
standardized) format of the Received headers. This version should
be more robust to deal with different variations.

Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
2010-04-07 15:36:40 -07:00
Carl Worth
8d4fa40bec notmuch-reply: Remove stray brace.
That was breaking the build.
2010-04-07 07:17:12 -07:00
Carl Worth
542e32876e notmuch-reply: Remove a useless level of nesting.
Making the code a tiny bit easier to read (in my opinion at least).
2010-04-06 18:51:57 -07:00
Carl Worth
3e216ba60d notmuch-reply: Fix some whitespace issues.
No actual code change here. Just whitespace style, (mostly just my
preferred space before a left parenthesis, and a space after a comma).
2010-04-06 18:51:47 -07:00
Dirk Hohndel
4fd9ea05e8 guess From address from Received headers
When replying to a message notmuch tries to pick the correct From
 address by looking which one of a user's configured email addresses
 were included in To or Cc headers of the email that is being replied to.
 If none of the users email addresses are in the To or Cc headers we now
 try to guess from the first (chronologically, last) Received header
 which domain this email was received in and therefore which of the
 email addresses to use in a reply
 If that fails we still use the primary email as From email

Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
2010-04-06 18:47:40 -07: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
Carl Worth
d111c720ba notmuch reply: Rename the mailing_list_munged_reply_to function
This function detects whether the address in the Reply-To header
already appears in either To or Cc. So give it a name that reflects
what it does (reply_to_header_is_redundant) rather than the old name
which described one possible use of the function, (as a simple
heuristic for detecting whether a mailing list had applied reply-to
munging).
2010-02-04 12:42:09 -08:00
Carl Worth
62379f3dee notmuch reply: Prevent GMIME assertion complaints for empty Reply-to header.
Apparently, GMime doesn't want to create a valid address list object
for an empty string. That's annoying, but it's easy enough to test for
the empty string and avoid the problem.
2010-02-04 12:42:09 -08:00
Carl Worth
82e47ec92b notmuch reply: Use strstr instead of strcasestr for portability.
This change was already recommended in a comment in the original
implementation of this patch. If someone really wants to support
un-munging in the case of To: and Reply-To: having the same address
but different case, then they can provide a portable approach for
that.
2010-02-04 12:42:09 -08:00
Carl Worth
aea35aa5c6 notmuch reply: Fix the support for reply-to un-munging.
The condition was using a reversed sense for the test of the return
value of strcasestr, (perhaps confusing it with the usage of strcmp?).
2010-02-04 12:42:09 -08:00
Carl Worth
9953e9a5a8 notmuch-reply: Add missing whitespace.
Some recently-added functions were to hard for me to read without
the expected whitespace. Fix these.
2010-02-04 12:42:09 -08:00
Jed Brown
fddd3d831b notmuch-reply.c: Handle munged `Reply-To' headers.
Some mailing lists engage in the evil practice of changing the Reply-To
header so that replies from all mailers go to the list by default, at
the expense of not responding to the person who actually sent the
message.  When this is detected, we reply to `From' and remove the
duplicate response to the mailing list.  Consider a reply to the
following message.

  From: Some User <some.user@example.com>
  To: Sample users list <sample-users@sample.org>
  Reply-To: Sample users list <sample-users@sample.org>

Prior to this patch, `notmuch reply' produces

  To: Sample users list <sample-users@sample.org>,
      Sample users list <sample-users@sample.org>

and after the patch,

  To: Some User <some.user@example.com>,
      Sample users list <sample-users@sample.org>

Signed-off-by: Jed Brown <jed@59A2.org>
2010-02-04 12:10:43 -08:00
Jed Brown
fb50f31048 notmuch-reply.c: Factor adding recipients into common function
This code was already duplicated. We move it to a new, shared
add_recipients_from_message function, in preparation for more
sophisticated mailing list logic.

Signed-off-by: Jed Brown <jed@59A2.org>
2010-02-04 12:10:43 -08:00
Kan-Ru Chen
c8b50eee28 notmuch-reply: Display reply 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-12-03 16:47:47 -08:00
Jed Brown
00b138ba2a reply --format=headers-only: set In-Reply-To header, with ID *last* in References
Apparently this is actually the correct way to do it, it's silly to do
it wrong just to conform to one of git's internal data structures.
2009-11-27 16:56:51 -08:00
Jed Brown
f47e54bc51 notmuch-reply.c: implement notmuch_reply_format_headers_only
This command only generates References, To, and Cc headers.
The purpose is primarily for use in

  git send-email --notmuch id:<MESSAGE-ID>

to get proper threading and address the relevant parties.  Hooks for
other SCMs may come later.

Signed-off-by: Jed Brown <jed@59A2.org>
2009-11-27 16:56:42 -08:00
Jed Brown
5d447f327f notmuch-reply.c: accept the --format=default default option.
This factors actual generation of the reply out of notmuch_reply_command
into notmuch_reply_format_default(), in preparation for other --format=
options.

Signed-off-by: Jed Brown <jed@59A2.org>
2009-11-27 16:56:23 -08:00
Carl Worth
94eb9aacd4 lib/query: Drop the first and max_messages arguments from search_messages.
These only existed to support the chunky-searching hack, but that
was recently dropped anyway.
2009-11-23 20:25:13 -08:00
Jed Brown
1e75f5f3a7 Make addresses case insensitive for the purpose of constructing replies.
The domain is alway case insensitive, but in principle the username is
case sensitive.  Few systems actually enforce this so I think a good
default is to treat the entire address as case insensitive, it will
eliminate a lot of superfluous self-addressed messages and reply from
the correct address in these cases.

Signed-off-by: Jed Brown <jed@59A2.org>
2009-11-23 18:35:01 -08: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
e94bd8506b notmuch reply: Include text parts in reply, even with disposition attachment.
If it's text, (such as a patch), then I want it quoted in my reply,
(so that I can comment on it).
2009-11-21 01:14:01 +01:00
Chris Wilson
f52528a344 reply: Pointer mismatch.
Apparently typeof (size_t) != unsigned int on my x86-64.
2009-11-19 00:20:24 +01:00