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)))
451 (message-hide-headers)
453 (gnus-configure-windows ,config t)
454 (run-hooks 'post-command-hook)
455 (set-buffer-modified-p nil))))
457 (defun gnus-inews-make-draft-meta-information (group article)
458 (concat "(\"" group "\" "
459 (if article (number-to-string
466 (defun gnus-msg-mail (&optional to subject other-headers continue
467 switch-action yank-action send-actions)
468 "Start editing a mail message to be sent.
469 Like `message-mail', but with Gnus paraphernalia, particularly the
470 Gcc: header for archiving purposes."
472 (let ((buf (current-buffer))
474 (gnus-setup-message 'message
475 (message-mail to subject other-headers continue
476 nil yank-action send-actions))
478 (setq mail-buf (current-buffer))
479 (switch-to-buffer buf)
480 (apply switch-action mail-buf nil)))
481 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
484 (defvar save-selected-window-window)
487 (defun gnus-button-mailto (address)
489 (set-buffer (gnus-copy-article-buffer))
490 (gnus-setup-message 'message
491 (message-reply address))
492 (and (boundp 'save-selected-window-window)
493 (not (window-live-p save-selected-window-window))
494 (setq save-selected-window-window (selected-window))))
497 (defun gnus-button-reply (&optional to-address wide)
498 "Like `message-reply'."
500 (gnus-setup-message 'message
501 (message-reply to-address wide))
502 (and (boundp 'save-selected-window-window)
503 (not (window-live-p save-selected-window-window))
504 (setq save-selected-window-window (selected-window))))
507 (define-mail-user-agent 'gnus-user-agent
508 'gnus-msg-mail 'message-send-and-exit
509 'message-kill-buffer 'message-send-hook)
511 (defun gnus-setup-posting-charset (group)
512 (let ((alist gnus-group-posting-charset-alist)
513 (group (or group ""))
517 (while (setq elem (pop alist))
518 (when (or (and (stringp (car elem))
519 (string-match (car elem) group))
520 (and (gnus-functionp (car elem))
521 (funcall (car elem) group))
522 (and (symbolp (car elem))
523 (symbol-value (car elem))))
524 (throw 'found (cons (cadr elem) (caddr elem)))))))))
526 (defun gnus-inews-add-send-actions (winconf buffer article
527 &optional config yanked)
528 (make-local-hook 'message-sent-hook)
529 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
530 'gnus-inews-do-gcc) nil t)
532 (make-local-hook 'message-header-hook)
533 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
534 (setq message-post-method
536 (gnus-post-method arg ,gnus-newsgroup-name)))
537 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
539 `(when (gnus-buffer-exists-p ,buffer)
540 (set-window-configuration ,winconf))
541 'exit 'postpone 'kill)
542 (let ((to-be-marked (cond
544 (article (if (listp article) article (list article)))
547 `(when (gnus-buffer-exists-p ,buffer)
551 (if (eq config 'forward)
552 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
553 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
556 (put 'gnus-setup-message 'lisp-indent-function 1)
557 (put 'gnus-setup-message 'edebug-form-spec '(form body))
559 ;;; Post news commands of Gnus group mode and summary mode
561 (defun gnus-group-mail (&optional arg)
562 "Start composing a mail.
563 If ARG, use the group under the point to find a posting style.
564 If ARG is 1, prompt for a group name to find the posting style."
566 ;; We can't `let' gnus-newsgroup-name here, since that leads
567 ;; to local variables leaking.
568 (let ((group gnus-newsgroup-name)
569 ;; make sure last viewed article doesn't affect posting styles:
571 (buffer (current-buffer)))
574 (setq gnus-newsgroup-name
576 (if (= 1 (prefix-numeric-value arg))
577 (completing-read "Use posting style of group: "
578 gnus-active-hashtb nil
579 (gnus-read-active-file-p))
580 (gnus-group-group-name))
582 ;; #### see comment in gnus-setup-message -- drv
583 (gnus-setup-message 'message (message-mail)))
586 (setq gnus-newsgroup-name group)))))
588 (defun gnus-group-news (&optional arg)
589 "Start composing a news.
590 If ARG, post to group under point.
591 If ARG is 1, prompt for group name to post to.
593 This function prepares a news even when using mail groups. This is useful
594 for posting messages to mail groups without actually sending them over the
595 network. The corresponding backend must have a 'request-post method."
597 ;; We can't `let' gnus-newsgroup-name here, since that leads
598 ;; to local variables leaking.
599 (let ((group gnus-newsgroup-name)
600 ;; make sure last viewed article doesn't affect posting styles:
602 (buffer (current-buffer)))
605 (setq gnus-newsgroup-name
607 (if (= 1 (prefix-numeric-value arg))
608 (completing-read "Use group: "
609 gnus-active-hashtb nil
610 (gnus-read-active-file-p))
611 (gnus-group-group-name))
613 ;; #### see comment in gnus-setup-message -- drv
614 (gnus-setup-message 'message
615 (message-news (gnus-group-real-name gnus-newsgroup-name))))
618 (setq gnus-newsgroup-name group)))))
620 (defun gnus-group-post-news (&optional arg)
621 "Start composing a message (a news by default).
622 If ARG, post to group under point. If ARG is 1, prompt for group name.
623 Depending on the selected group, the message might be either a mail or
626 ;; Bind this variable here to make message mode hooks work ok.
627 (let ((gnus-newsgroup-name
629 (if (= 1 (prefix-numeric-value arg))
630 (completing-read "Newsgroup: " gnus-active-hashtb nil
631 (gnus-read-active-file-p))
632 (gnus-group-group-name))
634 ;; make sure last viewed article doesn't affect posting styles:
636 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
637 (string= gnus-newsgroup-name ""))))
639 (defun gnus-summary-mail-other-window (&optional arg)
640 "Start composing a mail in another window.
641 Use the posting of the current group by default.
642 If ARG, don't do that. If ARG is 1, prompt for group name to find the
645 ;; We can't `let' gnus-newsgroup-name here, since that leads
646 ;; to local variables leaking.
647 (let ((group gnus-newsgroup-name)
648 ;; make sure last viewed article doesn't affect posting styles:
650 (buffer (current-buffer)))
653 (setq gnus-newsgroup-name
655 (if (= 1 (prefix-numeric-value arg))
656 (completing-read "Use group: "
657 gnus-active-hashtb nil
658 (gnus-read-active-file-p))
660 gnus-newsgroup-name))
661 ;; #### see comment in gnus-setup-message -- drv
662 (gnus-setup-message 'message (message-mail)))
665 (setq gnus-newsgroup-name group)))))
667 (defun gnus-summary-news-other-window (&optional arg)
668 "Start composing a news in another window.
669 Post to the current group by default.
670 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
672 This function prepares a news even when using mail groups. This is useful
673 for posting messages to mail groups without actually sending them over the
674 network. The corresponding backend must have a 'request-post method."
676 ;; We can't `let' gnus-newsgroup-name here, since that leads
677 ;; to local variables leaking.
678 (let ((group gnus-newsgroup-name)
679 ;; make sure last viewed article doesn't affect posting styles:
681 (buffer (current-buffer)))
684 (setq gnus-newsgroup-name
686 (if (= 1 (prefix-numeric-value arg))
687 (completing-read "Use group: "
688 gnus-active-hashtb nil
689 (gnus-read-active-file-p))
691 gnus-newsgroup-name))
692 ;; #### see comment in gnus-setup-message -- drv
693 (gnus-setup-message 'message
694 (message-news (gnus-group-real-name gnus-newsgroup-name))))
697 (setq gnus-newsgroup-name group)))))
699 (defun gnus-summary-post-news (&optional arg)
700 "Start composing a message. Post to the current group by default.
701 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
702 Depending on the selected group, the message might be either a mail or
705 ;; Bind this variable here to make message mode hooks work ok.
706 (let ((gnus-newsgroup-name
708 (if (= 1 (prefix-numeric-value arg))
709 (completing-read "Newsgroup: " gnus-active-hashtb nil
710 (gnus-read-active-file-p))
712 gnus-newsgroup-name))
713 ;; make sure last viewed article doesn't affect posting styles:
715 (gnus-post-news 'post gnus-newsgroup-name)))
718 (defun gnus-summary-followup (yank &optional force-news)
719 "Compose a followup to an article.
720 If prefix argument YANK is non-nil, the original article is yanked
722 YANK is a list of elements, where the car of each element is the
723 article number, and the two following numbers is the region to be
726 (list (and current-prefix-arg
727 (gnus-summary-work-articles 1))))
729 (gnus-summary-goto-subject
730 (if (listp (car yank))
733 (save-window-excursion
734 (gnus-summary-select-article))
735 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
736 (gnus-newsgroup-name gnus-newsgroup-name))
738 (gnus-post-news nil gnus-newsgroup-name
739 headers gnus-article-buffer
741 (gnus-summary-handle-replysign)))
743 (defun gnus-summary-followup-with-original (n &optional force-news)
744 "Compose a followup to an article and include the original article."
746 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
748 (defun gnus-summary-followup-to-mail (&optional arg)
749 "Followup to the current mail message via news."
751 (list (and current-prefix-arg
752 (gnus-summary-work-articles 1))))
753 (gnus-summary-followup arg t))
755 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
756 "Followup to the current mail message via news."
758 (gnus-summary-followup (gnus-summary-work-articles arg) t))
760 (defun gnus-inews-yank-articles (articles)
761 (let (beg article yank-string)
763 (while (setq article (pop articles))
764 (when (listp article)
765 (setq yank-string (nth 1 article)
766 article (nth 0 article)))
767 (save-window-excursion
768 (set-buffer gnus-summary-buffer)
769 (gnus-summary-select-article nil nil nil article)
770 (gnus-summary-remove-process-mark article))
771 (gnus-copy-article-buffer nil yank-string)
772 (let ((message-reply-buffer gnus-article-copy)
773 (message-reply-headers
774 ;; The headers are decoded.
775 (with-current-buffer gnus-article-copy
777 (nnheader-narrow-to-headers)
778 (nnheader-parse-naked-head)))))
779 (message-yank-original)
780 (setq beg (or beg (mark t))))
786 (defun gnus-summary-cancel-article (&optional n symp)
787 "Cancel an article you posted.
788 Uses the process-prefix convention. If given the symbolic
789 prefix `a', cancel using the standard posting method; if not
790 post using the current select method."
791 (interactive (gnus-interactive "P\ny"))
792 (let ((articles (gnus-summary-work-articles n))
795 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
797 (while (setq article (pop articles))
798 (when (gnus-summary-select-article t nil nil article)
799 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
800 (message-cancel-news))
801 (gnus-summary-mark-as-read article gnus-canceled-mark)
802 (gnus-cache-remove-article 1))
803 (gnus-article-hide-headers-if-wanted))
804 (gnus-summary-remove-process-mark article))))
806 (defun gnus-summary-supersede-article ()
807 "Compose an article that will supersede a previous article.
808 This is done simply by taking the old article and adding a Supersedes
809 header line with the old Message-ID."
811 (let ((article (gnus-summary-article-number)))
812 (gnus-setup-message 'reply-yank
813 (gnus-summary-select-article t)
814 (set-buffer gnus-original-article-buffer)
818 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
820 (set-buffer ,gnus-summary-buffer)
821 (gnus-cache-possibly-remove-article ,article nil nil nil t)
822 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
823 message-send-actions))))
827 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
828 ;; make a copy of the article buffer with all text properties removed
829 ;; this copy is in the buffer gnus-article-copy.
830 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
831 ;; this buffer should be passed to all mail/news reply/post routines.
832 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
834 (set-buffer gnus-article-copy)
835 (mm-enable-multibyte))
836 (let ((article-buffer (or article-buffer gnus-article-buffer))
838 (if (not (and (get-buffer article-buffer)
839 (gnus-buffer-exists-p article-buffer)))
840 (error "Can't find any article buffer")
842 (set-buffer article-buffer)
843 (let ((gnus-newsgroup-charset (or gnus-article-charset
844 gnus-newsgroup-charset))
845 (gnus-newsgroup-ignored-charsets
846 (or gnus-article-ignored-charsets
847 gnus-newsgroup-ignored-charsets)))
849 ;; Copy over the (displayed) article buffer, delete
850 ;; hidden text and remove text properties.
852 (copy-to-buffer gnus-article-copy (point-min) (point-max))
853 (set-buffer gnus-article-copy)
856 (delete-region (point) (point-max))
857 (insert yank-string))
858 (gnus-article-delete-text-of-type 'annotation)
859 (gnus-remove-text-with-property 'gnus-prev)
860 (gnus-remove-text-with-property 'gnus-next)
861 (gnus-remove-text-with-property 'gnus-decoration)
864 (buffer-substring-no-properties (point-min) (point-max))
866 ;; Find the original headers.
867 (set-buffer gnus-original-article-buffer)
868 (goto-char (point-min))
869 (while (looking-at message-unix-mail-delimiter)
871 (let ((mail-header-separator ""))
873 end (or (message-goto-body)
874 ;; There may be just a header.
876 ;; Delete the headers from the displayed articles.
877 (set-buffer gnus-article-copy)
878 (let ((mail-header-separator ""))
879 (delete-region (goto-char (point-min))
880 (or (message-goto-body) (point-max))))
881 ;; Insert the original article headers.
882 (insert-buffer-substring gnus-original-article-buffer beg end)
884 (let ((gnus-article-decode-hook
885 (delq 'article-decode-charset
886 (copy-sequence gnus-article-decode-hook))))
887 (run-hooks 'gnus-article-decode-hook)))))
890 (defun gnus-post-news (post &optional group header article-buffer yank subject
893 (gnus-copy-article-buffer))
894 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
895 (gnus-article-yanked-articles yank)
896 (add-to-list gnus-add-to-list))
897 (gnus-setup-message (cond (yank 'reply-yank)
898 (article-buffer 'reply)
900 (let* ((group (or group gnus-newsgroup-name))
901 (charset (gnus-group-name-charset nil group))
903 to-address to-group mailing-list to-list
906 (setq to-address (gnus-parameter-to-address group)
907 to-group (gnus-group-find-parameter group 'to-group)
908 to-list (gnus-parameter-to-list group)
909 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
910 mailing-list (when gnus-mailing-list-groups
911 (string-match gnus-mailing-list-groups group))
912 group (gnus-group-name-decode (gnus-group-real-name group)
914 (if (or (and to-group
915 (gnus-news-group-p to-group))
918 (and (gnus-news-group-p
919 (or pgroup gnus-newsgroup-name)
920 (or header gnus-current-article))
926 (message-news (or to-group group))
927 (set-buffer gnus-article-copy)
928 (gnus-msg-treat-broken-reply-to)
929 (message-followup (if (or newsgroup-p force-news)
930 (if (save-restriction
931 (article-narrow-to-head)
932 (message-fetch-field "newsgroups"))
939 (message-mail (or to-address to-list))
940 ;; Arrange for mail groups that have no `to-address' to
941 ;; get that when the user sends off the mail.
942 (when (and (not to-list)
945 (push (list 'gnus-inews-add-to-address pgroup)
946 message-send-actions)))
947 (set-buffer gnus-article-copy)
948 (gnus-msg-treat-broken-reply-to)
949 (message-wide-reply to-address)))
951 (gnus-inews-yank-articles yank))))))
953 (defun gnus-msg-treat-broken-reply-to (&optional force)
954 "Remove the Reply-to header if broken-reply-to."
956 (gnus-group-find-parameter
957 gnus-newsgroup-name 'broken-reply-to))
959 (message-narrow-to-head)
960 (message-remove-header "reply-to"))))
962 (defun gnus-post-method (arg group &optional silent)
963 "Return the posting method based on GROUP and ARG.
964 If SILENT, don't prompt the user."
965 (let ((gnus-post-method (or (gnus-parameter-post-method group)
967 (group-method (gnus-find-method-for-group group)))
969 ;; If the group-method is nil (which shouldn't happen) we use
970 ;; the default method.
972 (or (and (listp gnus-post-method) ;If not current/native/nil
973 (not (listp (car gnus-post-method))) ; and not a list of methods
974 gnus-post-method) ;then use it.
976 message-post-method))
977 ;; We want the inverse of the default
978 ((and arg (not (eq arg 0)))
979 (if (eq gnus-post-method 'current)
982 ;; We query the user for a post method.
984 (and (listp gnus-post-method)
985 (listp (car gnus-post-method))))
987 ;; Collect all methods we know about.
989 (when (listp gnus-post-method)
990 (if (listp (car gnus-post-method))
992 (list gnus-post-method)))
993 gnus-secondary-select-methods
994 (mapcar 'cdr gnus-server-alist)
995 (mapcar 'car gnus-opened-servers)
996 (list gnus-select-method)
997 (list group-method)))
998 method-alist post-methods method)
999 ;; Weed out all mail methods.
1001 (setq method (gnus-server-get-method "" (pop methods)))
1002 (when (and (or (gnus-method-option-p method 'post)
1003 (gnus-method-option-p method 'post-mail))
1004 (not (member method post-methods)))
1005 (push method post-methods)))
1006 ;; Create a name-method alist.
1010 (if (equal (cadr m) "")
1011 (list (symbol-name (car m)) m)
1012 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1017 (setq gnus-last-posting-server
1019 gnus-last-posting-server)
1020 ;; Just use the last value.
1021 gnus-last-posting-server
1023 "Posting method: " method-alist nil t
1024 (cons (or gnus-last-posting-server "") 0))))
1026 ;; Override normal method.
1027 ((and (eq gnus-post-method 'current)
1028 (not (memq (car group-method) gnus-discouraged-post-methods))
1029 (gnus-get-function group-method 'request-post t))
1032 ;; Use gnus-post-method.
1033 ((listp gnus-post-method) ;A method...
1034 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1036 ;; Use the normal select method (nil or native).
1037 (t gnus-select-method))))
1041 ;; Dummies to avoid byte-compile warning.
1043 (defvar nnspool-rejected-article-hook)
1044 (defvar xemacs-codename))
1046 (defun gnus-extended-version ()
1047 "Stringified Gnus version and Emacs version.
1048 See the variable `gnus-user-agent'."
1052 (prin1-to-string (gnus-continuum-version gnus-version) t)
1053 " (" gnus-version ")"))
1056 ((eq gnus-user-agent 'emacs-gnus-config)
1057 system-configuration)
1058 ((eq gnus-user-agent 'emacs-gnus-type)
1059 (symbol-name system-type))
1063 ((eq gnus-user-agent 'gnus)
1065 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
1066 (concat "Emacs/" (match-string 1 emacs-version)
1068 (concat " (" system-v ")")
1071 "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
1074 (match-string 1 emacs-version)
1075 (format "/%d.%d" emacs-major-version emacs-minor-version)
1076 (if (match-beginning 3)
1077 (match-string 3 emacs-version)
1079 (if (boundp 'xemacs-codename)
1081 " (" xemacs-codename
1083 (concat ", " system-v ")")
1086 (t emacs-version))))
1087 (if (stringp gnus-user-agent)
1091 (concat " " emacs-v))))))
1095 ;;; Gnus Mail Functions
1098 ;;; Mail reply commands of Gnus summary mode
1100 (defun gnus-summary-reply (&optional yank wide very-wide)
1101 "Start composing a mail reply to the current message.
1102 If prefix argument YANK is non-nil, the original article is yanked
1104 If WIDE, make a wide reply.
1105 If VERY-WIDE, make a very wide reply."
1107 (list (and current-prefix-arg
1108 (gnus-summary-work-articles 1))))
1109 ;; Allow user to require confirmation before replying by mail to the
1110 ;; author of a news article (or mail message).
1112 (not (or (gnus-news-group-p gnus-newsgroup-name)
1113 gnus-confirm-treat-mail-like-news))
1114 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1115 (string-match gnus-confirm-mail-reply-to-news
1116 gnus-newsgroup-name))
1117 ((functionp gnus-confirm-mail-reply-to-news)
1118 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1119 (t gnus-confirm-mail-reply-to-news)))
1120 (y-or-n-p "Really reply by mail to article author? "))
1122 (if (listp (car yank))
1125 (gnus-article-reply (or article (gnus-summary-article-number)))
1126 (gnus-article-yanked-articles yank)
1128 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1130 (gnus-summary-goto-subject article))
1131 (gnus-setup-message (if yank 'reply-yank 'reply)
1133 (gnus-summary-select-article)
1134 (dolist (article very-wide)
1135 (gnus-summary-select-article nil nil nil article)
1137 (set-buffer (gnus-copy-article-buffer))
1138 (gnus-msg-treat-broken-reply-to)
1140 (message-narrow-to-head)
1141 (setq headers (concat headers (buffer-string)))))))
1142 (set-buffer (gnus-copy-article-buffer))
1143 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1145 (message-narrow-to-head)
1149 (goto-char (point-max)))
1150 (mml-quote-region (point) (point-max))
1151 (message-reply nil wide)
1153 (gnus-inews-yank-articles yank))
1154 (gnus-summary-handle-replysign)))))
1156 (defun gnus-summary-handle-replysign ()
1157 "Check the various replysign variables and take action accordingly."
1158 (when (or gnus-message-replysign gnus-message-replyencrypt)
1159 (let (signed encrypted)
1161 (set-buffer gnus-article-buffer)
1162 (setq signed (memq 'signed gnus-article-wash-types))
1163 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1164 (cond ((and gnus-message-replyencrypt encrypted)
1165 (mml-secure-message mml-default-encrypt-method
1166 (if gnus-message-replysignencrypted
1169 ((and gnus-message-replysign signed)
1170 (mml-secure-message mml-default-sign-method 'sign))))))
1172 (defun gnus-summary-reply-with-original (n &optional wide)
1173 "Start composing a reply mail to the current message.
1174 The original article will be yanked."
1176 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1178 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1179 "Like `gnus-summary-reply' except removing reply-to field.
1180 If prefix argument YANK is non-nil, the original article is yanked
1182 If WIDE, make a wide reply.
1183 If VERY-WIDE, make a very wide reply."
1185 (list (and current-prefix-arg
1186 (gnus-summary-work-articles 1))))
1187 (let ((gnus-msg-force-broken-reply-to t))
1188 (gnus-summary-reply yank wide very-wide)))
1190 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1191 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1192 The original article will be yanked."
1194 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1196 (defun gnus-summary-wide-reply (&optional yank)
1197 "Start composing a wide reply mail to the current message.
1198 If prefix argument YANK is non-nil, the original article is yanked
1201 (list (and current-prefix-arg
1202 (gnus-summary-work-articles 1))))
1203 (gnus-summary-reply yank t))
1205 (defun gnus-summary-wide-reply-with-original (n)
1206 "Start composing a wide reply mail to the current message.
1207 The original article will be yanked."
1209 (gnus-summary-reply-with-original n t))
1211 (defun gnus-summary-very-wide-reply (&optional yank)
1212 "Start composing a very wide reply mail to the current message.
1213 If prefix argument YANK is non-nil, the original article is yanked
1216 (list (and current-prefix-arg
1217 (gnus-summary-work-articles 1))))
1218 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1220 (defun gnus-summary-very-wide-reply-with-original (n)
1221 "Start composing a very wide reply mail to the current message.
1222 The original article will be yanked."
1225 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1227 (defun gnus-summary-mail-forward (&optional arg post)
1228 "Forward the current message(s) to another user.
1229 If process marks exist, forward all marked messages;
1230 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1231 if ARG is 1, decode the message and forward directly inline;
1232 if ARG is 2, forward message as an rfc822 MIME section;
1233 if ARG is 3, decode message and forward as an rfc822 MIME section;
1234 if ARG is 4, forward message directly inline;
1235 otherwise, use flipped `message-forward-as-mime'.
1236 If POST, post instead of mail.
1237 For the `inline' alternatives, also see the variable
1238 `message-forward-ignored-headers'."
1240 (if (cdr (gnus-summary-work-articles nil))
1241 ;; Process marks are given.
1242 (gnus-uu-digest-mail-forward arg post)
1243 ;; No process marks.
1244 (let ((message-forward-as-mime message-forward-as-mime)
1245 (message-forward-show-mml message-forward-show-mml))
1249 (setq message-forward-as-mime nil
1250 message-forward-show-mml t))
1252 (setq message-forward-as-mime t
1253 message-forward-show-mml nil))
1255 (setq message-forward-as-mime t
1256 message-forward-show-mml t))
1258 (setq message-forward-as-mime nil
1259 message-forward-show-mml nil))
1261 (setq message-forward-as-mime (not message-forward-as-mime))))
1262 (let* ((gnus-article-reply (gnus-summary-article-number))
1263 (gnus-article-yanked-articles (list gnus-article-reply)))
1264 (gnus-setup-message 'forward
1265 (gnus-summary-select-article)
1266 (let ((mail-parse-charset
1267 (or (and (gnus-buffer-live-p gnus-article-buffer)
1268 (with-current-buffer gnus-article-buffer
1269 gnus-article-charset))
1270 gnus-newsgroup-charset))
1271 (mail-parse-ignored-charsets
1272 gnus-newsgroup-ignored-charsets))
1273 (set-buffer gnus-original-article-buffer)
1274 (message-forward post)))))))
1276 (defun gnus-summary-resend-message (address n)
1277 "Resend the current article to ADDRESS."
1279 (list (message-read-from-minibuffer
1280 "Resend message(s) to: "
1281 (when (and gnus-summary-resend-default-address
1282 (gnus-buffer-live-p gnus-original-article-buffer))
1283 ;; If some other article is currently selected, the
1284 ;; initial-contents is wrong. Whatever, it is just the
1285 ;; initial-contents.
1286 (with-current-buffer gnus-original-article-buffer
1287 (nnmail-fetch-field "to"))))
1288 current-prefix-arg))
1289 (let ((articles (gnus-summary-work-articles n))
1291 (while (setq article (pop articles))
1292 (gnus-summary-select-article nil nil nil article)
1294 (set-buffer gnus-original-article-buffer)
1295 (message-resend address))
1296 (gnus-summary-mark-article-as-forwarded article))))
1298 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1299 (defun gnus-summary-resend-message-edit ()
1300 "Resend an article that has already been sent.
1301 A new buffer will be created to allow the user to modify body and
1302 contents of the message, and then, everything will happen as when
1303 composing a new message."
1305 (let ((article (gnus-summary-article-number)))
1306 (gnus-setup-message 'reply-yank
1307 (gnus-summary-select-article t)
1308 (set-buffer gnus-original-article-buffer)
1309 (let ((cur (current-buffer))
1310 (to (message-fetch-field "to")))
1311 ;; Get a normal message buffer.
1312 (message-pop-to-buffer (message-buffer-name "Resend" to))
1313 (insert-buffer-substring cur)
1315 (message-narrow-to-head-1)
1316 ;; Gnus will generate a new one when sending.
1317 (message-remove-header "Message-ID")
1318 (message-remove-header message-ignored-resent-headers t)
1319 ;; Remove unwanted headers.
1320 (goto-char (point-max))
1321 (insert mail-header-separator)
1322 (goto-char (point-min))
1323 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1327 (defun gnus-summary-post-forward (&optional arg)
1328 "Forward the current article to a newsgroup.
1329 See `gnus-summary-mail-forward' for ARG."
1331 (gnus-summary-mail-forward arg t))
1333 (defvar gnus-nastygram-message
1334 "The following article was inappropriately posted to %s.\n\n"
1335 "Format string to insert in nastygrams.
1336 The current group name will be inserted at \"%s\".")
1338 (defun gnus-summary-mail-nastygram (n)
1339 "Send a nastygram to the author of the current article."
1341 (when (or gnus-expert-user
1343 "Really send a nastygram to the author of the current article? "))
1344 (let ((group gnus-newsgroup-name))
1345 (gnus-summary-reply-with-original n)
1346 (set-buffer gnus-message-buffer)
1348 (insert (format gnus-nastygram-message group))
1349 (message-send-and-exit))))
1351 (defun gnus-summary-mail-crosspost-complaint (n)
1352 "Send a complaint about crossposting to the current article(s)."
1354 (let ((articles (gnus-summary-work-articles n))
1356 (while (setq article (pop articles))
1357 (set-buffer gnus-summary-buffer)
1358 (gnus-summary-goto-subject article)
1359 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1360 newsgroups followup-to)
1361 (gnus-summary-select-article)
1362 (set-buffer gnus-original-article-buffer)
1363 (if (and (<= (length (message-tokenize-header
1365 (mail-fetch-field "newsgroups"))
1368 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1369 (not (member group (message-tokenize-header
1370 followup-to ", ")))))
1372 (gnus-message 1 "Followup-to restricted")
1373 (gnus-message 1 "Not a crossposted article"))
1374 (set-buffer gnus-summary-buffer)
1375 (gnus-summary-reply-with-original 1)
1376 (set-buffer gnus-message-buffer)
1378 (insert (format gnus-crosspost-complaint newsgroups group))
1379 (message-goto-subject)
1380 (re-search-forward " *$")
1381 (replace-match " (crosspost notification)" t t)
1382 (gnus-deactivate-mark)
1383 (when (gnus-y-or-n-p "Send this complaint? ")
1384 (message-send-and-exit)))))))
1386 (defun gnus-mail-parse-comma-list ()
1389 (skip-chars-forward " ")
1392 (skip-chars-forward "^,")
1397 (narrow-to-region beg (point))
1400 (while (search-forward "\"" nil t)
1404 (skip-chars-forward ",")
1405 (skip-chars-forward "^,"))
1406 (skip-chars-backward " ")
1407 (push (buffer-substring beg (point))
1409 (skip-chars-forward "^,")
1410 (skip-chars-forward ", "))
1413 (defun gnus-inews-add-to-address (group)
1414 (let ((to-address (mail-fetch-field "to")))
1415 (when (and to-address
1417 ;; This mail group doesn't have a `to-list', so we add one
1419 (when (gnus-y-or-n-p
1420 (format "Do you want to add this as `to-list': %s " to-address))
1421 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1423 (defun gnus-put-message ()
1424 "Put the current message in some group and return to Gnus."
1426 (let ((reply gnus-article-reply)
1427 (winconf gnus-prev-winconf)
1428 (group gnus-newsgroup-name))
1430 (not (gnus-group-read-only-p group)))
1431 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1433 (when (gnus-gethash group gnus-newsrc-hashtb)
1434 (error "No such group: %s" group))
1438 (message-narrow-to-headers)
1439 (let ((gnus-deletable-headers nil))
1440 (message-generate-headers
1441 (if (message-news-p)
1442 message-required-news-headers
1443 message-required-mail-headers)))
1444 (goto-char (point-max))
1445 (if (string-match " " group)
1446 (insert "Gcc: \"" group "\"\n")
1447 (insert "Gcc: " group "\n"))
1450 (when (and (get-buffer gnus-group-buffer)
1451 (gnus-buffer-exists-p (car-safe reply))
1453 (set-buffer (car reply))
1454 (gnus-summary-mark-article-as-replied (cdr reply)))
1456 (set-window-configuration winconf))))
1458 (defun gnus-article-mail (yank)
1459 "Send a reply to the address near point.
1460 If YANK is non-nil, include the original article."
1464 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1465 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1467 (gnus-msg-mail address)
1469 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1471 (defvar nntp-server-type)
1473 "Send a bug report to the Gnus maintainers."
1475 (unless (gnus-alive-p)
1476 (error "Gnus has been shut down"))
1477 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1478 (unless (message-mail-user-agent)
1479 (delete-other-windows)
1480 (when gnus-bug-create-help-buffer
1481 (switch-to-buffer "*Gnus Help Bug*")
1483 (insert gnus-bug-message)
1484 (goto-char (point-min)))
1485 (message-pop-to-buffer "*Gnus Bug*"))
1486 (let ((message-this-is-mail t))
1487 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1488 (when gnus-bug-create-help-buffer
1489 (push `(gnus-bug-kill-buffer) message-send-actions))
1490 (goto-char (point-min))
1491 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1493 (insert (gnus-version) "\n"
1494 (emacs-version) "\n")
1495 (when (and (boundp 'nntp-server-type)
1496 (stringp nntp-server-type))
1497 (insert nntp-server-type))
1498 (insert "\n\n\n\n\n")
1501 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1504 (setq text (buffer-string)))
1505 (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1506 (goto-char (point-min))
1507 (search-forward "Subject: " nil t)
1510 (defun gnus-bug-kill-buffer ()
1511 (when (get-buffer "*Gnus Help Bug*")
1512 (kill-buffer "*Gnus Help Bug*")))
1514 (defun gnus-summary-yank-message (buffer n)
1515 "Yank the current article into a composed message."
1517 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1518 current-prefix-arg))
1519 (gnus-summary-iterate n
1520 (let ((gnus-display-mime-function nil)
1521 (gnus-inhibit-treatment t))
1522 (gnus-summary-select-article))
1525 (message-yank-buffer gnus-article-buffer))))
1527 (defun gnus-debug ()
1528 "Attempts to go through the Gnus source file and report what variables have been changed.
1529 The source file has to be in the Emacs load path."
1531 (let ((files gnus-debug-files)
1533 file expr olist sym)
1534 (gnus-message 4 "Please wait while we snoop your variables...")
1536 ;; Go through all the files looking for non-default values for variables.
1538 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1541 (when (and (setq file (locate-library (pop files)))
1542 (file-exists-p file))
1543 (insert-file-contents file)
1544 (goto-char (point-min))
1545 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1546 (gnus-message 4 "Malformed sources in file %s" file)
1547 (narrow-to-region (point-min) (point))
1548 (goto-char (point-min))
1549 (while (setq expr (ignore-errors (read (current-buffer))))
1551 (and (or (eq (car expr) 'defvar)
1552 (eq (car expr) 'defcustom))
1553 (stringp (nth 3 expr))
1554 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1555 (or (not (boundp (nth 1 expr)))
1556 (not (equal (eval (nth 2 expr))
1557 (symbol-value (nth 1 expr)))))
1558 (push (nth 1 expr) olist)))))))
1559 (kill-buffer (current-buffer)))
1560 (when (setq olist (nreverse olist))
1561 (insert "------------------ Environment follows ------------------\n\n"))
1563 (if (boundp (car olist))
1565 (pp `(setq ,(car olist)
1566 ,(if (or (consp (setq sym (symbol-value (car olist))))
1568 (not (or (eq sym nil)
1570 (list 'quote (symbol-value (car olist)))
1571 (symbol-value (car olist))))
1573 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1574 (setq olist (cdr olist)))
1576 ;; Remove any control chars - they seem to cause trouble for some
1577 ;; mailers. (Byte-compiled output from the stuff above.)
1579 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1580 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1583 ;;; Treatment of rejected articles.
1586 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1587 "Re-mail the current message.
1588 This only makes sense if the current message is a bounce message than
1589 contains some mail you have written which has been bounced back to
1591 If FETCH, try to fetch the article that this is a reply to, if indeed
1594 (gnus-summary-select-article t)
1595 (set-buffer gnus-original-article-buffer)
1596 (gnus-setup-message 'compose-bounce
1597 (let* ((references (mail-fetch-field "references"))
1598 (parent (and references (gnus-parent-id references))))
1600 ;; If there are references, we fetch the article we answered to.
1602 (gnus-summary-refer-article parent)
1603 (gnus-summary-show-all-headers)))))
1607 (defun gnus-inews-group-method (group)
1609 ;; If the group doesn't exist, we assume
1610 ;; it's an archive group...
1611 ((and (null (gnus-get-info group))
1612 (eq (car (gnus-server-to-method gnus-message-archive-method))
1613 (car (gnus-server-to-method (gnus-group-method group)))))
1614 gnus-message-archive-method)
1616 ((gnus-info-method (gnus-get-info group))
1617 (gnus-info-method (gnus-get-info group)))
1619 (t (gnus-server-to-method (gnus-group-method group)))))
1621 ;; Do Gcc handling, which copied the message over to some group.
1622 (defun gnus-inews-do-gcc (&optional gcc)
1626 (message-narrow-to-headers)
1627 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1628 (cur (current-buffer))
1629 groups group method group-art
1630 mml-externalize-attachments)
1632 (message-remove-header "gcc")
1634 (setq groups (message-unquote-tokens
1635 (message-tokenize-header gcc " ,")))
1636 ;; Copy the article over to some group(s).
1637 (while (setq group (pop groups))
1638 (unless (gnus-check-server
1639 (setq method (gnus-inews-group-method group)))
1640 (error "Can't open server %s" (if (stringp method) method
1642 (unless (gnus-request-group group nil method)
1643 (gnus-request-create-group group method))
1644 (setq mml-externalize-attachments
1645 (if (stringp gnus-gcc-externalize-attachments)
1646 (string-match gnus-gcc-externalize-attachments group)
1647 gnus-gcc-externalize-attachments))
1649 (nnheader-set-temp-buffer " *acc*")
1650 (insert-buffer-substring cur)
1651 (message-encode-message-body)
1653 (message-narrow-to-headers)
1654 (let* ((mail-parse-charset message-default-charset)
1655 (newsgroups-field (save-restriction
1656 (message-narrow-to-headers-or-head)
1657 (message-fetch-field "Newsgroups")))
1658 (followup-field (save-restriction
1659 (message-narrow-to-headers-or-head)
1660 (message-fetch-field "Followup-To")))
1661 ;; BUG: We really need to get the charset for
1662 ;; each name in the Newsgroups and Followup-To
1663 ;; lines to allow crossposting between group
1664 ;; namess with incompatible character sets.
1665 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1666 (group-field-charset
1667 (gnus-group-name-charset
1668 method (or newsgroups-field "")))
1669 (followup-field-charset
1670 (gnus-group-name-charset
1671 method (or followup-field "")))
1672 (rfc2047-header-encoding-alist
1674 (when group-field-charset
1675 (list (cons "Newsgroups" group-field-charset)))
1676 (when followup-field-charset
1677 (list (cons "Followup-To" followup-field-charset)))
1678 rfc2047-header-encoding-alist)))
1679 (mail-encode-encoded-word-buffer)))
1680 (goto-char (point-min))
1681 (when (re-search-forward
1682 (concat "^" (regexp-quote mail-header-separator) "$")
1684 (replace-match "" t t ))
1685 (unless (setq group-art
1686 (gnus-request-accept-article group method t t))
1687 (gnus-message 1 "Couldn't store article in group %s: %s"
1688 group (gnus-status-message method))
1690 (when (and group-art
1691 ;; FIXME: Should gcc-mark-as-read work when
1692 ;; Gnus is not running?
1694 (or gnus-gcc-mark-as-read
1695 gnus-inews-mark-gcc-as-read))
1696 (gnus-group-mark-article-read group (cdr group-art)))
1697 (kill-buffer (current-buffer)))))))))
1699 (defun gnus-inews-insert-gcc ()
1700 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1703 (message-narrow-to-headers)
1704 (let* ((group gnus-outgoing-message-group)
1706 ((gnus-functionp group)
1708 ((or (stringp group) (list group))
1713 (if (string-match " " gcc)
1714 (concat "\"" gcc "\"")
1716 (mapconcat (lambda (group)
1717 (if (string-match " " group)
1718 (concat "\"" group "\"")
1723 (defun gnus-inews-insert-archive-gcc (&optional group)
1724 "Insert the Gcc to say where the article is to be archived."
1725 (let* ((var gnus-message-archive-group)
1726 (group (or group gnus-newsgroup-name ""))
1728 (and gnus-newsgroup-name
1729 (not (equal gnus-newsgroup-name ""))
1730 (gnus-group-find-parameter
1731 gnus-newsgroup-name 'gcc-self)))
1735 ((null gnus-message-archive-method)
1739 ;; Just a single group.
1742 ;; We don't want this.
1744 ((and (listp var) (stringp (car var)))
1745 ;; A list of groups.
1747 ((gnus-functionp var)
1749 (funcall var group))
1751 ;; An alist of regexps/functions/forms.
1756 ((stringp (caar var))
1758 (when (string-match (caar var) group)
1760 ((gnus-functionp (car var))
1762 (funcall (car var) group))
1764 (eval (car var)))))))
1765 (setq var (cdr var)))
1768 (when (or groups gcc-self-val)
1769 (when (stringp groups)
1770 (setq groups (list groups)))
1773 (message-narrow-to-headers)
1774 (goto-char (point-max))
1777 ;; Use the `gcc-self' param value instead.
1780 (if (stringp gcc-self-val)
1781 (if (string-match " " gcc-self-val)
1782 (concat "\"" gcc-self-val "\"")
1784 (if (string-match " " group)
1785 (concat "\"" group "\"")
1787 (if (not (eq gcc-self-val 'none))
1789 (gnus-delete-line)))
1790 ;; Use the list of groups.
1791 (while (setq name (pop groups))
1792 (let ((str (if (string-match ":" name)
1794 (gnus-group-prefixed-name
1795 name gnus-message-archive-method))))
1796 (insert (if (string-match " " str)
1797 (concat "\"" str "\"")
1803 (defun gnus-mailing-list-followup-to ()
1804 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1805 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1806 (list-post (gnus-fetch-original-field "list-post")))
1807 (when (and list-post
1808 (string-match "mailto:\\([^>]+\\)" list-post))
1809 (setq list-post (match-string 1 list-post)))
1815 (defun gnus-configure-posting-styles (&optional group-name)
1816 "Configure posting styles according to `gnus-posting-styles'."
1817 (unless gnus-inhibit-posting-styles
1818 (let ((group (or group-name gnus-newsgroup-name ""))
1819 (styles gnus-posting-styles)
1820 style match variable attribute value v results
1821 filep name address element)
1822 ;; If the group has a posting-style parameter, add it at the end with a
1823 ;; regexp matching everything, to be sure it takes precedence over all
1825 (when gnus-newsgroup-name
1826 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1828 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1829 ;; Go through all styles and look for matches.
1830 (dolist (style styles)
1831 (setq match (pop style))
1832 (goto-char (point-min))
1835 ;; Regexp string match on the group name.
1836 (string-match match group))
1838 ;; Obsolete format of header match.
1839 (and (gnus-buffer-live-p gnus-article-copy)
1840 (with-current-buffer gnus-article-copy
1841 (let ((header (message-fetch-field (pop style))))
1843 (string-match (pop style) header))))))
1844 ((or (symbolp match)
1845 (gnus-functionp match))
1847 ((gnus-functionp match)
1848 ;; Function to be called.
1851 ;; Variable to be checked.
1852 (symbol-value match))))
1855 ((eq (car match) 'header)
1856 ;; New format of header match.
1857 (and (gnus-buffer-live-p gnus-article-copy)
1858 (with-current-buffer gnus-article-copy
1859 (let ((header (message-fetch-field (nth 1 match))))
1861 (string-match (nth 2 match) header))))))
1863 ;; This is a form to be evaled.
1865 ;; We have a match, so we set the variables.
1866 (dolist (attribute style)
1867 (setq element (pop attribute)
1872 ((eq (car attribute) :file)
1875 ((eq (car attribute) :value)
1879 ;; We get the value.
1884 ((or (symbolp value)
1885 (gnus-functionp value))
1886 (cond ((gnus-functionp value)
1889 (symbol-value value))))
1892 ;; Translate obsolescent value.
1894 ((eq element 'signature-file)
1895 (setq element 'signature
1897 ((eq element 'x-face-file)
1898 (setq element 'x-face
1900 ;; Get the contents of file elems.
1902 (setq v (with-temp-buffer
1903 (insert-file-contents v)
1904 (goto-char (point-max))
1908 (setq results (delq (assoc element results) results))
1909 (push (cons element v) results))))
1910 ;; Now we have all the styles, so we insert them.
1911 (setq name (assq 'name results)
1912 address (assq 'address results))
1913 (setq results (delq name (delq address results)))
1914 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1915 (make-local-hook 'message-setup-hook)
1916 (setq results (sort results (lambda (x y)
1917 (string-lessp (car x) (car y)))))
1918 (dolist (result results)
1919 (add-hook 'message-setup-hook
1921 ((eq 'eval (car result))
1923 ((eq 'body (car result))
1927 (insert ,(cdr result)))))
1928 ((eq 'signature (car result))
1929 (set (make-local-variable 'message-signature) nil)
1930 (set (make-local-variable 'message-signature-file) nil)
1931 (if (not (cdr result))
1935 (let ((message-signature ,(cdr result)))
1936 (when message-signature
1937 (message-insert-signature)))))))
1940 (if (symbolp (car result))
1941 (capitalize (symbol-name (car result)))
1945 (message-remove-header ,header)
1946 (let ((value ,(cdr result)))
1949 (insert ,header ": " value)
1951 (insert "\n")))))))))
1953 (when (or name address)
1954 (add-hook 'message-setup-hook
1956 (set (make-local-variable 'user-mail-address)
1957 ,(or (cdr address) user-mail-address))
1958 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1960 ,(or (cdr address) user-mail-address)))
1962 (message-remove-header "From")
1964 (insert "From: " (message-make-from) "\n"))))
1967 ;;; Allow redefinition of functions.
1973 ;;; gnus-msg.el ends here