//! What a mailbox's labels say a message's state is: moved from //! cotton-core's `rules::email_state` (which re-exports it) so the mail //! decoder the Worker runs as WASM decides it the same way. /// The Gmail label ids Cotton keeps a COLUMN for. /// /// Everything else Gmail says about a message rides `labels` verbatim — a label /// with no column is still visible, never silently dropped. pub mod gmail_labels { pub const INBOX: &str = "INBOX"; pub const UNREAD: &str = "UNREAD"; pub const STARRED: &str = "STARRED"; pub const TRASH: &str = "TRASH"; } /// The columns v33 derives from a Gmail label set. #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct EmailState { pub unread: bool, pub starred: bool, pub in_inbox: bool, /// `TRASH` — the bin. A `trashed_at` INSTANT is what the row stores; the /// instant is the writer's clock, so it is not decided here. pub trashed: bool, } /// Gmail's labels → the four facts Cotton keeps columns for. pub fn email_state_from_labels(labels: &[String]) -> EmailState { let has = |label: &str| labels.iter().any(|l| l == label); EmailState { unread: has(gmail_labels::UNREAD), starred: has(gmail_labels::STARRED), in_inbox: has(gmail_labels::INBOX), trashed: has(gmail_labels::TRASH), } }