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 4c22c25..061d1f8 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 */ |
| @@ -2563,32 +2566,20 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2563 | } | 2566 | } |
| 2564 | 2567 | ||
| 2565 | 2568 | ||
| 2566 | int send_email(const char *msg) | 2569 | int send_email(const xs_dict *mailinfo) |
| 2567 | /* invoke sendmail with email headers and body in msg */ | 2570 | /* invoke curl */ |
| 2568 | { | 2571 | { |
| 2569 | FILE *f; | 2572 | const xs_dict *smtp_cfg = xs_dict_get(srv_config, "email_notifications"); |
| 2570 | int status; | 2573 | const char |
| 2571 | int fds[2]; | 2574 | *url = xs_dict_get(smtp_cfg, "url"), |
| 2572 | pid_t pid; | 2575 | *user = xs_dict_get(smtp_cfg, "username"), |
| 2573 | if (pipe(fds) == -1) return -1; | 2576 | *pass = xs_dict_get(smtp_cfg, "password"), |
| 2574 | pid = vfork(); | 2577 | *from = xs_dict_get(mailinfo, "from"), |
| 2575 | if (pid == -1) return -1; | 2578 | *to = xs_dict_get(mailinfo, "to"), |
| 2576 | else if (pid == 0) { | 2579 | *body = xs_dict_get(mailinfo, "body"); |
| 2577 | dup2(fds[0], 0); | 2580 | int smtp_port = parse_port(url, NULL); |
| 2578 | close(fds[0]); | 2581 | |
| 2579 | close(fds[1]); | 2582 | return xs_smtp_request(url, user, pass, from, to, body, smtp_port == 465 || smtp_port == 587); |
| 2580 | execl("/usr/sbin/sendmail", "sendmail", "-t", (char *) NULL); | ||
| 2581 | _exit(1); | ||
| 2582 | } | ||
| 2583 | close(fds[0]); | ||
| 2584 | if ((f = fdopen(fds[1], "w")) == NULL) { | ||
| 2585 | close(fds[1]); | ||
| 2586 | return -1; | ||
| 2587 | } | ||
| 2588 | fprintf(f, "%s\n", msg); | ||
| 2589 | fclose(f); | ||
| 2590 | if (waitpid(pid, &status, 0) == -1) return -1; | ||
| 2591 | return status; | ||
| 2592 | } | 2583 | } |
| 2593 | 2584 | ||
| 2594 | 2585 | ||
| @@ -2861,7 +2852,7 @@ void process_queue_item(xs_dict *q_item) | |||
| 2861 | else | 2852 | else |
| 2862 | if (strcmp(type, "email") == 0) { | 2853 | if (strcmp(type, "email") == 0) { |
| 2863 | /* send this email */ | 2854 | /* send this email */ |
| 2864 | const xs_str *msg = xs_dict_get(q_item, "message"); | 2855 | const xs_dict *msg = xs_dict_get(q_item, "message"); |
| 2865 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); | 2856 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); |
| 2866 | 2857 | ||
| 2867 | if (!send_email(msg)) | 2858 | if (!send_email(msg)) |