summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2022-10-21 10:26:45 +0200
committerGravatar default2022-10-21 10:26:45 +0200
commit6e470440f9971d0a2b63286215e2b019a8a7f802 (patch)
tree702daa4bbd52cc01a1a8d6742924fcfeafaf94b6
parentUpdated RELEASE_NOTES. (diff)
downloadpenes-snac2-6e470440f9971d0a2b63286215e2b019a8a7f802.tar.gz
penes-snac2-6e470440f9971d0a2b63286215e2b019a8a7f802.tar.xz
penes-snac2-6e470440f9971d0a2b63286215e2b019a8a7f802.zip
Rewritten notify() to write the message in bulk.
This was meant to avoid some 32 EPIPE from sendmail, but it's still happening.
-rw-r--r--activitypub.c66
1 files changed, 43 insertions, 23 deletions
diff --git a/activitypub.c b/activitypub.c
index 6aaabc9..f154515 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -650,30 +650,33 @@ void notify(snac *snac, char *type, char *utype, char *actor, char *msg)
650 650
651 snac_debug(snac, 1, xs_fmt("notify(%s, %s, %s)", type, utype, actor)); 651 snac_debug(snac, 1, xs_fmt("notify(%s, %s, %s)", type, utype, actor));
652 652
653 /* now write */ 653 /* prepare message */
654 FILE *f;
655
656 if ((f = popen("/usr/sbin/sendmail -t", "w")) == NULL) {
657 snac_log(snac, xs_fmt("cannot pipe to sendmail (errno: %d)", errno));
658 return;
659 }
660 654
661 xs *subject = xs_fmt("snac notify for @%s@%s", 655 xs *subject = xs_fmt("snac notify for @%s@%s",
662 xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")); 656 xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host"));
663 xs *from = xs_fmt("snac-daemon@%s (snac daemon)", xs_dict_get(srv_config, "host")); 657 xs *from = xs_fmt("snac-daemon@%s (snac daemon)", xs_dict_get(srv_config, "host"));
658 xs *header = xs_fmt(
659 "From: %s\n"
660 "To: %s\n"
661 "Subject: %s\n"
662 "\n",
663 from, email, subject);
664
665 xs *body = xs_str_new(header);
666
667 if (strcmp(utype, "(null)") != 0) {
668 xs *s1 = xs_fmt("Type : %s + %s\n", type, utype);
669 body = xs_str_cat(body, s1);
670 }
671 else {
672 xs *s1 = xs_fmt("Type : %s\n", type);
673 body = xs_str_cat(body, s1);
674 }
664 675
665 fprintf(f, "From: %s\n", from); 676 {
666 fprintf(f, "To: %s\n", email); 677 xs *s1 = xs_fmt("Actor : %s\n", actor);
667 fprintf(f, "Subject: %s\n", subject); 678 body = xs_str_cat(body, s1);
668 fprintf(f, "\n"); 679 }
669
670 fprintf(f, "Type : %s", type);
671
672 if (strcmp(utype, "(null)") != 0)
673 fprintf(f, " + %s", utype);
674 fprintf(f, "\n");
675
676 fprintf(f, "Actor : %s\n", actor);
677 680
678 if (strcmp(type, "Like") == 0 || strcmp(type, "Announce") == 0) { 681 if (strcmp(type, "Like") == 0 || strcmp(type, "Announce") == 0) {
679 /* there is a related object: add it */ 682 /* there is a related object: add it */
@@ -683,13 +686,30 @@ void notify(snac *snac, char *type, char *utype, char *actor, char *msg)
683 if (xs_type(object) == XSTYPE_DICT) 686 if (xs_type(object) == XSTYPE_DICT)
684 object = xs_dict_get(object, "id"); 687 object = xs_dict_get(object, "id");
685 688
686 if (!xs_is_null(object)) 689 if (!xs_is_null(object)) {
687 fprintf(f, "Object: %s\n", object); 690 xs *s1 = xs_fmt("Object: %s\n", object);
691 body = xs_str_cat(body, s1);
692 }
688 } 693 }
689 } 694 }
690 695
691 if (fclose(f) == EOF) 696 /* now write */
692 snac_log(snac, xs_fmt("fclose error in pipe to sendmail (errno: %d)", errno)); 697 FILE *f;
698
699 if ((f = popen("/usr/sbin/sendmail -t", "w")) != NULL) {
700 fprintf(f, "%s\n", body);
701
702 if (fclose(f) == EOF) {
703 snac_log(snac, xs_fmt("fclose error in pipe to sendmail (errno: %d)", errno));
704
705 if ((f = fopen("/tmp/dead-letter", "w")) != NULL) {
706 fprintf(f, "%s\n", body);
707 fclose(f);
708 }
709 }
710 }
711 else
712 snac_log(snac, xs_fmt("cannot pipe to sendmail (errno: %d)", errno));
693} 713}
694 714
695 715