operations capa

operations-mail-sync

Provider-agnostic mail sync worker loop over MailReader/RefreshPolicy, plus quota/audit send-path composition over MailSender

Provider-agnostic mail sync worker loop over MailReader/RefreshPolicy, plus quota/audit send-path composition over MailSender

Tieroperations
Roleunclassified (baselined)
Pathcrates/operations/mail-sync
Edition2021
Targetsoperations_mail_sync, composite_account
Public items12 across 4 modules
Tests14

What it is for

# operations-mail-sync

Two responsibilities (sprint 3.45 crate 10):

1. The sync worker loop (SyncWorker): turns a foundation_refresh_policy::RefreshPolicy decision into MailReader::list/fetch calls, persisting through a caller-supplied MailStore seam. Advances the cursor only after a full page has been persisted with zero errors (Gate 1.5.6 batch-failure rule). 2. Send-path quota/audit composition (SendGuard): wires operations-rate-limit and foundation-audit-log around a &dyn MailSender, per sprint 3.45's "No new crate" decision (Gate 0.5 dedup — composition, not a new primitives-mail-send-guard crate).

Source: rust-gmail-manager/src/services/sync_service.rs's worker-loop portion — the override -> full -> incremental -> bootstrap decision logic itself was already lifted into foundation-refresh-policy (crate 2); this crate builds the loop AROUND that decision, not a second extraction of it. See CHANGELOG.md for the full Gate 4.5 provenance note.

Capabilities

MailSyncError

Errors for the operations-mail-sync worker loop and send-path composition.

Item
pub enum MailSyncError

SendGuardError

Errors for the operations-mail-sync worker loop and send-path composition.

Item
pub enum SendGuardError

AuditSink

Send-path composition: quota (operations-rate-limit) + audit

Item
pub trait AuditSink

SendGuard

Send-path composition: quota (operations-rate-limit) + audit

Item
pub struct SendGuard
SendGuard :: fn per_day(max_per_day : u64) -> Self
SendGuard :: async fn send(& self, sender : & dyn MailSender, message : & Email, audit : & dyn AuditSink, override_quota : bool,) -> Result <SendReceipt, SendGuardError>

MailStore

MailStore — the persistence seam the sync worker writes through.

Item
pub trait MailStore

SyncOutcome

The sync worker loop: RefreshPolicy::decide chooses a SyncStrategy,

Item
pub struct SyncOutcome

SyncRequest

The sync worker loop: RefreshPolicy::decide chooses a SyncStrategy,

Item
pub struct SyncRequest<'a>

SyncWorker

The sync worker loop: RefreshPolicy::decide chooses a SyncStrategy,

Item
pub struct SyncWorker<'a>

SyncWorker<'a>

The sync worker loop: RefreshPolicy::decide chooses a SyncStrategy,

Item
SyncWorker<'a> :: fn new(reader : & 'a dyn MailReader, store : & 'a dyn MailStore, policy : RefreshPolicy,) -> Self
SyncWorker<'a> :: async fn run(& self, request : & SyncRequest <'_>) -> Result <SyncOutcome, MailSyncError>

How to use it

No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.

Module structure

operations_mail_sync

flowchart TD
  n_operations_mail_sync["operations_mail_sync"]
  n_operations_mail_sync --> n_error["error"]
  n_operations_mail_sync --> n_send_guard["send_guard"]
  n_operations_mail_sync --> n_store["store"]
  n_operations_mail_sync --> n_worker["worker"]

Public surface

`error`

ItemWhat it is
pub enum MailSyncErrorErrors from the sync worker loop (crate::worker::SyncWorker)
pub enum SendGuardErrorErrors from the send-path quota/audit composition (crate::send_guard::SendGuard).

`send_guard`

ItemWhat it is
pub trait AuditSinkWhere SendGuard writes every send/throttle/deny audit event
pub struct SendGuardComposes a per-day, per-recipient quota (operations-rate-limit) with mandatory audit logging (foundation-audit-log) around a &dyn MailSender.
SendGuard :: fn per_day(max_per_day : u64) -> SelfA guard enforcing max_per_day sends per recipient address (RateLimitKey::new("recipient", addr)).
SendGuard :: async fn send(& self, sender : & dyn MailSender, message : & Email, audit : & dyn AuditSink, override_quota : bool,) -> Result <SendReceipt, SendGuardError>Send message through sender, enforcing the per-recipient daily quota (checked against every address in message.to) unless override_quota is set, and recording an audit event for every outcome: mail.send (sent), mail.send.throttled (quota denied), or mail.send.denied (the backend itself rejected/failed the send)

