Diff
Logged in as anonymous

Differences From Artifact [bbe46eca75]:

To Artifact [3793bdb43d]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18











-







use crate::{
	Cursor,
	telegram::TelegramTransport,
	utils::{
		Attachment,
		RE_DOMAIN,
		validate,
	},
};

use std::{
	borrow::Cow,
	collections::{
		HashMap,
		HashSet,
	},
	io::Error,
	sync::Arc,
};
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
208
209
210
211
212
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







-
+
-
-
-
-











-
+












-
-
+
+
+
+

-

-
+




-
-
+







			}
			if self.fields.contains("date")
				&& let Some(date) = mail.date()
			{
				reply.push(format!("<u><i>Date:</i></u> <code>{date}</code>"));
			}
			reply.push("</blockquote><pre>".into());
			//let header_size = reply.join(" ").len();
			let reply = reply.join("\n");
			let mut header_size = 0;
			for i in reply.iter() {
				header_size += i.len() + 1;
			}

			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")?;
				// 7:
					.context("Failed to extract text from message")?
					.replace("\r\n", "\n");
				// 6:
				// - (headers)
				// - (mail text)
				// - 1 trailing newline
				// - 6: </pre>
				if text.len() < 4096 - ( header_size + 7 ) {
				if text.len() < 4096 - ( reply.len() + 7 ) {
					body = text;
					text_num = 1;
				}
			};
			reply.extend(body.lines().map(|x| x.into()));
			reply.push("</pre>".into());
			let msg = format!("{}{}</pre>", reply, validate(&body).stack()?);

			// 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()?);
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
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;