* gnus-msg.el (gnus-configure-posting-styles): Sort results.
[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   :type '(repeat (cons (choice (regexp)
119                                (variable)
120                                (list (const header)
121                                      (string :tag "Header")
122                                      (regexp :tag "Regexp"))
123                                (function)
124                                (sexp))
125                        (repeat (list
126                                 (choice (const signature)
127                                         (const signature-file)
128                                         (const organization)
129                                         (const address)
130                                         (const x-face-file)
131                                         (const name)
132                                         (const body)
133                                         (symbol)
134                                         (string :tag "Header"))
135                                 (choice (string)
136                                         (function)
137                                         (variable)
138                                         (sexp)))))))
139
140 (defcustom gnus-gcc-mark-as-read nil
141   "If non-nil, automatically mark Gcc articles as read."
142   :version "21.1"
143   :group 'gnus-message
144   :type 'boolean)
145
146 (defvar gnus-inews-mark-gcc-as-read nil
147   "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
148
149 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
150                         'gnus-gcc-mark-as-read)
151
152 (defcustom gnus-gcc-externalize-attachments nil
153   "Should local-file attachments be included as external parts in Gcc copies?
154 If it is `all', attach files as external parts;
155 if a regexp and matches the Gcc group name, attach files as external parts;
156 If nil, attach files as normal parts."
157   :version "21.1"
158   :group 'gnus-message
159   :type '(choice (const nil :tag "None")
160                  (const all :tag "Any")
161                  (string :tag "Regexp")))
162
163 (gnus-define-group-parameter
164  posting-charset-alist
165  :type list
166  :function-document
167  "Return the permitted unencoded charsets for posting of GROUP."
168  :variable gnus-group-posting-charset-alist
169  :variable-default
170   '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
171     ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
172     (message-this-is-mail nil nil)
173     (message-this-is-news nil t))
174  :variable-document
175   "Alist of regexps and permitted unencoded charsets for posting.
176 Each element of the alist has the form (TEST HEADER BODY-LIST), where
177 TEST is either a regular expression matching the newsgroup header or a
178 variable to query,
179 HEADER is the charset which may be left unencoded in the header (nil
180 means encode all charsets),
181 BODY-LIST is a list of charsets which may be encoded using 8bit
182 content-transfer encoding in the body, or one of the special values
183 nil (always encode using quoted-printable) or t (always use 8bit).
184
185 Note that any value other than nil for HEADER infringes some RFCs, so
186 use this option with care."
187  :variable-group gnus-charset
188  :variable-type
189  '(repeat (list :tag "Permitted unencoded charsets"
190                 (choice :tag "Where"
191                         (regexp :tag "Group")
192                         (const :tag "Mail message" :value message-this-is-mail)
193                         (const :tag "News article" :value message-this-is-news))
194                 (choice :tag "Header"
195                         (const :tag "None" nil)
196                         (symbol :tag "Charset"))
197                 (choice :tag "Body"
198                         (const :tag "Any" :value t)
199                         (const :tag "None" :value nil)
200                         (repeat :tag "Charsets"
201                                 (symbol :tag "Charset")))))
202  :parameter-type '(choice :tag "Permitted unencoded charsets"
203                           :value nil
204                           (repeat (symbol)))
205  :parameter-document       "\
206 List of charsets that are permitted to be unencoded.")
207
208 (defcustom gnus-debug-files
209   '("gnus.el" "gnus-sum.el" "gnus-group.el"
210     "gnus-art.el" "gnus-start.el" "gnus-async.el"
211     "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
212     "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
213     "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
214   "Files whose variables will be reported in `gnus-bug'."
215   :version "21.1"
216   :group 'gnus-message
217   :type '(repeat (string :tag "File")))
218
219 (defcustom gnus-debug-exclude-variables
220   '(mm-mime-mule-charset-alist
221     nnmail-split-fancy message-minibuffer-local-map)
222   "Variables that should not be reported in `gnus-bug'."
223   :version "21.1"
224   :group 'gnus-message
225   :type '(repeat (symbol :tag "Variable")))
226
227 (defcustom gnus-discouraged-post-methods
228   '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
229   "A list of back ends that are not used in \"real\" newsgroups.
230 This variable is used only when `gnus-post-method' is `current'."
231   :version "21.3"
232   :group 'gnus-group-foreign
233   :type '(repeat (symbol :tag "Back end")))
234
235 (defcustom gnus-message-replysign
236   nil
237   "Automatically sign replys to signed messages.
238 See also the `mml-default-sign-method' variable."
239   :group 'gnus-message
240   :type 'boolean)
241
242 (defcustom gnus-message-replyencrypt
243   nil
244   "Automatically encrypt replys to encrypted messages.
245 See also the `mml-default-encrypt-method' variable."
246   :group 'gnus-message
247   :type 'boolean)
248
249 (defcustom gnus-message-replysignencrypted
250   t
251   "Setting this causes automatically encryped messages to also be signed."
252   :group 'gnus-message
253   :type 'boolean)
254
255 (defcustom gnus-confirm-mail-reply-to-news nil
256   "If non-nil, Gnus requests confirmation when replying to news.
257 This is done because new users often reply by mistake when reading
258 news."
259   :group 'gnus-message
260   :type 'boolean)
261
262 (defcustom gnus-summary-resend-default-address t
263   "If non-nil, Gnus tries to suggest a default address to resend to.
264 If nil, the address field will always be empty after invoking
265 `gnus-summary-resend-message'."
266   :group 'gnus-message
267   :type 'boolean)
268
269 ;;; Internal variables.
270
271 (defvar gnus-inhibit-posting-styles nil
272   "Inhibit the use of posting styles.")
273
274 (defvar gnus-message-buffer "*Mail Gnus*")
275 (defvar gnus-article-copy nil)
276 (defvar gnus-check-before-posting nil)
277 (defvar gnus-last-posting-server nil)
278 (defvar gnus-message-group-art nil)
279
280 (defvar gnus-msg-force-broken-reply-to nil)
281
282 (defconst gnus-bug-message
283   "Sending a bug report to the Gnus Towers.
284 ========================================
285
286 The buffer below is a mail buffer.  When you press `C-c C-c', it will
287 be sent to the Gnus Bug Exterminators.
288
289 The thing near the bottom of the buffer is how the environment
290 settings will be included in the mail.  Please do not delete that.
291 They will tell the Bug People what your environment is, so that it
292 will be easier to locate the bugs.
293
294 If you have found a bug that makes Emacs go \"beep\", set
295 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
296 and include the backtrace in your bug report.
297
298 Please describe the bug in annoying, painstaking detail.
299
300 Thank you for your help in stamping out bugs.
301 ")
302
303 (eval-and-compile
304   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
305   (autoload 'news-setup "rnewspost")
306   (autoload 'news-reply-mode "rnewspost")
307   (autoload 'rmail-dont-reply-to "mail-utils")
308   (autoload 'rmail-output "rmailout"))
309
310 \f
311 ;;;
312 ;;; Gnus Posting Functions
313 ;;;
314
315 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
316   "p" gnus-summary-post-news
317   "i" gnus-summary-news-other-window
318   "f" gnus-summary-followup
319   "F" gnus-summary-followup-with-original
320   "c" gnus-summary-cancel-article
321   "s" gnus-summary-supersede-article
322   "r" gnus-summary-reply
323   "y" gnus-summary-yank-message
324   "R" gnus-summary-reply-with-original
325   "w" gnus-summary-wide-reply
326   "W" gnus-summary-wide-reply-with-original
327   "v" gnus-summary-very-wide-reply
328   "V" gnus-summary-very-wide-reply-with-original
329   "n" gnus-summary-followup-to-mail
330   "N" gnus-summary-followup-to-mail-with-original
331   "m" gnus-summary-mail-other-window
332   "u" gnus-uu-post-news
333   "\M-c" gnus-summary-mail-crosspost-complaint
334   "Br" gnus-summary-reply-broken-reply-to
335   "BR" gnus-summary-reply-broken-reply-to-with-original
336   "om" gnus-summary-mail-forward
337   "op" gnus-summary-post-forward
338   "Om" gnus-uu-digest-mail-forward
339   "Op" gnus-uu-digest-post-forward)
340
341 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
342   "b" gnus-summary-resend-bounced-mail
343   ;; "c" gnus-summary-send-draft
344   "r" gnus-summary-resend-message
345   "e" gnus-summary-resend-message-edit)
346
347 ;;; Internal functions.
348
349 (defvar gnus-article-reply nil)
350 (defmacro gnus-setup-message (config &rest forms)
351   (let ((winconf (make-symbol "gnus-setup-message-winconf"))
352         (buffer (make-symbol "gnus-setup-message-buffer"))
353         (article (make-symbol "gnus-setup-message-article"))
354         (group (make-symbol "gnus-setup-message-group")))
355     `(let ((,winconf (current-window-configuration))
356            (,buffer (buffer-name (current-buffer)))
357            (,article gnus-article-reply)
358            (,group gnus-newsgroup-name)
359            (message-header-setup-hook
360             (copy-sequence message-header-setup-hook))
361            (mbl mml-buffer-list)
362            (message-mode-hook (copy-sequence message-mode-hook)))
363        (setq mml-buffer-list nil)
364        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
365        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
366        ;; #### FIXME: for a reason that I did not manage to identify yet,
367        ;; the variable `gnus-newsgroup-name' does not honor a dynamically
368        ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
369        ;; After evaluation of @forms below, it gets the value we actually want
370        ;; to override, and the posting styles are used. For that reason, I've
371        ;; added an optional argument to `gnus-configure-posting-styles' to
372        ;; make sure that the correct value for the group name is used. -- drv
373        (add-hook 'message-mode-hook
374                  (lambda ()
375                    (gnus-configure-posting-styles ,group)))
376        (unwind-protect
377            (progn
378              ,@forms)
379          (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config)
380          (gnus-inews-insert-draft-meta-information ,group ,article)
381          (setq gnus-message-buffer (current-buffer))
382          (set (make-local-variable 'gnus-message-group-art)
383               (cons ,group ,article))
384          (set (make-local-variable 'gnus-newsgroup-name) ,group)
385          (gnus-run-hooks 'gnus-message-setup-hook)
386          (if (eq major-mode 'message-mode)
387              (let ((mbl1 mml-buffer-list))
388                (setq mml-buffer-list mbl)  ;; Global value
389                (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
390                ;; LOCAL argument of add-hook differs between GNU Emacs
391                ;; and XEmacs. make-local-hook makes sure they are local.
392                (make-local-hook 'kill-buffer-hook)
393                (make-local-hook 'change-major-mode-hook)
394                (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
395                (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
396            (mml-destroy-buffers)
397            (setq mml-buffer-list mbl)))
398        (gnus-add-buffer)
399        (gnus-configure-windows ,config t)
400        (run-hooks 'post-command-hook)
401        (set-buffer-modified-p nil))))
402
403 (defun gnus-inews-insert-draft-meta-information (group article)
404   (save-excursion
405     (when (and group
406                (not (string= group ""))
407                (not (message-fetch-field gnus-draft-meta-information-header)))
408       (goto-char (point-min))
409       (insert gnus-draft-meta-information-header ": (\"" group "\" "
410               (if article (number-to-string
411                            (if (listp article)
412                                (car article)
413                              article)) "\"\"")
414               ")\n"))))
415
416 ;;;###autoload
417 (defun gnus-msg-mail (&optional to subject other-headers continue
418                                 switch-action yank-action send-actions)
419   "Start editing a mail message to be sent.
420 Like `message-mail', but with Gnus paraphernalia, particularly the
421 Gcc: header for archiving purposes."
422   (interactive)
423   (let ((buf (current-buffer))
424         mail-buf)
425     (gnus-setup-message 'message
426       (message-mail to subject other-headers continue
427                     nil yank-action send-actions))
428     (when switch-action
429       (setq mail-buf (current-buffer))
430       (switch-to-buffer buf)
431       (apply switch-action mail-buf nil)))
432   ;; COMPOSEFUNC should return t if succeed.  Undocumented ???
433   t)
434
435 (defvar save-selected-window-window)
436
437 ;;;###autoload
438 (defun gnus-button-mailto (address)
439   "Mail to ADDRESS."
440   (set-buffer (gnus-copy-article-buffer))
441   (gnus-setup-message 'message
442     (message-reply address))
443   (and (boundp 'save-selected-window-window)
444        (not (window-live-p save-selected-window-window))
445        (setq save-selected-window-window (selected-window))))
446
447 ;;;###autoload
448 (defun gnus-button-reply (&optional to-address wide)
449   "Like `message-reply'."
450   (interactive)
451   (gnus-setup-message 'message
452     (message-reply to-address wide))
453   (and (boundp 'save-selected-window-window)
454        (not (window-live-p save-selected-window-window))
455        (setq save-selected-window-window (selected-window))))
456
457 ;;;###autoload
458 (define-mail-user-agent 'gnus-user-agent
459   'gnus-msg-mail 'message-send-and-exit
460   'message-kill-buffer 'message-send-hook)
461
462 (defun gnus-setup-posting-charset (group)
463   (let ((alist gnus-group-posting-charset-alist)
464         (group (or group ""))
465         elem)
466     (when group
467       (catch 'found
468         (while (setq elem (pop alist))
469           (when (or (and (stringp (car elem))
470                          (string-match (car elem) group))
471                     (and (gnus-functionp (car elem))
472                          (funcall (car elem) group))
473                     (and (symbolp (car elem))
474                          (symbol-value (car elem))))
475             (throw 'found (cons (cadr elem) (caddr elem)))))))))
476
477 (defun gnus-inews-add-send-actions (winconf buffer article &optional config)
478   (make-local-hook 'message-sent-hook)
479   (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
480                                  'gnus-inews-do-gcc) nil t)
481   (when gnus-agent
482     (make-local-hook 'message-header-hook)
483     (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
484   (setq message-post-method
485         `(lambda (arg)
486            (gnus-post-method arg ,gnus-newsgroup-name)))
487   (setq message-newsreader (setq message-mailer (gnus-extended-version)))
488   (message-add-action
489    `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
490   (message-add-action
491    `(when (gnus-buffer-exists-p ,buffer)
492       (save-excursion
493         (set-buffer ,buffer)
494         ,(when article
495            (if (eq config 'forward)
496                `(gnus-summary-mark-article-as-forwarded ',article)
497              `(gnus-summary-mark-article-as-replied ',article)))))
498    'send))
499
500 (put 'gnus-setup-message 'lisp-indent-function 1)
501 (put 'gnus-setup-message 'edebug-form-spec '(form body))
502
503 ;;; Post news commands of Gnus group mode and summary mode
504
505 (defun gnus-group-mail (&optional arg)
506   "Start composing a mail.
507 If ARG, use the group under the point to find a posting style.
508 If ARG is 1, prompt for a group name to find the posting style."
509   (interactive "P")
510   ;; We can't `let' gnus-newsgroup-name here, since that leads
511   ;; to local variables leaking.
512   (let ((group gnus-newsgroup-name)
513         ;; make sure last viewed article doesn't affect posting styles:
514         (gnus-article-copy)
515         (buffer (current-buffer)))
516     (unwind-protect
517         (progn
518           (setq gnus-newsgroup-name
519                 (if arg
520                     (if (= 1 (prefix-numeric-value arg))
521                         (completing-read "Use posting style of group: "
522                                          gnus-active-hashtb nil
523                                          (gnus-read-active-file-p))
524                       (gnus-group-group-name))
525                   ""))
526           ;; #### see comment in gnus-setup-message -- drv
527           (gnus-setup-message 'message (message-mail)))
528       (save-excursion
529         (set-buffer buffer)
530         (setq gnus-newsgroup-name group)))))
531
532 (defun gnus-group-news (&optional arg)
533   "Start composing a news.
534 If ARG, post to group under point.
535 If ARG is 1, prompt for group name to post to.
536
537 This function prepares a news even when using mail groups.  This is useful
538 for posting messages to mail groups without actually sending them over the
539 network.  The corresponding backend must have a 'request-post method."
540   (interactive "P")
541   ;; We can't `let' gnus-newsgroup-name here, since that leads
542   ;; to local variables leaking.
543   (let ((group gnus-newsgroup-name)
544         ;; make sure last viewed article doesn't affect posting styles:
545         (gnus-article-copy)
546         (buffer (current-buffer)))
547     (unwind-protect
548         (progn
549           (setq gnus-newsgroup-name
550                 (if arg
551                     (if (= 1 (prefix-numeric-value arg))
552                         (completing-read "Use group: "
553                                          gnus-active-hashtb nil
554                                          (gnus-read-active-file-p))
555                       (gnus-group-group-name))
556                   ""))
557           ;; #### see comment in gnus-setup-message -- drv
558           (gnus-setup-message 'message
559             (message-news (gnus-group-real-name gnus-newsgroup-name))))
560       (save-excursion
561         (set-buffer buffer)
562         (setq gnus-newsgroup-name group)))))
563
564 (defun gnus-group-post-news (&optional arg)
565   "Start composing a message (a news by default).
566 If ARG, post to group under point.  If ARG is 1, prompt for group name.
567 Depending on the selected group, the message might be either a mail or
568 a news."
569   (interactive "P")
570   ;; Bind this variable here to make message mode hooks work ok.
571   (let ((gnus-newsgroup-name
572          (if arg
573              (if (= 1 (prefix-numeric-value arg))
574                  (completing-read "Newsgroup: " gnus-active-hashtb nil
575                                   (gnus-read-active-file-p))
576                (gnus-group-group-name))
577            ""))
578         ;; make sure last viewed article doesn't affect posting styles:
579         (gnus-article-copy))
580     (gnus-post-news 'post gnus-newsgroup-name)))
581
582 (defun gnus-summary-mail-other-window (&optional arg)
583   "Start composing a mail in another window.
584 Use the posting of the current group by default.
585 If ARG, don't do that.  If ARG is 1, prompt for group name to find the
586 posting style."
587   (interactive "P")
588   ;; We can't `let' gnus-newsgroup-name here, since that leads
589   ;; to local variables leaking.
590   (let ((group gnus-newsgroup-name)
591         ;; make sure last viewed article doesn't affect posting styles:
592         (gnus-article-copy)
593         (buffer (current-buffer)))
594     (unwind-protect
595         (progn
596           (setq gnus-newsgroup-name
597                 (if arg
598                     (if (= 1 (prefix-numeric-value arg))
599                         (completing-read "Use group: "
600                                          gnus-active-hashtb nil
601                                          (gnus-read-active-file-p))
602                       "")
603                   gnus-newsgroup-name))
604           ;; #### see comment in gnus-setup-message -- drv
605           (gnus-setup-message 'message (message-mail)))
606       (save-excursion
607         (set-buffer buffer)
608         (setq gnus-newsgroup-name group)))))
609
610 (defun gnus-summary-news-other-window (&optional arg)
611   "Start composing a news in another window.
612 Post to the current group by default.
613 If ARG, don't do that.  If ARG is 1, prompt for group name to post to.
614
615 This function prepares a news even when using mail groups.  This is useful
616 for posting messages to mail groups without actually sending them over the
617 network.  The corresponding backend must have a 'request-post method."
618   (interactive "P")
619   ;; We can't `let' gnus-newsgroup-name here, since that leads
620   ;; to local variables leaking.
621   (let ((group gnus-newsgroup-name)
622         ;; make sure last viewed article doesn't affect posting styles:
623         (gnus-article-copy)
624         (buffer (current-buffer)))
625     (unwind-protect
626         (progn
627           (setq gnus-newsgroup-name
628                 (if arg
629                     (if (= 1 (prefix-numeric-value arg))
630                         (completing-read "Use group: "
631                                          gnus-active-hashtb nil
632                                          (gnus-read-active-file-p))
633                       "")
634                   gnus-newsgroup-name))
635           ;; #### see comment in gnus-setup-message -- drv
636           (gnus-setup-message 'message
637             (message-news (gnus-group-real-name gnus-newsgroup-name))))
638       (save-excursion
639         (set-buffer buffer)
640         (setq gnus-newsgroup-name group)))))
641
642 (defun gnus-summary-post-news (&optional arg)
643   "Start composing a message.  Post to the current group by default.
644 If ARG, don't do that.  If ARG is 1, prompt for a group name to post to.
645 Depending on the selected group, the message might be either a mail or
646 a news."
647   (interactive "P")
648   ;; Bind this variable here to make message mode hooks work ok.
649   (let ((gnus-newsgroup-name
650          (if arg
651              (if (= 1 (prefix-numeric-value arg))
652                  (completing-read "Newsgroup: " gnus-active-hashtb nil
653                                   (gnus-read-active-file-p))
654                "")
655            gnus-newsgroup-name))
656         ;; make sure last viewed article doesn't affect posting styles:
657         (gnus-article-copy))
658     (gnus-post-news 'post gnus-newsgroup-name)))
659
660
661 (defun gnus-summary-followup (yank &optional force-news)
662   "Compose a followup to an article.
663 If prefix argument YANK is non-nil, the original article is yanked
664 automatically.
665 YANK is a list of elements, where the car of each element is the
666 article number, and the two following numbers is the region to be
667 yanked."
668   (interactive
669    (list (and current-prefix-arg
670               (gnus-summary-work-articles 1))))
671   (when yank
672     (gnus-summary-goto-subject
673      (if (listp (car yank))
674          (caar yank)
675        (car yank))))
676   (save-window-excursion
677     (gnus-summary-select-article))
678   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
679         (gnus-newsgroup-name gnus-newsgroup-name))
680     ;; Send a followup.
681     (gnus-post-news nil gnus-newsgroup-name
682                     headers gnus-article-buffer
683                     yank nil force-news)
684     (gnus-summary-handle-replysign)))
685
686 (defun gnus-summary-followup-with-original (n &optional force-news)
687   "Compose a followup to an article and include the original article."
688   (interactive "P")
689   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
690
691 (defun gnus-summary-followup-to-mail (&optional arg)
692   "Followup to the current mail message via news."
693   (interactive
694    (list (and current-prefix-arg
695               (gnus-summary-work-articles 1))))
696   (gnus-summary-followup arg t))
697
698 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
699   "Followup to the current mail message via news."
700   (interactive "P")
701   (gnus-summary-followup (gnus-summary-work-articles arg) t))
702
703 (defun gnus-inews-yank-articles (articles)
704   (let (beg article yank-string)
705     (message-goto-body)
706     (while (setq article (pop articles))
707       (when (listp article)
708         (setq yank-string (nth 1 article)
709               article (nth 0 article)))
710       (save-window-excursion
711         (set-buffer gnus-summary-buffer)
712         (gnus-summary-select-article nil nil nil article)
713         (gnus-summary-remove-process-mark article))
714       (gnus-copy-article-buffer nil yank-string)
715       (let ((message-reply-buffer gnus-article-copy)
716             (message-reply-headers
717              ;; The headers are decoded.
718              (with-current-buffer gnus-article-copy
719                (save-restriction
720                  (nnheader-narrow-to-headers)
721                  (ietf-drums-unfold-fws)
722                  (nnheader-parse-head t)))))
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 iff 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