mail_builder/headers/
raw.rs1use std::borrow::Cow;
13
14use super::Header;
15
16#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
19pub struct Raw<'x> {
20 pub raw: Cow<'x, str>,
21}
22
23impl<'x> Raw<'x> {
24 pub fn new(raw: impl Into<Cow<'x, str>>) -> Self {
26 Self {
27 raw: raw.into(),
28 }
29 }
30}
31
32impl<'x, T> From<T> for Raw<'x>
33where
34 T: Into<Cow<'x, str>>,
35{
36 fn from(value: T) -> Self {
37 Self::new(value)
38 }
39}
40
41impl<'x> Header for Raw<'x> {
42 fn write_header(&self, mut output: impl std::io::Write, mut bytes_written: usize) -> std::io::Result<usize> {
43 for (pos, &ch) in self.raw.as_bytes().iter().enumerate() {
44 if bytes_written >= 76 && ch.is_ascii_whitespace() && pos < self.raw.len() - 1 {
45 output.write_all(b"\r\n\t")?;
46 bytes_written = 1;
47 }
48 output.write_all(&[ch])?;
49 bytes_written += 1;
50 }
51 output.write_all(b"\r\n")?;
52 Ok(0)
53 }
54}