1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
Description: SpamAssassin support, build optimization
Add SpamAssassin support.
Drop the unneeded MAX_ENV_BUFF definition.
Forwarded: not-needed
Author: Alex Dupre <ale@FreeBSD.org>,
Peter Pentchev <roam@FreeBSD.org>
Last-Update: 2009-11-26
--- a/vdelivermail.c
+++ b/vdelivermail.c
@@ -74,6 +74,7 @@
int is_spam();
#endif
int DeleteMail = 0;
+int MoveMail = 0;
int local = 1;
#define MSG_BUF_SIZE 5000
@@ -353,7 +354,6 @@
int fdcopy (int write_fd, int read_fd, const char *extra_headers, size_t headerlen, char *address)
{
- char msgbuf[4096];
ssize_t file_count;
struct vlimits limits;
#ifdef SPAMASSASSIN
@@ -393,7 +393,7 @@
close(pim[1]);
if (execl(SPAMC_PROG, SPAMC_PROG, "-f", "-u",
address, 0) == -1) {
- while ((file_count = read(0, msgbuf, MSG_BUF_SIZE)) > 0) {
+ while ((file_count = read(0, msgbuf, sizeof(msgbuf))) > 0) {
write(1, msgbuf, file_count);
}
_exit(0);
@@ -421,18 +421,36 @@
/* read it in chunks and write it to the new file */
while ((file_count = read(read_fd, msgbuf, sizeof(msgbuf))) > 0) {
#ifdef SPAMASSASSIN
- if ( local==1 && InHeaders==1 &&
- (limits.delete_spam==1 || vpw->pw_gid & DELETE_SPAM) ) {
- printf("check is_spam\n");
- if (is_spam(msgbuf) == 1) {
+ if ( local==1 && InHeaders==1
+#if defined(SPAM_THRESHOLD) || defined(SPAM_JUNKFOLDER)
+ ) {
+#else
+ && (limits.delete_spam==1 || vpw->pw_gid & DELETE_SPAM) ) {
+#endif
+ switch (is_spam(msgbuf, file_count)) {
+ case 2:
+#ifdef SPAM_THRESHOLD
DeleteMail = 1;
return(0);
+#endif
+ case 1:
+ if (limits.delete_spam==1 || vpw->pw_gid & DELETE_SPAM) {
+ DeleteMail = 1;
+ return(0);
+ }
+#ifdef SPAM_JUNKFOLDER
+ MoveMail = 1;
+#endif
}
}
#endif
if ( write(write_fd, msgbuf, file_count) == -1 ) return -1;
}
-
+#ifdef SPAMASSASSIN
+ /* No body */
+ if (InHeaders==1) DeleteMail = 1;
+#endif
+
return 0;
}
@@ -495,6 +513,11 @@
size_t headerlen;
int write_fd;
char quota[80];
+#ifdef SPAM_JUNKFOLDER
+ struct stat mystatbuf;
+ char dir[MAX_BUFF];
+ char calling_dir[MAX_BUFF];
+#endif
headerlen = strlen (extra_headers);
msgsize += headerlen;
@@ -557,6 +580,24 @@
}
/* if this succeeds link the file to the new directory */
+#ifdef SPAM_JUNKFOLDER
+ if (MoveMail == 1) {
+ snprintf(dir, sizeof(local_file_new), "%s/.Junk", maildir);
+ if (stat(dir, &mystatbuf) == -1) {
+ /* record the dir where the vdelivermail command was run from */
+ getcwd(calling_dir, sizeof(calling_dir));
+ if (mkdir(dir,VPOPMAIL_DIR_MODE) == -1) { chdir(calling_dir); unlink(local_file_tmp); return(-2); }
+ if (chdir(dir) == -1) { chdir(calling_dir); unlink(local_file_tmp); return(-2); }
+ if (mkdir("cur",VPOPMAIL_DIR_MODE) == -1) { chdir(calling_dir); unlink(local_file_tmp); return(-2); }
+ if (mkdir("new",VPOPMAIL_DIR_MODE) == -1) { chdir(calling_dir); unlink(local_file_tmp); return(-2); }
+ if (mkdir("tmp",VPOPMAIL_DIR_MODE) == -1) { chdir(calling_dir); unlink(local_file_tmp); return(-2); }
+ /* change back to the original dir */
+ chdir(calling_dir);
+ }
+ snprintf(local_file_new, sizeof(local_file_new), "%s/.Junk/new/%lu.%lu.%.32s,S=%lu",
+ maildir, tm, pid, hostname, (long unsigned) msgsize);
+ }
+#endif
if ( link( local_file_tmp, local_file_new ) == 0 ) {
/* file was successfully delivered, remove temp file */
if ( unlink(local_file_tmp) != 0 ) {
@@ -616,6 +657,9 @@
/* rewind the message */
lseek(0,0L,SEEK_SET);
+ /* reinitialize for each dot-qmail line */
+ DeleteMail = 0;
+
/* This is an command */
if ( *address == '|' ) {
@@ -898,9 +942,6 @@
*/
void run_command(char *prog)
{
-
-#define MAX_ENV_BUFF 100
-
int child;
char *(args[4]);
int wstat;
@@ -1214,19 +1255,22 @@
* * in the email headers for X-Spam-Level: which
* * we put in each spam email
* *
- * * Return 1 if spam
+ * * Return 2 if heavy spam
+ * * Return 1 if light spam
* * Return 0 if not spam
* * Return -1 on error
* */
-int is_spam(char *spambuf)
+int is_spam(char *spambuf, int len)
{
int i,j,k;
int found;
+ int spam = 0;
+ int rowlen;
- for(i=0,j=0;spambuf[i]!=0;++i) {
+ for(i=0,j=0;i<len;++i) {
/* found a line */
- if (spambuf[i]=='\n' || spambuf[i]=='\r' ) {
+ if (spambuf[i]=='\n') {
/* check for blank line, end of headers */
for(k=j,found=0;k<i;++k) {
@@ -1249,13 +1293,19 @@
}
if ( found == 0 ) {
InHeaders=0;
- return(0);
+ return(spam);
}
/* still in the headers check for spam header */
- if ( strncmp(&spambuf[j], "X-Spam-Flag: YES", 16 ) == 0 ) return(1);
+ rowlen = i - j;
+ if ( spam == 0 && rowlen == 16 && strncmp(&spambuf[j], "X-Spam-Flag: YES", 16 ) == 0 )
+ spam = 1;
+#ifdef SPAM_THRESHOLD
+ else if ( rowlen > 14 + SPAM_THRESHOLD && strncmp(&spambuf[j], "X-Spam-Level: ", 14 ) == 0 )
+ return(2);
+#endif
- if (spambuf[i+1]!=0) j=i+1;
+ j=i+1;
}
}
return(0);
|