Skip to main content

sova_mail/
fake.rs

1//! In-memory sent-mail recorder for tests (`Mail::fake()`).
2
3use crate::email::EmailSnapshot;
4use std::sync::{Arc, Mutex};
5
6/// Shared inbox of emails sent through a fake transport.
7#[derive(Clone, Default)]
8pub struct FakeMail {
9    inner: Arc<Mutex<Vec<EmailSnapshot>>>,
10}
11
12impl FakeMail {
13    pub fn new() -> Self {
14        Self::default()
15    }
16
17    pub(crate) fn record(&self, snap: EmailSnapshot) {
18        self.inner.lock().unwrap().push(snap);
19    }
20
21    /// Snapshot of all messages sent so far.
22    pub fn sent(&self) -> Vec<EmailSnapshot> {
23        self.inner.lock().unwrap().clone()
24    }
25
26    pub fn clear(&self) {
27        self.inner.lock().unwrap().clear();
28    }
29
30    pub fn len(&self) -> usize {
31        self.inner.lock().unwrap().len()
32    }
33
34    pub fn is_empty(&self) -> bool {
35        self.len() == 0
36    }
37}