1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995-2013 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 (defcustom gnus-gcc-self-resent-messages 'no-gcc-self
167 "Like `gcc-self' group parameter, only for unmodified resent messages.
168 Applied to messages sent by `gnus-summary-resend-message'. Non-nil
169 value of this variable takes precedence over any existing Gcc header.
171 If this is `none', no Gcc copy will be made. If this is t, messages
172 resent will be Gcc'd to the current group. If this is a string, it
173 specifies a group to which resent messages will be Gcc'd. If this is
174 nil, Gcc will be done according to existing Gcc header(s), if any.
175 If this is `no-gcc-self', resent messages will be Gcc'd to groups that
176 existing Gcc header specifies, except for the current group."
179 :type '(choice (const none) (const t) string (const nil)
180 (const no-gcc-self)))
182 (gnus-define-group-parameter
183 posting-charset-alist
186 "Return the permitted unencoded charsets for posting of GROUP."
187 :variable gnus-group-posting-charset-alist
189 '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
190 ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
191 (message-this-is-mail nil nil)
192 (message-this-is-news nil t))
194 "Alist of regexps and permitted unencoded charsets for posting.
195 Each element of the alist has the form (TEST HEADER BODY-LIST), where
196 TEST is either a regular expression matching the newsgroup header or a
198 HEADER is the charset which may be left unencoded in the header (nil
199 means encode all charsets),
200 BODY-LIST is a list of charsets which may be encoded using 8bit
201 content-transfer encoding in the body, or one of the special values
202 nil (always encode using quoted-printable) or t (always use 8bit).
204 Note that any value other than nil for HEADER infringes some RFCs, so
205 use this option with care."
206 :variable-group gnus-charset
208 '(repeat (list :tag "Permitted unencoded charsets"
210 (regexp :tag "Group")
211 (const :tag "Mail message" :value message-this-is-mail)
212 (const :tag "News article" :value message-this-is-news))
213 (choice :tag "Header"
214 (const :tag "None" nil)
215 (symbol :tag "Charset"))
217 (const :tag "Any" :value t)
218 (const :tag "None" :value nil)
219 (repeat :tag "Charsets"
220 (symbol :tag "Charset")))))
221 :parameter-type '(choice :tag "Permitted unencoded charsets"
224 :parameter-document "\
225 List of charsets that are permitted to be unencoded.")
227 (defcustom gnus-debug-files
228 '("gnus.el" "gnus-sum.el" "gnus-group.el"
229 "gnus-art.el" "gnus-start.el" "gnus-async.el"
230 "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
231 "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
232 "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
233 "Files whose variables will be reported in `gnus-bug'."
236 :type '(repeat (string :tag "File")))
238 (defcustom gnus-debug-exclude-variables
239 '(mm-mime-mule-charset-alist
240 nnmail-split-fancy message-minibuffer-local-map)
241 "Variables that should not be reported in `gnus-bug'."
244 :type '(repeat (symbol :tag "Variable")))
246 (defcustom gnus-discouraged-post-methods
247 '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
248 "A list of back ends that are not used in \"real\" newsgroups.
249 This variable is used only when `gnus-post-method' is `current'."
251 :group 'gnus-group-foreign
252 :type '(repeat (symbol :tag "Back end")))
254 (defcustom gnus-message-replysign
256 "Automatically sign replies to signed messages.
257 See also the `mml-default-sign-method' variable."
261 (defcustom gnus-message-replyencrypt t
262 "Automatically encrypt replies to encrypted messages.
263 See also the `mml-default-encrypt-method' variable."
268 (defcustom gnus-message-replysignencrypted
270 "Setting this causes automatically encrypted messages to also be signed."
274 (defcustom gnus-confirm-mail-reply-to-news (and gnus-novice-user
275 (not gnus-expert-user))
276 "If non-nil, Gnus requests confirmation when replying to news.
277 This is done because new users often reply by mistake when reading
279 This can also be a function receiving the group name as the only
280 parameter, which should return non-nil if a confirmation is needed; or
281 a regexp, in which case a confirmation is asked for if the group name
283 :version "23.1" ;; No Gnus (default changed)
285 :type '(choice (const :tag "No" nil)
287 (regexp :tag "If group matches regexp")
288 (function :tag "If function evaluates to non-nil")))
290 (defcustom gnus-confirm-treat-mail-like-news
292 "If non-nil, Gnus will treat mail like news with regard to confirmation
293 when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
294 for fine-tuning this.
295 If nil, Gnus will never ask for confirmation if replying to mail."
300 (defcustom gnus-summary-resend-default-address t
301 "If non-nil, Gnus tries to suggest a default address to resend to.
302 If nil, the address field will always be empty after invoking
303 `gnus-summary-resend-message'."
308 (defcustom gnus-message-highlight-citation
309 t ;; gnus-treat-highlight-citation ;; gnus-cite dependency
310 "Enable highlighting of different citation levels in message-mode."
311 :version "23.1" ;; No Gnus
316 (defcustom gnus-gcc-pre-body-encode-hook nil
317 "A hook called before encoding the body of the Gcc copy of a message.
318 The current buffer (when the hook is run) contains the message
319 including the message header. Changes made to the message will
320 only affect the Gcc copy, but not the original message."
325 (defcustom gnus-gcc-post-body-encode-hook nil
326 "A hook called after encoding the body of the Gcc copy of a message.
327 The current buffer (when the hook is run) contains the message
328 including the message header. Changes made to the message will
329 only affect the Gcc copy, but not the original message."
334 (autoload 'gnus-message-citation-mode "gnus-cite" nil t)
336 ;;; Internal variables.
338 (defvar gnus-inhibit-posting-styles nil
339 "Inhibit the use of posting styles.")
341 (defvar gnus-article-yanked-articles nil)
342 (defvar gnus-message-buffer "*Mail Gnus*")
343 (defvar gnus-article-copy nil)
344 (defvar gnus-check-before-posting nil)
345 (defvar gnus-last-posting-server nil)
346 (defvar gnus-message-group-art nil)
348 (defvar gnus-msg-force-broken-reply-to nil)
350 (defconst gnus-bug-message
351 "Sending a bug report to the Gnus Towers.
352 ========================================
354 The buffer below is a mail buffer. When you press `C-c C-c', it will
355 be sent to the Gnus Bug Exterminators.
357 The thing near the bottom of the buffer is how the environment
358 settings will be included in the mail. Please do not delete that.
359 They will tell the Bug People what your environment is, so that it
360 will be easier to locate the bugs.
362 If you have found a bug that makes Emacs go \"beep\", set
363 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
364 and include the backtrace in your bug report.
366 Please describe the bug in annoying, painstaking detail.
368 Thank you for your help in stamping out bugs.
371 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
375 ;;; Gnus Posting Functions
378 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
379 "p" gnus-summary-post-news
380 "i" gnus-summary-news-other-window
381 "f" gnus-summary-followup
382 "F" gnus-summary-followup-with-original
383 "c" gnus-summary-cancel-article
384 "s" gnus-summary-supersede-article
385 "r" gnus-summary-reply
386 "y" gnus-summary-yank-message
387 "R" gnus-summary-reply-with-original
388 "L" gnus-summary-reply-to-list-with-original
389 "w" gnus-summary-wide-reply
390 "W" gnus-summary-wide-reply-with-original
391 "v" gnus-summary-very-wide-reply
392 "V" gnus-summary-very-wide-reply-with-original
393 "n" gnus-summary-followup-to-mail
394 "N" gnus-summary-followup-to-mail-with-original
395 "m" gnus-summary-mail-other-window
396 "u" gnus-uu-post-news
397 "\M-c" gnus-summary-mail-crosspost-complaint
398 "Br" gnus-summary-reply-broken-reply-to
399 "BR" gnus-summary-reply-broken-reply-to-with-original
400 "om" gnus-summary-mail-forward
401 "op" gnus-summary-post-forward
402 "Om" gnus-uu-digest-mail-forward
403 "Op" gnus-uu-digest-post-forward)
405 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
406 "b" gnus-summary-resend-bounced-mail
407 ;; "c" gnus-summary-send-draft
408 "r" gnus-summary-resend-message
409 "e" gnus-summary-resend-message-edit)
411 ;;; Internal functions.
413 (defun gnus-inews-make-draft (articles)
415 (gnus-inews-make-draft-meta-information
416 ,(gnus-group-decoded-name gnus-newsgroup-name) ',articles)))
418 (autoload 'nnir-article-number "nnir" nil nil 'macro)
419 (autoload 'nnir-article-group "nnir" nil nil 'macro)
420 (autoload 'gnus-nnir-group-p "nnir")
423 (defvar gnus-article-reply nil)
424 (defmacro gnus-setup-message (config &rest forms)
425 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
426 (winconf-name (make-symbol "gnus-setup-message-winconf-name"))
427 (buffer (make-symbol "gnus-setup-message-buffer"))
428 (article (make-symbol "gnus-setup-message-article"))
429 (yanked (make-symbol "gnus-setup-yanked-articles"))
430 (group (make-symbol "gnus-setup-message-group")))
431 `(let ((,winconf (current-window-configuration))
432 (,winconf-name gnus-current-window-configuration)
433 (,buffer (buffer-name (current-buffer)))
434 (,article (if (and (gnus-nnir-group-p gnus-newsgroup-name)
436 (nnir-article-number gnus-article-reply)
438 (,yanked gnus-article-yanked-articles)
439 (,group (if (and (gnus-nnir-group-p gnus-newsgroup-name)
441 (nnir-article-group gnus-article-reply)
442 gnus-newsgroup-name))
443 (message-header-setup-hook
444 (copy-sequence message-header-setup-hook))
445 (mbl mml-buffer-list)
446 (message-mode-hook (copy-sequence message-mode-hook)))
447 (setq mml-buffer-list nil)
448 (add-hook 'message-header-setup-hook (lambda ()
449 (gnus-inews-insert-gcc ,group)))
450 ;; message-newsreader and message-mailer were formerly set in
451 ;; gnus-inews-add-send-actions, but this is too late when
452 ;; message-generate-headers-first is used. --ansel
453 (add-hook 'message-mode-hook
455 (setq message-newsreader
456 (setq message-mailer (gnus-extended-version)))))
457 ;; #### FIXME: for a reason that I did not manage to identify yet,
458 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
459 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
460 ;; After evaluation of @forms below, it gets the value we actually want
461 ;; to override, and the posting styles are used. For that reason, I've
462 ;; added an optional argument to `gnus-configure-posting-styles' to
463 ;; make sure that the correct value for the group name is used. -- drv
464 (add-hook 'message-mode-hook
465 (if (memq ,config '(reply-yank reply))
467 (gnus-configure-posting-styles ,group))
469 ;; There may be an old " *gnus article copy*" buffer.
470 (let (gnus-article-copy)
471 (gnus-configure-posting-styles ,group)))))
472 (gnus-alist-pull ',(intern gnus-draft-meta-information-header)
473 message-required-headers)
475 (not (string= ,group "")))
477 (intern gnus-draft-meta-information-header)
478 (gnus-inews-make-draft (or ,yanked ,article)))
479 message-required-headers))
483 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
484 ,yanked ,winconf-name)
485 (setq gnus-message-buffer (current-buffer))
486 (set (make-local-variable 'gnus-message-group-art)
487 (cons ,group ,article))
488 (set (make-local-variable 'gnus-newsgroup-name) ,group)
489 ;; Enable highlighting of different citation levels
490 (when gnus-message-highlight-citation
491 (gnus-message-citation-mode 1))
492 (gnus-run-hooks 'gnus-message-setup-hook)
493 (if (eq major-mode 'message-mode)
494 (let ((mbl1 mml-buffer-list))
495 (setq mml-buffer-list mbl) ;; Global value
496 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
497 (gnus-make-local-hook 'kill-buffer-hook)
498 (gnus-make-local-hook 'change-major-mode-hook)
499 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
500 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
501 (mml-destroy-buffers)
502 (setq mml-buffer-list mbl)))
503 (message-hide-headers)
505 (gnus-configure-windows ,config t)
506 (run-hooks 'post-command-hook)
507 (set-buffer-modified-p nil))))
509 (defun gnus-inews-make-draft-meta-information (group articles)
510 (when (numberp articles)
511 (setq articles (list articles)))
512 (concat "(\"" group "\""
526 (defun gnus-msg-mail (&optional to subject other-headers continue
527 switch-action yank-action send-actions
529 "Start editing a mail message to be sent.
530 Like `message-mail', but with Gnus paraphernalia, particularly the
531 Gcc: header for archiving purposes.
532 If Gnus isn't running, a plain `message-mail' setup is used
535 (if (not (gnus-alive-p))
537 (message "Gnus not running; using plain Message mode")
538 (message-mail to subject other-headers continue
539 nil yank-action send-actions return-action))
540 (let ((buf (current-buffer))
541 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
543 (gnus-setup-message 'message
544 (message-mail to subject other-headers continue
545 nil yank-action send-actions return-action))
547 (setq mail-buf (current-buffer))
548 (switch-to-buffer buf)
549 (apply switch-action mail-buf nil))
550 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
554 (defun gnus-button-mailto (address)
556 (set-buffer (gnus-copy-article-buffer))
557 (gnus-setup-message 'message
558 (message-reply address)))
561 (defun gnus-button-reply (&optional to-address wide)
562 "Like `message-reply'."
564 (gnus-setup-message 'message
565 (message-reply to-address wide)))
568 (define-mail-user-agent 'gnus-user-agent
569 'gnus-msg-mail 'message-send-and-exit
570 'message-kill-buffer 'message-send-hook)
572 (defun gnus-setup-posting-charset (group)
573 (let ((alist gnus-group-posting-charset-alist)
574 (group (or group ""))
578 (while (setq elem (pop alist))
579 (when (or (and (stringp (car elem))
580 (string-match (car elem) group))
581 (and (functionp (car elem))
582 (funcall (car elem) group))
583 (and (symbolp (car elem))
584 (symbol-value (car elem))))
585 (throw 'found (cons (cadr elem) (caddr elem)))))))))
587 (defun gnus-inews-add-send-actions (winconf buffer article
588 &optional config yanked
590 (gnus-make-local-hook 'message-sent-hook)
591 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
592 'gnus-inews-do-gcc) nil t)
594 (gnus-make-local-hook 'message-header-hook)
595 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
596 (setq message-post-method
597 `(lambda (&optional arg)
598 (gnus-post-method arg ,gnus-newsgroup-name)))
601 (setq gnus-current-window-configuration ',winconf-name)
602 (when (gnus-buffer-exists-p ,buffer)
603 (set-window-configuration ,winconf)))
604 'exit 'postpone 'kill)
605 (let ((to-be-marked (cond
608 (lambda (x) (if (listp x) (car x) x)) yanked))
609 (article (if (listp article) article (list article)))
612 `(when (gnus-buffer-exists-p ,buffer)
613 (with-current-buffer ,buffer
615 (if (eq config 'forward)
616 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
617 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
620 (put 'gnus-setup-message 'lisp-indent-function 1)
621 (put 'gnus-setup-message 'edebug-form-spec '(form body))
623 ;;; Post news commands of Gnus group mode and summary mode
625 (defun gnus-group-mail (&optional arg)
626 "Start composing a mail.
627 If ARG, use the group under the point to find a posting style.
628 If ARG is 1, prompt for a group name to find the posting style."
630 ;; We can't `let' gnus-newsgroup-name here, since that leads
631 ;; to local variables leaking.
632 (let ((group gnus-newsgroup-name)
633 ;; make sure last viewed article doesn't affect posting styles:
635 (buffer (current-buffer)))
638 (setq gnus-newsgroup-name
640 (if (= 1 (prefix-numeric-value arg))
641 (gnus-group-completing-read
642 "Use posting style of group"
643 nil (gnus-read-active-file-p))
644 (gnus-group-group-name))
646 ;; #### see comment in gnus-setup-message -- drv
647 (gnus-setup-message 'message (message-mail)))
648 (with-current-buffer buffer
649 (setq gnus-newsgroup-name group)))))
651 (defun gnus-group-news (&optional arg)
652 "Start composing a news.
653 If ARG, post to group under point.
654 If ARG is 1, prompt for group name to post to.
656 This function prepares a news even when using mail groups. This is useful
657 for posting messages to mail groups without actually sending them over the
658 network. The corresponding back end must have a 'request-post method."
660 ;; We can't `let' gnus-newsgroup-name here, since that leads
661 ;; to local variables leaking.
662 (let ((group gnus-newsgroup-name)
663 ;; make sure last viewed article doesn't affect posting styles:
665 (buffer (current-buffer)))
668 (setq gnus-newsgroup-name
670 (if (= 1 (prefix-numeric-value arg))
671 (gnus-group-completing-read "Use group"
673 (gnus-read-active-file-p))
674 (gnus-group-group-name))
676 ;; #### see comment in gnus-setup-message -- drv
677 (gnus-setup-message 'message
678 (message-news (gnus-group-real-name gnus-newsgroup-name))))
679 (with-current-buffer buffer
680 (setq gnus-newsgroup-name group)))))
682 (defun gnus-group-post-news (&optional arg)
683 "Start composing a message (a news by default).
684 If ARG, post to group under point. If ARG is 1, prompt for group name.
685 Depending on the selected group, the message might be either a mail or
688 ;; Bind this variable here to make message mode hooks work ok.
689 (let ((gnus-newsgroup-name
691 (if (= 1 (prefix-numeric-value arg))
692 (gnus-group-completing-read "Newsgroup" nil
693 (gnus-read-active-file-p))
694 (or (gnus-group-group-name) ""))
696 ;; make sure last viewed article doesn't affect posting styles:
698 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
699 (string= gnus-newsgroup-name ""))))
701 (defun gnus-summary-mail-other-window (&optional arg)
702 "Start composing a mail in another window.
703 Use the posting of the current group by default.
704 If ARG, don't do that. If ARG is 1, prompt for group name to find the
707 ;; We can't `let' gnus-newsgroup-name here, since that leads
708 ;; to local variables leaking.
709 (let ((group gnus-newsgroup-name)
710 ;; make sure last viewed article doesn't affect posting styles:
712 (buffer (current-buffer)))
715 (setq gnus-newsgroup-name
717 (if (= 1 (prefix-numeric-value arg))
718 (gnus-group-completing-read "Use group"
720 (gnus-read-active-file-p))
722 gnus-newsgroup-name))
723 ;; #### see comment in gnus-setup-message -- drv
724 (gnus-setup-message 'message (message-mail)))
725 (with-current-buffer buffer
726 (setq gnus-newsgroup-name group)))))
728 (defun gnus-summary-news-other-window (&optional arg)
729 "Start composing a news in another window.
730 Post to the current group by default.
731 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
733 This function prepares a news even when using mail groups. This is useful
734 for posting messages to mail groups without actually sending them over the
735 network. The corresponding back end must have a 'request-post method."
737 ;; We can't `let' gnus-newsgroup-name here, since that leads
738 ;; to local variables leaking.
739 (let ((group gnus-newsgroup-name)
740 ;; make sure last viewed article doesn't affect posting styles:
742 (buffer (current-buffer)))
745 (setq gnus-newsgroup-name
747 (if (= 1 (prefix-numeric-value arg))
748 (gnus-group-completing-read "Use group"
750 (gnus-read-active-file-p))
752 gnus-newsgroup-name))
753 ;; #### see comment in gnus-setup-message -- drv
754 (gnus-setup-message 'message
756 (message-news (gnus-group-real-name gnus-newsgroup-name))
757 (set (make-local-variable 'gnus-discouraged-post-methods)
759 (car (gnus-find-method-for-group gnus-newsgroup-name))
760 gnus-discouraged-post-methods)))))
761 (with-current-buffer buffer
762 (setq gnus-newsgroup-name group)))))
764 (defun gnus-summary-post-news (&optional arg)
765 "Start composing a message. Post to the current group by default.
766 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
767 Depending on the selected group, the message might be either a mail or
770 ;; Bind this variable here to make message mode hooks work ok.
771 (let ((gnus-newsgroup-name
773 (if (= 1 (prefix-numeric-value arg))
774 (gnus-group-completing-read "Newsgroup" nil
775 (gnus-read-active-file-p))
777 gnus-newsgroup-name))
778 ;; make sure last viewed article doesn't affect posting styles:
780 (gnus-post-news 'post gnus-newsgroup-name)))
783 (defun gnus-summary-followup (yank &optional force-news)
784 "Compose a followup to an article.
785 If prefix argument YANK is non-nil, the original article is yanked
787 YANK is a list of elements, where the car of each element is the
788 article number, and the cdr is the string to be yanked."
790 (list (and current-prefix-arg
791 (gnus-summary-work-articles 1))))
793 (gnus-summary-goto-subject
794 (if (listp (car yank))
797 (save-window-excursion
798 (gnus-summary-select-article))
799 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
800 (gnus-newsgroup-name gnus-newsgroup-name))
802 (gnus-post-news nil gnus-newsgroup-name
803 headers gnus-article-buffer
805 (gnus-summary-handle-replysign)))
807 (defun gnus-summary-followup-with-original (n &optional force-news)
808 "Compose a followup to an article and include the original article.
809 The text in the region will be yanked. If the region isn't
810 active, the entire article will be yanked."
812 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
814 (defun gnus-summary-followup-to-mail (&optional arg)
815 "Followup to the current mail message via news."
817 (list (and current-prefix-arg
818 (gnus-summary-work-articles 1))))
819 (gnus-summary-followup arg t))
821 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
822 "Followup to the current mail message via news."
824 (gnus-summary-followup (gnus-summary-work-articles arg) t))
826 (defun gnus-inews-yank-articles (articles)
827 (let (beg article yank-string)
829 (while (setq article (pop articles))
830 (when (listp article)
831 (setq yank-string (nth 1 article)
832 article (nth 0 article)))
833 (save-window-excursion
834 (set-buffer gnus-summary-buffer)
835 (gnus-summary-select-article nil nil nil article)
836 (gnus-summary-remove-process-mark article))
837 (gnus-copy-article-buffer nil yank-string)
838 (let ((message-reply-buffer gnus-article-copy)
839 (message-reply-headers
840 ;; The headers are decoded.
841 (with-current-buffer gnus-article-copy
843 (nnheader-narrow-to-headers)
844 (nnheader-parse-naked-head)))))
845 (message-yank-original)
846 (message-exchange-point-and-mark)
847 (setq beg (or beg (mark t))))
853 (defun gnus-summary-cancel-article (&optional n symp)
854 "Cancel an article you posted.
855 Uses the process-prefix convention. If given the symbolic
856 prefix `a', cancel using the standard posting method; if not
857 post using the current select method."
858 (interactive (gnus-interactive "P\ny"))
859 (let ((message-post-method
861 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
862 (user-mail-address user-mail-address))
863 (dolist (article (gnus-summary-work-articles n))
864 (when (gnus-summary-select-article t nil nil article)
865 ;; Pretend that we're doing a followup so that we can see what
866 ;; the From header would have ended up being.
867 (save-window-excursion
869 (gnus-summary-followup nil)
870 (let ((from (message-fetch-field "from")))
872 (setq user-mail-address
873 (car (mail-header-parse-address from)))))
874 (kill-buffer (current-buffer))))
875 ;; Now cancel the article using the From header we got.
876 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
877 (message-cancel-news))
878 (gnus-summary-mark-as-read article gnus-canceled-mark)
879 (gnus-cache-remove-article 1))
880 (gnus-article-hide-headers-if-wanted))
881 (gnus-summary-remove-process-mark article))))
883 (defun gnus-summary-supersede-article ()
884 "Compose an article that will supersede a previous article.
885 This is done simply by taking the old article and adding a Supersedes
886 header line with the old Message-ID."
888 (let ((article (gnus-summary-article-number))
889 (mail-parse-charset gnus-newsgroup-charset))
890 (gnus-setup-message 'reply-yank
891 (gnus-summary-select-article t)
892 (set-buffer gnus-original-article-buffer)
896 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
897 (with-current-buffer ,gnus-summary-buffer
898 (gnus-cache-possibly-remove-article ,article nil nil nil t)
899 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
900 message-send-actions)
902 (gnus-inews-insert-gcc))))
906 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
907 ;; make a copy of the article buffer with all text properties removed
908 ;; this copy is in the buffer gnus-article-copy.
909 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
910 ;; this buffer should be passed to all mail/news reply/post routines.
911 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
912 (with-current-buffer gnus-article-copy
913 (mm-enable-multibyte))
914 (let ((article-buffer (or article-buffer gnus-article-buffer))
916 (if (not (and (get-buffer article-buffer)
917 (gnus-buffer-exists-p article-buffer)))
918 (error "Can't find any article buffer")
919 (with-current-buffer article-buffer
920 (let ((gnus-newsgroup-charset (or gnus-article-charset
921 gnus-newsgroup-charset))
922 (gnus-newsgroup-ignored-charsets
923 (or gnus-article-ignored-charsets
924 gnus-newsgroup-ignored-charsets)))
926 ;; Copy over the (displayed) article buffer, delete
927 ;; hidden text and remove text properties.
929 (copy-to-buffer gnus-article-copy (point-min) (point-max))
930 (set-buffer gnus-article-copy)
933 (delete-region (point) (point-max))
934 (insert yank-string))
935 (gnus-article-delete-text-of-type 'annotation)
936 (gnus-article-delete-text-of-type 'multipart)
937 (gnus-remove-text-with-property 'gnus-prev)
938 (gnus-remove-text-with-property 'gnus-next)
939 (gnus-remove-text-with-property 'gnus-decoration)
942 (buffer-substring-no-properties (point-min) (point-max))
944 ;; Find the original headers.
945 (set-buffer gnus-original-article-buffer)
946 (goto-char (point-min))
947 (while (looking-at message-unix-mail-delimiter)
949 (let ((mail-header-separator ""))
951 end (or (message-goto-body)
952 ;; There may be just a header.
954 ;; Delete the headers from the displayed articles.
955 (set-buffer gnus-article-copy)
956 (let ((mail-header-separator ""))
957 (delete-region (goto-char (point-min))
958 (or (message-goto-body) (point-max))))
959 ;; Insert the original article headers.
960 (insert-buffer-substring gnus-original-article-buffer beg end)
962 (let ((gnus-article-decode-hook
963 (delq 'article-decode-charset
964 (copy-sequence gnus-article-decode-hook)))
965 (rfc2047-quote-decoded-words-containing-tspecials t))
966 (run-hooks 'gnus-article-decode-hook)))))
969 (defun gnus-post-news (post &optional group header article-buffer yank subject
972 (gnus-copy-article-buffer))
973 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
974 (gnus-article-yanked-articles yank)
975 (add-to-list gnus-add-to-list))
976 (gnus-setup-message (cond (yank 'reply-yank)
977 (article-buffer 'reply)
979 (let* ((group (or group gnus-newsgroup-name))
980 (charset (gnus-group-name-charset nil group))
982 to-address to-group mailing-list to-list
985 (setq to-address (gnus-parameter-to-address group)
986 to-group (gnus-group-find-parameter group 'to-group)
987 to-list (gnus-parameter-to-list group)
988 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
989 mailing-list (when gnus-mailing-list-groups
990 (string-match gnus-mailing-list-groups group))
991 group (gnus-group-name-decode (gnus-group-real-name group)
993 (if (or (and to-group
994 (gnus-news-group-p to-group))
997 (and (gnus-news-group-p
998 (or pgroup gnus-newsgroup-name)
999 (or header gnus-current-article))
1007 (and (not (gnus-virtual-group-p pgroup)) group)))
1008 (set-buffer gnus-article-copy)
1009 (gnus-msg-treat-broken-reply-to)
1010 (message-followup (if (or newsgroup-p force-news)
1011 (if (save-restriction
1012 (article-narrow-to-head)
1013 (message-fetch-field "newsgroups"))
1020 (message-mail (or to-address to-list))
1021 ;; Arrange for mail groups that have no `to-address' to
1022 ;; get that when the user sends off the mail.
1023 (when (and (not to-list)
1026 (push (list 'gnus-inews-add-to-address pgroup)
1027 message-send-actions)))
1028 (set-buffer gnus-article-copy)
1029 (gnus-msg-treat-broken-reply-to)
1030 (message-wide-reply to-address)))
1032 (gnus-inews-yank-articles yank))))))
1034 (defun gnus-msg-treat-broken-reply-to (&optional force)
1035 "Remove the Reply-to header if broken-reply-to."
1037 (gnus-group-find-parameter
1038 gnus-newsgroup-name 'broken-reply-to))
1040 (message-narrow-to-head)
1041 (message-remove-header "reply-to"))))
1043 (defun gnus-post-method (arg group &optional silent)
1044 "Return the posting method based on GROUP and ARG.
1045 If SILENT, don't prompt the user."
1046 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1048 (group-method (gnus-find-method-for-group group)))
1050 ;; If the group-method is nil (which shouldn't happen) we use
1051 ;; the default method.
1052 ((null group-method)
1053 (or (and (listp gnus-post-method) ;If not current/native/nil
1054 (not (listp (car gnus-post-method))) ; and not a list of methods
1055 gnus-post-method) ;then use it.
1057 message-post-method))
1058 ;; We want the inverse of the default
1059 ((and arg (not (eq arg 0)))
1060 (if (eq gnus-post-method 'current)
1063 ;; We query the user for a post method.
1065 (and (listp gnus-post-method)
1066 (listp (car gnus-post-method))))
1068 ;; Collect all methods we know about.
1070 (when (listp gnus-post-method)
1071 (if (listp (car gnus-post-method))
1073 (list gnus-post-method)))
1074 gnus-secondary-select-methods
1075 (mapcar 'cdr gnus-server-alist)
1076 (mapcar 'car gnus-opened-servers)
1077 (list gnus-select-method)
1078 (list group-method)))
1079 method-alist post-methods method)
1080 ;; Weed out all mail methods.
1082 (setq method (gnus-server-get-method "" (pop methods)))
1083 (when (and (or (gnus-method-option-p method 'post)
1084 (gnus-method-option-p method 'post-mail))
1085 (not (member method post-methods)))
1086 (push method post-methods)))
1087 ;; Create a name-method alist.
1091 (if (equal (cadr m) "")
1092 (list (symbol-name (car m)) m)
1093 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1098 (setq gnus-last-posting-server
1100 gnus-last-posting-server)
1101 ;; Just use the last value.
1102 gnus-last-posting-server
1103 (gnus-completing-read
1104 "Posting method" (mapcar 'car method-alist) t
1105 (cons (or gnus-last-posting-server "") 0))))
1107 ;; Override normal method.
1108 ((and (eq gnus-post-method 'current)
1109 (not (memq (car group-method) gnus-discouraged-post-methods))
1110 (gnus-get-function group-method 'request-post t))
1113 ;; Use gnus-post-method.
1114 ((listp gnus-post-method) ;A method...
1115 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1117 ;; Use the normal select method (nil or native).
1118 (t gnus-select-method))))
1122 (defun gnus-extended-version ()
1123 "Stringified Gnus version and Emacs version.
1124 See the variable `gnus-user-agent'."
1126 (if (stringp gnus-user-agent)
1128 ;; `gnus-user-agent' is a list:
1129 (let* ((float-output-format nil)
1131 (when (memq 'gnus gnus-user-agent)
1133 (prin1-to-string (gnus-continuum-version gnus-version) t)
1134 " (" gnus-version ")")))
1135 (emacs-v (gnus-emacs-version)))
1136 (concat gnus-v (when (and gnus-v emacs-v) " ")
1141 ;;; Gnus Mail Functions
1144 ;;; Mail reply commands of Gnus summary mode
1146 (defun gnus-summary-reply (&optional yank wide very-wide)
1147 "Start composing a mail reply to the current message.
1148 If prefix argument YANK is non-nil, the original article is yanked
1150 If WIDE, make a wide reply.
1151 If VERY-WIDE, make a very wide reply."
1153 (list (and current-prefix-arg
1154 (gnus-summary-work-articles 1))))
1155 ;; Allow user to require confirmation before replying by mail to the
1156 ;; author of a news article (or mail message).
1157 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1158 gnus-confirm-treat-mail-like-news))
1159 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1160 (string-match gnus-confirm-mail-reply-to-news
1161 gnus-newsgroup-name))
1162 ((functionp gnus-confirm-mail-reply-to-news)
1163 (funcall gnus-confirm-mail-reply-to-news
1164 gnus-newsgroup-name))
1165 (t gnus-confirm-mail-reply-to-news)))
1166 (if (or wide very-wide)
1167 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1169 (y-or-n-p "Really reply by mail to article author? ")))
1171 (if (listp (car yank))
1174 (gnus-article-reply (or article (gnus-summary-article-number)))
1175 (gnus-article-yanked-articles yank)
1177 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1179 (gnus-summary-goto-subject article))
1180 (gnus-setup-message (if yank 'reply-yank 'reply)
1182 (gnus-summary-select-article)
1183 (dolist (article very-wide)
1184 (gnus-summary-select-article nil nil nil article)
1185 (with-current-buffer (gnus-copy-article-buffer)
1186 (gnus-msg-treat-broken-reply-to)
1188 (message-narrow-to-head)
1189 (setq headers (concat headers (buffer-string)))))))
1190 (set-buffer (gnus-copy-article-buffer))
1191 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1193 (message-narrow-to-head)
1197 (goto-char (point-max)))
1198 (mml-quote-region (point) (point-max))
1199 (message-reply nil wide)
1201 (gnus-inews-yank-articles yank))
1202 (gnus-summary-handle-replysign)))))
1204 (defun gnus-summary-handle-replysign ()
1205 "Check the various replysign variables and take action accordingly."
1206 (when (or gnus-message-replysign gnus-message-replyencrypt)
1207 (let (signed encrypted)
1208 (with-current-buffer gnus-article-buffer
1209 (setq signed (memq 'signed gnus-article-wash-types))
1210 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1211 (cond ((and gnus-message-replyencrypt encrypted)
1212 (mml-secure-message mml-default-encrypt-method
1213 (if gnus-message-replysignencrypted
1216 ((and gnus-message-replysign signed)
1217 (mml-secure-message mml-default-sign-method 'sign))))))
1219 (defun gnus-summary-reply-with-original (n &optional wide)
1220 "Start composing a reply mail to the current message.
1221 The original article will be yanked."
1223 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1225 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1226 "Start composing a reply mail to the current message.
1227 The reply goes only to the mailing list.
1228 The original article will be yanked."
1230 (let ((message-reply-to-function
1232 `((To . ,(gnus-mailing-list-followup-to))))))
1233 (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1235 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1236 "Like `gnus-summary-reply' except removing reply-to field.
1237 If prefix argument YANK is non-nil, the original article is yanked
1239 If WIDE, make a wide reply.
1240 If VERY-WIDE, make a very wide reply."
1242 (list (and current-prefix-arg
1243 (gnus-summary-work-articles 1))))
1244 (let ((gnus-msg-force-broken-reply-to t))
1245 (gnus-summary-reply yank wide very-wide)))
1247 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1248 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1249 The original article will be yanked."
1251 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1253 (defun gnus-summary-wide-reply (&optional yank)
1254 "Start composing a wide reply mail to the current message.
1255 If prefix argument YANK is non-nil, the original article is yanked
1258 (list (and current-prefix-arg
1259 (gnus-summary-work-articles 1))))
1260 (gnus-summary-reply yank t))
1262 (defun gnus-summary-wide-reply-with-original (n)
1263 "Start composing a wide reply mail to the current message.
1264 The original article will be yanked.
1265 Uses the process/prefix convention."
1267 (gnus-summary-reply-with-original n t))
1269 (defun gnus-summary-very-wide-reply (&optional yank)
1270 "Start composing a very wide reply mail to the current message.
1271 If prefix argument YANK is non-nil, the original article is yanked
1274 (list (and current-prefix-arg
1275 (gnus-summary-work-articles 1))))
1276 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1278 (defun gnus-summary-very-wide-reply-with-original (n)
1279 "Start composing a very wide reply mail to the current message.
1280 The original article will be yanked."
1283 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1285 (defun gnus-summary-mail-forward (&optional arg post)
1286 "Forward the current message(s) to another user.
1287 If process marks exist, forward all marked messages;
1288 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1289 if ARG is 1, decode the message and forward directly inline;
1290 if ARG is 2, forward message as an rfc822 MIME section;
1291 if ARG is 3, decode message and forward as an rfc822 MIME section;
1292 if ARG is 4, forward message directly inline;
1293 otherwise, use flipped `message-forward-as-mime'.
1294 If POST, post instead of mail.
1295 For the \"inline\" alternatives, also see the variable
1296 `message-forward-ignored-headers'."
1298 (if (cdr (gnus-summary-work-articles nil))
1299 ;; Process marks are given.
1300 (gnus-uu-digest-mail-forward nil post)
1301 ;; No process marks.
1302 (let ((message-forward-as-mime message-forward-as-mime)
1303 (message-forward-show-mml message-forward-show-mml))
1307 (setq message-forward-as-mime nil
1308 message-forward-show-mml t))
1310 (setq message-forward-as-mime t
1311 message-forward-show-mml nil))
1313 (setq message-forward-as-mime t
1314 message-forward-show-mml t))
1316 (setq message-forward-as-mime nil
1317 message-forward-show-mml nil))
1319 (setq message-forward-as-mime (not message-forward-as-mime))))
1320 (let* ((gnus-article-reply (gnus-summary-article-number))
1321 (gnus-article-yanked-articles (list gnus-article-reply)))
1322 (gnus-setup-message 'forward
1323 (gnus-summary-select-article)
1324 (let ((mail-parse-charset
1325 (or (and (gnus-buffer-live-p gnus-article-buffer)
1326 (with-current-buffer gnus-article-buffer
1327 gnus-article-charset))
1328 gnus-newsgroup-charset))
1329 (mail-parse-ignored-charsets
1330 gnus-newsgroup-ignored-charsets))
1331 (set-buffer gnus-original-article-buffer)
1332 (message-forward post)))))))
1334 (defun gnus-summary-resend-message-insert-gcc ()
1335 "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1336 (gnus-inews-insert-gcc)
1339 (mm-encode-coding-string
1341 (gnus-group-name-charset (gnus-inews-group-method group)
1343 (message-unquote-tokens
1344 (message-tokenize-header (mail-fetch-field "gcc" nil t)
1346 (self (with-current-buffer gnus-summary-buffer
1347 gnus-gcc-self-resent-messages)))
1348 (message-remove-header "gcc")
1350 (goto-char (point-max))
1351 (cond ((eq self 'none))
1353 (insert "Gcc: \"" gnus-newsgroup-name "\"\n"))
1356 (mm-encode-coding-string
1357 (if (string-match " " self)
1358 (concat "\"" self "\"")
1360 (gnus-group-name-charset (gnus-inews-group-method self)
1364 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n"))
1365 ((eq self 'no-gcc-self)
1366 (when (setq gcc (delete
1368 (delete (concat "\"" gnus-newsgroup-name "\"")
1370 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n")))))))
1372 (defun gnus-summary-resend-message (address n)
1373 "Resend the current article to ADDRESS."
1375 (list (message-read-from-minibuffer
1376 "Resend message(s) to: "
1377 (when (and gnus-summary-resend-default-address
1378 (gnus-buffer-live-p gnus-original-article-buffer))
1379 ;; If some other article is currently selected, the
1380 ;; initial-contents is wrong. Whatever, it is just the
1381 ;; initial-contents.
1382 (with-current-buffer gnus-original-article-buffer
1383 (nnmail-fetch-field "to"))))
1384 current-prefix-arg))
1385 (let ((message-header-setup-hook (copy-sequence message-header-setup-hook))
1386 (message-sent-hook (copy-sequence message-sent-hook))
1387 ;; Honor posting-style for `name' and `address' in Resent-From header.
1388 (styles (gnus-group-find-parameter gnus-newsgroup-name
1390 (user-full-name user-full-name)
1391 (user-mail-address user-mail-address)
1393 (dolist (style styles)
1394 (when (stringp (cadr style))
1395 (setcdr style (list (mm-decode-coding-string (cadr style) 'utf-8)))))
1396 (dolist (style (if styles
1397 (append gnus-posting-styles (list (cons ".*" styles)))
1398 gnus-posting-styles))
1399 (when (and (stringp (car style))
1400 (string-match (pop style) gnus-newsgroup-name))
1401 (when (setq tem (cadr (assq 'name style)))
1402 (setq user-full-name tem))
1403 (when (setq tem (cadr (assq 'address style)))
1404 (setq user-mail-address tem))))
1405 ;; `gnus-summary-resend-message-insert-gcc' must run last.
1406 (add-hook 'message-header-setup-hook
1407 'gnus-summary-resend-message-insert-gcc t)
1408 (add-hook 'message-sent-hook
1410 (let ((rfc2047-encode-encoded-words nil))
1412 '(gnus-agent-possibly-do-gcc)
1413 '(gnus-inews-do-gcc)))))
1414 (dolist (article (gnus-summary-work-articles n))
1415 (gnus-summary-select-article nil nil nil article)
1416 (with-current-buffer gnus-original-article-buffer
1417 (let ((gnus-gcc-externalize-attachments nil)
1418 (message-inhibit-body-encoding t))
1419 (message-resend address)))
1420 (gnus-summary-mark-article-as-forwarded article))))
1422 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1423 (defun gnus-summary-resend-message-edit ()
1424 "Resend an article that has already been sent.
1425 A new buffer will be created to allow the user to modify body and
1426 contents of the message, and then, everything will happen as when
1427 composing a new message."
1429 (let ((mail-parse-charset gnus-newsgroup-charset))
1430 (gnus-setup-message 'reply-yank
1431 (gnus-summary-select-article t)
1432 (set-buffer gnus-original-article-buffer)
1433 (let ((cur (current-buffer))
1434 (to (message-fetch-field "to")))
1435 ;; Get a normal message buffer.
1436 (message-pop-to-buffer (message-buffer-name "Resend" to))
1437 (insert-buffer-substring cur)
1439 (message-narrow-to-head-1)
1440 ;; Gnus will generate a new one when sending.
1441 (message-remove-header "Message-ID")
1442 ;; Remove unwanted headers.
1443 (message-remove-header message-ignored-resent-headers t)
1444 (goto-char (point-max))
1445 (insert mail-header-separator)
1447 (gnus-inews-insert-gcc)
1448 (goto-char (point-min))
1449 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1453 (defun gnus-summary-post-forward (&optional arg)
1454 "Forward the current article to a newsgroup.
1455 See `gnus-summary-mail-forward' for ARG."
1457 (gnus-summary-mail-forward arg t))
1459 (defun gnus-summary-mail-crosspost-complaint (n)
1460 "Send a complaint about crossposting to the current article(s)."
1462 (dolist (article (gnus-summary-work-articles n))
1463 (set-buffer gnus-summary-buffer)
1464 (gnus-summary-goto-subject article)
1465 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1466 newsgroups followup-to)
1467 (gnus-summary-select-article)
1468 (set-buffer gnus-original-article-buffer)
1469 (if (and (<= (length (message-tokenize-header
1471 (mail-fetch-field "newsgroups"))
1474 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1475 (not (member group (message-tokenize-header
1476 followup-to ", ")))))
1478 (gnus-message 1 "Followup-to restricted")
1479 (gnus-message 1 "Not a crossposted article"))
1480 (set-buffer gnus-summary-buffer)
1481 (gnus-summary-reply-with-original 1)
1482 (set-buffer gnus-message-buffer)
1484 (insert (format gnus-crosspost-complaint newsgroups group))
1485 (message-goto-subject)
1486 (re-search-forward " *$")
1487 (replace-match " (crosspost notification)" t t)
1488 (gnus-deactivate-mark)
1489 (when (gnus-y-or-n-p "Send this complaint? ")
1490 (message-send-and-exit))))))
1492 (defun gnus-inews-add-to-address (group)
1493 (let ((to-address (mail-fetch-field "to")))
1494 (when (and to-address
1496 ;; This mail group doesn't have a `to-list', so we add one
1498 (when (gnus-y-or-n-p
1499 (format "Do you want to add this as `to-list': %s? " to-address))
1500 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1502 (defun gnus-article-mail (yank)
1503 "Send a reply to the address near point.
1504 If YANK is non-nil, include the original article."
1508 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1509 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1511 (gnus-msg-mail address)
1513 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1515 (defvar nntp-server-type)
1517 "Send a bug report to the Gnus maintainers."
1519 (unless (gnus-alive-p)
1520 (error "Gnus has been shut down"))
1521 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1522 (unless (message-mail-user-agent)
1523 (when gnus-bug-create-help-buffer
1524 (switch-to-buffer "*Gnus Help Bug*")
1526 (insert gnus-bug-message)
1527 (goto-char (point-min)))
1528 (message-pop-to-buffer "*Gnus Bug*"))
1529 (let ((message-this-is-mail t))
1530 (message-setup `((To . ,gnus-maintainer)
1533 . ,(format "%s" gnus-bug-package))
1535 . ,(format "%s" (gnus-continuum-version))))))
1536 (when gnus-bug-create-help-buffer
1537 (push `(gnus-bug-kill-buffer) message-send-actions))
1538 (goto-char (point-min))
1540 (insert "\n\n\n\n\n")
1541 (insert (gnus-version) "\n"
1542 (emacs-version) "\n")
1543 (when (and (boundp 'nntp-server-type)
1544 (stringp nntp-server-type))
1545 (insert nntp-server-type))
1546 (goto-char (point-min))
1547 (search-forward "Subject: " nil t)
1550 (defun gnus-bug-kill-buffer ()
1551 (when (get-buffer "*Gnus Help Bug*")
1552 (kill-buffer "*Gnus Help Bug*")))
1554 (defun gnus-summary-yank-message (buffer n)
1555 "Yank the current article into a composed message."
1557 (list (gnus-completing-read "Buffer" (message-buffers) t)
1558 current-prefix-arg))
1559 (gnus-summary-iterate n
1560 (let ((gnus-inhibit-treatment t))
1561 (gnus-summary-select-article))
1562 (with-current-buffer buffer
1563 (message-yank-buffer gnus-article-buffer))))
1565 ;;; Treatment of rejected articles.
1568 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1569 "Re-mail the current message.
1570 This only makes sense if the current message is a bounce message that
1571 contains some mail you have written which has been bounced back to
1573 If FETCH, try to fetch the article that this is a reply to, if indeed
1576 (gnus-summary-select-article t)
1577 (let (summary-buffer parent)
1580 (setq summary-buffer (current-buffer))
1581 (set-buffer gnus-original-article-buffer)
1583 (when (re-search-forward "^References:\n?" nil t)
1584 (while (memq (char-after) '(?\t ? ))
1586 (skip-chars-backward "\t\n ")
1588 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1589 (set-buffer gnus-original-article-buffer))
1590 (gnus-setup-message 'compose-bounce
1593 (gnus-inews-insert-gcc)
1594 ;; If there are references, we fetch the article we answered to.
1596 (with-current-buffer summary-buffer
1597 (gnus-summary-refer-article parent)
1598 (gnus-summary-show-all-headers))))))
1602 (defun gnus-inews-group-method (group)
1604 ;; If the group doesn't exist, we assume
1605 ;; it's an archive group...
1606 ((and (null (gnus-get-info group))
1607 (eq (car (gnus-server-to-method gnus-message-archive-method))
1608 (car (gnus-server-to-method (gnus-group-method group)))))
1609 gnus-message-archive-method)
1611 ((gnus-info-method (gnus-get-info group))
1612 (gnus-info-method (gnus-get-info group)))
1614 (t (gnus-server-to-method (gnus-group-method group)))))
1616 ;; Do Gcc handling, which copied the message over to some group.
1617 (defun gnus-inews-do-gcc (&optional gcc)
1621 (message-narrow-to-headers)
1622 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1623 (cur (current-buffer))
1624 groups group method group-art options
1625 mml-externalize-attachments)
1627 (message-remove-header "gcc")
1629 (setq groups (message-unquote-tokens
1630 (message-tokenize-header gcc " ,")))
1631 ;; Copy the article over to some group(s).
1632 (while (setq group (pop groups))
1633 (setq method (gnus-inews-group-method group)
1634 group (mm-encode-coding-string
1636 (gnus-group-name-charset method group)))
1637 (unless (gnus-check-server method)
1638 (error "Can't open server %s" (if (stringp method) method
1640 (unless (gnus-request-group group t method)
1641 (gnus-request-create-group group method))
1642 (setq mml-externalize-attachments
1643 (if (stringp gnus-gcc-externalize-attachments)
1644 (string-match gnus-gcc-externalize-attachments group)
1645 gnus-gcc-externalize-attachments))
1647 (nnheader-set-temp-buffer " *acc*")
1648 (setq message-options (with-current-buffer cur message-options))
1649 (insert-buffer-substring cur)
1650 (run-hooks 'gnus-gcc-pre-body-encode-hook)
1651 (message-encode-message-body)
1652 (run-hooks 'gnus-gcc-post-body-encode-hook)
1654 (message-narrow-to-headers)
1655 (let* ((mail-parse-charset message-default-charset)
1656 (newsgroups-field (save-restriction
1657 (message-narrow-to-headers-or-head)
1658 (message-fetch-field "Newsgroups")))
1659 (followup-field (save-restriction
1660 (message-narrow-to-headers-or-head)
1661 (message-fetch-field "Followup-To")))
1662 ;; BUG: We really need to get the charset for
1663 ;; each name in the Newsgroups and Followup-To
1664 ;; lines to allow crossposting between group
1665 ;; names with incompatible character sets.
1666 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1667 (group-field-charset
1668 (gnus-group-name-charset
1669 method (or newsgroups-field "")))
1670 (followup-field-charset
1671 (gnus-group-name-charset
1672 method (or followup-field "")))
1673 (rfc2047-header-encoding-alist
1675 (when group-field-charset
1676 (list (cons "Newsgroups" group-field-charset)))
1677 (when followup-field-charset
1678 (list (cons "Followup-To" followup-field-charset)))
1679 rfc2047-header-encoding-alist)))
1680 (mail-encode-encoded-word-buffer)))
1681 (goto-char (point-min))
1682 (when (re-search-forward
1683 (concat "^" (regexp-quote mail-header-separator) "$")
1685 (replace-match "" t t ))
1686 (when (or (not (gnus-check-backend-function
1687 'request-accept-article group))
1688 (not (setq group-art
1689 (gnus-request-accept-article
1690 group method t t))))
1691 (gnus-message 1 "Couldn't store article in group %s: %s"
1692 group (gnus-status-message method)))
1693 (when (stringp method)
1694 (setq method (gnus-server-to-method method)))
1695 (when (and (listp method)
1696 (gnus-native-method-p method))
1697 (setq group (gnus-group-short-name group)))
1698 (when (and group-art
1699 ;; FIXME: Should gcc-mark-as-read work when
1700 ;; Gnus is not running?
1702 (if (or gnus-gcc-mark-as-read
1703 (and (boundp 'gnus-inews-mark-gcc-as-read)
1704 (symbol-value 'gnus-inews-mark-gcc-as-read)))
1705 (gnus-group-mark-article-read group (cdr group-art))
1706 (with-current-buffer gnus-group-buffer
1707 (let ((gnus-group-marked (list group))
1708 (gnus-get-new-news-hook nil)
1709 (inhibit-read-only t))
1710 (gnus-group-get-new-news-this-group nil t)))))
1711 (setq options message-options)
1712 (with-current-buffer cur (setq message-options options))
1713 (kill-buffer (current-buffer)))))))))
1715 (defun gnus-inews-insert-gcc (&optional group)
1716 "Insert the Gcc to say where the article is to be archived."
1717 (let* ((group (or group gnus-newsgroup-name))
1718 (group (when group (gnus-group-decoded-name group)))
1719 (var (or gnus-outgoing-message-group gnus-message-archive-group))
1721 (and group (gnus-group-find-parameter group 'gcc-self)
1722 (not (gnus-virtual-group-p group))))
1726 ((null gnus-message-archive-method)
1730 ;; Just a single group.
1733 ;; We don't want this.
1735 ((and (listp var) (stringp (car var)))
1736 ;; A list of groups.
1740 (funcall var group))
1742 ;; An alist of regexps/functions/forms.
1748 (stringp (caar var)))
1750 (when (string-match (caar var) group)
1753 (functionp (car var)))
1755 (funcall (car var) group))
1757 (eval (car var)))))))
1758 (setq var (cdr var)))
1761 (when (and (or groups gcc-self-val)
1763 (when (stringp groups)
1764 (setq groups (list groups)))
1767 (message-narrow-to-headers)
1768 (goto-char (point-max))
1771 ;; Use the `gcc-self' param value instead.
1774 (if (stringp gcc-self-val)
1775 (if (string-match " " gcc-self-val)
1776 (concat "\"" gcc-self-val "\"")
1778 ;; In nndoc groups, we use the parent group name
1779 ;; instead of the current group.
1780 (let ((group (or (gnus-group-find-parameter
1781 gnus-newsgroup-name 'parent-group)
1783 (if (string-match " " group)
1784 (concat "\"" group "\"")
1786 (if (not (eq gcc-self-val 'none))
1788 (gnus-delete-line)))
1789 ;; Use the list of groups.
1790 (while (setq name (pop groups))
1791 (let ((str (if (string-match ":" name)
1793 (gnus-group-prefixed-name
1794 name gnus-message-archive-method))))
1795 (insert (if (string-match " " str)
1796 (concat "\"" str "\"")
1802 (defun gnus-mailing-list-followup-to ()
1803 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1804 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1805 (list-post (gnus-fetch-original-field "list-post")))
1806 (when (and list-post
1807 (string-match "mailto:\\([^>]+\\)" list-post))
1808 (setq list-post (match-string 1 list-post)))
1814 (defun gnus-configure-posting-styles (&optional group-name)
1815 "Configure posting styles according to `gnus-posting-styles'."
1816 (unless gnus-inhibit-posting-styles
1817 (let ((group (or group-name gnus-newsgroup-name ""))
1818 (styles (if (gnus-buffer-live-p gnus-summary-buffer)
1819 (with-current-buffer gnus-summary-buffer
1820 gnus-posting-styles)
1821 gnus-posting-styles))
1822 style match attribute value v results
1823 filep name address element)
1824 ;; If the group has a posting-style parameter, add it at the end with a
1825 ;; regexp matching everything, to be sure it takes precedence over all
1827 (when gnus-newsgroup-name
1828 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1830 (dolist (style tmp-style)
1831 (when (stringp (cadr style))
1832 (setcdr style (list (mm-decode-coding-string (cadr style)
1834 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1835 ;; Go through all styles and look for matches.
1836 (dolist (style styles)
1837 (setq match (pop style))
1838 (goto-char (point-min))
1841 ;; Regexp string match on the group name.
1842 (string-match match group))
1844 ;; Obsolete format of header match.
1845 (and (gnus-buffer-live-p gnus-article-copy)
1846 (with-current-buffer gnus-article-copy
1848 (nnheader-narrow-to-headers)
1849 (let ((header (message-fetch-field (pop style))))
1851 (string-match (pop style) header)))))))
1852 ((or (symbolp match)
1856 ;; Function to be called.
1859 ;; Variable to be checked.
1860 (symbol-value match))))
1863 ((eq (car match) 'header)
1864 ;; New format of header match.
1865 (and (gnus-buffer-live-p gnus-article-copy)
1866 (with-current-buffer gnus-article-copy
1868 (nnheader-narrow-to-headers)
1869 (let ((header (message-fetch-field (nth 1 match))))
1871 (string-match (nth 2 match) header)))))))
1873 ;; This is a form to be evalled.
1875 ;; We have a match, so we set the variables.
1876 (dolist (attribute style)
1877 (setq element (pop attribute)
1881 ((eq (car attribute) :file)
1884 ((eq (car attribute) :value)
1888 ;; We get the value.
1892 (if (and (stringp match)
1893 (gnus-string-match-p "\\\\[&[:digit:]]" value)
1894 (match-beginning 1))
1895 (gnus-match-substitute-replacement value nil nil group)
1897 ((or (symbolp value)
1899 (cond ((functionp value)
1902 (symbol-value value))))
1905 ;; Translate obsolescent value.
1907 ((eq element 'signature-file)
1908 (setq element 'signature
1910 ((eq element 'x-face-file)
1911 (setq element 'x-face
1913 ;; Post-processing for the signature posting-style:
1914 (and (eq element 'signature) filep
1915 message-signature-directory
1916 ;; don't actually use the signature directory
1917 ;; if message-signature-file contains a path.
1918 (not (file-name-directory v))
1919 (setq v (nnheader-concat message-signature-directory v)))
1920 ;; Get the contents of file elems.
1922 (setq v (with-temp-buffer
1923 (insert-file-contents v)
1927 (goto-char (point-max))
1928 (if (zerop (skip-chars-backward "\n"))
1931 (setq results (delq (assoc element results) results))
1932 (push (cons element v) results))))
1933 ;; Now we have all the styles, so we insert them.
1934 (setq name (assq 'name results)
1935 address (assq 'address results))
1936 (setq results (delq name (delq address results)))
1937 (gnus-make-local-hook 'message-setup-hook)
1938 (setq results (sort results (lambda (x y)
1939 (string-lessp (car x) (car y)))))
1940 (dolist (result results)
1941 (add-hook 'message-setup-hook
1943 ((eq 'eval (car result))
1945 ((eq 'body (car result))
1949 (insert ,(cdr result)))))
1950 ((eq 'signature (car result))
1951 (set (make-local-variable 'message-signature) nil)
1952 (set (make-local-variable 'message-signature-file) nil)
1953 (if (not (cdr result))
1957 (let ((message-signature ,(cdr result)))
1958 (when message-signature
1959 (message-insert-signature)))))))
1962 (if (symbolp (car result))
1963 (capitalize (symbol-name (car result)))
1967 (message-remove-header ,header)
1968 (let ((value ,(cdr result)))
1971 (insert ,header ": " value)
1973 (insert "\n")))))))))
1975 (when (or name address)
1976 (add-hook 'message-setup-hook
1978 (set (make-local-variable 'user-mail-address)
1979 ,(or (cdr address) user-mail-address))
1980 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1982 ,(or (cdr address) user-mail-address)))
1984 (message-remove-header "From")
1986 (insert "From: " (message-make-from) "\n"))))
1989 ;;; Allow redefinition of functions.
1995 ;;; gnus-msg.el ends here