* Image viewer code for the text client. Hit 'I' to view an image
authorMichael Hampton <io_error@uncensored.citadel.org>
Sun, 21 Dec 2003 00:19:41 +0000 (00:19 +0000)
committerMichael Hampton <io_error@uncensored.citadel.org>
Sun, 21 Dec 2003 00:19:41 +0000 (00:19 +0000)
  attached to a file.  Hey aahz, this code actually works!

citadel/ChangeLog
citadel/citadel.rc
citadel/citadel_decls.h
citadel/commands.c
citadel/messages.c

index 465520691f7932afc6dc0e9088a14cd58d46271a..fb0dbbe734caa0b4e95094d3695315b2a3e70980 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 613.2  2003/12/21 00:19:41  error
+ * Image viewer code for the text client.  Hit 'I' to view an image
+   attached to a file.  Hey aahz, this code actually works!
+
  Revision 613.1  2003/12/19 04:33:52  ajc
  * Changes to auto-expunge algorithm to support correct behavior in
    some IMAP clients while moving messages.
@@ -5165,3 +5169,5 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
+
index f768b2970112704023e9533c2e109503031f6839..7987a539dd4cdf5b6d12ee5adfd79655a2b972fc 100644 (file)
@@ -137,6 +137,10 @@ remember_passwords=0
 #
 #gotmailcmd=play gotmail.wav
 
+# If IMAGECMD is defined, users can hit 'I' to view images attached to a
+# message.  (Do not enable this command for public clients.)
+#
+#imagecmd=xv "%s"
 
 # MESSAGE READING SEMANTICS (experimental)
 #
index ee3a658cd758c78da77f058611ded0df8bfbf245..0b1181eab9f53e0ec1f316781fa02e8c013430c3 100644 (file)
@@ -9,6 +9,7 @@ extern unsigned userflags;
 extern char sigcaught;
 extern char editor_paths[MAX_EDITORS][SIZ];
 extern char printcmd[SIZ];
+extern char imagecmd[SIZ];
 extern char have_xterm;
 extern char rc_username[USERNAME_SIZE];
 extern char rc_password[32];
index a057577f782b251341704d71a7284f8ef22dfe83..bd5cff14f9f1fd96524fa696206ef8925f2652f1 100644 (file)
@@ -736,6 +736,7 @@ void load_command_set(void)
        for (i = 0; i < MAX_EDITORS; i++)
                strcpy(editor_paths[i], "");
        strcpy(printcmd, "");
+       strcpy(imagecmd, "");
        strcpy(rc_username, "");
        strcpy(rc_password, "");
        rc_floor_mode = 0;
@@ -824,6 +825,9 @@ void load_command_set(void)
                if (!strncasecmp(buf, "printcmd=", 9))
                        strcpy(printcmd, &buf[9]);
 
+               if (!strncasecmp(buf, "imagecmd=", 9))
+                       strcpy(imagecmd, &buf[9]);
+
                if (!strncasecmp(buf, "expcmd=", 7))
                        strcpy(rc_exp_cmd, &buf[7]);
 
index 2a814678ceb877d2e17ed78650865d144bd68ea4..57a13f548ece503b7b30548499b79f2308ac5a76 100644 (file)
@@ -90,6 +90,9 @@ extern int editor_pid;
 extern CtdlIPC *ipc_for_signal_handlers;       /* KLUDGE cover your eyes */
 int num_urls = 0;
 char urls[MAXURLS][SIZ];
+char imagecmd[SIZ];
+int has_images = 0;                            /* Current msg has images */
+struct parts *last_message_parts = NULL;       /* Parts from last msg */
 
 void ka_sigcatch(int signum)
 {
@@ -372,6 +375,8 @@ int read_message(CtdlIPC *ipc,
        int linelen;
        int final_line_is_blank = 0;
 
+       has_images = 0;
+
        sigcaught = 0;
        sttybbs(1);
 
@@ -685,10 +690,15 @@ int read_message(CtdlIPC *ipc,
                                scr_printf("%s", ptr->filename);
                                color(DIM_WHITE);
                                scr_printf(" (%s, %ld bytes)\n", ptr->mimetype, ptr->length);
+                               if (!strncmp(ptr->mimetype, "image/", 6))
+                                       has_images++;
                        }
                }
        }
 
+       /* Save the attachments info for later */
+       last_message_parts = message->attachments;
+
        /* Now we're done */
        free(message->text);
        free(message);
@@ -1291,6 +1301,75 @@ void list_urls(CtdlIPC *ipc)
        scr_printf("\n");
 }
 
+/*
+ * View an image attached to a message
+ */
+void image_view(CtdlIPC *ipc, unsigned long msg)
+{
+       char selected_part[SIZ];
+       struct parts *ptr = last_message_parts;
+       int found = 0;
+
+       scr_printf("\n");
+       /* List available parts */
+       for (ptr = last_message_parts; ptr; ptr = ptr->next) {
+               if ((!strcasecmp(ptr->disposition, "attachment")
+                  || !strcasecmp(ptr->disposition, "inline"))
+                  && !strncmp(ptr->mimetype, "image/", 6)) {
+                       color(DIM_WHITE);
+                       scr_printf("Part ");
+                       color(BRIGHT_MAGENTA);
+                       scr_printf("%s", ptr->number);
+                       if (!found) {
+                               found = 1;
+                               strncpy(selected_part, ptr->number, SIZ-1);
+                       }
+                       color(DIM_WHITE);
+                       scr_printf(": ");
+                       color(BRIGHT_CYAN);
+                       scr_printf("%s", ptr->filename);
+                       color(DIM_WHITE);
+                       scr_printf(" (%s, %ld bytes)\n", ptr->mimetype, ptr->length);
+               }
+       }
+
+       while (found) {
+               found = 0;
+               strprompt("View which part (0 when done)", selected_part, SIZ-1);
+               for (ptr = last_message_parts; ptr; ptr = ptr->next) {
+                       if ((!strcasecmp(ptr->disposition, "attachment")
+                          || !strcasecmp(ptr->disposition, "inline"))
+                          && !strncmp(ptr->mimetype, "image/", 6)
+                          && !strcmp(ptr->number, selected_part)) {
+                               char tmp[PATH_MAX];
+                               char buf[SIZ];
+                               void *file = NULL; /* The downloaded file */
+                               int r;
+
+                               // view image
+                               found = 1;
+                               r = CtdlIPCAttachmentDownload(ipc, msg, selected_part, &file, progress, buf);
+                               if (r / 100 != 2) {
+                                       scr_printf("%s\n", buf);
+                               } else {
+                                       size_t len;
+
+                                       len = (size_t)extract_long(buf, 0);
+                                       progress(len, len);
+                                       scr_flush();
+                                       strcpy(tmp, tmpnam(NULL));
+                                       save_buffer(file, len, tmp);
+                                       free(file);
+                                       snprintf(buf, sizeof buf, imagecmd, tmp);
+                                       system(buf);
+                                       unlink(tmp);
+                               }
+                       }
+               }
+       }
+}
+
 /*
  * Read the messages in the current room
  */
@@ -1370,6 +1449,10 @@ RAGAIN:          pagin = ((arcflag == 0)
                        screenwidth = 80;
                }
 
+               /* clear parts list */
+               /* FIXME free() the old parts list */
+               last_message_parts = NULL;
+
                /* now read the message... */
                e = read_message(ipc, msg_arr[a], pagin, dest);
 
@@ -1430,6 +1513,8 @@ RMSGREAD: scr_flush();
                        keyopt("<B>ack <A>gain <Q>uote <R>eply <N>ext <S>top m<Y> next ");
                        if (rc_url_cmd[0] && num_urls)
                                keyopt("<U>RLview ");
+                       if (has_images > 0 && strlen(imagecmd) > 0)
+                               keyopt("<I>mages ");
                        keyopt("<?>help -> ");
 
                        do {
@@ -1458,11 +1543,15 @@ RMSGREAD:       scr_flush();
                                    if ((e == 'u')
                                        && (strlen(rc_url_cmd) == 0))
                                        e = 0;
+                               if ((e == 'i')
+                                       && (!strlen(imagecmd) || !has_images))
+                                       e = 0;
                        } while ((e != 'a') && (e != 'n') && (e != 's')
                                 && (e != 'd') && (e != 'm') && (e != 'p')
                                 && (e != 'q') && (e != 'b') && (e != 'h')
                                 && (e != 'r') && (e != 'f') && (e != '?')
-                                && (e != 'u') && (e != 'c') && (e != 'y'));
+                                && (e != 'u') && (e != 'c') && (e != 'y')
+                                && (e != 'i'));
                        switch (e) {
                        case 's':
                                scr_printf("Stop");
@@ -1506,6 +1595,9 @@ RMSGREAD: scr_flush();
                        case 'y':
                                scr_printf("mY next");
                                break;
+                       case 'i':
+                               scr_printf("Images");
+                               break;
                        case '?':
                                scr_printf("? <help>");
                                break;
@@ -1543,6 +1635,8 @@ RMSGREAD: scr_flush();
                                    (" F  (save attachments to a file)\n");
                        if (strlen(rc_url_cmd) > 0)
                                scr_printf(" U  (list URL's for display)\n");
+                       if (strlen(imagecmd) > 0 && has_images > 0)
+                               scr_printf(" I  Image viewer\n");
                        scr_printf("\n");
                        goto RMSGREAD;
                case 'p':
@@ -1626,6 +1720,9 @@ RMSGREAD: scr_flush();
                case 'u':
                        list_urls(ipc);
                        goto RMSGREAD;
+               case 'i':
+                       image_view(ipc, msg_arr[a]);
+                       goto RMSGREAD;
            case 'y':
           { /* hack hack hack */
             /* find the next message by me, stay here if we find nothing */