serenade_mailer/
attachment.rs1#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum ContentDisposition {
6 Attachment,
8 Inline,
10}
11
12#[derive(Clone, Debug, Eq, PartialEq)]
14pub struct Attachment {
15 filename: String,
16 content_type: String,
17 body: Vec<u8>,
18 disposition: ContentDisposition,
19 content_id: Option<String>,
20}
21
22impl Attachment {
23 #[must_use]
25 pub fn from_bytes(
26 filename: impl Into<String>,
27 content_type: impl Into<String>,
28 body: impl Into<Vec<u8>>,
29 ) -> Self {
30 Self {
31 filename: filename.into(),
32 content_type: content_type.into(),
33 body: body.into(),
34 disposition: ContentDisposition::Attachment,
35 content_id: None,
36 }
37 }
38
39 #[must_use]
43 pub fn inline_from_bytes(
44 filename: impl Into<String>,
45 content_type: impl Into<String>,
46 content_id: impl Into<String>,
47 body: impl Into<Vec<u8>>,
48 ) -> Self {
49 Self {
50 filename: filename.into(),
51 content_type: content_type.into(),
52 body: body.into(),
53 disposition: ContentDisposition::Inline,
54 content_id: Some(content_id.into()),
55 }
56 }
57
58 #[must_use]
60 pub fn filename(&self) -> &str {
61 &self.filename
62 }
63
64 #[must_use]
66 pub fn content_type(&self) -> &str {
67 &self.content_type
68 }
69
70 #[must_use]
72 pub fn body(&self) -> &[u8] {
73 &self.body
74 }
75
76 #[must_use]
78 pub const fn disposition(&self) -> ContentDisposition {
79 self.disposition
80 }
81
82 #[must_use]
84 pub fn content_id(&self) -> Option<&str> {
85 self.content_id.as_deref()
86 }
87
88 #[must_use]
90 pub const fn is_inline(&self) -> bool {
91 matches!(self.disposition, ContentDisposition::Inline)
92 }
93}