Import Oort Gnus v0.13.
[elisp/gnus.git-] / lisp / gnus-msg.el
1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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' (which is the default), Gnus will use
41 the \"current\" select method when posting.  If it is `native', Gnus
42 will 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 `native' nor `current', 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   :link '(custom-manual "(gnus)Posting Server")
53   :type `(choice (const native)
54                  (const current)
55                  (sexp :tag "Methods" ,gnus-select-method)))
56
57 (defcustom 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   :group 'gnus-message
68   :type '(choice (string :tag "Group")
69                  (function)))
70
71 (defcustom gnus-mailing-list-groups nil
72   "*Regexp matching groups that are really mailing lists.
73 This is useful when you're reading a mailing list that has been
74 gatewayed to a newsgroup, and you want to followup to an article in
75 the group."
76   :group 'gnus-message
77   :type 'regexp)
78
79 (defcustom gnus-add-to-list nil
80   "*If non-nil, add a `to-list' parameter automatically."
81   :group 'gnus-message
82   :type 'boolean)
83
84 (defcustom gnus-crosspost-complaint
85   "Hi,
86
87 You posted the article below with the following Newsgroups header:
88
89 Newsgroups: %s
90
91 The %s group, at least, was an inappropriate recipient
92 of this message.  Please trim your Newsgroups header to exclude this
93 group before posting in the future.
94
95 Thank you.
96
97 "
98   "Format string to be inserted when complaining about crossposts.
99 The first %s will be replaced by the Newsgroups header;
100 the second with the current group name."
101   :group 'gnus-message
102   :type 'string)
103
104 (defcustom gnus-message-setup-hook nil
105   "Hook run after setting up a message buffer."
106   :group 'gnus-message
107   :type 'hook)
108
109 (defcustom gnus-bug-create-help-buffer t
110   "*Should we create the *Gnus Help Bug* buffer?"
111   :group 'gnus-message
112   :type 'boolean)
113
114 (defcustom gnus-posting-styles nil
115   "*Alist of styles to use when posting.
116 See Info node `(gnus)Posting Styles'."
117   :group 'gnus-message
118   :link '(custom-manual "(gnus)Posting Styles")
119   :type '(repeat (cons (choice (regexp)
120                                (variable)
121                                (list (const header)
122                                      (string :tag "Header")
123                                      (regexp :tag "Regexp"))
124                                (function)
125                                (sexp))
126                        (repeat (list
127                                 (choice (const signature)
128                                         (const signature-file)
129                                         (const organization)
130                                         (const address)
131                                         (const x-face-file)
132                                         (const name)
133                                         (const body)
134                                         (symbol)
135                                         (string :tag "Header"))
136                                 (choice (string)
137                                         (function)
138                                         (variable)
139                                         (sexp)))))))
140
141 (defcustom gnus-gcc-mark-as-read nil
142   "If non-nil, automatically mark Gcc articles as read."
143   :version "21.1"
144   :group 'gnus-message
145   :type 'boolean)
146
147 (defvar gnus-inews-mark-gcc-as-read nil
148   "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
149
150 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
151                         'gnus-gcc-mark-as-read)
152
153 (defcustom gnus-gcc-externalize-attachments nil
154   "Should local-file attachments be included as external parts in Gcc copies?
155 If it is `all', attach files as external parts;
156 if a regexp and matches the Gcc group name, attach files as external parts;
157 if nil, attach files as normal parts."
158   :version "21.1"
159   :group 'gnus-message
160   :type '(choice (const nil :tag "None")
161                  (const all :tag "Any")
162                  (string :tag "Regexp")))
163
164 (gnus-define-group-parameter
165  posting-charset-alist
166  :type list
167  :function-document
168  "Return the permitted unencoded charsets for posting of GROUP."
169  :variable gnus-group-posting-charset-alist
170  :variable-default
171   '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
172     ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
173     (message-this-is-mail nil nil)
174     (message-this-is-news nil t))
175  :variable-document
176   "Alist of regexps and permitted unencoded charsets for posting.
177 Each element of the alist has the form (TEST HEADER BODY-LIST), where
178 TEST is either a regular expression matching the newsgroup header or a
179 variable to query,
180 HEADER is the charset which may be left unencoded in the header (nil
181 means encode all charsets),
182 BODY-LIST is a list of charsets which may be encoded using 8bit
183 content-transfer encoding in the body, or one of the special values
184 nil (always encode using quoted-printable) or t (always use 8bit).
185
186 Note that any value other than nil for HEADER infringes some RFCs, so
187 use this option with care."
188  :variable-group gnus-charset
189  :variable-type
190  '(repeat (list :tag "Permitted unencoded charsets"
191                 (choice :tag "Where"
192                         (regexp :tag "Group")
193                         (const :tag "Mail message" :value message-this-is-mail)
194                         (const :tag "News article" :value message-this-is-news))
195                 (choice :tag "Header"
196                         (const :tag "None" nil)
197                         (symbol :tag "Charset"))
198                 (choice :tag "Body"
199                         (const :tag "Any" :value t)
200                         (const :tag "None" :value nil)
201                         (repeat :tag "Charsets"
202                                 (symbol :tag "Charset")))))
203  :parameter-type '(choice :tag "Permitted unencoded charsets"
204                           :value nil
205                           (repeat (symbol)))
206  :parameter-document       "\
207 List of charsets that are permitted to be unencoded.")
208
209 (defcustom gnus-debug-files
210   '("gnus.el" "gnus-sum.el" "gnus-group.el"
211     "gnus-art.el" "gnus-start.el" "gnus-async.el"
212     "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
213     "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
214     "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
215   "Files whose variables will be reported in `gnus-bug'."
216   :version "21.1"
217   :group 'gnus-message
218   :type '(repeat (string :tag "File")))
219
220 (defcustom gnus-debug-exclude-variables
221   '(mm-mime-mule-charset-alist
222     nnmail-split-fancy message-minibuffer-local-map)
223   "Variables that should not be reported in `gnus-bug'."
224   :version "21.1"
225   :group 'gnus-message
226   :type '(repeat (symbol :tag "Variable")))
227
228 (defcustom gnus-discouraged-post-methods
229   '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
230   "A list of back ends that are not used in \"real\" newsgroups.
231 This variable is used only when `gnus-post-method' is `current'."
232   :version "21.3"
233   :group 'gnus-group-foreign
234   :type '(repeat (symbol :tag "Back end")))
235
236 (defcustom gnus-message-replysign
237   nil
238   "Automatically sign replys to signed messages.
239 See also the `mml-default-sign-method' variable."
240   :group 'gnus-message
241   :type 'boolean)
242
243 (defcustom gnus-message-replyencrypt
244   nil
245   "Automatically encrypt replys to encrypted messages.
246 See also the `mml-default-encrypt-method' variable."
247   :group 'gnus-message
248   :type 'boolean)
249
250 (defcustom gnus-message-replysignencrypted
251   t
252   "Setting this causes automatically encryped messages to also be signed."
253   :group 'gnus-message
254   :type 'boolean)
255
256 (defcustom gnus-confirm-mail-reply-to-news nil
257   "If non-nil, Gnus requests confirmation when replying to news.
258 This is done because new users often reply by mistake when reading
259 news.
260 This can also be a function receiving the group name as the only
261 parameter which should return non-nil iff a confirmation is needed, or
262 a regexp, in which case a confirmation is asked for iff the group name
263 matches the regexp."
264   :group 'gnus-message
265   :type '(choice (const :tag "No" nil)
266                  (const :tag "Yes" t)
267                  (regexp :tag "Iff group matches regexp")
268                  (function :tag "Iff function evaluates to non-nil")))
269
270 (defcustom gnus-confirm-treat-mail-like-news
271   nil
272   "If non-nil, Gnus will treat mail like news with regard to confirmation
273 when replying by mail.  See the `gnus-confirm-mail-reply-to-news' variable
274 for fine-tuning this.
275 If nil, Gnus will never ask for confirmation if replying to mail."
276   :group 'gnus-message
277   :type 'boolean)
278
279 (defcustom gnus-summary-resend-default-address t
280   "If non-nil, Gnus tries to suggest a default address to resend to.
281 If nil, the address field will always be empty after invoking
282 `gnus-summary-resend-message'."
283   :group 'gnus-message
284   :type 'boolean)
285
286 ;;; Internal variables.
287
288 (defvar gnus-inhibit-posting-styles nil
289   "Inhibit the use of posting styles.")
290
291 (defvar gnus-article-yanked-articles nil)
292 (defvar gnus-message-buffer "*Mail Gnus*")
293 (defvar gnus-article-copy nil)
294 (defvar gnus-check-before-posting nil)
295 (defvar gnus-last-posting-server nil)
296 (defvar gnus-message-group-art nil)
297
298 (defvar gnus-msg-force-broken-reply-to nil)
299
300 (defconst gnus-bug-message
301   "Sending a bug report to the Gnus Towers.
302 ========================================
303
304 The buffer below is a mail buffer.  When you press `C-c C-c', it will
305 be sent to the Gnus Bug Exterminators.
306
307 The thing near the bottom of the buffer is how the environment
308 settings will be included in the mail.  Please do not delete that.
309 They will tell the Bug People what your environment is, so that it
310 will be easier to locate the bugs.
311
312 If you have found a bug that makes Emacs go \"beep\", set
313 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
314 and include the backtrace in your bug report.
315
316 Please describe the bug in annoying, painstaking detail.
317
318 Thank you for your help in stamping out bugs.
319 ")
320
321 (eval-and-compile
322   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
323   (autoload 'news-setup "rnewspost")
324   (autoload 'news-reply-mode "rnewspost")
325   (autoload 'rmail-dont-reply-to "mail-utils")
326   (autoload 'rmail-output "rmailout"))
327
328 \f
329 ;;;
330 ;;; Gnus Posting Functions
331 ;;;
332
333 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
334   "p" gnus-summary-post-news
335   "i" gnus-summary-news-other-window
336   "f" gnus-summary-followup
337   "F" gnus-summary-followup-with-original
338   "c" gnus-summary-cancel-article
339   "s" gnus-summary-supersede-article
340   "r" gnus-summary-reply
341   "y" gnus-summary-yank-message
342   "R" gnus-summary-reply-with-original
343   "w" gnus-summary-wide-reply
344   "W" gnus-summary-wide-reply-with-original
345   "v" gnus-summary-very-wide-reply
346   "V" gnus-summary-very-wide-reply-with-original
347   "n" gnus-summary-followup-to-mail
348   "N" gnus-summary-followup-to-mail-with-original
349   "m" gnus-summary-mail-other-window
350   "u" gnus-uu-post-news
351   "\M-c" gnus-summary-mail-crosspost-complaint
352   "Br" gnus-summary-reply-broken-reply-to
353   "BR" gnus-summary-reply-broken-reply-to-with-original
354   "om" gnus-summary-mail-forward
355   "op" gnus-summary-post-forward
356   "Om" gnus-uu-digest-mail-forward
357   "Op" gnus-uu-digest-post-forward)
358
359 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
360   "b" gnus-summary-resend-bounced-mail
361   ;; "c" gnus-summary-send-draft
362   "r" gnus-summary-resend-message
363   "e" gnus-summary-resend-message-edit)
364
365 ;;; Internal functions.
366
367 (defun gnus-inews-make-draft ()
368   `(lambda ()
369      (gnus-inews-make-draft-meta-information
370       ,gnus-newsgroup-name ',gnus-article-reply)))
371
372 (defvar gnus-article-reply nil)
373 (defmacro gnus-setup-message (config &rest forms)
374   (let ((winconf (make-symbol "gnus-setup-message-winconf"))
375         (buffer (make-symbol "gnus-setup-message-buffer"))
376         (article (make-symbol "gnus-setup-message-article"))
377         (yanked (make-symbol "gnus-setup-yanked-articles"))
378         (group (make-symbol "gnus-setup-message-group")))
379     `(let ((,winconf (current-window-configuration))
380            (,buffer (buffer-name (current-buffer)))
381            (,article gnus-article-reply)
382            (,yanked gnus-article-yanked-articles)
383            (,group gnus-newsgroup-name)
384            (message-header-setup-hook
385             (copy-sequence message-header-setup-hook))
386            (mbl mml-buffer-list)
387            (message-mode-hook (copy-sequence message-mode-hook)))
388        (setq mml-buffer-list nil)
389        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
390        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
391        ;; #### FIXME: for a reason that I did not manage to identify yet,
392        ;; the variable `gnus-newsgroup-name' does not honor a dynamically
393        ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
394        ;; After evaluation of @forms below, it gets the value we actually want
395        ;; to override, and the posting styles are used. For that reason, I've
396        ;; added an optional argument to `gnus-configure-posting-styles' to
397        ;; make sure that the correct value for the group name is used. -- drv
398        (add-hook 'message-mode-hook
399                  (lambda ()
400                    (gnus-configure-posting-styles ,group)))
401        (gnus-pull ',(intern gnus-draft-meta-information-header)
402                   message-required-headers)
403        (when (and ,group
404                   (not (string= ,group "")))
405          (push (cons
406                 (intern gnus-draft-meta-information-header)
407                 (gnus-inews-make-draft))
408                message-required-headers))
409        (unwind-protect
410            (progn
411              ,@forms)
412          (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
413                                       ,yanked)
414          (setq gnus-message-buffer (current-buffer))
415          (set (make-local-variable 'gnus-message-group-art)
416               (cons ,group ,article))
417          (set (make-local-variable 'gnus-newsgroup-name) ,group)
418          (gnus-run-hooks 'gnus-message-setup-hook)
419          (if (eq major-mode 'message-mode)
420              (let ((mbl1 mml-buffer-list))
421                (setq mml-buffer-list mbl)  ;; Global value
422                (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
423                ;; LOCAL argument of add-hook differs between GNU Emacs
424                ;; and XEmacs. make-local-hook makes sure they are local.
425                (make-local-hook 'kill-buffer-hook)
426                (make-local-hook 'change-major-mode-hook)
427                (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
428                (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
429            (mml-destroy-buffers)
430            (setq mml-buffer-list mbl)))
431        (gnus-add-buffer)
432        (gnus-configure-windows ,config t)
433        (run-hooks 'post-command-hook)
434        (set-buffer-modified-p nil))))
435
436 (defun gnus-inews-make-draft-meta-information (group article)
437   (concat "(\"" group "\" "
438           (if article (number-to-string
439                        (if (listp article)
440                            (car article)
441                          article)) "\"\"")
442           ")"))
443
444 ;;;###autoload
445 (defun gnus-msg-mail (&optional to subject other-headers continue
446                                 switch-action yank-action send-actions)
447   "Start editing a mail message to be sent.
448 Like `message-mail', but with Gnus paraphernalia, particularly the
449 Gcc: header for archiving purposes."
450   (interactive)
451   (let ((buf (current-buffer))
452         mail-buf)
453     (gnus-setup-message 'message
454       (message-mail to subject other-headers continue
455                     nil yank-action send-actions))
456     (when switch-action
457       (setq mail-buf (current-buffer))
458       (switch-to-buffer buf)
459       (apply switch-action mail-buf nil)))
460   ;; COMPOSEFUNC should return t if succeed.  Undocumented ???
461   t)
462
463 (defvar save-selected-window-window)
464
465 ;;;###autoload
466 (defun gnus-button-mailto (address)
467   "Mail to ADDRESS."
468   (set-buffer (gnus-copy-article-buffer))
469   (gnus-setup-message 'message
470     (message-reply address))
471   (and (boundp 'save-selected-window-window)
472        (not (window-live-p save-selected-window-window))
473        (setq save-selected-window-window (selected-window))))
474
475 ;;;###autoload
476 (defun gnus-button-reply (&optional to-address wide)
477   "Like `message-reply'."
478   (interactive)
479   (gnus-setup-message 'message
480     (message-reply to-address wide))
481   (and (boundp 'save-selected-window-window)
482        (not (window-live-p save-selected-window-window))
483        (setq save-selected-window-window (selected-window))))
484
485 ;;;###autoload
486 (define-mail-user-agent 'gnus-user-agent
487   'gnus-msg-mail 'message-send-and-exit
488   'message-kill-buffer 'message-send-hook)
489
490 (defun gnus-setup-posting-charset (group)
491   (let ((alist gnus-group-posting-charset-alist)
492         (group (or group ""))
493         elem)
494     (when group
495       (catch 'found
496         (while (setq elem (pop alist))
497           (when (or (and (stringp (car elem))
498                          (string-match (car elem) group))
499                     (and (gnus-functionp (car elem))
500                          (funcall (car elem) group))
501                     (and (symbolp (car elem))
502                          (symbol-value (car elem))))
503             (throw 'found (cons (cadr elem) (caddr elem)))))))))
504
505 (defun gnus-inews-add-send-actions (winconf buffer article
506                                             &optional config yanked)
507   (make-local-hook 'message-sent-hook)
508   (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
509                                  'gnus-inews-do-gcc) nil t)
510   (when gnus-agent
511     (make-local-hook 'message-header-hook)
512     (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
513   (setq message-post-method
514         `(lambda (arg)
515            (gnus-post-method arg ,gnus-newsgroup-name)))
516   (setq message-newsreader (setq message-mailer (gnus-extended-version)))
517   (message-add-action
518    `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
519   (let ((to-be-marked (cond
520                        (yanked yanked)
521                        (article (if (listp article) article (list article)))
522                        (t nil))))
523     (message-add-action
524      `(when (gnus-buffer-exists-p ,buffer)
525         (save-excursion
526           (set-buffer ,buffer)
527           ,(when to-be-marked
528              (if (eq config 'forward)
529                  `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
530                `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
531      'send)))
532
533 (put 'gnus-setup-message 'lisp-indent-function 1)
534 (put 'gnus-setup-message 'edebug-form-spec '(form body))
535
536 ;;; Post news commands of Gnus group mode and summary mode
537
538 (defun gnus-group-mail (&optional arg)
539   "Start composing a mail.
540 If ARG, use the group under the point to find a posting style.
541 If ARG is 1, prompt for a group name to find the posting style."
542   (interactive "P")
543   ;; We can't `let' gnus-newsgroup-name here, since that leads
544   ;; to local variables leaking.
545   (let ((group gnus-newsgroup-name)
546         ;; make sure last viewed article doesn't affect posting styles:
547         (gnus-article-copy)
548         (buffer (current-buffer)))
549     (unwind-protect
550         (progn
551           (setq gnus-newsgroup-name
552                 (if arg
553                     (if (= 1 (prefix-numeric-value arg))
554                         (completing-read "Use posting style of group: "
555                                          gnus-active-hashtb nil
556                                          (gnus-read-active-file-p))
557                       (gnus-group-group-name))
558                   ""))
559           ;; #### see comment in gnus-setup-message -- drv
560           (gnus-setup-message 'message (message-mail)))
561       (save-excursion
562         (set-buffer buffer)
563         (setq gnus-newsgroup-name group)))))
564
565 (defun gnus-group-news (&optional arg)
566   "Start composing a news.
567 If ARG, post to group under point.
568 If ARG is 1, prompt for group name to post to.
569
570 This function prepares a news even when using mail groups.  This is useful
571 for posting messages to mail groups without actually sending them over the
572 network.  The corresponding backend must have a 'request-post method."
573   (interactive "P")
574   ;; We can't `let' gnus-newsgroup-name here, since that leads
575   ;; to local variables leaking.
576   (let ((group gnus-newsgroup-name)
577         ;; make sure last viewed article doesn't affect posting styles:
578         (gnus-article-copy)
579         (buffer (current-buffer)))
580     (unwind-protect
581         (progn
582           (setq gnus-newsgroup-name
583                 (if arg
584                     (if (= 1 (prefix-numeric-value arg))
585                         (completing-read "Use group: "
586                                          gnus-active-hashtb nil
587                                          (gnus-read-active-file-p))
588                       (gnus-group-group-name))
589                   ""))
590           ;; #### see comment in gnus-setup-message -- drv
591           (gnus-setup-message 'message
592             (message-news (gnus-group-real-name gnus-newsgroup-name))))
593       (save-excursion
594         (set-buffer buffer)
595         (setq gnus-newsgroup-name group)))))
596
597 (defun gnus-group-post-news (&optional arg)
598   "Start composing a message (a news by default).
599 If ARG, post to group under point.  If ARG is 1, prompt for group name.
600 Depending on the selected group, the message might be either a mail or
601 a news."
602   (interactive "P")
603   ;; Bind this variable here to make message mode hooks work ok.
604   (let ((gnus-newsgroup-name
605          (if arg
606              (if (= 1 (prefix-numeric-value arg))
607                  (completing-read "Newsgroup: " gnus-active-hashtb nil
608                                   (gnus-read-active-file-p))
609                (gnus-group-group-name))
610            ""))
611         ;; make sure last viewed article doesn't affect posting styles:
612         (gnus-article-copy))
613     (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
614                     (string= gnus-newsgroup-name ""))))
615
616 (defun gnus-summary-mail-other-window (&optional arg)
617   "Start composing a mail in another window.
618 Use the posting of the current group by default.
619 If ARG, don't do that.  If ARG is 1, prompt for group name to find the
620 posting style."
621   (interactive "P")
622   ;; We can't `let' gnus-newsgroup-name here, since that leads
623   ;; to local variables leaking.
624   (let ((group gnus-newsgroup-name)
625         ;; make sure last viewed article doesn't affect posting styles:
626         (gnus-article-copy)
627         (buffer (current-buffer)))
628     (unwind-protect
629         (progn
630           (setq gnus-newsgroup-name
631                 (if arg
632                     (if (= 1 (prefix-numeric-value arg))
633                         (completing-read "Use group: "
634                                          gnus-active-hashtb nil
635                                          (gnus-read-active-file-p))
636                       "")
637                   gnus-newsgroup-name))
638           ;; #### see comment in gnus-setup-message -- drv
639           (gnus-setup-message 'message (message-mail)))
640       (save-excursion
641         (set-buffer buffer)
642         (setq gnus-newsgroup-name group)))))
643
644 (defun gnus-summary-news-other-window (&optional arg)
645   "Start composing a news in another window.
646 Post to the current group by default.
647 If ARG, don't do that.  If ARG is 1, prompt for group name to post to.
648
649 This function prepares a news even when using mail groups.  This is useful
650 for posting messages to mail groups without actually sending them over the
651 network.  The corresponding backend must have a 'request-post method."
652   (interactive "P")
653   ;; We can't `let' gnus-newsgroup-name here, since that leads
654   ;; to local variables leaking.
655   (let ((group gnus-newsgroup-name)
656         ;; make sure last viewed article doesn't affect posting styles:
657         (gnus-article-copy)
658         (buffer (current-buffer)))
659     (unwind-protect
660         (progn
661           (setq gnus-newsgroup-name
662                 (if arg
663                     (if (= 1 (prefix-numeric-value arg))
664                         (completing-read "Use group: "
665                                          gnus-active-hashtb nil
666                                          (gnus-read-active-file-p))
667                       "")
668                   gnus-newsgroup-name))
669           ;; #### see comment in gnus-setup-message -- drv
670           (gnus-setup-message 'message
671             (message-news (gnus-group-real-name gnus-newsgroup-name))))
672       (save-excursion
673         (set-buffer buffer)
674         (setq gnus-newsgroup-name group)))))
675
676 (defun gnus-summary-post-news (&optional arg)
677   "Start composing a message.  Post to the current group by default.
678 If ARG, don't do that.  If ARG is 1, prompt for a group name to post to.
679 Depending on the selected group, the message might be either a mail or
680 a news."
681   (interactive "P")
682   ;; Bind this variable here to make message mode hooks work ok.
683   (let ((gnus-newsgroup-name
684          (if arg
685              (if (= 1 (prefix-numeric-value arg))
686                  (completing-read "Newsgroup: " gnus-active-hashtb nil
687                                   (gnus-read-active-file-p))
688                "")
689            gnus-newsgroup-name))
690         ;; make sure last viewed article doesn't affect posting styles:
691         (gnus-article-copy))
692     (gnus-post-news 'post gnus-newsgroup-name)))
693
694
695 (defun gnus-summary-followup (yank &optional force-news)
696   "Compose a followup to an article.
697 If prefix argument YANK is non-nil, the original article is yanked
698 automatically.
699 YANK is a list of elements, where the car of each element is the
700 article number, and the two following numbers is the region to be
701 yanked."
702   (interactive
703    (list (and current-prefix-arg
704               (gnus-summary-work-articles 1))))
705   (when yank
706     (gnus-summary-goto-subject
707      (if (listp (car yank))
708          (caar yank)
709        (car yank))))
710   (save-window-excursion
711     (gnus-summary-select-article))
712   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
713         (gnus-newsgroup-name gnus-newsgroup-name))
714     ;; Send a followup.
715     (gnus-post-news nil gnus-newsgroup-name
716                     headers gnus-article-buffer
717                     yank nil force-news)
718     (gnus-summary-handle-replysign)))
719
720 (defun gnus-summary-followup-with-original (n &optional force-news)
721   "Compose a followup to an article and include the original article."
722   (interactive "P")
723   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
724
725 (defun gnus-summary-followup-to-mail (&optional arg)
726   "Followup to the current mail message via news."
727   (interactive
728    (list (and current-prefix-arg
729               (gnus-summary-work-articles 1))))
730   (gnus-summary-followup arg t))
731
732 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
733   "Followup to the current mail message via news."
734   (interactive "P")
735   (gnus-summary-followup (gnus-summary-work-articles arg) t))
736
737 (defun gnus-inews-yank-articles (articles)
738   (let (beg article yank-string)
739     (message-goto-body)
740     (while (setq article (pop articles))
741       (when (listp article)
742         (setq yank-string (nth 1 article)
743               article (nth 0 article)))
744       (save-window-excursion
745         (set-buffer gnus-summary-buffer)
746         (gnus-summary-select-article nil nil nil article)
747         (gnus-summary-remove-process-mark article))
748       (gnus-copy-article-buffer nil yank-string)
749       (let ((message-reply-buffer gnus-article-copy)
750             (message-reply-headers
751              ;; The headers are decoded.
752              (with-current-buffer gnus-article-copy
753                (save-restriction
754                  (nnheader-narrow-to-headers)
755                  (nnheader-parse-naked-head)))))
756         (message-yank-original)
757         (setq beg (or beg (mark t))))
758       (when articles
759         (insert "\n")))
760     (push-mark)
761     (goto-char beg)))
762
763 (defun gnus-summary-cancel-article (&optional n symp)
764   "Cancel an article you posted.
765 Uses the process-prefix convention.  If given the symbolic
766 prefix `a', cancel using the standard posting method; if not
767 post using the current select method."
768   (interactive (gnus-interactive "P\ny"))
769   (let ((articles (gnus-summary-work-articles n))
770         (message-post-method
771          `(lambda (arg)
772             (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
773         article)
774     (while (setq article (pop articles))
775       (when (gnus-summary-select-article t nil nil article)
776         (when (gnus-eval-in-buffer-window gnus-original-article-buffer
777                 (message-cancel-news))
778           (gnus-summary-mark-as-read article gnus-canceled-mark)
779           (gnus-cache-remove-article 1))
780         (gnus-article-hide-headers-if-wanted))
781       (gnus-summary-remove-process-mark article))))
782
783 (defun gnus-summary-supersede-article ()
784   "Compose an article that will supersede a previous article.
785 This is done simply by taking the old article and adding a Supersedes
786 header line with the old Message-ID."
787   (interactive)
788   (let ((article (gnus-summary-article-number)))
789     (gnus-setup-message 'reply-yank
790       (gnus-summary-select-article t)
791       (set-buffer gnus-original-article-buffer)
792       (message-supersede)
793       (push
794        `((lambda ()
795            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
796              (save-excursion
797                (set-buffer ,gnus-summary-buffer)
798                (gnus-cache-possibly-remove-article ,article nil nil nil t)
799                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
800        message-send-actions))))
801
802 \f
803
804 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
805   ;; make a copy of the article buffer with all text properties removed
806   ;; this copy is in the buffer gnus-article-copy.
807   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
808   ;; this buffer should be passed to all mail/news reply/post routines.
809   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
810   (save-excursion
811     (set-buffer gnus-article-copy)
812     (mm-enable-multibyte))
813   (let ((article-buffer (or article-buffer gnus-article-buffer))
814         end beg)
815     (if (not (and (get-buffer article-buffer)
816                   (gnus-buffer-exists-p article-buffer)))
817         (error "Can't find any article buffer")
818       (save-excursion
819         (set-buffer article-buffer)
820         (let ((gnus-newsgroup-charset (or gnus-article-charset
821                                           gnus-newsgroup-charset))
822               (gnus-newsgroup-ignored-charsets
823                (or gnus-article-ignored-charsets
824                    gnus-newsgroup-ignored-charsets)))
825           (save-restriction
826             ;; Copy over the (displayed) article buffer, delete
827             ;; hidden text and remove text properties.
828             (widen)
829             (copy-to-buffer gnus-article-copy (point-min) (point-max))
830             (set-buffer gnus-article-copy)
831             (when yank-string
832               (message-goto-body)
833               (delete-region (point) (point-max))
834               (insert yank-string))
835             (gnus-article-delete-text-of-type 'annotation)
836             (gnus-remove-text-with-property 'gnus-prev)
837             (gnus-remove-text-with-property 'gnus-next)
838             (gnus-remove-text-with-property 'gnus-decoration)
839             (insert
840              (prog1
841                  (buffer-substring-no-properties (point-min) (point-max))
842                (erase-buffer)))
843             ;; Find the original headers.
844             (set-buffer gnus-original-article-buffer)
845             (goto-char (point-min))
846             (while (looking-at message-unix-mail-delimiter)
847               (forward-line 1))
848             (let ((mail-header-separator ""))
849               (setq beg (point)
850                     end (or (message-goto-body) beg)))
851             ;; Delete the headers from the displayed articles.
852             (set-buffer gnus-article-copy)
853             (let ((mail-header-separator ""))
854               (delete-region (goto-char (point-min))
855                              (or (message-goto-body) (point-max))))
856             ;; Insert the original article headers.
857             (insert-buffer-substring gnus-original-article-buffer beg end)
858             ;; Decode charsets.
859             (let ((gnus-article-decode-hook
860                    (delq 'article-decode-charset
861                          (copy-sequence gnus-article-decode-hook))))
862               (run-hooks 'gnus-article-decode-hook)))))
863       gnus-article-copy)))
864
865 (defun gnus-post-news (post &optional group header article-buffer yank subject
866                             force-news)
867   (when article-buffer
868     (gnus-copy-article-buffer))
869   (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
870         (gnus-article-yanked-articles yank)
871         (add-to-list gnus-add-to-list))
872     (gnus-setup-message (cond (yank 'reply-yank)
873                               (article-buffer 'reply)
874                               (t 'message))
875       (let* ((group (or group gnus-newsgroup-name))
876              (charset (gnus-group-name-charset nil group))
877              (pgroup group)
878              to-address to-group mailing-list to-list
879              newsgroup-p)
880         (when group
881           (setq to-address (gnus-parameter-to-address group)
882                 to-group (gnus-group-find-parameter group 'to-group)
883                 to-list (gnus-parameter-to-list group)
884                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
885                 mailing-list (when gnus-mailing-list-groups
886                                (string-match gnus-mailing-list-groups group))
887                 group (gnus-group-name-decode (gnus-group-real-name group)
888                                               charset)))
889         (if (or (and to-group
890                      (gnus-news-group-p to-group))
891                 newsgroup-p
892                 force-news
893                 (and (gnus-news-group-p
894                       (or pgroup gnus-newsgroup-name)
895                       (or header gnus-current-article))
896                      (not mailing-list)
897                      (not to-list)
898                      (not to-address)))
899             ;; This is news.
900             (if post
901                 (message-news (or to-group group))
902               (set-buffer gnus-article-copy)
903               (gnus-msg-treat-broken-reply-to)
904               (message-followup (if (or newsgroup-p force-news)
905                                     (if (save-restriction
906                                           (article-narrow-to-head)
907                                           (message-fetch-field "newsgroups"))
908                                         nil
909                                       "")
910                                   to-group)))
911           ;; The is mail.
912           (if post
913               (progn
914                 (message-mail (or to-address to-list))
915                 ;; Arrange for mail groups that have no `to-address' to
916                 ;; get that when the user sends off the mail.
917                 (when (and (not to-list)
918                            (not to-address)
919                            add-to-list)
920                   (push (list 'gnus-inews-add-to-address pgroup)
921                         message-send-actions)))
922             (set-buffer gnus-article-copy)
923             (gnus-msg-treat-broken-reply-to)
924             (message-wide-reply to-address)))
925         (when yank
926           (gnus-inews-yank-articles yank))))))
927
928 (defun gnus-msg-treat-broken-reply-to (&optional force)
929   "Remove the Reply-to header if broken-reply-to."
930   (when (or force
931             (gnus-group-find-parameter
932              gnus-newsgroup-name 'broken-reply-to))
933     (save-restriction
934       (message-narrow-to-head)
935       (message-remove-header "reply-to"))))
936
937 (defun gnus-post-method (arg group &optional silent)
938   "Return the posting method based on GROUP and ARG.
939 If SILENT, don't prompt the user."
940   (let ((gnus-post-method (or (gnus-parameter-post-method group)
941                               gnus-post-method))
942         (group-method (gnus-find-method-for-group group)))
943     (cond
944      ;; If the group-method is nil (which shouldn't happen) we use
945      ;; the default method.
946      ((null group-method)
947       (or (and (listp gnus-post-method) ;If not current/native/nil
948                (not (listp (car gnus-post-method))) ; and not a list of methods
949                gnus-post-method)        ;then use it.
950           gnus-select-method
951           message-post-method))
952      ;; We want the inverse of the default
953      ((and arg (not (eq arg 0)))
954       (if (eq gnus-post-method 'current)
955           gnus-select-method
956         group-method))
957      ;; We query the user for a post method.
958      ((or arg
959           (and (listp gnus-post-method)
960                (listp (car gnus-post-method))))
961       (let* ((methods
962               ;; Collect all methods we know about.
963               (append
964                (when (listp gnus-post-method)
965                  (if (listp (car gnus-post-method))
966                      gnus-post-method
967                    (list gnus-post-method)))
968                gnus-secondary-select-methods
969                (mapcar 'cdr gnus-server-alist)
970                (mapcar 'car gnus-opened-servers)
971                (list gnus-select-method)
972                (list group-method)))
973              method-alist post-methods method)
974         ;; Weed out all mail methods.
975         (while methods
976           (setq method (gnus-server-get-method "" (pop methods)))
977           (when (and (or (gnus-method-option-p method 'post)
978                          (gnus-method-option-p method 'post-mail))
979                      (not (member method post-methods)))
980             (push method post-methods)))
981         ;; Create a name-method alist.
982         (setq method-alist
983               (mapcar
984                (lambda (m)
985                  (if (equal (cadr m) "")
986                      (list (symbol-name (car m)) m)
987                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
988                post-methods))
989         ;; Query the user.
990         (cadr
991          (assoc
992           (setq gnus-last-posting-server
993                 (if (and silent
994                          gnus-last-posting-server)
995                     ;; Just use the last value.
996                     gnus-last-posting-server
997                   (completing-read
998                    "Posting method: " method-alist nil t
999                    (cons (or gnus-last-posting-server "") 0))))
1000           method-alist))))
1001      ;; Override normal method.
1002      ((and (eq gnus-post-method 'current)
1003            (not (memq (car group-method) gnus-discouraged-post-methods))
1004            (gnus-get-function group-method 'request-post t))
1005       (assert (not arg))
1006       group-method)
1007      ;; Use gnus-post-method.
1008      ((listp gnus-post-method)          ;A method...
1009       (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1010       gnus-post-method)
1011      ;; Use the normal select method (nil or native).
1012      (t gnus-select-method))))
1013
1014 \f
1015
1016 ;; Dummies to avoid byte-compile warning.
1017 (eval-when-compile
1018   (defvar nnspool-rejected-article-hook)
1019   (defvar xemacs-codename))
1020
1021 (defun gnus-extended-version ()
1022   "Stringified Gnus version and Emacs version."
1023   (interactive)
1024   (concat
1025    "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
1026    " (" gnus-version ")"
1027    " "
1028    (cond
1029     ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
1030      (concat "Emacs/" (match-string 1 emacs-version)
1031              " (" system-configuration ")"))
1032     ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
1033                    emacs-version)
1034      (concat (match-string 1 emacs-version)
1035              (format "/%d.%d" emacs-major-version emacs-minor-version)
1036              (if (match-beginning 3)
1037                  (match-string 3 emacs-version)
1038                "")
1039              (if (boundp 'xemacs-codename)
1040                  (concat " (" xemacs-codename ", " system-configuration ")")
1041                "")))
1042     (t emacs-version))))
1043
1044 \f
1045 ;;;
1046 ;;; Gnus Mail Functions
1047 ;;;
1048
1049 ;;; Mail reply commands of Gnus summary mode
1050
1051 (defun gnus-summary-reply (&optional yank wide very-wide)
1052   "Start composing a mail reply to the current message.
1053 If prefix argument YANK is non-nil, the original article is yanked
1054 automatically.
1055 If WIDE, make a wide reply.
1056 If VERY-WIDE, make a very wide reply."
1057   (interactive
1058    (list (and current-prefix-arg
1059               (gnus-summary-work-articles 1))))
1060   ;; Allow user to require confirmation before replying by mail to the
1061   ;; author of a news article (or mail message).
1062   (when (or 
1063             (not (or (gnus-news-group-p gnus-newsgroup-name)
1064                      gnus-confirm-treat-mail-like-news))
1065             (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1066                         (string-match gnus-confirm-mail-reply-to-news
1067                                       gnus-newsgroup-name))
1068                        ((functionp gnus-confirm-mail-reply-to-news)
1069                         (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1070                        (t gnus-confirm-mail-reply-to-news)))
1071             (y-or-n-p "Really reply by mail to article author? "))
1072     (let* ((article
1073             (if (listp (car yank))
1074                 (caar yank)
1075               (car yank)))
1076            (gnus-article-reply (or article (gnus-summary-article-number)))
1077            (gnus-article-yanked-articles yank)
1078            (headers ""))
1079       ;; Stripping headers should be specified with mail-yank-ignored-headers.
1080       (when yank
1081         (gnus-summary-goto-subject article))
1082       (gnus-setup-message (if yank 'reply-yank 'reply)
1083         (if (not very-wide)
1084             (gnus-summary-select-article)
1085           (dolist (article very-wide)
1086             (gnus-summary-select-article nil nil nil article)
1087             (save-excursion
1088               (set-buffer (gnus-copy-article-buffer))
1089               (gnus-msg-treat-broken-reply-to)
1090               (save-restriction
1091                 (message-narrow-to-head)
1092                 (setq headers (concat headers (buffer-string)))))))
1093         (set-buffer (gnus-copy-article-buffer))
1094         (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1095         (save-restriction
1096           (message-narrow-to-head)
1097           (when very-wide
1098             (erase-buffer)
1099             (insert headers))
1100           (goto-char (point-max)))
1101         (mml-quote-region (point) (point-max))
1102         (message-reply nil wide)
1103         (when yank
1104           (gnus-inews-yank-articles yank))
1105         (gnus-summary-handle-replysign)))))
1106
1107 (defun gnus-summary-handle-replysign ()
1108   "Check the various replysign variables and take action accordingly."
1109   (when (or gnus-message-replysign gnus-message-replyencrypt)
1110     (let (signed encrypted)
1111       (save-excursion
1112         (set-buffer gnus-article-buffer)
1113         (setq signed (memq 'signed gnus-article-wash-types))
1114         (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1115       (cond ((and gnus-message-replyencrypt encrypted)
1116              (mml-secure-message mml-default-encrypt-method
1117                                  (if gnus-message-replysignencrypted
1118                                      'signencrypt
1119                                    'encrypt)))
1120             ((and gnus-message-replysign signed)
1121              (mml-secure-message mml-default-sign-method 'sign))))))
1122
1123 (defun gnus-summary-reply-with-original (n &optional wide)
1124   "Start composing a reply mail to the current message.
1125 The original article will be yanked."
1126   (interactive "P")
1127   (gnus-summary-reply (gnus-summary-work-articles n) wide))
1128
1129 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1130   "Like `gnus-summary-reply' except removing reply-to field.
1131 If prefix argument YANK is non-nil, the original article is yanked
1132 automatically.
1133 If WIDE, make a wide reply.
1134 If VERY-WIDE, make a very wide reply."
1135   (interactive
1136    (list (and current-prefix-arg
1137               (gnus-summary-work-articles 1))))
1138   (let ((gnus-msg-force-broken-reply-to t))
1139     (gnus-summary-reply yank wide very-wide)))
1140
1141 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1142   "Like `gnus-summary-reply-with-original' except removing reply-to field.
1143 The original article will be yanked."
1144   (interactive "P")
1145   (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1146
1147 (defun gnus-summary-wide-reply (&optional yank)
1148   "Start composing a wide reply mail to the current message.
1149 If prefix argument YANK is non-nil, the original article is yanked
1150 automatically."
1151   (interactive
1152    (list (and current-prefix-arg
1153               (gnus-summary-work-articles 1))))
1154   (gnus-summary-reply yank t))
1155
1156 (defun gnus-summary-wide-reply-with-original (n)
1157   "Start composing a wide reply mail to the current message.
1158 The original article will be yanked."
1159   (interactive "P")
1160   (gnus-summary-reply-with-original n t))
1161
1162 (defun gnus-summary-very-wide-reply (&optional yank)
1163   "Start composing a very wide reply mail to the current message.
1164 If prefix argument YANK is non-nil, the original article is yanked
1165 automatically."
1166   (interactive
1167    (list (and current-prefix-arg
1168               (gnus-summary-work-articles 1))))
1169   (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1170
1171 (defun gnus-summary-very-wide-reply-with-original (n)
1172   "Start composing a very wide reply mail to the current message.
1173 The original article will be yanked."
1174   (interactive "P")
1175   (gnus-summary-reply
1176    (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1177
1178 (defun gnus-summary-mail-forward (&optional arg post)
1179   "Forward the current message(s) to another user.
1180 If process marks exist, forward all marked messages;
1181 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1182 if ARG is 1, decode the message and forward directly inline;
1183 if ARG is 2, forward message as an rfc822 MIME section;
1184 if ARG is 3, decode message and forward as an rfc822 MIME section;
1185 if ARG is 4, forward message directly inline;
1186 otherwise, use flipped `message-forward-as-mime'.
1187 If POST, post instead of mail.
1188 For the `inline' alternatives, also see the variable
1189 `message-forward-ignored-headers'."
1190   (interactive "P")
1191   (if (cdr (gnus-summary-work-articles nil))
1192       ;; Process marks are given.
1193       (gnus-uu-digest-mail-forward arg post)
1194     ;; No process marks.
1195     (let ((message-forward-as-mime message-forward-as-mime)
1196           (message-forward-show-mml message-forward-show-mml))
1197       (cond
1198        ((null arg))
1199        ((eq arg 1)
1200         (setq message-forward-as-mime nil
1201               message-forward-show-mml t))
1202        ((eq arg 2)
1203         (setq message-forward-as-mime t
1204               message-forward-show-mml nil))
1205        ((eq arg 3)
1206         (setq message-forward-as-mime t
1207               message-forward-show-mml t))
1208        ((eq arg 4)
1209         (setq message-forward-as-mime nil
1210               message-forward-show-mml nil))
1211        (t
1212         (setq message-forward-as-mime (not message-forward-as-mime))))
1213       (let* ((gnus-article-reply (gnus-summary-article-number))
1214              (gnus-article-yanked-articles (list gnus-article-reply)))
1215         (gnus-setup-message 'forward
1216           (gnus-summary-select-article)
1217           (let ((mail-parse-charset
1218                  (or (and (gnus-buffer-live-p gnus-article-buffer)
1219                           (with-current-buffer gnus-article-buffer
1220                             gnus-article-charset))
1221                      gnus-newsgroup-charset))
1222                 (mail-parse-ignored-charsets
1223                  gnus-newsgroup-ignored-charsets))
1224             (set-buffer gnus-original-article-buffer)
1225             (message-forward post)))))))
1226
1227 (defun gnus-summary-resend-message (address n)
1228   "Resend the current article to ADDRESS."
1229   (interactive
1230    (list (message-read-from-minibuffer
1231           "Resend message(s) to: "
1232           (when (and gnus-summary-resend-default-address
1233                      (gnus-buffer-live-p gnus-original-article-buffer))
1234             ;; If some other article is currently selected, the
1235             ;; initial-contents is wrong. Whatever, it is just the
1236             ;; initial-contents.
1237             (with-current-buffer gnus-original-article-buffer
1238               (nnmail-fetch-field "to"))))
1239          current-prefix-arg))
1240   (let ((articles (gnus-summary-work-articles n))
1241         article)
1242     (while (setq article (pop articles))
1243       (gnus-summary-select-article nil nil nil article)
1244       (save-excursion
1245         (set-buffer gnus-original-article-buffer)
1246         (message-resend address))
1247       (gnus-summary-mark-article-as-forwarded article))))
1248
1249 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1250 (defun gnus-summary-resend-message-edit ()
1251   "Resend an article that has already been sent.
1252 A new buffer will be created to allow the user to modify body and
1253 contents of the message, and then, everything will happen as when
1254 composing a new message."
1255   (interactive)
1256   (let ((article (gnus-summary-article-number)))
1257     (gnus-setup-message 'reply-yank
1258       (gnus-summary-select-article t)
1259       (set-buffer gnus-original-article-buffer)
1260       (let ((cur (current-buffer))
1261             (to (message-fetch-field "to")))
1262         ;; Get a normal message buffer.
1263         (message-pop-to-buffer (message-buffer-name "Resend" to))
1264         (insert-buffer-substring cur)
1265         (mime-to-mml)
1266         (message-narrow-to-head-1)
1267         ;; Gnus will generate a new one when sending.
1268         (message-remove-header "Message-ID")
1269         (message-remove-header message-ignored-resent-headers t)
1270         ;; Remove unwanted headers.
1271         (goto-char (point-max))
1272         (insert mail-header-separator)
1273         (goto-char (point-min))
1274         (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1275         (forward-char 1)
1276         (widen)))))
1277
1278 (defun gnus-summary-post-forward (&optional arg)
1279   "Forward the current article to a newsgroup.
1280 See `gnus-summary-mail-forward' for ARG."
1281   (interactive "P")
1282   (gnus-summary-mail-forward arg t))
1283
1284 (defvar gnus-nastygram-message
1285   "The following article was inappropriately posted to %s.\n\n"
1286   "Format string to insert in nastygrams.
1287 The current group name will be inserted at \"%s\".")
1288
1289 (defun gnus-summary-mail-nastygram (n)
1290   "Send a nastygram to the author of the current article."
1291   (interactive "P")
1292   (when (or gnus-expert-user
1293             (gnus-y-or-n-p
1294              "Really send a nastygram to the author of the current article? "))
1295     (let ((group gnus-newsgroup-name))
1296       (gnus-summary-reply-with-original n)
1297       (set-buffer gnus-message-buffer)
1298       (message-goto-body)
1299       (insert (format gnus-nastygram-message group))
1300       (message-send-and-exit))))
1301
1302 (defun gnus-summary-mail-crosspost-complaint (n)
1303   "Send a complaint about crossposting to the current article(s)."
1304   (interactive "P")
1305   (let ((articles (gnus-summary-work-articles n))
1306         article)
1307     (while (setq article (pop articles))
1308       (set-buffer gnus-summary-buffer)
1309       (gnus-summary-goto-subject article)
1310       (let ((group (gnus-group-real-name gnus-newsgroup-name))
1311             newsgroups followup-to)
1312         (gnus-summary-select-article)
1313         (set-buffer gnus-original-article-buffer)
1314         (if (and (<= (length (message-tokenize-header
1315                               (setq newsgroups
1316                                     (mail-fetch-field "newsgroups"))
1317                               ", "))
1318                      1)
1319                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
1320                      (not (member group (message-tokenize-header
1321                                          followup-to ", ")))))
1322             (if followup-to
1323                 (gnus-message 1 "Followup-to restricted")
1324               (gnus-message 1 "Not a crossposted article"))
1325           (set-buffer gnus-summary-buffer)
1326           (gnus-summary-reply-with-original 1)
1327           (set-buffer gnus-message-buffer)
1328           (message-goto-body)
1329           (insert (format gnus-crosspost-complaint newsgroups group))
1330           (message-goto-subject)
1331           (re-search-forward " *$")
1332           (replace-match " (crosspost notification)" t t)
1333           (gnus-deactivate-mark)
1334           (when (gnus-y-or-n-p "Send this complaint? ")
1335             (message-send-and-exit)))))))
1336
1337 (defun gnus-mail-parse-comma-list ()
1338   (let (accumulated
1339         beg)
1340     (skip-chars-forward " ")
1341     (while (not (eobp))
1342       (setq beg (point))
1343       (skip-chars-forward "^,")
1344       (while (zerop
1345               (save-excursion
1346                 (save-restriction
1347                   (let ((i 0))
1348                     (narrow-to-region beg (point))
1349                     (goto-char beg)
1350                     (logand (progn
1351                               (while (search-forward "\"" nil t)
1352                                 (incf i))
1353                               (if (zerop i) 2 i))
1354                             2)))))
1355         (skip-chars-forward ",")
1356         (skip-chars-forward "^,"))
1357       (skip-chars-backward " ")
1358       (push (buffer-substring beg (point))
1359             accumulated)
1360       (skip-chars-forward "^,")
1361       (skip-chars-forward ", "))
1362     accumulated))
1363
1364 (defun gnus-inews-add-to-address (group)
1365   (let ((to-address (mail-fetch-field "to")))
1366     (when (and to-address
1367                (gnus-alive-p))
1368       ;; This mail group doesn't have a `to-list', so we add one
1369       ;; here.  Magic!
1370       (when (gnus-y-or-n-p
1371              (format "Do you want to add this as `to-list': %s " to-address))
1372         (gnus-group-add-parameter group (cons 'to-list to-address))))))
1373
1374 (defun gnus-put-message ()
1375   "Put the current message in some group and return to Gnus."
1376   (interactive)
1377   (let ((reply gnus-article-reply)
1378         (winconf gnus-prev-winconf)
1379         (group gnus-newsgroup-name))
1380     (unless (and group
1381                  (not (gnus-group-read-only-p group)))
1382       (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1383
1384     (when (gnus-gethash group gnus-newsrc-hashtb)
1385       (error "No such group: %s" group))
1386     (save-excursion
1387       (save-restriction
1388         (widen)
1389         (message-narrow-to-headers)
1390         (let ((gnus-deletable-headers nil))
1391           (message-generate-headers
1392            (if (message-news-p)
1393                message-required-news-headers
1394              message-required-mail-headers)))
1395         (goto-char (point-max))
1396         (if (string-match " " group)
1397             (insert "Gcc: \"" group "\"\n")
1398           (insert "Gcc: " group "\n"))
1399         (widen)))
1400     (gnus-inews-do-gcc)
1401     (when (and (get-buffer gnus-group-buffer)
1402                (gnus-buffer-exists-p (car-safe reply))
1403                (cdr reply))
1404       (set-buffer (car reply))
1405       (gnus-summary-mark-article-as-replied (cdr reply)))
1406     (when winconf
1407       (set-window-configuration winconf))))
1408
1409 (defun gnus-article-mail (yank)
1410   "Send a reply to the address near point.
1411 If YANK is non-nil, include the original article."
1412   (interactive "P")
1413   (let ((address
1414          (buffer-substring
1415           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1416           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1417     (when address
1418       (gnus-msg-mail address)
1419       (when yank
1420         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1421
1422 (defvar nntp-server-type)
1423 (defun gnus-bug ()
1424   "Send a bug report to the Gnus maintainers."
1425   (interactive)
1426   (unless (gnus-alive-p)
1427     (error "Gnus has been shut down"))
1428   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1429     (unless (message-mail-user-agent)
1430       (delete-other-windows)
1431       (when gnus-bug-create-help-buffer
1432         (switch-to-buffer "*Gnus Help Bug*")
1433         (erase-buffer)
1434         (insert gnus-bug-message)
1435         (goto-char (point-min)))
1436       (message-pop-to-buffer "*Gnus Bug*"))
1437     (let ((message-this-is-mail t))
1438       (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1439     (when gnus-bug-create-help-buffer
1440       (push `(gnus-bug-kill-buffer) message-send-actions))
1441     (goto-char (point-min))
1442     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1443     (forward-line 1)
1444     (insert (gnus-version) "\n"
1445             (emacs-version) "\n")
1446     (when (and (boundp 'nntp-server-type)
1447                (stringp nntp-server-type))
1448       (insert nntp-server-type))
1449     (insert "\n\n\n\n\n")
1450     (let (text)
1451       (save-excursion
1452         (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1453         (erase-buffer)
1454         (gnus-debug)
1455         (setq text (buffer-string)))
1456       (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1457     (goto-char (point-min))
1458     (search-forward "Subject: " nil t)
1459     (message "")))
1460
1461 (defun gnus-bug-kill-buffer ()
1462   (when (get-buffer "*Gnus Help Bug*")
1463     (kill-buffer "*Gnus Help Bug*")))
1464
1465 (defun gnus-summary-yank-message (buffer n)
1466   "Yank the current article into a composed message."
1467   (interactive
1468    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1469          current-prefix-arg))
1470   (gnus-summary-iterate n
1471     (let ((gnus-display-mime-function nil)
1472           (gnus-inhibit-treatment t))
1473       (gnus-summary-select-article))
1474     (save-excursion
1475       (set-buffer buffer)
1476       (message-yank-buffer gnus-article-buffer))))
1477
1478 (defun gnus-debug ()
1479   "Attempts to go through the Gnus source file and report what variables have been changed.
1480 The source file has to be in the Emacs load path."
1481   (interactive)
1482   (let ((files gnus-debug-files)
1483         (point (point))
1484         file expr olist sym)
1485     (gnus-message 4 "Please wait while we snoop your variables...")
1486     (sit-for 0)
1487     ;; Go through all the files looking for non-default values for variables.
1488     (save-excursion
1489       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1490       (while files
1491         (erase-buffer)
1492         (when (and (setq file (locate-library (pop files)))
1493                    (file-exists-p file))
1494           (insert-file-contents file)
1495           (goto-char (point-min))
1496           (if (not (re-search-forward "^;;* *Internal variables" nil t))
1497               (gnus-message 4 "Malformed sources in file %s" file)
1498             (narrow-to-region (point-min) (point))
1499             (goto-char (point-min))
1500             (while (setq expr (ignore-errors (read (current-buffer))))
1501               (ignore-errors
1502                 (and (or (eq (car expr) 'defvar)
1503                          (eq (car expr) 'defcustom))
1504                      (stringp (nth 3 expr))
1505                      (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1506                      (or (not (boundp (nth 1 expr)))
1507                          (not (equal (eval (nth 2 expr))
1508                                      (symbol-value (nth 1 expr)))))
1509                      (push (nth 1 expr) olist)))))))
1510       (kill-buffer (current-buffer)))
1511     (when (setq olist (nreverse olist))
1512       (insert "------------------ Environment follows ------------------\n\n"))
1513     (while olist
1514       (if (boundp (car olist))
1515           (ignore-errors
1516             (pp `(setq ,(car olist)
1517                        ,(if (or (consp (setq sym (symbol-value (car olist))))
1518                                 (and (symbolp sym)
1519                                      (not (or (eq sym nil)
1520                                               (eq sym t)))))
1521                             (list 'quote (symbol-value (car olist)))
1522                           (symbol-value (car olist))))
1523                 (current-buffer)))
1524         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1525       (setq olist (cdr olist)))
1526     (insert "\n\n")
1527     ;; Remove any control chars - they seem to cause trouble for some
1528     ;; mailers.  (Byte-compiled output from the stuff above.)
1529     (goto-char point)
1530     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1531       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1532                      t t))))
1533
1534 ;;; Treatment of rejected articles.
1535 ;;; Bounced mail.
1536
1537 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1538   "Re-mail the current message.
1539 This only makes sense if the current message is a bounce message than
1540 contains some mail you have written which has been bounced back to
1541 you.
1542 If FETCH, try to fetch the article that this is a reply to, if indeed
1543 this is a reply."
1544   (interactive "P")
1545   (gnus-summary-select-article t)
1546   (set-buffer gnus-original-article-buffer)
1547   (gnus-setup-message 'compose-bounce
1548     (let* ((references (mail-fetch-field "references"))
1549            (parent (and references (gnus-parent-id references))))
1550       (message-bounce)
1551       ;; If there are references, we fetch the article we answered to.
1552       (and fetch parent
1553            (gnus-summary-refer-article parent)
1554            (gnus-summary-show-all-headers)))))
1555
1556 ;;; Gcc handling.
1557
1558 (defun gnus-inews-group-method (group)
1559   (cond
1560    ;; If the group doesn't exist, we assume
1561    ;; it's an archive group...
1562    ((and (null (gnus-get-info group))
1563          (eq (car (gnus-server-to-method gnus-message-archive-method))
1564              (car (gnus-server-to-method (gnus-group-method group)))))
1565     gnus-message-archive-method)
1566    ;; Use the method.
1567    ((gnus-info-method (gnus-get-info group))
1568     (gnus-info-method (gnus-get-info group)))
1569    ;; Find the method.
1570    (t (gnus-server-to-method (gnus-group-method group)))))
1571
1572 ;; Do Gcc handling, which copied the message over to some group.
1573 (defun gnus-inews-do-gcc (&optional gcc)
1574   (interactive)
1575   (save-excursion
1576     (save-restriction
1577       (message-narrow-to-headers)
1578       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1579             (cur (current-buffer))
1580             groups group method group-art
1581             mml-externalize-attachments)
1582         (when gcc
1583           (message-remove-header "gcc")
1584           (widen)
1585           (setq groups (message-unquote-tokens
1586                         (message-tokenize-header gcc " ,")))
1587           ;; Copy the article over to some group(s).
1588           (while (setq group (pop groups))
1589             (unless (gnus-check-server
1590                      (setq method (gnus-inews-group-method group)))
1591               (error "Can't open server %s" (if (stringp method) method
1592                                               (car method))))
1593             (unless (gnus-request-group group nil method)
1594               (gnus-request-create-group group method))
1595             (setq mml-externalize-attachments
1596                   (if (stringp gnus-gcc-externalize-attachments)
1597                       (string-match gnus-gcc-externalize-attachments group)
1598                     gnus-gcc-externalize-attachments))
1599             (save-excursion
1600               (nnheader-set-temp-buffer " *acc*")
1601               (insert-buffer-substring cur)
1602               (message-encode-message-body)
1603               (save-restriction
1604                 (message-narrow-to-headers)
1605                 (let* ((mail-parse-charset message-default-charset)
1606                        (newsgroups-field (save-restriction
1607                                            (message-narrow-to-headers-or-head)
1608                                            (message-fetch-field "Newsgroups")))
1609                        (followup-field (save-restriction
1610                                          (message-narrow-to-headers-or-head)
1611                                          (message-fetch-field "Followup-To")))
1612                        ;; BUG: We really need to get the charset for
1613                        ;; each name in the Newsgroups and Followup-To
1614                        ;; lines to allow crossposting between group
1615                        ;; namess with incompatible character sets.
1616                        ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1617                        (group-field-charset
1618                         (gnus-group-name-charset
1619                          method (or newsgroups-field "")))
1620                        (followup-field-charset
1621                         (gnus-group-name-charset
1622                          method (or followup-field "")))
1623                        (rfc2047-header-encoding-alist
1624                         (append
1625                          (when group-field-charset
1626                            (list (cons "Newsgroups" group-field-charset)))
1627                          (when followup-field-charset
1628                            (list (cons "Followup-To" followup-field-charset)))
1629                          rfc2047-header-encoding-alist)))
1630                   (mail-encode-encoded-word-buffer)))
1631               (goto-char (point-min))
1632               (when (re-search-forward
1633                      (concat "^" (regexp-quote mail-header-separator) "$")
1634                      nil t)
1635                 (replace-match "" t t ))
1636               (unless (setq group-art
1637                             (gnus-request-accept-article group method t t))
1638                 (gnus-message 1 "Couldn't store article in group %s: %s"
1639                               group (gnus-status-message method))
1640                 (sit-for 2))
1641               (when (and group-art
1642                          ;; FIXME: Should gcc-mark-as-read work when
1643                          ;; Gnus is not running?
1644                          (gnus-alive-p)
1645                          (or gnus-gcc-mark-as-read
1646                              gnus-inews-mark-gcc-as-read))
1647                 (gnus-group-mark-article-read group (cdr group-art)))
1648               (kill-buffer (current-buffer)))))))))
1649
1650 (defun gnus-inews-insert-gcc ()
1651   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1652   (save-excursion
1653     (save-restriction
1654       (message-narrow-to-headers)
1655       (let* ((group gnus-outgoing-message-group)
1656              (gcc (cond
1657                    ((gnus-functionp group)
1658                     (funcall group))
1659                    ((or (stringp group) (list group))
1660                     group))))
1661         (when gcc
1662           (insert "Gcc: "
1663                   (if (stringp gcc)
1664                       (if (string-match " " gcc)
1665                           (concat "\"" gcc "\"")
1666                         gcc)
1667                     (mapconcat (lambda (group)
1668                                  (if (string-match " " group)
1669                                      (concat "\"" group "\"")
1670                                    group))
1671                                gcc " "))
1672                   "\n"))))))
1673
1674 (defun gnus-inews-insert-archive-gcc (&optional group)
1675   "Insert the Gcc to say where the article is to be archived."
1676   (let* ((var gnus-message-archive-group)
1677          (group (or group gnus-newsgroup-name ""))
1678          (gcc-self-val
1679           (and gnus-newsgroup-name
1680                (not (equal gnus-newsgroup-name ""))
1681                (gnus-group-find-parameter
1682                 gnus-newsgroup-name 'gcc-self)))
1683          result
1684          (groups
1685           (cond
1686            ((null gnus-message-archive-method)
1687             ;; Ignore.
1688             nil)
1689            ((stringp var)
1690             ;; Just a single group.
1691             (list var))
1692            ((null var)
1693             ;; We don't want this.
1694             nil)
1695            ((and (listp var) (stringp (car var)))
1696             ;; A list of groups.
1697             var)
1698            ((gnus-functionp var)
1699             ;; A function.
1700             (funcall var group))
1701            (t
1702             ;; An alist of regexps/functions/forms.
1703             (while (and var
1704                         (not
1705                          (setq result
1706                                (cond
1707                                 ((stringp (caar var))
1708                                  ;; Regexp.
1709                                  (when (string-match (caar var) group)
1710                                    (cdar var)))
1711                                 ((gnus-functionp (car var))
1712                                  ;; Function.
1713                                  (funcall (car var) group))
1714                                 (t
1715                                  (eval (car var)))))))
1716               (setq var (cdr var)))
1717             result)))
1718          name)
1719     (when (or groups gcc-self-val)
1720       (when (stringp groups)
1721         (setq groups (list groups)))
1722       (save-excursion
1723         (save-restriction
1724           (message-narrow-to-headers)
1725           (goto-char (point-max))
1726           (insert "Gcc: ")
1727           (if gcc-self-val
1728               ;; Use the `gcc-self' param value instead.
1729               (progn
1730                 (insert
1731                  (if (stringp gcc-self-val)
1732                      (if (string-match " " gcc-self-val)
1733                          (concat "\"" gcc-self-val "\"")
1734                        gcc-self-val)
1735                    (if (string-match " " group)
1736                        (concat "\"" group "\"")
1737                      group)))
1738                 (if (not (eq gcc-self-val 'none))
1739                     (insert "\n")
1740                   (progn
1741                     (beginning-of-line)
1742                     (kill-line))))
1743             ;; Use the list of groups.
1744             (while (setq name (pop groups))
1745               (let ((str (if (string-match ":" name)
1746                              name
1747                            (gnus-group-prefixed-name
1748                             name gnus-message-archive-method))))
1749                 (insert (if (string-match " " str)
1750                             (concat "\"" str "\"")
1751                           str)))
1752               (when groups
1753                 (insert " ")))
1754             (insert "\n")))))))
1755
1756 ;;; Posting styles.
1757
1758 (defun gnus-configure-posting-styles (&optional group-name)
1759   "Configure posting styles according to `gnus-posting-styles'."
1760   (unless gnus-inhibit-posting-styles
1761     (let ((group (or group-name gnus-newsgroup-name ""))
1762           (styles gnus-posting-styles)
1763           style match variable attribute value v results
1764           filep name address element)
1765       ;; If the group has a posting-style parameter, add it at the end with a
1766       ;; regexp matching everything, to be sure it takes precedence over all
1767       ;; the others.
1768       (when gnus-newsgroup-name
1769         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1770           (when tmp-style
1771             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1772       ;; Go through all styles and look for matches.
1773       (dolist (style styles)
1774         (setq match (pop style))
1775         (goto-char (point-min))
1776         (when (cond
1777                ((stringp match)
1778                 ;; Regexp string match on the group name.
1779                 (string-match match group))
1780                ((eq match 'header)
1781                 ;; Obsolete format of header match.
1782                 (and (gnus-buffer-live-p gnus-article-copy)
1783                      (with-current-buffer gnus-article-copy
1784                        (let ((header (message-fetch-field (pop style))))
1785                          (and header
1786                               (string-match (pop style) header))))))
1787                ((or (symbolp match)
1788                     (gnus-functionp match))
1789                 (cond
1790                  ((gnus-functionp match)
1791                   ;; Function to be called.
1792                   (funcall match))
1793                  ((boundp match)
1794                   ;; Variable to be checked.
1795                   (symbol-value match))))
1796                ((listp match)
1797                 (cond
1798                  ((eq (car match) 'header)
1799                   ;; New format of header match.
1800                   (and (gnus-buffer-live-p gnus-article-copy)
1801                        (with-current-buffer gnus-article-copy
1802                          (let ((header (message-fetch-field (nth 1 match))))
1803                            (and header
1804                                 (string-match (nth 2 match) header))))))
1805                  (t
1806                   ;; This is a form to be evaled.
1807                   (eval match)))))
1808           ;; We have a match, so we set the variables.
1809           (dolist (attribute style)
1810             (setq element (pop attribute)
1811                   variable nil
1812                   filep nil)
1813             (setq value
1814                   (cond
1815                    ((eq (car attribute) :file)
1816                     (setq filep t)
1817                     (cadr attribute))
1818                    ((eq (car attribute) :value)
1819                     (cadr attribute))
1820                    (t
1821                     (car attribute))))
1822             ;; We get the value.
1823             (setq v
1824                   (cond
1825                    ((stringp value)
1826                     value)
1827                    ((or (symbolp value)
1828                         (gnus-functionp value))
1829                     (cond ((gnus-functionp value)
1830                            (funcall value))
1831                           ((boundp value)
1832                            (symbol-value value))))
1833                    ((listp value)
1834                     (eval value))))
1835             ;; Translate obsolescent value.
1836             (cond
1837              ((eq element 'signature-file)
1838               (setq element 'signature
1839                     filep t))
1840              ((eq element 'x-face-file)
1841               (setq element 'x-face
1842                     filep t)))
1843             ;; Get the contents of file elems.
1844             (when (and filep v)
1845               (setq v (with-temp-buffer
1846                         (insert-file-contents v)
1847                         (goto-char (point-max))
1848                         (while (bolp)
1849                           (delete-char -1))
1850                         (buffer-string))))
1851             (setq results (delq (assoc element results) results))
1852             (push (cons element v) results))))
1853       ;; Now we have all the styles, so we insert them.
1854       (setq name (assq 'name results)
1855             address (assq 'address results))
1856       (setq results (delq name (delq address results)))
1857       ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1858       (make-local-hook 'message-setup-hook)
1859       (setq results (sort results (lambda (x y)
1860                                     (string-lessp (car x) (car y)))))
1861       (dolist (result results)
1862         (add-hook 'message-setup-hook
1863                   (cond
1864                    ((eq 'eval (car result))
1865                     'ignore)
1866                    ((eq 'body (car result))
1867                     `(lambda ()
1868                        (save-excursion
1869                          (message-goto-body)
1870                          (insert ,(cdr result)))))
1871                    ((eq 'signature (car result))
1872                     (set (make-local-variable 'message-signature) nil)
1873                     (set (make-local-variable 'message-signature-file) nil)
1874                     (if (not (cdr result))
1875                         'ignore
1876                       `(lambda ()
1877                          (save-excursion
1878                            (let ((message-signature ,(cdr result)))
1879                              (when message-signature
1880                                (message-insert-signature)))))))
1881                    (t
1882                     (let ((header
1883                            (if (symbolp (car result))
1884                                (capitalize (symbol-name (car result)))
1885                              (car result))))
1886                       `(lambda ()
1887                          (save-excursion
1888                            (message-remove-header ,header)
1889                            (let ((value ,(cdr result)))
1890                              (when value
1891                                (message-goto-eoh)
1892                                (insert ,header ": " value)
1893                                (unless (bolp)
1894                                  (insert "\n")))))))))
1895                   nil 'local))
1896       (when (or name address)
1897         (add-hook 'message-setup-hook
1898                   `(lambda ()
1899                      (set (make-local-variable 'user-mail-address)
1900                           ,(or (cdr address) user-mail-address))
1901                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1902                            (user-mail-address
1903                             ,(or (cdr address) user-mail-address)))
1904                        (save-excursion
1905                          (message-remove-header "From")
1906                          (message-goto-eoh)
1907                          (insert "From: " (message-make-from) "\n"))))
1908                   nil 'local)))))
1909
1910 ;;; Allow redefinition of functions.
1911
1912 (gnus-ems-redefine)
1913
1914 (provide 'gnus-msg)
1915
1916 ;;; gnus-msg.el ends here