Diff
Logged in as anonymous

Differences From Artifact [a66af013e1]:

To Artifact [44d6752f1f]:


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

use std::{
	os::unix::fs::PermissionsExt,
	path::Path,
};

use clap::Parser;
use smol::{
	fs::metadata,
};
use stacked_errors::{
	Result,
	StackableErr,
	bail,
};

use smtp2tg::mail::MailServer;







|
<
<







9
10
11
12
13
14
15
16


17
18
19
20
21
22
23

use std::{
	os::unix::fs::PermissionsExt,
	path::Path,
};

use clap::Parser;
use smol::fs::metadata;


use stacked_errors::{
	Result,
	StackableErr,
	bail,
};

use smtp2tg::mail::MailServer;
︙︙
47
48
49
50
51
52
53


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
/// Also returns an error if the system hostname cannot be read or is not
/// valid UTF-8, or if mail server initialisation fails.
///
/// # Panics
/// Panics if configuring or serving the SMTP server fails.
	async fn main (ex: &LocalExecutor<'_>) -> Result<()> {
		let args = Args::parse();


		let config_file = Path::new(&args.config);
		if !config_file.try_exists().stack()? {
			bail!("Configuration file not found: {config_file:?}\n\
				Hint: Ensure the file exists and the path is correct.");
		};
		{
			let meta = metadata(config_file).await.stack()?;
			if (!0o100600 & meta.permissions().mode()) > 0 {
				bail!("Configuration file permissions are insecure {config_file:?}\n\
					Current permissions: {:o}\n\
					Required: 0600 (owner read/write only).\n\
					Fix with: chmod 600 {config_file:?}",
					meta.permissions().mode());
		}	}
		let settings: config::Config = config::Config::builder()
			.set_default("api_gateway", "https://api.telegram.org").stack()?
			.set_default("fields", vec!["date", "from", "subject"]).stack()?
			.set_default("hostname", "smtp.2.tg").stack()?
			.set_default("listen_on", "0.0.0.0:1025").stack()?
			.set_default("domains", vec!["localhost",
				hostname::get().context("Failed to get current hostname")?
				.to_str().context("Can't convert hostname to string, bad UTF-8?")?]).stack()?
			.add_source(config::File::from(config_file))
			.build()
			.with_context(|| format!(
				"Failed to parse configuration file: {config_file:?}\n\
				Check syntax against smtp2tg.toml.example.\n\
				Common issues: missing quotes, trailing commas in inline tables, or invalid types."
			))?;


		let listen_on = settings.get_string("listen_on").stack()?;
		let server_name = settings.get_string("hostname").stack()?;
		let core = MailServer::new(settings)?;
		let mut server = mailin_embedded::Server::new(core);

		// TODO: remove unwraps when mailin-embedded bumps with better error handling







>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/// Also returns an error if the system hostname cannot be read or is not
/// valid UTF-8, or if mail server initialisation fails.
///
/// # Panics
/// Panics if configuring or serving the SMTP server fails.
	async fn main (ex: &LocalExecutor<'_>) -> Result<()> {
		let args = Args::parse();
		let settings = {
			// Load configuration defaults and overrides after checking file permissions.
			let config_file = Path::new(&args.config);
			if !config_file.try_exists().stack()? {
				bail!("Configuration file not found: {config_file:?}\n\
					Hint: Ensure the file exists and the path is correct.");
			};
			{
				let meta = metadata(config_file).await.stack()?;
				if (!0o100600 & meta.permissions().mode()) > 0 {
					bail!("Configuration file permissions are insecure {config_file:?}\n\
						Current permissions: {:o}\n\
						Required: 0600 (owner read/write only).\n\
						Fix with: chmod 600 {config_file:?}",
						meta.permissions().mode());
			}	}
			config::Config::builder()
				.set_default("api_gateway", "https://api.telegram.org").stack()?
				.set_default("fields", vec!["date", "from", "subject"]).stack()?
				.set_default("hostname", "smtp.2.tg").stack()?
				.set_default("listen_on", "0.0.0.0:1025").stack()?
				.set_default("domains", vec!["localhost",
					hostname::get().context("Failed to get current hostname")?
					.to_str().context("Can't convert hostname to string, bad UTF-8?")?]).stack()?
				.add_source(config::File::from(config_file))
				.build()
				.with_context(|| format!(
					"Failed to parse configuration file: {config_file:?}\n\
					Check syntax against smtp2tg.toml.example.\n\
					Common issues: missing quotes, trailing commas in inline tables, or invalid types."
				))?
		};

		let listen_on = settings.get_string("listen_on").stack()?;
		let server_name = settings.get_string("hostname").stack()?;
		let core = MailServer::new(settings)?;
		let mut server = mailin_embedded::Server::new(core);

		// TODO: remove unwraps when mailin-embedded bumps with better error handling
︙︙