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