Mercurial > emacs
annotate lisp/gnus/gnus-mlspl.el @ 42811:cf0c0ef57504
*** empty log message ***
| author | Jason Rumney <jasonr@gnu.org> |
|---|---|
| date | Thu, 17 Jan 2002 19:29:24 +0000 |
| parents | 647bc167565a |
| children | 52d99cc2e9e3 |
| rev | line source |
|---|---|
| 31717 | 1 ;;; gnus-mlspl.el --- a group params-based mail splitting mechanism |
|
33403
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
2 ;; Copyright (C) 1998, 1999, 2000 |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
3 ;; Free Software Foundation, Inc. |
| 31717 | 4 |
| 5 ;; Author: Alexandre Oliva <oliva@lsd.ic.unicamp.br> | |
| 6 ;; Keywords: news, mail | |
| 7 | |
| 38401 | 8 ;; This file is part of GNU Emacs. |
| 9 | |
| 10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 31717 | 11 ;; it under the terms of the GNU General Public License as published by |
| 12 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 13 ;; any later version. | |
| 14 | |
| 38401 | 15 ;; GNU Emacs is distributed in the hope that it will be useful, |
| 31717 | 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 38401 | 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 31717 | 18 ;; GNU General Public License for more details. |
| 19 | |
| 20 ;; You should have received a copy of the GNU General Public License | |
| 38401 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
| 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 31717 | 23 ;; Boston, MA 02111-1307, USA. |
| 24 | |
|
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Jan?k <Pavel@Janik.cz>
parents:
38401
diff
changeset
|
25 ;;; Commentary: |
|
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Jan?k <Pavel@Janik.cz>
parents:
38401
diff
changeset
|
26 |
|
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Jan?k <Pavel@Janik.cz>
parents:
38401
diff
changeset
|
27 ;;; Code: |
|
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Jan?k <Pavel@Janik.cz>
parents:
38401
diff
changeset
|
28 |
|
33270
93c83ac38c92
2000-11-06 John Wiegley <johnw@gnu.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
| 31717 | 30 (require 'gnus) |
| 31 (require 'gnus-sum) | |
| 32 (require 'gnus-group) | |
| 33 (require 'nnmail) | |
| 34 | |
| 35 (defvar gnus-group-split-updated-hook nil | |
|
33403
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
36 "Hook called just after nnmail-split-fancy is updated by |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
37 gnus-group-split-update.") |
| 31717 | 38 |
| 39 (defvar gnus-group-split-default-catch-all-group "mail.misc" | |
|
33403
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
40 "Group name (or arbitrary fancy split) with default splitting rules. |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
41 Used by gnus-group-split and gnus-group-split-update as a fallback |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
42 split, in case none of the group-based splits matches.") |
| 31717 | 43 |
| 44 ;;;###autoload | |
| 45 (defun gnus-group-split-setup (&optional auto-update catch-all) | |
| 46 "Set up the split for nnmail-split-fancy. | |
| 47 Sets things up so that nnmail-split-fancy is used for mail | |
| 48 splitting, and defines the variable nnmail-split-fancy according with | |
| 49 group parameters. | |
| 50 | |
| 51 If AUTO-UPDATE is non-nil (prefix argument accepted, if called | |
| 52 interactively), it makes sure nnmail-split-fancy is re-computed before | |
| 53 getting new mail, by adding gnus-group-split-update to | |
|
33403
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
54 nnmail-pre-get-new-mail-hook. |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
55 |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
56 A non-nil CATCH-ALL replaces the current value of |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
57 gnus-group-split-default-catch-all-group. This variable is only used |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
58 by gnus-group-split-update, and only when its CATCH-ALL argument is |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
59 nil. This argument may contain any fancy split, that will be added as |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
60 the last split in a `|' split produced by gnus-group-split-fancy, |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
61 unless overridden by any group marked as a catch-all group. Typical |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
62 uses are as simple as the name of a default mail group, but more |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
63 elaborate fancy splits may also be useful to split mail that doesn't |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
64 match any of the group-specified splitting rules. See |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
65 gnus-group-split-fancy for details." |
| 31717 | 66 (interactive "P") |
| 67 (setq nnmail-split-methods 'nnmail-split-fancy) | |
| 68 (when catch-all | |
| 69 (setq gnus-group-split-default-catch-all-group catch-all)) | |
| 70 (gnus-group-split-update) | |
| 71 (when auto-update | |
| 72 (add-hook 'nnmail-pre-get-new-mail-hook 'gnus-group-split-update))) | |
| 73 | |
| 74 ;;;###autoload | |
| 75 (defun gnus-group-split-update (&optional catch-all) | |
|
33403
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
76 "Computes nnmail-split-fancy from group params and CATCH-ALL, by |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
77 calling (gnus-group-split-fancy nil nil CATCH-ALL). |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
78 |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
79 If CATCH-ALL is nil, gnus-group-split-default-catch-all-group is used |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
80 instead. This variable is set by gnus-group-split-setup." |
| 31717 | 81 (interactive) |
| 82 (setq nnmail-split-fancy | |
| 83 (gnus-group-split-fancy | |
|
33270
93c83ac38c92
2000-11-06 John Wiegley <johnw@gnu.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
84 nil (null nnmail-crosspost) |
|
93c83ac38c92
2000-11-06 John Wiegley <johnw@gnu.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
85 (or catch-all gnus-group-split-default-catch-all-group))) |
| 31717 | 86 (run-hooks 'gnus-group-split-updated-hook)) |
| 87 | |
| 88 ;;;###autoload | |
| 89 (defun gnus-group-split () | |
| 90 "Uses information from group parameters in order to split mail. | |
| 91 See gnus-group-split-fancy for more information. | |
| 92 | |
| 93 gnus-group-split is a valid value for nnmail-split-methods." | |
| 94 (let (nnmail-split-fancy) | |
|
33403
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
95 (gnus-group-split-update) |
| 31717 | 96 (nnmail-split-fancy))) |
| 97 | |
| 98 ;;;###autoload | |
| 99 (defun gnus-group-split-fancy | |
| 100 (&optional groups no-crosspost catch-all) | |
|
41984
647bc167565a
(gnus-group-split-fancy): Doc fix (add reference to variable, follow
Pavel Jan?k <Pavel@Janik.cz>
parents:
38413
diff
changeset
|
101 "Uses information from group parameters in order to split mail. |
|
647bc167565a
(gnus-group-split-fancy): Doc fix (add reference to variable, follow
Pavel Jan?k <Pavel@Janik.cz>
parents:
38413
diff
changeset
|
102 It can be embedded into `nnmail-split-fancy' lists with the SPLIT |
| 31717 | 103 |
| 104 \(: gnus-group-split-fancy GROUPS NO-CROSSPOST CATCH-ALL\) | |
| 105 | |
| 106 GROUPS may be a regular expression or a list of group names, that will | |
| 107 be used to select candidate groups. If it is ommited or nil, all | |
| 108 existing groups are considered. | |
| 109 | |
| 110 if NO-CROSSPOST is ommitted or nil, a & split will be returned, | |
| 111 otherwise, a | split, that does not allow crossposting, will be | |
| 112 returned. | |
| 113 | |
| 114 For each selected group, a SPLIT is composed like this: if SPLIT-SPEC | |
| 115 is specified, this split is returned as-is (unless it is nil: in this | |
| 116 case, the group is ignored). Otherwise, if TO-ADDRESS, TO-LIST and/or | |
| 117 EXTRA-ALIASES are specified, a regexp that matches any of them is | |
| 118 constructed (extra-aliases may be a list). Additionally, if | |
| 119 SPLIT-REGEXP is specified, the regexp will be extended so that it | |
| 120 matches this regexp too, and if SPLIT-EXCLUDE is specified, RESTRICT | |
| 121 clauses will be generated. | |
| 122 | |
|
33403
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
123 If CATCH-ALL is nil, no catch-all handling is performed, regardless of |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
124 catch-all marks in group parameters. Otherwise, if there is no |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
125 selected group whose SPLIT-REGEXP matches the empty string, nor is |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
126 there a selected group whose SPLIT-SPEC is 'catch-all, this fancy |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
127 split (say, a group name) will be appended to the returned SPLIT list, |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
128 as the last element of a '| SPLIT. |
|
0ec780720bfe
2000-11-10 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Dave Love <fx@gnu.org>
parents:
33270
diff
changeset
|
129 |
| 31717 | 130 For example, given the following group parameters: |
| 131 | |
| 132 nnml:mail.bar: | |
| 133 \((to-address . \"bar@femail.com\") | |
| 134 (split-regexp . \".*@femail\\\\.com\")) | |
| 135 nnml:mail.foo: | |
| 136 \((to-list . \"foo@nowhere.gov\") | |
| 137 (extra-aliases \"foo@localhost\" \"foo-redist@home\") | |
| 138 (split-exclude \"bugs-foo\" \"rambling-foo\") | |
| 139 (admin-address . \"foo-request@nowhere.gov\")) | |
| 140 nnml:mail.others: | |
| 141 \((split-spec . catch-all)) | |
| 142 | |
| 143 Calling (gnus-group-split-fancy nil nil \"mail.misc\") returns: | |
| 144 | |
| 145 \(| (& (any \"\\\\(bar@femail\\\\.com\\\\|.*@femail\\\\.com\\\\)\" | |
| 146 \"mail.bar\") | |
| 147 (any \"\\\\(foo@nowhere\\\\.gov\\\\|foo@localhost\\\\|foo-redist@home\\\\)\" | |
| 148 - \"bugs-foo\" - \"rambling-foo\" \"mail.foo\")) | |
| 149 \"mail.others\")" | |
| 150 (let* ((newsrc (cdr gnus-newsrc-alist)) | |
| 151 split) | |
| 152 (dolist (info newsrc) | |
| 153 (let ((group (gnus-info-group info)) | |
| 154 (params (gnus-info-params info))) | |
| 155 ;; For all GROUPs that match the specified GROUPS | |
| 156 (when (or (not groups) | |
| 157 (and (listp groups) | |
| 158 (memq group groups)) | |
| 159 (and (stringp groups) | |
| 160 (string-match groups group))) | |
| 161 (let ((split-spec (assoc 'split-spec params)) group-clean) | |
| 162 ;; Remove backend from group name | |
| 163 (setq group-clean (string-match ":" group)) | |
| 164 (setq group-clean | |
| 165 (if group-clean | |
| 166 (substring group (1+ group-clean)) | |
| 167 group)) | |
| 168 (if split-spec | |
| 169 (when (setq split-spec (cdr split-spec)) | |
| 170 (if (eq split-spec 'catch-all) | |
| 171 ;; Emit catch-all only when requested | |
| 172 (when catch-all | |
| 173 (setq catch-all group-clean)) | |
| 174 ;; Append split-spec to the main split | |
| 175 (push split-spec split))) | |
| 176 ;; Let's deduce split-spec from other params | |
| 177 (let ((to-address (cdr (assoc 'to-address params))) | |
| 178 (to-list (cdr (assoc 'to-list params))) | |
| 179 (extra-aliases (cdr (assoc 'extra-aliases params))) | |
| 180 (split-regexp (cdr (assoc 'split-regexp params))) | |
| 181 (split-exclude (cdr (assoc 'split-exclude params)))) | |
| 182 (when (or to-address to-list extra-aliases split-regexp) | |
| 183 ;; regexp-quote to-address, to-list and extra-aliases | |
| 184 ;; and add them all to split-regexp | |
| 185 (setq split-regexp | |
| 186 (concat | |
| 187 "\\(" | |
| 188 (mapconcat | |
| 189 'identity | |
| 190 (append | |
| 191 (and to-address (list (regexp-quote to-address))) | |
| 192 (and to-list (list (regexp-quote to-list))) | |
| 193 (and extra-aliases | |
| 194 (if (listp extra-aliases) | |
| 195 (mapcar 'regexp-quote extra-aliases) | |
| 196 (list extra-aliases))) | |
| 197 (and split-regexp (list split-regexp))) | |
| 198 "\\|") | |
| 199 "\\)")) | |
| 200 ;; Now create the new SPLIT | |
| 201 (push (append | |
| 202 (list 'any split-regexp) | |
| 203 ;; Generate RESTRICTs for SPLIT-EXCLUDEs. | |
| 204 (if (listp split-exclude) | |
| 205 (let ((seq split-exclude) | |
| 206 res) | |
| 207 (while seq | |
| 208 (push (cons '- (pop seq)) | |
| 209 res)) | |
| 210 (apply #'nconc (nreverse res))) | |
| 211 (list '- split-exclude)) | |
| 212 (list group-clean)) | |
| 213 split) | |
| 214 ;; If it matches the empty string, it is a catch-all | |
| 215 (when (string-match split-regexp "") | |
| 216 (setq catch-all nil))))))))) | |
| 217 ;; Add catch-all if not crossposting | |
| 218 (if (and catch-all no-crosspost) | |
|
33270
93c83ac38c92
2000-11-06 John Wiegley <johnw@gnu.org>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
219 (push catch-all split)) |
| 31717 | 220 ;; Move it to the tail, while arranging that SPLITs appear in the |
| 221 ;; same order as groups. | |
| 222 (setq split (reverse split)) | |
| 223 ;; Decide whether to accept cross-postings or not. | |
| 224 (push (if no-crosspost '| '&) split) | |
| 225 ;; Even if we can cross-post, catch-all should not get | |
| 226 ;; cross-posts. | |
| 227 (if (and catch-all (not no-crosspost)) | |
| 228 (setq split (list '| split catch-all))) | |
| 229 split)) | |
| 230 | |
| 231 (provide 'gnus-mlspl) | |
|
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Jan?k <Pavel@Janik.cz>
parents:
38401
diff
changeset
|
232 |
|
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Jan?k <Pavel@Janik.cz>
parents:
38401
diff
changeset
|
233 ;;; gnus-mlspl.el ends here |
