Skip to content

Commit

Permalink
Resolve compilation warnings with Swift 5 and later (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
djones6 authored Oct 4, 2019
1 parent a24f187 commit 75ba1b9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.2
5.1
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 14 additions & 14 deletions Sources/SwiftSMTP/Attachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftSMTP/DataSender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down
13 changes: 11 additions & 2 deletions Tests/SwiftSMTPTests/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 75ba1b9

Please sign in to comment.