New option in the text client to open attachments
authorArt Cancro <ajc@citadel.org>
Tue, 5 Feb 2008 21:13:44 +0000 (21:13 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 5 Feb 2008 21:13:44 +0000 (21:13 +0000)
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
citadel/commands.c
citadel/commands.h
citadel/messages.c

index ccfccf640652d977ee066c9161f12e68c39730ae..da648888fbe5b29d1ba0ab6e0435adf022c29d31 100644 (file)
@@ -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.
 #
index 82db34c9e7311647c97e0b2d4181ba9146a931f1..d46e7afbc141f7f3d9ebfef0a3b650fe18268a08 100644 (file)
@@ -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]);
 
index cb8757516fe73ec4e62b980e69a1925fbc91eb65..f0bf2cd2b54e6a6409c1c35de810f02ae613a736 100644 (file)
@@ -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;
index 2da6b4efba02100735cf05281d096bb09f058629..37a2769a392da68e06e07a24fcc599ea451e22b3 100644 (file)
@@ -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);