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§

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

Encodingfalsetrue
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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.