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