static gboolean isprintableeuckanji(guchar c1, guchar c2)
{
- if (c1 <= 0xa0 || c1 == 0xff)
+ if (c1 <= 0xa0 || c1 >= 0xf5)
return FALSE;
if (c2 <= 0xa0 || c2 == 0xff)
return FALSE;
else {
gchar *str;
- str = conv_codeset_strdup(inbuf, conv->charset_str, NULL);
+ str = conv_iconv_strdup(inbuf, conv->charset_str, NULL);
if (!str)
return -1;
else {
}
#if HAVE_ICONV
- if (!src_code)
- src_code = conv_get_outgoing_charset_str();
- if (!dest_code) {
- dest_code = conv_get_current_charset_str();
- if (!strcasecmp(dest_code, CS_US_ASCII))
- dest_code = CS_ISO_8859_1;
- }
-
- /* don't convert if current codeset is US-ASCII */
- if (!strcasecmp(dest_code, CS_US_ASCII))
- return g_strdup(inbuf);
-
- /* don't convert if src and dest codeset are identical */
- if (!strcasecmp(src_code, dest_code))
- return g_strdup(inbuf);
-
return conv_iconv_strdup(inbuf, src_code, dest_code);
#else
return g_strdup(inbuf);
if (dest_charset == C_US_ASCII)
return conv_ustodisp;
+ else if (dest_charset == C_UTF_8 ||
+ (dest_charset == C_AUTO &&
+ conv_get_current_charset() == C_UTF_8))
+ return conv_noconv;
switch (src_charset) {
case C_ISO_2022_JP:
code_conv = conv_ustodisp;
break;
case C_ISO_8859_1:
-#if !HAVE_ICONV
case C_ISO_8859_2:
case C_ISO_8859_4:
case C_ISO_8859_5:
case C_ISO_8859_11:
case C_ISO_8859_13:
case C_ISO_8859_15:
-#endif
if (dest_charset == C_AUTO)
code_conv = conv_latintodisp;
break;
gint out_left;
gint n_conv;
+ if (!src_code)
+ src_code = conv_get_outgoing_charset_str();
+ if (!dest_code)
+ dest_code = conv_get_current_charset_str();
+
+ /* don't convert if current codeset is US-ASCII */
+ if (!strcasecmp(dest_code, CS_US_ASCII))
+ return g_strdup(inbuf);
+
+ /* don't convert if src and dest codeset are identical */
+ if (!strcasecmp(src_code, dest_code))
+ return g_strdup(inbuf);
+
cd = iconv_open(dest_code, src_code);
if (cd == (iconv_t)-1)
return NULL;
while ((n_conv = iconv(cd, (ICONV_CONST gchar **)&inbuf_p, &in_left,
&outbuf_p, &out_left)) < 0) {
if (EILSEQ == errno) {
- g_free(outbuf);
- outbuf = NULL;
- break;
+ inbuf_p++;
+ in_left--;
+ *outbuf_p++ = SUBST_CHAR;
+ out_left--;
} else if (EINVAL == errno) {
- g_free(outbuf);
- outbuf = NULL;
+ *outbuf_p = '\0';
break;
} else if (E2BIG == errno) {
out_size *= 2;
}
}
- if (outbuf) {
- iconv(cd, NULL, NULL, &outbuf_p, &out_left);
- outbuf = g_realloc(outbuf, strlen(outbuf) + 1);
- }
+ iconv(cd, NULL, NULL, &outbuf_p, &out_left);
+ outbuf = g_realloc(outbuf, strlen(outbuf) + 1);
iconv_close(cd);
unmime_header(outbuf, str);
}
-#define MAX_LINELEN 76
-#define MIMESEP_BEGIN "=?"
-#define MIMESEP_END "?="
+#define MAX_LINELEN 76
+#define MAX_HARD_LINELEN 996
+#define MIMESEP_BEGIN "=?"
+#define MIMESEP_END "?="
#define B64LEN(len) ((len) / 3 * 4 + ((len) % 3 ? 4 : 0))
-#define LBREAK_IF_REQUIRED(cond, plaintext) \
-{ \
- if (len - (destp - dest) < MAX_LINELEN + 2) { \
- *destp = '\0'; \
- return; \
- } \
- \
- if ((cond) && *srcp) { \
- if (destp > dest && isspace(*(destp - 1))) \
- destp--; \
- else if (plaintext && isspace(*srcp)) \
- srcp++; \
- if (destp > dest && *srcp) { \
- *destp++ = '\n'; \
- *destp++ = ' '; \
- left = MAX_LINELEN - 1; \
- } \
- } \
+#define LBREAK_IF_REQUIRED(cond, is_plain_text) \
+{ \
+ if (len - (destp - dest) < MAX_LINELEN + 2) { \
+ *destp = '\0'; \
+ return; \
+ } \
+ \
+ if ((cond) && *srcp) { \
+ if (destp > dest && left < MAX_LINELEN - 1) { \
+ if (isspace(*(destp - 1))) \
+ destp--; \
+ else if (is_plain_text && isspace(*srcp)) \
+ srcp++; \
+ if (*srcp) { \
+ *destp++ = '\n'; \
+ *destp++ = ' '; \
+ left = MAX_LINELEN - 1; \
+ } \
+ } \
+ } \
}
void conv_encode_header(gchar *dest, gint len, const gchar *src,
word_len = get_next_word_len(srcp);
LBREAK_IF_REQUIRED(left < word_len, TRUE);
while (word_len > 0) {
- LBREAK_IF_REQUIRED(left + 22 <= 0, TRUE);
+ LBREAK_IF_REQUIRED(left + (MAX_HARD_LINELEN - MAX_LINELEN) <= 0, TRUE)
*destp++ = *srcp++;
left--;
word_len--;