(gnus-build-sparse-threads): Use `make-full-mail-header-from-decoded-header'
[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             ;; Encode bitmap smileys to ordinary text.
486             ;; Possibly, the original text might be restored.
487             (static-unless (featurep 'xemacs)
488               (when (featurep 'smiley-mule)
489                 (smiley-encode-buffer)))
490             (gnus-article-delete-text-of-type 'annotation)
491             (gnus-remove-text-with-property 'gnus-prev)
492             (gnus-remove-text-with-property 'gnus-next)
493             (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
494             (insert
495              (prog1
496                  (buffer-substring-no-properties (point-min) (point-max))
497                (erase-buffer))))
498           ;; Find the original headers.
499           (set-buffer gnus-original-article-buffer)
500           (goto-char (point-min))
501           (while (looking-at message-unix-mail-delimiter)
502             (forward-line 1))
503           (setq beg (point))
504           (setq end (or (search-forward "\n\n" nil t) (point)))
505           ;; Delete the headers from the displayed articles.
506           (set-buffer gnus-article-copy)
507           (delete-region (goto-char (point-min))
508                          (or (search-forward "\n\n" nil t) (point-max)))
509           ;; Insert the original article headers.
510           (insert-buffer-substring gnus-original-article-buffer beg end)
511           (article-decode-encoded-words)))
512       gnus-article-copy)))
513
514 (defun gnus-post-news (post &optional group header article-buffer yank subject
515                             force-news)
516   (when article-buffer
517     (gnus-copy-article-buffer))
518   (let ((gnus-article-reply article-buffer)
519         (add-to-list gnus-add-to-list))
520     (gnus-setup-message (cond (yank 'reply-yank)
521                               (article-buffer 'reply)
522                               (t 'message))
523       (let* ((group (or group gnus-newsgroup-name))
524              (charset (gnus-group-name-charset nil group))
525              (pgroup group)
526              to-address to-group mailing-list to-list
527              newsgroup-p)
528         (when group
529           (setq to-address (gnus-group-find-parameter group 'to-address)
530                 to-group (gnus-group-find-parameter group 'to-group)
531                 to-list (gnus-group-find-parameter group 'to-list)
532                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
533                 mailing-list (when gnus-mailing-list-groups
534                                (string-match gnus-mailing-list-groups group))
535                 group (gnus-group-name-decode (gnus-group-real-name group)
536                                               charset)))
537         (if (or (and to-group
538                      (gnus-news-group-p to-group))
539                 newsgroup-p
540                 force-news
541                 (and (gnus-news-group-p
542                       (or pgroup gnus-newsgroup-name)
543                       (if header (mail-header-number header)
544                         gnus-current-article))
545                      (not mailing-list)
546                      (not to-list)
547                      (not to-address)))
548             ;; This is news.
549             (if post
550                 (message-news (or to-group group))
551               (set-buffer gnus-article-copy)
552               (gnus-msg-treat-broken-reply-to)
553               (message-followup (if (or newsgroup-p force-news) nil to-group)))
554           ;; The is mail.
555           (if post
556               (progn
557                 (message-mail (or to-address to-list))
558                 ;; Arrange for mail groups that have no `to-address' to
559                 ;; get that when the user sends off the mail.
560                 (when (and (not to-list)
561                            (not to-address)
562                            add-to-list)
563                   (push (list 'gnus-inews-add-to-address pgroup)
564                         message-send-actions)))
565             (set-buffer gnus-article-copy)
566             (gnus-msg-treat-broken-reply-to)
567             (message-wide-reply to-address)))
568         (when yank
569           (gnus-inews-yank-articles yank))))))
570
571 (defun gnus-msg-treat-broken-reply-to ()
572   "Remove the Reply-to header iff broken-reply-to."
573   (when (gnus-group-find-parameter
574          gnus-newsgroup-name 'broken-reply-to)
575     (save-restriction
576       (message-narrow-to-head)
577       (message-remove-header "reply-to"))))
578
579 (defun gnus-post-method (arg group &optional silent)
580   "Return the posting method based on GROUP and ARG.
581 If SILENT, don't prompt the user."
582   (let ((group-method (gnus-find-method-for-group group)))
583     (cond
584      ;; If the group-method is nil (which shouldn't happen) we use
585      ;; the default method.
586      ((null group-method)
587       (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
588           gnus-select-method message-post-method))
589      ;; We want the inverse of the default
590      ((and arg (not (eq arg 0)))
591       (if (eq gnus-post-method 'active)
592           gnus-select-method
593         group-method))
594      ;; We query the user for a post method.
595      ((or arg
596           (and gnus-post-method
597                (not (eq gnus-post-method 'current))
598                (listp (car gnus-post-method))))
599       (let* ((methods
600               ;; Collect all methods we know about.
601               (append
602                (when (and gnus-post-method
603                           (not (eq gnus-post-method 'current)))
604                  (if (listp (car gnus-post-method))
605                      gnus-post-method
606                    (list gnus-post-method)))
607                gnus-secondary-select-methods
608                (mapcar 'cdr gnus-server-alist)
609                (mapcar 'car gnus-opened-servers)
610                (list gnus-select-method)
611                (list group-method)))
612              method-alist post-methods method)
613         ;; Weed out all mail methods.
614         (while methods
615           (setq method (gnus-server-get-method "" (pop methods)))
616           (when (and (or (gnus-method-option-p method 'post)
617                          (gnus-method-option-p method 'post-mail))
618                      (not (member method post-methods)))
619             (push method post-methods)))
620         ;; Create a name-method alist.
621         (setq method-alist
622               (mapcar
623                (lambda (m)
624                  (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
625                post-methods))
626         ;; Query the user.
627         (cadr
628          (assoc
629           (setq gnus-last-posting-server
630                 (if (and silent
631                          gnus-last-posting-server)
632                     ;; Just use the last value.
633                     gnus-last-posting-server
634                   (completing-read
635                    "Posting method: " method-alist nil t
636                    (cons (or gnus-last-posting-server "") 0))))
637           method-alist))))
638      ;; Override normal method.
639      ((and (eq gnus-post-method 'current)
640            (not (eq (car group-method) 'nndraft))
641            (gnus-get-function group-method 'request-post t)
642            (not arg))
643       group-method)
644      ((and gnus-post-method
645            (not (eq gnus-post-method 'current)))
646       gnus-post-method)
647      ;; Use the normal select method.
648      (t gnus-select-method))))
649
650 \f
651
652 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
653   "Return user-agent info.
654 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
655   `mime-edit-user-agent-value' exists, the return value will include it.
656 MAX-COLUMN the optional second argument if it is specified, the return value
657   will be folded up in the proper way."
658   (let ((user-agent (if (and include-mime-info
659                              (boundp 'mime-edit-user-agent-value))
660                         (concat (gnus-extended-version)
661                                 " "
662                                 mime-edit-user-agent-value)
663                       (gnus-extended-version))))
664     (if max-column
665         (let (boundary)
666           (unless (natnump max-column) (setq max-column 76))
667           (with-temp-buffer
668             (insert "            " user-agent)
669             (goto-char 13)
670             (while (re-search-forward "[\n\t ]+" nil t)
671               (replace-match " "))
672             (goto-char 13)
673             (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
674               (while (eq ?\( (char-after (point)))
675                 (forward-list)
676                 (skip-chars-forward " "))
677               (skip-chars-backward " ")
678               (if (> (current-column) max-column)
679                   (progn
680                     (if (or (not boundary) (eq ?\n (char-after boundary)))
681                         (progn
682                           (setq boundary (point))
683                           (unless (eobp)
684                             (delete-char 1)
685                             (insert "\n ")))
686                       (goto-char boundary)
687                       (delete-char 1)
688                       (insert "\n ")))
689                 (setq boundary (point))))
690             (buffer-substring 13 (point-max))))
691       user-agent)))
692
693 \f
694 ;;;
695 ;;; Gnus Mail Functions
696 ;;;
697
698 ;;; Mail reply commands of Gnus summary mode
699
700 (defun gnus-summary-reply (&optional yank wide)
701   "Start composing a reply mail to the current message.
702 If prefix argument YANK is non-nil, the original article is yanked
703 automatically."
704   (interactive
705    (list (and current-prefix-arg
706               (gnus-summary-work-articles 1))))
707   ;; Stripping headers should be specified with mail-yank-ignored-headers.
708   (when yank
709     (gnus-summary-goto-subject (car yank)))
710   (let ((gnus-article-reply t))
711     (gnus-setup-message (if yank 'reply-yank 'reply)
712       (gnus-summary-select-article)
713       (set-buffer (gnus-copy-article-buffer))
714       (gnus-msg-treat-broken-reply-to)
715       (message-reply nil wide)
716       (when yank
717         (gnus-inews-yank-articles yank)))))
718
719 (defun gnus-summary-reply-with-original (n &optional wide)
720   "Start composing a reply mail to the current message.
721 The original article will be yanked."
722   (interactive "P")
723   (gnus-summary-reply (gnus-summary-work-articles n) wide))
724
725 (defun gnus-summary-wide-reply (&optional yank)
726   "Start composing a wide reply mail to the current message.
727 If prefix argument YANK is non-nil, the original article is yanked
728 automatically."
729   (interactive
730    (list (and current-prefix-arg
731               (gnus-summary-work-articles 1))))
732   (gnus-summary-reply yank t))
733
734 (defun gnus-summary-wide-reply-with-original (n)
735   "Start composing a wide reply mail to the current message.
736 The original article will be yanked."
737   (interactive "P")
738   (gnus-summary-reply-with-original n t))
739
740 (defun gnus-summary-mail-forward (&optional full-headers post)
741   "Forward the current message to another user.
742 If FULL-HEADERS (the prefix), include full headers when forwarding."
743   (interactive "P")
744   (gnus-setup-message 'forward
745     (gnus-summary-select-article)
746     (let ((charset default-mime-charset))
747       (set-buffer gnus-original-article-buffer)
748       (make-local-variable 'default-mime-charset)
749       (setq default-mime-charset charset)
750       )
751     (let ((message-included-forward-headers
752            (if full-headers "" message-included-forward-headers)))
753       (message-forward post))))
754
755 ;;;;; XXX: generate Subject and ``Topics''?
756 ;;(defun gnus-summary-mail-digest (&optional n post)
757 ;;  "Digests and forwards all articles in this series."
758 ;;  (interactive "P")
759 ;;  (let ((subject "Digested Articles")
760 ;;      (articles (gnus-summary-work-articles n))
761 ;;      article frame)
762 ;;    (gnus-setup-message 'forward
763 ;;      (gnus-summary-select-article)
764 ;;      (if post (message-news nil subject) (message-mail nil subject))
765 ;;      (when (and message-use-multi-frames (cdr articles))
766 ;;      (setq frame (window-frame (get-buffer-window (current-buffer)))))
767 ;;      (message-goto-body)
768 ;;      (while (setq article (pop articles))
769 ;;      (save-window-excursion
770 ;;        (set-buffer gnus-summary-buffer)
771 ;;        (gnus-summary-select-article nil nil nil article)
772 ;;        (gnus-summary-remove-process-mark article))
773 ;;      (when frame
774 ;;        (select-frame frame))
775 ;;      (insert (mime-make-tag "message" "rfc822") "\n")
776 ;;      (insert-buffer-substring gnus-original-article-buffer))
777 ;;      (push-mark)
778 ;;      (message-goto-body)
779 ;;      (mime-edit-enclose-digest-region (point)(mark t)))))
780 ;;
781 ;;(defun gnus-summary-post-digest (&optional n)
782 ;;  "Digest and forwards all articles in this series to a newsgroup."
783 ;;  (interactive "P")
784 ;;  (gnus-summary-mail-digest n t))
785
786 (defun gnus-summary-resend-message (address n)
787   "Resend the current article to ADDRESS."
788   (interactive "sResend message(s) to: \nP")
789   (let ((articles (gnus-summary-work-articles n))
790         article)
791     (while (setq article (pop articles))
792       (gnus-summary-select-article nil nil nil article)
793       (save-excursion
794         (set-buffer gnus-original-article-buffer)
795         (message-resend address)))))
796
797 (defun gnus-summary-post-forward (&optional full-headers)
798   "Forward the current article to a newsgroup.
799 If FULL-HEADERS (the prefix), include full headers when forwarding."
800   (interactive "P")
801   (gnus-summary-mail-forward full-headers t))
802
803 (defvar gnus-nastygram-message
804   "The following article was inappropriately posted to %s.\n\n"
805   "Format string to insert in nastygrams.
806 The current group name will be inserted at \"%s\".")
807
808 (defun gnus-summary-mail-nastygram (n)
809   "Send a nastygram to the author of the current article."
810   (interactive "P")
811   (when (or gnus-expert-user
812             (gnus-y-or-n-p
813              "Really send a nastygram to the author of the current article? "))
814     (let ((group gnus-newsgroup-name))
815       (gnus-summary-reply-with-original n)
816       (set-buffer gnus-message-buffer)
817       (message-goto-body)
818       (insert (format gnus-nastygram-message group))
819       (message-send-and-exit))))
820
821 (defun gnus-summary-mail-crosspost-complaint (n)
822   "Send a complaint about crossposting to the current article(s)."
823   (interactive "P")
824   (let ((articles (gnus-summary-work-articles n))
825         article)
826     (while (setq article (pop articles))
827       (set-buffer gnus-summary-buffer)
828       (gnus-summary-goto-subject article)
829       (let ((group (gnus-group-real-name gnus-newsgroup-name))
830             newsgroups followup-to)
831         (gnus-summary-select-article)
832         (set-buffer gnus-original-article-buffer)
833         (if (and (<= (length (message-tokenize-header
834                               (setq newsgroups
835                                     (mail-fetch-field "newsgroups"))
836                               ", "))
837                      1)
838                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
839                      (not (member group (message-tokenize-header
840                                          followup-to ", ")))))
841             (if followup-to
842                 (gnus-message 1 "Followup-to restricted")
843               (gnus-message 1 "Not a crossposted article"))
844           (set-buffer gnus-summary-buffer)
845           (gnus-summary-reply-with-original 1)
846           (set-buffer gnus-message-buffer)
847           (message-goto-body)
848           (insert (format gnus-crosspost-complaint newsgroups group))
849           (message-goto-subject)
850           (re-search-forward " *$")
851           (replace-match " (crosspost notification)" t t)
852           (gnus-deactivate-mark)
853           (when (gnus-y-or-n-p "Send this complaint? ")
854             (message-send-and-exit)))))))
855
856 (defun gnus-summary-mail-other-window ()
857   "Compose mail in other window."
858   (interactive)
859   (gnus-setup-message 'message
860     (message-mail)))
861
862 (defun gnus-mail-parse-comma-list ()
863   (let (accumulated
864         beg)
865     (skip-chars-forward " ")
866     (while (not (eobp))
867       (setq beg (point))
868       (skip-chars-forward "^,")
869       (while (zerop
870               (save-excursion
871                 (save-restriction
872                   (let ((i 0))
873                     (narrow-to-region beg (point))
874                     (goto-char beg)
875                     (logand (progn
876                               (while (search-forward "\"" nil t)
877                                 (incf i))
878                               (if (zerop i) 2 i))
879                             2)))))
880         (skip-chars-forward ",")
881         (skip-chars-forward "^,"))
882       (skip-chars-backward " ")
883       (push (buffer-substring beg (point))
884             accumulated)
885       (skip-chars-forward "^,")
886       (skip-chars-forward ", "))
887     accumulated))
888
889 (defun gnus-inews-add-to-address (group)
890   (let ((to-address (mail-fetch-field "to")))
891     (when (and to-address
892                (gnus-alive-p))
893       ;; This mail group doesn't have a `to-list', so we add one
894       ;; here.  Magic!
895       (when (gnus-y-or-n-p
896              (format "Do you want to add this as `to-list': %s " to-address))
897         (gnus-group-add-parameter group (cons 'to-list to-address))))))
898
899 (defun gnus-put-message ()
900   "Put the current message in some group and return to Gnus."
901   (interactive)
902   (let ((reply gnus-article-reply)
903         (winconf gnus-prev-winconf)
904         (group gnus-newsgroup-name))
905
906     (or (and group (not (gnus-group-read-only-p group)))
907         (setq group (read-string "Put in group: " nil
908                                  (gnus-writable-groups))))
909     (when (gnus-gethash group gnus-newsrc-hashtb)
910       (error "No such group: %s" group))
911
912     (save-excursion
913       (save-restriction
914         (widen)
915         (message-narrow-to-headers)
916         (let (gnus-deletable-headers)
917           (if (message-news-p)
918               (message-generate-headers message-required-news-headers)
919             (message-generate-headers message-required-mail-headers)))
920         (goto-char (point-max))
921         (insert "Gcc: " group "\n")
922         (widen)))
923
924     (gnus-inews-do-gcc)
925
926     (when (get-buffer gnus-group-buffer)
927       (when (gnus-buffer-exists-p (car-safe reply))
928         (set-buffer (car reply))
929         (and (cdr reply)
930              (gnus-summary-mark-article-as-replied
931               (cdr reply))))
932       (when winconf
933         (set-window-configuration winconf)))))
934
935 (defun gnus-article-mail (yank)
936   "Send a reply to the address near point.
937 If YANK is non-nil, include the original article."
938   (interactive "P")
939   (let ((address
940          (buffer-substring
941           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
942           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
943     (when address
944       (message-reply address)
945       (when yank
946         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
947
948 (defvar nntp-server-type)
949 (defun gnus-bug ()
950   "Send a bug report to the Gnus maintainers."
951   (interactive)
952   (unless (gnus-alive-p)
953     (error "Gnus has been shut down"))
954   (gnus-setup-message 'bug
955     (delete-other-windows)
956     (when gnus-bug-create-help-buffer
957       (switch-to-buffer "*Gnus Help Bug*")
958       (erase-buffer)
959       (insert gnus-bug-message)
960       (goto-char (point-min)))
961     (message-pop-to-buffer "*Gnus Bug*")
962     (message-setup `((To . ,gnus-maintainer) (Subject . "")))
963     (when gnus-bug-create-help-buffer
964       (push `(gnus-bug-kill-buffer) message-send-actions))
965     (goto-char (point-min))
966     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
967     (forward-line 1)
968     (insert gnus-product-name " " gnus-version-number
969             " (r" gnus-revision-number ") "
970             "based on " gnus-original-product-name " v"
971             gnus-original-version-number "\n"
972             (emacs-version) "\n")
973     (when (and (boundp 'nntp-server-type)
974                (stringp nntp-server-type))
975       (insert nntp-server-type))
976     (insert "\n\n\n\n\n")
977     (let (mime-content-types)
978       (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
979     (insert (with-temp-buffer
980               (gnus-debug)
981               (buffer-string)))
982     (let (mime-content-types)
983       (mime-edit-insert-tag "text" "plain"))
984     (goto-char (point-min))
985     (search-forward "Subject: " nil t)
986     (message "")))
987
988 (defun gnus-bug-kill-buffer ()
989   (when (get-buffer "*Gnus Help Bug*")
990     (kill-buffer "*Gnus Help Bug*")))
991
992 (defun gnus-summary-yank-message (buffer n)
993   "Yank the current article into a composed message."
994   (interactive
995    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
996          current-prefix-arg))
997   (when (gnus-buffer-live-p buffer)
998     (let ((summary-frame (selected-frame))
999           (message-frame (when (static-if (featurep 'xemacs)
1000                                    (device-on-window-system-p)
1001                                  window-system)
1002                            (let ((window (get-buffer-window buffer t)))
1003                              (when window
1004                                (window-frame window)))))
1005           (separator (concat "^" (regexp-quote mail-header-separator)
1006                              "\n")))
1007       (gnus-summary-iterate n
1008         (gnus-summary-select-article)
1009         (gnus-copy-article-buffer)
1010         (when (frame-live-p message-frame)
1011           (raise-frame message-frame)
1012           (select-frame message-frame))
1013         (with-current-buffer buffer
1014           (when (save-excursion
1015                   (beginning-of-line)
1016                   (let (case-fold-search)
1017                     (and (not (re-search-backward separator nil t))
1018                          (re-search-forward separator nil t))))
1019             (goto-char (match-end 0)))
1020           (message-yank-buffer gnus-article-copy))
1021         (select-frame summary-frame))
1022       (when (frame-live-p message-frame)
1023         (select-frame message-frame)))))
1024
1025 (defun gnus-debug ()
1026   "Attempts to go through the Gnus source file and report what variables have been changed.
1027 The source file has to be in the Emacs load path."
1028   (interactive)
1029   (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1030                  "gnus-art.el" "gnus-start.el" "gnus-async.el"
1031                  "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1032                  "nnmail.el" "nntp.el" "message.el"))
1033         (point (point))
1034         file expr olist sym)
1035     (gnus-message 4 "Please wait while we snoop your variables...")
1036     (sit-for 0)
1037     ;; Go through all the files looking for non-default values for variables.
1038     (save-excursion
1039       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1040       (while files
1041         (erase-buffer)
1042         (when (and (setq file (locate-library (pop files)))
1043                    (file-exists-p file))
1044           (insert-file-contents file)
1045           (goto-char (point-min))
1046           (if (not (re-search-forward "^;;* *Internal variables" nil t))
1047               (gnus-message 4 "Malformed sources in file %s" file)
1048             (narrow-to-region (point-min) (point))
1049             (goto-char (point-min))
1050             (while (setq expr (ignore-errors (read (current-buffer))))
1051               (ignore-errors
1052                 (and (memq (car expr) '(defvar defcustom defvoo))
1053                      (stringp (nth 3 expr))
1054                      (or (not (boundp (nth 1 expr)))
1055                          (not (equal (eval (nth 2 expr))
1056                                      (symbol-value (nth 1 expr)))))
1057                      (push (nth 1 expr) olist)))))))
1058       (kill-buffer (current-buffer)))
1059     (when (setq olist (nreverse olist))
1060       (insert ";----------------- Environment follows ------------------\n\n"))
1061     (while olist
1062       (if (boundp (car olist))
1063           (condition-case ()
1064               (pp `(setq ,(car olist)
1065                          ,(if (or (consp (setq sym (symbol-value (car olist))))
1066                                   (and (symbolp sym)
1067                                        (not (or (eq sym nil)
1068                                                 (eq sym t)))))
1069                               (list 'quote (symbol-value (car olist)))
1070                             (symbol-value (car olist))))
1071                   (current-buffer))
1072             (error
1073              (format "(setq %s 'whatever)\n" (car olist))))
1074         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1075       (setq olist (cdr olist)))
1076     ;; Remove any control chars - they seem to cause trouble for some
1077     ;; mailers.  (Byte-compiled output from the stuff above.)
1078     (goto-char point)
1079     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1080       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1081                      t t))
1082     ;; Break MIME tags purposely.
1083     (goto-char point)
1084     (while (re-search-forward mime-edit-tag-regexp nil t)
1085       (goto-char (1+ (match-beginning 0)))
1086       (insert "X"))))
1087
1088 ;;; Treatment of rejected articles.
1089 ;;; Bounced mail.
1090
1091 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1092   "Re-mail the current message.
1093 This only makes sense if the current message is a bounce message than
1094 contains some mail you have written which has been bounced back to
1095 you.
1096 If FETCH, try to fetch the article that this is a reply to, if indeed
1097 this is a reply."
1098   (interactive "P")
1099   (gnus-summary-select-article t)
1100   (set-buffer gnus-original-article-buffer)
1101   (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1102     (gnus-setup-message 'compose-bounce
1103       (let* ((references (mail-fetch-field "references"))
1104              (parent (and references (gnus-parent-id references))))
1105         (message-bounce)
1106         ;; If there are references, we fetch the article we answered to.
1107         (and fetch parent
1108              (gnus-summary-refer-article parent)
1109              (gnus-summary-show-all-headers))))))
1110
1111 ;;; Gcc handling.
1112
1113 ;; Do Gcc handling, which copied the message over to some group.
1114 (defun gnus-inews-do-gcc (&optional gcc)
1115   (interactive)
1116   (when (gnus-alive-p)
1117     (save-excursion
1118       (save-restriction
1119         (message-narrow-to-headers)
1120         (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1121               (coding-system-for-write 'raw-text)
1122               (output-coding-system 'raw-text)
1123               groups group method)
1124           (when gcc
1125             (message-remove-header "gcc")
1126             (widen)
1127             (setq groups (message-unquote-tokens
1128                           (message-tokenize-header gcc " ,")))
1129             ;; Copy the article over to some group(s).
1130             (while (setq group (pop groups))
1131               (gnus-check-server
1132                (setq method
1133                      (cond ((and (null (gnus-get-info group))
1134                                  (eq (car gnus-message-archive-method)
1135                                      (car
1136                                       (gnus-server-to-method
1137                                        (gnus-group-method group)))))
1138                             ;; If the group doesn't exist, we assume
1139                             ;; it's an archive group...
1140                             gnus-message-archive-method)
1141                            ;; Use the method.
1142                            ((gnus-info-method (gnus-get-info group))
1143                             (gnus-info-method (gnus-get-info group)))
1144                            ;; Find the method.
1145                            (t (gnus-group-method group)))))
1146               (gnus-check-server method)
1147               (unless (gnus-request-group group t method)
1148                 (gnus-request-create-group group method))
1149               (save-excursion
1150                 (nnheader-set-temp-buffer " *acc*")
1151                 (insert-buffer-substring message-encoding-buffer)
1152                 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1153                 (goto-char (point-min))
1154                 (when (re-search-forward
1155                        (concat "^" (regexp-quote mail-header-separator) "$")
1156                        nil t)
1157                   (replace-match "" t t ))
1158                 (unless (gnus-request-accept-article group method t t)
1159                   (gnus-message 1 "Couldn't store article in group %s: %s"
1160                                 group (gnus-status-message method))
1161                   (sit-for 2))
1162                 (kill-buffer (current-buffer))))))))))
1163
1164 (defun gnus-inews-insert-gcc ()
1165   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1166   (save-excursion
1167     (save-restriction
1168       (message-narrow-to-headers)
1169       (let* ((group gnus-outgoing-message-group)
1170              (gcc (cond
1171                    ((gnus-functionp group)
1172                     (funcall group))
1173                    ((or (stringp group) (list group))
1174                     group))))
1175         (when gcc
1176           (insert "Gcc: "
1177                   (if (stringp gcc) gcc
1178                     (mapconcat 'identity gcc " "))
1179                   "\n"))))))
1180
1181 (defun gnus-inews-insert-archive-gcc (&optional group)
1182   "Insert the Gcc to say where the article is to be archived."
1183   (let* ((var gnus-message-archive-group)
1184          (group (or group gnus-newsgroup-name ""))
1185          (gcc-self-val
1186           (and gnus-newsgroup-name
1187                (not (equal gnus-newsgroup-name ""))
1188                (gnus-group-find-parameter
1189                 gnus-newsgroup-name 'gcc-self)))
1190          result
1191          (groups
1192           (cond
1193            ((null gnus-message-archive-method)
1194             ;; Ignore.
1195             nil)
1196            ((stringp var)
1197             ;; Just a single group.
1198             (list var))
1199            ((null var)
1200             ;; We don't want this.
1201             nil)
1202            ((and (listp var) (stringp (car var)))
1203             ;; A list of groups.
1204             var)
1205            ((gnus-functionp var)
1206             ;; A function.
1207             (funcall var group))
1208            (t
1209             ;; An alist of regexps/functions/forms.
1210             (while (and var
1211                         (not
1212                          (setq result
1213                                (cond
1214                                 ((stringp (caar var))
1215                                  ;; Regexp.
1216                                  (when (string-match (caar var) group)
1217                                    (cdar var)))
1218                                 ((gnus-functionp (car var))
1219                                  ;; Function.
1220                                  (funcall (car var) group))
1221                                 (t
1222                                  (eval (car var)))))))
1223               (setq var (cdr var)))
1224             result)))
1225          name)
1226     (when (or groups gcc-self-val)
1227       (when (stringp groups)
1228         (setq groups (list groups)))
1229       (save-excursion
1230         (save-restriction
1231           (message-narrow-to-headers)
1232           (goto-char (point-max))
1233           (insert "Gcc: ")
1234           (if gcc-self-val
1235               ;; Use the `gcc-self' param value instead.
1236               (progn
1237                 (insert
1238                  (if (stringp gcc-self-val)
1239                      gcc-self-val
1240                    group))
1241                 (if (not (eq gcc-self-val 'none))
1242                     (insert "\n")
1243                   (progn
1244                     (beginning-of-line)
1245                     (kill-line))))
1246             ;; Use the list of groups.
1247             (while (setq name (pop groups))
1248               (insert (if (string-match ":" name)
1249                           name
1250                         (gnus-group-prefixed-name
1251                          name gnus-message-archive-method)))
1252               (when groups
1253                 (insert " ")))
1254             (insert "\n")))))))
1255
1256 ;;; Posting styles.
1257
1258 (defun gnus-configure-posting-styles ()
1259   "Configure posting styles according to `gnus-posting-styles'."
1260   (unless gnus-inhibit-posting-styles
1261     (let ((group (or gnus-newsgroup-name ""))
1262           (styles gnus-posting-styles)
1263           style match variable attribute value v results
1264           filep name address element)
1265       ;; If the group has a posting-style parameter, add it at the end with a
1266       ;; regexp matching everything, to be sure it takes precedence over all
1267       ;; the others.
1268       (when gnus-newsgroup-name
1269         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1270           (when tmp-style
1271             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1272       ;; Go through all styles and look for matches.
1273       (dolist (style styles)
1274         (setq match (pop style))
1275         (goto-char (point-min))
1276         (when (cond
1277                ((stringp match)
1278                 ;; Regexp string match on the group name.
1279                 (string-match match group))
1280                ((eq match 'header)
1281                 (let ((header (message-fetch-field (pop style))))
1282                   (and header
1283                        (string-match (pop style) header))))
1284                ((or (symbolp match)
1285                     (gnus-functionp match))
1286                 (cond
1287                  ((gnus-functionp match)
1288                   ;; Function to be called.
1289                   (funcall match))
1290                  ((boundp match)
1291                   ;; Variable to be checked.
1292                   (symbol-value match))))
1293                ((listp match)
1294                 ;; This is a form to be evaled.
1295                 (eval match)))
1296           ;; We have a match, so we set the variables.
1297           (dolist (attribute style)
1298             (setq element (pop attribute)
1299                   variable nil
1300                   filep nil)
1301             (setq value
1302                   (cond
1303                    ((eq (car attribute) ':file)
1304                     (setq filep t)
1305                     (cadr attribute))
1306                    ((eq (car attribute) :value)
1307                     (cadr attribute))
1308                    (t
1309                     (car attribute))))
1310             ;; We get the value.
1311             (setq v
1312                   (cond
1313                    ((stringp value)
1314                     value)
1315                    ((or (symbolp value)
1316                         (gnus-functionp value))
1317                     (cond ((gnus-functionp value)
1318                            (funcall value))
1319                           ((boundp value)
1320                            (symbol-value value))))
1321                    ((listp value)
1322                     (eval value))))
1323             ;; Translate obsolescent value.
1324             (when (eq element 'signature-file)
1325               (setq element 'signature
1326                     filep t))
1327             ;; Get the contents of file elems.
1328             (when (and filep v)
1329               (setq v (with-temp-buffer
1330                         (insert-file-contents v)
1331                         (buffer-string))))
1332             (setq results (delq (assoc element results) results))
1333             (push (cons element v) results))))
1334       ;; Now we have all the styles, so we insert them.
1335       (setq name (assq 'name results)
1336             address (assq 'address results))
1337       (setq results (delq name (delq address results)))
1338       (make-local-variable 'message-setup-hook)
1339       (dolist (result results)
1340         (add-hook 'message-setup-hook
1341                   (cond
1342                    ((eq 'eval (car result))
1343                     'ignore)
1344                    ((eq 'body (car result))
1345                     `(lambda ()
1346                        (save-excursion
1347                          (message-goto-body)
1348                          (insert ,(cdr result)))))
1349                    ((eq 'signature (car result))
1350                     (set (make-local-variable 'message-signature) nil)
1351                     (set (make-local-variable 'message-signature-file) nil)
1352                     (if (not (cdr result))
1353                         'ignore
1354                       `(lambda ()
1355                          (save-excursion
1356                            (let ((message-signature ,(cdr result)))
1357                              (when message-signature
1358                                (message-insert-signature)))))))
1359                    (t
1360                     (let ((header
1361                            (if (symbolp (car result))
1362                                (capitalize (symbol-name (car result)))
1363                              (car result))))
1364                       `(lambda ()
1365                          (save-excursion
1366                            (message-remove-header ,header)
1367                            (let ((value ,(cdr result)))
1368                              (when value
1369                                (message-goto-eoh)
1370                                (insert ,header ": " value "\n"))))))))))
1371       (when (or name address)
1372         (add-hook 'message-setup-hook
1373                   `(lambda ()
1374                      (set (make-local-variable 'user-mail-address)
1375                           ,(or (cdr address) user-mail-address))
1376                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1377                            (user-mail-address
1378                             ,(or (cdr address) user-mail-address)))
1379                        (save-excursion
1380                          (message-remove-header "From")
1381                          (message-goto-eoh)
1382                          (insert "From: " (message-make-from) "\n")))))))))
1383
1384
1385 ;;; @ for MIME Edit mode
1386 ;;;
1387
1388 (defun gnus-maybe-setup-default-charset ()
1389   (let ((charset
1390          (and (boundp 'gnus-summary-buffer)
1391               (buffer-live-p gnus-summary-buffer)
1392               (save-excursion
1393                 (set-buffer gnus-summary-buffer)
1394                 default-mime-charset))))
1395     (if charset
1396         (progn
1397           (make-local-variable 'default-mime-charset)
1398           (setq default-mime-charset charset)
1399           ))))
1400
1401
1402 ;;; @ for MIME view mode
1403 ;;;
1404
1405 (defun gnus-following-method (buf)
1406   (gnus-setup-message 'reply-yank
1407     (set-buffer buf)
1408     (if (message-news-p)
1409         (message-followup)
1410       (message-reply nil 'wide))
1411     (let ((message-reply-buffer buf))
1412       (message-yank-original))
1413     (message-goto-body))
1414   (kill-buffer buf))
1415
1416
1417 ;;; Allow redefinition of functions.
1418
1419 (gnus-ems-redefine)
1420
1421 (provide 'gnus-msg)
1422
1423 ;;; gnus-msg.el ends here