* 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
* Re: gnus-sieve: make it easier to customize.
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
0 siblings, 1 reply; 6+ messages in thread
From: Ted Zlatanov @ 2009-12-03 18:04 UTC (permalink / raw)
To: ding
On Fri, 04 Dec 2009 00:35:25 +1100 Daniel Pittman <daniel@rimspace.net> wrote:
DP> I have papers for Gnus, and Emacs, on file, although I don't consider the
DP> content original enough to warrant them: while it moves a whole bunch of
DP> lines, it just moves them. Anyway, whatever. I hope y'all accept it. :)
I think your version is much easier to read and understand. I don't use
Sieve so I can't test it but otherwise I'm in favor of comitting your
patch.
Ted
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: gnus-sieve: make it easier to customize.
2009-12-03 18:04 ` Ted Zlatanov
@ 2009-12-04 1:46 ` Daniel Pittman
2009-12-07 15:56 ` Ted Zlatanov
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Pittman @ 2009-12-04 1:46 UTC (permalink / raw)
To: ding
Ted Zlatanov <tzz@lifelogs.com> writes:
> On Fri, 04 Dec 2009 00:35:25 +1100 Daniel Pittman <daniel@rimspace.net> wrote:
>
> DP> I have papers for Gnus, and Emacs, on file, although I don't consider the
> DP> content original enough to warrant them: while it moves a whole bunch of
> DP> lines, it just moves them. Anyway, whatever. I hope y'all accept it. :)
>
> I think your version is much easier to read and understand. I don't use
> Sieve so I can't test it but otherwise I'm in favor of comitting your
> patch.
Well, the generated output is (trivially) identical to the original; it puts
us in no worse a state than the previous code, but more fine-grained.
Oh, and it actually generates a local file only; if you wish, you can test it
through generating the content and observing the output. :)
Daniel
--
✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707
♽ made with 100 percent post-consumer electrons
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: gnus-sieve: make it easier to customize.
2009-12-04 1:46 ` Daniel Pittman
@ 2009-12-07 15:56 ` Ted Zlatanov
2009-12-13 10:24 ` Daniel Pittman
0 siblings, 1 reply; 6+ messages in thread
From: Ted Zlatanov @ 2009-12-07 15:56 UTC (permalink / raw)
To: ding
On Fri, 04 Dec 2009 12:46:37 +1100 Daniel Pittman <daniel@rimspace.net> wrote:
DP> Ted Zlatanov <tzz@lifelogs.com> writes:
>> On Fri, 04 Dec 2009 00:35:25 +1100 Daniel Pittman <daniel@rimspace.net> wrote:
>>
DP> I have papers for Gnus, and Emacs, on file, although I don't consider the
DP> content original enough to warrant them: while it moves a whole bunch of
DP> lines, it just moves them. Anyway, whatever. I hope y'all accept it. :)
>>
>> I think your version is much easier to read and understand. I don't use
>> Sieve so I can't test it but otherwise I'm in favor of comitting your
>> patch.
DP> Well, the generated output is (trivially) identical to the original; it puts
DP> us in no worse a state than the previous code, but more fine-grained.
DP> Oh, and it actually generates a local file only; if you wish, you can test it
DP> through generating the content and observing the output. :)
I've been curious about Sieve but there's no info on using it with
Gnus. Also I found Cyrus IMAP painful when I set it up and at the time
it was the only decent Sieve implementation.
Does anyone use it with dovecot (http://wiki.dovecot.org/LDA/Sieve)? Do
we have ManageSieve support in Gnus, and if not, can it be added?
Ted
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: gnus-sieve: make it easier to customize.
2009-12-07 15:56 ` Ted Zlatanov
@ 2009-12-13 10:24 ` Daniel Pittman
2009-12-14 15:43 ` Ted Zlatanov
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Pittman @ 2009-12-13 10:24 UTC (permalink / raw)
To: ding
Ted Zlatanov <tzz@lifelogs.com> writes:
> On Fri, 04 Dec 2009 12:46:37 +1100 Daniel Pittman <daniel@rimspace.net> wrote:
> DP> Ted Zlatanov <tzz@lifelogs.com> writes:
>>> On Fri, 04 Dec 2009 00:35:25 +1100 Daniel Pittman <daniel@rimspace.net> wrote:
>>>
> DP> I have papers for Gnus, and Emacs, on file, although I don't consider the
> DP> content original enough to warrant them: while it moves a whole bunch of
> DP> lines, it just moves them. Anyway, whatever. I hope y'all accept it. :)
>>>
>>> I think your version is much easier to read and understand. I don't use
>>> Sieve so I can't test it but otherwise I'm in favor of comitting your
>>> patch.
>
> DP> Well, the generated output is (trivially) identical to the original; it puts
> DP> us in no worse a state than the previous code, but more fine-grained.
>
> DP> Oh, and it actually generates a local file only; if you wish, you can test it
> DP> through generating the content and observing the output. :)
>
> I've been curious about Sieve but there's no info on using it with Gnus.
The Gnus manual, and the Gnus-Sieve manual, both in info format, don't do it
for you? In fairness, I guess, they are "technical reference" guides to the
integration features, not anything user-focused about the Sieve language
itself.
The short version is, though, that you edit group properties to add a "sieve"
property resembling the expression to file messages into that group:
INBOX/personal =>
((sieve address ["to" "cc"] "daniel@rimspace.net"))
> Also I found Cyrus IMAP painful when I set it up and at the time it was the
> only decent Sieve implementation.
>
> Does anyone use it with dovecot (http://wiki.dovecot.org/LDA/Sieve)?
No, but friends of mine support large numbers (> 10K) users in education using
it, and find it effective and worthwhile. I use it with Zimbra, more or less.
> Do we have ManageSieve support in Gnus, and if not, can it be added?
Mostly outside it, but the facilities are there. Read the Sieve manual
shipped with Emacs for details. :)
Daniel
--
✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707
♽ made with 100 percent post-consumer electrons
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: gnus-sieve: make it easier to customize.
2009-12-13 10:24 ` Daniel Pittman
@ 2009-12-14 15:43 ` Ted Zlatanov
0 siblings, 0 replies; 6+ messages in thread
From: Ted Zlatanov @ 2009-12-14 15:43 UTC (permalink / raw)
To: Daniel Pittman; +Cc: ding
On Sun, 13 Dec 2009 21:24:38 +1100 Daniel Pittman <daniel@rimspace.net> wrote:
DP> Ted Zlatanov <tzz@lifelogs.com> writes:
>> I've been curious about Sieve but there's no info on using it with Gnus.
DP> The Gnus manual, and the Gnus-Sieve manual, both in info format, don't do it
DP> for you? In fairness, I guess, they are "technical reference" guides to the
DP> integration features, not anything user-focused about the Sieve language
DP> itself.
Sorry, I meant to say there's no user-focused info on using it with Gnus
as you said. I was not thinking when I wrote that.
The information in both manuals is for those who already have Sieve set
up. It's especially important to explain how Sieve works and how it's
different from client-side Gnus splitting, so maybe that requires a
separate section?
My eventual goal is to store the Gnus registry in a distributed way
(probably via imap-hash.el) and generate Sieve scripts from it to split
by sender, subject, or references. I don't know if that's the right
approach but it seems most useful.
DP> The short version is, though, that you edit group properties to add a "sieve"
DP> property resembling the expression to file messages into that group:
DP> INBOX/personal =>
DP> ((sieve address ["to" "cc"] "daniel@rimspace.net"))
Thanks for explaining. I saw the example in the "Sieve Commands" node
too.
The Gnus Sieve section points to a broken link
(http://www.gnu.org/software/emacs/manual/html_node/sieve/index.html#Top).
I think that's because the Emacs Sieve mode has its own manual.
http://www.emacswiki.org/emacs/SieveMode also has some good links.
>> Do we have ManageSieve support in Gnus, and if not, can it be added?
DP> Mostly outside it, but the facilities are there. Read the Sieve manual
DP> shipped with Emacs for details. :)
Yeah, that seems sufficient. It seems like there are only a few Sieve
Gnus users, though. I wonder if it's worth supporting ManageSieve
explicitly in Gnus. Maybe it's better to concentrate on generating the
rules on the server side from distributed rules, like the Gnus registry
I mentioned.
Ted
^ 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).