commit da0ce17
grunfink
·
2025-04-28 03:15:31 +0000 UTC
parent 2a353d2
Email notifications are sent the old way if 'spawn_sendmail' is set to true.
1 files changed,
+28,
-0
+28,
-0
1@@ -2570,6 +2570,34 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
2 int send_email(const xs_dict *mailinfo)
3 /* invoke curl */
4 {
5+ if (xs_is_true(xs_dict_get(srv_config, "spawn_sendmail"))) {
6+ const char *msg = xs_dict_get(mailinfo, "body");
7+ FILE *f;
8+ int status;
9+ int fds[2];
10+ pid_t pid;
11+
12+ if (pipe(fds) == -1) return -1;
13+ pid = vfork();
14+ if (pid == -1) return -1;
15+ else if (pid == 0) {
16+ dup2(fds[0], 0);
17+ close(fds[0]);
18+ close(fds[1]);
19+ execl("/usr/sbin/sendmail", "sendmail", "-t", (char *) NULL);
20+ _exit(1);
21+ }
22+ close(fds[0]);
23+ if ((f = fdopen(fds[1], "w")) == NULL) {
24+ close(fds[1]);
25+ return -1;
26+ }
27+ fprintf(f, "%s\n", msg);
28+ fclose(f);
29+ if (waitpid(pid, &status, 0) == -1) return -1;
30+ return status;
31+ }
32+
33 const char
34 *url = xs_dict_get(srv_config, "smtp_url"),
35 *user = xs_dict_get(srv_config, "smtp_username"),