1 /* a simple program to detect if an email arriving on standard input is SPAM */
8 /* a single occurance of any of these strings gets it banned */
9 static char *spam_strings[] = {
12 "removed from this advertiser",
13 "Adult Entertainment",
20 "build your business",
23 "fraction of the price",
41 "Adult Entertainment",
54 /* SPAM_WORDS_LIMIT occurances of any of these strings gets it banned */
55 #define SPAM_WORDS_LIMIT 2
56 static char *spam_words[] = {
84 static int match_spam_strings(char *buf, int size)
88 for (i=0;spam_strings[i];i++) {
89 if (memmem(buf, size, spam_strings[i], strlen(spam_strings[i])))
97 static int match_spam_words(char *buf, int size)
102 for (i=0;spam_words[i];i++) {
103 if (memmem(buf, size, spam_words[i], strlen(spam_words[i]))) {
108 if (count >= SPAM_WORDS_LIMIT)
115 /* messages longer than this get truncated */
116 #define MAXBUF 0xFFFF
118 int main(int argc, char *argv[])
124 fprintf(stderr,"spamstopper <spamfile>\n");
128 buf = (char *)malloc(MAXBUF);
133 int n = read(0, buf+size, MAXBUF-(size+1));
138 if (size <= 0) return 0;
142 if (match_spam_strings(buf, size) ||
143 match_spam_words(buf, size)) {
144 char *spamfile = argv[1];
147 fd = open(spamfile,O_CREAT|O_WRONLY|O_APPEND, 0666);
152 write(fd, buf, size);
157 /* its OK, pass it on */