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