Check-in [03fe0265ac]
Logged in as anonymous
Overview
Comment:fix parsing a little...
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 03fe0265ac73dda6c8d166ee54afe63791d95f4e5d152f8b2fd1921d5e9b5f43
User & Date: arcade on 2024-05-22 15:11:57.371
Other Links: manifest | tags
Context
2024-05-22
19:09
also parse Sender header check-in: 9c12e26fb6 user: arcade tags: trunk
15:11
fix parsing a little... check-in: 03fe0265ac user: arcade tags: trunk
13:39
mess with header/body formatting check-in: 667b874fdb user: arcade tags: trunk
Changes
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106







-
+







					let mut reply: Vec<Cow<str>> = vec![];
					if let Some(subject) = mail.subject() {
						reply.push(format!("**Subject:** `{}`", subject).into());
					} else if let Some(thread) = mail.thread_name() {
						reply.push(format!("**Thread:** `{}`", thread).into());
					}
					if let Some(from) = mail.from() {
						reply.push(format!("**From:** `{:?}`", from).into());
						reply.push(format!("**From:** `{:?}`", address_into_iter(from).collect::<Vec<_>>().join(", ")).into());
					}
					if let Some(sender) = mail.sender() {
						reply.push(format!("**Sender:** `{:?}`", sender).into());
					}
					reply.push("".into());
					let header_size = reply.join("\n").len() + 1;

129
130
131
132
133
134
135

136


137
138
139
140
141
142
143
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145







+
-
+
+







						let text = mail.body_text(0).unwrap();
						if text.len() < 4096 - header_size {
							body = text;
							text_num = 1;
						}
					};
					reply.push("```".into());
					for line in body.lines() {
					reply.push(body);
						reply.push(line.into());
					}
					reply.push("```".into());

					// and let's coillect 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 {
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
155
156
157
158
159
160
161

162
163
164
165
166
167
168







-







						files_to_send.push(mail.attachment(file_num).unwrap());
						file_num += 1;
					}

					for chat in rcpt {
						core.send(chat, reply.join("\n")).await.unwrap();
						for chunk in &files_to_send {
							task::sleep(Duration::from_secs(5)).await;
							let data = chunk.contents().to_vec();
							let obj = telegram_bot::types::InputFileUpload::with_data(data, "Attachment");
							core.sendfile(chat, obj).await.unwrap();
						}
					}
				},
				None => { core.debug("None mail.").await.unwrap(); },
198
199
200
201
202
203
204

205
206

207
208
209
210
211

212
213

214
215
216
217
218

219
220
221
222
223
224
225
199
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
225
226
227
228
229







+

-
+





+

-
+





+







			tg,
			recipients,
		}
	}

	pub async fn debug<'b, S>(&self, msg: S) -> Result<()>
	where S: Into<Cow<'b, str>> {
		task::sleep(Duration::from_secs(5)).await;
		self.tg.send(SendMessage::new(self.default, msg)
			.parse_mode(ParseMode::Html)).await?;
			.parse_mode(ParseMode::Markdown)).await?;
		Ok(())
	}

	pub async fn send<'b, S>(&self, to: UserId, msg: S) -> Result<()>
	where S: Into<Cow<'b, str>> {
		task::sleep(Duration::from_secs(5)).await;
		self.tg.send(SendMessage::new(to, msg)
			.parse_mode(ParseMode::Html)).await?;
			.parse_mode(ParseMode::Markdown)).await?;
		Ok(())
	}

	pub async fn sendfile<V>(&self, to: UserId, chunk: V) -> Result<()>
	where V: Into<telegram_bot::InputFile> {
		task::sleep(Duration::from_secs(5)).await;
		self.tg.send(telegram_bot::SendDocument::new(to, chunk)).await?;
		Ok(())
	}
}

#[async_std::main]
async fn main() {