Skip to main content

im_core/email/
service.rs

1pub struct EmailService<'a> {
2    client: &'a crate::core::ImClient,
3}
4
5impl<'a> EmailService<'a> {
6    pub(crate) fn new(client: &'a crate::core::ImClient) -> Self {
7        Self { client }
8    }
9
10    pub fn account(&self) -> crate::ImResult<super::EmailAccount> {
11        crate::internal::email_runtime::EmailRuntime::new(
12            self.client,
13            crate::internal::auth::session::FileSessionProvider::new(self.client),
14            crate::internal::transport::CoreHttpTransport::new(self.client),
15        )
16        .account()
17    }
18
19    pub async fn account_async(&self) -> crate::ImResult<super::EmailAccount> {
20        crate::internal::email_runtime::EmailRuntime::new(
21            self.client,
22            crate::internal::auth::session::FileSessionProvider::new(self.client),
23            crate::internal::transport::CoreHttpTransport::new(self.client),
24        )
25        .account_async()
26        .await
27    }
28
29    pub fn inbox(
30        &self,
31        query: super::EmailInboxQuery,
32    ) -> crate::ImResult<crate::ids::Page<super::EmailMessageSummary>> {
33        crate::internal::email_runtime::EmailRuntime::new(
34            self.client,
35            crate::internal::auth::session::FileSessionProvider::new(self.client),
36            crate::internal::transport::CoreHttpTransport::new(self.client),
37        )
38        .inbox(query)
39    }
40
41    pub async fn inbox_async(
42        &self,
43        query: super::EmailInboxQuery,
44    ) -> crate::ImResult<crate::ids::Page<super::EmailMessageSummary>> {
45        crate::internal::email_runtime::EmailRuntime::new(
46            self.client,
47            crate::internal::auth::session::FileSessionProvider::new(self.client),
48            crate::internal::transport::CoreHttpTransport::new(self.client),
49        )
50        .inbox_async(query)
51        .await
52    }
53
54    pub fn read(&self, id: super::EmailMessageId) -> crate::ImResult<super::EmailMessage> {
55        crate::internal::email_runtime::EmailRuntime::new(
56            self.client,
57            crate::internal::auth::session::FileSessionProvider::new(self.client),
58            crate::internal::transport::CoreHttpTransport::new(self.client),
59        )
60        .read(id)
61    }
62
63    pub async fn read_async(
64        &self,
65        id: super::EmailMessageId,
66    ) -> crate::ImResult<super::EmailMessage> {
67        crate::internal::email_runtime::EmailRuntime::new(
68            self.client,
69            crate::internal::auth::session::FileSessionProvider::new(self.client),
70            crate::internal::transport::CoreHttpTransport::new(self.client),
71        )
72        .read_async(id)
73        .await
74    }
75
76    pub fn mark_read(
77        &self,
78        request: super::EmailMarkReadRequest,
79    ) -> crate::ImResult<super::EmailMarkReadResult> {
80        crate::internal::email_runtime::EmailRuntime::new(
81            self.client,
82            crate::internal::auth::session::FileSessionProvider::new(self.client),
83            crate::internal::transport::CoreHttpTransport::new(self.client),
84        )
85        .mark_read(request)
86    }
87
88    pub async fn mark_read_async(
89        &self,
90        request: super::EmailMarkReadRequest,
91    ) -> crate::ImResult<super::EmailMarkReadResult> {
92        crate::internal::email_runtime::EmailRuntime::new(
93            self.client,
94            crate::internal::auth::session::FileSessionProvider::new(self.client),
95            crate::internal::transport::CoreHttpTransport::new(self.client),
96        )
97        .mark_read_async(request)
98        .await
99    }
100
101    pub fn send(
102        &self,
103        request: super::SendEmailRequest,
104    ) -> crate::ImResult<super::SendEmailResult> {
105        crate::internal::email_runtime::EmailRuntime::new(
106            self.client,
107            crate::internal::auth::session::FileSessionProvider::new(self.client),
108            crate::internal::transport::CoreHttpTransport::new(self.client),
109        )
110        .send(request)
111    }
112
113    pub async fn send_async(
114        &self,
115        request: super::SendEmailRequest,
116    ) -> crate::ImResult<super::SendEmailResult> {
117        crate::internal::email_runtime::EmailRuntime::new(
118            self.client,
119            crate::internal::auth::session::FileSessionProvider::new(self.client),
120            crate::internal::transport::CoreHttpTransport::new(self.client),
121        )
122        .send_async(request)
123        .await
124    }
125
126    pub fn download_attachment(
127        &self,
128        request: super::EmailAttachmentDownloadRequest,
129    ) -> crate::ImResult<super::EmailAttachmentContent> {
130        crate::internal::email_runtime::EmailRuntime::new(
131            self.client,
132            crate::internal::auth::session::FileSessionProvider::new(self.client),
133            crate::internal::transport::CoreHttpTransport::new(self.client),
134        )
135        .download_attachment(request)
136    }
137
138    pub async fn download_attachment_async(
139        &self,
140        request: super::EmailAttachmentDownloadRequest,
141    ) -> crate::ImResult<super::EmailAttachmentContent> {
142        crate::internal::email_runtime::EmailRuntime::new(
143            self.client,
144            crate::internal::auth::session::FileSessionProvider::new(self.client),
145            crate::internal::transport::CoreHttpTransport::new(self.client),
146        )
147        .download_attachment_async(request)
148        .await
149    }
150
151    pub fn notifications(
152        &self,
153        query: super::EmailNotificationQuery,
154    ) -> crate::ImResult<crate::ids::Page<super::EmailNotification>> {
155        crate::internal::email_runtime::EmailRuntime::new(
156            self.client,
157            crate::internal::auth::session::FileSessionProvider::new(self.client),
158            crate::internal::transport::CoreHttpTransport::new(self.client),
159        )
160        .notifications(query)
161    }
162
163    pub async fn notifications_async(
164        &self,
165        query: super::EmailNotificationQuery,
166    ) -> crate::ImResult<crate::ids::Page<super::EmailNotification>> {
167        crate::internal::email_runtime::EmailRuntime::new(
168            self.client,
169            crate::internal::auth::session::FileSessionProvider::new(self.client),
170            crate::internal::transport::CoreHttpTransport::new(self.client),
171        )
172        .notifications_async(query)
173        .await
174    }
175}