]> 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 95f369d3bb5bfa91faf1320c62e64c64bf6720c9..cef37b9e35b0b3bc3832190b53ba9748e4af3d98 100644 (file)
 #include "server.h"
 #include <errno.h>
 #include <sys/stat.h>
-#include "proto.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
@@ -60,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); */
@@ -84,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]);
@@ -142,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);
                }
@@ -308,7 +315,7 @@ 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;
        CIT_UBYTE format_type,anon_flag;
        char buf[1024];
@@ -412,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);
@@ -469,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);
@@ -489,7 +498,7 @@ 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);
@@ -507,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
@@ -635,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;
                        }
@@ -857,15 +863,17 @@ void aide_message(char *text)
 /*
  * 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;
@@ -909,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);
 
@@ -937,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;
@@ -947,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. */
 
@@ -1018,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;
@@ -1059,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;
@@ -1225,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;
                        }