From 5e73b14b909acb69a7595831119d06ba06238c85 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 22 Sep 1998 02:35:03 +0000 Subject: [PATCH] More changes to get attachments working. --- citadel/citadel.rc | 4 ++++ citadel/commands.c | 7 ++++++- citadel/messages.c | 21 ++++++++++++++------- citadel/msgbase.c | 36 ++++++++++++++++++++++++++---------- citadel/techdoc/hack.txt | 4 ++-- citadel/techdoc/session.txt | 2 +- 6 files changed, 53 insertions(+), 21 deletions(-) diff --git a/citadel/citadel.rc b/citadel/citadel.rc index ab74471b0..661f96505 100644 --- a/citadel/citadel.rc +++ b/citadel/citadel.rc @@ -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. # diff --git a/citadel/commands.c b/citadel/commands.c index 03ddacfcd..5ca24d2db 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -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]); diff --git a/citadel/messages.c b/citadel/messages.c index 04501a5ea..fd08ea0af 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -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') { diff --git a/citadel/msgbase.c b/citadel/msgbase.c index cef37b9e3..af13aeadf 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -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; a1) { - /* 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]; /* */ - 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; diff --git a/citadel/techdoc/hack.txt b/citadel/techdoc/hack.txt index 1a46a3ecf..3e783d7b3 100644 --- a/citadel/techdoc/hack.txt +++ b/citadel/techdoc/hack.txt @@ -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 diff --git a/citadel/techdoc/session.txt b/citadel/techdoc/session.txt index 4abd9d53f..2df5208d0 100644 --- a/citadel/techdoc/session.txt +++ b/citadel/techdoc/session.txt @@ -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: -- 2.30.2