+/* $Id$ */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include "citadel.h"
#include "server.h"
#include <syslog.h>
+#include <time.h>
#include "sysdep_decls.h"
#include "citserver.h"
#include "support.h"
#include "room_ops.h"
#include "policy.h"
#include "database.h"
+#include "msgbase.h"
extern struct CitContext *ContextList;
void DoPurgeMessages(struct quickroom *qrbuf) {
struct ExpirePolicy epbuf;
long delnum;
+ time_t xtime, now;
+ char msgid[64];
+ int a;
+ time(&now);
GetExpirePolicy(&epbuf, qrbuf);
- lprintf(9, "ExpirePolicy for <%s> is <%d> <%d>\n",
+ /* lprintf(9, "ExpirePolicy for <%s> is <%d> <%d>\n",
qrbuf->QRname, epbuf.expire_mode, epbuf.expire_value);
+ */
/* If the room is set to never expire messages ... do nothing */
if (epbuf.expire_mode == EXPIRE_NEXTLEVEL) return;
}
}
- /* If the room is set to expire by age... FIX (write this!!) */
+ /* If the room is set to expire by age... */
if (epbuf.expire_mode == EXPIRE_AGE) {
+ for (a=0; a<(CC->num_msgs); ++a) {
+ delnum = MessageFromList(a);
+ sprintf(msgid, "%ld", delnum);
+ xtime = output_message(msgid, MT_DATE, 0, 0);
+
+ if ((xtime > 0L)
+ && (now - xtime > (time_t)(epbuf.expire_value * 86400L))) {
+ cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
+ SetMessageInList(a, 0L);
+ lprintf(5, "Expiring message %ld\n", delnum);
+ }
+ }
}
-
+ CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
put_msglist(qrbuf);
}