From b6845a37c842070f70b8fbb98fb49c5e2cfc9644 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 16 Jul 2020 18:03:49 -0400 Subject: [PATCH] Handling is now to the point where user accounts requiring potential inbox processing are brought to the handler's attention. --- citadel/modules/inboxrules/serv_inboxrules.c | 86 +++++++++++++++++++- citadel/msgbase.c | 5 +- 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/citadel/modules/inboxrules/serv_inboxrules.c b/citadel/modules/inboxrules/serv_inboxrules.c index 30feea856..a54007f8a 100644 --- a/citadel/modules/inboxrules/serv_inboxrules.c +++ b/citadel/modules/inboxrules/serv_inboxrules.c @@ -841,12 +841,91 @@ BAIL: rewrite_ctdl_sieve_config(&u, (u.lastproc > orig_lastproc) ) ; } +#endif -#endif +/* + * A user account is identified as requring inbox processing. + * Do it. + */ +void do_inbox_processing_for_user(long usernum) { + if (CtdlGetUserByNumber(&CC->user, usernum) == 0) { + TRACE; + if (CC->user.msgnum_inboxrules <= 0) { + syslog(LOG_DEBUG, "NO RULEZ for %s", CC->user.fullname); + return; // this user has no inbox rules + } + syslog(LOG_DEBUG, "RULEZ for %s", CC->user.fullname); + } +} + + +/* + * Here is an array of users (by number) who have received messages in their inbox and may require processing. +*/ +long *users_requiring_inbox_processing = NULL; +int num_urip = 0; +int num_urip_alloc = 0; + + +/* + * Perform inbox processing for all rooms which require it + */ +void perform_inbox_processing(void) { + if (num_urip == 0) { + return; // no action required + } + + for (int i=0; iQRname[11], MAILROOM)) { + long usernum = atol(room->QRname); + if (usernum > 0) { + + // first check to see if this user is already on the list + if (num_urip > 0) { + for (int i=0; i<=num_urip; ++i) { + if (users_requiring_inbox_processing[i] == usernum) { // already on the list! + return(0); + } + } + } + + // make room if we need to + if (num_urip_alloc == 0) { + num_urip_alloc = 100; + users_requiring_inbox_processing = malloc(sizeof(long) * num_urip_alloc); + } + else if (num_urip >= num_urip_alloc) { + num_urip_alloc += 100; + users_requiring_inbox_processing = realloc(users_requiring_inbox_processing, (sizeof(long) * num_urip_alloc)); + } + + // now add the user to the list + users_requiring_inbox_processing[num_urip++] = usernum; + } + } + + // No errors are possible from this function. + return(0); +} /* @@ -946,11 +1025,10 @@ CTDL_MODULE_INIT(sieve) { if (!threading) { - // ctdl_sieve_init(); CtdlRegisterProtoHook(cmd_gibr, "GIBR", "Get InBox Rules"); CtdlRegisterProtoHook(cmd_pibr, "PIBR", "Put InBox Rules"); - // CtdlRegisterSessionHook(perform_sieve_processing, EVT_HOUSE, PRIO_HOUSE + 10); - // CtdlRegisterCleanupHook(cleanup_sieve); + CtdlRegisterRoomHook(serv_inboxrules_roomhook); + CtdlRegisterSessionHook(perform_inbox_processing, EVT_HOUSE, PRIO_HOUSE + 10); } /* return our module name for the log */ diff --git a/citadel/msgbase.c b/citadel/msgbase.c index d120ca410..0b4ed5c59 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -2419,7 +2419,10 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms } /* Submit this room for processing by hooks */ - PerformRoomHooks(&CC->room); + int total_roomhook_errors = PerformRoomHooks(&CC->room); + if (total_roomhook_errors) { + syslog(LOG_WARNING, "msgbase: room hooks returned %d errors", total_roomhook_errors); + } /* Go back to the room we were in before we wandered here... */ CtdlGetRoom(&CC->room, hold_rm); -- 2.30.2