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.
42 (defcustom gnus-post-method nil
43 "*Preferred method for posting USENET news.
45 If this variable is `current', Gnus will use the \"current\" select
46 method when posting. If it is nil (which is the default), Gnus will
47 use the native posting method of the server.
49 This method will not be used in mail groups and the like, only in
52 If not nil nor `native', the value must be a valid method as discussed
53 in the documentation of `gnus-select-method'. It can also be a list of
54 methods. If that is the case, the user will be queried for what select
55 method to use when posting."
56 :group 'gnus-group-foreign
57 :type `(choice (const nil)
60 (sexp :tag "Methods" ,gnus-select-method)))
62 (defvar gnus-outgoing-message-group nil
63 "*All outgoing messages will be put in this group.
64 If you want to store all your outgoing mail and articles in the group
65 \"nnml:archive\", you set this variable to that value. This variable
66 can also be a list of group names.
68 If you want to have greater control over what group to put each
69 message in, you can set this variable to a function that checks the
70 current newsgroup name and then returns a suitable group name (or list
73 (defvar gnus-mailing-list-groups nil
74 "*Regexp matching groups that are really mailing lists.
75 This is useful when you're reading a mailing list that has been
76 gatewayed to a newsgroup, and you want to followup to an article in
79 (defvar gnus-add-to-list nil
80 "*If non-nil, add a `to-list' parameter automatically.")
82 (defvar gnus-crosspost-complaint
85 You posted the article below with the following Newsgroups header:
89 The %s group, at least, was an inappropriate recipient
90 of this message. Please trim your Newsgroups header to exclude this
91 group before posting in the future.
96 "Format string to be inserted when complaining about crossposts.
97 The first %s will be replaced by the Newsgroups header;
98 the second with the current group name.")
100 (defvar gnus-message-setup-hook '(gnus-maybe-setup-default-charset)
101 "Hook run after setting up a message buffer.")
103 (defvar gnus-bug-create-help-buffer t
104 "*Should we create the *Gnus Help Bug* buffer?")
106 (defvar gnus-posting-styles nil
107 "*Alist of styles to use when posting.")
109 (defcustom gnus-group-posting-charset-alist
110 '(("^no\\." iso-8859-1)
111 (message-this-is-mail nil)
114 (message-this-is-news iso-8859-1))
115 "Alist of regexps (to match group names) and default charsets to be unencoded when posting."
116 :type '(repeat (list (regexp :tag "Group")
117 (symbol :tag "Charset")))
118 :group 'gnus-charset)
120 ;;; Internal variables.
122 (defvar gnus-inhibit-posting-styles nil
123 "Inhibit the use of posting styles.")
125 (defvar gnus-message-buffer "*Mail Gnus*")
126 (defvar gnus-article-copy nil)
127 (defvar gnus-last-posting-server nil)
128 (defvar gnus-message-group-art nil)
130 (defconst gnus-bug-message
131 (format "Sending a bug report to the Gnus Towers.
132 ========================================
134 This gnus is the %s%s.
135 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
136 Developers. (the addresses below are mailing list addresses)
138 ========================================
140 The buffer below is a mail buffer. When you press `C-c C-c', it will
141 be sent to the Gnus Bug Exterminators.
143 The thing near the bottom of the buffer is how the environment
144 settings will be included in the mail. Please do not delete that.
145 They will tell the Bug People what your environment is, so that it
146 will be easier to locate the bugs.
148 If you have found a bug that makes Emacs go \"beep\", set
149 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
150 and include the backtrace in your bug report.
152 Please describe the bug in annoying, painstaking detail.
154 Thank you for your help in stamping out bugs.
157 (if (string= gnus-product-name "Semi-gnus")
159 ", a modified version of Semi-gnus")))
162 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
163 (autoload 'news-setup "rnewspost")
164 (autoload 'news-reply-mode "rnewspost")
165 (autoload 'rmail-dont-reply-to "mail-utils")
166 (autoload 'rmail-output "rmailout"))
170 ;;; Gnus Posting Functions
173 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
174 "p" gnus-summary-post-news
175 "f" gnus-summary-followup
176 "F" gnus-summary-followup-with-original
177 "c" gnus-summary-cancel-article
178 "s" gnus-summary-supersede-article
179 "r" gnus-summary-reply
180 "R" gnus-summary-reply-with-original
181 "w" gnus-summary-wide-reply
182 "W" gnus-summary-wide-reply-with-original
183 "n" gnus-summary-followup-to-mail
184 "N" gnus-summary-followup-to-mail-with-original
185 "m" gnus-summary-mail-other-window
186 "u" gnus-uu-post-news
187 "\M-c" gnus-summary-mail-crosspost-complaint
188 "om" gnus-summary-mail-forward
189 "op" gnus-summary-post-forward
190 "Om" gnus-summary-mail-digest
191 "Op" gnus-summary-post-digest)
193 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
194 "b" gnus-summary-resend-bounced-mail
195 ;; "c" gnus-summary-send-draft
196 "r" gnus-summary-resend-message)
198 ;;; Internal functions.
200 (defvar gnus-article-reply nil)
201 (defmacro gnus-setup-message (config &rest forms)
202 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
203 (buffer (make-symbol "gnus-setup-message-buffer"))
204 (article (make-symbol "gnus-setup-message-article"))
205 (group (make-symbol "gnus-setup-message-group")))
206 `(let ((,winconf (current-window-configuration))
207 (,buffer (buffer-name (current-buffer)))
208 (,article (and gnus-article-reply (gnus-summary-article-number)))
209 (,group gnus-newsgroup-name)
210 (message-header-setup-hook
211 (copy-sequence message-header-setup-hook))
212 (message-mode-hook (copy-sequence message-mode-hook))
213 (message-startup-parameter-alist
214 '((reply-buffer . gnus-copy-article-buffer)
215 (original-buffer . gnus-original-article-buffer)
216 (user-agent . Gnus))))
217 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
218 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
219 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
223 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
224 (setq gnus-message-buffer (current-buffer))
225 (set (make-local-variable 'gnus-message-group-art)
226 (cons ,group ,article))
227 (set (make-local-variable 'gnus-newsgroup-name) ,group)
228 (set (make-local-variable 'message-posting-charset)
229 (gnus-setup-posting-charset ,group))
230 (gnus-run-hooks 'gnus-message-setup-hook))
232 (gnus-configure-windows ,config t)
233 (set-buffer-modified-p nil))))
235 (defun gnus-setup-posting-charset (group)
236 (let ((alist gnus-group-posting-charset-alist)
237 (group (or group ""))
241 (while (setq elem (pop alist))
242 (when (or (and (stringp (car elem))
243 (string-match (car elem) group))
244 (and (gnus-functionp (car elem))
245 (funcall (car elem) group))
246 (and (symbolp (car elem))
247 (symbol-value (car elem))))
248 (throw 'found (cadr elem))))))))
250 (defun gnus-inews-add-send-actions (winconf buffer article)
251 (make-local-hook 'message-sent-hook)
252 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
253 (setq message-post-method
255 (gnus-post-method arg ,gnus-newsgroup-name)))
256 (setq message-user-agent (gnus-extended-version))
257 (when (not message-use-multi-frames)
259 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
261 `(when (gnus-buffer-exists-p ,buffer)
265 `(gnus-summary-mark-article-as-replied ,article))))
268 (put 'gnus-setup-message 'lisp-indent-function 1)
269 (put 'gnus-setup-message 'edebug-form-spec '(form body))
271 ;;; Post news commands of Gnus group mode and summary mode
273 (defun gnus-group-mail (&optional arg)
274 "Start composing a mail.
275 If ARG, use the group under the point to find a posting style.
276 If ARG is 1, prompt for a group name to find the posting style."
278 ;; We can't `let' gnus-newsgroup-name here, since that leads
279 ;; to local variables leaking.
280 (let ((group gnus-newsgroup-name)
281 (buffer (current-buffer)))
284 (setq gnus-newsgroup-name
286 (if (= 1 (prefix-numeric-value arg))
287 (completing-read "Use posting style of group: "
288 gnus-active-hashtb nil
289 (gnus-read-active-file-p))
290 (gnus-group-group-name))
292 (gnus-setup-message 'message (message-mail)))
295 (setq gnus-newsgroup-name group)))))
297 (defun gnus-group-post-news (&optional arg)
298 "Start composing a news message.
299 If ARG, post to the group under point.
300 If ARG is 1, prompt for a group name."
302 ;; Bind this variable here to make message mode hooks work ok.
303 (let ((gnus-newsgroup-name
305 (if (= 1 (prefix-numeric-value arg))
306 (completing-read "Newsgroup: " gnus-active-hashtb nil
307 (gnus-read-active-file-p))
308 (gnus-group-group-name))
310 (gnus-post-news 'post gnus-newsgroup-name)))
312 (defun gnus-summary-post-news ()
313 "Start composing a news message."
315 (gnus-post-news 'post gnus-newsgroup-name))
317 (defun gnus-summary-followup (yank &optional force-news)
318 "Compose a followup to an article.
319 If prefix argument YANK is non-nil, original article is yanked automatically."
321 (list (and current-prefix-arg
322 (gnus-summary-work-articles 1))))
324 (gnus-summary-goto-subject (car yank)))
325 (save-window-excursion
326 (gnus-summary-select-article))
327 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
328 (gnus-newsgroup-name gnus-newsgroup-name))
330 (gnus-post-news nil gnus-newsgroup-name
331 headers gnus-article-buffer
332 yank nil force-news)))
334 (defun gnus-summary-followup-with-original (n &optional force-news)
335 "Compose a followup to an article and include the original article."
337 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
339 (defun gnus-summary-followup-to-mail (&optional arg)
340 "Followup to the current mail message via news."
342 (list (and current-prefix-arg
343 (gnus-summary-work-articles 1))))
344 (gnus-summary-followup arg t))
346 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
347 "Followup to the current mail message via news."
349 (gnus-summary-followup (gnus-summary-work-articles arg) t))
351 (defun gnus-inews-yank-articles (articles)
352 (let* ((more-than-one (cdr articles))
353 (frame (when (and message-use-multi-frames more-than-one)
354 (window-frame (get-buffer-window (current-buffer)))))
357 (while (setq article (pop articles))
358 (save-window-excursion
359 (set-buffer gnus-summary-buffer)
360 (gnus-summary-select-article nil nil nil article)
361 (gnus-summary-remove-process-mark article))
363 (select-frame frame))
365 ;; Gathering references.
367 (setq refs (message-list-references
369 (mail-header-references gnus-current-headers)
370 (mail-header-message-id gnus-current-headers))))
372 (gnus-copy-article-buffer)
373 (let ((message-reply-buffer gnus-article-copy)
374 (message-reply-headers gnus-current-headers))
375 (message-yank-original)
376 (setq beg (or beg (mark t))))
381 ;; Replace with the gathered references.
385 (message-narrow-to-headers)
386 (let ((case-fold-search t))
387 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
389 (goto-char (point-max))))
391 (list (or (assq 'References message-header-format-alist)
392 '(References . message-shorten-references)))
393 (list (cons 'References
394 (mapconcat 'identity (nreverse refs) " "))))
395 (backward-delete-char 1))
401 (defun gnus-summary-cancel-article (&optional n symp)
402 "Cancel an article you posted.
403 Uses the process-prefix convention. If given the symbolic
404 prefix `a', cancel using the standard posting method; if not
405 post using the current select method."
406 (interactive (gnus-interactive "P\ny"))
407 (let ((articles (gnus-summary-work-articles n))
410 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
412 (while (setq article (pop articles))
413 (when (gnus-summary-select-article t nil nil article)
414 (when (gnus-eval-in-buffer-window gnus-article-buffer
416 (set-buffer gnus-original-article-buffer)
417 (message-cancel-news)))
418 (gnus-summary-mark-as-read article gnus-canceled-mark)
419 (gnus-cache-remove-article 1))
420 (gnus-article-hide-headers-if-wanted))
421 (gnus-summary-remove-process-mark article))))
423 (defun gnus-summary-supersede-article ()
424 "Compose an article that will supersede a previous article.
425 This is done simply by taking the old article and adding a Supersedes
426 header line with the old Message-ID."
428 (let ((article (gnus-summary-article-number))
429 (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
430 (gnus-setup-message 'reply-yank
431 (gnus-summary-select-article t)
432 (set-buffer gnus-original-article-buffer)
436 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
438 (set-buffer ,gnus-summary-buffer)
439 (gnus-cache-possibly-remove-article ,article nil nil nil t)
440 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
441 message-send-actions))))
445 (defun gnus-copy-article-buffer (&optional article-buffer)
446 ;; make a copy of the article buffer with all text properties removed
447 ;; this copy is in the buffer gnus-article-copy.
448 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
449 ;; this buffer should be passed to all mail/news reply/post routines.
450 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
451 (let ((article-buffer (or article-buffer gnus-article-buffer))
453 (if (not (and (get-buffer article-buffer)
454 (gnus-buffer-exists-p article-buffer)))
455 (error "Can't find any article buffer")
457 (set-buffer article-buffer)
459 ;; Copy over the (displayed) article buffer, delete
460 ;; hidden text and remove text properties.
462 (let ((inhibit-read-only t))
463 (copy-to-buffer gnus-article-copy (point-min) (point-max))
464 (set-buffer gnus-article-copy)
465 (gnus-article-delete-text-of-type 'annotation)
466 (gnus-remove-text-with-property 'gnus-prev)
467 (gnus-remove-text-with-property 'gnus-next)
468 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
471 (format "%s" (buffer-string))
474 ;; Find the original headers.
475 (set-buffer gnus-original-article-buffer)
476 (goto-char (point-min))
477 (while (looking-at message-unix-mail-delimiter)
480 (setq end (or (search-forward "\n\n" nil t) (point)))
481 ;; Delete the headers from the displayed articles.
482 (set-buffer gnus-article-copy)
483 (delete-region (goto-char (point-min))
484 (or (search-forward "\n\n" nil t) (point-max)))
485 ;; Encode bitmap smileys to ordinary text.
486 (static-unless (featurep 'xemacs)
487 (when (featurep 'smiley-mule)
488 (smiley-encode-buffer)))
489 ;; Insert the original article headers.
490 (insert-buffer-substring gnus-original-article-buffer beg end)
491 (article-decode-encoded-words)))
494 (defun gnus-post-news (post &optional group header article-buffer yank subject
497 (gnus-copy-article-buffer))
498 (let ((gnus-article-reply article-buffer)
499 (add-to-list gnus-add-to-list))
500 (gnus-setup-message (cond (yank 'reply-yank)
501 (article-buffer 'reply)
503 (let* ((group (or group gnus-newsgroup-name))
505 to-address to-group mailing-list to-list
508 (setq to-address (gnus-group-find-parameter group 'to-address)
509 to-group (gnus-group-find-parameter group 'to-group)
510 to-list (gnus-group-find-parameter group 'to-list)
511 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
512 mailing-list (when gnus-mailing-list-groups
513 (string-match gnus-mailing-list-groups group))
514 group (gnus-group-real-name group)))
515 (if (or (and to-group
516 (gnus-news-group-p to-group))
519 (and (gnus-news-group-p
520 (or pgroup gnus-newsgroup-name)
521 (if header (mail-header-number header)
522 gnus-current-article))
528 (message-news (or to-group group))
529 (set-buffer gnus-article-copy)
530 (gnus-msg-treat-broken-reply-to)
531 (message-followup (if (or newsgroup-p force-news) nil to-group)))
535 (message-mail (or to-address to-list))
536 ;; Arrange for mail groups that have no `to-address' to
537 ;; get that when the user sends off the mail.
538 (when (and (not to-list)
541 (push (list 'gnus-inews-add-to-address pgroup)
542 message-send-actions)))
543 (set-buffer gnus-article-copy)
544 (gnus-msg-treat-broken-reply-to)
545 (message-wide-reply to-address)))
547 (gnus-inews-yank-articles yank))))))
549 (defun gnus-msg-treat-broken-reply-to ()
550 "Remove the Reply-to header iff broken-reply-to."
551 (when (gnus-group-find-parameter
552 gnus-newsgroup-name 'broken-reply-to)
554 (message-narrow-to-head)
555 (message-remove-header "reply-to"))))
557 (defun gnus-post-method (arg group &optional silent)
558 "Return the posting method based on GROUP and ARG.
559 If SILENT, don't prompt the user."
560 (let ((group-method (gnus-find-method-for-group group)))
562 ;; If the group-method is nil (which shouldn't happen) we use
563 ;; the default method.
565 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
566 gnus-select-method message-post-method))
567 ;; We want the inverse of the default
568 ((and arg (not (eq arg 0)))
569 (if (eq gnus-post-method 'active)
572 ;; We query the user for a post method.
574 (and gnus-post-method
575 (not (eq gnus-post-method 'current))
576 (listp (car gnus-post-method))))
578 ;; Collect all methods we know about.
580 (when (and gnus-post-method
581 (not (eq gnus-post-method 'current)))
582 (if (listp (car gnus-post-method))
584 (list gnus-post-method)))
585 gnus-secondary-select-methods
586 (mapcar 'cdr gnus-server-alist)
587 (mapcar 'car gnus-opened-servers)
588 (list gnus-select-method)
589 (list group-method)))
590 method-alist post-methods method)
591 ;; Weed out all mail methods.
593 (setq method (gnus-server-get-method "" (pop methods)))
594 (when (and (or (gnus-method-option-p method 'post)
595 (gnus-method-option-p method 'post-mail))
596 (not (member method post-methods)))
597 (push method post-methods)))
598 ;; Create a name-method alist.
602 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
607 (setq gnus-last-posting-server
609 gnus-last-posting-server)
610 ;; Just use the last value.
611 gnus-last-posting-server
613 "Posting method: " method-alist nil t
614 (cons (or gnus-last-posting-server "") 0))))
616 ;; Override normal method.
617 ((and (eq gnus-post-method 'current)
618 (not (eq (car group-method) 'nndraft))
619 (gnus-get-function group-method 'request-post t)
622 ((and gnus-post-method
623 (not (eq gnus-post-method 'current)))
625 ;; Use the normal select method.
626 (t gnus-select-method))))
630 (defun gnus-extended-version ()
631 "Stringified gnus version."
632 (concat gnus-product-name "/" gnus-version-number
634 gnus-original-product-name " v" gnus-original-version-number ")"
635 (if (zerop (string-to-number gnus-revision-number))
637 (concat " (revision " gnus-revision-number ")"))
640 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
641 "Return user-agent info.
642 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
643 `mime-edit-user-agent-value' exists, the return value will include it.
644 MAX-COLUMN the optional second argument if it is specified, the return value
645 will be folded up in the proper way."
646 (let ((user-agent (if (and include-mime-info
647 (boundp 'mime-edit-user-agent-value))
648 (concat (gnus-extended-version)
650 mime-edit-user-agent-value)
651 (gnus-extended-version))))
654 (unless (natnump max-column) (setq max-column 76))
656 (insert " " user-agent)
658 (while (re-search-forward "[\n\t ]+" nil t)
661 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
662 (while (eq ?\( (char-after (point)))
664 (skip-chars-forward " "))
665 (skip-chars-backward " ")
666 (if (> (current-column) max-column)
668 (if (or (not boundary) (eq ?\n (char-after boundary)))
670 (setq boundary (point))
677 (setq boundary (point))))
678 (buffer-substring 13 (point-max))))
683 ;;; Gnus Mail Functions
686 ;;; Mail reply commands of Gnus summary mode
688 (defun gnus-summary-reply (&optional yank wide)
689 "Start composing a reply mail to the current message.
690 If prefix argument YANK is non-nil, the original article is yanked
693 (list (and current-prefix-arg
694 (gnus-summary-work-articles 1))))
695 ;; Stripping headers should be specified with mail-yank-ignored-headers.
697 (gnus-summary-goto-subject (car yank)))
698 (let ((gnus-article-reply t))
699 (gnus-setup-message (if yank 'reply-yank 'reply)
700 (gnus-summary-select-article)
701 (set-buffer (gnus-copy-article-buffer))
702 (gnus-msg-treat-broken-reply-to)
703 (message-reply nil wide)
705 (gnus-inews-yank-articles yank)))))
707 (defun gnus-summary-reply-with-original (n &optional wide)
708 "Start composing a reply mail to the current message.
709 The original article will be yanked."
711 (gnus-summary-reply (gnus-summary-work-articles n) wide))
713 (defun gnus-summary-wide-reply (&optional yank)
714 "Start composing a wide reply mail to the current message.
715 If prefix argument YANK is non-nil, the original article is yanked
718 (list (and current-prefix-arg
719 (gnus-summary-work-articles 1))))
720 (gnus-summary-reply yank t))
722 (defun gnus-summary-wide-reply-with-original (n)
723 "Start composing a wide reply mail to the current message.
724 The original article will be yanked."
726 (gnus-summary-reply-with-original n t))
728 (defun gnus-summary-mail-forward (&optional full-headers post)
729 "Forward the current message to another user.
730 If FULL-HEADERS (the prefix), include full headers when forwarding."
732 (gnus-setup-message 'forward
733 (gnus-summary-select-article)
734 (let ((charset default-mime-charset))
735 (set-buffer gnus-original-article-buffer)
736 (make-local-variable 'default-mime-charset)
737 (setq default-mime-charset charset)
739 (let ((message-included-forward-headers
740 (if full-headers "" message-included-forward-headers)))
741 (message-forward post))))
743 ;;; XXX: generate Subject and ``Topics''?
744 (defun gnus-summary-mail-digest (&optional n post)
745 "Digests and forwards all articles in this series."
747 (let ((subject "Digested Articles")
748 (articles (gnus-summary-work-articles n))
750 (gnus-setup-message 'forward
751 (gnus-summary-select-article)
752 (if post (message-news nil subject) (message-mail nil subject))
753 (when (and message-use-multi-frames (cdr articles))
754 (setq frame (window-frame (get-buffer-window (current-buffer)))))
756 (while (setq article (pop articles))
757 (save-window-excursion
758 (set-buffer gnus-summary-buffer)
759 (gnus-summary-select-article nil nil nil article)
760 (gnus-summary-remove-process-mark article))
762 (select-frame frame))
763 (insert (mime-make-tag "message" "rfc822") "\n")
764 (insert-buffer-substring gnus-original-article-buffer))
767 (mime-edit-enclose-digest-region (point)(mark t)))))
769 (defun gnus-summary-post-digest (&optional n)
770 "Digest and forwards all articles in this series to a newsgroup."
772 (gnus-summary-mail-digest n t))
774 (defun gnus-summary-resend-message (address n)
775 "Resend the current article to ADDRESS."
776 (interactive "sResend message(s) to: \nP")
777 (let ((articles (gnus-summary-work-articles n))
779 (while (setq article (pop articles))
780 (gnus-summary-select-article nil nil nil article)
782 (set-buffer gnus-original-article-buffer)
783 (message-resend address)))))
785 (defun gnus-summary-post-forward (&optional full-headers)
786 "Forward the current article to a newsgroup.
787 If FULL-HEADERS (the prefix), include full headers when forwarding."
789 (gnus-summary-mail-forward full-headers t))
791 (defvar gnus-nastygram-message
792 "The following article was inappropriately posted to %s.\n\n"
793 "Format string to insert in nastygrams.
794 The current group name will be inserted at \"%s\".")
796 (defun gnus-summary-mail-nastygram (n)
797 "Send a nastygram to the author of the current article."
799 (when (or gnus-expert-user
801 "Really send a nastygram to the author of the current article? "))
802 (let ((group gnus-newsgroup-name))
803 (gnus-summary-reply-with-original n)
804 (set-buffer gnus-message-buffer)
806 (insert (format gnus-nastygram-message group))
807 (message-send-and-exit))))
809 (defun gnus-summary-mail-crosspost-complaint (n)
810 "Send a complaint about crossposting to the current article(s)."
812 (let ((articles (gnus-summary-work-articles n))
814 (while (setq article (pop articles))
815 (set-buffer gnus-summary-buffer)
816 (gnus-summary-goto-subject article)
817 (let ((group (gnus-group-real-name gnus-newsgroup-name))
818 newsgroups followup-to)
819 (gnus-summary-select-article)
820 (set-buffer gnus-original-article-buffer)
821 (if (and (<= (length (message-tokenize-header
823 (mail-fetch-field "newsgroups"))
826 (or (not (setq followup-to (mail-fetch-field "followup-to")))
827 (not (member group (message-tokenize-header
828 followup-to ", ")))))
830 (gnus-message 1 "Followup-to restricted")
831 (gnus-message 1 "Not a crossposted article"))
832 (set-buffer gnus-summary-buffer)
833 (gnus-summary-reply-with-original 1)
834 (set-buffer gnus-message-buffer)
836 (insert (format gnus-crosspost-complaint newsgroups group))
837 (message-goto-subject)
838 (re-search-forward " *$")
839 (replace-match " (crosspost notification)" t t)
840 (gnus-deactivate-mark)
841 (when (gnus-y-or-n-p "Send this complaint? ")
842 (message-send-and-exit)))))))
844 (defun gnus-summary-mail-other-window ()
845 "Compose mail in other window."
847 (gnus-setup-message 'message
850 (defun gnus-mail-parse-comma-list ()
853 (skip-chars-forward " ")
856 (skip-chars-forward "^,")
861 (narrow-to-region beg (point))
864 (while (search-forward "\"" nil t)
868 (skip-chars-forward ",")
869 (skip-chars-forward "^,"))
870 (skip-chars-backward " ")
871 (push (buffer-substring beg (point))
873 (skip-chars-forward "^,")
874 (skip-chars-forward ", "))
877 (defun gnus-inews-add-to-address (group)
878 (let ((to-address (mail-fetch-field "to")))
879 (when (and to-address
881 ;; This mail group doesn't have a `to-list', so we add one
884 (format "Do you want to add this as `to-list': %s " to-address))
885 (gnus-group-add-parameter group (cons 'to-list to-address))))))
887 (defun gnus-put-message ()
888 "Put the current message in some group and return to Gnus."
890 (let ((reply gnus-article-reply)
891 (winconf gnus-prev-winconf)
892 (group gnus-newsgroup-name))
894 (or (and group (not (gnus-group-read-only-p group)))
895 (setq group (read-string "Put in group: " nil
896 (gnus-writable-groups))))
897 (when (gnus-gethash group gnus-newsrc-hashtb)
898 (error "No such group: %s" group))
903 (message-narrow-to-headers)
904 (let (gnus-deletable-headers)
906 (message-generate-headers message-required-news-headers)
907 (message-generate-headers message-required-mail-headers)))
908 (goto-char (point-max))
909 (insert "Gcc: " group "\n")
914 (when (get-buffer gnus-group-buffer)
915 (when (gnus-buffer-exists-p (car-safe reply))
916 (set-buffer (car reply))
918 (gnus-summary-mark-article-as-replied
921 (set-window-configuration winconf)))))
923 (defun gnus-article-mail (yank)
924 "Send a reply to the address near point.
925 If YANK is non-nil, include the original article."
929 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
930 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
932 (message-reply address)
934 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
936 (defvar nntp-server-type)
938 "Send a bug report to the Gnus maintainers."
940 (unless (gnus-alive-p)
941 (error "Gnus has been shut down"))
942 (gnus-setup-message 'bug
943 (delete-other-windows)
944 (when gnus-bug-create-help-buffer
945 (switch-to-buffer "*Gnus Help Bug*")
947 (insert gnus-bug-message)
948 (goto-char (point-min)))
949 (message-pop-to-buffer "*Gnus Bug*")
950 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
951 (when gnus-bug-create-help-buffer
952 (push `(gnus-bug-kill-buffer) message-send-actions))
953 (goto-char (point-min))
954 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
956 (insert gnus-product-name " " gnus-version-number
957 " (r" gnus-revision-number ") "
958 "based on " gnus-original-product-name " v"
959 gnus-original-version-number "\n"
960 (emacs-version) "\n")
961 (when (and (boundp 'nntp-server-type)
962 (stringp nntp-server-type))
963 (insert nntp-server-type))
964 (insert "\n\n\n\n\n")
965 (let (mime-content-types)
966 (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
967 (insert (with-temp-buffer
970 (goto-char (point-min))
971 (search-forward "Subject: " nil t)
974 (defun gnus-bug-kill-buffer ()
975 (when (get-buffer "*Gnus Help Bug*")
976 (kill-buffer "*Gnus Help Bug*")))
979 "Attempts to go through the Gnus source file and report what variables have been changed.
980 The source file has to be in the Emacs load path."
982 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
983 "gnus-art.el" "gnus-start.el" "gnus-async.el"
984 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
985 "nnmail.el" "message.el"))
988 (gnus-message 4 "Please wait while we snoop your variables...")
990 ;; Go through all the files looking for non-default values for variables.
992 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
995 (when (and (setq file (locate-library (pop files)))
996 (file-exists-p file))
997 (insert-file-contents file)
998 (goto-char (point-min))
999 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1000 (gnus-message 4 "Malformed sources in file %s" file)
1001 (narrow-to-region (point-min) (point))
1002 (goto-char (point-min))
1003 (while (setq expr (ignore-errors (read (current-buffer))))
1005 (and (or (eq (car expr) 'defvar)
1006 (eq (car expr) 'defcustom))
1007 (stringp (nth 3 expr))
1008 (or (not (boundp (nth 1 expr)))
1009 (not (equal (eval (nth 2 expr))
1010 (symbol-value (nth 1 expr)))))
1011 (push (nth 1 expr) olist)))))))
1012 (kill-buffer (current-buffer)))
1013 (when (setq olist (nreverse olist))
1014 (insert "------------------ Environment follows ------------------\n\n"))
1016 (if (boundp (car olist))
1018 (pp `(setq ,(car olist)
1019 ,(if (or (consp (setq sym (symbol-value (car olist))))
1021 (not (or (eq sym nil)
1023 (list 'quote (symbol-value (car olist)))
1024 (symbol-value (car olist))))
1027 (format "(setq %s 'whatever)\n" (car olist))))
1028 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1029 (setq olist (cdr olist)))
1031 ;; Remove any control chars - they seem to cause trouble for some
1032 ;; mailers. (Byte-compiled output from the stuff above.)
1034 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1035 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1038 ;;; Treatment of rejected articles.
1041 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1042 "Re-mail the current message.
1043 This only makes sense if the current message is a bounce message than
1044 contains some mail you have written which has been bounced back to
1046 If FETCH, try to fetch the article that this is a reply to, if indeed
1049 (gnus-summary-select-article t)
1050 (set-buffer gnus-original-article-buffer)
1051 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1052 (gnus-setup-message 'compose-bounce
1053 (let* ((references (mail-fetch-field "references"))
1054 (parent (and references (gnus-parent-id references))))
1056 ;; If there are references, we fetch the article we answered to.
1058 (gnus-summary-refer-article parent)
1059 (gnus-summary-show-all-headers))))))
1063 ;; Do Gcc handling, which copied the message over to some group.
1064 (defun gnus-inews-do-gcc (&optional gcc)
1066 (when (gnus-alive-p)
1069 (message-narrow-to-headers)
1070 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1071 (coding-system-for-write 'raw-text)
1072 (output-coding-system 'raw-text)
1073 groups group method)
1075 (message-remove-header "gcc")
1077 (setq groups (message-tokenize-header gcc " ,"))
1078 ;; Copy the article over to some group(s).
1079 (while (setq group (pop groups))
1082 (cond ((and (null (gnus-get-info group))
1083 (eq (car gnus-message-archive-method)
1085 (gnus-server-to-method
1086 (gnus-group-method group)))))
1087 ;; If the group doesn't exist, we assume
1088 ;; it's an archive group...
1089 gnus-message-archive-method)
1091 ((gnus-info-method (gnus-get-info group))
1092 (gnus-info-method (gnus-get-info group)))
1094 (t (gnus-group-method group)))))
1095 (gnus-check-server method)
1096 (unless (gnus-request-group group t method)
1097 (gnus-request-create-group group method))
1099 (nnheader-set-temp-buffer " *acc*")
1100 (insert-buffer-substring message-encoding-buffer)
1101 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1102 (goto-char (point-min))
1103 (when (re-search-forward
1104 (concat "^" (regexp-quote mail-header-separator) "$")
1106 (replace-match "" t t ))
1107 (unless (gnus-request-accept-article group method t t)
1108 (gnus-message 1 "Couldn't store article in group %s: %s"
1109 group (gnus-status-message method))
1111 (kill-buffer (current-buffer))))))))))
1113 (defun gnus-inews-insert-gcc ()
1114 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1117 (message-narrow-to-headers)
1118 (let* ((group gnus-outgoing-message-group)
1120 ((gnus-functionp group)
1122 ((or (stringp group) (list group))
1126 (if (stringp gcc) gcc
1127 (mapconcat 'identity gcc " "))
1130 (defun gnus-inews-insert-archive-gcc (&optional group)
1131 "Insert the Gcc to say where the article is to be archived."
1132 (let* ((var gnus-message-archive-group)
1133 (group (or group gnus-newsgroup-name ""))
1135 (and gnus-newsgroup-name
1136 (gnus-group-find-parameter
1137 gnus-newsgroup-name 'gcc-self)))
1141 ((null gnus-message-archive-method)
1145 ;; Just a single group.
1148 ;; We don't want this.
1150 ((and (listp var) (stringp (car var)))
1151 ;; A list of groups.
1153 ((gnus-functionp var)
1155 (funcall var group))
1157 ;; An alist of regexps/functions/forms.
1162 ((stringp (caar var))
1164 (when (string-match (caar var) group)
1166 ((gnus-functionp (car var))
1168 (funcall (car var) group))
1170 (eval (car var)))))))
1171 (setq var (cdr var)))
1174 (when (or groups gcc-self-val)
1175 (when (stringp groups)
1176 (setq groups (list groups)))
1179 (message-narrow-to-headers)
1180 (goto-char (point-max))
1183 ;; Use the `gcc-self' param value instead.
1186 (if (stringp gcc-self-val)
1189 (if (not (eq gcc-self-val 'none))
1194 ;; Use the list of groups.
1195 (while (setq name (pop groups))
1196 (insert (if (string-match ":" name)
1198 (gnus-group-prefixed-name
1199 name gnus-message-archive-method)))
1206 (defun gnus-configure-posting-styles ()
1207 "Configure posting styles according to `gnus-posting-styles'."
1208 (unless gnus-inhibit-posting-styles
1209 (let ((group (or gnus-newsgroup-name ""))
1210 (styles gnus-posting-styles)
1211 style match variable attribute value v results
1212 filep name address element)
1213 ;; If the group has a posting-style parameter, add it at the end with a
1214 ;; regexp matching everything, to be sure it takes precedence over all
1216 (when gnus-newsgroup-name
1217 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1219 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1220 ;; Go through all styles and look for matches.
1221 (dolist (style styles)
1222 (setq match (pop style))
1225 ;; Regexp string match on the group name.
1226 (string-match match group))
1227 ((or (symbolp match)
1228 (gnus-functionp match))
1230 ((gnus-functionp match)
1231 ;; Function to be called.
1234 ;; Variable to be checked.
1235 (symbol-value match))))
1237 ;; This is a form to be evaled.
1239 ;; We have a match, so we set the variables.
1240 (dolist (attribute style)
1241 (setq element (pop attribute)
1246 ((eq (car attribute) ':file)
1249 ((eq (car attribute) :value)
1253 ;; We get the value.
1258 ((or (symbolp value)
1259 (gnus-functionp value))
1260 (cond ((gnus-functionp value)
1263 (symbol-value value))))
1266 ;; Translate obsolescent value.
1267 (when (eq element 'signature-file)
1268 (setq element 'signature
1270 ;; Get the contents of file elems.
1272 (setq v (with-temp-buffer
1273 (insert-file-contents v)
1275 (setq results (delq (assoc element results) results))
1276 (push (cons element v) results))))
1277 ;; Now we have all the styles, so we insert them.
1278 (setq name (assq 'name results)
1279 address (assq 'address results))
1280 (setq results (delq name (delq address results)))
1281 (make-local-variable 'message-setup-hook)
1282 (dolist (result results)
1284 (add-hook 'message-setup-hook
1286 ((eq 'eval (car result))
1288 ((eq 'body (car result))
1292 (insert ,(cdr result)))))
1293 ((eq 'signature (car result))
1294 (set (make-local-variable 'message-signature) nil)
1295 (set (make-local-variable 'message-signature-file) nil)
1298 (let ((message-signature ,(cdr result)))
1299 (message-insert-signature)))))
1302 (if (symbolp (car result))
1303 (capitalize (symbol-name (car result)))
1307 (message-remove-header ,header)
1309 (insert ,header ": " ,(cdr result) "\n")))))))))
1310 (when (or name address)
1311 (add-hook 'message-setup-hook
1313 (let ((user-full-name ,(or (cdr name) user-full-name))
1315 ,(or (cdr address) user-mail-address)))
1317 (message-remove-header "From")
1319 (insert "From: " (message-make-from) "\n")))))))))
1322 ;;; @ for MIME Edit mode
1325 (defun gnus-maybe-setup-default-charset ()
1327 (and (boundp 'gnus-summary-buffer)
1328 (buffer-live-p gnus-summary-buffer)
1330 (set-buffer gnus-summary-buffer)
1331 default-mime-charset))))
1334 (make-local-variable 'default-mime-charset)
1335 (setq default-mime-charset charset)
1339 ;;; @ for MIME view mode
1342 (defun gnus-following-method (buf)
1343 (gnus-setup-message 'reply-yank
1345 (if (message-news-p)
1347 (message-reply nil 'wide))
1348 (let ((message-reply-buffer buf))
1349 (message-yank-original))
1350 (message-goto-body))
1354 ;;; Allow redefinition of functions.
1360 ;;; gnus-msg.el ends here