From 75ba1b9c0f524f9f3a87f19d87c1a3f2dfb8710f Mon Sep 17 00:00:00 2001 From: David Jones Date: Fri, 4 Oct 2019 10:00:07 +0100 Subject: [PATCH] Resolve compilation warnings with Swift 5 and later (#105) --- .swift-version | 2 +- .travis.yml | 12 ++++++++++-- Sources/SwiftSMTP/Attachment.swift | 28 ++++++++++++++-------------- Sources/SwiftSMTP/DataSender.swift | 6 +++--- Tests/SwiftSMTPTests/Constant.swift | 13 +++++++++++-- 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/.swift-version b/.swift-version index a1ef0ca..a75b92f 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -5.0.2 +5.1 diff --git a/.travis.yml b/.travis.yml index dcbe980..ee21995 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,12 +30,17 @@ matrix: dist: xenial sudo: required services: docker - env: DOCKER_IMAGE=swift:5.0.2-xenial DOCKER_ENVIRONMENT="EMAIL PASSWORD" + env: DOCKER_IMAGE=swift:5.0.3-xenial SWIFT_SNAPSHOT=5.0.3 DOCKER_ENVIRONMENT="EMAIL PASSWORD" - os: linux dist: xenial sudo: required services: docker - env: DOCKER_IMAGE=swift:5.0.2 SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT DOCKER_ENVIRONMENT="EMAIL PASSWORD" + env: DOCKER_IMAGE=swift:5.1 DOCKER_ENVIRONMENT="EMAIL PASSWORD" + - os: linux + dist: xenial + sudo: required + services: docker + env: DOCKER_IMAGE=swift:5.1 SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT DOCKER_ENVIRONMENT="EMAIL PASSWORD" - os: osx osx_image: xcode9.2 sudo: required @@ -52,6 +57,9 @@ matrix: osx_image: xcode10.2 sudo: required env: SWIFT_SNAPSHOT=5.0.1 JAZZY_ELIGIBLE=true + - os: osx + osx_image: xcode11 + sudo: required - os: osx osx_image: xcode11 sudo: required diff --git a/Sources/SwiftSMTP/Attachment.swift b/Sources/SwiftSMTP/Attachment.swift index 6668458..9b2a177 100644 --- a/Sources/SwiftSMTP/Attachment.swift +++ b/Sources/SwiftSMTP/Attachment.swift @@ -131,24 +131,24 @@ extension Attachment { var dictionary = [String: String]() switch type { - case .data(let data): - dictionary["CONTENT-TYPE"] = data.mime - var attachmentDisposition = data.inline ? "inline" : "attachment" - if let mime = data.name.mimeEncoded { - attachmentDisposition.append("; filename=\"\(mime)\"") + case .data(_, let mime, let name, let inline): + dictionary["CONTENT-TYPE"] = mime + var attachmentDisposition = inline ? "inline" : "attachment" + if let mimeName = name.mimeEncoded { + attachmentDisposition.append("; filename=\"\(mimeName)\"") } dictionary["CONTENT-DISPOSITION"] = attachmentDisposition - case .file(let file): - dictionary["CONTENT-TYPE"] = file.mime - var attachmentDisposition = file.inline ? "inline" : "attachment" - if let mime = file.name.mimeEncoded { - attachmentDisposition.append("; filename=\"\(mime)\"") + case .file(_, let mime, let name, let inline): + dictionary["CONTENT-TYPE"] = mime + var attachmentDisposition = inline ? "inline" : "attachment" + if let mimeName = name.mimeEncoded { + attachmentDisposition.append("; filename=\"\(mimeName)\"") } dictionary["CONTENT-DISPOSITION"] = attachmentDisposition - case .html(let html): - dictionary["CONTENT-TYPE"] = "text/html; charset=\(html.characterSet)" + case .html(_, let characterSet, _): + dictionary["CONTENT-TYPE"] = "text/html; charset=\(characterSet)" dictionary["CONTENT-DISPOSITION"] = "inline" } @@ -179,8 +179,8 @@ extension Attachment { } var isAlternative: Bool { - if case .html(let html) = type, html.alternative { - return true + if case .html(_, _, let alternative) = type { + return alternative } return false } diff --git a/Sources/SwiftSMTP/DataSender.swift b/Sources/SwiftSMTP/DataSender.swift index 069ead2..a2f20a1 100644 --- a/Sources/SwiftSMTP/DataSender.swift +++ b/Sources/SwiftSMTP/DataSender.swift @@ -110,9 +110,9 @@ extension DataSender { try send(attachmentHeader) switch attachment.type { - case .data(let data): try sendData(data.data) - case .file(let file): try sendFile(at: file.path) - case .html(let html): try sendHTML(html.content) + case .data(let data, _, _, _): try sendData(data) + case .file(let path, _, _, _): try sendFile(at: path) + case .html(let content, _, _): try sendHTML(content) } try send("") diff --git a/Tests/SwiftSMTPTests/Constant.swift b/Tests/SwiftSMTPTests/Constant.swift index 032baff..1490296 100644 --- a/Tests/SwiftSMTPTests/Constant.swift +++ b/Tests/SwiftSMTPTests/Constant.swift @@ -58,12 +58,21 @@ let password: String = { }() let senderEmailDomain: String = { - if let atIndex = email.index(of: "@") { - let domainStart = email.index(after: atIndex) +#if swift(>=5) + if let atIndex = email.firstIndex(of: "@") { + let domainStart = email.index(after: atIndex) return String(email[domainStart...]) } else { return "gmail.com" } +#else + if let atIndex = email.index(of: "@") { + let domainStart = email.index(after: atIndex) + return String(email[domainStart...]) + } else { + return "gmail.com" + } +#endif }() let testsDir: String = {