Gnus development mailing list
 help / color / mirror / Atom feed
* [spam.el] Problem with obtaining the spam score for CRM114
@ 2006-04-15 11:59 João Cachopo
  2006-04-15 23:45 ` Miles Bader
  2006-04-16 16:31 ` Lars Magne Ingebrigtsen
  0 siblings, 2 replies; 5+ messages in thread
From: João Cachopo @ 2006-04-15 11:59 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 768 bytes --]


Hi!

I switched recently from bogofilter to CRM114 and when I tried to sort
the summary of my spam group by the article spam score assigned by
CRM114, I couldn't made it to work.  The spam score of every article
showed up as 0.00 in the summary buffer.

One of the problems seems to be that the spam-necessary-extra-headers
function on spam.el only deals with SpamAssassin and Bogofilter.  I
guess that the header added by the CRM114 filter should be added to
the list of extra headers, also.

Once that is fixed, there remains another problem in the
spam-extra-header-to-number function, which already extracts the
proper score from the CRM114 header, but returns a string instead of a
number.

I include below a patch against spam.el that fixes both these errors.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: spam.patch --]
[-- Type: text/x-patch, Size: 2163 bytes --]

--- spam.el.orig	2006-03-28 20:51:41.000000000 +0100
+++ spam.el	2006-04-15 12:33:48.000000000 +0100
@@ -1156,6 +1156,8 @@
       (push 'X-Spam-Status list))
     (when spam-use-bogofilter
       (push 'X-Bogosity list))
+    (when spam-use-crm114
+      (push 'X-CRM114-Status list))
     list))
 
 (defun spam-user-format-function-S (headers)
@@ -1186,24 +1188,25 @@
 (defun spam-extra-header-to-number (header headers)
   "Transform an extra HEADER to a number, using list of HEADERS.
 Note this has to be fast."
-  (if (gnus-extra-header header headers)
-      (cond
-       ((eq header 'X-Spam-Status)
-	(string-to-number (gnus-replace-in-string
-			   (gnus-extra-header header headers)
-			   spam-spamassassin-score-regexp
-			   "\\1")))
-       ;; for CRM checking, it's probably faster to just do the string match
-       ((and spam-use-crm114 (string-match "( pR: \\([0-9.-]+\\)" header))
-	(match-string 1 header))
-       ((eq header 'X-Bogosity)
-	(string-to-number (gnus-replace-in-string
-			   (gnus-replace-in-string
-			    (gnus-extra-header header headers)
-			    ".*spamicity=" "")
-			   ",.*" "")))
-       (t nil))
-    nil))
+  (let ((header-content (gnus-extra-header header headers)))
+    (if header-content
+        (cond
+         ((eq header 'X-Spam-Status)
+          (string-to-number (gnus-replace-in-string
+                             header-content
+                             spam-spamassassin-score-regexp
+                             "\\1")))
+         ;; for CRM checking, it's probably faster to just do the string match
+         ((and spam-use-crm114 (string-match "( pR: \\([0-9.-]+\\)" header-content))
+          (string-to-number (match-string 1 header-content)))
+         ((eq header 'X-Bogosity)
+          (string-to-number (gnus-replace-in-string
+                             (gnus-replace-in-string
+                              header-content
+                              ".*spamicity=" "")
+                             ",.*" "")))
+         (t nil))
+      nil)))
 
 (defun spam-summary-score (headers &optional specific-header)
   "Score an article for the summary buffer, as fast as possible.

[-- Attachment #3: Type: text/plain, Size: 31 bytes --]


Best regards,
--
João Cachopo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [spam.el] Problem with obtaining the spam score for CRM114
  2006-04-15 11:59 [spam.el] Problem with obtaining the spam score for CRM114 João Cachopo
@ 2006-04-15 23:45 ` Miles Bader
  2006-04-17  9:09   ` João Cachopo
  2006-04-16 16:31 ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 5+ messages in thread
From: Miles Bader @ 2006-04-15 23:45 UTC (permalink / raw)


joao.cachopo@inesc-id.pt (João Cachopo) writes:
> +        (cond
> +         ((eq header 'X-Spam-Status)
...
> +         ;; for CRM checking, it's probably faster to just do the string match
> +         ((and spam-use-crm114 (string-match "( pR: \\([0-9.-]+\\)" header-content))

Faster to do a string match than eq?!?  Seems unlikely...

-miles
-- 
`There are more things in heaven and earth, Horatio,
 Than are dreamt of in your philosophy.'




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [spam.el] Problem with obtaining the spam score for CRM114
  2006-04-15 11:59 [spam.el] Problem with obtaining the spam score for CRM114 João Cachopo
  2006-04-15 23:45 ` Miles Bader
@ 2006-04-16 16:31 ` Lars Magne Ingebrigtsen
  1 sibling, 0 replies; 5+ messages in thread
From: Lars Magne Ingebrigtsen @ 2006-04-16 16:31 UTC (permalink / raw)


joao.cachopo@inesc-id.pt (João Cachopo) writes:

> I include below a patch against spam.el that fixes both these errors.

Thanks; installed.  (The patch is fewer than ten lines if we don't
count the indentation change, so I think that should be OK without
paperwork.)

-- 
(domestic pets only, the antidote for overdose, milk.)
  larsi@gnus.org * Lars Magne Ingebrigtsen




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [spam.el] Problem with obtaining the spam score for CRM114
  2006-04-15 23:45 ` Miles Bader
@ 2006-04-17  9:09   ` João Cachopo
  2006-04-18 20:27     ` Ted Zlatanov
  0 siblings, 1 reply; 5+ messages in thread
From: João Cachopo @ 2006-04-17  9:09 UTC (permalink / raw)


Miles Bader <miles@gnu.org> writes:

> joao.cachopo@inesc-id.pt (João Cachopo) writes:
>> +        (cond
>> +         ((eq header 'X-Spam-Status)
> ...
>> +         ;; for CRM checking, it's probably faster to just do the string match
>> +         ((and spam-use-crm114 (string-match "( pR: \\([0-9.-]+\\)" header-content))
>
> Faster to do a string match than eq?!?  Seems unlikely...

Actually, the comment and that part of the code was already in the
original code.

I agree with you that an eq is faster than a string-match when the
string-match can be replaced with an eq.

However, how would you replace the string-match with an eq in this
case?   Note that the value of header-content contains the score
assigned to the article...

I believe that the comment was comparing the string-match with the
gnus-replace-string used in the other cases.

--
João Cachopo




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [spam.el] Problem with obtaining the spam score for CRM114
  2006-04-17  9:09   ` João Cachopo
@ 2006-04-18 20:27     ` Ted Zlatanov
  0 siblings, 0 replies; 5+ messages in thread
From: Ted Zlatanov @ 2006-04-18 20:27 UTC (permalink / raw)
  Cc: ding

On 17 Apr 2006, joao.cachopo@inesc-id.pt wrote:

> Miles Bader <miles@gnu.org> writes:

>> Faster to do a string match than eq?!?  Seems unlikely...
>
> Actually, the comment and that part of the code was already in the
> original code.
...
> I believe that the comment was comparing the string-match with the
> gnus-replace-string used in the other cases.

Right :)  Thanks for the great contribution, Joao!

Ted



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-04-18 20:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-15 11:59 [spam.el] Problem with obtaining the spam score for CRM114 João Cachopo
2006-04-15 23:45 ` Miles Bader
2006-04-17  9:09   ` João Cachopo
2006-04-18 20:27     ` Ted Zlatanov
2006-04-16 16:31 ` Lars Magne Ingebrigtsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).