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