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.
501 If Gnus isn't running, a plain `message-mail' setup is used
504 (if (not (gnus-alive-p))
506 (let ((buf (current-buffer))
508 (gnus-setup-message 'message
509 (message-mail to subject other-headers continue
510 nil yank-action send-actions return-action))
512 (setq mail-buf (current-buffer))
513 (switch-to-buffer buf)
514 (apply switch-action mail-buf nil))
515 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
519 (defun gnus-button-mailto (address)
521 (set-buffer (gnus-copy-article-buffer))
522 (gnus-setup-message 'message
523 (message-reply address)))
526 (defun gnus-button-reply (&optional to-address wide)
527 "Like `message-reply'."
529 (gnus-setup-message 'message
530 (message-reply to-address wide)))
533 (define-mail-user-agent 'gnus-user-agent
534 'gnus-msg-mail 'message-send-and-exit
535 'message-kill-buffer 'message-send-hook)
537 (defun gnus-setup-posting-charset (group)
538 (let ((alist gnus-group-posting-charset-alist)
539 (group (or group ""))
543 (while (setq elem (pop alist))
544 (when (or (and (stringp (car elem))
545 (string-match (car elem) group))
546 (and (functionp (car elem))
547 (funcall (car elem) group))
548 (and (symbolp (car elem))
549 (symbol-value (car elem))))
550 (throw 'found (cons (cadr elem) (caddr elem)))))))))
552 (defun gnus-inews-add-send-actions (winconf buffer article
553 &optional config yanked
555 (gnus-make-local-hook 'message-sent-hook)
556 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
557 'gnus-inews-do-gcc) nil t)
559 (gnus-make-local-hook 'message-header-hook)
560 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
561 (setq message-post-method
562 `(lambda (&optional arg)
563 (gnus-post-method arg ,gnus-newsgroup-name)))
566 (setq gnus-current-window-configuration ',winconf-name)
567 (when (gnus-buffer-exists-p ,buffer)
568 (set-window-configuration ,winconf)))
569 'exit 'postpone 'kill)
570 (let ((to-be-marked (cond
573 (lambda (x) (if (listp x) (car x) x)) yanked))
574 (article (if (listp article) article (list article)))
577 `(when (gnus-buffer-exists-p ,buffer)
578 (with-current-buffer ,buffer
580 (if (eq config 'forward)
581 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
582 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
585 (put 'gnus-setup-message 'lisp-indent-function 1)
586 (put 'gnus-setup-message 'edebug-form-spec '(form body))
588 ;;; Post news commands of Gnus group mode and summary mode
590 (defun gnus-group-mail (&optional arg)
591 "Start composing a mail.
592 If ARG, use the group under the point to find a posting style.
593 If ARG is 1, prompt for a group name to find the posting style."
595 ;; We can't `let' gnus-newsgroup-name here, since that leads
596 ;; to local variables leaking.
597 (let ((group gnus-newsgroup-name)
598 ;; make sure last viewed article doesn't affect posting styles:
600 (buffer (current-buffer)))
603 (setq gnus-newsgroup-name
605 (if (= 1 (prefix-numeric-value arg))
606 (gnus-group-completing-read
607 "Use posting style of group"
608 nil (gnus-read-active-file-p))
609 (gnus-group-group-name))
611 ;; #### see comment in gnus-setup-message -- drv
612 (gnus-setup-message 'message (message-mail)))
613 (with-current-buffer buffer
614 (setq gnus-newsgroup-name group)))))
616 (defun gnus-group-news (&optional arg)
617 "Start composing a news.
618 If ARG, post to group under point.
619 If ARG is 1, prompt for group name to post to.
621 This function prepares a news even when using mail groups. This is useful
622 for posting messages to mail groups without actually sending them over the
623 network. The corresponding back end must have a 'request-post method."
625 ;; We can't `let' gnus-newsgroup-name here, since that leads
626 ;; to local variables leaking.
627 (let ((group gnus-newsgroup-name)
628 ;; make sure last viewed article doesn't affect posting styles:
630 (buffer (current-buffer)))
633 (setq gnus-newsgroup-name
635 (if (= 1 (prefix-numeric-value arg))
636 (gnus-group-completing-read "Use group"
638 (gnus-read-active-file-p))
639 (gnus-group-group-name))
641 ;; #### see comment in gnus-setup-message -- drv
642 (gnus-setup-message 'message
643 (message-news (gnus-group-real-name gnus-newsgroup-name))))
644 (with-current-buffer buffer
645 (setq gnus-newsgroup-name group)))))
647 (defun gnus-group-post-news (&optional arg)
648 "Start composing a message (a news by default).
649 If ARG, post to group under point. If ARG is 1, prompt for group name.
650 Depending on the selected group, the message might be either a mail or
653 ;; Bind this variable here to make message mode hooks work ok.
654 (let ((gnus-newsgroup-name
656 (if (= 1 (prefix-numeric-value arg))
657 (gnus-group-completing-read "Newsgroup" nil
658 (gnus-read-active-file-p))
659 (or (gnus-group-group-name) ""))
661 ;; make sure last viewed article doesn't affect posting styles:
663 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
664 (string= gnus-newsgroup-name ""))))
666 (defun gnus-summary-mail-other-window (&optional arg)
667 "Start composing a mail in another window.
668 Use the posting of the current group by default.
669 If ARG, don't do that. If ARG is 1, prompt for group name to find the
672 ;; We can't `let' gnus-newsgroup-name here, since that leads
673 ;; to local variables leaking.
674 (let ((group gnus-newsgroup-name)
675 ;; make sure last viewed article doesn't affect posting styles:
677 (buffer (current-buffer)))
680 (setq gnus-newsgroup-name
682 (if (= 1 (prefix-numeric-value arg))
683 (gnus-group-completing-read "Use group"
685 (gnus-read-active-file-p))
687 gnus-newsgroup-name))
688 ;; #### see comment in gnus-setup-message -- drv
689 (gnus-setup-message 'message (message-mail)))
690 (with-current-buffer buffer
691 (setq gnus-newsgroup-name group)))))
693 (defun gnus-summary-news-other-window (&optional arg)
694 "Start composing a news in another window.
695 Post to the current group by default.
696 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
698 This function prepares a news even when using mail groups. This is useful
699 for posting messages to mail groups without actually sending them over the
700 network. The corresponding back end must have a 'request-post method."
702 ;; We can't `let' gnus-newsgroup-name here, since that leads
703 ;; to local variables leaking.
704 (let ((group gnus-newsgroup-name)
705 ;; make sure last viewed article doesn't affect posting styles:
707 (buffer (current-buffer)))
710 (setq gnus-newsgroup-name
712 (if (= 1 (prefix-numeric-value arg))
713 (gnus-group-completing-read "Use group"
715 (gnus-read-active-file-p))
717 gnus-newsgroup-name))
718 ;; #### see comment in gnus-setup-message -- drv
719 (gnus-setup-message 'message
721 (message-news (gnus-group-real-name gnus-newsgroup-name))
722 (set (make-local-variable 'gnus-discouraged-post-methods)
724 (car (gnus-find-method-for-group gnus-newsgroup-name))
725 gnus-discouraged-post-methods)))))
726 (with-current-buffer buffer
727 (setq gnus-newsgroup-name group)))))
729 (defun gnus-summary-post-news (&optional arg)
730 "Start composing a message. Post to the current group by default.
731 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
732 Depending on the selected group, the message might be either a mail or
735 ;; Bind this variable here to make message mode hooks work ok.
736 (let ((gnus-newsgroup-name
738 (if (= 1 (prefix-numeric-value arg))
739 (gnus-group-completing-read "Newsgroup" nil
740 (gnus-read-active-file-p))
742 gnus-newsgroup-name))
743 ;; make sure last viewed article doesn't affect posting styles:
745 (gnus-post-news 'post gnus-newsgroup-name)))
748 (defun gnus-summary-followup (yank &optional force-news)
749 "Compose a followup to an article.
750 If prefix argument YANK is non-nil, the original article is yanked
752 YANK is a list of elements, where the car of each element is the
753 article number, and the cdr is the string to be yanked."
755 (list (and current-prefix-arg
756 (gnus-summary-work-articles 1))))
758 (gnus-summary-goto-subject
759 (if (listp (car yank))
762 (save-window-excursion
763 (gnus-summary-select-article))
764 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
765 (gnus-newsgroup-name gnus-newsgroup-name))
767 (gnus-post-news nil gnus-newsgroup-name
768 headers gnus-article-buffer
770 (gnus-summary-handle-replysign)))
772 (defun gnus-summary-followup-with-original (n &optional force-news)
773 "Compose a followup to an article and include the original article.
774 The text in the region will be yanked. If the region isn't
775 active, the entire article will be yanked."
777 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
779 (defun gnus-summary-followup-to-mail (&optional arg)
780 "Followup to the current mail message via news."
782 (list (and current-prefix-arg
783 (gnus-summary-work-articles 1))))
784 (gnus-summary-followup arg t))
786 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
787 "Followup to the current mail message via news."
789 (gnus-summary-followup (gnus-summary-work-articles arg) t))
791 (defun gnus-inews-yank-articles (articles)
792 (let (beg article yank-string)
794 (while (setq article (pop articles))
795 (when (listp article)
796 (setq yank-string (nth 1 article)
797 article (nth 0 article)))
798 (save-window-excursion
799 (set-buffer gnus-summary-buffer)
800 (gnus-summary-select-article nil nil nil article)
801 (gnus-summary-remove-process-mark article))
802 (gnus-copy-article-buffer nil yank-string)
803 (let ((message-reply-buffer gnus-article-copy)
804 (message-reply-headers
805 ;; The headers are decoded.
806 (with-current-buffer gnus-article-copy
808 (nnheader-narrow-to-headers)
809 (nnheader-parse-naked-head)))))
810 (message-yank-original)
811 (message-exchange-point-and-mark)
812 (setq beg (or beg (mark t))))
818 (defun gnus-summary-cancel-article (&optional n symp)
819 "Cancel an article you posted.
820 Uses the process-prefix convention. If given the symbolic
821 prefix `a', cancel using the standard posting method; if not
822 post using the current select method."
823 (interactive (gnus-interactive "P\ny"))
824 (let ((message-post-method
826 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
827 (dolist (article (gnus-summary-work-articles n))
828 (when (gnus-summary-select-article t nil nil article)
829 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
830 (message-cancel-news))
831 (gnus-summary-mark-as-read article gnus-canceled-mark)
832 (gnus-cache-remove-article 1))
833 (gnus-article-hide-headers-if-wanted))
834 (gnus-summary-remove-process-mark article))))
836 (defun gnus-summary-supersede-article ()
837 "Compose an article that will supersede a previous article.
838 This is done simply by taking the old article and adding a Supersedes
839 header line with the old Message-ID."
841 (let ((article (gnus-summary-article-number))
842 (mail-parse-charset gnus-newsgroup-charset))
843 (gnus-setup-message 'reply-yank
844 (gnus-summary-select-article t)
845 (set-buffer gnus-original-article-buffer)
849 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
850 (with-current-buffer ,gnus-summary-buffer
851 (gnus-cache-possibly-remove-article ,article nil nil nil t)
852 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
853 message-send-actions)
855 (gnus-inews-insert-gcc))))
859 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
860 ;; make a copy of the article buffer with all text properties removed
861 ;; this copy is in the buffer gnus-article-copy.
862 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
863 ;; this buffer should be passed to all mail/news reply/post routines.
864 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
865 (with-current-buffer gnus-article-copy
866 (mm-enable-multibyte))
867 (let ((article-buffer (or article-buffer gnus-article-buffer))
869 (if (not (and (get-buffer article-buffer)
870 (gnus-buffer-exists-p article-buffer)))
871 (error "Can't find any article buffer")
872 (with-current-buffer article-buffer
873 (let ((gnus-newsgroup-charset (or gnus-article-charset
874 gnus-newsgroup-charset))
875 (gnus-newsgroup-ignored-charsets
876 (or gnus-article-ignored-charsets
877 gnus-newsgroup-ignored-charsets)))
879 ;; Copy over the (displayed) article buffer, delete
880 ;; hidden text and remove text properties.
882 (copy-to-buffer gnus-article-copy (point-min) (point-max))
883 (set-buffer gnus-article-copy)
886 (delete-region (point) (point-max))
887 (insert yank-string))
888 (gnus-article-delete-text-of-type 'annotation)
889 (gnus-article-delete-text-of-type 'multipart)
890 (gnus-remove-text-with-property 'gnus-prev)
891 (gnus-remove-text-with-property 'gnus-next)
892 (gnus-remove-text-with-property 'gnus-decoration)
895 (buffer-substring-no-properties (point-min) (point-max))
897 ;; Find the original headers.
898 (set-buffer gnus-original-article-buffer)
899 (goto-char (point-min))
900 (while (looking-at message-unix-mail-delimiter)
902 (let ((mail-header-separator ""))
904 end (or (message-goto-body)
905 ;; There may be just a header.
907 ;; Delete the headers from the displayed articles.
908 (set-buffer gnus-article-copy)
909 (let ((mail-header-separator ""))
910 (delete-region (goto-char (point-min))
911 (or (message-goto-body) (point-max))))
912 ;; Insert the original article headers.
913 (insert-buffer-substring gnus-original-article-buffer beg end)
915 (let ((gnus-article-decode-hook
916 (delq 'article-decode-charset
917 (copy-sequence gnus-article-decode-hook)))
918 (rfc2047-quote-decoded-words-containing-tspecials t))
919 (run-hooks 'gnus-article-decode-hook)))))
922 (defun gnus-post-news (post &optional group header article-buffer yank subject
925 (gnus-copy-article-buffer))
926 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
927 (gnus-article-yanked-articles yank)
928 (add-to-list gnus-add-to-list))
929 (gnus-setup-message (cond (yank 'reply-yank)
930 (article-buffer 'reply)
932 (let* ((group (or group gnus-newsgroup-name))
933 (charset (gnus-group-name-charset nil group))
935 to-address to-group mailing-list to-list
938 (setq to-address (gnus-parameter-to-address group)
939 to-group (gnus-group-find-parameter group 'to-group)
940 to-list (gnus-parameter-to-list group)
941 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
942 mailing-list (when gnus-mailing-list-groups
943 (string-match gnus-mailing-list-groups group))
944 group (gnus-group-name-decode (gnus-group-real-name group)
946 (if (or (and to-group
947 (gnus-news-group-p to-group))
950 (and (gnus-news-group-p
951 (or pgroup gnus-newsgroup-name)
952 (or header gnus-current-article))
960 (and (not (gnus-virtual-group-p pgroup)) group)))
961 (set-buffer gnus-article-copy)
962 (gnus-msg-treat-broken-reply-to)
963 (message-followup (if (or newsgroup-p force-news)
964 (if (save-restriction
965 (article-narrow-to-head)
966 (message-fetch-field "newsgroups"))
973 (message-mail (or to-address to-list))
974 ;; Arrange for mail groups that have no `to-address' to
975 ;; get that when the user sends off the mail.
976 (when (and (not to-list)
979 (push (list 'gnus-inews-add-to-address pgroup)
980 message-send-actions)))
981 (set-buffer gnus-article-copy)
982 (gnus-msg-treat-broken-reply-to)
983 (message-wide-reply to-address)))
985 (gnus-inews-yank-articles yank))))))
987 (defun gnus-msg-treat-broken-reply-to (&optional force)
988 "Remove the Reply-to header if broken-reply-to."
990 (gnus-group-find-parameter
991 gnus-newsgroup-name 'broken-reply-to))
993 (message-narrow-to-head)
994 (message-remove-header "reply-to"))))
996 (defun gnus-post-method (arg group &optional silent)
997 "Return the posting method based on GROUP and ARG.
998 If SILENT, don't prompt the user."
999 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1001 (group-method (gnus-find-method-for-group group)))
1003 ;; If the group-method is nil (which shouldn't happen) we use
1004 ;; the default method.
1005 ((null group-method)
1006 (or (and (listp gnus-post-method) ;If not current/native/nil
1007 (not (listp (car gnus-post-method))) ; and not a list of methods
1008 gnus-post-method) ;then use it.
1010 message-post-method))
1011 ;; We want the inverse of the default
1012 ((and arg (not (eq arg 0)))
1013 (if (eq gnus-post-method 'current)
1016 ;; We query the user for a post method.
1018 (and (listp gnus-post-method)
1019 (listp (car gnus-post-method))))
1021 ;; Collect all methods we know about.
1023 (when (listp gnus-post-method)
1024 (if (listp (car gnus-post-method))
1026 (list gnus-post-method)))
1027 gnus-secondary-select-methods
1028 (mapcar 'cdr gnus-server-alist)
1029 (mapcar 'car gnus-opened-servers)
1030 (list gnus-select-method)
1031 (list group-method)))
1032 method-alist post-methods method)
1033 ;; Weed out all mail methods.
1035 (setq method (gnus-server-get-method "" (pop methods)))
1036 (when (and (or (gnus-method-option-p method 'post)
1037 (gnus-method-option-p method 'post-mail))
1038 (not (member method post-methods)))
1039 (push method post-methods)))
1040 ;; Create a name-method alist.
1044 (if (equal (cadr m) "")
1045 (list (symbol-name (car m)) m)
1046 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1051 (setq gnus-last-posting-server
1053 gnus-last-posting-server)
1054 ;; Just use the last value.
1055 gnus-last-posting-server
1056 (gnus-completing-read
1057 "Posting method" (mapcar 'car method-alist) t
1058 (cons (or gnus-last-posting-server "") 0))))
1060 ;; Override normal method.
1061 ((and (eq gnus-post-method 'current)
1062 (not (memq (car group-method) gnus-discouraged-post-methods))
1063 (gnus-get-function group-method 'request-post t))
1066 ;; Use gnus-post-method.
1067 ((listp gnus-post-method) ;A method...
1068 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1070 ;; Use the normal select method (nil or native).
1071 (t gnus-select-method))))
1075 (defun gnus-extended-version ()
1076 "Stringified Gnus version and Emacs version.
1077 See the variable `gnus-user-agent'."
1079 (if (stringp gnus-user-agent)
1081 ;; `gnus-user-agent' is a list:
1082 (let* ((float-output-format nil)
1084 (when (memq 'gnus gnus-user-agent)
1086 (prin1-to-string (gnus-continuum-version gnus-version) t)
1087 " (" gnus-version ")")))
1088 (emacs-v (gnus-emacs-version)))
1089 (concat gnus-v (when (and gnus-v emacs-v) " ")
1094 ;;; Gnus Mail Functions
1097 ;;; Mail reply commands of Gnus summary mode
1099 (defun gnus-summary-reply (&optional yank wide very-wide)
1100 "Start composing a mail reply to the current message.
1101 If prefix argument YANK is non-nil, the original article is yanked
1103 If WIDE, make a wide reply.
1104 If VERY-WIDE, make a very wide reply."
1106 (list (and current-prefix-arg
1107 (gnus-summary-work-articles 1))))
1108 ;; Allow user to require confirmation before replying by mail to the
1109 ;; author of a news article (or mail message).
1110 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1111 gnus-confirm-treat-mail-like-news))
1112 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1113 (string-match gnus-confirm-mail-reply-to-news
1114 gnus-newsgroup-name))
1115 ((functionp gnus-confirm-mail-reply-to-news)
1116 (funcall gnus-confirm-mail-reply-to-news
1117 gnus-newsgroup-name))
1118 (t gnus-confirm-mail-reply-to-news)))
1119 (if (or wide very-wide)
1120 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1122 (y-or-n-p "Really reply by mail to article author? ")))
1124 (if (listp (car yank))
1127 (gnus-article-reply (or article (gnus-summary-article-number)))
1128 (gnus-article-yanked-articles yank)
1130 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1132 (gnus-summary-goto-subject article))
1133 (gnus-setup-message (if yank 'reply-yank 'reply)
1135 (gnus-summary-select-article)
1136 (dolist (article very-wide)
1137 (gnus-summary-select-article nil nil nil article)
1138 (with-current-buffer (gnus-copy-article-buffer)
1139 (gnus-msg-treat-broken-reply-to)
1141 (message-narrow-to-head)
1142 (setq headers (concat headers (buffer-string)))))))
1143 (set-buffer (gnus-copy-article-buffer))
1144 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1146 (message-narrow-to-head)
1150 (goto-char (point-max)))
1151 (mml-quote-region (point) (point-max))
1152 (message-reply nil wide)
1154 (gnus-inews-yank-articles yank))
1155 (gnus-summary-handle-replysign)))))
1157 (defun gnus-summary-handle-replysign ()
1158 "Check the various replysign variables and take action accordingly."
1159 (when (or gnus-message-replysign gnus-message-replyencrypt)
1160 (let (signed encrypted)
1161 (with-current-buffer gnus-article-buffer
1162 (setq signed (memq 'signed gnus-article-wash-types))
1163 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1164 (cond ((and gnus-message-replyencrypt encrypted)
1165 (mml-secure-message mml-default-encrypt-method
1166 (if gnus-message-replysignencrypted
1169 ((and gnus-message-replysign signed)
1170 (mml-secure-message mml-default-sign-method 'sign))))))
1172 (defun gnus-summary-reply-with-original (n &optional wide)
1173 "Start composing a reply mail to the current message.
1174 The original article will be yanked."
1176 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1178 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1179 "Start composing a reply mail to the current message.
1180 The reply goes only to the mailing list.
1181 The original article will be yanked."
1183 (let ((message-reply-to-function
1185 `((To . ,(gnus-mailing-list-followup-to))))))
1186 (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1188 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1189 "Like `gnus-summary-reply' except removing reply-to field.
1190 If prefix argument YANK is non-nil, the original article is yanked
1192 If WIDE, make a wide reply.
1193 If VERY-WIDE, make a very wide reply."
1195 (list (and current-prefix-arg
1196 (gnus-summary-work-articles 1))))
1197 (let ((gnus-msg-force-broken-reply-to t))
1198 (gnus-summary-reply yank wide very-wide)))
1200 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1201 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1202 The original article will be yanked."
1204 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1206 (defun gnus-summary-wide-reply (&optional yank)
1207 "Start composing a wide reply mail to the current message.
1208 If prefix argument YANK is non-nil, the original article is yanked
1211 (list (and current-prefix-arg
1212 (gnus-summary-work-articles 1))))
1213 (gnus-summary-reply yank t))
1215 (defun gnus-summary-wide-reply-with-original (n)
1216 "Start composing a wide reply mail to the current message.
1217 The original article will be yanked.
1218 Uses the process/prefix convention."
1220 (gnus-summary-reply-with-original n t))
1222 (defun gnus-summary-very-wide-reply (&optional yank)
1223 "Start composing a very wide reply mail to the current message.
1224 If prefix argument YANK is non-nil, the original article is yanked
1227 (list (and current-prefix-arg
1228 (gnus-summary-work-articles 1))))
1229 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1231 (defun gnus-summary-very-wide-reply-with-original (n)
1232 "Start composing a very wide reply mail to the current message.
1233 The original article will be yanked."
1236 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1238 (defun gnus-summary-mail-forward (&optional arg post)
1239 "Forward the current message(s) to another user.
1240 If process marks exist, forward all marked messages;
1241 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1242 if ARG is 1, decode the message and forward directly inline;
1243 if ARG is 2, forward message as an rfc822 MIME section;
1244 if ARG is 3, decode message and forward as an rfc822 MIME section;
1245 if ARG is 4, forward message directly inline;
1246 otherwise, use flipped `message-forward-as-mime'.
1247 If POST, post instead of mail.
1248 For the \"inline\" alternatives, also see the variable
1249 `message-forward-ignored-headers'."
1251 (if (cdr (gnus-summary-work-articles nil))
1252 ;; Process marks are given.
1253 (gnus-uu-digest-mail-forward nil post)
1254 ;; No process marks.
1255 (let ((message-forward-as-mime message-forward-as-mime)
1256 (message-forward-show-mml message-forward-show-mml))
1260 (setq message-forward-as-mime nil
1261 message-forward-show-mml t))
1263 (setq message-forward-as-mime t
1264 message-forward-show-mml nil))
1266 (setq message-forward-as-mime t
1267 message-forward-show-mml t))
1269 (setq message-forward-as-mime nil
1270 message-forward-show-mml nil))
1272 (setq message-forward-as-mime (not message-forward-as-mime))))
1273 (let* ((gnus-article-reply (gnus-summary-article-number))
1274 (gnus-article-yanked-articles (list gnus-article-reply)))
1275 (gnus-setup-message 'forward
1276 (gnus-summary-select-article)
1277 (let ((mail-parse-charset
1278 (or (and (gnus-buffer-live-p gnus-article-buffer)
1279 (with-current-buffer gnus-article-buffer
1280 gnus-article-charset))
1281 gnus-newsgroup-charset))
1282 (mail-parse-ignored-charsets
1283 gnus-newsgroup-ignored-charsets))
1284 (set-buffer gnus-original-article-buffer)
1285 (message-forward post)))))))
1287 (defun gnus-summary-resend-message-insert-gcc ()
1288 "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1289 (gnus-inews-insert-gcc)
1292 (mm-encode-coding-string
1294 (gnus-group-name-charset (gnus-inews-group-method group)
1296 (message-unquote-tokens
1297 (message-tokenize-header (mail-fetch-field "gcc" nil t)
1299 (message-remove-header "gcc")
1301 (goto-char (point-max))
1302 (cond ((eq gnus-gcc-self-resent-messages 'none))
1303 ((eq gnus-gcc-self-resent-messages t)
1304 (insert "Gcc: \"" gnus-newsgroup-name "\"\n"))
1305 ((stringp gnus-gcc-self-resent-messages)
1307 (mm-encode-coding-string
1308 (if (string-match " " gnus-gcc-self-resent-messages)
1309 (concat "\"" gnus-gcc-self-resent-messages "\"")
1310 gnus-gcc-self-resent-messages)
1311 (gnus-group-name-charset
1312 (gnus-inews-group-method gnus-gcc-self-resent-messages)
1313 gnus-gcc-self-resent-messages))
1315 ((null gnus-gcc-self-resent-messages)
1316 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n"))
1317 ((eq gnus-gcc-self-resent-messages 'no-gcc-self)
1318 (when (setq gcc (delete
1320 (delete (concat "\"" gnus-newsgroup-name "\"")
1322 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n")))))))
1324 (defun gnus-summary-resend-message (address n)
1325 "Resend the current article to ADDRESS."
1327 (list (message-read-from-minibuffer
1328 "Resend message(s) to: "
1329 (when (and gnus-summary-resend-default-address
1330 (gnus-buffer-live-p gnus-original-article-buffer))
1331 ;; If some other article is currently selected, the
1332 ;; initial-contents is wrong. Whatever, it is just the
1333 ;; initial-contents.
1334 (with-current-buffer gnus-original-article-buffer
1335 (nnmail-fetch-field "to"))))
1336 current-prefix-arg))
1337 (let ((message-header-setup-hook (copy-sequence message-header-setup-hook))
1338 (message-sent-hook (copy-sequence message-sent-hook)))
1339 ;; `gnus-summary-resend-message-insert-gcc' must run last.
1340 (add-hook 'message-header-setup-hook
1341 'gnus-summary-resend-message-insert-gcc t)
1342 (add-hook 'message-sent-hook (if gnus-agent
1343 'gnus-agent-possibly-do-gcc
1344 'gnus-inews-do-gcc))
1345 (dolist (article (gnus-summary-work-articles n))
1346 (gnus-summary-select-article nil nil nil article)
1347 (with-current-buffer gnus-original-article-buffer
1348 (let ((gnus-gcc-externalize-attachments nil)
1349 (message-inhibit-body-encoding t))
1350 (message-resend address)))
1351 (gnus-summary-mark-article-as-forwarded article))))
1353 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1354 (defun gnus-summary-resend-message-edit ()
1355 "Resend an article that has already been sent.
1356 A new buffer will be created to allow the user to modify body and
1357 contents of the message, and then, everything will happen as when
1358 composing a new message."
1360 (let ((mail-parse-charset gnus-newsgroup-charset))
1361 (gnus-setup-message 'reply-yank
1362 (gnus-summary-select-article t)
1363 (set-buffer gnus-original-article-buffer)
1364 (let ((cur (current-buffer))
1365 (to (message-fetch-field "to")))
1366 ;; Get a normal message buffer.
1367 (message-pop-to-buffer (message-buffer-name "Resend" to))
1368 (insert-buffer-substring cur)
1370 (message-narrow-to-head-1)
1371 ;; Gnus will generate a new one when sending.
1372 (message-remove-header "Message-ID")
1373 ;; Remove unwanted headers.
1374 (message-remove-header message-ignored-resent-headers t)
1375 (goto-char (point-max))
1376 (insert mail-header-separator)
1378 (gnus-inews-insert-gcc)
1379 (goto-char (point-min))
1380 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1384 (defun gnus-summary-post-forward (&optional arg)
1385 "Forward the current article to a newsgroup.
1386 See `gnus-summary-mail-forward' for ARG."
1388 (gnus-summary-mail-forward arg t))
1390 (defun gnus-summary-mail-crosspost-complaint (n)
1391 "Send a complaint about crossposting to the current article(s)."
1393 (dolist (article (gnus-summary-work-articles n))
1394 (set-buffer gnus-summary-buffer)
1395 (gnus-summary-goto-subject article)
1396 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1397 newsgroups followup-to)
1398 (gnus-summary-select-article)
1399 (set-buffer gnus-original-article-buffer)
1400 (if (and (<= (length (message-tokenize-header
1402 (mail-fetch-field "newsgroups"))
1405 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1406 (not (member group (message-tokenize-header
1407 followup-to ", ")))))
1409 (gnus-message 1 "Followup-to restricted")
1410 (gnus-message 1 "Not a crossposted article"))
1411 (set-buffer gnus-summary-buffer)
1412 (gnus-summary-reply-with-original 1)
1413 (set-buffer gnus-message-buffer)
1415 (insert (format gnus-crosspost-complaint newsgroups group))
1416 (message-goto-subject)
1417 (re-search-forward " *$")
1418 (replace-match " (crosspost notification)" t t)
1419 (gnus-deactivate-mark)
1420 (when (gnus-y-or-n-p "Send this complaint? ")
1421 (message-send-and-exit))))))
1423 (defun gnus-mail-parse-comma-list ()
1426 (skip-chars-forward " ")
1429 (skip-chars-forward "^,")
1434 (narrow-to-region beg (point))
1437 (while (search-forward "\"" nil t)
1441 (skip-chars-forward ",")
1442 (skip-chars-forward "^,"))
1443 (skip-chars-backward " ")
1444 (push (buffer-substring beg (point))
1446 (skip-chars-forward "^,")
1447 (skip-chars-forward ", "))
1450 (defun gnus-inews-add-to-address (group)
1451 (let ((to-address (mail-fetch-field "to")))
1452 (when (and to-address
1454 ;; This mail group doesn't have a `to-list', so we add one
1456 (when (gnus-y-or-n-p
1457 (format "Do you want to add this as `to-list': %s? " to-address))
1458 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1460 (defun gnus-put-message ()
1461 "Put the current message in some group and return to Gnus."
1463 (let ((reply gnus-article-reply)
1464 (winconf gnus-prev-winconf)
1465 (group gnus-newsgroup-name))
1467 (not (gnus-group-read-only-p group)))
1468 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1470 (when (gnus-group-entry group)
1471 (error "No such group: %s" group))
1475 (message-narrow-to-headers)
1476 (let ((gnus-deletable-headers nil))
1477 (message-generate-headers
1478 (if (message-news-p)
1479 message-required-news-headers
1480 message-required-mail-headers)))
1481 (goto-char (point-max))
1482 (if (string-match " " group)
1483 (insert "Gcc: \"" group "\"\n")
1484 (insert "Gcc: " group "\n"))
1487 (when (and (get-buffer gnus-group-buffer)
1488 (gnus-buffer-exists-p (car-safe reply))
1490 (set-buffer (car reply))
1491 (gnus-summary-mark-article-as-replied (cdr reply)))
1493 (set-window-configuration winconf))))
1495 (defun gnus-article-mail (yank)
1496 "Send a reply to the address near point.
1497 If YANK is non-nil, include the original article."
1501 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1502 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1504 (gnus-msg-mail address)
1506 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1508 (defvar nntp-server-type)
1510 "Send a bug report to the Gnus maintainers."
1512 (unless (gnus-alive-p)
1513 (error "Gnus has been shut down"))
1514 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1515 (unless (message-mail-user-agent)
1516 (delete-other-windows)
1517 (when gnus-bug-create-help-buffer
1518 (switch-to-buffer "*Gnus Help Bug*")
1520 (insert gnus-bug-message)
1521 (goto-char (point-min)))
1522 (message-pop-to-buffer "*Gnus Bug*"))
1523 (let ((message-this-is-mail t))
1524 (message-setup `((To . ,gnus-maintainer)
1527 . ,(format "%s" gnus-bug-package))
1529 . ,(format "%s" (gnus-continuum-version))))))
1530 (when gnus-bug-create-help-buffer
1531 (push `(gnus-bug-kill-buffer) message-send-actions))
1532 (goto-char (point-min))
1534 (insert "\n\n\n\n\n")
1535 (insert (gnus-version) "\n"
1536 (emacs-version) "\n")
1537 (when (and (boundp 'nntp-server-type)
1538 (stringp nntp-server-type))
1539 (insert nntp-server-type))
1540 (goto-char (point-min))
1541 (search-forward "Subject: " nil t)
1544 (defun gnus-bug-kill-buffer ()
1545 (when (get-buffer "*Gnus Help Bug*")
1546 (kill-buffer "*Gnus Help Bug*")))
1548 (defun gnus-summary-yank-message (buffer n)
1549 "Yank the current article into a composed message."
1551 (list (gnus-completing-read "Buffer" (message-buffers) t)
1552 current-prefix-arg))
1553 (gnus-summary-iterate n
1554 (let ((gnus-inhibit-treatment t))
1555 (gnus-summary-select-article))
1556 (with-current-buffer buffer
1557 (message-yank-buffer gnus-article-buffer))))
1559 ;;; Treatment of rejected articles.
1562 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1563 "Re-mail the current message.
1564 This only makes sense if the current message is a bounce message that
1565 contains some mail you have written which has been bounced back to
1567 If FETCH, try to fetch the article that this is a reply to, if indeed
1570 (gnus-summary-select-article t)
1571 (let (summary-buffer parent)
1574 (setq summary-buffer (current-buffer))
1575 (set-buffer gnus-original-article-buffer)
1577 (when (re-search-forward "^References:\n?" nil t)
1578 (while (memq (char-after) '(?\t ? ))
1580 (skip-chars-backward "\t\n ")
1582 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1583 (set-buffer gnus-original-article-buffer))
1584 (gnus-setup-message 'compose-bounce
1587 (gnus-inews-insert-gcc)
1588 ;; If there are references, we fetch the article we answered to.
1590 (with-current-buffer summary-buffer
1591 (gnus-summary-refer-article parent)
1592 (gnus-summary-show-all-headers))))))
1596 (defun gnus-inews-group-method (group)
1598 ;; If the group doesn't exist, we assume
1599 ;; it's an archive group...
1600 ((and (null (gnus-get-info group))
1601 (eq (car (gnus-server-to-method gnus-message-archive-method))
1602 (car (gnus-server-to-method (gnus-group-method group)))))
1603 gnus-message-archive-method)
1605 ((gnus-info-method (gnus-get-info group))
1606 (gnus-info-method (gnus-get-info group)))
1608 (t (gnus-server-to-method (gnus-group-method group)))))
1610 ;; Do Gcc handling, which copied the message over to some group.
1611 (defun gnus-inews-do-gcc (&optional gcc)
1615 (message-narrow-to-headers)
1616 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1617 (cur (current-buffer))
1618 groups group method group-art options
1619 mml-externalize-attachments)
1621 (message-remove-header "gcc")
1623 (setq groups (message-unquote-tokens
1624 (message-tokenize-header gcc " ,")))
1625 ;; Copy the article over to some group(s).
1626 (while (setq group (pop groups))
1627 (setq method (gnus-inews-group-method group)
1628 group (mm-encode-coding-string
1630 (gnus-group-name-charset method group)))
1631 (unless (gnus-check-server method)
1632 (error "Can't open server %s" (if (stringp method) method
1634 (unless (gnus-request-group group t method)
1635 (gnus-request-create-group group method))
1636 (setq mml-externalize-attachments
1637 (if (stringp gnus-gcc-externalize-attachments)
1638 (string-match gnus-gcc-externalize-attachments group)
1639 gnus-gcc-externalize-attachments))
1641 (nnheader-set-temp-buffer " *acc*")
1642 (setq message-options (with-current-buffer cur message-options))
1643 (insert-buffer-substring cur)
1644 (message-encode-message-body)
1646 (message-narrow-to-headers)
1647 (let* ((mail-parse-charset message-default-charset)
1648 (newsgroups-field (save-restriction
1649 (message-narrow-to-headers-or-head)
1650 (message-fetch-field "Newsgroups")))
1651 (followup-field (save-restriction
1652 (message-narrow-to-headers-or-head)
1653 (message-fetch-field "Followup-To")))
1654 ;; BUG: We really need to get the charset for
1655 ;; each name in the Newsgroups and Followup-To
1656 ;; lines to allow crossposting between group
1657 ;; names with incompatible character sets.
1658 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1659 (group-field-charset
1660 (gnus-group-name-charset
1661 method (or newsgroups-field "")))
1662 (followup-field-charset
1663 (gnus-group-name-charset
1664 method (or followup-field "")))
1665 (rfc2047-header-encoding-alist
1667 (when group-field-charset
1668 (list (cons "Newsgroups" group-field-charset)))
1669 (when followup-field-charset
1670 (list (cons "Followup-To" followup-field-charset)))
1671 rfc2047-header-encoding-alist)))
1672 (mail-encode-encoded-word-buffer)))
1673 (goto-char (point-min))
1674 (when (re-search-forward
1675 (concat "^" (regexp-quote mail-header-separator) "$")
1677 (replace-match "" t t ))
1678 (when (or (not (gnus-check-backend-function
1679 'request-accept-article group))
1680 (not (setq group-art
1681 (gnus-request-accept-article
1682 group method t t))))
1683 (gnus-message 1 "Couldn't store article in group %s: %s"
1684 group (gnus-status-message method)))
1685 (when (stringp method)
1686 (setq method (gnus-server-to-method method)))
1687 (when (and (listp method)
1688 (gnus-native-method-p method))
1689 (setq group (gnus-group-short-name group)))
1690 (when (and group-art
1691 ;; FIXME: Should gcc-mark-as-read work when
1692 ;; Gnus is not running?
1694 (if (or gnus-gcc-mark-as-read
1695 (and (boundp 'gnus-inews-mark-gcc-as-read)
1696 (symbol-value 'gnus-inews-mark-gcc-as-read)))
1697 (gnus-group-mark-article-read group (cdr group-art))
1698 (with-current-buffer gnus-group-buffer
1699 (let ((gnus-group-marked (list group))
1700 (gnus-get-new-news-hook nil)
1701 (inhibit-read-only t))
1702 (gnus-group-get-new-news-this-group nil t)))))
1703 (setq options message-options)
1704 (with-current-buffer cur (setq message-options options))
1705 (kill-buffer (current-buffer)))))))))
1707 (defun gnus-inews-insert-gcc (&optional group)
1708 "Insert the Gcc to say where the article is to be archived."
1709 (let* ((group (or group gnus-newsgroup-name))
1710 (group (when group (gnus-group-decoded-name group)))
1711 (var (or gnus-outgoing-message-group gnus-message-archive-group))
1713 (and group (gnus-group-find-parameter group 'gcc-self)))
1717 ((null gnus-message-archive-method)
1721 ;; Just a single group.
1724 ;; We don't want this.
1726 ((and (listp var) (stringp (car var)))
1727 ;; A list of groups.
1731 (funcall var group))
1733 ;; An alist of regexps/functions/forms.
1738 ((stringp (caar var))
1740 (when (string-match (caar var) group)
1742 ((functionp (car var))
1744 (funcall (car var) group))
1746 (eval (car var)))))))
1747 (setq var (cdr var)))
1750 (when (or groups gcc-self-val)
1751 (when (stringp groups)
1752 (setq groups (list groups)))
1755 (message-narrow-to-headers)
1756 (goto-char (point-max))
1759 ;; Use the `gcc-self' param value instead.
1762 (if (stringp gcc-self-val)
1763 (if (string-match " " gcc-self-val)
1764 (concat "\"" gcc-self-val "\"")
1766 ;; In nndoc groups, we use the parent group name
1767 ;; instead of the current group.
1768 (let ((group (or (gnus-group-find-parameter
1769 gnus-newsgroup-name 'parent-group)
1771 (if (string-match " " group)
1772 (concat "\"" group "\"")
1774 (if (not (eq gcc-self-val 'none))
1776 (gnus-delete-line)))
1777 ;; Use the list of groups.
1778 (while (setq name (pop groups))
1779 (let ((str (if (string-match ":" name)
1781 (gnus-group-prefixed-name
1782 name gnus-message-archive-method))))
1783 (insert (if (string-match " " str)
1784 (concat "\"" str "\"")
1790 (defun gnus-mailing-list-followup-to ()
1791 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1792 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1793 (list-post (gnus-fetch-original-field "list-post")))
1794 (when (and list-post
1795 (string-match "mailto:\\([^>]+\\)" list-post))
1796 (setq list-post (match-string 1 list-post)))
1802 (defun gnus-configure-posting-styles (&optional group-name)
1803 "Configure posting styles according to `gnus-posting-styles'."
1804 (unless gnus-inhibit-posting-styles
1805 (let ((group (or group-name gnus-newsgroup-name ""))
1806 (styles (if (gnus-buffer-live-p gnus-summary-buffer)
1807 (with-current-buffer gnus-summary-buffer
1808 gnus-posting-styles)
1809 gnus-posting-styles))
1810 style match attribute value v results
1811 filep name address element)
1812 ;; If the group has a posting-style parameter, add it at the end with a
1813 ;; regexp matching everything, to be sure it takes precedence over all
1815 (when gnus-newsgroup-name
1816 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1818 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1819 ;; Go through all styles and look for matches.
1820 (dolist (style styles)
1821 (setq match (pop style))
1822 (goto-char (point-min))
1825 ;; Regexp string match on the group name.
1826 (string-match match group))
1828 ;; Obsolete format of header match.
1829 (and (gnus-buffer-live-p gnus-article-copy)
1830 (with-current-buffer gnus-article-copy
1832 (nnheader-narrow-to-headers)
1833 (let ((header (message-fetch-field (pop style))))
1835 (string-match (pop style) header)))))))
1836 ((or (symbolp match)
1840 ;; Function to be called.
1843 ;; Variable to be checked.
1844 (symbol-value match))))
1847 ((eq (car match) 'header)
1848 ;; New format of header match.
1849 (and (gnus-buffer-live-p gnus-article-copy)
1850 (with-current-buffer gnus-article-copy
1852 (nnheader-narrow-to-headers)
1853 (let ((header (message-fetch-field (nth 1 match))))
1855 (string-match (nth 2 match) header)))))))
1857 ;; This is a form to be evalled.
1859 ;; We have a match, so we set the variables.
1860 (dolist (attribute style)
1861 (setq element (pop attribute)
1865 ((eq (car attribute) :file)
1868 ((eq (car attribute) :value)
1872 ;; We get the value.
1876 (if (and (stringp match)
1877 (gnus-string-match-p "\\\\[&[:digit:]]" value)
1878 (match-beginning 1))
1879 (gnus-match-substitute-replacement value nil nil group)
1881 ((or (symbolp value)
1883 (cond ((functionp value)
1886 (symbol-value value))))
1889 ;; Translate obsolescent value.
1891 ((eq element 'signature-file)
1892 (setq element 'signature
1894 ((eq element 'x-face-file)
1895 (setq element 'x-face
1897 ;; Post-processing for the signature posting-style:
1898 (and (eq element 'signature) filep
1899 message-signature-directory
1900 ;; don't actually use the signature directory
1901 ;; if message-signature-file contains a path.
1902 (not (file-name-directory v))
1903 (setq v (nnheader-concat message-signature-directory v)))
1904 ;; Get the contents of file elems.
1906 (setq v (with-temp-buffer
1907 (insert-file-contents v)
1911 (goto-char (point-max))
1912 (if (zerop (skip-chars-backward "\n"))
1915 (setq results (delq (assoc element results) results))
1916 (push (cons element v) results))))
1917 ;; Now we have all the styles, so we insert them.
1918 (setq name (assq 'name results)
1919 address (assq 'address results))
1920 (setq results (delq name (delq address results)))
1921 (gnus-make-local-hook 'message-setup-hook)
1922 (setq results (sort results (lambda (x y)
1923 (string-lessp (car x) (car y)))))
1924 (dolist (result results)
1925 (add-hook 'message-setup-hook
1927 ((eq 'eval (car result))
1929 ((eq 'body (car result))
1933 (insert ,(cdr result)))))
1934 ((eq 'signature (car result))
1935 (set (make-local-variable 'message-signature) nil)
1936 (set (make-local-variable 'message-signature-file) nil)
1937 (if (not (cdr result))
1941 (let ((message-signature ,(cdr result)))
1942 (when message-signature
1943 (message-insert-signature)))))))
1946 (if (symbolp (car result))
1947 (capitalize (symbol-name (car result)))
1951 (message-remove-header ,header)
1952 (let ((value ,(cdr result)))
1955 (insert ,header ": " value)
1957 (insert "\n")))))))))
1959 (when (or name address)
1960 (add-hook 'message-setup-hook
1962 (set (make-local-variable 'user-mail-address)
1963 ,(or (cdr address) user-mail-address))
1964 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1966 ,(or (cdr address) user-mail-address)))
1968 (message-remove-header "From")
1970 (insert "From: " (message-make-from) "\n"))))
1973 ;;; Allow redefinition of functions.
1979 ;;; gnus-msg.el ends here