]> code.citadel.org Git - citadel.git/blobdiff - citadel/msgbase.c
* msgbase.c: began laying the groundwork to support attachments.
[citadel.git] / citadel / msgbase.c
index a14cec67f8d5803c1232ed13c3237d9828c14801..cef37b9e35b0b3bc3832190b53ba9748e4af3d98 100644 (file)
 #include "citadel.h"
 #include "server.h"
 #include <errno.h>
-#include "proto.h"
+#include <sys/stat.h>
+#include "database.h"
+#include "msgbase.h"
+#include "support.h"
+#include "sysdep_decls.h"
+#include "room_ops.h"
+#include "user_ops.h"
+#include "control.h"
+#include "dynloader.h"
 
 #define MSGS_ALL       0
 #define MSGS_OLD       1
@@ -59,7 +67,7 @@ GNA:  strcpy(aaa,""); strcpy(bbb,"");
                fclose(fp);
                goto DETYPE;
                }
-       if (strucmp(name,aaa)) goto GNA;
+       if (strcasecmp(name,aaa)) goto GNA;
        fclose(fp);
        strcpy(name,bbb);
        /* cprintf("*** Mail is being forwarded to %s\n",name); */
@@ -83,7 +91,7 @@ DETYPE:       /* determine local or remote type, see citadel.h */
                if (fp==NULL) return(M_ERROR);
 GETSN:         do {
                        a=getstring(fp,aaa);
-                       } while ((a>=0)&&(strucmp(aaa,bbb)));
+                       } while ((a>=0)&&(strcasecmp(aaa,bbb)));
                a=getstring(fp,aaa);
                if (!strncmp(aaa,"use ",4)) {
                        strcpy(bbb,&aaa[4]);
@@ -141,17 +149,17 @@ void cmd_msgs(char *cmdbuf)
 
        mode = MSGS_ALL;
        strcat(which,"   ");
-       if (!struncmp(which,"OLD",3))   mode = MSGS_OLD;
-       if (!struncmp(which,"NEW",3))   mode = MSGS_NEW;
-       if (!struncmp(which,"FIRST",5)) {
+       if (!strncasecmp(which,"OLD",3))        mode = MSGS_OLD;
+       if (!strncasecmp(which,"NEW",3))        mode = MSGS_NEW;
+       if (!strncasecmp(which,"FIRST",5))      {
                mode = MSGS_FIRST;
                cm_howmany = extract_int(cmdbuf,1);
                }
-       if (!struncmp(which,"LAST",4))  {
+       if (!strncasecmp(which,"LAST",4))       {
                mode = MSGS_LAST;
                cm_howmany = extract_int(cmdbuf,1);
                }
-       if (!struncmp(which,"GT",2))    {
+       if (!strncasecmp(which,"GT",2)) {
                mode = MSGS_GT;
                cm_gt = extract_long(cmdbuf,1);
                }
@@ -165,25 +173,28 @@ void cmd_msgs(char *cmdbuf)
                return;
                }
        get_mm();
-       get_fullroom(&CC->fullroom,CC->curr_rm);
+       get_msglist(CC->curr_rm);
        getuser(&CC->usersupp,CC->curr_user);
-       cprintf("%d messages...\n",LISTING_FOLLOWS);
-       for (a=0; a<MSGSPERRM; ++a) 
-              if ((CC->fullroom.FRnum[a] >=0)
+       cprintf("%d %d messages...\n",LISTING_FOLLOWS, CC->num_msgs);
+       if (CC->num_msgs != 0) {
+          for (a=0; a<(CC->num_msgs); ++a) 
+              if ((MessageFromList(a) >=0)
               && ( 
 
 (mode==MSGS_ALL)
-|| ((mode==MSGS_OLD) && (CC->fullroom.FRnum[a] <= CC->usersupp.lastseen[CC->curr_rm]))
-|| ((mode==MSGS_NEW) && (CC->fullroom.FRnum[a] > CC->usersupp.lastseen[CC->curr_rm]))
-|| ((mode==MSGS_NEW) && (CC->fullroom.FRnum[a] >= CC->usersupp.lastseen[CC->curr_rm])
+|| ((mode==MSGS_OLD) && (MessageFromList(a) <= CC->usersupp.lastseen[CC->curr_rm]))
+|| ((mode==MSGS_NEW) && (MessageFromList(a) > CC->usersupp.lastseen[CC->curr_rm]))
+|| ((mode==MSGS_NEW) && (MessageFromList(a) >= CC->usersupp.lastseen[CC->curr_rm])
                     && (CC->usersupp.flags & US_LASTOLD))
-|| ((mode==MSGS_LAST)&& (a>=(MSGSPERRM-cm_howmany)))
+|| ((mode==MSGS_LAST)&& (a>=(CC->num_msgs-cm_howmany)))
 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
-|| ((mode==MSGS_GT) && (CC->fullroom.FRnum[a] > cm_gt))
+|| ((mode==MSGS_GT) && (MessageFromList(a) > cm_gt))
 
                        )
-               )
-               cprintf("%ld\n",CC->fullroom.FRnum[a]);
+               ) {
+                       cprintf("%ld\n", MessageFromList(a));
+                       }
+          }
        cprintf("000\n");
        }
 
@@ -304,9 +315,8 @@ FMTEND:     cprintf("\n");
 void output_message(char *msgid, int mode, int headers_only)
 {
        long msg_num;
-       int a,och,len;
+       int a;
        CIT_UBYTE ch, rch;
-       FILE *msg;
        CIT_UBYTE format_type,anon_flag;
        char buf[1024];
        long msg_len;
@@ -336,14 +346,21 @@ void output_message(char *msgid, int mode, int headers_only)
                return;
                }
 
-       /* We used to need to check in the current room's fullroom table
+       /* We used to need to check in the current room's message list
         * to determine where the message's disk position.  We no longer need
         * to do this, but we do it anyway as a security measure, in order to
         * prevent rogue clients from reading messages not in the current room.
         */
-       for (a=0; a<MSGSPERRM; ++a) if (CC->fullroom.FRnum[a] == msg_num) {
-               msg_ok = 1;
+
+       msg_ok = 0;
+       if (CC->num_msgs > 0) {
+               for (a=0; a<CC->num_msgs; ++a) {
+                       if (MessageFromList(a) == msg_num) {
+                               msg_ok = 1;
+                               }
+                       }
                }
+
        if (!msg_ok) {
                cprintf("%d Message %ld is not in this room.\n",
                        ERROR, msg_num);
@@ -402,6 +419,7 @@ void output_message(char *msgid, int mode, int headers_only)
                        } while (rch > 0);
 
                if (ch=='A') {
+                       PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
                        if (anon_flag==MES_ANON) cprintf("from=****");
                        else if (anon_flag==MES_AN2) cprintf("from=anonymous");
                        else cprintf("from=%s",buf);
@@ -459,10 +477,11 @@ void output_message(char *msgid, int mode, int headers_only)
                }
 
        if (mode == MT_RFC822) {
-               if (!strucmp(snode, NODENAME)) {
+               if (!strcasecmp(snode, NODENAME)) {
                        strcpy(snode, FQDN);
                        }
                cprintf("Message-ID: <%s@%s>\n", mid, snode);
+               PerformUserHooks(luser, (-1L), EVT_OUTPUTMSG);
                cprintf("From: %s@%s (%s)\n",
                        suser, snode, luser);
                cprintf("Organization: %s\n", lnode);
@@ -472,7 +491,6 @@ void output_message(char *msgid, int mode, int headers_only)
 
        if (ch==0) {
                cprintf("text\n*** ?Message truncated\n000\n");
-               fclose(msg);
                cdb_free(dmsgtext);
                return;
                }
@@ -480,12 +498,11 @@ void output_message(char *msgid, int mode, int headers_only)
        if (headers_only) {
                /* give 'em a length */
                msg_len = 0L;
-               while(och=ch, ch = *mptr++, ch>0) {
+               while(ch = *mptr++, ch>0) {
                        ++msg_len;
                        }
                cprintf("mlen=%ld\n", msg_len);
                cprintf("000\n");
-               fclose(msg);
                cdb_free(dmsgtext);
                return;
                }
@@ -499,22 +516,19 @@ void output_message(char *msgid, int mode, int headers_only)
         * what message transfer format is in use.
         */
        if (format_type == 1) {
-               och = 0;
-               len = 0;
-               while(och=ch, ch = *mptr++, ch>0) {
+               strcpy(buf, "");
+               while(ch = *mptr++, ch>0) {
                        if (ch == 13) ch = 10;
-                       ++len;
-                       if ((ch!=10)||(och!=10)) {
-                               cprintf("%c", ch);
-                               if (ch==10) len = 0;
+                       if ( (ch == 10) || (strlen(buf)>250) ) {
+                               cprintf("%s\n", buf);
+                               strcpy(buf, "");
                                }
-                       if (len>=250) {
-                               len = 0;
-                               /* cprintf("%c", ch); */
-                               cprintf("%c", 10);
+                       else {
+                               buf[strlen(buf)+1] = 0;
+                               buf[strlen(buf)] = ch;
                                }
                        }
-               if (len!=0) cprintf("%c", 10);
+               if (strlen(buf)>0) cprintf("%s\n", buf);
                }
        /* If the message on disk is format 0 (Citadel vari-format), we
         * output using the formatter at 80 columns.  This is the final output
@@ -586,43 +600,15 @@ void cmd_msg3(char *cmdbuf)
 
 
 /*
- * message base operation to send a message to the master file
+ * Message base operation to send a message to the master file
+ * (returns new message number)
  */
-void send_message(char *filename, struct smreturn *retbuf, int generate_id)
-                               /* tempfilename of proper message */
-                               /* return information */
-                               /* set to 1 to generate an 'I' field */
-{
+long send_message(char *message_in_memory,     /* pointer to buffer */
+               size_t message_length,          /* length of buffer */
+               int generate_id) {              /* 1 to generate an I field */
 
-       FILE *fp;
        long newmsgid;
 
-       char *message_in_memory;
-       size_t templen;
-
-       fp = fopen(filename, "rb");
-
-       /* Measure the message */
-       lprintf(9, "Measuring the message\n");
-       fseek(fp, 0L, SEEK_END);
-       templen = ftell(fp);
-
-       /* Now read it into memory */
-       lprintf(9, "Allocating %ld bytes\n", templen);
-       message_in_memory = (char *) malloc(templen);
-       if (message_in_memory == NULL) {
-               lprintf(2, "Can't allocate memory to save message!\n");
-               fclose(fp);     
-               retbuf->smnumber = 0L;
-               retbuf->smpos = 0L;
-               return;
-               }
-
-       lprintf(9, "Reading it into memory\n"); 
-       fseek(fp, 0L, SEEK_SET);
-       fread(message_in_memory, templen, 1, fp);
-       fclose(fp);
-
        /* Get a new message number */
        newmsgid = get_new_message_number();
 
@@ -631,19 +617,15 @@ void send_message(char *filename, struct smreturn *retbuf, int generate_id)
        lprintf(9, "Storing message %ld\n", newmsgid);
        begin_critical_section(S_MSGMAIN);
        if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
-                       message_in_memory, templen) < 0 ) {
+                       message_in_memory, message_length) < 0 ) {
                lprintf(2, "Can't store message\n");
-               retbuf->smnumber = 0L;
-               retbuf->smpos = 0L;
-               return;
+               end_critical_section(S_MSGMAIN);
+               return 0L;
                }
        end_critical_section(S_MSGMAIN);
-       free(message_in_memory);
-
 
        /* Finally, return the pointers */
-       retbuf->smnumber = newmsgid;
-       retbuf->smpos= 1L; /* FIX we really won't be needing this */
+       return(newmsgid);
        }
 
 
@@ -659,7 +641,7 @@ void loadtroom(void) {
        /* first try to locate the twit room */
        for (a=0; a<MAXROOMS; ++a) {
                getroom(&qrbuf,a);
-               if (!strucmp(qrbuf.QRname,config.c_twitroom)) {
+               if (!strcasecmp(qrbuf.QRname,config.c_twitroom)) {
                        twitroom = a;
                        return;
                        }
@@ -711,30 +693,57 @@ void save_message(char *mtmp,     /* file containing proper message */
                int mailtype,   /* local or remote type, see citadel.h */
                int generate_id) /* set to 1 to generate an 'I' field */
 {
-       int a,e;
        struct usersupp tempUS;
        char aaa[100];
-       struct smreturn smreturn;
        int hold_rm;
+       struct cdbdata *cdbmb;
+       long *dmailbox;
+       int dnum_mails;
+       long newmsgid;
+       char *message_in_memory;
+       struct stat statbuf;
+       size_t templen;
+       FILE *fp;
+
+       /* Measure the message */
+       lprintf(9, "Measuring the message\n");
+       stat(mtmp, &statbuf);
+       templen = statbuf.st_size;
+
+       /* Now read it into memory */
+       lprintf(9, "Allocating %ld bytes\n", templen);
+       message_in_memory = (char *) malloc(templen);
+       if (message_in_memory == NULL) {
+               lprintf(2, "Can't allocate memory to save message!\n");
+               return;
+               }
+
+       lprintf(9, "Reading it into memory\n"); 
+       fp = fopen(mtmp, "rb");
+       fread(message_in_memory, templen, 1, fp);
+       fclose(fp);
 
-       send_message(mtmp,&smreturn,generate_id);
+       newmsgid = send_message(message_in_memory, templen, generate_id);
+       free(message_in_memory);
+       if (newmsgid <= 0L) return;
        hold_rm=(-1);
 
-       /* if the user is a twit, move to the twit room for posting */
+       /* If the user is a twit, move to the twit room for posting... */
        if (TWITDETECT) if (CC->usersupp.axlevel==2) {
                if (twitroom<0) loadtroom();
                hold_rm=CC->curr_rm;
                CC->curr_rm=twitroom;
                }
 
-       /* and if this message is destined for Aide> then go there */
+       /* ...or if this message is destined for Aide> then go there. */
        if (mtsflag) {
                hold_rm=CC->curr_rm;
                CC->curr_rm=2;
                }
 
-       /* this call to usergoto() changes rooms if necessary.  It also
-          causes the latest fullroom structure to be read into memory */
+       /* This call to usergoto() changes rooms if necessary.  It also
+        * causes the latest message list to be read into memory.
+        */
        usergoto(CC->curr_rm,0);
 
        /* Store the message pointer, but NOT for sent mail! */
@@ -742,64 +751,84 @@ void save_message(char *mtmp,     /* file containing proper message */
 
                /* read in the quickroom record, obtaining a lock... */
                lgetroom(&CC->quickroom,CC->curr_rm);
-               get_fullroom(&CC->fullroom,CC->curr_rm);
+               get_msglist(CC->curr_rm);
 
-               /* Delete the oldest message if there is one */
-               if (CC->fullroom.FRnum[0] != 0L) {
-                       cdb_delete(CDB_MSGMAIN,
-                               &CC->fullroom.FRnum[0], sizeof(long));
-                       }
+               /* FIX here's where we have to to message expiry!! */
 
-               /* Now scroll... */
-               for (a=0; a<(MSGSPERRM-1); ++a) {
-                       CC->fullroom.FRnum[a]=CC->fullroom.FRnum[a+1];
+               /* Now add the new message */
+               CC->num_msgs = CC->num_msgs + 1;
+               CC->msglist = realloc(CC->msglist,
+                       ((CC->num_msgs) * sizeof(long)) );
+               if (CC->msglist == NULL) {
+                       lprintf(3, "ERROR can't realloc message list!\n");
                        }
-       
-               /* ...and add the new message */
-               CC->fullroom.FRnum[MSGSPERRM-1]=smreturn.smnumber;
+               SetMessageInList(CC->num_msgs - 1, newmsgid);
        
                /* Write it back to disk. */
-               put_fullroom(&CC->fullroom,CC->curr_rm);
+               put_msglist(CC->curr_rm);
        
                /* update quickroom */
-               CC->quickroom.QRhighest=CC->fullroom.FRnum[MSGSPERRM-1];
+               CC->quickroom.QRhighest = newmsgid;
                lputroom(&CC->quickroom,CC->curr_rm);
                }
 
        /* Bump this user's messages posted counter.  Also, if the user is a
-          twit, give them access to the twit room. */
+        * twit, give them access to the twit room.
+        */
        lgetuser(&CC->usersupp,CC->curr_user);
        CC->usersupp.posted = CC->usersupp.posted + 1;
-       if (CC->curr_rm==twitroom) CC->usersupp.generation[twitroom]=CC->quickroom.QRgen;
-       lputuser(&CC->usersupp,CC->curr_user);
+       if (CC->curr_rm==twitroom) {
+               CC->usersupp.generation[twitroom] = CC->quickroom.QRgen;
+               }
+       lputuser(&CC->usersupp, CC->curr_user);
 
-       /* if mail, there's still more to do, if not, skip it */
+       /* If mail, there's still more to do, if not, skip it. */
        if ((CC->curr_rm!=1)||(mtsflag)) goto ENTFIN;
 
-       /* network mail - send a copy to the network program */
+       /* Network mail - send a copy to the network program. */
        if (mailtype!=M_LOCAL) {
                sprintf(aaa,"./network/spoolin/nm.%d",getpid());
                copy_file(mtmp,aaa);
                system("exec nohup ./netproc >/dev/null 2>&1 &");
                }
 
-       /* local mail - put a copy in the recipient's mailbox */
-       if (mailtype==M_LOCAL) {
+       /* Local mail - put a copy in the recipient's mailbox. */
+       /* FIX here's where we have to handle expiry, stuffed boxes, etc. */
+       if (mailtype == M_LOCAL) {
                if (lgetuser(&tempUS,rec)==0) {
-                       if (tempUS.mailnum[0] != 0L) {
-                               cdb_delete(CDB_MSGMAIN, &tempUS.mailnum[0],
-                                       sizeof(long));
+
+                       cdbmb = cdb_fetch(CDB_MAILBOXES,
+                                       &tempUS.usernum, sizeof(long));
+                       if (cdbmb != NULL) {
+                               memcpy(dmailbox, cdbmb->ptr, cdbmb->len);
+                               dnum_mails = cdbmb->len / sizeof(long);
+                               cdb_free(cdbmb);
                                }
-                       for (e=0; e<(MAILSLOTS-1); ++e) {
-                               tempUS.mailnum[e]=tempUS.mailnum[e+1];
+                       else {
+                               dmailbox = NULL;
+                               dnum_mails = 0;
                                }
-                       tempUS.mailnum[MAILSLOTS-1]=smreturn.smnumber;
+       
+                       ++dnum_mails;
+                       if (dmailbox == NULL) {
+                               dmailbox = malloc(sizeof(long) * dnum_mails);
+                               }
+                       else {
+                               dmailbox = realloc(dmailbox,
+                                               sizeof(long) * dnum_mails);
+                               }
+                       
+                       dmailbox[dnum_mails - 1] = newmsgid;
+                       cdb_store(CDB_MAILBOXES, &tempUS.usernum, sizeof(long),
+                               dmailbox, (dnum_mails * sizeof(long)) );
                        lputuser(&tempUS,rec);
+                       free(dmailbox);
                        }
                }
 
-       /* if we've posted in a room other than the current room, then we
-          have to now go back to the current room... */
+       /* If we've posted in a room other than the current room, then we
+        * have to now go back to the current room...
+        */
 ENTFIN:        if (hold_rm!=(-1)) {
                usergoto(hold_rm,0);
                }
@@ -808,7 +837,7 @@ ENTFIN:     if (hold_rm!=(-1)) {
 
 
 /*
- * generate an administrative message and post it in the Aide> room
+ * Generate an administrative message and post it in the Aide> room.
  */
 void aide_message(char *text)
 {
@@ -832,27 +861,29 @@ void aide_message(char *text)
 
 
 /*
- * build a binary message to be saved on disk
+ * Build a binary message to be saved on disk.
  */
-void make_message(char *filename, struct usersupp *author, char *recipient, char *room, int type, int net_type, int format_type, char *fake_name)
-                       /* temporary file name */
-                          /* author's usersupp structure */
-                       /* NULL if it's not mail */
-                       /* room where it's going */
-                       /* see MES_ types in header file */
-                       /* local or remote type, see citadel.h */
-                       /* format type (see citadel.h) */
-{ 
+void make_message(
+       char *filename,                 /* temporary file name */
+       struct usersupp *author,        /* author's usersupp structure */
+       char *recipient,                /* NULL if it's not mail */
+       char *room,                     /* room where it's going */
+       int type,                       /* see MES_ types in header file */
+       int net_type,                   /* see MES_ types in header file */
+       int format_type,                /* local or remote (see citadel.h) */
+       char *fake_name,                /* who we're masquerading as */
+       char *separator) {              /* separator (if exist attachments) */
+
        FILE *fp;
        int a;
        long now;
        char dest_node[32];
        char buf[256];
 
-       /* don't confuse the poor folks if it's not routed mail. */
-       strcpy(dest_node,"");
+       /* Don't confuse the poor folks if it's not routed mail. */
+       strcpy(dest_node, "");
 
-       /* if net_type is M_BINARY, split out the destination node */
+       /* If net_type is M_BINARY, split out the destination node. */
        if (net_type == M_BINARY) {
                strcpy(dest_node,NODENAME);
                for (a=0; a<strlen(recipient); ++a) {
@@ -886,8 +917,9 @@ void make_message(char *filename, struct usersupp *author, char *recipient, char
        fprintf(fp,"N%s%c",NODENAME,0);                 /* nodename */
        fprintf(fp,"H%s%c",HUMANNODE,0);                /* human nodename */
 
-       if (recipient[0]!=0) fprintf(fp,"R%s%c",recipient,0);
-       if (dest_node[0]!=0) fprintf(fp,"D%s%c",dest_node,0);
+       if (recipient[0]!=0) fprintf(fp, "R%s%c", recipient, 0);
+       if (dest_node[0]!=0) fprintf(fp, "D%s%c", dest_node, 0);
+       if (separator[0]!=0) fprintf(fp, "Z%s%c", separator, 0);
 
        putc('M',fp);
 
@@ -914,6 +946,7 @@ void cmd_ent0(char *entargs)
        int anon_flag = 0;
        int format_type = 0;
        char newusername[256];          /* <bc> */
+       char separator[256];
 
        int a,b,e;
        int mtsflag = 0;
@@ -924,6 +957,7 @@ void cmd_ent0(char *entargs)
        extract(recipient,entargs,1);
        anon_flag = extract_int(entargs,2);
        format_type = extract_int(entargs,3);
+       extract(separator, entargs, 4);
 
        /* first check to make sure the request is valid. */
 
@@ -995,12 +1029,12 @@ void cmd_ent0(char *entargs)
                                ERROR+HIGHER_ACCESS_REQUIRED);
                        return;
                        }
-               if (!strucmp(buf,"sysop")) {
+               if (!strcasecmp(buf,"sysop")) {
                        mtsflag=1;
                        goto SKFALL;
                        }
                if (e!=M_LOCAL) goto SKFALL;    /* don't search local file  */
-               if (!strucmp(buf,CC->usersupp.fullname)) {
+               if (!strcasecmp(buf,CC->usersupp.fullname)) {
                        cprintf("%d Can't send mail to yourself!\n",
                                ERROR+NO_SUCH_USER);
                        return;
@@ -1036,12 +1070,12 @@ SKFALL: b=MES_NORMAL;
        
        cprintf("%d send message\n",SEND_LISTING);
        if (CC->fake_postname[0])
-          make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname);
+          make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname, separator);
        else
           if (CC->fake_username[0])
-             make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
+             make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username, separator);
           else
-             make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
+             make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "", separator);
        save_message(CC->temp,buf,mtsflag,e,1);
         CC->fake_postname[0]='\0';
        return;
@@ -1145,19 +1179,20 @@ void cmd_dele(char *delstr)
        
        /* get room records, obtaining a lock... */
        lgetroom(&CC->quickroom,CC->curr_rm);
-       get_fullroom(&CC->fullroom,CC->curr_rm);
+       get_msglist(CC->curr_rm);
 
        ok = 0;
-       for (a=0; a<MSGSPERRM; ++a)
-               if (CC->fullroom.FRnum[a]==delnum) {
-                       CC->fullroom.FRnum[a]=0L;
+       if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
+               if (MessageFromList(a) == delnum) {
+                       SetMessageInList(a, 0L);
                        ok = 1;
                        }
+               }
 
-       sort_fullroom(&CC->fullroom);
-       CC->quickroom.QRhighest = CC->fullroom.FRnum[MSGSPERRM-1];
+       CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
+       CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
 
-       put_fullroom(&CC->fullroom,CC->curr_rm);
+       put_msglist(CC->curr_rm);
        lputroom(&CC->quickroom,CC->curr_rm);
        if (ok==1) {
                cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
@@ -1177,8 +1212,10 @@ void cmd_move(char *args)
        int a;
        int targ_slot;
        struct quickroom qtemp;
-       struct fullroom ftemp;
        int foundit;
+       struct cdbdata *cdbtarg;
+       long *targmsgs;
+       int targ_count;
 
        num = extract_long(args,0);
        extract(targ,args,1);
@@ -1199,7 +1236,7 @@ void cmd_move(char *args)
        targ_slot = (-1);
        for (a=0; a<MAXROOMS; ++a) {
                getroom(&qtemp,a);
-               if (!strucmp(qtemp.QRname,targ)) {
+               if (!strcasecmp(qtemp.QRname,targ)) {
                        targ_slot = a;
                        a = MAXROOMS;
                        }
@@ -1211,19 +1248,19 @@ void cmd_move(char *args)
 
        /* yank the message out of the current room... */
        lgetroom(&CC->quickroom,CC->curr_rm);
-       get_fullroom(&CC->fullroom,CC->curr_rm);
+       get_msglist(CC->curr_rm);
 
        foundit = 0;
-       for (a=0; a<MSGSPERRM; ++a) {
-               if (CC->fullroom.FRnum[a] == num) {
+       for (a=0; a<(CC->num_msgs); ++a) {
+               if (MessageFromList(a) == num) {
                        foundit = 1;
-                       CC->fullroom.FRnum[a] = 0L;
+                       SetMessageInList(a, 0L);
                        }
                }
        if (foundit) {
-               sort_fullroom(&CC->fullroom);
-               put_fullroom(&CC->fullroom,CC->curr_rm);
-               CC->quickroom.QRhighest = CC->fullroom.FRnum[MSGSPERRM-1];
+               CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
+               put_msglist(CC->curr_rm);
+               CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
                }
        lputroom(&CC->quickroom,CC->curr_rm);
        if (!foundit) {
@@ -1231,18 +1268,28 @@ void cmd_move(char *args)
                return;
                }
 
+       /* put the message into the target room */
        lgetroom(&qtemp,targ_slot);
-       get_fullroom(&ftemp,targ_slot);
-       if (CC->fullroom.FRnum[0] != 0L) {
-               cdb_delete(CDB_MSGMAIN, &CC->fullroom.FRnum[0], sizeof(long));
-               }
-       for (a=0; a<MSGSPERRM-1; ++a) {
-               ftemp.FRnum[a]=ftemp.FRnum[a+1];
-               }
-       ftemp.FRnum[MSGSPERRM-1] = num;
-       sort_fullroom(&ftemp);
-       qtemp.QRhighest = ftemp.FRnum[MSGSPERRM-1];
-       put_fullroom(&ftemp,targ_slot);
+       cdbtarg = cdb_fetch(CDB_MSGLISTS, &targ_slot, sizeof(int));
+       if (cdbtarg != NULL) {
+               targmsgs = malloc(cdbtarg->len);
+               memcpy(targmsgs, cdbtarg->ptr, cdbtarg->len);
+               targ_count = cdbtarg->len / sizeof(long);
+               cdb_free(cdbtarg);
+               }
+       else {
+               targmsgs = NULL;
+               targ_count = 0;
+               }
+
+       ++targ_count;
+       targmsgs = realloc(targmsgs, ((CC->num_msgs) * sizeof(long)));
+       targmsgs[targ_count - 1] = num;
+       targ_count = sort_msglist(targmsgs, targ_count);
+       qtemp.QRhighest = targmsgs[targ_count - 1];
+       cdb_store(CDB_MSGLISTS, &targ_slot, sizeof(int),
+                       targmsgs, targ_count * sizeof(long));
+       free(targmsgs);
        lputroom(&qtemp,targ_slot);
        cprintf("%d ok\n",OK);
        }