]> code.citadel.org Git - citadel.git/commitdiff
messages.c: implemented client download of MIME attachments
authorArt Cancro <ajc@citadel.org>
Tue, 2 Feb 1999 00:49:41 +0000 (00:49 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 2 Feb 1999 00:49:41 +0000 (00:49 +0000)
citadel/ChangeLog
citadel/messages.c
citadel/rooms.c
citadel/rooms.h
citadel/tasklist.txt

index dfb75e731c3f98333eb108bc806c4c13e9f8c430..9507975f43e0a9752ff1cf76929ee3dbec568dcd 100644 (file)
@@ -1,3 +1,6 @@
+Mon Feb  1 19:48:04 EST 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+       * messages.c: implemented client download of MIME attachments
+
 Sun Jan 31 18:29:18 EST 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Added qpdecode.c to the distribution (decodes quoted-printable)
        * Finished the MIME parser
index 92c5b1eb2d81031434d27fac56bf89694336bf9b..7fd56a945c6a34609105fff8538e0d127dbb6b75 100644 (file)
@@ -19,6 +19,8 @@
 #include "citadel.h"
 #include "messages.h"
 #include "commands.h"
+#include "rooms.h"
+#include "tools.h"
 
 #define MAXWORDBUF 256
 #define MAXMSGS 512
@@ -895,6 +897,7 @@ void readmsgs(int c, int rdir, int q)       /* read contents of a room */
        char pagin;
        char cmd[256];
        char targ[ROOMNAMELEN];
+       char filename[256];
 
        signal(SIGINT,SIG_IGN);
        signal(SIGQUIT,SIG_IGN);
@@ -994,6 +997,7 @@ RMSGREAD:   fflush(stdout);
                        printf("(%d) ",num_msgs-a-1);
                        if (is_mail==1) printf("<R>eply ");
                        if (strlen(printcmd)>0) printf("<P>rint ");
+                       if (rc_allow_attachments) printf("<F>ile ");
                printf("<B>ack <A>gain <Q>uote <H>eader <N>ext <S>top -> ");
                        do {
                                lines_printed = 2;
@@ -1007,10 +1011,11 @@ RMSGREAD:       fflush(stdout);
 /* print only if available */  if ((e=='p')&&(strlen(printcmd)==0)) e=0;
 /* can't move from Mail> */    if ((e=='m')&&(is_mail==1)) e=0;
 /* can't reply in public rms */        if ((e=='r')&&(is_mail!=1)) e=0;
+/* can't file if not allowed */        if ((e=='f')&&(rc_allow_attachments==0)) e=0;
                                } while((e!='a')&&(e!='n')&&(e!='s')
                                        &&(e!='d')&&(e!='m')&&(e!='p')
                                        &&(e!='q')&&(e!='b')&&(e!='h')
-                                       &&(e!='r'));
+                                       &&(e!='r')&&(e!='f'));
                        switch(e) {
                                case 's':       printf("Stop\r");       break;
                                case 'a':       printf("Again\r");      break;
@@ -1022,6 +1027,8 @@ RMSGREAD: fflush(stdout);
                                case 'b':       printf("Back\r");       break;
                                case 'h':       printf("Header\r");     break;
                                case 'r':       printf("Reply\r");      break;
+                               case 'f':       printf("File attachment\r");
+                                                                       break;
                                }
                        if (userflags & US_DISAPPEAR)
                                printf("%75s\r","");
@@ -1061,6 +1068,21 @@ RMSGREAD:        fflush(stdout);
                                        }
                                if (cmd[0]!='2') goto RMSGREAD;
                                break;
