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