]> granicus.if.org Git - neomutt/commitdiff
Add option $show_multipart_alternative
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 10 Feb 2017 20:10:05 +0000 (21:10 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 14 Feb 2017 17:48:23 +0000 (17:48 +0000)
When viewing a multi-part MIME email:
    'alternative_order' determines which part is displayed
    'auto_view' determines how the part is displayed

$show_multipart_alternative has three options to control what is displayed:
    unset    Only the chosen part (default)
    'info'   The chosen part plus information about the other parts
    'inline' All the parts

globals.h
handler.c
init.c
init.h

index f5d7ee795658be7bdfb9bca2460592e0613459df..f9f915027cd01269c193a5ded64f95cc2b2f6528 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -135,6 +135,7 @@ WHERE short SearchContext;
 WHERE char *SendCharset;
 WHERE char *Sendmail;
 WHERE char *Shell;
+WHERE char *ShowMultipartAlternative;
 #ifdef USE_SIDEBAR
 WHERE char *SidebarDelimChars;
 WHERE char *SidebarDividerChar;
index a23f3c1d3b22a6ed4e75c66487e15b61cf8ee070..2be9d4936f2015899738755bfb77702cadad6eff 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -1004,6 +1004,8 @@ static int alternative_handler (BODY *a, STATE *s)
   int type = 0;
   int mustfree = 0;
   int rc = 0;
+  char length[5];
+  int count = 0;
 
   if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE ||
       a->encoding == ENCUUENCODED)
@@ -1130,7 +1132,38 @@ static int alternative_handler (BODY *a, STATE *s)
       fseeko (s->fpin, choice->hdr_offset, 0);
       mutt_copy_bytes(s->fpin, s->fpout, choice->offset-choice->hdr_offset);
     }
+
+    if (mutt_strcmp ("info", ShowMultipartAlternative) == 0)
+    {
+      mutt_pretty_size (length, sizeof (length), choice->length);
+      state_mark_attach (s);
+      state_printf (s, _("[-- Type: %s/%s, Encoding: %s, Size: %s --]\n"),
+                    TYPE (choice), choice->subtype, ENCODING (choice->encoding), length);
+    }
     mutt_body_handler (choice, s);
+
+    if (mutt_strcmp ("info", ShowMultipartAlternative) == 0)
+    {
+      if (a && a->parts)
+        b = a->parts;
+      else
+        b = a;
+      while (b)
+      {
+        if (choice != b)
+        {
+          count += 1;
+          mutt_pretty_size (length, sizeof (length), b->length);
+          if (count == 1)
+            state_putc ('\n', s);
+
+          state_mark_attach (s);
+          state_printf (s, _("[-- Alternative Type #%d %s/%s, Encoding: %s, Size: %s --]\n"),
+                        count, TYPE (b), b->subtype, ENCODING (b->encoding), length);
+        }
+        b = b->next;
+      }
+    }
   }
   else if (s->flags & MUTT_DISPLAY)
   {
@@ -1794,7 +1827,7 @@ int mutt_body_handler (BODY *b, STATE *s)
   {
     char *p;
 
-    if (ascii_strcasecmp ("alternative", b->subtype) == 0)
+    if ((mutt_strcmp ("inline", ShowMultipartAlternative) != 0) && (ascii_strcasecmp ("alternative", b->subtype) == 0))
       handler = alternative_handler;
     else if (WithCrypto && ascii_strcasecmp ("signed", b->subtype) == 0)
     {
diff --git a/init.c b/init.c
index 6b183aac14d232aea4ceca8d19be6d13496785eb..5bf71027cdbd4d82510880eaa7efdf82fc04a7a9 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1978,6 +1978,13 @@ static int check_charset (struct option_t *opt, const char *val)
   return rc;
 }
 
+static bool valid_show_multipart_alternative(const char *val)
+{
+  return ((mutt_strcmp(val, "inline") == 0) ||
+          (mutt_strcmp(val, "info") == 0) ||
+          (val == NULL) || (*val == 0));
+}
+
 static int parse_setenv(BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
 {
   int query, unset, len;
@@ -2342,6 +2349,14 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
          *((char **) MuttVars[idx].data) = safe_strdup (tmp->data);
          if (mutt_strcmp (MuttVars[idx].option, "charset") == 0)
            mutt_set_charset (Charset);
+
+          if ((mutt_strcmp (MuttVars[idx].option, "show_multipart_alternative") == 0) &&
+              !valid_show_multipart_alternative(tmp->data))
+          {
+            snprintf (err->data, err->dsize, _("Invalid value for option %s: \"%s\""),
+                      MuttVars[idx].option, tmp->data);
+            return -1;
+          }
         }
         else if (DTYPE (MuttVars[idx].type) == DT_MBCHARTBL)
         {
diff --git a/init.h b/init.h
index 394682bb1149970f56e937ea958473f7a80ec4a4..6c3824ccf51bfb153bce252f51ecc2f5c9e10c56 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1273,6 +1273,14 @@ struct option_t MuttVars[] = {
   ** function; \fC<group-reply>\fP will reply to both the sender and the
   ** list.
   */
+  { "show_multipart_alternative", DT_STR, R_NONE, UL &ShowMultipartAlternative, 0 },
+  /*
+  ** .pp
+  ** When \fIset\fP to \fCinfo\fP, the multipart/alternative information is shown.
+  ** When \fIset\fP to \fCinline\fP, all of the alternatives are displayed.
+  ** When not set, the default behavior is to show only the chosen alternative.
+  ** .pp
+  */
 #ifdef USE_IMAP
   { "imap_authenticators", DT_STR, R_NONE, UL &ImapAuthenticators, UL 0 },
   /*