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