Module imap_codec::encode
source · Expand description
Encoding of messages.
To facilitates handling of literals, Encoder::encode returns an instance of Encoded
.
The idea is that the encoder not only “dumps” the final serialization of a message but can be iterated over.
Example
use imap_codec::{
encode::{Encoder, Fragment},
imap_types::{
command::{Command, CommandBody},
core::LiteralMode,
},
CommandCodec,
};
let command = Command::new("A1", CommandBody::login("Alice", "Pa²²W0rD").unwrap()).unwrap();
for fragment in CommandCodec::default().encode(&command) {
match fragment {
Fragment::Line { data } => {
// A line that is ready to be send.
println!("C: {}", String::from_utf8(data).unwrap());
}
Fragment::Literal { data, mode } => match mode {
LiteralMode::Sync => {
// Wait for a continuation request.
println!("S: + ...")
}
LiteralMode::NonSync => {
// We don't need to wait for a continuation request
// as the server will also not send it.
}
},
}
}
Output of example:
C: A1 LOGIN alice {10}
S: + ...
C: Pa²²W0rD
Structs
- An encoded message.
Enums
- The intended action of a client or server.
Traits
- Encoder.