More changes to get attachments working.
authorArt Cancro <ajc@citadel.org>
Tue, 22 Sep 1998 02:35:03 +0000 (02:35 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 22 Sep 1998 02:35:03 +0000 (02:35 +0000)
citadel/citadel.rc
citadel/commands.c
citadel/messages.c
citadel/msgbase.c
citadel/techdoc/hack.txt
citadel/techdoc/session.txt

index ab74471b0e9efa01c03eedf436e971ee3e0067a1..661f96505a3117b2921193796efcbaf9d0208af7 100644 (file)
@@ -43,6 +43,10 @@ use_floors=DEFAULT
 #
 beep=1
 
+# ALLOW_ATTACHMENTS should be set to 1 if you wish the user to be able to
+# attach files to messages.  (Do not enable this for 'safe' public clients.)
+allow_attachments=1
+
 # If you set the USERNAME variable, the value you set here will automatically
 # be passed to the "Enter your name:" prompt.
 #
index 03ddacfcdf552b293b05ca9e0dc096e2e6bcf6ef..5ca24d2db79e2ed1d58a0187e530c507950e8c11 100644 (file)
@@ -47,7 +47,7 @@ struct citcmd {
 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
 
 
-char rc_exp_beep;
+int rc_exp_beep;
 char rc_exp_cmd[256];
 
 char *gl_string;
@@ -296,6 +296,7 @@ void load_command_set(void) {
        strcpy(rc_password,"");
        rc_floor_mode = 0;
        rc_exp_beep = 1;
+       rc_allow_attachments = 0;
        strcpy(rc_exp_cmd, "");
 
        /* now try to open the citadel.rc file */
@@ -343,6 +344,10 @@ void load_command_set(void) {
                rc_exp_beep = atoi(&buf[5]);
                }
 
+           if (!struncmp(buf,"allow_attachments=", 18)) {
+               rc_allow_attachments = atoi(&buf[18]);
+               }
+
            if (!struncmp(buf,"username=",9))
                strcpy(rc_username,&buf[9]);
 
index 04501a5eabc60e261fd386e89ccddbfef9442de6..fd08ea0afad2a69e491e7d74ad6b13cfb1746dca 100644 (file)
@@ -61,6 +61,7 @@ extern unsigned userflags;
 extern char sigcaught;
 extern char editor_path[];
 extern char printcmd[];
+extern int rc_allow_attachments;
 
 extern int editor_pid;
 
@@ -517,7 +518,7 @@ void replace_string(char *filename, long int startpos)
        }
 
 
-int make_message(char *filename, char *recipient, int anon_type, int format_type, int mode)
+int make_message(char *filename, char *recipient, int anon_type, int format_type, int mode, char *boundary)
                        /* temporary file name */
                        /* NULL if it's not mail */
                        /* see MES_ types in header file */
@@ -651,6 +652,14 @@ MECR2:     b=inkey();
                printf("Hold message\n");
                return(2);
                }
+       if ((b=='f')&&(rc_allow_attachments==1)) {
+               printf("attach File\n");
+               if (strlen(boundary)==0) {
+                       sprintf(boundary, "Citadel-Attachment-%ld.%d",
+                               time(NULL), getpid() );
+                       }
+               /* FIX FIX now you have to attach the file, stupid */
+               }
        goto MECR2;
 
 MEFIN: return(0);
@@ -707,6 +716,7 @@ int entmsg(int is_reply, int c)
        {               /* */
        char buf[300];
        char cmd[256];
+       char boundary[256];
        int a,b;
        int need_recp = 0;
        int mode;
@@ -777,14 +787,11 @@ int entmsg(int is_reply, int c)
                }
 
 /* now put together the message */
-       a=make_message(temp,buf,b,0,c);
-       if (a!=0)
-       {
-          return(2);
-       }
+       strcpy(boundary, "");
+       if ( make_message(temp,buf,b,0,c,boundary) != 0 ) return(2);
 
 /* and send it to the server */
-       sprintf(cmd,"ENT0 1|%s|%d|%d",buf,b,mode);
+       sprintf(cmd,"ENT0 1|%s|%d|%d||%s|",buf,b,mode,boundary);
        serv_puts(cmd);
        serv_gets(cmd);
        if (cmd[0]!='4') {
index cef37b9e35b0b3bc3832190b53ba9748e4af3d98..af13aeadf29921b31704993569c1de7eb29e50b5 100644 (file)
@@ -70,7 +70,7 @@ GNA:  strcpy(aaa,""); strcpy(bbb,"");
        if (strcasecmp(name,aaa)) goto GNA;
        fclose(fp);
        strcpy(name,bbb);
-       /* cprintf("*** Mail is being forwarded to %s\n",name); */
+       lprintf(7, "Mail is being forwarded to %s\n", name);
 
 DETYPE:        /* determine local or remote type, see citadel.h */
        for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
@@ -80,7 +80,7 @@ DETYPE:       /* determine local or remote type, see citadel.h */
                                if (name[b]=='.') return(M_INTERNET);
        b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
        if (b>1) {
-               /* cprintf("Too many @'s in address\n"); */
+               lprintf(7, "Too many @'s in address\n");
                return(M_ERROR);
                }
        if (b==1) {
@@ -321,6 +321,10 @@ void output_message(char *msgid, int mode, int headers_only)
        char buf[1024];
        long msg_len;
        int msg_ok = 0;
+       char boundary[256];             /* attachment boundary */
+       char current_section = 0;       /* section currently being parsed */
+       char desired_section = 0;       /* section desired for printing */
+       int has_attachments = 0;
 
        struct cdbdata *dmsgtext;
        char *mptr;
@@ -334,6 +338,7 @@ void output_message(char *msgid, int mode, int headers_only)
        long xtime;
        /* */
 
+       strcpy(boundary, "");
        msg_num = atol(msgid);
 
 
@@ -428,6 +433,10 @@ void output_message(char *msgid, int mode, int headers_only)
                                cprintf(" [%s]",buf);
                        cprintf("\n");
                        }
+               else if (ch=='Z') {
+                       has_attachments = 1;
+                       sprintf(boundary, "--%s", buf);
+                       }
                else if (ch=='P') cprintf("path=%s\n",buf);
                else if (ch=='U') cprintf("subj=%s\n",buf);
                else if (ch=='I') cprintf("msgn=%s\n",buf);
@@ -520,7 +529,14 @@ void output_message(char *msgid, int mode, int headers_only)
                while(ch = *mptr++, ch>0) {
                        if (ch == 13) ch = 10;
                        if ( (ch == 10) || (strlen(buf)>250) ) {
-                               cprintf("%s\n", buf);
+                               if (has_attachments) if (!strncmp(buf, boundary, strlen(boundary))) {
+                                       ++current_section;
+                                       }
+                               if (current_section == desired_section) {
+                                       if ( (has_attachments == 0) || (strncmp(buf, boundary, strlen(boundary)))) {
+                                               cprintf("%s\n", buf);
+                                               }
+                                       }
                                strcpy(buf, "");
                                }
                        else {
@@ -872,7 +888,7 @@ void make_message(
        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) */
+       char *boundary) {               /* boundary (if exist attachments) */
 
        FILE *fp;
        int a;
@@ -919,7 +935,7 @@ void make_message(
 
        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);
+       if (boundary[0]!=0) fprintf(fp, "Z%s%c", boundary, 0);
 
        putc('M',fp);
 
@@ -946,7 +962,7 @@ void cmd_ent0(char *entargs)
        int anon_flag = 0;
        int format_type = 0;
        char newusername[256];          /* <bc> */
-       char separator[256];
+       char boundary[256];
 
        int a,b,e;
        int mtsflag = 0;
@@ -957,7 +973,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);
+       extract(boundary, entargs, 4);
 
        /* first check to make sure the request is valid. */
 
@@ -1070,12 +1086,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, separator);
+          make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname, boundary);
        else
           if (CC->fake_username[0])
-             make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username, separator);
+             make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username, boundary);
           else
