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 (autoload 'gnus-message-citation-mode "gnus-cite" nil t)
318 ;;; Internal variables.
320 (defvar gnus-inhibit-posting-styles nil
321 "Inhibit the use of posting styles.")
323 (defvar gnus-article-yanked-articles nil)
324 (defvar gnus-message-buffer "*Mail Gnus*")
325 (defvar gnus-article-copy nil)
326 (defvar gnus-check-before-posting nil)
327 (defvar gnus-last-posting-server nil)
328 (defvar gnus-message-group-art nil)
330 (defvar gnus-msg-force-broken-reply-to nil)
332 (defconst gnus-bug-message
333 "Sending a bug report to the Gnus Towers.
334 ========================================
336 The buffer below is a mail buffer. When you press `C-c C-c', it will
337 be sent to the Gnus Bug Exterminators.
339 The thing near the bottom of the buffer is how the environment
340 settings will be included in the mail. Please do not delete that.
341 They will tell the Bug People what your environment is, so that it
342 will be easier to locate the bugs.
344 If you have found a bug that makes Emacs go \"beep\", set
345 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
346 and include the backtrace in your bug report.
348 Please describe the bug in annoying, painstaking detail.
350 Thank you for your help in stamping out bugs.
353 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
357 ;;; Gnus Posting Functions
360 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
361 "p" gnus-summary-post-news
362 "i" gnus-summary-news-other-window
363 "f" gnus-summary-followup
364 "F" gnus-summary-followup-with-original
365 "c" gnus-summary-cancel-article
366 "s" gnus-summary-supersede-article
367 "r" gnus-summary-reply
368 "y" gnus-summary-yank-message
369 "R" gnus-summary-reply-with-original
370 "L" gnus-summary-reply-to-list-with-original
371 "w" gnus-summary-wide-reply
372 "W" gnus-summary-wide-reply-with-original
373 "v" gnus-summary-very-wide-reply
374 "V" gnus-summary-very-wide-reply-with-original
375 "n" gnus-summary-followup-to-mail
376 "N" gnus-summary-followup-to-mail-with-original
377 "m" gnus-summary-mail-other-window
378 "u" gnus-uu-post-news
379 "\M-c" gnus-summary-mail-crosspost-complaint
380 "Br" gnus-summary-reply-broken-reply-to
381 "BR" gnus-summary-reply-broken-reply-to-with-original
382 "om" gnus-summary-mail-forward
383 "op" gnus-summary-post-forward
384 "Om" gnus-uu-digest-mail-forward
385 "Op" gnus-uu-digest-post-forward)
387 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
388 "b" gnus-summary-resend-bounced-mail
389 ;; "c" gnus-summary-send-draft
390 "r" gnus-summary-resend-message
391 "e" gnus-summary-resend-message-edit)
393 ;;; Internal functions.
395 (defun gnus-inews-make-draft (articles)
397 (gnus-inews-make-draft-meta-information
398 ,(gnus-group-decoded-name gnus-newsgroup-name) ',articles)))
400 (defvar gnus-article-reply nil)
401 (defmacro gnus-setup-message (config &rest forms)
402 (let ((winconf (make-symbol "gnus-setup-message-winconf"))
403 (winconf-name (make-symbol "gnus-setup-message-winconf-name"))
404 (buffer (make-symbol "gnus-setup-message-buffer"))
405 (article (make-symbol "gnus-setup-message-article"))
406 (yanked (make-symbol "gnus-setup-yanked-articles"))
407 (group (make-symbol "gnus-setup-message-group")))
408 `(let ((,winconf (current-window-configuration))
409 (,winconf-name gnus-current-window-configuration)
410 (,buffer (buffer-name (current-buffer)))
411 (,article gnus-article-reply)
412 (,yanked gnus-article-yanked-articles)
413 (,group gnus-newsgroup-name)
414 (message-header-setup-hook
415 (copy-sequence message-header-setup-hook))
416 (mbl mml-buffer-list)
417 (message-mode-hook (copy-sequence message-mode-hook)))
418 (setq mml-buffer-list nil)
419 (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
420 ;; message-newsreader and message-mailer were formerly set in
421 ;; gnus-inews-add-send-actions, but this is too late when
422 ;; message-generate-headers-first is used. --ansel
423 (add-hook 'message-mode-hook
425 (setq message-newsreader
426 (setq message-mailer (gnus-extended-version)))))
427 ;; #### FIXME: for a reason that I did not manage to identify yet,
428 ;; the variable `gnus-newsgroup-name' does not honor a dynamically
429 ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
430 ;; After evaluation of @forms below, it gets the value we actually want
431 ;; to override, and the posting styles are used. For that reason, I've
432 ;; added an optional argument to `gnus-configure-posting-styles' to
433 ;; make sure that the correct value for the group name is used. -- drv
434 (add-hook 'message-mode-hook
435 (if (memq ,config '(reply-yank reply))
437 (gnus-configure-posting-styles ,group))
439 ;; There may be an old " *gnus article copy*" buffer.
440 (let (gnus-article-copy)
441 (gnus-configure-posting-styles ,group)))))
442 (gnus-alist-pull ',(intern gnus-draft-meta-information-header)
443 message-required-headers)
445 (not (string= ,group "")))
447 (intern gnus-draft-meta-information-header)
448 (gnus-inews-make-draft (or ,yanked ,article)))
449 message-required-headers))
453 (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
454 ,yanked ,winconf-name)
455 (setq gnus-message-buffer (current-buffer))
456 (set (make-local-variable 'gnus-message-group-art)
457 (cons ,group ,article))
458 (set (make-local-variable 'gnus-newsgroup-name) ,group)
459 ;; Enable highlighting of different citation levels
460 (when gnus-message-highlight-citation
461 (gnus-message-citation-mode 1))
462 (gnus-run-hooks 'gnus-message-setup-hook)
463 (if (eq major-mode 'message-mode)
464 (let ((mbl1 mml-buffer-list))
465 (setq mml-buffer-list mbl) ;; Global value
466 (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
467 (gnus-make-local-hook 'kill-buffer-hook)
468 (gnus-make-local-hook 'change-major-mode-hook)
469 (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
470 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
471 (mml-destroy-buffers)
472 (setq mml-buffer-list mbl)))
473 (message-hide-headers)
475 (gnus-configure-windows ,config t)
476 (run-hooks 'post-command-hook)
477 (set-buffer-modified-p nil))))
479 (defun gnus-inews-make-draft-meta-information (group articles)
480 (when (numberp articles)
481 (setq articles (list articles)))
482 (concat "(\"" group "\""
496 (defun gnus-msg-mail (&optional to subject other-headers continue
497 switch-action yank-action send-actions return-action)
498 "Start editing a mail message to be sent.
499 Like `message-mail', but with Gnus paraphernalia, particularly the
500 Gcc: header for archiving purposes."
502 (let ((buf (current-buffer))
504 (gnus-setup-message 'message
505 (message-mail to subject other-headers continue
506 nil yank-action send-actions return-action))
508 (setq mail-buf (current-buffer))
509 (switch-to-buffer buf)
510 (apply switch-action mail-buf nil)))
511 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
515 (defun gnus-button-mailto (address)
517 (set-buffer (gnus-copy-article-buffer))
518 (gnus-setup-message 'message
519 (message-reply address)))
522 (defun gnus-button-reply (&optional to-address wide)
523 "Like `message-reply'."
525 (gnus-setup-message 'message
526 (message-reply to-address wide)))
529 (define-mail-user-agent 'gnus-user-agent
530 'gnus-msg-mail 'message-send-and-exit
531 'message-kill-buffer 'message-send-hook)
533 (defun gnus-setup-posting-charset (group)
534 (let ((alist gnus-group-posting-charset-alist)
535 (group (or group ""))
539 (while (setq elem (pop alist))
540 (when (or (and (stringp (car elem))
541 (string-match (car elem) group))
542 (and (functionp (car elem))
543 (funcall (car elem) group))
544 (and (symbolp (car elem))
545 (symbol-value (car elem))))
546 (throw 'found (cons (cadr elem) (caddr elem)))))))))
548 (defun gnus-inews-add-send-actions (winconf buffer article
549 &optional config yanked
551 (gnus-make-local-hook 'message-sent-hook)
552 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
553 'gnus-inews-do-gcc) nil t)
555 (gnus-make-local-hook 'message-header-hook)
556 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
557 (setq message-post-method
558 `(lambda (&optional arg)
559 (gnus-post-method arg ,gnus-newsgroup-name)))
562 (setq gnus-current-window-configuration ',winconf-name)
563 (when (gnus-buffer-exists-p ,buffer)
564 (set-window-configuration ,winconf)))
565 'exit 'postpone 'kill)
566 (let ((to-be-marked (cond
569 (lambda (x) (if (listp x) (car x) x)) yanked))
570 (article (if (listp article) article (list article)))
573 `(when (gnus-buffer-exists-p ,buffer)
574 (with-current-buffer ,buffer
576 (if (eq config 'forward)
577 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
578 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
581 (put 'gnus-setup-message 'lisp-indent-function 1)
582 (put 'gnus-setup-message 'edebug-form-spec '(form body))
584 ;;; Post news commands of Gnus group mode and summary mode
586 (defun gnus-group-mail (&optional arg)
587 "Start composing a mail.
588 If ARG, use the group under the point to find a posting style.
589 If ARG is 1, prompt for a group name to find the posting style."
591 ;; We can't `let' gnus-newsgroup-name here, since that leads
592 ;; to local variables leaking.
593 (let ((group gnus-newsgroup-name)
594 ;; make sure last viewed article doesn't affect posting styles:
596 (buffer (current-buffer)))
599 (setq gnus-newsgroup-name
601 (if (= 1 (prefix-numeric-value arg))
602 (gnus-group-completing-read
603 "Use posting style of group"
604 nil (gnus-read-active-file-p))
605 (gnus-group-group-name))
607 ;; #### see comment in gnus-setup-message -- drv
608 (gnus-setup-message 'message (message-mail)))
609 (with-current-buffer buffer
610 (setq gnus-newsgroup-name group)))))
612 (defun gnus-group-news (&optional arg)
613 "Start composing a news.
614 If ARG, post to group under point.
615 If ARG is 1, prompt for group name to post to.
617 This function prepares a news even when using mail groups. This is useful
618 for posting messages to mail groups without actually sending them over the
619 network. The corresponding back end must have a 'request-post method."
621 ;; We can't `let' gnus-newsgroup-name here, since that leads
622 ;; to local variables leaking.
623 (let ((group gnus-newsgroup-name)
624 ;; make sure last viewed article doesn't affect posting styles:
626 (buffer (current-buffer)))
629 (setq gnus-newsgroup-name
631 (if (= 1 (prefix-numeric-value arg))
632 (gnus-group-completing-read "Use group"
634 (gnus-read-active-file-p))
635 (gnus-group-group-name))
637 ;; #### see comment in gnus-setup-message -- drv
638 (gnus-setup-message 'message
639 (message-news (gnus-group-real-name gnus-newsgroup-name))))
640 (with-current-buffer buffer
641 (setq gnus-newsgroup-name group)))))
643 (defun gnus-group-post-news (&optional arg)
644 "Start composing a message (a news by default).
645 If ARG, post to group under point. If ARG is 1, prompt for group name.
646 Depending on the selected group, the message might be either a mail or
649 ;; Bind this variable here to make message mode hooks work ok.
650 (let ((gnus-newsgroup-name
652 (if (= 1 (prefix-numeric-value arg))
653 (gnus-group-completing-read "Newsgroup" nil
654 (gnus-read-active-file-p))
655 (gnus-group-group-name))
657 ;; make sure last viewed article doesn't affect posting styles:
659 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
660 (string= gnus-newsgroup-name ""))))
662 (defun gnus-summary-mail-other-window (&optional arg)
663 "Start composing a mail in another window.
664 Use the posting of the current group by default.
665 If ARG, don't do that. If ARG is 1, prompt for group name to find the
668 ;; We can't `let' gnus-newsgroup-name here, since that leads
669 ;; to local variables leaking.
670 (let ((group gnus-newsgroup-name)
671 ;; make sure last viewed article doesn't affect posting styles:
673 (buffer (current-buffer)))
676 (setq gnus-newsgroup-name
678 (if (= 1 (prefix-numeric-value arg))
679 (gnus-group-completing-read "Use group"
681 (gnus-read-active-file-p))
683 gnus-newsgroup-name))
684 ;; #### see comment in gnus-setup-message -- drv
685 (gnus-setup-message 'message (message-mail)))
686 (with-current-buffer buffer
687 (setq gnus-newsgroup-name group)))))
689 (defun gnus-summary-news-other-window (&optional arg)
690 "Start composing a news in another window.
691 Post to the current group by default.
692 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
694 This function prepares a news even when using mail groups. This is useful
695 for posting messages to mail groups without actually sending them over the
696 network. The corresponding back end must have a 'request-post method."
698 ;; We can't `let' gnus-newsgroup-name here, since that leads
699 ;; to local variables leaking.
700 (let ((group gnus-newsgroup-name)
701 ;; make sure last viewed article doesn't affect posting styles:
703 (buffer (current-buffer)))
706 (setq gnus-newsgroup-name
708 (if (= 1 (prefix-numeric-value arg))
709 (gnus-group-completing-read "Use group"
711 (gnus-read-active-file-p))
713 gnus-newsgroup-name))
714 ;; #### see comment in gnus-setup-message -- drv
715 (gnus-setup-message 'message
717 (message-news (gnus-group-real-name gnus-newsgroup-name))
718 (set (make-local-variable 'gnus-discouraged-post-methods)
720 (car (gnus-find-method-for-group gnus-newsgroup-name))
721 gnus-discouraged-post-methods)))))
722 (with-current-buffer buffer
723 (setq gnus-newsgroup-name group)))))
725 (defun gnus-summary-post-news (&optional arg)
726 "Start composing a message. Post to the current group by default.
727 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
728 Depending on the selected group, the message might be either a mail or
731 ;; Bind this variable here to make message mode hooks work ok.
732 (let ((gnus-newsgroup-name
734 (if (= 1 (prefix-numeric-value arg))
735 (gnus-group-completing-read "Newsgroup" nil
736 (gnus-read-active-file-p))
738 gnus-newsgroup-name))
739 ;; make sure last viewed article doesn't affect posting styles:
741 (gnus-post-news 'post gnus-newsgroup-name)))
744 (defun gnus-summary-followup (yank &optional force-news)
745 "Compose a followup to an article.
746 If prefix argument YANK is non-nil, the original article is yanked
748 YANK is a list of elements, where the car of each element is the
749 article number, and the cdr is the string to be yanked."
751 (list (and current-prefix-arg
752 (gnus-summary-work-articles 1))))
754 (gnus-summary-goto-subject
755 (if (listp (car yank))
758 (save-window-excursion
759 (gnus-summary-select-article))
760 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
761 (gnus-newsgroup-name gnus-newsgroup-name))
763 (gnus-post-news nil gnus-newsgroup-name
764 headers gnus-article-buffer
766 (gnus-summary-handle-replysign)))
768 (defun gnus-summary-followup-with-original (n &optional force-news)
769 "Compose a followup to an article and include the original article.
770 The text in the region will be yanked. If the region isn't
771 active, the entire article will be yanked."
773 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
775 (defun gnus-summary-followup-to-mail (&optional arg)
776 "Followup to the current mail message via news."
778 (list (and current-prefix-arg
779 (gnus-summary-work-articles 1))))
780 (gnus-summary-followup arg t))
782 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
783 "Followup to the current mail message via news."
785 (gnus-summary-followup (gnus-summary-work-articles arg) t))
787 (defun gnus-inews-yank-articles (articles)
788 (let (beg article yank-string)
790 (while (setq article (pop articles))
791 (when (listp article)
792 (setq yank-string (nth 1 article)
793 article (nth 0 article)))
794 (save-window-excursion
795 (set-buffer gnus-summary-buffer)
796 (gnus-summary-select-article nil nil nil article)
797 (gnus-summary-remove-process-mark article))
798 (gnus-copy-article-buffer nil yank-string)
799 (let ((message-reply-buffer gnus-article-copy)
800 (message-reply-headers
801 ;; The headers are decoded.
802 (with-current-buffer gnus-article-copy
804 (nnheader-narrow-to-headers)
805 (nnheader-parse-naked-head)))))
806 (message-yank-original)
807 (message-exchange-point-and-mark)
808 (setq beg (or beg (mark t))))
814 (defun gnus-summary-cancel-article (&optional n symp)
815 "Cancel an article you posted.
816 Uses the process-prefix convention. If given the symbolic
817 prefix `a', cancel using the standard posting method; if not
818 post using the current select method."
819 (interactive (gnus-interactive "P\ny"))
820 (let ((message-post-method
822 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
823 (dolist (article (gnus-summary-work-articles n))
824 (when (gnus-summary-select-article t nil nil article)
825 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
826 (message-cancel-news))
827 (gnus-summary-mark-as-read article gnus-canceled-mark)
828 (gnus-cache-remove-article 1))
829 (gnus-article-hide-headers-if-wanted))
830 (gnus-summary-remove-process-mark article))))
832 (defun gnus-summary-supersede-article ()
833 "Compose an article that will supersede a previous article.
834 This is done simply by taking the old article and adding a Supersedes
835 header line with the old Message-ID."
837 (let ((article (gnus-summary-article-number))
838 (mail-parse-charset gnus-newsgroup-charset))
839 (gnus-setup-message 'reply-yank
840 (gnus-summary-select-article t)
841 (set-buffer gnus-original-article-buffer)
845 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
846 (with-current-buffer ,gnus-summary-buffer
847 (gnus-cache-possibly-remove-article ,article nil nil nil t)
848 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
849 message-send-actions)
851 (gnus-inews-insert-gcc))))
855 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
856 ;; make a copy of the article buffer with all text properties removed
857 ;; this copy is in the buffer gnus-article-copy.
858 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
859 ;; this buffer should be passed to all mail/news reply/post routines.
860 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
861 (with-current-buffer gnus-article-copy
862 (mm-enable-multibyte))
863 (let ((article-buffer (or article-buffer gnus-article-buffer))
865 (if (not (and (get-buffer article-buffer)
866 (gnus-buffer-exists-p article-buffer)))
867 (error "Can't find any article buffer")
868 (with-current-buffer article-buffer
869 (let ((gnus-newsgroup-charset (or gnus-article-charset
870 gnus-newsgroup-charset))
871 (gnus-newsgroup-ignored-charsets
872 (or gnus-article-ignored-charsets
873 gnus-newsgroup-ignored-charsets)))
875 ;; Copy over the (displayed) article buffer, delete
876 ;; hidden text and remove text properties.
878 (copy-to-buffer gnus-article-copy (point-min) (point-max))
879 (set-buffer gnus-article-copy)
882 (delete-region (point) (point-max))
883 (insert yank-string))
884 (gnus-article-delete-text-of-type 'annotation)
885 (gnus-article-delete-text-of-type 'multipart)
886 (gnus-remove-text-with-property 'gnus-prev)
887 (gnus-remove-text-with-property 'gnus-next)
888 (gnus-remove-text-with-property 'gnus-decoration)
891 (buffer-substring-no-properties (point-min) (point-max))
893 ;; Find the original headers.
894 (set-buffer gnus-original-article-buffer)
895 (goto-char (point-min))
896 (while (looking-at message-unix-mail-delimiter)
898 (let ((mail-header-separator ""))
900 end (or (message-goto-body)
901 ;; There may be just a header.
903 ;; Delete the headers from the displayed articles.
904 (set-buffer gnus-article-copy)
905 (let ((mail-header-separator ""))
906 (delete-region (goto-char (point-min))
907 (or (message-goto-body) (point-max))))
908 ;; Insert the original article headers.
909 (insert-buffer-substring gnus-original-article-buffer beg end)
911 (let ((gnus-article-decode-hook
912 (delq 'article-decode-charset
913 (copy-sequence gnus-article-decode-hook)))
914 (rfc2047-quote-decoded-words-containing-tspecials t))
915 (run-hooks 'gnus-article-decode-hook)))))
918 (defun gnus-post-news (post &optional group header article-buffer yank subject
921 (gnus-copy-article-buffer))
922 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
923 (gnus-article-yanked-articles yank)
924 (add-to-list gnus-add-to-list))
925 (gnus-setup-message (cond (yank 'reply-yank)
926 (article-buffer 'reply)
928 (let* ((group (or group gnus-newsgroup-name))
929 (charset (gnus-group-name-charset nil group))
931 to-address to-group mailing-list to-list
934 (setq to-address (gnus-parameter-to-address group)
935 to-group (gnus-group-find-parameter group 'to-group)
936 to-list (gnus-parameter-to-list group)
937 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
938 mailing-list (when gnus-mailing-list-groups
939 (string-match gnus-mailing-list-groups group))
940 group (gnus-group-name-decode (gnus-group-real-name group)
942 (if (or (and to-group
943 (gnus-news-group-p to-group))
946 (and (gnus-news-group-p
947 (or pgroup gnus-newsgroup-name)
948 (or header gnus-current-article))
956 (and (not (gnus-virtual-group-p pgroup)) group)))
957 (set-buffer gnus-article-copy)
958 (gnus-msg-treat-broken-reply-to)
959 (message-followup (if (or newsgroup-p force-news)
960 (if (save-restriction
961 (article-narrow-to-head)
962 (message-fetch-field "newsgroups"))
969 (message-mail (or to-address to-list))
970 ;; Arrange for mail groups that have no `to-address' to
971 ;; get that when the user sends off the mail.
972 (when (and (not to-list)
975 (push (list 'gnus-inews-add-to-address pgroup)
976 message-send-actions)))
977 (set-buffer gnus-article-copy)
978 (gnus-msg-treat-broken-reply-to)
979 (message-wide-reply to-address)))
981 (gnus-inews-yank-articles yank))))))
983 (defun gnus-msg-treat-broken-reply-to (&optional force)
984 "Remove the Reply-to header if broken-reply-to."
986 (gnus-group-find-parameter
987 gnus-newsgroup-name 'broken-reply-to))
989 (message-narrow-to-head)
990 (message-remove-header "reply-to"))))
992 (defun gnus-post-method (arg group &optional silent)
993 "Return the posting method based on GROUP and ARG.
994 If SILENT, don't prompt the user."
995 (let ((gnus-post-method (or (gnus-parameter-post-method group)
997 (group-method (gnus-find-method-for-group group)))
999 ;; If the group-method is nil (which shouldn't happen) we use
1000 ;; the default method.
1001 ((null group-method)
1002 (or (and (listp gnus-post-method) ;If not current/native/nil
1003 (not (listp (car gnus-post-method))) ; and not a list of methods
1004 gnus-post-method) ;then use it.
1006 message-post-method))
1007 ;; We want the inverse of the default
1008 ((and arg (not (eq arg 0)))
1009 (if (eq gnus-post-method 'current)
1012 ;; We query the user for a post method.
1014 (and (listp gnus-post-method)
1015 (listp (car gnus-post-method))))
1017 ;; Collect all methods we know about.
1019 (when (listp gnus-post-method)
1020 (if (listp (car gnus-post-method))
1022 (list gnus-post-method)))
1023 gnus-secondary-select-methods
1024 (mapcar 'cdr gnus-server-alist)
1025 (mapcar 'car gnus-opened-servers)
1026 (list gnus-select-method)
1027 (list group-method)))
1028 method-alist post-methods method)
1029 ;; Weed out all mail methods.
1031 (setq method (gnus-server-get-method "" (pop methods)))
1032 (when (and (or (gnus-method-option-p method 'post)
1033 (gnus-method-option-p method 'post-mail))
1034 (not (member method post-methods)))
1035 (push method post-methods)))
1036 ;; Create a name-method alist.
1040 (if (equal (cadr m) "")
1041 (list (symbol-name (car m)) m)
1042 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1047 (setq gnus-last-posting-server
1049 gnus-last-posting-server)
1050 ;; Just use the last value.
1051 gnus-last-posting-server
1052 (gnus-completing-read
1053 "Posting method" (mapcar 'car method-alist) t
1054 (cons (or gnus-last-posting-server "") 0))))
1056 ;; Override normal method.
1057 ((and (eq gnus-post-method 'current)
1058 (not (memq (car group-method) gnus-discouraged-post-methods))
1059 (gnus-get-function group-method 'request-post t))
1062 ;; Use gnus-post-method.
1063 ((listp gnus-post-method) ;A method...
1064 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1066 ;; Use the normal select method (nil or native).
1067 (t gnus-select-method))))
1071 (defun gnus-extended-version ()
1072 "Stringified Gnus version and Emacs version.
1073 See the variable `gnus-user-agent'."
1075 (if (stringp gnus-user-agent)
1077 ;; `gnus-user-agent' is a list:
1078 (let* ((float-output-format nil)
1080 (when (memq 'gnus gnus-user-agent)
1082 (prin1-to-string (gnus-continuum-version gnus-version) t)
1083 " (" gnus-version ")")))
1084 (emacs-v (gnus-emacs-version)))
1085 (concat gnus-v (when (and gnus-v emacs-v) " ")
1090 ;;; Gnus Mail Functions
1093 ;;; Mail reply commands of Gnus summary mode
1095 (defun gnus-summary-reply (&optional yank wide very-wide)
1096 "Start composing a mail reply to the current message.
1097 If prefix argument YANK is non-nil, the original article is yanked
1099 If WIDE, make a wide reply.
1100 If VERY-WIDE, make a very wide reply."
1102 (list (and current-prefix-arg
1103 (gnus-summary-work-articles 1))))
1104 ;; Allow user to require confirmation before replying by mail to the
1105 ;; author of a news article (or mail message).
1106 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1107 gnus-confirm-treat-mail-like-news))
1108 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1109 (string-match gnus-confirm-mail-reply-to-news
1110 gnus-newsgroup-name))
1111 ((functionp gnus-confirm-mail-reply-to-news)
1112 (funcall gnus-confirm-mail-reply-to-news
1113 gnus-newsgroup-name))
1114 (t gnus-confirm-mail-reply-to-news)))
1115 (if (or wide very-wide)
1116 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1118 (y-or-n-p "Really reply by mail to article author? ")))
1120 (if (listp (car yank))
1123 (gnus-article-reply (or article (gnus-summary-article-number)))
1124 (gnus-article-yanked-articles yank)
1126 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1128 (gnus-summary-goto-subject article))
1129 (gnus-setup-message (if yank 'reply-yank 'reply)
1131 (gnus-summary-select-article)
1132 (dolist (article very-wide)
1133 (gnus-summary-select-article nil nil nil article)
1134 (with-current-buffer (gnus-copy-article-buffer)
1135 (gnus-msg-treat-broken-reply-to)
1137 (message-narrow-to-head)
1138 (setq headers (concat headers (buffer-string)))))))
1139 (set-buffer (gnus-copy-article-buffer))
1140 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1142 (message-narrow-to-head)
1146 (goto-char (point-max)))
1147 (mml-quote-region (point) (point-max))
1148 (message-reply nil wide)
1150 (gnus-inews-yank-articles yank))
1151 (gnus-summary-handle-replysign)))))
1153 (defun gnus-summary-handle-replysign ()
1154 "Check the various replysign variables and take action accordingly."
1155 (when (or gnus-message-replysign gnus-message-replyencrypt)
1156 (let (signed encrypted)
1157 (with-current-buffer gnus-article-buffer
1158 (setq signed (memq 'signed gnus-article-wash-types))
1159 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1160 (cond ((and gnus-message-replyencrypt encrypted)
1161 (mml-secure-message mml-default-encrypt-method
1162 (if gnus-message-replysignencrypted
1165 ((and gnus-message-replysign signed)
1166 (mml-secure-message mml-default-sign-method 'sign))))))
1168 (defun gnus-summary-reply-with-original (n &optional wide)
1169 "Start composing a reply mail to the current message.
1170 The original article will be yanked."
1172 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1174 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1175 "Start composing a reply mail to the current message.
1176 The reply goes only to the mailing list.
1177 The original article will be yanked."
1179 (let ((message-reply-to-function
1181 `((To . ,(gnus-mailing-list-followup-to))))))
1182 (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1184 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1185 "Like `gnus-summary-reply' except removing reply-to field.
1186 If prefix argument YANK is non-nil, the original article is yanked
1188 If WIDE, make a wide reply.
1189 If VERY-WIDE, make a very wide reply."
1191 (list (and current-prefix-arg
1192 (gnus-summary-work-articles 1))))
1193 (let ((gnus-msg-force-broken-reply-to t))
1194 (gnus-summary-reply yank wide very-wide)))
1196 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1197 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1198 The original article will be yanked."
1200 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1202 (defun gnus-summary-wide-reply (&optional yank)
1203 "Start composing a wide reply mail to the current message.
1204 If prefix argument YANK is non-nil, the original article is yanked
1207 (list (and current-prefix-arg
1208 (gnus-summary-work-articles 1))))
1209 (gnus-summary-reply yank t))
1211 (defun gnus-summary-wide-reply-with-original (n)
1212 "Start composing a wide reply mail to the current message.
1213 The original article will be yanked.
1214 Uses the process/prefix convention."
1216 (gnus-summary-reply-with-original n t))
1218 (defun gnus-summary-very-wide-reply (&optional yank)
1219 "Start composing a very wide reply mail to the current message.
1220 If prefix argument YANK is non-nil, the original article is yanked
1223 (list (and current-prefix-arg
1224 (gnus-summary-work-articles 1))))
1225 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1227 (defun gnus-summary-very-wide-reply-with-original (n)
1228 "Start composing a very wide reply mail to the current message.
1229 The original article will be yanked."
1232 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1234 (defun gnus-summary-mail-forward (&optional arg post)
1235 "Forward the current message(s) to another user.
1236 If process marks exist, forward all marked messages;
1237 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1238 if ARG is 1, decode the message and forward directly inline;
1239 if ARG is 2, forward message as an rfc822 MIME section;
1240 if ARG is 3, decode message and forward as an rfc822 MIME section;
1241 if ARG is 4, forward message directly inline;
1242 otherwise, use flipped `message-forward-as-mime'.
1243 If POST, post instead of mail.
1244 For the \"inline\" alternatives, also see the variable
1245 `message-forward-ignored-headers'."
1247 (if (cdr (gnus-summary-work-articles nil))
1248 ;; Process marks are given.
1249 (gnus-uu-digest-mail-forward nil post)
1250 ;; No process marks.
1251 (let ((message-forward-as-mime message-forward-as-mime)
1252 (message-forward-show-mml message-forward-show-mml))
1256 (setq message-forward-as-mime nil
1257 message-forward-show-mml t))
1259 (setq message-forward-as-mime t
1260 message-forward-show-mml nil))
1262 (setq message-forward-as-mime t
1263 message-forward-show-mml t))
1265 (setq message-forward-as-mime nil
1266 message-forward-show-mml nil))
1268 (setq message-forward-as-mime (not message-forward-as-mime))))
1269 (let* ((gnus-article-reply (gnus-summary-article-number))
1270 (gnus-article-yanked-articles (list gnus-article-reply)))
1271 (gnus-setup-message 'forward
1272 (gnus-summary-select-article)
1273 (let ((mail-parse-charset
1274 (or (and (gnus-buffer-live-p gnus-article-buffer)
1275 (with-current-buffer gnus-article-buffer
1276 gnus-article-charset))
1277 gnus-newsgroup-charset))
1278 (mail-parse-ignored-charsets
1279 gnus-newsgroup-ignored-charsets))
1280 (set-buffer gnus-original-article-buffer)
1281 (message-forward post)))))))
1283 (defun gnus-summary-resend-message-insert-gcc ()
1284 "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1285 (gnus-inews-insert-gcc)
1288 (mm-encode-coding-string
1290 (gnus-group-name-charset (gnus-inews-group-method group)
1292 (message-unquote-tokens
1293 (message-tokenize-header (mail-fetch-field "gcc" nil t)
1295 (message-remove-header "gcc")
1297 (goto-char (point-max))
1298 (cond ((eq gnus-gcc-self-resent-messages 'none))
1299 ((eq gnus-gcc-self-resent-messages t)
1300 (insert "Gcc: \"" gnus-newsgroup-name "\"\n"))
1301 ((stringp gnus-gcc-self-resent-messages)
1303 (mm-encode-coding-string
1304 (if (string-match " " gnus-gcc-self-resent-messages)
1305 (concat "\"" gnus-gcc-self-resent-messages "\"")
1306 gnus-gcc-self-resent-messages)
1307 (gnus-group-name-charset
1308 (gnus-inews-group-method gnus-gcc-self-resent-messages)
1309 gnus-gcc-self-resent-messages))
1311 ((null gnus-gcc-self-resent-messages)
1312 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n"))
1313 ((eq gnus-gcc-self-resent-messages 'no-gcc-self)
1314 (when (setq gcc (delete
1316 (delete (concat "\"" gnus-newsgroup-name "\"")
1318 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n")))))))
1320 (defun gnus-summary-resend-message (address n)
1321 "Resend the current article to ADDRESS."
1323 (list (message-read-from-minibuffer
1324 "Resend message(s) to: "
1325 (when (and gnus-summary-resend-default-address
1326 (gnus-buffer-live-p gnus-original-article-buffer))
1327 ;; If some other article is currently selected, the
1328 ;; initial-contents is wrong. Whatever, it is just the
1329 ;; initial-contents.
1330 (with-current-buffer gnus-original-article-buffer
1331 (nnmail-fetch-field "to"))))
1332 current-prefix-arg))
1333 (let ((message-header-setup-hook (copy-sequence message-header-setup-hook))
1334 (message-sent-hook (copy-sequence message-sent-hook)))
1335 (add-hook 'message-header-setup-hook
1336 'gnus-summary-resend-message-insert-gcc)
1337 (add-hook 'message-sent-hook (if gnus-agent
1338 'gnus-agent-possibly-do-gcc
1339 'gnus-inews-do-gcc))
1340 (dolist (article (gnus-summary-work-articles n))
1341 (gnus-summary-select-article nil nil nil article)
1342 (with-current-buffer gnus-original-article-buffer
1343 (let ((gnus-gcc-externalize-attachments nil)
1344 (message-inhibit-body-encoding t))
1345 (message-resend address)))
1346 (gnus-summary-mark-article-as-forwarded article))))
1348 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1349 (defun gnus-summary-resend-message-edit ()
1350 "Resend an article that has already been sent.
1351 A new buffer will be created to allow the user to modify body and
1352 contents of the message, and then, everything will happen as when
1353 composing a new message."
1355 (let ((mail-parse-charset gnus-newsgroup-charset))
1356 (gnus-setup-message 'reply-yank
1357 (gnus-summary-select-article t)
1358 (set-buffer gnus-original-article-buffer)
1359 (let ((cur (current-buffer))
1360 (to (message-fetch-field "to")))
1361 ;; Get a normal message buffer.
1362 (message-pop-to-buffer (message-buffer-name "Resend" to))
1363 (insert-buffer-substring cur)
1365 (message-narrow-to-head-1)
1366 ;; Gnus will generate a new one when sending.
1367 (message-remove-header "Message-ID")
1368 ;; Remove unwanted headers.
1369 (message-remove-header message-ignored-resent-headers t)
1370 (goto-char (point-max))
1371 (insert mail-header-separator)
1373 (gnus-inews-insert-gcc)
1374 (goto-char (point-min))
1375 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1379 (defun gnus-summary-post-forward (&optional arg)
1380 "Forward the current article to a newsgroup.
1381 See `gnus-summary-mail-forward' for ARG."
1383 (gnus-summary-mail-forward arg t))
1385 (defun gnus-summary-mail-crosspost-complaint (n)
1386 "Send a complaint about crossposting to the current article(s)."
1388 (dolist (article (gnus-summary-work-articles n))
1389 (set-buffer gnus-summary-buffer)
1390 (gnus-summary-goto-subject article)
1391 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1392 newsgroups followup-to)
1393 (gnus-summary-select-article)
1394 (set-buffer gnus-original-article-buffer)
1395 (if (and (<= (length (message-tokenize-header
1397 (mail-fetch-field "newsgroups"))
1400 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1401 (not (member group (message-tokenize-header
1402 followup-to ", ")))))
1404 (gnus-message 1 "Followup-to restricted")
1405 (gnus-message 1 "Not a crossposted article"))
1406 (set-buffer gnus-summary-buffer)
1407 (gnus-summary-reply-with-original 1)
1408 (set-buffer gnus-message-buffer)
1410 (insert (format gnus-crosspost-complaint newsgroups group))
1411 (message-goto-subject)
1412 (re-search-forward " *$")
1413 (replace-match " (crosspost notification)" t t)
1414 (gnus-deactivate-mark)
1415 (when (gnus-y-or-n-p "Send this complaint? ")
1416 (message-send-and-exit))))))
1418 (defun gnus-mail-parse-comma-list ()
1421 (skip-chars-forward " ")
1424 (skip-chars-forward "^,")
1429 (narrow-to-region beg (point))
1432 (while (search-forward "\"" nil t)
1436 (skip-chars-forward ",")
1437 (skip-chars-forward "^,"))
1438 (skip-chars-backward " ")
1439 (push (buffer-substring beg (point))
1441 (skip-chars-forward "^,")
1442 (skip-chars-forward ", "))
1445 (defun gnus-inews-add-to-address (group)
1446 (let ((to-address (mail-fetch-field "to")))
1447 (when (and to-address
1449 ;; This mail group doesn't have a `to-list', so we add one
1451 (when (gnus-y-or-n-p
1452 (format "Do you want to add this as `to-list': %s? " to-address))
1453 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1455 (defun gnus-put-message ()
1456 "Put the current message in some group and return to Gnus."
1458 (let ((reply gnus-article-reply)
1459 (winconf gnus-prev-winconf)
1460 (group gnus-newsgroup-name))
1462 (not (gnus-group-read-only-p group)))
1463 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1465 (when (gnus-group-entry group)
1466 (error "No such group: %s" group))
1470 (message-narrow-to-headers)
1471 (let ((gnus-deletable-headers nil))
1472 (message-generate-headers
1473 (if (message-news-p)
1474 message-required-news-headers
1475 message-required-mail-headers)))
1476 (goto-char (point-max))
1477 (if (string-match " " group)
1478 (insert "Gcc: \"" group "\"\n")
1479 (insert "Gcc: " group "\n"))
1482 (when (and (get-buffer gnus-group-buffer)
1483 (gnus-buffer-exists-p (car-safe reply))
1485 (set-buffer (car reply))
1486 (gnus-summary-mark-article-as-replied (cdr reply)))
1488 (set-window-configuration winconf))))
1490 (defun gnus-article-mail (yank)
1491 "Send a reply to the address near point.
1492 If YANK is non-nil, include the original article."
1496 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1497 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1499 (gnus-msg-mail address)
1501 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1503 (defvar nntp-server-type)
1505 "Send a bug report to the Gnus maintainers."
1507 (unless (gnus-alive-p)
1508 (error "Gnus has been shut down"))
1509 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1510 (unless (message-mail-user-agent)
1511 (delete-other-windows)
1512 (when gnus-bug-create-help-buffer
1513 (switch-to-buffer "*Gnus Help Bug*")
1515 (insert gnus-bug-message)
1516 (goto-char (point-min)))
1517 (message-pop-to-buffer "*Gnus Bug*"))
1518 (let ((message-this-is-mail t))
1519 (message-setup `((To . ,gnus-maintainer)
1522 . ,(format "%s" gnus-bug-package))
1524 . ,(format "%s" (gnus-continuum-version))))))
1525 (when gnus-bug-create-help-buffer
1526 (push `(gnus-bug-kill-buffer) message-send-actions))
1527 (goto-char (point-min))
1529 (insert "\n\n\n\n\n")
1530 (insert (gnus-version) "\n"
1531 (emacs-version) "\n")
1532 (when (and (boundp 'nntp-server-type)
1533 (stringp nntp-server-type))
1534 (insert nntp-server-type))
1535 (goto-char (point-min))
1536 (search-forward "Subject: " nil t)
1539 (defun gnus-bug-kill-buffer ()
1540 (when (get-buffer "*Gnus Help Bug*")
1541 (kill-buffer "*Gnus Help Bug*")))
1543 (defun gnus-summary-yank-message (buffer n)
1544 "Yank the current article into a composed message."
1546 (list (gnus-completing-read "Buffer" (message-buffers) t)
1547 current-prefix-arg))
1548 (gnus-summary-iterate n
1549 (let ((gnus-inhibit-treatment t))
1550 (gnus-summary-select-article))
1551 (with-current-buffer buffer
1552 (message-yank-buffer gnus-article-buffer))))
1554 ;;; Treatment of rejected articles.
1557 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1558 "Re-mail the current message.
1559 This only makes sense if the current message is a bounce message that
1560 contains some mail you have written which has been bounced back to
1562 If FETCH, try to fetch the article that this is a reply to, if indeed
1565 (gnus-summary-select-article t)
1566 (let (summary-buffer parent)
1569 (setq summary-buffer (current-buffer))
1570 (set-buffer gnus-original-article-buffer)
1572 (when (re-search-forward "^References:\n?" nil t)
1573 (while (memq (char-after) '(?\t ? ))
1575 (skip-chars-backward "\t\n ")
1577 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1578 (set-buffer gnus-original-article-buffer))
1579 (gnus-setup-message 'compose-bounce
1582 (gnus-inews-insert-gcc)
1583 ;; If there are references, we fetch the article we answered to.
1585 (with-current-buffer summary-buffer
1586 (gnus-summary-refer-article parent)
1587 (gnus-summary-show-all-headers))))))
1591 (defun gnus-inews-group-method (group)
1593 ;; If the group doesn't exist, we assume
1594 ;; it's an archive group...
1595 ((and (null (gnus-get-info group))
1596 (eq (car (gnus-server-to-method gnus-message-archive-method))
1597 (car (gnus-server-to-method (gnus-group-method group)))))
1598 gnus-message-archive-method)
1600 ((gnus-info-method (gnus-get-info group))
1601 (gnus-info-method (gnus-get-info group)))
1603 (t (gnus-server-to-method (gnus-group-method group)))))
1605 ;; Do Gcc handling, which copied the message over to some group.
1606 (defun gnus-inews-do-gcc (&optional gcc)
1610 (message-narrow-to-headers)
1611 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1612 (cur (current-buffer))
1613 groups group method group-art options
1614 mml-externalize-attachments)
1616 (message-remove-header "gcc")
1618 (setq groups (message-unquote-tokens
1619 (message-tokenize-header gcc " ,")))
1620 ;; Copy the article over to some group(s).
1621 (while (setq group (pop groups))
1622 (setq method (gnus-inews-group-method group)
1623 group (mm-encode-coding-string
1625 (gnus-group-name-charset method group)))
1626 (unless (gnus-check-server method)
1627 (error "Can't open server %s" (if (stringp method) method
1629 (unless (gnus-request-group group t method)
1630 (gnus-request-create-group group method))
1631 (setq mml-externalize-attachments
1632 (if (stringp gnus-gcc-externalize-attachments)
1633 (string-match gnus-gcc-externalize-attachments group)
1634 gnus-gcc-externalize-attachments))
1636 (nnheader-set-temp-buffer " *acc*")
1637 (setq message-options (with-current-buffer cur message-options))
1638 (insert-buffer-substring cur)
1639 (message-encode-message-body)
1641 (message-narrow-to-headers)
1642 (let* ((mail-parse-charset message-default-charset)
1643 (newsgroups-field (save-restriction
1644 (message-narrow-to-headers-or-head)
1645 (message-fetch-field "Newsgroups")))
1646 (followup-field (save-restriction
1647 (message-narrow-to-headers-or-head)
1648 (message-fetch-field "Followup-To")))
1649 ;; BUG: We really need to get the charset for
1650 ;; each name in the Newsgroups and Followup-To
1651 ;; lines to allow crossposting between group
1652 ;; names with incompatible character sets.
1653 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1654 (group-field-charset
1655 (gnus-group-name-charset
1656 method (or newsgroups-field "")))
1657 (followup-field-charset
1658 (gnus-group-name-charset
1659 method (or followup-field "")))
1660 (rfc2047-header-encoding-alist
1662 (when group-field-charset
1663 (list (cons "Newsgroups" group-field-charset)))
1664 (when followup-field-charset
1665 (list (cons "Followup-To" followup-field-charset)))
1666 rfc2047-header-encoding-alist)))
1667 (mail-encode-encoded-word-buffer)))
1668 (goto-char (point-min))
1669 (when (re-search-forward
1670 (concat "^" (regexp-quote mail-header-separator) "$")
1672 (replace-match "" t t ))
1673 (when (or (not (gnus-check-backend-function
1674 'request-accept-article group))
1675 (not (setq group-art
1676 (gnus-request-accept-article
1677 group method t t))))
1678 (gnus-message 1 "Couldn't store article in group %s: %s"
1679 group (gnus-status-message method)))
1680 (when (stringp method)
1681 (setq method (gnus-server-to-method method)))
1682 (when (and (listp method)
1683 (gnus-native-method-p method))
1684 (setq group (gnus-group-short-name group)))
1685 (when (and group-art
1686 ;; FIXME: Should gcc-mark-as-read work when
1687 ;; Gnus is not running?
1689 (if (or gnus-gcc-mark-as-read
1690 (and (boundp 'gnus-inews-mark-gcc-as-read)
1691 (symbol-value 'gnus-inews-mark-gcc-as-read)))
1692 (gnus-group-mark-article-read group (cdr group-art))
1693 (with-current-buffer gnus-group-buffer
1694 (let ((gnus-group-marked (list group))
1695 (gnus-get-new-news-hook nil)
1696 (inhibit-read-only t))
1697 (gnus-group-get-new-news-this-group nil t)))))
1698 (setq options message-options)
1699 (with-current-buffer cur (setq message-options options))
1700 (kill-buffer (current-buffer)))))))))
1702 (defun gnus-inews-insert-gcc (&optional group)
1703 "Insert the Gcc to say where the article is to be archived."
1704 (let* ((group (or group gnus-newsgroup-name))
1705 (group (when group (gnus-group-decoded-name group)))
1706 (var (or gnus-outgoing-message-group gnus-message-archive-group))
1708 (and group (gnus-group-find-parameter group 'gcc-self)))
1712 ((null gnus-message-archive-method)
1716 ;; Just a single group.
1719 ;; We don't want this.
1721 ((and (listp var) (stringp (car var)))
1722 ;; A list of groups.
1726 (funcall var group))
1728 ;; An alist of regexps/functions/forms.
1733 ((stringp (caar var))
1735 (when (string-match (caar var) group)
1737 ((functionp (car var))
1739 (funcall (car var) group))
1741 (eval (car var)))))))
1742 (setq var (cdr var)))
1745 (when (or groups gcc-self-val)
1746 (when (stringp groups)
1747 (setq groups (list groups)))
1750 (message-narrow-to-headers)
1751 (goto-char (point-max))
1754 ;; Use the `gcc-self' param value instead.
1757 (if (stringp gcc-self-val)
1758 (if (string-match " " gcc-self-val)
1759 (concat "\"" gcc-self-val "\"")
1761 ;; In nndoc groups, we use the parent group name
1762 ;; instead of the current group.
1763 (let ((group (or (gnus-group-find-parameter
1764 gnus-newsgroup-name 'parent-group)
1766 (if (string-match " " group)
1767 (concat "\"" group "\"")
1769 (if (not (eq gcc-self-val 'none))
1771 (gnus-delete-line)))
1772 ;; Use the list of groups.
1773 (while (setq name (pop groups))
1774 (let ((str (if (string-match ":" name)
1776 (gnus-group-prefixed-name
1777 name gnus-message-archive-method))))
1778 (insert (if (string-match " " str)
1779 (concat "\"" str "\"")
1785 (defun gnus-mailing-list-followup-to ()
1786 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1787 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1788 (list-post (gnus-fetch-original-field "list-post")))
1789 (when (and list-post
1790 (string-match "mailto:\\([^>]+\\)" list-post))
1791 (setq list-post (match-string 1 list-post)))
1797 (defun gnus-configure-posting-styles (&optional group-name)
1798 "Configure posting styles according to `gnus-posting-styles'."
1799 (unless gnus-inhibit-posting-styles
1800 (let ((group (or group-name gnus-newsgroup-name ""))
1801 (styles (if (gnus-buffer-live-p gnus-summary-buffer)
1802 (with-current-buffer gnus-summary-buffer
1803 gnus-posting-styles)
1804 gnus-posting-styles))
1805 style match attribute value v results
1806 filep name address element)
1807 ;; If the group has a posting-style parameter, add it at the end with a
1808 ;; regexp matching everything, to be sure it takes precedence over all
1810 (when gnus-newsgroup-name
1811 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1813 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1814 ;; Go through all styles and look for matches.
1815 (dolist (style styles)
1816 (setq match (pop style))
1817 (goto-char (point-min))
1820 ;; Regexp string match on the group name.
1821 (string-match match group))
1823 ;; Obsolete format of header match.
1824 (and (gnus-buffer-live-p gnus-article-copy)
1825 (with-current-buffer gnus-article-copy
1827 (nnheader-narrow-to-headers)
1828 (let ((header (message-fetch-field (pop style))))
1830 (string-match (pop style) header)))))))
1831 ((or (symbolp match)
1835 ;; Function to be called.
1838 ;; Variable to be checked.
1839 (symbol-value match))))
1842 ((eq (car match) 'header)
1843 ;; New format of header match.
1844 (and (gnus-buffer-live-p gnus-article-copy)
1845 (with-current-buffer gnus-article-copy
1847 (nnheader-narrow-to-headers)
1848 (let ((header (message-fetch-field (nth 1 match))))
1850 (string-match (nth 2 match) header)))))))
1852 ;; This is a form to be evalled.
1854 ;; We have a match, so we set the variables.
1855 (dolist (attribute style)
1856 (setq element (pop attribute)
1860 ((eq (car attribute) :file)
1863 ((eq (car attribute) :value)
1867 ;; We get the value.
1871 (if (and (stringp match)
1872 (gnus-string-match-p "\\\\[&[:digit:]]" value)
1873 (match-beginning 1))
1874 (gnus-match-substitute-replacement value nil nil group)
1876 ((or (symbolp value)
1878 (cond ((functionp value)
1881 (symbol-value value))))
1884 ;; Translate obsolescent value.
1886 ((eq element 'signature-file)
1887 (setq element 'signature
1889 ((eq element 'x-face-file)
1890 (setq element 'x-face
1892 ;; Post-processing for the signature posting-style:
1893 (and (eq element 'signature) filep
1894 message-signature-directory
1895 ;; don't actually use the signature directory
1896 ;; if message-signature-file contains a path.
1897 (not (file-name-directory v))
1898 (setq v (nnheader-concat message-signature-directory v)))
1899 ;; Get the contents of file elems.
1901 (setq v (with-temp-buffer
1902 (insert-file-contents v)
1906 (goto-char (point-max))
1907 (if (zerop (skip-chars-backward "\n"))
1910 (setq results (delq (assoc element results) results))
1911 (push (cons element v) results))))
1912 ;; Now we have all the styles, so we insert them.
1913 (setq name (assq 'name results)
1914 address (assq 'address results))
1915 (setq results (delq name (delq address results)))
1916 (gnus-make-local-hook 'message-setup-hook)
1917 (setq results (sort results (lambda (x y)
1918 (string-lessp (car x) (car y)))))
1919 (dolist (result results)
1920 (add-hook 'message-setup-hook
1922 ((eq 'eval (car result))
1924 ((eq 'body (car result))
1928 (insert ,(cdr result)))))
1929 ((eq 'signature (car result))
1930 (set (make-local-variable 'message-signature) nil)
1931 (set (make-local-variable 'message-signature-file) nil)
1932 (if (not (cdr result))
1936 (let ((message-signature ,(cdr result)))
1937 (when message-signature
1938 (message-insert-signature)))))))
1941 (if (symbolp (car result))
1942 (capitalize (symbol-name (car result)))
1946 (message-remove-header ,header)
1947 (let ((value ,(cdr result)))
1950 (insert ,header ": " value)
1952 (insert "\n")))))))))
1954 (when (or name address)
1955 (add-hook 'message-setup-hook
1957 (set (make-local-variable 'user-mail-address)
1958 ,(or (cdr address) user-mail-address))
1959 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1961 ,(or (cdr address) user-mail-address)))
1963 (message-remove-header "From")
1965 (insert "From: " (message-make-from) "\n"))))
1968 ;;; Allow redefinition of functions.
1974 ;;; gnus-msg.el ends here