samotop_core/smtp/rfc5321/
unknown.rs1use super::Esmtp;
2use crate::{
3 common::S1Fut,
4 smtp::{command::SmtpUnknownCommand, Action, SmtpContext},
5};
6
7impl Action<SmtpUnknownCommand> for Esmtp {
8 fn apply<'a, 's, 'f>(
9 &'a self,
10 _cmd: SmtpUnknownCommand,
11 state: &'s mut SmtpContext,
12 ) -> S1Fut<'f, ()>
13 where
14 'a: 'f,
15 's: 'f,
16 {
17 Box::pin(async move {
18 state.session.say_not_implemented();
19 })
20 }
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26 use crate::{
27 mail::Recipient,
28 smtp::{command::SmtpMail, DriverControl, SmtpContext, SmtpPath},
29 };
30
31 #[test]
32 fn response_is_not_implemented() {
33 async_std::task::block_on(async move {
34 let mut set = SmtpContext::default();
35 set.session.transaction.id = "someid".to_owned();
36 set.session.transaction.mail = Some(SmtpMail::Mail(SmtpPath::Null, vec![]));
37 set.session.transaction.rcpts.push(Recipient::null());
38 set.session
39 .transaction
40 .extra_headers
41 .insert_str(0, "feeeha");
42
43 Esmtp
44 .apply(SmtpUnknownCommand::new("HOOO".to_owned(), vec![]), &mut set)
45 .await;
46 match set.session.pop_control() {
47 Some(DriverControl::Response(bytes)) if bytes.starts_with(b"502 ") => {}
48 otherwise => panic!("Expected command not implemented, got {:?}", otherwise),
49 }
50 })
51 }
52}