ffrelay_api/
types.rs

1//! Data types for Firefox Relay API requests and responses.
2
3use bon::Builder;
4use serde::{Deserialize, Serialize};
5use tabled::Tabled;
6
7/// Represents an email relay (alias) with its statistics and metadata.
8///
9/// This structure contains information about a single email relay,
10/// including its unique identifier, email address, and usage statistics.
11#[derive(Deserialize, Tabled)]
12pub struct FirefoxEmailRelay {
13    /// Unique identifier for this relay.
14    pub id: u64,
15
16    /// The full email address of the relay (e.g., "abc123@mozmail.com").
17    pub full_address: String,
18
19    /// User-provided description for this relay.
20    pub description: String,
21
22    /// Number of emails that have been blocked by this relay.
23    pub num_blocked: u64,
24
25    /// Number of emails that have been forwarded to your real email address.
26    pub num_forwarded: u64,
27
28    /// Number of emails you've replied to through this relay.
29    pub num_replied: u64,
30
31    /// Number of spam emails detected for this relay.
32    pub num_spam: u64,
33}
34
35impl FirefoxEmailRelay {
36    /// Checks if this relay is a custom domain relay.
37    ///
38    /// Returns `true` if this is a custom domain relay (requires premium subscription),
39    /// or `false` if it's a standard @mozmail.com relay.
40    ///
41    /// # Example
42    ///
43    /// ```
44    /// # use ffrelay_api::types::FirefoxEmailRelay;
45    /// # use serde_json::json;
46    /// # let relay: FirefoxEmailRelay = serde_json::from_value(json!({
47    /// #     "id": 123,
48    /// #     "full_address": "test@mozmail.com",
49    /// #     "description": "test",
50    /// #     "num_blocked": 0,
51    /// #     "num_forwarded": 0,
52    /// #     "num_replied": 0,
53    /// #     "num_spam": 0
54    /// # })).unwrap();
55    /// assert_eq!(relay.is_domain(), false); // Standard relay
56    /// ```
57    pub fn is_domain(&self) -> bool {
58        if let Some((_, dom)) = self.full_address.split_once('@') {
59            !dom.eq("mozmail.com")
60        } else {
61            false
62        }
63    }
64}
65
66/// Request parameters for creating a new email relay.
67///
68/// Use the builder pattern to construct this request. The `description` field
69/// is required, while `enabled` defaults to `true` and `address` is optional.
70///
71/// # Example
72///
73/// ```
74/// use ffrelay_api::types::FirefoxEmailRelayRequest;
75///
76/// // Create a simple relay
77/// let request = FirefoxEmailRelayRequest::builder()
78///     .description("For newsletters".to_string())
79///     .build();
80///
81/// // Create a custom domain relay (requires premium)
82/// let request = FirefoxEmailRelayRequest::builder()
83///     .description("Shopping sites".to_string())
84///     .address("shopping".to_string())
85///     .build();
86/// ```
87#[derive(Debug, Serialize, Builder)]
88pub struct FirefoxEmailRelayRequest {
89    /// Description for the relay to help you remember its purpose.
90    description: String,
91
92    /// Whether the relay should be enabled immediately (defaults to `true`).
93    #[builder(default = true)]
94    enabled: bool,
95
96    /// Optional custom address for domain relays (requires premium subscription).
97    /// If `None`, a random address will be generated.
98    pub address: Option<String>,
99}
100
101/// Detailed information about a Firefox Relay profile.
102///
103/// Contains account-level information including subscription status,
104/// usage statistics, privacy settings, and configuration options.
105#[derive(Debug, Deserialize, Tabled)]
106pub struct FirefoxRelayProfile {
107    /// Unique identifier for this profile.
108    pub id: u64,
109
110    /// The API token for this profile (may be redacted in some responses).
111    pub api_token: String,
112
113    /// Whether the account has reached the maximum number of masks allowed.
114    pub at_mask_limit: bool,
115
116    /// URL to the user's avatar image.
117    pub avatar: String,
118
119    /// Date when the user subscribed to premium features (ISO 8601 format).
120    pub date_subscribed: String,
121
122    /// Total number of emails blocked across all relays.
123    pub emails_blocked: u64,
124
125    /// Total number of emails forwarded across all relays.
126    pub emails_forwarded: u64,
127
128    /// Total number of emails replied to across all relays.
129    pub emails_replied: u64,
130
131    /// Whether the account has the megabundle subscription.
132    pub has_megabundle: bool,
133
134    /// Whether the account has phone masking features.
135    pub has_phone: bool,
136
137    /// Whether the account has a premium subscription.
138    pub has_premium: bool,
139
140    /// Whether the account has Mozilla VPN.
141    pub has_vpn: bool,
142
143    /// Number of level one email trackers blocked.
144    pub level_one_trackers_blocked: u64,
145
146    /// Whether metrics collection is enabled for this profile.
147    pub metrics_enabled: bool,
148
149    /// Timestamp for the next allowed email creation attempt.
150    pub next_email_try: String,
151
152    /// Onboarding state for free tier users.
153    pub onboarding_free_state: u32,
154
155    /// General onboarding state.
156    pub onboarding_state: u32,
157
158    /// Whether level one email tracker removal is enabled.
159    pub remove_level_one_email_trackers: bool,
160
161    /// Whether server-side storage is enabled.
162    pub server_storage: bool,
163
164    /// Whether phone call logs are stored.
165    pub store_phone_log: bool,
166
167    /// Custom subdomain for premium users (e.g., "username" in username@mozilla.email).
168    pub subdomain: String,
169
170    /// Total number of email masks (relays) created.
171    pub total_masks: u64,
172}