mail_internals/
mail_type.rs

1/// Specifies what kind of mail we want to create.
2#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
3pub enum MailType {
4    /// A 7-bit us-ascii mail.
5    Ascii,
6
7    /// A us-ascii mail, but the body can contain 8bit values.
8    ///
9    /// This for example allows sending a mail with an utf-8
10    /// formatted body. But be aware that aspects like line
11    /// length limit still count an the ascii bytes for "\r\n"
12    /// still count as newlines. So using this for any non-us-ascii
13    /// compatible encoding (e.g. utf-16) isn't a good idea.
14    /// Neither is it suited for directly containing resources
15    /// like images.
16    Mime8BitEnabled,
17
18    /// A internationalized mail.
19    ///
20    /// Internationalized mails extend multiple grammar parts
21    /// to allow any non us-ascii utf-8 code point additionally
22    /// to the already allowed utf-8 code points. Internationalized
23    /// mails are required for any mail containing a mailbox with
24    /// an non us-ascii local/user part (the part before the `@`).
25    /// They also strongly simplify non ascii utf-8 in all other
26    /// places like e.g. the `Subject` header.
27    Internationalized
28}
29
30impl MailType {
31
32    /// Returns true if the self is equal to `Internationalized`
33    #[inline]
34    pub fn is_internationalized(&self) -> bool {
35        *self == MailType::Internationalized
36    }
37
38    /// Returns true if self is either `Internationalized` or `Mime8BitEnabled`
39    pub fn supports_8bit_bodies( &self ) -> bool {
40        use self::MailType::*;
41        match *self {
42            Ascii => false,
43            Mime8BitEnabled => true,
44            Internationalized => true
45        }
46    }
47}