Skip to content

Commit

Permalink
Replace domain placeholder
Browse files Browse the repository at this point in the history
Reply with lib name or custom set env variable
  • Loading branch information
starkbamse committed Sep 8, 2024
1 parent 66ec7b1 commit 9fc7236
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ mod tests {
log::info!("Received mail: {:?}", mail);
listening_server.stop().await.unwrap();
}

}
5 changes: 2 additions & 3 deletions src/parser/ehlo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::str::SplitWhitespace;

use tokio::io;

use crate::{
Expand All @@ -22,7 +21,7 @@ pub fn ehlo(
}
// Return based on the TLS configuration
Ok(match connection.tls_config {
TlsConfig::Encrypted { .. } => EHLO_TLS_AVAILABLE,
_ => EHLO_TLS_UNAVAILABLE,
TlsConfig::Encrypted { .. } => &EHLO_TLS_AVAILABLE,
_ => &EHLO_TLS_UNAVAILABLE,
})
}
3 changes: 1 addition & 2 deletions src/parser/helo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::str::SplitWhitespace;

use tokio::io;

use crate::{
Expand All @@ -21,5 +20,5 @@ pub fn helo(
connection.state = State::Ehlo("".to_string());
}
// We never support TLS on HELO
Ok(EHLO_TLS_UNAVAILABLE)
Ok(&EHLO_TLS_UNAVAILABLE)
}
12 changes: 10 additions & 2 deletions src/parser/responses.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
use std::{env, sync::LazyLock};

// Responses as per RFC 5321
// The following are the responses that the server can send to the client as per RFC 5321:
pub static EHLO_TLS_AVAILABLE: &[u8] = b"250-%DOMAIN%\r\n250 STARTTLS\r\n";
pub static EHLO_TLS_UNAVAILABLE: &[u8] = b"250 %DOMAIN%\r\n";
pub static EHLO_TLS_AVAILABLE:LazyLock<Vec<u8>> = LazyLock::new(|| {
let domain=env::var("MINISMTP_DOMAIN").unwrap_or_else(|_| "minismtp".to_string());
format!("250-{}\r\n250 STARTTLS\r\n",domain).as_bytes().to_vec()
});
pub static EHLO_TLS_UNAVAILABLE:LazyLock<Vec<u8>> = LazyLock::new(|| {
let domain=env::var("MINISMTP_DOMAIN").unwrap_or_else(|_| "minismtp".to_string());
format!("250 {}\r\n",domain).as_bytes().to_vec()
});
pub static OK: &[u8] = b"250 OK\r\n";
pub static READY_FOR_TLS: &[u8] = b"220 Ready to start TLS\r\n";
pub static TLS_NOT_AVAILABLE: &[u8] = b"502 TLS not available\r\n";
Expand Down

0 comments on commit 9fc7236

Please sign in to comment.