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