Gnus development mailing list
 help / color / mirror / Atom feed
* extensions to nnmail-split-fancy
@ 1996-11-04 20:32 Mark Eichin
  1996-11-05 21:39 ` David Moore
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Eichin @ 1996-11-04 20:32 UTC (permalink / raw)
  Cc: gsstark, raeburn

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)
		))))))


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-11-05 23:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-04 20:32 extensions to nnmail-split-fancy Mark Eichin
1996-11-05 21:39 ` David Moore
1996-11-05 23:11   ` Mark Eichin

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).