sendry/resources/
inbound.rs1use reqwest::Method;
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7use crate::{client::Sendry, error::Error, Page, PaginationParams};
8
9#[derive(Debug, Clone)]
11pub struct Inbound {
12 client: Sendry,
13}
14
15impl Inbound {
16 pub(crate) fn new(client: Sendry) -> Self {
17 Self { client }
18 }
19
20 pub async fn list(&self, params: PaginationParams) -> Result<Page<InboundEmail>, Error> {
22 let q = params.to_query();
23 self.client
24 .request(self.client.build::<()>(Method::GET, "/v1/inbound", &q, None))
25 .await
26 }
27
28 pub async fn get(&self, id: &str) -> Result<InboundEmail, Error> {
30 self.client
31 .request(self.client.build::<()>(
32 Method::GET,
33 &format!("/v1/inbound/{id}"),
34 &[],
35 None,
36 ))
37 .await
38 }
39
40 pub async fn get_config(&self) -> Result<InboundConfig, Error> {
42 self.client
43 .request(self.client.build::<()>(
44 Method::GET,
45 "/v1/inbound/config",
46 &[],
47 None,
48 ))
49 .await
50 }
51
52 pub async fn update_config(
54 &self,
55 params: UpdateInboundConfig,
56 ) -> Result<InboundConfig, Error> {
57 self.client
58 .request(self.client.build(
59 Method::PUT,
60 "/v1/inbound/config",
61 &[],
62 Some(¶ms),
63 ))
64 .await
65 }
66}
67
68#[derive(Debug, Clone, Deserialize)]
70pub struct InboundEmailAttachment {
71 pub filename: String,
73 #[serde(rename = "contentType")]
75 pub content_type: String,
76 pub size: u64,
78 #[serde(rename = "contentId", default)]
80 pub content_id: Option<String>,
81}
82
83#[derive(Debug, Clone, Deserialize)]
85pub struct InboundEmail {
86 pub id: String,
88 pub from: String,
90 pub to: Vec<String>,
92 #[serde(default)]
94 pub cc: Vec<String>,
95 pub subject: Option<String>,
97 pub text: Option<String>,
99 pub html: Option<String>,
101 pub headers: Option<HashMap<String, String>>,
103 #[serde(default)]
105 pub attachments: Vec<InboundEmailAttachment>,
106 pub webhook_delivered: bool,
108 pub created_at: String,
110}
111
112#[derive(Debug, Clone, Deserialize)]
114pub struct InboundConfig {
115 pub url: Option<String>,
117 pub secret: Option<String>,
119}
120
121#[derive(Debug, Clone, Serialize)]
123pub struct UpdateInboundConfig {
124 pub url: Option<String>,
126 #[serde(skip_serializing_if = "Option::is_none")]
128 pub secret: Option<String>,
129}