[notmuch] [patch] store folder information
authorAndreas Klöckner <lists@informa.tiker.net>
Mon, 14 Dec 2009 19:21:50 +0000 (14:21 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:52 +0000 (09:35 -0800)
df/a13115639b10afe4338b162afd01b282519a49 [new file with mode: 0644]

diff --git a/df/a13115639b10afe4338b162afd01b282519a49 b/df/a13115639b10afe4338b162afd01b282519a49
new file mode 100644 (file)
index 0000000..5e74723
--- /dev/null
@@ -0,0 +1,262 @@
+Return-Path: <lists@informa.tiker.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 625D0431FBD\r
+       for <notmuch@notmuchmail.org>; Mon, 14 Dec 2009 11:28:07 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id oOr2qMlFOKTu for <notmuch@notmuchmail.org>;\r
+       Mon, 14 Dec 2009 11:28:06 -0800 (PST)\r
+X-Greylist: delayed 399 seconds by postgrey-1.32 at olra;\r
+       Mon, 14 Dec 2009 11:28:06 PST\r
+Received: from outbound-mail-13.bluehost.com (outbound-mail-13.bluehost.com\r
+       [69.89.18.113])\r
+       by olra.theworths.org (Postfix) with SMTP id 4318A431FAE\r
+       for <notmuch@notmuchmail.org>; Mon, 14 Dec 2009 11:28:06 -0800 (PST)\r
+Received: (qmail 5184 invoked by uid 0); 14 Dec 2009 19:21:26 -0000\r
+Received: from unknown (HELO host304.hostmonster.com) (74.220.215.104)\r
+       by outboundproxy1.bluehost.com with SMTP; 14 Dec 2009 19:21:26 -0000\r
+DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default;\r
+ d=informa.tiker.net;\r
+       h=Received:From:To:Subject:Date:User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:X-Identified-User;\r
+       b=Vz72pF1VkS4iE6Y8Wik61cuUXzFLq6VGDO+N8oSn6WplA9tsgh7bDpky0HpbSfU/stLbcqwAMy3SA3eyF0J9vFy7djl8lJqW4lOWxAVgUqAAn8AoQWeA7dAANFMmNRcG;\r
+Received: from ip72-221-120-106.ri.ri.cox.net ([72.221.120.106]\r
+       helo=grizzly.localnet)\r
+       by host304.hostmonster.com with esmtpsa (TLSv1:AES256-SHA:256)\r
+       (Exim 4.69) (envelope-from <lists@informa.tiker.net>)\r
+       id 1NKGU2-00079r-E0\r
+       for notmuch@notmuchmail.org; Mon, 14 Dec 2009 12:21:26 -0700\r
+From: Andreas =?iso-8859-1?q?Kl=F6ckner?= <lists@informa.tiker.net>\r
+To: notmuch@notmuchmail.org\r
+Date: Mon, 14 Dec 2009 14:21:50 -0500\r
+User-Agent: KMail/1.12.2 (Linux/2.6.31-trunk-686; KDE/4.3.2; i686; ; )\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="nextPart1983344.e7oaIR2PZV";\r
+       protocol="application/pgp-signature"; micalg=pgp-sha1\r
+Content-Transfer-Encoding: 7bit\r
+Message-Id: <200912141421.52561.lists@informa.tiker.net>\r
+X-Identified-User: {11749:host304.hostmonster.com:tikernet:tiker.net}\r
+       {sentby:smtp auth 72.221.120.106 authed with\r
+       andreas-store+tiker.net}\r
+X-Mailman-Approved-At: Mon, 14 Dec 2009 14:44:28 -0800\r
+Subject: [notmuch] [patch] store folder information\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 14 Dec 2009 19:28:07 -0000\r
+\r
+--nextPart1983344.e7oaIR2PZV\r
+Content-Type: multipart/mixed;\r
+  boundary="Boundary-01=_OBpJLuJNt54jnVC"\r
+Content-Transfer-Encoding: 7bit\r
+\r
+\r
+--Boundary-01=_OBpJLuJNt54jnVC\r
+Content-Type: Text/Plain;\r
+  charset="us-ascii"\r
+Content-Transfer-Encoding: quoted-printable\r
+Content-Disposition: inline\r
+\r
+Hi there,\r
+\r
+I've patched notmuch to retain information on which folder emails are store=\r
+d=20\r
+in. This makes the transition from a folders-and-procmail model somewhat=20\r
+easier. The resulting changes are attached.\r
+\r
+Andreas\r
+\r
+--Boundary-01=_OBpJLuJNt54jnVC\r
+Content-Type: text/x-patch;\r
+  charset="UTF-8";\r
+  name="0001-Preseve-folder-information-when-indexing.patch"\r
+Content-Transfer-Encoding: quoted-printable\r
+Content-Disposition: attachment;\r
+       filename="0001-Preseve-folder-information-when-indexing.patch"\r
+\r
+=46rom 179af7f436d8c21bad90e7eb88fc17c56f83c26c Mon Sep 17 00:00:00 2001\r
+=46rom: Andreas Kloeckner <inform@tiker.net>\r
+Date: Mon, 14 Dec 2009 14:16:20 -0500\r
+Subject: [PATCH] Preseve folder information when indexing.\r
+\r
+=2D--\r
+ lib/database.cc |   14 +++++++++-----\r
+ lib/index.cc    |    2 ++\r
+ lib/notmuch.h   |    1 +\r
+ notmuch-new.c   |   35 ++++++++++++++++++++++++++++++++++-\r
+ 4 files changed, 46 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index b6c4d07..e6b4272 100644\r
+=2D-- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -70,10 +70,9 @@ typedef struct {\r
+  *\r
+  *    MESSAGE_ID:     The unique ID of the mail mess (see "id" above)\r
+  *\r
+=2D * In addition, terms from the content of the message are added with\r
+=2D * "from", "to", "attachment", and "subject" prefixes for use by the\r
+=2D * user in searching. But the database doesn't really care itself\r
+=2D * about any of these.\r
++ * In addition, terms from the content of the message are added with "from=\r
+",\r
++ * "to", "attachment", "subject", and "folder" prefixes for use by the use=\r
+r in\r
++ * searching. But the database doesn't really care itself about any of the=\r
+se.\r
+  *\r
+  * Timestamp document\r
+  * ------------------\r
+@@ -124,7 +123,8 @@ prefix_t PROBABILISTIC_PREFIX[]=3D {\r
+     { "from", "XFROM" },\r
+     { "to", "XTO" },\r
+     { "attachment", "XATTACHMENT" },\r
+=2D    { "subject", "XSUBJECT"}\r
++    { "subject", "XSUBJECT"},\r
++    { "folder", "XFOLDER"}\r
+ };\r
+=20\r
+ int\r
+@@ -889,6 +889,7 @@ _notmuch_database_link_message (notmuch_database_t *not=\r
+much,\r
+ notmuch_status_t\r
+ notmuch_database_add_message (notmuch_database_t *notmuch,\r
+                             const char *filename,\r
++                            const char *folder_name,\r
+                             notmuch_message_t **message_ret)\r
+ {\r
+     notmuch_message_file_t *message_file;\r
+@@ -1006,6 +1007,9 @@ notmuch_database_add_message (notmuch_database_t *not=\r
+much,\r
+=20\r
+       _notmuch_message_index_file (message, filename);\r
+=20\r
++        if (folder_name !=3D NULL)\r
++            _notmuch_message_gen_terms (message, "folder", folder_name);\r
++\r
+       _notmuch_message_sync (message);\r
+     } catch (const Xapian::Error &error) {\r
+       fprintf (stderr, "A Xapian exception occurred adding message: %s.\n",\r
+diff --git a/lib/index.cc b/lib/index.cc\r
+index 125fa6c..55f3fbc 100644\r
+=2D-- a/lib/index.cc\r
++++ b/lib/index.cc\r
+@@ -116,6 +116,8 @@ skip_re_in_subject (const char *subject)\r
+           s++;\r
+       if (strncasecmp (s, "re:", 3) =3D=3D 0)\r
+           s +=3D 3;\r
++        else if (strncasecmp (s, "aw:", 3) =3D=3D 0)\r
++          s +=3D 3;\r
+       else\r
+           break;\r
+     }\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 60834fb..5d3b3c6 100644\r
+=2D-- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -265,6 +265,7 @@ notmuch_database_get_timestamp (notmuch_database_t *dat=\r
+abase,\r
+ notmuch_status_t\r
+ notmuch_database_add_message (notmuch_database_t *database,\r
+                             const char *filename,\r
++                            const char *folder_name,\r
+                             notmuch_message_t **message);\r
+=20\r
+ /* Find a message with the given message_id.\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 9d20616..bc8adc8 100644\r
+=2D-- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -21,6 +21,7 @@\r
+ #include "notmuch-client.h"\r
+=20\r
+ #include <unistd.h>\r
++#include <glib.h>\r
+=20\r
+ static volatile sig_atomic_t do_add_files_print_progress =3D 0;\r
+=20\r
+@@ -144,6 +145,34 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+     struct dirent **namelist =3D NULL;\r
+     int num_entries;\r
+=20\r
++    gchar *full_folder_name =3D NULL;\r
++    gchar *folder_base_name =3D NULL;\r
++\r
++    /* Find name of "folder" containing the email. */\r
++    full_folder_name =3D g_strdup(path);\r
++    while (1)\r
++    {\r
++        folder_base_name =3D g_path_get_basename(full_folder_name);\r
++\r
++        if (strcmp(folder_base_name, "cur") =3D=3D 0\r
++                || strcmp(folder_base_name, "new") =3D=3D 0)\r
++        {\r
++            gchar *parent_name =3D g_path_get_dirname(full_folder_name);\r
++            g_free(full_folder_name);\r
++            full_folder_name =3D parent_name;\r
++        }\r
++        else\r
++            break;\r
++    }\r
++\r
++    g_free(full_folder_name);\r
++\r
++    if (strcmp(folder_base_name, ".") =3D=3D 0)\r
++    {\r
++        g_free(folder_base_name);\r
++        folder_base_name =3D NULL;\r
++    }\r
++\r
+     /* If we're told to, we bail out on encountering a read-only\r
+      * directory, (with this being a clear clue from the user to\r
+      * Notmuch that new mail won't be arriving there and we need not\r
+@@ -235,7 +264,9 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+                   fflush (stdout);\r
+               }\r
+=20\r
+=2D            status =3D notmuch_database_add_message (notmuch, next, &message);\r
++              status =3D notmuch_database_add_message (notmuch, next,=20\r
++                                                       folder_base_name,=20\r
++                                                       &message);\r
+               switch (status) {\r
+                   /* success */\r
+                   case NOTMUCH_STATUS_SUCCESS:\r
+@@ -301,6 +332,8 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+       closedir (dir);\r
+     if (namelist)\r
+       free (namelist);\r
++    if (folder_base_name)\r
++        g_free(folder_base_name);\r
+=20\r
+     return ret;\r
+ }\r
+=2D-=20\r
+1.6.5\r
+\r
+\r
+--Boundary-01=_OBpJLuJNt54jnVC--\r
+\r
+--nextPart1983344.e7oaIR2PZV\r
+Content-Type: application/pgp-signature; name=signature.asc \r
+Content-Description: This is a digitally signed message part.\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.10 (GNU/Linux)\r
+\r
+iD8DBQBLJpBOJZ7T4Hn4+FIRAv5IAJ9Yd+fs8bxZiQ05CTfh8ZEQYo2yLQCgg+pP\r
+sPs3672uLyTZNkcIZlj0zR8=\r
+=vdx5\r
+-----END PGP SIGNATURE-----\r
+\r
+--nextPart1983344.e7oaIR2PZV--\r