Diff
Logged in as anonymous

Differences From Artifact [1f629cd869]:

To Artifact [86c96bbf98]:


1
2
3
4
5
6
7
8
9
10

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










+







//! Simple SMTP-to-Telegram gateway. Can parse email and send them as telegram
//! messages to specified chats, generally you specify which email address is
//! available in configuration, everything else is sent to default address.

use anyhow::{
	anyhow,
	bail,
	Result,
};
use async_std::{
	fs::metadata,
	io::Error,
	task,
};
use just_getopt::{
	OptFlags,
	OptSpecs,
	OptValueType,
36
37
38
39
40
41
42

43
44
45
46
47
48
49
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51







+








use std::{
	borrow::Cow,
	collections::{
		HashMap,
		HashSet,
	},
	os::unix::fs::PermissionsExt,
	path::Path,
	vec::Vec,
};

/// `SomeHeaders` object to store data through SMTP session
#[derive(Clone, Debug)]
struct SomeHeaders {
371
372
373
374
375
376
377









378
379
380
381
382
383
384
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395







+
+
+
+
+
+
+
+
+







	} else {
		"smtp2tg.toml"
	});
	if !config_file.exists() {
		eprintln!("Error: can't read configuration from {:?}", config_file);
		std::process::exit(1);
	};
	{
		let meta = metadata(config_file).await?;
		if (!0o100600 & meta.permissions().mode()) > 0 {
			eprintln!("Error: other users can read or write config file {:?}\n\
				File permissions: {:o}",
				config_file, meta.permissions().mode());
			std::process::exit(1);
		}
	}
	let settings: config::Config = config::Config::builder()
		.set_default("fields", vec!["date", "from", "subject"]).unwrap()
		.set_default("hostname", "smtp.2.tg").unwrap()
		.set_default("listen_on", "0.0.0.0:1025").unwrap()
		.set_default("unknown", "relay").unwrap()
		.add_source(config::File::from(config_file))
		.build()