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