mail_send_fork/smtp/
mod.rs

1/*
2 * Copyright Stalwart Labs Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
7 * option. This file may not be copied, modified, or distributed
8 * except according to those terms.
9 */
10
11use smtp_proto::{Response, Severity};
12
13pub mod auth;
14pub mod builder;
15pub mod client;
16pub mod ehlo;
17pub mod envelope;
18pub mod message;
19pub mod tls;
20
21impl From<auth::Error> for crate::Error {
22    fn from(err: auth::Error) -> Self {
23        crate::Error::Auth(err)
24    }
25}
26
27pub trait AssertReply: Sized {
28    fn is_positive_completion(&self) -> bool;
29    fn assert_positive_completion(self) -> crate::Result<()>;
30    fn assert_severity(self, severity: Severity) -> crate::Result<()>;
31    fn assert_code(self, code: u16) -> crate::Result<()>;
32}
33
34impl AssertReply for Response<String> {
35    /// Returns `true` if the reply is a positive completion.
36    #[inline(always)]
37    fn is_positive_completion(&self) -> bool {
38        (200..=299).contains(&self.code)
39    }
40
41    /// Returns Ok if the reply has the specified severity.
42    #[inline(always)]
43    fn assert_severity(self, severity: Severity) -> crate::Result<()> {
44        if self.severity() == severity {
45            Ok(())
46        } else {
47            Err(crate::Error::UnexpectedReply(self))
48        }
49    }
50
51    /// Returns Ok if the reply returned a 2xx code.
52    #[inline(always)]
53    fn assert_positive_completion(self) -> crate::Result<()> {
54        if (200..=299).contains(&self.code) {
55            Ok(())
56        } else {
57            Err(crate::Error::UnexpectedReply(self))
58        }
59    }
60
61    /// Returns Ok if the reply has the specified status code.
62    #[inline(always)]
63    fn assert_code(self, code: u16) -> crate::Result<()> {
64        if self.code() == code {
65            Ok(())
66        } else {
67            Err(crate::Error::UnexpectedReply(self))
68        }
69    }
70}