Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 40 / 0635f6f54f9b31dbbbe5faf3c8d4db1ea848e4
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 F165B431FC3\r
6         for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:34 -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 zap7gjCqN2Lq for <notmuch@notmuchmail.org>;\r
11         Tue, 24 Nov 2009 14:10:34 -0800 (PST)\r
12 Received: from mail-fx0-f214.google.com (mail-fx0-f214.google.com\r
13         [209.85.220.214])\r
14         by olra.theworths.org (Postfix) with ESMTP id E631A431FBF\r
15         for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:33 -0800 (PST)\r
16 Received: by fxm6 with SMTP id 6so7397321fxm.0\r
17         for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:33 -0800 (PST)\r
18 Received: by 10.103.81.12 with SMTP id i12mr3003622mul.37.1259100633033;\r
19         Tue, 24 Nov 2009 14:10:33 -0800 (PST)\r
20 Received: from x61s.janakj (r2c34.net.upc.cz [62.245.66.34])\r
21         by mx.google.com with ESMTPS id 23sm740146mun.41.2009.11.24.14.10.31\r
22         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
23         Tue, 24 Nov 2009 14:10:32 -0800 (PST)\r
24 Received: by x61s.janakj (Postfix, from userid 1000)\r
25         id AB8E4440657; Tue, 24 Nov 2009 23:10:30 +0100 (CET)\r
26 From: Jan Janak <jan@ryngle.com>\r
27 To: notmuch@notmuchmail.org\r
28 Date: Tue, 24 Nov 2009 23:10:28 +0100\r
29 Message-Id: <1259100630-13673-3-git-send-email-jan@ryngle.com>\r
30 X-Mailer: git-send-email 1.6.3.3\r
31 In-Reply-To: <1259100630-13673-2-git-send-email-jan@ryngle.com>\r
32 References: <1259100630-13673-1-git-send-email-jan@ryngle.com>\r
33         <1259100630-13673-2-git-send-email-jan@ryngle.com>\r
34 Subject: [notmuch] [PATCH 2/4] notmuch: Config option to specify tags to be\r
35         applied by 'notmuch new'.\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.12\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Tue, 24 Nov 2009 22:10:35 -0000\r
49 \r
50 Add support for section [new] in the configuration file. This section\r
51 is supposed to contain options for 'notmuch new'. Currently there is\r
52 only one option called tags.\r
53 \r
54 The tags option can be used to configure a set of tags to be applied\r
55 by 'notmuch new'. Individual tags are separated by semicolon.\r
56 \r
57 'notmuch new' is modified not to apply 'inbox' and 'unread' by default,\r
58 but instead it obtains the set of tags to be applied from the new\r
59 configuration file option.\r
60 \r
61 Signed-off-by: Jan Janak <jan@ryngle.com>\r
62 ---\r
63  notmuch-client.h |    3 +++\r
64  notmuch-config.c |   44 ++++++++++++++++++++++++++++++++++++++++++++\r
65  notmuch-new.c    |   19 ++++++++++++++++++-\r
66  3 files changed, 65 insertions(+), 1 deletions(-)\r
67 \r
68 diff --git a/notmuch-client.h b/notmuch-client.h\r
69 index c04eaeb..0fb9c19 100644\r
70 --- a/notmuch-client.h\r
71 +++ b/notmuch-client.h\r
72 @@ -184,6 +184,9 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
73                                      const char *other_email[],\r
74                                      size_t length);\r
75  \r
76 +char **\r
77 +notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length);\r
78 +\r
79  notmuch_bool_t\r
80  debugger_is_active (void);\r
81  \r
82 diff --git a/notmuch-config.c b/notmuch-config.c\r
83 index fc65d6b..7f62a80 100644\r
84 --- a/notmuch-config.c\r
85 +++ b/notmuch-config.c\r
86 @@ -22,6 +22,7 @@\r
87  \r
88  #include <pwd.h>\r
89  #include <netdb.h>\r
90 +#include <ctype.h>\r
91  \r
92  static const char toplevel_config_comment[] =\r
93      " .notmuch-config - Configuration file for the notmuch mail system\n"\r
94 @@ -62,6 +63,9 @@ struct _notmuch_config {\r
95      char *user_primary_email;\r
96      char **user_other_email;\r
97      size_t user_other_email_length;\r
98 +\r
99 +    char **new_tags;\r
100 +    size_t new_tags_length;\r
101  };\r
102  \r
103  static int\r
104 @@ -199,6 +203,8 @@ notmuch_config_open (void *ctx,\r
105      config->user_primary_email = NULL;\r
106      config->user_other_email = NULL;\r
107      config->user_other_email_length = 0;\r
108 +    config->new_tags = NULL;\r
109 +    config->new_tags_length = 0;\r
110  \r
111      if (! g_key_file_load_from_file (config->key_file,\r
112                                      config->filename,\r
113 @@ -450,3 +456,41 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
114      talloc_free (config->user_other_email);\r
115      config->user_other_email = NULL;\r
116  }\r
117 +\r
118 +char **\r
119 +notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)\r
120 +{\r
121 +    char **tags;\r
122 +    size_t len;\r
123 +    unsigned int i;\r
124 +    char *start, *end;\r
125 +\r
126 +    if (config->new_tags == NULL) {\r
127 +       config->new_tags_length = 0;\r
128 +       tags = g_key_file_get_string_list (config->key_file, "new", "tags",\r
129 +                                          &len, NULL);\r
130 +\r
131 +       if (tags) {\r
132 +           config->new_tags = talloc_size (config, sizeof(char*) *\r
133 +                                           (len + 1));\r
134 +           for (i = 0; i < len; i++) {\r
135 +               /* Remove leading and trailing white space around the tag and\r
136 +                * filter out empty tags. */\r
137 +               start = tags[i];\r
138 +               end = start + strlen (start) - 1;\r
139 +               while (isspace (*start)) start++;\r
140 +               while (end > start && isspace (*end)) end--;\r
141 +               if (end >= start) {\r
142 +                   config->new_tags[config->new_tags_length++] =\r
143 +                       talloc_strndup (config->new_tags, start,\r
144 +                                       end - start + 1);\r
145 +               }\r
146 +           }\r
147 +           config->new_tags[config->new_tags_length] = NULL;\r
148 +           g_strfreev (tags);\r
149 +       }\r
150 +    }\r
151 +\r
152 +    *length = config->new_tags_length;\r
153 +    return config->new_tags;\r
154 +}\r
155 diff --git a/notmuch-new.c b/notmuch-new.c\r
156 index 9970407..10745e8 100644\r
157 --- a/notmuch-new.c\r
158 +++ b/notmuch-new.c\r
159 @@ -24,6 +24,8 @@\r
160  \r
161  static volatile sig_atomic_t do_add_files_print_progress = 0;\r
162  \r
163 +static notmuch_config_t *config = NULL;\r
164 +\r
165  static void\r
166  handle_sigalrm (unused (int signal))\r
167  {\r
168 @@ -68,6 +70,21 @@ add_files_print_progress (add_files_state_t *state)\r
169      fflush (stdout);\r
170  }\r
171  \r
172 +static void\r
173 +apply_tags (notmuch_message_t *message)\r
174 +{\r
175 +    char** tags;\r
176 +    unsigned int count, i;\r
177 +\r
178 +    if ((tags = notmuch_config_get_new_tags (config, &count)) == NULL)\r
179 +       return;\r
180 +\r
181 +    for (i = 0; i < count; i++) {\r
182 +       if (tags[i])\r
183 +           notmuch_message_add_tag (message, tags[i]);\r
184 +    }\r
185 +}\r
186 +\r
187  static int ino_cmp(const struct dirent **a, const struct dirent **b)\r
188  {\r
189      return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;\r
190 @@ -191,6 +208,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
191                     /* success */\r
192                     case NOTMUCH_STATUS_SUCCESS:\r
193                         state->added_messages++;\r
194 +                       apply_tags (message);\r
195                         break;\r
196                     /* Non-fatal issues (go on to next file) */\r
197                     case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
198 @@ -388,7 +406,6 @@ count_files (const char *path, int *count)\r
199  int\r
200  notmuch_new_command (void *ctx, int argc, char *argv[])\r
201  {\r
202 -    notmuch_config_t *config;\r
203      notmuch_database_t *notmuch;\r
204      add_files_state_t add_files_state;\r
205      double elapsed;\r
206 -- \r
207 1.6.3.3\r
208 \r