From f58938adf13af45527dd59838ba9782ba10d033c Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Fri, 28 Aug 1998 00:53:12 +0000 Subject: [PATCH] [patch-0.94.4i.tlr.get_attachment.1] Create a new "get-attachment" function on the compose menu which will copy an attachment to a temporary file. --- OPS | 1 + attach.c | 34 ++++++++++++++++++++++++++++++++++ compose.c | 34 ++++++++++++++++++++++++++++++++-- functions.h | 3 ++- protos.h | 1 + 5 files changed, 70 insertions(+), 3 deletions(-) diff --git a/OPS b/OPS index 6979d615..d1ca0fb5 100644 --- a/OPS +++ b/OPS @@ -23,6 +23,7 @@ OP_COMPOSE_EDIT_REPLY_TO "edit the Reply-To field" OP_COMPOSE_EDIT_SUBJECT "edit the subject of this message" OP_COMPOSE_EDIT_TO "edit the TO list" OP_COMPOSE_EDIT_TYPE "edit attachment type" +OP_COMPOSE_GET_ATTACHMENT "get a temporary copy of an attachment" OP_COMPOSE_ISPELL "run ispell on the message" OP_COMPOSE_NEW_MIME "compose new attachment using mailcap entry" OP_COMPOSE_POSTPONE_MESSAGE "save this message to send later" diff --git a/attach.c b/attach.c index d0a887e1..275ec3d3 100644 --- a/attach.c +++ b/attach.c @@ -40,6 +40,40 @@ #include #include +int mutt_get_tmp_attachment (BODY *a) +{ + char type[STRING]; + char tempfile[_POSIX_PATH_MAX]; + rfc1524_entry *entry = rfc1524_new_entry(); + FILE *fpin = NULL, *fpout = NULL; + + if(a->unlink) + return 0; + + snprintf(type, sizeof(type), "%s/%s", TYPE(a), a->subtype); + rfc1524_mailcap_lookup(a, type, entry, 0); + rfc1524_expand_filename(entry->nametemplate, a->filename, + tempfile, sizeof(tempfile)); + + rfc1524_free_entry(&entry); + + if((fpin = fopen(a->filename, "r")) && (fpout = safe_fopen(tempfile, "w"))) + { + mutt_copy_stream (fpin, fpout); + FREE(&a->filename); + a->filename = safe_strdup(tempfile); + a->unlink = 1; + } + else + mutt_perror(fpin ? tempfile : a->filename); + + if(fpin) fclose(fpin); + if(fpout) fclose(fpout); + + return a->unlink ? 0 : -1; +} + + /* return 1 if require full screen redraw, 0 otherwise */ int mutt_compose_attachment (BODY *a) { diff --git a/compose.c b/compose.c index c9915f39..f2049f75 100644 --- a/compose.c +++ b/compose.c @@ -746,8 +746,21 @@ int mutt_send_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_UPDATE_ENCODING: CHECK_COUNT; - mutt_update_encoding(idx[menu->current]->content); - menu->redraw = REDRAW_CURRENT; + if(menu->tagprefix) + { + BODY *top; + for(top = msg->content; top; top = top->next) + { + if(top->tagged) + mutt_update_encoding(top); + } + menu->redraw = REDRAW_FULL; + } + else + { + mutt_update_encoding(idx[menu->current]->content); + menu->redraw = REDRAW_CURRENT; + } break; case OP_COMPOSE_EDIT_TYPE: @@ -825,6 +838,23 @@ int mutt_send_menu (HEADER *msg, /* structure for new message */ menu->redraw = REDRAW_INDEX; break; + case OP_COMPOSE_GET_ATTACHMENT: + CHECK_COUNT; + if(menu->tagprefix) + { + BODY *top; + for(top = msg->content; top; top = top->next) + { + if(top->tagged) + mutt_get_tmp_attachment(top); + } + menu->redraw = REDRAW_FULL; + } + else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0) + menu->redraw = REDRAW_CURRENT; + + break; + case OP_COMPOSE_RENAME_FILE: CHECK_COUNT; strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname)); diff --git a/functions.h b/functions.h index 9579ec7c..384c5fd1 100644 --- a/functions.h +++ b/functions.h @@ -322,7 +322,8 @@ struct binding_t OpCompose[] = { { "edit-encoding", OP_COMPOSE_EDIT_ENCODING, "\005" }, { "edit-from", OP_COMPOSE_EDIT_FROM, "\033f" }, { "edit-fcc", OP_COMPOSE_EDIT_FCC, "f" }, - { "filter-entry", OP_FILTER, "F" }, + { "filter-entry", OP_FILTER, "F" }, + { "get-attachment", OP_COMPOSE_GET_ATTACHMENT, "G" }, { "ispell", OP_COMPOSE_ISPELL, "i" }, { "print-entry", OP_PRINT, "l" }, { "redraw-screen", OP_REDRAW, "\014" }, diff --git a/protos.h b/protos.h index 43b45508..159f5de6 100644 --- a/protos.h +++ b/protos.h @@ -222,6 +222,7 @@ int mutt_enter_string (unsigned char *, size_t, int, int, int); int mutt_get_field (char *, char *, size_t, int); int mutt_get_password (char *, char *, size_t); int mutt_get_postponed (CONTEXT *, HEADER *, HEADER **); +int mutt_get_tmp_attachment (BODY *); int mutt_index_menu (int); int mutt_invoke_sendmail (ADDRESS *, ADDRESS *, ADDRESS *, const char *, int); int mutt_is_autoview (char *); -- 2.40.0