*** 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@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 (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 ;;; 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 "gnus-setup-message-winconf"))
166         (buffer (make-symbol "gnus-setup-message-buffer"))
167         (article (make-symbol "gnus-setup-message-article"))
168         (group (make-symbol "gnus-setup-message-group")))
169     `(let ((,winconf (current-window-configuration))
170            (,buffer (buffer-name (current-buffer)))
171            (,article (and gnus-article-reply (gnus-summary-article-number)))
172            (,group gnus-newsgroup-name)
173            (message-header-setup-hook
174             (copy-sequence message-header-setup-hook)))
175        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
176        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
177        (unwind-protect
178            (progn
179              ,@forms)
180          (gnus-inews-add-send-actions ,winconf ,buffer ,article)
181          (setq gnus-message-buffer (current-buffer))
182          (set (make-local-variable 'gnus-message-group-art)
183               (cons ,group ,article))
184          (make-local-variable 'gnus-newsgroup-name)
185          (gnus-run-hooks 'gnus-message-setup-hook))
186        (gnus-configure-windows ,config t)
187        (set-buffer-modified-p nil))))
188
189 (defun gnus-inews-add-send-actions (winconf buffer article)
190   (make-local-hook 'message-sent-hook)
191   (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
192   (setq message-post-method
193         `(lambda (arg)
194            (gnus-post-method arg ,gnus-newsgroup-name)))
195   (setq message-newsreader (setq message-mailer (gnus-extended-version)))
196   (message-add-action
197    `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
198   (message-add-action
199    `(when (gnus-buffer-exists-p ,buffer)
200       (save-excursion
201         (set-buffer ,buffer)
202         ,(when article
203            `(gnus-summary-mark-article-as-replied ,article))))
204    'send))
205
206 (put 'gnus-setup-message 'lisp-indent-function 1)
207 (put 'gnus-setup-message 'edebug-form-spec '(form body))
208
209 ;;; Post news commands of Gnus group mode and summary mode
210
211 (defun gnus-group-mail ()
212   "Start composing a mail."
213   (interactive)
214   (gnus-setup-message 'message
215     (message-mail)))
216
217 (defun gnus-group-post-news (&optional arg)
218   "Start composing a news message.
219 If ARG, post to the group under point.
220 If ARG is 1, prompt for a group name."
221   (interactive "P")
222   ;; Bind this variable here to make message mode hooks work ok.
223   (let ((gnus-newsgroup-name
224          (if arg
225              (if (= 1 (prefix-numeric-value arg))
226                  (completing-read "Newsgroup: " gnus-active-hashtb nil
227                                   (gnus-read-active-file-p))
228                (gnus-group-group-name))
229            "")))
230     (gnus-post-news 'post gnus-newsgroup-name)))
231
232 (defun gnus-summary-post-news ()
233   "Start composing a news message."
234   (interactive)
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   (when yank
244     (gnus-summary-goto-subject (car yank)))
245   (save-window-excursion
246     (gnus-summary-select-article))
247   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
248         (gnus-newsgroup-name gnus-newsgroup-name))
249     ;; Send a followup.
250     (gnus-post-news nil gnus-newsgroup-name
251                     headers gnus-article-buffer
252                     yank nil force-news)))
253
254 (defun gnus-summary-followup-with-original (n &optional force-news)
255   "Compose a followup to an article and include the original article."
256   (interactive "P")
257   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
258
259 (defun gnus-summary-followup-to-mail (&optional arg)
260   "Followup to the current mail message via news."
261   (interactive
262    (list (and current-prefix-arg
263               (gnus-summary-work-articles 1))))
264   (gnus-summary-followup arg t))
265
266 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
267   "Followup to the current mail message via news."
268   (interactive "P")
269   (gnus-summary-followup (gnus-summary-work-articles arg) t))
270
271 (defun gnus-inews-yank-articles (articles)
272   (let (beg article)
273     (message-goto-body)
274     (while (setq article (pop articles))
275       (save-window-excursion
276         (set-buffer gnus-summary-buffer)
277         (gnus-summary-select-article nil nil nil article)
278         (gnus-summary-remove-process-mark article))
279       (gnus-copy-article-buffer)
280       (let ((message-reply-buffer gnus-article-copy)
281             (message-reply-headers gnus-current-headers))
282         (message-yank-original)
283         (setq beg (or beg (mark t))))
284       (when articles
285         (insert "\n")))
286     (push-mark)
287     (goto-char beg)))
288
289 (defun gnus-summary-cancel-article (&optional n symp)
290   "Cancel an article you posted.
291 Uses the process-prefix convention.  If given the symbolic
292 prefix `a', cancel using the standard posting method; if not
293 post using the current select method."
294   (interactive (gnus-interactive "P\ny"))
295   (let ((articles (gnus-summary-work-articles n))
296         (message-post-method
297          `(lambda (arg)
298             (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
299         article)
300     (while (setq article (pop articles))
301       (when (gnus-summary-select-article t nil nil article)
302         (when (gnus-eval-in-buffer-window gnus-original-article-buffer
303                 (message-cancel-news))
304           (gnus-summary-mark-as-read article gnus-canceled-mark)
305           (gnus-cache-remove-article 1))
306         (gnus-article-hide-headers-if-wanted))
307       (gnus-summary-remove-process-mark article))))
308
309 (defun gnus-summary-supersede-article ()
310   "Compose an article that will supersede a previous article.
311 This is done simply by taking the old article and adding a Supersedes
312 header line with the old Message-ID."
313   (interactive)
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 (gnus-buffer-exists-p ,gnus-summary-buffer)
322              (save-excursion
323                (set-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                   (gnus-buffer-exists-p 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 (and (null (eq gnus-post-method 'active)) gnus-post-method)
439                gnus-select-method message-post-method))
440      ;; We want the inverse of the default
441      ((and arg (not (eq arg 0)))
442       (if (eq gnus-post-method 'active)
443           gnus-select-method
444         group-method))
445      ;; We query the user for a post method.
446      ((or arg
447           (and gnus-post-method
448                (not (eq gnus-post-method 'current))
449                (listp (car gnus-post-method))))
450       (let* ((methods
451               ;; Collect all methods we know about.
452               (append
453                (when (and gnus-post-method
454                           (not (eq gnus-post-method 'current)))
455                  (if (listp (car gnus-post-method))
456                      gnus-post-method
457                    (list gnus-post-method)))
458                gnus-secondary-select-methods
459                (list gnus-select-method)
460                (list group-method)))
461              method-alist post-methods method)
462         ;; Weed out all mail methods.
463         (while methods
464           (setq method (gnus-server-get-method "" (pop methods)))
465           (when (or (gnus-method-option-p method 'post)
466                     (gnus-method-option-p method 'post-mail))
467             (push method post-methods)))
468         ;; Create a name-method alist.
469         (setq method-alist
470               (mapcar
471                (lambda (m)
472                  (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
473                post-methods))
474         ;; Query the user.
475         (cadr
476          (assoc
477           (setq gnus-last-posting-server
478                 (if (and silent
479                          gnus-last-posting-server)
480                     ;; Just use the last value.
481                     gnus-last-posting-server
482                   (completing-read
483                    "Posting method: " method-alist nil t
484                    (cons (or gnus-last-posting-server "") 0))))
485           method-alist))))
486      ;; Override normal method.
487      ((and (eq gnus-post-method 'current)
488            (not arg))
489       group-method) 
490      (gnus-post-method
491       gnus-post-method)
492      ;; Use the normal select method.
493      (t gnus-select-method))))
494
495 \f
496
497 ;; Dummy to avoid byte-compile warning.
498 (defvar nnspool-rejected-article-hook)
499 (defvar xemacs-codename)
500
501 ;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might
502 ;;; as well include the Emacs version as well.
503 ;;; The following function works with later GNU Emacs, and XEmacs.
504 (defun gnus-extended-version ()
505   "Stringified Gnus version and Emacs version"
506   (interactive)
507   (concat
508    gnus-version
509    "/"
510    (cond
511     ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
512      (concat "Emacs " (substring emacs-version
513                                  (match-beginning 1)
514                                  (match-end 1))))
515     ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
516                    emacs-version)
517      (concat (substring emacs-version
518                         (match-beginning 1)
519                         (match-end 1))
520              (format " %d.%d" emacs-major-version emacs-minor-version)
521              (if (match-beginning 3)
522                  (substring emacs-version
523                             (match-beginning 3)
524                             (match-end 3))
525                "")
526              (if (boundp 'xemacs-codename)
527                  (concat " - \"" xemacs-codename "\""))))
528     (t emacs-version))))
529
530 ;; Written by "Mr. Per Persson" <pp@gnu.ai.mit.edu>.
531 (defun gnus-inews-insert-mime-headers ()
532   "Insert MIME headers.  
533 Assumes ISO-Latin-1 is used iff 8-bit characters are present."
534   (goto-char (point-min))
535   (let ((mail-header-separator
536          (progn
537            (goto-char (point-min))
538            (if (and (search-forward (concat "\n" mail-header-separator "\n")
539                                     nil t)
540                     (not (search-backward "\n\n" nil t)))
541                mail-header-separator
542              ""))))
543     (or (mail-position-on-field "Mime-Version")
544         (insert "1.0")
545         (cond ((save-restriction
546                  (widen)
547                  (goto-char (point-min))
548                  (re-search-forward "[^\000-\177]" nil t))
549                (or (mail-position-on-field "Content-Type")
550                    (insert "text/plain; charset=ISO-8859-1"))
551                (or (mail-position-on-field "Content-Transfer-Encoding")
552                    (insert "8bit")))
553               (t (or (mail-position-on-field "Content-Type")
554                      (insert "text/plain; charset=US-ASCII"))
555                  (or (mail-position-on-field "Content-Transfer-Encoding")
556                      (insert "7bit")))))))
557
558 (custom-add-option 'message-header-hook 'gnus-inews-insert-mime-headers)
559
560 \f
561 ;;;
562 ;;; Gnus Mail Functions
563 ;;;
564
565 ;;; Mail reply commands of Gnus summary mode
566
567 (defun gnus-summary-reply (&optional yank wide)
568   "Start composing a reply mail to the current message.
569 If prefix argument YANK is non-nil, the original article is yanked
570 automatically."
571   (interactive
572    (list (and current-prefix-arg
573               (gnus-summary-work-articles 1))))
574   ;; Stripping headers should be specified with mail-yank-ignored-headers.
575   (when yank
576     (gnus-summary-goto-subject (car yank)))
577   (let ((gnus-article-reply t))
578     (gnus-setup-message (if yank 'reply-yank 'reply)
579       (gnus-summary-select-article)
580       (set-buffer (gnus-copy-article-buffer))
581       (message-reply nil wide (gnus-group-find-parameter
582                                gnus-newsgroup-name 'broken-reply-to))
583       (when yank
584         (gnus-inews-yank-articles yank)))))
585
586 (defun gnus-summary-reply-with-original (n &optional wide)
587   "Start composing a reply mail to the current message.
588 The original article will be yanked."
589   (interactive "P")
590   (gnus-summary-reply (gnus-summary-work-articles n) wide))
591
592 (defun gnus-summary-wide-reply (&optional yank)
593   "Start composing a wide reply mail to the current message.
594 If prefix argument YANK is non-nil, the original article is yanked
595 automatically."
596   (interactive
597    (list (and current-prefix-arg
598               (gnus-summary-work-articles 1))))
599   (gnus-summary-reply yank t))
600
601 (defun gnus-summary-wide-reply-with-original (n)
602   "Start composing a wide reply mail to the current message.
603 The original article will be yanked."
604   (interactive "P")
605   (gnus-summary-reply-with-original n t))
606
607 (defun gnus-summary-mail-forward (&optional full-headers post)
608   "Forward the current message to another user.
609 If FULL-HEADERS (the prefix), include full headers when forwarding."
610   (interactive "P")
611   (gnus-setup-message 'forward
612     (gnus-summary-select-article)
613     (set-buffer gnus-original-article-buffer)
614     (let ((message-included-forward-headers
615            (if full-headers "" message-included-forward-headers)))
616       (message-forward post))))
617
618 (defun gnus-summary-resend-message (address n)
619   "Resend the current article to ADDRESS."
620   (interactive "sResend message(s) to: \nP")
621   (let ((articles (gnus-summary-work-articles n))
622         article)
623     (while (setq article (pop articles))
624       (gnus-summary-select-article nil nil nil article)
625       (save-excursion
626         (set-buffer gnus-original-article-buffer)
627         (message-resend address)))))
628
629 (defun gnus-summary-post-forward (&optional full-headers)
630   "Forward the current article to a newsgroup.
631 If FULL-HEADERS (the prefix), include full headers when forwarding."
632   (interactive "P")
633   (gnus-summary-mail-forward full-headers t))
634
635 (defvar gnus-nastygram-message
636   "The following article was inappropriately posted to %s.\n\n"
637   "Format string to insert in nastygrams.
638 The current group name will be inserted at \"%s\".")
639
640 (defun gnus-summary-mail-nastygram (n)
641   "Send a nastygram to the author of the current article."
642   (interactive "P")
643   (when (or gnus-expert-user
644             (gnus-y-or-n-p
645              "Really send a nastygram to the author of the current article? "))
646     (let ((group gnus-newsgroup-name))
647       (gnus-summary-reply-with-original n)
648       (set-buffer gnus-message-buffer)
649       (message-goto-body)
650       (insert (format gnus-nastygram-message group))
651       (message-send-and-exit))))
652
653 (defun gnus-summary-mail-crosspost-complaint (n)
654   "Send a complaint about crossposting to the current article(s)."
655   (interactive "P")
656   (let ((articles (gnus-summary-work-articles n))
657         article)
658     (while (setq article (pop articles))
659       (set-buffer gnus-summary-buffer)
660       (gnus-summary-goto-subject article)
661       (let ((group (gnus-group-real-name gnus-newsgroup-name))
662             newsgroups followup-to)
663         (gnus-summary-select-article)
664         (set-buffer gnus-original-article-buffer)
665         (if (and (<= (length (message-tokenize-header
666                               (setq newsgroups (mail-fetch-field "newsgroups"))
667                               ", "))
668                      1)
669                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
670                      (not (member group (message-tokenize-header
671                                          followup-to ", ")))))
672             (if followup-to
673                 (gnus-message 1 "Followup-to restricted")
674               (gnus-message 1 "Not a crossposted article"))
675           (set-buffer gnus-summary-buffer)
676           (gnus-summary-reply-with-original 1)
677           (set-buffer gnus-message-buffer)
678           (message-goto-body)
679           (insert (format gnus-crosspost-complaint newsgroups group))
680           (message-goto-subject)
681           (re-search-forward " *$")
682           (replace-match " (crosspost notification)" t t)
683           (gnus-deactivate-mark)
684           (when (gnus-y-or-n-p "Send this complaint? ")
685             (message-send-and-exit)))))))
686
687 (defun gnus-summary-mail-other-window ()
688   "Compose mail in other window."
689   (interactive)
690   (gnus-setup-message 'message
691     (message-mail)))
692
693 (defun gnus-mail-parse-comma-list ()
694   (let (accumulated
695         beg)
696     (skip-chars-forward " ")
697     (while (not (eobp))
698       (setq beg (point))
699       (skip-chars-forward "^,")
700       (while (zerop
701               (save-excursion
702                 (save-restriction
703                   (let ((i 0))
704                     (narrow-to-region beg (point))
705                     (goto-char beg)
706                     (logand (progn
707                               (while (search-forward "\"" nil t)
708                                 (incf i))
709                               (if (zerop i) 2 i))
710                             2)))))
711         (skip-chars-forward ",")
712         (skip-chars-forward "^,"))
713       (skip-chars-backward " ")
714       (push (buffer-substring beg (point))
715             accumulated)
716       (skip-chars-forward "^,")
717       (skip-chars-forward ", "))
718     accumulated))
719
720 (defun gnus-inews-add-to-address (group)
721   (let ((to-address (mail-fetch-field "to")))
722     (when (and to-address
723                (gnus-alive-p))
724       ;; This mail group doesn't have a `to-list', so we add one
725       ;; here.  Magic!
726       (when (gnus-y-or-n-p
727              (format "Do you want to add this as `to-list': %s " to-address))
728         (gnus-group-add-parameter group (cons 'to-list to-address))))))
729
730 (defun gnus-put-message ()
731   "Put the current message in some group and return to Gnus."
732   (interactive)
733   (let ((reply gnus-article-reply)
734         (winconf gnus-prev-winconf)
735         (group gnus-newsgroup-name))
736
737     (or (and group (not (gnus-group-read-only-p group)))
738         (setq group (read-string "Put in group: " nil
739                                  (gnus-writable-groups))))
740     (when (gnus-gethash group gnus-newsrc-hashtb)
741       (error "No such group: %s" group))
742
743     (save-excursion
744       (save-restriction
745         (widen)
746         (message-narrow-to-headers)
747         (let (gnus-deletable-headers)
748           (if (message-news-p)
749               (message-generate-headers message-required-news-headers)
750             (message-generate-headers message-required-mail-headers)))
751         (goto-char (point-max))
752         (insert "Gcc: " group "\n")
753         (widen)))
754
755     (gnus-inews-do-gcc)
756
757     (when (get-buffer gnus-group-buffer)
758       (when (gnus-buffer-exists-p (car-safe reply))
759         (set-buffer (car reply))
760         (and (cdr reply)
761              (gnus-summary-mark-article-as-replied
762               (cdr reply))))
763       (when winconf
764         (set-window-configuration winconf)))))
765
766 (defun gnus-article-mail (yank)
767   "Send a reply to the address near point.
768 If YANK is non-nil, include the original article."
769   (interactive "P")
770   (let ((address
771          (buffer-substring
772           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
773           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
774     (when address
775       (message-reply address)
776       (when yank
777         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
778
779 (defvar nntp-server-type)
780 (defun gnus-bug ()
781   "Send a bug report to the Gnus maintainers."
782   (interactive)
783   (unless (gnus-alive-p)
784     (error "Gnus has been shut down"))
785   (gnus-setup-message 'bug
786     (delete-other-windows)
787     (switch-to-buffer (get-buffer-create "*Gnus Help Bug*"))
788     (erase-buffer)
789     (insert gnus-bug-message)
790     (goto-char (point-min))
791     (message-pop-to-buffer "*Gnus Bug*")
792     (message-setup `((To . ,gnus-maintainer) (Subject . "")))
793     (push `(gnus-bug-kill-buffer) message-send-actions)
794     (goto-char (point-min))
795     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
796     (forward-line 1)
797     (insert (gnus-version) "\n")
798     (insert (emacs-version) "\n")
799     (when (and (boundp 'nntp-server-type)
800                (stringp nntp-server-type))
801       (insert nntp-server-type))
802     (insert "\n\n\n\n\n")
803     (gnus-debug)
804     (goto-char (point-min))
805     (search-forward "Subject: " nil t)
806     (message "")))
807
808 (defun gnus-bug-kill-buffer ()
809   (when (get-buffer "*Gnus Help Bug*")
810     (kill-buffer "*Gnus Help Bug*")))
811
812 (defun gnus-debug ()
813   "Attempts to go through the Gnus source file and report what variables have been changed.
814 The source file has to be in the Emacs load path."
815   (interactive)
816   (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
817                  "gnus-art.el" "gnus-start.el" "gnus-async.el"
818                  "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
819                  "nnmail.el" "message.el"))
820         (point (point))
821         file expr olist sym)
822     (gnus-message 4 "Please wait while we snoop your variables...")
823     (sit-for 0)
824     ;; Go through all the files looking for non-default values for variables.
825     (save-excursion
826       (set-buffer (get-buffer-create " *gnus bug info*"))
827       (buffer-disable-undo (current-buffer))
828       (while files
829         (erase-buffer)
830         (when (and (setq file (locate-library (pop files)))
831                    (file-exists-p file))
832           (insert-file-contents file)
833           (goto-char (point-min))
834           (if (not (re-search-forward "^;;* *Internal variables" nil t))
835               (gnus-message 4 "Malformed sources in file %s" file)
836             (narrow-to-region (point-min) (point))
837             (goto-char (point-min))
838             (while (setq expr (ignore-errors (read (current-buffer))))
839               (ignore-errors
840                 (and (or (eq (car expr) 'defvar)
841                          (eq (car expr) 'defcustom))
842                      (stringp (nth 3 expr))
843                      (or (not (boundp (nth 1 expr)))
844                          (not (equal (eval (nth 2 expr))
845                                      (symbol-value (nth 1 expr)))))
846                      (push (nth 1 expr) olist)))))))
847       (kill-buffer (current-buffer)))
848     (when (setq olist (nreverse olist))
849       (insert "------------------ Environment follows ------------------\n\n"))
850     (while olist
851       (if (boundp (car olist))
852           (condition-case ()
853               (pp `(setq ,(car olist)
854                          ,(if (or (consp (setq sym (symbol-value (car olist))))
855                                   (and (symbolp sym)
856                                        (not (or (eq sym nil)
857                                                 (eq sym t)))))
858                               (list 'quote (symbol-value (car olist)))
859                             (symbol-value (car olist))))
860                   (current-buffer))
861             (error
862              (format "(setq %s 'whatever)\n" (car olist))))
863         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
864       (setq olist (cdr olist)))
865     (insert "\n\n")
866     ;; Remove any control chars - they seem to cause trouble for some
867     ;; mailers.  (Byte-compiled output from the stuff above.)
868     (goto-char point)
869     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
870       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
871                      t t))))
872
873 ;;; Treatment of rejected articles.
874 ;;; Bounced mail.
875
876 (defun gnus-summary-resend-bounced-mail (&optional fetch)
877   "Re-mail the current message.
878 This only makes sense if the current message is a bounce message than
879 contains some mail you have written which has been bounced back to
880 you.
881 If FETCH, try to fetch the article that this is a reply to, if indeed
882 this is a reply."
883   (interactive "P")
884   (gnus-summary-select-article t)
885   (set-buffer gnus-original-article-buffer)
886   (gnus-setup-message 'compose-bounce
887     (let* ((references (mail-fetch-field "references"))
888            (parent (and references (gnus-parent-id references))))
889       (message-bounce)
890       ;; If there are references, we fetch the article we answered to.
891       (and fetch parent
892            (gnus-summary-refer-article parent)
893            (gnus-summary-show-all-headers)))))
894
895 ;;; Gcc handling.
896
897 ;; Do Gcc handling, which copied the message over to some group.
898 (defun gnus-inews-do-gcc (&optional gcc)
899   (interactive)
900   (when (gnus-alive-p)
901     (save-excursion
902       (save-restriction
903         (message-narrow-to-headers)
904         (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
905               (cur (current-buffer))
906               groups group method)
907           (when gcc
908             (message-remove-header "gcc")
909             (widen)
910             (setq groups (message-tokenize-header gcc " ,"))
911             ;; Copy the article over to some group(s).
912             (while (setq group (pop groups))
913               (gnus-check-server
914                (setq method
915                      (cond ((and (null (gnus-get-info group))
916                                  (eq (car gnus-message-archive-method)
917                                      (car
918                                       (gnus-server-to-method
919                                        (gnus-group-method group)))))
920                             ;; If the group doesn't exist, we assume
921                             ;; it's an archive group...
922                             gnus-message-archive-method)
923                            ;; Use the method.
924                            ((gnus-info-method (gnus-get-info group))
925                             (gnus-info-method (gnus-get-info group)))
926                            ;; Find the method.
927                            (t (gnus-group-method group)))))
928               (gnus-check-server method)
929               (unless (gnus-request-group group t method)
930                 (gnus-request-create-group group method))
931               (save-excursion
932                 (nnheader-set-temp-buffer " *acc*")
933                 (insert-buffer-substring cur)
934                 (goto-char (point-min))
935                 (when (re-search-forward
936                        (concat "^" (regexp-quote mail-header-separator) "$")
937                        nil t)
938                   (replace-match "" t t ))
939                 (unless (gnus-request-accept-article group method t)
940                   (gnus-message 1 "Couldn't store article in group %s: %s"
941                                 group (gnus-status-message method))
942                   (sit-for 2))
943                 (kill-buffer (current-buffer))))))))))
944
945 (defun gnus-inews-insert-gcc ()
946   "Insert Gcc headers based on `gnus-outgoing-message-group'."
947   (save-excursion
948     (save-restriction
949       (message-narrow-to-headers)
950       (let* ((group gnus-outgoing-message-group)
951              (gcc (cond
952                    ((gnus-functionp group)
953                     (funcall group))
954                    ((or (stringp group) (list group))
955                     group))))
956         (when gcc
957           (insert "Gcc: "
958                   (if (stringp gcc) gcc
959                     (mapconcat 'identity gcc " "))
960                   "\n"))))))
961
962 (defun gnus-inews-insert-archive-gcc (&optional group)
963   "Insert the Gcc to say where the article is to be archived."
964   (let* ((var gnus-message-archive-group)
965          (group (or group gnus-newsgroup-name ""))
966          (gcc-self-val
967           (and gnus-newsgroup-name
968                (gnus-group-find-parameter
969                 gnus-newsgroup-name 'gcc-self)))
970          result 
971          (groups
972           (cond
973            ((null gnus-message-archive-method)
974             ;; Ignore.
975             nil)
976            ((stringp var)
977             ;; Just a single group.
978             (list var))
979            ((null var)
980             ;; We don't want this.
981             nil)
982            ((and (listp var) (stringp (car var)))
983             ;; A list of groups.
984             var)
985            ((gnus-functionp var)
986             ;; A function.
987             (funcall var group))
988            (t
989             ;; An alist of regexps/functions/forms.
990             (while (and var
991                         (not
992                          (setq result
993                                (cond
994                                 ((stringp (caar var))
995                                  ;; Regexp.
996                                  (when (string-match (caar var) group)
997                                    (cdar var)))
998                                 ((gnus-functionp (car var))
999                                  ;; Function.
1000                                  (funcall (car var) group))
1001                                 (t
1002                                  (eval (car var)))))))
1003               (setq var (cdr var)))
1004             result)))
1005          name)
1006     (when (or groups gcc-self-val)
1007       (when (stringp groups)
1008         (setq groups (list groups)))
1009       (save-excursion
1010         (save-restriction
1011           (message-narrow-to-headers)
1012           (goto-char (point-max))
1013           (insert "Gcc: ")
1014           (if gcc-self-val
1015               ;; Use the `gcc-self' param value instead.
1016               (progn
1017                 (insert
1018                  (if (stringp gcc-self-val)
1019                      gcc-self-val
1020                    group))
1021                 (if (not (eq gcc-self-val 'none))
1022                     (insert "\n")
1023                   (progn
1024                     (beginning-of-line)
1025                     (kill-line))))
1026             ;; Use the list of groups.
1027             (while (setq name (pop groups))
1028               (insert (if (string-match ":" name)
1029                           name
1030                         (gnus-group-prefixed-name
1031                          name gnus-message-archive-method)))
1032               (when groups
1033                 (insert " ")))
1034             (insert "\n")))))))
1035
1036 ;;; Allow redefinition of functions.
1037
1038 (gnus-ems-redefine)
1039
1040 (provide 'gnus-msg)
1041
1042 ;;; gnus-msg.el ends here