Enum email_encoding::body::Encoding
source · pub enum Encoding {
SevenBit,
EightBit,
QuotedPrintable,
Base64,
}
Expand description
A possible email Content-Transfer-Encoding
Variants§
Implementations§
source§impl Encoding
impl Encoding
sourcepub fn choose<'a>(input: impl Into<StrOrBytes<'a>>, supports_utf8: bool) -> Self
pub fn choose<'a>(input: impl Into<StrOrBytes<'a>>, supports_utf8: bool) -> Self
Choose the most efficient Encoding
for input
Look into input
and decide what encoding format could best
be used to represent it.
If the SMTP server supports the SMTPUTF8
extension
supports_utf8
may me set to true
, otherwise false
is the safest option.
Possible return values based on supports_utf8
Encoding | false | true |
---|---|---|
7bit | ✅ | ✅ |
8bit | ❌ | ✅ |
quoted-printable | ✅ | ✅ |
base64 | ✅ | ✅ |
Examples
// Ascii
{
let input = "Hello, World!";
assert_eq!(Encoding::choose(input, false), Encoding::SevenBit);
assert_eq!(Encoding::choose(input, true), Encoding::SevenBit);
}
// Mostly ascii + utf-8
{
let input = "Hello, World! 📬";
assert_eq!(Encoding::choose(input, false), Encoding::QuotedPrintable);
assert_eq!(Encoding::choose(input, true), Encoding::EightBit);
}
// Mostly utf-8
{
let input = "Hello! 📬📬📬📬📬📬📬📬📬📬";
assert_eq!(Encoding::choose(input, false), Encoding::Base64);
assert_eq!(Encoding::choose(input, true), Encoding::EightBit);
}
// Non utf-8 bytes
{
let input = &[255, 35, 123, 190];
assert_eq!(Encoding::choose(input, false), Encoding::Base64);
assert_eq!(Encoding::choose(input, true), Encoding::Base64);
}