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