diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 1999-02-02 15:47:44 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 1999-02-02 15:47:44 +0000 |
commit | be3b539741a3293ea5369c6817b2fbad28628c51 (patch) | |
tree | 6f80a6e005d49de6328e9258bb5cd1bb8248eb9b /handler.c | |
parent | 7403d5e81d9463c16c7f3ce19009460ef8816353 (diff) |
Merging the external character set patch into unstable.
Additionally, this change introduces a M_CHARCONV state flag which
gives us some more control about when character set conversions are
actually done. Current versions of mutt would happily apply
character set conversions when, e.g., saving a text/plain attachment
to a file. (We had at least one corrupt russing translation file
due to this mis-feature.)
Additionally, we clean up some of the character set related code in
handler.c. Most of that is now done by the decoder functions in
charset.c.
Diffstat (limited to 'handler.c')
-rw-r--r-- | handler.c | 94 |
1 files changed, 21 insertions, 73 deletions
@@ -64,14 +64,6 @@ int Index_64[128] = { 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1 }; -static void state_maybe_utf8_putc(STATE *s, char c, int is_utf8, CHARSET *chs, CHARSET_MAP *map) -{ - if(is_utf8) - state_fput_utf8(s, c, chs); - else - state_prefix_putc(mutt_display_char ((unsigned char) c, map), s); -} - void mutt_decode_xbit (STATE *s, BODY *b, int istext) { long len = b->length; @@ -79,15 +71,7 @@ void mutt_decode_xbit (STATE *s, BODY *b, int istext) if (istext) { - CHARSET_MAP *map = NULL; - CHARSET *chs = NULL; - char *charset = mutt_get_parameter("charset", b->parameter); - int is_utf8; - - if((is_utf8 = (mutt_is_utf8(charset) && !mutt_is_utf8(Charset)))) - chs = mutt_get_charset(Charset); - else - map = mutt_get_translation(charset, Charset); + DECODER *dec = mutt_open_decoder (s, b, istext); state_set_prefix(s); @@ -104,14 +88,10 @@ void mutt_decode_xbit (STATE *s, BODY *b, int istext) ungetc(ch, s->fpin); } - state_maybe_utf8_putc(s, c, is_utf8, chs, map); + mutt_decoder_putc (dec, c); } - - state_reset_prefix(s); - - if(is_utf8) - state_fput_utf8(s, '\0', chs); - + mutt_close_decoder (&dec); + state_reset_prefix (s); } else mutt_copy_bytes (s->fpin, s->fpout, len); @@ -133,18 +113,7 @@ void mutt_decode_quoted (STATE *s, BODY *b, int istext) { long len = b->length; int ch; - char *charset = mutt_get_parameter("charset", b->parameter); - int is_utf8 = 0; - CHARSET *chs = NULL; - CHARSET_MAP *map = NULL; - - if(istext) - { - if((is_utf8 = (mutt_is_utf8(charset) && !mutt_is_utf8(Charset)))) - chs = mutt_get_charset(Charset); - else - map = mutt_get_translation(charset, Charset); - } + DECODER *dec = mutt_open_decoder (s, b, istext); state_set_prefix(s); @@ -200,14 +169,13 @@ void mutt_decode_quoted (STATE *s, BODY *b, int istext) { continue; } + if(ch != EOF) - state_maybe_utf8_putc(s, ch, is_utf8, chs, map); + mutt_decoder_putc (dec, ch); } - - state_reset_prefix(s); - if(is_utf8) - state_fput_utf8(s, '\0', chs); + mutt_close_decoder (&dec); + state_reset_prefix(s); } void mutt_decode_base64 (STATE *s, BODY *b, int istext) @@ -215,18 +183,7 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext) long len = b->length; char buf[5]; int c1, c2, c3, c4, ch, cr = 0, i; - char *charset = mutt_get_parameter("charset", b->parameter); - CHARSET_MAP *map = NULL; - CHARSET *chs = NULL; - int is_utf8 = 0; - - if(istext) - { - if((is_utf8 = (mutt_is_utf8(charset) && !mutt_is_utf8(Charset)))) - chs = mutt_get_charset(Charset); - else - map = mutt_get_translation(charset, Charset); - } + DECODER *dec = mutt_open_decoder (s, b, istext); buf[4] = 0; @@ -249,13 +206,13 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext) ch = (c1 << 2) | (c2 >> 4); if (cr && ch != '\n') - state_maybe_utf8_putc(s, '\r', is_utf8, chs, map); + mutt_decoder_putc (dec, '\r'); cr = 0; if (istext && ch == '\r') cr = 1; else - state_maybe_utf8_putc(s, ch, is_utf8, chs, map); + mutt_decoder_putc (dec, ch); if (buf[2] == '=') break; @@ -263,28 +220,29 @@ void mutt_decode_base64 (STATE *s, BODY *b, int istext) ch = ((c2 & 0xf) << 4) | (c3 >> 2); if (cr && ch != '\n') - state_maybe_utf8_putc(s, ch, is_utf8, chs, map); + mutt_decoder_putc (dec, ch); cr = 0; if (istext && ch == '\r') cr = 1; else - state_maybe_utf8_putc(s, ch, is_utf8, chs, map); + mutt_decoder_putc (dec, ch); if (buf[3] == '=') break; c4 = base64val (buf[3]); ch = ((c3 & 0x3) << 6) | c4; if (cr && ch != '\n') - state_maybe_utf8_putc(s, ch, is_utf8, chs, map); + mutt_decoder_putc (dec, ch); cr = 0; if (istext && ch == '\r') cr = 1; else - state_maybe_utf8_putc(s, ch, is_utf8, chs, map); + mutt_decoder_putc (dec, ch); } + mutt_close_decoder (&dec); state_reset_prefix(s); } @@ -300,17 +258,9 @@ void mutt_decode_uuencoded (STATE *s, BODY *b, int istext) char tmps[SHORT_STRING]; char linelen, c, l, out; char *pt; - CHARSET_MAP *map = NULL; - CHARSET *chs = NULL; - char *charset = mutt_get_parameter("charset", b->parameter); - int is_utf8 = 0; long len = b->length; + DECODER *dec = mutt_open_decoder (s, b, istext); - if(istext && (is_utf8 = (mutt_is_utf8(charset) && !mutt_is_utf8(Charset)))) - chs = mutt_get_charset(Charset); - else - map = mutt_get_translation(charset, Charset); - if(istext) state_set_prefix(s); @@ -339,7 +289,7 @@ void mutt_decode_uuencoded (STATE *s, BODY *b, int istext) out = decode_byte (*pt) << l; pt++; out |= (decode_byte (*pt) >> (6 - l)); - state_maybe_utf8_putc(s, out, is_utf8, chs, map); + mutt_decoder_putc (dec, out); c++; if (c == linelen) break; @@ -347,11 +297,9 @@ void mutt_decode_uuencoded (STATE *s, BODY *b, int istext) pt++; } } - + + mutt_close_decoder (&dec); state_reset_prefix(s); - if(is_utf8) - state_fput_utf8(s, '\0', chs); - } /* ---------------------------------------------------------------------------- |