aboutsummaryrefslogtreecommitdiffhomepage
path: root/bindings/ruby
diff options
context:
space:
mode:
authorGravatar Ali Polatel <alip@exherbo.org>2011-10-04 16:06:20 +0300
committerGravatar Ali Polatel <alip@exherbo.org>2011-10-04 16:06:20 +0300
commit898613116db746aa0f915ae43da8aba28545203d (patch)
treea46a2cbb6ae2f095e8065983f21da75e23401ab0 /bindings/ruby
parent520c9c3131b84e30e0d31084a94c55c265f2042f (diff)
ruby: Add wrappers for database_find_message*
Two new wrappers: Notmuch::Database.find_message(id) => Notmuch::Message or nil Notmuch::Database.find_message_by_filename(path) => Notmuch::Message or nil
Diffstat (limited to 'bindings/ruby')
-rw-r--r--bindings/ruby/database.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index a4659ca3..90c220a1 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -331,6 +331,66 @@ notmuch_rb_database_remove_message(VALUE self, VALUE pathv)
}
/*
+ * call-seq: DB.find_message(id) => MESSAGE or nil
+ *
+ * Find a message by message id.
+ */
+VALUE
+notmuch_rb_database_find_message(VALUE self, VALUE idv)
+{
+ const char *id;
+ notmuch_status_t ret;
+ notmuch_database_t *db;
+ notmuch_message_t *message;
+
+ Data_Get_Notmuch_Database(self, db);
+
+#if !defined(RSTRING_PTR)
+#define RSTRING_PTR(v) (RSTRING((v))->ptr)
+#endif /* !defined(RSTRING_PTR) */
+
+ SafeStringValue(idv);
+ id = RSTRING_PTR(idv);
+
+ ret = notmuch_database_find_message(db, id, &message);
+ notmuch_rb_status_raise(ret);
+
+ if (message)
+ return Data_Wrap_Struct(notmuch_rb_cMessage, NULL, NULL, message);
+ return Qnil;
+}
+
+/*
+ * call-seq: DB.find_message_by_filename(path) => MESSAGE or nil
+ *
+ * Find a message by filename.
+ */
+VALUE
+notmuch_rb_database_find_message_by_filename(VALUE self, VALUE pathv)
+{
+ const char *path;
+ notmuch_status_t ret;
+ notmuch_database_t *db;
+ notmuch_message_t *message;
+
+ Data_Get_Notmuch_Database(self, db);
+
+#if !defined(RSTRING_PTR)
+#define RSTRING_PTR(v) (RSTRING((v))->ptr)
+#endif /* !defined(RSTRING_PTR) */
+
+ SafeStringValue(pathv);
+ path = RSTRING_PTR(pathv);
+
+ ret = notmuch_database_find_message_by_filename(db, path, &message);
+ notmuch_rb_status_raise(ret);
+
+ if (message)
+ return Data_Wrap_Struct(notmuch_rb_cMessage, NULL, NULL, message);
+ return Qnil;
+}
+
+/*
* call-seq: DB.query(query) => QUERY
*
* Retrieve a query object for the query string 'query'