Something went wrong. Try again.
A Gmail API client library for Zig: labels, messages, and the mailbox history that turns a second sync into an update.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! A Gmail API client for Zig: labels, messages, and the mailbox history that//! turns a second run into an update rather than another full download.//!//! ## The short version//!//! ```zig//! const gmail = @import("gmail");//!//! var client: gmail.Client = .{ .oauth = oauth, .tokens = &tokens };//! var d: gmail.Client.Diagnostics = .{};//! defer d.deinit(gpa);//!//! var labels = try client.labelMap(io, gpa, &d);//! defer labels.deinit();//!//! var it = client.messageIterator(.{ .q = "-in:chat", .include_spam_trash = true });//! defer it.deinit();//!//! while (try it.next(io, gpa, &d)) |stub| {//! var message = try client.getMessage(io, gpa, stub.id, .{ .format = .raw }, &d);//! defer message.deinit();//! // message.value.raw is the whole RFC 5322 message.//! }//! ```//!//! One message per request is one round trip per message, which is what//! `Client.batchGetMessages` is for once there are thousands of them.//!//! ## What is here//!//! - `Client` -- the API: the profile, the labels, the message listing and//! fetch, the history. It refreshes the access token on its own.//! - `batch` -- Gmail's batch endpoint, which is `multipart/mixed` with whole//! HTTP requests inside it. `Client.batchGetMessages` is fifty message//! fetches in one round trip, which is what makes a first sync bearable.//! - `Message`, `Label`, `History`, `Profile` -- the resources, parsed//! leniently, because Gmail omits empty fields and adds new ones without//! warning.//! - `ApiError` -- Google's error object, and the two questions worth asking//! of it: is this worth retrying, and is this the token.//! - `TokenStore` -- a refresh token in a 0600 file, so that a program works//! twice.//! - `scopes` -- the scope URLs, spelled correctly.//!//! ## What is not//!//! **No OAuth.** Signing in is [zig-oidc]'s job, and this takes one of its//! `Client`s and one of its `TokenSet`s already filled in. The two libraries//! were one library until the OAuth half was pulled out of it, and keeping//! them apart is what lets the flow be tested against something that is not//! Google.//!//! No sending, no drafts, no threads, no settings, no push notifications.//! Reading a mailbox is what this does.//!//! [zig-oidc]: https://git.jcollie.dev/jeff/zig-oidc
const std = @import("std");
pub const ApiError = @import("ApiError.zig");pub const Client = @import("Client.zig");pub const History = @import("History.zig");pub const Label = @import("Label.zig");pub const Message = @import("Message.zig");pub const Profile = @import("Profile.zig");pub const TokenStore = @import("TokenStore.zig");pub const batch = @import("batch.zig");pub const http = @import("http.zig");pub const json = @import("json.zig");pub const scopes = @import("scopes.zig");
/// `oidc.Provider.google`, so that a caller need not import zig-oidc merely to/// name the provider these tokens have to come from.pub const provider = @import("oidc").Provider.google;
test { // One test executable covers one module, and a test is only compiled if // something references the file it is in. Without this, everything below // the root would silently never run. _ = ApiError; _ = Client; _ = History; _ = Label; _ = Message; _ = Profile; _ = TokenStore; _ = batch; _ = http; _ = json; _ = scopes;}