Gnus development mailing list
 help / color / mirror / Atom feed
From: David Hansen <david.hansen@gmx.net>
Subject: Re: nnrss.el and <enclosure /> element
Date: Fri, 22 Apr 2005 02:15:43 +0200	[thread overview]
Message-ID: <87oec7k6og.fsf@robotron.ath.cx> (raw)
In-Reply-To: <873btkrvkq.fsf@robotron.ath.cx>

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

On Thu, 21 Apr 2005 17:36:05 +0200 David Hansen wrote:

> seems like nnrss.el ignores the enclosure element.

OK, did it myself, in case someone is interested the attached
patch is against current CVS HEAD.

But be aware it's the first time i touched gnus code.

David


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

--- cvs-src/gnus/lisp/nnrss.el	2005-04-21 23:37:13.000000000 +0200
+++ share/emacs/site-lisp/nnrss.el	2005-04-22 02:09:15.934656168 +0200
@@ -195,6 +195,7 @@
 				   (delete "" (split-string (nth 6 e) "\n+"))
 				   " ")))
 	      (link (nth 2 e))
+              (enclosure (nth 7 e))
 	      ;; Enable encoding of Newsgroups header in XEmacs.
 	      (default-enable-multibyte-characters t)
 	      (rfc2047-header-encoding-alist
@@ -203,18 +204,21 @@
 			 rfc2047-header-encoding-alist)
 		 rfc2047-header-encoding-alist))
 	      rfc2047-encode-encoded-words body)
-	  (when (or text link)
+	  (when (or text link enclosure)
 	    (insert "\n")
 	    (insert "<#multipart type=alternative>\n"
 		    "<#part type=\"text/plain\">\n")
 	    (setq body (point))
-	    (if text
-		(progn
-		  (insert text "\n")
-		  (when link
-		    (insert "\n" link "\n")))
-	      (when link
-		(insert link "\n")))
+	    (when text
+              (insert text "\n")
+              (when (or link enclosure)
+                (insert "\n")))
+            (when link
+              (insert link "\n"))
+            (when enclosure
+              (insert (car enclosure) " "
+                      (nth 2 enclosure) " "
+                      (nth 3 enclosure) "\n"))
 	    (setq body (buffer-substring body (point)))
 	    (insert "<#/part>\n"
 		    "<#part type=\"text/html\">\n"
@@ -223,6 +227,10 @@
 	      (insert text "\n"))
 	    (when link
 	      (insert "<p><a href=\"" link "\">link</a></p>\n"))
+            (when enclosure
+              (insert "<p><a href=\"" (car enclosure) "\">"
+                      (cadr enclosure) "</a> " (nth 2 enclosure)
+                      " " (nth 3 enclosure) "</p>\n"))
 	    (insert "</body></html>\n"
 		    "<#/part>\n"
 		    "<#/multipart>\n"))
@@ -519,8 +527,8 @@
 ;;; Snarf functions
 
 (defun nnrss-check-group (group server)
-  (let (file xml subject url extra changed author
-	     date rss-ns rdf-ns content-ns dc-ns)
+  (let (file xml subject url extra changed author date
+             enclosure rss-ns rdf-ns content-ns dc-ns)
     (if (and nnrss-use-local
 	     (file-exists-p (setq file (expand-file-name
 					(nnrss-translate-file-chars
@@ -568,6 +576,27 @@
 	(setq date (or (nnrss-node-text dc-ns 'date item)
 		       (nnrss-node-text rss-ns 'pubDate item)
 		       (message-make-date)))
+        (when (setq enclosure (cadr (assq (intern (concat rss-ns "enclosure")) item)))
+          (let ((url (cdr (assq 'url enclosure)))
+                (len (cdr (assq 'length enclosure)))
+                (type (cdr (assq 'type enclosure)))
+                (name))
+            (setq len
+                  (if (and len (integerp (setq len (string-to-number len))))
+                      ;; actually already in `ls-lisp-format-file-size' but
+                      ;; probably not worth to require it for one function
+                      (do ((size (/ len 1.0) (/ size 1024.0))
+                           (post-fixes (list "" "k" "M" "G" "T" "P" "E")
+                                       (cdr post-fixes)))
+                          ((< size 1024)
+                           (format "%.1f%s" size (car post-fixes))))
+                    "0"))
+            (setq url (or url ""))
+            (setq name (if (string-match "/\\([^/]*\\)$" url)
+                            (match-string 1 url)
+                          "file"))
+            (setq type (or type ""))
+            (setq enclosure (list url name len type))))
 	(push
 	 (list
 	  (incf nnrss-group-max)
@@ -576,7 +605,8 @@
 	  (and subject (nnrss-mime-encode-string subject))
 	  (and author (nnrss-mime-encode-string author))
 	  date
-	  (and extra (nnrss-decode-entities-string extra)))
+	  (and extra (nnrss-decode-entities-string extra))
+          enclosure)
 	 nnrss-group-data)
 	(puthash (or url extra) t nnrss-group-hashtb)
 	(setq changed t))

  reply	other threads:[~2005-04-22  0:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-21 15:36 David Hansen
2005-04-22  0:15 ` David Hansen [this message]
2005-04-22  2:08   ` Katsumi Yamaoka
2005-04-22  9:55     ` David Hansen
2005-04-22 10:30       ` Katsumi Yamaoka
2005-04-26 16:31         ` David Hansen

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=87oec7k6og.fsf@robotron.ath.cx \
    --to=david.hansen@gmx.net \
    /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).