]> code.citadel.org Git - citadel.git/blobdiff - citadel/messages.c
More changes to get attachments working.
[citadel.git] / citadel / messages.c
index 6628409d2226ff1c1398b46f97bc435fd89e0c6f..fd08ea0afad2a69e491e7d74ad6b13cfb1746dca 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Citadel/UX message support routines
- * see copyright.doc for copyright information
+ * see copyright.txt for copyright information
  */
 
 #include <stdlib.h>
@@ -26,7 +26,6 @@ struct cittext {
        char text[MAXWORDBUF];
        };
 
-long finduser(int file, char *name);
 char inkey(void);
 void sttybbs(int cmd);
 int struncmp(char *lstr, char *rstr, int len);
@@ -62,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;
 
@@ -320,8 +320,8 @@ void citedit(FILE *fp, long int base_pos)
        }
 
 
-int read_message(long int num, char pagin)     /* Read a message from the server */
-                               /* message number */
+int read_message(long int num, char pagin) /* Read a message from the server */
+                                          /* message number */
                /* 0 = normal read, 1 = read with pagination, 2 = header */
 {
        char buf[256];
@@ -518,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 */
@@ -652,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);
@@ -708,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;
@@ -778,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') {
@@ -837,7 +843,13 @@ FILE *qfile,*tfile;
 char buf[128];
 int line,qstart,qend;
 
+       /* Unlink the second temp file as soon as it's opened, so it'll get
+        * deleted even if the program dies
+        */
        qfile = fopen(temp2,"r");
+       unlink(temp2);
+
+       /* Display the quotable text with line numbers added */
        line = 0;
        fgets(buf,128,qfile);
        while (fgets(buf,128,qfile)!=NULL) {
@@ -859,7 +871,6 @@ int line,qstart,qend;
        fprintf(tfile," \n");
        fclose(qfile);
        fclose(tfile);
-       unlink(temp2);
        chmod(temp,0666);
        }