1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq)]
7pub enum Pop3Command {
8 User(String),
10 Pass(String),
12 Stat,
14 List(Option<u32>),
16 Retr(u32),
18 Dele(u32),
20 Noop,
22 Rset,
24 Quit,
26 Top { msg: u32, lines: u32 },
28 Uidl(Option<u32>),
30 Apop { name: String, digest: String },
32 Capa,
34 Stls,
36}
37
38impl fmt::Display for Pop3Command {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 Pop3Command::User(name) => write!(f, "USER {}", name),
42 Pop3Command::Pass(_) => write!(f, "PASS <hidden>"),
43 Pop3Command::Stat => write!(f, "STAT"),
44 Pop3Command::List(Some(msg)) => write!(f, "LIST {}", msg),
45 Pop3Command::List(None) => write!(f, "LIST"),
46 Pop3Command::Retr(msg) => write!(f, "RETR {}", msg),
47 Pop3Command::Dele(msg) => write!(f, "DELE {}", msg),
48 Pop3Command::Noop => write!(f, "NOOP"),
49 Pop3Command::Rset => write!(f, "RSET"),
50 Pop3Command::Quit => write!(f, "QUIT"),
51 Pop3Command::Top { msg, lines } => write!(f, "TOP {} {}", msg, lines),
52 Pop3Command::Uidl(Some(msg)) => write!(f, "UIDL {}", msg),
53 Pop3Command::Uidl(None) => write!(f, "UIDL"),
54 Pop3Command::Apop { name, .. } => write!(f, "APOP {}", name),
55 Pop3Command::Capa => write!(f, "CAPA"),
56 Pop3Command::Stls => write!(f, "STLS"),
57 }
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_command_display_capa() {
67 let cmd = Pop3Command::Capa;
68 assert_eq!(cmd.to_string(), "CAPA");
69 }
70
71 #[test]
72 fn test_command_display_stls() {
73 let cmd = Pop3Command::Stls;
74 assert_eq!(cmd.to_string(), "STLS");
75 }
76
77 #[test]
78 fn test_command_equality() {
79 assert_eq!(Pop3Command::Capa, Pop3Command::Capa);
80 assert_eq!(Pop3Command::Stls, Pop3Command::Stls);
81 assert_ne!(Pop3Command::Capa, Pop3Command::Stls);
82 }
83}