diff options
Diffstat (limited to 'core/src/mime.rs')
-rw-r--r-- | core/src/mime.rs | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/core/src/mime.rs b/core/src/mime.rs index 7897fe7..dbd11fe 100644 --- a/core/src/mime.rs +++ b/core/src/mime.rs @@ -1,25 +1,15 @@ //! Module containing some utilities for MIME usage/creation. use rand::{self, Rng}; - - // The maximal boundary with wich " boundary=\"...\"" fits into 78 chars line length limit const MULTIPART_BOUNDARY_MAX_LENGTH: usize = 66; // Does not include ' ' to remove special handling for last char. static BOUNDARY_CHARS: &[char] = &[ - '\'', - '(', ')', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', ':', '=', '?', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', - 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', - 'X', 'Y', 'Z', '_', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', + '\'', '(', ')', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', + '=', '?', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', + 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ]; /// Prevent collisions with Base64/Quoted-Printable @@ -56,12 +46,13 @@ static ANTI_COLLISION_CHARS: &str = "=_^"; /// Note that `' '` isn't used for simplicity. /// pub fn create_structured_random_boundary(count: usize) -> String { - let mut out = format!("{anti_collision}{count:x}.", - anti_collision=ANTI_COLLISION_CHARS, - count=count + let mut out = format!( + "{anti_collision}{count:x}.", + anti_collision = ANTI_COLLISION_CHARS, + count = count ); - let rem = MULTIPART_BOUNDARY_MAX_LENGTH-out.len(); + let rem = MULTIPART_BOUNDARY_MAX_LENGTH - out.len(); out.reserve(rem); let mut rng = rand::thread_rng(); @@ -74,7 +65,6 @@ pub fn create_structured_random_boundary(count: usize) -> String { out } - #[cfg(test)] mod test { @@ -107,7 +97,7 @@ mod test { // while it could contain them it's recommended not to do it let out = create_structured_random_boundary(0); - for ch in out[1..out.len()-1].chars() { + for ch in out[1..out.len() - 1].chars() { assert!(ch as u32 >= 32); assert!(ch as u32 <= 126); assert_ne!(ch, '\t'); @@ -115,7 +105,7 @@ mod test { assert_ne!(ch, '"'); } - assert_ne!(out.as_bytes()[out.len()-1], b' '); + assert_ne!(out.as_bytes()[out.len() - 1], b' '); } } -}
\ No newline at end of file +} |