[RFC PATCH 09/13] Mailstore also provides a "rename" function
authorEthan Glasser-Camp <glasse@cs.rpi.edu>
Wed, 15 Feb 2012 22:02:02 +0000 (17:02 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:34 +0000 (09:44 -0800)
f9/82cccd2043e79fcc1b423987cb98bad8faed88 [new file with mode: 0644]

diff --git a/f9/82cccd2043e79fcc1b423987cb98bad8faed88 b/f9/82cccd2043e79fcc1b423987cb98bad8faed88
new file mode 100644 (file)
index 0000000..07dbc70
--- /dev/null
@@ -0,0 +1,264 @@
+Return-Path: <glasse@cs.rpi.edu>\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 6D518429E48\r
+       for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:11:17 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.54\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3,\r
+       RCVD_IN_SORBS_WEB=0.614] autolearn=disabled\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 5Ccl3Vh7Qb3I for <notmuch@notmuchmail.org>;\r
+       Wed, 15 Feb 2012 14:11:13 -0800 (PST)\r
+Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu\r
+ [128.113.126.25])     (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)       by olra.theworths.org (Postfix) with ESMTPS\r
+ id B2208429E43        for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:11:13 -0800\r
+ (PST)\r
+X-Hash:\r
+ S|a57180726c74ee2ac7421b5b6afc127d9861b50d|f4c71ca8cd81772447cd914142de4b6b\r
+X-Countries: Cameroon, United States\r
+X-SMTP-From: accepted <glasse@cs.rpi.edu> [195.24.209.20] [195.24.209.20]\r
+       (localhost) {Cameroon}\r
+DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from\r
+       :to:cc:subject:date:message-id:in-reply-to:references; s=\r
+       default; i=glasse@cs.rpi.edu; t=1329343871; x=1329948671; l=6206;\r
+       bh=yMg95QHC9rjdhpvXA3C3pEILpds=; b=KPs/FicgdLWwKm5MvN2+tNv\r
+       FoOFOlGTwMtqb3vrO5PIKNU7TNR3PEiSKhmbvMaqtJJ1J7pRm4F6BChHcq0tDhmZ\r
+       MYllAwKxNWjBGwP5Q6AzceyUNjRrQD5gbz/3/vQdtrWCcRFySqlZcZ+cevHuaMrf\r
+       lvlpUZTnYA8MhuWRiDFc=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc\r
+       :subject:date:message-id:in-reply-to:references; q=dns; s=\r
+       default; b=dkuFtjxlcjmSruqxn5aKnbFRj1ZNIIGmoVhX1IWdhO0znn5Y2T+g+\r
+       ccv/6k19gUR4U35qHzb0ytig64FdlzMlMkYYG2JVWuyqBvIgK+cLFzOrZkS0gNis\r
+       LD36shUORy7x9lYbec9bEBcKeCOjIOxoAJMqrU4zB4+K4dGXkdUpY0=\r
+X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00\r
+X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit\r
+       15)\r
+Authentication-Results: cliffclavin.cs.rpi.edu;\r
+       DKIM=neutral (none) header.from=glasse@cs.rpi.edu;\r
+       SPF=neutral (mfrom;\r
+       Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu\r
+X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FMAgD5008841 Auth:glasse\r
+X-Virus-Scanned-By: cliffclavin.cs.rpi.edu\r
+Received: from localhost ([195.24.209.20]) (authenticated bits=0)\r
+       by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FMAgD5008841\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);\r
+       Wed, 15 Feb 2012 17:10:54 -0500 (EST)\r
+       (envelope-from glasse@cs.rpi.edu)\r
+From: Ethan Glasser-Camp <glasse@cs.rpi.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 09/13] Mailstore also provides a "rename" function\r
+Date: Wed, 15 Feb 2012 17:02:02 -0500\r
+Message-Id: <1329343326-16410-10-git-send-email-glasse@cs.rpi.edu>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>\r
+References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>\r
+X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25\r
+Cc: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\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: Wed, 15 Feb 2012 22:11:17 -0000\r
+\r
+From: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+\r
+This is used only in notmuch_message_tags_to_maildir_flags, to update\r
+a message's filename when its tags change. For mailstores where this\r
+doesn't make sense, they can of course define rename to be a NOOP.\r
+\r
+Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+---\r
+ lib/mailstore.c   |   21 ++++++++++++++++++++-\r
+ lib/message.cc    |    5 +++--\r
+ lib/notmuch.h     |   10 +++++++++-\r
+ notmuch-restore.c |    7 +++++--\r
+ notmuch-tag.c     |    7 +++++--\r
+ 5 files changed, 42 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/lib/mailstore.c b/lib/mailstore.c\r
+index 290da70..2c6beab 100644\r
+--- a/lib/mailstore.c\r
++++ b/lib/mailstore.c\r
+@@ -22,6 +22,8 @@\r
\r
+ typedef struct _notmuch_mailstore {\r
+     FILE *(*open) (struct _notmuch_mailstore *mailstore, const char *filename);\r
++    int (*rename) (struct _notmuch_mailstore *mailstore, const char *old_filename,\r
++                 const char *new_filename);\r
+ } _notmuch_mailstore;\r
\r
+ static FILE *\r
+@@ -31,17 +33,27 @@ _maildir_open_function (unused (notmuch_mailstore_t *mailstore),\r
+     return fopen (filename, "r");\r
+ }\r
\r
++static int\r
++_maildir_rename_function (unused (notmuch_mailstore_t *mailstore),\r
++                        const char *old_filename, const char *new_filename)\r
++{\r
++    return rename (old_filename, new_filename);\r
++}\r
++\r
+ /* A mailstore is defined as:\r
+  *\r
+  * - A function used to "open" a mail message. This takes the\r
+  *   "filename" for the file and should return a FILE *.\r
+  *\r
++ * - A function to "rename" a mail message, which is currently only\r
++ *   used in tags_to_maildir_flags.\r
++ *\r
+  * - TODO: A way to scan for new messages?\r
+  *\r
+  * - TODO: A "constructor"?\r
+  */\r
+ _notmuch_mailstore\r
+-notmuch_mailstore_maildir = { _maildir_open_function };\r
++notmuch_mailstore_maildir = { _maildir_open_function, _maildir_rename_function };\r
\r
+ _notmuch_mailstore *\r
+ notmuch_mailstore_get_by_name (const char *name)\r
+@@ -57,3 +69,10 @@ notmuch_mailstore_open (notmuch_mailstore_t *mailstore, const char *filename)\r
+ {\r
+     return mailstore->open (mailstore, filename);\r
+ }\r
++\r
++int\r
++notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filename,\r
++                        const char *new_filename)\r
++{\r
++    return mailstore->rename (mailstore, old_filename, new_filename);\r
++}\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 762a18f..cd81f6b 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -1291,7 +1291,8 @@ _new_maildir_filename (void *ctx,\r
+ }\r
\r
+ notmuch_status_t\r
+-notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
++notmuch_message_tags_to_maildir_flags (notmuch_mailstore_t *mailstore,\r
++                                     notmuch_message_t *message)\r
+ {\r
+     notmuch_filenames_t *filenames;\r
+     const char *filename;\r
+@@ -1319,7 +1320,7 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
+           int err;\r
+           notmuch_status_t new_status;\r
\r
+-          err = rename (filename, filename_new);\r
++          err = notmuch_mailstore_rename (mailstore, filename, filename_new);\r
+           if (err)\r
+               continue;\r
\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 7ebe034..b6e66a9 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -423,6 +423,13 @@ notmuch_mailstore_get_by_name (const char *name);\r
+ FILE *\r
+ notmuch_mailstore_open (notmuch_mailstore_t *mailstore, const char *filename);\r
\r
++/* Rename a file. This is used to update maildir tags and can safely\r
++ * be a NO-OP for non-filesystem mailstores.\r
++ */\r
++int\r
++notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filename,\r
++                        const char *new_filename);\r
++\r
+ /* Create a new query for 'database'.\r
+  *\r
+  * Here, 'database' should be an open database, (see\r
+@@ -1095,7 +1102,8 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);\r
+  * for synchronizing maildir flag changes back to tags.\r
+  */\r
+ notmuch_status_t\r
+-notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);\r
++notmuch_message_tags_to_maildir_flags (notmuch_mailstore_t *mailstore,\r
++                                     notmuch_message_t *message);\r
\r
+ /* Freeze the current state of 'message' within the database.\r
+  *\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index b382b7b..a0beab4 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -25,6 +25,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+ {\r
+     notmuch_config_t *config;\r
+     notmuch_database_t *notmuch;\r
++    notmuch_mailstore_t *mailstore;\r
+     notmuch_bool_t synchronize_flags;\r
+     notmuch_bool_t accumulate = FALSE;\r
+     char *input_file_name = NULL;\r
+@@ -40,7 +41,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+     if (config == NULL)\r
+       return 1;\r
\r
+-    notmuch = notmuch_database_open (notmuch_config_get_mailstore (config),\r
++    mailstore = notmuch_config_get_mailstore (config);\r
++\r
++    notmuch = notmuch_database_open (mailstore,\r
+                                    notmuch_config_get_database_path (config),\r
+                                    NOTMUCH_DATABASE_MODE_READ_WRITE);\r
+     if (notmuch == NULL)\r
+@@ -170,7 +173,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+       notmuch_message_thaw (message);\r
\r
+       if (synchronize_flags)\r
+-          notmuch_message_tags_to_maildir_flags (message);\r
++          notmuch_message_tags_to_maildir_flags (mailstore, message);\r
\r
+       NEXT_LINE:\r
+       if (message)\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index 5e8d74a..0e0a7b4 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -122,6 +122,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+     notmuch_query_t *query;\r
+     notmuch_messages_t *messages;\r
+     notmuch_message_t *message;\r
++    notmuch_mailstore_t *mailstore;\r
+     struct sigaction action;\r
+     notmuch_bool_t synchronize_flags;\r
+     int i;\r
+@@ -187,7 +188,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+     if (config == NULL)\r
+       return 1;\r
\r
+-    notmuch = notmuch_database_open (notmuch_config_get_mailstore (config),\r
++    mailstore = notmuch_config_get_mailstore (config);\r
++\r
++    notmuch = notmuch_database_open (mailstore,\r
+                                    notmuch_config_get_database_path (config),\r
+                                    NOTMUCH_DATABASE_MODE_READ_WRITE);\r
+     if (notmuch == NULL)\r
+@@ -222,7 +225,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+       notmuch_message_thaw (message);\r
\r
+       if (synchronize_flags)\r
+-          notmuch_message_tags_to_maildir_flags (message);\r
++          notmuch_message_tags_to_maildir_flags (mailstore, message);\r
\r
+       notmuch_message_destroy (message);\r
+     }\r
+-- \r
+1.7.5.4\r
+\r