diff -ur mutt-1.5.9.orig/PATCHES mutt-1.5.9/PATCHES --- mutt-1.5.9.orig/PATCHES 2005-03-14 01:33:06.000000000 +0900 +++ mutt-1.5.9/PATCHES 2005-03-28 01:47:46.229872728 +0900 @@ -0,0 +1 @@ +patch-1.5.9.tt.assumed_charset.2 diff -ur mutt-1.5.9.orig/charset.c mutt-1.5.9/charset.c --- mutt-1.5.9.orig/charset.c 2005-02-13 04:53:00.000000000 +0900 +++ mutt-1.5.9/charset.c 2005-03-28 01:47:46.234871968 +0900 @@ -282,6 +282,21 @@ return !ascii_strcasecmp (buffer, chs); } +char *mutt_get_default_charset () +{ + static char fcharset[SHORT_STRING]; + const char *c = AssumedCharset; + const char *c1; + + if (c && *c) + { + c1 = strchr (c, ':'); + strfcpy (fcharset, c, c1 ? (c1 - c + 1) : (mutt_strlen (c) + 1)); + } + else + strcpy (fcharset, "us-ascii"); + return fcharset; +} #ifndef HAVE_ICONV diff -ur mutt-1.5.9.orig/charset.h mutt-1.5.9/charset.h --- mutt-1.5.9.orig/charset.h 2003-03-03 19:22:06.000000000 +0900 +++ mutt-1.5.9/charset.h 2005-03-28 01:47:46.237871512 +0900 @@ -47,6 +47,7 @@ void fgetconv_close (FGETCONV **); void mutt_set_langinfo_charset (void); +char *mutt_get_default_charset (); #define M_ICONV_HOOK_FROM 1 #define M_ICONV_HOOK_TO 2 diff -ur mutt-1.5.9.orig/globals.h mutt-1.5.9/globals.h --- mutt-1.5.9.orig/globals.h 2005-02-13 05:01:02.000000000 +0900 +++ mutt-1.5.9/globals.h 2005-03-28 01:47:46.240871056 +0900 @@ -32,6 +32,7 @@ WHERE char *AliasFile; WHERE char *AliasFmt; +WHERE char *AssumedCharset; WHERE char *AttachSep; WHERE char *Attribution; WHERE char *AttachFormat; diff -ur mutt-1.5.9.orig/handler.c mutt-1.5.9/handler.c --- mutt-1.5.9.orig/handler.c 2005-02-04 03:47:52.000000000 +0900 +++ mutt-1.5.9/handler.c 2005-03-28 01:47:46.250869536 +0900 @@ -1728,6 +1728,8 @@ if (istext && s->flags & M_CHARCONV) { char *charset = mutt_get_parameter ("charset", b->parameter); + if (!charset && AssumedCharset && *AssumedCharset) + charset = mutt_get_default_charset (); if (charset && Charset) cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM); } diff -ur mutt-1.5.9.orig/init.h mutt-1.5.9/init.h --- mutt-1.5.9.orig/init.h 2005-03-02 00:56:02.000000000 +0900 +++ mutt-1.5.9/init.h 2005-03-28 01:47:46.267866952 +0900 @@ -185,6 +185,22 @@ ** If set, Mutt will prompt you for carbon-copy (Cc) recipients before ** editing the body of an outgoing message. */ + { "assumed_charset", DT_STR, R_NONE, UL &AssumedCharset, UL 0}, + /* + ** .pp + ** This variable is a colon-separated list of character encoding + ** schemes for messages without character encoding indication. + ** Header field values and message body content without character encoding + ** indication would be assumed that they are written in one of this list. + ** By default, all the header fields and message body without any charset + ** indication are assumed to be in "us-ascii". + ** .pp + ** For example, Japanese users might prefer this: + ** .pp + ** set assumed_charset="iso-2022-jp:euc-jp:shift_jis:utf-8" + ** .pp + ** However, only the first content is valid for the message body. + */ { "attach_format", DT_STR, R_NONE, UL &AttachFormat, UL "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " }, /* ** .pp diff -ur mutt-1.5.9.orig/parse.c mutt-1.5.9/parse.c --- mutt-1.5.9.orig/parse.c 2005-02-21 13:45:57.000000000 +0900 +++ mutt-1.5.9/parse.c 2005-03-28 01:47:46.276865584 +0900 @@ -213,9 +213,23 @@ if (*s == '"') { + int state_ascii = 1; s++; - for (i=0; *s && *s != '"' && i < sizeof (buffer) - 1; i++, s++) + for (i=0; *s && i < sizeof (buffer) - 1; i++, s++) { + if (AssumedCharset && *AssumedCharset) { + /* As iso-2022-* has a characer of '"' with non-ascii state, + * ignore it. */ + if (*s == 0x1b && i < sizeof (buffer) - 2) + { + if (s[1] == '(' && (s[2] == 'B' || s[2] == 'J')) + state_ascii = 1; + else + state_ascii = 0; + } + } + if (state_ascii && *s == '"') + break; if (*s == '\\') { /* Quote the next character */ @@ -384,7 +398,9 @@ if (ct->type == TYPETEXT) { if (!(pc = mutt_get_parameter ("charset", ct->parameter))) - mutt_set_parameter ("charset", "us-ascii", &ct->parameter); + mutt_set_parameter ("charset", (AssumedCharset && *AssumedCharset) ? + (const char *) mutt_get_default_charset () + : "us-ascii", &ct->parameter); } } diff -ur mutt-1.5.9.orig/rfc2047.c mutt-1.5.9/rfc2047.c --- mutt-1.5.9.orig/rfc2047.c 2005-02-04 03:47:53.000000000 +0900 +++ mutt-1.5.9/rfc2047.c 2005-03-28 01:47:53.060834264 +0900 @@ -87,6 +87,39 @@ return n; } +int convert_nonmime_string (char **ps) +{ + const char *p, *q; + + for (p = AssumedCharset; p; p = q ? q + 1 : 0) + { + char *u = *ps; + char *s; + char *fromcode; + size_t m, n; + size_t ulen = mutt_strlen (*ps); + size_t slen; + + if (!u || !*u) + return 0; + + q = strchr (p, ':'); + n = q ? q - p : mutt_strlen (p); + if (!n) + continue; + fromcode = mutt_substrdup(p, q); + m = convert_string (u, ulen, fromcode, Charset, &s, &slen); + FREE (&fromcode); + if (m != (size_t)(-1)) + { + FREE (ps); + *ps = s; + return 0; + } + } + return -1; +} + char *mutt_choose_charset (const char *fromcode, const char *charsets, char *u, size_t ulen, char **d, size_t *dlen) { @@ -733,6 +766,22 @@ if (!(p = find_encoded_word (s, &q))) { /* no encoded words */ + if (AssumedCharset && *AssumedCharset) + { + char *t; + size_t tlen; + + t = safe_strdup (s); + if (convert_nonmime_string (&t) == 0) + { + tlen = mutt_strlen (t); + strncpy (d, t, tlen); + d += tlen; + FREE (&t); + break; + } + FREE (&t); + } strncpy (d, s, dlen); d += dlen; break; @@ -770,7 +819,8 @@ { while (a) { - if (a->personal && strstr (a->personal, "=?") != NULL) + if (a->personal && ((strstr (a->personal, "=?") != NULL) || + (AssumedCharset && *AssumedCharset))) rfc2047_decode (&a->personal); #ifdef EXACT_ADDRESS if (a->val && strstr (a->val, "=?") != NULL) diff -ur mutt-1.5.9.orig/rfc2047.h mutt-1.5.9/rfc2047.h --- mutt-1.5.9.orig/rfc2047.h 2002-12-11 20:19:40.000000000 +0900 +++ mutt-1.5.9/rfc2047.h 2005-03-28 01:47:46.285864216 +0900 @@ -18,6 +18,7 @@ char *mutt_choose_charset (const char *fromcode, const char *charsets, char *u, size_t ulen, char **d, size_t *dlen); +int convert_nonmime_string (char **); void _rfc2047_encode_string (char **, int, int); void rfc2047_encode_adrlist (ADDRESS *, const char *); diff -ur mutt-1.5.9.orig/rfc2231.c mutt-1.5.9/rfc2231.c --- mutt-1.5.9.orig/rfc2231.c 2005-02-04 03:47:53.000000000 +0900 +++ mutt-1.5.9/rfc2231.c 2005-03-28 01:47:46.289863608 +0900 @@ -117,6 +117,8 @@ if (option (OPTRFC2047PARAMS) && p->value && strstr (p->value, "=?")) rfc2047_decode (&p->value); + else if (AssumedCharset && *AssumedCharset) + convert_nonmime_string (&p->value); *last = p; last = &p->next;