[RFC PATCH 09/13] Mailstore also provides a "rename" function
Ethan Glasser-Camp
glasse at cs.rpi.edu
Wed Feb 15 14:02:02 PST 2012
From: Ethan Glasser-Camp <ethan at 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 at 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
More information about the notmuch
mailing list