From 4e3d596bee1cee2c4146265eb6ac827f09820c53 Mon Sep 17 00:00:00 2001 From: shtrophic Date: Mon, 20 Jan 2025 19:43:42 +0100 Subject: add xs_smtp_request --- activitypub.c | 48 +++++++++++++++++++----------------------------- data.c | 2 +- xs_curl.h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 30 deletions(-) diff --git a/activitypub.c b/activitypub.c index 8b44dc8..ca5cc3e 100644 --- a/activitypub.c +++ b/activitypub.c @@ -962,17 +962,20 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, xs *subject = xs_fmt("snac notify for @%s@%s", xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); - xs *from = xs_fmt("snac-daemon ", xs_dict_get(srv_config, "host")); + xs *from = xs_fmt("", xs_dict_get(srv_config, "host")); xs *header = xs_fmt( - "From: %s\n" + "From: snac-daemon %s\n" "To: %s\n" "Subject: %s\n" "\n", from, email, subject); - xs *email_body = xs_fmt("%s%s", header, body); + xs_dict *mailinfo = xs_dict_new(); + xs_dict_append(mailinfo, "from", from); + xs_dict_append(mailinfo, "to", email); + xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); - enqueue_email(email_body, 0); + enqueue_email(mailinfo, 0); } /* telegram */ @@ -2461,32 +2464,19 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) } -int send_email(const char *msg) +int send_email(const xs_dict *mailinfo) /* invoke sendmail with email headers and body in msg */ { - FILE *f; - int status; - int fds[2]; - pid_t pid; - if (pipe(fds) == -1) return -1; - pid = vfork(); - if (pid == -1) return -1; - else if (pid == 0) { - dup2(fds[0], 0); - close(fds[0]); - close(fds[1]); - execl("/usr/sbin/sendmail", "sendmail", "-t", (char *) NULL); - _exit(1); - } - close(fds[0]); - if ((f = fdopen(fds[1], "w")) == NULL) { - close(fds[1]); - return -1; - } - fprintf(f, "%s\n", msg); - fclose(f); - if (waitpid(pid, &status, 0) == -1) return -1; - return status; + const xs_dict *smtp_cfg = xs_dict_get(srv_config, "smtp"); + const char + *url = xs_dict_get(smtp_cfg, "url"), + *user = xs_dict_get(smtp_cfg, "username"), + *pass = xs_dict_get(smtp_cfg, "password"), + *from = xs_dict_get(mailinfo, "from"), + *to = xs_dict_get(mailinfo, "to"), + *body = xs_dict_get(mailinfo, "body"); + + return xs_smtp_request(url, user, pass, from, to, body); } @@ -2749,7 +2739,7 @@ void process_queue_item(xs_dict *q_item) else if (strcmp(type, "email") == 0) { /* send this email */ - const xs_str *msg = xs_dict_get(q_item, "message"); + const xs_dict *msg = xs_dict_get(q_item, "message"); int retries = xs_number_get(xs_dict_get(q_item, "retries")); if (!send_email(msg)) diff --git a/data.c b/data.c index 33947ff..b148ac7 100644 --- a/data.c +++ b/data.c @@ -3195,7 +3195,7 @@ void enqueue_output_by_actor(snac *snac, const xs_dict *msg, } -void enqueue_email(const xs_str *msg, int retries) +void enqueue_email(const xs_dict *msg, int retries) /* enqueues an email message to be sent */ { xs *qmsg = _new_qmsg("email", msg, retries); diff --git a/xs_curl.h b/xs_curl.h index f0cfd98..886aee0 100644 --- a/xs_curl.h +++ b/xs_curl.h @@ -9,6 +9,9 @@ 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); + #ifdef XS_IMPLEMENTATION #include @@ -194,6 +197,39 @@ xs_dict *xs_http_request(const char *method, const char *url, return response; } +int xs_smtp_request(const char *url, const char *user, const char *pass, + const char *from, const char *to, const xs_str *body) +{ + CURL *curl; + CURLcode res = CURLE_OK; + struct curl_slist *rcpt = NULL; + struct _payload_data pd = { + .data = (char *)body, + .size = xs_size(body), + .offset = 0 + }; + + curl = curl_easy_init(); + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_USERNAME, user); + curl_easy_setopt(curl, CURLOPT_PASSWORD, pass); + + curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from); + curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt = curl_slist_append(rcpt, to)); + + 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_slist_free_all(rcpt); + curl_easy_cleanup(curl); + + return (int)res; +} + #endif /* XS_IMPLEMENTATION */ #endif /* _XS_CURL_H */ -- cgit v1.2.3 From 4c1a2d24d374d00c656c4489db7d28f80d64f9dc Mon Sep 17 00:00:00 2001 From: shtrophic Date: Mon, 20 Jan 2025 22:59:30 +0100 Subject: add port parsing for sandboxing --- activitypub.c | 4 ++-- sandbox.c | 31 +++++++++++++++---------------- snac.h | 1 + utils.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 18 deletions(-) diff --git a/activitypub.c b/activitypub.c index ca5cc3e..e5fc715 100644 --- a/activitypub.c +++ b/activitypub.c @@ -2465,9 +2465,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) int send_email(const xs_dict *mailinfo) -/* invoke sendmail with email headers and body in msg */ +/* invoke curl */ { - const xs_dict *smtp_cfg = xs_dict_get(srv_config, "smtp"); + const xs_dict *smtp_cfg = xs_dict_get(srv_config, "email_notifications"); const char *url = xs_dict_get(smtp_cfg, "url"), *user = xs_dict_get(smtp_cfg, "username"), diff --git a/sandbox.c b/sandbox.c index cbe0043..875ae4e 100644 --- a/sandbox.c +++ b/sandbox.c @@ -8,8 +8,6 @@ void sbox_enter(const char *basedir) { const char *address = xs_dict_get(srv_config, "address"); - int smail = !xs_is_true(xs_dict_get(srv_config, "disable_email_notifications")); - if (xs_is_true(xs_dict_get(srv_config, "disable_openbsd_security"))) { srv_log(xs_dup("OpenBSD security disabled by admin")); return; @@ -24,9 +22,6 @@ void sbox_enter(const char *basedir) unveil("/etc/ssl/cert.pem", "r"); unveil("/usr/share/zoneinfo", "r"); - if (smail) - unveil("/usr/sbin/sendmail", "x"); - if (*address == '/') unveil(address, "rwc"); @@ -36,9 +31,6 @@ void sbox_enter(const char *basedir) xs *p = xs_str_new("stdio rpath wpath cpath flock inet proc dns fattr"); - if (smail) - p = xs_str_cat(p, " exec"); - if (*address == '/') p = xs_str_cat(p, " unix"); @@ -55,7 +47,7 @@ void sbox_enter(const char *basedir) #include "landloc.h" static -LL_BEGIN(sbox_enter_linux_, const char* basedir, const char *address, int smail) { +LL_BEGIN(sbox_enter_linux_, const char* basedir, const char *address, int smtp_port) { const unsigned long long rd = LANDLOCK_ACCESS_FS_READ_DIR, @@ -94,9 +86,6 @@ LL_BEGIN(sbox_enter_linux_, const char* basedir, const char *address, int smail) LL_PATH(sdir, s); } - if (smail && mtime("/usr/sbin/sendmail") > 0) - LL_PATH("/usr/sbin/sendmail", x); - if (*address != '/') { unsigned short listen_port = xs_number_get(xs_dict_get(srv_config, "port")); LL_PORT(listen_port, LANDLOCK_ACCESS_NET_BIND_TCP_COMPAT); @@ -104,24 +93,34 @@ LL_BEGIN(sbox_enter_linux_, const char* basedir, const char *address, int smail) LL_PORT(80, LANDLOCK_ACCESS_NET_CONNECT_TCP_COMPAT); LL_PORT(443, LANDLOCK_ACCESS_NET_CONNECT_TCP_COMPAT); + if (smtp_port > 0) + LL_PORT((unsigned short)smtp_port, LANDLOCK_ACCESS_NET_CONNECT_TCP_COMPAT); } LL_END void sbox_enter(const char *basedir) { + const xs_val *v; + const char *errstr; const char *address = xs_dict_get(srv_config, "address"); - - int smail = !xs_is_true(xs_dict_get(srv_config, "disable_email_notifications")); + int smtp_port = -1; if (xs_is_true(xs_dict_get(srv_config, "disable_sandbox"))) { srv_debug(1, xs_dup("Linux sandbox disabled by admin")); return; } - if (sbox_enter_linux_(basedir, address, smail) == 0) + if ((v = xs_dict_get(srv_config, "email_notifications")) && + (v = xs_dict_get(v, "url"))) { + smtp_port = parse_port((const char *)v, &errstr); + if (errstr) + srv_debug(0, xs_fmt("Couldn't determine port from '%s': %s", (const char *)v, errstr)); + } + + if (sbox_enter_linux_(basedir, address, smtp_port) == 0) srv_debug(1, xs_dup("Linux sandbox enabled")); else - srv_debug(1, xs_dup("Linux sandbox failed")); + srv_debug(0, xs_dup("Linux sandbox failed")); } #else /* defined(WITH_LINUX_SANDBOX) */ diff --git a/snac.h b/snac.h index 65ece5d..3db7b63 100644 --- a/snac.h +++ b/snac.h @@ -417,6 +417,7 @@ void import_blocked_accounts_csv(snac *user, const char *fn); void import_following_accounts_csv(snac *user, const char *fn); void import_list_csv(snac *user, const char *fn); void import_csv(snac *user); +int parse_port(const char *url, const char **errstr); typedef enum { #define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code, diff --git a/utils.c b/utils.c index a5b1124..3b0a78f 100644 --- a/utils.c +++ b/utils.c @@ -904,3 +904,55 @@ void import_csv(snac *user) else snac_log(user, xs_fmt("Cannot open file %s", fn)); } + +static const struct { + const char *proto; + unsigned short default_port; +} FALLBACK_PORTS[] = { + /* caution: https > http, smpts > smtp */ + {"https", 443}, + {"http", 80}, + {"smtps", 465}, + {"smtp", 25} +}; + +int parse_port(const char *url, const char **errstr) +{ + const char *col, *rcol; + int tmp, ret = -1; + + if (errstr) + *errstr = NULL; + + if (!(col = strchr(url, ':'))) { + if (errstr) + *errstr = "bad url"; + return -1; + } + + for (size_t i = 0; i < sizeof(FALLBACK_PORTS) / sizeof(*FALLBACK_PORTS); ++i) { + if (memcmp(url, FALLBACK_PORTS[i].proto, strlen(FALLBACK_PORTS[i].proto)) == 0) { + ret = FALLBACK_PORTS[i].default_port; + break; + } + } + + if (!(rcol = strchr(col + 1, ':'))) + rcol = col; + + if (rcol) { + tmp = atoi(rcol + 1); + if (tmp == 0) { + if (ret != -1) + return ret; + + *errstr = strerror(errno); + return -1; + } + + return tmp; + } + + *errstr = "unknown protocol"; + return -1; +} -- cgit v1.2.3 From 13e4a7cda59db29063efc5dad0823fe99ec7b764 Mon Sep 17 00:00:00 2001 From: shtrophic Date: Mon, 20 Jan 2025 23:03:27 +0100 Subject: fix memory leak --- activitypub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activitypub.c b/activitypub.c index e5fc715..2b10435 100644 --- a/activitypub.c +++ b/activitypub.c @@ -970,7 +970,7 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, "\n", from, email, subject); - xs_dict *mailinfo = xs_dict_new(); + xs *mailinfo = xs_dict_new(); xs_dict_append(mailinfo, "from", from); xs_dict_append(mailinfo, "to", email); xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); -- cgit v1.2.3 From 1c4c15540360a5db9d56e6ae8d206a1f30a4f52b Mon Sep 17 00:00:00 2001 From: shtrophic Date: Fri, 24 Jan 2025 21:00:16 +0100 Subject: add tests subdirectory with makefile target --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 75d9562..764456d 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,16 @@ snac: snac.o main.o sandbox.o data.o http.o httpd.o webfinger.o \ activitypub.o html.o utils.o format.o upgrade.o mastoapi.o $(CC) $(CFLAGS) -L$(PREFIX)/lib *.o -lcurl -lcrypto $(LDFLAGS) -pthread -o $@ +test: tests/smtp + +tests/smtp: tests/smtp.o + $(CC) $(CFLAGS) -L$(PREFIX)/lib $< -lcurl $(LDFLAGS) -o $@ + .c.o: - $(CC) $(CFLAGS) $(CPPFLAGS) -I$(PREFIX)/include -c $< + $(CC) $(CFLAGS) $(CPPFLAGS) -I$(PREFIX)/include -c $< -o $@ clean: - rm -rf *.o *.core snac makefile.depend + rm -rf *.o tests/*.o tests/smtp *.core snac makefile.depend dep: $(CC) -I$(PREFIX)/include -MM *.c > makefile.depend @@ -64,3 +69,4 @@ utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \ xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h snac.h \ http_codes.h +tests/smtp.o: tests/smtp.c xs.h xs_curl.h -- cgit v1.2.3 From 3d96c576287736ebdf87e4a7b956842a6c6e055f Mon Sep 17 00:00:00 2001 From: shtrophic Date: Fri, 24 Jan 2025 22:24:05 +0100 Subject: enforce tls when supported && add tests --- .gitignore | 3 ++- activitypub.c | 3 ++- tests/smtp.c | 24 ++++++++++++++++++++++++ utils.c | 9 +++++++-- xs_curl.h | 22 ++++++++++++++++------ 5 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 tests/smtp.c diff --git a/.gitignore b/.gitignore index 7ead966..6ebb150 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -*.o +**/*.o +tests/smtp snac diff --git a/activitypub.c b/activitypub.c index 4cb779a..f3b2bae 100644 --- a/activitypub.c +++ b/activitypub.c @@ -2538,8 +2538,9 @@ int send_email(const xs_dict *mailinfo) *from = xs_dict_get(mailinfo, "from"), *to = xs_dict_get(mailinfo, "to"), *body = xs_dict_get(mailinfo, "body"); + int smtp_port = parse_port(url, NULL); - return xs_smtp_request(url, user, pass, from, to, body); + return xs_smtp_request(url, user, pass, from, to, body, smtp_port == 465 || smtp_port == 587); } diff --git a/tests/smtp.c b/tests/smtp.c new file mode 100644 index 0000000..1100a9d --- /dev/null +++ b/tests/smtp.c @@ -0,0 +1,24 @@ +/* snac - A simple, minimalistic ActivityPub instance */ +/* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ + +#define XS_IMPLEMENTATION +#include "../xs.h" +#include "../xs_curl.h" + +#define FROM "" + +int main(void) { + xs *to = xs_fmt("<%s@localhost>", getenv("USER")), + *body = xs_fmt("" + "To: %s \r\n" + "From: " FROM "\r\n" + "Subject: snac smtp test\r\n" + "\r\n" + "If you read this as an email, it probably worked!\r\n", + to); + + return xs_smtp_request("smtp://localhost", NULL, NULL, + FROM, + to, + body, 0); +} \ No newline at end of file diff --git a/utils.c b/utils.c index faf6d12..dbf798a 100644 --- a/utils.c +++ b/utils.c @@ -931,6 +931,7 @@ int parse_port(const char *url, const char **errstr) if (!(col = strchr(url, ':'))) { if (errstr) *errstr = "bad url"; + return -1; } @@ -950,13 +951,17 @@ int parse_port(const char *url, const char **errstr) if (ret != -1) return ret; - *errstr = strerror(errno); + if (errstr) + *errstr = strerror(errno); + return -1; } return tmp; } - *errstr = "unknown protocol"; + if (errstr) + *errstr = "unknown protocol"; + return -1; } diff --git a/xs_curl.h b/xs_curl.h index 886aee0..d98ac4c 100644 --- a/xs_curl.h +++ b/xs_curl.h @@ -10,7 +10,8 @@ xs_dict *xs_http_request(const char *method, const char *url, 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); + const char *from, const char *to, const xs_str *body, + int use_ssl); #ifdef XS_IMPLEMENTATION @@ -198,7 +199,8 @@ 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) + const char *from, const char *to, const xs_str *body, + int use_ssl) { CURL *curl; CURLcode res = CURLE_OK; @@ -212,11 +214,19 @@ int xs_smtp_request(const char *url, const char *user, const char *pass, curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_USERNAME, user); - curl_easy_setopt(curl, CURLOPT_PASSWORD, pass); + 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); - curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt = curl_slist_append(rcpt, to)); + + 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); @@ -224,8 +234,8 @@ int xs_smtp_request(const char *url, const char *user, const char *pass, res = curl_easy_perform(curl); - curl_slist_free_all(rcpt); curl_easy_cleanup(curl); + curl_slist_free_all(rcpt); return (int)res; } -- cgit v1.2.3 From 2ca7735779e79dbe6fe62f0111a12c145f428d8f Mon Sep 17 00:00:00 2001 From: shtrophic Date: Wed, 19 Feb 2025 08:56:14 +0100 Subject: fix ownership-problem of mailinfo --- activitypub.c | 2 +- data.c | 5 +++-- snac.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/activitypub.c b/activitypub.c index e2519e6..a91821d 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1025,7 +1025,7 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, "\n", from, email, subject); - xs *mailinfo = xs_dict_new(); + xs_dict *mailinfo = xs_dict_new(); xs_dict_append(mailinfo, "from", from); xs_dict_append(mailinfo, "to", email); xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); diff --git a/data.c b/data.c index ae85aaf..d25a5d7 100644 --- a/data.c +++ b/data.c @@ -3174,7 +3174,7 @@ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) } -static xs_dict *_new_qmsg(const char *type, const xs_val *msg, int retries) +static xs_dict *_new_qmsg(const char *type, xs_dict *msg, int retries) /* creates a queue message */ { int qrt = xs_number_get(xs_dict_get(srv_config, "queue_retry_minutes")); @@ -3276,9 +3276,10 @@ void enqueue_output_by_actor(snac *snac, const xs_dict *msg, } -void enqueue_email(const xs_dict *msg, int retries) +void enqueue_email(xs_dict *msg, int retries) /* enqueues an email message to be sent */ { + /* qmsg owns msg */ xs *qmsg = _new_qmsg("email", msg, retries); const char *ntid = xs_dict_get(qmsg, "ntid"); xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid); diff --git a/snac.h b/snac.h index 92ffb3f..545df74 100644 --- a/snac.h +++ b/snac.h @@ -274,7 +274,7 @@ void enqueue_output(snac *snac, const xs_dict *msg, const xs_str *inbox, int retries, int p_status); void enqueue_output_by_actor(snac *snac, const xs_dict *msg, const xs_str *actor, int retries); -void enqueue_email(const xs_str *msg, int retries); +void enqueue_email(xs_dict *msg, int retries); void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); void enqueue_ntfy(const xs_str *msg, const char *ntfy_server, const char *ntfy_token); void enqueue_message(snac *snac, const xs_dict *msg); -- cgit v1.2.3 From 59a34a9646e28cc9a63194ff55547de0005d0110 Mon Sep 17 00:00:00 2001 From: shtrophic Date: Thu, 20 Feb 2025 17:13:12 +0100 Subject: Revert "fix ownership-problem of mailinfo" This reverts commit 2ca7735779e79dbe6fe62f0111a12c145f428d8f. --- activitypub.c | 2 +- data.c | 5 ++--- snac.h | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/activitypub.c b/activitypub.c index a91821d..e2519e6 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1025,7 +1025,7 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, "\n", from, email, subject); - xs_dict *mailinfo = xs_dict_new(); + xs *mailinfo = xs_dict_new(); xs_dict_append(mailinfo, "from", from); xs_dict_append(mailinfo, "to", email); xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); diff --git a/data.c b/data.c index d25a5d7..ae85aaf 100644 --- a/data.c +++ b/data.c @@ -3174,7 +3174,7 @@ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) } -static xs_dict *_new_qmsg(const char *type, xs_dict *msg, int retries) +static xs_dict *_new_qmsg(const char *type, const xs_val *msg, int retries) /* creates a queue message */ { int qrt = xs_number_get(xs_dict_get(srv_config, "queue_retry_minutes")); @@ -3276,10 +3276,9 @@ void enqueue_output_by_actor(snac *snac, const xs_dict *msg, } -void enqueue_email(xs_dict *msg, int retries) +void enqueue_email(const xs_dict *msg, int retries) /* enqueues an email message to be sent */ { - /* qmsg owns msg */ xs *qmsg = _new_qmsg("email", msg, retries); const char *ntid = xs_dict_get(qmsg, "ntid"); xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid); diff --git a/snac.h b/snac.h index 545df74..92ffb3f 100644 --- a/snac.h +++ b/snac.h @@ -274,7 +274,7 @@ void enqueue_output(snac *snac, const xs_dict *msg, const xs_str *inbox, int retries, int p_status); void enqueue_output_by_actor(snac *snac, const xs_dict *msg, const xs_str *actor, int retries); -void enqueue_email(xs_dict *msg, int retries); +void enqueue_email(const xs_str *msg, int retries); void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); void enqueue_ntfy(const xs_str *msg, const char *ntfy_server, const char *ntfy_token); void enqueue_message(snac *snac, const xs_dict *msg); -- cgit v1.2.3 From b50631c0f7253e35310a14012e4fa9432aedfb5a Mon Sep 17 00:00:00 2001 From: shtrophic Date: Thu, 20 Feb 2025 17:16:16 +0100 Subject: duplicate dict instead --- data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data.c b/data.c index ae85aaf..a84cb8d 100644 --- a/data.c +++ b/data.c @@ -3279,7 +3279,7 @@ void enqueue_output_by_actor(snac *snac, const xs_dict *msg, void enqueue_email(const xs_dict *msg, int retries) /* enqueues an email message to be sent */ { - xs *qmsg = _new_qmsg("email", msg, retries); + xs *qmsg = _new_qmsg("email", xs_dup(msg), retries); const char *ntid = xs_dict_get(qmsg, "ntid"); xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid); -- cgit v1.2.3 From d19fe4157ced8789e43b7c061b11fcc7baf91c78 Mon Sep 17 00:00:00 2001 From: shtrophic Date: Thu, 20 Feb 2025 18:15:48 +0100 Subject: use xs_dict_append correctly --- activitypub.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activitypub.c b/activitypub.c index e2519e6..a209abd 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1026,9 +1026,9 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, from, email, subject); xs *mailinfo = xs_dict_new(); - xs_dict_append(mailinfo, "from", from); - xs_dict_append(mailinfo, "to", email); - xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); + mailinfo = xs_dict_append(mailinfo, "from", from); + mailinfo = xs_dict_append(mailinfo, "to", email); + mailinfo = xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); enqueue_email(mailinfo, 0); } -- cgit v1.2.3 From ff06e7e3e019f5f960bc6875d1f027e5e304ee4a Mon Sep 17 00:00:00 2001 From: shtrophic Date: Thu, 20 Feb 2025 18:25:47 +0100 Subject: duping isn't necessary as xs_vals are copied anyway (right?) --- data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data.c b/data.c index a84cb8d..ae85aaf 100644 --- a/data.c +++ b/data.c @@ -3279,7 +3279,7 @@ void enqueue_output_by_actor(snac *snac, const xs_dict *msg, void enqueue_email(const xs_dict *msg, int retries) /* enqueues an email message to be sent */ { - xs *qmsg = _new_qmsg("email", xs_dup(msg), retries); + xs *qmsg = _new_qmsg("email", msg, retries); const char *ntid = xs_dict_get(qmsg, "ntid"); xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid); -- cgit v1.2.3 From 7f936d2d1a88840209895c6091801e8c4cfdaaa1 Mon Sep 17 00:00:00 2001 From: shtrophic Date: Thu, 24 Apr 2025 12:18:23 +0200 Subject: default to `smtp://localhost` --- activitypub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activitypub.c b/activitypub.c index 061d1f8..df68151 100644 --- a/activitypub.c +++ b/activitypub.c @@ -2571,7 +2571,7 @@ int send_email(const xs_dict *mailinfo) { const xs_dict *smtp_cfg = xs_dict_get(srv_config, "email_notifications"); const char - *url = xs_dict_get(smtp_cfg, "url"), + *url = xs_dict_get_def(smtp_cfg, "url", "smtp://localhost"), *user = xs_dict_get(smtp_cfg, "username"), *pass = xs_dict_get(smtp_cfg, "password"), *from = xs_dict_get(mailinfo, "from"), -- cgit v1.2.3