Speedups; see ChangeLog for fine details.
[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 (defvar gnus-posting-style-alist
108   '((organization . message-user-organization)
109     (signature . message-signature)
110     (signature-file . message-signature-file)
111     (address . user-mail-address)
112     (name . user-full-name))
113   "*Mapping from style parameters to variables.")
114
115 (defcustom gnus-group-posting-charset-alist
116   '(("^no\\." iso-8859-1)
117     (message-this-is-mail nil)
118     (".*" iso-8859-1)
119     (message-this-is-news iso-8859-1))
120   "Alist of regexps (to match group names) and default charsets to be unencoded when posting."
121   :type '(repeat (list (regexp :tag "Group")
122                        (symbol :tag "Charset")))
123   :group 'gnus-charset)
124
125 ;;; Internal variables.
126
127 (defvar gnus-inhibit-posting-styles nil
128   "Inhibit the use of posting styles.")
129
130 (defvar gnus-message-buffer "*Mail Gnus*")
131 (defvar gnus-article-copy nil)
132 (defvar gnus-last-posting-server nil)
133 (defvar gnus-message-group-art nil)
134
135 (defconst gnus-bug-message
136   (format "Sending a bug report to the Gnus Towers.
137 ========================================
138
139 This gnus is the %s%s.
140 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
141 Developers. (the addresses below are mailing list addresses)
142
143 ========================================
144
145 The buffer below is a mail buffer.  When you press `C-c C-c', it will
146 be sent to the Gnus Bug Exterminators.
147
148 The thing near the bottom of the buffer is how the environment
149 settings will be included in the mail.  Please do not delete that.
150 They will tell the Bug People what your environment is, so that it
151 will be easier to locate the bugs.
152
153 If you have found a bug that makes Emacs go \"beep\", set
154 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
155 and include the backtrace in your bug report.
156
157 Please describe the bug in annoying, painstaking detail.
158
159 Thank you for your help in stamping out bugs.
160 "
161           gnus-product-name
162           (if (string= gnus-product-name "Semi-gnus")
163               ""
164             ", a modified version of Semi-gnus")))
165
166 (eval-and-compile
167   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
168   (autoload 'news-setup "rnewspost")
169   (autoload 'news-reply-mode "rnewspost")
170   (autoload 'rmail-dont-reply-to "mail-utils")
171   (autoload 'rmail-output "rmailout"))
172
173 \f
174 ;;;
175 ;;; Gnus Posting Functions
176 ;;;
177
178 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
179   "p" gnus-summary-post-news
180   "f" gnus-summary-followup
181   "F" gnus-summary-followup-with-original
182   "c" gnus-summary-cancel-article
183   "s" gnus-summary-supersede-article
184   "r" gnus-summary-reply
185   "R" gnus-summary-reply-with-original
186   "w" gnus-summary-wide-reply
187   "W" gnus-summary-wide-reply-with-original
188   "n" gnus-summary-followup-to-mail
189   "N" gnus-summary-followup-to-mail-with-original
190   "m" gnus-summary-mail-other-window
191   "u" gnus-uu-post-news
192   "\M-c" gnus-summary-mail-crosspost-complaint
193   "om" gnus-summary-mail-forward
194   "op" gnus-summary-post-forward
195   "Om" gnus-summary-mail-digest
196   "Op" gnus-summary-post-digest)
197
198 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
199   "b" gnus-summary-resend-bounced-mail
200   ;; "c" gnus-summary-send-draft
201   "r" gnus-summary-resend-message)
202
203 ;;; Internal functions.
204
205 (defvar gnus-article-reply nil)
206 (defmacro gnus-setup-message (config &rest forms)
207   (let ((winconf (make-symbol "gnus-setup-message-winconf"))
208         (buffer (make-symbol "gnus-setup-message-buffer"))
209         (article (make-symbol "gnus-setup-message-article"))
210         (group (make-symbol "gnus-setup-message-group")))
211     `(let ((,winconf (current-window-configuration))
212            (,buffer (buffer-name (current-buffer)))
213            (,article (and gnus-article-reply (gnus-summary-article-number)))
214            (,group gnus-newsgroup-name)
215            (message-header-setup-hook
216             (copy-sequence message-header-setup-hook))
217            (message-mode-hook (copy-sequence message-mode-hook))
218            (message-startup-parameter-alist
219             '((reply-buffer . gnus-copy-article-buffer)
220               (original-buffer . gnus-original-article-buffer)
221               (user-agent . Gnus))))
222        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
223        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
224        (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
225        (unwind-protect
226            (progn
227              ,@forms)
228          (gnus-inews-add-send-actions ,winconf ,buffer ,article)
229          (setq gnus-message-buffer (current-buffer))
230          (set (make-local-variable 'gnus-message-group-art)
231               (cons ,group ,article))
232          (set (make-local-variable 'gnus-newsgroup-name) ,group)
233          (set (make-local-variable 'message-posting-charset)
234               (gnus-setup-posting-charset ,group))
235          (gnus-run-hooks 'gnus-message-setup-hook))
236        (gnus-add-buffer)
237        (gnus-configure-windows ,config t)
238        (set-buffer-modified-p nil))))
239
240 (defun gnus-setup-posting-charset (group)
241   (let ((alist gnus-group-posting-charset-alist)
242         (group (or group ""))
243         elem)
244     (when group
245       (catch 'found
246         (while (setq elem (pop alist))
247           (when (or (and (stringp (car elem))
248                          (string-match (car elem) group))
249                     (and (gnus-functionp (car elem))
250                          (funcall (car elem) group))
251                     (and (symbolp (car elem))
252                          (symbol-value (car elem))))
253             (throw 'found (cadr elem))))))))
254
255 (defun gnus-inews-add-send-actions (winconf buffer article)
256   (make-local-hook 'message-sent-hook)
257   (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
258   (setq message-post-method
259         `(lambda (arg)
260            (gnus-post-method arg ,gnus-newsgroup-name)))
261   (setq message-user-agent (gnus-extended-version))
262   (when (not message-use-multi-frames)
263     (message-add-action
264      `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
265   (message-add-action
266    `(when (gnus-buffer-exists-p ,buffer)
267       (save-excursion
268         (set-buffer ,buffer)
269         ,(when article
270            `(gnus-summary-mark-article-as-replied ,article))))
271    'send))
272
273 (put 'gnus-setup-message 'lisp-indent-function 1)
274 (put 'gnus-setup-message 'edebug-form-spec '(form body))
275
276 ;;; Post news commands of Gnus group mode and summary mode
277
278 (defun gnus-group-mail (&optional arg)
279   "Start composing a mail.
280 If ARG, use the group under the point to find a posting style.
281 If ARG is 1, prompt for a group name to find the posting style."
282   (interactive "P")
283   ;; We can't `let' gnus-newsgroup-name here, since that leads
284   ;; to local variables leaking.
285   (let ((group gnus-newsgroup-name)
286         (buffer (current-buffer)))
287     (unwind-protect
288         (progn
289           (setq gnus-newsgroup-name
290                 (if arg
291                     (if (= 1 (prefix-numeric-value arg))
292                         (completing-read "Use posting style of group: "
293                                          gnus-active-hashtb nil
294                                          (gnus-read-active-file-p))
295                       (gnus-group-group-name))
296                   ""))
297           (gnus-setup-message 'message (message-mail)))
298       (save-excursion
299         (set-buffer buffer)
300         (setq gnus-newsgroup-name group)))))
301
302 (defun gnus-group-post-news (&optional arg)
303   "Start composing a news message.
304 If ARG, post to the group under point.
305 If ARG is 1, prompt for a group name."
306   (interactive "P")
307   ;; Bind this variable here to make message mode hooks work ok.
308   (let ((gnus-newsgroup-name
309          (if arg
310              (if (= 1 (prefix-numeric-value arg))
311                  (completing-read "Newsgroup: " gnus-active-hashtb nil
312                                   (gnus-read-active-file-p))
313                (gnus-group-group-name))
314            "")))
315     (gnus-post-news 'post gnus-newsgroup-name)))
316
317 (defun gnus-summary-post-news ()
318   "Start composing a news message."
319   (interactive)
320   (gnus-post-news 'post gnus-newsgroup-name))
321
322 (defun gnus-summary-followup (yank &optional force-news)
323   "Compose a followup to an article.
324 If prefix argument YANK is non-nil, original article is yanked automatically."
325   (interactive
326    (list (and current-prefix-arg
327               (gnus-summary-work-articles 1))))
328   (when yank
329     (gnus-summary-goto-subject (car yank)))
330   (save-window-excursion
331     (gnus-summary-select-article))
332   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
333         (gnus-newsgroup-name gnus-newsgroup-name))
334     ;; Send a followup.
335     (gnus-post-news nil gnus-newsgroup-name
336                     headers gnus-article-buffer
337                     yank nil force-news)))
338
339 (defun gnus-summary-followup-with-original (n &optional force-news)
340   "Compose a followup to an article and include the original article."
341   (interactive "P")
342   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
343
344 (defun gnus-summary-followup-to-mail (&optional arg)
345   "Followup to the current mail message via news."
346   (interactive
347    (list (and current-prefix-arg
348               (gnus-summary-work-articles 1))))
349   (gnus-summary-followup arg t))
350
351 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
352   "Followup to the current mail message via news."
353   (interactive "P")
354   (gnus-summary-followup (gnus-summary-work-articles arg) t))
355
356 (defun gnus-inews-yank-articles (articles)
357   (let* ((more-than-one (cdr articles))
358          (frame (when (and message-use-multi-frames more-than-one)
359                   (window-frame (get-buffer-window (current-buffer)))))
360          refs beg article)
361     (message-goto-body)
362     (while (setq article (pop articles))
363       (save-window-excursion
364         (set-buffer gnus-summary-buffer)
365         (gnus-summary-select-article nil nil nil article)
366         (gnus-summary-remove-process-mark article))
367       (when frame
368         (select-frame frame))
369
370       ;; Gathering references.
371       (when more-than-one
372         (setq refs (message-list-references
373                     refs
374                     (mail-header-references gnus-current-headers)
375                     (mail-header-message-id gnus-current-headers))))
376
377       (gnus-copy-article-buffer)
378       (let ((message-reply-buffer gnus-article-copy)
379             (message-reply-headers gnus-current-headers))
380         (message-yank-original)
381         (setq beg (or beg (mark t))))
382       (when articles
383         (insert "\n")))
384     (push-mark)
385
386     ;; Replace with the gathered references.
387     (when refs
388       (push-mark beg)
389       (save-restriction
390         (message-narrow-to-headers)
391         (let ((case-fold-search t))
392           (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
393               (replace-match "")
394             (goto-char (point-max))))
395         (mail-header-format
396          (list (or (assq 'References message-header-format-alist)
397                    '(References . message-shorten-references)))
398          (list (cons 'References
399                      (mapconcat 'identity (nreverse refs) " "))))
400         (backward-delete-char 1))
401       (setq beg (mark t))
402       (pop-mark))
403
404     (goto-char beg)))
405
406 (defun gnus-summary-cancel-article (&optional n symp)
407   "Cancel an article you posted.
408 Uses the process-prefix convention.  If given the symbolic
409 prefix `a', cancel using the standard posting method; if not
410 post using the current select method."
411   (interactive (gnus-interactive "P\ny"))
412   (let ((articles (gnus-summary-work-articles n))
413         (message-post-method
414          `(lambda (arg)
415             (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
416         article)
417     (while (setq article (pop articles))
418       (when (gnus-summary-select-article t nil nil article)
419         (when (gnus-eval-in-buffer-window gnus-article-buffer
420                 (save-excursion
421                   (set-buffer gnus-original-article-buffer)
422                   (message-cancel-news)))
423           (gnus-summary-mark-as-read article gnus-canceled-mark)
424           (gnus-cache-remove-article 1))
425         (gnus-article-hide-headers-if-wanted))
426       (gnus-summary-remove-process-mark article))))
427
428 (defun gnus-summary-supersede-article ()
429   "Compose an article that will supersede a previous article.
430 This is done simply by taking the old article and adding a Supersedes
431 header line with the old Message-ID."
432   (interactive)
433   (let ((article (gnus-summary-article-number))
434         (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
435     (gnus-setup-message 'reply-yank
436       (gnus-summary-select-article t)
437       (set-buffer gnus-original-article-buffer)
438       (message-supersede)
439       (push
440        `((lambda ()
441            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
442              (save-excursion
443                (set-buffer ,gnus-summary-buffer)
444                (gnus-cache-possibly-remove-article ,article nil nil nil t)
445                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
446        message-send-actions))))
447
448 \f
449
450 (defun gnus-copy-article-buffer (&optional article-buffer)
451   ;; make a copy of the article buffer with all text properties removed
452   ;; this copy is in the buffer gnus-article-copy.
453   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
454   ;; this buffer should be passed to all mail/news reply/post routines.
455   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
456   (let ((article-buffer (or article-buffer gnus-article-buffer))
457         end beg)
458     (if (not (and (get-buffer article-buffer)
459                   (gnus-buffer-exists-p article-buffer)))
460         (error "Can't find any article buffer")
461       (save-excursion
462         (set-buffer article-buffer)
463         (save-restriction
464           ;; Copy over the (displayed) article buffer, delete
465           ;; hidden text and remove text properties.
466           (widen)
467           (copy-to-buffer gnus-article-copy (point-min) (point-max))
468           (set-buffer gnus-article-copy)
469           (gnus-article-delete-text-of-type 'annotation)
470           (gnus-remove-text-with-property 'gnus-prev)
471           (gnus-remove-text-with-property 'gnus-next)
472           (insert
473            (prog1
474                (format "%s" (buffer-substring (point-min) (point-max)))
475              (erase-buffer)))
476           ;; Find the original headers.
477           (set-buffer gnus-original-article-buffer)
478           (goto-char (point-min))
479           (while (looking-at message-unix-mail-delimiter)
480             (forward-line 1))
481           (setq beg (point))
482           (setq end (or (search-forward "\n\n" nil t) (point)))
483           ;; Delete the headers from the displayed articles.
484           (set-buffer gnus-article-copy)
485           (delete-region (goto-char (point-min))
486                          (or (search-forward "\n\n" nil t) (point-max)))
487           ;; Insert the original article headers.
488           (insert-buffer-substring gnus-original-article-buffer beg end)
489           (article-decode-encoded-words)))
490       gnus-article-copy)))
491
492 (defun gnus-post-news (post &optional group header article-buffer yank subject
493                             force-news)
494   (when article-buffer
495     (gnus-copy-article-buffer))
496   (let ((gnus-article-reply article-buffer)
497         (add-to-list gnus-add-to-list))
498     (gnus-setup-message (cond (yank 'reply-yank)
499                               (article-buffer 'reply)
500                               (t 'message))
501       (let* ((group (or group gnus-newsgroup-name))
502              (pgroup group)
503              to-address to-group mailing-list to-list
504              newsgroup-p)
505         (when group
506           (setq to-address (gnus-group-find-parameter group 'to-address)
507                 to-group (gnus-group-find-parameter group 'to-group)
508                 to-list (gnus-group-find-parameter group 'to-list)
509                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
510                 mailing-list (when gnus-mailing-list-groups
511                                (string-match gnus-mailing-list-groups group))
512                 group (gnus-group-real-name group)))
513         (if (or (and to-group
514                      (gnus-news-group-p to-group))
515                 newsgroup-p
516                 force-news
517                 (and (gnus-news-group-p
518                       (or pgroup gnus-newsgroup-name)
519                       (if header (mail-header-number header)
520                         gnus-current-article))
521                      (not mailing-list)
522                      (not to-list)
523                      (not to-address)))
524             ;; This is news.
525             (if post
526                 (message-news (or to-group group))
527               (set-buffer gnus-article-copy)
528               (gnus-msg-treat-broken-reply-to)
529               (message-followup (if (or newsgroup-p force-news) nil to-group)))
530           ;; The is mail.
531           (if post
532               (progn
533                 (message-mail (or to-address to-list))
534                 ;; Arrange for mail groups that have no `to-address' to
535                 ;; get that when the user sends off the mail.
536                 (when (and (not to-list)
537                            (not to-address)
538                            add-to-list)
539                   (push (list 'gnus-inews-add-to-address pgroup)
540                         message-send-actions)))
541             (set-buffer gnus-article-copy)
542             (gnus-msg-treat-broken-reply-to)
543             (message-wide-reply to-address)))
544         (when yank
545           (gnus-inews-yank-articles yank))))))
546
547 (defun gnus-msg-treat-broken-reply-to ()
548   "Remove the Reply-to header iff broken-reply-to."
549   (when (gnus-group-find-parameter
550          gnus-newsgroup-name 'broken-reply-to)
551     (save-restriction
552       (message-narrow-to-head)
553       (message-remove-header "reply-to"))))
554
555 (defun gnus-post-method (arg group &optional silent)
556   "Return the posting method based on GROUP and ARG.
557 If SILENT, don't prompt the user."
558   (let ((group-method (gnus-find-method-for-group group)))
559     (cond
560      ;; If the group-method is nil (which shouldn't happen) we use
561      ;; the default method.
562      ((null group-method)
563       (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
564                gnus-select-method message-post-method))
565      ;; We want the inverse of the default
566      ((and arg (not (eq arg 0)))
567       (if (eq gnus-post-method 'active)
568           gnus-select-method
569         group-method))
570      ;; We query the user for a post method.
571      ((or arg
572           (and gnus-post-method
573                (not (eq gnus-post-method 'current))
574                (listp (car gnus-post-method))))
575       (let* ((methods
576               ;; Collect all methods we know about.
577               (append
578                (when (and gnus-post-method
579                           (not (eq gnus-post-method 'current)))
580                  (if (listp (car gnus-post-method))
581                      gnus-post-method
582                    (list gnus-post-method)))
583                gnus-secondary-select-methods
584                (mapcar 'cdr gnus-server-alist)
585                (mapcar 'car gnus-opened-servers)
586                (list gnus-select-method)
587                (list group-method)))
588              method-alist post-methods method)
589         ;; Weed out all mail methods.
590         (while methods
591           (setq method (gnus-server-get-method "" (pop methods)))
592           (when (and (or (gnus-method-option-p method 'post)
593                          (gnus-method-option-p method 'post-mail))
594                      (not (member method post-methods)))
595             (push method post-methods)))
596         ;; Create a name-method alist.
597         (setq method-alist
598               (mapcar
599                (lambda (m)
600                  (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
601                post-methods))
602         ;; Query the user.
603         (cadr
604          (assoc
605           (setq gnus-last-posting-server
606                 (if (and silent
607                          gnus-last-posting-server)
608                     ;; Just use the last value.
609                     gnus-last-posting-server
610                   (completing-read
611                    "Posting method: " method-alist nil t
612                    (cons (or gnus-last-posting-server "") 0))))
613           method-alist))))
614      ;; Override normal method.
615      ((and (eq gnus-post-method 'current)
616            (not (eq (car group-method) 'nndraft))
617            (not arg))
618       group-method)
619      ((and gnus-post-method
620            (not (eq gnus-post-method 'current)))
621       gnus-post-method)
622      ;; Use the normal select method.
623      (t gnus-select-method))))
624
625 \f
626
627 (defun gnus-extended-version ()
628   "Stringified gnus version."
629   (concat gnus-product-name "/" gnus-version-number " (based on "
630           gnus-original-product-name " v" gnus-original-version-number ")"))
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               groups group method)
1062           (when gcc
1063             (message-remove-header "gcc")
1064             (widen)
1065             (setq groups (message-tokenize-header gcc " ,"))
1066             ;; Copy the article over to some group(s).
1067             (while (setq group (pop groups))
1068               (gnus-check-server
1069                (setq method
1070                      (cond ((and (null (gnus-get-info group))
1071                                  (eq (car gnus-message-archive-method)
1072                                      (car
1073                                       (gnus-server-to-method
1074                                        (gnus-group-method group)))))
1075                             ;; If the group doesn't exist, we assume
1076                             ;; it's an archive group...
1077                             gnus-message-archive-method)
1078                            ;; Use the method.
1079                            ((gnus-info-method (gnus-get-info group))
1080                             (gnus-info-method (gnus-get-info group)))
1081                            ;; Find the method.
1082                            (t (gnus-group-method group)))))
1083               (gnus-check-server method)
1084               (unless (gnus-request-group group t method)
1085                 (gnus-request-create-group group method))
1086               (save-excursion
1087                 (nnheader-set-temp-buffer " *acc*")
1088                 (insert-buffer-substring message-encoding-buffer)
1089                 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1090                 (goto-char (point-min))
1091                 (when (re-search-forward
1092                        (concat "^" (regexp-quote mail-header-separator) "$")
1093                        nil t)
1094                   (replace-match "" t t ))
1095                 (unless (gnus-request-accept-article group method t t)
1096                   (gnus-message 1 "Couldn't store article in group %s: %s"
1097                                 group (gnus-status-message method))
1098                   (sit-for 2))
1099                 (kill-buffer (current-buffer))))))))))
1100
1101 (defun gnus-inews-insert-gcc ()
1102   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1103   (save-excursion
1104     (save-restriction
1105       (message-narrow-to-headers)
1106       (let* ((group gnus-outgoing-message-group)
1107              (gcc (cond
1108                    ((gnus-functionp group)
1109                     (funcall group))
1110                    ((or (stringp group) (list group))
1111                     group))))
1112         (when gcc
1113           (insert "Gcc: "
1114                   (if (stringp gcc) gcc
1115                     (mapconcat 'identity gcc " "))
1116                   "\n"))))))
1117
1118 (defun gnus-inews-insert-archive-gcc (&optional group)
1119   "Insert the Gcc to say where the article is to be archived."
1120   (let* ((var gnus-message-archive-group)
1121          (group (or group gnus-newsgroup-name ""))
1122          (gcc-self-val
1123           (and gnus-newsgroup-name
1124                (gnus-group-find-parameter
1125                 gnus-newsgroup-name 'gcc-self)))
1126          result
1127          (groups
1128           (cond
1129            ((null gnus-message-archive-method)
1130             ;; Ignore.
1131             nil)
1132            ((stringp var)
1133             ;; Just a single group.
1134             (list var))
1135            ((null var)
1136             ;; We don't want this.
1137             nil)
1138            ((and (listp var) (stringp (car var)))
1139             ;; A list of groups.
1140             var)
1141            ((gnus-functionp var)
1142             ;; A function.
1143             (funcall var group))
1144            (t
1145             ;; An alist of regexps/functions/forms.
1146             (while (and var
1147                         (not
1148                          (setq result
1149                                (cond
1150                                 ((stringp (caar var))
1151                                  ;; Regexp.
1152                                  (when (string-match (caar var) group)
1153                                    (cdar var)))
1154                                 ((gnus-functionp (car var))
1155                                  ;; Function.
1156                                  (funcall (car var) group))
1157                                 (t
1158                                  (eval (car var)))))))
1159               (setq var (cdr var)))
1160             result)))
1161          name)
1162     (when (or groups gcc-self-val)
1163       (when (stringp groups)
1164         (setq groups (list groups)))
1165       (save-excursion
1166         (save-restriction
1167           (message-narrow-to-headers)
1168           (goto-char (point-max))
1169           (insert "Gcc: ")
1170           (if gcc-self-val
1171               ;; Use the `gcc-self' param value instead.
1172               (progn
1173                 (insert
1174                  (if (stringp gcc-self-val)
1175                      gcc-self-val
1176                    group))
1177                 (if (not (eq gcc-self-val 'none))
1178                     (insert "\n")
1179                   (progn
1180                     (beginning-of-line)
1181                     (kill-line))))
1182             ;; Use the list of groups.
1183             (while (setq name (pop groups))
1184               (insert (if (string-match ":" name)
1185                           name
1186                         (gnus-group-prefixed-name
1187                          name gnus-message-archive-method)))
1188               (when groups
1189                 (insert " ")))
1190             (insert "\n")))))))
1191
1192 ;;; Posting styles.
1193
1194 (defvar gnus-message-style-insertions nil)
1195
1196 (defun gnus-configure-posting-styles ()
1197   "Configure posting styles according to `gnus-posting-styles'."
1198   (unless gnus-inhibit-posting-styles
1199     (let ((styles gnus-posting-styles)
1200           (gnus-newsgroup-name (or gnus-newsgroup-name ""))
1201           style match variable attribute value value-value)
1202       (make-local-variable 'gnus-message-style-insertions)
1203       ;; If the group has a posting-style parameter, add it at the end with a
1204       ;; regexp matching everything, to be sure it takes precedence over all
1205       ;; the others.
1206       (unless (zerop (length gnus-newsgroup-name))
1207         (let ((tmp-style (gnus-group-find-parameter
1208                           gnus-newsgroup-name 'posting-style t)))
1209           (when tmp-style
1210             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1211       ;; Go through all styles and look for matches.
1212       (while styles
1213         (setq style (pop styles)
1214               match (pop style))
1215         (when (cond
1216                ((stringp match)
1217                 ;; Regexp string match on the group name.
1218                 (string-match match gnus-newsgroup-name))
1219                ((or (symbolp match)
1220                     (gnus-functionp match))
1221                 (cond
1222                  ((gnus-functionp match)
1223                   ;; Function to be called.
1224                   (funcall match))
1225                  ((boundp match)
1226                   ;; Variable to be checked.
1227                   (symbol-value match))))
1228                ((listp match)
1229                 ;; This is a form to be evaled.
1230                 (eval match)))
1231           ;; We have a match, so we set the variables.
1232           (while style
1233             (setq attribute (pop style)
1234                   value (cadr attribute)
1235                   variable nil)
1236             ;; We find the variable that is to be modified.
1237             (if (and (not (stringp (car attribute)))
1238                      (not (eq 'body (car attribute)))
1239                      (not (setq variable
1240                                 (cdr (assq (car attribute)
1241                                            gnus-posting-style-alist)))))
1242                 (message "Couldn't find attribute %s" (car attribute))
1243               ;; We get the value.
1244               (setq value-value
1245                     (cond
1246                      ((stringp value)
1247                       value)
1248                      ((or (symbolp value)
1249                           (gnus-functionp value))
1250                       (cond ((gnus-functionp value)
1251                              (funcall value))
1252                             ((boundp value)
1253                              (symbol-value value))))
1254                      ((listp value)
1255                       (eval value))))
1256               (if variable
1257                   ;; This is an ordinary variable.
1258                   (set (make-local-variable variable) value-value)
1259                 ;; This is either a body or a header to be inserted in the
1260                 ;; message.
1261                 (let ((attr (car attribute)))
1262                   (make-local-variable 'message-setup-hook)
1263                   (if (eq 'body attr)
1264                       (add-hook 'message-setup-hook
1265                                 `(lambda ()
1266                                    (save-excursion
1267                                      (message-goto-body)
1268                                      (insert ,value-value))))
1269                     (add-hook 'message-setup-hook
1270                               'gnus-message-insert-stylings)
1271                     (push (cons (if (stringp attr) attr
1272                                   (symbol-name attr))
1273                                 value-value)
1274                           gnus-message-style-insertions)))))))))))
1275
1276 (defun gnus-message-insert-stylings ()
1277   (let (val)
1278     (save-excursion
1279       (while (setq val (pop gnus-message-style-insertions))
1280         (when (cdr val)
1281           (message-remove-header (car val))
1282           (message-goto-eoh)
1283           (insert (car val) ": " (cdr val) "\n"))
1284         (gnus-pull (car val) gnus-message-style-insertions t)))))
1285
1286
1287 ;;; @ for MIME Edit mode
1288 ;;;
1289
1290 (defun gnus-maybe-setup-default-charset ()
1291   (let ((charset
1292          (and (boundp 'gnus-summary-buffer)
1293               (buffer-live-p gnus-summary-buffer)
1294               (save-excursion
1295                 (set-buffer gnus-summary-buffer)
1296                 default-mime-charset))))
1297     (if charset
1298         (progn
1299           (make-local-variable 'default-mime-charset)
1300           (setq default-mime-charset charset)
1301           ))))
1302
1303
1304 ;;; Allow redefinition of functions.
1305
1306 (gnus-ems-redefine)
1307
1308 (provide 'gnus-msg)
1309
1310 ;;; gnus-msg.el ends here