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