-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widen support of auth methods #9
Conversation
ucomah
commented
Oct 14, 2023
- Added a support for PLAIN with method.
- If desired (forced) auth method is not set by user - most preferable one will be used from server's response.
@@ -43,3 +43,28 @@ public enum SMTPResponseCode: Int { | |||
case startMailInput = 354 | |||
case commandNotRecognized = 502 | |||
} | |||
|
|||
/// SMTP Authentication method. | |||
public enum SMTPAuthMethod: String, CaseIterable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add this myself, but feel that this should be a struct
, in case we add more auth methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't use a public enum
for SMTPAuthMethod
, because it doesn't allow us to expand the auth methods in the future. Adding this would force us to "freeze" the enums cases, so we'd be stuck supporting only these auth methods.
The solution is to make a public struct
around the same enum, that's instead an internal enum
. By adding static let
's for each enum case, we can have the same API but without worrying about API compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this PR for a related implementation: hummingbird-project/hummingbird#361
Sorry for missing your PR. I didn't see this because I wasn't marked for review |
No worries, hope you'll have a time to take a look )) |
|
||
|
||
if line.contains("AUTH"), auth.isEmpty { | ||
auth = Set(line.components(separatedBy: " ").compactMap { SMTPAuthMethod(rawValue: $0) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
auth = Set(line.components(separatedBy: " ").compactMap { SMTPAuthMethod(rawValue: $0) }) | |
auth = Set(line.components(separatedBy: " ").compactMap(SMTPAuthMethod.init) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! We'll need to adapt it a little, but I really appreciate the input
@@ -43,3 +43,28 @@ public enum SMTPResponseCode: Int { | |||
case startMailInput = 354 | |||
case commandNotRecognized = 502 | |||
} | |||
|
|||
/// SMTP Authentication method. | |||
public enum SMTPAuthMethod: String, CaseIterable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't use a public enum
for SMTPAuthMethod
, because it doesn't allow us to expand the auth methods in the future. Adding this would force us to "freeze" the enums cases, so we'd be stuck supporting only these auth methods.
The solution is to make a public struct
around the same enum, that's instead an internal enum
. By adding static let
's for each enum case, we can have the same API but without worrying about API compatibility.
@@ -43,3 +43,28 @@ public enum SMTPResponseCode: Int { | |||
case startMailInput = 354 | |||
case commandNotRecognized = 502 | |||
} | |||
|
|||
/// SMTP Authentication method. | |||
public enum SMTPAuthMethod: String, CaseIterable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this PR for a related implementation: hummingbird-project/hummingbird#361
/// Type for building a correct credentials for PLAIN SMTP auth. | ||
public struct SMTPPlainCreds: SMTPClientRequest { | ||
public let user: String | ||
public let password: String | ||
|
||
public var text: String { | ||
"\0\(user)\0\(password)" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this to be public?
/// Type for building a correct credentials for PLAIN SMTP auth. | |
public struct SMTPPlainCreds: SMTPClientRequest { | |
public let user: String | |
public let password: String | |
public var text: String { | |
"\0\(user)\0\(password)" | |
} | |
} | |
/// Type for building a correct credentials for PLAIN SMTP auth. | |
struct SMTPPlainCreds: SMTPClientRequest { | |
let user: String | |
let password: String | |
var text: String { | |
"\0\(user)\0\(password)" | |
} | |
} |
|
||
try await self.send(.authenticatePassword(password)) | ||
.status(.authSucceeded, or: SMTPError.loginFailure) | ||
public func login(user: String, password: String, force method: SMTPAuthMethod? = nil) async throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public func login(user: String, password: String, force method: SMTPAuthMethod? = nil) async throws { | |
/// Authenticates to the SMTP server. If `method` is `nil`, the method will be chosen automatically. Otherwise | |
/// the requested method will be used | |
public func login(user: String, password: String, method: SMTPAuthMethod? = nil) async throws { |
I'm going to add these changes into #14 |
My apologies for the silence for so long. II'll try to push requested changes this week. |