Overview
| Comment: | reorganize to lib + bin to separate tests, add logging, fix some small stuff |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
3c858ed7c4bad10014f3480fccef1320 |
| User & Date: | arcade on 2026-07-31 10:42:58.113 |
| Other Links: | manifest | tags |
Context
|
2026-07-31
| ||
| 10:43 | add some tests check-in: dd307557e6 user: arcade tags: trunk | |
| 10:42 | reorganize to lib + bin to separate tests, add logging, fix some small stuff check-in: 3c858ed7c4 user: arcade tags: trunk | |
| 10:38 | add deny.toml for checks check-in: f88aa03bf5 user: arcade tags: trunk | |
Changes
Added src/lib.rs version [9dab3246bf].
Modified src/mail.rs
from [420cd8d808]
to [d2ab1bd9bb].
| ︙ | ︙ | |||
104 105 106 107 108 109 110 | tg, fields, address, }) } /// Returns id for provided email address | | | | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
tg,
fields,
address,
})
}
/// Returns id for provided email address
fn get_id (&self, name_str: &str) -> Result<&ChatPeerId> {
// here we need to store String locally to borrow it after
let mut link = name_str;
let name: String;
if let Some(caps) = self.address.captures(link) {
name = caps["name"].to_string();
link = &name;
}
match self.tg.get(link) {
Ok(addr) => Ok(addr),
|
| ︙ | ︙ |
Modified src/main.rs
from [422765bb02]
to [150a105673].
1 2 3 4 | //! 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. | < < < < < < < < < < < < < < < < < | < < < < < < < < < | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//! 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 async_compat::Compat;
use stacked_errors:: Result;
// main function stub that executes main code from lib
fn main () -> Result<()> {
smol::block_on(Compat::new(async {
smtp2tg::async_main().await.unwrap()
}));
Ok(())
}
|
Deleted src/tests.rs version [e383e9fd77].
Modified src/utils.rs
from [85ea533bba]
to [8e25f3e7d7].
1 2 3 4 5 6 7 8 9 10 11 12 13 |
use crate::Cursor;
use std::borrow::Cow;
use html_escape::encode_text;
use lazy_static::lazy_static;
use regex::Regex;
use stacked_errors::{
bail,
Result,
};
lazy_static! {
| | | | > > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
use crate::Cursor;
use std::borrow::Cow;
use html_escape::encode_text;
use lazy_static::lazy_static;
use regex::Regex;
use stacked_errors::{
bail,
Result,
};
lazy_static! {
pub static ref RE_DOMAIN: Regex = Regex::new(r"^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$").expect("Invalid domain regex");
pub static ref RE_CLOSING: Regex = Regex::new(r"</[ \t]*(pre|code)[ \t]*>").expect("Invalid cloding tag regex");
}
/// Stores binary attachment data and metadata for Telegram messages.
/// The data is wrapped in a `Cursor<Vec<u8>>` for efficient streaming,
/// while `name` holds the filename or display name of the attachment.
#[derive(Debug)]
pub struct Attachment {
pub data: Cursor<Vec<u8>>,
pub name: String,
}
/// Pass any text here to be validated as not breaking from Telegram preformatted blocks
/// escape all HTML chars afterwards
pub fn validate <'a>(text: &'a str) -> Result<Cow<'a, str>> {
if RE_CLOSING.is_match(text) {
bail!("Telegram closing tag found.");
} else {
Ok(encode_text(text))
}
}
|