jmap_client/identity/
set.rs

1/*
2 * Copyright Stalwart Labs LLC See the COPYING
3 * file at the top-level directory of this distribution.
4 *
5 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8 * option. This file may not be copied, modified, or distributed
9 * except according to those terms.
10 */
11
12use crate::{core::set::SetObject, email::EmailAddress, Get, Set};
13
14use super::Identity;
15
16impl Identity<Set> {
17    pub fn name(&mut self, name: impl Into<String>) -> &mut Self {
18        self.name = Some(name.into());
19        self
20    }
21
22    pub fn email(&mut self, email: impl Into<String>) -> &mut Self {
23        self.email = Some(email.into());
24        self
25    }
26
27    pub fn bcc<T, U>(&mut self, bcc: Option<T>) -> &mut Self
28    where
29        T: Iterator<Item = U>,
30        U: Into<EmailAddress>,
31    {
32        self.bcc = bcc.map(|s| s.map(|s| s.into()).collect());
33        self
34    }
35
36    pub fn reply_to<T, U>(&mut self, reply_to: Option<T>) -> &mut Self
37    where
38        T: Iterator<Item = U>,
39        U: Into<EmailAddress>,
40    {
41        self.reply_to = reply_to.map(|s| s.map(|s| s.into()).collect());
42        self
43    }
44
45    pub fn text_signature(&mut self, text_signature: impl Into<String>) -> &mut Self {
46        self.text_signature = Some(text_signature.into());
47        self
48    }
49
50    pub fn html_signature(&mut self, html_signature: impl Into<String>) -> &mut Self {
51        self.html_signature = Some(html_signature.into());
52        self
53    }
54}
55
56impl SetObject for Identity<Set> {
57    type SetArguments = ();
58
59    fn new(_create_id: Option<usize>) -> Self {
60        Identity {
61            _create_id,
62            _state: Default::default(),
63            id: None,
64            name: None,
65            email: None,
66            reply_to: Vec::with_capacity(0).into(),
67            bcc: Vec::with_capacity(0).into(),
68            text_signature: None,
69            html_signature: None,
70            may_delete: None,
71        }
72    }
73
74    fn create_id(&self) -> Option<String> {
75        self._create_id.map(|id| format!("c{}", id))
76    }
77}
78
79impl SetObject for Identity<Get> {
80    type SetArguments = ();
81
82    fn new(_create_id: Option<usize>) -> Self {
83        unimplemented!()
84    }
85
86    fn create_id(&self) -> Option<String> {
87        None
88    }
89}