[PATCH 1/9] lib: read "property" terms from messages.
[notmuch-archives.git] / 80 / c354d99d26203455fdd18cdb49075afaffdf9c
1 Return-Path: <ethan.glasser.camp@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 48AA8431FB6\r
6         for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:52:39 -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.061\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.061 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_BL_SPAMCOP_NET=1.246,\r
14         RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_SORBS_WEB=0.614] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id cu+pW-1ustVL for <notmuch@notmuchmail.org>;\r
18         Mon, 25 Jun 2012 13:52:38 -0700 (PDT)\r
19 Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com\r
20  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
21  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
22  69A42431FAF    for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:52:38 -0700\r
23  (PDT)\r
24 Received: by mail-wg0-f45.google.com with SMTP id dt14so3709395wgb.2\r
25         for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:52:38 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=JtL1snjU/1Xpywll4abj5LfjBqekIq4oApY6aJ/KrtQ=;\r
29         b=OWAwcYcv2ABvErTrNS+iGCGjLMxlhPtXgbgd+aeoKvsYz0J/1O3332q1FjWjl8FQXG\r
30         GZmf8Rgua5MIJ/4oMlMYA1OPf0d8pZiYJHmtkM09RHb9zoyuLL4StAb9iCPOXmjO6764\r
31         qC6KA8oQs9n/5AShw99hkNc7GjeJN7dMsxVIkltTU9HQulWJ1LuzKkLj8NR4TmzsCsBi\r
32         b/9YYUUzTOQw5cFhnuHzDIO+8D5vJs+lvX8BlWk0VWBgfNZAlx9g5qdkiHTS3miH21hn\r
33         ewj/ty9GmIwziqU20Jy/waoQwqFOrXqH80WPuXLNXkHYdc10Prx8ra4nY+It9/udraxp\r
34         L8xw==\r
35 Received: by 10.216.194.23 with SMTP id l23mr6709137wen.121.1340657557073;\r
36         Mon, 25 Jun 2012 13:52:37 -0700 (PDT)\r
37 Received: from localhost ([195.24.209.21])\r
38         by mx.google.com with ESMTPS id eb8sm8374wib.11.2012.06.25.13.52.32\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Mon, 25 Jun 2012 13:52:36 -0700 (PDT)\r
41 From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [RFC PATCH 06/14] maildir URIs can be used in tags_to_maildir_flags\r
44 Date: Mon, 25 Jun 2012 16:51:49 -0400\r
45 Message-Id: <1340657517-6539-2-git-send-email-ethan@betacantrips.com>\r
46 X-Mailer: git-send-email 1.7.9.5\r
47 In-Reply-To: <1340657517-6539-1-git-send-email-ethan@betacantrips.com>\r
48 References: <1340657517-6539-1-git-send-email-ethan@betacantrips.com>\r
49 X-Mailman-Approved-At: Tue, 26 Jun 2012 03:51:54 -0700\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Mon, 25 Jun 2012 20:52:39 -0000\r
63 \r
64 A better fix would probably be based on scheme.\r
65 \r
66 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>\r
67 ---\r
68  lib/message.cc |   51 ++++++++++++++++++++++++++++++++++++++++++++++-----\r
69  1 file changed, 46 insertions(+), 5 deletions(-)\r
70 \r
71 diff --git a/lib/message.cc b/lib/message.cc\r
72 index c9857f5..8ecec71 100644\r
73 --- a/lib/message.cc\r
74 +++ b/lib/message.cc\r
75 @@ -23,6 +23,7 @@\r
76  \r
77  #include <stdint.h>\r
78  \r
79 +#include <uriparser/Uri.h>\r
80  #include <gmime/gmime.h>\r
81  \r
82  struct visible _notmuch_message {\r
83 @@ -1093,7 +1094,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
84      {\r
85         filename = notmuch_filenames_get (filenames);\r
86         dir = _filename_is_in_maildir (filename);\r
87 -\r
88         if (! dir)\r
89             continue;\r
90  \r
91 @@ -1304,12 +1304,46 @@ _new_maildir_filename (void *ctx,\r
92      return filename_new;\r
93  }\r
94  \r
95 +/* Parses a maildir URI and returns the filename corresponding to its\r
96 + * path.\r
97 + *\r
98 + * Returns NULL if either the URI couldn't be parsed or if the\r
99 + * scheme isn't maildir:.\r
100 + */\r
101 +static char *\r
102 +_get_maildir_filename (const char *filename)\r
103 +{\r
104 +    UriParserStateA parser_state;\r
105 +    UriUriA parsed;\r
106 +    char *path;\r
107 +    parser_state.uri = &parsed;\r
108 +\r
109 +    if (uriParseUriA (&parser_state, filename) != URI_SUCCESS) {\r
110 +       uriFreeUriMembersA (&parsed);\r
111 +       return NULL;\r
112 +    }\r
113 +\r
114 +    if (parsed.scheme.first != NULL &&\r
115 +       0 != strncmp(parsed.scheme.first, "maildir",\r
116 +                    parsed.scheme.afterLast-parsed.scheme.first)) {\r
117 +       /* Full URI with non-maildir scheme. */\r
118 +       uriFreeUriMembersA (&parsed);\r
119 +       return NULL;\r
120 +    }\r
121 +\r
122 +    path = (char *)parsed.pathHead->text.first - 1;\r
123 +    uriFreeUriMembersA (&parsed);\r
124 +    return path;\r
125 +\r
126 +}\r
127 +\r
128 +\r
129  notmuch_status_t\r
130  notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
131  {\r
132      notmuch_filenames_t *filenames;\r
133      const char *filename;\r
134 -    char *filename_new;\r
135 +    char *filename_new, *filename_old, *filename_new_uri;\r
136      char *to_set, *to_clear;\r
137      notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
138  \r
139 @@ -1324,16 +1358,22 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
140         if (! _filename_is_in_maildir (filename))\r
141             continue;\r
142  \r
143 -       filename_new = _new_maildir_filename (message, filename,\r
144 +       filename_old = _get_maildir_filename (filename);\r
145 +       if (filename_old == NULL)\r
146 +           continue;\r
147 +\r
148 +       filename_new = _new_maildir_filename (message, filename_old,\r
149                                               to_set, to_clear);\r
150         if (filename_new == NULL)\r
151             continue;\r
152  \r
153 +       filename_new_uri = talloc_asprintf (message, "maildir://%s", filename_new);\r
154 +\r
155         if (strcmp (filename, filename_new)) {\r
156             int err;\r
157             notmuch_status_t new_status;\r
158  \r
159 -           err = rename (filename, filename_new);\r
160 +           err = rename (filename_old, filename_new);\r
161             if (err)\r
162                 continue;\r
163  \r
164 @@ -1347,7 +1387,7 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
165             }\r
166  \r
167             new_status = _notmuch_message_add_filename (message,\r
168 -                                                       filename_new);\r
169 +                                                       filename_new_uri);\r
170             /* Hold on to only the first error. */\r
171             if (! status && new_status) {\r
172                 status = new_status;\r
173 @@ -1358,6 +1398,7 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
174         }\r
175  \r
176         talloc_free (filename_new);\r
177 +       talloc_free (filename_new_uri);\r
178      }\r
179  \r
180      talloc_free (to_set);\r
181 -- \r
182 1.7.9.5\r
183 \r