Add the concept of a "message identifier" - naming ideas welcome.  It
know this is a little too close to message-id and could be confusing.

For Maildir/mh it's the path inside the mailbox.
For IMAP it's the UID.
For POP3 it's the refno.
mbox doesn't currently implement anything.

Add expando %U to $index_format.

Add function <echo-message-identifier> to echo the message in the
message-window.
---

I'm sending this for FEEDBACK.  I don't currently plan to commit this
as-is, and perhaps not at all.

Once in a while I see requests to view the underlying information
about a message, for instance the UID of an IMAP message.  Or recently
on mutt-users, a request to find out which mailbox a notmuch-search
result came from.

This is just an idea for an expando or an echo command.  I've included
both in the patch.  Comments?


 OPS         |  5 +++++
 curs_main.c |  7 +++++++
 functions.h |  2 ++
 hdrline.c   |  9 +++++++++
 imap/imap.c |  8 ++++++++
 init.h      |  1 +
 mailbox.h   |  1 +
 mh.c        |  9 +++++++++
 mutt.h      |  1 +
 mx.c        | 13 +++++++++++++
 pager.c     |  7 +++++++
 pop.c       |  8 ++++++++
 12 files changed, 71 insertions(+)

diff --git a/OPS b/OPS
index aee20ac1..eb6e85cc 100644
--- a/OPS
+++ b/OPS
@@ -1219,3 +1219,8 @@ OP_MAIN_CLOSE_ALL_THREADS N_("collapse all threads")
  */
 OP_DESCEND_DIRECTORY N_("descend into a directory")
 
+/* L10N: Help screen description for OP_ECHO_MESSAGE_IDENTIFIER
+   index_menu: <echo-message-identifier>
+   pager_menu: <echo-message-identifier>
+ */
+OP_ECHO_MESSAGE_IDENTIFIER N_("echo current message identifier")
diff --git a/curs_main.c b/curs_main.c
index 372007ff..6f8a23a4 100644
--- a/curs_main.c
+++ b/curs_main.c
@@ -2672,6 +2672,13 @@ int mutt_index_menu(void)
         mutt_check_stats();
         break;
 
+      case OP_ECHO_MESSAGE_IDENTIFIER:
+        CHECK_MSGCOUNT;
+        CHECK_VISIBLE;
+        mx_get_message_identifier(Context, CURHDR, buf, sizeof(buf));
+        mutt_message(buf);
+        break;
+
 #ifdef USE_SIDEBAR
       case OP_SIDEBAR_FIRST:
       case OP_SIDEBAR_LAST:
