From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/34850 Path: main.gmane.org!not-for-mail From: NAGY Andras Newsgroups: gmane.emacs.gnus.general Subject: Sieve support in Gnus, sample implementation Date: 19 Feb 2001 04:45:55 +0100 Sender: owner-ding@hpc.uh.edu Message-ID: NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1035170696 32404 80.91.224.250 (21 Oct 2002 03:24:56 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 21 Oct 2002 03:24:56 +0000 (UTC) Return-Path: Original-Received: from karazm.math.uh.edu (karazm.math.uh.edu [129.7.128.1]) by mailhost.sclp.com (Postfix) with ESMTP id B71B4D049E for ; Mon, 19 Feb 2001 09:57:12 -0500 (EST) Original-Received: from sina.hpc.uh.edu (lists@Sina.HPC.UH.EDU [129.7.3.5]) by karazm.math.uh.edu (8.9.3/8.9.3) with ESMTP id IAC13206; Mon, 19 Feb 2001 08:56:48 -0600 (CST) Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Mon, 19 Feb 2001 08:55:36 -0600 (CST) Original-Received: from mailhost.sclp.com (postfix@66-209.196.61.interliant.com [209.196.61.66] (may be forged)) by sina.hpc.uh.edu (8.9.3/8.9.3) with ESMTP id IAA10437 for ; Mon, 19 Feb 2001 08:55:26 -0600 (CST) Original-Received: from mail.inf.elte.hu (mail.inf.elte.hu [157.181.161.6]) by mailhost.sclp.com (Postfix) with ESMTP id EE49BD049E for ; Mon, 19 Feb 2001 09:55:19 -0500 (EST) Original-Received: by mail.inf.elte.hu (Postfix, from userid 28535) id 5A430800D; Mon, 19 Feb 2001 04:45:55 +0100 (NFT) Original-To: ding@gnus.org Mail-Copies-To: nobody User-Agent: Gnus/5.090001 (Oort Gnus v0.01) XEmacs/21.1 (Biscayne) Precedence: list X-Majordomo: 1.94.jlt7 Original-Lines: 68 Xref: main.gmane.org gmane.emacs.gnus.general:34850 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:34850 --=-=-= Gnus has a nice feature, splitting (and fancy splitting), for sorting incoming mail to folders on the client side. Furthermore, Gnus has another feature, group mail splitting, which allows the user to store splitting info in group paramteres, that is, keep everything related to a particular mailing list (splitting rules, to-address, admin address, comments, styles etc) in one place. Sieve is a mail filtering language, available on certain IMAP servers, and enables server side mail filtering. Sieve's server side sorting is more efficient than Gnus' client side, but the user has to maintain a separate sieve script in addition to the other group paramteres. So why not combine these two things, and let Gnus auto-generate a Sieve script, based on group paramters? Why not, indeed. :) Below is a quick hack (no concepts, docs or whatever) demonstrating a possible implementation. This allows you to write things like (sieve address "sender" "owner-ding@hpc.uh.edu") or (sieve anyof ( (address "sender" ("quux@bar.com" "boss@bar.com") (size :over 12K)))) among group parameters, and integrate them into your sieve script, resulting in: if anyof (address "sender" ["quux@bar.com", "boss@bar.com"] ) { fileinto "INBOX.mail.bar"; } elsif address "sender" "owner-ding@hpc.uh.edu" { fileinto "INBOX.list.ding"; } Usage: create an empty, or modify your existing script to look like: ---> require "fileinto"; front of your script ## Begin Gnus Sieve Script # i think two newlines are needed here ## End Gnus Sieve Script rest of your script <--- Define group paramters, and do an M-x sieve-update, then upload your script. Opinions, suggestions (both technical and conceptual), patches etc are welcome. BTW, any ideas why lines 55-56 (commented out) not working? Andras --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=sieve.el ;; sieve.el ;; Copyright NAGY Andras (defun sieve-string-list (list) (concat "[\"" (mapconcat 'identity list "\", \"") "\"]")) (defun sieve-test-list (list) (concat "(" (mapconcat 'sieve-test list ", ") ")")) (defun sieve-test-word (word) (cond ((symbolp word) (symbol-name word)) ((stringp word) (concat "\"" word "\"")) ((and (listp word) (stringp (car word))) (sieve-string-list word)) ((and (listp word) (listp (car word))) (sieve-test-list word)))) (defun sieve-test (test) (mapconcat 'sieve-test-word test " ")) (defun sieve-script (&optional method crosspost) (let* ((newsrc (cdr gnus-newsrc-alist)) script) (dolist (info newsrc) (when (or (not method) (equal (gnus-info-method info) method)) (let* ((group (gnus-info-group info)) (spec (gnus-group-find-parameter group 'sieve t))) (when spec (push (concat "if " (sieve-test spec) " {\n\t" "fileinto \"" (gnus-group-real-name group) "\";\n}") script))))) (mapconcat 'identity script (if crosspost "\n" "\nels")))) (defconst sieve-region-start "\n## Begin Gnus Sieve Script\n") (defconst sieve-region-end "\n## End Gnus Sieve Script\n") (defun sieve-update (file) (interactive "fSieve script: ") (find-file file) (beginning-of-buffer) (re-search-forward (concat (regexp-quote sieve-region-start) "\\(.\\|\n\\)*" (regexp-quote sieve-region-end))) ;;(replace-match ;; (concat sieve-region-start (sieve-script) sieve-region-end) t t) (delete-region (match-beginning 0) (match-end 0)) (insert-string (concat sieve-region-start (sieve-script) sieve-region-end)) (save-buffer)) (provide 'sieve) --=-=-=--