1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
38 (defcustom gnus-post-method 'current
39 "*Preferred method for posting USENET news.
41 If this variable is `current' (which is the default), Gnus will use
42 the \"current\" select method when posting. If it is `native', Gnus
43 will use the native select method when posting.
45 This method will not be used in mail groups and the like, only in
48 If not `native' nor `current', the value must be a valid method as discussed
49 in the documentation of `gnus-select-method'. It can also be a list of
50 methods. If that is the case, the user will be queried for what select
51 method to use when posting."
52 :group 'gnus-group-foreign
53 :link '(custom-manual "(gnus)Posting Server")
54 :type `(choice (const native)
56 (sexp :tag "Methods" ,gnus-select-method)))
58 (defcustom gnus-outgoing-message-group nil
59 "*All outgoing messages will be put in this group.
60 If you want to store all your outgoing mail and articles in the group
61 \"nnml:archive\", you set this variable to that value. This variable
62 can also be a list of group names.
64 If you want to have greater control over what group to put each
65 message in, you can set this variable to a function that checks the
66 current newsgroup name and then returns a suitable group name (or list
69 :type '(choice (string :tag "Group")
72 (defcustom 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
80 (defcustom gnus-add-to-list nil
81 "*If non-nil, add a `to-list' parameter automatically."
85 (defcustom gnus-crosspost-complaint
88 You posted the article below with the following Newsgroups header:
92 The %s group, at least, was an inappropriate recipient
93 of this message. Please trim your Newsgroups header to exclude this
94 group before posting in the future.
99 "Format string to be inserted when complaining about crossposts.
100 The first %s will be replaced by the Newsgroups header;
101 the second with the current group name."
105 (defcustom gnus-message-setup-hook nil
106 "Hook run after setting up a message buffer."
110 (defcustom gnus-bug-create-help-buffer t
111 "*Should we create the *Gnus Help Bug* buffer?"
115 (defcustom gnus-posting-styles nil
116 "*Alist of styles to use when posting.
117 See Info node `(gnus)Posting Styles'."
119 :link '(custom-manual "(gnus)Posting Styles")
120 :type '(repeat (cons (choice (regexp)
123 (string :tag "Header")
124 (regexp :tag "Regexp"))
128 (choice (const signature)
129 (const signature-file)
136 (string :tag "Header"))
142 (defcustom gnus-gcc-mark-as-read nil
143 "If non-nil, automatically mark Gcc articles as read."
148 (defvar gnus-inews-mark-gcc-as-read nil
149 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
151 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
152 'gnus-gcc-mark-as-read)
154 (defcustom gnus-gcc-externalize-attachments nil
155 "Should local-file attachments be included as external parts in Gcc copies?
156 If it is `all', attach files as external parts;
157 if a regexp and matches the Gcc group name, attach files as external parts;
158 if nil, attach files as normal parts."
161 :type '(choice (const nil :tag "None")
162 (const all :tag "Any")
163 (string :tag "Regexp")))
165 (gnus-define-group-parameter
166 posting-charset-alist
169 "Return the permitted unencoded charsets for posting of GROUP."
170 :variable gnus-group-posting-charset-alist
172 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
173 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
174 (message-this-is-mail nil nil)
175 (message-this-is-news nil t))
177 "Alist of regexps and permitted unencoded charsets for posting.
178 Each element of the alist has the form (TEST HEADER BODY-LIST), where
179 TEST is either a regular expression matching the newsgroup header or a
181 HEADER is the charset which may be left unencoded in the header (nil
182 means encode all charsets),
183 BODY-LIST is a list of charsets which may be encoded using 8bit
184 content-transfer encoding in the body, or one of the special values
185 nil (always encode using quoted-printable) or t (always use 8bit).
187 Note that any value other than nil for HEADER infringes some RFCs, so
188 use this option with care."
189 :variable-group gnus-charset
191 '(repeat (list :tag "Permitted unencoded charsets"
193 (regexp :tag "Group")
194 (const :tag "Mail message" :value message-this-is-mail)
195 (const :tag "News article" :value message-this-is-news))
196 (choice :tag "Header"
197 (const :tag "None" nil)
198 (symbol :tag "Charset"))
200 (const :tag "Any" :value t)
201 (const :tag "None" :value nil)
202 (repeat :tag "Charsets"
203 (symbol :tag "Charset")))))
204 :parameter-type '(choice :tag "Permitted unencoded charsets"
207 :parameter-document "\
208 List of charsets that are permitted to be unencoded.")
210 (defcustom gnus-debug-files
211 '("gnus.el" "gnus-sum.el" "gnus-group.el"
212 "gnus-art.el" "gnus-start.el" "gnus-async.el"
213 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
214 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
215 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
216 "Files whose variables will be reported in `gnus-bug'."
219 :type '(repeat (string :tag "File")))
221 (defcustom gnus-debug-exclude-variables
222 '(mm-mime-mule-charset-alist
223 nnmail-split-fancy message-minibuffer-local-map)
224 "Variables that should not be reported in `gnus-bug'."
227 :type '(repeat (symbol :tag "Variable")))
229 (defcustom gnus-discouraged-post-methods
230 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
231 "A list of back ends that are not used in \"real\" newsgroups.
232 This variable is used only when `gnus-post-method' is `current'."
234 :group 'gnus-group-foreign
235 :type '(repeat (symbol :tag "Back end")))
237 (defcustom gnus-message-replysign
239 "Automatically sign replies to signed messages.
240 See also the `mml-default-sign-method' variable."
244 (defcustom gnus-message-replyencrypt
246 "Automatically encrypt replies to encrypted messages.
247 See also the `mml-default-encrypt-method' variable."
251 (defcustom gnus-message-replysignencrypted
253 "Setting this causes automatically encryped messages to also be signed."
257 (defcustom gnus-confirm-mail-reply-to-news nil
258 "If non-nil, Gnus requests confirmation when replying to news.
259 This is done because new users often reply by mistake when reading
261 This can also be a function receiving the group name as the only
262 parameter which should return non-nil iff a confirmation is needed, or
263 a regexp, in which case a confirmation is asked for iff the group name
266 :type '(choice (const :tag "No" nil)
268 (regexp :tag "Iff group matches regexp")
269 (function :tag "Iff function evaluates to non-nil")))
271 (defcustom gnus-confirm-treat-mail-like-news
273 "If non-nil, Gnus will treat mail like news with regard to confirmation
274 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
275 for fine-tuning this.
276 If nil, Gnus will never ask for confirmation if replying to mail."
280 (defcustom gnus-summary-resend-default-address t
281 "If non-nil, Gnus tries to suggest a default address to resend to.
282 If nil, the address field will always be empty after invoking
283 `gnus-summary-resend-message'."
287 (defcustom gnus-user-agent 'emacs-gnus-type
288 "Which information should be exposed in the User-Agent header.
290 It can be one of the symbols `gnus' \(show only Gnus version\), `emacs-gnus'
291 \(show only Emacs and Gnus versions\), `emacs-gnus-config' \(same as
292 `emacs-gnus' plus system configuration\), `emacs-gnus-type' \(same as
293 `emacs-gnus' plus system type\) or a custom string. If you set it to a
294 string, be sure to use a valid format, see RFC 2616."
297 (item :tag "Show Gnus and Emacs versions and system type"
299 (item :tag "Show Gnus and Emacs versions and system configuration"
301 (item :tag "Show Gnus and Emacs versions" emacs-gnus)
302 (item :tag "Show only Gnus version" gnus)
303 (string :tag "Other")))
305 ;;; Internal variables.
307 (defvar gnus-inhibit-posting-styles nil
308 "Inhibit the use of posting styles.")
310 (defvar gnus-article-yanked-articles nil)
311 (defvar gnus-message-buffer "*Mail Gnus*")
312 (defvar gnus-article-copy nil)
313 (defvar gnus-check-before-posting nil)
314 (defvar gnus-last-posting-server nil)
315 (defvar gnus-message-group-art nil)
317 (defvar gnus-msg-force-broken-reply-to nil)
319 (defconst gnus-bug-message
320 "Sending a bug report to the Gnus Towers.
321 ========================================
323 The buffer below is a mail buffer. When you press `C-c C-c', it will
324 be sent to the Gnus Bug Exterminators.
326 The thing near the bottom of the buffer is how the environment
327 settings will be included in the mail. Please do not delete that.
328 They will tell the Bug People what your environment is, so that it
329 will be easier to locate the bugs.
331 If you have found a bug that makes Emacs go \"beep\", set
332 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
333 and include the backtrace in your bug report.
335 Please describe the bug in annoying, painstaking detail.
337 Thank you for your help in stamping out bugs.
341 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
342 (autoload 'news-setup "rnewspost")
343 (autoload 'news-reply-mode "rnewspost")
344 (autoload 'rmail-dont-reply-to "mail-utils")
345 (autoload 'rmail-output "rmailout"))
349 ;;; Gnus Posting Functions
352 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
353 "p" gnus-summary-post-news
354 "i" gnus-summary-news-other-window
355 "f" gnus-summary-followup
356 "F" gnus-summary-followup-with-original
357 "c" gnus-summary-cancel-article
358 "s" gnus-summary-supersede-article
359 "r" gnus-summary-reply
360 "y" gnus-summary-yank-message
361 "R" gnus-summary-reply-with-original
362 "w" gnus-summary-wide-reply
363 "W" gnus-summary-wide-reply-with-original
364 "v" gnus-summary-very-wide-reply
365 "V" gnus-summary-very-wide-reply-with-original
366 "n" gnus-summary-followup-to-mail
367 "N" gnus-summary-followup-to-mail-with-original
368 "m" gnus-summary-mail-other-window
369 "u" gnus-uu-post-news
370 "\M-c" gnus-summary-mail-crosspost-complaint
371 "Br" gnus-summary-reply-broken-reply-to
372 "BR" gnus-summary-reply-broken-reply-to-with-original
373 "om" gnus-summary-mail-forward
374 "op" gnus-summary-post-forward
375 "Om" gnus-uu-digest-mail-forward
376 "Op" gnus-uu-digest-post-forward)
378 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
379 "b" gnus-summary-resend-bounced-mail
380 ;; "c" gnus-summary-send-draft
381 "r" gnus-summary-resend-message
382 "e" gnus-summary-resend-message-edit)
384 ;;; Internal functions.
386 (defun gnus-inews-make-draft ()
388 (gnus-inews-make-draft-meta-information
389 ,gnus-newsgroup-name ',gnus-article-reply)))
391 (defvar gnus-article-reply nil)
392 (defmacro gnus-setup-message (config &rest forms)
393 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
394 (buffer (make-symbol "gnus-setup-message-buffer"))
395 (article (make-symbol "gnus-setup-message-article"))
396 (yanked (make-symbol "gnus-setup-yanked-articles"))
397 (group (make-symbol "gnus-setup-message-group")))
398 `(let ((,winconf (current-window-configuration))
399 (,buffer (buffer-name (current-buffer)))
400 (,article gnus-article-reply)
401 (,yanked gnus-article-yanked-articles)
402 (,group gnus-newsgroup-name)
403 (message-header-setup-hook
404 (copy-sequence message-header-setup-hook))
405 (mbl mml-buffer-list)
406 (message-mode-hook (copy-sequence message-mode-hook)))
407 (setq mml-buffer-list nil)
408 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
409 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
410 ;; #### FIXME: for a reason that I did not manage to identify yet,
411 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
412 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
413 ;; After evaluation of @forms below, it gets the value we actually want
414 ;; to override, and the posting styles are used. For that reason, I've
415 ;; added an optional argument to `gnus-configure-posting-styles' to
416 ;; make sure that the correct value for the group name is used. -- drv
417 (add-hook 'message-mode-hook
419 (gnus-configure-posting-styles ,group)))
420 (gnus-pull ',(intern gnus-draft-meta-information-header)
421 message-required-headers)
423 (not (string= ,group "")))
425 (intern gnus-draft-meta-information-header)
426 (gnus-inews-make-draft))
427 message-required-headers))
431 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
433 (setq gnus-message-buffer (current-buffer))
434 (set (make-local-variable 'gnus-message-group-art)
435 (cons ,group ,article))
436 (set (make-local-variable 'gnus-newsgroup-name) ,group)
437 (gnus-run-hooks 'gnus-message-setup-hook)
438 (if (eq major-mode 'message-mode)
439 (let ((mbl1 mml-buffer-list))
440 (setq mml-buffer-list mbl) ;; Global value
441 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
442 ;; LOCAL argument of add-hook differs between GNU Emacs
443 ;; and XEmacs. make-local-hook makes sure they are local.
444 (make-local-hook 'kill-buffer-hook)
445 (make-local-hook 'change-major-mode-hook)
446 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
447 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
448 (mml-destroy-buffers)
449 (setq mml-buffer-list mbl)))
451 (gnus-configure-windows ,config t)
452 (run-hooks 'post-command-hook)
453 (set-buffer-modified-p nil))))
455 (defun gnus-inews-make-draft-meta-information (group article)
456 (concat "(\"" group "\" "
457 (if article (number-to-string
464 (defun gnus-msg-mail (&optional to subject other-headers continue
465 switch-action yank-action send-actions)
466 "Start editing a mail message to be sent.
467 Like `message-mail', but with Gnus paraphernalia, particularly the
468 Gcc: header for archiving purposes."
470 (let ((buf (current-buffer))
472 (gnus-setup-message 'message
473 (message-mail to subject other-headers continue
474 nil yank-action send-actions))
476 (setq mail-buf (current-buffer))
477 (switch-to-buffer buf)
478 (apply switch-action mail-buf nil)))
479 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
482 (defvar save-selected-window-window)
485 (defun gnus-button-mailto (address)
487 (set-buffer (gnus-copy-article-buffer))
488 (gnus-setup-message 'message
489 (message-reply address))
490 (and (boundp 'save-selected-window-window)
491 (not (window-live-p save-selected-window-window))
492 (setq save-selected-window-window (selected-window))))
495 (defun gnus-button-reply (&optional to-address wide)
496 "Like `message-reply'."
498 (gnus-setup-message 'message
499 (message-reply to-address wide))
500 (and (boundp 'save-selected-window-window)
501 (not (window-live-p save-selected-window-window))
502 (setq save-selected-window-window (selected-window))))
505 (define-mail-user-agent 'gnus-user-agent
506 'gnus-msg-mail 'message-send-and-exit
507 'message-kill-buffer 'message-send-hook)
509 (defun gnus-setup-posting-charset (group)
510 (let ((alist gnus-group-posting-charset-alist)
511 (group (or group ""))
515 (while (setq elem (pop alist))
516 (when (or (and (stringp (car elem))
517 (string-match (car elem) group))
518 (and (gnus-functionp (car elem))
519 (funcall (car elem) group))
520 (and (symbolp (car elem))
521 (symbol-value (car elem))))
522 (throw 'found (cons (cadr elem) (caddr elem)))))))))
524 (defun gnus-inews-add-send-actions (winconf buffer article
525 &optional config yanked)
526 (make-local-hook 'message-sent-hook)
527 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
528 'gnus-inews-do-gcc) nil t)
530 (make-local-hook 'message-header-hook)
531 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
532 (setq message-post-method
534 (gnus-post-method arg ,gnus-newsgroup-name)))
535 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
537 `(when (gnus-buffer-exists-p ,buffer)
538 (set-window-configuration ,winconf))
539 'exit 'postpone 'kill)
540 (let ((to-be-marked (cond
542 (article (if (listp article) article (list article)))
545 `(when (gnus-buffer-exists-p ,buffer)
549 (if (eq config 'forward)
550 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
551 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
554 (put 'gnus-setup-message 'lisp-indent-function 1)
555 (put 'gnus-setup-message 'edebug-form-spec '(form body))
557 ;;; Post news commands of Gnus group mode and summary mode
559 (defun gnus-group-mail (&optional arg)
560 "Start composing a mail.
561 If ARG, use the group under the point to find a posting style.
562 If ARG is 1, prompt for a group name to find the posting style."
564 ;; We can't `let' gnus-newsgroup-name here, since that leads
565 ;; to local variables leaking.
566 (let ((group gnus-newsgroup-name)
567 ;; make sure last viewed article doesn't affect posting styles:
569 (buffer (current-buffer)))
572 (setq gnus-newsgroup-name
574 (if (= 1 (prefix-numeric-value arg))
575 (completing-read "Use posting style of group: "
576 gnus-active-hashtb nil
577 (gnus-read-active-file-p))
578 (gnus-group-group-name))
580 ;; #### see comment in gnus-setup-message -- drv
581 (gnus-setup-message 'message (message-mail)))
584 (setq gnus-newsgroup-name group)))))
586 (defun gnus-group-news (&optional arg)
587 "Start composing a news.
588 If ARG, post to group under point.
589 If ARG is 1, prompt for group name to post to.
591 This function prepares a news even when using mail groups. This is useful
592 for posting messages to mail groups without actually sending them over the
593 network. The corresponding backend must have a 'request-post method."
595 ;; We can't `let' gnus-newsgroup-name here, since that leads
596 ;; to local variables leaking.
597 (let ((group gnus-newsgroup-name)
598 ;; make sure last viewed article doesn't affect posting styles:
600 (buffer (current-buffer)))
603 (setq gnus-newsgroup-name
605 (if (= 1 (prefix-numeric-value arg))
606 (completing-read "Use group: "
607 gnus-active-hashtb nil
608 (gnus-read-active-file-p))
609 (gnus-group-group-name))
611 ;; #### see comment in gnus-setup-message -- drv
612 (gnus-setup-message 'message
613 (message-news (gnus-group-real-name gnus-newsgroup-name))))
616 (setq gnus-newsgroup-name group)))))
618 (defun gnus-group-post-news (&optional arg)
619 "Start composing a message (a news by default).
620 If ARG, post to group under point. If ARG is 1, prompt for group name.
621 Depending on the selected group, the message might be either a mail or
624 ;; Bind this variable here to make message mode hooks work ok.
625 (let ((gnus-newsgroup-name
627 (if (= 1 (prefix-numeric-value arg))
628 (completing-read "Newsgroup: " gnus-active-hashtb nil
629 (gnus-read-active-file-p))
630 (gnus-group-group-name))
632 ;; make sure last viewed article doesn't affect posting styles:
634 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
635 (string= gnus-newsgroup-name ""))))
637 (defun gnus-summary-mail-other-window (&optional arg)
638 "Start composing a mail in another window.
639 Use the posting of the current group by default.
640 If ARG, don't do that. If ARG is 1, prompt for group name to find the
643 ;; We can't `let' gnus-newsgroup-name here, since that leads
644 ;; to local variables leaking.
645 (let ((group gnus-newsgroup-name)
646 ;; make sure last viewed article doesn't affect posting styles:
648 (buffer (current-buffer)))
651 (setq gnus-newsgroup-name
653 (if (= 1 (prefix-numeric-value arg))
654 (completing-read "Use group: "
655 gnus-active-hashtb nil
656 (gnus-read-active-file-p))
658 gnus-newsgroup-name))
659 ;; #### see comment in gnus-setup-message -- drv
660 (gnus-setup-message 'message (message-mail)))
663 (setq gnus-newsgroup-name group)))))
665 (defun gnus-summary-news-other-window (&optional arg)
666 "Start composing a news in another window.
667 Post to the current group by default.
668 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
670 This function prepares a news even when using mail groups. This is useful
671 for posting messages to mail groups without actually sending them over the
672 network. The corresponding backend must have a 'request-post method."
674 ;; We can't `let' gnus-newsgroup-name here, since that leads
675 ;; to local variables leaking.
676 (let ((group gnus-newsgroup-name)
677 ;; make sure last viewed article doesn't affect posting styles:
679 (buffer (current-buffer)))
682 (setq gnus-newsgroup-name
684 (if (= 1 (prefix-numeric-value arg))
685 (completing-read "Use group: "
686 gnus-active-hashtb nil
687 (gnus-read-active-file-p))
689 gnus-newsgroup-name))
690 ;; #### see comment in gnus-setup-message -- drv
691 (gnus-setup-message 'message
692 (message-news (gnus-group-real-name gnus-newsgroup-name))))
695 (setq gnus-newsgroup-name group)))))
697 (defun gnus-summary-post-news (&optional arg)
698 "Start composing a message. Post to the current group by default.
699 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
700 Depending on the selected group, the message might be either a mail or
703 ;; Bind this variable here to make message mode hooks work ok.
704 (let ((gnus-newsgroup-name
706 (if (= 1 (prefix-numeric-value arg))
707 (completing-read "Newsgroup: " gnus-active-hashtb nil
708 (gnus-read-active-file-p))
710 gnus-newsgroup-name))
711 ;; make sure last viewed article doesn't affect posting styles:
713 (gnus-post-news 'post gnus-newsgroup-name)))
716 (defun gnus-summary-followup (yank &optional force-news)
717 "Compose a followup to an article.
718 If prefix argument YANK is non-nil, the original article is yanked
720 YANK is a list of elements, where the car of each element is the
721 article number, and the two following numbers is the region to be
724 (list (and current-prefix-arg
725 (gnus-summary-work-articles 1))))
727 (gnus-summary-goto-subject
728 (if (listp (car yank))
731 (save-window-excursion
732 (gnus-summary-select-article))
733 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
734 (gnus-newsgroup-name gnus-newsgroup-name))
736 (gnus-post-news nil gnus-newsgroup-name
737 headers gnus-article-buffer
739 (gnus-summary-handle-replysign)))
741 (defun gnus-summary-followup-with-original (n &optional force-news)
742 "Compose a followup to an article and include the original article."
744 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
746 (defun gnus-summary-followup-to-mail (&optional arg)
747 "Followup to the current mail message via news."
749 (list (and current-prefix-arg
750 (gnus-summary-work-articles 1))))
751 (gnus-summary-followup arg t))
753 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
754 "Followup to the current mail message via news."
756 (gnus-summary-followup (gnus-summary-work-articles arg) t))
758 (defun gnus-inews-yank-articles (articles)
759 (let (beg article yank-string)
761 (while (setq article (pop articles))
762 (when (listp article)
763 (setq yank-string (nth 1 article)
764 article (nth 0 article)))
765 (save-window-excursion
766 (set-buffer gnus-summary-buffer)
767 (gnus-summary-select-article nil nil nil article)
768 (gnus-summary-remove-process-mark article))
769 (gnus-copy-article-buffer nil yank-string)
770 (let ((message-reply-buffer gnus-article-copy)
771 (message-reply-headers
772 ;; The headers are decoded.
773 (with-current-buffer gnus-article-copy
775 (nnheader-narrow-to-headers)
776 (nnheader-parse-naked-head)))))
777 (message-yank-original)
778 (setq beg (or beg (mark t))))
784 (defun gnus-summary-cancel-article (&optional n symp)
785 "Cancel an article you posted.
786 Uses the process-prefix convention. If given the symbolic
787 prefix `a', cancel using the standard posting method; if not
788 post using the current select method."
789 (interactive (gnus-interactive "P\ny"))
790 (let ((articles (gnus-summary-work-articles n))
793 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
795 (while (setq article (pop articles))
796 (when (gnus-summary-select-article t nil nil article)
797 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
798 (message-cancel-news))
799 (gnus-summary-mark-as-read article gnus-canceled-mark)
800 (gnus-cache-remove-article 1))
801 (gnus-article-hide-headers-if-wanted))
802 (gnus-summary-remove-process-mark article))))
804 (defun gnus-summary-supersede-article ()
805 "Compose an article that will supersede a previous article.
806 This is done simply by taking the old article and adding a Supersedes
807 header line with the old Message-ID."
809 (let ((article (gnus-summary-article-number)))
810 (gnus-setup-message 'reply-yank
811 (gnus-summary-select-article t)
812 (set-buffer gnus-original-article-buffer)
816 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
818 (set-buffer ,gnus-summary-buffer)
819 (gnus-cache-possibly-remove-article ,article nil nil nil t)
820 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
821 message-send-actions))))
825 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
826 ;; make a copy of the article buffer with all text properties removed
827 ;; this copy is in the buffer gnus-article-copy.
828 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
829 ;; this buffer should be passed to all mail/news reply/post routines.
830 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
832 (set-buffer gnus-article-copy)
833 (mm-enable-multibyte))
834 (let ((article-buffer (or article-buffer gnus-article-buffer))
836 (if (not (and (get-buffer article-buffer)
837 (gnus-buffer-exists-p article-buffer)))
838 (error "Can't find any article buffer")
840 (set-buffer article-buffer)
841 (let ((gnus-newsgroup-charset (or gnus-article-charset
842 gnus-newsgroup-charset))
843 (gnus-newsgroup-ignored-charsets
844 (or gnus-article-ignored-charsets
845 gnus-newsgroup-ignored-charsets)))
847 ;; Copy over the (displayed) article buffer, delete
848 ;; hidden text and remove text properties.
850 (copy-to-buffer gnus-article-copy (point-min) (point-max))
851 (set-buffer gnus-article-copy)
854 (delete-region (point) (point-max))
855 (insert yank-string))
856 (gnus-article-delete-text-of-type 'annotation)
857 (gnus-remove-text-with-property 'gnus-prev)
858 (gnus-remove-text-with-property 'gnus-next)
859 (gnus-remove-text-with-property 'gnus-decoration)
862 (buffer-substring-no-properties (point-min) (point-max))
864 ;; Find the original headers.
865 (set-buffer gnus-original-article-buffer)
866 (goto-char (point-min))
867 (while (looking-at message-unix-mail-delimiter)
869 (let ((mail-header-separator ""))
871 end (or (message-goto-body)
872 ;; There may be just a header.
874 ;; Delete the headers from the displayed articles.
875 (set-buffer gnus-article-copy)
876 (let ((mail-header-separator ""))
877 (delete-region (goto-char (point-min))
878 (or (message-goto-body) (point-max))))
879 ;; Insert the original article headers.
880 (insert-buffer-substring gnus-original-article-buffer beg end)
882 (let ((gnus-article-decode-hook
883 (delq 'article-decode-charset
884 (copy-sequence gnus-article-decode-hook))))
885 (run-hooks 'gnus-article-decode-hook)))))
888 (defun gnus-post-news (post &optional group header article-buffer yank subject
891 (gnus-copy-article-buffer))
892 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
893 (gnus-article-yanked-articles yank)
894 (add-to-list gnus-add-to-list))
895 (gnus-setup-message (cond (yank 'reply-yank)
896 (article-buffer 'reply)
898 (let* ((group (or group gnus-newsgroup-name))
899 (charset (gnus-group-name-charset nil group))
901 to-address to-group mailing-list to-list
904 (setq to-address (gnus-parameter-to-address group)
905 to-group (gnus-group-find-parameter group 'to-group)
906 to-list (gnus-parameter-to-list group)
907 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
908 mailing-list (when gnus-mailing-list-groups
909 (string-match gnus-mailing-list-groups group))
910 group (gnus-group-name-decode (gnus-group-real-name group)
912 (if (or (and to-group
913 (gnus-news-group-p to-group))
916 (and (gnus-news-group-p
917 (or pgroup gnus-newsgroup-name)
918 (or header gnus-current-article))
924 (message-news (or to-group group))
925 (set-buffer gnus-article-copy)
926 (gnus-msg-treat-broken-reply-to)
927 (message-followup (if (or newsgroup-p force-news)
928 (if (save-restriction
929 (article-narrow-to-head)
930 (message-fetch-field "newsgroups"))
937 (message-mail (or to-address to-list))
938 ;; Arrange for mail groups that have no `to-address' to
939 ;; get that when the user sends off the mail.
940 (when (and (not to-list)
943 (push (list 'gnus-inews-add-to-address pgroup)
944 message-send-actions)))
945 (set-buffer gnus-article-copy)
946 (gnus-msg-treat-broken-reply-to)
947 (message-wide-reply to-address)))
949 (gnus-inews-yank-articles yank))))))
951 (defun gnus-msg-treat-broken-reply-to (&optional force)
952 "Remove the Reply-to header if broken-reply-to."
954 (gnus-group-find-parameter
955 gnus-newsgroup-name 'broken-reply-to))
957 (message-narrow-to-head)
958 (message-remove-header "reply-to"))))
960 (defun gnus-post-method (arg group &optional silent)
961 "Return the posting method based on GROUP and ARG.
962 If SILENT, don't prompt the user."
963 (let ((gnus-post-method (or (gnus-parameter-post-method group)
965 (group-method (gnus-find-method-for-group group)))
967 ;; If the group-method is nil (which shouldn't happen) we use
968 ;; the default method.
970 (or (and (listp gnus-post-method) ;If not current/native/nil
971 (not (listp (car gnus-post-method))) ; and not a list of methods
972 gnus-post-method) ;then use it.
974 message-post-method))
975 ;; We want the inverse of the default
976 ((and arg (not (eq arg 0)))
977 (if (eq gnus-post-method 'current)
980 ;; We query the user for a post method.
982 (and (listp gnus-post-method)
983 (listp (car gnus-post-method))))
985 ;; Collect all methods we know about.
987 (when (listp gnus-post-method)
988 (if (listp (car gnus-post-method))
990 (list gnus-post-method)))
991 gnus-secondary-select-methods
992 (mapcar 'cdr gnus-server-alist)
993 (mapcar 'car gnus-opened-servers)
994 (list gnus-select-method)
995 (list group-method)))
996 method-alist post-methods method)
997 ;; Weed out all mail methods.
999 (setq method (gnus-server-get-method "" (pop methods)))
1000 (when (and (or (gnus-method-option-p method 'post)
1001 (gnus-method-option-p method 'post-mail))
1002 (not (member method post-methods)))
1003 (push method post-methods)))
1004 ;; Create a name-method alist.
1008 (if (equal (cadr m) "")
1009 (list (symbol-name (car m)) m)
1010 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1015 (setq gnus-last-posting-server
1017 gnus-last-posting-server)
1018 ;; Just use the last value.
1019 gnus-last-posting-server
1021 "Posting method: " method-alist nil t
1022 (cons (or gnus-last-posting-server "") 0))))
1024 ;; Override normal method.
1025 ((and (eq gnus-post-method 'current)
1026 (not (memq (car group-method) gnus-discouraged-post-methods))
1027 (gnus-get-function group-method 'request-post t))
1030 ;; Use gnus-post-method.
1031 ((listp gnus-post-method) ;A method...
1032 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1034 ;; Use the normal select method (nil or native).
1035 (t gnus-select-method))))
1039 ;; Dummies to avoid byte-compile warning.
1041 (defvar nnspool-rejected-article-hook)
1042 (defvar xemacs-codename))
1044 (defun gnus-extended-version ()
1045 "Stringified Gnus version and Emacs version.
1046 See the variable `gnus-user-agent'."
1050 (prin1-to-string (gnus-continuum-version gnus-version) t)
1051 " (" gnus-version ")"))
1054 ((eq gnus-user-agent 'emacs-gnus-config)
1055 system-configuration)
1056 ((eq gnus-user-agent 'emacs-gnus-type)
1057 (symbol-name system-type))
1061 ((eq gnus-user-agent 'gnus)
1063 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
1064 (concat "Emacs/" (match-string 1 emacs-version)
1066 (concat " (" system-v ")")
1069 "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
1072 (match-string 1 emacs-version)
1073 (format "/%d.%d" emacs-major-version emacs-minor-version)
1074 (if (match-beginning 3)
1075 (match-string 3 emacs-version)
1077 (if (boundp 'xemacs-codename)
1079 " (" xemacs-codename
1081 (concat ", " system-v ")")
1084 (t emacs-version))))
1085 (if (stringp gnus-user-agent)
1089 (concat " " emacs-v))))))
1093 ;;; Gnus Mail Functions
1096 ;;; Mail reply commands of Gnus summary mode
1098 (defun gnus-summary-reply (&optional yank wide very-wide)
1099 "Start composing a mail reply to the current message.
1100 If prefix argument YANK is non-nil, the original article is yanked
1102 If WIDE, make a wide reply.
1103 If VERY-WIDE, make a very wide reply."
1105 (list (and current-prefix-arg
1106 (gnus-summary-work-articles 1))))
1107 ;; Allow user to require confirmation before replying by mail to the
1108 ;; author of a news article (or mail message).
1110 (not (or (gnus-news-group-p gnus-newsgroup-name)
1111 gnus-confirm-treat-mail-like-news))
1112 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1113 (string-match gnus-confirm-mail-reply-to-news
1114 gnus-newsgroup-name))
1115 ((functionp gnus-confirm-mail-reply-to-news)
1116 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1117 (t gnus-confirm-mail-reply-to-news)))
1118 (y-or-n-p "Really reply by mail to article author? "))
1120 (if (listp (car yank))
1123 (gnus-article-reply (or article (gnus-summary-article-number)))
1124 (gnus-article-yanked-articles yank)
1126 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1128 (gnus-summary-goto-subject article))
1129 (gnus-setup-message (if yank 'reply-yank 'reply)
1131 (gnus-summary-select-article)
1132 (dolist (article very-wide)
1133 (gnus-summary-select-article nil nil nil article)
1135 (set-buffer (gnus-copy-article-buffer))
1136 (gnus-msg-treat-broken-reply-to)
1138 (message-narrow-to-head)
1139 (setq headers (concat headers (buffer-string)))))))
1140 (set-buffer (gnus-copy-article-buffer))
1141 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1143 (message-narrow-to-head)
1147 (goto-char (point-max)))
1148 (mml-quote-region (point) (point-max))
1149 (message-reply nil wide)
1151 (gnus-inews-yank-articles yank))
1152 (gnus-summary-handle-replysign)))))
1154 (defun gnus-summary-handle-replysign ()
1155 "Check the various replysign variables and take action accordingly."
1156 (when (or gnus-message-replysign gnus-message-replyencrypt)
1157 (let (signed encrypted)
1159 (set-buffer gnus-article-buffer)
1160 (setq signed (memq 'signed gnus-article-wash-types))
1161 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1162 (cond ((and gnus-message-replyencrypt encrypted)
1163 (mml-secure-message mml-default-encrypt-method
1164 (if gnus-message-replysignencrypted
1167 ((and gnus-message-replysign signed)
1168 (mml-secure-message mml-default-sign-method 'sign))))))
1170 (defun gnus-summary-reply-with-original (n &optional wide)
1171 "Start composing a reply mail to the current message.
1172 The original article will be yanked."
1174 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1176 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1177 "Like `gnus-summary-reply' except removing reply-to field.
1178 If prefix argument YANK is non-nil, the original article is yanked
1180 If WIDE, make a wide reply.
1181 If VERY-WIDE, make a very wide reply."
1183 (list (and current-prefix-arg
1184 (gnus-summary-work-articles 1))))
1185 (let ((gnus-msg-force-broken-reply-to t))
1186 (gnus-summary-reply yank wide very-wide)))
1188 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1189 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1190 The original article will be yanked."
1192 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1194 (defun gnus-summary-wide-reply (&optional yank)
1195 "Start composing a wide reply mail to the current message.
1196 If prefix argument YANK is non-nil, the original article is yanked
1199 (list (and current-prefix-arg
1200 (gnus-summary-work-articles 1))))
1201 (gnus-summary-reply yank t))
1203 (defun gnus-summary-wide-reply-with-original (n)
1204 "Start composing a wide reply mail to the current message.
1205 The original article will be yanked."
1207 (gnus-summary-reply-with-original n t))
1209 (defun gnus-summary-very-wide-reply (&optional yank)
1210 "Start composing a very wide reply mail to the current message.
1211 If prefix argument YANK is non-nil, the original article is yanked
1214 (list (and current-prefix-arg
1215 (gnus-summary-work-articles 1))))
1216 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1218 (defun gnus-summary-very-wide-reply-with-original (n)
1219 "Start composing a very wide reply mail to the current message.
1220 The original article will be yanked."
1223 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1225 (defun gnus-summary-mail-forward (&optional arg post)
1226 "Forward the current message(s) to another user.
1227 If process marks exist, forward all marked messages;
1228 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1229 if ARG is 1, decode the message and forward directly inline;
1230 if ARG is 2, forward message as an rfc822 MIME section;
1231 if ARG is 3, decode message and forward as an rfc822 MIME section;
1232 if ARG is 4, forward message directly inline;
1233 otherwise, use flipped `message-forward-as-mime'.
1234 If POST, post instead of mail.
1235 For the `inline' alternatives, also see the variable
1236 `message-forward-ignored-headers'."
1238 (if (cdr (gnus-summary-work-articles nil))
1239 ;; Process marks are given.
1240 (gnus-uu-digest-mail-forward arg post)
1241 ;; No process marks.
1242 (let ((message-forward-as-mime message-forward-as-mime)
1243 (message-forward-show-mml message-forward-show-mml))
1247 (setq message-forward-as-mime nil
1248 message-forward-show-mml t))
1250 (setq message-forward-as-mime t
1251 message-forward-show-mml nil))
1253 (setq message-forward-as-mime t
1254 message-forward-show-mml t))
1256 (setq message-forward-as-mime nil
1257 message-forward-show-mml nil))
1259 (setq message-forward-as-mime (not message-forward-as-mime))))
1260 (let* ((gnus-article-reply (gnus-summary-article-number))
1261 (gnus-article-yanked-articles (list gnus-article-reply)))
1262 (gnus-setup-message 'forward
1263 (gnus-summary-select-article)
1264 (let ((mail-parse-charset
1265 (or (and (gnus-buffer-live-p gnus-article-buffer)
1266 (with-current-buffer gnus-article-buffer
1267 gnus-article-charset))
1268 gnus-newsgroup-charset))
1269 (mail-parse-ignored-charsets
1270 gnus-newsgroup-ignored-charsets))
1271 (set-buffer gnus-original-article-buffer)
1272 (message-forward post)))))))
1274 (defun gnus-summary-resend-message (address n)