From: Michael Hampton Date: Sun, 21 Dec 2003 00:19:41 +0000 (+0000) Subject: * Image viewer code for the text client. Hit 'I' to view an image X-Git-Tag: v7.86~5669 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=6e3a9d6d8543eefb903e1cbccfba15412adff7f9;p=citadel.git * Image viewer code for the text client. Hit 'I' to view an image attached to a file. Hey aahz, this code actually works! --- diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 465520691..fb0dbbe73 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import + + diff --git a/citadel/citadel.rc b/citadel/citadel.rc index f768b2970..7987a539d 100644 --- a/citadel/citadel.rc +++ b/citadel/citadel.rc @@ -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) # diff --git a/citadel/citadel_decls.h b/citadel/citadel_decls.h index ee3a658cd..0b1181eab 100644 --- a/citadel/citadel_decls.h +++ b/citadel/citadel_decls.h @@ -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]; diff --git a/citadel/commands.c b/citadel/commands.c index a057577f7..bd5cff14f 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -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]); diff --git a/citadel/messages.c b/citadel/messages.c index 2a814678c..57a13f548 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -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("ack gain uote eply ext top m next "); if (rc_url_cmd[0] && num_urls) keyopt("RLview "); + if (has_images > 0 && strlen(imagecmd) > 0) + keyopt("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("? "); 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 */