Skip to content

Commit d2b57d5

Browse files
committed
Bill ShannonL: ISO-2022-JP support was incomplete and incorrect
Fixes #36
1 parent 9d995dd commit d2b57d5

File tree

2 files changed

+55
-21
lines changed

2 files changed

+55
-21
lines changed

Changelog

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ HYPERMAIL VERSION 2.4.0:
66

77
2018-11-04 Bill Shannon
88
* string.c
9-
i18n_convstring(): fix usage problems with iconv
9+
i18n_convstring(): When converting a utf-8 string to iso-2022-jp,
10+
hypermail always adds the "return to ASCII" escape sequence, even if
11+
the string ends with ASCII.
12+
13+
parseemail(): hypermail attempts to transform anything that looks like
14+
an email address by replacing the at sign (and optionally the domain
15+
name) with a string (default "at") to confuse screen-scraping
16+
programs. But if there's an "@" character in the middle of a string of
17+
iso-2022-jp encoded Japanese characters, hypermail still converts it,
18+
breaking the Japanese character.
1019

1120
2018-10-12 Jose Kahan
12-
* setup.c
13-
PreConfig(): removed a 64-bit warning
21+
* setup.c PreConfig(): removed a 64-bit warning
1422

1523
* hypermail.c
1624
main(): if the en_US locale is not available, try en_US.UTF-8

src/string.c

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ char *i18n_convstring(char *string, char *fromcharset, char *tocharset, size_t *
324324
origconvbuf[origlen]=0x0;
325325
*len=origlen;
326326
} else {
327+
#if 0
327328
/* hmm... do we really need to do this? (daigo) */
328329
if (strncasecmp(tocharset,"ISO-2022-JP",11)==0){
329330
*len=origlen*7-bufleft;
@@ -334,7 +335,9 @@ char *i18n_convstring(char *string, char *fromcharset, char *tocharset, size_t *
334335
}else{
335336
*len=origlen*7-bufleft;
336337
}
337-
338+
#else
339+
*len=origlen*7-bufleft;
340+
#endif
338341
*(origconvbuf+*len)=0x0;
339342
}
340343

@@ -1488,6 +1491,7 @@ char *parseemail(char *input, /* string to parse */
14881491
char tempbuff[MAXLINE];
14891492
char *ptr;
14901493
char *lastpos = input;
1494+
char *start = NULL;
14911495
struct Push buff;
14921496

14931497
char *at;
@@ -1500,32 +1504,51 @@ char *parseemail(char *input, /* string to parse */
15001504
else
15011505
at="@";
15021506

1507+
if (strchr(input, '@') == NULL && strstr(input, "@") == NULL) {
1508+
/* nothing to do here */
1509+
return strsav(input);
1510+
}
1511+
15031512
INIT_PUSH(buff);
15041513

15051514
while (*input) {
1506-
if ((ptr = strchr (input, '@')))
1507-
at_len = 1;
1508-
else if ((ptr = strstr (input, "@")))
1509-
at_len = 5;
1515+
1516+
/* skip detection if this is an escape or non-ascii sequence */
1517+
if (set_iso2022jp) {
1518+
iso2022_state(input, &in_ascii, &esclen);
1519+
if (esclen != 0) {
1520+
input += esclen;
1521+
continue;
1522+
}
1523+
if (in_ascii == FALSE) {
1524+
input++;
1525+
start = NULL;
1526+
continue;
1527+
}
1528+
}
1529+
1530+
if (start == NULL) {
1531+
start = input;
1532+
}
1533+
1534+
ptr = NULL;
1535+
if (*input == '@') {
1536+
ptr = input;
1537+
at_len = 1;
1538+
} else if (strncmp(input, "@", 5) == 0) {
1539+
ptr = input;
1540+
at_len = 5;
1541+
}
1542+
15101543
if (ptr) {
15111544
/* found a @ */
15121545
char *email = ptr - 1;
15131546
char content[2];
1514-
int backoff = ptr - input; /* max */
1547+
int backoff = ptr - start; /* max */
15151548

15161549
#define VALID_IN_EMAIL_USERNAME "a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~"
15171550
#define VALID_IN_EMAIL_DOMAINNAME "a-zA-Z0-9.-"
15181551

1519-
if (set_iso2022jp) {
1520-
for (; ptr > input; input++) {
1521-
iso2022_state(input, &in_ascii, &esclen);
1522-
if (!esclen) continue;
1523-
input += esclen;
1524-
if (in_ascii == TRUE)
1525-
backoff = ptr - input;
1526-
}
1527-
}
1528-
15291552
/* check left side */
15301553
while (backoff) {
15311554
int res;
@@ -1572,23 +1595,26 @@ char *parseemail(char *input, /* string to parse */
15721595
PushString(&buff, tempbuff);
15731596

15741597
input = ptr + strlen(mailbuff) + at_len;
1598+
start = input;
15751599
lastpos = input;
15761600
continue;
15771601
}
15781602
else { /* bad address */
15791603
PushString(&buff, mailaddr);
15801604
input = ptr + strlen(mailbuff) + at_len;
1605+
start = input;
15811606
lastpos = input;
15821607
continue;
15831608
}
15841609
}
15851610
}
15861611
/* no address, continue from here */
1587-
input = ptr + 1;
1612+
input = ptr + at_len;
1613+
start = input;
15881614
continue;
15891615
}
15901616
else
1591-
input = strchr(input, '\0');
1617+
input++;
15921618
}
15931619
if (lastpos < input) {
15941620
PushNString(&buff, lastpos, input - lastpos);

0 commit comments

Comments
 (0)