This commit is contained in:
2026-11-09 22:23:39 +01:00
committed by michael300679
parent 269a6e08b1
commit 469a9a11d2
12 changed files with 263 additions and 93 deletions
+7 -1
View File
@@ -17,7 +17,13 @@ final class IMAPClient {
let greeting = try await connection.readLine()
if greeting.uppercased().hasPrefix("* PREAUTH") { return }
guard greeting.uppercased().hasPrefix("* OK") else { throw MailError.message("IMAP: \(greeting)") }
_ = try await command("LOGIN \(Self.quote(account.username)) \(Self.quote(password))")
let capabilities = greeting.uppercased()
if capabilities.contains("AUTH=PLAIN"), capabilities.contains("SASL-IR") {
let credentials = Data(("\0" + account.username + "\0" + password).utf8).base64EncodedString()
_ = try await command("AUTHENTICATE PLAIN \(credentials)")
} else {
_ = try await command("LOGIN \(Self.quote(account.username)) \(Self.quote(password))")
}
}
static func quote(_ value: String) throws -> String {