From 62f91f8a64498d5dc50419f8db979de2e33229bc Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 28 Nov 2020 14:04:46 -0500 Subject: [PATCH] Send a hash of an auto-response to the use table. This keeps us from spamming the same correspondent with an auto-reply over and over. --- citadel/modules/inboxrules/serv_inboxrules.c | 69 +++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/citadel/modules/inboxrules/serv_inboxrules.c b/citadel/modules/inboxrules/serv_inboxrules.c index 17ea9713a..720d63fa5 100644 --- a/citadel/modules/inboxrules/serv_inboxrules.c +++ b/citadel/modules/inboxrules/serv_inboxrules.c @@ -441,7 +441,7 @@ void inbox_do_vacation(struct irule *rule, struct CtdlMessage *msg) { rule->autoreply_message ); - // If we can't determine who sent the message, reject silently. + // If we can't determine who sent the message, no auto-reply can be sent. char *sender; if (!IsEmptyStr(msg->cm_fields[eMessagePath])) { sender = msg->cm_fields[eMessagePath]; @@ -453,38 +453,45 @@ void inbox_do_vacation(struct irule *rule, struct CtdlMessage *msg) { return; } - - - // FIXME use the S_USETABLE to avoid sending the same correspondent a vacation message repeatedly. - - - - - // Assemble the reject message. - char *reject_text = malloc(strlen(rule->autoreply_message) + 1024); - if (reject_text == NULL) { - return; - } - sprintf(reject_text, - "Content-type: text/plain\n" - "\n" - "%s\n" - "\n" - , - rule->autoreply_message + // Avoid repeatedly sending auto-replies to the same correspondent over and over again by creating + // a hash of the user, correspondent, and reply text, and hitting the S_USETABLE database. + StrBuf *u = NewStrBuf(); + StrBufPrintf(u, "vacation/%x/%x/%x", + HashLittle(sender, strlen(sender)), + HashLittle(msg->cm_fields[eenVelopeTo], msg->cm_lengths[eenVelopeTo]), + HashLittle(rule->autoreply_message, strlen(rule->autoreply_message)) ); + int already_seen = CheckIfAlreadySeen(u); + FreeStrBuf(&u); + + if (!already_seen) { + // Assemble the auto-reply message. + StrBuf *reject_text = NewStrBuf(); + if (reject_text == NULL) { + return; + } - // Deliver the message - quickie_message( - NULL, - msg->cm_fields[eenVelopeTo], - sender, - NULL, - reject_text, - FMT_RFC822, - "Delivery status notification" - ); - free(reject_text); + StrBufPrintf(reject_text, + "Content-type: text/plain\n" + "\n" + "%s\n" + "\n" + , + rule->autoreply_message + ); + + // Deliver the auto-reply. + quickie_message( + NULL, + msg->cm_fields[eenVelopeTo], + sender, + NULL, + ChrPtr(reject_text), + FMT_RFC822, + "Delivery status notification" + ); + FreeStrBuf(&reject_text); + } } -- 2.30.2