[PATCH 0/8] packaging: fedora: general updates

2013-05-28 Thread Felipe Contreras
On Sat, May 25, 2013 at 7:41 AM, David Bremner  wrote:

> At this point we wait for somebody (else) with Fedora expertise to
> review the patches.

Like who? I though the reason these were never updated is that there
wasn't anybody else.

-- 
Felipe Contreras


[PATCH v3 4/4] NEWS: added information about new --stderr=FILE top level option

2013-05-28 Thread Tomi Ollila
---
 NEWS | 5 +
 1 file changed, 5 insertions(+)

diff --git a/NEWS b/NEWS
index a7f2ec6..80abd97 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,11 @@ Top level option to specify configuration file
   It's now possible to specify the configuration file to use on the
   command line using the `notmuch --config=FILE` option.

+Top level option to redirect writes to stderr
+
+  With `notmuch --stderr=FILE` all writes to stderr are redirected to
+  the specified file. If FILE is '-', stderr is redirected to stdout.
+
 Deprecated commands "part" and "search-tags" are removed.

 Bash command-line completion
-- 
1.8.1.4



[PATCH v3 3/4] man: documented --stderr=FILE in notmuch.1 manual page

2013-05-28 Thread Tomi Ollila
---
 man/man1/notmuch.1 | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/man/man1/notmuch.1 b/man/man1/notmuch.1
index 033cc10..f5ca0ad 100644
--- a/man/man1/notmuch.1
+++ b/man/man1/notmuch.1
@@ -76,7 +76,14 @@ Print the installed version of notmuch, and exit.

 Specify the configuration file to use. This overrides any
 configuration file specified by ${NOTMUCH_CONFIG}.
+.RE
+
+.RS 4
+.TP 4
+.B \-\-stderr=FILE

+Redirect all writes to stderr to the specified file.
+If FILE is '-', stderr is redirected to stdout.
 .RE

 .SH COMMANDS
-- 
1.8.1.4



[PATCH v3 2/4] test: added --stderr=FILE tests

2013-05-28 Thread Tomi Ollila
--stderr=FILE tests were added to test/help-test as it is the one
doing most global option testing. Also, it was simplest to test
this new option using `notmuch help` command.
---
 test/help-test | 9 +
 1 file changed, 9 insertions(+)

diff --git a/test/help-test b/test/help-test
index f7df725..bd0111c 100755
--- a/test/help-test
+++ b/test/help-test
@@ -9,4 +9,13 @@ test_expect_success 'notmuch help' 'notmuch help'
 test_expect_success 'notmuch help tag' 'notmuch help tag'
 test_expect_success 'notmuch --version' 'notmuch --version'

+test_begin_subtest "notmuch --stderr=stderr help %"
+notmuch --stderr=stderr help %
+test_expect_equal "$(cat stderr)" "
+Sorry, % is not a known command. There's not much I can do to help."
+
+test_begin_subtest "notmuch --stderr=- help %"
+test_expect_equal "$(notmuch --stderr=- help %)" "
+Sorry, % is not a known command. There's not much I can do to help."
+
 test_done
-- 
1.8.1.4



[PATCH v3 1/4] cli: add global option --stderr=FILE

2013-05-28 Thread Tomi Ollila
With this option all writes to stderr are redirected to the spesified
FILE (or to stdout on case FILE is '-'). This is immediately useful
in emacs interface as some of its exec intefaces do not provide
separation of stdout and stderr.
---
 notmuch-client.h |  1 +
 notmuch.c| 32 
 2 files changed, 33 insertions(+)

diff --git a/notmuch-client.h b/notmuch-client.h
index 45749a6..4a3c7ac 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -54,6 +54,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/notmuch.c b/notmuch.c
index f51a84f..15e90c8 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -251,6 +251,32 @@ notmuch_command (notmuch_config_t *config,
 return 0;
 }

