Index: Cargo.lock ================================================================== --- Cargo.lock +++ Cargo.lock @@ -1783,11 +1783,11 @@ "futures-lite", ] [[package]] name = "smtp2tg" -version = "0.6.7" +version = "0.6.8" dependencies = [ "async-compat", "clap", "config", "hostname", Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -17,14 +17,10 @@ regex = "1.11.1" smol = "2.0.2" stacked_errors = "0.8" tgbot = "0.48" -[profile.release] -lto = true -codegen-units = 1 - # All tests are moved to tests/ [lib] test = false [[bin]] Index: src/mail.rs ================================================================== --- src/mail.rs +++ src/mail.rs @@ -57,11 +57,10 @@ data: Vec, headers: Option, tg: Arc, fields: HashSet, address: Regex, - domains: HashSet, } impl MailServer { /// Initializes the mail server: sets up the Telegram API client and /// validates all required configuration values. @@ -112,11 +111,10 @@ data: vec!(), headers: None, tg, fields, address, - domains, }) } /// Retrieves the Telegram chat ID for a given email address, checks that /// used domain is allowed. Index: src/telegram.rs ================================================================== --- src/telegram.rs +++ src/telegram.rs @@ -16,21 +16,11 @@ StackableErr, }; use tgbot::{ api::Client, types::{ - ChatPeerId, - InputFile, - InputFileReader, - InputMediaDocument, - MediaGroup, - MediaGroupItem, - Message, - ParseMode::Html, - SendMediaGroup, - SendMessage, - SendDocument, + ChatPeerId, InputFile, InputFileReader, InputMediaDocument, InputText, MediaGroup, MediaGroupItem, Message, ParseMode::Html, SendDocument, SendMediaGroup, SendMessage }, }; #[derive(Debug)] pub struct TelegramTransport { @@ -79,11 +69,11 @@ /// * `Result` - Telegram API response. /// /// # Errors /// Returns an error if `msg` contains a closing Telegram tag or sending fails. pub async fn debug (&self, msg: &str) -> Result { - self.send(&self.default, format!("
{}
", validate(msg).stack()?)).await + self.send(&self.default, &format!("
{}
", validate(msg).stack()?)).await } /// Retrieves a chat ID by name. /// /// # Arguments @@ -105,15 +95,13 @@ /// * `to` - Target chat ID. /// * `msg` - Message text (supports HTML formatting). /// /// # Returns /// * `Result` - Telegram API response. - pub async fn send (&self, to: &ChatPeerId, msg: S) -> Result - where S: Into + Debug{ + pub async fn send (&self, to: &ChatPeerId, msg: &str) -> Result { self.tg.execute( - SendMessage::new(*to, msg) - .with_parse_mode(Html) + SendMessage::new(*to, InputText::from(msg).with_format(Html)) ).await.stack() } /// Sends a message with attachments to a specified chat. /// @@ -127,25 +115,22 @@ pub async fn sendgroup (&self, to: &ChatPeerId, media: Vec, msg: &str) -> Result<()> { if media.len() > 1 { let mut attach = vec![]; let mut pos = media.len(); for file in media { - let mut caption = InputMediaDocument::default(); + let mut doc = InputMediaDocument::from( + InputFile::from( + InputFileReader::from(file.data) + .with_file_name(file.name) + ) + ); if pos == 1 { - caption = caption.with_caption(msg) - .with_caption_parse_mode(Html); + doc = doc.with_caption(InputText::from(msg) + .with_format(Html)); } pos -= 1; - attach.push( - MediaGroupItem::for_document( - InputFile::from( - InputFileReader::from(file.data) - .with_file_name(file.name) - ), - caption - ) - ); + attach.push(MediaGroupItem::from(doc)); } self.tg.execute(SendMediaGroup::new(*to, MediaGroup::new(attach).stack()?)).await.stack()?; } else { if media.is_empty() { bail!("At least one attachment is required."); @@ -152,13 +137,13 @@ } self.tg.execute( SendDocument::new( *to, InputFileReader::from(media[0].data.clone()) - .with_file_name(media[0].name.clone()) - ).with_caption(msg) - .with_caption_parse_mode(Html) + .with_file_name(media[0].name.clone()) + ).with_caption(InputText::from(msg) + .with_format(Html)) ).await.stack()?; } Ok(()) } }