+#ifdef HAVE_ICONV
+ iconvbuffull:
+ /* NB that the string at convbuf is not necessarily NUL terminated here:
+ * q points to the first byte after the valid part.
+ */
+ /* Convert to native character set */
+ if (use_iconv) {
+ size_t inbytes = q - convbuf;
+ ICONV_CONST char *start = convbuf;
+
+ while (inbytes) {
+ if (iconv(cd, &start, &inbytes, &saveq, &savedstlen) ==
+ (size_t)-1) {
+ if (errno != EILSEQ) break;
+ /* character couldn't be converted. we output a `?'
+ * and try to carry on which won't work if
+ * either encoding was stateful */
+ iconv (cd, 0, 0, &saveq, &savedstlen);
+ if (!savedstlen)
+ break;
+ *saveq++ = '?';
+ savedstlen--;
+ if (!savedstlen)
+ break;
+ /* skip to next input character */
+ if (fromutf8) {
+ for (start++;(start < q) && ((*start & 192) == 128);start++)
+ inbytes--;
+ } else
+ start++, inbytes--;
+ if (start >= q)
+ break;
+ }
+ }
+ q = saveq;
+ /* Stop now if (1) we hit the end of the buffer trying to do
+ * MIME decoding and have just iconv-converted a partial string
+ * or (2) our iconv-conversion hit the end of the buffer.
+ */
+ if (!dstlen || !savedstlen)
+ goto buffull;
+ dstlen = savedstlen;
+ free(convbuf);
+ }
+#endif
+