2000-05-06 Florian Weimer <fw@deneb.cygnus.argh.org>
[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            (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           (mm-with-unibyte-current-buffer
695             (setq text (buffer-string))))
696         (set-buffer 
697          (gnus-get-buffer-create
698           (generate-new-buffer-name " *Gnus forward*")))
699         (erase-buffer)
700         (mm-disable-multibyte)
701         (insert text)
702         (goto-char (point-min))
703         (when (looking-at "From ")
704           (replace-match "X-From-Line: ") )
705         (when message-forward-show-mml
706           (mm-enable-multibyte)
707           (mime-to-mml))
708         (message-forward post)))))
709
710 (defun gnus-summary-resend-message (address n)
711   "Resend the current article to ADDRESS."
712   (interactive "sResend message(s) to: \nP")
713   (let ((articles (gnus-summary-work-articles n))
714         article)
715     (while (setq article (pop articles))
716       (gnus-summary-select-article nil nil nil article)
717       (save-excursion
718         (set-buffer gnus-original-article-buffer)
719         (message-resend address)))))
720
721 (defun gnus-summary-post-forward (&optional arg)
722   "Forward the current article to a newsgroup.
723 See `gnus-summary-mail-forward' for ARG."
724   (interactive "P")
725   (gnus-summary-mail-forward arg t))
726
727 (defvar gnus-nastygram-message
728   "The following article was inappropriately posted to %s.\n\n"
729   "Format string to insert in nastygrams.
730 The current group name will be inserted at \"%s\".")
731
732 (defun gnus-summary-mail-nastygram (n)
733   "Send a nastygram to the author of the current article."
734   (interactive "P")
735   (when (or gnus-expert-user
736             (gnus-y-or-n-p
737              "Really send a nastygram to the author of the current article? "))
738     (let ((group gnus-newsgroup-name))
739       (gnus-summary-reply-with-original n)
740       (set-buffer gnus-message-buffer)
741       (message-goto-body)
742       (insert (format gnus-nastygram-message group))
743       (message-send-and-exit))))
744
745 (defun gnus-summary-mail-crosspost-complaint (n)
746   "Send a complaint about crossposting to the current article(s)."
747   (interactive "P")
748   (let ((articles (gnus-summary-work-articles n))
749         article)
750     (while (setq article (pop articles))
751       (set-buffer gnus-summary-buffer)
752       (gnus-summary-goto-subject article)
753       (let ((group (gnus-group-real-name gnus-newsgroup-name))
754             newsgroups followup-to)
755         (gnus-summary-select-article)
756         (set-buffer gnus-original-article-buffer)
757         (if (and (<= (length (message-tokenize-header
758                               (setq newsgroups
759                                     (mail-fetch-field "newsgroups"))
760                               ", "))
761                      1)
762                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
763                      (not (member group (message-tokenize-header
764                                          followup-to ", ")))))
765             (if followup-to
766                 (gnus-message 1 "Followup-to restricted")
767               (gnus-message 1 "Not a crossposted article"))
768           (set-buffer gnus-summary-buffer)
769           (gnus-summary-reply-with-original 1)
770           (set-buffer gnus-message-buffer)
771           (message-goto-body)
772           (insert (format gnus-crosspost-complaint newsgroups group))
773           (message-goto-subject)
774           (re-search-forward " *$")
775           (replace-match " (crosspost notification)" t t)
776           (gnus-deactivate-mark)
777           (when (gnus-y-or-n-p "Send this complaint? ")
778             (message-send-and-exit)))))))
779
780 (defun gnus-summary-mail-other-window ()
781   "Compose mail in other window."
782   (interactive)
783   (gnus-setup-message 'message
784     (message-mail)))
785
786 (defun gnus-mail-parse-comma-list ()
787   (let (accumulated
788         beg)
789     (skip-chars-forward " ")
790     (while (not (eobp))
791       (setq beg (point))
792       (skip-chars-forward "^,")
793       (while (zerop
794               (save-excursion
795                 (save-restriction
796                   (let ((i 0))
797                     (narrow-to-region beg (point))
798                     (goto-char beg)
799                     (logand (progn
800                               (while (search-forward "\"" nil t)
801                                 (incf i))
802                               (if (zerop i) 2 i))
803                             2)))))
804         (skip-chars-forward ",")
805         (skip-chars-forward "^,"))
806       (skip-chars-backward " ")
807       (push (buffer-substring beg (point))
808             accumulated)
809       (skip-chars-forward "^,")
810       (skip-chars-forward ", "))
811     accumulated))
812
813 (defun gnus-inews-add-to-address (group)
814   (let ((to-address (mail-fetch-field "to")))
815     (when (and to-address
816                (gnus-alive-p))
817       ;; This mail group doesn't have a `to-list', so we add one
818       ;; here.  Magic!
819       (when (gnus-y-or-n-p
820              (format "Do you want to add this as `to-list': %s " to-address))
821         (gnus-group-add-parameter group (cons 'to-list to-address))))))
822
823 (defun gnus-put-message ()
824   "Put the current message in some group and return to Gnus."
825   (interactive)
826   (let ((reply gnus-article-reply)
827         (winconf gnus-prev-winconf)
828         (group gnus-newsgroup-name))
829
830     (or (and group (not (gnus-group-read-only-p group)))
831         (setq group (read-string "Put in group: " nil
832                                  (gnus-writable-groups))))
833     (when (gnus-gethash group gnus-newsrc-hashtb)
834       (error "No such group: %s" group))
835
836     (save-excursion
837       (save-restriction
838         (widen)
839         (message-narrow-to-headers)
840         (let (gnus-deletable-headers)
841           (if (message-news-p)
842               (message-generate-headers message-required-news-headers)
843             (message-generate-headers message-required-mail-headers)))
844         (goto-char (point-max))
845         (insert "Gcc: " group "\n")
846         (widen)))
847
848     (gnus-inews-do-gcc)
849
850     (when (get-buffer gnus-group-buffer)
851       (when (gnus-buffer-exists-p (car-safe reply))
852         (set-buffer (car reply))
853         (and (cdr reply)
854              (gnus-summary-mark-article-as-replied
855               (cdr reply))))
856       (when winconf
857         (set-window-configuration winconf)))))
858
859 (defun gnus-article-mail (yank)
860   "Send a reply to the address near point.
861 If YANK is non-nil, include the original article."
862   (interactive "P")
863   (let ((address
864          (buffer-substring
865           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
866           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
867     (when address
868       (message-reply address)
869       (when yank
870         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
871
872 (defvar nntp-server-type)
873 (defun gnus-bug ()
874   "Send a bug report to the Gnus maintainers."
875   (interactive)
876   (unless (gnus-alive-p)
877     (error "Gnus has been shut down"))
878   (gnus-setup-message 'bug
879     (delete-other-windows)
880     (when gnus-bug-create-help-buffer
881       (switch-to-buffer "*Gnus Help Bug*")
882       (erase-buffer)
883       (insert gnus-bug-message)
884       (goto-char (point-min)))
885     (message-pop-to-buffer "*Gnus Bug*")
886     (message-setup `((To . ,gnus-maintainer) (Subject . "")))
887     (when gnus-bug-create-help-buffer
888       (push `(gnus-bug-kill-buffer) message-send-actions))
889     (goto-char (point-min))
890     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
891     (forward-line 1)
892     (insert (gnus-version) "\n"
893             (emacs-version) "\n")
894     (when (and (boundp 'nntp-server-type)
895                (stringp nntp-server-type))
896       (insert nntp-server-type))
897     (insert "\n\n\n\n\n")
898     (let (text)
899       (save-excursion
900         (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
901         (gnus-debug)
902         (setq text (buffer-string)))
903       (insert "<#part type=application/x-emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
904     (goto-char (point-min))
905     (search-forward "Subject: " nil t)
906     (message "")))
907
908 (defun gnus-bug-kill-buffer ()
909   (when (get-buffer "*Gnus Help Bug*")
910     (kill-buffer "*Gnus Help Bug*")))
911
912 (defun gnus-summary-yank-message (buffer n)
913   "Yank the current article into a composed message."
914   (interactive
915    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
916          current-prefix-arg))
917   (gnus-summary-iterate n
918     (let ((gnus-display-mime-function nil)
919           (gnus-inhibit-treatment t))
920       (gnus-summary-select-article))
921     (save-excursion
922       (set-buffer buffer)
923       (message-yank-buffer gnus-article-buffer))))
924
925 (defun gnus-debug ()
926   "Attempts to go through the Gnus source file and report what variables have been changed.
927 The source file has to be in the Emacs load path."
928   (interactive)
929   (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
930                  "gnus-art.el" "gnus-start.el" "gnus-async.el"
931                  "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
932                  "nnmail.el" "message.el"))
933         (point (point))
934         file expr olist sym)
935     (gnus-message 4 "Please wait while we snoop your variables...")
936     (sit-for 0)
937     ;; Go through all the files looking for non-default values for variables.
938     (save-excursion
939       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
940       (while files
941         (erase-buffer)
942         (when (and (setq file (locate-library (pop files)))
943                    (file-exists-p file))
944           (insert-file-contents file)
945           (goto-char (point-min))
946           (if (not (re-search-forward "^;;* *Internal variables" nil t))
947               (gnus-message 4 "Malformed sources in file %s" file)
948             (narrow-to-region (point-min) (point))
949             (goto-char (point-min))
950             (while (setq expr (ignore-errors (read (current-buffer))))
951               (ignore-errors
952                 (and (or (eq (car expr) 'defvar)
953                          (eq (car expr) 'defcustom))
954                      (stringp (nth 3 expr))
955                      (or (not (boundp (nth 1 expr)))
956                          (not (equal (eval (nth 2 expr))
957                                      (symbol-value (nth 1 expr)))))
958                      (push (nth 1 expr) olist)))))))
959       (kill-buffer (current-buffer)))
960     (when (setq olist (nreverse olist))
961       (insert "------------------ Environment follows ------------------\n\n"))
962     (while olist
963       (if (boundp (car olist))
964           (condition-case ()
965               (pp `(setq ,(car olist)
966                          ,(if (or (consp (setq sym (symbol-value (car olist))))
967                                   (and (symbolp sym)
968                                        (not (or (eq sym nil)
969                                                 (eq sym t)))))
970                               (list 'quote (symbol-value (car olist)))
971                             (symbol-value (car olist))))
972                   (current-buffer))
973             (error
974              (format "(setq %s 'whatever)\n" (car olist))))
975         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
976       (setq olist (cdr olist)))
977     (insert "\n\n")
978     ;; Remove any control chars - they seem to cause trouble for some
979     ;; mailers.  (Byte-compiled output from the stuff above.)
980     (goto-char point)
981     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
982       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
983                      t t))))
984
985 ;;; Treatment of rejected articles.
986 ;;; Bounced mail.
987
988 (defun gnus-summary-resend-bounced-mail (&optional fetch)
989   "Re-mail the current message.
990 This only makes sense if the current message is a bounce message than
991 contains some mail you have written which has been bounced back to
992 you.
993 If FETCH, try to fetch the article that this is a reply to, if indeed
994 this is a reply."
995   (interactive "P")
996   (gnus-summary-select-article t)
997   (set-buffer gnus-original-article-buffer)
998   (gnus-setup-message 'compose-bounce
999     (let* ((references (mail-fetch-field "references"))
1000            (parent (and references (gnus-parent-id references))))
1001       (message-bounce)
1002       ;; If there are references, we fetch the article we answered to.
1003       (and fetch parent
1004            (gnus-summary-refer-article parent)
1005            (gnus-summary-show-all-headers)))))
1006
1007 ;;; Gcc handling.
1008
1009 ;; Do Gcc handling, which copied the message over to some group.
1010 (defun gnus-inews-do-gcc (&optional gcc)
1011   (interactive)
1012   (when (gnus-alive-p)
1013     (save-excursion
1014       (save-restriction
1015         (message-narrow-to-headers)
1016         (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1017               (cur (current-buffer))
1018               groups group method)
1019           (when gcc
1020             (message-remove-header "gcc")
1021             (widen)
1022             (setq groups (message-tokenize-header gcc " ,"))
1023             ;; Copy the article over to some group(s).
1024             (while (setq group (pop groups))
1025               (gnus-check-server
1026                (setq method
1027                      (cond ((and (null (gnus-get-info group))
1028                                  (eq (car gnus-message-archive-method)
1029                                      (car
1030                                       (gnus-server-to-method
1031                                        (gnus-group-method group)))))
1032                             ;; If the group doesn't exist, we assume
1033                             ;; it's an archive group...
1034                             gnus-message-archive-method)
1035                            ;; Use the method.
1036                            ((gnus-info-method (gnus-get-info group))
1037                             (gnus-info-method (gnus-get-info group)))
1038                            ;; Find the method.
1039                            (t (gnus-group-method group)))))
1040               (gnus-check-server method)
1041               (unless (gnus-request-group group t method)
1042                 (gnus-request-create-group group method))
1043               (save-excursion
1044                 (nnheader-set-temp-buffer " *acc*")
1045                 (insert-buffer-substring cur)
1046                 (message-encode-message-body)
1047                 (save-restriction
1048                   (message-narrow-to-headers)
1049                   (let ((mail-parse-charset message-default-charset))
1050                     (mail-encode-encoded-word-buffer)))
1051                 (goto-char (point-min))
1052                 (when (re-search-forward
1053                        (concat "^" (regexp-quote mail-header-separator) "$")
1054                        nil t)
1055                   (replace-match "" t t ))
1056                 (unless (gnus-request-accept-article group method t t)
1057                   (gnus-message 1 "Couldn't store article in group %s: %s"
1058                                 group (gnus-status-message method))
1059                   (sit-for 2))
1060                 (kill-buffer (current-buffer))))))))))
1061
1062 (defun gnus-inews-insert-gcc ()
1063   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1064   (save-excursion
1065     (save-restriction
1066       (message-narrow-to-headers)
1067       (let* ((group gnus-outgoing-message-group)
1068              (gcc (cond
1069                    ((gnus-functionp group)
1070                     (funcall group))
1071                    ((or (stringp group) (list group))
1072                     group))))
1073         (when gcc
1074           (insert "Gcc: "
1075                   (if (stringp gcc) gcc
1076                     (mapconcat 'identity gcc " "))
1077                   "\n"))))))
1078
1079 (defun gnus-inews-insert-archive-gcc (&optional group)
1080   "Insert the Gcc to say where the article is to be archived."
1081   (let* ((var gnus-message-archive-group)
1082          (group (or group gnus-newsgroup-name ""))
1083          (gcc-self-val
1084           (and gnus-newsgroup-name
1085                (not (equal gnus-newsgroup-name ""))
1086                (gnus-group-find-parameter
1087                 gnus-newsgroup-name 'gcc-self)))
1088          result
1089          (groups
1090           (cond
1091            ((null gnus-message-archive-method)
1092             ;; Ignore.
1093             nil)
1094            ((stringp var)
1095             ;; Just a single group.
1096             (list var))
1097            ((null var)
1098             ;; We don't want this.
1099             nil)
1100            ((and (listp var) (stringp (car var)))
1101             ;; A list of groups.
1102             var)
1103            ((gnus-functionp var)
1104             ;; A function.
1105             (funcall var group))
1106            (t
1107             ;; An alist of regexps/functions/forms.
1108             (while (and var
1109                         (not
1110                          (setq result
1111                                (cond
1112                                 ((stringp (caar var))
1113                                  ;; Regexp.
1114                                  (when (string-match (caar var) group)
1115                                    (cdar var)))
1116                                 ((gnus-functionp (car var))
1117                                  ;; Function.
1118                                  (funcall (car var) group))
1119                                 (t
1120                                  (eval (car var)))))))
1121               (setq var (cdr var)))
1122             result)))
1123          name)
1124     (when (or groups gcc-self-val)
1125       (when (stringp groups)
1126         (setq groups (list groups)))
1127       (save-excursion
1128         (save-restriction
1129           (message-narrow-to-headers)
1130           (goto-char (point-max))
1131           (insert "Gcc: ")
1132           (if gcc-self-val
1133               ;; Use the `gcc-self' param value instead.
1134               (progn
1135                 (insert
1136                  (if (stringp gcc-self-val)
1137                      gcc-self-val
1138                    group))
1139                 (if (not (eq gcc-self-val 'none))
1140                     (insert "\n")
1141                   (progn
1142                     (beginning-of-line)
1143                     (kill-line))))
1144             ;; Use the list of groups.
1145             (while (setq name (pop groups))
1146               (insert (if (string-match ":" name)
1147                           name
1148                         (gnus-group-prefixed-name
1149                          name gnus-message-archive-method)))
1150               (when groups
1151                 (insert " ")))
1152             (insert "\n")))))))
1153
1154 ;;; Posting styles.
1155
1156 (defun gnus-configure-posting-styles ()
1157   "Configure posting styles according to `gnus-posting-styles'."
1158   (unless gnus-inhibit-posting-styles
1159     (let ((group (or gnus-newsgroup-name ""))
1160           (styles gnus-posting-styles)
1161           style match variable attribute value v results
1162           filep name address element)
1163       ;; If the group has a posting-style parameter, add it at the end with a
1164       ;; regexp matching everything, to be sure it takes precedence over all
1165       ;; the others.
1166       (when gnus-newsgroup-name
1167         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1168           (when tmp-style
1169             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1170       ;; Go through all styles and look for matches.
1171       (dolist (style styles)
1172         (setq match (pop style))
1173         (goto-char (point-min))
1174         (when (cond
1175                ((stringp match)
1176                 ;; Regexp string match on the group name.
1177                 (string-match match group))
1178                ((eq match 'header)
1179                 (let ((header (message-fetch-field (pop style))))
1180                   (and header
1181                        (string-match (pop style) header))))
1182                ((or (symbolp match)
1183                     (gnus-functionp match))
1184                 (cond
1185                  ((gnus-functionp match)
1186                   ;; Function to be called.
1187                   (funcall match))
1188                  ((boundp match)
1189                   ;; Variable to be checked.
1190                   (symbol-value match))))
1191                ((listp match)
1192                 ;; This is a form to be evaled.
1193                 (eval match)))
1194           ;; We have a match, so we set the variables.
1195           (dolist (attribute style)
1196             (setq element (pop attribute)
1197                   variable nil
1198                   filep nil)
1199             (setq value
1200                   (cond
1201                    ((eq (car attribute) :file)
1202                     (setq filep t)
1203                     (cadr attribute))
1204                    ((eq (car attribute) :value)
1205                     (cadr attribute))
1206                    (t
1207                     (car attribute))))
1208             ;; We get the value.
1209             (setq v
1210                   (cond
1211                    ((stringp value)
1212                     value)
1213                    ((or (symbolp value)
1214                         (gnus-functionp value))
1215                     (cond ((gnus-functionp value)
1216                            (funcall value))
1217                           ((boundp value)
1218                            (symbol-value value))))
1219                    ((listp value)
1220                     (eval value))))
1221             ;; Translate obsolescent value.
1222             (when (eq element 'signature-file)
1223               (setq element 'signature
1224                     filep t))
1225             ;; Get the contents of file elems.
1226             (when (and filep v)
1227               (setq v (with-temp-buffer
1228                         (insert-file-contents v)
1229                         (buffer-string))))
1230             (setq results (delq (assoc element results) results))
1231             (push (cons element v) results))))
1232       ;; Now we have all the styles, so we insert them.
1233       (setq name (assq 'name results)
1234             address (assq 'address results))
1235       (setq results (delq name (delq address results)))
1236       (make-local-variable 'message-setup-hook)
1237       (dolist (result results)
1238         (add-hook 'message-setup-hook
1239                   (cond
1240                    ((eq 'eval (car result))
1241                     'ignore)
1242                    ((eq 'body (car result))
1243                     `(lambda ()
1244                        (save-excursion
1245                          (message-goto-body)
1246                          (insert ,(cdr result)))))
1247                    ((eq 'signature (car result))
1248                     (set (make-local-variable 'message-signature) nil)
1249                     (set (make-local-variable 'message-signature-file) nil)
1250                     (if (not (cdr result))
1251                         'ignore
1252                       `(lambda ()
1253                          (save-excursion
1254                            (let ((message-signature ,(cdr result)))
1255                              (when message-signature
1256                                (message-insert-signature)))))))
1257                    (t
1258                     (let ((header
1259                            (if (symbolp (car result))
1260                                (capitalize (symbol-name (car result)))
1261                              (car result))))
1262                       `(lambda ()
1263                          (save-excursion
1264                            (message-remove-header ,header)
1265                            (let ((value ,(cdr result)))
1266                              (when value
1267                                (message-goto-eoh)
1268                                (insert ,header ": " value "\n"))))))))))
1269       (when (or name address)
1270         (add-hook 'message-setup-hook
1271                   `(lambda ()
1272                      (set (make-local-variable 'user-mail-address)
1273                           ,(or (cdr address) user-mail-address))
1274                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1275                            (user-mail-address
1276                             ,(or (cdr address) user-mail-address)))
1277                        (save-excursion
1278                          (message-remove-header "From")
1279                          (message-goto-eoh)
1280                          (insert "From: " (message-make-from) "\n")))))))))
1281
1282 ;;; Allow redefinition of functions.
1283
1284 (gnus-ems-redefine)
1285
1286 (provide 'gnus-msg)
1287
1288 ;;; gnus-msg.el ends here