AmendHub

Download:

jcs

/

subtext

/

amendments

/

427

mail: Add mail pruning


jcs made amendment 427 about 1 year ago
--- mail.c Wed Mar 15 14:10:16 2023 +++ mail.c Wed Mar 15 15:14:57 2023 @@ -956,3 +956,46 @@ done: xfree(&to); return ret; } + +void +mail_prune(short days) +{ + struct mail_message msg; + size_t n, nids, size, deleted, delta; + unsigned long secs, *ids = NULL; + + if (days < 1) + return; + + secs = (60UL * 60UL * 24UL * (unsigned long)days); + + logger_printf("[db] Pruning mail older than %d days", days); + + nids = bile_ids_by_type(db->mail_bile, MAIL_SPOOL_MESSAGE_RTYPE, + &ids); + if (nids == 0) + return; + + size = offsetof(struct mail_message, time) + + member_size(struct mail_message, time); + deleted = 0; + for (n = 0; n < nids; n++) { + if (bile_read(db->mail_bile, MAIL_SPOOL_MESSAGE_RTYPE, ids[n], + &msg, size) != size) + break; + + delta = Time - msg.time; + if (delta > secs) { + deleted++; + bile_delete(db->mail_bile, MAIL_SPOOL_MESSAGE_RTYPE, ids[n], 0); + uthread_yield(); + } + } + xfree(&ids); + + if (deleted) { + logger_printf("[db] Deleted %ld of %ld mail messages", deleted, + nids); + bile_write_map(db->mail_bile); + } +} --- mail.h Tue Mar 14 10:16:31 2023 +++ mail.h Wed Mar 15 15:01:12 2023 @@ -55,5 +55,6 @@ size_t mail_find_ids_for_user(struct user *user, size_ short mail_toss_ftn_message(struct fidopkt_message *fidomsg); size_t mail_encode_as_fidopkt(unsigned long id, struct fidopkt_address *orig_node, char **pkt_buf); +void mail_prune(short days); #endif --- main.c Tue Mar 14 15:23:02 2023 +++ main.c Wed Mar 15 15:29:57 2023 @@ -23,6 +23,7 @@ #include "db.h" #include "focusable.h" #include "logger.h" +#include "mail.h" #include "main_menu.h" #include "serial_local.h" #include "session.h" @@ -454,9 +455,16 @@ periodic_jobs(struct uthread *uthread, void *arg) goto sleep; if (last_daily_job != date_tm->tm_mday) { - session_prune_logs(db->config.session_log_days); - uthread_yield(); - + if (db->config.session_log_prune_days) { + session_prune_logs(db->config.session_log_prune_days); + uthread_yield(); + } + + if (db->config.mail_prune_days) { + mail_prune(db->config.mail_prune_days); + uthread_yield(); + } + for (n = 0; n < db->nboards; n++) { board_prune_old_posts(&db->boards[n]); uthread_yield();