1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-24 09:25:01 +00:00

- Fix foreign charset decoding in headers

- Fix handing of Big5 characters

PR:		ports/103082
Submitted by:	wchunhao@csie.nctu.edu.tw
This commit is contained in:
Johan van Selst 2006-09-21 13:52:51 +00:00
parent 8edc50012b
commit f0369b73a2
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=173538
2 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,84 @@
--- lib/hdrdecode.c Sat Jul 9 18:03:15 2005
+++ lib/hdrdecode.c Sun Sep 10 04:57:10 2006
@@ -173,9 +173,16 @@
char *encoded = NULL;
struct string *ret = NULL;
charset_t set;
+ char *front, *end;
+ struct string *fstr, *estr;
- if ('=' != *p++)
+ /* Pasear: front, end are used to solve buffer: abc""=?...?=" problem */
+ front = p;
+ while (*p && '=' != *p) ++p;
+ if (front != p && '=' == *p && '"' == *(p-1)) *(p-1) = '\0';
+ if ('=' != *p)
goto fail;
+ *p = '\0'; ++p;
if ('?' != *p++)
goto fail;
sn = p;
@@ -209,8 +216,8 @@
p++;
if ('=' != *p++)
goto fail;
- if (*p)
- goto fail;
+ if ('"' == *p) ++p;
+ end = p;
set = MIME_name_to_charset(sn,CHARSET_create);
@@ -225,6 +232,18 @@
break;
}
+ /* Pasear */
+ if (ret){
+ estr = ret;
+ fstr = new_string2(system_charset,us_str(front));
+ fstr = ret = cat_strings(fstr, ret, 0);
+ free_string(&estr);
+ estr = new_string2(system_charset,us_str(end));
+ ret = cat_strings(ret, estr, 0);
+ free_string(&estr);
+ free_string(&fstr);
+ }
+
fail:
if (!ret) {
DPRINT(Debug,20,(&Debug,
@@ -341,20 +360,31 @@
struct string * ret = new_string(defcharset);
char **tokenized = rfc822_tokenize(buffer);
unsigned char * last_char = NULL;
- int i;
+ int i, encoded;
+ char* p;
for (i = 0; tokenized[i]; i++) {
struct string * ok = NULL;
int nostore = 0;
+ /* Pasear: detect if it is a encoded string */
+ encoded = 0;
+ if ('"' == tokenized[i][0]){
+ p = tokenized[i];
+ while (*p && *p != '=') ++p;
+ if (*p && *p == '=' && *(p+1) && *(p+1) == '?' )
+ encoded = 1;
+ }
+
+
if ('(' == tokenized[i][0]) {
/* we need add last space */
if (last_char)
add_ascii_to_string(ret,last_char);
ok = hdr_comment(tokenized[i],defcharset,demime);
nostore = 1;
- } else if ('"' == tokenized[i][0]) {
+ } else if (!encoded && '"' == tokenized[i][0]) {
/* we need add last space */
if (last_char)
add_ascii_to_string(ret,last_char);

View File

@ -0,0 +1,12 @@
--- lib/precompiled_sets.c Sat Jul 9 18:03:15 2005
+++ lib/precompiled_sets.c Sun Sep 10 03:29:48 2006
@@ -404,7 +404,8 @@
{ CS_charset_magic, &cs_euc, &map_EUC_ascii, SET_valid, "GB2312", NULL,
&set_EUCCN, 2025, "GB2312-1980" }, /* ASCII + GB 2312-80 */
- { CS_charset_magic, &cs_unknown, NULL, SET_valid, "Big5", NULL, NULL, 2026, NULL },
+ { CS_charset_magic, &cs_ascii, &map_latin1, SET_valid, "Big5", ASCII,
+ &(sets_iso_8859_X[1]), 2026, "Big5" },
{ CS_charset_magic, &cs_ascii, NULL, SET_valid, "windows-1250", ASCII, NULL, 2250, NULL },
{ CS_charset_magic, &cs_ascii, NULL, SET_valid, "windows-1253", ASCII, NULL, 2253, NULL },
{ CS_charset_magic, &cs_ascii, NULL, SET_valid, "windows-1254", ASCII ,NULL, 2254, NULL },