Skip to content

Commit 275a205

Browse files
committed
grouping all spamify/unspamify functions under string.c
1 parent 406ee9e commit 275a205

File tree

3 files changed

+66
-71
lines changed

3 files changed

+66
-71
lines changed

src/getname.c

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,77 +14,6 @@ static int blankstring(char *str)
1414
return (1);
1515
}
1616

17-
char *spamify(char *input)
18-
{
19-
if (set_antispamdomain) {
20-
return spamify_replacedomain(input, set_antispamdomain);
21-
}
22-
else {
23-
return spamify_small(input);
24-
}
25-
}
26-
27-
char *spamify_small(char *input)
28-
{
29-
int insertlen = strlen(set_antispam_at);
30-
/* we should replace the @-letter in the email address */
31-
int newlen = strlen(input) + insertlen;
32-
33-
char *atptr = strchr(input, '@');
34-
35-
if (atptr) {
36-
char *newbuf = malloc(newlen);
37-
int index = atptr - input;
38-
/* copy the part before the @ */
39-
memcpy(newbuf, input, index);
40-
memcpy(newbuf + index, set_antispam_at, insertlen);
41-
42-
/* append the part after the @ */
43-
strcpy(newbuf + index + insertlen, input + index + 1);
44-
45-
/* correct the pointer and free the old */
46-
free(input);
47-
return newbuf;
48-
}
49-
/* weird email, bail out */
50-
return input;
51-
}
52-
53-
char *spamify_replacedomain(char *input, char *antispamdomain)
54-
{
55-
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;
62-
63-
INIT_PUSH(buff);
64-
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);
82-
}
83-
84-
/* weird email, bail out */
85-
return input;
86-
}
87-
8817
/*
8918
** Grabs the name and email address from a From: header.
9019
** This could get tricky; I've tried to keep it simple.

src/proto.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ char *convcharsnospamprotect(char *, char *);
124124
char *unconvchars(char *);
125125
char *makemailcommand(char *, char *, char *, char *);
126126
char *makeinreplytocommand(char *, char *, char *);
127+
char *spamify(char *input);
128+
char *spamify_small(char *input);
129+
char *spamify_replacedomain(char *input, char *antispamdomain);
127130
char *unspamify(char *);
128131
char *parseemail(char *, char *, char *);
129132
char *parseurl(char *, char *);

src/string.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,69 @@ char *makeinreplytocommand(char *inreplytocommand, char *subject, char *id)
14501450
return newcmd;
14511451
}
14521452

1453+
char *spamify(char *input)
1454+
{
1455+
if (set_antispamdomain) {
1456+
return spamify_replacedomain(input, set_antispamdomain);
1457+
}
1458+
else {
1459+
return spamify_small(input);
1460+
}
1461+
}
1462+
1463+
char *spamify_small(char *input)
1464+
{
1465+
/* we should replace the @-letter in the email address */
1466+
1467+
char *atptr = strchr(input, '@');
1468+
1469+
if (atptr) {
1470+
char *newbuf = replacechar(input, '@', set_antispam_at);
1471+
1472+
/* correct the pointer and free the old */
1473+
free(input);
1474+
return newbuf;
1475+
}
1476+
/* weird email, bail out */
1477+
return input;
1478+
}
1479+
1480+
char *spamify_replacedomain(char *input, char *antispamdomain)
1481+
{
1482+
char *atptr = strchr(input, '@');
1483+
1484+
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+
1490+
INIT_PUSH(buff);
1491+
1492+
for (; *input; input++) {
1493+
if (set_iso2022jp) {
1494+
iso2022_state(input, &in_ascii, &esclen);
1495+
}
1496+
if (in_ascii == TRUE && *input == '@') {
1497+
PushString(&buff, set_antispam_at);
1498+
if (domainlen > 0) {
1499+
/* append the new domain */
1500+
PushString(&buff, antispamdomain);
1501+
break;
1502+
}
1503+
}
1504+
else {
1505+
PushByte(&buff, *input);
1506+
}
1507+
}
1508+
free(input);
1509+
RETURN_PUSH(buff);
1510+
}
1511+
1512+
/* weird email, bail out */
1513+
return input;
1514+
}
1515+
14531516
char *unspamify(char *s)
14541517
{
14551518
char *p;

0 commit comments

Comments
 (0)