]> diplodocus.org Git - nmh/blobdiff - uip/mhshowsbr.c
Merge remote-tracking branch 'origin' into xoauth
[nmh] / uip / mhshowsbr.c
index 4b11494e50063ac29937dcb975c403cc3da8ad58..a87778efcf7e4677a85b67317e140261d2205982 100644 (file)
@@ -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.