pidge_client/lib.rs
1//! Microsoft 365 client and OAuth flows for the pidge CLI.
2//!
3//! Provides `AuthClient` (sign-in, refresh, token retrieval) and `GraphClient`
4//! (Microsoft Graph API access). Depends on `pidge-core` for types.
5
6pub mod auth;
7mod error;
8pub mod graph;
9pub mod mcp;
10#[cfg(test)]
11pub(crate) mod test_support;
12pub mod unsubscribe;
13
14pub use auth::AuthClient;
15pub use error::ClientError;
16pub use graph::{GraphClient, MailFolder, Outgoing};
17pub use unsubscribe::{UnsubscribeMethod, mailto_subject, parse_unsubscribe};
18
19pub mod cursor;
20
21pub use cursor::{Cursor, CursorError};
22
23/// Resolve pidge's config directory, which the config-dir-rooted stores
24/// (Microsoft tokens in `auth::file_store`, MCP tokens in `mcp::store`)
25/// live under: `${XDG_CONFIG_HOME:-~/.config}/pidge` on Linux and macOS,
26/// `%APPDATA%\pidge` on Windows (see `pidge_core::paths`).
27///
28/// In tests, honors a thread-local override set via
29/// [`test_support::with_base_dir`] so tests never mutate process-wide
30/// `HOME`/`XDG_CONFIG_HOME` env vars: two independent stores' tests
31/// overriding those globally, each behind its own lock, can still race
32/// across threads in the same test binary. A thread-local sidesteps that
33/// entirely: it's invisible to every thread but the one that set it, so
34/// parallel `#[test]` functions never interfere and no lock is needed.
35///
36/// In production this is always `pidge_core::paths::config_dir()`.
37pub(crate) fn config_dir() -> Result<std::path::PathBuf, ClientError> {
38 #[cfg(test)]
39 if let Some(base) = test_support::base_dir_override() {
40 return Ok(base);
41 }
42 pidge_core::paths::config_dir().ok_or(ClientError::NoConfigDir)
43}
44
45#[cfg(test)]
46mod tests {
47 #[test]
48 fn config_dir_is_pidge_core_paths_config_dir() {
49 // No thread-local override on this thread: production resolution.
50 assert_eq!(
51 super::config_dir().ok(),
52 pidge_core::paths::config_dir(),
53 "client stores must share the one XDG-style config dir"
54 );
55 }
56}