1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995-2011 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 3 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
28 (eval-when-compile (require 'cl))
36 (defcustom gnus-post-method 'current
37 "*Preferred method for posting USENET news.
39 If this variable is `current' (which is the default), Gnus will use
40 the \"current\" select method when posting. If it is `native', Gnus
41 will use the native select method when posting.
43 This method will not be used in mail groups and the like, only in
46 If not `native' nor `current', the value must be a valid method as discussed
47 in the documentation of `gnus-select-method'. It can also be a list of
48 methods. If that is the case, the user will be queried for what select
49 method to use when posting."
50 :group 'gnus-group-foreign
51 :link '(custom-manual "(gnus)Posting Server")
52 :type `(choice (const native)
54 (sexp :tag "Methods" ,gnus-select-method)))
56 (defcustom gnus-outgoing-message-group nil
57 "All outgoing messages will be put in this group.
58 If you want to store all your outgoing mail and articles in the group
59 \"nnml:archive\", you set this variable to that value. This variable
60 can also be a list of group names.
62 If you want to have greater control over what group to put each
63 message in, you can set this variable to a function that checks the
64 current newsgroup name and then returns a suitable group name (or list
67 :type '(choice (const nil)
70 (repeat :tag "List of groups" (string :tag "Group"))))
72 (make-obsolete-variable 'gnus-outgoing-message-group 'gnus-message-archive-group "24.1")
74 (defcustom gnus-mailing-list-groups nil
75 "*If non-nil a regexp matching groups that are really mailing lists.
76 This is useful when you're reading a mailing list that has been
77 gatewayed to a newsgroup, and you want to followup to an article in
80 :type '(choice (regexp)
83 (defcustom gnus-add-to-list nil
84 "*If non-nil, add a `to-list' parameter automatically."
88 (defcustom gnus-crosspost-complaint
91 You posted the article below with the following Newsgroups header:
95 The %s group, at least, was an inappropriate recipient
96 of this message. Please trim your Newsgroups header to exclude this
97 group before posting in the future.
102 "Format string to be inserted when complaining about crossposts.
103 The first %s will be replaced by the Newsgroups header;
104 the second with the current group name."
108 (defcustom gnus-message-setup-hook nil
109 "Hook run after setting up a message buffer."
111 :options '(message-remove-blank-cited-lines)
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 "Emacs 22.1")
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 t
246 "Automatically encrypt replies to encrypted messages.
247 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 if a confirmation is needed; or
265 a regexp, in which case a confirmation is asked for if the group name
267 :version "23.1" ;; No Gnus (default changed)
269 :type '(choice (const :tag "No" nil)
271 (regexp :tag "If group matches regexp")
272 (function :tag "If function evaluates to non-nil")))
274 (defcustom gnus-confirm-treat-mail-like-news
276 "If non-nil, Gnus will treat mail like news with regard to confirmation
277 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
278 for fine-tuning this.
279 If nil, Gnus will never ask for confirmation if replying to mail."
284 (defcustom gnus-summary-resend-default-address t
285 "If non-nil, Gnus tries to suggest a default address to resend to.
286 If nil, the address field will always be empty after invoking
287 `gnus-summary-resend-message'."
292 (defcustom gnus-message-highlight-citation
293 t ;; gnus-treat-highlight-citation ;; gnus-cite dependency
294 "Enable highlighting of different citation levels in message-mode."
295 :version "23.1" ;; No Gnus
300 (autoload 'gnus-message-citation-mode "gnus-cite" nil t)
302 ;;; Internal variables.
304 (defvar gnus-inhibit-posting-styles nil
305 "Inhibit the use of posting styles.")
307 (defvar gnus-article-yanked-articles nil)
308 (defvar gnus-message-buffer "*Mail Gnus*")
309 (defvar gnus-article-copy nil)
310 (defvar gnus-check-before-posting nil)
311 (defvar gnus-last-posting-server nil)
312 (defvar gnus-message-group-art nil)
314 (defvar gnus-msg-force-broken-reply-to nil)
316 (defconst gnus-bug-message
317 "Sending a bug report to the Gnus Towers.
318 ========================================
320 The buffer below is a mail buffer. When you press `C-c C-c', it will
321 be sent to the Gnus Bug Exterminators.
323 The thing near the bottom of the buffer is how the environment
324 settings will be included in the mail. Please do not delete that.
325 They will tell the Bug People what your environment is, so that it
326 will be easier to locate the bugs.
328 If you have found a bug that makes Emacs go \"beep\", set
329 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
330 and include the backtrace in your bug report.
332 Please describe the bug in annoying, painstaking detail.
334 Thank you for your help in stamping out bugs.
337 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
341 ;;; Gnus Posting Functions
344 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
345 "p" gnus-summary-post-news
346 "i" gnus-summary-news-other-window
347 "f" gnus-summary-followup
348 "F" gnus-summary-followup-with-original
349 "c" gnus-summary-cancel-article
350 "s" gnus-summary-supersede-article
351 "r" gnus-summary-reply
352 "y" gnus-summary-yank-message
353 "R" gnus-summary-reply-with-original
354 "L" gnus-summary-reply-to-list-with-original
355 "w" gnus-summary-wide-reply
356 "W" gnus-summary-wide-reply-with-original
357 "v" gnus-summary-very-wide-reply
358 "V" gnus-summary-very-wide-reply-with-original
359 "n" gnus-summary-followup-to-mail
360 "N" gnus-summary-followup-to-mail-with-original
361 "m" gnus-summary-mail-other-window
362 "u" gnus-uu-post-news
363 "\M-c" gnus-summary-mail-crosspost-complaint
364 "Br" gnus-summary-reply-broken-reply-to
365 "BR" gnus-summary-reply-broken-reply-to-with-original
366 "om" gnus-summary-mail-forward
367 "op" gnus-summary-post-forward
368 "Om" gnus-uu-digest-mail-forward
369 "Op" gnus-uu-digest-post-forward)
371 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
372 "b" gnus-summary-resend-bounced-mail
373 ;; "c" gnus-summary-send-draft
374 "r" gnus-summary-resend-message
375 "e" gnus-summary-resend-message-edit)
377 ;;; Internal functions.
379 (defun gnus-inews-make-draft (articles)
381 (gnus-inews-make-draft-meta-information
382 ,(gnus-group-decoded-name gnus-newsgroup-name) ',articles)))
384 (defvar gnus-article-reply nil)
385 (defmacro gnus-setup-message (config &rest forms)
386 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
387 (winconf-name (make-symbol "gnus-setup-message-winconf-name"))
388 (buffer (make-symbol "gnus-setup-message-buffer"))
389 (article (make-symbol "gnus-setup-message-article"))
390 (yanked (make-symbol "gnus-setup-yanked-articles"))
391 (group (make-symbol "gnus-setup-message-group")))
392 `(let ((,winconf (current-window-configuration))
393 (,winconf-name gnus-current-window-configuration)
394 (,buffer (buffer-name (current-buffer)))
395 (,article gnus-article-reply)
396 (,yanked gnus-article-yanked-articles)
397 (,group gnus-newsgroup-name)
398 (message-header-setup-hook
399 (copy-sequence message-header-setup-hook))
400 (mbl mml-buffer-list)
401 (message-mode-hook (copy-sequence message-mode-hook)))
402 (setq mml-buffer-list nil)
403 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
404 ;; message-newsreader and message-mailer were formerly set in
405 ;; gnus-inews-add-send-actions, but this is too late when
406 ;; message-generate-headers-first is used. --ansel
407 (add-hook 'message-mode-hook
409 (setq message-newsreader
410 (setq message-mailer (gnus-extended-version)))))
411 ;; #### FIXME: for a reason that I did not manage to identify yet,
412 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
413 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
414 ;; After evaluation of @forms below, it gets the value we actually want
415 ;; to override, and the posting styles are used. For that reason, I've
416 ;; added an optional argument to `gnus-configure-posting-styles' to
417 ;; make sure that the correct value for the group name is used. -- drv
418 (add-hook 'message-mode-hook
419 (if (memq ,config '(reply-yank reply))
421 (gnus-configure-posting-styles ,group))
423 ;; There may be an old " *gnus article copy*" buffer.
424 (let (gnus-article-copy)
425 (gnus-configure-posting-styles ,group)))))
426 (gnus-alist-pull ',(intern gnus-draft-meta-information-header)
427 message-required-headers)
429 (not (string= ,group "")))
431 (intern gnus-draft-meta-information-header)
432 (gnus-inews-make-draft (or ,yanked ,article)))
433 message-required-headers))
437 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
438 ,yanked ',winconf-name)
439 (setq gnus-message-buffer (current-buffer))
440 (set (make-local-variable 'gnus-message-group-art)
441 (cons ,group ,article))
442 (set (make-local-variable 'gnus-newsgroup-name) ,group)
443 ;; Enable highlighting of different citation levels
444 (when gnus-message-highlight-citation
445 (gnus-message-citation-mode 1))
446 (gnus-run-hooks 'gnus-message-setup-hook)
447 (if (eq major-mode 'message-mode)
448 (let ((mbl1 mml-buffer-list))
449 (setq mml-buffer-list mbl) ;; Global value
450 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
451 (gnus-make-local-hook 'kill-buffer-hook)
452 (gnus-make-local-hook 'change-major-mode-hook)
453 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
454 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
455 (mml-destroy-buffers)
456 (setq mml-buffer-list mbl)))
457 (message-hide-headers)
459 (gnus-configure-windows ,config t)
460 (run-hooks 'post-command-hook)
461 (set-buffer-modified-p nil))))
463 (defun gnus-inews-make-draft-meta-information (group articles)
464 (when (numberp articles)
465 (setq articles (list articles)))
466 (concat "(\"" group "\""
480 (defun gnus-msg-mail (&optional to subject other-headers continue
481 switch-action yank-action send-actions return-action)
482 "Start editing a mail message to be sent.
483 Like `message-mail', but with Gnus paraphernalia, particularly the
484 Gcc: header for archiving purposes."
486 (let ((buf (current-buffer))
488 (gnus-setup-message 'message
489 (message-mail to subject other-headers continue
490 nil yank-action send-actions return-action))
492 (setq mail-buf (current-buffer))
493 (switch-to-buffer buf)
494 (apply switch-action mail-buf nil)))
495 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
499 (defun gnus-button-mailto (address)
501 (set-buffer (gnus-copy-article-buffer))
502 (gnus-setup-message 'message
503 (message-reply address)))
506 (defun gnus-button-reply (&optional to-address wide)
507 "Like `message-reply'."
509 (gnus-setup-message 'message
510 (message-reply to-address wide)))
513 (define-mail-user-agent 'gnus-user-agent
514 'gnus-msg-mail 'message-send-and-exit
515 'message-kill-buffer 'message-send-hook)
517 (defun gnus-setup-posting-charset (group)
518 (let ((alist gnus-group-posting-charset-alist)
519 (group (or group ""))
523 (while (setq elem (pop alist))
524 (when (or (and (stringp (car elem))
525 (string-match (car elem) group))
526 (and (functionp (car elem))
527 (funcall (car elem) group))
528 (and (symbolp (car elem))
529 (symbol-value (car elem))))
530 (throw 'found (cons (cadr elem) (caddr elem)))))))))
532 (defun gnus-inews-add-send-actions (winconf buffer article
533 &optional config yanked
535 (gnus-make-local-hook 'message-sent-hook)
536 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
537 'gnus-inews-do-gcc) nil t)
539 (gnus-make-local-hook 'message-header-hook)
540 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
541 (setq message-post-method
542 `(lambda (&optional arg)
543 (gnus-post-method arg ,gnus-newsgroup-name)))
546 (setq gnus-current-window-configuration ',winconf-name)
547 (when (gnus-buffer-exists-p ,buffer)
548 (set-window-configuration ,winconf)))
549 'exit 'postpone 'kill)
550 (let ((to-be-marked (cond
553 (lambda (x) (if (listp x) (car x) x)) yanked))
554 (article (if (listp article) article (list article)))
557 `(when (gnus-buffer-exists-p ,buffer)
558 (with-current-buffer ,buffer
560 (if (eq config 'forward)
561 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
562 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
565 (put 'gnus-setup-message 'lisp-indent-function 1)
566 (put 'gnus-setup-message 'edebug-form-spec '(form body))
568 ;;; Post news commands of Gnus group mode and summary mode
570 (defun gnus-group-mail (&optional arg)
571 "Start composing a mail.
572 If ARG, use the group under the point to find a posting style.
573 If ARG is 1, prompt for a group name to find the posting style."
575 ;; We can't `let' gnus-newsgroup-name here, since that leads
576 ;; to local variables leaking.
577 (let ((group gnus-newsgroup-name)
578 ;; make sure last viewed article doesn't affect posting styles:
580 (buffer (current-buffer)))
583 (setq gnus-newsgroup-name
585 (if (= 1 (prefix-numeric-value arg))
586 (gnus-group-completing-read
587 "Use posting style of group"
588 nil (gnus-read-active-file-p))
589 (gnus-group-group-name))
591 ;; #### see comment in gnus-setup-message -- drv
592 (gnus-setup-message 'message (message-mail)))
593 (with-current-buffer buffer
594 (setq gnus-newsgroup-name group)))))
596 (defun gnus-group-news (&optional arg)
597 "Start composing a news.
598 If ARG, post to group under point.
599 If ARG is 1, prompt for group name to post to.
601 This function prepares a news even when using mail groups. This is useful
602 for posting messages to mail groups without actually sending them over the
603 network. The corresponding back end must have a 'request-post method."
605 ;; We can't `let' gnus-newsgroup-name here, since that leads
606 ;; to local variables leaking.
607 (let ((group gnus-newsgroup-name)
608 ;; make sure last viewed article doesn't affect posting styles:
610 (buffer (current-buffer)))
613 (setq gnus-newsgroup-name
615 (if (= 1 (prefix-numeric-value arg))
616 (gnus-group-completing-read "Use group"
618 (gnus-read-active-file-p))
619 (gnus-group-group-name))
621 ;; #### see comment in gnus-setup-message -- drv
622 (gnus-setup-message 'message
623 (message-news (gnus-group-real-name gnus-newsgroup-name))))
624 (with-current-buffer buffer
625 (setq gnus-newsgroup-name group)))))
627 (defun gnus-group-post-news (&optional arg)
628 "Start composing a message (a news by default).
629 If ARG, post to group under point. If ARG is 1, prompt for group name.
630 Depending on the selected group, the message might be either a mail or
633 ;; Bind this variable here to make message mode hooks work ok.
634 (let ((gnus-newsgroup-name
636 (if (= 1 (prefix-numeric-value arg))
637 (gnus-group-completing-read "Newsgroup" nil
638 (gnus-read-active-file-p))
639 (gnus-group-group-name))
641 ;; make sure last viewed article doesn't affect posting styles:
643 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
644 (string= gnus-newsgroup-name ""))))
646 (defun gnus-summary-mail-other-window (&optional arg)
647 "Start composing a mail in another window.
648 Use the posting of the current group by default.
649 If ARG, don't do that. If ARG is 1, prompt for group name to find the
652 ;; We can't `let' gnus-newsgroup-name here, since that leads
653 ;; to local variables leaking.
654 (let ((group gnus-newsgroup-name)
655 ;; make sure last viewed article doesn't affect posting styles:
657 (buffer (current-buffer)))
660 (setq gnus-newsgroup-name
662 (if (= 1 (prefix-numeric-value arg))
663 (gnus-group-completing-read "Use group"
665 (gnus-read-active-file-p))
667 gnus-newsgroup-name))
668 ;; #### see comment in gnus-setup-message -- drv
669 (gnus-setup-message 'message (message-mail)))
670 (with-current-buffer buffer
671 (setq gnus-newsgroup-name group)))))
673 (defun gnus-summary-news-other-window (&optional arg)
674 "Start composing a news in another window.
675 Post to the current group by default.
676 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
678 This function prepares a news even when using mail groups. This is useful
679 for posting messages to mail groups without actually sending them over the
680 network. The corresponding back end must have a 'request-post method."
682 ;; We can't `let' gnus-newsgroup-name here, since that leads
683 ;; to local variables leaking.
684 (let ((group gnus-newsgroup-name)
685 ;; make sure last viewed article doesn't affect posting styles:
687 (buffer (current-buffer)))
690 (setq gnus-newsgroup-name
692 (if (= 1 (prefix-numeric-value arg))
693 (gnus-group-completing-read "Use group"
695 (gnus-read-active-file-p))
697 gnus-newsgroup-name))
698 ;; #### see comment in gnus-setup-message -- drv
699 (gnus-setup-message 'message
701 (message-news (gnus-group-real-name gnus-newsgroup-name))
702 (set (make-local-variable 'gnus-discouraged-post-methods)
704 (car (gnus-find-method-for-group gnus-newsgroup-name))
705 gnus-discouraged-post-methods)))))
706 (with-current-buffer buffer
707 (setq gnus-newsgroup-name group)))))
709 (defun gnus-summary-post-news (&optional arg)
710 "Start composing a message. Post to the current group by default.
711 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
712 Depending on the selected group, the message might be either a mail or
715 ;; Bind this variable here to make message mode hooks work ok.
716 (let ((gnus-newsgroup-name
718 (if (= 1 (prefix-numeric-value arg))
719 (gnus-group-completing-read "Newsgroup" nil
720 (gnus-read-active-file-p))
722 gnus-newsgroup-name))
723 ;; make sure last viewed article doesn't affect posting styles:
725 (gnus-post-news 'post gnus-newsgroup-name)))
728 (defun gnus-summary-followup (yank &optional force-news)
729 "Compose a followup to an article.
730 If prefix argument YANK is non-nil, the original article is yanked
732 YANK is a list of elements, where the car of each element is the
733 article number, and the cdr is the string to be yanked."
735 (list (and current-prefix-arg
736 (gnus-summary-work-articles 1))))
738 (gnus-summary-goto-subject
739 (if (listp (car yank))
742 (save-window-excursion
743 (gnus-summary-select-article))
744 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
745 (gnus-newsgroup-name gnus-newsgroup-name))
747 (gnus-post-news nil gnus-newsgroup-name
748 headers gnus-article-buffer
750 (gnus-summary-handle-replysign)))
752 (defun gnus-summary-followup-with-original (n &optional force-news)
753 "Compose a followup to an article and include the original article.
754 The text in the region will be yanked. If the region isn't
755 active, the entire article will be yanked."
757 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
759 (defun gnus-summary-followup-to-mail (&optional arg)
760 "Followup to the current mail message via news."
762 (list (and current-prefix-arg
763 (gnus-summary-work-articles 1))))
764 (gnus-summary-followup arg t))
766 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
767 "Followup to the current mail message via news."
769 (gnus-summary-followup (gnus-summary-work-articles arg) t))
771 (defun gnus-inews-yank-articles (articles)
772 (let (beg article yank-string)
774 (while (setq article (pop articles))
775 (when (listp article)
776 (setq yank-string (nth 1 article)
777 article (nth 0 article)))
778 (save-window-excursion
779 (set-buffer gnus-summary-buffer)
780 (gnus-summary-select-article nil nil nil article)
781 (gnus-summary-remove-process-mark article))
782 (gnus-copy-article-buffer nil yank-string)
783 (let ((message-reply-buffer gnus-article-copy)
784 (message-reply-headers
785 ;; The headers are decoded.
786 (with-current-buffer gnus-article-copy
788 (nnheader-narrow-to-headers)
789 (nnheader-parse-naked-head)))))
790 (message-yank-original)
791 (message-exchange-point-and-mark)
792 (setq beg (or beg (mark t))))
798 (defun gnus-summary-cancel-article (&optional n symp)
799 "Cancel an article you posted.
800 Uses the process-prefix convention. If given the symbolic
801 prefix `a', cancel using the standard posting method; if not
802 post using the current select method."
803 (interactive (gnus-interactive "P\ny"))
804 (let ((message-post-method
806 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
807 (dolist (article (gnus-summary-work-articles n))
808 (when (gnus-summary-select-article t nil nil article)
809 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
810 (message-cancel-news))
811 (gnus-summary-mark-as-read article gnus-canceled-mark)
812 (gnus-cache-remove-article 1))
813 (gnus-article-hide-headers-if-wanted))
814 (gnus-summary-remove-process-mark article))))
816 (defun gnus-summary-supersede-article ()
817 "Compose an article that will supersede a previous article.
818 This is done simply by taking the old article and adding a Supersedes
819 header line with the old Message-ID."
821 (let ((article (gnus-summary-article-number))
822 (mail-parse-charset gnus-newsgroup-charset))
823 (gnus-setup-message 'reply-yank
824 (gnus-summary-select-article t)
825 (set-buffer gnus-original-article-buffer)
829 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
830 (with-current-buffer ,gnus-summary-buffer
831 (gnus-cache-possibly-remove-article ,article nil nil nil t)
832 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
833 message-send-actions)
835 (gnus-inews-insert-gcc))))
839 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
840 ;; make a copy of the article buffer with all text properties removed
841 ;; this copy is in the buffer gnus-article-copy.
842 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
843 ;; this buffer should be passed to all mail/news reply/post routines.
844 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
845 (with-current-buffer gnus-article-copy
846 (mm-enable-multibyte))
847 (let ((article-buffer (or article-buffer gnus-article-buffer))
849 (if (not (and (get-buffer article-buffer)
850 (gnus-buffer-exists-p article-buffer)))
851 (error "Can't find any article buffer")
852 (with-current-buffer article-buffer
853 (let ((gnus-newsgroup-charset (or gnus-article-charset
854 gnus-newsgroup-charset))
855 (gnus-newsgroup-ignored-charsets
856 (or gnus-article-ignored-charsets
857 gnus-newsgroup-ignored-charsets)))
859 ;; Copy over the (displayed) article buffer, delete
860 ;; hidden text and remove text properties.
862 (copy-to-buffer gnus-article-copy (point-min) (point-max))
863 (set-buffer gnus-article-copy)
866 (delete-region (point) (point-max))
867 (insert yank-string))
868 (gnus-article-delete-text-of-type 'annotation)
869 (gnus-article-delete-text-of-type 'multipart)
870 (gnus-remove-text-with-property 'gnus-prev)
871 (gnus-remove-text-with-property 'gnus-next)
872 (gnus-remove-text-with-property 'gnus-decoration)
875 (buffer-substring-no-properties (point-min) (point-max))
877 ;; Find the original headers.
878 (set-buffer gnus-original-article-buffer)
879 (goto-char (point-min))
880 (while (looking-at message-unix-mail-delimiter)
882 (let ((mail-header-separator ""))
884 end (or (message-goto-body)
885 ;; There may be just a header.
887 ;; Delete the headers from the displayed articles.
888 (set-buffer gnus-article-copy)
889 (let ((mail-header-separator ""))
890 (delete-region (goto-char (point-min))
891 (or (message-goto-body) (point-max))))
892 ;; Insert the original article headers.
893 (insert-buffer-substring gnus-original-article-buffer beg end)
895 (let ((gnus-article-decode-hook
896 (delq 'article-decode-charset
897 (copy-sequence gnus-article-decode-hook)))
898 (rfc2047-quote-decoded-words-containing-tspecials t))
899 (run-hooks 'gnus-article-decode-hook)))))
902 (defun gnus-post-news (post &optional group header article-buffer yank subject
905 (gnus-copy-article-buffer))
906 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
907 (gnus-article-yanked-articles yank)
908 (add-to-list gnus-add-to-list))
909 (gnus-setup-message (cond (yank 'reply-yank)
910 (article-buffer 'reply)
912 (let* ((group (or group gnus-newsgroup-name))
913 (charset (gnus-group-name-charset nil group))
915 to-address to-group mailing-list to-list
918 (setq to-address (gnus-parameter-to-address group)
919 to-group (gnus-group-find-parameter group 'to-group)
920 to-list (gnus-parameter-to-list group)
921 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
922 mailing-list (when gnus-mailing-list-groups
923 (string-match gnus-mailing-list-groups group))
924 group (gnus-group-name-decode (gnus-group-real-name group)
926 (if (or (and to-group
927 (gnus-news-group-p to-group))
930 (and (gnus-news-group-p
931 (or pgroup gnus-newsgroup-name)
932 (or header gnus-current-article))
940 (and (not (gnus-virtual-group-p pgroup)) group)))
941 (set-buffer gnus-article-copy)
942 (gnus-msg-treat-broken-reply-to)
943 (message-followup (if (or newsgroup-p force-news)
944 (if (save-restriction
945 (article-narrow-to-head)
946 (message-fetch-field "newsgroups"))
953 (message-mail (or to-address to-list))
954 ;; Arrange for mail groups that have no `to-address' to
955 ;; get that when the user sends off the mail.
956 (when (and (not to-list)
959 (push (list 'gnus-inews-add-to-address pgroup)
960 message-send-actions)))
961 (set-buffer gnus-article-copy)
962 (gnus-msg-treat-broken-reply-to)
963 (message-wide-reply to-address)))
965 (gnus-inews-yank-articles yank))))))
967 (defun gnus-msg-treat-broken-reply-to (&optional force)
968 "Remove the Reply-to header if broken-reply-to."
970 (gnus-group-find-parameter
971 gnus-newsgroup-name 'broken-reply-to))
973 (message-narrow-to-head)
974 (message-remove-header "reply-to"))))
976 (defun gnus-post-method (arg group &optional silent)
977 "Return the posting method based on GROUP and ARG.
978 If SILENT, don't prompt the user."
979 (let ((gnus-post-method (or (gnus-parameter-post-method group)
981 (group-method (gnus-find-method-for-group group)))
983 ;; If the group-method is nil (which shouldn't happen) we use
984 ;; the default method.
986 (or (and (listp gnus-post-method) ;If not current/native/nil
987 (not (listp (car gnus-post-method))) ; and not a list of methods
988 gnus-post-method) ;then use it.
990 message-post-method))
991 ;; We want the inverse of the default
992 ((and arg (not (eq arg 0)))
993 (if (eq gnus-post-method 'current)
996 ;; We query the user for a post method.
998 (and (listp gnus-post-method)
999 (listp (car gnus-post-method))))
1001 ;; Collect all methods we know about.
1003 (when (listp gnus-post-method)
1004 (if (listp (car gnus-post-method))
1006 (list gnus-post-method)))
1007 gnus-secondary-select-methods
1008 (mapcar 'cdr gnus-server-alist)
1009 (mapcar 'car gnus-opened-servers)
1010 (list gnus-select-method)
1011 (list group-method)))
1012 method-alist post-methods method)
1013 ;; Weed out all mail methods.
1015 (setq method (gnus-server-get-method "" (pop methods)))
1016 (when (and (or (gnus-method-option-p method 'post)
1017 (gnus-method-option-p method 'post-mail))
1018 (not (member method post-methods)))
1019 (push method post-methods)))
1020 ;; Create a name-method alist.
1024 (if (equal (cadr m) "")
1025 (list (symbol-name (car m)) m)
1026 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1031 (setq gnus-last-posting-server
1033 gnus-last-posting-server)
1034 ;; Just use the last value.
1035 gnus-last-posting-server
1036 (gnus-completing-read
1037 "Posting method" (mapcar 'car method-alist) t
1038 (cons (or gnus-last-posting-server "") 0))))
1040 ;; Override normal method.
1041 ((and (eq gnus-post-method 'current)
1042 (not (memq (car group-method) gnus-discouraged-post-methods))
1043 (gnus-get-function group-method 'request-post t))
1046 ;; Use gnus-post-method.
1047 ((listp gnus-post-method) ;A method...
1048 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1050 ;; Use the normal select method (nil or native).
1051 (t gnus-select-method))))
1055 (defun gnus-extended-version ()
1056 "Stringified Gnus version and Emacs version.
1057 See the variable `gnus-user-agent'."
1059 (if (stringp gnus-user-agent)
1061 ;; `gnus-user-agent' is a list:
1062 (let* ((float-output-format nil)
1064 (when (memq 'gnus gnus-user-agent)
1066 (prin1-to-string (gnus-continuum-version gnus-version) t)
1067 " (" gnus-version ")")))
1068 (emacs-v (gnus-emacs-version)))
1069 (concat gnus-v (when (and gnus-v emacs-v) " ")
1074 ;;; Gnus Mail Functions
1077 ;;; Mail reply commands of Gnus summary mode
1079 (defun gnus-summary-reply (&optional yank wide very-wide)
1080 "Start composing a mail reply to the current message.
1081 If prefix argument YANK is non-nil, the original article is yanked
1083 If WIDE, make a wide reply.
1084 If VERY-WIDE, make a very wide reply."
1086 (list (and current-prefix-arg
1087 (gnus-summary-work-articles 1))))
1088 ;; Allow user to require confirmation before replying by mail to the
1089 ;; author of a news article (or mail message).
1090 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1091 gnus-confirm-treat-mail-like-news))
1092 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1093 (string-match gnus-confirm-mail-reply-to-news
1094 gnus-newsgroup-name))
1095 ((functionp gnus-confirm-mail-reply-to-news)
1096 (funcall gnus-confirm-mail-reply-to-news
1097 gnus-newsgroup-name))
1098 (t gnus-confirm-mail-reply-to-news)))
1099 (if (or wide very-wide)
1100 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1102 (y-or-n-p "Really reply by mail to article author? ")))
1104 (if (listp (car yank))
1107 (gnus-article-reply (or article (gnus-summary-article-number)))
1108 (gnus-article-yanked-articles yank)
1110 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1112 (gnus-summary-goto-subject article))
1113 (gnus-setup-message (if yank 'reply-yank 'reply)
1115 (gnus-summary-select-article)
1116 (dolist (article very-wide)
1117 (gnus-summary-select-article nil nil nil article)
1118 (with-current-buffer (gnus-copy-article-buffer)
1119 (gnus-msg-treat-broken-reply-to)
1121 (message-narrow-to-head)
1122 (setq headers (concat headers (buffer-string)))))))
1123 (set-buffer (gnus-copy-article-buffer))
1124 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1126 (message-narrow-to-head)
1130 (goto-char (point-max)))
1131 (mml-quote-region (point) (point-max))
1132 (message-reply nil wide 'switch-to-buffer)
1134 (gnus-inews-yank-articles yank))
1135 (gnus-summary-handle-replysign)))))
1137 (defun gnus-summary-handle-replysign ()
1138 "Check the various replysign variables and take action accordingly."
1139 (when (or gnus-message-replysign gnus-message-replyencrypt)
1140 (let (signed encrypted)
1141 (with-current-buffer gnus-article-buffer
1142 (setq signed (memq 'signed gnus-article-wash-types))
1143 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1144 (cond ((and gnus-message-replyencrypt encrypted)
1145 (mml-secure-message mml-default-encrypt-method
1146 (if gnus-message-replysignencrypted
1149 ((and gnus-message-replysign signed)
1150 (mml-secure-message mml-default-sign-method 'sign))))))
1152 (defun gnus-summary-reply-with-original (n &optional wide)
1153 "Start composing a reply mail to the current message.
1154 The original article will be yanked."
1156 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1158 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1159 "Start composing a reply mail to the current message.
1160 The reply goes only to the mailing list.
1161 The original article will be yanked."
1163 (let ((message-reply-to-function
1165 `((To . ,(gnus-mailing-list-followup-to))))))
1166 (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1168 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1169 "Like `gnus-summary-reply' except removing reply-to field.
1170 If prefix argument YANK is non-nil, the original article is yanked
1172 If WIDE, make a wide reply.
1173 If VERY-WIDE, make a very wide reply."
1175 (list (and current-prefix-arg
1176 (gnus-summary-work-articles 1))))
1177 (let ((gnus-msg-force-broken-reply-to t))
1178 (gnus-summary-reply yank wide very-wide)))
1180 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1181 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1182 The original article will be yanked."
1184 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1186 (defun gnus-summary-wide-reply (&optional yank)
1187 "Start composing a wide reply mail to the current message.
1188 If prefix argument YANK is non-nil, the original article is yanked
1191 (list (and current-prefix-arg
1192 (gnus-summary-work-articles 1))))
1193 (gnus-summary-reply yank t))
1195 (defun gnus-summary-wide-reply-with-original (n)
1196 "Start composing a wide reply mail to the current message.
1197 The original article will be yanked.
1198 Uses the process/prefix convention."
1200 (gnus-summary-reply-with-original n t))
1202 (defun gnus-summary-very-wide-reply (&optional yank)
1203 "Start composing a very wide reply mail to the current message.
1204 If prefix argument YANK is non-nil, the original article is yanked
1207 (list (and current-prefix-arg
1208 (gnus-summary-work-articles 1))))
1209 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1211 (defun gnus-summary-very-wide-reply-with-original (n)
1212 "Start composing a very wide reply mail to the current message.
1213 The original article will be yanked."
1216 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1218 (defun gnus-summary-mail-forward (&optional arg post)
1219 "Forward the current message(s) to another user.
1220 If process marks exist, forward all marked messages;
1221 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1222 if ARG is 1, decode the message and forward directly inline;
1223 if ARG is 2, forward message as an rfc822 MIME section;
1224 if ARG is 3, decode message and forward as an rfc822 MIME section;
1225 if ARG is 4, forward message directly inline;
1226 otherwise, use flipped `message-forward-as-mime'.
1227 If POST, post instead of mail.
1228 For the `inline' alternatives, also see the variable
1229 `message-forward-ignored-headers'."
1231 (if (cdr (gnus-summary-work-articles nil))
1232 ;; Process marks are given.
1233 (gnus-uu-digest-mail-forward arg post)
1234 ;; No process marks.
1235 (let ((message-forward-as-mime message-forward-as-mime)
1236 (message-forward-show-mml message-forward-show-mml))
1240 (setq message-forward-as-mime nil
1241 message-forward-show-mml t))
1243 (setq message-forward-as-mime t
1244 message-forward-show-mml nil))
1246 (setq message-forward-as-mime t
1247 message-forward-show-mml t))
1249 (setq message-forward-as-mime nil
1250 message-forward-show-mml nil))
1252 (setq message-forward-as-mime (not message-forward-as-mime))))
1253 (let* ((gnus-article-reply (gnus-summary-article-number))
1254 (gnus-article-yanked-articles (list gnus-article-reply)))
1255 (gnus-setup-message 'forward
1256 (gnus-summary-select-article)
1257 (let ((mail-parse-charset
1258 (or (and (gnus-buffer-live-p gnus-article-buffer)
1259 (with-current-buffer gnus-article-buffer
1260 gnus-article-charset))
1261 gnus-newsgroup-charset))
1262 (mail-parse-ignored-charsets
1263 gnus-newsgroup-ignored-charsets))
1264 (set-buffer gnus-original-article-buffer)
1265 (message-forward post)))))))
1267 (defun gnus-summary-resend-message (address n)
1268 "Resend the current article to ADDRESS."
1270 (list (message-read-from-minibuffer
1271 "Resend message(s) to: "
1272 (when (and gnus-summary-resend-default-address
1273 (gnus-buffer-live-p gnus-original-article-buffer))
1274 ;; If some other article is currently selected, the
1275 ;; initial-contents is wrong. Whatever, it is just the
1276 ;; initial-contents.
1277 (with-current-buffer gnus-original-article-buffer
1278 (nnmail-fetch-field "to"))))
1279 current-prefix-arg))
1280 (dolist (article (gnus-summary-work-articles n))
1281 (gnus-summary-select-article nil nil nil article)
1282 (with-current-buffer gnus-original-article-buffer
1283 (let ((gnus-gcc-externalize-attachments nil))
1284 (message-resend address)))
1285 (gnus-summary-mark-article-as-forwarded article)))
1287 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1288 (defun gnus-summary-resend-message-edit ()
1289 "Resend an article that has already been sent.
1290 A new buffer will be created to allow the user to modify body and
1291 contents of the message, and then, everything will happen as when
1292 composing a new message."
1294 (let ((mail-parse-charset gnus-newsgroup-charset))
1295 (gnus-setup-message 'reply-yank
1296 (gnus-summary-select-article t)
1297 (set-buffer gnus-original-article-buffer)
1298 (let ((cur (current-buffer))
1299 (to (message-fetch-field "to")))
1300 ;; Get a normal message buffer.
1301 (message-pop-to-buffer (message-buffer-name "Resend" to))
1302 (insert-buffer-substring cur)
1304 (message-narrow-to-head-1)
1305 ;; Gnus will generate a new one when sending.
1306 (message-remove-header "Message-ID")
1307 ;; Remove unwanted headers.
1308 (message-remove-header message-ignored-resent-headers t)
1309 (goto-char (point-max))
1310 (insert mail-header-separator)
1312 (gnus-inews-insert-gcc)
1313 (goto-char (point-min))
1314 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1318 (defun gnus-summary-post-forward (&optional arg)
1319 "Forward the current article to a newsgroup.
1320 See `gnus-summary-mail-forward' for ARG."
1322 (gnus-summary-mail-forward arg t))
1324 (defun gnus-summary-mail-crosspost-complaint (n)
1325 "Send a complaint about crossposting to the current article(s)."
1327 (dolist (article (gnus-summary-work-articles n))
1328 (set-buffer gnus-summary-buffer)
1329 (gnus-summary-goto-subject article)
1330 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1331 newsgroups followup-to)
1332 (gnus-summary-select-article)
1333 (set-buffer gnus-original-article-buffer)
1334 (if (and (<= (length (message-tokenize-header
1336 (mail-fetch-field "newsgroups"))
1339 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1340 (not (member group (message-tokenize-header
1341 followup-to ", ")))))
1343 (gnus-message 1 "Followup-to restricted")
1344 (gnus-message 1 "Not a crossposted article"))
1345 (set-buffer gnus-summary-buffer)
1346 (gnus-summary-reply-with-original 1)
1347 (set-buffer gnus-message-buffer)
1349 (insert (format gnus-crosspost-complaint newsgroups group))
1350 (message-goto-subject)
1351 (re-search-forward " *$")
1352 (replace-match " (crosspost notification)" t t)
1353 (gnus-deactivate-mark)
1354 (when (gnus-y-or-n-p "Send this complaint? ")
1355 (message-send-and-exit))))))
1357 (defun gnus-mail-parse-comma-list ()
1360 (skip-chars-forward " ")
1363 (skip-chars-forward "^,")
1368 (narrow-to-region beg (point))
1371 (while (search-forward "\"" nil t)
1375 (skip-chars-forward ",")
1376 (skip-chars-forward "^,"))
1377 (skip-chars-backward " ")
1378 (push (buffer-substring beg (point))
1380 (skip-chars-forward "^,")
1381 (skip-chars-forward ", "))
1384 (defun gnus-inews-add-to-address (group)
1385 (let ((to-address (mail-fetch-field "to")))
1386 (when (and to-address
1388 ;; This mail group doesn't have a `to-list', so we add one
1390 (when (gnus-y-or-n-p
1391 (format "Do you want to add this as `to-list': %s? " to-address))
1392 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1394 (defun gnus-put-message ()
1395 "Put the current message in some group and return to Gnus."
1397 (let ((reply gnus-article-reply)
1398 (winconf gnus-prev-winconf)
1399 (group gnus-newsgroup-name))
1401 (not (gnus-group-read-only-p group)))
1402 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1404 (when (gnus-group-entry group)
1405 (error "No such group: %s" group))
1409 (message-narrow-to-headers)
1410 (let ((gnus-deletable-headers nil))
1411 (message-generate-headers
1412 (if (message-news-p)
1413 message-required-news-headers
1414 message-required-mail-headers)))
1415 (goto-char (point-max))
1416 (if (string-match " " group)
1417 (insert "Gcc: \"" group "\"\n")
1418 (insert "Gcc: " group "\n"))
1421 (when (and (get-buffer gnus-group-buffer)
1422 (gnus-buffer-exists-p (car-safe reply))
1424 (set-buffer (car reply))
1425 (gnus-summary-mark-article-as-replied (cdr reply)))
1427 (set-window-configuration winconf))))
1429 (defun gnus-article-mail (yank)
1430 "Send a reply to the address near point.
1431 If YANK is non-nil, include the original article."
1435 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1436 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1438 (gnus-msg-mail address)
1440 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1442 (defvar nntp-server-type)
1444 "Send a bug report to the Gnus maintainers."
1446 (unless (gnus-alive-p)
1447 (error "Gnus has been shut down"))
1448 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1449 (unless (message-mail-user-agent)
1450 (delete-other-windows)
1451 (when gnus-bug-create-help-buffer
1452 (switch-to-buffer "*Gnus Help Bug*")
1454 (insert gnus-bug-message)
1455 (goto-char (point-min)))
1456 (message-pop-to-buffer "*Gnus Bug*"))
1457 (let ((message-this-is-mail t))
1458 (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1459 (when gnus-bug-create-help-buffer
1460 (push `(gnus-bug-kill-buffer) message-send-actions))
1461 (goto-char (point-min))
1462 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1464 (insert (format "Package: %s\n" gnus-bug-package))
1465 (insert (format "Version: %s\n" (gnus-continuum-version)))
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")
1473 (with-current-buffer (gnus-get-buffer-create " *gnus environment info*")
1476 (setq text (buffer-string)))
1477 (insert "<#part type=application/emacs-lisp disposition=inline description=\"User settings\">\n" text "\n<#/part>"))
1478 (goto-char (point-min))
1479 (search-forward "Subject: " nil t)
1482 (defun gnus-bug-kill-buffer ()
1483 (when (get-buffer "*Gnus Help Bug*")
1484 (kill-buffer "*Gnus Help Bug*")))
1486 (defun gnus-summary-yank-message (buffer n)
1487 "Yank the current article into a composed message."
1489 (list (gnus-completing-read "Buffer" (message-buffers) t)
1490 current-prefix-arg))
1491 (gnus-summary-iterate n
1492 (let ((gnus-inhibit-treatment t))
1493 (gnus-summary-select-article))
1494 (with-current-buffer buffer
1495 (message-yank-buffer gnus-article-buffer))))
1497 (defun gnus-debug ()
1498 "Attempts to go through the Gnus source file and report what variables have been changed.
1499 The source file has to be in the Emacs load path."
1501 (let ((files gnus-debug-files)
1503 file expr olist sym)
1504 (gnus-message 4 "Please wait while we snoop your variables...")
1506 ;; Go through all the files looking for non-default values for variables.
1507 (with-current-buffer (gnus-get-buffer-create " *gnus bug info*")
1510 (when (and (setq file (locate-library (pop files)))
1511 (file-exists-p file))
1512 (insert-file-contents file)
1513 (goto-char (point-min))
1514 (if (not (re-search-forward "^;;* *Internal variables" nil t))
1515 (gnus-message 4 "Malformed sources in file %s" file)
1516 (narrow-to-region (point-min) (point))
1517 (goto-char (point-min))
1518 (while (setq expr (ignore-errors (read (current-buffer))))
1520 (and (or (eq (car expr) 'defvar)
1521 (eq (car expr) 'defcustom))
1522 (stringp (nth 3 expr))
1523 (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1524 (or (not (boundp (nth 1 expr)))
1525 (not (equal (eval (nth 2 expr))
1526 (symbol-value (nth 1 expr)))))
1527 (push (nth 1 expr) olist)))))))
1528 (kill-buffer (current-buffer)))
1529 (when (setq olist (nreverse olist))
1530 (insert "------------------ Environment follows ------------------\n\n"))
1532 (if (boundp (car olist))
1536 ,(if (or (consp (setq sym (symbol-value (car olist))))
1538 (not (or (eq sym nil)
1540 (list 'quote (symbol-value (car olist)))
1541 (symbol-value (car olist))))))
1542 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1543 (setq olist (cdr olist)))
1545 ;; Remove any control chars - they seem to cause trouble for some
1546 ;; mailers. (Byte-compiled output from the stuff above.)
1548 (while (re-search-forward (mm-string-to-multibyte
1549 "[\000-\010\013-\037\200-\237]") nil t)
1550 (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1553 ;;; Treatment of rejected articles.
1556 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1557 "Re-mail the current message.
1558 This only makes sense if the current message is a bounce message that
1559 contains some mail you have written which has been bounced back to
1561 If FETCH, try to fetch the article that this is a reply to, if indeed
1564 (gnus-summary-select-article t)
1565 (let (summary-buffer parent)
1568 (setq summary-buffer (current-buffer))
1569 (set-buffer gnus-original-article-buffer)
1571 (when (re-search-forward "^References:\n?" nil t)
1572 (while (memq (char-after) '(?\t ? ))
1574 (skip-chars-backward "\t\n ")
1576 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1577 (set-buffer gnus-original-article-buffer))
1578 (gnus-setup-message 'compose-bounce
1581 (gnus-inews-insert-gcc)
1582 ;; If there are references, we fetch the article we answered to.
1584 (with-current-buffer summary-buffer
1585 (gnus-summary-refer-article parent)
1586 (gnus-summary-show-all-headers))))))
1590 (defun gnus-inews-group-method (group)
1592 ;; If the group doesn't exist, we assume
1593 ;; it's an archive group...
1594 ((and (null (gnus-get-info group))
1595 (eq (car (gnus-server-to-method gnus-message-archive-method))
1596 (car (gnus-server-to-method (gnus-group-method group)))))
1597 gnus-message-archive-method)
1599 ((gnus-info-method (gnus-get-info group))
1600 (gnus-info-method (gnus-get-info group)))
1602 (t (gnus-server-to-method (gnus-group-method group)))))
1604 ;; Do Gcc handling, which copied the message over to some group.
1605 (defun gnus-inews-do-gcc (&optional gcc)
1609 (message-narrow-to-headers)
1610 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1611 (cur (current-buffer))
1612 groups group method group-art
1613 mml-externalize-attachments)
1615 (message-remove-header "gcc")
1617 (setq groups (message-unquote-tokens
1618 (message-tokenize-header gcc " ,")))
1619 ;; Copy the article over to some group(s).
1620 (while (setq group (pop groups))
1621 (setq method (gnus-inews-group-method group)
1622 group (mm-encode-coding-string
1624 (gnus-group-name-charset method group)))
1625 (unless (gnus-check-server method)
1626 (error "Can't open server %s" (if (stringp method) method
1628 (unless (gnus-request-group group t method)
1629 (gnus-request-create-group group method))
1630 (setq mml-externalize-attachments
1631 (if (stringp gnus-gcc-externalize-attachments)
1632 (string-match gnus-gcc-externalize-attachments group)
1633 gnus-gcc-externalize-attachments))
1635 (nnheader-set-temp-buffer " *acc*")
1636 (insert-buffer-substring cur)
1637 (message-encode-message-body)
1639 (message-narrow-to-headers)
1640 (let* ((mail-parse-charset message-default-charset)
1641 (newsgroups-field (save-restriction
1642 (message-narrow-to-headers-or-head)
1643 (message-fetch-field "Newsgroups")))
1644 (followup-field (save-restriction
1645 (message-narrow-to-headers-or-head)
1646 (message-fetch-field "Followup-To")))
1647 ;; BUG: We really need to get the charset for
1648 ;; each name in the Newsgroups and Followup-To
1649 ;; lines to allow crossposting between group
1650 ;; namess with incompatible character sets.
1651 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1652 (group-field-charset
1653 (gnus-group-name-charset
1654 method (or newsgroups-field "")))
1655 (followup-field-charset
1656 (gnus-group-name-charset
1657 method (or followup-field "")))
1658 (rfc2047-header-encoding-alist
1660 (when group-field-charset
1661 (list (cons "Newsgroups" group-field-charset)))
1662 (when followup-field-charset
1663 (list (cons "Followup-To" followup-field-charset)))
1664 rfc2047-header-encoding-alist)))
1665 (mail-encode-encoded-word-buffer)))
1666 (goto-char (point-min))
1667 (when (re-search-forward
1668 (concat "^" (regexp-quote mail-header-separator) "$")
1670 (replace-match "" t t ))
1671 (when (or (not (gnus-check-backend-function
1672 'request-accept-article group))
1673 (not (setq group-art
1674 (gnus-request-accept-article
1675 group method t t))))
1676 (gnus-message 1 "Couldn't store article in group %s: %s"
1677 group (gnus-status-message method)))
1678 (when (stringp method)
1679 (setq method (gnus-server-to-method method)))
1680 (when (and (listp method)
1681 (gnus-native-method-p method))
1682 (setq group (gnus-group-short-name group)))
1683 (when (and group-art
1684 ;; FIXME: Should gcc-mark-as-read work when
1685 ;; Gnus is not running?
1687 (or gnus-gcc-mark-as-read
1689 (boundp 'gnus-inews-mark-gcc-as-read)
1690 (symbol-value 'gnus-inews-mark-gcc-as-read))))
1691 (gnus-group-mark-article-read group (cdr group-art)))
1692 (kill-buffer (current-buffer)))))))))
1694 (defun gnus-inews-insert-gcc (&optional group)
1695 "Insert the Gcc to say where the article is to be archived."
1696 (let* ((group (or group gnus-newsgroup-name))
1697 (group (when group (gnus-group-decoded-name group)))
1698 (var (or gnus-outgoing-message-group gnus-message-archive-group))
1700 (and group (gnus-group-find-parameter group 'gcc-self)))
1704 ((null gnus-message-archive-method)
1708 ;; Just a single group.
1711 ;; We don't want this.
1713 ((and (listp var) (stringp (car var)))
1714 ;; A list of groups.
1718 (funcall var group))
1720 ;; An alist of regexps/functions/forms.
1725 ((stringp (caar var))
1727 (when (string-match (caar var) group)
1729 ((functionp (car var))
1731 (funcall (car var) group))
1733 (eval (car var)))))))
1734 (setq var (cdr var)))
1737 (when (or groups gcc-self-val)
1738 (when (stringp groups)
1739 (setq groups (list groups)))
1742 (message-narrow-to-headers)
1743 (goto-char (point-max))
1746 ;; Use the `gcc-self' param value instead.
1749 (if (stringp gcc-self-val)
1750 (if (string-match " " gcc-self-val)
1751 (concat "\"" gcc-self-val "\"")
1753 ;; In nndoc groups, we use the parent group name
1754 ;; instead of the current group.
1755 (let ((group (or (gnus-group-find-parameter
1756 gnus-newsgroup-name 'parent-group)
1758 (if (string-match " " group)
1759 (concat "\"" group "\"")
1761 (if (not (eq gcc-self-val 'none))
1763 (gnus-delete-line)))
1764 ;; Use the list of groups.
1765 (while (setq name (pop groups))
1766 (let ((str (if (string-match ":" name)
1768 (gnus-group-prefixed-name
1769 name gnus-message-archive-method))))
1770 (insert (if (string-match " " str)
1771 (concat "\"" str "\"")
1777 (defun gnus-mailing-list-followup-to ()
1778 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1779 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1780 (list-post (gnus-fetch-original-field "list-post")))
1781 (when (and list-post
1782 (string-match "mailto:\\([^>]+\\)" list-post))
1783 (setq list-post (match-string 1 list-post)))
1789 (defun gnus-configure-posting-styles (&optional group-name)
1790 "Configure posting styles according to `gnus-posting-styles'."
1791 (unless gnus-inhibit-posting-styles
1792 (let ((group (or group-name gnus-newsgroup-name ""))
1793 (styles gnus-posting-styles)
1794 style match attribute value v results
1795 filep name address element)
1796 ;; If the group has a posting-style parameter, add it at the end with a
1797 ;; regexp matching everything, to be sure it takes precedence over all
1799 (when gnus-newsgroup-name
1800 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1802 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1803 ;; Go through all styles and look for matches.
1804 (dolist (style styles)
1805 (setq match (pop style))
1806 (goto-char (point-min))
1809 ;; Regexp string match on the group name.
1810 (string-match match group))
1812 ;; Obsolete format of header match.
1813 (and (gnus-buffer-live-p gnus-article-copy)
1814 (with-current-buffer gnus-article-copy
1816 (nnheader-narrow-to-headers)
1817 (let ((header (message-fetch-field (pop style))))
1819 (string-match (pop style) header)))))))
1820 ((or (symbolp match)
1824 ;; Function to be called.
1827 ;; Variable to be checked.
1828 (symbol-value match))))
1831 ((eq (car match) 'header)
1832 ;; New format of header match.
1833 (and (gnus-buffer-live-p gnus-article-copy)
1834 (with-current-buffer gnus-article-copy
1836 (nnheader-narrow-to-headers)
1837 (let ((header (message-fetch-field (nth 1 match))))
1839 (string-match (nth 2 match) header)))))))
1841 ;; This is a form to be evaled.
1843 ;; We have a match, so we set the variables.
1844 (dolist (attribute style)
1845 (setq element (pop attribute)
1849 ((eq (car attribute) :file)
1852 ((eq (car attribute) :value)
1856 ;; We get the value.
1860 (if (and (stringp match)
1861 (gnus-string-match-p "\\\\[&[:digit:]]" value)
1862 (match-beginning 1))
1863 (gnus-match-substitute-replacement value nil nil group)
1865 ((or (symbolp value)
1867 (cond ((functionp value)
1870 (symbol-value value))))
1873 ;; Translate obsolescent value.
1875 ((eq element 'signature-file)
1876 (setq element 'signature
1878 ((eq element 'x-face-file)
1879 (setq element 'x-face
1881 ;; Post-processing for the signature posting-style:
1882 (and (eq element 'signature) filep
1883 message-signature-directory
1884 ;; don't actually use the signature directory
1885 ;; if message-signature-file contains a path.
1886 (not (file-name-directory v))
1887 (setq v (nnheader-concat message-signature-directory v)))
1888 ;; Get the contents of file elems.
1890 (setq v (with-temp-buffer
1891 (insert-file-contents v)
1895 (goto-char (point-max))
1896 (if (zerop (skip-chars-backward "\n"))
1899 (setq results (delq (assoc element results) results))
1900 (push (cons element v) results))))
1901 ;; Now we have all the styles, so we insert them.
1902 (setq name (assq 'name results)
1903 address (assq 'address results))
1904 (setq results (delq name (delq address results)))
1905 (gnus-make-local-hook 'message-setup-hook)
1906 (setq results (sort results (lambda (x y)
1907 (string-lessp (car x) (car y)))))
1908 (dolist (result results)
1909 (add-hook 'message-setup-hook
1911 ((eq 'eval (car result))
1913 ((eq 'body (car result))
1917 (insert ,(cdr result)))))
1918 ((eq 'signature (car result))
1919 (set (make-local-variable 'message-signature) nil)
1920 (set (make-local-variable 'message-signature-file) nil)
1921 (if (not (cdr result))
1925 (let ((message-signature ,(cdr result)))
1926 (when message-signature
1927 (message-insert-signature)))))))
1930 (if (symbolp (car result))
1931 (capitalize (symbol-name (car result)))
1935 (message-remove-header ,header)
1936 (let ((value ,(cdr result)))
1939 (insert ,header ": " value)
1941 (insert "\n")))))))))
1943 (when (or name address)
1944 (add-hook 'message-setup-hook
1946 (set (make-local-variable 'user-mail-address)
1947 ,(or (cdr address) user-mail-address))
1948 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1950 ,(or (cdr address) user-mail-address)))
1952 (message-remove-header "From")
1954 (insert "From: " (message-make-from) "\n"))))
1957 ;;; Allow redefinition of functions.
1963 ;;; gnus-msg.el ends here