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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
use smtp_message::{EnhancedReplyCode, MaybeUtf8, Reply, ReplyCode};
#[inline]
pub fn welcome_banner(hostname: &str, banner: &str) -> Reply {
Reply {
code: ReplyCode::SERVICE_READY,
ecode: None,
text: vec![MaybeUtf8::Utf8(String::from(hostname) + " " + banner)],
}
}
#[inline]
pub fn okay_hello(
is_extended: bool,
local_hostname: &str,
banner: &str,
can_do_tls: bool,
) -> Reply {
let mut built_banner = String::from(local_hostname);
if !banner.is_empty() {
built_banner += " ";
built_banner += banner;
}
let mut text = vec![MaybeUtf8::Utf8(built_banner)];
if is_extended {
text.push(MaybeUtf8::Ascii("8BITMIME".into()));
text.push(MaybeUtf8::Ascii("ENHANCEDSTATUSCODES".into()));
text.push(MaybeUtf8::Ascii("PIPELINING".into()));
text.push(MaybeUtf8::Ascii("SMTPUTF8".into()));
if can_do_tls {
text.push(MaybeUtf8::Ascii("STARTTLS".into()));
}
}
Reply {
code: ReplyCode::OKAY,
ecode: None,
text,
}
}
#[inline]
pub fn okay(ecode: EnhancedReplyCode<&'static str>) -> Reply<&'static str> {
Reply {
code: ReplyCode::OKAY,
ecode: Some(ecode),
text: vec![MaybeUtf8::Ascii("Okay")],
}
}
#[inline]
pub fn okay_from() -> Reply<&'static str> {
okay(EnhancedReplyCode::SUCCESS_UNDEFINED)
}
#[inline]
pub fn okay_to() -> Reply<&'static str> {
okay(EnhancedReplyCode::SUCCESS_DEST_VALID)
}
#[inline]
pub fn okay_data() -> Reply<&'static str> {
Reply {
code: ReplyCode::START_MAIL_INPUT,
ecode: None,
text: vec![MaybeUtf8::Ascii("Start mail input; end with <CRLF>.<CRLF>")],
}
}
#[inline]
pub fn okay_mail() -> Reply<&'static str> {
okay(EnhancedReplyCode::SUCCESS_UNDEFINED)
}
#[inline]
pub fn okay_starttls() -> Reply<&'static str> {
Reply {
code: ReplyCode::SERVICE_READY,
ecode: Some(EnhancedReplyCode::SUCCESS_UNDEFINED),
text: vec![MaybeUtf8::Ascii("Ready to start TLS")],
}
}
#[inline]
pub fn okay_rset() -> Reply<&'static str> {
okay(EnhancedReplyCode::SUCCESS_UNDEFINED)
}
#[inline]
pub fn ignore_vrfy() -> Reply<&'static str> {
Reply {
code: ReplyCode::CANNOT_VRFY_BUT_PLEASE_TRY,
ecode: Some(EnhancedReplyCode::SUCCESS_DEST_VALID),
text: vec![MaybeUtf8::Ascii(
"Cannot VRFY user, but will accept message and attempt delivery",
)],
}
}
#[inline]
pub fn ignore_help() -> Reply<&'static str> {
Reply {
code: ReplyCode::HELP_MESSAGE,
ecode: Some(EnhancedReplyCode::SUCCESS_UNDEFINED),
text: vec![MaybeUtf8::Ascii("See https://tools.ietf.org/html/rfc5321")],
}
}
#[inline]
pub fn okay_noop() -> Reply<&'static str> {
okay(EnhancedReplyCode::SUCCESS_UNDEFINED)
}
#[inline]
pub fn okay_quit() -> Reply<&'static str> {
Reply {
code: ReplyCode::CLOSING_CHANNEL,
ecode: Some(EnhancedReplyCode::SUCCESS_UNDEFINED),
text: vec![MaybeUtf8::Utf8("Bye")],
}
}
#[inline]
pub fn bad_sequence() -> Reply<&'static str> {
Reply {
code: ReplyCode::BAD_SEQUENCE,
ecode: Some(EnhancedReplyCode::PERMANENT_INVALID_COMMAND),
text: vec![MaybeUtf8::Ascii("Bad sequence of commands")],
}
}
#[inline]
pub fn command_unimplemented() -> Reply<&'static str> {
Reply {
code: ReplyCode::COMMAND_UNIMPLEMENTED,
ecode: Some(EnhancedReplyCode::PERMANENT_INVALID_COMMAND),
text: vec![MaybeUtf8::Ascii("Command not implemented")],
}
}
#[inline]
pub fn command_unrecognized() -> Reply<&'static str> {
Reply {
code: ReplyCode::COMMAND_UNRECOGNIZED,
ecode: Some(EnhancedReplyCode::PERMANENT_INVALID_COMMAND),
text: vec![MaybeUtf8::Ascii("Command not recognized")],
}
}
#[inline]
pub fn command_not_supported() -> Reply<&'static str> {
Reply {
code: ReplyCode::COMMAND_UNIMPLEMENTED,
ecode: Some(EnhancedReplyCode::PERMANENT_INVALID_COMMAND),
text: vec![MaybeUtf8::Ascii("Command not supported")],
}
}
#[inline]
pub fn pipeline_forbidden_after_starttls() -> Reply<&'static str> {
Reply {
code: ReplyCode::BAD_SEQUENCE,
ecode: Some(EnhancedReplyCode::PERMANENT_INVALID_COMMAND),
text: vec![MaybeUtf8::Ascii("Pipelining after starttls is forbidden")],
}
}
#[inline]
pub fn line_too_long() -> Reply<&'static str> {
Reply {
code: ReplyCode::COMMAND_UNRECOGNIZED,
ecode: Some(EnhancedReplyCode::PERMANENT_UNDEFINED),
text: vec![MaybeUtf8::Ascii("Line too long")],
}
}
#[inline]
pub fn internal_server_error() -> Reply<&'static str> {
Reply {
code: ReplyCode::LOCAL_ERROR,
ecode: Some(EnhancedReplyCode::TRANSIENT_UNDEFINED),
text: vec![MaybeUtf8::Ascii("Internal server error")],
}
}
#[inline]
pub fn handle_mail_did_not_call_complete() -> Reply<&'static str> {
Reply {
code: ReplyCode::LOCAL_ERROR,
ecode: Some(EnhancedReplyCode::TRANSIENT_SYSTEM_INCORRECTLY_CONFIGURED),
text: vec![MaybeUtf8::Ascii("System incorrectly configured")],
}
}