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