unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Ethan Glasser-Camp <glasse@cs.rpi.edu>
To: notmuch@notmuchmail.org
Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
Subject: [RFC PATCH 09/13] Mailstore also provides a "rename" function
Date: Wed, 15 Feb 2012 17:02:02 -0500	[thread overview]
Message-ID: <1329343326-16410-10-git-send-email-glasse@cs.rpi.edu> (raw)
In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>

From: Ethan Glasser-Camp <ethan@betacantrips.com>

This is used only in notmuch_message_tags_to_maildir_flags, to update
a message's filename when its tags change. For mailstores where this
doesn't make sense, they can of course define rename to be a NOOP.

Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
---
 lib/mailstore.c   |   21 ++++++++++++++++++++-
 lib/message.cc    |    5 +++--
 lib/notmuch.h     |   10 +++++++++-
 notmuch-restore.c |    7 +++++--
 notmuch-tag.c     |    7 +++++--
 5 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/lib/mailstore.c b/lib/mailstore.c
index 290da70..2c6beab 100644
--- a/lib/mailstore.c
+++ b/lib/mailstore.c
@@ -22,6 +22,8 @@
 
 typedef struct _notmuch_mailstore {
     FILE *(*open) (struct _notmuch_mailstore *mailstore, const char *filename);
+    int (*rename) (struct _notmuch_mailstore *mailstore, const char *old_filename,
+		   const char *new_filename);
 } _notmuch_mailstore;
 
 static FILE *
@@ -31,17 +33,27 @@ _maildir_open_function (unused (notmuch_mailstore_t *mailstore),
     return fopen (filename, "r");
 }
 
+static int
+_maildir_rename_function (unused (notmuch_mailstore_t *mailstore),
+			  const char *old_filename, const char *new_filename)
+{
+    return rename (old_filename, new_filename);
+}
+
 /* A mailstore is defined as:
  *
  * - A function used to "open" a mail message. This takes the
  *   "filename" for the file and should return a FILE *.
  *
+ * - A function to "rename" a mail message, which is currently only
+ *   used in tags_to_maildir_flags.
+ *
  * - TODO: A way to scan for new messages?
  *
  * - TODO: A "constructor"?
  */
 _notmuch_mailstore
-notmuch_mailstore_maildir = { _maildir_open_function };
+notmuch_mailstore_maildir = { _maildir_open_function, _maildir_rename_function };
 
 _notmuch_mailstore *
 notmuch_mailstore_get_by_name (const char *name)
@@ -57,3 +69,10 @@ notmuch_mailstore_open (notmuch_mailstore_t *mailstore, const char *filename)
 {
     return mailstore->open (mailstore, filename);
 }
+
+int
+notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filename,
+			  const char *new_filename)
+{
+    return mailstore->rename (mailstore, old_filename, new_filename);
+}
diff --git a/lib/message.cc b/lib/message.cc
index 762a18f..cd81f6b 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1291,7 +1291,8 @@ _new_maildir_filename (void *ctx,
 }
 
 notmuch_status_t
-notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)
+notmuch_message_tags_to_maildir_flags (notmuch_mailstore_t *mailstore,
+				       notmuch_message_t *message)
 {
     notmuch_filenames_t *filenames;
     const char *filename;
@@ -1319,7 +1320,7 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)
 	    int err;
 	    notmuch_status_t new_status;
 
-	    err = rename (filename, filename_new);
+	    err = notmuch_mailstore_rename (mailstore, filename, filename_new);
 	    if (err)
 		continue;
 
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 7ebe034..b6e66a9 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -423,6 +423,13 @@ notmuch_mailstore_get_by_name (const char *name);
 FILE *
 notmuch_mailstore_open (notmuch_mailstore_t *mailstore, const char *filename);
 
+/* Rename a file. This is used to update maildir tags and can safely
+ * be a NO-OP for non-filesystem mailstores.
+ */
+int
+notmuch_mailstore_rename (notmuch_mailstore_t *mailstore, const char *old_filename,
+			  const char *new_filename);
+
 /* Create a new query for 'database'.
  *
  * Here, 'database' should be an open database, (see
@@ -1095,7 +1102,8 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);
  * for synchronizing maildir flag changes back to tags.
  */
 notmuch_status_t
-notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);
+notmuch_message_tags_to_maildir_flags (notmuch_mailstore_t *mailstore,
+				       notmuch_message_t *message);
 
 /* Freeze the current state of 'message' within the database.
  *
diff --git a/notmuch-restore.c b/notmuch-restore.c
index b382b7b..a0beab4 100644
--- a/notmuch-restore.c
+++ b/notmuch-restore.c
@@ -25,6 +25,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
 {
     notmuch_config_t *config;
     notmuch_database_t *notmuch;
+    notmuch_mailstore_t *mailstore;
     notmuch_bool_t synchronize_flags;
     notmuch_bool_t accumulate = FALSE;
     char *input_file_name = NULL;
@@ -40,7 +41,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
     if (config == NULL)
 	return 1;
 
-    notmuch = notmuch_database_open (notmuch_config_get_mailstore (config),
+    mailstore = notmuch_config_get_mailstore (config);
+
+    notmuch = notmuch_database_open (mailstore,
 				     notmuch_config_get_database_path (config),
 				     NOTMUCH_DATABASE_MODE_READ_WRITE);
     if (notmuch == NULL)
@@ -170,7 +173,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
 	notmuch_message_thaw (message);
 
 	if (synchronize_flags)
-	    notmuch_message_tags_to_maildir_flags (message);
+	    notmuch_message_tags_to_maildir_flags (mailstore, message);
 
       NEXT_LINE:
 	if (message)
diff --git a/notmuch-tag.c b/notmuch-tag.c
index 5e8d74a..0e0a7b4 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -122,6 +122,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
     notmuch_query_t *query;
     notmuch_messages_t *messages;
     notmuch_message_t *message;
+    notmuch_mailstore_t *mailstore;
     struct sigaction action;
     notmuch_bool_t synchronize_flags;
     int i;
@@ -187,7 +188,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
     if (config == NULL)
 	return 1;
 
-    notmuch = notmuch_database_open (notmuch_config_get_mailstore (config),
+    mailstore = notmuch_config_get_mailstore (config);
+
+    notmuch = notmuch_database_open (mailstore,
 				     notmuch_config_get_database_path (config),
 				     NOTMUCH_DATABASE_MODE_READ_WRITE);
     if (notmuch == NULL)
@@ -222,7 +225,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
 	notmuch_message_thaw (message);
 
 	if (synchronize_flags)
-	    notmuch_message_tags_to_maildir_flags (message);
+	    notmuch_message_tags_to_maildir_flags (mailstore, message);
 
 	notmuch_message_destroy (message);
     }
-- 
1.7.5.4

  parent reply	other threads:[~2012-02-15 22:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-15 22:01 [RFC PATCH 00/13] Modular message store code Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 01/13] Create configuration paramater database.type Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 02/13] Add the concept of a mailstore in its absolute minimal sense Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 03/13] Introduce mailstore in the python bindings Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 04/13] Replace remaining places where fopen occurs Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 05/13] notmuch_database_add_message calculates sha1 of messages using mailstore Ethan Glasser-Camp
2012-02-15 22:01 ` [RFC PATCH 06/13] Pass mailstore to _notmuch_message_index_file Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 07/13] notmuch-new: pull out useful bits of add_files_recursive Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 08/13] count_files and add_files shall be generic Ethan Glasser-Camp
2012-02-15 22:02 ` Ethan Glasser-Camp [this message]
2012-02-15 22:02 ` [RFC PATCH 10/13] Introduce concept of mailstore "constructor" Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 11/13] Add a close function to mailstore Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 12/13] Close files using notmuch_mailstore_close instead of fclose Ethan Glasser-Camp
2012-02-15 22:02 ` [RFC PATCH 13/13] First crack at a CouchDB mailstore Ethan Glasser-Camp
2012-02-16  0:56 ` [RFC PATCH 00/13] Modular message store code Mark Walters
2012-03-01 13:51   ` Ethan Glasser-Camp
2012-02-16  7:47 ` Stewart Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1329343326-16410-10-git-send-email-glasse@cs.rpi.edu \
    --to=glasse@cs.rpi.edu \
    --cc=ethan@betacantrips.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).