diff --git a/functions.h b/functions.h
index eab3df3d..0ba54c12 100644
--- a/functions.h
+++ b/functions.h
@@ -163,6 +163,7 @@ const struct menu_func_op_t OpMain[] = { /* map: index */
   { "display-address",           OP_DISPLAY_ADDRESS },
   { "display-message",           OP_DISPLAY_MESSAGE },
   { "display-toggle-weed",       OP_DISPLAY_HEADERS },
+  { "echo-message-identifier",   OP_ECHO_MESSAGE_IDENTIFIER },
   { "edit",                      OP_EDIT_MESSAGE },
   { "edit-label",                OP_EDIT_LABEL },
   { "edit-type",                 OP_EDIT_TYPE },
@@ -361,6 +362,7 @@ const struct menu_func_op_t OpPager[] = { /* map: pager */
   { "delete-thread",             OP_DELETE_THREAD },
   { "display-address",           OP_DISPLAY_ADDRESS },
   { "display-toggle-weed",       OP_DISPLAY_HEADERS },
+  { "echo-message-identifier",   OP_ECHO_MESSAGE_IDENTIFIER },
   { "edit",                      OP_EDIT_MESSAGE },
   { "edit-label",                OP_EDIT_LABEL },
   { "edit-type",                 OP_EDIT_TYPE },
diff --git a/hdrline.c b/hdrline.c
index 01a99638..6381113a 100644
--- a/hdrline.c
+++ b/hdrline.c
@@ -26,6 +26,7 @@
 #include "charset.h"
 #include "mutt_crypt.h"
 #include "mutt_idna.h"
+#include "mailbox.h"
 
 #include <ctype.h>
 #include <stdlib.h>
@@ -663,6 +664,14 @@ hdr_format_str(char *dest,
       mutt_format_s(dest, destlen, prefix, buf2);
       break;
 
+    case 'U':
+      if (ctx)
+      {
+        mx_get_message_identifier(ctx, hdr, buf2, sizeof(buf2));
+        mutt_format_s(dest, destlen, prefix, buf2);
+      }
+      break;
+
     case 'v':
       if (mutt_addr_is_user(hdr->env->from))
       {
diff --git a/imap/imap.c b/imap/imap.c
index 7e349fa9..f372359d 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -1859,6 +1859,13 @@ static int imap_save_to_header_cache(CONTEXT *ctx, 
HEADER *h)
   return rc;
 }
 
+static int imap_get_message_identifier(CONTEXT *ctx, HEADER *h, char *dest, 
size_t destlen)
+{
+  snprintf(dest, destlen, "%u", HEADER_DATA(h)->uid);
+
+  return 0;
+}
+
 /* split path into (idata,mailbox name) */
 static int imap_get_mailbox(const char *path, IMAP_DATA **hidata, char *buf, 
size_t blen)
 {
@@ -2620,4 +2627,5 @@ struct mx_ops mx_imap_ops = {
   .check = imap_check_mailbox_reopen,
   .sync = NULL,      /* imap syncing is handled by imap_sync_mailbox */
   .save_to_header_cache = imap_save_to_header_cache,
+  .get_message_identifier = imap_get_message_identifier,
 };
diff --git a/init.h b/init.h
index 394d3d1d..cf5f3d6b 100644
--- a/init.h
+++ b/init.h
@@ -1963,6 +1963,7 @@ struct option_t MuttVars[] = {
   ** .dt %t .dd ``To:'' field (recipients)
   ** .dt %T .dd the appropriate character from the $$to_chars string
   ** .dt %u .dd user (login) name of the author
+  ** .dt %U .dd message identifier (UID or path in mh/maildir)
   ** .dt %v .dd first name of the author, or the recipient if the message is 
from you
   ** .dt %X .dd number of attachments
   **            (please see the ``$attachments'' section for possible speed 
effects)
diff --git a/mailbox.h b/mailbox.h
index 6d89cf41..3bb24aac 100644
--- a/mailbox.h
+++ b/mailbox.h
@@ -84,6 +84,7 @@ int mx_access(const char*, int);
 int mx_check_empty(const char *);
 int mx_msg_padding_size(CONTEXT *);
 int mx_save_to_header_cache(CONTEXT *, HEADER *);
+int mx_get_message_identifier(CONTEXT *, HEADER *, char *, size_t);
 
 int mx_is_maildir(const char *);
 int mx_is_mh(const char *);
diff --git a/mh.c b/mh.c
index eda484ae..220a46a8 100644
--- a/mh.c
+++ b/mh.c
@@ -2523,6 +2523,13 @@ static int mh_save_to_header_cache(CONTEXT *ctx, HEADER 
*h)
   return rc;
 }
 
+static int maildir_get_message_identifier(CONTEXT *ctx, HEADER *h, char *dest, 
size_t destlen)
+{
+  strfcpy(dest, h->path, destlen);
+
+  return 0;
+}
+
 
 /*
  * These functions try to find a message in a maildir folder when it
@@ -2778,6 +2785,7 @@ struct mx_ops mx_maildir_ops = {
   .check = maildir_check_mailbox,
   .sync = mh_sync_mailbox,
   .save_to_header_cache = maildir_save_to_header_cache,
+  .get_message_identifier = maildir_get_message_identifier,
 };
 
 struct mx_ops mx_mh_ops = {
@@ -2791,4 +2799,5 @@ struct mx_ops mx_mh_ops = {
   .check = mh_check_mailbox,
   .sync = mh_sync_mailbox,
   .save_to_header_cache = mh_save_to_header_cache,
+  .get_message_identifier = maildir_get_message_identifier,
 };
diff --git a/mutt.h b/mutt.h
index 262c7e54..19c0188b 100644
--- a/mutt.h
+++ b/mutt.h
@@ -1078,6 +1078,7 @@ struct mx_ops
   int (*open_new_msg)(struct _message *, struct _context *, HEADER *);
   int (*msg_padding_size)(struct _context *);
   int (*save_to_header_cache)(struct _context *, struct header *);
+  int (*get_message_identifier)(struct _context *, struct header *, char *, 
size_t);
 };
 
 typedef struct _context
diff --git a/mx.c b/mx.c
index 6c5b1754..9552d87e 100644
--- a/mx.c
+++ b/mx.c
@@ -1620,4 +1620,17 @@ int mx_save_to_header_cache(CONTEXT *ctx, HEADER *h)
   return ctx->mx_ops->save_to_header_cache(ctx, h);
 }
 
+int mx_get_message_identifier(CONTEXT *ctx, HEADER *h, char *dest, size_t 
destlen)
+{
+  if (!dest || !destlen)
+    return 0;
+
+  *dest = 0;
+
+  if (!ctx->mx_ops || !ctx->mx_ops->get_message_identifier)
+    return 0;
+
+  return ctx->mx_ops->get_message_identifier(ctx, h, dest, destlen);
+}
+
 /* vim: set sw=2: */
diff --git a/pager.c b/pager.c
index fcadf26e..10911403 100644
--- a/pager.c
+++ b/pager.c
@@ -33,6 +33,7 @@
 #include "buffy.h"
 #include "send.h"
 #include "background.h"
+#include "mailbox.h"
 
 #ifdef USE_SIDEBAR
 #include "sidebar.h"
@@ -3158,6 +3159,12 @@ search_next:
         mutt_check_stats();
         break;
 
+      case OP_ECHO_MESSAGE_IDENTIFIER:
+        CHECK_MODE(IsHeader(extra));
+        mx_get_message_identifier(Context, extra->hdr, buffer, sizeof(buffer));
+        mutt_message(buffer);
+        break;
+
 #ifdef USE_SIDEBAR
       case OP_SIDEBAR_FIRST:
       case OP_SIDEBAR_LAST:
diff --git a/pop.c b/pop.c
index 3077c94e..e5a26fc2 100644
--- a/pop.c
+++ b/pop.c
@@ -860,6 +860,13 @@ static int pop_check_mailbox(CONTEXT *ctx, int *index_hint)
   return 0;
 }
 
+static int pop_get_message_identifier(CONTEXT *ctx, HEADER *h, char *dest, 
size_t destlen)
+{
+  snprintf(dest, destlen, "%d", h->refno);
+
+  return 0;
+}
+
 static int pop_save_to_header_cache(CONTEXT *ctx, HEADER *h)
 {
   int rc = 0;
@@ -1053,4 +1060,5 @@ struct mx_ops mx_pop_ops = {
   .open_new_msg = NULL,
   .sync = pop_sync_mailbox,
   .save_to_header_cache = pop_save_to_header_cache,
+  .get_message_identifier = pop_get_message_identifier,
 };
-- 
2.56.0

Reply via email to