1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
7 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
31 (eval-when-compile (require 'cl))
39 (defcustom gnus-post-method 'current
40 "*Preferred method for posting USENET news.
42 If this variable is `current' (which is the default), Gnus will use
43 the \"current\" select method when posting. If it is `native', Gnus
44 will use the native select method when posting.
46 This method will not be used in mail groups and the like, only in
49 If not `native' nor `current', the value must be a valid method as discussed
50 in the documentation of `gnus-select-method'. It can also be a list of
51 methods. If that is the case, the user will be queried for what select
52 method to use when posting."
53 :group 'gnus-group-foreign
54 :link '(custom-manual "(gnus)Posting Server")
55 :type `(choice (const native)
57 (sexp :tag "Methods" ,gnus-select-method)))
59 (defcustom gnus-outgoing-message-group nil
60 "*All outgoing messages will be put in this group.
61 If you want to store all your outgoing mail and articles in the group
62 \"nnml:archive\", you set this variable to that value. This variable
63 can also be a list of group names.
65 If you want to have greater control over what group to put each
66 message in, you can set this variable to a function that checks the
67 current newsgroup name and then returns a suitable group name (or list
70 :type '(choice (const nil)
73 (repeat :tag "List of groups" (string :tag "Group"))))
75 (defcustom gnus-mailing-list-groups nil
76 "*If non-nil a regexp matching groups that are really mailing lists.
77 This is useful when you're reading a mailing list that has been
78 gatewayed to a newsgroup, and you want to followup to an article in
81 :type '(choice (regexp)
84 (defcustom gnus-add-to-list nil
85 "*If non-nil, add a `to-list' parameter automatically."
89 (defcustom gnus-crosspost-complaint
92 You posted the article below with the following Newsgroups header:
96 The %s group, at least, was an inappropriate recipient
97 of this message. Please trim your Newsgroups header to exclude this
98 group before posting in the future.
103 "Format string to be inserted when complaining about crossposts.
104 The first %s will be replaced by the Newsgroups header;
105 the second with the current group name."
109 (defcustom gnus-message-setup-hook nil
110 "Hook run after setting up a message buffer."
114 (defcustom gnus-bug-create-help-buffer t
115 "*Should we create the *Gnus Help Bug* buffer?"
119 (defcustom gnus-posting-styles nil
120 "*Alist of styles to use when posting.
121 See Info node `(gnus)Posting Styles'."
123 :link '(custom-manual "(gnus)Posting Styles")
124 :type '(repeat (cons (choice (regexp)
127 (string :tag "Header")
128 (regexp :tag "Regexp"))
132 (choice (const signature)
133 (const signature-file)
140 (string :tag "Header"))
146 (defcustom gnus-gcc-mark-as-read nil
147 "If non-nil, automatically mark Gcc articles as read."
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 encrypted messages to also be signed."
258 (defcustom gnus-confirm-mail-reply-to-news (and gnus-novice-user
259 (not gnus-expert-user))
260 "If non-nil, Gnus requests confirmation when replying to news.
261 This is done because new users often reply by mistake when reading
263 This can also be a function receiving the group name as the only
264 parameter which should return non-nil iff a confirmation is needed, or
265 a regexp, in which case a confirmation is asked for iff the group name
269 :type '(choice (const :tag "No" nil)
271 (regexp :tag "Iff group matches regexp")
272 (function :tag "Iff function evaluates to non-nil")))
274 (defcustom gnus-confirm-treat-mail-like-news
276 "If non-nil, Gnus will treat mail like news with regard to confirmation
277 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
278 for fine-tuning this.
279 If nil, Gnus will never ask for confirmation if replying to mail."
284 (defcustom gnus-summary-resend-default-address t
285 "If non-nil, Gnus tries to suggest a default address to resend to.
286 If nil, the address field will always be empty after invoking
287 `gnus-summary-resend-message'."
292 (defcustom gnus-message-highlight-citation
293 t ;; gnus-treat-highlight-citation ;; gnus-cite dependency
294 "Enable highlighting of different citation levels in message-mode."
295 :version "23.0" ;; No Gnus
300 (autoload 'gnus-message-citation-mode "gnus-cite" nil t)
302 ;;; Internal variables.
304 (defvar gnus-inhibit-posting-styles nil
305 "Inhibit the use of posting styles.")
307 (defvar gnus-article-yanked-articles nil)
308 (defvar gnus-message-buffer "*Mail Gnus*")
309 (defvar gnus-article-copy nil)
310 (defvar gnus-check-before-posting nil)
311 (defvar gnus-last-posting-server nil)
312 (defvar gnus-message-group-art nil)
314 (defvar gnus-msg-force-broken-reply-to nil)
316 (defconst gnus-bug-message
317 "Sending a bug report to the Gnus Towers.
318 ========================================
320 The buffer below is a mail buffer. When you press `C-c C-c', it will
321 be sent to the Gnus Bug Exterminators.
323 The thing near the bottom of the buffer is how the environment
324 settings will be included in the mail. Please do not delete that.
325 They will tell the Bug People what your environment is, so that it
326 will be easier to locate the bugs.
328 If you have found a bug that makes Emacs go \"beep\", set
329 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
330 and include the backtrace in your bug report.
332 Please describe the bug in annoying, painstaking detail.
334 Thank you for your help in stamping out bugs.
338 (autoload 'gnus-uu-post-news "gnus-uu" nil t))
342 ;;; Gnus Posting Functions
345 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
346 "p" gnus-summary-post-news
347 "i" gnus-summary-news-other-window
348 "f" gnus-summary-followup
349 "F" gnus-summary-followup-with-original
350 "c" gnus-summary-cancel-article
351 "s" gnus-summary-supersede-article
352 "r" gnus-summary-reply
353 "y" gnus-summary-yank-message
354 "R" gnus-summary-reply-with-original
355 "w" gnus-summary-wide-reply
356 "W" gnus-summary-wide-reply-with-original
357 "v" gnus-summary-very-wide-reply
358 "V" gnus-summary-very-wide-reply-with-original
359 "n" gnus-summary-followup-to-mail
360 "N" gnus-summary-followup-to-mail-with-original
361 "m" gnus-summary-mail-other-window
362 "u" gnus-uu-post-news
363 "\M-c" gnus-summary-mail-crosspost-complaint
364 "Br" gnus-summary-reply-broken-reply-to
365 "BR" gnus-summary-reply-broken-reply-to-with-original
366 "om" gnus-summary-mail-forward
367 "op" gnus-summary-post-forward
368 "Om" gnus-uu-digest-mail-forward
369 "Op" gnus-uu-digest-post-forward)
371 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
372 "b" gnus-summary-resend-bounced-mail
373 ;; "c" gnus-summary-send-draft
374 "r" gnus-summary-resend-message
375 "e" gnus-summary-resend-message-edit)
377 ;;; Internal functions.
379 (defun gnus-inews-make-draft (articles)
381 (gnus-inews-make-draft-meta-information
382 ,gnus-newsgroup-name ',articles)))
384 (defvar gnus-article-reply nil)
385 (defmacro gnus-setup-message (config &rest forms)
386 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
387 (buffer (make-symbol "gnus-setup-message-buffer"))
388 (article (make-symbol "gnus-setup-message-article"))
389 (yanked (make-symbol "gnus-setup-yanked-articles"))
390 (group (make-symbol "gnus-setup-message-group")))
391 `(let ((,winconf (current-window-configuration))
392 (,buffer (buffer-name (current-buffer)))
393 (,article gnus-article-reply)
394 (,yanked gnus-article-yanked-articles)
395 (,group gnus-newsgroup-name)
396 (message-header-setup-hook
397 (copy-sequence message-header-setup-hook))
398 (mbl mml-buffer-list)
399 (message-mode-hook (copy-sequence message-mode-hook)))
400 (setq mml-buffer-list nil)
401 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
402 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
403 ;; message-newsreader and message-mailer were formerly set in
404 ;; gnus-inews-add-send-actions, but this is too late when
405 ;; message-generate-headers-first is used. --ansel
406 (add-hook 'message-mode-hook
408 (setq message-newsreader
409 (setq message-mailer (gnus-extended-version)))))
410 ;; #### FIXME: for a reason that I did not manage to identify yet,
411 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
412 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
413 ;; After evaluation of @forms below, it gets the value we actually want
414 ;; to override, and the posting styles are used. For that reason, I've
415 ;; added an optional argument to `gnus-configure-posting-styles' to
416 ;; make sure that the correct value for the group name is used. -- drv
417 (add-hook 'message-mode-hook
418 (if (memq ,config '(reply-yank reply))
420 (gnus-configure-posting-styles ,group))
422 ;; There may be an old " *gnus article copy*" buffer.
423 (let (gnus-article-copy)
424 (gnus-configure-posting-styles ,group)))))
425 (gnus-pull ',(intern gnus-draft-meta-information-header)
426 message-required-headers)
428 (not (string= ,group "")))
430 (intern gnus-draft-meta-information-header)
431 (gnus-inews-make-draft (or ,yanked ,article)))
432 message-required-headers))
436 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
438 (setq gnus-message-buffer (current-buffer))
439 (set (make-local-variable 'gnus-message-group-art)
440 (cons ,group ,article))
441 (set (make-local-variable 'gnus-newsgroup-name) ,group)
442 ;; Enable highlighting of different citation levels
443 (when gnus-message-highlight-citation
444 (gnus-message-citation-mode 1))
445 (gnus-run-hooks 'gnus-message-setup-hook)
446 (if (eq major-mode 'message-mode)
447 (let ((mbl1 mml-buffer-list))
448 (setq mml-buffer-list mbl) ;; Global value
449 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
450 (gnus-make-local-hook 'kill-buffer-hook)
451 (gnus-make-local-hook 'change-major-mode-hook)
452 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
453 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
454 (mml-destroy-buffers)
455 (setq mml-buffer-list mbl)))
456 (message-hide-headers)
458 (gnus-configure-windows ,config t)
459 (run-hooks 'post-command-hook)
460 (set-buffer-modified-p nil))))
462 (defun gnus-inews-make-draft-meta-information (group articles)
463 (when (numberp articles)
464 (setq articles (list articles)))
465 (concat "(\"" group "\""
479 (defun gnus-msg-mail (&optional to subject other-headers continue
480 switch-action yank-action send-actions)
481 "Start editing a mail message to be sent.
482 Like `message-mail', but with Gnus paraphernalia, particularly the
483 Gcc: header for archiving purposes."
485 (let ((buf (current-buffer))
487 (gnus-setup-message 'message
488 (message-mail to subject other-headers continue
489 nil yank-action send-actions))
491 (setq mail-buf (current-buffer))
492 (switch-to-buffer buf)
493 (apply switch-action mail-buf nil)))
494 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
498 (defun gnus-button-mailto (address)
500 (set-buffer (gnus-copy-article-buffer))
501 (gnus-setup-message 'message
502 (message-reply address)))
505 (defun gnus-button-reply (&optional to-address wide)
506 "Like `message-reply'."
508 (gnus-setup-message 'message
509 (message-reply to-address wide)))
512 (define-mail-user-agent 'gnus-user-agent
513 'gnus-msg-mail 'message-send-and-exit
514 'message-kill-buffer 'message-send-hook)
516 (defun gnus-setup-posting-charset (group)
517 (let ((alist gnus-group-posting-charset-alist)
518 (group (or group ""))
522 (while (setq elem (pop alist))
523 (when (or (and (stringp (car elem))
524 (string-match (car elem) group))
525 (and (functionp (car elem))
526 (funcall (car elem) group))
527 (and (symbolp (car elem))
528 (symbol-value (car elem))))
529 (throw 'found (cons (cadr elem) (caddr elem)))))))))
531 (defun gnus-inews-add-send-actions (winconf buffer article
532 &optional config yanked)
533 (gnus-make-local-hook 'message-sent-hook)
534 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
535 'gnus-inews-do-gcc) nil t)
537 (gnus-make-local-hook 'message-header-hook)
538 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
539 (setq message-post-method
540 `(lambda (&optional arg)
541 (gnus-post-method arg ,gnus-newsgroup-name)))
543 `(when (gnus-buffer-exists-p ,buffer)
544 (set-window-configuration ,winconf))
545 'exit 'postpone 'kill)
546 (let ((to-be-marked (cond
549 (lambda (x) (if (listp x) (car x) x)) yanked))
550 (article (if (listp article) article (list article)))
553 `(when (gnus-buffer-exists-p ,buffer)
557 (if (eq config 'forward)
558 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
559 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
562 (put 'gnus-setup-message 'lisp-indent-function 1)
563 (put 'gnus-setup-message 'edebug-form-spec '(form body))
565 ;;; Post news commands of Gnus group mode and summary mode
567 (defun gnus-group-mail (&optional arg)
568 "Start composing a mail.
569 If ARG, use the group under the point to find a posting style.
570 If ARG is 1, prompt for a group name to find the posting style."
572 ;; We can't `let' gnus-newsgroup-name here, since that leads
573 ;; to local variables leaking.
574 (let ((group gnus-newsgroup-name)
575 ;; make sure last viewed article doesn't affect posting styles:
577 (buffer (current-buffer)))
580 (setq gnus-newsgroup-name
582 (if (= 1 (prefix-numeric-value arg))
583 (completing-read "Use posting style of group: "
584 gnus-active-hashtb nil
585 (gnus-read-active-file-p))
586 (gnus-group-group-name))
588 ;; #### see comment in gnus-setup-message -- drv
589 (gnus-setup-message 'message (message-mail)))
592 (setq gnus-newsgroup-name group)))))
594 (defun gnus-group-news (&optional arg)
595 "Start composing a news.
596 If ARG, post to group under point.
597 If ARG is 1, prompt for group name to post to.
599 This function prepares a news even when using mail groups. This is useful
600 for posting messages to mail groups without actually sending them over the
601 network. The corresponding back end must have a 'request-post method."
603 ;; We can't `let' gnus-newsgroup-name here, since that leads
604 ;; to local variables leaking.
605 (let ((group gnus-newsgroup-name)
606 ;; make sure last viewed article doesn't affect posting styles:
608 (buffer (current-buffer)))
611 (setq gnus-newsgroup-name
613 (if (= 1 (prefix-numeric-value arg))
614 (completing-read "Use group: "
615 gnus-active-hashtb nil
616 (gnus-read-active-file-p))
617 (gnus-group-group-name))
619 ;; #### see comment in gnus-setup-message -- drv
620 (gnus-setup-message 'message
621 (message-news (gnus-group-real-name gnus-newsgroup-name))))
624 (setq gnus-newsgroup-name group)))))
626 (defun gnus-group-post-news (&optional arg)
627 "Start composing a message (a news by default).
628 If ARG, post to group under point. If ARG is 1, prompt for group name.
629 Depending on the selected group, the message might be either a mail or
632 ;; Bind this variable here to make message mode hooks work ok.
633 (let ((gnus-newsgroup-name
635 (if (= 1 (prefix-numeric-value arg))
636 (completing-read "Newsgroup: " gnus-active-hashtb nil
637 (gnus-read-active-file-p))
638 (gnus-group-group-name))
640 ;; make sure last viewed article doesn't affect posting styles:
642 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
643 (string= gnus-newsgroup-name ""))))
645 (defun gnus-summary-mail-other-window (&optional arg)
646 "Start composing a mail in another window.
647 Use the posting of the current group by default.
648 If ARG, don't do that. If ARG is 1, prompt for group name to find the
651 ;; We can't `let' gnus-newsgroup-name here, since that leads
652 ;; to local variables leaking.
653 (let ((group gnus-newsgroup-name)
654 ;; make sure last viewed article doesn't affect posting styles:
656 (buffer (current-buffer)))
659 (setq gnus-newsgroup-name
661 (if (= 1 (prefix-numeric-value arg))
662 (completing-read "Use group: "
663 gnus-active-hashtb nil
664 (gnus-read-active-file-p))
666 gnus-newsgroup-name))
667 ;; #### see comment in gnus-setup-message -- drv
668 (gnus-setup-message 'message (message-mail)))
671 (setq gnus-newsgroup-name group)))))
673 (defun gnus-summary-news-other-window (&optional arg)
674 "Start composing a news in another window.
675 Post to the current group by default.
676 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
678 This function prepares a news even when using mail groups. This is useful
679 for posting messages to mail groups without actually sending them over the
680 network. The corresponding back end must have a 'request-post method."
682 ;; We can't `let' gnus-newsgroup-name here, since that leads
683 ;; to local variables leaking.
684 (let ((group gnus-newsgroup-name)
685 ;; make sure last viewed article doesn't affect posting styles:
687 (buffer (current-buffer)))
690 (setq gnus-newsgroup-name
692 (if (= 1 (prefix-numeric-value arg))
693 (completing-read "Use group: "
694 gnus-active-hashtb nil
695 (gnus-read-active-file-p))
697 gnus-newsgroup-name))
698 ;; #### see comment in gnus-setup-message -- drv
699 (gnus-setup-message 'message
701 (message-news (gnus-group-real-name gnus-newsgroup-name))
702 (set (make-local-variable 'gnus-discouraged-post-methods)
704 (car (gnus-find-method-for-group gnus-newsgroup-name))
705 gnus-discouraged-post-methods)))))
708 (setq gnus-newsgroup-name group)))))
710 (defun gnus-summary-post-news (&optional arg)
711 "Start composing a message. Post to the current group by default.
712 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
713 Depending on the selected group, the message might be either a mail or
716 ;; Bind this variable here to make message mode hooks work ok.
717 (let ((gnus-newsgroup-name
719 (if (= 1 (prefix-numeric-value arg))
720 (completing-read "Newsgroup: " gnus-active-hashtb nil
721 (gnus-read-active-file-p))
723 gnus-newsgroup-name))
724 ;; make sure last viewed article doesn't affect posting styles:
726 (gnus-post-news 'post gnus-newsgroup-name)))
729 (defun gnus-summary-followup (yank &optional force-news)
730 "Compose a followup to an article.
731 If prefix argument YANK is non-nil, the original article is yanked
733 YANK is a list of elements, where the car of each element is the
734 article number, and the cdr is the string to be yanked."
736 (list (and current-prefix-arg
737 (gnus-summary-work-articles 1))))
739 (gnus-summary-goto-subject
740 (if (listp (car yank))
743 (save-window-excursion
744 (gnus-summary-select-article))
745 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
746 (gnus-newsgroup-name gnus-newsgroup-name))
748 (gnus-post-news nil gnus-newsgroup-name
749 headers gnus-article-buffer
751 (gnus-summary-handle-replysign)))
753 (defun gnus-summary-followup-with-original (n &optional force-news)
754 "Compose a followup to an article and include the original article.
755 The text in the region will be yanked. If the region isn't
756 active, the entire article will be yanked."
758 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
760 (defun gnus-summary-followup-to-mail (&optional arg)
761 "Followup to the current mail message via news."
763 (list (and current-prefix-arg
764 (gnus-summary-work-articles 1))))
765 (gnus-summary-followup arg t))
767 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
768 "Followup to the current mail message via news."
770 (gnus-summary-followup (gnus-summary-work-articles arg) t))
772 (defun gnus-inews-yank-articles (articles)
773 (let (beg article yank-string)
775 (while (setq article (pop articles))
776 (when (listp article)
777 (setq yank-string (nth 1 article)
778 article (nth 0 article)))
779 (save-window-excursion
780 (set-buffer gnus-summary-buffer)
781 (gnus-summary-select-article nil nil nil article)
782 (gnus-summary-remove-process-mark article))
783 (gnus-copy-article-buffer nil yank-string)
784 (let ((message-reply-buffer gnus-article-copy)
785 (message-reply-headers
786 ;; The headers are decoded.
787 (with-current-buffer gnus-article-copy
789 (nnheader-narrow-to-headers)
790 (nnheader-parse-naked-head)))))
791 (message-yank-original)
792 (message-exchange-point-and-mark)
793 (setq beg (or beg (mark t))))
799 (defun gnus-summary-cancel-article (&optional n symp)
800 "Cancel an article you posted.
801 Uses the process-prefix convention. If given the symbolic
802 prefix `a', cancel using the standard posting method; if not
803 post using the current select method."
804 (interactive (gnus-interactive "P\ny"))
805 (let ((message-post-method
807 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
808 (dolist (article (gnus-summary-work-articles n))
809 (when (gnus-summary-select-article t nil nil article)
810 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
811 (message-cancel-news))
812 (gnus-summary-mark-as-read article gnus-canceled-mark)
813 (gnus-cache-remove-article 1))
814 (gnus-article-hide-headers-if-wanted))
815 (gnus-summary-remove-process-mark article))))
817 (defun gnus-summary-supersede-article ()
818 "Compose an article that will supersede a previous article.
819 This is done simply by taking the old article and adding a Supersedes
820 header line with the old Message-ID."
822 (let ((article (gnus-summary-article-number)))
823 (gnus-setup-message 'reply-yank
824 (gnus-summary-select-article t)
825 (set-buffer gnus-original-article-buffer)
829 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
831 (set-buffer ,gnus-summary-buffer)
832 (gnus-cache-possibly-remove-article ,article nil nil nil t)
833 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
834 message-send-actions))))
838 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
839 ;; make a copy of the article buffer with all text properties removed
840 ;; this copy is in the buffer gnus-article-copy.
841 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
842 ;; this buffer should be passed to all mail/news reply/post routines.
843 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
845 (set-buffer gnus-article-copy)
846 (mm-enable-multibyte))
847 (let ((article-buffer (or article-buffer gnus-article-buffer))
849 (if (not (and (get-buffer article-buffer)
850 (gnus-buffer-exists-p article-buffer)))
851 (error "Can't find any article buffer")
853 (set-buffer article-buffer)
854 (let ((gnus-newsgroup-charset (or gnus-article-charset
855 gnus-newsgroup-charset))
856 (gnus-newsgroup-ignored-charsets
857 (or gnus-article-ignored-charsets
858 gnus-newsgroup-ignored-charsets)))
860 ;; Copy over the (displayed) article buffer, delete
861 ;; hidden text and remove text properties.
863 (copy-to-buffer gnus-article-copy (point-min) (point-max))
864 (set-buffer gnus-article-copy)
867 (delete-region (point) (point-max))
868 (insert yank-string))
869 (gnus-article-delete-text-of-type 'annotation)
870 (gnus-article-delete-text-of-type 'multipart)
871 (gnus-remove-text-with-property 'gnus-prev)
872 (gnus-remove-text-with-property 'gnus-next)
873 (gnus-remove-text-with-property 'gnus-decoration)
876 (buffer-substring-no-properties (point-min) (point-max))
878 ;; Find the original headers.
879 (set-buffer gnus-original-article-buffer)
880 (goto-char (point-min))
881 (while (looking-at message-unix-mail-delimiter)
883 (let ((mail-header-separator ""))
885 end (or (message-goto-body)
886 ;; There may be just a header.
888 ;; Delete the headers from the displayed articles.
889 (set-buffer gnus-article-copy)
890 (let ((mail-header-separator ""))
891 (delete-region (goto-char (point-min))
892 (or (message-goto-body) (point-max))))
893 ;; Insert the original article headers.
894 (insert-buffer-substring gnus-original-article-buffer beg end)
896 (let ((gnus-article-decode-hook
897 (delq 'article-decode-charset
898 (copy-sequence gnus-article-decode-hook)))
899 (rfc2047-quote-decoded-words-containing-tspecials t))
900 (run-hooks 'gnus-article-decode-hook)))))
903 (defun gnus-post-news (post &optional group header article-buffer yank subject
906 (gnus-copy-article-buffer))
907 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
908 (gnus-article-yanked-articles yank)
909 (add-to-list gnus-add-to-list))
910 (gnus-setup-message (cond (yank 'reply-yank)
911 (article-buffer 'reply)
913 (let* ((group (or group gnus-newsgroup-name))
914 (charset (gnus-group-name-charset nil group))
916 to-address to-group mailing-list to-list
919 (setq to-address (gnus-parameter-to-address group)
920 to-group (gnus-group-find-parameter group 'to-group)
921 to-list (gnus-parameter-to-list group)
922 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
923 mailing-list (when gnus-mailing-list-groups
924 (string-match gnus-mailing-list-groups group))
925 group (gnus-group-name-decode (gnus-group-real-name group)
927 (if (or (and to-group
928 (gnus-news-group-p to-group))
931 (and (gnus-news-group-p
932 (or pgroup gnus-newsgroup-name)
933 (or header gnus-current-article))
941 (and (not (gnus-virtual-group-p pgroup)) group)))
942 (set-buffer gnus-article-copy)
943 (gnus-msg-treat-broken-reply-to)
944 (message-followup (if (or newsgroup-p force-news)
945 (if (save-restriction
946 (article-narrow-to-head)
947 (message-fetch-field "newsgroups"))
954 (message-mail (or to-address to-list))
955 ;; Arrange for mail groups that have no `to-address' to
956 ;; get that when the user sends off the mail.
957 (when (and (not to-list)
960 (push (list 'gnus-inews-add-to-address pgroup)
961 message-send-actions)))
962 (set-buffer gnus-article-copy)
963 (gnus-msg-treat-broken-reply-to)
964 (message-wide-reply to-address)))
966 (gnus-inews-yank-articles yank))))))
968 (defun gnus-msg-treat-broken-reply-to (&optional force)
969 "Remove the Reply-to header if broken-reply-to."
971 (gnus-group-find-parameter
972 gnus-newsgroup-name 'broken-reply-to))
974 (message-narrow-to-head)
975 (message-remove-header "reply-to"))))
977 (defun gnus-post-method (arg group &optional silent)
978 "Return the posting method based on GROUP and ARG.
979 If SILENT, don't prompt the user."
980 (let ((gnus-post-method (or (gnus-parameter-post-method group)
982 (group-method (gnus-find-method-for-group group)))
984 ;; If the group-method is nil (which shouldn't happen) we use
985 ;; the default method.
987 (or (and (listp gnus-post-method) ;If not current/native/nil
988 (not (listp (car gnus-post-method))) ; and not a list of methods
989 gnus-post-method) ;then use it.
991 message-post-method))
992 ;; We want the inverse of the default
993 ((and arg (not (eq arg 0)))
994 (if (eq gnus-post-method 'current)
997 ;; We query the user for a post method.
999 (and (listp gnus-post-method)
1000 (listp (car gnus-post-method))))
1002 ;; Collect all methods we know about.
1004 (when (listp gnus-post-method)
1005 (if (listp (car gnus-post-method))
1007 (list gnus-post-method)))
1008 gnus-secondary-select-methods
1009 (mapcar 'cdr gnus-server-alist)
1010 (mapcar 'car gnus-opened-servers)
1011 (list gnus-select-method)
1012 (list group-method)))
1013 method-alist post-methods method)
1014 ;; Weed out all mail methods.
1016 (setq method (gnus-server-get-method "" (pop methods)))
1017 (when (and (or (gnus-method-option-p method 'post)
1018 (gnus-method-option-p method 'post-mail))
1019 (not (member method post-methods)))
1020 (push method post-methods)))
1021 ;; Create a name-method alist.
1025 (if (equal (cadr m) "")
1026 (list (symbol-name (car m)) m)
1027 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1032 (setq gnus-last-posting-server
1034 gnus-last-posting-server)
1035 ;; Just use the last value.
1036 gnus-last-posting-server
1038 "Posting method: " method-alist nil t
1039 (cons (or gnus-last-posting-server "") 0))))
1041 ;; Override normal method.
1042 ((and (eq gnus-post-method 'current)
1043 (not (memq (car group-method) gnus-discouraged-post-methods))
1044 (gnus-get-function group-method 'request-post t))
1047 ;; Use gnus-post-method.
1048 ((listp gnus-post-method) ;A method...
1049 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1051 ;; Use the normal select method (nil or native).
1052 (t gnus-select-method))))
1056 (defun gnus-extended-version ()
1057 "Stringified Gnus version and Emacs version.
1058 See the variable `gnus-user-agent'."
1060 (if (stringp gnus-user-agent)
1062 ;; `gnus-user-agent' is a list:
1063 (let* ((float-output-format nil)
1065 (when (memq 'gnus gnus-user-agent)
1067 (prin1-to-string (gnus-continuum-version gnus-version) t)
1068 " (" gnus-version ")")))
1069 (emacs-v (gnus-emacs-version)))
1070 (concat gnus-v (when (and gnus-v emacs-v) " ")
1075 ;;; Gnus Mail Functions
1078 ;;; Mail reply commands of Gnus summary mode
1080 (defun gnus-summary-reply (&optional yank wide very-wide)
1081 "Start composing a mail reply to the current message.
1082 If prefix argument YANK is non-nil, the original article is yanked
1084 If WIDE, make a wide reply.
1085 If VERY-WIDE, make a very wide reply."
1087 (list (and current-prefix-arg
1088 (gnus-summary-work-articles 1))))
1089 ;; Allow user to require confirmation before replying by mail to the
1090 ;; author of a news article (or mail message).
1092 (not (or (gnus-news-group-p gnus-newsgroup-name)
1093 gnus-confirm-treat-mail-like-news))
1094 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1095 (string-match gnus-confirm-mail-reply-to-news
1096 gnus-newsgroup-name))
1097 ((functionp gnus-confirm-mail-reply-to-news)
1098 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1099 (t gnus-confirm-mail-reply-to-news)))
1100 (y-or-n-p "Really reply by mail to article author? "))
1102 (if (listp (car yank))
1105 (gnus-article-reply (or article (gnus-summary-article-number)))
1106 (gnus-article-yanked-articles yank)
1108 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1110 (gnus-summary-goto-subject article))
1111 (gnus-setup-message (if yank 'reply-yank 'reply)
1113 (gnus-summary-select-article)
1114 (dolist (article very-wide)
1115 (gnus-summary-select-article nil nil nil article)
1117 (set-buffer (gnus-copy-article-buffer))
1118 (gnus-msg-treat-broken-reply-to)
1120 (message-narrow-to-head)
1121 (setq headers (concat headers (buffer-string)))))))
1122 (set-buffer (gnus-copy-article-buffer))
1123 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1125 (message-narrow-to-head)
1129 (goto-char (point-max)))
1130 (mml-quote-region (point) (point-max))
1131 (message-reply nil wide)
1133 (gnus-inews-yank-articles yank))
1134 (gnus-summary-handle-replysign)))))
1136 (defun gnus-summary-handle-replysign ()
1137 "Check the various replysign variables and take action accordingly."
1138 (when (or gnus-message-replysign gnus-message-replyencrypt)
1139 (let (signed encrypted)
1141 (set-buffer gnus-article-buffer)
1142 (setq signed (memq 'signed gnus-article-wash-types))
1143 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1144 (cond ((and gnus-message-replyencrypt encrypted)
1145 (mml-secure-message mml-default-encrypt-method
1146 (if gnus-message-replysignencrypted
1149 ((and gnus-message-replysign signed)
1150 (mml-secure-message mml-default-sign-method 'sign))))))
1152 (defun gnus-summary-reply-with-original (n &optional wide)
1153 "Start composing a reply mail to the current message.
1154 The original article will be yanked."
1156 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1158 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1159 "Like `gnus-summary-reply' except removing reply-to field.
1160 If prefix argument YANK is non-nil, the original article is yanked
1162 If WIDE, make a wide reply.
1163 If VERY-WIDE, make a very wide reply."
1165 (list (and current-prefix-arg
1166 (gnus-summary-work-articles 1))))
1167 (let ((gnus-msg-force-broken-reply-to t))
1168 (gnus-summary-reply yank wide very-wide)))
1170 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1171 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1172 The original article will be yanked."
1174 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1176 (defun gnus-summary-wide-reply (&optional yank)
1177 "Start composing a wide reply mail to the current message.
1178 If prefix argument YANK is non-nil, the original article is yanked
1181 (list (and current-prefix-arg
1182 (gnus-summary-work-articles 1))))
1183 (gnus-summary-reply yank t))
1185 (defun gnus-summary-wide-reply-with-original (n)
1186 "Start composing a wide reply mail to the current message.
1187 The original article will be yanked.
1188 Uses the process/prefix convention."
1190 (gnus-summary-reply-with-original n t))
1192 (defun gnus-summary-very-wide-reply (&optional yank)
1193 "Start composing a very wide reply mail to the current message.
1194 If prefix argument YANK is non-nil, the original article is yanked
1197 (list (and current-prefix-arg
1198 (gnus-summary-work-articles 1))))
1199 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1201 (defun gnus-summary-very-wide-reply-with-original (n)
1202 "Start composing a very wide reply mail to the current message.
1203 The original article will be yanked."
1206 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1208 (defun gnus-summary-mail-forward (&optional arg post)
1209 "Forward the current message(s) to another user.
1210 If process marks exist, forward all marked messages;
1211 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1212 if ARG is 1, decode the message and forward directly inline;
1213 if ARG is 2, forward message as an rfc822 MIME section;
1214 if ARG is 3, decode message and forward as an rfc822 MIME section;
1215 if ARG is 4, forward message directly inline;
1216 otherwise, use flipped `message-forward-as-mime'.
1217 If POST, post instead of mail.
1218 For the `inline' alternatives, also see the variable
1219 `message-forward-ignored-headers'."
1221 (if (cdr (gnus-summary-work-articles nil))
1222 ;; Process marks are given.
1223 (gnus-uu-digest-mail-forward arg post)
1224 ;; No process marks.
1225 (let ((message-forward-as-mime message-forward-as-mime)
1226 (message-forward-show-mml message-forward-show-mml))
1230 (setq message-forward-as-mime nil
1231 message-forward-show-mml t))
1233 (setq message-forward-as-mime t
1234 message-forward-show-mml nil))
1236 (setq message-forward-as-mime t
1237 message-forward-show-mml t))
1239 (setq message-forward-as-mime nil
1240 message-forward-show-mml nil))
1242 (setq message-forward-as-mime (not message-forward-as-mime))))
1243 (let* ((gnus-article-reply (gnus-summary-article-number))
1244 (gnus-article-yanked-articles (list gnus-article-reply)))
1245 (gnus-setup-message 'forward
1246 (gnus-summary-select-article)
1247 (let ((mail-parse-charset
1248 (or (and (gnus-buffer-live-p gnus-article-buffer)
1249 (with-current-buffer gnus-article-buffer
1250 gnus-article-charset))
1251 gnus-newsgroup-charset))
1252 (mail-parse-ignored-charsets
1253 gnus-newsgroup-ignored-charsets))
1254 (set-buffer gnus-original-article-buffer)
1255 (message-forward post)))))))
1257 (defun gnus-summary-resend-message (address n)
1258 "Resend the current article to ADDRESS."
1260 (list (message-read-from-minibuffer
1261 "Resend message(s) to: "
1262 (when (and gnus-summary-resend-default-address
1263 (gnus-buffer-live-p gnus-original-article-buffer))
1264 ;; If some other article is currently selected, the
1265 ;; initial-contents is wrong. Whatever, it is just the
1266 ;; initial-contents.
1267 (with-current-buffer gnus-original-article-buffer
1268 (nnmail-fetch-field "to"))))
1269 current-prefix-arg))
1270 (dolist (article (gnus-summary-work-articles n))
1271 (gnus-summary-select-article nil nil nil article)
1273 (set-buffer gnus-original-article-buffer)
1274 (message-resend address))
1275 (gnus-summary-mark-article-as-forwarded article)))
1277 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1278 (defun gnus-summary-resend-message-edit ()
1279 "Resend an article that has already been sent.
1280 A new buffer will be created to allow the user to modify body and
1281 contents of the message, and then, everything will happen as when
1282 composing a new message."
1284 (let ((article (gnus-summary-article-number)))
1285 (gnus-setup-message 'reply-yank
1286 (gnus-summary-select-article t)
1287 (set-buffer gnus-original-article-buffer)
1288 (let ((cur (current-buffer))
1289 (to (message-fetch-field "to")))
1290 ;; Get a normal message buffer.
1291 (message-pop-to-buffer (message-buffer-name "Resend" to))
1292 (insert-buffer-substring cur)
1294 (message-narrow-to-head-1)
1295 ;; Gnus will generate a new one when sending.
1296 (message-remove-header "Message-ID")
1297 (message-remove-header message-ignored-resent-headers t)
1298 ;; Remove unwanted headers.
1299 (goto-char (point-max))
1300 (insert mail-header-separator)
1301 (goto-char (point-min))
1302 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1306 (defun gnus-summary-post-forward (&optional arg)
1307 "Forward the current article to a newsgroup.
1308 See `gnus-summary-mail-forward' for ARG."
1310 (gnus-summary-mail-forward arg t))
1312 (defvar gnus-nastygram-message
1313 "The following article was inappropriately posted to %s.\n\n"
1314 "Format string to insert in nastygrams.
1315 The current group name will be inserted at \"%s\".")
1317 (defun gnus-summary-mail-nastygram (n)
1318 "Send a nastygram to the author of the current article."
1320 (when (or gnus-expert-user
1322 "Really send a nastygram to the author of the current article? "))
1323 (let ((group gnus-newsgroup-name))
1324 (gnus-summary-reply-with-original n)
1325 (set-buffer gnus-message-buffer)
1327 (insert (format gnus-nastygram-message group))
1328 (message-send-and-exit))))
1330 (defun gnus-summary-mail-crosspost-complaint (n)
1331 "Send a complaint about crossposting to the current article(s)."
1333 (dolist (article (gnus-summary-work-articles n))
1334 (set-buffer gnus-summary-buffer)
1335 (gnus-summary-goto-subject article)
1336 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1337 newsgroups followup-to)
1338 (gnus-summary-select-article)
1339 (set-buffer gnus-original-article-buffer)
1340 (if (and (<= (length (message-tokenize-header
1342 (mail-fetch-field "newsgroups"))
1345 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1346 (not (member group (message-tokenize-header
1347 followup-to ", ")))))
1349 (gnus-message 1 "Followup-to restricted")
1350 (gnus-message 1 "Not a crossposted article"))
1351 (set-buffer gnus-summary-buffer)
1352 (gnus-summary-reply-with-original 1)
1353 (set-buffer gnus-message-buffer)
1355 (insert (format gnus-crosspost-complaint newsgroups group))
1356 (message-goto-subject)
1357 (re-search-forward " *$")
1358 (replace-match " (crosspost notification)" t t)
1359 (gnus-deactivate-mark)
1360 (when (gnus-y-or-n-p "Send this complaint? ")
1361 (message-send-and-exit))))))
1363 (defun gnus-mail-parse-comma-list ()
1366 (skip-chars-forward " ")
1369 (skip-chars-forward "^,")
1374 (narrow-to-region beg (point))
1377 (while (search-forward "\"" nil t)
1381 (skip-chars-forward ",")
1382 (skip-chars-forward "^,"))
1383 (skip-chars-backward " ")
1384 (push (buffer-substring beg (point))
1386 (skip-chars-forward "^,")
1387 (skip-chars-forward ", "))
1390 (defun gnus-inews-add-to-address (group)
1391 (let ((to-address (mail-fetch-field "to")))
1392 (when (and to-address
1394 ;; This mail group doesn't have a `to-list', so we add one
1396 (when (gnus-y-or-n-p
1397 (format "Do you want to add this as `to-list': %s? " to-address))
1398 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1400 (defun gnus-put-message ()
1401 "Put the current message in some group and return to Gnus."
1403 (let ((reply gnus-article-reply)
1404 (winconf gnus-prev-winconf)
1405 (group gnus-newsgroup-name))
1407 (not (gnus-group-read-only-p group)))
1408 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1410 (when (gnus-group-entry group)
1411 (error "No such group: %s" group))
1415 (message-narrow-to-headers)
1416 (let ((gnus-deletable-headers nil))
1417 (message-generate-headers
1418 (if (message-news-p)
1419 message-required-news-headers
1420 message-required-mail-headers)))
1421 (goto-char (point-max))
1422 (if (string-match " " group)
1423 (insert "Gcc: \"" group "\"\n")
1424 (insert "Gcc: " group "\n"))
1427 (when (and (get-buffer gnus-group-buffer)
1428 (gnus-buffer-exists-p (car-safe reply))
1430 (set-buffer (car reply))
1431 (gnus-summary-mark-article-as-replied (cdr reply)))
1433 (set-window-configuration winconf))))
1435 (defun gnus-article-mail (yank)
1436 "Send a reply to the address near point.
1437 If YANK is non-nil, include the original article."
1441 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1442 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1444 (gnus-msg-mail address)
1446 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1448 (defvar nntp-server-type)
1450 "Send a bug report to the Gnus maintainers."
1452 (unless (gnus-alive-p)
1453 (error "Gnus has been shut down"))
1454 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1455 (unless (message-mail-user-agent)
1456 (delete-other-windows)
1457 (when gnus-bug-create-help-buffer
1458 (switch-to-buffer "*Gnus Help Bug*")
1460 (insert gnus-bug-message)
1461 (goto-char (point-min)))
1462 (message-pop-to-buffer "*Gnus Bug*"))
1463 (let ((message-this-is-mail t))
1464 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1465 (when gnus-bug-create-help-buffer
1466 (push `(gnus-bug-kill-buffer) message-send-actions))
1467 (goto-char (point-min))
1468 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1470 (insert (gnus-version) "\n"
1471 (emacs-version) "\n")
1472 (when (and (boundp 'nntp-server-type)
1473 (stringp nntp-server-type))
1474 (insert nntp-server-type))
1475 (insert "\n\n\n\n\n")
1478 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1481 (setq text (buffer-string)))
1482 (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1483 (goto-char (point-min))
1484 (search-forward "Subject: " nil t)
1487 (defun gnus-bug-kill-buffer ()
1488 (when (get-buffer "*Gnus Help Bug*")
1489 (kill-buffer "*Gnus Help Bug*")))
1491 (defun gnus-summary-yank-message (buffer n)
1492 "Yank the current article into a composed message."
1494 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1495 current-prefix-arg))
1496 (gnus-summary-iterate n
1497 (let ((gnus-inhibit-treatment t))
1498 (gnus-summary-select-article))
1501 (message-yank-buffer gnus-article-buffer))))
1503 (defun gnus-debug ()
1504 "Attempts to go through the Gnus source file and report what variables have been changed.
1505 The source file has to be in the Emacs load path."
1507 (let ((files gnus-debug-files)
1509 file expr olist sym)
1510 (gnus-message 4 "Please wait while we snoop your variables...")
1512 ;; Go through all the files looking for non-default values for variables.
1514 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1517 (when (and (setq file (locate-library (pop files)))
1518 (file-exists-p file))
1519 (insert-file-contents file)
1520 (goto-char (point-min))
1521 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1522 (gnus-message 4 "Malformed sources in file %s" file)
1523 (narrow-to-region (point-min) (point))
1524 (goto-char (point-min))
1525 (while (setq expr (ignore-errors (read (current-buffer))))
1527 (and (or (eq (car expr) 'defvar)
1528 (eq (car expr) 'defcustom))
1529 (stringp (nth 3 expr))
1530 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1531 (or (not (boundp (nth 1 expr)))
1532 (not (equal (eval (nth 2 expr))
1533 (symbol-value (nth 1 expr)))))
1534 (push (nth 1 expr) olist)))))))
1535 (kill-buffer (current-buffer)))
1536 (when (setq olist (nreverse olist))
1537 (insert "------------------ Environment follows ------------------\n\n"))
1539 (if (boundp (car olist))
1543 ,(if (or (consp (setq sym (symbol-value (car olist))))
1545 (not (or (eq sym nil)
1547 (list 'quote (symbol-value (car olist)))
1548 (symbol-value (car olist))))))
1549 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1550 (setq olist (cdr olist)))
1552 ;; Remove any control chars - they seem to cause trouble for some
1553 ;; mailers. (Byte-compiled output from the stuff above.)
1555 (while (re-search-forward (mm-string-as-multibyte
1556 "[\000-\010\013-\037\200-\237]") nil t)
1557 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1560 ;;; Treatment of rejected articles.
1563 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1564 "Re-mail the current message.
1565 This only makes sense if the current message is a bounce message that
1566 contains some mail you have written which has been bounced back to
1568 If FETCH, try to fetch the article that this is a reply to, if indeed
1571 (gnus-summary-select-article t)
1572 (set-buffer gnus-original-article-buffer)
1573 (gnus-setup-message 'compose-bounce
1574 (let* ((references (mail-fetch-field "references"))
1575 (parent (and references (gnus-parent-id references))))
1577 ;; If there are references, we fetch the article we answered to.
1579 (gnus-summary-refer-article parent)
1580 (gnus-summary-show-all-headers)))))
1584 (defun gnus-inews-group-method (group)
1586 ;; If the group doesn't exist, we assume
1587 ;; it's an archive group...
1588 ((and (null (gnus-get-info group))
1589 (eq (car (gnus-server-to-method gnus-message-archive-method))
1590 (car (gnus-server-to-method (gnus-group-method group)))))
1591 gnus-message-archive-method)
1593 ((gnus-info-method (gnus-get-info group))
1594 (gnus-info-method (gnus-get-info group)))
1596 (t (gnus-server-to-method (gnus-group-method group)))))
1598 ;; Do Gcc handling, which copied the message over to some group.
1599 (defun gnus-inews-do-gcc (&optional gcc)
1603 (message-narrow-to-headers)
1604 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1605 (cur (current-buffer))
1606 groups group method group-art
1607 mml-externalize-attachments)
1609 (message-remove-header "gcc")
1611 (setq groups (message-unquote-tokens
1612 (message-tokenize-header gcc " ,")))
1613 ;; Copy the article over to some group(s).
1614 (while (setq group (pop groups))
1615 (unless (gnus-check-server
1616 (setq method (gnus-inews-group-method group)))
1617 (error "Can't open server %s" (if (stringp method) method
1619 (unless (gnus-request-group group nil method)
1620 (gnus-request-create-group group method))
1621 (setq mml-externalize-attachments
1622 (if (stringp gnus-gcc-externalize-attachments)
1623 (string-match gnus-gcc-externalize-attachments group)
1624 gnus-gcc-externalize-attachments))
1626 (nnheader-set-temp-buffer " *acc*")
1627 (insert-buffer-substring cur)
1628 (message-encode-message-body)
1630 (message-narrow-to-headers)
1631 (let* ((mail-parse-charset message-default-charset)
1632 (newsgroups-field (save-restriction
1633 (message-narrow-to-headers-or-head)
1634 (message-fetch-field "Newsgroups")))
1635 (followup-field (save-restriction
1636 (message-narrow-to-headers-or-head)
1637 (message-fetch-field "Followup-To")))
1638 ;; BUG: We really need to get the charset for
1639 ;; each name in the Newsgroups and Followup-To
1640 ;; lines to allow crossposting between group
1641 ;; namess with incompatible character sets.
1642 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1643 (group-field-charset
1644 (gnus-group-name-charset
1645 method (or newsgroups-field "")))
1646 (followup-field-charset
1647 (gnus-group-name-charset
1648 method (or followup-field "")))
1649 (rfc2047-header-encoding-alist
1651 (when group-field-charset
1652 (list (cons "Newsgroups" group-field-charset)))
1653 (when followup-field-charset
1654 (list (cons "Followup-To" followup-field-charset)))
1655 rfc2047-header-encoding-alist)))
1656 (mail-encode-encoded-word-buffer)))
1657 (goto-char (point-min))
1658 (when (re-search-forward
1659 (concat "^" (regexp-quote mail-header-separator) "$")
1661 (replace-match "" t t ))
1662 (when (or (not (gnus-check-backend-function
1663 'request-accept-article group))
1664 (not (setq group-art
1665 (gnus-request-accept-article
1666 group method t t))))
1667 (gnus-message 1 "Couldn't store article in group %s: %s"
1668 group (gnus-status-message method)))
1669 (when (and group-art
1670 ;; FIXME: Should gcc-mark-as-read work when
1671 ;; Gnus is not running?
1673 (or gnus-gcc-mark-as-read
1675 (boundp 'gnus-inews-mark-gcc-as-read)
1676 (symbol-value 'gnus-inews-mark-gcc-as-read))))
1677 (gnus-group-mark-article-read group (cdr group-art)))
1678 (kill-buffer (current-buffer)))))))))
1680 (defun gnus-inews-insert-gcc ()
1681 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1684 (message-narrow-to-headers)
1685 (let* ((group gnus-outgoing-message-group)
1689 ((or (stringp group) (listp group))
1694 (if (string-match " " gcc)
1695 (concat "\"" gcc "\"")
1697 (mapconcat (lambda (group)
1698 (if (string-match " " group)
1699 (concat "\"" group "\"")
1704 (defun gnus-inews-insert-archive-gcc (&optional group)
1705 "Insert the Gcc to say where the article is to be archived."
1706 (let* ((var gnus-message-archive-group)
1707 (group (or group gnus-newsgroup-name ""))
1709 (and gnus-newsgroup-name
1710 (not (equal gnus-newsgroup-name ""))
1711 (gnus-group-find-parameter
1712 gnus-newsgroup-name 'gcc-self)))
1716 ((null gnus-message-archive-method)
1720 ;; Just a single group.
1723 ;; We don't want this.
1725 ((and (listp var) (stringp (car var)))
1726 ;; A list of groups.
1730 (funcall var group))
1732 ;; An alist of regexps/functions/forms.
1737 ((stringp (caar var))
1739 (when (string-match (caar var) group)
1741 ((functionp (car var))
1743 (funcall (car var) group))
1745 (eval (car var)))))))
1746 (setq var (cdr var)))
1749 (when (or groups gcc-self-val)
1750 (when (stringp groups)
1751 (setq groups (list groups)))
1754 (message-narrow-to-headers)
1755 (goto-char (point-max))
1758 ;; Use the `gcc-self' param value instead.
1761 (if (stringp gcc-self-val)
1762 (if (string-match " " gcc-self-val)
1763 (concat "\"" gcc-self-val "\"")
1765 ;; In nndoc groups, we use the parent group name
1766 ;; instead of the current group.
1767 (let ((group (or (gnus-group-find-parameter
1768 gnus-newsgroup-name 'parent-group)
1770 (if (string-match " " group)
1771 (concat "\"" group "\"")
1773 (if (not (eq gcc-self-val 'none))
1775 (gnus-delete-line)))
1776 ;; Use the list of groups.
1777 (while (setq name (pop groups))
1778 (let ((str (if (string-match ":" name)
1780 (gnus-group-prefixed-name
1781 name gnus-message-archive-method))))
1782 (insert (if (string-match " " str)
1783 (concat "\"" str "\"")
1789 (defun gnus-mailing-list-followup-to ()
1790 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1791 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1792 (list-post (gnus-fetch-original-field "list-post")))
1793 (when (and list-post
1794 (string-match "mailto:\\([^>]+\\)" list-post))
1795 (setq list-post (match-string 1 list-post)))
1801 (defun gnus-configure-posting-styles (&optional group-name)
1802 "Configure posting styles according to `gnus-posting-styles'."
1803 (unless gnus-inhibit-posting-styles
1804 (let ((group (or group-name gnus-newsgroup-name ""))
1805 (styles gnus-posting-styles)
1806 style match attribute value v results
1807 filep name address element)
1808 ;; If the group has a posting-style parameter, add it at the end with a
1809 ;; regexp matching everything, to be sure it takes precedence over all
1811 (when gnus-newsgroup-name
1812 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1814 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1815 ;; Go through all styles and look for matches.
1816 (dolist (style styles)
1817 (setq match (pop style))
1818 (goto-char (point-min))
1821 ;; Regexp string match on the group name.
1822 (string-match match group))
1824 ;; Obsolete format of header match.
1825 (and (gnus-buffer-live-p gnus-article-copy)
1826 (with-current-buffer gnus-article-copy
1828 (nnheader-narrow-to-headers)
1829 (let ((header (message-fetch-field (pop style))))
1831 (string-match (pop style) header)))))))
1832 ((or (symbolp match)
1836 ;; Function to be called.
1839 ;; Variable to be checked.
1840 (symbol-value match))))
1843 ((eq (car match) 'header)
1844 ;; New format of header match.
1845 (and (gnus-buffer-live-p gnus-article-copy)
1846 (with-current-buffer gnus-article-copy
1848 (nnheader-narrow-to-headers)
1849 (let ((header (message-fetch-field (nth 1 match))))
1851 (string-match (nth 2 match) header)))))))
1853 ;; This is a form to be evaled.
1855 ;; We have a match, so we set the variables.
1856 (dolist (attribute style)
1857 (setq element (pop attribute)
1861 ((eq (car attribute) :file)
1864 ((eq (car attribute) :value)
1868 ;; We get the value.
1873 ((or (symbolp value)
1875 (cond ((functionp value)
1878 (symbol-value value))))
1881 ;; Translate obsolescent value.
1883 ((eq element 'signature-file)
1884 (setq element 'signature
1886 ((eq element 'x-face-file)
1887 (setq element 'x-face
1889 ;; Post-processing for the signature posting-style:
1890 (and (eq element 'signature) filep
1891 message-signature-directory
1892 ;; don't actually use the signature directory
1893 ;; if message-signature-file contains a path.
1894 (not (file-name-directory v))
1895 (setq v (nnheader-concat message-signature-directory v)))
1896 ;; Get the contents of file elems.
1898 (setq v (with-temp-buffer
1899 (insert-file-contents v)
1903 (goto-char (point-max))
1904 (if (zerop (skip-chars-backward "\n"))
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 (gnus-make-local-hook 'message-setup-hook)
1914 (setq results (sort results (lambda (x y)
1915 (string-lessp (car x) (car y)))))
1916 (dolist (result results)
1917 (add-hook 'message-setup-hook
1919 ((eq 'eval (car result))
1921 ((eq 'body (car result))
1925 (insert ,(cdr result)))))
1926 ((eq 'signature (car result))
1927 (set (make-local-variable 'message-signature) nil)
1928 (set (make-local-variable 'message-signature-file) nil)
1929 (if (not (cdr result))
1933 (let ((message-signature ,(cdr result)))
1934 (when message-signature
1935 (message-insert-signature)))))))
1938 (if (symbolp (car result))
1939 (capitalize (symbol-name (car result)))
1943 (message-remove-header ,header)
1944 (let ((value ,(cdr result)))
1947 (insert ,header ": " value)
1949 (insert "\n")))))))))
1951 (when (or name address)
1952 (add-hook 'message-setup-hook
1954 (set (make-local-variable 'user-mail-address)
1955 ,(or (cdr address) user-mail-address))
1956 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1958 ,(or (cdr address) user-mail-address)))
1960 (message-remove-header "From")
1962 (insert "From: " (message-make-from) "\n"))))
1965 ;;; Allow redefinition of functions.
1971 ;;; arch-tag: 9f22b2f5-1c0a-49de-916e-4c88e984852b
1972 ;;; gnus-msg.el ends here