Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Conversation

ucomah
Copy link

@ucomah 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.

@Joannis Joannis self-requested a review January 22, 2024 23:37
@@ -43,3 +43,28 @@ public enum SMTPResponseCode: Int {
case startMailInput = 354
case commandNotRecognized = 502
}

/// SMTP Authentication method.
public enum SMTPAuthMethod: String, CaseIterable {
Copy link
Owner

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

Copy link
Owner

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.

Copy link
Owner

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

@Joannis
Copy link
Owner

Joannis commented Jan 25, 2024

Sorry for missing your PR. I didn't see this because I wasn't marked for review

@ucomah
Copy link
Author

ucomah commented Jan 26, 2024

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) })
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
auth = Set(line.components(separatedBy: " ").compactMap { SMTPAuthMethod(rawValue: $0) })
auth = Set(line.components(separatedBy: " ").compactMap(SMTPAuthMethod.init)

Copy link
Owner

@Joannis Joannis left a 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 {
Copy link
Owner

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 {
Copy link
Owner

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

Comment on lines +62 to +70
/// 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)"
}
}
Copy link
Owner

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?

Suggested change
/// 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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {

@Joannis
Copy link
Owner

Joannis commented Feb 19, 2024

I'm going to add these changes into #14

@ucomah
Copy link
Author

ucomah commented Feb 21, 2024

My apologies for the silence for so long. II'll try to push requested changes this week.

@Joannis Joannis closed this Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants