Expand description
A POP3 protocol parser. Given bytes and a sawp::parser::Direction
, it will
attempt to parse the bytes and return a Message
. The parser will
inform the caller about what went wrong if no message is returned (see sawp::parser::Parse
for details on possible return types).
The following protocol references were used to create this module:
RFC 1939 - Post Office Protocol Version 3 RFC 2449 - POP3 Extension Mechanism
§Example
use sawp::parser::{Direction, Parse};
use sawp::error::Error;
use sawp_flags::Flag;
use sawp_pop3::{POP3, Message, InnerMessage, ErrorFlag};
fn parse_bytes(input: &[u8]) -> std::result::Result<&[u8], Error> {
let pop3 = POP3 {};
let mut bytes = input;
while bytes.len() > 0 {
match pop3.parse(bytes, Direction::Unknown) {
// The parser succeeded and returned the remaining bytes and the parsed POP3 message
Ok((rest, Some(message))) => {
bytes = rest;
// Message violates POP3 standard in some way
if message.error_flags != ErrorFlag::none() {
println!("Error flags: {:?}", message.error_flags);
}
match message.inner {
// Command sent by client
InnerMessage::Command(_) => println!("POP3 Command {:?}", message.inner),
// Response sent by server
InnerMessage::Response(_) => println!("POP3 Response {:?}", message.inner),
}
}
// This should never occur with POP3 but is included for consistency with other parsers
Ok((_rest, None)) => {}
// The parser determined that this was not POP3
Err(e) => return Err(e),
}
}
Ok(bytes)
}
Structs§
- Command
- Flags
- Re-export of the
Flags
struct that is used to represent bit flags in this crate. Storage type for handling flags - Message
- POP3
- Response
Enums§
- Error
Flag - Parser-identified errors that are not fatal
- Inner
Message - Keyword
- The supported POP3 client commands
- Status
- POP3 servers can respond with either an OK or Error response based on client input
Constants§
Traits§
- Flag
- Re-export of the
Flags
struct that is used to represent bit flags in this crate. A trait implemented by all flag enums.