From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/23553 Path: main.gmane.org!not-for-mail From: Alexandre Oliva Newsgroups: gmane.emacs.gnus.general Subject: Using to-(address|list) group params for mail splitting Date: 25 Jun 1999 07:51:43 -0300 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 1035161265 2636 80.91.224.250 (21 Oct 2002 00:47:45 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 21 Oct 2002 00:47:45 +0000 (UTC) Return-Path: Original-Received: from farabi.math.uh.edu (farabi.math.uh.edu [129.7.128.57]) by sclp3.sclp.com (8.8.5/8.8.5) with ESMTP id GAA10336 for ; Fri, 25 Jun 1999 06:53:05 -0400 (EDT) Original-Received: from sina.hpc.uh.edu (lists@Sina.HPC.UH.EDU [129.7.3.5]) by farabi.math.uh.edu (8.9.1/8.9.1) with ESMTP id FAB06501; Fri, 25 Jun 1999 05:52:35 -0500 (CDT) Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Fri, 25 Jun 1999 05:53:06 -0500 (CDT) Original-Received: from sclp3.sclp.com (root@sclp3.sclp.com [204.252.123.139]) by sina.hpc.uh.edu (8.9.3/8.9.3) with ESMTP id FAA28205 for ; Fri, 25 Jun 1999 05:52:55 -0500 (CDT) Original-Received: from grande.dcc.unicamp.br (grande.dcc.unicamp.br [143.106.1.11]) by sclp3.sclp.com (8.8.5/8.8.5) with ESMTP id GAA10322 for ; Fri, 25 Jun 1999 06:51:55 -0400 (EDT) Original-Received: from amazonas.dcc.unicamp.br (amazonas.dcc.unicamp.br [143.106.7.11]) by grande.dcc.unicamp.br (8.9.1/8.9.1) with ESMTP id HAA28934 for ; Fri, 25 Jun 1999 07:48:04 -0300 (EST) Original-Received: from saci.lsd.dcc.unicamp.br (oliva@saci.lsd.dcc.unicamp.br [143.106.23.3]) by amazonas.dcc.unicamp.br (8.8.5/8.8.5) with SMTP id HAA20424 for ; Fri, 25 Jun 1999 07:48:03 -0300 (EST) Original-To: ding@gnus.org Original-Lines: 16 User-Agent: Gnus/5.070088 (Pterodactyl Gnus v0.88) XEmacs/20.4 (Emerald) Precedence: list X-Majordomo: 1.94.jlt7 Xref: main.gmane.org gmane.emacs.gnus.general:23553 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:23553 --=-=-= Here's a bit of emacs-lisp I wrote to help me reduce the redundancy between to-list in group-params and the definition of nnmail-split-fancy: the latter is derived from the former. There's also a lot of fancy stuff if you need more complex rules. Lars, I believe this could go into gnus now that I've got an assignment to FSF on file. If you agree with it, I'll write something for the texinfo docs, and post it as a separate patch. -- Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il {oliva,Alexandre.Oliva}@dcc.unicamp.br aoliva@{acm.org,computer.org} oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org} *** E-mail about software projects will be forwarded to mailing lists --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=split-params.el Content-Transfer-Encoding: 8bit ;;; split-params.el --- a group-params-based mail splitting mechanism for gnus ;; Copyright (C) 1998,1999 Free Software Foundation, Inc. ;; Author: Alexandre Oliva ;; Keywords: news, mail ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. (require 'gnus) (require 'gnus-sum) (require 'gnus-group) (require 'nnmail) (defvar nnmail-updated-split-from-group-params-hook nil "Hook called just after nnmail-split-fancy is updated by nnmail-update-split-from-group-params") (defvar nnmail-default-catch-all-group "mail.misc" "Group used by nnmail-split-from-group-params and nnmail-update-split-from-group-params as default catch-all group") (defun nnmail-setup-split-from-group-params (&optional auto-update catch-all) "Sets things up so that nnmail-split-fancy is used for mail splitting, and defines the variable nnmail-split-fancy according with group parameters. if AUTO-UPDATE is non-nil (prefix argument accepted, if called interactive), makes sure nnmail-split-fancy is re-computed before getting new mail, by adding nnmail-update-split-from-group-params to nnmail-pre-get-new-mail-hook." (interactive "P") (setq nnmail-split-methods 'nnmail-split-fancy) (when catch-all (setq nnmail-default-catch-all-group catch-all)) (nnmail-update-split-from-group-params) (when auto-update (add-hook 'nnmail-pre-get-new-mail-hook 'nnmail-update-split-from-group-params))) (defun nnmail-update-split-from-group-params (&optional catch-all) "Computes nnmail-split-fancy from group params, by calling \(nnmail-split-fancy-from-group-params nil nil DEFAULTGROUP)" (interactive) (setq nnmail-split-fancy (nnmail-split-fancy-from-group-params nil nil (or catch-all nnmail-default-catch-all-group))) (run-hooks 'nnmail-updated-split-fancy-hook) ) (defun nnmail-split-from-group-params () "Uses information from group parameters in order to split mail. See nnmail-split-fancy-from-group-params for more information. If no group is defined as catch-all, the value of nnmail-default-catch-all-group is used. nnmail-split-from-group-params is a valid value for nnmail-split-methods." (let (nnmail-split-fancy) (nnmail-update-split-from-group-params nnmail-default-catch-all-group) (nnmail-split-fancy))) (defun nnmail-split-fancy-from-group-params (&optional groups no-crosspost catch-all) "Uses information from group parameters in order to split mail. It can be embedded into nnmail-split-fancy lists with the SPLIT \(: nnmail-split-fancy-from-group-params GROUPS NO-CROSSPOST CATCH-ALL\) GROUPS may be a regular expression or a list of group names, that will be used to select candidate groups. If it is ommited or nil, all existing groups are considered. if NO-CROSSPOST is ommitted or nil, a & split will be returned, otherwise, a | split, that does not allow crossposting, will be returned. if CATCH-ALL is not nil, and there is no selected group whose split-regexp matches the empty string, nor is there a selected group whose SPLIT-SPEC is 'catch-all, this group name will be appended to the returned SPLIT list, as the last element in a '| SPLIT. For each selected group, a SPLIT is composed like this: if split-spec is specified, this split is returned as-is (unless it is nil: in this case, the group is ignored). Otherwise, if TO-ADDRESS, TO-LIST and/or EXTRA-ALIASES are specified, a regexp that matches any of them is constructed (extra-aliases may be a list). Additionally, if SPLIT-REGEXP is specified, the regexp will be extended so that it matches this regexp too, and if SPLIT-EXCLUDE is specified, RESTRICT clauses will be generated. For example, given the following group parameters: nnml:mail.bar: \((to-address . \"bar@femail.com\") (split-regexp . \".*@femail\\\\.com\")) nnml:mail.foo: \((to-list . \"foo@nowhere.gov\") (extra-aliases \"foo@localhost\" \"foo-redist@home\") (split-exclude \"bugs-foo\" \"rambling-foo\") (admin-address . \"foo-request@nowhere.gov\")) nnml:mail.others: \((split-spec . catch-all)) Calling (nnmail-split-fancy-from-group-params nil nil \"mail.misc\") returns: \(| (& (any \"\\\\(bar@femail\\\\.com\\\\|.*@femail\\\\.com\\\\)\" \"nnml:mail.bar\") (any \"\\\\(foo@nowhere\\\\.gov\\\\|foo@localhost\\\\|foo-redist@home\\\\)\" - \"bugs-foo\" - \"rambling-foo\" \"nnml:mail.foo\")) \"nnml:mail.others\")" (let* ((newsrc (cdr gnus-newsrc-alist)) split) (dolist (info newsrc) (let ((group (gnus-info-group info)) (params (gnus-info-params info))) ;; For all GROUPs that match the specified GROUPS (when (or (not groups) (and (listp groups) (memq group groups)) (and (stringp groups) (string-match groups group))) (let ((split-spec (cdr (assoc 'split-spec params))) group-clean) ;; Remove backend from group name (setq group-clean (string-match ":" group)) (setq group-clean (if group-clean (substring group (1+ group-clean)) group)) (if split-spec (if (eq split-spec 'catch-all) ;; Emit catch-all only when requested (when catch-all (setq catch-all group-clean)) ;; Append split-spec to the main split (push split-spec split)) ;; Let's deduce split-spec from other params (let ((to-address (cdr (assoc 'to-address params))) (to-list (cdr (assoc 'to-list params))) (extra-aliases (cdr (assoc 'extra-aliases params))) (split-regexp (cdr (assoc 'split-regexp params))) (split-exclude (cdr (assoc 'split-exclude params)))) (when (or to-address to-list extra-aliases split-regexp) ;; regexp-quote to-address, to-list and extra-aliases ;; and add them all to split-regexp (setq split-regexp (concat "\\(" (mapconcat 'identity (append (and to-address (list (regexp-quote to-address))) (and to-list (list (regexp-quote to-list))) (and extra-aliases (if (listp extra-aliases) (mapcar 'regexp-quote extra-aliases) (list extra-aliases))) (and split-regexp (list split-regexp))) "\\|") "\\)")) ;; Now create the new SPLIT (push (append (list 'any split-regexp) ;; Generate RESTRICTs for SPLIT-EXCLUDEs. (if (listp split-exclude) (mapcon (lambda (arg) (cons '- arg)) split-exclude) (list '- split-exclude)) (list group-clean)) split) ;; If it matches the empty string, it is a catch-all (when (string-match split-regexp "") (setq catch-all nil))))))))) ;; Add catch-all if not crossposting (if (and catch-all no-crosspost) (push split catch-all)) ;; Move it to the tail, while arranging that SPLITs appear in the ;; same order as groups. (setq split (reverse split)) ;; Decide whether to accept cross-postings or not. (push (if no-crosspost '| '&) split) ;; Even if we can cross-post, catch-all should not get ;; cross-posts. (if (and catch-all (not no-crosspost)) (setq split (list '| split catch-all))) split)) (provide 'split-params) --=-=-=--