]> granicus.if.org Git - neomutt/commitdiff
Unified edit-type function for the index, compose, and
authorThomas Roessler <roessler@does-not-exist.org>
Sat, 8 Jan 2000 09:38:10 +0000 (09:38 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Sat, 8 Jan 2000 09:38:10 +0000 (09:38 +0000)
receive-attachment menus.  Mostly by Michael Elkins.

OPS
commands.c
compose.c
curs_main.c
functions.h
protos.h
recvattach.c

diff --git a/OPS b/OPS
index 88390c82e9b94d673c8af973ed953281c19ace89..a4e8fa758cf9b52c578dd20c1dab251f292088c9 100644 (file)
--- a/OPS
+++ b/OPS
@@ -27,7 +27,7 @@ OP_COMPOSE_EDIT_MIME "edit attachment using mailcap entry"
 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_EDIT_TYPE "edit attachment content 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"
index 89b54f4a42dae74c1259971abc40cbfd1d7ed0c0..36d0ec54db70bd1838a45cfdc2f2c4e9e529d2b1 100644 (file)
@@ -750,3 +750,55 @@ void mutt_version (void)
 {
   mutt_message ("Mutt %s (%s)", MUTT_VERSION, ReleaseDate);
 }
+
+void mutt_edit_content_type (HEADER *h, BODY *b)
+{
+  char buf[LONG_STRING];
+  char tmp[STRING];
+  PARAMETER *p;
+  
+  snprintf (buf, sizeof (buf), "%s/%s", TYPE (b), b->subtype);
+  if (b->parameter)
+  {
+    size_t l;
+    
+    for (p = b->parameter; p; p = p->next)
+    {
+      l = strlen (buf);
+
+      rfc822_cat (tmp, sizeof (tmp), p->value, MimeSpecials);
+      snprintf (buf + l, sizeof (buf) - l, "; %s=%s", p->attribute, tmp);
+    }
+  }
+  
+  if (mutt_get_field ("Content-Type: ", buf, sizeof (buf), 0) != 0 ||
+      buf[0] == 0)
+    return;
+  
+  /* clean up previous junk */
+  mutt_free_parameter (&b->parameter);
+  FREE (&b->subtype);
+  
+  mutt_parse_content_type (buf, b);
+  
+  mutt_message ("Content-Type changed to %s/%s.", TYPE (b),
+               NONULL (b->subtype));
+  
+  if (!is_multipart (b) && b->parts)
+    mutt_free_body (&b->parts);
+  if (!mutt_is_message_type (b->type, b->subtype) && b->hdr)
+  {
+    b->hdr->content = NULL;
+    mutt_free_header (&b->hdr);
+  }
+
+#ifdef _PGPPATH
+  if (h)
+  {
+    if (h->content == b)
+      h->pgp = 0;
+    h->pgp |= pgp_query (b);
+  }
+#endif /* _PGPPATH */
+
+}
index 2ae3678d3680675dacad4b4ee970fc23624b4485..d49a22d7c2ee2134ced94bfe8baea93d7a5db092 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -850,54 +850,13 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
        }
         break;
       
-      case OP_COMPOSE_EDIT_TYPE:
+      case OP_EDIT_TYPE:
        CHECK_COUNT;
-       snprintf (buf, sizeof (buf), "%s/%s",
-                 TYPE (idx[menu->current]->content),
-                 idx[menu->current]->content->subtype);
-       if (mutt_get_field ("Content-Type: ", buf, sizeof (buf), 0) == 0 && buf[0])
-       {
-         char *s;
-         PARAMETER *par;
-         BODY *b;
-         
-         b = idx[menu->current]->content;
-         
-         s  = b->filename;  par = b->parameter;
-         b->filename  = NULL;  b->parameter = NULL;
-         
-         mutt_parse_content_type (buf, b);
-
-         safe_free ((void **) &b->filename);
-         b->filename = s;
-         
-         if ((s = mutt_get_parameter("charset", b->parameter)))
-           mutt_set_parameter("charset", s, &par);
-         
-         /* These are needed for "traditional" PGP.
-          * Should we switch to a "negative list" instead?
-          */
-
-         if ((s = mutt_get_parameter("x-action", b->parameter)))
-           mutt_set_parameter("x-action", s, &par);
-         if ((s = mutt_get_parameter("format", b->parameter)))
-           mutt_set_parameter("format", s, &par);
-
-         /* ignore the other parameters for now */
-         mutt_free_parameter(&b->parameter);
-         b->parameter = par;
-
-         /* this may have been a "structured" message */
-         if  (b->parts)
-           mutt_free_body (&b->parts);
-         if (b->hdr)
-         {
-           b->hdr->content = NULL;
-           mutt_free_header (&b->hdr);
-         }
+        {
+         mutt_edit_content_type (NULL, idx[menu->current]->content);
 
          /* this may have been a change to text/something */
-         mutt_update_encoding (b);
+         mutt_update_encoding (idx[menu->current]->content);
 
          menu->redraw = REDRAW_CURRENT;
        }
index 540a71e70e3503d250e7234ae6730d1f60ba7fa3..af352027449ed87404984d9749750d6b19aa98fd 100644 (file)
@@ -1009,6 +1009,21 @@ int mutt_index_menu (void)
        }
        break;
 
