]> code.citadel.org Git - citadel.git/blobdiff - citadel/msgbase.c
* citserver.c, msgbase.c, user_ops.c: hide the owner-prefix of mail
[citadel.git] / citadel / msgbase.c
index eb14ebf280d9390d6deed4322ed66688d20f02c1..e1322aeaa00fea8a5ce5aa6d96873ced919bf48a 100644 (file)
@@ -1,3 +1,4 @@
+/* $Id$ */
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -309,10 +310,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 +335,16 @@ void output_message(char *msgid, int mode,
        char snode[256];
        char lnode[256];
        char mid[256];
-       long 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,29 +363,31 @@ 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;
        mptr = dmsgtext->ptr;
-       lprintf(9, "Returned message length is %ld\n", msg_len);
 
        /* this loop spews out the whole message if we're doing raw format */
        if (mode == MT_RAW) {
                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... */
@@ -393,12 +396,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);
 
@@ -496,7 +516,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) {
@@ -508,7 +528,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 */
@@ -556,6 +576,7 @@ void output_message(char *msgid, int mode,
        /* now we're done */
        cprintf("000\n");
        cdb_free(dmsgtext);
+       return(xtime);
        }
 
 
@@ -573,6 +594,7 @@ void cmd_msg0(char *cmdbuf)
        desired_section = extract_int(cmdbuf, 2);
 
        output_message(msgid,MT_CITADEL, headers_only, desired_section);
+       return;
        }
 
 
