unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Igor Almeida <igor.contato@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH/RFC 1/3] David Bremner's patch for custom maildir flags
Date: Wed, 25 Nov 2015 23:16:29 -0300	[thread overview]
Message-ID: <1448504191-30974-2-git-send-email-igor.contato@gmail.com> (raw)
In-Reply-To: <1448504191-30974-1-git-send-email-igor.contato@gmail.com>

---
 lib/database.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/notmuch.h   | 18 +++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/lib/database.cc b/lib/database.cc
index 3b342f1..592cbcc 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1329,6 +1329,67 @@ notmuch_database_get_version (notmuch_database_t *notmuch)
     return version;
 }
 
+notmuch_status_t
+notmuch_database_get_maildir_keyword (notmuch_database_t *notmuch,
+				      int index, const char **tag)
+{
+    string tag_string;
+    const char *key;
+    const char *str;
+
+    if (!notmuch || !tag)
+	return NOTMUCH_STATUS_NULL_POINTER;
+
+    if (index < 0 || index > ('z' - 'a'))
+	return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
+
+    key = talloc_asprintf(notmuch, "maildir_keyword_%c", 'a' + index);
+    if (!key)
+	return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
+    *tag = NULL;
+    tag_string = notmuch->xapian_db->get_metadata (key);
+    if (tag_string.empty ())
+	return NOTMUCH_STATUS_SUCCESS;
+
+    str = tag_string.c_str ();
+    if (str == NULL || *str == '\0')
+	return NOTMUCH_STATUS_SUCCESS;
+
+    *tag = str;
+
+    return NOTMUCH_STATUS_SUCCESS;
+}
+
+notmuch_status_t
+notmuch_database_set_maildir_keyword (notmuch_database_t *notmuch,
+				      int index, const char *tag)
+{
+    string tag_string;
+    const char *key;
+    notmuch_status_t ret;
+    Xapian::WritableDatabase *db;
+
+    if (!notmuch || !tag)
+	return NOTMUCH_STATUS_NULL_POINTER;
+
+    ret = _notmuch_database_ensure_writable (notmuch);
+    if (ret)
+	return ret;
+
+    if (index < 0 || index > ('z' - 'a'))
+	return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
+
+    key = talloc_asprintf(notmuch, "maildir_keyword_%c", 'a' + index);
+    if (!key)
+	return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
+    db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
+    db->set_metadata (key, tag);
+
+    return NOTMUCH_STATUS_SUCCESS;
+}
+
 notmuch_bool_t
 notmuch_database_needs_upgrade (notmuch_database_t *notmuch)
 {
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 310a8b8..779a5ea 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -674,6 +674,24 @@ notmuch_tags_t *
 notmuch_database_get_all_tags (notmuch_database_t *db);
 
 /**
+ * Return the tag corresponding to a maildir keyword.
+ *
+ */
+notmuch_status_t
+notmuch_database_get_maildir_keyword(notmuch_database_t *db,
+				     int index, const char **tag);
+
+/**
+ * Set the tag corresponding to a maildir keyword.
+ *
+ * Note that no messages have their tags modified by this call.
+ */
+
+notmuch_status_t
+notmuch_database_set_maildir_keyword(notmuch_database_t *db,
+				     int index, const char *tag);
+
+/**
  * Create a new query for 'database'.
  *
  * Here, 'database' should be an open database, (see
-- 
2.5.3

  reply	other threads:[~2015-11-26  2:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-26  2:16 [PATCH/RFC 0/3] Maildir custom flags and notmuch tags Igor Almeida
2015-11-26  2:16 ` Igor Almeida [this message]
2015-11-26  2:16 ` [PATCH/RFC 2/3] notmuch new: tag messages based on maildir custom flags Igor Almeida
2015-11-26  2:16 ` [PATCH/RFC 3/3] notmuch new: sync maildir custom flag user configuration Igor Almeida
2016-01-10 13:59 ` [PATCH/RFC 0/3] Maildir custom flags and notmuch tags David Bremner
2016-02-02 16:52   ` Jan Pobrislo
2016-02-03 12:03     ` David Bremner
2016-02-03 14:32       ` Jan Pobrislo
2016-02-03 15:38         ` David Bremner
2016-02-03 15:39           ` David Bremner
2016-02-03 16:00           ` Jan Pobrislo
     [not found]           ` <20160203165650.4ae528c1@dorje.v103.te2000>
2016-02-03 16:04             ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1448504191-30974-2-git-send-email-igor.contato@gmail.com \
    --to=igor.contato@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).