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