]> 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 4a6a1a735d365919e818fe4702868dc7a900b46d..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];
-       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 +363,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 +387,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 +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);
 
@@ -495,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) {
@@ -507,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 */
@@ -555,6 +576,7 @@ void output_message(char *msgid, int mode,
        /* now we're done */
        cprintf("000\n");
        cdb_free(dmsgtext);
+       return(xtime);
        }
 
 
@@ -572,6 +594,7 @@ void cmd_msg0(char *cmdbuf)
        desired_section = extract_int(cmdbuf, 2);
 
        output_message(msgid,MT_CITADEL, headers_only, desired_section);
+       return;
        }
 
 
@@ -708,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) {
@@ -735,7 +759,6 @@ 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.
         */
@@ -743,21 +766,14 @@ void save_message(char *mtmp,     /* file containing proper message */
 
        /* read in the quickroom record, obtaining a lock... */
        lgetroom(&CC->quickroom, actual_rm);
-       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. */
-       put_msglist(&CC->quickroom);
+       /* Add the message pointer to the room */
+       AddMessageToRoom(&CC->quickroom, newmsgid);
 
        /* update quickroom */
        CC->quickroom.QRhighest = newmsgid;
@@ -832,6 +848,7 @@ void make_message(
        /* 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);
@@ -862,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 */
 
@@ -1192,13 +1216,8 @@ void cmd_move(char *args)
 
        /* put the message into the target room */
        lgetroom(&qtemp, targ);
-       get_msglist(&qtemp);
-       CC->num_msgs = CC->num_msgs + 1;
-       CC->msglist = realloc(CC->msglist, (CC->num_msgs * sizeof(long)) );
-       SetMessageInList(CC->num_msgs - 1, num);
-       CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
-       put_msglist(&qtemp);
+       AddMessageToRoom(&qtemp, num);
        lputroom(&qtemp, targ);
 
-       cprintf("%d I think this worked, FIX check to make sure\n", OK);
+       cprintf("%d Message moved.\n", OK);
        }