From 0fb62857e6f4c081bf304f04eee55b06122e784d Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 5 Feb 2008 21:13:44 +0000 Subject: [PATCH] New option in the text client to open attachments directly instead of saving them to a temporary file. The fact that most Linux systems now have 'xdg-open' makes this a big win. --- citadel/citadel.rc | 12 ++++++++++++ citadel/commands.c | 5 +++++ citadel/commands.h | 1 + citadel/messages.c | 41 +++++++++++++++++++++++++++++------------ 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/citadel/citadel.rc b/citadel/citadel.rc index ccfccf640..da648888f 100644 --- a/citadel/citadel.rc +++ b/citadel/citadel.rc @@ -137,6 +137,18 @@ remember_passwords=0 # browser you have configured as the system default. #urlcmd=open "%s" +# If OPENCMD is defined, users can hit 'O' after reading a message which +# contains attachments, to open the attachments using that command. This +# allows attachments to be opened directly from the Citadel client without +# having to first save them in a file. The "allow_attachments" option (see +# above) must be enabled in order for this to work. +# +# xdg-open works on most newer Linux systems +opencmd=xdg-open "%s" +# +# This probably will work on a Macintosh +#opencmd=open "%s" + # If GOTMAILCMD is defined, the specified command will be executed. This # might be nice for playing sounds or providing any other type of notification. # diff --git a/citadel/commands.c b/citadel/commands.c index 82db34c9e..d46e7afbc 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -81,6 +81,7 @@ int rc_color_use_bg; int rc_prompt_control = 0; time_t rc_idle_threshold = (time_t)900; char rc_url_cmd[SIZ]; +char rc_open_cmd[SIZ]; char rc_gotmail_cmd[SIZ]; char *gl_string; @@ -772,6 +773,7 @@ void load_command_set(void) rc_ansi_color = 0; rc_color_use_bg = 0; strcpy(rc_url_cmd, ""); + strcpy(rc_open_cmd, ""); strcpy(rc_gotmail_cmd, ""); #ifdef HAVE_OPENSSL rc_encrypt = RC_DEFAULT; @@ -908,6 +910,9 @@ void load_command_set(void) if (!strncasecmp(buf, "urlcmd=", 7)) strcpy(rc_url_cmd, &buf[7]); + if (!strncasecmp(buf, "opencmd=", 7)) + strcpy(rc_open_cmd, &buf[8]); + if (!strncasecmp(buf, "gotmailcmd=", 11)) strcpy(rc_gotmail_cmd, &buf[11]); diff --git a/citadel/commands.h b/citadel/commands.h index cb8757516..f0bf2cd2b 100644 --- a/citadel/commands.h +++ b/citadel/commands.h @@ -64,6 +64,7 @@ void pprintf(const char *format, ...); extern char rc_url_cmd[SIZ]; +extern char rc_open_cmd[SIZ]; extern char rc_gotmail_cmd[SIZ]; extern int lines_printed; extern int rc_remember_passwords; diff --git a/citadel/messages.c b/citadel/messages.c index 2da6b4efb..37a2769a3 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -70,6 +70,7 @@ int msg_arr_size = 0; int num_msgs; char rc_alt_semantics; extern char room_name[]; +extern char tempdir[]; extern unsigned room_flags; extern unsigned room_flags2; extern long highest_msg_read; @@ -1470,8 +1471,9 @@ void readmsgs(CtdlIPC *ipc, char filename[PATH_MAX]; char save_to[PATH_MAX]; void *attachment = NULL; /* Downloaded attachment */ - FILE *dest = NULL; /* Alternate destination other than screen */ + FILE *dest = NULL; /* Alternate destination other than screen */ int r; /* IPC response code */ + static int att_seq = 0; /* Attachment download sequence number */ if (c < 0) b = (num_msgs - 1); @@ -1631,7 +1633,7 @@ RMSGREAD: scr_flush(); && (e != 'q') && (e != 'b') && (e != 'h') && (e != 'r') && (e != 'f') && (e != '?') && (e != 'u') && (e != 'c') && (e != 'y') - && (e != 'i')); + && (e != 'i') && (e != 'o') ); switch (e) { case 's': scr_printf("Stop"); @@ -1666,6 +1668,9 @@ RMSGREAD: scr_flush(); case 'r': scr_printf("Reply"); break; + case 'o': + scr_printf("Open attachments"); + break; case 'f': scr_printf("File"); break; @@ -1711,9 +1716,10 @@ RMSGREAD: scr_flush(); " H Headers (display message headers only)\n"); if (is_mail) scr_printf(" R Reply to this message\n"); - if (rc_allow_attachments) - scr_printf - (" F (save attachments to a file)\n"); + if (rc_allow_attachments) { + scr_printf(" O (Open attachments)\n"); + scr_printf(" F (save attachments to a File)\n"); + } if (!IsEmptyStr(rc_url_cmd)) scr_printf(" U (list URL's for display)\n"); if (!IsEmptyStr(imagecmd) && has_images > 0) @@ -1757,9 +1763,9 @@ RMSGREAD: scr_flush(); if (r / 100 != 2) /* r will be init'ed, FIXME */ goto RMSGREAD; /* the logic here sucks */ break; + case 'o': case 'f': - newprompt("Which section? ", filename, - ((sizeof filename) - 1)); + newprompt("Which section? ", filename, ((sizeof filename) - 1)); r = CtdlIPCAttachmentDownload(ipc, msg_arr[a], filename, &attachment, progress, cmd); if (r / 100 != 2) { @@ -1770,12 +1776,23 @@ RMSGREAD: scr_flush(); * Part 1 won't have a filename; use the * subject of the message instead. IO */ - if (IsEmptyStr(filename)) + if (IsEmptyStr(filename)) { strcpy(filename, reply_subject); - destination_directory(save_to, filename); - save_buffer(attachment, - extract_unsigned_long(cmd, 0), - save_to); + } + if (e == 'o') { /* open attachment */ + mkdir(tempdir, 0700); + snprintf(save_to, sizeof save_to, "%s/%04x.%s", + tempdir, + ++att_seq, + filename); + save_buffer(attachment, extract_unsigned_long(cmd, 0), save_to); + snprintf(cmd, sizeof cmd, rc_open_cmd, save_to); + system(cmd); + } + else { /* save attachment to disk */ + destination_directory(save_to, filename); + save_buffer(attachment, extract_unsigned_long(cmd, 0), save_to); + } } if (attachment) { free(attachment); -- 2.39.2