templateless/
email.rs

1use serde::Serialize;
2use std::collections::HashSet;
3
4use crate::{Content, EmailAddress, Result};
5
6#[derive(Clone, Serialize)]
7#[serde(rename_all = "camelCase")]
8pub struct EmailOptions {
9	#[serde(skip_serializing_if = "Option::is_none")]
10	delete_after: Option<u64>,
11}
12
13#[derive(Clone, Serialize)]
14#[serde(rename_all = "camelCase")]
15pub struct Email {
16	to: HashSet<EmailAddress>,
17	subject: String,
18	content: Content,
19	options: EmailOptions,
20}
21
22impl Email {
23	pub fn builder() -> Self {
24		Self {
25			to: HashSet::new(),
26			subject: "".to_string(),
27			content: Content::builder(),
28			options: EmailOptions { delete_after: None },
29		}
30	}
31
32	pub fn to(mut self, email_address: EmailAddress) -> Self {
33		self.to.insert(email_address);
34		self
35	}
36
37	pub fn to_many(mut self, email_addresses: Vec<EmailAddress>) -> Self {
38		for email_address in email_addresses.into_iter() {
39			self.to.insert(email_address);
40		}
41
42		self
43	}
44
45	pub fn subject(mut self, subject: &str) -> Self {
46		self.subject = subject.to_string();
47		self
48	}
49
50	pub fn content(mut self, content: Content) -> Self {
51		self.content = content;
52		self
53	}
54
55	pub fn delete_after(mut self, seconds: u64) -> Self {
56		self.options.delete_after = Some(seconds);
57		self
58	}
59
60	pub fn build(&self) -> Result<Self> {
61		Ok(self.clone())
62	}
63}