Gnus development mailing list
 help / color / mirror / Atom feed
* gnus-sieve: make it easier to customize.
@ 2009-12-03 13:35 Daniel Pittman
  2009-12-03 18:04 ` Ted Zlatanov
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Pittman @ 2009-12-03 13:35 UTC (permalink / raw)
  To: ding

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

G'day.

My mail server places some particular demands on the format of Sieve scripts;
specifically, it likes to have a comment before each item to show as the
"name" of the filter rule in the web interface.

Actually trying to hack this into gnus-sieve was surprisingly difficult: the
generation process wraps the formatting of each command into the same process
that loops the overall map.

Attached is a patch that splits this out into two components: one function
that loops through newsrc and finds the groups, and another that is
responsible for generating the individual Sieve expression for a single group.

It also implements the comment-before-content used by my server, although that
is reasonably self-contained and optional; if y'all felt like taking the patch
without that I would be happy.[1]


I have papers for Gnus, and Emacs, on file, although I don't consider the
content original enough to warrant them: while it moves a whole bunch of
lines, it just moves them.  Anyway, whatever.  I hope y'all accept it. :)

Regards,
        Daniel

Footnotes: 
[1]  Specifically, I could advise the function to inject the comment
     appropriately without worrying about changes to the overall design later
     breaking my nasty hacks. :)

-- 
✣ Daniel Pittman            ✉ daniel@rimspace.net            ☎ +61 401 155 707
               ♽ made with 100 percent post-consumer electrons


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

diff -u -p /home/daniel/tmp/t/gnus-sieve.el.orig /home/daniel/tmp/t/gnus-sieve.el
--- /home/daniel/tmp/t/gnus-sieve.el.orig	2009-12-04 00:18:17.978172193 +1100
+++ /home/daniel/tmp/t/gnus-sieve.el	2009-12-04 00:31:32.797180020 +1100
@@ -205,6 +205,31 @@ test as the condition and { fileinto \"g
 If CROSSPOST is nil, each conditional body contains a \"stop\" command
 which stops execution after a match is found.
 
+The function `gnus-sieve-script-one' generates the actual commands,
+while this provides the overall structure and iteration.
+
+This is returned as a string."
+  (let* ((newsrc (cdr gnus-newsrc-alist))
+	 script)
+    (dolist (info newsrc)
+      (when (or (not method)
+		(gnus-server-equal method (gnus-info-method info)))
+	(let ((spec (gnus-sieve-script-one (gnus-info-group info) crosspost)))
+	  (when spec
+	    (push spec script)))))
+    (mapconcat 'identity script "\n")))
+
+(defun gnus-sieve-script-one (group &optional crosspost)
+  "Generate a single Sieve command for a single Gnus GROUP,
+passed as an object.  Only groups having a `sieve' parameter have
+a command generated; `nil' is returned otherwise.
+
+A Sieve IF control structure is generated, having the test as the
+condition and { fileinto \"group.name\"; } as the body.
+
+If CROSSPOST is nil, each conditional body contains a \"stop\"
+command which stops execution after a match is found.
+
 For example: If the INBOX.list.sieve group has the
 
   (sieve address \"sender\" \"sieve-admin@extundo.com\")
@@ -216,22 +241,16 @@ group parameter, (gnus-sieve-script) res
   }
 
 This is returned as a string."
-  (let* ((newsrc (cdr gnus-newsrc-alist))
-	 script)
-    (dolist (info newsrc)
-      (when (or (not method)
-		(gnus-server-equal method (gnus-info-method info)))
-	(let* ((group (gnus-info-group info))
-	       (spec (gnus-group-find-parameter group 'sieve t)))
-	  (when spec
-	    (push (concat "if " (gnus-sieve-test spec) " {\n"
-			  "\tfileinto \"" (gnus-group-real-name group) "\";\n"
-			  (if crosspost
-			      ""
-			    "\tstop;\n")
-			  "}")
-		  script)))))
-    (mapconcat 'identity script "\n")))
+  (let ((spec (gnus-group-find-parameter group 'sieve t)))
+    (when spec
+      (concat (format "# %s: %s\n" (gnus-group-real-name group) spec)
+              "if " (gnus-sieve-test spec) " {\n"
+              "\tfileinto \"" (gnus-group-real-name group) "\";\n"
+              (if crosspost
+                  ""
+                "\tstop;\n")
+              "}"))))
+
 
 (provide 'gnus-sieve)
 

Diff finished.  Fri Dec  4 00:31:54 2009

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

end of thread, other threads:[~2009-12-14 15:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-03 13:35 gnus-sieve: make it easier to customize Daniel Pittman
2009-12-03 18:04 ` Ted Zlatanov
2009-12-04  1:46   ` Daniel Pittman
2009-12-07 15:56     ` Ted Zlatanov
2009-12-13 10:24       ` Daniel Pittman
2009-12-14 15:43         ` Ted Zlatanov

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).