]> granicus.if.org Git - neomutt/commitdiff
preferred_languages -> slist
authorRichard Russon <rich@flatcap.org>
Mon, 10 Jun 2019 21:48:25 +0000 (22:48 +0100)
committerRichard Russon <rich@flatcap.org>
Wed, 12 Jun 2019 23:23:35 +0000 (00:23 +0100)
Convert `$preferred_languages` to use the new DT_SLIST type (string list).

handler.c
handler.h
init.h

index 42c5d2400eac93cbae0b6e9163a979c039e00718..6a6d0fcc9a4d2e9d36621792b04266131d8402b0 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -65,7 +65,7 @@ bool C_HonorDisposition; ///< Config: Don't display MIME parts inline if they ha
 bool C_ImplicitAutoview; ///< Config: Display MIME attachments inline if a 'copiousoutput' mailcap entry exists
 bool C_IncludeEncrypted; ///< Config: Whether to include encrypted content when replying
 bool C_IncludeOnlyfirst; ///< Config: Only include the first attachment when replying
-char *C_PreferredLanguages; ///< Config: Preferred languages for multilingual MIME
+struct Slist *C_PreferredLanguages; ///< Config: Preferred languages for multilingual MIME
 bool C_ReflowText; ///< Config: Reformat paragraphs of 'format=flowed' text
 char *C_ShowMultipartAlternative; ///< Config: How to display 'multipart/alternative' MIME parts
 
@@ -1106,13 +1106,9 @@ static int alternative_handler(struct Body *a, struct State *s)
  */
 static int multilingual_handler(struct Body *a, struct State *s)
 {
-  struct Body *choice = NULL;
   struct Body *b = NULL;
   bool mustfree = false;
   int rc = 0;
-  struct Body *first_part = NULL;
-  struct Body *zxx_part = NULL;
-  char *lang = NULL;
 
   mutt_debug(LL_DEBUG2,
              "RFC8255 >> entering in handler multilingual handler\n");
@@ -1138,16 +1134,21 @@ static int multilingual_handler(struct Body *a, struct State *s)
   else
     b = a;
 
-  char *preferred_languages = NULL;
   if (C_PreferredLanguages)
   {
+    struct Buffer *langs = mutt_buffer_pool_get();
+    cs_str_string_get(Config, "preferred_languages", langs);
     mutt_debug(LL_DEBUG2, "RFC8255 >> preferred_languages set in config to '%s'\n",
-               C_PreferredLanguages);
-    preferred_languages = mutt_str_strdup(C_PreferredLanguages);
-    lang = strtok(preferred_languages, ",");
+               mutt_b2s(langs));
+    mutt_buffer_pool_release(&langs);
   }
 
-  while (lang)
+  struct Body *choice = NULL;
+  struct Body *first_part = NULL;
+  struct Body *zxx_part = NULL;
+  struct ListNode *np = NULL;
+
+  STAILQ_FOREACH(np, &C_PreferredLanguages->head, entries)
   {
     while (b)
     {
@@ -1160,11 +1161,11 @@ static int multilingual_handler(struct Body *a, struct State *s)
           zxx_part = b;
 
         mutt_debug(LL_DEBUG2, "RFC8255 >> comparing configuration preferred_language='%s' to mail part content-language='%s'\n",
-                   lang, b->language);
-        if (lang && b->language && (mutt_str_strcmp(lang, b->language) == 0))
+                   np->data, b->language);
+        if (b->language && (mutt_str_strcmp(np->data, b->language) == 0))
         {
           mutt_debug(LL_DEBUG2, "RFC8255 >> preferred_language='%s' matches content-language='%s' >> part selected to be displayed\n",
-                     lang, b->language);
+                     np->data, b->language);
           choice = b;
           break;
         }
@@ -1176,8 +1177,6 @@ static int multilingual_handler(struct Body *a, struct State *s)
     if (choice)
       break;
 
-    lang = strtok(NULL, ",");
-
     if (a->parts)
       b = a->parts;
     else
@@ -1197,7 +1196,6 @@ static int multilingual_handler(struct Body *a, struct State *s)
   if (mustfree)
     mutt_body_free(&a);
 
-  FREE(&preferred_languages);
   return rc;
 }
 
index 803e18b41b3972a93cecb3bf43b1febdd5fb811a..bf8555a290ef4099c3320e4eaf60d925f73debe7 100644 (file)
--- a/handler.h
+++ b/handler.h
@@ -35,7 +35,7 @@ extern bool  C_HonorDisposition;
 extern bool  C_ImplicitAutoview;
 extern bool  C_IncludeEncrypted;
 extern bool  C_IncludeOnlyfirst;
-extern char *C_PreferredLanguages;
+extern struct Slist *C_PreferredLanguages;
 extern bool  C_ReflowText;
 extern char *C_ShowMultipartAlternative;
 
diff --git a/init.h b/init.h
index 5b4590d04aa16570205b5ef2324b22e38525b0fa..0dc44eb00b6b6c849cff64a9d172810c24e340fb 100644 (file)
--- a/init.h
+++ b/init.h
@@ -3111,7 +3111,7 @@ struct ConfigDef MuttVars[] = {
   ** remote machine without having to enter a password.
   */
 #endif /* USE_SOCKET */
-  { "preferred_languages", DT_STRING, &C_PreferredLanguages, 0 },
+  { "preferred_languages", DT_SLIST|SLIST_SEP_COMMA, &C_PreferredLanguages, 0 },
   /*
   ** .pp
   ** RFC8255 : user preferred languages to be search in parts and display