Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 45 / e9627f611ba49317e94e6d2eb49d553d50c42d
1 Return-Path: <jani@nikula.org>\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 75C5E431FBF\r
6         for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 12:19:03 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 oE4gAdve4m0a for <notmuch@notmuchmail.org>;\r
17         Sun, 25 Mar 2012 12:19:01 -0700 (PDT)\r
18 Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
19         [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 69FC8431FC0\r
22         for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 12:18:57 -0700 (PDT)\r
23 Received: by mail-lpp01m010-f53.google.com with SMTP id c1so3755652lah.26\r
24         for <notmuch@notmuchmail.org>; Sun, 25 Mar 2012 12:18:57 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=google.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references\r
28         :in-reply-to:references:x-gm-message-state;\r
29         bh=LkSeekLEJWTehEeU/FuWZ+1VC8hs51RqlfXXDHatRpo=;\r
30         b=Cdxs34NRVl0QLCWk15JlreDJiX9uZcFcl6ApyZnO3NqW2zeTHM4WLOeOSOwT5Xpf8Y\r
31         MBWR0A8KkHNgC/DsU3og3ZhDRtvKKEKfOfJ9GJ+z9EKeCz/fOhnXFidtHeLkGaJ4noI+\r
32         QNlIVmsDLt12eNWa/3uW7JFSAhGolwdM8/srZVE3gmDPvfzcw9/NWDQwafAt5cs3IRb0\r
33         Y/RMfXtLlextiTybz2gXs4CiwyV0o9CHlRQTOpqfPN0d0B7bcwaR65jLEnbA798m8Hbo\r
34         vUSuoX88K0zt7CxKZWAPdXuGojTd87w3JlKi5XurHQKOdSpdhmznh865jhrsPShE9PDD\r
35         Qysg==\r
36 Received: by 10.152.132.6 with SMTP id oq6mr14347923lab.44.1332703136987;\r
37         Sun, 25 Mar 2012 12:18:56 -0700 (PDT)\r
38 Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
39         [84.248.80.253])\r
40         by mx.google.com with ESMTPS id mq3sm14857176lab.0.2012.03.25.12.18.55\r
41         (version=SSLv3 cipher=OTHER); Sun, 25 Mar 2012 12:18:56 -0700 (PDT)\r
42 From: Jani Nikula <jani@nikula.org>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH v2 2/3] cli: refactor "notmuch tag" query tagging into a\r
45         separate function\r
46 Date: Sun, 25 Mar 2012 22:18:44 +0300\r
47 Message-Id:\r
48  <584067da00dd9f04a7f3982b76fd4b4918e4fe61.1332702915.git.jani@nikula.org>\r
49 X-Mailer: git-send-email 1.7.5.4\r
50 In-Reply-To: <cover.1332702915.git.jani@nikula.org>\r
51 References: <cover.1332702915.git.jani@nikula.org>\r
52 In-Reply-To: <cover.1332702915.git.jani@nikula.org>\r
53 References: <cover.1332702915.git.jani@nikula.org>\r
54 X-Gm-Message-State:\r
55  ALoCoQnzihF3JGRAoi7+ZpfNu+t/EAm4chgKyenjq+qjri7vAouKN8bJBOPk+pEIrhN++oR5ZLKJ\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Sun, 25 Mar 2012 19:19:04 -0000\r
69 \r
70 Refactor to make tagging code easier to reuse in the future. No\r
71 functional changes.\r
72 \r
73 Signed-off-by: Jani Nikula <jani@nikula.org>\r
74 ---\r
75  notmuch-tag.c |  101 ++++++++++++++++++++++++++++++++-------------------------\r
76  1 files changed, 57 insertions(+), 44 deletions(-)\r
77 \r
78 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
79 index c39b235..edbfdec 100644\r
80 --- a/notmuch-tag.c\r
81 +++ b/notmuch-tag.c\r
82 @@ -106,6 +106,60 @@ _optimize_tag_query (void *ctx, const char *orig_query_string,\r
83      return query_string;\r
84  }\r
85  \r
86 +static int\r
87 +tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
88 +          tag_operation_t *tag_ops, notmuch_bool_t synchronize_flags)\r
89 +{\r
90 +    notmuch_query_t *query;\r
91 +    notmuch_messages_t *messages;\r
92 +    notmuch_message_t *message;\r
93 +    int i;\r
94 +\r
95 +    /* Optimize the query so it excludes messages that already have\r
96 +     * the specified set of tags. */\r
97 +    query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
98 +    if (query_string == NULL) {\r
99 +       fprintf (stderr, "Out of memory.\n");\r
100 +       return 1;\r
101 +    }\r
102 +\r
103 +    query = notmuch_query_create (notmuch, query_string);\r
104 +    if (query == NULL) {\r
105 +       fprintf (stderr, "Out of memory.\n");\r
106 +       return 1;\r
107 +    }\r
108 +\r
109 +    /* tagging is not interested in any special sort order */\r
110 +    notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
111 +\r
112 +    for (messages = notmuch_query_search_messages (query);\r
113 +        notmuch_messages_valid (messages) && !interrupted;\r
114 +        notmuch_messages_move_to_next (messages))\r
115 +    {\r
116 +       message = notmuch_messages_get (messages);\r
117 +\r
118 +       notmuch_message_freeze (message);\r
119 +\r
120 +       for (i = 0; tag_ops[i].tag; i++) {\r
121 +           if (tag_ops[i].remove)\r
122 +               notmuch_message_remove_tag (message, tag_ops[i].tag);\r
123 +           else\r
124 +               notmuch_message_add_tag (message, tag_ops[i].tag);\r
125 +       }\r
126 +\r
127 +       notmuch_message_thaw (message);\r
128 +\r
129 +       if (synchronize_flags)\r
130 +           notmuch_message_tags_to_maildir_flags (message);\r
131 +\r
132 +       notmuch_message_destroy (message);\r
133 +    }\r
134 +\r
135 +    notmuch_query_destroy (query);\r
136 +\r
137 +    return interrupted;\r
138 +}\r
139 +\r
140  int\r
141  notmuch_tag_command (void *ctx, int argc, char *argv[])\r
142  {\r
143 @@ -114,12 +168,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
144      char *query_string;\r
145      notmuch_config_t *config;\r
146      notmuch_database_t *notmuch;\r
147 -    notmuch_query_t *query;\r
148 -    notmuch_messages_t *messages;\r
149 -    notmuch_message_t *message;\r
150      struct sigaction action;\r
151      notmuch_bool_t synchronize_flags;\r
152      int i;\r
153 +    int ret;\r
154  \r
155      /* Setup our handler for SIGINT */\r
156      memset (&action, 0, sizeof (struct sigaction));\r
157 @@ -166,14 +218,6 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
158         return 1;\r
159      }\r
160  \r
161 -    /* Optimize the query so it excludes messages that already have\r
162 -     * the specified set of tags. */\r
163 -    query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
164 -    if (query_string == NULL) {\r
165 -       fprintf (stderr, "Out of memory.\n");\r
166 -       return 1;\r
167 -    }\r
168 -\r
169      config = notmuch_config_open (ctx, NULL, NULL);\r
170      if (config == NULL)\r
171         return 1;\r
172 @@ -185,40 +229,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
173  \r
174      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
175  \r
176 -    query = notmuch_query_create (notmuch, query_string);\r
177 -    if (query == NULL) {\r
178 -       fprintf (stderr, "Out of memory.\n");\r
179 -       return 1;\r
180 -    }\r
181 -\r
182 -    /* tagging is not interested in any special sort order */\r
183 -    notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
184 +    ret = tag_query (ctx, notmuch, query_string, tag_ops, synchronize_flags);\r
185  \r
186 -    for (messages = notmuch_query_search_messages (query);\r
187 -        notmuch_messages_valid (messages) && !interrupted;\r
188 -        notmuch_messages_move_to_next (messages))\r
189 -    {\r
190 -       message = notmuch_messages_get (messages);\r
191 -\r
192 -       notmuch_message_freeze (message);\r
193 -\r
194 -       for (i = 0; tag_ops[i].tag; i++) {\r
195 -           if (tag_ops[i].remove)\r
196 -               notmuch_message_remove_tag (message, tag_ops[i].tag);\r
197 -           else\r
198 -               notmuch_message_add_tag (message, tag_ops[i].tag);\r
199 -       }\r
200 -\r
201 -       notmuch_message_thaw (message);\r
202 -\r
203 -       if (synchronize_flags)\r
204 -           notmuch_message_tags_to_maildir_flags (message);\r
205 -\r
206 -       notmuch_message_destroy (message);\r
207 -    }\r
208 -\r
209 -    notmuch_query_destroy (query);\r
210      notmuch_database_close (notmuch);\r
211  \r
212 -    return interrupted;\r
213 +    return ret;\r
214  }\r
215 -- \r
216 1.7.5.4\r
217 \r