[PATCH v5 0/2] emacs: User-defined sections in notmuch-hello
[notmuch-archives.git] / 82 / 13d70b02bde9a7b32520aa2f465370460f506b
1 Return-Path: <anthony.j.towns@gmail.com>\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 043224196F2\r
6         for <notmuch@notmuchmail.org>; Sat, 10 Apr 2010 08:03:07 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.899\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.899 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham\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 EUKbabgtfdu2 for <notmuch@notmuchmail.org>;\r
17         Sat, 10 Apr 2010 08:03:06 -0700 (PDT)\r
18 Received: from mail-yw0-f187.google.com (mail-yw0-f187.google.com\r
19         [209.85.211.187])\r
20         by olra.theworths.org (Postfix) with ESMTP id D6FEE431FC1\r
21         for <notmuch@notmuchmail.org>; Sat, 10 Apr 2010 08:03:05 -0700 (PDT)\r
22 Received: by ywh17 with SMTP id 17so816203ywh.22\r
23         for <notmuch@notmuchmail.org>; Sat, 10 Apr 2010 08:03:05 -0700 (PDT)\r
24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
25         h=domainkey-signature:mime-version:sender:received:date\r
26         :x-google-sender-auth:received:message-id:subject:from:to\r
27         :content-type; bh=WQWH5nAUZwnz1o9Vj12pWs+XAS/tDeOKUqxcSY6dHPk=;\r
28         b=fEj49pk9mMO4GLMRZgHE/Ahb8g+aeM6k0TJaOZCOSS5V/Xn3+NbBftw7nyA0PJwubb\r
29         AcWcWRhdEPqdkOAuFJQQB6W+6mtiyWVuPUDBVkQITIX98dz95lXSrRDXv5eyXmIdvCWa\r
30         C1KLKft/CL4O7GKxJqkbL8nFfoKOJdG1cAb04=\r
31 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
32         h=mime-version:sender:date:x-google-sender-auth:message-id:subject\r
33         :from:to:content-type;\r
34         b=kPGxo3HrT3L/NQrGHPPy7Ls4bQ/osUPUKKZg0Z+cGpYv0NW5jfD9tO0Qw/wA4BoWmo\r
35         FM4IC6/lg8vIvp2GXictL19ln3RCZ09fz8caxpe3/BI/XbdbtqwI2KfW1cFD6jJZ/HeL\r
36         tXcMh/qzhgPz8QVAT/HKUPq4J51WYcCfHfWh8=\r
37 MIME-Version: 1.0\r
38 Sender: anthony.j.towns@gmail.com\r
39 Received: by 10.90.114.1 with HTTP; Sat, 10 Apr 2010 08:03:04 -0700 (PDT)\r
40 Date: Sun, 11 Apr 2010 01:03:04 +1000\r
41 X-Google-Sender-Auth: 5bef8ae0e3f058d7\r
42 Received: by 10.91.1.2 with SMTP id d2mr680895agi.121.1270911784490; Sat, 10 \r
43         Apr 2010 08:03:04 -0700 (PDT)\r
44 Message-ID: <n2x87b3a4191004100803z9d4c4c2bp52f5cf0d7b712362@mail.gmail.com>\r
45 Subject: [PATCH] notmuch new --new-tags=tags...\r
46 From: Anthony Towns <aj@erisian.com.au>\r
47 To: notmuch <notmuch@notmuchmail.org>\r
48 Content-Type: text/plain; charset=ISO-8859-1\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Sat, 10 Apr 2010 15:03:07 -0000\r
62 \r
63 Hi *,\r
64 \r
65 The attached patch makes "notmuch new --new-tags=unread,new" set the\r
66 "unread" and "new" tags on any new mail it finds rather than "unread"\r
67 and "inbox". Or whatever other tags you happen to specify.\r
68 \r
69 Signed-off-by: Anthony Towns <aj@erisian.com.au>\r
70 ---\r
71  NEWS          |    3 +++\r
72  notmuch-new.c |   49 +++++++++++++++++++++++++++++++++++++++++++++----\r
73  notmuch.1     |   19 ++++++++++++++++++-\r
74  notmuch.c     |    7 ++++++-\r
75  4 files changed, 72 insertions(+), 6 deletions(-)\r
76 \r
77 diff --git a/NEWS b/NEWS\r
78 index f29ac27..cbfae5a 100644\r
79 --- a/NEWS\r
80 +++ b/NEWS\r
81 @@ -1,3 +1,6 @@\r
82 +The "notmuch new" command accepts a "--new-tags=tags..." option to override\r
83 +the default tags applied to new mail.\r
84 +\r
85  Notmuch 0.1 (2010-04-05)\r
86  ========================\r
87  This is the first release of the notmuch mail system.\r
88 diff --git a/notmuch-new.c b/notmuch-new.c\r
89 index 44b50aa..77c99e0 100644\r
90 --- a/notmuch-new.c\r
91 +++ b/notmuch-new.c\r
92 @@ -32,6 +32,11 @@ typedef struct _filename_list {\r
93      _filename_node_t **tail;\r
94  } _filename_list_t;\r
95 \r
96 +typedef struct _tag_list {\r
97 +    char *tag;\r
98 +    struct _tag_list *next;\r
99 +} _tag_list_t;\r
100 +\r
101  typedef struct {\r
102      int output_is_a_tty;\r
103      int verbose;\r
104 @@ -41,6 +46,8 @@ typedef struct {\r
105      int added_messages;\r
106      struct timeval tv_start;\r
107 \r
108 +    _tag_list_t *new_msg_tags;\r
109 +\r
110      _filename_list_t *removed_files;\r
111      _filename_list_t *removed_directories;\r
112  } add_files_state_t;\r
113 @@ -93,11 +100,40 @@ _filename_list_add (_filename_list_t *list,\r
114      list->tail = &node->next;\r
115  }\r
116 \r
117 +static _tag_list_t *\r
118 +_parse_tags (void *ctx, const char *orig_str)\r
119 +{\r
120 +    _tag_list_t *tag_head = NULL, **tag_tail = &tag_head;\r
121 +    char *dupe_str, *start, *comma;\r
122 +\r
123 +    dupe_str = talloc_strdup(ctx, orig_str);\r
124 +    start = dupe_str;\r
125 +\r
126 +    do {\r
127 +       comma = strchr(start, ',');\r
128 +       if (comma)\r
129 +           *(comma++) = '\0';\r
130 +\r
131 +       if (*start != '\0') {\r
132 +           *tag_tail = talloc(dupe_str, _tag_list_t);\r
133 +           (*tag_tail)->tag = start;\r
134 +           (*tag_tail)->next = NULL;\r
135 +           tag_tail = &(*tag_tail)->next;\r
136 +       }\r
137 +\r
138 +       start = comma;\r
139 +    } while (start);\r
140 +\r
141 +    return tag_head;\r
142 +}\r
143 +\r
144  static void\r
145 -tag_inbox_and_unread (notmuch_message_t *message)\r
146 +tag_new_message (add_files_state_t *state, notmuch_message_t *message)\r
147  {\r
148 -    notmuch_message_add_tag (message, "inbox");\r
149 -    notmuch_message_add_tag (message, "unread");\r
150 +    _tag_list_t *cur;\r
151 +    for (cur = state->new_msg_tags; cur; cur = cur->next) {\r
152 +       notmuch_message_add_tag (message, cur->tag);\r
153 +    }\r
154  }\r
155 \r
156  static void\r
157 @@ -412,7 +448,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
158         /* success */\r
159         case NOTMUCH_STATUS_SUCCESS:\r
160             state->added_messages++;\r
161 -           tag_inbox_and_unread (message);\r
162 +           tag_new_message (state, message);\r
163             break;\r
164         /* Non-fatal issues (go on to next file) */\r
165         case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
166 @@ -714,6 +750,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
167      struct stat st;\r
168      const char *db_path;\r
169      char *dot_notmuch_path;\r
170 +    const char *new_msg_tags = "inbox,unread";\r
171      struct sigaction action;\r
172      _filename_node_t *f;\r
173      int renamed_files, removed_files;\r
174 @@ -726,12 +763,16 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
175      for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
176         if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
177             add_files_state.verbose = 1;\r
178 +       } else if (STRNCMP_LITERAL (argv[i], "--new-tags=") == 0) {\r
179 +           new_msg_tags = argv[i]+strlen("--new-tags=");\r
180         } else {\r
181             fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
182             return 1;\r
183         }\r
184      }\r
185 \r
186 +    add_files_state.new_msg_tags = _parse_tags(ctx, new_msg_tags);\r
187 +\r
188      config = notmuch_config_open (ctx, NULL, NULL);\r
189      if (config == NULL)\r
190         return 1;\r
191 diff --git a/notmuch.1 b/notmuch.1\r
192 index 86830f4..3bab17c 100644\r
193 --- a/notmuch.1\r
194 +++ b/notmuch.1\r
195 @@ -85,7 +85,7 @@ The\r
196  command is used to incorporate new mail into the notmuch database.\r
197  .RS 4\r
198  .TP 4\r
199 -.B new\r
200 +.BR new " [options...]"\r
201 \r
202  Find and import any new messages to the database.\r
203 \r
204 @@ -109,6 +109,23 @@ whenever new mail is delivered and you wish to\r
205 incorporate it into the\r
206  database. These subsequent runs will be much quicker than the initial\r
207  run.\r
208 \r
209 +Supported options for\r
210 +.B new\r
211 +include:\r
212 +.RS 4\r
213 +.TP 4\r
214 +.BR \-\-new\-tags= tags...\r
215 +\r
216 +Set the listed tags (separated by commas) on new messages\r
217 +instead of the default\r
218 +.B "inbox"\r
219 +and\r
220 +.B "unread"\r
221 +tags.\r
222 +\r
223 +.RE\r
224 +.RS 4\r
225 +\r
226  Invoking\r
227  .B notmuch\r
228  with no command argument will run\r
229 diff --git a/notmuch.c b/notmuch.c\r
230 index dcfda32..f7b16e3 100644\r
231 --- a/notmuch.c\r
232 +++ b/notmuch.c\r
233 @@ -126,7 +126,7 @@ command_t commands[] = {\r
234        "\tInvoking notmuch with no command argument will run setup if\n"\r
235        "\tthe setup command has not previously been completed." },\r
236      { "new", notmuch_new_command,\r
237 -      "[--verbose]",\r
238 +      "[--verbose] [--new-tags=inbox,unread]",\r
239        "Find and import new messages to the notmuch database.",\r
240        "\tScans all sub-directories of the mail directory, performing\n"\r
241        "\tfull-text indexing on new messages that are found. Each new\n"\r
242 @@ -148,6 +148,11 @@ command_t commands[] = {\r
243        "\t\tVerbose operation. Shows paths of message files as\n"\r
244        "\t\tthey are being indexed.\n"\r
245        "\n"\r
246 +      "\t--new-tags=tags...\n"\r
247 +      "\n"\r
248 +      "\t\tSet the listed tags (separated by commas) on new messages\n"\r
249 +      "\t\tinstead of the default \"inbox\" and \"unread\" tags.\n"\r
250 +      "\n"\r
251        "\tInvoking notmuch with no command argument will run new if\n"\r
252        "\tthe setup command has previously been completed, but new has\n"\r
253        "\tnot previously been run." },\r
254 -- \r
255 1.7.0\r