-             make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "", separator);
+             make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "", boundary);
        save_message(CC->temp,buf,mtsflag,e,1);
         CC->fake_postname[0]='\0';
        return;
index 1a46a3ecf9a68b8852b27dc9a0f2d23c8b2fdf2a..3e783d7b397f25779e37192bca00669a71ea6f0c 100644 (file)
@@ -113,8 +113,8 @@ U       Subject         Optional.  Developers may choose whether they wish to
 X      eXtension field Extension fields are used to carry additional RFC822
                        type lines.  X fields contain the X byte followed by
                        the RFC822 field name, a colon, a space, and the value.
-Z      Separator       If there are MIME attachments following the message
-                       text, the Z field specifies the separator string.
+Z      Boundary        If there are MIME attachments following the message
+                       text, the Z field specifies the boundary string.
   
                        EXAMPLE
 
index 4abd9d53f9ec858d897107c0571c0dff0b98e184..2df5208d0f106d7dfde699d02bf01cd2ed1f8bcc 100644 (file)
@@ -676,7 +676,7 @@ message as anonymous, otherwise 0 for a normal message.
 typically be 0; see the MSG0 command above).
   4  -  Post name.  When postflag is 2, this is the name you are posting as.
 This is an Aide only command.
-  5  -  Separator string to be used when there are MIME attachments following
+  5  -  Boundary string to be used when there are MIME attachments following
 the normal message text.
 
  Possible result codes: