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")],
}
}