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))
37 (defcustom gnus-post-method 'current
38 "*Preferred method for posting USENET news.
40 If this variable is `current' (which is the default), Gnus will use
41 the \"current\" select method when posting. If it is `native', Gnus
42 will use the native select method when posting.
44 This method will not be used in mail groups and the like, only in
47 If not `native' nor `current', the value must be a valid method as discussed
48 in the documentation of `gnus-select-method'. It can also be a list of
49 methods. If that is the case, the user will be queried for what select
50 method to use when posting."
51 :group 'gnus-group-foreign
52 :link '(custom-manual "(gnus)Posting Server")
53 :type `(choice (const native)
55 (sexp :tag "Methods" ,gnus-select-method)))
57 (defcustom gnus-outgoing-message-group nil
58 "*All outgoing messages will be put in this group.
59 If you want to store all your outgoing mail and articles in the group
60 \"nnml:archive\", you set this variable to that value. This variable
61 can also be a list of group names.
63 If you want to have greater control over what group to put each
64 message in, you can set this variable to a function that checks the
65 current newsgroup name and then returns a suitable group name (or list
68 :type '(choice (string :tag "Group")
71 (defcustom gnus-mailing-list-groups nil
72 "*Regexp matching groups that are really mailing lists.
73 This is useful when you're reading a mailing list that has been
74 gatewayed to a newsgroup, and you want to followup to an article in
79 (defcustom gnus-add-to-list nil
80 "*If non-nil, add a `to-list' parameter automatically."
84 (defcustom gnus-crosspost-complaint
87 You posted the article below with the following Newsgroups header:
91 The %s group, at least, was an inappropriate recipient
92 of this message. Please trim your Newsgroups header to exclude this
93 group before posting in the future.
98 "Format string to be inserted when complaining about crossposts.
99 The first %s will be replaced by the Newsgroups header;
100 the second with the current group name."
104 (defcustom gnus-message-setup-hook nil
105 "Hook run after setting up a message buffer."
109 (defcustom gnus-bug-create-help-buffer t
110 "*Should we create the *Gnus Help Bug* buffer?"
114 (defcustom gnus-posting-styles nil
115 "*Alist of styles to use when posting.
116 See Info node `(gnus)Posting Styles'."
118 :link '(custom-manual "(gnus)Posting Styles")
119 :type '(repeat (cons (choice (regexp)
122 (string :tag "Header")
123 (regexp :tag "Regexp"))
127 (choice (const signature)
128 (const signature-file)
135 (string :tag "Header"))
141 (defcustom gnus-gcc-mark-as-read nil
142 "If non-nil, automatically mark Gcc articles as read."
147 (defvar gnus-inews-mark-gcc-as-read nil
148 "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
150 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
151 'gnus-gcc-mark-as-read)
153 (defcustom gnus-gcc-externalize-attachments nil
154 "Should local-file attachments be included as external parts in Gcc copies?
155 If it is `all', attach files as external parts;
156 if a regexp and matches the Gcc group name, attach files as external parts;
157 if nil, attach files as normal parts."
160 :type '(choice (const nil :tag "None")
161 (const all :tag "Any")
162 (string :tag "Regexp")))
164 (gnus-define-group-parameter
165 posting-charset-alist
168 "Return the permitted unencoded charsets for posting of GROUP."
169 :variable gnus-group-posting-charset-alist
171 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
172 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
173 (message-this-is-mail nil nil)
174 (message-this-is-news nil t))
176 "Alist of regexps and permitted unencoded charsets for posting.
177 Each element of the alist has the form (TEST HEADER BODY-LIST), where
178 TEST is either a regular expression matching the newsgroup header or a
180 HEADER is the charset which may be left unencoded in the header (nil
181 means encode all charsets),
182 BODY-LIST is a list of charsets which may be encoded using 8bit
183 content-transfer encoding in the body, or one of the special values
184 nil (always encode using quoted-printable) or t (always use 8bit).
186 Note that any value other than nil for HEADER infringes some RFCs, so
187 use this option with care."
188 :variable-group gnus-charset
190 '(repeat (list :tag "Permitted unencoded charsets"
192 (regexp :tag "Group")
193 (const :tag "Mail message" :value message-this-is-mail)
194 (const :tag "News article" :value message-this-is-news))
195 (choice :tag "Header"
196 (const :tag "None" nil)
197 (symbol :tag "Charset"))
199 (const :tag "Any" :value t)
200 (const :tag "None" :value nil)
201 (repeat :tag "Charsets"
202 (symbol :tag "Charset")))))
203 :parameter-type '(choice :tag "Permitted unencoded charsets"
206 :parameter-document "\
207 List of charsets that are permitted to be unencoded.")
209 (defcustom gnus-debug-files
210 '("gnus.el" "gnus-sum.el" "gnus-group.el"
211 "gnus-art.el" "gnus-start.el" "gnus-async.el"
212 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
213 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
214 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
215 "Files whose variables will be reported in `gnus-bug'."
218 :type '(repeat (string :tag "File")))
220 (defcustom gnus-debug-exclude-variables
221 '(mm-mime-mule-charset-alist
222 nnmail-split-fancy message-minibuffer-local-map)
223 "Variables that should not be reported in `gnus-bug'."
226 :type '(repeat (symbol :tag "Variable")))
228 (defcustom gnus-discouraged-post-methods
229 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
230 "A list of back ends that are not used in \"real\" newsgroups.
231 This variable is used only when `gnus-post-method' is `current'."
233 :group 'gnus-group-foreign
234 :type '(repeat (symbol :tag "Back end")))
236 (defcustom gnus-message-replysign
238 "Automatically sign replys to signed messages.
239 See also the `mml-default-sign-method' variable."
243 (defcustom gnus-message-replyencrypt
245 "Automatically encrypt replys to encrypted messages.
246 See also the `mml-default-encrypt-method' variable."
250 (defcustom gnus-message-replysignencrypted
252 "Setting this causes automatically encryped messages to also be signed."
256 (defcustom gnus-confirm-mail-reply-to-news nil
257 "If non-nil, Gnus requests confirmation when replying to news.
258 This is done because new users often reply by mistake when reading
260 This can also be a function which should return non-nil iff a
261 confirmation is needed, or a regexp, in which case a confirmation is
262 asked if the group name matches the regexp."
264 :type '(choice (const :tag "No" nil)
265 (const :tag "Yes" nil)
266 (regexp :tag "Iff group matches regexp")
267 (function :tag "Iff function evaluates to non-nil")))
269 (defcustom gnus-confirm-treat-mail-like-news
271 "If non-nil, Gnus will treat mail like news with regard to confirmation
272 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
273 for fine-tuning this.
274 If nil, Gnus will never ask for confirmation if replying to mail."
278 (defcustom gnus-summary-resend-default-address t
279 "If non-nil, Gnus tries to suggest a default address to resend to.
280 If nil, the address field will always be empty after invoking
281 `gnus-summary-resend-message'."
285 ;;; Internal variables.
287 (defvar gnus-inhibit-posting-styles nil
288 "Inhibit the use of posting styles.")
290 (defvar gnus-article-yanked-articles nil)
291 (defvar gnus-message-buffer "*Mail Gnus*")
292 (defvar gnus-article-copy nil)
293 (defvar gnus-check-before-posting nil)
294 (defvar gnus-last-posting-server nil)
295 (defvar gnus-message-group-art nil)
297 (defvar gnus-msg-force-broken-reply-to nil)
299 (defconst gnus-bug-message
300 "Sending a bug report to the Gnus Towers.
301 ========================================
303 The buffer below is a mail buffer. When you press `C-c C-c', it will
304 be sent to the Gnus Bug Exterminators.
306 The thing near the bottom of the buffer is how the environment
307 settings will be included in the mail. Please do not delete that.
308 They will tell the Bug People what your environment is, so that it
309 will be easier to locate the bugs.
311 If you have found a bug that makes Emacs go \"beep\", set
312 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
313 and include the backtrace in your bug report.
315 Please describe the bug in annoying, painstaking detail.
317 Thank you for your help in stamping out bugs.
321 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
322 (autoload 'news-setup "rnewspost")
323 (autoload 'news-reply-mode "rnewspost")
324 (autoload 'rmail-dont-reply-to "mail-utils")
325 (autoload 'rmail-output "rmailout"))
329 ;;; Gnus Posting Functions
332 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
333 "p" gnus-summary-post-news
334 "i" gnus-summary-news-other-window
335 "f" gnus-summary-followup
336 "F" gnus-summary-followup-with-original
337 "c" gnus-summary-cancel-article
338 "s" gnus-summary-supersede-article
339 "r" gnus-summary-reply
340 "y" gnus-summary-yank-message
341 "R" gnus-summary-reply-with-original
342 "w" gnus-summary-wide-reply
343 "W" gnus-summary-wide-reply-with-original
344 "v" gnus-summary-very-wide-reply
345 "V" gnus-summary-very-wide-reply-with-original
346 "n" gnus-summary-followup-to-mail
347 "N" gnus-summary-followup-to-mail-with-original
348 "m" gnus-summary-mail-other-window
349 "u" gnus-uu-post-news
350 "\M-c" gnus-summary-mail-crosspost-complaint
351 "Br" gnus-summary-reply-broken-reply-to
352 "BR" gnus-summary-reply-broken-reply-to-with-original
353 "om" gnus-summary-mail-forward
354 "op" gnus-summary-post-forward
355 "Om" gnus-uu-digest-mail-forward
356 "Op" gnus-uu-digest-post-forward)
358 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
359 "b" gnus-summary-resend-bounced-mail
360 ;; "c" gnus-summary-send-draft
361 "r" gnus-summary-resend-message
362 "e" gnus-summary-resend-message-edit)
364 ;;; Internal functions.
366 (defun gnus-inews-make-draft ()
368 (gnus-inews-make-draft-meta-information
369 ,gnus-newsgroup-name ',gnus-article-reply)))
371 (defvar gnus-article-reply nil)
372 (defmacro gnus-setup-message (config &rest forms)
373 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
374 (buffer (make-symbol "gnus-setup-message-buffer"))
375 (article (make-symbol "gnus-setup-message-article"))
376 (yanked (make-symbol "gnus-setup-yanked-articles"))
377 (group (make-symbol "gnus-setup-message-group")))
378 `(let ((,winconf (current-window-configuration))
379 (,buffer (buffer-name (current-buffer)))
380 (,article gnus-article-reply)
381 (,yanked gnus-article-yanked-articles)
382 (,group gnus-newsgroup-name)
383 (message-header-setup-hook
384 (copy-sequence message-header-setup-hook))
385 (mbl mml-buffer-list)
386 (message-mode-hook (copy-sequence message-mode-hook)))
387 (setq mml-buffer-list nil)
388 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
389 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
390 ;; #### FIXME: for a reason that I did not manage to identify yet,
391 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
392 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
393 ;; After evaluation of @forms below, it gets the value we actually want
394 ;; to override, and the posting styles are used. For that reason, I've
395 ;; added an optional argument to `gnus-configure-posting-styles' to
396 ;; make sure that the correct value for the group name is used. -- drv
397 (add-hook 'message-mode-hook
399 (gnus-configure-posting-styles ,group)))
400 (gnus-pull ',(intern gnus-draft-meta-information-header)
401 message-required-headers)
403 (not (string= ,group "")))
405 (intern gnus-draft-meta-information-header)
406 (gnus-inews-make-draft))
407 message-required-headers))
411 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
413 (setq gnus-message-buffer (current-buffer))
414 (set (make-local-variable 'gnus-message-group-art)
415 (cons ,group ,article))
416 (set (make-local-variable 'gnus-newsgroup-name) ,group)
417 (gnus-run-hooks 'gnus-message-setup-hook)
418 (if (eq major-mode 'message-mode)
419 (let ((mbl1 mml-buffer-list))
420 (setq mml-buffer-list mbl) ;; Global value
421 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
422 ;; LOCAL argument of add-hook differs between GNU Emacs
423 ;; and XEmacs. make-local-hook makes sure they are local.
424 (make-local-hook 'kill-buffer-hook)
425 (make-local-hook 'change-major-mode-hook)
426 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
427 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
428 (mml-destroy-buffers)
429 (setq mml-buffer-list mbl)))
431 (gnus-configure-windows ,config t)
432 (run-hooks 'post-command-hook)
433 (set-buffer-modified-p nil))))
435 (defun gnus-inews-make-draft-meta-information (group article)
436 (concat "(\"" group "\" "
437 (if article (number-to-string
444 (defun gnus-msg-mail (&optional to subject other-headers continue
445 switch-action yank-action send-actions)
446 "Start editing a mail message to be sent.
447 Like `message-mail', but with Gnus paraphernalia, particularly the
448 Gcc: header for archiving purposes."
450 (let ((buf (current-buffer))
452 (gnus-setup-message 'message
453 (message-mail to subject other-headers continue
454 nil yank-action send-actions))
456 (setq mail-buf (current-buffer))
457 (switch-to-buffer buf)
458 (apply switch-action mail-buf nil)))
459 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
462 (defvar save-selected-window-window)
465 (defun gnus-button-mailto (address)
467 (set-buffer (gnus-copy-article-buffer))
468 (gnus-setup-message 'message
469 (message-reply address))
470 (and (boundp 'save-selected-window-window)
471 (not (window-live-p save-selected-window-window))
472 (setq save-selected-window-window (selected-window))))
475 (defun gnus-button-reply (&optional to-address wide)
476 "Like `message-reply'."
478 (gnus-setup-message 'message
479 (message-reply to-address wide))
480 (and (boundp 'save-selected-window-window)
481 (not (window-live-p save-selected-window-window))
482 (setq save-selected-window-window (selected-window))))
485 (define-mail-user-agent 'gnus-user-agent
486 'gnus-msg-mail 'message-send-and-exit
487 'message-kill-buffer 'message-send-hook)
489 (defun gnus-setup-posting-charset (group)
490 (let ((alist gnus-group-posting-charset-alist)
491 (group (or group ""))
495 (while (setq elem (pop alist))
496 (when (or (and (stringp (car elem))
497 (string-match (car elem) group))
498 (and (gnus-functionp (car elem))
499 (funcall (car elem) group))
500 (and (symbolp (car elem))
501 (symbol-value (car elem))))
502 (throw 'found (cons (cadr elem) (caddr elem)))))))))
504 (defun gnus-inews-add-send-actions (winconf buffer article
505 &optional config yanked)
506 (make-local-hook 'message-sent-hook)
507 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
508 'gnus-inews-do-gcc) nil t)
510 (make-local-hook 'message-header-hook)
511 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
512 (setq message-post-method
514 (gnus-post-method arg ,gnus-newsgroup-name)))
515 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
517 `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
519 `(when (gnus-buffer-exists-p ,buffer)
523 (if (eq config 'forward)
524 `(gnus-summary-mark-article-as-forwarded ',yanked)
525 `(gnus-summary-mark-article-as-replied ',yanked)))))
528 (put 'gnus-setup-message 'lisp-indent-function 1)
529 (put 'gnus-setup-message 'edebug-form-spec '(form body))
531 ;;; Post news commands of Gnus group mode and summary mode
533 (defun gnus-group-mail (&optional arg)
534 "Start composing a mail.
535 If ARG, use the group under the point to find a posting style.
536 If ARG is 1, prompt for a group name to find the posting style."
538 ;; We can't `let' gnus-newsgroup-name here, since that leads
539 ;; to local variables leaking.
540 (let ((group gnus-newsgroup-name)
541 ;; make sure last viewed article doesn't affect posting styles:
543 (buffer (current-buffer)))
546 (setq gnus-newsgroup-name
548 (if (= 1 (prefix-numeric-value arg))
549 (completing-read "Use posting style of group: "
550 gnus-active-hashtb nil
551 (gnus-read-active-file-p))
552 (gnus-group-group-name))
554 ;; #### see comment in gnus-setup-message -- drv
555 (gnus-setup-message 'message (message-mail)))
558 (setq gnus-newsgroup-name group)))))
560 (defun gnus-group-news (&optional arg)
561 "Start composing a news.
562 If ARG, post to group under point.
563 If ARG is 1, prompt for group name to post to.
565 This function prepares a news even when using mail groups. This is useful
566 for posting messages to mail groups without actually sending them over the
567 network. The corresponding backend must have a 'request-post method."
569 ;; We can't `let' gnus-newsgroup-name here, since that leads
570 ;; to local variables leaking.
571 (let ((group gnus-newsgroup-name)
572 ;; make sure last viewed article doesn't affect posting styles:
574 (buffer (current-buffer)))
577 (setq gnus-newsgroup-name
579 (if (= 1 (prefix-numeric-value arg))
580 (completing-read "Use group: "
581 gnus-active-hashtb nil
582 (gnus-read-active-file-p))
583 (gnus-group-group-name))
585 ;; #### see comment in gnus-setup-message -- drv
586 (gnus-setup-message 'message
587 (message-news (gnus-group-real-name gnus-newsgroup-name))))
590 (setq gnus-newsgroup-name group)))))
592 (defun gnus-group-post-news (&optional arg)
593 "Start composing a message (a news by default).
594 If ARG, post to group under point. If ARG is 1, prompt for group name.
595 Depending on the selected group, the message might be either a mail or
598 ;; Bind this variable here to make message mode hooks work ok.
599 (let ((gnus-newsgroup-name
601 (if (= 1 (prefix-numeric-value arg))
602 (completing-read "Newsgroup: " gnus-active-hashtb nil
603 (gnus-read-active-file-p))
604 (gnus-group-group-name))
606 ;; make sure last viewed article doesn't affect posting styles:
608 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
609 (string= gnus-newsgroup-name ""))))
611 (defun gnus-summary-mail-other-window (&optional arg)
612 "Start composing a mail in another window.
613 Use the posting of the current group by default.
614 If ARG, don't do that. If ARG is 1, prompt for group name to find the
617 ;; We can't `let' gnus-newsgroup-name here, since that leads
618 ;; to local variables leaking.
619 (let ((group gnus-newsgroup-name)
620 ;; make sure last viewed article doesn't affect posting styles:
622 (buffer (current-buffer)))
625 (setq gnus-newsgroup-name
627 (if (= 1 (prefix-numeric-value arg))
628 (completing-read "Use group: "
629 gnus-active-hashtb nil
630 (gnus-read-active-file-p))
632 gnus-newsgroup-name))
633 ;; #### see comment in gnus-setup-message -- drv
634 (gnus-setup-message 'message (message-mail)))
637 (setq gnus-newsgroup-name group)))))
639 (defun gnus-summary-news-other-window (&optional arg)
640 "Start composing a news in another window.
641 Post to the current group by default.
642 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
644 This function prepares a news even when using mail groups. This is useful
645 for posting messages to mail groups without actually sending them over the
646 network. The corresponding backend must have a 'request-post method."
648 ;; We can't `let' gnus-newsgroup-name here, since that leads
649 ;; to local variables leaking.
650 (let ((group gnus-newsgroup-name)
651 ;; make sure last viewed article doesn't affect posting styles:
653 (buffer (current-buffer)))
656 (setq gnus-newsgroup-name
658 (if (= 1 (prefix-numeric-value arg))
659 (completing-read "Use group: "
660 gnus-active-hashtb nil
661 (gnus-read-active-file-p))
663 gnus-newsgroup-name))
664 ;; #### see comment in gnus-setup-message -- drv
665 (gnus-setup-message 'message
666 (message-news (gnus-group-real-name gnus-newsgroup-name))))
669 (setq gnus-newsgroup-name group)))))
671 (defun gnus-summary-post-news (&optional arg)
672 "Start composing a message. Post to the current group by default.
673 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
674 Depending on the selected group, the message might be either a mail or
677 ;; Bind this variable here to make message mode hooks work ok.
678 (let ((gnus-newsgroup-name
680 (if (= 1 (prefix-numeric-value arg))
681 (completing-read "Newsgroup: " gnus-active-hashtb nil
682 (gnus-read-active-file-p))
684 gnus-newsgroup-name))
685 ;; make sure last viewed article doesn't affect posting styles:
687 (gnus-post-news 'post gnus-newsgroup-name)))
690 (defun gnus-summary-followup (yank &optional force-news)
691 "Compose a followup to an article.
692 If prefix argument YANK is non-nil, the original article is yanked
694 YANK is a list of elements, where the car of each element is the
695 article number, and the two following numbers is the region to be
698 (list (and current-prefix-arg
699 (gnus-summary-work-articles 1))))
701 (gnus-summary-goto-subject
702 (if (listp (car yank))
705 (save-window-excursion
706 (gnus-summary-select-article))
707 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
708 (gnus-newsgroup-name gnus-newsgroup-name))
710 (gnus-post-news nil gnus-newsgroup-name
711 headers gnus-article-buffer
713 (gnus-summary-handle-replysign)))
715 (defun gnus-summary-followup-with-original (n &optional force-news)
716 "Compose a followup to an article and include the original article."
718 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
720 (defun gnus-summary-followup-to-mail (&optional arg)
721 "Followup to the current mail message via news."
723 (list (and current-prefix-arg
724 (gnus-summary-work-articles 1))))
725 (gnus-summary-followup arg t))
727 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
728 "Followup to the current mail message via news."
730 (gnus-summary-followup (gnus-summary-work-articles arg) t))
732 (defun gnus-inews-yank-articles (articles)
733 (let (beg article yank-string)
735 (while (setq article (pop articles))
736 (when (listp article)
737 (setq yank-string (nth 1 article)
738 article (nth 0 article)))
739 (save-window-excursion
740 (set-buffer gnus-summary-buffer)
741 (gnus-summary-select-article nil nil nil article)
742 (gnus-summary-remove-process-mark article))
743 (gnus-copy-article-buffer nil yank-string)
744 (let ((message-reply-buffer gnus-article-copy)
745 (message-reply-headers
746 ;; The headers are decoded.
747 (with-current-buffer gnus-article-copy
749 (nnheader-narrow-to-headers)
750 (nnheader-parse-naked-head)))))
751 (message-yank-original)
752 (setq beg (or beg (mark t))))
758 (defun gnus-summary-cancel-article (&optional n symp)
759 "Cancel an article you posted.
760 Uses the process-prefix convention. If given the symbolic
761 prefix `a', cancel using the standard posting method; if not
762 post using the current select method."
763 (interactive (gnus-interactive "P\ny"))
764 (let ((articles (gnus-summary-work-articles n))
767 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
769 (while (setq article (pop articles))
770 (when (gnus-summary-select-article t nil nil article)
771 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
772 (message-cancel-news))
773 (gnus-summary-mark-as-read article gnus-canceled-mark)
774 (gnus-cache-remove-article 1))
775 (gnus-article-hide-headers-if-wanted))
776 (gnus-summary-remove-process-mark article))))
778 (defun gnus-summary-supersede-article ()
779 "Compose an article that will supersede a previous article.
780 This is done simply by taking the old article and adding a Supersedes
781 header line with the old Message-ID."
783 (let ((article (gnus-summary-article-number)))
784 (gnus-setup-message 'reply-yank
785 (gnus-summary-select-article t)
786 (set-buffer gnus-original-article-buffer)
790 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
792 (set-buffer ,gnus-summary-buffer)
793 (gnus-cache-possibly-remove-article ,article nil nil nil t)
794 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
795 message-send-actions))))
799 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
800 ;; make a copy of the article buffer with all text properties removed
801 ;; this copy is in the buffer gnus-article-copy.
802 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
803 ;; this buffer should be passed to all mail/news reply/post routines.
804 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
806 (set-buffer gnus-article-copy)
807 (mm-enable-multibyte))
808 (let ((article-buffer (or article-buffer gnus-article-buffer))
810 (if (not (and (get-buffer article-buffer)
811 (gnus-buffer-exists-p article-buffer)))
812 (error "Can't find any article buffer")
814 (set-buffer article-buffer)
815 (let ((gnus-newsgroup-charset (or gnus-article-charset
816 gnus-newsgroup-charset))
817 (gnus-newsgroup-ignored-charsets
818 (or gnus-article-ignored-charsets
819 gnus-newsgroup-ignored-charsets)))
821 ;; Copy over the (displayed) article buffer, delete
822 ;; hidden text and remove text properties.
824 (copy-to-buffer gnus-article-copy (point-min) (point-max))
825 (set-buffer gnus-article-copy)
828 (delete-region (point) (point-max))
829 (insert yank-string))
830 (gnus-article-delete-text-of-type 'annotation)
831 (gnus-remove-text-with-property 'gnus-prev)
832 (gnus-remove-text-with-property 'gnus-next)
833 (gnus-remove-text-with-property 'gnus-decoration)
836 (buffer-substring-no-properties (point-min) (point-max))
838 ;; Find the original headers.
839 (set-buffer gnus-original-article-buffer)
840 (goto-char (point-min))
841 (while (looking-at message-unix-mail-delimiter)
843 (let ((mail-header-separator ""))
845 end (or (message-goto-body) beg)))
846 ;; Delete the headers from the displayed articles.
847 (set-buffer gnus-article-copy)
848 (let ((mail-header-separator ""))
849 (delete-region (goto-char (point-min))
850 (or (message-goto-body) (point-max))))
851 ;; Insert the original article headers.
852 (insert-buffer-substring gnus-original-article-buffer beg end)
854 (let ((gnus-article-decode-hook
855 (delq 'article-decode-charset
856 (copy-sequence gnus-article-decode-hook))))
857 (run-hooks 'gnus-article-decode-hook)))))
860 (defun gnus-post-news (post &optional group header article-buffer yank subject
863 (gnus-copy-article-buffer))
864 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
865 (gnus-article-yanked-articles yank)
866 (add-to-list gnus-add-to-list))
867 (gnus-setup-message (cond (yank 'reply-yank)
868 (article-buffer 'reply)
870 (let* ((group (or group gnus-newsgroup-name))
871 (charset (gnus-group-name-charset nil group))
873 to-address to-group mailing-list to-list
876 (setq to-address (gnus-parameter-to-address group)
877 to-group (gnus-group-find-parameter group 'to-group)
878 to-list (gnus-parameter-to-list group)
879 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
880 mailing-list (when gnus-mailing-list-groups
881 (string-match gnus-mailing-list-groups group))
882 group (gnus-group-name-decode (gnus-group-real-name group)
884 (if (or (and to-group
885 (gnus-news-group-p to-group))
888 (and (gnus-news-group-p
889 (or pgroup gnus-newsgroup-name)
890 (or header gnus-current-article))
896 (message-news (or to-group group))
897 (set-buffer gnus-article-copy)
898 (gnus-msg-treat-broken-reply-to)
899 (message-followup (if (or newsgroup-p force-news)
900 (if (save-restriction
901 (article-narrow-to-head)
902 (message-fetch-field "newsgroups"))
909 (message-mail (or to-address to-list))
910 ;; Arrange for mail groups that have no `to-address' to
911 ;; get that when the user sends off the mail.
912 (when (and (not to-list)
915 (push (list 'gnus-inews-add-to-address pgroup)
916 message-send-actions)))
917 (set-buffer gnus-article-copy)
918 (gnus-msg-treat-broken-reply-to)
919 (message-wide-reply to-address)))
921 (gnus-inews-yank-articles yank))))))
923 (defun gnus-msg-treat-broken-reply-to (&optional force)
924 "Remove the Reply-to header if broken-reply-to."
926 (gnus-group-find-parameter
927 gnus-newsgroup-name 'broken-reply-to))
929 (message-narrow-to-head)
930 (message-remove-header "reply-to"))))
932 (defun gnus-post-method (arg group &optional silent)
933 "Return the posting method based on GROUP and ARG.
934 If SILENT, don't prompt the user."
935 (let ((gnus-post-method (or (gnus-parameter-post-method group)
937 (group-method (gnus-find-method-for-group group)))
939 ;; If the group-method is nil (which shouldn't happen) we use
940 ;; the default method.
942 (or (and (listp gnus-post-method) ;If not current/native/nil
943 (not (listp (car gnus-post-method))) ; and not a list of methods
944 gnus-post-method) ;then use it.
946 message-post-method))
947 ;; We want the inverse of the default
948 ((and arg (not (eq arg 0)))
949 (if (eq gnus-post-method 'current)
952 ;; We query the user for a post method.
954 (and (listp gnus-post-method)
955 (listp (car gnus-post-method))))
957 ;; Collect all methods we know about.
959 (when (listp gnus-post-method)
960 (if (listp (car gnus-post-method))
962 (list gnus-post-method)))
963 gnus-secondary-select-methods
964 (mapcar 'cdr gnus-server-alist)
965 (mapcar 'car gnus-opened-servers)
966 (list gnus-select-method)
967 (list group-method)))
968 method-alist post-methods method)
969 ;; Weed out all mail methods.
971 (setq method (gnus-server-get-method "" (pop methods)))
972 (when (and (or (gnus-method-option-p method 'post)
973 (gnus-method-option-p method 'post-mail))
974 (not (member method post-methods)))
975 (push method post-methods)))
976 ;; Create a name-method alist.
980 (if (equal (cadr m) "")
981 (list (symbol-name (car m)) m)
982 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
987 (setq gnus-last-posting-server
989 gnus-last-posting-server)
990 ;; Just use the last value.
991 gnus-last-posting-server
993 "Posting method: " method-alist nil t
994 (cons (or gnus-last-posting-server "") 0))))
996 ;; Override normal method.
997 ((and (eq gnus-post-method 'current)
998 (not (memq (car group-method) gnus-discouraged-post-methods))
999 (gnus-get-function group-method 'request-post t))
1002 ;; Use gnus-post-method.
1003 ((listp gnus-post-method) ;A method...
1004 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1006 ;; Use the normal select method (nil or native).
1007 (t gnus-select-method))))
1011 ;; Dummies to avoid byte-compile warning.
1013 (defvar nnspool-rejected-article-hook)
1014 (defvar xemacs-codename))
1016 (defun gnus-extended-version ()
1017 "Stringified Gnus version and Emacs version."
1020 "Gnus/" (prin1-to-string (gnus-continuum-version gnus-version) t)
1021 " (" gnus-version ")"
1024 ((string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
1025 (concat "Emacs/" (match-string 1 emacs-version)
1026 " (" system-configuration ")"))
1027 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
1029 (concat (match-string 1 emacs-version)
1030 (format "/%d.%d" emacs-major-version emacs-minor-version)
1031 (if (match-beginning 3)
1032 (match-string 3 emacs-version)
1034 (if (boundp 'xemacs-codename)
1035 (concat " (" xemacs-codename ", " system-configuration ")")
1037 (t emacs-version))))
1041 ;;; Gnus Mail Functions
1044 ;;; Mail reply commands of Gnus summary mode
1046 (defun gnus-summary-reply (&optional yank wide very-wide)
1047 "Start composing a mail reply to the current message.
1048 If prefix argument YANK is non-nil, the original article is yanked
1050 If WIDE, make a wide reply.
1051 If VERY-WIDE, make a very wide reply."
1053 (list (and current-prefix-arg
1054 (gnus-summary-work-articles 1))))
1055 ;; Allow user to require confirmation before replying by mail to the
1056 ;; author of a news article (or mail message).
1058 (not (or (gnus-news-group-p gnus-newsgroup-name)
1059 gnus-confirm-treat-mail-like-news))
1060 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1061 (string-match gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1062 ((functionp gnus-confirm-mail-reply-to-news)
1063 (funcall gnus-confirm-mail-reply-to-news))
1064 (t gnus-confirm-mail-reply-to-news)))
1065 (y-or-n-p "Really reply by mail to article author? "))
1067 (if (listp (car yank))
1070 (gnus-article-reply (or article (gnus-summary-article-number)))
1071 (gnus-article-yanked-articles yank)
1073 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1075 (gnus-summary-goto-subject article))
1076 (gnus-setup-message (if yank 'reply-yank 'reply)
1078 (gnus-summary-select-article)
1079 (dolist (article very-wide)
1080 (gnus-summary-select-article nil nil nil article)
1082 (set-buffer (gnus-copy-article-buffer))
1083 (gnus-msg-treat-broken-reply-to)
1085 (message-narrow-to-head)
1086 (setq headers (concat headers (buffer-string)))))))
1087 (set-buffer (gnus-copy-article-buffer))
1088 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1090 (message-narrow-to-head)
1094 (goto-char (point-max)))
1095 (mml-quote-region (point) (point-max))
1096 (message-reply nil wide)
1098 (gnus-inews-yank-articles yank))
1099 (gnus-summary-handle-replysign)))))
1101 (defun gnus-summary-handle-replysign ()
1102 "Check the various replysign variables and take action accordingly."
1103 (when (or gnus-message-replysign gnus-message-replyencrypt)
1104 (let (signed encrypted)
1106 (set-buffer gnus-article-buffer)
1107 (setq signed (memq 'signed gnus-article-wash-types))
1108 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1109 (cond ((and gnus-message-replyencrypt encrypted)
1110 (mml-secure-message mml-default-encrypt-method
1111 (if gnus-message-replysignencrypted
1114 ((and gnus-message-replysign signed)
1115 (mml-secure-message mml-default-sign-method 'sign))))))
1117 (defun gnus-summary-reply-with-original (n &optional wide)
1118 "Start composing a reply mail to the current message.
1119 The original article will be yanked."
1121 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1123 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1124 "Like `gnus-summary-reply' except removing reply-to field.
1125 If prefix argument YANK is non-nil, the original article is yanked
1127 If WIDE, make a wide reply.
1128 If VERY-WIDE, make a very wide reply."
1130 (list (and current-prefix-arg
1131 (gnus-summary-work-articles 1))))
1132 (let ((gnus-msg-force-broken-reply-to t))
1133 (gnus-summary-reply yank wide very-wide)))
1135 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1136 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1137 The original article will be yanked."
1139 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1141 (defun gnus-summary-wide-reply (&optional yank)
1142 "Start composing a wide reply mail to the current message.
1143 If prefix argument YANK is non-nil, the original article is yanked
1146 (list (and current-prefix-arg
1147 (gnus-summary-work-articles 1))))
1148 (gnus-summary-reply yank t))
1150 (defun gnus-summary-wide-reply-with-original (n)
1151 "Start composing a wide reply mail to the current message.
1152 The original article will be yanked."
1154 (gnus-summary-reply-with-original n t))
1156 (defun gnus-summary-very-wide-reply (&optional yank)
1157 "Start composing a very wide reply mail to the current message.
1158 If prefix argument YANK is non-nil, the original article is yanked
1161 (list (and current-prefix-arg
1162 (gnus-summary-work-articles 1))))
1163 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1165 (defun gnus-summary-very-wide-reply-with-original (n)
1166 "Start composing a very wide reply mail to the current message.
1167 The original article will be yanked."
1170 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1172 (defun gnus-summary-mail-forward (&optional arg post)
1173 "Forward the current message(s) to another user.
1174 If process marks exist, forward all marked messages;
1175 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1176 if ARG is 1, decode the message and forward directly inline;
1177 if ARG is 2, forward message as an rfc822 MIME section;
1178 if ARG is 3, decode message and forward as an rfc822 MIME section;
1179 if ARG is 4, forward message directly inline;
1180 otherwise, use flipped `message-forward-as-mime'.
1181 If POST, post instead of mail.
1182 For the `inline' alternatives, also see the variable
1183 `message-forward-ignored-headers'."
1185 (if (cdr (gnus-summary-work-articles nil))
1186 ;; Process marks are given.
1187 (gnus-uu-digest-mail-forward arg post)
1188 ;; No process marks.
1189 (let ((message-forward-as-mime message-forward-as-mime)
1190 (message-forward-show-mml message-forward-show-mml))
1194 (setq message-forward-as-mime nil
1195 message-forward-show-mml t))
1197 (setq message-forward-as-mime t
1198 message-forward-show-mml nil))
1200 (setq message-forward-as-mime t
1201 message-forward-show-mml t))
1203 (setq message-forward-as-mime nil
1204 message-forward-show-mml nil))
1206 (setq message-forward-as-mime (not message-forward-as-mime))))
1207 (let* ((gnus-article-reply (gnus-summary-article-number))
1208 (gnus-article-yanked-articles (list gnus-article-reply)))
1209 (gnus-setup-message 'forward
1210 (gnus-summary-select-article)
1211 (let ((mail-parse-charset
1212 (or (and (gnus-buffer-live-p gnus-article-buffer)
1213 (with-current-buffer gnus-article-buffer
1214 gnus-article-charset))
1215 gnus-newsgroup-charset))
1216 (mail-parse-ignored-charsets
1217 gnus-newsgroup-ignored-charsets))
1218 (set-buffer gnus-original-article-buffer)
1219 (message-forward post)))))))
1221 (defun gnus-summary-resend-message (address n)
1222 "Resend the current article to ADDRESS."
1224 (list (message-read-from-minibuffer
1225 "Resend message(s) to: "
1226 (when (and gnus-summary-resend-default-address
1227 (gnus-buffer-live-p gnus-original-article-buffer))
1228 ;; If some other article is currently selected, the
1229 ;; initial-contents is wrong. Whatever, it is just the
1230 ;; initial-contents.
1231 (with-current-buffer gnus-original-article-buffer
1232 (nnmail-fetch-field "to"))))
1233 current-prefix-arg))
1234 (let ((articles (gnus-summary-work-articles n))
1236 (while (setq article (pop articles))
1237 (gnus-summary-select-article nil nil nil article)
1239 (set-buffer gnus-original-article-buffer)
1240 (message-resend address))
1241 (gnus-summary-mark-article-as-forwarded article))))
1243 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1244 (defun gnus-summary-resend-message-edit ()
1245 "Resend an article that has already been sent.
1246 A new buffer will be created to allow the user to modify body and
1247 contents of the message, and then, everything will happen as when
1248 composing a new message."
1250 (let ((article (gnus-summary-article-number)))
1251 (gnus-setup-message 'reply-yank
1252 (gnus-summary-select-article t)
1253 (set-buffer gnus-original-article-buffer)
1254 (let ((cur (current-buffer))
1255 (to (message-fetch-field "to")))
1256 ;; Get a normal message buffer.
1257 (message-pop-to-buffer (message-buffer-name "Resend" to))
1258 (insert-buffer-substring cur)
1260 (message-narrow-to-head-1)
1261 ;; Gnus will generate a new one when sending.
1262 (message-remove-header "Message-ID")
1263 (message-remove-header message-ignored-resent-headers t)
1264 ;; Remove unwanted headers.
1265 (goto-char (point-max))
1266 (insert mail-header-separator)
1267 (goto-char (point-min))
1268 (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1272 (defun gnus-summary-post-forward (&optional arg)
1273 "Forward the current article to a newsgroup.
1274 See `gnus-summary-mail-forward' for ARG."
1276 (gnus-summary-mail-forward arg t))
1278 (defvar gnus-nastygram-message
1279 "The following article was inappropriately posted to %s.\n\n"
1280 "Format string to insert in nastygrams.
1281 The current group name will be inserted at \"%s\".")
1283 (defun gnus-summary-mail-nastygram (n)
1284 "Send a nastygram to the author of the current article."
1286 (when (or gnus-expert-user
1288 "Really send a nastygram to the author of the current article? "))
1289 (let ((group gnus-newsgroup-name))
1290 (gnus-summary-reply-with-original n)
1291 (set-buffer gnus-message-buffer)
1293 (insert (format gnus-nastygram-message group))
1294 (message-send-and-exit))))
1296 (defun gnus-summary-mail-crosspost-complaint (n)
1297 "Send a complaint about crossposting to the current article(s)."
1299 (let ((articles (gnus-summary-work-articles n))
1301 (while (setq article (pop articles))
1302 (set-buffer gnus-summary-buffer)
1303 (gnus-summary-goto-subject article)
1304 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1305 newsgroups followup-to)
1306 (gnus-summary-select-article)
1307 (set-buffer gnus-original-article-buffer)
1308 (if (and (<= (length (message-tokenize-header
1310 (mail-fetch-field "newsgroups"))
1313 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1314 (not (member group (message-tokenize-header
1315 followup-to ", ")))))
1317 (gnus-message 1 "Followup-to restricted")
1318 (gnus-message 1 "Not a crossposted article"))
1319 (set-buffer gnus-summary-buffer)
1320 (gnus-summary-reply-with-original 1)
1321 (set-buffer gnus-message-buffer)
1323 (insert (format gnus-crosspost-complaint newsgroups group))
1324 (message-goto-subject)
1325 (re-search-forward " *$")
1326 (replace-match " (crosspost notification)" t t)
1327 (gnus-deactivate-mark)
1328 (when (gnus-y-or-n-p "Send this complaint? ")
1329 (message-send-and-exit)))))))
1331 (defun gnus-mail-parse-comma-list ()
1334 (skip-chars-forward " ")
1337 (skip-chars-forward "^,")
1342 (narrow-to-region beg (point))
1345 (while (search-forward "\"" nil t)
1349 (skip-chars-forward ",")
1350 (skip-chars-forward "^,"))
1351 (skip-chars-backward " ")
1352 (push (buffer-substring beg (point))
1354 (skip-chars-forward "^,")
1355 (skip-chars-forward ", "))
1358 (defun gnus-inews-add-to-address (group)
1359 (let ((to-address (mail-fetch-field "to")))
1360 (when (and to-address
1362 ;; This mail group doesn't have a `to-list', so we add one
1364 (when (gnus-y-or-n-p
1365 (format "Do you want to add this as `to-list': %s " to-address))
1366 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1368 (defun gnus-put-message ()
1369 "Put the current message in some group and return to Gnus."
1371 (let ((reply gnus-article-reply)
1372 (winconf gnus-prev-winconf)
1373 (group gnus-newsgroup-name))
1375 (not (gnus-group-read-only-p group)))
1376 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1378 (when (gnus-gethash group gnus-newsrc-hashtb)
1379 (error "No such group: %s" group))
1383 (message-narrow-to-headers)
1384 (let ((gnus-deletable-headers nil))
1385 (message-generate-headers
1386 (if (message-news-p)
1387 message-required-news-headers
1388 message-required-mail-headers)))
1389 (goto-char (point-max))
1390 (if (string-match " " group)
1391 (insert "Gcc: \"" group "\"\n")
1392 (insert "Gcc: " group "\n"))
1395 (when (and (get-buffer gnus-group-buffer)
1396 (gnus-buffer-exists-p (car-safe reply))
1398 (set-buffer (car reply))
1399 (gnus-summary-mark-article-as-replied (cdr reply)))
1401 (set-window-configuration winconf))))
1403 (defun gnus-article-mail (yank)
1404 "Send a reply to the address near point.
1405 If YANK is non-nil, include the original article."
1409 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1410 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1412 (gnus-msg-mail address)
1414 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1416 (defvar nntp-server-type)
1418 "Send a bug report to the Gnus maintainers."
1420 (unless (gnus-alive-p)
1421 (error "Gnus has been shut down"))
1422 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1423 (unless (message-mail-user-agent)
1424 (delete-other-windows)
1425 (when gnus-bug-create-help-buffer
1426 (switch-to-buffer "*Gnus Help Bug*")
1428 (insert gnus-bug-message)
1429 (goto-char (point-min)))
1430 (message-pop-to-buffer "*Gnus Bug*"))
1431 (let ((message-this-is-mail t))
1432 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1433 (when gnus-bug-create-help-buffer
1434 (push `(gnus-bug-kill-buffer) message-send-actions))
1435 (goto-char (point-min))
1436 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1438 (insert (gnus-version) "\n"
1439 (emacs-version) "\n")
1440 (when (and (boundp 'nntp-server-type)
1441 (stringp nntp-server-type))
1442 (insert nntp-server-type))
1443 (insert "\n\n\n\n\n")
1446 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1449 (setq text (buffer-string)))
1450 (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1451 (goto-char (point-min))
1452 (search-forward "Subject: " nil t)
1455 (defun gnus-bug-kill-buffer ()
1456 (when (get-buffer "*Gnus Help Bug*")
1457 (kill-buffer "*Gnus Help Bug*")))
1459 (defun gnus-summary-yank-message (buffer n)
1460 "Yank the current article into a composed message."
1462 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1463 current-prefix-arg))
1464 (gnus-summary-iterate n
1465 (let ((gnus-display-mime-function nil)
1466 (gnus-inhibit-treatment t))
1467 (gnus-summary-select-article))
1470 (message-yank-buffer gnus-article-buffer))))
1472 (defun gnus-debug ()
1473 "Attempts to go through the Gnus source file and report what variables have been changed.
1474 The source file has to be in the Emacs load path."
1476 (let ((files gnus-debug-files)
1478 file expr olist sym)
1479 (gnus-message 4 "Please wait while we snoop your variables...")
1481 ;; Go through all the files looking for non-default values for variables.
1483 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1486 (when (and (setq file (locate-library (pop files)))
1487 (file-exists-p file))
1488 (insert-file-contents file)
1489 (goto-char (point-min))
1490 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1491 (gnus-message 4 "Malformed sources in file %s" file)
1492 (narrow-to-region (point-min) (point))
1493 (goto-char (point-min))
1494 (while (setq expr (ignore-errors (read (current-buffer))))
1496 (and (or (eq (car expr) 'defvar)
1497 (eq (car expr) 'defcustom))
1498 (stringp (nth 3 expr))
1499 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1500 (or (not (boundp (nth 1 expr)))
1501 (not (equal (eval (nth 2 expr))
1502 (symbol-value (nth 1 expr)))))
1503 (push (nth 1 expr) olist)))))))
1504 (kill-buffer (current-buffer)))
1505 (when (setq olist (nreverse olist))
1506 (insert "------------------ Environment follows ------------------\n\n"))
1508 (if (boundp (car olist))
1510 (pp `(setq ,(car olist)
1511 ,(if (or (consp (setq sym (symbol-value (car olist))))
1513 (not (or (eq sym nil)
1515 (list 'quote (symbol-value (car olist)))
1516 (symbol-value (car olist))))
1518 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1519 (setq olist (cdr olist)))
1521 ;; Remove any control chars - they seem to cause trouble for some
1522 ;; mailers. (Byte-compiled output from the stuff above.)
1524 (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1525 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1528 ;;; Treatment of rejected articles.
1531 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1532 "Re-mail the current message.
1533 This only makes sense if the current message is a bounce message than
1534 contains some mail you have written which has been bounced back to
1536 If FETCH, try to fetch the article that this is a reply to, if indeed
1539 (gnus-summary-select-article t)
1540 (set-buffer gnus-original-article-buffer)
1541 (gnus-setup-message 'compose-bounce
1542 (let* ((references (mail-fetch-field "references"))
1543 (parent (and references (gnus-parent-id references))))
1545 ;; If there are references, we fetch the article we answered to.
1547 (gnus-summary-refer-article parent)
1548 (gnus-summary-show-all-headers)))))
1552 (defun gnus-inews-group-method (group)
1554 ;; If the group doesn't exist, we assume
1555 ;; it's an archive group...
1556 ((and (null (gnus-get-info group))
1557 (eq (car (gnus-server-to-method gnus-message-archive-method))
1558 (car (gnus-server-to-method (gnus-group-method group)))))
1559 gnus-message-archive-method)
1561 ((gnus-info-method (gnus-get-info group))
1562 (gnus-info-method (gnus-get-info group)))
1564 (t (gnus-server-to-method (gnus-group-method group)))))
1566 ;; Do Gcc handling, which copied the message over to some group.
1567 (defun gnus-inews-do-gcc (&optional gcc)
1571 (message-narrow-to-headers)
1572 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1573 (cur (current-buffer))
1574 groups group method group-art
1575 mml-externalize-attachments)
1577 (message-remove-header "gcc")
1579 (setq groups (message-unquote-tokens
1580 (message-tokenize-header gcc " ,")))
1581 ;; Copy the article over to some group(s).
1582 (while (setq group (pop groups))
1583 (unless (gnus-check-server
1584 (setq method (gnus-inews-group-method group)))
1585 (error "Can't open server %s" (if (stringp method) method
1587 (unless (gnus-request-group group nil method)
1588 (gnus-request-create-group group method))
1589 (setq mml-externalize-attachments
1590 (if (stringp gnus-gcc-externalize-attachments)
1591 (string-match gnus-gcc-externalize-attachments group)
1592 gnus-gcc-externalize-attachments))
1594 (nnheader-set-temp-buffer " *acc*")
1595 (insert-buffer-substring cur)
1596 (message-encode-message-body)
1598 (message-narrow-to-headers)
1599 (let* ((mail-parse-charset message-default-charset)
1600 (newsgroups-field (save-restriction
1601 (message-narrow-to-headers-or-head)
1602 (message-fetch-field "Newsgroups")))
1603 (followup-field (save-restriction
1604 (message-narrow-to-headers-or-head)
1605 (message-fetch-field "Followup-To")))
1606 ;; BUG: We really need to get the charset for
1607 ;; each name in the Newsgroups and Followup-To
1608 ;; lines to allow crossposting between group
1609 ;; namess with incompatible character sets.
1610 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1611 (group-field-charset
1612 (gnus-group-name-charset
1613 method (or newsgroups-field "")))
1614 (followup-field-charset
1615 (gnus-group-name-charset
1616 method (or followup-field "")))
1617 (rfc2047-header-encoding-alist
1619 (when group-field-charset
1620 (list (cons "Newsgroups" group-field-charset)))
1621 (when followup-field-charset
1622 (list (cons "Followup-To" followup-field-charset)))
1623 rfc2047-header-encoding-alist)))
1624 (mail-encode-encoded-word-buffer)))
1625 (goto-char (point-min))
1626 (when (re-search-forward
1627 (concat "^" (regexp-quote mail-header-separator) "$")
1629 (replace-match "" t t ))
1630 (unless (setq group-art
1631 (gnus-request-accept-article group method t t))
1632 (gnus-message 1 "Couldn't store article in group %s: %s"
1633 group (gnus-status-message method))
1635 (when (and group-art
1637 (or gnus-gcc-mark-as-read
1638 gnus-inews-mark-gcc-as-read))
1639 (gnus-group-mark-article-read group (cdr group-art)))
1640 (kill-buffer (current-buffer)))))))))
1642 (defun gnus-inews-insert-gcc ()
1643 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1646 (message-narrow-to-headers)
1647 (let* ((group gnus-outgoing-message-group)
1649 ((gnus-functionp group)
1651 ((or (stringp group) (list group))
1656 (if (string-match " " gcc)
1657 (concat "\"" gcc "\"")
1659 (mapconcat (lambda (group)
1660 (if (string-match " " group)
1661 (concat "\"" group "\"")
1666 (defun gnus-inews-insert-archive-gcc (&optional group)
1667 "Insert the Gcc to say where the article is to be archived."
1668 (let* ((var gnus-message-archive-group)
1669 (group (or group gnus-newsgroup-name ""))
1671 (and gnus-newsgroup-name
1672 (not (equal gnus-newsgroup-name ""))
1673 (gnus-group-find-parameter
1674 gnus-newsgroup-name 'gcc-self)))
1678 ((null gnus-message-archive-method)
1682 ;; Just a single group.
1685 ;; We don't want this.
1687 ((and (listp var) (stringp (car var)))
1688 ;; A list of groups.
1690 ((gnus-functionp var)
1692 (funcall var group))
1694 ;; An alist of regexps/functions/forms.
1699 ((stringp (caar var))
1701 (when (string-match (caar var) group)
1703 ((gnus-functionp (car var))
1705 (funcall (car var) group))
1707 (eval (car var)))))))
1708 (setq var (cdr var)))
1711 (when (or groups gcc-self-val)
1712 (when (stringp groups)
1713 (setq groups (list groups)))
1716 (message-narrow-to-headers)
1717 (goto-char (point-max))
1720 ;; Use the `gcc-self' param value instead.
1723 (if (stringp gcc-self-val)
1724 (if (string-match " " gcc-self-val)
1725 (concat "\"" gcc-self-val "\"")
1727 (if (string-match " " group)
1728 (concat "\"" group "\"")
1730 (if (not (eq gcc-self-val 'none))
1735 ;; Use the list of groups.
1736 (while (setq name (pop groups))
1737 (let ((str (if (string-match ":" name)
1739 (gnus-group-prefixed-name
1740 name gnus-message-archive-method))))
1741 (insert (if (string-match " " str)
1742 (concat "\"" str "\"")
1750 (defun gnus-configure-posting-styles (&optional group-name)
1751 "Configure posting styles according to `gnus-posting-styles'."
1752 (unless gnus-inhibit-posting-styles
1753 (let ((group (or group-name gnus-newsgroup-name ""))
1754 (styles gnus-posting-styles)
1755 style match variable attribute value v results
1756 filep name address element)
1757 ;; If the group has a posting-style parameter, add it at the end with a
1758 ;; regexp matching everything, to be sure it takes precedence over all
1760 (when gnus-newsgroup-name
1761 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1763 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1764 ;; Go through all styles and look for matches.
1765 (dolist (style styles)
1766 (setq match (pop style))
1767 (goto-char (point-min))
1770 ;; Regexp string match on the group name.
1771 (string-match match group))
1773 ;; Obsolete format of header match.
1774 (and (gnus-buffer-live-p gnus-article-copy)
1775 (with-current-buffer gnus-article-copy
1776 (let ((header (message-fetch-field (pop style))))
1778 (string-match (pop style) header))))))
1779 ((or (symbolp match)
1780 (gnus-functionp match))
1782 ((gnus-functionp match)
1783 ;; Function to be called.
1786 ;; Variable to be checked.
1787 (symbol-value match))))
1790 ((eq (car match) 'header)
1791 ;; New format of header match.
1792 (and (gnus-buffer-live-p gnus-article-copy)
1793 (with-current-buffer gnus-article-copy
1794 (let ((header (message-fetch-field (nth 1 match))))
1796 (string-match (nth 2 match) header))))))
1798 ;; This is a form to be evaled.
1800 ;; We have a match, so we set the variables.
1801 (dolist (attribute style)
1802 (setq element (pop attribute)
1807 ((eq (car attribute) :file)
1810 ((eq (car attribute) :value)
1814 ;; We get the value.
1819 ((or (symbolp value)
1820 (gnus-functionp value))
1821 (cond ((gnus-functionp value)
1824 (symbol-value value))))
1827 ;; Translate obsolescent value.
1829 ((eq element 'signature-file)
1830 (setq element 'signature
1832 ((eq element 'x-face-file)
1833 (setq element 'x-face
1835 ;; Get the contents of file elems.
1837 (setq v (with-temp-buffer
1838 (insert-file-contents v)
1839 (goto-char (point-max))
1843 (setq results (delq (assoc element results) results))
1844 (push (cons element v) results))))
1845 ;; Now we have all the styles, so we insert them.
1846 (setq name (assq 'name results)
1847 address (assq 'address results))
1848 (setq results (delq name (delq address results)))
1849 ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1850 (make-local-hook 'message-setup-hook)
1851 (setq results (sort results (lambda (x y)
1852 (string-lessp (car x) (car y)))))
1853 (dolist (result results)
1854 (add-hook 'message-setup-hook
1856 ((eq 'eval (car result))
1858 ((eq 'body (car result))
1862 (insert ,(cdr result)))))
1863 ((eq 'signature (car result))
1864 (set (make-local-variable 'message-signature) nil)
1865 (set (make-local-variable 'message-signature-file) nil)
1866 (if (not (cdr result))
1870 (let ((message-signature ,(cdr result)))
1871 (when message-signature
1872 (message-insert-signature)))))))
1875 (if (symbolp (car result))
1876 (capitalize (symbol-name (car result)))
1880 (message-remove-header ,header)
1881 (let ((value ,(cdr result)))
1884 (insert ,header ": " value)
1886 (insert "\n")))))))))
1888 (when (or name address)
1889 (add-hook 'message-setup-hook
1891 (set (make-local-variable 'user-mail-address)
1892 ,(or (cdr address) user-mail-address))
1893 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1895 ,(or (cdr address) user-mail-address)))
1897 (message-remove-header "From")
1899 (insert "From: " (message-make-from) "\n"))))
1902 ;;; Allow redefinition of functions.
1908 ;;; gnus-msg.el ends here