Sun Nov 1 18:47:42 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
* serv_upgrade.c: cosmetic changes
+ * Implemented message expiry by date (this really needs to be moved
+ out of serv_test.c, but where does it belong?)
1998-11-01 Nathan Bryant <bryant@cs.usm.maine.edu>
* serv_upgrade.c: warning fixes
#define MT_CITADEL 0 /* Citadel proprietary */
#define MT_RFC822 2 /* RFC822 */
#define MT_RAW 3 /* IGnet raw format */
+#define MT_DATE 4 /* We're only looking for the date */
/*
- * get a message off disk.
+ * Get a message off disk. (return value is the message's timestamp)
*
*/
-void output_message(char *msgid, int mode,
+time_t output_message(char *msgid, int mode,
int headers_only, int desired_section) {
long msg_num;
int a;
char snode[256];
char lnode[256];
char mid[256];
- time_t xtime;
+ time_t xtime = 0L;
/* */
strcpy(boundary, "");
msg_num = atol(msgid);
- if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
+ if ((!(CC->logged_in))&&(!(CC->internal_pgm))&&(mode!=MT_DATE)) {
cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
- return;
+ return(xtime);
}
/* We used to need to check in the current room's message list
}
if (!msg_ok) {
- cprintf("%d Message %ld is not in this room.\n",
- ERROR, msg_num);
- return;
+ if (mode != MT_DATE)
+ cprintf("%d Message %ld is not in this room.\n",
+ ERROR, msg_num);
+ return(xtime);
}
dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
if (dmsgtext == NULL) {
- cprintf("%d Can't find message %ld\n", ERROR+INTERNAL_ERROR);
- return;
+ if (mode != MT_DATE)
+ cprintf("%d Can't find message %ld\n",
+ ERROR+INTERNAL_ERROR);
+ return(xtime);
}
msg_len = (long) dmsgtext->len;
cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
client_write(dmsgtext->ptr, (int) msg_len);
cdb_free(dmsgtext);
- return;
+ return(xtime);
}
/* Otherwise, we'll start parsing it field by field... */
cprintf("%d Illegal message format on disk\n",
ERROR+INTERNAL_ERROR);
cdb_free(dmsgtext);
- return;
+ return(xtime);
}
anon_flag = *mptr++;
format_type = *mptr++;
+ /* Are we just looking for the message date? */
+ if (mode == MT_DATE) while(ch = *mptr++, (ch!='M' && ch!=0)) {
+ buf[0] = 0;
+ do {
+ buf[strlen(buf)+1] = 0;
+ rch = *mptr++;
+ buf[strlen(buf)] = rch;
+ } while (rch > 0);
+
+ if (ch=='T') {
+ xtime = atol(buf);
+ cdb_free(dmsgtext);
+ return(xtime);
+ }
+ }
+
+
/* now for the user-mode message reading loops */
cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
if (ch==0) {
cprintf("text\n*** ?Message truncated\n000\n");
cdb_free(dmsgtext);
- return;
+ return(xtime);
}
if (headers_only) {
cprintf("mlen=%ld\n", msg_len);
cprintf("000\n");
cdb_free(dmsgtext);
- return;
+ return(xtime);
}
/* signify start of msg text */
/* now we're done */
cprintf("000\n");
cdb_free(dmsgtext);
+ return(xtime);
}
desired_section = extract_int(cmdbuf, 2);
output_message(msgid,MT_CITADEL, headers_only, desired_section);
+ return;
}
void help_subst (char *strbuf, char *source, char *dest);
void do_help_subst (char *buffer);
void memfmout (int width, char *mptr, char subst);
-void output_message (char *msgid, int mode,
+time_t output_message (char *msgid, int mode,
int headers_only, int desired_section);
void cmd_msg0 (char *cmdbuf);
void cmd_msg2 (char *cmdbuf);
#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);
}