`store`

ItemWhat it is
pub trait MailStoreWhere the sync worker persists fetched messages and the sync cursor

`worker`

ItemWhat it is
pub struct SyncRequest<'a>One sync run's request parameters.
pub struct SyncOutcomePer-run counters, mirroring rust-gmail-manager's SyncReport (new_emails/updated_emails/errors), plus the strategy this run resolved to (useful for caller-side logging/telemetry).
pub struct SyncWorker<'a>The sync worker: composes a &dyn MailReader, a RefreshPolicy, and a &dyn MailStore into one account's sync run
SyncWorker<'a> :: fn new(reader : & 'a dyn MailReader, store : & 'a dyn MailStore, policy : RefreshPolicy,) -> SelfCompose a worker from a reader backend, a storage seam, and a decision policy.
SyncWorker<'a> :: async fn run(& self, request : & SyncRequest <'_>) -> Result <SyncOutcome, MailSyncError>Run one sync: decide the strategy, page through list()/fetch(), persist through store, and advance the stored cursor only after a full page has been persisted with zero errors

Re-exports. Exported here, defined elsewhere.

ExportDefined in
MailStorestore::MailStore
{AuditSink,SendGuard}send_guard::{AuditSink,SendGuard}
{MailSyncError,SendGuardError}error::{MailSyncError,SendGuardError}
{SyncOutcome,SyncRequest,SyncWorker}worker::{SyncOutcome,SyncRequest,SyncWorker}

Boundary

Reaches into foundation.

Shares tier operations with 40 other crates: operations-approval-workflow, operations-assessments, operations-block-imaging, operations-boot-media, operations-browser-agent-worker, operations-camera-discovery, operations-camera-liveview, operations-camera-registry, … (40 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)operations
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/operations/mail-sync
Vocabulary in force (lexicon)current

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

flowchart LR
  n_operations["operations"] --> n_foundation["foundation"]

Dependencies

Runtime, in this workspace.

CrateTierOptionalOnly on
`foundation-audit-log`foundationnoalways
`foundation-mail-message`foundationnoalways
`foundation-refresh-policy`foundationnoalways
`operations-rate-limit`operationsnoalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
async-trait^0.1noalways
chrono^0.4serdenoalways
serde^1derivenoalways
serde_json^1noalways
thiserror^2noalways
tokio^1fullnoalways
uuid^1v4, v7, serde, jsnoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
tokio^1full, macros, rt-multi-threadnoalways

Build. None.

Depended on by. 1 workspace crate.

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

flowchart LR
  n_tools_mail_manager["tools-mail-manager"] -->|uses| SELF
  SELF["operations-mail-sync"]
  SELF -->|runtime| n_foundation_audit_log["foundation-audit-log"]
  SELF -->|runtime| n_foundation_mail_message["foundation-mail-message"]
  SELF -->|runtime| n_foundation_refresh_policy["foundation-refresh-policy"]
  SELF -->|runtime| n_operations_rate_limit["operations-rate-limit"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.

Targets

KindNameSource
liboperations_mail_sync`src/lib.rs`
testcomposite_account`tests/composite_account.rs`

Error model

Error typeNamed by
MailSyncErrordeclared, no public signature returns it
SendGuardErrordeclared, no public signature returns it

Operational characteristics

PropertyEvidence
async public surfaceyes
async runtimeyes
database accessnone detected
network I/Onone detected
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.

1 workspace crate depends on this one: tools-mail-manager.

Verification

KindCount
Unit tests13
Integration tests1
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
error202
send_guard202
store101
worker303

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc1212
Public modules with a //! block44
pie showData
    title Public items with rustdoc
    "Documented" : 12
    "No rustdoc detected" : 0

Metrics

MetricValue
Rust source files5
Source lines1151
Code lines797
Public API items12
Public modules4
Tests14
Examples0
Cargo features0
Direct runtime dependencies11
Workspace reverse dependencies1
pie showData
    title Public API by kind
    "enum" : 2
    "method" : 4
    "struct" : 4
    "trait" : 2
pie showData
    title Rust source composition
    "Code" : 797
    "Blank or comment" : 354

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 operations · Manual