Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / e1 / f50d36d777fa78d5c1f095bb66ae183b9a3ecd
1 Return-Path: <sojkam1@fel.cvut.cz>\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 24613431FC4\r
6         for <notmuch@notmuchmail.org>; Tue,  2 Feb 2010 07:01:14 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.959\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.959 tagged_above=-999 required=5\r
12         tests=[AWL=-0.960, BAYES_50=0.001] autolearn=ham\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 6XPr0jM+WH9T for <notmuch@notmuchmail.org>;\r
16         Tue,  2 Feb 2010 07:01:13 -0800 (PST)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id D1C35431FC0\r
19         for <notmuch@notmuchmail.org>; Tue,  2 Feb 2010 07:01:12 -0800 (PST)\r
20 Received: from localhost (unknown [192.168.200.4])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 3BA3219F3331\r
22         for <notmuch@notmuchmail.org>; Tue,  2 Feb 2010 16:01:11 +0100 (CET)\r
23 X-Virus-Scanned: IMAP AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
26         port 10044) with ESMTP id KfMAfBLv1ay5 for <notmuch@notmuchmail.org>;\r
27         Tue,  2 Feb 2010 16:01:11 +0100 (CET)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id 1408B19F332E\r
30         for <notmuch@notmuchmail.org>; Tue,  2 Feb 2010 16:01:11 +0100 (CET)\r
31 Received: from localhost.localdomain (k335-30.felk.cvut.cz [147.32.86.30])\r
32         (Authenticated sender: sojkam1)\r
33         by imap.feld.cvut.cz (Postfix) with ESMTPSA id 0B87215C052\r
34         for <notmuch@notmuchmail.org>; Tue,  2 Feb 2010 16:01:10 +0100 (CET)\r
35 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
36 To: notmuch@notmuchmail.org\r
37 Date: Tue,  2 Feb 2010 16:01:08 +0100\r
38 Message-Id: <1265122868-12133-1-git-send-email-sojkam1@fel.cvut.cz>\r
39 X-Mailer: git-send-email 1.6.6\r
40 In-Reply-To: <201001291049.21048.sojkam1@fel.cvut.cz>\r
41 References: <201001291049.21048.sojkam1@fel.cvut.cz>\r
42 MIME-Version: 1.0\r
43 Content-Type: text/plain; charset=UTF-8\r
44 Content-Transfer-Encoding: 8bit\r
45 Subject: [notmuch] [PATCHv2] Preserve folder information when indexing\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Tue, 02 Feb 2010 15:01:14 -0000\r
59 \r
60 Stores the folder (directory name) of the message in the database as a\r
61 term with folder prefix.\r
62 \r
63 This patch was originally sent by Andreas Klöckner. The differences\r
64 from the original patch are:\r
65 - Folder name is taken from strings generated during travesal. It no\r
66   longer uses glib nor it allocates additional memory to determine the\r
67   base name. The same approach as in\r
68   id:87fx8bygi7.fsf@linux.vnet.ibm.com was used.\r
69 - Removed unrelated change which was submitted separately as\r
70   id:1264691584-8290-2-git-send-email-sojkam1@fel.cvut.cz\r
71 - Changed the comment describing database schema.\r
72 \r
73 TODO (see the previous Carl's email):\r
74 - Support hierarchical folders\r
75 \r
76 ---\r
77  lib/database.cc |   17 ++++++++++++-----\r
78  lib/notmuch.h   |    1 +\r
79  notmuch-new.c   |    9 ++++++---\r
80  3 files changed, 19 insertions(+), 8 deletions(-)\r
81 \r
82 diff --git a/lib/database.cc b/lib/database.cc\r
83 index cce7847..ba2aa16 100644\r
84 --- a/lib/database.cc\r
85 +++ b/lib/database.cc\r
86 @@ -83,10 +83,10 @@ typedef struct {\r
87   *\r
88   *     MESSAGE_ID:     The unique ID of the mail mess (see "id" above)\r
89   *\r
90 - * In addition, terms from the content of the message are added with\r
91 - * "from", "to", "attachment", and "subject" prefixes for use by the\r
92 - * user in searching. But the database doesn't really care itself\r
93 - * about any of these.\r
94 + * In addition, terms from the content and path of the message are\r
95 + * added with "from", "to", "attachment", "subject" and "folder"\r
96 + * prefixes for use by the user in searching. But the database doesn't\r
97 + * really care itself about any of these.\r
98   *\r
99   * The data portion of a mail document is empty.\r
100   *\r
101 @@ -154,7 +154,10 @@ prefix_t PROBABILISTIC_PREFIX[]= {\r
102      { "from",                  "XFROM" },\r
103      { "to",                    "XTO" },\r
104      { "attachment",            "XATTACHMENT" },\r
105 -    { "subject",               "XSUBJECT"}\r
106 +    { "subject",               "XSUBJECT"},\r
107 +    { "folder",                "XFOLDER"}\r
108 +    // FIXME: Is folder realy a candidate for probabilistic prefix or\r
109 +    // it should be a boolean prefix instead?\r
110  };\r
111  \r
112  int\r
113 @@ -1317,6 +1320,7 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,\r
114  notmuch_status_t\r
115  notmuch_database_add_message (notmuch_database_t *notmuch,\r
116                               const char *filename,\r
117 +                             const char *folder_name,\r
118                               notmuch_message_t **message_ret)\r
119  {\r
120      notmuch_message_file_t *message_file;\r
121 @@ -1432,6 +1436,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
122             date = notmuch_message_file_get_header (message_file, "date");\r
123             _notmuch_message_set_date (message, date);\r
124  \r
125 +           if (folder_name != NULL)\r
126 +               _notmuch_message_gen_terms (message, "folder", folder_name);\r
127 +\r
128             _notmuch_message_index_file (message, filename);\r
129         } else {\r
130             ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;\r
131 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
132 index 15c9db4..3a5ab78 100644\r
133 --- a/lib/notmuch.h\r
134 +++ b/lib/notmuch.h\r
135 @@ -263,6 +263,7 @@ notmuch_database_get_directory (notmuch_database_t *database,\r
136  notmuch_status_t\r
137  notmuch_database_add_message (notmuch_database_t *database,\r
138                               const char *filename,\r
139 +                             const char *folder_name,\r
140                               notmuch_message_t **message);\r
141  \r
142  /* Remove a message from the given notmuch database.\r
143 diff --git a/notmuch-new.c b/notmuch-new.c\r
144 index f25c71f..afd4e3d 100644\r
145 --- a/notmuch-new.c\r
146 +++ b/notmuch-new.c\r
147 @@ -207,6 +207,7 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
148  static notmuch_status_t\r
149  add_files_recursive (notmuch_database_t *notmuch,\r
150                      const char *path,\r
151 +                    const char *folder,\r
152                      add_files_state_t *state)\r
153  {\r
154      DIR *dir = NULL;\r
155 @@ -302,7 +303,9 @@ add_files_recursive (notmuch_database_t *notmuch,\r
156         }\r
157  \r
158         next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
159 -       status = add_files_recursive (notmuch, next, state);\r
160 +       status = add_files_recursive (notmuch, next,\r
161 +                                     is_maildir ? folder : entry->d_name,\r
162 +                                     state);\r
163         if (status && ret == NOTMUCH_STATUS_SUCCESS)\r
164             ret = status;\r
165         talloc_free (next);\r
166 @@ -407,7 +410,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
167             fflush (stdout);\r
168         }\r
169  \r
170 -       status = notmuch_database_add_message (notmuch, next, &message);\r
171 +       status = notmuch_database_add_message (notmuch, next, folder, &message);\r
172         switch (status) {\r
173         /* success */\r
174         case NOTMUCH_STATUS_SUCCESS:\r
175 @@ -546,7 +549,7 @@ add_files (notmuch_database_t *notmuch,\r
176         return NOTMUCH_STATUS_FILE_ERROR;\r
177      }\r
178  \r
179 -    status = add_files_recursive (notmuch, path, state);\r
180 +    status = add_files_recursive (notmuch, path, basename(path), state);\r
181  \r
182      if (timer_is_active) {\r
183         /* Now stop the timer. */\r
184 -- \r
185 tg: (a2d919e..) t/Preserve-folder-information-when-indexing (depends on: master)\r