From d7e704815c36593111157aa5cddcd7d201f72e05 Mon Sep 17 00:00:00 2001 From: Reis Radomil Date: Wed, 15 Nov 2017 21:53:03 +0100 Subject: [PATCH] Add `<{edit,edit-or-view,view}-raw-message>` functions Add mutt-functions ``, `` and ``. `` is a binding for the C-function `mutt_view_message()`, which opens the raw message as a read-only file in an external editor. `` is a dispatcher function: If the mailbox is writable then this is the same as ``, otherwise it is the same as ``. `` is a synonym for `` whose name coherent with the naming scheme of the other two functions introduced. Change default key binding of `e` from `edit` to `edit-or-view-raw-message`. This allows viewing the raw message in an external editor also in read-only mailboxes. --- curs_main.c | 25 ++++++++++++++++++++----- functions.h | 10 ++++++++-- opcodes.h | 4 +++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/curs_main.c b/curs_main.c index 616fc7483..a474dc46f 100644 --- a/curs_main.c +++ b/curs_main.c @@ -2873,19 +2873,34 @@ int mutt_index_menu(void) mutt_check_rescore(Context); break; - case OP_EDIT_RAW_MESSAGE: + case OP_EDIT_OR_VIEW_RAW_MESSAGE: /* fall through */ + case OP_EDIT_RAW_MESSAGE: /* fall through */ + case OP_VIEW_RAW_MESSAGE: + /* TODO split this into 3 cases? */ CHECK_MSGCOUNT; CHECK_VISIBLE; - CHECK_READONLY; CHECK_ATTACH; - /* L10N: CHECK_ACL */ - CHECK_ACL(MUTT_ACL_INSERT, _("Cannot edit message")); + bool edit; + if (op == OP_EDIT_RAW_MESSAGE) + { + CHECK_READONLY; + /* L10N: CHECK_ACL */ + CHECK_ACL(MUTT_ACL_INSERT, _("Cannot edit message")); + edit = true; + } + else if (op == OP_EDIT_OR_VIEW_RAW_MESSAGE) + edit = !Context->readonly && mutt_bit_isset(Context->rights, MUTT_ACL_INSERT); + else + edit = false; if (option(OPT_PGP_AUTO_DECODE) && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))) mutt_check_traditional_pgp(tag ? NULL : CURHDR, &menu->redraw); - mutt_edit_message(Context, tag ? NULL : CURHDR); + if (edit) + mutt_edit_message(Context, tag ? NULL : CURHDR); + else + mutt_view_message(Context, tag ? NULL : CURHDR); menu->redraw = REDRAW_FULL; break; diff --git a/functions.h b/functions.h index f7586513d..4430c41fa 100644 --- a/functions.h +++ b/functions.h @@ -111,8 +111,10 @@ const struct Binding OpMain[] = { /* map: index */ { "delete-pattern", OP_MAIN_DELETE_PATTERN, "D" }, { "delete-thread", OP_DELETE_THREAD, "\004" }, { "delete-subthread", OP_DELETE_SUBTHREAD, "\033d" }, - { "edit", OP_EDIT_RAW_MESSAGE, "e" }, + { "edit", OP_EDIT_RAW_MESSAGE, NULL }, + { "edit-raw-message", OP_EDIT_RAW_MESSAGE, NULL }, { "edit-label", OP_EDIT_LABEL, "Y" }, + { "edit-or-view-raw-message", OP_EDIT_OR_VIEW_RAW_MESSAGE, "e" }, { "edit-type", OP_EDIT_TYPE, "\005" }, { "forward-message", OP_FORWARD_MESSAGE, "f" }, #ifdef USE_NNTP @@ -173,6 +175,7 @@ const struct Binding OpMain[] = { /* map: index */ { "undelete-subthread", OP_UNDELETE_SUBTHREAD, "\033u" }, { "undelete-thread", OP_UNDELETE_THREAD, "\025" }, { "view-attachments", OP_VIEW_ATTACHMENTS, "v" }, + { "view-raw-message", OP_VIEW_RAW_MESSAGE, NULL }, { "show-version", OP_VERSION, "V" }, { "set-flag", OP_MAIN_SET_FLAG, "w" }, { "clear-flag", OP_MAIN_CLEAR_FLAG, "W" }, @@ -247,8 +250,10 @@ const struct Binding OpPager[] = { /* map: pager */ { "delete-subthread", OP_DELETE_SUBTHREAD, "\033d" }, { "set-flag", OP_MAIN_SET_FLAG, "w" }, { "clear-flag", OP_MAIN_CLEAR_FLAG, "W" }, - { "edit", OP_EDIT_RAW_MESSAGE, "e" }, + { "edit", OP_EDIT_RAW_MESSAGE, NULL }, + { "edit-raw-message", OP_EDIT_RAW_MESSAGE, NULL }, { "edit-label", OP_EDIT_LABEL, "Y" }, + { "edit-or-view-raw-message", OP_EDIT_OR_VIEW_RAW_MESSAGE, "e" }, { "edit-type", OP_EDIT_TYPE, "\005" }, #ifdef USE_NNTP { "followup-message", OP_FOLLOWUP, NULL }, @@ -304,6 +309,7 @@ const struct Binding OpPager[] = { /* map: pager */ { "undelete-subthread", OP_UNDELETE_SUBTHREAD, "\033u" }, { "undelete-thread", OP_UNDELETE_THREAD, "\025" }, { "view-attachments", OP_VIEW_ATTACHMENTS, "v" }, + { "view-raw-message", OP_VIEW_RAW_MESSAGE, NULL }, { "show-version", OP_VERSION, "V" }, { "search-toggle", OP_SEARCH_TOGGLE, "\\" }, { "display-address", OP_DISPLAY_ADDRESS, "@" }, diff --git a/opcodes.h b/opcodes.h index a20d154e2..090c490c6 100644 --- a/opcodes.h +++ b/opcodes.h @@ -93,7 +93,8 @@ _fmt(OP_DISPLAY_HEADERS, N_("display message and toggle header weeding")) \ _fmt(OP_DISPLAY_MESSAGE, N_("display a message")) \ _fmt(OP_EDIT_LABEL, N_("add, change, or delete a message's label")) \ - _fmt(OP_EDIT_RAW_MESSAGE, N_("edit the raw message")) \ + _fmt(OP_EDIT_RAW_MESSAGE, N_("edit the raw message (edit and edit-raw-message are synonyms)")) \ + _fmt(OP_EDIT_OR_VIEW_RAW_MESSAGE, N_("edit the raw message if the mailbox is not read-only, otherwise view it")) \ _fmt(OP_EDITOR_BACKSPACE, N_("delete the char in front of the cursor")) \ _fmt(OP_EDITOR_BACKWARD_CHAR, N_("move the cursor one character to the left")) \ _fmt(OP_EDITOR_BACKWARD_WORD, N_("move the cursor to the beginning of the word")) \ @@ -229,6 +230,7 @@ _fmt(OP_VERSION, N_("show the NeoMutt version number and date")) \ _fmt(OP_VIEW_ATTACH, N_("view attachment using mailcap entry if necessary")) \ _fmt(OP_VIEW_ATTACHMENTS, N_("show MIME attachments")) \ + _fmt(OP_VIEW_RAW_MESSAGE, N_("show the raw message")) \ _fmt(OP_WHAT_KEY, N_("display the keycode for a key press")) \ _fmt(OP_LIMIT_CURRENT_THREAD, N_("limit view to current thread")) \ _fmt(OP_MAIN_SHOW_LIMIT, N_("show currently active limit pattern")) \ -- 2.40.0