--- /dev/null
+Return-Path: <too@guru-group.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id C4436431FB6\r
+ for <notmuch@notmuchmail.org>; Tue, 21 May 2013 11:42:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id g2vnzCchdrmJ for <notmuch@notmuchmail.org>;\r
+ Tue, 21 May 2013 11:42:36 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 82B1B431FBF\r
+ for <notmuch@notmuchmail.org>; Tue, 21 May 2013 11:42:36 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+ id 05B871002C4; Tue, 21 May 2013 21:42:33 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 1/1] add --stderr option\r
+Date: Tue, 21 May 2013 21:42:30 +0300\r
+Message-Id: <1369161750-12342-1-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 1.8.0\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 21 May 2013 18:42:42 -0000\r
+\r
+---\r
+\r
+Note quickly written untested code (but compiles!), just to show an idea...\r
+\r
+This implements (i hope) curl(1) --stderr option in notmuch(1):\r
+\r
+ --stderr <file>\r
+ Redirect all writes to stderr to the specified file instead. If\r
+ the file name is a plain '-', it is instead written to stdout.\r
+\r
+This would be useful in emacs interface.\r
+\r
+Please comment; I'll do help and manual page changes (and NEWS) if\r
+this is good idea :D\r
+\r
+Tomi\r
+\r
+\r
+ notmuch.c | 20 ++++++++++++++++++++\r
+ 1 file changed, 20 insertions(+)\r
+\r
+diff --git a/notmuch.c b/notmuch.c\r
+index f51a84f..3b8bd5d 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -21,6 +21,7 @@\r
+ */\r
+ \r
+ #include "notmuch-client.h"\r
++#include <fcntl.h>\r
+ \r
+ typedef int (*command_function_t) (notmuch_config_t *config, int argc, char *argv[]);\r
+ \r
+@@ -259,6 +260,7 @@ main (int argc, char *argv[])\r
+ const char *command_name = NULL;\r
+ command_t *command;\r
+ char *config_file_name = NULL;\r
++ char *stderr_file = NULL;\r
+ notmuch_config_t *config;\r
+ notmuch_bool_t print_help=FALSE, print_version=FALSE;\r
+ int opt_index;\r
+@@ -268,6 +270,7 @@ main (int argc, char *argv[])\r
+ { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },\r
+ { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 },\r
++ { NOTMUCH_OPT_STRING, &stderr_file, "stderr", 'c', 0 },\r
+ { 0, 0, 0, 0, 0 }\r
+ };\r
+ \r
+@@ -295,6 +298,23 @@ main (int argc, char *argv[])\r
+ return 0;\r
+ }\r
+ \r
++ if (stderr_file) {\r
++ if (strcmp (stderr_file, "-") == 0)\r
++ dup2 (STDOUT_FILENO, STDERR_FILENO);\r
++ else {\r
++ int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644);\r
++ if (fd < 0) {\r
++ fprintf (stderr, "Error: Cannot redirect stderr to '%s': %s\n",\r
++ stderr_file, strerror(errno));\r
++ return 1;\r
++ }\r
++ if (fd != STDERR_FILENO) {\r
++ dup2 (fd, STDERR_FILENO);\r
++ close (fd);\r
++ }\r
++ }\r
++ }\r
++\r
+ if (opt_index < argc)\r
+ command_name = argv[opt_index];\r
+ \r
+-- \r
+1.8.1.4\r
+\r