1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
-
+
-
-
-
+
-
|
use crate::{
Cursor,
telegram::{
telegram::TelegramTransport,
encode,
TelegramTransport,
},
utils::{
Attachment,
RE_DOMAIN,
validate,
},
};
use std::{
borrow::Cow,
collections::{
HashMap,
HashSet,
},
io::Error,
sync::Arc,
};
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
-
-
+
+
-
+
-
+
-
+
-
-
-
-
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
-
+
-
-
|
rcpt.insert(self.get_id(item)?);
};
if rcpt.is_empty() {
self.tg.debug("No recipient or envelope address.").await?;
rcpt.insert(&self.tg.default);
};
// prepating message header
let mut reply: Vec<String> = vec![];
// preparing message header
let mut reply: Vec<String> = vec!["<blockquote expandable>".into()];
if self.fields.contains("subject") {
if let Some(subject) = mail.subject() {
reply.push(format!("__*Subject:*__ `{}`", encode(subject)));
reply.push(format!("<u><i>Subject:</i></u> <code>{}</code>", validate(subject).stack()?));
} else if let Some(thread) = mail.thread_name() {
reply.push(format!("__*Thread:*__ `{}`", encode(thread)));
reply.push(format!("<u><i>Thread:</i></u> <code>{}</code>", validate(thread).stack()?));
}
}
// do we need to replace spaces here?
if self.fields.contains("from") {
reply.push(format!("__*From:*__ `{}`", encode(&headers.from)));
reply.push(format!("<u><i>From:</i></u> <code>{}</code>", validate(&headers.from).stack()?));
}
if self.fields.contains("date") {
if let Some(date) = mail.date() {
reply.push(format!("__*Date:*__ `{date}`"));
}
if self.fields.contains("date")
&& let Some(date) = mail.date()
{
reply.push(format!("<u><i>Date:</i></u> <code>{date}</code>"));
}
}
let header_size = reply.join(" ").len() + 1;
reply.push("</blockquote><pre>".into());
let reply = reply.join("\n");
let html_parts = mail.html_body_count();
let text_parts = mail.text_body_count();
let attachments = mail.attachment_count();
if html_parts != text_parts {
self.tg.debug(&format!("Hm, we have {html_parts} HTML parts and {text_parts} text parts.")).await?;
}
//let mut html_num = 0;
let mut text_num = 0;
let mut file_num = 0;
// let's display first html or text part as body
let mut body: Cow<'_, str> = "".into();
let mut body: String = "".into();
/*
* actually I don't wanna parse that html stuff
if html_parts > 0 {
let text = mail.body_html(0).stack()?;
if text.len() < 4096 - header_size {
body = text;
html_num = 1;
}
};
*/
if body.is_empty() && text_parts > 0 {
let text = mail.body_text(0)
.context("Failed to extract text from message")?;
if text.len() < 4096 - header_size {
.context("Failed to extract text from message")?
.replace("\r\n", "\n");
// 6:
// - (headers)
// - (mail text)
// - 6: </pre>
if text.len() < 4096 - ( reply.len() + 6 ) {
body = text;
text_num = 1;
}
};
reply.push("```".into());
let msg = format!("{}{}</pre>", reply, validate(&body).stack()?);
reply.extend(body.lines().map(|x| x.into()));
reply.push("```".into());
// and let's collect all other attachment parts
let mut files_to_send = vec![];
/*
* let's just skip html parts for now, they just duplicate text?
while html_num < html_parts {
files_to_send.push(mail.html_part(html_num).stack()?);
|
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
-
|
}
while file_num < attachments {
files_to_send.push(mail.attachment(file_num.try_into().stack()?)
.context("Failed to get file part from message.")?);
file_num += 1;
}
let msg = reply.join("\n");
for chat in rcpt {
if !files_to_send.is_empty() {
let mut files = vec![];
// let mut first_one = true;
for chunk in &files_to_send {
let data: Vec<u8> = chunk.contents().to_vec();
let mut filename: Option<String> = None;
|