1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995-2012 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."
324 (defcustom gnus-gcc-post-body-encode-hook nil
325 "A hook called after encoding the body of the Gcc copy of a message.
326 The current buffer (when the hook is run) contains the message
327 including the message header. Changes made to the message will
328 only affect the Gcc copy, but not the original message."
332 (autoload 'gnus-message-citation-mode "gnus-cite" nil t)
334 ;;; Internal variables.
336 (defvar gnus-inhibit-posting-styles nil
337 "Inhibit the use of posting styles.")
339 (defvar gnus-article-yanked-articles nil)
340 (defvar gnus-message-buffer "*Mail Gnus*")
341 (defvar gnus-article-copy nil)
342 (defvar gnus-check-before-posting nil)
343 (defvar gnus-last-posting-server nil)
344 (defvar gnus-message-group-art nil)
346 (defvar gnus-msg-force-broken-reply-to nil)
348 (defconst gnus-bug-message
349 "Sending a bug report to the Gnus Towers.
350 ========================================
352 The buffer below is a mail buffer. When you press `C-c C-c', it will
353 be sent to the Gnus Bug Exterminators.
355 The thing near the bottom of the buffer is how the environment
356 settings will be included in the mail. Please do not delete that.
357 They will tell the Bug People what your environment is, so that it
358 will be easier to locate the bugs.
360 If you have found a bug that makes Emacs go \"beep\", set
361 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
362 and include the backtrace in your bug report.
364 Please describe the bug in annoying, painstaking detail.
366 Thank you for your help in stamping out bugs.
369 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
373 ;;; Gnus Posting Functions
376 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
377 "p" gnus-summary-post-news
378 "i" gnus-summary-news-other-window
379 "f" gnus-summary-followup
380 "F" gnus-summary-followup-with-original
381 "c" gnus-summary-cancel-article
382 "s" gnus-summary-supersede-article
383 "r" gnus-summary-reply
384 "y" gnus-summary-yank-message
385 "R" gnus-summary-reply-with-original
386 "L" gnus-summary-reply-to-list-with-original
387 "w" gnus-summary-wide-reply
388 "W" gnus-summary-wide-reply-with-original
389 "v" gnus-summary-very-wide-reply
390 "V" gnus-summary-very-wide-reply-with-original
391 "n" gnus-summary-followup-to-mail
392 "N" gnus-summary-followup-to-mail-with-original
393 "m" gnus-summary-mail-other-window
394 "u" gnus-uu-post-news
395 "\M-c" gnus-summary-mail-crosspost-complaint
396 "Br" gnus-summary-reply-broken-reply-to
397 "BR" gnus-summary-reply-broken-reply-to-with-original
398 "om" gnus-summary-mail-forward
399 "op" gnus-summary-post-forward
400 "Om" gnus-uu-digest-mail-forward
401 "Op" gnus-uu-digest-post-forward)
403 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
404 "b" gnus-summary-resend-bounced-mail
405 ;; "c" gnus-summary-send-draft
406 "r" gnus-summary-resend-message
407 "e" gnus-summary-resend-message-edit)
409 ;;; Internal functions.
411 (defun gnus-inews-make-draft (articles)
413 (gnus-inews-make-draft-meta-information
414 ,(gnus-group-decoded-name gnus-newsgroup-name) ',articles)))
416 (defvar gnus-article-reply nil)
417 (defmacro gnus-setup-message (config &rest forms)
418 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
419 (winconf-name (make-symbol "gnus-setup-message-winconf-name"))
420 (buffer (make-symbol "gnus-setup-message-buffer"))
421 (article (make-symbol "gnus-setup-message-article"))
422 (yanked (make-symbol "gnus-setup-yanked-articles"))
423 (group (make-symbol "gnus-setup-message-group")))
424 `(let ((,winconf (current-window-configuration))
425 (,winconf-name gnus-current-window-configuration)
426 (,buffer (buffer-name (current-buffer)))
427 (,article gnus-article-reply)
428 (,yanked gnus-article-yanked-articles)
429 (,group gnus-newsgroup-name)
430 (message-header-setup-hook
431 (copy-sequence message-header-setup-hook))
432 (mbl mml-buffer-list)
433 (message-mode-hook (copy-sequence message-mode-hook)))
434 (setq mml-buffer-list nil)
435 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
436 ;; message-newsreader and message-mailer were formerly set in
437 ;; gnus-inews-add-send-actions, but this is too late when
438 ;; message-generate-headers-first is used. --ansel
439 (add-hook 'message-mode-hook
441 (setq message-newsreader
442 (setq message-mailer (gnus-extended-version)))))
443 ;; #### FIXME: for a reason that I did not manage to identify yet,
444 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
445 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
446 ;; After evaluation of @forms below, it gets the value we actually want
447 ;; to override, and the posting styles are used. For that reason, I've
448 ;; added an optional argument to `gnus-configure-posting-styles' to
449 ;; make sure that the correct value for the group name is used. -- drv
450 (add-hook 'message-mode-hook
451 (if (memq ,config '(reply-yank reply))
453 (gnus-configure-posting-styles ,group))
455 ;; There may be an old " *gnus article copy*" buffer.
456 (let (gnus-article-copy)
457 (gnus-configure-posting-styles ,group)))))
458 (gnus-alist-pull ',(intern gnus-draft-meta-information-header)
459 message-required-headers)
461 (not (string= ,group "")))
463 (intern gnus-draft-meta-information-header)
464 (gnus-inews-make-draft (or ,yanked ,article)))
465 message-required-headers))
469 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
470 ,yanked ,winconf-name)
471 (setq gnus-message-buffer (current-buffer))
472 (set (make-local-variable 'gnus-message-group-art)
473 (cons ,group ,article))
474 (set (make-local-variable 'gnus-newsgroup-name) ,group)
475 ;; Enable highlighting of different citation levels
476 (when gnus-message-highlight-citation
477 (gnus-message-citation-mode 1))
478 (gnus-run-hooks 'gnus-message-setup-hook)
479 (if (eq major-mode 'message-mode)
480 (let ((mbl1 mml-buffer-list))
481 (setq mml-buffer-list mbl) ;; Global value
482 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
483 (gnus-make-local-hook 'kill-buffer-hook)
484 (gnus-make-local-hook 'change-major-mode-hook)
485 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
486 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
487 (mml-destroy-buffers)
488 (setq mml-buffer-list mbl)))
489 (message-hide-headers)
491 (gnus-configure-windows ,config t)
492 (run-hooks 'post-command-hook)
493 (set-buffer-modified-p nil))))
495 (defun gnus-inews-make-draft-meta-information (group articles)
496 (when (numberp articles)
497 (setq articles (list articles)))
498 (concat "(\"" group "\""
512 (defun gnus-msg-mail (&optional to subject other-headers continue
513 switch-action yank-action send-actions
515 "Start editing a mail message to be sent.
516 Like `message-mail', but with Gnus paraphernalia, particularly the
517 Gcc: header for archiving purposes.
518 If Gnus isn't running, a plain `message-mail' setup is used
521 (if (not (gnus-alive-p))
522 (message-mail to subject other-headers continue
523 nil yank-action send-actions return-action)
524 (let ((buf (current-buffer))
526 (gnus-setup-message 'message
527 (message-mail to subject other-headers continue
528 nil yank-action send-actions return-action))
530 (setq mail-buf (current-buffer))
531 (switch-to-buffer buf)
532 (apply switch-action mail-buf nil))
533 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
537 (defun gnus-button-mailto (address)
539 (set-buffer (gnus-copy-article-buffer))
540 (gnus-setup-message 'message
541 (message-reply address)))
544 (defun gnus-button-reply (&optional to-address wide)
545 "Like `message-reply'."
547 (gnus-setup-message 'message
548 (message-reply to-address wide)))
551 (define-mail-user-agent 'gnus-user-agent
552 'gnus-msg-mail 'message-send-and-exit
553 'message-kill-buffer 'message-send-hook)
555 (defun gnus-setup-posting-charset (group)
556 (let ((alist gnus-group-posting-charset-alist)
557 (group (or group ""))
561 (while (setq elem (pop alist))
562 (when (or (and (stringp (car elem))
563 (string-match (car elem) group))
564 (and (functionp (car elem))
565 (funcall (car elem) group))
566 (and (symbolp (car elem))
567 (symbol-value (car elem))))
568 (throw 'found (cons (cadr elem) (caddr elem)))))))))
570 (defun gnus-inews-add-send-actions (winconf buffer article
571 &optional config yanked
573 (gnus-make-local-hook 'message-sent-hook)
574 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
575 'gnus-inews-do-gcc) nil t)
577 (gnus-make-local-hook 'message-header-hook)
578 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
579 (setq message-post-method
580 `(lambda (&optional arg)
581 (gnus-post-method arg ,gnus-newsgroup-name)))
584 (setq gnus-current-window-configuration ',winconf-name)
585 (when (gnus-buffer-exists-p ,buffer)
586 (set-window-configuration ,winconf)))
587 'exit 'postpone 'kill)
588 (let ((to-be-marked (cond
591 (lambda (x) (if (listp x) (car x) x)) yanked))
592 (article (if (listp article) article (list article)))
595 `(when (gnus-buffer-exists-p ,buffer)
596 (with-current-buffer ,buffer
598 (if (eq config 'forward)
599 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
600 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
603 (put 'gnus-setup-message 'lisp-indent-function 1)
604 (put 'gnus-setup-message 'edebug-form-spec '(form body))
606 ;;; Post news commands of Gnus group mode and summary mode
608 (defun gnus-group-mail (&optional arg)
609 "Start composing a mail.
610 If ARG, use the group under the point to find a posting style.
611 If ARG is 1, prompt for a group name to find the posting style."
613 ;; We can't `let' gnus-newsgroup-name here, since that leads
614 ;; to local variables leaking.
615 (let ((group gnus-newsgroup-name)
616 ;; make sure last viewed article doesn't affect posting styles:
618 (buffer (current-buffer)))
621 (setq gnus-newsgroup-name
623 (if (= 1 (prefix-numeric-value arg))
624 (gnus-group-completing-read
625 "Use posting style of group"
626 nil (gnus-read-active-file-p))
627 (gnus-group-group-name))
629 ;; #### see comment in gnus-setup-message -- drv
630 (gnus-setup-message 'message (message-mail)))
631 (with-current-buffer buffer
632 (setq gnus-newsgroup-name group)))))
634 (defun gnus-group-news (&optional arg)
635 "Start composing a news.
636 If ARG, post to group under point.
637 If ARG is 1, prompt for group name to post to.
639 This function prepares a news even when using mail groups. This is useful
640 for posting messages to mail groups without actually sending them over the
641 network. The corresponding back end must have a 'request-post method."
643 ;; We can't `let' gnus-newsgroup-name here, since that leads
644 ;; to local variables leaking.
645 (let ((group gnus-newsgroup-name)
646 ;; make sure last viewed article doesn't affect posting styles:
648 (buffer (current-buffer)))
651 (setq gnus-newsgroup-name
653 (if (= 1 (prefix-numeric-value arg))
654 (gnus-group-completing-read "Use group"
656 (gnus-read-active-file-p))
657 (gnus-group-group-name))
659 ;; #### see comment in gnus-setup-message -- drv
660 (gnus-setup-message 'message
661 (message-news (gnus-group-real-name gnus-newsgroup-name))))
662 (with-current-buffer buffer
663 (setq gnus-newsgroup-name group)))))
665 (defun gnus-group-post-news (&optional arg)
666 "Start composing a message (a news by default).
667 If ARG, post to group under point. If ARG is 1, prompt for group name.
668 Depending on the selected group, the message might be either a mail or
671 ;; Bind this variable here to make message mode hooks work ok.
672 (let ((gnus-newsgroup-name
674 (if (= 1 (prefix-numeric-value arg))
675 (gnus-group-completing-read "Newsgroup" nil
676 (gnus-read-active-file-p))
677 (or (gnus-group-group-name) ""))
679 ;; make sure last viewed article doesn't affect posting styles:
681 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
682 (string= gnus-newsgroup-name ""))))
684 (defun gnus-summary-mail-other-window (&optional arg)
685 "Start composing a mail in another window.
686 Use the posting of the current group by default.
687 If ARG, don't do that. If ARG is 1, prompt for group name to find the
690 ;; We can't `let' gnus-newsgroup-name here, since that leads
691 ;; to local variables leaking.
692 (let ((group gnus-newsgroup-name)
693 ;; make sure last viewed article doesn't affect posting styles:
695 (buffer (current-buffer)))
698 (setq gnus-newsgroup-name
700 (if (= 1 (prefix-numeric-value arg))
701 (gnus-group-completing-read "Use group"
703 (gnus-read-active-file-p))
705 gnus-newsgroup-name))
706 ;; #### see comment in gnus-setup-message -- drv
707 (gnus-setup-message 'message (message-mail)))
708 (with-current-buffer buffer
709 (setq gnus-newsgroup-name group)))))
711 (defun gnus-summary-news-other-window (&optional arg)
712 "Start composing a news in another window.
713 Post to the current group by default.
714 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
716 This function prepares a news even when using mail groups. This is useful
717 for posting messages to mail groups without actually sending them over the
718 network. The corresponding back end must have a 'request-post method."
720 ;; We can't `let' gnus-newsgroup-name here, since that leads
721 ;; to local variables leaking.
722 (let ((group gnus-newsgroup-name)
723 ;; make sure last viewed article doesn't affect posting styles:
725 (buffer (current-buffer)))
728 (setq gnus-newsgroup-name
730 (if (= 1 (prefix-numeric-value arg))
731 (gnus-group-completing-read "Use group"
733 (gnus-read-active-file-p))
735 gnus-newsgroup-name))
736 ;; #### see comment in gnus-setup-message -- drv
737 (gnus-setup-message 'message
739 (message-news (gnus-group-real-name gnus-newsgroup-name))
740 (set (make-local-variable 'gnus-discouraged-post-methods)
742 (car (gnus-find-method-for-group gnus-newsgroup-name))
743 gnus-discouraged-post-methods)))))
744 (with-current-buffer buffer
745 (setq gnus-newsgroup-name group)))))
747 (defun gnus-summary-post-news (&optional arg)
748 "Start composing a message. Post to the current group by default.
749 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
750 Depending on the selected group, the message might be either a mail or
753 ;; Bind this variable here to make message mode hooks work ok.
754 (let ((gnus-newsgroup-name
756 (if (= 1 (prefix-numeric-value arg))
757 (gnus-group-completing-read "Newsgroup" nil
758 (gnus-read-active-file-p))
760 gnus-newsgroup-name))
761 ;; make sure last viewed article doesn't affect posting styles:
763 (gnus-post-news 'post gnus-newsgroup-name)))
766 (defun gnus-summary-followup (yank &optional force-news)
767 "Compose a followup to an article.
768 If prefix argument YANK is non-nil, the original article is yanked
770 YANK is a list of elements, where the car of each element is the
771 article number, and the cdr is the string to be yanked."
773 (list (and current-prefix-arg
774 (gnus-summary-work-articles 1))))
776 (gnus-summary-goto-subject
777 (if (listp (car yank))
780 (save-window-excursion
781 (gnus-summary-select-article))
782 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
783 (gnus-newsgroup-name gnus-newsgroup-name))
785 (gnus-post-news nil gnus-newsgroup-name
786 headers gnus-article-buffer
788 (gnus-summary-handle-replysign)))
790 (defun gnus-summary-followup-with-original (n &optional force-news)
791 "Compose a followup to an article and include the original article.
792 The text in the region will be yanked. If the region isn't
793 active, the entire article will be yanked."
795 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
797 (defun gnus-summary-followup-to-mail (&optional arg)
798 "Followup to the current mail message via news."
800 (list (and current-prefix-arg
801 (gnus-summary-work-articles 1))))
802 (gnus-summary-followup arg t))
804 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
805 "Followup to the current mail message via news."
807 (gnus-summary-followup (gnus-summary-work-articles arg) t))
809 (defun gnus-inews-yank-articles (articles)
810 (let (beg article yank-string)
812 (while (setq article (pop articles))
813 (when (listp article)
814 (setq yank-string (nth 1 article)
815 article (nth 0 article)))
816 (save-window-excursion
817 (set-buffer gnus-summary-buffer)
818 (gnus-summary-select-article nil nil nil article)
819 (gnus-summary-remove-process-mark article))
820 (gnus-copy-article-buffer nil yank-string)
821 (let ((message-reply-buffer gnus-article-copy)
822 (message-reply-headers
823 ;; The headers are decoded.
824 (with-current-buffer gnus-article-copy
826 (nnheader-narrow-to-headers)
827 (nnheader-parse-naked-head)))))
828 (message-yank-original)
829 (message-exchange-point-and-mark)
830 (setq beg (or beg (mark t))))
836 (defun gnus-summary-cancel-article (&optional n symp)
837 "Cancel an article you posted.
838 Uses the process-prefix convention. If given the symbolic
839 prefix `a', cancel using the standard posting method; if not
840 post using the current select method."
841 (interactive (gnus-interactive "P\ny"))
842 (let ((message-post-method
844 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
845 (dolist (article (gnus-summary-work-articles n))
846 (when (gnus-summary-select-article t nil nil article)
847 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
848 (message-cancel-news))
849 (gnus-summary-mark-as-read article gnus-canceled-mark)
850 (gnus-cache-remove-article 1))
851 (gnus-article-hide-headers-if-wanted))
852 (gnus-summary-remove-process-mark article))))
854 (defun gnus-summary-supersede-article ()
855 "Compose an article that will supersede a previous article.
856 This is done simply by taking the old article and adding a Supersedes
857 header line with the old Message-ID."
859 (let ((article (gnus-summary-article-number))
860 (mail-parse-charset gnus-newsgroup-charset))
861 (gnus-setup-message 'reply-yank
862 (gnus-summary-select-article t)
863 (set-buffer gnus-original-article-buffer)
867 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
868 (with-current-buffer ,gnus-summary-buffer
869 (gnus-cache-possibly-remove-article ,article nil nil nil t)
870 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
871 message-send-actions)
873 (gnus-inews-insert-gcc))))
877 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
878 ;; make a copy of the article buffer with all text properties removed
879 ;; this copy is in the buffer gnus-article-copy.
880 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
881 ;; this buffer should be passed to all mail/news reply/post routines.
882 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
883 (with-current-buffer gnus-article-copy
884 (mm-enable-multibyte))
885 (let ((article-buffer (or article-buffer gnus-article-buffer))
887 (if (not (and (get-buffer article-buffer)
888 (gnus-buffer-exists-p article-buffer)))
889 (error "Can't find any article buffer")
890 (with-current-buffer article-buffer
891 (let ((gnus-newsgroup-charset (or gnus-article-charset
892 gnus-newsgroup-charset))
893 (gnus-newsgroup-ignored-charsets
894 (or gnus-article-ignored-charsets
895 gnus-newsgroup-ignored-charsets)))
897 ;; Copy over the (displayed) article buffer, delete
898 ;; hidden text and remove text properties.
900 (copy-to-buffer gnus-article-copy (point-min) (point-max))
901 (set-buffer gnus-article-copy)
904 (delete-region (point) (point-max))
905 (insert yank-string))
906 (gnus-article-delete-text-of-type 'annotation)
907 (gnus-article-delete-text-of-type 'multipart)
908 (gnus-remove-text-with-property 'gnus-prev)
909 (gnus-remove-text-with-property 'gnus-next)
910 (gnus-remove-text-with-property 'gnus-decoration)
913 (buffer-substring-no-properties (point-min) (point-max))
915 ;; Find the original headers.
916 (set-buffer gnus-original-article-buffer)
917 (goto-char (point-min))
918 (while (looking-at message-unix-mail-delimiter)
920 (let ((mail-header-separator ""))
922 end (or (message-goto-body)
923 ;; There may be just a header.
925 ;; Delete the headers from the displayed articles.
926 (set-buffer gnus-article-copy)
927 (let ((mail-header-separator ""))
928 (delete-region (goto-char (point-min))
929 (or (message-goto-body) (point-max))))
930 ;; Insert the original article headers.
931 (insert-buffer-substring gnus-original-article-buffer beg end)
933 (let ((gnus-article-decode-hook
934 (delq 'article-decode-charset
935 (copy-sequence gnus-article-decode-hook)))
936 (rfc2047-quote-decoded-words-containing-tspecials t))
937 (run-hooks 'gnus-article-decode-hook)))))
940 (defun gnus-post-news (post &optional group header article-buffer yank subject
943 (gnus-copy-article-buffer))
944 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
945 (gnus-article-yanked-articles yank)
946 (add-to-list gnus-add-to-list))
947 (gnus-setup-message (cond (yank 'reply-yank)
948 (article-buffer 'reply)
950 (let* ((group (or group gnus-newsgroup-name))
951 (charset (gnus-group-name-charset nil group))
953 to-address to-group mailing-list to-list
956 (setq to-address (gnus-parameter-to-address group)
957 to-group (gnus-group-find-parameter group 'to-group)
958 to-list (gnus-parameter-to-list group)
959 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
960 mailing-list (when gnus-mailing-list-groups
961 (string-match gnus-mailing-list-groups group))
962 group (gnus-group-name-decode (gnus-group-real-name group)
964 (if (or (and to-group
965 (gnus-news-group-p to-group))
968 (and (gnus-news-group-p
969 (or pgroup gnus-newsgroup-name)
970 (or header gnus-current-article))
978 (and (not (gnus-virtual-group-p pgroup)) group)))
979 (set-buffer gnus-article-copy)
980 (gnus-msg-treat-broken-reply-to)
981 (message-followup (if (or newsgroup-p force-news)
982 (if (save-restriction
983 (article-narrow-to-head)
984 (message-fetch-field "newsgroups"))
991 (message-mail (or to-address to-list))
992 ;; Arrange for mail groups that have no `to-address' to
993 ;; get that when the user sends off the mail.
994 (when (and (not to-list)
997 (push (list 'gnus-inews-add-to-address pgroup)
998 message-send-actions)))
999 (set-buffer gnus-article-copy)
1000 (gnus-msg-treat-broken-reply-to)
1001 (message-wide-reply to-address)))
1003 (gnus-inews-yank-articles yank))))))
1005 (defun gnus-msg-treat-broken-reply-to (&optional force)
1006 "Remove the Reply-to header if broken-reply-to."
1008 (gnus-group-find-parameter
1009 gnus-newsgroup-name 'broken-reply-to))
1011 (message-narrow-to-head)
1012 (message-remove-header "reply-to"))))
1014 (defun gnus-post-method (arg group &optional silent)
1015 "Return the posting method based on GROUP and ARG.
1016 If SILENT, don't prompt the user."
1017 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1019 (group-method (gnus-find-method-for-group group)))
1021 ;; If the group-method is nil (which shouldn't happen) we use
1022 ;; the default method.
1023 ((null group-method)
1024 (or (and (listp gnus-post-method) ;If not current/native/nil
1025 (not (listp (car gnus-post-method))) ; and not a list of methods
1026 gnus-post-method) ;then use it.
1028 message-post-method))
1029 ;; We want the inverse of the default
1030 ((and arg (not (eq arg 0)))
1031 (if (eq gnus-post-method 'current)
1034 ;; We query the user for a post method.
1036 (and (listp gnus-post-method)
1037 (listp (car gnus-post-method))))
1039 ;; Collect all methods we know about.
1041 (when (listp gnus-post-method)
1042 (if (listp (car gnus-post-method))
1044 (list gnus-post-method)))
1045 gnus-secondary-select-methods
1046 (mapcar 'cdr gnus-server-alist)
1047 (mapcar 'car gnus-opened-servers)
1048 (list gnus-select-method)
1049 (list group-method)))
1050 method-alist post-methods method)
1051 ;; Weed out all mail methods.
1053 (setq method (gnus-server-get-method "" (pop methods)))
1054 (when (and (or (gnus-method-option-p method 'post)
1055 (gnus-method-option-p method 'post-mail))
1056 (not (member method post-methods)))
1057 (push method post-methods)))
1058 ;; Create a name-method alist.
1062 (if (equal (cadr m) "")
1063 (list (symbol-name (car m)) m)
1064 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1069 (setq gnus-last-posting-server
1071 gnus-last-posting-server)
1072 ;; Just use the last value.
1073 gnus-last-posting-server
1074 (gnus-completing-read
1075 "Posting method" (mapcar 'car method-alist) t
1076 (cons (or gnus-last-posting-server "") 0))))
1078 ;; Override normal method.
1079 ((and (eq gnus-post-method 'current)
1080 (not (memq (car group-method) gnus-discouraged-post-methods))
1081 (gnus-get-function group-method 'request-post t))
1084 ;; Use gnus-post-method.
1085 ((listp gnus-post-method) ;A method...
1086 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1088 ;; Use the normal select method (nil or native).
1089 (t gnus-select-method))))
1093 (defun gnus-extended-version ()
1094 "Stringified Gnus version and Emacs version.
1095 See the variable `gnus-user-agent'."
1097 (if (stringp gnus-user-agent)
1099 ;; `gnus-user-agent' is a list:
1100 (let* ((float-output-format nil)
1102 (when (memq 'gnus gnus-user-agent)
1104 (prin1-to-string (gnus-continuum-version gnus-version) t)
1105 " (" gnus-version ")")))
1106 (emacs-v (gnus-emacs-version)))
1107 (concat gnus-v (when (and gnus-v emacs-v) " ")
1112 ;;; Gnus Mail Functions
1115 ;;; Mail reply commands of Gnus summary mode
1117 (defun gnus-summary-reply (&optional yank wide very-wide)
1118 "Start composing a mail reply to the current message.
1119 If prefix argument YANK is non-nil, the original article is yanked
1121 If WIDE, make a wide reply.
1122 If VERY-WIDE, make a very wide reply."
1124 (list (and current-prefix-arg
1125 (gnus-summary-work-articles 1))))
1126 ;; Allow user to require confirmation before replying by mail to the
1127 ;; author of a news article (or mail message).
1128 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1129 gnus-confirm-treat-mail-like-news))
1130 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1131 (string-match gnus-confirm-mail-reply-to-news
1132 gnus-newsgroup-name))
1133 ((functionp gnus-confirm-mail-reply-to-news)
1134 (funcall gnus-confirm-mail-reply-to-news
1135 gnus-newsgroup-name))
1136 (t gnus-confirm-mail-reply-to-news)))
1137 (if (or wide very-wide)
1138 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1140 (y-or-n-p "Really reply by mail to article author? ")))
1142 (if (listp (car yank))
1145 (gnus-article-reply (or article (gnus-summary-article-number)))
1146 (gnus-article-yanked-articles yank)
1148 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1150 (gnus-summary-goto-subject article))
1151 (gnus-setup-message (if yank 'reply-yank 'reply)
1153 (gnus-summary-select-article)
1154 (dolist (article very-wide)
1155 (gnus-summary-select-article nil nil nil article)
1156 (with-current-buffer (gnus-copy-article-buffer)
1157 (gnus-msg-treat-broken-reply-to)
1159 (message-narrow-to-head)
1160 (setq headers (concat headers (buffer-string)))))))
1161 (set-buffer (gnus-copy-article-buffer))
1162 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1164 (message-narrow-to-head)
1168 (goto-char (point-max)))
1169 (mml-quote-region (point) (point-max))
1170 (message-reply nil wide)
1172 (gnus-inews-yank-articles yank))
1173 (gnus-summary-handle-replysign)))))
1175 (defun gnus-summary-handle-replysign ()
1176 "Check the various replysign variables and take action accordingly."
1177 (when (or gnus-message-replysign gnus-message-replyencrypt)
1178 (let (signed encrypted)
1179 (with-current-buffer gnus-article-buffer
1180 (setq signed (memq 'signed gnus-article-wash-types))
1181 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1182 (cond ((and gnus-message-replyencrypt encrypted)
1183 (mml-secure-message mml-default-encrypt-method
1184 (if gnus-message-replysignencrypted
1187 ((and gnus-message-replysign signed)
1188 (mml-secure-message mml-default-sign-method 'sign))))))
1190 (defun gnus-summary-reply-with-original (n &optional wide)
1191 "Start composing a reply mail to the current message.
1192 The original article will be yanked."
1194 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1196 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1197 "Start composing a reply mail to the current message.
1198 The reply goes only to the mailing list.
1199 The original article will be yanked."
1201 (let ((message-reply-to-function
1203 `((To . ,(gnus-mailing-list-followup-to))))))
1204 (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1206 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1207 "Like `gnus-summary-reply' except removing reply-to field.
1208 If prefix argument YANK is non-nil, the original article is yanked
1210 If WIDE, make a wide reply.
1211 If VERY-WIDE, make a very wide reply."
1213 (list (and current-prefix-arg
1214 (gnus-summary-work-articles 1))))
1215 (let ((gnus-msg-force-broken-reply-to t))
1216 (gnus-summary-reply yank wide very-wide)))
1218 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1219 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1220 The original article will be yanked."
1222 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1224 (defun gnus-summary-wide-reply (&optional yank)
1225 "Start composing a wide reply mail to the current message.
1226 If prefix argument YANK is non-nil, the original article is yanked
1229 (list (and current-prefix-arg
1230 (gnus-summary-work-articles 1))))
1231 (gnus-summary-reply yank t))
1233 (defun gnus-summary-wide-reply-with-original (n)
1234 "Start composing a wide reply mail to the current message.
1235 The original article will be yanked.
1236 Uses the process/prefix convention."
1238 (gnus-summary-reply-with-original n t))
1240 (defun gnus-summary-very-wide-reply (&optional yank)
1241 "Start composing a very wide reply mail to the current message.
1242 If prefix argument YANK is non-nil, the original article is yanked
1245 (list (and current-prefix-arg
1246 (gnus-summary-work-articles 1))))
1247 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1249 (defun gnus-summary-very-wide-reply-with-original (n)
1250 "Start composing a very wide reply mail to the current message.
1251 The original article will be yanked."
1254 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1256 (defun gnus-summary-mail-forward (&optional arg post)
1257 "Forward the current message(s) to another user.
1258 If process marks exist, forward all marked messages;
1259 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1260 if ARG is 1, decode the message and forward directly inline;
1261 if ARG is 2, forward message as an rfc822 MIME section;
1262 if ARG is 3, decode message and forward as an rfc822 MIME section;
1263 if ARG is 4, forward message directly inline;
1264 otherwise, use flipped `message-forward-as-mime'.
1265 If POST, post instead of mail.
1266 For the \"inline\" alternatives, also see the variable
1267 `message-forward-ignored-headers'."
1269 (if (cdr (gnus-summary-work-articles nil))
1270 ;; Process marks are given.
1271 (gnus-uu-digest-mail-forward nil post)
1272 ;; No process marks.
1273 (let ((message-forward-as-mime message-forward-as-mime)
1274 (message-forward-show-mml message-forward-show-mml))
1278 (setq message-forward-as-mime nil
1279 message-forward-show-mml t))
1281 (setq message-forward-as-mime t
1282 message-forward-show-mml nil))
1284 (setq message-forward-as-mime t
1285 message-forward-show-mml t))
1287 (setq message-forward-as-mime nil
1288 message-forward-show-mml nil))
1290 (setq message-forward-as-mime (not message-forward-as-mime))))
1291 (let* ((gnus-article-reply (gnus-summary-article-number))
1292 (gnus-article-yanked-articles (list gnus-article-reply)))
1293 (gnus-setup-message 'forward
1294 (gnus-summary-select-article)
1295 (let ((mail-parse-charset
1296 (or (and (gnus-buffer-live-p gnus-article-buffer)
1297 (with-current-buffer gnus-article-buffer
1298 gnus-article-charset))
1299 gnus-newsgroup-charset))
1300 (mail-parse-ignored-charsets
1301 gnus-newsgroup-ignored-charsets))
1302 (set-buffer gnus-original-article-buffer)
1303 (message-forward post)))))))
1305 (defun gnus-summary-resend-message-insert-gcc ()
1306 "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1307 (gnus-inews-insert-gcc)
1310 (mm-encode-coding-string
1312 (gnus-group-name-charset (gnus-inews-group-method group)
1314 (message-unquote-tokens
1315 (message-tokenize-header (mail-fetch-field "gcc" nil t)
1317 (message-remove-header "gcc")
1319 (goto-char (point-max))
1320 (cond ((eq gnus-gcc-self-resent-messages 'none))
1321 ((eq gnus-gcc-self-resent-messages t)
1322 (insert "Gcc: \"" gnus-newsgroup-name "\"\n"))
1323 ((stringp gnus-gcc-self-resent-messages)
1325 (mm-encode-coding-string
1326 (if (string-match " " gnus-gcc-self-resent-messages)
1327 (concat "\"" gnus-gcc-self-resent-messages "\"")
1328 gnus-gcc-self-resent-messages)
1329 (gnus-group-name-charset
1330 (gnus-inews-group-method gnus-gcc-self-resent-messages)
1331 gnus-gcc-self-resent-messages))
1333 ((null gnus-gcc-self-resent-messages)
1334 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n"))
1335 ((eq gnus-gcc-self-resent-messages 'no-gcc-self)
1336 (when (setq gcc (delete
1338 (delete (concat "\"" gnus-newsgroup-name "\"")
1340 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n")))))))
1342 (defun gnus-summary-resend-message (address n)
1343 "Resend the current article to ADDRESS."
1345 (list (message-read-from-minibuffer
1346 "Resend message(s) to: "
1347 (when (and gnus-summary-resend-default-address
1348 (gnus-buffer-live-p gnus-original-article-buffer))
1349 ;; If some other article is currently selected, the
1350 ;; initial-contents is wrong. Whatever, it is just the
1351 ;; initial-contents.
1352 (with-current-buffer gnus-original-article-buffer
1353 (nnmail-fetch-field "to"))))
1354 current-prefix-arg))
1355 (let ((message-header-setup-hook (copy-sequence message-header-setup-hook))
1356 (message-sent-hook (copy-sequence message-sent-hook)))
1357 ;; `gnus-summary-resend-message-insert-gcc' must run last.
1358 (add-hook 'message-header-setup-hook
1359 'gnus-summary-resend-message-insert-gcc t)
1360 (add-hook 'message-sent-hook (if gnus-agent
1361 'gnus-agent-possibly-do-gcc
1362 'gnus-inews-do-gcc))
1363 (dolist (article (gnus-summary-work-articles n))
1364 (gnus-summary-select-article nil nil nil article)
1365 (with-current-buffer gnus-original-article-buffer
1366 (let ((gnus-gcc-externalize-attachments nil)
1367 (message-inhibit-body-encoding t))
1368 (message-resend address)))
1369 (gnus-summary-mark-article-as-forwarded article))))
1371 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1372 (defun gnus-summary-resend-message-edit ()
1373 "Resend an article that has already been sent.
1374 A new buffer will be created to allow the user to modify body and
1375 contents of the message, and then, everything will happen as when
1376 composing a new message."
1378 (let ((mail-parse-charset gnus-newsgroup-charset))
1379 (gnus-setup-message 'reply-yank
1380 (gnus-summary-select-article t)
1381 (set-buffer gnus-original-article-buffer)
1382 (let ((cur (current-buffer))
1383 (to (message-fetch-field "to")))
1384 ;; Get a normal message buffer.
1385 (message-pop-to-buffer (message-buffer-name "Resend" to))
1386 (insert-buffer-substring cur)
1388 (message-narrow-to-head-1)
1389 ;; Gnus will generate a new one when sending.
1390 (message-remove-header "Message-ID")
1391 ;; Remove unwanted headers.
1392 (message-remove-header message-ignored-resent-headers t)
1393 (goto-char (point-max))
1394 (insert mail-header-separator)
1396 (gnus-inews-insert-gcc)
1397 (goto-char (point-min))
1398 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1402 (defun gnus-summary-post-forward (&optional arg)
1403 "Forward the current article to a newsgroup.
1404 See `gnus-summary-mail-forward' for ARG."
1406 (gnus-summary-mail-forward arg t))
1408 (defun gnus-summary-mail-crosspost-complaint (n)
1409 "Send a complaint about crossposting to the current article(s)."
1411 (dolist (article (gnus-summary-work-articles n))
1412 (set-buffer gnus-summary-buffer)
1413 (gnus-summary-goto-subject article)
1414 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1415 newsgroups followup-to)
1416 (gnus-summary-select-article)
1417 (set-buffer gnus-original-article-buffer)
1418 (if (and (<= (length (message-tokenize-header
1420 (mail-fetch-field "newsgroups"))
1423 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1424 (not (member group (message-tokenize-header
1425 followup-to ", ")))))
1427 (gnus-message 1 "Followup-to restricted")
1428 (gnus-message 1 "Not a crossposted article"))
1429 (set-buffer gnus-summary-buffer)
1430 (gnus-summary-reply-with-original 1)
1431 (set-buffer gnus-message-buffer)
1433 (insert (format gnus-crosspost-complaint newsgroups group))
1434 (message-goto-subject)
1435 (re-search-forward " *$")
1436 (replace-match " (crosspost notification)" t t)
1437 (gnus-deactivate-mark)
1438 (when (gnus-y-or-n-p "Send this complaint? ")
1439 (message-send-and-exit))))))
1441 (defun gnus-mail-parse-comma-list ()
1444 (skip-chars-forward " ")
1447 (skip-chars-forward "^,")
1452 (narrow-to-region beg (point))
1455 (while (search-forward "\"" nil t)
1459 (skip-chars-forward ",")
1460 (skip-chars-forward "^,"))
1461 (skip-chars-backward " ")
1462 (push (buffer-substring beg (point))
1464 (skip-chars-forward "^,")
1465 (skip-chars-forward ", "))
1468 (defun gnus-inews-add-to-address (group)
1469 (let ((to-address (mail-fetch-field "to")))
1470 (when (and to-address
1472 ;; This mail group doesn't have a `to-list', so we add one
1474 (when (gnus-y-or-n-p
1475 (format "Do you want to add this as `to-list': %s? " to-address))
1476 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1478 (defun gnus-put-message ()
1479 "Put the current message in some group and return to Gnus."
1481 (let ((reply gnus-article-reply)
1482 (winconf gnus-prev-winconf)
1483 (group gnus-newsgroup-name))
1485 (not (gnus-group-read-only-p group)))
1486 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1488 (when (gnus-group-entry group)
1489 (error "No such group: %s" group))
1493 (message-narrow-to-headers)
1494 (let ((gnus-deletable-headers nil))
1495 (message-generate-headers
1496 (if (message-news-p)
1497 message-required-news-headers
1498 message-required-mail-headers)))
1499 (goto-char (point-max))
1500 (if (string-match " " group)
1501 (insert "Gcc: \"" group "\"\n")
1502 (insert "Gcc: " group "\n"))
1505 (when (and (get-buffer gnus-group-buffer)
1506 (gnus-buffer-exists-p (car-safe reply))
1508 (set-buffer (car reply))
1509 (gnus-summary-mark-article-as-replied (cdr reply)))
1511 (set-window-configuration winconf))))
1513 (defun gnus-article-mail (yank)
1514 "Send a reply to the address near point.
1515 If YANK is non-nil, include the original article."
1519 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1520 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1522 (gnus-msg-mail address)
1524 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1526 (defvar nntp-server-type)
1528 "Send a bug report to the Gnus maintainers."
1530 (unless (gnus-alive-p)
1531 (error "Gnus has been shut down"))
1532 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1533 (unless (message-mail-user-agent)
1534 (when gnus-bug-create-help-buffer
1535 (switch-to-buffer "*Gnus Help Bug*")
1537 (insert gnus-bug-message)
1538 (goto-char (point-min)))
1539 (message-pop-to-buffer "*Gnus Bug*"))
1540 (let ((message-this-is-mail t))
1541 (message-setup `((To . ,gnus-maintainer)
1544 . ,(format "%s" gnus-bug-package))
1546 . ,(format "%s" (gnus-continuum-version))))))
1547 (when gnus-bug-create-help-buffer
1548 (push `(gnus-bug-kill-buffer) message-send-actions))
1549 (goto-char (point-min))
1551 (insert "\n\n\n\n\n")
1552 (insert (gnus-version) "\n"
1553 (emacs-version) "\n")
1554 (when (and (boundp 'nntp-server-type)
1555 (stringp nntp-server-type))
1556 (insert nntp-server-type))
1557 (goto-char (point-min))
1558 (search-forward "Subject: " nil t)
1561 (defun gnus-bug-kill-buffer ()
1562 (when (get-buffer "*Gnus Help Bug*")
1563 (kill-buffer "*Gnus Help Bug*")))
1565 (defun gnus-summary-yank-message (buffer n)
1566 "Yank the current article into a composed message."
1568 (list (gnus-completing-read "Buffer" (message-buffers) t)
1569 current-prefix-arg))
1570 (gnus-summary-iterate n
1571 (let ((gnus-inhibit-treatment t))
1572 (gnus-summary-select-article))
1573 (with-current-buffer buffer
1574 (message-yank-buffer gnus-article-buffer))))
1576 ;;; Treatment of rejected articles.
1579 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1580 "Re-mail the current message.
1581 This only makes sense if the current message is a bounce message that
1582 contains some mail you have written which has been bounced back to
1584 If FETCH, try to fetch the article that this is a reply to, if indeed
1587 (gnus-summary-select-article t)
1588 (let (summary-buffer parent)
1591 (setq summary-buffer (current-buffer))
1592 (set-buffer gnus-original-article-buffer)
1594 (when (re-search-forward "^References:\n?" nil t)
1595 (while (memq (char-after) '(?\t ? ))
1597 (skip-chars-backward "\t\n ")
1599 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1600 (set-buffer gnus-original-article-buffer))
1601 (gnus-setup-message 'compose-bounce
1604 (gnus-inews-insert-gcc)
1605 ;; If there are references, we fetch the article we answered to.
1607 (with-current-buffer summary-buffer
1608 (gnus-summary-refer-article parent)
1609 (gnus-summary-show-all-headers))))))
1613 (defun gnus-inews-group-method (group)
1615 ;; If the group doesn't exist, we assume
1616 ;; it's an archive group...
1617 ((and (null (gnus-get-info group))
1618 (eq (car (gnus-server-to-method gnus-message-archive-method))
1619 (car (gnus-server-to-method (gnus-group-method group)))))
1620 gnus-message-archive-method)
1622 ((gnus-info-method (gnus-get-info group))
1623 (gnus-info-method (gnus-get-info group)))
1625 (t (gnus-server-to-method (gnus-group-method group)))))
1627 ;; Do Gcc handling, which copied the message over to some group.
1628 (defun gnus-inews-do-gcc (&optional gcc)
1632 (message-narrow-to-headers)
1633 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1634 (cur (current-buffer))
1635 groups group method group-art options
1636 mml-externalize-attachments)
1638 (message-remove-header "gcc")
1640 (setq groups (message-unquote-tokens
1641 (message-tokenize-header gcc " ,")))
1642 ;; Copy the article over to some group(s).
1643 (while (setq group (pop groups))
1644 (setq method (gnus-inews-group-method group)
1645 group (mm-encode-coding-string
1647 (gnus-group-name-charset method group)))
1648 (unless (gnus-check-server method)
1649 (error "Can't open server %s" (if (stringp method) method
1651 (unless (gnus-request-group group t method)
1652 (gnus-request-create-group group method))
1653 (setq mml-externalize-attachments
1654 (if (stringp gnus-gcc-externalize-attachments)
1655 (string-match gnus-gcc-externalize-attachments group)
1656 gnus-gcc-externalize-attachments))
1658 (nnheader-set-temp-buffer " *acc*")
1659 (setq message-options (with-current-buffer cur message-options))
1660 (insert-buffer-substring cur)
1661 (run-hooks 'gnus-gcc-pre-body-encode-hook)
1662 (message-encode-message-body)
1663 (run-hooks 'gnus-gcc-post-body-encode-hook)
1665 (message-narrow-to-headers)
1666 (let* ((mail-parse-charset message-default-charset)
1667 (newsgroups-field (save-restriction
1668 (message-narrow-to-headers-or-head)
1669 (message-fetch-field "Newsgroups")))
1670 (followup-field (save-restriction
1671 (message-narrow-to-headers-or-head)
1672 (message-fetch-field "Followup-To")))
1673 ;; BUG: We really need to get the charset for
1674 ;; each name in the Newsgroups and Followup-To
1675 ;; lines to allow crossposting between group
1676 ;; names with incompatible character sets.
1677 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1678 (group-field-charset
1679 (gnus-group-name-charset
1680 method (or newsgroups-field "")))
1681 (followup-field-charset
1682 (gnus-group-name-charset
1683 method (or followup-field "")))
1684 (rfc2047-header-encoding-alist
1686 (when group-field-charset
1687 (list (cons "Newsgroups" group-field-charset)))
1688 (when followup-field-charset
1689 (list (cons "Followup-To" followup-field-charset)))
1690 rfc2047-header-encoding-alist)))
1691 (mail-encode-encoded-word-buffer)))
1692 (goto-char (point-min))
1693 (when (re-search-forward
1694 (concat "^" (regexp-quote mail-header-separator) "$")
1696 (replace-match "" t t ))
1697 (when (or (not (gnus-check-backend-function
1698 'request-accept-article group))
1699 (not (setq group-art
1700 (gnus-request-accept-article
1701 group method t t))))
1702 (gnus-message 1 "Couldn't store article in group %s: %s"
1703 group (gnus-status-message method)))
1704 (when (stringp method)
1705 (setq method (gnus-server-to-method method)))
1706 (when (and (listp method)
1707 (gnus-native-method-p method))
1708 (setq group (gnus-group-short-name group)))
1709 (when (and group-art
1710 ;; FIXME: Should gcc-mark-as-read work when
1711 ;; Gnus is not running?
1713 (if (or gnus-gcc-mark-as-read
1714 (and (boundp 'gnus-inews-mark-gcc-as-read)
1715 (symbol-value 'gnus-inews-mark-gcc-as-read)))
1716 (gnus-group-mark-article-read group (cdr group-art))
1717 (with-current-buffer gnus-group-buffer
1718 (let ((gnus-group-marked (list group))
1719 (gnus-get-new-news-hook nil)
1720 (inhibit-read-only t))
1721 (gnus-group-get-new-news-this-group nil t)))))
1722 (setq options message-options)
1723 (with-current-buffer cur (setq message-options options))
1724 (kill-buffer (current-buffer)))))))))
1726 (defun gnus-inews-insert-gcc (&optional group)
1727 "Insert the Gcc to say where the article is to be archived."
1728 (let* ((group (or group gnus-newsgroup-name))
1729 (group (when group (gnus-group-decoded-name group)))
1730 (var (or gnus-outgoing-message-group gnus-message-archive-group))
1732 (and group (gnus-group-find-parameter group 'gcc-self)))
1736 ((null gnus-message-archive-method)
1740 ;; Just a single group.
1743 ;; We don't want this.
1745 ((and (listp var) (stringp (car var)))
1746 ;; A list of groups.
1750 (funcall var group))
1752 ;; An alist of regexps/functions/forms.
1757 ((stringp (caar var))
1759 (when (string-match (caar var) group)
1761 ((functionp (car var))
1763 (funcall (car var) group))
1765 (eval (car var)))))))
1766 (setq var (cdr var)))
1769 (when (or groups gcc-self-val)
1770 (when (stringp groups)
1771 (setq groups (list groups)))
1774 (message-narrow-to-headers)
1775 (goto-char (point-max))
1778 ;; Use the `gcc-self' param value instead.
1781 (if (stringp gcc-self-val)
1782 (if (string-match " " gcc-self-val)
1783 (concat "\"" gcc-self-val "\"")
1785 ;; In nndoc groups, we use the parent group name
1786 ;; instead of the current group.
1787 (let ((group (or (gnus-group-find-parameter
1788 gnus-newsgroup-name 'parent-group)
1790 (if (string-match " " group)
1791 (concat "\"" group "\"")
1793 (if (not (eq gcc-self-val 'none))
1795 (gnus-delete-line)))
1796 ;; Use the list of groups.
1797 (while (setq name (pop groups))
1798 (let ((str (if (string-match ":" name)
1800 (gnus-group-prefixed-name
1801 name gnus-message-archive-method))))
1802 (insert (if (string-match " " str)
1803 (concat "\"" str "\"")
1809 (defun gnus-mailing-list-followup-to ()
1810 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1811 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1812 (list-post (gnus-fetch-original-field "list-post")))
1813 (when (and list-post
1814 (string-match "mailto:\\([^>]+\\)" list-post))
1815 (setq list-post (match-string 1 list-post)))
1821 (defun gnus-configure-posting-styles (&optional group-name)
1822 "Configure posting styles according to `gnus-posting-styles'."
1823 (unless gnus-inhibit-posting-styles
1824 (let ((group (or group-name gnus-newsgroup-name ""))
1825 (styles (if (gnus-buffer-live-p gnus-summary-buffer)
1826 (with-current-buffer gnus-summary-buffer
1827 gnus-posting-styles)
1828 gnus-posting-styles))
1829 style match attribute value v results
1830 filep name address element)
1831 ;; If the group has a posting-style parameter, add it at the end with a
1832 ;; regexp matching everything, to be sure it takes precedence over all
1834 (when gnus-newsgroup-name
1835 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1837 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1838 ;; Go through all styles and look for matches.
1839 (dolist (style styles)
1840 (setq match (pop style))
1841 (goto-char (point-min))
1844 ;; Regexp string match on the group name.
1845 (string-match match group))
1847 ;; Obsolete format of header match.
1848 (and (gnus-buffer-live-p gnus-article-copy)
1849 (with-current-buffer gnus-article-copy
1851 (nnheader-narrow-to-headers)
1852 (let ((header (message-fetch-field (pop style))))
1854 (string-match (pop style) header)))))))
1855 ((or (symbolp match)
1859 ;; Function to be called.
1862 ;; Variable to be checked.
1863 (symbol-value match))))
1866 ((eq (car match) 'header)
1867 ;; New format of header match.
1868 (and (gnus-buffer-live-p gnus-article-copy)
1869 (with-current-buffer gnus-article-copy
1871 (nnheader-narrow-to-headers)
1872 (let ((header (message-fetch-field (nth 1 match))))
1874 (string-match (nth 2 match) header)))))))
1876 ;; This is a form to be evalled.
1878 ;; We have a match, so we set the variables.
1879 (dolist (attribute style)
1880 (setq element (pop attribute)
1884 ((eq (car attribute) :file)
1887 ((eq (car attribute) :value)
1891 ;; We get the value.
1895 (if (and (stringp match)
1896 (gnus-string-match-p "\\\\[&[:digit:]]" value)
1897 (match-beginning 1))
1898 (gnus-match-substitute-replacement value nil nil group)
1900 ((or (symbolp value)
1902 (cond ((functionp value)
1905 (symbol-value value))))
1908 ;; Translate obsolescent value.
1910 ((eq element 'signature-file)
1911 (setq element 'signature
1913 ((eq element 'x-face-file)
1914 (setq element 'x-face
1916 ;; Post-processing for the signature posting-style:
1917 (and (eq element 'signature) filep
1918 message-signature-directory
1919 ;; don't actually use the signature directory
1920 ;; if message-signature-file contains a path.
1921 (not (file-name-directory v))
1922 (setq v (nnheader-concat message-signature-directory v)))
1923 ;; Get the contents of file elems.
1925 (setq v (with-temp-buffer
1926 (insert-file-contents v)
1930 (goto-char (point-max))
1931 (if (zerop (skip-chars-backward "\n"))
1934 (setq results (delq (assoc element results) results))
1935 (push (cons element v) results))))
1936 ;; Now we have all the styles, so we insert them.
1937 (setq name (assq 'name results)
1938 address (assq 'address results))
1939 (setq results (delq name (delq address results)))
1940 (gnus-make-local-hook 'message-setup-hook)
1941 (setq results (sort results (lambda (x y)
1942 (string-lessp (car x) (car y)))))
1943 (dolist (result results)
1944 (add-hook 'message-setup-hook
1946 ((eq 'eval (car result))
1948 ((eq 'body (car result))
1952 (insert ,(cdr result)))))
1953 ((eq 'signature (car result))
1954 (set (make-local-variable 'message-signature) nil)
1955 (set (make-local-variable 'message-signature-file) nil)
1956 (if (not (cdr result))
1960 (let ((message-signature ,(cdr result)))
1961 (when message-signature
1962 (message-insert-signature)))))))
1965 (if (symbolp (car result))
1966 (capitalize (symbol-name (car result)))
1970 (message-remove-header ,header)
1971 (let ((value ,(cdr result)))
1974 (insert ,header ": " value)
1976 (insert "\n")))))))))
1978 (when (or name address)
1979 (add-hook 'message-setup-hook
1981 (set (make-local-variable 'user-mail-address)
1982 ,(or (cdr address) user-mail-address))
1983 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1985 ,(or (cdr address) user-mail-address)))
1987 (message-remove-header "From")
1989 (insert "From: " (message-make-from) "\n"))))
1992 ;;; Allow redefinition of functions.
1998 ;;; gnus-msg.el ends here