+static int
+redirect_stderr (const char * stderr_file)
+{
+if (strcmp (stderr_file, "-") == 0) {
+   if (dup2 (STDOUT_FILENO, STDERR_FILENO) < 0) {
+   perror ("dup2");
+   return 1;
+   }
+} else {
+   int fd = open (stderr_file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
+   if (fd < 0) {
+   fprintf (stderr, "Error: Cannot redirect stderr to '%s': %s\n",
+stderr_file, strerror (errno));
+   return 1;
+   }
+   if (fd != STDERR_FILENO) {
+   if (dup2 (fd, STDERR_FILENO) < 0) {
+   perror ("dup2");
+   return 1;
+   }
+   close (fd);
+   }
+}
+return 0;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -259,6 +285,7 @@ main (int argc, char *argv[])
 const char *command_name = NULL;
 command_t *command;
 char *config_file_name = NULL;
+char *stderr_file = NULL;
 notmuch_config_t *config;
 notmuch_bool_t print_help=FALSE, print_version=FALSE;
 int opt_index;
@@ -268,6 +295,7 @@ main (int argc, char *argv[])
{ NOTMUCH_OPT_BOOLEAN, _help, "help", 'h', 0 },
{ NOTMUCH_OPT_BOOLEAN, _version, "version", 'v', 0 },
{ NOTMUCH_OPT_STRING, _file_name, "config", 'c', 0 },
+   { NOTMUCH_OPT_STRING, _file, "stderr", '\0', 0 },
{ 0, 0, 0, 0, 0 }
 };

@@ -287,6 +315,10 @@ main (int argc, char *argv[])
return 1;
 }

+if (stderr_file && redirect_stderr (stderr_file) != 0) {
+   /* error already printed */
+   return 1;
+}
 if (print_help)
return notmuch_help_command (NULL, argc - 1, [1]);

-- 
1.8.1.4



v3 of --stderr=FILE patches

2013-05-28 Thread Tomi Ollila
This is v3 of id:1369557954-13439-1-git-send-email-tomi.ollila at iki.fi

In id:m2a9nfr4tb.fsf at guru.guru-group.fi I suggested to use 0600 as
permission bits so that files written to /tmp would not have write
bits set in any case. That would have been inconsistent what is
normally expected in redirection cases. The problem I described
is easily avoided in emacs as (make-temp-file "nmerr") will create
file "/tmp/nmerrXX" with permissions 0600 -- and writing to
that already-created file will not change its permissions. Writing
elsewhere is usually covered with directory permissions.


Diffdiff from v2 is shown below.

diff --git a/NEWS b/NEWS
index 990b038..80abd97 100644
--- a/NEWS
+++ b/NEWS
@@ -38,8 +38,7 @@ Top level option to specify configuration file
 Top level option to redirect writes to stderr

   With `notmuch --stderr=FILE` all writes to stderr are redirected to
-  the specified file. If the file name is a plain '-', stderr is
-  written to stdout.
+  the specified file. If FILE is '-', stderr is redirected to stdout.

 Deprecated commands "part" and "search-tags" are removed.

diff --git a/man/man1/notmuch.1 b/man/man1/notmuch.1
index fbd575a..f5ca0ad 100644
--- a/man/man1/notmuch.1
+++ b/man/man1/notmuch.1
@@ -83,7 +83,7 @@ configuration file specified by ${NOTMUCH_CONFIG}.
 .B \-\-stderr=FILE

 Redirect all writes to stderr to the specified file.
-If the file name is a plain '-', stderr is written to stdout.
+If FILE is '-', stderr is redirected to stdout.
 .RE

 .SH COMMANDS