+      case OP_EDIT_TYPE:
+
+       CHECK_MSGCOUNT;
+       CHECK_ATTACH;
+       mutt_edit_content_type (CURHDR, CURHDR->content);
+       /* if we were in the pager, redisplay the message */
+       if (menu->menu == MENU_PAGER)
+       {
+         op = OP_DISPLAY_MESSAGE;
+         continue;
+       }
+        else
+         menu->redraw = REDRAW_CURRENT;
+       break;
+
       case OP_MAIN_NEXT_UNDELETED:
 
        CHECK_MSGCOUNT;
index 4a9ee160678da42c5e7f3700468ff4c4a7ece16b..b8513d7f19a2b07e66d940d2be9d672d8ee1e1bb 100644 (file)
@@ -78,6 +78,7 @@ struct binding_t OpMain[] = {
   { "delete-thread",           OP_DELETE_THREAD,               "\004" },
   { "delete-subthread",                OP_DELETE_SUBTHREAD,            "\033d" },
   { "edit",                    OP_EDIT_MESSAGE,                "e" },
+  { "edit-type",               OP_EDIT_TYPE,                   "\005" },
   { "forward-message",         OP_FORWARD_MESSAGE,             "f" },
   { "flag-message",            OP_FLAG_MESSAGE,                "F" },
   { "group-reply",             OP_GROUP_REPLY,                 "g" },
@@ -155,6 +156,7 @@ struct binding_t OpPager[] = {
   { "delete-thread",   OP_DELETE_THREAD,               "\004" },
   { "delete-subthread",        OP_DELETE_SUBTHREAD,            "\033d" },
   { "edit",            OP_EDIT_MESSAGE,                "e" },
+  { "edit-type",       OP_EDIT_TYPE,                   "\005" },
   { "forward-message", OP_FORWARD_MESSAGE,             "f" },
   { "flag-message",    OP_FLAG_MESSAGE,                "F" },
   { "group-reply",     OP_GROUP_REPLY,                 "g" },
@@ -234,6 +236,7 @@ struct binding_t OpPager[] = {
 struct binding_t OpAttach[] = {
   { "bounce-message",  OP_BOUNCE_MESSAGE,              "b" },
   { "display-headers", OP_DISPLAY_HEADERS,             "h" },
+  { "edit-type",       OP_EDIT_TYPE,                   "\005" },
   { "print-entry",     OP_PRINT,                       "p" },
   { "save-entry",      OP_SAVE,                        "s" },
   { "pipe-entry",      OP_PIPE,                        "|" },
@@ -286,7 +289,7 @@ struct binding_t OpCompose[] = {
   { "rename-file",     OP_COMPOSE_RENAME_FILE,         "R" },
   { "edit-subject",    OP_COMPOSE_EDIT_SUBJECT,        "s" },
   { "edit-to",         OP_COMPOSE_EDIT_TO,             "t" },
-  { "edit-type",       OP_COMPOSE_EDIT_TYPE,           "\024" },
+  { "edit-type",       OP_EDIT_TYPE,                   "\024" },
   { "write-fcc",       OP_COMPOSE_WRITE_MESSAGE,       "w" },
   { "recode-attachment",OP_COMPOSE_RECODE,             NULL },
   { "toggle-unlink",   OP_COMPOSE_TOGGLE_UNLINK,       "u" },
index 56cd89e7a3e6c6d79e3260adb5c707343be46df2..7efd31245cc27357e332e144c90e5df1dd462984 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -138,6 +138,7 @@ void mutt_create_alias (ENVELOPE *, ADDRESS *);
 void mutt_decode_attachment (BODY *, STATE *);
 void mutt_default_save (char *, size_t, HEADER *);
 void mutt_display_address (ENVELOPE *);
+void mutt_edit_content_type (HEADER *, BODY *);
 void mutt_edit_file (const char *, const char *);
 void mutt_edit_headers (const char *, const char *, HEADER *, char *, size_t);
 void mutt_curses_error (const char *, ...);
index e4b93656cf182c5608e7899fd457e936f10c5733..09b034c859b82feead1d6261b80a3c69d901921b 100644 (file)
@@ -737,6 +737,12 @@ mutt_attach_display_loop (MUTTMENU *menu, int op, FILE *fp, HEADER *hdr,
        else
          op = OP_NULL;
        break;
+      case OP_EDIT_TYPE:
+       /* when we edit the content-type, we should redisplay the attachment
+          immediately */
+       mutt_edit_content_type (hdr, idx[menu->current]->content);
+       op = OP_VIEW_ATTACH;
+       break;
       default:
        op = OP_NULL;
     }
@@ -993,6 +999,11 @@ void mutt_view_attachments (HEADER *hdr)
        menu->redraw = REDRAW_FULL;
        break;
 
+      case OP_EDIT_TYPE:
+       mutt_edit_content_type (hdr, idx[menu->current]->content);
+       menu->redraw = REDRAW_CURRENT;
+       break;
+
       case OP_EXIT:
        mx_close_message (&msg);
        hdr->attach_del = 0;
@@ -1010,14 +1021,6 @@ void mutt_view_attachments (HEADER *hdr)
 
 
 
-
-
-
-
-
-
-
-
 #ifdef _PGPPATH
        if (pgp)
        {