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