]> granicus.if.org Git - neomutt/commitdiff
[patch-0.94.4i.tlr.get_attachment.1] Create a new
authorThomas Roessler <roessler@does-not-exist.org>
Fri, 28 Aug 1998 00:53:12 +0000 (00:53 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Fri, 28 Aug 1998 00:53:12 +0000 (00:53 +0000)
"get-attachment" function on the compose menu which will
copy an attachment to a temporary file.

OPS
attach.c
compose.c
functions.h
protos.h

diff --git a/OPS b/OPS
index 6979d6150cb36f8c7d64d80258337e495eac55ad..d1ca0fb5aebb4b0e01646d4587c515e1f9887d8f 100644 (file)
--- 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"
index d0a887e1dda3542818eef1a6335c7cfae2c3337e..275ec3d31367bdbde7a002ce9478302cd6471f3b 100644 (file)
--- a/attach.c
+++ b/attach.c
 #include <string.h>
 #include <errno.h>
 
+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)
 {
index c9915f39f6f060287f76c69bc5aaec64f34689d0..f2049f7580fd998169b0d91c1e44834ff2352b5e 100644 (file)
--- 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));
index 9579ec7ca81195ed9e32081280e9a66402648ad4..384c5fd154c6d2c471087c1281924cf0ee54ae3c 100644 (file)
@@ -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" },
index 43b45508edc95f9bb8fa1a358e53f8302460c51b..159f5de684d9d78b07fbc65da27a45e66d83983c 100644 (file)
--- 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 *);