Require `cl' using `eval-when-compile'.
[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 (eval-when-compile (require 'static))
35
36 (require 'gnus)
37 (require 'gnus-ems)
38 (require 'message)
39 (require 'gnus-art)
40
41 (defcustom gnus-post-method nil
42   "*Preferred method for posting USENET news.
43
44 If this variable is `current', Gnus will use the \"current\" select
45 method when posting.  If it is nil (which is the default), Gnus will
46 use the native posting method of the server.
47
48 This method will not be used in mail groups and the like, only in
49 \"real\" newsgroups.
50
51 If not nil nor `native', the value must be a valid method as discussed
52 in the documentation of `gnus-select-method'. It can also be a list of
53 methods. If that is the case, the user will be queried for what select
54 method to use when posting."
55   :group 'gnus-group-foreign
56   :type `(choice (const nil)
57                  (const current)
58                  (const native)
59                  (sexp :tag "Methods" ,gnus-select-method)))
60
61 (defvar gnus-outgoing-message-group nil
62   "*All outgoing messages will be put in this group.
63 If you want to store all your outgoing mail and articles in the group
64 \"nnml:archive\", you set this variable to that value.  This variable
65 can also be a list of group names.
66
67 If you want to have greater control over what group to put each
68 message in, you can set this variable to a function that checks the
69 current newsgroup name and then returns a suitable group name (or list
70 of names).")
71
72 (defvar gnus-mailing-list-groups nil
73   "*Regexp matching groups that are really mailing lists.
74 This is useful when you're reading a mailing list that has been
75 gatewayed to a newsgroup, and you want to followup to an article in
76 the group.")
77
78 (defvar gnus-add-to-list nil
79   "*If non-nil, add a `to-list' parameter automatically.")
80
81 (defvar gnus-crosspost-complaint
82   "Hi,
83
84 You posted the article below with the following Newsgroups header:
85
86 Newsgroups: %s
87
88 The %s group, at least, was an inappropriate recipient
89 of this message.  Please trim your Newsgroups header to exclude this
90 group before posting in the future.
91
92 Thank you.
93
94 "
95   "Format string to be inserted when complaining about crossposts.
96 The first %s will be replaced by the Newsgroups header;
97 the second with the current group name.")
98
99 (defvar gnus-message-setup-hook '(gnus-maybe-setup-default-charset)
100   "Hook run after setting up a message buffer.")
101
102 (defvar gnus-bug-create-help-buffer t
103   "*Should we create the *Gnus Help Bug* buffer?")
104
105 (defvar gnus-posting-styles nil
106   "*Alist of styles to use when posting.")
107
108 (defcustom gnus-group-posting-charset-alist
109   '(("^no\\." iso-8859-1)
110     (message-this-is-mail nil)
111     ("^de\\." 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            (gnus-get-function group-method 'request-post t)
619            (not arg))
620       group-method)
621      ((and gnus-post-method
622            (not (eq gnus-post-method 'current)))
623       gnus-post-method)
624      ;; Use the normal select method.
625      (t gnus-select-method))))
626
627 \f
628
629 (defun gnus-extended-version ()
630   "Stringified gnus version."
631   (concat gnus-product-name "/" gnus-version-number
632           " (based on "
633           gnus-original-product-name " v" gnus-original-version-number ")"
634           (if (zerop (string-to-number gnus-revision-number))
635               ""
636             (concat " (revision " gnus-revision-number ")"))
637           ))
638
639 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
640   "Return user-agent info.
641 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
642   `mime-edit-user-agent-value' exists, the return value will include it.
643 MAX-COLUMN the optional second argument if it is specified, the return value
644   will be folded up in the proper way."
645   (let ((user-agent (if (and include-mime-info
646                              (boundp 'mime-edit-user-agent-value))
647                         (concat (gnus-extended-version)
648                                 " "
649                                 mime-edit-user-agent-value)
650                       (gnus-extended-version))))
651     (if max-column
652         (let (boundary)
653           (unless (natnump max-column) (setq max-column 76))
654           (with-temp-buffer
655             (insert "            " user-agent)
656             (goto-char 13)
657             (while (re-search-forward "[\n\t ]+" nil t)
658               (replace-match " "))
659             (goto-char 13)
660             (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
661               (while (eq ?\( (char-after (point)))
662                 (forward-list)
663                 (skip-chars-forward " "))
664               (skip-chars-backward " ")
665               (if (> (current-column) max-column)
666                   (progn
667                     (if (or (not boundary) (eq ?\n (char-after boundary)))
668                         (progn
669                           (setq boundary (point))
670                           (unless (eobp)
671                             (delete-char 1)
672                             (insert "\n ")))
673                       (goto-char boundary)
674                       (delete-char 1)
675                       (insert "\n ")))
676                 (setq boundary (point))))
677             (buffer-substring 13 (point-max))))
678       user-agent)))
679
680 \f
681 ;;;
682 ;;; Gnus Mail Functions
683 ;;;
684
685 ;;; Mail reply commands of Gnus summary mode
686
687 (defun gnus-summary-reply (&optional yank wide)
688   "Start composing a reply mail to the current message.
689 If prefix argument YANK is non-nil, the original article is yanked
690 automatically."
691   (interactive
692    (list (and current-prefix-arg
693               (gnus-summary-work-articles 1))))
694   ;; Stripping headers should be specified with mail-yank-ignored-headers.
695   (when yank
696     (gnus-summary-goto-subject (car yank)))
697   (let ((gnus-article-reply t))
698     (gnus-setup-message (if yank 'reply-yank 'reply)
699       (gnus-summary-select-article)
700       (set-buffer (gnus-copy-article-buffer))
701       (gnus-msg-treat-broken-reply-to)
702       (message-reply nil wide)
703       (when yank
704         (gnus-inews-yank-articles yank)))))
705
706 (defun gnus-summary-reply-with-original (n &optional wide)
707   "Start composing a reply mail to the current message.
708 The original article will be yanked."
709   (interactive "P")
710   (gnus-summary-reply (gnus-summary-work-articles n) wide))
711
712 (defun gnus-summary-wide-reply (&optional yank)
713   "Start composing a wide reply mail to the current message.
714 If prefix argument YANK is non-nil, the original article is yanked
715 automatically."
716   (interactive
717    (list (and current-prefix-arg
718               (gnus-summary-work-articles 1))))
719   (gnus-summary-reply yank t))
720
721 (defun gnus-summary-wide-reply-with-original (n)
722   "Start composing a wide reply mail to the current message.
723 The original article will be yanked."
724   (interactive "P")
725   (gnus-summary-reply-with-original n t))
726
727 (defun gnus-summary-mail-forward (&optional full-headers post)
728   "Forward the current message to another user.
729 If FULL-HEADERS (the prefix), include full headers when forwarding."
730   (interactive "P")
731   (gnus-setup-message 'forward
732     (gnus-summary-select-article)
733     (let ((charset default-mime-charset))
734       (set-buffer gnus-original-article-buffer)
735       (make-local-variable 'default-mime-charset)
736       (setq default-mime-charset charset)
737       )
738     (let ((message-included-forward-headers
739            (if full-headers "" message-included-forward-headers)))
740       (message-forward post))))
741
742 ;;; XXX: generate Subject and ``Topics''?
743 (defun gnus-summary-mail-digest (&optional n post)
744   "Digests and forwards all articles in this series."
745   (interactive "P")
746   (let ((subject "Digested Articles")
747         (articles (gnus-summary-work-articles n))
748         article frame)
749     (gnus-setup-message 'forward
750       (gnus-summary-select-article)
751       (if post (message-news nil subject) (message-mail nil subject))
752       (when (and message-use-multi-frames (cdr articles))
753         (setq frame (window-frame (get-buffer-window (current-buffer)))))
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         (when frame
761           (select-frame frame))
762         (insert (mime-make-tag "message" "rfc822") "\n")
763         (insert-buffer-substring gnus-original-article-buffer))
764       (push-mark)
765       (message-goto-body)
766       (mime-edit-enclose-digest-region (point)(mark t)))))
767
768 (defun gnus-summary-post-digest (&optional n)
769   "Digest and forwards all articles in this series to a newsgroup."
770   (interactive "P")
771   (gnus-summary-mail-digest n t))
772
773 (defun gnus-summary-resend-message (address n)
774   "Resend the current article to ADDRESS."
775   (interactive "sResend message(s) to: \nP")
776   (let ((articles (gnus-summary-work-articles n))
777         article)
778     (while (setq article (pop articles))
779       (gnus-summary-select-article nil nil nil article)
780       (save-excursion
781         (set-buffer gnus-original-article-buffer)
782         (message-resend address)))))
783
784 (defun gnus-summary-post-forward (&optional full-headers)
785   "Forward the current article to a newsgroup.
786 If FULL-HEADERS (the prefix), include full headers when forwarding."
787   (interactive "P")
788   (gnus-summary-mail-forward full-headers t))
789
790 (defvar gnus-nastygram-message
791   "The following article was inappropriately posted to %s.\n\n"
792   "Format string to insert in nastygrams.
793 The current group name will be inserted at \"%s\".")
794
795 (defun gnus-summary-mail-nastygram (n)
796   "Send a nastygram to the author of the current article."
797   (interactive "P")
798   (when (or gnus-expert-user
799             (gnus-y-or-n-p
800              "Really send a nastygram to the author of the current article? "))
801     (let ((group gnus-newsgroup-name))
802       (gnus-summary-reply-with-original n)
803       (set-buffer gnus-message-buffer)
804       (message-goto-body)
805       (insert (format gnus-nastygram-message group))
806       (message-send-and-exit))))
807
808 (defun gnus-summary-mail-crosspost-complaint (n)
809   "Send a complaint about crossposting to the current article(s)."
810   (interactive "P")
811   (let ((articles (gnus-summary-work-articles n))
812         article)
813     (while (setq article (pop articles))
814       (set-buffer gnus-summary-buffer)
815       (gnus-summary-goto-subject article)
816       (let ((group (gnus-group-real-name gnus-newsgroup-name))
817             newsgroups followup-to)
818         (gnus-summary-select-article)
819         (set-buffer gnus-original-article-buffer)
820         (if (and (<= (length (message-tokenize-header
821                               (setq newsgroups
822                                     (mail-fetch-field "newsgroups"))
823                               ", "))
824                      1)
825                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
826                      (not (member group (message-tokenize-header
827                                          followup-to ", ")))))
828             (if followup-to
829                 (gnus-message 1 "Followup-to restricted")
830               (gnus-message 1 "Not a crossposted article"))
831           (set-buffer gnus-summary-buffer)
832           (gnus-summary-reply-with-original 1)
833           (set-buffer gnus-message-buffer)
834           (message-goto-body)
835           (insert (format gnus-crosspost-complaint newsgroups group))
836           (message-goto-subject)
837           (re-search-forward " *$")
838           (replace-match " (crosspost notification)" t t)
839           (gnus-deactivate-mark)
840           (when (gnus-y-or-n-p "Send this complaint? ")
841             (message-send-and-exit)))))))
842
843 (defun gnus-summary-mail-other-window ()
844   "Compose mail in other window."
845   (interactive)
846   (gnus-setup-message 'message
847     (message-mail)))
848
849 (defun gnus-mail-parse-comma-list ()
850   (let (accumulated
851         beg)
852     (skip-chars-forward " ")
853     (while (not (eobp))
854       (setq beg (point))
855       (skip-chars-forward "^,")
856       (while (zerop
857               (save-excursion
858                 (save-restriction
859                   (let ((i 0))
860                     (narrow-to-region beg (point))
861                     (goto-char beg)
862                     (logand (progn
863                               (while (search-forward "\"" nil t)
864                                 (incf i))
865                               (if (zerop i) 2 i))
866                             2)))))
867         (skip-chars-forward ",")
868         (skip-chars-forward "^,"))
869       (skip-chars-backward " ")
870       (push (buffer-substring beg (point))
871             accumulated)
872       (skip-chars-forward "^,")
873       (skip-chars-forward ", "))
874     accumulated))
875
876 (defun gnus-inews-add-to-address (group)
877   (let ((to-address (mail-fetch-field "to")))
878     (when (and to-address
879                (gnus-alive-p))
880       ;; This mail group doesn't have a `to-list', so we add one
881       ;; here.  Magic!
882       (when (gnus-y-or-n-p
883              (format "Do you want to add this as `to-list': %s " to-address))
884         (gnus-group-add-parameter group (cons 'to-list to-address))))))
885
886 (defun gnus-put-message ()
887   "Put the current message in some group and return to Gnus."
888   (interactive)
889   (let ((reply gnus-article-reply)
890         (winconf gnus-prev-winconf)
891         (group gnus-newsgroup-name))
892
893     (or (and group (not (gnus-group-read-only-p group)))
894         (setq group (read-string "Put in group: " nil
895                                  (gnus-writable-groups))))
896     (when (gnus-gethash group gnus-newsrc-hashtb)
897       (error "No such group: %s" group))
898
899     (save-excursion
900       (save-restriction
901         (widen)
902         (message-narrow-to-headers)
903         (let (gnus-deletable-headers)
904           (if (message-news-p)
905               (message-generate-headers message-required-news-headers)
906             (message-generate-headers message-required-mail-headers)))
907         (goto-char (point-max))
908         (insert "Gcc: " group "\n")
909         (widen)))
910
911     (gnus-inews-do-gcc)
912
913     (when (get-buffer gnus-group-buffer)
914       (when (gnus-buffer-exists-p (car-safe reply))
915         (set-buffer (car reply))
916         (and (cdr reply)
917              (gnus-summary-mark-article-as-replied
918               (cdr reply))))
919       (when winconf
920         (set-window-configuration winconf)))))
921
922 (defun gnus-article-mail (yank)
923   "Send a reply to the address near point.
924 If YANK is non-nil, include the original article."
925   (interactive "P")
926   (let ((address
927          (buffer-substring
928           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
929           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
930     (when address
931       (message-reply address)
932       (when yank
933         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
934
935 (defvar nntp-server-type)
936 (defun gnus-bug ()
937   "Send a bug report to the Gnus maintainers."
938   (interactive)
939   (unless (gnus-alive-p)
940     (error "Gnus has been shut down"))
941   (gnus-setup-message 'bug
942     (delete-other-windows)
943     (when gnus-bug-create-help-buffer
944       (switch-to-buffer "*Gnus Help Bug*")
945       (erase-buffer)
946       (insert gnus-bug-message)
947       (goto-char (point-min)))
948     (message-pop-to-buffer "*Gnus Bug*")
949     (message-setup `((To . ,gnus-maintainer) (Subject . "")))
950     (when gnus-bug-create-help-buffer
951       (push `(gnus-bug-kill-buffer) message-send-actions))
952     (goto-char (point-min))
953     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
954     (forward-line 1)
955     (insert gnus-product-name " " gnus-version-number
956             " (r" gnus-revision-number ") "
957             "based on " gnus-original-product-name " v"
958             gnus-original-version-number "\n"
959             (emacs-version) "\n")
960     (when (and (boundp 'nntp-server-type)
961                (stringp nntp-server-type))
962       (insert nntp-server-type))
963     (insert "\n\n\n\n\n")
964     (let (mime-content-types)
965       (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
966     (insert (with-temp-buffer
967               (gnus-debug)
968               (buffer-string)))
969     (goto-char (point-min))
970     (search-forward "Subject: " nil t)
971     (message "")))
972
973 (defun gnus-bug-kill-buffer ()
974   (when (get-buffer "*Gnus Help Bug*")
975     (kill-buffer "*Gnus Help Bug*")))
976
977 (defun gnus-debug ()
978   "Attempts to go through the Gnus source file and report what variables have been changed.
979 The source file has to be in the Emacs load path."
980   (interactive)
981   (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
982                  "gnus-art.el" "gnus-start.el" "gnus-async.el"
983                  "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
984                  "nnmail.el" "message.el"))
985         (point (point))
986         file expr olist sym)
987     (gnus-message 4 "Please wait while we snoop your variables...")
988     (sit-for 0)
989     ;; Go through all the files looking for non-default values for variables.
990     (save-excursion
991       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
992       (while files
993         (erase-buffer)
994         (when (and (setq file (locate-library (pop files)))
995                    (file-exists-p file))
996           (insert-file-contents file)
997           (goto-char (point-min))
998           (if (not (re-search-forward "^;;* *Internal variables" nil t))
999               (gnus-message 4 "Malformed sources in file %s" file)
1000             (narrow-to-region (point-min) (point))
1001             (goto-char (point-min))
1002             (while (setq expr (ignore-errors (read (current-buffer))))
1003               (ignore-errors
1004                 (and (or (eq (car expr) 'defvar)
1005                          (eq (car expr) 'defcustom))
1006                      (stringp (nth 3 expr))
1007                      (or (not (boundp (nth 1 expr)))
1008                          (not (equal (eval (nth 2 expr))
1009                                      (symbol-value (nth 1 expr)))))
1010                      (push (nth 1 expr) olist)))))))
1011       (kill-buffer (current-buffer)))
1012     (when (setq olist (nreverse olist))
1013       (insert "------------------ Environment follows ------------------\n\n"))
1014     (while olist
1015       (if (boundp (car olist))
1016           (condition-case ()
1017               (pp `(setq ,(car olist)
1018                          ,(if (or (consp (setq sym (symbol-value (car olist))))
1019                                   (and (symbolp sym)
1020                                        (not (or (eq sym nil)
1021                                                 (eq sym t)))))
1022                               (list 'quote (symbol-value (car olist)))
1023                             (symbol-value (car olist))))
1024                   (current-buffer))
1025             (error
1026              (format "(setq %s 'whatever)\n" (car olist))))
1027         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1028       (setq olist (cdr olist)))
1029     (insert "\n\n")
1030     ;; Remove any control chars - they seem to cause trouble for some
1031     ;; mailers.  (Byte-compiled output from the stuff above.)
1032     (goto-char point)
1033     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1034       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1035                      t t))))
1036
1037 ;;; Treatment of rejected articles.
1038 ;;; Bounced mail.
1039
1040 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1041   "Re-mail the current message.
1042 This only makes sense if the current message is a bounce message than
1043 contains some mail you have written which has been bounced back to
1044 you.
1045 If FETCH, try to fetch the article that this is a reply to, if indeed
1046 this is a reply."
1047   (interactive "P")
1048   (gnus-summary-select-article t)
1049   (set-buffer gnus-original-article-buffer)
1050   (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1051     (gnus-setup-message 'compose-bounce
1052       (let* ((references (mail-fetch-field "references"))
1053              (parent (and references (gnus-parent-id references))))
1054         (message-bounce)
1055         ;; If there are references, we fetch the article we answered to.
1056         (and fetch parent
1057              (gnus-summary-refer-article parent)
1058              (gnus-summary-show-all-headers))))))
1059
1060 ;;; Gcc handling.
1061
1062 ;; Do Gcc handling, which copied the message over to some group.
1063 (defun gnus-inews-do-gcc (&optional gcc)
1064   (interactive)
1065   (when (gnus-alive-p)
1066     (save-excursion
1067       (save-restriction
1068         (message-narrow-to-headers)
1069         (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1070               (coding-system-for-write 'raw-text)
1071               (output-coding-system 'raw-text)
1072               groups group method)
1073           (when gcc
1074             (message-remove-header "gcc")
1075             (widen)
1076             (setq groups (message-tokenize-header gcc " ,"))
1077             ;; Copy the article over to some group(s).
1078             (while (setq group (pop groups))
1079               (gnus-check-server
1080                (setq method
1081                      (cond ((and (null (gnus-get-info group))
1082                                  (eq (car gnus-message-archive-method)
1083                                      (car
1084                                       (gnus-server-to-method
1085                                        (gnus-group-method group)))))
1086                             ;; If the group doesn't exist, we assume
1087                             ;; it's an archive group...
1088                             gnus-message-archive-method)
1089                            ;; Use the method.
1090                            ((gnus-info-method (gnus-get-info group))
1091                             (gnus-info-method (gnus-get-info group)))
1092                            ;; Find the method.
1093                            (t (gnus-group-method group)))))
1094               (gnus-check-server method)
1095               (unless (gnus-request-group group t method)
1096                 (gnus-request-create-group group method))
1097               (save-excursion
1098                 (nnheader-set-temp-buffer " *acc*")
1099                 (insert-buffer-substring message-encoding-buffer)
1100                 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1101                 (goto-char (point-min))
1102                 (when (re-search-forward
1103                        (concat "^" (regexp-quote mail-header-separator) "$")
1104                        nil t)
1105                   (replace-match "" t t ))
1106                 (unless (gnus-request-accept-article group method t t)
1107                   (gnus-message 1 "Couldn't store article in group %s: %s"
1108                                 group (gnus-status-message method))
1109                   (sit-for 2))
1110                 (kill-buffer (current-buffer))))))))))
1111
1112 (defun gnus-inews-insert-gcc ()
1113   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1114   (save-excursion
1115     (save-restriction
1116       (message-narrow-to-headers)
1117       (let* ((group gnus-outgoing-message-group)
1118              (gcc (cond
1119                    ((gnus-functionp group)
1120                     (funcall group))
1121                    ((or (stringp group) (list group))
1122                     group))))
1123         (when gcc
1124           (insert "Gcc: "
1125                   (if (stringp gcc) gcc
1126                     (mapconcat 'identity gcc " "))
1127                   "\n"))))))
1128
1129 (defun gnus-inews-insert-archive-gcc (&optional group)
1130   "Insert the Gcc to say where the article is to be archived."
1131   (let* ((var gnus-message-archive-group)
1132          (group (or group gnus-newsgroup-name ""))
1133          (gcc-self-val
1134           (and gnus-newsgroup-name
1135                (gnus-group-find-parameter
1136                 gnus-newsgroup-name 'gcc-self)))
1137          result
1138          (groups
1139           (cond
1140            ((null gnus-message-archive-method)
1141             ;; Ignore.
1142             nil)
1143            ((stringp var)
1144             ;; Just a single group.
1145             (list var))
1146            ((null var)
1147             ;; We don't want this.
1148             nil)
1149            ((and (listp var) (stringp (car var)))
1150             ;; A list of groups.
1151             var)
1152            ((gnus-functionp var)
1153             ;; A function.
1154             (funcall var group))
1155            (t
1156             ;; An alist of regexps/functions/forms.
1157             (while (and var
1158                         (not
1159                          (setq result
1160                                (cond
1161                                 ((stringp (caar var))
1162                                  ;; Regexp.
1163                                  (when (string-match (caar var) group)
1164                                    (cdar var)))
1165                                 ((gnus-functionp (car var))
1166                                  ;; Function.
1167                                  (funcall (car var) group))
1168                                 (t
1169                                  (eval (car var)))))))
1170               (setq var (cdr var)))
1171             result)))
1172          name)
1173     (when (or groups gcc-self-val)
1174       (when (stringp groups)
1175         (setq groups (list groups)))
1176       (save-excursion
1177         (save-restriction
1178           (message-narrow-to-headers)
1179           (goto-char (point-max))
1180           (insert "Gcc: ")
1181           (if gcc-self-val
1182               ;; Use the `gcc-self' param value instead.
1183               (progn
1184                 (insert
1185                  (if (stringp gcc-self-val)
1186                      gcc-self-val
1187                    group))
1188                 (if (not (eq gcc-self-val 'none))
1189                     (insert "\n")
1190                   (progn
1191                     (beginning-of-line)
1192                     (kill-line))))
1193             ;; Use the list of groups.
1194             (while (setq name (pop groups))
1195               (insert (if (string-match ":" name)
1196                           name
1197                         (gnus-group-prefixed-name
1198                          name gnus-message-archive-method)))
1199               (when groups
1200                 (insert " ")))
1201             (insert "\n")))))))
1202
1203 ;;; Posting styles.
1204
1205 (defun gnus-configure-posting-styles ()
1206   "Configure posting styles according to `gnus-posting-styles'."
1207   (unless gnus-inhibit-posting-styles
1208     (let ((group (or gnus-newsgroup-name ""))
1209           (styles gnus-posting-styles)
1210           style match variable attribute value v results
1211           filep name address element)
1212       ;; If the group has a posting-style parameter, add it at the end with a
1213       ;; regexp matching everything, to be sure it takes precedence over all
1214       ;; the others.
1215       (when gnus-newsgroup-name
1216         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1217           (when tmp-style
1218             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1219       ;; Go through all styles and look for matches.
1220       (dolist (style styles)
1221         (setq match (pop style))
1222         (when (cond
1223                ((stringp match)
1224                 ;; Regexp string match on the group name.
1225                 (string-match match group))
1226                ((or (symbolp match)
1227                     (gnus-functionp match))
1228                 (cond
1229                  ((gnus-functionp match)
1230                   ;; Function to be called.
1231                   (funcall match))
1232                  ((boundp match)
1233                   ;; Variable to be checked.
1234                   (symbol-value match))))
1235                ((listp match)
1236                 ;; This is a form to be evaled.
1237                 (eval match)))
1238           ;; We have a match, so we set the variables.
1239           (dolist (attribute style)
1240             (setq element (pop attribute)
1241                   variable nil
1242                   filep nil)
1243             (setq value
1244                   (cond
1245                    ((eq (car attribute) ':file)
1246                     (setq filep t)
1247                     (cadr attribute))
1248                    ((eq (car attribute) :value)
1249                     (cadr attribute))
1250                    (t
1251                     (car attribute))))
1252             ;; We get the value.
1253             (setq v
1254                   (cond
1255                    ((stringp value)
1256                     value)
1257                    ((or (symbolp value)
1258                         (gnus-functionp value))
1259                     (cond ((gnus-functionp value)
1260                            (funcall value))
1261                           ((boundp value)
1262                            (symbol-value value))))
1263                    ((listp value)
1264                     (eval value))))
1265             ;; Translate obsolescent value.
1266             (when (eq element 'signature-file)
1267               (setq element 'signature
1268                     filep t))
1269             ;; Get the contents of file elems.
1270             (when filep
1271               (setq v (with-temp-buffer
1272                         (insert-file-contents v)
1273                         (buffer-string))))
1274             (setq results (delq (assoc element results) results))
1275             (push (cons element v) results))))
1276       ;; Now we have all the styles, so we insert them.
1277       (setq name (assq 'name results)
1278             address (assq 'address results))
1279       (setq results (delq name (delq address results)))
1280       (make-local-variable 'message-setup-hook)
1281       (dolist (result results)
1282         (when (cdr result)
1283           (add-hook 'message-setup-hook
1284                     (cond
1285                      ((eq 'eval (car result))
1286                       'ignore)
1287                      ((eq 'body (car result))
1288                       `(lambda ()
1289                          (save-excursion
1290                            (message-goto-body)
1291                            (insert ,(cdr result)))))
1292                      ((eq 'signature (car result))
1293                       (set (make-local-variable 'message-signature) nil)
1294                       (set (make-local-variable 'message-signature-file) nil)
1295                       `(lambda ()
1296                          (save-excursion
1297                            (let ((message-signature ,(cdr result)))
1298                              (message-insert-signature)))))
1299                      (t
1300                       (let ((header
1301                              (if (symbolp (car result))
1302                                  (capitalize (symbol-name (car result)))
1303                                (car result))))
1304                         `(lambda ()
1305                            (save-excursion
1306                              (message-remove-header ,header)
1307                              (message-goto-eoh)
1308                              (insert ,header ": " ,(cdr result) "\n")))))))))
1309       (when (or name address)
1310         (add-hook 'message-setup-hook
1311                   `(lambda ()
1312                      (let ((user-full-name ,(or (cdr name) user-full-name))
1313                            (user-mail-address
1314                             ,(or (cdr address) user-mail-address)))
1315                        (save-excursion
1316                          (message-remove-header "From")
1317                          (message-goto-eoh)
1318                          (insert "From: " (message-make-from) "\n")))))))))
1319
1320
1321 ;;; @ for MIME Edit mode
1322 ;;;
1323
1324 (defun gnus-maybe-setup-default-charset ()
1325   (let ((charset
1326          (and (boundp 'gnus-summary-buffer)
1327               (buffer-live-p gnus-summary-buffer)
1328               (save-excursion
1329                 (set-buffer gnus-summary-buffer)
1330                 default-mime-charset))))
1331     (if charset
1332         (progn
1333           (make-local-variable 'default-mime-charset)
1334           (setq default-mime-charset charset)
1335           ))))
1336
1337
1338 ;;; @ for MIME view mode
1339 ;;;
1340
1341 (defun gnus-following-method (buf)
1342   (gnus-setup-message 'reply-yank
1343     (set-buffer buf)
1344     (if (message-news-p)
1345         (message-followup)
1346       (message-reply nil 'wide))
1347     (let ((message-reply-buffer buf))
1348       (message-yank-original))
1349     (message-goto-body))
1350   (kill-buffer buf))
1351
1352
1353 ;;; Allow redefinition of functions.
1354
1355 (gnus-ems-redefine)
1356
1357 (provide 'gnus-msg)
1358
1359 ;;; gnus-msg.el ends here