diff options
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/activitypub.c b/activitypub.c index 24bf04e..5b2d981 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -626,8 +626,6 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char | |||
| 626 | } | 626 | } |
| 627 | 627 | ||
| 628 | 628 | ||
| 629 | |||
| 630 | |||
| 631 | void notify(snac *snac, char *type, char *utype, char *actor, char *msg) | 629 | void notify(snac *snac, char *type, char *utype, char *actor, char *msg) |
| 632 | /* notifies the user of relevant events */ | 630 | /* notifies the user of relevant events */ |
| 633 | { | 631 | { |
| @@ -670,7 +668,7 @@ void notify(snac *snac, char *type, char *utype, char *actor, char *msg) | |||
| 670 | 668 | ||
| 671 | xs *subject = xs_fmt("snac notify for @%s@%s", | 669 | xs *subject = xs_fmt("snac notify for @%s@%s", |
| 672 | xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); | 670 | xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); |
| 673 | xs *from = xs_fmt("snac-daemon@%s (snac daemon)", xs_dict_get(srv_config, "host")); | 671 | xs *from = xs_fmt("snac-daemon <snac-daemon@%s>", xs_dict_get(srv_config, "host")); |
| 674 | xs *header = xs_fmt( | 672 | xs *header = xs_fmt( |
| 675 | "From: %s\n" | 673 | "From: %s\n" |
| 676 | "To: %s\n" | 674 | "To: %s\n" |
| @@ -699,23 +697,7 @@ void notify(snac *snac, char *type, char *utype, char *actor, char *msg) | |||
| 699 | body = xs_str_cat(body, s1); | 697 | body = xs_str_cat(body, s1); |
| 700 | } | 698 | } |
| 701 | 699 | ||
| 702 | /* now write */ | 700 | enqueue_email(snac, body, 0); |
| 703 | FILE *f; | ||
| 704 | |||
| 705 | if ((f = popen("/usr/sbin/sendmail -t", "w")) != NULL) { | ||
| 706 | fprintf(f, "%s\n", body); | ||
| 707 | |||
| 708 | if (fclose(f) == EOF) { | ||
| 709 | snac_log(snac, xs_fmt("fclose error in pipe to sendmail (errno: %d)", errno)); | ||
| 710 | |||
| 711 | if ((f = fopen("/tmp/dead-letter", "w")) != NULL) { | ||
| 712 | fprintf(f, "%s\n", body); | ||
| 713 | fclose(f); | ||
| 714 | } | ||
| 715 | } | ||
| 716 | } | ||
| 717 | else | ||
| 718 | snac_log(snac, xs_fmt("cannot pipe to sendmail (errno: %d)", errno)); | ||
| 719 | } | 701 | } |
| 720 | 702 | ||
| 721 | 703 | ||
| @@ -958,6 +940,35 @@ void process_queue(snac *snac) | |||
| 958 | } | 940 | } |
| 959 | } | 941 | } |
| 960 | } | 942 | } |
| 943 | else | ||
| 944 | if (strcmp(type, "email") == 0) { | ||
| 945 | /* send this email */ | ||
| 946 | char *msg = xs_dict_get(q_item, "message"); | ||
| 947 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); | ||
| 948 | FILE *f; | ||
| 949 | int ok = 0; | ||
| 950 | |||
| 951 | if ((f = popen("/usr/sbin/sendmail -t", "w")) != NULL) { | ||
| 952 | fprintf(f, "%s\n", msg); | ||
| 953 | |||
| 954 | if (fclose(f) != EOF) | ||
| 955 | ok = 1; | ||
| 956 | } | ||
| 957 | |||
| 958 | if (ok) | ||
| 959 | snac_debug(snac, 1, xs_fmt("email message sent")); | ||
| 960 | else { | ||
| 961 | if (retries > queue_retry_max) | ||
| 962 | snac_log(snac, xs_fmt("process_queue email giving up (errno: %d)", errno)); | ||
| 963 | else { | ||
| 964 | /* requeue */ | ||
| 965 | snac_log(snac, xs_fmt( | ||
| 966 | "process_queue email requeue %d (errno: %d)", retries + 1, errno)); | ||
| 967 | |||
| 968 | enqueue_email(snac, msg, retries + 1); | ||
| 969 | } | ||
| 970 | } | ||
| 971 | } | ||
| 961 | } | 972 | } |
| 962 | } | 973 | } |
| 963 | 974 | ||
| @@ -973,6 +984,8 @@ void post(snac *snac, char *msg) | |||
| 973 | enqueue_output(snac, msg, v, 0); | 984 | enqueue_output(snac, msg, v, 0); |
| 974 | } | 985 | } |
| 975 | } | 986 | } |
| 987 | |||
| 988 | |||
| 976 | /** HTTP handlers */ | 989 | /** HTTP handlers */ |
| 977 | 990 | ||
| 978 | int activitypub_get_handler(d_char *req, char *q_path, | 991 | int activitypub_get_handler(d_char *req, char *q_path, |