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