--- /dev/null
+Return-Path: <ethan.glasser.camp@gmail.com>\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 48AA8431FB6\r
+ for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:52:39 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.061\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.061 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_BL_SPAMCOP_NET=1.246,\r
+ RCVD_IN_DNSWL_LOW=-0.7, 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 cu+pW-1ustVL for <notmuch@notmuchmail.org>;\r
+ Mon, 25 Jun 2012 13:52:38 -0700 (PDT)\r
+Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com\r
+ [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ 69A42431FAF for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:52:38 -0700\r
+ (PDT)\r
+Received: by mail-wg0-f45.google.com with SMTP id dt14so3709395wgb.2\r
+ for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:52:38 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=JtL1snjU/1Xpywll4abj5LfjBqekIq4oApY6aJ/KrtQ=;\r
+ b=OWAwcYcv2ABvErTrNS+iGCGjLMxlhPtXgbgd+aeoKvsYz0J/1O3332q1FjWjl8FQXG\r
+ GZmf8Rgua5MIJ/4oMlMYA1OPf0d8pZiYJHmtkM09RHb9zoyuLL4StAb9iCPOXmjO6764\r
+ qC6KA8oQs9n/5AShw99hkNc7GjeJN7dMsxVIkltTU9HQulWJ1LuzKkLj8NR4TmzsCsBi\r
+ b/9YYUUzTOQw5cFhnuHzDIO+8D5vJs+lvX8BlWk0VWBgfNZAlx9g5qdkiHTS3miH21hn\r
+ ewj/ty9GmIwziqU20Jy/waoQwqFOrXqH80WPuXLNXkHYdc10Prx8ra4nY+It9/udraxp\r
+ L8xw==\r
+Received: by 10.216.194.23 with SMTP id l23mr6709137wen.121.1340657557073;\r
+ Mon, 25 Jun 2012 13:52:37 -0700 (PDT)\r
+Received: from localhost ([195.24.209.21])\r
+ by mx.google.com with ESMTPS id eb8sm8374wib.11.2012.06.25.13.52.32\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Mon, 25 Jun 2012 13:52:36 -0700 (PDT)\r
+From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 06/14] maildir URIs can be used in tags_to_maildir_flags\r
+Date: Mon, 25 Jun 2012 16:51:49 -0400\r
+Message-Id: <1340657517-6539-2-git-send-email-ethan@betacantrips.com>\r
+X-Mailer: git-send-email 1.7.9.5\r
+In-Reply-To: <1340657517-6539-1-git-send-email-ethan@betacantrips.com>\r
+References: <1340657517-6539-1-git-send-email-ethan@betacantrips.com>\r
+X-Mailman-Approved-At: Tue, 26 Jun 2012 03:51:54 -0700\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: Mon, 25 Jun 2012 20:52:39 -0000\r
+\r
+A better fix would probably be based on scheme.\r
+\r
+Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+---\r
+ lib/message.cc | 51 ++++++++++++++++++++++++++++++++++++++++++++++-----\r
+ 1 file changed, 46 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index c9857f5..8ecec71 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -23,6 +23,7 @@\r
+ \r
+ #include <stdint.h>\r
+ \r
++#include <uriparser/Uri.h>\r
+ #include <gmime/gmime.h>\r
+ \r
+ struct visible _notmuch_message {\r
+@@ -1093,7 +1094,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
+ {\r
+ filename = notmuch_filenames_get (filenames);\r
+ dir = _filename_is_in_maildir (filename);\r
+-\r
+ if (! dir)\r
+ continue;\r
+ \r
+@@ -1304,12 +1304,46 @@ _new_maildir_filename (void *ctx,\r
+ return filename_new;\r
+ }\r
+ \r
++/* Parses a maildir URI and returns the filename corresponding to its\r
++ * path.\r
++ *\r
++ * Returns NULL if either the URI couldn't be parsed or if the\r
++ * scheme isn't maildir:.\r
++ */\r
++static char *\r
++_get_maildir_filename (const char *filename)\r
++{\r
++ UriParserStateA parser_state;\r
++ UriUriA parsed;\r
++ char *path;\r
++ parser_state.uri = &parsed;\r
++\r
++ if (uriParseUriA (&parser_state, filename) != URI_SUCCESS) {\r
++ uriFreeUriMembersA (&parsed);\r
++ return NULL;\r
++ }\r
++\r
++ if (parsed.scheme.first != NULL &&\r
++ 0 != strncmp(parsed.scheme.first, "maildir",\r
++ parsed.scheme.afterLast-parsed.scheme.first)) {\r
++ /* Full URI with non-maildir scheme. */\r
++ uriFreeUriMembersA (&parsed);\r
++ return NULL;\r
++ }\r
++\r
++ path = (char *)parsed.pathHead->text.first - 1;\r
++ uriFreeUriMembersA (&parsed);\r
++ return path;\r
++\r
++}\r
++\r
++\r
+ notmuch_status_t\r
+ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
+ {\r
+ notmuch_filenames_t *filenames;\r
+ const char *filename;\r
+- char *filename_new;\r
++ char *filename_new, *filename_old, *filename_new_uri;\r
+ char *to_set, *to_clear;\r
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
+ \r
+@@ -1324,16 +1358,22 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
+ if (! _filename_is_in_maildir (filename))\r
+ continue;\r
+ \r
+- filename_new = _new_maildir_filename (message, filename,\r
++ filename_old = _get_maildir_filename (filename);\r
++ if (filename_old == NULL)\r
++ continue;\r
++\r
++ filename_new = _new_maildir_filename (message, filename_old,\r
+ to_set, to_clear);\r
+ if (filename_new == NULL)\r
+ continue;\r
+ \r
++ filename_new_uri = talloc_asprintf (message, "maildir://%s", filename_new);\r
++\r
+ if (strcmp (filename, filename_new)) {\r
+ int err;\r
+ notmuch_status_t new_status;\r
+ \r
+- err = rename (filename, filename_new);\r
++ err = rename (filename_old, filename_new);\r
+ if (err)\r
+ continue;\r
+ \r
+@@ -1347,7 +1387,7 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
+ }\r
+ \r
+ new_status = _notmuch_message_add_filename (message,\r
+- filename_new);\r
++ filename_new_uri);\r
+ /* Hold on to only the first error. */\r
+ if (! status && new_status) {\r
+ status = new_status;\r
+@@ -1358,6 +1398,7 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
+ }\r
+ \r
+ talloc_free (filename_new);\r
++ talloc_free (filename_new_uri);\r
+ }\r
+ \r
+ talloc_free (to_set);\r
+-- \r
+1.7.9.5\r
+\r