[PATCH 8/9] cli: optionally restore message properties from dump file
[notmuch-archives.git] / b0 / dafc334f92ab20a0d4c79d0426dfcaa81b1f02
1 Return-Path: <jani@nikula.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 2CDF6431FBF\r
6         for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:08:03 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id RU+4LbszokoC for <notmuch@notmuchmail.org>;\r
17         Tue, 25 Mar 2014 10:07:59 -0700 (PDT)\r
18 Received: from mail-ee0-f52.google.com (mail-ee0-f52.google.com\r
19  [74.125.83.52])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
20  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
21  5BED8431FC0    for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:07:59 -0700\r
22  (PDT)\r
23 Received: by mail-ee0-f52.google.com with SMTP id e49so699698eek.11\r
24         for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:07:58 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=1e100.net; s=20130820;\r
27         h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
28         :references:in-reply-to:references;\r
29         bh=eUoxc5Cau1BOQncxLPyJmpBSprrtgIScYhtrM9R6Sm0=;\r
30         b=RHi3ji1bpszx3hTa2LG9I2oTTM5XjFqfs2EDVQ0iKuY3Jy1OWYtr2er1RCidNYor/j\r
31         TqnXnJhRpZfyuRwBoVTeD/vg34fe8CL+hnhxouwDXxw6woOmpl0vvu0kSMTBR7Zn10sK\r
32         /kHi2Jd/S+MBWTm666OTJ9ueeaBv9WByYxUHvq8GseU82Ar3fB2HE+RgJ7bbWIwLi7bj\r
33         cMGbL26CWVruTzTrg5GFCiCizmbAIxA471w38+Xt+AUbX8nItXq8GNB7N16bQRgNkOOZ\r
34         UW1mvBQxkPTn9KrxaQVoSZ2FPNAEFLQB13N2Hh0zIJ2WysTmVBznA4ucUcKqJQD2cLsC\r
35         RvtA==\r
36 X-Gm-Message-State:\r
37  ALoCoQmbBYXmakBWT57yoJqWXXGI0viTAb2tKrly7rz49KxF7evSigtjkaOhtQkde4uPd9+bvzVI\r
38 X-Received: by 10.14.39.65 with SMTP id c41mr1262236eeb.97.1395767277975;\r
39         Tue, 25 Mar 2014 10:07:57 -0700 (PDT)\r
40 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
41         [88.195.111.91])\r
42         by mx.google.com with ESMTPSA id y7sm22946700eev.5.2014.03.25.10.07.56\r
43         for <multiple recipients>\r
44         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
45         Tue, 25 Mar 2014 10:07:57 -0700 (PDT)\r
46 From: Jani Nikula <jani@nikula.org>\r
47 To: notmuch@notmuchmail.org\r
48 Subject: [PATCH 2/2] cli: abstract dump file open from the dump command\r
49 Date: Tue, 25 Mar 2014 19:07:50 +0200\r
50 Message-Id:\r
51  <92929cc512b9e9cd5ccb7d4e537671ce84de514f.1395767165.git.jani@nikula.org>\r
52 X-Mailer: git-send-email 1.9.0\r
53 In-Reply-To: <cover.1395767165.git.jani@nikula.org>\r
54 References: <cover.1395767165.git.jani@nikula.org>\r
55 In-Reply-To: <cover.1395767165.git.jani@nikula.org>\r
56 References: <cover.1395767165.git.jani@nikula.org>\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Tue, 25 Mar 2014 17:08:03 -0000\r
70 \r
71 No functional changes, except for slight improvement in error\r
72 handling.\r
73 ---\r
74  notmuch-dump.c | 43 ++++++++++++++++++++++++++++---------------\r
75  1 file changed, 28 insertions(+), 15 deletions(-)\r
76 \r
77 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
78 index 179e2e97bf61..88bef3f77e82 100644\r
79 --- a/notmuch-dump.c\r
80 +++ b/notmuch-dump.c\r
81 @@ -115,11 +115,37 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,\r
82      return EXIT_SUCCESS;\r
83  }\r
84  \r
85 +/* Dump database into output_file_name if it's non-NULL, stdout\r
86 + * otherwise.\r
87 + */\r
88 +static int\r
89 +database_dump (notmuch_database_t *notmuch, const char *output_file_name,\r
90 +              const char *query_str, int output_format)\r
91 +{\r
92 +    FILE *output = stdout;\r
93 +    int ret;\r
94 +\r
95 +    if (output_file_name) {\r
96 +       output = fopen (output_file_name, "w");\r
97 +       if (output == NULL) {\r
98 +           fprintf (stderr, "Error opening %s for writing: %s\n",\r
99 +                    output_file_name, strerror (errno));\r
100 +           return EXIT_FAILURE;\r
101 +       }\r
102 +    }\r
103 +\r
104 +    ret = database_dump_file (notmuch, output, query_str, output_format);\r
105 +\r
106 +    if (output != stdout)\r
107 +       fclose (output);\r
108 +\r
109 +    return ret;\r
110 +}\r
111 +\r
112  int\r
113  notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
114  {\r
115      notmuch_database_t *notmuch;\r
116 -    FILE *output = stdout;\r
117      const char *query_str = NULL;\r
118      int ret;\r
119  \r
120 @@ -145,16 +171,6 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
121      if (opt_index < 0)\r
122         return EXIT_FAILURE;\r
123  \r
124 -    if (output_file_name) {\r
125 -       output = fopen (output_file_name, "w");\r
126 -       if (output == NULL) {\r
127 -           fprintf (stderr, "Error opening %s for writing: %s\n",\r
128 -                    output_file_name, strerror (errno));\r
129 -           return EXIT_FAILURE;\r
130 -       }\r
131 -    }\r
132 -\r
133 -\r
134      if (opt_index < argc) {\r
135         query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);\r
136         if (query_str == NULL) {\r
137 @@ -163,10 +179,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
138         }\r
139      }\r
140  \r
141 -    ret = database_dump_file (notmuch, output, query_str, output_format);\r
142 -\r
143 -    if (output != stdout)\r
144 -       fclose (output);\r
145 +    ret = database_dump (notmuch, output_file_name, query_str, output_format);\r
146  \r
147      notmuch_database_destroy (notmuch);\r
148  \r
149 -- \r
150 1.9.0\r
151 \r