X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/5b035a57c6f503870fa01242724c20ef907bc35c..8e0f9bd3daae9d05dec58026d5a5924367e4e874:/uip/mhshowsbr.c diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index 4b11494e..a87778ef 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -1080,6 +1080,7 @@ convert_charset (CT ct, char *dest_charset, int *message_mods) { char *dest_buffer = mh_xmalloc(dest_buffer_size); HF hf; char *tempfile; + int fromutf8 = !strcasecmp(src_charset, "UTF-8"); if ((conv_desc = iconv_open (dest_charset, src_charset)) == (iconv_t) -1) { @@ -1149,6 +1150,32 @@ iconv_start: outbytes_before += bumpup; goto iconv_start; } + if (errno == EINVAL) { + /* middle of multi-byte sequence */ + if (write (fd, dest_buffer, outbytes_before - outbytes) < 0) { + advise (dest, "write"); + } + fseeko (*fp, -inbytes, SEEK_CUR); + if (end > 0) bytes_to_read += inbytes; + /* advise(NULL, "convert_charset: EINVAL"); */ + continue; + } + if (errno == EILSEQ) { + /* invalid multi-byte sequence */ + if (fromutf8) { + for (++ib, --inbytes; + inbytes > 0 && + (((unsigned char) *ib) & 0xc0) == 0x80; + ++ib, --inbytes) + continue; + } else { + ib++; inbytes--; /* skip it */ + } + (*ob++) = '?'; outbytes --; + /* advise(NULL, "convert_charset: EILSEQ"); */ + goto iconv_start; + } + advise (NULL, "convert_charset: errno = %d", errno); status = NOTOK; break; } else { @@ -1355,12 +1382,10 @@ static void output_header(CT ct, struct format *fmt) { charstring_t outbuf = charstring_create (BUFSIZ); - int dat[5]; + int dat[5] = { 0 }; char *endp; int message = 0; - dat[0] = dat[1] = dat[2] = dat[3] = dat[4] = dat[5] = 0; - if (folder_comp) folder_comp->c_text = getcpy(folder); @@ -1392,9 +1417,7 @@ output_marker(CT ct, struct format *fmt, int hidden) int partsize; int message = 0; char *endp; - int dat[5]; - - dat[0] = dat[1] = dat[2] = dat[3] = dat[4] = dat[5] = 0; + int dat[5] = { 0 }; /* * Grab any items we care about.