aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/message.cc
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2010-11-11 03:41:39 -0800
committerGravatar Carl Worth <cworth@cworth.org>2010-11-11 03:47:11 -0800
commit71a3201885d508f10ecd24a0887337e1624ffbf1 (patch)
tree41fc4a0fb0b7b8c1d8a078727c1a036dc5c43a25 /lib/message.cc
parent8480a0a00370f997a29ebf98560a799ece43d3f4 (diff)
notmuch_message_tags_to_maildir_flags: Fix to rename multiple files
This function was documented as modifying every filename associated with the message. Fix it to actually do that.
Diffstat (limited to 'lib/message.cc')
-rw-r--r--lib/message.cc78
1 files changed, 42 insertions, 36 deletions
diff --git a/lib/message.cc b/lib/message.cc
index b8128505..8ae92901 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -961,15 +961,14 @@ maildir_get_subdir (char *filename)
return subdir;
}
-/* XXX: Needs to iterate over all filenames in the message
- *
- * XXX: Needs to ensure that existing, unsupported flags in the
+/* XXX: Needs to ensure that existing, unsupported flags in the
* filename are left unchanged (which also needs a test in the
* test suite).
*/
notmuch_status_t
notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)
{
+ notmuch_filenames_t *filenames;
char flags[ARRAY_SIZE(flag2tag)+1];
const char *filename, *p;
char *filename_new, *subdir = NULL;
@@ -977,49 +976,56 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)
maildir_get_new_flags (message, flags);
- filename = notmuch_message_get_filename (message);
- /* TODO: Iterate over all file names. */
- p = strstr(filename, ":2,");
- if ((p && strcmp (p+3, flags) == 0) ||
- (!p && flags[0] == '\0')) {
- // Return if flags are not to be changed - this suppresses
- // moving the message from new/ to cur/ during initial
- // tagging.
- return NOTMUCH_STATUS_SUCCESS;
- }
- if (!p)
- p = filename + strlen(filename);
+ for (filenames = notmuch_message_get_filenames (message);
+ notmuch_filenames_valid (filenames);
+ notmuch_filenames_move_to_next (filenames))
+ {
+ filename = notmuch_filenames_get (filenames);
- filename_new = (char*)talloc_size(message, (p-filename) + 3 + sizeof(flags));
- if (unlikely (filename_new == NULL))
- return NOTMUCH_STATUS_OUT_OF_MEMORY;
+ p = strstr(filename, ":2,");
+ if ((p && strcmp (p+3, flags) == 0) ||
+ (!p && flags[0] == '\0'))
+ {
+ continue;
+ }
- memcpy(filename_new, filename, p-filename);
- filename_new[p-filename] = '\0';
+ if (!p)
+ p = filename + strlen(filename);
- /* If message is in new/ move it under cur/. */
- subdir = maildir_get_subdir (filename_new);
- if (subdir && memcmp (subdir, "new/", 4) == 0)
- memcpy (subdir, "cur/", 4);
+ filename_new = (char*) talloc_size (message,
+ (p-filename) + 3 + sizeof (flags));
+ if (unlikely (filename_new == NULL))
+ return NOTMUCH_STATUS_OUT_OF_MEMORY;
- strcpy (filename_new+(p-filename), ":2,");
- strcpy (filename_new+(p-filename)+3, flags);
+ memcpy (filename_new, filename, p-filename);
+ filename_new[p-filename] = '\0';
- if (strcmp (filename, filename_new) != 0) {
- notmuch_status_t status;
+ /* If message is in new/ move it under cur/. */
+ subdir = maildir_get_subdir (filename_new);
+ if (subdir && memcmp (subdir, "new/", 4) == 0)
+ memcpy (subdir, "cur/", 4);
- ret = rename (filename, filename_new);
- if (ret == -1) {
- perror (talloc_asprintf (message, "rename of %s to %s failed",
+ strcpy (filename_new+(p-filename), ":2,");
+ strcpy (filename_new+(p-filename)+3, flags);
+
+ if (strcmp (filename, filename_new) != 0) {
+ notmuch_status_t status;
+
+ ret = rename (filename, filename_new);
+ if (ret == -1) {
+ perror (talloc_asprintf (message, "rename of %s to %s failed",
filename, filename_new));
- exit (1);
- }
- status = _notmuch_message_rename (message, filename_new);
+ exit (1);
+ }
+ status = _notmuch_message_rename (message, filename_new);
- _notmuch_message_sync (message);
+ _notmuch_message_sync (message);
- return status;
+ if (status)
+ return status;
+ }
}
+
return NOTMUCH_STATUS_SUCCESS;
}