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