From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/69259 Path: news.gmane.org!not-for-mail From: Daniel Pittman Newsgroups: gmane.emacs.gnus.general Subject: gnus-sieve: make it easier to customize. Date: Fri, 04 Dec 2009 00:35:25 +1100 Message-ID: <87ljhkrxia.fsf@rimspace.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1259850863 9443 80.91.229.12 (3 Dec 2009 14:34:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 3 Dec 2009 14:34:23 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M17664@lists.math.uh.edu Thu Dec 03 15:34:16 2009 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.50) id 1NGCl4-0001np-Mp for ding-account@gmane.org; Thu, 03 Dec 2009 15:34:15 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1NGCks-0004GK-59; Thu, 03 Dec 2009 08:34:02 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1NGC6Z-00044N-2X for ding@lists.math.uh.edu; Thu, 03 Dec 2009 07:52:23 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.69) (envelope-from ) id 1NGC6W-0001Wc-Vp for ding@lists.math.uh.edu; Thu, 03 Dec 2009 07:52:23 -0600 Original-Received: from lo.gmane.org ([80.91.229.12]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1NGC6W-0005LI-00 for ; Thu, 03 Dec 2009 14:52:20 +0100 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1NGC6O-0004GU-Gm for ding@gnus.org; Thu, 03 Dec 2009 14:52:12 +0100 Original-Received: from ppp59-167-189-244.static.internode.on.net ([59.167.189.244]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Dec 2009 14:52:12 +0100 Original-Received: from daniel by ppp59-167-189-244.static.internode.on.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Dec 2009 14:52:12 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 116 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ppp59-167-189-244.static.internode.on.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:exXtczDB3q6R6oonvTXYGNl1xvQ= X-Spam-Score: -2.8 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:69259 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=gnus-sieve.patch 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 --=-=-=--