]> code.citadel.org Git - citadel.git/blobdiff - citadel/msgbase.c
More changes to get attachments working.
[citadel.git] / citadel / msgbase.c
index 8274ca1dac2bd08803625661f149ffcf071281a4..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) {
@@ -315,12 +315,16 @@ 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];
        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);
@@ -498,7 +507,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);
@@ -516,22 +525,26 @@ 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 (len>=250) {
-                               len = 0;
-                               /* cprintf("%c", ch); */
-                               cprintf("%c", 10);
+                       if ( (ch == 10) || (strlen(buf)>250) ) {
+                               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 {
+                               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
@@ -866,15 +879,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 *boundary) {               /* boundary (if exist attachments) */
+
        FILE *fp;
        int a;
        long now;
@@ -918,8 +933,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 (boundary[0]!=0) fprintf(fp, "Z%s%c", boundary, 0);
 
        putc('M',fp);
 
@@ -946,6 +962,7 @@ void cmd_ent0(char *entargs)
        int anon_flag = 0;
        int format_type = 0;
        char newusername[256];          /* <bc> */
+       char boundary[256];
 
        int a,b,e;
        int mtsflag = 0;
@@ -956,6 +973,7 @@ void cmd_ent0(char *entargs)
        extract(recipient,entargs,1);
        anon_flag = extract_int(entargs,2);
        format_type = extract_int(entargs,3);
+       extract(boundary, entargs, 4);
 
        /* first check to make sure the request is valid. */
 
@@ -1068,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);
+          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);
+             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, "");
+             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;