diff --git a/notmuch.c b/notmuch.c
index 654a568..15e90c8 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -260,7 +260,7 @@ redirect_stderr (const char * stderr_file)
return 1;
}
 } else {
-   int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644);
+   int fd = open (stderr_file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (fd < 0) {
fprintf (stderr, "Error: Cannot redirect stderr to '%s': %s\n",
 stderr_file, strerror (errno));


>From Tomi Ollila  # This line is ignored.



[PATCH v2 1/4] cli: add global option --stderr=FILE

2013-05-28 Thread Tomi Ollila
On Tue, May 28 2013, Austin Clements  wrote:

> Quoth Tomi Ollila on May 26 at 11:45 am:
>> With this option all writes to stderr are redirected to the spesified
>> FILE (or to stdout on case FILE is '-'). This is immediately useful
>> in emacs interface as some of its exec intefaces do not provide
>> separation of stdout and stderr.
>> ---
>>  notmuch-client.h |  1 +
>>  notmuch.c| 32 
>>  2 files changed, 33 insertions(+)
>> 
>> diff --git a/notmuch-client.h b/notmuch-client.h
>> index 45749a6..4a3c7ac 100644
>> --- a/notmuch-client.h
>> +++ b/notmuch-client.h
>> @@ -54,6 +54,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> diff --git a/notmuch.c b/notmuch.c
>> index f51a84f..654a568 100644
>> --- a/notmuch.c
>> +++ b/notmuch.c
>> @@ -251,6 +251,32 @@ notmuch_command (notmuch_config_t *config,
>>  return 0;
>>  }
>>  
>> +static int
>> +redirect_stderr (const char * stderr_file)
>> +{
>> +if (strcmp (stderr_file, "-") == 0) {
>> +if (dup2 (STDOUT_FILENO, STDERR_FILENO) < 0) {
>> +perror ("dup2");
>> +return 1;
>> +}
>> +} else {
>> +int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644);
>
> I think this should include O_TRUNC; otherwise it's too error-prone to
> use programmatically. 

You're right! I thought this one night and was supposed check that it is
O_TRUNC there -- forgot and obviously it wasn't ;/

> The permissions should be 0666 (if the user's
> umask says things should be group or world writable, it's not our job
> to disagree).

I agree that 0644 is incorrect -- but IMHO it should be 0600 -- when the
data is written to /tmp world-readable file gave others chance to read
potentially sensitive information from that file...

I'll ask this (also) in IRC -- if people generally agree the bits should
be 0666 I'll do that change instead (even personally opposing ATM).

I'll also do the man and NEWS chances suggested for v3.

Thanks for the review (this also goes to Jani & Mark).

Tomi

>> +if (fd < 0) {
>> +fprintf (stderr, "Error: Cannot redirect stderr to '%s': %s\n",
>> + stderr_file, strerror (errno));
>> +return 1;
>> +}
>> +if (fd != STDERR_FILENO) {
>> +if (dup2 (fd, STDERR_FILENO) < 0) {
>> +perror ("dup2");
>> +return 1;
>> +}
>> +close (fd);
>> +}
>> +}
>> +return 0;
>> +}
>> +
>>  int
>>  main (int argc, char *argv[])
>>  {
>> @@ -259,6 +285,7 @@ main (int argc, char *argv[])
>>  const char *command_name = NULL;
>>  command_t *command;
>>  char *config_file_name = NULL;
>> +char *stderr_file = NULL;
>>  notmuch_config_t *config;
>>  notmuch_bool_t print_help=FALSE, print_version=FALSE;
>>  int opt_index;
>> @@ -268,6 +295,7 @@ main (int argc, char *argv[])
>>  { NOTMUCH_OPT_BOOLEAN, _help, "help", 'h', 0 },
>>  { NOTMUCH_OPT_BOOLEAN, _version, "version", 'v', 0 },
>>  { NOTMUCH_OPT_STRING, _file_name, "config", 'c', 0 },
>> +{ NOTMUCH_OPT_STRING, _file, "stderr", '\0', 0 },
>>  { 0, 0, 0, 0, 0 }
>>  };
>>  
>> @@ -287,6 +315,10 @@ main (int argc, char *argv[])
>>  return 1;
>>  }
>>  
>> +if (stderr_file && redirect_stderr (stderr_file) != 0) {
>> +/* error already printed */
>> +return 1;
>> +}
>>  if (print_help)
>>  return notmuch_help_command (NULL, argc - 1, [1]);
>>  
> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 0/4] emacs: Part command improvements

2013-05-28 Thread Mark Walters
Austin Clements  writes:

> This is a follow-up of sorts to id:"8761ycc19t.fsf at qmul.ac.uk", where
> Mark suggested that the part handling commands could all use the
> correponding mm-* functions.  I ran with the idea and wound up with
> this series, which, in addition to standardizing on the mm-* functions
> for everything and simplifying the implementation overall, decouples
> the part commands from part buttons, which removes an entire layer
> from the implementation and adds the ability to invoke part commands
> with point anywhere in a part (something I often find myself wanting).

Overall I really like this series. In addition to the clean up etc it
makes it easy to export the text/plain part (which doesn't have a part
button). I have recollection of this being difficult if it is base64
encoded.

I have a few small comments

As mentioned on irc (just included here in case other people are
testing) make-composed-keymap is emacs 24 only.

This does change the default directory for saving: not serious but it's
probably worth deciding do we want to use mailcap-download-directory or
home or where emacs was started or?

