1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
11 ;; Keywords: mail, news, MIME
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl))
35 (eval-when-compile (require 'static))
42 (defcustom gnus-post-method 'current
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 select method when posting.
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\\|fr\\|dk\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\|dk\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
111 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
112 (message-this-is-mail nil nil)
113 (message-this-is-news nil t))
114 "Alist of regexps and permitted unencoded charsets for posting.
115 Each element of the alist has the form (TEST HEADER BODY-LIST), where
116 TEST is either a regular expression matching the newsgroup header or a
118 HEADER is the charset which may be left unencoded in the header (nil
119 means encode all charsets),
120 BODY-LIST is a list of charsets which may be encoded using 8bit
121 content-transfer encoding in the body, or one of the special values
122 nil (always encode using quoted-printable) or t (always use 8bit).
124 Note that any value other than nil for HEADER infringes some RFCs, so
125 use this option with care."
126 :type '(repeat (list :tag "Permitted unencoded charsets"
128 (regexp :tag "Group")
129 (const :tag "Mail message" :value message-this-is-mail)
130 (const :tag "News article" :value message-this-is-news))
131 (choice :tag "Header"
132 (const :tag "None" nil)
133 (symbol :tag "Charset"))
135 (const :tag "Any" :value t)
136 (const :tag "None" :value nil)
137 (repeat :tag "Charsets"
138 (symbol :tag "Charset")))))
139 :group 'gnus-charset)
141 ;;; Internal variables.
143 (defvar gnus-inhibit-posting-styles nil
144 "Inhibit the use of posting styles.")
146 (defvar gnus-message-buffer "*Mail Gnus*")
147 (defvar gnus-article-copy nil)
148 (defvar gnus-last-posting-server nil)
149 (defvar gnus-message-group-art nil)
151 (defconst gnus-bug-message
152 (format "Sending a bug report to the Gnus Towers.
153 ========================================
155 This gnus is the %s%s.
156 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
157 Developers. (the addresses below are mailing list addresses)
159 ========================================
161 The buffer below is a mail buffer. When you press `C-c C-c', it will
162 be sent to the Gnus Bug Exterminators.
164 The thing near the bottom of the buffer is how the environment
165 settings will be included in the mail. Please do not delete that.
166 They will tell the Bug People what your environment is, so that it
167 will be easier to locate the bugs.
169 If you have found a bug that makes Emacs go \"beep\", set
170 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
171 and include the backtrace in your bug report.
173 Please describe the bug in annoying, painstaking detail.
175 Thank you for your help in stamping out bugs.
178 (if (string= gnus-product-name "Semi-gnus")
180 ", a modified version of Semi-gnus")))
183 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
184 (autoload 'news-setup "rnewspost")
185 (autoload 'news-reply-mode "rnewspost")
186 (autoload 'rmail-dont-reply-to "mail-utils")
187 (autoload 'rmail-output "rmailout"))
191 ;;; Gnus Posting Functions
194 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
195 "p" gnus-summary-post-news
196 "f" gnus-summary-followup
197 "F" gnus-summary-followup-with-original
198 "c" gnus-summary-cancel-article
199 "s" gnus-summary-supersede-article
200 "r" gnus-summary-reply
201 "y" gnus-summary-yank-message
202 "R" gnus-summary-reply-with-original
203 "w" gnus-summary-wide-reply
204 "W" gnus-summary-wide-reply-with-original
205 "n" gnus-summary-followup-to-mail
206 "N" gnus-summary-followup-to-mail-with-original
207 "m" gnus-summary-mail-other-window
208 "u" gnus-uu-post-news
209 "\M-c" gnus-summary-mail-crosspost-complaint
210 "om" gnus-summary-mail-forward
211 "op" gnus-summary-post-forward
212 "Om" gnus-uu-digest-mail-forward
213 "Op" gnus-uu-digest-post-forward)
215 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
216 "b" gnus-summary-resend-bounced-mail
217 ;; "c" gnus-summary-send-draft
218 "r" gnus-summary-resend-message)
221 (defun gnus-msg-mail (&rest args)
222 "Start editing a mail message to be sent.
223 Like `message-mail', but with Gnus paraphernalia, particularly the
224 the Gcc: header for archiving purposes."
226 (gnus-setup-message 'message
227 (apply 'message-mail args)))
230 (define-mail-user-agent 'gnus-user-agent
231 'gnus-msg-mail 'message-send-and-exit
232 'message-kill-buffer 'message-send-hook)
234 ;;; Internal functions.
236 (defvar gnus-article-reply nil)
237 (defmacro gnus-setup-message (config &rest forms)
238 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
239 (buffer (make-symbol "gnus-setup-message-buffer"))
240 (article (make-symbol "gnus-setup-message-article"))
241 (group (make-symbol "gnus-setup-message-group")))
242 `(let ((,winconf (current-window-configuration))
243 (,buffer (buffer-name (current-buffer)))
244 (,article (and gnus-article-reply (gnus-summary-article-number)))
245 (,group gnus-newsgroup-name)
246 (message-header-setup-hook
247 (copy-sequence message-header-setup-hook))
248 (message-mode-hook (copy-sequence message-mode-hook))
249 (message-startup-parameter-alist
250 '((reply-buffer . gnus-copy-article-buffer)
251 (original-buffer . gnus-original-article-buffer)
252 (user-agent . Gnus))))
253 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
254 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
255 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
259 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
260 (setq gnus-message-buffer (current-buffer))
261 (set (make-local-variable 'gnus-message-group-art)
262 (cons ,group ,article))
263 (set (make-local-variable 'gnus-newsgroup-name) ,group)
264 (gnus-run-hooks 'gnus-message-setup-hook))
266 (gnus-configure-windows ,config t)
267 (set-buffer-modified-p nil))))
269 (defun gnus-setup-posting-charset (group)
270 (let ((alist gnus-group-posting-charset-alist)
271 (group (or group ""))
275 (while (setq elem (pop alist))
276 (when (or (and (stringp (car elem))
277 (string-match (car elem) group))
278 (and (gnus-functionp (car elem))
279 (funcall (car elem) group))
280 (and (symbolp (car elem))
281 (symbol-value (car elem))))
282 (throw 'found (cons (cadr elem) (caddr elem)))))))))
284 (defun gnus-inews-add-send-actions (winconf buffer article)
285 (make-local-hook 'message-sent-hook)
286 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
287 (setq message-post-method
289 (gnus-post-method arg ,gnus-newsgroup-name)))
290 (setq message-user-agent (gnus-extended-version))
291 (when (not message-use-multi-frames)
293 `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
295 `(when (gnus-buffer-exists-p ,buffer)
299 `(gnus-summary-mark-article-as-replied ,article))))
302 (put 'gnus-setup-message 'lisp-indent-function 1)
303 (put 'gnus-setup-message 'edebug-form-spec '(form body))
305 ;;; Post news commands of Gnus group mode and summary mode
307 (defun gnus-group-mail (&optional arg)
308 "Start composing a mail.
309 If ARG, use the group under the point to find a posting style.
310 If ARG is 1, prompt for a group name to find the posting style."
312 ;; We can't `let' gnus-newsgroup-name here, since that leads
313 ;; to local variables leaking.
314 (let ((group gnus-newsgroup-name)
315 (buffer (current-buffer)))
318 (setq gnus-newsgroup-name
320 (if (= 1 (prefix-numeric-value arg))
321 (completing-read "Use posting style of group: "
322 gnus-active-hashtb nil
323 (gnus-read-active-file-p))
324 (gnus-group-group-name))
326 (gnus-setup-message 'message (message-mail)))
329 (setq gnus-newsgroup-name group)))))
331 (defun gnus-group-post-news (&optional arg)
332 "Start composing a news message.
333 If ARG, post to the group under point.
334 If ARG is 1, prompt for a group name."
336 ;; Bind this variable here to make message mode hooks work ok.
337 (let ((gnus-newsgroup-name
339 (if (= 1 (prefix-numeric-value arg))
340 (completing-read "Newsgroup: " gnus-active-hashtb nil
341 (gnus-read-active-file-p))
342 (gnus-group-group-name))
344 (gnus-post-news 'post gnus-newsgroup-name)))
346 (defun gnus-summary-post-news ()
347 "Start composing a news message."
349 (gnus-post-news 'post gnus-newsgroup-name))
351 (defun gnus-summary-followup (yank &optional force-news)
352 "Compose a followup to an article.
353 If prefix argument YANK is non-nil, original article is yanked automatically."
355 (list (and current-prefix-arg
356 (gnus-summary-work-articles 1))))
358 (gnus-summary-goto-subject (car yank)))
359 (save-window-excursion
360 (gnus-summary-select-article))
361 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
362 (gnus-newsgroup-name gnus-newsgroup-name))
364 (gnus-post-news nil gnus-newsgroup-name
365 headers gnus-article-buffer
366 yank nil force-news)))
368 (defun gnus-summary-followup-with-original (n &optional force-news)
369 "Compose a followup to an article and include the original article."
371 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
373 (defun gnus-summary-followup-to-mail (&optional arg)
374 "Followup to the current mail message via news."
376 (list (and current-prefix-arg
377 (gnus-summary-work-articles 1))))
378 (gnus-summary-followup arg t))
380 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
381 "Followup to the current mail message via news."
383 (gnus-summary-followup (gnus-summary-work-articles arg) t))
385 (defun gnus-inews-yank-articles (articles)
386 (let* ((more-than-one (cdr articles))
387 (frame (when (and message-use-multi-frames more-than-one)
388 (window-frame (get-buffer-window (current-buffer)))))
391 (while (setq article (pop articles))
392 (save-window-excursion
393 (set-buffer gnus-summary-buffer)
394 (gnus-summary-select-article nil nil nil article)
395 (gnus-summary-remove-process-mark article))
397 (select-frame frame))
399 ;; Gathering references.
401 (setq refs (message-list-references
403 (mail-header-references gnus-current-headers)
404 (mail-header-message-id gnus-current-headers))))
406 (gnus-copy-article-buffer)
407 (let ((message-reply-buffer gnus-article-copy)
408 (message-reply-headers gnus-current-headers))
409 (message-yank-original)
410 (setq beg (or beg (mark t))))
415 ;; Replace with the gathered references.
419 (message-narrow-to-headers)
420 (let ((case-fold-search t))
421 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
423 (goto-char (point-max))))
425 (list (or (assq 'References message-header-format-alist)
426 '(References . message-shorten-references)))
427 (list (cons 'References
428 (mapconcat 'identity (nreverse refs) " "))))
429 (backward-delete-char 1))
435 (defun gnus-summary-cancel-article (&optional n symp)
436 "Cancel an article you posted.
437 Uses the process-prefix convention. If given the symbolic
438 prefix `a', cancel using the standard posting method; if not
439 post using the current select method."
440 (interactive (gnus-interactive "P\ny"))
441 (let ((articles (gnus-summary-work-articles n))
444 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
446 (while (setq article (pop articles))
447 (when (gnus-summary-select-article t nil nil article)
448 (when (gnus-eval-in-buffer-window gnus-article-buffer
450 (set-buffer gnus-original-article-buffer)
451 (message-cancel-news)))
452 (gnus-summary-mark-as-read article gnus-canceled-mark)
453 (gnus-cache-remove-article 1))
454 (gnus-article-hide-headers-if-wanted))
455 (gnus-summary-remove-process-mark article))))
457 (defun gnus-summary-supersede-article ()
458 "Compose an article that will supersede a previous article.
459 This is done simply by taking the old article and adding a Supersedes
460 header line with the old Message-ID."
462 (let ((article (gnus-summary-article-number))
463 (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
464 (gnus-setup-message 'reply-yank
465 (gnus-summary-select-article t)
466 (set-buffer gnus-original-article-buffer)
470 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
472 (set-buffer ,gnus-summary-buffer)
473 (gnus-cache-possibly-remove-article ,article nil nil nil t)
474 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
475 message-send-actions))))
479 (defun gnus-copy-article-buffer (&optional article-buffer)
480 ;; make a copy of the article buffer with all text properties removed
481 ;; this copy is in the buffer gnus-article-copy.
482 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
483 ;; this buffer should be passed to all mail/news reply/post routines.
484 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
485 (let ((article-buffer (or article-buffer gnus-article-buffer))
487 (if (not (and (get-buffer article-buffer)
488 (gnus-buffer-exists-p article-buffer)))
489 (error "Can't find any article buffer")
491 (set-buffer article-buffer)
493 ;; Copy over the (displayed) article buffer, delete
494 ;; hidden text and remove text properties.
496 (let ((inhibit-read-only t))
497 (copy-to-buffer gnus-article-copy (point-min) (point-max))
498 (set-buffer gnus-article-copy)
499 ;; Encode bitmap smileys to ordinary text.
500 ;; Possibly, the original text might be restored.
501 (static-unless (featurep 'xemacs)
502 (when (featurep 'smiley-mule)
503 (smiley-encode-buffer)))
504 (gnus-article-delete-text-of-type 'annotation)
505 (gnus-remove-text-with-property 'gnus-prev)
506 (gnus-remove-text-with-property 'gnus-next)
507 (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
510 (buffer-substring-no-properties (point-min) (point-max))
512 ;; Find the original headers.
513 (set-buffer gnus-original-article-buffer)
514 (goto-char (point-min))
515 (while (looking-at message-unix-mail-delimiter)
518 (setq end (or (search-forward "\n\n" nil t) (point)))
519 ;; Delete the headers from the displayed articles.
520 (set-buffer gnus-article-copy)
521 (delete-region (goto-char (point-min))
522 (or (search-forward "\n\n" nil t) (point-max)))
523 ;; Insert the original article headers.
524 (insert-buffer-substring gnus-original-article-buffer beg end)
525 (article-decode-encoded-words)))
528 (defun gnus-post-news (post &optional group header article-buffer yank subject
531 (gnus-copy-article-buffer))
532 (let ((gnus-article-reply article-buffer)
533 (add-to-list gnus-add-to-list))
534 (gnus-setup-message (cond (yank 'reply-yank)
535 (article-buffer 'reply)
537 (let* ((group (or group gnus-newsgroup-name))
538 (charset (gnus-group-name-charset nil group))
540 to-address to-group mailing-list to-list
543 (setq to-address (gnus-group-find-parameter group 'to-address)
544 to-group (gnus-group-find-parameter group 'to-group)
545 to-list (gnus-group-find-parameter group 'to-list)
546 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
547 mailing-list (when gnus-mailing-list-groups
548 (string-match gnus-mailing-list-groups group))
549 group (gnus-group-name-decode (gnus-group-real-name group)
551 (if (or (and to-group
552 (gnus-news-group-p to-group))
555 (and (gnus-news-group-p
556 (or pgroup gnus-newsgroup-name)
557 (if header (mail-header-number header)
558 gnus-current-article))
564 (message-news (or to-group group))
565 (set-buffer gnus-article-copy)
566 (gnus-msg-treat-broken-reply-to)
567 (message-followup (if (or newsgroup-p force-news) nil to-group)))
571 (message-mail (or to-address to-list))
572 ;; Arrange for mail groups that have no `to-address' to
573 ;; get that when the user sends off the mail.
574 (when (and (not to-list)
577 (push (list 'gnus-inews-add-to-address pgroup)
578 message-send-actions)))
579 (set-buffer gnus-article-copy)
580 (gnus-msg-treat-broken-reply-to)
581 (message-wide-reply to-address)))
583 (gnus-inews-yank-articles yank))))))
585 (defun gnus-msg-treat-broken-reply-to ()
586 "Remove the Reply-to header iff broken-reply-to."
587 (when (gnus-group-find-parameter
588 gnus-newsgroup-name 'broken-reply-to)
590 (message-narrow-to-head)
591 (message-remove-header "reply-to"))))
593 (defun gnus-post-method (arg group &optional silent)
594 "Return the posting method based on GROUP and ARG.
595 If SILENT, don't prompt the user."
596 (let ((group-method (gnus-find-method-for-group group)))
598 ;; If the group-method is nil (which shouldn't happen) we use
599 ;; the default method.
601 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
602 gnus-select-method message-post-method))
603 ;; We want the inverse of the default
604 ((and arg (not (eq arg 0)))
605 (if (eq gnus-post-method 'active)
608 ;; We query the user for a post method.
610 (and gnus-post-method
611 (not (eq gnus-post-method 'current))
612 (listp (car gnus-post-method))))
614 ;; Collect all methods we know about.
616 (when (and gnus-post-method
617 (not (eq gnus-post-method 'current)))
618 (if (listp (car gnus-post-method))
620 (list gnus-post-method)))
621 gnus-secondary-select-methods
622 (mapcar 'cdr gnus-server-alist)
623 (mapcar 'car gnus-opened-servers)
624 (list gnus-select-method)
625 (list group-method)))
626 method-alist post-methods method)
627 ;; Weed out all mail methods.
629 (setq method (gnus-server-get-method "" (pop methods)))
630 (when (and (or (gnus-method-option-p method 'post)
631 (gnus-method-option-p method 'post-mail))
632 (not (member method post-methods)))
633 (push method post-methods)))
634 ;; Create a name-method alist.
638 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
643 (setq gnus-last-posting-server
645 gnus-last-posting-server)
646 ;; Just use the last value.
647 gnus-last-posting-server
649 "Posting method: " method-alist nil t
650 (cons (or gnus-last-posting-server "") 0))))
652 ;; Override normal method.
653 ((and (eq gnus-post-method 'current)
654 (not (eq (car group-method) 'nndraft))
655 (gnus-get-function group-method 'request-post t)
658 ((and gnus-post-method
659 (not (eq gnus-post-method 'current)))
661 ;; Use the normal select method.
662 (t gnus-select-method))))
666 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
667 "Return user-agent info.
668 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
669 `mime-edit-user-agent-value' exists, the return value will include it.
670 MAX-COLUMN the optional second argument if it is specified, the return value
671 will be folded up in the proper way."
672 (let ((user-agent (if (and include-mime-info
673 (boundp 'mime-edit-user-agent-value))
674 (concat (gnus-extended-version)
676 mime-edit-user-agent-value)
677 (gnus-extended-version))))
680 (unless (natnump max-column) (setq max-column 76))
682 (insert " " user-agent)
684 (while (re-search-forward "[\n\t ]+" nil t)
687 (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
688 (while (eq ?\( (char-after (point)))
690 (skip-chars-forward " "))
691 (skip-chars-backward " ")
692 (if (> (current-column) max-column)
694 (if (or (not boundary) (eq ?\n (char-after boundary)))
696 (setq boundary (point))
703 (setq boundary (point))))
704 (buffer-substring 13 (point-max))))
709 ;;; Gnus Mail Functions
712 ;;; Mail reply commands of Gnus summary mode
714 (defun gnus-summary-reply (&optional yank wide)
715 "Start composing a reply mail to the current message.
716 If prefix argument YANK is non-nil, the original article is yanked
719 (list (and current-prefix-arg
720 (gnus-summary-work-articles 1))))
721 ;; Stripping headers should be specified with mail-yank-ignored-headers.
723 (gnus-summary-goto-subject (car yank)))
724 (let ((gnus-article-reply t))
725 (gnus-setup-message (if yank 'reply-yank 'reply)
726 (gnus-summary-select-article)
727 (set-buffer (gnus-copy-article-buffer))
728 (gnus-msg-treat-broken-reply-to)
729 (message-reply nil wide)
731 (gnus-inews-yank-articles yank)))))
733 (defun gnus-summary-reply-with-original (n &optional wide)
734 "Start composing a reply mail to the current message.
735 The original article will be yanked."
737 (gnus-summary-reply (gnus-summary-work-articles n) wide))
739 (defun gnus-summary-wide-reply (&optional yank)
740 "Start composing a wide reply mail to the current message.
741 If prefix argument YANK is non-nil, the original article is yanked
744 (list (and current-prefix-arg
745 (gnus-summary-work-articles 1))))
746 (gnus-summary-reply yank t))
748 (defun gnus-summary-wide-reply-with-original (n)
749 "Start composing a wide reply mail to the current message.
750 The original article will be yanked."
752 (gnus-summary-reply-with-original n t))
754 (defun gnus-summary-mail-forward (&optional full-headers post)
755 "Forward the current message to another user.
756 If FULL-HEADERS (the prefix), include full headers when forwarding."
758 (gnus-setup-message 'forward
759 (gnus-summary-select-article)
760 (let ((charset default-mime-charset))
761 (set-buffer gnus-original-article-buffer)
762 (make-local-variable 'default-mime-charset)
763 (setq default-mime-charset charset)
765 (let ((message-included-forward-headers
766 (if full-headers "" message-included-forward-headers)))
767 (message-forward post))))
769 ;;;;; XXX: generate Subject and ``Topics''?
770 ;;(defun gnus-summary-mail-digest (&optional n post)
771 ;; "Digests and forwards all articles in this series."
773 ;; (let ((subject "Digested Articles")
774 ;; (articles (gnus-summary-work-articles n))
776 ;; (gnus-setup-message 'forward
777 ;; (gnus-summary-select-article)
778 ;; (if post (message-news nil subject) (message-mail nil subject))
779 ;; (when (and message-use-multi-frames (cdr articles))
780 ;; (setq frame (window-frame (get-buffer-window (current-buffer)))))
781 ;; (message-goto-body)
782 ;; (while (setq article (pop articles))
783 ;; (save-window-excursion
784 ;; (set-buffer gnus-summary-buffer)
785 ;; (gnus-summary-select-article nil nil nil article)
786 ;; (gnus-summary-remove-process-mark article))
788 ;; (select-frame frame))
789 ;; (insert (mime-make-tag "message" "rfc822") "\n")
790 ;; (insert-buffer-substring gnus-original-article-buffer))
792 ;; (message-goto-body)
793 ;; (mime-edit-enclose-digest-region (point)(mark t)))))
795 ;;(defun gnus-summary-post-digest (&optional n)
796 ;; "Digest and forwards all articles in this series to a newsgroup."
798 ;; (gnus-summary-mail-digest n t))
800 (defun gnus-summary-resend-message (address n)
801 "Resend the current article to ADDRESS."
802 (interactive "sResend message(s) to: \nP")
803 (let ((articles (gnus-summary-work-articles n))
805 (while (setq article (pop articles))
806 (gnus-summary-select-article nil nil nil article)
808 (set-buffer gnus-original-article-buffer)
809 (message-resend address)))))
811 (defun gnus-summary-post-forward (&optional full-headers)
812 "Forward the current article to a newsgroup.
813 If FULL-HEADERS (the prefix), include full headers when forwarding."
815 (gnus-summary-mail-forward full-headers t))
817 (defvar gnus-nastygram-message
818 "The following article was inappropriately posted to %s.\n\n"
819 "Format string to insert in nastygrams.
820 The current group name will be inserted at \"%s\".")
822 (defun gnus-summary-mail-nastygram (n)
823 "Send a nastygram to the author of the current article."
825 (when (or gnus-expert-user
827 "Really send a nastygram to the author of the current article? "))
828 (let ((group gnus-newsgroup-name))
829 (gnus-summary-reply-with-original n)
830 (set-buffer gnus-message-buffer)
832 (insert (format gnus-nastygram-message group))
833 (message-send-and-exit))))
835 (defun gnus-summary-mail-crosspost-complaint (n)
836 "Send a complaint about crossposting to the current article(s)."
838 (let ((articles (gnus-summary-work-articles n))
840 (while (setq article (pop articles))
841 (set-buffer gnus-summary-buffer)
842 (gnus-summary-goto-subject article)
843 (let ((group (gnus-group-real-name gnus-newsgroup-name))
844 newsgroups followup-to)
845 (gnus-summary-select-article)
846 (set-buffer gnus-original-article-buffer)
847 (if (and (<= (length (message-tokenize-header
849 (mail-fetch-field "newsgroups"))
852 (or (not (setq followup-to (mail-fetch-field "followup-to")))
853 (not (member group (message-tokenize-header
854 followup-to ", ")))))
856 (gnus-message 1 "Followup-to restricted")
857 (gnus-message 1 "Not a crossposted article"))
858 (set-buffer gnus-summary-buffer)
859 (gnus-summary-reply-with-original 1)
860 (set-buffer gnus-message-buffer)
862 (insert (format gnus-crosspost-complaint newsgroups group))
863 (message-goto-subject)
864 (re-search-forward " *$")
865 (replace-match " (crosspost notification)" t t)
866 (gnus-deactivate-mark)
867 (when (gnus-y-or-n-p "Send this complaint? ")
868 (message-send-and-exit)))))))
870 (defun gnus-summary-mail-other-window ()
871 "Compose mail in other window."
873 (gnus-setup-message 'message
876 (defun gnus-mail-parse-comma-list ()
879 (skip-chars-forward " ")
882 (skip-chars-forward "^,")
887 (narrow-to-region beg (point))
890 (while (search-forward "\"" nil t)
894 (skip-chars-forward ",")
895 (skip-chars-forward "^,"))
896 (skip-chars-backward " ")
897 (push (buffer-substring beg (point))
899 (skip-chars-forward "^,")
900 (skip-chars-forward ", "))
903 (defun gnus-inews-add-to-address (group)
904 (let ((to-address (mail-fetch-field "to")))
905 (when (and to-address
907 ;; This mail group doesn't have a `to-list', so we add one
910 (format "Do you want to add this as `to-list': %s " to-address))
911 (gnus-group-add-parameter group (cons 'to-list to-address))))))
913 (defun gnus-put-message ()
914 "Put the current message in some group and return to Gnus."
916 (let ((reply gnus-article-reply)
917 (winconf gnus-prev-winconf)
918 (group gnus-newsgroup-name))
920 (or (and group (not (gnus-group-read-only-p group)))
921 (setq group (read-string "Put in group: " nil
922 (gnus-writable-groups))))
923 (when (gnus-gethash group gnus-newsrc-hashtb)
924 (error "No such group: %s" group))
929 (message-narrow-to-headers)
930 (let (gnus-deletable-headers)
932 (message-generate-headers message-required-news-headers)
933 (message-generate-headers message-required-mail-headers)))
934 (goto-char (point-max))
935 (insert "Gcc: " group "\n")
940 (when (get-buffer gnus-group-buffer)
941 (when (gnus-buffer-exists-p (car-safe reply))
942 (set-buffer (car reply))
944 (gnus-summary-mark-article-as-replied
947 (set-window-configuration winconf)))))
949 (defun gnus-article-mail (yank)
950 "Send a reply to the address near point.
951 If YANK is non-nil, include the original article."
955 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
956 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
958 (message-reply address)
960 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
962 (defvar nntp-server-type)
964 "Send a bug report to the Gnus maintainers."
966 (unless (gnus-alive-p)
967 (error "Gnus has been shut down"))
968 (gnus-setup-message 'bug
969 (delete-other-windows)
970 (when gnus-bug-create-help-buffer
971 (switch-to-buffer "*Gnus Help Bug*")
973 (insert gnus-bug-message)
974 (goto-char (point-min)))
975 (message-pop-to-buffer "*Gnus Bug*")
976 (message-setup `((To . ,gnus-maintainer) (Subject . "")))
977 (when gnus-bug-create-help-buffer
978 (push `(gnus-bug-kill-buffer) message-send-actions))
979 (goto-char (point-min))
980 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
982 (insert gnus-product-name " " gnus-version-number
983 " (r" gnus-revision-number ") "
984 "based on " gnus-original-product-name " v"
985 gnus-original-version-number "\n"
986 (emacs-version) "\n")
987 (when (and (boundp 'nntp-server-type)
988 (stringp nntp-server-type))
989 (insert nntp-server-type))
990 (insert "\n\n\n\n\n")
991 (let (mime-content-types)
992 (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
993 (insert (with-temp-buffer
996 (let (mime-content-types)
997 (mime-edit-insert-tag "text" "plain"))
998 (goto-char (point-min))
999 (search-forward "Subject: " nil t)
1002 (defun gnus-bug-kill-buffer ()
1003 (when (get-buffer "*Gnus Help Bug*")
1004 (kill-buffer "*Gnus Help Bug*")))
1006 (defun gnus-summary-yank-message (buffer n)
1007 "Yank the current article into a composed message."
1009 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1010 current-prefix-arg))
1011 (when (gnus-buffer-live-p buffer)
1012 (let ((summary-frame (selected-frame))
1013 (message-frame (when (static-if (featurep 'xemacs)
1014 (device-on-window-system-p)
1016 (let ((window (get-buffer-window buffer t)))
1018 (window-frame window)))))
1019 (separator (concat "^" (regexp-quote mail-header-separator)
1021 (gnus-summary-iterate n
1022 (gnus-summary-select-article)
1023 (gnus-copy-article-buffer)
1024 (when (frame-live-p message-frame)
1025 (raise-frame message-frame)
1026 (select-frame message-frame))
1027 (with-current-buffer buffer
1028 (when (save-excursion
1030 (let (case-fold-search)
1031 (and (not (re-search-backward separator nil t))
1032 (re-search-forward separator nil t))))
1033 (goto-char (match-end 0)))
1034 (message-yank-buffer gnus-article-copy))
1035 (select-frame summary-frame))
1036 (when (frame-live-p message-frame)
1037 (select-frame message-frame)))))
1039 (defun gnus-debug ()
1040 "Attempts to go through the Gnus source file and report what variables have been changed.
1041 The source file has to be in the Emacs load path."
1043 (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1044 "gnus-art.el" "gnus-start.el" "gnus-async.el"
1045 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1046 "nnmail.el" "nntp.el" "message.el"))
1048 file expr olist sym)
1049 (gnus-message 4 "Please wait while we snoop your variables...")
1051 ;; Go through all the files looking for non-default values for variables.
1053 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1056 (when (and (setq file (locate-library (pop files)))
1057 (file-exists-p file))
1058 (insert-file-contents file)
1059 (goto-char (point-min))
1060 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1061 (gnus-message 4 "Malformed sources in file %s" file)
1062 (narrow-to-region (point-min) (point))
1063 (goto-char (point-min))
1064 (while (setq expr (ignore-errors (read (current-buffer))))
1066 (and (memq (car expr) '(defvar defcustom defvoo))
1067 (stringp (nth 3 expr))
1068 (or (not (boundp (nth 1 expr)))
1069 (not (equal (eval (nth 2 expr))
1070 (symbol-value (nth 1 expr)))))
1071 (push (nth 1 expr) olist)))))))
1072 (kill-buffer (current-buffer)))
1073 (when (setq olist (nreverse olist))
1074 (insert ";----------------- Environment follows ------------------\n\n"))
1076 (if (boundp (car olist))
1078 (pp `(setq ,(car olist)
1079 ,(if (or (consp (setq sym (symbol-value (car olist))))
1081 (not (or (eq sym nil)
1083 (list 'quote (symbol-value (car olist)))
1084 (symbol-value (car olist))))
1087 (format "(setq %s 'whatever)\n" (car olist))))
1088 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1089 (setq olist (cdr olist)))
1090 ;; Remove any control chars - they seem to cause trouble for some
1091 ;; mailers. (Byte-compiled output from the stuff above.)
1093 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1094 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1096 ;; Break MIME tags purposely.
1098 (while (re-search-forward mime-edit-tag-regexp nil t)
1099 (goto-char (1+ (match-beginning 0)))
1102 ;;; Treatment of rejected articles.
1105 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1106 "Re-mail the current message.
1107 This only makes sense if the current message is a bounce message than
1108 contains some mail you have written which has been bounced back to
1110 If FETCH, try to fetch the article that this is a reply to, if indeed
1113 (gnus-summary-select-article t)
1114 (set-buffer gnus-original-article-buffer)
1115 (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1116 (gnus-setup-message 'compose-bounce
1117 (let* ((references (mail-fetch-field "references"))
1118 (parent (and references (gnus-parent-id references))))
1120 ;; If there are references, we fetch the article we answered to.
1122 (gnus-summary-refer-article parent)
1123 (gnus-summary-show-all-headers))))))
1127 ;; Do Gcc handling, which copied the message over to some group.
1128 (defun gnus-inews-do-gcc (&optional gcc)
1130 (when (gnus-alive-p)
1133 (message-narrow-to-headers)
1134 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1135 (coding-system-for-write 'raw-text)
1136 (output-coding-system 'raw-text)
1137 groups group method)
1139 (message-remove-header "gcc")
1141 (setq groups (message-unquote-tokens
1142 (message-tokenize-header gcc " ,")))
1143 ;; Copy the article over to some group(s).
1144 (while (setq group (pop groups))
1147 (cond ((and (null (gnus-get-info group))
1148 (eq (car gnus-message-archive-method)
1150 (gnus-server-to-method
1151 (gnus-group-method group)))))
1152 ;; If the group doesn't exist, we assume
1153 ;; it's an archive group...
1154 gnus-message-archive-method)
1156 ((gnus-info-method (gnus-get-info group))
1157 (gnus-info-method (gnus-get-info group)))
1159 (t (gnus-group-method group)))))
1160 (gnus-check-server method)
1161 (unless (gnus-request-group group t method)
1162 (gnus-request-create-group group method))
1164 (nnheader-set-temp-buffer " *acc*")
1165 (insert-buffer-substring message-encoding-buffer)
1166 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1167 (goto-char (point-min))
1168 (when (re-search-forward
1169 (concat "^" (regexp-quote mail-header-separator) "$")
1171 (replace-match "" t t ))
1172 (unless (gnus-request-accept-article group method t t)
1173 (gnus-message 1 "Couldn't store article in group %s: %s"
1174 group (gnus-status-message method))
1176 (kill-buffer (current-buffer))))))))))
1178 (defun gnus-inews-insert-gcc ()
1179 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1182 (message-narrow-to-headers)
1183 (let* ((group gnus-outgoing-message-group)
1185 ((gnus-functionp group)
1187 ((or (stringp group) (list group))
1191 (if (stringp gcc) gcc
1192 (mapconcat 'identity gcc " "))
1195 (defun gnus-inews-insert-archive-gcc (&optional group)
1196 "Insert the Gcc to say where the article is to be archived."
1197 (let* ((var gnus-message-archive-group)
1198 (group (or group gnus-newsgroup-name ""))
1200 (and gnus-newsgroup-name
1201 (not (equal gnus-newsgroup-name ""))
1202 (gnus-group-find-parameter
1203 gnus-newsgroup-name 'gcc-self)))
1207 ((null gnus-message-archive-method)
1211 ;; Just a single group.
1214 ;; We don't want this.
1216 ((and (listp var) (stringp (car var)))
1217 ;; A list of groups.
1219 ((gnus-functionp var)
1221 (funcall var group))
1223 ;; An alist of regexps/functions/forms.
1228 ((stringp (caar var))
1230 (when (string-match (caar var) group)
1232 ((gnus-functionp (car var))
1234 (funcall (car var) group))
1236 (eval (car var)))))))
1237 (setq var (cdr var)))
1240 (when (or groups gcc-self-val)
1241 (when (stringp groups)
1242 (setq groups (list groups)))
1245 (message-narrow-to-headers)
1246 (goto-char (point-max))
1249 ;; Use the `gcc-self' param value instead.
1252 (if (stringp gcc-self-val)
1255 (if (not (eq gcc-self-val 'none))
1260 ;; Use the list of groups.
1261 (while (setq name (pop groups))
1262 (insert (if (string-match ":" name)
1264 (gnus-group-prefixed-name
1265 name gnus-message-archive-method)))
1272 (defun gnus-configure-posting-styles ()
1273 "Configure posting styles according to `gnus-posting-styles'."
1274 (unless gnus-inhibit-posting-styles
1275 (let ((group (or gnus-newsgroup-name ""))
1276 (styles gnus-posting-styles)
1277 style match variable attribute value v results
1278 filep name address element)
1279 ;; If the group has a posting-style parameter, add it at the end with a
1280 ;; regexp matching everything, to be sure it takes precedence over all
1282 (when gnus-newsgroup-name
1283 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1285 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1286 ;; Go through all styles and look for matches.
1287 (dolist (style styles)
1288 (setq match (pop style))
1289 (goto-char (point-min))
1292 ;; Regexp string match on the group name.
1293 (string-match match group))
1295 (let ((header (message-fetch-field (pop style))))
1297 (string-match (pop style) header))))
1298 ((or (symbolp match)
1299 (gnus-functionp match))
1301 ((gnus-functionp match)
1302 ;; Function to be called.
1305 ;; Variable to be checked.
1306 (symbol-value match))))
1308 ;; This is a form to be evaled.
1310 ;; We have a match, so we set the variables.
1311 (dolist (attribute style)
1312 (setq element (pop attribute)
1317 ((eq (car attribute) ':file)
1320 ((eq (car attribute) :value)
1324 ;; We get the value.
1329 ((or (symbolp value)
1330 (gnus-functionp value))
1331 (cond ((gnus-functionp value)
1334 (symbol-value value))))
1337 ;; Translate obsolescent value.
1338 (when (eq element 'signature-file)
1339 (setq element 'signature
1341 ;; Get the contents of file elems.
1343 (setq v (with-temp-buffer
1344 (insert-file-contents v)
1346 (setq results (delq (assoc element results) results))
1347 (push (cons element v) results))))
1348 ;; Now we have all the styles, so we insert them.
1349 (setq name (assq 'name results)
1350 address (assq 'address results))
1351 (setq results (delq name (delq address results)))
1352 (make-local-variable 'message-setup-hook)
1353 (dolist (result results)
1354 (add-hook 'message-setup-hook
1356 ((eq 'eval (car result))
1358 ((eq 'body (car result))
1362 (insert ,(cdr result)))))
1363 ((eq 'signature (car result))
1364 (set (make-local-variable 'message-signature) nil)
1365 (set (make-local-variable 'message-signature-file) nil)
1366 (if (not (cdr result))
1370 (let ((message-signature ,(cdr result)))
1371 (when message-signature
1372 (message-insert-signature)))))))
1375 (if (symbolp (car result))
1376 (capitalize (symbol-name (car result)))
1380 (message-remove-header ,header)
1381 (let ((value ,(cdr result)))
1384 (insert ,header ": " value "\n"))))))))))
1385 (when (or name address)
1386 (add-hook 'message-setup-hook
1388 (set (make-local-variable 'user-mail-address)
1389 ,(or (cdr address) user-mail-address))
1390 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1392 ,(or (cdr address) user-mail-address)))
1394 (message-remove-header "From")
1396 (insert "From: " (message-make-from) "\n")))))))))
1399 ;;; @ for MIME Edit mode
1402 (defun gnus-maybe-setup-default-charset ()
1404 (and (boundp 'gnus-summary-buffer)
1405 (buffer-live-p gnus-summary-buffer)
1407 (set-buffer gnus-summary-buffer)
1408 default-mime-charset))))
1411 (make-local-variable 'default-mime-charset)
1412 (setq default-mime-charset charset)
1416 ;;; @ for MIME view mode
1419 (defun gnus-following-method (buf)
1420 (gnus-setup-message 'reply-yank
1422 (if (message-news-p)
1424 (message-reply nil 'wide))
1425 (let ((message-reply-buffer buf))
1426 (message-yank-original))
1427 (message-goto-body))
1431 ;;; Allow redefinition of functions.
1437 ;;; gnus-msg.el ends here