1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995,96,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Katsumi Yamaoka <yamaoka@jpl.org>
9 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
10 ;; Keywords: mail, news, MIME
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
33 (eval-when-compile (require 'cl))
40 (defcustom gnus-post-method nil
41 "*Preferred method for posting USENET news.
43 If this variable is `current', Gnus will use the \"current\" select
44 method when posting. If it is nil (which is the default), Gnus will
45 use the native posting method of the server.
47 This method will not be used in mail groups and the like, only in
50 If not nil nor `native', the value must be a valid method as discussed
51 in the documentation of `gnus-select-method'. It can also be a list of
52 methods. If that is the case, the user will be queried for what select
53 method to use when posting."
54 :group 'gnus-group-foreign
55 :type `(choice (const nil)
58 (sexp :tag "Methods" ,gnus-select-method)))
60 (defvar gnus-outgoing-message-group nil
61 "*All outgoing messages will be put in this group.
62 If you want to store all your outgoing mail and articles in the group
63 \"nnml:archive\", you set this variable to that value. This variable
64 can also be a list of group names.
66 If you want to have greater control over what group to put each
67 message in, you can set this variable to a function that checks the
68 current newsgroup name and then returns a suitable group name (or list
71 (defvar gnus-mailing-list-groups nil
72 "*Regexp matching groups that are really mailing lists.
73 This is useful when you're reading a mailing list that has been
74 gatewayed to a newsgroup, and you want to followup to an article in
77 (defvar gnus-add-to-list nil
78 "*If non-nil, add a `to-list' parameter automatically.")
80 (defvar gnus-crosspost-complaint
83 You posted the article below with the following Newsgroups header:
87 The %s group, at least, was an inappropriate recipient
88 of this message. Please trim your Newsgroups header to exclude this
89 group before posting in the future.
94 "Format string to be inserted when complaining about crossposts.
95 The first %s will be replaced by the Newsgroups header;
96 the second with the current group name.")
98 (defvar gnus-message-setup-hook '(gnus-maybe-setup-default-charset)
99 "Hook run after setting up a message buffer.")
101 (defvar gnus-bug-create-help-buffer t
102 "*Should we create the *Gnus Help Bug* buffer?")
104 (defvar gnus-posting-styles nil
105 "*Alist of styles to use when posting.")
107 (defvar gnus-posting-style-alist
108 '((organization . message-user-organization)
109 (signature . message-signature)
110 (signature-file . message-signature-file)
111 (address . user-mail-address)
112 (name . user-full-name))
113 "*Mapping from style parameters to variables.")
115 (defcustom gnus-group-posting-charset-alist
116 '(("^no\\." iso-8859-1)
118 (message-this-is-news iso-8859-1)
119 (message-this-is-mail nil)
121 "Alist of regexps (to match group names) and default charsets to be unencoded when posting."
122 :type '(repeat (list (regexp :tag "Group")
123 (symbol :tag "Charset")))
124 :group 'gnus-charset)
126 ;;; Internal variables.
128 (defvar gnus-inhibit-posting-styles nil
129 "Inhibit the use of posting styles.")
131 (defvar gnus-message-buffer "*Mail Gnus*")
132 (defvar gnus-article-copy nil)
133 (defvar gnus-last-posting-server nil)
134 (defvar gnus-message-group-art nil)
136 (defconst gnus-bug-message
137 (format "Sending a bug report to the Gnus Towers.
138 ========================================
140 This gnus is the %s%s.
141 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
142 Developers. (the addresses below are mailing list addresses)
144 ========================================
146 The buffer below is a mail buffer. When you press `C-c C-c', it will
147 be sent to the Gnus Bug Exterminators.
149 At the bottom of the buffer you'll see lots of variable settings.
150 Please do not delete those. They will tell the Bug People what your
151 environment is, so that it will be easier to locate the bugs.
153 If you have found a bug that makes Emacs go \"beep\", set
154 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
155 and include the backtrace in your bug report.
157 Please describe the bug in annoying, painstaking detail.
159 Thank you for your help in stamping out bugs.
162 (if (string= gnus-product-name "Semi-gnus")
164 ", a modified version of Semi-gnus")))
167 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
168 (autoload 'news-setup "rnewspost")
169 (autoload 'news-reply-mode "rnewspost")
170 (autoload 'rmail-dont-reply-to "mail-utils")
171 (autoload 'rmail-output "rmailout"))
175 ;;; Gnus Posting Functions
178 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
179 "p" gnus-summary-post-news
180 "f" gnus-summary-followup
181 "F" gnus-summary-followup-with-original
182 "c" gnus-summary-cancel-article
183 "s" gnus-summary-supersede-article
184 "r" gnus-summary-reply
185 "R" gnus-summary-reply-with-original
186 "w" gnus-summary-wide-reply
187 "W" gnus-summary-wide-reply-with-original
188 "n" gnus-summary-followup-to-mail
189 "N" gnus-summary-followup-to-mail-with-original
190 "m" gnus-summary-mail-other-window
191 "u" gnus-uu-post-news
192 "\M-c" gnus-summary-mail-crosspost-complaint
193 "om" gnus-summary-mail-forward
194 "op" gnus-summary-post-forward
195 "Om" gnus-summary-mail-digest
196 "Op" gnus-summary-post-digest)
198 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
199 "b" gnus-summary-resend-bounced-mail
200 ;; "c" gnus-summary-send-draft
201 "r" gnus-summary-resend-message)
203 ;;; Internal functions.
205 (defvar gnus-article-reply nil)
206 (defmacro gnus-setup-message (config &rest forms)
207 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
208 (buffer (make-symbol "gnus-setup-message-buffer"))
209 (article (make-symbol "gnus-setup-message-article"))
210 (group (make-symbol "gnus-setup-message-group")))
211 `(let ((,winconf (current-window-configuration))
212 (,buffer (buffer-name (current-buffer)))
213 (,article (and gnus-article-reply (gnus-summary-article-number)))
214 (,group gnus-newsgroup-name)
215 (message-header-setup-hook
216 (copy-sequence message-header-setup-hook))
217 (message-mode-hook (copy-sequence message-mode-hook))
218 (message-startup-parameter-alist
219 '((reply-buffer . gnus-copy-article-buffer)
220 (original-buffer . gnus-original-article-buffer)
221 (user-agent . Gnus))))
222 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
223 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
224 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
228 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
229 (setq gnus-message-buffer (current-buffer))
230 (set (make-local-variable 'gnus-message-group-art)
231 (cons ,group ,article))
232 (set (make-local-variable 'gnus-newsgroup-name) ,group)
233 (set (make-local-variable 'message-posting-charset)
234 (gnus-setup-posting-charset ,group))
235 (gnus-run-hooks 'gnus-message-setup-hook))
237 (gnus-configure-windows ,config t)
238 (set-buffer-modified-p nil))))
240 (defun gnus-setup-posting-charset (group)
241 (let ((alist gnus-group-posting-charset-alist)
245 (while (setq elem (pop alist))
246 (when (or (and (stringp (car elem))
247 (string-match (car elem) group))
248 (and (gnus-functionp (car elem))
249 (funcall (car elem) group))
250 (and (symbolp (car elem))
251 (symbol-value (car elem))))
252 (throw 'found (cadr elem))))))))
254 (defun gnus-inews-add-send-actions (winconf buffer article)
255 (make-local-hook 'message-sent-hook)
256 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
257 (setq message-post-method
259 (gnus-post-method arg ,gnus-newsgroup-name)))
260 (setq message-user-agent (gnus-extended-version))
261 (when (not message-use-multi-frames)
263 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
265 `(when (gnus-buffer-exists-p ,buffer)
269 `(gnus-summary-mark-article-as-replied ,article))))
272 (put 'gnus-setup-message 'lisp-indent-function 1)
273 (put 'gnus-setup-message 'edebug-form-spec '(form body))
275 ;;; Post news commands of Gnus group mode and summary mode
277 (defun gnus-group-mail (&optional arg)
278 "Start composing a mail.
279 If ARG, use the group under the point to find a posting style.
280 If ARG is 1, prompt for a group name to find the posting style."
282 ;; We can't `let' gnus-newsgroup-name here, since that leads
283 ;; to local variables leaking.
284 (let ((group gnus-newsgroup-name)
285 (buffer (current-buffer)))
288 (setq gnus-newsgroup-name
290 (if (= 1 (prefix-numeric-value arg))
291 (completing-read "Use posting style of group: "
292 gnus-active-hashtb nil
293 (gnus-read-active-file-p))
294 (gnus-group-group-name))
296 (gnus-setup-message 'message (message-mail)))
299 (setq gnus-newsgroup-name group)))))
301 (defun gnus-group-post-news (&optional arg)
302 "Start composing a news message.
303 If ARG, post to the group under point.
304 If ARG is 1, prompt for a group name."
306 ;; Bind this variable here to make message mode hooks work ok.
307 (let ((gnus-newsgroup-name
309 (if (= 1 (prefix-numeric-value arg))
310 (completing-read "Newsgroup: " gnus-active-hashtb nil
311 (gnus-read-active-file-p))
312 (gnus-group-group-name))
314 (gnus-post-news 'post gnus-newsgroup-name)))
316 (defun gnus-summary-post-news ()
317 "Start composing a news message."
319 (gnus-post-news 'post gnus-newsgroup-name))
321 (defun gnus-summary-followup (yank &optional force-news)
322 "Compose a followup to an article.
323 If prefix argument YANK is non-nil, original article is yanked automatically."
325 (list (and current-prefix-arg
326 (gnus-summary-work-articles 1))))
328 (gnus-summary-goto-subject (car yank)))
329 (save-window-excursion
330 (gnus-summary-select-article))
331 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
332 (gnus-newsgroup-name gnus-newsgroup-name))
334 (gnus-post-news nil gnus-newsgroup-name
335 headers gnus-article-buffer
336 yank nil force-news)))
338 (defun gnus-summary-followup-with-original (n &optional force-news)
339 "Compose a followup to an article and include the original article."
341 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
343 (defun gnus-summary-followup-to-mail (&optional arg)
344 "Followup to the current mail message via news."
346 (list (and current-prefix-arg
347 (gnus-summary-work-articles 1))))
348 (gnus-summary-followup arg t))
350 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
351 "Followup to the current mail message via news."
353 (gnus-summary-followup (gnus-summary-work-articles arg) t))
355 (defun gnus-inews-yank-articles (articles)
356 (let* ((more-than-one (cdr articles))
357 (frame (when (and message-use-multi-frames more-than-one)
358 (window-frame (get-buffer-window (current-buffer)))))
361 (while (setq article (pop articles))
362 (save-window-excursion
363 (set-buffer gnus-summary-buffer)
364 (gnus-summary-select-article nil nil nil article)
365 (gnus-summary-remove-process-mark article))
367 (select-frame frame))
369 ;; Gathering references.
371 (setq refs (message-list-references
373 (mail-header-references gnus-current-headers)
374 (mail-header-message-id gnus-current-headers))))
376 (gnus-copy-article-buffer)
377 (let ((message-reply-buffer gnus-article-copy)
378 (message-reply-headers gnus-current-headers))
379 (message-yank-original)
380 (setq beg (or beg (mark t))))
385 ;; Replace with the gathered references.
389 (message-narrow-to-headers)
390 (let ((case-fold-search t))
391 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
393 (goto-char (point-max))))
395 (list (or (assq 'References message-header-format-alist)
396 '(References . message-shorten-references)))
397 (list (cons 'References
398 (mapconcat 'identity (nreverse refs) " "))))
399 (backward-delete-char 1))
405 (defun gnus-summary-cancel-article (&optional n symp)
406 "Cancel an article you posted.
407 Uses the process-prefix convention. If given the symbolic
408 prefix `a', cancel using the standard posting method; if not
409 post using the current select method."
410 (interactive (gnus-interactive "P\ny"))
411 (let ((articles (gnus-summary-work-articles n))
414 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
416 (while (setq article (pop articles))
417 (when (gnus-summary-select-article t nil nil article)
418 (when (gnus-eval-in-buffer-window gnus-article-buffer
420 (set-buffer gnus-original-article-buffer)
421 (message-cancel-news)))
422 (gnus-summary-mark-as-read article gnus-canceled-mark)
423 (gnus-cache-remove-article 1))
424 (gnus-article-hide-headers-if-wanted))
425 (gnus-summary-remove-process-mark article))))
427 (defun gnus-summary-supersede-article ()
428 "Compose an article that will supersede a previous article.
429 This is done simply by taking the old article and adding a Supersedes
430 header line with the old Message-ID."
432 (let ((article (gnus-summary-article-number))
433 (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
434 (gnus-setup-message 'reply-yank
435 (gnus-summary-select-article t)
436 (set-buffer gnus-original-article-buffer)
440 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
442 (set-buffer ,gnus-summary-buffer)
443 (gnus-cache-possibly-remove-article ,article nil nil nil t)
444 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
445 message-send-actions))))
449 (defun gnus-copy-article-buffer (&optional article-buffer)
450 ;; make a copy of the article buffer with all text properties removed
451 ;; this copy is in the buffer gnus-article-copy.
452 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
453 ;; this buffer should be passed to all mail/news reply/post routines.
454 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
455 (let ((article-buffer (or article-buffer gnus-article-buffer))
457 (if (not (and (get-buffer article-buffer)
458 (gnus-buffer-exists-p article-buffer)))
459 (error "Can't find any article buffer")
461 (set-buffer article-buffer)
463 ;; Copy over the (displayed) article buffer, delete
464 ;; hidden text and remove text properties.
466 (copy-to-buffer gnus-article-copy (point-min) (point-max))
467 (set-buffer gnus-article-copy)
468 (gnus-article-delete-text-of-type 'annotation)
469 (gnus-remove-text-with-property 'gnus-prev)
470 (gnus-remove-text-with-property 'gnus-next)
473 (format "%s" (buffer-string))
475 ;; Find the original headers.
476 (set-buffer gnus-original-article-buffer)
477 (goto-char (point-min))
478 (while (looking-at message-unix-mail-delimiter)
481 (setq end (or (search-forward "\n\n" nil t) (point)))
482 ;; Delete the headers from the displayed articles.
483 (set-buffer gnus-article-copy)
484 (delete-region (goto-char (point-min))
485 (or (search-forward "\n\n" nil t) (point-max)))
486 ;; Insert the original article headers.
487 (insert-buffer-substring gnus-original-article-buffer beg end)
488 (article-decode-encoded-words)))
491 (defun gnus-post-news (post &optional group header article-buffer yank subject
494 (gnus-copy-article-buffer))
495 (let ((gnus-article-reply article-buffer)
496 (add-to-list gnus-add-to-list))
497 (gnus-setup-message (cond (yank 'reply-yank)
498 (article-buffer 'reply)
500 (let* ((group (or group gnus-newsgroup-name))
502 to-address to-group mailing-list to-list
505 (setq to-address (gnus-group-find-parameter group 'to-address)
506 to-group (gnus-group-find-parameter group 'to-group)
507 to-list (gnus-group-find-parameter group 'to-list)
508 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
509 mailing-list (when gnus-mailing-list-groups
510 (string-match gnus-mailing-list-groups group))
511 group (gnus-group-real-name group)))
512 (if (or (and to-group
513 (gnus-news-group-p to-group))
516 (and (gnus-news-group-p
517 (or pgroup gnus-newsgroup-name)
518 (if header (mail-header-number header)
519 gnus-current-article))
525 (message-news (or to-group group))
526 (set-buffer gnus-article-copy)
527 (gnus-msg-treat-broken-reply-to)
528 (message-followup (if (or newsgroup-p force-news) nil to-group)))
532 (message-mail (or to-address to-list))
533 ;; Arrange for mail groups that have no `to-address' to
534 ;; get that when the user sends off the mail.
535 (when (and (not to-list)
538 (push (list 'gnus-inews-add-to-address pgroup)
539 message-send-actions)))
540 (set-buffer gnus-article-copy)
541 (gnus-msg-treat-broken-reply-to)
542 (message-wide-reply to-address)))
544 (gnus-inews-yank-articles yank))))))
546 (defun gnus-msg-treat-broken-reply-to ()
547 "Remove the Reply-to header iff broken-reply-to."
548 (when (gnus-group-find-parameter
549 gnus-newsgroup-name 'broken-reply-to)
551 (message-narrow-to-head)
552 (message-remove-header "reply-to"))))
554 (defun gnus-post-method (arg group &optional silent)
555 "Return the posting method based on GROUP and ARG.
556 If SILENT, don't prompt the user."
557 (let ((group-method (gnus-find-method-for-group group)))
559 ;; If the group-method is nil (which shouldn't happen) we use
560 ;; the default method.
562 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
563 gnus-select-method message-post-method))
564 ;; We want the inverse of the default
565 ((and arg (not (eq arg 0)))
566 (if (eq gnus-post-method 'active)
569 ;; We query the user for a post method.
571 (and gnus-post-method
572 (not (eq gnus-post-method 'current))
573 (listp (car gnus-post-method))))
575 ;; Collect all methods we know about.
577 (when (and gnus-post-method
578 (not (eq gnus-post-method 'current)))
579 (if (listp (car gnus-post-method))
581 (list gnus-post-method)))
582 gnus-secondary-select-methods
583 (mapcar 'cdr gnus-server-alist)
584 (mapcar 'car gnus-opened-servers)
585 (list gnus-select-method)
586 (list group-method)))
587 method-alist post-methods method)
588 ;; Weed out all mail methods.
590 (setq method (gnus-server-get-method "" (pop methods)))
591 (when (and (or (gnus-method-option-p method 'post)
592 (gnus-method-option-p method 'post-mail))
593 (not (member method post-methods)))
594 (push method post-methods)))
595 ;; Create a name-method alist.
599 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
604 (setq gnus-last-posting-server
606 gnus-last-posting-server)
607 ;; Just use the last value.
608 gnus-last-posting-server
610 "Posting method: " method-alist nil t
611 (cons (or gnus-last-posting-server "") 0))))
613 ;; Override normal method.
614 ((and (eq gnus-post-method 'current)
615 (not (eq (car group-method) 'nndraft))
618 ((and gnus-post-method
619 (not (eq gnus-post-method 'current)))
621 ;; Use the normal select method.
622 (t gnus-select-method))))
626 (defun gnus-extended-version ()
627 "Stringified gnus version."
628 (concat gnus-product-name "/" gnus-version-number " (based on "
629 gnus-original-product-name " v" gnus-original-version-number ")"))
631 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
632 "Return user-agent info.
633 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
634 `mime-edit-user-agent-value' exists, the return value will include it.
635 MAX-COLUMN the optional second argument if it is specified, the return value
636 will be folded up in the proper way."
637 (let ((user-agent (if (and include-mime-info
638 (boundp 'mime-edit-user-agent-value))
639 (concat (gnus-extended-version)
641 mime-edit-user-agent-value)
642 (gnus-extended-version))))
645 (unless (natnump max-column) (setq max-column 76))
647 (insert " " user-agent)
649 (while (re-search-forward "[\n\t ]+" nil t)
652 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
653 (while (eq ?\( (char-after (point)))
655 (skip-chars-forward " "))
656 (skip-chars-backward " ")
657 (if (> (current-column) max-column)
659 (if (or (not boundary) (eq ?\n (char-after boundary)))
661 (setq boundary (point))
668 (setq boundary (point))))
669 (buffer-substring 13 (point-max))))
674 ;;; Gnus Mail Functions
677 ;;; Mail reply commands of Gnus summary mode
679 (defun gnus-summary-reply (&optional yank wide)
680 "Start composing a reply mail to the current message.
681 If prefix argument YANK is non-nil, the original article is yanked
684 (list (and current-prefix-arg
685 (gnus-summary-work-articles 1))))
686 ;; Stripping headers should be specified with mail-yank-ignored-headers.
688 (gnus-summary-goto-subject (car yank)))
689 (let ((gnus-article-reply t))
690 (gnus-setup-message (if yank 'reply-yank 'reply)
691 (gnus-summary-select-article)
692 (set-buffer (gnus-copy-article-buffer))
693 (gnus-msg-treat-broken-reply-to)
694 (message-reply nil wide)
696 (gnus-inews-yank-articles yank)))))
698 (defun gnus-summary-reply-with-original (n &optional wide)
699 "Start composing a reply mail to the current message.
700 The original article will be yanked."
702 (gnus-summary-reply (gnus-summary-work-articles n) wide))
704 (defun gnus-summary-wide-reply (&optional yank)
705 "Start composing a wide reply mail to the current message.
706 If prefix argument YANK is non-nil, the original article is yanked
709 (list (and current-prefix-arg
710 (gnus-summary-work-articles 1))))
711 (gnus-summary-reply yank t))
713 (defun gnus-summary-wide-reply-with-original (n)
714 "Start composing a wide reply mail to the current message.
715 The original article will be yanked."
717 (gnus-summary-reply-with-original n t))
719 (defun gnus-summary-mail-forward (&optional full-headers post)
720 "Forward the current message to another user.
721 If FULL-HEADERS (the prefix), include full headers when forwarding."
723 (gnus-setup-message 'forward
724 (gnus-summary-select-article)
725 (let ((charset default-mime-charset))
726 (set-buffer gnus-original-article-buffer)
727 (make-local-variable 'default-mime-charset)
728 (setq default-mime-charset charset)
730 (let ((message-included-forward-headers
731 (if full-headers "" message-included-forward-headers)))
732 (message-forward post))))
734 ;;; XXX: generate Subject and ``Topics''?
735 (defun gnus-summary-mail-digest (&optional n post)
736 "Digests and forwards all articles in this series."
738 (let ((subject "Digested Articles")
739 (articles (gnus-summary-work-articles n))
741 (gnus-setup-message 'forward
742 (gnus-summary-select-article)
743 (if post (message-news nil subject) (message-mail nil subject))
744 (when (and message-use-multi-frames (cdr articles))
745 (setq frame (window-frame (get-buffer-window (current-buffer)))))
747 (while (setq article (pop articles))
748 (save-window-excursion
749 (set-buffer gnus-summary-buffer)
750 (gnus-summary-select-article nil nil nil article)
751 (gnus-summary-remove-process-mark article))
753 (select-frame frame))
754 (insert (mime-make-tag "message" "rfc822") "\n")
755 (insert-buffer-substring gnus-original-article-buffer))
758 (mime-edit-enclose-digest-region (point)(mark t)))))
760 (defun gnus-summary-post-digest (&optional n)
761 "Digest and forwards all articles in this series to a newsgroup."
763 (gnus-summary-mail-digest n t))
765 (defun gnus-summary-resend-message (address n)
766 "Resend the current article to ADDRESS."
767 (interactive "sResend message(s) to: \nP")
768 (let ((articles (gnus-summary-work-articles n))
770 (while (setq article (pop articles))
771 (gnus-summary-select-article nil nil nil article)
773 (set-buffer gnus-original-article-buffer)
774 (message-resend address)))))
776 (defun gnus-summary-post-forward (&optional full-headers)
777 "Forward the current article to a newsgroup.
778 If FULL-HEADERS (the prefix), include full headers when forwarding."
780 (gnus-summary-mail-forward full-headers t))
782 (defvar gnus-nastygram-message
783 "The following article was inappropriately posted to %s.\n\n"
784 "Format string to insert in nastygrams.
785 The current group name will be inserted at \"%s\".")
787 (defun gnus-summary-mail-nastygram (n)
788 "Send a nastygram to the author of the current article."
790 (when (or gnus-expert-user
792 "Really send a nastygram to the author of the current article? "))
793 (let ((group gnus-newsgroup-name))
794 (gnus-summary-reply-with-original n)
795 (set-buffer gnus-message-buffer)
797 (insert (format gnus-nastygram-message group))
798 (message-send-and-exit))))
800 (defun gnus-summary-mail-crosspost-complaint (n)
801 "Send a complaint about crossposting to the current article(s)."
803 (let ((articles (gnus-summary-work-articles n))
805 (while (setq article (pop articles))
806 (set-buffer gnus-summary-buffer)
807 (gnus-summary-goto-subject article)
808 (let ((group (gnus-group-real-name gnus-newsgroup-name))
809 newsgroups followup-to)
810 (gnus-summary-select-article)
811 (set-buffer gnus-original-article-buffer)
812 (if (and (<= (length (message-tokenize-header
814 (mail-fetch-field "newsgroups"))
817 (or (not (setq followup-to (mail-fetch-field "followup-to")))
818 (not (member group (message-tokenize-header
819 followup-to ", ")))))
821 (gnus-message 1 "Followup-to restricted")
822 (gnus-message 1 "Not a crossposted article"))
823 (set-buffer gnus-summary-buffer)
824 (gnus-summary-reply-with-original 1)
825 (set-buffer gnus-message-buffer)
827 (insert (format gnus-crosspost-complaint newsgroups group))
828 (message-goto-subject)
829 (re-search-forward " *$")
830 (replace-match " (crosspost notification)" t t)
831 (gnus-deactivate-mark)
832 (when (gnus-y-or-n-p "Send this complaint? ")
833 (message-send-and-exit)))))))
835 (defun gnus-summary-mail-other-window ()
836 "Compose mail in other window."
838 (gnus-setup-message 'message
841 (defun gnus-mail-parse-comma-list ()
844 (skip-chars-forward " ")
847 (skip-chars-forward "^,")
852 (narrow-to-region beg (point))
855 (while (search-forward "\"" nil t)
859 (skip-chars-forward ",")
860 (skip-chars-forward "^,"))
861 (skip-chars-backward " ")
862 (push (buffer-substring beg (point))
864 (skip-chars-forward "^,")
865 (skip-chars-forward ", "))
868 (defun gnus-inews-add-to-address (group)
869 (let ((to-address (mail-fetch-field "to")))
870 (when (and to-address
872 ;; This mail group doesn't have a `to-list', so we add one
875 (format "Do you want to add this as `to-list': %s " to-address))
876 (gnus-group-add-parameter group (cons 'to-list to-address))))))
878 (defun gnus-put-message ()
879 "Put the current message in some group and return to Gnus."
881 (let ((reply gnus-article-reply)
882 (winconf gnus-prev-winconf)
883 (group gnus-newsgroup-name))
885 (or (and group (not (gnus-group-read-only-p group)))
886 (setq group (read-string "Put in group: " nil
887 (gnus-writable-groups))))
888 (when (gnus-gethash group gnus-newsrc-hashtb)
889 (error "No such group: %s" group))
894 (message-narrow-to-headers)
895 (let (gnus-deletable-headers)
897 (message-generate-headers message-required-news-headers)
898 (message-generate-headers message-required-mail-headers)))
899 (goto-char (point-max))
900 (insert "Gcc: " group "\n")
905 (when (get-buffer gnus-group-buffer)
906 (when (gnus-buffer-exists-p (car-safe reply))
907 (set-buffer (car reply))
909 (gnus-summary-mark-article-as-replied
912 (set-window-configuration winconf)))))
914 (defun gnus-article-mail (yank)
915 "Send a reply to the address near point.
916 If YANK is non-nil, include the original article."
920 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
921 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
923 (message-reply address)
925 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
927 (defvar nntp-server-type)
929 "Send a bug report to the Gnus maintainers."
931 (unless (gnus-alive-p)
932 (error "Gnus has been shut down"))
933 (gnus-setup-message 'bug
934 (delete-other-windows)
935 (when gnus-bug-create-help-buffer
936 (switch-to-buffer "*Gnus Help Bug*")
938 (insert gnus-bug-message)
939 (goto-char (point-min)))
940 (message-pop-to-buffer "*Gnus Bug*")
942 `((To . ,gnus-maintainer) (Cc . ,semi-gnus-developers) (Subject . "")))
943 (when gnus-bug-create-help-buffer
944 (push `(gnus-bug-kill-buffer) message-send-actions))
945 (goto-char (point-min))
946 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
948 (insert (gnus-version) "\n"
949 (emacs-version) "\n")
950 (when (and (boundp 'nntp-server-type)
951 (stringp nntp-server-type))
952 (insert nntp-server-type))
953 (insert "\n\n\n\n\n")
955 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
957 (insert "<#part type=application/emacs-lisp buffer=\" *gnus environment info*\" disposition=inline><#/part>")
958 (goto-char (point-min))
959 (search-forward "Subject: " nil t)
962 (defun gnus-bug-kill-buffer ()
963 (when (get-buffer "*Gnus Help Bug*")
964 (kill-buffer "*Gnus Help Bug*")))
967 "Attempts to go through the Gnus source file and report what variables have been changed.
968 The source file has to be in the Emacs load path."
970 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
971 "gnus-art.el" "gnus-start.el" "gnus-async.el"
972 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
973 "nnmail.el" "message.el"))
976 (gnus-message 4 "Please wait while we snoop your variables...")
978 ;; Go through all the files looking for non-default values for variables.
980 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
983 (when (and (setq file (locate-library (pop files)))
984 (file-exists-p file))
985 (insert-file-contents file)
986 (goto-char (point-min))
987 (if (not (re-search-forward "^;;* *Internal variables" nil t))
988 (gnus-message 4 "Malformed sources in file %s" file)
989 (narrow-to-region (point-min) (point))
990 (goto-char (point-min))
991 (while (setq expr (ignore-errors (read (current-buffer))))
993 (and (or (eq (car expr) 'defvar)
994 (eq (car expr) 'defcustom))
995 (stringp (nth 3 expr))
996 (or (not (boundp (nth 1 expr)))
997 (not (equal (eval (nth 2 expr))
998 (symbol-value (nth 1 expr)))))
999 (push (nth 1 expr) olist)))))))
1000 (kill-buffer (current-buffer)))
1001 (when (setq olist (nreverse olist))
1002 (insert "------------------ Environment follows ------------------\n\n"))
1004 (if (boundp (car olist))
1006 (pp `(setq ,(car olist)
1007 ,(if (or (consp (setq sym (symbol-value (car olist))))
1009 (not (or (eq sym nil)
1011 (list 'quote (symbol-value (car olist)))
1012 (symbol-value (car olist))))
1015 (format "(setq %s 'whatever)\n" (car olist))))
1016 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1017 (setq olist (cdr olist)))
1019 ;; Remove any control chars - they seem to cause trouble for some
1020 ;; mailers. (Byte-compiled output from the stuff above.)
1022 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1023 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1026 ;;; Treatment of rejected articles.
1029 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1030 "Re-mail the current message.
1031 This only makes sense if the current message is a bounce message than
1032 contains some mail you have written which has been bounced back to
1034 If FETCH, try to fetch the article that this is a reply to, if indeed
1037 (gnus-summary-select-article t)
1038 (set-buffer gnus-original-article-buffer)
1039 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1040 (gnus-setup-message 'compose-bounce
1041 (let* ((references (mail-fetch-field "references"))
1042 (parent (and references (gnus-parent-id references))))
1044 ;; If there are references, we fetch the article we answered to.
1046 (gnus-summary-refer-article parent)
1047 (gnus-summary-show-all-headers))))))
1051 ;; Do Gcc handling, which copied the message over to some group.
1052 (defun gnus-inews-do-gcc (&optional gcc)
1054 (when (gnus-alive-p)
1057 (message-narrow-to-headers)
1058 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1059 (coding-system-for-write 'raw-text)
1060 groups group method)
1062 (message-remove-header "gcc")
1064 (setq groups (message-tokenize-header gcc " ,"))
1065 ;; Copy the article over to some group(s).
1066 (while (setq group (pop groups))
1069 (cond ((and (null (gnus-get-info group))
1070 (eq (car gnus-message-archive-method)
1072 (gnus-server-to-method
1073 (gnus-group-method group)))))
1074 ;; If the group doesn't exist, we assume
1075 ;; it's an archive group...
1076 gnus-message-archive-method)
1078 ((gnus-info-method (gnus-get-info group))
1079 (gnus-info-method (gnus-get-info group)))
1081 (t (gnus-group-method group)))))
1082 (gnus-check-server method)
1083 (unless (gnus-request-group group t method)
1084 (gnus-request-create-group group method))
1086 (nnheader-set-temp-buffer " *acc*")
1087 (insert-buffer-substring message-encoding-buffer)
1088 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1089 (goto-char (point-min))
1090 (when (re-search-forward
1091 (concat "^" (regexp-quote mail-header-separator) "$")
1093 (replace-match "" t t ))
1094 (unless (gnus-request-accept-article group method t t)
1095 (gnus-message 1 "Couldn't store article in group %s: %s"
1096 group (gnus-status-message method))
1098 (kill-buffer (current-buffer))))))))))
1100 (defun gnus-inews-insert-gcc ()
1101 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1104 (message-narrow-to-headers)
1105 (let* ((group gnus-outgoing-message-group)
1107 ((gnus-functionp group)
1109 ((or (stringp group) (list group))
1113 (if (stringp gcc) gcc
1114 (mapconcat 'identity gcc " "))
1117 (defun gnus-inews-insert-archive-gcc (&optional group)
1118 "Insert the Gcc to say where the article is to be archived."
1119 (let* ((var gnus-message-archive-group)
1120 (group (or group gnus-newsgroup-name ""))
1122 (and gnus-newsgroup-name
1123 (gnus-group-find-parameter
1124 gnus-newsgroup-name 'gcc-self)))
1128 ((null gnus-message-archive-method)
1132 ;; Just a single group.
1135 ;; We don't want this.
1137 ((and (listp var) (stringp (car var)))
1138 ;; A list of groups.
1140 ((gnus-functionp var)
1142 (funcall var group))
1144 ;; An alist of regexps/functions/forms.
1149 ((stringp (caar var))
1151 (when (string-match (caar var) group)
1153 ((gnus-functionp (car var))
1155 (funcall (car var) group))
1157 (eval (car var)))))))
1158 (setq var (cdr var)))
1161 (when (or groups gcc-self-val)
1162 (when (stringp groups)
1163 (setq groups (list groups)))
1166 (message-narrow-to-headers)
1167 (goto-char (point-max))
1170 ;; Use the `gcc-self' param value instead.
1173 (if (stringp gcc-self-val)
1176 (if (not (eq gcc-self-val 'none))
1181 ;; Use the list of groups.
1182 (while (setq name (pop groups))
1183 (insert (if (string-match ":" name)
1185 (gnus-group-prefixed-name
1186 name gnus-message-archive-method)))
1193 (defvar gnus-message-style-insertions nil)
1195 (defun gnus-configure-posting-styles ()
1196 "Configure posting styles according to `gnus-posting-styles'."
1197 (unless gnus-inhibit-posting-styles
1198 (let ((styles gnus-posting-styles)
1199 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
1200 style match variable attribute value value-value)
1201 (make-local-variable 'gnus-message-style-insertions)
1202 ;; If the group has a posting-style parameter, add it at the end with a
1203 ;; regexp matching everything, to be sure it takes precedence over all
1205 (unless (zerop (length gnus-newsgroup-name))
1206 (let ((tmp-style (gnus-group-find-parameter
1207 gnus-newsgroup-name 'posting-style t)))
1209 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1210 ;; Go through all styles and look for matches.
1212 (setq style (pop styles)
1216 ;; Regexp string match on the group name.
1217 (string-match match gnus-newsgroup-name))
1218 ((or (symbolp match)
1219 (gnus-functionp match))
1221 ((gnus-functionp match)
1222 ;; Function to be called.
1225 ;; Variable to be checked.
1226 (symbol-value match))))
1228 ;; This is a form to be evaled.
1230 ;; We have a match, so we set the variables.
1232 (setq attribute (pop style)
1233 value (cadr attribute)
1235 ;; We find the variable that is to be modified.
1236 (if (and (not (stringp (car attribute)))
1237 (not (eq 'body (car attribute)))
1239 (cdr (assq (car attribute)
1240 gnus-posting-style-alist)))))
1241 (message "Couldn't find attribute %s" (car attribute))
1242 ;; We get the value.
1247 ((or (symbolp value)
1248 (gnus-functionp value))
1249 (cond ((gnus-functionp value)
1252 (symbol-value value))))
1256 ;; This is an ordinary variable.
1257 (set (make-local-variable variable) value-value)
1258 ;; This is either a body or a header to be inserted in the
1260 (let ((attr (car attribute)))
1261 (make-local-variable 'message-setup-hook)
1263 (add-hook 'message-setup-hook
1267 (insert ,value-value))))
1268 (add-hook 'message-setup-hook
1269 'gnus-message-insert-stylings)
1270 (push (cons (if (stringp attr) attr
1273 gnus-message-style-insertions)))))))))))
1275 (defun gnus-message-insert-stylings ()
1279 (while (setq val (pop gnus-message-style-insertions))
1281 (insert (car val) ": " (cdr val) "\n"))
1282 (gnus-pull (car val) gnus-message-style-insertions t)))))
1285 ;;; @ for MIME Edit mode
1288 (defun gnus-maybe-setup-default-charset ()
1290 (and (boundp 'gnus-summary-buffer)
1291 (buffer-live-p gnus-summary-buffer)
1293 (set-buffer gnus-summary-buffer)
1294 default-mime-charset))))
1297 (make-local-variable 'default-mime-charset)
1298 (setq default-mime-charset charset)
1302 ;;; Allow redefinition of functions.
1308 ;;; gnus-msg.el ends here