aboutsummaryrefslogtreecommitdiff
path: root/xs_curl.h
diff options
context:
space:
mode:
authorOliver <zen@noreply.codeberg.org>2025-05-21 21:11:47 +0200
committerOliver <zen@noreply.codeberg.org>2025-05-21 21:11:47 +0200
commit979718e3cc5489efdce2acc6f8c86f6d00bb91c7 (patch)
tree7b4936bdb5ea07c7dd617d508c487d70020f0146 /xs_curl.h
parent1b0804bb0da0ef89aef98d9a771d2aa5bfeb34d7 (diff)
parent5059fadf34b79a9f596313b0bd859c1eb89342ae (diff)
Merge pull request 'master refresh' (#8) from grunfink/snac2:master into master
Reviewed-on: https://codeberg.org/zen/snac2/pulls/8
Diffstat (limited to 'xs_curl.h')
-rw-r--r--xs_curl.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/xs_curl.h b/xs_curl.h
index 657644a..2301661 100644
--- a/xs_curl.h
+++ b/xs_curl.h
@@ -9,6 +9,10 @@ xs_dict *xs_http_request(const char *method, const char *url,
const xs_str *body, int b_size, int *status,
xs_str **payload, int *p_size, int timeout);
+int xs_smtp_request(const char *url, const char *user, const char *pass,
+ const char *from, const char *to, const xs_str *body,
+ int use_ssl);
+
const char *xs_curl_strerr(int errnum);
#ifdef XS_IMPLEMENTATION
@@ -197,6 +201,49 @@ xs_dict *xs_http_request(const char *method, const char *url,
}
+int xs_smtp_request(const char *url, const char *user, const char *pass,
+ const char *from, const char *to, const xs_str *body,
+ int use_ssl)
+{
+ CURL *curl;
+ CURLcode res = CURLE_OK;
+ struct curl_slist *rcpt = NULL;
+ struct _payload_data pd = {
+ .data = (char *)body,
+ .size = strlen(body),
+ .offset = 0
+ };
+
+ curl = curl_easy_init();
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ if (user && pass) {
+ /* allow authless connections, to, e.g. localhost */
+ curl_easy_setopt(curl, CURLOPT_USERNAME, user);
+ curl_easy_setopt(curl, CURLOPT_PASSWORD, pass);
+ }
+
+ if (use_ssl)
+ curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
+
+ curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);
+
+ rcpt = curl_slist_append(rcpt, to);
+ curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt);
+
+ curl_easy_setopt(curl, CURLOPT_READDATA, &pd);
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, _post_callback);
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+
+ res = curl_easy_perform(curl);
+
+ curl_easy_cleanup(curl);
+ curl_slist_free_all(rcpt);
+
+ return (int)res;
+}
+
+
const char *xs_curl_strerr(int errnum)
{
CURLcode cc = errnum < 0 ? -errnum : errnum;