Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / d0 / 56ec382a10cced230d0260ab17528ce8bf7fcd
1 Return-Path: <bremner@tethera.net>\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 1CDF1431FCB\r
6         for <notmuch@notmuchmail.org>; Sat,  8 Dec 2012 07:08:20 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id FH7svC+sRZIr for <notmuch@notmuchmail.org>;\r
16         Sat,  8 Dec 2012 07:08:18 -0800 (PST)\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
18         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id A09B0431E82\r
21         for <notmuch@notmuchmail.org>; Sat,  8 Dec 2012 07:08:14 -0800 (PST)\r
22 Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net\r
23         ([142.167.90.129] helo=zancas.localnet)\r
24         by tesseract.cs.unb.ca with esmtpsa\r
25         (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
26         (envelope-from <bremner@tethera.net>)\r
27         id 1ThM0j-0005dK-E1; Sat, 08 Dec 2012 11:08:13 -0400\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1ThM0d-0005Gf-Vm; Sat, 08 Dec 2012 11:08:08 -0400\r
31 From: david@tethera.net\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [Patch v4 01/10] notmuch-dump: add --format=(batch-tag|sup)\r
34 Date: Sat,  8 Dec 2012 11:07:47 -0400\r
35 Message-Id: <1354979276-20099-2-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.10.4\r
37 In-Reply-To: <1354979276-20099-1-git-send-email-david@tethera.net>\r
38 References: <1354979276-20099-1-git-send-email-david@tethera.net>\r
39 X-Spam_bar: -\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Sat, 08 Dec 2012 15:08:20 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 sup is the old format, and remains the default, at least until\r
58 restore is converted to parse this format.\r
59 \r
60 Each line of the batch-tag format is modelled on the syntax of notmuch tag:\r
61 - "notmuch tag" is omitted from the front of the line\r
62 - The dump format only uses query strings of a single message-id.\r
63 - Each space seperated tag/message-id is 'hex-encoded' to remove\r
64   trouble-making characters.\r
65 - It is permitted (and will be useful) for there to be no tags before\r
66   the query.\r
67 \r
68 In particular this format won't have the same problem with e.g. spaces\r
69 in message-ids or tags; they will be round-trip-able.\r
70 ---\r
71  dump-restore-private.h |   13 +++++++++++++\r
72  notmuch-dump.c         |   48 ++++++++++++++++++++++++++++++++++++++++++------\r
73  2 files changed, 55 insertions(+), 6 deletions(-)\r
74  create mode 100644 dump-restore-private.h\r
75 \r
76 diff --git a/dump-restore-private.h b/dump-restore-private.h\r
77 new file mode 100644\r
78 index 0000000..896a004\r
79 --- /dev/null\r
80 +++ b/dump-restore-private.h\r
81 @@ -0,0 +1,13 @@\r
82 +#ifndef DUMP_RESTORE_PRIVATE_H\r
83 +#define DUMP_RESTORE_PRIVATE_H\r
84 +\r
85 +#include "hex-escape.h"\r
86 +#include "command-line-arguments.h"\r
87 +\r
88 +typedef enum dump_formats {\r
89 +    DUMP_FORMAT_AUTO,\r
90 +    DUMP_FORMAT_BATCH_TAG,\r
91 +    DUMP_FORMAT_SUP\r
92 +} dump_format_t;\r
93 +\r
94 +#endif\r
95 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
96 index 88f598a..d2dad40 100644\r
97 --- a/notmuch-dump.c\r
98 +++ b/notmuch-dump.c\r
99 @@ -19,6 +19,7 @@\r
100   */\r
101  \r
102  #include "notmuch-client.h"\r
103 +#include "dump-restore-private.h"\r
104  \r
105  int\r
106  notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
107 @@ -43,7 +44,13 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
108      char *output_file_name = NULL;\r
109      int opt_index;\r
110  \r
111 +    int output_format = DUMP_FORMAT_SUP;\r
112 +\r
113      notmuch_opt_desc_t options[] = {\r
114 +       { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',\r
115 +         (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },\r
116 +                                 { "batch-tag", DUMP_FORMAT_BATCH_TAG },\r
117 +                                 { 0, 0 } } },\r
118         { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0  },\r
119         { 0, 0, 0, 0, 0 }\r
120      };\r
121 @@ -83,27 +90,56 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
122       */\r
123      notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
124  \r
125 +    char *buffer = NULL;\r
126 +    size_t buffer_size = 0;\r
127 +\r
128      for (messages = notmuch_query_search_messages (query);\r
129          notmuch_messages_valid (messages);\r
130          notmuch_messages_move_to_next (messages)) {\r
131         int first = 1;\r
132 +       const char *message_id;\r
133 +\r
134         message = notmuch_messages_get (messages);\r
135 +       message_id = notmuch_message_get_message_id (message);\r
136  \r
137 -       fprintf (output,\r
138 -                "%s (", notmuch_message_get_message_id (message));\r
139 +       if (output_format == DUMP_FORMAT_SUP) {\r
140 +           fprintf (output, "%s (", message_id);\r
141 +       }\r
142  \r
143         for (tags = notmuch_message_get_tags (message);\r
144              notmuch_tags_valid (tags);\r
145              notmuch_tags_move_to_next (tags)) {\r
146 -           if (! first)\r
147 -               fprintf (output, " ");\r
148 +           const char *tag_str = notmuch_tags_get (tags);\r
149  \r
150 -           fprintf (output, "%s", notmuch_tags_get (tags));\r
151 +           if (! first)\r
152 +               fputs (" ", output);\r
153  \r
154             first = 0;\r
155 +\r
156 +           if (output_format == DUMP_FORMAT_SUP) {\r
157 +               fputs (tag_str, output);\r
158 +           } else {\r
159 +               if (hex_encode (notmuch, tag_str,\r
160 +                               &buffer, &buffer_size) != HEX_SUCCESS) {\r
161 +                   fprintf (stderr, "Error: failed to hex-encode tag %s\n",\r
162 +                            tag_str);\r
163 +                   return 1;\r
164 +               }\r
165 +               fprintf (output, "+%s", buffer);\r
166 +           }\r
167         }\r
168  \r
169 -       fprintf (output, ")\n");\r
170 +       if (output_format == DUMP_FORMAT_SUP) {\r
171 +           fputs (")\n", output);\r
172 +       } else {\r
173 +           if (hex_encode (notmuch, message_id,\r
174 +                           &buffer, &buffer_size) != HEX_SUCCESS) {\r
175 +                   fprintf (stderr, "Error: failed to hex-encode msg-id %s\n",\r
176 +                            message_id);\r
177 +                   return 1;\r
178 +           }\r
179 +           fprintf (output, " -- id:%s\n", buffer);\r
180 +       }\r
181  \r
182         notmuch_message_destroy (message);\r
183      }\r
184 -- \r
185 1.7.10.4\r
186 \r