+                  case 'f':    newprompt("Which section? ", filename,
+                                       ((sizeof filename) -1));
+                               snprintf(cmd, sizeof cmd,
+                                       "OPNA %ld|%s", msg_arr[a], filename);
+                               serv_puts(cmd);
+                               serv_gets(cmd);
+                               if (cmd[0]=='2') {
+                                       extract(filename, &cmd[4], 2);
+                                       download_to_local_disk(filename,
+                                               extract_int(&cmd[4], 0));
+                                       }
+                               else {
+                                       printf("%s\n",&cmd[4]);
+                                       }
+                               goto RMSGREAD;
                   case 'd':    printf("*** Delete this message? ");
                                if (yesno()==1) {
                                        sprintf(cmd,"DELE %ld",msg_arr[a]);
index b3df62d33df33656a1460a0ee7168d59a9781d57..551add113d7792bf08fc952bf0f9cb4942d27d2f 100644 (file)
@@ -525,18 +525,75 @@ void ungoto(void) {
        }
 
 
+/* Here's the code for simply transferring the file to the client,
+ * for folks who have their own clientware.  It's a lot simpler than
+ * the [XYZ]modem code below...
+ * (This function assumes that a download file is already open on the server)
+ */
+void download_to_local_disk(char *filename, long total_bytes)
+{
+       char buf[256];
+       char dbuf[4096];
+       long transmitted_bytes = 0L;
+       long aa,bb;
+       FILE *savefp;
+       int broken = 0;
+       int packet;
+
+       printf("Enter the name of the directory to save '%s'\n",
+               filename);
+       printf("to, or press return for the current directory.\n");
+       newprompt("Directory: ",dbuf,256);
+       if (strlen(dbuf)==0) strcpy(dbuf,".");
+       strcat(dbuf,"/");
+       strcat(dbuf,filename);
+       
+       savefp = fopen(dbuf,"w");
+       if (savefp == NULL) {
+               printf("Cannot open '%s': %s\n",dbuf,strerror(errno));
+               /* close the download file at the server */
+               serv_puts("CLOS");
+               serv_gets(buf);
+               if (buf[0]!='2') {
+                       printf("%s\n",&buf[4]);
+                       }
+               return;
+               }
+       progress(0,total_bytes);
+       while ( (transmitted_bytes < total_bytes) && (broken == 0) ) {
+               bb = total_bytes - transmitted_bytes;
+               aa = ((bb < 4096) ? bb : 4096);
+               sprintf(buf,"READ %ld|%ld",transmitted_bytes,aa);
+               serv_puts(buf);
+               serv_gets(buf);
+               if (buf[0]!='6') {
+                       printf("%s\n",&buf[4]);
+                       return;
+                       }
+               packet = extract_int(&buf[4],0);
+               serv_read(dbuf,packet);
+               if (fwrite(dbuf,packet,1,savefp) < 1) broken = 1;
+               transmitted_bytes = transmitted_bytes + (long)packet;
+               progress(transmitted_bytes,total_bytes);
+               }
+       fclose(savefp);
+       /* close the download file at the server */
+       serv_puts("CLOS");
+       serv_gets(buf);
+       if (buf[0]!='2') {
+               printf("%s\n",&buf[4]);
+               }
+       return;
+       }
+
+
 /*
  * download()  -  download a file or files.  The argument passed to this
  *                function determines which protocol to use.
+ *  proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
  */
 void download(int proto)
 {
-
-/*
-  - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
-*/
-
-
        char buf[256];
        char dbuf[4096];
        char filename[256];
@@ -546,7 +603,6 @@ void download(int proto)
        int a,b;
        int packet;
        FILE *tpipe = NULL;
-       FILE *savefp = NULL;
        int proto_pid;
        int broken = 0;
 
@@ -566,59 +622,13 @@ void download(int proto)
                }
        total_bytes = extract_long(&buf[4],0);
 
-
-       /* Here's the code for simply transferring the file to the client,
-        * for folks who have their own clientware.  It's a lot simpler than
-        * the [XYZ]modem code below...
-        */
+       /* Save to local disk, for folks with their own copy of the client */
        if (proto == 5) {
-               printf("Enter the name of the directory to save '%s'\n",
-                       filename);
-               printf("to, or press return for the current directory.\n");
-               newprompt("Directory: ",dbuf,256);
-               if (strlen(dbuf)==0) strcpy(dbuf,".");
-               strcat(dbuf,"/");
-               strcat(dbuf,filename);
-               
-               savefp = fopen(dbuf,"w");
-               if (savefp == NULL) {
-                       printf("Cannot open '%s': %s\n",dbuf,strerror(errno));
-                       /* close the download file at the server */
-                       serv_puts("CLOS");
-                       serv_gets(buf);
-                       if (buf[0]!='2') {
-                               printf("%s\n",&buf[4]);
-                               }
-                       return;
-                       }
-               progress(0,total_bytes);
-               while ( (transmitted_bytes < total_bytes) && (broken == 0) ) {
-                       bb = total_bytes - transmitted_bytes;
-                       aa = ((bb < 4096) ? bb : 4096);
-                       sprintf(buf,"READ %ld|%ld",transmitted_bytes,aa);
-                       serv_puts(buf);
-                       serv_gets(buf);
-                       if (buf[0]!='6') {
-                               printf("%s\n",&buf[4]);
-                               return;
-                               }
-                       packet = extract_int(&buf[4],0);
-                       serv_read(dbuf,packet);
-                       if (fwrite(dbuf,packet,1,savefp) < 1) broken = 1;
-                       transmitted_bytes = transmitted_bytes + (long)packet;
-                       progress(transmitted_bytes,total_bytes);
-                       }
-               fclose(savefp);
-               /* close the download file at the server */
-               serv_puts("CLOS");
-               serv_gets(buf);
-               if (buf[0]!='2') {
-                       printf("%s\n",&buf[4]);
-                       }
+               download_to_local_disk(filename, total_bytes);
                return;
                }
 
-
+       /* Meta-download for public clients */
        mkdir(tempdir,0700);
        snprintf(buf,sizeof buf,"%s/%s",tempdir,filename);
        mkfifo(buf, 0777);
index 631651aa450a01bd9cbac1813c5c143c156bdef7..8953c43734c411605759ee547ad14827f6ed15ed 100644 (file)
@@ -18,6 +18,8 @@ void create_floor(void);
 void edit_floor(void);
 void kill_floor(void);
 void enter_bio(void);
+void download_to_local_disk(char *, long);
+
 
 /* 
  * This struct holds a list of rooms for client display.
index 61804edadb16f6a6fb3f24f53c96e08dd652958b..a2297b256c53b43aecece03545ebfec3452dc25a 100644 (file)
@@ -1,10 +1,12 @@
 Priority items
 --------------
-* There's a memory leak in the server.  Fix it.
+* There's a memory leak in the server.  Fix it.  (Is there?)
 
 Important items
 ---------------
 * In the client, make <G>oto go directly to Mail> when there's new mail.
+* In the client, when a user hits <F>ile to download an attachment, list the
+  available attachments before prompting for which one to download.
 
 Honeydew items
 --------------