use serde::{Deserialize, Serialize}; use std::sync::Arc; use tokio::sync::Mutex; #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct Mail { pub from: String, pub to: String, pub date: String, pub reply_to: String, pub subject: String, pub body: Vec, } #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct MailPart { pub content_type: String, pub data: String, } #[derive(Debug, Clone)] pub struct Mailbox(Arc>>); impl Mailbox { pub fn new() -> Self { Self(Arc::new(Mutex::new(vec![]))) } pub async fn store(&self, mail: Mail) { let mut inner = self.0.lock().await; inner.push(mail); tracing::info!("New message stored"); } pub async fn clear(&self) { let mut inner = self.0.lock().await; inner.clear(); } pub async fn all(&self) -> Vec { let inner = self.0.lock().await; inner.clone() } }