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