Skip to content

Commit 406ee9e

Browse files
committed
spamify_replacedomain: another fix for greedy "@" replacement in the
middle of a string of iso-2022-jp encoded Japanese characters.
1 parent d2b57d5 commit 406ee9e

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

Changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Version Changes for Hypermail
44
HYPERMAIL VERSION 2.4.0:
55
============================
66

7+
2018-11-29 Bill Shannon
8+
* string.c
9+
spamify_replacedomain: another fix for greedy "@" replacement in the
10+
middle of a string of iso-2022-jp encoded Japanese characters.
11+
712
2018-11-04 Bill Shannon
813
* string.c
914
i18n_convstring(): When converting a utf-8 string to iso-2022-jp,

src/getname.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,35 +52,35 @@ char *spamify_small(char *input)
5252

5353
char *spamify_replacedomain(char *input, char *antispamdomain)
5454
{
55-
/* replace everything after the @-letter in the email address */
56-
int newlen = strlen(input) + strlen(set_antispam_at);
57-
int domainlen = strlen(antispamdomain);
58-
5955
char *atptr = strchr(input, '@');
56+
57+
if (atptr) {
58+
/* replace everything after the @-letter in the email address */
59+
int domainlen = strlen(antispamdomain);
60+
struct Push buff;
61+
int in_ascii = TRUE, esclen = 0;
6062

61-
if (domainlen > 0) {
62-
newlen = newlen + domainlen;
63-
}
63+
INIT_PUSH(buff);
6464

65-
if (atptr) {
66-
char *newbuf = malloc(newlen);
67-
int index = atptr - input;
68-
/* copy the part before the @ */
69-
memcpy(newbuf, input, index);
70-
/* append _at_ */
71-
memcpy(newbuf + index, set_antispam_at, strlen(set_antispam_at));
72-
if (domainlen > 0) {
73-
/* append the new domain */
74-
strcpy(newbuf + index + strlen(set_antispam_at), antispamdomain);
75-
}
76-
else {
77-
/* append the part after the @ */
78-
strcpy(newbuf + index + strlen(set_antispam_at), input + index + 1);
79-
}
80-
/* correct the pointer and free the old */
81-
free(input);
82-
return newbuf;
65+
for (; *input; input++) {
66+
if (set_iso2022jp) {
67+
iso2022_state(input, &in_ascii, &esclen);
68+
}
69+
if (in_ascii == TRUE && *input == '@') {
70+
PushString(&buff, set_antispam_at);
71+
if (domainlen > 0) {
72+
/* append the new domain */
73+
PushString(&buff, antispamdomain);
74+
break;
75+
}
76+
}
77+
else {
78+
PushByte(&buff, *input);
79+
}
80+
}
81+
RETURN_PUSH(buff);
8382
}
83+
8484
/* weird email, bail out */
8585
return input;
8686
}
@@ -252,9 +252,9 @@ void getname(char *line, char **namep, char **emailp)
252252
char *c2 = strchr(line, '>');
253253
if (c2 != NULL) {
254254
c = c2 + 1;
255-
for (i = 0, len = NAMESTRLEN - 1; *c && *c != '\n' && i < len; c++)
255+
for (i = 0, len = NAMESTRLEN - 1; *c && *c != '\n' && i < len; c++) {
256256
name[i++] = *c;
257-
257+
}
258258
comment_fnd = 1;
259259
}
260260
}

0 commit comments

Comments
 (0)