Commit
+51 -45 +/-3 browse
1 | diff --git a/ayllu-mail/src/delivery.rs b/ayllu-mail/src/delivery.rs |
2 | index 44e69e6..6f0286e 100644 |
3 | --- a/ayllu-mail/src/delivery.rs |
4 | +++ b/ayllu-mail/src/delivery.rs |
5 | @@ -147,17 +147,17 @@ pub async fn deliver_all(config: &Config) -> Result<Summary, Error> { |
6 | message.to() |
7 | ); |
8 | |
9 | + // read_headers(&message), |
10 | if let Err(err) = mail::Database(&db) |
11 | - .deliver( |
12 | + .deliver(&mail::DeliveryParams { |
13 | message_id, |
14 | - mail_to.as_slice(), |
15 | + mail_to: mail_to.as_slice(), |
16 | mail_from, |
17 | subject, |
18 | - content_body.as_ref(), |
19 | - message_bytes.as_slice(), |
20 | - read_headers(&message), |
21 | + content_body: content_body.as_ref(), |
22 | + raw_message: message_bytes.as_slice(), |
23 | in_reply_to, |
24 | - ) |
25 | + }) |
26 | .await |
27 | { |
28 | summary |
29 | diff --git a/ayllu-mail/src/server.rs b/ayllu-mail/src/server.rs |
30 | index 01d3746..e3cb102 100644 |
31 | --- a/ayllu-mail/src/server.rs |
32 | +++ b/ayllu-mail/src/server.rs |
33 | @@ -45,31 +45,32 @@ pub async fn serve(config: &Config) -> Result<(), Error> { |
34 | .read_only(false) |
35 | .build() |
36 | .await?; |
37 | - mail::Database(&db).setup( |
38 | - config |
39 | |
40 | - .lists |
41 | - .iter() |
42 | - .map(|cfg_list| List { |
43 | - name: cfg_list.name.clone(), |
44 | - address: cfg_list.address.clone(), |
45 | - description: cfg_list.description.clone(), |
46 | - enabled: cfg_list.enabled.is_none_or(|enabled| enabled), |
47 | - }) |
48 | - .collect(), |
49 | - config.mail.participants.as_ref().map(|participants| { |
50 | - participants |
51 | + mail::Database(&db) |
52 | + .setup( |
53 | + config |
54 | |
55 | + .lists |
56 | .iter() |
57 | - .map(|participant| Participant { |
58 | - name: participant.name.clone(), |
59 | - address: participant.address.clone(), |
60 | - authorized_sender: participant.authorized_sender, |
61 | - subscriptions: participant.subscriptions.clone(), |
62 | + .map(|cfg_list| List { |
63 | + name: cfg_list.name.clone(), |
64 | + address: cfg_list.address.clone(), |
65 | + description: cfg_list.description.clone(), |
66 | + enabled: cfg_list.enabled.is_none_or(|enabled| enabled), |
67 | }) |
68 | - .collect() |
69 | - }), |
70 | - ) |
71 | - .await?; |
72 | + .collect(), |
73 | + config.mail.participants.as_ref().map(|participants| { |
74 | + participants |
75 | + .iter() |
76 | + .map(|participant| Participant { |
77 | + name: participant.name.clone(), |
78 | + address: participant.address.clone(), |
79 | + authorized_sender: participant.authorized_sender, |
80 | + subscriptions: participant.subscriptions.clone(), |
81 | + }) |
82 | + .collect() |
83 | + }), |
84 | + ) |
85 | + .await?; |
86 | let maildir = Maildir::from(config.mail.maildir.clone()); |
87 | tracing::info!( |
88 | "Initializing maildir path: {}", |
89 | diff --git a/crates/database/src/mail.rs b/crates/database/src/mail.rs |
90 | index c59cd3e..30dc6d5 100644 |
91 | --- a/crates/database/src/mail.rs |
92 | +++ b/crates/database/src/mail.rs |
93 | @@ -73,6 +73,16 @@ pub struct ThreadSummary { |
94 | pub reply_count: i64, |
95 | } |
96 | |
97 | + pub struct DeliveryParams<'a> { |
98 | + pub message_id: &'a str, |
99 | + pub mail_to: &'a[&'a str], |
100 | + pub mail_from: &'a str, |
101 | + pub subject: Option<&'a str>, |
102 | + pub raw_message: &'a [u8], |
103 | + pub content_body: &'a str, |
104 | + pub in_reply_to: Option<&'a str>, |
105 | + } |
106 | + |
107 | pub struct Database<'a>(pub &'a Wrapper); |
108 | |
109 | impl Database<'_> { |
110 | @@ -122,6 +132,8 @@ impl Database<'_> { |
111 | .await?; |
112 | if let Some(subscriptions) = &participant.subscriptions { |
113 | for subscription in subscriptions { |
114 | + // FIXME declarative |
115 | + tracing::info!("Creating subscription: {}", subscription); |
116 | sqlx::query_file!( |
117 | "../../queries/mail_upsert_subscription.sql", |
118 | participant.address, |
119 | @@ -139,36 +151,29 @@ impl Database<'_> { |
120 | |
121 | pub async fn deliver( |
122 | &self, |
123 | - message_id: &str, |
124 | - mail_to: &[&str], |
125 | - mail_from: &str, |
126 | - subject: Option<&str>, |
127 | - content_body: &str, // fixme |
128 | - raw_message: &[u8], |
129 | - headers: Vec<(String, String)>, // fixme |
130 | - in_reply_to: Option<&str>, |
131 | + params: &DeliveryParams<'_>, |
132 | ) -> Result<Vec<i64>, Error> { |
133 | let mut tx = self.0.pool.begin().await?; |
134 | let participant_id = sqlx::query_file!( |
135 | "../../queries/mail_upsert_participant.sql", |
136 | - mail_from, |
137 | + params.mail_from, |
138 | false, |
139 | - mail_from |
140 | + params.mail_from |
141 | ) |
142 | .fetch_one(&mut *tx) |
143 | .await? |
144 | .id; |
145 | let mut message_ids: Vec<i64> = Vec::new(); |
146 | - for mail_to_addr in mail_to.iter() { |
147 | + for mail_to_addr in params.mail_to.iter() { |
148 | let ret = sqlx::query_file!( |
149 | "../../queries/mail_deliver_message.sql", |
150 | - message_id, |
151 | + params.message_id, |
152 | mail_to_addr, |
153 | - in_reply_to, |
154 | - subject, |
155 | + params.in_reply_to, |
156 | + params.subject, |
157 | participant_id, |
158 | - content_body, |
159 | - raw_message, |
160 | + params.content_body, |
161 | + params.raw_message, |
162 | ) |
163 | .fetch_one(&mut *tx) |
164 | .await?; |