io_email/envelope/event.rs
1//! Watch event shared across all protocols.
2//!
3//! Surfaced by the watch-mailbox API as a continuous stream. Each
4//! variant is the pre-diffed delta the backend observed: envelopes
5//! added or removed from the watched mailbox, and per-message flag
6//! additions or removals computed against the watcher's in-memory
7//! shadow.
8
9use alloc::{collections::BTreeSet, string::String};
10
11use crate::{envelope::types::Envelope, flag::types::Flag};
12
13/// Delta produced by a watch-mailbox stream.
14///
15/// `mailbox` is the watched mailbox name (always the same value for the
16/// lifetime of a single stream). Flag deltas are split into `FlagsAdded`
17/// and `FlagsRemoved` so hook configs can target one side of a toggle
18/// (e.g. "fire when `\Seen` is added").
19#[derive(Clone, Debug)]
20#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case", tag = "type"))]
22pub enum WatchEvent {
23 /// A new message landed in the watched mailbox.
24 EnvelopeAdded { mailbox: String, envelope: Envelope },
25 /// An existing message was expunged from the watched mailbox.
26 EnvelopeRemoved { mailbox: String, id: String },
27 /// One or more flags were set on an existing message.
28 FlagsAdded {
29 mailbox: String,
30 id: String,
31 flags: BTreeSet<Flag>,
32 },
33 /// One or more flags were unset on an existing message.
34 FlagsRemoved {
35 mailbox: String,
36 id: String,
37 flags: BTreeSet<Flag>,
38 },
39 /// The transport is still alive but had no changes to report.
40 /// Useful for callers that want to distinguish "stream healthy" from
41 /// "stream stalled" without arming their own timer.
42 KeepAlive,
43}