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