Diff
Logged in as anonymous

Differences From Artifact [c4a8eb25d5]:

To Artifact [b5c79e7814]:


10
11
12
13
14
15
16

17
18
19
20
21
22
23
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24







+







	smtp::{
		SmtpParser,
		Prudence,
	},
};
use telegram_bot::{
	Api,
	MessageOrChannelPost,
	ParseMode,
	SendMessage,
	UserId,
};

use std::{
	borrow::Cow,
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
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







-
+


















-
+



-
+







					};
					reply.push("```".into());
					for line in body.lines() {
						reply.push(line.into());
					}
					reply.push("```".into());

					// and let's coillect all other attachment parts
					// 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).unwrap());
						html_num += 1;
					}
					*/
					while text_num < text_parts {
						files_to_send.push(mail.text_part(text_num).unwrap());
						text_num += 1;
					}
					while file_num < attachments {
						files_to_send.push(mail.attachment(file_num).unwrap());
						file_num += 1;
					}

					for chat in rcpt {
						core.send(chat, reply.join("\n")).await.unwrap();
						let base_post = core.send(chat, reply.join("\n")).await.unwrap();
						for chunk in &files_to_send {
							let data = chunk.contents().to_vec();
							let obj = telegram_bot::types::InputFileUpload::with_data(data, "Attachment");
							core.sendfile(chat, obj).await.unwrap();
							core.sendfile(chat, obj, Some(&base_post)).await.unwrap();
						}
					}
				},
				None => { core.debug("None mail.").await.unwrap(); },
			};
		});

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





230



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249


250
251
252
253
254
255
256
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
230
231
232
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264







-
+


-
-
+
+
-


-
+


-
-
+
+
-


-
+


+
+
+
+
+
-
+
+
+



















+
+








		TelegramTransport {
			tg,
			recipients,
		}
	}

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

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

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

#[async_std::main]
async fn main() {
	let settings: config::Config = config::Config::builder()
		.add_source(config::File::with_name("smtp2tg.toml"))
		.build()
		.expect("[smtp2tg.toml] there was an error reading config\n\
			\tplease consult \"smtp2tg.toml.example\" for details");

	let maildir: PathBuf = settings.get_string("maildir")
		.expect("[smtp2tg.toml] missing \"maildir\" parameter.\n").into();
	let listen_on = settings.get_string("listen_on")
		.expect("[smtp2tg.toml] missing \"listen_on\" parameter.\n");
	let core = TelegramTransport::new(settings);
	let sink = Builder + Name::new("smtp2tg") + DebugService +
		my_prudence() + MailDir::new(maildir.clone()).unwrap();

	env_logger::init();

	task::spawn(async move {
		loop {
			relay_mails(&maildir, &core).unwrap();
			task::sleep(Duration::from_secs(5)).await;
		}
	});