1
2
3
4
5
6
7
|
use crate::{
Cursor,
telegram::TelegramTransport,
utils::{
Attachment,
RE_DOMAIN,
validate,
|
>
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
|
//! SMTP server implementation for receiving and processing emails.
//!
//! This module handles SMTP connections, email parsing, and forwarding to
//! Telegram.
use crate::{
Cursor,
telegram::TelegramTransport,
utils::{
Attachment,
RE_DOMAIN,
validate,
|
| ︙ | | | ︙ | |
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
relay: bool,
tg: Arc<TelegramTransport>,
fields: HashSet<String>,
address: Regex,
}
impl MailServer {
/// Initialize API and read configuration
pub fn new(settings: config::Config) -> Result<MailServer> {
let api_key = settings.get_string("api_key")
.context("[smtp2tg.toml] missing \"api_key\" parameter.\n")?;
let mut recipients = HashMap::new();
for (name, value) in settings.get_table("recipients")
.expect("[smtp2tg.toml] missing table \"recipients\".\n")
{
|
>
>
>
>
>
>
|
>
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
relay: bool,
tg: Arc<TelegramTransport>,
fields: HashSet<String>,
address: Regex,
}
impl MailServer {
/// Main asynchronous entry point for the application.
///
/// Parses command-line arguments, loads configuration, and starts the SMTP
/// server.
///
/// # Errors
/// Returns an error if configuration is invalid, files are inaccessible, or
/// server fails to start.
pub fn new(settings: config::Config) -> Result<MailServer> {
let api_key = settings.get_string("api_key")
.context("[smtp2tg.toml] missing \"api_key\" parameter.\n")?;
let mut recipients = HashMap::new();
for (name, value) in settings.get_table("recipients")
.expect("[smtp2tg.toml] missing table \"recipients\".\n")
{
|
| ︙ | | | ︙ | |
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
relay,
tg,
fields,
address,
})
}
/// Returns id for provided email address
pub fn get_id (&self, name: &str) -> Result<&ChatPeerId> {
if self.address.is_match(name) {
match self.tg.get(name) {
Ok(addr) => Ok(addr),
Err(_) => Ok(&self.tg.default),
}
} else {
|
>
>
>
>
>
>
|
>
>
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
relay,
tg,
fields,
address,
})
}
/// Retrieves the Telegram chat ID for a given email address, checks that
/// used domain is allowed.
///
/// # Arguments
/// * `name_str` - Email address or username to look up.
///
/// # Returns
/// * `Result<ChatPeerId>` - Telegram chat ID for the address, or default if
/// not found.
pub fn get_id (&self, name: &str) -> Result<&ChatPeerId> {
if self.address.is_match(name) {
match self.tg.get(name) {
Ok(addr) => Ok(addr),
Err(_) => Ok(&self.tg.default),
}
} else {
|
| ︙ | | | ︙ | |
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
} else {
bail!("Required headers were not found.");
}
Ok(())
}
}
impl mailin_embedded::Handler for MailServer {
/// Just deny login auth
fn auth_login (&mut self, _username: &str, _password: &str) -> Response {
INVALID_CREDENTIALS
}
/// Just deny plain auth
|
>
|
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
} else {
bail!("Required headers were not found.");
}
Ok(())
}
}
/// SMTP handler implementation for mailin-embedded.
impl mailin_embedded::Handler for MailServer {
/// Just deny login auth
fn auth_login (&mut self, _username: &str, _password: &str) -> Response {
INVALID_CREDENTIALS
}
/// Just deny plain auth
|
| ︙ | | | ︙ | |