From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/8588 Path: main.gmane.org!not-for-mail From: Mark Eichin Newsgroups: gmane.emacs.gnus.general Subject: extensions to nnmail-split-fancy Date: 04 Nov 1996 15:32:49 -0500 Sender: eichin@cygnus.com Message-ID: NNTP-Posting-Host: coloc-standby.netfonds.no X-Trace: main.gmane.org 1035148733 13041 80.91.224.250 (20 Oct 2002 21:18:53 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 20 Oct 2002 21:18:53 +0000 (UTC) Cc: gsstark@MIT.EDU, raeburn@cygnus.com Return-Path: Original-Received: (qmail 30223 invoked from smtpd); 4 Nov 1996 20:49:34 -0000 Original-Received: from ifi.uio.no (0@129.240.64.2) by deanna.miranova.com with SMTP; 4 Nov 1996 20:49:32 -0000 Original-Received: from cygnus.com (cygnus.com [140.174.1.1]) by ifi.uio.no with ESMTP (8.6.11/ifi2.4) id for ; Mon, 4 Nov 1996 21:33:19 +0100 Original-Received: from tweedledumb.cygnus.com (tweedledumb.cygnus.com [192.80.44.1]) by cygnus.com (8.6.12/8.6.9) with SMTP id MAA06848; Mon, 4 Nov 1996 12:32:59 -0800 Original-Received: from maneki-neko.cygnus.com by tweedledumb.cygnus.com (4.1/4.7) id AA12521; Mon, 4 Nov 96 15:32:50 EST Original-Received: (from eichin@localhost) by maneki-neko.cygnus.com (8.7.6/8.7.3) id PAA21933; Mon, 4 Nov 1996 15:32:50 -0500 Original-To: ding@ifi.uio.no Original-Lines: 79 X-Mailer: Gnus v5.2.39/Emacs 19.34 Xref: main.gmane.org gmane.emacs.gnus.general:8588 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:8588 I wanted to be able to do a split of the form: (any "debian-\\(\\w*\\)@lists.debian.org" "mail.debian.\\1") [actually I use X-Mailing-List, so I seperate out personals and list copies, but that's not important here.] I've kludged something together, but thought I'd ask for improvements and suggestsions on how to do it "right"... The kludge part: it *only* handles \1, I'm not sure if there's a generic interface to that kind of substitution that works on strings instead of buffers. Also, it "knows" that this is really match-string 3, with 1=the header line, 2=the whole pattern (from the ^\(\) wrapping) so 3 is anything extra. It would seem that a *much* more general extension would be to allow arbitrary functions in a split, but lacking functionp it would need to use something like eq car lambda/function/byte-foo and that wouldn't be fun. (Or perhaps just grab another special character, like & | are now, and have it mean eval? hmm.) But that wouldn't make the above that much easier, just possible... _Mark_ Cygnus Support, Eastern USA ps. the nnmail-split-it below is from 5.2.39, where I last stopped keeping up :-) (defun mwegnus-subst-1 (str repl1) (let ( (strind (string-match "\\\\1$" str)) ) (if strind (concat (substring str 0 strind) repl1) str))) (defun nnmail-split-it (split) ;; Return a list of groups matching SPLIT. (cond ((stringp split) ;; A group. (list split)) ((eq (car split) '&) (apply 'nconc (mapcar 'nnmail-split-it (cdr split)))) ((eq (car split) '|) (let (done) (while (and (not done) (cdr split)) (setq split (cdr split) done (nnmail-split-it (car split)))) done)) ((assq split nnmail-split-cache) ;; A compiled match expression. (goto-char (point-max)) (if (re-search-backward (cdr (assq split nnmail-split-cache)) nil t) (nnmail-split-it ;; change 1 (if (stringp (nth 2 split)) (mwegnus-subst-1 (nth 2 split) (match-string 3)) (nth 2 split))))) (t ;; An uncompiled match. (let* ((field (nth 0 split)) (value (nth 1 split)) (result (nth 2 split)) ;; change 2a (regexp (concat "^\\(" (if (symbolp field) (cdr (assq field nnmail-split-abbrev-alist)) field) "\\):.*\\<\\(" (if (symbolp value) (cdr (assq value nnmail-split-abbrev-alist)) value) "\\)\\>"))) (setq nnmail-split-cache (cons (cons split regexp) nnmail-split-cache)) (goto-char (point-max)) (if (re-search-backward regexp nil t) (nnmail-split-it ;; change 2b (if (stringp result) (mwegnus-subst-1 result (match-string 3)) result) ))))))