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 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 (and (not (featurep 'xemacs))
294 ;; gnus-treat-highlight-citation ;; gnus-cite dependency
295 (fboundp 'font-lock-add-keywords))
296 "Enable highlighting of different citation levels in message-mode."
297 :version "23.0" ;; No Gnus
302 (unless (featurep 'xemacs)
303 (autoload 'gnus-message-citation-mode "gnus-cite" nil t))
305 ;;; Internal variables.
307 (defvar gnus-inhibit-posting-styles nil
308 "Inhibit the use of posting styles.")
310 (defvar gnus-article-yanked-articles nil)
311 (defvar gnus-message-buffer "*Mail Gnus*")
312 (defvar gnus-article-copy nil)
313 (defvar gnus-check-before-posting nil)
314 (defvar gnus-last-posting-server nil)
315 (defvar gnus-message-group-art nil)
317 (defvar gnus-msg-force-broken-reply-to nil)
319 (defconst gnus-bug-message
320 "Sending a bug report to the Gnus Towers.
321 ========================================
323 The buffer below is a mail buffer. When you press `C-c C-c', it will
324 be sent to the Gnus Bug Exterminators.
326 The thing near the bottom of the buffer is how the environment
327 settings will be included in the mail. Please do not delete that.
328 They will tell the Bug People what your environment is, so that it
329 will be easier to locate the bugs.
331 If you have found a bug that makes Emacs go \"beep\", set
332 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
333 and include the backtrace in your bug report.
335 Please describe the bug in annoying, painstaking detail.
337 Thank you for your help in stamping out bugs.
341 (autoload 'gnus-uu-post-news "gnus-uu" nil t))
345 ;;; Gnus Posting Functions
348 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
349 "p" gnus-summary-post-news
350 "i" gnus-summary-news-other-window
351 "f" gnus-summary-followup
352 "F" gnus-summary-followup-with-original
353 "c" gnus-summary-cancel-article
354 "s" gnus-summary-supersede-article
355 "r" gnus-summary-reply
356 "y" gnus-summary-yank-message
357 "R" gnus-summary-reply-with-original
358 "w" gnus-summary-wide-reply
359 "W" gnus-summary-wide-reply-with-original
360 "v" gnus-summary-very-wide-reply
361 "V" gnus-summary-very-wide-reply-with-original
362 "n" gnus-summary-followup-to-mail
363 "N" gnus-summary-followup-to-mail-with-original
364 "m" gnus-summary-mail-other-window
365 "u" gnus-uu-post-news
366 "\M-c" gnus-summary-mail-crosspost-complaint
367 "Br" gnus-summary-reply-broken-reply-to
368 "BR" gnus-summary-reply-broken-reply-to-with-original
369 "om" gnus-summary-mail-forward
370 "op" gnus-summary-post-forward
371 "Om" gnus-uu-digest-mail-forward
372 "Op" gnus-uu-digest-post-forward)
374 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
375 "b" gnus-summary-resend-bounced-mail
376 ;; "c" gnus-summary-send-draft
377 "r" gnus-summary-resend-message
378 "e" gnus-summary-resend-message-edit)
380 ;;; Internal functions.
382 (defun gnus-inews-make-draft (articles)
384 (gnus-inews-make-draft-meta-information
385 ,gnus-newsgroup-name ',articles)))
387 (defvar gnus-article-reply nil)
388 (defmacro gnus-setup-message (config &rest forms)
389 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
390 (buffer (make-symbol "gnus-setup-message-buffer"))
391 (article (make-symbol "gnus-setup-message-article"))
392 (yanked (make-symbol "gnus-setup-yanked-articles"))
393 (group (make-symbol "gnus-setup-message-group")))
394 `(let ((,winconf (current-window-configuration))
395 (,buffer (buffer-name (current-buffer)))
396 (,article gnus-article-reply)
397 (,yanked gnus-article-yanked-articles)
398 (,group gnus-newsgroup-name)
399 (message-header-setup-hook
400 (copy-sequence message-header-setup-hook))
401 (mbl mml-buffer-list)
402 (message-mode-hook (copy-sequence message-mode-hook)))
403 (setq mml-buffer-list nil)
404 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
405 (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
406 ;; #### FIXME: for a reason that I did not manage to identify yet,
407 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
408 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
409 ;; After evaluation of @forms below, it gets the value we actually want
410 ;; to override, and the posting styles are used. For that reason, I've
411 ;; added an optional argument to `gnus-configure-posting-styles' to
412 ;; make sure that the correct value for the group name is used. -- drv
413 (add-hook 'message-mode-hook
414 (if (memq ,config '(reply-yank reply))
416 (gnus-configure-posting-styles ,group))
418 ;; There may be an old " *gnus article copy*" buffer.
419 (let (gnus-article-copy)
420 (gnus-configure-posting-styles ,group)))))
421 (gnus-pull ',(intern gnus-draft-meta-information-header)
422 message-required-headers)
424 (not (string= ,group "")))
426 (intern gnus-draft-meta-information-header)
427 (gnus-inews-make-draft (or ,yanked ,article)))
428 message-required-headers))
432 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
434 (setq gnus-message-buffer (current-buffer))
435 (set (make-local-variable 'gnus-message-group-art)
436 (cons ,group ,article))
437 (set (make-local-variable 'gnus-newsgroup-name) ,group)
438 ;; Enable highlighting of different citation levels
439 (when gnus-message-highlight-citation
440 (gnus-message-citation-mode 1))
441 (gnus-run-hooks 'gnus-message-setup-hook)
442 (if (eq major-mode 'message-mode)
443 (let ((mbl1 mml-buffer-list))
444 (setq mml-buffer-list mbl) ;; Global value
445 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
446 (gnus-make-local-hook 'kill-buffer-hook)
447 (gnus-make-local-hook 'change-major-mode-hook)
448 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
449 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
450 (mml-destroy-buffers)
451 (setq mml-buffer-list mbl)))
452 (message-hide-headers)
454 (gnus-configure-windows ,config t)
455 (run-hooks 'post-command-hook)
456 (set-buffer-modified-p nil))))
458 (defun gnus-inews-make-draft-meta-information (group articles)
459 (when (numberp articles)
460 (setq articles (list articles)))
461 (concat "(\"" group "\""
475 (defun gnus-msg-mail (&optional to subject other-headers continue
476 switch-action yank-action send-actions)
477 "Start editing a mail message to be sent.
478 Like `message-mail', but with Gnus paraphernalia, particularly the
479 Gcc: header for archiving purposes."
481 (let ((buf (current-buffer))
483 (gnus-setup-message 'message
484 (message-mail to subject other-headers continue
485 nil yank-action send-actions))
487 (setq mail-buf (current-buffer))
488 (switch-to-buffer buf)
489 (apply switch-action mail-buf nil)))
490 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
494 (defun gnus-button-mailto (address)
496 (set-buffer (gnus-copy-article-buffer))
497 (gnus-setup-message 'message
498 (message-reply address)))
501 (defun gnus-button-reply (&optional to-address wide)
502 "Like `message-reply'."
504 (gnus-setup-message 'message
505 (message-reply to-address wide)))
508 (define-mail-user-agent 'gnus-user-agent
509 'gnus-msg-mail 'message-send-and-exit
510 'message-kill-buffer 'message-send-hook)
512 (defun gnus-setup-posting-charset (group)
513 (let ((alist gnus-group-posting-charset-alist)
514 (group (or group ""))
518 (while (setq elem (pop alist))
519 (when (or (and (stringp (car elem))
520 (string-match (car elem) group))
521 (and (functionp (car elem))
522 (funcall (car elem) group))
523 (and (symbolp (car elem))
524 (symbol-value (car elem))))
525 (throw 'found (cons (cadr elem) (caddr elem)))))))))
527 (defun gnus-inews-add-send-actions (winconf buffer article
528 &optional config yanked)
529 (gnus-make-local-hook 'message-sent-hook)
530 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
531 'gnus-inews-do-gcc) nil t)
533 (gnus-make-local-hook 'message-header-hook)
534 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
535 (setq message-post-method
536 `(lambda (&optional arg)
537 (gnus-post-method arg ,gnus-newsgroup-name)))
538 (setq message-newsreader (setq message-mailer (gnus-extended-version)))
540 `(when (gnus-buffer-exists-p ,buffer)
541 (set-window-configuration ,winconf))
542 'exit 'postpone 'kill)
543 (let ((to-be-marked (cond
546 (lambda (x) (if (listp x) (car x) x)) yanked))
547 (article (if (listp article) article (list article)))
550 `(when (gnus-buffer-exists-p ,buffer)
554 (if (eq config 'forward)
555 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
556 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
559 (put 'gnus-setup-message 'lisp-indent-function 1)
560 (put 'gnus-setup-message 'edebug-form-spec '(form body))
562 ;;; Post news commands of Gnus group mode and summary mode
564 (defun gnus-group-mail (&optional arg)
565 "Start composing a mail.
566 If ARG, use the group under the point to find a posting style.
567 If ARG is 1, prompt for a group name to find the posting style."
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 posting style of 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 (message-mail)))
589 (setq gnus-newsgroup-name group)))))
591 (defun gnus-group-news (&optional arg)
592 "Start composing a news.
593 If ARG, post to group under point.
594 If ARG is 1, prompt for group name to post to.
596 This function prepares a news even when using mail groups. This is useful
597 for posting messages to mail groups without actually sending them over the
598 network. The corresponding back end must have a 'request-post method."
600 ;; We can't `let' gnus-newsgroup-name here, since that leads
601 ;; to local variables leaking.
602 (let ((group gnus-newsgroup-name)
603 ;; make sure last viewed article doesn't affect posting styles:
605 (buffer (current-buffer)))
608 (setq gnus-newsgroup-name
610 (if (= 1 (prefix-numeric-value arg))
611 (completing-read "Use group: "
612 gnus-active-hashtb nil
613 (gnus-read-active-file-p))
614 (gnus-group-group-name))
616 ;; #### see comment in gnus-setup-message -- drv
617 (gnus-setup-message 'message
618 (message-news (gnus-group-real-name gnus-newsgroup-name))))
621 (setq gnus-newsgroup-name group)))))
623 (defun gnus-group-post-news (&optional arg)
624 "Start composing a message (a news by default).
625 If ARG, post to group under point. If ARG is 1, prompt for group name.
626 Depending on the selected group, the message might be either a mail or
629 ;; Bind this variable here to make message mode hooks work ok.
630 (let ((gnus-newsgroup-name
632 (if (= 1 (prefix-numeric-value arg))
633 (completing-read "Newsgroup: " gnus-active-hashtb nil
634 (gnus-read-active-file-p))
635 (gnus-group-group-name))
637 ;; make sure last viewed article doesn't affect posting styles:
639 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
640 (string= gnus-newsgroup-name ""))))
642 (defun gnus-summary-mail-other-window (&optional arg)
643 "Start composing a mail in another window.
644 Use the posting of the current group by default.
645 If ARG, don't do that. If ARG is 1, prompt for group name to find the
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 (message-mail)))
668 (setq gnus-newsgroup-name group)))))
670 (defun gnus-summary-news-other-window (&optional arg)
671 "Start composing a news in another window.
672 Post to the current group by default.
673 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
675 This function prepares a news even when using mail groups. This is useful
676 for posting messages to mail groups without actually sending them over the
677 network. The corresponding back end must have a 'request-post method."
679 ;; We can't `let' gnus-newsgroup-name here, since that leads
680 ;; to local variables leaking.
681 (let ((group gnus-newsgroup-name)
682 ;; make sure last viewed article doesn't affect posting styles:
684 (buffer (current-buffer)))
687 (setq gnus-newsgroup-name
689 (if (= 1 (prefix-numeric-value arg))
690 (completing-read "Use group: "
691 gnus-active-hashtb nil
692 (gnus-read-active-file-p))
694 gnus-newsgroup-name))
695 ;; #### see comment in gnus-setup-message -- drv
696 (gnus-setup-message 'message
698 (message-news (gnus-group-real-name gnus-newsgroup-name))
699 (set (make-local-variable 'gnus-discouraged-post-methods)
701 (car (gnus-find-method-for-group gnus-newsgroup-name))
702 gnus-discouraged-post-methods)))))
705 (setq gnus-newsgroup-name group)))))
707 (defun gnus-summary-post-news (&optional arg)
708 "Start composing a message. Post to the current group by default.
709 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
710 Depending on the selected group, the message might be either a mail or
713 ;; Bind this variable here to make message mode hooks work ok.
714 (let ((gnus-newsgroup-name
716 (if (= 1 (prefix-numeric-value arg))
717 (completing-read "Newsgroup: " gnus-active-hashtb nil
718 (gnus-read-active-file-p))
720 gnus-newsgroup-name))
721 ;; make sure last viewed article doesn't affect posting styles:
723 (gnus-post-news 'post gnus-newsgroup-name)))
726 (defun gnus-summary-followup (yank &optional force-news)
727 "Compose a followup to an article.
728 If prefix argument YANK is non-nil, the original article is yanked
730 YANK is a list of elements, where the car of each element is the
731 article number, and the cdr is the string to be yanked."
733 (list (and current-prefix-arg
734 (gnus-summary-work-articles 1))))
736 (gnus-summary-goto-subject
737 (if (listp (car yank))
740 (save-window-excursion
741 (gnus-summary-select-article))
742 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
743 (gnus-newsgroup-name gnus-newsgroup-name))
745 (gnus-post-news nil gnus-newsgroup-name
746 headers gnus-article-buffer
748 (gnus-summary-handle-replysign)))
750 (defun gnus-summary-followup-with-original (n &optional force-news)
751 "Compose a followup to an article and include the original article.
752 The text in the region will be yanked. If the region isn't
753 active, the entire article will be yanked."
755 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
757 (defun gnus-summary-followup-to-mail (&optional arg)
758 "Followup to the current mail message via news."
760 (list (and current-prefix-arg
761 (gnus-summary-work-articles 1))))
762 (gnus-summary-followup arg t))
764 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
765 "Followup to the current mail message via news."
767 (gnus-summary-followup (gnus-summary-work-articles arg) t))
769 (defun gnus-inews-yank-articles (articles)
770 (let (beg article yank-string)
772 (while (setq article (pop articles))
773 (when (listp article)
774 (setq yank-string (nth 1 article)
775 article (nth 0 article)))
776 (save-window-excursion
777 (set-buffer gnus-summary-buffer)
778 (gnus-summary-select-article nil nil nil article)
779 (gnus-summary-remove-process-mark article))
780 (gnus-copy-article-buffer nil yank-string)
781 (let ((message-reply-buffer gnus-article-copy)
782 (message-reply-headers
783 ;; The headers are decoded.
784 (with-current-buffer gnus-article-copy
786 (nnheader-narrow-to-headers)
787 (nnheader-parse-naked-head)))))
788 (message-yank-original)
789 (setq beg (or beg (mark t))))
795 (defun gnus-summary-cancel-article (&optional n symp)
796 "Cancel an article you posted.
797 Uses the process-prefix convention. If given the symbolic
798 prefix `a', cancel using the standard posting method; if not
799 post using the current select method."
800 (interactive (gnus-interactive "P\ny"))
801 (let ((message-post-method
803 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
804 (dolist (article (gnus-summary-work-articles n))
805 (when (gnus-summary-select-article t nil nil article)
806 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
807 (message-cancel-news))
808 (gnus-summary-mark-as-read article gnus-canceled-mark)
809 (gnus-cache-remove-article 1))
810 (gnus-article-hide-headers-if-wanted))
811 (gnus-summary-remove-process-mark article))))
813 (defun gnus-summary-supersede-article ()
814 "Compose an article that will supersede a previous article.
815 This is done simply by taking the old article and adding a Supersedes
816 header line with the old Message-ID."
818 (let ((article (gnus-summary-article-number)))
819 (gnus-setup-message 'reply-yank
820 (gnus-summary-select-article t)
821 (set-buffer gnus-original-article-buffer)
825 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
827 (set-buffer ,gnus-summary-buffer)
828 (gnus-cache-possibly-remove-article ,article nil nil nil t)
829 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
830 message-send-actions))))
834 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
835 ;; make a copy of the article buffer with all text properties removed
836 ;; this copy is in the buffer gnus-article-copy.
837 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
838 ;; this buffer should be passed to all mail/news reply/post routines.
839 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
841 (set-buffer gnus-article-copy)
842 (mm-enable-multibyte))
843 (let ((article-buffer (or article-buffer gnus-article-buffer))
845 (if (not (and (get-buffer article-buffer)
846 (gnus-buffer-exists-p article-buffer)))
847 (error "Can't find any article buffer")
849 (set-buffer article-buffer)
850 (let ((gnus-newsgroup-charset (or gnus-article-charset
851 gnus-newsgroup-charset))
852 (gnus-newsgroup-ignored-charsets
853 (or gnus-article-ignored-charsets
854 gnus-newsgroup-ignored-charsets)))
856 ;; Copy over the (displayed) article buffer, delete
857 ;; hidden text and remove text properties.
859 (copy-to-buffer gnus-article-copy (point-min) (point-max))
860 (set-buffer gnus-article-copy)
863 (delete-region (point) (point-max))
864 (insert yank-string))
865 (gnus-article-delete-text-of-type 'annotation)
866 (gnus-article-delete-text-of-type 'multipart)
867 (gnus-remove-text-with-property 'gnus-prev)
868 (gnus-remove-text-with-property 'gnus-next)
869 (gnus-remove-text-with-property 'gnus-decoration)
872 (buffer-substring-no-properties (point-min) (point-max))
874 ;; Find the original headers.
875 (set-buffer gnus-original-article-buffer)
876 (goto-char (point-min))
877 (while (looking-at message-unix-mail-delimiter)
879 (let ((mail-header-separator ""))
881 end (or (message-goto-body)
882 ;; There may be just a header.
884 ;; Delete the headers from the displayed articles.
885 (set-buffer gnus-article-copy)
886 (let ((mail-header-separator ""))
887 (delete-region (goto-char (point-min))
888 (or (message-goto-body) (point-max))))
889 ;; Insert the original article headers.
890 (insert-buffer-substring gnus-original-article-buffer beg end)
892 (let ((gnus-article-decode-hook
893 (delq 'article-decode-charset
894 (copy-sequence gnus-article-decode-hook)))
895 (rfc2047-quote-decoded-words-containing-tspecials t))
896 (run-hooks 'gnus-article-decode-hook)))))
899 (defun gnus-post-news (post &optional group header article-buffer yank subject
902 (gnus-copy-article-buffer))
903 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
904 (gnus-article-yanked-articles yank)
905 (add-to-list gnus-add-to-list))
906 (gnus-setup-message (cond (yank 'reply-yank)
907 (article-buffer 'reply)
909 (let* ((group (or group gnus-newsgroup-name))
910 (charset (gnus-group-name-charset nil group))
912 to-address to-group mailing-list to-list
915 (setq to-address (gnus-parameter-to-address group)
916 to-group (gnus-group-find-parameter group 'to-group)
917 to-list (gnus-parameter-to-list group)
918 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
919 mailing-list (when gnus-mailing-list-groups
920 (string-match gnus-mailing-list-groups group))
921 group (gnus-group-name-decode (gnus-group-real-name group)
923 (if (or (and to-group
924 (gnus-news-group-p to-group))
927 (and (gnus-news-group-p
928 (or pgroup gnus-newsgroup-name)
929 (or header gnus-current-article))
937 (and (not (gnus-virtual-group-p pgroup)) group)))
938 (set-buffer gnus-article-copy)
939 (gnus-msg-treat-broken-reply-to)
940 (message-followup (if (or newsgroup-p force-news)
941 (if (save-restriction
942 (article-narrow-to-head)
943 (message-fetch-field "newsgroups"))
950 (message-mail (or to-address to-list))
951 ;; Arrange for mail groups that have no `to-address' to
952 ;; get that when the user sends off the mail.
953 (when (and (not to-list)
956 (push (list 'gnus-inews-add-to-address pgroup)
957 message-send-actions)))
958 (set-buffer gnus-article-copy)
959 (gnus-msg-treat-broken-reply-to)
960 (message-wide-reply to-address)))
962 (gnus-inews-yank-articles yank))))))
964 (defun gnus-msg-treat-broken-reply-to (&optional force)
965 "Remove the Reply-to header if broken-reply-to."
967 (gnus-group-find-parameter
968 gnus-newsgroup-name 'broken-reply-to))
970 (message-narrow-to-head)
971 (message-remove-header "reply-to"))))
973 (defun gnus-post-method (arg group &optional silent)
974 "Return the posting method based on GROUP and ARG.
975 If SILENT, don't prompt the user."
976 (let ((gnus-post-method (or (gnus-parameter-post-method group)
978 (group-method (gnus-find-method-for-group group)))
980 ;; If the group-method is nil (which shouldn't happen) we use
981 ;; the default method.
983 (or (and (listp gnus-post-method) ;If not current/native/nil
984 (not (listp (car gnus-post-method))) ; and not a list of methods
985 gnus-post-method) ;then use it.
987 message-post-method))
988 ;; We want the inverse of the default
989 ((and arg (not (eq arg 0)))
990 (if (eq gnus-post-method 'current)
993 ;; We query the user for a post method.
995 (and (listp gnus-post-method)
996 (listp (car gnus-post-method))))
998 ;; Collect all methods we know about.
1000 (when (listp gnus-post-method)
1001 (if (listp (car gnus-post-method))
1003 (list gnus-post-method)))
1004 gnus-secondary-select-methods
1005 (mapcar 'cdr gnus-server-alist)
1006 (mapcar 'car gnus-opened-servers)
1007 (list gnus-select-method)
1008 (list group-method)))
1009 method-alist post-methods method)
1010 ;; Weed out all mail methods.
1012 (setq method (gnus-server-get-method "" (pop methods)))
1013 (when (and (or (gnus-method-option-p method 'post)
1014 (gnus-method-option-p method 'post-mail))
1015 (not (member method post-methods)))
1016 (push method post-methods)))
1017 ;; Create a name-method alist.
1021 (if (equal (cadr m) "")
1022 (list (symbol-name (car m)) m)
1023 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1028 (setq gnus-last-posting-server
1030 gnus-last-posting-server)
1031 ;; Just use the last value.
1032 gnus-last-posting-server
1034 "Posting method: " method-alist nil t
1035 (cons (or gnus-last-posting-server "") 0))))
1037 ;; Override normal method.
1038 ((and (eq gnus-post-method 'current)
1039 (not (memq (car group-method) gnus-discouraged-post-methods))
1040 (gnus-get-function group-method 'request-post t))
1043 ;; Use gnus-post-method.
1044 ((listp gnus-post-method) ;A method...
1045 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1047 ;; Use the normal select method (nil or native).
1048 (t gnus-select-method))))
1052 (defun gnus-extended-version ()
1053 "Stringified Gnus version and Emacs version.
1054 See the variable `gnus-user-agent'."
1056 (if (stringp gnus-user-agent)
1058 ;; `gnus-user-agent' is a list:
1059 (let* ((float-output-format nil)
1061 (when (memq 'gnus gnus-user-agent)
1063 (prin1-to-string (gnus-continuum-version gnus-version) t)
1064 " (" gnus-version ")")))
1065 (emacs-v (gnus-emacs-version)))
1066 (concat gnus-v (when (and gnus-v emacs-v) " ")
1071 ;;; Gnus Mail Functions
1074 ;;; Mail reply commands of Gnus summary mode
1076 (defun gnus-summary-reply (&optional yank wide very-wide)
1077 "Start composing a mail reply to the current message.
1078 If prefix argument YANK is non-nil, the original article is yanked
1080 If WIDE, make a wide reply.
1081 If VERY-WIDE, make a very wide reply."
1083 (list (and current-prefix-arg
1084 (gnus-summary-work-articles 1))))
1085 ;; Allow user to require confirmation before replying by mail to the
1086 ;; author of a news article (or mail message).
1088 (not (or (gnus-news-group-p gnus-newsgroup-name)
1089 gnus-confirm-treat-mail-like-news))
1090 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1091 (string-match gnus-confirm-mail-reply-to-news
1092 gnus-newsgroup-name))
1093 ((functionp gnus-confirm-mail-reply-to-news)
1094 (funcall gnus-confirm-mail-reply-to-news gnus-newsgroup-name))
1095 (t gnus-confirm-mail-reply-to-news)))
1096 (y-or-n-p "Really reply by mail to article author? "))
1098 (if (listp (car yank))
1101 (gnus-article-reply (or article (gnus-summary-article-number)))
1102 (gnus-article-yanked-articles yank)
1104 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1106 (gnus-summary-goto-subject article))
1107 (gnus-setup-message (if yank 'reply-yank 'reply)
1109 (gnus-summary-select-article)
1110 (dolist (article very-wide)
1111 (gnus-summary-select-article nil nil nil article)
1113 (set-buffer (gnus-copy-article-buffer))
1114 (gnus-msg-treat-broken-reply-to)
1116 (message-narrow-to-head)
1117 (setq headers (concat headers (buffer-string)))))))
1118 (set-buffer (gnus-copy-article-buffer))
1119 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1121 (message-narrow-to-head)
1125 (goto-char (point-max)))
1126 (mml-quote-region (point) (point-max))
1127 (message-reply nil wide)
1129 (gnus-inews-yank-articles yank))
1130 (gnus-summary-handle-replysign)))))
1132 (defun gnus-summary-handle-replysign ()
1133 "Check the various replysign variables and take action accordingly."
1134 (when (or gnus-message-replysign gnus-message-replyencrypt)
1135 (let (signed encrypted)
1137 (set-buffer gnus-article-buffer)
1138 (setq signed (memq 'signed gnus-article-wash-types))
1139 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1140 (cond ((and gnus-message-replyencrypt encrypted)
1141 (mml-secure-message mml-default-encrypt-method
1142 (if gnus-message-replysignencrypted
1145 ((and gnus-message-replysign signed)
1146 (mml-secure-message mml-default-sign-method 'sign))))))
1148 (defun gnus-summary-reply-with-original (n &optional wide)
1149 "Start composing a reply mail to the current message.
1150 The original article will be yanked."
1152 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1154 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1155 "Like `gnus-summary-reply' except removing reply-to field.
1156 If prefix argument YANK is non-nil, the original article is yanked
1158 If WIDE, make a wide reply.
1159 If VERY-WIDE, make a very wide reply."
1161 (list (and current-prefix-arg
1162 (gnus-summary-work-articles 1))))
1163 (let ((gnus-msg-force-broken-reply-to t))
1164 (gnus-summary-reply yank wide very-wide)))
1166 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1167 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1168 The original article will be yanked."
1170 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1172 (defun gnus-summary-wide-reply (&optional yank)
1173 "Start composing a wide reply mail to the current message.
1174 If prefix argument YANK is non-nil, the original article is yanked
1177 (list (and current-prefix-arg
1178 (gnus-summary-work-articles 1))))
1179 (gnus-summary-reply yank t))
1181 (defun gnus-summary-wide-reply-with-original (n)
1182 "Start composing a wide reply mail to the current message.
1183 The original article will be yanked.
1184 Uses the process/prefix convention."
1186 (gnus-summary-reply-with-original n t))
1188 (defun gnus-summary-very-wide-reply (&optional yank)
1189 "Start composing a very wide reply mail to the current message.
1190 If prefix argument YANK is non-nil, the original article is yanked
1193 (list (and current-prefix-arg
1194 (gnus-summary-work-articles 1))))
1195 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1197 (defun gnus-summary-very-wide-reply-with-original (n)
1198 "Start composing a very wide reply mail to the current message.
1199 The original article will be yanked."
1202 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1204 (defun gnus-summary-mail-forward (&optional arg post)
1205 "Forward the current message(s) to another user.
1206 If process marks exist, forward all marked messages;
1207 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1208 if ARG is 1, decode the message and forward directly inline;
1209 if ARG is 2, forward message as an rfc822 MIME section;
1210 if ARG is 3, decode message and forward as an rfc822 MIME section;
1211 if ARG is 4, forward message directly inline;
1212 otherwise, use flipped `message-forward-as-mime'.
1213 If POST, post instead of mail.
1214 For the `inline' alternatives, also see the variable
1215 `message-forward-ignored-headers'."
1217 (if (cdr (gnus-summary-work-articles nil))
1218 ;; Process marks are given.
1219 (gnus-uu-digest-mail-forward arg post)
1220 ;; No process marks.
1221 (let ((message-forward-as-mime message-forward-as-mime)
1222 (message-forward-show-mml message-forward-show-mml))
1226 (setq message-forward-as-mime nil
1227 message-forward-show-mml t))
1229 (setq message-forward-as-mime t
1230 message-forward-show-mml nil))
1232 (setq message-forward-as-mime t
1233 message-forward-show-mml t))
1235 (setq message-forward-as-mime nil
1236 message-forward-show-mml nil))
1238 (setq message-forward-as-mime (not message-forward-as-mime))))
1239 (let* ((gnus-article-reply (gnus-summary-article-number))
1240 (gnus-article-yanked-articles (list gnus-article-reply)))
1241 (gnus-setup-message 'forward
1242 (gnus-summary-select-article)
1243 (let ((mail-parse-charset
1244 (or (and (gnus-buffer-live-p gnus-article-buffer)
1245 (with-current-buffer gnus-article-buffer
1246 gnus-article-charset))
1247 gnus-newsgroup-charset))
1248 (mail-parse-ignored-charsets
1249 gnus-newsgroup-ignored-charsets))
1250 (set-buffer gnus-original-article-buffer)
1251 (message-forward post)))))))
1253 (defun gnus-summary-resend-message (address n)
1254 "Resend the current article to ADDRESS."
1256 (list (message-read-from-minibuffer
1257 "Resend message(s) to: "
1258 (when (and gnus-summary-resend-default-address
1259 (gnus-buffer-live-p gnus-original-article-buffer))
1260 ;; If some other article is currently selected, the
1261 ;; initial-contents is wrong. Whatever, it is just the
1262 ;; initial-contents.
1263 (with-current-buffer gnus-original-article-buffer
1264 (nnmail-fetch-field "to"))))
1265 current-prefix-arg))
1266 (dolist (article (gnus-summary-work-articles n))
1267 (gnus-summary-select-article nil nil nil article)
1269 (set-buffer gnus-original-article-buffer)
1270 (message-resend address))
1271 (gnus-summary-mark-article-as-forwarded article)))
1273 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1274 (defun gnus-summary-resend-message-edit ()
1275 "Resend an article that has already been sent.
1276 A new buffer will be created to allow the user to modify body and
1277 contents of the message, and then, everything will happen as when
1278 composing a new message."
1280 (let ((article (gnus-summary-article-number)))
1281 (gnus-setup-message 'reply-yank
1282 (gnus-summary-select-article t)
1283 (set-buffer gnus-original-article-buffer)
1284 (let ((cur (current-buffer))
1285 (to (message-fetch-field "to")))
1286 ;; Get a normal message buffer.
1287 (message-pop-to-buffer (message-buffer-name "Resend" to))
1288 (insert-buffer-substring cur)
1290 (message-narrow-to-head-1)
1291 ;; Gnus will generate a new one when sending.
1292 (message-remove-header "Message-ID")
1293 (message-remove-header message-ignored-resent-headers t)
1294 ;; Remove unwanted headers.
1295 (goto-char (point-max))
1296 (insert mail-header-separator)
1297 (goto-char (point-min))
1298 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1302 (defun gnus-summary-post-forward (&optional arg)
1303 "Forward the current article to a newsgroup.
1304 See `gnus-summary-mail-forward' for ARG."
1306 (gnus-summary-mail-forward arg t))
1308 (defvar gnus-nastygram-message
1309 "The following article was inappropriately posted to %s.\n\n"
1310 "Format string to insert in nastygrams.
1311 The current group name will be inserted at \"%s\".")
1313 (defun gnus-summary-mail-nastygram (n)
1314 "Send a nastygram to the author of the current article."
1316 (when (or gnus-expert-user
1318 "Really send a nastygram to the author of the current article? "))
1319 (let ((group gnus-newsgroup-name))
1320 (gnus-summary-reply-with-original n)
1321 (set-buffer gnus-message-buffer)
1323 (insert (format gnus-nastygram-message group))
1324 (message-send-and-exit))))
1326 (defun gnus-summary-mail-crosspost-complaint (n)
1327 "Send a complaint about crossposting to the current article(s)."
1329 (dolist (article (gnus-summary-work-articles n))
1330 (set-buffer gnus-summary-buffer)
1331 (gnus-summary-goto-subject article)
1332 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1333 newsgroups followup-to)
1334 (gnus-summary-select-article)
1335 (set-buffer gnus-original-article-buffer)
1336 (if (and (<= (length (message-tokenize-header
1338 (mail-fetch-field "newsgroups"))
1341 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1342 (not (member group (message-tokenize-header
1343 followup-to ", ")))))
1345 (gnus-message 1 "Followup-to restricted")
1346 (gnus-message 1 "Not a crossposted article"))
1347 (set-buffer gnus-summary-buffer)
1348 (gnus-summary-reply-with-original 1)
1349 (set-buffer gnus-message-buffer)
1351 (insert (format gnus-crosspost-complaint newsgroups group))
1352 (message-goto-subject)
1353 (re-search-forward " *$")
1354 (replace-match " (crosspost notification)" t t)
1355 (gnus-deactivate-mark)
1356 (when (gnus-y-or-n-p "Send this complaint? ")
1357 (message-send-and-exit))))))
1359 (defun gnus-mail-parse-comma-list ()
1362 (skip-chars-forward " ")
1365 (skip-chars-forward "^,")
1370 (narrow-to-region beg (point))
1373 (while (search-forward "\"" nil t)
1377 (skip-chars-forward ",")
1378 (skip-chars-forward "^,"))
1379 (skip-chars-backward " ")
1380 (push (buffer-substring beg (point))
1382 (skip-chars-forward "^,")
1383 (skip-chars-forward ", "))
1386 (defun gnus-inews-add-to-address (group)
1387 (let ((to-address (mail-fetch-field "to")))
1388 (when (and to-address
1390 ;; This mail group doesn't have a `to-list', so we add one
1392 (when (gnus-y-or-n-p
1393 (format "Do you want to add this as `to-list': %s? " to-address))
1394 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1396 (defun gnus-put-message ()
1397 "Put the current message in some group and return to Gnus."
1399 (let ((reply gnus-article-reply)
1400 (winconf gnus-prev-winconf)
1401 (group gnus-newsgroup-name))
1403 (not (gnus-group-read-only-p group)))
1404 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1406 (when (gnus-group-entry group)
1407 (error "No such group: %s" group))
1411 (message-narrow-to-headers)
1412 (let ((gnus-deletable-headers nil))
1413 (message-generate-headers
1414 (if (message-news-p)
1415 message-required-news-headers
1416 message-required-mail-headers)))
1417 (goto-char (point-max))
1418 (if (string-match " " group)
1419 (insert "Gcc: \"" group "\"\n")
1420 (insert "Gcc: " group "\n"))
1423 (when (and (get-buffer gnus-group-buffer)
1424 (gnus-buffer-exists-p (car-safe reply))
1426 (set-buffer (car reply))
1427 (gnus-summary-mark-article-as-replied (cdr reply)))
1429 (set-window-configuration winconf))))
1431 (defun gnus-article-mail (yank)
1432 "Send a reply to the address near point.
1433 If YANK is non-nil, include the original article."
1437 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1438 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1440 (gnus-msg-mail address)
1442 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1444 (defvar nntp-server-type)
1446 "Send a bug report to the Gnus maintainers."
1448 (unless (gnus-alive-p)
1449 (error "Gnus has been shut down"))
1450 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1451 (unless (message-mail-user-agent)
1452 (delete-other-windows)
1453 (when gnus-bug-create-help-buffer
1454 (switch-to-buffer "*Gnus Help Bug*")
1456 (insert gnus-bug-message)
1457 (goto-char (point-min)))
1458 (message-pop-to-buffer "*Gnus Bug*"))
1459 (let ((message-this-is-mail t))
1460 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1461 (when gnus-bug-create-help-buffer
1462 (push `(gnus-bug-kill-buffer) message-send-actions))
1463 (goto-char (point-min))
1464 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1466 (insert (gnus-version) "\n"
1467 (emacs-version) "\n")
1468 (when (and (boundp 'nntp-server-type)
1469 (stringp nntp-server-type))
1470 (insert nntp-server-type))
1471 (insert "\n\n\n\n\n")
1474 (set-buffer (gnus-get-buffer-create " *gnus environment info*"))
1477 (setq text (buffer-string)))
1478 (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1479 (goto-char (point-min))
1480 (search-forward "Subject: " nil t)
1483 (defun gnus-bug-kill-buffer ()
1484 (when (get-buffer "*Gnus Help Bug*")
1485 (kill-buffer "*Gnus Help Bug*")))
1487 (defun gnus-summary-yank-message (buffer n)
1488 "Yank the current article into a composed message."
1490 (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1491 current-prefix-arg))
1492 (gnus-summary-iterate n
1493 (let ((gnus-inhibit-treatment t))
1494 (gnus-summary-select-article))
1497 (message-yank-buffer gnus-article-buffer))))
1499 (defun gnus-debug ()
1500 "Attempts to go through the Gnus source file and report what variables have been changed.
1501 The source file has to be in the Emacs load path."
1503 (let ((files gnus-debug-files)
1505 file expr olist sym)
1506 (gnus-message 4 "Please wait while we snoop your variables...")
1508 ;; Go through all the files looking for non-default values for variables.
1510 (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1513 (when (and (setq file (locate-library (pop files)))
1514 (file-exists-p file))
1515 (insert-file-contents file)
1516 (goto-char (point-min))
1517 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1518 (gnus-message 4 "Malformed sources in file %s" file)
1519 (narrow-to-region (point-min) (point))
1520 (goto-char (point-min))
1521 (while (setq expr (ignore-errors (read (current-buffer))))
1523 (and (or (eq (car expr) 'defvar)
1524 (eq (car expr) 'defcustom))
1525 (stringp (nth 3 expr))
1526 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1527 (or (not (boundp (nth 1 expr)))
1528 (not (equal (eval (nth 2 expr))
1529 (symbol-value (nth 1 expr)))))
1530 (push (nth 1 expr) olist)))))))
1531 (kill-buffer (current-buffer)))
1532 (when (setq olist (nreverse olist))
1533 (insert "------------------ Environment follows ------------------\n\n"))
1535 (if (boundp (car olist))
1539 ,(if (or (consp (setq sym (symbol-value (car olist))))
1541 (not (or (eq sym nil)
1543 (list 'quote (symbol-value (car olist)))
1544 (symbol-value (car olist))))))
1545 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1546 (setq olist (cdr olist)))
1548 ;; Remove any control chars - they seem to cause trouble for some
1549 ;; mailers. (Byte-compiled output from the stuff above.)
1551 (while (re-search-forward (mm-string-as-multibyte
1552 "[\000-\010\013-\037\200-\237]") nil t)
1553 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1556 ;;; Treatment of rejected articles.
1559 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1560 "Re-mail the current message.
1561 This only makes sense if the current message is a bounce message that
1562 contains some mail you have written which has been bounced back to
1564 If FETCH, try to fetch the article that this is a reply to, if indeed
1567 (gnus-summary-select-article t)
1568 (set-buffer gnus-original-article-buffer)
1569 (gnus-setup-message 'compose-bounce
1570 (let* ((references (mail-fetch-field "references"))
1571 (parent (and references (gnus-parent-id references))))
1573 ;; If there are references, we fetch the article we answered to.
1575 (gnus-summary-refer-article parent)
1576 (gnus-summary-show-all-headers)))))
1580 (defun gnus-inews-group-method (group)
1582 ;; If the group doesn't exist, we assume
1583 ;; it's an archive group...
1584 ((and (null (gnus-get-info group))
1585 (eq (car (gnus-server-to-method gnus-message-archive-method))
1586 (car (gnus-server-to-method (gnus-group-method group)))))
1587 gnus-message-archive-method)
1589 ((gnus-info-method (gnus-get-info group))
1590 (gnus-info-method (gnus-get-info group)))
1592 (t (gnus-server-to-method (gnus-group-method group)))))
1594 ;; Do Gcc handling, which copied the message over to some group.
1595 (defun gnus-inews-do-gcc (&optional gcc)
1599 (message-narrow-to-headers)
1600 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1601 (cur (current-buffer))
1602 groups group method group-art
1603 mml-externalize-attachments)
1605 (message-remove-header "gcc")
1607 (setq groups (message-unquote-tokens
1608 (message-tokenize-header gcc " ,")))
1609 ;; Copy the article over to some group(s).
1610 (while (setq group (pop groups))
1611 (unless (gnus-check-server
1612 (setq method (gnus-inews-group-method group)))
1613 (error "Can't open server %s" (if (stringp method) method
1615 (unless (gnus-request-group group nil method)
1616 (gnus-request-create-group group method))
1617 (setq mml-externalize-attachments
1618 (if (stringp gnus-gcc-externalize-attachments)
1619 (string-match gnus-gcc-externalize-attachments group)
1620 gnus-gcc-externalize-attachments))
1622 (nnheader-set-temp-buffer " *acc*")
1623 (insert-buffer-substring cur)
1624 (message-encode-message-body)
1626 (message-narrow-to-headers)
1627 (let* ((mail-parse-charset message-default-charset)
1628 (newsgroups-field (save-restriction
1629 (message-narrow-to-headers-or-head)
1630 (message-fetch-field "Newsgroups")))
1631 (followup-field (save-restriction
1632 (message-narrow-to-headers-or-head)
1633 (message-fetch-field "Followup-To")))
1634 ;; BUG: We really need to get the charset for
1635 ;; each name in the Newsgroups and Followup-To
1636 ;; lines to allow crossposting between group
1637 ;; namess with incompatible character sets.
1638 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1639 (group-field-charset
1640 (gnus-group-name-charset
1641 method (or newsgroups-field "")))
1642 (followup-field-charset
1643 (gnus-group-name-charset
1644 method (or followup-field "")))
1645 (rfc2047-header-encoding-alist
1647 (when group-field-charset
1648 (list (cons "Newsgroups" group-field-charset)))
1649 (when followup-field-charset
1650 (list (cons "Followup-To" followup-field-charset)))
1651 rfc2047-header-encoding-alist)))
1652 (mail-encode-encoded-word-buffer)))
1653 (goto-char (point-min))
1654 (when (re-search-forward
1655 (concat "^" (regexp-quote mail-header-separator) "$")
1657 (replace-match "" t t ))
1658 (when (or (not (gnus-check-backend-function
1659 'request-accept-article group))
1660 (not (setq group-art
1661 (gnus-request-accept-article
1662 group method t t))))
1663 (gnus-message 1 "Couldn't store article in group %s: %s"
1664 group (gnus-status-message method)))
1665 (when (and group-art
1666 ;; FIXME: Should gcc-mark-as-read work when
1667 ;; Gnus is not running?
1669 (or gnus-gcc-mark-as-read
1671 (boundp 'gnus-inews-mark-gcc-as-read)
1672 (symbol-value 'gnus-inews-mark-gcc-as-read))))
1673 (gnus-group-mark-article-read group (cdr group-art)))
1674 (kill-buffer (current-buffer)))))))))
1676 (defun gnus-inews-insert-gcc ()
1677 "Insert Gcc headers based on `gnus-outgoing-message-group'."
1680 (message-narrow-to-headers)
1681 (let* ((group gnus-outgoing-message-group)
1685 ((or (stringp group) (listp group))
1690 (if (string-match " " gcc)
1691 (concat "\"" gcc "\"")
1693 (mapconcat (lambda (group)
1694 (if (string-match " " group)
1695 (concat "\"" group "\"")
1700 (defun gnus-inews-insert-archive-gcc (&optional group)
1701 "Insert the Gcc to say where the article is to be archived."
1702 (let* ((var gnus-message-archive-group)
1703 (group (or group gnus-newsgroup-name ""))
1705 (and gnus-newsgroup-name
1706 (not (equal gnus-newsgroup-name ""))
1707 (gnus-group-find-parameter
1708 gnus-newsgroup-name 'gcc-self)))
1712 ((null gnus-message-archive-method)
1716 ;; Just a single group.
1719 ;; We don't want this.
1721 ((and (listp var) (stringp (car var)))
1722 ;; A list of groups.
1726 (funcall var group))
1728 ;; An alist of regexps/functions/forms.
1733 ((stringp (caar var))
1735 (when (string-match (caar var) group)
1737 ((functionp (car var))
1739 (funcall (car var) group))
1741 (eval (car var)))))))
1742 (setq var (cdr var)))
1745 (when (or groups gcc-self-val)
1746 (when (stringp groups)
1747 (setq groups (list groups)))
1750 (message-narrow-to-headers)
1751 (goto-char (point-max))
1754 ;; Use the `gcc-self' param value instead.
1757 (if (stringp gcc-self-val)
1758 (if (string-match " " gcc-self-val)
1759 (concat "\"" gcc-self-val "\"")
1761 ;; In nndoc groups, we use the parent group name
1762 ;; instead of the current group.
1763 (let ((group (or (gnus-group-find-parameter
1764 gnus-newsgroup-name 'parent-group)
1766 (if (string-match " " group)
1767 (concat "\"" group "\"")
1769 (if (not (eq gcc-self-val 'none))
1771 (gnus-delete-line)))
1772 ;; Use the list of groups.
1773 (while (setq name (pop groups))
1774 (let ((str (if (string-match ":" name)
1776 (gnus-group-prefixed-name
1777 name gnus-message-archive-method))))
1778 (insert (if (string-match " " str)
1779 (concat "\"" str "\"")
1785 (defun gnus-mailing-list-followup-to ()
1786 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1787 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1788 (list-post (gnus-fetch-original-field "list-post")))
1789 (when (and list-post
1790 (string-match "mailto:\\([^>]+\\)" list-post))
1791 (setq list-post (match-string 1 list-post)))
1797 (defun gnus-configure-posting-styles (&optional group-name)
1798 "Configure posting styles according to `gnus-posting-styles'."
1799 (unless gnus-inhibit-posting-styles
1800 (let ((group (or group-name gnus-newsgroup-name ""))
1801 (styles gnus-posting-styles)
1802 style match attribute value v results
1803 filep name address element)
1804 ;; If the group has a posting-style parameter, add it at the end with a
1805 ;; regexp matching everything, to be sure it takes precedence over all
1807 (when gnus-newsgroup-name
1808 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1810 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1811 ;; Go through all styles and look for matches.
1812 (dolist (style styles)
1813 (setq match (pop style))
1814 (goto-char (point-min))
1817 ;; Regexp string match on the group name.
1818 (string-match match group))
1820 ;; Obsolete format of header match.
1821 (and (gnus-buffer-live-p gnus-article-copy)
1822 (with-current-buffer gnus-article-copy
1824 (nnheader-narrow-to-headers)
1825 (let ((header (message-fetch-field (pop style))))
1827 (string-match (pop style) header)))))))
1828 ((or (symbolp match)
1832 ;; Function to be called.
1835 ;; Variable to be checked.
1836 (symbol-value match))))
1839 ((eq (car match) 'header)
1840 ;; New format of header match.
1841 (and (gnus-buffer-live-p gnus-article-copy)
1842 (with-current-buffer gnus-article-copy
1844 (nnheader-narrow-to-headers)
1845 (let ((header (message-fetch-field (nth 1 match))))
1847 (string-match (nth 2 match) header)))))))
1849 ;; This is a form to be evaled.
1851 ;; We have a match, so we set the variables.
1852 (dolist (attribute style)
1853 (setq element (pop attribute)
1857 ((eq (car attribute) :file)
1860 ((eq (car attribute) :value)
1864 ;; We get the value.
1869 ((or (symbolp value)
1871 (cond ((functionp value)
1874 (symbol-value value))))
1877 ;; Translate obsolescent value.
1879 ((eq element 'signature-file)
1880 (setq element 'signature
1882 ((eq element 'x-face-file)
1883 (setq element 'x-face
1885 ;; Get the contents of file elems.
1887 (setq v (with-temp-buffer
1888 (insert-file-contents v)
1892 (goto-char (point-max))
1893 (if (zerop (skip-chars-backward "\n"))
1896 (setq results (delq (assoc element results) results))
1897 (push (cons element v) results))))
1898 ;; Now we have all the styles, so we insert them.
1899 (setq name (assq 'name results)
1900 address (assq 'address results))
1901 (setq results (delq name (delq address results)))
1902 (gnus-make-local-hook 'message-setup-hook)
1903 (setq results (sort results (lambda (x y)
1904 (string-lessp (car x) (car y)))))
1905 (dolist (result results)
1906 (add-hook 'message-setup-hook
1908 ((eq 'eval (car result))
1910 ((eq 'body (car result))
1914 (insert ,(cdr result)))))
1915 ((eq 'signature (car result))
1916 (set (make-local-variable 'message-signature) nil)
1917 (set (make-local-variable 'message-signature-file) nil)
1918 (if (not (cdr result))
1922 (let ((message-signature ,(cdr result)))
1923 (when message-signature
1924 (message-insert-signature)))))))
1927 (if (symbolp (car result))
1928 (capitalize (symbol-name (car result)))
1932 (message-remove-header ,header)
1933 (let ((value ,(cdr result)))
1936 (insert ,header ": " value)
1938 (insert "\n")))))))))
1940 (when (or name address)
1941 (add-hook 'message-setup-hook
1943 (set (make-local-variable 'user-mail-address)
1944 ,(or (cdr address) user-mail-address))
1945 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1947 ,(or (cdr address) user-mail-address)))
1949 (message-remove-header "From")
1951 (insert "From: " (message-make-from) "\n"))))
1954 ;;; Allow redefinition of functions.
1960 ;;; arch-tag: 9f22b2f5-1c0a-49de-916e-4c88e984852b
1961 ;;; gnus-msg.el ends here