Merge pull request #241 from amousset/add-serde-impls

feat(transport): Add serde derive when possible
This commit is contained in:
Alexis Mousset
2018-03-31 17:49:14 +02:00
committed by GitHub
9 changed files with 30 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ pub mod error;
/// Writes the content and the envelope information to a file
#[derive(Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct FileEmailTransport {
path: PathBuf,
}

View File

@@ -11,6 +11,7 @@ pub mod error;
/// Sends an email using the `sendmail` command
#[derive(Debug, Default)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct SendmailTransport {
command: String,
}

View File

@@ -51,6 +51,7 @@ impl<S: Into<String>, T: Into<String>> IntoCredentials for (S, T) {
/// Contains user credentials
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct Credentials {
username: String,
password: String,
@@ -65,6 +66,7 @@ impl Credentials {
/// Represents authentication mechanisms
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum Mechanism {
/// PLAIN authentication mechanism
/// RFC 4616: https://tools.ietf.org/html/rfc4616

View File

@@ -19,6 +19,7 @@ pub mod mock;
/// The codec used for transparency
#[derive(Default, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct ClientCodec {
escape_count: u8,
}

View File

@@ -12,6 +12,7 @@ use std::fmt::{self, Display, Formatter};
/// EHLO command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct EhloCommand {
client_id: ClientId,
}
@@ -32,6 +33,7 @@ impl EhloCommand {
/// STARTTLS command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct StarttlsCommand;
impl Display for StarttlsCommand {
@@ -43,6 +45,7 @@ impl Display for StarttlsCommand {
/// MAIL command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct MailCommand {
sender: Option<EmailAddress>,
parameters: Vec<MailParameter>,
@@ -74,6 +77,7 @@ impl MailCommand {
/// RCPT command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct RcptCommand {
recipient: EmailAddress,
parameters: Vec<RcptParameter>,
@@ -101,6 +105,7 @@ impl RcptCommand {
/// DATA command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct DataCommand;
impl Display for DataCommand {
@@ -112,6 +117,7 @@ impl Display for DataCommand {
/// QUIT command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct QuitCommand;
impl Display for QuitCommand {
@@ -123,6 +129,7 @@ impl Display for QuitCommand {
/// NOOP command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct NoopCommand;
impl Display for NoopCommand {
@@ -134,6 +141,7 @@ impl Display for NoopCommand {
/// HELP command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct HelpCommand {
argument: Option<String>,
}
@@ -157,6 +165,7 @@ impl HelpCommand {
/// VRFY command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct VrfyCommand {
argument: String,
}
@@ -177,6 +186,7 @@ impl VrfyCommand {
/// EXPN command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct ExpnCommand {
argument: String,
}
@@ -197,6 +207,7 @@ impl ExpnCommand {
/// RSET command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct RsetCommand;
impl Display for RsetCommand {
@@ -208,6 +219,7 @@ impl Display for RsetCommand {
/// AUTH command
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct AuthCommand {
mechanism: Mechanism,
credentials: Credentials,

View File

@@ -15,6 +15,7 @@ pub const DEFAULT_EHLO_HOSTNAME: &str = "localhost";
/// Client identifier, the parameter to `EHLO`
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum ClientId {
/// A fully-qualified domain name
Domain(String),
@@ -52,6 +53,7 @@ impl ClientId {
/// Supported ESMTP keywords
#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum Extension {
/// 8BITMIME keyword
///
@@ -82,6 +84,7 @@ impl Display for Extension {
/// Contains information about an SMTP server
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct ServerInfo {
/// Server name
///
@@ -173,6 +176,7 @@ impl ServerInfo {
/// A `MAIL FROM` extension parameter
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum MailParameter {
/// `BODY` parameter
Body(MailBodyParameter),
@@ -209,6 +213,7 @@ impl Display for MailParameter {
/// Values for the `BODY` parameter to `MAIL FROM`
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum MailBodyParameter {
/// `7BIT`
SevenBit,
@@ -227,6 +232,7 @@ impl Display for MailBodyParameter {
/// A `RCPT TO` extension parameter
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum RcptParameter {
/// Custom parameter
Other {

View File

@@ -80,6 +80,7 @@ pub enum ClientSecurity {
/// Configures connection reuse behavior
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum ConnectionReuseParameters {
/// Unlimitied connection reuse
ReuseUnlimited,

View File

@@ -10,6 +10,7 @@ use std::str::{FromStr, from_utf8};
/// First digit indicates severity
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum Severity {
/// 2yx
PositiveCompletion = 2,
@@ -29,6 +30,7 @@ impl Display for Severity {
/// Second digit
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum Category {
/// x0z
Syntax = 0,
@@ -52,6 +54,7 @@ impl Display for Category {
/// The detail digit of a response code (third digit)
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub enum Detail {
#[allow(missing_docs)]
Zero = 0,
@@ -83,6 +86,7 @@ impl Display for Detail {
/// Represents a 3 digit SMTP response code
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct Code {
/// First digit of the response code
pub severity: Severity,
@@ -113,6 +117,7 @@ impl Code {
///
/// The text message is optional, only the code is mandatory
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct Response {
/// Response code
pub code: Code,

View File

@@ -4,6 +4,7 @@ use std::fmt::{Display, Formatter, Result as FmtResult};
/// Encode a string as xtext
#[derive(Debug)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
pub struct XText<'a>(pub &'a str);
impl<'a> Display for XText<'a> {