1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
//! Module containing all custom errors.
use std::{io as std_io};
use new_tokio_smtp::error::{
ConnectingFailed,
LogicError, GeneralError
};
use mail::error::MailError;
use headers::error::HeaderValidationError;
/// Error used when sending a mail fails.
///
/// Failing to encode a mail before sending
/// it also counts as a `MailSendError`, as
/// it's done "on the fly" when sending a mail.
#[derive(Debug, Fail)]
pub enum MailSendError {
/// Something is wrong with the mail instance (e.g. it can't be encoded).
///
/// This can happen for a number of reasons including:
///
/// 1. Missing header fields.
/// 2. Invalid header fields.
/// 2. Encoding header fields fails.
/// 3. Loading resources failed (resources like e.g. appendix, logo embedded in html mail, etc.)
#[fail(display = "{}", _0)]
Mail(MailError),
/// Sending the mail failed.
///
/// This can happen for a number of reasons including:
/// 1. Server rejects mail transaction because of send or receiver
/// address or body data (e.g. body to long).
/// 2. Mail address requires smtputf8 support, which is not given.
/// 3. Server rejects sending the mail for other reasons (it's
/// closing, overloaded etc.).
#[fail(display = "{}", _0)]
Smtp(LogicError),
/// Setting up the connection failed.
///
/// Failures can include but are not limited to:
///
/// - Connecting with TCP failed.
/// - Starting TLS failed.
/// - Server does not want to be used (e.g. failure on sending EHLO).
/// - Authentication failed.
#[fail(display = "{}", _0)]
Connecting(ConnectingFailed),
/// An I/O error happened while using the connection.
///
/// This is mainly for I/O errors after the setup of the connection
/// was successful, which normally includes sending Ehlo and Auth
/// commands.
#[fail(display = "{}", _0)]
Io(std_io::Error)
}
impl From<MailError> for MailSendError {
fn from(err: MailError) -> Self {
MailSendError::Mail(err)
}
}
impl From<LogicError> for MailSendError {
fn from(err: LogicError) -> Self {
MailSendError::Smtp(err)
}
}
impl From<std_io::Error> for MailSendError {
fn from(err: std_io::Error) -> Self {
MailSendError::Io(err)
}
}
impl From<ConnectingFailed> for MailSendError {
fn from(err: ConnectingFailed) -> Self {
MailSendError::Connecting(err)
}
}
impl From<GeneralError> for MailSendError {
fn from(err: GeneralError) -> Self {
use self::GeneralError::*;
match err {
Connecting(err) => Self::from(err),
Cmd(err) => Self::from(err),
Io(err) => Self::from(err)
}
}
}
#[derive(Debug, Fail)]
pub enum OtherValidationError {
#[fail(display = "no To header was present")]
NoTo
}
impl From<OtherValidationError> for HeaderValidationError {
fn from(ove: OtherValidationError) -> Self {
HeaderValidationError::Custom(ove.into())
}
}
impl From<OtherValidationError> for MailError {
fn from(ove: OtherValidationError) -> Self {
MailError::from(HeaderValidationError::from(ove))
}
}
|