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

Fixed issue with HTML attachments (501 Syntax error - line too long) #114

Merged
merged 4 commits into from
Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftSMTP/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let CRLF = "\r\n"

extension String {
var base64Encoded: String {
return Data(utf8).base64EncodedString()
return Data(utf8).base64EncodedString(options: .lineLength76Characters)
}

var mimeEncoded: String? {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSMTP/SMTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ public struct SMTP {
/// - mail: `Mail` object to send.
/// - completion: Callback when sending finishes. `Error` is nil on success. (optional)
public func send(_ mail: Mail, completion: ((Error?) -> Void)? = nil) {
send([mail]) { (_, failed) in
send([mail], completion: { (_, failed) in
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, were these syntax changes necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Necessary, no - it was just XCode 12.2 (12B45b) complaining with a warning:

Backward matching of the unlabeled trailing closure is deprecated; label the argument with 'completion' to suppress this warning

Copy link
Contributor

@dannys42 dannys42 Dec 16, 2020

Choose a reason for hiding this comment

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

Oh interesting. I'll make a note to review that Issue 116, but I think your update is more readable anyway.

if let error = failed.first?.1 {
completion?(error)
} else {
completion?(nil)
}
}
})
}

/// Send multiple emails.
Expand Down
12 changes: 6 additions & 6 deletions Tests/SwiftSMTPTests/TestMailSender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class TestMailSender: XCTestCase {
defer { waitForExpectations(timeout: testDuration) }

let mail = Mail(from: from, to: [to], subject: #function, text: text)
smtp.send([mail]) { _, failed in
smtp.send([mail], completion: { _, failed in
XCTAssert(failed.isEmpty)
x.fulfill()
}
})
}

func testSendMailNoRecipient() {
Expand Down Expand Up @@ -150,7 +150,7 @@ class TestMailSender: XCTestCase {
let badUser = Mail.User(email: "")
let badMail = Mail(from: from, to: [badUser])
let goodMail = Mail(from: from, to: [to], subject: "Send multiple mails with fail")
smtp.send([badMail, goodMail]) { (sent, failed) in
smtp.send([badMail, goodMail], completion: { (sent, failed) in
guard sent.count == 1 && failed.count == 1 else {
XCTFail("Send did not complete with 1 mail sent and 1 mail failed.")
return
Expand All @@ -159,17 +159,17 @@ class TestMailSender: XCTestCase {
XCTAssertEqual(failed[0].0.id, badMail.id, "Invalid email returned does not match the invalid email sent.")
XCTAssertNotNil(failed[0].1, "Invalid email did not return an error when sending.")
x.fulfill()
}
})
waitForExpectations(timeout: testDuration)
}

func testSendNoMail() {
let x = expectation(description: #function)
defer { waitForExpectations(timeout: testDuration) }
smtp.send([]) { (sent, failed) in
smtp.send([], completion: { (sent, failed) in
XCTAssert(sent.isEmpty)
XCTAssert(failed.isEmpty)
x.fulfill()
}
})
}
}