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 "*If non-nil a regexp matching groups that are really mailing lists.
74 This is useful when you're reading a mailing list that has been
75 gatewayed to a newsgroup, and you want to followup to an article in
78 :type '(choice (regexp)
81 (defcustom gnus-add-to-list nil
82 "*If non-nil, add a `to-list' parameter automatically."
86 (defcustom gnus-crosspost-complaint
89 You posted the article below with the following Newsgroups header:
93 The %s group, at least, was an inappropriate recipient
94 of this message. Please trim your Newsgroups header to exclude this
95 group before posting in the future.
100 "Format string to be inserted when complaining about crossposts.
101 The first %s will be replaced by the Newsgroups header;
102 the second with the current group name."
106 (defcustom gnus-message-setup-hook nil
107 "Hook run after setting up a message buffer."
111 (defcustom gnus-bug-create-help-buffer t
112 "*Should we create the *Gnus Help Bug* buffer?"
116 (defcustom gnus-posting-styles nil
117 "*Alist of styles to use when posting.
118 See Info node `(gnus)Posting Styles'."
120 :link '(custom-manual "(gnus)Posting Styles")
121 :type '(repeat (cons (choice (regexp)
124 (string :tag "Header")
125 (regexp :tag "Regexp"))
129 (choice (const signature)
130 (const signature-file)
137 (string :tag "Header"))
143 (defcustom gnus-gcc-mark-as-read nil
144 "If non-nil, automatically mark Gcc articles as read."
149 (defvar gnus-inews-mark-gcc-as-read nil
150 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
152 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
153 'gnus-gcc-mark-as-read)
155 (defcustom gnus-gcc-externalize-attachments nil
156 "Should local-file attachments be included as external parts in Gcc copies?
157 If it is `all', attach files as external parts;
158 if a regexp and matches the Gcc group name, attach files as external parts;
159 if nil, attach files as normal parts."
162 :type '(choice (const nil :tag "None")
163 (const all :tag "Any")
164 (string :tag "Regexp")))
166 (gnus-define-group-parameter
167 posting-charset-alist
170 "Return the permitted unencoded charsets for posting of GROUP."
171 :variable gnus-group-posting-charset-alist
173 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
174 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
175 (message-this-is-mail nil nil)
176 (message-this-is-news nil t))
178 "Alist of regexps and permitted unencoded charsets for posting.
179 Each element of the alist has the form (TEST HEADER BODY-LIST), where
180 TEST is either a regular expression matching the newsgroup header or a
182 HEADER is the charset which may be left unencoded in the header (nil
183 means encode all charsets),
184 BODY-LIST is a list of charsets which may be encoded using 8bit
185 content-transfer encoding in the body, or one of the special values
186 nil (always encode using quoted-printable) or t (always use 8bit).
188 Note that any value other than nil for HEADER infringes some RFCs, so
189 use this option with care."
190 :variable-group gnus-charset
192 '(repeat (list :tag "Permitted unencoded charsets"
194 (regexp :tag "Group")
195 (const :tag "Mail message" :value message-this-is-mail)
196 (const :tag "News article" :value message-this-is-news))
197 (choice :tag "Header"
198 (const :tag "None" nil)
199 (symbol :tag "Charset"))
201 (const :tag "Any" :value t)
202 (const :tag "None" :value nil)
203 (repeat :tag "Charsets"
204 (symbol :tag "Charset")))))
205 :parameter-type '(choice :tag "Permitted unencoded charsets"
208 :parameter-document "\
209 List of charsets that are permitted to be unencoded.")
211 (defcustom gnus-debug-files
212 '("gnus.el" "gnus-sum.el" "gnus-group.el"
213 "gnus-art.el" "gnus-start.el" "gnus-async.el"
214 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
215 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
216 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
217 "Files whose variables will be reported in `gnus-bug'."
220 :type '(repeat (string :tag "File")))
222 (defcustom gnus-debug-exclude-variables
223 '(mm-mime-mule-charset-alist
224 nnmail-split-fancy message-minibuffer-local-map)
225 "Variables that should not be reported in `gnus-bug'."
228 :type '(repeat (symbol :tag "Variable")))
230 (defcustom gnus-discouraged-post-methods
231 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
232 "A list of back ends that are not used in \"real\" newsgroups.
233 This variable is used only when `gnus-post-method' is `current'."
235 :group 'gnus-group-foreign
236 :type '(repeat (symbol :tag "Back end")))
238 (defcustom gnus-message-replysign
240 "Automatically sign replies to signed messages.
241 See also the `mml-default-sign-method' variable."
245 (defcustom gnus-message-replyencrypt
247 "Automatically encrypt replies to encrypted messages.
248 See also the `mml-default-encrypt-method' variable."
252 (defcustom gnus-message-replysignencrypted
254 "Setting this causes automatically encryped messages to also be signed."
258 (defcustom gnus-confirm-mail-reply-to-news nil
259 "If non-nil, Gnus requests confirmation when replying to news.
260 This is done because new users often reply by mistake when reading
262 This can also be a function receiving the group name as the only
263 parameter which should return non-nil iff a confirmation is needed, or
264 a regexp, in which case a confirmation is asked for iff the group name
267 :type '(choice (const :tag "No" nil)
269 (regexp :tag "Iff group matches regexp")
270 (function :tag "Iff function evaluates to non-nil")))
272 (defcustom gnus-confirm-treat-mail-like-news
274 "If non-nil, Gnus will treat mail like news with regard to confirmation
275 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
276 for fine-tuning this.
277 If nil, Gnus will never ask for confirmation if replying to mail."
281 (defcustom gnus-summary-resend-default-address t
282 "If non-nil, Gnus tries to suggest a default address to resend to.
283 If nil, the address field will always be empty after invoking
284 `gnus-summary-resend-message'."
288 (defcustom gnus-user-agent 'emacs-gnus-type
289 "Which information should be exposed in the User-Agent header.
291 It can be one of the symbols `gnus' \(show only Gnus version\), `emacs-gnus'
292 \(show only Emacs and Gnus versions\), `emacs-gnus-config' \(same as
293 `emacs-gnus' plus system configuration\), `emacs-gnus-type' \(same as
294 `emacs-gnus' plus system type\) or a custom string. If you set it to a
295 string, be sure to use a valid format, see RFC 2616."
298 (item :tag "Show Gnus and Emacs versions and system type"
300 (item :tag "Show Gnus and Emacs versions and system configuration"
302 (item :tag "Show Gnus and Emacs versions" emacs-gnus)
303 (item :tag "Show only Gnus version" gnus)
304 (string :tag "Other")))
306 ;;; Internal variables.
308 (defvar gnus-inhibit-posting-styles nil
309 "Inhibit the use of posting styles.")
311 (defvar gnus-article-yanked-articles nil)
312 (defvar gnus-message-buffer "*Mail Gnus*")
313 (defvar gnus-article-copy nil)
314 (defvar gnus-check-before-posting nil)
315 (defvar gnus-last-posting-server nil)
316 (defvar gnus-message-group-art nil)
318 (defvar gnus-msg-force-broken-reply-to nil)
320 (defconst gnus-bug-message
321 "Sending a bug report to the Gnus Towers.
322 ========================================
324 The buffer below is a mail buffer. When you press `C-c C-c', it will
325 be sent to the Gnus Bug Exterminators.
327 The thing near the bottom of the buffer is how the environment
328 settings will be included in the mail. Please do not delete that.
329 They will tell the Bug People what your environment is, so that it
330 will be easier to locate the bugs.
332 If you have found a bug that makes Emacs go \"beep\", set
333 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
334 and include the backtrace in your bug report.
336 Please describe the bug in annoying, painstaking detail.
338 Thank you for your help in stamping out bugs.
342 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
343 (autoload 'news-setup "rnewspost")
344 (autoload 'news-reply-mode "rnewspost")
345 (autoload 'rmail-dont-reply-to "mail-utils")
346 (autoload 'rmail-output "rmailout"))
350 ;;; Gnus Posting Functions
353 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
354 "p" gnus-summary-post-news
355 "i" gnus-summary-news-other-window
356 "f" gnus-summary-followup
357 "F" gnus-summary-followup-with-original
358 "c" gnus-summary-cancel-article
359 "s" gnus-summary-supersede-article
360 "r" gnus-summary-reply
361 "y" gnus-summary-yank-message
362 "R" gnus-summary-reply-with-original
363 "w" gnus-summary-wide-reply
364 "W" gnus-summary-wide-reply-with-original
365 "v" gnus-summary-very-wide-reply
366 "V" gnus-summary-very-wide-reply-with-original
367 "n" gnus-summary-followup-to-mail
368 "N" gnus-summary-followup-to-mail-with-original
369 "m" gnus-summary-mail-other-window
370 "u" gnus-uu-post-news
371 "\M-c" gnus-summary-mail-crosspost-complaint
372 "Br" gnus-summary-reply-broken-reply-to
373 "BR" gnus-summary-reply-broken-reply-to-with-original
374 "om" gnus-summary-mail-forward
375 "op" gnus-summary-post-forward
376 "Om" gnus-uu-digest-mail-forward
377 "Op" gnus-uu-digest-post-forward)
379 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
380 "b" gnus-summary-resend-bounced-mail
381 ;; "c" gnus-summary-send-draft
382 "r" gnus-summary-resend-message
383 "e" gnus-summary-resend-message-edit)
385 ;;; Internal functions.
387 (defun gnus-inews-make-draft ()
389 (gnus-inews-make-draft-meta-information
390 ,gnus-newsgroup-name ',gnus-article-reply)))
392 (defvar gnus-article-reply nil)
393 (defmacro gnus-setup-message (config &rest forms)
394 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
395 (buffer (make-symbol "gnus-setup-message-buffer"))
396 (article (make-symbol "gnus-setup-message-article"))
397 (yanked (make-symbol "gnus-setup-yanked-articles"))
398 (group (make-symbol "gnus-setup-message-group")))
399 `(let ((,winconf (current-window-configuration))
400 (,buffer (buffer-name (current-buffer)))
401 (,article gnus-article-reply)
402 (,yanked gnus-article-yanked-articles)
403 (,group gnus-newsgroup-name)
404 (message-header-setup-hook
405 (copy-sequence message-header-setup-hook))
406 (mbl mml-buffer-list)
407 (message-mode-hook (copy-sequence message-mode-hook)))
408 (setq mml-buffer-list nil)
409 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
410 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
411 ;; #### FIXME: for a reason that I did not manage to identify yet,
412 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
413 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
414 ;; After evaluation of @forms below, it gets the value we actually want
415 ;; to override, and the posting styles are used. For that reason, I've
416 ;; added an optional argument to `gnus-configure-posting-styles' to
417 ;; make sure that the correct value for the group name is used. -- drv
418 (add-hook 'message-mode-hook
420 (gnus-configure-posting-styles ,group)))
421 (gnus-pull ',(intern gnus-draft-meta-information-header)
422 message-required-headers)
424 (not (string= ,group "")))
426 (intern gnus-draft-meta-information-header)
427 (gnus-inews-make-draft))
428 message-required-headers))
432 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
434 (setq gnus-message-buffer (current-buffer))
435 (set (make-local-variable 'gnus-message-group-art)
436 (cons ,group ,article))
437 (set (make-local-variable 'gnus-newsgroup-name) ,group)
438 (gnus-run-hooks 'gnus-message-setup-hook)
439 (if (eq major-mode 'message-mode)
440 (let ((mbl1 mml-buffer-list))
441 (setq mml-buffer-list mbl) ;; Global value
442 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
443 ;; LOCAL argument of add-hook differs between GNU Emacs
444 ;; and XEmacs. make-local-hook makes sure they are local.
445 (make-local-hook 'kill-buffer-hook)
446 (make-local-hook 'change-major-mode-hook)
447 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
448 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
449 (mml-destroy-buffers)
450 (setq mml-buffer-list mbl)))
452 (gnus-configure-windows ,config t)
453 (run-hooks 'post-command-hook)
454 (set-buffer-modified-p nil))))
456 (defun gnus-inews-make-draft-meta-information (group article)
457 (concat "(\"" group "\" "
458 (if article (number-to-string
465 (defun gnus-msg-mail (&optional to subject other-headers continue
466 switch-action yank-action send-actions)
467 "Start editing a mail message to be sent.
468 Like `message-mail', but with Gnus paraphernalia, particularly the
469 Gcc: header for archiving purposes."
471 (let ((buf (current-buffer))
473 (gnus-setup-message 'message
474 (message-mail to subject other-headers continue
475 nil yank-action send-actions))
477 (setq mail-buf (current-buffer))
478 (switch-to-buffer buf)
479 (apply switch-action mail-buf nil)))
480 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
483 (defvar save-selected-window-window)
486 (defun gnus-button-mailto (address)
488 (set-buffer (gnus-copy-article-buffer))
489 (gnus-setup-message 'message
490 (message-reply address))
491 (and (boundp 'save-selected-window-window)
492 (not (window-live-p save-selected-window-window))
493 (setq save-selected-window-window (selected-window))))
496 (defun gnus-button-reply (&optional to-address wide)
497 "Like `message-reply'."
499 (gnus-setup-message 'message
500 (message-reply to-address wide))
501 (and (boundp 'save-selected-window-window)
502 (not (window-live-p save-selected-window-window))
503 (setq save-selected-window-window (selected-window))))
506 (define-mail-user-agent 'gnus-user-agent
507 'gnus-msg-mail 'message-send-and-exit
508 'message-kill-buffer 'message-send-hook)
510 (defun gnus-setup-posting-charset (group)
511 (let ((alist gnus-group-posting-charset-alist)
512 (group (or group ""))
516 (while (setq elem (pop alist))
517 (when (or (and (stringp (car elem))
518 (string-match (car elem) group))
519 (and (gnus-functionp (car elem))
520 (funcall (car elem) group))
521 (and (symbolp (car elem))
522 (symbol-value (car elem))))
523 (throw 'found (cons (cadr elem) (caddr elem)))))))))
525 (defun gnus-inews-add-send-actions (winconf buffer article
526 &optional config yanked)
527 (make-local-hook 'message-sent-hook)
528 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
529 'gnus-inews-do-gcc) nil t)
531 (make-local-hook 'message-header-hook)
532 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
533 (setq message-post-method
535 (gnus-post-method arg ,gnus-newsgroup-name)))
536 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
538 `(when (gnus-buffer-exists-p ,buffer)
539 (set-window-configuration ,winconf))
540 'exit 'postpone 'kill)
541 (let ((to-be-marked (cond
543 (article (if (listp article) article (list article)))
546 `(when (gnus-buffer-exists-p ,buffer)
550 (if (eq config 'forward)
551 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
552 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
555 (put 'gnus-setup-message 'lisp-indent-function 1)
556 (put 'gnus-setup-message 'edebug-form-spec '(form body))
558 ;;; Post news commands of Gnus group mode and summary mode
560 (defun gnus-group-mail (&optional arg)
561 "Start composing a mail.
562 If ARG, use the group under the point to find a posting style.
563 If ARG is 1, prompt for a group name to find the posting style."
565 ;; We can't `let' gnus-newsgroup-name here, since that leads
566 ;; to local variables leaking.
567 (let ((group gnus-newsgroup-name)
568 ;; make sure last viewed article doesn't affect posting styles:
570 (buffer (current-buffer)))
573 (setq gnus-newsgroup-name
575 (if (= 1 (prefix-numeric-value arg))
576 (completing-read "Use posting style of group: "
577 gnus-active-hashtb nil
578 (gnus-read-active-file-p))
579 (gnus-group-group-name))
581 ;; #### see comment in gnus-setup-message -- drv
582 (gnus-setup-message 'message (message-mail)))
585 (setq gnus-newsgroup-name group)))))
587 (defun gnus-group-news (&optional arg)
588 "Start composing a news.
589 If ARG, post to group under point.
590 If ARG is 1, prompt for group name to post to.
592 This function prepares a news even when using mail groups. This is useful
593 for posting messages to mail groups without actually sending them over the
594 network. The corresponding backend must have a 'request-post method."
596 ;; We can't `let' gnus-newsgroup-name here, since that leads
597 ;; to local variables leaking.
598 (let ((group gnus-newsgroup-name)
599 ;; make sure last viewed article doesn't affect posting styles:
601 (buffer (current-buffer)))
604 (setq gnus-newsgroup-name
606 (if (= 1 (prefix-numeric-value arg))
607 (completing-read "Use group: "
608 gnus-active-hashtb nil
609 (gnus-read-active-file-p))
610 (gnus-group-group-name))
612 ;; #### see comment in gnus-setup-message -- drv
613 (gnus-setup-message 'message
614 (message-news (gnus-group-real-name gnus-newsgroup-name))))
617 (setq gnus-newsgroup-name group)))))
619 (defun gnus-group-post-news (&optional arg)
620 "Start composing a message (a news by default).
621 If ARG, post to group under point. If ARG is 1, prompt for group name.
622 Depending on the selected group, the message might be either a mail or
625 ;; Bind this variable here to make message mode hooks work ok.
626 (let ((gnus-newsgroup-name
628 (if (= 1 (prefix-numeric-value arg))
629 (completing-read "Newsgroup: " gnus-active-hashtb nil
630 (gnus-read-active-file-p))
631 (gnus-group-group-name))
633 ;; make sure last viewed article doesn't affect posting styles:
635 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
636 (string= gnus-newsgroup-name ""))))
638 (defun gnus-summary-mail-other-window (&optional arg)
639 "Start composing a mail in another window.
640 Use the posting of the current group by default.
641 If ARG, don't do that. If ARG is 1, prompt for group name to find the
644 ;; We can't `let' gnus-newsgroup-name here, since that leads
645 ;; to local variables leaking.
646 (let ((group gnus-newsgroup-name)
647 ;; make sure last viewed article doesn't affect posting styles:
649 (buffer (current-buffer)))
652 (setq gnus-newsgroup-name
654 (if (= 1 (prefix-numeric-value arg))
655 (completing-read "Use group: "
656 gnus-active-hashtb nil
657 (gnus-read-active-file-p))
659 gnus-newsgroup-name))
660 ;; #### see comment in gnus-setup-message -- drv
661 (gnus-setup-message 'message (message-mail)))
664 (setq gnus-newsgroup-name group)))))
666 (defun gnus-summary-news-other-window (&optional arg)
667 "Start composing a news in another window.
668 Post to the current group by default.
669 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
671 This function prepares a news even when using mail groups. This is useful
672 for posting messages to mail groups without actually sending them over the
673 network. The corresponding backend must have a 'request-post method."
675 ;; We can't `let' gnus-newsgroup-name here, since that leads
676 ;; to local variables leaking.
677 (let ((group gnus-newsgroup-name)
678 ;; make sure last viewed article doesn't affect posting styles:
680 (buffer (current-buffer)))
683 (setq gnus-newsgroup-name
685 (if (= 1 (prefix-numeric-value arg))
686 (completing-read "Use group: "
687 gnus-active-hashtb nil
688 (gnus-read-active-file-p))
690 gnus-newsgroup-name))
691 ;; #### see comment in gnus-setup-message -- drv
692 (gnus-setup-message 'message
693 (message-news (gnus-group-real-name gnus-newsgroup-name))))
696 (setq gnus-newsgroup-name group)))))
698 (defun gnus-summary-post-news (&optional arg)
699 "Start composing a message. Post to the current group by default.
700 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
701 Depending on the selected group, the message might be either a mail or
704 ;; Bind this variable here to make message mode hooks work ok.
705 (let ((gnus-newsgroup-name
707 (if (= 1 (prefix-numeric-value arg))
708 (completing-read "Newsgroup: " gnus-active-hashtb nil
709 (gnus-read-active-file-p))
711 gnus-newsgroup-name))
712 ;; make sure last viewed article doesn't affect posting styles:
714 (gnus-post-news 'post gnus-newsgroup-name)))
717 (defun gnus-summary-followup (yank &optional force-news)
718 "Compose a followup to an article.
719 If prefix argument YANK is non-nil, the original article is yanked
721 YANK is a list of elements, where the car of each element is the
722 article number, and the two following numbers is the region to be
725 (list (and current-prefix-arg
726 (gnus-summary-work-articles 1))))
728 (gnus-summary-goto-subject
729 (if (listp (car yank))
732 (save-window-excursion
733 (gnus-summary-select-article))
734 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
735 (gnus-newsgroup-name gnus-newsgroup-name))
737 (gnus-post-news nil gnus-newsgroup-name
738 headers gnus-article-buffer
740 (gnus-summary-handle-replysign)))
742 (defun gnus-summary-followup-with-original (n &optional force-news)
743 "Compose a followup to an article and include the original article."
745 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
747 (defun gnus-summary-followup-to-mail (&optional arg)
748 "Followup to the current mail message via news."
750 (list (and current-prefix-arg
751 (gnus-summary-work-articles 1))))
752 (gnus-summary-followup arg t))
754 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
755 "Followup to the current mail message via news."
757 (gnus-summary-followup (gnus-summary-work-articles arg) t))
759 (defun gnus-inews-yank-articles (articles)
760 (let (beg article yank-string)
762 (while (setq article (pop articles))
763 (when (listp article)
764 (setq yank-string (nth 1 article)
765 article (nth 0 article)))
766 (save-window-excursion
767 (set-buffer gnus-summary-buffer)
768 (gnus-summary-select-article nil nil nil article)
769 (gnus-summary-remove-process-mark article))
770 (gnus-copy-article-buffer nil yank-string)
771 (let ((message-reply-buffer gnus-article-copy)
772 (message-reply-headers
773 ;; The headers are decoded.
774 (with-current-buffer gnus-article-copy
776 (nnheader-narrow-to-headers)
777 (nnheader-parse-naked-head)))))
778 (message-yank-original)
779 (setq beg (or beg (mark t))))
785 (defun gnus-summary-cancel-article (&optional n symp)
786 "Cancel an article you posted.
787 Uses the process-prefix convention. If given the symbolic
788 prefix `a', cancel using the standard posting method; if not
789 post using the current select method."
790 (interactive (gnus-interactive "P\ny"))
791 (let ((articles (gnus-summary-work-articles n))
794 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
796 (while (setq article (pop articles))
797 (when (gnus-summary-select-article t nil nil article)
798 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
799 (message-cancel-news))
800 (gnus-summary-mark-as-read article gnus-canceled-mark)
801 (gnus-cache-remove-article 1))
802 (gnus-article-hide-headers-if-wanted))
803 (gnus-summary-remove-process-mark article))))
805 (defun gnus-summary-supersede-article ()
806 "Compose an article that will supersede a previous article.
807 This is done simply by taking the old article and adding a Supersedes
808 header line with the old Message-ID."
810 (let ((article (gnus-summary-article-number)))
811 (gnus-setup-message 'reply-yank
812 (gnus-summary-select-article t)
813 (set-buffer gnus-original-article-buffer)
817 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
819 (set-buffer ,gnus-summary-buffer)
820 (gnus-cache-possibly-remove-article ,article nil nil nil t)
821 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
822 message-send-actions))))
826 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
827 ;; make a copy of the article buffer with all text properties removed
828 ;; this copy is in the buffer gnus-article-copy.
829 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
830 ;; this buffer should be passed to all mail/news reply/post routines.
831 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
833 (set-buffer gnus-article-copy)
834 (mm-enable-multibyte))
835 (let ((article-buffer (or article-buffer gnus-article-buffer))
837 (if (not (and (get-buffer article-buffer)
838 (gnus-buffer-exists-p article-buffer)))
839 (error "Can't find any article buffer")
841 (set-buffer article-buffer)
842 (let ((gnus-newsgroup-charset (or gnus-article-charset
843 gnus-newsgroup-charset))
844 (gnus-newsgroup-ignored-charsets
845 (or gnus-article-ignored-charsets
846 gnus-newsgroup-ignored-charsets)))
848 ;; Copy over the (displayed) article buffer, delete
849 ;; hidden text and remove text properties.
851 (copy-to-buffer gnus-article-copy (point-min) (point-max))
852 (set-buffer gnus-article-copy)
855 (delete-region (point) (point-max))
856 (insert yank-string))
857 (gnus-article-delete-text-of-type 'annotation)
858 (gnus-remove-text-with-property 'gnus-prev)
859 (gnus-remove-text-with-property 'gnus-next)
860 (gnus-remove-text-with-property 'gnus-decoration)
863 (buffer-substring-no-properties (point-min) (point-max))
865 ;; Find the original headers.
866 (set-buffer gnus-original-article-buffer)
867 (goto-char (point-min))
868 (while (looking-at message-unix-mail-delimiter)
870 (let ((mail-header-separator ""))
872 end (or (message-goto-body)
873 ;; There may be just a header.
875 ;; Delete the headers from the displayed articles.
876 (set-buffer gnus-article-copy)
877 (let ((mail-header-separator ""))
878 (delete-region (goto-char (point-min))
879 (or (message-goto-body) (point-max))))
880 ;; Insert the original article headers.
881 (insert-buffer-substring gnus-original-article-buffer beg end)
883 (let ((gnus-article-decode-hook
884 (delq 'article-decode-charset
885 (copy-sequence gnus-article-decode-hook))))
886 (run-hooks 'gnus-article-decode-hook)))))
889 (defun gnus-post-news (post &optional group header article-buffer yank subject
892 (gnus-copy-article-buffer))
893 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
894 (gnus-article-yanked-articles yank)
895 (add-to-list gnus-add-to-list))
896 (gnus-setup-message (cond (yank 'reply-yank)
897 (article-buffer 'reply)
899 (let* ((group (or group gnus-newsgroup-name))
900 (charset (gnus-group-name-charset nil group))
902 to-address to-group mailing-list to-list
905 (setq to-address (gnus-parameter-to-address group)
906 to-group (gnus-group-find-parameter group 'to-group)
907 to-list (gnus-parameter-to-list group)
908 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
909 mailing-list (when gnus-mailing-list-groups
910 (string-match gnus-mailing-list-groups group))
911 group (gnus-group-name-decode (gnus-group-real-name group)
913 (if (or (and to-group
914 (gnus-news-group-p to-group))
917 (and (gnus-news-group-p
918 (or pgroup gnus-newsgroup-name)
919 (or header gnus-current-article))
925 (message-news (or to-group group))
926 (set-buffer gnus-article-copy)
927 (gnus-msg-treat-broken-reply-to)
928 (message-followup (if (or newsgroup-p force-news)
929 (if (save-restriction
930 (article-narrow-to-head)
931 (message-fetch-field "newsgroups"))
938 (message-mail (or to-address to-list))
939 ;; Arrange for mail groups that have no `to-address' to
940 ;; get that when the user sends off the mail.
941 (when (and (not to-list)
944 (push (list 'gnus-inews-add-to-address pgroup)
945 message-send-actions)))
946 (set-buffer gnus-article-copy)
947 (gnus-msg-treat-broken-reply-to)
948 (message-wide-reply to-address)))
950 (gnus-inews-yank-articles yank))))))
952 (defun gnus-msg-treat-broken-reply-to (&optional force)
953 "Remove the Reply-to header if broken-reply-to."
955 (gnus-group-find-parameter
956 gnus-newsgroup-name 'broken-reply-to))
958 (message-narrow-to-head)
959 (message-remove-header "reply-to"))))
961 (defun gnus-post-method (arg group &optional silent)
962 "Return the posting method based on GROUP and ARG.
963 If SILENT, don't prompt the user."
964 (let ((gnus-post-method (or (gnus-parameter-post-method group)
966 (group-method (gnus-find-method-for-group group)))
968 ;; If the group-method is nil (which shouldn't happen) we use
969 ;; the default method.
971 (or (and (listp gnus-post-method) ;If not current/native/nil
972 (not (listp (car gnus-post-method))) ; and not a list of methods
973 gnus-post-method) ;then use it.
975 message-post-method))
976 ;; We want the inverse of the default
977 ((and arg (not (eq arg 0)))
978 (if (eq gnus-post-method 'current)
981 ;; We query the user for a post method.
983 (and (listp gnus-post-method)
984 (listp (car gnus-post-method))))
986 ;; Collect all methods we know about.
988 (when (listp gnus-post-method)
989 (if (listp (car gnus-post-method))
991 (list gnus-post-method)))
992 gnus-secondary-select-methods
993 (mapcar 'cdr gnus-server-alist)
994 (mapcar 'car gnus-opened-servers)
995 (list gnus-select-method)
996 (list group-method)))
997 method-alist post-methods method)
998 ;; Weed out all mail methods.
1000 (setq method (gnus-server-get-method "" (pop methods)))
1001 (when (and (or (gnus-method-option-p method 'post)
1002 (gnus-method-option-p method 'post-mail))
1003 (not (member method post-methods)))
1004 (push method post-methods)))
1005 ;; Create a name-method alist.
1009 (if (equal (cadr m) "")
1010 (list (symbol-name (car m)) m)
1011 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1016 (setq gnus-last-posting-server
1018 gnus-last-posting-server)
1019 ;; Just use the last value.
1020 gnus-last-posting-server
1022 "Posting method: " method-alist nil t
1023 (cons (or gnus-last-posting-server "") 0))))
1025 ;; Override normal method.
1026 ((and (eq gnus-post-method 'current)
1027 (not (memq (car group-method) gnus-discouraged-post-methods))
1028 (gnus-get-function group-method 'request-post t))
1031 ;; Use gnus-post-method.
1032 ((listp gnus-post-method) ;A method...
1033 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1035 ;; Use the normal select method (nil or native).
1036 (t gnus-select-method))))
1040 ;; Dummies to avoid byte-compile warning.
1042 (defvar nnspool-rejected-article-hook)
1043 (defvar xemacs-codename))
1045 (defun gnus-extended-version ()
1046 "Stringified Gnus version and Emacs version.
1047 See the variable `gnus-user-agent'."
1051 (prin1-to-string (gnus-continuum-version gnus-version) t)
1052 " (" gnus-version ")"))
1055 ((eq gnus-user-agent 'emacs-gnus-config)
1056 system-configuration)
1057 ((eq gnus-user-agent 'emacs-gnus-type)
1058 (symbol-name system-type))
1062 ((eq gnus-user-agent 'gnus)
1064 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
1065 (concat "Emacs/" (match-string 1 emacs-version)
1067 (concat " (" system-v ")")
1070 "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
1073 (match-string 1 emacs-version)
1074 (format "/%d.%d" emacs-major-version emacs-minor-version)
1075 (if (match-beginning 3)
1076 (match-string 3 emacs-version)
1078 (if (boundp 'xemacs-codename)
1080 " (" xemacs-codename
1082 (concat ", " system-v ")")
1085 (t emacs-version))))
1086 (if (stringp gnus-user-agent)
1090 (concat " " emacs-v))))))
1094 ;;; Gnus Mail Functions
1097 ;;; Mail reply commands of Gnus summary mode
1099 (defun gnus-summary-reply (&optional yank wide very-wide)
1100 "Start composing a mail reply to the current message.
1101 If prefix argument YANK is non-nil, the original article is yanked
1103 If WIDE, make a wide reply.
1104 If VERY-WIDE, make a very wide reply."
1106 (list (and current-prefix-arg
1107 (gnus-summary-work-articles 1))))
1108 ;; Allow user to require confirmation before replying by mail to the
1109 ;; author of a news article (or mail message).
1111 (not (or (gnus-news-group-p gnus-newsgroup-name)
1112 gnus-confirm-treat-mail-like-news))
1113 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1114 (string-match gnus-confirm-mail-reply-to-news
1115 gnus-newsgroup-name))
1116 ((functionp gnus-confirm-mail-reply-to-news)
1117 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1118 (t gnus-confirm-mail-reply-to-news)))
1119 (y-or-n-p "Really reply by mail to article author? "))
1121 (if (listp (car yank))
1124 (gnus-article-reply (or article (gnus-summary-article-number)))
1125 (gnus-article-yanked-articles yank)
1127 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1129 (gnus-summary-goto-subject article))
1130 (gnus-setup-message (if yank 'reply-yank 'reply)
1132 (gnus-summary-select-article)
1133 (dolist (article very-wide)
1134 (gnus-summary-select-article nil nil nil article)
1136 (set-buffer (gnus-copy-article-buffer))
1137 (gnus-msg-treat-broken-reply-to)
1139 (message-narrow-to-head)
1140 (setq headers (concat headers (buffer-string)))))))
1141 (set-buffer (gnus-copy-article-buffer))
1142 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1144 (message-narrow-to-head)
1148 (goto-char (point-max)))
1149 (mml-quote-region (point) (point-max))
1150 (message-reply nil wide)
1152 (gnus-inews-yank-articles yank))
1153 (gnus-summary-handle-replysign)))))
1155 (defun gnus-summary-handle-replysign ()
1156 "Check the various replysign variables and take action accordingly."
1157 (when (or gnus-message-replysign gnus-message-replyencrypt)
1158 (let (signed encrypted)
1160 (set-buffer gnus-article-buffer)
1161 (setq signed (memq 'signed gnus-article-wash-types))
1162 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1163 (cond ((and gnus-message-replyencrypt encrypted)
1164 (mml-secure-message mml-default-encrypt-method
1165 (if gnus-message-replysignencrypted
1168 ((and gnus-message-replysign signed)
1169 (mml-secure-message mml-default-sign-method 'sign))))))
1171 (defun gnus-summary-reply-with-original (n &optional wide)
1172 "Start composing a reply mail to the current message.
1173 The original article will be yanked."
1175 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1177 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1178 "Like `gnus-summary-reply' except removing reply-to field.
1179 If prefix argument YANK is non-nil, the original article is yanked
1181 If WIDE, make a wide reply.
1182 If VERY-WIDE, make a very wide reply."
1184 (list (and current-prefix-arg
1185 (gnus-summary-work-articles 1))))
1186 (let ((gnus-msg-force-broken-reply-to t))
1187 (gnus-summary-reply yank wide very-wide)))
1189 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1190 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1191 The original article will be yanked."
1193 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1195 (defun gnus-summary-wide-reply (&optional yank)
1196 "Start composing a wide reply mail to the current message.
1197 If prefix argument YANK is non-nil, the original article is yanked
1200 (list (and current-prefix-arg
1201 (gnus-summary-work-articles 1))))
1202 (gnus-summary-reply yank t))
1204 (defun gnus-summary-wide-reply-with-original (n)
1205 "Start composing a wide reply mail to the current message.
1206 The original article will be yanked."
1208 (gnus-summary-reply-with-original n t))
1210 (defun gnus-summary-very-wide-reply (&optional yank)
1211 "Start composing a very wide reply mail to the current message.
1212 If prefix argument YANK is non-nil, the original article is yanked
1215 (list (and current-prefix-arg
1216 (gnus-summary-work-articles 1))))
1217 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1219 (defun gnus-summary-very-wide-reply-with-original (n)
1220 "Start composing a very wide reply mail to the current message.
1221 The original article will be yanked."
1224 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1226 (defun gnus-summary-mail-forward (&optional arg post)
1227 "Forward the current message(s) to another user.
1228 If process marks exist, forward all marked messages;
1229 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1230 if ARG is 1, decode the message and forward directly inline;
1231 if ARG is 2, forward message as an rfc822 MIME section;
1232 if ARG is 3, decode message and forward as an rfc822 MIME section;
1233 if ARG is 4, forward message directly inline;
1234 otherwise, use flipped `message-forward-as-mime'.
1235 If POST, post instead of mail.
1236 For the `inline' alternatives, also see the variable
1237 `message-forward-ignored-headers'."
1239 (if (cdr (gnus-summary-work-articles nil))
1240 ;; Process marks are given.
1241 (gnus-uu-digest-mail-forward arg post)
1242 ;; No process marks.
1243 (let ((message-forward-as-mime message-forward-as-mime)
1244 (message-forward-show-mml message-forward-show-mml))
1248 (setq message-forward-as-mime nil
1249 message-forward-show-mml t))
1251 (setq message-forward-as-mime t
1252 message-forward-show-mml nil))
1254 (setq message-forward-as-mime t
1255 message-forward-show-mml t))
1257 (setq message-forward-as-mime nil
1258 message-forward-show-mml nil))
1260 (setq message-forward-as-mime (not message-forward-as-mime))))
1261 (let* ((gnus-article-reply (gnus-summary-article-number))
1262 (gnus-article-yanked-articles (list gnus-article-reply)))
1263 (gnus-setup-message 'forward
1264 (gnus-summary-select-article)
1265 (let ((mail-parse-charset
1266 (or (and (gnus-buffer-live-p gnus-article-buffer)
1267 (with-current-buffer gnus-article-buffer
1268 gnus-article-charset))
1269 gnus-newsgroup-charset))
1270 (mail-parse-ignored-charsets
1271 gnus-newsgroup-ignored-charsets))
1272 (set-buffer gnus-original-article-buffer)
1273 (message-forward post)))))))
1275 (defun gnus-summary-resend-message (address n)
1276 "Resend the current article to ADDRESS."
1278 (list (message-read-from-minibuffer
1279 "Resend message(s) to: "
1280 (when (and gnus-summary-resend-default-address
1281 (gnus-buffer-live-p gnus-original-article-buffer))
1282 ;; If some other article is currently selected, the
1283 ;; initial-contents is wrong. Whatever, it is just the
1284 ;; initial-contents.
1285 (with-current-buffer gnus-original-article-buffer
1286 (nnmail-fetch-field "to"))))
1287 current-prefix-arg))
1288 (let ((articles (gnus-summary-work-articles n))
1290 (while (setq article (pop articles))
1291 (gnus-summary-select-article nil nil nil article)
1293 (set-buffer gnus-original-article-buffer)
1294 (message-resend address))
1295 (gnus-summary-mark-article-as-forwarded article))))
1297 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1298 (defun gnus-summary-resend-message-edit ()
1299 "Resend an article that has already been sent.
1300 A new buffer will be created to allow the user to modify body and
1301 contents of the message, and then, everything will happen as when
1302 composing a new message."
1304 (let ((article (gnus-summary-article-number)))
1305 (gnus-setup-message 'reply-yank
1306 (gnus-summary-select-article t)
1307 (set-buffer gnus-original-article-buffer)
1308 (let ((cur (current-buffer))
1309 (to (message-fetch-field "to")))
1310 ;; Get a normal message buffer.
1311 (message-pop-to-buffer (message-buffer-name "Resend" to))
1312 (insert-buffer-substring cur)
1314 (message-narrow-to-head-1)
1315 ;; Gnus will generate a new one when sending.
1316 (message-remove-header "Message-ID")
1317 (message-remove-header message-ignored-resent-headers t)
1318 ;; Remove unwanted headers.
1319 (goto-char (point-max))
1320 (insert mail-header-separator)
1321 (goto-char (point-min))
1322 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1326 (defun gnus-summary-post-forward (&optional arg)
1327 "Forward the current article to a newsgroup.
1328 See `gnus-summary-mail-forward' for ARG."
1330 (gnus-summary-mail-forward arg t))
1332 (defvar gnus-nastygram-message
1333 "The following article was inappropriately posted to %s.\n\n"
1334 "Format string to insert in nastygrams.
1335 The current group name will be inserted at \"%s\".")
1337 (defun gnus-summary-mail-nastygram (n)
1338 "Send a nastygram to the author of the current article."
1340 (when (or gnus-expert-user
1342 "Really send a nastygram to the author of the current article? "))
1343 (let ((group gnus-newsgroup-name))
1344 (gnus-summary-reply-with-original n)
1345 (set-buffer gnus-message-buffer)
1347 (insert (format gnus-nastygram-message group))
1348 (message-send-and-exit))))
1350 (defun gnus-summary-mail-crosspost-complaint (n)
1351 "Send a complaint about crossposting to the current article(s)."
1353 (let ((articles (gnus-summary-work-articles n))
1355 (while (setq article (pop articles))
1356 (set-buffer gnus-summary-buffer)
1357 (gnus-summary-goto-subject article)
1358 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1359 newsgroups followup-to)
1360 (gnus-summary-select-article)
1361 (set-buffer gnus-original-article-buffer)
1362 (if (and (<= (length (message-tokenize-header
1364 (mail-fetch-field "newsgroups"))
1367 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1368 (not (member group (message-tokenize-header
1369 followup-to ", ")))))
1371 (gnus-message 1 "Followup-to restricted")
1372 (gnus-message 1 "Not a crossposted article"))
1373 (set-buffer gnus-summary-buffer)
1374 (gnus-summary-reply-with-original 1)
1375 (set-buffer gnus-message-buffer)
1377 (insert (format gnus-crosspost-complaint newsgroups group))
1378 (message-goto-subject)
1379 (re-search-forward " *$")
1380 (replace-match " (crosspost notification)" t t)
1381 (gnus-deactivate-mark)
1382 (when (gnus-y-or-n-p "Send this complaint? ")
1383 (message-send-and-exit)))))))
1385 (defun gnus-mail-parse-comma-list ()
1388 (skip-chars-forward " ")
1391 (skip-chars-forward "^,")
1396 (narrow-to-region beg (point))
1399 (while (search-forward "\"" nil t)
1403 (skip-chars-forward ",")
1404 (skip-chars-forward "^,"))
1405 (skip-chars-backward " ")
1406 (push (buffer-substring beg (point))
1408 (skip-chars-forward "^,")
1409 (skip-chars-forward ", "))
1412 (defun gnus-inews-add-to-address (group)
1413 (let ((to-address (mail-fetch-field "to")))
1414 (when (and to-address
1416 ;; This mail group doesn't have a `to-list', so we add one
1418 (when (gnus-y-or-n-p
1419 (format "Do you want to add this as `to-list': %s " to-address))
1420 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1422 (defun gnus-put-message ()
1423 "Put the current message in some group and return to Gnus."
1425 (let ((reply gnus-article-reply)
1426 (winconf gnus-prev-winconf)
1427 (group gnus-newsgroup-name))
1429 (not (gnus-group-read-only-p group)))
1430 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1432 (when (gnus-gethash group gnus-newsrc-hashtb)
1433 (error "No such group: %s" group))
1437 (message-narrow-to-headers)
1438 (let ((gnus-deletable-headers nil))
1439 (message-generate-headers
1440 (if (message-news-p)
1441 message-required-news-headers
1442 message-required-mail-headers)))
1443 (goto-char (point-max))
1444 (if (string-match " " group)
1445 (insert "Gcc: \"" group "\"\n")
1446 (insert "Gcc: " group "\n"))
1449 (when (and (get-buffer gnus-group-buffer)
1450 (gnus-buffer-exists-p (car-safe reply))
1452 (set-buffer (car reply))
1453 (gnus-summary-mark-article-as-replied (cdr reply)))
1455 (set-window-configuration winconf))))
1457 (defun gnus-article-mail (yank)
1458 "Send a reply to the address near point.
1459 If YANK is non-nil, include the original article."
1463 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1464 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1466 (gnus-msg-mail address)
1468 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1470 (defvar nntp-server-type)
1472 "Send a bug report to the Gnus maintainers."
1474 (unless (gnus-alive-p)
1475 (error "Gnus has been shut down"))
1476 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1477 (unless (message-mail-user-agent)
1478 (delete-other-windows)
1479 (when gnus-bug-create-help-buffer
1480 (switch-to-buffer "*Gnus Help Bug*")
1482 (insert gnus-bug-message)
1483 (goto-char (point-min)))
1484 (message-pop-to-buffer "*Gnus Bug*"))
1485 (let ((message-this-is-mail t))
1486 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1487 (when gnus-bug-create-help-buffer
1488 (push `(gnus-bug-kill-buffer) message-send-actions))
1489 (goto-char (point-min))
1490 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1492 (insert (gnus-version) "\n"
1493 (emacs-version) "\n")
1494 (when (and (boundp 'nntp-server-type)
1495 (stringp nntp-server-type))
1496 (insert nntp-server-type))
1497 (insert "\n\n\n\n\n")
1500 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1503 (setq text (buffer-string)))
1504 (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1505 (goto-char (point-min))
1506 (search-forward "Subject: " nil t)
1509 (defun gnus-bug-kill-buffer ()
1510 (when (get-buffer "*Gnus Help Bug*")
1511 (kill-buffer "*Gnus Help Bug*")))
1513 (defun gnus-summary-yank-message (buffer n)
1514 "Yank the current article into a composed message."
1516 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1517 current-prefix-arg))
1518 (gnus-summary-iterate n
1519 (let ((gnus-display-mime-function nil)
1520 (gnus-inhibit-treatment t))
1521 (gnus-summary-select-article))
1524 (message-yank-buffer gnus-article-buffer))))
1526 (defun gnus-debug ()
1527 "Attempts to go through the Gnus source file and report what variables have been changed.
1528 The source file has to be in the Emacs load path."
1530 (let ((files gnus-debug-files)
1532 file expr olist sym)
1533 (gnus-message 4 "Please wait while we snoop your variables...")
1535 ;; Go through all the files looking for non-default values for variables.
1537 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1540 (when (and (setq file (locate-library (pop files)))
1541 (file-exists-p file))
1542 (insert-file-contents file)
1543 (goto-char (point-min))
1544 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1545 (gnus-message 4 "Malformed sources in file %s" file)
1546 (narrow-to-region (point-min) (point))
1547 (goto-char (point-min))
1548 (while (setq expr (ignore-errors (read (current-buffer))))
1550 (and (or (eq (car expr) 'defvar)
1551 (eq (car expr) 'defcustom))
1552 (stringp (nth 3 expr))
1553 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1554 (or (not (boundp (nth 1 expr)))
1555 (not (equal (eval (nth 2 expr))
1556 (symbol-value (nth 1 expr)))))
1557 (push (nth 1 expr) olist)))))))
1558 (kill-buffer (current-buffer)))
1559 (when (setq olist (nreverse olist))
1560 (insert "------------------ Environment follows ------------------\n\n"))
1562 (if (boundp (car olist))
1564 (pp `(setq ,(car olist)
1565 ,(if (or (consp (setq sym (symbol-value (car olist))))
1567 (not (or (eq sym nil)
1569 (list 'quote (symbol-value (car olist)))
1570 (symbol-value (car olist))))
1572 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1573 (setq olist (cdr olist)))
1575 ;; Remove any control chars - they seem to cause trouble for some
1576 ;; mailers. (Byte-compiled output from the stuff above.)
1578 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1579 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1582 ;;; Treatment of rejected articles.
1585 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1586 "Re-mail the current message.
1587 This only makes sense if the current message is a bounce message than
1588 contains some mail you have written which has been bounced back to
1590 If FETCH, try to fetch the article that this is a reply to, if indeed
1593 (gnus-summary-select-article t)
1594 (set-buffer gnus-original-article-buffer)
1595 (gnus-setup-message 'compose-bounce
1596 (let* ((references (mail-fetch-field "references"))
1597 (parent (and references (gnus-parent-id references))))
1599 ;; If there are references, we fetch the article we answered to.
1601 (gnus-summary-refer-article parent)
1602 (gnus-summary-show-all-headers)))))
1606 (defun gnus-inews-group-method (group)
1608 ;; If the group doesn't exist, we assume
1609 ;; it's an archive group...
1610 ((and (null (gnus-get-info group))
1611 (eq (car (gnus-server-to-method gnus-message-archive-method))
1612 (car (gnus-server-to-method (gnus-group-method group)))))
1613 gnus-message-archive-method)
1615 ((gnus-info-method (gnus-get-info group))
1616 (gnus-info-method (gnus-get-info group)))
1618 (t (gnus-server-to-method (gnus-group-method group)))))
1620 ;; Do Gcc handling, which copied the message over to some group.
1621 (defun gnus-inews-do-gcc (&optional gcc)
1625 (message-narrow-to-headers)
1626 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1627 (cur (current-buffer))
1628 groups group method group-art
1629 mml-externalize-attachments)
1631 (message-remove-header "gcc")
1633 (setq groups (message-unquote-tokens
1634 (message-tokenize-header gcc " ,")))
1635 ;; Copy the article over to some group(s).
1636 (while (setq group (pop groups))
1637 (unless (gnus-check-server
1638 (setq method (gnus-inews-group-method group)))
1639 (error "Can't open server %s" (if (stringp method) method
1641 (unless (gnus-request-group group nil method)
1642 (gnus-request-create-group group method))
1643 (setq mml-externalize-attachments
1644 (if (stringp gnus-gcc-externalize-attachments)
1645 (string-match gnus-gcc-externalize-attachments group)
1646 gnus-gcc-externalize-attachments))
1648 (nnheader-set-temp-buffer " *acc*")
1649 (insert-buffer-substring cur)
1650 (message-encode-message-body)
1652 (message-narrow-to-headers)
1653 (let* ((mail-parse-charset message-default-charset)
1654 (newsgroups-field (save-restriction
1655 (message-narrow-to-headers-or-head)
1656 (message-fetch-field "Newsgroups")))
1657 (followup-field (save-restriction
1658 (message-narrow-to-headers-or-head)
1659 (message-fetch-field "Followup-To")))
1660 ;; BUG: We really need to get the charset for
1661 ;; each name in the Newsgroups and Followup-To
1662 ;; lines to allow crossposting between group
1663 ;; namess with incompatible character sets.
1664 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1665 (group-field-charset
1666 (gnus-group-name-charset
1667 method (or newsgroups-field "")))
1668 (followup-field-charset
1669 (gnus-group-name-charset
1670 method (or followup-field "")))
1671 (rfc2047-header-encoding-alist
1673 (when group-field-charset
1674 (list (cons "Newsgroups" group-field-charset)))
1675 (when followup-field-charset
1676 (list (cons "Followup-To" followup-field-charset)))
1677 rfc2047-header-encoding-alist)))
1678 (mail-encode-encoded-word-buffer)))
1679 (goto-char (point-min))
1680 (when (re-search-forward
1681 (concat "^" (regexp-quote mail-header-separator) "$")
1683 (replace-match "" t t ))
1684 (unless (setq group-art
1685 (gnus-request-accept-article group method t t))
1686 (gnus-message 1 "Couldn't store article in group %s: %s"
1687 group (gnus-status-message method))
1689 (when (and group-art
1690 ;; FIXME: Should gcc-mark-as-read work when
1691 ;; Gnus is not running?
1693 (or gnus-gcc-mark-as-read
1694 gnus-inews-mark-gcc-as-read))
1695 (gnus-group-mark-article-read group (cdr group-art)))
1696 (kill-buffer (current-buffer)))))))))
1698 (defun gnus-inews-insert-gcc ()
1699 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1702 (message-narrow-to-headers)
1703 (let* ((group gnus-outgoing-message-group)
1705 ((gnus-functionp group)
1707 ((or (stringp group) (list group))
1712 (if (string-match " " gcc)
1713 (concat "\"" gcc "\"")
1715 (mapconcat (lambda (group)
1716 (if (string-match " " group)
1717 (concat "\"" group "\"")
1722 (defun gnus-inews-insert-archive-gcc (&optional group)
1723 "Insert the Gcc to say where the article is to be archived."
1724 (let* ((var gnus-message-archive-group)
1725 (group (or group gnus-newsgroup-name ""))
1727 (and gnus-newsgroup-name
1728 (not (equal gnus-newsgroup-name ""))
1729 (gnus-group-find-parameter
1730 gnus-newsgroup-name 'gcc-self)))
1734 ((null gnus-message-archive-method)
1738 ;; Just a single group.
1741 ;; We don't want this.
1743 ((and (listp var) (stringp (car var)))
1744 ;; A list of groups.
1746 ((gnus-functionp var)
1748 (funcall var group))
1750 ;; An alist of regexps/functions/forms.
1755 ((stringp (caar var))
1757 (when (string-match (caar var) group)
1759 ((gnus-functionp (car var))
1761 (funcall (car var) group))
1763 (eval (car var)))))))
1764 (setq var (cdr var)))
1767 (when (or groups gcc-self-val)
1768 (when (stringp groups)
1769 (setq groups (list groups)))
1772 (message-narrow-to-headers)
1773 (goto-char (point-max))
1776 ;; Use the `gcc-self' param value instead.
1779 (if (stringp gcc-self-val)
1780 (if (string-match " " gcc-self-val)
1781 (concat "\"" gcc-self-val "\"")
1783 (if (string-match " " group)
1784 (concat "\"" group "\"")
1786 (if (not (eq gcc-self-val 'none))
1788 (gnus-delete-line)))
1789 ;; Use the list of groups.
1790 (while (setq name (pop groups))
1791 (let ((str (if (string-match ":" name)
1793 (gnus-group-prefixed-name
1794 name gnus-message-archive-method))))
1795 (insert (if (string-match " " str)
1796 (concat "\"" str "\"")
1802 (defun gnus-mailing-list-followup-to ()
1803 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1804 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1805 (list-post (gnus-fetch-original-field "list-post")))
1806 (when (and list-post
1807 (string-match "mailto:\\([^>]+\\)" list-post))
1808 (setq list-post (match-string 1 list-post)))
1814 (defun gnus-configure-posting-styles (&optional group-name)
1815 "Configure posting styles according to `gnus-posting-styles'."
1816 (unless gnus-inhibit-posting-styles
1817 (let ((group (or group-name gnus-newsgroup-name ""))
1818 (styles gnus-posting-styles)
1819 style match variable attribute value v results
1820 filep name address element)
1821 ;; If the group has a posting-style parameter, add it at the end with a
1822 ;; regexp matching everything, to be sure it takes precedence over all
1824 (when gnus-newsgroup-name
1825 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1827 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1828 ;; Go through all styles and look for matches.
1829 (dolist (style styles)
1830 (setq match (pop style))
1831 (goto-char (point-min))
1834 ;; Regexp string match on the group name.
1835 (string-match match group))
1837 ;; Obsolete format of header match.
1838 (and (gnus-buffer-live-p gnus-article-copy)
1839 (with-current-buffer gnus-article-copy
1840 (let ((header (message-fetch-field (pop style))))
1842 (string-match (pop style) header))))))
1843 ((or (symbolp match)
1844 (gnus-functionp match))
1846 ((gnus-functionp match)
1847 ;; Function to be called.
1850 ;; Variable to be checked.
1851 (symbol-value match))))
1854 ((eq (car match) 'header)
1855 ;; New format of header match.
1856 (and (gnus-buffer-live-p gnus-article-copy)
1857 (with-current-buffer gnus-article-copy
1858 (let ((header (message-fetch-field (nth 1 match))))
1860 (string-match (nth 2 match) header))))))
1862 ;; This is a form to be evaled.
1864 ;; We have a match, so we set the variables.
1865 (dolist (attribute style)
1866 (setq element (pop attribute)
1871 ((eq (car attribute) :file)
1874 ((eq (car attribute) :value)
1878 ;; We get the value.
1883 ((or (symbolp value)
1884 (gnus-functionp value))
1885 (cond ((gnus-functionp value)
1888 (symbol-value value))))
1891 ;; Translate obsolescent value.
1893 ((eq element 'signature-file)
1894 (setq element 'signature
1896 ((eq element 'x-face-file)
1897 (setq element 'x-face
1899 ;; Get the contents of file elems.
1901 (setq v (with-temp-buffer
1902 (insert-file-contents v)
1903 (goto-char (point-max))
1907 (setq results (delq (assoc element results) results))
1908 (push (cons element v) results))))
1909 ;; Now we have all the styles, so we insert them.
1910 (setq name (assq 'name results)
1911 address (assq 'address results))
1912 (setq results (delq name (delq address results)))
1913 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1914 (make-local-hook 'message-setup-hook)
1915 (setq results (sort results (lambda (x y)
1916 (string-lessp (car x) (car y)))))
1917 (dolist (result results)
1918 (add-hook 'message-setup-hook
1920 ((eq 'eval (car result))
1922 ((eq 'body (car result))
1926 (insert ,(cdr result)))))
1927 ((eq 'signature (car result))
1928 (set (make-local-variable 'message-signature) nil)
1929 (set (make-local-variable 'message-signature-file) nil)
1930 (if (not (cdr result))
1934 (let ((message-signature ,(cdr result)))
1935 (when message-signature
1936 (message-insert-signature)))))))
1939 (if (symbolp (car result))
1940 (capitalize (symbol-name (car result)))
1944 (message-remove-header ,header)
1945 (let ((value ,(cdr result)))
1948 (insert ,header ": " value)
1950 (insert "\n")))))))))
1952 (when (or name address)
1953 (add-hook 'message-setup-hook
1955 (set (make-local-variable 'user-mail-address)
1956 ,(or (cdr address) user-mail-address))
1957 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1959 ,(or (cdr address) user-mail-address)))
1961 (message-remove-header "From")
1963 (insert "From: " (message-make-from) "\n"))))
1966 ;;; Allow redefinition of functions.
1972 ;;; gnus-msg.el ends here