*** empty log message ***
[gnus] / lisp / gnus-msg.el
1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
3
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;;      Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (require 'gnus)
30 (require 'gnus-ems)
31 (require 'message)
32 (require 'gnus-art)
33
34 ;; Added by Sudish Joseph <joseph@cis.ohio-state.edu>.
35 (defvar gnus-post-method nil
36   "*Preferred method for posting USENET news.
37 If this variable is nil, Gnus will use the current method to decide
38 which method to use when posting.  If it is non-nil, it will override
39 the current method.  This method will not be used in mail groups and
40 the like, only in \"real\" newsgroups.
41
42 The value must be a valid method as discussed in the documentation of
43 `gnus-select-method'.  It can also be a list of methods.  If that is
44 the case, the user will be queried for what select method to use when
45 posting.")
46
47 (defvar gnus-outgoing-message-group nil
48   "*All outgoing messages will be put in this group.
49 If you want to store all your outgoing mail and articles in the group
50 \"nnml:archive\", you set this variable to that value.  This variable
51 can also be a list of group names. 
52
53 If you want to have greater control over what group to put each
54 message in, you can set this variable to a function that checks the
55 current newsgroup name and then returns a suitable group name (or list
56 of names).")
57
58 (defvar gnus-mailing-list-groups nil
59   "*Regexp matching groups that are really mailing lists.
60 This is useful when you're reading a mailing list that has been
61 gatewayed to a newsgroup, and you want to followup to an article in
62 the group.")
63
64 (defvar gnus-sent-message-ids-file 
65   (nnheader-concat gnus-directory "Sent-Message-IDs")
66   "File where Gnus saves a cache of sent message ids.")
67
68 (defvar gnus-sent-message-ids-length 1000
69   "The number of sent Message-IDs to save.")
70
71 (defvar gnus-crosspost-complaint
72   "Hi,
73
74 You posted the article below with the following Newsgroups header:
75
76 Newsgroups: %s
77
78 The %s group, at least, was an inappropriate recipient
79 of this message.  Please trim your Newsgroups header to exclude this
80 group before posting in the future.
81
82 Thank you.
83
84 "
85   "Format string to be inserted when complaining about crossposts.
86 The first %s will be replaced by the Newsgroups header;
87 the second with the current group name.")
88
89 ;;; Internal variables.
90
91 (defvar gnus-message-buffer "*Mail Gnus*")
92 (defvar gnus-article-copy nil)
93 (defvar gnus-last-posting-server nil)
94
95 (defconst gnus-bug-message
96   "Sending a bug report to the Gnus Towers.
97 ========================================
98
99 The buffer below is a mail buffer.  When you press `C-c C-c', it will
100 be sent to the Gnus Bug Exterminators.
101
102 At the bottom of the buffer you'll see lots of variable settings.
103 Please do not delete those.  They will tell the Bug People what your
104 environment is, so that it will be easier to locate the bugs.
105
106 If you have found a bug that makes Emacs go \"beep\", set
107 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
108 and include the backtrace in your bug report.
109
110 Please describe the bug in annoying, painstaking detail.
111
112 Thank you for your help in stamping out bugs.
113 ")
114
115 (eval-and-compile
116   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
117   (autoload 'news-setup "rnewspost")
118   (autoload 'news-reply-mode "rnewspost")
119   (autoload 'rmail-dont-reply-to "mail-utils")
120   (autoload 'rmail-output "rmailout"))
121
122 \f
123 ;;;
124 ;;; Gnus Posting Functions
125 ;;;
126
127 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
128   "p" gnus-summary-post-news
129   "f" gnus-summary-followup
130   "F" gnus-summary-followup-with-original
131   "c" gnus-summary-cancel-article
132   "s" gnus-summary-supersede-article
133   "r" gnus-summary-reply
134   "R" gnus-summary-reply-with-original
135   "n" gnus-summary-followup-to-mail
136   "N" gnus-summary-followup-to-mail-with-original
137   "m" gnus-summary-mail-other-window
138   "u" gnus-uu-post-news
139   "\M-c" gnus-summary-mail-crosspost-complaint
140   "om" gnus-summary-mail-forward
141   "op" gnus-summary-post-forward
142   "Om" gnus-uu-digest-mail-forward
143   "Op" gnus-uu-digest-post-forward)
144
145 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
146   "b" gnus-summary-resend-bounced-mail
147   ;; "c" gnus-summary-send-draft
148   "r" gnus-summary-resend-message)
149
150 ;;; Internal functions.
151
152 (defvar gnus-article-reply nil)
153 (defmacro gnus-setup-message (config &rest forms)
154   (let ((winconf (make-symbol "winconf"))
155         (buffer (make-symbol "buffer"))
156         (article (make-symbol "article")))
157     `(let ((,winconf (current-window-configuration))
158            (,buffer (buffer-name (current-buffer)))
159            (,article (and gnus-article-reply (gnus-summary-article-number)))
160            (message-header-setup-hook
161             (copy-sequence message-header-setup-hook)))
162        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
163        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
164        ,@forms
165        (gnus-inews-add-send-actions ,winconf ,buffer ,article)
166        (setq gnus-message-buffer (current-buffer))
167        (make-local-variable 'gnus-newsgroup-name)
168        (gnus-configure-windows ,config t))))
169     
170 (defun gnus-inews-add-send-actions (winconf buffer article)
171   (gnus-make-local-hook 'message-sent-hook)
172   (gnus-add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
173   (setq message-post-method
174         `(lambda (arg)
175            (gnus-post-method arg ,gnus-newsgroup-name)))
176   (setq message-newsreader (setq message-mailer (gnus-extended-version)))
177   (message-add-action
178    `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
179   (message-add-action
180    `(when (buffer-name (get-buffer ,buffer))
181       (save-excursion
182         (set-buffer (get-buffer ,buffer))
183         ,(when article
184            `(gnus-summary-mark-article-as-replied ,article))))
185    'send))
186
187 (put 'gnus-setup-message 'lisp-indent-function 1)
188 (put 'gnus-setup-message 'edebug-form-spec '(form body))
189
190 ;;; Post news commands of Gnus group mode and summary mode
191
192 (defun gnus-group-mail ()
193   "Start composing a mail."
194   (interactive)
195   (gnus-setup-message 'message
196     (message-mail)))
197
198 (defun gnus-group-post-news (&optional arg)
199   "Start composing a news message.
200 If ARG, post to the group under point.
201 If ARG is 1, prompt for a group name."
202   (interactive "P")
203   ;; Bind this variable here to make message mode hooks
204   ;; work ok.
205   (let ((gnus-newsgroup-name
206          (if arg
207              (if (= 1 (prefix-numeric-value arg))
208                  (completing-read "Newsgroup: " gnus-active-hashtb nil
209                                   (gnus-read-active-file-p))
210                (gnus-group-group-name))
211            "")))
212     (gnus-post-news 'post gnus-newsgroup-name)))
213
214 (defun gnus-summary-post-news ()
215   "Start composing a news message."
216   (interactive)
217   (gnus-set-global-variables)
218   (gnus-post-news 'post gnus-newsgroup-name))
219
220 (defun gnus-summary-followup (yank &optional force-news)
221   "Compose a followup to an article.
222 If prefix argument YANK is non-nil, original article is yanked automatically."
223   (interactive 
224    (list (and current-prefix-arg 
225               (gnus-summary-work-articles 1))))
226   (gnus-set-global-variables)
227   (when yank
228     (gnus-summary-goto-subject (car yank)))
229   (save-window-excursion
230     (gnus-summary-select-article))
231   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
232         (gnus-newsgroup-name gnus-newsgroup-name))
233     ;; Send a followup.
234     (gnus-post-news nil gnus-newsgroup-name
235                     headers gnus-article-buffer 
236                     yank nil force-news)))
237
238 (defun gnus-summary-followup-with-original (n &optional force-news)
239   "Compose a followup to an article and include the original article."
240   (interactive "P")
241   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
242
243 (defun gnus-summary-followup-to-mail (&optional arg)
244   "Followup to the current mail message via news."
245   (interactive 
246    (list (and current-prefix-arg 
247               (gnus-summary-work-articles 1))))
248   (gnus-summary-followup arg t))
249
250 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
251   "Followup to the current mail message via news."
252   (interactive "P")
253   (gnus-summary-followup (gnus-summary-work-articles arg) t))
254
255 (defun gnus-inews-yank-articles (articles)
256   (let (beg article)
257     (message-goto-body)
258     (while (setq article (pop articles))
259       (save-window-excursion
260         (set-buffer gnus-summary-buffer)
261         (gnus-summary-select-article nil nil nil article)
262         (gnus-summary-remove-process-mark article))
263       (gnus-copy-article-buffer)
264       (let ((message-reply-buffer gnus-article-copy)
265             (message-reply-headers gnus-current-headers))
266         (message-yank-original)
267         (setq beg (or beg (mark t))))
268       (when articles
269         (insert "\n")))
270     (push-mark)
271     (goto-char beg)))
272
273 (defun gnus-summary-cancel-article (n)
274   "Cancel an article you posted."
275   (interactive "P")
276   (gnus-set-global-variables)
277   (let ((articles (gnus-summary-work-articles n))
278         (message-post-method
279          `(lambda (arg)
280             (gnus-post-method nil ,gnus-newsgroup-name)))
281         article)
282     (while (setq article (pop articles))
283       (when (gnus-summary-select-article t nil nil article)
284         (when (gnus-eval-in-buffer-window gnus-original-article-buffer
285                 (message-cancel-news))
286           (gnus-summary-mark-as-read article gnus-canceled-mark)
287           (gnus-cache-remove-article 1))
288         (gnus-article-hide-headers-if-wanted))
289       (gnus-summary-remove-process-mark article))))
290
291 (defun gnus-summary-supersede-article ()
292   "Compose an article that will supersede a previous article.
293 This is done simply by taking the old article and adding a Supersedes
294 header line with the old Message-ID."
295   (interactive)
296   (gnus-set-global-variables)
297   (let ((article (gnus-summary-article-number)))
298     (gnus-setup-message 'reply-yank
299       (gnus-summary-select-article t)
300       (set-buffer gnus-original-article-buffer)
301       (message-supersede)
302       (push
303        `((lambda ()
304            (gnus-cache-possibly-remove-article ,article nil nil nil t)))
305        message-send-actions))))
306
307 \f
308
309 (defun gnus-copy-article-buffer (&optional article-buffer)
310   ;; make a copy of the article buffer with all text properties removed
311   ;; this copy is in the buffer gnus-article-copy.
312   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
313   ;; this buffer should be passed to all mail/news reply/post routines.
314   (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
315   (buffer-disable-undo gnus-article-copy)
316   (or (memq gnus-article-copy gnus-buffer-list)
317       (push gnus-article-copy gnus-buffer-list))
318   (let ((article-buffer (or article-buffer gnus-article-buffer))
319         end beg contents)
320     (when (and (get-buffer article-buffer)
321                (buffer-name (get-buffer article-buffer)))
322       (save-excursion
323         (set-buffer article-buffer)
324         (save-restriction
325           ;; Copy over the (displayed) article buffer, delete
326           ;; hidden text and remove text properties.
327           (widen)
328           (copy-to-buffer gnus-article-copy (point-min) (point-max))
329           (set-buffer gnus-article-copy)
330           (article-delete-text-of-type 'annotation)
331           (gnus-remove-text-with-property 'gnus-prev)
332           (gnus-remove-text-with-property 'gnus-next)
333           (insert
334            (prog1
335                (format "%s" (buffer-string))
336              (erase-buffer)))
337           ;; Find the original headers.
338           (set-buffer gnus-original-article-buffer)
339           (goto-char (point-min))
340           (while (looking-at message-unix-mail-delimiter)
341             (forward-line 1))
342           (setq beg (point))
343           (setq end (or (search-forward "\n\n" nil t) (point)))
344           ;; Delete the headers from the displayed articles.
345           (set-buffer gnus-article-copy)
346           (delete-region (goto-char (point-min))
347                          (or (search-forward "\n\n" nil t) (point)))
348           ;; Insert the original article headers.
349           (insert-buffer-substring gnus-original-article-buffer beg end)
350           (article-decode-rfc1522)))
351       gnus-article-copy)))
352
353 (defun gnus-post-news (post &optional group header article-buffer yank subject
354                             force-news)
355   (when article-buffer
356     (gnus-copy-article-buffer))
357   (let ((gnus-article-reply article-buffer))
358     (gnus-setup-message (cond (yank 'reply-yank)
359                               (article-buffer 'reply)
360                               (t 'message))
361       (let* ((group (or group gnus-newsgroup-name))
362              (pgroup group)
363              to-address to-group mailing-list to-list 
364              newsgroup-p)
365         (when group
366           (setq to-address (gnus-group-find-parameter group 'to-address)
367                 to-group (gnus-group-find-parameter group 'to-group)
368                 to-list (gnus-group-find-parameter group 'to-list)
369                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
370                 mailing-list (when gnus-mailing-list-groups
371                                (string-match gnus-mailing-list-groups group))
372                 group (gnus-group-real-name group)))
373         (if (or (and to-group
374                      (gnus-news-group-p to-group))
375                 newsgroup-p
376                 force-news
377                 (and (gnus-news-group-p 
378                       (or pgroup gnus-newsgroup-name)
379                       (if header (mail-header-number header)
380                         gnus-current-article))
381                      (not mailing-list)
382                      (not to-list)
383                      (not to-address)))
384             ;; This is news.
385             (if post
386                 (message-news (or to-group group))
387               (set-buffer gnus-article-copy)
388               (message-followup (if (or newsgroup-p force-news) nil to-group)))
389           ;; The is mail.
390           (if post
391               (progn
392                 (message-mail (or to-address to-list))
393                 ;; Arrange for mail groups that have no `to-address' to
394                 ;; get that when the user sends off the mail.
395                 (push (list 'gnus-inews-add-to-address group)
396                       message-send-actions))
397             (set-buffer gnus-article-copy)
398             (message-wide-reply to-address)))
399         (when yank
400           (gnus-inews-yank-articles yank))))))
401
402 (defun gnus-post-method (arg group &optional silent)
403   "Return the posting method based on GROUP and ARG.
404 If SILENT, don't prompt the user."
405   (let ((group-method (gnus-find-method-for-group group)))
406     (cond 
407      ;; If the group-method is nil (which shouldn't happen) we use 
408      ;; the default method.
409      ((null group-method)
410       (or gnus-post-method gnus-select-method message-post-method))
411      ;; We want this group's method.
412      ((and arg (not (eq arg 0)))
413       group-method)
414      ;; We query the user for a post method.
415      ((or arg
416           (and gnus-post-method
417                (listp (car gnus-post-method))))
418       (let* ((methods
419               ;; Collect all methods we know about.
420               (append
421                (when gnus-post-method
422                  (if (listp (car gnus-post-method))
423                      gnus-post-method
424                    (list gnus-post-method)))
425                gnus-secondary-select-methods
426                (list gnus-select-method)
427                (list group-method)))
428              method-alist post-methods method)
429         ;; Weed out all mail methods.
430         (while methods
431           (setq method (gnus-server-get-method "" (pop methods)))
432           (when (or (gnus-method-option-p method 'post)
433                     (gnus-method-option-p method 'post-mail))
434             (push method post-methods)))
435         ;; Create a name-method alist.
436         (setq method-alist
437               (mapcar 
438                (lambda (m)
439                  (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
440                post-methods))
441         ;; Query the user.
442         (cadr
443          (assoc
444           (setq gnus-last-posting-server
445                 (if (and silent
446                          gnus-last-posting-server)
447                     ;; Just use the last value.
448                     gnus-last-posting-server
449                   (completing-read
450                    "Posting method: " method-alist nil t
451                    (cons (or gnus-last-posting-server "") 0))))
452           method-alist))))
453      ;; Override normal method.
454      (gnus-post-method
455       gnus-post-method)
456      ;; Use the normal select method.
457      (t gnus-select-method))))
458
459 (defun gnus-inews-narrow-to-headers ()
460   (widen)
461   (narrow-to-region
462    (goto-char (point-min))
463    (or (and (re-search-forward 
464              (concat "^" (regexp-quote mail-header-separator) "$") nil t)
465             (match-beginning 0))
466        (point-max)))
467   (goto-char (point-min)))
468
469 ;;;
470 ;;; Check whether the message has been sent already.
471 ;;;
472
473 (defvar gnus-inews-sent-ids nil)
474
475 (defun gnus-inews-reject-message ()
476   "Check whether this message has already been sent."
477   (when gnus-sent-message-ids-file
478     (let ((message-id (save-restriction (gnus-inews-narrow-to-headers)
479                                         (mail-fetch-field "message-id")))
480           end)
481       (when message-id
482         (unless gnus-inews-sent-ids
483           (ignore-errors
484             (load t t t)))
485         (if (member message-id gnus-inews-sent-ids)
486             ;; Reject this message.
487             (not (gnus-yes-or-no-p 
488                   (format "Message %s already sent.  Send anyway? "
489                           message-id)))
490           (push message-id gnus-inews-sent-ids)
491           ;; Chop off the last Message-IDs.
492           (when (setq end (nthcdr gnus-sent-message-ids-length 
493                                   gnus-inews-sent-ids))
494             (setcdr end nil))
495           (nnheader-temp-write gnus-sent-message-ids-file
496             (gnus-prin1 `(setq gnus-inews-sent-ids ',gnus-inews-sent-ids)))
497           nil)))))
498
499 \f
500
501 ;; Dummy to avoid byte-compile warning.
502 (defvar nnspool-rejected-article-hook)
503
504 ;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might
505 ;;; as well include the Emacs version as well.
506 ;;; The following function works with later GNU Emacs, and XEmacs.
507 (defun gnus-extended-version ()
508   "Stringified Gnus version and Emacs version"
509   (interactive)
510   (concat
511    gnus-version
512    "/"
513    (cond
514     ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
515      (concat "Emacs " (substring emacs-version
516                                  (match-beginning 1)
517                                  (match-end 1))))
518     ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)" emacs-version)
519      (concat (substring emacs-version
520                         (match-beginning 1)
521                         (match-end 1))
522              (format " %d.%d" emacs-major-version emacs-minor-version)))
523     (t emacs-version))))
524
525 ;; Written by "Mr. Per Persson" <pp@gnu.ai.mit.edu>.
526 (defun gnus-inews-insert-mime-headers ()
527   (goto-char (point-min))
528   (let ((mail-header-separator 
529          (progn 
530            (goto-char (point-min))
531            (if (and (search-forward (concat "\n" mail-header-separator "\n")
532                                     nil t)
533                     (not (search-backward "\n\n" nil t)))
534                mail-header-separator
535              ""))))
536     (or (mail-position-on-field "Mime-Version")
537         (insert "1.0")
538         (cond ((save-restriction
539                  (widen)
540                  (goto-char (point-min))
541                  (re-search-forward "[\200-\377]" nil t))
542                (or (mail-position-on-field "Content-Type")
543                    (insert "text/plain; charset=ISO-8859-1"))
544                (or (mail-position-on-field "Content-Transfer-Encoding")
545                    (insert "8bit")))
546               (t (or (mail-position-on-field "Content-Type")
547                      (insert "text/plain; charset=US-ASCII"))
548                  (or (mail-position-on-field "Content-Transfer-Encoding")
549                      (insert "7bit")))))))
550
551 \f
552 ;;;
553 ;;; Gnus Mail Functions 
554 ;;;
555
556 ;;; Mail reply commands of Gnus summary mode
557
558 (defun gnus-summary-reply (&optional yank)
559   "Reply mail to news author.
560 If prefix argument YANK is non-nil, original article is yanked automatically."
561   (interactive 
562    (list (and current-prefix-arg 
563               (gnus-summary-work-articles 1))))
564   ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
565   ;; Stripping headers should be specified with mail-yank-ignored-headers.
566   (gnus-set-global-variables)
567   (when yank 
568     (gnus-summary-goto-subject (car yank)))
569   (let ((gnus-article-reply t))
570     (gnus-setup-message (if yank 'reply-yank 'reply)
571       (gnus-summary-select-article)
572       (set-buffer (gnus-copy-article-buffer))
573       (message-reply nil nil (gnus-group-find-parameter
574                               gnus-newsgroup-name 'broken-reply-to))
575       (when yank
576         (gnus-inews-yank-articles yank)))))
577
578 (defun gnus-summary-reply-with-original (n)
579   "Reply mail to news author with original article."
580   (interactive "P")
581   (gnus-summary-reply (gnus-summary-work-articles n)))
582
583 (defun gnus-summary-mail-forward (&optional full-headers post)
584   "Forward the current message to another user.
585 If FULL-HEADERS (the prefix), include full headers when forwarding."
586   (interactive "P")
587   (gnus-set-global-variables)
588   (gnus-setup-message 'forward
589     (gnus-summary-select-article)
590     (set-buffer gnus-original-article-buffer)
591     (let ((message-included-forward-headers
592            (if full-headers "" message-included-forward-headers)))
593       (message-forward post))))
594
595 (defun gnus-summary-resend-message (address)
596   "Resend the current article to ADDRESS."
597   (interactive "sResend message to: ")
598   (gnus-summary-select-article)
599   (save-excursion
600     (set-buffer gnus-original-article-buffer)
601     (message-resend address)))
602
603 (defun gnus-summary-post-forward (&optional full-headers)
604   "Forward the current article to a newsgroup.
605 If FULL-HEADERS (the prefix), include full headers when forwarding."
606   (interactive "P")
607   (gnus-summary-mail-forward full-headers t))
608
609 (defvar gnus-nastygram-message 
610   "The following article was inappropriately posted to %s.\n\n"
611   "Format string to insert in nastygrams.
612 The current group name will be inserted at \"%s\".")
613
614 (defun gnus-summary-mail-nastygram (n)
615   "Send a nastygram to the author of the current article."
616   (interactive "P")
617   (when (or gnus-expert-user
618             (gnus-y-or-n-p 
619              "Really send a nastygram to the author of the current article? "))
620     (let ((group gnus-newsgroup-name))
621       (gnus-summary-reply-with-original n)
622       (set-buffer gnus-message-buffer)
623       (message-goto-body)
624       (insert (format gnus-nastygram-message group))
625       (message-send-and-exit))))
626
627 (defun gnus-summary-mail-crosspost-complaint (n)
628   "Send a complaint about crossposting to the current article(s)."
629   (interactive "P")
630   (let ((articles (gnus-summary-work-articles n))
631         article)
632     (while (setq article (pop articles))
633       (set-buffer gnus-summary-buffer)
634       (gnus-summary-goto-subject article)
635       (let ((group (gnus-group-real-name gnus-newsgroup-name))
636             newsgroups followup-to)
637         (gnus-summary-select-article)
638         (set-buffer gnus-original-article-buffer)
639         (if (and (<= (length (message-tokenize-header
640                               (setq newsgroups (mail-fetch-field "newsgroups"))
641                               ", "))
642                      1)
643                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
644                      (not (member group (message-tokenize-header
645                                          followup-to ", ")))))
646             (if followup-to
647                 (gnus-message 1 "Followup-to restricted")
648               (gnus-message 1 "Not a crossposted article"))
649           (set-buffer gnus-summary-buffer)
650           (gnus-summary-reply-with-original 1)
651           (set-buffer gnus-message-buffer)
652           (message-goto-body)
653           (insert (format gnus-crosspost-complaint newsgroups group))
654           (message-goto-subject)
655           (re-search-forward " *$")
656           (replace-match " (crosspost notification)" t t)
657           (when (gnus-y-or-n-p "Send this complaint? ")
658             (message-send-and-exit)))))))
659
660 (defun gnus-summary-mail-other-window ()
661   "Compose mail in other window."
662   (interactive)
663   (gnus-setup-message 'message
664     (message-mail)))
665
666 (defun gnus-mail-parse-comma-list ()
667   (let (accumulated
668         beg)
669     (skip-chars-forward " ")
670     (while (not (eobp))
671       (setq beg (point))
672       (skip-chars-forward "^,")
673       (while (zerop
674               (save-excursion 
675                 (save-restriction
676                   (let ((i 0))
677                     (narrow-to-region beg (point))
678                     (goto-char beg)
679                     (logand (progn
680                               (while (search-forward "\"" nil t)
681                                 (incf i))
682                               (if (zerop i) 2 i))
683                             2)))))
684         (skip-chars-forward ",")
685         (skip-chars-forward "^,"))
686       (skip-chars-backward " ")
687       (push (buffer-substring beg (point))
688             accumulated)
689       (skip-chars-forward "^,")
690       (skip-chars-forward ", "))
691     accumulated))
692
693 (defun gnus-inews-add-to-address (group)
694   (let ((to-address (mail-fetch-field "to")))
695     (when (and to-address
696                (gnus-alive-p))
697       ;; This mail group doesn't have a `to-list', so we add one
698       ;; here.  Magic!  
699       (gnus-group-add-parameter group (cons 'to-list to-address)))))
700
701 (defun gnus-put-message ()
702   "Put the current message in some group and return to Gnus."
703   (interactive)
704   (let ((reply gnus-article-reply)
705         (winconf gnus-prev-winconf)
706         (group gnus-newsgroup-name))
707     
708     (or (and group (not (gnus-group-read-only-p group)))
709         (setq group (read-string "Put in group: " nil
710                                  (gnus-writable-groups))))
711     (when (gnus-gethash group gnus-newsrc-hashtb)
712       (error "No such group: %s" group))
713
714     (save-excursion
715       (save-restriction
716         (widen)
717         (gnus-inews-narrow-to-headers)
718         (let (gnus-deletable-headers)
719           (if (message-news-p)
720               (message-generate-headers message-required-news-headers)
721             (message-generate-headers message-required-mail-headers)))
722         (goto-char (point-max))
723         (insert "Gcc: " group "\n")
724         (widen)))
725
726     (gnus-inews-do-gcc)
727
728     (when (get-buffer gnus-group-buffer)
729       (when (gnus-buffer-exists-p (car-safe reply))
730         (set-buffer (car reply))
731         (and (cdr reply)
732              (gnus-summary-mark-article-as-replied 
733               (cdr reply))))
734       (when winconf
735         (set-window-configuration winconf)))))
736
737 (defun gnus-article-mail (yank)
738   "Send a reply to the address near point.
739 If YANK is non-nil, include the original article."
740   (interactive "P")
741   (let ((address 
742          (buffer-substring
743           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
744           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
745     (when address
746       (message-reply address)
747       (when yank
748         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
749
750 (defvar nntp-server-type)
751 (defun gnus-bug ()
752   "Send a bug report to the Gnus maintainers."
753   (interactive)
754   (unless (gnus-alive-p)
755     (error "Gnus has been shut down"))
756   (gnus-setup-message 'bug
757     (delete-other-windows)
758     (switch-to-buffer "*Gnus Help Bug*")
759     (erase-buffer)
760     (insert gnus-bug-message)
761     (goto-char (point-min))
762     (message-pop-to-buffer "*Gnus Bug*")
763     (message-setup `((To . ,gnus-maintainer) (Subject . "")))
764     (push `(gnus-bug-kill-buffer) message-send-actions)
765     (goto-char (point-min))
766     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
767     (forward-line 1)
768     (insert (gnus-version) "\n")
769     (insert (emacs-version) "\n")
770     (when (and (boundp 'nntp-server-type)
771                (stringp nntp-server-type))
772       (insert nntp-server-type))
773     (insert "\n\n\n\n\n")
774     (gnus-debug)
775     (goto-char (point-min))
776     (search-forward "Subject: " nil t)
777     (message "")))
778
779 (defun gnus-bug-kill-buffer ()
780   (when (get-buffer "*Gnus Help Bug*")
781     (kill-buffer "*Gnus Help Bug*")))
782
783 (defun gnus-debug ()
784   "Attempts to go through the Gnus source file and report what variables have been changed.
785 The source file has to be in the Emacs load path."
786   (interactive)
787   (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
788                  "gnus-art.el" "gnus-start.el" "gnus-async.el"
789                  "gnus-msg.el" "gnus-score.el" "gnus-win.el"
790                  "nnmail.el" "message.el"))
791         file expr olist sym)
792     (gnus-message 4 "Please wait while we snoop your variables...")
793     (sit-for 0)
794     ;; Go through all the files looking for non-default values for variables.
795     (save-excursion
796       (set-buffer (get-buffer-create " *gnus bug info*"))
797       (buffer-disable-undo (current-buffer))
798       (while files
799         (erase-buffer)
800         (when (and (setq file (locate-library (pop files)))
801                    (file-exists-p file))
802           (insert-file-contents file)
803           (goto-char (point-min))
804           (if (not (re-search-forward "^;;* *Internal variables" nil t))
805               (gnus-message 4 "Malformed sources in file %s" file)
806             (narrow-to-region (point-min) (point))
807             (goto-char (point-min))
808             (while (setq expr (ignore-errors (read (current-buffer))))
809               (ignore-errors
810                 (and (or (eq (car expr) 'defvar)
811                          (eq (car expr) 'defcustom))
812                      (stringp (nth 3 expr))
813                      (or (not (boundp (nth 1 expr)))
814                          (not (equal (eval (nth 2 expr))
815                                      (symbol-value (nth 1 expr)))))
816                      (push (nth 1 expr) olist)))))))
817       (kill-buffer (current-buffer)))
818     (when (setq olist (nreverse olist))
819       (insert "------------------ Environment follows ------------------\n\n"))
820     (while olist
821       (if (boundp (car olist))
822           (condition-case ()
823               (pp `(setq ,(car olist)
824                          ,(if (or (consp (setq sym (symbol-value (car olist))))
825                                   (and (symbolp sym)
826                                        (not (or (eq sym nil)
827                                                 (eq sym t)))))
828                               (list 'quote (symbol-value (car olist)))
829                             (symbol-value (car olist))))
830                   (current-buffer))
831             (error
832              (format "(setq %s 'whatever)\n" (car olist))))
833         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
834       (setq olist (cdr olist)))
835     (insert "\n\n")
836     ;; Remove any null chars - they seem to cause trouble for some
837     ;; mailers.  (Byte-compiled output from the stuff above.)
838     (goto-char (point-min))
839     (while (re-search-forward "[\000\200]" nil t)
840       (replace-match "" t t))))
841
842 ;;; Treatment of rejected articles.
843 ;;; Bounced mail.
844
845 (defun gnus-summary-resend-bounced-mail (&optional fetch)
846   "Re-mail the current message.
847 This only makes sense if the current message is a bounce message than
848 contains some mail you have written which has been bounced back to
849 you.
850 If FETCH, try to fetch the article that this is a reply to, if indeed
851 this is a reply."
852   (interactive "P")
853   (gnus-summary-select-article t)
854   (set-buffer gnus-original-article-buffer)
855   (gnus-setup-message 'compose-bounce
856     (let* ((references (mail-fetch-field "references"))
857            (parent (and references (gnus-parent-id references))))
858       (message-bounce)
859       ;; If there are references, we fetch the article we answered to.  
860       (and fetch parent
861            (gnus-summary-refer-article parent)
862            (gnus-summary-show-all-headers)))))
863
864 ;;; Gcc handling.
865
866 ;; Do Gcc handling, which copied the message over to some group. 
867 (defun gnus-inews-do-gcc (&optional gcc)
868   (when (gnus-alive-p)
869     (save-excursion
870       (save-restriction
871         (message-narrow-to-headers)
872         (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
873               (cur (current-buffer))
874               groups group method)
875           (when gcc
876             (message-remove-header "gcc")
877             (widen)
878             (setq groups (message-tokenize-header gcc " ,"))
879             ;; Copy the article over to some group(s).
880             (while (setq group (pop groups))
881               (gnus-check-server 
882                (setq method
883                      (cond ((and (null (gnus-get-info group))
884                                  (eq (car gnus-message-archive-method)
885                                      (car 
886                                       (gnus-server-to-method
887                                        (gnus-group-method group)))))
888                             ;; If the group doesn't exist, we assume
889                             ;; it's an archive group...
890                             gnus-message-archive-method)
891                            ;; Use the method.
892                            ((gnus-info-method (gnus-get-info group))
893                             (gnus-info-method (gnus-get-info group)))
894                            ;; Find the method.
895                            (t (gnus-group-method group)))))
896               (gnus-check-server method)
897               (unless (gnus-request-group group t method)
898                 (gnus-request-create-group group method))
899               (save-excursion
900                 (nnheader-set-temp-buffer " *acc*")
901                 (insert-buffer-substring cur)
902                 (goto-char (point-min))
903                 (when (re-search-forward 
904                        (concat "^" (regexp-quote mail-header-separator) "$")
905                        nil t)
906                   (replace-match "" t t ))
907                 (unless (gnus-request-accept-article group method t)
908                   (gnus-message 1 "Couldn't store article in group %s: %s" 
909                                 group (gnus-status-message method))
910                   (sit-for 2))
911                 (kill-buffer (current-buffer))))))))))
912
913 (defun gnus-inews-insert-gcc ()
914   "Insert Gcc headers based on `gnus-outgoing-message-group'."
915   (save-excursion
916     (save-restriction
917       (gnus-inews-narrow-to-headers)
918       (let* ((group gnus-outgoing-message-group)
919              (gcc (cond 
920                    ((gnus-functionp group)
921                     (funcall group))
922                    ((or (stringp group) (list group))
923                     group))))
924         (when gcc
925           (insert "Gcc: "
926                   (if (stringp gcc) gcc
927                     (mapconcat 'identity gcc " "))
928                   "\n"))))))
929
930 (defun gnus-inews-insert-archive-gcc (&optional group)
931   "Insert the Gcc to say where the article is to be archived."
932   (let* ((var gnus-message-archive-group)
933          (group (or group gnus-newsgroup-name ""))
934          result
935          gcc-self-val
936          (groups
937           (cond 
938            ((null gnus-message-archive-method)
939             ;; Ignore.
940             nil)
941            ((stringp var)
942             ;; Just a single group.
943             (list var))
944            ((null var)
945             ;; We don't want this.
946             nil)
947            ((and (listp var) (stringp (car var)))
948             ;; A list of groups.
949             var)
950            ((gnus-functionp var)
951             ;; A function.
952             (funcall var group))
953            (t
954             ;; An alist of regexps/functions/forms.
955             (while (and var
956                         (not
957                          (setq result
958                                (cond 
959                                 ((stringp (caar var))
960                                  ;; Regexp.
961                                  (when (string-match (caar var) group)
962                                    (cdar var)))
963                                 ((gnus-functionp (car var))
964                                  ;; Function.
965                                  (funcall (car var) group))
966                                 (t
967                                  (eval (car var)))))))
968               (setq var (cdr var)))
969             result)))
970          name)
971     (when groups
972       (when (stringp groups)
973         (setq groups (list groups)))
974       (save-excursion
975         (save-restriction
976           (gnus-inews-narrow-to-headers)
977           (goto-char (point-max))
978           (insert "Gcc: ")
979           (if (and gnus-newsgroup-name
980                    (setq gcc-self-val
981                          (gnus-group-find-parameter
982                           gnus-newsgroup-name 'gcc-self)))
983               (progn 
984                 (insert
985                  (if (stringp gcc-self-val)
986                      gcc-self-val
987                    group))
988                 (if (not (eq gcc-self-val 'none))
989                     (insert "\n")
990                   (progn
991                     (beginning-of-line)
992                     (kill-line))))
993             (while (setq name (pop groups))
994               (insert (if (string-match ":" name)
995                           name
996                         (gnus-group-prefixed-name 
997                          name gnus-message-archive-method)))
998               (when groups
999                 (insert " ")))
1000             (insert "\n")))))))
1001
1002 (defun gnus-summary-send-draft ()
1003   "Enter a mail/post buffer to edit and send the draft."
1004   (interactive)
1005   (gnus-set-global-variables)
1006   (let (buf)
1007     (if (not (setq buf (gnus-request-restore-buffer 
1008                         (gnus-summary-article-number) gnus-newsgroup-name)))
1009         (error "Couldn't restore the article")
1010       (switch-to-buffer buf)
1011       (when (eq major-mode 'news-reply-mode)
1012         (local-set-key "\C-c\C-c" 'gnus-inews-news))
1013       ;; Insert the separator.
1014       (goto-char (point-min))
1015       (search-forward "\n\n")
1016       (forward-char -1)
1017       (insert mail-header-separator)
1018       ;; Configure windows.
1019       (let ((gnus-draft-buffer (current-buffer)))
1020         (gnus-configure-windows 'draft t)
1021         (goto-char (point))))))
1022   
1023 (gnus-add-shutdown 'gnus-inews-close 'gnus)
1024
1025 (defun gnus-inews-close ()
1026   (setq gnus-inews-sent-ids nil))
1027   
1028 ;;; Allow redefinition of functions.
1029
1030 (gnus-ems-redefine)
1031
1032 (provide 'gnus-msg)
1033
1034 ;;; gnus-msg.el ends here