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