summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/activitypub.c b/activitypub.c
index a73b107..97fdc7b 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -13,6 +13,8 @@
13 13
14#include "snac.h" 14#include "snac.h"
15 15
16#include <sys/wait.h>
17
16const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public"; 18const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public";
17 19
18int activitypub_request(snac *snac, char *url, d_char **data) 20int activitypub_request(snac *snac, char *url, d_char **data)
@@ -999,6 +1001,35 @@ int process_message(snac *snac, char *msg, char *req)
999} 1001}
1000 1002
1001 1003
1004int send_email(char *msg)
1005/* invoke sendmail with email headers and body in msg */
1006{
1007 FILE *f;
1008 int status;
1009 int fds[2];
1010 pid_t pid;
1011 if (pipe(fds) == -1) return -1;
1012 pid = vfork();
1013 if (pid == -1) return -1;
1014 else if (pid == 0) {
1015 dup2(fds[0], 0);
1016 close(fds[0]);
1017 close(fds[1]);
1018 execl("/usr/sbin/sendmail", "sendmail", "-t", (char *) NULL);
1019 _exit(1);
1020 }
1021 close(fds[0]);
1022 if ((f = fdopen(fds[1], "w")) == NULL) {
1023 close(fds[1]);
1024 return -1;
1025 }
1026 fprintf(f, "%s\n", msg);
1027 fclose(f);
1028 if (waitpid(pid, &status, 0) == -1) return -1;
1029 return status;
1030}
1031
1032
1002void process_queue(snac *snac) 1033void process_queue(snac *snac)
1003/* processes the queue */ 1034/* processes the queue */
1004{ 1035{
@@ -1085,17 +1116,8 @@ void process_queue(snac *snac)
1085 /* send this email */ 1116 /* send this email */
1086 char *msg = xs_dict_get(q_item, "message"); 1117 char *msg = xs_dict_get(q_item, "message");
1087 int retries = xs_number_get(xs_dict_get(q_item, "retries")); 1118 int retries = xs_number_get(xs_dict_get(q_item, "retries"));
1088 FILE *f;
1089 int ok = 0;
1090
1091 if ((f = popen("/usr/sbin/sendmail -t", "w")) != NULL) {
1092 fprintf(f, "%s\n", msg);
1093
1094 if (pclose(f) != -1)
1095 ok = 1;
1096 }
1097 1119
1098 if (ok) 1120 if (!send_email(msg))
1099 snac_debug(snac, 1, xs_fmt("email message sent")); 1121 snac_debug(snac, 1, xs_fmt("email message sent"));
1100 else { 1122 else {
1101 if (retries > queue_retry_max) 1123 if (retries > queue_retry_max)