X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/f1b704d05c9a2209edf851392220438e62470314..e6917522:/uip/mhshowsbr.c diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index e3b8d6bb..45c73cbe 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -362,8 +362,8 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked) if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) return NOTOK; } else { - admonish (NULL, "unable to convert character set%s to %s", - ct->c_partno ? "of part " : "", + admonish (NULL, "unable to convert character set%s%s to %s", + ct->c_partno ? " of part " : "", ct->c_partno ? ct->c_partno : "", content_charset (ct)); } @@ -466,7 +466,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer, close (fd); execvp (file, vec); fprintf (stderr, "unable to exec "); - perror ("/bin/sh"); + perror (buffer); _exit (-1); /* NOTREACHED */ @@ -508,9 +508,12 @@ show_text (CT ct, int alternate, int concatsw) * if it is not a text part of a multipart/alternative */ if (!alternate || ct->c_subtype == TEXT_PLAIN) { - if (concatsw) - snprintf(buffer, sizeof(buffer), "%%l"); - else + if (concatsw) { + if (ct->c_termproc) + snprintf(buffer, sizeof(buffer), "%%lcat"); + else + snprintf(buffer, sizeof(buffer), "%%l"); + } else snprintf (buffer, sizeof(buffer), "%%l%s %%F", progsw ? progsw : moreproc && *moreproc ? moreproc : DEFAULT_PAGER); cp = (ct->c_showproc = add (buffer, NULL)); @@ -704,7 +707,7 @@ show_message_rfc822 (CT ct, int alternate) /* default method for message/rfc822 */ if (ct->c_subtype == MESSAGE_RFC822) { - cp = (ct->c_showproc = add ("%pecho -file %F", NULL)); + cp = (ct->c_showproc = add ("%pshow -file %F", NULL)); return show_content_aux (ct, alternate, cp, NULL); } @@ -1043,6 +1046,8 @@ convert_charset (CT ct, char *dest_charset, int *message_mods) { size_t end; int opened_input_file = 0; char src_buffer[BUFSIZ]; + size_t dest_buffer_size = BUFSIZ; + char *dest_buffer = mh_xmalloc(dest_buffer_size); HF hf; char *tempfile; @@ -1089,16 +1094,30 @@ convert_charset (CT ct, char *dest_charset, int *message_mods) { while ((inbytes = fread (src_buffer, 1, min (bytes_to_read, sizeof src_buffer), *fp)) > 0) { - char dest_buffer[BUFSIZ]; ICONV_CONST char *ib = src_buffer; char *ob = dest_buffer; - size_t outbytes = sizeof dest_buffer; + size_t outbytes = dest_buffer_size; size_t outbytes_before = outbytes; if (end > 0) bytes_to_read -= inbytes; +iconv_start: if (iconv (conv_desc, &ib, &inbytes, &ob, &outbytes) == (size_t) -1) { + if (errno == E2BIG) { + /* + * Bump up the buffer by at least a factor of 2 + * over what we need. + */ + size_t bumpup = inbytes * 2, ob_off = ob - dest_buffer; + dest_buffer_size += bumpup; + dest_buffer = mh_xrealloc(dest_buffer, + dest_buffer_size); + ob = dest_buffer + ob_off; + outbytes += bumpup; + outbytes_before += bumpup; + goto iconv_start; + } status = NOTOK; break; } else { @@ -1161,11 +1180,13 @@ convert_charset (CT ct, char *dest_charset, int *message_mods) { } else { (void) m_unlink (dest); } + free(dest_buffer); #else /* ! HAVE_ICONV */ NMH_UNUSED (message_mods); advise (NULL, "Can't convert %s to %s without iconv", src_charset, dest_charset); + errno = ENOSYS; status = NOTOK; #endif /* ! HAVE_ICONV */ }