Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 6D518429E48 for ; Wed, 15 Feb 2012 14:11:17 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.54 X-Spam-Level: X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_SORBS_WEB=0.614] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5Ccl3Vh7Qb3I for ; Wed, 15 Feb 2012 14:11:13 -0800 (PST) Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B2208429E43 for ; Wed, 15 Feb 2012 14:11:13 -0800 (PST) X-Hash: S|a57180726c74ee2ac7421b5b6afc127d9861b50d|f4c71ca8cd81772447cd914142de4b6b X-Countries: Cameroon, United States X-SMTP-From: accepted [195.24.209.20] [195.24.209.20] (localhost) {Cameroon} DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from :to:cc:subject:date:message-id:in-reply-to:references; s= default; i=glasse@cs.rpi.edu; t=1329343871; x=1329948671; l=6206; bh=yMg95QHC9rjdhpvXA3C3pEILpds=; b=KPs/FicgdLWwKm5MvN2+tNv FoOFOlGTwMtqb3vrO5PIKNU7TNR3PEiSKhmbvMaqtJJ1J7pRm4F6BChHcq0tDhmZ MYllAwKxNWjBGwP5Q6AzceyUNjRrQD5gbz/3/vQdtrWCcRFySqlZcZ+cevHuaMrf lvlpUZTnYA8MhuWRiDFc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc :subject:date:message-id:in-reply-to:references; q=dns; s= default; b=dkuFtjxlcjmSruqxn5aKnbFRj1ZNIIGmoVhX1IWdhO0znn5Y2T+g+ ccv/6k19gUR4U35qHzb0ytig64FdlzMlMkYYG2JVWuyqBvIgK+cLFzOrZkS0gNis LD36shUORy7x9lYbec9bEBcKeCOjIOxoAJMqrU4zB4+K4dGXkdUpY0= X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00 X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit 15) Authentication-Results: cliffclavin.cs.rpi.edu; DKIM=neutral (none) header.from=glasse@cs.rpi.edu; SPF=neutral (mfrom; Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FMAgD5008841 Auth:glasse X-Virus-Scanned-By: cliffclavin.cs.rpi.edu Received: from localhost ([195.24.209.20]) (authenticated bits=0) by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FMAgD5008841 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 15 Feb 2012 17:10:54 -0500 (EST) (envelope-from glasse@cs.rpi.edu) From: Ethan Glasser-Camp To: notmuch@notmuchmail.org Subject: [RFC PATCH 09/13] Mailstore also provides a "rename" function Date: Wed, 15 Feb 2012 17:02:02 -0500 Message-Id: <1329343326-16410-10-git-send-email-glasse@cs.rpi.edu> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25 Cc: Ethan Glasser-Camp X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Feb 2012 22:11:17 -0000 From: Ethan Glasser-Camp 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 --- 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