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