Gnus development mailing list
 help / color / mirror / Atom feed
From: Mark Eichin <eichin@cygnus.com>
Cc: gsstark@MIT.EDU, raeburn@cygnus.com
Subject: extensions to nnmail-split-fancy
Date: 04 Nov 1996 15:32:49 -0500	[thread overview]
Message-ID: <xe1viblzjm6.fsf@maneki-neko.cygnus.com> (raw)

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_ <eichin@cygnus.com>
					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)
		))))))


             reply	other threads:[~1996-11-04 20:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-04 20:32 Mark Eichin [this message]
1996-11-05 21:39 ` David Moore
1996-11-05 23:11   ` Mark Eichin

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=xe1viblzjm6.fsf@maneki-neko.cygnus.com \
    --to=eichin@cygnus.com \
    --cc=gsstark@MIT.EDU \
    --cc=raeburn@cygnus.com \
    /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).