Enum email_encoding::body::Encoding
source · [−]pub enum Encoding {
SevenBit,
EightBit,
QuotedPrintable,
Base64,
}
Expand description
A possible email Content-Transfer-Encoding
Variants
SevenBit
7bit (US-ASCII)
EightBit
8bit (UTF-8)
QuotedPrintable
Base64
Implementations
sourceimpl 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);
}
Trait Implementations
impl Copy for Encoding
impl Eq for Encoding
impl StructuralEq for Encoding
impl StructuralPartialEq for Encoding
Auto Trait Implementations
impl RefUnwindSafe for Encoding
impl Send for Encoding
impl Sync for Encoding
impl Unpin for Encoding
impl UnwindSafe for Encoding
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more