Commit 54c92539 authored by Thomas Roessler's avatar Thomas Roessler

Unified edit-type function for the index, compose, and

receive-attachment menus.  Mostly by Michael Elkins.
parent 33acfb1e
......@@ -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"
......
......@@ -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 */
}
......@@ -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;
}
......
......@@ -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;
......
......@@ -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" },
......
......@@ -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 *, ...);
......
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment