Diff
Logged in as anonymous

Differences From Artifact [44d6752f1f]:

To Artifact [fcb6cd99e3]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! 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 smol_macros::{
	LocalExecutor,
	main,
};

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

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




<
<
<
<
<







1
2
3
4





5
6
7
8
9
10
11
//! 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 std::{
	os::unix::fs::PermissionsExt,
	path::Path,
};

use clap::Parser;
use smol::fs::metadata;
︙︙
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
#[command(about = format!("SMTP-to-Telegram gateway v{}, (C) 2024 - 2026", env!("CARGO_PKG_VERSION")), long_about = None)]
struct Args {
	/// Set configuration file location
	#[arg(short, long, default_value = "smtp2tg.toml")]
	config: String,
}

main! {
/// Main asynchronous entry point for the application. Runs the gateway using
/// the configuration selected on the command line.
///
/// The configuration file must use owner-only permissions. Once configured,
/// the SMTP server runs until it stops or encounters an error.
///
/// # Errors
/// Returns an error if the configuration file is missing, inaccessible,
/// insecure, malformed, or contains invalid required settings.
/// 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.");







<














|
>







23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#[command(about = format!("SMTP-to-Telegram gateway v{}, (C) 2024 - 2026", env!("CARGO_PKG_VERSION")), long_about = None)]
struct Args {
	/// Set configuration file location
	#[arg(short, long, default_value = "smtp2tg.toml")]
	config: String,
}


/// Main asynchronous entry point for the application. Runs the gateway using
/// the configuration selected on the command line.
///
/// The configuration file must use owner-only permissions. Once configured,
/// the SMTP server runs until it stops or encounters an error.
///
/// # Errors
/// Returns an error if the configuration file is missing, inaccessible,
/// insecure, malformed, or contains invalid required settings.
/// 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.
fn main () -> Result<()> {
	smol::block_on(async move{
		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.");
︙︙
86
87
88
89
90
91
92
93

94
95
96
97

		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
		server.with_name(server_name)
			.with_ssl(mailin_embedded::SslConfig::None).unwrap()
			.with_addr(listen_on).unwrap();

		server.serve().unwrap();

		Ok(())
}	}








|
>



|
>
81
82
83
84
85
86
87
88
89
90
91
92
93
94
		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
		server.with_name(server_name)
			.with_ssl(mailin_embedded::SslConfig::None).unwrap()
			.with_addr(listen_on).unwrap()
			.with_num_threads(1);
		server.serve().unwrap();

		Ok(())
	})
}