X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=bindings%2Fruby%2Fdatabase.c;h=90c220a14b93a0c5bafaf5fd807645fd782bb2ec;hb=898613116db746aa0f915ae43da8aba28545203d;hp=f4edd77303afb2be7ed64b22d49b789cd43b1472;hpb=5c9e385591b66fa20cbb186393c48c52831a23b7;p=notmuch diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c index f4edd773..90c220a1 100644 --- a/bindings/ruby/database.c +++ b/bindings/ruby/database.c @@ -1,6 +1,6 @@ /* The Ruby interface to the notmuch mail library * - * Copyright © 2010 Ali Polatel + * Copyright © 2010, 2011 Ali Polatel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -204,6 +204,44 @@ notmuch_rb_database_upgrade(VALUE self) return Qtrue; } +/* + * call-seq: DB.begin_atomic => nil + * + * Begin an atomic database operation. + */ +VALUE +notmuch_rb_database_begin_atomic(VALUE self) +{ + notmuch_status_t ret; + notmuch_database_t *db; + + Data_Get_Notmuch_Database(self, db); + + ret = notmuch_database_begin_atomic(db); + notmuch_rb_status_raise(ret); + + return Qtrue; +} + +/* + * call-seq: DB.end_atomic => nil + * + * Indicate the end of an atomic database operation. + */ +VALUE +notmuch_rb_database_end_atomic(VALUE self) +{ + notmuch_status_t ret; + notmuch_database_t *db; + + Data_Get_Notmuch_Database(self, db); + + ret = notmuch_database_end_atomic(db); + notmuch_rb_status_raise(ret); + + return Qtrue; +} + /* * call-seq: DB.get_directory(path) => DIR * @@ -292,6 +330,66 @@ notmuch_rb_database_remove_message(VALUE self, VALUE pathv) return (ret == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) ? Qtrue : Qfalse; } +/* + * 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 *