Copyright year updates (things touched in 2015)
[exim.git] / src / src / spam.c
CommitLineData
8523533c
TK
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
3386088d 5/* Copyright (c) Tom Kistner <tom@duncanthrax.net> 2003 - 2015 */
8523533c
TK
6/* License: GPL */
7
8/* Code for calling spamassassin's spamd. Called from acl.c. */
9
10#include "exim.h"
11#ifdef WITH_CONTENT_SCAN
12#include "spam.h"
13
14uschar spam_score_buffer[16];
15uschar spam_score_int_buffer[16];
16uschar spam_bar_buffer[128];
c5f280e2 17uschar spam_action_buffer[32];
8523533c
TK
18uschar spam_report_buffer[32600];
19uschar prev_user_name[128] = "";
20int spam_ok = 0;
21int spam_rc = 0;
f7274286 22uschar *prev_spamd_address_work = NULL;
8523533c 23
fd4d8871 24static const uschar * loglabel = US"spam acl condition:";
8523533c 25
23763898 26
fd4d8871
R
27static int
28spamd_param_init(spamd_address_container *spamd)
29{
dc7b3d36 30/* default spamd server weight, time and priority value */
fd4d8871 31spamd->is_failed = FALSE;
8a512ed5
JH
32spamd->weight = SPAMD_WEIGHT;
33spamd->timeout = SPAMD_TIMEOUT;
34spamd->retry = 0;
dc7b3d36 35spamd->priority = 1;
fd4d8871
R
36return 0;
37}
8523533c 38
8523533c 39
fd4d8871 40static int
fc362fc5 41spamd_param(const uschar * param, spamd_address_container * spamd)
fd4d8871
R
42{
43static int timesinceday = -1;
23763898 44const uschar * s;
8a512ed5 45const uschar * name;
fd4d8871 46
fd4d8871
R
47/*XXX more clever parsing could discard embedded spaces? */
48
fc362fc5 49if (sscanf(CCS param, "pri=%u", &spamd->priority))
dc7b3d36
JH
50 return 0; /* OK */
51
fc362fc5 52if (sscanf(CCS param, "weight=%u", &spamd->weight))
fd4d8871
R
53 {
54 if (spamd->weight == 0) /* this server disabled: skip it */
55 return 1;
56 return 0; /* OK */
57 }
58
23763898 59if (Ustrncmp(param, "time=", 5) == 0)
fd4d8871
R
60 {
61 unsigned int start_h = 0, start_m = 0, start_s = 0;
62 unsigned int end_h = 24, end_m = 0, end_s = 0;
63 unsigned int time_start, time_end;
23763898 64 const uschar * end_string;
fd4d8871 65
8a512ed5 66 name = US"time";
23763898
JH
67 s = param+5;
68 if ((end_string = Ustrchr(s, '-')))
ddcf2b5f 69 {
23763898
JH
70 end_string++;
71 if ( sscanf(CS end_string, "%u.%u.%u", &end_h, &end_m, &end_s) == 0
72 || sscanf(CS s, "%u.%u.%u", &start_h, &start_m, &start_s) == 0
73 )
8a512ed5 74 goto badval;
f7274286 75 }
f7274286 76 else
8a512ed5 77 goto badval;
8523533c 78
fd4d8871 79 if (timesinceday < 0)
ddcf2b5f 80 {
fd4d8871
R
81 time_t now = time(NULL);
82 struct tm *tmp = localtime(&now);
83 timesinceday = tmp->tm_hour*3600 + tmp->tm_min*60 + tmp->tm_sec;
84 }
8e669ac1 85
fd4d8871
R
86 time_start = start_h*3600 + start_m*60 + start_s;
87 time_end = end_h*3600 + end_m*60 + end_s;
8e669ac1 88
fd4d8871
R
89 if (timesinceday < time_start || timesinceday >= time_end)
90 return 1; /* skip spamd server */
c5f280e2 91
fd4d8871
R
92 return 0; /* OK */
93 }
8e669ac1 94
fd4d8871
R
95if (Ustrcmp(param, "variant=rspamd") == 0)
96 {
97 spamd->is_rspamd = TRUE;
98 return 0;
99 }
8e669ac1 100
23763898
JH
101if (Ustrncmp(param, "tmo=", 4) == 0)
102 {
103 int sec = readconf_readtime((s = param+4), '\0', FALSE);
8a512ed5 104 name = US"timeout";
23763898 105 if (sec < 0)
8a512ed5
JH
106 goto badval;
107 spamd->timeout = sec;
108 return 0;
109 }
110
111if (Ustrncmp(param, "retry=", 6) == 0)
112 {
113 int sec = readconf_readtime((s = param+6), '\0', FALSE);
114 name = US"retry";
115 if (sec < 0)
116 goto badval;
117 spamd->retry = sec;
23763898
JH
118 return 0;
119 }
120
fd4d8871
R
121log_write(0, LOG_MAIN, "%s warning - invalid spamd parameter: '%s'",
122 loglabel, param);
123return -1; /* syntax error */
8a512ed5
JH
124
125badval:
126 log_write(0, LOG_MAIN,
127 "%s warning - invalid spamd %s value: '%s'", loglabel, name, s);
128 return -1; /* syntax error */
fd4d8871 129}
8523533c 130
8523533c 131
fd4d8871 132static int
dc7b3d36 133spamd_get_server(spamd_address_container ** spamds, int num_servers)
fd4d8871
R
134{
135unsigned int i;
dc7b3d36
JH
136spamd_address_container * sd;
137long rnd, weights;
138unsigned pri;
139static BOOL srandomed = FALSE;
fd4d8871 140
dc7b3d36
JH
141/* seedup, if we have only 1 server */
142if (num_servers == 1)
143 return (spamds[0]->is_failed ? -1 : 0);
8e669ac1 144
dc7b3d36
JH
145/* init ranmod */
146if (!srandomed)
147 {
148 struct timeval tv;
149 gettimeofday(&tv, NULL);
150 srandom((unsigned int)(tv.tv_usec/1000));
151 srandomed = TRUE;
152 }
8e669ac1 153
dc7b3d36
JH
154/* scan for highest pri */
155for (pri = 0, i = 0; i < num_servers; i++)
156 {
157 sd = spamds[i];
158 if (!sd->is_failed && sd->priority > pri) pri = sd->priority;
fd4d8871 159 }
8e669ac1 160
dc7b3d36
JH
161/* get sum of weights */
162for (weights = 0, i = 0; i < num_servers; i++)
163 {
164 sd = spamds[i];
165 if (!sd->is_failed && sd->priority == pri) weights += sd->weight;
166 }
167if (weights == 0) /* all servers failed */
168 return -1;
8e669ac1 169
dc7b3d36
JH
170for (rnd = random() % weights, i = 0; i < num_servers; i++)
171 {
172 sd = spamds[i];
173 if (!sd->is_failed && sd->priority == pri)
174 if ((rnd -= sd->weight) <= 0)
fd4d8871 175 return i;
dc7b3d36 176 }
29cfeb94 177
fd4d8871
R
178log_write(0, LOG_MAIN|LOG_PANIC,
179 "%s unknown error (memory/cpu corruption?)", loglabel);
180return -1;
181}
29cfeb94 182
29cfeb94 183
fd4d8871 184int
55414b25 185spam(const uschar **listptr)
fd4d8871
R
186{
187int sep = 0;
55414b25 188const uschar *list = *listptr;
fd4d8871
R
189uschar *user_name;
190uschar user_name_buffer[128];
191unsigned long mbox_size;
192FILE *mbox_file;
193int spamd_sock = -1;
194uschar spamd_buffer[32600];
195int i, j, offset, result;
fd4d8871
R
196uschar spamd_version[8];
197uschar spamd_short_result[8];
198uschar spamd_score_char;
199double spamd_threshold, spamd_score, spamd_reject_score;
200int spamd_report_offset;
201uschar *p,*q;
202int override = 0;
203time_t start;
204size_t read, wrote;
fd4d8871
R
205#ifndef NO_POLL_H
206struct pollfd pollfd;
207#else /* Patch posted by Erik ? for OS X */
208struct timeval select_tv; /* and applied by PH */
209fd_set select_fd;
210#endif
211uschar *spamd_address_work;
8a512ed5 212spamd_address_container * sd;
fd4d8871
R
213
214/* stop compiler warning */
215result = 0;
216
217/* find the username from the option list */
218if ((user_name = string_nextinlist(&list, &sep,
219 user_name_buffer,
220 sizeof(user_name_buffer))) == NULL)
221 {
222 /* no username given, this means no scanning should be done */
223 return FAIL;
224 }
225
226/* if username is "0" or "false", do not scan */
227if ( (Ustrcmp(user_name,"0") == 0) ||
228 (strcmpic(user_name,US"false") == 0) )
229 return FAIL;
230
231/* if there is an additional option, check if it is "true" */
232if (strcmpic(list,US"true") == 0)
233 /* in that case, always return true later */
234 override = 1;
235
236/* expand spamd_address if needed */
237if (*spamd_address == '$')
238 {
239 spamd_address_work = expand_string(spamd_address);
240 if (spamd_address_work == NULL)
241 {
242 log_write(0, LOG_MAIN|LOG_PANIC,
243 "%s spamd_address starts with $, but expansion failed: %s",
244 loglabel, expand_string_message);
245 return DEFER;
29cfeb94 246 }
fd4d8871
R
247 }
248else
249 spamd_address_work = spamd_address;
250
dc7b3d36 251DEBUG(D_acl) debug_printf("spamd: addrlist '%s'\n", spamd_address_work);
fd4d8871
R
252
253/* check if previous spamd_address was expanded and has changed. dump cached results if so */
254if ( spam_ok
255 && prev_spamd_address_work != NULL
256 && Ustrcmp(prev_spamd_address_work, spamd_address_work) != 0
257 )
258 spam_ok = 0;
259
260/* if we scanned for this username last time, just return */
261if (spam_ok && Ustrcmp(prev_user_name, user_name) == 0)
262 return override ? OK : spam_rc;
263
264/* make sure the eml mbox file is spooled up */
265mbox_file = spool_mbox(&mbox_size, NULL);
266
267if (mbox_file == NULL)
268 {
269 /* error while spooling */
270 log_write(0, LOG_MAIN|LOG_PANIC,
271 "%s error while creating mbox spool file", loglabel);
272 return DEFER;
273 }
274
275start = time(NULL);
276
277 {
278 int num_servers = 0;
279 int current_server;
dc7b3d36
JH
280 uschar * address;
281 const uschar * spamd_address_list_ptr = spamd_address_work;
fd4d8871 282 spamd_address_container * spamd_address_vector[32];
fd4d8871
R
283
284 /* Check how many spamd servers we have
285 and register their addresses */
dc7b3d36 286 sep = 0; /* default colon-sep */
fd4d8871
R
287 while ((address = string_nextinlist(&spamd_address_list_ptr, &sep,
288 NULL, 0)) != NULL)
ddcf2b5f 289 {
55414b25 290 const uschar * sublist;
fd4d8871
R
291 int sublist_sep = -(int)' '; /* default space-sep */
292 unsigned args;
293 uschar * s;
fd4d8871 294
dc7b3d36 295 DEBUG(D_acl) debug_printf("spamd: addr entry '%s'\n", address);
2aad5761 296 sd = (spamd_address_container *)store_get(sizeof(spamd_address_container));
fd4d8871 297
2aad5761 298 for (sublist = address, args = 0, spamd_param_init(sd);
fd4d8871
R
299 s = string_nextinlist(&sublist, &sublist_sep, NULL, 0);
300 args++
301 )
ddcf2b5f 302 {
dc7b3d36 303 DEBUG(D_acl) debug_printf("spamd: addr parm '%s'\n", s);
fd4d8871
R
304 switch (args)
305 {
2aad5761 306 case 0: sd->hostspec = s;
fd4d8871
R
307 if (*s == '/') args++; /* local; no port */
308 break;
2aad5761
JH
309 case 1: sd->hostspec = string_sprintf("%s %s", sd->hostspec, s);
310 break;
311 default: spamd_param(s, sd);
312 break;
fd4d8871 313 }
ddcf2b5f 314 }
fd4d8871 315 if (args < 2)
c5f280e2 316 {
fd4d8871
R
317 log_write(0, LOG_MAIN,
318 "%s warning - invalid spamd address: '%s'", loglabel, address);
319 continue;
c5f280e2 320 }
8523533c 321
2aad5761 322 spamd_address_vector[num_servers] = sd;
fd4d8871
R
323 if (++num_servers > 31)
324 break;
8523533c
TK
325 }
326
fd4d8871
R
327 /* check if we have at least one server */
328 if (!num_servers)
ddcf2b5f 329 {
0f501486 330 log_write(0, LOG_MAIN|LOG_PANIC,
fd4d8871
R
331 "%s no useable spamd server addresses in spamd_address configuration option.",
332 loglabel);
8acbb134 333 goto defer;
ddcf2b5f 334 }
0f501486 335
8a512ed5
JH
336 current_server = spamd_get_server(spamd_address_vector, num_servers);
337 sd = spamd_address_vector[current_server];
338 for(;;)
ddcf2b5f 339 {
2aad5761 340 uschar * errstr;
8523533c 341
35deab6a 342 DEBUG(D_acl) debug_printf("spamd: trying server %s\n", sd->hostspec);
fd4d8871 343
8a512ed5
JH
344 for (;;)
345 {
346 if ( (spamd_sock = ip_streamsocket(sd->hostspec, &errstr, 5)) >= 0
347 || sd->retry <= 0
348 )
349 break;
35deab6a 350 DEBUG(D_acl) debug_printf("sspamd: erver %s: retry conn\n", sd->hostspec);
8a512ed5
JH
351 while (sd->retry > 0) sd->retry = sleep(sd->retry);
352 }
353 if (spamd_sock >= 0)
2aad5761 354 break;
25257489 355
2aad5761
JH
356 log_write(0, LOG_MAIN, "%s spamd: %s", loglabel, errstr);
357 sd->is_failed = TRUE;
25257489 358
2aad5761
JH
359 current_server = spamd_get_server(spamd_address_vector, num_servers);
360 if (current_server < 0)
fd4d8871 361 {
8a512ed5 362 log_write(0, LOG_MAIN|LOG_PANIC, "%s all spamd servers failed", loglabel);
2aad5761 363 goto defer;
fd4d8871 364 }
8a512ed5 365 sd = spamd_address_vector[current_server];
ddcf2b5f 366 }
fd4d8871 367 }
8523533c 368
fd4d8871
R
369if (spamd_sock == -1)
370 {
371 log_write(0, LOG_MAIN|LOG_PANIC,
372 "programming fault, spamd_sock unexpectedly unset");
8acbb134 373 goto defer;
fd4d8871
R
374 }
375
376(void)fcntl(spamd_sock, F_SETFL, O_NONBLOCK);
377/* now we are connected to spamd on spamd_sock */
8a512ed5 378if (sd->is_rspamd)
fd4d8871
R
379 { /* rspamd variant */
380 uschar *req_str;
6c54be64
AL
381 const uschar * helo;
382 const uschar * fcrdns;
383 const uschar * authid;
fd4d8871
R
384
385 req_str = string_sprintf("CHECK RSPAMC/1.3\r\nContent-length: %lu\r\n"
35deab6a
JH
386 "Queue-Id: %s\r\nFrom: <%s>\r\nRecipient-Number: %d\r\n",
387 mbox_size, message_id, sender_address, recipients_count);
fd4d8871
R
388 for (i = 0; i < recipients_count; i ++)
389 req_str = string_sprintf("%sRcpt: <%s>\r\n", req_str, recipients_list[i].address);
390 if ((helo = expand_string(US"$sender_helo_name")) != NULL && *helo != '\0')
391 req_str = string_sprintf("%sHelo: %s\r\n", req_str, helo);
392 if ((fcrdns = expand_string(US"$sender_host_name")) != NULL && *fcrdns != '\0')
393 req_str = string_sprintf("%sHostname: %s\r\n", req_str, fcrdns);
394 if (sender_host_address != NULL)
395 req_str = string_sprintf("%sIP: %s\r\n", req_str, sender_host_address);
6c54be64
AL
396 if ((authid = expand_string(US"$authenticated_id")) != NULL && *authid != '\0')
397 req_str = string_sprintf("%sUser: %s\r\n", req_str, authid);
fd4d8871
R
398 req_str = string_sprintf("%s\r\n", req_str);
399 wrote = send(spamd_sock, req_str, Ustrlen(req_str), 0);
400 }
6c54be64 401else
fd4d8871
R
402 { /* spamassassin variant */
403 (void)string_format(spamd_buffer,
404 sizeof(spamd_buffer),
405 "REPORT SPAMC/1.2\r\nUser: %s\r\nContent-length: %ld\r\n\r\n",
406 user_name,
407 mbox_size);
408 /* send our request */
409 wrote = send(spamd_sock, spamd_buffer, Ustrlen(spamd_buffer), 0);
410 }
6c54be64 411
fd4d8871
R
412if (wrote == -1)
413 {
414 (void)close(spamd_sock);
415 log_write(0, LOG_MAIN|LOG_PANIC,
416 "%s spamd send failed: %s", loglabel, strerror(errno));
8acbb134 417 goto defer;
fd4d8871
R
418 }
419
420/* now send the file */
421/* spamd sometimes accepts conections but doesn't read data off
422 * the connection. We make the file descriptor non-blocking so
423 * that the write will only write sufficient data without blocking
424 * and we poll the desciptor to make sure that we can write without
425 * blocking. Short writes are gracefully handled and if the whole
426 * trasaction takes too long it is aborted.
427 * Note: poll() is not supported in OSX 10.2 and is reported to be
428 * broken in more recent versions (up to 10.4).
429 */
430#ifndef NO_POLL_H
431pollfd.fd = spamd_sock;
432pollfd.events = POLLOUT;
433#endif
434(void)fcntl(spamd_sock, F_SETFL, O_NONBLOCK);
435do
436 {
437 read = fread(spamd_buffer,1,sizeof(spamd_buffer),mbox_file);
438 if (read > 0)
ddcf2b5f 439 {
fd4d8871
R
440 offset = 0;
441again:
442#ifndef NO_POLL_H
443 result = poll(&pollfd, 1, 1000);
8523533c 444
fd4d8871
R
445/* Patch posted by Erik ? for OS X and applied by PH */
446#else
447 select_tv.tv_sec = 1;
448 select_tv.tv_usec = 0;
449 FD_ZERO(&select_fd);
450 FD_SET(spamd_sock, &select_fd);
451 result = select(spamd_sock+1, NULL, &select_fd, NULL, &select_tv);
452#endif
453/* End Erik's patch */
8523533c 454
fd4d8871
R
455 if (result == -1 && errno == EINTR)
456 goto again;
457 else if (result < 1)
c5f280e2 458 {
fd4d8871
R
459 if (result == -1)
460 log_write(0, LOG_MAIN|LOG_PANIC,
461 "%s %s on spamd socket", loglabel, strerror(errno));
462 else
463 {
8a512ed5 464 if (time(NULL) - start < sd->timeout)
fd4d8871
R
465 goto again;
466 log_write(0, LOG_MAIN|LOG_PANIC,
467 "%s timed out writing spamd socket", loglabel);
468 }
469 (void)close(spamd_sock);
8acbb134 470 goto defer;
c5f280e2 471 }
8e669ac1 472
fd4d8871
R
473 wrote = send(spamd_sock,spamd_buffer + offset,read - offset,0);
474 if (wrote == -1)
c5f280e2 475 {
fd4d8871
R
476 log_write(0, LOG_MAIN|LOG_PANIC,
477 "%s %s on spamd socket", loglabel, strerror(errno));
478 (void)close(spamd_sock);
8acbb134 479 goto defer;
c5f280e2 480 }
fd4d8871 481 if (offset + wrote != read)
ddcf2b5f 482 {
fd4d8871
R
483 offset += wrote;
484 goto again;
ddcf2b5f
JH
485 }
486 }
fd4d8871
R
487 }
488while (!feof(mbox_file) && !ferror(mbox_file));
8523533c 489
fd4d8871
R
490if (ferror(mbox_file))
491 {
492 log_write(0, LOG_MAIN|LOG_PANIC,
493 "%s error reading spool file: %s", loglabel, strerror(errno));
494 (void)close(spamd_sock);
8acbb134 495 goto defer;
fd4d8871
R
496 }
497
498(void)fclose(mbox_file);
499
500/* we're done sending, close socket for writing */
501shutdown(spamd_sock,SHUT_WR);
502
503/* read spamd response using what's left of the timeout. */
504memset(spamd_buffer, 0, sizeof(spamd_buffer));
505offset = 0;
506while ((i = ip_recv(spamd_sock,
507 spamd_buffer + offset,
508 sizeof(spamd_buffer) - offset - 1,
8a512ed5 509 sd->timeout - time(NULL) + start)) > 0 )
fd4d8871
R
510 offset += i;
511
512/* error handling */
513if (i <= 0 && errno != 0)
514 {
515 log_write(0, LOG_MAIN|LOG_PANIC,
516 "%s error reading from spamd socket: %s", loglabel, strerror(errno));
517 (void)close(spamd_sock);
518 return DEFER;
519 }
520
521/* reading done */
522(void)close(spamd_sock);
523
8a512ed5 524if (sd->is_rspamd)
fd4d8871
R
525 { /* rspamd variant of reply */
526 int r;
527 if ((r = sscanf(CS spamd_buffer,
528 "RSPAMD/%7s 0 EX_OK\r\nMetric: default; %7s %lf / %lf / %lf\r\n%n",
529 spamd_version, spamd_short_result, &spamd_score, &spamd_threshold,
530 &spamd_reject_score, &spamd_report_offset)) != 5)
531 {
6c54be64
AL
532 log_write(0, LOG_MAIN|LOG_PANIC,
533 "%s cannot parse spamd output: %d", loglabel, r);
534 return DEFER;
fd4d8871
R
535 }
536 /* now parse action */
8523533c 537 p = &spamd_buffer[spamd_report_offset];
fd4d8871
R
538
539 if (Ustrncmp(p, "Action: ", sizeof("Action: ") - 1) == 0)
ddcf2b5f 540 {
fd4d8871
R
541 p += sizeof("Action: ") - 1;
542 q = &spam_action_buffer[0];
543 while (*p && *p != '\r' && (q - spam_action_buffer) < sizeof(spam_action_buffer) - 1)
544 *q++ = *p++;
545 *q = '\0';
ddcf2b5f 546 }
fd4d8871
R
547 }
548else
549 { /* spamassassin */
550 /* dig in the spamd output and put the report in a multiline header,
551 if requested */
552 if (sscanf(CS spamd_buffer,
553 "SPAMD/%7s 0 EX_OK\r\nContent-length: %*u\r\n\r\n%lf/%lf\r\n%n",
554 spamd_version,&spamd_score,&spamd_threshold,&spamd_report_offset) != 3)
ddcf2b5f 555 {
fd4d8871
R
556 /* try to fall back to pre-2.50 spamd output */
557 if (sscanf(CS spamd_buffer,
558 "SPAMD/%7s 0 EX_OK\r\nSpam: %*s ; %lf / %lf\r\n\r\n%n",
559 spamd_version,&spamd_score,&spamd_threshold,&spamd_report_offset) != 3)
560 {
561 log_write(0, LOG_MAIN|LOG_PANIC,
562 "%s cannot parse spamd output", loglabel);
563 return DEFER;
564 }
ddcf2b5f 565 }
fd4d8871
R
566
567 Ustrcpy(spam_action_buffer,
568 spamd_score >= spamd_threshold ? "reject" : "no action");
569 }
570
571/* Create report. Since this is a multiline string,
572we must hack it into shape first */
573p = &spamd_buffer[spamd_report_offset];
574q = spam_report_buffer;
575while (*p != '\0')
576 {
577 /* skip \r */
578 if (*p == '\r')
579 {
580 p++;
581 continue;
582 }
583 *q++ = *p;
584 if (*p++ == '\n')
585 {
586 /* add an extra space after the newline to ensure
587 that it is treated as a header continuation line */
588 *q++ = ' ';
589 }
590 }
591/* NULL-terminate */
592*q-- = '\0';
593/* cut off trailing leftovers */
594while (*q <= ' ')
595 *q-- = '\0';
596
597spam_report = spam_report_buffer;
598spam_action = spam_action_buffer;
599
600/* create spam bar */
601spamd_score_char = spamd_score > 0 ? '+' : '-';
602j = abs((int)(spamd_score));
603i = 0;
604if (j != 0)
605 while ((i < j) && (i <= MAX_SPAM_BAR_CHARS))
606 spam_bar_buffer[i++] = spamd_score_char;
607else
608 {
609 spam_bar_buffer[0] = '/';
610 i = 1;
611 }
612spam_bar_buffer[i] = '\0';
613spam_bar = spam_bar_buffer;
614
615/* create "float" spam score */
616(void)string_format(spam_score_buffer, sizeof(spam_score_buffer),
617 "%.1f", spamd_score);
618spam_score = spam_score_buffer;
619
620/* create "int" spam score */
621j = (int)((spamd_score + 0.001)*10);
622(void)string_format(spam_score_int_buffer, sizeof(spam_score_int_buffer),
623 "%d", j);
624spam_score_int = spam_score_int_buffer;
625
626/* compare threshold against score */
627spam_rc = spamd_score >= spamd_threshold
628 ? OK /* spam as determined by user's threshold */
629 : FAIL; /* not spam */
630
631/* remember expanded spamd_address if needed */
632if (spamd_address_work != spamd_address)
633 prev_spamd_address_work = string_copy(spamd_address_work);
634
635/* remember user name and "been here" for it */
636Ustrcpy(prev_user_name, user_name);
637spam_ok = 1;
638
639return override
640 ? OK /* always return OK, no matter what the score */
641 : spam_rc;
8acbb134
JH
642
643defer:
644 (void)fclose(mbox_file);
645 return DEFER;
8523533c
TK
646}
647
648#endif
2aad5761
JH
649/* vi: aw ai sw=2
650*/