@@ -627,7 +649,6 @@ long send_message(char *message_in_memory,  /* pointer to buffer */
 
        /* Write our little bundle of joy into the message base */
 
-       lprintf(9, "Storing message %ld\n", newmsgid);
        begin_critical_section(S_MSGMAIN);
        if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
                        message_in_memory, message_length) < 0 ) {
@@ -689,19 +710,16 @@ void save_message(char *mtmp,     /* file containing proper message */
        struct usersupp userbuf;
 
        /* 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);
@@ -713,6 +731,7 @@ void save_message(char *mtmp,       /* file containing proper message */
        strcpy(actual_rm, CC->quickroom.QRname);
        strcpy(hold_rm, "");
        strcpy(recipient, rec);
+       strproc(recipient);
 
        /* If the user is a twit, move to the twit room for posting... */
        if (TWITDETECT) if (CC->usersupp.axlevel==2) {
@@ -740,49 +759,33 @@ void save_message(char *mtmp,     /* file containing proper message */
                strcpy(actual_rm, AIDEROOM);
                }
 
-
        /* This call to usergoto() changes rooms if necessary.  It also
         * causes the latest message list to be read into memory.
         */
-       lprintf(9, "Changing rooms if necessary...\n");
        usergoto(actual_rm, 0);
 
        /* read in the quickroom record, obtaining a lock... */
-       lprintf(9, "Reading/locking <%s>...\n", actual_rm);
        lgetroom(&CC->quickroom, actual_rm);
-       lprintf(9, "Fetching message list...\n");
-       get_msglist(&CC->quickroom);
-
-       /* FIX here's where we have to handle message expiry!! */
 
-       /* 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");
+       /* Fix an obscure bug */
+       if (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) {
+               CC->quickroom.QRflags = CC->quickroom.QRflags & ~QR_MAILBOX;
                }
-       SetMessageInList(CC->num_msgs - 1, newmsgid);
 
-       /* Write it back to disk. */
-       lprintf(9, "Writing message list...\n");
-       put_msglist(&CC->quickroom);
+       /* Add the message pointer to the room */
+       AddMessageToRoom(&CC->quickroom, newmsgid);
 
        /* update quickroom */
        CC->quickroom.QRhighest = newmsgid;
-       lprintf(9, "Writing/unlocking room <%s>...\n", actual_rm);
        lputroom(&CC->quickroom, actual_rm);
 
-       /* Bump this user's messages posted counter.  Also, if the user is a
-        * twit, give them access to the twit room.
-        */
+       /* Bump this user's messages posted counter. */
        lgetuser(&CC->usersupp, CC->curr_user);
        CC->usersupp.posted = CC->usersupp.posted + 1;
-       /* FIX if user is twit, grant access to twitroom here */
        lputuser(&CC->usersupp, CC->curr_user);
 
        /* Network mail - send a copy to the network program. */
-       if ((strlen(recipient)>0)&&(mailtype != M_LOCAL)) {
+       if ( (strlen(recipient)>0) && (mailtype != M_LOCAL) ) {
                sprintf(aaa,"./network/spoolin/nm.%d",getpid());
                copy_file(mtmp,aaa);
                system("exec nohup ./netproc >/dev/null 2>&1 &");
@@ -792,12 +795,9 @@ void save_message(char *mtmp,      /* file containing proper message */
         * have to now go back to the current room...
         */
        if (strlen(hold_rm) > 0) {
-               lprintf(9, "Returning to <%s>\n", hold_rm);
                usergoto(hold_rm, 0);
                }
-       lprintf(9, "Deleting temporary file\n");
        unlink(mtmp);           /* delete the temporary file */
-       lprintf(9, "Finished with save_message()\n");
        }
 
 
@@ -806,7 +806,7 @@ void save_message(char *mtmp,       /* file containing proper message */
  */
 void aide_message(char *text)
 {
-       long now;
+       time_t now;
        FILE *fp;
 
        time(&now);
@@ -841,13 +841,14 @@ void make_message(
 
        FILE *fp;
        int a;
-       long now;
+       time_t now;
        char dest_node[32];
        char buf[256];
 
        /* 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 == M_BINARY) {
                strcpy(dest_node,NODENAME);
@@ -878,7 +879,14 @@ void make_message(
           fprintf(fp,"A%s%c",fake_name,0);
        else
           fprintf(fp,"A%s%c",author->fullname,0);      /* author */
-       fprintf(fp,"O%s%c",CC->quickroom.QRname,0);     /* room */
+
+       if (CC->quickroom.QRflags & QR_MAILBOX) {       /* room */
+               fprintf(fp,"O%s%c", &CC->quickroom.QRname[11], 0);
+               }
+       else {
+               fprintf(fp,"O%s%c",CC->quickroom.QRname,0);
+               }
+
        fprintf(fp,"N%s%c",NODENAME,0);                 /* nodename */
        fprintf(fp,"H%s%c",HUMANNODE,0);                /* human nodename */
 
@@ -973,9 +981,7 @@ void cmd_ent0(char *entargs)
                        strcpy(buf,recipient);
                        }
                else strcpy(buf,"sysop");
-               lprintf(9, "aliasing...\n");
                e=alias(buf);                   /* alias and mail type */
-               lprintf(9,"...type is %d\n", e);
                if ((buf[0]==0) || (e==M_ERROR)) {
                        cprintf("%d Unknown address - cannot send message.\n",
                                ERROR+NO_SUCH_USER);
@@ -1007,9 +1013,7 @@ void cmd_ent0(char *entargs)
                /* Check to make sure the user exists; also get the correct
                * upper/lower casing of the name. 
                */
-               lprintf(9, "checking validity of %s\n", buf);
                a = getuser(&tempUS,buf);
-               lprintf(9, "getuser() returned %d\n", a);
                if (a != 0) {
                        cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
                        return;
@@ -1070,9 +1074,7 @@ void cmd_ent3(char *entargs)
        /* If we're in Mail, check the recipient */
        if (CC->quickroom.QRflags & QR_MAILBOX) {
                extract(recp, entargs, 1);
-               lprintf(9, "aliasing...\n");
                e=alias(recp);                  /* alias and mail type */
-               lprintf(9,"...type is %d\n", e);
                if ((buf[0]==0) || (e==M_ERROR)) {
                        cprintf("%d Unknown address - cannot send message.\n",
                                ERROR+NO_SUCH_USER);
@@ -1213,6 +1215,9 @@ void cmd_move(char *args)
                }
 
        /* put the message into the target room */
+       lgetroom(&qtemp, targ);
+       AddMessageToRoom(&qtemp, num);
+       lputroom(&qtemp, targ);
 
-       cprintf("%d FIX FIX FIX implement this!!!!!\n", ERROR);
+       cprintf("%d Message moved.\n", OK);
        }