diff options
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 48 |
1 files changed, 19 insertions, 29 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, | |||
| 962 | 962 | ||
| 963 | xs *subject = xs_fmt("snac notify for @%s@%s", | 963 | xs *subject = xs_fmt("snac notify for @%s@%s", |
| 964 | xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); | 964 | xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); |
| 965 | xs *from = xs_fmt("snac-daemon <snac-daemon@%s>", xs_dict_get(srv_config, "host")); | 965 | xs *from = xs_fmt("<snac-daemon@%s>", xs_dict_get(srv_config, "host")); |
| 966 | xs *header = xs_fmt( | 966 | xs *header = xs_fmt( |
| 967 | "From: %s\n" | 967 | "From: snac-daemon %s\n" |
| 968 | "To: %s\n" | 968 | "To: %s\n" |
| 969 | "Subject: %s\n" | 969 | "Subject: %s\n" |
| 970 | "\n", | 970 | "\n", |
| 971 | from, email, subject); | 971 | from, email, subject); |
| 972 | 972 | ||
| 973 | xs *email_body = xs_fmt("%s%s", header, body); | 973 | xs_dict *mailinfo = xs_dict_new(); |
| 974 | xs_dict_append(mailinfo, "from", from); | ||
| 975 | xs_dict_append(mailinfo, "to", email); | ||
| 976 | xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); | ||
| 974 | 977 | ||
| 975 | enqueue_email(email_body, 0); | 978 | enqueue_email(mailinfo, 0); |
| 976 | } | 979 | } |
| 977 | 980 | ||
| 978 | /* telegram */ | 981 | /* telegram */ |
| @@ -2461,32 +2464,19 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2461 | } | 2464 | } |
| 2462 | 2465 | ||
| 2463 | 2466 | ||
| 2464 | int send_email(const char *msg) | 2467 | int send_email(const xs_dict *mailinfo) |
| 2465 | /* invoke sendmail with email headers and body in msg */ | 2468 | /* invoke sendmail with email headers and body in msg */ |
| 2466 | { | 2469 | { |
| 2467 | FILE *f; | 2470 | const xs_dict *smtp_cfg = xs_dict_get(srv_config, "smtp"); |
| 2468 | int status; | 2471 | const char |
| 2469 | int fds[2]; | 2472 | *url = xs_dict_get(smtp_cfg, "url"), |
| 2470 | pid_t pid; | 2473 | *user = xs_dict_get(smtp_cfg, "username"), |
| 2471 | if (pipe(fds) == -1) return -1; | 2474 | *pass = xs_dict_get(smtp_cfg, "password"), |
| 2472 | pid = vfork(); | 2475 | *from = xs_dict_get(mailinfo, "from"), |
| 2473 | if (pid == -1) return -1; | 2476 | *to = xs_dict_get(mailinfo, "to"), |
| 2474 | else if (pid == 0) { | 2477 | *body = xs_dict_get(mailinfo, "body"); |
| 2475 | dup2(fds[0], 0); | 2478 | |
| 2476 | close(fds[0]); | 2479 | return xs_smtp_request(url, user, pass, from, to, body); |
| 2477 | close(fds[1]); | ||
| 2478 | execl("/usr/sbin/sendmail", "sendmail", "-t", (char *) NULL); | ||
| 2479 | _exit(1); | ||
| 2480 | } | ||
| 2481 | close(fds[0]); | ||
| 2482 | if ((f = fdopen(fds[1], "w")) == NULL) { | ||
| 2483 | close(fds[1]); | ||
| 2484 | return -1; | ||
| 2485 | } | ||
| 2486 | fprintf(f, "%s\n", msg); | ||
| 2487 | fclose(f); | ||
| 2488 | if (waitpid(pid, &status, 0) == -1) return -1; | ||
| 2489 | return status; | ||
| 2490 | } | 2480 | } |
| 2491 | 2481 | ||
| 2492 | 2482 | ||
| @@ -2749,7 +2739,7 @@ void process_queue_item(xs_dict *q_item) | |||
| 2749 | else | 2739 | else |
| 2750 | if (strcmp(type, "email") == 0) { | 2740 | if (strcmp(type, "email") == 0) { |
| 2751 | /* send this email */ | 2741 | /* send this email */ |
| 2752 | const xs_str *msg = xs_dict_get(q_item, "message"); | 2742 | const xs_dict *msg = xs_dict_get(q_item, "message"); |
| 2753 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); | 2743 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); |
| 2754 | 2744 | ||
| 2755 | if (!send_email(msg)) | 2745 | if (!send_email(msg)) |