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