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 (user-mail-address user-mail-address))
846 (dolist (article (gnus-summary-work-articles n))
847 (when (gnus-summary-select-article t nil nil article)
848 ;; Pretend that we're doing a followup so that we can see what
849 ;; the From header would have ended up being.
850 (save-window-excursion
852 (gnus-summary-followup nil)
853 (let ((from (message-fetch-field "from")))
855 (setq user-mail-address
856 (car (mail-header-parse-address from)))))
857 (kill-buffer (current-buffer))))
858 ;; Now cancel the article using the From header we got.
859 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
860 (message-cancel-news))
861 (gnus-summary-mark-as-read article gnus-canceled-mark)
862 (gnus-cache-remove-article 1))
863 (gnus-article-hide-headers-if-wanted))
864 (gnus-summary-remove-process-mark article))))
866 (defun gnus-summary-supersede-article ()
867 "Compose an article that will supersede a previous article.
868 This is done simply by taking the old article and adding a Supersedes
869 header line with the old Message-ID."
871 (let ((article (gnus-summary-article-number))
872 (mail-parse-charset gnus-newsgroup-charset))
873 (gnus-setup-message 'reply-yank
874 (gnus-summary-select-article t)
875 (set-buffer gnus-original-article-buffer)
879 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
880 (with-current-buffer ,gnus-summary-buffer
881 (gnus-cache-possibly-remove-article ,article nil nil nil t)
882 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
883 message-send-actions)
885 (gnus-inews-insert-gcc))))
889 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
890 ;; make a copy of the article buffer with all text properties removed
891 ;; this copy is in the buffer gnus-article-copy.
892 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
893 ;; this buffer should be passed to all mail/news reply/post routines.
894 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
895 (with-current-buffer gnus-article-copy
896 (mm-enable-multibyte))
897 (let ((article-buffer (or article-buffer gnus-article-buffer))
899 (if (not (and (get-buffer article-buffer)
900 (gnus-buffer-exists-p article-buffer)))
901 (error "Can't find any article buffer")
902 (with-current-buffer article-buffer
903 (let ((gnus-newsgroup-charset (or gnus-article-charset
904 gnus-newsgroup-charset))
905 (gnus-newsgroup-ignored-charsets
906 (or gnus-article-ignored-charsets
907 gnus-newsgroup-ignored-charsets)))
909 ;; Copy over the (displayed) article buffer, delete
910 ;; hidden text and remove text properties.
912 (copy-to-buffer gnus-article-copy (point-min) (point-max))
913 (set-buffer gnus-article-copy)
916 (delete-region (point) (point-max))
917 (insert yank-string))
918 (gnus-article-delete-text-of-type 'annotation)
919 (gnus-article-delete-text-of-type 'multipart)
920 (gnus-remove-text-with-property 'gnus-prev)
921 (gnus-remove-text-with-property 'gnus-next)
922 (gnus-remove-text-with-property 'gnus-decoration)
925 (buffer-substring-no-properties (point-min) (point-max))
927 ;; Find the original headers.
928 (set-buffer gnus-original-article-buffer)
929 (goto-char (point-min))
930 (while (looking-at message-unix-mail-delimiter)
932 (let ((mail-header-separator ""))
934 end (or (message-goto-body)
935 ;; There may be just a header.
937 ;; Delete the headers from the displayed articles.
938 (set-buffer gnus-article-copy)
939 (let ((mail-header-separator ""))
940 (delete-region (goto-char (point-min))
941 (or (message-goto-body) (point-max))))
942 ;; Insert the original article headers.
943 (insert-buffer-substring gnus-original-article-buffer beg end)
945 (let ((gnus-article-decode-hook
946 (delq 'article-decode-charset
947 (copy-sequence gnus-article-decode-hook)))
948 (rfc2047-quote-decoded-words-containing-tspecials t))
949 (run-hooks 'gnus-article-decode-hook)))))
952 (defun gnus-post-news (post &optional group header article-buffer yank subject
955 (gnus-copy-article-buffer))
956 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
957 (gnus-article-yanked-articles yank)
958 (add-to-list gnus-add-to-list))
959 (gnus-setup-message (cond (yank 'reply-yank)
960 (article-buffer 'reply)
962 (let* ((group (or group gnus-newsgroup-name))
963 (charset (gnus-group-name-charset nil group))
965 to-address to-group mailing-list to-list
968 (setq to-address (gnus-parameter-to-address group)
969 to-group (gnus-group-find-parameter group 'to-group)
970 to-list (gnus-parameter-to-list group)
971 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
972 mailing-list (when gnus-mailing-list-groups
973 (string-match gnus-mailing-list-groups group))
974 group (gnus-group-name-decode (gnus-group-real-name group)
976 (if (or (and to-group
977 (gnus-news-group-p to-group))
980 (and (gnus-news-group-p
981 (or pgroup gnus-newsgroup-name)
982 (or header gnus-current-article))
990 (and (not (gnus-virtual-group-p pgroup)) group)))
991 (set-buffer gnus-article-copy)
992 (gnus-msg-treat-broken-reply-to)
993 (message-followup (if (or newsgroup-p force-news)
994 (if (save-restriction
995 (article-narrow-to-head)
996 (message-fetch-field "newsgroups"))
1003 (message-mail (or to-address to-list))
1004 ;; Arrange for mail groups that have no `to-address' to
1005 ;; get that when the user sends off the mail.
1006 (when (and (not to-list)
1009 (push (list 'gnus-inews-add-to-address pgroup)
1010 message-send-actions)))
1011 (set-buffer gnus-article-copy)
1012 (gnus-msg-treat-broken-reply-to)
1013 (message-wide-reply to-address)))
1015 (gnus-inews-yank-articles yank))))))
1017 (defun gnus-msg-treat-broken-reply-to (&optional force)
1018 "Remove the Reply-to header if broken-reply-to."
1020 (gnus-group-find-parameter
1021 gnus-newsgroup-name 'broken-reply-to))
1023 (message-narrow-to-head)
1024 (message-remove-header "reply-to"))))
1026 (defun gnus-post-method (arg group &optional silent)
1027 "Return the posting method based on GROUP and ARG.
1028 If SILENT, don't prompt the user."
1029 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1031 (group-method (gnus-find-method-for-group group)))
1033 ;; If the group-method is nil (which shouldn't happen) we use
1034 ;; the default method.
1035 ((null group-method)
1036 (or (and (listp gnus-post-method) ;If not current/native/nil
1037 (not (listp (car gnus-post-method))) ; and not a list of methods
1038 gnus-post-method) ;then use it.
1040 message-post-method))
1041 ;; We want the inverse of the default
1042 ((and arg (not (eq arg 0)))
1043 (if (eq gnus-post-method 'current)
1046 ;; We query the user for a post method.
1048 (and (listp gnus-post-method)
1049 (listp (car gnus-post-method))))
1051 ;; Collect all methods we know about.
1053 (when (listp gnus-post-method)
1054 (if (listp (car gnus-post-method))
1056 (list gnus-post-method)))
1057 gnus-secondary-select-methods
1058 (mapcar 'cdr gnus-server-alist)
1059 (mapcar 'car gnus-opened-servers)
1060 (list gnus-select-method)
1061 (list group-method)))
1062 method-alist post-methods method)
1063 ;; Weed out all mail methods.
1065 (setq method (gnus-server-get-method "" (pop methods)))
1066 (when (and (or (gnus-method-option-p method 'post)
1067 (gnus-method-option-p method 'post-mail))
1068 (not (member method post-methods)))
1069 (push method post-methods)))
1070 ;; Create a name-method alist.
1074 (if (equal (cadr m) "")
1075 (list (symbol-name (car m)) m)
1076 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1081 (setq gnus-last-posting-server
1083 gnus-last-posting-server)
1084 ;; Just use the last value.
1085 gnus-last-posting-server
1086 (gnus-completing-read
1087 "Posting method" (mapcar 'car method-alist) t
1088 (cons (or gnus-last-posting-server "") 0))))
1090 ;; Override normal method.
1091 ((and (eq gnus-post-method 'current)
1092 (not (memq (car group-method) gnus-discouraged-post-methods))
1093 (gnus-get-function group-method 'request-post t))
1096 ;; Use gnus-post-method.
1097 ((listp gnus-post-method) ;A method...
1098 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1100 ;; Use the normal select method (nil or native).
1101 (t gnus-select-method))))
1105 (defun gnus-extended-version ()
1106 "Stringified Gnus version and Emacs version.
1107 See the variable `gnus-user-agent'."
1109 (if (stringp gnus-user-agent)
1111 ;; `gnus-user-agent' is a list:
1112 (let* ((float-output-format nil)
1114 (when (memq 'gnus gnus-user-agent)
1116 (prin1-to-string (gnus-continuum-version gnus-version) t)
1117 " (" gnus-version ")")))
1118 (emacs-v (gnus-emacs-version)))
1119 (concat gnus-v (when (and gnus-v emacs-v) " ")
1124 ;;; Gnus Mail Functions
1127 ;;; Mail reply commands of Gnus summary mode
1129 (defun gnus-summary-reply (&optional yank wide very-wide)
1130 "Start composing a mail reply to the current message.
1131 If prefix argument YANK is non-nil, the original article is yanked
1133 If WIDE, make a wide reply.
1134 If VERY-WIDE, make a very wide reply."
1136 (list (and current-prefix-arg
1137 (gnus-summary-work-articles 1))))
1138 ;; Allow user to require confirmation before replying by mail to the
1139 ;; author of a news article (or mail message).
1140 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1141 gnus-confirm-treat-mail-like-news))
1142 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1143 (string-match gnus-confirm-mail-reply-to-news
1144 gnus-newsgroup-name))
1145 ((functionp gnus-confirm-mail-reply-to-news)
1146 (funcall gnus-confirm-mail-reply-to-news
1147 gnus-newsgroup-name))
1148 (t gnus-confirm-mail-reply-to-news)))
1149 (if (or wide very-wide)
1150 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1152 (y-or-n-p "Really reply by mail to article author? ")))
1154 (if (listp (car yank))
1157 (gnus-article-reply (or article (gnus-summary-article-number)))
1158 (gnus-article-yanked-articles yank)
1160 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1162 (gnus-summary-goto-subject article))
1163 (gnus-setup-message (if yank 'reply-yank 'reply)
1165 (gnus-summary-select-article)
1166 (dolist (article very-wide)
1167 (gnus-summary-select-article nil nil nil article)
1168 (with-current-buffer (gnus-copy-article-buffer)
1169 (gnus-msg-treat-broken-reply-to)
1171 (message-narrow-to-head)
1172 (setq headers (concat headers (buffer-string)))))))
1173 (set-buffer (gnus-copy-article-buffer))
1174 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1176 (message-narrow-to-head)
1180 (goto-char (point-max)))
1181 (mml-quote-region (point) (point-max))
1182 (message-reply nil wide)
1184 (gnus-inews-yank-articles yank))
1185 (gnus-summary-handle-replysign)))))
1187 (defun gnus-summary-handle-replysign ()
1188 "Check the various replysign variables and take action accordingly."
1189 (when (or gnus-message-replysign gnus-message-replyencrypt)
1190 (let (signed encrypted)
1191 (with-current-buffer gnus-article-buffer
1192 (setq signed (memq 'signed gnus-article-wash-types))
1193 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1194 (cond ((and gnus-message-replyencrypt encrypted)
1195 (mml-secure-message mml-default-encrypt-method
1196 (if gnus-message-replysignencrypted
1199 ((and gnus-message-replysign signed)
1200 (mml-secure-message mml-default-sign-method 'sign))))))
1202 (defun gnus-summary-reply-with-original (n &optional wide)
1203 "Start composing a reply mail to the current message.
1204 The original article will be yanked."
1206 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1208 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1209 "Start composing a reply mail to the current message.
1210 The reply goes only to the mailing list.
1211 The original article will be yanked."
1213 (let ((message-reply-to-function
1215 `((To . ,(gnus-mailing-list-followup-to))))))
1216 (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1218 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1219 "Like `gnus-summary-reply' except removing reply-to field.
1220 If prefix argument YANK is non-nil, the original article is yanked
1222 If WIDE, make a wide reply.
1223 If VERY-WIDE, make a very wide reply."
1225 (list (and current-prefix-arg
1226 (gnus-summary-work-articles 1))))
1227 (let ((gnus-msg-force-broken-reply-to t))
1228 (gnus-summary-reply yank wide very-wide)))
1230 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1231 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1232 The original article will be yanked."
1234 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1236 (defun gnus-summary-wide-reply (&optional yank)
1237 "Start composing a wide reply mail to the current message.
1238 If prefix argument YANK is non-nil, the original article is yanked
1241 (list (and current-prefix-arg
1242 (gnus-summary-work-articles 1))))
1243 (gnus-summary-reply yank t))
1245 (defun gnus-summary-wide-reply-with-original (n)
1246 "Start composing a wide reply mail to the current message.
1247 The original article will be yanked.
1248 Uses the process/prefix convention."
1250 (gnus-summary-reply-with-original n t))
1252 (defun gnus-summary-very-wide-reply (&optional yank)
1253 "Start composing a very wide reply mail to the current message.
1254 If prefix argument YANK is non-nil, the original article is yanked
1257 (list (and current-prefix-arg
1258 (gnus-summary-work-articles 1))))
1259 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1261 (defun gnus-summary-very-wide-reply-with-original (n)
1262 "Start composing a very wide reply mail to the current message.
1263 The original article will be yanked."
1266 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1268 (defun gnus-summary-mail-forward (&optional arg post)
1269 "Forward the current message(s) to another user.
1270 If process marks exist, forward all marked messages;
1271 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1272 if ARG is 1, decode the message and forward directly inline;
1273 if ARG is 2, forward message as an rfc822 MIME section;
1274 if ARG is 3, decode message and forward as an rfc822 MIME section;
1275 if ARG is 4, forward message directly inline;
1276 otherwise, use flipped `message-forward-as-mime'.
1277 If POST, post instead of mail.
1278 For the \"inline\" alternatives, also see the variable
1279 `message-forward-ignored-headers'."
1281 (if (cdr (gnus-summary-work-articles nil))
1282 ;; Process marks are given.
1283 (gnus-uu-digest-mail-forward nil post)
1284 ;; No process marks.
1285 (let ((message-forward-as-mime message-forward-as-mime)
1286 (message-forward-show-mml message-forward-show-mml))
1290 (setq message-forward-as-mime nil
1291 message-forward-show-mml t))
1293 (setq message-forward-as-mime t
1294 message-forward-show-mml nil))
1296 (setq message-forward-as-mime t
1297 message-forward-show-mml t))
1299 (setq message-forward-as-mime nil
1300 message-forward-show-mml nil))
1302 (setq message-forward-as-mime (not message-forward-as-mime))))
1303 (let* ((gnus-article-reply (gnus-summary-article-number))
1304 (gnus-article-yanked-articles (list gnus-article-reply)))
1305 (gnus-setup-message 'forward
1306 (gnus-summary-select-article)
1307 (let ((mail-parse-charset
1308 (or (and (gnus-buffer-live-p gnus-article-buffer)
1309 (with-current-buffer gnus-article-buffer
1310 gnus-article-charset))
1311 gnus-newsgroup-charset))
1312 (mail-parse-ignored-charsets
1313 gnus-newsgroup-ignored-charsets))
1314 (set-buffer gnus-original-article-buffer)
1315 (message-forward post)))))))
1317 (defun gnus-summary-resend-message-insert-gcc ()
1318 "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1319 (gnus-inews-insert-gcc)
1322 (mm-encode-coding-string
1324 (gnus-group-name-charset (gnus-inews-group-method group)
1326 (message-unquote-tokens
1327 (message-tokenize-header (mail-fetch-field "gcc" nil t)
1329 (self (with-current-buffer gnus-summary-buffer
1330 gnus-gcc-self-resent-messages)))
1331 (message-remove-header "gcc")
1333 (goto-char (point-max))
1334 (cond ((eq self 'none))
1336 (insert "Gcc: \"" gnus-newsgroup-name "\"\n"))
1339 (mm-encode-coding-string
1340 (if (string-match " " self)
1341 (concat "\"" self "\"")
1343 (gnus-group-name-charset (gnus-inews-group-method self)
1347 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n"))
1348 ((eq self 'no-gcc-self)
1349 (when (setq gcc (delete
1351 (delete (concat "\"" gnus-newsgroup-name "\"")
1353 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n")))))))
1355 (defun gnus-summary-resend-message (address n)
1356 "Resend the current article to ADDRESS."
1358 (list (message-read-from-minibuffer
1359 "Resend message(s) to: "
1360 (when (and gnus-summary-resend-default-address
1361 (gnus-buffer-live-p gnus-original-article-buffer))
1362 ;; If some other article is currently selected, the
1363 ;; initial-contents is wrong. Whatever, it is just the
1364 ;; initial-contents.
1365 (with-current-buffer gnus-original-article-buffer
1366 (nnmail-fetch-field "to"))))
1367 current-prefix-arg))
1368 (let ((message-header-setup-hook (copy-sequence message-header-setup-hook))
1369 (message-sent-hook (copy-sequence message-sent-hook)))
1370 ;; `gnus-summary-resend-message-insert-gcc' must run last.
1371 (add-hook 'message-header-setup-hook
1372 'gnus-summary-resend-message-insert-gcc t)
1373 (add-hook 'message-sent-hook
1375 (let ((rfc2047-encode-encoded-words nil))
1377 '(gnus-agent-possibly-do-gcc)
1378 '(gnus-inews-do-gcc)))))
1379 (dolist (article (gnus-summary-work-articles n))
1380 (gnus-summary-select-article nil nil nil article)
1381 (with-current-buffer gnus-original-article-buffer
1382 (let ((gnus-gcc-externalize-attachments nil)
1383 (message-inhibit-body-encoding t))
1384 (message-resend address)))
1385 (gnus-summary-mark-article-as-forwarded article))))
1387 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1388 (defun gnus-summary-resend-message-edit ()
1389 "Resend an article that has already been sent.
1390 A new buffer will be created to allow the user to modify body and
1391 contents of the message, and then, everything will happen as when
1392 composing a new message."
1394 (let ((mail-parse-charset gnus-newsgroup-charset))
1395 (gnus-setup-message 'reply-yank
1396 (gnus-summary-select-article t)
1397 (set-buffer gnus-original-article-buffer)
1398 (let ((cur (current-buffer))
1399 (to (message-fetch-field "to")))
1400 ;; Get a normal message buffer.
1401 (message-pop-to-buffer (message-buffer-name "Resend" to))
1402 (insert-buffer-substring cur)
1404 (message-narrow-to-head-1)
1405 ;; Gnus will generate a new one when sending.
1406 (message-remove-header "Message-ID")
1407 ;; Remove unwanted headers.
1408 (message-remove-header message-ignored-resent-headers t)
1409 (goto-char (point-max))
1410 (insert mail-header-separator)
1412 (gnus-inews-insert-gcc)
1413 (goto-char (point-min))
1414 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1418 (defun gnus-summary-post-forward (&optional arg)
1419 "Forward the current article to a newsgroup.
1420 See `gnus-summary-mail-forward' for ARG."
1422 (gnus-summary-mail-forward arg t))
1424 (defun gnus-summary-mail-crosspost-complaint (n)
1425 "Send a complaint about crossposting to the current article(s)."
1427 (dolist (article (gnus-summary-work-articles n))
1428 (set-buffer gnus-summary-buffer)
1429 (gnus-summary-goto-subject article)
1430 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1431 newsgroups followup-to)
1432 (gnus-summary-select-article)
1433 (set-buffer gnus-original-article-buffer)
1434 (if (and (<= (length (message-tokenize-header
1436 (mail-fetch-field "newsgroups"))
1439 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1440 (not (member group (message-tokenize-header
1441 followup-to ", ")))))
1443 (gnus-message 1 "Followup-to restricted")
1444 (gnus-message 1 "Not a crossposted article"))
1445 (set-buffer gnus-summary-buffer)
1446 (gnus-summary-reply-with-original 1)
1447 (set-buffer gnus-message-buffer)
1449 (insert (format gnus-crosspost-complaint newsgroups group))
1450 (message-goto-subject)
1451 (re-search-forward " *$")
1452 (replace-match " (crosspost notification)" t t)
1453 (gnus-deactivate-mark)
1454 (when (gnus-y-or-n-p "Send this complaint? ")
1455 (message-send-and-exit))))))
1457 (defun gnus-mail-parse-comma-list ()
1460 (skip-chars-forward " ")
1463 (skip-chars-forward "^,")
1468 (narrow-to-region beg (point))
1471 (while (search-forward "\"" nil t)
1475 (skip-chars-forward ",")
1476 (skip-chars-forward "^,"))
1477 (skip-chars-backward " ")
1478 (push (buffer-substring beg (point))
1480 (skip-chars-forward "^,")
1481 (skip-chars-forward ", "))
1484 (defun gnus-inews-add-to-address (group)
1485 (let ((to-address (mail-fetch-field "to")))
1486 (when (and to-address
1488 ;; This mail group doesn't have a `to-list', so we add one
1490 (when (gnus-y-or-n-p
1491 (format "Do you want to add this as `to-list': %s? " to-address))
1492 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1494 (defun gnus-put-message ()
1495 "Put the current message in some group and return to Gnus."
1497 (let ((reply gnus-article-reply)
1498 (winconf gnus-prev-winconf)
1499 (group gnus-newsgroup-name))
1501 (not (gnus-group-read-only-p group)))
1502 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1504 (when (gnus-group-entry group)
1505 (error "No such group: %s" group))
1509 (message-narrow-to-headers)
1510 (let ((gnus-deletable-headers nil))
1511 (message-generate-headers
1512 (if (message-news-p)
1513 message-required-news-headers
1514 message-required-mail-headers)))
1515 (goto-char (point-max))
1516 (if (string-match " " group)
1517 (insert "Gcc: \"" group "\"\n")
1518 (insert "Gcc: " group "\n"))
1521 (when (and (get-buffer gnus-group-buffer)
1522 (gnus-buffer-exists-p (car-safe reply))
1524 (set-buffer (car reply))
1525 (gnus-summary-mark-article-as-replied (cdr reply)))
1527 (set-window-configuration winconf))))
1529 (defun gnus-article-mail (yank)
1530 "Send a reply to the address near point.
1531 If YANK is non-nil, include the original article."
1535 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1536 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1538 (gnus-msg-mail address)
1540 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1542 (defvar nntp-server-type)
1544 "Send a bug report to the Gnus maintainers."
1546 (unless (gnus-alive-p)
1547 (error "Gnus has been shut down"))
1548 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1549 (unless (message-mail-user-agent)
1550 (when gnus-bug-create-help-buffer
1551 (switch-to-buffer "*Gnus Help Bug*")
1553 (insert gnus-bug-message)
1554 (goto-char (point-min)))
1555 (message-pop-to-buffer "*Gnus Bug*"))
1556 (let ((message-this-is-mail t))
1557 (message-setup `((To . ,gnus-maintainer)
1560 . ,(format "%s" gnus-bug-package))
1562 . ,(format "%s" (gnus-continuum-version))))))
1563 (when gnus-bug-create-help-buffer
1564 (push `(gnus-bug-kill-buffer) message-send-actions))
1565 (goto-char (point-min))
1567 (insert "\n\n\n\n\n")
1568 (insert (gnus-version) "\n"
1569 (emacs-version) "\n")
1570 (when (and (boundp 'nntp-server-type)
1571 (stringp nntp-server-type))
1572 (insert nntp-server-type))
1573 (goto-char (point-min))
1574 (search-forward "Subject: " nil t)
1577 (defun gnus-bug-kill-buffer ()
1578 (when (get-buffer "*Gnus Help Bug*")
1579 (kill-buffer "*Gnus Help Bug*")))
1581 (defun gnus-summary-yank-message (buffer n)
1582 "Yank the current article into a composed message."
1584 (list (gnus-completing-read "Buffer" (message-buffers) t)
1585 current-prefix-arg))
1586 (gnus-summary-iterate n
1587 (let ((gnus-inhibit-treatment t))
1588 (gnus-summary-select-article))
1589 (with-current-buffer buffer
1590 (message-yank-buffer gnus-article-buffer))))
1592 ;;; Treatment of rejected articles.
1595 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1596 "Re-mail the current message.
1597 This only makes sense if the current message is a bounce message that
1598 contains some mail you have written which has been bounced back to
1600 If FETCH, try to fetch the article that this is a reply to, if indeed
1603 (gnus-summary-select-article t)
1604 (let (summary-buffer parent)
1607 (setq summary-buffer (current-buffer))
1608 (set-buffer gnus-original-article-buffer)
1610 (when (re-search-forward "^References:\n?" nil t)
1611 (while (memq (char-after) '(?\t ? ))
1613 (skip-chars-backward "\t\n ")
1615 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1616 (set-buffer gnus-original-article-buffer))
1617 (gnus-setup-message 'compose-bounce
1620 (gnus-inews-insert-gcc)
1621 ;; If there are references, we fetch the article we answered to.
1623 (with-current-buffer summary-buffer
1624 (gnus-summary-refer-article parent)
1625 (gnus-summary-show-all-headers))))))
1629 (defun gnus-inews-group-method (group)
1631 ;; If the group doesn't exist, we assume
1632 ;; it's an archive group...
1633 ((and (null (gnus-get-info group))
1634 (eq (car (gnus-server-to-method gnus-message-archive-method))
1635 (car (gnus-server-to-method (gnus-group-method group)))))
1636 gnus-message-archive-method)
1638 ((gnus-info-method (gnus-get-info group))
1639 (gnus-info-method (gnus-get-info group)))
1641 (t (gnus-server-to-method (gnus-group-method group)))))
1643 ;; Do Gcc handling, which copied the message over to some group.
1644 (defun gnus-inews-do-gcc (&optional gcc)
1648 (message-narrow-to-headers)
1649 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1650 (cur (current-buffer))
1651 groups group method group-art options
1652 mml-externalize-attachments)
1654 (message-remove-header "gcc")
1656 (setq groups (message-unquote-tokens
1657 (message-tokenize-header gcc " ,")))
1658 ;; Copy the article over to some group(s).
1659 (while (setq group (pop groups))
1660 (setq method (gnus-inews-group-method group)
1661 group (mm-encode-coding-string
1663 (gnus-group-name-charset method group)))
1664 (unless (gnus-check-server method)
1665 (error "Can't open server %s" (if (stringp method) method
1667 (unless (gnus-request-group group t method)
1668 (gnus-request-create-group group method))
1669 (setq mml-externalize-attachments
1670 (if (stringp gnus-gcc-externalize-attachments)
1671 (string-match gnus-gcc-externalize-attachments group)
1672 gnus-gcc-externalize-attachments))
1674 (nnheader-set-temp-buffer " *acc*")
1675 (setq message-options (with-current-buffer cur message-options))
1676 (insert-buffer-substring cur)
1677 (run-hooks 'gnus-gcc-pre-body-encode-hook)
1678 (message-encode-message-body)
1679 (run-hooks 'gnus-gcc-post-body-encode-hook)
1681 (message-narrow-to-headers)
1682 (let* ((mail-parse-charset message-default-charset)
1683 (newsgroups-field (save-restriction
1684 (message-narrow-to-headers-or-head)
1685 (message-fetch-field "Newsgroups")))
1686 (followup-field (save-restriction
1687 (message-narrow-to-headers-or-head)
1688 (message-fetch-field "Followup-To")))
1689 ;; BUG: We really need to get the charset for
1690 ;; each name in the Newsgroups and Followup-To
1691 ;; lines to allow crossposting between group
1692 ;; names with incompatible character sets.
1693 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1694 (group-field-charset
1695 (gnus-group-name-charset
1696 method (or newsgroups-field "")))
1697 (followup-field-charset
1698 (gnus-group-name-charset
1699 method (or followup-field "")))
1700 (rfc2047-header-encoding-alist
1702 (when group-field-charset
1703 (list (cons "Newsgroups" group-field-charset)))
1704 (when followup-field-charset
1705 (list (cons "Followup-To" followup-field-charset)))
1706 rfc2047-header-encoding-alist)))
1707 (mail-encode-encoded-word-buffer)))
1708 (goto-char (point-min))
1709 (when (re-search-forward
1710 (concat "^" (regexp-quote mail-header-separator) "$")
1712 (replace-match "" t t ))
1713 (when (or (not (gnus-check-backend-function
1714 'request-accept-article group))
1715 (not (setq group-art
1716 (gnus-request-accept-article
1717 group method t t))))
1718 (gnus-message 1 "Couldn't store article in group %s: %s"
1719 group (gnus-status-message method)))
1720 (when (stringp method)
1721 (setq method (gnus-server-to-method method)))
1722 (when (and (listp method)
1723 (gnus-native-method-p method))
1724 (setq group (gnus-group-short-name group)))
1725 (when (and group-art
1726 ;; FIXME: Should gcc-mark-as-read work when
1727 ;; Gnus is not running?
1729 (if (or gnus-gcc-mark-as-read
1730 (and (boundp 'gnus-inews-mark-gcc-as-read)
1731 (symbol-value 'gnus-inews-mark-gcc-as-read)))
1732 (gnus-group-mark-article-read group (cdr group-art))
1733 (with-current-buffer gnus-group-buffer
1734 (let ((gnus-group-marked (list group))
1735 (gnus-get-new-news-hook nil)
1736 (inhibit-read-only t))
1737 (gnus-group-get-new-news-this-group nil t)))))
1738 (setq options message-options)
1739 (with-current-buffer cur (setq message-options options))
1740 (kill-buffer (current-buffer)))))))))
1742 (defun gnus-inews-insert-gcc (&optional group)
1743 "Insert the Gcc to say where the article is to be archived."
1744 (let* ((group (or group gnus-newsgroup-name))
1745 (group (when group (gnus-group-decoded-name group)))
1746 (var (or gnus-outgoing-message-group gnus-message-archive-group))
1748 (and group (gnus-group-find-parameter group 'gcc-self)))
1752 ((null gnus-message-archive-method)
1756 ;; Just a single group.
1759 ;; We don't want this.
1761 ((and (listp var) (stringp (car var)))
1762 ;; A list of groups.
1766 (funcall var group))
1768 ;; An alist of regexps/functions/forms.
1774 (stringp (caar var)))
1776 (when (string-match (caar var) group)
1779 (functionp (car var)))
1781 (funcall (car var) group))
1783 (eval (car var)))))))
1784 (setq var (cdr var)))
1787 (when (or groups gcc-self-val)
1788 (when (stringp groups)
1789 (setq groups (list groups)))
1792 (message-narrow-to-headers)
1793 (goto-char (point-max))
1796 ;; Use the `gcc-self' param value instead.
1799 (if (stringp gcc-self-val)
1800 (if (string-match " " gcc-self-val)
1801 (concat "\"" gcc-self-val "\"")
1803 ;; In nndoc groups, we use the parent group name
1804 ;; instead of the current group.
1805 (let ((group (or (gnus-group-find-parameter
1806 gnus-newsgroup-name 'parent-group)
1808 (if (string-match " " group)
1809 (concat "\"" group "\"")
1811 (if (not (eq gcc-self-val 'none))
1813 (gnus-delete-line)))
1814 ;; Use the list of groups.
1815 (while (setq name (pop groups))
1816 (let ((str (if (string-match ":" name)
1818 (gnus-group-prefixed-name
1819 name gnus-message-archive-method))))
1820 (insert (if (string-match " " str)
1821 (concat "\"" str "\"")
1827 (defun gnus-mailing-list-followup-to ()
1828 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1829 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1830 (list-post (gnus-fetch-original-field "list-post")))
1831 (when (and list-post
1832 (string-match "mailto:\\([^>]+\\)" list-post))
1833 (setq list-post (match-string 1 list-post)))
1839 (defun gnus-configure-posting-styles (&optional group-name)
1840 "Configure posting styles according to `gnus-posting-styles'."
1841 (unless gnus-inhibit-posting-styles
1842 (let ((group (or group-name gnus-newsgroup-name ""))
1843 (styles (if (gnus-buffer-live-p gnus-summary-buffer)
1844 (with-current-buffer gnus-summary-buffer
1845 gnus-posting-styles)
1846 gnus-posting-styles))
1847 style match attribute value v results
1848 filep name address element)
1849 ;; If the group has a posting-style parameter, add it at the end with a
1850 ;; regexp matching everything, to be sure it takes precedence over all
1852 (when gnus-newsgroup-name
1853 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1855 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1856 ;; Go through all styles and look for matches.
1857 (dolist (style styles)
1858 (setq match (pop style))
1859 (goto-char (point-min))
1862 ;; Regexp string match on the group name.
1863 (string-match match group))
1865 ;; Obsolete format of header match.
1866 (and (gnus-buffer-live-p gnus-article-copy)
1867 (with-current-buffer gnus-article-copy
1869 (nnheader-narrow-to-headers)
1870 (let ((header (message-fetch-field (pop style))))
1872 (string-match (pop style) header)))))))
1873 ((or (symbolp match)
1877 ;; Function to be called.
1880 ;; Variable to be checked.
1881 (symbol-value match))))
1884 ((eq (car match) 'header)
1885 ;; New format of header match.
1886 (and (gnus-buffer-live-p gnus-article-copy)
1887 (with-current-buffer gnus-article-copy
1889 (nnheader-narrow-to-headers)
1890 (let ((header (message-fetch-field (nth 1 match))))
1892 (string-match (nth 2 match) header)))))))
1894 ;; This is a form to be evalled.
1896 ;; We have a match, so we set the variables.
1897 (dolist (attribute style)
1898 (setq element (pop attribute)
1902 ((eq (car attribute) :file)
1905 ((eq (car attribute) :value)
1909 ;; We get the value.
1913 (if (and (stringp match)
1914 (gnus-string-match-p "\\\\[&[:digit:]]" value)
1915 (match-beginning 1))
1916 (gnus-match-substitute-replacement value nil nil group)
1918 ((or (symbolp value)
1920 (cond ((functionp value)
1923 (symbol-value value))))
1926 ;; Translate obsolescent value.
1928 ((eq element 'signature-file)
1929 (setq element 'signature
1931 ((eq element 'x-face-file)
1932 (setq element 'x-face
1934 ;; Post-processing for the signature posting-style:
1935 (and (eq element 'signature) filep
1936 message-signature-directory
1937 ;; don't actually use the signature directory
1938 ;; if message-signature-file contains a path.
1939 (not (file-name-directory v))
1940 (setq v (nnheader-concat message-signature-directory v)))
1941 ;; Get the contents of file elems.
1943 (setq v (with-temp-buffer
1944 (insert-file-contents v)
1948 (goto-char (point-max))
1949 (if (zerop (skip-chars-backward "\n"))
1952 (setq results (delq (assoc element results) results))
1953 (push (cons element v) results))))
1954 ;; Now we have all the styles, so we insert them.
1955 (setq name (assq 'name results)
1956 address (assq 'address results))
1957 (setq results (delq name (delq address results)))
1958 (gnus-make-local-hook 'message-setup-hook)
1959 (setq results (sort results (lambda (x y)
1960 (string-lessp (car x) (car y)))))
1961 (dolist (result results)
1962 (add-hook 'message-setup-hook
1964 ((eq 'eval (car result))
1966 ((eq 'body (car result))
1970 (insert ,(cdr result)))))
1971 ((eq 'signature (car result))
1972 (set (make-local-variable 'message-signature) nil)
1973 (set (make-local-variable 'message-signature-file) nil)
1974 (if (not (cdr result))
1978 (let ((message-signature ,(cdr result)))
1979 (when message-signature
1980 (message-insert-signature)))))))
1983 (if (symbolp (car result))
1984 (capitalize (symbol-name (car result)))
1988 (message-remove-header ,header)
1989 (let ((value ,(cdr result)))
1992 (insert ,header ": " value)
1994 (insert "\n")))))))))
1996 (when (or name address)
1997 (add-hook 'message-setup-hook
1999 (set (make-local-variable 'user-mail-address)
2000 ,(or (cdr address) user-mail-address))
2001 (let ((user-full-name ,(or (cdr name) (user-full-name)))
2003 ,(or (cdr address) user-mail-address)))
2005 (message-remove-header "From")
2007 (insert "From: " (message-make-from) "\n"))))
2010 ;;; Allow redefinition of functions.
2016 ;;; gnus-msg.el ends here