aboutsummaryrefslogtreecommitdiff
path: root/mflib/sa.mf
blob: 0d03189aaf6aef4c644ab7bbd3b5a489b72834e6 (plain)
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
/* Auxiliary functions for interfacing with SpamAssassin
   Copyright (C) 2008-2011, 2015 Sergey Poznyakoff

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

module 'sa'.

const SA_SYMBOLS    0
const SA_REPORT     1
const SA_LEARN_SPAM 2
const SA_LEARN_HAM  3
const SA_FORGET     4

#pragma regex push +extended

static func __sa_format_score0(string code, number prec)
  returns string
do
  number len length(code)
  if len > prec
    return substring(code, 0, len - prec-1) . '.' .
           substring(code, len - prec, -1)
  else
    return "0." . replstr("0", prec - len) . code
  fi
done

/* Format CODE as a floating-point number with PREC decimal digits, i.e.:

      printf("%0.*f", prec, code/pow(10,prec))

   in C equivalent.   
*/
func sa_format_score(number code, number prec)
  returns string
do
  if code < 0
    return "-" . __sa_format_score0(- code, prec)
  else
    return __sa_format_score0(code, prec)
  fi
done

/* Reformat SpamAssassin report text in order to include it in a
   RFC 822 header:

     1. Remove the preamble and epilogue parts.
     2. Prefix each description line with a "* "
*/
func sa_format_report_header(string text)
  returns string
do
  number start index(text, "pts rule name")
  if start == -1
    return text
  fi
  set start index(text, "\n", start + 1)
  if start == -1
    return text
  fi
  set start index(text, "\n", start + 1)
  if start == -1
    return text
  fi

  string ret ""
  number len length(text)
  loop for number i start + 1,
       while i < len 
  do
    if substr(text, i) matches '^ *-?[0-9]\.[0-9]'
      set pfx "* "
    else
      set pfx "  "
    fi
    number n index(text, "\n", i)
    if n >= 0
      set ret ret . pfx . substring(text, i, n)
      set i n + 1
    else
      set ret ret . pfx . substr(text, i)
      break
    fi
  done
  return ret
done

func sa(string urlstr, number prec; number flag)
  returns number
do
  number command
  if defined(flag)
    set command flag
  else
    set command SA_SYMBOLS
  fi
  return spamc(current_message(), urlstr, prec, command)
done

#pragma regex pop

Return to:

Send suggestions and report system problems to the System administrator.