I don't know if we want to keep a special keymap for the button or just
always use the . prefix; the advantage is that you don't have 's' on a
button acting differently from 's' in the text (which has annoyed me
several times) otoh it is the extra keystroke which may annoy people
too. Let the bikeshedding begin! (obviously return for the default
action would remain.

Would it be worth having . return in the part body  as the default
action ?

Finally, with message indenting it's the start/end of the part are a
little unclear. I think it's the [ of the part button at the start of
the part to the character before the [ of the next part button. In
particular on the line of a new part but before the button is still the
old part. Since parts are whole lines it would be nice if the region
were line based but I don't know if that is easy.

Best wishes

Mark





[PATCH 2/4] emacs: Record part p-list in a text property

2013-05-28 Thread Mark Walters

A couple of small nits:

Austin Clements  writes:

> This is similar to what we already do with the message p-list, though
> we apply the part's text property to the whole part's text, in
> contrast with the message p-list, which is (rather obscurely) only
> applied to the first character.
> ---
>  emacs/notmuch-lib.el  |   16 
>  emacs/notmuch-show.el |   13 -
>  2 files changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
> index 790136e..09ce25e 100644
> --- a/emacs/notmuch-lib.el
> +++ b/emacs/notmuch-lib.el
> @@ -360,6 +360,22 @@ OBJECT."
> below
> string))
>  
> +(defun notmuch-put-text-property-if-nil (start end property value
> + object)
> +  "Like `put-text-property', but only set the property where it is nil."
> +  (while (< start end)
> +(let ((start-nil (text-property-any start end property nil object)))
> +  (if (null start-nil)
> +   ;; There are no more nil regions; exit the loop
> +   (setq start end)
> + ;; Find the end of the nil region
> + (let ((end-nil
> +(or (text-property-not-all start-nil end property nil object)
> +end)))
> +   ;; Set the property
> +   (put-text-property start-nil end-nil property value object)
> +   (setq start end-nil))
> +
>  (defun notmuch-logged-error (msg  extra)
>"Log MSG and EXTRA to *Notmuch errors* and signal MSG.
>  
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index a080134..acd0b55 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -900,7 +900,10 @@ If HIDE is non-nil then initially hide this part."
>  ;; Ensure that the part ends with a carriage return.
>  (unless (bolp)
>(insert "\n"))
> -(notmuch-show-create-part-overlays msg beg (point) hide)))
> +(notmuch-show-create-part-overlays msg beg (point) hide)
> +;; Record part information.  Since we already inserted subparts,
> +;; don't override exiting :notmuch-part properties.
 ^^^
existing

> +(notmuch-put-text-property-if-nil beg (point) :notmuch-part part)))
>  
>  (defun notmuch-show-insert-body (msg body depth)
>"Insert the body BODY at depth DEPTH in the current thread."
> @@ -1404,6 +1407,14 @@ Some useful entries are:
>  (notmuch-show-move-to-message-top)
>  (get-text-property (point) :notmuch-message-properties)))
>  
> +(defun notmuch-show-get-part-properties ()
> +  "Return the properties of the part containing point.
> +
> +This is the part property list retrieved from the CLI.  Signals
> +an error if there is no part containing point."

I think something here should say innermost part or something similar.

Best wishes

Mark


> +  (or (get-text-property (point) :notmuch-part)
> +  (error "No message part here")))
> +
>  (defun notmuch-show-set-prop (prop val  props)
>(let ((inhibit-read-only t)
>   (props (or props
> -- 
> 1.7.10.4


Re: The Python bindings are now back on PyPI

2013-05-28 Thread Julian Berman
Looks like remnants from the first time it was there. I'll update that link
but it may take a bit, PyPI is being upgraded so the upload mechanism is
down currently.

Julian


On Mon, May 27, 2013 at 5:31 AM, Justus Winter 
4win...@informatik.uni-hamburg.de wrote:

 Hi :)

 Quoting Julian Berman (2013-05-26 16:27:31)
  I've queried gently to find out if anyone was interested in putting the
 Python
  bindings back on PyPI a few times in IRC before, and didn't really see
 much
  interest one way or the other. I saw a mailing list post that seemed
  indifferent, though it brought up that version mismatches would cause
 runtime
  errors,which I think is OK, it's still useful to be able to install the
  corresponding version (e.g. homebrew on OSX currently packages notmuch
 0.14 but
  does not by default install the bindings, which is good for me, because
 I only
  want them installed in a virtualenv, so I'd like to be able to `pip
 install
  notmuch==0.14).
 
 
  So I took the liberty of re-uploading them. They're here: https://
  pypi.python.org/pypi/notmuch

 There are two links to documentation, one in the paragraph above
 Requirements, one in the list below the download box. The first link
 is correct, http://pythonhosted.org/notmuch/ is severely outdated
 (0.9rc1). Dunno who put the docs there (autogenerated from pypi
 packages?).

 Justus

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v2 1/4] cli: add global option --stderr=FILE

2013-05-28 Thread Tomi Ollila
On Tue, May 28 2013, Austin Clements amdra...@mit.edu wrote:

 Quoth Tomi Ollila on May 26 at 11:45 am:
 With this option all writes to stderr are redirected to the spesified
 FILE (or to stdout on case FILE is '-'). This is immediately useful
 in emacs interface as some of its exec intefaces do not provide
 separation of stdout and stderr.
 ---
  notmuch-client.h |  1 +
  notmuch.c| 32 
  2 files changed, 33 insertions(+)
 
 diff --git a/notmuch-client.h b/notmuch-client.h
 index 45749a6..4a3c7ac 100644
 --- a/notmuch-client.h
 +++ b/notmuch-client.h
 @@ -54,6 +54,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;
  #include sys/stat.h
  #include sys/time.h
  #include unistd.h
 +#include fcntl.h
  #include dirent.h
  #include errno.h
  #include signal.h
 diff --git a/notmuch.c b/notmuch.c
 index f51a84f..654a568 100644
 --- a/notmuch.c
 +++ b/notmuch.c
 @@ -251,6 +251,32 @@ notmuch_command (notmuch_config_t *config,
  return 0;
  }
  
 +static int
 +redirect_stderr (const char * stderr_file)
 +{
 +if (strcmp (stderr_file, -) == 0) {
 +if (dup2 (STDOUT_FILENO, STDERR_FILENO)  0) {
 +perror (dup2);
 +return 1;
 +}
 +} else {
 +int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644);

 I think this should include O_TRUNC; otherwise it's too error-prone to
 use programmatically. 

You're right! I thought this one night and was supposed check that it is
O_TRUNC there -- forgot and obviously it wasn't ;/

 The permissions should be 0666 (if the user's
 umask says things should be group or world writable, it's not our job
 to disagree).

I agree that 0644 is incorrect -- but IMHO it should be 0600 -- when the
data is written to /tmp world-readable file gave others chance to read
potentially sensitive information from that file...

I'll ask this (also) in IRC -- if people generally agree the bits should
be 0666 I'll do that change instead (even personally opposing ATM).

I'll also do the man and NEWS chances suggested for v3.

Thanks for the review (this also goes to Jani  Mark).

Tomi

 +if (fd  0) {
 +fprintf (stderr, Error: Cannot redirect stderr to '%s': %s\n,
 + stderr_file, strerror (errno));
 +return 1;
 +}
 +if (fd != STDERR_FILENO) {
 +if (dup2 (fd, STDERR_FILENO)  0) {
 +perror (dup2);
 +return 1;
 +}
 +close (fd);
 +}
 +}
 +return 0;
 +}
 +
  int
  main (int argc, char *argv[])
  {
 @@ -259,6 +285,7 @@ main (int argc, char *argv[])
  const char *command_name = NULL;
  command_t *command;
  char *config_file_name = NULL;
 +char *stderr_file = NULL;
  notmuch_config_t *config;
  notmuch_bool_t print_help=FALSE, print_version=FALSE;
  int opt_index;
 @@ -268,6 +295,7 @@ main (int argc, char *argv[])
  { NOTMUCH_OPT_BOOLEAN, print_help, help, 'h', 0 },
  { NOTMUCH_OPT_BOOLEAN, print_version, version, 'v', 0 },
  { NOTMUCH_OPT_STRING, config_file_name, config, 'c', 0 },
 +{ NOTMUCH_OPT_STRING, stderr_file, stderr, '\0', 0 },
  { 0, 0, 0, 0, 0 }
  };
  
 @@ -287,6 +315,10 @@ main (int argc, char *argv[])
  return 1;
  }
  
 +if (stderr_file  redirect_stderr (stderr_file) != 0) {
 +/* error already printed */
 +return 1;
 +}
  if (print_help)
  return notmuch_help_command (NULL, argc - 1, argv[1]);
  
 ___
 notmuch mailing list
 notmuch@notmuchmail.org
 http://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v5 03/12] cli: add insert command

2013-05-28 Thread Peter Wang
On Sun, 28 Apr 2013 00:24:28 +0300, Jani Nikula j...@nikula.org wrote:
 On Wed, 03 Apr 2013, Peter Wang noval...@gmail.com wrote:
  The notmuch insert command reads a message from standard input,
  writes it to a Maildir folder, and then incorporates the message into
  the notmuch database.  Essentially it moves the functionality of
  notmuch-deliver into notmuch.
 
  Though it could be used as an alternative to notmuch new, the reason
  I want this is to allow my notmuch frontend to add postponed or sent
  messages to the mail store and notmuch database, without resorting to
  another tool (e.g. notmuch-deliver) nor directly modifying the maildir.
  ---
   Makefile.local   |   1 +
   notmuch-client.h |   3 +
   notmuch-insert.c | 336 
  +++
   notmuch.c|   3 +
   4 files changed, 343 insertions(+)
   create mode 100644 notmuch-insert.c
 
...
  +/* Add the specified message file to the notmuch database, applying tags.
  + * The file is renamed to encode notmuch tags as maildir flags. */
  +static notmuch_bool_t
  +add_file_to_database (notmuch_database_t *notmuch, const char *path,
  + tag_op_list_t *tag_ops)
  +{
  +notmuch_message_t *message;
  +notmuch_status_t status;
  +
  +status = notmuch_database_add_message (notmuch, path, message);
  +switch (status) {
  +case NOTMUCH_STATUS_SUCCESS:
  +case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
  +   break;
  +default:
  +case NOTMUCH_STATUS_FILE_NOT_EMAIL:
 
 If such a message really arrives, the mail system will keep trying if
 failure is returned. Maybe deliver the file without indexing, and return
 success?
 

Rethinking it, if notmuch insert is going to used as a general mail
delivery tool (not my own use case) then its primary job should be to
get the file to disk.  As long as that is done, we should return success.

Indexing the message would be considered a bonus, and failure there
or in syncing tags to flags should not cause the file to be deleted and
an error code returned.  (A warning can be written to standard error.)

  +case NOTMUCH_STATUS_READ_ONLY_DATABASE:
  +case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
  +case NOTMUCH_STATUS_OUT_OF_MEMORY:
  +case NOTMUCH_STATUS_FILE_ERROR:
  +case NOTMUCH_STATUS_NULL_POINTER:
  +case NOTMUCH_STATUS_TAG_TOO_LONG:
  +case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
  +case NOTMUCH_STATUS_UNBALANCED_ATOMIC:
  +case NOTMUCH_STATUS_LAST_STATUS:
  +   fprintf (stderr, Error: failed to add `%s' to notmuch database: %s\n,
  +path, notmuch_status_to_string (status));
  +   return FALSE;
  +}
  +
  +if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
  +   /* Don't change tags of an existing message. */
  +   status = notmuch_message_tags_to_maildir_flags (message);
  +   if (status != NOTMUCH_STATUS_SUCCESS)
  +   fprintf (stderr, Error: failed to sync tags to maildir flags\n);
  +} else {
  +   status = tag_op_list_apply (message, tag_ops, TAG_FLAG_MAILDIR_SYNC);
 
 Syncing tags to maildir flags is more interesting here than above. And
 it should be done because notmuch insert allows arbitrary tags on the
 command line. Having, for example, -unread or +flagged on the command
 line makes the flags go out of sync. (notmuch new should do the syncing
 too, but it's less important because it only adds new.tags.)
 
 However, calling notmuch_message_tags_to_maildir_flags() may rename the
 file from new to cur, which blows up the directory syncing and file
 unlinking on the error path in insert_message() below.

We would sidestep these problems.

  +static notmuch_bool_t
  +insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
  +   const char *dir, tag_op_list_t *tag_ops)
  +{
  +char *tmppath;
  +char *newpath;
  +char *newdir;
  +int fdout;
  +char *cleanup_path;
  +
  +fdout = maildir_open_tmp_file (ctx, dir, tmppath, newpath, newdir);
  +if (fdout  0)
  +   return FALSE;
  +
  +cleanup_path = tmppath;
  +
  +if (! copy_stdin (fdin, fdout))
  +   goto FAIL;
  +
  +if (fsync (fdout) != 0) {
  +   fprintf (stderr, Error: fsync failed: %s\n, strerror (errno));
  +   goto FAIL;
  +}
  +
  +close (fdout);
  +fdout = -1;
  +
  +/* Atomically move the new message file from the Maildir 'tmp' 
  directory
  + * to the 'new' directory.  We follow the Dovecot recommendation to
  + * simply use rename() instead of link() and unlink().
  + * See also: 
  http://wiki.dovecot.org/MailboxFormat/Maildir#Mail_delivery
  + */
  +if (rename (tmppath, newpath) != 0) {
  +   fprintf (stderr, Error: rename() failed: %s\n, strerror (errno));
  +   goto FAIL;
  +}
  +
  +cleanup_path = newpath;
  +
  +if (! add_file_to_database (notmuch, newpath, tag_ops)) {
  +   /* XXX add an option to keep the file in maildir? */
 
 Possibly a good idea to let the user decide. This is the part 

[PATCH v3 2/4] test: added --stderr=FILE tests

2013-05-28 Thread Tomi Ollila
--stderr=FILE tests were added to test/help-test as it is the one
doing most global option testing. Also, it was simplest to test
this new option using `notmuch help` command.
---
 test/help-test | 9 +
 1 file changed, 9 insertions(+)

diff --git a/test/help-test b/test/help-test
index f7df725..bd0111c 100755
--- a/test/help-test
+++ b/test/help-test
@@ -9,4 +9,13 @@ test_expect_success 'notmuch help' 'notmuch help'
 test_expect_success 'notmuch help tag' 'notmuch help tag'
 test_expect_success 'notmuch --version' 'notmuch --version'
 
+test_begin_subtest notmuch --stderr=stderr help %
+notmuch --stderr=stderr help %
+test_expect_equal $(cat stderr) 
+Sorry, % is not a known command. There's not much I can do to help.
+
+test_begin_subtest notmuch --stderr=- help %
+test_expect_equal $(notmuch --stderr=- help %) 
+Sorry, % is not a known command. There's not much I can do to help.
+
 test_done
-- 
1.8.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3 3/4] man: documented --stderr=FILE in notmuch.1 manual page

2013-05-28 Thread Tomi Ollila
---
 man/man1/notmuch.1 | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/man/man1/notmuch.1 b/man/man1/notmuch.1
index 033cc10..f5ca0ad 100644
--- a/man/man1/notmuch.1
+++ b/man/man1/notmuch.1
@@ -76,7 +76,14 @@ Print the installed version of notmuch, and exit.
 
 Specify the configuration file to use. This overrides any
 configuration file specified by ${NOTMUCH_CONFIG}.
+.RE
+
+.RS 4
+.TP 4
+.B \-\-stderr=FILE
 
+Redirect all writes to stderr to the specified file.
+If FILE is '-', stderr is redirected to stdout.
 .RE
 
 .SH COMMANDS
-- 
1.8.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3 1/4] cli: add global option --stderr=FILE

2013-05-28 Thread Tomi Ollila
With this option all writes to stderr are redirected to the spesified
FILE (or to stdout on case FILE is '-'). This is immediately useful
in emacs interface as some of its exec intefaces do not provide
separation of stdout and stderr.
---
 notmuch-client.h |  1 +
 notmuch.c| 32 
 2 files changed, 33 insertions(+)

diff --git a/notmuch-client.h b/notmuch-client.h
index 45749a6..4a3c7ac 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -54,6 +54,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;
 #include sys/stat.h
 #include sys/time.h
 #include unistd.h
+#include fcntl.h
 #include dirent.h
 #include errno.h
 #include signal.h
diff --git a/notmuch.c b/notmuch.c
index f51a84f..15e90c8 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -251,6 +251,32 @@ notmuch_command (notmuch_config_t *config,
 return 0;
 }
 
+static int
+redirect_stderr (const char * stderr_file)
+{
+if (strcmp (stderr_file, -) == 0) {
+   if (dup2 (STDOUT_FILENO, STDERR_FILENO)  0) {
+   perror (dup2);
+   return 1;
+   }
+} else {
+   int fd = open (stderr_file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
+   if (fd  0) {
+   fprintf (stderr, Error: Cannot redirect stderr to '%s': %s\n,
+stderr_file, strerror (errno));
+   return 1;
+   }
+   if (fd != STDERR_FILENO) {
+   if (dup2 (fd, STDERR_FILENO)  0) {
+   perror (dup2);
+   return 1;
+   }
+   close (fd);
+   }
+}
+return 0;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -259,6 +285,7 @@ main (int argc, char *argv[])
 const char *command_name = NULL;
 command_t *command;
 char *config_file_name = NULL;
+char *stderr_file = NULL;
 notmuch_config_t *config;
 notmuch_bool_t print_help=FALSE, print_version=FALSE;
 int opt_index;
@@ -268,6 +295,7 @@ main (int argc, char *argv[])
{ NOTMUCH_OPT_BOOLEAN, print_help, help, 'h', 0 },
{ NOTMUCH_OPT_BOOLEAN, print_version, version, 'v', 0 },
{ NOTMUCH_OPT_STRING, config_file_name, config, 'c', 0 },
+   { NOTMUCH_OPT_STRING, stderr_file, stderr, '\0', 0 },
{ 0, 0, 0, 0, 0 }
 };
 
@@ -287,6 +315,10 @@ main (int argc, char *argv[])
return 1;
 }
 
+if (stderr_file  redirect_stderr (stderr_file) != 0) {
+   /* error already printed */
+   return 1;
+}
 if (print_help)
return notmuch_help_command (NULL, argc - 1, argv[1]);
 
-- 
1.8.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3 4/4] NEWS: added information about new --stderr=FILE top level option

2013-05-28 Thread Tomi Ollila
---
 NEWS | 5 +
 1 file changed, 5 insertions(+)

diff --git a/NEWS b/NEWS
index a7f2ec6..80abd97 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,11 @@ Top level option to specify configuration file
   It's now possible to specify the configuration file to use on the
   command line using the `notmuch --config=FILE` option.
 
+Top level option to redirect writes to stderr
+
+  With `notmuch --stderr=FILE` all writes to stderr are redirected to
+  the specified file. If FILE is '-', stderr is redirected to stdout.
+
 Deprecated commands part and search-tags are removed.
 
 Bash command-line completion
-- 
1.8.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


v3 of --stderr=FILE patches

2013-05-28 Thread Tomi Ollila
This is v3 of id:1369557954-13439-1-git-send-email-tomi.oll...@iki.fi

In id:m2a9nfr4tb@guru.guru-group.fi I suggested to use 0600 as
permission bits so that files written to /tmp would not have write
bits set in any case. That would have been inconsistent what is
normally expected in redirection cases. The problem I described
is easily avoided in emacs as (make-temp-file nmerr) will create
file /tmp/nmerrXX with permissions 0600 -- and writing to
that already-created file will not change its permissions. Writing
elsewhere is usually covered with directory permissions.


Diffdiff from v2 is shown below.

diff --git a/NEWS b/NEWS
index 990b038..80abd97 100644
--- a/NEWS
+++ b/NEWS
@@ -38,8 +38,7 @@ Top level option to specify configuration file
 Top level option to redirect writes to stderr
 
   With `notmuch --stderr=FILE` all writes to stderr are redirected to
-  the specified file. If the file name is a plain '-', stderr is
-  written to stdout.
+  the specified file. If FILE is '-', stderr is redirected to stdout.
 
 Deprecated commands part and search-tags are removed.
 
diff --git a/man/man1/notmuch.1 b/man/man1/notmuch.1
index fbd575a..f5ca0ad 100644
--- a/man/man1/notmuch.1
+++ b/man/man1/notmuch.1
@@ -83,7 +83,7 @@ configuration file specified by ${NOTMUCH_CONFIG}.
 .B \-\-stderr=FILE
 
 Redirect all writes to stderr to the specified file.
-If the file name is a plain '-', stderr is written to stdout.
+If FILE is '-', stderr is redirected to stdout.
 .RE
 
 .SH COMMANDS
diff --git a/notmuch.c b/notmuch.c
index 654a568..15e90c8 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -260,7 +260,7 @@ redirect_stderr (const char * stderr_file)
return 1;
}
 } else {
-   int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644);
+   int fd = open (stderr_file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (fd  0) {
fprintf (stderr, Error: Cannot redirect stderr to '%s': %s\n,
 stderr_file, strerror (errno));


From Tomi Ollila tomi.oll...@iki.fi # This line is ignored.

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 0/8] packaging: fedora: general updates

2013-05-28 Thread Felipe Contreras
On Sat, May 25, 2013 at 7:41 AM, David Bremner da...@tethera.net wrote:

 At this point we wait for somebody (else) with Fedora expertise to
 review the patches.

Like who? I though the reason these were never updated is that there
wasn't anybody else.

-- 
Felipe Contreras
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] Fix shared library loading in Python bindings.

2013-05-28 Thread Julian Berman
Specifically, fixes loading on OS X, where libnotmuch will be
a dylib.:
---
 bindings/python/notmuch/globals.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bindings/python/notmuch/globals.py 
b/bindings/python/notmuch/globals.py
index c7632c3..5e08e73 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -18,11 +18,12 @@ Copyright 2010 Sebastian Spaeth sebast...@sspaeth.de
 
 
 from ctypes import CDLL, Structure, POINTER
+from ctypes.util import find_library
 
 #-
 #package-global instance of the notmuch library
 try:
-nmlib = CDLL(libnotmuch.so.3)
+nmlib = CDLL(find_library(libnotmuch))
 except:
 raise ImportError(Could not find shared 'notmuch' library.)
 
-- 
1.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch