Skip to content

Commit f3ceae8

Browse files
committed
spamify_replacedomain was replacing everything after a "@" character
This fix makes it replace only the domain after the "@" char and only in an email address.
1 parent 270623e commit f3ceae8

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

src/hypermail.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ typedef enum {
190190
FORMAT_FIXED = 0,
191191
FORMAT_FLOWED = 1
192192
} textplain_format_t;
193+
194+
/* conversions supported by string.c:parseemail() */
195+
typedef enum {
196+
MAKEMAILCOMMAND = 1, /* makes links clickable */
197+
REPLACE_DOMAIN = 2, /* replaces domain by antispamdomain */
198+
} parseemail_conversion_t;
199+
193200
/*
194201
* Path separator for attachment file path generation
195202
*/

src/print.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,8 @@ char *ConvURLsString(char *line, char *mailid, char *mailsubject, char *charset)
11051105
if (parsed && *parsed) {
11061106
newparse = parseemail(parsed, /* source */
11071107
mailid, /* mail's Message-Id: */
1108-
mailsubject); /* mail's Subject: */
1108+
mailsubject, /* mail's Subject: */
1109+
MAKEMAILCOMMAND); /* make a mailto: */
11091110
free(parsed);
11101111
parsed = newparse;
11111112
}

src/proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ char *spamify(char *input);
128128
char *spamify_small(char *input);
129129
char *spamify_replacedomain(char *input, char *antispamdomain);
130130
char *unspamify(char *);
131-
char *parseemail(char *, char *, char *);
131+
char *parseemail(char *, char *, char *, parseemail_conversion_t);
132132
char *parseurl(char *, char *);
133133

134134
char *hm_strchr(const char *, int);

src/string.c

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <string.h>
3838
#endif
3939

40-
4140
/*
4241
** email address obfuscation
4342
*/
@@ -1482,32 +1481,11 @@ char *spamify_replacedomain(char *input, char *antispamdomain)
14821481
char *atptr = strchr(input, '@');
14831482

14841483
if (atptr) {
1485-
/* replace everything after the @-letter in the email address */
1486-
int domainlen = strlen(antispamdomain);
1487-
struct Push buff;
1488-
int in_ascii = TRUE, esclen = 0;
1489-
char *cursor;
1490-
1491-
INIT_PUSH(buff);
1484+
char *buff;
14921485

1493-
for (cursor = input; *cursor; cursor++) {
1494-
if (set_iso2022jp) {
1495-
iso2022_state(cursor, &in_ascii, &esclen);
1496-
}
1497-
if (in_ascii == TRUE && *cursor == '@') {
1498-
PushString(&buff, set_antispam_at);
1499-
if (domainlen > 0) {
1500-
/* append the new domain */
1501-
PushString(&buff, antispamdomain);
1502-
break;
1503-
}
1504-
}
1505-
else {
1506-
PushByte(&buff, *cursor);
1507-
}
1508-
}
1509-
free(input);
1510-
RETURN_PUSH(buff);
1486+
buff = parseemail(input, NULL, antispamdomain, REPLACE_DOMAIN);
1487+
free(input);
1488+
return(buff);
15111489
}
15121490

15131491
/* weird email, bail out */
@@ -1548,7 +1526,8 @@ char *unspamify(char *s)
15481526

15491527
char *parseemail(char *input, /* string to parse */
15501528
char *mid, /* message ID */
1551-
char *msubject)
1529+
char *msubject,
1530+
parseemail_conversion_t conversion) /* how to output parsed mail */
15521531
{ /* message subject */
15531532
char mailbuff[256];
15541533
char mailaddr[MAILSTRLEN];
@@ -1647,15 +1626,26 @@ char *parseemail(char *input, /* string to parse */
16471626
ptr-email, email, at, mailbuff);
16481627

16491628
if (valid_root_domain(mailaddr)) {
1650-
char *mailcmd = makemailcommand(set_mailcommand,
1651-
mailaddr, mid,
1652-
msubject);
1653-
trio_snprintf(tempbuff, sizeof(tempbuff),
1654-
"<a href=\"%s\">%s</a>", mailcmd,
1655-
obfuscate_email_address(mailaddr));
1656-
1657-
free(mailcmd);
16581629

1630+
if (conversion == MAKEMAILCOMMAND) {
1631+
char *mailcmd = makemailcommand(set_mailcommand,
1632+
mailaddr, mid,
1633+
msubject);
1634+
trio_snprintf(tempbuff, sizeof(tempbuff),
1635+
"<a href=\"%s\">%s</a>", mailcmd,
1636+
obfuscate_email_address(mailaddr));
1637+
1638+
free(mailcmd);
1639+
}
1640+
else if (conversion == REPLACE_DOMAIN) {
1641+
trio_snprintf(tempbuff, sizeof(mailaddr),"%.*s%s%s",
1642+
ptr-email, email, at, msubject);
1643+
1644+
}
1645+
else {
1646+
strcpy (tempbuff, mailaddr);
1647+
}
1648+
16591649
PushString(&buff, tempbuff);
16601650

16611651
input = ptr + strlen(mailbuff) + at_len;

0 commit comments

Comments
 (0)