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)
113 (message-this-is-news iso-8859-1))
114 "Alist of regexps (to match group names) and default charsets to be unencoded when posting."
115 :type '(repeat (list (regexp :tag "Group")
116 (symbol :tag "Charset")))
117 :group 'gnus-charset)
119 ;;; Internal variables.
121 (defvar gnus-inhibit-posting-styles nil
122 "Inhibit the use of posting styles.")
124 (defvar gnus-message-buffer "*Mail Gnus*")
125 (defvar gnus-article-copy nil)
126 (defvar gnus-last-posting-server nil)
127 (defvar gnus-message-group-art nil)
129 (defconst gnus-bug-message
130 (format "Sending a bug report to the Gnus Towers.
131 ========================================
133 This gnus is the %s%s.
134 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
135 Developers. (the addresses below are mailing list addresses)
137 ========================================
139 The buffer below is a mail buffer. When you press `C-c C-c', it will
140 be sent to the Gnus Bug Exterminators.
142 The thing near the bottom of the buffer is how the environment
143 settings will be included in the mail. Please do not delete that.
144 They will tell the Bug People what your environment is, so that it
145 will be easier to locate the bugs.
147 If you have found a bug that makes Emacs go \"beep\", set
148 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
149 and include the backtrace in your bug report.
151 Please describe the bug in annoying, painstaking detail.
153 Thank you for your help in stamping out bugs.
156 (if (string= gnus-product-name "Semi-gnus")
158 ", a modified version of Semi-gnus")))
161 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
162 (autoload 'news-setup "rnewspost")
163 (autoload 'news-reply-mode "rnewspost")
164 (autoload 'rmail-dont-reply-to "mail-utils")
165 (autoload 'rmail-output "rmailout"))
169 ;;; Gnus Posting Functions
172 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
173 "p" gnus-summary-post-news
174 "f" gnus-summary-followup
175 "F" gnus-summary-followup-with-original
176 "c" gnus-summary-cancel-article
177 "s" gnus-summary-supersede-article
178 "r" gnus-summary-reply
179 "R" gnus-summary-reply-with-original
180 "w" gnus-summary-wide-reply
181 "W" gnus-summary-wide-reply-with-original
182 "n" gnus-summary-followup-to-mail
183 "N" gnus-summary-followup-to-mail-with-original
184 "m" gnus-summary-mail-other-window
185 "u" gnus-uu-post-news
186 "\M-c" gnus-summary-mail-crosspost-complaint
187 "om" gnus-summary-mail-forward
188 "op" gnus-summary-post-forward
189 "Om" gnus-summary-mail-digest
190 "Op" gnus-summary-post-digest)
192 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
193 "b" gnus-summary-resend-bounced-mail
194 ;; "c" gnus-summary-send-draft
195 "r" gnus-summary-resend-message)
197 ;;; Internal functions.
199 (defvar gnus-article-reply nil)
200 (defmacro gnus-setup-message (config &rest forms)
201 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
202 (buffer (make-symbol "gnus-setup-message-buffer"))
203 (article (make-symbol "gnus-setup-message-article"))
204 (group (make-symbol "gnus-setup-message-group")))
205 `(let ((,winconf (current-window-configuration))
206 (,buffer (buffer-name (current-buffer)))
207 (,article (and gnus-article-reply (gnus-summary-article-number)))
208 (,group gnus-newsgroup-name)
209 (message-header-setup-hook
210 (copy-sequence message-header-setup-hook))
211 (message-mode-hook (copy-sequence message-mode-hook))
212 (message-startup-parameter-alist
213 '((reply-buffer . gnus-copy-article-buffer)
214 (original-buffer . gnus-original-article-buffer)
215 (user-agent . Gnus))))
216 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
217 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
218 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
222 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
223 (setq gnus-message-buffer (current-buffer))
224 (set (make-local-variable 'gnus-message-group-art)
225 (cons ,group ,article))
226 (set (make-local-variable 'gnus-newsgroup-name) ,group)
227 (set (make-local-variable 'message-posting-charset)
228 (gnus-setup-posting-charset ,group))
229 (gnus-run-hooks 'gnus-message-setup-hook))
231 (gnus-configure-windows ,config t)
232 (set-buffer-modified-p nil))))
234 (defun gnus-setup-posting-charset (group)
235 (let ((alist gnus-group-posting-charset-alist)
236 (group (or group ""))
240 (while (setq elem (pop alist))
241 (when (or (and (stringp (car elem))
242 (string-match (car elem) group))
243 (and (gnus-functionp (car elem))
244 (funcall (car elem) group))
245 (and (symbolp (car elem))
246 (symbol-value (car elem))))
247 (throw 'found (cadr elem))))))))
249 (defun gnus-inews-add-send-actions (winconf buffer article)
250 (make-local-hook 'message-sent-hook)
251 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
252 (setq message-post-method
254 (gnus-post-method arg ,gnus-newsgroup-name)))
255 (setq message-user-agent (gnus-extended-version))
256 (when (not message-use-multi-frames)
258 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
260 `(when (gnus-buffer-exists-p ,buffer)
264 `(gnus-summary-mark-article-as-replied ,article))))
267 (put 'gnus-setup-message 'lisp-indent-function 1)
268 (put 'gnus-setup-message 'edebug-form-spec '(form body))
270 ;;; Post news commands of Gnus group mode and summary mode
272 (defun gnus-group-mail (&optional arg)
273 "Start composing a mail.
274 If ARG, use the group under the point to find a posting style.
275 If ARG is 1, prompt for a group name to find the posting style."
277 ;; We can't `let' gnus-newsgroup-name here, since that leads
278 ;; to local variables leaking.
279 (let ((group gnus-newsgroup-name)
280 (buffer (current-buffer)))
283 (setq gnus-newsgroup-name
285 (if (= 1 (prefix-numeric-value arg))
286 (completing-read "Use posting style of group: "
287 gnus-active-hashtb nil
288 (gnus-read-active-file-p))
289 (gnus-group-group-name))
291 (gnus-setup-message 'message (message-mail)))
294 (setq gnus-newsgroup-name group)))))
296 (defun gnus-group-post-news (&optional arg)
297 "Start composing a news message.
298 If ARG, post to the group under point.
299 If ARG is 1, prompt for a group name."
301 ;; Bind this variable here to make message mode hooks work ok.
302 (let ((gnus-newsgroup-name
304 (if (= 1 (prefix-numeric-value arg))
305 (completing-read "Newsgroup: " gnus-active-hashtb nil
306 (gnus-read-active-file-p))
307 (gnus-group-group-name))
309 (gnus-post-news 'post gnus-newsgroup-name)))
311 (defun gnus-summary-post-news ()
312 "Start composing a news message."
314 (gnus-post-news 'post gnus-newsgroup-name))
316 (defun gnus-summary-followup (yank &optional force-news)
317 "Compose a followup to an article.
318 If prefix argument YANK is non-nil, original article is yanked automatically."
320 (list (and current-prefix-arg
321 (gnus-summary-work-articles 1))))
323 (gnus-summary-goto-subject (car yank)))
324 (save-window-excursion
325 (gnus-summary-select-article))
326 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
327 (gnus-newsgroup-name gnus-newsgroup-name))
329 (gnus-post-news nil gnus-newsgroup-name
330 headers gnus-article-buffer
331 yank nil force-news)))
333 (defun gnus-summary-followup-with-original (n &optional force-news)
334 "Compose a followup to an article and include the original article."
336 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
338 (defun gnus-summary-followup-to-mail (&optional arg)
339 "Followup to the current mail message via news."
341 (list (and current-prefix-arg
342 (gnus-summary-work-articles 1))))
343 (gnus-summary-followup arg t))
345 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
346 "Followup to the current mail message via news."
348 (gnus-summary-followup (gnus-summary-work-articles arg) t))
350 (defun gnus-inews-yank-articles (articles)
351 (let* ((more-than-one (cdr articles))
352 (frame (when (and message-use-multi-frames more-than-one)
353 (window-frame (get-buffer-window (current-buffer)))))
356 (while (setq article (pop articles))
357 (save-window-excursion
358 (set-buffer gnus-summary-buffer)
359 (gnus-summary-select-article nil nil nil article)
360 (gnus-summary-remove-process-mark article))
362 (select-frame frame))
364 ;; Gathering references.
366 (setq refs (message-list-references
368 (mail-header-references gnus-current-headers)
369 (mail-header-message-id gnus-current-headers))))
371 (gnus-copy-article-buffer)
372 (let ((message-reply-buffer gnus-article-copy)
373 (message-reply-headers gnus-current-headers))
374 (message-yank-original)
375 (setq beg (or beg (mark t))))
380 ;; Replace with the gathered references.
384 (message-narrow-to-headers)
385 (let ((case-fold-search t))
386 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
388 (goto-char (point-max))))
390 (list (or (assq 'References message-header-format-alist)
391 '(References . message-shorten-references)))
392 (list (cons 'References
393 (mapconcat 'identity (nreverse refs) " "))))
394 (backward-delete-char 1))
400 (defun gnus-summary-cancel-article (&optional n symp)
401 "Cancel an article you posted.
402 Uses the process-prefix convention. If given the symbolic
403 prefix `a', cancel using the standard posting method; if not
404 post using the current select method."
405 (interactive (gnus-interactive "P\ny"))
406 (let ((articles (gnus-summary-work-articles n))
409 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
411 (while (setq article (pop articles))
412 (when (gnus-summary-select-article t nil nil article)
413 (when (gnus-eval-in-buffer-window gnus-article-buffer
415 (set-buffer gnus-original-article-buffer)
416 (message-cancel-news)))
417 (gnus-summary-mark-as-read article gnus-canceled-mark)
418 (gnus-cache-remove-article 1))
419 (gnus-article-hide-headers-if-wanted))
420 (gnus-summary-remove-process-mark article))))
422 (defun gnus-summary-supersede-article ()
423 "Compose an article that will supersede a previous article.
424 This is done simply by taking the old article and adding a Supersedes
425 header line with the old Message-ID."
427 (let ((article (gnus-summary-article-number))
428 (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
429 (gnus-setup-message 'reply-yank
430 (gnus-summary-select-article t)
431 (set-buffer gnus-original-article-buffer)
435 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
437 (set-buffer ,gnus-summary-buffer)
438 (gnus-cache-possibly-remove-article ,article nil nil nil t)
439 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
440 message-send-actions))))
444 (defun gnus-copy-article-buffer (&optional article-buffer)
445 ;; make a copy of the article buffer with all text properties removed
446 ;; this copy is in the buffer gnus-article-copy.
447 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
448 ;; this buffer should be passed to all mail/news reply/post routines.
449 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
450 (let ((article-buffer (or article-buffer gnus-article-buffer))
452 (if (not (and (get-buffer article-buffer)
453 (gnus-buffer-exists-p article-buffer)))
454 (error "Can't find any article buffer")
456 (set-buffer article-buffer)
458 ;; Copy over the (displayed) article buffer, delete
459 ;; hidden text and remove text properties.
461 (let ((inhibit-read-only t))
462 (copy-to-buffer gnus-article-copy (point-min) (point-max))
463 (set-buffer gnus-article-copy)
464 (gnus-article-delete-text-of-type 'annotation)
465 (gnus-remove-text-with-property 'gnus-prev)
466 (gnus-remove-text-with-property 'gnus-next)
467 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
470 (format "%s" (buffer-string))
473 ;; Find the original headers.
474 (set-buffer gnus-original-article-buffer)
475 (goto-char (point-min))
476 (while (looking-at message-unix-mail-delimiter)
479 (setq end (or (search-forward "\n\n" nil t) (point)))
480 ;; Delete the headers from the displayed articles.
481 (set-buffer gnus-article-copy)
482 (delete-region (goto-char (point-min))
483 (or (search-forward "\n\n" nil t) (point-max)))
484 ;; Encode bitmap smileys to ordinary text.
485 (static-unless (featurep 'xemacs)
486 (when (featurep 'smiley-mule)
487 (smiley-encode-buffer)))
488 ;; Insert the original article headers.
489 (insert-buffer-substring gnus-original-article-buffer beg end)
490 (article-decode-encoded-words)))
493 (defun gnus-post-news (post &optional group header article-buffer yank subject
496 (gnus-copy-article-buffer))
497 (let ((gnus-article-reply article-buffer)
498 (add-to-list gnus-add-to-list))
499 (gnus-setup-message (cond (yank 'reply-yank)
500 (article-buffer 'reply)
502 (let* ((group (or group gnus-newsgroup-name))
504 to-address to-group mailing-list to-list
507 (setq to-address (gnus-group-find-parameter group 'to-address)
508 to-group (gnus-group-find-parameter group 'to-group)
509 to-list (gnus-group-find-parameter group 'to-list)
510 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
511 mailing-list (when gnus-mailing-list-groups
512 (string-match gnus-mailing-list-groups group))
513 group (gnus-group-real-name group)))
514 (if (or (and to-group
515 (gnus-news-group-p to-group))
518 (and (gnus-news-group-p
519 (or pgroup gnus-newsgroup-name)
520 (if header (mail-header-number header)
521 gnus-current-article))
527 (message-news (or to-group group))
528 (set-buffer gnus-article-copy)
529 (gnus-msg-treat-broken-reply-to)
530 (message-followup (if (or newsgroup-p force-news) nil to-group)))
534 (message-mail (or to-address to-list))
535 ;; Arrange for mail groups that have no `to-address' to
536 ;; get that when the user sends off the mail.
537 (when (and (not to-list)
540 (push (list 'gnus-inews-add-to-address pgroup)
541 message-send-actions)))
542 (set-buffer gnus-article-copy)
543 (gnus-msg-treat-broken-reply-to)
544 (message-wide-reply to-address)))
546 (gnus-inews-yank-articles yank))))))
548 (defun gnus-msg-treat-broken-reply-to ()
549 "Remove the Reply-to header iff broken-reply-to."
550 (when (gnus-group-find-parameter
551 gnus-newsgroup-name 'broken-reply-to)
553 (message-narrow-to-head)
554 (message-remove-header "reply-to"))))
556 (defun gnus-post-method (arg group &optional silent)
557 "Return the posting method based on GROUP and ARG.
558 If SILENT, don't prompt the user."
559 (let ((group-method (gnus-find-method-for-group group)))
561 ;; If the group-method is nil (which shouldn't happen) we use
562 ;; the default method.
564 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
565 gnus-select-method message-post-method))
566 ;; We want the inverse of the default
567 ((and arg (not (eq arg 0)))
568 (if (eq gnus-post-method 'active)
571 ;; We query the user for a post method.
573 (and gnus-post-method
574 (not (eq gnus-post-method 'current))
575 (listp (car gnus-post-method))))
577 ;; Collect all methods we know about.
579 (when (and gnus-post-method
580 (not (eq gnus-post-method 'current)))
581 (if (listp (car gnus-post-method))
583 (list gnus-post-method)))
584 gnus-secondary-select-methods
585 (mapcar 'cdr gnus-server-alist)
586 (mapcar 'car gnus-opened-servers)
587 (list gnus-select-method)
588 (list group-method)))
589 method-alist post-methods method)
590 ;; Weed out all mail methods.
592 (setq method (gnus-server-get-method "" (pop methods)))
593 (when (and (or (gnus-method-option-p method 'post)
594 (gnus-method-option-p method 'post-mail))
595 (not (member method post-methods)))
596 (push method post-methods)))
597 ;; Create a name-method alist.
601 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
606 (setq gnus-last-posting-server
608 gnus-last-posting-server)
609 ;; Just use the last value.
610 gnus-last-posting-server
612 "Posting method: " method-alist nil t
613 (cons (or gnus-last-posting-server "") 0))))
615 ;; Override normal method.
616 ((and (eq gnus-post-method 'current)
617 (not (eq (car group-method) 'nndraft))
620 ((and gnus-post-method
621 (not (eq gnus-post-method 'current)))
623 ;; Use the normal select method.
624 (t gnus-select-method))))
628 (defun gnus-extended-version ()
629 "Stringified gnus version."
630 (concat gnus-product-name "/" gnus-version-number
632 gnus-original-product-name " v" gnus-original-version-number ")"
633 (if (zerop (string-to-number gnus-revision-number))
635 (concat " (revision " gnus-revision-number ")"))
638 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
639 "Return user-agent info.
640 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
641 `mime-edit-user-agent-value' exists, the return value will include it.
642 MAX-COLUMN the optional second argument if it is specified, the return value
643 will be folded up in the proper way."
644 (let ((user-agent (if (and include-mime-info
645 (boundp 'mime-edit-user-agent-value))
646 (concat (gnus-extended-version)
648 mime-edit-user-agent-value)
649 (gnus-extended-version))))
652 (unless (natnump max-column) (setq max-column 76))
654 (insert " " user-agent)
656 (while (re-search-forward "[\n\t ]+" nil t)
659 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
660 (while (eq ?\( (char-after (point)))
662 (skip-chars-forward " "))
663 (skip-chars-backward " ")
664 (if (> (current-column) max-column)
666 (if (or (not boundary) (eq ?\n (char-after boundary)))
668 (setq boundary (point))
675 (setq boundary (point))))
676 (buffer-substring 13 (point-max))))
681 ;;; Gnus Mail Functions
684 ;;; Mail reply commands of Gnus summary mode
686 (defun gnus-summary-reply (&optional yank wide)
687 "Start composing a reply mail to the current message.
688 If prefix argument YANK is non-nil, the original article is yanked
691 (list (and current-prefix-arg
692 (gnus-summary-work-articles 1))))
693 ;; Stripping headers should be specified with mail-yank-ignored-headers.
695 (gnus-summary-goto-subject (car yank)))
696 (let ((gnus-article-reply t))
697 (gnus-setup-message (if yank 'reply-yank 'reply)
698 (gnus-summary-select-article)
699 (set-buffer (gnus-copy-article-buffer))
700 (gnus-msg-treat-broken-reply-to)
701 (message-reply nil wide)
703 (gnus-inews-yank-articles yank)))))
705 (defun gnus-summary-reply-with-original (n &optional wide)
706 "Start composing a reply mail to the current message.
707 The original article will be yanked."
709 (gnus-summary-reply (gnus-summary-work-articles n) wide))
711 (defun gnus-summary-wide-reply (&optional yank)
712 "Start composing a wide reply mail to the current message.
713 If prefix argument YANK is non-nil, the original article is yanked
716 (list (and current-prefix-arg
717 (gnus-summary-work-articles 1))))
718 (gnus-summary-reply yank t))
720 (defun gnus-summary-wide-reply-with-original (n)
721 "Start composing a wide reply mail to the current message.
722 The original article will be yanked."
724 (gnus-summary-reply-with-original n t))
726 (defun gnus-summary-mail-forward (&optional full-headers post)
727 "Forward the current message to another user.
728 If FULL-HEADERS (the prefix), include full headers when forwarding."
730 (gnus-setup-message 'forward
731 (gnus-summary-select-article)
732 (let ((charset default-mime-charset))
733 (set-buffer gnus-original-article-buffer)
734 (make-local-variable 'default-mime-charset)
735 (setq default-mime-charset charset)
737 (let ((message-included-forward-headers
738 (if full-headers "" message-included-forward-headers)))
739 (message-forward post))))
741 ;;; XXX: generate Subject and ``Topics''?
742 (defun gnus-summary-mail-digest (&optional n post)
743 "Digests and forwards all articles in this series."
745 (let ((subject "Digested Articles")
746 (articles (gnus-summary-work-articles n))
748 (gnus-setup-message 'forward
749 (gnus-summary-select-article)
750 (if post (message-news nil subject) (message-mail nil subject))
751 (when (and message-use-multi-frames (cdr articles))
752 (setq frame (window-frame (get-buffer-window (current-buffer)))))
754 (while (setq article (pop articles))
755 (save-window-excursion
756 (set-buffer gnus-summary-buffer)
757 (gnus-summary-select-article nil nil nil article)
758 (gnus-summary-remove-process-mark article))
760 (select-frame frame))
761 (insert (mime-make-tag "message" "rfc822") "\n")
762 (insert-buffer-substring gnus-original-article-buffer))
765 (mime-edit-enclose-digest-region (point)(mark t)))))
767 (defun gnus-summary-post-digest (&optional n)
768 "Digest and forwards all articles in this series to a newsgroup."
770 (gnus-summary-mail-digest n t))
772 (defun gnus-summary-resend-message (address n)
773 "Resend the current article to ADDRESS."
774 (interactive "sResend message(s) to: \nP")
775 (let ((articles (gnus-summary-work-articles n))
777 (while (setq article (pop articles))
778 (gnus-summary-select-article nil nil nil article)
780 (set-buffer gnus-original-article-buffer)
781 (message-resend address)))))
783 (defun gnus-summary-post-forward (&optional full-headers)
784 "Forward the current article to a newsgroup.
785 If FULL-HEADERS (the prefix), include full headers when forwarding."
787 (gnus-summary-mail-forward full-headers t))
789 (defvar gnus-nastygram-message
790 "The following article was inappropriately posted to %s.\n\n"
791 "Format string to insert in nastygrams.
792 The current group name will be inserted at \"%s\".")
794 (defun gnus-summary-mail-nastygram (n)
795 "Send a nastygram to the author of the current article."
797 (when (or gnus-expert-user
799 "Really send a nastygram to the author of the current article? "))
800 (let ((group gnus-newsgroup-name))
801 (gnus-summary-reply-with-original n)
802 (set-buffer gnus-message-buffer)
804 (insert (format gnus-nastygram-message group))
805 (message-send-and-exit))))
807 (defun gnus-summary-mail-crosspost-complaint (n)
808 "Send a complaint about crossposting to the current article(s)."
810 (let ((articles (gnus-summary-work-articles n))
812 (while (setq article (pop articles))
813 (set-buffer gnus-summary-buffer)
814 (gnus-summary-goto-subject article)
815 (let ((group (gnus-group-real-name gnus-newsgroup-name))
816 newsgroups followup-to)
817 (gnus-summary-select-article)
818 (set-buffer gnus-original-article-buffer)
819 (if (and (<= (length (message-tokenize-header
821 (mail-fetch-field "newsgroups"))
824 (or (not (setq followup-to (mail-fetch-field "followup-to")))
825 (not (member group (message-tokenize-header
826 followup-to ", ")))))
828 (gnus-message 1 "Followup-to restricted")
829 (gnus-message 1 "Not a crossposted article"))
830 (set-buffer gnus-summary-buffer)
831 (gnus-summary-reply-with-original 1)
832 (set-buffer gnus-message-buffer)
834 (insert (format gnus-crosspost-complaint newsgroups group))
835 (message-goto-subject)
836 (re-search-forward " *$")
837 (replace-match " (crosspost notification)" t t)
838 (gnus-deactivate-mark)
839 (when (gnus-y-or-n-p "Send this complaint? ")
840 (message-send-and-exit)))))))
842 (defun gnus-summary-mail-other-window ()
843 "Compose mail in other window."
845 (gnus-setup-message 'message
848 (defun gnus-mail-parse-comma-list ()
851 (skip-chars-forward " ")
854 (skip-chars-forward "^,")
859 (narrow-to-region beg (point))
862 (while (search-forward "\"" nil t)
866 (skip-chars-forward ",")
867 (skip-chars-forward "^,"))
868 (skip-chars-backward " ")
869 (push (buffer-substring beg (point))
871 (skip-chars-forward "^,")
872 (skip-chars-forward ", "))
875 (defun gnus-inews-add-to-address (group)
876 (let ((to-address (mail-fetch-field "to")))
877 (when (and to-address
879 ;; This mail group doesn't have a `to-list', so we add one
882 (format "Do you want to add this as `to-list': %s " to-address))
883 (gnus-group-add-parameter group (cons 'to-list to-address))))))
885 (defun gnus-put-message ()
886 "Put the current message in some group and return to Gnus."
888 (let ((reply gnus-article-reply)
889 (winconf gnus-prev-winconf)
890 (group gnus-newsgroup-name))
892 (or (and group (not (gnus-group-read-only-p group)))
893 (setq group (read-string "Put in group: " nil
894 (gnus-writable-groups))))
895 (when (gnus-gethash group gnus-newsrc-hashtb)
896 (error "No such group: %s" group))
901 (message-narrow-to-headers)
902 (let (gnus-deletable-headers)
904 (message-generate-headers message-required-news-headers)
905 (message-generate-headers message-required-mail-headers)))
906 (goto-char (point-max))
907 (insert "Gcc: " group "\n")
912 (when (get-buffer gnus-group-buffer)
913 (when (gnus-buffer-exists-p (car-safe reply))
914 (set-buffer (car reply))
916 (gnus-summary-mark-article-as-replied
919 (set-window-configuration winconf)))))
921 (defun gnus-article-mail (yank)
922 "Send a reply to the address near point.
923 If YANK is non-nil, include the original article."
927 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
928 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
930 (message-reply address)
932 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
934 (defvar nntp-server-type)
936 "Send a bug report to the Gnus maintainers."
938 (unless (gnus-alive-p)
939 (error "Gnus has been shut down"))
940 (gnus-setup-message 'bug
941 (delete-other-windows)
942 (when gnus-bug-create-help-buffer
943 (switch-to-buffer "*Gnus Help Bug*")
945 (insert gnus-bug-message)
946 (goto-char (point-min)))
947 (message-pop-to-buffer "*Gnus Bug*")
948 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
949 (when gnus-bug-create-help-buffer
950 (push `(gnus-bug-kill-buffer) message-send-actions))
951 (goto-char (point-min))
952 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
954 (insert gnus-product-name " " gnus-version-number
955 " (r" gnus-revision-number ") "
956 "based on " gnus-original-product-name " v"
957 gnus-original-version-number "\n"
958 (emacs-version) "\n")
959 (when (and (boundp 'nntp-server-type)
960 (stringp nntp-server-type))
961 (insert nntp-server-type))
962 (insert "\n\n\n\n\n")
963 (let (mime-content-types)
964 (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
965 (insert (with-temp-buffer
968 (goto-char (point-min))
969 (search-forward "Subject: " nil t)
972 (defun gnus-bug-kill-buffer ()
973 (when (get-buffer "*Gnus Help Bug*")
974 (kill-buffer "*Gnus Help Bug*")))
977 "Attempts to go through the Gnus source file and report what variables have been changed.
978 The source file has to be in the Emacs load path."
980 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
981 "gnus-art.el" "gnus-start.el" "gnus-async.el"
982 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
983 "nnmail.el" "message.el"))
986 (gnus-message 4 "Please wait while we snoop your variables...")
988 ;; Go through all the files looking for non-default values for variables.
990 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
993 (when (and (setq file (locate-library (pop files)))
994 (file-exists-p file))
995 (insert-file-contents file)
996 (goto-char (point-min))
997 (if (not (re-search-forward "^;;* *Internal variables" nil t))
998 (gnus-message 4 "Malformed sources in file %s" file)
999 (narrow-to-region (point-min) (point))
1000 (goto-char (point-min))
1001 (while (setq expr (ignore-errors (read (current-buffer))))
1003 (and (or (eq (car expr) 'defvar)
1004 (eq (car expr) 'defcustom))
1005 (stringp (nth 3 expr))
1006 (or (not (boundp (nth 1 expr)))
1007 (not (equal (eval (nth 2 expr))
1008 (symbol-value (nth 1 expr)))))
1009 (push (nth 1 expr) olist)))))))
1010 (kill-buffer (current-buffer)))
1011 (when (setq olist (nreverse olist))
1012 (insert "------------------ Environment follows ------------------\n\n"))
1014 (if (boundp (car olist))
1016 (pp `(setq ,(car olist)
1017 ,(if (or (consp (setq sym (symbol-value (car olist))))
1019 (not (or (eq sym nil)
1021 (list 'quote (symbol-value (car olist)))
1022 (symbol-value (car olist))))
1025 (format "(setq %s 'whatever)\n" (car olist))))
1026 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1027 (setq olist (cdr olist)))
1029 ;; Remove any control chars - they seem to cause trouble for some
1030 ;; mailers. (Byte-compiled output from the stuff above.)
1032 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1033 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1036 ;;; Treatment of rejected articles.
1039 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1040 "Re-mail the current message.
1041 This only makes sense if the current message is a bounce message than
1042 contains some mail you have written which has been bounced back to
1044 If FETCH, try to fetch the article that this is a reply to, if indeed
1047 (gnus-summary-select-article t)
1048 (set-buffer gnus-original-article-buffer)
1049 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1050 (gnus-setup-message 'compose-bounce
1051 (let* ((references (mail-fetch-field "references"))
1052 (parent (and references (gnus-parent-id references))))
1054 ;; If there are references, we fetch the article we answered to.
1056 (gnus-summary-refer-article parent)
1057 (gnus-summary-show-all-headers))))))
1061 ;; Do Gcc handling, which copied the message over to some group.
1062 (defun gnus-inews-do-gcc (&optional gcc)
1064 (when (gnus-alive-p)
1067 (message-narrow-to-headers)
1068 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1069 (coding-system-for-write 'raw-text)
1070 (output-coding-system 'raw-text)
1071 groups group method)
1073 (message-remove-header "gcc")
1075 (setq groups (message-tokenize-header gcc " ,"))
1076 ;; Copy the article over to some group(s).
1077 (while (setq group (pop groups))
1080 (cond ((and (null (gnus-get-info group))
1081 (eq (car gnus-message-archive-method)
1083 (gnus-server-to-method
1084 (gnus-group-method group)))))
1085 ;; If the group doesn't exist, we assume
1086 ;; it's an archive group...
1087 gnus-message-archive-method)
1089 ((gnus-info-method (gnus-get-info group))
1090 (gnus-info-method (gnus-get-info group)))
1092 (t (gnus-group-method group)))))
1093 (gnus-check-server method)
1094 (unless (gnus-request-group group t method)
1095 (gnus-request-create-group group method))
1097 (nnheader-set-temp-buffer " *acc*")
1098 (insert-buffer-substring message-encoding-buffer)
1099 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1100 (goto-char (point-min))
1101 (when (re-search-forward
1102 (concat "^" (regexp-quote mail-header-separator) "$")
1104 (replace-match "" t t ))
1105 (unless (gnus-request-accept-article group method t t)
1106 (gnus-message 1 "Couldn't store article in group %s: %s"
1107 group (gnus-status-message method))
1109 (kill-buffer (current-buffer))))))))))
1111 (defun gnus-inews-insert-gcc ()
1112 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1115 (message-narrow-to-headers)
1116 (let* ((group gnus-outgoing-message-group)
1118 ((gnus-functionp group)
1120 ((or (stringp group) (list group))
1124 (if (stringp gcc) gcc
1125 (mapconcat 'identity gcc " "))
1128 (defun gnus-inews-insert-archive-gcc (&optional group)
1129 "Insert the Gcc to say where the article is to be archived."
1130 (let* ((var gnus-message-archive-group)
1131 (group (or group gnus-newsgroup-name ""))
1133 (and gnus-newsgroup-name
1134 (gnus-group-find-parameter
1135 gnus-newsgroup-name 'gcc-self)))
1139 ((null gnus-message-archive-method)
1143 ;; Just a single group.
1146 ;; We don't want this.
1148 ((and (listp var) (stringp (car var)))
1149 ;; A list of groups.
1151 ((gnus-functionp var)
1153 (funcall var group))
1155 ;; An alist of regexps/functions/forms.
1160 ((stringp (caar var))
1162 (when (string-match (caar var) group)
1164 ((gnus-functionp (car var))
1166 (funcall (car var) group))
1168 (eval (car var)))))))
1169 (setq var (cdr var)))
1172 (when (or groups gcc-self-val)
1173 (when (stringp groups)
1174 (setq groups (list groups)))
1177 (message-narrow-to-headers)
1178 (goto-char (point-max))
1181 ;; Use the `gcc-self' param value instead.
1184 (if (stringp gcc-self-val)
1187 (if (not (eq gcc-self-val 'none))
1192 ;; Use the list of groups.
1193 (while (setq name (pop groups))
1194 (insert (if (string-match ":" name)
1196 (gnus-group-prefixed-name
1197 name gnus-message-archive-method)))
1204 (defun gnus-configure-posting-styles ()
1205 "Configure posting styles according to `gnus-posting-styles'."
1206 (unless gnus-inhibit-posting-styles
1207 (let ((group (or gnus-newsgroup-name ""))
1208 (styles gnus-posting-styles)
1209 style match variable attribute value v results
1210 filep name address element)
1211 ;; If the group has a posting-style parameter, add it at the end with a
1212 ;; regexp matching everything, to be sure it takes precedence over all
1214 (when gnus-newsgroup-name
1215 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1217 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1218 ;; Go through all styles and look for matches.
1219 (dolist (style styles)
1220 (setq match (pop style))
1223 ;; Regexp string match on the group name.
1224 (string-match match group))
1225 ((or (symbolp match)
1226 (gnus-functionp match))
1228 ((gnus-functionp match)
1229 ;; Function to be called.
1232 ;; Variable to be checked.
1233 (symbol-value match))))
1235 ;; This is a form to be evaled.
1237 ;; We have a match, so we set the variables.
1238 (dolist (attribute style)
1239 (setq element (pop attribute)
1244 ((eq (car attribute) ':file)
1247 ((eq (car attribute) :value)
1251 ;; We get the value.
1256 ((or (symbolp value)
1257 (gnus-functionp value))
1258 (cond ((gnus-functionp value)
1261 (symbol-value value))))
1264 ;; Translate obsolescent value.
1265 (when (eq element 'signature-file)
1266 (setq element 'signature
1268 ;; Get the contents of file elems.
1270 (setq v (with-temp-buffer
1271 (insert-file-contents v)
1273 (setq results (delq (assoc element results) results))
1274 (push (cons element v) results))))
1275 ;; Now we have all the styles, so we insert them.
1276 (setq name (assq 'name results)
1277 address (assq 'address results))
1278 (setq results (delq name (delq address results)))
1279 (make-local-variable 'message-setup-hook)
1280 (dolist (result results)
1282 (add-hook 'message-setup-hook
1284 ((eq 'eval (car result))
1286 ((eq 'body (car result))
1290 (insert ,(cdr result)))))
1291 ((eq 'signature (car result))
1292 (set (make-local-variable 'message-signature) nil)
1293 (set (make-local-variable 'message-signature-file) nil)
1296 (let ((message-signature ,(cdr result)))
1297 (message-insert-signature)))))
1300 (if (symbolp (car result))
1301 (capitalize (symbol-name (car result)))
1305 (message-remove-header ,header)
1307 (insert ,header ": " ,(cdr result) "\n")))))))))
1308 (when (or name address)
1309 (add-hook 'message-setup-hook
1311 (let ((user-full-name ,(or (cdr name) user-full-name))
1313 ,(or (cdr address) user-mail-address)))
1315 (message-remove-header "From")
1317 (insert "From: " (message-make-from) "\n")))))))))
1320 ;;; @ for MIME Edit mode
1323 (defun gnus-maybe-setup-default-charset ()
1325 (and (boundp 'gnus-summary-buffer)
1326 (buffer-live-p gnus-summary-buffer)
1328 (set-buffer gnus-summary-buffer)
1329 default-mime-charset))))
1332 (make-local-variable 'default-mime-charset)
1333 (setq default-mime-charset charset)
1337 ;;; Allow redefinition of functions.
1343 ;;; gnus-msg.el ends here