From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 102026DE021D for ; Wed, 25 Nov 2015 18:16:54 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.801 X-Spam-Level: X-Spam-Status: No, score=-0.801 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_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MsVd5ov0_EZP for ; Wed, 25 Nov 2015 18:16:50 -0800 (PST) Received: from mail-qg0-f41.google.com (mail-qg0-f41.google.com [209.85.192.41]) by arlo.cworth.org (Postfix) with ESMTPS id 49A1E6DE18F2 for ; Wed, 25 Nov 2015 18:16:50 -0800 (PST) Received: by qgea14 with SMTP id a14so45748138qge.0 for ; Wed, 25 Nov 2015 18:16:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/XitwozIVezmpJjXOJchGJm9LBEPzSd28ook1esCBOg=; b=T/52MbLPS0TDBoJsJ1sV3QcVOz6B+6EbridfKQYTwfDlNGo3iGH3UM4D9thR7UEDCu xwGLzYUEFQ9T5blknpbQNEcVVMYoTuk3/Y3fX8yjYhgJBl3UtjIj/Z8cu/wNK2J0sEKE MbHuFgArcgrSGAvx6ICxnLA+ZfiZcnx3B+bXaZpYDIKXRCOCkBOIwBcjCasgcKsn7UuW kNkZ5ChD8iL6aMnxxnX+mSrx0NwiIYwgh3u8+zP6jXzeYVxbwxOoLvlpYU0j/2Is5BdR sHsFKOOf+3I52rIC4lgsl7217+S7hHqa7FrwGaQcH+eaXxSv4b3zgC9bObWMQ9Ow2S+p QkxQ== X-Received: by 10.140.105.101 with SMTP id b92mr34664504qgf.5.1448504209256; Wed, 25 Nov 2015 18:16:49 -0800 (PST) Received: from arch-laptop.localdomain ([200.195.16.216]) by smtp.gmail.com with ESMTPSA id h206sm1566011qhc.43.2015.11.25.18.16.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Nov 2015 18:16:48 -0800 (PST) From: Igor Almeida 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 Message-Id: <1448504191-30974-2-git-send-email-igor.contato@gmail.com> X-Mailer: git-send-email 2.5.3 In-Reply-To: <1448504191-30974-1-git-send-email-igor.contato@gmail.com> References: <1448504191-30974-1-git-send-email-igor.contato@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 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: Thu, 26 Nov 2015 02:16:54 -0000 --- 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 (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