netpkt/pop3.rs#
Source: lib/netpkt/pop3.rs
pop3 -- the Post Office Protocol version 3 (RFC 1939) with its optional commands UIDL, TOP
and USER / PASS, and CAPA of RFC 2449: command lines, the status line +OK / -ERR, multi-line
responses with their dot-stuffing
Command { verb, args } Command::parse(line) (the verb in capitals), Command::new(verb,
args), to_line() ("RETR 1\r\n"; CR, LF and NUL of the fields left
out)
Response { ok, text, body } Response::ok(text) / err(text), with_body(bytes) (a multi-
line response: the lines of the bytes follow the status line,
each with a leading dot doubled, then the line with the dot);
to_bytes()
multi_line(&Command) a +OK to it carries a body: LIST and UIDL without an argument,
RETR, TOP, CAPA
Reader the responses of a server from its bytes in any pieces; the
client says for each command it sent whether a body may follow
(expect(multi)); Reader::new() waits for the greeting first
PORT_POP3 (110), verb_known
A body travels with CRLF line ends; Response::body holds it with the dots undone and CRLF
after every line (the message as the server stored it). The text after +OK and -ERR is the
server's own words; RFC 2449's codes in brackets ("-ERR [AUTH] ...") stay part of it.
PORT_POP3: u16 = 110
fn verb_known(v: &str) -> boolthe commands of RFC 1939 and 2449 (and those of later RFCs a dissector names)struct Commanda command line of a clientverb: String-- in capitalsargs: Vec<String>-- the words after it (PASS keeps the rest of the line as one argument: a password may hold spaces)
impl Command
fn new(verb: &str, args: &[&str]) -> Commandfn parse(line: &str) -> Option<Command>a line without its line end; None for an empty onefn to_line(&self) -> Stringthe line on the wire, CRLF included; CR, LF and NUL of verb and arguments are left out (they would end the line and start another command)fn num(&self, k: usize) -> Option<u32>argument k as a number (a message number)fn multi_line(c: &Command) -> boola +OK to this command is followed by lines and the line with the dot (RFC 1939 3)struct Responsea response of a serverok: bool-- +OK (else -ERR)text: String-- the text after the status indicatorbody: Option<Vec<u8>>-- the lines of a multi-line response, CRLF after each, dots undone
impl Response
fn ok(text: &str) -> Responsefn err(text: &str) -> Responsefn with_body(mut self, body: &[u8]) -> Responsethe same response with lines after itfn status_line(&self) -> Stringthe status line ("+OK text") without the line endfn to_bytes(&self) -> Vec<u8>the bytes on the wire: the status line, the body lines with dot-stuffing and ".\r\n"fn stuffed(body: &[u8]) -> Vec<u8>a body as it travels: CRLF line ends, a line that starts with a dot gets another one, then ".\r\n"struct Readerthe responses of a server, as its bytes arrive
impl Reader
fn new() -> Readera reader that waits for the greeting first (a single line)fn expect(&mut self, multi: bool)the next response (after the greeting, which is single-line) answers a command whose +OK carries a body whenmultifn push(&mut self, b: &[u8]) -> Vec<Response>bytes of the server: the responses complete now