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