MML buffer leaks.
[gnus] / lisp / gnus-msg.el
1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
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', Gnus will use the \"current\" select
41 method when posting.  If it is nil (which is the default), Gnus will
42 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 nil nor `native', 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   :type `(choice (const nil)
53                  (const current)
54                  (const native)
55                  (sexp :tag "Methods" ,gnus-select-method)))
56
57 (defvar 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
68 (defvar gnus-mailing-list-groups nil
69   "*Regexp matching groups that are really mailing lists.
70 This is useful when you're reading a mailing list that has been
71 gatewayed to a newsgroup, and you want to followup to an article in
72 the group.")
73
74 (defvar gnus-add-to-list nil
75   "*If non-nil, add a `to-list' parameter automatically.")
76
77 (defvar gnus-crosspost-complaint
78   "Hi,
79
80 You posted the article below with the following Newsgroups header:
81
82 Newsgroups: %s
83
84 The %s group, at least, was an inappropriate recipient
85 of this message.  Please trim your Newsgroups header to exclude this
86 group before posting in the future.
87
88 Thank you.
89
90 "
91   "Format string to be inserted when complaining about crossposts.
92 The first %s will be replaced by the Newsgroups header;
93 the second with the current group name.")
94
95 (defvar gnus-message-setup-hook nil
96   "Hook run after setting up a message buffer.")
97
98 (defvar gnus-bug-create-help-buffer t
99   "*Should we create the *Gnus Help Bug* buffer?")
100
101 (defvar gnus-posting-styles nil
102   "*Alist of styles to use when posting.")
103
104 (defcustom gnus-group-posting-charset-alist
105   '(("^\\(no\\|fr\\|dk\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\|dk\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
106     ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
107     (message-this-is-mail nil nil)
108     (message-this-is-news nil t))
109   "Alist of regexps and permitted unencoded charsets for posting.
110 Each element of the alist has the form (TEST HEADER BODY-LIST), where
111 TEST is either a regular expression matching the newsgroup header or a
112 variable to query,
113 HEADER is the charset which may be left unencoded in the header (nil
114 means encode all charsets),
115 BODY-LIST is a list of charsets which may be encoded using 8bit
116 content-transfer encoding in the body, or one of the special values
117 nil (always encode using quoted-printable) or t (always use 8bit).
118
119 Note that any value other than nil for HEADER infringes some RFCs, so
120 use this option with care."
121   :type '(repeat (list :tag "Permitted unencoded charsets"
122                   (choice :tag "Where"
123                    (regexp :tag "Group")
124                    (const :tag "Mail message" :value message-this-is-mail)
125                    (const :tag "News article" :value message-this-is-news))
126                   (choice :tag "Header"
127                    (const :tag "None" nil)
128                    (symbol :tag "Charset"))
129                   (choice :tag "Body"
130                           (const :tag "Any" :value t)
131                           (const :tag "None" :value nil)
132                           (repeat :tag "Charsets"
133                                   (symbol :tag "Charset")))))
134   :group 'gnus-charset)
135
136 ;;; Internal variables.
137
138 (defvar gnus-inhibit-posting-styles nil
139   "Inhibit the use of posting styles.")
140
141 (defvar gnus-message-buffer "*Mail Gnus*")
142 (defvar gnus-article-copy nil)
143 (defvar gnus-last-posting-server nil)
144 (defvar gnus-message-group-art nil)
145
146 (defconst gnus-bug-message
147   "Sending a bug report to the Gnus Towers.
148 ========================================
149
150 The buffer below is a mail buffer.  When you press `C-c C-c', it will
151 be sent to the Gnus Bug Exterminators.
152
153 The thing near the bottom of the buffer is how the environment
154 settings will be included in the mail.  Please do not delete that.
155 They will tell the Bug People what your environment is, so that it
156 will be easier to locate the bugs.
157
158 If you have found a bug that makes Emacs go \"beep\", set
159 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
160 and include the backtrace in your bug report.
161
162 Please describe the bug in annoying, painstaking detail.
163
164 Thank you for your help in stamping out bugs.
165 ")
166
167 (eval-and-compile
168   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
169   (autoload 'news-setup "rnewspost")
170   (autoload 'news-reply-mode "rnewspost")
171   (autoload 'rmail-dont-reply-to "mail-utils")
172   (autoload 'rmail-output "rmailout"))
173
174 \f
175 ;;;
176 ;;; Gnus Posting Functions
177 ;;;
178
179 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
180   "p" gnus-summary-post-news
181   "f" gnus-summary-followup
182   "F" gnus-summary-followup-with-original
183   "c" gnus-summary-cancel-article
184   "s" gnus-summary-supersede-article
185   "r" gnus-summary-reply
186   "y" gnus-summary-yank-message
187   "R" gnus-summary-reply-with-original
188   "w" gnus-summary-wide-reply
189   "W" gnus-summary-wide-reply-with-original
190   "n" gnus-summary-followup-to-mail
191   "N" gnus-summary-followup-to-mail-with-original
192   "m" gnus-summary-mail-other-window
193   "u" gnus-uu-post-news
194   "\M-c" gnus-summary-mail-crosspost-complaint
195   "om" gnus-summary-mail-forward
196   "op" gnus-summary-post-forward
197   "Om" gnus-uu-digest-mail-forward
198   "Op" gnus-uu-digest-post-forward)
199
200 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
201   "b" gnus-summary-resend-bounced-mail
202   ;; "c" gnus-summary-send-draft
203   "r" gnus-summary-resend-message)
204
205 ;;; Internal functions.
206
207 (defvar gnus-article-reply nil)
208 (defmacro gnus-setup-message (config &rest forms)
209   (let ((winconf (make-symbol "gnus-setup-message-winconf"))
210         (buffer (make-symbol "gnus-setup-message-buffer"))
211         (article (make-symbol "gnus-setup-message-article"))
212         (group (make-symbol "gnus-setup-message-group")))
213     `(let ((,winconf (current-window-configuration))
214            (,buffer (buffer-name (current-buffer)))
215            (,article (and gnus-article-reply (gnus-summary-article-number)))
216            (,group gnus-newsgroup-name)
217            (message-header-setup-hook
218             (copy-sequence message-header-setup-hook))
219            (mbl mml-buffer-list)
220            (message-mode-hook (copy-sequence message-mode-hook)))
221        (setq mml-buffer-list nil)
222        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
223        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
224        (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
225        (unwind-protect
226            (progn
227              ,@forms)
228          (gnus-inews-add-send-actions ,winconf ,buffer ,article)
229          (setq gnus-message-buffer (current-buffer))
230          (set (make-local-variable 'gnus-message-group-art)
231               (cons ,group ,article))
232          (set (make-local-variable 'gnus-newsgroup-name) ,group)
233          (gnus-run-hooks 'gnus-message-setup-hook)
234          (if (eq major-mode 'message-mode)
235              ;; Make mml-buffer-list local.
236              ;; Restore global mml-buffer-list value as mbl.
237              ;; What a hack! -- Shenghuo
238              (let ((mml-buffer-list mml-buffer-list))
239                (setq mml-buffer-list mbl)
240                (make-local-variable 'mml-buffer-list)
241                (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
242            (mml-destroy-buffers)
243            (setq mml-buffer-list mbl)))
244        (gnus-add-buffer)
245        (gnus-configure-windows ,config t)
246        (set-buffer-modified-p nil))))
247
248 (defun gnus-setup-posting-charset (group)
249   (let ((alist gnus-group-posting-charset-alist)
250         (group (or group ""))
251         elem)
252     (when group
253       (catch 'found
254         (while (setq elem (pop alist))
255           (when (or (and (stringp (car elem))
256                          (string-match (car elem) group))
257                     (and (gnus-functionp (car elem))
258                          (funcall (car elem) group))
259                     (and (symbolp (car elem))
260                          (symbol-value (car elem))))
261             (throw 'found (cons (cadr elem) (caddr elem)))))))))
262
263 (defun gnus-inews-add-send-actions (winconf buffer article)
264   (make-local-hook 'message-sent-hook)
265   (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
266   (setq message-post-method
267         `(lambda (arg)
268            (gnus-post-method arg ,gnus-newsgroup-name)))
269   (setq message-newsreader (setq message-mailer (gnus-extended-version)))
270   (message-add-action
271    `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
272   (message-add-action
273    `(when (gnus-buffer-exists-p ,buffer)
274       (save-excursion
275         (set-buffer ,buffer)
276         ,(when article
277            `(gnus-summary-mark-article-as-replied ,article))))
278    'send))
279
280 (put 'gnus-setup-message 'lisp-indent-function 1)
281 (put 'gnus-setup-message 'edebug-form-spec '(form body))
282
283 ;;; Post news commands of Gnus group mode and summary mode
284
285 (defun gnus-group-mail (&optional arg)
286   "Start composing a mail.
287 If ARG, use the group under the point to find a posting style.
288 If ARG is 1, prompt for a group name to find the posting style."
289   (interactive "P")
290   ;; We can't `let' gnus-newsgroup-name here, since that leads
291   ;; to local variables leaking.
292   (let ((group gnus-newsgroup-name)
293         (buffer (current-buffer)))
294     (unwind-protect
295         (progn
296           (setq gnus-newsgroup-name
297                 (if arg
298                     (if (= 1 (prefix-numeric-value arg))
299                         (completing-read "Use posting style of group: "
300                                          gnus-active-hashtb nil
301                                          (gnus-read-active-file-p))
302                       (gnus-group-group-name))
303                   ""))
304           (gnus-setup-message 'message (message-mail)))
305       (save-excursion
306         (set-buffer buffer)
307         (setq gnus-newsgroup-name group)))))
308
309 (defun gnus-group-post-news (&optional arg)
310   "Start composing a news message.
311 If ARG, post to the group under point.
312 If ARG is 1, prompt for a group name."
313   (interactive "P")
314   ;; Bind this variable here to make message mode hooks work ok.
315   (let ((gnus-newsgroup-name
316          (if arg
317              (if (= 1 (prefix-numeric-value arg))
318                  (completing-read "Newsgroup: " gnus-active-hashtb nil
319                                   (gnus-read-active-file-p))
320                (gnus-group-group-name))
321            "")))
322     (gnus-post-news 'post gnus-newsgroup-name)))
323
324 (defun gnus-summary-post-news ()
325   "Start composing a news message."
326   (interactive)
327   (gnus-post-news 'post gnus-newsgroup-name))
328
329 (defun gnus-summary-followup (yank &optional force-news)
330   "Compose a followup to an article.
331 If prefix argument YANK is non-nil, original article is yanked automatically."
332   (interactive
333    (list (and current-prefix-arg
334               (gnus-summary-work-articles 1))))
335   (when yank
336     (gnus-summary-goto-subject (car yank)))
337   (save-window-excursion
338     (gnus-summary-select-article))
339   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
340         (gnus-newsgroup-name gnus-newsgroup-name))
341     ;; Send a followup.
342     (gnus-post-news nil gnus-newsgroup-name
343                     headers gnus-article-buffer
344                     yank nil force-news)))
345
346 (defun gnus-summary-followup-with-original (n &optional force-news)
347   "Compose a followup to an article and include the original article."
348   (interactive "P")
349   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
350
351 (defun gnus-summary-followup-to-mail (&optional arg)
352   "Followup to the current mail message via news."
353   (interactive
354    (list (and current-prefix-arg
355               (gnus-summary-work-articles 1))))
356   (gnus-summary-followup arg t))
357
358 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
359   "Followup to the current mail message via news."
360   (interactive "P")
361   (gnus-summary-followup (gnus-summary-work-articles arg) t))
362
363 (defun gnus-inews-yank-articles (articles)
364   (let (beg article)
365     (message-goto-body)
366     (while (setq article (pop articles))
367       (save-window-excursion
368         (set-buffer gnus-summary-buffer)
369         (gnus-summary-select-article nil nil nil article)
370         (gnus-summary-remove-process-mark article))
371       (gnus-copy-article-buffer)
372       (let ((message-reply-buffer gnus-article-copy)
373             (message-reply-headers gnus-current-headers))
374         (message-yank-original)
375         (setq beg (or beg (mark t))))
376       (when articles
377         (insert "\n")))
378     (push-mark)
379     (goto-char beg)))
380
381 (defun gnus-summary-cancel-article (&optional n symp)
382   "Cancel an article you posted.
383 Uses the process-prefix convention.  If given the symbolic
384 prefix `a', cancel using the standard posting method; if not
385 post using the current select method."
386   (interactive (gnus-interactive "P\ny"))
387   (let ((articles (gnus-summary-work-articles n))
388         (message-post-method
389          `(lambda (arg)
390             (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
391         article)
392     (while (setq article (pop articles))
393       (when (gnus-summary-select-article t nil nil article)
394         (when (gnus-eval-in-buffer-window gnus-original-article-buffer
395                 (message-cancel-news))
396           (gnus-summary-mark-as-read article gnus-canceled-mark)
397           (gnus-cache-remove-article 1))
398         (gnus-article-hide-headers-if-wanted))
399       (gnus-summary-remove-process-mark article))))
400
401 (defun gnus-summary-supersede-article ()
402   "Compose an article that will supersede a previous article.
403 This is done simply by taking the old article and adding a Supersedes
404 header line with the old Message-ID."
405   (interactive)
406   (let ((article (gnus-summary-article-number)))
407     (gnus-setup-message 'reply-yank
408       (gnus-summary-select-article t)
409       (set-buffer gnus-original-article-buffer)
410       (message-supersede)
411       (push
412        `((lambda ()
413            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
414              (save-excursion
415                (set-buffer ,gnus-summary-buffer)
416                (gnus-cache-possibly-remove-article ,article nil nil nil t)
417                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
418        message-send-actions))))
419
420 \f
421
422 (defun gnus-copy-article-buffer (&optional article-buffer)
423   ;; make a copy of the article buffer with all text properties removed
424   ;; this copy is in the buffer gnus-article-copy.
425   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
426   ;; this buffer should be passed to all mail/news reply/post routines.
427   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
428   (save-excursion
429     (set-buffer gnus-article-copy)
430     (mm-enable-multibyte))
431   (let ((article-buffer (or article-buffer gnus-article-buffer))
432         end beg)
433     (if (not (and (get-buffer article-buffer)
434                   (gnus-buffer-exists-p article-buffer)))
435         (error "Can't find any article buffer")
436       (save-excursion
437         (set-buffer article-buffer)
438         (save-restriction
439           ;; Copy over the (displayed) article buffer, delete
440           ;; hidden text and remove text properties.
441           (widen)
442           (copy-to-buffer gnus-article-copy (point-min) (point-max))
443           (set-buffer gnus-article-copy)
444           (gnus-article-delete-text-of-type 'annotation)
445           (gnus-remove-text-with-property 'gnus-prev)
446           (gnus-remove-text-with-property 'gnus-next)
447           (insert
448            (prog1
449                (format "%s" (buffer-string))
450              (erase-buffer)))
451           ;; Find the original headers.
452           (set-buffer gnus-original-article-buffer)
453           (goto-char (point-min))
454           (while (looking-at message-unix-mail-delimiter)
455             (forward-line 1))
456           (setq beg (point))
457           (setq end (or (search-forward "\n\n" nil t) (point)))
458           ;; Delete the headers from the displayed articles.
459           (set-buffer gnus-article-copy)
460           (delete-region (goto-char (point-min))
461                          (or (search-forward "\n\n" nil t) (point-max)))
462           ;; Insert the original article headers.
463           (insert-buffer-substring gnus-original-article-buffer beg end)
464           (article-decode-encoded-words)))
465       gnus-article-copy)))
466
467 (defun gnus-post-news (post &optional group header article-buffer yank subject
468                             force-news)
469   (when article-buffer
470     (gnus-copy-article-buffer))
471   (let ((gnus-article-reply article-buffer)
472         (add-to-list gnus-add-to-list))
473     (gnus-setup-message (cond (yank 'reply-yank)
474                               (article-buffer 'reply)
475                               (t 'message))
476       (let* ((group (or group gnus-newsgroup-name))
477              (pgroup group)
478              to-address to-group mailing-list to-list
479              newsgroup-p)
480         (when group
481           (setq to-address (gnus-group-find-parameter group 'to-address)
482                 to-group (gnus-group-find-parameter group 'to-group)
483                 to-list (gnus-group-find-parameter group 'to-list)
484                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
485                 mailing-list (when gnus-mailing-list-groups
486                                (string-match gnus-mailing-list-groups group))
487                 group (gnus-group-real-name group)))
488         (if (or (and to-group
489                      (gnus-news-group-p to-group))
490                 newsgroup-p
491                 force-news
492                 (and (gnus-news-group-p
493                       (or pgroup gnus-newsgroup-name)
494                       (if header (mail-header-number header)
495                         gnus-current-article))
496                      (not mailing-list)
497                      (not to-list)
498                      (not to-address)))
499             ;; This is news.
500             (if post
501                 (message-news (or to-group group))
502               (set-buffer gnus-article-copy)
503               (gnus-msg-treat-broken-reply-to)
504               (message-followup (if (or newsgroup-p force-news) nil to-group)))
505           ;; The is mail.
506           (if post
507               (progn
508                 (message-mail (or to-address to-list))
509                 ;; Arrange for mail groups that have no `to-address' to
510                 ;; get that when the user sends off the mail.
511                 (when (and (not to-list)
512                            (not to-address)
513                            add-to-list)
514                   (push (list 'gnus-inews-add-to-address pgroup)
515                         message-send-actions)))
516             (set-buffer gnus-article-copy)
517             (gnus-msg-treat-broken-reply-to)
518             (message-wide-reply to-address)))
519         (when yank
520           (gnus-inews-yank-articles yank))))))
521
522 (defun gnus-msg-treat-broken-reply-to ()
523   "Remove the Reply-to header iff broken-reply-to."
524   (when (gnus-group-find-parameter
525          gnus-newsgroup-name 'broken-reply-to)
526     (save-restriction
527       (message-narrow-to-head)
528       (message-remove-header "reply-to"))))
529
530 (defun gnus-post-method (arg group &optional silent)
531   "Return the posting method based on GROUP and ARG.
532 If SILENT, don't prompt the user."
533   (let ((group-method (gnus-find-method-for-group group)))
534     (cond
535      ;; If the group-method is nil (which shouldn't happen) we use
536      ;; the default method.
537      ((null group-method)
538       (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
539           gnus-select-method message-post-method))
540      ;; We want the inverse of the default
541      ((and arg (not (eq arg 0)))
542       (if (eq gnus-post-method 'active)
543           gnus-select-method
544         group-method))
545      ;; We query the user for a post method.
546      ((or arg
547           (and gnus-post-method
548                (not (eq gnus-post-method 'current))
549                (listp (car gnus-post-method))))
550       (let* ((methods
551               ;; Collect all methods we know about.
552               (append
553                (when (and gnus-post-method
554                           (not (eq gnus-post-method 'current)))
555                  (if (listp (car gnus-post-method))
556                      gnus-post-method
557                    (list gnus-post-method)))
558                gnus-secondary-select-methods
559                (mapcar 'cdr gnus-server-alist)
560                (mapcar 'car gnus-opened-servers)
561                (list gnus-select-method)
562                (list group-method)))
563              method-alist post-methods method)
564         ;; Weed out all mail methods.
565         (while methods
566           (setq method (gnus-server-get-method "" (pop methods)))
567           (when (and (or (gnus-method-option-p method 'post)
568                          (gnus-method-option-p method 'post-mail))
569                      (not (member method post-methods)))
570             (push method post-methods)))
571         ;; Create a name-method alist.
572         (setq method-alist
573               (mapcar
574                (lambda (m)
575                  (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
576                post-methods))
577         ;; Query the user.
578         (cadr
579          (assoc
580           (setq gnus-last-posting-server
581                 (if (and silent
582                          gnus-last-posting-server)
583                     ;; Just use the last value.
584                     gnus-last-posting-server
585                   (completing-read
586                    "Posting method: " method-alist nil t
587                    (cons (or gnus-last-posting-server "") 0))))
588           method-alist))))
589      ;; Override normal method.
590      ((and (eq gnus-post-method 'current)
591            (not (eq (car group-method) 'nndraft))
592            (gnus-get-function group-method 'request-post t)
593            (not arg))
594       group-method)
595      ((and gnus-post-method
596            (not (eq gnus-post-method 'current)))
597       gnus-post-method)
598      ;; Use the normal select method.
599      (t gnus-select-method))))
600
601 \f
602
603 ;; Dummies to avoid byte-compile warning.
604 (defvar nnspool-rejected-article-hook)
605 (defvar xemacs-codename)
606
607 (defun gnus-extended-version ()
608   "Stringified Gnus version and Emacs version."
609   (interactive)
610   (concat
611    "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
612    " (" gnus-version ")"
613    " "
614    (cond
615     ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
616      (concat "Emacs/" (match-string 1 emacs-version)))
617     ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
618                    emacs-version)
619      (concat (match-string 1 emacs-version)
620              (format "/%d.%d" emacs-major-version emacs-minor-version)
621              (if (match-beginning 3)
622                  (match-string 3 emacs-version)
623                "")
624              (if (boundp 'xemacs-codename)
625                  (concat " (" xemacs-codename ")")
626                "")))
627     (t emacs-version))))
628
629 \f
630 ;;;
631 ;;; Gnus Mail Functions
632 ;;;
633
634 ;;; Mail reply commands of Gnus summary mode
635
636 (defun gnus-summary-reply (&optional yank wide)
637   "Start composing a reply mail to the current message.
638 If prefix argument YANK is non-nil, the original article is yanked
639 automatically."
640   (interactive
641    (list (and current-prefix-arg
642               (gnus-summary-work-articles 1))))
643   ;; Stripping headers should be specified with mail-yank-ignored-headers.
644   (when yank
645     (gnus-summary-goto-subject (car yank)))
646   (let ((gnus-article-reply t))
647     (gnus-setup-message (if yank 'reply-yank 'reply)
648       (gnus-summary-select-article)
649       (set-buffer (gnus-copy-article-buffer))
650       (gnus-msg-treat-broken-reply-to)
651       (message-reply nil wide)
652       (when yank
653         (gnus-inews-yank-articles yank)))))
654
655 (defun gnus-summary-reply-with-original (n &optional wide)
656   "Start composing a reply mail to the current message.
657 The original article will be yanked."
658   (interactive "P")
659   (gnus-summary-reply (gnus-summary-work-articles n) wide))
660
661 (defun gnus-summary-wide-reply (&optional yank)
662   "Start composing a wide reply mail to the current message.
663 If prefix argument YANK is non-nil, the original article is yanked
664 automatically."
665   (interactive
666    (list (and current-prefix-arg
667               (gnus-summary-work-articles 1))))
668   (gnus-summary-reply yank t))
669
670 (defun gnus-summary-wide-reply-with-original (n)
671   "Start composing a wide reply mail to the current message.
672 The original article will be yanked."
673   (interactive "P")
674   (gnus-summary-reply-with-original n t))
675
676 (defun gnus-summary-mail-forward (&optional arg post)
677   "Forward the current message to another user.  
678 If ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
679 if ARG is 1, decode the message and forward directly inline;
680 if ARG is 2, foward message as an rfc822 MIME section;
681 if ARG is 3, decode message and forward as an rfc822 MIME section;
682 if ARG is 4, foward message directly inline;
683 otherwise, use flipped `message-forward-as-mime'.
684 If POST, post instead of mail."
685   (interactive "P")
686   (let ((message-forward-as-mime message-forward-as-mime)
687         (message-forward-show-mml message-forward-show-mml))
688     (cond 
689      ((null arg))
690      ((eq arg 1) (setq message-forward-as-mime nil
691                        message-forward-show-mml t))
692      ((eq arg 2) (setq message-forward-as-mime t
693                        message-forward-show-mml nil))
694      ((eq arg 3) (setq message-forward-as-mime t
695                        message-forward-show-mml t))
696      ((eq arg 4) (setq message-forward-as-mime nil
697                        message-forward-show-mml nil))
698      (t (setq message-forward-as-mime (not message-forward-as-mime))))
699     (gnus-setup-message 'forward
700       (gnus-summary-select-article)
701       (let ((mail-parse-charset gnus-newsgroup-charset)
702             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
703             text)
704         (save-excursion
705           (set-buffer gnus-original-article-buffer)
706           (mm-with-unibyte-current-buffer
707             (setq text (buffer-string))))
708         (set-buffer 
709          (gnus-get-buffer-create
710           (generate-new-buffer-name " *Gnus forward*")))
711         (erase-buffer)
712         (mm-disable-multibyte)
713         (insert text)
714         (goto-char (point-min))
715         (when (looking-at "From ")
716           (replace-match "X-From-Line: ") )
717         (when message-forward-show-mml
718           (mm-enable-multibyte)
719           (mime-to-mml))
720         (message-forward post)))))
721
722 (defun gnus-summary-resend-message (address n)
723   "Resend the current article to ADDRESS."
724   (interactive "sResend message(s) to: \nP")
725   (let ((articles (gnus-summary-work-articles n))
726         article)
727     (while (setq article (pop articles))
728       (gnus-summary-select-article nil nil nil article)
729       (save-excursion
730         (set-buffer gnus-original-article-buffer)
731         (message-resend address)))))
732
733 (defun gnus-summary-post-forward (&optional arg)
734   "Forward the current article to a newsgroup.
735 See `gnus-summary-mail-forward' for ARG."
736   (interactive "P")
737   (gnus-summary-mail-forward arg t))
738
739 (defvar gnus-nastygram-message
740   "The following article was inappropriately posted to %s.\n\n"
741   "Format string to insert in nastygrams.
742 The current group name will be inserted at \"%s\".")
743
744 (defun gnus-summary-mail-nastygram (n)
745   "Send a nastygram to the author of the current article."
746   (interactive "P")
747   (when (or gnus-expert-user
748             (gnus-y-or-n-p
749              "Really send a nastygram to the author of the current article? "))
750     (let ((group gnus-newsgroup-name))
751       (gnus-summary-reply-with-original n)
752       (set-buffer gnus-message-buffer)
753       (message-goto-body)
754       (insert (format gnus-nastygram-message group))
755       (message-send-and-exit))))
756
757 (defun gnus-summary-mail-crosspost-complaint (n)
758   "Send a complaint about crossposting to the current article(s)."
759   (interactive "P")
760   (let ((articles (gnus-summary-work-articles n))
761         article)
762     (while (setq article (pop articles))
763       (set-buffer gnus-summary-buffer)
764       (gnus-summary-goto-subject article)
765       (let ((group (gnus-group-real-name gnus-newsgroup-name))
766             newsgroups followup-to)
767         (gnus-summary-select-article)
768         (set-buffer gnus-original-article-buffer)
769         (if (and (<= (length (message-tokenize-header
770                               (setq newsgroups
771                                     (mail-fetch-field "newsgroups"))
772                               ", "))
773                      1)
774                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
775                      (not (member group (message-tokenize-header
776                                          followup-to ", ")))))
777             (if followup-to
778                 (gnus-message 1 "Followup-to restricted")
779               (gnus-message 1 "Not a crossposted article"))
780           (set-buffer gnus-summary-buffer)
781           (gnus-summary-reply-with-original 1)
782           (set-buffer gnus-message-buffer)
783           (message-goto-body)
784           (insert (format gnus-crosspost-complaint newsgroups group))
785           (message-goto-subject)
786           (re-search-forward " *$")
787           (replace-match " (crosspost notification)" t t)
788           (gnus-deactivate-mark)
789           (when (gnus-y-or-n-p "Send this complaint? ")
790             (message-send-and-exit)))))))
791
792 (defun gnus-summary-mail-other-window ()
793   "Compose mail in other window."
794   (interactive)
795   (gnus-setup-message 'message
796     (message-mail)))
797
798 (defun gnus-mail-parse-comma-list ()
799   (let (accumulated
800         beg)
801     (skip-chars-forward " ")
802     (while (not (eobp))
803       (setq beg (point))
804       (skip-chars-forward "^,")
805       (while (zerop
806               (save-excursion
807                 (save-restriction
808                   (let ((i 0))
809                     (narrow-to-region beg (point))
810                     (goto-char beg)
811                     (logand (progn
812                               (while (search-forward "\"" nil t)
813                                 (incf i))
814                               (if (zerop i) 2 i))
815                             2)))))
816         (skip-chars-forward ",")
817         (skip-chars-forward "^,"))
818       (skip-chars-backward " ")
819       (push (buffer-substring beg (point))
820             accumulated)
821       (skip-chars-forward "^,")
822       (skip-chars-forward ", "))
823     accumulated))
824
825 (defun gnus-inews-add-to-address (group)
826   (let ((to-address (mail-fetch-field "to")))
827     (when (and to-address
828                (gnus-alive-p))
829       ;; This mail group doesn't have a `to-list', so we add one
830       ;; here.  Magic!
831       (when (gnus-y-or-n-p
832              (format "Do you want to add this as `to-list': %s " to-address))
833         (gnus-group-add-parameter group (cons 'to-list to-address))))))
834
835 (defun gnus-put-message ()
836   "Put the current message in some group and return to Gnus."
837   (interactive)
838   (let ((reply gnus-article-reply)
839         (winconf gnus-prev-winconf)
840         (group gnus-newsgroup-name))
841
842     (or (and group (not (gnus-group-read-only-p group)))
843         (setq group (read-string "Put in group: " nil
844                                  (gnus-writable-groups))))
845     (when (gnus-gethash group gnus-newsrc-hashtb)
846       (error "No such group: %s" group))
847
848     (save-excursion
849       (save-restriction
850         (widen)
851         (message-narrow-to-headers)
852         (let (gnus-deletable-headers)
853           (if (message-news-p)
854               (message-generate-headers message-required-news-headers)
855             (message-generate-headers message-required-mail-headers)))
856         (goto-char (point-max))
857         (insert "Gcc: " group "\n")
858         (widen)))
859
860     (gnus-inews-do-gcc)
861
862     (when (get-buffer gnus-group-buffer)
863       (when (gnus-buffer-exists-p (car-safe reply))
864         (set-buffer (car reply))
865         (and (cdr reply)
866              (gnus-summary-mark-article-as-replied
867               (cdr reply))))
868       (when winconf
869         (set-window-configuration winconf)))))
870
871 (defun gnus-article-mail (yank)
872   "Send a reply to the address near point.
873 If YANK is non-nil, include the original article."
874   (interactive "P")
875   (let ((address
876          (buffer-substring
877           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
878           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
879     (when address
880       (message-reply address)
881       (when yank
882         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
883
884 (defvar nntp-server-type)
885 (defun gnus-bug ()
886   "Send a bug report to the Gnus maintainers."
887   (interactive)
888   (unless (gnus-alive-p)
889     (error "Gnus has been shut down"))
890   (gnus-setup-message 'bug
891     (delete-other-windows)
892     (when gnus-bug-create-help-buffer
893       (switch-to-buffer "*Gnus Help Bug*")
894       (erase-buffer)
895       (insert gnus-bug-message)
896       (goto-char (point-min)))
897     (message-pop-to-buffer "*Gnus Bug*")
898     (message-setup `((To . ,gnus-maintainer) (Subject . "")))
899     (when gnus-bug-create-help-buffer
900       (push `(gnus-bug-kill-buffer) message-send-actions))
901     (goto-char (point-min))
902     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
903     (forward-line 1)
904     (insert (gnus-version) "\n"
905             (emacs-version) "\n")
906     (when (and (boundp 'nntp-server-type)
907                (stringp nntp-server-type))
908       (insert nntp-server-type))
909     (insert "\n\n\n\n\n")
910     (let (text)
911       (save-excursion
912         (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
913         (gnus-debug)
914         (setq text (buffer-string)))
915       (insert "<#part type=application/x-emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
916     (goto-char (point-min))
917     (search-forward "Subject: " nil t)
918     (message "")))
919
920 (defun gnus-bug-kill-buffer ()
921   (when (get-buffer "*Gnus Help Bug*")
922     (kill-buffer "*Gnus Help Bug*")))
923
924 (defun gnus-summary-yank-message (buffer n)
925   "Yank the current article into a composed message."
926   (interactive
927    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
928          current-prefix-arg))
929   (gnus-summary-iterate n
930     (let ((gnus-display-mime-function nil)
931           (gnus-inhibit-treatment t))
932       (gnus-summary-select-article))
933     (save-excursion
934       (set-buffer buffer)
935       (message-yank-buffer gnus-article-buffer))))
936
937 (defun gnus-debug ()
938   "Attempts to go through the Gnus source file and report what variables have been changed.
939 The source file has to be in the Emacs load path."
940   (interactive)
941   (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
942                  "gnus-art.el" "gnus-start.el" "gnus-async.el"
943                  "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
944                  "nnmail.el" "message.el"))
945         (point (point))
946         file expr olist sym)
947     (gnus-message 4 "Please wait while we snoop your variables...")
948     (sit-for 0)
949     ;; Go through all the files looking for non-default values for variables.
950     (save-excursion
951       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
952       (while files
953         (erase-buffer)
954         (when (and (setq file (locate-library (pop files)))
955                    (file-exists-p file))
956           (insert-file-contents file)
957           (goto-char (point-min))
958           (if (not (re-search-forward "^;;* *Internal variables" nil t))
959               (gnus-message 4 "Malformed sources in file %s" file)
960             (narrow-to-region (point-min) (point))
961             (goto-char (point-min))
962             (while (setq expr (ignore-errors (read (current-buffer))))
963               (ignore-errors
964                 (and (or (eq (car expr) 'defvar)
965                          (eq (car expr) 'defcustom))
966                      (stringp (nth 3 expr))
967                      (or (not (boundp (nth 1 expr)))
968                          (not (equal (eval (nth 2 expr))
969                                      (symbol-value (nth 1 expr)))))
970                      (push (nth 1 expr) olist)))))))
971       (kill-buffer (current-buffer)))
972     (when (setq olist (nreverse olist))
973       (insert "------------------ Environment follows ------------------\n\n"))
974     (while olist
975       (if (boundp (car olist))
976           (condition-case ()
977               (pp `(setq ,(car olist)
978                          ,(if (or (consp (setq sym (symbol-value (car olist))))
979                                   (and (symbolp sym)
980                                        (not (or (eq sym nil)
981                                                 (eq sym t)))))
982                               (list 'quote (symbol-value (car olist)))
983                             (symbol-value (car olist))))
984                   (current-buffer))
985             (error
986              (format "(setq %s 'whatever)\n" (car olist))))
987         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
988       (setq olist (cdr olist)))
989     (insert "\n\n")
990     ;; Remove any control chars - they seem to cause trouble for some
991     ;; mailers.  (Byte-compiled output from the stuff above.)
992     (goto-char point)
993     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
994       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
995                      t t))))
996
997 ;;; Treatment of rejected articles.
998 ;;; Bounced mail.
999
1000 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1001   "Re-mail the current message.
1002 This only makes sense if the current message is a bounce message than
1003 contains some mail you have written which has been bounced back to
1004 you.
1005 If FETCH, try to fetch the article that this is a reply to, if indeed
1006 this is a reply."
1007   (interactive "P")
1008   (gnus-summary-select-article t)
1009   (set-buffer gnus-original-article-buffer)
1010   (gnus-setup-message 'compose-bounce
1011     (let* ((references (mail-fetch-field "references"))
1012            (parent (and references (gnus-parent-id references))))
1013       (message-bounce)
1014       ;; If there are references, we fetch the article we answered to.
1015       (and fetch parent
1016            (gnus-summary-refer-article parent)
1017            (gnus-summary-show-all-headers)))))
1018
1019 ;;; Gcc handling.
1020
1021 ;; Do Gcc handling, which copied the message over to some group.
1022 (defun gnus-inews-do-gcc (&optional gcc)
1023   (interactive)
1024   (when (gnus-alive-p)
1025     (save-excursion
1026       (save-restriction
1027         (message-narrow-to-headers)
1028         (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1029               (cur (current-buffer))
1030               groups group method)
1031           (when gcc
1032             (message-remove-header "gcc")
1033             (widen)
1034             (setq groups (message-tokenize-header gcc " ,"))
1035             ;; Copy the article over to some group(s).
1036             (while (setq group (pop groups))
1037               (gnus-check-server
1038                (setq method
1039                      (cond ((and (null (gnus-get-info group))
1040                                  (eq (car gnus-message-archive-method)
1041                                      (car
1042                                       (gnus-server-to-method
1043                                        (gnus-group-method group)))))
1044                             ;; If the group doesn't exist, we assume
1045                             ;; it's an archive group...
1046                             gnus-message-archive-method)
1047                            ;; Use the method.
1048                            ((gnus-info-method (gnus-get-info group))
1049                             (gnus-info-method (gnus-get-info group)))
1050                            ;; Find the method.
1051                            (t (gnus-group-method group)))))
1052               (gnus-check-server method)
1053               (unless (gnus-request-group group t method)
1054                 (gnus-request-create-group group method))
1055               (save-excursion
1056                 (nnheader-set-temp-buffer " *acc*")
1057                 (insert-buffer-substring cur)
1058                 (message-encode-message-body)
1059                 (save-restriction
1060                   (message-narrow-to-headers)
1061                   (let ((mail-parse-charset message-default-charset))
1062                     (mail-encode-encoded-word-buffer)))
1063                 (goto-char (point-min))
1064                 (when (re-search-forward
1065                        (concat "^" (regexp-quote mail-header-separator) "$")
1066                        nil t)
1067                   (replace-match "" t t ))
1068                 (unless (gnus-request-accept-article group method t t)
1069                   (gnus-message 1 "Couldn't store article in group %s: %s"
1070                                 group (gnus-status-message method))
1071                   (sit-for 2))
1072                 (kill-buffer (current-buffer))))))))))
1073
1074 (defun gnus-inews-insert-gcc ()
1075   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1076   (save-excursion
1077     (save-restriction
1078       (message-narrow-to-headers)
1079       (let* ((group gnus-outgoing-message-group)
1080              (gcc (cond
1081                    ((gnus-functionp group)
1082                     (funcall group))
1083                    ((or (stringp group) (list group))
1084                     group))))
1085         (when gcc
1086           (insert "Gcc: "
1087                   (if (stringp gcc) gcc
1088                     (mapconcat 'identity gcc " "))
1089                   "\n"))))))
1090
1091 (defun gnus-inews-insert-archive-gcc (&optional group)
1092   "Insert the Gcc to say where the article is to be archived."
1093   (let* ((var gnus-message-archive-group)
1094          (group (or group gnus-newsgroup-name ""))
1095          (gcc-self-val
1096           (and gnus-newsgroup-name
1097                (not (equal gnus-newsgroup-name ""))
1098                (gnus-group-find-parameter
1099                 gnus-newsgroup-name 'gcc-self)))
1100          result
1101          (groups
1102           (cond
1103            ((null gnus-message-archive-method)
1104             ;; Ignore.
1105             nil)
1106            ((stringp var)
1107             ;; Just a single group.
1108             (list var))
1109            ((null var)
1110             ;; We don't want this.
1111             nil)
1112            ((and (listp var) (stringp (car var)))
1113             ;; A list of groups.
1114             var)
1115            ((gnus-functionp var)
1116             ;; A function.
1117             (funcall var group))
1118            (t
1119             ;; An alist of regexps/functions/forms.
1120             (while (and var
1121                         (not
1122                          (setq result
1123                                (cond
1124                                 ((stringp (caar var))
1125                                  ;; Regexp.
1126                                  (when (string-match (caar var) group)
1127                                    (cdar var)))
1128                                 ((gnus-functionp (car var))
1129                                  ;; Function.
1130                                  (funcall (car var) group))
1131                                 (t
1132                                  (eval (car var)))))))
1133               (setq var (cdr var)))
1134             result)))
1135          name)
1136     (when (or groups gcc-self-val)
1137       (when (stringp groups)
1138         (setq groups (list groups)))
1139       (save-excursion
1140         (save-restriction
1141           (message-narrow-to-headers)
1142           (goto-char (point-max))
1143           (insert "Gcc: ")
1144           (if gcc-self-val
1145               ;; Use the `gcc-self' param value instead.
1146               (progn
1147                 (insert
1148                  (if (stringp gcc-self-val)
1149                      gcc-self-val
1150                    group))
1151                 (if (not (eq gcc-self-val 'none))
1152                     (insert "\n")
1153                   (progn
1154                     (beginning-of-line)
1155                     (kill-line))))
1156             ;; Use the list of groups.
1157             (while (setq name (pop groups))
1158               (insert (if (string-match ":" name)
1159                           name
1160                         (gnus-group-prefixed-name
1161                          name gnus-message-archive-method)))
1162               (when groups
1163                 (insert " ")))
1164             (insert "\n")))))))
1165
1166 ;;; Posting styles.
1167
1168 (defun gnus-configure-posting-styles ()
1169   "Configure posting styles according to `gnus-posting-styles'."
1170   (unless gnus-inhibit-posting-styles
1171     (let ((group (or gnus-newsgroup-name ""))
1172           (styles gnus-posting-styles)
1173           style match variable attribute value v results
1174           filep name address element)
1175       ;; If the group has a posting-style parameter, add it at the end with a
1176       ;; regexp matching everything, to be sure it takes precedence over all
1177       ;; the others.
1178       (when gnus-newsgroup-name
1179         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1180           (when tmp-style
1181             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1182       ;; Go through all styles and look for matches.
1183       (dolist (style styles)
1184         (setq match (pop style))
1185         (goto-char (point-min))
1186         (when (cond
1187                ((stringp match)
1188                 ;; Regexp string match on the group name.
1189                 (string-match match group))
1190                ((eq match 'header)
1191                 (let ((header (message-fetch-field (pop style))))
1192                   (and header
1193                        (string-match (pop style) header))))
1194                ((or (symbolp match)
1195                     (gnus-functionp match))
1196                 (cond
1197                  ((gnus-functionp match)
1198                   ;; Function to be called.
1199                   (funcall match))
1200                  ((boundp match)
1201                   ;; Variable to be checked.
1202                   (symbol-value match))))
1203                ((listp match)
1204                 ;; This is a form to be evaled.
1205                 (eval match)))
1206           ;; We have a match, so we set the variables.
1207           (dolist (attribute style)
1208             (setq element (pop attribute)
1209                   variable nil
1210                   filep nil)
1211             (setq value
1212                   (cond
1213                    ((eq (car attribute) :file)
1214                     (setq filep t)
1215                     (cadr attribute))
1216                    ((eq (car attribute) :value)
1217                     (cadr attribute))
1218                    (t
1219                     (car attribute))))
1220             ;; We get the value.
1221             (setq v
1222                   (cond
1223                    ((stringp value)
1224                     value)
1225                    ((or (symbolp value)
1226                         (gnus-functionp value))
1227                     (cond ((gnus-functionp value)
1228                            (funcall value))
1229                           ((boundp value)
1230                            (symbol-value value))))
1231                    ((listp value)
1232                     (eval value))))
1233             ;; Translate obsolescent value.
1234             (when (eq element 'signature-file)
1235               (setq element 'signature
1236                     filep t))
1237             ;; Get the contents of file elems.
1238             (when (and filep v)
1239               (setq v (with-temp-buffer
1240                         (insert-file-contents v)
1241                         (buffer-string))))
1242             (setq results (delq (assoc element results) results))
1243             (push (cons element v) results))))
1244       ;; Now we have all the styles, so we insert them.
1245       (setq name (assq 'name results)
1246             address (assq 'address results))
1247       (setq results (delq name (delq address results)))
1248       (make-local-variable 'message-setup-hook)
1249       (dolist (result results)
1250         (add-hook 'message-setup-hook
1251                   (cond
1252                    ((eq 'eval (car result))
1253                     'ignore)
1254                    ((eq 'body (car result))
1255                     `(lambda ()
1256                        (save-excursion
1257                          (message-goto-body)
1258                          (insert ,(cdr result)))))
1259                    ((eq 'signature (car result))
1260                     (set (make-local-variable 'message-signature) nil)
1261                     (set (make-local-variable 'message-signature-file) nil)
1262                     (if (not (cdr result))
1263                         'ignore
1264                       `(lambda ()
1265                          (save-excursion
1266                            (let ((message-signature ,(cdr result)))
1267                              (when message-signature
1268                                (message-insert-signature)))))))
1269                    (t
1270                     (let ((header
1271                            (if (symbolp (car result))
1272                                (capitalize (symbol-name (car result)))
1273                              (car result))))
1274                       `(lambda ()
1275                          (save-excursion
1276                            (message-remove-header ,header)
1277                            (let ((value ,(cdr result)))
1278                              (when value
1279                                (message-goto-eoh)
1280                                (insert ,header ": " value "\n"))))))))))
1281       (when (or name address)
1282         (add-hook 'message-setup-hook
1283                   `(lambda ()
1284                      (set (make-local-variable 'user-mail-address)
1285                           ,(or (cdr address) user-mail-address))
1286                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1287                            (user-mail-address
1288                             ,(or (cdr address) user-mail-address)))
1289                        (save-excursion
1290                          (message-remove-header "From")
1291                          (message-goto-eoh)
1292                          (insert "From: " (message-make-from) "\n")))))))))
1293
1294 ;;; Allow redefinition of functions.
1295
1296 (gnus-ems-redefine)
1297
1298 (provide 'gnus-msg)
1299
1300 ;;; gnus-msg.el ends here