return new CurlHTTPRequest(url, self)
end
- # Get a MAIL Request Object
- fun mail_request: nullable CurlMailRequest
- do
- var err: CURLCode
- err = self.prim_curl.easy_setopt(new CURLOption.follow_location, 1)
- if not err.is_ok then return null
+ # Get a MAIL Request Object
+ fun mail_request: nullable CurlMailRequest
+ do
+ var err: CURLCode
+ err = self.prim_curl.easy_setopt(new CURLOption.follow_location, 1)
+ if not err.is_ok then return null
- return new CurlMailRequest(self)
- end
+ return new CurlMailRequest(self)
+ end
# Release Curl instance
fun destroy do self.prim_curl.easy_clean
# CURL HTTP Request
class CurlHTTPRequest
super CurlRequest
- super CCurlCallbacks
- super CurlCallbacksRegisterIntern
+ super CCurlCallbacks
+ super CurlCallbacksRegisterIntern
- var url: String
+ var url: String
var datas: nullable HeaderMap writable = null
var headers: nullable HeaderMap writable = null
- init (url: String, curl: nullable Curl)
- do
- self.url = url
- self.curl = curl
- end
+ init (url: String, curl: nullable Curl)
+ do
+ self.url = url
+ self.curl = curl
+ end
# Execute HTTP request with settings configured through attribute
redef fun execute: CurlResponse
if self.delegate != null then callback_receiver = self.delegate.as(not null)
var err: CURLCode
- # Callbacks
+ # Callbacks
err = self.curl.prim_curl.register_callback(callback_receiver, new CURLCallbackType.header)
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
err = self.curl.prim_curl.register_callback(callback_receiver, new CURLCallbackType.body)
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
- # HTTP Header
+ # HTTP Header
if self.headers != null then
var headers_joined = self.headers.join_pairs(": ")
err = self.curl.prim_curl.easy_setopt(new CURLOption.httpheader, headers_joined.to_curlslist)
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
end
- # Datas
+ # Datas
if self.datas != null then
var postdatas = self.datas.to_url_encoded(self.curl.prim_curl)
err = self.curl.prim_curl.easy_setopt(new CURLOption.postfields, postdatas)
# CURL Mail Request
class CurlMailRequest
- super CurlRequest
- super CCurlCallbacks
+ super CurlRequest
+ super CCurlCallbacks
- var headers: nullable HeaderMap writable = null
+ var headers: nullable HeaderMap writable = null
var headers_body: nullable HeaderMap writable = null
var from: nullable String writable = null
var to: nullable Array[String] writable = null
var body: nullable String writable = ""
private var supported_outgoing_protocol: Array[String]
- init (curl: nullable Curl)
- do
- self.curl = curl
+ init (curl: nullable Curl)
+ do
+ self.curl = curl
self.supported_outgoing_protocol = once ["smtp", "smtps"]
- end
+ end
# Helper method to add conventional space while building entire mail
private fun add_conventional_space(str: String):String do return "{str}\n" end
return "{str}{att}\n"
end
- # Helper method to add entire list of pairs to mail content
- private fun add_pairs_to_content(content: String, pairs: HeaderMap):String
- do
- for h_key, h_val in pairs do content = add_pair_to_content(content, h_key, h_val)
- return content
- end
+ # Helper method to add entire list of pairs to mail content
+ private fun add_pairs_to_content(content: String, pairs: HeaderMap):String
+ do
+ for h_key, h_val in pairs do content = add_pair_to_content(content, h_key, h_val)
+ return content
+ end
# Check for host and protocol availability
private fun is_supported_outgoing_protocol(host: String):CURLCode
var err: CURLCode
- # Host & Protocol
+ # Host & Protocol
err = is_supported_outgoing_protocol(host)
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
err = self.curl.prim_curl.easy_setopt(new CURLOption.url, host)
var success_response: CurlMailResponseSuccess = new CurlMailResponseSuccess
var err: CURLCode
- var content = ""
- # Headers
+ var content = ""
+ # Headers
if self.headers != null then
- content = add_pairs_to_content(content, self.headers.as(not null))
+ content = add_pairs_to_content(content, self.headers.as(not null))
end
# Recipients
err = self.curl.prim_curl.easy_setopt(new CURLOption.mail_rcpt, g_rec.to_curlslist)
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
- # From
+ # From
if not self.from == null then
content = add_pair_to_content(content, "From:", self.from)
err = self.curl.prim_curl.easy_setopt(new CURLOption.mail_from, self.from.as(not null))
# Subject
content = add_pair_to_content(content, "Subject:", self.subject)
- # Headers body
+ # Headers body
if self.headers_body != null then
- content = add_pairs_to_content(content, self.headers_body.as(not null))
+ content = add_pairs_to_content(content, self.headers_body.as(not null))
end
# Body
# Callbacks attributes
abstract class CurlCallbacksRegisterIntern
- var delegate: nullable CurlCallbacks writable = null
+ var delegate: nullable CurlCallbacks writable = null
end
# Abstract Curl request response
# Success Response Class of mail request
class CurlMailResponseSuccess
- super CurlResponseSuccessIntern
+ super CurlResponseSuccessIntern
end
# Success Response Class of a downloaded File