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