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