]> code.citadel.org Git - citadel.git/blobdiff - citadel/msgbase.c
* Various changes to begin work on support for MIME messages
[citadel.git] / citadel / msgbase.c
index 296cfc2d18f603704ed032777f36f8346e2d18d5..257e03ceede7f5676ce1ae11d376713fd2197b8f 100644 (file)
@@ -357,7 +357,7 @@ time_t output_message(char *msgid, int mode,
        char lnode[256];
        char mid[256];
        time_t xtime = 0L;
-       /* */
+       /*                                       */
 
        msg_num = atol(msgid);
 
@@ -442,7 +442,7 @@ time_t output_message(char *msgid, int mode,
        /* now for the user-mode message reading loops */
        cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
 
-       if (mode == MT_CITADEL) cprintf("type=%d\n",format_type);
+       if (mode == MT_CITADEL) cprintf("type=%d\n", format_type);
 
        if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
                cprintf("nhdr=yes\n");
@@ -553,9 +553,10 @@ time_t output_message(char *msgid, int mode,
 
        /* If the format type on disk is 1 (fixed-format), then we want
         * everything to be output completely literally ... regardless of
-        * what message transfer format is in use.
+        * what message transfer format is in use.  Format type 4 is 
+        * temporarily being output this way as well.
         */
-       if (format_type == 1) {
+       if ( (format_type == 1) || (format_type == 4)) {
                strcpy(buf, "");
                while(ch = *mptr++, ch>0) {
                        if (ch == 13) ch = 10;
@@ -602,7 +603,7 @@ void cmd_msg0(char *cmdbuf)
        headers_only = extract_int(cmdbuf, 1);
        desired_section = extract_int(cmdbuf, 2);
 
-       output_message(msgid,MT_CITADEL, headers_only, desired_section);
+       output_message(msgid, MT_CITADEL, headers_only, desired_section);
        return;
        }
 
@@ -652,23 +653,47 @@ long send_message(char *message_in_memory,        /* pointer to buffer */
                int generate_id) {              /* 1 to generate an I field */
 
        long newmsgid;
+       char *actual_message;
+       size_t actual_length;
+       long retval;
+       char msgidbuf[32];
 
        /* Get a new message number */
        newmsgid = get_new_message_number();
 
-       /* Write our little bundle of joy into the message base */
+       if (generate_id) {
+               sprintf(msgidbuf, "I%ld", newmsgid);
+               actual_length = message_length + strlen(msgidbuf) + 1;
+               actual_message = mallok(actual_length);
+               memcpy(actual_message, message_in_memory, 3);
+               memcpy(&actual_message[3], msgidbuf, (strlen(msgidbuf)+1) );
+               memcpy(&actual_message[strlen(msgidbuf)+4],
+                       &message_in_memory[3], message_length - 3);
+               }
+       
+       else {
+               actual_message = message_in_memory;
+               actual_length = message_length;
+               }
 
+       /* Write our little bundle of joy into the message base */
        begin_critical_section(S_MSGMAIN);
        if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
-                       message_in_memory, message_length) < 0 ) {
+                       actual_message, actual_length) < 0 ) {
                lprintf(2, "Can't store message\n");
-               end_critical_section(S_MSGMAIN);
-               return 0L;
+               retval = 0L;
+               }
+       else {
+               retval = newmsgid;
                }
        end_critical_section(S_MSGMAIN);
 
+       if (generate_id) {
+               phree(actual_message);
+               }
+
        /* Finally, return the pointers */
-       return(newmsgid);
+       return(retval);
        }
 
 
@@ -703,7 +728,7 @@ void copy_file(char *from, char *to)
  */
 void save_message(char *mtmp,  /* file containing proper message */
                char *rec,      /* Recipient (if mail) */
-               char mtsflag,   /* 0 for normal, 1 to force Aide> room */
+               char *force_room, /* if non-zero length, force a room */
                int mailtype,   /* local or remote type, see citadel.h */
                int generate_id) /* set to 1 to generate an 'I' field */
 {
@@ -718,9 +743,10 @@ void save_message(char *mtmp,      /* file containing proper message */
        FILE *fp;
        struct usersupp userbuf;
        int a;
+       static int seqnum = 0;
 
-       lprintf(9, "save_message(%s,%s,%d,%d,%d)\n",
-               mtmp, rec, mtsflag, mailtype, generate_id);
+       lprintf(9, "save_message(%s,%s,%s,%d,%d)\n",
+               mtmp, rec, force_room, mailtype, generate_id);
 
        /* Strip non-printable characters out of the recipient name */
        strcpy(recipient, rec);
@@ -733,7 +759,7 @@ void save_message(char *mtmp,       /* file containing proper message */
        templen = statbuf.st_size;
 
        /* Now read it into memory */
-       message_in_memory = (char *) malloc(templen);
+       message_in_memory = (char *) mallok(templen);
        if (message_in_memory == NULL) {
                lprintf(2, "Can't allocate memory to save message!\n");
                return;
@@ -744,7 +770,7 @@ void save_message(char *mtmp,       /* file containing proper message */
        fclose(fp);
 
        newmsgid = send_message(message_in_memory, templen, generate_id);
-       free(message_in_memory);
+       phree(message_in_memory);
        if (newmsgid <= 0L) return;
 
        strcpy(actual_rm, CC->quickroom.QRname);
@@ -761,7 +787,8 @@ void save_message(char *mtmp,       /* file containing proper message */
                /* mailtype = alias(recipient); */
                if (mailtype == M_LOCAL) {
                        if (getuser(&userbuf, recipient)!=0) {
-                               mtsflag = 1; /* User not found, goto Aide */
+                               /* User not found, goto Aide */
+                               strcpy(force_room, AIDEROOM);
                                }
                        else {
                                strcpy(hold_rm, actual_rm);
@@ -771,9 +798,9 @@ void save_message(char *mtmp,       /* file containing proper message */
                }
 
        /* ...or if this message is destined for Aide> then go there. */
-       if (mtsflag) {
+       if (strlen(force_room) > 0) {
                strcpy(hold_rm, actual_rm);
-               strcpy(actual_rm, AIDEROOM);
+               strcpy(actual_rm, force_room);
                }
 
        /* This call to usergoto() changes rooms if necessary.  It also
@@ -797,9 +824,10 @@ void save_message(char *mtmp,      /* file containing proper message */
 
        /* Network mail - send a copy to the network program. */
        if ( (strlen(recipient)>0) && (mailtype != M_LOCAL) ) {
-               sprintf(aaa,"./network/spoolin/nm.%d",getpid());
+               sprintf(aaa,"./network/spoolin/netmail.%04x.%04x.%04x",
+                       getpid(), CC->cs_pid, ++seqnum);
                copy_file(mtmp,aaa);
-               system("exec nohup ./netproc >/dev/null 2>&1 &");
+               system("exec nohup ./netproc -i >/dev/null 2>&1 &");
                }
 
        /* Bump this user's messages posted counter. */
@@ -822,20 +850,18 @@ void save_message(char *mtmp,     /* file containing proper message */
  */
 void aide_message(char *text)
 {
-       time_t now;
        FILE *fp;
 
-       time(&now);
        fp=fopen(CC->temp,"wb");
        fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
        fprintf(fp,"Psysop%c",0);
-       fprintf(fp,"T%ld%c",now,0);
+       fprintf(fp,"T%ld%c", time(NULL), 0);
        fprintf(fp,"ACitadel%c",0);
        fprintf(fp,"OAide%c",0);
        fprintf(fp,"N%s%c",NODENAME,0);
        fprintf(fp,"M%s\n%c",text,0);
        fclose(fp);
-       save_message(CC->temp,"",1,M_LOCAL,1);
+       save_message(CC->temp,"",AIDEROOM,M_LOCAL,1);
        syslog(LOG_NOTICE,text);
        }
 
@@ -1056,7 +1082,7 @@ SKFALL: b=MES_NORMAL;
              make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
           else
              make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
-       save_message(CC->temp,buf,mtsflag,e,1);
+       save_message(CC->temp,buf, (mtsflag ? AIDEROOM : ""), e,1);
         CC->fake_postname[0]='\0';
        return;
        }
@@ -1134,7 +1160,7 @@ void cmd_ent3(char *entargs)
                }
        fclose(fp);
 
-       save_message(CC->temp, recp, 0, e, 0);
+       save_message(CC->temp, recp, "", e, 0);
        }