17 |
|
#define NEGATIVE "Spam/False Negative" |
18 |
|
#define POSITIVE "Spam/False Positive" |
19 |
|
|
20 |
– |
/*#define SED "/usr/bin/sed" |
21 |
– |
#define ASSASSIN "/usr/local/bin/spamassassin"*/ |
20 |
|
#define SPAMC "/usr/local/bin/spamc" |
21 |
|
#define SPAMD "/var/run/spamd/spamd.sock" |
22 |
|
|
25 |
– |
/*#define INDENT "s/^/ /" |
26 |
– |
#define PERIOD "s/[^.]$/&./"*/ |
27 |
– |
|
23 |
|
#define TEMP "/tmp/SpamUpdate.XXXXXX" |
24 |
|
|
25 |
|
static jmp_buf environment; |
39 |
|
return value; |
40 |
|
} |
41 |
|
|
47 |
– |
/*static char *fcheck(char *value, FILE *stream, jmp_buf environment) |
48 |
– |
{ |
49 |
– |
if (!value) |
50 |
– |
{ |
51 |
– |
if (ferror(stream)) |
52 |
– |
longjmp(environment, 1); |
53 |
– |
else |
54 |
– |
{ |
55 |
– |
clearerr(stream); |
56 |
– |
|
57 |
– |
if (stream == stdin) |
58 |
– |
printf("\n"); |
59 |
– |
|
60 |
– |
return ""; |
61 |
– |
} |
62 |
– |
} |
63 |
– |
|
64 |
– |
return value; |
65 |
– |
}*/ |
66 |
– |
|
42 |
|
static void *mcheck(void *value, jmp_buf environment) |
43 |
|
{ |
44 |
|
if (value == NIL) |
68 |
|
for (size_t index = 0; index != count; ++index) |
69 |
|
{ |
70 |
|
unsigned long size; |
71 |
< |
char *header = mcheck(mail_fetchheader_full(streams[job - jobs], messages_[index], NIL, &size, FT_UID), environment); |
71 |
> |
char *message = mcheck(mail_fetch_message(streams[job - jobs], messages_[index], &size, FT_UID), environment); |
72 |
|
char file[sizeof (TEMP) / sizeof (char)] = TEMP; |
73 |
|
int file_ = check(mkstemp(file), environment); |
74 |
|
|
75 |
< |
check(write(file_, header, size), environment); |
101 |
< |
|
102 |
< |
char *text = mcheck(mail_fetchtext_full(streams[job - jobs], messages_[index], &size, FT_UID), environment); |
103 |
< |
|
104 |
< |
check(write(file_, text, size), environment); |
75 |
> |
check(write(file_, message, size * sizeof (char)), environment); |
76 |
|
check(lseek(file_, 0, SEEK_SET), environment); |
77 |
|
|
78 |
|
pid_t learn; |
108 |
|
} |
109 |
|
} |
110 |
|
|
140 |
– |
// XXX: this is going to be moved to a deliver daemon that will run more often |
141 |
– |
/*static void deliver() |
142 |
– |
{ |
143 |
– |
printf("\nDelivering messages from the " POSITIVE " mailbox:\n"); |
144 |
– |
|
145 |
– |
const unsigned long *messages_ = messages[1]; |
146 |
– |
const size_t count = counts[1]; |
147 |
– |
|
148 |
– |
streams[0] = mcheck(mail_open(streams[0], "INBOX", (debug ? OP_DEBUG : 0) | OP_SHORTCACHE), environment); |
149 |
– |
|
150 |
– |
for (int index = 0; index != count; ++index) |
151 |
– |
{ |
152 |
– |
int out[2], in[2]; |
153 |
– |
|
154 |
– |
check(pipe(out), environment); |
155 |
– |
check(pipe(in), environment); |
156 |
– |
|
157 |
– |
pid_t assassin; |
158 |
– |
|
159 |
– |
if (!(assassin = check(fork(), environment))) |
160 |
– |
{ |
161 |
– |
check(dup2(out[0], 0), environment); |
162 |
– |
check(close(out[1]), environment); |
163 |
– |
check(dup2(in[1], 1), environment); |
164 |
– |
check(close(in[0]), environment); |
165 |
– |
check(execl(ASSASSIN, "spamassassin", "-d", NULL), environment); |
166 |
– |
} |
167 |
– |
|
168 |
– |
check(close(out[0]), environment); |
169 |
– |
check(close(in[1]), environment); |
170 |
– |
|
171 |
– |
unsigned long size; |
172 |
– |
char *header = mcheck(mail_fetchheader_full(streams[1], messages_[index], NIL, &size, FT_UID), environment); |
173 |
– |
|
174 |
– |
check(write(out[1], header, size), environment); |
175 |
– |
|
176 |
– |
char *text = mcheck(mail_fetchtext_full(streams[1], messages_[index], &size, FT_UID), environment); |
177 |
– |
|
178 |
– |
check(write(out[1], text, size), environment); |
179 |
– |
check(close(out[1]), environment); |
180 |
– |
|
181 |
– |
FILE *assassin_ = fdopen(in[0], "r"); |
182 |
– |
size_t size_; |
183 |
– |
bool header_ = true; |
184 |
– |
char *message = NULL; |
185 |
– |
|
186 |
– |
size = 0; |
187 |
– |
|
188 |
– |
do |
189 |
– |
{ |
190 |
– |
char *line = fcheck(fgetln(assassin_, &size_), assassin_, environment); |
191 |
– |
|
192 |
– |
message = message ? realloc(message, (size + size_) * sizeof (char)) : malloc((size + size_) * sizeof (char)); |
193 |
– |
|
194 |
– |
memcpy(message + size, line, size_); |
195 |
– |
|
196 |
– |
size += size_; |
197 |
– |
|
198 |
– |
if (header_) |
199 |
– |
{ |
200 |
– |
if (size_ == 1) |
201 |
– |
{ |
202 |
– |
assert(*line == '\n'); |
203 |
– |
|
204 |
– |
header_ = false; |
205 |
– |
|
206 |
– |
goto crlf; |
207 |
– |
} |
208 |
– |
else if (size_ == 2 && !memcmp(line, "\r\n", 2)) |
209 |
– |
header_ = false; |
210 |
– |
else if (!(size_ > 2 && !memcmp(line + size_ - 2, "\r\n", 2))) |
211 |
– |
{ |
212 |
– |
crlf: assert(message); |
213 |
– |
|
214 |
– |
message = realloc(message, ++size * sizeof (char)); |
215 |
– |
|
216 |
– |
memcpy(message + size - 2, "\r\n", 2); |
217 |
– |
} |
218 |
– |
} |
219 |
– |
} |
220 |
– |
while (size_ != 0); |
221 |
– |
|
222 |
– |
if (fclose(assassin_)) |
223 |
– |
longjmp(environment, 1); |
224 |
– |
|
225 |
– |
int status; |
226 |
– |
|
227 |
– |
check(waitpid(assassin, &status, 0), environment); |
228 |
– |
|
229 |
– |
STRING message_; |
230 |
– |
|
231 |
– |
INIT(&message_, mail_string, message, size); |
232 |
– |
mcheck((void *)mail_append_full(streams[0], "INBOX", "\\Seen", NIL, &message_), environment); |
233 |
– |
free(message); |
234 |
– |
} |
235 |
– |
|
236 |
– |
streams[0] = mcheck(mail_open(streams[0], NEGATIVE, debug ? OP_DEBUG : 0), environment); |
237 |
– |
|
238 |
– |
printf(" %u message(s) delivered.\n", count); |
239 |
– |
}*/ |
240 |
– |
|
111 |
|
void delete() |
112 |
|
{ |
113 |
|
char *mailboxes[] = { NEGATIVE, POSITIVE }; |
180 |
|
streams[1] = mcheck(mail_open(NIL, POSITIVE, debug ? OP_DEBUG : 0), environment); |
181 |
|
|
182 |
|
learn(); |
313 |
– |
//deliver(); |
183 |
|
delete(); |
184 |
|
mail_close(streams[0]); |
185 |
|
mail_close(streams[1]); |
211 |
|
void mm_expunged(MAILSTREAM *stream, unsigned long number) {} |
212 |
|
void mm_list(MAILSTREAM *stream, int delim, char *name, long attrib) {} |
213 |
|
void mm_lsub(MAILSTREAM *stream, int delim, char *name, long attrib) {} |
214 |
+ |
|
215 |
|
void mm_notify(MAILSTREAM *stream, char *string, long errflg) {} |
216 |
|
|
217 |
|
void mm_log(char *string, long errflg) |
218 |
|
{ |
219 |
+ |
if (debug) |
220 |
+ |
fprintf(stderr, "%li: %s\n", errflg, string); |
221 |
+ |
|
222 |
|
if (errflg == ERROR) |
223 |
|
asprintf(&error, "%s", string); |
224 |
|
} |