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-extended-version ()
649 "Stringified gnus version."
650 (concat gnus-product-name "/" gnus-version-number
652 gnus-original-product-name " v" gnus-original-version-number ")"
653 (if (zerop (string-to-number gnus-revision-number))
655 (concat " (revision " gnus-revision-number ")"))
658 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
659 "Return user-agent info.
660 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
661 `mime-edit-user-agent-value' exists, the return value will include it.
662 MAX-COLUMN the optional second argument if it is specified, the return value
663 will be folded up in the proper way."
664 (let ((user-agent (if (and include-mime-info
665 (boundp 'mime-edit-user-agent-value))
666 (concat (gnus-extended-version)
668 mime-edit-user-agent-value)
669 (gnus-extended-version))))
672 (unless (natnump max-column) (setq max-column 76))
674 (insert " " user-agent)
676 (while (re-search-forward "[\n\t ]+" nil t)
679 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
680 (while (eq ?\( (char-after (point)))
682 (skip-chars-forward " "))
683 (skip-chars-backward " ")
684 (if (> (current-column) max-column)
686 (if (or (not boundary) (eq ?\n (char-after boundary)))
688 (setq boundary (point))
695 (setq boundary (point))))
696 (buffer-substring 13 (point-max))))
701 ;;; Gnus Mail Functions
704 ;;; Mail reply commands of Gnus summary mode
706 (defun gnus-summary-reply (&optional yank wide)
707 "Start composing a reply mail to the current message.
708 If prefix argument YANK is non-nil, the original article is yanked
711 (list (and current-prefix-arg
712 (gnus-summary-work-articles 1))))
713 ;; Stripping headers should be specified with mail-yank-ignored-headers.
715 (gnus-summary-goto-subject (car yank)))
716 (let ((gnus-article-reply t))
717 (gnus-setup-message (if yank 'reply-yank 'reply)
718 (gnus-summary-select-article)
719 (set-buffer (gnus-copy-article-buffer))
720 (gnus-msg-treat-broken-reply-to)
721 (message-reply nil wide)
723 (gnus-inews-yank-articles yank)))))
725 (defun gnus-summary-reply-with-original (n &optional wide)
726 "Start composing a reply mail to the current message.
727 The original article will be yanked."
729 (gnus-summary-reply (gnus-summary-work-articles n) wide))
731 (defun gnus-summary-wide-reply (&optional yank)
732 "Start composing a wide reply mail to the current message.
733 If prefix argument YANK is non-nil, the original article is yanked
736 (list (and current-prefix-arg
737 (gnus-summary-work-articles 1))))
738 (gnus-summary-reply yank t))
740 (defun gnus-summary-wide-reply-with-original (n)
741 "Start composing a wide reply mail to the current message.
742 The original article will be yanked."
744 (gnus-summary-reply-with-original n t))
746 (defun gnus-summary-mail-forward (&optional full-headers post)
747 "Forward the current message to another user.
748 If FULL-HEADERS (the prefix), include full headers when forwarding."
750 (gnus-setup-message 'forward
751 (gnus-summary-select-article)
752 (let ((charset default-mime-charset))
753 (set-buffer gnus-original-article-buffer)
754 (make-local-variable 'default-mime-charset)
755 (setq default-mime-charset charset)
757 (let ((message-included-forward-headers
758 (if full-headers "" message-included-forward-headers)))
759 (message-forward post))))
761 ;;; XXX: generate Subject and ``Topics''?
762 (defun gnus-summary-mail-digest (&optional n post)
763 "Digests and forwards all articles in this series."
765 (let ((subject "Digested Articles")
766 (articles (gnus-summary-work-articles n))
768 (gnus-setup-message 'forward
769 (gnus-summary-select-article)
770 (if post (message-news nil subject) (message-mail nil subject))
771 (when (and message-use-multi-frames (cdr articles))
772 (setq frame (window-frame (get-buffer-window (current-buffer)))))
774 (while (setq article (pop articles))
775 (save-window-excursion
776 (set-buffer gnus-summary-buffer)
777 (gnus-summary-select-article nil nil nil article)
778 (gnus-summary-remove-process-mark article))
780 (select-frame frame))
781 (insert (mime-make-tag "message" "rfc822") "\n")
782 (insert-buffer-substring gnus-original-article-buffer))
785 (mime-edit-enclose-digest-region (point)(mark t)))))
787 (defun gnus-summary-post-digest (&optional n)
788 "Digest and forwards all articles in this series to a newsgroup."
790 (gnus-summary-mail-digest n t))
792 (defun gnus-summary-resend-message (address n)
793 "Resend the current article to ADDRESS."
794 (interactive "sResend message(s) to: \nP")
795 (let ((articles (gnus-summary-work-articles n))
797 (while (setq article (pop articles))
798 (gnus-summary-select-article nil nil nil article)
800 (set-buffer gnus-original-article-buffer)
801 (message-resend address)))))
803 (defun gnus-summary-post-forward (&optional full-headers)
804 "Forward the current article to a newsgroup.
805 If FULL-HEADERS (the prefix), include full headers when forwarding."
807 (gnus-summary-mail-forward full-headers t))
809 (defvar gnus-nastygram-message
810 "The following article was inappropriately posted to %s.\n\n"
811 "Format string to insert in nastygrams.
812 The current group name will be inserted at \"%s\".")
814 (defun gnus-summary-mail-nastygram (n)
815 "Send a nastygram to the author of the current article."
817 (when (or gnus-expert-user
819 "Really send a nastygram to the author of the current article? "))
820 (let ((group gnus-newsgroup-name))
821 (gnus-summary-reply-with-original n)
822 (set-buffer gnus-message-buffer)
824 (insert (format gnus-nastygram-message group))
825 (message-send-and-exit))))
827 (defun gnus-summary-mail-crosspost-complaint (n)
828 "Send a complaint about crossposting to the current article(s)."
830 (let ((articles (gnus-summary-work-articles n))
832 (while (setq article (pop articles))
833 (set-buffer gnus-summary-buffer)
834 (gnus-summary-goto-subject article)
835 (let ((group (gnus-group-real-name gnus-newsgroup-name))
836 newsgroups followup-to)
837 (gnus-summary-select-article)
838 (set-buffer gnus-original-article-buffer)
839 (if (and (<= (length (message-tokenize-header
841 (mail-fetch-field "newsgroups"))
844 (or (not (setq followup-to (mail-fetch-field "followup-to")))
845 (not (member group (message-tokenize-header
846 followup-to ", ")))))
848 (gnus-message 1 "Followup-to restricted")
849 (gnus-message 1 "Not a crossposted article"))
850 (set-buffer gnus-summary-buffer)
851 (gnus-summary-reply-with-original 1)
852 (set-buffer gnus-message-buffer)
854 (insert (format gnus-crosspost-complaint newsgroups group))
855 (message-goto-subject)
856 (re-search-forward " *$")
857 (replace-match " (crosspost notification)" t t)
858 (gnus-deactivate-mark)
859 (when (gnus-y-or-n-p "Send this complaint? ")
860 (message-send-and-exit)))))))
862 (defun gnus-summary-mail-other-window ()
863 "Compose mail in other window."
865 (gnus-setup-message 'message
868 (defun gnus-mail-parse-comma-list ()
871 (skip-chars-forward " ")
874 (skip-chars-forward "^,")
879 (narrow-to-region beg (point))
882 (while (search-forward "\"" nil t)
886 (skip-chars-forward ",")
887 (skip-chars-forward "^,"))
888 (skip-chars-backward " ")
889 (push (buffer-substring beg (point))
891 (skip-chars-forward "^,")
892 (skip-chars-forward ", "))
895 (defun gnus-inews-add-to-address (group)
896 (let ((to-address (mail-fetch-field "to")))
897 (when (and to-address
899 ;; This mail group doesn't have a `to-list', so we add one
902 (format "Do you want to add this as `to-list': %s " to-address))
903 (gnus-group-add-parameter group (cons 'to-list to-address))))))
905 (defun gnus-put-message ()
906 "Put the current message in some group and return to Gnus."
908 (let ((reply gnus-article-reply)
909 (winconf gnus-prev-winconf)
910 (group gnus-newsgroup-name))
912 (or (and group (not (gnus-group-read-only-p group)))
913 (setq group (read-string "Put in group: " nil
914 (gnus-writable-groups))))
915 (when (gnus-gethash group gnus-newsrc-hashtb)
916 (error "No such group: %s" group))
921 (message-narrow-to-headers)
922 (let (gnus-deletable-headers)
924 (message-generate-headers message-required-news-headers)
925 (message-generate-headers message-required-mail-headers)))
926 (goto-char (point-max))
927 (insert "Gcc: " group "\n")
932 (when (get-buffer gnus-group-buffer)
933 (when (gnus-buffer-exists-p (car-safe reply))
934 (set-buffer (car reply))
936 (gnus-summary-mark-article-as-replied
939 (set-window-configuration winconf)))))
941 (defun gnus-article-mail (yank)
942 "Send a reply to the address near point.
943 If YANK is non-nil, include the original article."
947 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
948 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
950 (message-reply address)
952 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
954 (defvar nntp-server-type)
956 "Send a bug report to the Gnus maintainers."
958 (unless (gnus-alive-p)
959 (error "Gnus has been shut down"))
960 (gnus-setup-message 'bug
961 (delete-other-windows)
962 (when gnus-bug-create-help-buffer
963 (switch-to-buffer "*Gnus Help Bug*")
965 (insert gnus-bug-message)
966 (goto-char (point-min)))
967 (message-pop-to-buffer "*Gnus Bug*")
968 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
969 (when gnus-bug-create-help-buffer
970 (push `(gnus-bug-kill-buffer) message-send-actions))
971 (goto-char (point-min))
972 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
974 (insert gnus-product-name " " gnus-version-number
975 " (r" gnus-revision-number ") "
976 "based on " gnus-original-product-name " v"
977 gnus-original-version-number "\n"
978 (emacs-version) "\n")
979 (when (and (boundp 'nntp-server-type)
980 (stringp nntp-server-type))
981 (insert nntp-server-type))
982 (insert "\n\n\n\n\n")
983 (let (mime-content-types)
984 (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
985 (insert (with-temp-buffer
988 (goto-char (point-min))
989 (search-forward "Subject: " nil t)
992 (defun gnus-bug-kill-buffer ()
993 (when (get-buffer "*Gnus Help Bug*")
994 (kill-buffer "*Gnus Help Bug*")))
996 (defun gnus-summary-yank-message (buffer n)
997 "Yank the current article into a composed message."
999 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1000 current-prefix-arg))
1001 (gnus-summary-iterate n
1002 (let ((gnus-display-mime-function nil)
1003 (gnus-inhibit-treatment t))
1004 (gnus-summary-select-article))
1007 (message-yank-buffer gnus-article-buffer))))
1009 (defun gnus-debug ()
1010 "Attempts to go through the Gnus source file and report what variables have been changed.
1011 The source file has to be in the Emacs load path."
1013 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1014 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1015 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1016 "nnmail.el" "message.el"))
1018 file expr olist sym)
1019 (gnus-message 4 "Please wait while we snoop your variables...")
1021 ;; Go through all the files looking for non-default values for variables.
1023 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1026 (when (and (setq file (locate-library (pop files)))
1027 (file-exists-p file))
1028 (insert-file-contents file)
1029 (goto-char (point-min))
1030 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1031 (gnus-message 4 "Malformed sources in file %s" file)
1032 (narrow-to-region (point-min) (point))
1033 (goto-char (point-min))
1034 (while (setq expr (ignore-errors (read (current-buffer))))
1036 (and (or (eq (car expr) 'defvar)
1037 (eq (car expr) 'defcustom))
1038 (stringp (nth 3 expr))
1039 (or (not (boundp (nth 1 expr)))
1040 (not (equal (eval (nth 2 expr))
1041 (symbol-value (nth 1 expr)))))
1042 (push (nth 1 expr) olist)))))))
1043 (kill-buffer (current-buffer)))
1044 (when (setq olist (nreverse olist))
1045 (insert "------------------ Environment follows ------------------\n\n"))
1047 (if (boundp (car olist))
1049 (pp `(setq ,(car olist)
1050 ,(if (or (consp (setq sym (symbol-value (car olist))))
1052 (not (or (eq sym nil)
1054 (list 'quote (symbol-value (car olist)))
1055 (symbol-value (car olist))))
1058 (format "(setq %s 'whatever)\n" (car olist))))
1059 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1060 (setq olist (cdr olist)))
1062 ;; Remove any control chars - they seem to cause trouble for some
1063 ;; mailers. (Byte-compiled output from the stuff above.)
1065 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1066 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1069 ;;; Treatment of rejected articles.
1072 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1073 "Re-mail the current message.
1074 This only makes sense if the current message is a bounce message than
1075 contains some mail you have written which has been bounced back to
1077 If FETCH, try to fetch the article that this is a reply to, if indeed
1080 (gnus-summary-select-article t)
1081 (set-buffer gnus-original-article-buffer)
1082 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1083 (gnus-setup-message 'compose-bounce
1084 (let* ((references (mail-fetch-field "references"))
1085 (parent (and references (gnus-parent-id references))))
1087 ;; If there are references, we fetch the article we answered to.
1089 (gnus-summary-refer-article parent)
1090 (gnus-summary-show-all-headers))))))
1094 ;; Do Gcc handling, which copied the message over to some group.
1095 (defun gnus-inews-do-gcc (&optional gcc)
1097 (when (gnus-alive-p)
1100 (message-narrow-to-headers)
1101 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1102 (coding-system-for-write 'raw-text)
1103 (output-coding-system 'raw-text)
1104 groups group method)
1106 (message-remove-header "gcc")
1108 (setq groups (message-tokenize-header gcc " ,"))
1109 ;; Copy the article over to some group(s).
1110 (while (setq group (pop groups))
1113 (cond ((and (null (gnus-get-info group))
1114 (eq (car gnus-message-archive-method)
1116 (gnus-server-to-method
1117 (gnus-group-method group)))))
1118 ;; If the group doesn't exist, we assume
1119 ;; it's an archive group...
1120 gnus-message-archive-method)
1122 ((gnus-info-method (gnus-get-info group))
1123 (gnus-info-method (gnus-get-info group)))
1125 (t (gnus-group-method group)))))
1126 (gnus-check-server method)
1127 (unless (gnus-request-group group t method)
1128 (gnus-request-create-group group method))
1130 (nnheader-set-temp-buffer " *acc*")
1131 (insert-buffer-substring message-encoding-buffer)
1132 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1133 (goto-char (point-min))
1134 (when (re-search-forward
1135 (concat "^" (regexp-quote mail-header-separator) "$")
1137 (replace-match "" t t ))
1138 (unless (gnus-request-accept-article group method t t)
1139 (gnus-message 1 "Couldn't store article in group %s: %s"
1140 group (gnus-status-message method))
1142 (kill-buffer (current-buffer))))))))))
1144 (defun gnus-inews-insert-gcc ()
1145 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1148 (message-narrow-to-headers)
1149 (let* ((group gnus-outgoing-message-group)
1151 ((gnus-functionp group)
1153 ((or (stringp group) (list group))
1157 (if (stringp gcc) gcc
1158 (mapconcat 'identity gcc " "))
1161 (defun gnus-inews-insert-archive-gcc (&optional group)
1162 "Insert the Gcc to say where the article is to be archived."
1163 (let* ((var gnus-message-archive-group)
1164 (group (or group gnus-newsgroup-name ""))
1166 (and gnus-newsgroup-name
1167 (gnus-group-find-parameter
1168 gnus-newsgroup-name 'gcc-self)))
1172 ((null gnus-message-archive-method)
1176 ;; Just a single group.
1179 ;; We don't want this.
1181 ((and (listp var) (stringp (car var)))
1182 ;; A list of groups.
1184 ((gnus-functionp var)
1186 (funcall var group))
1188 ;; An alist of regexps/functions/forms.
1193 ((stringp (caar var))
1195 (when (string-match (caar var) group)
1197 ((gnus-functionp (car var))
1199 (funcall (car var) group))
1201 (eval (car var)))))))
1202 (setq var (cdr var)))
1205 (when (or groups gcc-self-val)
1206 (when (stringp groups)
1207 (setq groups (list groups)))
1210 (message-narrow-to-headers)
1211 (goto-char (point-max))
1214 ;; Use the `gcc-self' param value instead.
1217 (if (stringp gcc-self-val)
1220 (if (not (eq gcc-self-val 'none))
1225 ;; Use the list of groups.
1226 (while (setq name (pop groups))
1227 (insert (if (string-match ":" name)
1229 (gnus-group-prefixed-name
1230 name gnus-message-archive-method)))
1237 (defun gnus-configure-posting-styles ()
1238 "Configure posting styles according to `gnus-posting-styles'."
1239 (unless gnus-inhibit-posting-styles
1240 (let ((group (or gnus-newsgroup-name ""))
1241 (styles gnus-posting-styles)
1242 style match variable attribute value v results
1243 filep name address element)
1244 ;; If the group has a posting-style parameter, add it at the end with a
1245 ;; regexp matching everything, to be sure it takes precedence over all
1247 (when gnus-newsgroup-name
1248 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1250 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1251 ;; Go through all styles and look for matches.
1252 (dolist (style styles)
1253 (setq match (pop style))
1254 (goto-char (point-min))
1257 ;; Regexp string match on the group name.
1258 (string-match match group))
1260 (let ((header (message-fetch-field (pop style))))
1262 (string-match (pop style) header))))
1263 ((or (symbolp match)
1264 (gnus-functionp match))
1266 ((gnus-functionp match)
1267 ;; Function to be called.
1270 ;; Variable to be checked.
1271 (symbol-value match))))
1273 ;; This is a form to be evaled.
1275 ;; We have a match, so we set the variables.
1276 (dolist (attribute style)
1277 (setq element (pop attribute)
1282 ((eq (car attribute) ':file)
1285 ((eq (car attribute) :value)
1289 ;; We get the value.
1294 ((or (symbolp value)
1295 (gnus-functionp value))
1296 (cond ((gnus-functionp value)
1299 (symbol-value value))))
1302 ;; Translate obsolescent value.
1303 (when (eq element 'signature-file)
1304 (setq element 'signature
1306 ;; Get the contents of file elems.
1308 (setq v (with-temp-buffer
1309 (insert-file-contents v)
1311 (setq results (delq (assoc element results) results))
1312 (push (cons element v) results))))
1313 ;; Now we have all the styles, so we insert them.
1314 (setq name (assq 'name results)
1315 address (assq 'address results))
1316 (setq results (delq name (delq address results)))
1317 (make-local-variable 'message-setup-hook)
1318 (dolist (result results)
1320 (add-hook 'message-setup-hook
1322 ((eq 'eval (car result))
1324 ((eq 'body (car result))
1328 (insert ,(cdr result)))))
1329 ((eq 'signature (car result))
1330 (set (make-local-variable 'message-signature) nil)
1331 (set (make-local-variable 'message-signature-file) nil)
1332 (if (not (cdr result))
1336 (let ((message-signature ,(cdr result)))
1337 (when message-signature
1338 (message-insert-signature)))))))
1341 (if (symbolp (car result))
1342 (capitalize (symbol-name (car result)))
1346 (message-remove-header ,header)
1348 (insert ,header ": " ,(cdr result) "\n")))))))))
1349 (when (or name address)
1350 (add-hook 'message-setup-hook
1352 (set (make-local-variable 'user-mail-address)
1353 ,(or (cdr address) user-mail-address))
1354 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1356 ,(or (cdr address) user-mail-address)))
1358 (message-remove-header "From")
1360 (insert "From: " (message-make-from) "\n")))))))))
1363 ;;; @ for MIME Edit mode
1366 (defun gnus-maybe-setup-default-charset ()
1368 (and (boundp 'gnus-summary-buffer)
1369 (buffer-live-p gnus-summary-buffer)
1371 (set-buffer gnus-summary-buffer)
1372 default-mime-charset))))
1375 (make-local-variable 'default-mime-charset)
1376 (setq default-mime-charset charset)
1380 ;;; @ for MIME view mode
1383 (defun gnus-following-method (buf)
1384 (gnus-setup-message 'reply-yank
1386 (if (message-news-p)
1388 (message-reply nil 'wide))
1389 (let ((message-reply-buffer buf))
1390 (message-yank-original))
1391 (message-goto-body))
1395 ;;; Allow redefinition of functions.
1401 ;;; gnus-msg.el ends here