mail_headers/header_components/
cfws.rs

1use internals::error::EncodingError;
2use internals::encoder::{EncodableInHeader, EncodingWriter};
3
4//FEATURE_TODO(fws_controll): allow controlling the amount of WS and if a CRLF should be used in FWS
5//  this is also usefull for parsing and keeping information about FWS structure
6//FEATURE_TODO(cfws_with_comments): allow encoding commnets in CFWS
7//  this allows encoding comments in CFWS, combine with (part of?) fws_controll
8//  required (partially) for parsing comments (through skipping them works without this)
9
10//
11//pub enum WS {
12//    TAB,
13//    SPACE
14//}
15//
16//pub struct FWS(pub Option<WithCRLF>, pub Vec1<WS> );
17//
18//pub struct WithCRLF {
19//    pub trailing: Vec<WS>
20//}
21
22#[derive(Debug, Hash, Clone, Eq, PartialEq)]
23pub struct FWS;
24
25//NOTE(IMPORTANT): when implementing this I have to assure that encoding CFWS followed by FWS works
26// mainly after using a CR-LF-WSP seq you CAN NOT have another FWS which uses unsolds to a CR-LF-WSP
27// currently we only remember the last FWS and do only make it in a CR-LF-SPACE sequence when we
28// need to, so no problem here for now.
29#[derive(Debug, Clone, Hash, Eq, PartialEq)]
30pub enum CFWS {
31    //WithComment( Vec1<(Option<FWS>, Comment)>, Option<FWS> ),
32    SingleFws( FWS )
33}
34
35
36impl EncodableInHeader for CFWS {
37    fn encode(&self, handle: &mut EncodingWriter) -> Result<(), EncodingError> {
38        match *self {
39            CFWS::SingleFws(ref _fws ) => {
40                handle.write_fws();
41            }
42        }
43        Ok( () )
44    }
45
46    fn boxed_clone(&self) -> Box<EncodableInHeader> {
47        Box::new(self.clone())
48    }
49}
50
51#[cfg(test)]
52mod test {
53    use super::*;
54
55    ec_test!{ simple_encode,
56        {
57            CFWS::SingleFws( FWS )
58        } => utf8 => [
59            MarkFWS,
60            Text " "
61        ]
62    }
63
64}