Skip to main content

mailrs_smtp_proto/
command.rs

1//! Typed SMTP command representation.
2
3/// SASL authentication mechanism advertised by the client.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum AuthMechanism {
6    /// `AUTH PLAIN` — RFC 4616.
7    Plain,
8    /// `AUTH LOGIN` — non-standard but widely supported.
9    Login,
10}
11
12/// A parsed SMTP command, borrowed from the input line.
13///
14/// Lifetimes match the input slice given to [`parse_command`], so commands
15/// must be consumed before the input buffer is reused.
16///
17/// [`parse_command`]: crate::parse_command
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum Command<'a> {
20    /// `EHLO <domain>` — start an ESMTP session.
21    Ehlo(&'a str),
22    /// `HELO <domain>` — start a legacy SMTP session.
23    Helo(&'a str),
24    /// `MAIL FROM:<reverse-path> [params]` — open a mail transaction.
25    MailFrom {
26        /// Reverse path (envelope sender).
27        path: ReversePath<'a>,
28        /// ESMTP parameters (SIZE, AUTH, BODY, etc).
29        params: Vec<Param<'a>>,
30    },
31    /// `RCPT TO:<forward-path> [params]` — add a recipient.
32    RcptTo {
33        /// Forward path (envelope recipient).
34        path: ForwardPath<'a>,
35        /// ESMTP parameters (NOTIFY, ORCPT, etc).
36        params: Vec<Param<'a>>,
37    },
38    /// `DATA` — begin message body input.
39    Data,
40    /// `RSET` — reset the mail transaction.
41    Rset,
42    /// `QUIT` — close the connection.
43    Quit,
44    /// `NOOP [string]` — no-op.
45    Noop(Option<&'a str>),
46    /// `VRFY <user>` — verify a user.
47    Vrfy(&'a str),
48    /// `HELP [topic]` — request help.
49    Help(Option<&'a str>),
50    /// `STARTTLS` — upgrade the connection to TLS (RFC 3207).
51    StartTls,
52    /// `AUTH <mechanism> [initial-response]` — start SASL authentication.
53    Auth {
54        /// SASL mechanism the client wants to use.
55        mechanism: AuthMechanism,
56        /// Optional initial client response (base64-encoded SASL payload).
57        initial_response: Option<&'a str>,
58    },
59    /// Continuation line during an in-progress AUTH challenge.
60    AuthResponse(&'a str),
61}
62
63/// Reverse path (the `MAIL FROM:<...>` envelope sender).
64#[derive(Debug, Clone, PartialEq, Eq)]
65pub enum ReversePath<'a> {
66    /// Empty reverse path (`<>`) — null sender, used for bounces.
67    Null,
68    /// Concrete sender address.
69    Path(&'a str),
70}
71
72/// Forward path (the `RCPT TO:<...>` envelope recipient).
73#[derive(Debug, Clone, PartialEq, Eq)]
74pub enum ForwardPath<'a> {
75    /// Special `<Postmaster>` recipient required by RFC 5321 § 4.1.1.3.
76    Postmaster,
77    /// Concrete recipient address.
78    Path(&'a str),
79}
80
81/// A `key=value` (or bare `key`) ESMTP parameter, e.g. `SIZE=12345` or
82/// `BODY=8BITMIME`.
83#[derive(Debug, Clone, PartialEq, Eq)]
84pub struct Param<'a> {
85    /// Parameter name (uppercase by convention, but match case-insensitively).
86    pub key: &'a str,
87    /// Parameter value, or empty string for bare parameters.
88    pub value: &'a str,
89}