Skip to main content

mailbourne_core/
event.rs

1//! # event — everything the engine announces
2//!
3//! One enum, designed once, used everywhere: the in-process stream that
4//! library consumers subscribe to, the log narrator's input, outbound
5//! webhooks, and (later) zebflow triggers. If something happens to a
6//! message, it is a [`MailEvent`] — there is no second announcement channel.
7
8/// A lifecycle event emitted by the engine.
9///
10/// Marked `#[non_exhaustive]`: new variants will appear as the engine grows,
11/// and consumers must keep a catch-all arm.
12#[non_exhaustive]
13#[derive(Debug, Clone)]
14pub enum MailEvent {
15    /// An outbound message was accepted by the remote server (`250` to our
16    /// `DATA`). Responsibility has transferred.
17    Delivered {
18        /// Engine-assigned identifier of the message.
19        message_id: String,
20        /// The recipient this delivery was for.
21        recipient: String,
22    },
23    /// The remote server said "not now" (4xx). The message stays queued and
24    /// will be retried with backoff — this is normal email behavior, not an
25    /// error (greylisting relies on it).
26    Deferred {
27        /// Engine-assigned identifier of the message.
28        message_id: String,
29        /// The recipient whose delivery was deferred.
30        recipient: String,
31        /// Which delivery attempt this was (1-based).
32        attempt: u32,
33    },
34    /// The remote server said "no, permanently" (5xx), or the queue lifetime
35    /// expired. A bounce is generated toward the envelope `MAIL FROM`.
36    Bounced {
37        /// Engine-assigned identifier of the message.
38        message_id: String,
39        /// The recipient that could not be reached.
40        recipient: String,
41        /// The SMTP status code that ended the attempt.
42        code: u16,
43        /// The remote server's human-readable reason line.
44        reason: String,
45    },
46    /// An inbound message was accepted and stored.
47    Received {
48        /// Engine-assigned identifier of the message.
49        message_id: String,
50        /// The envelope sender it arrived with.
51        from: String,
52        /// The local mailbox it was delivered to.
53        mailbox: String,
54    },
55}