···2424database: *c.notmuch_database_t,
25252626pub const OpenOptions = struct {
2727- config_path: ?[:0]const u8,
2828- database_path: ?[*:0]const u8,
2929- profile: ?[:0]const u8,
2727+ /// Specify a config file.
2828+ config_path: ?[:0]const u8 = null,
2929+ /// Specify a database path.
3030+ database_path: ?[*:0]const u8 = null,
3131+ /// Specify a profile.
3232+ profile: ?[:0]const u8 = null,
3033};
31343535+/// Open an existing notmuch database.
3236pub fn open(mode: DATABASE_MODE, options: OpenOptions) Error!Database {
3337 if (!c.LIBNOTMUCH_CHECK_VERSION(5, 6, 0)) {
3438 return error.NotmuchVersion;
···3741 var error_message: [*c]u8 = null;
3842 var database: ?*c.notmuch_database_t = null;
3943 try wrapMessage(c.notmuch_database_open_with_config(
4040- options.database_path orelse null,
4444+ options.database_path,
4145 @intFromEnum(mode),
4242- options.config_path orelse null,
4343- options.profile orelse null,
4646+ options.config_path,
4747+ options.profile,
4448 &database,
4549 &error_message,
4650 ), error_message);
···5054}
51555256pub const CreateOptions = struct {
5353- config_path: ?[:0]const u8,
5454- database_path: ?[*:0]const u8,
5555- profile: ?[:0]const u8,
5757+ /// Specify a config file.
5858+ config_path: ?[:0]const u8 = null,
5959+ /// Specify a database path.
6060+ database_path: ?[*:0]const u8 = null,
6161+ /// Specify a profile.
6262+ profile: ?[:0]const u8 = null,
5663};
57646565+/// Create a new notmuch database.
5866pub fn create(options: CreateOptions) Error!Database {
5967 if (!c.LIBNOTMUCH_CHECK_VERSION(5, 6, 0)) {
6068 return error.NotmuchVersion;
···6472 var database: ?*c.notmuch_database_t = null;
6573 try wrapMessage(
6674 c.notmuch_database_create_with_config(
6767- options.database_path orelse null,
6868- options.config_path orelse null,
6969- options.profile orelse null,
7575+ options.database_path,
7676+ options.config_path,
7777+ options.profile,
7078 &database,
7179 &error_message,
7280 ),
···7785 };
7886}
79878888+/// Close the database.
8089pub fn close(self: *const Database) void {
8190 _ = c.notmuch_database_close(self.database);
8291}
83929393+/// Destroy the notmuch database, closing it if necessary and freeing all
9494+/// associated resources.
9595+///
9696+/// Return value as in notmuch_database_close if the database was open;
9797+/// notmuch_database_destroy itself has no failure modes.
9898+pub fn destroy(self: *const Database) Error!void {
9999+ try wrap(c.notmuch_database_destroy(self.database));
100100+}
101101+84102pub fn indexFile(self: *const Database, filename: [:0]const u8, indexopts: ?IndexOpts) Error!void {
85103 try wrap(c.notmuch_database_index_file(
86104 self.database,
···90108 ));
91109}
92110111111+/// A callback invoked by Database.compact to notify the user of the
112112+/// progress of the compaction process.
113113+pub const StatusCallback = fn (message: [*c]const u8, closure: ?*anyopaque) callconv(.c) void;
114114+115115+/// Compact a notmuch database, backing up the original database to the given
116116+/// path.
117117+///
118118+/// The database will be opened in read-write mode during the compaction process
119119+/// to ensure no writes are made.
120120+///
121121+/// If the optional callback function `status_cb` is non-`null`, it will be
122122+/// called with diagnostic and informational messages. The argument `closure` is
123123+/// passed verbatim to any callback invoked.
124124+pub fn compact(path: [:0]const u8, backup_path: [:0]const u8, status_cb: ?StatusCallback, closure: ?*anyopaque) Error!void {
125125+ try wrap(c.notmuch_database_compact(path, backup_path, status_cb, closure));
126126+}
127127+128128+/// Return the database format version of the database.
129129+pub fn getVersion(self: *const Database) error{FormatVersionError}!c_uint {
130130+ const version = c.notmuch_database_get_version(self.database);
131131+ if (version == 0) return error.FormatVersionError;
132132+ return version;
133133+}
134134+135135+/// Can the database be upgraded to a newer database version?
136136+///
137137+/// If this function returns TRUE, then the caller may call
138138+/// notmuch_database_upgrade to upgrade the database. If the caller does
139139+/// not upgrade an out-of-date database, then some functions may fail with
140140+/// NOTMUCH_STATUS_UPGRADE_REQUIRED. This always returns FALSE for a read-only
141141+/// database because there's no way to upgrade a read-only database.
142142+///
143143+/// Also returns FALSE if an error occurs accessing the database.
144144+pub fn needsUpgrade(self: *const Database) bool {
145145+ return c.notmuch_database_needs_upgrade(self.database) != 0;
146146+}
147147+148148+pub const UpgradeProgressNotifyCallback = fn (closure: ?*anyopaque, progress: f64) callconv(.c) void;
149149+150150+/// Upgrade the current database to the latest supported version.
151151+///
152152+/// This ensures that all current notmuch functionality will be available on the
153153+/// database. After opening a database in read-write mode, it is recommended
154154+/// that clients check if an upgrade is needed (Database.needsUpgrade) and
155155+/// if so, upgrade with this function before making any modifications. If
156156+/// Database.needsUpgrade returns FALSE, this will be a no-op.
157157+///
158158+/// The optional `progress_notify` callback can be used by the caller to provide
159159+/// progress indication to the user. If non-`null` it will be called periodically
160160+/// with `progress` as a floating-point value in the range of [0.0 .. 1.0]
161161+/// indicating the progress made so far in the upgrade process. The argument
162162+/// `closure` is passed verbatim to any callback invoked.
163163+pub fn upgrade(self: *const Database, progress_notify: ?UpgradeProgressNotifyCallback, closure: ?*anyopaque) Error!void {
164164+ try wrap(c.notmuch_database_upgrade(self.database, progress_notify, closure));
165165+}
166166+93167pub fn indexFileGetMessage(self: *const Database, filename: [:0]const u8, indexopts: ?IndexOpts) Error!Message {
94168 var message: ?*c.notmuch_message_t = null;
95169 wrap(c.notmuch_database_index_file(
···134208 return std.mem.span(config orelse return null);
135209}
136210137137-/// get a configuration value from an open database.
211211+/// Get a configuration value from an open database.
138212///
139213/// This value reflects all configuration information given at the time
140214/// the database was opened.
141215///
142142-/// Returns NULL if 'key' unknown or if no value is known for 'key'.
143143-/// Otherwise returns a string owned by notmuch which should not be modified
216216+/// Returns `null` if `key` is unknown or if no value is known for `key`.
217217+/// Otherwise returns a string owned by `notmuch` which should not be modified
144218/// nor freed by the caller.
145219pub fn configGet(self: *const Database, key: CONFIG) Error!?[:0]const u8 {
146220 return std.mem.span(c.notmuch_config_get(self.database, @intFromEnum(key)) orelse return null);
147221}
148222149149-/// set a configuration value
223223+/// Set a configuration value
150224pub fn configSet(self: *const Database, key: CONFIG, value: [:0]const u8) Error!void {
151225 try wrap(c.notmuch_config_set(self.database, @intFromEnum(key), value));
152226}
153227154154-/// Returns an iterator for a ';'-delimited list of configuration values
228228+/// Returns an iterator for a `;`-delimited list of configuration values.
155229///
156230/// These values reflect all configuration information given at the
157231/// time the database was opened.
···197271 };
198272}
199273200200-/// Create a new query for 'database'.
201201-///
202202-/// Here, 'database' should be an open database, (see `open` and `create`).
274274+/// Create a new query.
203275///
204276/// For the query string, we'll document the syntax here more completely in the
205277/// future, but it's likely to be a specialized version of the general Xapian
···215287/// `Query.searchMessages` and `Query.searchThreads` to actually execute the
216288/// query.
217289pub fn queryCreate(self: *const Database, query_string: [:0]const u8) Error!Query {
218218- return .{
219219- .query = c.notmuch_query_create(self.database, query_string) orelse return error.OutOfMemory,
220220- };
290290+ return .init(c.notmuch_query_create(self.database, query_string) orelse return error.OutOfMemory);
221291}
222292223293pub fn queryCreateWithSyntax(self: *const Database, query_string: [:0]const u8, syntax: QUERY_SYNTAX) Error!Query {
···225295226296 try wrap(c.notmuch_query_create_with_syntax(self.database, query_string, @intFromEnum(syntax), &query));
227297228228- return .{
229229- .query = query orelse return error.OutOfMemory,
230230- };
298298+ return .init(query orelse return error.OutOfMemory);
231299}
232300233301pub const IndexOpts = struct {
+9-5
src/Query.zig
···18181919query: *c.notmuch_query_t,
20202121-/// Return the query_string of this query.
2121+pub fn init(query: *c.notmuch_query_t) Query {
2222+ return .{ .query = query };
2323+}
2424+2525+/// Return the query string of this query.
2226pub fn getQueryString(self: *const Query) [:0]const u8 {
2327 return std.mem.span(c.notmuch_query_get_query_string(self.query));
2428}
25292626-/// Specify whether to omit excluded results or simply flag them. By default,
3030+/// Specify whether to omit excluded results or simply flag them. By default,
2731/// this is set to TRUE.
2832///
2933/// If set to TRUE or ALL, notmuch_query_search_messages will omit excluded
3034/// messages from the results, and notmuch_query_search_threads will
3131-/// omit threads that match only in excluded messages. If set to TRUE,
3535+/// omit threads that match only in excluded messages. If set to TRUE,
3236/// notmuch_query_search_threads will include all messages in threads that
3333-/// match in at least one non-excluded message. Otherwise, if set to ALL,
3737+/// match in at least one non-excluded message. Otherwise, if set to ALL,
3438/// notmuch_query_search_threads will omit excluded messages from all threads.
3539///
3640/// If set to FALSE or FLAG then both notmuch_query_search_messages and
···4347/// completely ignored.
4448///
4549/// The performance difference when calling notmuch_query_search_messages should
4646-/// be relatively small (and both should be very fast). However, in some cases,
5050+/// be relatively small (and both should be very fast). However, in some cases,
4751/// notmuch_query_search_threads is very much faster when omitting excluded
4852/// messages as it does not need to construct the threads that only match in
4953/// excluded messages.
+4-2
src/enums.zig
···1717 count += 1;
1818 }
1919 }
2020+ const TagType = std.math.IntFittingRange(0, max);
2021 var field_names: [count]std.builtin.Type.EnumField = undefined;
2121- var field_values: [count]std.math.IntFittingRange(0, max) = undefined;
2222+ var field_values: [count]TagType = undefined;
2223 var index = 0;
2324 outer: for (info.@"struct".decls) |decl| {
2425 for (skips) |skip| if (std.mem.eql(u8, skip, decl.name)) continue :outer;
···2930 }
3031 }
3132 return @Enum(
3232- std.math.IntFittingRange(0, max),
3333+ TagType,
3334 .exhaustive,
3435 &field_names,
3536 &field_values,
···5455/// Sort values for notmuch_query_set_sort.
5556pub const SORT = generateEnum("NOTMUCH_SORT_", &.{});
56575858+/// Status codes used for the return values of most functions.
5759pub const STATUS = generateEnum("NOTMUCH_STATUS_", &.{"NOTMUCH_STATUS_LAST_STATUS"});
+9
src/error.zig
···1212pub const Error = error{
1313 BadQuerySyntax,
1414 ClosedDatabase,
1515+ /// Database already exists, not created.
1516 DatabaseExists,
1617 DuplicateMessageID,
1718 FailedCryptoContextCreation,
1919+ /// An error occurred trying to open the database or config file (such as
2020+ /// permission denied, or file not found, etc.).
1821 FileError,
1922 FileNotEmail,
2323+ /// There was an error determining the database format version.
2424+ FormatVersionError,
2025 Ignored,
2126 IllegalArgument,
2227 MaformedCryptoProtocol,
2328 NoConfig,
2429 NoDatabase,
2530 NoMailRoot,
3131+ /// A newer version of the notmuch library is required.
2632 NotmuchVersion,
2733 NullPointer,
3434+ /// Out of memory.
2835 OutOfMemory,
2936 PathError,
3037 ReadOnlyDatabase,
···3340 UnbalancedFreezeThaw,
3441 UnknownCryptoProtocol,
3542 UnsupportedOperation,
4343+ /// The database needs to be upgraded to a newer format.
3644 UpgradeRequired,
4545+ /// A Xapian exception occurred.
3746 XapianException,
3847};
3948