#include "citadel.h"
#include "messages.h"
#include "commands.h"
+#include "rooms.h"
+#include "tools.h"
#define MAXWORDBUF 256
#define MAXMSGS 512
char pagin;
char cmd[256];
char targ[ROOMNAMELEN];
+ char filename[256];
signal(SIGINT,SIG_IGN);
signal(SIGQUIT,SIG_IGN);
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;
/* 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;
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","");
}
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]);
}
+/* 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];
int a,b;
int packet;
FILE *tpipe = NULL;
- FILE *savefp = NULL;
int proto_pid;
int broken = 0;
}
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);