Skip to main content

agentmail/types/
lists.rs

1use serde::{Deserialize, Serialize};
2
3/// Which traffic direction a list governs.
4#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)]
5#[serde(rename_all = "lowercase")]
6pub enum ListDirection {
7    /// Applied to outbound (sent) mail.
8    Send,
9    /// Applied to inbound (received) mail.
10    Receive,
11    /// Applied to replies.
12    Reply,
13    /// A direction this client version does not recognize.
14    #[serde(other)]
15    Unknown,
16}
17
18impl ListDirection {
19    /// The path segment for this direction.
20    pub(crate) fn as_path(self) -> &'static str {
21        match self {
22            ListDirection::Send => "send",
23            ListDirection::Receive => "receive",
24            ListDirection::Reply => "reply",
25            ListDirection::Unknown => "unknown",
26        }
27    }
28}
29
30/// Whether a list allows or blocks its entries.
31#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)]
32#[serde(rename_all = "lowercase")]
33pub enum ListKind {
34    /// An allow list.
35    Allow,
36    /// A block list.
37    Block,
38    /// A kind this client version does not recognize.
39    #[serde(other)]
40    Unknown,
41}
42
43impl ListKind {
44    /// The path segment for this kind.
45    pub(crate) fn as_path(self) -> &'static str {
46        match self {
47            ListKind::Allow => "allow",
48            ListKind::Block => "block",
49            ListKind::Unknown => "unknown",
50        }
51    }
52}
53
54/// Whether a list entry is an address or a whole domain.
55#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)]
56#[serde(rename_all = "lowercase")]
57pub enum EntryType {
58    /// A single email address.
59    Email,
60    /// A whole domain.
61    Domain,
62    /// An entry type this client version does not recognize.
63    #[serde(other)]
64    Unknown,
65}
66
67/// A single allow/block list entry.
68#[derive(Clone, Debug, Deserialize)]
69pub struct ListEntry {
70    /// The address or domain.
71    pub entry: String,
72    /// Free-text reason recorded with the entry.
73    #[serde(default)]
74    pub reason: Option<String>,
75    /// Whether the entry is an address or a domain.
76    #[serde(default = "unknown_entry_type")]
77    pub entry_type: EntryType,
78    /// The organization the entry belongs to.
79    #[serde(default)]
80    pub organization_id: Option<String>,
81    /// Whether the entry is read-only (system-managed).
82    #[serde(default)]
83    pub read_only: bool,
84    /// Timestamp the entry was created (RFC 3339).
85    #[serde(default)]
86    pub created_at: Option<String>,
87}
88
89fn unknown_entry_type() -> EntryType {
90    EntryType::Unknown
91}
92
93/// Request body for [`Client::create_list_entry`](crate::Client::create_list_entry).
94#[derive(Clone, Debug, Default, Serialize)]
95pub struct CreateListEntry {
96    /// The address or domain to add.
97    pub entry: String,
98    /// An optional reason to record with the entry.
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub reason: Option<String>,
101}
102
103/// One page of list entries from [`Client::list_list_entries_page`](crate::Client::list_list_entries_page).
104#[derive(Clone, Debug, Deserialize)]
105pub struct ListEntries {
106    /// Total entries in the list (not just this page).
107    pub count: u64,
108    /// This page of entries.
109    #[serde(default)]
110    pub entries: Vec<ListEntry>,
111    /// Cursor for the next page; `None` on the last page.
112    #[serde(default)]
113    pub next_page_token: Option<String>,
114}