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))
34 (eval-when-compile (require 'static))
41 (defcustom gnus-post-method 'current
42 "*Preferred method for posting USENET news.
44 If this variable is `current', Gnus will use the \"current\" select
45 method when posting. If it is nil (which is the default), Gnus will
46 use the native select method when posting.
48 This method will not be used in mail groups and the like, only in
51 If not nil nor `native', the value must be a valid method as discussed
52 in the documentation of `gnus-select-method'. It can also be a list of
53 methods. If that is the case, the user will be queried for what select
54 method to use when posting."
55 :group 'gnus-group-foreign
56 :type `(choice (const nil)
59 (sexp :tag "Methods" ,gnus-select-method)))
61 (defvar gnus-outgoing-message-group nil
62 "*All outgoing messages will be put in this group.
63 If you want to store all your outgoing mail and articles in the group
64 \"nnml:archive\", you set this variable to that value. This variable
65 can also be a list of group names.
67 If you want to have greater control over what group to put each
68 message in, you can set this variable to a function that checks the
69 current newsgroup name and then returns a suitable group name (or list
72 (defvar gnus-mailing-list-groups nil
73 "*Regexp matching groups that are really mailing lists.
74 This is useful when you're reading a mailing list that has been
75 gatewayed to a newsgroup, and you want to followup to an article in
78 (defvar gnus-add-to-list nil
79 "*If non-nil, add a `to-list' parameter automatically.")
81 (defvar gnus-crosspost-complaint
84 You posted the article below with the following Newsgroups header:
88 The %s group, at least, was an inappropriate recipient
89 of this message. Please trim your Newsgroups header to exclude this
90 group before posting in the future.
95 "Format string to be inserted when complaining about crossposts.
96 The first %s will be replaced by the Newsgroups header;
97 the second with the current group name.")
99 (defvar gnus-message-setup-hook '(gnus-maybe-setup-default-charset)
100 "Hook run after setting up a message buffer.")
102 (defvar gnus-bug-create-help-buffer t
103 "*Should we create the *Gnus Help Bug* buffer?")
105 (defvar gnus-posting-styles nil
106 "*Alist of styles to use when posting.")
108 (defcustom gnus-group-posting-charset-alist
109 '(("^\\(no\\|fr\\|dk\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\|dk\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
110 (message-this-is-mail nil nil)
111 (message-this-is-news nil t))
112 "Alist of regexps and permitted unencoded charsets for posting.
113 Each element of the alist has the form (TEST HEADER BODY-LIST), where
114 TEST is either a regular expression matching the newsgroup header or a
116 HEADER is the charset which may be left unencoded in the header (nil
117 means encode all charsets),
118 BODY-LIST is a list of charsets which may be encoded using 8bit
119 content-transfer encoding in the body, or one of the special values
120 nil (always encode using quoted-printable) or t (always use 8bit).
122 Note that any value other tha nil for HEADER infringes some RFCs, so
123 use this option with care."
124 :type '(repeat (list :tag "Permitted unencoded charsets"
126 (regexp :tag "Group")
127 (const :tag "Mail message" :value message-this-is-mail)
128 (const :tag "News article" :value message-this-is-news))
129 (choice :tag "Header"
130 (const :tag "None" nil)
131 (symbol :tag "Charset"))
133 (const :tag "Any" :value t)
134 (const :tag "None" :value nil)
135 (repeat :tag "Charsets"
136 (symbol :tag "Charset")))))
137 :group 'gnus-charset)
139 ;;; Internal variables.
141 (defvar gnus-inhibit-posting-styles nil
142 "Inhibit the use of posting styles.")
144 (defvar gnus-message-buffer "*Mail Gnus*")
145 (defvar gnus-article-copy nil)
146 (defvar gnus-last-posting-server nil)
147 (defvar gnus-message-group-art nil)
149 (defconst gnus-bug-message
150 (format "Sending a bug report to the Gnus Towers.
151 ========================================
153 This gnus is the %s%s.
154 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
155 Developers. (the addresses below are mailing list addresses)
157 ========================================
159 The buffer below is a mail buffer. When you press `C-c C-c', it will
160 be sent to the Gnus Bug Exterminators.
162 The thing near the bottom of the buffer is how the environment
163 settings will be included in the mail. Please do not delete that.
164 They will tell the Bug People what your environment is, so that it
165 will be easier to locate the bugs.
167 If you have found a bug that makes Emacs go \"beep\", set
168 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
169 and include the backtrace in your bug report.
171 Please describe the bug in annoying, painstaking detail.
173 Thank you for your help in stamping out bugs.
176 (if (string= gnus-product-name "Semi-gnus")
178 ", a modified version of Semi-gnus")))
181 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
182 (autoload 'news-setup "rnewspost")
183 (autoload 'news-reply-mode "rnewspost")
184 (autoload 'rmail-dont-reply-to "mail-utils")
185 (autoload 'rmail-output "rmailout"))
189 ;;; Gnus Posting Functions
192 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
193 "p" gnus-summary-post-news
194 "f" gnus-summary-followup
195 "F" gnus-summary-followup-with-original
196 "c" gnus-summary-cancel-article
197 "s" gnus-summary-supersede-article
198 "r" gnus-summary-reply
199 "y" gnus-summary-yank-message
200 "R" gnus-summary-reply-with-original
201 "w" gnus-summary-wide-reply
202 "W" gnus-summary-wide-reply-with-original
203 "n" gnus-summary-followup-to-mail
204 "N" gnus-summary-followup-to-mail-with-original
205 "m" gnus-summary-mail-other-window
206 "u" gnus-uu-post-news
207 "\M-c" gnus-summary-mail-crosspost-complaint
208 "om" gnus-summary-mail-forward
209 "op" gnus-summary-post-forward
210 "Om" gnus-summary-mail-digest
211 "Op" gnus-summary-post-digest)
213 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
214 "b" gnus-summary-resend-bounced-mail
215 ;; "c" gnus-summary-send-draft
216 "r" gnus-summary-resend-message)
218 ;;; Internal functions.
220 (defvar gnus-article-reply nil)
221 (defmacro gnus-setup-message (config &rest forms)
222 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
223 (buffer (make-symbol "gnus-setup-message-buffer"))
224 (article (make-symbol "gnus-setup-message-article"))
225 (group (make-symbol "gnus-setup-message-group")))
226 `(let ((,winconf (current-window-configuration))
227 (,buffer (buffer-name (current-buffer)))
228 (,article (and gnus-article-reply (gnus-summary-article-number)))
229 (,group gnus-newsgroup-name)
230 (message-header-setup-hook
231 (copy-sequence message-header-setup-hook))
232 (message-mode-hook (copy-sequence message-mode-hook))
233 (message-startup-parameter-alist
234 '((reply-buffer . gnus-copy-article-buffer)
235 (original-buffer . gnus-original-article-buffer)
236 (user-agent . Gnus))))
237 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
238 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
239 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
243 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
244 (setq gnus-message-buffer (current-buffer))
245 (set (make-local-variable 'gnus-message-group-art)
246 (cons ,group ,article))
247 (set (make-local-variable 'gnus-newsgroup-name) ,group)
248 (gnus-run-hooks 'gnus-message-setup-hook))
250 (gnus-configure-windows ,config t)
251 (set-buffer-modified-p nil))))
253 (defun gnus-setup-posting-charset (group)
254 (let ((alist gnus-group-posting-charset-alist)
255 (group (or group ""))
259 (while (setq elem (pop alist))
260 (when (or (and (stringp (car elem))
261 (string-match (car elem) group))
262 (and (gnus-functionp (car elem))
263 (funcall (car elem) group))
264 (and (symbolp (car elem))
265 (symbol-value (car elem))))
266 (throw 'found (cons (cadr elem) (caddr elem)))))))))
268 (defun gnus-inews-add-send-actions (winconf buffer article)
269 (make-local-hook 'message-sent-hook)
270 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
271 (setq message-post-method
273 (gnus-post-method arg ,gnus-newsgroup-name)))
274 (setq message-user-agent (gnus-extended-version))
275 (when (not message-use-multi-frames)
277 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
279 `(when (gnus-buffer-exists-p ,buffer)
283 `(gnus-summary-mark-article-as-replied ,article))))
286 (put 'gnus-setup-message 'lisp-indent-function 1)
287 (put 'gnus-setup-message 'edebug-form-spec '(form body))
289 ;;; Post news commands of Gnus group mode and summary mode
291 (defun gnus-group-mail (&optional arg)
292 "Start composing a mail.
293 If ARG, use the group under the point to find a posting style.
294 If ARG is 1, prompt for a group name to find the posting style."
296 ;; We can't `let' gnus-newsgroup-name here, since that leads
297 ;; to local variables leaking.
298 (let ((group gnus-newsgroup-name)
299 (buffer (current-buffer)))
302 (setq gnus-newsgroup-name
304 (if (= 1 (prefix-numeric-value arg))
305 (completing-read "Use posting style of group: "
306 gnus-active-hashtb nil
307 (gnus-read-active-file-p))
308 (gnus-group-group-name))
310 (gnus-setup-message 'message (message-mail)))
313 (setq gnus-newsgroup-name group)))))
315 (defun gnus-group-post-news (&optional arg)
316 "Start composing a news message.
317 If ARG, post to the group under point.
318 If ARG is 1, prompt for a group name."
320 ;; Bind this variable here to make message mode hooks work ok.
321 (let ((gnus-newsgroup-name
323 (if (= 1 (prefix-numeric-value arg))
324 (completing-read "Newsgroup: " gnus-active-hashtb nil
325 (gnus-read-active-file-p))
326 (gnus-group-group-name))
328 (gnus-post-news 'post gnus-newsgroup-name)))
330 (defun gnus-summary-post-news ()
331 "Start composing a news message."
333 (gnus-post-news 'post gnus-newsgroup-name))
335 (defun gnus-summary-followup (yank &optional force-news)
336 "Compose a followup to an article.
337 If prefix argument YANK is non-nil, original article is yanked automatically."
339 (list (and current-prefix-arg
340 (gnus-summary-work-articles 1))))
342 (gnus-summary-goto-subject (car yank)))
343 (save-window-excursion
344 (gnus-summary-select-article))
345 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
346 (gnus-newsgroup-name gnus-newsgroup-name))
348 (gnus-post-news nil gnus-newsgroup-name
349 headers gnus-article-buffer
350 yank nil force-news)))
352 (defun gnus-summary-followup-with-original (n &optional force-news)
353 "Compose a followup to an article and include the original article."
355 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
357 (defun gnus-summary-followup-to-mail (&optional arg)
358 "Followup to the current mail message via news."
360 (list (and current-prefix-arg
361 (gnus-summary-work-articles 1))))
362 (gnus-summary-followup arg t))
364 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
365 "Followup to the current mail message via news."
367 (gnus-summary-followup (gnus-summary-work-articles arg) t))
369 (defun gnus-inews-yank-articles (articles)
370 (let* ((more-than-one (cdr articles))
371 (frame (when (and message-use-multi-frames more-than-one)
372 (window-frame (get-buffer-window (current-buffer)))))
375 (while (setq article (pop articles))
376 (save-window-excursion
377 (set-buffer gnus-summary-buffer)
378 (gnus-summary-select-article nil nil nil article)
379 (gnus-summary-remove-process-mark article))
381 (select-frame frame))
383 ;; Gathering references.
385 (setq refs (message-list-references
387 (mail-header-references gnus-current-headers)
388 (mail-header-message-id gnus-current-headers))))
390 (gnus-copy-article-buffer)
391 (let ((message-reply-buffer gnus-article-copy)
392 (message-reply-headers gnus-current-headers))
393 (message-yank-original)
394 (setq beg (or beg (mark t))))
399 ;; Replace with the gathered references.
403 (message-narrow-to-headers)
404 (let ((case-fold-search t))
405 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
407 (goto-char (point-max))))
409 (list (or (assq 'References message-header-format-alist)
410 '(References . message-shorten-references)))
411 (list (cons 'References
412 (mapconcat 'identity (nreverse refs) " "))))
413 (backward-delete-char 1))
419 (defun gnus-summary-cancel-article (&optional n symp)
420 "Cancel an article you posted.
421 Uses the process-prefix convention. If given the symbolic
422 prefix `a', cancel using the standard posting method; if not
423 post using the current select method."
424 (interactive (gnus-interactive "P\ny"))
425 (let ((articles (gnus-summary-work-articles n))
428 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
430 (while (setq article (pop articles))
431 (when (gnus-summary-select-article t nil nil article)
432 (when (gnus-eval-in-buffer-window gnus-article-buffer
434 (set-buffer gnus-original-article-buffer)
435 (message-cancel-news)))
436 (gnus-summary-mark-as-read article gnus-canceled-mark)
437 (gnus-cache-remove-article 1))
438 (gnus-article-hide-headers-if-wanted))
439 (gnus-summary-remove-process-mark article))))
441 (defun gnus-summary-supersede-article ()
442 "Compose an article that will supersede a previous article.
443 This is done simply by taking the old article and adding a Supersedes
444 header line with the old Message-ID."
446 (let ((article (gnus-summary-article-number))
447 (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
448 (gnus-setup-message 'reply-yank
449 (gnus-summary-select-article t)
450 (set-buffer gnus-original-article-buffer)
454 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
456 (set-buffer ,gnus-summary-buffer)
457 (gnus-cache-possibly-remove-article ,article nil nil nil t)
458 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
459 message-send-actions))))
463 (defun gnus-copy-article-buffer (&optional article-buffer)
464 ;; make a copy of the article buffer with all text properties removed
465 ;; this copy is in the buffer gnus-article-copy.
466 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
467 ;; this buffer should be passed to all mail/news reply/post routines.
468 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
469 (let ((article-buffer (or article-buffer gnus-article-buffer))
471 (if (not (and (get-buffer article-buffer)
472 (gnus-buffer-exists-p article-buffer)))
473 (error "Can't find any article buffer")
475 (set-buffer article-buffer)
477 ;; Copy over the (displayed) article buffer, delete
478 ;; hidden text and remove text properties.
480 (let ((inhibit-read-only t))
481 (copy-to-buffer gnus-article-copy (point-min) (point-max))
482 (set-buffer gnus-article-copy)
483 (gnus-article-delete-text-of-type 'annotation)
484 (gnus-remove-text-with-property 'gnus-prev)
485 (gnus-remove-text-with-property 'gnus-next)
486 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
489 (format "%s" (buffer-string))
492 ;; Find the original headers.
493 (set-buffer gnus-original-article-buffer)
494 (goto-char (point-min))
495 (while (looking-at message-unix-mail-delimiter)
498 (setq end (or (search-forward "\n\n" nil t) (point)))
499 ;; Delete the headers from the displayed articles.
500 (set-buffer gnus-article-copy)
501 (delete-region (goto-char (point-min))
502 (or (search-forward "\n\n" nil t) (point-max)))
503 ;; Encode bitmap smileys to ordinary text.
504 (static-unless (featurep 'xemacs)
505 (when (featurep 'smiley-mule)
506 (smiley-encode-buffer)))
507 ;; Insert the original article headers.
508 (insert-buffer-substring gnus-original-article-buffer beg end)
509 (article-decode-encoded-words)))
512 (defun gnus-post-news (post &optional group header article-buffer yank subject
515 (gnus-copy-article-buffer))
516 (let ((gnus-article-reply article-buffer)
517 (add-to-list gnus-add-to-list))
518 (gnus-setup-message (cond (yank 'reply-yank)
519 (article-buffer 'reply)
521 (let* ((group (or group gnus-newsgroup-name))
523 to-address to-group mailing-list to-list
526 (setq to-address (gnus-group-find-parameter group 'to-address)
527 to-group (gnus-group-find-parameter group 'to-group)
528 to-list (gnus-group-find-parameter group 'to-list)
529 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
530 mailing-list (when gnus-mailing-list-groups
531 (string-match gnus-mailing-list-groups group))
532 group (gnus-group-real-name group)))
533 (if (or (and to-group
534 (gnus-news-group-p to-group))
537 (and (gnus-news-group-p
538 (or pgroup gnus-newsgroup-name)
539 (if header (mail-header-number header)
540 gnus-current-article))
546 (message-news (or to-group group))
547 (set-buffer gnus-article-copy)
548 (gnus-msg-treat-broken-reply-to)
549 (message-followup (if (or newsgroup-p force-news) nil to-group)))
553 (message-mail (or to-address to-list))
554 ;; Arrange for mail groups that have no `to-address' to
555 ;; get that when the user sends off the mail.
556 (when (and (not to-list)
559 (push (list 'gnus-inews-add-to-address pgroup)
560 message-send-actions)))
561 (set-buffer gnus-article-copy)
562 (gnus-msg-treat-broken-reply-to)
563 (message-wide-reply to-address)))
565 (gnus-inews-yank-articles yank))))))
567 (defun gnus-msg-treat-broken-reply-to ()
568 "Remove the Reply-to header iff broken-reply-to."
569 (when (gnus-group-find-parameter
570 gnus-newsgroup-name 'broken-reply-to)
572 (message-narrow-to-head)
573 (message-remove-header "reply-to"))))
575 (defun gnus-post-method (arg group &optional silent)
576 "Return the posting method based on GROUP and ARG.
577 If SILENT, don't prompt the user."
578 (let ((group-method (gnus-find-method-for-group group)))
580 ;; If the group-method is nil (which shouldn't happen) we use
581 ;; the default method.
583 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
584 gnus-select-method message-post-method))
585 ;; We want the inverse of the default
586 ((and arg (not (eq arg 0)))
587 (if (eq gnus-post-method 'active)
590 ;; We query the user for a post method.
592 (and gnus-post-method
593 (not (eq gnus-post-method 'current))
594 (listp (car gnus-post-method))))
596 ;; Collect all methods we know about.
598 (when (and gnus-post-method
599 (not (eq gnus-post-method 'current)))
600 (if (listp (car gnus-post-method))
602 (list gnus-post-method)))
603 gnus-secondary-select-methods
604 (mapcar 'cdr gnus-server-alist)
605 (mapcar 'car gnus-opened-servers)
606 (list gnus-select-method)
607 (list group-method)))
608 method-alist post-methods method)
609 ;; Weed out all mail methods.
611 (setq method (gnus-server-get-method "" (pop methods)))
612 (when (and (or (gnus-method-option-p method 'post)
613 (gnus-method-option-p method 'post-mail))
614 (not (member method post-methods)))
615 (push method post-methods)))
616 ;; Create a name-method alist.
620 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
625 (setq gnus-last-posting-server
627 gnus-last-posting-server)
628 ;; Just use the last value.
629 gnus-last-posting-server
631 "Posting method: " method-alist nil t
632 (cons (or gnus-last-posting-server "") 0))))
634 ;; Override normal method.
635 ((and (eq gnus-post-method 'current)
636 (not (eq (car group-method) 'nndraft))
637 (gnus-get-function group-method 'request-post t)
640 ((and gnus-post-method
641 (not (eq gnus-post-method 'current)))
643 ;; Use the normal select method.
644 (t gnus-select-method))))
648 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
649 "Return user-agent info.
650 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
651 `mime-edit-user-agent-value' exists, the return value will include it.
652 MAX-COLUMN the optional second argument if it is specified, the return value
653 will be folded up in the proper way."
654 (let ((user-agent (if (and include-mime-info
655 (boundp 'mime-edit-user-agent-value))
656 (concat (gnus-extended-version)
658 mime-edit-user-agent-value)
659 (gnus-extended-version))))
662 (unless (natnump max-column) (setq max-column 76))
664 (insert " " user-agent)
666 (while (re-search-forward "[\n\t ]+" nil t)
669 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
670 (while (eq ?\( (char-after (point)))
672 (skip-chars-forward " "))
673 (skip-chars-backward " ")
674 (if (> (current-column) max-column)
676 (if (or (not boundary) (eq ?\n (char-after boundary)))
678 (setq boundary (point))
685 (setq boundary (point))))
686 (buffer-substring 13 (point-max))))
691 ;;; Gnus Mail Functions
694 ;;; Mail reply commands of Gnus summary mode
696 (defun gnus-summary-reply (&optional yank wide)
697 "Start composing a reply mail to the current message.
698 If prefix argument YANK is non-nil, the original article is yanked
701 (list (and current-prefix-arg
702 (gnus-summary-work-articles 1))))
703 ;; Stripping headers should be specified with mail-yank-ignored-headers.
705 (gnus-summary-goto-subject (car yank)))
706 (let ((gnus-article-reply t))
707 (gnus-setup-message (if yank 'reply-yank 'reply)
708 (gnus-summary-select-article)
709 (set-buffer (gnus-copy-article-buffer))
710 (gnus-msg-treat-broken-reply-to)
711 (message-reply nil wide)
713 (gnus-inews-yank-articles yank)))))
715 (defun gnus-summary-reply-with-original (n &optional wide)
716 "Start composing a reply mail to the current message.
717 The original article will be yanked."
719 (gnus-summary-reply (gnus-summary-work-articles n) wide))
721 (defun gnus-summary-wide-reply (&optional yank)
722 "Start composing a wide reply mail to the current message.
723 If prefix argument YANK is non-nil, the original article is yanked
726 (list (and current-prefix-arg
727 (gnus-summary-work-articles 1))))
728 (gnus-summary-reply yank t))
730 (defun gnus-summary-wide-reply-with-original (n)
731 "Start composing a wide reply mail to the current message.
732 The original article will be yanked."
734 (gnus-summary-reply-with-original n t))
736 (defun gnus-summary-mail-forward (&optional full-headers post)
737 "Forward the current message to another user.
738 If FULL-HEADERS (the prefix), include full headers when forwarding."
740 (gnus-setup-message 'forward
741 (gnus-summary-select-article)
742 (let ((charset default-mime-charset))
743 (set-buffer gnus-original-article-buffer)
744 (make-local-variable 'default-mime-charset)
745 (setq default-mime-charset charset)
747 (let ((message-included-forward-headers
748 (if full-headers "" message-included-forward-headers)))
749 (message-forward post))))
751 ;;; XXX: generate Subject and ``Topics''?
752 (defun gnus-summary-mail-digest (&optional n post)
753 "Digests and forwards all articles in this series."
755 (let ((subject "Digested Articles")
756 (articles (gnus-summary-work-articles n))
758 (gnus-setup-message 'forward
759 (gnus-summary-select-article)
760 (if post (message-news nil subject) (message-mail nil subject))
761 (when (and message-use-multi-frames (cdr articles))
762 (setq frame (window-frame (get-buffer-window (current-buffer)))))
764 (while (setq article (pop articles))
765 (save-window-excursion
766 (set-buffer gnus-summary-buffer)
767 (gnus-summary-select-article nil nil nil article)
768 (gnus-summary-remove-process-mark article))
770 (select-frame frame))
771 (insert (mime-make-tag "message" "rfc822") "\n")
772 (insert-buffer-substring gnus-original-article-buffer))
775 (mime-edit-enclose-digest-region (point)(mark t)))))
777 (defun gnus-summary-post-digest (&optional n)
778 "Digest and forwards all articles in this series to a newsgroup."
780 (gnus-summary-mail-digest n t))
782 (defun gnus-summary-resend-message (address n)
783 "Resend the current article to ADDRESS."
784 (interactive "sResend message(s) to: \nP")
785 (let ((articles (gnus-summary-work-articles n))
787 (while (setq article (pop articles))
788 (gnus-summary-select-article nil nil nil article)
790 (set-buffer gnus-original-article-buffer)
791 (message-resend address)))))
793 (defun gnus-summary-post-forward (&optional full-headers)
794 "Forward the current article to a newsgroup.
795 If FULL-HEADERS (the prefix), include full headers when forwarding."
797 (gnus-summary-mail-forward full-headers t))
799 (defvar gnus-nastygram-message
800 "The following article was inappropriately posted to %s.\n\n"
801 "Format string to insert in nastygrams.
802 The current group name will be inserted at \"%s\".")
804 (defun gnus-summary-mail-nastygram (n)
805 "Send a nastygram to the author of the current article."
807 (when (or gnus-expert-user
809 "Really send a nastygram to the author of the current article? "))
810 (let ((group gnus-newsgroup-name))
811 (gnus-summary-reply-with-original n)
812 (set-buffer gnus-message-buffer)
814 (insert (format gnus-nastygram-message group))
815 (message-send-and-exit))))
817 (defun gnus-summary-mail-crosspost-complaint (n)
818 "Send a complaint about crossposting to the current article(s)."
820 (let ((articles (gnus-summary-work-articles n))
822 (while (setq article (pop articles))
823 (set-buffer gnus-summary-buffer)
824 (gnus-summary-goto-subject article)
825 (let ((group (gnus-group-real-name gnus-newsgroup-name))
826 newsgroups followup-to)
827 (gnus-summary-select-article)
828 (set-buffer gnus-original-article-buffer)
829 (if (and (<= (length (message-tokenize-header
831 (mail-fetch-field "newsgroups"))
834 (or (not (setq followup-to (mail-fetch-field "followup-to")))
835 (not (member group (message-tokenize-header
836 followup-to ", ")))))
838 (gnus-message 1 "Followup-to restricted")
839 (gnus-message 1 "Not a crossposted article"))
840 (set-buffer gnus-summary-buffer)
841 (gnus-summary-reply-with-original 1)
842 (set-buffer gnus-message-buffer)
844 (insert (format gnus-crosspost-complaint newsgroups group))
845 (message-goto-subject)
846 (re-search-forward " *$")
847 (replace-match " (crosspost notification)" t t)
848 (gnus-deactivate-mark)
849 (when (gnus-y-or-n-p "Send this complaint? ")
850 (message-send-and-exit)))))))
852 (defun gnus-summary-mail-other-window ()
853 "Compose mail in other window."
855 (gnus-setup-message 'message
858 (defun gnus-mail-parse-comma-list ()
861 (skip-chars-forward " ")
864 (skip-chars-forward "^,")
869 (narrow-to-region beg (point))
872 (while (search-forward "\"" nil t)
876 (skip-chars-forward ",")
877 (skip-chars-forward "^,"))
878 (skip-chars-backward " ")
879 (push (buffer-substring beg (point))
881 (skip-chars-forward "^,")
882 (skip-chars-forward ", "))
885 (defun gnus-inews-add-to-address (group)
886 (let ((to-address (mail-fetch-field "to")))
887 (when (and to-address
889 ;; This mail group doesn't have a `to-list', so we add one
892 (format "Do you want to add this as `to-list': %s " to-address))
893 (gnus-group-add-parameter group (cons 'to-list to-address))))))
895 (defun gnus-put-message ()
896 "Put the current message in some group and return to Gnus."
898 (let ((reply gnus-article-reply)
899 (winconf gnus-prev-winconf)
900 (group gnus-newsgroup-name))
902 (or (and group (not (gnus-group-read-only-p group)))
903 (setq group (read-string "Put in group: " nil
904 (gnus-writable-groups))))
905 (when (gnus-gethash group gnus-newsrc-hashtb)
906 (error "No such group: %s" group))
911 (message-narrow-to-headers)
912 (let (gnus-deletable-headers)
914 (message-generate-headers message-required-news-headers)
915 (message-generate-headers message-required-mail-headers)))
916 (goto-char (point-max))
917 (insert "Gcc: " group "\n")
922 (when (get-buffer gnus-group-buffer)
923 (when (gnus-buffer-exists-p (car-safe reply))
924 (set-buffer (car reply))
926 (gnus-summary-mark-article-as-replied
929 (set-window-configuration winconf)))))
931 (defun gnus-article-mail (yank)
932 "Send a reply to the address near point.
933 If YANK is non-nil, include the original article."
937 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
938 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
940 (message-reply address)
942 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
944 (defvar nntp-server-type)
946 "Send a bug report to the Gnus maintainers."
948 (unless (gnus-alive-p)
949 (error "Gnus has been shut down"))
950 (gnus-setup-message 'bug
951 (delete-other-windows)
952 (when gnus-bug-create-help-buffer
953 (switch-to-buffer "*Gnus Help Bug*")
955 (insert gnus-bug-message)
956 (goto-char (point-min)))
957 (message-pop-to-buffer "*Gnus Bug*")
958 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
959 (when gnus-bug-create-help-buffer
960 (push `(gnus-bug-kill-buffer) message-send-actions))
961 (goto-char (point-min))
962 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
964 (insert gnus-product-name " " gnus-version-number
965 " (r" gnus-revision-number ") "
966 "based on " gnus-original-product-name " v"
967 gnus-original-version-number "\n"
968 (emacs-version) "\n")
969 (when (and (boundp 'nntp-server-type)
970 (stringp nntp-server-type))
971 (insert nntp-server-type))
972 (insert "\n\n\n\n\n")
973 (let (mime-content-types)
974 (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
975 (insert (with-temp-buffer
978 (goto-char (point-min))
979 (search-forward "Subject: " nil t)
982 (defun gnus-bug-kill-buffer ()
983 (when (get-buffer "*Gnus Help Bug*")
984 (kill-buffer "*Gnus Help Bug*")))
986 (defun gnus-summary-yank-message (buffer n)
987 "Yank the current article into a composed message."
989 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
991 (when (gnus-buffer-live-p buffer)
992 (let ((summary-frame (selected-frame))
993 (message-frame (when (static-if (featurep 'xemacs)
994 (device-on-window-system-p)
996 (let ((window (get-buffer-window buffer t)))
998 (window-frame window)))))
999 (separator (concat "^" (regexp-quote mail-header-separator)
1001 (gnus-summary-iterate n
1002 (gnus-summary-select-article)
1003 (gnus-copy-article-buffer)
1004 (when (frame-live-p message-frame)
1005 (raise-frame message-frame)
1006 (select-frame message-frame))
1007 (with-current-buffer buffer
1008 (when (save-excursion
1010 (let (case-fold-search)
1011 (and (not (re-search-backward separator nil t))
1012 (re-search-forward separator nil t))))
1013 (goto-char (match-end 0)))
1014 (message-yank-buffer gnus-article-copy))
1015 (select-frame summary-frame))
1016 (when (frame-live-p message-frame)
1017 (select-frame message-frame)))))
1019 (defun gnus-debug ()
1020 "Attempts to go through the Gnus source file and report what variables have been changed.
1021 The source file has to be in the Emacs load path."
1023 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1024 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1025 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1026 "nnmail.el" "message.el"))
1028 file expr olist sym)
1029 (gnus-message 4 "Please wait while we snoop your variables...")
1031 ;; Go through all the files looking for non-default values for variables.
1033 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1036 (when (and (setq file (locate-library (pop files)))
1037 (file-exists-p file))
1038 (insert-file-contents file)
1039 (goto-char (point-min))
1040 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1041 (gnus-message 4 "Malformed sources in file %s" file)
1042 (narrow-to-region (point-min) (point))
1043 (goto-char (point-min))
1044 (while (setq expr (ignore-errors (read (current-buffer))))
1046 (and (or (eq (car expr) 'defvar)
1047 (eq (car expr) 'defcustom))
1048 (stringp (nth 3 expr))
1049 (or (not (boundp (nth 1 expr)))
1050 (not (equal (eval (nth 2 expr))
1051 (symbol-value (nth 1 expr)))))
1052 (push (nth 1 expr) olist)))))))
1053 (kill-buffer (current-buffer)))
1054 (when (setq olist (nreverse olist))
1055 (insert "------------------ Environment follows ------------------\n\n"))
1057 (if (boundp (car olist))
1059 (pp `(setq ,(car olist)
1060 ,(if (or (consp (setq sym (symbol-value (car olist))))
1062 (not (or (eq sym nil)
1064 (list 'quote (symbol-value (car olist)))
1065 (symbol-value (car olist))))
1068 (format "(setq %s 'whatever)\n" (car olist))))
1069 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1070 (setq olist (cdr olist)))
1072 ;; Remove any control chars - they seem to cause trouble for some
1073 ;; mailers. (Byte-compiled output from the stuff above.)
1075 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1076 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1079 ;;; Treatment of rejected articles.
1082 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1083 "Re-mail the current message.
1084 This only makes sense if the current message is a bounce message than
1085 contains some mail you have written which has been bounced back to
1087 If FETCH, try to fetch the article that this is a reply to, if indeed
1090 (gnus-summary-select-article t)
1091 (set-buffer gnus-original-article-buffer)
1092 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1093 (gnus-setup-message 'compose-bounce
1094 (let* ((references (mail-fetch-field "references"))
1095 (parent (and references (gnus-parent-id references))))
1097 ;; If there are references, we fetch the article we answered to.
1099 (gnus-summary-refer-article parent)
1100 (gnus-summary-show-all-headers))))))
1104 ;; Do Gcc handling, which copied the message over to some group.
1105 (defun gnus-inews-do-gcc (&optional gcc)
1107 (when (gnus-alive-p)
1110 (message-narrow-to-headers)
1111 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1112 (coding-system-for-write 'raw-text)
1113 (output-coding-system 'raw-text)
1114 groups group method)
1116 (message-remove-header "gcc")
1118 (setq groups (message-tokenize-header gcc " ,"))
1119 ;; Copy the article over to some group(s).
1120 (while (setq group (pop groups))
1123 (cond ((and (null (gnus-get-info group))
1124 (eq (car gnus-message-archive-method)
1126 (gnus-server-to-method
1127 (gnus-group-method group)))))
1128 ;; If the group doesn't exist, we assume
1129 ;; it's an archive group...
1130 gnus-message-archive-method)
1132 ((gnus-info-method (gnus-get-info group))
1133 (gnus-info-method (gnus-get-info group)))
1135 (t (gnus-group-method group)))))
1136 (gnus-check-server method)
1137 (unless (gnus-request-group group t method)
1138 (gnus-request-create-group group method))
1140 (nnheader-set-temp-buffer " *acc*")
1141 (insert-buffer-substring message-encoding-buffer)
1142 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1143 (goto-char (point-min))
1144 (when (re-search-forward
1145 (concat "^" (regexp-quote mail-header-separator) "$")
1147 (replace-match "" t t ))
1148 (unless (gnus-request-accept-article group method t t)
1149 (gnus-message 1 "Couldn't store article in group %s: %s"
1150 group (gnus-status-message method))
1152 (kill-buffer (current-buffer))))))))))
1154 (defun gnus-inews-insert-gcc ()
1155 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1158 (message-narrow-to-headers)
1159 (let* ((group gnus-outgoing-message-group)
1161 ((gnus-functionp group)
1163 ((or (stringp group) (list group))
1167 (if (stringp gcc) gcc
1168 (mapconcat 'identity gcc " "))
1171 (defun gnus-inews-insert-archive-gcc (&optional group)
1172 "Insert the Gcc to say where the article is to be archived."
1173 (let* ((var gnus-message-archive-group)
1174 (group (or group gnus-newsgroup-name ""))
1176 (and gnus-newsgroup-name
1177 (gnus-group-find-parameter
1178 gnus-newsgroup-name 'gcc-self)))
1182 ((null gnus-message-archive-method)
1186 ;; Just a single group.
1189 ;; We don't want this.
1191 ((and (listp var) (stringp (car var)))
1192 ;; A list of groups.
1194 ((gnus-functionp var)
1196 (funcall var group))
1198 ;; An alist of regexps/functions/forms.
1203 ((stringp (caar var))
1205 (when (string-match (caar var) group)
1207 ((gnus-functionp (car var))
1209 (funcall (car var) group))
1211 (eval (car var)))))))
1212 (setq var (cdr var)))
1215 (when (or groups gcc-self-val)
1216 (when (stringp groups)
1217 (setq groups (list groups)))
1220 (message-narrow-to-headers)
1221 (goto-char (point-max))
1224 ;; Use the `gcc-self' param value instead.
1227 (if (stringp gcc-self-val)
1230 (if (not (eq gcc-self-val 'none))
1235 ;; Use the list of groups.
1236 (while (setq name (pop groups))
1237 (insert (if (string-match ":" name)
1239 (gnus-group-prefixed-name
1240 name gnus-message-archive-method)))
1247 (defun gnus-configure-posting-styles ()
1248 "Configure posting styles according to `gnus-posting-styles'."
1249 (unless gnus-inhibit-posting-styles
1250 (let ((group (or gnus-newsgroup-name ""))
1251 (styles gnus-posting-styles)
1252 style match variable attribute value v results
1253 filep name address element)
1254 ;; If the group has a posting-style parameter, add it at the end with a
1255 ;; regexp matching everything, to be sure it takes precedence over all
1257 (when gnus-newsgroup-name
1258 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1260 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1261 ;; Go through all styles and look for matches.
1262 (dolist (style styles)
1263 (setq match (pop style))
1264 (goto-char (point-min))
1267 ;; Regexp string match on the group name.
1268 (string-match match group))
1270 (let ((header (message-fetch-field (pop style))))
1272 (string-match (pop style) header))))
1273 ((or (symbolp match)
1274 (gnus-functionp match))
1276 ((gnus-functionp match)
1277 ;; Function to be called.
1280 ;; Variable to be checked.
1281 (symbol-value match))))
1283 ;; This is a form to be evaled.
1285 ;; We have a match, so we set the variables.
1286 (dolist (attribute style)
1287 (setq element (pop attribute)
1292 ((eq (car attribute) ':file)
1295 ((eq (car attribute) :value)
1299 ;; We get the value.
1304 ((or (symbolp value)
1305 (gnus-functionp value))
1306 (cond ((gnus-functionp value)
1309 (symbol-value value))))
1312 ;; Translate obsolescent value.
1313 (when (eq element 'signature-file)
1314 (setq element 'signature
1316 ;; Get the contents of file elems.
1318 (setq v (with-temp-buffer
1319 (insert-file-contents v)
1321 (setq results (delq (assoc element results) results))
1322 (push (cons element v) results))))
1323 ;; Now we have all the styles, so we insert them.
1324 (setq name (assq 'name results)
1325 address (assq 'address results))
1326 (setq results (delq name (delq address results)))
1327 (make-local-variable 'message-setup-hook)
1328 (dolist (result results)
1330 (add-hook 'message-setup-hook
1332 ((eq 'eval (car result))
1334 ((eq 'body (car result))
1338 (insert ,(cdr result)))))
1339 ((eq 'signature (car result))
1340 (set (make-local-variable 'message-signature) nil)
1341 (set (make-local-variable 'message-signature-file) nil)
1342 (if (not (cdr result))
1346 (let ((message-signature ,(cdr result)))
1347 (when message-signature
1348 (message-insert-signature)))))))
1351 (if (symbolp (car result))
1352 (capitalize (symbol-name (car result)))
1356 (message-remove-header ,header)
1358 (insert ,header ": " ,(cdr result) "\n")))))))))
1359 (when (or name address)
1360 (add-hook 'message-setup-hook
1362 (set (make-local-variable 'user-mail-address)
1363 ,(or (cdr address) user-mail-address))
1364 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1366 ,(or (cdr address) user-mail-address)))
1368 (message-remove-header "From")
1370 (insert "From: " (message-make-from) "\n")))))))))
1373 ;;; @ for MIME Edit mode
1376 (defun gnus-maybe-setup-default-charset ()
1378 (and (boundp 'gnus-summary-buffer)
1379 (buffer-live-p gnus-summary-buffer)
1381 (set-buffer gnus-summary-buffer)
1382 default-mime-charset))))
1385 (make-local-variable 'default-mime-charset)
1386 (setq default-mime-charset charset)
1390 ;;; @ for MIME view mode
1393 (defun gnus-following-method (buf)
1394 (gnus-setup-message 'reply-yank
1396 (if (message-news-p)
1398 (message-reply nil 'wide))
1399 (let ((message-reply-buffer buf))
1400 (message-yank-original))
1401 (message-goto-body))
1405 ;;; Allow redefinition of functions.
1411 ;;; gnus-msg.el ends here