2000-11-12 23:36:45 ShengHuo ZHU <zsh@cs.rochester.edu>
[gnus] / lisp / gnus-msg.el
1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;;      Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile (require 'cl))
31
32 (require 'gnus)
33 (require 'gnus-ems)
34 (require 'message)
35 (require 'gnus-art)
36
37 (defcustom gnus-post-method 'current
38   "*Preferred method for posting USENET news.
39
40 If this variable is `current', Gnus will use the \"current\" select
41 method when posting.  If it is nil (which is the default), Gnus will
42 use the native select method when posting.
43
44 This method will not be used in mail groups and the like, only in
45 \"real\" newsgroups.
46
47 If not nil nor `native', the value must be a valid method as discussed
48 in the documentation of `gnus-select-method'.  It can also be a list of
49 methods.  If that is the case, the user will be queried for what select
50 method to use when posting."
51   :group 'gnus-group-foreign
52   :type `(choice (const nil)
53                  (const current)
54                  (const native)
55                  (sexp :tag "Methods" ,gnus-select-method)))
56
57 (defvar gnus-outgoing-message-group nil
58   "*All outgoing messages will be put in this group.
59 If you want to store all your outgoing mail and articles in the group
60 \"nnml:archive\", you set this variable to that value.  This variable
61 can also be a list of group names.
62
63 If you want to have greater control over what group to put each
64 message in, you can set this variable to a function that checks the
65 current newsgroup name and then returns a suitable group name (or list
66 of names).")
67
68 (defvar gnus-mailing-list-groups nil
69   "*Regexp matching groups that are really mailing lists.
70 This is useful when you're reading a mailing list that has been
71 gatewayed to a newsgroup, and you want to followup to an article in
72 the group.")
73
74 (defvar gnus-add-to-list nil
75   "*If non-nil, add a `to-list' parameter automatically.")
76
77 (defvar gnus-crosspost-complaint
78   "Hi,
79
80 You posted the article below with the following Newsgroups header:
81
82 Newsgroups: %s
83
84 The %s group, at least, was an inappropriate recipient
85 of this message.  Please trim your Newsgroups header to exclude this
86 group before posting in the future.
87
88 Thank you.
89
90 "
91   "Format string to be inserted when complaining about crossposts.
92 The first %s will be replaced by the Newsgroups header;
93 the second with the current group name.")
94
95 (defvar gnus-message-setup-hook nil
96   "Hook run after setting up a message buffer.")
97
98 (defvar gnus-bug-create-help-buffer t
99   "*Should we create the *Gnus Help Bug* buffer?")
100
101 (defvar gnus-posting-styles nil
102   "*Alist of styles to use when posting.")
103
104 (defvar gnus-inews-mark-gcc-as-read nil
105   "If non-nil, automatically mark Gcc articles as read.")
106
107 (defcustom gnus-group-posting-charset-alist
108   '(("^\\(no\\|fr\\|dk\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\|dk\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
109     ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
110     (message-this-is-mail nil nil)
111     (message-this-is-news nil t))
112   "Alist of regexps and permitted unencoded charsets for posting.
113 Each element of the alist has the form (TEST HEADER BODY-LIST), where
114 TEST is either a regular expression matching the newsgroup header or a
115 variable to query,
116 HEADER is the charset which may be left unencoded in the header (nil
117 means encode all charsets),
118 BODY-LIST is a list of charsets which may be encoded using 8bit
119 content-transfer encoding in the body, or one of the special values
120 nil (always encode using quoted-printable) or t (always use 8bit).
121
122 Note that any value other than nil for HEADER infringes some RFCs, so
123 use this option with care."
124   :type '(repeat (list :tag "Permitted unencoded charsets"
125                   (choice :tag "Where"
126                    (regexp :tag "Group")
127                    (const :tag "Mail message" :value message-this-is-mail)
128                    (const :tag "News article" :value message-this-is-news))
129                   (choice :tag "Header"
130                    (const :tag "None" nil)
131                    (symbol :tag "Charset"))
132                   (choice :tag "Body"
133                           (const :tag "Any" :value t)
134                           (const :tag "None" :value nil)
135                           (repeat :tag "Charsets"
136                                   (symbol :tag "Charset")))))
137   :group 'gnus-charset)
138
139 ;;; Internal variables.
140
141 (defvar gnus-inhibit-posting-styles nil
142   "Inhibit the use of posting styles.")
143
144 (defvar gnus-message-buffer "*Mail Gnus*")
145 (defvar gnus-article-copy nil)
146 (defvar gnus-last-posting-server nil)
147 (defvar gnus-message-group-art nil)
148
149 (defconst gnus-bug-message
150   "Sending a bug report to the Gnus Towers.
151 ========================================
152
153 The buffer below is a mail buffer.  When you press `C-c C-c', it will
154 be sent to the Gnus Bug Exterminators.
155
156 The thing near the bottom of the buffer is how the environment
157 settings will be included in the mail.  Please do not delete that.
158 They will tell the Bug People what your environment is, so that it
159 will be easier to locate the bugs.
160
161 If you have found a bug that makes Emacs go \"beep\", set
162 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
163 and include the backtrace in your bug report.
164
165 Please describe the bug in annoying, painstaking detail.
166
167 Thank you for your help in stamping out bugs.
168 ")
169
170 (eval-and-compile
171   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
172   (autoload 'news-setup "rnewspost")
173   (autoload 'news-reply-mode "rnewspost")
174   (autoload 'rmail-dont-reply-to "mail-utils")
175   (autoload 'rmail-output "rmailout"))
176
177 \f
178 ;;;
179 ;;; Gnus Posting Functions
180 ;;;
181
182 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
183   "p" gnus-summary-post-news
184   "f" gnus-summary-followup
185   "F" gnus-summary-followup-with-original
186   "c" gnus-summary-cancel-article
187   "s" gnus-summary-supersede-article
188   "r" gnus-summary-reply
189   "y" gnus-summary-yank-message
190   "R" gnus-summary-reply-with-original
191   "w" gnus-summary-wide-reply
192   "W" gnus-summary-wide-reply-with-original
193   "n" gnus-summary-followup-to-mail
194   "N" gnus-summary-followup-to-mail-with-original
195   "m" gnus-summary-mail-other-window
196   "u" gnus-uu-post-news
197   "\M-c" gnus-summary-mail-crosspost-complaint
198   "om" gnus-summary-mail-forward
199   "op" gnus-summary-post-forward
200   "Om" gnus-uu-digest-mail-forward
201   "Op" gnus-uu-digest-post-forward)
202
203 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
204   "b" gnus-summary-resend-bounced-mail
205   ;; "c" gnus-summary-send-draft
206   "r" gnus-summary-resend-message)
207
208 ;;; Internal functions.
209
210 (defvar gnus-article-reply nil)
211 (defmacro gnus-setup-message (config &rest forms)
212   (let ((winconf (make-symbol "gnus-setup-message-winconf"))
213         (buffer (make-symbol "gnus-setup-message-buffer"))
214         (article (make-symbol "gnus-setup-message-article"))
215         (group (make-symbol "gnus-setup-message-group")))
216     `(let ((,winconf (current-window-configuration))
217            (,buffer (buffer-name (current-buffer)))
218            (,article (and gnus-article-reply (gnus-summary-article-number)))
219            (,group gnus-newsgroup-name)
220            (message-header-setup-hook
221             (copy-sequence message-header-setup-hook))
222            (mbl mml-buffer-list)
223            (message-mode-hook (copy-sequence message-mode-hook)))
224        (setq mml-buffer-list nil)
225        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
226        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
227        (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
228        (unwind-protect
229            (progn
230              ,@forms)
231          (gnus-inews-add-send-actions ,winconf ,buffer ,article)
232          (setq gnus-message-buffer (current-buffer))
233          (set (make-local-variable 'gnus-message-group-art)
234               (cons ,group ,article))
235          (set (make-local-variable 'gnus-newsgroup-name) ,group)
236          (gnus-run-hooks 'gnus-message-setup-hook)
237          (if (eq major-mode 'message-mode)
238              (let ((mbl1 mml-buffer-list))
239                (setq mml-buffer-list mbl)  ;; Global value
240                (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
241                (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
242            (mml-destroy-buffers)
243            (setq mml-buffer-list mbl)))
244        (gnus-add-buffer)
245        (gnus-configure-windows ,config t)
246        (set-buffer-modified-p nil))))
247
248 ;;;###autoload
249 (defun gnus-msg-mail (&rest args)
250   "Start editing a mail message to be sent.
251 Like `message-mail', but with Gnus paraphernalia, particularly the
252 the Gcc: header for archiving purposes."
253   (interactive)
254   (gnus-setup-message 'message
255     (apply 'message-mail args)))
256
257 ;;;###autoload
258 (define-mail-user-agent 'gnus-user-agent
259       'gnus-msg-mail 'message-send-and-exit
260       'message-kill-buffer 'message-send-hook)
261
262 (defun gnus-setup-posting-charset (group)
263   (let ((alist gnus-group-posting-charset-alist)
264         (group (or group ""))
265         elem)
266     (when group
267       (catch 'found
268         (while (setq elem (pop alist))
269           (when (or (and (stringp (car elem))
270                          (string-match (car elem) group))
271                     (and (gnus-functionp (car elem))
272                          (funcall (car elem) group))
273                     (and (symbolp (car elem))
274                          (symbol-value (car elem))))
275             (throw 'found (cons (cadr elem) (caddr elem)))))))))
276
277 (defun gnus-inews-add-send-actions (winconf buffer article)
278   (make-local-hook 'message-sent-hook)
279   (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
280                                  'gnus-inews-do-gcc) nil t)
281   (when gnus-agent
282     (make-local-hook 'message-header-hook)
283     (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
284   (setq message-post-method
285         `(lambda (arg)
286            (gnus-post-method arg ,gnus-newsgroup-name)))
287   (setq message-newsreader (setq message-mailer (gnus-extended-version)))
288   (message-add-action
289    `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
290   (message-add-action
291    `(when (gnus-buffer-exists-p ,buffer)
292       (save-excursion
293         (set-buffer ,buffer)
294         ,(when article
295            `(gnus-summary-mark-article-as-replied ,article))))
296    'send))
297
298 (put 'gnus-setup-message 'lisp-indent-function 1)
299 (put 'gnus-setup-message 'edebug-form-spec '(form body))
300
301 ;;; Post news commands of Gnus group mode and summary mode
302
303 (defun gnus-group-mail (&optional arg)
304   "Start composing a mail.
305 If ARG, use the group under the point to find a posting style.
306 If ARG is 1, prompt for a group name to find the posting style."
307   (interactive "P")
308   ;; We can't `let' gnus-newsgroup-name here, since that leads
309   ;; to local variables leaking.
310   (let ((group gnus-newsgroup-name)
311         (buffer (current-buffer)))
312     (unwind-protect
313         (progn
314           (setq gnus-newsgroup-name
315                 (if arg
316                     (if (= 1 (prefix-numeric-value arg))
317                         (completing-read "Use posting style of group: "
318                                          gnus-active-hashtb nil
319                                          (gnus-read-active-file-p))
320                       (gnus-group-group-name))
321                   ""))
322           (gnus-setup-message 'message (message-mail)))
323       (save-excursion
324         (set-buffer buffer)
325         (setq gnus-newsgroup-name group)))))
326
327 (defun gnus-group-post-news (&optional arg)
328   "Start composing a news message.
329 If ARG, post to the group under point.
330 If ARG is 1, prompt for a group name."
331   (interactive "P")
332   ;; Bind this variable here to make message mode hooks work ok.
333   (let ((gnus-newsgroup-name
334          (if arg
335              (if (= 1 (prefix-numeric-value arg))
336                  (completing-read "Newsgroup: " gnus-active-hashtb nil
337                                   (gnus-read-active-file-p))
338                (gnus-group-group-name))
339            "")))
340     (gnus-post-news 'post gnus-newsgroup-name)))
341
342 (defun gnus-summary-post-news ()
343   "Start composing a news message."
344   (interactive)
345   (gnus-post-news 'post gnus-newsgroup-name))
346
347 (defun gnus-summary-followup (yank &optional force-news)
348   "Compose a followup to an article.
349 If prefix argument YANK is non-nil, original article is yanked automatically."
350   (interactive
351    (list (and current-prefix-arg
352               (gnus-summary-work-articles 1))))
353   (when yank
354     (gnus-summary-goto-subject (car yank)))
355   (save-window-excursion
356     (gnus-summary-select-article))
357   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
358         (gnus-newsgroup-name gnus-newsgroup-name))
359     ;; Send a followup.
360     (gnus-post-news nil gnus-newsgroup-name
361                     headers gnus-article-buffer
362                     yank nil force-news)))
363
364 (defun gnus-summary-followup-with-original (n &optional force-news)
365   "Compose a followup to an article and include the original article."
366   (interactive "P")
367   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
368
369 (defun gnus-summary-followup-to-mail (&optional arg)
370   "Followup to the current mail message via news."
371   (interactive
372    (list (and current-prefix-arg
373               (gnus-summary-work-articles 1))))
374   (gnus-summary-followup arg t))
375
376 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
377   "Followup to the current mail message via news."
378   (interactive "P")
379   (gnus-summary-followup (gnus-summary-work-articles arg) t))
380
381 (defun gnus-inews-yank-articles (articles)
382   (let (beg article)
383     (message-goto-body)
384     (while (setq article (pop articles))
385       (save-window-excursion
386         (set-buffer gnus-summary-buffer)
387         (gnus-summary-select-article nil nil nil article)
388         (gnus-summary-remove-process-mark article))
389       (gnus-copy-article-buffer)
390       (let ((message-reply-buffer gnus-article-copy)
391             (message-reply-headers gnus-current-headers))
392         (message-yank-original)
393         (setq beg (or beg (mark t))))
394       (when articles
395         (insert "\n")))
396     (push-mark)
397     (goto-char beg)))
398
399 (defun gnus-summary-cancel-article (&optional n symp)
400   "Cancel an article you posted.
401 Uses the process-prefix convention.  If given the symbolic
402 prefix `a', cancel using the standard posting method; if not
403 post using the current select method."
404   (interactive (gnus-interactive "P\ny"))
405   (let ((articles (gnus-summary-work-articles n))
406         (message-post-method
407          `(lambda (arg)
408             (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
409         article)
410     (while (setq article (pop articles))
411       (when (gnus-summary-select-article t nil nil article)
412         (when (gnus-eval-in-buffer-window gnus-original-article-buffer
413                 (message-cancel-news))
414           (gnus-summary-mark-as-read article gnus-canceled-mark)
415           (gnus-cache-remove-article 1))
416         (gnus-article-hide-headers-if-wanted))
417       (gnus-summary-remove-process-mark article))))
418
419 (defun gnus-summary-supersede-article ()
420   "Compose an article that will supersede a previous article.
421 This is done simply by taking the old article and adding a Supersedes
422 header line with the old Message-ID."
423   (interactive)
424   (let ((article (gnus-summary-article-number)))
425     (gnus-setup-message 'reply-yank
426       (gnus-summary-select-article t)
427       (set-buffer gnus-original-article-buffer)
428       (message-supersede)
429       (push
430        `((lambda ()
431            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
432              (save-excursion
433                (set-buffer ,gnus-summary-buffer)
434                (gnus-cache-possibly-remove-article ,article nil nil nil t)
435                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
436        message-send-actions))))
437
438 \f
439
440 (defun gnus-copy-article-buffer (&optional article-buffer)
441   ;; make a copy of the article buffer with all text properties removed
442   ;; this copy is in the buffer gnus-article-copy.
443   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
444   ;; this buffer should be passed to all mail/news reply/post routines.
445   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
446   (save-excursion
447     (set-buffer gnus-article-copy)
448     (mm-enable-multibyte))
449   (let ((article-buffer (or article-buffer gnus-article-buffer))
450         end beg)
451     (if (not (and (get-buffer article-buffer)
452                   (gnus-buffer-exists-p article-buffer)))
453         (error "Can't find any article buffer")
454       (save-excursion
455         (set-buffer article-buffer)
456         (let ((gnus-newsgroup-charset (or gnus-article-charset
457                                           gnus-newsgroup-charset))
458               (gnus-newsgroup-ignored-charsets 
459                (or gnus-article-ignored-charsets
460                    gnus-newsgroup-ignored-charsets)))
461           (save-restriction
462             ;; Copy over the (displayed) article buffer, delete
463             ;; hidden text and remove text properties.
464             (widen)
465             (copy-to-buffer gnus-article-copy (point-min) (point-max))
466             (set-buffer gnus-article-copy)
467             (gnus-article-delete-text-of-type 'annotation)
468             (gnus-remove-text-with-property 'gnus-prev)
469             (gnus-remove-text-with-property 'gnus-next)
470             (insert
471              (prog1
472                  (buffer-substring-no-properties (point-min) (point-max))
473                (erase-buffer)))
474             ;; Find the original headers.
475             (set-buffer gnus-original-article-buffer)
476             (goto-char (point-min))
477             (while (looking-at message-unix-mail-delimiter)
478               (forward-line 1))
479             (setq beg (point))
480             (setq end (or (search-forward "\n\n" nil t) (point)))
481             ;; Delete the headers from the displayed articles.
482             (set-buffer gnus-article-copy)
483             (delete-region (goto-char (point-min))
484                            (or (search-forward "\n\n" nil t) (point-max)))
485             ;; Insert the original article headers.
486             (insert-buffer-substring gnus-original-article-buffer beg end)
487             (article-decode-encoded-words))))
488       gnus-article-copy)))
489
490 (defun gnus-post-news (post &optional group header article-buffer yank subject
491                             force-news)
492   (when article-buffer
493     (gnus-copy-article-buffer))
494   (let ((gnus-article-reply article-buffer)
495         (add-to-list gnus-add-to-list))
496     (gnus-setup-message (cond (yank 'reply-yank)
497                               (article-buffer 'reply)
498                               (t 'message))
499       (let* ((group (or group gnus-newsgroup-name))
500              (charset (gnus-group-name-charset nil group))
501              (pgroup group)
502              to-address to-group mailing-list to-list
503              newsgroup-p)
504         (when group
505           (setq to-address (gnus-group-find-parameter group 'to-address)
506                 to-group (gnus-group-find-parameter group 'to-group)
507                 to-list (gnus-group-find-parameter group 'to-list)
508                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
509                 mailing-list (when gnus-mailing-list-groups
510                                (string-match gnus-mailing-list-groups group))
511                 group (gnus-group-name-decode (gnus-group-real-name group)
512                                               charset)))
513         (if (or (and to-group
514                      (gnus-news-group-p to-group))
515                 newsgroup-p
516                 force-news
517                 (and (gnus-news-group-p
518                       (or pgroup gnus-newsgroup-name)
519                       (if header (mail-header-number header)
520                         gnus-current-article))
521                      (not mailing-list)
522                      (not to-list)
523                      (not to-address)))
524             ;; This is news.
525             (if post
526                 (message-news (or to-group group))
527               (set-buffer gnus-article-copy)
528               (gnus-msg-treat-broken-reply-to)
529               (message-followup (if (or newsgroup-p force-news) nil to-group)))
530           ;; The is mail.
531           (if post
532               (progn
533                 (message-mail (or to-address to-list))
534                 ;; Arrange for mail groups that have no `to-address' to
535                 ;; get that when the user sends off the mail.
536                 (when (and (not to-list)
537                            (not to-address)
538                            add-to-list)
539                   (push (list 'gnus-inews-add-to-address pgroup)
540                         message-send-actions)))
541             (set-buffer gnus-article-copy)
542             (gnus-msg-treat-broken-reply-to)
543             (message-wide-reply to-address)))
544         (when yank
545           (gnus-inews-yank-articles yank))))))
546
547 (defun gnus-msg-treat-broken-reply-to ()
548   "Remove the Reply-to header iff broken-reply-to."
549   (when (gnus-group-find-parameter
550          gnus-newsgroup-name 'broken-reply-to)
551     (save-restriction
552       (message-narrow-to-head)
553       (message-remove-header "reply-to"))))
554
555 (defun gnus-post-method (arg group &optional silent)
556   "Return the posting method based on GROUP and ARG.
557 If SILENT, don't prompt the user."
558   (let ((group-method (gnus-find-method-for-group group)))
559     (cond
560      ;; If the group-method is nil (which shouldn't happen) we use
561      ;; the default method.
562      ((null group-method)
563       (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
564           gnus-select-method message-post-method))
565      ;; We want the inverse of the default
566      ((and arg (not (eq arg 0)))
567       (if (eq gnus-post-method 'active)
568           gnus-select-method
569         group-method))
570      ;; We query the user for a post method.
571      ((or arg
572           (and gnus-post-method
573                (not (eq gnus-post-method 'current))
574                (listp (car gnus-post-method))))
575       (let* ((methods
576               ;; Collect all methods we know about.
577               (append
578                (when (and gnus-post-method
579                           (not (eq gnus-post-method 'current)))
580                  (if (listp (car gnus-post-method))
581                      gnus-post-method
582                    (list gnus-post-method)))
583                gnus-secondary-select-methods
584                (mapcar 'cdr gnus-server-alist)
585                (mapcar 'car gnus-opened-servers)
586                (list gnus-select-method)
587                (list group-method)))
588              method-alist post-methods method)
589         ;; Weed out all mail methods.
590         (while methods
591           (setq method (gnus-server-get-method "" (pop methods)))
592           (when (and (or (gnus-method-option-p method 'post)
593                          (gnus-method-option-p method 'post-mail))
594                      (not (member method post-methods)))
595             (push method post-methods)))
596         ;; Create a name-method alist.
597         (setq method-alist
598               (mapcar
599                (lambda (m)
600                  (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
601                post-methods))
602         ;; Query the user.
603         (cadr
604          (assoc
605           (setq gnus-last-posting-server
606                 (if (and silent
607                          gnus-last-posting-server)
608                     ;; Just use the last value.
609                     gnus-last-posting-server
610                   (completing-read
611                    "Posting method: " method-alist nil t
612                    (cons (or gnus-last-posting-server "") 0))))
613           method-alist))))
614      ;; Override normal method.
615      ((and (eq gnus-post-method 'current)
616            (not (eq (car group-method) 'nndraft))
617            (gnus-get-function group-method 'request-post t)
618            (not arg))
619       group-method)
620      ((and gnus-post-method
621            (not (eq gnus-post-method 'current)))
622       gnus-post-method)
623      ;; Use the normal select method.
624      (t gnus-select-method))))
625
626 \f
627
628 ;; Dummies to avoid byte-compile warning.
629 (defvar nnspool-rejected-article-hook)
630 (defvar xemacs-codename)
631
632 (defun gnus-extended-version ()
633   "Stringified Gnus version and Emacs version."
634   (interactive)
635   (concat
636    "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
637    " (" gnus-version ")"
638    " "
639    (cond
640     ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
641      (concat "Emacs/" (match-string 1 emacs-version)))
642     ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
643                    emacs-version)
644      (concat (match-string 1 emacs-version)
645              (format "/%d.%d" emacs-major-version emacs-minor-version)
646              (if (match-beginning 3)
647                  (match-string 3 emacs-version)
648                "")
649              (if (boundp 'xemacs-codename)
650                  (concat " (" xemacs-codename ")")
651                "")))
652     (t emacs-version))))
653
654 \f
655 ;;;
656 ;;; Gnus Mail Functions
657 ;;;
658
659 ;;; Mail reply commands of Gnus summary mode
660
661 (defun gnus-summary-reply (&optional yank wide)
662   "Start composing a reply mail to the current message.
663 If prefix argument YANK is non-nil, the original article is yanked
664 automatically."
665   (interactive
666    (list (and current-prefix-arg
667               (gnus-summary-work-articles 1))))
668   ;; Stripping headers should be specified with mail-yank-ignored-headers.
669   (when yank
670     (gnus-summary-goto-subject (car yank)))
671   (let ((gnus-article-reply t))
672     (gnus-setup-message (if yank 'reply-yank 'reply)
673       (gnus-summary-select-article)
674       (set-buffer (gnus-copy-article-buffer))
675       (gnus-msg-treat-broken-reply-to)
676       (save-restriction
677         (message-narrow-to-head)
678         (goto-char (point-max)))
679       (mml-quote-region (point) (point-max))
680       (message-reply nil wide)
681       (when yank
682         (gnus-inews-yank-articles yank)))))
683
684 (defun gnus-summary-reply-with-original (n &optional wide)
685   "Start composing a reply mail to the current message.
686 The original article will be yanked."
687   (interactive "P")
688   (gnus-summary-reply (gnus-summary-work-articles n) wide))
689
690 (defun gnus-summary-wide-reply (&optional yank)
691   "Start composing a wide reply mail to the current message.
692 If prefix argument YANK is non-nil, the original article is yanked
693 automatically."
694   (interactive
695    (list (and current-prefix-arg
696               (gnus-summary-work-articles 1))))
697   (gnus-summary-reply yank t))
698
699 (defun gnus-summary-wide-reply-with-original (n)
700   "Start composing a wide reply mail to the current message.
701 The original article will be yanked."
702   (interactive "P")
703   (gnus-summary-reply-with-original n t))
704
705 (defun gnus-summary-mail-forward (&optional arg post)
706   "Forward the current message to another user.  
707 If ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
708 if ARG is 1, decode the message and forward directly inline;
709 if ARG is 2, foward message as an rfc822 MIME section;
710 if ARG is 3, decode message and forward as an rfc822 MIME section;
711 if ARG is 4, foward message directly inline;
712 otherwise, use flipped `message-forward-as-mime'.
713 If POST, post instead of mail."
714   (interactive "P")
715   (let ((message-forward-as-mime message-forward-as-mime)
716         (message-forward-show-mml message-forward-show-mml))
717     (cond 
718      ((null arg))
719      ((eq arg 1) (setq message-forward-as-mime nil
720                        message-forward-show-mml t))
721      ((eq arg 2) (setq message-forward-as-mime t
722                        message-forward-show-mml nil))
723      ((eq arg 3) (setq message-forward-as-mime t
724                        message-forward-show-mml t))
725      ((eq arg 4) (setq message-forward-as-mime nil
726                        message-forward-show-mml nil))
727      (t (setq message-forward-as-mime (not message-forward-as-mime))))
728     (gnus-setup-message 'forward
729       (gnus-summary-select-article)
730       (let ((mail-parse-charset gnus-newsgroup-charset)
731             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
732             text)
733         (save-excursion
734           (set-buffer gnus-original-article-buffer)
735           (setq text (buffer-string)))
736         (set-buffer 
737          (gnus-get-buffer-create
738           (generate-new-buffer-name " *Gnus forward*")))
739         (erase-buffer)
740         (unless message-forward-show-mml
741           (mm-disable-multibyte))
742         (insert text)
743         (goto-char (point-min))
744         (when (looking-at "From ")
745           (replace-match "X-From-Line: ") )
746         (when message-forward-show-mml
747           (mime-to-mml))
748         (message-forward post)))))
749
750 (defun gnus-summary-resend-message (address n)
751   "Resend the current article to ADDRESS."
752   (interactive "sResend message(s) to: \nP")
753   (let ((articles (gnus-summary-work-articles n))
754         article)
755     (while (setq article (pop articles))
756       (gnus-summary-select-article nil nil nil article)
757       (save-excursion
758         (set-buffer gnus-original-article-buffer)
759         (message-resend address)))))
760
761 (defun gnus-summary-post-forward (&optional arg)
762   "Forward the current article to a newsgroup.
763 See `gnus-summary-mail-forward' for ARG."
764   (interactive "P")
765   (gnus-summary-mail-forward arg t))
766
767 (defvar gnus-nastygram-message
768   "The following article was inappropriately posted to %s.\n\n"
769   "Format string to insert in nastygrams.
770 The current group name will be inserted at \"%s\".")
771
772 (defun gnus-summary-mail-nastygram (n)
773   "Send a nastygram to the author of the current article."
774   (interactive "P")
775   (when (or gnus-expert-user
776             (gnus-y-or-n-p
777              "Really send a nastygram to the author of the current article? "))
778     (let ((group gnus-newsgroup-name))
779       (gnus-summary-reply-with-original n)
780       (set-buffer gnus-message-buffer)
781       (message-goto-body)
782       (insert (format gnus-nastygram-message group))
783       (message-send-and-exit))))
784
785 (defun gnus-summary-mail-crosspost-complaint (n)
786   "Send a complaint about crossposting to the current article(s)."
787   (interactive "P")
788   (let ((articles (gnus-summary-work-articles n))
789         article)
790     (while (setq article (pop articles))
791       (set-buffer gnus-summary-buffer)
792       (gnus-summary-goto-subject article)
793       (let ((group (gnus-group-real-name gnus-newsgroup-name))
794             newsgroups followup-to)
795         (gnus-summary-select-article)
796         (set-buffer gnus-original-article-buffer)
797         (if (and (<= (length (message-tokenize-header
798                               (setq newsgroups
799                                     (mail-fetch-field "newsgroups"))
800                               ", "))
801                      1)
802                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
803                      (not (member group (message-tokenize-header
804                                          followup-to ", ")))))
805             (if followup-to
806                 (gnus-message 1 "Followup-to restricted")
807               (gnus-message 1 "Not a crossposted article"))
808           (set-buffer gnus-summary-buffer)
809           (gnus-summary-reply-with-original 1)
810           (set-buffer gnus-message-buffer)
811           (message-goto-body)
812           (insert (format gnus-crosspost-complaint newsgroups group))
813           (message-goto-subject)
814           (re-search-forward " *$")
815           (replace-match " (crosspost notification)" t t)
816           (gnus-deactivate-mark)
817           (when (gnus-y-or-n-p "Send this complaint? ")
818             (message-send-and-exit)))))))
819
820 (defun gnus-summary-mail-other-window ()
821   "Compose mail in other window."
822   (interactive)
823   (gnus-setup-message 'message
824     (message-mail)))
825
826 (defun gnus-mail-parse-comma-list ()
827   (let (accumulated
828         beg)
829     (skip-chars-forward " ")
830     (while (not (eobp))
831       (setq beg (point))
832       (skip-chars-forward "^,")
833       (while (zerop
834               (save-excursion
835                 (save-restriction
836                   (let ((i 0))
837                     (narrow-to-region beg (point))
838                     (goto-char beg)
839                     (logand (progn
840                               (while (search-forward "\"" nil t)
841                                 (incf i))
842                               (if (zerop i) 2 i))
843                             2)))))
844         (skip-chars-forward ",")
845         (skip-chars-forward "^,"))
846       (skip-chars-backward " ")
847       (push (buffer-substring beg (point))
848             accumulated)
849       (skip-chars-forward "^,")
850       (skip-chars-forward ", "))
851     accumulated))
852
853 (defun gnus-inews-add-to-address (group)
854   (let ((to-address (mail-fetch-field "to")))
855     (when (and to-address
856                (gnus-alive-p))
857       ;; This mail group doesn't have a `to-list', so we add one
858       ;; here.  Magic!
859       (when (gnus-y-or-n-p
860              (format "Do you want to add this as `to-list': %s " to-address))
861         (gnus-group-add-parameter group (cons 'to-list to-address))))))
862
863 (defun gnus-put-message ()
864   "Put the current message in some group and return to Gnus."
865   (interactive)
866   (let ((reply gnus-article-reply)
867         (winconf gnus-prev-winconf)
868         (group gnus-newsgroup-name))
869
870     (or (and group (not (gnus-group-read-only-p group)))
871         (setq group (read-string "Put in group: " nil
872                                  (gnus-writable-groups))))
873     (when (gnus-gethash group gnus-newsrc-hashtb)
874       (error "No such group: %s" group))
875
876     (save-excursion
877       (save-restriction
878         (widen)
879         (message-narrow-to-headers)
880         (let (gnus-deletable-headers)
881           (if (message-news-p)
882               (message-generate-headers message-required-news-headers)
883             (message-generate-headers message-required-mail-headers)))
884         (goto-char (point-max))
885         (insert "Gcc: " group "\n")
886         (widen)))
887
888     (gnus-inews-do-gcc)
889
890     (when (get-buffer gnus-group-buffer)
891       (when (gnus-buffer-exists-p (car-safe reply))
892         (set-buffer (car reply))
893         (and (cdr reply)
894              (gnus-summary-mark-article-as-replied
895               (cdr reply))))
896       (when winconf
897         (set-window-configuration winconf)))))
898
899 (defun gnus-article-mail (yank)
900   "Send a reply to the address near point.
901 If YANK is non-nil, include the original article."
902   (interactive "P")
903   (let ((address
904          (buffer-substring
905           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
906           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
907     (when address
908       (message-reply address)
909       (when yank
910         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
911
912 (defvar nntp-server-type)
913 (defun gnus-bug ()
914   "Send a bug report to the Gnus maintainers."
915   (interactive)
916   (unless (gnus-alive-p)
917     (error "Gnus has been shut down"))
918   (gnus-setup-message 'bug
919     (delete-other-windows)
920     (when gnus-bug-create-help-buffer
921       (switch-to-buffer "*Gnus Help Bug*")
922       (erase-buffer)
923       (insert gnus-bug-message)
924       (goto-char (point-min)))
925     (message-pop-to-buffer "*Gnus Bug*")
926     (message-setup `((To . ,gnus-maintainer) (Subject . "")))
927     (when gnus-bug-create-help-buffer
928       (push `(gnus-bug-kill-buffer) message-send-actions))
929     (goto-char (point-min))
930     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
931     (forward-line 1)
932     (insert (gnus-version) "\n"
933             (emacs-version) "\n")
934     (when (and (boundp 'nntp-server-type)
935                (stringp nntp-server-type))
936       (insert nntp-server-type))
937     (insert "\n\n\n\n\n")
938     (let (text)
939       (save-excursion
940         (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
941         (gnus-debug)
942         (setq text (buffer-string)))
943       (insert "<#part type=application/x-emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
944     (goto-char (point-min))
945     (search-forward "Subject: " nil t)
946     (message "")))
947
948 (defun gnus-bug-kill-buffer ()
949   (when (get-buffer "*Gnus Help Bug*")
950     (kill-buffer "*Gnus Help Bug*")))
951
952 (defun gnus-summary-yank-message (buffer n)
953   "Yank the current article into a composed message."
954   (interactive
955    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
956          current-prefix-arg))
957   (gnus-summary-iterate n
958     (let ((gnus-display-mime-function nil)
959           (gnus-inhibit-treatment t))
960       (gnus-summary-select-article))
961     (save-excursion
962       (set-buffer buffer)
963       (message-yank-buffer gnus-article-buffer))))
964
965 (defun gnus-debug ()
966   "Attempts to go through the Gnus source file and report what variables have been changed.
967 The source file has to be in the Emacs load path."
968   (interactive)
969   (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
970                  "gnus-art.el" "gnus-start.el" "gnus-async.el"
971                  "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
972                  "nnmail.el" "message.el"))
973         (point (point))
974         file expr olist sym)
975     (gnus-message 4 "Please wait while we snoop your variables...")
976     (sit-for 0)
977     ;; Go through all the files looking for non-default values for variables.
978     (save-excursion
979       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
980       (while files
981         (erase-buffer)
982         (when (and (setq file (locate-library (pop files)))
983                    (file-exists-p file))
984           (insert-file-contents file)
985           (goto-char (point-min))
986           (if (not (re-search-forward "^;;* *Internal variables" nil t))
987               (gnus-message 4 "Malformed sources in file %s" file)
988             (narrow-to-region (point-min) (point))
989             (goto-char (point-min))
990             (while (setq expr (ignore-errors (read (current-buffer))))
991               (ignore-errors
992                 (and (or (eq (car expr) 'defvar)
993                          (eq (car expr) 'defcustom))
994                      (stringp (nth 3 expr))
995                      (or (not (boundp (nth 1 expr)))
996                          (not (equal (eval (nth 2 expr))
997                                      (symbol-value (nth 1 expr)))))
998                      (push (nth 1 expr) olist)))))))
999       (kill-buffer (current-buffer)))
1000     (when (setq olist (nreverse olist))
1001       (insert "------------------ Environment follows ------------------\n\n"))
1002     (while olist
1003       (if (boundp (car olist))
1004           (condition-case ()
1005               (pp `(setq ,(car olist)
1006                          ,(if (or (consp (setq sym (symbol-value (car olist))))
1007                                   (and (symbolp sym)
1008                                        (not (or (eq sym nil)
1009                                                 (eq sym t)))))
1010                               (list 'quote (symbol-value (car olist)))
1011                             (symbol-value (car olist))))
1012                   (current-buffer))
1013             (error
1014              (format "(setq %s 'whatever)\n" (car olist))))
1015         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1016       (setq olist (cdr olist)))
1017     (insert "\n\n")
1018     ;; Remove any control chars - they seem to cause trouble for some
1019     ;; mailers.  (Byte-compiled output from the stuff above.)
1020     (goto-char point)
1021     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1022       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1023                      t t))))
1024
1025 ;;; Treatment of rejected articles.
1026 ;;; Bounced mail.
1027
1028 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1029   "Re-mail the current message.
1030 This only makes sense if the current message is a bounce message than
1031 contains some mail you have written which has been bounced back to
1032 you.
1033 If FETCH, try to fetch the article that this is a reply to, if indeed
1034 this is a reply."
1035   (interactive "P")
1036   (gnus-summary-select-article t)
1037   (set-buffer gnus-original-article-buffer)
1038   (gnus-setup-message 'compose-bounce
1039     (let* ((references (mail-fetch-field "references"))
1040            (parent (and references (gnus-parent-id references))))
1041       (message-bounce)
1042       ;; If there are references, we fetch the article we answered to.
1043       (and fetch parent
1044            (gnus-summary-refer-article parent)
1045            (gnus-summary-show-all-headers)))))
1046
1047 ;;; Gcc handling.
1048
1049 (defun gnus-inews-group-method (group)
1050   (cond ((and (null (gnus-get-info group))
1051               (eq (car gnus-message-archive-method)
1052                   (car
1053                    (gnus-server-to-method
1054                     (gnus-group-method group)))))
1055          ;; If the group doesn't exist, we assume
1056          ;; it's an archive group...
1057          gnus-message-archive-method)
1058         ;; Use the method.
1059         ((gnus-info-method (gnus-get-info group))
1060          (gnus-info-method (gnus-get-info group)))
1061         ;; Find the method.
1062         (t (gnus-group-method group))))
1063
1064 ;; Do Gcc handling, which copied the message over to some group.
1065 (defun gnus-inews-do-gcc (&optional gcc)
1066   (interactive)
1067   (when (gnus-alive-p)
1068     (save-excursion
1069       (save-restriction
1070         (message-narrow-to-headers)
1071         (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1072               (cur (current-buffer))
1073               groups group method group-art)
1074           (when gcc
1075             (message-remove-header "gcc")
1076             (widen)
1077             (setq groups (message-unquote-tokens
1078                           (message-tokenize-header gcc " ,")))
1079             ;; Copy the article over to some group(s).
1080             (while (setq group (pop groups))
1081               (gnus-check-server
1082                (setq method (gnus-inews-group-method group)))
1083               (unless (gnus-request-group group t method)
1084                 (gnus-request-create-group group method))
1085               (save-excursion
1086                 (nnheader-set-temp-buffer " *acc*")
1087                 (insert-buffer-substring cur)
1088                 (message-encode-message-body)
1089                 (save-restriction
1090                   (message-narrow-to-headers)
1091                   (let ((mail-parse-charset message-default-charset)
1092                         (rfc2047-header-encoding-alist
1093                          (cons '("Newsgroups" . default)
1094                                rfc2047-header-encoding-alist)))
1095                     (mail-encode-encoded-word-buffer)))
1096                 (goto-char (point-min))
1097                 (when (re-search-forward
1098                        (concat "^" (regexp-quote mail-header-separator) "$")
1099                        nil t)
1100                   (replace-match "" t t ))
1101                 (unless (setq group-art 
1102                               (gnus-request-accept-article group method t t))
1103                   (gnus-message 1 "Couldn't store article in group %s: %s"
1104                                 group (gnus-status-message method))
1105                   (sit-for 2))
1106                 (when gnus-inews-mark-gcc-as-read
1107                   (let ((active (gnus-active group)))
1108                     (when active
1109                       (if (< (cdr active) (cdr group-art))
1110                           (gnus-set-active group (cons (car active) 
1111                                                        (cdr group-art))))
1112                       (gnus-group-make-articles-read group 
1113                                                      (list (cdr group-art))))))
1114                 (kill-buffer (current-buffer))))))))))
1115
1116 (defun gnus-inews-insert-gcc ()
1117   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1118   (save-excursion
1119     (save-restriction
1120       (message-narrow-to-headers)
1121       (let* ((group gnus-outgoing-message-group)
1122              (gcc (cond
1123                    ((gnus-functionp group)
1124                     (funcall group))
1125                    ((or (stringp group) (list group))
1126                     group))))
1127         (when gcc
1128           (insert "Gcc: "
1129                   (if (stringp gcc) gcc
1130                     (mapconcat 'identity gcc " "))
1131                   "\n"))))))
1132
1133 (defun gnus-inews-insert-archive-gcc (&optional group)
1134   "Insert the Gcc to say where the article is to be archived."
1135   (let* ((var gnus-message-archive-group)
1136          (group (or group gnus-newsgroup-name ""))
1137          (gcc-self-val
1138           (and gnus-newsgroup-name
1139                (not (equal gnus-newsgroup-name ""))
1140                (gnus-group-find-parameter
1141                 gnus-newsgroup-name 'gcc-self)))
1142          result
1143          (groups
1144           (cond
1145            ((null gnus-message-archive-method)
1146             ;; Ignore.
1147             nil)
1148            ((stringp var)
1149             ;; Just a single group.
1150             (list var))
1151            ((null var)
1152             ;; We don't want this.
1153             nil)
1154            ((and (listp var) (stringp (car var)))
1155             ;; A list of groups.
1156             var)
1157            ((gnus-functionp var)
1158             ;; A function.
1159             (funcall var group))
1160            (t
1161             ;; An alist of regexps/functions/forms.
1162             (while (and var
1163                         (not
1164                          (setq result
1165                                (cond
1166                                 ((stringp (caar var))
1167                                  ;; Regexp.
1168                                  (when (string-match (caar var) group)
1169                                    (cdar var)))
1170                                 ((gnus-functionp (car var))
1171                                  ;; Function.
1172                                  (funcall (car var) group))
1173                                 (t
1174                                  (eval (car var)))))))
1175               (setq var (cdr var)))
1176             result)))
1177          name)
1178     (when (or groups gcc-self-val)
1179       (when (stringp groups)
1180         (setq groups (list groups)))
1181       (save-excursion
1182         (save-restriction
1183           (message-narrow-to-headers)
1184           (goto-char (point-max))
1185           (insert "Gcc: ")
1186           (if gcc-self-val
1187               ;; Use the `gcc-self' param value instead.
1188               (progn
1189                 (insert
1190                  (if (stringp gcc-self-val)
1191                      gcc-self-val
1192                    group))
1193                 (if (not (eq gcc-self-val 'none))
1194                     (insert "\n")
1195                   (progn
1196                     (beginning-of-line)
1197                     (kill-line))))
1198             ;; Use the list of groups.
1199             (while (setq name (pop groups))
1200               (insert (if (string-match ":" name)
1201                           name
1202                         (gnus-group-prefixed-name
1203                          name gnus-message-archive-method)))
1204               (when groups
1205                 (insert " ")))
1206             (insert "\n")))))))
1207
1208 ;;; Posting styles.
1209
1210 (defun gnus-configure-posting-styles ()
1211   "Configure posting styles according to `gnus-posting-styles'."
1212   (unless gnus-inhibit-posting-styles
1213     (let ((group (or gnus-newsgroup-name ""))
1214           (styles gnus-posting-styles)
1215           style match variable attribute value v results
1216           filep name address element)
1217       ;; If the group has a posting-style parameter, add it at the end with a
1218       ;; regexp matching everything, to be sure it takes precedence over all
1219       ;; the others.
1220       (when gnus-newsgroup-name
1221         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1222           (when tmp-style
1223             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1224       ;; Go through all styles and look for matches.
1225       (dolist (style styles)
1226         (setq match (pop style))
1227         (goto-char (point-min))
1228         (when (cond
1229                ((stringp match)
1230                 ;; Regexp string match on the group name.
1231                 (string-match match group))
1232                ((eq match 'header)
1233                 (let ((header (message-fetch-field (pop style))))
1234                   (and header
1235                        (string-match (pop style) header))))
1236                ((or (symbolp match)
1237                     (gnus-functionp match))
1238                 (cond
1239                  ((gnus-functionp match)
1240                   ;; Function to be called.
1241                   (funcall match))
1242                  ((boundp match)
1243                   ;; Variable to be checked.
1244                   (symbol-value match))))
1245                ((listp match)
1246                 ;; This is a form to be evaled.
1247                 (eval match)))
1248           ;; We have a match, so we set the variables.
1249           (dolist (attribute style)
1250             (setq element (pop attribute)
1251                   variable nil
1252                   filep nil)
1253             (setq value
1254                   (cond
1255                    ((eq (car attribute) :file)
1256                     (setq filep t)
1257                     (cadr attribute))
1258                    ((eq (car attribute) :value)
1259                     (cadr attribute))
1260                    (t
1261                     (car attribute))))
1262             ;; We get the value.
1263             (setq v
1264                   (cond
1265                    ((stringp value)
1266                     value)
1267                    ((or (symbolp value)
1268                         (gnus-functionp value))
1269                     (cond ((gnus-functionp value)
1270                            (funcall value))
1271                           ((boundp value)
1272                            (symbol-value value))))
1273                    ((listp value)
1274                     (eval value))))
1275             ;; Translate obsolescent value.
1276             (when (eq element 'signature-file)
1277               (setq element 'signature
1278                     filep t))
1279             ;; Get the contents of file elems.
1280             (when (and filep v)
1281               (setq v (with-temp-buffer
1282                         (insert-file-contents v)
1283                         (buffer-string))))
1284             (setq results (delq (assoc element results) results))
1285             (push (cons element v) results))))
1286       ;; Now we have all the styles, so we insert them.
1287       (setq name (assq 'name results)
1288             address (assq 'address results))
1289       (setq results (delq name (delq address results)))
1290       (make-local-variable 'message-setup-hook)
1291       (dolist (result results)
1292         (add-hook 'message-setup-hook
1293                   (cond
1294                    ((eq 'eval (car result))
1295                     'ignore)
1296                    ((eq 'body (car result))
1297                     `(lambda ()
1298                        (save-excursion
1299                          (message-goto-body)
1300                          (insert ,(cdr result)))))
1301                    ((eq 'signature (car result))
1302                     (set (make-local-variable 'message-signature) nil)
1303                     (set (make-local-variable 'message-signature-file) nil)
1304                     (if (not (cdr result))
1305                         'ignore
1306                       `(lambda ()
1307                          (save-excursion
1308                            (let ((message-signature ,(cdr result)))
1309                              (when message-signature
1310                                (message-insert-signature)))))))
1311                    (t
1312                     (let ((header
1313                            (if (symbolp (car result))
1314                                (capitalize (symbol-name (car result)))
1315                              (car result))))
1316                       `(lambda ()
1317                          (save-excursion
1318                            (message-remove-header ,header)
1319                            (let ((value ,(cdr result)))
1320                              (when value
1321                                (message-goto-eoh)
1322                                (insert ,header ": " value "\n"))))))))))
1323       (when (or name address)
1324         (add-hook 'message-setup-hook
1325                   `(lambda ()
1326                      (set (make-local-variable 'user-mail-address)
1327                           ,(or (cdr address) user-mail-address))
1328                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1329                            (user-mail-address
1330                             ,(or (cdr address) user-mail-address)))
1331                        (save-excursion
1332                          (message-remove-header "From")
1333                          (message-goto-eoh)
1334                          (insert "From: " (message-make-from) "\n")))))))))
1335
1336 ;;; Allow redefinition of functions.
1337
1338 (gnus-ems-redefine)
1339
1340 (provide 'gnus-msg)
1341
1342 ;;; gnus-msg.el ends here