Diff
Logged in as anonymous

Differences From Artifact [7173095649]:

To Artifact [bbe46eca75]:


1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
use crate::{
	Cursor,
	telegram::{
		encode,
		TelegramTransport,
	},
	utils::{
		Attachment,
		RE_DOMAIN,

	},
};

use std::{
	borrow::Cow,
	collections::{
		HashMap,


|
<
<
<



>







1
2
3



4
5
6
7
8
9
10
11
12
13
14
use crate::{
	Cursor,
	telegram::TelegramTransport,



	utils::{
		Attachment,
		RE_DOMAIN,
		validate,
	},
};

use std::{
	borrow::Cow,
	collections::{
		HashMap,
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
				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![];
			if self.fields.contains("subject") {
				if let Some(subject) = mail.subject() {
					reply.push(format!("__*Subject:*__`{}`", encode(subject)));
				} else if let Some(thread) = mail.thread_name() {
					reply.push(format!("__*Thread:*__`{}`", encode(thread)));
				}
			}
			// do we need to replace spaces here?
			if self.fields.contains("from") {
				reply.push(format!("__*From:*__`{}`", encode(&headers.from)));
			}
			if self.fields.contains("date") {
				if let Some(date) = mail.date() {

					reply.push(format!("__*Date:*__`{date}`"));
				}





			}
			let header_size = reply.join(" ").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?;
			}







|
|


|

|




|

|
|
>
|
|
>
>
>
>
>

<







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
				rcpt.insert(self.get_id(item)?);
			};
			if rcpt.is_empty() {
				self.tg.debug("No recipient or envelope address.").await?;
				rcpt.insert(&self.tg.default);
			};

			// 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!("<u><i>Subject:</i></u><code>{}</code>", validate(subject).stack()?));
				} else if let Some(thread) = mail.thread_name() {
					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!("<u><i>From:</i></u><code>{}</code>", validate(&headers.from).stack()?));
			}
			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 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?;
			}
185
186
187
188
189
190
191




192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
					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 {
					body = text;
					text_num = 1;
				}
			};
			reply.push("```".into());
			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()?);







>
>
>
>
|




<

|







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
					html_num = 1;
				}
			};
			*/
			if body.is_empty() && text_parts > 0 {
				let text = mail.body_text(0)
					.context("Failed to extract text from message")?;
				// 7:
				// - (mail text)
				// - 1 trailing newline
				// - 6: </pre>
				if text.len() < 4096 - ( header_size + 7 ) {
					body = text;
					text_num = 1;
				}
			};

			reply.extend(body.lines().map(|x| x.into()));
			reply.push("</pre>".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()?);