Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_net/src/smtp/codes.rs

9.1 KiB, 6 runs

created by r1870400018:595, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use oxedyne_fe2o3_core::prelude::*;
2
3use std::{
4 fmt,
5};
6
7
8#[derive(Clone, Debug, PartialEq)]
9pub enum CompletionState {
10 PositiveCompletion,
11 PositiveIntermediate,
12 TransientNegativeCompletion,
13 PermanentNegativeCompletion,
14}
15
16#[derive(Clone, Debug, PartialEq)]
17pub enum SmtpResponseCode {
18 NonStandardSuccess,
19 SystemStatusReply,
20 HelpMessage,
21 ServiceReady,
22 ServiceClosingTransmissionChannel,
23 AuthenticationSuccessful,
24 RequestedMailActionOkayCompleted,
25 UserNotLocalWillForward,
26 CannotVerifyUserButWillAttemptDelivery,
27 AuthInputData,
28 StartMailInput,
29 ServiceNotAvailableClosingTransmissionChannel,
30 PasswordTransitionNeeded,
31 MailboxUnavailable,
32 LocalErrorInProcessing,
33 InsufficientSystemStorage,
34 UnableToAccommodateParameters,
35 CommandUnrecognized,
36 SyntaxErrorInParameters,
37 CommandNotImplemented,
38 BadSequenceOfCommands,
39 CommandParameterNotImplemented,
40 DomainDoesNotAcceptMail,
41 AuthenticationRequired,
42 AuthenticationMechanismTooWeak,
43 AuthenticationCredentialsInvalid,
44 EncryptionRequiredForAuthentication,
45 MailboxUnavailableOrAccessDenied,
46 UserNotLocalTryForwardPath,
47 ExceededStorageAllocation,
48 MailboxNameNotAllowed,
49 TransactionFailed,
50 MailFromRcptToParametersNotRecognizedOrImplemented,
51 AuthenticationMechanismNotAvailable,
52}
53
54impl SmtpResponseCode {
55
56 pub fn state(&self) -> CompletionState {
57 match self {
58 Self::NonStandardSuccess |
59 Self::SystemStatusReply |
60 Self::HelpMessage |
61 Self::ServiceReady |
62 Self::AuthenticationSuccessful |
63 Self::RequestedMailActionOkayCompleted |
64 Self::UserNotLocalWillForward |
65 Self::CannotVerifyUserButWillAttemptDelivery |
66 Self::ServiceClosingTransmissionChannel => CompletionState::PositiveCompletion,
67 Self::AuthInputData |
68 Self::StartMailInput => CompletionState::PositiveIntermediate,
69 Self::ServiceNotAvailableClosingTransmissionChannel |
70 Self::PasswordTransitionNeeded |
71 Self::MailboxUnavailable |
72 Self::LocalErrorInProcessing |
73 Self::InsufficientSystemStorage |
74 Self::UnableToAccommodateParameters => CompletionState::TransientNegativeCompletion,
75 Self::CommandUnrecognized |
76 Self::SyntaxErrorInParameters |
77 Self::CommandNotImplemented |
78 Self::BadSequenceOfCommands |
79 Self::CommandParameterNotImplemented |
80 Self::DomainDoesNotAcceptMail |
81 Self::AuthenticationRequired |
82 Self::AuthenticationMechanismTooWeak |
83 Self::AuthenticationCredentialsInvalid |
84 Self::EncryptionRequiredForAuthentication |
85 Self::MailboxUnavailableOrAccessDenied |
86 Self::UserNotLocalTryForwardPath |
87 Self::ExceededStorageAllocation |
88 Self::MailboxNameNotAllowed |
89 Self::TransactionFailed |
90 Self::MailFromRcptToParametersNotRecognizedOrImplemented |
91 Self::AuthenticationMechanismNotAvailable => CompletionState::PermanentNegativeCompletion,
92 }
93 }
94}
95
96impl fmt::Display for SmtpResponseCode {
97 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98 match self {
99 Self::NonStandardSuccess => write!(f, "200"),
100 Self::SystemStatusReply => write!(f, "211"),
101 Self::HelpMessage => write!(f, "214"),
102 Self::ServiceReady => write!(f, "220"),
103 Self::ServiceClosingTransmissionChannel => write!(f, "221"),
104 Self::AuthenticationSuccessful => write!(f, "235"),
105 Self::RequestedMailActionOkayCompleted => write!(f, "250"),
106 Self::UserNotLocalWillForward => write!(f, "251"),
107 Self::CannotVerifyUserButWillAttemptDelivery => write!(f, "252"),
108 Self::AuthInputData => write!(f, "334"),
109 Self::StartMailInput => write!(f, "354"),
110 Self::ServiceNotAvailableClosingTransmissionChannel => write!(f, "421"),
111 Self::PasswordTransitionNeeded => write!(f, "432"),
112 Self::MailboxUnavailable => write!(f, "450"),
113 Self::LocalErrorInProcessing => write!(f, "451"),
114 Self::InsufficientSystemStorage => write!(f, "452"),
115 Self::UnableToAccommodateParameters => write!(f, "455"),
116 Self::CommandUnrecognized => write!(f, "500"),
117 Self::SyntaxErrorInParameters => write!(f, "501"),
118 Self::CommandNotImplemented => write!(f, "502"),
119 Self::BadSequenceOfCommands => write!(f, "503"),
120 Self::CommandParameterNotImplemented => write!(f, "504"),
121 Self::DomainDoesNotAcceptMail => write!(f, "521"),
122 Self::AuthenticationRequired => write!(f, "530"),
123 Self::AuthenticationMechanismTooWeak => write!(f, "534"),
124 Self::AuthenticationCredentialsInvalid => write!(f, "535"),
125 Self::EncryptionRequiredForAuthentication => write!(f, "538"),
126 Self::MailboxUnavailableOrAccessDenied => write!(f, "550"),
127 Self::UserNotLocalTryForwardPath => write!(f, "551"),
128 Self::ExceededStorageAllocation => write!(f, "552"),
129 Self::MailboxNameNotAllowed => write!(f, "553"),
130 Self::TransactionFailed => write!(f, "554"),
131 Self::MailFromRcptToParametersNotRecognizedOrImplemented => write!(f, "555"),
132 Self::AuthenticationMechanismNotAvailable => write!(f, "556"),
133 }
134 }
135}
136
137impl FromStr for SmtpResponseCode {
138 type Err = Error<ErrTag>;
139
140 fn from_str(code: &str) -> Result<Self, Self::Err> {
141 Ok(match code {
142 "200" => Self::NonStandardSuccess,
143 "211" => Self::SystemStatusReply,
144 "214" => Self::HelpMessage,
145 "220" => Self::ServiceReady,
146 "221" => Self::ServiceClosingTransmissionChannel,
147 "235" => Self::AuthenticationSuccessful,
148 "250" => Self::RequestedMailActionOkayCompleted,
149 "251" => Self::UserNotLocalWillForward,
150 "252" => Self::CannotVerifyUserButWillAttemptDelivery,
151 "334" => Self::AuthInputData,
152 "354" => Self::StartMailInput,
153 "421" => Self::ServiceNotAvailableClosingTransmissionChannel,
154 "432" => Self::PasswordTransitionNeeded,
155 "450" => Self::MailboxUnavailable,
156 "451" => Self::LocalErrorInProcessing,
157 "452" => Self::InsufficientSystemStorage,
158 "455" => Self::UnableToAccommodateParameters,
159 "500" => Self::CommandUnrecognized,
160 "501" => Self::SyntaxErrorInParameters,
161 "502" => Self::CommandNotImplemented,
162 "503" => Self::BadSequenceOfCommands,
163 "504" => Self::CommandParameterNotImplemented,
164 "521" => Self::DomainDoesNotAcceptMail,
165 "530" => Self::AuthenticationRequired,
166 "534" => Self::AuthenticationMechanismTooWeak,
167 "535" => Self::AuthenticationCredentialsInvalid,
168 "538" => Self::EncryptionRequiredForAuthentication,
169 "550" => Self::MailboxUnavailableOrAccessDenied,
170 "551" => Self::UserNotLocalTryForwardPath,
171 "552" => Self::ExceededStorageAllocation,
172 "553" => Self::MailboxNameNotAllowed,
173 "554" => Self::TransactionFailed,
174 "555" => Self::MailFromRcptToParametersNotRecognizedOrImplemented,
175 "556" => Self::AuthenticationMechanismNotAvailable,
176 _ => return Err(err!(
177 "SMTP code '{}' not recognised.", code;
178 IO, Network, Wire, Unknown, Input)),
179 })
180 }
181}