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