diff options
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/activitypub.c b/activitypub.c index 104110d..e2519e6 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1017,17 +1017,20 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, | |||
| 1017 | 1017 | ||
| 1018 | xs *subject = xs_fmt("snac notify for @%s@%s", | 1018 | xs *subject = xs_fmt("snac notify for @%s@%s", |
| 1019 | xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); | 1019 | xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); |
| 1020 | xs *from = xs_fmt("snac-daemon <snac-daemon@%s>", xs_dict_get(srv_config, "host")); | 1020 | xs *from = xs_fmt("<snac-daemon@%s>", xs_dict_get(srv_config, "host")); |
| 1021 | xs *header = xs_fmt( | 1021 | xs *header = xs_fmt( |
| 1022 | "From: %s\n" | 1022 | "From: snac-daemon %s\n" |
| 1023 | "To: %s\n" | 1023 | "To: %s\n" |
| 1024 | "Subject: %s\n" | 1024 | "Subject: %s\n" |
| 1025 | "\n", | 1025 | "\n", |
| 1026 | from, email, subject); | 1026 | from, email, subject); |
| 1027 | 1027 | ||
| 1028 | xs *email_body = xs_fmt("%s%s", header, body); | 1028 | xs *mailinfo = xs_dict_new(); |
| 1029 | xs_dict_append(mailinfo, "from", from); | ||
| 1030 | xs_dict_append(mailinfo, "to", email); | ||
| 1031 | xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); | ||
| 1029 | 1032 | ||
| 1030 | enqueue_email(email_body, 0); | 1033 | enqueue_email(mailinfo, 0); |
| 1031 | } | 1034 | } |
| 1032 | 1035 | ||
| 1033 | /* telegram */ | 1036 | /* telegram */ |
| @@ -2524,32 +2527,20 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2524 | } | 2527 | } |
| 2525 | 2528 | ||
| 2526 | 2529 | ||
| 2527 | int send_email(const char *msg) | 2530 | int send_email(const xs_dict *mailinfo) |
| 2528 | /* invoke sendmail with email headers and body in msg */ | 2531 | /* invoke curl */ |
| 2529 | { | 2532 | { |
| 2530 | FILE *f; | 2533 | const xs_dict *smtp_cfg = xs_dict_get(srv_config, "email_notifications"); |
| 2531 | int status; | 2534 | const char |
| 2532 | int fds[2]; | 2535 | *url = xs_dict_get(smtp_cfg, "url"), |
| 2533 | pid_t pid; | 2536 | *user = xs_dict_get(smtp_cfg, "username"), |
| 2534 | if (pipe(fds) == -1) return -1; | 2537 | *pass = xs_dict_get(smtp_cfg, "password"), |
| 2535 | pid = vfork(); | 2538 | *from = xs_dict_get(mailinfo, "from"), |
| 2536 | if (pid == -1) return -1; | 2539 | *to = xs_dict_get(mailinfo, "to"), |
| 2537 | else if (pid == 0) { | 2540 | *body = xs_dict_get(mailinfo, "body"); |
| 2538 | dup2(fds[0], 0); | 2541 | int smtp_port = parse_port(url, NULL); |
| 2539 | close(fds[0]); | 2542 | |
| 2540 | close(fds[1]); | 2543 | return xs_smtp_request(url, user, pass, from, to, body, smtp_port == 465 || smtp_port == 587); |
| 2541 | execl("/usr/sbin/sendmail", "sendmail", "-t", (char *) NULL); | ||
| 2542 | _exit(1); | ||
| 2543 | } | ||
| 2544 | close(fds[0]); | ||
| 2545 | if ((f = fdopen(fds[1], "w")) == NULL) { | ||
| 2546 | close(fds[1]); | ||
| 2547 | return -1; | ||
| 2548 | } | ||
| 2549 | fprintf(f, "%s\n", msg); | ||
| 2550 | fclose(f); | ||
| 2551 | if (waitpid(pid, &status, 0) == -1) return -1; | ||
| 2552 | return status; | ||
| 2553 | } | 2544 | } |
| 2554 | 2545 | ||
| 2555 | 2546 | ||
| @@ -2820,7 +2811,7 @@ void process_queue_item(xs_dict *q_item) | |||
| 2820 | else | 2811 | else |
| 2821 | if (strcmp(type, "email") == 0) { | 2812 | if (strcmp(type, "email") == 0) { |
| 2822 | /* send this email */ | 2813 | /* send this email */ |
| 2823 | const xs_str *msg = xs_dict_get(q_item, "message"); | 2814 | const xs_dict *msg = xs_dict_get(q_item, "message"); |
| 2824 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); | 2815 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); |
| 2825 | 2816 | ||
| 2826 | if (!send_email(msg)) | 2817 | if (!send_email(msg)) |