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