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 c9f700f..aa679a0 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1044,17 +1044,20 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, | |||
| 1044 | 1044 | ||
| 1045 | xs *subject = xs_fmt("snac notify for @%s@%s", | 1045 | xs *subject = xs_fmt("snac notify for @%s@%s", |
| 1046 | xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); | 1046 | xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); |
| 1047 | xs *from = xs_fmt("snac-daemon <snac-daemon@%s>", xs_dict_get(srv_config, "host")); | 1047 | xs *from = xs_fmt("<snac-daemon@%s>", xs_dict_get(srv_config, "host")); |
| 1048 | xs *header = xs_fmt( | 1048 | xs *header = xs_fmt( |
| 1049 | "From: %s\n" | 1049 | "From: snac-daemon %s\n" |
| 1050 | "To: %s\n" | 1050 | "To: %s\n" |
| 1051 | "Subject: %s\n" | 1051 | "Subject: %s\n" |
| 1052 | "\n", | 1052 | "\n", |
| 1053 | from, email, subject); | 1053 | from, email, subject); |
| 1054 | 1054 | ||
| 1055 | xs *email_body = xs_fmt("%s%s", header, body); | 1055 | xs *mailinfo = xs_dict_new(); |
| 1056 | mailinfo = xs_dict_append(mailinfo, "from", from); | ||
| 1057 | mailinfo = xs_dict_append(mailinfo, "to", email); | ||
| 1058 | mailinfo = xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); | ||
| 1056 | 1059 | ||
| 1057 | enqueue_email(email_body, 0); | 1060 | enqueue_email(mailinfo, 0); |
| 1058 | } | 1061 | } |
| 1059 | 1062 | ||
| 1060 | /* telegram */ | 1063 | /* telegram */ |
| @@ -2556,32 +2559,20 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2556 | } | 2559 | } |
| 2557 | 2560 | ||
| 2558 | 2561 | ||
| 2559 | int send_email(const char *msg) | 2562 | int send_email(const xs_dict *mailinfo) |
| 2560 | /* invoke sendmail with email headers and body in msg */ | 2563 | /* invoke curl */ |
| 2561 | { | 2564 | { |
| 2562 | FILE *f; | 2565 | const xs_dict *smtp_cfg = xs_dict_get(srv_config, "email_notifications"); |
| 2563 | int status; | 2566 | const char |
| 2564 | int fds[2]; | 2567 | *url = xs_dict_get(smtp_cfg, "url"), |
| 2565 | pid_t pid; | 2568 | *user = xs_dict_get(smtp_cfg, "username"), |
| 2566 | if (pipe(fds) == -1) return -1; | 2569 | *pass = xs_dict_get(smtp_cfg, "password"), |
| 2567 | pid = vfork(); | 2570 | *from = xs_dict_get(mailinfo, "from"), |
| 2568 | if (pid == -1) return -1; | 2571 | *to = xs_dict_get(mailinfo, "to"), |
| 2569 | else if (pid == 0) { | 2572 | *body = xs_dict_get(mailinfo, "body"); |
| 2570 | dup2(fds[0], 0); | 2573 | int smtp_port = parse_port(url, NULL); |
| 2571 | close(fds[0]); | 2574 | |
| 2572 | close(fds[1]); | 2575 | return xs_smtp_request(url, user, pass, from, to, body, smtp_port == 465 || smtp_port == 587); |
| 2573 | execl("/usr/sbin/sendmail", "sendmail", "-t", (char *) NULL); | ||
| 2574 | _exit(1); | ||
| 2575 | } | ||
| 2576 | close(fds[0]); | ||
| 2577 | if ((f = fdopen(fds[1], "w")) == NULL) { | ||
| 2578 | close(fds[1]); | ||
| 2579 | return -1; | ||
| 2580 | } | ||
| 2581 | fprintf(f, "%s\n", msg); | ||
| 2582 | fclose(f); | ||
| 2583 | if (waitpid(pid, &status, 0) == -1) return -1; | ||
| 2584 | return status; | ||
| 2585 | } | 2576 | } |
| 2586 | 2577 | ||
| 2587 | 2578 | ||
| @@ -2852,7 +2843,7 @@ void process_queue_item(xs_dict *q_item) | |||
| 2852 | else | 2843 | else |
| 2853 | if (strcmp(type, "email") == 0) { | 2844 | if (strcmp(type, "email") == 0) { |
| 2854 | /* send this email */ | 2845 | /* send this email */ |
| 2855 | const xs_str *msg = xs_dict_get(q_item, "message"); | 2846 | const xs_dict *msg = xs_dict_get(q_item, "message"); |
| 2856 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); | 2847 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); |
| 2857 | 2848 | ||
| 2858 | if (!send_email(msg)) | 2849 | if (!send_email(msg)) |