# 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
{ NULL, NULL }
};
+#ifdef HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+
+
void mutt_set_langinfo_charset (void)
{
char buff[LONG_STRING];
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);
void mutt_set_charset (char *charset)
{
- char buffer[8];
+ char buffer[STRING];
mutt_canonical_charset (buffer, sizeof (buffer), charset);
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. */
}
/* 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;
FILE *fp = NULL;
char *tocode;
char buffer[100];
+ char chsbuf[STRING];
size_t r;
if(b && !fname) fname = b->filename;
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;
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;
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;
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);