Skip to content

Commit

Permalink
Merge pull request #5 from RockfordWei/master
Browse files Browse the repository at this point in the history
Fixing ISS-356
  • Loading branch information
kjessup authored Dec 29, 2016
2 parents e17fb20 + 9ce2d43 commit 7f0053f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
12 changes: 2 additions & 10 deletions Sources/cURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,7 @@ public class CURL {
}
let _ = setOption(CURLOPT_WRITEFUNCTION, f: writeFunc)

let readFunc: curl_func = {
(a, b, c, p) -> Int in

// !FIX!

// let crl = Unmanaged<CURL>.fromOpaque(COpaquePointer(p)).takeUnretainedValue()
return 0
}
_ = setOption(CURLOPT_READFUNCTION, f: readFunc)
let _ = setOption(CURLOPT_READFUNCTION, f: { fread($0, $1, $2, unsafeBitCast($3, to: UnsafeMutablePointer<FILE>.self)) })

}

Expand Down Expand Up @@ -335,7 +327,7 @@ public class CURL {
CURLOPT_POSTQUOTE.rawValue,
CURLOPT_PREQUOTE.rawValue,
CURLOPT_QUOTE.rawValue,
CURLOPT_MAIL_FROM.rawValue,
//CURLOPT_MAIL_FROM.rawValue,
CURLOPT_MAIL_RCPT.rawValue:
let slists = curl_slist_append(self.slists, s)
guard slists != nil else {
Expand Down
43 changes: 43 additions & 0 deletions Tests/PerfectCURLTests/PerfectCURLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,54 @@ class PerfectCURLTests: XCTestCase {
}
}

func testSMTP () {
var timestamp = time(nil)
let now = String(cString: asctime(localtime(&timestamp))!)
let sender = "[email protected]"
let recipient = sender
let u = UnsafeMutablePointer<UInt8>.allocate(capacity: MemoryLayout<uuid_t>.size)
uuid_generate_random(u)
let unu = UnsafeMutablePointer<Int8>.allocate(capacity: 37)
uuid_unparse_lower(u, unu)
let uuid = String(validatingUTF8: unu)!
u.deallocate(capacity: MemoryLayout<uuid_t>.size)
unu.deallocate(capacity: 37)

let content = "Date: \(now)To: \(recipient)\r\nFrom: \(sender)\r\nCc:\r\nBcc:\r\n" +
"Message-ID: <\(uuid)@perfect.org>\r\n" +
"Subject: Hello Perfect-CURL\r\n\r\nSMTP test \(now)\r\n\r\n"
print(content)
let curl = CURL(url: "smtp://smtp.gmx.com")
let _ = curl.setOption(CURLOPT_USERNAME, s: sender)
let _ = curl.setOption(CURLOPT_PASSWORD, s: "abcd1234")
//let _ = curl.setOption(CURLOPT_USE_SSL, int: Int(CURLUSESSL_ALL.rawValue))
let _ = curl.setOption(CURLOPT_MAIL_FROM, s: sender)
let _ = curl.setOption(CURLOPT_MAIL_RCPT, s: recipient)
let _ = curl.setOption(CURLOPT_VERBOSE, int: 1)
let _ = curl.setOption(CURLOPT_UPLOAD, int: 1)
let _ = curl.setOption(CURLOPT_INFILESIZE, int: content.utf8.count)
var p:[Int32] = [-1, -1]
let result = pipe(&p)
XCTAssertEqual(result, 0)
let fi = fdopen(p[0], "rb")
let fo = fdopen(p[1], "wb")
let w = fwrite(content, 1, content.utf8.count, fo)
fclose(fo)
XCTAssertEqual(w, content.utf8.count)
let _ = curl.setOption(CURLOPT_READDATA, v: fi!)
let r = curl.performFully()
print(r.0)
print(String(cString:r.1))
print(String(cString:r.2))
fclose(fi)
XCTAssertEqual(r.0, 0)
}
static var allTests : [(String, (PerfectCURLTests) -> () throws -> Void)] {
return [
("testCURLPost", testCURLPost),
("testCURLHeader", testCURLHeader),
("testCURLAsync", testCURLAsync),
("testSMTP", testSMTP),
("testCURL", testCURL)
]
}
Expand Down

0 comments on commit 7f0053f

Please sign in to comment.