Skip to main content

io_smtp/rfc5321/types/
parameter.rs

1//! ESMTP parameter (RFC 5321 ยง4.1.2).
2//!
3//! The keyword and optional value pair appended to MAIL FROM and
4//! RCPT TO commands by SMTP extensions.
5
6use core::fmt;
7
8use alloc::borrow::Cow;
9
10use bounded_static_derive::ToStatic;
11
12use crate::rfc5321::SmtpAtom;
13
14/// An ESMTP parameter (keyword[=value]).
15#[derive(Debug, Clone, PartialEq, Eq, Hash, ToStatic)]
16pub struct SmtpParameter<'a> {
17    /// The parameter keyword
18    pub keyword: SmtpAtom<'a>,
19    /// The optional parameter value
20    pub value: Option<Cow<'a, str>>,
21}
22
23impl fmt::Display for SmtpParameter<'_> {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        match &self.value {
26            Some(value) => write!(f, "{}={}", self.keyword, value),
27            None => write!(f, "{}", self.keyword),
28        }
29    }
30}