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