]> code.citadel.org Git - citadel.git/blobdiff - citadel/messages.c
More changes to get attachments working.
[citadel.git] / citadel / messages.c
index 051f218f5db2b8406d7de4bc529544de418a8f8a..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>
@@ -16,6 +16,7 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include "citadel.h"
+#include "messages.h"
 
 #define MAXWORDBUF 256
 #define MAXMSGS 512
@@ -25,20 +26,19 @@ struct cittext {
        char text[MAXWORDBUF];
        };
 
-long finduser();
-char inkey();
-void sttybbs();
-int struncmp();
-int fmout();
-int haschar();
-int checkpagin();
-void getline();
-void formout();
-int yesno();
-void newprompt();
-int file_checksum();
-void color();
-void do_edit();
+char inkey(void);
+void sttybbs(int cmd);
+int struncmp(char *lstr, char *rstr, int len);
+int fmout(int width, FILE *fp, char pagin, int height, int starting_lp, char subst);
+int haschar(char *st, int ch);
+int checkpagin(int lp, int pagin, int height);
+void getline(char *string, int lim);
+void formout(char *name);
+int yesno(void);
+void newprompt(char *prompt, char *str, int len);
+int file_checksum(char *filename);
+void color(int colornum);
+void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd);
 
 char reply_to[512];
 long msg_arr[MAXMSGS];
@@ -46,7 +46,7 @@ int num_msgs;
 extern char room_name[];
 extern unsigned room_flags;
 extern long highest_msg_read;
-extern struct serv_info serv_info;
+extern struct CtdlServInfo serv_info;
 extern char temp[];
 extern char temp2[];
 extern int screenwidth;
@@ -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;
 
@@ -319,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];
@@ -379,8 +380,6 @@ int read_message(long int num, char pagin)  /* Read a message from the server */
                if (!struncmp(buf,"from=",5)) {
                        printf("from %s ",&buf[5]);
                        }
-               if (!struncmp(buf,"path=",5))
-                       strcpy(reply_to,&buf[5]);
                if (!struncmp(buf,"subj=",5))
                        strcpy(m_subject,&buf[5]);
                if ((!struncmp(buf,"hnod=",5)) 
@@ -402,7 +401,7 @@ int read_message(long int num, char pagin)  /* Read a message from the server */
                                {
                                strcpy(reply_to,from);
                                }
-                       else if (haschar(&buf[5],'.')==0) {
+                       else {
                                sprintf(reply_to,"%s @ %s",from,&buf[5]);
                                }
                        }
@@ -519,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 */
@@ -653,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);
@@ -709,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;
@@ -779,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') {
@@ -838,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) {
@@ -860,7 +871,6 @@ int line,qstart,qend;
        fprintf(tfile," \n");
        fclose(qfile);
        fclose(tfile);
-       unlink(temp2);
        chmod(temp,0666);
        }
 
@@ -882,7 +892,7 @@ void readmsgs(int c, int rdir, int q)       /* read contents of a room */
        signal(SIGINT,SIG_IGN);
        signal(SIGQUIT,SIG_IGN);
 
-       if (c<0) b=(MSGSPERRM-1);
+       if (c<0) b=(MAXMSGS-1);
        else b=0;
 
        sprintf(prtfile,"/tmp/CPrt%d",getpid());
@@ -916,7 +926,7 @@ void readmsgs(int c, int rdir, int q)       /* read contents of a room */
        start = ( (rdir==1) ? 0 : (num_msgs-1) );
        for (a=start; ((a<num_msgs)&&(a>=0)); a=a+rdir) {
                while (msg_arr[a]==0L) {
-                       a=a+rdir; if ((a==MSGSPERRM)||(a==(-1))) return;
+                       a=a+rdir; if ((a==MAXMSGS)||(a==(-1))) return;
                        }
 
 RAGAIN:                pagin=((arcflag==0)&&(quotflag==0)&&