patch-lib_MailScanner_CustomFunctions_GenericSpamScanner_pm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. $OpenBSD: patch-lib_MailScanner_CustomFunctions_GenericSpamScanner_pm,v 1.1.1.1 2008/02/20 03:47:18 todd Exp $
  2. --- lib/MailScanner/CustomFunctions/GenericSpamScanner.pm.orig Thu Dec 7 13:12:22 2006
  3. +++ lib/MailScanner/CustomFunctions/GenericSpamScanner.pm Thu Dec 7 13:32:50 2006
  4. @@ -35,66 +35,80 @@ use IPC::Open2;
  5. use FileHandle;
  6. sub GenericSpamScanner {
  7. - my($ip, $from, $to, $message) = @_;
  8. + my($Message, $message) = @_;
  9. + my($ip, $from, $to) = ($Message->{clientip},
  10. + $Message->{from},
  11. + $Message->{to});
  12. - print STDERR "Generic Spam Scanner\n";
  13. - print STDERR "====================\n";
  14. - print STDERR "\n";
  15. - print STDERR "IP = \"$ip\"\n";
  16. - print STDERR "From = \"$from\"\n";
  17. - print STDERR "To = \"" . join(", ", @$to) . "\"\n";
  18. + #print STDERR "Generic Spam Scanner\n";
  19. + #print STDERR "====================\n";
  20. + #print STDERR "\n";
  21. + #print STDERR "IP = \"$ip\"\n";
  22. + #print STDERR "From = \"$from\"\n";
  23. + #print STDERR "To = \"" . join(", ", @$to) . "\"\n";
  24. #print STDERR "Message = \"" . join(", ", @$message) . "\"\n";
  25. # To call a remote program you might want to do this:
  26. - my($fhread, $fhwrite, $pid, $score, $report);
  27. - die "Can't fork: $!" unless defined($pid = open2($fhread, $fhwrite,
  28. - '/usr/local/bin/yourprogramhere'));
  29. - $fhwrite->print("$ip\n");
  30. - $fhwrite->print("$from\n");
  31. + my($fhread, $fhwrite, $pid, @result, $report, $users);
  32. foreach my $address (@$to) {
  33. - $fhwrite->print("$address\n");
  34. + $users .= "$address ";
  35. }
  36. + my $cmd = sprintf "/usr/local/bin/dspamc --client --stdout --deliver=innocent,spam --mode=tum --user %s",$users;
  37. + #print STDERR "cmd: $cmd\n";
  38. + die "Can't fork: $!" unless defined($pid = open2($fhread, $fhwrite, $cmd));
  39. $fhwrite->print(@$message);
  40. $fhwrite->flush();
  41. $fhwrite->close();
  42. - $score = <$fhread>;
  43. - chomp $score;
  44. - print STDERR "Read \"$score\" from your program\n\n";
  45. + my $state = 0;
  46. + my ($score,$report);
  47. + my @headers = ();
  48. + foreach my $line (<$fhread>) {
  49. + next if ($state > 0);
  50. + chomp $line;
  51. + if ($line =~ m/^$/) {
  52. + $state++;
  53. + next;
  54. + }
  55. + if ($line =~ m/^X-DSPAM/) {
  56. + $line =~ m/^([^:]*): (.*)$/;
  57. + my ($header,$val)=($1,$2);
  58. + next if ($header eq "X-DSPAM-Processed");
  59. + push @headers,"$header:$val";
  60. + #printf STDERR "Storing: $header \/ $val, now %s headers\n", $#headers;
  61. + $global::MS->{mta}->AddHeader($Message,
  62. + "${header}:", $val);
  63. + #@$message = ($line,@$message);
  64. + if ($header eq "X-DSPAM-Result") {
  65. + $result=$val;
  66. + }
  67. + if ($header eq "X-DSPAM-Confidence") {
  68. + # Confidence is a percentage, so
  69. + # make it 'spam' for 1.0 - 7.0, and
  70. + # make it 'ham' for 0.0 - 0.999999
  71. + if ($result eq "Spam") {
  72. + $score= 6.0*$val+1.0;
  73. + } else {
  74. + $score = 1.0-$val;
  75. + }
  76. + #print STDERR "Score! $score\n";
  77. + }
  78. + if ($header eq "X-DSPAM-Improbability") {
  79. + $report=$val;
  80. + #print STDERR "Report! $report\n";
  81. + }
  82. + }
  83. + next;
  84. + }
  85. +
  86. + #print STDERR "Read \"$score\" from your program\n";
  87. $score = $score+0.0;
  88. - $report = <$fhread>;
  89. - chomp $report;
  90. - print STDERR "Read \"$report\" from your program\n\n";
  91. + #print STDERR "Read \"$report\" from your program\n";
  92. + #printf STDERR "Read %d headers from your program\n",$#headers;
  93. - return ($score, $report);
  94. + return ($score, $report, @headers);
  95. # return (0.0, 'No report');
  96. }
  97. 1;
  98. -
  99. -__DATA__
  100. -
  101. -#------------------------------------------------------------
  102. -#
  103. -# C source code of a skeleton yourprogramhere program
  104. -#
  105. -#------------------------------------------------------------
  106. -
  107. -#include <stdio.h>
  108. -#include <stdlib.h>
  109. -
  110. -char buffer[256];
  111. -
  112. -int main(void) {
  113. - char *result;
  114. -
  115. - result = fgets(buffer, 256, stdin);
  116. - while(result!=NULL) {
  117. - result = fgets(buffer, 256, stdin);
  118. - }
  119. -
  120. - printf("55\n");
  121. - printf("This is a report\n");
  122. -}
  123. -