Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make gethostname an optional feature #25

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ categories = ["email"]
readme = "README.md"

[features]
default = []
default = ["gethostname"]
gethostname = ["dep:gethostname"]
ludicrous_mode = []

[dependencies]
gethostname = "0.4.0"
gethostname = { version = "0.4.0", optional = true }

[dev-dependencies]
mail-parser = "0.9"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _mail-builder_ is a flexible **e-mail builder library** written in Rust. It incl
- Full **MIME** support (_RFC 2045 - 2049_) with automatic selection of the most optimal encoding for each message body part.
- **Fast Base64 encoding** based on Chromium's decoder ([the fastest non-SIMD encoder](https://github.com/lemire/fastbase64)).
- Minimal dependencies.
- The dependency on `gethostname` is optional.

Please note that this library does not support sending or parsing e-mail messages as these functionalities are provided by the crates [`mail-send`](https://crates.io/crates/mail-send) and [`mail-parser`](https://crates.io/crates/mail-parser).

Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,16 @@ impl<'x> MessageBuilder<'x> {

if !has_message_id {
output.write_all(b"Message-ID: ")?;

#[cfg(feature = "gethostname")]
generate_message_id_header(
&mut output,
gethostname::gethostname().to_str().unwrap_or("localhost"),
)?;

#[cfg(not(feature = "gethostname"))]
generate_message_id_header(&mut output, "localhost")?;

output.write_all(b"\r\n")?;
}

Expand Down
6 changes: 6 additions & 0 deletions src/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ thread_local!(static COUNTER: Cell<u64> = Cell::new(0));

pub fn make_boundary(separator: &str) -> String {
let mut s = DefaultHasher::new();

#[cfg(feature = "gethostname")]
gethostname::gethostname().hash(&mut s);

#[cfg(not(feature = "gethostname"))]
"localhost".hash(&mut s);

thread::current().id().hash(&mut s);
let hash = s.finish();

Expand Down
Loading