From: Daniel Pittman <daniel@rimspace.net>
To: ding@gnus.org
Subject: gnus-sieve: make it easier to customize.
Date: Fri, 04 Dec 2009 00:35:25 +1100 [thread overview]
Message-ID: <87ljhkrxia.fsf@rimspace.net> (raw)
[-- 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
next reply other threads:[~2009-12-03 13:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-03 13:35 Daniel Pittman [this message]
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
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=87ljhkrxia.fsf@rimspace.net \
--to=daniel@rimspace.net \
--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).