]> granicus.if.org Git - mutt/commitdiff
Fix some more character set glitches.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 11 Sep 2000 10:50:37 +0000 (10:50 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 11 Sep 2000 10:50:37 +0000 (10:50 +0000)
charset.c
copy.c
mbyte.c
rfc2047.c
sendlib.c

index 8961ebde8111052cbad9fa2cbc6aafd1224014ea..00efd6f555a36cd1a4f19840a4ea55073ccc758e 100644 (file)
--- a/charset.c
+++ b/charset.c
 # define EILSEQ EINVAL
 #endif
 
-#ifdef HAVE_LANGINFO_CODESET
-# include <langinfo.h>
-
-/* 
- * Try to convert nl_langinfo's return value to something we can
- * use for MIME's purposes.
- *
- * Note that the algorithm used here is quite different from the
- * one in mutt_canonical_charset. 
- */
-
 /* 
  * The following list has been created manually from the data under:
  * http://www.isi.edu/in-notes/iana/assignments/character-sets
@@ -191,6 +180,10 @@ PreferredMIMENames[] =
   { NULL,              NULL            }
 };
 
+#ifdef HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+
+
 void mutt_set_langinfo_charset (void)
 {
   char buff[LONG_STRING];
diff --git a/copy.c b/copy.c
index 58194003d40ed62c3f742d9c815126cd26df7961..1a9c61ca6d9cefe39df7f14799e42ad2d145f25e 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -284,16 +284,18 @@ int
 mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix)
 {
   char buffer[SHORT_STRING];
-
+  
   if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == -1)
     return (-1);
 
   if (flags & CH_TXTPLAIN)
   {
+    char chsbuf[SHORT_STRING];
     fputs ("Mime-Version: 1.0\n", out);
     fputs ("Content-Transfer-Encoding: 8bit\n", out);
     fputs ("Content-Type: text/plain; charset=", out);
-    rfc822_cat(buffer, sizeof(buffer), Charset ? Charset : "", MimeSpecials);
+    mutt_canonical_charset (chsbuf, sizeof (chsbuf), Charset ? Charset : "us-ascii");
+    rfc822_cat(buffer, sizeof(buffer), chsbuf, MimeSpecials);
     fputs(buffer, out);
     fputc('\n', out);
     
diff --git a/mbyte.c b/mbyte.c
index ceb227281415ef7248c3d028a0d68741a1fbcb3e..c38e3fa92c9263a4b45cfd79ca9bb92013d9190d 100644 (file)
--- a/mbyte.c
+++ b/mbyte.c
@@ -41,7 +41,7 @@ static iconv_t charset_from_utf8 = (iconv_t)(-1);
 
 void mutt_set_charset (char *charset)
 {
-  char buffer[8];
+  char buffer[STRING];
 
   mutt_canonical_charset (buffer, sizeof (buffer), charset);
 
index 255a6e08725f773280502f6be9f388c2d0b85eec..f5217984cc4a4551fe991222090a3b9e9a21cc5b 100644 (file)
--- a/rfc2047.c
+++ b/rfc2047.c
@@ -357,7 +357,7 @@ static int rfc2047_encode (const char *d, size_t dlen, int col,
   size_t ulen, r, n, wlen;
   encoder_t encoder;
   char *tocode1 = 0;
-  const char *tocode;
+  char tocode[STRING];
   char *icode = "UTF-8";
 
   /* Try to convert to UTF-8. */
@@ -384,15 +384,18 @@ static int rfc2047_encode (const char *d, size_t dlen, int col,
   }
 
   /* Choose target charset. */
-  tocode = fromcode;
+  mutt_canonical_charset (tocode, sizeof (tocode), fromcode);
   if (icode)
   {
     if ((tocode1 = mutt_choose_charset (icode, charsets, u, ulen, 0, 0)))
-      tocode = tocode1;
+      mutt_canonical_charset (tocode, sizeof (tocode), tocode1);
     else
       ret = 2, icode = 0;
   }
-
+  
+  if (mutt_is_us_ascii (tocode))
+    strfcpy (tocode, "unknown-8bit", sizeof (tocode));
+  
   /* Adjust t0 for maximum length of line. */
   t = u + (ENCWORD_LEN_MAX + 1) - col - ENCWORD_LEN_MIN;
   t = t > u ? t : u;
index c3aca6ae2193c8251521cb7776a8b9607f789911..9f8f00d2207f712cbec0c7cde62528f8102893d0 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -890,6 +890,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b)
   FILE *fp = NULL;
   char *tocode;
   char buffer[100];
+  char chsbuf[STRING];
   size_t r;
 
   if(b && !fname) fname = b->filename;
@@ -912,7 +913,10 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b)
                              0, &tocode, info) != (size_t)(-1))
     {
       if (!chs)
+      {
+       mutt_canonical_charset (chsbuf, sizeof (chsbuf), tocode);
        mutt_set_parameter ("charset", tocode, &b->parameter);
+      }
       safe_free ((void **) &tocode);
       safe_fclose (&fp);
       return info;
@@ -928,7 +932,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b)
   
   if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
     mutt_set_parameter ("charset", (!info->hibin ? "us-ascii" :
-                                   Charset ? Charset : "unknown-8bit"),
+                                   Charset  && !mutt_is_us_ascii (Charset) ? Charset : "unknown-8bit"),
                        &b->parameter);
 
   return info;
@@ -1159,7 +1163,7 @@ static void mutt_set_encoding (BODY *b, CONTENT *info)
   if (b->type == TYPETEXT)
   {
     char *chsname = mutt_get_body_charset (send_charset, sizeof (send_charset), b);
-    if ((info->lobin && strncasecmp (chsname, "iso-2022-jp", 11)) || info->linemax > 990 || (info->from && option (OPTENCODEFROM)))
+    if ((info->lobin && strncasecmp (chsname, "iso-2022", 8)) || info->linemax > 990 || (info->from && option (OPTENCODEFROM)))
       b->encoding = ENCQUOTEDPRINTABLE;
     else if (info->hibin)
       b->encoding = option (OPTALLOW8BIT) ? ENC8BIT : ENCQUOTEDPRINTABLE;
@@ -1210,7 +1214,7 @@ char *mutt_get_body_charset (char *d, size_t dlen, BODY *b)
     p = mutt_get_parameter ("charset", b->parameter);
 
   if (p)
-    strfcpy (d, NONULL(p), dlen);
+    mutt_canonical_charset (d, dlen, NONULL(p));
   else
     strfcpy (d, "us-ascii", dlen);