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