Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / 11 / 4a7ea3bb968c5c09270f261ab8dd3977bb0230
1 Return-Path: <jan@ryngle.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 85A86431FC2\r
6         for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 15:30:25 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id 1WODlr6XHDxl for <notmuch@notmuchmail.org>;\r
11         Wed, 25 Nov 2009 15:30:24 -0800 (PST)\r
12 Received: from mail-ew0-f213.google.com (mail-ew0-f213.google.com\r
13         [209.85.219.213])\r
14         by olra.theworths.org (Postfix) with ESMTP id F2498431FAE\r
15         for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 15:30:23 -0800 (PST)\r
16 Received: by ewy5 with SMTP id 5so257217ewy.30\r
17         for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 15:30:23 -0800 (PST)\r
18 Received: by 10.213.23.146 with SMTP id r18mr7432978ebb.46.1259191823025;\r
19         Wed, 25 Nov 2009 15:30:23 -0800 (PST)\r
20 Received: from x61s.janakj ([213.192.30.141])\r
21         by mx.google.com with ESMTPS id 28sm329450eyg.44.2009.11.25.15.30.18\r
22         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
23         Wed, 25 Nov 2009 15:30:21 -0800 (PST)\r
24 Received: by x61s.janakj (Postfix, from userid 1000)\r
25         id AF8C3440656; Thu, 26 Nov 2009 00:30:16 +0100 (CET)\r
26 From: Jan Janak <jan@ryngle.com>\r
27 To: notmuch@notmuchmail.org\r
28 Date: Thu, 26 Nov 2009 00:30:15 +0100\r
29 Message-Id: <1259191816-1982-4-git-send-email-jan@ryngle.com>\r
30 X-Mailer: git-send-email 1.6.3.3\r
31 In-Reply-To: <1259191816-1982-3-git-send-email-jan@ryngle.com>\r
32 References: <1259100630-13673-1-git-send-email-jan@ryngle.com>\r
33         <1259191816-1982-1-git-send-email-jan@ryngle.com>\r
34         <1259191816-1982-2-git-send-email-jan@ryngle.com>\r
35         <1259191816-1982-3-git-send-email-jan@ryngle.com>\r
36 Subject: [notmuch] [PATCH 4/5] notmuch-new: New cmdline option --tag=<name>.\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.12\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41         <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Wed, 25 Nov 2009 23:30:25 -0000\r
50 \r
51 The list of tags to be applied by 'notmuch new' can be configured in\r
52 the configuration file. This command line option can be used to\r
53 override the list of tags from the coonfiguration file on the command\r
54 line. You may repeat the option several times if you want to apply\r
55 more than one tag:\r
56 \r
57   notmuch new --tag=apple --tag=orange\r
58 \r
59 This is useful, for example, if you have an archive of messages you\r
60 would like to add to the database with a special tag so that they can\r
61 be easily identified later. To do that, you could simply copy the files\r
62 from the archive to the database directory and then index them all with:\r
63 \r
64   notmuch new --tag=prehistory\r
65 \r
66 Tags to be applied every time 'notmuch new' is run can be specified in\r
67 the configuration file. One-time tags for individual runs can be\r
68 specified on the command line with this new option.\r
69 \r
70 This revision of the patch includes suggestions from Bart Trojanowski.\r
71 \r
72 Signed-off-by: Jan Janak <jan@ryngle.com>\r
73 ---\r
74  notmuch-new.c |   40 ++++++++++++++++++++++++++++++++++------\r
75  notmuch.c     |    8 +++++++-\r
76  2 files changed, 41 insertions(+), 7 deletions(-)\r
77 \r
78 diff --git a/notmuch-new.c b/notmuch-new.c\r
79 index af717b7..cfbc6aa 100644\r
80 --- a/notmuch-new.c\r
81 +++ b/notmuch-new.c\r
82 @@ -26,6 +26,9 @@ static volatile sig_atomic_t do_add_files_print_progress = 0;\r
83  \r
84  static notmuch_config_t *config = NULL;\r
85  \r
86 +static char **cmdline_tags = NULL;\r
87 +static size_t cmdline_tags_count = 0;\r
88 +\r
89  static void\r
90  handle_sigalrm (unused (int signal))\r
91  {\r
92 @@ -76,12 +79,19 @@ apply_tags (notmuch_message_t *message)\r
93      char** tags;\r
94      size_t count, i;\r
95  \r
96 -    if ((tags = notmuch_config_get_new_tags (config, &count)) == NULL)\r
97 -       return;\r
98 +    if (cmdline_tags_count) {\r
99 +       for (i = 0; i < cmdline_tags_count; i++) {\r
100 +           if (cmdline_tags[i])\r
101 +               notmuch_message_add_tag (message, cmdline_tags[i]);\r
102 +       }\r
103 +    } else {\r
104 +       if ((tags = notmuch_config_get_new_tags (config, &count)) == NULL)\r
105 +           return;\r
106  \r
107 -    for (i = 0; i < count; i++) {\r
108 -       if (tags[i])\r
109 -           notmuch_message_add_tag (message, tags[i]);\r
110 +       for (i = 0; i < count; i++) {\r
111 +           if (tags[i])\r
112 +               notmuch_message_add_tag (message, tags[i]);\r
113 +       }\r
114      }\r
115  }\r
116  \r
117 @@ -413,7 +423,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
118      int ret = 0;\r
119      struct stat st;\r
120      const char *db_path;\r
121 -    char *dot_notmuch_path;\r
122 +    char *dot_notmuch_path, *opt;\r
123 +    char **tmp;\r
124      struct sigaction action;\r
125      int i;\r
126  \r
127 @@ -423,6 +434,23 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
128      for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
129         if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
130             add_files_state.verbose = 1;\r
131 +       } else if (STRNCMP_LITERAL (argv[i], "--tag=") == 0) {\r
132 +           opt = argv[i] + sizeof ("--tag=") - 1;\r
133 +           /* FIXME: We should check for leading and trailing white-space in\r
134 +            * option value here and remove it.\r
135 +            */\r
136 +           if (*opt == '\0') {\r
137 +               fprintf (stderr, "Option value missing: %s\n", argv[i]);\r
138 +               return 1;\r
139 +           }\r
140 +           tmp = talloc_realloc (ctx, cmdline_tags, char*,\r
141 +                                 cmdline_tags_count + 1);\r
142 +           if (tmp == NULL) {\r
143 +               fprintf (stderr, "Notmuch ran out of memory.\n");\r
144 +               return 1;\r
145 +           }\r
146 +           tmp[cmdline_tags_count++] = opt;\r
147 +           cmdline_tags = tmp;\r
148         } else {\r
149             fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
150             return 1;\r
151 diff --git a/notmuch.c b/notmuch.c\r
152 index f45b692..1bd3265 100644\r
153 --- a/notmuch.c\r
154 +++ b/notmuch.c\r
155 @@ -123,7 +123,7 @@ command_t commands[] = {\r
156        "\t\tInvoking notmuch with no command argument will run setup if\n"\r
157        "\t\tthe setup command has not previously been completed." },\r
158      { "new", notmuch_new_command,\r
159 -      "[--verbose]",\r
160 +      "[--verbose] [--tag=<name>]",\r
161        "\t\tFind and import new messages to the notmuch database.",\r
162        "\t\tScans all sub-directories of the mail directory, performing\n"\r
163        "\t\tfull-text indexing on new messages that are found. Each new\n"\r
164 @@ -145,6 +145,12 @@ command_t commands[] = {\r
165        "\t\t\tVerbose operation. Shows paths of message files as\n"\r
166        "\t\t\tthey are being indexed.\n"\r
167        "\n"\r
168 +      "\t\t--tag=<name>\n"\r
169 +      "\n"\r
170 +      "\t\t\tAdd the tag <name> to all messages newly added to the\n"\r
171 +      "\t\t\tdatabase. You may repeat this option several times if\n"\r
172 +      "\t\t\tyou want to add more tags.\n"\r
173 +      "\n"\r
174        "\t\tNote: \"notmuch new\" runs (other than the first run) will\n"\r
175        "\t\tskip any read-only directories, so you can use that to mark\n"\r
176        "\t\tdirectories that will not receive any new mail (and make\n"\r
177 -- \r
178 1.6.3.3\r
179 \r