1 ;;; gnus-msg.el --- mail and post interface for 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>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
36 (defcustom gnus-post-method 'current
37 "*Preferred method for posting USENET news.
39 If this variable is `current', Gnus will use the \"current\" select
40 method when posting. If it is nil (which is the default), Gnus will
41 use the native select method when posting.
43 This method will not be used in mail groups and the like, only in
46 If not nil nor `native', the value must be a valid method as discussed
47 in the documentation of `gnus-select-method'. It can also be a list of
48 methods. If that is the case, the user will be queried for what select
49 method to use when posting."
50 :group 'gnus-group-foreign
51 :type `(choice (const nil)
54 (sexp :tag "Methods" ,gnus-select-method)))
56 (defvar gnus-outgoing-message-group nil
57 "*All outgoing messages will be put in this group.
58 If you want to store all your outgoing mail and articles in the group
59 \"nnml:archive\", you set this variable to that value. This variable
60 can also be a list of group names.
62 If you want to have greater control over what group to put each
63 message in, you can set this variable to a function that checks the
64 current newsgroup name and then returns a suitable group name (or list
67 (defvar gnus-mailing-list-groups nil
68 "*Regexp matching groups that are really mailing lists.
69 This is useful when you're reading a mailing list that has been
70 gatewayed to a newsgroup, and you want to followup to an article in
73 (defvar gnus-add-to-list nil
74 "*If non-nil, add a `to-list' parameter automatically.")
76 (defvar gnus-crosspost-complaint
79 You posted the article below with the following Newsgroups header:
83 The %s group, at least, was an inappropriate recipient
84 of this message. Please trim your Newsgroups header to exclude this
85 group before posting in the future.
90 "Format string to be inserted when complaining about crossposts.
91 The first %s will be replaced by the Newsgroups header;
92 the second with the current group name.")
94 (defvar gnus-message-setup-hook nil
95 "Hook run after setting up a message buffer.")
97 (defvar gnus-bug-create-help-buffer t
98 "*Should we create the *Gnus Help Bug* buffer?")
100 (defvar gnus-posting-styles nil
101 "*Alist of styles to use when posting.")
103 (defcustom gnus-group-posting-charset-alist
104 '(("^no\\." iso-8859-1)
105 ("^de\\." iso-8859-1)
106 (message-this-is-mail nil)
108 (message-this-is-news iso-8859-1))
109 "Alist of regexps (to match group names) and default charsets to be unencoded when posting."
110 :type '(repeat (list (regexp :tag "Group")
111 (symbol :tag "Charset")))
112 :group 'gnus-charset)
114 ;;; Internal variables.
116 (defvar gnus-inhibit-posting-styles nil
117 "Inhibit the use of posting styles.")
119 (defvar gnus-message-buffer "*Mail Gnus*")
120 (defvar gnus-article-copy nil)
121 (defvar gnus-last-posting-server nil)
122 (defvar gnus-message-group-art nil)
124 (defconst gnus-bug-message
125 "Sending a bug report to the Gnus Towers.
126 ========================================
128 The buffer below is a mail buffer. When you press `C-c C-c', it will
129 be sent to the Gnus Bug Exterminators.
131 The thing near the bottom of the buffer is how the environment
132 settings will be included in the mail. Please do not delete that.
133 They will tell the Bug People what your environment is, so that it
134 will be easier to locate the bugs.
136 If you have found a bug that makes Emacs go \"beep\", set
137 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
138 and include the backtrace in your bug report.
140 Please describe the bug in annoying, painstaking detail.
142 Thank you for your help in stamping out bugs.
146 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
147 (autoload 'news-setup "rnewspost")
148 (autoload 'news-reply-mode "rnewspost")
149 (autoload 'rmail-dont-reply-to "mail-utils")
150 (autoload 'rmail-output "rmailout"))
154 ;;; Gnus Posting Functions
157 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
158 "p" gnus-summary-post-news
159 "f" gnus-summary-followup
160 "F" gnus-summary-followup-with-original
161 "c" gnus-summary-cancel-article
162 "s" gnus-summary-supersede-article
163 "r" gnus-summary-reply
164 "y" gnus-summary-yank-message
165 "R" gnus-summary-reply-with-original
166 "w" gnus-summary-wide-reply
167 "W" gnus-summary-wide-reply-with-original
168 "n" gnus-summary-followup-to-mail
169 "N" gnus-summary-followup-to-mail-with-original
170 "m" gnus-summary-mail-other-window
171 "u" gnus-uu-post-news
172 "\M-c" gnus-summary-mail-crosspost-complaint
173 "om" gnus-summary-mail-forward
174 "op" gnus-summary-post-forward
175 "Om" gnus-uu-digest-mail-forward
176 "Op" gnus-uu-digest-post-forward)
178 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
179 "b" gnus-summary-resend-bounced-mail
180 ;; "c" gnus-summary-send-draft
181 "r" gnus-summary-resend-message)
183 ;;; Internal functions.
185 (defvar gnus-article-reply nil)
186 (defmacro gnus-setup-message (config &rest forms)
187 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
188 (buffer (make-symbol "gnus-setup-message-buffer"))
189 (article (make-symbol "gnus-setup-message-article"))
190 (group (make-symbol "gnus-setup-message-group")))
191 `(let ((,winconf (current-window-configuration))
192 (,buffer (buffer-name (current-buffer)))
193 (,article (and gnus-article-reply (gnus-summary-article-number)))
194 (,group gnus-newsgroup-name)
195 (message-header-setup-hook
196 (copy-sequence message-header-setup-hook))
197 (message-mode-hook (copy-sequence message-mode-hook)))
198 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
199 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
200 (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
201 (add-hook 'message-mode-hook
203 (set (make-local-variable 'message-posting-charset)
204 (gnus-setup-posting-charset ,group))))
208 (gnus-inews-add-send-actions ,winconf ,buffer ,article)
209 (setq gnus-message-buffer (current-buffer))
210 (set (make-local-variable 'gnus-message-group-art)
211 (cons ,group ,article))
212 (set (make-local-variable 'gnus-newsgroup-name) ,group)
213 (gnus-run-hooks 'gnus-message-setup-hook))
215 (gnus-configure-windows ,config t)
216 (set-buffer-modified-p nil))))
218 (defun gnus-setup-posting-charset (group)
219 (let ((alist gnus-group-posting-charset-alist)
220 (group (or group ""))
224 (while (setq elem (pop alist))
225 (when (or (and (stringp (car elem))
226 (string-match (car elem) group))
227 (and (gnus-functionp (car elem))
228 (funcall (car elem) group))
229 (and (symbolp (car elem))
230 (symbol-value (car elem))))
231 (throw 'found (cadr elem))))))))
233 (defun gnus-inews-add-send-actions (winconf buffer article)
234 (make-local-hook 'message-sent-hook)
235 (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
236 (setq message-post-method
238 (gnus-post-method arg ,gnus-newsgroup-name)))
239 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
241 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
243 `(when (gnus-buffer-exists-p ,buffer)
247 `(gnus-summary-mark-article-as-replied ,article))))
250 (put 'gnus-setup-message 'lisp-indent-function 1)
251 (put 'gnus-setup-message 'edebug-form-spec '(form body))
253 ;;; Post news commands of Gnus group mode and summary mode
255 (defun gnus-group-mail (&optional arg)
256 "Start composing a mail.
257 If ARG, use the group under the point to find a posting style.
258 If ARG is 1, prompt for a group name to find the posting style."
260 ;; We can't `let' gnus-newsgroup-name here, since that leads
261 ;; to local variables leaking.
262 (let ((group gnus-newsgroup-name)
263 (buffer (current-buffer)))
266 (setq gnus-newsgroup-name
268 (if (= 1 (prefix-numeric-value arg))
269 (completing-read "Use posting style of group: "
270 gnus-active-hashtb nil
271 (gnus-read-active-file-p))
272 (gnus-group-group-name))
274 (gnus-setup-message 'message (message-mail)))
277 (setq gnus-newsgroup-name group)))))
279 (defun gnus-group-post-news (&optional arg)
280 "Start composing a news message.
281 If ARG, post to the group under point.
282 If ARG is 1, prompt for a group name."
284 ;; Bind this variable here to make message mode hooks work ok.
285 (let ((gnus-newsgroup-name
287 (if (= 1 (prefix-numeric-value arg))
288 (completing-read "Newsgroup: " gnus-active-hashtb nil
289 (gnus-read-active-file-p))
290 (gnus-group-group-name))
292 (gnus-post-news 'post gnus-newsgroup-name)))
294 (defun gnus-summary-post-news ()
295 "Start composing a news message."
297 (gnus-post-news 'post gnus-newsgroup-name))
299 (defun gnus-summary-followup (yank &optional force-news)
300 "Compose a followup to an article.
301 If prefix argument YANK is non-nil, original article is yanked automatically."
303 (list (and current-prefix-arg
304 (gnus-summary-work-articles 1))))
306 (gnus-summary-goto-subject (car yank)))
307 (save-window-excursion
308 (gnus-summary-select-article))
309 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
310 (gnus-newsgroup-name gnus-newsgroup-name))
312 (gnus-post-news nil gnus-newsgroup-name
313 headers gnus-article-buffer
314 yank nil force-news)))
316 (defun gnus-summary-followup-with-original (n &optional force-news)
317 "Compose a followup to an article and include the original article."
319 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
321 (defun gnus-summary-followup-to-mail (&optional arg)
322 "Followup to the current mail message via news."
324 (list (and current-prefix-arg
325 (gnus-summary-work-articles 1))))
326 (gnus-summary-followup arg t))
328 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
329 "Followup to the current mail message via news."
331 (gnus-summary-followup (gnus-summary-work-articles arg) t))
333 (defun gnus-inews-yank-articles (articles)
336 (while (setq article (pop articles))
337 (save-window-excursion
338 (set-buffer gnus-summary-buffer)
339 (gnus-summary-select-article nil nil nil article)
340 (gnus-summary-remove-process-mark article))
341 (gnus-copy-article-buffer)
342 (let ((message-reply-buffer gnus-article-copy)
343 (message-reply-headers gnus-current-headers))
344 (message-yank-original)
345 (setq beg (or beg (mark t))))
351 (defun gnus-summary-cancel-article (&optional n symp)
352 "Cancel an article you posted.
353 Uses the process-prefix convention. If given the symbolic
354 prefix `a', cancel using the standard posting method; if not
355 post using the current select method."
356 (interactive (gnus-interactive "P\ny"))
357 (let ((articles (gnus-summary-work-articles n))
360 (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
362 (while (setq article (pop articles))
363 (when (gnus-summary-select-article t nil nil article)
364 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
365 (message-cancel-news))
366 (gnus-summary-mark-as-read article gnus-canceled-mark)
367 (gnus-cache-remove-article 1))
368 (gnus-article-hide-headers-if-wanted))
369 (gnus-summary-remove-process-mark article))))
371 (defun gnus-summary-supersede-article ()
372 "Compose an article that will supersede a previous article.
373 This is done simply by taking the old article and adding a Supersedes
374 header line with the old Message-ID."
376 (let ((article (gnus-summary-article-number)))
377 (gnus-setup-message 'reply-yank
378 (gnus-summary-select-article t)
379 (set-buffer gnus-original-article-buffer)
383 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
385 (set-buffer ,gnus-summary-buffer)
386 (gnus-cache-possibly-remove-article ,article nil nil nil t)
387 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
388 message-send-actions))))
392 (defun gnus-copy-article-buffer (&optional article-buffer)
393 ;; make a copy of the article buffer with all text properties removed
394 ;; this copy is in the buffer gnus-article-copy.
395 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
396 ;; this buffer should be passed to all mail/news reply/post routines.
397 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
399 (set-buffer gnus-article-copy)
400 (mm-enable-multibyte))
401 (let ((article-buffer (or article-buffer gnus-article-buffer))
403 (if (not (and (get-buffer article-buffer)
404 (gnus-buffer-exists-p article-buffer)))
405 (error "Can't find any article buffer")
407 (set-buffer article-buffer)
409 ;; Copy over the (displayed) article buffer, delete
410 ;; hidden text and remove text properties.
412 (copy-to-buffer gnus-article-copy (point-min) (point-max))
413 (set-buffer gnus-article-copy)
414 (gnus-article-delete-text-of-type 'annotation)
415 (gnus-remove-text-with-property 'gnus-prev)
416 (gnus-remove-text-with-property 'gnus-next)
419 (format "%s" (buffer-string))
421 ;; Find the original headers.
422 (set-buffer gnus-original-article-buffer)
423 (goto-char (point-min))
424 (while (looking-at message-unix-mail-delimiter)
427 (setq end (or (search-forward "\n\n" nil t) (point)))
428 ;; Delete the headers from the displayed articles.
429 (set-buffer gnus-article-copy)
430 (delete-region (goto-char (point-min))
431 (or (search-forward "\n\n" nil t) (point-max)))
432 ;; Insert the original article headers.
433 (insert-buffer-substring gnus-original-article-buffer beg end)
434 (article-decode-encoded-words)))
437 (defun gnus-post-news (post &optional group header article-buffer yank subject
440 (gnus-copy-article-buffer))
441 (let ((gnus-article-reply article-buffer)
442 (add-to-list gnus-add-to-list))
443 (gnus-setup-message (cond (yank 'reply-yank)
444 (article-buffer 'reply)
446 (let* ((group (or group gnus-newsgroup-name))
448 to-address to-group mailing-list to-list
451 (setq to-address (gnus-group-find-parameter group 'to-address)
452 to-group (gnus-group-find-parameter group 'to-group)
453 to-list (gnus-group-find-parameter group 'to-list)
454 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
455 mailing-list (when gnus-mailing-list-groups
456 (string-match gnus-mailing-list-groups group))
457 group (gnus-group-real-name group)))
458 (if (or (and to-group
459 (gnus-news-group-p to-group))
462 (and (gnus-news-group-p
463 (or pgroup gnus-newsgroup-name)
464 (if header (mail-header-number header)
465 gnus-current-article))
471 (message-news (or to-group group))
472 (set-buffer gnus-article-copy)
473 (gnus-msg-treat-broken-reply-to)
474 (message-followup (if (or newsgroup-p force-news) nil to-group)))
478 (message-mail (or to-address to-list))
479 ;; Arrange for mail groups that have no `to-address' to
480 ;; get that when the user sends off the mail.
481 (when (and (not to-list)
484 (push (list 'gnus-inews-add-to-address pgroup)
485 message-send-actions)))
486 (set-buffer gnus-article-copy)
487 (gnus-msg-treat-broken-reply-to)
488 (message-wide-reply to-address)))
490 (gnus-inews-yank-articles yank))))))
492 (defun gnus-msg-treat-broken-reply-to ()
493 "Remove the Reply-to header iff broken-reply-to."
494 (when (gnus-group-find-parameter
495 gnus-newsgroup-name 'broken-reply-to)
497 (message-narrow-to-head)
498 (message-remove-header "reply-to"))))
500 (defun gnus-post-method (arg group &optional silent)
501 "Return the posting method based on GROUP and ARG.
502 If SILENT, don't prompt the user."
503 (let ((group-method (gnus-find-method-for-group group)))
505 ;; If the group-method is nil (which shouldn't happen) we use
506 ;; the default method.
508 (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
509 gnus-select-method message-post-method))
510 ;; We want the inverse of the default
511 ((and arg (not (eq arg 0)))
512 (if (eq gnus-post-method 'active)
515 ;; We query the user for a post method.
517 (and gnus-post-method
518 (not (eq gnus-post-method 'current))
519 (listp (car gnus-post-method))))
521 ;; Collect all methods we know about.
523 (when (and gnus-post-method
524 (not (eq gnus-post-method 'current)))
525 (if (listp (car gnus-post-method))
527 (list gnus-post-method)))
528 gnus-secondary-select-methods
529 (mapcar 'cdr gnus-server-alist)
530 (mapcar 'car gnus-opened-servers)
531 (list gnus-select-method)
532 (list group-method)))
533 method-alist post-methods method)
534 ;; Weed out all mail methods.
536 (setq method (gnus-server-get-method "" (pop methods)))
537 (when (and (or (gnus-method-option-p method 'post)
538 (gnus-method-option-p method 'post-mail))
539 (not (member method post-methods)))
540 (push method post-methods)))
541 ;; Create a name-method alist.
545 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
550 (setq gnus-last-posting-server
552 gnus-last-posting-server)
553 ;; Just use the last value.
554 gnus-last-posting-server
556 "Posting method: " method-alist nil t
557 (cons (or gnus-last-posting-server "") 0))))
559 ;; Override normal method.
560 ((and (eq gnus-post-method 'current)
561 (not (eq (car group-method) 'nndraft))
562 (gnus-get-function group-method 'request-post t)
565 ((and gnus-post-method
566 (not (eq gnus-post-method 'current)))
568 ;; Use the normal select method.
569 (t gnus-select-method))))
573 ;; Dummies to avoid byte-compile warning.
574 (defvar nnspool-rejected-article-hook)
575 (defvar xemacs-codename)
577 (defun gnus-extended-version ()
578 "Stringified Gnus version and Emacs version."
581 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
582 " (" gnus-version ")"
585 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
586 (concat "Emacs/" (match-string 1 emacs-version)))
587 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
589 (concat (match-string 1 emacs-version)
590 (format "/%d.%d" emacs-major-version emacs-minor-version)
591 (if (match-beginning 3)
592 (match-string 3 emacs-version)
594 (if (boundp 'xemacs-codename)
595 (concat " (" xemacs-codename ")")
601 ;;; Gnus Mail Functions
604 ;;; Mail reply commands of Gnus summary mode
606 (defun gnus-summary-reply (&optional yank wide)
607 "Start composing a reply mail to the current message.
608 If prefix argument YANK is non-nil, the original article is yanked
611 (list (and current-prefix-arg
612 (gnus-summary-work-articles 1))))
613 ;; Stripping headers should be specified with mail-yank-ignored-headers.
615 (gnus-summary-goto-subject (car yank)))
616 (let ((gnus-article-reply t))
617 (gnus-setup-message (if yank 'reply-yank 'reply)
618 (gnus-summary-select-article)
619 (set-buffer (gnus-copy-article-buffer))
620 (gnus-msg-treat-broken-reply-to)
621 (message-reply nil wide)
623 (gnus-inews-yank-articles yank)))))
625 (defun gnus-summary-reply-with-original (n &optional wide)
626 "Start composing a reply mail to the current message.
627 The original article will be yanked."
629 (gnus-summary-reply (gnus-summary-work-articles n) wide))
631 (defun gnus-summary-wide-reply (&optional yank)
632 "Start composing a wide reply mail to the current message.
633 If prefix argument YANK is non-nil, the original article is yanked
636 (list (and current-prefix-arg
637 (gnus-summary-work-articles 1))))
638 (gnus-summary-reply yank t))
640 (defun gnus-summary-wide-reply-with-original (n)
641 "Start composing a wide reply mail to the current message.
642 The original article will be yanked."
644 (gnus-summary-reply-with-original n t))
646 (defun gnus-summary-mail-forward (&optional not-used post)
647 "Forward the current message to another user.
648 If POST, post instead of mail."
650 (gnus-setup-message 'forward
651 (gnus-summary-select-article)
654 (set-buffer gnus-original-article-buffer)
655 (setq text (buffer-string)))
656 (set-buffer (gnus-get-buffer-create
657 (generate-new-buffer-name " *Gnus forward*")))
660 (goto-char (point-min))
661 (when (looking-at "From ")
662 (replace-match "X-From-Line: ") )
663 (run-hooks 'gnus-article-decode-hook)
664 (message-forward post))))
666 (defun gnus-summary-resend-message (address n)
667 "Resend the current article to ADDRESS."
668 (interactive "sResend message(s) to: \nP")
669 (let ((articles (gnus-summary-work-articles n))
671 (while (setq article (pop articles))
672 (gnus-summary-select-article nil nil nil article)
674 (set-buffer gnus-original-article-buffer)
675 (message-resend address)))))
677 (defun gnus-summary-post-forward (&optional full-headers)
678 "Forward the current article to a newsgroup.
679 If FULL-HEADERS (the prefix), include full headers when forwarding."
681 (gnus-summary-mail-forward full-headers t))
683 (defvar gnus-nastygram-message
684 "The following article was inappropriately posted to %s.\n\n"
685 "Format string to insert in nastygrams.
686 The current group name will be inserted at \"%s\".")
688 (defun gnus-summary-mail-nastygram (n)
689 "Send a nastygram to the author of the current article."
691 (when (or gnus-expert-user
693 "Really send a nastygram to the author of the current article? "))
694 (let ((group gnus-newsgroup-name))
695 (gnus-summary-reply-with-original n)
696 (set-buffer gnus-message-buffer)
698 (insert (format gnus-nastygram-message group))
699 (message-send-and-exit))))
701 (defun gnus-summary-mail-crosspost-complaint (n)
702 "Send a complaint about crossposting to the current article(s)."
704 (let ((articles (gnus-summary-work-articles n))
706 (while (setq article (pop articles))
707 (set-buffer gnus-summary-buffer)