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