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