Gnus development mailing list
 help / color / mirror / Atom feed
From: Jan Tatarik <jan.tatarik@gmail.com>
To: ding@gnus.org
Subject: Re: Scoring on basee64 encoded message body
Date: Fri, 13 Apr 2012 00:58:59 +0200	[thread overview]
Message-ID: <5n5x2riph4d0b0.fsf@nb-jtatarik2.xing.hh> (raw)
In-Reply-To: <m38vi0g55u.fsf@stories.gnus.org> (Lars Magne Ingebrigtsen's message of "Thu, 12 Apr 2012 20:45:49 +0200")

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

On Thu, Apr 12 2012, Lars Magne Ingebrigtsen Lars Magne Ingebrigtsen wrote:

>> - run mm-dissect-buffer on the message body (any idea which args would
>>   be appropriate?)

> NO-STRICT-MIME, I think.

>> - for multipart messages, pick the handles with text/* type, run them
>>   through their respective mm-inline-* function as defined in
>>   mm-inline-media-tests

>> - score on all the decoded text parts

>> Is this the way to go?

> Yup; sounds good.

And here is the new patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: decode mm messages when scoring on body --]
[-- Type: text/x-diff, Size: 3002 bytes --]

diff --git a/lisp/gnus-logic.el b/lisp/gnus-logic.el
index 954295438c953c2500b9c1959a49e52312cc9653..38442a406dd6fb6ef47cd468248618e68337a26a 100644
--- a/lisp/gnus-logic.el
+++ b/lisp/gnus-logic.el
@@ -181,8 +181,10 @@
   (with-current-buffer nntp-server-buffer
     (let* ((request-func (cond ((string= "head" header)
 				'gnus-request-head)
+                               ;; We need to peek at the headers to detect the
+                               ;; content encoding
 			       ((string= "body" header)
-				'gnus-request-body)
+                    'gnus-request-article)
 			       (t 'gnus-request-article)))
 	   ofunc article)
       ;; Not all backends support partial fetching.  In that case, we
@@ -196,6 +198,7 @@
       (gnus-message 7 "Scoring article %s..." article)
       (when (funcall request-func article gnus-newsgroup-name)
 	(goto-char (point-min))
+    (gnus-score-decode-text-parts)
 	;; If just parts of the article is to be searched and the
 	;; backend didn't support partial fetching, we just narrow to
 	;; the relevant parts.
diff --git a/lisp/gnus-score.el b/lisp/gnus-score.el
index f86b6f837a70ce54b06668187821fe57c3f80f4c..003355dd2c91847241dc67263f83d26ae52920de 100644
--- a/lisp/gnus-score.el
+++ b/lisp/gnus-score.el
@@ -1736,6 +1736,24 @@ score in `gnus-newsgroup-scored' by SCORE."
 	  (setq entries rest)))))
   nil)
 
+(defun gnus-score-decode-text-parts ()
+  (let ((handles (mm-dissect-buffer t)))
+    (cond ((stringp (car handles)) (pop handles))
+          ((and (bufferp (car handles))
+                (stringp (car (mm-handle-type handles))))
+           (setq handles (list handles))))
+
+    (save-excursion
+      (article-goto-body)
+      (delete-region (point) (point-max))
+      (save-restriction
+        (narrow-to-region (point) (point))
+        (mapc #'mm-display-inline
+              (remove-if-not
+               (lambda (handle)
+                 (string-match "^text/" (mm-handle-media-type handle)))
+               handles))))))
+
 (defun gnus-score-body (scores header now expire &optional trace)
   (if gnus-agent-fetching
       nil
@@ -1752,8 +1770,10 @@ score in `gnus-newsgroup-scored' by SCORE."
 	       (all-scores scores)
 	       (request-func (cond ((string= "head" header)
 				    'gnus-request-head)
+                               ;; We need to peek at the headers to detect
+                               ;; the content encoding
 				   ((string= "body" header)
-				    'gnus-request-body)
+                    'gnus-request-article)
 				   (t 'gnus-request-article)))
 	       entries alist ofunc article last)
 	  (when articles
@@ -1773,6 +1793,7 @@ score in `gnus-newsgroup-scored' by SCORE."
 	      (widen)
 	      (when (funcall request-func article gnus-newsgroup-name)
 		(goto-char (point-min))
+        (gnus-score-decode-text-parts)
 	    ;; If just parts of the article is to be searched, but the
 	    ;; backend didn't support partial fetching, we just narrow
 		;; to the relevant parts.

  reply	other threads:[~2012-04-12 22:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-13 10:39 Jan Tatarik
2012-03-14 14:38 ` Lars Magne Ingebrigtsen
2012-03-14 20:21   ` Reiner Steib
2012-03-15  1:29     ` Lars Magne Ingebrigtsen
2012-03-15 21:05   ` Jan Tatarik
2012-03-22 20:38     ` Lars Magne Ingebrigtsen
2012-03-23 12:11       ` Jan Tatarik
2012-04-10 19:32         ` Lars Magne Ingebrigtsen
2012-04-11  7:30           ` Jan Tatarik
2012-04-11 19:34           ` Jan Tatarik
2012-04-12 18:45             ` Lars Magne Ingebrigtsen
2012-04-12 22:58               ` Jan Tatarik [this message]
2012-06-10 21:08                 ` Lars Magne Ingebrigtsen
2012-06-28  9:45                   ` Jan Tatarik
2012-09-05 13:40                     ` Lars Ingebrigtsen
2012-09-05 14:39                       ` Jan Tatarik
2012-09-05 14:43                         ` Lars Ingebrigtsen
2012-09-05 15:07                           ` Jan Tatarik
2012-09-05 15:35                             ` Lars Ingebrigtsen
2012-09-05 15:42                           ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5n5x2riph4d0b0.fsf@nb-jtatarik2.xing.hh \
    --to=jan.tatarik@gmail.com \
    --cc=ding@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).