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
499 "Start editing a mail message to be sent.
500 Like `message-mail', but with Gnus paraphernalia, particularly the
501 Gcc: header for archiving purposes.
502 If Gnus isn't running, a plain `message-mail' setup is used
505 (if (not (gnus-alive-p))
506 (message-mail to subject other-headers continue
507 nil yank-action send-actions return-action)
508 (let ((buf (current-buffer))
510 (gnus-setup-message 'message
511 (message-mail to subject other-headers continue
512 nil yank-action send-actions return-action))
514 (setq mail-buf (current-buffer))
515 (switch-to-buffer buf)
516 (apply switch-action mail-buf nil))
517 ;; COMPOSEFUNC should return t if succeed. Undocumented ???
521 (defun gnus-button-mailto (address)
523 (set-buffer (gnus-copy-article-buffer))
524 (gnus-setup-message 'message
525 (message-reply address)))
528 (defun gnus-button-reply (&optional to-address wide)
529 "Like `message-reply'."
531 (gnus-setup-message 'message
532 (message-reply to-address wide)))
535 (define-mail-user-agent 'gnus-user-agent
536 'gnus-msg-mail 'message-send-and-exit
537 'message-kill-buffer 'message-send-hook)
539 (defun gnus-setup-posting-charset (group)
540 (let ((alist gnus-group-posting-charset-alist)
541 (group (or group ""))
545 (while (setq elem (pop alist))
546 (when (or (and (stringp (car elem))
547 (string-match (car elem) group))
548 (and (functionp (car elem))
549 (funcall (car elem) group))
550 (and (symbolp (car elem))
551 (symbol-value (car elem))))
552 (throw 'found (cons (cadr elem) (caddr elem)))))))))
554 (defun gnus-inews-add-send-actions (winconf buffer article
555 &optional config yanked
557 (gnus-make-local-hook 'message-sent-hook)
558 (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
559 'gnus-inews-do-gcc) nil t)
561 (gnus-make-local-hook 'message-header-hook)
562 (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
563 (setq message-post-method
564 `(lambda (&optional arg)
565 (gnus-post-method arg ,gnus-newsgroup-name)))
568 (setq gnus-current-window-configuration ',winconf-name)
569 (when (gnus-buffer-exists-p ,buffer)
570 (set-window-configuration ,winconf)))
571 'exit 'postpone 'kill)
572 (let ((to-be-marked (cond
575 (lambda (x) (if (listp x) (car x) x)) yanked))
576 (article (if (listp article) article (list article)))
579 `(when (gnus-buffer-exists-p ,buffer)
580 (with-current-buffer ,buffer
582 (if (eq config 'forward)
583 `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
584 `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
587 (put 'gnus-setup-message 'lisp-indent-function 1)
588 (put 'gnus-setup-message 'edebug-form-spec '(form body))
590 ;;; Post news commands of Gnus group mode and summary mode
592 (defun gnus-group-mail (&optional arg)
593 "Start composing a mail.
594 If ARG, use the group under the point to find a posting style.
595 If ARG is 1, prompt for a group name to find the posting style."
597 ;; We can't `let' gnus-newsgroup-name here, since that leads
598 ;; to local variables leaking.
599 (let ((group gnus-newsgroup-name)
600 ;; make sure last viewed article doesn't affect posting styles:
602 (buffer (current-buffer)))
605 (setq gnus-newsgroup-name
607 (if (= 1 (prefix-numeric-value arg))
608 (gnus-group-completing-read
609 "Use posting style of group"
610 nil (gnus-read-active-file-p))
611 (gnus-group-group-name))
613 ;; #### see comment in gnus-setup-message -- drv
614 (gnus-setup-message 'message (message-mail)))
615 (with-current-buffer buffer
616 (setq gnus-newsgroup-name group)))))
618 (defun gnus-group-news (&optional arg)
619 "Start composing a news.
620 If ARG, post to group under point.
621 If ARG is 1, prompt for group name to post to.
623 This function prepares a news even when using mail groups. This is useful
624 for posting messages to mail groups without actually sending them over the
625 network. The corresponding back end must have a 'request-post method."
627 ;; We can't `let' gnus-newsgroup-name here, since that leads
628 ;; to local variables leaking.
629 (let ((group gnus-newsgroup-name)
630 ;; make sure last viewed article doesn't affect posting styles:
632 (buffer (current-buffer)))
635 (setq gnus-newsgroup-name
637 (if (= 1 (prefix-numeric-value arg))
638 (gnus-group-completing-read "Use group"
640 (gnus-read-active-file-p))
641 (gnus-group-group-name))
643 ;; #### see comment in gnus-setup-message -- drv
644 (gnus-setup-message 'message
645 (message-news (gnus-group-real-name gnus-newsgroup-name))))
646 (with-current-buffer buffer
647 (setq gnus-newsgroup-name group)))))
649 (defun gnus-group-post-news (&optional arg)
650 "Start composing a message (a news by default).
651 If ARG, post to group under point. If ARG is 1, prompt for group name.
652 Depending on the selected group, the message might be either a mail or
655 ;; Bind this variable here to make message mode hooks work ok.
656 (let ((gnus-newsgroup-name
658 (if (= 1 (prefix-numeric-value arg))
659 (gnus-group-completing-read "Newsgroup" nil
660 (gnus-read-active-file-p))
661 (or (gnus-group-group-name) ""))
663 ;; make sure last viewed article doesn't affect posting styles:
665 (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
666 (string= gnus-newsgroup-name ""))))
668 (defun gnus-summary-mail-other-window (&optional arg)
669 "Start composing a mail in another window.
670 Use the posting of the current group by default.
671 If ARG, don't do that. If ARG is 1, prompt for group name to find the
674 ;; We can't `let' gnus-newsgroup-name here, since that leads
675 ;; to local variables leaking.
676 (let ((group gnus-newsgroup-name)
677 ;; make sure last viewed article doesn't affect posting styles:
679 (buffer (current-buffer)))
682 (setq gnus-newsgroup-name
684 (if (= 1 (prefix-numeric-value arg))
685 (gnus-group-completing-read "Use group"
687 (gnus-read-active-file-p))
689 gnus-newsgroup-name))
690 ;; #### see comment in gnus-setup-message -- drv
691 (gnus-setup-message 'message (message-mail)))
692 (with-current-buffer buffer
693 (setq gnus-newsgroup-name group)))))
695 (defun gnus-summary-news-other-window (&optional arg)
696 "Start composing a news in another window.
697 Post to the current group by default.
698 If ARG, don't do that. If ARG is 1, prompt for group name to post to.
700 This function prepares a news even when using mail groups. This is useful
701 for posting messages to mail groups without actually sending them over the
702 network. The corresponding back end must have a 'request-post method."
704 ;; We can't `let' gnus-newsgroup-name here, since that leads
705 ;; to local variables leaking.
706 (let ((group gnus-newsgroup-name)
707 ;; make sure last viewed article doesn't affect posting styles:
709 (buffer (current-buffer)))
712 (setq gnus-newsgroup-name
714 (if (= 1 (prefix-numeric-value arg))
715 (gnus-group-completing-read "Use group"
717 (gnus-read-active-file-p))
719 gnus-newsgroup-name))
720 ;; #### see comment in gnus-setup-message -- drv
721 (gnus-setup-message 'message
723 (message-news (gnus-group-real-name gnus-newsgroup-name))
724 (set (make-local-variable 'gnus-discouraged-post-methods)
726 (car (gnus-find-method-for-group gnus-newsgroup-name))
727 gnus-discouraged-post-methods)))))
728 (with-current-buffer buffer
729 (setq gnus-newsgroup-name group)))))
731 (defun gnus-summary-post-news (&optional arg)
732 "Start composing a message. Post to the current group by default.
733 If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
734 Depending on the selected group, the message might be either a mail or
737 ;; Bind this variable here to make message mode hooks work ok.
738 (let ((gnus-newsgroup-name
740 (if (= 1 (prefix-numeric-value arg))
741 (gnus-group-completing-read "Newsgroup" nil
742 (gnus-read-active-file-p))
744 gnus-newsgroup-name))
745 ;; make sure last viewed article doesn't affect posting styles:
747 (gnus-post-news 'post gnus-newsgroup-name)))
750 (defun gnus-summary-followup (yank &optional force-news)
751 "Compose a followup to an article.
752 If prefix argument YANK is non-nil, the original article is yanked
754 YANK is a list of elements, where the car of each element is the
755 article number, and the cdr is the string to be yanked."
757 (list (and current-prefix-arg
758 (gnus-summary-work-articles 1))))
760 (gnus-summary-goto-subject
761 (if (listp (car yank))
764 (save-window-excursion
765 (gnus-summary-select-article))
766 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
767 (gnus-newsgroup-name gnus-newsgroup-name))
769 (gnus-post-news nil gnus-newsgroup-name
770 headers gnus-article-buffer
772 (gnus-summary-handle-replysign)))
774 (defun gnus-summary-followup-with-original (n &optional force-news)
775 "Compose a followup to an article and include the original article.
776 The text in the region will be yanked. If the region isn't
777 active, the entire article will be yanked."
779 (gnus-summary-followup (gnus-summary-work-articles n) force-news))
781 (defun gnus-summary-followup-to-mail (&optional arg)
782 "Followup to the current mail message via news."
784 (list (and current-prefix-arg
785 (gnus-summary-work-articles 1))))
786 (gnus-summary-followup arg t))
788 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
789 "Followup to the current mail message via news."
791 (gnus-summary-followup (gnus-summary-work-articles arg) t))
793 (defun gnus-inews-yank-articles (articles)
794 (let (beg article yank-string)
796 (while (setq article (pop articles))
797 (when (listp article)
798 (setq yank-string (nth 1 article)
799 article (nth 0 article)))
800 (save-window-excursion
801 (set-buffer gnus-summary-buffer)
802 (gnus-summary-select-article nil nil nil article)
803 (gnus-summary-remove-process-mark article))
804 (gnus-copy-article-buffer nil yank-string)
805 (let ((message-reply-buffer gnus-article-copy)
806 (message-reply-headers
807 ;; The headers are decoded.
808 (with-current-buffer gnus-article-copy
810 (nnheader-narrow-to-headers)
811 (nnheader-parse-naked-head)))))
812 (message-yank-original)
813 (message-exchange-point-and-mark)
814 (setq beg (or beg (mark t))))
820 (defun gnus-summary-cancel-article (&optional n symp)
821 "Cancel an article you posted.
822 Uses the process-prefix convention. If given the symbolic
823 prefix `a', cancel using the standard posting method; if not
824 post using the current select method."
825 (interactive (gnus-interactive "P\ny"))
826 (let ((message-post-method
828 (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
829 (dolist (article (gnus-summary-work-articles n))
830 (when (gnus-summary-select-article t nil nil article)
831 (when (gnus-eval-in-buffer-window gnus-original-article-buffer
832 (message-cancel-news))
833 (gnus-summary-mark-as-read article gnus-canceled-mark)
834 (gnus-cache-remove-article 1))
835 (gnus-article-hide-headers-if-wanted))
836 (gnus-summary-remove-process-mark article))))
838 (defun gnus-summary-supersede-article ()
839 "Compose an article that will supersede a previous article.
840 This is done simply by taking the old article and adding a Supersedes
841 header line with the old Message-ID."
843 (let ((article (gnus-summary-article-number))
844 (mail-parse-charset gnus-newsgroup-charset))
845 (gnus-setup-message 'reply-yank
846 (gnus-summary-select-article t)
847 (set-buffer gnus-original-article-buffer)
851 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
852 (with-current-buffer ,gnus-summary-buffer
853 (gnus-cache-possibly-remove-article ,article nil nil nil t)
854 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
855 message-send-actions)
857 (gnus-inews-insert-gcc))))
861 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
862 ;; make a copy of the article buffer with all text properties removed
863 ;; this copy is in the buffer gnus-article-copy.
864 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
865 ;; this buffer should be passed to all mail/news reply/post routines.
866 (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
867 (with-current-buffer gnus-article-copy
868 (mm-enable-multibyte))
869 (let ((article-buffer (or article-buffer gnus-article-buffer))
871 (if (not (and (get-buffer article-buffer)
872 (gnus-buffer-exists-p article-buffer)))
873 (error "Can't find any article buffer")
874 (with-current-buffer article-buffer
875 (let ((gnus-newsgroup-charset (or gnus-article-charset
876 gnus-newsgroup-charset))
877 (gnus-newsgroup-ignored-charsets
878 (or gnus-article-ignored-charsets
879 gnus-newsgroup-ignored-charsets)))
881 ;; Copy over the (displayed) article buffer, delete
882 ;; hidden text and remove text properties.
884 (copy-to-buffer gnus-article-copy (point-min) (point-max))
885 (set-buffer gnus-article-copy)
888 (delete-region (point) (point-max))
889 (insert yank-string))
890 (gnus-article-delete-text-of-type 'annotation)
891 (gnus-article-delete-text-of-type 'multipart)
892 (gnus-remove-text-with-property 'gnus-prev)
893 (gnus-remove-text-with-property 'gnus-next)
894 (gnus-remove-text-with-property 'gnus-decoration)
897 (buffer-substring-no-properties (point-min) (point-max))
899 ;; Find the original headers.
900 (set-buffer gnus-original-article-buffer)
901 (goto-char (point-min))
902 (while (looking-at message-unix-mail-delimiter)
904 (let ((mail-header-separator ""))
906 end (or (message-goto-body)
907 ;; There may be just a header.
909 ;; Delete the headers from the displayed articles.
910 (set-buffer gnus-article-copy)
911 (let ((mail-header-separator ""))
912 (delete-region (goto-char (point-min))
913 (or (message-goto-body) (point-max))))
914 ;; Insert the original article headers.
915 (insert-buffer-substring gnus-original-article-buffer beg end)
917 (let ((gnus-article-decode-hook
918 (delq 'article-decode-charset
919 (copy-sequence gnus-article-decode-hook)))
920 (rfc2047-quote-decoded-words-containing-tspecials t))
921 (run-hooks 'gnus-article-decode-hook)))))
924 (defun gnus-post-news (post &optional group header article-buffer yank subject
927 (gnus-copy-article-buffer))
928 (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
929 (gnus-article-yanked-articles yank)
930 (add-to-list gnus-add-to-list))
931 (gnus-setup-message (cond (yank 'reply-yank)
932 (article-buffer 'reply)
934 (let* ((group (or group gnus-newsgroup-name))
935 (charset (gnus-group-name-charset nil group))
937 to-address to-group mailing-list to-list
940 (setq to-address (gnus-parameter-to-address group)
941 to-group (gnus-group-find-parameter group 'to-group)
942 to-list (gnus-parameter-to-list group)
943 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
944 mailing-list (when gnus-mailing-list-groups
945 (string-match gnus-mailing-list-groups group))
946 group (gnus-group-name-decode (gnus-group-real-name group)
948 (if (or (and to-group
949 (gnus-news-group-p to-group))
952 (and (gnus-news-group-p
953 (or pgroup gnus-newsgroup-name)
954 (or header gnus-current-article))
962 (and (not (gnus-virtual-group-p pgroup)) group)))
963 (set-buffer gnus-article-copy)
964 (gnus-msg-treat-broken-reply-to)
965 (message-followup (if (or newsgroup-p force-news)
966 (if (save-restriction
967 (article-narrow-to-head)
968 (message-fetch-field "newsgroups"))
975 (message-mail (or to-address to-list))
976 ;; Arrange for mail groups that have no `to-address' to
977 ;; get that when the user sends off the mail.
978 (when (and (not to-list)
981 (push (list 'gnus-inews-add-to-address pgroup)
982 message-send-actions)))
983 (set-buffer gnus-article-copy)
984 (gnus-msg-treat-broken-reply-to)
985 (message-wide-reply to-address)))
987 (gnus-inews-yank-articles yank))))))
989 (defun gnus-msg-treat-broken-reply-to (&optional force)
990 "Remove the Reply-to header if broken-reply-to."
992 (gnus-group-find-parameter
993 gnus-newsgroup-name 'broken-reply-to))
995 (message-narrow-to-head)
996 (message-remove-header "reply-to"))))
998 (defun gnus-post-method (arg group &optional silent)
999 "Return the posting method based on GROUP and ARG.
1000 If SILENT, don't prompt the user."
1001 (let ((gnus-post-method (or (gnus-parameter-post-method group)
1003 (group-method (gnus-find-method-for-group group)))
1005 ;; If the group-method is nil (which shouldn't happen) we use
1006 ;; the default method.
1007 ((null group-method)
1008 (or (and (listp gnus-post-method) ;If not current/native/nil
1009 (not (listp (car gnus-post-method))) ; and not a list of methods
1010 gnus-post-method) ;then use it.
1012 message-post-method))
1013 ;; We want the inverse of the default
1014 ((and arg (not (eq arg 0)))
1015 (if (eq gnus-post-method 'current)
1018 ;; We query the user for a post method.
1020 (and (listp gnus-post-method)
1021 (listp (car gnus-post-method))))
1023 ;; Collect all methods we know about.
1025 (when (listp gnus-post-method)
1026 (if (listp (car gnus-post-method))
1028 (list gnus-post-method)))
1029 gnus-secondary-select-methods
1030 (mapcar 'cdr gnus-server-alist)
1031 (mapcar 'car gnus-opened-servers)
1032 (list gnus-select-method)
1033 (list group-method)))
1034 method-alist post-methods method)
1035 ;; Weed out all mail methods.
1037 (setq method (gnus-server-get-method "" (pop methods)))
1038 (when (and (or (gnus-method-option-p method 'post)
1039 (gnus-method-option-p method 'post-mail))
1040 (not (member method post-methods)))
1041 (push method post-methods)))
1042 ;; Create a name-method alist.
1046 (if (equal (cadr m) "")
1047 (list (symbol-name (car m)) m)
1048 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1053 (setq gnus-last-posting-server
1055 gnus-last-posting-server)
1056 ;; Just use the last value.
1057 gnus-last-posting-server
1058 (gnus-completing-read
1059 "Posting method" (mapcar 'car method-alist) t
1060 (cons (or gnus-last-posting-server "") 0))))
1062 ;; Override normal method.
1063 ((and (eq gnus-post-method 'current)
1064 (not (memq (car group-method) gnus-discouraged-post-methods))
1065 (gnus-get-function group-method 'request-post t))
1068 ;; Use gnus-post-method.
1069 ((listp gnus-post-method) ;A method...
1070 (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1072 ;; Use the normal select method (nil or native).
1073 (t gnus-select-method))))
1077 (defun gnus-extended-version ()
1078 "Stringified Gnus version and Emacs version.
1079 See the variable `gnus-user-agent'."
1081 (if (stringp gnus-user-agent)
1083 ;; `gnus-user-agent' is a list:
1084 (let* ((float-output-format nil)
1086 (when (memq 'gnus gnus-user-agent)
1088 (prin1-to-string (gnus-continuum-version gnus-version) t)
1089 " (" gnus-version ")")))
1090 (emacs-v (gnus-emacs-version)))
1091 (concat gnus-v (when (and gnus-v emacs-v) " ")
1096 ;;; Gnus Mail Functions
1099 ;;; Mail reply commands of Gnus summary mode
1101 (defun gnus-summary-reply (&optional yank wide very-wide)
1102 "Start composing a mail reply to the current message.
1103 If prefix argument YANK is non-nil, the original article is yanked
1105 If WIDE, make a wide reply.
1106 If VERY-WIDE, make a very wide reply."
1108 (list (and current-prefix-arg
1109 (gnus-summary-work-articles 1))))
1110 ;; Allow user to require confirmation before replying by mail to the
1111 ;; author of a news article (or mail message).
1112 (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
1113 gnus-confirm-treat-mail-like-news))
1114 (not (cond ((stringp gnus-confirm-mail-reply-to-news)
1115 (string-match gnus-confirm-mail-reply-to-news
1116 gnus-newsgroup-name))
1117 ((functionp gnus-confirm-mail-reply-to-news)
1118 (funcall gnus-confirm-mail-reply-to-news
1119 gnus-newsgroup-name))
1120 (t gnus-confirm-mail-reply-to-news)))
1121 (if (or wide very-wide)
1122 t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
1124 (y-or-n-p "Really reply by mail to article author? ")))
1126 (if (listp (car yank))
1129 (gnus-article-reply (or article (gnus-summary-article-number)))
1130 (gnus-article-yanked-articles yank)
1132 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1134 (gnus-summary-goto-subject article))
1135 (gnus-setup-message (if yank 'reply-yank 'reply)
1137 (gnus-summary-select-article)
1138 (dolist (article very-wide)
1139 (gnus-summary-select-article nil nil nil article)
1140 (with-current-buffer (gnus-copy-article-buffer)
1141 (gnus-msg-treat-broken-reply-to)
1143 (message-narrow-to-head)
1144 (setq headers (concat headers (buffer-string)))))))
1145 (set-buffer (gnus-copy-article-buffer))
1146 (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1148 (message-narrow-to-head)
1152 (goto-char (point-max)))
1153 (mml-quote-region (point) (point-max))
1154 (message-reply nil wide)
1156 (gnus-inews-yank-articles yank))
1157 (gnus-summary-handle-replysign)))))
1159 (defun gnus-summary-handle-replysign ()
1160 "Check the various replysign variables and take action accordingly."
1161 (when (or gnus-message-replysign gnus-message-replyencrypt)
1162 (let (signed encrypted)
1163 (with-current-buffer gnus-article-buffer
1164 (setq signed (memq 'signed gnus-article-wash-types))
1165 (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1166 (cond ((and gnus-message-replyencrypt encrypted)
1167 (mml-secure-message mml-default-encrypt-method
1168 (if gnus-message-replysignencrypted
1171 ((and gnus-message-replysign signed)
1172 (mml-secure-message mml-default-sign-method 'sign))))))
1174 (defun gnus-summary-reply-with-original (n &optional wide)
1175 "Start composing a reply mail to the current message.
1176 The original article will be yanked."
1178 (gnus-summary-reply (gnus-summary-work-articles n) wide))
1180 (defun gnus-summary-reply-to-list-with-original (n &optional wide)
1181 "Start composing a reply mail to the current message.
1182 The reply goes only to the mailing list.
1183 The original article will be yanked."
1185 (let ((message-reply-to-function
1187 `((To . ,(gnus-mailing-list-followup-to))))))
1188 (gnus-summary-reply (gnus-summary-work-articles n) wide)))
1190 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1191 "Like `gnus-summary-reply' except removing reply-to field.
1192 If prefix argument YANK is non-nil, the original article is yanked
1194 If WIDE, make a wide reply.
1195 If VERY-WIDE, make a very wide reply."
1197 (list (and current-prefix-arg
1198 (gnus-summary-work-articles 1))))
1199 (let ((gnus-msg-force-broken-reply-to t))
1200 (gnus-summary-reply yank wide very-wide)))
1202 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1203 "Like `gnus-summary-reply-with-original' except removing reply-to field.
1204 The original article will be yanked."
1206 (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1208 (defun gnus-summary-wide-reply (&optional yank)
1209 "Start composing a wide reply mail to the current message.
1210 If prefix argument YANK is non-nil, the original article is yanked
1213 (list (and current-prefix-arg
1214 (gnus-summary-work-articles 1))))
1215 (gnus-summary-reply yank t))
1217 (defun gnus-summary-wide-reply-with-original (n)
1218 "Start composing a wide reply mail to the current message.
1219 The original article will be yanked.
1220 Uses the process/prefix convention."
1222 (gnus-summary-reply-with-original n t))
1224 (defun gnus-summary-very-wide-reply (&optional yank)
1225 "Start composing a very wide reply mail to the current message.
1226 If prefix argument YANK is non-nil, the original article is yanked
1229 (list (and current-prefix-arg
1230 (gnus-summary-work-articles 1))))
1231 (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1233 (defun gnus-summary-very-wide-reply-with-original (n)
1234 "Start composing a very wide reply mail to the current message.
1235 The original article will be yanked."
1238 (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1240 (defun gnus-summary-mail-forward (&optional arg post)
1241 "Forward the current message(s) to another user.
1242 If process marks exist, forward all marked messages;
1243 if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
1244 if ARG is 1, decode the message and forward directly inline;
1245 if ARG is 2, forward message as an rfc822 MIME section;
1246 if ARG is 3, decode message and forward as an rfc822 MIME section;
1247 if ARG is 4, forward message directly inline;
1248 otherwise, use flipped `message-forward-as-mime'.
1249 If POST, post instead of mail.
1250 For the \"inline\" alternatives, also see the variable
1251 `message-forward-ignored-headers'."
1253 (if (cdr (gnus-summary-work-articles nil))
1254 ;; Process marks are given.
1255 (gnus-uu-digest-mail-forward nil post)
1256 ;; No process marks.
1257 (let ((message-forward-as-mime message-forward-as-mime)
1258 (message-forward-show-mml message-forward-show-mml))
1262 (setq message-forward-as-mime nil
1263 message-forward-show-mml t))
1265 (setq message-forward-as-mime t
1266 message-forward-show-mml nil))
1268 (setq message-forward-as-mime t
1269 message-forward-show-mml t))
1271 (setq message-forward-as-mime nil
1272 message-forward-show-mml nil))
1274 (setq message-forward-as-mime (not message-forward-as-mime))))
1275 (let* ((gnus-article-reply (gnus-summary-article-number))
1276 (gnus-article-yanked-articles (list gnus-article-reply)))
1277 (gnus-setup-message 'forward
1278 (gnus-summary-select-article)
1279 (let ((mail-parse-charset
1280 (or (and (gnus-buffer-live-p gnus-article-buffer)
1281 (with-current-buffer gnus-article-buffer
1282 gnus-article-charset))
1283 gnus-newsgroup-charset))
1284 (mail-parse-ignored-charsets
1285 gnus-newsgroup-ignored-charsets))
1286 (set-buffer gnus-original-article-buffer)
1287 (message-forward post)))))))
1289 (defun gnus-summary-resend-message-insert-gcc ()
1290 "Insert Gcc header according to `gnus-gcc-self-resent-messages'."
1291 (gnus-inews-insert-gcc)
1294 (mm-encode-coding-string
1296 (gnus-group-name-charset (gnus-inews-group-method group)
1298 (message-unquote-tokens
1299 (message-tokenize-header (mail-fetch-field "gcc" nil t)
1301 (message-remove-header "gcc")
1303 (goto-char (point-max))
1304 (cond ((eq gnus-gcc-self-resent-messages 'none))
1305 ((eq gnus-gcc-self-resent-messages t)
1306 (insert "Gcc: \"" gnus-newsgroup-name "\"\n"))
1307 ((stringp gnus-gcc-self-resent-messages)
1309 (mm-encode-coding-string
1310 (if (string-match " " gnus-gcc-self-resent-messages)
1311 (concat "\"" gnus-gcc-self-resent-messages "\"")
1312 gnus-gcc-self-resent-messages)
1313 (gnus-group-name-charset
1314 (gnus-inews-group-method gnus-gcc-self-resent-messages)
1315 gnus-gcc-self-resent-messages))
1317 ((null gnus-gcc-self-resent-messages)
1318 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n"))
1319 ((eq gnus-gcc-self-resent-messages 'no-gcc-self)
1320 (when (setq gcc (delete
1322 (delete (concat "\"" gnus-newsgroup-name "\"")
1324 (insert "Gcc: " (mapconcat 'identity gcc ", ") "\n")))))))
1326 (defun gnus-summary-resend-message (address n)
1327 "Resend the current article to ADDRESS."
1329 (list (message-read-from-minibuffer
1330 "Resend message(s) to: "
1331 (when (and gnus-summary-resend-default-address
1332 (gnus-buffer-live-p gnus-original-article-buffer))
1333 ;; If some other article is currently selected, the
1334 ;; initial-contents is wrong. Whatever, it is just the
1335 ;; initial-contents.
1336 (with-current-buffer gnus-original-article-buffer
1337 (nnmail-fetch-field "to"))))
1338 current-prefix-arg))
1339 (let ((message-header-setup-hook (copy-sequence message-header-setup-hook))
1340 (message-sent-hook (copy-sequence message-sent-hook)))
1341 ;; `gnus-summary-resend-message-insert-gcc' must run last.
1342 (add-hook 'message-header-setup-hook
1343 'gnus-summary-resend-message-insert-gcc t)
1344 (add-hook 'message-sent-hook (if gnus-agent
1345 'gnus-agent-possibly-do-gcc
1346 'gnus-inews-do-gcc))
1347 (dolist (article (gnus-summary-work-articles n))
1348 (gnus-summary-select-article nil nil nil article)
1349 (with-current-buffer gnus-original-article-buffer
1350 (let ((gnus-gcc-externalize-attachments nil)
1351 (message-inhibit-body-encoding t))
1352 (message-resend address)))
1353 (gnus-summary-mark-article-as-forwarded article))))
1355 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1356 (defun gnus-summary-resend-message-edit ()
1357 "Resend an article that has already been sent.
1358 A new buffer will be created to allow the user to modify body and
1359 contents of the message, and then, everything will happen as when
1360 composing a new message."
1362 (let ((mail-parse-charset gnus-newsgroup-charset))
1363 (gnus-setup-message 'reply-yank
1364 (gnus-summary-select-article t)
1365 (set-buffer gnus-original-article-buffer)
1366 (let ((cur (current-buffer))
1367 (to (message-fetch-field "to")))
1368 ;; Get a normal message buffer.
1369 (message-pop-to-buffer (message-buffer-name "Resend" to))
1370 (insert-buffer-substring cur)
1372 (message-narrow-to-head-1)
1373 ;; Gnus will generate a new one when sending.
1374 (message-remove-header "Message-ID")
1375 ;; Remove unwanted headers.
1376 (message-remove-header message-ignored-resent-headers t)
1377 (goto-char (point-max))
1378 (insert mail-header-separator)
1380 (gnus-inews-insert-gcc)
1381 (goto-char (point-min))
1382 (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1386 (defun gnus-summary-post-forward (&optional arg)
1387 "Forward the current article to a newsgroup.
1388 See `gnus-summary-mail-forward' for ARG."
1390 (gnus-summary-mail-forward arg t))
1392 (defun gnus-summary-mail-crosspost-complaint (n)
1393 "Send a complaint about crossposting to the current article(s)."
1395 (dolist (article (gnus-summary-work-articles n))
1396 (set-buffer gnus-summary-buffer)
1397 (gnus-summary-goto-subject article)
1398 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1399 newsgroups followup-to)
1400 (gnus-summary-select-article)
1401 (set-buffer gnus-original-article-buffer)
1402 (if (and (<= (length (message-tokenize-header
1404 (mail-fetch-field "newsgroups"))
1407 (or (not (setq followup-to (mail-fetch-field "followup-to")))
1408 (not (member group (message-tokenize-header
1409 followup-to ", ")))))
1411 (gnus-message 1 "Followup-to restricted")
1412 (gnus-message 1 "Not a crossposted article"))
1413 (set-buffer gnus-summary-buffer)
1414 (gnus-summary-reply-with-original 1)
1415 (set-buffer gnus-message-buffer)
1417 (insert (format gnus-crosspost-complaint newsgroups group))
1418 (message-goto-subject)
1419 (re-search-forward " *$")
1420 (replace-match " (crosspost notification)" t t)
1421 (gnus-deactivate-mark)
1422 (when (gnus-y-or-n-p "Send this complaint? ")
1423 (message-send-and-exit))))))
1425 (defun gnus-mail-parse-comma-list ()
1428 (skip-chars-forward " ")
1431 (skip-chars-forward "^,")
1436 (narrow-to-region beg (point))
1439 (while (search-forward "\"" nil t)
1443 (skip-chars-forward ",")
1444 (skip-chars-forward "^,"))
1445 (skip-chars-backward " ")
1446 (push (buffer-substring beg (point))
1448 (skip-chars-forward "^,")
1449 (skip-chars-forward ", "))
1452 (defun gnus-inews-add-to-address (group)
1453 (let ((to-address (mail-fetch-field "to")))
1454 (when (and to-address
1456 ;; This mail group doesn't have a `to-list', so we add one
1458 (when (gnus-y-or-n-p
1459 (format "Do you want to add this as `to-list': %s? " to-address))
1460 (gnus-group-add-parameter group (cons 'to-list to-address))))))
1462 (defun gnus-put-message ()
1463 "Put the current message in some group and return to Gnus."
1465 (let ((reply gnus-article-reply)
1466 (winconf gnus-prev-winconf)
1467 (group gnus-newsgroup-name))
1469 (not (gnus-group-read-only-p group)))
1470 (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1472 (when (gnus-group-entry group)
1473 (error "No such group: %s" group))
1477 (message-narrow-to-headers)
1478 (let ((gnus-deletable-headers nil))
1479 (message-generate-headers
1480 (if (message-news-p)
1481 message-required-news-headers
1482 message-required-mail-headers)))
1483 (goto-char (point-max))
1484 (if (string-match " " group)
1485 (insert "Gcc: \"" group "\"\n")
1486 (insert "Gcc: " group "\n"))
1489 (when (and (get-buffer gnus-group-buffer)
1490 (gnus-buffer-exists-p (car-safe reply))
1492 (set-buffer (car reply))
1493 (gnus-summary-mark-article-as-replied (cdr reply)))
1495 (set-window-configuration winconf))))
1497 (defun gnus-article-mail (yank)
1498 "Send a reply to the address near point.
1499 If YANK is non-nil, include the original article."
1503 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1504 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1506 (gnus-msg-mail address)
1508 (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1510 (defvar nntp-server-type)
1512 "Send a bug report to the Gnus maintainers."
1514 (unless (gnus-alive-p)
1515 (error "Gnus has been shut down"))
1516 (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1517 (unless (message-mail-user-agent)
1518 (when gnus-bug-create-help-buffer
1519 (switch-to-buffer "*Gnus Help Bug*")
1521 (insert gnus-bug-message)
1522 (goto-char (point-min)))
1523 (message-pop-to-buffer "*Gnus Bug*"))
1524 (let ((message-this-is-mail t))
1525 (message-setup `((To . ,gnus-maintainer)
1528 . ,(format "%s" gnus-bug-package))
1530 . ,(format "%s" (gnus-continuum-version))))))
1531 (when gnus-bug-create-help-buffer
1532 (push `(gnus-bug-kill-buffer) message-send-actions))
1533 (goto-char (point-min))
1535 (insert "\n\n\n\n\n")
1536 (insert (gnus-version) "\n"
1537 (emacs-version) "\n")
1538 (when (and (boundp 'nntp-server-type)
1539 (stringp nntp-server-type))
1540 (insert nntp-server-type))
1541 (goto-char (point-min))
1542 (search-forward "Subject: " nil t)
1545 (defun gnus-bug-kill-buffer ()
1546 (when (get-buffer "*Gnus Help Bug*")
1547 (kill-buffer "*Gnus Help Bug*")))
1549 (defun gnus-summary-yank-message (buffer n)
1550 "Yank the current article into a composed message."
1552 (list (gnus-completing-read "Buffer" (message-buffers) t)
1553 current-prefix-arg))
1554 (gnus-summary-iterate n
1555 (let ((gnus-inhibit-treatment t))
1556 (gnus-summary-select-article))
1557 (with-current-buffer buffer
1558 (message-yank-buffer gnus-article-buffer))))
1560 ;;; Treatment of rejected articles.
1563 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1564 "Re-mail the current message.
1565 This only makes sense if the current message is a bounce message that
1566 contains some mail you have written which has been bounced back to
1568 If FETCH, try to fetch the article that this is a reply to, if indeed
1571 (gnus-summary-select-article t)
1572 (let (summary-buffer parent)
1575 (setq summary-buffer (current-buffer))
1576 (set-buffer gnus-original-article-buffer)
1578 (when (re-search-forward "^References:\n?" nil t)
1579 (while (memq (char-after) '(?\t ? ))
1581 (skip-chars-backward "\t\n ")
1583 (gnus-parent-id (buffer-substring (match-end 0) (point))))))
1584 (set-buffer gnus-original-article-buffer))
1585 (gnus-setup-message 'compose-bounce
1588 (gnus-inews-insert-gcc)
1589 ;; If there are references, we fetch the article we answered to.
1591 (with-current-buffer summary-buffer
1592 (gnus-summary-refer-article parent)
1593 (gnus-summary-show-all-headers))))))
1597 (defun gnus-inews-group-method (group)
1599 ;; If the group doesn't exist, we assume
1600 ;; it's an archive group...
1601 ((and (null (gnus-get-info group))
1602 (eq (car (gnus-server-to-method gnus-message-archive-method))
1603 (car (gnus-server-to-method (gnus-group-method group)))))
1604 gnus-message-archive-method)
1606 ((gnus-info-method (gnus-get-info group))
1607 (gnus-info-method (gnus-get-info group)))
1609 (t (gnus-server-to-method (gnus-group-method group)))))
1611 ;; Do Gcc handling, which copied the message over to some group.
1612 (defun gnus-inews-do-gcc (&optional gcc)
1616 (message-narrow-to-headers)
1617 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1618 (cur (current-buffer))
1619 groups group method group-art options
1620 mml-externalize-attachments)
1622 (message-remove-header "gcc")
1624 (setq groups (message-unquote-tokens
1625 (message-tokenize-header gcc " ,")))
1626 ;; Copy the article over to some group(s).
1627 (while (setq group (pop groups))
1628 (setq method (gnus-inews-group-method group)
1629 group (mm-encode-coding-string
1631 (gnus-group-name-charset method group)))
1632 (unless (gnus-check-server method)
1633 (error "Can't open server %s" (if (stringp method) method
1635 (unless (gnus-request-group group t method)
1636 (gnus-request-create-group group method))
1637 (setq mml-externalize-attachments
1638 (if (stringp gnus-gcc-externalize-attachments)
1639 (string-match gnus-gcc-externalize-attachments group)
1640 gnus-gcc-externalize-attachments))
1642 (nnheader-set-temp-buffer " *acc*")
1643 (setq message-options (with-current-buffer cur message-options))
1644 (insert-buffer-substring cur)
1645 (message-encode-message-body)
1647 (message-narrow-to-headers)
1648 (let* ((mail-parse-charset message-default-charset)
1649 (newsgroups-field (save-restriction
1650 (message-narrow-to-headers-or-head)
1651 (message-fetch-field "Newsgroups")))
1652 (followup-field (save-restriction
1653 (message-narrow-to-headers-or-head)
1654 (message-fetch-field "Followup-To")))
1655 ;; BUG: We really need to get the charset for
1656 ;; each name in the Newsgroups and Followup-To
1657 ;; lines to allow crossposting between group
1658 ;; names with incompatible character sets.
1659 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
1660 (group-field-charset
1661 (gnus-group-name-charset
1662 method (or newsgroups-field "")))
1663 (followup-field-charset
1664 (gnus-group-name-charset
1665 method (or followup-field "")))
1666 (rfc2047-header-encoding-alist
1668 (when group-field-charset
1669 (list (cons "Newsgroups" group-field-charset)))
1670 (when followup-field-charset
1671 (list (cons "Followup-To" followup-field-charset)))
1672 rfc2047-header-encoding-alist)))
1673 (mail-encode-encoded-word-buffer)))
1674 (goto-char (point-min))
1675 (when (re-search-forward
1676 (concat "^" (regexp-quote mail-header-separator) "$")
1678 (replace-match "" t t ))
1679 (when (or (not (gnus-check-backend-function
1680 'request-accept-article group))
1681 (not (setq group-art
1682 (gnus-request-accept-article
1683 group method t t))))
1684 (gnus-message 1 "Couldn't store article in group %s: %s"
1685 group (gnus-status-message method)))
1686 (when (stringp method)
1687 (setq method (gnus-server-to-method method)))
1688 (when (and (listp method)
1689 (gnus-native-method-p method))
1690 (setq group (gnus-group-short-name group)))
1691 (when (and group-art
1692 ;; FIXME: Should gcc-mark-as-read work when
1693 ;; Gnus is not running?
1695 (if (or gnus-gcc-mark-as-read
1696 (and (boundp 'gnus-inews-mark-gcc-as-read)
1697 (symbol-value 'gnus-inews-mark-gcc-as-read)))
1698 (gnus-group-mark-article-read group (cdr group-art))
1699 (with-current-buffer gnus-group-buffer
1700 (let ((gnus-group-marked (list group))
1701 (gnus-get-new-news-hook nil)
1702 (inhibit-read-only t))
1703 (gnus-group-get-new-news-this-group nil t)))))
1704 (setq options message-options)
1705 (with-current-buffer cur (setq message-options options))
1706 (kill-buffer (current-buffer)))))))))
1708 (defun gnus-inews-insert-gcc (&optional group)
1709 "Insert the Gcc to say where the article is to be archived."
1710 (let* ((group (or group gnus-newsgroup-name))
1711 (group (when group (gnus-group-decoded-name group)))
1712 (var (or gnus-outgoing-message-group gnus-message-archive-group))
1714 (and group (gnus-group-find-parameter group 'gcc-self)))
1718 ((null gnus-message-archive-method)
1722 ;; Just a single group.
1725 ;; We don't want this.
1727 ((and (listp var) (stringp (car var)))
1728 ;; A list of groups.
1732 (funcall var group))
1734 ;; An alist of regexps/functions/forms.
1739 ((stringp (caar var))
1741 (when (string-match (caar var) group)
1743 ((functionp (car var))
1745 (funcall (car var) group))
1747 (eval (car var)))))))
1748 (setq var (cdr var)))
1751 (when (or groups gcc-self-val)
1752 (when (stringp groups)
1753 (setq groups (list groups)))
1756 (message-narrow-to-headers)
1757 (goto-char (point-max))
1760 ;; Use the `gcc-self' param value instead.
1763 (if (stringp gcc-self-val)
1764 (if (string-match " " gcc-self-val)
1765 (concat "\"" gcc-self-val "\"")
1767 ;; In nndoc groups, we use the parent group name
1768 ;; instead of the current group.
1769 (let ((group (or (gnus-group-find-parameter
1770 gnus-newsgroup-name 'parent-group)
1772 (if (string-match " " group)
1773 (concat "\"" group "\"")
1775 (if (not (eq gcc-self-val 'none))
1777 (gnus-delete-line)))
1778 ;; Use the list of groups.
1779 (while (setq name (pop groups))
1780 (let ((str (if (string-match ":" name)
1782 (gnus-group-prefixed-name
1783 name gnus-message-archive-method))))
1784 (insert (if (string-match " " str)
1785 (concat "\"" str "\"")
1791 (defun gnus-mailing-list-followup-to ()
1792 "Look at the headers in the current buffer and return a Mail-Followup-To address."
1793 (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
1794 (list-post (gnus-fetch-original-field "list-post")))
1795 (when (and list-post
1796 (string-match "mailto:\\([^>]+\\)" list-post))
1797 (setq list-post (match-string 1 list-post)))
1803 (defun gnus-configure-posting-styles (&optional group-name)
1804 "Configure posting styles according to `gnus-posting-styles'."
1805 (unless gnus-inhibit-posting-styles
1806 (let ((group (or group-name gnus-newsgroup-name ""))
1807 (styles (if (gnus-buffer-live-p gnus-summary-buffer)
1808 (with-current-buffer gnus-summary-buffer
1809 gnus-posting-styles)
1810 gnus-posting-styles))
1811 style match attribute value v results
1812 filep name address element)
1813 ;; If the group has a posting-style parameter, add it at the end with a
1814 ;; regexp matching everything, to be sure it takes precedence over all
1816 (when gnus-newsgroup-name
1817 (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1819 (setq styles (append styles (list (cons ".*" tmp-style)))))))
1820 ;; Go through all styles and look for matches.
1821 (dolist (style styles)
1822 (setq match (pop style))
1823 (goto-char (point-min))
1826 ;; Regexp string match on the group name.
1827 (string-match match group))
1829 ;; Obsolete format of header match.
1830 (and (gnus-buffer-live-p gnus-article-copy)
1831 (with-current-buffer gnus-article-copy
1833 (nnheader-narrow-to-headers)
1834 (let ((header (message-fetch-field (pop style))))
1836 (string-match (pop style) header)))))))
1837 ((or (symbolp match)
1841 ;; Function to be called.
1844 ;; Variable to be checked.
1845 (symbol-value match))))
1848 ((eq (car match) 'header)
1849 ;; New format of header match.
1850 (and (gnus-buffer-live-p gnus-article-copy)
1851 (with-current-buffer gnus-article-copy
1853 (nnheader-narrow-to-headers)
1854 (let ((header (message-fetch-field (nth 1 match))))
1856 (string-match (nth 2 match) header)))))))
1858 ;; This is a form to be evalled.
1860 ;; We have a match, so we set the variables.
1861 (dolist (attribute style)
1862 (setq element (pop attribute)
1866 ((eq (car attribute) :file)
1869 ((eq (car attribute) :value)
1873 ;; We get the value.
1877 (if (and (stringp match)
1878 (gnus-string-match-p "\\\\[&[:digit:]]" value)
1879 (match-beginning 1))
1880 (gnus-match-substitute-replacement value nil nil group)
1882 ((or (symbolp value)
1884 (cond ((functionp value)
1887 (symbol-value value))))
1890 ;; Translate obsolescent value.
1892 ((eq element 'signature-file)
1893 (setq element 'signature
1895 ((eq element 'x-face-file)
1896 (setq element 'x-face
1898 ;; Post-processing for the signature posting-style:
1899 (and (eq element 'signature) filep
1900 message-signature-directory
1901 ;; don't actually use the signature directory
1902 ;; if message-signature-file contains a path.
1903 (not (file-name-directory v))
1904 (setq v (nnheader-concat message-signature-directory v)))
1905 ;; Get the contents of file elems.
1907 (setq v (with-temp-buffer
1908 (insert-file-contents v)
1912 (goto-char (point-max))
1913 (if (zerop (skip-chars-backward "\n"))
1916 (setq results (delq (assoc element results) results))
1917 (push (cons element v) results))))
1918 ;; Now we have all the styles, so we insert them.
1919 (setq name (assq 'name results)
1920 address (assq 'address results))
1921 (setq results (delq name (delq address results)))
1922 (gnus-make-local-hook 'message-setup-hook)
1923 (setq results (sort results (lambda (x y)
1924 (string-lessp (car x) (car y)))))
1925 (dolist (result results)
1926 (add-hook 'message-setup-hook
1928 ((eq 'eval (car result))
1930 ((eq 'body (car result))
1934 (insert ,(cdr result)))))
1935 ((eq 'signature (car result))
1936 (set (make-local-variable 'message-signature) nil)
1937 (set (make-local-variable 'message-signature-file) nil)
1938 (if (not (cdr result))
1942 (let ((message-signature ,(cdr result)))
1943 (when message-signature
1944 (message-insert-signature)))))))
1947 (if (symbolp (car result))
1948 (capitalize (symbol-name (car result)))
1952 (message-remove-header ,header)
1953 (let ((value ,(cdr result)))
1956 (insert ,header ": " value)
1958 (insert "\n")))))))))
1960 (when (or name address)
1961 (add-hook 'message-setup-hook
1963 (set (make-local-variable 'user-mail-address)
1964 ,(or (cdr address) user-mail-address))
1965 (let ((user-full-name ,(or (cdr name) (user-full-name)))
1967 ,(or (cdr address) user-mail-address)))
1969 (message-remove-header "From")
1971 (insert "From: " (message-make-from) "\n"))))
1974 ;;; Allow redefinition of functions.
1980 ;;; gnus-msg.el ends here