]> granicus.if.org Git - neomutt/commitdiff
Add `<{edit,edit-or-view,view}-raw-message>` functions 948/head
authorReis Radomil <reisradomil@fake-box.com>
Wed, 15 Nov 2017 20:53:03 +0000 (21:53 +0100)
committerReis Radomil <reisradomil@fake-box.com>
Wed, 15 Nov 2017 20:58:37 +0000 (21:58 +0100)
Add mutt-functions `<edit-raw-message>`, `<edit-or-view-raw-message>`
and `<view-raw-message>`.

`<view-raw-message>` is a binding for the C-function
`mutt_view_message()`, which opens the raw message as a read-only file
in an external editor.

`<edit-or-view-raw-message>` is a dispatcher function: If the mailbox
is writable then this is the same as `<edit-raw-message>`, otherwise it
is the same as `<view-raw-message>`.

`<edit-raw-message>` is a synonym for `<edit>` 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
functions.h
opcodes.h

index 616fc74833d2391964ba9f8e23ffa23ae59656d4..a474dc46f5d5ed265e86899402a66bdd5f4cd529 100644 (file)
@@ -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;
index f7586513d6cbe9e7b4df25d7c2a9c078e02695d3..4430c41fa078aa929b17bcc3c23e894951f6f5c7 100644 (file)
@@ -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,              "@" },
index a20d154e2c3e009b61ba3db23b356d38d52c99cd..090c490c675a078ef9b694bd16b81af25eadd322 100644 (file)
--- 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")) \
   _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")) \