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)
{
int linelen;
int final_line_is_blank = 0;
+ has_images = 0;
+
sigcaught = 0;
sttybbs(1);
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);
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
*/
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);
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 {
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");
case 'y':
scr_printf("mY next");
break;
+ case 'i':
+ scr_printf("Images");
+ break;
case '?':
scr_printf("? <help>");
break;
(" 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':
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 */