Last active
September 14, 2016 17:00
-
-
Save amuramatsu/d0027ba6d2b33ad360b21e452230b4fc to your computer and use it in GitHub Desktop.
mh-6.8.4-JP-3.05-utf8.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -u conf/MH.in.orig conf/MH.in | |
--- conf/MH.in.orig 2016-09-10 21:56:53.000000000 +0900 | |
+++ conf/MH.in 2016-09-10 21:58:16.000000000 +0900 | |
@@ -15,7 +15,7 @@ | |
# some options | |
cc @CC@ | |
cpp @CPP@ | |
-ccoptions @CFLAGS@ | |
+ccoptions @CFLAGS@ -DWITH_ICONV | |
ldoptions @LDFLAGS@ | |
ldoptlibs @LIBS@ | |
curses @curses@ | |
diff -u sbr/formatsbr.c.orig sbr/formatsbr.c | |
--- sbr/formatsbr.c.orig 2001-04-03 01:12:40.000000000 +0900 | |
+++ sbr/formatsbr.c 2016-09-10 22:02:16.000000000 +0900 | |
@@ -652,7 +652,7 @@ | |
case FT_LS_HDECODE: | |
if (str) { | |
char *ep; | |
- if ((ep = malloc((unsigned)strlen(str)+1)) == NULL) | |
+ if ((ep = malloc((unsigned)strlen(str)*10+1)) == NULL) | |
adios(NULLCP, "out of memory"); | |
(void) exthdr_decode(str, ep); | |
(void) strncpy(buffer, ep, BUFSIZ); | |
diff -u sbr/ml_exthdr.c.orig sbr/ml_exthdr.c | |
--- sbr/ml_exthdr.c 1999-02-09 20:30:00.000000000 +0900 | |
+++ sbr/ml_exthdr.c.orig 2016-09-10 22:00:57.000000000 +0900 | |
@@ -7,6 +7,10 @@ | |
#include "../h/mh.h" | |
#include <stdio.h> | |
#include <ctype.h> | |
+#ifdef WITH_ICONV | |
+#include <iconv.h> | |
+#include <errno.h> | |
+#endif | |
#define MAXWIDTH 75 | |
@@ -697,6 +701,11 @@ | |
{ | |
char *ip, *cp, *tmp, buf[BUFSIZ], encode; | |
int result; | |
+#ifdef WITH_ICONV | |
+ int utf8_flag = 0; | |
+ const char *iconv_encoding = NULL; | |
+ char encoding_buf[BUFSIZ]; | |
+#endif /* WITH_ICONV */ | |
#ifdef JAPAN | |
if (japan_environ) | |
@@ -722,8 +731,24 @@ | |
if (*tmp++ != '-') return(-1); | |
} | |
} | |
+#ifdef WITH_ICONV | |
+ if (!uleq(buf, "us-ascii") && (!mm_charset || !uleq(buf, mm_charset))) { | |
+ if (uleq(buf, "utf-8")) { | |
+ utf8_flag = 1; | |
+ iconv_encoding = "utf-8"; | |
+ } | |
+ else if (uleq(buf, "shift_jis") || uleq(buf, "cp932")) { | |
+ iconv_encoding = "cp932"; | |
+ } | |
+ else { | |
+ strcpy(encoding_buf, buf); | |
+ iconv_encoding = encoding_buf; | |
+ } | |
+ } | |
+#else /* not WITH_ICONV */ | |
if (!uleq(buf, "us-ascii") && (!mm_charset || !uleq(buf, mm_charset))) | |
return(-1); | |
+#endif /* WITH_ICONV */ | |
ip = cp + 1; | |
if (ip > ep) return(-1); | |
if ((*ip == 'B') || (*ip == 'b')) | |
@@ -745,6 +770,50 @@ | |
} else { | |
(void) qpr_to_bin(buf, op); | |
} | |
+#ifdef WITH_ICONV | |
+ if (iconv_encoding) { | |
+ char *inbuf, *outbuf; | |
+ size_t inbuf_left, outbuf_left; | |
+ iconv_t conv; | |
+ do { | |
+ if (mm_charset) | |
+ conv = iconv_open(mm_charset, iconv_encoding); | |
+ else | |
+ conv = iconv_open("ascii", iconv_encoding); | |
+ if (conv == (iconv_t)-1 && strcmp(iconv_encoding, "cp932") == 0) { | |
+ iconv_encoding = "shift_jis"; /* FALLBACK */ | |
+ continue; | |
+ } | |
+ } while (0); | |
+ inbuf = op; inbuf_left = strlen(op); | |
+ outbuf = buf; outbuf_left = BUFSIZ - 1; | |
+ errno = 0; | |
+ while (iconv(conv, &inbuf, &inbuf_left, &outbuf, &outbuf_left) == (size_t)-1) { | |
+ if (errno == E2BIG) break; | |
+ errno = 0; | |
+ *outbuf++ = '?'; | |
+ if (--outbuf_left == 0) break; | |
+ if (utf8_flag) { | |
+ do { /* SKIP one charactor */ | |
+ inbuf++; inbuf_left--; | |
+ } while (inbuf_left > 0 && (*inbuf & 0xc0) == 0x80); | |
+ } | |
+ else { | |
+ /* SKIP one or two byte */ | |
+ /* if (inbuf_left > 1 && (*inbuf & 0x80) != 0) { | |
+ inbuf++; inbuf_left--; | |
+ } */ | |
+ inbuf++; inbuf_left--; | |
+ } | |
+ if (inbuf_left == 0) break; | |
+ } | |
+ iconv_close(conv); | |
+ buf[BUFSIZ-1 - outbuf_left] = '\0'; | |
+ strcpy(op, buf); | |
+ if (uleq(mm_charset, "iso-2022-jp")) | |
+ strcat(op, "\033(B"); | |
+ } | |
+#endif /* WITH_ICONV */ | |
return(strlen(op)); | |
} | |
diff -u uip/mhlsbr.c.orig uip/mhlsbr.c | |
--- uip/mhlsbr.c.orig 2016-09-10 21:56:53.000000000 +0900 | |
+++ uip/mhlsbr.c 2016-09-10 22:02:54.000000000 +0900 | |
@@ -1291,7 +1291,7 @@ | |
#ifdef MIME_HEADERS | |
if (c1 -> c_flags & DECODE) { | |
char *ep; | |
- if ((ep = malloc((unsigned)strlen(c2 -> c_text)+1)) == NULL) | |
+ if ((ep = malloc((unsigned)strlen(c2 -> c_text)*10+1)) == NULL) | |
adios(NULLCP, "out of memory"); | |
(void) exthdr_decode(c2 -> c_text, ep); | |
free(c2 -> c_text); | |
diff -u uip/replsbr.c.orig uip/replsbr.c | |
--- uip/replsbr.c.orig 2016-09-10 21:56:53.000000000 +0900 | |
+++ uip/replsbr.c 2016-09-10 22:03:55.000000000 +0900 | |
@@ -418,7 +418,7 @@ | |
#ifdef MIME_HEADERS | |
char *cp, *ep; | |
cp = adrformat (np); | |
- if ((ep = malloc((unsigned)strlen(cp)+1)) == NULL) | |
+ if ((ep = malloc((unsigned)strlen(cp)*10+1)) == NULL) | |
adios (NULLCP, "out of memory"); | |
(void) exthdr_decode(cp, ep); | |
(void) sprintf (buffer, "Reply to %s? ", ep); | |
diff -u uip/slocal.c.orig uip/slocal.c | |
--- uip/slocal.c.orig 2016-09-10 21:56:53.000000000 +0900 | |
+++ uip/slocal.c 2016-09-10 22:05:53.000000000 +0900 | |
@@ -846,7 +846,11 @@ | |
char *tmpbuf; | |
if (! p -> p_value) | |
continue; | |
- tmpbuf = getcpy(p -> p_value); | |
+ tmpbuf = p->p_value; | |
+ if ((p->p_value = malloc(strlen(tmpbuf)*10+1)) == NULL) { | |
+ p->p_value = tmpbuf; | |
+ continue; | |
+ } | |
exthdr_decode(tmpbuf, p -> p_value); | |
free(tmpbuf); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment