Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / 06 / cd85e37e0a88981084c656dcafefc11bfbc905
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 arlo.cworth.org (Postfix) with ESMTP id 558576DE0360\r
6  for <notmuch@notmuchmail.org>; Tue,  2 Aug 2016 21:38:57 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.005\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5\r
12  tests=[AWL=-0.006, HEADER_FROM_DIFFERENT_DOMAINS=0.001]\r
13  autolearn=disabled\r
14 Received: from arlo.cworth.org ([127.0.0.1])\r
15  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
16  with ESMTP id fOqQ3axHE4eS for <notmuch@notmuchmail.org>;\r
17  Tue,  2 Aug 2016 21:38:49 -0700 (PDT)\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id 623116DE02AF\r
20  for <notmuch@notmuchmail.org>; Tue,  2 Aug 2016 21:38:27 -0700 (PDT)\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2)\r
22  (envelope-from <bremner@tesseract.cs.unb.ca>)\r
23  id 1bUnx5-0000Ge-Js; Wed, 03 Aug 2016 00:38:43 -0400\r
24 Received: (nullmailer pid 12789 invoked by uid 1000);\r
25  Wed, 03 Aug 2016 00:30:32 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 6/8] CLI: refactor dumping of tags.\r
29 Date: Wed,  3 Aug 2016 09:30:26 +0900\r
30 Message-Id: <1470184228-12517-7-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.8.1\r
32 In-Reply-To: <1470184228-12517-1-git-send-email-david@tethera.net>\r
33 References: <1470184228-12517-1-git-send-email-david@tethera.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.20\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Wed, 03 Aug 2016 04:38:57 -0000\r
47 \r
48 This is mainly code movement, to make room in the loop over messages for\r
49 dumping properties.\r
50 ---\r
51  notmuch-dump.c | 127 +++++++++++++++++++++++++++++++--------------------------\r
52  1 file changed, 69 insertions(+), 58 deletions(-)\r
53 \r
54 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
55 index cae1db8..d80ed8b8 100644\r
56 --- a/notmuch-dump.c\r
57 +++ b/notmuch-dump.c\r
58 @@ -78,13 +78,78 @@ print_dump_header (gzFile output, int output_format, int include)\r
59  }\r
60  \r
61  static int\r
62 +dump_tags_message (void *ctx,\r
63 +                  notmuch_message_t *message, int output_format,\r
64 +                  gzFile output,\r
65 +                  char **buffer_p, size_t *size_p)\r
66 +{\r
67 +    int first = 1;\r
68 +    const char *message_id;\r
69 +\r
70 +    message_id = notmuch_message_get_message_id (message);\r
71 +\r
72 +    if (output_format == DUMP_FORMAT_BATCH_TAG &&\r
73 +       strchr (message_id, '\n')) {\r
74 +       /* This will produce a line break in the output, which\r
75 +        * would be difficult to handle in tools.  However, it's\r
76 +        * also impossible to produce an email containing a line\r
77 +        * break in a message ID because of unfolding, so we can\r
78 +        * safely disallow it. */\r
79 +       fprintf (stderr, "Warning: skipping message id containing line break: \"%s\"\n", message_id);\r
80 +       return EXIT_SUCCESS;\r
81 +    }\r
82 +\r
83 +    if (output_format == DUMP_FORMAT_SUP) {\r
84 +       gzprintf (output, "%s (", message_id);\r
85 +    }\r
86 +\r
87 +    for (notmuch_tags_t *tags = notmuch_message_get_tags (message);\r
88 +        notmuch_tags_valid (tags);\r
89 +        notmuch_tags_move_to_next (tags)) {\r
90 +       const char *tag_str = notmuch_tags_get (tags);\r
91 +\r
92 +       if (! first)\r
93 +           gzputs (output, " ");\r
94 +\r
95 +       first = 0;\r
96 +\r
97 +       if (output_format == DUMP_FORMAT_SUP) {\r
98 +           gzputs (output, tag_str);\r
99 +       } else {\r
100 +           if (hex_encode (ctx, tag_str,\r
101 +                           buffer_p, size_p) != HEX_SUCCESS) {\r
102 +               fprintf (stderr, "Error: failed to hex-encode tag %s\n",\r
103 +                        tag_str);\r
104 +               return EXIT_FAILURE;\r
105 +           }\r
106 +           gzprintf (output, "+%s", *buffer_p);\r
107 +       }\r
108 +    }\r
109 +\r
110 +    if (output_format == DUMP_FORMAT_SUP) {\r
111 +       gzputs (output, ")\n");\r
112 +    } else {\r
113 +       if (make_boolean_term (ctx, "id", message_id,\r
114 +                              buffer_p, size_p)) {\r
115 +           fprintf (stderr, "Error quoting message id %s: %s\n",\r
116 +                    message_id, strerror (errno));\r
117 +           return EXIT_FAILURE;\r
118 +       }\r
119 +       gzprintf (output, " -- %s\n", *buffer_p);\r
120 +    }\r
121 +    return EXIT_SUCCESS;\r
122 +}\r
123 +\r
124 +static int\r
125  database_dump_file (notmuch_database_t *notmuch, gzFile output,\r
126                     const char *query_str, int output_format, int include)\r
127  {\r
128      notmuch_query_t *query;\r
129      notmuch_messages_t *messages;\r
130      notmuch_message_t *message;\r
131 -    notmuch_tags_t *tags;\r
132 +    notmuch_status_t status;\r
133 +    char *buffer = NULL;\r
134 +    size_t buffer_size = 0;\r
135  \r
136      print_dump_header (output, output_format, include);\r
137  \r
138 @@ -110,10 +175,6 @@ database_dump_file (notmuch_database_t *notmuch, gzFile output,\r
139       */\r
140      notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
141  \r
142 -    char *buffer = NULL;\r
143 -    size_t buffer_size = 0;\r
144 -    notmuch_status_t status;\r
145 -\r
146      status = notmuch_query_search_messages_st (query, &messages);\r
147      if (print_status_query ("notmuch dump", query, status))\r
148         return EXIT_FAILURE;\r
149 @@ -121,62 +182,12 @@ database_dump_file (notmuch_database_t *notmuch, gzFile output,\r
150      for (;\r
151          notmuch_messages_valid (messages);\r
152          notmuch_messages_move_to_next (messages)) {\r
153 -       int first = 1;\r
154 -       const char *message_id;\r
155  \r
156         message = notmuch_messages_get (messages);\r
157 -       message_id = notmuch_message_get_message_id (message);\r
158 -\r
159 -       if (output_format == DUMP_FORMAT_BATCH_TAG &&\r
160 -           strchr (message_id, '\n')) {\r
161 -           /* This will produce a line break in the output, which\r
162 -            * would be difficult to handle in tools.  However, it's\r
163 -            * also impossible to produce an email containing a line\r
164 -            * break in a message ID because of unfolding, so we can\r
165 -            * safely disallow it. */\r
166 -           fprintf (stderr, "Warning: skipping message id containing line break: \"%s\"\n", message_id);\r
167 -           notmuch_message_destroy (message);\r
168 -           continue;\r
169 -       }\r
170  \r
171 -       if (output_format == DUMP_FORMAT_SUP) {\r
172 -           gzprintf (output, "%s (", message_id);\r
173 -       }\r
174 -\r
175 -       for (tags = notmuch_message_get_tags (message);\r
176 -            notmuch_tags_valid (tags);\r
177 -            notmuch_tags_move_to_next (tags)) {\r
178 -           const char *tag_str = notmuch_tags_get (tags);\r
179 -\r
180 -           if (! first)\r
181 -               gzputs (output, " ");\r
182 -\r
183 -           first = 0;\r
184 -\r
185 -           if (output_format == DUMP_FORMAT_SUP) {\r
186 -               gzputs (output, tag_str);\r
187 -           } else {\r
188 -               if (hex_encode (notmuch, tag_str,\r
189 -                               &buffer, &buffer_size) != HEX_SUCCESS) {\r
190 -                   fprintf (stderr, "Error: failed to hex-encode tag %s\n",\r
191 -                            tag_str);\r
192 -                   return EXIT_FAILURE;\r
193 -               }\r
194 -               gzprintf (output, "+%s", buffer);\r
195 -           }\r
196 -       }\r
197 -\r
198 -       if (output_format == DUMP_FORMAT_SUP) {\r
199 -           gzputs (output, ")\n");\r
200 -       } else {\r
201 -           if (make_boolean_term (notmuch, "id", message_id,\r
202 -                                  &buffer, &buffer_size)) {\r
203 -                   fprintf (stderr, "Error quoting message id %s: %s\n",\r
204 -                            message_id, strerror (errno));\r
205 -                   return EXIT_FAILURE;\r
206 -           }\r
207 -           gzprintf (output, " -- %s\n", buffer);\r
208 -       }\r
209 +       if (dump_tags_message (notmuch, message, output_format, output,\r
210 +                              &buffer, &buffer_size))\r
211 +           return EXIT_FAILURE;\r
212  \r
213         notmuch_message_destroy (message);\r
214      }\r
215 -- \r
216 2.8.1\r
217 \r