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