infrastructure capa

infrastructure-adapters-google-gmail

Gmail adapter via OAuth2 — read, send, search, and manage email

Gmail adapter via OAuth2 — read, send, search, and manage email

Tierinfrastructure
Roleunclassified (baselined)
Pathcrates/infrastructure/adapters-google-gmail
Edition2021
Targetsauthorize, test_inbox, infrastructure_adapters_google_gmail
Public items0 across 0 modules
Tests49

What it is for

Gmail adapter via OAuth2 for personal Google accounts.

Provides an async client for the Gmail API v1 using OAuth2 authorization code flow with refresh token persistence.

# Setup

1. Create an OAuth client ID in GCP Console (Web application type) 2. Add http://localhost:8085 as an authorized redirect URI 3. Run the authorize example to get a refresh token:

cargo run -p infrastructure-adapters-google-gmail --example authorize

4. Use the client:

use infrastructure_adapters_google_gmail::GmailClient;
let client = GmailClient::from_files(
"client-secrets.json",
"gmail-token.json",
"http://localhost:8085",
)?;
let messages = client.list_messages(Some("is:unread"), 10, None).await?;

Capabilities

No public items.

How to use it

From `examples/authorize.rs`:


use infrastructure_adapters_google_gmail::{generate_pkce, OAuthConfig};
use std::io::{BufRead, BufReader, Write};
use std::net::TcpListener;

const REDIRECT_URI: &str = "http://localhost:8085";
const SCOPES: &[&str] = &[
    "https://www.googleapis.com/auth/gmail.modify",
    "https://www.googleapis.com/auth/gmail.send",
    "https://www.googleapis.com/auth/gmail.readonly",
];

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let args = CliArgs::parse(std::env::args().skip(1));

    let client_json_path = args
        .client_json

From `examples/test_inbox.rs`:


use infrastructure_adapters_google_gmail::GmailClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = GmailClient::from_files(
        "/home/nwheelo/.config/wa-bridge/oauth-client.json",
        "/home/nwheelo/.config/wa-bridge/gmail-token.json",
        "http://localhost:8085",
    )?;

    println!("=== Unread Messages (last 5) ===\n");

    let list = client.list_messages(Some("is:unread"), 5, None).await?;

    match list.messages {
        Some(refs) => {
            for msg_ref in &refs {

Module structure

No public modules: the crate root is its whole surface.

Public surface

No public items.

Re-exports. Exported here, defined elsewhere.

ExportDefined in
GmailClientclient::GmailClient
GmailErrorerror::GmailError
{build_raw_email,encode_base64url,Header,Label,LabelList,Message,MessageList,MessagePart,MessagePartBody,MessageRef,SendRequest,}types::{build_raw_email,encode_base64url,Header,Label,LabelList,Message,MessageList,MessagePart,MessagePartBody,MessageRef,SendRequest,}
{build_raw_mime,email_from_message}mime::{build_raw_mime,email_from_message}
{generate_pkce,pkce_challenge,random_state,OAuthConfig,PkcePair,TokenData}auth::{generate_pkce,pkce_challenge,random_state,OAuthConfig,PkcePair,TokenData}

Boundary

Reaches into foundation.

Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, infrastructure-ai, … (82 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)infrastructure
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/infrastructure/adapters-google-gmail
Vocabulary in force (lexicon)current

Tier flow. Which tiers this crate's own edges cross.

flowchart LR
  n_infrastructure["infrastructure"] --> n_foundation["foundation"]

Dependencies

Runtime, in this workspace.

CrateTierOptionalOnly on
`foundation-audit-log`foundationnoalways
`foundation-mail-message`foundationnoalways
`infrastructure-fetcher`infrastructureyesalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
async-trait^0.1noalways
base64^0.22noalways
chrono^0.4serdenoalways
hex^0.4noalways
reqwest^0.12jsonnoalways
serde^1derivenoalways
serde_json^1noalways
thiserror^2noalways
tokio^1net, io-util, macros, rt-multi-threadnoalways
tracing^0.1noalways
urlencoding^2noalways
uuid^1v4, v7, serde, jsnoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
wiremock^0.6noalways

Build. None.

Depended on by. 4 workspace crates.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_google_gmail["application-google-gmail"] -->|uses| SELF
  n_infrastructure_mail_headers["infrastructure-mail-headers"] -->|uses| SELF
  n_tools_mail_manager["tools-mail-manager"] -->|uses| SELF
  n_tools_paced_send["tools-paced-send"] -->|uses| SELF
  SELF["infrastructure-adapters-google-gmail"]
  SELF -->|runtime| n_foundation_audit_log["foundation-audit-log"]
  SELF -->|runtime| n_foundation_mail_message["foundation-mail-message"]
  SELF -->|runtime| n_infrastructure_fetcher["infrastructure-fetcher"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

FeatureEnablesOn by default
defaultsecure-egressyes
secure-egressdep:infrastructure-fetcheryes
flowchart LR
  n_default["default"] --> n_secure_egress["secure-egress"]
  n_secure_egress["secure-egress"] --> n_dep_infrastructure_fetcher["dep:infrastructure-fetcher"]

Targets

KindNameSource
exampleauthorize`examples/authorize.rs`
exampletest_inbox`examples/test_inbox.rs`
libinfrastructure_adapters_google_gmail`src/lib.rs`

Error model

No public error type was detected: no public item declares a type named *Error, and no public signature returns one.

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimeyes
database accessnone detected
network I/Oyes
unsafe codenone detected
environment variablesnone detected

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.

4 workspace crates depend on this one: application-google-gmail, infrastructure-mail-headers, tools-mail-manager, tools-paced-send.

Verification

KindCount
Unit tests49
Integration tests0
Examples2
Doctests0

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc00
Public modules with a //! block00

Metrics

MetricValue
Rust source files7
Source lines2478
Code lines1965
Public API items0
Public modules0
Tests49
Examples2
Cargo features2
Direct runtime dependencies15
Workspace reverse dependencies4
pie showData
    title Rust source composition
    "Code" : 1965
    "Blank or comment" : 513

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

Todas las infrastructure · Manual