Don't run headers that don't need encoding though the encoder (#739)

This commit is contained in:
Paolo Barbolini
2022-02-17 20:18:54 +01:00
committed by GitHub
parent 1ea4987023
commit 96b42515cd
3 changed files with 9 additions and 7 deletions

View File

@@ -36,7 +36,8 @@ impl Header for ContentTransferEncoding {
}
fn display(&self) -> HeaderValue {
HeaderValue::new(Self::name(), self.to_string())
let val = self.to_string();
HeaderValue::dangerous_new_pre_encoded(Self::name(), val.clone(), val)
}
}

View File

@@ -44,17 +44,17 @@ impl Header for Date {
}
fn display(&self) -> HeaderValue {
let mut s = self.0.to_string();
if s.ends_with(" GMT") {
let mut val = self.0.to_string();
if val.ends_with(" GMT") {
// The httpdate crate always appends ` GMT` to the end of the string,
// but this is considered an obsolete date format for email
// https://tools.ietf.org/html/rfc2822#appendix-A.6.2,
// so we replace `GMT` with `-0000`
s.truncate(s.len() - "GMT".len());
s.push_str("-0000");
val.truncate(val.len() - "GMT".len());
val.push_str("-0000");
}
HeaderValue::new(Self::name(), s)
HeaderValue::dangerous_new_pre_encoded(Self::name(), val.clone(), val)
}
}

View File

@@ -51,7 +51,8 @@ impl Header for MimeVersion {
}
fn display(&self) -> HeaderValue {
HeaderValue::new(Self::name(), format!("{}.{}", self.major, self.minor))
let val = format!("{}.{}", self.major, self.minor);
HeaderValue::dangerous_new_pre_encoded(Self::name(), val.clone(), val)
}
}