Permalink
Browse files

Add $assumed_charset, $file_charset and $strict_mime.

--HG--
branch : HEAD
  • Loading branch information...
ttkzw committed Feb 24, 2007
1 parent bdacee9 commit ee628ac8f5ee7d27dc50bfe2410c5c9dead7c594
Showing with 283 additions and 18 deletions.
  1. +2 −0 UPDATING
  2. +83 −0 charset.c
  3. +2 −0 charset.h
  4. +2 −0 globals.h
  5. +14 −4 handler.c
  6. +44 −0 init.h
  7. +2 −0 mutt.h
  8. +18 −2 parse.c
  9. +103 −9 rfc2047.c
  10. +5 −0 rfc2231.c
  11. +8 −3 sendlib.c
View
@@ -4,6 +4,8 @@ mutt. Please read this file carefully when upgrading your installation.
The keys used are:
!: modified feature, -: deleted feature, +: new feature
+ + $assumed_charset, $file_charset, $strict_mime
+ + $smtp_url (ESMTP relay support)
+ $crypt_use_pka (use GPGME PKA signature verification)
1.5.13 (2006-08-14):
View
@@ -591,3 +591,86 @@ void fgetconv_close (FGETCONV **_fc)
iconv_close (fc->cd);
FREE (_fc); /* __FREE_CHECKED__ */
}
+
+const char *mutt_get_first_charset (const char *charset)
+{
+ static char fcharset[SHORT_STRING];
+ const char *c, *c1;
+
+ c = charset;
+ if (!mutt_strlen(c))
+ return "us-ascii";
+ if (!(c1 = strchr (c, ':')))
+ return charset;
+ strfcpy (fcharset, c, c1 - c + 1);
+ return fcharset;
+}
+
+static size_t convert_string (ICONV_CONST char *f, size_t flen,
+ const char *from, const char *to,
+ char **t, size_t *tlen)
+{
+ iconv_t cd;
+ char *buf, *ob;
+ size_t obl, n;
+ int e;
+
+ cd = mutt_iconv_open (to, from, 0);
+ if (cd == (iconv_t)(-1))
+ return (size_t)(-1);
+ obl = 4 * flen + 1;
+ ob = buf = safe_malloc (obl);
+ n = iconv (cd, &f, &flen, &ob, &obl);
+ if (n == (size_t)(-1) || iconv (cd, 0, 0, &ob, &obl) == (size_t)(-1))
+ {
+ e = errno;
+ FREE (&buf);
+ iconv_close (cd);
+ errno = e;
+ return (size_t)(-1);
+ }
+ *ob = '\0';
+
+ *tlen = ob - buf;
+
+ safe_realloc ((void **) &buf, ob - buf + 1);
+ *t = buf;
+ iconv_close (cd);
+
+ return n;
+}
+
+int mutt_convert_nonmime_string (char **ps)
+{
+ const char *c, *c1;
+
+ for (c = AssumedCharset; c; c = c1 ? c1 + 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;
+
+ c1 = strchr (c, ':');
+ n = c1 ? c1 - c : mutt_strlen (c);
+ if (!n)
+ continue;
+ fromcode = safe_malloc (n + 1);
+ strfcpy (fromcode, c, n + 1);
+ m = convert_string (u, ulen, fromcode, Charset, &s, &slen);
+ FREE (&fromcode);
+ if (m != (size_t)(-1))
+ {
+ FREE (ps); /* __FREE_CHECKED__ */
+ *ps = s;
+ return 0;
+ }
+ }
+ return -1;
+}
+
View
@@ -35,6 +35,8 @@ int iconv_close (iconv_t);
#endif
int mutt_convert_string (char **, const char *, const char *, int);
+const char *mutt_get_first_charset (const char *);
+int mutt_convert_nonmime_string (char **);
iconv_t mutt_iconv_open (const char *, const char *, int);
size_t mutt_iconv (iconv_t, ICONV_CONST char **, size_t *, char **, size_t *, ICONV_CONST char **, const char *);
View
@@ -33,6 +33,7 @@ WHERE ADDRESS *From;
WHERE char *AliasFile;
WHERE char *AliasFmt;
+WHERE char *AssumedCharset;
WHERE char *AttachSep;
WHERE char *Attribution;
WHERE char *AttachFormat;
@@ -47,6 +48,7 @@ WHERE char *DsnNotify;
WHERE char *DsnReturn;
WHERE char *Editor;
WHERE char *EscChar;
+WHERE char *FileCharset;
WHERE char *FolderFormat;
WHERE char *ForwFmt;
WHERE char *Fqdn;
View
@@ -1743,11 +1743,21 @@ void mutt_decode_attachment (BODY *b, STATE *s)
int istext = mutt_is_text_part (b);
iconv_t cd = (iconv_t)(-1);
- if (istext && s->flags & M_CHARCONV)
+ if (istext)
{
- char *charset = mutt_get_parameter ("charset", b->parameter);
- if (charset && Charset)
- cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM);
+ if(s->flags & M_CHARCONV)
+ {
+ char *charset = mutt_get_parameter ("charset", b->parameter);
+ if (!option (OPTSTRICTMIME) && !charset)
+ charset = mutt_get_first_charset (AssumedCharset);
+ if (charset && Charset)
+ cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM);
+ }
+ else
+ {
+ if (b->file_charset)
+ cd = mutt_iconv_open (Charset, b->file_charset, M_ICONV_HOOK_FROM);
+ }
}
fseeko (s->fpin, b->offset, 0);
View
44 init.h
@@ -218,6 +218,23 @@ struct option_t MuttVars[] = {
** 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 "us-ascii"},
+ /*
+ ** .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.
+ ** This variable is valid only if $$strict_mime is unset.
+ */
{ "attach_format", DT_STR, R_NONE, UL &AttachFormat, UL "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " },
/*
** .pp
@@ -597,6 +614,20 @@ struct option_t MuttVars[] = {
** signed.
** (PGP only)
*/
+ { "file_charset", DT_STR, R_NONE, UL &FileCharset, UL 0 },
+ /*
+ ** .pp
+ ** This variable is a colon-separated list of character encoding
+ ** schemes for text file attatchments.
+ ** If unset, $$charset value will be used instead.
+ ** For example, the following configuration would work for Japanese
+ ** text handling:
+ ** .pp
+ ** set file_charset="iso-2022-jp:euc-jp:shift_jis:utf-8"
+ ** .pp
+ ** Note: "iso-2022-*" must be put at the head of the value as shown above
+ ** if included.
+ */
{ "folder", DT_PATH, R_NONE, UL &Maildir, UL "~/Mail" },
/*
** .pp
@@ -2766,6 +2797,19 @@ struct option_t MuttVars[] = {
** Setting this variable causes the ``status bar'' to be displayed on
** the first line of the screen rather than near the bottom.
*/
+ { "strict_mime", DT_BOOL, R_NONE, OPTSTRICTMIME, 1 },
+ /*
+ ** .pp
+ ** When unset, non MIME-compliant messages that doesn't have any
+ ** charset indication in ``Content-Type'' field can be displayed
+ ** (non MIME-compliant messages are often generated by old mailers
+ ** or buggy mailers like MS Outlook Express).
+ ** See also $$assumed_charset.
+ ** .pp
+ ** This option also replaces linear-white-space between encoded-word
+ ** and *text to a single space to prevent the display of MIME-encoded
+ ** ``Subject'' field from being devided into multiple lines.
+ */
{ "strict_threads", DT_BOOL, R_RESORT|R_RESORT_INIT|R_INDEX, OPTSTRICTTHREADS, 0 },
/*
** .pp
View
2 mutt.h
@@ -428,6 +428,7 @@ enum
OPTSORTRE,
OPTSPAMSEP,
OPTSTATUSONTOP,
+ OPTSTRICTMIME,
OPTSTRICTTHREADS,
OPTSUSPEND,
OPTTEXTFLOWED,
@@ -642,6 +643,7 @@ typedef struct body
* If NULL, filename is used
* instead.
*/
+ char *file_charset; /* charset of attached file */
CONTENT *content; /* structure used to store detailed info about
* the content of the attachment. this is used
* to determine what content-transfer-encoding
View
20 parse.c
@@ -213,9 +213,23 @@ static PARAMETER *parse_parameters (const char *s)
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 (!option (OPTSTRICTMIME)) {
+ /* 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 */
@@ -388,7 +402,9 @@ void mutt_parse_content_type (char *s, BODY *ct)
if (ct->type == TYPETEXT)
{
if (!(pc = mutt_get_parameter ("charset", ct->parameter)))
- mutt_set_parameter ("charset", "us-ascii", &ct->parameter);
+ mutt_set_parameter ("charset", option (OPTSTRICTMIME) ? "us-ascii" :
+ (const char *) mutt_get_first_charset (AssumedCharset),
+ &ct->parameter);
}
}
Oops, something went wrong.

0 comments on commit ee628ac

Please sign in to comment.