* Implemented message expiry by date (this really needs to be moved
authorArt Cancro <ajc@citadel.org>
Mon, 2 Nov 1998 00:43:39 +0000 (00:43 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 2 Nov 1998 00:43:39 +0000 (00:43 +0000)
          out of serv_test.c, but where does it belong?)

citadel/ChangeLog
citadel/citadel.h
citadel/msgbase.c
citadel/msgbase.h
citadel/serv_test.c

index 7dc1e8edc9305ab24035c9815ab9ffcae2770069..19c2cf4efe8d8baef090679ec4f16755224665a9 100644 (file)
@@ -1,5 +1,7 @@
 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
index 118788c42042e4409d2974334d0e01a6d240bd88..4c22bfb5ca44c9aad0df766f446989c10ce93755 100644 (file)
@@ -240,6 +240,7 @@ struct floor {
 #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 */
 
 
 
index 9b825fbb2e8b7edf53cb07ddb26c680d69407c98..c683a6bdf3637a9eb9c36c6e67e504646374a8d4 100644 (file)
@@ -309,10 +309,10 @@ FMTEND:   cprintf("\n");
 
 
 /*
- * 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;
@@ -334,16 +334,16 @@ void output_message(char *msgid, int mode,
        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
@@ -362,17 +362,20 @@ void output_message(char *msgid, int mode,
                }
 
        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;
@@ -383,7 +386,7 @@ void output_message(char *msgid, int mode,
                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... */
@@ -392,12 +395,29 @@ void output_message(char *msgid, int mode,
                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);
 
@@ -495,7 +515,7 @@ void output_message(char *msgid, int mode,
        if (ch==0) {
                cprintf("text\n*** ?Message truncated\n000\n");
                cdb_free(dmsgtext);
-               return;
+               return(xtime);
                }
 
        if (headers_only) {
@@ -507,7 +527,7 @@ void output_message(char *msgid, int mode,
                cprintf("mlen=%ld\n", msg_len);
                cprintf("000\n");
                cdb_free(dmsgtext);
-               return;
+               return(xtime);
                }
 
        /* signify start of msg text */
@@ -555,6 +575,7 @@ void output_message(char *msgid, int mode,
        /* now we're done */
        cprintf("000\n");
        cdb_free(dmsgtext);
+       return(xtime);
        }
 
 
@@ -572,6 +593,7 @@ void cmd_msg0(char *cmdbuf)
        desired_section = extract_int(cmdbuf, 2);
 
        output_message(msgid,MT_CITADEL, headers_only, desired_section);
+       return;
        }
 
 
index c1708fb572622e65055f54af24ca0af7eaf461d5..0c4232066b6b51e0c0100c3ed77dd3139b2edf8b 100644 (file)
@@ -4,7 +4,7 @@ void cmd_msgs (char *cmdbuf);
 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);
index 758ce19f542995216caf035b35997982dde48453..bec09516fb2d647a9abc148e60edd145d787c639 100644 (file)
@@ -14,6 +14,7 @@
 #include "citadel.h"
 #include "server.h"
 #include <syslog.h>
+#include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
@@ -22,6 +23,7 @@
 #include "room_ops.h"
 #include "policy.h"
 #include "database.h"
+#include "msgbase.h"
 
 extern struct CitContext *ContextList;
 
@@ -74,11 +76,16 @@ void Ygorl(char *username, long usernum) {
 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;
@@ -101,10 +108,22 @@ void DoPurgeMessages(struct quickroom *qrbuf) {
                        }
                }
 
-       /* 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);
        }